From patchwork Thu Feb 9 03:41:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 93664 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp65726qgi; Wed, 8 Feb 2017 19:48:39 -0800 (PST) X-Received: by 10.99.243.21 with SMTP id l21mr1317171pgh.37.1486612119295; Wed, 08 Feb 2017 19:48:39 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j9si8889746pfc.290.2017.02.08.19.48.38; Wed, 08 Feb 2017 19:48:39 -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; 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 S1751785AbdBIDs2 (ORCPT + 25 others); Wed, 8 Feb 2017 22:48:28 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:32827 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751668AbdBIDs0 (ORCPT ); Wed, 8 Feb 2017 22:48:26 -0500 Received: by mail-pf0-f170.google.com with SMTP id y143so46721402pfb.0 for ; Wed, 08 Feb 2017 19:48:25 -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 :in-reply-to:references; bh=eHFtdZTcJLiAsOT3EUOGi9F5tfzhvOHRrw1XhrAK3E8=; b=gc71FmxEdAuynXGTwbKgBIO4gFPh+FCqgAd+4cCY1dVromQlpU/WNbGXnTnsNzkmMB R18ExXgmR4KiwGORO/DDZ/0kbuhwIy/ZfeM6XV1f4LVIEUFZvnhpPU5uF25RCNqLfcxj gWojrOBv9Di0iwdzqoSL8OVv0OVvQH2+7ASYM= 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:in-reply-to:references; bh=eHFtdZTcJLiAsOT3EUOGi9F5tfzhvOHRrw1XhrAK3E8=; b=qP8owA/IHH3pKi3QBy+mucwC+D9N2dOgLT86YdFWsa9AOMf4MD+n7+oNmIerL61FAp LDjTNrHentHC/4s/ZZi/AFIVdx2ycZfDF0DpHpgIpoqko2flJ5L/aadAE+BLFhWPmp1c QqP3rcssWGkeMmZgRqi7zyfQNYEBRnMa5tsltsNCxvFPc5SvxwTnLhE/k32VkGMRCLC3 Z+8MMXTxzr7IqZ2tP8bpwQpSFQn6tsRzGxblxzDTq3DZBb3BLbwtCKbhoUeerdHfrEmU 7Ayys6eIsDQ2nJ3fD+kTAT+r6kubx+8tnAhvyen/eEI5L3hxYSZOj7IQ8ju55Yewce6T NbTQ== X-Gm-Message-State: AMke39nLiFfyGSbT4wa+318bI2rZRiIXQtZr8VlNpA15q1vRa3lqHGvkdP+niPtb0ADaT3Ya X-Received: by 10.98.14.217 with SMTP id 86mr1202839pfo.79.1486611725850; Wed, 08 Feb 2017 19:42:05 -0800 (PST) Received: from localhost ([122.172.165.189]) by smtp.gmail.com with ESMTPSA id z70sm23882928pff.26.2017.02.08.19.42.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2017 19:42:05 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , khilman@baylibre.com, ulf.hansson@linaro.org, Len Brown , Pavel Machek Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , sboyd@codeaurora.org, nm@ti.com, robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, Viresh Kumar Subject: [PATCH V2 1/6] PM / QOS: Add default case to the switch Date: Thu, 9 Feb 2017 09:11:47 +0530 Message-Id: <338b16e4c882634e30e4f4c011a9e9c52d134cbc.1486611268.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The switch block handles all the QOS request types present today, but starts giving compilation warnings as soon as a new type is added and not handled in this. To prevent against that, add the default case as well and do a WARN from it. Signed-off-by: Viresh Kumar --- drivers/base/power/qos.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.7.1.410.g6faf27b diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index 58fcc758334e..01f615b18055 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -621,6 +621,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); From patchwork Thu Feb 9 03:41:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 93672 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp90110qgi; Wed, 8 Feb 2017 21:26:40 -0800 (PST) X-Received: by 10.84.197.3 with SMTP id m3mr1778998pld.89.1486618000141; Wed, 08 Feb 2017 21:26:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p29si9082219pfd.190.2017.02.08.21.26.39; Wed, 08 Feb 2017 21:26:40 -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; 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 S1751553AbdBIF00 (ORCPT + 25 others); Thu, 9 Feb 2017 00:26:26 -0500 Received: from mail-pf0-f177.google.com ([209.85.192.177]:36068 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751055AbdBIF0Y (ORCPT ); Thu, 9 Feb 2017 00:26:24 -0500 Received: by mail-pf0-f177.google.com with SMTP id 189so47397662pfu.3 for ; Wed, 08 Feb 2017 21:26:19 -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 :in-reply-to:references; bh=NNE21DV9tUmYIY1X/dR+s6B66tDJfnSKFHEohIj5G8s=; b=AjbP27nBGGkm0tbd0d2C//i+P+q2HRGUlQ8CsmxCpLh2wSMfSoMcNIr7VTmEnE4Oqd oe9s2YqxQXDTi+lgzZvAPYFOszvDER3usYNh7lVO7Vo7BxCtntKQ+MoaAMeQNtWRG4PK PcVYbvQYyeHektRpSa2wrZ2anjdQxZTh4/F2k= 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:in-reply-to:references; bh=NNE21DV9tUmYIY1X/dR+s6B66tDJfnSKFHEohIj5G8s=; b=AqYE3UZ3cmPCg7j0tqg2nvjm6AAvDAXCDNNvmbGJlC7BAPkv0OW8UHj2OY9k56YaIr j9Gy1NgoBeDr0whPTxOoZZonvowoNKkmxti8xhnTOp7fdNPdikaSwoI1X6KTr50cGP/5 6Yqg8TmHmlO/TYyd7v9NZtqi6kHKRNBw147DopCcJ9OJDHXEc26ELUmDYX1AvJEQ+MPa hmrxXJXTN7G/5BI7kPWQYFpmIcdH6IgilDJ1t55ZbcOxcR4W/CsSLllxgQjl1xBeRsqE QCsYiHNbYT4lQyVv6MFzjhTMpV2fmVEQyff+ByUHQYYwMmL+/OC7cSVlUhaWTdV/KQe4 rZOQ== X-Gm-Message-State: AMke39nxYsBloYcIHvra1wEB5Ivg5CDpJHKpnmDNtKrVyMOcaW1INYxN34jeTytYKVLmx+D1 X-Received: by 10.98.147.78 with SMTP id b75mr1249959pfe.128.1486611732892; Wed, 08 Feb 2017 19:42:12 -0800 (PST) Received: from localhost ([122.172.165.189]) by smtp.gmail.com with ESMTPSA id s26sm23878974pge.33.2017.02.08.19.42.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2017 19:42:12 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , khilman@baylibre.com, ulf.hansson@linaro.org, Len Brown , Pavel Machek Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , sboyd@codeaurora.org, nm@ti.com, robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, Viresh Kumar Subject: [PATCH V2 3/6] PM / QOS: Add 'performance' request Date: Thu, 9 Feb 2017 09:11:49 +0530 Message-Id: <9820795796278bc66baa3f41220f8524cbdda537.1486611268.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new QOS request type: DEV_PM_QOS_PERFORMANCE. This is required to support runtime performance constraints for the devices. Also allow notifiers to be registered against it, which can be used by frameworks like genpd. Signed-off-by: Viresh Kumar --- Documentation/power/pm_qos_interface.txt | 2 +- drivers/base/power/qos.c | 69 +++++++++++++++++++++++++++----- include/linux/pm_qos.h | 4 ++ 3 files changed, 63 insertions(+), 12 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/Documentation/power/pm_qos_interface.txt b/Documentation/power/pm_qos_interface.txt index c7989d140428..a0a45ecbc1a8 100644 --- a/Documentation/power/pm_qos_interface.txt +++ b/Documentation/power/pm_qos_interface.txt @@ -172,7 +172,7 @@ type. The callback is called when the aggregated value of the device constraints list is changed. Currently it only supports the notifier to be registered for resume -latency device PM QoS. +latency and performance device PM QoS. int dev_pm_qos_remove_notifier(device, notifier, type): Removes the notification callback function for the device. diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c index 9adc208cf1fc..cf070468a7ca 100644 --- a/drivers/base/power/qos.c +++ b/drivers/base/power/qos.c @@ -163,6 +163,10 @@ static int apply_constraint(struct dev_pm_qos_request *req, req->dev->power.set_latency_tolerance(req->dev, value); } break; + case DEV_PM_QOS_PERFORMANCE: + ret = pm_qos_update_target(&qos->performance, &req->data.pnode, + action, value); + break; case DEV_PM_QOS_FLAGS: ret = pm_qos_update_flags(&qos->flags, &req->data.flr, action, value); @@ -191,12 +195,13 @@ static int dev_pm_qos_constraints_allocate(struct device *dev) if (!qos) return -ENOMEM; - n = kzalloc(sizeof(*n), GFP_KERNEL); + n = kzalloc(2 * sizeof(*n), GFP_KERNEL); if (!n) { kfree(qos); return -ENOMEM; } BLOCKING_INIT_NOTIFIER_HEAD(n); + BLOCKING_INIT_NOTIFIER_HEAD(n + 1); c = &qos->resume_latency; plist_head_init(&c->list); @@ -213,6 +218,14 @@ 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->performance; + plist_head_init(&c->list); + c->target_value = PM_QOS_PERFORMANCE_DEFAULT_VALUE; + c->default_value = PM_QOS_PERFORMANCE_DEFAULT_VALUE; + c->no_constraint_value = PM_QOS_PERFORMANCE_DEFAULT_VALUE; + c->type = PM_QOS_MAX; + c->notifiers = n + 1; + INIT_LIST_HEAD(&qos->flags.list); spin_lock_irq(&dev->power.lock); @@ -271,6 +284,11 @@ 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->performance; + 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)); + } 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); @@ -382,6 +400,7 @@ 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_PERFORMANCE: curr_value = req->data.pnode.prio; break; case DEV_PM_QOS_FLAGS: @@ -492,11 +511,9 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_remove_request); int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier, enum dev_pm_qos_req_type type) { + struct dev_pm_qos *qos; 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)) @@ -504,10 +521,26 @@ 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) - ret = blocking_notifier_chain_register(dev->power.qos->resume_latency.notifiers, + if (ret) + goto unlock; + + qos = dev->power.qos; + + switch (type) { + case DEV_PM_QOS_RESUME_LATENCY: + ret = blocking_notifier_chain_register(qos->resume_latency.notifiers, + notifier); + break; + case DEV_PM_QOS_PERFORMANCE: + ret = blocking_notifier_chain_register(qos->performance.notifiers, notifier); + break; + default: + WARN_ON(1); + ret = -EINVAL; + } +unlock: mutex_unlock(&dev_pm_qos_mtx); return ret; } @@ -528,18 +561,32 @@ int dev_pm_qos_remove_notifier(struct device *dev, struct notifier_block *notifier, enum dev_pm_qos_req_type type) { + struct dev_pm_qos *qos; int retval = 0; - if (WARN_ON(type != DEV_PM_QOS_RESUME_LATENCY)) - return -EINVAL; - mutex_lock(&dev_pm_qos_mtx); + qos = dev->power.qos; + /* 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, + if (IS_ERR_OR_NULL(qos)) + goto unlock; + + switch (type) { + case DEV_PM_QOS_RESUME_LATENCY: + retval = blocking_notifier_chain_unregister(qos->resume_latency.notifiers, + notifier); + break; + case DEV_PM_QOS_PERFORMANCE: + retval = blocking_notifier_chain_unregister(qos->performance.notifiers, notifier); + break; + default: + WARN_ON(1); + retval = -EINVAL; + } +unlock: mutex_unlock(&dev_pm_qos_mtx); return retval; } diff --git a/include/linux/pm_qos.h b/include/linux/pm_qos.h index 08cfaeb6c178..0e8386adb21c 100644 --- a/include/linux/pm_qos.h +++ b/include/linux/pm_qos.h @@ -36,6 +36,7 @@ enum pm_qos_flags_status { #define PM_QOS_RESUME_LATENCY_DEFAULT_VALUE 0 #define PM_QOS_LATENCY_TOLERANCE_DEFAULT_VALUE 0 #define PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT (-1) +#define PM_QOS_PERFORMANCE_DEFAULT_VALUE 0 #define PM_QOS_LATENCY_ANY ((s32)(~(__u32)0 >> 1)) #define PM_QOS_FLAG_NO_POWER_OFF (1 << 0) @@ -55,6 +56,7 @@ 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_PERFORMANCE, DEV_PM_QOS_FLAGS, }; @@ -96,9 +98,11 @@ struct pm_qos_flags { struct dev_pm_qos { struct pm_qos_constraints resume_latency; struct pm_qos_constraints latency_tolerance; + struct pm_qos_constraints performance; 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 *performance_req; struct dev_pm_qos_request *flags_req; }; From patchwork Thu Feb 9 03:41:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 93671 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp72876qgi; Wed, 8 Feb 2017 20:17:19 -0800 (PST) X-Received: by 10.98.152.218 with SMTP id d87mr1338827pfk.17.1486613839142; Wed, 08 Feb 2017 20:17:19 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p80si8978210pfk.56.2017.02.08.20.17.18; Wed, 08 Feb 2017 20:17:19 -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; 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 S1751739AbdBIERE (ORCPT + 25 others); Wed, 8 Feb 2017 23:17:04 -0500 Received: from mail-pg0-f44.google.com ([74.125.83.44]:36138 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbdBIERC (ORCPT ); Wed, 8 Feb 2017 23:17:02 -0500 Received: by mail-pg0-f44.google.com with SMTP id v184so53942066pgv.3 for ; Wed, 08 Feb 2017 20:15:24 -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 :in-reply-to:references; bh=boF/CQjUTqiTrmqWV7Kcq4Y71ecH+N6IfNRG9Q9iUqQ=; b=VgGw7AMb4+LOk2WGsOnpsVGcf2T1NFdUtCyBxKh3+lKGfqTTTNffXKJU0J62xK944P 3eCEMeUq4yMDNEr10tGEsztoLjzRicr9AGo+oGieSEuX7xZzQcKifXS3HSSI/rrjqT7V 1uILExm0zrU2nQ9NALmEb/nrtNG2xM4UvL4N0= 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:in-reply-to:references; bh=boF/CQjUTqiTrmqWV7Kcq4Y71ecH+N6IfNRG9Q9iUqQ=; b=oI5Sd0HyApQ/Aqk+26BceGy5nt8oVWfHHSYkL6gYYDac/H2EaFevHhCt44l5Uu8MYa wsAcvaIzDIJ4hc6mcZltXX+rwuuqj/6BhDsyrpQifE2lQnJAnoIPmEDAaRagJDcbWAnx ZwpeOe5DyYgJtyub4KaBmUip1mDRoe7sW/KcJyxHNibJEOo+zewU7fZE0vZ5GSBtyy1j pbV14vkzrHBwhcci1oETGR39qB5imMkmlQyIgXienEI+LEqM8tjgwQD0r/kMhQtjsk9H A07q1rMlHP8/+NnvJ/t0I5/34vGsB1IocQVQbD6TmnqljuYyWMaPNa6KifAeQzPs0e8O /E9Q== X-Gm-Message-State: AMke39leH1LWXlft157+PXCwqRvpIGfWhys71hqU+70wN5btCzXo3NR9G4VBIoCWeP/gBcn8 X-Received: by 10.98.131.136 with SMTP id h130mr1268832pfe.4.1486611736333; Wed, 08 Feb 2017 19:42:16 -0800 (PST) Received: from localhost ([122.172.165.189]) by smtp.gmail.com with ESMTPSA id t185sm23885898pgb.32.2017.02.08.19.42.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2017 19:42:15 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , khilman@baylibre.com, ulf.hansson@linaro.org, Kevin Hilman , Len Brown , Pavel Machek Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , sboyd@codeaurora.org, nm@ti.com, robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, Viresh Kumar Subject: [PATCH V2 4/6] PM / domain: Register for PM QOS performance notifier Date: Thu, 9 Feb 2017 09:11:50 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some platforms have the capability to configure the performance state of their Power Domains. The performance levels are represented by positive integer values, a lower value represents lower performance state. This patch registers the power domain framework for PM QOS performance notifier in order to manage performance state of power domains. This also allows the power domain drivers to implement a ->set_performance_state() callback, which will be called by the power domain core from the notifier routine. Signed-off-by: Viresh Kumar --- drivers/base/power/domain.c | 98 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/pm_domain.h | 5 +++ 2 files changed, 101 insertions(+), 2 deletions(-) -- 2.7.1.410.g6faf27b diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index a73d79670a64..1158a07f92de 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -367,6 +367,88 @@ static int genpd_dev_pm_qos_notifier(struct notifier_block *nb, return NOTIFY_DONE; } +static void update_domain_performance_state(struct generic_pm_domain *genpd, + int depth) +{ + struct generic_pm_domain_data *pd_data; + struct generic_pm_domain *subdomain; + struct pm_domain_data *pdd; + unsigned int state = 0; + struct gpd_link *link; + + /* Traverse all devices within the domain */ + list_for_each_entry(pdd, &genpd->dev_list, list_node) { + pd_data = to_gpd_data(pdd); + + if (pd_data->performance_state > state) + state = pd_data->performance_state; + } + + /* Traverse all subdomains within the domain */ + list_for_each_entry(link, &genpd->master_links, master_node) { + subdomain = link->slave; + + if (subdomain->performance_state > state) + state = subdomain->performance_state; + } + + if (genpd->performance_state == state) + return; + + genpd->performance_state = state; + + if (genpd->set_performance_state) { + genpd->set_performance_state(genpd, state); + return; + } + + /* Propagate only if this domain has a single parent */ + if (list_is_singular(&genpd->slave_links)) { + /* Performance levels are managed by parent power domain */ + + struct generic_pm_domain *master; + + link = list_first_entry(&genpd->slave_links, struct gpd_link, slave_node); + master = link->master; + + genpd_lock_nested(master, depth + 1); + update_domain_performance_state(master, depth + 1); + genpd_unlock(master); + } +} + +static int genpd_dev_pm_qos_perf_notifier(struct notifier_block *nb, + unsigned long val, void *ptr) +{ + struct generic_pm_domain_data *gpd_data; + struct generic_pm_domain *genpd = ERR_PTR(-ENODATA); + struct pm_domain_data *pdd; + struct device *dev; + + gpd_data = container_of(nb, struct generic_pm_domain_data, perf_nb); + dev = gpd_data->base.dev; + + spin_lock_irq(&dev->power.lock); + + pdd = dev->power.subsys_data ? + dev->power.subsys_data->domain_data : NULL; + + if (pdd && pdd->dev) + genpd = dev_to_genpd(dev); + + spin_unlock_irq(&dev->power.lock); + + if (IS_ERR(genpd)) + return NOTIFY_DONE; + + genpd_lock(genpd); + gpd_data->performance_state = val; + update_domain_performance_state(genpd, 0); + genpd_unlock(genpd); + + return NOTIFY_DONE; +} + /** * genpd_power_off - Remove power from a given PM domain. * @genpd: PM domain to power down. @@ -1137,6 +1219,9 @@ static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, gpd_data->td.constraint_changed = true; gpd_data->td.effective_constraint_ns = -1; gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier; + gpd_data->performance_state = 0; + + gpd_data->perf_nb.notifier_call = genpd_dev_pm_qos_perf_notifier; spin_lock_irq(&dev->power.lock); @@ -1210,12 +1295,16 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, out: genpd_unlock(genpd); - if (ret) + if (ret) { genpd_free_dev_data(dev, gpd_data); - else + } else { dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); + dev_pm_qos_add_notifier(dev, &gpd_data->perf_nb, + DEV_PM_QOS_PERFORMANCE); + } + return ret; } @@ -1249,6 +1338,8 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, pdd = dev->power.subsys_data->domain_data; gpd_data = to_gpd_data(pdd); + dev_pm_qos_remove_notifier(dev, &gpd_data->perf_nb, + DEV_PM_QOS_PERFORMANCE); dev_pm_qos_remove_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); @@ -1277,6 +1368,9 @@ static int genpd_remove_device(struct generic_pm_domain *genpd, genpd_unlock(genpd); dev_pm_qos_add_notifier(dev, &gpd_data->nb, DEV_PM_QOS_RESUME_LATENCY); + dev_pm_qos_add_notifier(dev, &gpd_data->perf_nb, + DEV_PM_QOS_PERFORMANCE); + return ret; } diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 81ece61075df..d994ad5ba1c0 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -62,8 +62,11 @@ struct generic_pm_domain { unsigned int device_count; /* Number of devices */ unsigned int suspended_count; /* System suspend device counter */ unsigned int prepared_count; /* Suspend counter of prepared devices */ + unsigned int performance_state; /* Max requested performance state */ int (*power_off)(struct generic_pm_domain *domain); int (*power_on)(struct generic_pm_domain *domain); + int (*set_performance_state)(struct generic_pm_domain *domain, + unsigned int state); struct gpd_dev_ops dev_ops; s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ bool max_off_time_changed; @@ -117,6 +120,8 @@ struct generic_pm_domain_data { struct pm_domain_data base; struct gpd_timing_data td; struct notifier_block nb; + struct notifier_block perf_nb; + unsigned int performance_state; }; #ifdef CONFIG_PM_GENERIC_DOMAINS