Android-x86
Fork
Spenden

  • R/O
  • HTTP
  • SSH
  • HTTPS

kernel: Commit

kernel


Commit MetaInfo

Revision2099353f7a187ba0eb44cf955c741edfa2b5ab94 (tree)
Zeit2019-09-21 14:14:19
AutorKim Phillips <kim.phillips@amd....>
CommiterGreg Kroah-Hartman

Log Message

perf/x86/amd/ibs: Fix sample bias for dispatched micro-ops

[ Upstream commit 0f4cd769c410e2285a4e9873a684d90423f03090 ]

When counting dispatched micro-ops with cnt_ctl=1, in order to prevent
sample bias, IBS hardware preloads the least significant 7 bits of
current count (IbsOpCurCnt) with random values, such that, after the
interrupt is handled and counting resumes, the next sample taken
will be slightly perturbed.

The current count bitfield is in the IBS execution control h/w register,
alongside the maximum count field.

Currently, the IBS driver writes that register with the maximum count,
leaving zeroes to fill the current count field, thereby overwriting
the random bits the hardware preloaded for itself.

Fix the driver to actually retain and carry those random bits from the
read of the IBS control register, through to its write, instead of
overwriting the lower current count bits with zeroes.

Tested with:

perf record -c 100001 -e ibs_op/cnt_ctl=1/pp -a -C 0 taskset -c 0 <workload>

'perf annotate' output before:

15.70 65: addsd %xmm0,%xmm1
17.30 add $0x1,%rax
15.88 cmp %rdx,%rax
je 82
17.32 72: test $0x1,%al
jne 7c
7.52 movapd %xmm1,%xmm0
5.90 jmp 65
8.23 7c: sqrtsd %xmm1,%xmm0
12.15 jmp 65

'perf annotate' output after:

16.63 65: addsd %xmm0,%xmm1
16.82 add $0x1,%rax
16.81 cmp %rdx,%rax
je 82
16.69 72: test $0x1,%al
jne 7c
8.30 movapd %xmm1,%xmm0
8.13 jmp 65
8.24 7c: sqrtsd %xmm1,%xmm0
8.39 jmp 65

Tested on Family 15h and 17h machines.

Machines prior to family 10h Rev. C don't have the RDWROPCNT capability,
and have the IbsOpCurCnt bitfield reserved, so this patch shouldn't
affect their operation.

It is unknown why commit db98c5faf8cb ("perf/x86: Implement 64-bit
counter support for IBS") ignored the lower 4 bits of the IbsOpCurCnt
field; the number of preloaded random bits has always been 7, AFAICT.

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: "Arnaldo Carvalho de Melo" <acme@kernel.org>
Cc: <x86@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "Borislav Petkov" <bp@alien8.de>
Cc: Stephane Eranian <eranian@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: "Namhyung Kim" <namhyung@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lkml.kernel.org/r/20190826195730.30614-1-kim.phillips@amd.com
Signed-off-by: Sasha Levin <sashal@kernel.org>

Ändern Zusammenfassung

Diff

--- a/arch/x86/events/amd/ibs.c
+++ b/arch/x86/events/amd/ibs.c
@@ -671,10 +671,17 @@ fail:
671671
672672 throttle = perf_event_overflow(event, &data, &regs);
673673 out:
674- if (throttle)
674+ if (throttle) {
675675 perf_ibs_stop(event, 0);
676- else
677- perf_ibs_enable_event(perf_ibs, hwc, period >> 4);
676+ } else {
677+ period >>= 4;
678+
679+ if ((ibs_caps & IBS_CAPS_RDWROPCNT) &&
680+ (*config & IBS_OP_CNT_CTL))
681+ period |= *config & IBS_OP_CUR_CNT_RAND;
682+
683+ perf_ibs_enable_event(perf_ibs, hwc, period);
684+ }
678685
679686 perf_event_update_userpage(event);
680687
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -200,16 +200,20 @@ struct x86_pmu_capability {
200200 #define IBSCTL_LVT_OFFSET_VALID (1ULL<<8)
201201 #define IBSCTL_LVT_OFFSET_MASK 0x0F
202202
203-/* ibs fetch bits/masks */
203+/* IBS fetch bits/masks */
204204 #define IBS_FETCH_RAND_EN (1ULL<<57)
205205 #define IBS_FETCH_VAL (1ULL<<49)
206206 #define IBS_FETCH_ENABLE (1ULL<<48)
207207 #define IBS_FETCH_CNT 0xFFFF0000ULL
208208 #define IBS_FETCH_MAX_CNT 0x0000FFFFULL
209209
210-/* ibs op bits/masks */
211-/* lower 4 bits of the current count are ignored: */
212-#define IBS_OP_CUR_CNT (0xFFFF0ULL<<32)
210+/*
211+ * IBS op bits/masks
212+ * The lower 7 bits of the current count are random bits
213+ * preloaded by hardware and ignored in software
214+ */
215+#define IBS_OP_CUR_CNT (0xFFF80ULL<<32)
216+#define IBS_OP_CUR_CNT_RAND (0x0007FULL<<32)
213217 #define IBS_OP_CNT_CTL (1ULL<<19)
214218 #define IBS_OP_VAL (1ULL<<18)
215219 #define IBS_OP_ENABLE (1ULL<<17)
Show on old repository browser