From patchwork Thu Feb 21 11:29:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 158906 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp373310jaa; Thu, 21 Feb 2019 03:30:05 -0800 (PST) X-Google-Smtp-Source: AHgI3IawGJNN90ZLlCSIxKM6XiIXeQhbXSaj7KO7nN3pGBeW0jYxTLDWv5p0uSuOkyWUVTNGEzsu X-Received: by 2002:a63:2bcd:: with SMTP id r196mr33304592pgr.355.1550748605871; Thu, 21 Feb 2019 03:30:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550748605; cv=none; d=google.com; s=arc-20160816; b=I5b/sm8E6JjDNXABapokhrxy9FECwvitup6sXmMlxIkQ0Rvq4CS8DjHtITIwmPGxqe EqEND5KnEZjGSdD16taKOxaIR756DJJnSd4wbpZTMg9rGz67duFe1joJVg4VDNk5LOFS Y72mfxvuzL6wu6jyCIkkQX+G6jrSgkaq2as/3NoAbbtb2KEcpd5xHUmUHgQLfE0FUd56 MTuleP05DzFuN83hnZfNXMuwGdP3+gXIu7GSHF71GjQVKrCkr2nGLfhuCCdZyX4UNsL0 exgWZAjfqHPRwBNVU9GnAt2La1EyILme8xaeHvgF/F1MlhKBfEzFMgyr7Zl5jbLOV7kh 6EBQ== 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=3RtHEYciGp3wZ5IC0stPd9CIwj1alFGW6YIZIibelFE=; b=B0Gu0UVpERHg2hvlWprvoE2zGMJAC2bqjQT0s1x2nIJMd5VXBlDIMrswgOTh983uFT l2elqszp4U7x+4a40f6p+AsoAjY2It+FEv7RNXJBezasyobLbLh4coaTxkFOnvavTebq e/Lk0OTpx3XWhPiyo0onqIfPoczK496mXvKlcNxhyqj+nsEl+QlCflbyzJmsbJJSRZ9S Na9XLVNcSJlG+ami+/LN3mgqpjbiGvBmCehH7CziBvPj84wWBWcGxB8HHiCfP++ROMO6 WGvXStegzkYVoxojM3cW5ljIFBhCJkHSsdDu5KtOzlzvDBmuAxLbilkuRA3ux2rTOwoo mfIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HJcxlD2+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 s2si15173242plq.345.2019.02.21.03.30.05; Thu, 21 Feb 2019 03:30:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=HJcxlD2+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1727667AbfBULaD (ORCPT + 32 others); Thu, 21 Feb 2019 06:30:03 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34036 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbfBUL34 (ORCPT ); Thu, 21 Feb 2019 06:29:56 -0500 Received: by mail-pl1-f193.google.com with SMTP id d15so6899178plr.1 for ; Thu, 21 Feb 2019 03:29:56 -0800 (PST) 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=3RtHEYciGp3wZ5IC0stPd9CIwj1alFGW6YIZIibelFE=; b=HJcxlD2+L3p4W0nDT7+XS3EOC61KgQtsQk2X0ochBuuG//m+LuB+9m8/PLQCP1orA/ qziCxAw4fF2s3edkKvvJLsNygAQD0QlY0FOzb4AjnKOXtVsqXlFDKJzk69BQcB4LBWEn L5q6fc0F4NsC3giNoU7tOcgzldDr8yTZ9EruGbF0cTNswN66zKNJCa5qehU8zBoG1n91 /9mHfA9IkvQxixHNhAXDJrXQ8XdeQ430PTcqPtyka8eX2t06FIw7vnGYEm8MncNcbpAg sihzzQFvOcqWFcpISCoO2KxBLNnzVaxnLNIx24n1oy8QndkpIsNheyXEU+EK6CB31d0T E/Kg== 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=3RtHEYciGp3wZ5IC0stPd9CIwj1alFGW6YIZIibelFE=; b=CMmUfLMczrlJ42DYNYKTJevT7NTcTv6/oN825+2RXRqKUsu0S4KzSttQ+xYMM+NCrz U5CteZGgr6VMCJuf7vjBXID7jfXHQHQjF+47ovkMdG/EJYM/emavSXRsIAip9LzOsfVh LHGsyiz7dzBtNpYzrSxKzIZGhc5oPoFZnrPtCMEqTzuzjWOXLSDG2rsvwhya/icgBdZ+ neKCLj2NFR2yC1YQMSCIJMoX2VrNCwr5EpCMIKWZBHI8X5kGhDzoYFYJR2JM8kUhNTLj stIs6kXVHIIuPm8oiFsvn3/dBrUVI+oAD/0ldYNWyfm1vd7vZqrBLmOIAJ8ClpIwQGR1 HIrA== X-Gm-Message-State: AHQUAuYU5mp/sjqbHFGWPZV3GfAWAu6EJpIlUK8vHqpM2X3Y8HSR/Dkw G8mt7CTxMslBjHYw707tMvEFEQ== X-Received: by 2002:a17:902:8602:: with SMTP id f2mr42552253plo.263.1550748595870; Thu, 21 Feb 2019 03:29:55 -0800 (PST) Received: from localhost ([122.172.102.63]) by smtp.gmail.com with ESMTPSA id n1sm42134336pfi.123.2019.02.21.03.29.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 03:29:55 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Pavel Machek , Len Brown Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , mka@chromium.org, juri.lelli@gmail.com, Qais.Yousef@arm.com, linux-kernel@vger.kernel.org Subject: [PATCH V2 3/5] PM / QoS: Add support for MIN/MAX frequency constraints Date: Thu, 21 Feb 2019 16:59:29 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Signed-off-by: Viresh Kumar --- drivers/base/power/qos.c | 103 +++++++++++++++++++++++++++++++++------ include/linux/pm_qos.h | 18 +++++++ 2 files changed, 107 insertions(+), 14 deletions(-) -- 2.21.0.rc0.269.g1a574e7a288b diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index fda7266970e9..30fe1e98b343 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -155,6 +155,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); @@ -183,12 +191,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); @@ -197,6 +204,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); @@ -205,6 +213,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); @@ -258,11 +284,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); @@ -374,6 +414,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: @@ -486,9 +528,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)) @@ -496,10 +535,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; } @@ -520,20 +577,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); @@ -593,6 +665,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 55814d48c39c..3f994283a5ae 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 */ @@ -185,6 +193,12 @@ static inline s32 dev_pm_qos_raw_read_value(struct device *dev, case DEV_PM_QOS_RESUME_LATENCY: return IS_ERR_OR_NULL(qos) ? PM_QOS_RESUME_LATENCY_NO_CONSTRAINT : pm_qos_read_value(&qos->resume_latency); + case DEV_PM_QOS_MIN_FREQUENCY: + return IS_ERR_OR_NULL(qos) ? PM_QOS_MIN_FREQUENCY_DEFAULT_VALUE + : pm_qos_read_value(&qos->min_frequency); + case DEV_PM_QOS_MAX_FREQUENCY: + return IS_ERR_OR_NULL(qos) ? PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE + : pm_qos_read_value(&qos->max_frequency); default: WARN_ON(1); return 0; @@ -256,6 +270,10 @@ static inline s32 dev_pm_qos_raw_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;