From patchwork Fri May 28 09:11:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12286449 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 08148C4708C for ; Fri, 28 May 2021 09:12:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6F126124C for ; Fri, 28 May 2021 09:12:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229911AbhE1JNa (ORCPT ); Fri, 28 May 2021 05:13:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235361AbhE1JN1 (ORCPT ); Fri, 28 May 2021 05:13:27 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2532EC061760 for ; Fri, 28 May 2021 02:11:53 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id a2so4276780lfc.9 for ; Fri, 28 May 2021 02:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sUYpUgduivuCVF6eHvNxAOyVhrifC73di+ff0lHlcsA=; b=wyZ4T5i+3aVchglrAZqFAVF0C6hOe/zQhiG/Y2DqaSz/q2fNL7xknah6KEG0xpQN3A qg34hQVg80hsXJnqaNIMyx+RpN/y8DQ41nGBEPG/xBJ8/N6MfM+4yG5VAI1iwDWtJ7IN vsdoma7Wxm/rhHsbi4rGtxG7lNuXCSDOXForFR1s6FEyAt+o5MJp4tps0GAuUyCiq25r yr0E0DXczvkGlrHEnEXfWRWJnuw3Mqo7iNaozOpvj5rllSI1mfflbG4RSybvt24L5Dro G3tKsOcQCYEmNN4QEe42/KZJa+zWf5t/d7Qt17qWGFIULkOsu0hVEJC9j5VCRTzildIH nTHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sUYpUgduivuCVF6eHvNxAOyVhrifC73di+ff0lHlcsA=; b=DSX1j8fbvDEEQviK5OA00UqbumhKUwcKahVhA8sbbbk5Mj8W9JKRZlTmUXN90NS3Dx oIDuz80wkXL1D5we6V49YWGgkg9mZaRBEMBRDfFwzGB7rqCyqWCKNtI18I0z2O71B+FB eFfrNlaLOIvQvreQ3dzsEMKxki0oN9Ym3G7en3+qMf/j6VjFWCZUA++/n3oNZtBPwCfv ghn4kvAARuRZzOm12YlwzMyJQfZPl3xRxa7GCThJ4ZtkPa1kAQUQM8qNiFvF5tPPkYVQ ZeXXvk8a7DgliCk75WPdWlnbc23E6/AcOvoG/2rEGzaGds1DNOUKLLufkmwBsKiLirJI 9C9A== X-Gm-Message-State: AOAM531WuVKLq8qy7d6XbzjYLpYKIKllDXF+43sLVP3WPLBiPLDUXhh5 G8pd7zi7QFPUwbKZJ28lW2SQbg== X-Google-Smtp-Source: ABdhPJwsVzF+nC4WNJPqBtVliQbqeg943XE0P+2MUBvV2a1tnubgAiDDFZnyk++mWwJZ3eEuHuTE4Q== X-Received: by 2002:ac2:4908:: with SMTP id n8mr5125093lfi.641.1622193111489; Fri, 28 May 2021 02:11:51 -0700 (PDT) Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id n15sm421927lfq.274.2021.05.28.02.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:11:50 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Saravana Kannan , Alan Stern , Adrian Hunter , Tony Lindgren , Kevin Hilman , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PM: runtime: Improve path in rpm_idle() when no callback Date: Fri, 28 May 2021 11:11:47 +0200 Message-Id: <20210528091147.11541-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When pm_runtime_no_callbacks() has been called for a struct device to set the dev->power.no_callbacks flag for it, it enables rpm_idle() to take a slightly quicker path by assuming that a ->runtime_idle() callback would have returned 0 to indicate success. A device that does not have the dev->power.no_callbacks flag set for it, may still be missing a corresponding ->runtime_idle() callback, in which case the slower path in rpm_idle() is taken. Let's improve the behaviour for this case, by aligning code to the quicker path. Signed-off-by: Ulf Hansson --- drivers/base/power/runtime.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index b570848d23e0..68bebbf81347 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -446,7 +446,10 @@ static int rpm_idle(struct device *dev, int rpmflags) /* Pending requests need to be canceled. */ dev->power.request = RPM_REQ_NONE; - if (dev->power.no_callbacks) + callback = RPM_GET_CALLBACK(dev, runtime_idle); + + /* If no callback assume success. */ + if (!callback || dev->power.no_callbacks) goto out; /* Carry out an asynchronous or a synchronous idle notification. */ @@ -462,10 +465,7 @@ static int rpm_idle(struct device *dev, int rpmflags) dev->power.idle_notification = true; - callback = RPM_GET_CALLBACK(dev, runtime_idle); - - if (callback) - retval = __rpm_callback(callback, dev); + retval = __rpm_callback(callback, dev); dev->power.idle_notification = false; wake_up_all(&dev->power.wait_queue); From patchwork Fri May 28 09:12:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12286451 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 C532EC4708C for ; Fri, 28 May 2021 09:12:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7FC9613EC for ; Fri, 28 May 2021 09:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235430AbhE1JNn (ORCPT ); Fri, 28 May 2021 05:13:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235422AbhE1JNm (ORCPT ); Fri, 28 May 2021 05:13:42 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0028C06174A for ; Fri, 28 May 2021 02:12:07 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id w33so4295904lfu.7 for ; Fri, 28 May 2021 02:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZB800bOhKFCGK6d7wDa9t/A1lZSI4wYj4YKflJqW4BE=; b=KlhgpHI6b5tTvVjNUp85mgiuuWggqNBSOcObUyi0mrUDSuH0/J9coPaxoqyBwaw9qK RDGeCgR8eODiassfVCSNeLmOyRUMFeid8Yd2LyGwWto6lydEIzcSGgSgXTe4/2PRJW71 CXBY4DZpHotaNtp7TMg/f57+OpBhzFCZDWicDleIh8Ijdey1ym7VFXViRzwojlW0gUjK sdcY27oD7qneN++kxIT1Atlis8+pgDdeeXS+VfZ7hQdqJO8PfLg1lx8vBtbIm1afRH0E QOQ+2yycLqX3/9bcWZUU5wNBncEx0hCGD9LiKoGKFadmS0jwTc39Ei8JtuQlxzhpWZOS dELQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZB800bOhKFCGK6d7wDa9t/A1lZSI4wYj4YKflJqW4BE=; b=bs1MZxQDeFfTJ6s42E4h+aP8qRJdio8dnmy92Pn7K53a2AzPlz5FeN1isrbb/PyumE uOAAuFqiJJmDRkllC3Mnn3G8GxtXKA+s0/6pFntM2uAYYTY+IOncYZyULCa9JhTAf4SC eWoe5G2uba2RMMcZtCIMSzonDDYGpMV2MJ3eE+CwEernYMuSHTqL8sNNX1PSZrWNeS8K 74xZ/YQlSBy12hYtDbVt2LRh6pBaXqrCIWNV78ov6R2FqCCf3eqnqlPHnKP/kE1FEf03 jRr7xWFyYr4IA26WC5O+tGPKYcCvhId3zIsZ4V+7ciAqLY85oboJJLIaIEzcRduwIgxD Us5A== X-Gm-Message-State: AOAM531nWJ137SbxWdCUoEF1EboO/LMeGZT6RkPNSWOQVNtYeRbdB5q3 edEkU79qSDOxYyeLUEsU8leBaQ== X-Google-Smtp-Source: ABdhPJw3cbp9c36WWL8oxcRJGQCUpv15fo/C/Ij+mnr+wRpiMSsA1kh7obLCs9cz7vWnAxlGRhBbrQ== X-Received: by 2002:ac2:598e:: with SMTP id w14mr5037682lfn.558.1622193126115; Fri, 28 May 2021 02:12:06 -0700 (PDT) Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id m4sm537061ljp.9.2021.05.28.02.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 May 2021 02:12:05 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , linux-pm@vger.kernel.org Cc: Ulf Hansson , Saravana Kannan , Alan Stern , Adrian Hunter , Tony Lindgren , Kevin Hilman , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] PM: runtime: Allow unassigned ->runtime_suspend|resume callbacks Date: Fri, 28 May 2021 11:12:02 +0200 Message-Id: <20210528091202.11603-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We are currently allowing ->rpm_idle() callbacks to be unassigned without returning an error code from rpm_idle(). This has been useful to avoid boilerplate code in drivers. Let's take this approach a step further, by allowing unassigned ->runtime_suspend|resume() callbacks as well. In this way, a consumer/supplier device link can be used to let a consumer device be power managed through its supplier device, without requiring assigned ->runtime_suspend|resume() callbacks for the consumer device, for example. Signed-off-by: Ulf Hansson --- drivers/base/power/runtime.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 68bebbf81347..8a66eaf731e4 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -345,7 +345,7 @@ static void rpm_suspend_suppliers(struct device *dev) static int __rpm_callback(int (*cb)(struct device *), struct device *dev) __releases(&dev->power.lock) __acquires(&dev->power.lock) { - int retval, idx; + int retval = 0, idx; bool use_links = dev->power.links_count > 0; if (dev->power.irq_safe) { @@ -373,7 +373,8 @@ static int __rpm_callback(int (*cb)(struct device *), struct device *dev) } } - retval = cb(dev); + if (cb) + retval = cb(dev); if (dev->power.irq_safe) { spin_lock(&dev->power.lock); @@ -484,9 +485,6 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev) { int retval; - if (!cb) - return -ENOSYS; - if (dev->power.memalloc_noio) { unsigned int noio_flag;