powernv:cpufreq: Export nominal and current frequency via sysfs
Subsystems (2)
PATCH 3/4 powernv:cpufreq: Create a powernv_cpu_to_core_mask() helper.
In reply to Gautham R. ShenoyFrom: "Gautham R. Shenoy" <[email protected]>
Move the code that computes the cpumask corresponding to the thread-siblings of a cpu to a new method named powernv_cpu_to_core_mask() so that it can be used by other places in the code.
--- drivers/cpufreq/powernv-cpufreq.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +19 -5
@@ -166,6 +166,23 @@ static struct freq_attr *powernv_cpu_freq_attr[] = {/* Helper routines */ +/** +* Sets the bits corresponding to the thread-siblings of cpu in its core +* in 'cpus'. +*/ +static void powernv_cpu_to_core_mask (unsigned int cpu,cpumask_var_t cpus) +{ +int base, i; + + base =cpu_first_thread_sibling (cpu); + +for (i =0 ; i < threads_per_core; i++) { +cpumask_set_cpu (base + i, cpus); + } + +return ; +} +/* Access helpers to power mgt SPR */ static inline unsigned long get_pmspr (unsigned long sprn)
@@ -231,13 +248,10 @@ static int powernv_set_freq(cpumask_var_t cpus, unsigned int new_index)static int powernv_cpufreq_cpu_init (struct cpufreq_policy *policy) { -int base, i; +int i;#ifdef CONFIG_SMP - base =cpu_first_thread_sibling (policy->cpu); - -for (i =0 ; i < threads_per_core; i++) -cpumask_set_cpu (base + i, policy->cpus); +powernv_cpu_to_core_mask (policy->cpu, policy->cpus);#endif policy->cpuinfo.transition_latency =25000 ;
Signature · 1 line
1.8.3.1
cover powernv:cpufreq: Export nominal and current frequency via sysfs
From: "Gautham R. Shenoy" <[email protected]>
Hi,
On IBM POWERNV platforms[1], presently we do not report the current operating frequency of the processor through the sysfs interface "cpuinfo_cur_freq" since the cpu frequency driver[1] has not implemented the ->get(unsigned int cpu) method. Fix this by implementing the ->get(unsigned int cpu) method which will report the frequency corresponding to the pstate_id on PMSR on "cpu".
Also, export the nominal frequency of the processor through the sysfs interface "cpuinfo_nominal_freq" by defining it as a driver attribute.
The patch series depends on the cpu-frequency driver patch-series[1].
[1] http://comments.gmane.org/gmane.linux.ports.ppc.embedded/67905
Thanks and Regards
gautham.
Summary:
==========================
Gautham R. Shenoy (4):
powernv:cpufreq: Create pstate_id_to_freq() helper powernv:cpufreq: Export nominal frequency via sysfs. powernv:cpufreq: Create a powernv_cpu_to_core_mask() helper. powernv:cpufreq: Implement the driver->get() method
drivers/cpufreq/powernv-cpufreq.c | 115 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/4 powernv:cpufreq: Create pstate_id_to_freq() helper
From: "Gautham R. Shenoy" <[email protected]>
Create a helper routine that can return the cpu-frequency for the corresponding pstate_id.
Also, cache the values of the pstate_max, pstate_min and pstate_nominal and nr_pstates in a static structure so that they can be reused in the future to perform any validations.
--- drivers/cpufreq/powernv-cpufreq.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/cpufreq/powernv-cpufreq.c +28 -0
@@ -37,6 +37,15 @@ static DEFINE_PER_CPU(struct mutex, freq_switch_lock);#define POWERNV_MAX_PSTATES 256static struct cpufreq_frequency_table powernv_freqs[POWERNV_MAX_PSTATES +1 ]; +struct powernv_pstate_info { +int pstate_min_id; +int pstate_max_id; +int pstate_nominal_id; +int nr_pstates; +}; + +static struct powernv_pstate_info powernv_pstate_info; +/* * Initialize the freq table based on data obtained
@@ -106,9 +115,28 @@ static int init_powernv_pstates(void) powernv_freqs[i].driver_data =0 ; powernv_freqs[i].frequency =CPUFREQ_TABLE_END ; + powernv_pstate_info.pstate_min_id = pstate_min; + powernv_pstate_info.pstate_max_id = pstate_max; + powernv_pstate_info.pstate_nominal_id = pstate_nominal; + powernv_pstate_info.nr_pstates = nr_pstates; +return 0 ; } +/** +* Returns the cpu frequency corresponding to the pstate_id. +*/ +static unsigned int pstate_id_to_freq (int pstate_id) +{ +int i; + + i = powernv_pstate_info.pstate_max_id - pstate_id; + +BUG_ON (i >= powernv_pstate_info.nr_pstates || i <0 ); +WARN_ON (powernv_freqs[i].driver_data != pstate_id); +return powernv_freqs[i].frequency; +} +static struct freq_attr *powernv_cpu_freq_attr[] = { &cpufreq_freq_attr_scaling_available_freqs,NULL ,
Signature · 1 line
1.8.3.1
PATCH 2/4 powernv:cpufreq: Export nominal frequency via sysfs.
In reply to Gautham R. ShenoyFrom: "Gautham R. Shenoy" <[email protected]>
Create a driver attribute named cpuinfo_nominal_frequency which creates a sysfs read-only file named cpuinfo_nominal_frequency. Export the frequency corresponding to the nominal_pstate through this interface.
--- drivers/cpufreq/powernv-cpufreq.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/cpufreq/powernv-cpufreq.c +22 -0
@@ -137,8 +137,30 @@ static unsigned int pstate_id_to_freq(int pstate_id)return powernv_freqs[i].frequency; } +/** +* show_cpuinfo_nominal_freq - Show the nominal CPU frequency as indicated by +* the firmware +*/ +static ssize_t show_cpuinfo_nominal_freq (struct cpufreq_policy *policy, +char *buf) +{ +int nominal_freq; + nominal_freq =pstate_id_to_freq (powernv_pstate_info.pstate_nominal_id); +return sprintf (buf,"%u\n" , nominal_freq); +} + + +struct freq_attr cpufreq_freq_attr_cpuinfo_nominal_freq = { + .attr = { .name ="cpuinfo_nominal_freq" , + .mode =0444 , + }, + .show = show_cpuinfo_nominal_freq, +}; + +static struct freq_attr *powernv_cpu_freq_attr[] = { &cpufreq_freq_attr_scaling_available_freqs, + &cpufreq_freq_attr_cpuinfo_nominal_freq,NULL , };
Signature · 1 line
1.8.3.1
PATCH 4/4 powernv:cpufreq: Implement the driver->get() method
In reply to Gautham R. ShenoyFrom: "Gautham R. Shenoy" <[email protected]>
The current frequency of a cpu is reported through the sysfs file cpuinfo_cur_freq. This requires the driver to implement a "->get(unsigned int cpu)" method which will return the current operating frequency.
Implement a function named powernv_cpufreq_get() which corresponds to the required ->get() method.
--- drivers/cpufreq/powernv-cpufreq.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/cpufreq/powernv-cpufreq.c +41 -0
@@ -218,6 +218,46 @@ static inline void set_pmspr(unsigned long sprn, unsigned long val)BUG (); } +/** +* Computes the current frequency on this cpu +* and stores the result in *ret_freq. +*/ +static void powernv_get_cpu_freq (void *ret_freq) +{ +unsigned long pmspr_val; +long pstate_id; +int *cur_freq, freq; + + cur_freq = (int *)ret_freq; + pmspr_val =get_pmspr (SPRN_PMSR ); + pstate_id = pmspr_val; + pstate_id = pstate_id >>56 ; +WARN_ON (pstate_id >0 ); + freq =pstate_id_to_freq (pstate_id); +pr_debug ("cpu %d pmsr %lx pstate_id %ld frequency %d \n" , +smp_processor_id (), pmspr_val, pstate_id, freq); + *cur_freq = freq; +} + +/** +* Returns the cpu frequency as reported by the firmware for 'cpu'. +* This value is reported through the sysfs file cpuinfo_cur_freq. +*/ +unsigned int powernv_cpufreq_get (unsigned int cpu) +{ +int ret_freq; +cpumask_var_t sibling_mask; + +if (!zalloc_cpumask_var (&sibling_mask,GFP_KERNEL )) +return -ENOMEM ; + +powernv_cpu_to_core_mask (cpu, sibling_mask); +smp_call_function_any (sibling_mask, powernv_get_cpu_freq, &ret_freq,1 ); + +free_cpumask_var (sibling_mask); +return ret_freq; +} +static void set_pstate (void *pstate) {unsigned long val;
@@ -310,6 +350,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy,static struct cpufreq_driver powernv_cpufreq_driver = { .verify = powernv_cpufreq_verify, .target = powernv_cpufreq_target, + .get = powernv_cpufreq_get, .init = powernv_cpufreq_cpu_init, .exit = powernv_cpufreq_cpu_exit, .name ="powernv-cpufreq" ,
Signature · 1 line
1.8.3.1