From patchwork Tue Sep 19 22:32:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 113070 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp34728qgf; Tue, 19 Sep 2017 15:33:57 -0700 (PDT) X-Received: by 10.84.217.27 with SMTP id o27mr98159pli.339.1505860437389; Tue, 19 Sep 2017 15:33:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505860437; cv=none; d=google.com; s=arc-20160816; b=oKS14X1qiJlV5+fysuJXzmTJU2+t0nNTBAweN85dNUb0zbg4Hot4+T4XHtWR6O4iWb 904l0x02kF7rDimZsRKXJkpPbY8m1ADj3tZ+CDOd0a5J/fPRjSiN72za1+MJbc6kRC/K +0MC5ZobyzRbcOKko18oBtIy4OS8zF1ET+8wzkV7621me0fCOzn+PfQAaJhVcoC5Xw+Q NcyP0jphWciT56Eu+smUrE5t8Q/b6YGUzt8HpPHWnVVqxTG7GMNspvQVMp2ThcmG5kFH hjHzOytjwd+OSGq2BtXLtMs24aKbIs3QMpG8w8hq04tDff2QsYLsI6Uz3DK8tSGRIu/G lBEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=QnufuqY2MfSRVWRFA1lwc1lGASp65+sGryeN0sqeYbY=; b=fR7ILWjudIfLMoZDSYHWfczaF7AAzD2fF3Zxsb3hUy0ihKOOelyXsH29UucyAQTqln cAiABPmicWzEiSFiC+u7KNceyQzQn0RVF2TRIBTeXfE4Sr0c86xzhC63a3jqR2VsdTZP 1hHxhYStT6Z9GQCXjreq3jc8PJJAr8ccOqyRS5etsiusAcWeZ7Z8IelREInZj2l33av0 OJ1SDrwSZ++kCnLQJa4T3ZyCNr6zREQJKAjDsU79EYgi9TCw6+4IGG2t6nOtgsKv1yyN opII46zl/zFOuNlNEIJB97/jSj6RGql4OpAJWMWZ99v23cFHYmQEl7m/+6F4AQzNrT0o iGJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=icgv6W9W; 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 i5si229453plt.633.2017.09.19.15.33.57; Tue, 19 Sep 2017 15:33:57 -0700 (PDT) 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=icgv6W9W; 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 S1751873AbdISWdy (ORCPT + 26 others); Tue, 19 Sep 2017 18:33:54 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:47234 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751709AbdISWcm (ORCPT ); Tue, 19 Sep 2017 18:32:42 -0400 Received: by mail-pf0-f174.google.com with SMTP id u12so543384pfl.4 for ; Tue, 19 Sep 2017 15:32: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 :in-reply-to:references; bh=QnufuqY2MfSRVWRFA1lwc1lGASp65+sGryeN0sqeYbY=; b=icgv6W9WdwKuHqCuhQaTVGwIX8KRICc4nWKqAgnpBbjVUwY08s6Y+dukdnh+/iS6il quB2A/xstEt3EdIk1Yfc9PXnYuMJ2Vlx6Le80UBBX1OYJDAZ7X9Ai7xNbVRYPuk1zpU0 39G2QmFKXN9fSi9nHThFpFp2M6c+bc5C0B198= 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=QnufuqY2MfSRVWRFA1lwc1lGASp65+sGryeN0sqeYbY=; b=Aqfxl61pQnMwZ/3tMCjNeerbdNDAx3/KHIzR9IOJHByuf9oI8ZDIWY4BXR5MkLVc97 7k3G8JYmXf3z8m+dWlPrYy8frpqFJayeSUmwWYgIiCuFeaz+Ckpqre8DKe3ImJghgqOL e/3qgSznfWe/51JO9fvDN7AoiZ670w+qG97QfK94cJnF/Yk57oQqmIVBBkhstLOOtzAK OOTov7BGR64r60s/K6kWd3X7Rqy9QAfpgoHe1qCgyREnIRZ2H3j4cMA0c6irKUpoH9cF RUZk2EadR8xl3h6dcgL15ps2oQCEM0yjYgl1Y/A5ZX3/d2HbHrgPgLkvHay+w5iSbkzm wMrQ== X-Gm-Message-State: AHPjjUgLu4RHnAd9ZJ3/8UO6T/aYQ77K8U/nFsBJxteySZOULG+pE01X QhIxu2NKhWs+SOHaJ0RkgmEhXg== X-Google-Smtp-Source: AOwi7QCKBXTHEXQx1KYpR2bunZv8eMWPFx2Jh2n1ispD+kkWJVH2gK9ZqZDBTnSibzzmaUoiW+vvnw== X-Received: by 10.99.42.11 with SMTP id q11mr117439pgq.7.1505860361784; Tue, 19 Sep 2017 15:32:41 -0700 (PDT) Received: from localhost (cpe-172-88-64-62.socal.res.rr.com. [172.88.64.62]) by smtp.gmail.com with ESMTPSA id b65sm4626960pfg.30.2017.09.19.15.32.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Sep 2017 15:32:41 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ulf.hansson@linaro.org, Kevin Hilman Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Stephen Boyd , Nishanth Menon , robh+dt@kernel.org, lina.iyer@linaro.org, rnayak@codeaurora.org, sudeep.holla@arm.com, linux-kernel@vger.kernel.org, Len Brown , Pavel Machek , Andy Gross , David Brown Subject: [PATCH V10 3/7] PM / Domains: Catch missing genpd_set_performance_state() in masters Date: Tue, 19 Sep 2017 15:32:19 -0700 Message-Id: X-Mailer: git-send-email 2.7.4 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 This patch catches the cases where dev_get_performance_state() callback is implemented for a genpd, but none of its masters or their masters (and so on) have implemented genpd_set_performance_state() callback. The internal performance state routines don't return 0 anymore for success, rather they return count of the domains whose performance state is updated and the top level routine checks for that. A zero value there would indicate that the genpd_set_performance_state() callbacks are missing in the master hierarchy of the device. This adds very little burden on the API and can be pretty useful. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- Note that similar checks aren't present in other APIs in genpd, like genpd_power_on/off(). Maybe we should add some there as well? --- drivers/base/power/domain.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) -- 2.7.4 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 6d05c91cf44f..7e00b817abc7 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -264,13 +264,13 @@ EXPORT_SYMBOL_GPL(dev_pm_genpd_has_performance_state); static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd, int state, int depth); -/* Returns -ve errors or 0 on success */ +/* Returns -ve errors or number of domains whose performance is set */ static int _genpd_set_performance_state(struct generic_pm_domain *genpd, int state, int depth) { struct generic_pm_domain *master; struct gpd_link *link; - int prev = genpd->performance_state, ret; + int prev = genpd->performance_state, ret, count = 0; /* Propagate to masters of genpd */ list_for_each_entry(link, &genpd->slave_links, slave_node) { @@ -280,19 +280,23 @@ static int _genpd_set_performance_state(struct generic_pm_domain *genpd, link->performance_state = state; ret = _genpd_reeval_performance_state(master, state, depth + 1); - if (ret) + if (ret < 0) link->performance_state = prev; genpd_unlock(master); - if (ret) + if (ret < 0) goto err; + + count += ret; } if (genpd->genpd_set_performance_state) { ret = genpd->genpd_set_performance_state(genpd, state); if (ret) goto err; + + count++; } /* @@ -300,7 +304,7 @@ static int _genpd_set_performance_state(struct generic_pm_domain *genpd, * with those. */ genpd->performance_state = state; - return 0; + return count; err: /* Encountered an error, lets rollback */ @@ -310,7 +314,7 @@ static int _genpd_set_performance_state(struct generic_pm_domain *genpd, genpd_lock_nested(master, depth + 1); link->performance_state = prev; - if (_genpd_reeval_performance_state(master, prev, depth + 1)) { + if (_genpd_reeval_performance_state(master, prev, depth + 1) < 0) { pr_err("%s: Failed to roll back to %d performance state\n", master->name, prev); } @@ -345,7 +349,7 @@ static int _genpd_set_performance_state(struct generic_pm_domain *genpd, * - The locks are always taken in bottom->up order, i.e. subdomain first, * followed by its masters. * - * Returns -ve errors or 0 on success. + * Returns -ve errors or number of domains whose performance is set. */ static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd, int state, int depth) @@ -354,9 +358,14 @@ static int _genpd_reeval_performance_state(struct generic_pm_domain *genpd, struct pm_domain_data *pdd; struct gpd_link *link; - /* New requested state is same as Max requested state */ - if (state == genpd->performance_state) - return 0; + if (state == genpd->performance_state) { + /* + * New requested state is same as Max requested state, return 1 + * to distinguish from the case where none of the masters have + * set their genpd_set_performance_state() callback. + */ + return 1; + } /* New requested state is higher than Max requested state */ if (state > genpd->performance_state) @@ -444,7 +453,7 @@ int dev_pm_genpd_update_performance_state(struct device *dev, } ret = _genpd_reeval_performance_state(genpd, state, 0); - if (!ret) { + if (ret > 0) { /* * Since we are passing "state" to * _genpd_reeval_performance_state() as well, we don't need to @@ -453,6 +462,13 @@ int dev_pm_genpd_update_performance_state(struct device *dev, * state of master domain is updated. */ __genpd_dev_update_performance_state(dev, state); + ret = 0; + } else if (ret < 0) { + dev_err(dev, "Couldn't update performance state (%d)\n", ret); + } else { + WARN(1, "%s: None of %s and its masters have provided genpd_set_performance_state()\n", + __func__, genpd->name); + ret = -ENODEV; } unlock: @@ -471,7 +487,7 @@ static int _genpd_on_update_performance_state(struct generic_pm_domain *genpd, return 0; ret = _genpd_set_performance_state(genpd, prev, depth); - if (ret) { + if (ret < 0) { pr_err("%s: Failed to restore performance state to %d (%d)\n", genpd->name, prev, ret); } else { @@ -490,7 +506,7 @@ static void _genpd_off_update_performance_state(struct generic_pm_domain *genpd, return; ret = _genpd_set_performance_state(genpd, 0, depth); - if (ret) { + if (ret < 0) { pr_err("%s: Failed to set performance state to 0 (%d)\n", genpd->name, ret); } else {