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=ham 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 05335C2D0A3 for ; Mon, 9 Nov 2020 15:54:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C335206D8 for ; Mon, 9 Nov 2020 15:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604937252; bh=mUqh2gUEyeY+Qbyqa4m7pgLF0tO/AG6xHYHeYRetCbg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=dfiQdCQK6nnI7/jRdiXl/w+2Pac12R7wb/N8GbCXBUtB0gRG6kfCDAZ4q1CF7Ut5p scFaQY8jQrJu21MGh4ijddsc5y6btDPcCjWavXL3FXDPFk7OncUg6SI6QbPg385zrS wNlat/XKJzIIAShujLDa+AVxLPt+CpofQQJFkB5s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729658AbgKIPyL (ORCPT ); Mon, 9 Nov 2020 10:54:11 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:37736 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729302AbgKIPyL (ORCPT ); Mon, 9 Nov 2020 10:54:11 -0500 Received: by mail-ot1-f65.google.com with SMTP id l36so9381062ota.4; Mon, 09 Nov 2020 07:54:09 -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=lKVvLVZefOAL5DWeQTQm2qn558EoCC4J5KNFm0S/6hs=; b=pMX4qjy6Y3mjzXZ89XpC4w/aXC3CuMebDWW7HyZKskwkfX7AMRs3If03voO4wRrMRa RJlEOhXsjHWD+rgjWHmKKfCCCjs0Tm2yDUYoO5IMCzav4uWFjDbm1H01xmLxRm7tAGcq uiUwrXy8bz/C+VNhIMEXs1TYHCHdsLn8frROlfj7C2Hcvd6b+jkJTXEjmAbQjIGuvMYX 7GEioFoMmjzl8YDuv+EFOaTHUcLwLDpFJ8PxLM78w6gGeoRm0nbP6DKNJsWf6zil161I XMB/HBKiqfpAxcMKuKLt7s8Vn5CFH5W9NE5nktDkX+z5vhNMj6gHp+Eh5NJ6ZAdKj+zy b6yw== X-Gm-Message-State: AOAM531Az/xRCU6wUV3SYfF3iqPpagd0icyhDR8V3wkqh1jjjQOeVZ+h AXkYHAlVtZ6T88NmXzqkP3fK70GRkX4/YNfcCpc= X-Google-Smtp-Source: ABdhPJzQBwdiGIpAMFtpH9CrblAwwoEPOFUQj9qJW2BETLPwj7y5RqhvN4Fbk/Q0zr5+AGvwBfiDIOhzX8LMVHkFoEY= X-Received: by 2002:a9d:171a:: with SMTP id i26mr11356995ota.260.1604937249238; Mon, 09 Nov 2020 07:54:09 -0800 (PST) MIME-Version: 1.0 References: <20201109150416.1877878-1-zhangqilong3@huawei.com> <20201109150416.1877878-2-zhangqilong3@huawei.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Mon, 9 Nov 2020 16:53:57 +0100 Message-ID: Subject: Re: [PATCH v2 1/2] PM: runtime: Add a general runtime get sync operation to deal with usage counter To: Ulf Hansson Cc: "Rafael J. Wysocki" , Zhang Qilong , "Rafael J. Wysocki" , Fugang Duan , 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:50 PM Ulf Hansson wrote: > > On Mon, 9 Nov 2020 at 16:20, Rafael J. Wysocki wrote: > > > > 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()? > > We already have pm_runtime_get_if_active() - so perhaps > pm_runtime_get_if_suspended() could be an option as well? It doesn't work this way, though. The "get" happens even if the device has not been suspended.