aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/trace
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2015-12-01 20:00:59 -0500
committerIngo Molnar <mingo@kernel.org>2015-12-06 06:56:10 -0500
commit7f47d8cc039f8746e0038fe05f1ddcb15a2e27f0 (patch)
treebbd8cc8f4dbe6b441325d12d9c86dae26bdfb846 /Documentation/trace
parentbd2a634d9e852b9b6100f9ae9c3c790b0ff91ce0 (diff)
x86, tracing, perf: Add trace point for MSR accesses
For debugging low level code interacting with the CPU it is often useful to trace the MSR read/writes. This gives a concise summary of PMU and other operations. perf has an ad-hoc way to do this using trace_printk, but it's somewhat limited (and also now spews ugly boot messages when enabled) Instead define real trace points for all MSR accesses. This adds three new trace points: read_msr and write_msr and rdpmc. They also report if the access faulted (if *_safe is used) This allows filtering and triggering on specific MSR values, which allows various more advanced debugging techniques. All the values are well defined in the CPU documentation. The trace can be post processed with Documentation/trace/postprocess/decode_msr.py to add symbolic MSR names to the trace. I only added it to native MSR accesses in C, not paravirtualized or in entry*.S (which is not too interesting) Originally the patch kit moved the MSRs out of line. This uses an alternative approach recommended by Steven Rostedt of only moving the trace calls out of line, but open coding the access to the jump label. Signed-off-by: Andi Kleen <ak@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Steven Rostedt <rostedt@goodmis.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Link: http://lkml.kernel.org/r/1449018060-1742-3-git-send-email-andi@firstfloor.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'Documentation/trace')
-rw-r--r--Documentation/trace/events-msr.txt37
-rw-r--r--Documentation/trace/postprocess/decode_msr.py37
2 files changed, 74 insertions, 0 deletions
diff --git a/Documentation/trace/events-msr.txt b/Documentation/trace/events-msr.txt
new file mode 100644
index 000000000000..78c383bf06aa
--- /dev/null
+++ b/Documentation/trace/events-msr.txt
@@ -0,0 +1,37 @@
1
2The x86 kernel supports tracing most MSR (Model Specific Register) accesses.
3To see the definition of the MSRs on Intel systems please see the SDM
4at http://www.intel.com/sdm (Volume 3)
5
6Available trace points:
7
8/sys/kernel/debug/tracing/events/msr/
9
10Trace MSR reads
11
12read_msr
13
14msr: MSR number
15val: Value written
16failed: 1 if the access failed, otherwise 0
17
18
19Trace MSR writes
20
21write_msr
22
23msr: MSR number
24val: Value written
25failed: 1 if the access failed, otherwise 0
26
27
28Trace RDPMC in kernel
29
30rdpmc
31
32The trace data can be post processed with the postprocess/decode_msr.py script
33
34cat /sys/kernel/debug/tracing/trace | decode_msr.py /usr/src/linux/include/asm/msr-index.h
35
36to add symbolic MSR names.
37
diff --git a/Documentation/trace/postprocess/decode_msr.py b/Documentation/trace/postprocess/decode_msr.py
new file mode 100644
index 000000000000..0ab40e0db580
--- /dev/null
+++ b/Documentation/trace/postprocess/decode_msr.py
@@ -0,0 +1,37 @@
1#!/usr/bin/python
2# add symbolic names to read_msr / write_msr in trace
3# decode_msr msr-index.h < trace
4import sys
5import re
6
7msrs = dict()
8
9with open(sys.argv[1] if len(sys.argv) > 1 else "msr-index.h", "r") as f:
10 for j in f:
11 m = re.match(r'#define (MSR_\w+)\s+(0x[0-9a-fA-F]+)', j)
12 if m:
13 msrs[int(m.group(2), 16)] = m.group(1)
14
15extra_ranges = (
16 ( "MSR_LASTBRANCH_%d_FROM_IP", 0x680, 0x69F ),
17 ( "MSR_LASTBRANCH_%d_TO_IP", 0x6C0, 0x6DF ),
18 ( "LBR_INFO_%d", 0xdc0, 0xddf ),
19)
20
21for j in sys.stdin:
22 m = re.search(r'(read|write)_msr:\s+([0-9a-f]+)', j)
23 if m:
24 r = None
25 num = int(m.group(2), 16)
26 if num in msrs:
27 r = msrs[num]
28 else:
29 for er in extra_ranges:
30 if er[1] <= num <= er[2]:
31 r = er[0] % (num - er[1],)
32 break
33 if r:
34 j = j.replace(" " + m.group(2), " " + r + "(" + m.group(2) + ")")
35 print j,
36
37