From: Matthew Wilcox <mawilcox@linuxonhyperv.com>
To: Zhang Rui <rui.zhang@intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>, linux-pm@vger.kernel.org
Subject: [PATCH 4/4] thermal: convert devfreq_cooling to use an IDA
Date: Wed, 21 Dec 2016 09:47:06 -0800 [thread overview]
Message-ID: <1482342426-30520-5-git-send-email-mawilcox@linuxonhyperv.com> (raw)
In-Reply-To: <1482342426-30520-1-git-send-email-mawilcox@linuxonhyperv.com>
From: Matthew Wilcox <mawilcox@microsoft.com>
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: Matthew Wilcox <mawilcox@microsoft.com>
---
drivers/thermal/devfreq_cooling.c | 53 +++++++--------------------------------
1 file changed, 9 insertions(+), 44 deletions(-)
diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c
index 5a737fd5f1aa..a667ba779a43 100644
--- a/drivers/thermal/devfreq_cooling.c
+++ b/drivers/thermal/devfreq_cooling.c
@@ -21,14 +21,14 @@
#include <linux/devfreq.h>
#include <linux/devfreq_cooling.h>
#include <linux/export.h>
+#include <linux/idr.h>
#include <linux/slab.h>
#include <linux/pm_opp.h>
#include <linux/thermal.h>
#include <trace/events/thermal.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 +58,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,9 +460,10 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,
if (err)
goto free_dfc;
- err = get_idr(&devfreq_idr, &dfc->id);
- if (err)
+ err = ida_simple_get(&devfreq_ida, 0, 0, GFP_KERNEL);
+ if (err < 0)
goto free_tables;
+ dfc->id = err;
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,
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:
+ ida_simple_remove(&devfreq_ida, 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);
+ ida_simple_remove(&devfreq_ida, dfc->id);
kfree(dfc->power_table);
kfree(dfc->freq_table);
--
2.11.0
next prev parent reply other threads:[~2016-12-21 15:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-21 17:47 [PATCH 0/4] Convert thermal subsystem to the IDA allocator Matthew Wilcox
2016-12-21 17:47 ` [PATCH 1/4] thermal core: convert ID allocation to IDA Matthew Wilcox
2016-12-21 17:47 ` [PATCH 2/4] thermal: convert clock cooling to use an IDA Matthew Wilcox
2016-12-21 17:47 ` [PATCH 3/4] thermal: convert cpu_cooling " Matthew Wilcox
2016-12-21 17:47 ` Matthew Wilcox [this message]
2017-01-04 4:49 ` [PATCH 0/4] Convert thermal subsystem to the IDA allocator Zhang Rui
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=1482342426-30520-5-git-send-email-mawilcox@linuxonhyperv.com \
--to=mawilcox@linuxonhyperv.com \
--cc=linux-pm@vger.kernel.org \
--cc=mawilcox@microsoft.com \
--cc=rui.zhang@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).