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);