From patchwork Thu Sep 24 11:04:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 313459 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp115480ilg; Thu, 24 Sep 2020 04:06:14 -0700 (PDT) X-Received: by 2002:a19:8bc2:: with SMTP id n185mr91428lfd.211.1600945574815; Thu, 24 Sep 2020 04:06:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600945574; cv=none; d=google.com; s=arc-20160816; b=Rsru4T3ObspbNqMgkQvBdNtu0Dgs09+RgNnSQ037m0Y2EPlg4xDYKs2f6XIMqSK00b 6Nh8dOp4bwlEWCkzgezrI8CZ4dU/SL/PYRfTld/yGuoP6SnNMlNXcjRu4eumsBCjIgrd jFgfq6Z7MyWfypDK2MKBiqZfZrIEiJNYkoVz3k3FUWOWTR94gEf76DIoqTgq282qo19w yxGxU/NN6l/2wf8EucGxz4T9E9S/c2tKP/Bk86IGwoGmjLxcJOrMNInYn1CVvwm6UDrv 8POE93qtxykKn9dXQfJO2lm3m/cRyZ+7CEzBTARW9UQFYybZ2sUCnwAtG5keIud4C6Tg 2mng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=rLopvQrJpLUDqmj8LU9atUffkZGt0vm6zsb0hp7AK58=; b=uWoisy4s9RnDdnbsqLzhZ1JFwdB8GSnMrWKL3UFVDJaRpgw9OImpE5Aw+7fmXKJZpK ugJ/Wptzft/lCNlAnykk8Gr63MUw7MchhLkMIosxnNKi9pSVo2v1ik5jEVwkZzw0YrNc aHV1o2T1++tX5BQxusRrK3Dc0EyCBkGcg31LJFwUSUB/S8snw4Cb/Cj10+WDL87KNfRt HLWMyBdyx1qrw6+jGDX87k8MC8x8cWBsPLxFBepeFDSRFju5IbyE16Qv/d+U3souMKL2 yl29WjZbQUEh5a+tc5vLeBZlFMHWSXnEwLRtlSf32q6e5o/5FZR3jt7zXkHHKOvOdhA0 k8kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wvcRRsSv; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c11sor582742ljd.16.2020.09.24.04.06.14 for (Google Transport Security); Thu, 24 Sep 2020 04:06:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wvcRRsSv; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rLopvQrJpLUDqmj8LU9atUffkZGt0vm6zsb0hp7AK58=; b=wvcRRsSvhqV6/9Q6s7YiZ+xs12EtQc5ccJUikKs3Qu4pVZqzgGRQ4eRGNt3NyG4jZS vz2iWC8lkiFCM0Kb/P+XhVsxQTCJNTZ0tEVw5eGWvJZG6IvzU1BOfH9Twnj6HprWuz1n t8vqUn2XuKlu2hYk0V5YEpT9MuEznOXCNfdx5Yfg6zUrjFXKxJ3BZe3z0VKO2k2MsNrL cvD0ksN/Ldr8fnidbDytW6HYMCIjNlHUvCUlsJ0XoFVytbCe8/cE1PSCfxsM78isRuic 9+C9kBeTglf981ThomRSgdEk8kL18qVvyEQWMf6BwJ4h2AC+BiIvZg5mW4InypZY3d5Y tlog== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=rLopvQrJpLUDqmj8LU9atUffkZGt0vm6zsb0hp7AK58=; b=GKbvKvwnfTaXmrxWfGV5OcTPioaG0RpkzMBk731ptR9MJaPJC4Y+KZhDgduCDD83Xo hLHDMfNg9mWHIHwznP95R4IznPDtLVzrgIicnSnmpVSaHeUMLuDYEvKJXEPGeWuIKiBm gTRojpSjeqhiahBWJgE+6cUTdgMVwSiIXl1Va/804ggEgsZcZSbKCNVgRd8eA5MlSXTS bWldUW8eGICKWJ121QfYCfbvuxWInRBx1LNCZGRJHpNm3Kz6DdV616eLiMj0b48G+N8W AgLMuBKez7Pp+sMJL6iB8I0bpmzcNPQgfaO2TVIZOcho0s7B2DIXV7qyXpmhoNi370J3 F4SA== X-Gm-Message-State: AOAM532QiMfhNaZ0jvWxY1rKt5x5KOW9+q9F7p4Cvg2yrl1+IzBZ3BUY 4TM6GI52Y7s5T3K9wj+uRbk5F+8wIrbwqE7XIZE= X-Google-Smtp-Source: ABdhPJxXyCts6JOnHefb+CB97QTvaVZVj9HjBW9bsIXEL3WVQlR11HP3SjW8xg9SLfHQFjDh9Asd9A== X-Received: by 2002:a05:651c:32e:: with SMTP id b14mr144247ljp.314.1600945574405; Thu, 24 Sep 2020 04:06:14 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-133-169.NA.cust.bahnhof.se. [155.4.133.169]) by smtp.gmail.com with ESMTPSA id w4sm1762393lfr.139.2020.09.24.04.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:06:13 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Kevin Hilman , linux-pm@vger.kernel.org Cc: Sudeep Holla , Lorenzo Pieralisi , Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] PM / Domains: Rename power state enums for genpd Date: Thu, 24 Sep 2020 13:04:47 +0200 Message-Id: <20200924110449.329523-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200924110449.329523-1-ulf.hansson@linaro.org> References: <20200924110449.329523-1-ulf.hansson@linaro.org> MIME-Version: 1.0 To clarify the code a bit, let's rename GPD_STATE_ACTIVE into GENPD_STATE_ON and GPD_STATE_POWER_OFF to GENPD_STATE_OFF. Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- drivers/base/power/domain.c | 33 ++++++++++++++++----------------- include/linux/pm_domain.h | 4 ++-- 2 files changed, 18 insertions(+), 19 deletions(-) -- 2.25.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 2cb5e04cf86c..23aa2feced77 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -123,7 +123,7 @@ static const struct genpd_lock_ops genpd_spin_ops = { #define genpd_lock_interruptible(p) p->lock_ops->lock_interruptible(p) #define genpd_unlock(p) p->lock_ops->unlock(p) -#define genpd_status_on(genpd) (genpd->status == GPD_STATE_ACTIVE) +#define genpd_status_on(genpd) (genpd->status == GENPD_STATE_ON) #define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE) #define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON) #define genpd_is_active_wakeup(genpd) (genpd->flags & GENPD_FLAG_ACTIVE_WAKEUP) @@ -222,7 +222,7 @@ static void genpd_update_accounting(struct generic_pm_domain *genpd) * out of off and so update the idle time and vice * versa. */ - if (genpd->status == GPD_STATE_ACTIVE) { + if (genpd->status == GENPD_STATE_ON) { int state_idx = genpd->state_idx; genpd->states[state_idx].idle_time = @@ -563,7 +563,7 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, return ret; } - genpd->status = GPD_STATE_POWER_OFF; + genpd->status = GENPD_STATE_OFF; genpd_update_accounting(genpd); list_for_each_entry(link, &genpd->child_links, child_node) { @@ -616,7 +616,7 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) if (ret) goto err; - genpd->status = GPD_STATE_ACTIVE; + genpd->status = GENPD_STATE_ON; genpd_update_accounting(genpd); return 0; @@ -961,7 +961,7 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, if (_genpd_power_off(genpd, false)) return; - genpd->status = GPD_STATE_POWER_OFF; + genpd->status = GENPD_STATE_OFF; list_for_each_entry(link, &genpd->child_links, child_node) { genpd_sd_counter_dec(link->parent); @@ -1007,8 +1007,7 @@ static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock, } _genpd_power_on(genpd, false); - - genpd->status = GPD_STATE_ACTIVE; + genpd->status = GENPD_STATE_ON; } /** @@ -1287,7 +1286,7 @@ static int genpd_restore_noirq(struct device *dev) * so make it appear as powered off to genpd_sync_power_on(), * so that it tries to power it on in case it was really off. */ - genpd->status = GPD_STATE_POWER_OFF; + genpd->status = GENPD_STATE_OFF; genpd_sync_power_on(genpd, true, 0); genpd_unlock(genpd); @@ -1777,7 +1776,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd, genpd->gov = gov; INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn); atomic_set(&genpd->sd_count, 0); - genpd->status = is_off ? GPD_STATE_POWER_OFF : GPD_STATE_ACTIVE; + genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON; genpd->device_count = 0; genpd->max_off_time_ns = -1; genpd->max_off_time_changed = true; @@ -2802,8 +2801,8 @@ static int genpd_summary_one(struct seq_file *s, struct generic_pm_domain *genpd) { static const char * const status_lookup[] = { - [GPD_STATE_ACTIVE] = "on", - [GPD_STATE_POWER_OFF] = "off" + [GENPD_STATE_ON] = "on", + [GENPD_STATE_OFF] = "off" }; struct pm_domain_data *pm_data; const char *kobj_path; @@ -2881,8 +2880,8 @@ static int summary_show(struct seq_file *s, void *data) static int status_show(struct seq_file *s, void *data) { static const char * const status_lookup[] = { - [GPD_STATE_ACTIVE] = "on", - [GPD_STATE_POWER_OFF] = "off" + [GENPD_STATE_ON] = "on", + [GENPD_STATE_OFF] = "off" }; struct generic_pm_domain *genpd = s->private; @@ -2895,7 +2894,7 @@ static int status_show(struct seq_file *s, void *data) if (WARN_ON_ONCE(genpd->status >= ARRAY_SIZE(status_lookup))) goto exit; - if (genpd->status == GPD_STATE_POWER_OFF) + if (genpd->status == GENPD_STATE_OFF) seq_printf(s, "%s-%u\n", status_lookup[genpd->status], genpd->state_idx); else @@ -2938,7 +2937,7 @@ static int idle_states_show(struct seq_file *s, void *data) ktime_t delta = 0; s64 msecs; - if ((genpd->status == GPD_STATE_POWER_OFF) && + if ((genpd->status == GENPD_STATE_OFF) && (genpd->state_idx == i)) delta = ktime_sub(ktime_get(), genpd->accounting_time); @@ -2961,7 +2960,7 @@ static int active_time_show(struct seq_file *s, void *data) if (ret) return -ERESTARTSYS; - if (genpd->status == GPD_STATE_ACTIVE) + if (genpd->status == GENPD_STATE_ON) delta = ktime_sub(ktime_get(), genpd->accounting_time); seq_printf(s, "%lld ms\n", ktime_to_ms( @@ -2984,7 +2983,7 @@ static int total_idle_time_show(struct seq_file *s, void *data) for (i = 0; i < genpd->state_count; i++) { - if ((genpd->status == GPD_STATE_POWER_OFF) && + if ((genpd->status == GENPD_STATE_OFF) && (genpd->state_idx == i)) delta = ktime_sub(ktime_get(), genpd->accounting_time); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index ee11502a575b..66f3c5d64d81 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -64,8 +64,8 @@ #define GENPD_FLAG_RPM_ALWAYS_ON (1U << 5) enum gpd_status { - GPD_STATE_ACTIVE = 0, /* PM domain is active */ - GPD_STATE_POWER_OFF, /* PM domain is off */ + GENPD_STATE_ON = 0, /* PM domain is on */ + GENPD_STATE_OFF, /* PM domain is off */ }; struct dev_power_governor { From patchwork Thu Sep 24 11:04:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 256710 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=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, 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 B773CC4727E for ; Thu, 24 Sep 2020 11:06:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E5F3239CF for ; Thu, 24 Sep 2020 11:06:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="H3Oho9fG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727517AbgIXLGe (ORCPT ); Thu, 24 Sep 2020 07:06:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727468AbgIXLGV (ORCPT ); Thu, 24 Sep 2020 07:06:21 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 520A0C0613CE for ; Thu, 24 Sep 2020 04:06:21 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id z19so3445301lfr.4 for ; Thu, 24 Sep 2020 04:06:21 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=gaTG8nB7urYK9rRS90jMgYPOQXnTJzMb/qGUVRNiFp8=; b=H3Oho9fGD6RyE7bc1Vbkj0h4ig5GO+l5hocswqpFb3dkMRdGklpkEO9eBeBB09TcZ9 dftfi52ZqomV7nQ5Jw4OENJNRUEafEY7gOz2sx2BWm9cKXHYJ3ewwEeGRbghiXv6jogt pq/UIkU9ZDJCvoaCwnFnveqJoBFTG0thF0oLs7pGD1AQss2M3HJgb8Sxn5yiuQodFhYQ hJ06vs873IdJJRlZHWgRr0oI3i4ffJ+zB+41wDaroaypmlaxB1CosR1jfIh3LdygOJ+e NyQtY3j5INzmct44KCjDtbRCFhjJPwVkl5ISX6mEJuMJa0p1tORTGhFUuRX7TYNJ50ZX vkRg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=gaTG8nB7urYK9rRS90jMgYPOQXnTJzMb/qGUVRNiFp8=; b=sOUOZvyTQ+dGTnzW1kAoYls/z5p1zcGc+eVqBdOOIuAG0Ee4n0HYrqcx8ayjqLN/oj kCa30uDxBRGhZlAyENIx5QH7n9GtOcZuUl814eJ/PLZHIz+d/dATK+y5fjVsy5bWqzS2 B7s3J8aSsjHwfB7M2w9nwOlkJ3nLPCWA5t1zvPyhD5xtJLVSpsLHTWqcb8TLyxTDe0KK rTKOusC8JNN0vGK+8YS8TkhPhJzXGAZmFv7Oy/XH35rX4VRESbD53s+3woGAH+nlTd+z ENanMocvWHnGhPmHZPGVs5BRvvwCT9UO+7ROLUH+pzTE4YHOtFc4to1e7wZBkfWdgDzi nI1g== X-Gm-Message-State: AOAM531dz+4UlBY5Wpo1zSeyxKDVoWVP7l93oFzkjNKlPjEIEziMr87n RaHHm4nP+RN7N4c+I45uJH3PJCZ7ewENsPOa X-Google-Smtp-Source: ABdhPJymetcRsIgXO87ErAfpmmQHrT9SqTFIGB3QpkJ315XgLg9UgC/VPtV4CqPurtYJMsiQe6O3rQ== X-Received: by 2002:a19:674f:: with SMTP id e15mr108526lfj.50.1600945579746; Thu, 24 Sep 2020 04:06:19 -0700 (PDT) Received: from localhost.localdomain (h-155-4-133-169.NA.cust.bahnhof.se. [155.4.133.169]) by smtp.gmail.com with ESMTPSA id w4sm1762393lfr.139.2020.09.24.04.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:06:18 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Kevin Hilman , linux-pm@vger.kernel.org Cc: Sudeep Holla , Lorenzo Pieralisi , Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] PM / Domains: Allow to abort power off when no ->power_off() callback Date: Thu, 24 Sep 2020 13:04:48 +0200 Message-Id: <20200924110449.329523-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200924110449.329523-1-ulf.hansson@linaro.org> References: <20200924110449.329523-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In genpd_power_off() we may decide to abort the power off of the PM domain, even beyond the point when the governor would accept it. The abort is done if it turns out that a child domain has been requested to be powered on, which means it's waiting for the lock of the parent to be released. However, the abort is currently only considered if the genpd in question has a ->power_off() callback assigned. This is unnecessary limiting, especially if the genpd would have a parent of its own. Let's remove the limitation and make the behaviour consistent. Signed-off-by: Ulf Hansson --- Changes in v2: - None. --- drivers/base/power/domain.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 23aa2feced77..0198af358503 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -497,6 +497,7 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, struct pm_domain_data *pdd; struct gpd_link *link; unsigned int not_suspended = 0; + int ret; /* * Do not try to power off the domain in the following situations: @@ -544,24 +545,13 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, if (!genpd->gov) genpd->state_idx = 0; - if (genpd->power_off) { - int ret; - - if (atomic_read(&genpd->sd_count) > 0) - return -EBUSY; + /* Don't power off, if a child domain is waiting to power on. */ + if (atomic_read(&genpd->sd_count) > 0) + return -EBUSY; - /* - * If sd_count > 0 at this point, one of the subdomains hasn't - * managed to call genpd_power_on() for the parent yet after - * incrementing it. In that case genpd_power_on() will wait - * for us to drop the lock, so we can call .power_off() and let - * the genpd_power_on() restore power for us (this shouldn't - * happen very often). - */ - ret = _genpd_power_off(genpd, true); - if (ret) - return ret; - } + ret = _genpd_power_off(genpd, true); + if (ret) + return ret; genpd->status = GENPD_STATE_OFF; genpd_update_accounting(genpd); From patchwork Thu Sep 24 11:04:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 313461 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp115579ilg; Thu, 24 Sep 2020 04:06:23 -0700 (PDT) X-Received: by 2002:ac2:489b:: with SMTP id x27mr125835lfc.242.1600945582758; Thu, 24 Sep 2020 04:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600945582; cv=none; d=google.com; s=arc-20160816; b=J+P9bO6v26zdZjmIbwuI1Du582Jt/QVXvTdwfVYRqRDfHVFnU8MmOBCJRLLcqvfWWr NzZ8dHkgIz1AhnZaaffzfVYy1MoGSerEhAc2mDFoO5uPfCJ1ozt0y/rSnsuHwWfeP3Zj x2NqFYW8U9p/CtkQe+/IjKOqpbHC3Jz9tJyW9BD2IIoVZmZNq+9NeYdengBj1t9xgzFE 7qDk5GEJUXsC4DxW2KDpEFGi/oo9cz+U1KZr6VFxMVytCmHLnxvBKluuQclMWLpTGlt6 fhXw6nRxJGZXxAp2zZknVsn0Dlu+MtoUnc+/pLqkfqw79L2ZYQsoaxWoYqyeZw1KQ0e5 eH0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=eAxfRIdJbGO7nz2FmPpJIl5UEIFSG/7HeLctBXhA9PY=; b=HXxQnsIb9eR+yUe3zBYo0rJRDjOr+ADbfzZTLv8AK7qb3I1LVs+EMgzEZ0U9hy2Q43 FqBdgct9/jPVw5W/diJbb/m++8njldRJukXxl4MHAjWWuBIYKl20rIIDC2Ywy1ZeJsXz DbZIDU1Ae7ZoE1VEj9iXPmIZUNZUYluKB75L/D7e39Sl1R+cTpUNEblOqMF9u08k4oRX 5FUYbcM4LuI0ERgUTwR4eBR5Qh+axUzPeXZaTKISih0AkCWw61efOAVxC9FeyrVvp2dB qvJTwLZ2c44enEPzxhiag1khf6udtwBB4NinBbVZ962HZ8TBfKE5XGuUu7tv9f90pL1G To0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xd2x+7jf; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id e16sor595188ljh.32.2020.09.24.04.06.22 for (Google Transport Security); Thu, 24 Sep 2020 04:06:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xd2x+7jf; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eAxfRIdJbGO7nz2FmPpJIl5UEIFSG/7HeLctBXhA9PY=; b=xd2x+7jffqo3IG1nC2Bh6YjiWXK6oQeUrj18f4UYn13yo1kDoEYZLXJQ7DzI31GdBM omhixxdIWqCLw/GR4uUzWinDwcjSdBW6Ip+GccLJ+LH0J3t1iaQ+G7JvvuRZ6/T85fFP koy/iazYUQa+iS7PobmSEnPYZk9lkcBJug7OsWP2+eozPAi7LXmTcaQwcSIev9hkci63 ++LGPo8uiWlJDUXxHztCp0zoL52Xc++ra+7+OhOYsVrVqo7lyHG1p4UlkcBd4rTMV5qV jZYkitBbmLG8zpIEMYVznb82woHzIA3PLUlc1yWpnE4DHRGXr7JAgaAElhfTkCbrQyiA UXFg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=eAxfRIdJbGO7nz2FmPpJIl5UEIFSG/7HeLctBXhA9PY=; b=Z0xyZb6GsMfDkDjPXYK/5CsXohw46PsVP6YId5RwYfWVzQb0i5hRmUPyTCRE4hosrc gfb8g24l4WxfJSMPZWCqpOBhoQoFk0bNzMleF9Yg2L0P+KdigEFUN4tz/G7NoQWcQAp0 0FueyFfVAA+Fhg683TA7QbsxPSh4mInxPl8cuVwT4Vq1MCV9keaogY7ZSd4HOidfHCrY iEakz3urWpfzBGgSXyqnwbf+y9+yMNNbeWuzyleeX26mA4KfCChRnP+Vp1lNMD1u7zyA Jnq0AlJqapflnfhPL/r0etUmAmrQcw5BBxwFKoGRqyKfBzgLF9+MHsS/MQCsHNdQnxWZ r4Uw== X-Gm-Message-State: AOAM5314tTLhNVkyC03qHtlCY0+P2f0p38ZMc/WDhEadypeA+KFMEWbM LyXSrhuHM7+CGqT9+NIH+ic4GIUJ X-Google-Smtp-Source: ABdhPJwpqdgNbpHQwGyumC6fGscyjxCmKxqGXHBdvb8Jnrdlfy/a3rsww4Votv4EU/TC8XrBncuG/g== X-Received: by 2002:a2e:9143:: with SMTP id q3mr147845ljg.253.1600945581946; Thu, 24 Sep 2020 04:06:21 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-133-169.NA.cust.bahnhof.se. [155.4.133.169]) by smtp.gmail.com with ESMTPSA id w4sm1762393lfr.139.2020.09.24.04.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 04:06:20 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Kevin Hilman , linux-pm@vger.kernel.org Cc: Sudeep Holla , Lorenzo Pieralisi , Daniel Lezcano , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Ulf Hansson , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] PM / Domains: Add support for PM domain on/off notifiers for genpd Date: Thu, 24 Sep 2020 13:04:49 +0200 Message-Id: <20200924110449.329523-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200924110449.329523-1-ulf.hansson@linaro.org> References: <20200924110449.329523-1-ulf.hansson@linaro.org> MIME-Version: 1.0 A device may have specific HW constraints that must be obeyed to, before its corresponding PM domain (genpd) can be powered off - and vice verse at power on. These constraints can't be managed through the regular runtime PM based deployment for a device, because the access pattern for it, isn't always request based. In other words, using the runtime PM callbacks to deal with the constraints doesn't work for these cases. For these reasons, let's instead add a PM domain power on/off notification mechanism to genpd. To add/remove a notifier for a device, the device must already have been attached to the genpd, which also means that it needs to be a part of the PM domain topology. To add/remove a notifier, let's introduce two genpd specific functions: - dev_pm_genpd_add|remove_notifier() Note that, to further clarify when genpd power on/off notifiers may be used, one can compare with the existing CPU_CLUSTER_PM_ENTER|EXIT notifiers. In the long run, the genpd power on/off notifiers should be able to replace them, but that requires additional genpd based platform support for the current users. Signed-off-by: Ulf Hansson --- Changes in v2: - Improved error handling from fired notifications, according to suggestions by Lina Iyer. --- drivers/base/power/domain.c | 142 ++++++++++++++++++++++++++++++++++-- include/linux/pm_domain.h | 15 ++++ 2 files changed, 152 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 0198af358503..f001ac6326fb 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -497,7 +497,7 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, struct pm_domain_data *pdd; struct gpd_link *link; unsigned int not_suspended = 0; - int ret; + int ret, nr_calls = 0; /* * Do not try to power off the domain in the following situations: @@ -545,13 +545,22 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, if (!genpd->gov) genpd->state_idx = 0; + /* Notify consumers that we are about to power off. */ + ret = __raw_notifier_call_chain(&genpd->power_notifiers, + GENPD_STATE_OFF, NULL, -1, &nr_calls); + ret = notifier_to_errno(ret); + if (ret) + goto busy; + /* Don't power off, if a child domain is waiting to power on. */ - if (atomic_read(&genpd->sd_count) > 0) - return -EBUSY; + if (atomic_read(&genpd->sd_count) > 0) { + ret = -EBUSY; + goto busy; + } ret = _genpd_power_off(genpd, true); if (ret) - return ret; + goto busy; genpd->status = GENPD_STATE_OFF; genpd_update_accounting(genpd); @@ -564,6 +573,12 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, } return 0; +busy: + if (nr_calls) + __raw_notifier_call_chain(&genpd->power_notifiers, + GENPD_STATE_ON, NULL, + nr_calls - 1, NULL); + return ret; } /** @@ -609,6 +624,9 @@ static int genpd_power_on(struct generic_pm_domain *genpd, unsigned int depth) genpd->status = GENPD_STATE_ON; genpd_update_accounting(genpd); + /* Inform consumers that we have powered on. */ + raw_notifier_call_chain(&genpd->power_notifiers, GENPD_STATE_ON, NULL); + return 0; err: @@ -938,6 +956,7 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, unsigned int depth) { struct gpd_link *link; + int err, nr_calls = 0; if (!genpd_status_on(genpd) || genpd_is_always_on(genpd)) return; @@ -948,8 +967,15 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, /* Choose the deepest state when suspending */ genpd->state_idx = genpd->state_count - 1; + + /* Notify consumers that we are about to power off. */ + err = __raw_notifier_call_chain(&genpd->power_notifiers, + GENPD_STATE_OFF, NULL, -1, &nr_calls); + if (notifier_to_errno(err)) + goto err; + if (_genpd_power_off(genpd, false)) - return; + goto err; genpd->status = GENPD_STATE_OFF; @@ -964,6 +990,13 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, if (use_lock) genpd_unlock(link->parent); } + + return; +err: + if (nr_calls) + __raw_notifier_call_chain(&genpd->power_notifiers, + GENPD_STATE_ON, NULL, + nr_calls - 1, NULL); } /** @@ -998,6 +1031,9 @@ static void genpd_sync_power_on(struct generic_pm_domain *genpd, bool use_lock, _genpd_power_on(genpd, false); genpd->status = GENPD_STATE_ON; + + /* Inform consumers that we have powered on. */ + raw_notifier_call_chain(&genpd->power_notifiers, GENPD_STATE_ON, NULL); } /** @@ -1592,6 +1628,101 @@ int pm_genpd_remove_device(struct device *dev) } EXPORT_SYMBOL_GPL(pm_genpd_remove_device); +/** + * dev_pm_genpd_add_notifier - Add a genpd power on/off notifier for @dev + * + * @dev: Device that should be associated with the notifier + * @nb: The notifier block to register + * + * Users may call this function to add a genpd power on/off notifier for an + * attached @dev. Only one notifier per device is allowed. The notifier is + * sent when genpd is powering on/off the PM domain. + * + * It is assumed that the user guarantee that the genpd wouldn't be detached + * while this routine is getting called. + * + * Returns 0 on success and negative error values on failures. + */ +int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb) +{ + struct generic_pm_domain *genpd; + struct generic_pm_domain_data *gpd_data; + int ret; + + genpd = dev_to_genpd_safe(dev); + if (!genpd) + return -ENODEV; + + if (WARN_ON(!dev->power.subsys_data || + !dev->power.subsys_data->domain_data)) + return -EINVAL; + + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); + if (gpd_data->power_nb) + return -EEXIST; + + genpd_lock(genpd); + ret = raw_notifier_chain_register(&genpd->power_notifiers, nb); + genpd_unlock(genpd); + + if (ret) { + dev_warn(dev, "failed to add notifier for PM domain %s\n", + genpd->name); + return ret; + } + + gpd_data->power_nb = nb; + return 0; +} +EXPORT_SYMBOL_GPL(dev_pm_genpd_add_notifier); + +/** + * dev_pm_genpd_remove_notifier - Remove a genpd power on/off notifier for @dev + * + * @dev: Device that is associated with the notifier + * + * Users may call this function to remove a genpd power on/off notifier for an + * attached @dev. + * + * It is assumed that the user guarantee that the genpd wouldn't be detached + * while this routine is getting called. + * + * Returns 0 on success and negative error values on failures. + */ +int dev_pm_genpd_remove_notifier(struct device *dev) +{ + struct generic_pm_domain *genpd; + struct generic_pm_domain_data *gpd_data; + int ret; + + genpd = dev_to_genpd_safe(dev); + if (!genpd) + return -ENODEV; + + if (WARN_ON(!dev->power.subsys_data || + !dev->power.subsys_data->domain_data)) + return -EINVAL; + + gpd_data = to_gpd_data(dev->power.subsys_data->domain_data); + if (!gpd_data->power_nb) + return -ENODEV; + + genpd_lock(genpd); + ret = raw_notifier_chain_unregister(&genpd->power_notifiers, + gpd_data->power_nb); + genpd_unlock(genpd); + + if (ret) { + dev_warn(dev, "failed to remove notifier for PM domain %s\n", + genpd->name); + return ret; + } + + gpd_data->power_nb = NULL; + return 0; +} +EXPORT_SYMBOL_GPL(dev_pm_genpd_remove_notifier); + static int genpd_add_subdomain(struct generic_pm_domain *genpd, struct generic_pm_domain *subdomain) { @@ -1762,6 +1893,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd, INIT_LIST_HEAD(&genpd->parent_links); INIT_LIST_HEAD(&genpd->child_links); INIT_LIST_HEAD(&genpd->dev_list); + RAW_INIT_NOTIFIER_HEAD(&genpd->power_notifiers); genpd_lock_init(genpd); genpd->gov = gov; INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 66f3c5d64d81..3b2b561ce846 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -112,6 +112,7 @@ struct generic_pm_domain { cpumask_var_t cpus; /* A cpumask of the attached CPUs */ int (*power_off)(struct generic_pm_domain *domain); int (*power_on)(struct generic_pm_domain *domain); + struct raw_notifier_head power_notifiers; /* Power on/off notifiers */ struct opp_table *opp_table; /* OPP table of the genpd */ unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd, struct dev_pm_opp *opp); @@ -178,6 +179,7 @@ struct generic_pm_domain_data { struct pm_domain_data base; struct gpd_timing_data td; struct notifier_block nb; + struct notifier_block *power_nb; int cpu; unsigned int performance_state; void *data; @@ -204,6 +206,8 @@ int pm_genpd_init(struct generic_pm_domain *genpd, struct dev_power_governor *gov, bool is_off); int pm_genpd_remove(struct generic_pm_domain *genpd); int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state); +int dev_pm_genpd_add_notifier(struct device *dev, struct notifier_block *nb); +int dev_pm_genpd_remove_notifier(struct device *dev); extern struct dev_power_governor simple_qos_governor; extern struct dev_power_governor pm_domain_always_on_gov; @@ -251,6 +255,17 @@ static inline int dev_pm_genpd_set_performance_state(struct device *dev, return -ENOTSUPP; } +static inline int dev_pm_genpd_add_notifier(struct device *dev, + struct notifier_block *nb) +{ + return -ENOTSUPP; +} + +static inline int dev_pm_genpd_remove_notifier(struct device *dev) +{ + return -ENOTSUPP; +} + #define simple_qos_governor (*(struct dev_power_governor *)(NULL)) #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) #endif