From patchwork Wed Sep 19 22:20:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147050 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1232864ljw; Wed, 19 Sep 2018 15:20:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbMTwcG/PBRSmnDp18y2oY2S58WvHVROiO+momREDsVk4EdRNbANLY25COh2xaCaWznlSkJ X-Received: by 2002:a17:902:3041:: with SMTP id u59-v6mr35465614plb.99.1537395649053; Wed, 19 Sep 2018 15:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395649; cv=none; d=google.com; s=arc-20160816; b=TJitA8lEIzSW/g1dCCY+0cnIpLx4rahXa3xIcW+YH2DQMT2mVZ2k37lpBduQWGoQG3 bGjcSR2/hfHCufHI1RKugtI/tgTcFSDnWdh06vTTENdcKFUk+ID/sQGvXXpKMqeaNYiY 6EIRGZjOjgF5hbWNsuaNsiG495wzpgpuKx6Gtg6qeLnNZ41WK8BYJDBGIJhaMrpCxjhv PQNCraONE/YMud/vm56cWtMLUluTtUBpmSgfO0jPMYZv3qeUEdncrEhWWicj4cSNX4+O oEPtXU3mTS1Fe0a7HZQLx/vGYkjt3HhCtggTL+szI1rrvtUtsfJtAXfKB7hlH/lV7DPK HlYg== 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=eozK+qk21bu6C0o4GTQGviL35NBsR1qUdySDKI0vP2I=; b=arAXk7nsyn8tUYDwNNONbk0t5Dq9clCEoYjNBETeWMxS84VThhbYDAcCbz8NSSz469 /0ZVlCPRC7oT6RANtopd6SCOlKbyYo+CM4sUVXPI+Uwi+QRoVm1Ttx/8XeNlqG7e+ckl hqBQTa/5jmgMPUf/f+4JkRyV4RPLBhdNbZzYSI7U7xZlk/Nn4mx4F1T/ImUrCfor2Jrj TE+R1z9VvdgXWRd1+8ig4Q7htYY/2L7LJYebvQFDqjgNV40OvQb8L/4OUfO4I2AQAiPl CS47rqz7Keg++NIE5GWWV4EU8f9UVa2DB9n47XME79g29AYPcH8scrjK1gotQUmdAz1G GX2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SwuaU0eM; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=SwuaU0eM; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1725784AbeITEAr (ORCPT + 10 others); Thu, 20 Sep 2018 00:00:47 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34051 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726123AbeITEAr (ORCPT ); Thu, 20 Sep 2018 00:00:47 -0400 Received: by mail-pg1-f195.google.com with SMTP id d19-v6so3409722pgv.1 for ; Wed, 19 Sep 2018 15:20:46 -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=eozK+qk21bu6C0o4GTQGviL35NBsR1qUdySDKI0vP2I=; b=SwuaU0eMFXWnHwJhPlvOyv1Ga8JLS7+7VSsRo3kxfYuFSx+xD06mKbdqANxh0D6aTu yLH7qygik4fIlLze/wJlcC5Jp2Y8uuYOFSS9qnG2Ec1Z4KM/QmhRNrRZfrZjs0N9C6oK mghgYTt71zKhka1NiY4O/UJ9fQUBja1hRVG7c= 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=eozK+qk21bu6C0o4GTQGviL35NBsR1qUdySDKI0vP2I=; b=VcWnfvTb1SaGAwHT9VBOmjXBJA5iCqEGAiaywL6af0u7uw8qLJ+mSj5o4eKO+l1p0l 5EqFNVtXWOIXpXlOBQoQ0M3TkoInquCNYfXSfmCzmX1IRSatCY2xr1KdpjVrvq8KfQIf RNaKWL8g7fgwqwH1IeIjOCfgpmGV1vsaMSxqkbUF74c2h9Z5jbpv9bKqCMf+V7Cgn72b RADyrBPgVlM8v3MHyp/q9U3o3I/2ZkCdtfQBURwfU+ix63kjcOEyN8d8qTYkSyrHXqVT widCQ958LGSMStPz6V+nMoNh7aONe/fxHBB/LAJIaCi0V9K8L/rY7EA80xsEBAh+PaHX ZRlA== X-Gm-Message-State: APzg51CLz9Gmcx+gbKOuZpu2omTjEuI53dEi6DwNXEmGageRmeWxW0nb t9jWgsmUEfAIAAXUW99vkMthnw== X-Received: by 2002:a62:6690:: with SMTP id s16-v6mr38022974pfj.152.1537395645964; Wed, 19 Sep 2018 15:20:45 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id e190-v6sm45557047pfc.81.2018.09.19.15.20.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:45 -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 02/12] OPP: Don't try to remove all OPP tables on failure Date: Wed, 19 Sep 2018 15:20:21 -0700 Message-Id: <404b1369ea26f598b96ae4d3183262a879703cfe.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org dev_pm_opp_of_cpumask_add_table() creates the OPP table for all CPUs present in the cpumask and on errors it should revert all changes it has done. It actually is doing a bit more than that. On errors, it tries to free all the OPP tables, even the one it hasn't created yet. This may also end up freeing the OPP tables which were created from separate path, like dev_pm_opp_set_supported_hw(). Reported-and-tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/cpu.c | 8 ++++++-- drivers/opp/of.c | 4 ++-- drivers/opp/opp.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) -- 2.14.1 diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 0c0910709435..2eb5e2e7ff66 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -108,7 +108,8 @@ void dev_pm_opp_free_cpufreq_table(struct device *dev, EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table); #endif /* CONFIG_CPU_FREQ */ -void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of) +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, + int last_cpu) { struct device *cpu_dev; int cpu; @@ -116,6 +117,9 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of) WARN_ON(cpumask_empty(cpumask)); for_each_cpu(cpu, cpumask) { + if (cpu == last_cpu) + break; + cpu_dev = get_cpu_device(cpu); if (!cpu_dev) { pr_err("%s: failed to get cpu%d device\n", __func__, @@ -140,7 +144,7 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of) */ void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, false); + _dev_pm_opp_cpumask_remove_table(cpumask, false, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 20988c426650..86222586f27b 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -592,7 +592,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); */ void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, true); + _dev_pm_opp_cpumask_remove_table(cpumask, true, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table); @@ -627,7 +627,7 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) __func__, cpu, ret); /* Free all other OPPs */ - dev_pm_opp_of_cpumask_remove_table(cpumask); + _dev_pm_opp_cpumask_remove_table(cpumask, true, cpu); break; } } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 7c540fd063b2..a9d22aa534c3 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -196,7 +196,7 @@ struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); void _opp_free(struct dev_pm_opp *opp); int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available); 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); +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); #ifdef CONFIG_OF From patchwork Wed Sep 19 22:20:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147060 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233684ljw; Wed, 19 Sep 2018 15:21:40 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdau5yueplUwcYkNCKDiSlBJ3oXTL7dXE/gTHLQwIjEOsLAG6pIn/sV3RRbUkiCUvM1FASGd X-Received: by 2002:a63:fe49:: with SMTP id x9-v6mr4091492pgj.152.1537395700856; Wed, 19 Sep 2018 15:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395700; cv=none; d=google.com; s=arc-20160816; b=AKOYeNNuIoOYqBuOdqtfwdtjw13M5ztGwx7QyQOBFMSyj2gmvbRgk8kTLYGP78wxx+ x/sD+pWD8nMlYrWL5Hl26lfbFgXA8UPS3Iu2iAeQSPgNsj1Z2TrtZuQNI577vnFcoPf9 JNmR7JLVxBPOcS7j4mU0A/2Yklytt18XdRgMIB+rsqsWv/hQXOMhiMLhEmJi9hAI6Kes uaaZsYQxQoW9Ko8VyrumE9FnuLsquUvEkotpVTDmm9nDXvNe/BRAXEZzqTzDE2jcPuVA xem4DnFbwokKy617ZNKuzB1TVGz4KIB4FCVjFQPBI+6uIo3TnGsb6yv2ONGIYnv/jdxR PmYg== 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=KNbb/GBRT5l235B0JCuUrzsEESNrHyS5fTToF34GITM=; b=dm8O4OdsVLJvwmhN7Z+u5/xgJDjoKMPxjgZgjGLAUxzki3DZgSl2hHLGBU5m4gcD9R t6/k2a9EMSVxvYvzxLDREg5Xtp2hXP1WNFiXPNiHX6vw8gsV9KJ5HlOCT7XYf2f+YbbS l1j7w01cyvOhhtD03Dudw4JpsjZEklKesiXnuwPp/MHe6LiyRQZdbMYF2NTo6UdrVVF3 RJtutnWdbpLmH2K+j7lU5OLgNI87epXX5NHs+Pz06f7MeC4/FkSQjotrhbuq+zgrRCJL cJUgGargpWDZI6bafweP/OQd7FiWo1eW1JKhZZd/7wsOCLxDHTMtKG9ZieSMTI0YzB3G RGYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kb0LyyBA; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 a24-v6si17927966pgi.515.2018.09.19.15.21.40; Wed, 19 Sep 2018 15:21:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=kb0LyyBA; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1725993AbeITEAs (ORCPT + 10 others); Thu, 20 Sep 2018 00:00:48 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:34907 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726592AbeITEAs (ORCPT ); Thu, 20 Sep 2018 00:00:48 -0400 Received: by mail-pl1-f195.google.com with SMTP id g2-v6so3307027plo.2 for ; Wed, 19 Sep 2018 15:20:47 -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=KNbb/GBRT5l235B0JCuUrzsEESNrHyS5fTToF34GITM=; b=kb0LyyBAoMOdq8BVQnvoGN9iZbuEZTsvI+BGU1C2Nbd4tVxnR4nkW+xpV48FIidvwW V9fAIAsXEWiLB5gKDmOybT339oXK8ne+05ELmx7mTffsLEes7801R35UJB+176ZVj9r7 bQJrjdt8aL4wZOPVcT0HKAIvA0ueZm7rAT3fs= 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=KNbb/GBRT5l235B0JCuUrzsEESNrHyS5fTToF34GITM=; b=ZXRxAMgNFJG/kQvd/nFBOZW/Ju6pAtfLjyHX/SYs21eU4x9kHBFuoIAlqQC20EZAvN klCI41t+ckXzYr0ZWpeNeiLj18BhmA5kvnC1kpWQoARNd1xsO8NFs2e3nA7Y0fUyLDP6 vA/eGFb6tlwQsB1piZt/0HNqKI4jwqmAJLRqi6EBXYrQfb43wdRB0hWo1H81XCvL86Vx jiUosOQ8B3BinLUBm7XSr/yUapVhZgA24pcnoNkIsJvJwK5ALUcV6qsiEERKt1qeDgyY hlrDDL5tGoDtDbtZoFiAfZ/lQS/TSWVODcS9Ge1ac/ugpX0xl5BHo/ilIllrz+GXDMUr MmiQ== X-Gm-Message-State: APzg51AEuR++vYOOyL74xR3jk0ZsTC12vTBxrD69ZW0/Fq9pZjHyg4HX OVMvCxTitX16uDdrNi+UZUMMIw== X-Received: by 2002:a17:902:286a:: with SMTP id e97-v6mr36378195plb.340.1537395647452; Wed, 19 Sep 2018 15:20:47 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id a20-v6sm52014829pfc.14.2018.09.19.15.20.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:46 -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 03/12] OPP: Protect dev_list with opp_table lock Date: Wed, 19 Sep 2018 15:20:22 -0700 Message-Id: <3d2556992a878a2210d3be498416aee39e0c32aa.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The dev_list needs to be protected with a lock, else we may have simultaneous access (addition/removal) to it and that would be racy. Extend scope of the opp_table lock to protect dev_list as well. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 21 +++++++++++++++++++-- drivers/opp/cpu.c | 2 ++ drivers/opp/opp.h | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) -- 2.14.1 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 31ff03dbeb83..9f8aa31265fe 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -48,9 +48,14 @@ static struct opp_device *_find_opp_dev(const struct device *dev, static struct opp_table *_find_opp_table_unlocked(struct device *dev) { struct opp_table *opp_table; + bool found; list_for_each_entry(opp_table, &opp_tables, node) { - if (_find_opp_dev(dev, opp_table)) { + mutex_lock(&opp_table->lock); + found = !!_find_opp_dev(dev, opp_table); + mutex_unlock(&opp_table->lock); + + if (found) { _get_opp_table_kref(opp_table); return opp_table; @@ -766,6 +771,8 @@ struct opp_device *_add_opp_dev(const struct device *dev, /* Initialize opp-dev */ opp_dev->dev = dev; + + mutex_lock(&opp_table->lock); list_add(&opp_dev->node, &opp_table->dev_list); /* Create debugfs entries for the opp_table */ @@ -773,6 +780,7 @@ struct opp_device *_add_opp_dev(const struct device *dev, if (ret) dev_err(dev, "%s: Failed to register opp debugfs (%d)\n", __func__, ret); + mutex_unlock(&opp_table->lock); return opp_dev; } @@ -791,6 +799,7 @@ static struct opp_table *_allocate_opp_table(struct device *dev) if (!opp_table) return NULL; + mutex_init(&opp_table->lock); INIT_LIST_HEAD(&opp_table->dev_list); opp_dev = _add_opp_dev(dev, opp_table); @@ -812,7 +821,6 @@ static struct opp_table *_allocate_opp_table(struct device *dev) BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head); INIT_LIST_HEAD(&opp_table->opp_list); - mutex_init(&opp_table->lock); kref_init(&opp_table->kref); /* Secure the device table modification */ @@ -854,6 +862,10 @@ static void _opp_table_kref_release(struct kref *kref) 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); @@ -1716,6 +1728,9 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, { struct dev_pm_opp *opp, *tmp; + /* 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 */ @@ -1733,6 +1748,8 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, } else { _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, bool remove_all) diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 2eb5e2e7ff66..36586f66cd83 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -226,8 +226,10 @@ int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask) cpumask_clear(cpumask); if (opp_table->shared_opp == OPP_TABLE_ACCESS_SHARED) { + mutex_lock(&opp_table->lock); list_for_each_entry(opp_dev, &opp_table->dev_list, node) cpumask_set_cpu(opp_dev->dev->id, cpumask); + mutex_unlock(&opp_table->lock); } else { cpumask_set_cpu(cpu_dev->id, cpumask); } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index a9d22aa534c3..88e9f47aadf1 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -126,7 +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. - * @lock: mutex protecting 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. * @shared_opp: OPP is shared between multiple devices. From patchwork Wed Sep 19 22:20:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147056 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233095ljw; Wed, 19 Sep 2018 15:21:02 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZZkSd8c0iOmYo7gE6rpjbq84xUK1AM8I6ba9GxmGH2GQ3kiyVmMhsGjn4FO4TDDNSVt0gI X-Received: by 2002:a63:4745:: with SMTP id w5-v6mr34759218pgk.140.1537395662430; Wed, 19 Sep 2018 15:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395662; cv=none; d=google.com; s=arc-20160816; b=Se211ns1RSYBGDatco+jug0EK8XJIo2lmhAfldj/ryIkDJKAMbLGvuGM3XKvuiKAst /sJg4+vRp/Ln9v83Dfvc17/xjKGnY+gWtWyjvmdjiNQAYYstqgPJ03njjY20X4rlKY3O M+atjQLUMe7+7pYb8zK/uLmIPzN6Io/IhOt575945nXG0aIUx60VuhzunSlyrQU5U8mJ kyFRoNF4JFmg6ruz9rkGAo4I+CzfLsfMXzPnF7JtDIgmGju8G/L9wItEyuGZx3Fo4F2R xFYPfUdvkVnXd0pcFwjgNguSZrUPHJl5/Pc/9Ger2Djn/wh6R6X5oTq9eAzJzaYfXE5Z O+pw== 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=lOCO4EDC8Q7oDBzPlggldAfccotE1FhuTN71HpuLTTI=; b=axErbjOGhS0WlGws2TAOM5D9KRmUBlmVfz0P1F5fF8eD5h0UtkXXLst3o6FTxP8eGT g80BObGolDAHSa0LTiMqO9cIUPRSgR9WQpI8ybG3V4s7lmVDMeAGAczbj13aY20d5/w6 e+MY7XNLpvvbGEIocy0Ik5g2R0Yz9vgzYd0r4kEzBAOlU7NkB1dMFuEbpbnbDjyEodPI j1cTEm65+zDb0W2Je0LwG60G8W5pxwFmkQw+C1Ar9cnhMrHucodyC8W3rtAV1neL/u7+ yUi92I6LL+DZ1+4mQFT6Kuj2jqy2K8KuiT81R6f9UsYLEC0sKvhyAaqoqhLsdUARwMxC es6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dxzQxtXO; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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.21.02; Wed, 19 Sep 2018 15:21:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=dxzQxtXO; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1732890AbeITEBB (ORCPT + 10 others); Thu, 20 Sep 2018 00:01:01 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43302 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387458AbeITEA5 (ORCPT ); Thu, 20 Sep 2018 00:00:57 -0400 Received: by mail-pg1-f195.google.com with SMTP id q19-v6so2534151pgn.10 for ; Wed, 19 Sep 2018 15:20:57 -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=lOCO4EDC8Q7oDBzPlggldAfccotE1FhuTN71HpuLTTI=; b=dxzQxtXOMt24gp9Kdm/pMZ4LveTazVeLqdhF0qSrKiMNHtcJ44NVLQzl9NBf+hGERr JhaKkEzKDIC4UUM4N51wTgrXmUhXBu5rFIbe7nDqq/HjP0dKHAXUBMbLAquaY8pySmiy itRyPU2Xdg6pKq0p+JcgiptMxGSHBVQbyWTsE= 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=lOCO4EDC8Q7oDBzPlggldAfccotE1FhuTN71HpuLTTI=; b=prZEF+Doog1ybaXc33x0a0cpSCcqUYVKshc80goxpXnjALF2l4B84NWrp7HxPA0aTO KzV3+TB/DCahoMktygZ7x5B+hEaZr12m46EKBI6fBH8rBxb/+N1JTwAnbUQHKJJ4QkZh qmCZP/uPDlWzvDIpi2EE8FCvbtuoEnxZbLSZV/lTTIIjU3dZPkBLTCKCaeNt6lo0P/RT tLB1IVQs5MyxAWQx0q7JCASPIGsARpjIynV+dvwhCp2cxsbMVp1tdjx9BfSgVBf0sPC3 g5RYzEJMM66SFvzUr5C8LPXInFiOYnhuMT0UReZXJn1VyHjB3Bwlg//D4jmsrcvsARsD HAVw== X-Gm-Message-State: APzg51AEWOI1Hr86GXJ5holdRbExE3wySG/zZgMVMT+kL7Ss5U5EdqUD U/40o014zWM7SZmgKFtZeztpkA== X-Received: by 2002:a62:225d:: with SMTP id i90-v6mr37923089pfi.246.1537395656692; Wed, 19 Sep 2018 15:20:56 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id f11-v6sm32580232pfa.131.2018.09.19.15.20.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:56 -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 09/12] OPP: Don't remove dynamic OPPs from _dev_pm_opp_remove_table() Date: Wed, 19 Sep 2018 15:20:28 -0700 Message-Id: <2a4eb7358aba6beff7fa23f028c733310756e525.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Only one platform was depending on this feature and it is already updated now. Stop removing dynamic OPPs from _dev_pm_opp_remove_table(). This simplifies lot of paths and removes unnecessary parameters. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 20 +++++--------------- drivers/opp/cpu.c | 9 +++------ drivers/opp/of.c | 12 ++++++------ drivers/opp/opp.h | 6 +++--- 4 files changed, 17 insertions(+), 30 deletions(-) -- 2.14.1 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index b555121b878b..2319ad4a0177 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1759,14 +1759,10 @@ 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 or even the - * dynamically added entries based on remove_all param. + * Free OPPs either created using static entries present in DT. */ -void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, - bool remove_all) +void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev) { - struct dev_pm_opp *opp, *tmp; - /* Protect dev_list */ mutex_lock(&opp_table->lock); @@ -1775,12 +1771,6 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, /* 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) - dev_pm_opp_put(opp); - } - /* * The OPP table is getting removed, drop the performance state * constraints. @@ -1795,7 +1785,7 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, mutex_unlock(&opp_table->lock); } -void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all) +void _dev_pm_opp_find_and_remove_table(struct device *dev) { struct opp_table *opp_table; @@ -1812,7 +1802,7 @@ void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all) return; } - _dev_pm_opp_remove_table(opp_table, dev, remove_all); + _dev_pm_opp_remove_table(opp_table, dev); dev_pm_opp_put_opp_table(opp_table); } @@ -1826,6 +1816,6 @@ void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all) */ void dev_pm_opp_remove_table(struct device *dev) { - _dev_pm_opp_find_and_remove_table(dev, true); + _dev_pm_opp_find_and_remove_table(dev); } EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table); diff --git a/drivers/opp/cpu.c b/drivers/opp/cpu.c index 36586f66cd83..ab6d07e78945 100644 --- a/drivers/opp/cpu.c +++ b/drivers/opp/cpu.c @@ -108,7 +108,7 @@ void dev_pm_opp_free_cpufreq_table(struct device *dev, EXPORT_SYMBOL_GPL(dev_pm_opp_free_cpufreq_table); #endif /* CONFIG_CPU_FREQ */ -void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu) { struct device *cpu_dev; @@ -127,10 +127,7 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, continue; } - if (of) - dev_pm_opp_of_remove_table(cpu_dev); - else - dev_pm_opp_remove_table(cpu_dev); + _dev_pm_opp_find_and_remove_table(cpu_dev); } } @@ -144,7 +141,7 @@ void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of, */ void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, false, -1); + _dev_pm_opp_cpumask_remove_table(cpumask, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_cpumask_remove_table); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index aaa4bab69846..861cc75de329 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -279,7 +279,7 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, */ void dev_pm_opp_of_remove_table(struct device *dev) { - _dev_pm_opp_find_and_remove_table(dev, false); + _dev_pm_opp_find_and_remove_table(dev); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); @@ -432,7 +432,7 @@ 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, false); + _dev_pm_opp_remove_table(opp_table, dev); of_node_put(np); goto put_opp_table; } @@ -453,7 +453,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); + _dev_pm_opp_remove_table(opp_table, dev); goto put_opp_table; } @@ -507,7 +507,7 @@ 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, false); + _dev_pm_opp_remove_table(opp_table, dev); break; } nr -= 2; @@ -618,7 +618,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed); */ void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask) { - _dev_pm_opp_cpumask_remove_table(cpumask, true, -1); + _dev_pm_opp_cpumask_remove_table(cpumask, -1); } EXPORT_SYMBOL_GPL(dev_pm_opp_of_cpumask_remove_table); @@ -653,7 +653,7 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask) __func__, cpu, ret); /* Free all other OPPs */ - _dev_pm_opp_cpumask_remove_table(cpumask, true, cpu); + _dev_pm_opp_cpumask_remove_table(cpumask, cpu); break; } } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 9274116c90e4..98dd7d39e1ad 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -194,13 +194,13 @@ 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, bool remove_all); -void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all); +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); int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available); 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); +void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu); struct opp_table *_add_opp_table(struct device *dev); void _put_opp_list_kref(struct opp_table *opp_table); From patchwork Wed Sep 19 22:20:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147059 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233295ljw; Wed, 19 Sep 2018 15:21:15 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdaz8t0Lhb6/iDxzksNxmAoyDcjXyPQL9Odg/yCLh6YnPa8vKBQF/Pdt6MWo8ot3XnMadnJh X-Received: by 2002:a63:24c4:: with SMTP id k187-v6mr34401879pgk.162.1537395675204; Wed, 19 Sep 2018 15:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395675; cv=none; d=google.com; s=arc-20160816; b=Npaau7RKktrlu93uNI4ikX5qQ7NPXaV7MY2uo+3dUvcy1qr/ras/PyeHNMfOIMv0j1 t64qfhbbp7InolhmEADznoK4AH74MLTnNose2umHuTTQIfrImqFz1Fx4Ztq3lHEhlwP/ jAOB5eFT+CK+GM/wWfBPaYXi0QSxUUItvPEW4/9d8Yt5Hq4qSv/hxuOPpHTnrDSbFtWB ADVQOzew19vAQEPfTuU7B2gQiCJ7EeMdXtkni/8a6i0VXUwGlEIT6p2ZlKgsL5UfPYhT GHL3FzJobumveir/0YZKfFy3ucREtGXncEG124E+ivlRyw0oKMux+JGeU9kEuCLPxL2S Wmig== 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=rxiJu/KT0VOL6VfChRrYVDga8+0QfxrCXpVuzdXnBO4=; b=bqCYfgQDBoW7kgp58CokUh+JlIJkvNWCK4EfzeSeIavrDALTReirZIpvQcKweKNAIV N1BKDSPT9ZlQNZrIYhYcM3Z8f4OFg03ZdwpluAsjrKkNUG8E78Vu25f2xa43yd+cinlO 4TO362o2WmTg3l3M3yVUsaDIMtPs8T8cACYFiMug23qm7005tMzDeEuJgQd+J1wbcsLI HHv35lfdj8xhkKjqd6uFLdaT9T5KhGGueTG06i6ORGyUxTejBcjYxIDh7HyZD7WqsN91 uWscUfqM4914GFli9Beq5Ui+/UOr2sNOR+YYKrBilme2kNBDRSK1gt9XCvhLSaqEvL9i WBvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ikzmAEGB; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 q28-v6si22116431pgm.689.2018.09.19.15.21.14; Wed, 19 Sep 2018 15:21:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=ikzmAEGB; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S2387504AbeITEBB (ORCPT + 10 others); Thu, 20 Sep 2018 00:01:01 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34567 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387462AbeITEBB (ORCPT ); Thu, 20 Sep 2018 00:01:01 -0400 Received: by mail-pl1-f193.google.com with SMTP id f6-v6so3310601plo.1 for ; Wed, 19 Sep 2018 15:21:00 -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=rxiJu/KT0VOL6VfChRrYVDga8+0QfxrCXpVuzdXnBO4=; b=ikzmAEGB42Zj3XDq48lFhnbEIA+c4LuNJVaQsujEHiXSx6BS3+oapROn/ZkNBKiMsm wL4GwkY2G66JLWmNNyTaeOCduCVoUZmepJKZnaevA7P+ckL6+5JviKqvH9Zx+I9CsaJi hdOJHWpo9kSX+XGRMIkbSJyIAzaYlAjN9Ktm0= 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=rxiJu/KT0VOL6VfChRrYVDga8+0QfxrCXpVuzdXnBO4=; b=Wb9RG+B1i7LYxb3bo+obCDkXRYT1/Laowe2Ad2Zrv0oRN7DpVEU5ax/Qvb0955EXb6 85mJROgR2Q4M5qRsgMkl2d9zef/4VQD8eSFoXxj3aew67qEwCCW/1qw6UAbVZ1lubNbf YAQDGw4YlMtxTPtz/zBC+IKO8b6FQbGn9YQWqScJi8hmFvnHriCrCIlz+nBX2Zj31sj9 8bWkflWtLXeNqAnqVU2UzVjGXGRMerbd1KVmXtLqdnr48djac7MeiwyvFsuNZWLStssO 1oBIgJD0sfnRYrcZK5tTPZrVAC+Z3C2fvsm6YYFIRJWSkqDIyrbgUYPbxo2By6sjuQO/ rwNQ== X-Gm-Message-State: APzg51B6/mOChFXFJqzhzkVMRGQt8xflgNX3XSirKVAF6rTey2Q2v9GI neUql14BJpUeW2k6/ccRPJrOVA== X-Received: by 2002:a17:902:8a92:: with SMTP id p18-v6mr36016518plo.148.1537395660158; Wed, 19 Sep 2018 15:21:00 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id w81-v6sm41086185pfk.92.2018.09.19.15.20.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:20:59 -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 11/12] OPP: Prevent creating multiple OPP tables for devices sharing OPP nodes Date: Wed, 19 Sep 2018 15:20:30 -0700 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When two or more devices are sharing their clock and voltage rails, they share the same OPP table. But there are some corner cases where the OPP core incorrectly creates separate OPP tables for them. For example, CPU 0 and 1 share clock/voltage rails. The platform specific code calls dev_pm_opp_set_regulators() for CPU0 and the OPP core creates an OPP table for it (the individual OPPs aren't initialized as of now). The same is repeated for CPU1 then. Because _opp_get_opp_table() doesn't compare DT node pointers currently, it fails to find the link between CPU0 and CPU1 and so creates a new OPP table. Fix this by calling _managed_opp() from _opp_get_opp_table(). _managed_opp() gain an additional argument (index) to get the right node pointer. This resulted in simplifying code in _of_add_opp_table_v2() as well. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 25 ++++++++++++++++++++++--- drivers/opp/of.c | 35 +++++++++++++---------------------- drivers/opp/opp.h | 2 ++ 3 files changed, 37 insertions(+), 25 deletions(-) -- 2.14.1 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index d3e33fd32694..aaef20cf4df2 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -759,8 +759,8 @@ static void _remove_opp_dev(struct opp_device *opp_dev, kfree(opp_dev); } -struct opp_device *_add_opp_dev(const struct device *dev, - struct opp_table *opp_table) +struct opp_device *_add_opp_dev_unlocked(const struct device *dev, + struct opp_table *opp_table) { struct opp_device *opp_dev; int ret; @@ -772,7 +772,6 @@ struct opp_device *_add_opp_dev(const struct device *dev, /* Initialize opp-dev */ opp_dev->dev = dev; - mutex_lock(&opp_table->lock); list_add(&opp_dev->node, &opp_table->dev_list); /* Create debugfs entries for the opp_table */ @@ -780,6 +779,17 @@ struct opp_device *_add_opp_dev(const struct device *dev, if (ret) dev_err(dev, "%s: Failed to register opp debugfs (%d)\n", __func__, ret); + + return opp_dev; +} + +struct opp_device *_add_opp_dev(const struct device *dev, + struct opp_table *opp_table) +{ + struct opp_device *opp_dev; + + mutex_lock(&opp_table->lock); + opp_dev = _add_opp_dev_unlocked(dev, opp_table); mutex_unlock(&opp_table->lock); return opp_dev; @@ -844,6 +854,15 @@ static struct opp_table *_opp_get_opp_table(struct device *dev, int index) if (!IS_ERR(opp_table)) goto unlock; + opp_table = _managed_opp(dev, index); + if (opp_table) { + if (!_add_opp_dev_unlocked(dev, opp_table)) { + dev_pm_opp_put_opp_table(opp_table); + opp_table = NULL; + } + goto unlock; + } + opp_table = _allocate_opp_table(dev, index); unlock: diff --git a/drivers/opp/of.c b/drivers/opp/of.c index ae0436eaa911..1ddef52c27fd 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -41,11 +41,14 @@ struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) } 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 *_managed_opp(struct device *dev, int index) { struct opp_table *opp_table, *managed_table = NULL; + struct device_node *np; - mutex_lock(&opp_table_lock); + np = _opp_of_get_opp_desc_node(dev->of_node, index); + if (!np) + return NULL; list_for_each_entry(opp_table, &opp_tables, node) { if (opp_table->np == np) { @@ -65,7 +68,7 @@ static struct opp_table *_managed_opp(const struct device_node *np) } } - mutex_unlock(&opp_table_lock); + of_node_put(np); return managed_table; } @@ -401,30 +404,19 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, { struct device_node *np; struct opp_table *opp_table; - int ret = 0, count = 0, pstate_count = 0; + int ret, count = 0, pstate_count = 0; struct dev_pm_opp *opp; - opp_table = _managed_opp(opp_np); - if (opp_table) { - /* OPPs are already managed */ - if (!_add_opp_dev(dev, opp_table)) { - ret = -ENOMEM; - goto put_opp_table; - } - - if (opp_table->parsed_static_opps) { - kref_get(&opp_table->list_kref); - return 0; - } - - goto initialize_static_opps; - } - opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); if (!opp_table) return -ENOMEM; -initialize_static_opps: + /* OPP table is already initialized for the device */ + if (opp_table->parsed_static_opps) { + kref_get(&opp_table->list_kref); + return 0; + } + kref_init(&opp_table->list_kref); /* We have opp-table node now, iterate over it and add OPPs */ @@ -466,7 +458,6 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, put_list_kref: _put_opp_list_kref(opp_table); -put_opp_table: dev_pm_opp_put_opp_table(opp_table); return ret; diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index f9fbb7553fc4..9c6544b4f4f9 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -206,8 +206,10 @@ 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); +struct opp_table *_managed_opp(struct device *dev, int index); #else static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {} +static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; } #endif #ifdef CONFIG_DEBUG_FS From patchwork Wed Sep 19 22:20:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147057 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233122ljw; Wed, 19 Sep 2018 15:21:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYBJIeaQYmhjnrZlKtk3Mlf9Zty/wvPzL9s78hwJrWJxfKS2pybgQS/D64y+mWgVkXW3Xn+ X-Received: by 2002:a17:902:bd44:: with SMTP id b4-v6mr25530251plx.144.1537395664306; Wed, 19 Sep 2018 15:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395664; cv=none; d=google.com; s=arc-20160816; b=geQXBqvZZIAa7/ouP2m7HxFYt+QkxppDb7B61elzBKTHz3/ITZpH2Q7nMFgCp/iFFT 402ppIj9DEkfUp6zJAfindpunm5rnIFxIqs9avisc5yxchDx/xHHmbbn4l5TpjOcSQVu rC162IlfltWIcquVLigkA/QGqHLehYrW6Cs2Sna4VNgKaTdK82XhEOoBDgMPYENBSVqt YZzbvMMi3+yt51BGxcAzU6OTO5k/PeUIVfkLPPopq5pORv76NAL12Pg2MCD40Yo+GcRS dzPT0uUQG+WMYqz8Ta+AVt43ffNXzf57gmHV/W3K2Egj0o8V2mUOQrpcPaazJqz7HgYN FKNg== 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=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=tcl1nmg48DaC9i1KrMB/XgkqbE0+pNwV9qx27U5jomUxc1D2dvScZ3RfmafC6UAyy8 8fK6hXCGGGEO7LUVWOeSyFPNNqkf1ScO4azNK4MCgJLNAqfSAa971pde8f4Wt3hWPeB9 QHcEMAmQMmbFcn7G8o5oThZ1IuO25L0Ch1mrRG0tDew/mC2qrt9xoGI1RXZjYYsgfUSu X2oC0Mfl/gXeX8m7E6nXUg4RdqXcs1XZn5hdLXdTYldlSI1eht3sR5E3iOcbBYt3gjpl 7/6SVU/i36Iyu7q5/WcmPNG0YvsQQ3CbEDL5jbWtcAADdLfdo61SORq4hMQ2NcUL+t4C FHYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hhjieuyC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 c125-v6si22234558pga.268.2018.09.19.15.21.04; Wed, 19 Sep 2018 15:21:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=hhjieuyC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S2387546AbeITEBC (ORCPT + 10 others); Thu, 20 Sep 2018 00:01:02 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38693 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387400AbeITEBC (ORCPT ); Thu, 20 Sep 2018 00:01:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id t84-v6so3394264pgb.5 for ; Wed, 19 Sep 2018 15:21:01 -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=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=hhjieuyCFF5O3dZJ7hBHeN+t4o6LV6wzvk0nAfJBO0tOBLRhitxoGt/uNlyTwgFAuj kiEIPcaxjMAEuTNiHupwpORBRBSIM7YeX/KHhHiOdiowaviDkLmFjis0/ewTbtRkZHdz B12lgvkMKp8upAfDAPVWxk8hzgd7wJ8l19sXg= 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=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=i6FPanH4fsscoFl3RcE0dFDbQt+DI9fpNA7Alv91huc49OTqIK02kIlBpo5C12cARd Fr4zRAhcLU9cE4ZDriZfdA49lOXF6hDAkzwU5yp5JM1Su/dsfRkUz6M9W+Y0diGdReLl LNb5EMXGsKSpHZpi3I+RHWjmTwVczidPzoAWhTiY6ouuFiagqzGmlNvx48qbWUggBIuf C5AEzqVFE5JhDS+7UBIwXbRsWd3nUvVy/O2GafaYGhmaIGH+sfn3ps2rhhI4SS7/945R Krgu6RmwuTWnLVY2/90ofxYsCDo0zvWLdtkl53TvfL++4kYT1aRcI7FQKDaKpQuc2mlS t8wg== X-Gm-Message-State: APzg51CQ7Wc/NSnZyacvPZJ+QcRjJ1mw/b4o0IPHS1kYLaS1F9DQq2za ESxzWa3u0KV0VWZW04Pmt1phLQ== X-Received: by 2002:a63:8648:: with SMTP id x69-v6mr32605489pgd.268.1537395661604; Wed, 19 Sep 2018 15:21:01 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id h130-v6sm27647724pgc.88.2018.09.19.15.21.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:21:00 -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 12/12] OPP: Pass OPP table to _of_add_opp_table_v{1|2}() Date: Wed, 19 Sep 2018 15:20:31 -0700 Message-Id: <9ea47a1cc5f08797e6c854c234acbe269b98405a.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Both _of_add_opp_table_v1() and _of_add_opp_table_v2() contain similar code to get the OPP table and their parent routine also parses the DT to find the OPP table's node pointer. This can be simplified by getting the OPP table in advance and then passing it as argument to these routines. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 68 +++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) -- 2.14.1 diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 1ddef52c27fd..a71ff3acca0f 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -399,18 +399,12 @@ 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, - int index) +static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table) { struct device_node *np; - struct opp_table *opp_table; int ret, count = 0, pstate_count = 0; struct dev_pm_opp *opp; - opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); - if (!opp_table) - return -ENOMEM; - /* OPP table is already initialized for the device */ if (opp_table->parsed_static_opps) { kref_get(&opp_table->list_kref); @@ -420,7 +414,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, 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) { + for_each_available_child_of_node(opp_table->np, np) { count++; ret = _opp_add_static_v2(opp_table, dev, np); @@ -458,15 +452,13 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, put_list_kref: _put_opp_list_kref(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } /* Initializes OPP tables based on old-deprecated bindings */ -static int _of_add_opp_table_v1(struct device *dev) +static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table) { - struct opp_table *opp_table; const struct property *prop; const __be32 *val; int nr, ret = 0; @@ -487,10 +479,6 @@ static int _of_add_opp_table_v1(struct device *dev) return -EINVAL; } - opp_table = dev_pm_opp_get_opp_table(dev); - if (!opp_table) - return -ENOMEM; - kref_init(&opp_table->list_kref); val = prop->value; @@ -503,7 +491,6 @@ static int _of_add_opp_table_v1(struct device *dev) dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", __func__, freq, ret); _put_opp_list_kref(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } nr -= 2; @@ -531,24 +518,24 @@ static int _of_add_opp_table_v1(struct device *dev) */ int dev_pm_opp_of_add_table(struct device *dev) { - struct device_node *opp_np; + struct opp_table *opp_table; int ret; + opp_table = dev_pm_opp_get_opp_table_indexed(dev, 0); + if (!opp_table) + return -ENOMEM; + /* - * OPPs have two version of bindings now. The older one is deprecated, - * try for the new binding first. + * OPPs have two version of bindings now. Also try the old (v1) + * bindings for backward compatibility with older dtbs. */ - opp_np = dev_pm_opp_of_get_opp_desc_node(dev); - if (!opp_np) { - /* - * Try old-deprecated bindings for backward compatibility with - * older dtbs. - */ - return _of_add_opp_table_v1(dev); - } + if (opp_table->np) + ret = _of_add_opp_table_v2(dev, opp_table); + else + ret = _of_add_opp_table_v1(dev, opp_table); - ret = _of_add_opp_table_v2(dev, opp_np, 0); - of_node_put(opp_np); + if (ret) + dev_pm_opp_put_opp_table(opp_table); return ret; } @@ -575,28 +562,29 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); */ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) { - struct device_node *opp_np; + struct opp_table *opp_table; int ret, count; -again: - opp_np = _opp_of_get_opp_desc_node(dev->of_node, index); - if (!opp_np) { + if (index) { /* * If only one phandle is present, then the same OPP table * applies for all index requests. */ count = of_count_phandle_with_args(dev->of_node, "operating-points-v2", NULL); - if (count == 1 && index) { - index = 0; - goto again; - } + if (count != 1) + return -ENODEV; - return -ENODEV; + index = 0; } - ret = _of_add_opp_table_v2(dev, opp_np, index); - of_node_put(opp_np); + opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); + if (!opp_table) + return -ENOMEM; + + ret = _of_add_opp_table_v2(dev, opp_table); + if (ret) + dev_pm_opp_put_opp_table(opp_table); return ret; }