Skip to contentSkip to conversation

perf/x86: fix bug in event constraint end marker macro

PATCH In review Stephane Eranian 2 participants 4 messages Dec 4, 2013 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/x86: fix bug in event constraint end marker macro

[repost because typo in Ingo's email address]

The EVENT_CONSTRAINT_END macro defines the end marker as a constraint with a weight of zero. This was all fine until we blacklisted the corrupting memory events on Intel IvyBridge. These events are blacklisted by using a counter bitmask of zero. Thus, they also get a constraint weight of zero.

The iteration macro: for_each_constraint tests the weight==0. Therefore, it was stopping at the first blacklisted event, i.e., 0xd0. The corrupting events were therefore considered as unconstrained and were scheduled on any of the generic counters.

This patch fixes the end marker to have a weight of -1. With this, the blacklisted events get an empty constraint and cannot be scheduled which is what we want for now.

---
 arch/x86/kernel/cpu/perf_event.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/perf_event.h +8 -2
index fd00bb2..7c900c9 100644
@@ -263,10 +263,16 @@ struct cpu_hw_events {
 			  HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST_HSW)
 
 #define EVENT_CONSTRAINT_END		\
-	EVENT_CONSTRAINT(0, 0, 0)
+	{ .idxmsk64 = 0,		\
+	  .code = 0,			\
+	  .cmask = 0,			\
+	  .weight = -1,			\
+	  .overlap = 0,			\
+	  .flags = 0,			\
+}
 
 #define for_each_event_constraint(e, c)	\
-	for ((e) = (c); (e)->weight; (e)++)
+	for ((e) = (c); (e)->weight != -1; (e)++)
 
 /*
  * Extra registers for specific events.
Signature · 1 line
1.8.1.2
#1 lore raw

arch/x86/kernel/cpu/perf_event.h struct cpu_hw_events { · line 272

Quoted 9 lines · Stephane Eranian

#define EVENT_CONSTRAINT_END \

arch/x86/kernel/cpu/perf_event.h +7 -1
-	EVENT_CONSTRAINT(0, 0, 0)
+	{ .idxmsk64 = 0,		\
+	  .code = 0,			\
+	  .cmask = 0,			\
+	  .weight = -1,			\
+	  .overlap = 0,			\
+	  .flags = 0,			\
+}

A nit, simply writing:

#define EVENT_CONSTRAINT_END { .weight = -1, }

... should be enough as initialization to zero is guaranteed for the other fields.

Thanks,

Ingo

#2 lore raw

Ingo,

Ok, I have asked Maria to clean the patch up add more comments and repost a new version of the
patch. She will repost ASAP.

Thanks.

Quoted 23 lines · Ingo Molnar

arch/x86/kernel/cpu/perf_event.h struct cpu_hw_events { · line 272

Quoted 9 lines · Stephane Eranian

#define EVENT_CONSTRAINT_END \

arch/x86/kernel/cpu/perf_event.h +7 -1
-     EVENT_CONSTRAINT(0, 0, 0)
+     { .idxmsk64 = 0,                \
+       .code = 0,                    \
+       .cmask = 0,                   \
+       .weight = -1,                 \
+       .overlap = 0,                 \
+       .flags = 0,                   \
+}

A nit, simply writing:

#define EVENT_CONSTRAINT_END { .weight = -1, }

... should be enough as initialization to zero is guaranteed for the other fields.

Thanks,

Ingo

#3 lore raw
Quoted 5 lines · Stephane Eranian

Ingo,

Ok, I have asked Maria to clean the patch up add more comments and repost a new version of the
patch. She will repost ASAP.

Ok!

Thanks,

Ingo