From patchwork Tue May 22 11:34:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 136534 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1501209lji; Tue, 22 May 2018 04:34:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqP7tEDIyffqakLNitum8ySeHvDfD5PDFr6AGkXkId6kSL/5uX8xPwn0Si262ZzyvfzT9Bh X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr23915523pla.287.1526988862154; Tue, 22 May 2018 04:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526988862; cv=none; d=google.com; s=arc-20160816; b=ZqkOeLDyBk+0lE7sF87i1CYfOyki4thxZHYSFHPwtAQVbrghIq4Ibt+VHX+cN4FkyR 9VUxG7ScpI9Y0hn2kkK/XhAaVQCWzWTnvOkOnCOcJbcAPvRT5yGuWKgNDirdD+Re8CX/ IZWgHAeFiIgzOo+obn/Twr5a3NgwIr+Yno88t8LwteHPZ31Zsoe3WN8LbLlzt529wYMs MM1L0OUrMzYTUak4dp52ZW5NF9v4QeiB4tjPnVnRV/m5e0sVw0RkKD689pWgOar986pS NcpowCesv7/c7sBpop/V3OVfjH+i5y2rkqWVsoUdrvZ31GviZJf4RFCb8KmCiDXUDBmA VHDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=9fhSEpFDhOfAXGpRd7GnA7gv001esXQhIOvd+5gtnbQ=; b=T2tsan0GfRqm7scBEIxRkjot+ZhIcCLI+6xvS9qQd3Msv4UiqwNChkcDgiPqtUwWzc ynKCibMSEX6Zbg22WMwgolIQitkUozBv9RNCuQr+Nguhkb10T+ZqDbQkjci65yqGe/gh ZU+WfJfIFkRttUoV7/gEAqMto7jKMRUysbeyJ1ZNDxvIUaY+6zLacGxU188QZZ4yQJP0 dazCWaOCxpD0T/2OpBerCT4z7VjxQVmV++GlNsp8mXE86Wbt5xuT2mOsQM2EaebV/ZCb PZZlKEUOFbG+StwXtw+om2uLSIpSqfmAMbrMZJPbbO0SLY9YzY+56Tz1HLYUStGK5lQj Xgvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nx8gTerE; 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 p1-v6si16083025pfe.158.2018.05.22.04.34.21; Tue, 22 May 2018 04:34:22 -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=Nx8gTerE; 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 S1751278AbeEVLeT (ORCPT + 10 others); Tue, 22 May 2018 07:34:19 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:38156 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752993AbeEVLeQ (ORCPT ); Tue, 22 May 2018 07:34:16 -0400 Received: by mail-pl0-f65.google.com with SMTP id c11-v6so10750436plr.5 for ; Tue, 22 May 2018 04:34:16 -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=9fhSEpFDhOfAXGpRd7GnA7gv001esXQhIOvd+5gtnbQ=; b=Nx8gTerEntlpJkwB8uJXRLau+8wL9DSWyeQutyBkF9c1UWxGLfZpBoKraWJNO9bDyH J6+o/yfDMMTmDH/S+ZsT4FxzKJN/9w8RL+ZiJeZW16uFeRBQNqjGfBYLBhde2Exv2lxj OT89ChevbnyF5xkCUkGvBmp4j8VCIFabUo2MI= 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=9fhSEpFDhOfAXGpRd7GnA7gv001esXQhIOvd+5gtnbQ=; b=PQwfN/lGgg7kMhCz+s6X3QjJ+aAowOKeeAQ8Xs48JfiIBhNQbcFc49zele0Gc9Zrpz Vfag30yaCXltX9fD/wDc2AoXx8N/ANpxu6Euv/fINWH2CtW4YQvwE9mbs1SnpgXHSiVE SsganyIQudZt9ju5T9PJz+4M0Xg9IcratX4Tp/sFbh+MBm/m35nKVm0JDT1LY8mAnk54 rVD52Hw2oTBzVBYUZgLFSxEwSuSeFJXHVZyA0jt3i20iBgR33RgNA5cwKDKWm5bwvcNJ anJ0BCFI7YgE3QtGfcO1N0WQh7isqP06PVZ6p4uqZnJiHsn64PKO0TWzUrMKMfZh8q+X sR+w== X-Gm-Message-State: ALKqPwfw3t+U+7eWIGT4QgkilBQepFJM6WJ8FDUpF7/8CQRfaBQo730F aHea56TY8R61UqW9PbuqU9xfjf2jxuU= X-Received: by 2002:a17:902:bc4a:: with SMTP id t10-v6mr24334312plz.343.1526988856191; Tue, 22 May 2018 04:34:16 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id m14-v6sm25595506pgs.72.2018.05.22.04.34.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 04:34:15 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ilialin@codeaurora.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , amit.kucheria@linaro.org Subject: [PATCH 1/4] PM / OPP: Fix shared OPP table support in dev_pm_opp_set_supported_hw() Date: Tue, 22 May 2018 17:04:06 +0530 Message-Id: <25419de1b8dda24f3e02478b12b724a9b0cc4e78.1526988624.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 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 It should be fine to call dev_pm_opp_set_supported_hw() for all possible CPUs, even if some of them share the OPP table as the caller may not be aware of sharing policy. Lets increment the reference count of the OPP table and return its pointer. The caller need to call dev_pm_opp_put_supported_hw() the same number of times later on to drop all the references. To avoid adding another counter to count how many times dev_pm_opp_set_supported_hw() is called for the same OPP table, dev_pm_opp_put_supported_hw() frees the resources on the very first call made to it, assuming that the caller would be calling it sequentially for all the CPUs. We can revisit that if that assumption is broken in the future. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 6d3624ba89b6..481affb783f3 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1157,7 +1157,6 @@ struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count) { struct opp_table *opp_table; - int ret; opp_table = dev_pm_opp_get_opp_table(dev); if (!opp_table) @@ -1166,29 +1165,20 @@ struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - /* Do we already have a version hierarchy associated with opp_table? */ - if (opp_table->supported_hw) { - dev_err(dev, "%s: Already have supported hardware list\n", - __func__); - ret = -EBUSY; - goto err; - } + /* Another CPU that shares the OPP table has set the property ? */ + if (opp_table->supported_hw) + return opp_table; opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions), GFP_KERNEL); if (!opp_table->supported_hw) { - ret = -ENOMEM; - goto err; + dev_pm_opp_put_opp_table(opp_table); + return ERR_PTR(-ENOMEM); } opp_table->supported_hw_count = count; return opp_table; - -err: - dev_pm_opp_put_opp_table(opp_table); - - return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw); @@ -1205,12 +1195,6 @@ void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - if (!opp_table->supported_hw) { - pr_err("%s: Doesn't have supported hardware list\n", - __func__); - return; - } - kfree(opp_table->supported_hw); opp_table->supported_hw = NULL; opp_table->supported_hw_count = 0; From patchwork Tue May 22 11:34:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 136535 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1501273lji; Tue, 22 May 2018 04:34:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpxyV8059ov65RN6e7lMv9HNSmSyF/aITKgDW8XhAhS9V4W6ZUHCecHZD+SElwx9n/mEDwq X-Received: by 2002:a17:902:1004:: with SMTP id b4-v6mr23915858pla.82.1526988865557; Tue, 22 May 2018 04:34:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526988865; cv=none; d=google.com; s=arc-20160816; b=hS1dypMkvJx+OrT/At6u8sivtYLhdVWCJhxNeGgar7AUebPlGQIL5CqvcbJkS9D+9+ fTSkjHUSX7O0lSu19SBNtq4X15E66FOUUgUDVV6FI/KQym5yBIdatrS0dHuE3j3WbFxw TFpWoowmZFiSR3dDg8icQ03SCJiodG83i5VIPpHjvyG5rBpeTljVlPk/ItrddZZLioo8 H4QFTJ6dG4tBT7QQWOS5U9VBNVGuGtwfF9Eim1K+wbDaUuPZU/eoppf0xDMjHk+dwiyR l8zJuVuke7+M5KwD9wf0CdGhtTZqJbeNjxitO/VY+hx8ImjFL3aucfgyQrQnHo0yR3Ax 9/iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=5T8/cv5o59a28hEbzUm0/3ssnG/cGhlzW/1AMUv0uHo=; b=BPgJdkGRi0LuLLyd1R/MYhMKLSptvU+abKhcE9ah1XgPr+emhh0rSf2sP4/+LLCKCC Nstr/WUlfO79qAKNoG2apBKvaEJLjEE/hEiYarfGXfV6D0ysBAKLiwplk4N+yCaKfH1R xN6DnBS/FNZo3HymDeyB1ZcG7McpcIK5DqBsjBgfZV4pXhoOm5VSkxwi8H+FxeWx09P4 z1CDXhu0+qSi8ZK779vurtuHXfKeUe58ZWwAb4FqJwcLr+t0ywtHpAGzhZ7VanmQcBal cBLoeg1uGCqPjDzNhIjyZ5/rS/TihoRVUrJWRhlSZpeMfTzHdvlGKGvNOJCRw0DKZ0Ex 7fBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aUuoSnQF; 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 p1-v6si16083025pfe.158.2018.05.22.04.34.25; Tue, 22 May 2018 04:34:25 -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=aUuoSnQF; 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 S1752994AbeEVLeX (ORCPT + 10 others); Tue, 22 May 2018 07:34:23 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:44032 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752986AbeEVLeT (ORCPT ); Tue, 22 May 2018 07:34:19 -0400 Received: by mail-pf0-f196.google.com with SMTP id q22-v6so8633380pff.11 for ; Tue, 22 May 2018 04:34:19 -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=5T8/cv5o59a28hEbzUm0/3ssnG/cGhlzW/1AMUv0uHo=; b=aUuoSnQFuQfB2SIrE4xjgJy4iy6E3i5amWrjGx4mbx13nrUg8uNG5eao+Nt6MS/HdO ykP1MOyHls7fXZHqGzKj+pbX8p5MJHTcP9nrUXzQyybxKp3lUGa3Tq1AmMzIg2oCBRUI GjBqkubGUnF1inZUTrxi9KxkmgWFqwxQguvEw= 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=5T8/cv5o59a28hEbzUm0/3ssnG/cGhlzW/1AMUv0uHo=; b=W/niplJwtNwKV4PIUBERNYcN76wFAAgguOsc4usiTTmtk0bn5NxqwlBOtHJQedFvGX vXha8WEfCkcgRTdb3zP3x+po8lGS2/jC1IYsdwEp8rT4lWQB2pTahqXSRStkxno212Gx YI7x2LKPoyaTArEqYGE4AqznEuJKYkGz4BB4xrWUk5AHVwaU6WAJgP8zeN682BRsb0Xm xTeRpCKUTdTLsjTF2dnhicUN4iI/cxsq6lWseJK/vAAsxxiz71a92b6jW2HrImXV7/rJ tvHN61ZdCE7IJTFPhR1XTvlM/2EbvoIhv9TMMwk4nAKuv68jZdqVvLMU+W8lc/8ORSd3 8ViQ== X-Gm-Message-State: ALKqPwcrW4RSAYyQXN1yt2NZgb81llfdmZ8E/EzBdADO+jVm39mFPipU PFileZPkHNWewpoMUyufDYrpqj2gLjc= X-Received: by 2002:a62:7105:: with SMTP id m5-v6mr23275556pfc.167.1526988859296; Tue, 22 May 2018 04:34:19 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id w134-v6sm27796468pfd.187.2018.05.22.04.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 04:34:18 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ilialin@codeaurora.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , amit.kucheria@linaro.org Subject: [PATCH 2/4] PM / OPP: Fix shared OPP table support in dev_pm_opp_set_prop_name() Date: Tue, 22 May 2018 17:04:07 +0530 Message-Id: <878ec1a9f0e5a6b344c12fdc349ec7cb036c2a42.1526988624.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 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 It should be fine to call dev_pm_opp_set_prop_name() for all possible CPUs, even if some of them share the OPP table as the caller may not be aware of sharing policy. Lets increment the reference count of the OPP table and return its pointer. The caller need to call dev_pm_opp_put_prop_name() the same number of times later on to drop all the references. To avoid adding another counter to count how many times dev_pm_opp_set_prop_name() is called for the same OPP table, dev_pm_opp_put_prop_name() frees the resources on the very first call made to it, assuming that the caller would be calling it sequentially for all the CPUs. We can revisit that if that assumption is broken in the future. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 481affb783f3..86e8e2c1905f 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1216,7 +1216,6 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) { struct opp_table *opp_table; - int ret; opp_table = dev_pm_opp_get_opp_table(dev); if (!opp_table) @@ -1225,26 +1224,17 @@ struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - /* Do we already have a prop-name associated with opp_table? */ - if (opp_table->prop_name) { - dev_err(dev, "%s: Already have prop-name %s\n", __func__, - opp_table->prop_name); - ret = -EBUSY; - goto err; - } + /* Another CPU that shares the OPP table has set the property ? */ + if (opp_table->prop_name) + return opp_table; opp_table->prop_name = kstrdup(name, GFP_KERNEL); if (!opp_table->prop_name) { - ret = -ENOMEM; - goto err; + dev_pm_opp_put_opp_table(opp_table); + return ERR_PTR(-ENOMEM); } return opp_table; - -err: - dev_pm_opp_put_opp_table(opp_table); - - return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name); @@ -1261,11 +1251,6 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_table) /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); - if (!opp_table->prop_name) { - pr_err("%s: Doesn't have a prop-name\n", __func__); - return; - } - kfree(opp_table->prop_name); opp_table->prop_name = NULL; From patchwork Tue May 22 11:34:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 136536 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1501298lji; Tue, 22 May 2018 04:34:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoLPMoHUsgy2m8QR35TyrEiew3hapW7zJnm6U+fkWZI4ZiR8Ri+viIPb6QxHSqQ+QZYyOCm X-Received: by 2002:a65:4e03:: with SMTP id r3-v6mr19104181pgt.121.1526988866760; Tue, 22 May 2018 04:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526988866; cv=none; d=google.com; s=arc-20160816; b=ZTNve6b7In2no00V10W8y85nnTooCIyYY5SqoYGL0c/CB1LSFCow0J4hDK0jMVED3I jwJvsNTlgKug2r6N9qha16GwTpw6fOsok9ar1gTVXRZ1PuGVWDsViu3qrWvTH9zrtlmv zhKloCo7zHVv1pxwRRV8t9KiWD2ndbqlF9Faj3wPv88FxWYjKhuKylHsxkb8va92Z4Qn Hm+KR28UE7bdjGIyvZYvcLm5ZzQqmBdVnJmphMgWO5kgwEsgkmfqCpjp/RD+AyROPB3g oNU2X3AfF2Rs34rQUrgwJV5xbl+lDsFACTbr7txFSObGwJkg3NnOk5KfmXC51BjaCqxs f7Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Pp08jTz6aT12v1/R1YgaZvRyRqHCjx/r+S+6v9bTkIs=; b=PaOnmYjt7cgbTSC0pFt3s6HS2KM8H3CCQ7BK7ti4B9RAPtLouoS46+hGrr6YVLJegB 01bHh504V+OAgBDWjbNMCkwqh9/KYkdyMuv4y4JzhODLnHPojmXR/PWTsNwrwRVz70zh WqpV9l4YlzBOpRm7Zk6kwF3GGtut0wPILq0+fA29rYXFNucWpKCHPsLuz/y6WbkoPPlX YvUugB7vRdhJpfLvRgCqv6XzUyJxgdCWqomVjpLO1xLkOgQQ/58fJtW0JrlQhBIH8sOi qi/QMNsg2DCoPFa4CdDqINL36a+8lZJuE6gYeIgfbVX4NpY2N5cqqT4tUrAFw5PhQBrU az6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G0rJCJ6q; 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 p1-v6si16083025pfe.158.2018.05.22.04.34.26; Tue, 22 May 2018 04:34:26 -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=G0rJCJ6q; 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 S1752986AbeEVLeY (ORCPT + 10 others); Tue, 22 May 2018 07:34:24 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:40152 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752719AbeEVLeX (ORCPT ); Tue, 22 May 2018 07:34:23 -0400 Received: by mail-pg0-f65.google.com with SMTP id l2-v6so7749783pgc.7 for ; Tue, 22 May 2018 04:34:22 -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=Pp08jTz6aT12v1/R1YgaZvRyRqHCjx/r+S+6v9bTkIs=; b=G0rJCJ6qNE5tIPqbeSpQKfGrZX88j0IXJTm9ajuIzglx3By0rRFR40QAnvQuwqUf35 Gy3qvHLtYz1pBx2Ju7fGHQS5yhdezr9AMyoD7n0c5tJrxNchHqoRrbO7i/BdSSXl9DGs y213bKMod8vjy3mEaXiPbb5fvQ89HXjMCKl3I= 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=Pp08jTz6aT12v1/R1YgaZvRyRqHCjx/r+S+6v9bTkIs=; b=EIll4yKqlUJ7N7PM07/Ri3lDojlU93FsRVqHkvseJxcma1GYL9zgpyUEuM6zE6B4AO Wc2Y/kvBFiZj1zlPAbDAsvCZxyRHsCnxicQlYjvTXwHCnFFXYuvxsPjUzztzIa4i59W5 D778e9lIyf3gMIY91dpMZALNs/n0m2kwjFVHpBG71LLl4zofsyk8ndGtGbKzCapqzfWM EHoYP5m4+iZc1HcQgKn4tNI945XS9TX2rCpDHBa2gdWnPOkNmeag++3lJxU7GZSBPKGG A5Gz8cLt2b+hTj66LeO1tkiRr43IzderGpg3oOntVYs8jFvpVuSzncLqqfKBYvHxavFB mU2g== X-Gm-Message-State: ALKqPwfrdzNelp4yanFvBZmG5yZfSSIwz4n+Qorxx7qDjvy4nSzGyyG0 ZV9O8SVBiUC7FlTI5VThOsm/RQ== X-Received: by 2002:a62:5610:: with SMTP id k16-v6mr23674080pfb.19.1526988862524; Tue, 22 May 2018 04:34:22 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id x84-v6sm38719430pfi.160.2018.05.22.04.34.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 04:34:22 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ilialin@codeaurora.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , amit.kucheria@linaro.org Subject: [PATCH 3/4] PM / OPP: Fix shared OPP table support in dev_pm_opp_set_regulators() Date: Tue, 22 May 2018 17:04:08 +0530 Message-Id: <779b783cfaa726cbe35317ae2c1968c5496a3a03.1526988624.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 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 It should be fine to call dev_pm_opp_set_regulators() for all possible CPUs, even if some of them share the OPP table as the caller may not be aware of sharing policy. Lets increment the reference count of the OPP table and return its pointer. The caller need to call dev_pm_opp_put_regulators() the same number of times later on to drop all the references. To avoid adding another counter to count how many times dev_pm_opp_set_regulators() is called for the same OPP table, dev_pm_opp_put_regulators() frees the resources on the very first call made to it, assuming that the caller would be calling it sequentially for all the CPUs. We can revisit that if that assumption is broken in the future. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 86e8e2c1905f..780c89a49d18 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1320,11 +1320,9 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev, goto err; } - /* Already have regulators set */ - if (opp_table->regulators) { - ret = -EBUSY; - goto err; - } + /* Another CPU that shares the OPP table has set the regulators ? */ + if (opp_table->regulators) + return opp_table; opp_table->regulators = kmalloc_array(count, sizeof(*opp_table->regulators), @@ -1378,10 +1376,8 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table) { int i; - if (!opp_table->regulators) { - pr_err("%s: Doesn't have regulators set\n", __func__); - return; - } + if (!opp_table->regulators) + goto put_opp_table; /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); @@ -1395,6 +1391,7 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table) opp_table->regulators = NULL; opp_table->regulator_count = 0; +put_opp_table: dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators); From patchwork Tue May 22 11:34:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 136537 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1501433lji; Tue, 22 May 2018 04:34:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpwo8oYFdHO6tTyKix6VdjDPRMUsz3FsDtrf4LkzJ3KeMkfls2t+VP+oD37Q4wykP/c8eEx X-Received: by 2002:a65:61c8:: with SMTP id j8-v6mr18730723pgv.370.1526988873450; Tue, 22 May 2018 04:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526988873; cv=none; d=google.com; s=arc-20160816; b=qmoAhNjmzui383A2LtJqg2xv+87W2wQGnKMOYCQQwocWnv61vNTMqi9wzNL2Br2gFi zeX8IR5ySPv4YZdyXukVFYAqKl1k9IEyNiMKA0H/RiWRKsOt0fqk0GooGUHhZZXYYiUB tOoNHu4Dh139be8lCEXoM/qb7Wi9rd2scbsnDA5B2qB16PjgTlxpzIU37g/SZQ41pI6e KDPTR0KrEWlgkczjIbttTLoWStLx5zHIUYeb4uvqb/4GxLAq56QKf9/eWo9+u6FUKgW8 tQvzME4DEv1ONlLIYkqiMTTcAqE+yhCgHj43bW7VVrz+ubmOGUspF4t3ky2cQ4f/aluf Ks4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Yl7zp/L8fRi8phM4xTrgkJO1DrtRi8ypmUvBOZ65yU8=; b=J0VEqdvo4ajMgphFWQtwCt3/mJ74lPWNjG8VQLyRycpjR6pP+4A81kzY7tEh+A9TuE wOnF/xDwzgzRl/5MG9GXF4cCNrzC5adTWs6RUjINIwKOQ3Yo4kdlHTKHrhosmKc/GYE6 pYFeO/bK5nUaRbXumj9XUmooV1mM85kaNIZmu2xOBR5gRzgdOPhBMzFh7Mv7CfPUO+la sK/4NHrFMERYhr9RNUVx431xROZGghluF1TZ3r8ur7xU0u0jPZVIp9oDaO9MZ/V9GQX2 gsBmawY1xi6tSzW/6JeLJX1sEEukvidayxEXBa5ZLmcWFco/THLY+lgLEeETiMkDTUUp dAVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WkgxSmfx; 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 o8-v6si12530857pgp.628.2018.05.22.04.34.33; Tue, 22 May 2018 04:34:33 -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=WkgxSmfx; 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 S1752825AbeEVLea (ORCPT + 10 others); Tue, 22 May 2018 07:34:30 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:40648 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752719AbeEVLe0 (ORCPT ); Tue, 22 May 2018 07:34:26 -0400 Received: by mail-pl0-f67.google.com with SMTP id t12-v6so10740454plo.7 for ; Tue, 22 May 2018 04:34:26 -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=Yl7zp/L8fRi8phM4xTrgkJO1DrtRi8ypmUvBOZ65yU8=; b=WkgxSmfxVRhxPTx/9hzWoY8BoNluVwbIGNO4+Z9DOgfQujeYDJmfxpCnkPtyiQDt2F pJWf61qDrkGiHl7/NL0DwNre1I8fDS3Iac4UZUYgCRPkSWsvtKIaP5khGaxclBT1bJn/ bbYC2VZWjjAK28ulrIAKrbDs8jeLAo+s0PHFk= 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=Yl7zp/L8fRi8phM4xTrgkJO1DrtRi8ypmUvBOZ65yU8=; b=SDK1ATxXXaqqxqq3g0y3/1pukEUoVf1bxfAvuY3xwb1oJ9R5088jCiHm3q27ZL6rI4 CgOqCytcLlcYSDMKJtfCo8h9iCHWKw2yrnFK0DS6+hhq/rgAAnjw65MPVtvlx1yP3Mjm EiPtEL572V17iftfeOrkBWrHSx7NDaKbentT1tk38bkniAhXac9OemO57em3WKWVBb5X AWZWG2wsOp9+oDGaVHpAl0it+1mGlPZZRLvb0uzE6ijchdQLJ/TLp0MIjRJfcw+QA7VQ 3edou34OIT/DcTSJb+BKSLbPJVMW51xDpNWxiptjL3BEhqm4oKGV+erxWXeE5tt/hvgs GKIA== X-Gm-Message-State: ALKqPwcxcYHMRvGNCssH5fj3kUvi4mhGy6Q/H+q259zd8znQRqOhEZU3 A1XHRk8PW1ZCovgR/QMJwRrx5w== X-Received: by 2002:a17:902:2848:: with SMTP id e66-v6mr16817314plb.319.1526988866141; Tue, 22 May 2018 04:34:26 -0700 (PDT) Received: from localhost ([122.167.163.112]) by smtp.gmail.com with ESMTPSA id a4-v6sm34935884pfj.19.2018.05.22.04.34.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 04:34:25 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , ilialin@codeaurora.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , amit.kucheria@linaro.org Subject: [PATCH 4/4] PM / OPP: Fix shared OPP table support in dev_pm_opp_register_set_opp_helper() Date: Tue, 22 May 2018 17:04:09 +0530 Message-Id: <5019acc693d3183a19d4844f6e2d878ea2dd7ddd.1526988624.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 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 It should be fine to call dev_pm_opp_register_set_opp_helper() for all possible CPUs, even if some of them share the OPP table as the caller may not be aware of sharing policy. Lets increment the reference count of the OPP table and return its pointer. The caller need to call dev_pm_opp_register_put_opp_helper() the same number of times later on to drop all the references. To avoid adding another counter to count how many times dev_pm_opp_register_set_opp_helper() is called for the same OPP table, dev_pm_opp_register_put_opp_helper() frees the resources on the very first call made to it, assuming that the caller would be calling it sequentially for all the CPUs. We can revisit that if that assumption is broken in the future. Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 780c89a49d18..ab2f3fead6b1 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1477,7 +1477,6 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)) { struct opp_table *opp_table; - int ret; if (!set_opp) return ERR_PTR(-EINVAL); @@ -1488,24 +1487,15 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, /* This should be called before OPPs are initialized */ if (WARN_ON(!list_empty(&opp_table->opp_list))) { - ret = -EBUSY; - goto err; - } - - /* Already have custom set_opp helper */ - if (WARN_ON(opp_table->set_opp)) { - ret = -EBUSY; - goto err; + dev_pm_opp_put_opp_table(opp_table); + return ERR_PTR(-EBUSY); } - opp_table->set_opp = set_opp; + /* Another CPU that shares the OPP table has set the helper ? */ + if (!opp_table->set_opp) + opp_table->set_opp = set_opp; return opp_table; - -err: - dev_pm_opp_put_opp_table(opp_table); - - return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper); @@ -1518,17 +1508,10 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper); */ void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) { - if (!opp_table->set_opp) { - pr_err("%s: Doesn't have custom set_opp helper set\n", - __func__); - return; - } - /* Make sure there are no concurrent readers while updating opp_table */ WARN_ON(!list_empty(&opp_table->opp_list)); opp_table->set_opp = NULL; - dev_pm_opp_put_opp_table(opp_table); } EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper);