From 98525f6faf75f24856895d6925b649b14dfd25b0 Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Fri, 7 May 2004 17:09:07 +0100 Subject: [PATCH] [CPUFREQ] Export cpufreq_get() to userspace. As it involves calls to hardware which might take some time, only let the super-user read out this value. --- drivers/cpufreq/cpufreq.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index bf1005a080917..32d789ea7a265 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -189,6 +189,18 @@ static ssize_t store_##file_name \ store_one(scaling_min_freq,min); store_one(scaling_max_freq,max); +/** + * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware + */ +static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy, char *buf) +{ + unsigned int cur_freq = cpufreq_get(policy->cpu); + if (!cur_freq) + return sprintf(buf, ""); + return sprintf(buf, "%u\n", cur_freq); +} + + /** * show_scaling_governor - show the current policy for the specified CPU */ @@ -269,6 +281,12 @@ struct freq_attr _name = { \ .show = show_##_name, \ } +#define define_one_ro0400(_name) \ +struct freq_attr _name = { \ + .attr = { .name = __stringify(_name), .mode = 0400 }, \ + .show = show_##_name, \ +} + #define define_one_rw(_name) \ struct freq_attr _name = { \ .attr = { .name = __stringify(_name), .mode = 0644 }, \ @@ -276,6 +294,7 @@ struct freq_attr _name = { \ .store = store_##_name, \ } +define_one_ro0400(cpuinfo_cur_freq); define_one_ro(cpuinfo_min_freq); define_one_ro(cpuinfo_max_freq); define_one_ro(scaling_available_governors); @@ -396,6 +415,8 @@ static int cpufreq_add_dev (struct sys_device * sys_dev) sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); drv_attr++; } + if (cpufreq_driver->get) + sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); if (cpufreq_driver->target) sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); -- 2.53.0