powerpc/perf/hv-24x7: Check support before registering
PATCH 1/1 powerpc/perf/hv-24x7: Check support before registering
Quoted 1 line
From
955102eacf035b19080dc659a15d9b8fbd8fae7fMon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <[email protected]>
Date: Tue, 28 Apr 2015 18:47:58 -0400
Subject: [PATCH 1/1] powerpc/perf/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.
---
Changelog[v2]
- [Michael Ellerman] Simplify check with bogus parameters.
--- arch/powerpc/perf/hv-24x7.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/powerpc/perf/hv-24x7.c +21 -0
@@ -1268,12 +1268,33 @@ 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 bool hv_has_24x7 (void ) +{ +unsigned long hret; + + hret =h_get_24x7_catalog_page (0 ,0 ,0 ); + +if (hret !=H_FUNCTION ) +pr_err ("Error %ld reading catalog, disabling 24x7 PMU\n" , hret); + +return hret ==0 ; + +} + +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.7.9.5
Michael Ellerman
reviewerQuoted 28 lines · Sukadev Bhattiprolu
Quoted 1 line
From
955102eacf035b19080dc659a15d9b8fbd8fae7fMon Sep 17 00:00:00 2001From: Sukadev Bhattiprolu <[email protected]>
Date: Tue, 28 Apr 2015 18:47:58 -0400
Subject: [PATCH 1/1] powerpc/perf/hv-24x7: Check support before registering
PMUWe 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.
Reported-by Gustavo Luiz Duarte <[email protected]>Signed-off-by Sukadev Bhattiprolu <[email protected]>---
Changelog[v2]
- [Michael Ellerman] Simplify check with bogus parameters.--- arch/powerpc/perf/hv-24x7.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)arch/powerpc/perf/hv-24x7.c +0
-0
arch/powerpc/perf/hv-24x7.c static struct pmu h_24x7_pmu = { · line 1273
Quoted 6 lines
arch/powerpc/perf/hv-24x7.c +3
-0@@ -1268,12 +1268,33 @@ 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.
Comment is wrong.
arch/powerpc/perf/hv-24x7.c static struct pmu h_24x7_pmu = { · line 1277
Quoted 4 lines
arch/powerpc/perf/hv-24x7.c +4
-0+*/ +static bool hv_has_24x7 (void ) +{ +unsigned long hret;
ret would be fine.
arch/powerpc/perf/hv-24x7.c static struct pmu h_24x7_pmu = { · line 1284
Quoted 7 lines
arch/powerpc/perf/hv-24x7.c +7
-0+ + hret =h_get_24x7_catalog_page (0 ,0 ,0 ); + +if (hret !=H_FUNCTION ) +pr_err ("Error %ld reading catalog, disabling 24x7 PMU\n" , hret); + +return hret ==0 ;
I don't get what you're doing here.
You check for something other than H_FUNCTION, and print, and then you just compare against 0. But I wouldn't ever expect that to return 0, because you passed it bogus args.
The logic should be:
static bool is_24x7_supported(void)
{
if (h_get_24x7_catalog_page(0, 0, 0) == H_FUNCTION)
return false;
return true;
}arch/powerpc/perf/hv-24x7.c static struct pmu h_24x7_pmu = { · line 1297
Quoted 9 lines
arch/powerpc/perf/hv-24x7.c +3
-0static int hv_24x7_init (void ) {int r;unsigned long hret;struct hv_perf_caps caps; +if (!hv_has_24x7 ()) +return -ENODEV ; +
This is no good. You're doing the check, which involves a hcall, before you even check if you're running with a hypervisor (below).
arch/powerpc/perf/hv-24x7.c static struct pmu h_24x7_pmu = { · line 1300
Quoted 3 lines
arch/powerpc/perf/hv-24x7.c +0
-0if (!firmware_has_feature (FW_FEATURE_LPAR )) {pr_debug ("not a virtualized system, not enabling\n" );return -ENODEV ;
cheers