From patchwork Mon Nov 5 06:36:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 150139 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2242317ljp; Sun, 4 Nov 2018 22:37:18 -0800 (PST) X-Google-Smtp-Source: AJdET5dQqAWXyuB1NaQIAbq8J48rsRnkP/LX3/wacFlITXssfIznahV0UXdbVTJXZuvHexzhXRPY X-Received: by 2002:a17:902:b592:: with SMTP id a18-v6mr20344158pls.248.1541399838151; Sun, 04 Nov 2018 22:37:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541399838; cv=none; d=google.com; s=arc-20160816; b=lxJeIrHaJtYREag3KsKcrXS0ycDiGIpNnqY0L32esR1H+BTlsPL/7IqY6TLnRoxM0n kZkcMv6U8blHNQEhF2geOBdyy7XyEkPy8KwAuiDwXaG67hOHP2VNtlcPlZoVMZtMSQeO J0hEyuKYv+BFi7fMXSbkNeW+uMdZ+SDiIftHwyXPsG4OWjb3SkjOdH/t9uMMz6vFEe3P mBx4hl7rYbVWCiMwmfex1yBVoMwkDVF83/gGtp9zy7IzlidVUqreenU9aFsU4j/cGGLO otGGpQ10BWCPTxY6cFmBdX7PQQuD0V3Ckb0iVLkHlfV4N4uFEsvJMlAwG4ZO1ybS1Vaz 07bw== 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=w59iisoJQ78soOoIeJ+J+gAbXxrCAkavZgo9Hnt+aE4=; b=BA+DlaNdeWfyy8XHGnPa2zoav7T8zf4sQRJRDLEajsrYgbjFFPYGRTPV5OnZSeo8+z 5Kq9nxRdKGWneBBngAO3j5KKTOKb8Cr+XrzHecaawAK/Iy4SclApMEY8Effl0wEe/B1V E/p6s7izoMaKFxZFT8B3JYvzuH7SZojSpdWaxFhsTlLHsG8gKGZac+ApQgeWmiDn+2CQ ugsSa03/EGktH5LMgKOKv6LH88MPQG/YJNQU8C25vIpGXVtF6pB51ZGGnMFYDzsaPczP gEYn5ze1Ds+qMVWTk2woH3oZlos7N2913hOALRpU5bKV6JEGRsKe/8DiQ+47Rc5HaMw6 +wWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rj4f5AW1; 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 g70-v6si40999838pfd.86.2018.11.04.22.37.17; Sun, 04 Nov 2018 22:37:18 -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=Rj4f5AW1; 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 S1729422AbeKEPzV (ORCPT + 32 others); Mon, 5 Nov 2018 10:55:21 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44350 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729398AbeKEPzU (ORCPT ); Mon, 5 Nov 2018 10:55:20 -0500 Received: by mail-pl1-f196.google.com with SMTP id s5-v6so3932446plq.11 for ; Sun, 04 Nov 2018 22:37:14 -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=w59iisoJQ78soOoIeJ+J+gAbXxrCAkavZgo9Hnt+aE4=; b=Rj4f5AW1+BA3NUNvWqeTjieSLCp56uqjDOnTkd1zeupuaVDqmjavpQ9jwF4s8XRVfU uuKA4c/VT/XVQwq29U5ELFcqai41MZ62End4FWp2TXM43zl1KnFDh8+Meup6iU2IUSHa YmLF1RhPKhm5I2eKi7ukKVLRX5HcMC36ERHLs= 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=w59iisoJQ78soOoIeJ+J+gAbXxrCAkavZgo9Hnt+aE4=; b=lAQgNP/qBlADrvJU6w0JyGUCMm9JvZ+5Zto8JWHtmjJrJRyfSWFezdu0KRu+jeLNOp 59aeCfVlhm9rHoEJe2/PRZ6KNnYqA6bEylTYU7/OtIjrbjdBZNwAoePUg7xXATHLaH0g cFhLIsIFqIo7Od8VQhY3gnRQmecbfVUCgpXlCPHwHxp2U6UjSiXYkftaBGY3OzMDIjf6 1EVqxBGv7lh26NtV4mc8Ai50e/uJIkWED72HEguA1qZxj1NiOYHcBrRwAY4vKjY3onGE l/s9i+W/xw2anw0cZ+YRZIzwxQPNjQOfxS+trl4JQhuxVXr1aKiy7mfWCzFkXZw63X9T bNrw== X-Gm-Message-State: AGRZ1gJqz8UdGZFAPNkrPw1SpeQpMxFti7X33oMxy0uAthWRyTINFwCW z0XkV0u/6R0X34v96H6aYvONTQ== X-Received: by 2002:a17:902:a9:: with SMTP id a38-v6mr9378635pla.7.1541399833493; Sun, 04 Nov 2018 22:37:13 -0800 (PST) Received: from localhost ([171.61.116.174]) by smtp.gmail.com with ESMTPSA id m5-v6sm52108824pfc.188.2018.11.04.22.37.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 22:37:12 -0800 (PST) From: Viresh Kumar To: ulf.hansson@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] OPP: Add dev_pm_opp_xlate_performance_state() helper Date: Mon, 5 Nov 2018 12:06:43 +0530 Message-Id: X-Mailer: git-send-email 2.19.1.568.g152ad8e3369a 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 Introduce a new helper dev_pm_opp_xlate_performance_state() which will be used to translate from pstate of a device to another one. Initially this will be used by genpd to find pstate of a master domain using its sub-domain's pstate. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 49 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 7 ++++++ 2 files changed, 56 insertions(+) -- 2.19.1.568.g152ad8e3369a diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 0eaa954b3f6c..010a4268e8dd 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1707,6 +1707,55 @@ void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, dev_err(virt_dev, "Failed to find required device entry\n"); } +/** + * dev_pm_opp_xlate_performance_state() - Find required OPP's pstate for src_table. + * @src_table: OPP table which has dst_table as one of its required OPP table. + * @dst_table: Required OPP table of the src_table. + * @pstate: Current performance state of the src_table. + * + * This Returns pstate of the OPP (present in @dst_table) pointed out by the + * "required-opps" property of the OPP (present in @src_table) which has + * performance state set to @pstate. + * + * Return: Positive performance state on success, otherwise 0 on errors. + */ +unsigned int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, + struct opp_table *dst_table, + unsigned int pstate) +{ + struct dev_pm_opp *opp; + unsigned int dest_pstate = 0; + int i; + + for (i = 0; i < src_table->required_opp_count; i++) { + if (src_table->required_opp_tables[i] == dst_table) + break; + } + + if (unlikely(i == src_table->required_opp_count)) { + pr_err("%s: Couldn't find matching OPP table (%p: %p)\n", + __func__, src_table, dst_table); + return 0; + } + + mutex_lock(&src_table->lock); + + list_for_each_entry(opp, &src_table->opp_list, node) { + if (opp->pstate == pstate) { + dest_pstate = opp->required_opps[i]->pstate; + goto unlock; + } + } + + pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__, src_table, + dst_table); + +unlock: + mutex_unlock(&src_table->lock); + + return dest_pstate; +} + /** * dev_pm_opp_add() - Add an OPP table from a table definitions * @dev: device for which we do this operation diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 2b2c3fd985ab..5a64a81a1789 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -128,6 +128,7 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*s void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct device *dev, struct device *virt_dev, int index); void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, struct device *virt_dev); +unsigned int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); @@ -280,6 +281,12 @@ static inline struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct device *dev } static inline void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, struct device *virt_dev) {} + +static inline unsigned int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) +{ + return 0; +} + static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { return -ENOTSUPP; From patchwork Mon Nov 5 06:36:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 150140 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2242335ljp; Sun, 4 Nov 2018 22:37:20 -0800 (PST) X-Google-Smtp-Source: AJdET5dH7pDCIQh/x6XJdDMTZJyOwjYfbAJ51HSz3QL4NejIGMCRPzDjy5U3cOCKaqB569qpupad X-Received: by 2002:a62:5285:: with SMTP id g127-v6mr12896800pfb.128.1541399840732; Sun, 04 Nov 2018 22:37:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541399840; cv=none; d=google.com; s=arc-20160816; b=WXCwUpUg1Qw7TIVVqt2rum7Fg3DdFMsVf6Rv8+SeU8zJmolU2hxBpWcPP4Izt7cBOp PfUmG08Ukp6Z8lAU6mdM24xp1KP8CJ7/wFLdLqt3KzemjRj9j1YJOkhVY2Le97XrQCAc G6AgPGr1bspK/o1lG2PVhvIyx7X6Jnv16yMFY0ltPN0Lf1ABw2cBAi7hYQbDrt6m/i2C wP9/MoWdKdxwL/hQ60xy6f3yp4vYZVtrrsgPC41CN4Qe6LcPRLBejdTUgkFrw72CSHIj 7k/y1NmnBjWsNIi5WimLB25mfnOYyO2czrdWOud5O4THnZmmurXPGSDUhPgyTnWotlyk D6lg== 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=++v3XXRbpVHJuX8RyfyvTaqYBFuAGN2iIxtK4ZIufKQ=; b=wTUjqSF2pLhjBahpW9CEESpYzYSBr5WnF7SmzPTqlutGFeeW0pZNufuvjCKRzRzpOM 1AMI0I/9NtVIqxtHPTrHP9TnpiIDro3cuhjoiUJTkHFvWucCuzTwYTSaGs3a/BXVIY8C h1kXFIQYgJBIpgVJx3RS6T7fQ1nsK7+KuZKCqbbfoTnIxqTnv24Vk51HWkgBY9b+h+/T 9kZpJtAUxYTym5TAYeMr9TxNckTogEzMwodnYpqcjTTPrFR3IRcleHV5Lh78s/jLYsDV 1aCCq5vXXKT10DeTvYF293LrlrHePM/eho3psZtWGGxiaz8FHIuteUnHYrENix2df2yA dG/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bsoKAnUs; 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 bi6-v6si30585614plb.348.2018.11.04.22.37.20; Sun, 04 Nov 2018 22:37:20 -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=bsoKAnUs; 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 S1729448AbeKEPzY (ORCPT + 32 others); Mon, 5 Nov 2018 10:55:24 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39900 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729398AbeKEPzX (ORCPT ); Mon, 5 Nov 2018 10:55:23 -0500 Received: by mail-pl1-f196.google.com with SMTP id b5-v6so3941888pla.6 for ; Sun, 04 Nov 2018 22:37:17 -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=++v3XXRbpVHJuX8RyfyvTaqYBFuAGN2iIxtK4ZIufKQ=; b=bsoKAnUs+j9TMTBQiNfz11G8VWYBM+z6/t3fMiHdrKu1VTmHha1XLRO7mN6d0iSqTR UcklcFwRcjxJCN1buo21Thb8oHsVenu+WKDhTHAqg0YXPo3aI5cZMZrqnrSkB/r7fGR9 XjNoSn71TgZ6arMdToxGrwhQSoKRg44gjubtk= 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=++v3XXRbpVHJuX8RyfyvTaqYBFuAGN2iIxtK4ZIufKQ=; b=m4FA2V2T8HUjj/6E+xBq4jT+FxYsikeuTzd4haqBONxlrlQw/LqPCsRHpkvCr2wdEQ sPsIWqO2TigrDAIatEPDr9P7kN93dFFlSCNp29Xu3UCRXKcKIPlQaIDTEVw8IorGOiTr uxI2wc8dRBAKXcplF1JuMpDYL8FfuTjKvE35+dkZq1952R+qpzhsrTwv6VSAo9bg1jJg OF0MDaintX6ty0ZODeKADNbMuC1kRcT5m4+DtwZy/Ho12Q49VJf6QMyix6upi4E1f1B0 g+qbZI2iTGz7hhvLd5IeUA9ZczvX5ZDZf/Mnp5j2THfxt8byDTN9RHPjeL99sCW/qdir 1CiQ== X-Gm-Message-State: AGRZ1gLBsWALI1RcBhyLQrMfE6EeUJKgPRA5LtY2wkSovowNc6W2xG/2 EHBYCLBCgMrvxv1EUI+8hl/j/w== X-Received: by 2002:a17:902:7c0b:: with SMTP id x11-v6mr20640642pll.60.1541399836850; Sun, 04 Nov 2018 22:37:16 -0800 (PST) Received: from localhost ([171.61.116.174]) by smtp.gmail.com with ESMTPSA id o83-v6sm30019326pfa.90.2018.11.04.22.37.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Nov 2018 22:37:16 -0800 (PST) From: Viresh Kumar To: ulf.hansson@linaro.org, "Rafael J. Wysocki" , Kevin Hilman , Pavel Machek , Len Brown Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , niklas.cassel@linaro.org, rnayak@codeaurora.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] PM / Domains: Save OPP table pointer in genpd Date: Mon, 5 Nov 2018 12:06:44 +0530 Message-Id: X-Mailer: git-send-email 2.19.1.568.g152ad8e3369a 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 We will need these going forward in hotpath, i.e. from within dev_pm_genpd_set_performance_state(). Lets fetch and save them while the OPP tables are added. Signed-off-by: Viresh Kumar --- drivers/base/power/domain.c | 23 +++++++++++++++++++++-- include/linux/pm_domain.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) -- 2.19.1.568.g152ad8e3369a diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 8e554e6a82a2..0d928359b880 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1907,12 +1907,21 @@ int of_genpd_add_provider_simple(struct device_node *np, ret); goto unlock; } + + /* + * Save table for faster processing while setting performance + * state. + */ + genpd->opp_table = dev_pm_opp_get_opp_table(&genpd->dev); + WARN_ON(!genpd->opp_table); } ret = genpd_add_provider(np, genpd_xlate_simple, genpd); if (ret) { - if (genpd->set_performance_state) + if (genpd->set_performance_state) { + dev_pm_opp_put_opp_table(genpd->opp_table); dev_pm_opp_of_remove_table(&genpd->dev); + } goto unlock; } @@ -1965,6 +1974,13 @@ int of_genpd_add_provider_onecell(struct device_node *np, i, ret); goto error; } + + /* + * Save table for faster processing while setting + * performance state. + */ + genpd->opp_table = dev_pm_opp_get_opp_table_indexed(&genpd->dev, i); + WARN_ON(!genpd->opp_table); } genpd->provider = &np->fwnode; @@ -1989,8 +2005,10 @@ int of_genpd_add_provider_onecell(struct device_node *np, genpd->provider = NULL; genpd->has_provider = false; - if (genpd->set_performance_state) + if (genpd->set_performance_state) { + dev_pm_opp_put_opp_table(genpd->opp_table); dev_pm_opp_of_remove_table(&genpd->dev); + } } mutex_unlock(&gpd_list_lock); @@ -2024,6 +2042,7 @@ void of_genpd_del_provider(struct device_node *np) if (!gpd->set_performance_state) continue; + dev_pm_opp_put_opp_table(gpd->opp_table); dev_pm_opp_of_remove_table(&gpd->dev); } } diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 642036952553..9ad101362aef 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -73,6 +73,7 @@ struct genpd_power_state { struct genpd_lock_ops; struct dev_pm_opp; +struct opp_table; struct generic_pm_domain { struct device dev; @@ -94,6 +95,7 @@ struct generic_pm_domain { unsigned int performance_state; /* Aggregated max performance state */ int (*power_off)(struct generic_pm_domain *domain); int (*power_on)(struct generic_pm_domain *domain); + struct opp_table *opp_table; /* OPP table of the genpd */ unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd, struct dev_pm_opp *opp); int (*set_performance_state)(struct generic_pm_domain *genpd,