LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] perf_events: fix Pentium4 raw event validation
@ 2011-01-25 15:32 Stephane Eranian
  2011-01-25 16:48 ` Cyrill Gorcunov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Stephane Eranian @ 2011-01-25 15:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: peterz, mingo, paulus, davem, fweisbec, perfmon2-devel, eranian,
	eranian, robert.richter, acme, gorcunov, ming.m.lin

This patches fixes some issies with raw event validation on Pentium 4 (Netburst)
processors.

As I was testing libpfm4 Netburst support, I ran into two problems in the
p4_validate_raw_event() function:
   - the shared field must be checked ONLY when HT is on
   - the binding to ESCR register was missing

The second item was causing raw events to not be encoded correctly compared
to generic PMU events.

With this patch, I can now pass Netburst events to libpfm4 examples and
get meaningful results:
  $ task -e global_power_events:running:u  noploop 1
  noploop for 1 seconds
  3,206,304,898 global_power_events:running

Signed-off-by: Stephane Eranian <eranian@google.com>
---

diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c
index e56b9bf..f7a0993 100644
--- a/arch/x86/kernel/cpu/perf_event_p4.c
+++ b/arch/x86/kernel/cpu/perf_event_p4.c
@@ -682,7 +682,7 @@ static int p4_validate_raw_event(struct perf_event *event)
 	 * if an event is shared accross the logical threads
 	 * the user needs special permissions to be able to use it
 	 */
-	if (p4_event_bind_map[v].shared) {
+	if (p4_ht_active() && p4_event_bind_map[v].shared) {
 		if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
 			return -EACCES;
 	}
@@ -727,7 +727,8 @@ static int p4_hw_config(struct perf_event *event)
 		event->hw.config = p4_set_ht_bit(event->hw.config);
 
 	if (event->attr.type == PERF_TYPE_RAW) {
-
+		struct p4_event_bind *bind;
+		unsigned int esel;
 		/*
 		 * Clear bits we reserve to be managed by kernel itself
 		 * and never allowed from a user space
@@ -743,6 +744,13 @@ static int p4_hw_config(struct perf_event *event)
 		 * bits since we keep additional info here (for cache events and etc)
 		 */
 		event->hw.config |= event->attr.config;
+		bind = p4_config_get_bind(event->attr.config);
+		if (!bind) {
+			rc = -EINVAL;
+			goto out;
+		}
+		esel = P4_OPCODE_ESEL(bind->opcode);
+		event->hw.config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel));
 	}
 
 	rc = x86_setup_perfctr(event);

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

* Re: [PATCH] perf_events: fix Pentium4 raw event validation
  2011-01-25 15:32 [PATCH] perf_events: fix Pentium4 raw event validation Stephane Eranian
@ 2011-01-25 16:48 ` Cyrill Gorcunov
  2011-01-26  7:26 ` [tip:perf/urgent] perf: Fix " tip-bot for Stephane Eranian
  2011-01-27 18:28 ` tip-bot for Stephane Eranian
  2 siblings, 0 replies; 4+ messages in thread
From: Cyrill Gorcunov @ 2011-01-25 16:48 UTC (permalink / raw)
  To: eranian
  Cc: linux-kernel, peterz, mingo, paulus, davem, fweisbec,
	perfmon2-devel, eranian, robert.richter, acme, ming.m.lin

On 01/25/2011 06:32 PM, Stephane Eranian wrote:
> This patches fixes some issies with raw event validation on Pentium 4 (Netburst)
> processors.
> 
> As I was testing libpfm4 Netburst support, I ran into two problems in the
> p4_validate_raw_event() function:
>    - the shared field must be checked ONLY when HT is on
>    - the binding to ESCR register was missing
> 
> The second item was causing raw events to not be encoded correctly compared
> to generic PMU events.
> 
> With this patch, I can now pass Netburst events to libpfm4 examples and
> get meaningful results:
>   $ task -e global_power_events:running:u  noploop 1
>   noploop for 1 seconds
>   3,206,304,898 global_power_events:running
> 
> Signed-off-by: Stephane Eranian <eranian@google.com>

Thanks a lot Stephane!

Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
-- 
    Cyrill

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

* [tip:perf/urgent] perf: Fix Pentium4 raw event validation
  2011-01-25 15:32 [PATCH] perf_events: fix Pentium4 raw event validation Stephane Eranian
  2011-01-25 16:48 ` Cyrill Gorcunov
@ 2011-01-26  7:26 ` tip-bot for Stephane Eranian
  2011-01-27 18:28 ` tip-bot for Stephane Eranian
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Stephane Eranian @ 2011-01-26  7:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, eranian, hpa, mingo, gorcunov, tglx, mingo

Commit-ID:  3284063535adb5ca02e7ad51d7556193fb8e799e
Gitweb:     http://git.kernel.org/tip/3284063535adb5ca02e7ad51d7556193fb8e799e
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Tue, 25 Jan 2011 17:32:01 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 26 Jan 2011 08:01:20 +0100

perf: Fix Pentium4 raw event validation

This patch fixes some issues with raw event validation on
Pentium 4 (Netburst) based processors.

As I was testing libpfm4 Netburst support, I ran into two
problems in the p4_validate_raw_event() function:

   - the shared field must be checked ONLY when HT is on
   - the binding to ESCR register was missing

The second item was causing raw events to not be encoded
correctly compared to generic PMU events.

With this patch, I can now pass Netburst events to libpfm4
examples and get meaningful results:

  $ task -e global_power_events:running:u  noploop 1
  noploop for 1 seconds
  3,206,304,898 global_power_events:running

Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: peterz@infradead.org
Cc: paulus@samba.org
Cc: davem@davemloft.net
Cc: fweisbec@gmail.com
Cc: perfmon2-devel@lists.sf.net
Cc: eranian@gmail.com
Cc: robert.richter@amd.com
Cc: acme@redhat.com
Cc: gorcunov@gmail.com
Cc: ming.m.lin@intel.com
LKML-Reference: <4d3efb2f.1252d80a.1a80.ffffc83f@mx.google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/cpu/perf_event_p4.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c
index e56b9bf..f7a0993 100644
--- a/arch/x86/kernel/cpu/perf_event_p4.c
+++ b/arch/x86/kernel/cpu/perf_event_p4.c
@@ -682,7 +682,7 @@ static int p4_validate_raw_event(struct perf_event *event)
 	 * if an event is shared accross the logical threads
 	 * the user needs special permissions to be able to use it
 	 */
-	if (p4_event_bind_map[v].shared) {
+	if (p4_ht_active() && p4_event_bind_map[v].shared) {
 		if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
 			return -EACCES;
 	}
@@ -727,7 +727,8 @@ static int p4_hw_config(struct perf_event *event)
 		event->hw.config = p4_set_ht_bit(event->hw.config);
 
 	if (event->attr.type == PERF_TYPE_RAW) {
-
+		struct p4_event_bind *bind;
+		unsigned int esel;
 		/*
 		 * Clear bits we reserve to be managed by kernel itself
 		 * and never allowed from a user space
@@ -743,6 +744,13 @@ static int p4_hw_config(struct perf_event *event)
 		 * bits since we keep additional info here (for cache events and etc)
 		 */
 		event->hw.config |= event->attr.config;
+		bind = p4_config_get_bind(event->attr.config);
+		if (!bind) {
+			rc = -EINVAL;
+			goto out;
+		}
+		esel = P4_OPCODE_ESEL(bind->opcode);
+		event->hw.config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel));
 	}
 
 	rc = x86_setup_perfctr(event);

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

* [tip:perf/urgent] perf: Fix Pentium4 raw event validation
  2011-01-25 15:32 [PATCH] perf_events: fix Pentium4 raw event validation Stephane Eranian
  2011-01-25 16:48 ` Cyrill Gorcunov
  2011-01-26  7:26 ` [tip:perf/urgent] perf: Fix " tip-bot for Stephane Eranian
@ 2011-01-27 18:28 ` tip-bot for Stephane Eranian
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Stephane Eranian @ 2011-01-27 18:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, eranian, hpa, mingo, gorcunov, tglx, mingo

Commit-ID:  d038b12c6d773a4b9f69ca5243773bf6314f7ee9
Gitweb:     http://git.kernel.org/tip/d038b12c6d773a4b9f69ca5243773bf6314f7ee9
Author:     Stephane Eranian <eranian@google.com>
AuthorDate: Tue, 25 Jan 2011 17:32:01 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 27 Jan 2011 19:21:53 +0100

perf: Fix Pentium4 raw event validation

This patch fixes some issues with raw event validation on
Pentium 4 (Netburst) based processors.

As I was testing libpfm4 Netburst support, I ran into two
problems in the p4_validate_raw_event() function:

   - the shared field must be checked ONLY when HT is on
   - the binding to ESCR register was missing

The second item was causing raw events to not be encoded
correctly compared to generic PMU events.

With this patch, I can now pass Netburst events to libpfm4
examples and get meaningful results:

  $ task -e global_power_events:running:u  noploop 1
  noploop for 1 seconds
  3,206,304,898 global_power_events:running

Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: peterz@infradead.org
Cc: paulus@samba.org
Cc: davem@davemloft.net
Cc: fweisbec@gmail.com
Cc: perfmon2-devel@lists.sf.net
Cc: eranian@gmail.com
Cc: robert.richter@amd.com
Cc: acme@redhat.com
Cc: gorcunov@gmail.com
Cc: ming.m.lin@intel.com
LKML-Reference: <4d3efb2f.1252d80a.1a80.ffffc83f@mx.google.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 arch/x86/kernel/cpu/perf_event_p4.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c
index e56b9bf..f7a0993 100644
--- a/arch/x86/kernel/cpu/perf_event_p4.c
+++ b/arch/x86/kernel/cpu/perf_event_p4.c
@@ -682,7 +682,7 @@ static int p4_validate_raw_event(struct perf_event *event)
 	 * if an event is shared accross the logical threads
 	 * the user needs special permissions to be able to use it
 	 */
-	if (p4_event_bind_map[v].shared) {
+	if (p4_ht_active() && p4_event_bind_map[v].shared) {
 		if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
 			return -EACCES;
 	}
@@ -727,7 +727,8 @@ static int p4_hw_config(struct perf_event *event)
 		event->hw.config = p4_set_ht_bit(event->hw.config);
 
 	if (event->attr.type == PERF_TYPE_RAW) {
-
+		struct p4_event_bind *bind;
+		unsigned int esel;
 		/*
 		 * Clear bits we reserve to be managed by kernel itself
 		 * and never allowed from a user space
@@ -743,6 +744,13 @@ static int p4_hw_config(struct perf_event *event)
 		 * bits since we keep additional info here (for cache events and etc)
 		 */
 		event->hw.config |= event->attr.config;
+		bind = p4_config_get_bind(event->attr.config);
+		if (!bind) {
+			rc = -EINVAL;
+			goto out;
+		}
+		esel = P4_OPCODE_ESEL(bind->opcode);
+		event->hw.config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel));
 	}
 
 	rc = x86_setup_perfctr(event);

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

end of thread, other threads:[~2011-01-27 18:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-25 15:32 [PATCH] perf_events: fix Pentium4 raw event validation Stephane Eranian
2011-01-25 16:48 ` Cyrill Gorcunov
2011-01-26  7:26 ` [tip:perf/urgent] perf: Fix " tip-bot for Stephane Eranian
2011-01-27 18:28 ` tip-bot for Stephane Eranian

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).