powerpc/kernel/sysfs: Add PMU_SYSFS config option to enable PMU SPRs sysfs file creation
PATCH RESEND v2 1/1 powerpc/kernel/sysfs: Add PMU_SYSFS config option to enable PMU SPRs sysfs file creation
Many of the performance moniroting unit (PMU) SPRs are exposed in the sysfs. "perf" API is the primary interface to program PMU and collect counter data in the system. So expose these PMU SPRs in the absence of CONFIG_PERF_EVENTS.
Patch adds a new CONFIG option 'CONFIG_PMU_SYSFS'. The new config option used in kernel/sysfs.c for PMU SPRs sysfs file creation and this new option is enabled only if 'CONFIG_PERF_EVENTS' option is disabled.
Tested this patch with enable/disable CONFIG_PERF_EVENTS option in powernv and pseries machines.
Also did compilation testing for different architecture include:
x86, mips, mips64, alpha, arm. And with book3s_32.config option.
Tested using the following different scenarios:
1. CONFIG_PERF_EVENT - enabled, CONFIG_PMU_SYSFS - disabled,
RESULT: not seen any sysfs files(mmrc*, pmc*) from /sys/bus/cpu/devices/cpu?/
2. CONFIG_PERF_EVENT - disabled, CONFIG_PMU_SYSFS - enabled,
RESULT: seen any sysfs files(mmrc*, pmc*) from /sys/bus/cpu/devices/cpu?/
3. CONFIG_PERF_EVENT -disabled, CONFIG_PMU_SYSFS - disabled,
RESULT: not possible, any one of the config options need to be enabled.
4. CONFIG_PERF_EVENT -enabled, CONFIG_PMU_SYSFS - enabled,
RESULT: not possible, any one of the config options need to be enabled.
--- arch/powerpc/kernel/sysfs.c | 21 +++++++++++++++++++++ arch/powerpc/platforms/Kconfig.cputype | 8 ++++++++ 2 files changed, 29 insertions(+)
---
Changelog:
Resend v2
Added 'Reviewed-by' and 'Tested-by' tag along with test scenarios.
v1 -> v2
- Added new config option 'PMU_SYSFS' for PMU SPR's creation rather than using PERF_EVENTS config option directly and make sure SPR's file creation only if 'CONFIG_PERF_EVENTS' disabled.
---
arch/powerpc/kernel/sysfs.c +21 -0
@@ -457,16 +457,21 @@ static ssize_t __used \#if defined(CONFIG_PPC64 )#define HAS_PPC_PMC_CLASSIC 1 +#ifdef CONFIG_PMU_SYSFS #define HAS_PPC_PMC_IBM 1 +#endif #define HAS_PPC_PMC_PA6T 1#elif defined(CONFIG_PPC_BOOK3S_32 )#define HAS_PPC_PMC_CLASSIC 1 +#ifdef CONFIG_PMU_SYSFS #define HAS_PPC_PMC_IBM 1#define HAS_PPC_PMC_G4 1#endif +#endif #ifdef HAS_PPC_PMC_CLASSIC +#ifdef CONFIG_PMU_SYSFS SYSFS_PMCSETUP (mmcr0,SPRN_MMCR0 );SYSFS_PMCSETUP (mmcr1,SPRN_MMCR1 );SYSFS_PMCSETUP (pmc1,SPRN_PMC1 );
@@ -485,6 +490,10 @@ SYSFS_PMCSETUP(pmc7, SPRN_PMC7);SYSFS_PMCSETUP (pmc8,SPRN_PMC8 );SYSFS_PMCSETUP (mmcra,SPRN_MMCRA ); +#endif /* CONFIG_PPC64 */ +#endif /* CONFIG_PMU_SYSFS */ + +#ifdef CONFIG_PPC64 SYSFS_SPRSETUP (purr,SPRN_PURR );SYSFS_SPRSETUP (spurr,SPRN_SPURR );SYSFS_SPRSETUP (pir,SPRN_PIR );
@@ -495,7 +504,9 @@ SYSFS_SPRSETUP(tscr, SPRN_TSCR);enable write when needed with a separate function. Lets be conservative and default to pseries. */ +#ifdef CONFIG_PMU_SYSFS static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra); +#endif /* CONFIG_PMU_SYSFS */ static DEVICE_ATTR(spurr, 0400, show_spurr, NULL); static DEVICE_ATTR(purr, 0400, show_purr, store_purr); static DEVICE_ATTR(pir, 0400, show_pir, NULL);
@@ -606,12 +617,14 @@ static void sysfs_create_dscr_default(void)#endif /* CONFIG_PPC64 */ #ifdef HAS_PPC_PMC_PA6T +#ifdef CONFIG_PMU_SYSFS SYSFS_PMCSETUP (pa6t_pmc0,SPRN_PA6T_PMC0 );SYSFS_PMCSETUP (pa6t_pmc1,SPRN_PA6T_PMC1 );SYSFS_PMCSETUP (pa6t_pmc2,SPRN_PA6T_PMC2 );SYSFS_PMCSETUP (pa6t_pmc3,SPRN_PA6T_PMC3 );SYSFS_PMCSETUP (pa6t_pmc4,SPRN_PA6T_PMC4 );SYSFS_PMCSETUP (pa6t_pmc5,SPRN_PA6T_PMC5 ); +#endif /* CONFIG_PMU_SYSFS */ #ifdef CONFIG_DEBUG_MISC SYSFS_SPRSETUP (hid0,SPRN_HID0 );SYSFS_SPRSETUP (hid1,SPRN_HID1 );
@@ -644,6 +657,7 @@ SYSFS_SPRSETUP(tsr3, SPRN_PA6T_TSR3);#endif /* CONFIG_DEBUG_MISC */ #endif /* HAS_PPC_PMC_PA6T */ +#ifdef CONFIG_PMU_SYSFS #ifdef HAS_PPC_PMC_IBM static struct device_attribute ibm_common_attrs[] = { __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
@@ -671,9 +685,11 @@ static struct device_attribute classic_pmc_attrs[] = { __ATTR(pmc8, 0600, show_pmc8, store_pmc8), #endif }; +#endif /* CONFIG_PMU_SYSFS */ #ifdef HAS_PPC_PMC_PA6T static struct device_attribute pa6t_attrs[] = { +#ifdef CONFIG_PMU_SYSFS __ATTR (mmcr0,0600 , show_mmcr0, store_mmcr0),__ATTR (mmcr1,0600 , show_mmcr1, store_mmcr1), __ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0),
@@ -682,6 +698,7 @@ static struct device_attribute pa6t_attrs[] = {__ATTR (pmc3,0600 , show_pa6t_pmc3, store_pa6t_pmc3),__ATTR (pmc4,0600 , show_pa6t_pmc4, store_pa6t_pmc4),__ATTR (pmc5,0600 , show_pa6t_pmc5, store_pa6t_pmc5), +#endif /* CONFIG_PMU_SYSFS */ #ifdef CONFIG_DEBUG_MISC__ATTR (hid0,0600 , show_hid0, store_hid0), __ATTR(hid1, 0600, show_hid1, store_hid1),
@@ -787,8 +804,10 @@ static int register_cpu_online(unsigned int cpu)device_create_file (s, &pmc_attrs[i]);#ifdef CONFIG_PPC64 +#ifdef CONFIG_PMU_SYSFS if (cpu_has_feature (CPU_FTR_MMCRA ))device_create_file (s, &dev_attr_mmcra); +#endif /* CONFIG_PMU_SYSFS */ if (cpu_has_feature (CPU_FTR_PURR )) {if (!firmware_has_feature (FW_FEATURE_LPAR ))
@@ -876,8 +895,10 @@ static int unregister_cpu_online(unsigned int cpu)device_remove_file (s, &pmc_attrs[i]);#ifdef CONFIG_PPC64 +#ifdef CONFIG_PMU_SYSFS if (cpu_has_feature (CPU_FTR_MMCRA ))device_remove_file (s, &dev_attr_mmcra); +#endif /* CONFIG_PMU_SYSFS */ if (cpu_has_feature (CPU_FTR_PURR ))device_remove_file (s, &dev_attr_purr);
arch/powerpc/platforms/Kconfig.cputype +8 -0
@@ -417,6 +417,14 @@ config PPC_MM_SLICES config PPC_HAVE_PMU_SUPPORT bool +config PMU_SYSFS + bool + default y if !PERF_EVENTS + help + This option enables PMU SPR sysfs file creation. Since PMU SPRs are + intended to be used via "perf" interface, config option is enabled + only when CONFIG_PERF_EVENTS is disabled. + config PPC_PERF_CTRS def_bool y depends on PERF_EVENTS && PPC_HAVE_PMU_SUPPORT
Signature · 1 line
2.12.3
Le 05/12/2019 à 06:25, Kajol Jain a écrit :
Quoted 9 lines
Many of the performance moniroting unit (PMU) SPRs are exposed in the sysfs. "perf" API is the primary interface to program PMU and collect counter data in the system. So expose these PMU SPRs in the absence of
CONFIG_PERF_EVENTS.Patch adds a new CONFIG option '
CONFIG_PMU_SYSFS'. The new config option used inkernel/sysfs.cfor PMU SPRs sysfs file creation and this new option is enabled only if 'CONFIG_PERF_EVENTS' option is disabled.
Not sure this new unselectable option is worth it. See below.
By the way I also find the subject misleading, as you may believe when reading it that there is something to select.
Quoted 5 lines
Tested this patch with enable/disable
CONFIG_PERF_EVENTSoption in powernv and pseries machines.
Also did compilation testing for different architecture include:
x86, mips, mips64, alpha, arm. And with book3s_32.config option.
How do you use book3s_32.config exactly ? That's a portion of config, not a config by itself. You should use pmac32_defconfig I guess.
Quoted 43 lines
Signed-off-by Kajol Jain <[email protected]>Reviewed-by Madhavan Srinivasan <[email protected]>Tested-by Nageswara R Sastry <[email protected]>Tested using the following different scenarios:
1.CONFIG_PERF_EVENT- enabled,CONFIG_PMU_SYSFS- disabled,
RESULT: not seen any sysfsfiles(mmrc*, pmc*)from /sys/bus/cpu/devices/cpu?/
2.CONFIG_PERF_EVENT- disabled,CONFIG_PMU_SYSFS- enabled,
RESULT: seen any sysfsfiles(mmrc*, pmc*)from /sys/bus/cpu/devices/cpu?/
3.CONFIG_PERF_EVENT-disabled,CONFIG_PMU_SYSFS- disabled,
RESULT: not possible, any one of the config options need to be enabled.
4.CONFIG_PERF_EVENT-enabled,CONFIG_PMU_SYSFS- enabled,
RESULT: not possible, any one of the config options need to be enabled.--- arch/powerpc/kernel/sysfs.c | 21 +++++++++++++++++++++ arch/powerpc/platforms/Kconfig.cputype | 8 ++++++++ 2 files changed, 29 insertions(+)---
Changelog:
Resend v2
Added 'Reviewed-by' and 'Tested-by' tag along with test scenarios.v1 -> v2
- Added new config option 'PMU_SYSFS' for PMU SPR's creation rather than usingPERF_EVENTSconfig option directly and make sure SPR's file creation only if 'CONFIG_PERF_EVENTS' disabled.
---arch/powerpc/kernel/sysfs.c +2
-0@@ -457,16 +457,21 @@ static ssize_t __used \#if defined(CONFIG_PPC64 )#define HAS_PPC_PMC_CLASSIC 1 +#ifdef CONFIG_PMU_SYSFS #define HAS_PPC_PMC_IBM 1 +#endif #define HAS_PPC_PMC_PA6T 1#elif defined(CONFIG_PPC_BOOK3S_32 )
arch/powerpc/kernel/sysfs.c static ssize_t __used \ · line 474
Quoted 10 lines
arch/powerpc/kernel/sysfs.c +3
-0#define HAS_PPC_PMC_CLASSIC 1 +#ifdef CONFIG_PMU_SYSFS #define HAS_PPC_PMC_IBM 1#define HAS_PPC_PMC_G4 1#endif +#endif #ifdef HAS_PPC_PMC_CLASSIC +#ifdef CONFIG_PMU_SYSFS
You don't need this big forest of #ifdefs (this one and all the ones after). All the objets you are protecting with this are indeed static. So the only thing you have to do is to register them only when relevant, and GCC will get rid of the objects by itself when the config option is not enabled. See below.
And the advantage of doing that way is that you don't need to build it with both options to check the build. That's recommended by kernel codying style (Refer https://www.kernel.org/doc/html/latest/process/coding-style.html#conditional-compilation)
[...]
arch/powerpc/kernel/sysfs.c static int register_cpu_online(unsigned int cpu) · line 807
Quoted 5 lines
arch/powerpc/kernel/sysfs.c +1
-0@@ -787,8 +804,10 @@ static int register_cpu_online(unsigned int cpu)device_create_file (s, &pmc_attrs[i]);#ifdef CONFIG_PPC64 +#ifdef CONFIG_PMU_SYSFS
Don't use #ifdef here, just do instead:
if (IS_ENABLED(CONFIG_PMU_SYSFS) && cpu_has_feature(CPU_FTR_MMCRA))
arch/powerpc/kernel/sysfs.c static int unregister_cpu_online(unsigned int cpu) · line 898
Quoted 11 lines
arch/powerpc/kernel/sysfs.c +2
-0if (cpu_has_feature (CPU_FTR_MMCRA ))device_create_file (s, &dev_attr_mmcra); +#endif /* CONFIG_PMU_SYSFS */ if (cpu_has_feature (CPU_FTR_PURR )) {if (!firmware_has_feature (FW_FEATURE_LPAR ))@@ -876,8 +895,10 @@ static int unregister_cpu_online(unsigned int cpu)device_remove_file (s, &pmc_attrs[i]);#ifdef CONFIG_PPC64 +#ifdef CONFIG_PMU_SYSFS
Same, use IS_ENABLED() here as well.
Quoted 12 lines
arch/powerpc/kernel/sysfs.c +1
-0if (cpu_has_feature (CPU_FTR_MMCRA ))device_remove_file (s, &dev_attr_mmcra); +#endif /* CONFIG_PMU_SYSFS */ if (cpu_has_feature (CPU_FTR_PURR ))device_remove_file (s, &dev_attr_purr);arch/powerpc/platforms/Kconfig.cputype +0
-0@@ -417,6 +417,14 @@ config PPC_MM_SLICES config PPC_HAVE_PMU_SUPPORT
arch/powerpc/platforms/Kconfig.cputype config PPC_MM_SLICES · line 427
Quoted 10 lines
arch/powerpc/platforms/Kconfig.cputype +8
-0bool +config PMU_SYSFS + bool + default y if !PERF_EVENTS + help + This option enables PMU SPR sysfs file creation. Since PMU SPRs are + intended to be used via "perf" interface, config option is enabled + only when CONFIG_PERF_EVENTS is disabled. +
Not sure you need this at all. Once you have changed to just using IS_ENABLED() in the two places above, I think it is acceptable to use !IS_ENABLED(CONFIG_PERF_EVENTS) instead.
arch/powerpc/platforms/Kconfig.cputype config PPC_MM_SLICES · line 430
Quoted 4 lines
arch/powerpc/platforms/Kconfig.cputype +0
-0config PPC_PERF_CTRS def_bool y depends on PERF_EVENTS && PPC_HAVE_PMU_SUPPORT
Christophe
Hi Christophe,
Thankyou for reviewing the patch.
Quoted 8 lines · Christophe Leroy
Le 05/12/2019 à 06:25, Kajol Jain a écrit :
Quoted 5 lines
Many of the performance moniroting unit (PMU) SPRs are exposed in the sysfs. "perf" API is the primary interface to program PMU and collect counter data in the system. So expose these PMU SPRs in the absence of
CONFIG_PERF_EVENTS.
Quoted 7 lines
Quoted 4 lines
Patch adds a new CONFIG option '
CONFIG_PMU_SYSFS'. The new config option used inkernel/sysfs.cfor PMU SPRs sysfs file creation and this new option is enabled only if 'CONFIG_PERF_EVENTS' option is disabled.Not sure this new unselectable option is worth it. See below.
By the way I also find the subject misleading, as you may believe when reading it that there is something to select.
Ok I wiil change the subject.
Quoted 8 lines
Quoted 6 lines
Tested this patch with enable/disable
CONFIG_PERF_EVENTSoption in powernv and pseries machines.
Also did compilation testing for different architecture include:
x86, mips, mips64, alpha, arm. And with book3s_32.config option.How do you use book3s_32.config exactly ? That's a portion of config, not a config by itself. You should use
pmac32_defconfigI guess.
Yes you are right, its not a config option. Actually I was playing around with 'CONFIG_PPC_BOOK3S' option in .config file. As you suggested,
I will try to build with 'pmac32_defconfig' option.
Quoted 58 lines
Quoted 41 lines
Signed-off-by Kajol Jain <[email protected]>Reviewed-by Madhavan Srinivasan <[email protected]>Tested-by Nageswara R Sastry <[email protected]>Tested using the following different scenarios:
1.CONFIG_PERF_EVENT- enabled,CONFIG_PMU_SYSFS- disabled,
RESULT: not seen any sysfsfiles(mmrc*, pmc*)from /sys/bus/cpu/devices/cpu?/
2.CONFIG_PERF_EVENT- disabled,CONFIG_PMU_SYSFS- enabled,
RESULT: seen any sysfsfiles(mmrc*, pmc*)from /sys/bus/cpu/devices/cpu?/
3.CONFIG_PERF_EVENT-disabled,CONFIG_PMU_SYSFS- disabled,
RESULT: not possible, any one of the config options need to be enabled.
4.CONFIG_PERF_EVENT-enabled,CONFIG_PMU_SYSFS- enabled,
RESULT: not possible, any one of the config options need to be enabled.
---
arch/powerpc/kernel/sysfs.c | 21 +++++++++++++++++++++arch/powerpc/platforms/Kconfig.cputype| 8 ++++++++2 files changed, 29 insertions(+)---
Changelog:
Resend v2
Added 'Reviewed-by' and 'Tested-by' tag along with test scenarios.v1 -> v2
- Added new config option 'PMU_SYSFS' for PMU SPR's creation rather than usingPERF_EVENTSconfig option directly and make sure SPR's file creation only if 'CONFIG_PERF_EVENTS' disabled.
---arch/powerpc/kernel/sysfs.c +2
-0@@ -457,16 +457,21 @@ static ssize_t __used \ #if defined(CONFIG_PPC64) #define HAS_PPC_PMC_CLASSIC 1 +#ifdef CONFIG_PMU_SYSFS #define HAS_PPC_PMC_IBM 1 +#endif arch/powerpc/kernel/sysfs.c static ssize_t __used \ · line 471
Quoted 10 lines
arch/powerpc/kernel/sysfs.c +3
-0#define HAS_PPC_PMC_PA6T 1 #elif defined(CONFIG_PPC_BOOK3S_32) #define HAS_PPC_PMC_CLASSIC 1 +#ifdef CONFIG_PMU_SYSFS #define HAS_PPC_PMC_IBM 1 #define HAS_PPC_PMC_G4 1 #endif +#endif #ifdef HAS_PPC_PMC_CLASSIC +#ifdef CONFIG_PMU_SYSFS You don't need this big forest of #ifdefs (this one and all the ones after). All the objets you are protecting with this are indeed static. So the only thing you have to do is to register them only when relevant, and GCC will get rid of the objects by itself when the config option is not enabled. See below.
And the advantage of doing that way is that you don't need to build it with both options to check the build. That's recommended by kernel codying style (Refer https://www.kernel.org/doc/html/latest/process/coding-style.html#conditional-compilation)
[...]
Quoted 8 lines
arch/powerpc/kernel/sysfs.c static int register_cpu_online(unsigned int cpu) · line 806
Quoted 4 lines
arch/powerpc/kernel/sysfs.c +1
-0@@ -787,8 +804,10 @@ static int register_cpu_online(unsigned int cpu) device_create_file(s, &pmc_attrs[i]); #ifdef CONFIG_PPC64 +#ifdef CONFIG_PMU_SYSFS Don't use #ifdef here, just do instead:
if (
IS_ENABLED(CONFIG_PMU_SYSFS)&&cpu_has_feature(CPU_FTR_MMCRA))
Thanks for the suggestion I will use IS_ENABLED here.
Quoted 29 lines
arch/powerpc/kernel/sysfs.c static int unregister_cpu_online(unsigned int cpu) · line 897
Quoted 10 lines
arch/powerpc/kernel/sysfs.c +2
-0if (cpu_has_feature(CPU_FTR_MMCRA)) device_create_file(s, &dev_attr_mmcra); +#endif /* CONFIG_PMU_SYSFS */ if (cpu_has_feature(CPU_FTR_PURR)) { if (!firmware_has_feature(FW_FEATURE_LPAR))@@ -876,8 +895,10 @@ static int unregister_cpu_online(unsigned int cpu) device_remove_file(s, &pmc_attrs[i]); #ifdef CONFIG_PPC64 +#ifdef CONFIG_PMU_SYSFS Same, use
IS_ENABLED()here as well.Quoted 16 lines
arch/powerpc/kernel/sysfs.c +1
-0if (cpu_has_feature(CPU_FTR_MMCRA)) device_remove_file(s, &dev_attr_mmcra); +#endif /* CONFIG_PMU_SYSFS */ if (cpu_has_feature(CPU_FTR_PURR)) device_remove_file(s, &dev_attr_purr);arch/powerpc/platforms/Kconfig.cputype +0
-0@@ -417,6 +417,14 @@ config PPC_MM_SLICESconfig
PPC_HAVE_PMU_SUPPORT
bool
+configPMU_SYSFS
+ bool
+ default y if !PERF_EVENTS
+ help
Quoted 8 lines
Quoted 6 lines
+ This option enables PMU SPR sysfs file creation. Since PMU SPRs are
+ intended to be used via "perf" interface, config option is enabled
+ only whenCONFIG_PERF_EVENTSis disabled.
+Not sure you need this at all. Once you have changed to just using
IS_ENABLED()in the two places above, I think it is acceptable to use !IS_ENABLED(CONFIG_PERF_EVENTS) instead.
Actually with v1 of the patch, I tried with PERF_EVENT option, but it was getting bit messy to recreate the current arrangement in the file. So took a new config option path.
Quoted 8 lines
Quoted 5 lines
config
PPC_PERF_CTRS
def_booly
depends onPERF_EVENTS&&PPC_HAVE_PMU_SUPPORTChristophe
Thanks,
Kajol Jain
Michael Ellerman
reviewerQuoted 9 lines · Kajol Jain
Many of the performance moniroting unit (PMU) SPRs are exposed in the sysfs. "perf" API is the primary interface to program PMU and collect counter data in the system. So expose these PMU SPRs in the absence of
CONFIG_PERF_EVENTS.Patch adds a new CONFIG option '
CONFIG_PMU_SYSFS'. The new config option used inkernel/sysfs.cfor PMU SPRs sysfs file creation and this new option is enabled only if 'CONFIG_PERF_EVENTS' option is disabled.
...
Quoted 5 lines
arch/powerpc/platforms/Kconfig.cputype +0
-0
arch/powerpc/platforms/Kconfig.cputype config PPC_MM_SLICES · line 426
Quoted 10 lines
arch/powerpc/platforms/Kconfig.cputype +7
-0@@ -417,6 +417,14 @@ config PPC_MM_SLICES config PPC_HAVE_PMU_SUPPORT bool +config PMU_SYSFS + bool + default y if !PERF_EVENTS + help + This option enables PMU SPR sysfs file creation. Since PMU SPRs are + intended to be used via "perf" interface, config option is enabled + only when CONFIG_PERF_EVENTS is disabled.
This could break existing users that expect the sysfs files to exist.
The situation we have is that all these registers are currently exposed in sysfs, but we don't *think* anything/anyone is using them.
But we're not sure, so we can't just remove them entirely. And we also can't make them incompatible with perf, because then a user has to choose the sysfs files OR perf, which could break someone's setup.
So the option must be user selectable, it should not depend on PERF_EVENTS, and it should be 'default n' (which is the default).
That way it's off by default, unless someone turns it on deliberately.
cheers