linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] powerpc/hv-24x7: Check support before registering PMU
@ 2015-04-30  3:04 Sukadev Bhattiprolu
  2015-05-11 10:26 ` [1/1] " Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: Sukadev Bhattiprolu @ 2015-04-30  3:04 UTC (permalink / raw)
  To: Paul Mackerras, Michael Ellerman; +Cc: gusld, linuxppc-dev, dev, linux-kernel

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.

Reported-by: Gustavo Luiz Duarte <gusld@br.ibm.com>
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
 arch/powerpc/perf/hv-24x7.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index ec2eb20..19a59a3 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -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;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [1/1] powerpc/hv-24x7: Check support before registering PMU
  2015-04-30  3:04 [PATCH 1/1] powerpc/hv-24x7: Check support before registering PMU Sukadev Bhattiprolu
@ 2015-05-11 10:26 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2015-05-11 10:26 UTC (permalink / raw)
  To: Sukadev Bhattiprolu, Paul Mackerras
  Cc: gusld, dev, linuxppc-dev, linux-kernel

On Thu, 2015-30-04 at 03:04:51 UTC, Sukadev Bhattiprolu wrote:
> 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 ..

> diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
> index ec2eb20..19a59a3 100644
> --- a/arch/powerpc/perf/hv-24x7.c
> +++ b/arch/powerpc/perf/hv-24x7.c
> @@ -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

> +{
> +	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);


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-11 10:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-30  3:04 [PATCH 1/1] powerpc/hv-24x7: Check support before registering PMU Sukadev Bhattiprolu
2015-05-11 10:26 ` [1/1] " Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).