powerpc/hv-24x7: Check support before registering PMU
PATCH 1/1 powerpc/hv-24x7: Check support before registering PMU
We currently try to register the 24x7 PMU unconditionally. Not all Power systems support 24x7 counters (eg: Power7). On these systems we get a backtrace during boot when trying to register the 24x7 PMU.
Check if the hypervisor supports 24x7 counters before attempting to register the 24x7 PMU.
--- arch/powerpc/perf/hv-24x7.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
arch/powerpc/perf/hv-24x7.c +32 -0
@@ -1268,12 +1268,44 @@ static struct pmu h_24x7_pmu = { .read = h_24x7_event_read, }; +/* +* Return 1 if we can access the 24x7 counter catalog from the hypervisor. +* Return 0 otherwise. +*/ +static int hv_has_24x7 (void ) +{ +int page_size =4096 ; +unsigned long hret; +void *page; +struct hv_24x7_catalog_page_0 *page_0; + + page_0 =kmalloc (page_size*2 ,GFP_KERNEL ); +if (!page_0) +return 0 ; + +/* buffer for catalog needs to be 4K-aligned */ + page = (void *)((long )page_0 & (~page_size-1 )) + page_size; + hret =h_get_24x7_catalog_page (page,0 ,0 ); +kfree (page_0); + +if (hret) { +pr_devel ("Error %ld reading catalog, disabling 24x7 PMU\n" , hret); +return 0 ; + } + +return 1 ; +} + +static int hv_24x7_init (void ) {int r;unsigned long hret;struct hv_perf_caps caps; +if (!hv_has_24x7 ()) +return -ENODEV ; +if (!firmware_has_feature (FW_FEATURE_LPAR )) {pr_debug ("not a virtualized system, not enabling\n" );return -ENODEV ;
Signature · 1 line
1.8.3.1
Michael Ellerman
reviewerQuoted 6 lines · Sukadev Bhattiprolu
We currently try to register the 24x7 PMU unconditionally. Not all Power systems support 24x7 counters (eg: Power7). On these systems we get a backtrace during boot when trying to register the 24x7 PMU.
Check if the hypervisor supports 24x7 counters before attempting to register the 24x7 PMU.
The concept is good, but ..
arch/powerpc/perf/hv-24x7.c static struct pmu h_24x7_pmu = { · line 1275
Quoted 13 lines
arch/powerpc/perf/hv-24x7.c +5
-0@@ -1268,12 +1268,44 @@ static struct pmu h_24x7_pmu = { .read = h_24x7_event_read, }; +/* +* Return 1 if we can access the 24x7 counter catalog from the hypervisor. +* Return 0 otherwise. +*/ +static int hv_has_24x7 (void )
bool please
Quoted 4 lines
arch/powerpc/perf/hv-24x7.c +4
-0+{ +int page_size =4096 ; +unsigned long hret; +void *page;
arch/powerpc/perf/hv-24x7.c static struct pmu h_24x7_pmu = { · line 1289
Quoted 10 lines
arch/powerpc/perf/hv-24x7.c +10
-0+struct hv_24x7_catalog_page_0 *page_0; + + page_0 =kmalloc (page_size*2 ,GFP_KERNEL ); +if (!page_0) +return 0 ; + +/* buffer for catalog needs to be 4K-aligned */ + page = (void *)((long )page_0 & (~page_size-1 )) + page_size; + hret =h_get_24x7_catalog_page (page,0 ,0 ); +kfree (page_0);
It shouldn't need to be this complicated.
You should just be able to do the hcall with bogus args and if you get H_FUNCTION then 24x7 is not supported.
cheers