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;