From patchwork Wed Jun 2 10:12:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 452488 Delivered-To: patches@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp429532jao; Wed, 2 Jun 2021 03:12:33 -0700 (PDT) X-Received: by 2002:ac2:5a0e:: with SMTP id q14mr10894784lfn.647.1622628753018; Wed, 02 Jun 2021 03:12:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622628753; cv=none; d=google.com; s=arc-20160816; b=o79hVilqRHUVmtP5Rwpc/oXchZOtywskrbkKFNB6dOC/dQu2s4gZR80/Ue0UFM+1x2 F9g4PN0NwGITDYr4Qbn1KU/h6i+hTst4kct4R0t6Bf8SVqBkW6SqDUJjFNG8sl2XpZKW z25UMAk9WyVfamT56N08UZGKVy8/INqCGFF2hAKIisOM2HwJ5WkJM7RxG4fmM8Rp2S/+ Po6rsvf6+NOCW/iTLfptrtuw3fjmUCRwOVhsurgvpRwLB3fNPhtLn8cvXMyXgw/2yfvx OUPXOfechPqd2p5hKzCVwMRO9r/KRy/e0g0IaSIQUxmZD8EKON8TUjX0+T2XSBNZ4LpP SnSA== 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=KSQ/Hhdv/geuNZerNpw5PmMWOOCJZ7RFgPSp5JORONg=; b=fYRtJru6duE2BjY19mSiGKCOTiUibWu02KZWw/XLgCC6v+sIUW7RwficQUIYy497di bMX8llTbmHrovIzSroaJPMMKfzZkfZhfNi6TD3CNuCb6bcDYmE62Dhnp6iEzH5FGX4+w NxJIkiLDOLGfZIA0mvs7qnPRzCjHt8AUM8Pm5Qi196+XZazqZSiTPK5xkn0aEg1q+YEO IV87pU4VvBjJtw55004itz7ktTbO/m9W24PQQjQGE+s12RRc1u3RkvW97ic7Igg/zE48 foXj6awgIQDlFnhIhodI2gaD7kaQcT2osssnTHk2MGqI17o+EfHNj4L8j5oyql0I5yWK kV8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IkG/6epN"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 10sor2129453lfo.16.2021.06.02.03.12.32 for (Google Transport Security); Wed, 02 Jun 2021 03:12:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IkG/6epN"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=KSQ/Hhdv/geuNZerNpw5PmMWOOCJZ7RFgPSp5JORONg=; b=IkG/6epNfEkZ1qT7vpb6Doka0wPZaljxQ/pa1Fi76aylVEMGZMdt0S46sfAP/7fNVM V81JWsEqBwjvDpbeGGqraXSw/dwEsUw3/rjoj+KWLwupUC9PYRuvScCpSJgCS5d38BeW eiaOvhiUuVhWtRpyTBcc/pKklqAJ01CqW8wxMWIjEHN9yh589IHdSmSzFsT5Iz9dvS3v I9BHqGMi32JjknuHwpUTdnvKbshxSx4xcl0QPfWnxmb2vYMi9DsIe5HAbMZvIZXb6k54 yuvcIir/0Di6lDsdfebIF/pphyfwC4IGrTbteJReNWa3kK5ks6VFyXkXHOEhsrvImyPW iV3A== 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=KSQ/Hhdv/geuNZerNpw5PmMWOOCJZ7RFgPSp5JORONg=; b=NrtF32NN1TMLUR3PVBIz6CKTEfDvTZZkyAAFRBREza6h2Gidfp/KCpGXG374xwS+vp pBudJ7qUnoY/EzDNVPdRTklvKlCqf2g3KQypsmubjGmISoLCbDxp+JOArpcGr5z47uj+ ckrQfRQYWSzcdt2u9CfvEFJVAZk42Jbr9evWCatUaHoSqwrwZWslZjVQf45d5Lx5nC04 ykj2p+6ljZAt7XamWsUlnU01S6io/34LCbXhr/MfVSGmx7F/T2MXcfSUaNbMHbAAKMBi TbRR5lgD92ENgCRePl7M9DYdhZfd0cTl6hiPiN3fPpTnIZ9FWMql8LNMGfAST6+r52Eu ZWHA== X-Gm-Message-State: AOAM531S6lZ1kc8y7UIfudge9QIJgtW6/OcMeNH/efzahTNMEX6qH973 JpKwcpW+w8ldQRP0mG4YEtsjXUmlXBvTrjzl2bM= X-Google-Smtp-Source: ABdhPJx2vFqeoY4uP0jDdYZn95EyK+JpOwpNLIysagQIHxDH0hKmm4tvud9jfcRlkruXAxUZYhrZvg== X-Received: by 2002:ac2:5237:: with SMTP id i23mr4873494lfl.22.1622628752661; Wed, 02 Jun 2021 03:12:32 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id y35sm1948938lfa.122.2021.06.02.03.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 03:12:31 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Viresh Kumar , linux-pm@vger.kernel.org Cc: Ulf Hansson , Dmitry Osipenko , Jonathan Hunter , Thierry Reding , Rajendra Nayak , Stephan Gerhold , Roja Rani Yarubandi , Bjorn Andersson , Vincent Guittot , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] PM: domains: Drop/restore performance state votes for devices at runtime PM Date: Wed, 2 Jun 2021 12:12:14 +0200 Message-Id: <20210602101215.78094-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602101215.78094-1-ulf.hansson@linaro.org> References: <20210602101215.78094-1-ulf.hansson@linaro.org> MIME-Version: 1.0 A subsystem/driver that need to manage OPPs for its device, should typically drop its vote for the OPP when the device becomes runtime suspended. In this way, the corresponding aggregation of the performance state votes that is managed in genpd for the attached PM domain, may find that the aggregated vote can be decreased. Hence, it may allow genpd to set the lower performance state for the PM domain, thus avoiding to waste energy. To accomplish this, typically a subsystem/driver would need to call dev_pm_opp_set_rate|opp() for its device from its ->runtime_suspend() callback, to drop the vote for the OPP. Accordingly, it needs another call to dev_pm_opp_set_rate|opp() to restore the vote for the OPP from its ->runtime_resume() callback. To avoid boilerplate code in subsystems/driver to deal with these things, let's instead manage this internally in genpd. Signed-off-by: Ulf Hansson --- drivers/base/power/domain.c | 21 +++++++++++++++++++-- include/linux/pm_domain.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index a3b6e751f366..81b9d4652b90 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -397,6 +397,18 @@ static int genpd_set_performance_state(struct device *dev, unsigned int state) return ret; } +static int genpd_drop_performance_state(struct device *dev) +{ + struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); + unsigned int prev_state; + + prev_state = gpd_data->performance_state; + if (prev_state && !genpd_set_performance_state(dev, 0)) + return prev_state; + + return 0; +} + /** * dev_pm_genpd_set_performance_state- Set performance state of device's power * domain. @@ -839,7 +851,8 @@ static int genpd_runtime_suspend(struct device *dev) { struct generic_pm_domain *genpd; bool (*suspend_ok)(struct device *__dev); - struct gpd_timing_data *td = &dev_gpd_data(dev)->td; + struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); + struct gpd_timing_data *td = &gpd_data->td; bool runtime_pm = pm_runtime_enabled(dev); ktime_t time_start; s64 elapsed_ns; @@ -896,6 +909,7 @@ static int genpd_runtime_suspend(struct device *dev) return 0; genpd_lock(genpd); + gpd_data->rpm_saved_pstate = genpd_drop_performance_state(dev); genpd_power_off(genpd, true, 0); genpd_unlock(genpd); @@ -913,7 +927,8 @@ static int genpd_runtime_suspend(struct device *dev) static int genpd_runtime_resume(struct device *dev) { struct generic_pm_domain *genpd; - struct gpd_timing_data *td = &dev_gpd_data(dev)->td; + struct generic_pm_domain_data *gpd_data = dev_gpd_data(dev); + struct gpd_timing_data *td = &gpd_data->td; bool runtime_pm = pm_runtime_enabled(dev); ktime_t time_start; s64 elapsed_ns; @@ -937,6 +952,8 @@ static int genpd_runtime_resume(struct device *dev) genpd_lock(genpd); ret = genpd_power_on(genpd, 0); + if (!ret && gpd_data->rpm_saved_pstate) + genpd_set_performance_state(dev, gpd_data->rpm_saved_pstate); genpd_unlock(genpd); if (ret) diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index dfcfbcecc34b..c3d6c15788a3 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -198,6 +198,7 @@ struct generic_pm_domain_data { struct notifier_block *power_nb; int cpu; unsigned int performance_state; + unsigned int rpm_saved_pstate; ktime_t next_wakeup; void *data; };