powernv: cpufreq support for IBM POWERNV platform
Subsystems (2)
cover powernv: cpufreq support for IBM POWERNV platform
Hi,
The following patch series implements the platform driver to support dynamic CPU frequency scaling on IBM POWERNV platforms.
This patch series is based on Linux kernel 3.14-rc2 and tested on OPAL v3 based IBM POWERNV platform and IBM POWER8 processor.
--Vaidy
---
Srivatsa S. Bhat (1):
powernv, cpufreq: Add per-core locking to serialize frequency transitions
Vaidyanathan Srinivasan (1):
powernv: cpufreq driver for powernv platform
arch/powerpc/include/asm/reg.h | 4 + drivers/cpufreq/Kconfig.powerpc | 9 + drivers/cpufreq/Makefile | 1 drivers/cpufreq/powernv-cpufreq.c | 286 +++++++++++++++++++++++++++++++++++++ 4 files changed, 300 insertions(+) create mode 100644 drivers/cpufreq/powernv-cpufreq.c
PATCH 1/2 powernv: cpufreq driver for powernv platform
Backend driver to dynamically set voltage and frequency on IBM POWER non-virtualized platforms. Power management SPRs are used to set the required PState.
This driver works in conjunction with cpufreq governors like 'ondemand' to provide a demand based frequency and voltage setting on IBM POWER non-virtualized platforms.
PState table is obtained from OPAL v3 firmware through device tree.
powernv_cpufreq back-end driver would parse the relevant device-tree nodes and initialise the cpufreq subsystem on powernv platform.
--- arch/powerpc/include/asm/reg.h | 4 + drivers/cpufreq/Kconfig.powerpc | 9 + drivers/cpufreq/Makefile | 1 drivers/cpufreq/powernv-cpufreq.c | 275 +++++++++++++++++++++++++++++++++++++ 4 files changed, 289 insertions(+) create mode 100644 drivers/cpufreq/powernv-cpufreq.c
arch/powerpc/include/asm/reg.h +4 -0
@@ -271,6 +271,10 @@#define SPRN_HSRR1 0x13B/* Hypervisor Save/Restore 1 */ #define SPRN_IC 0x350/* Virtual Instruction Count */ #define SPRN_VTB 0x351/* Virtual Time Base */ +#define SPRN_PMICR 0x354/* Power Management Idle Control Reg */ +#define SPRN_PMSR 0x355/* Power Management Status Reg */ +#define SPRN_PMCR 0x374/* Power Management Control Register */ +/* HFSCR and FSCR bit numbers are the same */ #define FSCR_TAR_LG 8/* Enable Target Address Register */ #define FSCR_EBB_LG 7/* Enable Event Based Branching */
drivers/cpufreq/Kconfig.powerpc +9 -0
@@ -54,3 +54,12 @@ config PPC_PASEMI_CPUFREQ help This adds the support for frequency switching on PA Semi PWRficient processors. + +config POWERNV_CPUFREQ + tristate "CPU frequency scaling for IBM POWERNV platform" + depends on PPC_POWERNV + select CPU_FREQ_TABLE + default y + help + This adds support for CPU frequency switching on IBM POWERNV + platform
drivers/cpufreq/Makefile +1 -0
@@ -86,6 +86,7 @@ obj-$(CONFIG_PPC_CORENET_CPUFREQ) += ppc-corenet-cpufreq.o obj-$(CONFIG_CPU_FREQ_PMAC) += pmac32-cpufreq.o obj-$(CONFIG_CPU_FREQ_PMAC64) += pmac64-cpufreq.o obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += pasemi-cpufreq.o +obj-$(CONFIG_POWERNV_CPUFREQ) += powernv-cpufreq.o ################################################################################## # Other platform drivers
drivers/cpufreq/powernv-cpufreq.c new file +275 -0
275 lines not on this page · raw message
Re: [PATCH v1 1/2] powernv: cpufreq driver for powernv platform
Hi Vaidy,
Quoted 18 lines · Vaidyanathan Srinivasan
Backend driver to dynamically set voltage and frequency on IBM POWER non-virtualized platforms. Power management SPRs are used to set the required PState.
This driver works in conjunction with cpufreq governors like 'ondemand' to provide a demand based frequency and voltage setting on IBM POWER non-virtualized platforms.
PState table is obtained from OPAL v3 firmware through device tree.
powernv_cpufreqback-end driver would parse the relevant device-tree nodes and initialise the cpufreq subsystem on powernv platform.Signed-off-by Vaidyanathan Srinivasan <[email protected]>Signed-off-by Srivatsa S. Bhat <[email protected]>Signed-off-by Anton Blanchard <[email protected]>---
<snip>
drivers/cpufreq/powernv-cpufreq.c line 185
Quoted 11 lines
drivers/cpufreq/powernv-cpufreq.c new file +11
-0+static int powernv_cpufreq_cpu_init (struct cpufreq_policy *policy) +{ +int base, 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); +#endif + policy->cpuinfo.transition_latency =25000 ;
Is it ok to hard code this field? How about getting this also from the device tree?
drivers/cpufreq/powernv-cpufreq.c line 189
Quoted 4 lines
drivers/cpufreq/powernv-cpufreq.c new file +4
-0+ +/* Print frequency table */ +for (i =0 ; powernv_freqs[i].frequency !=CPUFREQ_TABLE_END ; i++) +pr_debug ("%d: %d\n" , i, powernv_freqs[i].frequency);
The frequency table as a result will be printed on every cpu when cpufreq gets initialized. Considering this information will not vary across CPUs, can we print this during powernv_cpufreq_init() after parsing the device tree for the pstates?
Thanks
Regards
Preeti U Murthy
PATCH 2/2 powernv, cpufreq: Add per-core locking to serialize frequency transitions
In reply to Vaidyanathan SrinivasanFrom: Srivatsa S. Bhat <[email protected]>
On POWER systems, the CPU frequency is controlled at a core-level and hence we need to serialize so that only one of the threads in the core switches the core's frequency at a time.
Using a global mutex lock would needlessly serialize _all_ frequency transitions in the system (across all cores). So introduce per-core locking to enable finer-grained synchronization and thereby enhance the speed and responsiveness of the cpufreq driver to varying workload demands.
The design of per-core locking is very simple and straight-forward: we first define a Per-CPU lock and use the ones that belongs to the first thread sibling of the core.
cpu_first_thread_sibling() macro is used to find the *common* lock for all thread siblings belonging to a core.
--- drivers/cpufreq/powernv-cpufreq.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/cpufreq/powernv-cpufreq.c +16 -5
@@ -24,8 +24,15 @@#include <linux/of.h> #include <asm/cputhreads.h> -/* FIXME: Make this per-core */ -static DEFINE_MUTEX (freq_switch_mutex); +/* Per-Core locking for frequency transitions */ +static DEFINE_PER_CPU(struct mutex, freq_switch_lock); + +#define lock_core_freq (cpu) \ + mutex_lock(&per_cpu(freq_switch_lock,\ + cpu_first_thread_sibling(cpu))); +#define unlock_core_freq (cpu) \ + mutex_unlock(&per_cpu(freq_switch_lock,\ + cpu_first_thread_sibling(cpu)));#define POWERNV_MAX_PSTATES 256
@@ -219,7 +226,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy, freqs.new = powernv_freqs[new_index].frequency; freqs.cpu = policy->cpu; -mutex_lock (&freq_switch_mutex); +lock_core_freq (policy->cpu);cpufreq_notify_transition (policy, &freqs,CPUFREQ_PRECHANGE ); pr_debug("setting frequency for cpu %d to %d kHz index %d pstate %d",
@@ -231,7 +238,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy, rc =powernv_set_freq (policy->cpus, new_index);cpufreq_notify_transition (policy, &freqs,CPUFREQ_POSTCHANGE ); -mutex_unlock (&freq_switch_mutex); +unlock_core_freq (policy->cpu);return rc; }
@@ -248,7 +255,7 @@ static struct cpufreq_driver powernv_cpufreq_driver = {static int __init powernv_cpufreq_init (void ) { -int rc =0 ; +int cpu, rc =0 ;/* Discover pstates from device tree and init */
@@ -258,6 +265,10 @@ static int __init powernv_cpufreq_init(void)pr_info ("powernv-cpufreq disabled\n" );return rc; } +/* Init per-core mutex */ +for_each_possible_cpu (cpu) { +mutex_init (&per_cpu (freq_switch_lock, cpu)); + } rc =cpufreq_register_driver (&powernv_cpufreq_driver);return rc;
Re: [PATCH v1 2/2] powernv, cpufreq: Add per-core locking to serialize frequency transitions
Hi Vaidy,
Quoted 75 lines · Vaidyanathan Srinivasan
From: Srivatsa S. Bhat <[email protected]>
On POWER systems, the CPU frequency is controlled at a core-level and hence we need to serialize so that only one of the threads in the core switches the core's frequency at a time.
Using a global mutex lock would needlessly serialize _all_ frequency transitions in the system (across all cores). So introduce per-core locking to enable finer-grained synchronization and thereby enhance the speed and responsiveness of the cpufreq driver to varying workload demands.
The design of per-core locking is very simple and straight-forward: we first define a Per-CPU lock and use the ones that belongs to the first thread sibling of the core.
cpu_first_thread_sibling()macro is used to find the *common* lock for all thread siblings belonging to a core.Signed-off-by Srivatsa S. Bhat <[email protected]>Signed-off-by Vaidyanathan Srinivasan <[email protected]>--- drivers/cpufreq/powernv-cpufreq.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/cpufreq/powernv-cpufreq.c +12
-5@@ -24,8 +24,15 @@#include <linux/of.h> #include <asm/cputhreads.h> -/* FIXME: Make this per-core */ -static DEFINE_MUTEX (freq_switch_mutex); +/* Per-Core locking for frequency transitions */ +static DEFINE_PER_CPU(struct mutex, freq_switch_lock); + +#define lock_core_freq (cpu) \ + mutex_lock(&per_cpu(freq_switch_lock,\ + cpu_first_thread_sibling(cpu))); +#define unlock_core_freq (cpu) \ + mutex_unlock(&per_cpu(freq_switch_lock,\ + cpu_first_thread_sibling(cpu)));#define POWERNV_MAX_PSTATES 256@@ -219,7 +226,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy, freqs.new = powernv_freqs[new_index].frequency; freqs.cpu = policy->cpu; -mutex_lock (&freq_switch_mutex); +lock_core_freq (policy->cpu);cpufreq_notify_transition (policy, &freqs,CPUFREQ_PRECHANGE ); pr_debug("setting frequency for cpu %d to %d kHz index %d pstate %d",@@ -231,7 +238,7 @@ static int powernv_cpufreq_target(struct cpufreq_policy *policy, rc =powernv_set_freq (policy->cpus, new_index);cpufreq_notify_transition (policy, &freqs,CPUFREQ_POSTCHANGE ); -mutex_unlock (&freq_switch_mutex); +unlock_core_freq (policy->cpu);return rc; }@@ -248,7 +255,7 @@ static struct cpufreq_driver powernv_cpufreq_driver = {static int __init powernv_cpufreq_init (void ) { -int rc =0 ; +int cpu, rc =0 ;/* Discover pstates from device tree and init */
drivers/cpufreq/powernv-cpufreq.c static int __init powernv_cpufreq_init(void) · line 274
Quoted 10 lines
drivers/cpufreq/powernv-cpufreq.c +4
-0@@ -258,6 +265,10 @@ static int __init powernv_cpufreq_init(void)pr_info ("powernv-cpufreq disabled\n" );return rc; } +/* Init per-core mutex */ +for_each_possible_cpu (cpu) { +mutex_init (&per_cpu (freq_switch_lock, cpu)); + } rc =cpufreq_register_driver (&powernv_cpufreq_driver);return rc;
This looks good to me.
Thanks
Regards
Preeti U Murthy
Quoted 6 lines
_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev