Skip to contentSkip to conversation

powerpc, perf: Clear out branch entries to avoid any previous stale values

PATCH In review Anshuman Khandual 2 participants 2 messages May 6, 2013 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc, perf: Clear out branch entries to avoid any previous stale values

The 'to' field inside branch entries might contain stale values from previous PMU interrupt instances which had indirect branches. So clear all the values before reading a fresh set of BHRB entries after a PMU interrupt.

---
 arch/powerpc/perf/core-book3s.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/perf/core-book3s.c +2 -0
index c627843..09db68d 100644
@@ -1590,6 +1590,8 @@ static void record_and_restart(struct perf_event *event, unsigned long val,
 		if (event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK) {
 			struct cpu_hw_events *cpuhw;
 			cpuhw = &__get_cpu_var(cpu_hw_events);
+			memset(cpuhw->bhrb_entries, 0,
+				sizeof(struct perf_branch_entry) * BHRB_MAX_ENTRIES);
 			power_pmu_bhrb_read(cpuhw);
 			data.br_stack = &cpuhw->bhrb_stack;
 		}
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 14 lines · Anshuman Khandual

The 'to' field inside branch entries might contain stale values from previous PMU interrupt instances which had indirect branches. So clear all the values before reading a fresh set of BHRB entries after a PMU interrupt.

---
 arch/powerpc/perf/core-book3s.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/perf/core-book3s.c +0 -0
index c627843..09db68d 100644

arch/powerpc/perf/core-book3s.c static void record_and_restart(struct perf_event *event, unsigned long val, · line 1597

Quoted 8 lines
arch/powerpc/perf/core-book3s.c +2 -0
@@ -1590,6 +1590,8 @@ static void record_and_restart(struct perf_event *event, unsigned long val,
 		if (event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK) {
 			struct cpu_hw_events *cpuhw;
 			cpuhw = &__get_cpu_var(cpu_hw_events);
+			memset(cpuhw->bhrb_entries, 0,
+				sizeof(struct perf_branch_entry) * BHRB_MAX_ENTRIES);
 			power_pmu_bhrb_read(cpuhw);
 			data.br_stack = &cpuhw->bhrb_stack;
 		}

Wouldn't it be just as effective, and less overhead, to set .to = 0; in the else branch in power_pmu_bhrb_read() ?

eg:

arch/powerpc/perf/core-book3s.c +1 -0
index c627843..30af11a4 100644
@@ -1516,6 +1516,7 @@ void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)
                        } else {
                                /* Update address, flags for current entry */
                                cpuhw->bhrb_entries[u_index].from = addr;
+                               cpuhw->bhrb_entries[u_index].to = 0;
                                cpuhw->bhrb_entries[u_index].mispred = pred;
                                cpuhw->bhrb_entries[u_index].predicted = ~pred;
 

cheers