mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
thermal core: convert ID allocation to IDA
The thermal core 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: Matthew Wilcox <mawilcox@microsoft.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
This commit is contained in:
parent
0c744ea4f7
commit
b31ef8285b
2 changed files with 28 additions and 51 deletions
|
@ -36,9 +36,8 @@ MODULE_AUTHOR("Zhang Rui");
|
||||||
MODULE_DESCRIPTION("Generic thermal management sysfs support");
|
MODULE_DESCRIPTION("Generic thermal management sysfs support");
|
||||||
MODULE_LICENSE("GPL v2");
|
MODULE_LICENSE("GPL v2");
|
||||||
|
|
||||||
static DEFINE_IDR(thermal_tz_idr);
|
static DEFINE_IDA(thermal_tz_ida);
|
||||||
static DEFINE_IDR(thermal_cdev_idr);
|
static DEFINE_IDA(thermal_cdev_ida);
|
||||||
static DEFINE_MUTEX(thermal_idr_lock);
|
|
||||||
|
|
||||||
static LIST_HEAD(thermal_tz_list);
|
static LIST_HEAD(thermal_tz_list);
|
||||||
static LIST_HEAD(thermal_cdev_list);
|
static LIST_HEAD(thermal_cdev_list);
|
||||||
|
@ -589,29 +588,6 @@ void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz,
|
||||||
* - thermal zone devices lifecycle: registration, unregistration,
|
* - thermal zone devices lifecycle: registration, unregistration,
|
||||||
* binding, and unbinding.
|
* binding, and unbinding.
|
||||||
*/
|
*/
|
||||||
static int get_idr(struct idr *idr, struct mutex *lock, int *id)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (lock)
|
|
||||||
mutex_lock(lock);
|
|
||||||
ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
|
|
||||||
if (lock)
|
|
||||||
mutex_unlock(lock);
|
|
||||||
if (unlikely(ret < 0))
|
|
||||||
return ret;
|
|
||||||
*id = ret;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void release_idr(struct idr *idr, struct mutex *lock, int id)
|
|
||||||
{
|
|
||||||
if (lock)
|
|
||||||
mutex_lock(lock);
|
|
||||||
idr_remove(idr, id);
|
|
||||||
if (lock)
|
|
||||||
mutex_unlock(lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
|
* thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
|
||||||
|
@ -685,15 +661,16 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
|
||||||
dev->target = THERMAL_NO_TARGET;
|
dev->target = THERMAL_NO_TARGET;
|
||||||
dev->weight = weight;
|
dev->weight = weight;
|
||||||
|
|
||||||
result = get_idr(&tz->idr, &tz->lock, &dev->id);
|
result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL);
|
||||||
if (result)
|
if (result < 0)
|
||||||
goto free_mem;
|
goto free_mem;
|
||||||
|
|
||||||
|
dev->id = result;
|
||||||
sprintf(dev->name, "cdev%d", dev->id);
|
sprintf(dev->name, "cdev%d", dev->id);
|
||||||
result =
|
result =
|
||||||
sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
|
sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
|
||||||
if (result)
|
if (result)
|
||||||
goto release_idr;
|
goto release_ida;
|
||||||
|
|
||||||
sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
|
sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
|
||||||
sysfs_attr_init(&dev->attr.attr);
|
sysfs_attr_init(&dev->attr.attr);
|
||||||
|
@ -737,8 +714,8 @@ remove_trip_file:
|
||||||
device_remove_file(&tz->device, &dev->attr);
|
device_remove_file(&tz->device, &dev->attr);
|
||||||
remove_symbol_link:
|
remove_symbol_link:
|
||||||
sysfs_remove_link(&tz->device.kobj, dev->name);
|
sysfs_remove_link(&tz->device.kobj, dev->name);
|
||||||
release_idr:
|
release_ida:
|
||||||
release_idr(&tz->idr, &tz->lock, dev->id);
|
ida_simple_remove(&tz->ida, dev->id);
|
||||||
free_mem:
|
free_mem:
|
||||||
kfree(dev);
|
kfree(dev);
|
||||||
return result;
|
return result;
|
||||||
|
@ -785,7 +762,7 @@ unbind:
|
||||||
device_remove_file(&tz->device, &pos->weight_attr);
|
device_remove_file(&tz->device, &pos->weight_attr);
|
||||||
device_remove_file(&tz->device, &pos->attr);
|
device_remove_file(&tz->device, &pos->attr);
|
||||||
sysfs_remove_link(&tz->device.kobj, pos->name);
|
sysfs_remove_link(&tz->device.kobj, pos->name);
|
||||||
release_idr(&tz->idr, &tz->lock, pos->id);
|
ida_simple_remove(&tz->ida, pos->id);
|
||||||
kfree(pos);
|
kfree(pos);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -920,12 +897,13 @@ __thermal_cooling_device_register(struct device_node *np,
|
||||||
if (!cdev)
|
if (!cdev)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
|
result = ida_simple_get(&thermal_cdev_ida, 0, 0, GFP_KERNEL);
|
||||||
if (result) {
|
if (result < 0) {
|
||||||
kfree(cdev);
|
kfree(cdev);
|
||||||
return ERR_PTR(result);
|
return ERR_PTR(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cdev->id = result;
|
||||||
strlcpy(cdev->type, type ? : "", sizeof(cdev->type));
|
strlcpy(cdev->type, type ? : "", sizeof(cdev->type));
|
||||||
mutex_init(&cdev->lock);
|
mutex_init(&cdev->lock);
|
||||||
INIT_LIST_HEAD(&cdev->thermal_instances);
|
INIT_LIST_HEAD(&cdev->thermal_instances);
|
||||||
|
@ -938,7 +916,7 @@ __thermal_cooling_device_register(struct device_node *np,
|
||||||
dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
|
dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
|
||||||
result = device_register(&cdev->device);
|
result = device_register(&cdev->device);
|
||||||
if (result) {
|
if (result) {
|
||||||
release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
|
ida_simple_remove(&thermal_cdev_ida, cdev->id);
|
||||||
kfree(cdev);
|
kfree(cdev);
|
||||||
return ERR_PTR(result);
|
return ERR_PTR(result);
|
||||||
}
|
}
|
||||||
|
@ -1065,7 +1043,7 @@ void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
|
||||||
|
|
||||||
mutex_unlock(&thermal_list_lock);
|
mutex_unlock(&thermal_list_lock);
|
||||||
|
|
||||||
release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
|
ida_simple_remove(&thermal_cdev_ida, cdev->id);
|
||||||
device_unregister(&cdev->device);
|
device_unregister(&cdev->device);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
|
EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
|
||||||
|
@ -1167,14 +1145,15 @@ thermal_zone_device_register(const char *type, int trips, int mask,
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
INIT_LIST_HEAD(&tz->thermal_instances);
|
INIT_LIST_HEAD(&tz->thermal_instances);
|
||||||
idr_init(&tz->idr);
|
ida_init(&tz->ida);
|
||||||
mutex_init(&tz->lock);
|
mutex_init(&tz->lock);
|
||||||
result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
|
result = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL);
|
||||||
if (result) {
|
if (result < 0) {
|
||||||
kfree(tz);
|
kfree(tz);
|
||||||
return ERR_PTR(result);
|
return ERR_PTR(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tz->id = result;
|
||||||
strlcpy(tz->type, type, sizeof(tz->type));
|
strlcpy(tz->type, type, sizeof(tz->type));
|
||||||
tz->ops = ops;
|
tz->ops = ops;
|
||||||
tz->tzp = tzp;
|
tz->tzp = tzp;
|
||||||
|
@ -1196,7 +1175,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
|
||||||
dev_set_name(&tz->device, "thermal_zone%d", tz->id);
|
dev_set_name(&tz->device, "thermal_zone%d", tz->id);
|
||||||
result = device_register(&tz->device);
|
result = device_register(&tz->device);
|
||||||
if (result) {
|
if (result) {
|
||||||
release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
|
ida_simple_remove(&thermal_tz_ida, tz->id);
|
||||||
kfree(tz);
|
kfree(tz);
|
||||||
return ERR_PTR(result);
|
return ERR_PTR(result);
|
||||||
}
|
}
|
||||||
|
@ -1250,7 +1229,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
|
||||||
return tz;
|
return tz;
|
||||||
|
|
||||||
unregister:
|
unregister:
|
||||||
release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
|
ida_simple_remove(&thermal_tz_ida, tz->id);
|
||||||
device_unregister(&tz->device);
|
device_unregister(&tz->device);
|
||||||
return ERR_PTR(result);
|
return ERR_PTR(result);
|
||||||
}
|
}
|
||||||
|
@ -1312,8 +1291,8 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
|
||||||
thermal_set_governor(tz, NULL);
|
thermal_set_governor(tz, NULL);
|
||||||
|
|
||||||
thermal_remove_hwmon_sysfs(tz);
|
thermal_remove_hwmon_sysfs(tz);
|
||||||
release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
|
ida_simple_remove(&thermal_tz_ida, tz->id);
|
||||||
idr_destroy(&tz->idr);
|
ida_destroy(&tz->ida);
|
||||||
mutex_destroy(&tz->lock);
|
mutex_destroy(&tz->lock);
|
||||||
device_unregister(&tz->device);
|
device_unregister(&tz->device);
|
||||||
kfree(tz->device.groups);
|
kfree(tz->device.groups);
|
||||||
|
@ -1514,9 +1493,8 @@ unregister_class:
|
||||||
unregister_governors:
|
unregister_governors:
|
||||||
thermal_unregister_governors();
|
thermal_unregister_governors();
|
||||||
error:
|
error:
|
||||||
idr_destroy(&thermal_tz_idr);
|
ida_destroy(&thermal_tz_ida);
|
||||||
idr_destroy(&thermal_cdev_idr);
|
ida_destroy(&thermal_cdev_ida);
|
||||||
mutex_destroy(&thermal_idr_lock);
|
|
||||||
mutex_destroy(&thermal_list_lock);
|
mutex_destroy(&thermal_list_lock);
|
||||||
mutex_destroy(&thermal_governor_lock);
|
mutex_destroy(&thermal_governor_lock);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1529,9 +1507,8 @@ static void __exit thermal_exit(void)
|
||||||
genetlink_exit();
|
genetlink_exit();
|
||||||
class_unregister(&thermal_class);
|
class_unregister(&thermal_class);
|
||||||
thermal_unregister_governors();
|
thermal_unregister_governors();
|
||||||
idr_destroy(&thermal_tz_idr);
|
ida_destroy(&thermal_tz_ida);
|
||||||
idr_destroy(&thermal_cdev_idr);
|
ida_destroy(&thermal_cdev_ida);
|
||||||
mutex_destroy(&thermal_idr_lock);
|
|
||||||
mutex_destroy(&thermal_list_lock);
|
mutex_destroy(&thermal_list_lock);
|
||||||
mutex_destroy(&thermal_governor_lock);
|
mutex_destroy(&thermal_governor_lock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ struct thermal_attr {
|
||||||
* @governor: pointer to the governor for this thermal zone
|
* @governor: pointer to the governor for this thermal zone
|
||||||
* @governor_data: private pointer for governor data
|
* @governor_data: private pointer for governor data
|
||||||
* @thermal_instances: list of &struct thermal_instance of this thermal zone
|
* @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
|
* devices
|
||||||
* @lock: lock to protect thermal_instances list
|
* @lock: lock to protect thermal_instances list
|
||||||
* @node: node in thermal_tz_list (in thermal_core.c)
|
* @node: node in thermal_tz_list (in thermal_core.c)
|
||||||
|
@ -227,7 +227,7 @@ struct thermal_zone_device {
|
||||||
struct thermal_governor *governor;
|
struct thermal_governor *governor;
|
||||||
void *governor_data;
|
void *governor_data;
|
||||||
struct list_head thermal_instances;
|
struct list_head thermal_instances;
|
||||||
struct idr idr;
|
struct ida ida;
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
struct list_head node;
|
struct list_head node;
|
||||||
struct delayed_work poll_queue;
|
struct delayed_work poll_queue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue