All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Rui <rui.zhang@intel.com>
To: linux-pm@vger.kernel.org
Cc: Matthew Wilcox <mawilcox@microsoft.com>, Zhang Rui <rui.zhang@intel.com>
Subject: [PATCH 5/5] thermal: clock cooling: convert ID allocation to IDA
Date: Wed, 21 Dec 2016 10:04:15 +0800	[thread overview]
Message-ID: <1482285855-2974-6-git-send-email-rui.zhang@intel.com> (raw)
In-Reply-To: <1482285855-2974-1-git-send-email-rui.zhang@intel.com>

thermal clock cooling currently uses IDRs to allocate IDs, but it only needs
to know whether IDs are in use or not; the ID to pointer functionality
of the IDR is unused. That means it can use the more space-efficient IDA.

CC: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/clock_cooling.c | 46 ++++++-----------------------------------
 1 file changed, 6 insertions(+), 40 deletions(-)

diff --git a/drivers/thermal/clock_cooling.c b/drivers/thermal/clock_cooling.c
index ed5dd0e..f84a8d8 100644
--- a/drivers/thermal/clock_cooling.c
+++ b/drivers/thermal/clock_cooling.c
@@ -23,12 +23,12 @@
 #include <linux/cpufreq.h>
 #include <linux/device.h>
 #include <linux/err.h>
-#include <linux/idr.h>
 #include <linux/mutex.h>
 #include <linux/pm_opp.h>
 #include <linux/slab.h>
 #include <linux/thermal.h>
 #include <linux/clock_cooling.h>
+#include "thermal_core.h"
 
 /**
  * struct clock_cooling_device - data for cooling device with clock
@@ -65,43 +65,9 @@ struct clock_cooling_device {
 };
 #define to_clock_cooling_device(x) \
 		container_of(x, struct clock_cooling_device, clk_rate_change_nb)
-static DEFINE_IDR(clock_idr);
+static DEFINE_IDA(clock_ida);
 static DEFINE_MUTEX(cooling_clock_lock);
 
-/**
- * clock_cooling_get_idr - function to get an unique id.
- * @id: int * value generated by this function.
- *
- * This function will populate @id with an unique
- * id, using the idr API.
- *
- * Return: 0 on success, an error code on failure.
- */
-static int clock_cooling_get_idr(int *id)
-{
-	int ret;
-
-	mutex_lock(&cooling_clock_lock);
-	ret = idr_alloc(&clock_idr, NULL, 0, 0, GFP_KERNEL);
-	mutex_unlock(&cooling_clock_lock);
-	if (unlikely(ret < 0))
-		return ret;
-	*id = ret;
-
-	return 0;
-}
-
-/**
- * release_idr - function to free the unique id.
- * @id: int value representing the unique id.
- */
-static void release_idr(int id)
-{
-	mutex_lock(&cooling_clock_lock);
-	idr_remove(&clock_idr, id);
-	mutex_unlock(&cooling_clock_lock);
-}
-
 /* Below code defines functions to be used for clock as cooling device */
 
 enum clock_cooling_property {
@@ -432,7 +398,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
 	if (IS_ERR(ccdev->clk))
 		return ERR_CAST(ccdev->clk);
 
-	ret = clock_cooling_get_idr(&ccdev->id);
+	ret = get_ida(&clock_ida, &cooling_clock_lock, &ccdev->id);
 	if (ret)
 		return ERR_PTR(-EINVAL);
 
@@ -441,7 +407,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
 	cdev = thermal_cooling_device_register(dev_name, ccdev,
 					       &clock_cooling_ops);
 	if (IS_ERR(cdev)) {
-		release_idr(ccdev->id);
+		release_ida(&clock_ida, &cooling_clock_lock, ccdev->id);
 		return ERR_PTR(-EINVAL);
 	}
 	ccdev->cdev = cdev;
@@ -450,7 +416,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
 	/* Assuming someone has already filled the opp table for this device */
 	ret = dev_pm_opp_init_cpufreq_table(dev, &ccdev->freq_table);
 	if (ret) {
-		release_idr(ccdev->id);
+		release_ida(&clock_ida, &cooling_clock_lock, ccdev->id);
 		return ERR_PTR(ret);
 	}
 	ccdev->clock_state = 0;
@@ -481,6 +447,6 @@ void clock_cooling_unregister(struct thermal_cooling_device *cdev)
 	dev_pm_opp_free_cpufreq_table(ccdev->dev, &ccdev->freq_table);
 
 	thermal_cooling_device_unregister(ccdev->cdev);
-	release_idr(ccdev->id);
+	release_ida(&clock_ida, &cooling_clock_lock, ccdev->id);
 }
 EXPORT_SYMBOL_GPL(clock_cooling_unregister);
-- 
2.7.4


      parent reply	other threads:[~2016-12-21  2:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-21  2:04 [PATCH 0/5] thermal: convert ID allocation to IDA Zhang Rui
2016-12-21  2:04 ` [PATCH 1/5] thermal: core: " Zhang Rui
2016-12-21  2:04 ` [PATCH 2/5] thermal: share get_ida()/release_ida() for other thermal ida users Zhang Rui
2016-12-21 15:54   ` Matthew Wilcox
2016-12-21  2:04 ` [PATCH 3/5] thermal: cpu cooling: convert ID allocation to IDA Zhang Rui
2016-12-21  2:04 ` [PATCH 4/5] thermal: devfreq " Zhang Rui
2016-12-21  2:04 ` Zhang Rui [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482285855-2974-6-git-send-email-rui.zhang@intel.com \
    --to=rui.zhang@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=mawilcox@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.