powerpc: add support for new hcall H_BEST_ENERGY
v4 cover powerpc: add support for new hcall H_BEST_ENERGY
Hi Ben,
The following series adds a kernel module for powerpc pseries platforms in order to export platform energy management capabilities.
The module exports data from a new hypervisor call H_BEST_ENERGY.
Some of the comments and suggestions made on the previous iteration of the patch has been incorporated.
Changes in v4:
* Added more documentation
* Added check_for_h_best_energy() to look in ibm,hypertas-functions so that sysfs entries are not created in an unsupported platform
* Added cleaner error checks and correct of_node_put()
* Rebased and tested on 2.6.35-rc5
Changed in v3:
[3] [PATCH v3 0/2] powerpc: add support for new hcall H_BEST_ENERGY
http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-June/083414.html
* Added more documentation in the cleanup patch
* Removed RFC tag, rebased and tested on 2.6.35-rc3
* Ready for inclusion in powerpc/next tree for further testing
Changes in v2:
[2] [RFC PATCH v2 0/2] powerpc: add support for new hcall H_BEST_ENERGY
http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-May/082246.html
* Cleanup cpu/thread/core APIs
* Export APIs to module instead of threads_per_core
* Use of_find_node_by_path() instead of of_find_node_by_name()
* Error checking and whitespace cleanups
First version:
[1] [RFC] powerpc: add support for new hcall H_BEST_ENERGY
http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-March/080796.html
This patch series will apply on 2.6.35-rc5 as well as powerpc/next tree. Please review and include in powerpc/next tree for further testing.
I could incrementally reduce some of the error checks as suggested by Michael Neuling as next steps.
Thanks,
Vaidy
---
Vaidyanathan Srinivasan (2):
powerpc: cleanup APIs for cpu/thread/core mappings
powerpc: add support for new hcall H_BEST_ENERGY
arch/powerpc/include/asm/cputhreads.h | 15 + arch/powerpc/include/asm/hvcall.h | 3 arch/powerpc/kernel/smp.c | 19 + arch/powerpc/mm/mmu_context_nohash.c | 12 - arch/powerpc/platforms/pseries/Kconfig | 10 + arch/powerpc/platforms/pseries/Makefile | 1 arch/powerpc/platforms/pseries/pseries_energy.c | 326 +++++++++++++++++++++++ 7 files changed, 370 insertions(+), 16 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/pseries_energy.c
PATCH v4 1/2 powerpc: cleanup APIs for cpu/thread/core mappings
These APIs take logical cpu number as input
Change cpu_first_thread_in_core() to cpu_leftmost_thread_sibling() Change cpu_last_thread_in_core() to cpu_rightmost_thread_sibling()
These APIs convert core number (index) to logical cpu/thread numbers Add cpu_first_thread_of_core(int core)
Changed cpu_thread_to_core() to cpu_core_of_thread(int cpu)
The goal is to make 'threads_per_core' accessible to the pseries_energy module. Instead of making an API to read threads_per_core, this is a higher level wrapper function to convert from logical cpu number to core number.
The current APIs cpu_first_thread_in_core() and cpu_last_thread_in_core() returns logical CPU number while cpu_thread_to_core() returns core number or index which is not a logical CPU number. The APIs are now clearly named to distinguish 'core number' versus first and last 'logical cpu number' in that core.
The new APIs cpu_{left,right}most_thread_sibling() work on logical cpu numbers. While cpu_first_thread_of_core() and cpu_core_of_thread() work on core index.
Example usage: (4 threads per core system)
cpu_leftmost_thread_sibling(5) = 4cpu_rightmost_thread_sibling(5) = 7cpu_core_of_thread(5) = 1cpu_first_thread_of_core(1) = 4
cpu_core_of_thread() is used in cpu_to_drc_index() in the module and cpu_first_thread_of_core() is used in drc_index_to_cpu() in the module.
Made API changes to few callers. Exported symbols for use in modules.
--- arch/powerpc/include/asm/cputhreads.h | 15 +++++++++------ arch/powerpc/kernel/smp.c | 19 ++++++++++++++++--- arch/powerpc/mm/mmu_context_nohash.c | 12 ++++++------ 3 files changed, 31 insertions(+), 15 deletions(-)
arch/powerpc/include/asm/cputhreads.h +9 -6
@@ -61,22 +61,25 @@ static inline cpumask_t cpu_online_cores_map(void)return cpu_thread_mask_to_cores (cpu_online_map); } -static inline int cpu_thread_to_core (int cpu) -{ -return cpu >> threads_shift; -} +#ifdef CONFIG_SMP +int cpu_core_of_thread (int cpu); +int cpu_first_thread_of_core (int core); +#else +static inline int cpu_core_of_thread (int cpu) {return cpu; } +static inline int cpu_first_thread_of_core (int core) {return core; } +#endif static inline int cpu_thread_in_core (int cpu) {return cpu & (threads_per_core -1 ); } -static inline int cpu_first_thread_in_core (int cpu) +static inline int cpu_leftmost_thread_sibling (int cpu) {return cpu & ~(threads_per_core -1 ); } -static inline int cpu_last_thread_in_core (int cpu) +static inline int cpu_rightmost_thread_sibling (int cpu) {return cpu | (threads_per_core -1 ); }
arch/powerpc/kernel/smp.c +16 -3
@@ -468,7 +468,20 @@ out:return id; } -/* Must be called when no change can occur to cpu_present_mask, +/* Helper routines for cpu to core mapping */ +int cpu_core_of_thread (int cpu) +{ +return cpu >> threads_shift; +} +EXPORT_SYMBOL_GPL (cpu_core_of_thread); + +int cpu_first_thread_of_core (int core) +{ +return core << threads_shift; +} +EXPORT_SYMBOL_GPL (cpu_first_thread_of_core); + +/* Must be called when no change can occur to cpu_present_map, * i.e. during cpu online or offline. */ static struct device_node *cpu_to_l2cache (int cpu)
@@ -527,7 +540,7 @@ int __devinit start_secondary(void *unused)notify_cpu_starting (cpu);set_cpu_online (cpu, true);/* Update sibling maps */ - base =cpu_first_thread_in_core (cpu); + base =cpu_leftmost_thread_sibling (cpu);for (i =0 ; i < threads_per_core; i++) {if (cpu_is_offline (base + i))continue ;
@@ -606,7 +619,7 @@ int __cpu_disable(void)return err;/* Update sibling maps */ - base =cpu_first_thread_in_core (cpu); + base =cpu_leftmost_thread_sibling (cpu);for (i =0 ; i < threads_per_core; i++) {cpumask_clear_cpu (cpu,cpu_sibling_mask (base + i));cpumask_clear_cpu (base + i,cpu_sibling_mask (cpu));
arch/powerpc/mm/mmu_context_nohash.c +6 -6
@@ -111,8 +111,8 @@ static unsigned int steal_context_smp(unsigned int id)* a core map instead but this will do for now. */ for_each_cpu (cpu,mm_cpumask (mm)) { -for (i =cpu_first_thread_in_core (cpu); - i <=cpu_last_thread_in_core (cpu); i++) +for (i =cpu_leftmost_thread_sibling (cpu); + i <=cpu_rightmost_thread_sibling (cpu); i++)__set_bit (id, stale_map[i]); cpu = i -1 ; }
@@ -264,14 +264,14 @@ void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next)*/ if (test_bit (id, stale_map[cpu])) {pr_hardcont (" | stale flush %d [%d..%d]" , - id,cpu_first_thread_in_core (cpu), -cpu_last_thread_in_core (cpu)); + id,cpu_leftmost_thread_sibling (cpu), +cpu_rightmost_thread_sibling (cpu));local_flush_tlb_mm (next);/* XXX This clear should ultimately be part of local_flush_tlb_mm */ -for (i =cpu_first_thread_in_core (cpu); - i <=cpu_last_thread_in_core (cpu); i++) { +for (i =cpu_leftmost_thread_sibling (cpu); + i <=cpu_rightmost_thread_sibling (cpu); i++) {__clear_bit (id, stale_map[i]); } }
Re: [PATCH v4 1/2] powerpc: cleanup APIs for cpu/thread/core mappings
Quoted 3 lines · Vaidyanathan Srinivasan
These APIs take logical cpu number as input
Changecpu_first_thread_in_core()tocpu_leftmost_thread_sibling()Changecpu_last_thread_in_core()tocpu_rightmost_thread_sibling()
I'm still not happy here.
I don't find leftmost/rightmost to be a "progress" from the previous naming. If you really want to change to avoid in_core() at the end, then call them first_thread_sibling() and last_thread_sibling().
Then you change:
arch/powerpc/include/asm/cputhreads.h static inline cpumask_t cpu_online_cores_map(void) · line 67
Quoted 4 lines
arch/powerpc/include/asm/cputhreads.h +0
-4-static inline int cpu_thread_to_core (int cpu) -{ -return cpu >> threads_shift; -}
.../... to:
arch/powerpc/kernel/smp.c out: · line 476
Quoted 7 lines
arch/powerpc/kernel/smp.c +6
-1-/* Must be called when no change can occur to cpu_present_mask, +/* Helper routines for cpu to core mapping */ +int cpu_core_of_thread (int cpu) +{ +return cpu >> threads_shift; +} +EXPORT_SYMBOL_GPL (cpu_core_of_thread);
Any reason you are making it out of line other than gratuituous bloat ? :-)
arch/powerpc/kernel/smp.c out: · line 482
Quoted 5 lines
arch/powerpc/kernel/smp.c +5
-0+int cpu_first_thread_of_core (int core) +{ +return core << threads_shift; +} +EXPORT_SYMBOL_GPL (cpu_first_thread_of_core);
Same.
Ben.
Quoted 56 lines
arch/powerpc/kernel/smp.c +3
-2+/* Must be called when no change can occur to cpu_present_map, * i.e. during cpu online or offline. */ static struct device_node *cpu_to_l2cache (int cpu)@@ -527,7 +540,7 @@ int __devinit start_secondary(void *unused)notify_cpu_starting (cpu);set_cpu_online (cpu, true);/* Update sibling maps */ - base =cpu_first_thread_in_core (cpu); + base =cpu_leftmost_thread_sibling (cpu);for (i =0 ; i < threads_per_core; i++) {if (cpu_is_offline (base + i))continue ;@@ -606,7 +619,7 @@ int __cpu_disable(void)return err;/* Update sibling maps */ - base =cpu_first_thread_in_core (cpu); + base =cpu_leftmost_thread_sibling (cpu);for (i =0 ; i < threads_per_core; i++) {cpumask_clear_cpu (cpu,cpu_sibling_mask (base + i));cpumask_clear_cpu (base + i,cpu_sibling_mask (cpu));arch/powerpc/mm/mmu_context_nohash.c +6
-6@@ -111,8 +111,8 @@ static unsigned int steal_context_smp(unsigned int id)* a core map instead but this will do for now. */ for_each_cpu (cpu,mm_cpumask (mm)) { -for (i =cpu_first_thread_in_core (cpu); - i <=cpu_last_thread_in_core (cpu); i++) +for (i =cpu_leftmost_thread_sibling (cpu); + i <=cpu_rightmost_thread_sibling (cpu); i++)__set_bit (id, stale_map[i]); cpu = i -1 ; }@@ -264,14 +264,14 @@ void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next)*/ if (test_bit (id, stale_map[cpu])) {pr_hardcont (" | stale flush %d [%d..%d]" , - id,cpu_first_thread_in_core (cpu), -cpu_last_thread_in_core (cpu)); + id,cpu_leftmost_thread_sibling (cpu), +cpu_rightmost_thread_sibling (cpu));local_flush_tlb_mm (next);/* XXX This clear should ultimately be part of local_flush_tlb_mm */ -for (i =cpu_first_thread_in_core (cpu); - i <=cpu_last_thread_in_core (cpu); i++) { +for (i =cpu_leftmost_thread_sibling (cpu); + i <=cpu_rightmost_thread_sibling (cpu); i++) {__clear_bit (id, stale_map[i]); } }
Re: [PATCH v4 1/2] powerpc: cleanup APIs for cpu/thread/core mappings
Quoted 10 lines · Benjamin Herrenschmidt
Quoted 3 lines · Vaidyanathan Srinivasan
These APIs take logical cpu number as input
Changecpu_first_thread_in_core()tocpu_leftmost_thread_sibling()Changecpu_last_thread_in_core()tocpu_rightmost_thread_sibling()I'm still not happy here.
I don't find leftmost/rightmost to be a "progress" from the previous naming. If you really want to change to avoid
in_core()at the end, then call themfirst_thread_sibling()andlast_thread_sibling().
Hi Ben,
The naming is based on our discussion during the first RFC:
http://lists.ozlabs.org/pipermail/linuxppc-dev/2010-April/081610.html
I am fine with first_thread_sibling() name instead of cpu_{left,right}most_thread_sibling(). The goal is to distinguish between APIs returning logical cpu numbers and core indexes.
first_thread_sibling() implies that the parameter and return value are logical cpu (thread) number.
I will change the name as per your suggestion and post an update.
Quoted 9 lines
Then you change:
arch/powerpc/include/asm/cputhreads.h static inline cpumask_t cpu_online_cores_map(void) · line 67
Quoted 4 lines
arch/powerpc/include/asm/cputhreads.h +0
-4-static inline int cpu_thread_to_core (int cpu) -{ -return cpu >> threads_shift; -}.../... to:
Quoted 7 lines
arch/powerpc/kernel/smp.c out: · line 476
Quoted 7 lines
arch/powerpc/kernel/smp.c +6
-1-/* Must be called when no change can occur to cpu_present_mask, +/* Helper routines for cpu to core mapping */ +int cpu_core_of_thread (int cpu) +{ +return cpu >> threads_shift; +} +EXPORT_SYMBOL_GPL (cpu_core_of_thread);
The cpu_core_of_thread() name implies that the return type is a core index and not a logical cpu number.
cpu_core_of_thread(5) = 1cpu_first_thread_of_core(1) = 4
Do you think cpu_core_number_of_thread() will explain the return type better?
Quoted 10 lines
Any reason you are making it out of line other than gratuituous bloat ? :-)
arch/powerpc/kernel/smp.c out: · line 482
Quoted 5 lines
arch/powerpc/kernel/smp.c +5
-0+int cpu_first_thread_of_core (int core) +{ +return core << threads_shift; +} +EXPORT_SYMBOL_GPL (cpu_first_thread_of_core);Same.
The reason behind out of line is to avoid exporting threads_shift or other variables like threads_per_core and have this API exported so that modules can read them. If we make these wrapper inline, then we will have to export the variables themselves which is not a good idea.
Thanks for the review.
--Vaidy
PATCH v4 2/2 powerpc: add support for new hcall H_BEST_ENERGY
In reply to Vaidyanathan Srinivasan Create sysfs interface to export data from H_BEST_ENERGY hcall that can be used by administrative tools on supported pseries
platforms for energy management optimizations.
/sys/device/system/cpu/pseries_(de)activate_hint_list and /sys/device/system/cpu/cpuN/pseries_(de)activate_hint will provide hints for activation and deactivation of cpus respectively.
These hints are abstract number given by the hypervisor based on the extended knowledge the hypervisor has regarding the current system topology and resource mappings.
The activate and the deactivate sysfs entry is for the two distinct operations that we could do for energy savings. When we have more capacity than required, we could deactivate few core to save energy. The choice of the core to deactivate will be based on /sys/devices/system/cpu/deactivate_hint_list. The comma separated list of cpus (cores) will be the preferred choice. If we have to activate some of the deactivated cores, then /sys/devices/system/cpu/activate_hint_list will be used.
The per-cpu file /sys/device/system/cpu/cpuN/pseries_(de)activate_hint further provide more fine grain information by exporting the value of the hint itself.
Added new driver module
arch/powerpc/platforms/pseries/pseries_energy.c
under new config option CONFIG_PSERIES_ENERGY
--- arch/powerpc/include/asm/hvcall.h | 3 arch/powerpc/platforms/pseries/Kconfig | 10 + arch/powerpc/platforms/pseries/Makefile | 1 arch/powerpc/platforms/pseries/pseries_energy.c | 326 +++++++++++++++++++++++ 4 files changed, 339 insertions(+), 1 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/pseries_energy.c
arch/powerpc/include/asm/hvcall.h +2 -1
@@ -231,7 +231,8 @@#define H_GET_EM_PARMS 0x2B8#define H_SET_MPP 0x2D0#define H_GET_MPP 0x2D4 -#define MAX_HCALL_OPCODE H_GET_MPP +#define H_BEST_ENERGY 0x2F4 +#define MAX_HCALL_OPCODE H_BEST_ENERGY#ifndef __ASSEMBLY__
arch/powerpc/platforms/pseries/Kconfig +10 -0
@@ -33,6 +33,16 @@ config PSERIES_MSI depends on PCI_MSI && EEH default y +config PSERIES_ENERGY + tristate "pSeries energy management capabilities driver" + depends on PPC_PSERIES + default y + help + Provides interface to platform energy management capabilities + on supported PSERIES platforms. + Provides: /sys/devices/system/cpu/pseries_(de)activation_hint_list + and /sys/devices/system/cpu/cpuN/pseries_(de)activation_hint + config SCANLOG tristate "Scanlog dump interface" depends on RTAS_PROC && PPC_PSERIES
arch/powerpc/platforms/pseries/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_EEH) += eeh.o eeh_cache.o eeh_driver.o eeh_event.o eeh_sysfs.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_PCI) += pci.o pci_dlpar.o obj-$(CONFIG_PSERIES_MSI) += msi.o +obj-$(CONFIG_PSERIES_ENERGY) += pseries_energy.o obj-$(CONFIG_HOTPLUG_CPU) += hotplug-cpu.o obj-$(CONFIG_MEMORY_HOTPLUG) += hotplug-memory.o
arch/powerpc/platforms/pseries/pseries_energy.c new file +326 -0
326 lines not on this page · raw message