From patchwork Wed Sep 19 22:20:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147049 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1232856ljw; Wed, 19 Sep 2018 15:20:48 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdaaxl3431P8KRgn+2fuLaVSa2oBZV296quB5ZHdarhK+D6wKP4xLYo0m3bSoyKZXZpm2QV/ X-Received: by 2002:a62:3909:: with SMTP id g9-v6mr37928541pfa.176.1537395648728; Wed, 19 Sep 2018 15:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395648; cv=none; d=google.com; s=arc-20160816; b=VEzYWYZfJplEjlc1CjtF+SSTpR7Xq27yLzAgw/suqFKwow53vxad+IfOKWIeVehEux z72NJIe8hC9ouz9tdR9ltgl8w8yNN+JSSx6wqJONDVlDl+tmlxtyILFqbuA0GzzXQl06 dC+oXS1qb8pybyhS1RLACTYUHyWbR/KQxBycMnZ8Kx5GjanS7isNSL0MWqTsUiI3aMZ6 v4xprLzsGLofgNR0jmzR5K7yDZccFBVhYzDmvQ6puOO2AMCWllj04Rg4i9pAcpHXg9/S LQ2dDyzzn7X+gz2AcZmv+uD+uhsz+mA2otUg969U0/CiSlCcOI928Mi6puzGxpYo3FD7 H6lA== 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; bh=/7A+jgDIUZCGxGLhoGYTieLMUMpj5eaMcqaxJhDr4YA=; b=y3g2Hg8+cvVUNn6GheXD3K/xwi38LUWDw8/+5pYhx5an47ogabyTYZrjys+vYuWPHk f8taLbiuAVLlndKu97liMb8l8ul6q9mD4EQ1df3KwWMDRXhmY88eDYoGLtAYLUPr3zJ1 wR+/3/FWmweWE+cIj9trnSuDbomH3Qe4JTkWGnLj4Z7IuQcUzVP37crhrqZwTNlF2xzA R9FwUvOqA385cade2fcuEvQofjhrLAOd00gv3soRrW0BnLzPbUH2ry8lh04WOD6yGlPW 4HpV6+TYKMMJGlByQM33oIHEtrRm2pC/ppL0w6fat7N594wxfkfnQZxMPJiBEPcul+/N nYzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BXitjeAa; 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 b30-v6si22112844pgm.389.2018.09.19.15.20.48; Wed, 19 Sep 2018 15:20:48 -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=BXitjeAa; 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 S1726296AbeITEAr (ORCPT + 32 others); Thu, 20 Sep 2018 00:00:47 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41893 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725784AbeITEAp (ORCPT ); Thu, 20 Sep 2018 00:00:45 -0400 Received: by mail-pf1-f196.google.com with SMTP id h79-v6so3343686pfk.8 for ; Wed, 19 Sep 2018 15:20:44 -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=/7A+jgDIUZCGxGLhoGYTieLMUMpj5eaMcqaxJhDr4YA=; b=BXitjeAafq8N0RjL/QUGy9m5AifOy3d1uuIkG/hOfeQrnNf1WzTljTy2lUbyaBJPfO KWqpu6n98jyuWmA6R4w0PI0OnZNlmgjAe6EbRFKFcFfc9UYON/AX0QI+KcTeF2k123a9 dNbuUEn9RMaKtaFqrXV+FqWr/1kr/Im2EfI5Q= 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=/7A+jgDIUZCGxGLhoGYTieLMUMpj5eaMcqaxJhDr4YA=; b=bjc0rKBmEH9u/MOLxA2YpCKcdjzTTpmXKeYcccQ47LDIoBlaJpfIpfU9JWgOHrO4qJ wRreMb5w+dZsEtt9ctx8gl7SJU0ItAJB0XeH7sMruoka6PIEf8vkBbBk5YRemJ7q3P9/ IrLvkizu7/bRnAA29j14s8GgtOtf2l566KJlV3eHnF7vzUhvH9/cGLcI3fViFOQQ8t+R Bu9yBB+748QT7EWWvomlK2UFjrRLwxpyoNjPxC73sRu9uN4ZH1fLWIrzXizYxZC1WB5F kdPWchpaf+f6mSCNnBR203yljf0SpoFU4bxvp+mj4oQOPMtsLtPGcDT4drD0ZMBdddOH o7pw== X-Gm-Message-State: APzg51D4v5QYkwAwHZIH30YWOv9S7ceacgMGR4oHoAP4Ku4gmICHX6fQ 65jlhblPuMfUWezA4YF7dCIdnA== X-Received: by 2002:a65:5284:: with SMTP id y4-v6mr32790902pgp.283.1537395644376; Wed, 19 Sep 2018 15:20:44 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id f13-v6sm21489306pgq.63.2018.09.19.15.20.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:43 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , "4 . 18" , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 01/12] OPP: Free OPP table properly on performance state irregularities Date: Wed, 19 Sep 2018 15:20:20 -0700 Message-Id: <2fbb8670b4ff4454f1c0de510f788d737edc4b90.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 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 OPP table was freed, but not the individual OPPs which is done from _dev_pm_opp_remove_table(). Fix it by calling _dev_pm_opp_remove_table() as well. Cc: 4.18 # v4.18 Fixes: 3ba98324e81a ("PM / OPP: Get performance state using genpd helper") Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 1 + 1 file changed, 1 insertion(+) -- 2.14.1 diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 7af0ddec936b..20988c426650 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -425,6 +425,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) dev_err(dev, "Not all nodes have performance state set (%d: %d)\n", count, pstate_count); ret = -ENOENT; + _dev_pm_opp_remove_table(opp_table, dev, false); goto put_opp_table; } From patchwork Wed Sep 19 22:20:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147051 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1232938ljw; Wed, 19 Sep 2018 15:20:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaWKus5jPUbNLI6jaGllYt8K6NaTpP59pVozIDr2Vg8z4FGsCwExG1gxRFrDoGaMPIUd59r X-Received: by 2002:a62:6a01:: with SMTP id f1-v6mr37911060pfc.156.1537395653440; Wed, 19 Sep 2018 15:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395653; cv=none; d=google.com; s=arc-20160816; b=rTmo2Uj18Z2jaxgcvpop8U2iZP9bh7i6ncRb6DuqE/VcVzU96J5neFIvOmvyRF9Xs3 SOXoyBSiLkyh4VjN6F0oTh8WFwIpnfjdic6teVGLZmvhJlG63owPh8TYkk8eoT72DnIo woyjyWb12vNjrnaIJATKoSMB1c9K/LG9+9aYR9fog4ShzC/s/B9plFlFyJgRczmDUIf/ YXVSSmFqeeJojOjrqbrf1sSrQgmJQy6kbe8sZxOYMbEsVZv6h+u+mmxAZKLzQ59aNlO7 H2bjtx4mhZY2HURCCc3WjjVDHoPUnsK18M+ePaV/QFccTf40LepoTa/jO4pM0LyNIEXG PR4g== 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; bh=+qw1WHdkun9NT16a0EkMQe8eVOqrEPq24qtM3EnA0WM=; b=tKw6PBq4+XoFAccGsMZVTOMPexkwnNF6iL7a1HN8hcoSNuLLNuFCpGvZ5dZ6VezXRI kMtaOfz2FAmXGn69rcMTmMjXgyXp7Ms+z5WFmhcnCaOR6OJFfFsItmfsw2MNm+MFig0G cD5449CY6B9Xr8OBUE76IfaFW7zn+gLc9eAHM2CvQztdlCItTsC25+CIuuxwmBZ+W7hM hRacktiNnuYznEusDSN3JfpHMRAPXaiE6XL71j60qBKEYd/0P4tGFcToGBLAD509ThgA 7mibNQY8r1XHuGPeY4Mn9Thw291FzvBwsCW8EbVxQyB0QQ3RrSkJVew2duTRFcgvC7/j 8Zlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N7qKUtGR; 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 r34-v6si22350170pgb.656.2018.09.19.15.20.52; Wed, 19 Sep 2018 15:20:53 -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=N7qKUtGR; 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 S1732960AbeITEAv (ORCPT + 32 others); Thu, 20 Sep 2018 00:00:51 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:36810 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728124AbeITEAt (ORCPT ); Thu, 20 Sep 2018 00:00:49 -0400 Received: by mail-pl1-f195.google.com with SMTP id p5-v6so3305976plk.3 for ; Wed, 19 Sep 2018 15:20:49 -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=+qw1WHdkun9NT16a0EkMQe8eVOqrEPq24qtM3EnA0WM=; b=N7qKUtGRcs8B8Xx/g9uYzFVy1r8dhJsiLpibsY278uGTZ/Argo3cU52+D0Tu52336f 9P5KRj/dchx8/qRWJ9lhmvRj/SqI/QJaF19LpniElgWN472BjJwdMSor+5GDMNK9RH6v VoQzaSlIL7MZK1v3CR48y8VppWW3aOnAbqctk= 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=+qw1WHdkun9NT16a0EkMQe8eVOqrEPq24qtM3EnA0WM=; b=omo9Q3PEt6iPUv1dGHR0cUX2Ar9CNNGt3hB6Wc3XtY0x24+PH7Nz4zXvPEOm5RBA0C s56rfu9G3jrN7BoTQZPGOsVQQp6W0dYHLyK/+U0q+CGhz31qHc2EyOqZMwo4Dgxi6zPk gA8AfQTO7Bg5FOklvVGDYDiTpRIrMOkiFVJCAIFgtGXD+YiYsidGWw2d6OTTqT1JbrNi lW0qfCsgr7uVZhooID9Bly5sfUbElcDmULQhL+33WxmWWLmxLv40HV1DDR2Q8qw83Oli yqLZ7nj4geWHcDORtA8skislAkN/Ip98qsMCXPsqRFOJIyKO1qCOOwlWlZ7N1+xAic+x uKgw== X-Gm-Message-State: APzg51CBRbAehofawKSie+7dEakWY+kSjLwthBAyiw3hXd/tGQiKvplC tNWY+DKpCeUZfXwp5wDxU/+FQw== X-Received: by 2002:a17:902:2f43:: with SMTP id s61-v6mr35459595plb.176.1537395649068; Wed, 19 Sep 2018 15:20:49 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id k26-v6sm39170825pfb.167.2018.09.19.15.20.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:48 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 04/12] OPP: Pass index to _of_init_opp_table() Date: Wed, 19 Sep 2018 15:20:23 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 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 is a preparatory patch required for the next commit which will start using OPP table's node pointer in _of_init_opp_table(), which requires the index in order to read the OPP table's phandle. This commit adds the index argument in the call chains in order to get it delivered to _of_init_opp_table(). Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 19 +++++++++++++++---- drivers/opp/of.c | 12 +++++++----- drivers/opp/opp.h | 4 ++-- include/linux/pm_opp.h | 6 ++++++ 4 files changed, 30 insertions(+), 11 deletions(-) -- 2.14.1 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 9f8aa31265fe..332748adc262 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -785,7 +785,7 @@ struct opp_device *_add_opp_dev(const struct device *dev, return opp_dev; } -static struct opp_table *_allocate_opp_table(struct device *dev) +static struct opp_table *_allocate_opp_table(struct device *dev, int index) { struct opp_table *opp_table; struct opp_device *opp_dev; @@ -808,7 +808,7 @@ static struct opp_table *_allocate_opp_table(struct device *dev) return NULL; } - _of_init_opp_table(opp_table, dev); + _of_init_opp_table(opp_table, dev, index); /* Find clk for the device */ opp_table->clk = clk_get(dev, NULL); @@ -833,7 +833,7 @@ void _get_opp_table_kref(struct opp_table *opp_table) kref_get(&opp_table->kref); } -struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) +static struct opp_table *_opp_get_opp_table(struct device *dev, int index) { struct opp_table *opp_table; @@ -844,15 +844,26 @@ struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) if (!IS_ERR(opp_table)) goto unlock; - opp_table = _allocate_opp_table(dev); + opp_table = _allocate_opp_table(dev, index); unlock: mutex_unlock(&opp_table_lock); return opp_table; } + +struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) +{ + return _opp_get_opp_table(dev, 0); +} EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table); +struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, + int index) +{ + return _opp_get_opp_table(dev, index); +} + static void _opp_table_kref_release(struct kref *kref) { struct opp_table *opp_table = container_of(kref, struct opp_table, kref); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 86222586f27b..1a9e1242a2a7 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -52,7 +52,8 @@ static struct opp_table *_managed_opp(const struct device_node *np) return managed_table; } -void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) +void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, + int index) { struct device_node *np; @@ -378,7 +379,8 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, } /* Initializes OPP tables based on new bindings */ -static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) +static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, + int index) { struct device_node *np; struct opp_table *opp_table; @@ -393,7 +395,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) goto put_opp_table; } - opp_table = dev_pm_opp_get_opp_table(dev); + opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); if (!opp_table) return -ENOMEM; @@ -526,7 +528,7 @@ int dev_pm_opp_of_add_table(struct device *dev) return _of_add_opp_table_v1(dev); } - ret = _of_add_opp_table_v2(dev, opp_np); + ret = _of_add_opp_table_v2(dev, opp_np, 0); of_node_put(opp_np); return ret; @@ -574,7 +576,7 @@ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) return -ENODEV; } - ret = _of_add_opp_table_v2(dev, opp_np); + ret = _of_add_opp_table_v2(dev, opp_np, index); of_node_put(opp_np); return ret; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 88e9f47aadf1..b235e76fc8cc 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -200,9 +200,9 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, in struct opp_table *_add_opp_table(struct device *dev); #ifdef CONFIG_OF -void _of_init_opp_table(struct opp_table *opp_table, struct device *dev); +void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index); #else -static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {} +static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {} #endif #ifdef CONFIG_DEBUG_FS diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 099b31960dec..5d399eeef172 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -79,6 +79,7 @@ struct dev_pm_set_opp_data { #if defined(CONFIG_PM_OPP) struct opp_table *dev_pm_opp_get_opp_table(struct device *dev); +struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index); void dev_pm_opp_put_opp_table(struct opp_table *opp_table); unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); @@ -136,6 +137,11 @@ static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev) return ERR_PTR(-ENOTSUPP); } +static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index) +{ + return ERR_PTR(-ENOTSUPP); +} + static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {} static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) From patchwork Wed Sep 19 22:20:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147052 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1232960ljw; Wed, 19 Sep 2018 15:20:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbTS0MQAGwwE3yvv9vSNKZSBRaTOiRb9pz4PLsHnKhrqjZIepxrvN8RO3ZahNmxmwKsmjYs X-Received: by 2002:a62:642:: with SMTP id 63-v6mr38271335pfg.42.1537395655044; Wed, 19 Sep 2018 15:20:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395655; cv=none; d=google.com; s=arc-20160816; b=bROOm3gwkiZe9Qmj3xinu5/N6VkHMux6OeXg/p988OPwfZHBddVtEmNOV2meEN+OPz +g9tvHKhaWYBp6UinaNVp2BTpZO9oaIQNXksDrVq65pBx3UKRdV753Tn8oqz9y+y3tJh p3g1I/bjfggfHCPF77J4MqeAgEnwqyIdkKZiealFQNmqo5djVzi4j+wExlRvF+dtzbus 396dSlaskNl/emaIY1D8vOnfQ3tR8aGkVFS8BaAW49KNEPeb35Ij7XpXLw41AmyCWgPr ZMhRNfZivGlhlPPIRy5pdlR6FbnZvpnlz9CUwx+d2thY3dEvD+m/8GU75lg5wFgI8n7n o26Q== 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; bh=6ebVYraCbWvrsnGm3xtUNzVrcWRfL2zqlZLpD6LOi2s=; b=ZuClWWaqcFHHMkTDgb//CQLxIICn2QGlBeMQrEuLRyQHjajWDH0/bdPqziMvOi+taL 4y91SkZZHeNo1pFFdDIyvhCQXOzJ7tX+bh4QsYMUYJUtkWTNHSqACJxKyOMetQoxxRam xPz8vWIehrUBnrJuWBoZvN0ilCNjZCqnD8Gbh+UJgT+4wtiEfFSkvXLqZaKmvTfyQS91 ioZX369nUnHRKPpsqpKA9JIi2nC7tNA2bFpsGC79PYFo0ZBaK0KxV5Fk++nbSI5njq66 ksnrNYv56l5qSDt8wvM+lr5e3B38GLM36wZ5Z+eJq47ChqZMs4F6I11fqmTfwP+Zk67w i6ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dxjJqa1v; 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 n8-v6si22034915pgl.101.2018.09.19.15.20.54; Wed, 19 Sep 2018 15:20:55 -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=dxjJqa1v; 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 S1733243AbeITEAw (ORCPT + 32 others); Thu, 20 Sep 2018 00:00:52 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33633 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731782AbeITEAv (ORCPT ); Thu, 20 Sep 2018 00:00:51 -0400 Received: by mail-pg1-f195.google.com with SMTP id y18-v6so93034pge.0 for ; Wed, 19 Sep 2018 15:20:50 -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=6ebVYraCbWvrsnGm3xtUNzVrcWRfL2zqlZLpD6LOi2s=; b=dxjJqa1vvwPFcHa03u/ywqzWZVjSAg+zQ0FUfhWhg+CmV6zWPXiDg3FTuIg/a0YyKI 4YVIOIxjGAif2hAns3p6bTfCickHn0wwirtX58hXnPGGb1t/6shCyxGqOmSI8z+8eZVK dmbmYz3dZ2xnncmMbnMPyAifJLoOg2CG1zSzs= 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=6ebVYraCbWvrsnGm3xtUNzVrcWRfL2zqlZLpD6LOi2s=; b=B1vXiyfF4mVgwfFRgkIdppZashqcKWuA78kjJwecBm6JaTbHKAB8ni1b328bmHd+m2 mAkC9lRK7qfgiR2AydgK7p+PAqPY1sAzO60dlC9FkK7EtYsbFl7H6TeHOnLoED616JH5 cZHniOMbrxV26ZFvTME/uh6GHX2Fk8kpFA6UDTQ2G+YmjlwlWdfNexqGYi8LC01wZlbP tJFMikMCHiWxSScrGqg9KD7gReJFu90Q9BgFGIQpJsl2SspBLDLfie85I7ISKCwlE8Cy lSiAngREsC71U6wA7izYxdwLlEytJHppgTzW6A9j4kQBZkOiaF1ukPkCpHuZGsCFjGL1 RQFQ== X-Gm-Message-State: APzg51CmGx0NIzc7gvnK8f5gaxrH5rU6/C0tCmAmiKVQCmua+VsYcbN7 UDob00Gz9x8M1m08+4WgfLqB4w== X-Received: by 2002:a62:438f:: with SMTP id l15-v6mr38615178pfi.196.1537395650494; Wed, 19 Sep 2018 15:20:50 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id u184-v6sm41809554pgd.46.2018.09.19.15.20.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:49 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 05/12] OPP: Parse OPP table's DT properties from _of_init_opp_table() Date: Wed, 19 Sep 2018 15:20:24 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 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 Parse the DT properties present in the OPP table from _of_init_opp_table(), which is a dedicated routine for DT parsing. Minor relocation of helpers is required for this. It is possible now for _managed_opp() to return a partially initialized OPP table if the OPP table is created via the helpers like dev_pm_opp_set_supported_hw() and we need another flag to indicate if the static OPP are already parsed or not to make sure we don't incorrectly skip initializing the static OPPs. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 79 +++++++++++++++++++++++++++++++++---------------------- drivers/opp/opp.h | 2 ++ 2 files changed, 50 insertions(+), 31 deletions(-) -- 2.14.1 diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 1a9e1242a2a7..4a19f76880d3 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -23,6 +23,24 @@ #include "opp.h" +/* + * Returns opp descriptor node for a device node, caller must + * do of_node_put(). + */ +static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np, + int index) +{ + /* "operating-points-v2" can be an array for power domain providers */ + return of_parse_phandle(np, "operating-points-v2", index); +} + +/* Returns opp descriptor node for a device, caller must do of_node_put() */ +struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) +{ + return _opp_of_get_opp_desc_node(dev->of_node, 0); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node); + static struct opp_table *_managed_opp(const struct device_node *np) { struct opp_table *opp_table, *managed_table = NULL; @@ -55,22 +73,37 @@ static struct opp_table *_managed_opp(const struct device_node *np) void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) { - struct device_node *np; + struct device_node *np, *opp_np; + u32 val; /* * Only required for backward compatibility with v1 bindings, but isn't * harmful for other cases. And so we do it unconditionally. */ np = of_node_get(dev->of_node); - if (np) { - u32 val; - - if (!of_property_read_u32(np, "clock-latency", &val)) - opp_table->clock_latency_ns_max = val; - of_property_read_u32(np, "voltage-tolerance", - &opp_table->voltage_tolerance_v1); - of_node_put(np); - } + if (!np) + return; + + if (!of_property_read_u32(np, "clock-latency", &val)) + opp_table->clock_latency_ns_max = val; + of_property_read_u32(np, "voltage-tolerance", + &opp_table->voltage_tolerance_v1); + + /* Get OPP table node */ + opp_np = _opp_of_get_opp_desc_node(np, index); + of_node_put(np); + + if (!opp_np) + return; + + if (of_property_read_bool(opp_np, "opp-shared")) + opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; + else + opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; + + opp_table->np = opp_np; + + of_node_put(opp_np); } static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table, @@ -250,22 +283,6 @@ void dev_pm_opp_of_remove_table(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); -/* Returns opp descriptor node for a device node, caller must - * do of_node_put() */ -static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np, - int index) -{ - /* "operating-points-v2" can be an array for power domain providers */ - return of_parse_phandle(np, "operating-points-v2", index); -} - -/* Returns opp descriptor node for a device, caller must do of_node_put() */ -struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) -{ - return _opp_of_get_opp_desc_node(dev->of_node, 0); -} -EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node); - /** * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings) * @opp_table: OPP table @@ -392,6 +409,9 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, /* OPPs are already managed */ if (!_add_opp_dev(dev, opp_table)) ret = -ENOMEM; + else if (!opp_table->parsed_static_opps) + goto initialize_static_opps; + goto put_opp_table; } @@ -399,6 +419,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, if (!opp_table) return -ENOMEM; +initialize_static_opps: /* We have opp-table node now, iterate over it and add OPPs */ for_each_available_child_of_node(opp_np, np) { count++; @@ -434,11 +455,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, if (pstate_count) opp_table->genpd_performance_state = true; - opp_table->np = opp_np; - if (of_property_read_bool(opp_np, "opp-shared")) - opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; - else - opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE; + opp_table->parsed_static_opps = true; put_opp_table: dev_pm_opp_put_opp_table(opp_table); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index b235e76fc8cc..b04c2b511c4d 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -129,6 +129,7 @@ enum opp_table_access { * @lock: mutex protecting the opp_list and dev_list. * @np: struct device_node pointer for opp's DT node. * @clock_latency_ns_max: Max clock latency in nanoseconds. + * @parsed_static_opps: True if OPPs are initialized from DT. * @shared_opp: OPP is shared between multiple devices. * @suspend_opp: Pointer to OPP to be used during device suspend. * @supported_hw: Array of version number to support. @@ -164,6 +165,7 @@ struct opp_table { /* For backward compatibility with v1 bindings */ unsigned int voltage_tolerance_v1; + bool parsed_static_opps; enum opp_table_access shared_opp; struct dev_pm_opp *suspend_opp; From patchwork Wed Sep 19 22:20:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147053 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1232966ljw; Wed, 19 Sep 2018 15:20:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYhaW0dt/+46jqyIlPlOH59i9hQuM3cqeL4FBtmaPFZuTqAdd7jGt51GZlRyApvVq87mSzp X-Received: by 2002:a63:5204:: with SMTP id g4-v6mr33813925pgb.274.1537395655513; Wed, 19 Sep 2018 15:20:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395655; cv=none; d=google.com; s=arc-20160816; b=J3YkHePA4FocHgnUNxXDex1chAq/rTPUeVynNpMhlZcID8kp1gd0+U9xouoAq+8R/D c8bakQuUAVGZVaYSsm4xhCV5e/efcFfYlknR9fS8CoplmXtPNa6WlUKqyZXvAarcx/lb dCbgphLFlTT3RuY3BdOtkpQhEVfW7wG7Imkd5ImzfdMs1uozbq8xClj8QniJB/TnMmvV TUft2c/nKxevqTvOvmJys2Eru4o+eJ8LQm0tGR2ZS8ZBJMvTyvYAOuMG+Bq6xwY48oCD TB41sqv1Kl6oKZL45cD32EzPhJF0NXf060BNzvgZLUCUVSyxVXpE5LM874wDBZ+RCWJU SB2Q== 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; bh=WirGS/aOSjVS/D7R/G1/ncvS7OJ05Sy4IF/d4iCNwD8=; b=CK9SOIzsVzqj/sFtJoEcFn5Igqrg7uXSwDEPR8mLDhtB3iHliqHGS0yNOzl8IxUaQV aifI9mCXEBnzY5bMza/fPcFFE6T02BCF3IuY1fPSauSTMAylDUv0UKfKEFMM6af62QYB 0VtsoRVqsijehPvZsKE4ke1AGIf+jKTBmCgfuHS9EO8WUV6jgAK0x1KY8hGAuPcn5lCC sfCs2G/JdyGPfKXtR5lWzv9Af+qEczTwM5h0WE6O0l8AG0VZYN1K9g0DcEqKcoynauP7 GEkFT7VKhqXFSW7DI4/4unANMaaiDvAy/z1TTOEfVtjvTaEKOnsDeLLr2Dgl5kszvDo3 LuxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fha9ep2Y; 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 n8-v6si22034915pgl.101.2018.09.19.15.20.55; Wed, 19 Sep 2018 15:20:55 -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=fha9ep2Y; 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 S1733308AbeITEAx (ORCPT + 32 others); Thu, 20 Sep 2018 00:00:53 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34461 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733245AbeITEAw (ORCPT ); Thu, 20 Sep 2018 00:00:52 -0400 Received: by mail-pf1-f194.google.com with SMTP id k19-v6so3357982pfi.1 for ; Wed, 19 Sep 2018 15:20:52 -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=WirGS/aOSjVS/D7R/G1/ncvS7OJ05Sy4IF/d4iCNwD8=; b=fha9ep2Y2vw9rRqF09AyZZ8ZlWVXYyqZM5Q1h0q2YhrXNxungj8Mdm1ZHZySaVzJhc J+Ri+e9fLBrHNL2/yyYo0LthjssGM3j1zS4ucn4QdKyXKt7VlCj9ciQV4SZYwySjCJsA HGSoI8N3t286OoUVhOaHKirL8HjtFU3cDhem4= 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=WirGS/aOSjVS/D7R/G1/ncvS7OJ05Sy4IF/d4iCNwD8=; b=fcGJNoBtL+KzMjcUOIE4Xb0PrfmHHJ5FJnk9Z4j96/2l0orm+dlSi1nNP5FjgxCBG+ c3vE0hsy7d0A8ZmwNqBk2yJvMxOb8ljeTYHRiQ9UBWCJfv8c7JMqmCZsU2d1/I8Z5BVl J09ypXnyqYD/V2B02LwfcxsJd4PH+xLWP06UaUuYkN9rVRQ2B01KeDbi17PUPFFPNgKo Ll5ekcMzwBpHoMKTuE/qCzYXb7kJ+EtGmX9wUV2c+R9oNyIMJ7kWtsTAQ9EfArLkjrxa EWchUbehaFjDjEYDRaKSNqfTTb3EASH9CQOK0WtrnITqfUMNbPu/IFV7GDo1UXpNZSb0 tFFA== X-Gm-Message-State: APzg51CaAuUYMcMxYQ/CeoehL9k9pPrkZZSDHlpyZ6UKFhKns/fl6hxO VgQGuTjDarJOZuJFZKv7TbIyVA== X-Received: by 2002:a63:5204:: with SMTP id g4-v6mr33813789pgb.274.1537395651939; Wed, 19 Sep 2018 15:20:51 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id w16-v6sm53798471pfi.101.2018.09.19.15.20.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:51 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 06/12] OPP: Don't take OPP table's kref for static OPPs Date: Wed, 19 Sep 2018 15:20:25 -0700 Message-Id: <0ad8c623907c27f4b8572d36c4ba73ea103e3108.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 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 reference count is only required to be incremented for every call that may lead to adding the OPP table. For static OPPs the same should be done from the parent routine which adds all static OPPs together and so only one refcount for all static OPPs. Update code to reflect that. The refcount is incremented every time a dynamic OPP is created (as that can lead to creating the OPP table) and the same is dropped when the OPP is removed. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.14.1 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 332748adc262..2a6976265580 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -919,7 +919,6 @@ static void _opp_kref_release(struct kref *kref) kfree(opp); mutex_unlock(&opp_table->lock); - dev_pm_opp_put_opp_table(opp_table); } void dev_pm_opp_get(struct dev_pm_opp *opp) @@ -963,11 +962,15 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) if (found) { dev_pm_opp_put(opp); + + /* Drop the reference taken by dev_pm_opp_add() */ + dev_pm_opp_put_opp_table(opp_table); } else { dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n", __func__, freq); } + /* Drop the reference taken by _find_opp_table() */ dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove); @@ -1085,9 +1088,6 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, new_opp->opp_table = opp_table; kref_init(&new_opp->kref); - /* Get a reference to the OPP table */ - _get_opp_table_kref(opp_table); - ret = opp_debug_create_one(new_opp, opp_table); if (ret) dev_err(dev, "%s: Failed to register opp to debugfs (%d)\n", @@ -1566,8 +1566,9 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) return -ENOMEM; ret = _opp_add_v1(opp_table, dev, freq, u_volt, true); + if (ret) + dev_pm_opp_put_opp_table(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_add); From patchwork Wed Sep 19 22:20:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147054 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233043ljw; Wed, 19 Sep 2018 15:20:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYImI1m0iOXoQ/GEwsPRSZa90eLubMYUZco3ACi+37IX8Y80/7EqsexHZi89Qxoz49XSh2F X-Received: by 2002:a17:902:1566:: with SMTP id b35-v6mr36097318plh.135.1537395659752; Wed, 19 Sep 2018 15:20:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395659; cv=none; d=google.com; s=arc-20160816; b=T2N5BoP3xQTAjqTTPdM8ODuIGl8BxfaWn6kSwpyJwVAn7L4xkbdrS+D5du/Rh4dxgT Yyvn/WwQ0Kj91nPscZjUprEr180bNilNA1wFt4r0SL6Q9fKFAnYjMJGuCkH6kd0DkI6R mm8oH4wCXyBD0H92dvQIPKhFJr2JLb6OUHf/PLltDKSB/vjLOkLcrBDrIVDr7rgIb6rA MuK6DuHXB8aWHvLvyf/TW2f2d4uw24xoxgb8ZxIUM5EJYfNreV07DstrDkNOOp6++1ET wwYJGMQxc+Z6ato5vHLD9wMzIlyf0VIrwNAVw/tqE5g3yp5MS3tu0Sj6/B0/uaGV5M0a oyDA== 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; bh=HX5eDqLq6MnZX9E6B4v/vOFT0a/x+hzpVnpPDmao/5Y=; b=dekf8ruSsndW1zB60ktYISyrmE+lGcTr8Z9nqGjXUJP8v3Zn5g072rBf5QM9C2VSN9 wWCkeWPAa+2MEilatawQmKCvrja7+Si+ObD9j2fO3vEx1N7Gqbff2faXkgc4KwiNlhd+ 2vzdYrswtTzfJB9qAU4IArOj2dSjWk1AYpekZvGKDlM/CmNCjVpnqHd3o3qLd76N4Sam y4977krmITarzmKN+Vaf12gh5mAU5XVXfKlJMlzaAyYhHGxs+mCTwGJZoSNd+zAQC3t4 7qBJ/HAx5X86lEd/VreBlX9Annjd1T9L+/ntNCeMtBpKVQejFJG/STB/ObwU+BA30f42 DDsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iVliWPLg; 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 n8-v6si22034915pgl.101.2018.09.19.15.20.57; Wed, 19 Sep 2018 15:20:59 -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=iVliWPLg; 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 S2387432AbeITEA4 (ORCPT + 32 others); Thu, 20 Sep 2018 00:00:56 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:38946 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387399AbeITEAy (ORCPT ); Thu, 20 Sep 2018 00:00:54 -0400 Received: by mail-pl1-f193.google.com with SMTP id w14-v6so3300416plp.6 for ; Wed, 19 Sep 2018 15:20:53 -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=HX5eDqLq6MnZX9E6B4v/vOFT0a/x+hzpVnpPDmao/5Y=; b=iVliWPLgAZaeCvinWz/oXkCKCEBJw1rChrOeNhddY1LOHXqe/CHuwAQXYj44J7S12i 25l3DV1zAWvCPZDDN2CY767iL2caYnqVIbfSnFHr2mi9KdLXlxPYhe3FgFRarJGxxYIf F4zcVTyNjt0kBVeOH86pNmt/0oVYwvXw5XY0Q= 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=HX5eDqLq6MnZX9E6B4v/vOFT0a/x+hzpVnpPDmao/5Y=; b=ncWtmbuuNw6yI9sQXeJbqS1RX1ifM8h4n9WJEEIChyrGLuNw5rdC/F8QJEWwCcGFz8 dm1gnyLpjX93O8JQh46TWOaiYemeSQiPoMsMkO/9TVP8ZPcbP3Cnx2+7GrfYnF7wvSzG oGI0HwPIWzNg2GZbemJKSXBdt06gQa1Z7V74DWbF20YQEqX5NEe1Hhb/eTLTXx0PxZkF 4xIzVLdo8XH4UOO7GKLuCwqJS/V1mgmQFVhUrbu7vWnQWJeCL790kOzqjZB1isYtydEf RgY8zkLAUqL+E3aWzbV+ARR8MPje2stqtu47ejwVSaeNS0ZOir81fQvF9Yqhkyuy3PYG r2rg== X-Gm-Message-State: APzg51DVTQoMmBK31zkMAIu8jIvyDm0S4U7uEkK3kHkpdH2IA2Ib8X18 P7yc0s8OfrvUPl7yUorqz0Kvaw== X-Received: by 2002:a17:902:e281:: with SMTP id cf1-v6mr36276933plb.86.1537395653568; Wed, 19 Sep 2018 15:20:53 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id x9-v6sm33824822pfd.31.2018.09.19.15.20.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:52 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 07/12] OPP: Create separate kref for static OPPs list Date: Wed, 19 Sep 2018 15:20:26 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 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 static OPPs don't always get freed with the OPP table, it can happen before that as well. For example, if the OPP table is first created using helpers like dev_pm_opp_set_supported_hw() and the OPPs are created at a later point. Now when the OPPs are removed, the OPP table stays until the time dev_pm_opp_put_supported_hw() is called. Later patches will streamline the freeing of OPP table and that requires the static OPPs to get freed with help of a separate kernel reference. This patch prepares for that by creating a separate kref for static OPPs list. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 33 ++++++++++++++++++++++++++++++++- drivers/opp/of.c | 7 +++++++ drivers/opp/opp.h | 3 +++ 3 files changed, 42 insertions(+), 1 deletion(-) -- 2.14.1 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2a6976265580..b555121b878b 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -892,6 +892,33 @@ static void _opp_table_kref_release(struct kref *kref) mutex_unlock(&opp_table_lock); } +void _opp_remove_all_static(struct opp_table *opp_table) +{ + struct dev_pm_opp *opp, *tmp; + + list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { + if (!opp->dynamic) + dev_pm_opp_put(opp); + } + + opp_table->parsed_static_opps = false; +} + +static void _opp_table_list_kref_release(struct kref *kref) +{ + struct opp_table *opp_table = container_of(kref, struct opp_table, + list_kref); + + _opp_remove_all_static(opp_table); + mutex_unlock(&opp_table_lock); +} + +void _put_opp_list_kref(struct opp_table *opp_table) +{ + kref_put_mutex(&opp_table->list_kref, _opp_table_list_kref_release, + &opp_table_lock); +} + void dev_pm_opp_put_opp_table(struct opp_table *opp_table) { kref_put_mutex(&opp_table->kref, _opp_table_kref_release, @@ -1746,8 +1773,11 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, /* Find if opp_table manages a single device */ if (list_is_singular(&opp_table->dev_list)) { /* Free static OPPs */ + _put_opp_list_kref(opp_table); + + /* Free dynamic OPPs */ list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { - if (remove_all || !opp->dynamic) + if (remove_all) dev_pm_opp_put(opp); } @@ -1758,6 +1788,7 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, if (opp_table->genpd_performance_state) dev_pm_genpd_set_performance_state(dev, 0); } else { + _put_opp_list_kref(opp_table); _remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table); } diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 4a19f76880d3..aaa4bab69846 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -411,6 +411,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, ret = -ENOMEM; else if (!opp_table->parsed_static_opps) goto initialize_static_opps; + else + kref_get(&opp_table->list_kref); goto put_opp_table; } @@ -420,6 +422,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, return -ENOMEM; initialize_static_opps: + kref_init(&opp_table->list_kref); + /* We have opp-table node now, iterate over it and add OPPs */ for_each_available_child_of_node(opp_np, np) { count++; @@ -437,6 +441,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, /* There should be one of more OPP defined */ if (WARN_ON(!count)) { ret = -ENOENT; + _put_opp_list_kref(opp_table); goto put_opp_table; } @@ -491,6 +496,8 @@ static int _of_add_opp_table_v1(struct device *dev) if (!opp_table) return -ENOMEM; + kref_init(&opp_table->list_kref); + val = prop->value; while (nr) { unsigned long freq = be32_to_cpup(val++) * 1000; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index b04c2b511c4d..9274116c90e4 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -126,6 +126,7 @@ enum opp_table_access { * @dev_list: list of devices that share these OPPs * @opp_list: table of opps * @kref: for reference count of the table. + * @list_kref: for reference count of the OPP list. * @lock: mutex protecting the opp_list and dev_list. * @np: struct device_node pointer for opp's DT node. * @clock_latency_ns_max: Max clock latency in nanoseconds. @@ -157,6 +158,7 @@ struct opp_table { struct list_head dev_list; struct list_head opp_list; struct kref kref; + struct kref list_kref; struct mutex lock; struct device_node *np; @@ -200,6 +202,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *o int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, int last_cpu); struct opp_table *_add_opp_table(struct device *dev); +void _put_opp_list_kref(struct opp_table *opp_table); #ifdef CONFIG_OF void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index); From patchwork Wed Sep 19 22:20:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147055 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233050ljw; Wed, 19 Sep 2018 15:21:00 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ5NiEWBNAaMK9igEBQQ59h31javtlYl0x61a59gURQJuJmPNhkVE9yKcgLv0hp83O7Bsko X-Received: by 2002:a65:5545:: with SMTP id t5-v6mr33923867pgr.157.1537395660219; Wed, 19 Sep 2018 15:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395660; cv=none; d=google.com; s=arc-20160816; b=paoTYUM/kNePngYbQ0ve2E0ANk7G8gthNu8lsaEau7DfvApHQP0Nw2sdEwnhTpRu/2 a5AG/khcI3WnoeOrayWfiiD2WVKUXHZiMWB2sfCHGyAj6ytME8yOjGEsrXvmuG1o8MyF blN3MaM50cnJNoEhZQRdzLMnaUDQmE/NLwxfzjxRUiHuQ6+H2PqL8xlZK4fe3TQCP7l4 osn8cxF9PeccGo4Wnd+ZBJsV89HDP1HaXm3R6au3k0hAnvrg04IUOqhrzujgDsXj1DEg InZp9AyyV/brHvHLvfn5YjEvGjZWIPLl6JNiEmhG/XyhXQtxtH8TYgqINO16CyRdEXVx djpQ== 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; bh=25gV/yr+DQaieOUd7LXdpHMVharUDBC9tXEOJxeQeO8=; b=sHk83KgmVwsReU3MNa+sNiciAtJ6GNlAStk4aR9DFP19Auppy3yr7GvabDwbAzl+1a 5ujr0Fq+KGcylQmqnAZXHnQdFFQ9pz+oSNvFlnVD0wjCgzfm5r57lxfYIKM/2qQ48Orb h5b6hpHZOPz0D12xhZ44Sm1i5k6ElJmx6WveWLbt8LKXn4Eg/XZ84gQCyQIqk7YuZIOu VLENWHBVy+TdYrQ4gT0/ZsvkQCY7kw0f2IgbYkROpi+PdIvY40P0XcJAFENvEDQu/Awg EJ2b1zMaqutMc5pjQbYRATtTEIDNgidVLJ/GI3f8OGp0yMYGgSo5fGFOd7572ypaq2hA ed+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Djc6bI6B; 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 n8-v6si22034915pgl.101.2018.09.19.15.20.59; Wed, 19 Sep 2018 15:21:00 -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=Djc6bI6B; 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 S2387455AbeITEA4 (ORCPT + 32 others); Thu, 20 Sep 2018 00:00:56 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38615 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387400AbeITEA4 (ORCPT ); Thu, 20 Sep 2018 00:00:56 -0400 Received: by mail-pf1-f196.google.com with SMTP id x17-v6so3349369pfh.5 for ; Wed, 19 Sep 2018 15:20:55 -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=25gV/yr+DQaieOUd7LXdpHMVharUDBC9tXEOJxeQeO8=; b=Djc6bI6BMMVojfSs9W39ToJZ753bA6PsqPD81ey1/C6zHiIfxmZW6YnXtHhub/fUNm 7HMSwb/5oxeFPv89MelgsJ76rIoRbPpkKQjuQSkDhXcmrMVXJXFvLri/s5j7QEj5CvVv Y5Tty7RqTw+A7oAp+29XLZVaByP+2HFlecf5c= 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=25gV/yr+DQaieOUd7LXdpHMVharUDBC9tXEOJxeQeO8=; b=WzxdcVJ0JzChuxJbfshNR+qeeVuCuK1MZBMZKnW0zIeKbfz0RA6zayTlqLcRohTe5+ Jv3msIXp/75LIhbz75ZVXFOWIeExPhtOqbplJ/QJnS2+/FdBMlcT3eR+lyNIr6xn1ac1 rKWS+jANNzi6n+yuVAXijld5sAp78xYdHl+TDy89SasAV7lsQHOdOqxe+Y0HHXYMhgMt 8vQJ0QsV9r6yKL1Veug9EMPmkeXRjKGEFk6Rsu/II93NJ+cgV4Ouzx7JUBXOKAGq3CW8 s2QhnyN2mR2S/yjGI6ef+3SxToRXg7xP/bBBVJEJ/5gMqmY0ywS4xezYQEkaNWpMYsK6 fhSA== X-Gm-Message-State: APzg51D3dREZbpqhdshr2Zt7ZsWe+NwUUJfjUeNU/YQ5rO1uUipDI0jN TXnpeqAPfqhKb3rUF3VUDvjnSg== X-Received: by 2002:a63:26c6:: with SMTP id m189-v6mr33939143pgm.70.1537395655114; Wed, 19 Sep 2018 15:20:55 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id k23-v6sm23996094pgl.42.2018.09.19.15.20.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:54 -0700 (PDT) From: Viresh Kumar To: Jason Cooper , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , "Rafael J. Wysocki" Cc: Viresh Kumar , linux-pm@vger.kernel.org, Stephen Boyd , Nishanth Menon , Vincent Guittot , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 08/12] cpufreq: mvebu: Remove OPPs using dev_pm_opp_remove() Date: Wed, 19 Sep 2018 15:20:27 -0700 Message-Id: <883071c4bd9a6e45bf0b5e45575d110eaeb2e6d0.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 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 dev_pm_opp_cpumask_remove_table() is going to change in the next commit and will not remove dynamic OPPs automatically. They must be removed with a call to dev_pm_opp_remove(). Reviewed-by: Gregory CLEMENT Signed-off-by: Viresh Kumar --- drivers/cpufreq/mvebu-cpufreq.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) -- 2.14.1 diff --git a/drivers/cpufreq/mvebu-cpufreq.c b/drivers/cpufreq/mvebu-cpufreq.c index 31513bd42705..6d33a639f902 100644 --- a/drivers/cpufreq/mvebu-cpufreq.c +++ b/drivers/cpufreq/mvebu-cpufreq.c @@ -84,9 +84,10 @@ static int __init armada_xp_pmsu_cpufreq_init(void) ret = dev_pm_opp_add(cpu_dev, clk_get_rate(clk) / 2, 0); if (ret) { + dev_pm_opp_remove(cpu_dev, clk_get_rate(clk)); clk_put(clk); dev_err(cpu_dev, "Failed to register OPPs\n"); - goto opp_register_failed; + return ret; } ret = dev_pm_opp_set_sharing_cpus(cpu_dev, @@ -99,11 +100,5 @@ static int __init armada_xp_pmsu_cpufreq_init(void) platform_device_register_simple("cpufreq-dt", -1, NULL, 0); return 0; - -opp_register_failed: - /* As registering has failed remove all the opp for all cpus */ - dev_pm_opp_cpumask_remove_table(cpu_possible_mask); - - return ret; } device_initcall(armada_xp_pmsu_cpufreq_init); From patchwork Wed Sep 19 22:20:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147058 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233271ljw; Wed, 19 Sep 2018 15:21:13 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb+tCVOBVLqOF6oeU18EE5/GE++L1O877kOX9PS+MidZwn/Jl9MZ5HUN4efbb/nYsLwUtGZ X-Received: by 2002:a62:68c3:: with SMTP id d186-v6mr37911593pfc.70.1537395673770; Wed, 19 Sep 2018 15:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395673; cv=none; d=google.com; s=arc-20160816; b=jJbNecMK3jR+sZ1YZHYgn4FiWjZqDWDL4Lt9WcAHj82YTcEPvjFc1s5MRJNFd9zV9K +ilyzQNKQM+jezvLfIOGu7odgIKRqOfAHGu9j4cyH2EuBkZoRWXjeKMi43vEnHridgC6 91J39hCKtfMhPfyo3w76LtLpDhLaYNOuM0chz440MdM8+PWZvuJ7TU6QwZ6OVEJNSAU3 t2c8W7DM2UmrOvQYUSdWSSj09WvQyOQVmACcnpIKOzntBr5KCsvPHkrzxR/pfz8Uildc ohBWusL7BOEb+0nNzNnIr7zpeXsxm9y/vRMb6G1Kbdxz2EyJbfsKGae+qkqz6sj+sNeO VSrA== 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; bh=FGjzVhkQGPOODLqAXRdoaHZm4n2l5c0zwlvyqWMhwuw=; b=koaZzdH/zgVLVIYqUBHUcIgII/Fw6PhmRBTgcsNoGN6gDn+GcF5rM4oSpEjHbS8EoU d/2m9e1sLyW36l6Ns4zTM0itvwrouHZGDGnwogScEpQyLb9WpJet3UHvUx+h4KPI+Ff9 QGywL6W82i3/Wz9xvkk0nmVcQ3f5CB7codgA1v1eCMA9wru8jHcg03ef5RltNOUMT8Wm /2lNncsFkouC0wDf/SB1UhAnlrXyAx0CajH+8Vo8m5wqjxuNLXXCeFfGaANDLk6PA9P8 oYFAwMmbuCnHK+keJk0/CsFnzUDOavUSIuaO/82VdD6ybVpmPR8E/1Mcd2ssWjQmB21p OUbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a3osEZ3s; 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 d26-v6si22530421pgd.32.2018.09.19.15.21.13; Wed, 19 Sep 2018 15:21:13 -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=a3osEZ3s; 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 S2387514AbeITEBB (ORCPT + 32 others); Thu, 20 Sep 2018 00:01:01 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36482 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387460AbeITEBA (ORCPT ); Thu, 20 Sep 2018 00:01:00 -0400 Received: by mail-pf1-f195.google.com with SMTP id b11-v6so3357193pfo.3 for ; Wed, 19 Sep 2018 15:20:58 -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=FGjzVhkQGPOODLqAXRdoaHZm4n2l5c0zwlvyqWMhwuw=; b=a3osEZ3sHowHWjU78Z2zkw3YpuUItl/Yoh4wmulmmJDKNHQ3lp3Dbe2TntakK96VCQ DhSc6Zkvb5Pgo8QlXVP/JW0mum/05dyz13mMThJVeKiSbRnZbv9wa//6BenKqDIQcdEI MLX3cNzrrg51ZD9vTtSY70F1UuFfmJKQ9b59Y= 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=FGjzVhkQGPOODLqAXRdoaHZm4n2l5c0zwlvyqWMhwuw=; b=Yd6SQ9fL7lP2M9ZKAMw0qh9hJLLWXyW+qk4OifrxKWzwIGswwXQNLFFNpJA5U+vX8c frorBwf/w6m+5pNVrGhxiKKuDnr5LraEsao04nNNIEh5egu6C22cTBqi0fNoqSs0zlKV W2+0i8z/k/oHKt7jI7yPzgLa2uBzoDLn1kz+25zLizrLs40qmq1Cj2m0coV4Y38yezts xpdoqrpaAF4LaH3z5eZ+aq2fx30iI/ikwF+WYBfshHZqMP27olxN5FJ2r4mGqdPZSwPa oSk3KmcpdP5YWageczuybz64nEtxCQyrFclWPyPitDFMX4+Zk2Ny+lMygR4n97v6YZns ujvA== X-Gm-Message-State: APzg51Cpv8JhGdQP8nh0B7gYVW9nEcwtIX0RThVEL3UbQ1jZHfhOKprD Dbp+um6s7px8T/b9M/+rOwFaWQ== X-Received: by 2002:a63:7a50:: with SMTP id j16-v6mr97237pgn.112.1537395658493; Wed, 19 Sep 2018 15:20:58 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id v26-v6sm30312412pfe.57.2018.09.19.15.20.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:57 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 10/12] OPP: Use a single mechanism to free the OPP table Date: Wed, 19 Sep 2018 15:20:29 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 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 Currently there are two separate ways to free the OPP table based on how it is created in the first place. We call _dev_pm_opp_remove_table() to free the static and/or dynamic OPP, OPP list devices, etc. This is done for the case where the OPP table is added while initializing the OPPs, like via the path dev_pm_opp_of_add_table(). We also call dev_pm_opp_put_opp_table() in some cases which eventually frees the OPP table structure once the reference count reaches 0. This is used by the first case as well as other cases like dev_pm_opp_set_regulators() where the OPPs aren't necessarily initialized at this point. This whole thing is a bit unclear and messy and obstruct any further cleanup/fixup of OPP core. This patch tries to streamline this by keeping a single path for OPP table destruction, i.e. dev_pm_opp_put_opp_table(). All the cleanup happens in _opp_table_kref_release() now after the reference count reaches 0. _dev_pm_opp_remove_table() is removed as it isn't required anymore. We don't drop the reference to the OPP table after creating it from _of_add_opp_table_v{1|2}() anymore and the same is dropped only when we try to remove them. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 54 ++++++++++++++++-------------------------------------- drivers/opp/of.c | 32 ++++++++++++++++++-------------- drivers/opp/opp.h | 2 +- 3 files changed, 35 insertions(+), 53 deletions(-) -- 2.14.1 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 2319ad4a0177..d3e33fd32694 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -867,23 +867,24 @@ struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, static void _opp_table_kref_release(struct kref *kref) { struct opp_table *opp_table = container_of(kref, struct opp_table, kref); - struct opp_device *opp_dev; + struct opp_device *opp_dev, *temp; /* Release clk */ if (!IS_ERR(opp_table->clk)) clk_put(opp_table->clk); - /* - * No need to take opp_table->lock here as we are guaranteed that no - * references to the OPP table are taken at this point. - */ - opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, - node); + WARN_ON(!list_empty(&opp_table->opp_list)); - _remove_opp_dev(opp_dev, opp_table); + list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node) { + /* + * The OPP table is getting removed, drop the performance state + * constraints. + */ + if (opp_table->genpd_performance_state) + dev_pm_genpd_set_performance_state((struct device *)(opp_dev->dev), 0); - /* dev_list must be empty now */ - WARN_ON(!list_empty(&opp_table->dev_list)); + _remove_opp_dev(opp_dev, opp_table); + } mutex_destroy(&opp_table->lock); list_del(&opp_table->node); @@ -1758,33 +1759,6 @@ int dev_pm_opp_unregister_notifier(struct device *dev, } EXPORT_SYMBOL(dev_pm_opp_unregister_notifier); -/* - * Free OPPs either created using static entries present in DT. - */ -void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev) -{ - /* Protect dev_list */ - mutex_lock(&opp_table->lock); - - /* Find if opp_table manages a single device */ - if (list_is_singular(&opp_table->dev_list)) { - /* Free static OPPs */ - _put_opp_list_kref(opp_table); - - /* - * The OPP table is getting removed, drop the performance state - * constraints. - */ - if (opp_table->genpd_performance_state) - dev_pm_genpd_set_performance_state(dev, 0); - } else { - _put_opp_list_kref(opp_table); - _remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table); - } - - mutex_unlock(&opp_table->lock); -} - void _dev_pm_opp_find_and_remove_table(struct device *dev) { struct opp_table *opp_table; @@ -1802,8 +1776,12 @@ void _dev_pm_opp_find_and_remove_table(struct device *dev) return; } - _dev_pm_opp_remove_table(opp_table, dev); + _put_opp_list_kref(opp_table); + + /* Drop reference taken by _find_opp_table() */ + dev_pm_opp_put_opp_table(opp_table); + /* Drop reference taken while the OPP table was added */ dev_pm_opp_put_opp_table(opp_table); } diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 861cc75de329..ae0436eaa911 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -407,14 +407,17 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, opp_table = _managed_opp(opp_np); if (opp_table) { /* OPPs are already managed */ - if (!_add_opp_dev(dev, opp_table)) + if (!_add_opp_dev(dev, opp_table)) { ret = -ENOMEM; - else if (!opp_table->parsed_static_opps) - goto initialize_static_opps; - else + goto put_opp_table; + } + + if (opp_table->parsed_static_opps) { kref_get(&opp_table->list_kref); + return 0; + } - goto put_opp_table; + goto initialize_static_opps; } opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); @@ -432,17 +435,15 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, if (ret) { dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, ret); - _dev_pm_opp_remove_table(opp_table, dev); of_node_put(np); - goto put_opp_table; + goto put_list_kref; } } /* There should be one of more OPP defined */ if (WARN_ON(!count)) { ret = -ENOENT; - _put_opp_list_kref(opp_table); - goto put_opp_table; + goto put_list_kref; } list_for_each_entry(opp, &opp_table->opp_list, node) @@ -453,8 +454,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, dev_err(dev, "Not all nodes have performance state set (%d: %d)\n", count, pstate_count); ret = -ENOENT; - _dev_pm_opp_remove_table(opp_table, dev); - goto put_opp_table; + goto put_list_kref; } if (pstate_count) @@ -462,6 +462,10 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, opp_table->parsed_static_opps = true; + return 0; + +put_list_kref: + _put_opp_list_kref(opp_table); put_opp_table: dev_pm_opp_put_opp_table(opp_table); @@ -507,13 +511,13 @@ static int _of_add_opp_table_v1(struct device *dev) if (ret) { dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", __func__, freq, ret); - _dev_pm_opp_remove_table(opp_table, dev); - break; + _put_opp_list_kref(opp_table); + dev_pm_opp_put_opp_table(opp_table); + return ret; } nr -= 2; } - dev_pm_opp_put_opp_table(opp_table); return ret; } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 98dd7d39e1ad..f9fbb7553fc4 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -190,11 +190,11 @@ struct opp_table { /* Routines internal to opp core */ void dev_pm_opp_get(struct dev_pm_opp *opp); +void _opp_remove_all_static(struct opp_table *opp_table); void _get_opp_table_kref(struct opp_table *opp_table); int _get_opp_count(struct opp_table *opp_table); struct opp_table *_find_opp_table(struct device *dev); struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table); -void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev); void _dev_pm_opp_find_and_remove_table(struct device *dev); struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); void _opp_free(struct dev_pm_opp *opp);