From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 999F4C4741F for ; Mon, 9 Nov 2020 15:20:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45A44206E3 for ; Mon, 9 Nov 2020 15:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604935258; bh=Cth1QJvvekjB03ZZjYoOHU7UlQ6K6fm3Qvk6L9xnx9g=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=cmz+BHgDhV2CZd+Njod2OJoXlg/htMveumhax6QdDKZgdFEju+D+q0OZ3+VoBWTEG nChSsEKt0pdJ5u1h1K8w0lxl1iJvM1LlCTlZjikz5sKBnMrPiFFNIBNefIhcdNxTnU 3kIUnnRdFMKZUV0a5CrycY00RNtWTaosU/9Au39E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730539AbgKIPU5 (ORCPT ); Mon, 9 Nov 2020 10:20:57 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:37404 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727077AbgKIPU4 (ORCPT ); Mon, 9 Nov 2020 10:20:56 -0500 Received: by mail-ot1-f66.google.com with SMTP id l36so9264469ota.4; Mon, 09 Nov 2020 07:20:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CdGO/90kcr4f31GvGdKRgTjSScpvfcOUI5SEBiL1EOA=; b=crwL3KcLBR18efgVSCR5SEqF+HF6tPLoG1uQk/bb+zdrehr7DOtGNHJSL071armlqT 6xl20J7gSvRCLnZnT5s4WxVgvcVJlbnPrYDV0jISRBMCSTfj1AWAoNLO25GcL60CmiG3 +fy4fcQQP3XrukFJ4Bt2hR3ckizh+HEQOil9EHkmDsn2IU9ccIBM2SlECoabCHUj6fWc 5Q37sGonVSgZ7rtNIaLf0XnM/88fkt7PL0niBADhsuGRAw/YY0bUvnV3xPcrnnxZ0PTx dYG6IJeC3kgut4UQ/wDfR7d1/z2fKZAedkFrWbQvdeuNwa3yU4aqSp07rBMWzvybyxpY poWQ== X-Gm-Message-State: AOAM531HMOYxtP+Kcs2LHoruI3QerO3OmsVR33zT8vj+85Qpdpia8lej 7AJmd97/w6F592cvVxScr9IEcZAmGTJI4iHHMW/hH9Et X-Google-Smtp-Source: ABdhPJw70Qaea5loILHHnrwzHV1xU4x41jwgxIGZggvhcZrO8OGG4v1QzFpHW/n9zj+yJ2XTC+irnNGUXr3C1IVwSCg= X-Received: by 2002:a9d:171a:: with SMTP id i26mr11257116ota.260.1604935255974; Mon, 09 Nov 2020 07:20:55 -0800 (PST) MIME-Version: 1.0 References: <20201109150416.1877878-1-zhangqilong3@huawei.com> <20201109150416.1877878-2-zhangqilong3@huawei.com> In-Reply-To: <20201109150416.1877878-2-zhangqilong3@huawei.com> From: "Rafael J. Wysocki" Date: Mon, 9 Nov 2020 16:20:44 +0100 Message-ID: Subject: Re: [PATCH v2 1/2] PM: runtime: Add a general runtime get sync operation to deal with usage counter To: Zhang Qilong Cc: "Rafael J. Wysocki" , fugang.duan@nxp.com, David Miller , Jakub Kicinski , Linux PM , netdev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, Nov 9, 2020 at 4:00 PM Zhang Qilong wrote: > > In many case, we need to check return value of pm_runtime_get_sync, but > it brings a trouble to the usage counter processing. Many callers forget > to decrease the usage counter when it failed. It has been discussed a > lot[0][1]. So we add a function to deal with the usage counter for better > coding. > > [0]https://lkml.org/lkml/2020/6/14/88 > [1]https://patchwork.ozlabs.org/project/linux-tegra/patch/20200520095148.10995-1-dinghao.liu@zju.edu.cn/ > Signed-off-by: Zhang Qilong > --- > include/linux/pm_runtime.h | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h > index 4b708f4e8eed..6549ce764400 100644 > --- a/include/linux/pm_runtime.h > +++ b/include/linux/pm_runtime.h > @@ -386,6 +386,36 @@ static inline int pm_runtime_get_sync(struct device *dev) > return __pm_runtime_resume(dev, RPM_GET_PUT); > } > > +/** > + * pm_runtime_general_get - Bump up usage counter of a device and resume it. > + * @dev: Target device. > + * > + * Increase runtime PM usage counter of @dev first, and carry out runtime-resume > + * of it synchronously. If __pm_runtime_resume return negative value(device is in > + * error state), we to need decrease the usage counter before it return. If > + * __pm_runtime_resume return positive value, it means the runtime of device has > + * already been in active state, and we let the new wrapper return zero instead. > + * > + * The possible return values of this function is zero or negative value. > + * zero: > + * - it means resume succeeed or runtime of device has already been active, the > + * runtime PM usage counter of @dev remains incremented. > + * negative: > + * - it means failure and the runtime PM usage counter of @dev has been balanced. The kerneldoc above is kind of noisy and it is hard to figure out what the helper really does from it. You could basically say something like "Resume @dev synchronously and if that is successful, increment its runtime PM usage counter. Return 0 if the runtime PM usage counter of @dev has been incremented or a negative error code otherwise." > + */ > +static inline int pm_runtime_general_get(struct device *dev) What about pm_runtime_resume_and_get()? > +{ > + int ret = 0; This extra initialization is not necessary. You can initialize ret to the __pm_runtime_resume() return value right away. > + > + ret = __pm_runtime_resume(dev, RPM_GET_PUT); > + if (ret < 0) { > + pm_runtime_put_noidle(dev); > + return ret; > + } > + > + return 0; > +} > + > /** > * pm_runtime_put - Drop device usage counter and queue up "idle check" if 0. > * @dev: Target device. > --