From patchwork Mon Jul 1 11:26:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 168204 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2802051ilk; Mon, 1 Jul 2019 04:26:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYm0dkKn0CVcIDZ6XtIVWeZu2RKfPpIdxe5Tpaa/iahQiVmEXAW5+HsAQn2OGR+4TM8/Hr X-Received: by 2002:a17:90a:cb81:: with SMTP id a1mr29785023pju.81.1561980392233; Mon, 01 Jul 2019 04:26:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561980392; cv=none; d=google.com; s=arc-20160816; b=VA9E22VowaV7K0sIF+Kw+Y330XG3bNvUXf47DtuvaLI2G71Z0jhTIi2Q2Bb2avgdea SEDs1uYPra3asvy30aiCiZjghhV9rvwp1nXvbKx7hF3vfOoPbOkv4rEZZ5x6IiyipbSz W7dUSEZVQpJZmNIBM5nj2gIKjSgEeo5oLMn3qhFkxA37qWfsVJfY4RSrEl6wWqg17dHC wOesubVHx/T0Qz6nTH+6Mkmb5N5gUs+IqOt7cyzNQh3ZbGPyiviiYPqlgPvohesfqZsk zYr1x/C8G1QypGoevFIuCqI1IAQp8HYPJlmteSd9yJ9STXfvA3+XJMCX/mliaEE3svrY baEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PlxocW5hWVYXfPkN8RZ8vxi1sxzrmOenQcvIcTZd5kM=; b=QuhmlXK9XYb6yU285X/VBruZ3f/C8k80PrYeA7v2xhsApf0i1d7LoDvunH+h98rzqK KhDsAJDuyG4daxSeH8DxBbdinMiC/UxQvu412ZuVSVWK7oSI/YUwoBr/0c+tFT2yeSb2 DkydPEfPg9FYZge2LpngIa7qF/Czt0zDd3imGDbRFCchrzLkNbgNarUOjXhE9yj5xVa9 iM6pfUn+Df0I4eYuMThqhvmdKk6AeZ4gYPBzednZa+JawUXQZIiA5nmarAjvMJDDiL3o U/trVg2/krBUOqL2O2WRibk+cM74BNVfF/LAYGohbem1liu0LsM6aR3NxWL01cEi4WCg BPGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XUamftty; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7si10868394pfr.145.2019.07.01.04.26.31; Mon, 01 Jul 2019 04:26:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XUamftty; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728473AbfGAL0a (ORCPT + 11 others); Mon, 1 Jul 2019 07:26:30 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45632 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728441AbfGAL0a (ORCPT ); Mon, 1 Jul 2019 07:26:30 -0400 Received: by mail-pg1-f195.google.com with SMTP id o13so1414200pgp.12 for ; Mon, 01 Jul 2019 04:26:30 -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=PlxocW5hWVYXfPkN8RZ8vxi1sxzrmOenQcvIcTZd5kM=; b=XUamfttyP80qdspJgf1uIrYuYqNj/n0X1CzPBvPz4mMVT/y51sj6kZS6OMaVHEigV0 AWHBSQtCgD6fzdYqfjQ4vQ5+CSxugvayzemLhR5nad63DIF2NZptTU7b3vY/IAsf4Kqh qaL7GgFhQfaCU/UQ6zPKAYk0JZpem/ygA+1PtSJumre9Jf0FyXphj6sUSAmM7jrpd8zo ra/51juPWGNEtGpCyxWs4AggISzIwaTywOYJHN26VS+B4tS8k5b1ooEwWHnscsmtlpDN zu3qVHaTP20si2JQVegs0PzPnBAsBoSoV1Jc12R516XJNpRs2qPPMmGz5lgMahUGQTas 8Q5g== 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=PlxocW5hWVYXfPkN8RZ8vxi1sxzrmOenQcvIcTZd5kM=; b=DXO7sGpTNOdbO84qKWKbBOC+NNpBNT/DagqZnxeW0Duv9mxUbL1fnRySK7oLcqV37m 4PHT04qaR+qML6kphwX6rDWg6QdILN7MiqG0b0o/5MiZ1Q/LHDRbBWUMsnN7423fyIa7 HUyESOeTdqD3X7CPYMK/kvdk0vQdYCwb/Wh+AHIU+7n4qi0kBgTli4NuW534btfROC86 sYObZ8B1wDo++3lWQm2l4Vv/95OMR2XHTAxST744NlhYvvPkG+3wRySMTf9N8Q1yw185 6u9t6g7c/orTNk4JBKlyxYSzjzzPMrItQS5tBoGAXhoxIZjnZM8A6uj2NlJZ6DJzv++v WLnQ== X-Gm-Message-State: APjAAAWJtc2mI1WoMjRdDIJUkxyJGwbSlgsS2OkfrSoV/E7+mm0C3Onh r3Mpu4s5dFOeBT2kuIsT9gsm5w== X-Received: by 2002:a65:62c2:: with SMTP id m2mr24639022pgv.413.1561980389387; Mon, 01 Jul 2019 04:26:29 -0700 (PDT) Received: from localhost ([122.172.21.205]) by smtp.gmail.com with ESMTPSA id m4sm19139569pff.108.2019.07.01.04.26.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jul 2019 04:26:28 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Kevin Hilman , Ulf Hansson , Len Brown , Pavel Machek , Daniel Lezcano Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Qais.Yousef@arm.com, mka@chromium.org, juri.lelli@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH V5 2/7] PM / QOS: Rename __dev_pm_qos_read_value() and dev_pm_qos_raw_read_value() Date: Mon, 1 Jul 2019 16:56:10 +0530 Message-Id: <5c38b4a94f5114bbc99f62d89d4c09f877194dc7.1561979715.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org dev_pm_qos_read_value() will soon need to support more constraint types (min/max frequency) and will have another argument to it, i.e. type of the constraint. While that is fine for the existing users of dev_pm_qos_read_value(), but not that optimal for the callers of __dev_pm_qos_read_value() and dev_pm_qos_raw_read_value() as all the callers of these two routines are only looking for resume latency constraint. Lets make these two routines care only about the resume latency constraint and rename them to __dev_pm_qos_resume_latency() and dev_pm_qos_raw_resume_latency(). Suggested-by: Rafael J. Wysocki Signed-off-by: Viresh Kumar --- drivers/base/power/domain_governor.c | 2 +- drivers/base/power/qos.c | 13 +++++++++---- drivers/base/power/runtime.c | 2 +- drivers/cpuidle/governor.c | 2 +- include/linux/pm_qos.h | 8 ++++---- 5 files changed, 16 insertions(+), 11 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c index 3838045c9277..20e56a5be01f 100644 --- a/drivers/base/power/domain_governor.c +++ b/drivers/base/power/domain_governor.c @@ -66,7 +66,7 @@ static bool default_suspend_ok(struct device *dev) td->constraint_changed = false; td->cached_suspend_ok = false; td->effective_constraint_ns = 0; - constraint_ns = __dev_pm_qos_read_value(dev); + constraint_ns = __dev_pm_qos_resume_latency(dev); spin_unlock_irqrestore(&dev->power.lock, flags); diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index cfd463212513..7a0d197f0809 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -90,16 +90,16 @@ enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask) EXPORT_SYMBOL_GPL(dev_pm_qos_flags); /** - * __dev_pm_qos_read_value - Get PM QoS constraint for a given device. + * __dev_pm_qos_resume_latency - Get resume latency constraint for a given device. * @dev: Device to get the PM QoS constraint value for. * * This routine must be called with dev->power.lock held. */ -s32 __dev_pm_qos_read_value(struct device *dev) +s32 __dev_pm_qos_resume_latency(struct device *dev) { lockdep_assert_held(&dev->power.lock); - return dev_pm_qos_raw_read_value(dev); + return dev_pm_qos_raw_resume_latency(dev); } /** @@ -112,7 +112,12 @@ s32 dev_pm_qos_read_value(struct device *dev) s32 ret; spin_lock_irqsave(&dev->power.lock, flags); - ret = __dev_pm_qos_read_value(dev); + + if (IS_ERR_OR_NULL(dev->power.qos)) + ret = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; + else + ret = pm_qos_read_value(&dev->power.qos->resume_latency); + spin_unlock_irqrestore(&dev->power.lock, flags); return ret; diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 952a1e7057c7..b75335508d2c 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -275,7 +275,7 @@ static int rpm_check_suspend_allowed(struct device *dev) || (dev->power.request_pending && dev->power.request == RPM_REQ_RESUME)) retval = -EAGAIN; - else if (__dev_pm_qos_read_value(dev) == 0) + else if (__dev_pm_qos_resume_latency(dev) == 0) retval = -EPERM; else if (dev->power.runtime_status == RPM_SUSPENDED) retval = 1; diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c index 9fddf828a76f..2e3e14192bee 100644 --- a/drivers/cpuidle/governor.c +++ b/drivers/cpuidle/governor.c @@ -110,7 +110,7 @@ int cpuidle_governor_latency_req(unsigned int cpu) { int global_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); struct device *device = get_cpu_device(cpu); - int device_req = dev_pm_qos_raw_read_value(device); + int device_req = dev_pm_qos_raw_resume_latency(device); return device_req < global_req ? device_req : global_req; } diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h index 1f4d456e8fff..06aa88496761 100644 --- a/include/linux/pm_qos.h +++ b/include/linux/pm_qos.h @@ -139,7 +139,7 @@ s32 pm_qos_read_value(struct pm_qos_constraints *c); #ifdef CONFIG_PM enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, s32 mask); enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask); -s32 __dev_pm_qos_read_value(struct device *dev); +s32 __dev_pm_qos_resume_latency(struct device *dev); s32 dev_pm_qos_read_value(struct device *dev); int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req, enum dev_pm_qos_req_type type, s32 value); @@ -176,7 +176,7 @@ static inline s32 dev_pm_qos_requested_flags(struct device *dev) return dev->power.qos->flags_req->data.flr.flags; } -static inline s32 dev_pm_qos_raw_read_value(struct device *dev) +static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev) { return IS_ERR_OR_NULL(dev->power.qos) ? PM_QOS_RESUME_LATENCY_NO_CONSTRAINT : @@ -189,7 +189,7 @@ static inline enum pm_qos_flags_status __dev_pm_qos_flags(struct device *dev, static inline enum pm_qos_flags_status dev_pm_qos_flags(struct device *dev, s32 mask) { return PM_QOS_FLAGS_UNDEFINED; } -static inline s32 __dev_pm_qos_read_value(struct device *dev) +static inline s32 __dev_pm_qos_resume_latency(struct device *dev) { return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; } static inline s32 dev_pm_qos_read_value(struct device *dev) { return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; } @@ -245,7 +245,7 @@ static inline s32 dev_pm_qos_requested_resume_latency(struct device *dev) return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; } static inline s32 dev_pm_qos_requested_flags(struct device *dev) { return 0; } -static inline s32 dev_pm_qos_raw_read_value(struct device *dev) +static inline s32 dev_pm_qos_raw_resume_latency(struct device *dev) { return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; } From patchwork Mon Jul 1 11:26:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 168206 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2802140ilk; Mon, 1 Jul 2019 04:26:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8Sl6RICsze79X7R5gi3lJOQmwsFlwxrW2nqniyrhzS5cTAjedVy7B0NqkQe/LMXPTEEUF X-Received: by 2002:a17:90a:4f0e:: with SMTP id p14mr29606492pjh.40.1561980397538; Mon, 01 Jul 2019 04:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561980397; cv=none; d=google.com; s=arc-20160816; b=up/LtJ2nBzcOG3zcFWxUm4A8REycJcCQ60E36KU4CLM/X1DoBUnsaraaSrdrApuu1m cOzC8PEUYkgoSR2db8Bl/tSvacy/j3MoJL78JsGtINeFmxnll9T8xmq6dwkz5bxh478j 9VEiFtarfbkzKVnPy6Ga87p778sD/ltu16eUEmZ2vAellV38VVNSIvWlh4wxlR5be/+s 4hIJWHh3wPPwsh2cDASMkF6RAI+HFW6DD+xIex6OJ551fHwzrIIB0+K7tBBIQfgK+irU PjKF6Heso4mAfV2USJHrL/Yy8tux0/fV6sJgThjscdUXlsnprfPfFhfVbg4kiT8gD8kW aEYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iLaNaNEqpEZ8RJPh9tk4QDLad7h0DvU5BxSRq4ruwcY=; b=jDm9Kt2NfUVUfWi8675ElUSQMhByKKiW2YsfezXoozHPEMVkS63SdjssCq/BaUjf2Q y7v4PGP7flILfUQ0J3I5YnZEpTaCz2uT3g7VJvFpqPZu7EmEipgVV7q4imPkA1JBKxHk L3VWR3UJULZoO73KRH2JKD1WSkZP+dJIr12d4x1j78jYBRIN9RyN7c++0ZQysIyIfetv ZFqBIGlh6pCIYlKGjmhdPTQFILklBmQPGlHz9rs0lXJF/UXuTtCtjo+1gnXzagFUEgM7 FYFrUEa1jKrzi+L+CLiGSdtcyl5qd+oTQxnmx3TibIlYHjhVoLKqqSAkmaE842uXEQfd W9UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JKPg1fm6; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1si10317541plb.337.2019.07.01.04.26.37; Mon, 01 Jul 2019 04:26:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JKPg1fm6; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728517AbfGAL0g (ORCPT + 11 others); Mon, 1 Jul 2019 07:26:36 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43351 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728554AbfGAL0g (ORCPT ); Mon, 1 Jul 2019 07:26:36 -0400 Received: by mail-pl1-f194.google.com with SMTP id cl9so7192884plb.10 for ; Mon, 01 Jul 2019 04:26:36 -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=iLaNaNEqpEZ8RJPh9tk4QDLad7h0DvU5BxSRq4ruwcY=; b=JKPg1fm6KZpvTiEccwD1i3ZtTOusbf0ulctUqmPcTV0XxU9RvrSlRYlcmAXovCYvMc ydswYHkOgWMMKgvfXBf6hCXPp+66/9WTqTURLUBAjxgiSVEF67KiD68sVAAGBQw2hb9L eDG64fc5BE0j+9byHAMhgifSjhmLVUN8RDLgyZ6pzzwQq4o+5mYP+IqNLKjlgxV8J6Is DRufAQNQg7mAqfZK3QAQd1Ajdrav7D9ybBY/Ihu2kupBc1OUCrE/qo8NZpn4E7LcEx9R k7FrvYDRU7kwu+Cmw7BSomknmNrBZm0YQL4Dao+CRqX5F2g9wRFVxWpY4MyVnQiChnfM W18w== 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=iLaNaNEqpEZ8RJPh9tk4QDLad7h0DvU5BxSRq4ruwcY=; b=XwliU0kQQdShH8HgXrEtN7vGfJxI4jFI3Jg3FnrAxJTaOeFI8WmLQXorPB3Iw9/77a b0ZKRxoWtqd5pC1plb3si4ytAYTQXT1/okAfaGwG0XQEaiGjiVhaoQE/1kWOqEvBNugH OMMYLIPiHq3iP9ombXDQHRlu2d3+jviz1z4KPgy22VwBHMu2UgBsOOmG3hOPbwamygrs iTjZsbKtKZBQzSobJ+wWlaYM9rzrgoxyYQ6YKs1tusDpZSJS9cUk/tb8iBktoE6uTswZ I5W/ta04CedLCLF2zbWel/s0RoWydkOiJdolhN0VSmluOPzOB88uYV+Ny3iKYkEMkTHs d42A== X-Gm-Message-State: APjAAAV9Rl5uuiAdXGfGqTj7klOcCMT2607UbY7UE1ceW7GC/UQLQq4K xkl1opIEQBHdtu0QJpcNZIalTA== X-Received: by 2002:a17:902:a03:: with SMTP id 3mr28187530plo.302.1561980395608; Mon, 01 Jul 2019 04:26:35 -0700 (PDT) Received: from localhost ([122.172.21.205]) by smtp.gmail.com with ESMTPSA id b5sm26091351pga.72.2019.07.01.04.26.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jul 2019 04:26:35 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Len Brown , Pavel Machek Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Qais.Yousef@arm.com, mka@chromium.org, juri.lelli@gmail.com, Ulf Hansson , linux-kernel@vger.kernel.org Subject: [PATCH V5 4/7] PM / QoS: Add support for MIN/MAX frequency constraints Date: Mon, 1 Jul 2019 16:56:12 +0530 Message-Id: <274abd14ec4c68c06fb2b4a366a172e34f0e686e.1561979715.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This patch introduces the min-frequency and max-frequency device constraints, which will be used by the cpufreq core to begin with. Reviewed-by: Matthias Kaehlcke Reviewed-by: Ulf Hansson Signed-off-by: Viresh Kumar --- drivers/base/power/qos.c | 111 ++++++++++++++++++++++++++++++++++----- include/linux/pm_qos.h | 12 +++++ 2 files changed, 109 insertions(+), 14 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index 2461fed0efa0..6c90fd7e2ff8 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -120,6 +120,14 @@ s32 dev_pm_qos_read_value(struct device *dev, enum dev_pm_qos_req_type type) ret = IS_ERR_OR_NULL(qos) ? PM_QOS_RESUME_LATENCY_NO_CONSTRAINT : pm_qos_read_value(&qos->resume_latency); break; + case DEV_PM_QOS_MIN_FREQUENCY: + ret = IS_ERR_OR_NULL(qos) ? PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE + : pm_qos_read_value(&qos->min_frequency); + break; + case DEV_PM_QOS_MAX_FREQUENCY: + ret = IS_ERR_OR_NULL(qos) ? PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE + : pm_qos_read_value(&qos->max_frequency); + break; default: WARN_ON(1); ret = 0; @@ -161,6 +169,14 @@ static int apply_constraint(struct dev_pm_qos_request *req, req->dev->power.set_latency_tolerance(req->dev, value); } break; + case DEV_PM_QOS_MIN_FREQUENCY: + ret = pm_qos_update_target(&qos->min_frequency, + &req->data.pnode, action, value); + break; + case DEV_PM_QOS_MAX_FREQUENCY: + ret = pm_qos_update_target(&qos->max_frequency, + &req->data.pnode, action, value); + break; case DEV_PM_QOS_FLAGS: ret = pm_qos_update_flags(&qos->flags, &req->data.flr, action, value); @@ -189,12 +205,11 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) if (!qos) return -ENOMEM; - n = kzalloc(sizeof(*n), GFP_KERNEL); + n = kzalloc(3 * sizeof(*n), GFP_KERNEL); if (!n) { kfree(qos); return -ENOMEM; } - BLOCKING_INIT_NOTIFIER_HEAD(n); c = &qos->resume_latency; plist_head_init(&c->list); @@ -203,6 +218,7 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) c->no_constraint_value = PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; c->type = PM_QOS_MIN; c->notifiers = n; + BLOCKING_INIT_NOTIFIER_HEAD(n); c = &qos->latency_tolerance; plist_head_init(&c->list); @@ -211,6 +227,24 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) c->no_constraint_value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT; c->type = PM_QOS_MIN; + c = &qos->min_frequency; + plist_head_init(&c->list); + c->target_value = PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE; + c->default_value = PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE; + c->no_constraint_value = PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE; + c->type = PM_QOS_MAX; + c->notifiers = ++n; + BLOCKING_INIT_NOTIFIER_HEAD(n); + + c = &qos->max_frequency; + plist_head_init(&c->list); + c->target_value = PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE; + c->default_value = PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE; + c->no_constraint_value = PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE; + c->type = PM_QOS_MIN; + c->notifiers = ++n; + BLOCKING_INIT_NOTIFIER_HEAD(n); + INIT_LIST_HEAD(&qos->flags.list); spin_lock_irq(&dev->power.lock); @@ -264,11 +298,25 @@ void dev_pm_qos_constraints_destroy(struct device *dev) apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE); memset(req, 0, sizeof(*req)); } + c = &qos->latency_tolerance; plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) { apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE); memset(req, 0, sizeof(*req)); } + + c = &qos->min_frequency; + plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) { + apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE); + memset(req, 0, sizeof(*req)); + } + + c = &qos->max_frequency; + plist_for_each_entry_safe(req, tmp, &c->list, data.pnode) { + apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE); + memset(req, 0, sizeof(*req)); + } + f = &qos->flags; list_for_each_entry_safe(req, tmp, &f->list, data.flr.node) { apply_constraint(req, PM_QOS_REMOVE_REQ, PM_QOS_DEFAULT_VALUE); @@ -380,6 +428,8 @@ static int __dev_pm_qos_update_request(struct dev_pm_qos_request *req, switch(req->type) { case DEV_PM_QOS_RESUME_LATENCY: case DEV_PM_QOS_LATENCY_TOLERANCE: + case DEV_PM_QOS_MIN_FREQUENCY: + case DEV_PM_QOS_MAX_FREQUENCY: curr_value = req->data.pnode.prio; break; case DEV_PM_QOS_FLAGS: @@ -492,9 +542,6 @@ int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier, { int ret = 0; - if (WARN_ON(type != DEV_PM_QOS_RESUME_LATENCY)) - return -EINVAL; - mutex_lock(&dev_pm_qos_mtx); if (IS_ERR(dev->power.qos)) @@ -502,10 +549,28 @@ int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier, else if (!dev->power.qos) ret = dev_pm_qos_constraints_allocate(dev); - if (!ret) + if (ret) + goto unlock; + + switch (type) { + case DEV_PM_QOS_RESUME_LATENCY: ret = blocking_notifier_chain_register(dev->power.qos->resume_latency.notifiers, notifier); + break; + case DEV_PM_QOS_MIN_FREQUENCY: + ret = blocking_notifier_chain_register(dev->power.qos->min_frequency.notifiers, + notifier); + break; + case DEV_PM_QOS_MAX_FREQUENCY: + ret = blocking_notifier_chain_register(dev->power.qos->max_frequency.notifiers, + notifier); + break; + default: + WARN_ON(1); + ret = -EINVAL; + } +unlock: mutex_unlock(&dev_pm_qos_mtx); return ret; } @@ -526,20 +591,35 @@ int dev_pm_qos_remove_notifier(struct device *dev, struct notifier_block *notifier, enum dev_pm_qos_req_type type) { - int retval = 0; - - if (WARN_ON(type != DEV_PM_QOS_RESUME_LATENCY)) - return -EINVAL; + int ret = 0; mutex_lock(&dev_pm_qos_mtx); /* Silently return if the constraints object is not present. */ - if (!IS_ERR_OR_NULL(dev->power.qos)) - retval = blocking_notifier_chain_unregister(dev->power.qos->resume_latency.notifiers, - notifier); + if (IS_ERR_OR_NULL(dev->power.qos)) + goto unlock; + + switch (type) { + case DEV_PM_QOS_RESUME_LATENCY: + ret = blocking_notifier_chain_unregister(dev->power.qos->resume_latency.notifiers, + notifier); + break; + case DEV_PM_QOS_MIN_FREQUENCY: + ret = blocking_notifier_chain_unregister(dev->power.qos->min_frequency.notifiers, + notifier); + break; + case DEV_PM_QOS_MAX_FREQUENCY: + ret = blocking_notifier_chain_unregister(dev->power.qos->max_frequency.notifiers, + notifier); + break; + default: + WARN_ON(1); + ret = -EINVAL; + } +unlock: mutex_unlock(&dev_pm_qos_mtx); - return retval; + return ret; } EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier); @@ -599,6 +679,9 @@ static void __dev_pm_qos_drop_user_request(struct device *dev, req = dev->power.qos->flags_req; dev->power.qos->flags_req = NULL; break; + default: + WARN_ON(1); + return; } __dev_pm_qos_remove_request(req); kfree(req); diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h index 5ce1c310373e..17132b10b233 100644 --- a/include/linux/pm_qos.h +++ b/include/linux/pm_qos.h @@ -40,6 +40,8 @@ enum pm_qos_flags_status { #define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT PM_QOS_LATENCY_ANY #define PM_QOS_RESUME_LATENCY_NO_CONSTRAINT_NS PM_QOS_LATENCY_ANY_NS #define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE 0 +#define PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE 0 +#define PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE (-1) #define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT (-1) #define PM_QOS_FLAG_NO_POWER_OFF (1 << 0) @@ -58,6 +60,8 @@ struct pm_qos_flags_request { enum dev_pm_qos_req_type { DEV_PM_QOS_RESUME_LATENCY = 1, DEV_PM_QOS_LATENCY_TOLERANCE, + DEV_PM_QOS_MIN_FREQUENCY, + DEV_PM_QOS_MAX_FREQUENCY, DEV_PM_QOS_FLAGS, }; @@ -99,10 +103,14 @@ struct pm_qos_flags { struct dev_pm_qos { struct pm_qos_constraints resume_latency; struct pm_qos_constraints latency_tolerance; + struct pm_qos_constraints min_frequency; + struct pm_qos_constraints max_frequency; struct pm_qos_flags flags; struct dev_pm_qos_request *resume_latency_req; struct dev_pm_qos_request *latency_tolerance_req; struct dev_pm_qos_request *flags_req; + struct dev_pm_qos_request *min_frequency_req; + struct dev_pm_qos_request *max_frequency_req; }; /* Action requested to pm_qos_update_target */ @@ -197,6 +205,10 @@ static inline s32 dev_pm_qos_read_value(struct device *dev, switch type { case DEV_PM_QOS_RESUME_LATENCY: return PM_QOS_RESUME_LATENCY_NO_CONSTRAINT; + case DEV_PM_QOS_MIN_FREQUENCY: + return PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE; + case DEV_PM_QOS_MAX_FREQUENCY: + return PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE; default: WARN_ON(1); return 0; From patchwork Mon Jul 1 11:26:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 168207 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2802213ilk; Mon, 1 Jul 2019 04:26:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjildnv3EprlpjmgzBFi+9tzqKUEmqYtjXnkBQ6pQHDTU/Q1MqgZEEP0BoNl67Os6Yf6tD X-Received: by 2002:a17:902:6b07:: with SMTP id o7mr27749408plk.180.1561980402155; Mon, 01 Jul 2019 04:26:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561980402; cv=none; d=google.com; s=arc-20160816; b=VqxGUZb+ehg1GOy7M4OIXVGr7LiTv3KOwI9/uc1GeXudGMD/82tOvNeHiV0ICOZj/L 2BjKzYQFQnjRTBmtb7FUCiP6JF8ZASPtPwjf9OiiLXLMUWsBxzeLdtrmqW1OVgimaDHP EfowxYu75e07Co2tIVWslkvqOAcEkNWXyDQy59QoFDzVQmKRAOfbm8Q9xqSNZETH4ZuC MZPo0LXBa4StzgrHyws7Y6bTv7t65W6eE9lxy+NOeruP4+BLRQw2mBasPqq2w/5OdoHa T5Nsb59eEuCpqiy3R6llPkZkuVD+aiqeQGeyGWvAmB2eO25OMxU6yGXNHzDBsNVrR0qM y8ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7tIaWJKZO58buVERPc/8TeKEDpPYUYeCcKfKixqGQKs=; b=DsOnavWVUZdRFqONkglV4vaTa7woqbRb2lMk+e9mvekipH7TtJuE590m4bUeS+ixeh GN+sveUSLEMgPoYAUZST/Nvk5QNzT2vT/l0WswCmxCTqJm3+5xRkSqH2Qla/ni7M9HeR IOyru+d1NB6qJXbl0QdMJugd3mPHdvfy62Y8mR3iPPtWKgBDmtFSmq1d3GkDtLJH99bt 5AQUkUljYey/YdatmBv5dc2zBcQbuwJkTYOdGzEKxV7vZR5Nn4DhKGT2cpGvF3cag3UX qKg8WLTz9dR+7MKguD/O/2S5zKYKQ06Bo91UT/MwMaafm/0fPoio2UE55wz5XiC2QGNm D/NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bVuI8w0y; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v16si11434499pfi.142.2019.07.01.04.26.41; Mon, 01 Jul 2019 04:26:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bVuI8w0y; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728694AbfGAL0k (ORCPT + 11 others); Mon, 1 Jul 2019 07:26:40 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44866 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728621AbfGAL0j (ORCPT ); Mon, 1 Jul 2019 07:26:39 -0400 Received: by mail-pg1-f193.google.com with SMTP id i18so1243943pgl.11 for ; Mon, 01 Jul 2019 04:26:39 -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=7tIaWJKZO58buVERPc/8TeKEDpPYUYeCcKfKixqGQKs=; b=bVuI8w0yMqvNqdcpMb2++FBPQclfdtoCRICFC+qKr90krKTbFyMZEn3BNxuggmiD5d jf8gky5yX9/zAMkECe5gRJQsNX8q68EciaxxJW9RDvW3THYAceV0Ewitr2WKeB+y6D7m NWs307w9lR7keCZu6kD5o7Faqv1GYK0V340W/IXkgK5/W6N4/WjVlhvKrVMa1DYR0qR+ Vaq+GGCeXdqzO/qQhvBHmHxeVLSl4emC4JFPwbwOxYGSEl+ltnpdLbTzGYGX4g54Aqog mAFGuz+pKPiKX4TMeRTpH1jlEuVHHHxiX0NrsqlGXgXJPfE8Pq7jw346YaIu3pukwp5+ W0hw== 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=7tIaWJKZO58buVERPc/8TeKEDpPYUYeCcKfKixqGQKs=; b=opIMGSz7O7KA7IYjmNeQxcEgnLdrtRakg6yuJ3DIKKRgIYSxn79LQZYBKplTKJWcoH UHNnUfgrzM03v9UUMoT4e9SISXiHTWG+uhbZo9SoAQ/1FYgLgg9wj03PY3ca9ZQyK4Qi ptzu7c3tkg97Dz4sMqn8M0F3uPZszAPvzzGWpH+g6bYzWDVwK9CDNaAlk8I2PBxO/0oE nhjgMJXNW03DUEXM0F4Ghfs2IlL+AduHyy5GE2TBWpkh6dGi4mkp0x7wsewj4DUWiyqK aRiBTEYZNhX/5ms0kkQ1u1a+wo9uyqwcuQTUWTekyjAZjbgQ0DTNsXSqsP3avjxoWXcT LKtQ== X-Gm-Message-State: APjAAAVAN/W8imzjPgX1ALYUaDdFs43y9STLnjKJkU4qMtV7ZjIB+PQK l5gb6Jq54IEusO8yB6q/1i9KCw== X-Received: by 2002:a63:8f55:: with SMTP id r21mr21798624pgn.318.1561980398876; Mon, 01 Jul 2019 04:26:38 -0700 (PDT) Received: from localhost ([122.172.21.205]) by smtp.gmail.com with ESMTPSA id q1sm15319064pfn.178.2019.07.01.04.26.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jul 2019 04:26:38 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Qais.Yousef@arm.com, mka@chromium.org, juri.lelli@gmail.com, Ulf Hansson , linux-kernel@vger.kernel.org Subject: [PATCH V5 5/7] cpufreq: Register notifiers with the PM QoS framework Date: Mon, 1 Jul 2019 16:56:13 +0530 Message-Id: <76801b90502a69a0fc49844bd257f9bb3314f757.1561979715.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This registers the notifiers for min/max frequency constraints with the PM QoS framework. The constraints are also taken into consideration in cpufreq_set_policy(). This also relocates cpufreq_policy_put_kobj() as it is required to be called from cpufreq_policy_alloc() now. refresh_frequency_limits() is updated to have proper locking in place and avoid calling cpufreq_set_policy() for inactive policies. No constraints are added until now though. Reviewed-by: Matthias Kaehlcke Reviewed-by: Ulf Hansson Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 135 ++++++++++++++++++++++++++++++-------- include/linux/cpufreq.h | 3 + 2 files changed, 109 insertions(+), 29 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index ceb57af15ca0..81117e4d43cc 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -999,7 +1000,7 @@ static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu) { struct device *dev = get_cpu_device(cpu); - if (!dev) + if (unlikely(!dev)) return; if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) @@ -1117,14 +1118,20 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp static void refresh_frequency_limits(struct cpufreq_policy *policy) { - struct cpufreq_policy new_policy = *policy; + struct cpufreq_policy new_policy; - pr_debug("updating policy for CPU %u\n", policy->cpu); + down_write(&policy->rwsem); + + if (!policy_is_inactive(policy)) { + new_policy = *policy; + pr_debug("updating policy for CPU %u\n", policy->cpu); - new_policy.min = policy->user_policy.min; - new_policy.max = policy->user_policy.max; + new_policy.min = policy->user_policy.min; + new_policy.max = policy->user_policy.max; + cpufreq_set_policy(policy, &new_policy); + } - cpufreq_set_policy(policy, &new_policy); + up_write(&policy->rwsem); } static void handle_update(struct work_struct *work) @@ -1136,11 +1143,55 @@ static void handle_update(struct work_struct *work) refresh_frequency_limits(policy); } +static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, + void *data) +{ + struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min); + + schedule_work(&policy->update); + return 0; +} + +static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, + void *data) +{ + struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max); + + schedule_work(&policy->update); + return 0; +} + +static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) +{ + struct kobject *kobj; + struct completion *cmp; + + down_write(&policy->rwsem); + cpufreq_stats_free_table(policy); + kobj = &policy->kobj; + cmp = &policy->kobj_unregister; + up_write(&policy->rwsem); + kobject_put(kobj); + + /* + * We need to make sure that the underlying kobj is + * actually not referenced anymore by anybody before we + * proceed with unloading. + */ + pr_debug("waiting for dropping of refcount\n"); + wait_for_completion(cmp); + pr_debug("wait complete\n"); +} + static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) { struct cpufreq_policy *policy; + struct device *dev = get_cpu_device(cpu); int ret; + if (!dev) + return NULL; + policy = kzalloc(sizeof(*policy), GFP_KERNEL); if (!policy) return NULL; @@ -1157,7 +1208,7 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, cpufreq_global_kobject, "policy%u", cpu); if (ret) { - pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret); + dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); /* * The entire policy object will be freed below, but the extra * memory allocated for the kobject name needs to be freed by @@ -1167,6 +1218,25 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) goto err_free_real_cpus; } + policy->nb_min.notifier_call = cpufreq_notifier_min; + policy->nb_max.notifier_call = cpufreq_notifier_max; + + ret = dev_pm_qos_add_notifier(dev, &policy->nb_min, + DEV_PM_QOS_MIN_FREQUENCY); + if (ret) { + dev_err(dev, "Failed to register MIN QoS notifier: %d (%*pbl)\n", + ret, cpumask_pr_args(policy->cpus)); + goto err_kobj_remove; + } + + ret = dev_pm_qos_add_notifier(dev, &policy->nb_max, + DEV_PM_QOS_MAX_FREQUENCY); + if (ret) { + dev_err(dev, "Failed to register MAX QoS notifier: %d (%*pbl)\n", + ret, cpumask_pr_args(policy->cpus)); + goto err_min_qos_notifier; + } + INIT_LIST_HEAD(&policy->policy_list); init_rwsem(&policy->rwsem); spin_lock_init(&policy->transition_lock); @@ -1177,6 +1247,11 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) policy->cpu = cpu; return policy; +err_min_qos_notifier: + dev_pm_qos_remove_notifier(dev, &policy->nb_min, + DEV_PM_QOS_MIN_FREQUENCY); +err_kobj_remove: + cpufreq_policy_put_kobj(policy); err_free_real_cpus: free_cpumask_var(policy->real_cpus); err_free_rcpumask: @@ -1189,30 +1264,9 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) return NULL; } -static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) -{ - struct kobject *kobj; - struct completion *cmp; - - down_write(&policy->rwsem); - cpufreq_stats_free_table(policy); - kobj = &policy->kobj; - cmp = &policy->kobj_unregister; - up_write(&policy->rwsem); - kobject_put(kobj); - - /* - * We need to make sure that the underlying kobj is - * actually not referenced anymore by anybody before we - * proceed with unloading. - */ - pr_debug("waiting for dropping of refcount\n"); - wait_for_completion(cmp); - pr_debug("wait complete\n"); -} - static void cpufreq_policy_free(struct cpufreq_policy *policy) { + struct device *dev = get_cpu_device(policy->cpu); unsigned long flags; int cpu; @@ -1224,6 +1278,11 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy) per_cpu(cpufreq_cpu_data, cpu) = NULL; write_unlock_irqrestore(&cpufreq_driver_lock, flags); + dev_pm_qos_remove_notifier(dev, &policy->nb_max, + DEV_PM_QOS_MAX_FREQUENCY); + dev_pm_qos_remove_notifier(dev, &policy->nb_min, + DEV_PM_QOS_MIN_FREQUENCY); + cpufreq_policy_put_kobj(policy); free_cpumask_var(policy->real_cpus); free_cpumask_var(policy->related_cpus); @@ -2283,6 +2342,8 @@ int cpufreq_set_policy(struct cpufreq_policy *policy, struct cpufreq_policy *new_policy) { struct cpufreq_governor *old_gov; + struct device *cpu_dev = get_cpu_device(policy->cpu); + unsigned long min, max; int ret; pr_debug("setting new policy for CPU %u: %u - %u kHz\n", @@ -2297,11 +2358,27 @@ int cpufreq_set_policy(struct cpufreq_policy *policy, if (new_policy->min > new_policy->max) return -EINVAL; + /* + * PM QoS framework collects all the requests from users and provide us + * the final aggregated value here. + */ + min = dev_pm_qos_read_value(cpu_dev, DEV_PM_QOS_MIN_FREQUENCY); + max = dev_pm_qos_read_value(cpu_dev, DEV_PM_QOS_MAX_FREQUENCY); + + if (min > new_policy->min) + new_policy->min = min; + if (max < new_policy->max) + new_policy->max = max; + /* verify the cpu speed can be set within this limit */ ret = cpufreq_driver->verify(new_policy); if (ret) return ret; + /* + * The notifier-chain shall be removed once all the users of + * CPUFREQ_ADJUST are moved to use the QoS framework. + */ /* adjust if necessary - all reasons */ blocking_notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_ADJUST, new_policy); diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index a1467aa7f58b..95425941f46d 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -147,6 +147,9 @@ struct cpufreq_policy { /* Pointer to the cooling device if used for thermal mitigation */ struct thermal_cooling_device *cdev; + + struct notifier_block nb_min; + struct notifier_block nb_max; }; struct cpufreq_freqs { From patchwork Mon Jul 1 11:26:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 168208 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2802300ilk; Mon, 1 Jul 2019 04:26:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlcSFYKyZ5CS11AjGeB+qbIdxP/2szAR3JfP9f6vj2TSBR+H4T9drj8ATGqQsmPpiJ7CKR X-Received: by 2002:a63:3f48:: with SMTP id m69mr23776504pga.17.1561980406820; Mon, 01 Jul 2019 04:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561980406; cv=none; d=google.com; s=arc-20160816; b=zW8FHbV+umEGlsQyk+Bv6Rctqaj8kj2ZI4uvHFRX8wf3trCkow/WxclJG3saluQ+5Y FukHz3DVuvPPIwCxmsxnRrvNq+jt0olRqN7o13z/5mwCG7CIB6ohNbfj6f9yxQgQLhTN Y1oNtLRX/LGLofr63VHsEILr/bflcXgAhpsJNaC9zQKrFI5Go1/CvGWAg6cLaS7WS5dc QnlkBAGWgdu+LFW3CTyR6CLQEIIbtIVkjYuzTjSB4Ue/vij0xYCrdBktho/4lYberT7i qIxatXFWmGVmbrwuB6LJ4xZgBYD9xLxfL4SfQdh5mK62SMAJnG/N3kCwV+SMNWu/QL6m Cxbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YRWeVW4p/qldJNkKTR6o7SUC4e45+GXMXjYNi3OfnwU=; b=1AbWNZOJojsP3SZOb2pW6uIENypMMviZetutOhFp8DkWhadgZmLI6AEUm9tJFsHsRl Bx4UQKnyhqDaTCkjq9oAeys633ZMCmZP0eyuzlPIail7AwIUeSJ5DShK9SOERRSSkPXR GiRKLbjd3jIy6ythh/4wD/ieIWMn07UZHVlrnmgIT4oss5aPsJmEeARfGjylYUqkmylk yGBF6oUQk672Sph+IxIN5FI44P+l6rxaPYe+jc+eQpTd2OP7/r/pnbMFtqR/8HPVOoph a4rZlnzDxKD4yff0LUEjhMLiB0Nz/3xbq2WZSgUnFTV3Mb3n8jGhfdsw2uv0JlNEym8J Xvww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hsn6sfyg; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r19si9771438pgl.203.2019.07.01.04.26.46; Mon, 01 Jul 2019 04:26:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hsn6sfyg; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728719AbfGAL0n (ORCPT + 11 others); Mon, 1 Jul 2019 07:26:43 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40761 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728707AbfGAL0m (ORCPT ); Mon, 1 Jul 2019 07:26:42 -0400 Received: by mail-pf1-f196.google.com with SMTP id p184so6430863pfp.7 for ; Mon, 01 Jul 2019 04:26:42 -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=YRWeVW4p/qldJNkKTR6o7SUC4e45+GXMXjYNi3OfnwU=; b=Hsn6sfygmZ5FO1B898kaMm55vMC5QRAPoqINN4vDEHrpzmav792D9MAFcMOYEKcCr8 61KKGQKwR1ypYa7srp2wsbEczuZfcgfnHEVD89JRlYVgQas+FjTHxjiEq67EivMqk7fl QBAY1fQXmeh8b3gvlvkMhxb0GBX66dybYq89L3TcvqbKh2kKaW+dvywqhHqOT9PAXXD/ w4LqJx8OUtGo74kV+AcqQX5SB7epcnE3iTdl/QwXmygYcxB3EBecDrDQZChvNTCWuAuo thgEWb4W6j7cy8RKNXMeOev/iJlRmStmJXI0GNrBVtP08XfEh60aGU1P6Nlr7H+jj8v4 fJ9w== 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=YRWeVW4p/qldJNkKTR6o7SUC4e45+GXMXjYNi3OfnwU=; b=F9v+nBdI6e/WCGkGpOGmJ8QxRomLsRLZuHoSZiJiRHThgQ/E7cpFa/0c/Rtz44eG7o jTksq2rmiqi9R5N4lu0kOTthrR57g90yhTpkWQNZzl19D4kQmEK1HECHN8IVslPPcaa3 PuJrJ1wexENTBFiIcRGEaysGvW1apPZCEgljVnRa74WsK9YnnkyPj6mrKmfwT6nEehbz zlozj3Xf1IK3Rhjw7LjLPkH23yWTTvBSQrGNdKp4t9fkEkhjQNjHRrHnj3oKe2LzRB9M 5so/tJERK51hyK0FhHuEHLACASvn6cbVNEvYRvvFcR1H0FISpAMoJFm2HzwoNivqJXhK hf6A== X-Gm-Message-State: APjAAAXJwFg0Axj2K7TwE7CgV+XMUrRbCG2yQCmJxn+G1OgcpeDBf6kN qzfnbk3NIfX7BmF7CUJbrC7k6A== X-Received: by 2002:a63:c24d:: with SMTP id l13mr15194332pgg.330.1561980401775; Mon, 01 Jul 2019 04:26:41 -0700 (PDT) Received: from localhost ([122.172.21.205]) by smtp.gmail.com with ESMTPSA id h14sm11138160pfq.22.2019.07.01.04.26.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jul 2019 04:26:41 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Srinivas Pandruvada , Len Brown Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Qais.Yousef@arm.com, mka@chromium.org, juri.lelli@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH V5 6/7] cpufreq: intel_pstate: Reuse refresh_frequency_limits() Date: Mon, 1 Jul 2019 16:56:14 +0530 Message-Id: <76b40f45a13ea8c27afdf218f38f0c54a1100300.1561979715.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The implementation of intel_pstate_update_max_freq() is quite similar to refresh_frequency_limits(), lets reuse it. Finding minimum of policy->user_policy.max and policy->cpuinfo.max_freq in intel_pstate_update_max_freq() is redundant as cpufreq_set_policy() will call the ->verify() callback of intel-pstate driver, which will do this comparison anyway and so dropping it from intel_pstate_update_max_freq() doesn't harm. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq.c | 3 ++- drivers/cpufreq/intel_pstate.c | 7 +------ include/linux/cpufreq.h | 1 + 3 files changed, 4 insertions(+), 7 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 81117e4d43cc..091789e868ee 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1116,7 +1116,7 @@ static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cp return ret; } -static void refresh_frequency_limits(struct cpufreq_policy *policy) +void refresh_frequency_limits(struct cpufreq_policy *policy) { struct cpufreq_policy new_policy; @@ -1133,6 +1133,7 @@ static void refresh_frequency_limits(struct cpufreq_policy *policy) up_write(&policy->rwsem); } +EXPORT_SYMBOL(refresh_frequency_limits); static void handle_update(struct work_struct *work) { diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index f2ff5de988c1..cc27d4c59dca 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -898,7 +898,6 @@ static void intel_pstate_update_policies(void) static void intel_pstate_update_max_freq(unsigned int cpu) { struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); - struct cpufreq_policy new_policy; struct cpudata *cpudata; if (!policy) @@ -908,11 +907,7 @@ static void intel_pstate_update_max_freq(unsigned int cpu) policy->cpuinfo.max_freq = global.turbo_disabled_mf ? cpudata->pstate.max_freq : cpudata->pstate.turbo_freq; - memcpy(&new_policy, policy, sizeof(*policy)); - new_policy.max = min(policy->user_policy.max, policy->cpuinfo.max_freq); - new_policy.min = min(policy->user_policy.min, new_policy.max); - - cpufreq_set_policy(policy, &new_policy); + refresh_frequency_limits(policy); cpufreq_cpu_release(policy); } diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 95425941f46d..1fa37b675a80 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -207,6 +207,7 @@ void cpufreq_cpu_release(struct cpufreq_policy *policy); int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu); int cpufreq_set_policy(struct cpufreq_policy *policy, struct cpufreq_policy *new_policy); +void refresh_frequency_limits(struct cpufreq_policy *policy); void cpufreq_update_policy(unsigned int cpu); void cpufreq_update_limits(unsigned int cpu); bool have_governor_per_policy(void);