提交 2f96c035 编写于 作者: M Matthew Wilcox 提交者: Zhang Rui

thermal: convert devfreq_cooling to use an IDA

thermal devfreq cooling does not use the ability to look up pointers by
ID, so convert it from using an IDR to the more space-efficient IDA.
Signed-off-by: NMatthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: NZhang Rui <rui.zhang@intel.com>
上级 ae606089
...@@ -21,14 +21,14 @@ ...@@ -21,14 +21,14 @@
#include <linux/devfreq.h> #include <linux/devfreq.h>
#include <linux/devfreq_cooling.h> #include <linux/devfreq_cooling.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/idr.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/pm_opp.h> #include <linux/pm_opp.h>
#include <linux/thermal.h> #include <linux/thermal.h>
#include <trace/events/thermal.h> #include <trace/events/thermal.h>
static DEFINE_MUTEX(devfreq_lock); static DEFINE_IDA(devfreq_ida);
static DEFINE_IDR(devfreq_idr);
/** /**
* struct devfreq_cooling_device - Devfreq cooling device * struct devfreq_cooling_device - Devfreq cooling device
...@@ -57,42 +57,6 @@ struct devfreq_cooling_device { ...@@ -57,42 +57,6 @@ struct devfreq_cooling_device {
struct devfreq_cooling_power *power_ops; struct devfreq_cooling_power *power_ops;
}; };
/**
* 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 * partition_enable_opps() - disable all opps above a given state
* @dfc: Pointer to devfreq we are operating on * @dfc: Pointer to devfreq we are operating on
...@@ -496,9 +460,10 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, ...@@ -496,9 +460,10 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
if (err) if (err)
goto free_dfc; goto free_dfc;
err = get_idr(&devfreq_idr, &dfc->id); err = ida_simple_get(&devfreq_ida, 0, 0, GFP_KERNEL);
if (err) if (err < 0)
goto free_tables; goto free_tables;
dfc->id = err;
snprintf(dev_name, sizeof(dev_name), "thermal-devfreq-%d", dfc->id); snprintf(dev_name, sizeof(dev_name), "thermal-devfreq-%d", dfc->id);
...@@ -509,15 +474,15 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, ...@@ -509,15 +474,15 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
dev_err(df->dev.parent, dev_err(df->dev.parent,
"Failed to register devfreq cooling device (%d)\n", "Failed to register devfreq cooling device (%d)\n",
err); err);
goto release_idr; goto release_ida;
} }
dfc->cdev = cdev; dfc->cdev = cdev;
return cdev; return cdev;
release_idr: release_ida:
release_idr(&devfreq_idr, dfc->id); ida_simple_remove(&devfreq_ida, dfc->id);
free_tables: free_tables:
kfree(dfc->power_table); kfree(dfc->power_table);
kfree(dfc->freq_table); kfree(dfc->freq_table);
...@@ -565,7 +530,7 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) ...@@ -565,7 +530,7 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev)
dfc = cdev->devdata; dfc = cdev->devdata;
thermal_cooling_device_unregister(dfc->cdev); thermal_cooling_device_unregister(dfc->cdev);
release_idr(&devfreq_idr, dfc->id); ida_simple_remove(&devfreq_ida, dfc->id);
kfree(dfc->power_table); kfree(dfc->power_table);
kfree(dfc->freq_table); kfree(dfc->freq_table);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册