From patchwork Wed Dec 7 10:37:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 87023 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp247074qgi; Wed, 7 Dec 2016 02:48:48 -0800 (PST) X-Received: by 10.84.216.28 with SMTP id m28mr147288080pli.107.1481107728410; Wed, 07 Dec 2016 02:48:48 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u64si23517253pgc.175.2016.12.07.02.48.48; Wed, 07 Dec 2016 02:48:48 -0800 (PST) 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=neutral (body hash did not verify) header.i=@linaro.org; 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=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932129AbcLGKsp (ORCPT + 13 others); Wed, 7 Dec 2016 05:48:45 -0500 Received: from mail-pg0-f43.google.com ([74.125.83.43]:35087 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932111AbcLGKso (ORCPT ); Wed, 7 Dec 2016 05:48:44 -0500 Received: by mail-pg0-f43.google.com with SMTP id p66so160890034pga.2 for ; Wed, 07 Dec 2016 02:48:43 -0800 (PST) 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=dXU4dnmCPWf6SHonBuBIOAcakCgGoO0xYG2JuDY36Vs=; b=YwWznWNjrVjY1pLqyqoC/Du2qrKCVMS3N+s7l6+fIDLlkuLK/ilI5pnK55wxuH4/DX rfKh5hc/TkyWfsaSvalgtzvtdzp8Wd3wbeix6qE2jrkN3N5JAoDHfRIOvIQx7vHmzRfj epdBfwvZbvaACr2ljMX4oegDYfuWJ4xHfd5co= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=dXU4dnmCPWf6SHonBuBIOAcakCgGoO0xYG2JuDY36Vs=; b=jy22ktJRgTtIuo9284q0Dv/CPWgjlGl5rx50akjn8iaTtD9HmXgJqmjLBSmuPj0KaD mLrzw10GdxN05FhY49t8k42wMrVCSfGc1yzYjT+tiglwCto8ddOp8mvrdMUI970VHXEg lEeq4MZdbVXXK86K8XgoD9L6uM1mN/9l0uNYk2xfcQduU/Ms8ea7E8Sd8ZY+zeWzqBV3 Xq2ojsOeCusLH0gI4T+TEjFB39bWu+oPBt6iMpFUjn0B2Xn6tqPa3dSvQx2COqgmqxC+ 5h9yHTD7dzGj/53xmLXcdHZq/hteZTi+WvN5+Ibaztlg7K3NauHFPi3kWXW72HSna8Jl BvLg== X-Gm-Message-State: AKaTC03C8YyvpO4W80Aoiel1axkxD8wv7UhldyQHNOJt76IWpnxGUCLN6YnHPDNS+IhtuooE X-Received: by 10.99.56.82 with SMTP id h18mr118046468pgn.55.1481107290330; Wed, 07 Dec 2016 02:41:30 -0800 (PST) Received: from localhost ([122.172.43.83]) by smtp.gmail.com with ESMTPSA id n24sm41617790pfb.0.2016.12.07.02.41.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 02:41:29 -0800 (PST) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Vincent Guittot , Viresh Kumar Subject: [PATCH 06/12] PM / OPP: Add 'struct kref' to struct dev_pm_opp Date: Wed, 7 Dec 2016 16:07:44 +0530 Message-Id: <1d5f61440dbfb640c330f77c9090e2ac23482ebc.1481106919.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.7.1.410.g6faf27b 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 Add kref to struct dev_pm_opp for easier accounting of the OPPs. Note that the OPPs are freed under the opp_table->lock mutex only. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/core.c | 27 ++++++++++++--------------- drivers/base/power/opp/opp.h | 3 +++ include/linux/pm_opp.h | 3 +++ 3 files changed, 18 insertions(+), 15 deletions(-) -- 2.7.1.410.g6faf27b -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index ec833a8f7aa5..12be0f29f2ad 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c @@ -949,20 +949,10 @@ static void _kfree_opp_rcu(struct rcu_head *head) kfree_rcu(opp, rcu_head); } -/** - * _opp_remove() - Remove an OPP from a table definition - * @opp_table: points back to the opp_table struct this opp belongs to - * @opp: pointer to the OPP to remove - * - * This function removes an opp definition from the opp table. - * - * Locking: The internal opp_table and opp structures are RCU protected. - * It is assumed that the caller holds required mutex for an RCU updater - * strategy. - */ -static void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp) +static void _opp_kref_release(struct kref *kref) { - mutex_lock(&opp_table->lock); + struct dev_pm_opp *opp = container_of(kref, struct dev_pm_opp, kref); + struct opp_table *opp_table = opp->opp_table; /* * Notify the changes in the availability of the operable @@ -977,6 +967,12 @@ static void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp) dev_pm_opp_put_opp_table(opp_table); } +void dev_pm_opp_put(struct dev_pm_opp *opp) +{ + kref_put_mutex(&opp->kref, _opp_kref_release, &opp->opp_table->lock); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_put); + /** * dev_pm_opp_remove() - Remove an OPP from OPP table * @dev: device for which we do this operation @@ -1020,7 +1016,7 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq) goto unlock; } - _opp_remove(opp_table, opp); + dev_pm_opp_put(opp); unlock: mutex_unlock(&opp_table_lock); } @@ -1125,6 +1121,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, mutex_unlock(&opp_table->lock); new_opp->opp_table = opp_table; + kref_init(&new_opp->kref); /* Get a reference to the OPP table */ _get_opp_table_kref(opp_table); @@ -1820,7 +1817,7 @@ void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, /* Free static OPPs */ list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { if (remove_all || !opp->dynamic) - _opp_remove(opp_table, opp); + dev_pm_opp_put(opp); } } else { _remove_opp_dev(_find_opp_dev(dev, opp_table), opp_table); diff --git a/drivers/base/power/opp/opp.h b/drivers/base/power/opp/opp.h index 8435a0eb27be..bd929ba6efaf 100644 --- a/drivers/base/power/opp/opp.h +++ b/drivers/base/power/opp/opp.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -56,6 +57,7 @@ extern struct list_head opp_tables; * are protected by the opp_table_lock for integrity. * IMPORTANT: the opp nodes should be maintained in increasing * order. + * @kref: for reference count of the OPP. * @available: true/false - marks if this OPP as available or not * @dynamic: not-created from static DT entries. * @turbo: true if turbo (boost) OPP @@ -73,6 +75,7 @@ extern struct list_head opp_tables; */ struct dev_pm_opp { struct list_head node; + struct kref kref; bool available; bool dynamic; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 99787cbcaab2..731d548657aa 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -102,6 +102,7 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev, struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, unsigned long *freq); +void dev_pm_opp_put(struct dev_pm_opp *opp); int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt); @@ -193,6 +194,8 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev, return ERR_PTR(-ENOTSUPP); } +static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {} + static inline int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt) {