All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] thermal: convert ID allocation to IDA
@ 2016-12-21  2:04 Zhang Rui
  2016-12-21  2:04 ` [PATCH 1/5] thermal: core: " Zhang Rui
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Zhang Rui @ 2016-12-21  2:04 UTC (permalink / raw)
  To: linux-pm

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

This patch set converts ID allocation to IDA for thermal subsystem.

PS: only build test is done for this patch set.

thanks,
rui

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] thermal: core: convert ID allocation to IDA
  2016-12-21  2:04 [PATCH 0/5] thermal: convert ID allocation to IDA Zhang Rui
@ 2016-12-21  2:04 ` Zhang Rui
  2016-12-21  2:04 ` [PATCH 2/5] thermal: share get_ida()/release_ida() for other thermal ida users Zhang Rui
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Zhang Rui @ 2016-12-21  2:04 UTC (permalink / raw)
  To: linux-pm; +Cc: Matthew Wilcox, Zhang Rui

thermal core 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/thermal_core.c | 75 +++++++++++++++++++++---------------------
 include/linux/thermal.h        |  4 +--
 2 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 641faab..1b6fde2 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -36,9 +36,9 @@ MODULE_AUTHOR("Zhang Rui");
 MODULE_DESCRIPTION("Generic thermal management sysfs support");
 MODULE_LICENSE("GPL v2");
 
-static DEFINE_IDR(thermal_tz_idr);
-static DEFINE_IDR(thermal_cdev_idr);
-static DEFINE_MUTEX(thermal_idr_lock);
+static DEFINE_IDA(thermal_tz_ida);
+static DEFINE_IDA(thermal_cdev_ida);
+static DEFINE_MUTEX(thermal_ida_lock);
 
 static LIST_HEAD(thermal_tz_list);
 static LIST_HEAD(thermal_cdev_list);
@@ -589,28 +589,29 @@ void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
  * - thermal zone devices lifecycle: registration, unregistration,
  *				     binding, and unbinding.
  */
-static int get_idr(struct idr *idr, struct mutex *lock, int *id)
+static int get_ida(struct ida *ida, struct mutex *lock, int *id)
 {
 	int ret;
 
-	if (lock)
+	if (!ida || !lock || !id)
+		return -EINVAL;
+	do {
+		if (!ida_pre_get(ida, GFP_KERNEL))
+			return -ENOMEM;
 		mutex_lock(lock);
-	ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
-	if (lock)
+		ret = ida_get_new(ida, id);
 		mutex_unlock(lock);
-	if (unlikely(ret < 0))
-		return ret;
-	*id = ret;
-	return 0;
+	} while (ret == -EAGAIN);
+	return ret;
 }
 
-static void release_idr(struct idr *idr, struct mutex *lock, int id)
+static void release_ida(struct ida *ida, struct mutex *lock, int id)
 {
-	if (lock)
-		mutex_lock(lock);
-	idr_remove(idr, id);
-	if (lock)
-		mutex_unlock(lock);
+	if (!ida || !lock)
+		return;
+	mutex_lock(lock);
+	ida_remove(ida, id);
+	mutex_unlock(lock);
 }
 
 /**
@@ -685,7 +686,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 	dev->target = THERMAL_NO_TARGET;
 	dev->weight = weight;
 
-	result = get_idr(&tz->idr, &tz->lock, &dev->id);
+	result = get_ida(&tz->ida, &tz->lock, &dev->id);
 	if (result)
 		goto free_mem;
 
@@ -693,7 +694,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 	result =
 	    sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
 	if (result)
-		goto release_idr;
+		goto release_ida;
 
 	sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
 	sysfs_attr_init(&dev->attr.attr);
@@ -737,8 +738,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 	device_remove_file(&tz->device, &dev->attr);
 remove_symbol_link:
 	sysfs_remove_link(&tz->device.kobj, dev->name);
-release_idr:
-	release_idr(&tz->idr, &tz->lock, dev->id);
+release_ida:
+	release_ida(&tz->ida, &tz->lock, dev->id);
 free_mem:
 	kfree(dev);
 	return result;
@@ -785,7 +786,7 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
 	device_remove_file(&tz->device, &pos->weight_attr);
 	device_remove_file(&tz->device, &pos->attr);
 	sysfs_remove_link(&tz->device.kobj, pos->name);
-	release_idr(&tz->idr, &tz->lock, pos->id);
+	release_ida(&tz->ida, &tz->lock, pos->id);
 	kfree(pos);
 	return 0;
 }
@@ -920,7 +921,7 @@ __thermal_cooling_device_register(struct device_node *np,
 	if (!cdev)
 		return ERR_PTR(-ENOMEM);
 
-	result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
+	result = get_ida(&thermal_cdev_ida, &thermal_ida_lock, &cdev->id);
 	if (result) {
 		kfree(cdev);
 		return ERR_PTR(result);
@@ -938,7 +939,7 @@ __thermal_cooling_device_register(struct device_node *np,
 	dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
 	result = device_register(&cdev->device);
 	if (result) {
-		release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
+		release_ida(&thermal_cdev_ida, &thermal_ida_lock, cdev->id);
 		kfree(cdev);
 		return ERR_PTR(result);
 	}
@@ -1065,7 +1066,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
 
 	mutex_unlock(&thermal_list_lock);
 
-	release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
+	release_ida(&thermal_cdev_ida, &thermal_ida_lock, cdev->id);
 	device_unregister(&cdev->device);
 }
 EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
@@ -1167,9 +1168,9 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 		return ERR_PTR(-ENOMEM);
 
 	INIT_LIST_HEAD(&tz->thermal_instances);
-	idr_init(&tz->idr);
+	ida_init(&tz->ida);
 	mutex_init(&tz->lock);
-	result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
+	result = get_ida(&thermal_tz_ida, &thermal_ida_lock, &tz->id);
 	if (result) {
 		kfree(tz);
 		return ERR_PTR(result);
@@ -1196,7 +1197,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 	dev_set_name(&tz->device, "thermal_zone%d", tz->id);
 	result = device_register(&tz->device);
 	if (result) {
-		release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
+		release_ida(&thermal_tz_ida, &thermal_ida_lock, tz->id);
 		kfree(tz);
 		return ERR_PTR(result);
 	}
@@ -1250,7 +1251,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 	return tz;
 
 unregister:
-	release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
+	release_ida(&thermal_tz_ida, &thermal_ida_lock, tz->id);
 	device_unregister(&tz->device);
 	return ERR_PTR(result);
 }
@@ -1312,8 +1313,8 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
 	thermal_set_governor(tz, NULL);
 
 	thermal_remove_hwmon_sysfs(tz);
-	release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
-	idr_destroy(&tz->idr);
+	release_ida(&thermal_tz_ida, &thermal_ida_lock, tz->id);
+	ida_destroy(&tz->ida);
 	mutex_destroy(&tz->lock);
 	device_unregister(&tz->device);
 	kfree(tz->device.groups);
@@ -1514,9 +1515,9 @@ static int __init thermal_init(void)
 unregister_governors:
 	thermal_unregister_governors();
 error:
-	idr_destroy(&thermal_tz_idr);
-	idr_destroy(&thermal_cdev_idr);
-	mutex_destroy(&thermal_idr_lock);
+	ida_destroy(&thermal_tz_ida);
+	ida_destroy(&thermal_cdev_ida);
+	mutex_destroy(&thermal_ida_lock);
 	mutex_destroy(&thermal_list_lock);
 	mutex_destroy(&thermal_governor_lock);
 	return result;
@@ -1529,9 +1530,9 @@ static void __exit thermal_exit(void)
 	genetlink_exit();
 	class_unregister(&thermal_class);
 	thermal_unregister_governors();
-	idr_destroy(&thermal_tz_idr);
-	idr_destroy(&thermal_cdev_idr);
-	mutex_destroy(&thermal_idr_lock);
+	ida_destroy(&thermal_tz_ida);
+	ida_destroy(&thermal_cdev_ida);
+	mutex_destroy(&thermal_ida_lock);
 	mutex_destroy(&thermal_list_lock);
 	mutex_destroy(&thermal_governor_lock);
 }
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index e275e98..dab11f9 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -194,7 +194,7 @@ struct thermal_attr {
  * @governor:	pointer to the governor for this thermal zone
  * @governor_data:	private pointer for governor data
  * @thermal_instances:	list of &struct thermal_instance of this thermal zone
- * @idr:	&struct idr to generate unique id for this zone's cooling
+ * @ida:	&struct ida to generate unique id for this zone's cooling
  *		devices
  * @lock:	lock to protect thermal_instances list
  * @node:	node in thermal_tz_list (in thermal_core.c)
@@ -227,7 +227,7 @@ struct thermal_zone_device {
 	struct thermal_governor *governor;
 	void *governor_data;
 	struct list_head thermal_instances;
-	struct idr idr;
+	struct ida ida;
 	struct mutex lock;
 	struct list_head node;
 	struct delayed_work poll_queue;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] thermal: share get_ida()/release_ida() for other thermal ida users
  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 ` 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
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Zhang Rui @ 2016-12-21  2:04 UTC (permalink / raw)
  To: linux-pm; +Cc: Matthew Wilcox, Zhang Rui

CC: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c | 4 ++--
 drivers/thermal/thermal_core.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 1b6fde2..5849727 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -589,7 +589,7 @@ void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
  * - thermal zone devices lifecycle: registration, unregistration,
  *				     binding, and unbinding.
  */
-static int get_ida(struct ida *ida, struct mutex *lock, int *id)
+int get_ida(struct ida *ida, struct mutex *lock, int *id)
 {
 	int ret;
 
@@ -605,7 +605,7 @@ static int get_ida(struct ida *ida, struct mutex *lock, int *id)
 	return ret;
 }
 
-static void release_ida(struct ida *ida, struct mutex *lock, int id)
+void release_ida(struct ida *ida, struct mutex *lock, int id)
 {
 	if (!ida || !lock)
 		return;
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 2412b37..e49f9f5 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -68,6 +68,8 @@ void thermal_zone_device_unbind_exception(struct thermal_zone_device *,
 					  const char *, size_t);
 int thermal_zone_device_set_policy(struct thermal_zone_device *, char *);
 int thermal_build_list_of_policies(char *buf);
+int get_ida(struct ida *, struct mutex *, int *);
+void release_ida(struct ida *, struct mutex *, int);
 
 /* sysfs I/F */
 int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] thermal: cpu cooling: convert ID allocation to IDA
  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  2:04 ` Zhang Rui
  2016-12-21  2:04 ` [PATCH 4/5] thermal: devfreq " Zhang Rui
  2016-12-21  2:04 ` [PATCH 5/5] thermal: clock " Zhang Rui
  4 siblings, 0 replies; 7+ messages in thread
From: Zhang Rui @ 2016-12-21  2:04 UTC (permalink / raw)
  To: linux-pm; +Cc: Zhang Rui

thermal cpu 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.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/cpu_cooling.c | 50 ++++++-------------------------------------
 1 file changed, 7 insertions(+), 43 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 9ce0e9e..6ade44d 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -32,7 +32,7 @@
 #include <linux/cpu_cooling.h>
 
 #include <trace/events/thermal.h>
-
+#include "thermal_core.h"
 /*
  * Cooling state <-> CPUFreq frequency
  *
@@ -104,7 +104,7 @@ struct cpufreq_cooling_device {
 	struct device *cpu_dev;
 	get_static_t plat_get_static_power;
 };
-static DEFINE_IDR(cpufreq_idr);
+static DEFINE_IDA(cpufreq_ida);
 static DEFINE_MUTEX(cooling_cpufreq_lock);
 
 static unsigned int cpufreq_dev_count;
@@ -112,42 +112,6 @@ static unsigned int cpufreq_dev_count;
 static DEFINE_MUTEX(cooling_list_lock);
 static LIST_HEAD(cpufreq_dev_list);
 
-/**
- * get_idr - function to get a unique id.
- * @idr: struct idr * handle used to create a 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 get_idr(struct idr *idr, int *id)
-{
-	int ret;
-
-	mutex_lock(&cooling_cpufreq_lock);
-	ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
-	mutex_unlock(&cooling_cpufreq_lock);
-	if (unlikely(ret < 0))
-		return ret;
-	*id = ret;
-
-	return 0;
-}
-
-/**
- * release_idr - function to free the unique id.
- * @idr: struct idr * handle used for creating the id.
- * @id: int value representing the unique id.
- */
-static void release_idr(struct idr *idr, int id)
-{
-	mutex_lock(&cooling_cpufreq_lock);
-	idr_remove(idr, id);
-	mutex_unlock(&cooling_cpufreq_lock);
-}
-
 /* Below code defines functions to be used for cpufreq as cooling device */
 
 /**
@@ -874,7 +838,7 @@ __cpufreq_cooling_register(struct device_node *np,
 		cooling_ops = &cpufreq_cooling_ops;
 	}
 
-	ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
+	ret = get_ida(&cpufreq_ida, &cooling_cpufreq_lock, &cpufreq_dev->id);
 	if (ret) {
 		cool_dev = ERR_PTR(ret);
 		goto free_power_table;
@@ -898,7 +862,7 @@ __cpufreq_cooling_register(struct device_node *np,
 	cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev,
 						      cooling_ops);
 	if (IS_ERR(cool_dev))
-		goto remove_idr;
+		goto remove_ida;
 
 	cpufreq_dev->clipped_freq = cpufreq_dev->freq_table[0];
 	cpufreq_dev->cool_dev = cool_dev;
@@ -917,8 +881,8 @@ __cpufreq_cooling_register(struct device_node *np,
 
 	goto put_policy;
 
-remove_idr:
-	release_idr(&cpufreq_idr, cpufreq_dev->id);
+remove_ida:
+	release_ida(&cpufreq_ida, &cooling_cpufreq_lock, cpufreq_dev->id);
 free_power_table:
 	kfree(cpufreq_dev->dyn_power_table);
 free_table:
@@ -1072,7 +1036,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
 	mutex_unlock(&cooling_cpufreq_lock);
 
 	thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
-	release_idr(&cpufreq_idr, cpufreq_dev->id);
+	release_ida(&cpufreq_ida, &cooling_cpufreq_lock, cpufreq_dev->id);
 	kfree(cpufreq_dev->dyn_power_table);
 	kfree(cpufreq_dev->time_in_idle_timestamp);
 	kfree(cpufreq_dev->time_in_idle);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] thermal: devfreq cooling: convert ID allocation to IDA
  2016-12-21  2:04 [PATCH 0/5] thermal: convert ID allocation to IDA Zhang Rui
                   ` (2 preceding siblings ...)
  2016-12-21  2:04 ` [PATCH 3/5] thermal: cpu cooling: convert ID allocation to IDA Zhang Rui
@ 2016-12-21  2:04 ` Zhang Rui
  2016-12-21  2:04 ` [PATCH 5/5] thermal: clock " Zhang Rui
  4 siblings, 0 replies; 7+ messages in thread
From: Zhang Rui @ 2016-12-21  2:04 UTC (permalink / raw)
  To: linux-pm; +Cc: Matthew Wilcox, Zhang Rui

thermal devfreq 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/devfreq_cooling.c | 49 ++++++---------------------------------
 1 file changed, 7 insertions(+), 42 deletions(-)

diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
index 5a737fd..00832bb 100644
--- a/drivers/thermal/devfreq_cooling.c
+++ b/drivers/thermal/devfreq_cooling.c
@@ -26,9 +26,10 @@
 #include <linux/thermal.h>
 
 #include <trace/events/thermal.h>
+#include <thermal_core.h>
 
 static DEFINE_MUTEX(devfreq_lock);
-static DEFINE_IDR(devfreq_idr);
+static DEFINE_IDA(devfreq_ida);
 
 /**
  * struct devfreq_cooling_device - Devfreq cooling device
@@ -58,42 +59,6 @@ struct devfreq_cooling_device {
 };
 
 /**
- * get_idr - function to get a unique id.
- * @idr: struct idr * handle used to create a 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 get_idr(struct idr *idr, int *id)
-{
-	int ret;
-
-	mutex_lock(&devfreq_lock);
-	ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
-	mutex_unlock(&devfreq_lock);
-	if (unlikely(ret < 0))
-		return ret;
-	*id = ret;
-
-	return 0;
-}
-
-/**
- * release_idr - function to free the unique id.
- * @idr: struct idr * handle used for creating the id.
- * @id: int value representing the unique id.
- */
-static void release_idr(struct idr *idr, int id)
-{
-	mutex_lock(&devfreq_lock);
-	idr_remove(idr, id);
-	mutex_unlock(&devfreq_lock);
-}
-
-/**
  * partition_enable_opps() - disable all opps above a given state
  * @dfc:	Pointer to devfreq we are operating on
  * @cdev_state:	cooling device state we're setting
@@ -496,7 +461,7 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
 	if (err)
 		goto free_dfc;
 
-	err = get_idr(&devfreq_idr, &dfc->id);
+	err = get_ida(&devfreq_ida, &devfreq_lock, &dfc->id);
 	if (err)
 		goto free_tables;
 
@@ -509,15 +474,15 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
 		dev_err(df->dev.parent,
 			"Failed to register devfreq cooling device (%d)\n",
 			err);
-		goto release_idr;
+		goto release_ida;
 	}
 
 	dfc->cdev = cdev;
 
 	return cdev;
 
-release_idr:
-	release_idr(&devfreq_idr, dfc->id);
+release_ida:
+	release_ida(&devfreq_ida, &devfreq_lock, dfc->id);
 free_tables:
 	kfree(dfc->power_table);
 	kfree(dfc->freq_table);
@@ -565,7 +530,7 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
 	dfc = cdev->devdata;
 
 	thermal_cooling_device_unregister(dfc->cdev);
-	release_idr(&devfreq_idr, dfc->id);
+	release_ida(&devfreq_ida, &devfreq_lock, dfc->id);
 	kfree(dfc->power_table);
 	kfree(dfc->freq_table);
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] thermal: clock cooling: convert ID allocation to IDA
  2016-12-21  2:04 [PATCH 0/5] thermal: convert ID allocation to IDA Zhang Rui
                   ` (3 preceding siblings ...)
  2016-12-21  2:04 ` [PATCH 4/5] thermal: devfreq " Zhang Rui
@ 2016-12-21  2:04 ` Zhang Rui
  4 siblings, 0 replies; 7+ messages in thread
From: Zhang Rui @ 2016-12-21  2:04 UTC (permalink / raw)
  To: linux-pm; +Cc: Matthew Wilcox, Zhang Rui

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: [PATCH 2/5] thermal: share get_ida()/release_ida() for other thermal ida users
  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
  0 siblings, 0 replies; 7+ messages in thread
From: Matthew Wilcox @ 2016-12-21 15:54 UTC (permalink / raw)
  To: Zhang Rui, linux-pm

From: Zhang Rui [mailto:rui.zhang@intel.com]
>   * - thermal zone devices lifecycle: registration, unregistration,
>   *				     binding, and unbinding.
>   */
> -static int get_ida(struct ida *ida, struct mutex *lock, int *id)
> +int get_ida(struct ida *ida, struct mutex *lock, int *id)

I don't like making a function as generically named as "get_ida" non-static.  Unless it's part of the IDA code :-)  In any case, I don't think these drivers need their own mutexes, so I sent a replacement set of patches.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-12-21 22:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 5/5] thermal: clock " Zhang Rui

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.