History

Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull perf updates from Ingo Molnar: "Kernel side changes: - Improve accuracy of perf/sched clock on x86. (Adrian Hunter) - Intel DS and BTS updates. (Alexander Shishkin) - Intel cstate PMU support. (Kan Liang) - Add group read support to perf_event_read(). (Peter Zijlstra) - Branch call hardware sampling support, implemented on x86 and PowerPC. (Stephane Eranian) - Event groups transactional interface enhancements. (Sukadev Bhattiprolu) - Enable proper x86/intel/uncore PMU support on multi-segment PCI systems. (Taku Izumi) - ... misc fixes and cleanups. The perf tooling team was very busy again with 200+ commits, the full diff doesn't fit into lkml size limits. Here's an (incomplete) list of the tooling highlights: New features: - Change the default event used in all tools (record/top): use the most precise "cycles" hw counter available, i.e. when the user doesn't specify any event, it will try using cycles:ppp, cycles:pp, etc and fall back transparently until it finds a working counter. (Arnaldo Carvalho de Melo) - Integration of perf with eBPF that, given an eBPF .c source file (or .o file built for the 'bpf' target with clang), will get it automatically built, validated and loaded into the kernel via the sys_bpf syscall, which can then be used and seen using 'perf trace' and other tools. (Wang Nan) Various user interface improvements: - Automatic pager invocation on long help output. (Namhyung Kim) - Search for more options when passing args to -h, e.g.: (Arnaldo Carvalho de Melo) $ perf report -h interface Usage: perf report [<options>] --gtk Use the GTK2 interface --stdio Use the stdio interface --tui Use the TUI interface - Show ordered command line options when -h is used or when an unknown option is specified. (Arnaldo Carvalho de Melo) - If options are passed after -h, show just its descriptions, not all options. (Arnaldo Carvalho de Melo) - Implement column based horizontal scrolling in the hists browser (top, report), making it possible to use the TUI for things like 'perf mem report' where there are many more columns than can fit in a terminal. (Arnaldo Carvalho de Melo) - Enhance the error reporting of tracepoint event parsing, e.g.: $ oldperf record -e sched:sched_switc usleep 1 event syntax error: 'sched:sched_switc' \___ unknown tracepoint Run 'perf list' for a list of valid events Now we get the much nicer: $ perf record -e sched:sched_switc ls event syntax error: 'sched:sched_switc' \___ can't access trace events Error: No permissions to read /sys/kernel/debug/tracing/events/sched/sched_switc Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/debug' And after we have those mount point permissions fixed: $ perf record -e sched:sched_switc ls event syntax error: 'sched:sched_switc' \___ unknown tracepoint Error: File /sys/kernel/debug/tracing/events/sched/sched_switc not found. Hint: Perhaps this kernel misses some CONFIG_ setting to enable this feature?. I.e. basically now the event parsing routing uses the strerror_open() routines introduced by and used in 'perf trace' work. (Jiri Olsa) - Fail properly when pattern matching fails to find a tracepoint, i.e. '-e non:existent' was being correctly handled, with a proper error message about that not being a valid event, but '-e non:existent*' wasn't, fix it. (Jiri Olsa) - Do event name substring search as last resort in 'perf list'. (Arnaldo Carvalho de Melo) E.g.: # perf list clock List of pre-defined events (to be used in -e): cpu-clock [Software event] task-clock [Software event] uncore_cbox_0/clockticks/ [Kernel PMU event] uncore_cbox_1/clockticks/ [Kernel PMU event] kvm:kvm_pvclock_update [Tracepoint event] kvm:kvm_update_master_clock [Tracepoint event] power:clock_disable [Tracepoint event] power:clock_enable [Tracepoint event] power:clock_set_rate [Tracepoint event] syscalls:sys_enter_clock_adjtime [Tracepoint event] syscalls:sys_enter_clock_getres [Tracepoint event] syscalls:sys_enter_clock_gettime [Tracepoint event] syscalls:sys_enter_clock_nanosleep [Tracepoint event] syscalls:sys_enter_clock_settime [Tracepoint event] syscalls:sys_exit_clock_adjtime [Tracepoint event] syscalls:sys_exit_clock_getres [Tracepoint event] syscalls:sys_exit_clock_gettime [Tracepoint event] syscalls:sys_exit_clock_nanosleep [Tracepoint event] syscalls:sys_exit_clock_settime [Tracepoint event] Intel PT hardware tracing enhancements: - Accept a zero --itrace period, meaning "as often as possible". In the case of Intel PT that is the same as a period of 1 and a unit of 'instructions' (i.e. --itrace=i1i). (Adrian Hunter) - Harmonize itrace's synthesized callchains with the existing --max-stack tool option. (Adrian Hunter) - Allow time to be displayed in nanoseconds in 'perf script'. (Adrian Hunter) - Fix potential infinite loop when handling Intel PT timestamps. (Adrian Hunter) - Slighly improve Intel PT debug logging. (Adrian Hunter) - Warn when AUX data has been lost, just like when processing PERF_RECORD_LOST. (Adrian Hunter) - Further document export-to-postgresql.py script. (Adrian Hunter) - Add option to synthesize branch stack from auxtrace data. (Adrian Hunter) Misc notable changes: - Switch the default callchain output mode to 'graph,0.5,caller', to make it look like the default for other tools, reducing the learning curve for people used to 'caller' based viewing. (Arnaldo Carvalho de Melo) - various call chain usability enhancements. (Namhyung Kim) - Introduce the 'P' event modifier, meaning 'max precision level, please', i.e.: $ perf record -e cycles:P usleep 1 Is now similar to: $ perf record usleep 1 Useful, for instance, when specifying multiple events. (Jiri Olsa) - Add 'socket' sort entry, to sort by the processor socket in 'perf top' and 'perf report'. (Kan Liang) - Introduce --socket-filter to 'perf report', for filtering by processor socket. (Kan Liang) - Add new "Zoom into Processor Socket" operation in the perf hists browser, used in 'perf top' and 'perf report'. (Kan Liang) - Allow probing on kmodules without DWARF. (Masami Hiramatsu) - Fix 'perf probe -l' for probes added to kernel module functions. (Masami Hiramatsu) - Preparatory work for the 'perf stat record' feature that will allow generating perf.data files with counting data in addition to the sampling mode we have now (Jiri Olsa) - Update libtraceevent KVM plugin. (Paolo Bonzini) - ... plus lots of other enhancements that I failed to list properly, by: Adrian Hunter, Alexander Shishkin, Andi Kleen, Andrzej Hajda, Arnaldo Carvalho de Melo, Dima Kogan, Don Zickus, Geliang Tang, He Kuang, Huaitong Han, Ingo Molnar, Jan Stancek, Jiri Olsa, Kan Liang, Kirill Tkhai, Masami Hiramatsu, Matt Fleming, Namhyung Kim, Paolo Bonzini, Peter Zijlstra, Rabin Vincent, Scott Wood, Stephane Eranian, Sukadev Bhattiprolu, Taku Izumi, Vaishali Thakkar, Wang Nan, Yang Shi and Yunlong Song" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (260 commits) perf unwind: Pass symbol source to libunwind tools build: Fix libiberty feature detection perf tools: Compile scriptlets to BPF objects when passing '.c' to --event perf record: Add clang options for compiling BPF scripts perf bpf: Attach eBPF filter to perf event perf tools: Make sure fixdep is built before libbpf perf script: Enable printing of branch stack perf trace: Add cmd string table to decode sys_bpf first arg perf bpf: Collect perf_evsel in BPF object files perf tools: Load eBPF object into kernel perf tools: Create probe points for BPF programs perf tools: Enable passing bpf object file to --event perf ebpf: Add the libbpf glue perf tools: Make perf depend on libbpf perf symbols: Fix endless loop in dso__split_kallsyms_for_kcore perf tools: Enable pre-event inherit setting by config terms perf symbols: we can now read separate debug-info files based on a build ID perf symbols: Fix type error when reading a build-id perf tools: Search for more options when passing args to -h perf stat: Cache aggregated map entries in extra cpumap ...

Linus Torvalds committed 11 years ago

Commit b02ac6b2 parents 105ff3c bebd23a215 files · +9951 −2026Browse files

Unified · Split

215 files
  1. arch/powerpc/perf/core-book3s.c +30 −6
  2. arch/powerpc/perf/hv-24x7.c +164 −2
  3. arch/powerpc/perf/power8-pmu.c +3 −0
  4. arch/s390/kernel/perf_cpum_cf.c +30 −5
  5. arch/sparc/kernel/perf_event.c +25 −7
  6. arch/x86/kernel/cpu/Makefile +1 −0
  7. arch/x86/kernel/cpu/intel_cacheinfo.c +4 −4
  8. arch/x86/kernel/cpu/perf_event.c +33 −6
  9. arch/x86/kernel/cpu/perf_event.h +1 −1
  10. arch/x86/kernel/cpu/perf_event_intel_bts.c +13 −0
  11. arch/x86/kernel/cpu/perf_event_intel_cstate.c +694 −0
  12. arch/x86/kernel/cpu/perf_event_intel_ds.c +34 −6
  13. arch/x86/kernel/cpu/perf_event_intel_lbr.c +6 −2
  14. arch/x86/kernel/cpu/perf_event_intel_pt.c +4 −3
  15. arch/x86/kernel/cpu/perf_event_intel_uncore.c +58 −3
  16. arch/x86/kernel/cpu/perf_event_intel_uncore.h +11 −1
  17. arch/x86/kernel/cpu/perf_event_intel_uncore_snb.c +13 −3
  18. arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c +25 −9
  19. arch/x86/kernel/tsc.c +22 −13
  20. arch/x86/lib/x86-opcode-map.txt +19 −5
  21. include/linux/perf_event.h +103 −17
  22. include/uapi/linux/perf_event.h +4 −2
  23. kernel/events/core.c +165 −59
  24. tools/build/.gitignore +1 −0
  25. tools/build/Build +1 −0
  26. tools/build/Build.include +14 −3
  27. tools/build/Documentation/Build.txt +39 −13
  28. tools/build/Makefile +43 −0
  29. tools/build/Makefile.build +7 −0
  30. tools/build/Makefile.feature +9 −6
  31. tools/build/Makefile.include +10 −0
  32. tools/build/feature/Makefile +2 −2
  33. tools/build/fixdep.c +168 −0
  34. tools/build/tests/ex/Build +1 −0
  35. tools/build/tests/ex/Makefile +8 −5
  36. tools/build/tests/ex/ex.c +2 −0
  37. tools/build/tests/ex/inc.c +8 −0
  38. tools/build/tests/run.sh +27 −0
  39. tools/include/linux/compiler.h +24 −8
  40. tools/include/linux/err.h +49 −0
  41. tools/include/linux/filter.h +231 −0
  42. tools/lib/api/Build +1 −0
  43. tools/lib/api/Makefile +4 −2
  44. tools/lib/api/cpu.c +18 −0
  45. tools/lib/api/cpu.h +6 −0
  46. tools/lib/api/fs/Build +1 −3
  47. tools/lib/api/fs/debugfs.c +0 −129
  48. tools/lib/api/fs/debugfs.h +0 −23
  49. tools/lib/api/fs/findfs.c +0 −63
  50. tools/lib/api/fs/findfs.h +0 −23
  51. tools/lib/api/fs/fs.c +153 −12
  52. tools/lib/api/fs/fs.h +23 −7
  53. tools/lib/api/fs/tracefs.c +0 −78
  54. tools/lib/api/fs/tracefs.h +0 −21
  55. tools/lib/api/fs/tracing_path.c +135 −0
  56. tools/lib/api/fs/tracing_path.h +16 −0
  57. tools/lib/bpf/Makefile +7 −4
  58. tools/lib/lockdep/Makefile +4 −2
  59. tools/lib/symbol/kallsyms.c +6 −0
  60. tools/lib/symbol/kallsyms.h +3 −1
  61. tools/lib/traceevent/event-parse.c +56 −4
  62. tools/lib/traceevent/event-parse.h +1 −0
  63. tools/lib/traceevent/plugin_kvm.c +17 −8
  64. tools/perf/Documentation/intel-pt.txt +44 −0
  65. tools/perf/Documentation/itrace.txt +4 −0
  66. tools/perf/Documentation/perf-bench.txt +19 −35
  67. tools/perf/Documentation/perf-inject.txt +3 −0
  68. tools/perf/Documentation/perf-list.txt +3 −0
  69. tools/perf/Documentation/perf-record.txt +14 −2
  70. tools/perf/Documentation/perf-report.txt +32 −16
  71. tools/perf/Documentation/perf-script.txt +15 −2
  72. tools/perf/Documentation/perf-stat.txt +3 −2
  73. tools/perf/Documentation/perf-top.txt +3 −2
  74. tools/perf/Documentation/perf.txt +8 −0
  75. tools/perf/MANIFEST +5 −0
  76. tools/perf/Makefile.perf +35 −18
  77. tools/perf/arch/common.c +4 −6
  78. tools/perf/arch/common.h +2 −2
  79. tools/perf/arch/x86/Build +1 −1
  80. tools/perf/arch/x86/Makefile +1 −0
  81. tools/perf/arch/x86/include/arch-tests.h +19 −0
  82. tools/perf/arch/x86/tests/Build +8 −2
  83. tools/perf/arch/x86/tests/arch-tests.c +34 −0
  84. tools/perf/arch/x86/tests/dwarf-unwind.c +1 −0
  85. tools/perf/arch/x86/tests/gen-insn-x86-dat.awk +75 −0
  86. tools/perf/arch/x86/tests/gen-insn-x86-dat.sh +43 −0
  87. tools/perf/arch/x86/tests/insn-x86-dat-32.c +658 −0
  88. tools/perf/arch/x86/tests/insn-x86-dat-64.c +768 −0
  89. tools/perf/arch/x86/tests/insn-x86-dat-src.c +877 −0
  90. tools/perf/arch/x86/tests/insn-x86.c +185 −0
  91. tools/perf/arch/x86/tests/intel-cqm.c +124 −0
  92. tools/perf/arch/x86/tests/perf-time-to-tsc.c +3 −1
  93. tools/perf/arch/x86/tests/rdpmc.c +2 −5
  94. tools/perf/arch/x86/util/dwarf-regs.c +88 −34
  95. tools/perf/arch/x86/util/intel-pt.c +47 −8
  96. tools/perf/bench/Build +1 −1
  97. tools/perf/bench/mem-functions.c +379 −0
  98. tools/perf/bench/mem-memcpy.c +0 −434
  99. tools/perf/bench/numa.c +2 −2
  100. tools/perf/bench/sched-messaging.c +5 −5
  101. tools/perf/builtin-annotate.c +1 −1
  102. tools/perf/builtin-bench.c +7 −7
  103. tools/perf/builtin-evlist.c +2 −2
  104. tools/perf/builtin-help.c +1 −1
  105. tools/perf/builtin-inject.c +125 −2
  106. tools/perf/builtin-kmem.c +1 −1
  107. tools/perf/builtin-kvm.c +0 −1
  108. tools/perf/builtin-list.c +17 −3
  109. tools/perf/builtin-probe.c +131 −16
  110. tools/perf/builtin-record.c +40 −16
  111. tools/perf/builtin-report.c +55 −10
  112. tools/perf/builtin-sched.c +2 −2
  113. tools/perf/builtin-script.c +104 −9
  114. tools/perf/builtin-stat.c +82 −11
  115. tools/perf/builtin-top.c +50 −9
  116. tools/perf/builtin-trace.c +21 −10
  117. tools/perf/config/Makefile +22 −1
  118. tools/perf/perf.c +25 −5
  119. tools/perf/python/twatch.py +20 −3
  120. tools/perf/scripts/python/export-to-postgresql.py +221 −0
  121. tools/perf/tests/Build +1 −3
  122. tools/perf/tests/bpf-script-example.c +44 −0
  123. tools/perf/tests/builtin-test.c +36 −40
  124. tools/perf/tests/code-reading.c +61 −15
  125. tools/perf/tests/dwarf-unwind.c +4 −0
  126. tools/perf/tests/evsel-tp-sched.c +8 −2
  127. tools/perf/tests/hists_filter.c +45 −10
  128. tools/perf/tests/make +3 −1
  129. tools/perf/tests/mmap-basic.c +2 −1
  130. tools/perf/tests/openat-syscall-all-cpus.c +6 −7
  131. tools/perf/tests/openat-syscall-tp-fields.c +3 −2
  132. tools/perf/tests/openat-syscall.c +6 −7
  133. tools/perf/tests/parse-events.c +33 −16
  134. tools/perf/tests/tests.h +7 −3
  135. tools/perf/tests/topology.c +115 −0
  136. tools/perf/tests/vmlinux-kallsyms.c +2 −2
  137. tools/perf/trace/strace/groups/file +2 −0
  138. tools/perf/ui/browser.c +14 −0
  139. tools/perf/ui/browser.h +1 −1
  140. tools/perf/ui/browsers/annotate.c +7 −7
  141. tools/perf/ui/browsers/hists.c +95 −25
  142. tools/perf/ui/browsers/map.c +1 −1
  143. tools/perf/ui/browsers/scripts.c +1 −1
  144. tools/perf/ui/hist.c +8 −8
  145. tools/perf/ui/tui/setup.c +4 −4
  146. tools/perf/util/Build +2 −0
  147. tools/perf/util/annotate.c +4 −1
  148. tools/perf/util/annotate.h +1 −1
  149. tools/perf/util/auxtrace.c +23 −1
  150. tools/perf/util/auxtrace.h +4 −0
  151. tools/perf/util/bpf-loader.c +352 −0
  152. tools/perf/util/bpf-loader.h +85 −0
  153. tools/perf/util/callchain.c +39 −3
  154. tools/perf/util/callchain.h +26 −0
  155. tools/perf/util/cpumap.c +52 −45
  156. tools/perf/util/cpumap.h +8 −2
  157. tools/perf/util/env.c +86 −0
  158. tools/perf/util/env.h +44 −0
  159. tools/perf/util/event.c +15 −7
  160. tools/perf/util/event.h +6 −0
  161. tools/perf/util/evlist.c +43 −4
  162. tools/perf/util/evlist.h +5 −0
  163. tools/perf/util/evsel.c +45 −5
  164. tools/perf/util/evsel.h +8 −2
  165. tools/perf/util/header.c +93 −43
  166. tools/perf/util/header.h +1 −26
  167. tools/perf/util/hist.c +56 −3
  168. tools/perf/util/hist.h +7 −1
  169. tools/perf/util/include/dwarf-regs.h +8 −0
  170. tools/perf/util/intel-pt-decoder/Build +12 −1
  171. tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +2 −2
  172. tools/perf/util/intel-pt-decoder/intel-pt-log.c +11 −10
  173. tools/perf/util/intel-pt-decoder/intel-pt-log.h +32 −6
  174. tools/perf/util/intel-pt-decoder/x86-opcode-map.txt +19 −5
  175. tools/perf/util/intel-pt.c +237 −29
  176. tools/perf/util/machine.c +15 −14
  177. tools/perf/util/machine.h +8 −1
  178. tools/perf/util/map.c +14 −7
  179. tools/perf/util/map.h +2 −0
  180. tools/perf/util/parse-branch-options.c +1 −0
  181. tools/perf/util/parse-events.c +334 −40
  182. tools/perf/util/parse-events.h +15 −1
  183. tools/perf/util/parse-events.l +10 −2
  184. tools/perf/util/parse-events.y +69 −13
  185. tools/perf/util/parse-options.c +133 −23
  186. tools/perf/util/parse-options.h +5 −0
  187. tools/perf/util/pmu.c +17 −25
  188. tools/perf/util/probe-event.c +122 −112
  189. tools/perf/util/probe-event.h +11 −0
  190. tools/perf/util/probe-file.c +38 −18
  191. tools/perf/util/probe-file.h +4 −0
  192. tools/perf/util/probe-finder.c +54 −4
  193. tools/perf/util/python.c +55 −4
  194. tools/perf/util/scripting-engines/trace-event-perl.c +1 −0
  195. tools/perf/util/scripting-engines/trace-event-python.c +2 −1
  196. tools/perf/util/session.c +16 −21
  197. tools/perf/util/session.h +2 −0
  198. tools/perf/util/sort.c +70 −4
  199. tools/perf/util/sort.h +6 −0
  200. tools/perf/util/srcline.c +24 −5
  201. tools/perf/util/stat.c +7 −6
  202. tools/perf/util/stat.h +2 −1
  203. tools/perf/util/strbuf.c +15 −7
  204. tools/perf/util/strbuf.h +2 −0
  205. tools/perf/util/symbol-minimal.c +1 −1
  206. tools/perf/util/symbol.c +20 −11
  207. tools/perf/util/symbol.h +1 −0
  208. tools/perf/util/trace-event-info.c +1 −1
  209. tools/perf/util/trace-event.c +13 −3
  210. tools/perf/util/trace-event.h +2 −0
  211. tools/perf/util/unwind-libunwind.c +12 −7
  212. tools/perf/util/usage.c +5 −0
  213. tools/perf/util/util.c +1 −71
  214. tools/perf/util/util.h +4 −8
  215. tools/vm/page-types.c +3 −3
arch/powerpc/perf/core-book3s.c+30−6
@@ -48,7 +48,7 @@ struct cpu_hw_events { · 47 unmodified lines
48 unsigned long amasks[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];48 unsigned long amasks[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];
49 unsigned long avalues[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];49 unsigned long avalues[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];
50 50
51 unsigned int group_flag;51 unsigned int txn_flags;
52 int n_txn_start;52 int n_txn_start;
53 53
54 /* BHRB bits */54 /* BHRB bits */
@@ -1441,7 +1441,7 @@ static int power_pmu_add(struct perf_event *event, int ef_flags) · 1386 unmodified lines
1441 * skip the schedulability test here, it will be performed1441 * skip the schedulability test here, it will be performed
1442 * at commit time(->commit_txn) as a whole1442 * at commit time(->commit_txn) as a whole
1443 */1443 */
1444 if (cpuhw->group_flag & PERF_EVENT_TXN)1444 if (cpuhw->txn_flags & PERF_PMU_TXN_ADD)
1445 goto nocheck;1445 goto nocheck;
1446 1446
1447 if (check_excludes(cpuhw->event, cpuhw->flags, n0, 1))1447 if (check_excludes(cpuhw->event, cpuhw->flags, n0, 1))
@@ -1586,13 +1586,22 @@ static void power_pmu_stop(struct perf_event *event, int ef_flags) · 138 unmodified lines
1586 * Start group events scheduling transaction1586 * Start group events scheduling transaction
1587 * Set the flag to make pmu::enable() not perform the1587 * Set the flag to make pmu::enable() not perform the
1588 * schedulability test, it will be performed at commit time1588 * schedulability test, it will be performed at commit time
1589 *
1590 * We only support PERF_PMU_TXN_ADD transactions. Save the
1591 * transaction flags but otherwise ignore non-PERF_PMU_TXN_ADD
1592 * transactions.
1589 */1593 */
1590static void power_pmu_start_txn(struct pmu *pmu)1594static void power_pmu_start_txn(struct pmu *pmu, unsigned int txn_flags)
1591{1595{
1592 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);1596 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
1593 1597
1598 WARN_ON_ONCE(cpuhw->txn_flags); /* txn already in flight */
1599
1600 cpuhw->txn_flags = txn_flags;
1601 if (txn_flags & ~PERF_PMU_TXN_ADD)
1602 return;
1603
1594 perf_pmu_disable(pmu);1604 perf_pmu_disable(pmu);
1595 cpuhw->group_flag |= PERF_EVENT_TXN;
1596 cpuhw->n_txn_start = cpuhw->n_events;1605 cpuhw->n_txn_start = cpuhw->n_events;
1597}1606}
1598 1607
@@ -1604,8 +1613,15 @@ static void power_pmu_start_txn(struct pmu *pmu) · 5 unmodified lines
1604static void power_pmu_cancel_txn(struct pmu *pmu)1613static void power_pmu_cancel_txn(struct pmu *pmu)
1605{1614{
1606 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);1615 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
1616 unsigned int txn_flags;
1617
1618 WARN_ON_ONCE(!cpuhw->txn_flags); /* no txn in flight */
1619
1620 txn_flags = cpuhw->txn_flags;
1621 cpuhw->txn_flags = 0;
1622 if (txn_flags & ~PERF_PMU_TXN_ADD)
1623 return;
1607 1624
1608 cpuhw->group_flag &= ~PERF_EVENT_TXN;
1609 perf_pmu_enable(pmu);1625 perf_pmu_enable(pmu);
1610}1626}
1611 1627
@@ -1621,7 +1637,15 @@ static int power_pmu_commit_txn(struct pmu *pmu) · 9 unmodified lines
1621 1637
1622 if (!ppmu)1638 if (!ppmu)
1623 return -EAGAIN;1639 return -EAGAIN;
1640
1624 cpuhw = this_cpu_ptr(&cpu_hw_events);1641 cpuhw = this_cpu_ptr(&cpu_hw_events);
1642 WARN_ON_ONCE(!cpuhw->txn_flags); /* no txn in flight */
1643
1644 if (cpuhw->txn_flags & ~PERF_PMU_TXN_ADD) {
1645 cpuhw->txn_flags = 0;
1646 return 0;
1647 }
1648
1625 n = cpuhw->n_events;1649 n = cpuhw->n_events;
1626 if (check_excludes(cpuhw->event, cpuhw->flags, 0, n))1650 if (check_excludes(cpuhw->event, cpuhw->flags, 0, n))
1627 return -EAGAIN;1651 return -EAGAIN;
@@ -1632,7 +1656,7 @@ static int power_pmu_commit_txn(struct pmu *pmu) · 4 unmodified lines
1632 for (i = cpuhw->n_txn_start; i < n; ++i)1656 for (i = cpuhw->n_txn_start; i < n; ++i)
1633 cpuhw->event[i]->hw.config = cpuhw->events[i];1657 cpuhw->event[i]->hw.config = cpuhw->events[i];
1634 1658
1635 cpuhw->group_flag &= ~PERF_EVENT_TXN;1659 cpuhw->txn_flags = 0;
1636 perf_pmu_enable(pmu);1660 perf_pmu_enable(pmu);
1637 return 0;1661 return 0;
1638}1662}
arch/powerpc/perf/hv-24x7.c+164−2
@@ -142,6 +142,15 @@ static struct attribute_group event_long_desc_group = { · 141 unmodified lines
142 142
143static struct kmem_cache *hv_page_cache;143static struct kmem_cache *hv_page_cache;
144 144
145DEFINE_PER_CPU(int, hv_24x7_txn_flags);
146DEFINE_PER_CPU(int, hv_24x7_txn_err);
147
148struct hv_24x7_hw {
149 struct perf_event *events[255];
150};
151
152DEFINE_PER_CPU(struct hv_24x7_hw, hv_24x7_hw);
153
145/*154/*
146 * request_buffer and result_buffer are not required to be 4k aligned,155 * request_buffer and result_buffer are not required to be 4k aligned,
147 * but are not allowed to cross any 4k boundary. Aligning them to 4k is156 * but are not allowed to cross any 4k boundary. Aligning them to 4k is
@@ -1231,9 +1240,48 @@ static void update_event_count(struct perf_event *event, u64 now) · 1083 unmodified lines
1231static void h_24x7_event_read(struct perf_event *event)1240static void h_24x7_event_read(struct perf_event *event)
1232{1241{
1233 u64 now;1242 u64 now;
1243 struct hv_24x7_request_buffer *request_buffer;
1244 struct hv_24x7_hw *h24x7hw;
1245 int txn_flags;
1246
1247 txn_flags = __this_cpu_read(hv_24x7_txn_flags);
1248
1249 /*
1250 * If in a READ transaction, add this counter to the list of
1251 * counters to read during the next HCALL (i.e commit_txn()).
1252 * If not in a READ transaction, go ahead and make the HCALL
1253 * to read this counter by itself.
1254 */
1255
1256 if (txn_flags & PERF_PMU_TXN_READ) {
1257 int i;
1258 int ret;
1234 1259
1235 now = h_24x7_get_value(event);1260 if (__this_cpu_read(hv_24x7_txn_err))
1236 update_event_count(event, now);1261 return;
1262
1263 request_buffer = (void *)get_cpu_var(hv_24x7_reqb);
1264
1265 ret = add_event_to_24x7_request(event, request_buffer);
1266 if (ret) {
1267 __this_cpu_write(hv_24x7_txn_err, ret);
1268 } else {
1269 /*
1270 * Assoicate the event with the HCALL request index,
1271 * so ->commit_txn() can quickly find/update count.
1272 */
1273 i = request_buffer->num_requests - 1;
1274
1275 h24x7hw = &get_cpu_var(hv_24x7_hw);
1276 h24x7hw->events[i] = event;
1277 put_cpu_var(h24x7hw);
1278 }
1279
1280 put_cpu_var(hv_24x7_reqb);
1281 } else {
1282 now = h_24x7_get_value(event);
1283 update_event_count(event, now);
1284 }
1237}1285}
1238 1286
1239static void h_24x7_event_start(struct perf_event *event, int flags)1287static void h_24x7_event_start(struct perf_event *event, int flags)
@@ -1255,6 +1303,117 @@ static int h_24x7_event_add(struct perf_event *event, int flags) · 15 unmodified lines
1255 return 0;1303 return 0;
1256}1304}
1257 1305
1306/*
1307 * 24x7 counters only support READ transactions. They are
1308 * always counting and dont need/support ADD transactions.
1309 * Cache the flags, but otherwise ignore transactions that
1310 * are not PERF_PMU_TXN_READ.
1311 */
1312static void h_24x7_event_start_txn(struct pmu *pmu, unsigned int flags)
1313{
1314 struct hv_24x7_request_buffer *request_buffer;
1315 struct hv_24x7_data_result_buffer *result_buffer;
1316
1317 /* We should not be called if we are already in a txn */
1318 WARN_ON_ONCE(__this_cpu_read(hv_24x7_txn_flags));
1319
1320 __this_cpu_write(hv_24x7_txn_flags, flags);
1321 if (flags & ~PERF_PMU_TXN_READ)
1322 return;
1323
1324 request_buffer = (void *)get_cpu_var(hv_24x7_reqb);
1325 result_buffer = (void *)get_cpu_var(hv_24x7_resb);
1326
1327 init_24x7_request(request_buffer, result_buffer);
1328
1329 put_cpu_var(hv_24x7_resb);
1330 put_cpu_var(hv_24x7_reqb);
1331}
1332
1333/*
1334 * Clean up transaction state.
1335 *
1336 * NOTE: Ignore state of request and result buffers for now.
1337 * We will initialize them during the next read/txn.
1338 */
1339static void reset_txn(void)
1340{
1341 __this_cpu_write(hv_24x7_txn_flags, 0);
1342 __this_cpu_write(hv_24x7_txn_err, 0);
1343}
1344
1345/*
1346 * 24x7 counters only support READ transactions. They are always counting
1347 * and dont need/support ADD transactions. Clear ->txn_flags but otherwise
1348 * ignore transactions that are not of type PERF_PMU_TXN_READ.
1349 *
1350 * For READ transactions, submit all pending 24x7 requests (i.e requests
1351 * that were queued by h_24x7_event_read()), to the hypervisor and update
1352 * the event counts.
1353 */
1354static int h_24x7_event_commit_txn(struct pmu *pmu)
1355{
1356 struct hv_24x7_request_buffer *request_buffer;
1357 struct hv_24x7_data_result_buffer *result_buffer;
1358 struct hv_24x7_result *resb;
1359 struct perf_event *event;
1360 u64 count;
1361 int i, ret, txn_flags;
1362 struct hv_24x7_hw *h24x7hw;
1363
1364 txn_flags = __this_cpu_read(hv_24x7_txn_flags);
1365 WARN_ON_ONCE(!txn_flags);
1366
1367 ret = 0;
1368 if (txn_flags & ~PERF_PMU_TXN_READ)
1369 goto out;
1370
1371 ret = __this_cpu_read(hv_24x7_txn_err);
1372 if (ret)
1373 goto out;
1374
1375 request_buffer = (void *)get_cpu_var(hv_24x7_reqb);
1376 result_buffer = (void *)get_cpu_var(hv_24x7_resb);
1377
1378 ret = make_24x7_request(request_buffer, result_buffer);
1379 if (ret) {
1380 log_24x7_hcall(request_buffer, result_buffer, ret);
1381 goto put_reqb;
1382 }
1383
1384 h24x7hw = &get_cpu_var(hv_24x7_hw);
1385
1386 /* Update event counts from hcall */
1387 for (i = 0; i < request_buffer->num_requests; i++) {
1388 resb = &result_buffer->results[i];
1389 count = be64_to_cpu(resb->elements[0].element_data[0]);
1390 event = h24x7hw->events[i];
1391 h24x7hw->events[i] = NULL;
1392 update_event_count(event, count);
1393 }
1394
1395 put_cpu_var(hv_24x7_hw);
1396
1397put_reqb:
1398 put_cpu_var(hv_24x7_resb);
1399 put_cpu_var(hv_24x7_reqb);
1400out:
1401 reset_txn();
1402 return ret;
1403}
1404
1405/*
1406 * 24x7 counters only support READ transactions. They are always counting
1407 * and dont need/support ADD transactions. However, regardless of type
1408 * of transaction, all we need to do is cleanup, so we don't have to check
1409 * the type of transaction.
1410 */
1411static void h_24x7_event_cancel_txn(struct pmu *pmu)
1412{
1413 WARN_ON_ONCE(!__this_cpu_read(hv_24x7_txn_flags));
1414 reset_txn();
1415}
1416
1258static struct pmu h_24x7_pmu = {1417static struct pmu h_24x7_pmu = {
1259 .task_ctx_nr = perf_invalid_context,1418 .task_ctx_nr = perf_invalid_context,
1260 1419
@@ -1266,6 +1425,9 @@ static struct pmu h_24x7_pmu = { · 5 unmodified lines
1266 .start = h_24x7_event_start,1425 .start = h_24x7_event_start,
1267 .stop = h_24x7_event_stop,1426 .stop = h_24x7_event_stop,
1268 .read = h_24x7_event_read,1427 .read = h_24x7_event_read,
1428 .start_txn = h_24x7_event_start_txn,
1429 .commit_txn = h_24x7_event_commit_txn,
1430 .cancel_txn = h_24x7_event_cancel_txn,
1269};1431};
1270 1432
1271static int hv_24x7_init(void)1433static int hv_24x7_init(void)
arch/powerpc/perf/power8-pmu.c+3−0
@@ -676,6 +676,9 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type) · 675 unmodified lines
676 if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)676 if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)
677 return -1;677 return -1;
678 678
679 if (branch_sample_type & PERF_SAMPLE_BRANCH_CALL)
680 return -1;
681
679 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {682 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {
680 pmu_bhrb_filter |= POWER8_MMCRA_IFM1;683 pmu_bhrb_filter |= POWER8_MMCRA_IFM1;
681 return pmu_bhrb_filter;684 return pmu_bhrb_filter;
arch/s390/kernel/perf_cpum_cf.c+30−5
@@ -72,6 +72,7 @@ struct cpu_hw_events { · 71 unmodified lines
72 atomic_t ctr_set[CPUMF_CTR_SET_MAX];72 atomic_t ctr_set[CPUMF_CTR_SET_MAX];
73 u64 state, tx_state;73 u64 state, tx_state;
74 unsigned int flags;74 unsigned int flags;
75 unsigned int txn_flags;
75};76};
76static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {77static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = {
77 .ctr_set = {78 .ctr_set = {
@@ -82,6 +83,7 @@ static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { · 4 unmodified lines
82 },83 },
83 .state = 0,84 .state = 0,
84 .flags = 0,85 .flags = 0,
86 .txn_flags = 0,
85};87};
86 88
87static int get_counter_set(u64 event)89static int get_counter_set(u64 event)
@@ -538,7 +540,7 @@ static int cpumf_pmu_add(struct perf_event *event, int flags) · 450 unmodified lines
538 * For group events transaction, the authorization check is540 * For group events transaction, the authorization check is
539 * done in cpumf_pmu_commit_txn().541 * done in cpumf_pmu_commit_txn().
540 */542 */
541 if (!(cpuhw->flags & PERF_EVENT_TXN))543 if (!(cpuhw->txn_flags & PERF_PMU_TXN_ADD))
542 if (validate_ctr_auth(&event->hw))544 if (validate_ctr_auth(&event->hw))
543 return -ENOENT;545 return -ENOENT;
544 546
@@ -576,13 +578,22 @@ static void cpumf_pmu_del(struct perf_event *event, int flags) · 31 unmodified lines
576/*578/*
577 * Start group events scheduling transaction.579 * Start group events scheduling transaction.
578 * Set flags to perform a single test at commit time.580 * Set flags to perform a single test at commit time.
581 *
582 * We only support PERF_PMU_TXN_ADD transactions. Save the
583 * transaction flags but otherwise ignore non-PERF_PMU_TXN_ADD
584 * transactions.
579 */585 */
580static void cpumf_pmu_start_txn(struct pmu *pmu)586static void cpumf_pmu_start_txn(struct pmu *pmu, unsigned int txn_flags)
581{587{
582 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);588 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
583 589
590 WARN_ON_ONCE(cpuhw->txn_flags); /* txn already in flight */
591
592 cpuhw->txn_flags = txn_flags;
593 if (txn_flags & ~PERF_PMU_TXN_ADD)
594 return;
595
584 perf_pmu_disable(pmu);596 perf_pmu_disable(pmu);
585 cpuhw->flags |= PERF_EVENT_TXN;
586 cpuhw->tx_state = cpuhw->state;597 cpuhw->tx_state = cpuhw->state;
587}598}
588 599
@@ -593,11 +604,18 @@ static void cpumf_pmu_start_txn(struct pmu *pmu) · 4 unmodified lines
593 */604 */
594static void cpumf_pmu_cancel_txn(struct pmu *pmu)605static void cpumf_pmu_cancel_txn(struct pmu *pmu)
595{606{
607 unsigned int txn_flags;
596 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);608 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
597 609
610 WARN_ON_ONCE(!cpuhw->txn_flags); /* no txn in flight */
611
612 txn_flags = cpuhw->txn_flags;
613 cpuhw->txn_flags = 0;
614 if (txn_flags & ~PERF_PMU_TXN_ADD)
615 return;
616
598 WARN_ON(cpuhw->tx_state != cpuhw->state);617 WARN_ON(cpuhw->tx_state != cpuhw->state);
599 618
600 cpuhw->flags &= ~PERF_EVENT_TXN;
601 perf_pmu_enable(pmu);619 perf_pmu_enable(pmu);
602}620}
603 621
@@ -611,13 +629,20 @@ static int cpumf_pmu_commit_txn(struct pmu *pmu) · 7 unmodified lines
611 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);629 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
612 u64 state;630 u64 state;
613 631
632 WARN_ON_ONCE(!cpuhw->txn_flags); /* no txn in flight */
633
634 if (cpuhw->txn_flags & ~PERF_PMU_TXN_ADD) {
635 cpuhw->txn_flags = 0;
636 return 0;
637 }
638
614 /* check if the updated state can be scheduled */639 /* check if the updated state can be scheduled */
615 state = cpuhw->state & ~((1 << CPUMF_LCCTL_ENABLE_SHIFT) - 1);640 state = cpuhw->state & ~((1 << CPUMF_LCCTL_ENABLE_SHIFT) - 1);
616 state >>= CPUMF_LCCTL_ENABLE_SHIFT;641 state >>= CPUMF_LCCTL_ENABLE_SHIFT;
617 if ((state & cpuhw->info.auth_ctl) != state)642 if ((state & cpuhw->info.auth_ctl) != state)
618 return -ENOENT;643 return -ENOENT;
619 644
620 cpuhw->flags &= ~PERF_EVENT_TXN;645 cpuhw->txn_flags = 0;
621 perf_pmu_enable(pmu);646 perf_pmu_enable(pmu);
622 return 0;647 return 0;
623}648}
arch/sparc/kernel/perf_event.c+25−7
@@ -108,7 +108,7 @@ struct cpu_hw_events { · 107 unmodified lines
108 /* Enabled/disable state. */108 /* Enabled/disable state. */
109 int enabled;109 int enabled;
110 110
111 unsigned int group_flag;111 unsigned int txn_flags;
112};112};
113static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, };113static DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events) = { .enabled = 1, };
114 114
@@ -1379,7 +1379,7 @@ static int sparc_pmu_add(struct perf_event *event, int ef_flags) · 1264 unmodified lines
1379 * skip the schedulability test here, it will be performed1379 * skip the schedulability test here, it will be performed
1380 * at commit time(->commit_txn) as a whole1380 * at commit time(->commit_txn) as a whole
1381 */1381 */
1382 if (cpuc->group_flag & PERF_EVENT_TXN)1382 if (cpuc->txn_flags & PERF_PMU_TXN_ADD)
1383 goto nocheck;1383 goto nocheck;
1384 1384
1385 if (check_excludes(cpuc->event, n0, 1))1385 if (check_excludes(cpuc->event, n0, 1))
@@ -1494,12 +1494,17 @@ static int sparc_pmu_event_init(struct perf_event *event) · 108 unmodified lines
1494 * Set the flag to make pmu::enable() not perform the1494 * Set the flag to make pmu::enable() not perform the
1495 * schedulability test, it will be performed at commit time1495 * schedulability test, it will be performed at commit time
1496 */1496 */
1497static void sparc_pmu_start_txn(struct pmu *pmu)1497static void sparc_pmu_start_txn(struct pmu *pmu, unsigned int txn_flags)
1498{1498{
1499 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);1499 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
1500 1500
1501 WARN_ON_ONCE(cpuhw->txn_flags); /* txn already in flight */
1502
1503 cpuhw->txn_flags = txn_flags;
1504 if (txn_flags & ~PERF_PMU_TXN_ADD)
1505 return;
1506
1501 perf_pmu_disable(pmu);1507 perf_pmu_disable(pmu);
1502 cpuhw->group_flag |= PERF_EVENT_TXN;
1503}1508}
1504 1509
1505/*1510/*
@@ -1510,8 +1515,15 @@ static void sparc_pmu_start_txn(struct pmu *pmu) · 4 unmodified lines
1510static void sparc_pmu_cancel_txn(struct pmu *pmu)1515static void sparc_pmu_cancel_txn(struct pmu *pmu)
1511{1516{
1512 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);1517 struct cpu_hw_events *cpuhw = this_cpu_ptr(&cpu_hw_events);
1518 unsigned int txn_flags;
1519
1520 WARN_ON_ONCE(!cpuhw->txn_flags); /* no txn in flight */
1521
1522 txn_flags = cpuhw->txn_flags;
1523 cpuhw->txn_flags = 0;
1524 if (txn_flags & ~PERF_PMU_TXN_ADD)
1525 return;
1513 1526
1514 cpuhw->group_flag &= ~PERF_EVENT_TXN;
1515 perf_pmu_enable(pmu);1527 perf_pmu_enable(pmu);
1516}1528}
1517 1529
@@ -1528,14 +1540,20 @@ static int sparc_pmu_commit_txn(struct pmu *pmu) · 10 unmodified lines
1528 if (!sparc_pmu)1540 if (!sparc_pmu)
1529 return -EINVAL;1541 return -EINVAL;
1530 1542
1531 cpuc = this_cpu_ptr(&cpu_hw_events);1543 WARN_ON_ONCE(!cpuc->txn_flags); /* no txn in flight */
1544
1545 if (cpuc->txn_flags & ~PERF_PMU_TXN_ADD) {
1546 cpuc->txn_flags = 0;
1547 return 0;
1548 }
1549
1532 n = cpuc->n_events;1550 n = cpuc->n_events;
1533 if (check_excludes(cpuc->event, 0, n))1551 if (check_excludes(cpuc->event, 0, n))
1534 return -EINVAL;1552 return -EINVAL;
1535 if (sparc_check_constraints(cpuc->event, cpuc->events, n))1553 if (sparc_check_constraints(cpuc->event, cpuc->events, n))
1536 return -EAGAIN;1554 return -EAGAIN;
1537 1555
1538 cpuc->group_flag &= ~PERF_EVENT_TXN;1556 cpuc->txn_flags = 0;
1539 perf_pmu_enable(pmu);1557 perf_pmu_enable(pmu);
1540 return 0;1558 return 0;
1541}1559}
arch/x86/kernel/cpu/Makefile+1−0
@@ -41,6 +41,7 @@ obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o · 40 unmodified lines
41obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o41obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o
42obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o perf_event_intel_cqm.o42obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_rapl.o perf_event_intel_cqm.o
43obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o43obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_pt.o perf_event_intel_bts.o
44obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_cstate.o
44 45
45obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \46obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += perf_event_intel_uncore.o \
46 perf_event_intel_uncore_snb.o \47 perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/intel_cacheinfo.c+4−4
@@ -157,7 +157,7 @@ struct _cpuid4_info_regs { · 156 unmodified lines
157 struct amd_northbridge *nb;157 struct amd_northbridge *nb;
158};158};
159 159
160unsigned short num_cache_leaves;160static unsigned short num_cache_leaves;
161 161
162/* AMD doesn't have CPUID4. Emulate it here to report the same162/* AMD doesn't have CPUID4. Emulate it here to report the same
163 information to the user. This makes some assumptions about the machine:163 information to the user. This makes some assumptions about the machine:
@@ -326,7 +326,7 @@ static void amd_calc_l3_indices(struct amd_northbridge *nb) · 162 unmodified lines
326 *326 *
327 * @returns: the disabled index if used or negative value if slot free.327 * @returns: the disabled index if used or negative value if slot free.
328 */328 */
329int amd_get_l3_disable_slot(struct amd_northbridge *nb, unsigned slot)329static int amd_get_l3_disable_slot(struct amd_northbridge *nb, unsigned slot)
330{330{
331 unsigned int reg = 0;331 unsigned int reg = 0;
332 332
@@ -403,8 +403,8 @@ static void amd_l3_disable_index(struct amd_northbridge *nb, int cpu, · 70 unmodified lines
403 *403 *
404 * @return: 0 on success, error status on failure404 * @return: 0 on success, error status on failure
405 */405 */
406int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu, unsigned slot,406static int amd_set_l3_disable_slot(struct amd_northbridge *nb, int cpu,
407 unsigned long index)407 unsigned slot, unsigned long index)
408{408{
409 int ret = 0;409 int ret = 0;
410 410
arch/x86/kernel/cpu/perf_event.c+33−6
@@ -1175,7 +1175,7 @@ static int x86_pmu_add(struct perf_event *event, int flags) · 1174 unmodified lines
1175 * skip the schedulability test here, it will be performed1175 * skip the schedulability test here, it will be performed
1176 * at commit time (->commit_txn) as a whole.1176 * at commit time (->commit_txn) as a whole.
1177 */1177 */
1178 if (cpuc->group_flag & PERF_EVENT_TXN)1178 if (cpuc->txn_flags & PERF_PMU_TXN_ADD)
1179 goto done_collect;1179 goto done_collect;
1180 1180
1181 ret = x86_pmu.schedule_events(cpuc, n, assign);1181 ret = x86_pmu.schedule_events(cpuc, n, assign);
@@ -1326,7 +1326,7 @@ static void x86_pmu_del(struct perf_event *event, int flags) · 144 unmodified lines
1326 * XXX assumes any ->del() called during a TXN will only be on1326 * XXX assumes any ->del() called during a TXN will only be on
1327 * an event added during that same TXN.1327 * an event added during that same TXN.
1328 */1328 */
1329 if (cpuc->group_flag & PERF_EVENT_TXN)1329 if (cpuc->txn_flags & PERF_PMU_TXN_ADD)
1330 return;1330 return;
1331 1331
1332 /*1332 /*
@@ -1748,11 +1748,22 @@ static inline void x86_pmu_read(struct perf_event *event) · 415 unmodified lines
1748 * Start group events scheduling transaction1748 * Start group events scheduling transaction
1749 * Set the flag to make pmu::enable() not perform the1749 * Set the flag to make pmu::enable() not perform the
1750 * schedulability test, it will be performed at commit time1750 * schedulability test, it will be performed at commit time
1751 *
1752 * We only support PERF_PMU_TXN_ADD transactions. Save the
1753 * transaction flags but otherwise ignore non-PERF_PMU_TXN_ADD
1754 * transactions.
1751 */1755 */
1752static void x86_pmu_start_txn(struct pmu *pmu)1756static void x86_pmu_start_txn(struct pmu *pmu, unsigned int txn_flags)
1753{1757{
1758 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
1759
1760 WARN_ON_ONCE(cpuc->txn_flags); /* txn already in flight */
1761
1762 cpuc->txn_flags = txn_flags;
1763 if (txn_flags & ~PERF_PMU_TXN_ADD)
1764 return;
1765
1754 perf_pmu_disable(pmu);1766 perf_pmu_disable(pmu);
1755 __this_cpu_or(cpu_hw_events.group_flag, PERF_EVENT_TXN);
1756 __this_cpu_write(cpu_hw_events.n_txn, 0);1767 __this_cpu_write(cpu_hw_events.n_txn, 0);
1757}1768}
1758 1769
@@ -1763,7 +1774,16 @@ static void x86_pmu_start_txn(struct pmu *pmu) · 4 unmodified lines
1763 */1774 */
1764static void x86_pmu_cancel_txn(struct pmu *pmu)1775static void x86_pmu_cancel_txn(struct pmu *pmu)
1765{1776{
1766 __this_cpu_and(cpu_hw_events.group_flag, ~PERF_EVENT_TXN);1777 unsigned int txn_flags;
1778 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
1779
1780 WARN_ON_ONCE(!cpuc->txn_flags); /* no txn in flight */
1781
1782 txn_flags = cpuc->txn_flags;
1783 cpuc->txn_flags = 0;
1784 if (txn_flags & ~PERF_PMU_TXN_ADD)
1785 return;
1786
1767 /*1787 /*
1768 * Truncate collected array by the number of events added in this1788 * Truncate collected array by the number of events added in this
1769 * transaction. See x86_pmu_add() and x86_pmu_*_txn().1789 * transaction. See x86_pmu_add() and x86_pmu_*_txn().
@@ -1786,6 +1806,13 @@ static int x86_pmu_commit_txn(struct pmu *pmu) · 16 unmodified lines
1786 int assign[X86_PMC_IDX_MAX];1806 int assign[X86_PMC_IDX_MAX];
1787 int n, ret;1807 int n, ret;
1788 1808
1809 WARN_ON_ONCE(!cpuc->txn_flags); /* no txn in flight */
1810
1811 if (cpuc->txn_flags & ~PERF_PMU_TXN_ADD) {
1812 cpuc->txn_flags = 0;
1813 return 0;
1814 }
1815
1789 n = cpuc->n_events;1816 n = cpuc->n_events;
1790 1817
1791 if (!x86_pmu_initialized())1818 if (!x86_pmu_initialized())
@@ -1801,7 +1828,7 @@ static int x86_pmu_commit_txn(struct pmu *pmu) · 9 unmodified lines
1801 */1828 */
1802 memcpy(cpuc->assign, assign, n*sizeof(int));1829 memcpy(cpuc->assign, assign, n*sizeof(int));
1803 1830
1804 cpuc->group_flag &= ~PERF_EVENT_TXN;1831 cpuc->txn_flags = 0;
1805 perf_pmu_enable(pmu);1832 perf_pmu_enable(pmu);
1806 return 0;1833 return 0;
1807}1834}
arch/x86/kernel/cpu/perf_event.h+1−1
@@ -196,7 +196,7 @@ struct cpu_hw_events { · 195 unmodified lines
196 196
197 int n_excl; /* the number of exclusive events */197 int n_excl; /* the number of exclusive events */
198 198
199 unsigned int group_flag;199 unsigned int txn_flags;
200 int is_fake;200 int is_fake;
201 201
202 /*202 /*
arch/x86/kernel/cpu/perf_event_intel_bts.c+13−0
@@ -495,6 +495,19 @@ static int bts_event_init(struct perf_event *event) · 494 unmodified lines
495 if (x86_add_exclusive(x86_lbr_exclusive_bts))495 if (x86_add_exclusive(x86_lbr_exclusive_bts))
496 return -EBUSY;496 return -EBUSY;
497 497
498 /*
499 * BTS leaks kernel addresses even when CPL0 tracing is
500 * disabled, so disallow intel_bts driver for unprivileged
501 * users on paranoid systems since it provides trace data
502 * to the user in a zero-copy fashion.
503 *
504 * Note that the default paranoia setting permits unprivileged
505 * users to profile the kernel.
506 */
507 if (event->attr.exclude_kernel && perf_paranoid_kernel() &&
508 !capable(CAP_SYS_ADMIN))
509 return -EACCES;
510
498 ret = x86_reserve_hardware();511 ret = x86_reserve_hardware();
499 if (ret) {512 if (ret) {
500 x86_del_exclusive(x86_lbr_exclusive_bts);513 x86_del_exclusive(x86_lbr_exclusive_bts);
arch/x86/kernel/cpu/perf_event_intel_cstate.c+694−0
@@ -0,0 +1,694 @@
1/*
2 * perf_event_intel_cstate.c: support cstate residency counters
3 *
4 * Copyright (C) 2015, Intel Corp.
5 * Author: Kan Liang (kan.liang@intel.com)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 */
18
19/*
20 * This file export cstate related free running (read-only) counters
21 * for perf. These counters may be use simultaneously by other tools,
22 * such as turbostat. However, it still make sense to implement them
23 * in perf. Because we can conveniently collect them together with
24 * other events, and allow to use them from tools without special MSR
25 * access code.
26 *
27 * The events only support system-wide mode counting. There is no
28 * sampling support because it is not supported by the hardware.
29 *
30 * According to counters' scope and category, two PMUs are registered
31 * with the perf_event core subsystem.
32 * - 'cstate_core': The counter is available for each physical core.
33 * The counters include CORE_C*_RESIDENCY.
34 * - 'cstate_pkg': The counter is available for each physical package.
35 * The counters include PKG_C*_RESIDENCY.
36 *
37 * All of these counters are specified in the Intel® 64 and IA-32
38 * Architectures Software Developer.s Manual Vol3b.
39 *
40 * Model specific counters:
41 * MSR_CORE_C1_RES: CORE C1 Residency Counter
42 * perf code: 0x00
43 * Available model: SLM,AMT
44 * Scope: Core (each processor core has a MSR)
45 * MSR_CORE_C3_RESIDENCY: CORE C3 Residency Counter
46 * perf code: 0x01
47 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL
48 * Scope: Core
49 * MSR_CORE_C6_RESIDENCY: CORE C6 Residency Counter
50 * perf code: 0x02
51 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW,SKL
52 * Scope: Core
53 * MSR_CORE_C7_RESIDENCY: CORE C7 Residency Counter
54 * perf code: 0x03
55 * Available model: SNB,IVB,HSW,BDW,SKL
56 * Scope: Core
57 * MSR_PKG_C2_RESIDENCY: Package C2 Residency Counter.
58 * perf code: 0x00
59 * Available model: SNB,IVB,HSW,BDW,SKL
60 * Scope: Package (physical package)
61 * MSR_PKG_C3_RESIDENCY: Package C3 Residency Counter.
62 * perf code: 0x01
63 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL
64 * Scope: Package (physical package)
65 * MSR_PKG_C6_RESIDENCY: Package C6 Residency Counter.
66 * perf code: 0x02
67 * Available model: SLM,AMT,NHM,WSM,SNB,IVB,HSW,BDW,SKL
68 * Scope: Package (physical package)
69 * MSR_PKG_C7_RESIDENCY: Package C7 Residency Counter.
70 * perf code: 0x03
71 * Available model: NHM,WSM,SNB,IVB,HSW,BDW,SKL
72 * Scope: Package (physical package)
73 * MSR_PKG_C8_RESIDENCY: Package C8 Residency Counter.
74 * perf code: 0x04
75 * Available model: HSW ULT only
76 * Scope: Package (physical package)
77 * MSR_PKG_C9_RESIDENCY: Package C9 Residency Counter.
78 * perf code: 0x05
79 * Available model: HSW ULT only
80 * Scope: Package (physical package)
81 * MSR_PKG_C10_RESIDENCY: Package C10 Residency Counter.
82 * perf code: 0x06
83 * Available model: HSW ULT only
84 * Scope: Package (physical package)
85 *
86 */
87
88#include <linux/module.h>
89#include <linux/slab.h>
90#include <linux/perf_event.h>
91#include <asm/cpu_device_id.h>
92#include "perf_event.h"
93
94#define DEFINE_CSTATE_FORMAT_ATTR(_var, _name, _format) \
95static ssize_t __cstate_##_var##_show(struct kobject *kobj, \
96 struct kobj_attribute *attr, \
97 char *page) \
98{ \
99 BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
100 return sprintf(page, _format "\n"); \
101} \
102static struct kobj_attribute format_attr_##_var = \
103 __ATTR(_name, 0444, __cstate_##_var##_show, NULL)
104
105static ssize_t cstate_get_attr_cpumask(struct device *dev,
106 struct device_attribute *attr,
107 char *buf);
108
109struct perf_cstate_msr {
110 u64 msr;
111 struct perf_pmu_events_attr *attr;
112 bool (*test)(int idx);
113};
114
115
116/* cstate_core PMU */
117
118static struct pmu cstate_core_pmu;
119static bool has_cstate_core;
120
121enum perf_cstate_core_id {
122 /*
123 * cstate_core events
124 */
125 PERF_CSTATE_CORE_C1_RES = 0,
126 PERF_CSTATE_CORE_C3_RES,
127 PERF_CSTATE_CORE_C6_RES,
128 PERF_CSTATE_CORE_C7_RES,
129
130 PERF_CSTATE_CORE_EVENT_MAX,
131};
132
133bool test_core(int idx)
134{
135 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
136 boot_cpu_data.x86 != 6)
137 return false;
138
139 switch (boot_cpu_data.x86_model) {
140 case 30: /* 45nm Nehalem */
141 case 26: /* 45nm Nehalem-EP */
142 case 46: /* 45nm Nehalem-EX */
143
144 case 37: /* 32nm Westmere */
145 case 44: /* 32nm Westmere-EP */
146 case 47: /* 32nm Westmere-EX */
147 if (idx == PERF_CSTATE_CORE_C3_RES ||
148 idx == PERF_CSTATE_CORE_C6_RES)
149 return true;
150 break;
151 case 42: /* 32nm SandyBridge */
152 case 45: /* 32nm SandyBridge-E/EN/EP */
153
154 case 58: /* 22nm IvyBridge */
155 case 62: /* 22nm IvyBridge-EP/EX */
156
157 case 60: /* 22nm Haswell Core */
158 case 63: /* 22nm Haswell Server */
159 case 69: /* 22nm Haswell ULT */
160 case 70: /* 22nm Haswell + GT3e (Intel Iris Pro graphics) */
161
162 case 61: /* 14nm Broadwell Core-M */
163 case 86: /* 14nm Broadwell Xeon D */
164 case 71: /* 14nm Broadwell + GT3e (Intel Iris Pro graphics) */
165 case 79: /* 14nm Broadwell Server */
166
167 case 78: /* 14nm Skylake Mobile */
168 case 94: /* 14nm Skylake Desktop */
169 if (idx == PERF_CSTATE_CORE_C3_RES ||
170 idx == PERF_CSTATE_CORE_C6_RES ||
171 idx == PERF_CSTATE_CORE_C7_RES)
172 return true;
173 break;
174 case 55: /* 22nm Atom "Silvermont" */
175 case 77: /* 22nm Atom "Silvermont Avoton/Rangely" */
176 case 76: /* 14nm Atom "Airmont" */
177 if (idx == PERF_CSTATE_CORE_C1_RES ||
178 idx == PERF_CSTATE_CORE_C6_RES)
179 return true;
180 break;
181 }
182
183 return false;
184}
185
186PMU_EVENT_ATTR_STRING(c1-residency, evattr_cstate_core_c1, "event=0x00");
187PMU_EVENT_ATTR_STRING(c3-residency, evattr_cstate_core_c3, "event=0x01");
188PMU_EVENT_ATTR_STRING(c6-residency, evattr_cstate_core_c6, "event=0x02");
189PMU_EVENT_ATTR_STRING(c7-residency, evattr_cstate_core_c7, "event=0x03");
190
191static struct perf_cstate_msr core_msr[] = {
192 [PERF_CSTATE_CORE_C1_RES] = { MSR_CORE_C1_RES, &evattr_cstate_core_c1, test_core, },
193 [PERF_CSTATE_CORE_C3_RES] = { MSR_CORE_C3_RESIDENCY, &evattr_cstate_core_c3, test_core, },
194 [PERF_CSTATE_CORE_C6_RES] = { MSR_CORE_C6_RESIDENCY, &evattr_cstate_core_c6, test_core, },
195 [PERF_CSTATE_CORE_C7_RES] = { MSR_CORE_C7_RESIDENCY, &evattr_cstate_core_c7, test_core, },
196};
197
198static struct attribute *core_events_attrs[PERF_CSTATE_CORE_EVENT_MAX + 1] = {
199 NULL,
200};
201
202static struct attribute_group core_events_attr_group = {
203 .name = "events",
204 .attrs = core_events_attrs,
205};
206
207DEFINE_CSTATE_FORMAT_ATTR(core_event, event, "config:0-63");
208static struct attribute *core_format_attrs[] = {
209 &format_attr_core_event.attr,
210 NULL,
211};
212
213static struct attribute_group core_format_attr_group = {
214 .name = "format",
215 .attrs = core_format_attrs,
216};
217
218static cpumask_t cstate_core_cpu_mask;
219static DEVICE_ATTR(cpumask, S_IRUGO, cstate_get_attr_cpumask, NULL);
220
221static struct attribute *cstate_cpumask_attrs[] = {
222 &dev_attr_cpumask.attr,
223 NULL,
224};
225
226static struct attribute_group cpumask_attr_group = {
227 .attrs = cstate_cpumask_attrs,
228};
229
230static const struct attribute_group *core_attr_groups[] = {
231 &core_events_attr_group,
232 &core_format_attr_group,
233 &cpumask_attr_group,
234 NULL,
235};
236
237/* cstate_core PMU end */
238
239
240/* cstate_pkg PMU */
241
242static struct pmu cstate_pkg_pmu;
243static bool has_cstate_pkg;
244
245enum perf_cstate_pkg_id {
246 /*
247 * cstate_pkg events
248 */
249 PERF_CSTATE_PKG_C2_RES = 0,
250 PERF_CSTATE_PKG_C3_RES,
251 PERF_CSTATE_PKG_C6_RES,
252 PERF_CSTATE_PKG_C7_RES,
253 PERF_CSTATE_PKG_C8_RES,
254 PERF_CSTATE_PKG_C9_RES,
255 PERF_CSTATE_PKG_C10_RES,
256
257 PERF_CSTATE_PKG_EVENT_MAX,
258};
259
260bool test_pkg(int idx)
261{
262 if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
263 boot_cpu_data.x86 != 6)
264 return false;
265
266 switch (boot_cpu_data.x86_model) {
267 case 30: /* 45nm Nehalem */
268 case 26: /* 45nm Nehalem-EP */
269 case 46: /* 45nm Nehalem-EX */
270
271 case 37: /* 32nm Westmere */
272 case 44: /* 32nm Westmere-EP */
273 case 47: /* 32nm Westmere-EX */
274 if (idx == PERF_CSTATE_CORE_C3_RES ||
275 idx == PERF_CSTATE_CORE_C6_RES ||
276 idx == PERF_CSTATE_CORE_C7_RES)
277 return true;
278 break;
279 case 42: /* 32nm SandyBridge */
280 case 45: /* 32nm SandyBridge-E/EN/EP */
281
282 case 58: /* 22nm IvyBridge */
283 case 62: /* 22nm IvyBridge-EP/EX */
284
285 case 60: /* 22nm Haswell Core */
286 case 63: /* 22nm Haswell Server */
287 case 70: /* 22nm Haswell + GT3e (Intel Iris Pro graphics) */
288
289 case 61: /* 14nm Broadwell Core-M */
290 case 86: /* 14nm Broadwell Xeon D */
291 case 71: /* 14nm Broadwell + GT3e (Intel Iris Pro graphics) */
292 case 79: /* 14nm Broadwell Server */
293
294 case 78: /* 14nm Skylake Mobile */
295 case 94: /* 14nm Skylake Desktop */
296 if (idx == PERF_CSTATE_PKG_C2_RES ||
297 idx == PERF_CSTATE_PKG_C3_RES ||
298 idx == PERF_CSTATE_PKG_C6_RES ||
299 idx == PERF_CSTATE_PKG_C7_RES)
300 return true;
301 break;
302 case 55: /* 22nm Atom "Silvermont" */
303 case 77: /* 22nm Atom "Silvermont Avoton/Rangely" */
304 case 76: /* 14nm Atom "Airmont" */
305 if (idx == PERF_CSTATE_CORE_C6_RES)
306 return true;
307 break;
308 case 69: /* 22nm Haswell ULT */
309 if (idx == PERF_CSTATE_PKG_C2_RES ||
310 idx == PERF_CSTATE_PKG_C3_RES ||
311 idx == PERF_CSTATE_PKG_C6_RES ||
312 idx == PERF_CSTATE_PKG_C7_RES ||
313 idx == PERF_CSTATE_PKG_C8_RES ||
314 idx == PERF_CSTATE_PKG_C9_RES ||
315 idx == PERF_CSTATE_PKG_C10_RES)
316 return true;
317 break;
318 }
319
320 return false;
321}
322
323PMU_EVENT_ATTR_STRING(c2-residency, evattr_cstate_pkg_c2, "event=0x00");
324PMU_EVENT_ATTR_STRING(c3-residency, evattr_cstate_pkg_c3, "event=0x01");
325PMU_EVENT_ATTR_STRING(c6-residency, evattr_cstate_pkg_c6, "event=0x02");
326PMU_EVENT_ATTR_STRING(c7-residency, evattr_cstate_pkg_c7, "event=0x03");
327PMU_EVENT_ATTR_STRING(c8-residency, evattr_cstate_pkg_c8, "event=0x04");
328PMU_EVENT_ATTR_STRING(c9-residency, evattr_cstate_pkg_c9, "event=0x05");
329PMU_EVENT_ATTR_STRING(c10-residency, evattr_cstate_pkg_c10, "event=0x06");
330
331static struct perf_cstate_msr pkg_msr[] = {
332 [PERF_CSTATE_PKG_C2_RES] = { MSR_PKG_C2_RESIDENCY, &evattr_cstate_pkg_c2, test_pkg, },
333 [PERF_CSTATE_PKG_C3_RES] = { MSR_PKG_C3_RESIDENCY, &evattr_cstate_pkg_c3, test_pkg, },
334 [PERF_CSTATE_PKG_C6_RES] = { MSR_PKG_C6_RESIDENCY, &evattr_cstate_pkg_c6, test_pkg, },
335 [PERF_CSTATE_PKG_C7_RES] = { MSR_PKG_C7_RESIDENCY, &evattr_cstate_pkg_c7, test_pkg, },
336 [PERF_CSTATE_PKG_C8_RES] = { MSR_PKG_C8_RESIDENCY, &evattr_cstate_pkg_c8, test_pkg, },
337 [PERF_CSTATE_PKG_C9_RES] = { MSR_PKG_C9_RESIDENCY, &evattr_cstate_pkg_c9, test_pkg, },
338 [PERF_CSTATE_PKG_C10_RES] = { MSR_PKG_C10_RESIDENCY, &evattr_cstate_pkg_c10, test_pkg, },
339};
340
341static struct attribute *pkg_events_attrs[PERF_CSTATE_PKG_EVENT_MAX + 1] = {
342 NULL,
343};
344
345static struct attribute_group pkg_events_attr_group = {
346 .name = "events",
347 .attrs = pkg_events_attrs,
348};
349
350DEFINE_CSTATE_FORMAT_ATTR(pkg_event, event, "config:0-63");
351static struct attribute *pkg_format_attrs[] = {
352 &format_attr_pkg_event.attr,
353 NULL,
354};
355static struct attribute_group pkg_format_attr_group = {
356 .name = "format",
357 .attrs = pkg_format_attrs,
358};
359
360static cpumask_t cstate_pkg_cpu_mask;
361
362static const struct attribute_group *pkg_attr_groups[] = {
363 &pkg_events_attr_group,
364 &pkg_format_attr_group,
365 &cpumask_attr_group,
366 NULL,
367};
368
369/* cstate_pkg PMU end*/
370
371static ssize_t cstate_get_attr_cpumask(struct device *dev,
372 struct device_attribute *attr,
373 char *buf)
374{
375 struct pmu *pmu = dev_get_drvdata(dev);
376
377 if (pmu == &cstate_core_pmu)
378 return cpumap_print_to_pagebuf(true, buf, &cstate_core_cpu_mask);
379 else if (pmu == &cstate_pkg_pmu)
380 return cpumap_print_to_pagebuf(true, buf, &cstate_pkg_cpu_mask);
381 else
382 return 0;
383}
384
385static int cstate_pmu_event_init(struct perf_event *event)
386{
387 u64 cfg = event->attr.config;
388 int ret = 0;
389
390 if (event->attr.type != event->pmu->type)
391 return -ENOENT;
392
393 /* unsupported modes and filters */
394 if (event->attr.exclude_user ||
395 event->attr.exclude_kernel ||
396 event->attr.exclude_hv ||
397 event->attr.exclude_idle ||
398 event->attr.exclude_host ||
399 event->attr.exclude_guest ||
400 event->attr.sample_period) /* no sampling */
401 return -EINVAL;
402
403 if (event->pmu == &cstate_core_pmu) {
404 if (cfg >= PERF_CSTATE_CORE_EVENT_MAX)
405 return -EINVAL;
406 if (!core_msr[cfg].attr)
407 return -EINVAL;
408 event->hw.event_base = core_msr[cfg].msr;
409 } else if (event->pmu == &cstate_pkg_pmu) {
410 if (cfg >= PERF_CSTATE_PKG_EVENT_MAX)
411 return -EINVAL;
412 if (!pkg_msr[cfg].attr)
413 return -EINVAL;
414 event->hw.event_base = pkg_msr[cfg].msr;
415 } else
416 return -ENOENT;
417
418 /* must be done before validate_group */
419 event->hw.config = cfg;
420 event->hw.idx = -1;
421
422 return ret;
423}
424
425static inline u64 cstate_pmu_read_counter(struct perf_event *event)
426{
427 u64 val;
428
429 rdmsrl(event->hw.event_base, val);
430 return val;
431}
432
433static void cstate_pmu_event_update(struct perf_event *event)
434{
435 struct hw_perf_event *hwc = &event->hw;
436 u64 prev_raw_count, new_raw_count;
437
438again:
439 prev_raw_count = local64_read(&hwc->prev_count);
440 new_raw_count = cstate_pmu_read_counter(event);
441
442 if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
443 new_raw_count) != prev_raw_count)
444 goto again;
445
446 local64_add(new_raw_count - prev_raw_count, &event->count);
447}
448
449static void cstate_pmu_event_start(struct perf_event *event, int mode)
450{
451 local64_set(&event->hw.prev_count, cstate_pmu_read_counter(event));
452}
453
454static void cstate_pmu_event_stop(struct perf_event *event, int mode)
455{
456 cstate_pmu_event_update(event);
457}
458
459static void cstate_pmu_event_del(struct perf_event *event, int mode)
460{
461 cstate_pmu_event_stop(event, PERF_EF_UPDATE);
462}
463
464static int cstate_pmu_event_add(struct perf_event *event, int mode)
465{
466 if (mode & PERF_EF_START)
467 cstate_pmu_event_start(event, mode);
468
469 return 0;
470}
471
472static void cstate_cpu_exit(int cpu)
473{
474 int i, id, target;
475
476 /* cpu exit for cstate core */
477 if (has_cstate_core) {
478 id = topology_core_id(cpu);
479 target = -1;
480
481 for_each_online_cpu(i) {
482 if (i == cpu)
483 continue;
484 if (id == topology_core_id(i)) {
485 target = i;
486 break;
487 }
488 }
489 if (cpumask_test_and_clear_cpu(cpu, &cstate_core_cpu_mask) && target >= 0)
490 cpumask_set_cpu(target, &cstate_core_cpu_mask);
491 WARN_ON(cpumask_empty(&cstate_core_cpu_mask));
492 if (target >= 0)
493 perf_pmu_migrate_context(&cstate_core_pmu, cpu, target);
494 }
495
496 /* cpu exit for cstate pkg */
497 if (has_cstate_pkg) {
498 id = topology_physical_package_id(cpu);
499 target = -1;
500
501 for_each_online_cpu(i) {
502 if (i == cpu)
503 continue;
504 if (id == topology_physical_package_id(i)) {
505 target = i;
506 break;
507 }
508 }
509 if (cpumask_test_and_clear_cpu(cpu, &cstate_pkg_cpu_mask) && target >= 0)
510 cpumask_set_cpu(target, &cstate_pkg_cpu_mask);
511 WARN_ON(cpumask_empty(&cstate_pkg_cpu_mask));
512 if (target >= 0)
513 perf_pmu_migrate_context(&cstate_pkg_pmu, cpu, target);
514 }
515}
516
517static void cstate_cpu_init(int cpu)
518{
519 int i, id;
520
521 /* cpu init for cstate core */
522 if (has_cstate_core) {
523 id = topology_core_id(cpu);
524 for_each_cpu(i, &cstate_core_cpu_mask) {
525 if (id == topology_core_id(i))
526 break;
527 }
528 if (i >= nr_cpu_ids)
529 cpumask_set_cpu(cpu, &cstate_core_cpu_mask);
530 }
531
532 /* cpu init for cstate pkg */
533 if (has_cstate_pkg) {
534 id = topology_physical_package_id(cpu);
535 for_each_cpu(i, &cstate_pkg_cpu_mask) {
536 if (id == topology_physical_package_id(i))
537 break;
538 }
539 if (i >= nr_cpu_ids)
540 cpumask_set_cpu(cpu, &cstate_pkg_cpu_mask);
541 }
542}
543
544static int cstate_cpu_notifier(struct notifier_block *self,
545 unsigned long action, void *hcpu)
546{
547 unsigned int cpu = (long)hcpu;
548
549 switch (action & ~CPU_TASKS_FROZEN) {
550 case CPU_UP_PREPARE:
551 break;
552 case CPU_STARTING:
553 cstate_cpu_init(cpu);
554 break;
555 case CPU_UP_CANCELED:
556 case CPU_DYING:
557 break;
558 case CPU_ONLINE:
559 case CPU_DEAD:
560 break;
561 case CPU_DOWN_PREPARE:
562 cstate_cpu_exit(cpu);
563 break;
564 default:
565 break;
566 }
567
568 return NOTIFY_OK;
569}
570
571/*
572 * Probe the cstate events and insert the available one into sysfs attrs
573 * Return false if there is no available events.
574 */
575static bool cstate_probe_msr(struct perf_cstate_msr *msr,
576 struct attribute **events_attrs,
577 int max_event_nr)
578{
579 int i, j = 0;
580 u64 val;
581
582 /* Probe the cstate events. */
583 for (i = 0; i < max_event_nr; i++) {
584 if (!msr[i].test(i) || rdmsrl_safe(msr[i].msr, &val))
585 msr[i].attr = NULL;
586 }
587
588 /* List remaining events in the sysfs attrs. */
589 for (i = 0; i < max_event_nr; i++) {
590 if (msr[i].attr)
591 events_attrs[j++] = &msr[i].attr->attr.attr;
592 }
593 events_attrs[j] = NULL;
594
595 return (j > 0) ? true : false;
596}
597
598static int __init cstate_init(void)
599{
600 /* SLM has different MSR for PKG C6 */
601 switch (boot_cpu_data.x86_model) {
602 case 55:
603 case 76:
604 case 77:
605 pkg_msr[PERF_CSTATE_PKG_C6_RES].msr = MSR_PKG_C7_RESIDENCY;
606 }
607
608 if (cstate_probe_msr(core_msr, core_events_attrs, PERF_CSTATE_CORE_EVENT_MAX))
609 has_cstate_core = true;
610
611 if (cstate_probe_msr(pkg_msr, pkg_events_attrs, PERF_CSTATE_PKG_EVENT_MAX))
612 has_cstate_pkg = true;
613
614 return (has_cstate_core || has_cstate_pkg) ? 0 : -ENODEV;
615}
616
617static void __init cstate_cpumask_init(void)
618{
619 int cpu;
620
621 cpu_notifier_register_begin();
622
623 for_each_online_cpu(cpu)
624 cstate_cpu_init(cpu);
625
626 __perf_cpu_notifier(cstate_cpu_notifier);
627
628 cpu_notifier_register_done();
629}
630
631static struct pmu cstate_core_pmu = {
632 .attr_groups = core_attr_groups,
633 .name = "cstate_core",
634 .task_ctx_nr = perf_invalid_context,
635 .event_init = cstate_pmu_event_init,
636 .add = cstate_pmu_event_add, /* must have */
637 .del = cstate_pmu_event_del, /* must have */
638 .start = cstate_pmu_event_start,
639 .stop = cstate_pmu_event_stop,
640 .read = cstate_pmu_event_update,
641 .capabilities = PERF_PMU_CAP_NO_INTERRUPT,
642};
643
644static struct pmu cstate_pkg_pmu = {
645 .attr_groups = pkg_attr_groups,
646 .name = "cstate_pkg",
647 .task_ctx_nr = perf_invalid_context,
648 .event_init = cstate_pmu_event_init,
649 .add = cstate_pmu_event_add, /* must have */
650 .del = cstate_pmu_event_del, /* must have */
651 .start = cstate_pmu_event_start,
652 .stop = cstate_pmu_event_stop,
653 .read = cstate_pmu_event_update,
654 .capabilities = PERF_PMU_CAP_NO_INTERRUPT,
655};
656
657static void __init cstate_pmus_register(void)
658{
659 int err;
660
661 if (has_cstate_core) {
662 err = perf_pmu_register(&cstate_core_pmu, cstate_core_pmu.name, -1);
663 if (WARN_ON(err))
664 pr_info("Failed to register PMU %s error %d\n",
665 cstate_core_pmu.name, err);
666 }
667
668 if (has_cstate_pkg) {
669 err = perf_pmu_register(&cstate_pkg_pmu, cstate_pkg_pmu.name, -1);
670 if (WARN_ON(err))
671 pr_info("Failed to register PMU %s error %d\n",
672 cstate_pkg_pmu.name, err);
673 }
674}
675
676static int __init cstate_pmu_init(void)
677{
678 int err;
679
680 if (cpu_has_hypervisor)
681 return -ENODEV;
682
683 err = cstate_init();
684 if (err)
685 return err;
686
687 cstate_cpumask_init();
688
689 cstate_pmus_register();
690
691 return 0;
692}
693
694device_initcall(cstate_pmu_init);
arch/x86/kernel/cpu/perf_event_intel_ds.c+34−6
@@ -510,10 +510,11 @@ int intel_pmu_drain_bts_buffer(void) · 509 unmodified lines
510 u64 flags;510 u64 flags;
511 };511 };
512 struct perf_event *event = cpuc->events[INTEL_PMC_IDX_FIXED_BTS];512 struct perf_event *event = cpuc->events[INTEL_PMC_IDX_FIXED_BTS];
513 struct bts_record *at, *top;513 struct bts_record *at, *base, *top;
514 struct perf_output_handle handle;514 struct perf_output_handle handle;
515 struct perf_event_header header;515 struct perf_event_header header;
516 struct perf_sample_data data;516 struct perf_sample_data data;
517 unsigned long skip = 0;
517 struct pt_regs regs;518 struct pt_regs regs;
518 519
519 if (!event)520 if (!event)
@@ -522,10 +523,10 @@ int intel_pmu_drain_bts_buffer(void) · 2 unmodified lines
522 if (!x86_pmu.bts_active)523 if (!x86_pmu.bts_active)
523 return 0;524 return 0;
524 525
525 at = (struct bts_record *)(unsigned long)ds->bts_buffer_base;526 base = (struct bts_record *)(unsigned long)ds->bts_buffer_base;
526 top = (struct bts_record *)(unsigned long)ds->bts_index;527 top = (struct bts_record *)(unsigned long)ds->bts_index;
527 528
528 if (top <= at)529 if (top <= base)
529 return 0;530 return 0;
530 531
531 memset(&regs, 0, sizeof(regs));532 memset(&regs, 0, sizeof(regs));
@@ -534,6 +535,27 @@ int intel_pmu_drain_bts_buffer(void) · 2 unmodified lines
534 535
535 perf_sample_data_init(&data, 0, event->hw.last_period);536 perf_sample_data_init(&data, 0, event->hw.last_period);
536 537
538 /*
539 * BTS leaks kernel addresses in branches across the cpl boundary,
540 * such as traps or system calls, so unless the user is asking for
541 * kernel tracing (and right now it's not possible), we'd need to
542 * filter them out. But first we need to count how many of those we
543 * have in the current batch. This is an extra O(n) pass, however,
544 * it's much faster than the other one especially considering that
545 * n <= 2560 (BTS_BUFFER_SIZE / BTS_RECORD_SIZE * 15/16; see the
546 * alloc_bts_buffer()).
547 */
548 for (at = base; at < top; at++) {
549 /*
550 * Note that right now *this* BTS code only works if
551 * attr::exclude_kernel is set, but let's keep this extra
552 * check here in case that changes.
553 */
554 if (event->attr.exclude_kernel &&
555 (kernel_ip(at->from) || kernel_ip(at->to)))
556 skip++;
557 }
558
537 /*559 /*
538 * Prepare a generic sample, i.e. fill in the invariant fields.560 * Prepare a generic sample, i.e. fill in the invariant fields.
539 * We will overwrite the from and to address before we output561 * We will overwrite the from and to address before we output
@@ -541,10 +563,16 @@ int intel_pmu_drain_bts_buffer(void) · 1 unmodified line
541 */563 */
542 perf_prepare_sample(&header, &data, event, &regs);564 perf_prepare_sample(&header, &data, event, &regs);
543 565
544 if (perf_output_begin(&handle, event, header.size * (top - at)))566 if (perf_output_begin(&handle, event, header.size *
567 (top - base - skip)))
545 return 1;568 return 1;
546 569
547 for (; at < top; at++) {570 for (at = base; at < top; at++) {
571 /* Filter out any records that contain kernel addresses. */
572 if (event->attr.exclude_kernel &&
573 (kernel_ip(at->from) || kernel_ip(at->to)))
574 continue;
575
548 data.ip = at->from;576 data.ip = at->from;
549 data.addr = at->to;577 data.addr = at->to;
550 578
arch/x86/kernel/cpu/perf_event_intel_lbr.c+6−2
@@ -151,10 +151,10 @@ static void __intel_pmu_lbr_enable(bool pmi) · 150 unmodified lines
151 * No need to reprogram LBR_SELECT in a PMI, as it151 * No need to reprogram LBR_SELECT in a PMI, as it
152 * did not change.152 * did not change.
153 */153 */
154 if (cpuc->lbr_sel && !pmi) {154 if (cpuc->lbr_sel)
155 lbr_select = cpuc->lbr_sel->config;155 lbr_select = cpuc->lbr_sel->config;
156 if (!pmi)
156 wrmsrl(MSR_LBR_SELECT, lbr_select);157 wrmsrl(MSR_LBR_SELECT, lbr_select);
157 }
158 158
159 rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);159 rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
160 orig_debugctl = debugctl;160 orig_debugctl = debugctl;
@@ -555,6 +555,8 @@ static int intel_pmu_setup_sw_lbr_filter(struct perf_event *event) · 394 unmodified lines
555 if (br_type & PERF_SAMPLE_BRANCH_IND_JUMP)555 if (br_type & PERF_SAMPLE_BRANCH_IND_JUMP)
556 mask |= X86_BR_IND_JMP;556 mask |= X86_BR_IND_JMP;
557 557
558 if (br_type & PERF_SAMPLE_BRANCH_CALL)
559 mask |= X86_BR_CALL | X86_BR_ZERO_CALL;
558 /*560 /*
559 * stash actual user request into reg, it may561 * stash actual user request into reg, it may
560 * be used by fixup code for some CPU562 * be used by fixup code for some CPU
@@ -890,6 +892,7 @@ static const int snb_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX_SHIFT] = { · 329 unmodified lines
890 [PERF_SAMPLE_BRANCH_IND_CALL_SHIFT] = LBR_IND_CALL,892 [PERF_SAMPLE_BRANCH_IND_CALL_SHIFT] = LBR_IND_CALL,
891 [PERF_SAMPLE_BRANCH_COND_SHIFT] = LBR_JCC,893 [PERF_SAMPLE_BRANCH_COND_SHIFT] = LBR_JCC,
892 [PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT] = LBR_IND_JMP,894 [PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT] = LBR_IND_JMP,
895 [PERF_SAMPLE_BRANCH_CALL_SHIFT] = LBR_REL_CALL,
893};896};
894 897
895static const int hsw_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX_SHIFT] = {898static const int hsw_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX_SHIFT] = {
@@ -905,6 +908,7 @@ static const int hsw_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX_SHIFT] = { · 9 unmodified lines
905 [PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT] = LBR_REL_CALL | LBR_IND_CALL908 [PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT] = LBR_REL_CALL | LBR_IND_CALL
906 | LBR_RETURN | LBR_CALL_STACK,909 | LBR_RETURN | LBR_CALL_STACK,
907 [PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT] = LBR_IND_JMP,910 [PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT] = LBR_IND_JMP,
911 [PERF_SAMPLE_BRANCH_CALL_SHIFT] = LBR_REL_CALL,
908};912};
909 913
910/* core */914/* core */
arch/x86/kernel/cpu/perf_event_intel_pt.c+4−3
@@ -139,9 +139,6 @@ static int __init pt_pmu_hw_init(void) · 138 unmodified lines
139 long i;139 long i;
140 140
141 attrs = NULL;141 attrs = NULL;
142 ret = -ENODEV;
143 if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT))
144 goto fail;
145 142
146 for (i = 0; i < PT_CPUID_LEAVES; i++) {143 for (i = 0; i < PT_CPUID_LEAVES; i++) {
147 cpuid_count(20, i,144 cpuid_count(20, i,
@@ -1130,6 +1127,10 @@ static __init int pt_init(void) · 982 unmodified lines
1130 int ret, cpu, prior_warn = 0;1127 int ret, cpu, prior_warn = 0;
1131 1128
1132 BUILD_BUG_ON(sizeof(struct topa) > PAGE_SIZE);1129 BUILD_BUG_ON(sizeof(struct topa) > PAGE_SIZE);
1130
1131 if (!test_cpu_cap(&boot_cpu_data, X86_FEATURE_INTEL_PT))
1132 return -ENODEV;
1133
1133 get_online_cpus();1134 get_online_cpus();
1134 for_each_online_cpu(cpu) {1135 for_each_online_cpu(cpu) {
1135 u64 ctl;1136 u64 ctl;
arch/x86/kernel/cpu/perf_event_intel_uncore.c+58−3
@@ -7,7 +7,8 @@ struct intel_uncore_type **uncore_pci_uncores = empty_uncore; · 6 unmodified lines
7static bool pcidrv_registered;7static bool pcidrv_registered;
8struct pci_driver *uncore_pci_driver;8struct pci_driver *uncore_pci_driver;
9/* pci bus to socket mapping */9/* pci bus to socket mapping */
10int uncore_pcibus_to_physid[256] = { [0 ... 255] = -1, };10DEFINE_RAW_SPINLOCK(pci2phy_map_lock);
11struct list_head pci2phy_map_head = LIST_HEAD_INIT(pci2phy_map_head);
11struct pci_dev *uncore_extra_pci_dev[UNCORE_SOCKET_MAX][UNCORE_EXTRA_PCI_DEV_MAX];12struct pci_dev *uncore_extra_pci_dev[UNCORE_SOCKET_MAX][UNCORE_EXTRA_PCI_DEV_MAX];
12 13
13static DEFINE_RAW_SPINLOCK(uncore_box_lock);14static DEFINE_RAW_SPINLOCK(uncore_box_lock);
@@ -20,6 +21,59 @@ static struct event_constraint uncore_constraint_fixed = · 6 unmodified lines
20struct event_constraint uncore_constraint_empty =21struct event_constraint uncore_constraint_empty =
21 EVENT_CONSTRAINT(0, 0, 0);22 EVENT_CONSTRAINT(0, 0, 0);
22 23
24int uncore_pcibus_to_physid(struct pci_bus *bus)
25{
26 struct pci2phy_map *map;
27 int phys_id = -1;
28
29 raw_spin_lock(&pci2phy_map_lock);
30 list_for_each_entry(map, &pci2phy_map_head, list) {
31 if (map->segment == pci_domain_nr(bus)) {
32 phys_id = map->pbus_to_physid[bus->number];
33 break;
34 }
35 }
36 raw_spin_unlock(&pci2phy_map_lock);
37
38 return phys_id;
39}
40
41struct pci2phy_map *__find_pci2phy_map(int segment)
42{
43 struct pci2phy_map *map, *alloc = NULL;
44 int i;
45
46 lockdep_assert_held(&pci2phy_map_lock);
47
48lookup:
49 list_for_each_entry(map, &pci2phy_map_head, list) {
50 if (map->segment == segment)
51 goto end;
52 }
53
54 if (!alloc) {
55 raw_spin_unlock(&pci2phy_map_lock);
56 alloc = kmalloc(sizeof(struct pci2phy_map), GFP_KERNEL);
57 raw_spin_lock(&pci2phy_map_lock);
58
59 if (!alloc)
60 return NULL;
61
62 goto lookup;
63 }
64
65 map = alloc;
66 alloc = NULL;
67 map->segment = segment;
68 for (i = 0; i < 256; i++)
69 map->pbus_to_physid[i] = -1;
70 list_add_tail(&map->list, &pci2phy_map_head);
71
72end:
73 kfree(alloc);
74 return map;
75}
76
23ssize_t uncore_event_show(struct kobject *kobj,77ssize_t uncore_event_show(struct kobject *kobj,
24 struct kobj_attribute *attr, char *buf)78 struct kobj_attribute *attr, char *buf)
25{79{
@@ -809,7 +863,7 @@ static int uncore_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id · 783 unmodified lines
809 int phys_id;863 int phys_id;
810 bool first_box = false;864 bool first_box = false;
811 865
812 phys_id = uncore_pcibus_to_physid[pdev->bus->number];866 phys_id = uncore_pcibus_to_physid(pdev->bus);
813 if (phys_id < 0)867 if (phys_id < 0)
814 return -ENODEV;868 return -ENODEV;
815 869
@@ -856,9 +910,10 @@ static void uncore_pci_remove(struct pci_dev *pdev) · 40 unmodified lines
856{910{
857 struct intel_uncore_box *box = pci_get_drvdata(pdev);911 struct intel_uncore_box *box = pci_get_drvdata(pdev);
858 struct intel_uncore_pmu *pmu;912 struct intel_uncore_pmu *pmu;
859 int i, cpu, phys_id = uncore_pcibus_to_physid[pdev->bus->number];913 int i, cpu, phys_id;
860 bool last_box = false;914 bool last_box = false;
861 915
916 phys_id = uncore_pcibus_to_physid(pdev->bus);
862 box = pci_get_drvdata(pdev);917 box = pci_get_drvdata(pdev);
863 if (!box) {918 if (!box) {
864 for (i = 0; i < UNCORE_EXTRA_PCI_DEV_MAX; i++) {919 for (i = 0; i < UNCORE_EXTRA_PCI_DEV_MAX; i++) {
arch/x86/kernel/cpu/perf_event_intel_uncore.h+11−1
@@ -117,6 +117,15 @@ struct uncore_event_desc { · 116 unmodified lines
117 const char *config;117 const char *config;
118};118};
119 119
120struct pci2phy_map {
121 struct list_head list;
122 int segment;
123 int pbus_to_physid[256];
124};
125
126int uncore_pcibus_to_physid(struct pci_bus *bus);
127struct pci2phy_map *__find_pci2phy_map(int segment);
128
120ssize_t uncore_event_show(struct kobject *kobj,129ssize_t uncore_event_show(struct kobject *kobj,
121 struct kobj_attribute *attr, char *buf);130 struct kobj_attribute *attr, char *buf);
122 131
@@ -317,7 +326,8 @@ u64 uncore_shared_reg_config(struct intel_uncore_box *box, int idx); · 194 unmodified lines
317extern struct intel_uncore_type **uncore_msr_uncores;326extern struct intel_uncore_type **uncore_msr_uncores;
318extern struct intel_uncore_type **uncore_pci_uncores;327extern struct intel_uncore_type **uncore_pci_uncores;
319extern struct pci_driver *uncore_pci_driver;328extern struct pci_driver *uncore_pci_driver;
320extern int uncore_pcibus_to_physid[256];329extern raw_spinlock_t pci2phy_map_lock;
330extern struct list_head pci2phy_map_head;
321extern struct pci_dev *uncore_extra_pci_dev[UNCORE_SOCKET_MAX][UNCORE_EXTRA_PCI_DEV_MAX];331extern struct pci_dev *uncore_extra_pci_dev[UNCORE_SOCKET_MAX][UNCORE_EXTRA_PCI_DEV_MAX];
322extern struct event_constraint uncore_constraint_empty;332extern struct event_constraint uncore_constraint_empty;
323 333
arch/x86/kernel/cpu/perf_event_intel_uncore_snb.c+13−3
@@ -420,15 +420,25 @@ static void snb_uncore_imc_event_del(struct perf_event *event, int flags) · 419 unmodified lines
420static int snb_pci2phy_map_init(int devid)420static int snb_pci2phy_map_init(int devid)
421{421{
422 struct pci_dev *dev = NULL;422 struct pci_dev *dev = NULL;
423 int bus;423 struct pci2phy_map *map;
424 int bus, segment;
424 425
425 dev = pci_get_device(PCI_VENDOR_ID_INTEL, devid, dev);426 dev = pci_get_device(PCI_VENDOR_ID_INTEL, devid, dev);
426 if (!dev)427 if (!dev)
427 return -ENOTTY;428 return -ENOTTY;
428 429
429 bus = dev->bus->number;430 bus = dev->bus->number;
430 431 segment = pci_domain_nr(dev->bus);
431 uncore_pcibus_to_physid[bus] = 0;432
433 raw_spin_lock(&pci2phy_map_lock);
434 map = __find_pci2phy_map(segment);
435 if (!map) {
436 raw_spin_unlock(&pci2phy_map_lock);
437 pci_dev_put(dev);
438 return -ENOMEM;
439 }
440 map->pbus_to_physid[bus] = 0;
441 raw_spin_unlock(&pci2phy_map_lock);
432 442
433 pci_dev_put(dev);443 pci_dev_put(dev);
434 444
arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c+25−9
@@ -1087,7 +1087,8 @@ static struct pci_driver snbep_uncore_pci_driver = { · 1086 unmodified lines
1087static int snbep_pci2phy_map_init(int devid)1087static int snbep_pci2phy_map_init(int devid)
1088{1088{
1089 struct pci_dev *ubox_dev = NULL;1089 struct pci_dev *ubox_dev = NULL;
1090 int i, bus, nodeid;1090 int i, bus, nodeid, segment;
1091 struct pci2phy_map *map;
1091 int err = 0;1092 int err = 0;
1092 u32 config = 0;1093 u32 config = 0;
1093 1094
@@ -1106,16 +1107,27 @@ static int snbep_pci2phy_map_init(int devid) · 12 unmodified lines
1106 err = pci_read_config_dword(ubox_dev, 0x54, &config);1107 err = pci_read_config_dword(ubox_dev, 0x54, &config);
1107 if (err)1108 if (err)
1108 break;1109 break;
1110
1111 segment = pci_domain_nr(ubox_dev->bus);
1112 raw_spin_lock(&pci2phy_map_lock);
1113 map = __find_pci2phy_map(segment);
1114 if (!map) {
1115 raw_spin_unlock(&pci2phy_map_lock);
1116 err = -ENOMEM;
1117 break;
1118 }
1119
1109 /*1120 /*
1110 * every three bits in the Node ID mapping register maps1121 * every three bits in the Node ID mapping register maps
1111 * to a particular node.1122 * to a particular node.
1112 */1123 */
1113 for (i = 0; i < 8; i++) {1124 for (i = 0; i < 8; i++) {
1114 if (nodeid == ((config >> (3 * i)) & 0x7)) {1125 if (nodeid == ((config >> (3 * i)) & 0x7)) {
1115 uncore_pcibus_to_physid[bus] = i;1126 map->pbus_to_physid[bus] = i;
1116 break;1127 break;
1117 }1128 }
1118 }1129 }
1130 raw_spin_unlock(&pci2phy_map_lock);
1119 }1131 }
1120 1132
1121 if (!err) {1133 if (!err) {
@@ -1123,13 +1135,17 @@ static int snbep_pci2phy_map_init(int devid) · 1 unmodified line
1123 * For PCI bus with no UBOX device, find the next bus1135 * For PCI bus with no UBOX device, find the next bus
1124 * that has UBOX device and use its mapping.1136 * that has UBOX device and use its mapping.
1125 */1137 */
1126 i = -1;1138 raw_spin_lock(&pci2phy_map_lock);
1127 for (bus = 255; bus >= 0; bus--) {1139 list_for_each_entry(map, &pci2phy_map_head, list) {
1128 if (uncore_pcibus_to_physid[bus] >= 0)1140 i = -1;
1129 i = uncore_pcibus_to_physid[bus];1141 for (bus = 255; bus >= 0; bus--) {
1130 else1142 if (map->pbus_to_physid[bus] >= 0)
1131 uncore_pcibus_to_physid[bus] = i;1143 i = map->pbus_to_physid[bus];
1144 else
1145 map->pbus_to_physid[bus] = i;
1146 }
1132 }1147 }
1148 raw_spin_unlock(&pci2phy_map_lock);
1133 }1149 }
1134 1150
1135 pci_dev_put(ubox_dev);1151 pci_dev_put(ubox_dev);
@@ -2444,7 +2460,7 @@ static struct intel_uncore_type *bdx_pci_uncores[] = { · 1308 unmodified lines
2444 NULL,2460 NULL,
2445};2461};
2446 2462
2447static DEFINE_PCI_DEVICE_TABLE(bdx_uncore_pci_ids) = {2463static const struct pci_device_id bdx_uncore_pci_ids[] = {
2448 { /* Home Agent 0 */2464 { /* Home Agent 0 */
2449 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x6f30),2465 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x6f30),
2450 .driver_data = UNCORE_PCI_DEV_DATA(BDX_PCI_UNCORE_HA, 0),2466 .driver_data = UNCORE_PCI_DEV_DATA(BDX_PCI_UNCORE_HA, 0),
arch/x86/kernel/tsc.c+22−13
@@ -168,21 +168,20 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data) · 167 unmodified lines
168 * ns = cycles * cyc2ns_scale / SC168 * ns = cycles * cyc2ns_scale / SC
169 *169 *
170 * And since SC is a constant power of two, we can convert the div170 * And since SC is a constant power of two, we can convert the div
171 * into a shift.171 * into a shift. The larger SC is, the more accurate the conversion, but
172 * cyc2ns_scale needs to be a 32-bit value so that 32-bit multiplication
173 * (64-bit result) can be used.
172 *174 *
173 * We can use khz divisor instead of mhz to keep a better precision, since175 * We can use khz divisor instead of mhz to keep a better precision.
174 * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
175 * (mathieu.desnoyers@polymtl.ca)176 * (mathieu.desnoyers@polymtl.ca)
176 *177 *
177 * -johnstul@us.ibm.com "math is hard, lets go shopping!"178 * -johnstul@us.ibm.com "math is hard, lets go shopping!"
178 */179 */
179 180
180#define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */
181
182static void cyc2ns_data_init(struct cyc2ns_data *data)181static void cyc2ns_data_init(struct cyc2ns_data *data)
183{182{
184 data->cyc2ns_mul = 0;183 data->cyc2ns_mul = 0;
185 data->cyc2ns_shift = CYC2NS_SCALE_FACTOR;184 data->cyc2ns_shift = 0;
186 data->cyc2ns_offset = 0;185 data->cyc2ns_offset = 0;
187 data->__count = 0;186 data->__count = 0;
188}187}
@@ -216,14 +215,14 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc) · 27 unmodified lines
216 215
217 if (likely(data == tail)) {216 if (likely(data == tail)) {
218 ns = data->cyc2ns_offset;217 ns = data->cyc2ns_offset;
219 ns += mul_u64_u32_shr(cyc, data->cyc2ns_mul, CYC2NS_SCALE_FACTOR);218 ns += mul_u64_u32_shr(cyc, data->cyc2ns_mul, data->cyc2ns_shift);
220 } else {219 } else {
221 data->__count++;220 data->__count++;
222 221
223 barrier();222 barrier();
224 223
225 ns = data->cyc2ns_offset;224 ns = data->cyc2ns_offset;
226 ns += mul_u64_u32_shr(cyc, data->cyc2ns_mul, CYC2NS_SCALE_FACTOR);225 ns += mul_u64_u32_shr(cyc, data->cyc2ns_mul, data->cyc2ns_shift);
227 226
228 barrier();227 barrier();
229 228
@@ -257,12 +256,22 @@ static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu) · 27 unmodified lines
257 * time function is continuous; see the comment near struct256 * time function is continuous; see the comment near struct
258 * cyc2ns_data.257 * cyc2ns_data.
259 */258 */
260 data->cyc2ns_mul =259 clocks_calc_mult_shift(&data->cyc2ns_mul, &data->cyc2ns_shift, cpu_khz,
261 DIV_ROUND_CLOSEST(NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR,260 NSEC_PER_MSEC, 0);
262 cpu_khz);261
263 data->cyc2ns_shift = CYC2NS_SCALE_FACTOR;262 /*
263 * cyc2ns_shift is exported via arch_perf_update_userpage() where it is
264 * not expected to be greater than 31 due to the original published
265 * conversion algorithm shifting a 32-bit value (now specifies a 64-bit
266 * value) - refer perf_event_mmap_page documentation in perf_event.h.
267 */
268 if (data->cyc2ns_shift == 32) {
269 data->cyc2ns_shift = 31;
270 data->cyc2ns_mul >>= 1;
271 }
272
264 data->cyc2ns_offset = ns_now -273 data->cyc2ns_offset = ns_now -
265 mul_u64_u32_shr(tsc_now, data->cyc2ns_mul, CYC2NS_SCALE_FACTOR);274 mul_u64_u32_shr(tsc_now, data->cyc2ns_mul, data->cyc2ns_shift);
266 275
267 cyc2ns_write_end(cpu, data);276 cyc2ns_write_end(cpu, data);
268 277
arch/x86/lib/x86-opcode-map.txt+19−5
@@ -353,8 +353,12 @@ AVXcode: 1 · 352 unmodified lines
35317: vmovhps Mq,Vq (v1) | vmovhpd Mq,Vq (66),(v1)35317: vmovhps Mq,Vq (v1) | vmovhpd Mq,Vq (66),(v1)
35418: Grp16 (1A)35418: Grp16 (1A)
35519:35519:
3561a: BNDCL Ev,Gv | BNDCU Ev,Gv | BNDMOV Gv,Ev | BNDLDX Gv,Ev,Gv356# Intel SDM opcode map does not list MPX instructions. For now using Gv for
3571b: BNDCN Ev,Gv | BNDMOV Ev,Gv | BNDMK Gv,Ev | BNDSTX Ev,GV,Gv357# bnd registers and Ev for everything else is OK because the instruction
358# decoder does not use the information except as an indication that there is
359# a ModR/M byte.
3601a: BNDCL Gv,Ev (F3) | BNDCU Gv,Ev (F2) | BNDMOV Gv,Ev (66) | BNDLDX Gv,Ev
3611b: BNDCN Gv,Ev (F2) | BNDMOV Ev,Gv (66) | BNDMK Gv,Ev (F3) | BNDSTX Ev,Gv
3581c:3621c:
3591d:3631d:
3601e:3641e:
@@ -732,6 +736,12 @@ bd: vfnmadd231ss/d Vx,Hx,Wx (66),(v),(v1) · 371 unmodified lines
732be: vfnmsub231ps/d Vx,Hx,Wx (66),(v)736be: vfnmsub231ps/d Vx,Hx,Wx (66),(v)
733bf: vfnmsub231ss/d Vx,Hx,Wx (66),(v),(v1)737bf: vfnmsub231ss/d Vx,Hx,Wx (66),(v),(v1)
734# 0x0f 0x38 0xc0-0xff738# 0x0f 0x38 0xc0-0xff
739c8: sha1nexte Vdq,Wdq
740c9: sha1msg1 Vdq,Wdq
741ca: sha1msg2 Vdq,Wdq
742cb: sha256rnds2 Vdq,Wdq
743cc: sha256msg1 Vdq,Wdq
744cd: sha256msg2 Vdq,Wdq
735db: VAESIMC Vdq,Wdq (66),(v1)745db: VAESIMC Vdq,Wdq (66),(v1)
736dc: VAESENC Vdq,Hdq,Wdq (66),(v1)746dc: VAESENC Vdq,Hdq,Wdq (66),(v1)
737dd: VAESENCLAST Vdq,Hdq,Wdq (66),(v1)747dd: VAESENCLAST Vdq,Hdq,Wdq (66),(v1)
@@ -790,6 +800,7 @@ AVXcode: 3 · 52 unmodified lines
79061: vpcmpestri Vdq,Wdq,Ib (66),(v1)80061: vpcmpestri Vdq,Wdq,Ib (66),(v1)
79162: vpcmpistrm Vdq,Wdq,Ib (66),(v1)80162: vpcmpistrm Vdq,Wdq,Ib (66),(v1)
79263: vpcmpistri Vdq,Wdq,Ib (66),(v1)80263: vpcmpistri Vdq,Wdq,Ib (66),(v1)
803cc: sha1rnds4 Vdq,Wdq,Ib
793df: VAESKEYGEN Vdq,Wdq,Ib (66),(v1)804df: VAESKEYGEN Vdq,Wdq,Ib (66),(v1)
794f0: RORX Gy,Ey,Ib (F2),(v)805f0: RORX Gy,Ey,Ib (F2),(v)
795EndTable806EndTable
@@ -874,7 +885,7 @@ GrpTable: Grp7 · 78 unmodified lines
8742: LGDT Ms | XGETBV (000),(11B) | XSETBV (001),(11B) | VMFUNC (100),(11B) | XEND (101)(11B) | XTEST (110)(11B)8852: LGDT Ms | XGETBV (000),(11B) | XSETBV (001),(11B) | VMFUNC (100),(11B) | XEND (101)(11B) | XTEST (110)(11B)
8753: LIDT Ms8863: LIDT Ms
8764: SMSW Mw/Rv8874: SMSW Mw/Rv
8775:8885: rdpkru (110),(11B) | wrpkru (111),(11B)
8786: LMSW Ew8896: LMSW Ew
8797: INVLPG Mb | SWAPGS (o64),(000),(11B) | RDTSCP (001),(11B)8907: INVLPG Mb | SWAPGS (o64),(000),(11B) | RDTSCP (001),(11B)
880EndTable891EndTable
@@ -888,6 +899,9 @@ EndTable · 7 unmodified lines
888 899
889GrpTable: Grp9900GrpTable: Grp9
8901: CMPXCHG8B/16B Mq/Mdq9011: CMPXCHG8B/16B Mq/Mdq
9023: xrstors
9034: xsavec
9045: xsaves
8916: VMPTRLD Mq | VMCLEAR Mq (66) | VMXON Mq (F3) | RDRAND Rv (11B)9056: VMPTRLD Mq | VMCLEAR Mq (66) | VMXON Mq (F3) | RDRAND Rv (11B)
8927: VMPTRST Mq | VMPTRST Mq (F3) | RDSEED Rv (11B)9067: VMPTRST Mq | VMPTRST Mq (F3) | RDSEED Rv (11B)
893EndTable907EndTable
@@ -932,8 +946,8 @@ GrpTable: Grp15 · 38 unmodified lines
9323: vstmxcsr Md (v1) | WRGSBASE Ry (F3),(11B)9463: vstmxcsr Md (v1) | WRGSBASE Ry (F3),(11B)
9334: XSAVE9474: XSAVE
9345: XRSTOR | lfence (11B)9485: XRSTOR | lfence (11B)
9356: XSAVEOPT | mfence (11B)9496: XSAVEOPT | clwb (66) | mfence (11B)
9367: clflush | sfence (11B)9507: clflush | clflushopt (66) | sfence (11B) | pcommit (66),(11B)
937EndTable951EndTable
938 952
939GrpTable: Grp16953GrpTable: Grp16
include/linux/perf_event.h+103−17
@@ -140,33 +140,67 @@ struct hw_perf_event { · 139 unmodified lines
140 };140 };
141#endif141#endif
142 };142 };
143 /*
144 * If the event is a per task event, this will point to the task in
145 * question. See the comment in perf_event_alloc().
146 */
143 struct task_struct *target;147 struct task_struct *target;
148
149/*
150 * hw_perf_event::state flags; used to track the PERF_EF_* state.
151 */
152#define PERF_HES_STOPPED 0x01 /* the counter is stopped */
153#define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
154#define PERF_HES_ARCH 0x04
155
144 int state;156 int state;
157
158 /*
159 * The last observed hardware counter value, updated with a
160 * local64_cmpxchg() such that pmu::read() can be called nested.
161 */
145 local64_t prev_count;162 local64_t prev_count;
163
164 /*
165 * The period to start the next sample with.
166 */
146 u64 sample_period;167 u64 sample_period;
168
169 /*
170 * The period we started this sample with.
171 */
147 u64 last_period;172 u64 last_period;
173
174 /*
175 * However much is left of the current period; note that this is
176 * a full 64bit value and allows for generation of periods longer
177 * than hardware might allow.
178 */
148 local64_t period_left;179 local64_t period_left;
180
181 /*
182 * State for throttling the event, see __perf_event_overflow() and
183 * perf_adjust_freq_unthr_context().
184 */
149 u64 interrupts_seq;185 u64 interrupts_seq;
150 u64 interrupts;186 u64 interrupts;
151 187
188 /*
189 * State for freq target events, see __perf_event_overflow() and
190 * perf_adjust_freq_unthr_context().
191 */
152 u64 freq_time_stamp;192 u64 freq_time_stamp;
153 u64 freq_count_stamp;193 u64 freq_count_stamp;
154#endif194#endif
155};195};
156 196
157/*
158 * hw_perf_event::state flags
159 */
160#define PERF_HES_STOPPED 0x01 /* the counter is stopped */
161#define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
162#define PERF_HES_ARCH 0x04
163
164struct perf_event;197struct perf_event;
165 198
166/*199/*
167 * Common implementation detail of pmu::{start,commit,cancel}_txn200 * Common implementation detail of pmu::{start,commit,cancel}_txn
168 */201 */
169#define PERF_EVENT_TXN 0x1202#define PERF_PMU_TXN_ADD 0x1 /* txn to add/schedule event on PMU */
203#define PERF_PMU_TXN_READ 0x2 /* txn to read event group from PMU */
170 204
171/**205/**
172 * pmu::capabilities flags206 * pmu::capabilities flags
@@ -210,7 +244,19 @@ struct pmu { · 37 unmodified lines
210 244
211 /*245 /*
212 * Try and initialize the event for this PMU.246 * Try and initialize the event for this PMU.
213 * Should return -ENOENT when the @event doesn't match this PMU.247 *
248 * Returns:
249 * -ENOENT -- @event is not for this PMU
250 *
251 * -ENODEV -- @event is for this PMU but PMU not present
252 * -EBUSY -- @event is for this PMU but PMU temporarily unavailable
253 * -EINVAL -- @event is for this PMU but @event is not valid
254 * -EOPNOTSUPP -- @event is for this PMU, @event is valid, but not supported
255 * -EACCESS -- @event is for this PMU, @event is valid, but no privilidges
256 *
257 * 0 -- @event is for this PMU and valid
258 *
259 * Other error return values are allowed.
214 */260 */
215 int (*event_init) (struct perf_event *event);261 int (*event_init) (struct perf_event *event);
216 262
@@ -221,27 +267,61 @@ struct pmu { · 4 unmodified lines
221 void (*event_mapped) (struct perf_event *event); /*optional*/267 void (*event_mapped) (struct perf_event *event); /*optional*/
222 void (*event_unmapped) (struct perf_event *event); /*optional*/268 void (*event_unmapped) (struct perf_event *event); /*optional*/
223 269
270 /*
271 * Flags for ->add()/->del()/ ->start()/->stop(). There are
272 * matching hw_perf_event::state flags.
273 */
224#define PERF_EF_START 0x01 /* start the counter when adding */274#define PERF_EF_START 0x01 /* start the counter when adding */
225#define PERF_EF_RELOAD 0x02 /* reload the counter when starting */275#define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
226#define PERF_EF_UPDATE 0x04 /* update the counter when stopping */276#define PERF_EF_UPDATE 0x04 /* update the counter when stopping */
227 277
228 /*278 /*
229 * Adds/Removes a counter to/from the PMU, can be done inside279 * Adds/Removes a counter to/from the PMU, can be done inside a
230 * a transaction, see the ->*_txn() methods.280 * transaction, see the ->*_txn() methods.
281 *
282 * The add/del callbacks will reserve all hardware resources required
283 * to service the event, this includes any counter constraint
284 * scheduling etc.
285 *
286 * Called with IRQs disabled and the PMU disabled on the CPU the event
287 * is on.
288 *
289 * ->add() called without PERF_EF_START should result in the same state
290 * as ->add() followed by ->stop().
291 *
292 * ->del() must always PERF_EF_UPDATE stop an event. If it calls
293 * ->stop() that must deal with already being stopped without
294 * PERF_EF_UPDATE.
231 */295 */
232 int (*add) (struct perf_event *event, int flags);296 int (*add) (struct perf_event *event, int flags);
233 void (*del) (struct perf_event *event, int flags);297 void (*del) (struct perf_event *event, int flags);
234 298
235 /*299 /*
236 * Starts/Stops a counter present on the PMU. The PMI handler300 * Starts/Stops a counter present on the PMU.
237 * should stop the counter when perf_event_overflow() returns301 *
238 * !0. ->start() will be used to continue.302 * The PMI handler should stop the counter when perf_event_overflow()
303 * returns !0. ->start() will be used to continue.
304 *
305 * Also used to change the sample period.
306 *
307 * Called with IRQs disabled and the PMU disabled on the CPU the event
308 * is on -- will be called from NMI context with the PMU generates
309 * NMIs.
310 *
311 * ->stop() with PERF_EF_UPDATE will read the counter and update
312 * period/count values like ->read() would.
313 *
314 * ->start() with PERF_EF_RELOAD will reprogram the the counter
315 * value, must be preceded by a ->stop() with PERF_EF_UPDATE.
239 */316 */
240 void (*start) (struct perf_event *event, int flags);317 void (*start) (struct perf_event *event, int flags);
241 void (*stop) (struct perf_event *event, int flags);318 void (*stop) (struct perf_event *event, int flags);
242 319
243 /*320 /*
244 * Updates the counter value of the event.321 * Updates the counter value of the event.
322 *
323 * For sampling capable PMUs this will also update the software period
324 * hw_perf_event::period_left field.
245 */325 */
246 void (*read) (struct perf_event *event);326 void (*read) (struct perf_event *event);
247 327
@@ -252,20 +332,26 @@ struct pmu { · 4 unmodified lines
252 *332 *
253 * Start the transaction, after this ->add() doesn't need to333 * Start the transaction, after this ->add() doesn't need to
254 * do schedulability tests.334 * do schedulability tests.
335 *
336 * Optional.
255 */337 */
256 void (*start_txn) (struct pmu *pmu); /* optional */338 void (*start_txn) (struct pmu *pmu, unsigned int txn_flags);
257 /*339 /*
258 * If ->start_txn() disabled the ->add() schedulability test340 * If ->start_txn() disabled the ->add() schedulability test
259 * then ->commit_txn() is required to perform one. On success341 * then ->commit_txn() is required to perform one. On success
260 * the transaction is closed. On error the transaction is kept342 * the transaction is closed. On error the transaction is kept
261 * open until ->cancel_txn() is called.343 * open until ->cancel_txn() is called.
344 *
345 * Optional.
262 */346 */
263 int (*commit_txn) (struct pmu *pmu); /* optional */347 int (*commit_txn) (struct pmu *pmu);
264 /*348 /*
265 * Will cancel the transaction, assumes ->del() is called349 * Will cancel the transaction, assumes ->del() is called
266 * for each successful ->add() during the transaction.350 * for each successful ->add() during the transaction.
351 *
352 * Optional.
267 */353 */
268 void (*cancel_txn) (struct pmu *pmu); /* optional */354 void (*cancel_txn) (struct pmu *pmu);
269 355
270 /*356 /*
271 * Will return the value for perf_event_mmap_page::index for this event,357 * Will return the value for perf_event_mmap_page::index for this event,
include/uapi/linux/perf_event.h+4−2
@@ -168,6 +168,7 @@ enum perf_branch_sample_type_shift { · 167 unmodified lines
168 168
169 PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* call/ret stack */169 PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* call/ret stack */
170 PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT = 12, /* indirect jumps */170 PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT = 12, /* indirect jumps */
171 PERF_SAMPLE_BRANCH_CALL_SHIFT = 13, /* direct call */
171 172
172 PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */173 PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */
173};174};
@@ -188,6 +189,7 @@ enum perf_branch_sample_type { · 14 unmodified lines
188 189
189 PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,190 PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,
190 PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,191 PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,
192 PERF_SAMPLE_BRANCH_CALL = 1U << PERF_SAMPLE_BRANCH_CALL_SHIFT,
191 193
192 PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,194 PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
193};195};
@@ -476,7 +478,7 @@ struct perf_event_mmap_page { · 282 unmodified lines
476 * u64 delta;478 * u64 delta;
477 *479 *
478 * quot = (cyc >> time_shift);480 * quot = (cyc >> time_shift);
479 * rem = cyc & ((1 << time_shift) - 1);481 * rem = cyc & (((u64)1 << time_shift) - 1);
480 * delta = time_offset + quot * time_mult +482 * delta = time_offset + quot * time_mult +
481 * ((rem * time_mult) >> time_shift);483 * ((rem * time_mult) >> time_shift);
482 *484 *
@@ -507,7 +509,7 @@ struct perf_event_mmap_page { · 24 unmodified lines
507 * And vice versa:509 * And vice versa:
508 *510 *
509 * quot = cyc >> time_shift;511 * quot = cyc >> time_shift;
510 * rem = cyc & ((1 << time_shift) - 1);512 * rem = cyc & (((u64)1 << time_shift) - 1);
511 * timestamp = time_zero + quot * time_mult +513 * timestamp = time_zero + quot * time_mult +
512 * ((rem * time_mult) >> time_shift);514 * ((rem * time_mult) >> time_shift);
513 */515 */
kernel/events/core.c+165−59
@@ -196,7 +196,7 @@ static int perf_sample_period_ns __read_mostly = DEFAULT_SAMPLE_PERIOD_NS; · 195 unmodified lines
196static int perf_sample_allowed_ns __read_mostly =196static int perf_sample_allowed_ns __read_mostly =
197 DEFAULT_SAMPLE_PERIOD_NS * DEFAULT_CPU_TIME_MAX_PERCENT / 100;197 DEFAULT_SAMPLE_PERIOD_NS * DEFAULT_CPU_TIME_MAX_PERCENT / 100;
198 198
199void update_perf_cpu_limits(void)199static void update_perf_cpu_limits(void)
200{200{
201 u64 tmp = perf_sample_period_ns;201 u64 tmp = perf_sample_period_ns;
202 202
@@ -472,7 +472,7 @@ perf_cgroup_set_timestamp(struct task_struct *task, · 269 unmodified lines
472 * mode SWOUT : schedule out everything472 * mode SWOUT : schedule out everything
473 * mode SWIN : schedule in based on cgroup for next473 * mode SWIN : schedule in based on cgroup for next
474 */474 */
475void perf_cgroup_switch(struct task_struct *task, int mode)475static void perf_cgroup_switch(struct task_struct *task, int mode)
476{476{
477 struct perf_cpu_context *cpuctx;477 struct perf_cpu_context *cpuctx;
478 struct pmu *pmu;478 struct pmu *pmu;
@@ -1939,7 +1939,7 @@ group_sched_in(struct perf_event *group_event, · 1460 unmodified lines
1939 if (group_event->state == PERF_EVENT_STATE_OFF)1939 if (group_event->state == PERF_EVENT_STATE_OFF)
1940 return 0;1940 return 0;
1941 1941
1942 pmu->start_txn(pmu);1942 pmu->start_txn(pmu, PERF_PMU_TXN_ADD);
1943 1943
1944 if (event_sched_in(group_event, cpuctx, ctx)) {1944 if (event_sched_in(group_event, cpuctx, ctx)) {
1945 pmu->cancel_txn(pmu);1945 pmu->cancel_txn(pmu);
@@ -3209,14 +3209,22 @@ void perf_event_exec(void) · 1263 unmodified lines
3209 rcu_read_unlock();3209 rcu_read_unlock();
3210}3210}
3211 3211
3212struct perf_read_data {
3213 struct perf_event *event;
3214 bool group;
3215 int ret;
3216};
3217
3212/*3218/*
3213 * Cross CPU call to read the hardware event3219 * Cross CPU call to read the hardware event
3214 */3220 */
3215static void __perf_event_read(void *info)3221static void __perf_event_read(void *info)
3216{3222{
3217 struct perf_event *event = info;3223 struct perf_read_data *data = info;
3224 struct perf_event *sub, *event = data->event;
3218 struct perf_event_context *ctx = event->ctx;3225 struct perf_event_context *ctx = event->ctx;
3219 struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);3226 struct perf_cpu_context *cpuctx = __get_cpu_context(ctx);
3227 struct pmu *pmu = event->pmu;
3220 3228
3221 /*3229 /*
3222 * If this is a task context, we need to check whether it is3230 * If this is a task context, we need to check whether it is
@@ -3233,9 +3241,35 @@ static void __perf_event_read(void *info) · 10 unmodified lines
3233 update_context_time(ctx);3241 update_context_time(ctx);
3234 update_cgrp_time_from_event(event);3242 update_cgrp_time_from_event(event);
3235 }3243 }
3244
3236 update_event_times(event);3245 update_event_times(event);
3237 if (event->state == PERF_EVENT_STATE_ACTIVE)3246 if (event->state != PERF_EVENT_STATE_ACTIVE)
3238 event->pmu->read(event);3247 goto unlock;
3248
3249 if (!data->group) {
3250 pmu->read(event);
3251 data->ret = 0;
3252 goto unlock;
3253 }
3254
3255 pmu->start_txn(pmu, PERF_PMU_TXN_READ);
3256
3257 pmu->read(event);
3258
3259 list_for_each_entry(sub, &event->sibling_list, group_entry) {
3260 update_event_times(sub);
3261 if (sub->state == PERF_EVENT_STATE_ACTIVE) {
3262 /*
3263 * Use sibling's PMU rather than @event's since
3264 * sibling could be on different (eg: software) PMU.
3265 */
3266 sub->pmu->read(sub);
3267 }
3268 }
3269
3270 data->ret = pmu->commit_txn(pmu);
3271
3272unlock:
3239 raw_spin_unlock(&ctx->lock);3273 raw_spin_unlock(&ctx->lock);
3240}3274}
3241 3275
@@ -3300,15 +3334,23 @@ u64 perf_event_read_local(struct perf_event *event) · 58 unmodified lines
3300 return val;3334 return val;
3301}3335}
3302 3336
3303static u64 perf_event_read(struct perf_event *event)3337static int perf_event_read(struct perf_event *event, bool group)
3304{3338{
3339 int ret = 0;
3340
3305 /*3341 /*
3306 * If event is enabled and currently active on a CPU, update the3342 * If event is enabled and currently active on a CPU, update the
3307 * value in the event structure:3343 * value in the event structure:
3308 */3344 */
3309 if (event->state == PERF_EVENT_STATE_ACTIVE) {3345 if (event->state == PERF_EVENT_STATE_ACTIVE) {
3346 struct perf_read_data data = {
3347 .event = event,
3348 .group = group,
3349 .ret = 0,
3350 };
3310 smp_call_function_single(event->oncpu,3351 smp_call_function_single(event->oncpu,
3311 __perf_event_read, event, 1);3352 __perf_event_read, &data, 1);
3353 ret = data.ret;
3312 } else if (event->state == PERF_EVENT_STATE_INACTIVE) {3354 } else if (event->state == PERF_EVENT_STATE_INACTIVE) {
3313 struct perf_event_context *ctx = event->ctx;3355 struct perf_event_context *ctx = event->ctx;
3314 unsigned long flags;3356 unsigned long flags;
@@ -3323,11 +3365,14 @@ static u64 perf_event_read(struct perf_event *event) · 8 unmodified lines
3323 update_context_time(ctx);3365 update_context_time(ctx);
3324 update_cgrp_time_from_event(event);3366 update_cgrp_time_from_event(event);
3325 }3367 }
3326 update_event_times(event);3368 if (group)
3369 update_group_times(event);
3370 else
3371 update_event_times(event);
3327 raw_spin_unlock_irqrestore(&ctx->lock, flags);3372 raw_spin_unlock_irqrestore(&ctx->lock, flags);
3328 }3373 }
3329 3374
3330 return perf_event_count(event);3375 return ret;
3331}3376}
3332 3377
3333/*3378/*
@@ -3769,7 +3814,7 @@ static void put_event(struct perf_event *event) · 435 unmodified lines
3769 * see the comment there.3814 * see the comment there.
3770 *3815 *
3771 * 2) there is a lock-inversion with mmap_sem through3816 * 2) there is a lock-inversion with mmap_sem through
3772 * perf_event_read_group(), which takes faults while3817 * perf_read_group(), which takes faults while
3773 * holding ctx->mutex, however this is called after3818 * holding ctx->mutex, however this is called after
3774 * the last filedesc died, so there is no possibility3819 * the last filedesc died, so there is no possibility
3775 * to trigger the AB-BA case.3820 * to trigger the AB-BA case.
@@ -3843,14 +3888,18 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running) · 67 unmodified lines
3843 *running = 0;3888 *running = 0;
3844 3889
3845 mutex_lock(&event->child_mutex);3890 mutex_lock(&event->child_mutex);
3846 total += perf_event_read(event);3891
3892 (void)perf_event_read(event, false);
3893 total += perf_event_count(event);
3894
3847 *enabled += event->total_time_enabled +3895 *enabled += event->total_time_enabled +
3848 atomic64_read(&event->child_total_time_enabled);3896 atomic64_read(&event->child_total_time_enabled);
3849 *running += event->total_time_running +3897 *running += event->total_time_running +
3850 atomic64_read(&event->child_total_time_running);3898 atomic64_read(&event->child_total_time_running);
3851 3899
3852 list_for_each_entry(child, &event->child_list, child_list) {3900 list_for_each_entry(child, &event->child_list, child_list) {
3853 total += perf_event_read(child);3901 (void)perf_event_read(child, false);
3902 total += perf_event_count(child);
3854 *enabled += child->total_time_enabled;3903 *enabled += child->total_time_enabled;
3855 *running += child->total_time_running;3904 *running += child->total_time_running;
3856 }3905 }
@@ -3860,55 +3909,95 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running) · 3 unmodified lines
3860}3909}
3861EXPORT_SYMBOL_GPL(perf_event_read_value);3910EXPORT_SYMBOL_GPL(perf_event_read_value);
3862 3911
3863static int perf_event_read_group(struct perf_event *event,3912static int __perf_read_group_add(struct perf_event *leader,
3864 u64 read_format, char __user *buf)3913 u64 read_format, u64 *values)
3865{3914{
3866 struct perf_event *leader = event->group_leader, *sub;3915 struct perf_event *sub;
3867 struct perf_event_context *ctx = leader->ctx;3916 int n = 1; /* skip @nr */
3868 int n = 0, size = 0, ret;3917 int ret;
3869 u64 count, enabled, running;
3870 u64 values[5];
3871 3918
3872 lockdep_assert_held(&ctx->mutex);3919 ret = perf_event_read(leader, true);
3920 if (ret)
3921 return ret;
3873 3922
3874 count = perf_event_read_value(leader, &enabled, &running);3923 /*
3924 * Since we co-schedule groups, {enabled,running} times of siblings
3925 * will be identical to those of the leader, so we only publish one
3926 * set.
3927 */
3928 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
3929 values[n++] += leader->total_time_enabled +
3930 atomic64_read(&leader->child_total_time_enabled);
3931 }
3875 3932
3876 values[n++] = 1 + leader->nr_siblings;3933 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
3877 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)3934 values[n++] += leader->total_time_running +
3878 values[n++] = enabled;3935 atomic64_read(&leader->child_total_time_running);
3879 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)3936 }
3880 values[n++] = running;3937
3881 values[n++] = count;3938 /*
3939 * Write {count,id} tuples for every sibling.
3940 */
3941 values[n++] += perf_event_count(leader);
3882 if (read_format & PERF_FORMAT_ID)3942 if (read_format & PERF_FORMAT_ID)
3883 values[n++] = primary_event_id(leader);3943 values[n++] = primary_event_id(leader);
3884 3944
3885 size = n * sizeof(u64);3945 list_for_each_entry(sub, &leader->sibling_list, group_entry) {
3946 values[n++] += perf_event_count(sub);
3947 if (read_format & PERF_FORMAT_ID)
3948 values[n++] = primary_event_id(sub);
3949 }
3886 3950
3887 if (copy_to_user(buf, values, size))3951 return 0;
3888 return -EFAULT;3952}
3953
3954static int perf_read_group(struct perf_event *event,
3955 u64 read_format, char __user *buf)
3956{
3957 struct perf_event *leader = event->group_leader, *child;
3958 struct perf_event_context *ctx = leader->ctx;
3959 int ret;
3960 u64 *values;
3889 3961
3890 ret = size;3962 lockdep_assert_held(&ctx->mutex);
3891 3963
3892 list_for_each_entry(sub, &leader->sibling_list, group_entry) {3964 values = kzalloc(event->read_size, GFP_KERNEL);
3893 n = 0;3965 if (!values)
3966 return -ENOMEM;
3894 3967
3895 values[n++] = perf_event_read_value(sub, &enabled, &running);3968 values[0] = 1 + leader->nr_siblings;
3896 if (read_format & PERF_FORMAT_ID)
3897 values[n++] = primary_event_id(sub);
3898 3969
3899 size = n * sizeof(u64);3970 /*
3971 * By locking the child_mutex of the leader we effectively
3972 * lock the child list of all siblings.. XXX explain how.
3973 */
3974 mutex_lock(&leader->child_mutex);
3900 3975
3901 if (copy_to_user(buf + ret, values, size)) {3976 ret = __perf_read_group_add(leader, read_format, values);
3902 return -EFAULT;3977 if (ret)
3903 }3978 goto unlock;
3904 3979
3905 ret += size;3980 list_for_each_entry(child, &leader->child_list, child_list) {
3981 ret = __perf_read_group_add(child, read_format, values);
3982 if (ret)
3983 goto unlock;
3906 }3984 }
3907 3985
3986 mutex_unlock(&leader->child_mutex);
3987
3988 ret = event->read_size;
3989 if (copy_to_user(buf, values, event->read_size))
3990 ret = -EFAULT;
3991 goto out;
3992
3993unlock:
3994 mutex_unlock(&leader->child_mutex);
3995out:
3996 kfree(values);
3908 return ret;3997 return ret;
3909}3998}
3910 3999
3911static int perf_event_read_one(struct perf_event *event,4000static int perf_read_one(struct perf_event *event,
3912 u64 read_format, char __user *buf)4001 u64 read_format, char __user *buf)
3913{4002{
3914 u64 enabled, running;4003 u64 enabled, running;
@@ -3946,7 +4035,7 @@ static bool is_event_hup(struct perf_event *event) · 31 unmodified lines
3946 * Read the performance event - simple non blocking version for now4035 * Read the performance event - simple non blocking version for now
3947 */4036 */
3948static ssize_t4037static ssize_t
3949perf_read_hw(struct perf_event *event, char __user *buf, size_t count)4038__perf_read(struct perf_event *event, char __user *buf, size_t count)
3950{4039{
3951 u64 read_format = event->attr.read_format;4040 u64 read_format = event->attr.read_format;
3952 int ret;4041 int ret;
@@ -3964,9 +4053,9 @@ perf_read_hw(struct perf_event *event, char __user *buf, size_t count) · 11 unmodified lines
3964 4053
3965 WARN_ON_ONCE(event->ctx->parent_ctx);4054 WARN_ON_ONCE(event->ctx->parent_ctx);
3966 if (read_format & PERF_FORMAT_GROUP)4055 if (read_format & PERF_FORMAT_GROUP)
3967 ret = perf_event_read_group(event, read_format, buf);4056 ret = perf_read_group(event, read_format, buf);
3968 else4057 else
3969 ret = perf_event_read_one(event, read_format, buf);4058 ret = perf_read_one(event, read_format, buf);
3970 4059
3971 return ret;4060 return ret;
3972}4061}
@@ -3979,7 +4068,7 @@ perf_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) · 6 unmodified lines
3979 int ret;4068 int ret;
3980 4069
3981 ctx = perf_event_ctx_lock(event);4070 ctx = perf_event_ctx_lock(event);
3982 ret = perf_read_hw(event, buf, count);4071 ret = __perf_read(event, buf, count);
3983 perf_event_ctx_unlock(event, ctx);4072 perf_event_ctx_unlock(event, ctx);
3984 4073
3985 return ret;4074 return ret;
@@ -4010,7 +4099,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait) · 24 unmodified lines
4010 4099
4011static void _perf_event_reset(struct perf_event *event)4100static void _perf_event_reset(struct perf_event *event)
4012{4101{
4013 (void)perf_event_read(event);4102 (void)perf_event_read(event, false);
4014 local64_set(&event->count, 0);4103 local64_set(&event->count, 0);
4015 perf_event_update_userpage(event);4104 perf_event_update_userpage(event);
4016}4105}
@@ -7292,24 +7381,49 @@ static void perf_pmu_nop_void(struct pmu *pmu) · 3275 unmodified lines
7292{7381{
7293}7382}
7294 7383
7384static void perf_pmu_nop_txn(struct pmu *pmu, unsigned int flags)
7385{
7386}
7387
7295static int perf_pmu_nop_int(struct pmu *pmu)7388static int perf_pmu_nop_int(struct pmu *pmu)
7296{7389{
7297 return 0;7390 return 0;
7298}7391}
7299 7392
7300static void perf_pmu_start_txn(struct pmu *pmu)7393static DEFINE_PER_CPU(unsigned int, nop_txn_flags);
7394
7395static void perf_pmu_start_txn(struct pmu *pmu, unsigned int flags)
7301{7396{
7397 __this_cpu_write(nop_txn_flags, flags);
7398
7399 if (flags & ~PERF_PMU_TXN_ADD)
7400 return;
7401
7302 perf_pmu_disable(pmu);7402 perf_pmu_disable(pmu);
7303}7403}
7304 7404
7305static int perf_pmu_commit_txn(struct pmu *pmu)7405static int perf_pmu_commit_txn(struct pmu *pmu)
7306{7406{
7407 unsigned int flags = __this_cpu_read(nop_txn_flags);
7408
7409 __this_cpu_write(nop_txn_flags, 0);
7410
7411 if (flags & ~PERF_PMU_TXN_ADD)
7412 return 0;
7413
7307 perf_pmu_enable(pmu);7414 perf_pmu_enable(pmu);
7308 return 0;7415 return 0;
7309}7416}
7310 7417
7311static void perf_pmu_cancel_txn(struct pmu *pmu)7418static void perf_pmu_cancel_txn(struct pmu *pmu)
7312{7419{
7420 unsigned int flags = __this_cpu_read(nop_txn_flags);
7421
7422 __this_cpu_write(nop_txn_flags, 0);
7423
7424 if (flags & ~PERF_PMU_TXN_ADD)
7425 return;
7426
7313 perf_pmu_enable(pmu);7427 perf_pmu_enable(pmu);
7314}7428}
7315 7429
@@ -7548,7 +7662,7 @@ got_cpu_context: · 232 unmodified lines
7548 pmu->commit_txn = perf_pmu_commit_txn;7662 pmu->commit_txn = perf_pmu_commit_txn;
7549 pmu->cancel_txn = perf_pmu_cancel_txn;7663 pmu->cancel_txn = perf_pmu_cancel_txn;
7550 } else {7664 } else {
7551 pmu->start_txn = perf_pmu_nop_void;7665 pmu->start_txn = perf_pmu_nop_txn;
7552 pmu->commit_txn = perf_pmu_nop_int;7666 pmu->commit_txn = perf_pmu_nop_int;
7553 pmu->cancel_txn = perf_pmu_nop_void;7667 pmu->cancel_txn = perf_pmu_nop_void;
7554 }7668 }
@@ -7636,7 +7750,7 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event) · 81 unmodified lines
7636 return ret;7750 return ret;
7637}7751}
7638 7752
7639struct pmu *perf_init_event(struct perf_event *event)7753static struct pmu *perf_init_event(struct perf_event *event)
7640{7754{
7641 struct pmu *pmu = NULL;7755 struct pmu *pmu = NULL;
7642 int idx;7756 int idx;
@@ -9345,14 +9459,6 @@ static void perf_cgroup_exit(struct cgroup_subsys_state *css, · 1702 unmodified lines
9345 struct cgroup_subsys_state *old_css,9459 struct cgroup_subsys_state *old_css,
9346 struct task_struct *task)9460 struct task_struct *task)
9347{9461{
9348 /*
9349 * cgroup_exit() is called in the copy_process() failure path.
9350 * Ignore this case since the task hasn't ran yet, this avoids
9351 * trying to poke a half freed task state from generic code.
9352 */
9353 if (!(task->flags & PF_EXITING))
9354 return;
9355
9356 task_function_call(task, __perf_cgroup_move, task);9462 task_function_call(task, __perf_cgroup_move, task);
9357}9463}
9358 9464
tools/build/.gitignore+1−0
@@ -0,0 +1 @@
1fixdep
tools/build/Build+1−0
@@ -0,0 +1 @@
1fixdep-y := fixdep.o
tools/build/Build.include+14−3
@@ -54,15 +54,26 @@ make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1))))) · 53 unmodified lines
54# PHONY targets skipped in both cases.54# PHONY targets skipped in both cases.
55any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)55any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
56 56
57###
58# Copy dependency data into .cmd file
59# - gcc -M dependency info
60# - command line to create object 'cmd_object :='
61dep-cmd = $(if $(wildcard $(fixdep)), \
62 $(fixdep) $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp; \
63 rm -f $(depfile); \
64 mv -f $(dot-target).tmp $(dot-target).cmd, \
65 printf '\# cannot find fixdep (%s)\n' $(fixdep) > $(dot-target).cmd; \
66 printf '\# using basic dep data\n\n' >> $(dot-target).cmd; \
67 cat $(depfile) >> $(dot-target).cmd; \
68 printf '%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd)
69
57###70###
58# if_changed_dep - execute command if any prerequisite is newer than71# if_changed_dep - execute command if any prerequisite is newer than
59# target, or command line has changed and update72# target, or command line has changed and update
60# dependencies in the cmd file73# dependencies in the cmd file
61if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \74if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \
62 @set -e; \75 @set -e; \
63 $(echo-cmd) $(cmd_$(1)); \76 $(echo-cmd) $(cmd_$(1)) && $(dep-cmd))
64 cat $(depfile) > $(dot-target).cmd; \
65 printf '%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd)
66 77
67# if_changed - execute command if any prerequisite is newer than78# if_changed - execute command if any prerequisite is newer than
68# target, or command line has changed79# target, or command line has changed
tools/build/Documentation/Build.txt+39−13
@@ -11,8 +11,9 @@ Unlike the kernel we don't have a single build object 'obj-y' list that where · 10 unmodified lines
11we setup source objects, but we support more. This allows one 'Build' file to11we setup source objects, but we support more. This allows one 'Build' file to
12carry a sources list for multiple build objects.12carry a sources list for multiple build objects.
13 13
14a) Build framework makefiles14
15----------------------------15Build framework makefiles
16-------------------------
16 17
17The build framework consists of 2 Makefiles:18The build framework consists of 2 Makefiles:
18 19
@@ -23,7 +24,7 @@ While the 'Build.include' file contains just some generic definitions, the · 4 unmodified lines
23'Makefile.build' file is the makefile used from the outside. It's24'Makefile.build' file is the makefile used from the outside. It's
24interface/usage is following:25interface/usage is following:
25 26
26 $ make -f tools/build/Makefile srctree=$(KSRC) dir=$(DIR) obj=$(OBJECT)27 $ make -f tools/build/Makefile.build srctree=$(KSRC) dir=$(DIR) obj=$(OBJECT)
27 28
28where:29where:
29 30
@@ -38,8 +39,9 @@ called $(OBJECT)-in.o: · 8 unmodified lines
38 39
39which includes all compiled sources described in 'Build' makefiles.40which includes all compiled sources described in 'Build' makefiles.
40 41
41a) Build makefiles42
42------------------43Build makefiles
44---------------
43 45
44The user supplies 'Build' makefiles that contains a objects list, and connects46The user supplies 'Build' makefiles that contains a objects list, and connects
45the build to nested directories.47the build to nested directories.
@@ -95,8 +97,31 @@ It's only a matter of 2 single commands to create the final binaries: · 49 unmodified lines
95 97
96You can check the 'ex' example in 'tools/build/tests/ex' for more details.98You can check the 'ex' example in 'tools/build/tests/ex' for more details.
97 99
98b) Rules100
99--------101Makefile.include
102----------------
103
104The tools/build/Makefile.include makefile could be included
105via user makefiles to get usefull definitions.
106
107It defines following interface:
108
109 - build macro definition:
110 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
111
112 to make it easier to invoke build like:
113 make $(build)=ex
114
115
116Fixdep
117------
118It is necessary to build the fixdep helper before invoking the build.
119The Makefile.include file adds the fixdep target, that could be
120invoked by the user.
121
122
123Rules
124-----
100 125
101The build framework provides standard compilation rules to handle .S and .c126The build framework provides standard compilation rules to handle .S and .c
102compilation.127compilation.
@@ -104,8 +129,9 @@ compilation. · 1 unmodified line
104It's possible to include special rule if needed (like we do for flex or bison129It's possible to include special rule if needed (like we do for flex or bison
105code generation).130code generation).
106 131
107c) CFLAGS132
108---------133CFLAGS
134------
109 135
110It's possible to alter the standard object C flags in the following way:136It's possible to alter the standard object C flags in the following way:
111 137
@@ -115,8 +141,8 @@ It's possible to alter the standard object C flags in the following way: · 3 unmodified lines
115This C flags changes has the scope of the Build makefile they are defined in.141This C flags changes has the scope of the Build makefile they are defined in.
116 142
117 143
118d) Dependencies144Dependencies
119---------------145------------
120 146
121For each built object file 'a.o' the '.a.cmd' is created and holds:147For each built object file 'a.o' the '.a.cmd' is created and holds:
122 148
@@ -130,8 +156,8 @@ All existing '.cmd' files are included in the Build process to follow properly · 7 unmodified lines
130the dependencies and trigger a rebuild when necessary.156the dependencies and trigger a rebuild when necessary.
131 157
132 158
133e) Single rules159Single rules
134---------------160------------
135 161
136It's possible to build single object file by choice, like:162It's possible to build single object file by choice, like:
137 163
tools/build/Makefile+43−0
@@ -0,0 +1,43 @@
1ifeq ($(srctree),)
2srctree := $(patsubst %/,%,$(dir $(shell pwd)))
3srctree := $(patsubst %/,%,$(dir $(srctree)))
4endif
5
6include $(srctree)/tools//scripts/Makefile.include
7
8define allow-override
9 $(if $(or $(findstring environment,$(origin $(1))),\
10 $(findstring command line,$(origin $(1)))),,\
11 $(eval $(1) = $(2)))
12endef
13
14$(call allow-override,CC,$(CROSS_COMPILE)gcc)
15$(call allow-override,LD,$(CROSS_COMPILE)ld)
16
17ifeq ($(V),1)
18 Q =
19else
20 Q = @
21endif
22
23export Q srctree CC LD
24
25MAKEFLAGS := --no-print-directory
26build := -f $(srctree)/tools/build/Makefile.build dir=. obj
27
28all: fixdep
29
30clean:
31 $(call QUIET_CLEAN, fixdep)
32 $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
33 $(Q)rm -f fixdep
34
35$(OUTPUT)fixdep-in.o: FORCE
36 $(Q)$(MAKE) $(build)=fixdep
37
38$(OUTPUT)fixdep: $(OUTPUT)fixdep-in.o
39 $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $<
40
41FORCE:
42
43.PHONY: FORCE
tools/build/Makefile.build+7−0
@@ -21,6 +21,13 @@ endif · 20 unmodified lines
21 21
22build-dir := $(srctree)/tools/build22build-dir := $(srctree)/tools/build
23 23
24# Define $(fixdep) for dep-cmd function
25ifeq ($(OUTPUT),)
26 fixdep := $(build-dir)/fixdep
27else
28 fixdep := $(OUTPUT)/fixdep
29endif
30
24# Generic definitions31# Generic definitions
25include $(build-dir)/Build.include32include $(build-dir)/Build.include
26 33
tools/build/Makefile.feature+9−6
@@ -53,7 +53,8 @@ FEATURE_TESTS ?= \ · 52 unmodified lines
53 libdw-dwarf-unwind \53 libdw-dwarf-unwind \
54 zlib \54 zlib \
55 lzma \55 lzma \
56 get_cpuid56 get_cpuid \
57 bpf
57 58
58FEATURE_DISPLAY ?= \59FEATURE_DISPLAY ?= \
59 dwarf \60 dwarf \
@@ -71,7 +72,8 @@ FEATURE_DISPLAY ?= \ · 11 unmodified lines
71 libdw-dwarf-unwind \72 libdw-dwarf-unwind \
72 zlib \73 zlib \
73 lzma \74 lzma \
74 get_cpuid75 get_cpuid \
76 bpf
75 77
76# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.78# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
77# If in the future we need per-feature checks/flags for features not79# If in the future we need per-feature checks/flags for features not
@@ -121,8 +123,9 @@ define feature_print_text_code · 43 unmodified lines
121 MSG = $(shell printf '...%30s: %s' $(1) $(2))123 MSG = $(shell printf '...%30s: %s' $(1) $(2))
122endef124endef
123 125
126FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
124FEATURE_DUMP := $(foreach feat,$(FEATURE_DISPLAY),feature-$(feat)($(feature-$(feat))))127FEATURE_DUMP := $(foreach feat,$(FEATURE_DISPLAY),feature-$(feat)($(feature-$(feat))))
125FEATURE_DUMP_FILE := $(shell touch $(OUTPUT)FEATURE-DUMP; cat $(OUTPUT)FEATURE-DUMP)128FEATURE_DUMP_FILE := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
126 129
127ifeq ($(dwarf-post-unwind),1)130ifeq ($(dwarf-post-unwind),1)
128 FEATURE_DUMP += dwarf-post-unwind($(dwarf-post-unwind-text))131 FEATURE_DUMP += dwarf-post-unwind($(dwarf-post-unwind-text))
@@ -131,16 +134,16 @@ endif · 2 unmodified lines
131# The $(feature_display) controls the default detection message134# The $(feature_display) controls the default detection message
132# output. It's set if:135# output. It's set if:
133# - detected features differes from stored features from136# - detected features differes from stored features from
134# last build (in FEATURE-DUMP file)137# last build (in $(FEATURE_DUMP_FILENAME) file)
135# - one of the $(FEATURE_DISPLAY) is not detected138# - one of the $(FEATURE_DISPLAY) is not detected
136# - VF is enabled139# - VF is enabled
137 140
138ifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)")141ifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)")
139 $(shell echo "$(FEATURE_DUMP)" > $(OUTPUT)FEATURE-DUMP)142 $(shell echo "$(FEATURE_DUMP)" > $(FEATURE_DUMP_FILENAME))
140 feature_display := 1143 feature_display := 1
141endif144endif
142 145
143feature_display_check = $(eval $(feature_check_code))146feature_display_check = $(eval $(feature_check_display_code))
144define feature_display_check_code147define feature_display_check_code
145 ifneq ($(feature-$(1)), 1)148 ifneq ($(feature-$(1)), 1)
146 feature_display := 1149 feature_display := 1
tools/build/Makefile.include+10−0
@@ -0,0 +1,10 @@
1build := -f $(srctree)/tools/build/Makefile.build dir=. obj
2
3ifdef CROSS_COMPILE
4fixdep:
5else
6fixdep:
7 $(Q)$(MAKE) -C $(srctree)/tools/build fixdep
8endif
9
10.PHONY: fixdep
tools/build/feature/Makefile+2−2
@@ -132,10 +132,10 @@ test-libbfd.bin: · 131 unmodified lines
132 $(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl132 $(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl
133 133
134test-liberty.bin:134test-liberty.bin:
135 $(CC) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' -lbfd -ldl -liberty135 $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
136 136
137test-liberty-z.bin:137test-liberty-z.bin:
138 $(CC) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' -lbfd -ldl -liberty -lz138 $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
139 139
140test-cplus-demangle.bin:140test-cplus-demangle.bin:
141 $(BUILD) -liberty141 $(BUILD) -liberty
tools/build/fixdep.c+168−0
@@ -0,0 +1,168 @@
1/*
2 * "Optimize" a list of dependencies as spit out by gcc -MD
3 * for the build framework.
4 *
5 * Original author:
6 * Copyright 2002 by Kai Germaschewski <kai.germaschewski@gmx.de>
7 *
8 * This code has been borrowed from kbuild's fixdep (scripts/basic/fixdep.c),
9 * Please check it for detailed explanation. This fixdep borow only the
10 * base transformation of dependecies without the CONFIG mangle.
11 */
12
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <sys/mman.h>
16#include <unistd.h>
17#include <fcntl.h>
18#include <string.h>
19#include <stdlib.h>
20#include <stdio.h>
21#include <limits.h>
22
23char *target;
24char *depfile;
25char *cmdline;
26
27static void usage(void)
28{
29 fprintf(stderr, "Usage: fixdep <depfile> <target> <cmdline>\n");
30 exit(1);
31}
32
33/*
34 * Print out the commandline prefixed with cmd_<target filename> :=
35 */
36static void print_cmdline(void)
37{
38 printf("cmd_%s := %s\n\n", target, cmdline);
39}
40
41/*
42 * Important: The below generated source_foo.o and deps_foo.o variable
43 * assignments are parsed not only by make, but also by the rather simple
44 * parser in scripts/mod/sumversion.c.
45 */
46static void parse_dep_file(void *map, size_t len)
47{
48 char *m = map;
49 char *end = m + len;
50 char *p;
51 char s[PATH_MAX];
52 int is_target;
53 int saw_any_target = 0;
54 int is_first_dep = 0;
55
56 while (m < end) {
57 /* Skip any "white space" */
58 while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
59 m++;
60 /* Find next "white space" */
61 p = m;
62 while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
63 p++;
64 /* Is the token we found a target name? */
65 is_target = (*(p-1) == ':');
66 /* Don't write any target names into the dependency file */
67 if (is_target) {
68 /* The /next/ file is the first dependency */
69 is_first_dep = 1;
70 } else {
71 /* Save this token/filename */
72 memcpy(s, m, p-m);
73 s[p - m] = 0;
74
75 /*
76 * Do not list the source file as dependency,
77 * so that kbuild is not confused if a .c file
78 * is rewritten into .S or vice versa. Storing
79 * it in source_* is needed for modpost to
80 * compute srcversions.
81 */
82 if (is_first_dep) {
83 /*
84 * If processing the concatenation of
85 * multiple dependency files, only
86 * process the first target name, which
87 * will be the original source name,
88 * and ignore any other target names,
89 * which will be intermediate temporary
90 * files.
91 */
92 if (!saw_any_target) {
93 saw_any_target = 1;
94 printf("source_%s := %s\n\n",
95 target, s);
96 printf("deps_%s := \\\n",
97 target);
98 }
99 is_first_dep = 0;
100 } else
101 printf(" %s \\\n", s);
102 }
103 /*
104 * Start searching for next token immediately after the first
105 * "whitespace" character that follows this token.
106 */
107 m = p + 1;
108 }
109
110 if (!saw_any_target) {
111 fprintf(stderr, "fixdep: parse error; no targets found\n");
112 exit(1);
113 }
114
115 printf("\n%s: $(deps_%s)\n\n", target, target);
116 printf("$(deps_%s):\n", target);
117}
118
119static void print_deps(void)
120{
121 struct stat st;
122 int fd;
123 void *map;
124
125 fd = open(depfile, O_RDONLY);
126 if (fd < 0) {
127 fprintf(stderr, "fixdep: error opening depfile: ");
128 perror(depfile);
129 exit(2);
130 }
131 if (fstat(fd, &st) < 0) {
132 fprintf(stderr, "fixdep: error fstat'ing depfile: ");
133 perror(depfile);
134 exit(2);
135 }
136 if (st.st_size == 0) {
137 fprintf(stderr, "fixdep: %s is empty\n", depfile);
138 close(fd);
139 return;
140 }
141 map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
142 if ((long) map == -1) {
143 perror("fixdep: mmap");
144 close(fd);
145 return;
146 }
147
148 parse_dep_file(map, st.st_size);
149
150 munmap(map, st.st_size);
151
152 close(fd);
153}
154
155int main(int argc, char **argv)
156{
157 if (argc != 4)
158 usage();
159
160 depfile = argv[1];
161 target = argv[2];
162 cmdline = argv[3];
163
164 print_cmdline();
165 print_deps();
166
167 return 0;
168}
tools/build/tests/ex/Build+1−0
@@ -4,6 +4,7 @@ ex-y += b.o · 3 unmodified lines
4ex-y += b.o4ex-y += b.o
5ex-y += empty/5ex-y += empty/
6ex-y += empty2/6ex-y += empty2/
7ex-y += inc.o
7 8
8libex-y += c.o9libex-y += c.o
9libex-y += d.o10libex-y += d.o
tools/build/tests/ex/Makefile+8−5
@@ -1,19 +1,22 @@
1export srctree := ../../../..1export srctree := $(abspath ../../../..)
2export CC := gcc2export CC := gcc
3export LD := ld3export LD := ld
4export AR := ar4export AR := ar
5 5
6build := -f $(srctree)/tools/build/Makefile.build dir=. obj6ex:
7
8include $(srctree)/tools/build/Makefile.include
9
7ex: ex-in.o libex-in.o10ex: ex-in.o libex-in.o
8 gcc -o $@ $^11 gcc -o $@ $^
9 12
10ex.%: FORCE13ex.%: fixdep FORCE
11 make -f $(srctree)/tools/build/Makefile.build dir=. $@14 make -f $(srctree)/tools/build/Makefile.build dir=. $@
12 15
13ex-in.o: FORCE16ex-in.o: fixdep FORCE
14 make $(build)=ex17 make $(build)=ex
15 18
16libex-in.o: FORCE19libex-in.o: fixdep FORCE
17 make $(build)=libex20 make $(build)=libex
18 21
19clean:22clean:
tools/build/tests/ex/ex.c+2−0
@@ -5,6 +5,7 @@ int c(void); · 4 unmodified lines
5int d(void);5int d(void);
6int e(void);6int e(void);
7int f(void);7int f(void);
8int inc(void);
8 9
9int main(void)10int main(void)
10{11{
@@ -14,6 +15,7 @@ int main(void) · 3 unmodified lines
14 d();15 d();
15 e();16 e();
16 f();17 f();
18 inc();
17 19
18 return 0;20 return 0;
19}21}
tools/build/tests/ex/inc.c+8−0
@@ -0,0 +1,8 @@
1#ifdef INCLUDE
2#include "krava.h"
3#endif
4
5int inc(void)
6{
7 return 0;
8}
tools/build/tests/run.sh+27−0
@@ -34,9 +34,36 @@ function test_ex_suffix { · 33 unmodified lines
34 make -C ex V=1 clean > /dev/null 2>&134 make -C ex V=1 clean > /dev/null 2>&1
35 rm -f ex.out35 rm -f ex.out
36}36}
37
38function test_ex_include {
39 make -C ex V=1 clean > ex.out 2>&1
40
41 # build with krava.h include
42 touch ex/krava.h
43 make -C ex V=1 CFLAGS=-DINCLUDE >> ex.out 2>&1
44
45 if [ ! -x ./ex/ex ]; then
46 echo FAILED
47 exit -1
48 fi
49
50 # build without the include
51 rm -f ex/krava.h ex/ex
52 make -C ex V=1 >> ex.out 2>&1
53
54 if [ ! -x ./ex/ex ]; then
55 echo FAILED
56 exit -1
57 fi
58
59 make -C ex V=1 clean > /dev/null 2>&1
60 rm -f ex.out
61}
62
37echo -n Testing..63echo -n Testing..
38 64
39test_ex65test_ex
40test_ex_suffix66test_ex_suffix
67test_ex_include
41 68
42echo OK69echo OK
tools/include/linux/compiler.h+24−8
@@ -43,13 +43,29 @@ · 42 unmodified lines
43 43
44#include <linux/types.h>44#include <linux/types.h>
45 45
46/*
47 * Following functions are taken from kernel sources and
48 * break aliasing rules in their original form.
49 *
50 * While kernel is compiled with -fno-strict-aliasing,
51 * perf uses -Wstrict-aliasing=3 which makes build fail
52 * under gcc 4.4.
53 *
54 * Using extra __may_alias__ type to allow aliasing
55 * in this case.
56 */
57typedef __u8 __attribute__((__may_alias__)) __u8_alias_t;
58typedef __u16 __attribute__((__may_alias__)) __u16_alias_t;
59typedef __u32 __attribute__((__may_alias__)) __u32_alias_t;
60typedef __u64 __attribute__((__may_alias__)) __u64_alias_t;
61
46static __always_inline void __read_once_size(const volatile void *p, void *res, int size)62static __always_inline void __read_once_size(const volatile void *p, void *res, int size)
47{63{
48 switch (size) {64 switch (size) {
49 case 1: *(__u8 *)res = *(volatile __u8 *)p; break;65 case 1: *(__u8_alias_t *) res = *(volatile __u8_alias_t *) p; break;
50 case 2: *(__u16 *)res = *(volatile __u16 *)p; break;66 case 2: *(__u16_alias_t *) res = *(volatile __u16_alias_t *) p; break;
51 case 4: *(__u32 *)res = *(volatile __u32 *)p; break;67 case 4: *(__u32_alias_t *) res = *(volatile __u32_alias_t *) p; break;
52 case 8: *(__u64 *)res = *(volatile __u64 *)p; break;68 case 8: *(__u64_alias_t *) res = *(volatile __u64_alias_t *) p; break;
53 default:69 default:
54 barrier();70 barrier();
55 __builtin_memcpy((void *)res, (const void *)p, size);71 __builtin_memcpy((void *)res, (const void *)p, size);
@@ -60,10 +76,10 @@ static __always_inline void __read_once_size(const volatile void *p, void *res, · 4 unmodified lines
60static __always_inline void __write_once_size(volatile void *p, void *res, int size)76static __always_inline void __write_once_size(volatile void *p, void *res, int size)
61{77{
62 switch (size) {78 switch (size) {
63 case 1: *(volatile __u8 *)p = *(__u8 *)res; break;79 case 1: *(volatile __u8_alias_t *) p = *(__u8_alias_t *) res; break;
64 case 2: *(volatile __u16 *)p = *(__u16 *)res; break;80 case 2: *(volatile __u16_alias_t *) p = *(__u16_alias_t *) res; break;
65 case 4: *(volatile __u32 *)p = *(__u32 *)res; break;81 case 4: *(volatile __u32_alias_t *) p = *(__u32_alias_t *) res; break;
66 case 8: *(volatile __u64 *)p = *(__u64 *)res; break;82 case 8: *(volatile __u64_alias_t *) p = *(__u64_alias_t *) res; break;
67 default:83 default:
68 barrier();84 barrier();
69 __builtin_memcpy((void *)p, (const void *)res, size);85 __builtin_memcpy((void *)p, (const void *)res, size);
tools/include/linux/err.h+49−0
@@ -0,0 +1,49 @@
1#ifndef __TOOLS_LINUX_ERR_H
2#define __TOOLS_LINUX_ERR_H
3
4#include <linux/compiler.h>
5#include <linux/types.h>
6
7#include <asm/errno.h>
8
9/*
10 * Original kernel header comment:
11 *
12 * Kernel pointers have redundant information, so we can use a
13 * scheme where we can return either an error code or a normal
14 * pointer with the same return value.
15 *
16 * This should be a per-architecture thing, to allow different
17 * error and pointer decisions.
18 *
19 * Userspace note:
20 * The same principle works for userspace, because 'error' pointers
21 * fall down to the unused hole far from user space, as described
22 * in Documentation/x86/x86_64/mm.txt for x86_64 arch:
23 *
24 * 0000000000000000 - 00007fffffffffff (=47 bits) user space, different per mm hole caused by [48:63] sign extension
25 * ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole
26 *
27 * It should be the same case for other architectures, because
28 * this code is used in generic kernel code.
29 */
30#define MAX_ERRNO 4095
31
32#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
33
34static inline void * __must_check ERR_PTR(long error_)
35{
36 return (void *) error_;
37}
38
39static inline long __must_check PTR_ERR(__force const void *ptr)
40{
41 return (long) ptr;
42}
43
44static inline bool __must_check IS_ERR(__force const void *ptr)
45{
46 return IS_ERR_VALUE((unsigned long)ptr);
47}
48
49#endif /* _LINUX_ERR_H */
tools/include/linux/filter.h+231−0
@@ -0,0 +1,231 @@
1/*
2 * Linux Socket Filter Data Structures
3 */
4#ifndef __TOOLS_LINUX_FILTER_H
5#define __TOOLS_LINUX_FILTER_H
6
7#include <linux/bpf.h>
8
9/* ArgX, context and stack frame pointer register positions. Note,
10 * Arg1, Arg2, Arg3, etc are used as argument mappings of function
11 * calls in BPF_CALL instruction.
12 */
13#define BPF_REG_ARG1 BPF_REG_1
14#define BPF_REG_ARG2 BPF_REG_2
15#define BPF_REG_ARG3 BPF_REG_3
16#define BPF_REG_ARG4 BPF_REG_4
17#define BPF_REG_ARG5 BPF_REG_5
18#define BPF_REG_CTX BPF_REG_6
19#define BPF_REG_FP BPF_REG_10
20
21/* Additional register mappings for converted user programs. */
22#define BPF_REG_A BPF_REG_0
23#define BPF_REG_X BPF_REG_7
24#define BPF_REG_TMP BPF_REG_8
25
26/* BPF program can access up to 512 bytes of stack space. */
27#define MAX_BPF_STACK 512
28
29/* Helper macros for filter block array initializers. */
30
31/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
32
33#define BPF_ALU64_REG(OP, DST, SRC) \
34 ((struct bpf_insn) { \
35 .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
36 .dst_reg = DST, \
37 .src_reg = SRC, \
38 .off = 0, \
39 .imm = 0 })
40
41#define BPF_ALU32_REG(OP, DST, SRC) \
42 ((struct bpf_insn) { \
43 .code = BPF_ALU | BPF_OP(OP) | BPF_X, \
44 .dst_reg = DST, \
45 .src_reg = SRC, \
46 .off = 0, \
47 .imm = 0 })
48
49/* ALU ops on immediates, bpf_add|sub|...: dst_reg += imm32 */
50
51#define BPF_ALU64_IMM(OP, DST, IMM) \
52 ((struct bpf_insn) { \
53 .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
54 .dst_reg = DST, \
55 .src_reg = 0, \
56 .off = 0, \
57 .imm = IMM })
58
59#define BPF_ALU32_IMM(OP, DST, IMM) \
60 ((struct bpf_insn) { \
61 .code = BPF_ALU | BPF_OP(OP) | BPF_K, \
62 .dst_reg = DST, \
63 .src_reg = 0, \
64 .off = 0, \
65 .imm = IMM })
66
67/* Endianess conversion, cpu_to_{l,b}e(), {l,b}e_to_cpu() */
68
69#define BPF_ENDIAN(TYPE, DST, LEN) \
70 ((struct bpf_insn) { \
71 .code = BPF_ALU | BPF_END | BPF_SRC(TYPE), \
72 .dst_reg = DST, \
73 .src_reg = 0, \
74 .off = 0, \
75 .imm = LEN })
76
77/* Short form of mov, dst_reg = src_reg */
78
79#define BPF_MOV64_REG(DST, SRC) \
80 ((struct bpf_insn) { \
81 .code = BPF_ALU64 | BPF_MOV | BPF_X, \
82 .dst_reg = DST, \
83 .src_reg = SRC, \
84 .off = 0, \
85 .imm = 0 })
86
87#define BPF_MOV32_REG(DST, SRC) \
88 ((struct bpf_insn) { \
89 .code = BPF_ALU | BPF_MOV | BPF_X, \
90 .dst_reg = DST, \
91 .src_reg = SRC, \
92 .off = 0, \
93 .imm = 0 })
94
95/* Short form of mov, dst_reg = imm32 */
96
97#define BPF_MOV64_IMM(DST, IMM) \
98 ((struct bpf_insn) { \
99 .code = BPF_ALU64 | BPF_MOV | BPF_K, \
100 .dst_reg = DST, \
101 .src_reg = 0, \
102 .off = 0, \
103 .imm = IMM })
104
105#define BPF_MOV32_IMM(DST, IMM) \
106 ((struct bpf_insn) { \
107 .code = BPF_ALU | BPF_MOV | BPF_K, \
108 .dst_reg = DST, \
109 .src_reg = 0, \
110 .off = 0, \
111 .imm = IMM })
112
113/* Short form of mov based on type, BPF_X: dst_reg = src_reg, BPF_K: dst_reg = imm32 */
114
115#define BPF_MOV64_RAW(TYPE, DST, SRC, IMM) \
116 ((struct bpf_insn) { \
117 .code = BPF_ALU64 | BPF_MOV | BPF_SRC(TYPE), \
118 .dst_reg = DST, \
119 .src_reg = SRC, \
120 .off = 0, \
121 .imm = IMM })
122
123#define BPF_MOV32_RAW(TYPE, DST, SRC, IMM) \
124 ((struct bpf_insn) { \
125 .code = BPF_ALU | BPF_MOV | BPF_SRC(TYPE), \
126 .dst_reg = DST, \
127 .src_reg = SRC, \
128 .off = 0, \
129 .imm = IMM })
130
131/* Direct packet access, R0 = *(uint *) (skb->data + imm32) */
132
133#define BPF_LD_ABS(SIZE, IMM) \
134 ((struct bpf_insn) { \
135 .code = BPF_LD | BPF_SIZE(SIZE) | BPF_ABS, \
136 .dst_reg = 0, \
137 .src_reg = 0, \
138 .off = 0, \
139 .imm = IMM })
140
141/* Indirect packet access, R0 = *(uint *) (skb->data + src_reg + imm32) */
142
143#define BPF_LD_IND(SIZE, SRC, IMM) \
144 ((struct bpf_insn) { \
145 .code = BPF_LD | BPF_SIZE(SIZE) | BPF_IND, \
146 .dst_reg = 0, \
147 .src_reg = SRC, \
148 .off = 0, \
149 .imm = IMM })
150
151/* Memory load, dst_reg = *(uint *) (src_reg + off16) */
152
153#define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
154 ((struct bpf_insn) { \
155 .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \
156 .dst_reg = DST, \
157 .src_reg = SRC, \
158 .off = OFF, \
159 .imm = 0 })
160
161/* Memory store, *(uint *) (dst_reg + off16) = src_reg */
162
163#define BPF_STX_MEM(SIZE, DST, SRC, OFF) \
164 ((struct bpf_insn) { \
165 .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \
166 .dst_reg = DST, \
167 .src_reg = SRC, \
168 .off = OFF, \
169 .imm = 0 })
170
171/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
172
173#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
174 ((struct bpf_insn) { \
175 .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \
176 .dst_reg = DST, \
177 .src_reg = 0, \
178 .off = OFF, \
179 .imm = IMM })
180
181/* Conditional jumps against registers, if (dst_reg 'op' src_reg) goto pc + off16 */
182
183#define BPF_JMP_REG(OP, DST, SRC, OFF) \
184 ((struct bpf_insn) { \
185 .code = BPF_JMP | BPF_OP(OP) | BPF_X, \
186 .dst_reg = DST, \
187 .src_reg = SRC, \
188 .off = OFF, \
189 .imm = 0 })
190
191/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */
192
193#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
194 ((struct bpf_insn) { \
195 .code = BPF_JMP | BPF_OP(OP) | BPF_K, \
196 .dst_reg = DST, \
197 .src_reg = 0, \
198 .off = OFF, \
199 .imm = IMM })
200
201/* Function call */
202
203#define BPF_EMIT_CALL(FUNC) \
204 ((struct bpf_insn) { \
205 .code = BPF_JMP | BPF_CALL, \
206 .dst_reg = 0, \
207 .src_reg = 0, \
208 .off = 0, \
209 .imm = ((FUNC) - BPF_FUNC_unspec) })
210
211/* Raw code statement block */
212
213#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \
214 ((struct bpf_insn) { \
215 .code = CODE, \
216 .dst_reg = DST, \
217 .src_reg = SRC, \
218 .off = OFF, \
219 .imm = IMM })
220
221/* Program exit */
222
223#define BPF_EXIT_INSN() \
224 ((struct bpf_insn) { \
225 .code = BPF_JMP | BPF_EXIT, \
226 .dst_reg = 0, \
227 .src_reg = 0, \
228 .off = 0, \
229 .imm = 0 })
230
231#endif /* __TOOLS_LINUX_FILTER_H */
tools/lib/api/Build+1−0
@@ -1,2 +1,3 @@
1libapi-y += fd/1libapi-y += fd/
2libapi-y += fs/2libapi-y += fs/
3libapi-y += cpu.o
tools/lib/api/Makefile+4−2
@@ -21,12 +21,14 @@ CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 · 20 unmodified lines
21 21
22RM = rm -f22RM = rm -f
23 23
24build := -f $(srctree)/tools/build/Makefile.build dir=. obj
25API_IN := $(OUTPUT)libapi-in.o24API_IN := $(OUTPUT)libapi-in.o
26 25
26all:
27
27export srctree OUTPUT CC LD CFLAGS V28export srctree OUTPUT CC LD CFLAGS V
29include $(srctree)/tools/build/Makefile.include
28 30
29all: $(LIBFILE)31all: fixdep $(LIBFILE)
30 32
31$(API_IN): FORCE33$(API_IN): FORCE
32 @$(MAKE) $(build)=libapi34 @$(MAKE) $(build)=libapi
tools/lib/api/cpu.c+18−0
@@ -0,0 +1,18 @@
1#include <stdio.h>
2
3#include "cpu.h"
4#include "fs/fs.h"
5
6int cpu__get_max_freq(unsigned long long *freq)
7{
8 char entry[PATH_MAX];
9 int cpu;
10
11 if (sysfs__read_int("devices/system/cpu/online", &cpu) < 0)
12 return -1;
13
14 snprintf(entry, sizeof(entry),
15 "devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu);
16
17 return sysfs__read_ull(entry, freq);
18}
tools/lib/api/cpu.h+6−0
@@ -0,0 +1,6 @@
1#ifndef __API_CPU__
2#define __API_CPU__
3
4int cpu__get_max_freq(unsigned long long *freq);
5
6#endif /* __API_CPU__ */
tools/lib/api/fs/Build+1−3
@@ -1,4 +1,2 @@
1libapi-y += fs.o1libapi-y += fs.o
2libapi-y += debugfs.o2libapi-y += tracing_path.o
3libapi-y += findfs.o
4libapi-y += tracefs.o
tools/lib/api/fs/debugfs.c+0−129
@@ -1,129 +0,0 @@
1#define _GNU_SOURCE
2#include <errno.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <unistd.h>
7#include <stdbool.h>
8#include <sys/vfs.h>
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <sys/mount.h>
12#include <linux/kernel.h>
13
14#include "debugfs.h"
15#include "tracefs.h"
16
17#ifndef DEBUGFS_DEFAULT_PATH
18#define DEBUGFS_DEFAULT_PATH "/sys/kernel/debug"
19#endif
20
21char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;
22
23static const char * const debugfs_known_mountpoints[] = {
24 DEBUGFS_DEFAULT_PATH,
25 "/debug",
26 0,
27};
28
29static bool debugfs_found;
30
31bool debugfs_configured(void)
32{
33 return debugfs_find_mountpoint() != NULL;
34}
35
36/* find the path to the mounted debugfs */
37const char *debugfs_find_mountpoint(void)
38{
39 const char *ret;
40
41 if (debugfs_found)
42 return (const char *)debugfs_mountpoint;
43
44 ret = find_mountpoint("debugfs", (long) DEBUGFS_MAGIC,
45 debugfs_mountpoint, PATH_MAX + 1,
46 debugfs_known_mountpoints);
47 if (ret)
48 debugfs_found = true;
49
50 return ret;
51}
52
53/* mount the debugfs somewhere if it's not mounted */
54char *debugfs_mount(const char *mountpoint)
55{
56 /* see if it's already mounted */
57 if (debugfs_find_mountpoint())
58 goto out;
59
60 /* if not mounted and no argument */
61 if (mountpoint == NULL) {
62 /* see if environment variable set */
63 mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
64 /* if no environment variable, use default */
65 if (mountpoint == NULL)
66 mountpoint = DEBUGFS_DEFAULT_PATH;
67 }
68
69 if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
70 return NULL;
71
72 /* save the mountpoint */
73 debugfs_found = true;
74 strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
75out:
76 return debugfs_mountpoint;
77}
78
79int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename)
80{
81 char sbuf[128];
82
83 switch (err) {
84 case ENOENT:
85 if (debugfs_found) {
86 snprintf(buf, size,
87 "Error:\tFile %s/%s not found.\n"
88 "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n",
89 debugfs_mountpoint, filename);
90 break;
91 }
92 snprintf(buf, size, "%s",
93 "Error:\tUnable to find debugfs\n"
94 "Hint:\tWas your kernel compiled with debugfs support?\n"
95 "Hint:\tIs the debugfs filesystem mounted?\n"
96 "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
97 break;
98 case EACCES: {
99 const char *mountpoint = debugfs_mountpoint;
100
101 if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) {
102 const char *tracefs_mntpoint = tracefs_find_mountpoint();
103
104 if (tracefs_mntpoint)
105 mountpoint = tracefs_mntpoint;
106 }
107
108 snprintf(buf, size,
109 "Error:\tNo permissions to read %s/%s\n"
110 "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
111 debugfs_mountpoint, filename, mountpoint);
112 }
113 break;
114 default:
115 snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf)));
116 break;
117 }
118
119 return 0;
120}
121
122int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name)
123{
124 char path[PATH_MAX];
125
126 snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*");
127
128 return debugfs__strerror_open(err, buf, size, path);
129}
tools/lib/api/fs/debugfs.h+0−23
@@ -1,23 +0,0 @@
1#ifndef __API_DEBUGFS_H__
2#define __API_DEBUGFS_H__
3
4#include "findfs.h"
5
6#ifndef DEBUGFS_MAGIC
7#define DEBUGFS_MAGIC 0x64626720
8#endif
9
10#ifndef PERF_DEBUGFS_ENVIRONMENT
11#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
12#endif
13
14bool debugfs_configured(void);
15const char *debugfs_find_mountpoint(void);
16char *debugfs_mount(const char *mountpoint);
17
18extern char debugfs_mountpoint[];
19
20int debugfs__strerror_open(int err, char *buf, size_t size, const char *filename);
21int debugfs__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
22
23#endif /* __API_DEBUGFS_H__ */
tools/lib/api/fs/findfs.c+0−63
@@ -1,63 +0,0 @@
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <stdbool.h>
6#include <sys/vfs.h>
7
8#include "findfs.h"
9
10/* verify that a mountpoint is actually the type we want */
11
12int valid_mountpoint(const char *mount, long magic)
13{
14 struct statfs st_fs;
15
16 if (statfs(mount, &st_fs) < 0)
17 return -ENOENT;
18 else if ((long)st_fs.f_type != magic)
19 return -ENOENT;
20
21 return 0;
22}
23
24/* find the path to a mounted file system */
25const char *find_mountpoint(const char *fstype, long magic,
26 char *mountpoint, int len,
27 const char * const *known_mountpoints)
28{
29 const char * const *ptr;
30 char format[128];
31 char type[100];
32 FILE *fp;
33
34 if (known_mountpoints) {
35 ptr = known_mountpoints;
36 while (*ptr) {
37 if (valid_mountpoint(*ptr, magic) == 0) {
38 strncpy(mountpoint, *ptr, len - 1);
39 mountpoint[len-1] = 0;
40 return mountpoint;
41 }
42 ptr++;
43 }
44 }
45
46 /* give up and parse /proc/mounts */
47 fp = fopen("/proc/mounts", "r");
48 if (fp == NULL)
49 return NULL;
50
51 snprintf(format, 128, "%%*s %%%ds %%99s %%*s %%*d %%*d\n", len);
52
53 while (fscanf(fp, format, mountpoint, type) == 2) {
54 if (strcmp(type, fstype) == 0)
55 break;
56 }
57 fclose(fp);
58
59 if (strcmp(type, fstype) != 0)
60 return NULL;
61
62 return mountpoint;
63}
tools/lib/api/fs/findfs.h+0−23
@@ -1,23 +0,0 @@
1#ifndef __API_FINDFS_H__
2#define __API_FINDFS_H__
3
4#include <stdbool.h>
5
6#define _STR(x) #x
7#define STR(x) _STR(x)
8
9/*
10 * On most systems <limits.h> would have given us this, but not on some systems
11 * (e.g. GNU/Hurd).
12 */
13#ifndef PATH_MAX
14#define PATH_MAX 4096
15#endif
16
17const char *find_mountpoint(const char *fstype, long magic,
18 char *mountpoint, int len,
19 const char * const *known_mountpoints);
20
21int valid_mountpoint(const char *mount, long magic);
22
23#endif /* __API_FINDFS_H__ */
tools/lib/api/fs/fs.c+153−12
@@ -1,7 +1,6 @@
1/* TODO merge/factor in debugfs.c here */
2
3#include <ctype.h>1#include <ctype.h>
4#include <errno.h>2#include <errno.h>
3#include <limits.h>
5#include <stdbool.h>4#include <stdbool.h>
6#include <stdio.h>5#include <stdio.h>
7#include <stdlib.h>6#include <stdlib.h>
@@ -11,10 +10,29 @@ · 3 unmodified lines
11#include <sys/stat.h>10#include <sys/stat.h>
12#include <fcntl.h>11#include <fcntl.h>
13#include <unistd.h>12#include <unistd.h>
13#include <sys/mount.h>
14 14
15#include "debugfs.h"
16#include "fs.h"15#include "fs.h"
17 16
17#define _STR(x) #x
18#define STR(x) _STR(x)
19
20#ifndef SYSFS_MAGIC
21#define SYSFS_MAGIC 0x62656572
22#endif
23
24#ifndef PROC_SUPER_MAGIC
25#define PROC_SUPER_MAGIC 0x9fa0
26#endif
27
28#ifndef DEBUGFS_MAGIC
29#define DEBUGFS_MAGIC 0x64626720
30#endif
31
32#ifndef TRACEFS_MAGIC
33#define TRACEFS_MAGIC 0x74726163
34#endif
35
18static const char * const sysfs__fs_known_mountpoints[] = {36static const char * const sysfs__fs_known_mountpoints[] = {
19 "/sys",37 "/sys",
20 0,38 0,
@@ -25,19 +43,48 @@ static const char * const procfs__known_mountpoints[] = { · 4 unmodified lines
25 0,43 0,
26};44};
27 45
46#ifndef DEBUGFS_DEFAULT_PATH
47#define DEBUGFS_DEFAULT_PATH "/sys/kernel/debug"
48#endif
49
50static const char * const debugfs__known_mountpoints[] = {
51 DEBUGFS_DEFAULT_PATH,
52 "/debug",
53 0,
54};
55
56
57#ifndef TRACEFS_DEFAULT_PATH
58#define TRACEFS_DEFAULT_PATH "/sys/kernel/tracing"
59#endif
60
61static const char * const tracefs__known_mountpoints[] = {
62 TRACEFS_DEFAULT_PATH,
63 "/sys/kernel/debug/tracing",
64 "/tracing",
65 "/trace",
66 0,
67};
68
28struct fs {69struct fs {
29 const char *name;70 const char *name;
30 const char * const *mounts;71 const char * const *mounts;
31 char path[PATH_MAX + 1];72 char path[PATH_MAX];
32 bool found;73 bool found;
33 long magic;74 long magic;
34};75};
35 76
36enum {77enum {
37 FS__SYSFS = 0,78 FS__SYSFS = 0,
38 FS__PROCFS = 1,79 FS__PROCFS = 1,
80 FS__DEBUGFS = 2,
81 FS__TRACEFS = 3,
39};82};
40 83
84#ifndef TRACEFS_MAGIC
85#define TRACEFS_MAGIC 0x74726163
86#endif
87
41static struct fs fs__entries[] = {88static struct fs fs__entries[] = {
42 [FS__SYSFS] = {89 [FS__SYSFS] = {
43 .name = "sysfs",90 .name = "sysfs",
@@ -49,6 +96,16 @@ static struct fs fs__entries[] = { · 5 unmodified lines
49 .mounts = procfs__known_mountpoints,96 .mounts = procfs__known_mountpoints,
50 .magic = PROC_SUPER_MAGIC,97 .magic = PROC_SUPER_MAGIC,
51 },98 },
99 [FS__DEBUGFS] = {
100 .name = "debugfs",
101 .mounts = debugfs__known_mountpoints,
102 .magic = DEBUGFS_MAGIC,
103 },
104 [FS__TRACEFS] = {
105 .name = "tracefs",
106 .mounts = tracefs__known_mountpoints,
107 .magic = TRACEFS_MAGIC,
108 },
52};109};
53 110
54static bool fs__read_mounts(struct fs *fs)111static bool fs__read_mounts(struct fs *fs)
@@ -159,14 +216,54 @@ static const char *fs__mountpoint(int idx) · 104 unmodified lines
159 return fs__get_mountpoint(fs);216 return fs__get_mountpoint(fs);
160}217}
161 218
162#define FS__MOUNTPOINT(name, idx) \219static const char *mount_overload(struct fs *fs)
163const char *name##__mountpoint(void) \220{
164{ \221 size_t name_len = strlen(fs->name);
165 return fs__mountpoint(idx); \222 /* "PERF_" + name + "_ENVIRONMENT" + '\0' */
223 char upper_name[5 + name_len + 12 + 1];
224
225 snprintf(upper_name, name_len, "PERF_%s_ENVIRONMENT", fs->name);
226 mem_toupper(upper_name, name_len);
227
228 return getenv(upper_name) ?: *fs->mounts;
229}
230
231static const char *fs__mount(int idx)
232{
233 struct fs *fs = &fs__entries[idx];
234 const char *mountpoint;
235
236 if (fs__mountpoint(idx))
237 return (const char *)fs->path;
238
239 mountpoint = mount_overload(fs);
240
241 if (mount(NULL, mountpoint, fs->name, 0, NULL) < 0)
242 return NULL;
243
244 return fs__check_mounts(fs) ? fs->path : NULL;
245}
246
247#define FS(name, idx) \
248const char *name##__mountpoint(void) \
249{ \
250 return fs__mountpoint(idx); \
251} \
252 \
253const char *name##__mount(void) \
254{ \
255 return fs__mount(idx); \
256} \
257 \
258bool name##__configured(void) \
259{ \
260 return name##__mountpoint() != NULL; \
166}261}
167 262
168FS__MOUNTPOINT(sysfs, FS__SYSFS);263FS(sysfs, FS__SYSFS);
169FS__MOUNTPOINT(procfs, FS__PROCFS);264FS(procfs, FS__PROCFS);
265FS(debugfs, FS__DEBUGFS);
266FS(tracefs, FS__TRACEFS);
170 267
171int filename__read_int(const char *filename, int *value)268int filename__read_int(const char *filename, int *value)
172{269{
@@ -185,6 +282,50 @@ int filename__read_int(const char *filename, int *value) · 12 unmodified lines
185 return err;282 return err;
186}283}
187 284
285int filename__read_ull(const char *filename, unsigned long long *value)
286{
287 char line[64];
288 int fd = open(filename, O_RDONLY), err = -1;
289
290 if (fd < 0)
291 return -1;
292
293 if (read(fd, line, sizeof(line)) > 0) {
294 *value = strtoull(line, NULL, 10);
295 if (*value != ULLONG_MAX)
296 err = 0;
297 }
298
299 close(fd);
300 return err;
301}
302
303int sysfs__read_ull(const char *entry, unsigned long long *value)
304{
305 char path[PATH_MAX];
306 const char *sysfs = sysfs__mountpoint();
307
308 if (!sysfs)
309 return -1;
310
311 snprintf(path, sizeof(path), "%s/%s", sysfs, entry);
312
313 return filename__read_ull(path, value);
314}
315
316int sysfs__read_int(const char *entry, int *value)
317{
318 char path[PATH_MAX];
319 const char *sysfs = sysfs__mountpoint();
320
321 if (!sysfs)
322 return -1;
323
324 snprintf(path, sizeof(path), "%s/%s", sysfs, entry);
325
326 return filename__read_int(path, value);
327}
328
188int sysctl__read_int(const char *sysctl, int *value)329int sysctl__read_int(const char *sysctl, int *value)
189{330{
190 char path[PATH_MAX];331 char path[PATH_MAX];
tools/lib/api/fs/fs.h+23−7
@@ -1,17 +1,33 @@
1#ifndef __API_FS__1#ifndef __API_FS__
2#define __API_FS__2#define __API_FS__
3 3
4#ifndef SYSFS_MAGIC4#include <stdbool.h>
5#define SYSFS_MAGIC 0x62656572
6#endif
7 5
8#ifndef PROC_SUPER_MAGIC6/*
9#define PROC_SUPER_MAGIC 0x9fa07 * On most systems <limits.h> would have given us this, but not on some systems
8 * (e.g. GNU/Hurd).
9 */
10#ifndef PATH_MAX
11#define PATH_MAX 4096
10#endif12#endif
11 13
12const char *sysfs__mountpoint(void);14#define FS(name) \
13const char *procfs__mountpoint(void);15 const char *name##__mountpoint(void); \
16 const char *name##__mount(void); \
17 bool name##__configured(void); \
18
19FS(sysfs)
20FS(procfs)
21FS(debugfs)
22FS(tracefs)
23
24#undef FS
25
14 26
15int filename__read_int(const char *filename, int *value);27int filename__read_int(const char *filename, int *value);
28int filename__read_ull(const char *filename, unsigned long long *value);
29
16int sysctl__read_int(const char *sysctl, int *value);30int sysctl__read_int(const char *sysctl, int *value);
31int sysfs__read_int(const char *entry, int *value);
32int sysfs__read_ull(const char *entry, unsigned long long *value);
17#endif /* __API_FS__ */33#endif /* __API_FS__ */
tools/lib/api/fs/tracefs.c+0−78
@@ -1,78 +0,0 @@
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6#include <stdbool.h>
7#include <sys/vfs.h>
8#include <sys/types.h>
9#include <sys/stat.h>
10#include <sys/mount.h>
11#include <linux/kernel.h>
12
13#include "tracefs.h"
14
15#ifndef TRACEFS_DEFAULT_PATH
16#define TRACEFS_DEFAULT_PATH "/sys/kernel/tracing"
17#endif
18
19char tracefs_mountpoint[PATH_MAX + 1] = TRACEFS_DEFAULT_PATH;
20
21static const char * const tracefs_known_mountpoints[] = {
22 TRACEFS_DEFAULT_PATH,
23 "/sys/kernel/debug/tracing",
24 "/tracing",
25 "/trace",
26 0,
27};
28
29static bool tracefs_found;
30
31bool tracefs_configured(void)
32{
33 return tracefs_find_mountpoint() != NULL;
34}
35
36/* find the path to the mounted tracefs */
37const char *tracefs_find_mountpoint(void)
38{
39 const char *ret;
40
41 if (tracefs_found)
42 return (const char *)tracefs_mountpoint;
43
44 ret = find_mountpoint("tracefs", (long) TRACEFS_MAGIC,
45 tracefs_mountpoint, PATH_MAX + 1,
46 tracefs_known_mountpoints);
47
48 if (ret)
49 tracefs_found = true;
50
51 return ret;
52}
53
54/* mount the tracefs somewhere if it's not mounted */
55char *tracefs_mount(const char *mountpoint)
56{
57 /* see if it's already mounted */
58 if (tracefs_find_mountpoint())
59 goto out;
60
61 /* if not mounted and no argument */
62 if (mountpoint == NULL) {
63 /* see if environment variable set */
64 mountpoint = getenv(PERF_TRACEFS_ENVIRONMENT);
65 /* if no environment variable, use default */
66 if (mountpoint == NULL)
67 mountpoint = TRACEFS_DEFAULT_PATH;
68 }
69
70 if (mount(NULL, mountpoint, "tracefs", 0, NULL) < 0)
71 return NULL;
72
73 /* save the mountpoint */
74 tracefs_found = true;
75 strncpy(tracefs_mountpoint, mountpoint, sizeof(tracefs_mountpoint));
76out:
77 return tracefs_mountpoint;
78}
tools/lib/api/fs/tracefs.h+0−21
@@ -1,21 +0,0 @@
1#ifndef __API_TRACEFS_H__
2#define __API_TRACEFS_H__
3
4#include "findfs.h"
5
6#ifndef TRACEFS_MAGIC
7#define TRACEFS_MAGIC 0x74726163
8#endif
9
10#ifndef PERF_TRACEFS_ENVIRONMENT
11#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
12#endif
13
14bool tracefs_configured(void);
15const char *tracefs_find_mountpoint(void);
16int tracefs_valid_mountpoint(const char *debugfs);
17char *tracefs_mount(const char *mountpoint);
18
19extern char tracefs_mountpoint[];
20
21#endif /* __API_DEBUGFS_H__ */
tools/lib/api/fs/tracing_path.c+135−0
@@ -0,0 +1,135 @@
1#ifndef _GNU_SOURCE
2# define _GNU_SOURCE
3#endif
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <errno.h>
9#include <unistd.h>
10#include "fs.h"
11
12#include "tracing_path.h"
13
14
15char tracing_mnt[PATH_MAX] = "/sys/kernel/debug";
16char tracing_path[PATH_MAX] = "/sys/kernel/debug/tracing";
17char tracing_events_path[PATH_MAX] = "/sys/kernel/debug/tracing/events";
18
19
20static void __tracing_path_set(const char *tracing, const char *mountpoint)
21{
22 snprintf(tracing_mnt, sizeof(tracing_mnt), "%s", mountpoint);
23 snprintf(tracing_path, sizeof(tracing_path), "%s/%s",
24 mountpoint, tracing);
25 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
26 mountpoint, tracing, "events");
27}
28
29static const char *tracing_path_tracefs_mount(void)
30{
31 const char *mnt;
32
33 mnt = tracefs__mount();
34 if (!mnt)
35 return NULL;
36
37 __tracing_path_set("", mnt);
38
39 return mnt;
40}
41
42static const char *tracing_path_debugfs_mount(void)
43{
44 const char *mnt;
45
46 mnt = debugfs__mount();
47 if (!mnt)
48 return NULL;
49
50 __tracing_path_set("tracing/", mnt);
51
52 return mnt;
53}
54
55const char *tracing_path_mount(void)
56{
57 const char *mnt;
58
59 mnt = tracing_path_tracefs_mount();
60 if (mnt)
61 return mnt;
62
63 mnt = tracing_path_debugfs_mount();
64
65 return mnt;
66}
67
68void tracing_path_set(const char *mntpt)
69{
70 __tracing_path_set("tracing/", mntpt);
71}
72
73char *get_tracing_file(const char *name)
74{
75 char *file;
76
77 if (asprintf(&file, "%s/%s", tracing_path, name) < 0)
78 return NULL;
79
80 return file;
81}
82
83void put_tracing_file(char *file)
84{
85 free(file);
86}
87
88static int strerror_open(int err, char *buf, size_t size, const char *filename)
89{
90 char sbuf[128];
91
92 switch (err) {
93 case ENOENT:
94 /*
95 * We will get here if we can't find the tracepoint, but one of
96 * debugfs or tracefs is configured, which means you probably
97 * want some tracepoint which wasn't compiled in your kernel.
98 * - jirka
99 */
100 if (debugfs__configured() || tracefs__configured()) {
101 snprintf(buf, size,
102 "Error:\tFile %s/%s not found.\n"
103 "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n",
104 tracing_events_path, filename);
105 break;
106 }
107 snprintf(buf, size, "%s",
108 "Error:\tUnable to find debugfs/tracefs\n"
109 "Hint:\tWas your kernel compiled with debugfs/tracefs support?\n"
110 "Hint:\tIs the debugfs/tracefs filesystem mounted?\n"
111 "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
112 break;
113 case EACCES: {
114 snprintf(buf, size,
115 "Error:\tNo permissions to read %s/%s\n"
116 "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
117 tracing_events_path, filename, tracing_mnt);
118 }
119 break;
120 default:
121 snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf)));
122 break;
123 }
124
125 return 0;
126}
127
128int tracing_path__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name)
129{
130 char path[PATH_MAX];
131
132 snprintf(path, PATH_MAX, "%s/%s", sys, name ?: "*");
133
134 return strerror_open(err, buf, size, path);
135}
tools/lib/api/fs/tracing_path.h+16−0
@@ -0,0 +1,16 @@
1#ifndef __API_FS_TRACING_PATH_H
2#define __API_FS_TRACING_PATH_H
3
4#include <linux/types.h>
5
6extern char tracing_path[];
7extern char tracing_events_path[];
8
9void tracing_path_set(const char *mountpoint);
10const char *tracing_path_mount(void);
11
12char *get_tracing_file(const char *name);
13void put_tracing_file(char *file);
14
15int tracing_path__strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
16#endif /* __API_FS_TRACING_PATH_H */
tools/lib/bpf/Makefile+7−4
@@ -64,8 +64,9 @@ srctree := $(patsubst %/,%,$(dir $(srctree))) · 63 unmodified lines
64#$(info Determined 'srctree' to be $(srctree))64#$(info Determined 'srctree' to be $(srctree))
65endif65endif
66 66
67FEATURE_DISPLAY = libelf libelf-getphdrnum libelf-mmap bpf67FEATURE_USER = .libbpf
68FEATURE_TESTS = libelf bpf68FEATURE_TESTS = libelf libelf-getphdrnum libelf-mmap bpf
69FEATURE_DISPLAY = libelf bpf
69 70
70INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi71INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
71FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES)72FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES)
@@ -122,8 +123,10 @@ endif · 50 unmodified lines
122# the same command line setup.123# the same command line setup.
123MAKEOVERRIDES=124MAKEOVERRIDES=
124 125
126all:
127
125export srctree OUTPUT CC LD CFLAGS V128export srctree OUTPUT CC LD CFLAGS V
126build := -f $(srctree)/tools/build/Makefile.build dir=. obj129include $(srctree)/tools/build/Makefile.include
127 130
128BPF_IN := $(OUTPUT)libbpf-in.o131BPF_IN := $(OUTPUT)libbpf-in.o
129LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))132LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
@@ -132,7 +135,7 @@ CMD_TARGETS = $(LIB_FILE) · 2 unmodified lines
132 135
133TARGETS = $(CMD_TARGETS)136TARGETS = $(CMD_TARGETS)
134 137
135all: $(VERSION_FILES) all_cmd138all: fixdep $(VERSION_FILES) all_cmd
136 139
137all_cmd: $(CMD_TARGETS)140all_cmd: $(CMD_TARGETS)
138 141
tools/lib/lockdep/Makefile+4−2
@@ -93,8 +93,10 @@ else · 92 unmodified lines
93 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';93 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
94endif94endif
95 95
96all:
97
96export srctree OUTPUT CC LD CFLAGS V98export srctree OUTPUT CC LD CFLAGS V
97build := -f $(srctree)/tools/build/Makefile.build dir=. obj99include $(srctree)/tools/build/Makefile.include
98 100
99do_compile_shared_library = \101do_compile_shared_library = \
100 ($(print_shared_lib_compile) \102 ($(print_shared_lib_compile) \
@@ -109,7 +111,7 @@ CMD_TARGETS = $(LIB_FILE) · 8 unmodified lines
109TARGETS = $(CMD_TARGETS)111TARGETS = $(CMD_TARGETS)
110 112
111 113
112all: all_cmd114all: fixdep all_cmd
113 115
114all_cmd: $(CMD_TARGETS)116all_cmd: $(CMD_TARGETS)
115 117
tools/lib/symbol/kallsyms.c+6−0
@@ -2,6 +2,12 @@ · 1 unmodified line
2#include <stdio.h>2#include <stdio.h>
3#include <stdlib.h>3#include <stdlib.h>
4 4
5u8 kallsyms2elf_type(char type)
6{
7 type = tolower(type);
8 return (type == 't' || type == 'w') ? STT_FUNC : STT_OBJECT;
9}
10
5int kallsyms__parse(const char *filename, void *arg,11int kallsyms__parse(const char *filename, void *arg,
6 int (*process_symbol)(void *arg, const char *name,12 int (*process_symbol)(void *arg, const char *name,
7 char type, u64 start))13 char type, u64 start))
tools/lib/symbol/kallsyms.h+3−1
@@ -9,7 +9,7 @@ · 8 unmodified lines
9#define KSYM_NAME_LEN 2569#define KSYM_NAME_LEN 256
10#endif10#endif
11 11
12static inline u8 kallsyms2elf_type(char type)12static inline u8 kallsyms2elf_binding(char type)
13{13{
14 if (type == 'W')14 if (type == 'W')
15 return STB_WEAK;15 return STB_WEAK;
@@ -17,6 +17,8 @@ static inline u8 kallsyms2elf_type(char type) · 1 unmodified line
17 return isupper(type) ? STB_GLOBAL : STB_LOCAL;17 return isupper(type) ? STB_GLOBAL : STB_LOCAL;
18}18}
19 19
20u8 kallsyms2elf_type(char type);
21
20int kallsyms__parse(const char *filename, void *arg,22int kallsyms__parse(const char *filename, void *arg,
21 int (*process_symbol)(void *arg, const char *name,23 int (*process_symbol)(void *arg, const char *name,
22 char type, u64 start));24 char type, u64 start));
tools/lib/traceevent/event-parse.c+56−4
@@ -848,6 +848,7 @@ static void free_arg(struct print_arg *arg) · 847 unmodified lines
848 free(arg->bitmask.bitmask);848 free(arg->bitmask.bitmask);
849 break;849 break;
850 case PRINT_DYNAMIC_ARRAY:850 case PRINT_DYNAMIC_ARRAY:
851 case PRINT_DYNAMIC_ARRAY_LEN:
851 free(arg->dynarray.index);852 free(arg->dynarray.index);
852 break;853 break;
853 case PRINT_OP:854 case PRINT_OP:
@@ -2728,6 +2729,42 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char ** · 1874 unmodified lines
2728 return EVENT_ERROR;2729 return EVENT_ERROR;
2729}2730}
2730 2731
2732static enum event_type
2733process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
2734 char **tok)
2735{
2736 struct format_field *field;
2737 enum event_type type;
2738 char *token;
2739
2740 if (read_expect_type(EVENT_ITEM, &token) < 0)
2741 goto out_free;
2742
2743 arg->type = PRINT_DYNAMIC_ARRAY_LEN;
2744
2745 /* Find the field */
2746 field = pevent_find_field(event, token);
2747 if (!field)
2748 goto out_free;
2749
2750 arg->dynarray.field = field;
2751 arg->dynarray.index = 0;
2752
2753 if (read_expected(EVENT_DELIM, ")") < 0)
2754 goto out_err;
2755
2756 type = read_token(&token);
2757 *tok = token;
2758
2759 return type;
2760
2761 out_free:
2762 free_token(token);
2763 out_err:
2764 *tok = NULL;
2765 return EVENT_ERROR;
2766}
2767
2731static enum event_type2768static enum event_type
2732process_paren(struct event_format *event, struct print_arg *arg, char **tok)2769process_paren(struct event_format *event, struct print_arg *arg, char **tok)
2733{2770{
@@ -2975,6 +3012,10 @@ process_function(struct event_format *event, struct print_arg *arg, · 241 unmodified lines
2975 free_token(token);3012 free_token(token);
2976 return process_dynamic_array(event, arg, tok);3013 return process_dynamic_array(event, arg, tok);
2977 }3014 }
3015 if (strcmp(token, "__get_dynamic_array_len") == 0) {
3016 free_token(token);
3017 return process_dynamic_array_len(event, arg, tok);
3018 }
2978 3019
2979 func = find_func_handler(event->pevent, token);3020 func = find_func_handler(event->pevent, token);
2980 if (func) {3021 if (func) {
@@ -3655,14 +3696,25 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg · 674 unmodified lines
3655 goto out_warning_op;3696 goto out_warning_op;
3656 }3697 }
3657 break;3698 break;
3699 case PRINT_DYNAMIC_ARRAY_LEN:
3700 offset = pevent_read_number(pevent,
3701 data + arg->dynarray.field->offset,
3702 arg->dynarray.field->size);
3703 /*
3704 * The total allocated length of the dynamic array is
3705 * stored in the top half of the field, and the offset
3706 * is in the bottom half of the 32 bit field.
3707 */
3708 val = (unsigned long long)(offset >> 16);
3709 break;
3658 case PRINT_DYNAMIC_ARRAY:3710 case PRINT_DYNAMIC_ARRAY:
3659 /* Without [], we pass the address to the dynamic data */3711 /* Without [], we pass the address to the dynamic data */
3660 offset = pevent_read_number(pevent,3712 offset = pevent_read_number(pevent,
3661 data + arg->dynarray.field->offset,3713 data + arg->dynarray.field->offset,
3662 arg->dynarray.field->size);3714 arg->dynarray.field->size);
3663 /*3715 /*
3664 * The actual length of the dynamic array is stored3716 * The total allocated length of the dynamic array is
3665 * in the top half of the field, and the offset3717 * stored in the top half of the field, and the offset
3666 * is in the bottom half of the 32 bit field.3718 * is in the bottom half of the 32 bit field.
3667 */3719 */
3668 offset &= 0xffff;3720 offset &= 0xffff;
@@ -4853,8 +4905,8 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event · 1184 unmodified lines
4853 else4905 else
4854 ls = 2;4906 ls = 2;
4855 4907
4856 if (*(ptr+1) == 'F' ||4908 if (*(ptr+1) == 'F' || *(ptr+1) == 'f' ||
4857 *(ptr+1) == 'f') {4909 *(ptr+1) == 'S' || *(ptr+1) == 's') {
4858 ptr++;4910 ptr++;
4859 show_func = *ptr;4911 show_func = *ptr;
4860 } else if (*(ptr+1) == 'M' || *(ptr+1) == 'm') {4912 } else if (*(ptr+1) == 'M' || *(ptr+1) == 'm') {
tools/lib/traceevent/event-parse.h+1−0
@@ -294,6 +294,7 @@ enum print_arg_type { · 293 unmodified lines
294 PRINT_OP,294 PRINT_OP,
295 PRINT_FUNC,295 PRINT_FUNC,
296 PRINT_BITMASK,296 PRINT_BITMASK,
297 PRINT_DYNAMIC_ARRAY_LEN,
297};298};
298 299
299struct print_arg {300struct print_arg {
tools/lib/traceevent/plugin_kvm.c+17−8
@@ -124,7 +124,10 @@ static const char *disassemble(unsigned char *insn, int len, uint64_t rip, · 123 unmodified lines
124 _ER(WBINVD, 54) \124 _ER(WBINVD, 54) \
125 _ER(XSETBV, 55) \125 _ER(XSETBV, 55) \
126 _ER(APIC_WRITE, 56) \126 _ER(APIC_WRITE, 56) \
127 _ER(INVPCID, 58)127 _ER(INVPCID, 58) \
128 _ER(PML_FULL, 62) \
129 _ER(XSAVES, 63) \
130 _ER(XRSTORS, 64)
128 131
129#define SVM_EXIT_REASONS \132#define SVM_EXIT_REASONS \
130 _ER(EXIT_READ_CR0, 0x000) \133 _ER(EXIT_READ_CR0, 0x000) \
@@ -352,15 +355,18 @@ static int kvm_nested_vmexit_handler(struct trace_seq *s, struct pevent_record * · 221 unmodified lines
352union kvm_mmu_page_role {355union kvm_mmu_page_role {
353 unsigned word;356 unsigned word;
354 struct {357 struct {
355 unsigned glevels:4;
356 unsigned level:4;358 unsigned level:4;
359 unsigned cr4_pae:1;
357 unsigned quadrant:2;360 unsigned quadrant:2;
358 unsigned pad_for_nice_hex_output:6;
359 unsigned direct:1;361 unsigned direct:1;
360 unsigned access:3;362 unsigned access:3;
361 unsigned invalid:1;363 unsigned invalid:1;
362 unsigned cr4_pge:1;
363 unsigned nxe:1;364 unsigned nxe:1;
365 unsigned cr0_wp:1;
366 unsigned smep_and_not_wp:1;
367 unsigned smap_and_not_wp:1;
368 unsigned pad_for_nice_hex_output:8;
369 unsigned smm:8;
364 };370 };
365};371};
366 372
@@ -385,15 +391,18 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct pevent_record *record, · 18 unmodified lines
385 if (pevent_is_file_bigendian(event->pevent) ==391 if (pevent_is_file_bigendian(event->pevent) ==
386 pevent_is_host_bigendian(event->pevent)) {392 pevent_is_host_bigendian(event->pevent)) {
387 393
388 trace_seq_printf(s, "%u/%u q%u%s %s%s %spge %snxe",394 trace_seq_printf(s, "%u q%u%s %s%s %spae %snxe %swp%s%s%s",
389 role.level,395 role.level,
390 role.glevels,
391 role.quadrant,396 role.quadrant,
392 role.direct ? " direct" : "",397 role.direct ? " direct" : "",
393 access_str[role.access],398 access_str[role.access],
394 role.invalid ? " invalid" : "",399 role.invalid ? " invalid" : "",
395 role.cr4_pge ? "" : "!",400 role.cr4_pae ? "" : "!",
396 role.nxe ? "" : "!");401 role.nxe ? "" : "!",
402 role.cr0_wp ? "" : "!",
403 role.smep_and_not_wp ? " smep" : "",
404 role.smap_and_not_wp ? " smap" : "",
405 role.smm ? " smm" : "");
397 } else406 } else
398 trace_seq_printf(s, "WORD: %08x", role.word);407 trace_seq_printf(s, "WORD: %08x", role.word);
399 408
tools/perf/Documentation/intel-pt.txt+44−0
@@ -671,6 +671,7 @@ The letters are: · 670 unmodified lines
671 e synthesize tracing error events671 e synthesize tracing error events
672 d create a debug log672 d create a debug log
673 g synthesize a call chain (use with i or x)673 g synthesize a call chain (use with i or x)
674 l synthesize last branch entries (use with i or x)
674 675
675"Instructions" events look like they were recorded by "perf record -e676"Instructions" events look like they were recorded by "perf record -e
676instructions".677instructions".
@@ -707,12 +708,26 @@ on the sample is *not* adjusted and reflects the last known value of TSC. · 30 unmodified lines
707 708
708For Intel PT, the default period is 100us.709For Intel PT, the default period is 100us.
709 710
711Setting it to a zero period means "as often as possible".
712
713In the case of Intel PT that is the same as a period of 1 and a unit of
714'instructions' (i.e. --itrace=i1i).
715
710Also the call chain size (default 16, max. 1024) for instructions or716Also the call chain size (default 16, max. 1024) for instructions or
711transactions events can be specified. e.g.717transactions events can be specified. e.g.
712 718
713 --itrace=ig32719 --itrace=ig32
714 --itrace=xg32720 --itrace=xg32
715 721
722Also the number of last branch entries (default 64, max. 1024) for instructions or
723transactions events can be specified. e.g.
724
725 --itrace=il10
726 --itrace=xl10
727
728Note that last branch entries are cleared for each sample, so there is no overlap
729from one sample to the next.
730
716To disable trace decoding entirely, use the option --no-itrace.731To disable trace decoding entirely, use the option --no-itrace.
717 732
718 733
@@ -749,3 +764,32 @@ perf inject also accepts the --itrace option in which case tracing data is · 30 unmodified lines
749removed and replaced with the synthesized events. e.g.764removed and replaced with the synthesized events. e.g.
750 765
751 perf inject --itrace -i perf.data -o perf.data.new766 perf inject --itrace -i perf.data -o perf.data.new
767
768Below is an example of using Intel PT with autofdo. It requires autofdo
769(https://github.com/google/autofdo) and gcc version 5. The bubble
770sort example is from the AutoFDO tutorial (https://gcc.gnu.org/wiki/AutoFDO/Tutorial)
771amended to take the number of elements as a parameter.
772
773 $ gcc-5 -O3 sort.c -o sort_optimized
774 $ ./sort_optimized 30000
775 Bubble sorting array of 30000 elements
776 2254 ms
777
778 $ cat ~/.perfconfig
779 [intel-pt]
780 mispred-all
781
782 $ perf record -e intel_pt//u ./sort 3000
783 Bubble sorting array of 3000 elements
784 58 ms
785 [ perf record: Woken up 2 times to write data ]
786 [ perf record: Captured and wrote 3.939 MB perf.data ]
787 $ perf inject -i perf.data -o inj --itrace=i100usle --strip
788 $ ./create_gcov --binary=./sort --profile=inj --gcov=sort.gcov -gcov_version=1
789 $ gcc-5 -O3 -fauto-profile=sort.gcov sort.c -o sort_autofdo
790 $ ./sort_autofdo 30000
791 Bubble sorting array of 30000 elements
792 2155 ms
793
794Note there is currently no advantage to using Intel PT instead of LBR, but
795that may change in the future if greater use is made of the data.
tools/perf/Documentation/itrace.txt+4−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
6 e synthesize error events6 e synthesize error events
7 d create a debug log7 d create a debug log
8 g synthesize a call chain (use with i or x)8 g synthesize a call chain (use with i or x)
9 l synthesize last branch entries (use with i or x)
9 10
10 The default is all events i.e. the same as --itrace=ibxe11 The default is all events i.e. the same as --itrace=ibxe
11 12
@@ -20,3 +21,6 @@ · 8 unmodified lines
20 21
21 Also the call chain size (default 16, max. 1024) for instructions or22 Also the call chain size (default 16, max. 1024) for instructions or
22 transactions events can be specified.23 transactions events can be specified.
24
25 Also the number of last branch entries (default 64, max. 1024) for
26 instructions or transactions events can be specified.
tools/perf/Documentation/perf-bench.txt+19−35
@@ -82,7 +82,7 @@ Be multi thread instead of multi process · 81 unmodified lines
82Specify number of groups82Specify number of groups
83 83
84-l::84-l::
85--loop=::85--nr_loops=::
86Specify number of loops86Specify number of loops
87 87
88Example of *messaging*88Example of *messaging*
@@ -139,64 +139,48 @@ Suite for evaluating performance of simple memory copy in various ways. · 50 unmodified lines
139Options of *memcpy*139Options of *memcpy*
140^^^^^^^^^^^^^^^^^^^140^^^^^^^^^^^^^^^^^^^
141-l::141-l::
142--length::142--size::
143Specify length of memory to copy (default: 1MB).143Specify size of memory to copy (default: 1MB).
144Available units are B, KB, MB, GB and TB (case insensitive).144Available units are B, KB, MB, GB and TB (case insensitive).
145 145
146-r::146-f::
147--routine::147--function::
148Specify routine to copy (default: default).148Specify function to copy (default: default).
149Available routines are depend on the architecture.149Available functions are depend on the architecture.
150On x86-64, x86-64-unrolled, x86-64-movsq and x86-64-movsb are supported.150On x86-64, x86-64-unrolled, x86-64-movsq and x86-64-movsb are supported.
151 151
152-i::152-l::
153--iterations::153--nr_loops::
154Repeat memcpy invocation this number of times.154Repeat memcpy invocation this number of times.
155 155
156-c::156-c::
157--cycle::157--cycles::
158Use perf's cpu-cycles event instead of gettimeofday syscall.158Use perf's cpu-cycles event instead of gettimeofday syscall.
159 159
160-o::
161--only-prefault::
162Show only the result with page faults before memcpy.
163
164-n::
165--no-prefault::
166Show only the result without page faults before memcpy.
167
168*memset*::160*memset*::
169Suite for evaluating performance of simple memory set in various ways.161Suite for evaluating performance of simple memory set in various ways.
170 162
171Options of *memset*163Options of *memset*
172^^^^^^^^^^^^^^^^^^^164^^^^^^^^^^^^^^^^^^^
173-l::165-l::
174--length::166--size::
175Specify length of memory to set (default: 1MB).167Specify size of memory to set (default: 1MB).
176Available units are B, KB, MB, GB and TB (case insensitive).168Available units are B, KB, MB, GB and TB (case insensitive).
177 169
178-r::170-f::
179--routine::171--function::
180Specify routine to set (default: default).172Specify function to set (default: default).
181Available routines are depend on the architecture.173Available functions are depend on the architecture.
182On x86-64, x86-64-unrolled, x86-64-stosq and x86-64-stosb are supported.174On x86-64, x86-64-unrolled, x86-64-stosq and x86-64-stosb are supported.
183 175
184-i::176-l::
185--iterations::177--nr_loops::
186Repeat memset invocation this number of times.178Repeat memset invocation this number of times.
187 179
188-c::180-c::
189--cycle::181--cycles::
190Use perf's cpu-cycles event instead of gettimeofday syscall.182Use perf's cpu-cycles event instead of gettimeofday syscall.
191 183
192-o::
193--only-prefault::
194Show only the result with page faults before memset.
195
196-n::
197--no-prefault::
198Show only the result without page faults before memset.
199
200SUITES FOR 'numa'184SUITES FOR 'numa'
201~~~~~~~~~~~~~~~~~185~~~~~~~~~~~~~~~~~
202*mem*::186*mem*::
tools/perf/Documentation/perf-inject.txt+3−0
@@ -50,6 +50,9 @@ OPTIONS · 49 unmodified lines
50 50
51include::itrace.txt[]51include::itrace.txt[]
52 52
53--strip::
54 Use with --itrace to strip out non-synthesized events.
55
53SEE ALSO56SEE ALSO
54--------57--------
55linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]58linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]
tools/perf/Documentation/perf-list.txt+3−0
@@ -30,6 +30,7 @@ counted. The following modifiers exist: · 29 unmodified lines
30 G - guest counting (in KVM guests)30 G - guest counting (in KVM guests)
31 H - host counting (not in KVM guests)31 H - host counting (not in KVM guests)
32 p - precise level32 p - precise level
33 P - use maximum detected precise level
33 S - read sample value (PERF_SAMPLE_READ)34 S - read sample value (PERF_SAMPLE_READ)
34 D - pin the event to the PMU35 D - pin the event to the PMU
35 36
@@ -125,6 +126,8 @@ To limit the list use: · 89 unmodified lines
125. If none of the above is matched, it will apply the supplied glob to all126. If none of the above is matched, it will apply the supplied glob to all
126 events, printing the ones that match.127 events, printing the ones that match.
127 128
129. As a last resort, it will do a substring search in all event names.
130
128One or more types can be used at the same time, listing the events for the131One or more types can be used at the same time, listing the events for the
129types specified.132types specified.
130 133
tools/perf/Documentation/perf-record.txt+14−2
@@ -144,7 +144,7 @@ OPTIONS · 143 unmodified lines
144 144
145--call-graph::145--call-graph::
146 Setup and enable call-graph (stack chain/backtrace) recording,146 Setup and enable call-graph (stack chain/backtrace) recording,
147 implies -g.147 implies -g. Default is "fp".
148 148
149 Allows specifying "fp" (frame pointer) or "dwarf"149 Allows specifying "fp" (frame pointer) or "dwarf"
150 (DWARF's CFI - Call Frame Information) or "lbr"150 (DWARF's CFI - Call Frame Information) or "lbr"
@@ -154,13 +154,18 @@ OPTIONS · 3 unmodified lines
154 In some systems, where binaries are build with gcc154 In some systems, where binaries are build with gcc
155 --fomit-frame-pointer, using the "fp" method will produce bogus155 --fomit-frame-pointer, using the "fp" method will produce bogus
156 call graphs, using "dwarf", if available (perf tools linked to156 call graphs, using "dwarf", if available (perf tools linked to
157 the libunwind library) should be used instead.157 the libunwind or libdw library) should be used instead.
158 Using the "lbr" method doesn't require any compiler options. It158 Using the "lbr" method doesn't require any compiler options. It
159 will produce call graphs from the hardware LBR registers. The159 will produce call graphs from the hardware LBR registers. The
160 main limition is that it is only available on new Intel160 main limition is that it is only available on new Intel
161 platforms, such as Haswell. It can only get user call chain. It161 platforms, such as Haswell. It can only get user call chain. It
162 doesn't work with branch stack sampling at the same time.162 doesn't work with branch stack sampling at the same time.
163 163
164 When "dwarf" recording is used, perf also records (user) stack dump
165 when sampled. Default size of the stack dump is 8192 (bytes).
166 User can change the size by passing the size after comma like
167 "--call-graph dwarf,4096".
168
164-q::169-q::
165--quiet::170--quiet::
166 Don't print any message, useful for scripting.171 Don't print any message, useful for scripting.
@@ -236,6 +241,7 @@ following filters are defined: · 69 unmodified lines
236 - any_call: any function call or system call241 - any_call: any function call or system call
237 - any_ret: any function return or system call return242 - any_ret: any function return or system call return
238 - ind_call: any indirect branch243 - ind_call: any indirect branch
244 - call: direct calls, including far (to/from kernel) calls
239 - u: only when the branch target is at the user level245 - u: only when the branch target is at the user level
240 - k: only when the branch target is in the kernel246 - k: only when the branch target is in the kernel
241 - hv: only when the target is at the hypervisor level247 - hv: only when the target is at the hypervisor level
@@ -308,6 +314,12 @@ This option sets the time out limit. The default value is 500 ms. · 66 unmodified lines
308Record context switch events i.e. events of type PERF_RECORD_SWITCH or314Record context switch events i.e. events of type PERF_RECORD_SWITCH or
309PERF_RECORD_SWITCH_CPU_WIDE.315PERF_RECORD_SWITCH_CPU_WIDE.
310 316
317--clang-path::
318Path to clang binary to use for compiling BPF scriptlets.
319
320--clang-opt::
321Options passed to clang when compiling BPF scriptlets.
322
311SEE ALSO323SEE ALSO
312--------324--------
313linkperf:perf-stat[1], linkperf:perf-list[1]325linkperf:perf-stat[1], linkperf:perf-list[1]
tools/perf/Documentation/perf-report.txt+32−16
@@ -29,7 +29,7 @@ OPTIONS · 28 unmodified lines
29--show-nr-samples::29--show-nr-samples::
30 Show the number of samples for each symbol30 Show the number of samples for each symbol
31 31
32--showcpuutilization::32--show-cpu-utilization::
33 Show sample percentage for different cpu modes.33 Show sample percentage for different cpu modes.
34 34
35-T::35-T::
@@ -68,7 +68,7 @@ OPTIONS · 32 unmodified lines
68--sort=::68--sort=::
69 Sort histogram entries by given key(s) - multiple keys can be specified69 Sort histogram entries by given key(s) - multiple keys can be specified
70 in CSV format. Following sort keys are available:70 in CSV format. Following sort keys are available:
71 pid, comm, dso, symbol, parent, cpu, srcline, weight, local_weight.71 pid, comm, dso, symbol, parent, cpu, socket, srcline, weight, local_weight.
72 72
73 Each key has following meaning:73 Each key has following meaning:
74 74
@@ -79,6 +79,7 @@ OPTIONS · 4 unmodified lines
79 - parent: name of function matched to the parent regex filter. Unmatched79 - parent: name of function matched to the parent regex filter. Unmatched
80 entries are displayed as "[other]".80 entries are displayed as "[other]".
81 - cpu: cpu number the task ran at the time of sample81 - cpu: cpu number the task ran at the time of sample
82 - socket: processor socket number the task ran at the time of sample
82 - srcline: filename and line number executed at the time of sample. The83 - srcline: filename and line number executed at the time of sample. The
83 DWARF debugging info must be provided.84 DWARF debugging info must be provided.
84 - srcfile: file name of the source file of the same. Requires dwarf85 - srcfile: file name of the source file of the same. Requires dwarf
@@ -168,30 +169,40 @@ OPTIONS · 83 unmodified lines
168--dump-raw-trace::169--dump-raw-trace::
169 Dump raw trace in ASCII.170 Dump raw trace in ASCII.
170 171
171-g [type,min[,limit],order[,key][,branch]]::172-g::
172--call-graph::173--call-graph=<print_type,threshold[,print_limit],order,sort_key,branch>::
173 Display call chains using type, min percent threshold, optional print174 Display call chains using type, min percent threshold, print limit,
174 limit and order.175 call order, sort key and branch. Note that ordering of parameters is not
175 type can be either:176 fixed so any parement can be given in an arbitraty order. One exception
177 is the print_limit which should be preceded by threshold.
178
179 print_type can be either:
176 - flat: single column, linear exposure of call chains.180 - flat: single column, linear exposure of call chains.
177 - graph: use a graph tree, displaying absolute overhead rates.181 - graph: use a graph tree, displaying absolute overhead rates. (default)
178 - fractal: like graph, but displays relative rates. Each branch of182 - fractal: like graph, but displays relative rates. Each branch of
179 the tree is considered as a new profiled object. +183 the tree is considered as a new profiled object.
184 - none: disable call chain display.
185
186 threshold is a percentage value which specifies a minimum percent to be
187 included in the output call graph. Default is 0.5 (%).
188
189 print_limit is only applied when stdio interface is used. It's to limit
190 number of call graph entries in a single hist entry. Note that it needs
191 to be given after threshold (but not necessarily consecutive).
192 Default is 0 (unlimited).
180 193
181 order can be either:194 order can be either:
182 - callee: callee based call graph.195 - callee: callee based call graph.
183 - caller: inverted caller based call graph.196 - caller: inverted caller based call graph.
197 Default is 'caller' when --children is used, otherwise 'callee'.
184 198
185 key can be:199 sort_key can be:
186 - function: compare on functions200 - function: compare on functions (default)
187 - address: compare on individual code addresses201 - address: compare on individual code addresses
188 202
189 branch can be:203 branch can be:
190 - branch: include last branch information in callgraph204 - branch: include last branch information in callgraph when available.
191 when available. Usually more convenient to use --branch-history205 Usually more convenient to use --branch-history for this.
192 for this.
193
194 Default: fractal,0.5,callee,function.
195 206
196--children::207--children::
197 Accumulate callchain of children to parent entry so that then can208 Accumulate callchain of children to parent entry so that then can
@@ -204,6 +215,8 @@ OPTIONS · 6 unmodified lines
204 beyond the specified depth will be ignored. This is a trade-off215 beyond the specified depth will be ignored. This is a trade-off
205 between information loss and faster processing especially for216 between information loss and faster processing especially for
206 workloads that can have a very long callchain stack.217 workloads that can have a very long callchain stack.
218 Note that when using the --itrace option the synthesized callchain size
219 will override this value if the synthesized callchain size is bigger.
207 220
208 Default: 127221 Default: 127
209 222
@@ -349,6 +362,9 @@ include::itrace.txt[] · 139 unmodified lines
349 This option extends the perf report to show reference callgraphs,362 This option extends the perf report to show reference callgraphs,
350 which collected by reference event, in no callgraph event.363 which collected by reference event, in no callgraph event.
351 364
365--socket-filter::
366 Only report the samples on the processor socket that match with this filter
367
352include::callchain-overhead-calculation.txt[]368include::callchain-overhead-calculation.txt[]
353 369
354SEE ALSO370SEE ALSO
tools/perf/Documentation/perf-script.txt+15−2
@@ -112,11 +112,11 @@ OPTIONS · 111 unmodified lines
112--debug-mode::112--debug-mode::
113 Do various checks like samples ordering and lost events.113 Do various checks like samples ordering and lost events.
114 114
115-f::115-F::
116--fields::116--fields::
117 Comma separated list of fields to print. Options are:117 Comma separated list of fields to print. Options are:
118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,118 comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff,
119 srcline, period, iregs, flags.119 srcline, period, iregs, brstack, brstacksym, flags.
120 Field list can be prepended with the type, trace, sw or hw,120 Field list can be prepended with the type, trace, sw or hw,
121 to indicate to which event type the field list applies.121 to indicate to which event type the field list applies.
122 e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace122 e.g., -f sw:comm,tid,time,ip,sym and -f trace:time,cpu,trace
@@ -175,6 +175,16 @@ OPTIONS · 52 unmodified lines
175 Finally, a user may not set fields to none for all event types.175 Finally, a user may not set fields to none for all event types.
176 i.e., -f "" is not allowed.176 i.e., -f "" is not allowed.
177 177
178 The brstack output includes branch related information with raw addresses using the
179 /v/v/v/v/ syntax in the following order:
180 FROM: branch source instruction
181 TO : branch target instruction
182 M/P/-: M=branch target mispredicted or branch direction was mispredicted, P=target predicted or direction predicted, -=not supported
183 X/- : X=branch inside a transactional region, -=not in transaction region or not supported
184 A/- : A=TSX abort entry, -=not aborted region or not supported
185
186 The brstacksym is identical to brstack, except that the FROM and TO addresses are printed in a symbolic form if possible.
187
178-k::188-k::
179--vmlinux=<file>::189--vmlinux=<file>::
180 vmlinux pathname190 vmlinux pathname
@@ -249,6 +259,9 @@ include::itrace.txt[] · 68 unmodified lines
249--full-source-path::259--full-source-path::
250 Show the full path for source files for srcline output.260 Show the full path for source files for srcline output.
251 261
262--ns::
263 Use 9 decimal places when displaying time (i.e. show the nanoseconds)
264
252SEE ALSO265SEE ALSO
253--------266--------
254linkperf:perf-record[1], linkperf:perf-script-perl[1],267linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/Documentation/perf-stat.txt+3−2
@@ -128,8 +128,9 @@ perf stat --repeat 10 --null --sync --pre 'make -s O=defconfig-build/clean' -- m · 127 unmodified lines
128 128
129-I msecs::129-I msecs::
130--interval-print msecs::130--interval-print msecs::
131 Print count deltas every N milliseconds (minimum: 100ms)131Print count deltas every N milliseconds (minimum: 10ms)
132 example: perf stat -I 1000 -e cycles -a sleep 5132The overhead percentage could be high in some cases, for instance with small, sub 100ms intervals. Use with caution.
133 example: 'perf stat -I 1000 -e cycles -a sleep 5'
133 134
134--per-socket::135--per-socket::
135Aggregate counts per processor socket for system-wide mode measurements. This136Aggregate counts per processor socket for system-wide mode measurements. This
tools/perf/Documentation/perf-top.txt+3−2
@@ -160,9 +160,10 @@ Default is to monitor all CPUS. · 159 unmodified lines
160-g::160-g::
161 Enables call-graph (stack chain/backtrace) recording.161 Enables call-graph (stack chain/backtrace) recording.
162 162
163--call-graph::163--call-graph [mode,type,min[,limit],order[,key][,branch]]::
164 Setup and enable call-graph (stack chain/backtrace) recording,164 Setup and enable call-graph (stack chain/backtrace) recording,
165 implies -g.165 implies -g. See `--call-graph` section in perf-record and
166 perf-report man pages for details.
166 167
167--children::168--children::
168 Accumulate callchain of children to parent entry so that then can169 Accumulate callchain of children to parent entry so that then can
tools/perf/Documentation/perf.txt+8−0
@@ -27,6 +27,14 @@ OPTIONS · 26 unmodified lines
27 Setup buildid cache directory. It has higher priority than27 Setup buildid cache directory. It has higher priority than
28 buildid.dir config file option.28 buildid.dir config file option.
29 29
30-v::
31--version::
32 Display perf version.
33
34-h::
35--help::
36 Run perf help command.
37
30DESCRIPTION38DESCRIPTION
31-----------39-----------
32Performance counters for Linux are a new kernel-based subsystem40Performance counters for Linux are a new kernel-based subsystem
tools/perf/MANIFEST+5−0
@@ -17,6 +17,7 @@ tools/build · 16 unmodified lines
17tools/arch/x86/include/asm/atomic.h17tools/arch/x86/include/asm/atomic.h
18tools/arch/x86/include/asm/rmwcc.h18tools/arch/x86/include/asm/rmwcc.h
19tools/lib/traceevent19tools/lib/traceevent
20tools/lib/bpf
20tools/lib/api21tools/lib/api
21tools/lib/bpf22tools/lib/bpf
22tools/lib/hweight.c23tools/lib/hweight.c
@@ -41,6 +42,7 @@ tools/include/asm-generic/bitops.h · 18 unmodified lines
41tools/include/linux/atomic.h42tools/include/linux/atomic.h
42tools/include/linux/bitops.h43tools/include/linux/bitops.h
43tools/include/linux/compiler.h44tools/include/linux/compiler.h
45tools/include/linux/filter.h
44tools/include/linux/hash.h46tools/include/linux/hash.h
45tools/include/linux/kernel.h47tools/include/linux/kernel.h
46tools/include/linux/list.h48tools/include/linux/list.h
@@ -49,6 +51,7 @@ tools/include/linux/poison.h · 2 unmodified lines
49tools/include/linux/rbtree.h51tools/include/linux/rbtree.h
50tools/include/linux/rbtree_augmented.h52tools/include/linux/rbtree_augmented.h
51tools/include/linux/types.h53tools/include/linux/types.h
54tools/include/linux/err.h
52include/asm-generic/bitops/arch_hweight.h55include/asm-generic/bitops/arch_hweight.h
53include/asm-generic/bitops/const_hweight.h56include/asm-generic/bitops/const_hweight.h
54include/asm-generic/bitops/fls64.h57include/asm-generic/bitops/fls64.h
@@ -67,6 +70,8 @@ arch/*/lib/memset*.S · 12 unmodified lines
67include/linux/poison.h70include/linux/poison.h
68include/linux/hw_breakpoint.h71include/linux/hw_breakpoint.h
69include/uapi/linux/perf_event.h72include/uapi/linux/perf_event.h
73include/uapi/linux/bpf.h
74include/uapi/linux/bpf_common.h
70include/uapi/linux/const.h75include/uapi/linux/const.h
71include/uapi/linux/swab.h76include/uapi/linux/swab.h
72include/uapi/linux/hw_breakpoint.h77include/uapi/linux/hw_breakpoint.h
tools/perf/Makefile.perf+35−18
@@ -75,6 +75,8 @@ include config/utilities.mak · 74 unmodified lines
75# Define NO_LZMA if you do not want to support compressed (xz) kernel modules75# Define NO_LZMA if you do not want to support compressed (xz) kernel modules
76#76#
77# Define NO_AUXTRACE if you do not want AUX area tracing support77# Define NO_AUXTRACE if you do not want AUX area tracing support
78#
79# Define NO_LIBBPF if you do not want BPF support
78 80
79# As per kernel Makefile, avoid funny character set dependencies81# As per kernel Makefile, avoid funny character set dependencies
80unexport LC_ALL82unexport LC_ALL
@@ -145,6 +147,7 @@ AWK = awk · 64 unmodified lines
145 147
146LIB_DIR = $(srctree)/tools/lib/api/148LIB_DIR = $(srctree)/tools/lib/api/
147TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/149TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
150BPF_DIR = $(srctree)/tools/lib/bpf/
148 151
149# include config/Makefile by default and rule out152# include config/Makefile by default and rule out
150# non-config cases153# non-config cases
@@ -180,6 +183,7 @@ strip-libs = $(filter-out -l%,$(1)) · 29 unmodified lines
180 183
181ifneq ($(OUTPUT),)184ifneq ($(OUTPUT),)
182 TE_PATH=$(OUTPUT)185 TE_PATH=$(OUTPUT)
186 BPF_PATH=$(OUTPUT)
183ifneq ($(subdir),)187ifneq ($(subdir),)
184 LIB_PATH=$(OUTPUT)/../lib/api/188 LIB_PATH=$(OUTPUT)/../lib/api/
185else189else
@@ -188,6 +192,7 @@ endif · 2 unmodified lines
188else192else
189 TE_PATH=$(TRACE_EVENT_DIR)193 TE_PATH=$(TRACE_EVENT_DIR)
190 LIB_PATH=$(LIB_DIR)194 LIB_PATH=$(LIB_DIR)
195 BPF_PATH=$(BPF_DIR)
191endif196endif
192 197
193LIBTRACEEVENT = $(TE_PATH)libtraceevent.a198LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -199,6 +204,8 @@ LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS = -Xlinker --dynamic-list=$(LIBTRACEEVENT_DYN · 5 unmodified lines
199LIBAPI = $(LIB_PATH)libapi.a204LIBAPI = $(LIB_PATH)libapi.a
200export LIBAPI205export LIBAPI
201 206
207LIBBPF = $(BPF_PATH)libbpf.a
208
202# python extension build directories209# python extension build directories
203PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/210PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
204PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/211PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -251,6 +258,9 @@ export PERL_PATH · 46 unmodified lines
251LIB_FILE=$(OUTPUT)libperf.a258LIB_FILE=$(OUTPUT)libperf.a
252 259
253PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)260PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
261ifndef NO_LIBBPF
262 PERFLIBS += $(LIBBPF)
263endif
254 264
255# We choose to avoid "if .. else if .. else .. endif endif"265# We choose to avoid "if .. else if .. else .. endif endif"
256# because maintaining the nesting to match is a pain. If266# because maintaining the nesting to match is a pain. If
@@ -297,16 +307,16 @@ strip: $(PROGRAMS) $(OUTPUT)perf · 40 unmodified lines
297PERF_IN := $(OUTPUT)perf-in.o307PERF_IN := $(OUTPUT)perf-in.o
298 308
299export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK309export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK
300build := -f $(srctree)/tools/build/Makefile.build dir=. obj310include $(srctree)/tools/build/Makefile.include
301 311
302$(PERF_IN): $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h FORCE312$(PERF_IN): prepare FORCE
303 $(Q)$(MAKE) $(build)=perf313 $(Q)$(MAKE) $(build)=perf
304 314
305$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)315$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)
306 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS) \316 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS) \
307 $(PERF_IN) $(LIBS) -o $@317 $(PERF_IN) $(LIBS) -o $@
308 318
309$(GTK_IN): FORCE319$(GTK_IN): fixdep FORCE
310 $(Q)$(MAKE) $(build)=gtk320 $(Q)$(MAKE) $(build)=gtk
311 321
312$(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS)322$(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS)
@@ -349,27 +359,27 @@ endif · 36 unmodified lines
349__build-dir = $(subst $(OUTPUT),,$(dir $@))359__build-dir = $(subst $(OUTPUT),,$(dir $@))
350build-dir = $(if $(__build-dir),$(__build-dir),.)360build-dir = $(if $(__build-dir),$(__build-dir),.)
351 361
352single_dep: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h362prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h fixdep
353 363
354$(OUTPUT)%.o: %.c single_dep FORCE364$(OUTPUT)%.o: %.c prepare FORCE
355 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@365 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
356 366
357$(OUTPUT)%.i: %.c single_dep FORCE367$(OUTPUT)%.i: %.c prepare FORCE
358 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@368 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
359 369
360$(OUTPUT)%.s: %.c single_dep FORCE370$(OUTPUT)%.s: %.c prepare FORCE
361 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@371 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
362 372
363$(OUTPUT)%-bison.o: %.c single_dep FORCE373$(OUTPUT)%-bison.o: %.c prepare FORCE
364 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@374 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
365 375
366$(OUTPUT)%-flex.o: %.c single_dep FORCE376$(OUTPUT)%-flex.o: %.c prepare FORCE
367 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@377 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
368 378
369$(OUTPUT)%.o: %.S single_dep FORCE379$(OUTPUT)%.o: %.S prepare FORCE
370 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@380 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
371 381
372$(OUTPUT)%.i: %.S single_dep FORCE382$(OUTPUT)%.i: %.S prepare FORCE
373 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@383 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
374 384
375$(OUTPUT)perf-%: %.o $(PERFLIBS)385$(OUTPUT)perf-%: %.o $(PERFLIBS)
@@ -389,7 +399,7 @@ $(patsubst perf-%,%.o,$(PROGRAMS)): $(wildcard */*.h) · 13 unmodified lines
389 399
390LIBPERF_IN := $(OUTPUT)libperf-in.o400LIBPERF_IN := $(OUTPUT)libperf-in.o
391 401
392$(LIBPERF_IN): FORCE402$(LIBPERF_IN): fixdep FORCE
393 $(Q)$(MAKE) $(build)=libperf403 $(Q)$(MAKE) $(build)=libperf
394 404
395$(LIB_FILE): $(LIBPERF_IN)405$(LIB_FILE): $(LIBPERF_IN)
@@ -397,10 +407,10 @@ $(LIB_FILE): $(LIBPERF_IN) · 1 unmodified line
397 407
398LIBTRACEEVENT_FLAGS += plugin_dir=$(plugindir_SQ)408LIBTRACEEVENT_FLAGS += plugin_dir=$(plugindir_SQ)
399 409
400$(LIBTRACEEVENT): FORCE410$(LIBTRACEEVENT): fixdep FORCE
401 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent.a411 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent.a
402 412
403libtraceevent_plugins: FORCE413libtraceevent_plugins: fixdep FORCE
404 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) plugins414 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) plugins
405 415
406$(LIBTRACEEVENT_DYNAMIC_LIST): libtraceevent_plugins416$(LIBTRACEEVENT_DYNAMIC_LIST): libtraceevent_plugins
@@ -413,13 +423,20 @@ $(LIBTRACEEVENT)-clean: · 6 unmodified lines
413install-traceevent-plugins: $(LIBTRACEEVENT)423install-traceevent-plugins: $(LIBTRACEEVENT)
414 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) install_plugins424 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) install_plugins
415 425
416$(LIBAPI): FORCE426$(LIBAPI): fixdep FORCE
417 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a427 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
418 428
419$(LIBAPI)-clean:429$(LIBAPI)-clean:
420 $(call QUIET_CLEAN, libapi)430 $(call QUIET_CLEAN, libapi)
421 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null431 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
422 432
433$(LIBBPF): fixdep FORCE
434 $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) $(OUTPUT)libbpf.a
435
436$(LIBBPF)-clean:
437 $(call QUIET_CLEAN, libbpf)
438 $(Q)$(MAKE) -C $(BPF_DIR) O=$(OUTPUT) clean >/dev/null
439
423help:440help:
424 @echo 'Perf make targets:'441 @echo 'Perf make targets:'
425 @echo ' doc - make *all* documentation (see below)'442 @echo ' doc - make *all* documentation (see below)'
@@ -459,7 +476,7 @@ INSTALL_DOC_TARGETS += quick-install-doc quick-install-man quick-install-html · 33 unmodified lines
459$(DOC_TARGETS):476$(DOC_TARGETS):
460 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all)477 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) $(@:doc=all)
461 478
462TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol479TAG_FOLDERS= . ../lib/traceevent ../lib/api ../lib/symbol ../include ../lib/bpf
463TAG_FILES= ../../include/uapi/linux/perf_event.h480TAG_FILES= ../../include/uapi/linux/perf_event.h
464 481
465TAGS:482TAGS:
@@ -567,7 +584,7 @@ config-clean: · 101 unmodified lines
567 $(call QUIET_CLEAN, config)584 $(call QUIET_CLEAN, config)
568 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null585 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
569 586
570clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean587clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean config-clean
571 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)588 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
572 $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete589 $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
573 $(Q)$(RM) $(OUTPUT).config-detected590 $(Q)$(RM) $(OUTPUT).config-detected
@@ -591,6 +608,6 @@ FORCE: · 17 unmodified lines
591 608
592.PHONY: all install clean config-clean strip install-gtk609.PHONY: all install clean config-clean strip install-gtk
593.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell610.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
594.PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope FORCE single_dep611.PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope FORCE prepare
595.PHONY: libtraceevent_plugins612.PHONY: libtraceevent_plugins
596 613
tools/perf/arch/common.c+4−6
@@ -128,9 +128,8 @@ static const char *normalize_arch(char *arch) · 127 unmodified lines
128 return arch;128 return arch;
129}129}
130 130
131static int perf_session_env__lookup_binutils_path(struct perf_env *env,131static int perf_env__lookup_binutils_path(struct perf_env *env,
132 const char *name,132 const char *name, const char **path)
133 const char **path)
134{133{
135 int idx;134 int idx;
136 const char *arch, *cross_env;135 const char *arch, *cross_env;
@@ -206,7 +205,7 @@ out_error: · 69 unmodified lines
206 return -1;205 return -1;
207}206}
208 207
209int perf_session_env__lookup_objdump(struct perf_env *env)208int perf_env__lookup_objdump(struct perf_env *env)
210{209{
211 /*210 /*
212 * For live mode, env->arch will be NULL and we can use211 * For live mode, env->arch will be NULL and we can use
@@ -215,6 +214,5 @@ int perf_session_env__lookup_objdump(struct perf_env *env) · 2 unmodified lines
215 if (env->arch == NULL)214 if (env->arch == NULL)
216 return 0;215 return 0;
217 216
218 return perf_session_env__lookup_binutils_path(env, "objdump",217 return perf_env__lookup_binutils_path(env, "objdump", &objdump_path);
219 &objdump_path);
220}218}
tools/perf/arch/common.h+2−2
@@ -1,10 +1,10 @@
1#ifndef ARCH_PERF_COMMON_H1#ifndef ARCH_PERF_COMMON_H
2#define ARCH_PERF_COMMON_H2#define ARCH_PERF_COMMON_H
3 3
4#include "../util/session.h"4#include "../util/env.h"
5 5
6extern const char *objdump_path;6extern const char *objdump_path;
7 7
8int perf_session_env__lookup_objdump(struct perf_env *env);8int perf_env__lookup_objdump(struct perf_env *env);
9 9
10#endif /* ARCH_PERF_COMMON_H */10#endif /* ARCH_PERF_COMMON_H */
tools/perf/arch/x86/Build+1−1
@@ -1,2 +1,2 @@
1libperf-y += util/1libperf-y += util/
2libperf-$(CONFIG_DWARF_UNWIND) += tests/2libperf-y += tests/
tools/perf/arch/x86/Makefile+1−0
@@ -2,3 +2,4 @@ ifndef NO_DWARF · 1 unmodified line
2PERF_HAVE_DWARF_REGS := 12PERF_HAVE_DWARF_REGS := 1
3endif3endif
4HAVE_KVM_STAT_SUPPORT := 14HAVE_KVM_STAT_SUPPORT := 1
5PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET := 1
tools/perf/arch/x86/include/arch-tests.h+19−0
@@ -0,0 +1,19 @@
1#ifndef ARCH_TESTS_H
2#define ARCH_TESTS_H
3
4/* Tests */
5int test__rdpmc(void);
6int test__perf_time_to_tsc(void);
7int test__insn_x86(void);
8int test__intel_cqm_count_nmi_context(void);
9
10#ifdef HAVE_DWARF_UNWIND_SUPPORT
11struct thread;
12struct perf_sample;
13int test__arch_unwind_sample(struct perf_sample *sample,
14 struct thread *thread);
15#endif
16
17extern struct test arch_tests[];
18
19#endif
tools/perf/arch/x86/tests/Build+8−2
@@ -1,2 +1,8 @@
1libperf-y += regs_load.o1libperf-$(CONFIG_DWARF_UNWIND) += regs_load.o
2libperf-y += dwarf-unwind.o2libperf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
3
4libperf-y += arch-tests.o
5libperf-y += rdpmc.o
6libperf-y += perf-time-to-tsc.o
7libperf-$(CONFIG_AUXTRACE) += insn-x86.o
8libperf-y += intel-cqm.o
tools/perf/arch/x86/tests/arch-tests.c+34−0
@@ -0,0 +1,34 @@
1#include <string.h>
2#include "tests/tests.h"
3#include "arch-tests.h"
4
5struct test arch_tests[] = {
6 {
7 .desc = "x86 rdpmc test",
8 .func = test__rdpmc,
9 },
10 {
11 .desc = "Test converting perf time to TSC",
12 .func = test__perf_time_to_tsc,
13 },
14#ifdef HAVE_DWARF_UNWIND_SUPPORT
15 {
16 .desc = "Test dwarf unwind",
17 .func = test__dwarf_unwind,
18 },
19#endif
20#ifdef HAVE_AUXTRACE_SUPPORT
21 {
22 .desc = "Test x86 instruction decoder - new instructions",
23 .func = test__insn_x86,
24 },
25#endif
26 {
27 .desc = "Test intel cqm nmi context read",
28 .func = test__intel_cqm_count_nmi_context,
29 },
30 {
31 .func = NULL,
32 },
33
34};
tools/perf/arch/x86/tests/dwarf-unwind.c+1−0
@@ -5,6 +5,7 @@ · 4 unmodified lines
5#include "event.h"5#include "event.h"
6#include "debug.h"6#include "debug.h"
7#include "tests/tests.h"7#include "tests/tests.h"
8#include "arch-tests.h"
8 9
9#define STACK_SIZE 819210#define STACK_SIZE 8192
10 11
tools/perf/arch/x86/tests/gen-insn-x86-dat.awk+75−0
@@ -0,0 +1,75 @@
1#!/bin/awk -f
2# gen-insn-x86-dat.awk: script to convert data for the insn-x86 test
3# Copyright (c) 2015, Intel Corporation.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms and conditions of the GNU General Public License,
7# version 2, as published by the Free Software Foundation.
8#
9# This program is distributed in the hope it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12# more details.
13
14BEGIN {
15 print "/*"
16 print " * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk"
17 print " * from insn-x86-dat-src.c for inclusion by insn-x86.c"
18 print " * Do not change this code."
19 print "*/\n"
20 op = ""
21 branch = ""
22 rel = 0
23 going = 0
24}
25
26/ Start here / {
27 going = 1
28}
29
30/ Stop here / {
31 going = 0
32}
33
34/^\s*[0-9a-fA-F]+\:/ {
35 if (going) {
36 colon_pos = index($0, ":")
37 useful_line = substr($0, colon_pos + 1)
38 first_pos = match(useful_line, "[0-9a-fA-F]")
39 useful_line = substr(useful_line, first_pos)
40 gsub("\t", "\\t", useful_line)
41 printf "{{"
42 len = 0
43 for (i = 2; i <= NF; i++) {
44 if (match($i, "^[0-9a-fA-F][0-9a-fA-F]$")) {
45 printf "0x%s, ", $i
46 len += 1
47 } else {
48 break
49 }
50 }
51 printf "}, %d, %s, \"%s\", \"%s\",", len, rel, op, branch
52 printf "\n\"%s\",},\n", useful_line
53 op = ""
54 branch = ""
55 rel = 0
56 }
57}
58
59/ Expecting: / {
60 expecting_str = " Expecting: "
61 expecting_len = length(expecting_str)
62 expecting_pos = index($0, expecting_str)
63 useful_line = substr($0, expecting_pos + expecting_len)
64 for (i = 1; i <= NF; i++) {
65 if ($i == "Expecting:") {
66 i++
67 op = $i
68 i++
69 branch = $i
70 i++
71 rel = $i
72 break
73 }
74 }
75}
tools/perf/arch/x86/tests/gen-insn-x86-dat.sh+43−0
@@ -0,0 +1,43 @@
1#!/bin/sh
2# gen-insn-x86-dat: generate data for the insn-x86 test
3# Copyright (c) 2015, Intel Corporation.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms and conditions of the GNU General Public License,
7# version 2, as published by the Free Software Foundation.
8#
9# This program is distributed in the hope it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12# more details.
13
14set -e
15
16if [ "$(uname -m)" != "x86_64" ]; then
17 echo "ERROR: This script only works on x86_64"
18 exit 1
19fi
20
21cd $(dirname $0)
22
23trap 'echo "Might need a more recent version of binutils"' EXIT
24
25echo "Compiling insn-x86-dat-src.c to 64-bit object"
26
27gcc -g -c insn-x86-dat-src.c
28
29objdump -dSw insn-x86-dat-src.o | awk -f gen-insn-x86-dat.awk > insn-x86-dat-64.c
30
31rm -f insn-x86-dat-src.o
32
33echo "Compiling insn-x86-dat-src.c to 32-bit object"
34
35gcc -g -c -m32 insn-x86-dat-src.c
36
37objdump -dSw insn-x86-dat-src.o | awk -f gen-insn-x86-dat.awk > insn-x86-dat-32.c
38
39rm -f insn-x86-dat-src.o
40
41trap - EXIT
42
43echo "Done (use git diff to see the changes)"
tools/perf/arch/x86/tests/insn-x86-dat-32.c+658−0
@@ -0,0 +1,658 @@
1/*
2 * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk
3 * from insn-x86-dat-src.c for inclusion by insn-x86.c
4 * Do not change this code.
5*/
6
7{{0x0f, 0x31, }, 2, 0, "", "",
8"0f 31 \trdtsc ",},
9{{0xf3, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
10"f3 0f 1b 00 \tbndmk (%eax),%bnd0",},
11{{0xf3, 0x0f, 0x1b, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
12"f3 0f 1b 05 78 56 34 12 \tbndmk 0x12345678,%bnd0",},
13{{0xf3, 0x0f, 0x1b, 0x18, }, 4, 0, "", "",
14"f3 0f 1b 18 \tbndmk (%eax),%bnd3",},
15{{0xf3, 0x0f, 0x1b, 0x04, 0x01, }, 5, 0, "", "",
16"f3 0f 1b 04 01 \tbndmk (%ecx,%eax,1),%bnd0",},
17{{0xf3, 0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
18"f3 0f 1b 04 05 78 56 34 12 \tbndmk 0x12345678(,%eax,1),%bnd0",},
19{{0xf3, 0x0f, 0x1b, 0x04, 0x08, }, 5, 0, "", "",
20"f3 0f 1b 04 08 \tbndmk (%eax,%ecx,1),%bnd0",},
21{{0xf3, 0x0f, 0x1b, 0x04, 0xc8, }, 5, 0, "", "",
22"f3 0f 1b 04 c8 \tbndmk (%eax,%ecx,8),%bnd0",},
23{{0xf3, 0x0f, 0x1b, 0x40, 0x12, }, 5, 0, "", "",
24"f3 0f 1b 40 12 \tbndmk 0x12(%eax),%bnd0",},
25{{0xf3, 0x0f, 0x1b, 0x45, 0x12, }, 5, 0, "", "",
26"f3 0f 1b 45 12 \tbndmk 0x12(%ebp),%bnd0",},
27{{0xf3, 0x0f, 0x1b, 0x44, 0x01, 0x12, }, 6, 0, "", "",
28"f3 0f 1b 44 01 12 \tbndmk 0x12(%ecx,%eax,1),%bnd0",},
29{{0xf3, 0x0f, 0x1b, 0x44, 0x05, 0x12, }, 6, 0, "", "",
30"f3 0f 1b 44 05 12 \tbndmk 0x12(%ebp,%eax,1),%bnd0",},
31{{0xf3, 0x0f, 0x1b, 0x44, 0x08, 0x12, }, 6, 0, "", "",
32"f3 0f 1b 44 08 12 \tbndmk 0x12(%eax,%ecx,1),%bnd0",},
33{{0xf3, 0x0f, 0x1b, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
34"f3 0f 1b 44 c8 12 \tbndmk 0x12(%eax,%ecx,8),%bnd0",},
35{{0xf3, 0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
36"f3 0f 1b 80 78 56 34 12 \tbndmk 0x12345678(%eax),%bnd0",},
37{{0xf3, 0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
38"f3 0f 1b 85 78 56 34 12 \tbndmk 0x12345678(%ebp),%bnd0",},
39{{0xf3, 0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
40"f3 0f 1b 84 01 78 56 34 12 \tbndmk 0x12345678(%ecx,%eax,1),%bnd0",},
41{{0xf3, 0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
42"f3 0f 1b 84 05 78 56 34 12 \tbndmk 0x12345678(%ebp,%eax,1),%bnd0",},
43{{0xf3, 0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
44"f3 0f 1b 84 08 78 56 34 12 \tbndmk 0x12345678(%eax,%ecx,1),%bnd0",},
45{{0xf3, 0x0f, 0x1b, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
46"f3 0f 1b 84 c8 78 56 34 12 \tbndmk 0x12345678(%eax,%ecx,8),%bnd0",},
47{{0xf3, 0x0f, 0x1a, 0x00, }, 4, 0, "", "",
48"f3 0f 1a 00 \tbndcl (%eax),%bnd0",},
49{{0xf3, 0x0f, 0x1a, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
50"f3 0f 1a 05 78 56 34 12 \tbndcl 0x12345678,%bnd0",},
51{{0xf3, 0x0f, 0x1a, 0x18, }, 4, 0, "", "",
52"f3 0f 1a 18 \tbndcl (%eax),%bnd3",},
53{{0xf3, 0x0f, 0x1a, 0x04, 0x01, }, 5, 0, "", "",
54"f3 0f 1a 04 01 \tbndcl (%ecx,%eax,1),%bnd0",},
55{{0xf3, 0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
56"f3 0f 1a 04 05 78 56 34 12 \tbndcl 0x12345678(,%eax,1),%bnd0",},
57{{0xf3, 0x0f, 0x1a, 0x04, 0x08, }, 5, 0, "", "",
58"f3 0f 1a 04 08 \tbndcl (%eax,%ecx,1),%bnd0",},
59{{0xf3, 0x0f, 0x1a, 0x04, 0xc8, }, 5, 0, "", "",
60"f3 0f 1a 04 c8 \tbndcl (%eax,%ecx,8),%bnd0",},
61{{0xf3, 0x0f, 0x1a, 0x40, 0x12, }, 5, 0, "", "",
62"f3 0f 1a 40 12 \tbndcl 0x12(%eax),%bnd0",},
63{{0xf3, 0x0f, 0x1a, 0x45, 0x12, }, 5, 0, "", "",
64"f3 0f 1a 45 12 \tbndcl 0x12(%ebp),%bnd0",},
65{{0xf3, 0x0f, 0x1a, 0x44, 0x01, 0x12, }, 6, 0, "", "",
66"f3 0f 1a 44 01 12 \tbndcl 0x12(%ecx,%eax,1),%bnd0",},
67{{0xf3, 0x0f, 0x1a, 0x44, 0x05, 0x12, }, 6, 0, "", "",
68"f3 0f 1a 44 05 12 \tbndcl 0x12(%ebp,%eax,1),%bnd0",},
69{{0xf3, 0x0f, 0x1a, 0x44, 0x08, 0x12, }, 6, 0, "", "",
70"f3 0f 1a 44 08 12 \tbndcl 0x12(%eax,%ecx,1),%bnd0",},
71{{0xf3, 0x0f, 0x1a, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
72"f3 0f 1a 44 c8 12 \tbndcl 0x12(%eax,%ecx,8),%bnd0",},
73{{0xf3, 0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
74"f3 0f 1a 80 78 56 34 12 \tbndcl 0x12345678(%eax),%bnd0",},
75{{0xf3, 0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
76"f3 0f 1a 85 78 56 34 12 \tbndcl 0x12345678(%ebp),%bnd0",},
77{{0xf3, 0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
78"f3 0f 1a 84 01 78 56 34 12 \tbndcl 0x12345678(%ecx,%eax,1),%bnd0",},
79{{0xf3, 0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
80"f3 0f 1a 84 05 78 56 34 12 \tbndcl 0x12345678(%ebp,%eax,1),%bnd0",},
81{{0xf3, 0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
82"f3 0f 1a 84 08 78 56 34 12 \tbndcl 0x12345678(%eax,%ecx,1),%bnd0",},
83{{0xf3, 0x0f, 0x1a, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
84"f3 0f 1a 84 c8 78 56 34 12 \tbndcl 0x12345678(%eax,%ecx,8),%bnd0",},
85{{0xf3, 0x0f, 0x1a, 0xc0, }, 4, 0, "", "",
86"f3 0f 1a c0 \tbndcl %eax,%bnd0",},
87{{0xf2, 0x0f, 0x1a, 0x00, }, 4, 0, "", "",
88"f2 0f 1a 00 \tbndcu (%eax),%bnd0",},
89{{0xf2, 0x0f, 0x1a, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
90"f2 0f 1a 05 78 56 34 12 \tbndcu 0x12345678,%bnd0",},
91{{0xf2, 0x0f, 0x1a, 0x18, }, 4, 0, "", "",
92"f2 0f 1a 18 \tbndcu (%eax),%bnd3",},
93{{0xf2, 0x0f, 0x1a, 0x04, 0x01, }, 5, 0, "", "",
94"f2 0f 1a 04 01 \tbndcu (%ecx,%eax,1),%bnd0",},
95{{0xf2, 0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
96"f2 0f 1a 04 05 78 56 34 12 \tbndcu 0x12345678(,%eax,1),%bnd0",},
97{{0xf2, 0x0f, 0x1a, 0x04, 0x08, }, 5, 0, "", "",
98"f2 0f 1a 04 08 \tbndcu (%eax,%ecx,1),%bnd0",},
99{{0xf2, 0x0f, 0x1a, 0x04, 0xc8, }, 5, 0, "", "",
100"f2 0f 1a 04 c8 \tbndcu (%eax,%ecx,8),%bnd0",},
101{{0xf2, 0x0f, 0x1a, 0x40, 0x12, }, 5, 0, "", "",
102"f2 0f 1a 40 12 \tbndcu 0x12(%eax),%bnd0",},
103{{0xf2, 0x0f, 0x1a, 0x45, 0x12, }, 5, 0, "", "",
104"f2 0f 1a 45 12 \tbndcu 0x12(%ebp),%bnd0",},
105{{0xf2, 0x0f, 0x1a, 0x44, 0x01, 0x12, }, 6, 0, "", "",
106"f2 0f 1a 44 01 12 \tbndcu 0x12(%ecx,%eax,1),%bnd0",},
107{{0xf2, 0x0f, 0x1a, 0x44, 0x05, 0x12, }, 6, 0, "", "",
108"f2 0f 1a 44 05 12 \tbndcu 0x12(%ebp,%eax,1),%bnd0",},
109{{0xf2, 0x0f, 0x1a, 0x44, 0x08, 0x12, }, 6, 0, "", "",
110"f2 0f 1a 44 08 12 \tbndcu 0x12(%eax,%ecx,1),%bnd0",},
111{{0xf2, 0x0f, 0x1a, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
112"f2 0f 1a 44 c8 12 \tbndcu 0x12(%eax,%ecx,8),%bnd0",},
113{{0xf2, 0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
114"f2 0f 1a 80 78 56 34 12 \tbndcu 0x12345678(%eax),%bnd0",},
115{{0xf2, 0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
116"f2 0f 1a 85 78 56 34 12 \tbndcu 0x12345678(%ebp),%bnd0",},
117{{0xf2, 0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
118"f2 0f 1a 84 01 78 56 34 12 \tbndcu 0x12345678(%ecx,%eax,1),%bnd0",},
119{{0xf2, 0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
120"f2 0f 1a 84 05 78 56 34 12 \tbndcu 0x12345678(%ebp,%eax,1),%bnd0",},
121{{0xf2, 0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
122"f2 0f 1a 84 08 78 56 34 12 \tbndcu 0x12345678(%eax,%ecx,1),%bnd0",},
123{{0xf2, 0x0f, 0x1a, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
124"f2 0f 1a 84 c8 78 56 34 12 \tbndcu 0x12345678(%eax,%ecx,8),%bnd0",},
125{{0xf2, 0x0f, 0x1a, 0xc0, }, 4, 0, "", "",
126"f2 0f 1a c0 \tbndcu %eax,%bnd0",},
127{{0xf2, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
128"f2 0f 1b 00 \tbndcn (%eax),%bnd0",},
129{{0xf2, 0x0f, 0x1b, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
130"f2 0f 1b 05 78 56 34 12 \tbndcn 0x12345678,%bnd0",},
131{{0xf2, 0x0f, 0x1b, 0x18, }, 4, 0, "", "",
132"f2 0f 1b 18 \tbndcn (%eax),%bnd3",},
133{{0xf2, 0x0f, 0x1b, 0x04, 0x01, }, 5, 0, "", "",
134"f2 0f 1b 04 01 \tbndcn (%ecx,%eax,1),%bnd0",},
135{{0xf2, 0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
136"f2 0f 1b 04 05 78 56 34 12 \tbndcn 0x12345678(,%eax,1),%bnd0",},
137{{0xf2, 0x0f, 0x1b, 0x04, 0x08, }, 5, 0, "", "",
138"f2 0f 1b 04 08 \tbndcn (%eax,%ecx,1),%bnd0",},
139{{0xf2, 0x0f, 0x1b, 0x04, 0xc8, }, 5, 0, "", "",
140"f2 0f 1b 04 c8 \tbndcn (%eax,%ecx,8),%bnd0",},
141{{0xf2, 0x0f, 0x1b, 0x40, 0x12, }, 5, 0, "", "",
142"f2 0f 1b 40 12 \tbndcn 0x12(%eax),%bnd0",},
143{{0xf2, 0x0f, 0x1b, 0x45, 0x12, }, 5, 0, "", "",
144"f2 0f 1b 45 12 \tbndcn 0x12(%ebp),%bnd0",},
145{{0xf2, 0x0f, 0x1b, 0x44, 0x01, 0x12, }, 6, 0, "", "",
146"f2 0f 1b 44 01 12 \tbndcn 0x12(%ecx,%eax,1),%bnd0",},
147{{0xf2, 0x0f, 0x1b, 0x44, 0x05, 0x12, }, 6, 0, "", "",
148"f2 0f 1b 44 05 12 \tbndcn 0x12(%ebp,%eax,1),%bnd0",},
149{{0xf2, 0x0f, 0x1b, 0x44, 0x08, 0x12, }, 6, 0, "", "",
150"f2 0f 1b 44 08 12 \tbndcn 0x12(%eax,%ecx,1),%bnd0",},
151{{0xf2, 0x0f, 0x1b, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
152"f2 0f 1b 44 c8 12 \tbndcn 0x12(%eax,%ecx,8),%bnd0",},
153{{0xf2, 0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
154"f2 0f 1b 80 78 56 34 12 \tbndcn 0x12345678(%eax),%bnd0",},
155{{0xf2, 0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
156"f2 0f 1b 85 78 56 34 12 \tbndcn 0x12345678(%ebp),%bnd0",},
157{{0xf2, 0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
158"f2 0f 1b 84 01 78 56 34 12 \tbndcn 0x12345678(%ecx,%eax,1),%bnd0",},
159{{0xf2, 0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
160"f2 0f 1b 84 05 78 56 34 12 \tbndcn 0x12345678(%ebp,%eax,1),%bnd0",},
161{{0xf2, 0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
162"f2 0f 1b 84 08 78 56 34 12 \tbndcn 0x12345678(%eax,%ecx,1),%bnd0",},
163{{0xf2, 0x0f, 0x1b, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
164"f2 0f 1b 84 c8 78 56 34 12 \tbndcn 0x12345678(%eax,%ecx,8),%bnd0",},
165{{0xf2, 0x0f, 0x1b, 0xc0, }, 4, 0, "", "",
166"f2 0f 1b c0 \tbndcn %eax,%bnd0",},
167{{0x66, 0x0f, 0x1a, 0x00, }, 4, 0, "", "",
168"66 0f 1a 00 \tbndmov (%eax),%bnd0",},
169{{0x66, 0x0f, 0x1a, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
170"66 0f 1a 05 78 56 34 12 \tbndmov 0x12345678,%bnd0",},
171{{0x66, 0x0f, 0x1a, 0x18, }, 4, 0, "", "",
172"66 0f 1a 18 \tbndmov (%eax),%bnd3",},
173{{0x66, 0x0f, 0x1a, 0x04, 0x01, }, 5, 0, "", "",
174"66 0f 1a 04 01 \tbndmov (%ecx,%eax,1),%bnd0",},
175{{0x66, 0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
176"66 0f 1a 04 05 78 56 34 12 \tbndmov 0x12345678(,%eax,1),%bnd0",},
177{{0x66, 0x0f, 0x1a, 0x04, 0x08, }, 5, 0, "", "",
178"66 0f 1a 04 08 \tbndmov (%eax,%ecx,1),%bnd0",},
179{{0x66, 0x0f, 0x1a, 0x04, 0xc8, }, 5, 0, "", "",
180"66 0f 1a 04 c8 \tbndmov (%eax,%ecx,8),%bnd0",},
181{{0x66, 0x0f, 0x1a, 0x40, 0x12, }, 5, 0, "", "",
182"66 0f 1a 40 12 \tbndmov 0x12(%eax),%bnd0",},
183{{0x66, 0x0f, 0x1a, 0x45, 0x12, }, 5, 0, "", "",
184"66 0f 1a 45 12 \tbndmov 0x12(%ebp),%bnd0",},
185{{0x66, 0x0f, 0x1a, 0x44, 0x01, 0x12, }, 6, 0, "", "",
186"66 0f 1a 44 01 12 \tbndmov 0x12(%ecx,%eax,1),%bnd0",},
187{{0x66, 0x0f, 0x1a, 0x44, 0x05, 0x12, }, 6, 0, "", "",
188"66 0f 1a 44 05 12 \tbndmov 0x12(%ebp,%eax,1),%bnd0",},
189{{0x66, 0x0f, 0x1a, 0x44, 0x08, 0x12, }, 6, 0, "", "",
190"66 0f 1a 44 08 12 \tbndmov 0x12(%eax,%ecx,1),%bnd0",},
191{{0x66, 0x0f, 0x1a, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
192"66 0f 1a 44 c8 12 \tbndmov 0x12(%eax,%ecx,8),%bnd0",},
193{{0x66, 0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
194"66 0f 1a 80 78 56 34 12 \tbndmov 0x12345678(%eax),%bnd0",},
195{{0x66, 0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
196"66 0f 1a 85 78 56 34 12 \tbndmov 0x12345678(%ebp),%bnd0",},
197{{0x66, 0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
198"66 0f 1a 84 01 78 56 34 12 \tbndmov 0x12345678(%ecx,%eax,1),%bnd0",},
199{{0x66, 0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
200"66 0f 1a 84 05 78 56 34 12 \tbndmov 0x12345678(%ebp,%eax,1),%bnd0",},
201{{0x66, 0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
202"66 0f 1a 84 08 78 56 34 12 \tbndmov 0x12345678(%eax,%ecx,1),%bnd0",},
203{{0x66, 0x0f, 0x1a, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
204"66 0f 1a 84 c8 78 56 34 12 \tbndmov 0x12345678(%eax,%ecx,8),%bnd0",},
205{{0x66, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
206"66 0f 1b 00 \tbndmov %bnd0,(%eax)",},
207{{0x66, 0x0f, 0x1b, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
208"66 0f 1b 05 78 56 34 12 \tbndmov %bnd0,0x12345678",},
209{{0x66, 0x0f, 0x1b, 0x18, }, 4, 0, "", "",
210"66 0f 1b 18 \tbndmov %bnd3,(%eax)",},
211{{0x66, 0x0f, 0x1b, 0x04, 0x01, }, 5, 0, "", "",
212"66 0f 1b 04 01 \tbndmov %bnd0,(%ecx,%eax,1)",},
213{{0x66, 0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
214"66 0f 1b 04 05 78 56 34 12 \tbndmov %bnd0,0x12345678(,%eax,1)",},
215{{0x66, 0x0f, 0x1b, 0x04, 0x08, }, 5, 0, "", "",
216"66 0f 1b 04 08 \tbndmov %bnd0,(%eax,%ecx,1)",},
217{{0x66, 0x0f, 0x1b, 0x04, 0xc8, }, 5, 0, "", "",
218"66 0f 1b 04 c8 \tbndmov %bnd0,(%eax,%ecx,8)",},
219{{0x66, 0x0f, 0x1b, 0x40, 0x12, }, 5, 0, "", "",
220"66 0f 1b 40 12 \tbndmov %bnd0,0x12(%eax)",},
221{{0x66, 0x0f, 0x1b, 0x45, 0x12, }, 5, 0, "", "",
222"66 0f 1b 45 12 \tbndmov %bnd0,0x12(%ebp)",},
223{{0x66, 0x0f, 0x1b, 0x44, 0x01, 0x12, }, 6, 0, "", "",
224"66 0f 1b 44 01 12 \tbndmov %bnd0,0x12(%ecx,%eax,1)",},
225{{0x66, 0x0f, 0x1b, 0x44, 0x05, 0x12, }, 6, 0, "", "",
226"66 0f 1b 44 05 12 \tbndmov %bnd0,0x12(%ebp,%eax,1)",},
227{{0x66, 0x0f, 0x1b, 0x44, 0x08, 0x12, }, 6, 0, "", "",
228"66 0f 1b 44 08 12 \tbndmov %bnd0,0x12(%eax,%ecx,1)",},
229{{0x66, 0x0f, 0x1b, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
230"66 0f 1b 44 c8 12 \tbndmov %bnd0,0x12(%eax,%ecx,8)",},
231{{0x66, 0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
232"66 0f 1b 80 78 56 34 12 \tbndmov %bnd0,0x12345678(%eax)",},
233{{0x66, 0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
234"66 0f 1b 85 78 56 34 12 \tbndmov %bnd0,0x12345678(%ebp)",},
235{{0x66, 0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
236"66 0f 1b 84 01 78 56 34 12 \tbndmov %bnd0,0x12345678(%ecx,%eax,1)",},
237{{0x66, 0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
238"66 0f 1b 84 05 78 56 34 12 \tbndmov %bnd0,0x12345678(%ebp,%eax,1)",},
239{{0x66, 0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
240"66 0f 1b 84 08 78 56 34 12 \tbndmov %bnd0,0x12345678(%eax,%ecx,1)",},
241{{0x66, 0x0f, 0x1b, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
242"66 0f 1b 84 c8 78 56 34 12 \tbndmov %bnd0,0x12345678(%eax,%ecx,8)",},
243{{0x66, 0x0f, 0x1a, 0xc8, }, 4, 0, "", "",
244"66 0f 1a c8 \tbndmov %bnd0,%bnd1",},
245{{0x66, 0x0f, 0x1a, 0xc1, }, 4, 0, "", "",
246"66 0f 1a c1 \tbndmov %bnd1,%bnd0",},
247{{0x0f, 0x1a, 0x00, }, 3, 0, "", "",
248"0f 1a 00 \tbndldx (%eax),%bnd0",},
249{{0x0f, 0x1a, 0x05, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
250"0f 1a 05 78 56 34 12 \tbndldx 0x12345678,%bnd0",},
251{{0x0f, 0x1a, 0x18, }, 3, 0, "", "",
252"0f 1a 18 \tbndldx (%eax),%bnd3",},
253{{0x0f, 0x1a, 0x04, 0x01, }, 4, 0, "", "",
254"0f 1a 04 01 \tbndldx (%ecx,%eax,1),%bnd0",},
255{{0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
256"0f 1a 04 05 78 56 34 12 \tbndldx 0x12345678(,%eax,1),%bnd0",},
257{{0x0f, 0x1a, 0x04, 0x08, }, 4, 0, "", "",
258"0f 1a 04 08 \tbndldx (%eax,%ecx,1),%bnd0",},
259{{0x0f, 0x1a, 0x40, 0x12, }, 4, 0, "", "",
260"0f 1a 40 12 \tbndldx 0x12(%eax),%bnd0",},
261{{0x0f, 0x1a, 0x45, 0x12, }, 4, 0, "", "",
262"0f 1a 45 12 \tbndldx 0x12(%ebp),%bnd0",},
263{{0x0f, 0x1a, 0x44, 0x01, 0x12, }, 5, 0, "", "",
264"0f 1a 44 01 12 \tbndldx 0x12(%ecx,%eax,1),%bnd0",},
265{{0x0f, 0x1a, 0x44, 0x05, 0x12, }, 5, 0, "", "",
266"0f 1a 44 05 12 \tbndldx 0x12(%ebp,%eax,1),%bnd0",},
267{{0x0f, 0x1a, 0x44, 0x08, 0x12, }, 5, 0, "", "",
268"0f 1a 44 08 12 \tbndldx 0x12(%eax,%ecx,1),%bnd0",},
269{{0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
270"0f 1a 80 78 56 34 12 \tbndldx 0x12345678(%eax),%bnd0",},
271{{0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
272"0f 1a 85 78 56 34 12 \tbndldx 0x12345678(%ebp),%bnd0",},
273{{0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
274"0f 1a 84 01 78 56 34 12 \tbndldx 0x12345678(%ecx,%eax,1),%bnd0",},
275{{0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
276"0f 1a 84 05 78 56 34 12 \tbndldx 0x12345678(%ebp,%eax,1),%bnd0",},
277{{0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
278"0f 1a 84 08 78 56 34 12 \tbndldx 0x12345678(%eax,%ecx,1),%bnd0",},
279{{0x0f, 0x1b, 0x00, }, 3, 0, "", "",
280"0f 1b 00 \tbndstx %bnd0,(%eax)",},
281{{0x0f, 0x1b, 0x05, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
282"0f 1b 05 78 56 34 12 \tbndstx %bnd0,0x12345678",},
283{{0x0f, 0x1b, 0x18, }, 3, 0, "", "",
284"0f 1b 18 \tbndstx %bnd3,(%eax)",},
285{{0x0f, 0x1b, 0x04, 0x01, }, 4, 0, "", "",
286"0f 1b 04 01 \tbndstx %bnd0,(%ecx,%eax,1)",},
287{{0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
288"0f 1b 04 05 78 56 34 12 \tbndstx %bnd0,0x12345678(,%eax,1)",},
289{{0x0f, 0x1b, 0x04, 0x08, }, 4, 0, "", "",
290"0f 1b 04 08 \tbndstx %bnd0,(%eax,%ecx,1)",},
291{{0x0f, 0x1b, 0x40, 0x12, }, 4, 0, "", "",
292"0f 1b 40 12 \tbndstx %bnd0,0x12(%eax)",},
293{{0x0f, 0x1b, 0x45, 0x12, }, 4, 0, "", "",
294"0f 1b 45 12 \tbndstx %bnd0,0x12(%ebp)",},
295{{0x0f, 0x1b, 0x44, 0x01, 0x12, }, 5, 0, "", "",
296"0f 1b 44 01 12 \tbndstx %bnd0,0x12(%ecx,%eax,1)",},
297{{0x0f, 0x1b, 0x44, 0x05, 0x12, }, 5, 0, "", "",
298"0f 1b 44 05 12 \tbndstx %bnd0,0x12(%ebp,%eax,1)",},
299{{0x0f, 0x1b, 0x44, 0x08, 0x12, }, 5, 0, "", "",
300"0f 1b 44 08 12 \tbndstx %bnd0,0x12(%eax,%ecx,1)",},
301{{0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
302"0f 1b 80 78 56 34 12 \tbndstx %bnd0,0x12345678(%eax)",},
303{{0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
304"0f 1b 85 78 56 34 12 \tbndstx %bnd0,0x12345678(%ebp)",},
305{{0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
306"0f 1b 84 01 78 56 34 12 \tbndstx %bnd0,0x12345678(%ecx,%eax,1)",},
307{{0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
308"0f 1b 84 05 78 56 34 12 \tbndstx %bnd0,0x12345678(%ebp,%eax,1)",},
309{{0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
310"0f 1b 84 08 78 56 34 12 \tbndstx %bnd0,0x12345678(%eax,%ecx,1)",},
311{{0xf2, 0xe8, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "call", "unconditional",
312"f2 e8 fc ff ff ff \tbnd call 3c3 <main+0x3c3>",},
313{{0xf2, 0xff, 0x10, }, 3, 0, "call", "indirect",
314"f2 ff 10 \tbnd call *(%eax)",},
315{{0xf2, 0xc3, }, 2, 0, "ret", "indirect",
316"f2 c3 \tbnd ret ",},
317{{0xf2, 0xe9, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "jmp", "unconditional",
318"f2 e9 fc ff ff ff \tbnd jmp 3ce <main+0x3ce>",},
319{{0xf2, 0xe9, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "jmp", "unconditional",
320"f2 e9 fc ff ff ff \tbnd jmp 3d4 <main+0x3d4>",},
321{{0xf2, 0xff, 0x21, }, 3, 0, "jmp", "indirect",
322"f2 ff 21 \tbnd jmp *(%ecx)",},
323{{0xf2, 0x0f, 0x85, 0xfc, 0xff, 0xff, 0xff, }, 7, 0xfffffffc, "jcc", "conditional",
324"f2 0f 85 fc ff ff ff \tbnd jne 3de <main+0x3de>",},
325{{0x0f, 0x3a, 0xcc, 0xc1, 0x00, }, 5, 0, "", "",
326"0f 3a cc c1 00 \tsha1rnds4 $0x0,%xmm1,%xmm0",},
327{{0x0f, 0x3a, 0xcc, 0xd7, 0x91, }, 5, 0, "", "",
328"0f 3a cc d7 91 \tsha1rnds4 $0x91,%xmm7,%xmm2",},
329{{0x0f, 0x3a, 0xcc, 0x00, 0x91, }, 5, 0, "", "",
330"0f 3a cc 00 91 \tsha1rnds4 $0x91,(%eax),%xmm0",},
331{{0x0f, 0x3a, 0xcc, 0x05, 0x78, 0x56, 0x34, 0x12, 0x91, }, 9, 0, "", "",
332"0f 3a cc 05 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678,%xmm0",},
333{{0x0f, 0x3a, 0xcc, 0x18, 0x91, }, 5, 0, "", "",
334"0f 3a cc 18 91 \tsha1rnds4 $0x91,(%eax),%xmm3",},
335{{0x0f, 0x3a, 0xcc, 0x04, 0x01, 0x91, }, 6, 0, "", "",
336"0f 3a cc 04 01 91 \tsha1rnds4 $0x91,(%ecx,%eax,1),%xmm0",},
337{{0x0f, 0x3a, 0xcc, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
338"0f 3a cc 04 05 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(,%eax,1),%xmm0",},
339{{0x0f, 0x3a, 0xcc, 0x04, 0x08, 0x91, }, 6, 0, "", "",
340"0f 3a cc 04 08 91 \tsha1rnds4 $0x91,(%eax,%ecx,1),%xmm0",},
341{{0x0f, 0x3a, 0xcc, 0x04, 0xc8, 0x91, }, 6, 0, "", "",
342"0f 3a cc 04 c8 91 \tsha1rnds4 $0x91,(%eax,%ecx,8),%xmm0",},
343{{0x0f, 0x3a, 0xcc, 0x40, 0x12, 0x91, }, 6, 0, "", "",
344"0f 3a cc 40 12 91 \tsha1rnds4 $0x91,0x12(%eax),%xmm0",},
345{{0x0f, 0x3a, 0xcc, 0x45, 0x12, 0x91, }, 6, 0, "", "",
346"0f 3a cc 45 12 91 \tsha1rnds4 $0x91,0x12(%ebp),%xmm0",},
347{{0x0f, 0x3a, 0xcc, 0x44, 0x01, 0x12, 0x91, }, 7, 0, "", "",
348"0f 3a cc 44 01 12 91 \tsha1rnds4 $0x91,0x12(%ecx,%eax,1),%xmm0",},
349{{0x0f, 0x3a, 0xcc, 0x44, 0x05, 0x12, 0x91, }, 7, 0, "", "",
350"0f 3a cc 44 05 12 91 \tsha1rnds4 $0x91,0x12(%ebp,%eax,1),%xmm0",},
351{{0x0f, 0x3a, 0xcc, 0x44, 0x08, 0x12, 0x91, }, 7, 0, "", "",
352"0f 3a cc 44 08 12 91 \tsha1rnds4 $0x91,0x12(%eax,%ecx,1),%xmm0",},
353{{0x0f, 0x3a, 0xcc, 0x44, 0xc8, 0x12, 0x91, }, 7, 0, "", "",
354"0f 3a cc 44 c8 12 91 \tsha1rnds4 $0x91,0x12(%eax,%ecx,8),%xmm0",},
355{{0x0f, 0x3a, 0xcc, 0x80, 0x78, 0x56, 0x34, 0x12, 0x91, }, 9, 0, "", "",
356"0f 3a cc 80 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%eax),%xmm0",},
357{{0x0f, 0x3a, 0xcc, 0x85, 0x78, 0x56, 0x34, 0x12, 0x91, }, 9, 0, "", "",
358"0f 3a cc 85 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%ebp),%xmm0",},
359{{0x0f, 0x3a, 0xcc, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
360"0f 3a cc 84 01 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%ecx,%eax,1),%xmm0",},
361{{0x0f, 0x3a, 0xcc, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
362"0f 3a cc 84 05 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%ebp,%eax,1),%xmm0",},
363{{0x0f, 0x3a, 0xcc, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
364"0f 3a cc 84 08 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%eax,%ecx,1),%xmm0",},
365{{0x0f, 0x3a, 0xcc, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
366"0f 3a cc 84 c8 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%eax,%ecx,8),%xmm0",},
367{{0x0f, 0x38, 0xc8, 0xc1, }, 4, 0, "", "",
368"0f 38 c8 c1 \tsha1nexte %xmm1,%xmm0",},
369{{0x0f, 0x38, 0xc8, 0xd7, }, 4, 0, "", "",
370"0f 38 c8 d7 \tsha1nexte %xmm7,%xmm2",},
371{{0x0f, 0x38, 0xc8, 0x00, }, 4, 0, "", "",
372"0f 38 c8 00 \tsha1nexte (%eax),%xmm0",},
373{{0x0f, 0x38, 0xc8, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
374"0f 38 c8 05 78 56 34 12 \tsha1nexte 0x12345678,%xmm0",},
375{{0x0f, 0x38, 0xc8, 0x18, }, 4, 0, "", "",
376"0f 38 c8 18 \tsha1nexte (%eax),%xmm3",},
377{{0x0f, 0x38, 0xc8, 0x04, 0x01, }, 5, 0, "", "",
378"0f 38 c8 04 01 \tsha1nexte (%ecx,%eax,1),%xmm0",},
379{{0x0f, 0x38, 0xc8, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
380"0f 38 c8 04 05 78 56 34 12 \tsha1nexte 0x12345678(,%eax,1),%xmm0",},
381{{0x0f, 0x38, 0xc8, 0x04, 0x08, }, 5, 0, "", "",
382"0f 38 c8 04 08 \tsha1nexte (%eax,%ecx,1),%xmm0",},
383{{0x0f, 0x38, 0xc8, 0x04, 0xc8, }, 5, 0, "", "",
384"0f 38 c8 04 c8 \tsha1nexte (%eax,%ecx,8),%xmm0",},
385{{0x0f, 0x38, 0xc8, 0x40, 0x12, }, 5, 0, "", "",
386"0f 38 c8 40 12 \tsha1nexte 0x12(%eax),%xmm0",},
387{{0x0f, 0x38, 0xc8, 0x45, 0x12, }, 5, 0, "", "",
388"0f 38 c8 45 12 \tsha1nexte 0x12(%ebp),%xmm0",},
389{{0x0f, 0x38, 0xc8, 0x44, 0x01, 0x12, }, 6, 0, "", "",
390"0f 38 c8 44 01 12 \tsha1nexte 0x12(%ecx,%eax,1),%xmm0",},
391{{0x0f, 0x38, 0xc8, 0x44, 0x05, 0x12, }, 6, 0, "", "",
392"0f 38 c8 44 05 12 \tsha1nexte 0x12(%ebp,%eax,1),%xmm0",},
393{{0x0f, 0x38, 0xc8, 0x44, 0x08, 0x12, }, 6, 0, "", "",
394"0f 38 c8 44 08 12 \tsha1nexte 0x12(%eax,%ecx,1),%xmm0",},
395{{0x0f, 0x38, 0xc8, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
396"0f 38 c8 44 c8 12 \tsha1nexte 0x12(%eax,%ecx,8),%xmm0",},
397{{0x0f, 0x38, 0xc8, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
398"0f 38 c8 80 78 56 34 12 \tsha1nexte 0x12345678(%eax),%xmm0",},
399{{0x0f, 0x38, 0xc8, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
400"0f 38 c8 85 78 56 34 12 \tsha1nexte 0x12345678(%ebp),%xmm0",},
401{{0x0f, 0x38, 0xc8, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
402"0f 38 c8 84 01 78 56 34 12 \tsha1nexte 0x12345678(%ecx,%eax,1),%xmm0",},
403{{0x0f, 0x38, 0xc8, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
404"0f 38 c8 84 05 78 56 34 12 \tsha1nexte 0x12345678(%ebp,%eax,1),%xmm0",},
405{{0x0f, 0x38, 0xc8, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
406"0f 38 c8 84 08 78 56 34 12 \tsha1nexte 0x12345678(%eax,%ecx,1),%xmm0",},
407{{0x0f, 0x38, 0xc8, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
408"0f 38 c8 84 c8 78 56 34 12 \tsha1nexte 0x12345678(%eax,%ecx,8),%xmm0",},
409{{0x0f, 0x38, 0xc9, 0xc1, }, 4, 0, "", "",
410"0f 38 c9 c1 \tsha1msg1 %xmm1,%xmm0",},
411{{0x0f, 0x38, 0xc9, 0xd7, }, 4, 0, "", "",
412"0f 38 c9 d7 \tsha1msg1 %xmm7,%xmm2",},
413{{0x0f, 0x38, 0xc9, 0x00, }, 4, 0, "", "",
414"0f 38 c9 00 \tsha1msg1 (%eax),%xmm0",},
415{{0x0f, 0x38, 0xc9, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
416"0f 38 c9 05 78 56 34 12 \tsha1msg1 0x12345678,%xmm0",},
417{{0x0f, 0x38, 0xc9, 0x18, }, 4, 0, "", "",
418"0f 38 c9 18 \tsha1msg1 (%eax),%xmm3",},
419{{0x0f, 0x38, 0xc9, 0x04, 0x01, }, 5, 0, "", "",
420"0f 38 c9 04 01 \tsha1msg1 (%ecx,%eax,1),%xmm0",},
421{{0x0f, 0x38, 0xc9, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
422"0f 38 c9 04 05 78 56 34 12 \tsha1msg1 0x12345678(,%eax,1),%xmm0",},
423{{0x0f, 0x38, 0xc9, 0x04, 0x08, }, 5, 0, "", "",
424"0f 38 c9 04 08 \tsha1msg1 (%eax,%ecx,1),%xmm0",},
425{{0x0f, 0x38, 0xc9, 0x04, 0xc8, }, 5, 0, "", "",
426"0f 38 c9 04 c8 \tsha1msg1 (%eax,%ecx,8),%xmm0",},
427{{0x0f, 0x38, 0xc9, 0x40, 0x12, }, 5, 0, "", "",
428"0f 38 c9 40 12 \tsha1msg1 0x12(%eax),%xmm0",},
429{{0x0f, 0x38, 0xc9, 0x45, 0x12, }, 5, 0, "", "",
430"0f 38 c9 45 12 \tsha1msg1 0x12(%ebp),%xmm0",},
431{{0x0f, 0x38, 0xc9, 0x44, 0x01, 0x12, }, 6, 0, "", "",
432"0f 38 c9 44 01 12 \tsha1msg1 0x12(%ecx,%eax,1),%xmm0",},
433{{0x0f, 0x38, 0xc9, 0x44, 0x05, 0x12, }, 6, 0, "", "",
434"0f 38 c9 44 05 12 \tsha1msg1 0x12(%ebp,%eax,1),%xmm0",},
435{{0x0f, 0x38, 0xc9, 0x44, 0x08, 0x12, }, 6, 0, "", "",
436"0f 38 c9 44 08 12 \tsha1msg1 0x12(%eax,%ecx,1),%xmm0",},
437{{0x0f, 0x38, 0xc9, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
438"0f 38 c9 44 c8 12 \tsha1msg1 0x12(%eax,%ecx,8),%xmm0",},
439{{0x0f, 0x38, 0xc9, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
440"0f 38 c9 80 78 56 34 12 \tsha1msg1 0x12345678(%eax),%xmm0",},
441{{0x0f, 0x38, 0xc9, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
442"0f 38 c9 85 78 56 34 12 \tsha1msg1 0x12345678(%ebp),%xmm0",},
443{{0x0f, 0x38, 0xc9, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
444"0f 38 c9 84 01 78 56 34 12 \tsha1msg1 0x12345678(%ecx,%eax,1),%xmm0",},
445{{0x0f, 0x38, 0xc9, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
446"0f 38 c9 84 05 78 56 34 12 \tsha1msg1 0x12345678(%ebp,%eax,1),%xmm0",},
447{{0x0f, 0x38, 0xc9, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
448"0f 38 c9 84 08 78 56 34 12 \tsha1msg1 0x12345678(%eax,%ecx,1),%xmm0",},
449{{0x0f, 0x38, 0xc9, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
450"0f 38 c9 84 c8 78 56 34 12 \tsha1msg1 0x12345678(%eax,%ecx,8),%xmm0",},
451{{0x0f, 0x38, 0xca, 0xc1, }, 4, 0, "", "",
452"0f 38 ca c1 \tsha1msg2 %xmm1,%xmm0",},
453{{0x0f, 0x38, 0xca, 0xd7, }, 4, 0, "", "",
454"0f 38 ca d7 \tsha1msg2 %xmm7,%xmm2",},
455{{0x0f, 0x38, 0xca, 0x00, }, 4, 0, "", "",
456"0f 38 ca 00 \tsha1msg2 (%eax),%xmm0",},
457{{0x0f, 0x38, 0xca, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
458"0f 38 ca 05 78 56 34 12 \tsha1msg2 0x12345678,%xmm0",},
459{{0x0f, 0x38, 0xca, 0x18, }, 4, 0, "", "",
460"0f 38 ca 18 \tsha1msg2 (%eax),%xmm3",},
461{{0x0f, 0x38, 0xca, 0x04, 0x01, }, 5, 0, "", "",
462"0f 38 ca 04 01 \tsha1msg2 (%ecx,%eax,1),%xmm0",},
463{{0x0f, 0x38, 0xca, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
464"0f 38 ca 04 05 78 56 34 12 \tsha1msg2 0x12345678(,%eax,1),%xmm0",},
465{{0x0f, 0x38, 0xca, 0x04, 0x08, }, 5, 0, "", "",
466"0f 38 ca 04 08 \tsha1msg2 (%eax,%ecx,1),%xmm0",},
467{{0x0f, 0x38, 0xca, 0x04, 0xc8, }, 5, 0, "", "",
468"0f 38 ca 04 c8 \tsha1msg2 (%eax,%ecx,8),%xmm0",},
469{{0x0f, 0x38, 0xca, 0x40, 0x12, }, 5, 0, "", "",
470"0f 38 ca 40 12 \tsha1msg2 0x12(%eax),%xmm0",},
471{{0x0f, 0x38, 0xca, 0x45, 0x12, }, 5, 0, "", "",
472"0f 38 ca 45 12 \tsha1msg2 0x12(%ebp),%xmm0",},
473{{0x0f, 0x38, 0xca, 0x44, 0x01, 0x12, }, 6, 0, "", "",
474"0f 38 ca 44 01 12 \tsha1msg2 0x12(%ecx,%eax,1),%xmm0",},
475{{0x0f, 0x38, 0xca, 0x44, 0x05, 0x12, }, 6, 0, "", "",
476"0f 38 ca 44 05 12 \tsha1msg2 0x12(%ebp,%eax,1),%xmm0",},
477{{0x0f, 0x38, 0xca, 0x44, 0x08, 0x12, }, 6, 0, "", "",
478"0f 38 ca 44 08 12 \tsha1msg2 0x12(%eax,%ecx,1),%xmm0",},
479{{0x0f, 0x38, 0xca, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
480"0f 38 ca 44 c8 12 \tsha1msg2 0x12(%eax,%ecx,8),%xmm0",},
481{{0x0f, 0x38, 0xca, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
482"0f 38 ca 80 78 56 34 12 \tsha1msg2 0x12345678(%eax),%xmm0",},
483{{0x0f, 0x38, 0xca, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
484"0f 38 ca 85 78 56 34 12 \tsha1msg2 0x12345678(%ebp),%xmm0",},
485{{0x0f, 0x38, 0xca, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
486"0f 38 ca 84 01 78 56 34 12 \tsha1msg2 0x12345678(%ecx,%eax,1),%xmm0",},
487{{0x0f, 0x38, 0xca, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
488"0f 38 ca 84 05 78 56 34 12 \tsha1msg2 0x12345678(%ebp,%eax,1),%xmm0",},
489{{0x0f, 0x38, 0xca, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
490"0f 38 ca 84 08 78 56 34 12 \tsha1msg2 0x12345678(%eax,%ecx,1),%xmm0",},
491{{0x0f, 0x38, 0xca, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
492"0f 38 ca 84 c8 78 56 34 12 \tsha1msg2 0x12345678(%eax,%ecx,8),%xmm0",},
493{{0x0f, 0x38, 0xcb, 0xcc, }, 4, 0, "", "",
494"0f 38 cb cc \tsha256rnds2 %xmm0,%xmm4,%xmm1",},
495{{0x0f, 0x38, 0xcb, 0xd7, }, 4, 0, "", "",
496"0f 38 cb d7 \tsha256rnds2 %xmm0,%xmm7,%xmm2",},
497{{0x0f, 0x38, 0xcb, 0x08, }, 4, 0, "", "",
498"0f 38 cb 08 \tsha256rnds2 %xmm0,(%eax),%xmm1",},
499{{0x0f, 0x38, 0xcb, 0x0d, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
500"0f 38 cb 0d 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678,%xmm1",},
501{{0x0f, 0x38, 0xcb, 0x18, }, 4, 0, "", "",
502"0f 38 cb 18 \tsha256rnds2 %xmm0,(%eax),%xmm3",},
503{{0x0f, 0x38, 0xcb, 0x0c, 0x01, }, 5, 0, "", "",
504"0f 38 cb 0c 01 \tsha256rnds2 %xmm0,(%ecx,%eax,1),%xmm1",},
505{{0x0f, 0x38, 0xcb, 0x0c, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
506"0f 38 cb 0c 05 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(,%eax,1),%xmm1",},
507{{0x0f, 0x38, 0xcb, 0x0c, 0x08, }, 5, 0, "", "",
508"0f 38 cb 0c 08 \tsha256rnds2 %xmm0,(%eax,%ecx,1),%xmm1",},
509{{0x0f, 0x38, 0xcb, 0x0c, 0xc8, }, 5, 0, "", "",
510"0f 38 cb 0c c8 \tsha256rnds2 %xmm0,(%eax,%ecx,8),%xmm1",},
511{{0x0f, 0x38, 0xcb, 0x48, 0x12, }, 5, 0, "", "",
512"0f 38 cb 48 12 \tsha256rnds2 %xmm0,0x12(%eax),%xmm1",},
513{{0x0f, 0x38, 0xcb, 0x4d, 0x12, }, 5, 0, "", "",
514"0f 38 cb 4d 12 \tsha256rnds2 %xmm0,0x12(%ebp),%xmm1",},
515{{0x0f, 0x38, 0xcb, 0x4c, 0x01, 0x12, }, 6, 0, "", "",
516"0f 38 cb 4c 01 12 \tsha256rnds2 %xmm0,0x12(%ecx,%eax,1),%xmm1",},
517{{0x0f, 0x38, 0xcb, 0x4c, 0x05, 0x12, }, 6, 0, "", "",
518"0f 38 cb 4c 05 12 \tsha256rnds2 %xmm0,0x12(%ebp,%eax,1),%xmm1",},
519{{0x0f, 0x38, 0xcb, 0x4c, 0x08, 0x12, }, 6, 0, "", "",
520"0f 38 cb 4c 08 12 \tsha256rnds2 %xmm0,0x12(%eax,%ecx,1),%xmm1",},
521{{0x0f, 0x38, 0xcb, 0x4c, 0xc8, 0x12, }, 6, 0, "", "",
522"0f 38 cb 4c c8 12 \tsha256rnds2 %xmm0,0x12(%eax,%ecx,8),%xmm1",},
523{{0x0f, 0x38, 0xcb, 0x88, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
524"0f 38 cb 88 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%eax),%xmm1",},
525{{0x0f, 0x38, 0xcb, 0x8d, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
526"0f 38 cb 8d 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%ebp),%xmm1",},
527{{0x0f, 0x38, 0xcb, 0x8c, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
528"0f 38 cb 8c 01 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%ecx,%eax,1),%xmm1",},
529{{0x0f, 0x38, 0xcb, 0x8c, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
530"0f 38 cb 8c 05 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%ebp,%eax,1),%xmm1",},
531{{0x0f, 0x38, 0xcb, 0x8c, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
532"0f 38 cb 8c 08 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%eax,%ecx,1),%xmm1",},
533{{0x0f, 0x38, 0xcb, 0x8c, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
534"0f 38 cb 8c c8 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%eax,%ecx,8),%xmm1",},
535{{0x0f, 0x38, 0xcc, 0xc1, }, 4, 0, "", "",
536"0f 38 cc c1 \tsha256msg1 %xmm1,%xmm0",},
537{{0x0f, 0x38, 0xcc, 0xd7, }, 4, 0, "", "",
538"0f 38 cc d7 \tsha256msg1 %xmm7,%xmm2",},
539{{0x0f, 0x38, 0xcc, 0x00, }, 4, 0, "", "",
540"0f 38 cc 00 \tsha256msg1 (%eax),%xmm0",},
541{{0x0f, 0x38, 0xcc, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
542"0f 38 cc 05 78 56 34 12 \tsha256msg1 0x12345678,%xmm0",},
543{{0x0f, 0x38, 0xcc, 0x18, }, 4, 0, "", "",
544"0f 38 cc 18 \tsha256msg1 (%eax),%xmm3",},
545{{0x0f, 0x38, 0xcc, 0x04, 0x01, }, 5, 0, "", "",
546"0f 38 cc 04 01 \tsha256msg1 (%ecx,%eax,1),%xmm0",},
547{{0x0f, 0x38, 0xcc, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
548"0f 38 cc 04 05 78 56 34 12 \tsha256msg1 0x12345678(,%eax,1),%xmm0",},
549{{0x0f, 0x38, 0xcc, 0x04, 0x08, }, 5, 0, "", "",
550"0f 38 cc 04 08 \tsha256msg1 (%eax,%ecx,1),%xmm0",},
551{{0x0f, 0x38, 0xcc, 0x04, 0xc8, }, 5, 0, "", "",
552"0f 38 cc 04 c8 \tsha256msg1 (%eax,%ecx,8),%xmm0",},
553{{0x0f, 0x38, 0xcc, 0x40, 0x12, }, 5, 0, "", "",
554"0f 38 cc 40 12 \tsha256msg1 0x12(%eax),%xmm0",},
555{{0x0f, 0x38, 0xcc, 0x45, 0x12, }, 5, 0, "", "",
556"0f 38 cc 45 12 \tsha256msg1 0x12(%ebp),%xmm0",},
557{{0x0f, 0x38, 0xcc, 0x44, 0x01, 0x12, }, 6, 0, "", "",
558"0f 38 cc 44 01 12 \tsha256msg1 0x12(%ecx,%eax,1),%xmm0",},
559{{0x0f, 0x38, 0xcc, 0x44, 0x05, 0x12, }, 6, 0, "", "",
560"0f 38 cc 44 05 12 \tsha256msg1 0x12(%ebp,%eax,1),%xmm0",},
561{{0x0f, 0x38, 0xcc, 0x44, 0x08, 0x12, }, 6, 0, "", "",
562"0f 38 cc 44 08 12 \tsha256msg1 0x12(%eax,%ecx,1),%xmm0",},
563{{0x0f, 0x38, 0xcc, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
564"0f 38 cc 44 c8 12 \tsha256msg1 0x12(%eax,%ecx,8),%xmm0",},
565{{0x0f, 0x38, 0xcc, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
566"0f 38 cc 80 78 56 34 12 \tsha256msg1 0x12345678(%eax),%xmm0",},
567{{0x0f, 0x38, 0xcc, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
568"0f 38 cc 85 78 56 34 12 \tsha256msg1 0x12345678(%ebp),%xmm0",},
569{{0x0f, 0x38, 0xcc, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
570"0f 38 cc 84 01 78 56 34 12 \tsha256msg1 0x12345678(%ecx,%eax,1),%xmm0",},
571{{0x0f, 0x38, 0xcc, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
572"0f 38 cc 84 05 78 56 34 12 \tsha256msg1 0x12345678(%ebp,%eax,1),%xmm0",},
573{{0x0f, 0x38, 0xcc, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
574"0f 38 cc 84 08 78 56 34 12 \tsha256msg1 0x12345678(%eax,%ecx,1),%xmm0",},
575{{0x0f, 0x38, 0xcc, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
576"0f 38 cc 84 c8 78 56 34 12 \tsha256msg1 0x12345678(%eax,%ecx,8),%xmm0",},
577{{0x0f, 0x38, 0xcd, 0xc1, }, 4, 0, "", "",
578"0f 38 cd c1 \tsha256msg2 %xmm1,%xmm0",},
579{{0x0f, 0x38, 0xcd, 0xd7, }, 4, 0, "", "",
580"0f 38 cd d7 \tsha256msg2 %xmm7,%xmm2",},
581{{0x0f, 0x38, 0xcd, 0x00, }, 4, 0, "", "",
582"0f 38 cd 00 \tsha256msg2 (%eax),%xmm0",},
583{{0x0f, 0x38, 0xcd, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
584"0f 38 cd 05 78 56 34 12 \tsha256msg2 0x12345678,%xmm0",},
585{{0x0f, 0x38, 0xcd, 0x18, }, 4, 0, "", "",
586"0f 38 cd 18 \tsha256msg2 (%eax),%xmm3",},
587{{0x0f, 0x38, 0xcd, 0x04, 0x01, }, 5, 0, "", "",
588"0f 38 cd 04 01 \tsha256msg2 (%ecx,%eax,1),%xmm0",},
589{{0x0f, 0x38, 0xcd, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
590"0f 38 cd 04 05 78 56 34 12 \tsha256msg2 0x12345678(,%eax,1),%xmm0",},
591{{0x0f, 0x38, 0xcd, 0x04, 0x08, }, 5, 0, "", "",
592"0f 38 cd 04 08 \tsha256msg2 (%eax,%ecx,1),%xmm0",},
593{{0x0f, 0x38, 0xcd, 0x04, 0xc8, }, 5, 0, "", "",
594"0f 38 cd 04 c8 \tsha256msg2 (%eax,%ecx,8),%xmm0",},
595{{0x0f, 0x38, 0xcd, 0x40, 0x12, }, 5, 0, "", "",
596"0f 38 cd 40 12 \tsha256msg2 0x12(%eax),%xmm0",},
597{{0x0f, 0x38, 0xcd, 0x45, 0x12, }, 5, 0, "", "",
598"0f 38 cd 45 12 \tsha256msg2 0x12(%ebp),%xmm0",},
599{{0x0f, 0x38, 0xcd, 0x44, 0x01, 0x12, }, 6, 0, "", "",
600"0f 38 cd 44 01 12 \tsha256msg2 0x12(%ecx,%eax,1),%xmm0",},
601{{0x0f, 0x38, 0xcd, 0x44, 0x05, 0x12, }, 6, 0, "", "",
602"0f 38 cd 44 05 12 \tsha256msg2 0x12(%ebp,%eax,1),%xmm0",},
603{{0x0f, 0x38, 0xcd, 0x44, 0x08, 0x12, }, 6, 0, "", "",
604"0f 38 cd 44 08 12 \tsha256msg2 0x12(%eax,%ecx,1),%xmm0",},
605{{0x0f, 0x38, 0xcd, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
606"0f 38 cd 44 c8 12 \tsha256msg2 0x12(%eax,%ecx,8),%xmm0",},
607{{0x0f, 0x38, 0xcd, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
608"0f 38 cd 80 78 56 34 12 \tsha256msg2 0x12345678(%eax),%xmm0",},
609{{0x0f, 0x38, 0xcd, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
610"0f 38 cd 85 78 56 34 12 \tsha256msg2 0x12345678(%ebp),%xmm0",},
611{{0x0f, 0x38, 0xcd, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
612"0f 38 cd 84 01 78 56 34 12 \tsha256msg2 0x12345678(%ecx,%eax,1),%xmm0",},
613{{0x0f, 0x38, 0xcd, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
614"0f 38 cd 84 05 78 56 34 12 \tsha256msg2 0x12345678(%ebp,%eax,1),%xmm0",},
615{{0x0f, 0x38, 0xcd, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
616"0f 38 cd 84 08 78 56 34 12 \tsha256msg2 0x12345678(%eax,%ecx,1),%xmm0",},
617{{0x0f, 0x38, 0xcd, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
618"0f 38 cd 84 c8 78 56 34 12 \tsha256msg2 0x12345678(%eax,%ecx,8),%xmm0",},
619{{0x66, 0x0f, 0xae, 0x38, }, 4, 0, "", "",
620"66 0f ae 38 \tclflushopt (%eax)",},
621{{0x66, 0x0f, 0xae, 0x3d, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
622"66 0f ae 3d 78 56 34 12 \tclflushopt 0x12345678",},
623{{0x66, 0x0f, 0xae, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
624"66 0f ae bc c8 78 56 34 12 \tclflushopt 0x12345678(%eax,%ecx,8)",},
625{{0x0f, 0xae, 0x38, }, 3, 0, "", "",
626"0f ae 38 \tclflush (%eax)",},
627{{0x0f, 0xae, 0xf8, }, 3, 0, "", "",
628"0f ae f8 \tsfence ",},
629{{0x66, 0x0f, 0xae, 0x30, }, 4, 0, "", "",
630"66 0f ae 30 \tclwb (%eax)",},
631{{0x66, 0x0f, 0xae, 0x35, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
632"66 0f ae 35 78 56 34 12 \tclwb 0x12345678",},
633{{0x66, 0x0f, 0xae, 0xb4, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
634"66 0f ae b4 c8 78 56 34 12 \tclwb 0x12345678(%eax,%ecx,8)",},
635{{0x0f, 0xae, 0x30, }, 3, 0, "", "",
636"0f ae 30 \txsaveopt (%eax)",},
637{{0x0f, 0xae, 0xf0, }, 3, 0, "", "",
638"0f ae f0 \tmfence ",},
639{{0x0f, 0xc7, 0x20, }, 3, 0, "", "",
640"0f c7 20 \txsavec (%eax)",},
641{{0x0f, 0xc7, 0x25, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
642"0f c7 25 78 56 34 12 \txsavec 0x12345678",},
643{{0x0f, 0xc7, 0xa4, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
644"0f c7 a4 c8 78 56 34 12 \txsavec 0x12345678(%eax,%ecx,8)",},
645{{0x0f, 0xc7, 0x28, }, 3, 0, "", "",
646"0f c7 28 \txsaves (%eax)",},
647{{0x0f, 0xc7, 0x2d, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
648"0f c7 2d 78 56 34 12 \txsaves 0x12345678",},
649{{0x0f, 0xc7, 0xac, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
650"0f c7 ac c8 78 56 34 12 \txsaves 0x12345678(%eax,%ecx,8)",},
651{{0x0f, 0xc7, 0x18, }, 3, 0, "", "",
652"0f c7 18 \txrstors (%eax)",},
653{{0x0f, 0xc7, 0x1d, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
654"0f c7 1d 78 56 34 12 \txrstors 0x12345678",},
655{{0x0f, 0xc7, 0x9c, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
656"0f c7 9c c8 78 56 34 12 \txrstors 0x12345678(%eax,%ecx,8)",},
657{{0x66, 0x0f, 0xae, 0xf8, }, 4, 0, "", "",
658"66 0f ae f8 \tpcommit ",},
tools/perf/arch/x86/tests/insn-x86-dat-64.c+768−0
@@ -0,0 +1,768 @@
1/*
2 * Generated by gen-insn-x86-dat.sh and gen-insn-x86-dat.awk
3 * from insn-x86-dat-src.c for inclusion by insn-x86.c
4 * Do not change this code.
5*/
6
7{{0x0f, 0x31, }, 2, 0, "", "",
8"0f 31 \trdtsc ",},
9{{0xf3, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
10"f3 0f 1b 00 \tbndmk (%rax),%bnd0",},
11{{0xf3, 0x41, 0x0f, 0x1b, 0x00, }, 5, 0, "", "",
12"f3 41 0f 1b 00 \tbndmk (%r8),%bnd0",},
13{{0xf3, 0x0f, 0x1b, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
14"f3 0f 1b 04 25 78 56 34 12 \tbndmk 0x12345678,%bnd0",},
15{{0xf3, 0x0f, 0x1b, 0x18, }, 4, 0, "", "",
16"f3 0f 1b 18 \tbndmk (%rax),%bnd3",},
17{{0xf3, 0x0f, 0x1b, 0x04, 0x01, }, 5, 0, "", "",
18"f3 0f 1b 04 01 \tbndmk (%rcx,%rax,1),%bnd0",},
19{{0xf3, 0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
20"f3 0f 1b 04 05 78 56 34 12 \tbndmk 0x12345678(,%rax,1),%bnd0",},
21{{0xf3, 0x0f, 0x1b, 0x04, 0x08, }, 5, 0, "", "",
22"f3 0f 1b 04 08 \tbndmk (%rax,%rcx,1),%bnd0",},
23{{0xf3, 0x0f, 0x1b, 0x04, 0xc8, }, 5, 0, "", "",
24"f3 0f 1b 04 c8 \tbndmk (%rax,%rcx,8),%bnd0",},
25{{0xf3, 0x0f, 0x1b, 0x40, 0x12, }, 5, 0, "", "",
26"f3 0f 1b 40 12 \tbndmk 0x12(%rax),%bnd0",},
27{{0xf3, 0x0f, 0x1b, 0x45, 0x12, }, 5, 0, "", "",
28"f3 0f 1b 45 12 \tbndmk 0x12(%rbp),%bnd0",},
29{{0xf3, 0x0f, 0x1b, 0x44, 0x01, 0x12, }, 6, 0, "", "",
30"f3 0f 1b 44 01 12 \tbndmk 0x12(%rcx,%rax,1),%bnd0",},
31{{0xf3, 0x0f, 0x1b, 0x44, 0x05, 0x12, }, 6, 0, "", "",
32"f3 0f 1b 44 05 12 \tbndmk 0x12(%rbp,%rax,1),%bnd0",},
33{{0xf3, 0x0f, 0x1b, 0x44, 0x08, 0x12, }, 6, 0, "", "",
34"f3 0f 1b 44 08 12 \tbndmk 0x12(%rax,%rcx,1),%bnd0",},
35{{0xf3, 0x0f, 0x1b, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
36"f3 0f 1b 44 c8 12 \tbndmk 0x12(%rax,%rcx,8),%bnd0",},
37{{0xf3, 0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
38"f3 0f 1b 80 78 56 34 12 \tbndmk 0x12345678(%rax),%bnd0",},
39{{0xf3, 0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
40"f3 0f 1b 85 78 56 34 12 \tbndmk 0x12345678(%rbp),%bnd0",},
41{{0xf3, 0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
42"f3 0f 1b 84 01 78 56 34 12 \tbndmk 0x12345678(%rcx,%rax,1),%bnd0",},
43{{0xf3, 0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
44"f3 0f 1b 84 05 78 56 34 12 \tbndmk 0x12345678(%rbp,%rax,1),%bnd0",},
45{{0xf3, 0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
46"f3 0f 1b 84 08 78 56 34 12 \tbndmk 0x12345678(%rax,%rcx,1),%bnd0",},
47{{0xf3, 0x0f, 0x1b, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
48"f3 0f 1b 84 c8 78 56 34 12 \tbndmk 0x12345678(%rax,%rcx,8),%bnd0",},
49{{0xf3, 0x0f, 0x1a, 0x00, }, 4, 0, "", "",
50"f3 0f 1a 00 \tbndcl (%rax),%bnd0",},
51{{0xf3, 0x41, 0x0f, 0x1a, 0x00, }, 5, 0, "", "",
52"f3 41 0f 1a 00 \tbndcl (%r8),%bnd0",},
53{{0xf3, 0x0f, 0x1a, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
54"f3 0f 1a 04 25 78 56 34 12 \tbndcl 0x12345678,%bnd0",},
55{{0xf3, 0x0f, 0x1a, 0x18, }, 4, 0, "", "",
56"f3 0f 1a 18 \tbndcl (%rax),%bnd3",},
57{{0xf3, 0x0f, 0x1a, 0x04, 0x01, }, 5, 0, "", "",
58"f3 0f 1a 04 01 \tbndcl (%rcx,%rax,1),%bnd0",},
59{{0xf3, 0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
60"f3 0f 1a 04 05 78 56 34 12 \tbndcl 0x12345678(,%rax,1),%bnd0",},
61{{0xf3, 0x0f, 0x1a, 0x04, 0x08, }, 5, 0, "", "",
62"f3 0f 1a 04 08 \tbndcl (%rax,%rcx,1),%bnd0",},
63{{0xf3, 0x0f, 0x1a, 0x04, 0xc8, }, 5, 0, "", "",
64"f3 0f 1a 04 c8 \tbndcl (%rax,%rcx,8),%bnd0",},
65{{0xf3, 0x0f, 0x1a, 0x40, 0x12, }, 5, 0, "", "",
66"f3 0f 1a 40 12 \tbndcl 0x12(%rax),%bnd0",},
67{{0xf3, 0x0f, 0x1a, 0x45, 0x12, }, 5, 0, "", "",
68"f3 0f 1a 45 12 \tbndcl 0x12(%rbp),%bnd0",},
69{{0xf3, 0x0f, 0x1a, 0x44, 0x01, 0x12, }, 6, 0, "", "",
70"f3 0f 1a 44 01 12 \tbndcl 0x12(%rcx,%rax,1),%bnd0",},
71{{0xf3, 0x0f, 0x1a, 0x44, 0x05, 0x12, }, 6, 0, "", "",
72"f3 0f 1a 44 05 12 \tbndcl 0x12(%rbp,%rax,1),%bnd0",},
73{{0xf3, 0x0f, 0x1a, 0x44, 0x08, 0x12, }, 6, 0, "", "",
74"f3 0f 1a 44 08 12 \tbndcl 0x12(%rax,%rcx,1),%bnd0",},
75{{0xf3, 0x0f, 0x1a, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
76"f3 0f 1a 44 c8 12 \tbndcl 0x12(%rax,%rcx,8),%bnd0",},
77{{0xf3, 0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
78"f3 0f 1a 80 78 56 34 12 \tbndcl 0x12345678(%rax),%bnd0",},
79{{0xf3, 0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
80"f3 0f 1a 85 78 56 34 12 \tbndcl 0x12345678(%rbp),%bnd0",},
81{{0xf3, 0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
82"f3 0f 1a 84 01 78 56 34 12 \tbndcl 0x12345678(%rcx,%rax,1),%bnd0",},
83{{0xf3, 0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
84"f3 0f 1a 84 05 78 56 34 12 \tbndcl 0x12345678(%rbp,%rax,1),%bnd0",},
85{{0xf3, 0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
86"f3 0f 1a 84 08 78 56 34 12 \tbndcl 0x12345678(%rax,%rcx,1),%bnd0",},
87{{0xf3, 0x0f, 0x1a, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
88"f3 0f 1a 84 c8 78 56 34 12 \tbndcl 0x12345678(%rax,%rcx,8),%bnd0",},
89{{0xf3, 0x0f, 0x1a, 0xc0, }, 4, 0, "", "",
90"f3 0f 1a c0 \tbndcl %rax,%bnd0",},
91{{0xf2, 0x0f, 0x1a, 0x00, }, 4, 0, "", "",
92"f2 0f 1a 00 \tbndcu (%rax),%bnd0",},
93{{0xf2, 0x41, 0x0f, 0x1a, 0x00, }, 5, 0, "", "",
94"f2 41 0f 1a 00 \tbndcu (%r8),%bnd0",},
95{{0xf2, 0x0f, 0x1a, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
96"f2 0f 1a 04 25 78 56 34 12 \tbndcu 0x12345678,%bnd0",},
97{{0xf2, 0x0f, 0x1a, 0x18, }, 4, 0, "", "",
98"f2 0f 1a 18 \tbndcu (%rax),%bnd3",},
99{{0xf2, 0x0f, 0x1a, 0x04, 0x01, }, 5, 0, "", "",
100"f2 0f 1a 04 01 \tbndcu (%rcx,%rax,1),%bnd0",},
101{{0xf2, 0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
102"f2 0f 1a 04 05 78 56 34 12 \tbndcu 0x12345678(,%rax,1),%bnd0",},
103{{0xf2, 0x0f, 0x1a, 0x04, 0x08, }, 5, 0, "", "",
104"f2 0f 1a 04 08 \tbndcu (%rax,%rcx,1),%bnd0",},
105{{0xf2, 0x0f, 0x1a, 0x04, 0xc8, }, 5, 0, "", "",
106"f2 0f 1a 04 c8 \tbndcu (%rax,%rcx,8),%bnd0",},
107{{0xf2, 0x0f, 0x1a, 0x40, 0x12, }, 5, 0, "", "",
108"f2 0f 1a 40 12 \tbndcu 0x12(%rax),%bnd0",},
109{{0xf2, 0x0f, 0x1a, 0x45, 0x12, }, 5, 0, "", "",
110"f2 0f 1a 45 12 \tbndcu 0x12(%rbp),%bnd0",},
111{{0xf2, 0x0f, 0x1a, 0x44, 0x01, 0x12, }, 6, 0, "", "",
112"f2 0f 1a 44 01 12 \tbndcu 0x12(%rcx,%rax,1),%bnd0",},
113{{0xf2, 0x0f, 0x1a, 0x44, 0x05, 0x12, }, 6, 0, "", "",
114"f2 0f 1a 44 05 12 \tbndcu 0x12(%rbp,%rax,1),%bnd0",},
115{{0xf2, 0x0f, 0x1a, 0x44, 0x08, 0x12, }, 6, 0, "", "",
116"f2 0f 1a 44 08 12 \tbndcu 0x12(%rax,%rcx,1),%bnd0",},
117{{0xf2, 0x0f, 0x1a, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
118"f2 0f 1a 44 c8 12 \tbndcu 0x12(%rax,%rcx,8),%bnd0",},
119{{0xf2, 0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
120"f2 0f 1a 80 78 56 34 12 \tbndcu 0x12345678(%rax),%bnd0",},
121{{0xf2, 0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
122"f2 0f 1a 85 78 56 34 12 \tbndcu 0x12345678(%rbp),%bnd0",},
123{{0xf2, 0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
124"f2 0f 1a 84 01 78 56 34 12 \tbndcu 0x12345678(%rcx,%rax,1),%bnd0",},
125{{0xf2, 0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
126"f2 0f 1a 84 05 78 56 34 12 \tbndcu 0x12345678(%rbp,%rax,1),%bnd0",},
127{{0xf2, 0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
128"f2 0f 1a 84 08 78 56 34 12 \tbndcu 0x12345678(%rax,%rcx,1),%bnd0",},
129{{0xf2, 0x0f, 0x1a, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
130"f2 0f 1a 84 c8 78 56 34 12 \tbndcu 0x12345678(%rax,%rcx,8),%bnd0",},
131{{0xf2, 0x0f, 0x1a, 0xc0, }, 4, 0, "", "",
132"f2 0f 1a c0 \tbndcu %rax,%bnd0",},
133{{0xf2, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
134"f2 0f 1b 00 \tbndcn (%rax),%bnd0",},
135{{0xf2, 0x41, 0x0f, 0x1b, 0x00, }, 5, 0, "", "",
136"f2 41 0f 1b 00 \tbndcn (%r8),%bnd0",},
137{{0xf2, 0x0f, 0x1b, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
138"f2 0f 1b 04 25 78 56 34 12 \tbndcn 0x12345678,%bnd0",},
139{{0xf2, 0x0f, 0x1b, 0x18, }, 4, 0, "", "",
140"f2 0f 1b 18 \tbndcn (%rax),%bnd3",},
141{{0xf2, 0x0f, 0x1b, 0x04, 0x01, }, 5, 0, "", "",
142"f2 0f 1b 04 01 \tbndcn (%rcx,%rax,1),%bnd0",},
143{{0xf2, 0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
144"f2 0f 1b 04 05 78 56 34 12 \tbndcn 0x12345678(,%rax,1),%bnd0",},
145{{0xf2, 0x0f, 0x1b, 0x04, 0x08, }, 5, 0, "", "",
146"f2 0f 1b 04 08 \tbndcn (%rax,%rcx,1),%bnd0",},
147{{0xf2, 0x0f, 0x1b, 0x04, 0xc8, }, 5, 0, "", "",
148"f2 0f 1b 04 c8 \tbndcn (%rax,%rcx,8),%bnd0",},
149{{0xf2, 0x0f, 0x1b, 0x40, 0x12, }, 5, 0, "", "",
150"f2 0f 1b 40 12 \tbndcn 0x12(%rax),%bnd0",},
151{{0xf2, 0x0f, 0x1b, 0x45, 0x12, }, 5, 0, "", "",
152"f2 0f 1b 45 12 \tbndcn 0x12(%rbp),%bnd0",},
153{{0xf2, 0x0f, 0x1b, 0x44, 0x01, 0x12, }, 6, 0, "", "",
154"f2 0f 1b 44 01 12 \tbndcn 0x12(%rcx,%rax,1),%bnd0",},
155{{0xf2, 0x0f, 0x1b, 0x44, 0x05, 0x12, }, 6, 0, "", "",
156"f2 0f 1b 44 05 12 \tbndcn 0x12(%rbp,%rax,1),%bnd0",},
157{{0xf2, 0x0f, 0x1b, 0x44, 0x08, 0x12, }, 6, 0, "", "",
158"f2 0f 1b 44 08 12 \tbndcn 0x12(%rax,%rcx,1),%bnd0",},
159{{0xf2, 0x0f, 0x1b, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
160"f2 0f 1b 44 c8 12 \tbndcn 0x12(%rax,%rcx,8),%bnd0",},
161{{0xf2, 0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
162"f2 0f 1b 80 78 56 34 12 \tbndcn 0x12345678(%rax),%bnd0",},
163{{0xf2, 0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
164"f2 0f 1b 85 78 56 34 12 \tbndcn 0x12345678(%rbp),%bnd0",},
165{{0xf2, 0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
166"f2 0f 1b 84 01 78 56 34 12 \tbndcn 0x12345678(%rcx,%rax,1),%bnd0",},
167{{0xf2, 0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
168"f2 0f 1b 84 05 78 56 34 12 \tbndcn 0x12345678(%rbp,%rax,1),%bnd0",},
169{{0xf2, 0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
170"f2 0f 1b 84 08 78 56 34 12 \tbndcn 0x12345678(%rax,%rcx,1),%bnd0",},
171{{0xf2, 0x0f, 0x1b, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
172"f2 0f 1b 84 c8 78 56 34 12 \tbndcn 0x12345678(%rax,%rcx,8),%bnd0",},
173{{0xf2, 0x0f, 0x1b, 0xc0, }, 4, 0, "", "",
174"f2 0f 1b c0 \tbndcn %rax,%bnd0",},
175{{0x66, 0x0f, 0x1a, 0x00, }, 4, 0, "", "",
176"66 0f 1a 00 \tbndmov (%rax),%bnd0",},
177{{0x66, 0x41, 0x0f, 0x1a, 0x00, }, 5, 0, "", "",
178"66 41 0f 1a 00 \tbndmov (%r8),%bnd0",},
179{{0x66, 0x0f, 0x1a, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
180"66 0f 1a 04 25 78 56 34 12 \tbndmov 0x12345678,%bnd0",},
181{{0x66, 0x0f, 0x1a, 0x18, }, 4, 0, "", "",
182"66 0f 1a 18 \tbndmov (%rax),%bnd3",},
183{{0x66, 0x0f, 0x1a, 0x04, 0x01, }, 5, 0, "", "",
184"66 0f 1a 04 01 \tbndmov (%rcx,%rax,1),%bnd0",},
185{{0x66, 0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
186"66 0f 1a 04 05 78 56 34 12 \tbndmov 0x12345678(,%rax,1),%bnd0",},
187{{0x66, 0x0f, 0x1a, 0x04, 0x08, }, 5, 0, "", "",
188"66 0f 1a 04 08 \tbndmov (%rax,%rcx,1),%bnd0",},
189{{0x66, 0x0f, 0x1a, 0x04, 0xc8, }, 5, 0, "", "",
190"66 0f 1a 04 c8 \tbndmov (%rax,%rcx,8),%bnd0",},
191{{0x66, 0x0f, 0x1a, 0x40, 0x12, }, 5, 0, "", "",
192"66 0f 1a 40 12 \tbndmov 0x12(%rax),%bnd0",},
193{{0x66, 0x0f, 0x1a, 0x45, 0x12, }, 5, 0, "", "",
194"66 0f 1a 45 12 \tbndmov 0x12(%rbp),%bnd0",},
195{{0x66, 0x0f, 0x1a, 0x44, 0x01, 0x12, }, 6, 0, "", "",
196"66 0f 1a 44 01 12 \tbndmov 0x12(%rcx,%rax,1),%bnd0",},
197{{0x66, 0x0f, 0x1a, 0x44, 0x05, 0x12, }, 6, 0, "", "",
198"66 0f 1a 44 05 12 \tbndmov 0x12(%rbp,%rax,1),%bnd0",},
199{{0x66, 0x0f, 0x1a, 0x44, 0x08, 0x12, }, 6, 0, "", "",
200"66 0f 1a 44 08 12 \tbndmov 0x12(%rax,%rcx,1),%bnd0",},
201{{0x66, 0x0f, 0x1a, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
202"66 0f 1a 44 c8 12 \tbndmov 0x12(%rax,%rcx,8),%bnd0",},
203{{0x66, 0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
204"66 0f 1a 80 78 56 34 12 \tbndmov 0x12345678(%rax),%bnd0",},
205{{0x66, 0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
206"66 0f 1a 85 78 56 34 12 \tbndmov 0x12345678(%rbp),%bnd0",},
207{{0x66, 0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
208"66 0f 1a 84 01 78 56 34 12 \tbndmov 0x12345678(%rcx,%rax,1),%bnd0",},
209{{0x66, 0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
210"66 0f 1a 84 05 78 56 34 12 \tbndmov 0x12345678(%rbp,%rax,1),%bnd0",},
211{{0x66, 0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
212"66 0f 1a 84 08 78 56 34 12 \tbndmov 0x12345678(%rax,%rcx,1),%bnd0",},
213{{0x66, 0x0f, 0x1a, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
214"66 0f 1a 84 c8 78 56 34 12 \tbndmov 0x12345678(%rax,%rcx,8),%bnd0",},
215{{0x66, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
216"66 0f 1b 00 \tbndmov %bnd0,(%rax)",},
217{{0x66, 0x41, 0x0f, 0x1b, 0x00, }, 5, 0, "", "",
218"66 41 0f 1b 00 \tbndmov %bnd0,(%r8)",},
219{{0x66, 0x0f, 0x1b, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
220"66 0f 1b 04 25 78 56 34 12 \tbndmov %bnd0,0x12345678",},
221{{0x66, 0x0f, 0x1b, 0x18, }, 4, 0, "", "",
222"66 0f 1b 18 \tbndmov %bnd3,(%rax)",},
223{{0x66, 0x0f, 0x1b, 0x04, 0x01, }, 5, 0, "", "",
224"66 0f 1b 04 01 \tbndmov %bnd0,(%rcx,%rax,1)",},
225{{0x66, 0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
226"66 0f 1b 04 05 78 56 34 12 \tbndmov %bnd0,0x12345678(,%rax,1)",},
227{{0x66, 0x0f, 0x1b, 0x04, 0x08, }, 5, 0, "", "",
228"66 0f 1b 04 08 \tbndmov %bnd0,(%rax,%rcx,1)",},
229{{0x66, 0x0f, 0x1b, 0x04, 0xc8, }, 5, 0, "", "",
230"66 0f 1b 04 c8 \tbndmov %bnd0,(%rax,%rcx,8)",},
231{{0x66, 0x0f, 0x1b, 0x40, 0x12, }, 5, 0, "", "",
232"66 0f 1b 40 12 \tbndmov %bnd0,0x12(%rax)",},
233{{0x66, 0x0f, 0x1b, 0x45, 0x12, }, 5, 0, "", "",
234"66 0f 1b 45 12 \tbndmov %bnd0,0x12(%rbp)",},
235{{0x66, 0x0f, 0x1b, 0x44, 0x01, 0x12, }, 6, 0, "", "",
236"66 0f 1b 44 01 12 \tbndmov %bnd0,0x12(%rcx,%rax,1)",},
237{{0x66, 0x0f, 0x1b, 0x44, 0x05, 0x12, }, 6, 0, "", "",
238"66 0f 1b 44 05 12 \tbndmov %bnd0,0x12(%rbp,%rax,1)",},
239{{0x66, 0x0f, 0x1b, 0x44, 0x08, 0x12, }, 6, 0, "", "",
240"66 0f 1b 44 08 12 \tbndmov %bnd0,0x12(%rax,%rcx,1)",},
241{{0x66, 0x0f, 0x1b, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
242"66 0f 1b 44 c8 12 \tbndmov %bnd0,0x12(%rax,%rcx,8)",},
243{{0x66, 0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
244"66 0f 1b 80 78 56 34 12 \tbndmov %bnd0,0x12345678(%rax)",},
245{{0x66, 0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
246"66 0f 1b 85 78 56 34 12 \tbndmov %bnd0,0x12345678(%rbp)",},
247{{0x66, 0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
248"66 0f 1b 84 01 78 56 34 12 \tbndmov %bnd0,0x12345678(%rcx,%rax,1)",},
249{{0x66, 0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
250"66 0f 1b 84 05 78 56 34 12 \tbndmov %bnd0,0x12345678(%rbp,%rax,1)",},
251{{0x66, 0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
252"66 0f 1b 84 08 78 56 34 12 \tbndmov %bnd0,0x12345678(%rax,%rcx,1)",},
253{{0x66, 0x0f, 0x1b, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
254"66 0f 1b 84 c8 78 56 34 12 \tbndmov %bnd0,0x12345678(%rax,%rcx,8)",},
255{{0x66, 0x0f, 0x1a, 0xc8, }, 4, 0, "", "",
256"66 0f 1a c8 \tbndmov %bnd0,%bnd1",},
257{{0x66, 0x0f, 0x1a, 0xc1, }, 4, 0, "", "",
258"66 0f 1a c1 \tbndmov %bnd1,%bnd0",},
259{{0x0f, 0x1a, 0x00, }, 3, 0, "", "",
260"0f 1a 00 \tbndldx (%rax),%bnd0",},
261{{0x41, 0x0f, 0x1a, 0x00, }, 4, 0, "", "",
262"41 0f 1a 00 \tbndldx (%r8),%bnd0",},
263{{0x0f, 0x1a, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
264"0f 1a 04 25 78 56 34 12 \tbndldx 0x12345678,%bnd0",},
265{{0x0f, 0x1a, 0x18, }, 3, 0, "", "",
266"0f 1a 18 \tbndldx (%rax),%bnd3",},
267{{0x0f, 0x1a, 0x04, 0x01, }, 4, 0, "", "",
268"0f 1a 04 01 \tbndldx (%rcx,%rax,1),%bnd0",},
269{{0x0f, 0x1a, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
270"0f 1a 04 05 78 56 34 12 \tbndldx 0x12345678(,%rax,1),%bnd0",},
271{{0x0f, 0x1a, 0x04, 0x08, }, 4, 0, "", "",
272"0f 1a 04 08 \tbndldx (%rax,%rcx,1),%bnd0",},
273{{0x0f, 0x1a, 0x40, 0x12, }, 4, 0, "", "",
274"0f 1a 40 12 \tbndldx 0x12(%rax),%bnd0",},
275{{0x0f, 0x1a, 0x45, 0x12, }, 4, 0, "", "",
276"0f 1a 45 12 \tbndldx 0x12(%rbp),%bnd0",},
277{{0x0f, 0x1a, 0x44, 0x01, 0x12, }, 5, 0, "", "",
278"0f 1a 44 01 12 \tbndldx 0x12(%rcx,%rax,1),%bnd0",},
279{{0x0f, 0x1a, 0x44, 0x05, 0x12, }, 5, 0, "", "",
280"0f 1a 44 05 12 \tbndldx 0x12(%rbp,%rax,1),%bnd0",},
281{{0x0f, 0x1a, 0x44, 0x08, 0x12, }, 5, 0, "", "",
282"0f 1a 44 08 12 \tbndldx 0x12(%rax,%rcx,1),%bnd0",},
283{{0x0f, 0x1a, 0x80, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
284"0f 1a 80 78 56 34 12 \tbndldx 0x12345678(%rax),%bnd0",},
285{{0x0f, 0x1a, 0x85, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
286"0f 1a 85 78 56 34 12 \tbndldx 0x12345678(%rbp),%bnd0",},
287{{0x0f, 0x1a, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
288"0f 1a 84 01 78 56 34 12 \tbndldx 0x12345678(%rcx,%rax,1),%bnd0",},
289{{0x0f, 0x1a, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
290"0f 1a 84 05 78 56 34 12 \tbndldx 0x12345678(%rbp,%rax,1),%bnd0",},
291{{0x0f, 0x1a, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
292"0f 1a 84 08 78 56 34 12 \tbndldx 0x12345678(%rax,%rcx,1),%bnd0",},
293{{0x0f, 0x1b, 0x00, }, 3, 0, "", "",
294"0f 1b 00 \tbndstx %bnd0,(%rax)",},
295{{0x41, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
296"41 0f 1b 00 \tbndstx %bnd0,(%r8)",},
297{{0x0f, 0x1b, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
298"0f 1b 04 25 78 56 34 12 \tbndstx %bnd0,0x12345678",},
299{{0x0f, 0x1b, 0x18, }, 3, 0, "", "",
300"0f 1b 18 \tbndstx %bnd3,(%rax)",},
301{{0x0f, 0x1b, 0x04, 0x01, }, 4, 0, "", "",
302"0f 1b 04 01 \tbndstx %bnd0,(%rcx,%rax,1)",},
303{{0x0f, 0x1b, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
304"0f 1b 04 05 78 56 34 12 \tbndstx %bnd0,0x12345678(,%rax,1)",},
305{{0x0f, 0x1b, 0x04, 0x08, }, 4, 0, "", "",
306"0f 1b 04 08 \tbndstx %bnd0,(%rax,%rcx,1)",},
307{{0x0f, 0x1b, 0x40, 0x12, }, 4, 0, "", "",
308"0f 1b 40 12 \tbndstx %bnd0,0x12(%rax)",},
309{{0x0f, 0x1b, 0x45, 0x12, }, 4, 0, "", "",
310"0f 1b 45 12 \tbndstx %bnd0,0x12(%rbp)",},
311{{0x0f, 0x1b, 0x44, 0x01, 0x12, }, 5, 0, "", "",
312"0f 1b 44 01 12 \tbndstx %bnd0,0x12(%rcx,%rax,1)",},
313{{0x0f, 0x1b, 0x44, 0x05, 0x12, }, 5, 0, "", "",
314"0f 1b 44 05 12 \tbndstx %bnd0,0x12(%rbp,%rax,1)",},
315{{0x0f, 0x1b, 0x44, 0x08, 0x12, }, 5, 0, "", "",
316"0f 1b 44 08 12 \tbndstx %bnd0,0x12(%rax,%rcx,1)",},
317{{0x0f, 0x1b, 0x80, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
318"0f 1b 80 78 56 34 12 \tbndstx %bnd0,0x12345678(%rax)",},
319{{0x0f, 0x1b, 0x85, 0x78, 0x56, 0x34, 0x12, }, 7, 0, "", "",
320"0f 1b 85 78 56 34 12 \tbndstx %bnd0,0x12345678(%rbp)",},
321{{0x0f, 0x1b, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
322"0f 1b 84 01 78 56 34 12 \tbndstx %bnd0,0x12345678(%rcx,%rax,1)",},
323{{0x0f, 0x1b, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
324"0f 1b 84 05 78 56 34 12 \tbndstx %bnd0,0x12345678(%rbp,%rax,1)",},
325{{0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
326"0f 1b 84 08 78 56 34 12 \tbndstx %bnd0,0x12345678(%rax,%rcx,1)",},
327{{0xf2, 0xe8, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "call", "unconditional",
328"f2 e8 00 00 00 00 \tbnd callq 3f6 <main+0x3f6>",},
329{{0x67, 0xf2, 0xff, 0x10, }, 4, 0, "call", "indirect",
330"67 f2 ff 10 \tbnd callq *(%eax)",},
331{{0xf2, 0xc3, }, 2, 0, "ret", "indirect",
332"f2 c3 \tbnd retq ",},
333{{0xf2, 0xe9, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "jmp", "unconditional",
334"f2 e9 00 00 00 00 \tbnd jmpq 402 <main+0x402>",},
335{{0xf2, 0xe9, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "jmp", "unconditional",
336"f2 e9 00 00 00 00 \tbnd jmpq 408 <main+0x408>",},
337{{0x67, 0xf2, 0xff, 0x21, }, 4, 0, "jmp", "indirect",
338"67 f2 ff 21 \tbnd jmpq *(%ecx)",},
339{{0xf2, 0x0f, 0x85, 0x00, 0x00, 0x00, 0x00, }, 7, 0, "jcc", "conditional",
340"f2 0f 85 00 00 00 00 \tbnd jne 413 <main+0x413>",},
341{{0x0f, 0x3a, 0xcc, 0xc1, 0x00, }, 5, 0, "", "",
342"0f 3a cc c1 00 \tsha1rnds4 $0x0,%xmm1,%xmm0",},
343{{0x0f, 0x3a, 0xcc, 0xd7, 0x91, }, 5, 0, "", "",
344"0f 3a cc d7 91 \tsha1rnds4 $0x91,%xmm7,%xmm2",},
345{{0x41, 0x0f, 0x3a, 0xcc, 0xc0, 0x91, }, 6, 0, "", "",
346"41 0f 3a cc c0 91 \tsha1rnds4 $0x91,%xmm8,%xmm0",},
347{{0x44, 0x0f, 0x3a, 0xcc, 0xc7, 0x91, }, 6, 0, "", "",
348"44 0f 3a cc c7 91 \tsha1rnds4 $0x91,%xmm7,%xmm8",},
349{{0x45, 0x0f, 0x3a, 0xcc, 0xc7, 0x91, }, 6, 0, "", "",
350"45 0f 3a cc c7 91 \tsha1rnds4 $0x91,%xmm15,%xmm8",},
351{{0x0f, 0x3a, 0xcc, 0x00, 0x91, }, 5, 0, "", "",
352"0f 3a cc 00 91 \tsha1rnds4 $0x91,(%rax),%xmm0",},
353{{0x41, 0x0f, 0x3a, 0xcc, 0x00, 0x91, }, 6, 0, "", "",
354"41 0f 3a cc 00 91 \tsha1rnds4 $0x91,(%r8),%xmm0",},
355{{0x0f, 0x3a, 0xcc, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
356"0f 3a cc 04 25 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678,%xmm0",},
357{{0x0f, 0x3a, 0xcc, 0x18, 0x91, }, 5, 0, "", "",
358"0f 3a cc 18 91 \tsha1rnds4 $0x91,(%rax),%xmm3",},
359{{0x0f, 0x3a, 0xcc, 0x04, 0x01, 0x91, }, 6, 0, "", "",
360"0f 3a cc 04 01 91 \tsha1rnds4 $0x91,(%rcx,%rax,1),%xmm0",},
361{{0x0f, 0x3a, 0xcc, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
362"0f 3a cc 04 05 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(,%rax,1),%xmm0",},
363{{0x0f, 0x3a, 0xcc, 0x04, 0x08, 0x91, }, 6, 0, "", "",
364"0f 3a cc 04 08 91 \tsha1rnds4 $0x91,(%rax,%rcx,1),%xmm0",},
365{{0x0f, 0x3a, 0xcc, 0x04, 0xc8, 0x91, }, 6, 0, "", "",
366"0f 3a cc 04 c8 91 \tsha1rnds4 $0x91,(%rax,%rcx,8),%xmm0",},
367{{0x0f, 0x3a, 0xcc, 0x40, 0x12, 0x91, }, 6, 0, "", "",
368"0f 3a cc 40 12 91 \tsha1rnds4 $0x91,0x12(%rax),%xmm0",},
369{{0x0f, 0x3a, 0xcc, 0x45, 0x12, 0x91, }, 6, 0, "", "",
370"0f 3a cc 45 12 91 \tsha1rnds4 $0x91,0x12(%rbp),%xmm0",},
371{{0x0f, 0x3a, 0xcc, 0x44, 0x01, 0x12, 0x91, }, 7, 0, "", "",
372"0f 3a cc 44 01 12 91 \tsha1rnds4 $0x91,0x12(%rcx,%rax,1),%xmm0",},
373{{0x0f, 0x3a, 0xcc, 0x44, 0x05, 0x12, 0x91, }, 7, 0, "", "",
374"0f 3a cc 44 05 12 91 \tsha1rnds4 $0x91,0x12(%rbp,%rax,1),%xmm0",},
375{{0x0f, 0x3a, 0xcc, 0x44, 0x08, 0x12, 0x91, }, 7, 0, "", "",
376"0f 3a cc 44 08 12 91 \tsha1rnds4 $0x91,0x12(%rax,%rcx,1),%xmm0",},
377{{0x0f, 0x3a, 0xcc, 0x44, 0xc8, 0x12, 0x91, }, 7, 0, "", "",
378"0f 3a cc 44 c8 12 91 \tsha1rnds4 $0x91,0x12(%rax,%rcx,8),%xmm0",},
379{{0x0f, 0x3a, 0xcc, 0x80, 0x78, 0x56, 0x34, 0x12, 0x91, }, 9, 0, "", "",
380"0f 3a cc 80 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%rax),%xmm0",},
381{{0x0f, 0x3a, 0xcc, 0x85, 0x78, 0x56, 0x34, 0x12, 0x91, }, 9, 0, "", "",
382"0f 3a cc 85 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%rbp),%xmm0",},
383{{0x0f, 0x3a, 0xcc, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
384"0f 3a cc 84 01 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%rcx,%rax,1),%xmm0",},
385{{0x0f, 0x3a, 0xcc, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
386"0f 3a cc 84 05 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%rbp,%rax,1),%xmm0",},
387{{0x0f, 0x3a, 0xcc, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
388"0f 3a cc 84 08 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%rax,%rcx,1),%xmm0",},
389{{0x0f, 0x3a, 0xcc, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, 0x91, }, 10, 0, "", "",
390"0f 3a cc 84 c8 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%rax,%rcx,8),%xmm0",},
391{{0x44, 0x0f, 0x3a, 0xcc, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, 0x91, }, 11, 0, "", "",
392"44 0f 3a cc bc c8 78 56 34 12 91 \tsha1rnds4 $0x91,0x12345678(%rax,%rcx,8),%xmm15",},
393{{0x0f, 0x38, 0xc8, 0xc1, }, 4, 0, "", "",
394"0f 38 c8 c1 \tsha1nexte %xmm1,%xmm0",},
395{{0x0f, 0x38, 0xc8, 0xd7, }, 4, 0, "", "",
396"0f 38 c8 d7 \tsha1nexte %xmm7,%xmm2",},
397{{0x41, 0x0f, 0x38, 0xc8, 0xc0, }, 5, 0, "", "",
398"41 0f 38 c8 c0 \tsha1nexte %xmm8,%xmm0",},
399{{0x44, 0x0f, 0x38, 0xc8, 0xc7, }, 5, 0, "", "",
400"44 0f 38 c8 c7 \tsha1nexte %xmm7,%xmm8",},
401{{0x45, 0x0f, 0x38, 0xc8, 0xc7, }, 5, 0, "", "",
402"45 0f 38 c8 c7 \tsha1nexte %xmm15,%xmm8",},
403{{0x0f, 0x38, 0xc8, 0x00, }, 4, 0, "", "",
404"0f 38 c8 00 \tsha1nexte (%rax),%xmm0",},
405{{0x41, 0x0f, 0x38, 0xc8, 0x00, }, 5, 0, "", "",
406"41 0f 38 c8 00 \tsha1nexte (%r8),%xmm0",},
407{{0x0f, 0x38, 0xc8, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
408"0f 38 c8 04 25 78 56 34 12 \tsha1nexte 0x12345678,%xmm0",},
409{{0x0f, 0x38, 0xc8, 0x18, }, 4, 0, "", "",
410"0f 38 c8 18 \tsha1nexte (%rax),%xmm3",},
411{{0x0f, 0x38, 0xc8, 0x04, 0x01, }, 5, 0, "", "",
412"0f 38 c8 04 01 \tsha1nexte (%rcx,%rax,1),%xmm0",},
413{{0x0f, 0x38, 0xc8, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
414"0f 38 c8 04 05 78 56 34 12 \tsha1nexte 0x12345678(,%rax,1),%xmm0",},
415{{0x0f, 0x38, 0xc8, 0x04, 0x08, }, 5, 0, "", "",
416"0f 38 c8 04 08 \tsha1nexte (%rax,%rcx,1),%xmm0",},
417{{0x0f, 0x38, 0xc8, 0x04, 0xc8, }, 5, 0, "", "",
418"0f 38 c8 04 c8 \tsha1nexte (%rax,%rcx,8),%xmm0",},
419{{0x0f, 0x38, 0xc8, 0x40, 0x12, }, 5, 0, "", "",
420"0f 38 c8 40 12 \tsha1nexte 0x12(%rax),%xmm0",},
421{{0x0f, 0x38, 0xc8, 0x45, 0x12, }, 5, 0, "", "",
422"0f 38 c8 45 12 \tsha1nexte 0x12(%rbp),%xmm0",},
423{{0x0f, 0x38, 0xc8, 0x44, 0x01, 0x12, }, 6, 0, "", "",
424"0f 38 c8 44 01 12 \tsha1nexte 0x12(%rcx,%rax,1),%xmm0",},
425{{0x0f, 0x38, 0xc8, 0x44, 0x05, 0x12, }, 6, 0, "", "",
426"0f 38 c8 44 05 12 \tsha1nexte 0x12(%rbp,%rax,1),%xmm0",},
427{{0x0f, 0x38, 0xc8, 0x44, 0x08, 0x12, }, 6, 0, "", "",
428"0f 38 c8 44 08 12 \tsha1nexte 0x12(%rax,%rcx,1),%xmm0",},
429{{0x0f, 0x38, 0xc8, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
430"0f 38 c8 44 c8 12 \tsha1nexte 0x12(%rax,%rcx,8),%xmm0",},
431{{0x0f, 0x38, 0xc8, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
432"0f 38 c8 80 78 56 34 12 \tsha1nexte 0x12345678(%rax),%xmm0",},
433{{0x0f, 0x38, 0xc8, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
434"0f 38 c8 85 78 56 34 12 \tsha1nexte 0x12345678(%rbp),%xmm0",},
435{{0x0f, 0x38, 0xc8, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
436"0f 38 c8 84 01 78 56 34 12 \tsha1nexte 0x12345678(%rcx,%rax,1),%xmm0",},
437{{0x0f, 0x38, 0xc8, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
438"0f 38 c8 84 05 78 56 34 12 \tsha1nexte 0x12345678(%rbp,%rax,1),%xmm0",},
439{{0x0f, 0x38, 0xc8, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
440"0f 38 c8 84 08 78 56 34 12 \tsha1nexte 0x12345678(%rax,%rcx,1),%xmm0",},
441{{0x0f, 0x38, 0xc8, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
442"0f 38 c8 84 c8 78 56 34 12 \tsha1nexte 0x12345678(%rax,%rcx,8),%xmm0",},
443{{0x44, 0x0f, 0x38, 0xc8, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
444"44 0f 38 c8 bc c8 78 56 34 12 \tsha1nexte 0x12345678(%rax,%rcx,8),%xmm15",},
445{{0x0f, 0x38, 0xc9, 0xc1, }, 4, 0, "", "",
446"0f 38 c9 c1 \tsha1msg1 %xmm1,%xmm0",},
447{{0x0f, 0x38, 0xc9, 0xd7, }, 4, 0, "", "",
448"0f 38 c9 d7 \tsha1msg1 %xmm7,%xmm2",},
449{{0x41, 0x0f, 0x38, 0xc9, 0xc0, }, 5, 0, "", "",
450"41 0f 38 c9 c0 \tsha1msg1 %xmm8,%xmm0",},
451{{0x44, 0x0f, 0x38, 0xc9, 0xc7, }, 5, 0, "", "",
452"44 0f 38 c9 c7 \tsha1msg1 %xmm7,%xmm8",},
453{{0x45, 0x0f, 0x38, 0xc9, 0xc7, }, 5, 0, "", "",
454"45 0f 38 c9 c7 \tsha1msg1 %xmm15,%xmm8",},
455{{0x0f, 0x38, 0xc9, 0x00, }, 4, 0, "", "",
456"0f 38 c9 00 \tsha1msg1 (%rax),%xmm0",},
457{{0x41, 0x0f, 0x38, 0xc9, 0x00, }, 5, 0, "", "",
458"41 0f 38 c9 00 \tsha1msg1 (%r8),%xmm0",},
459{{0x0f, 0x38, 0xc9, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
460"0f 38 c9 04 25 78 56 34 12 \tsha1msg1 0x12345678,%xmm0",},
461{{0x0f, 0x38, 0xc9, 0x18, }, 4, 0, "", "",
462"0f 38 c9 18 \tsha1msg1 (%rax),%xmm3",},
463{{0x0f, 0x38, 0xc9, 0x04, 0x01, }, 5, 0, "", "",
464"0f 38 c9 04 01 \tsha1msg1 (%rcx,%rax,1),%xmm0",},
465{{0x0f, 0x38, 0xc9, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
466"0f 38 c9 04 05 78 56 34 12 \tsha1msg1 0x12345678(,%rax,1),%xmm0",},
467{{0x0f, 0x38, 0xc9, 0x04, 0x08, }, 5, 0, "", "",
468"0f 38 c9 04 08 \tsha1msg1 (%rax,%rcx,1),%xmm0",},
469{{0x0f, 0x38, 0xc9, 0x04, 0xc8, }, 5, 0, "", "",
470"0f 38 c9 04 c8 \tsha1msg1 (%rax,%rcx,8),%xmm0",},
471{{0x0f, 0x38, 0xc9, 0x40, 0x12, }, 5, 0, "", "",
472"0f 38 c9 40 12 \tsha1msg1 0x12(%rax),%xmm0",},
473{{0x0f, 0x38, 0xc9, 0x45, 0x12, }, 5, 0, "", "",
474"0f 38 c9 45 12 \tsha1msg1 0x12(%rbp),%xmm0",},
475{{0x0f, 0x38, 0xc9, 0x44, 0x01, 0x12, }, 6, 0, "", "",
476"0f 38 c9 44 01 12 \tsha1msg1 0x12(%rcx,%rax,1),%xmm0",},
477{{0x0f, 0x38, 0xc9, 0x44, 0x05, 0x12, }, 6, 0, "", "",
478"0f 38 c9 44 05 12 \tsha1msg1 0x12(%rbp,%rax,1),%xmm0",},
479{{0x0f, 0x38, 0xc9, 0x44, 0x08, 0x12, }, 6, 0, "", "",
480"0f 38 c9 44 08 12 \tsha1msg1 0x12(%rax,%rcx,1),%xmm0",},
481{{0x0f, 0x38, 0xc9, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
482"0f 38 c9 44 c8 12 \tsha1msg1 0x12(%rax,%rcx,8),%xmm0",},
483{{0x0f, 0x38, 0xc9, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
484"0f 38 c9 80 78 56 34 12 \tsha1msg1 0x12345678(%rax),%xmm0",},
485{{0x0f, 0x38, 0xc9, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
486"0f 38 c9 85 78 56 34 12 \tsha1msg1 0x12345678(%rbp),%xmm0",},
487{{0x0f, 0x38, 0xc9, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
488"0f 38 c9 84 01 78 56 34 12 \tsha1msg1 0x12345678(%rcx,%rax,1),%xmm0",},
489{{0x0f, 0x38, 0xc9, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
490"0f 38 c9 84 05 78 56 34 12 \tsha1msg1 0x12345678(%rbp,%rax,1),%xmm0",},
491{{0x0f, 0x38, 0xc9, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
492"0f 38 c9 84 08 78 56 34 12 \tsha1msg1 0x12345678(%rax,%rcx,1),%xmm0",},
493{{0x0f, 0x38, 0xc9, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
494"0f 38 c9 84 c8 78 56 34 12 \tsha1msg1 0x12345678(%rax,%rcx,8),%xmm0",},
495{{0x44, 0x0f, 0x38, 0xc9, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
496"44 0f 38 c9 bc c8 78 56 34 12 \tsha1msg1 0x12345678(%rax,%rcx,8),%xmm15",},
497{{0x0f, 0x38, 0xca, 0xc1, }, 4, 0, "", "",
498"0f 38 ca c1 \tsha1msg2 %xmm1,%xmm0",},
499{{0x0f, 0x38, 0xca, 0xd7, }, 4, 0, "", "",
500"0f 38 ca d7 \tsha1msg2 %xmm7,%xmm2",},
501{{0x41, 0x0f, 0x38, 0xca, 0xc0, }, 5, 0, "", "",
502"41 0f 38 ca c0 \tsha1msg2 %xmm8,%xmm0",},
503{{0x44, 0x0f, 0x38, 0xca, 0xc7, }, 5, 0, "", "",
504"44 0f 38 ca c7 \tsha1msg2 %xmm7,%xmm8",},
505{{0x45, 0x0f, 0x38, 0xca, 0xc7, }, 5, 0, "", "",
506"45 0f 38 ca c7 \tsha1msg2 %xmm15,%xmm8",},
507{{0x0f, 0x38, 0xca, 0x00, }, 4, 0, "", "",
508"0f 38 ca 00 \tsha1msg2 (%rax),%xmm0",},
509{{0x41, 0x0f, 0x38, 0xca, 0x00, }, 5, 0, "", "",
510"41 0f 38 ca 00 \tsha1msg2 (%r8),%xmm0",},
511{{0x0f, 0x38, 0xca, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
512"0f 38 ca 04 25 78 56 34 12 \tsha1msg2 0x12345678,%xmm0",},
513{{0x0f, 0x38, 0xca, 0x18, }, 4, 0, "", "",
514"0f 38 ca 18 \tsha1msg2 (%rax),%xmm3",},
515{{0x0f, 0x38, 0xca, 0x04, 0x01, }, 5, 0, "", "",
516"0f 38 ca 04 01 \tsha1msg2 (%rcx,%rax,1),%xmm0",},
517{{0x0f, 0x38, 0xca, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
518"0f 38 ca 04 05 78 56 34 12 \tsha1msg2 0x12345678(,%rax,1),%xmm0",},
519{{0x0f, 0x38, 0xca, 0x04, 0x08, }, 5, 0, "", "",
520"0f 38 ca 04 08 \tsha1msg2 (%rax,%rcx,1),%xmm0",},
521{{0x0f, 0x38, 0xca, 0x04, 0xc8, }, 5, 0, "", "",
522"0f 38 ca 04 c8 \tsha1msg2 (%rax,%rcx,8),%xmm0",},
523{{0x0f, 0x38, 0xca, 0x40, 0x12, }, 5, 0, "", "",
524"0f 38 ca 40 12 \tsha1msg2 0x12(%rax),%xmm0",},
525{{0x0f, 0x38, 0xca, 0x45, 0x12, }, 5, 0, "", "",
526"0f 38 ca 45 12 \tsha1msg2 0x12(%rbp),%xmm0",},
527{{0x0f, 0x38, 0xca, 0x44, 0x01, 0x12, }, 6, 0, "", "",
528"0f 38 ca 44 01 12 \tsha1msg2 0x12(%rcx,%rax,1),%xmm0",},
529{{0x0f, 0x38, 0xca, 0x44, 0x05, 0x12, }, 6, 0, "", "",
530"0f 38 ca 44 05 12 \tsha1msg2 0x12(%rbp,%rax,1),%xmm0",},
531{{0x0f, 0x38, 0xca, 0x44, 0x08, 0x12, }, 6, 0, "", "",
532"0f 38 ca 44 08 12 \tsha1msg2 0x12(%rax,%rcx,1),%xmm0",},
533{{0x0f, 0x38, 0xca, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
534"0f 38 ca 44 c8 12 \tsha1msg2 0x12(%rax,%rcx,8),%xmm0",},
535{{0x0f, 0x38, 0xca, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
536"0f 38 ca 80 78 56 34 12 \tsha1msg2 0x12345678(%rax),%xmm0",},
537{{0x0f, 0x38, 0xca, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
538"0f 38 ca 85 78 56 34 12 \tsha1msg2 0x12345678(%rbp),%xmm0",},
539{{0x0f, 0x38, 0xca, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
540"0f 38 ca 84 01 78 56 34 12 \tsha1msg2 0x12345678(%rcx,%rax,1),%xmm0",},
541{{0x0f, 0x38, 0xca, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
542"0f 38 ca 84 05 78 56 34 12 \tsha1msg2 0x12345678(%rbp,%rax,1),%xmm0",},
543{{0x0f, 0x38, 0xca, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
544"0f 38 ca 84 08 78 56 34 12 \tsha1msg2 0x12345678(%rax,%rcx,1),%xmm0",},
545{{0x0f, 0x38, 0xca, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
546"0f 38 ca 84 c8 78 56 34 12 \tsha1msg2 0x12345678(%rax,%rcx,8),%xmm0",},
547{{0x44, 0x0f, 0x38, 0xca, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
548"44 0f 38 ca bc c8 78 56 34 12 \tsha1msg2 0x12345678(%rax,%rcx,8),%xmm15",},
549{{0x0f, 0x38, 0xcb, 0xcc, }, 4, 0, "", "",
550"0f 38 cb cc \tsha256rnds2 %xmm0,%xmm4,%xmm1",},
551{{0x0f, 0x38, 0xcb, 0xd7, }, 4, 0, "", "",
552"0f 38 cb d7 \tsha256rnds2 %xmm0,%xmm7,%xmm2",},
553{{0x41, 0x0f, 0x38, 0xcb, 0xc8, }, 5, 0, "", "",
554"41 0f 38 cb c8 \tsha256rnds2 %xmm0,%xmm8,%xmm1",},
555{{0x44, 0x0f, 0x38, 0xcb, 0xc7, }, 5, 0, "", "",
556"44 0f 38 cb c7 \tsha256rnds2 %xmm0,%xmm7,%xmm8",},
557{{0x45, 0x0f, 0x38, 0xcb, 0xc7, }, 5, 0, "", "",
558"45 0f 38 cb c7 \tsha256rnds2 %xmm0,%xmm15,%xmm8",},
559{{0x0f, 0x38, 0xcb, 0x08, }, 4, 0, "", "",
560"0f 38 cb 08 \tsha256rnds2 %xmm0,(%rax),%xmm1",},
561{{0x41, 0x0f, 0x38, 0xcb, 0x08, }, 5, 0, "", "",
562"41 0f 38 cb 08 \tsha256rnds2 %xmm0,(%r8),%xmm1",},
563{{0x0f, 0x38, 0xcb, 0x0c, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
564"0f 38 cb 0c 25 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678,%xmm1",},
565{{0x0f, 0x38, 0xcb, 0x18, }, 4, 0, "", "",
566"0f 38 cb 18 \tsha256rnds2 %xmm0,(%rax),%xmm3",},
567{{0x0f, 0x38, 0xcb, 0x0c, 0x01, }, 5, 0, "", "",
568"0f 38 cb 0c 01 \tsha256rnds2 %xmm0,(%rcx,%rax,1),%xmm1",},
569{{0x0f, 0x38, 0xcb, 0x0c, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
570"0f 38 cb 0c 05 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(,%rax,1),%xmm1",},
571{{0x0f, 0x38, 0xcb, 0x0c, 0x08, }, 5, 0, "", "",
572"0f 38 cb 0c 08 \tsha256rnds2 %xmm0,(%rax,%rcx,1),%xmm1",},
573{{0x0f, 0x38, 0xcb, 0x0c, 0xc8, }, 5, 0, "", "",
574"0f 38 cb 0c c8 \tsha256rnds2 %xmm0,(%rax,%rcx,8),%xmm1",},
575{{0x0f, 0x38, 0xcb, 0x48, 0x12, }, 5, 0, "", "",
576"0f 38 cb 48 12 \tsha256rnds2 %xmm0,0x12(%rax),%xmm1",},
577{{0x0f, 0x38, 0xcb, 0x4d, 0x12, }, 5, 0, "", "",
578"0f 38 cb 4d 12 \tsha256rnds2 %xmm0,0x12(%rbp),%xmm1",},
579{{0x0f, 0x38, 0xcb, 0x4c, 0x01, 0x12, }, 6, 0, "", "",
580"0f 38 cb 4c 01 12 \tsha256rnds2 %xmm0,0x12(%rcx,%rax,1),%xmm1",},
581{{0x0f, 0x38, 0xcb, 0x4c, 0x05, 0x12, }, 6, 0, "", "",
582"0f 38 cb 4c 05 12 \tsha256rnds2 %xmm0,0x12(%rbp,%rax,1),%xmm1",},
583{{0x0f, 0x38, 0xcb, 0x4c, 0x08, 0x12, }, 6, 0, "", "",
584"0f 38 cb 4c 08 12 \tsha256rnds2 %xmm0,0x12(%rax,%rcx,1),%xmm1",},
585{{0x0f, 0x38, 0xcb, 0x4c, 0xc8, 0x12, }, 6, 0, "", "",
586"0f 38 cb 4c c8 12 \tsha256rnds2 %xmm0,0x12(%rax,%rcx,8),%xmm1",},
587{{0x0f, 0x38, 0xcb, 0x88, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
588"0f 38 cb 88 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%rax),%xmm1",},
589{{0x0f, 0x38, 0xcb, 0x8d, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
590"0f 38 cb 8d 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%rbp),%xmm1",},
591{{0x0f, 0x38, 0xcb, 0x8c, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
592"0f 38 cb 8c 01 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%rcx,%rax,1),%xmm1",},
593{{0x0f, 0x38, 0xcb, 0x8c, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
594"0f 38 cb 8c 05 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%rbp,%rax,1),%xmm1",},
595{{0x0f, 0x38, 0xcb, 0x8c, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
596"0f 38 cb 8c 08 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%rax,%rcx,1),%xmm1",},
597{{0x0f, 0x38, 0xcb, 0x8c, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
598"0f 38 cb 8c c8 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%rax,%rcx,8),%xmm1",},
599{{0x44, 0x0f, 0x38, 0xcb, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
600"44 0f 38 cb bc c8 78 56 34 12 \tsha256rnds2 %xmm0,0x12345678(%rax,%rcx,8),%xmm15",},
601{{0x0f, 0x38, 0xcc, 0xc1, }, 4, 0, "", "",
602"0f 38 cc c1 \tsha256msg1 %xmm1,%xmm0",},
603{{0x0f, 0x38, 0xcc, 0xd7, }, 4, 0, "", "",
604"0f 38 cc d7 \tsha256msg1 %xmm7,%xmm2",},
605{{0x41, 0x0f, 0x38, 0xcc, 0xc0, }, 5, 0, "", "",
606"41 0f 38 cc c0 \tsha256msg1 %xmm8,%xmm0",},
607{{0x44, 0x0f, 0x38, 0xcc, 0xc7, }, 5, 0, "", "",
608"44 0f 38 cc c7 \tsha256msg1 %xmm7,%xmm8",},
609{{0x45, 0x0f, 0x38, 0xcc, 0xc7, }, 5, 0, "", "",
610"45 0f 38 cc c7 \tsha256msg1 %xmm15,%xmm8",},
611{{0x0f, 0x38, 0xcc, 0x00, }, 4, 0, "", "",
612"0f 38 cc 00 \tsha256msg1 (%rax),%xmm0",},
613{{0x41, 0x0f, 0x38, 0xcc, 0x00, }, 5, 0, "", "",
614"41 0f 38 cc 00 \tsha256msg1 (%r8),%xmm0",},
615{{0x0f, 0x38, 0xcc, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
616"0f 38 cc 04 25 78 56 34 12 \tsha256msg1 0x12345678,%xmm0",},
617{{0x0f, 0x38, 0xcc, 0x18, }, 4, 0, "", "",
618"0f 38 cc 18 \tsha256msg1 (%rax),%xmm3",},
619{{0x0f, 0x38, 0xcc, 0x04, 0x01, }, 5, 0, "", "",
620"0f 38 cc 04 01 \tsha256msg1 (%rcx,%rax,1),%xmm0",},
621{{0x0f, 0x38, 0xcc, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
622"0f 38 cc 04 05 78 56 34 12 \tsha256msg1 0x12345678(,%rax,1),%xmm0",},
623{{0x0f, 0x38, 0xcc, 0x04, 0x08, }, 5, 0, "", "",
624"0f 38 cc 04 08 \tsha256msg1 (%rax,%rcx,1),%xmm0",},
625{{0x0f, 0x38, 0xcc, 0x04, 0xc8, }, 5, 0, "", "",
626"0f 38 cc 04 c8 \tsha256msg1 (%rax,%rcx,8),%xmm0",},
627{{0x0f, 0x38, 0xcc, 0x40, 0x12, }, 5, 0, "", "",
628"0f 38 cc 40 12 \tsha256msg1 0x12(%rax),%xmm0",},
629{{0x0f, 0x38, 0xcc, 0x45, 0x12, }, 5, 0, "", "",
630"0f 38 cc 45 12 \tsha256msg1 0x12(%rbp),%xmm0",},
631{{0x0f, 0x38, 0xcc, 0x44, 0x01, 0x12, }, 6, 0, "", "",
632"0f 38 cc 44 01 12 \tsha256msg1 0x12(%rcx,%rax,1),%xmm0",},
633{{0x0f, 0x38, 0xcc, 0x44, 0x05, 0x12, }, 6, 0, "", "",
634"0f 38 cc 44 05 12 \tsha256msg1 0x12(%rbp,%rax,1),%xmm0",},
635{{0x0f, 0x38, 0xcc, 0x44, 0x08, 0x12, }, 6, 0, "", "",
636"0f 38 cc 44 08 12 \tsha256msg1 0x12(%rax,%rcx,1),%xmm0",},
637{{0x0f, 0x38, 0xcc, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
638"0f 38 cc 44 c8 12 \tsha256msg1 0x12(%rax,%rcx,8),%xmm0",},
639{{0x0f, 0x38, 0xcc, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
640"0f 38 cc 80 78 56 34 12 \tsha256msg1 0x12345678(%rax),%xmm0",},
641{{0x0f, 0x38, 0xcc, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
642"0f 38 cc 85 78 56 34 12 \tsha256msg1 0x12345678(%rbp),%xmm0",},
643{{0x0f, 0x38, 0xcc, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
644"0f 38 cc 84 01 78 56 34 12 \tsha256msg1 0x12345678(%rcx,%rax,1),%xmm0",},
645{{0x0f, 0x38, 0xcc, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
646"0f 38 cc 84 05 78 56 34 12 \tsha256msg1 0x12345678(%rbp,%rax,1),%xmm0",},
647{{0x0f, 0x38, 0xcc, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
648"0f 38 cc 84 08 78 56 34 12 \tsha256msg1 0x12345678(%rax,%rcx,1),%xmm0",},
649{{0x0f, 0x38, 0xcc, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
650"0f 38 cc 84 c8 78 56 34 12 \tsha256msg1 0x12345678(%rax,%rcx,8),%xmm0",},
651{{0x44, 0x0f, 0x38, 0xcc, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
652"44 0f 38 cc bc c8 78 56 34 12 \tsha256msg1 0x12345678(%rax,%rcx,8),%xmm15",},
653{{0x0f, 0x38, 0xcd, 0xc1, }, 4, 0, "", "",
654"0f 38 cd c1 \tsha256msg2 %xmm1,%xmm0",},
655{{0x0f, 0x38, 0xcd, 0xd7, }, 4, 0, "", "",
656"0f 38 cd d7 \tsha256msg2 %xmm7,%xmm2",},
657{{0x41, 0x0f, 0x38, 0xcd, 0xc0, }, 5, 0, "", "",
658"41 0f 38 cd c0 \tsha256msg2 %xmm8,%xmm0",},
659{{0x44, 0x0f, 0x38, 0xcd, 0xc7, }, 5, 0, "", "",
660"44 0f 38 cd c7 \tsha256msg2 %xmm7,%xmm8",},
661{{0x45, 0x0f, 0x38, 0xcd, 0xc7, }, 5, 0, "", "",
662"45 0f 38 cd c7 \tsha256msg2 %xmm15,%xmm8",},
663{{0x0f, 0x38, 0xcd, 0x00, }, 4, 0, "", "",
664"0f 38 cd 00 \tsha256msg2 (%rax),%xmm0",},
665{{0x41, 0x0f, 0x38, 0xcd, 0x00, }, 5, 0, "", "",
666"41 0f 38 cd 00 \tsha256msg2 (%r8),%xmm0",},
667{{0x0f, 0x38, 0xcd, 0x04, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
668"0f 38 cd 04 25 78 56 34 12 \tsha256msg2 0x12345678,%xmm0",},
669{{0x0f, 0x38, 0xcd, 0x18, }, 4, 0, "", "",
670"0f 38 cd 18 \tsha256msg2 (%rax),%xmm3",},
671{{0x0f, 0x38, 0xcd, 0x04, 0x01, }, 5, 0, "", "",
672"0f 38 cd 04 01 \tsha256msg2 (%rcx,%rax,1),%xmm0",},
673{{0x0f, 0x38, 0xcd, 0x04, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
674"0f 38 cd 04 05 78 56 34 12 \tsha256msg2 0x12345678(,%rax,1),%xmm0",},
675{{0x0f, 0x38, 0xcd, 0x04, 0x08, }, 5, 0, "", "",
676"0f 38 cd 04 08 \tsha256msg2 (%rax,%rcx,1),%xmm0",},
677{{0x0f, 0x38, 0xcd, 0x04, 0xc8, }, 5, 0, "", "",
678"0f 38 cd 04 c8 \tsha256msg2 (%rax,%rcx,8),%xmm0",},
679{{0x0f, 0x38, 0xcd, 0x40, 0x12, }, 5, 0, "", "",
680"0f 38 cd 40 12 \tsha256msg2 0x12(%rax),%xmm0",},
681{{0x0f, 0x38, 0xcd, 0x45, 0x12, }, 5, 0, "", "",
682"0f 38 cd 45 12 \tsha256msg2 0x12(%rbp),%xmm0",},
683{{0x0f, 0x38, 0xcd, 0x44, 0x01, 0x12, }, 6, 0, "", "",
684"0f 38 cd 44 01 12 \tsha256msg2 0x12(%rcx,%rax,1),%xmm0",},
685{{0x0f, 0x38, 0xcd, 0x44, 0x05, 0x12, }, 6, 0, "", "",
686"0f 38 cd 44 05 12 \tsha256msg2 0x12(%rbp,%rax,1),%xmm0",},
687{{0x0f, 0x38, 0xcd, 0x44, 0x08, 0x12, }, 6, 0, "", "",
688"0f 38 cd 44 08 12 \tsha256msg2 0x12(%rax,%rcx,1),%xmm0",},
689{{0x0f, 0x38, 0xcd, 0x44, 0xc8, 0x12, }, 6, 0, "", "",
690"0f 38 cd 44 c8 12 \tsha256msg2 0x12(%rax,%rcx,8),%xmm0",},
691{{0x0f, 0x38, 0xcd, 0x80, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
692"0f 38 cd 80 78 56 34 12 \tsha256msg2 0x12345678(%rax),%xmm0",},
693{{0x0f, 0x38, 0xcd, 0x85, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
694"0f 38 cd 85 78 56 34 12 \tsha256msg2 0x12345678(%rbp),%xmm0",},
695{{0x0f, 0x38, 0xcd, 0x84, 0x01, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
696"0f 38 cd 84 01 78 56 34 12 \tsha256msg2 0x12345678(%rcx,%rax,1),%xmm0",},
697{{0x0f, 0x38, 0xcd, 0x84, 0x05, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
698"0f 38 cd 84 05 78 56 34 12 \tsha256msg2 0x12345678(%rbp,%rax,1),%xmm0",},
699{{0x0f, 0x38, 0xcd, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
700"0f 38 cd 84 08 78 56 34 12 \tsha256msg2 0x12345678(%rax,%rcx,1),%xmm0",},
701{{0x0f, 0x38, 0xcd, 0x84, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
702"0f 38 cd 84 c8 78 56 34 12 \tsha256msg2 0x12345678(%rax,%rcx,8),%xmm0",},
703{{0x44, 0x0f, 0x38, 0xcd, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
704"44 0f 38 cd bc c8 78 56 34 12 \tsha256msg2 0x12345678(%rax,%rcx,8),%xmm15",},
705{{0x66, 0x0f, 0xae, 0x38, }, 4, 0, "", "",
706"66 0f ae 38 \tclflushopt (%rax)",},
707{{0x66, 0x41, 0x0f, 0xae, 0x38, }, 5, 0, "", "",
708"66 41 0f ae 38 \tclflushopt (%r8)",},
709{{0x66, 0x0f, 0xae, 0x3c, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
710"66 0f ae 3c 25 78 56 34 12 \tclflushopt 0x12345678",},
711{{0x66, 0x0f, 0xae, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
712"66 0f ae bc c8 78 56 34 12 \tclflushopt 0x12345678(%rax,%rcx,8)",},
713{{0x66, 0x41, 0x0f, 0xae, 0xbc, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
714"66 41 0f ae bc c8 78 56 34 12 \tclflushopt 0x12345678(%r8,%rcx,8)",},
715{{0x0f, 0xae, 0x38, }, 3, 0, "", "",
716"0f ae 38 \tclflush (%rax)",},
717{{0x41, 0x0f, 0xae, 0x38, }, 4, 0, "", "",
718"41 0f ae 38 \tclflush (%r8)",},
719{{0x0f, 0xae, 0xf8, }, 3, 0, "", "",
720"0f ae f8 \tsfence ",},
721{{0x66, 0x0f, 0xae, 0x30, }, 4, 0, "", "",
722"66 0f ae 30 \tclwb (%rax)",},
723{{0x66, 0x41, 0x0f, 0xae, 0x30, }, 5, 0, "", "",
724"66 41 0f ae 30 \tclwb (%r8)",},
725{{0x66, 0x0f, 0xae, 0x34, 0x25, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
726"66 0f ae 34 25 78 56 34 12 \tclwb 0x12345678",},
727{{0x66, 0x0f, 0xae, 0xb4, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
728"66 0f ae b4 c8 78 56 34 12 \tclwb 0x12345678(%rax,%rcx,8)",},
729{{0x66, 0x41, 0x0f, 0xae, 0xb4, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 10, 0, "", "",
730"66 41 0f ae b4 c8 78 56 34 12 \tclwb 0x12345678(%r8,%rcx,8)",},
731{{0x0f, 0xae, 0x30, }, 3, 0, "", "",
732"0f ae 30 \txsaveopt (%rax)",},
733{{0x41, 0x0f, 0xae, 0x30, }, 4, 0, "", "",
734"41 0f ae 30 \txsaveopt (%r8)",},
735{{0x0f, 0xae, 0xf0, }, 3, 0, "", "",
736"0f ae f0 \tmfence ",},
737{{0x0f, 0xc7, 0x20, }, 3, 0, "", "",
738"0f c7 20 \txsavec (%rax)",},
739{{0x41, 0x0f, 0xc7, 0x20, }, 4, 0, "", "",
740"41 0f c7 20 \txsavec (%r8)",},
741{{0x0f, 0xc7, 0x24, 0x25, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
742"0f c7 24 25 78 56 34 12 \txsavec 0x12345678",},
743{{0x0f, 0xc7, 0xa4, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
744"0f c7 a4 c8 78 56 34 12 \txsavec 0x12345678(%rax,%rcx,8)",},
745{{0x41, 0x0f, 0xc7, 0xa4, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
746"41 0f c7 a4 c8 78 56 34 12 \txsavec 0x12345678(%r8,%rcx,8)",},
747{{0x0f, 0xc7, 0x28, }, 3, 0, "", "",
748"0f c7 28 \txsaves (%rax)",},
749{{0x41, 0x0f, 0xc7, 0x28, }, 4, 0, "", "",
750"41 0f c7 28 \txsaves (%r8)",},
751{{0x0f, 0xc7, 0x2c, 0x25, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
752"0f c7 2c 25 78 56 34 12 \txsaves 0x12345678",},
753{{0x0f, 0xc7, 0xac, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
754"0f c7 ac c8 78 56 34 12 \txsaves 0x12345678(%rax,%rcx,8)",},
755{{0x41, 0x0f, 0xc7, 0xac, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
756"41 0f c7 ac c8 78 56 34 12 \txsaves 0x12345678(%r8,%rcx,8)",},
757{{0x0f, 0xc7, 0x18, }, 3, 0, "", "",
758"0f c7 18 \txrstors (%rax)",},
759{{0x41, 0x0f, 0xc7, 0x18, }, 4, 0, "", "",
760"41 0f c7 18 \txrstors (%r8)",},
761{{0x0f, 0xc7, 0x1c, 0x25, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
762"0f c7 1c 25 78 56 34 12 \txrstors 0x12345678",},
763{{0x0f, 0xc7, 0x9c, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
764"0f c7 9c c8 78 56 34 12 \txrstors 0x12345678(%rax,%rcx,8)",},
765{{0x41, 0x0f, 0xc7, 0x9c, 0xc8, 0x78, 0x56, 0x34, 0x12, }, 9, 0, "", "",
766"41 0f c7 9c c8 78 56 34 12 \txrstors 0x12345678(%r8,%rcx,8)",},
767{{0x66, 0x0f, 0xae, 0xf8, }, 4, 0, "", "",
768"66 0f ae f8 \tpcommit ",},
tools/perf/arch/x86/tests/insn-x86-dat-src.c+877−0
@@ -0,0 +1,877 @@
1/*
2 * This file contains instructions for testing by the test titled:
3 *
4 * "Test x86 instruction decoder - new instructions"
5 *
6 * Note that the 'Expecting' comment lines are consumed by the
7 * gen-insn-x86-dat.awk script and have the format:
8 *
9 * Expecting: <op> <branch> <rel>
10 *
11 * If this file is changed, remember to run the gen-insn-x86-dat.sh
12 * script and commit the result.
13 *
14 * Refer to insn-x86.c for more details.
15 */
16
17int main(void)
18{
19 /* Following line is a marker for the awk script - do not change */
20 asm volatile("rdtsc"); /* Start here */
21
22#ifdef __x86_64__
23
24 /* bndmk m64, bnd */
25
26 asm volatile("bndmk (%rax), %bnd0");
27 asm volatile("bndmk (%r8), %bnd0");
28 asm volatile("bndmk (0x12345678), %bnd0");
29 asm volatile("bndmk (%rax), %bnd3");
30 asm volatile("bndmk (%rcx,%rax,1), %bnd0");
31 asm volatile("bndmk 0x12345678(,%rax,1), %bnd0");
32 asm volatile("bndmk (%rax,%rcx,1), %bnd0");
33 asm volatile("bndmk (%rax,%rcx,8), %bnd0");
34 asm volatile("bndmk 0x12(%rax), %bnd0");
35 asm volatile("bndmk 0x12(%rbp), %bnd0");
36 asm volatile("bndmk 0x12(%rcx,%rax,1), %bnd0");
37 asm volatile("bndmk 0x12(%rbp,%rax,1), %bnd0");
38 asm volatile("bndmk 0x12(%rax,%rcx,1), %bnd0");
39 asm volatile("bndmk 0x12(%rax,%rcx,8), %bnd0");
40 asm volatile("bndmk 0x12345678(%rax), %bnd0");
41 asm volatile("bndmk 0x12345678(%rbp), %bnd0");
42 asm volatile("bndmk 0x12345678(%rcx,%rax,1), %bnd0");
43 asm volatile("bndmk 0x12345678(%rbp,%rax,1), %bnd0");
44 asm volatile("bndmk 0x12345678(%rax,%rcx,1), %bnd0");
45 asm volatile("bndmk 0x12345678(%rax,%rcx,8), %bnd0");
46
47 /* bndcl r/m64, bnd */
48
49 asm volatile("bndcl (%rax), %bnd0");
50 asm volatile("bndcl (%r8), %bnd0");
51 asm volatile("bndcl (0x12345678), %bnd0");
52 asm volatile("bndcl (%rax), %bnd3");
53 asm volatile("bndcl (%rcx,%rax,1), %bnd0");
54 asm volatile("bndcl 0x12345678(,%rax,1), %bnd0");
55 asm volatile("bndcl (%rax,%rcx,1), %bnd0");
56 asm volatile("bndcl (%rax,%rcx,8), %bnd0");
57 asm volatile("bndcl 0x12(%rax), %bnd0");
58 asm volatile("bndcl 0x12(%rbp), %bnd0");
59 asm volatile("bndcl 0x12(%rcx,%rax,1), %bnd0");
60 asm volatile("bndcl 0x12(%rbp,%rax,1), %bnd0");
61 asm volatile("bndcl 0x12(%rax,%rcx,1), %bnd0");
62 asm volatile("bndcl 0x12(%rax,%rcx,8), %bnd0");
63 asm volatile("bndcl 0x12345678(%rax), %bnd0");
64 asm volatile("bndcl 0x12345678(%rbp), %bnd0");
65 asm volatile("bndcl 0x12345678(%rcx,%rax,1), %bnd0");
66 asm volatile("bndcl 0x12345678(%rbp,%rax,1), %bnd0");
67 asm volatile("bndcl 0x12345678(%rax,%rcx,1), %bnd0");
68 asm volatile("bndcl 0x12345678(%rax,%rcx,8), %bnd0");
69 asm volatile("bndcl %rax, %bnd0");
70
71 /* bndcu r/m64, bnd */
72
73 asm volatile("bndcu (%rax), %bnd0");
74 asm volatile("bndcu (%r8), %bnd0");
75 asm volatile("bndcu (0x12345678), %bnd0");
76 asm volatile("bndcu (%rax), %bnd3");
77 asm volatile("bndcu (%rcx,%rax,1), %bnd0");
78 asm volatile("bndcu 0x12345678(,%rax,1), %bnd0");
79 asm volatile("bndcu (%rax,%rcx,1), %bnd0");
80 asm volatile("bndcu (%rax,%rcx,8), %bnd0");
81 asm volatile("bndcu 0x12(%rax), %bnd0");
82 asm volatile("bndcu 0x12(%rbp), %bnd0");
83 asm volatile("bndcu 0x12(%rcx,%rax,1), %bnd0");
84 asm volatile("bndcu 0x12(%rbp,%rax,1), %bnd0");
85 asm volatile("bndcu 0x12(%rax,%rcx,1), %bnd0");
86 asm volatile("bndcu 0x12(%rax,%rcx,8), %bnd0");
87 asm volatile("bndcu 0x12345678(%rax), %bnd0");
88 asm volatile("bndcu 0x12345678(%rbp), %bnd0");
89 asm volatile("bndcu 0x12345678(%rcx,%rax,1), %bnd0");
90 asm volatile("bndcu 0x12345678(%rbp,%rax,1), %bnd0");
91 asm volatile("bndcu 0x12345678(%rax,%rcx,1), %bnd0");
92 asm volatile("bndcu 0x12345678(%rax,%rcx,8), %bnd0");
93 asm volatile("bndcu %rax, %bnd0");
94
95 /* bndcn r/m64, bnd */
96
97 asm volatile("bndcn (%rax), %bnd0");
98 asm volatile("bndcn (%r8), %bnd0");
99 asm volatile("bndcn (0x12345678), %bnd0");
100 asm volatile("bndcn (%rax), %bnd3");
101 asm volatile("bndcn (%rcx,%rax,1), %bnd0");
102 asm volatile("bndcn 0x12345678(,%rax,1), %bnd0");
103 asm volatile("bndcn (%rax,%rcx,1), %bnd0");
104 asm volatile("bndcn (%rax,%rcx,8), %bnd0");
105 asm volatile("bndcn 0x12(%rax), %bnd0");
106 asm volatile("bndcn 0x12(%rbp), %bnd0");
107 asm volatile("bndcn 0x12(%rcx,%rax,1), %bnd0");
108 asm volatile("bndcn 0x12(%rbp,%rax,1), %bnd0");
109 asm volatile("bndcn 0x12(%rax,%rcx,1), %bnd0");
110 asm volatile("bndcn 0x12(%rax,%rcx,8), %bnd0");
111 asm volatile("bndcn 0x12345678(%rax), %bnd0");
112 asm volatile("bndcn 0x12345678(%rbp), %bnd0");
113 asm volatile("bndcn 0x12345678(%rcx,%rax,1), %bnd0");
114 asm volatile("bndcn 0x12345678(%rbp,%rax,1), %bnd0");
115 asm volatile("bndcn 0x12345678(%rax,%rcx,1), %bnd0");
116 asm volatile("bndcn 0x12345678(%rax,%rcx,8), %bnd0");
117 asm volatile("bndcn %rax, %bnd0");
118
119 /* bndmov m128, bnd */
120
121 asm volatile("bndmov (%rax), %bnd0");
122 asm volatile("bndmov (%r8), %bnd0");
123 asm volatile("bndmov (0x12345678), %bnd0");
124 asm volatile("bndmov (%rax), %bnd3");
125 asm volatile("bndmov (%rcx,%rax,1), %bnd0");
126 asm volatile("bndmov 0x12345678(,%rax,1), %bnd0");
127 asm volatile("bndmov (%rax,%rcx,1), %bnd0");
128 asm volatile("bndmov (%rax,%rcx,8), %bnd0");
129 asm volatile("bndmov 0x12(%rax), %bnd0");
130 asm volatile("bndmov 0x12(%rbp), %bnd0");
131 asm volatile("bndmov 0x12(%rcx,%rax,1), %bnd0");
132 asm volatile("bndmov 0x12(%rbp,%rax,1), %bnd0");
133 asm volatile("bndmov 0x12(%rax,%rcx,1), %bnd0");
134 asm volatile("bndmov 0x12(%rax,%rcx,8), %bnd0");
135 asm volatile("bndmov 0x12345678(%rax), %bnd0");
136 asm volatile("bndmov 0x12345678(%rbp), %bnd0");
137 asm volatile("bndmov 0x12345678(%rcx,%rax,1), %bnd0");
138 asm volatile("bndmov 0x12345678(%rbp,%rax,1), %bnd0");
139 asm volatile("bndmov 0x12345678(%rax,%rcx,1), %bnd0");
140 asm volatile("bndmov 0x12345678(%rax,%rcx,8), %bnd0");
141
142 /* bndmov bnd, m128 */
143
144 asm volatile("bndmov %bnd0, (%rax)");
145 asm volatile("bndmov %bnd0, (%r8)");
146 asm volatile("bndmov %bnd0, (0x12345678)");
147 asm volatile("bndmov %bnd3, (%rax)");
148 asm volatile("bndmov %bnd0, (%rcx,%rax,1)");
149 asm volatile("bndmov %bnd0, 0x12345678(,%rax,1)");
150 asm volatile("bndmov %bnd0, (%rax,%rcx,1)");
151 asm volatile("bndmov %bnd0, (%rax,%rcx,8)");
152 asm volatile("bndmov %bnd0, 0x12(%rax)");
153 asm volatile("bndmov %bnd0, 0x12(%rbp)");
154 asm volatile("bndmov %bnd0, 0x12(%rcx,%rax,1)");
155 asm volatile("bndmov %bnd0, 0x12(%rbp,%rax,1)");
156 asm volatile("bndmov %bnd0, 0x12(%rax,%rcx,1)");
157 asm volatile("bndmov %bnd0, 0x12(%rax,%rcx,8)");
158 asm volatile("bndmov %bnd0, 0x12345678(%rax)");
159 asm volatile("bndmov %bnd0, 0x12345678(%rbp)");
160 asm volatile("bndmov %bnd0, 0x12345678(%rcx,%rax,1)");
161 asm volatile("bndmov %bnd0, 0x12345678(%rbp,%rax,1)");
162 asm volatile("bndmov %bnd0, 0x12345678(%rax,%rcx,1)");
163 asm volatile("bndmov %bnd0, 0x12345678(%rax,%rcx,8)");
164
165 /* bndmov bnd2, bnd1 */
166
167 asm volatile("bndmov %bnd0, %bnd1");
168 asm volatile("bndmov %bnd1, %bnd0");
169
170 /* bndldx mib, bnd */
171
172 asm volatile("bndldx (%rax), %bnd0");
173 asm volatile("bndldx (%r8), %bnd0");
174 asm volatile("bndldx (0x12345678), %bnd0");
175 asm volatile("bndldx (%rax), %bnd3");
176 asm volatile("bndldx (%rcx,%rax,1), %bnd0");
177 asm volatile("bndldx 0x12345678(,%rax,1), %bnd0");
178 asm volatile("bndldx (%rax,%rcx,1), %bnd0");
179 asm volatile("bndldx 0x12(%rax), %bnd0");
180 asm volatile("bndldx 0x12(%rbp), %bnd0");
181 asm volatile("bndldx 0x12(%rcx,%rax,1), %bnd0");
182 asm volatile("bndldx 0x12(%rbp,%rax,1), %bnd0");
183 asm volatile("bndldx 0x12(%rax,%rcx,1), %bnd0");
184 asm volatile("bndldx 0x12345678(%rax), %bnd0");
185 asm volatile("bndldx 0x12345678(%rbp), %bnd0");
186 asm volatile("bndldx 0x12345678(%rcx,%rax,1), %bnd0");
187 asm volatile("bndldx 0x12345678(%rbp,%rax,1), %bnd0");
188 asm volatile("bndldx 0x12345678(%rax,%rcx,1), %bnd0");
189
190 /* bndstx bnd, mib */
191
192 asm volatile("bndstx %bnd0, (%rax)");
193 asm volatile("bndstx %bnd0, (%r8)");
194 asm volatile("bndstx %bnd0, (0x12345678)");
195 asm volatile("bndstx %bnd3, (%rax)");
196 asm volatile("bndstx %bnd0, (%rcx,%rax,1)");
197 asm volatile("bndstx %bnd0, 0x12345678(,%rax,1)");
198 asm volatile("bndstx %bnd0, (%rax,%rcx,1)");
199 asm volatile("bndstx %bnd0, 0x12(%rax)");
200 asm volatile("bndstx %bnd0, 0x12(%rbp)");
201 asm volatile("bndstx %bnd0, 0x12(%rcx,%rax,1)");
202 asm volatile("bndstx %bnd0, 0x12(%rbp,%rax,1)");
203 asm volatile("bndstx %bnd0, 0x12(%rax,%rcx,1)");
204 asm volatile("bndstx %bnd0, 0x12345678(%rax)");
205 asm volatile("bndstx %bnd0, 0x12345678(%rbp)");
206 asm volatile("bndstx %bnd0, 0x12345678(%rcx,%rax,1)");
207 asm volatile("bndstx %bnd0, 0x12345678(%rbp,%rax,1)");
208 asm volatile("bndstx %bnd0, 0x12345678(%rax,%rcx,1)");
209
210 /* bnd prefix on call, ret, jmp and all jcc */
211
212 asm volatile("bnd call label1"); /* Expecting: call unconditional 0 */
213 asm volatile("bnd call *(%eax)"); /* Expecting: call indirect 0 */
214 asm volatile("bnd ret"); /* Expecting: ret indirect 0 */
215 asm volatile("bnd jmp label1"); /* Expecting: jmp unconditional 0 */
216 asm volatile("bnd jmp label1"); /* Expecting: jmp unconditional 0 */
217 asm volatile("bnd jmp *(%ecx)"); /* Expecting: jmp indirect 0 */
218 asm volatile("bnd jne label1"); /* Expecting: jcc conditional 0 */
219
220 /* sha1rnds4 imm8, xmm2/m128, xmm1 */
221
222 asm volatile("sha1rnds4 $0x0, %xmm1, %xmm0");
223 asm volatile("sha1rnds4 $0x91, %xmm7, %xmm2");
224 asm volatile("sha1rnds4 $0x91, %xmm8, %xmm0");
225 asm volatile("sha1rnds4 $0x91, %xmm7, %xmm8");
226 asm volatile("sha1rnds4 $0x91, %xmm15, %xmm8");
227 asm volatile("sha1rnds4 $0x91, (%rax), %xmm0");
228 asm volatile("sha1rnds4 $0x91, (%r8), %xmm0");
229 asm volatile("sha1rnds4 $0x91, (0x12345678), %xmm0");
230 asm volatile("sha1rnds4 $0x91, (%rax), %xmm3");
231 asm volatile("sha1rnds4 $0x91, (%rcx,%rax,1), %xmm0");
232 asm volatile("sha1rnds4 $0x91, 0x12345678(,%rax,1), %xmm0");
233 asm volatile("sha1rnds4 $0x91, (%rax,%rcx,1), %xmm0");
234 asm volatile("sha1rnds4 $0x91, (%rax,%rcx,8), %xmm0");
235 asm volatile("sha1rnds4 $0x91, 0x12(%rax), %xmm0");
236 asm volatile("sha1rnds4 $0x91, 0x12(%rbp), %xmm0");
237 asm volatile("sha1rnds4 $0x91, 0x12(%rcx,%rax,1), %xmm0");
238 asm volatile("sha1rnds4 $0x91, 0x12(%rbp,%rax,1), %xmm0");
239 asm volatile("sha1rnds4 $0x91, 0x12(%rax,%rcx,1), %xmm0");
240 asm volatile("sha1rnds4 $0x91, 0x12(%rax,%rcx,8), %xmm0");
241 asm volatile("sha1rnds4 $0x91, 0x12345678(%rax), %xmm0");
242 asm volatile("sha1rnds4 $0x91, 0x12345678(%rbp), %xmm0");
243 asm volatile("sha1rnds4 $0x91, 0x12345678(%rcx,%rax,1), %xmm0");
244 asm volatile("sha1rnds4 $0x91, 0x12345678(%rbp,%rax,1), %xmm0");
245 asm volatile("sha1rnds4 $0x91, 0x12345678(%rax,%rcx,1), %xmm0");
246 asm volatile("sha1rnds4 $0x91, 0x12345678(%rax,%rcx,8), %xmm0");
247 asm volatile("sha1rnds4 $0x91, 0x12345678(%rax,%rcx,8), %xmm15");
248
249 /* sha1nexte xmm2/m128, xmm1 */
250
251 asm volatile("sha1nexte %xmm1, %xmm0");
252 asm volatile("sha1nexte %xmm7, %xmm2");
253 asm volatile("sha1nexte %xmm8, %xmm0");
254 asm volatile("sha1nexte %xmm7, %xmm8");
255 asm volatile("sha1nexte %xmm15, %xmm8");
256 asm volatile("sha1nexte (%rax), %xmm0");
257 asm volatile("sha1nexte (%r8), %xmm0");
258 asm volatile("sha1nexte (0x12345678), %xmm0");
259 asm volatile("sha1nexte (%rax), %xmm3");
260 asm volatile("sha1nexte (%rcx,%rax,1), %xmm0");
261 asm volatile("sha1nexte 0x12345678(,%rax,1), %xmm0");
262 asm volatile("sha1nexte (%rax,%rcx,1), %xmm0");
263 asm volatile("sha1nexte (%rax,%rcx,8), %xmm0");
264 asm volatile("sha1nexte 0x12(%rax), %xmm0");
265 asm volatile("sha1nexte 0x12(%rbp), %xmm0");
266 asm volatile("sha1nexte 0x12(%rcx,%rax,1), %xmm0");
267 asm volatile("sha1nexte 0x12(%rbp,%rax,1), %xmm0");
268 asm volatile("sha1nexte 0x12(%rax,%rcx,1), %xmm0");
269 asm volatile("sha1nexte 0x12(%rax,%rcx,8), %xmm0");
270 asm volatile("sha1nexte 0x12345678(%rax), %xmm0");
271 asm volatile("sha1nexte 0x12345678(%rbp), %xmm0");
272 asm volatile("sha1nexte 0x12345678(%rcx,%rax,1), %xmm0");
273 asm volatile("sha1nexte 0x12345678(%rbp,%rax,1), %xmm0");
274 asm volatile("sha1nexte 0x12345678(%rax,%rcx,1), %xmm0");
275 asm volatile("sha1nexte 0x12345678(%rax,%rcx,8), %xmm0");
276 asm volatile("sha1nexte 0x12345678(%rax,%rcx,8), %xmm15");
277
278 /* sha1msg1 xmm2/m128, xmm1 */
279
280 asm volatile("sha1msg1 %xmm1, %xmm0");
281 asm volatile("sha1msg1 %xmm7, %xmm2");
282 asm volatile("sha1msg1 %xmm8, %xmm0");
283 asm volatile("sha1msg1 %xmm7, %xmm8");
284 asm volatile("sha1msg1 %xmm15, %xmm8");
285 asm volatile("sha1msg1 (%rax), %xmm0");
286 asm volatile("sha1msg1 (%r8), %xmm0");
287 asm volatile("sha1msg1 (0x12345678), %xmm0");
288 asm volatile("sha1msg1 (%rax), %xmm3");
289 asm volatile("sha1msg1 (%rcx,%rax,1), %xmm0");
290 asm volatile("sha1msg1 0x12345678(,%rax,1), %xmm0");
291 asm volatile("sha1msg1 (%rax,%rcx,1), %xmm0");
292 asm volatile("sha1msg1 (%rax,%rcx,8), %xmm0");
293 asm volatile("sha1msg1 0x12(%rax), %xmm0");
294 asm volatile("sha1msg1 0x12(%rbp), %xmm0");
295 asm volatile("sha1msg1 0x12(%rcx,%rax,1), %xmm0");
296 asm volatile("sha1msg1 0x12(%rbp,%rax,1), %xmm0");
297 asm volatile("sha1msg1 0x12(%rax,%rcx,1), %xmm0");
298 asm volatile("sha1msg1 0x12(%rax,%rcx,8), %xmm0");
299 asm volatile("sha1msg1 0x12345678(%rax), %xmm0");
300 asm volatile("sha1msg1 0x12345678(%rbp), %xmm0");
301 asm volatile("sha1msg1 0x12345678(%rcx,%rax,1), %xmm0");
302 asm volatile("sha1msg1 0x12345678(%rbp,%rax,1), %xmm0");
303 asm volatile("sha1msg1 0x12345678(%rax,%rcx,1), %xmm0");
304 asm volatile("sha1msg1 0x12345678(%rax,%rcx,8), %xmm0");
305 asm volatile("sha1msg1 0x12345678(%rax,%rcx,8), %xmm15");
306
307 /* sha1msg2 xmm2/m128, xmm1 */
308
309 asm volatile("sha1msg2 %xmm1, %xmm0");
310 asm volatile("sha1msg2 %xmm7, %xmm2");
311 asm volatile("sha1msg2 %xmm8, %xmm0");
312 asm volatile("sha1msg2 %xmm7, %xmm8");
313 asm volatile("sha1msg2 %xmm15, %xmm8");
314 asm volatile("sha1msg2 (%rax), %xmm0");
315 asm volatile("sha1msg2 (%r8), %xmm0");
316 asm volatile("sha1msg2 (0x12345678), %xmm0");
317 asm volatile("sha1msg2 (%rax), %xmm3");
318 asm volatile("sha1msg2 (%rcx,%rax,1), %xmm0");
319 asm volatile("sha1msg2 0x12345678(,%rax,1), %xmm0");
320 asm volatile("sha1msg2 (%rax,%rcx,1), %xmm0");
321 asm volatile("sha1msg2 (%rax,%rcx,8), %xmm0");
322 asm volatile("sha1msg2 0x12(%rax), %xmm0");
323 asm volatile("sha1msg2 0x12(%rbp), %xmm0");
324 asm volatile("sha1msg2 0x12(%rcx,%rax,1), %xmm0");
325 asm volatile("sha1msg2 0x12(%rbp,%rax,1), %xmm0");
326 asm volatile("sha1msg2 0x12(%rax,%rcx,1), %xmm0");
327 asm volatile("sha1msg2 0x12(%rax,%rcx,8), %xmm0");
328 asm volatile("sha1msg2 0x12345678(%rax), %xmm0");
329 asm volatile("sha1msg2 0x12345678(%rbp), %xmm0");
330 asm volatile("sha1msg2 0x12345678(%rcx,%rax,1), %xmm0");
331 asm volatile("sha1msg2 0x12345678(%rbp,%rax,1), %xmm0");
332 asm volatile("sha1msg2 0x12345678(%rax,%rcx,1), %xmm0");
333 asm volatile("sha1msg2 0x12345678(%rax,%rcx,8), %xmm0");
334 asm volatile("sha1msg2 0x12345678(%rax,%rcx,8), %xmm15");
335
336 /* sha256rnds2 <XMM0>, xmm2/m128, xmm1 */
337 /* Note sha256rnds2 has an implicit operand 'xmm0' */
338
339 asm volatile("sha256rnds2 %xmm4, %xmm1");
340 asm volatile("sha256rnds2 %xmm7, %xmm2");
341 asm volatile("sha256rnds2 %xmm8, %xmm1");
342 asm volatile("sha256rnds2 %xmm7, %xmm8");
343 asm volatile("sha256rnds2 %xmm15, %xmm8");
344 asm volatile("sha256rnds2 (%rax), %xmm1");
345 asm volatile("sha256rnds2 (%r8), %xmm1");
346 asm volatile("sha256rnds2 (0x12345678), %xmm1");
347 asm volatile("sha256rnds2 (%rax), %xmm3");
348 asm volatile("sha256rnds2 (%rcx,%rax,1), %xmm1");
349 asm volatile("sha256rnds2 0x12345678(,%rax,1), %xmm1");
350 asm volatile("sha256rnds2 (%rax,%rcx,1), %xmm1");
351 asm volatile("sha256rnds2 (%rax,%rcx,8), %xmm1");
352 asm volatile("sha256rnds2 0x12(%rax), %xmm1");
353 asm volatile("sha256rnds2 0x12(%rbp), %xmm1");
354 asm volatile("sha256rnds2 0x12(%rcx,%rax,1), %xmm1");
355 asm volatile("sha256rnds2 0x12(%rbp,%rax,1), %xmm1");
356 asm volatile("sha256rnds2 0x12(%rax,%rcx,1), %xmm1");
357 asm volatile("sha256rnds2 0x12(%rax,%rcx,8), %xmm1");
358 asm volatile("sha256rnds2 0x12345678(%rax), %xmm1");
359 asm volatile("sha256rnds2 0x12345678(%rbp), %xmm1");
360 asm volatile("sha256rnds2 0x12345678(%rcx,%rax,1), %xmm1");
361 asm volatile("sha256rnds2 0x12345678(%rbp,%rax,1), %xmm1");
362 asm volatile("sha256rnds2 0x12345678(%rax,%rcx,1), %xmm1");
363 asm volatile("sha256rnds2 0x12345678(%rax,%rcx,8), %xmm1");
364 asm volatile("sha256rnds2 0x12345678(%rax,%rcx,8), %xmm15");
365
366 /* sha256msg1 xmm2/m128, xmm1 */
367
368 asm volatile("sha256msg1 %xmm1, %xmm0");
369 asm volatile("sha256msg1 %xmm7, %xmm2");
370 asm volatile("sha256msg1 %xmm8, %xmm0");
371 asm volatile("sha256msg1 %xmm7, %xmm8");
372 asm volatile("sha256msg1 %xmm15, %xmm8");
373 asm volatile("sha256msg1 (%rax), %xmm0");
374 asm volatile("sha256msg1 (%r8), %xmm0");
375 asm volatile("sha256msg1 (0x12345678), %xmm0");
376 asm volatile("sha256msg1 (%rax), %xmm3");
377 asm volatile("sha256msg1 (%rcx,%rax,1), %xmm0");
378 asm volatile("sha256msg1 0x12345678(,%rax,1), %xmm0");
379 asm volatile("sha256msg1 (%rax,%rcx,1), %xmm0");
380 asm volatile("sha256msg1 (%rax,%rcx,8), %xmm0");
381 asm volatile("sha256msg1 0x12(%rax), %xmm0");
382 asm volatile("sha256msg1 0x12(%rbp), %xmm0");
383 asm volatile("sha256msg1 0x12(%rcx,%rax,1), %xmm0");
384 asm volatile("sha256msg1 0x12(%rbp,%rax,1), %xmm0");
385 asm volatile("sha256msg1 0x12(%rax,%rcx,1), %xmm0");
386 asm volatile("sha256msg1 0x12(%rax,%rcx,8), %xmm0");
387 asm volatile("sha256msg1 0x12345678(%rax), %xmm0");
388 asm volatile("sha256msg1 0x12345678(%rbp), %xmm0");
389 asm volatile("sha256msg1 0x12345678(%rcx,%rax,1), %xmm0");
390 asm volatile("sha256msg1 0x12345678(%rbp,%rax,1), %xmm0");
391 asm volatile("sha256msg1 0x12345678(%rax,%rcx,1), %xmm0");
392 asm volatile("sha256msg1 0x12345678(%rax,%rcx,8), %xmm0");
393 asm volatile("sha256msg1 0x12345678(%rax,%rcx,8), %xmm15");
394
395 /* sha256msg2 xmm2/m128, xmm1 */
396
397 asm volatile("sha256msg2 %xmm1, %xmm0");
398 asm volatile("sha256msg2 %xmm7, %xmm2");
399 asm volatile("sha256msg2 %xmm8, %xmm0");
400 asm volatile("sha256msg2 %xmm7, %xmm8");
401 asm volatile("sha256msg2 %xmm15, %xmm8");
402 asm volatile("sha256msg2 (%rax), %xmm0");
403 asm volatile("sha256msg2 (%r8), %xmm0");
404 asm volatile("sha256msg2 (0x12345678), %xmm0");
405 asm volatile("sha256msg2 (%rax), %xmm3");
406 asm volatile("sha256msg2 (%rcx,%rax,1), %xmm0");
407 asm volatile("sha256msg2 0x12345678(,%rax,1), %xmm0");
408 asm volatile("sha256msg2 (%rax,%rcx,1), %xmm0");
409 asm volatile("sha256msg2 (%rax,%rcx,8), %xmm0");
410 asm volatile("sha256msg2 0x12(%rax), %xmm0");
411 asm volatile("sha256msg2 0x12(%rbp), %xmm0");
412 asm volatile("sha256msg2 0x12(%rcx,%rax,1), %xmm0");
413 asm volatile("sha256msg2 0x12(%rbp,%rax,1), %xmm0");
414 asm volatile("sha256msg2 0x12(%rax,%rcx,1), %xmm0");
415 asm volatile("sha256msg2 0x12(%rax,%rcx,8), %xmm0");
416 asm volatile("sha256msg2 0x12345678(%rax), %xmm0");
417 asm volatile("sha256msg2 0x12345678(%rbp), %xmm0");
418 asm volatile("sha256msg2 0x12345678(%rcx,%rax,1), %xmm0");
419 asm volatile("sha256msg2 0x12345678(%rbp,%rax,1), %xmm0");
420 asm volatile("sha256msg2 0x12345678(%rax,%rcx,1), %xmm0");
421 asm volatile("sha256msg2 0x12345678(%rax,%rcx,8), %xmm0");
422 asm volatile("sha256msg2 0x12345678(%rax,%rcx,8), %xmm15");
423
424 /* clflushopt m8 */
425
426 asm volatile("clflushopt (%rax)");
427 asm volatile("clflushopt (%r8)");
428 asm volatile("clflushopt (0x12345678)");
429 asm volatile("clflushopt 0x12345678(%rax,%rcx,8)");
430 asm volatile("clflushopt 0x12345678(%r8,%rcx,8)");
431 /* Also check instructions in the same group encoding as clflushopt */
432 asm volatile("clflush (%rax)");
433 asm volatile("clflush (%r8)");
434 asm volatile("sfence");
435
436 /* clwb m8 */
437
438 asm volatile("clwb (%rax)");
439 asm volatile("clwb (%r8)");
440 asm volatile("clwb (0x12345678)");
441 asm volatile("clwb 0x12345678(%rax,%rcx,8)");
442 asm volatile("clwb 0x12345678(%r8,%rcx,8)");
443 /* Also check instructions in the same group encoding as clwb */
444 asm volatile("xsaveopt (%rax)");
445 asm volatile("xsaveopt (%r8)");
446 asm volatile("mfence");
447
448 /* xsavec mem */
449
450 asm volatile("xsavec (%rax)");
451 asm volatile("xsavec (%r8)");
452 asm volatile("xsavec (0x12345678)");
453 asm volatile("xsavec 0x12345678(%rax,%rcx,8)");
454 asm volatile("xsavec 0x12345678(%r8,%rcx,8)");
455
456 /* xsaves mem */
457
458 asm volatile("xsaves (%rax)");
459 asm volatile("xsaves (%r8)");
460 asm volatile("xsaves (0x12345678)");
461 asm volatile("xsaves 0x12345678(%rax,%rcx,8)");
462 asm volatile("xsaves 0x12345678(%r8,%rcx,8)");
463
464 /* xrstors mem */
465
466 asm volatile("xrstors (%rax)");
467 asm volatile("xrstors (%r8)");
468 asm volatile("xrstors (0x12345678)");
469 asm volatile("xrstors 0x12345678(%rax,%rcx,8)");
470 asm volatile("xrstors 0x12345678(%r8,%rcx,8)");
471
472#else /* #ifdef __x86_64__ */
473
474 /* bndmk m32, bnd */
475
476 asm volatile("bndmk (%eax), %bnd0");
477 asm volatile("bndmk (0x12345678), %bnd0");
478 asm volatile("bndmk (%eax), %bnd3");
479 asm volatile("bndmk (%ecx,%eax,1), %bnd0");
480 asm volatile("bndmk 0x12345678(,%eax,1), %bnd0");
481 asm volatile("bndmk (%eax,%ecx,1), %bnd0");
482 asm volatile("bndmk (%eax,%ecx,8), %bnd0");
483 asm volatile("bndmk 0x12(%eax), %bnd0");
484 asm volatile("bndmk 0x12(%ebp), %bnd0");
485 asm volatile("bndmk 0x12(%ecx,%eax,1), %bnd0");
486 asm volatile("bndmk 0x12(%ebp,%eax,1), %bnd0");
487 asm volatile("bndmk 0x12(%eax,%ecx,1), %bnd0");
488 asm volatile("bndmk 0x12(%eax,%ecx,8), %bnd0");
489 asm volatile("bndmk 0x12345678(%eax), %bnd0");
490 asm volatile("bndmk 0x12345678(%ebp), %bnd0");
491 asm volatile("bndmk 0x12345678(%ecx,%eax,1), %bnd0");
492 asm volatile("bndmk 0x12345678(%ebp,%eax,1), %bnd0");
493 asm volatile("bndmk 0x12345678(%eax,%ecx,1), %bnd0");
494 asm volatile("bndmk 0x12345678(%eax,%ecx,8), %bnd0");
495
496 /* bndcl r/m32, bnd */
497
498 asm volatile("bndcl (%eax), %bnd0");
499 asm volatile("bndcl (0x12345678), %bnd0");
500 asm volatile("bndcl (%eax), %bnd3");
501 asm volatile("bndcl (%ecx,%eax,1), %bnd0");
502 asm volatile("bndcl 0x12345678(,%eax,1), %bnd0");
503 asm volatile("bndcl (%eax,%ecx,1), %bnd0");
504 asm volatile("bndcl (%eax,%ecx,8), %bnd0");
505 asm volatile("bndcl 0x12(%eax), %bnd0");
506 asm volatile("bndcl 0x12(%ebp), %bnd0");
507 asm volatile("bndcl 0x12(%ecx,%eax,1), %bnd0");
508 asm volatile("bndcl 0x12(%ebp,%eax,1), %bnd0");
509 asm volatile("bndcl 0x12(%eax,%ecx,1), %bnd0");
510 asm volatile("bndcl 0x12(%eax,%ecx,8), %bnd0");
511 asm volatile("bndcl 0x12345678(%eax), %bnd0");
512 asm volatile("bndcl 0x12345678(%ebp), %bnd0");
513 asm volatile("bndcl 0x12345678(%ecx,%eax,1), %bnd0");
514 asm volatile("bndcl 0x12345678(%ebp,%eax,1), %bnd0");
515 asm volatile("bndcl 0x12345678(%eax,%ecx,1), %bnd0");
516 asm volatile("bndcl 0x12345678(%eax,%ecx,8), %bnd0");
517 asm volatile("bndcl %eax, %bnd0");
518
519 /* bndcu r/m32, bnd */
520
521 asm volatile("bndcu (%eax), %bnd0");
522 asm volatile("bndcu (0x12345678), %bnd0");
523 asm volatile("bndcu (%eax), %bnd3");
524 asm volatile("bndcu (%ecx,%eax,1), %bnd0");
525 asm volatile("bndcu 0x12345678(,%eax,1), %bnd0");
526 asm volatile("bndcu (%eax,%ecx,1), %bnd0");
527 asm volatile("bndcu (%eax,%ecx,8), %bnd0");
528 asm volatile("bndcu 0x12(%eax), %bnd0");
529 asm volatile("bndcu 0x12(%ebp), %bnd0");
530 asm volatile("bndcu 0x12(%ecx,%eax,1), %bnd0");
531 asm volatile("bndcu 0x12(%ebp,%eax,1), %bnd0");
532 asm volatile("bndcu 0x12(%eax,%ecx,1), %bnd0");
533 asm volatile("bndcu 0x12(%eax,%ecx,8), %bnd0");
534 asm volatile("bndcu 0x12345678(%eax), %bnd0");
535 asm volatile("bndcu 0x12345678(%ebp), %bnd0");
536 asm volatile("bndcu 0x12345678(%ecx,%eax,1), %bnd0");
537 asm volatile("bndcu 0x12345678(%ebp,%eax,1), %bnd0");
538 asm volatile("bndcu 0x12345678(%eax,%ecx,1), %bnd0");
539 asm volatile("bndcu 0x12345678(%eax,%ecx,8), %bnd0");
540 asm volatile("bndcu %eax, %bnd0");
541
542 /* bndcn r/m32, bnd */
543
544 asm volatile("bndcn (%eax), %bnd0");
545 asm volatile("bndcn (0x12345678), %bnd0");
546 asm volatile("bndcn (%eax), %bnd3");
547 asm volatile("bndcn (%ecx,%eax,1), %bnd0");
548 asm volatile("bndcn 0x12345678(,%eax,1), %bnd0");
549 asm volatile("bndcn (%eax,%ecx,1), %bnd0");
550 asm volatile("bndcn (%eax,%ecx,8), %bnd0");
551 asm volatile("bndcn 0x12(%eax), %bnd0");
552 asm volatile("bndcn 0x12(%ebp), %bnd0");
553 asm volatile("bndcn 0x12(%ecx,%eax,1), %bnd0");
554 asm volatile("bndcn 0x12(%ebp,%eax,1), %bnd0");
555 asm volatile("bndcn 0x12(%eax,%ecx,1), %bnd0");
556 asm volatile("bndcn 0x12(%eax,%ecx,8), %bnd0");
557 asm volatile("bndcn 0x12345678(%eax), %bnd0");
558 asm volatile("bndcn 0x12345678(%ebp), %bnd0");
559 asm volatile("bndcn 0x12345678(%ecx,%eax,1), %bnd0");
560 asm volatile("bndcn 0x12345678(%ebp,%eax,1), %bnd0");
561 asm volatile("bndcn 0x12345678(%eax,%ecx,1), %bnd0");
562 asm volatile("bndcn 0x12345678(%eax,%ecx,8), %bnd0");
563 asm volatile("bndcn %eax, %bnd0");
564
565 /* bndmov m64, bnd */
566
567 asm volatile("bndmov (%eax), %bnd0");
568 asm volatile("bndmov (0x12345678), %bnd0");
569 asm volatile("bndmov (%eax), %bnd3");
570 asm volatile("bndmov (%ecx,%eax,1), %bnd0");
571 asm volatile("bndmov 0x12345678(,%eax,1), %bnd0");
572 asm volatile("bndmov (%eax,%ecx,1), %bnd0");
573 asm volatile("bndmov (%eax,%ecx,8), %bnd0");
574 asm volatile("bndmov 0x12(%eax), %bnd0");
575 asm volatile("bndmov 0x12(%ebp), %bnd0");
576 asm volatile("bndmov 0x12(%ecx,%eax,1), %bnd0");
577 asm volatile("bndmov 0x12(%ebp,%eax,1), %bnd0");
578 asm volatile("bndmov 0x12(%eax,%ecx,1), %bnd0");
579 asm volatile("bndmov 0x12(%eax,%ecx,8), %bnd0");
580 asm volatile("bndmov 0x12345678(%eax), %bnd0");
581 asm volatile("bndmov 0x12345678(%ebp), %bnd0");
582 asm volatile("bndmov 0x12345678(%ecx,%eax,1), %bnd0");
583 asm volatile("bndmov 0x12345678(%ebp,%eax,1), %bnd0");
584 asm volatile("bndmov 0x12345678(%eax,%ecx,1), %bnd0");
585 asm volatile("bndmov 0x12345678(%eax,%ecx,8), %bnd0");
586
587 /* bndmov bnd, m64 */
588
589 asm volatile("bndmov %bnd0, (%eax)");
590 asm volatile("bndmov %bnd0, (0x12345678)");
591 asm volatile("bndmov %bnd3, (%eax)");
592 asm volatile("bndmov %bnd0, (%ecx,%eax,1)");
593 asm volatile("bndmov %bnd0, 0x12345678(,%eax,1)");
594 asm volatile("bndmov %bnd0, (%eax,%ecx,1)");
595 asm volatile("bndmov %bnd0, (%eax,%ecx,8)");
596 asm volatile("bndmov %bnd0, 0x12(%eax)");
597 asm volatile("bndmov %bnd0, 0x12(%ebp)");
598 asm volatile("bndmov %bnd0, 0x12(%ecx,%eax,1)");
599 asm volatile("bndmov %bnd0, 0x12(%ebp,%eax,1)");
600 asm volatile("bndmov %bnd0, 0x12(%eax,%ecx,1)");
601 asm volatile("bndmov %bnd0, 0x12(%eax,%ecx,8)");
602 asm volatile("bndmov %bnd0, 0x12345678(%eax)");
603 asm volatile("bndmov %bnd0, 0x12345678(%ebp)");
604 asm volatile("bndmov %bnd0, 0x12345678(%ecx,%eax,1)");
605 asm volatile("bndmov %bnd0, 0x12345678(%ebp,%eax,1)");
606 asm volatile("bndmov %bnd0, 0x12345678(%eax,%ecx,1)");
607 asm volatile("bndmov %bnd0, 0x12345678(%eax,%ecx,8)");
608
609 /* bndmov bnd2, bnd1 */
610
611 asm volatile("bndmov %bnd0, %bnd1");
612 asm volatile("bndmov %bnd1, %bnd0");
613
614 /* bndldx mib, bnd */
615
616 asm volatile("bndldx (%eax), %bnd0");
617 asm volatile("bndldx (0x12345678), %bnd0");
618 asm volatile("bndldx (%eax), %bnd3");
619 asm volatile("bndldx (%ecx,%eax,1), %bnd0");
620 asm volatile("bndldx 0x12345678(,%eax,1), %bnd0");
621 asm volatile("bndldx (%eax,%ecx,1), %bnd0");
622 asm volatile("bndldx 0x12(%eax), %bnd0");
623 asm volatile("bndldx 0x12(%ebp), %bnd0");
624 asm volatile("bndldx 0x12(%ecx,%eax,1), %bnd0");
625 asm volatile("bndldx 0x12(%ebp,%eax,1), %bnd0");
626 asm volatile("bndldx 0x12(%eax,%ecx,1), %bnd0");
627 asm volatile("bndldx 0x12345678(%eax), %bnd0");
628 asm volatile("bndldx 0x12345678(%ebp), %bnd0");
629 asm volatile("bndldx 0x12345678(%ecx,%eax,1), %bnd0");
630 asm volatile("bndldx 0x12345678(%ebp,%eax,1), %bnd0");
631 asm volatile("bndldx 0x12345678(%eax,%ecx,1), %bnd0");
632
633 /* bndstx bnd, mib */
634
635 asm volatile("bndstx %bnd0, (%eax)");
636 asm volatile("bndstx %bnd0, (0x12345678)");
637 asm volatile("bndstx %bnd3, (%eax)");
638 asm volatile("bndstx %bnd0, (%ecx,%eax,1)");
639 asm volatile("bndstx %bnd0, 0x12345678(,%eax,1)");
640 asm volatile("bndstx %bnd0, (%eax,%ecx,1)");
641 asm volatile("bndstx %bnd0, 0x12(%eax)");
642 asm volatile("bndstx %bnd0, 0x12(%ebp)");
643 asm volatile("bndstx %bnd0, 0x12(%ecx,%eax,1)");
644 asm volatile("bndstx %bnd0, 0x12(%ebp,%eax,1)");
645 asm volatile("bndstx %bnd0, 0x12(%eax,%ecx,1)");
646 asm volatile("bndstx %bnd0, 0x12345678(%eax)");
647 asm volatile("bndstx %bnd0, 0x12345678(%ebp)");
648 asm volatile("bndstx %bnd0, 0x12345678(%ecx,%eax,1)");
649 asm volatile("bndstx %bnd0, 0x12345678(%ebp,%eax,1)");
650 asm volatile("bndstx %bnd0, 0x12345678(%eax,%ecx,1)");
651
652 /* bnd prefix on call, ret, jmp and all jcc */
653
654 asm volatile("bnd call label1"); /* Expecting: call unconditional 0xfffffffc */
655 asm volatile("bnd call *(%eax)"); /* Expecting: call indirect 0 */
656 asm volatile("bnd ret"); /* Expecting: ret indirect 0 */
657 asm volatile("bnd jmp label1"); /* Expecting: jmp unconditional 0xfffffffc */
658 asm volatile("bnd jmp label1"); /* Expecting: jmp unconditional 0xfffffffc */
659 asm volatile("bnd jmp *(%ecx)"); /* Expecting: jmp indirect 0 */
660 asm volatile("bnd jne label1"); /* Expecting: jcc conditional 0xfffffffc */
661
662 /* sha1rnds4 imm8, xmm2/m128, xmm1 */
663
664 asm volatile("sha1rnds4 $0x0, %xmm1, %xmm0");
665 asm volatile("sha1rnds4 $0x91, %xmm7, %xmm2");
666 asm volatile("sha1rnds4 $0x91, (%eax), %xmm0");
667 asm volatile("sha1rnds4 $0x91, (0x12345678), %xmm0");
668 asm volatile("sha1rnds4 $0x91, (%eax), %xmm3");
669 asm volatile("sha1rnds4 $0x91, (%ecx,%eax,1), %xmm0");
670 asm volatile("sha1rnds4 $0x91, 0x12345678(,%eax,1), %xmm0");
671 asm volatile("sha1rnds4 $0x91, (%eax,%ecx,1), %xmm0");
672 asm volatile("sha1rnds4 $0x91, (%eax,%ecx,8), %xmm0");
673 asm volatile("sha1rnds4 $0x91, 0x12(%eax), %xmm0");
674 asm volatile("sha1rnds4 $0x91, 0x12(%ebp), %xmm0");
675 asm volatile("sha1rnds4 $0x91, 0x12(%ecx,%eax,1), %xmm0");
676 asm volatile("sha1rnds4 $0x91, 0x12(%ebp,%eax,1), %xmm0");
677 asm volatile("sha1rnds4 $0x91, 0x12(%eax,%ecx,1), %xmm0");
678 asm volatile("sha1rnds4 $0x91, 0x12(%eax,%ecx,8), %xmm0");
679 asm volatile("sha1rnds4 $0x91, 0x12345678(%eax), %xmm0");
680 asm volatile("sha1rnds4 $0x91, 0x12345678(%ebp), %xmm0");
681 asm volatile("sha1rnds4 $0x91, 0x12345678(%ecx,%eax,1), %xmm0");
682 asm volatile("sha1rnds4 $0x91, 0x12345678(%ebp,%eax,1), %xmm0");
683 asm volatile("sha1rnds4 $0x91, 0x12345678(%eax,%ecx,1), %xmm0");
684 asm volatile("sha1rnds4 $0x91, 0x12345678(%eax,%ecx,8), %xmm0");
685
686 /* sha1nexte xmm2/m128, xmm1 */
687
688 asm volatile("sha1nexte %xmm1, %xmm0");
689 asm volatile("sha1nexte %xmm7, %xmm2");
690 asm volatile("sha1nexte (%eax), %xmm0");
691 asm volatile("sha1nexte (0x12345678), %xmm0");
692 asm volatile("sha1nexte (%eax), %xmm3");
693 asm volatile("sha1nexte (%ecx,%eax,1), %xmm0");
694 asm volatile("sha1nexte 0x12345678(,%eax,1), %xmm0");
695 asm volatile("sha1nexte (%eax,%ecx,1), %xmm0");
696 asm volatile("sha1nexte (%eax,%ecx,8), %xmm0");
697 asm volatile("sha1nexte 0x12(%eax), %xmm0");
698 asm volatile("sha1nexte 0x12(%ebp), %xmm0");
699 asm volatile("sha1nexte 0x12(%ecx,%eax,1), %xmm0");
700 asm volatile("sha1nexte 0x12(%ebp,%eax,1), %xmm0");
701 asm volatile("sha1nexte 0x12(%eax,%ecx,1), %xmm0");
702 asm volatile("sha1nexte 0x12(%eax,%ecx,8), %xmm0");
703 asm volatile("sha1nexte 0x12345678(%eax), %xmm0");
704 asm volatile("sha1nexte 0x12345678(%ebp), %xmm0");
705 asm volatile("sha1nexte 0x12345678(%ecx,%eax,1), %xmm0");
706 asm volatile("sha1nexte 0x12345678(%ebp,%eax,1), %xmm0");
707 asm volatile("sha1nexte 0x12345678(%eax,%ecx,1), %xmm0");
708 asm volatile("sha1nexte 0x12345678(%eax,%ecx,8), %xmm0");
709
710 /* sha1msg1 xmm2/m128, xmm1 */
711
712 asm volatile("sha1msg1 %xmm1, %xmm0");
713 asm volatile("sha1msg1 %xmm7, %xmm2");
714 asm volatile("sha1msg1 (%eax), %xmm0");
715 asm volatile("sha1msg1 (0x12345678), %xmm0");
716 asm volatile("sha1msg1 (%eax), %xmm3");
717 asm volatile("sha1msg1 (%ecx,%eax,1), %xmm0");
718 asm volatile("sha1msg1 0x12345678(,%eax,1), %xmm0");
719 asm volatile("sha1msg1 (%eax,%ecx,1), %xmm0");
720 asm volatile("sha1msg1 (%eax,%ecx,8), %xmm0");
721 asm volatile("sha1msg1 0x12(%eax), %xmm0");
722 asm volatile("sha1msg1 0x12(%ebp), %xmm0");
723 asm volatile("sha1msg1 0x12(%ecx,%eax,1), %xmm0");
724 asm volatile("sha1msg1 0x12(%ebp,%eax,1), %xmm0");
725 asm volatile("sha1msg1 0x12(%eax,%ecx,1), %xmm0");
726 asm volatile("sha1msg1 0x12(%eax,%ecx,8), %xmm0");
727 asm volatile("sha1msg1 0x12345678(%eax), %xmm0");
728 asm volatile("sha1msg1 0x12345678(%ebp), %xmm0");
729 asm volatile("sha1msg1 0x12345678(%ecx,%eax,1), %xmm0");
730 asm volatile("sha1msg1 0x12345678(%ebp,%eax,1), %xmm0");
731 asm volatile("sha1msg1 0x12345678(%eax,%ecx,1), %xmm0");
732 asm volatile("sha1msg1 0x12345678(%eax,%ecx,8), %xmm0");
733
734 /* sha1msg2 xmm2/m128, xmm1 */
735
736 asm volatile("sha1msg2 %xmm1, %xmm0");
737 asm volatile("sha1msg2 %xmm7, %xmm2");
738 asm volatile("sha1msg2 (%eax), %xmm0");
739 asm volatile("sha1msg2 (0x12345678), %xmm0");
740 asm volatile("sha1msg2 (%eax), %xmm3");
741 asm volatile("sha1msg2 (%ecx,%eax,1), %xmm0");
742 asm volatile("sha1msg2 0x12345678(,%eax,1), %xmm0");
743 asm volatile("sha1msg2 (%eax,%ecx,1), %xmm0");
744 asm volatile("sha1msg2 (%eax,%ecx,8), %xmm0");
745 asm volatile("sha1msg2 0x12(%eax), %xmm0");
746 asm volatile("sha1msg2 0x12(%ebp), %xmm0");
747 asm volatile("sha1msg2 0x12(%ecx,%eax,1), %xmm0");
748 asm volatile("sha1msg2 0x12(%ebp,%eax,1), %xmm0");
749 asm volatile("sha1msg2 0x12(%eax,%ecx,1), %xmm0");
750 asm volatile("sha1msg2 0x12(%eax,%ecx,8), %xmm0");
751 asm volatile("sha1msg2 0x12345678(%eax), %xmm0");
752 asm volatile("sha1msg2 0x12345678(%ebp), %xmm0");
753 asm volatile("sha1msg2 0x12345678(%ecx,%eax,1), %xmm0");
754 asm volatile("sha1msg2 0x12345678(%ebp,%eax,1), %xmm0");
755 asm volatile("sha1msg2 0x12345678(%eax,%ecx,1), %xmm0");
756 asm volatile("sha1msg2 0x12345678(%eax,%ecx,8), %xmm0");
757
758 /* sha256rnds2 <XMM0>, xmm2/m128, xmm1 */
759 /* Note sha256rnds2 has an implicit operand 'xmm0' */
760
761 asm volatile("sha256rnds2 %xmm4, %xmm1");
762 asm volatile("sha256rnds2 %xmm7, %xmm2");
763 asm volatile("sha256rnds2 (%eax), %xmm1");
764 asm volatile("sha256rnds2 (0x12345678), %xmm1");
765 asm volatile("sha256rnds2 (%eax), %xmm3");
766 asm volatile("sha256rnds2 (%ecx,%eax,1), %xmm1");
767 asm volatile("sha256rnds2 0x12345678(,%eax,1), %xmm1");
768 asm volatile("sha256rnds2 (%eax,%ecx,1), %xmm1");
769 asm volatile("sha256rnds2 (%eax,%ecx,8), %xmm1");
770 asm volatile("sha256rnds2 0x12(%eax), %xmm1");
771 asm volatile("sha256rnds2 0x12(%ebp), %xmm1");
772 asm volatile("sha256rnds2 0x12(%ecx,%eax,1), %xmm1");
773 asm volatile("sha256rnds2 0x12(%ebp,%eax,1), %xmm1");
774 asm volatile("sha256rnds2 0x12(%eax,%ecx,1), %xmm1");
775 asm volatile("sha256rnds2 0x12(%eax,%ecx,8), %xmm1");
776 asm volatile("sha256rnds2 0x12345678(%eax), %xmm1");
777 asm volatile("sha256rnds2 0x12345678(%ebp), %xmm1");
778 asm volatile("sha256rnds2 0x12345678(%ecx,%eax,1), %xmm1");
779 asm volatile("sha256rnds2 0x12345678(%ebp,%eax,1), %xmm1");
780 asm volatile("sha256rnds2 0x12345678(%eax,%ecx,1), %xmm1");
781 asm volatile("sha256rnds2 0x12345678(%eax,%ecx,8), %xmm1");
782
783 /* sha256msg1 xmm2/m128, xmm1 */
784
785 asm volatile("sha256msg1 %xmm1, %xmm0");
786 asm volatile("sha256msg1 %xmm7, %xmm2");
787 asm volatile("sha256msg1 (%eax), %xmm0");
788 asm volatile("sha256msg1 (0x12345678), %xmm0");
789 asm volatile("sha256msg1 (%eax), %xmm3");
790 asm volatile("sha256msg1 (%ecx,%eax,1), %xmm0");
791 asm volatile("sha256msg1 0x12345678(,%eax,1), %xmm0");
792 asm volatile("sha256msg1 (%eax,%ecx,1), %xmm0");
793 asm volatile("sha256msg1 (%eax,%ecx,8), %xmm0");
794 asm volatile("sha256msg1 0x12(%eax), %xmm0");
795 asm volatile("sha256msg1 0x12(%ebp), %xmm0");
796 asm volatile("sha256msg1 0x12(%ecx,%eax,1), %xmm0");
797 asm volatile("sha256msg1 0x12(%ebp,%eax,1), %xmm0");
798 asm volatile("sha256msg1 0x12(%eax,%ecx,1), %xmm0");
799 asm volatile("sha256msg1 0x12(%eax,%ecx,8), %xmm0");
800 asm volatile("sha256msg1 0x12345678(%eax), %xmm0");
801 asm volatile("sha256msg1 0x12345678(%ebp), %xmm0");
802 asm volatile("sha256msg1 0x12345678(%ecx,%eax,1), %xmm0");
803 asm volatile("sha256msg1 0x12345678(%ebp,%eax,1), %xmm0");
804 asm volatile("sha256msg1 0x12345678(%eax,%ecx,1), %xmm0");
805 asm volatile("sha256msg1 0x12345678(%eax,%ecx,8), %xmm0");
806
807 /* sha256msg2 xmm2/m128, xmm1 */
808
809 asm volatile("sha256msg2 %xmm1, %xmm0");
810 asm volatile("sha256msg2 %xmm7, %xmm2");
811 asm volatile("sha256msg2 (%eax), %xmm0");
812 asm volatile("sha256msg2 (0x12345678), %xmm0");
813 asm volatile("sha256msg2 (%eax), %xmm3");
814 asm volatile("sha256msg2 (%ecx,%eax,1), %xmm0");
815 asm volatile("sha256msg2 0x12345678(,%eax,1), %xmm0");
816 asm volatile("sha256msg2 (%eax,%ecx,1), %xmm0");
817 asm volatile("sha256msg2 (%eax,%ecx,8), %xmm0");
818 asm volatile("sha256msg2 0x12(%eax), %xmm0");
819 asm volatile("sha256msg2 0x12(%ebp), %xmm0");
820 asm volatile("sha256msg2 0x12(%ecx,%eax,1), %xmm0");
821 asm volatile("sha256msg2 0x12(%ebp,%eax,1), %xmm0");
822 asm volatile("sha256msg2 0x12(%eax,%ecx,1), %xmm0");
823 asm volatile("sha256msg2 0x12(%eax,%ecx,8), %xmm0");
824 asm volatile("sha256msg2 0x12345678(%eax), %xmm0");
825 asm volatile("sha256msg2 0x12345678(%ebp), %xmm0");
826 asm volatile("sha256msg2 0x12345678(%ecx,%eax,1), %xmm0");
827 asm volatile("sha256msg2 0x12345678(%ebp,%eax,1), %xmm0");
828 asm volatile("sha256msg2 0x12345678(%eax,%ecx,1), %xmm0");
829 asm volatile("sha256msg2 0x12345678(%eax,%ecx,8), %xmm0");
830
831 /* clflushopt m8 */
832
833 asm volatile("clflushopt (%eax)");
834 asm volatile("clflushopt (0x12345678)");
835 asm volatile("clflushopt 0x12345678(%eax,%ecx,8)");
836 /* Also check instructions in the same group encoding as clflushopt */
837 asm volatile("clflush (%eax)");
838 asm volatile("sfence");
839
840 /* clwb m8 */
841
842 asm volatile("clwb (%eax)");
843 asm volatile("clwb (0x12345678)");
844 asm volatile("clwb 0x12345678(%eax,%ecx,8)");
845 /* Also check instructions in the same group encoding as clwb */
846 asm volatile("xsaveopt (%eax)");
847 asm volatile("mfence");
848
849 /* xsavec mem */
850
851 asm volatile("xsavec (%eax)");
852 asm volatile("xsavec (0x12345678)");
853 asm volatile("xsavec 0x12345678(%eax,%ecx,8)");
854
855 /* xsaves mem */
856
857 asm volatile("xsaves (%eax)");
858 asm volatile("xsaves (0x12345678)");
859 asm volatile("xsaves 0x12345678(%eax,%ecx,8)");
860
861 /* xrstors mem */
862
863 asm volatile("xrstors (%eax)");
864 asm volatile("xrstors (0x12345678)");
865 asm volatile("xrstors 0x12345678(%eax,%ecx,8)");
866
867#endif /* #ifndef __x86_64__ */
868
869 /* pcommit */
870
871 asm volatile("pcommit");
872
873 /* Following line is a marker for the awk script - do not change */
874 asm volatile("rdtsc"); /* Stop here */
875
876 return 0;
877}
tools/perf/arch/x86/tests/insn-x86.c+185−0
@@ -0,0 +1,185 @@
1#include <linux/types.h>
2
3#include "debug.h"
4#include "tests/tests.h"
5#include "arch-tests.h"
6
7#include "intel-pt-decoder/insn.h"
8#include "intel-pt-decoder/intel-pt-insn-decoder.h"
9
10struct test_data {
11 u8 data[MAX_INSN_SIZE];
12 int expected_length;
13 int expected_rel;
14 const char *expected_op_str;
15 const char *expected_branch_str;
16 const char *asm_rep;
17};
18
19struct test_data test_data_32[] = {
20#include "insn-x86-dat-32.c"
21 {{0x0f, 0x01, 0xee}, 3, 0, NULL, NULL, "0f 01 ee \trdpkru"},
22 {{0x0f, 0x01, 0xef}, 3, 0, NULL, NULL, "0f 01 ef \twrpkru"},
23 {{0}, 0, 0, NULL, NULL, NULL},
24};
25
26struct test_data test_data_64[] = {
27#include "insn-x86-dat-64.c"
28 {{0x0f, 0x01, 0xee}, 3, 0, NULL, NULL, "0f 01 ee \trdpkru"},
29 {{0x0f, 0x01, 0xef}, 3, 0, NULL, NULL, "0f 01 ef \twrpkru"},
30 {{0}, 0, 0, NULL, NULL, NULL},
31};
32
33static int get_op(const char *op_str)
34{
35 struct val_data {
36 const char *name;
37 int val;
38 } vals[] = {
39 {"other", INTEL_PT_OP_OTHER},
40 {"call", INTEL_PT_OP_CALL},
41 {"ret", INTEL_PT_OP_RET},
42 {"jcc", INTEL_PT_OP_JCC},
43 {"jmp", INTEL_PT_OP_JMP},
44 {"loop", INTEL_PT_OP_LOOP},
45 {"iret", INTEL_PT_OP_IRET},
46 {"int", INTEL_PT_OP_INT},
47 {"syscall", INTEL_PT_OP_SYSCALL},
48 {"sysret", INTEL_PT_OP_SYSRET},
49 {NULL, 0},
50 };
51 struct val_data *val;
52
53 if (!op_str || !strlen(op_str))
54 return 0;
55
56 for (val = vals; val->name; val++) {
57 if (!strcmp(val->name, op_str))
58 return val->val;
59 }
60
61 pr_debug("Failed to get op\n");
62
63 return -1;
64}
65
66static int get_branch(const char *branch_str)
67{
68 struct val_data {
69 const char *name;
70 int val;
71 } vals[] = {
72 {"no_branch", INTEL_PT_BR_NO_BRANCH},
73 {"indirect", INTEL_PT_BR_INDIRECT},
74 {"conditional", INTEL_PT_BR_CONDITIONAL},
75 {"unconditional", INTEL_PT_BR_UNCONDITIONAL},
76 {NULL, 0},
77 };
78 struct val_data *val;
79
80 if (!branch_str || !strlen(branch_str))
81 return 0;
82
83 for (val = vals; val->name; val++) {
84 if (!strcmp(val->name, branch_str))
85 return val->val;
86 }
87
88 pr_debug("Failed to get branch\n");
89
90 return -1;
91}
92
93static int test_data_item(struct test_data *dat, int x86_64)
94{
95 struct intel_pt_insn intel_pt_insn;
96 struct insn insn;
97 int op, branch;
98
99 insn_init(&insn, dat->data, MAX_INSN_SIZE, x86_64);
100 insn_get_length(&insn);
101
102 if (!insn_complete(&insn)) {
103 pr_debug("Failed to decode: %s\n", dat->asm_rep);
104 return -1;
105 }
106
107 if (insn.length != dat->expected_length) {
108 pr_debug("Failed to decode length (%d vs expected %d): %s\n",
109 insn.length, dat->expected_length, dat->asm_rep);
110 return -1;
111 }
112
113 op = get_op(dat->expected_op_str);
114 branch = get_branch(dat->expected_branch_str);
115
116 if (intel_pt_get_insn(dat->data, MAX_INSN_SIZE, x86_64, &intel_pt_insn)) {
117 pr_debug("Intel PT failed to decode: %s\n", dat->asm_rep);
118 return -1;
119 }
120
121 if ((int)intel_pt_insn.op != op) {
122 pr_debug("Failed to decode 'op' value (%d vs expected %d): %s\n",
123 intel_pt_insn.op, op, dat->asm_rep);
124 return -1;
125 }
126
127 if ((int)intel_pt_insn.branch != branch) {
128 pr_debug("Failed to decode 'branch' value (%d vs expected %d): %s\n",
129 intel_pt_insn.branch, branch, dat->asm_rep);
130 return -1;
131 }
132
133 if (intel_pt_insn.rel != dat->expected_rel) {
134 pr_debug("Failed to decode 'rel' value (%#x vs expected %#x): %s\n",
135 intel_pt_insn.rel, dat->expected_rel, dat->asm_rep);
136 return -1;
137 }
138
139 pr_debug("Decoded ok: %s\n", dat->asm_rep);
140
141 return 0;
142}
143
144static int test_data_set(struct test_data *dat_set, int x86_64)
145{
146 struct test_data *dat;
147 int ret = 0;
148
149 for (dat = dat_set; dat->expected_length; dat++) {
150 if (test_data_item(dat, x86_64))
151 ret = -1;
152 }
153
154 return ret;
155}
156
157/**
158 * test__insn_x86 - test x86 instruction decoder - new instructions.
159 *
160 * This function implements a test that decodes a selection of instructions and
161 * checks the results. The Intel PT function that further categorizes
162 * instructions (i.e. intel_pt_get_insn()) is also checked.
163 *
164 * The instructions are originally in insn-x86-dat-src.c which has been
165 * processed by scripts gen-insn-x86-dat.sh and gen-insn-x86-dat.awk to produce
166 * insn-x86-dat-32.c and insn-x86-dat-64.c which are included into this program.
167 * i.e. to add new instructions to the test, edit insn-x86-dat-src.c, run the
168 * gen-insn-x86-dat.sh script, make perf, and then run the test.
169 *
170 * If the test passes %0 is returned, otherwise %-1 is returned. Use the
171 * verbose (-v) option to see all the instructions and whether or not they
172 * decoded successfuly.
173 */
174int test__insn_x86(void)
175{
176 int ret = 0;
177
178 if (test_data_set(test_data_32, 0))
179 ret = -1;
180
181 if (test_data_set(test_data_64, 1))
182 ret = -1;
183
184 return ret;
185}
tools/perf/arch/x86/tests/intel-cqm.c+124−0
@@ -0,0 +1,124 @@
1#include "tests/tests.h"
2#include "perf.h"
3#include "cloexec.h"
4#include "debug.h"
5#include "evlist.h"
6#include "evsel.h"
7#include "arch-tests.h"
8
9#include <sys/mman.h>
10#include <string.h>
11
12static pid_t spawn(void)
13{
14 pid_t pid;
15
16 pid = fork();
17 if (pid)
18 return pid;
19
20 while(1);
21 sleep(5);
22 return 0;
23}
24
25/*
26 * Create an event group that contains both a sampled hardware
27 * (cpu-cycles) and software (intel_cqm/llc_occupancy/) event. We then
28 * wait for the hardware perf counter to overflow and generate a PMI,
29 * which triggers an event read for both of the events in the group.
30 *
31 * Since reading Intel CQM event counters requires sending SMP IPIs, the
32 * CQM pmu needs to handle the above situation gracefully, and return
33 * the last read counter value to avoid triggering a WARN_ON_ONCE() in
34 * smp_call_function_many() caused by sending IPIs from NMI context.
35 */
36int test__intel_cqm_count_nmi_context(void)
37{
38 struct perf_evlist *evlist = NULL;
39 struct perf_evsel *evsel = NULL;
40 struct perf_event_attr pe;
41 int i, fd[2], flag, ret;
42 size_t mmap_len;
43 void *event;
44 pid_t pid;
45 int err = TEST_FAIL;
46
47 flag = perf_event_open_cloexec_flag();
48
49 evlist = perf_evlist__new();
50 if (!evlist) {
51 pr_debug("perf_evlist__new failed\n");
52 return TEST_FAIL;
53 }
54
55 ret = parse_events(evlist, "intel_cqm/llc_occupancy/", NULL);
56 if (ret) {
57 pr_debug("parse_events failed\n");
58 err = TEST_SKIP;
59 goto out;
60 }
61
62 evsel = perf_evlist__first(evlist);
63 if (!evsel) {
64 pr_debug("perf_evlist__first failed\n");
65 goto out;
66 }
67
68 memset(&pe, 0, sizeof(pe));
69 pe.size = sizeof(pe);
70
71 pe.type = PERF_TYPE_HARDWARE;
72 pe.config = PERF_COUNT_HW_CPU_CYCLES;
73 pe.read_format = PERF_FORMAT_GROUP;
74
75 pe.sample_period = 128;
76 pe.sample_type = PERF_SAMPLE_IP | PERF_SAMPLE_READ;
77
78 pid = spawn();
79
80 fd[0] = sys_perf_event_open(&pe, pid, -1, -1, flag);
81 if (fd[0] < 0) {
82 pr_debug("failed to open event\n");
83 goto out;
84 }
85
86 memset(&pe, 0, sizeof(pe));
87 pe.size = sizeof(pe);
88
89 pe.type = evsel->attr.type;
90 pe.config = evsel->attr.config;
91
92 fd[1] = sys_perf_event_open(&pe, pid, -1, fd[0], flag);
93 if (fd[1] < 0) {
94 pr_debug("failed to open event\n");
95 goto out;
96 }
97
98 /*
99 * Pick a power-of-two number of pages + 1 for the meta-data
100 * page (struct perf_event_mmap_page). See tools/perf/design.txt.
101 */
102 mmap_len = page_size * 65;
103
104 event = mmap(NULL, mmap_len, PROT_READ, MAP_SHARED, fd[0], 0);
105 if (event == (void *)(-1)) {
106 pr_debug("failed to mmap %d\n", errno);
107 goto out;
108 }
109
110 sleep(1);
111
112 err = TEST_OK;
113
114 munmap(event, mmap_len);
115
116 for (i = 0; i < 2; i++)
117 close(fd[i]);
118
119 kill(pid, SIGKILL);
120 wait(NULL);
121out:
122 perf_evlist__delete(evlist);
123 return err;
124}
tools/perf/arch/x86/tests/perf-time-to-tsc.crenamed from tools/perf/tests/perf-time-to-tsc.c+3−1
@@ -9,7 +9,9 @@ · 8 unmodified lines
9#include "thread_map.h"9#include "thread_map.h"
10#include "cpumap.h"10#include "cpumap.h"
11#include "tsc.h"11#include "tsc.h"
12#include "tests.h"12#include "tests/tests.h"
13
14#include "arch-tests.h"
13 15
14#define CHECK__(x) { \16#define CHECK__(x) { \
15 while ((x) < 0) { \17 while ((x) < 0) { \
tools/perf/arch/x86/tests/rdpmc.crenamed from tools/perf/tests/rdpmc.c+2−5
@@ -5,10 +5,9 @@ · 4 unmodified lines
5#include <linux/types.h>5#include <linux/types.h>
6#include "perf.h"6#include "perf.h"
7#include "debug.h"7#include "debug.h"
8#include "tests.h"8#include "tests/tests.h"
9#include "cloexec.h"9#include "cloexec.h"
10 10#include "arch-tests.h"
11#if defined(__x86_64__) || defined(__i386__)
12 11
13static u64 rdpmc(unsigned int counter)12static u64 rdpmc(unsigned int counter)
14{13{
@@ -173,5 +172,3 @@ int test__rdpmc(void) · 158 unmodified lines
173 172
174 return 0;173 return 0;
175}174}
176
177#endif
tools/perf/arch/x86/util/dwarf-regs.c+88−34
@@ -21,55 +21,109 @@ · 20 unmodified lines
21 */21 */
22 22
23#include <stddef.h>23#include <stddef.h>
24#include <errno.h> /* for EINVAL */
25#include <string.h> /* for strcmp */
26#include <linux/ptrace.h> /* for struct pt_regs */
27#include <linux/kernel.h> /* for offsetof */
24#include <dwarf-regs.h>28#include <dwarf-regs.h>
25 29
26/*30/*
27 * Generic dwarf analysis helpers31 * See arch/x86/kernel/ptrace.c.
32 * Different from it:
33 *
34 * - Since struct pt_regs is defined differently for user and kernel,
35 * but we want to use 'ax, bx' instead of 'rax, rbx' (which is struct
36 * field name of user's pt_regs), we make REG_OFFSET_NAME to accept
37 * both string name and reg field name.
38 *
39 * - Since accessing x86_32's pt_regs from x86_64 building is difficult
40 * and vise versa, we simply fill offset with -1, so
41 * get_arch_regstr() still works but regs_query_register_offset()
42 * returns error.
43 * The only inconvenience caused by it now is that we are not allowed
44 * to generate BPF prologue for a x86_64 kernel if perf is built for
45 * x86_32. This is really a rare usecase.
46 *
47 * - Order is different from kernel's ptrace.c for get_arch_regstr(). Use
48 * the order defined by dwarf.
28 */49 */
29 50
30#define X86_32_MAX_REGS 851struct pt_regs_offset {
31const char *x86_32_regs_table[X86_32_MAX_REGS] = {52 const char *name;
32 "%ax",53 int offset;
33 "%cx",54};
34 "%dx",55
35 "%bx",56#define REG_OFFSET_END {.name = NULL, .offset = 0}
36 "$stack", /* Stack address instead of %sp */57
37 "%bp",58#ifdef __x86_64__
38 "%si",59# define REG_OFFSET_NAME_64(n, r) {.name = n, .offset = offsetof(struct pt_regs, r)}
39 "%di",60# define REG_OFFSET_NAME_32(n, r) {.name = n, .offset = -1}
61#else
62# define REG_OFFSET_NAME_64(n, r) {.name = n, .offset = -1}
63# define REG_OFFSET_NAME_32(n, r) {.name = n, .offset = offsetof(struct pt_regs, r)}
64#endif
65
66static const struct pt_regs_offset x86_32_regoffset_table[] = {
67 REG_OFFSET_NAME_32("%ax", eax),
68 REG_OFFSET_NAME_32("%cx", ecx),
69 REG_OFFSET_NAME_32("%dx", edx),
70 REG_OFFSET_NAME_32("%bx", ebx),
71 REG_OFFSET_NAME_32("$stack", esp), /* Stack address instead of %sp */
72 REG_OFFSET_NAME_32("%bp", ebp),
73 REG_OFFSET_NAME_32("%si", esi),
74 REG_OFFSET_NAME_32("%di", edi),
75 REG_OFFSET_END,
40};76};
41 77
42#define X86_64_MAX_REGS 1678static const struct pt_regs_offset x86_64_regoffset_table[] = {
43const char *x86_64_regs_table[X86_64_MAX_REGS] = {79 REG_OFFSET_NAME_64("%ax", rax),
44 "%ax",80 REG_OFFSET_NAME_64("%dx", rdx),
45 "%dx",81 REG_OFFSET_NAME_64("%cx", rcx),
46 "%cx",82 REG_OFFSET_NAME_64("%bx", rbx),
47 "%bx",83 REG_OFFSET_NAME_64("%si", rsi),
48 "%si",84 REG_OFFSET_NAME_64("%di", rdi),
49 "%di",85 REG_OFFSET_NAME_64("%bp", rbp),
50 "%bp",86 REG_OFFSET_NAME_64("%sp", rsp),
51 "%sp",87 REG_OFFSET_NAME_64("%r8", r8),
52 "%r8",88 REG_OFFSET_NAME_64("%r9", r9),
53 "%r9",89 REG_OFFSET_NAME_64("%r10", r10),
54 "%r10",90 REG_OFFSET_NAME_64("%r11", r11),
55 "%r11",91 REG_OFFSET_NAME_64("%r12", r12),
56 "%r12",92 REG_OFFSET_NAME_64("%r13", r13),
57 "%r13",93 REG_OFFSET_NAME_64("%r14", r14),
58 "%r14",94 REG_OFFSET_NAME_64("%r15", r15),
59 "%r15",95 REG_OFFSET_END,
60};96};
61 97
62/* TODO: switching by dwarf address size */98/* TODO: switching by dwarf address size */
63#ifdef __x86_64__99#ifdef __x86_64__
64#define ARCH_MAX_REGS X86_64_MAX_REGS100#define regoffset_table x86_64_regoffset_table
65#define arch_regs_table x86_64_regs_table
66#else101#else
67#define ARCH_MAX_REGS X86_32_MAX_REGS102#define regoffset_table x86_32_regoffset_table
68#define arch_regs_table x86_32_regs_table
69#endif103#endif
70 104
105/* Minus 1 for the ending REG_OFFSET_END */
106#define ARCH_MAX_REGS ((sizeof(regoffset_table) / sizeof(regoffset_table[0])) - 1)
107
71/* Return architecture dependent register string (for kprobe-tracer) */108/* Return architecture dependent register string (for kprobe-tracer) */
72const char *get_arch_regstr(unsigned int n)109const char *get_arch_regstr(unsigned int n)
73{110{
74 return (n < ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;111 return (n < ARCH_MAX_REGS) ? regoffset_table[n].name : NULL;
112}
113
114/* Reuse code from arch/x86/kernel/ptrace.c */
115/**
116 * regs_query_register_offset() - query register offset from its name
117 * @name: the name of a register
118 *
119 * regs_query_register_offset() returns the offset of a register in struct
120 * pt_regs from its name. If the name is invalid, this returns -EINVAL;
121 */
122int regs_query_register_offset(const char *name)
123{
124 const struct pt_regs_offset *roff;
125 for (roff = regoffset_table; roff->name != NULL; roff++)
126 if (!strcmp(roff->name, name))
127 return roff->offset;
128 return -EINVAL;
75}129}
tools/perf/arch/x86/util/intel-pt.c+47−8
@@ -624,13 +624,49 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, · 623 unmodified lines
624 * threads.624 * threads.
625 */625 */
626 if (have_timing_info && !cpu_map__empty(cpus)) {626 if (have_timing_info && !cpu_map__empty(cpus)) {
627 err = intel_pt_track_switches(evlist);627 if (perf_can_record_switch_events()) {
628 if (err == -EPERM)628 bool cpu_wide = !target__none(&opts->target) &&
629 pr_debug2("Unable to select sched:sched_switch\n");629 !target__has_task(&opts->target);
630 else if (err)630
631 return err;631 if (!cpu_wide && perf_can_record_cpu_wide()) {
632 else632 struct perf_evsel *switch_evsel;
633 ptr->have_sched_switch = 1;633
634 err = parse_events(evlist, "dummy:u", NULL);
635 if (err)
636 return err;
637
638 switch_evsel = perf_evlist__last(evlist);
639
640 switch_evsel->attr.freq = 0;
641 switch_evsel->attr.sample_period = 1;
642 switch_evsel->attr.context_switch = 1;
643
644 switch_evsel->system_wide = true;
645 switch_evsel->no_aux_samples = true;
646 switch_evsel->immediate = true;
647
648 perf_evsel__set_sample_bit(switch_evsel, TID);
649 perf_evsel__set_sample_bit(switch_evsel, TIME);
650 perf_evsel__set_sample_bit(switch_evsel, CPU);
651
652 opts->record_switch_events = false;
653 ptr->have_sched_switch = 3;
654 } else {
655 opts->record_switch_events = true;
656 if (cpu_wide)
657 ptr->have_sched_switch = 3;
658 else
659 ptr->have_sched_switch = 2;
660 }
661 } else {
662 err = intel_pt_track_switches(evlist);
663 if (err == -EPERM)
664 pr_debug2("Unable to select sched:sched_switch\n");
665 else if (err)
666 return err;
667 else
668 ptr->have_sched_switch = 1;
669 }
634 }670 }
635 671
636 if (intel_pt_evsel) {672 if (intel_pt_evsel) {
@@ -663,8 +699,11 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, · 26 unmodified lines
663 tracking_evsel->attr.sample_period = 1;699 tracking_evsel->attr.sample_period = 1;
664 700
665 /* In per-cpu case, always need the time of mmap events etc */701 /* In per-cpu case, always need the time of mmap events etc */
666 if (!cpu_map__empty(cpus))702 if (!cpu_map__empty(cpus)) {
667 perf_evsel__set_sample_bit(tracking_evsel, TIME);703 perf_evsel__set_sample_bit(tracking_evsel, TIME);
704 /* And the CPU for switch events */
705 perf_evsel__set_sample_bit(tracking_evsel, CPU);
706 }
668 }707 }
669 708
670 /*709 /*
tools/perf/bench/Build+1−1
@@ -1,6 +1,6 @@
1perf-y += sched-messaging.o1perf-y += sched-messaging.o
2perf-y += sched-pipe.o2perf-y += sched-pipe.o
3perf-y += mem-memcpy.o3perf-y += mem-functions.o
4perf-y += futex-hash.o4perf-y += futex-hash.o
5perf-y += futex-wake.o5perf-y += futex-wake.o
6perf-y += futex-wake-parallel.o6perf-y += futex-wake-parallel.o
tools/perf/bench/mem-functions.c+379−0
@@ -0,0 +1,379 @@
1/*
2 * mem-memcpy.c
3 *
4 * Simple memcpy() and memset() benchmarks
5 *
6 * Written by Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
7 */
8
9#include "../perf.h"
10#include "../util/util.h"
11#include "../util/parse-options.h"
12#include "../util/header.h"
13#include "../util/cloexec.h"
14#include "bench.h"
15#include "mem-memcpy-arch.h"
16#include "mem-memset-arch.h"
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <sys/time.h>
22#include <errno.h>
23
24#define K 1024
25
26static const char *size_str = "1MB";
27static const char *function_str = "all";
28static int nr_loops = 1;
29static bool use_cycles;
30static int cycles_fd;
31
32static const struct option options[] = {
33 OPT_STRING('s', "size", &size_str, "1MB",
34 "Specify the size of the memory buffers. "
35 "Available units: B, KB, MB, GB and TB (case insensitive)"),
36
37 OPT_STRING('f', "function", &function_str, "all",
38 "Specify the function to run, \"all\" runs all available functions, \"help\" lists them"),
39
40 OPT_INTEGER('l', "nr_loops", &nr_loops,
41 "Specify the number of loops to run. (default: 1)"),
42
43 OPT_BOOLEAN('c', "cycles", &use_cycles,
44 "Use a cycles event instead of gettimeofday() to measure performance"),
45
46 OPT_END()
47};
48
49typedef void *(*memcpy_t)(void *, const void *, size_t);
50typedef void *(*memset_t)(void *, int, size_t);
51
52struct function {
53 const char *name;
54 const char *desc;
55 union {
56 memcpy_t memcpy;
57 memset_t memset;
58 } fn;
59};
60
61static struct perf_event_attr cycle_attr = {
62 .type = PERF_TYPE_HARDWARE,
63 .config = PERF_COUNT_HW_CPU_CYCLES
64};
65
66static void init_cycles(void)
67{
68 cycles_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, perf_event_open_cloexec_flag());
69
70 if (cycles_fd < 0 && errno == ENOSYS)
71 die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
72 else
73 BUG_ON(cycles_fd < 0);
74}
75
76static u64 get_cycles(void)
77{
78 int ret;
79 u64 clk;
80
81 ret = read(cycles_fd, &clk, sizeof(u64));
82 BUG_ON(ret != sizeof(u64));
83
84 return clk;
85}
86
87static double timeval2double(struct timeval *ts)
88{
89 return (double)ts->tv_sec + (double)ts->tv_usec / (double)1000000;
90}
91
92#define print_bps(x) do { \
93 if (x < K) \
94 printf(" %14lf bytes/sec\n", x); \
95 else if (x < K * K) \
96 printf(" %14lfd KB/sec\n", x / K); \
97 else if (x < K * K * K) \
98 printf(" %14lf MB/sec\n", x / K / K); \
99 else \
100 printf(" %14lf GB/sec\n", x / K / K / K); \
101 } while (0)
102
103struct bench_mem_info {
104 const struct function *functions;
105 u64 (*do_cycles)(const struct function *r, size_t size);
106 double (*do_gettimeofday)(const struct function *r, size_t size);
107 const char *const *usage;
108};
109
110static void __bench_mem_function(struct bench_mem_info *info, int r_idx, size_t size, double size_total)
111{
112 const struct function *r = &info->functions[r_idx];
113 double result_bps = 0.0;
114 u64 result_cycles = 0;
115
116 printf("# function '%s' (%s)\n", r->name, r->desc);
117
118 if (bench_format == BENCH_FORMAT_DEFAULT)
119 printf("# Copying %s bytes ...\n\n", size_str);
120
121 if (use_cycles) {
122 result_cycles = info->do_cycles(r, size);
123 } else {
124 result_bps = info->do_gettimeofday(r, size);
125 }
126
127 switch (bench_format) {
128 case BENCH_FORMAT_DEFAULT:
129 if (use_cycles) {
130 printf(" %14lf cycles/byte\n", (double)result_cycles/size_total);
131 } else {
132 print_bps(result_bps);
133 }
134 break;
135
136 case BENCH_FORMAT_SIMPLE:
137 if (use_cycles) {
138 printf("%lf\n", (double)result_cycles/size_total);
139 } else {
140 printf("%lf\n", result_bps);
141 }
142 break;
143
144 default:
145 BUG_ON(1);
146 break;
147 }
148}
149
150static int bench_mem_common(int argc, const char **argv, struct bench_mem_info *info)
151{
152 int i;
153 size_t size;
154 double size_total;
155
156 argc = parse_options(argc, argv, options, info->usage, 0);
157
158 if (use_cycles)
159 init_cycles();
160
161 size = (size_t)perf_atoll((char *)size_str);
162 size_total = (double)size * nr_loops;
163
164 if ((s64)size <= 0) {
165 fprintf(stderr, "Invalid size:%s\n", size_str);
166 return 1;
167 }
168
169 if (!strncmp(function_str, "all", 3)) {
170 for (i = 0; info->functions[i].name; i++)
171 __bench_mem_function(info, i, size, size_total);
172 return 0;
173 }
174
175 for (i = 0; info->functions[i].name; i++) {
176 if (!strcmp(info->functions[i].name, function_str))
177 break;
178 }
179 if (!info->functions[i].name) {
180 if (strcmp(function_str, "help") && strcmp(function_str, "h"))
181 printf("Unknown function: %s\n", function_str);
182 printf("Available functions:\n");
183 for (i = 0; info->functions[i].name; i++) {
184 printf("\t%s ... %s\n",
185 info->functions[i].name, info->functions[i].desc);
186 }
187 return 1;
188 }
189
190 __bench_mem_function(info, i, size, size_total);
191
192 return 0;
193}
194
195static void memcpy_alloc_mem(void **dst, void **src, size_t size)
196{
197 *dst = zalloc(size);
198 if (!*dst)
199 die("memory allocation failed - maybe size is too large?\n");
200
201 *src = zalloc(size);
202 if (!*src)
203 die("memory allocation failed - maybe size is too large?\n");
204
205 /* Make sure to always prefault zero pages even if MMAP_THRESH is crossed: */
206 memset(*src, 0, size);
207}
208
209static u64 do_memcpy_cycles(const struct function *r, size_t size)
210{
211 u64 cycle_start = 0ULL, cycle_end = 0ULL;
212 void *src = NULL, *dst = NULL;
213 memcpy_t fn = r->fn.memcpy;
214 int i;
215
216 memcpy_alloc_mem(&dst, &src, size);
217
218 /*
219 * We prefault the freshly allocated memory range here,
220 * to not measure page fault overhead:
221 */
222 fn(dst, src, size);
223
224 cycle_start = get_cycles();
225 for (i = 0; i < nr_loops; ++i)
226 fn(dst, src, size);
227 cycle_end = get_cycles();
228
229 free(src);
230 free(dst);
231 return cycle_end - cycle_start;
232}
233
234static double do_memcpy_gettimeofday(const struct function *r, size_t size)
235{
236 struct timeval tv_start, tv_end, tv_diff;
237 memcpy_t fn = r->fn.memcpy;
238 void *src = NULL, *dst = NULL;
239 int i;
240
241 memcpy_alloc_mem(&dst, &src, size);
242
243 /*
244 * We prefault the freshly allocated memory range here,
245 * to not measure page fault overhead:
246 */
247 fn(dst, src, size);
248
249 BUG_ON(gettimeofday(&tv_start, NULL));
250 for (i = 0; i < nr_loops; ++i)
251 fn(dst, src, size);
252 BUG_ON(gettimeofday(&tv_end, NULL));
253
254 timersub(&tv_end, &tv_start, &tv_diff);
255
256 free(src);
257 free(dst);
258
259 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
260}
261
262struct function memcpy_functions[] = {
263 { .name = "default",
264 .desc = "Default memcpy() provided by glibc",
265 .fn.memcpy = memcpy },
266
267#ifdef HAVE_ARCH_X86_64_SUPPORT
268# define MEMCPY_FN(_fn, _name, _desc) {.name = _name, .desc = _desc, .fn.memcpy = _fn},
269# include "mem-memcpy-x86-64-asm-def.h"
270# undef MEMCPY_FN
271#endif
272
273 { .name = NULL, }
274};
275
276static const char * const bench_mem_memcpy_usage[] = {
277 "perf bench mem memcpy <options>",
278 NULL
279};
280
281int bench_mem_memcpy(int argc, const char **argv, const char *prefix __maybe_unused)
282{
283 struct bench_mem_info info = {
284 .functions = memcpy_functions,
285 .do_cycles = do_memcpy_cycles,
286 .do_gettimeofday = do_memcpy_gettimeofday,
287 .usage = bench_mem_memcpy_usage,
288 };
289
290 return bench_mem_common(argc, argv, &info);
291}
292
293static void memset_alloc_mem(void **dst, size_t size)
294{
295 *dst = zalloc(size);
296 if (!*dst)
297 die("memory allocation failed - maybe size is too large?\n");
298}
299
300static u64 do_memset_cycles(const struct function *r, size_t size)
301{
302 u64 cycle_start = 0ULL, cycle_end = 0ULL;
303 memset_t fn = r->fn.memset;
304 void *dst = NULL;
305 int i;
306
307 memset_alloc_mem(&dst, size);
308
309 /*
310 * We prefault the freshly allocated memory range here,
311 * to not measure page fault overhead:
312 */
313 fn(dst, -1, size);
314
315 cycle_start = get_cycles();
316 for (i = 0; i < nr_loops; ++i)
317 fn(dst, i, size);
318 cycle_end = get_cycles();
319
320 free(dst);
321 return cycle_end - cycle_start;
322}
323
324static double do_memset_gettimeofday(const struct function *r, size_t size)
325{
326 struct timeval tv_start, tv_end, tv_diff;
327 memset_t fn = r->fn.memset;
328 void *dst = NULL;
329 int i;
330
331 memset_alloc_mem(&dst, size);
332
333 /*
334 * We prefault the freshly allocated memory range here,
335 * to not measure page fault overhead:
336 */
337 fn(dst, -1, size);
338
339 BUG_ON(gettimeofday(&tv_start, NULL));
340 for (i = 0; i < nr_loops; ++i)
341 fn(dst, i, size);
342 BUG_ON(gettimeofday(&tv_end, NULL));
343
344 timersub(&tv_end, &tv_start, &tv_diff);
345
346 free(dst);
347 return (double)(((double)size * nr_loops) / timeval2double(&tv_diff));
348}
349
350static const char * const bench_mem_memset_usage[] = {
351 "perf bench mem memset <options>",
352 NULL
353};
354
355static const struct function memset_functions[] = {
356 { .name = "default",
357 .desc = "Default memset() provided by glibc",
358 .fn.memset = memset },
359
360#ifdef HAVE_ARCH_X86_64_SUPPORT
361# define MEMSET_FN(_fn, _name, _desc) { .name = _name, .desc = _desc, .fn.memset = _fn },
362# include "mem-memset-x86-64-asm-def.h"
363# undef MEMSET_FN
364#endif
365
366 { .name = NULL, }
367};
368
369int bench_mem_memset(int argc, const char **argv, const char *prefix __maybe_unused)
370{
371 struct bench_mem_info info = {
372 .functions = memset_functions,
373 .do_cycles = do_memset_cycles,
374 .do_gettimeofday = do_memset_gettimeofday,
375 .usage = bench_mem_memset_usage,
376 };
377
378 return bench_mem_common(argc, argv, &info);
379}
tools/perf/bench/mem-memcpy.c+0−434
@@ -1,434 +0,0 @@
1/*
2 * mem-memcpy.c
3 *
4 * memcpy: Simple memory copy in various ways
5 *
6 * Written by Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
7 */
8
9#include "../perf.h"
10#include "../util/util.h"
11#include "../util/parse-options.h"
12#include "../util/header.h"
13#include "../util/cloexec.h"
14#include "bench.h"
15#include "mem-memcpy-arch.h"
16#include "mem-memset-arch.h"
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <sys/time.h>
22#include <errno.h>
23
24#define K 1024
25
26static const char *length_str = "1MB";
27static const char *routine = "default";
28static int iterations = 1;
29static bool use_cycle;
30static int cycle_fd;
31static bool only_prefault;
32static bool no_prefault;
33
34static const struct option options[] = {
35 OPT_STRING('l', "length", &length_str, "1MB",
36 "Specify length of memory to copy. "
37 "Available units: B, KB, MB, GB and TB (upper and lower)"),
38 OPT_STRING('r', "routine", &routine, "default",
39 "Specify routine to copy, \"all\" runs all available routines"),
40 OPT_INTEGER('i', "iterations", &iterations,
41 "repeat memcpy() invocation this number of times"),
42 OPT_BOOLEAN('c', "cycle", &use_cycle,
43 "Use cycles event instead of gettimeofday() for measuring"),
44 OPT_BOOLEAN('o', "only-prefault", &only_prefault,
45 "Show only the result with page faults before memcpy()"),
46 OPT_BOOLEAN('n', "no-prefault", &no_prefault,
47 "Show only the result without page faults before memcpy()"),
48 OPT_END()
49};
50
51typedef void *(*memcpy_t)(void *, const void *, size_t);
52typedef void *(*memset_t)(void *, int, size_t);
53
54struct routine {
55 const char *name;
56 const char *desc;
57 union {
58 memcpy_t memcpy;
59 memset_t memset;
60 } fn;
61};
62
63struct routine memcpy_routines[] = {
64 { .name = "default",
65 .desc = "Default memcpy() provided by glibc",
66 .fn.memcpy = memcpy },
67#ifdef HAVE_ARCH_X86_64_SUPPORT
68
69#define MEMCPY_FN(_fn, _name, _desc) {.name = _name, .desc = _desc, .fn.memcpy = _fn},
70#include "mem-memcpy-x86-64-asm-def.h"
71#undef MEMCPY_FN
72
73#endif
74
75 { NULL,
76 NULL,
77 {NULL} }
78};
79
80static const char * const bench_mem_memcpy_usage[] = {
81 "perf bench mem memcpy <options>",
82 NULL
83};
84
85static struct perf_event_attr cycle_attr = {
86 .type = PERF_TYPE_HARDWARE,
87 .config = PERF_COUNT_HW_CPU_CYCLES
88};
89
90static void init_cycle(void)
91{
92 cycle_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1,
93 perf_event_open_cloexec_flag());
94
95 if (cycle_fd < 0 && errno == ENOSYS)
96 die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
97 else
98 BUG_ON(cycle_fd < 0);
99}
100
101static u64 get_cycle(void)
102{
103 int ret;
104 u64 clk;
105
106 ret = read(cycle_fd, &clk, sizeof(u64));
107 BUG_ON(ret != sizeof(u64));
108
109 return clk;
110}
111
112static double timeval2double(struct timeval *ts)
113{
114 return (double)ts->tv_sec +
115 (double)ts->tv_usec / (double)1000000;
116}
117
118#define pf (no_prefault ? 0 : 1)
119
120#define print_bps(x) do { \
121 if (x < K) \
122 printf(" %14lf B/Sec", x); \
123 else if (x < K * K) \
124 printf(" %14lfd KB/Sec", x / K); \
125 else if (x < K * K * K) \
126 printf(" %14lf MB/Sec", x / K / K); \
127 else \
128 printf(" %14lf GB/Sec", x / K / K / K); \
129 } while (0)
130
131struct bench_mem_info {
132 const struct routine *routines;
133 u64 (*do_cycle)(const struct routine *r, size_t len, bool prefault);
134 double (*do_gettimeofday)(const struct routine *r, size_t len, bool prefault);
135 const char *const *usage;
136};
137
138static void __bench_mem_routine(struct bench_mem_info *info, int r_idx, size_t len, double totallen)
139{
140 const struct routine *r = &info->routines[r_idx];
141 double result_bps[2];
142 u64 result_cycle[2];
143
144 result_cycle[0] = result_cycle[1] = 0ULL;
145 result_bps[0] = result_bps[1] = 0.0;
146
147 printf("Routine %s (%s)\n", r->name, r->desc);
148
149 if (bench_format == BENCH_FORMAT_DEFAULT)
150 printf("# Copying %s Bytes ...\n\n", length_str);
151
152 if (!only_prefault && !no_prefault) {
153 /* show both of results */
154 if (use_cycle) {
155 result_cycle[0] = info->do_cycle(r, len, false);
156 result_cycle[1] = info->do_cycle(r, len, true);
157 } else {
158 result_bps[0] = info->do_gettimeofday(r, len, false);
159 result_bps[1] = info->do_gettimeofday(r, len, true);
160 }
161 } else {
162 if (use_cycle)
163 result_cycle[pf] = info->do_cycle(r, len, only_prefault);
164 else
165 result_bps[pf] = info->do_gettimeofday(r, len, only_prefault);
166 }
167
168 switch (bench_format) {
169 case BENCH_FORMAT_DEFAULT:
170 if (!only_prefault && !no_prefault) {
171 if (use_cycle) {
172 printf(" %14lf Cycle/Byte\n",
173 (double)result_cycle[0]
174 / totallen);
175 printf(" %14lf Cycle/Byte (with prefault)\n",
176 (double)result_cycle[1]
177 / totallen);
178 } else {
179 print_bps(result_bps[0]);
180 printf("\n");
181 print_bps(result_bps[1]);
182 printf(" (with prefault)\n");
183 }
184 } else {
185 if (use_cycle) {
186 printf(" %14lf Cycle/Byte",
187 (double)result_cycle[pf]
188 / totallen);
189 } else
190 print_bps(result_bps[pf]);
191
192 printf("%s\n", only_prefault ? " (with prefault)" : "");
193 }
194 break;
195 case BENCH_FORMAT_SIMPLE:
196 if (!only_prefault && !no_prefault) {
197 if (use_cycle) {
198 printf("%lf %lf\n",
199 (double)result_cycle[0] / totallen,
200 (double)result_cycle[1] / totallen);
201 } else {
202 printf("%lf %lf\n",
203 result_bps[0], result_bps[1]);
204 }
205 } else {
206 if (use_cycle) {
207 printf("%lf\n", (double)result_cycle[pf]
208 / totallen);
209 } else
210 printf("%lf\n", result_bps[pf]);
211 }
212 break;
213 default:
214 /* reaching this means there's some disaster: */
215 die("unknown format: %d\n", bench_format);
216 break;
217 }
218}
219
220static int bench_mem_common(int argc, const char **argv,
221 const char *prefix __maybe_unused,
222 struct bench_mem_info *info)
223{
224 int i;
225 size_t len;
226 double totallen;
227
228 argc = parse_options(argc, argv, options,
229 info->usage, 0);
230
231 if (no_prefault && only_prefault) {
232 fprintf(stderr, "Invalid options: -o and -n are mutually exclusive\n");
233 return 1;
234 }
235
236 if (use_cycle)
237 init_cycle();
238
239 len = (size_t)perf_atoll((char *)length_str);
240 totallen = (double)len * iterations;
241
242 if ((s64)len <= 0) {
243 fprintf(stderr, "Invalid length:%s\n", length_str);
244 return 1;
245 }
246
247 /* same to without specifying either of prefault and no-prefault */
248 if (only_prefault && no_prefault)
249 only_prefault = no_prefault = false;
250
251 if (!strncmp(routine, "all", 3)) {
252 for (i = 0; info->routines[i].name; i++)
253 __bench_mem_routine(info, i, len, totallen);
254 return 0;
255 }
256
257 for (i = 0; info->routines[i].name; i++) {
258 if (!strcmp(info->routines[i].name, routine))
259 break;
260 }
261 if (!info->routines[i].name) {
262 printf("Unknown routine:%s\n", routine);
263 printf("Available routines...\n");
264 for (i = 0; info->routines[i].name; i++) {
265 printf("\t%s ... %s\n",
266 info->routines[i].name, info->routines[i].desc);
267 }
268 return 1;
269 }
270
271 __bench_mem_routine(info, i, len, totallen);
272
273 return 0;
274}
275
276static void memcpy_alloc_mem(void **dst, void **src, size_t length)
277{
278 *dst = zalloc(length);
279 if (!*dst)
280 die("memory allocation failed - maybe length is too large?\n");
281
282 *src = zalloc(length);
283 if (!*src)
284 die("memory allocation failed - maybe length is too large?\n");
285 /* Make sure to always replace the zero pages even if MMAP_THRESH is crossed */
286 memset(*src, 0, length);
287}
288
289static u64 do_memcpy_cycle(const struct routine *r, size_t len, bool prefault)
290{
291 u64 cycle_start = 0ULL, cycle_end = 0ULL;
292 void *src = NULL, *dst = NULL;
293 memcpy_t fn = r->fn.memcpy;
294 int i;
295
296 memcpy_alloc_mem(&dst, &src, len);
297
298 if (prefault)
299 fn(dst, src, len);
300
301 cycle_start = get_cycle();
302 for (i = 0; i < iterations; ++i)
303 fn(dst, src, len);
304 cycle_end = get_cycle();
305
306 free(src);
307 free(dst);
308 return cycle_end - cycle_start;
309}
310
311static double do_memcpy_gettimeofday(const struct routine *r, size_t len,
312 bool prefault)
313{
314 struct timeval tv_start, tv_end, tv_diff;
315 memcpy_t fn = r->fn.memcpy;
316 void *src = NULL, *dst = NULL;
317 int i;
318
319 memcpy_alloc_mem(&dst, &src, len);
320
321 if (prefault)
322 fn(dst, src, len);
323
324 BUG_ON(gettimeofday(&tv_start, NULL));
325 for (i = 0; i < iterations; ++i)
326 fn(dst, src, len);
327 BUG_ON(gettimeofday(&tv_end, NULL));
328
329 timersub(&tv_end, &tv_start, &tv_diff);
330
331 free(src);
332 free(dst);
333 return (double)(((double)len * iterations) / timeval2double(&tv_diff));
334}
335
336int bench_mem_memcpy(int argc, const char **argv,
337 const char *prefix __maybe_unused)
338{
339 struct bench_mem_info info = {
340 .routines = memcpy_routines,
341 .do_cycle = do_memcpy_cycle,
342 .do_gettimeofday = do_memcpy_gettimeofday,
343 .usage = bench_mem_memcpy_usage,
344 };
345
346 return bench_mem_common(argc, argv, prefix, &info);
347}
348
349static void memset_alloc_mem(void **dst, size_t length)
350{
351 *dst = zalloc(length);
352 if (!*dst)
353 die("memory allocation failed - maybe length is too large?\n");
354}
355
356static u64 do_memset_cycle(const struct routine *r, size_t len, bool prefault)
357{
358 u64 cycle_start = 0ULL, cycle_end = 0ULL;
359 memset_t fn = r->fn.memset;
360 void *dst = NULL;
361 int i;
362
363 memset_alloc_mem(&dst, len);
364
365 if (prefault)
366 fn(dst, -1, len);
367
368 cycle_start = get_cycle();
369 for (i = 0; i < iterations; ++i)
370 fn(dst, i, len);
371 cycle_end = get_cycle();
372
373 free(dst);
374 return cycle_end - cycle_start;
375}
376
377static double do_memset_gettimeofday(const struct routine *r, size_t len,
378 bool prefault)
379{
380 struct timeval tv_start, tv_end, tv_diff;
381 memset_t fn = r->fn.memset;
382 void *dst = NULL;
383 int i;
384
385 memset_alloc_mem(&dst, len);
386
387 if (prefault)
388 fn(dst, -1, len);
389
390 BUG_ON(gettimeofday(&tv_start, NULL));
391 for (i = 0; i < iterations; ++i)
392 fn(dst, i, len);
393 BUG_ON(gettimeofday(&tv_end, NULL));
394
395 timersub(&tv_end, &tv_start, &tv_diff);
396
397 free(dst);
398 return (double)(((double)len * iterations) / timeval2double(&tv_diff));
399}
400
401static const char * const bench_mem_memset_usage[] = {
402 "perf bench mem memset <options>",
403 NULL
404};
405
406static const struct routine memset_routines[] = {
407 { .name ="default",
408 .desc = "Default memset() provided by glibc",
409 .fn.memset = memset },
410#ifdef HAVE_ARCH_X86_64_SUPPORT
411
412#define MEMSET_FN(_fn, _name, _desc) { .name = _name, .desc = _desc, .fn.memset = _fn },
413#include "mem-memset-x86-64-asm-def.h"
414#undef MEMSET_FN
415
416#endif
417
418 { .name = NULL,
419 .desc = NULL,
420 .fn.memset = NULL }
421};
422
423int bench_mem_memset(int argc, const char **argv,
424 const char *prefix __maybe_unused)
425{
426 struct bench_mem_info info = {
427 .routines = memset_routines,
428 .do_cycle = do_memset_cycle,
429 .do_gettimeofday = do_memset_gettimeofday,
430 .usage = bench_mem_memset_usage,
431 };
432
433 return bench_mem_common(argc, argv, prefix, &info);
434}
tools/perf/bench/numa.c+2−2
@@ -164,8 +164,8 @@ static const struct option options[] = { · 163 unmodified lines
164 OPT_STRING('L', "mb_proc_locked", &p0.mb_proc_locked_str,"MB", "process serialized/locked memory access (MBs), <= process_memory"),164 OPT_STRING('L', "mb_proc_locked", &p0.mb_proc_locked_str,"MB", "process serialized/locked memory access (MBs), <= process_memory"),
165 OPT_STRING('T', "mb_thread" , &p0.mb_thread_str, "MB", "thread memory (MBs)"),165 OPT_STRING('T', "mb_thread" , &p0.mb_thread_str, "MB", "thread memory (MBs)"),
166 166
167 OPT_UINTEGER('l', "nr_loops" , &p0.nr_loops, "max number of loops to run"),167 OPT_UINTEGER('l', "nr_loops" , &p0.nr_loops, "max number of loops to run (default: unlimited)"),
168 OPT_UINTEGER('s', "nr_secs" , &p0.nr_secs, "max number of seconds to run"),168 OPT_UINTEGER('s', "nr_secs" , &p0.nr_secs, "max number of seconds to run (default: 5 secs)"),
169 OPT_UINTEGER('u', "usleep" , &p0.sleep_usecs, "usecs to sleep per loop iteration"),169 OPT_UINTEGER('u', "usleep" , &p0.sleep_usecs, "usecs to sleep per loop iteration"),
170 170
171 OPT_BOOLEAN('R', "data_reads" , &p0.data_reads, "access the data via writes (can be mixed with -W)"),171 OPT_BOOLEAN('R', "data_reads" , &p0.data_reads, "access the data via writes (can be mixed with -W)"),
tools/perf/bench/sched-messaging.c+5−5
@@ -33,7 +33,7 @@ · 32 unmodified lines
33#define DATASIZE 10033#define DATASIZE 100
34 34
35static bool use_pipes = false;35static bool use_pipes = false;
36static unsigned int loops = 100;36static unsigned int nr_loops = 100;
37static bool thread_mode = false;37static bool thread_mode = false;
38static unsigned int num_groups = 10;38static unsigned int num_groups = 10;
39 39
@@ -79,7 +79,7 @@ static void ready(int ready_out, int wakefd) · 39 unmodified lines
79 err(EXIT_FAILURE, "poll");79 err(EXIT_FAILURE, "poll");
80}80}
81 81
82/* Sender sprays loops messages down each file descriptor */82/* Sender sprays nr_loops messages down each file descriptor */
83static void *sender(struct sender_context *ctx)83static void *sender(struct sender_context *ctx)
84{84{
85 char data[DATASIZE];85 char data[DATASIZE];
@@ -88,7 +88,7 @@ static void *sender(struct sender_context *ctx) · 2 unmodified lines
88 ready(ctx->ready_out, ctx->wakefd);88 ready(ctx->ready_out, ctx->wakefd);
89 89
90 /* Now pump to every receiver. */90 /* Now pump to every receiver. */
91 for (i = 0; i < loops; i++) {91 for (i = 0; i < nr_loops; i++) {
92 for (j = 0; j < ctx->num_fds; j++) {92 for (j = 0; j < ctx->num_fds; j++) {
93 int ret, done = 0;93 int ret, done = 0;
94 94
@@ -213,7 +213,7 @@ static unsigned int group(pthread_t *pth, · 118 unmodified lines
213 /* Create the pipe between client and server */213 /* Create the pipe between client and server */
214 fdpair(fds);214 fdpair(fds);
215 215
216 ctx->num_packets = num_fds * loops;216 ctx->num_packets = num_fds * nr_loops;
217 ctx->in_fds[0] = fds[0];217 ctx->in_fds[0] = fds[0];
218 ctx->in_fds[1] = fds[1];218 ctx->in_fds[1] = fds[1];
219 ctx->ready_out = ready_out;219 ctx->ready_out = ready_out;
@@ -250,7 +250,7 @@ static const struct option options[] = { · 30 unmodified lines
250 OPT_BOOLEAN('t', "thread", &thread_mode,250 OPT_BOOLEAN('t', "thread", &thread_mode,
251 "Be multi thread instead of multi process"),251 "Be multi thread instead of multi process"),
252 OPT_UINTEGER('g', "group", &num_groups, "Specify number of groups"),252 OPT_UINTEGER('g', "group", &num_groups, "Specify number of groups"),
253 OPT_UINTEGER('l', "loop", &loops, "Specify number of loops"),253 OPT_UINTEGER('l', "nr_loops", &nr_loops, "Specify the number of loops to run (default: 100)"),
254 OPT_END()254 OPT_END()
255};255};
256 256
tools/perf/builtin-annotate.c+1−1
@@ -211,7 +211,7 @@ static int __cmd_annotate(struct perf_annotate *ann) · 210 unmodified lines
211 }211 }
212 212
213 if (!objdump_path) {213 if (!objdump_path) {
214 ret = perf_session_env__lookup_objdump(&session->header.env);214 ret = perf_env__lookup_objdump(&session->header.env);
215 if (ret)215 if (ret)
216 goto out;216 goto out;
217 }217 }
tools/perf/builtin-bench.c+7−7
@@ -36,7 +36,7 @@ struct bench { · 35 unmodified lines
36#ifdef HAVE_LIBNUMA_SUPPORT36#ifdef HAVE_LIBNUMA_SUPPORT
37static struct bench numa_benchmarks[] = {37static struct bench numa_benchmarks[] = {
38 { "mem", "Benchmark for NUMA workloads", bench_numa },38 { "mem", "Benchmark for NUMA workloads", bench_numa },
39 { "all", "Test all NUMA benchmarks", NULL },39 { "all", "Run all NUMA benchmarks", NULL },
40 { NULL, NULL, NULL }40 { NULL, NULL, NULL }
41};41};
42#endif42#endif
@@ -44,14 +44,14 @@ static struct bench numa_benchmarks[] = { · 1 unmodified line
44static struct bench sched_benchmarks[] = {44static struct bench sched_benchmarks[] = {
45 { "messaging", "Benchmark for scheduling and IPC", bench_sched_messaging },45 { "messaging", "Benchmark for scheduling and IPC", bench_sched_messaging },
46 { "pipe", "Benchmark for pipe() between two processes", bench_sched_pipe },46 { "pipe", "Benchmark for pipe() between two processes", bench_sched_pipe },
47 { "all", "Test all scheduler benchmarks", NULL },47 { "all", "Run all scheduler benchmarks", NULL },
48 { NULL, NULL, NULL }48 { NULL, NULL, NULL }
49};49};
50 50
51static struct bench mem_benchmarks[] = {51static struct bench mem_benchmarks[] = {
52 { "memcpy", "Benchmark for memcpy()", bench_mem_memcpy },52 { "memcpy", "Benchmark for memcpy() functions", bench_mem_memcpy },
53 { "memset", "Benchmark for memset() tests", bench_mem_memset },53 { "memset", "Benchmark for memset() functions", bench_mem_memset },
54 { "all", "Test all memory benchmarks", NULL },54 { "all", "Run all memory access benchmarks", NULL },
55 { NULL, NULL, NULL }55 { NULL, NULL, NULL }
56};56};
57 57
@@ -62,7 +62,7 @@ static struct bench futex_benchmarks[] = { · 4 unmodified lines
62 { "requeue", "Benchmark for futex requeue calls", bench_futex_requeue },62 { "requeue", "Benchmark for futex requeue calls", bench_futex_requeue },
63 /* pi-futexes */63 /* pi-futexes */
64 { "lock-pi", "Benchmark for futex lock_pi calls", bench_futex_lock_pi },64 { "lock-pi", "Benchmark for futex lock_pi calls", bench_futex_lock_pi },
65 { "all", "Test all futex benchmarks", NULL },65 { "all", "Run all futex benchmarks", NULL },
66 { NULL, NULL, NULL }66 { NULL, NULL, NULL }
67};67};
68 68
@@ -110,7 +110,7 @@ int bench_format = BENCH_FORMAT_DEFAULT; · 41 unmodified lines
110unsigned int bench_repeat = 10; /* default number of times to repeat the run */110unsigned int bench_repeat = 10; /* default number of times to repeat the run */
111 111
112static const struct option bench_options[] = {112static const struct option bench_options[] = {
113 OPT_STRING('f', "format", &bench_format_str, "default", "Specify format style"),113 OPT_STRING('f', "format", &bench_format_str, "default|simple", "Specify the output formatting style"),
114 OPT_UINTEGER('r', "repeat", &bench_repeat, "Specify amount of times to repeat the run"),114 OPT_UINTEGER('r', "repeat", &bench_repeat, "Specify amount of times to repeat the run"),
115 OPT_END()115 OPT_END()
116};116};
tools/perf/builtin-evlist.c+2−2
@@ -61,8 +61,8 @@ int cmd_evlist(int argc, const char **argv, const char *prefix __maybe_unused) · 60 unmodified lines
61 usage_with_options(evlist_usage, options);61 usage_with_options(evlist_usage, options);
62 62
63 if (details.event_group && (details.verbose || details.freq)) {63 if (details.event_group && (details.verbose || details.freq)) {
64 pr_err("--group option is not compatible with other options\n");64 usage_with_options_msg(evlist_usage, options,
65 usage_with_options(evlist_usage, options);65 "--group option is not compatible with other options\n");
66 }66 }
67 67
68 return __cmd_evlist(input_name, &details);68 return __cmd_evlist(input_name, &details);
tools/perf/builtin-help.c+1−1
@@ -463,7 +463,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused) · 462 unmodified lines
463 builtin_help_subcommands, builtin_help_usage, 0);463 builtin_help_subcommands, builtin_help_usage, 0);
464 464
465 if (show_all) {465 if (show_all) {
466 printf("\n usage: %s\n\n", perf_usage_string);466 printf("\n Usage: %s\n\n", perf_usage_string);
467 list_commands("perf commands", &main_cmds, &other_cmds);467 list_commands("perf commands", &main_cmds, &other_cmds);
468 printf(" %s\n\n", perf_more_info_string);468 printf(" %s\n\n", perf_more_info_string);
469 return 0;469 return 0;
tools/perf/builtin-inject.c+125−2
@@ -28,9 +28,11 @@ struct perf_inject { · 27 unmodified lines
28 bool build_ids;28 bool build_ids;
29 bool sched_stat;29 bool sched_stat;
30 bool have_auxtrace;30 bool have_auxtrace;
31 bool strip;
31 const char *input_name;32 const char *input_name;
32 struct perf_data_file output;33 struct perf_data_file output;
33 u64 bytes_written;34 u64 bytes_written;
35 u64 aux_id;
34 struct list_head samples;36 struct list_head samples;
35 struct itrace_synth_opts itrace_synth_opts;37 struct itrace_synth_opts itrace_synth_opts;
36};38};
@@ -176,6 +178,27 @@ static int perf_event__repipe(struct perf_tool *tool, · 139 unmodified lines
176 return perf_event__repipe_synth(tool, event);178 return perf_event__repipe_synth(tool, event);
177}179}
178 180
181static int perf_event__drop(struct perf_tool *tool __maybe_unused,
182 union perf_event *event __maybe_unused,
183 struct perf_sample *sample __maybe_unused,
184 struct machine *machine __maybe_unused)
185{
186 return 0;
187}
188
189static int perf_event__drop_aux(struct perf_tool *tool,
190 union perf_event *event __maybe_unused,
191 struct perf_sample *sample,
192 struct machine *machine __maybe_unused)
193{
194 struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
195
196 if (!inject->aux_id)
197 inject->aux_id = sample->id;
198
199 return 0;
200}
201
179typedef int (*inject_handler)(struct perf_tool *tool,202typedef int (*inject_handler)(struct perf_tool *tool,
180 union perf_event *event,203 union perf_event *event,
181 struct perf_sample *sample,204 struct perf_sample *sample,
@@ -466,6 +489,78 @@ static int perf_evsel__check_stype(struct perf_evsel *evsel, · 284 unmodified lines
466 return 0;489 return 0;
467}490}
468 491
492static int drop_sample(struct perf_tool *tool __maybe_unused,
493 union perf_event *event __maybe_unused,
494 struct perf_sample *sample __maybe_unused,
495 struct perf_evsel *evsel __maybe_unused,
496 struct machine *machine __maybe_unused)
497{
498 return 0;
499}
500
501static void strip_init(struct perf_inject *inject)
502{
503 struct perf_evlist *evlist = inject->session->evlist;
504 struct perf_evsel *evsel;
505
506 inject->tool.context_switch = perf_event__drop;
507
508 evlist__for_each(evlist, evsel)
509 evsel->handler = drop_sample;
510}
511
512static bool has_tracking(struct perf_evsel *evsel)
513{
514 return evsel->attr.mmap || evsel->attr.mmap2 || evsel->attr.comm ||
515 evsel->attr.task;
516}
517
518#define COMPAT_MASK (PERF_SAMPLE_ID | PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \
519 PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_IDENTIFIER)
520
521/*
522 * In order that the perf.data file is parsable, tracking events like MMAP need
523 * their selected event to exist, except if there is only 1 selected event left
524 * and it has a compatible sample type.
525 */
526static bool ok_to_remove(struct perf_evlist *evlist,
527 struct perf_evsel *evsel_to_remove)
528{
529 struct perf_evsel *evsel;
530 int cnt = 0;
531 bool ok = false;
532
533 if (!has_tracking(evsel_to_remove))
534 return true;
535
536 evlist__for_each(evlist, evsel) {
537 if (evsel->handler != drop_sample) {
538 cnt += 1;
539 if ((evsel->attr.sample_type & COMPAT_MASK) ==
540 (evsel_to_remove->attr.sample_type & COMPAT_MASK))
541 ok = true;
542 }
543 }
544
545 return ok && cnt == 1;
546}
547
548static void strip_fini(struct perf_inject *inject)
549{
550 struct perf_evlist *evlist = inject->session->evlist;
551 struct perf_evsel *evsel, *tmp;
552
553 /* Remove non-synthesized evsels if possible */
554 evlist__for_each_safe(evlist, tmp, evsel) {
555 if (evsel->handler == drop_sample &&
556 ok_to_remove(evlist, evsel)) {
557 pr_debug("Deleting %s\n", perf_evsel__name(evsel));
558 perf_evlist__remove(evlist, evsel);
559 perf_evsel__delete(evsel);
560 }
561 }
562}
563
469static int __cmd_inject(struct perf_inject *inject)564static int __cmd_inject(struct perf_inject *inject)
470{565{
471 int ret = -EINVAL;566 int ret = -EINVAL;
@@ -512,10 +607,14 @@ static int __cmd_inject(struct perf_inject *inject) · 40 unmodified lines
512 inject->tool.id_index = perf_event__repipe_id_index;607 inject->tool.id_index = perf_event__repipe_id_index;
513 inject->tool.auxtrace_info = perf_event__process_auxtrace_info;608 inject->tool.auxtrace_info = perf_event__process_auxtrace_info;
514 inject->tool.auxtrace = perf_event__process_auxtrace;609 inject->tool.auxtrace = perf_event__process_auxtrace;
610 inject->tool.aux = perf_event__drop_aux;
611 inject->tool.itrace_start = perf_event__drop_aux,
515 inject->tool.ordered_events = true;612 inject->tool.ordered_events = true;
516 inject->tool.ordering_requires_timestamps = true;613 inject->tool.ordering_requires_timestamps = true;
517 /* Allow space in the header for new attributes */614 /* Allow space in the header for new attributes */
518 output_data_offset = 4096;615 output_data_offset = 4096;
616 if (inject->strip)
617 strip_init(inject);
519 }618 }
520 619
521 if (!inject->itrace_synth_opts.set)620 if (!inject->itrace_synth_opts.set)
@@ -535,11 +634,28 @@ static int __cmd_inject(struct perf_inject *inject) · 13 unmodified lines
535 }634 }
536 /*635 /*
537 * The AUX areas have been removed and replaced with636 * The AUX areas have been removed and replaced with
538 * synthesized hardware events, so clear the feature flag.637 * synthesized hardware events, so clear the feature flag and
638 * remove the evsel.
539 */639 */
540 if (inject->itrace_synth_opts.set)640 if (inject->itrace_synth_opts.set) {
641 struct perf_evsel *evsel;
642
541 perf_header__clear_feat(&session->header,643 perf_header__clear_feat(&session->header,
542 HEADER_AUXTRACE);644 HEADER_AUXTRACE);
645 if (inject->itrace_synth_opts.last_branch)
646 perf_header__set_feat(&session->header,
647 HEADER_BRANCH_STACK);
648 evsel = perf_evlist__id2evsel_strict(session->evlist,
649 inject->aux_id);
650 if (evsel) {
651 pr_debug("Deleting %s\n",
652 perf_evsel__name(evsel));
653 perf_evlist__remove(session->evlist, evsel);
654 perf_evsel__delete(evsel);
655 }
656 if (inject->strip)
657 strip_fini(inject);
658 }
543 session->header.data_offset = output_data_offset;659 session->header.data_offset = output_data_offset;
544 session->header.data_size = inject->bytes_written;660 session->header.data_size = inject->bytes_written;
545 perf_session__write_header(session, session->evlist, fd, true);661 perf_session__write_header(session, session->evlist, fd, true);
@@ -604,6 +720,8 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) · 58 unmodified lines
604 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts,720 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts,
605 NULL, "opts", "Instruction Tracing options",721 NULL, "opts", "Instruction Tracing options",
606 itrace_parse_synth_opts),722 itrace_parse_synth_opts),
723 OPT_BOOLEAN(0, "strip", &inject.strip,
724 "strip non-synthesized events (use with --itrace)"),
607 OPT_END()725 OPT_END()
608 };726 };
609 const char * const inject_usage[] = {727 const char * const inject_usage[] = {
@@ -619,6 +737,11 @@ int cmd_inject(int argc, const char **argv, const char *prefix __maybe_unused) · 9 unmodified lines
619 if (argc)737 if (argc)
620 usage_with_options(inject_usage, options);738 usage_with_options(inject_usage, options);
621 739
740 if (inject.strip && !inject.itrace_synth_opts.set) {
741 pr_err("--strip option requires --itrace option\n");
742 return -1;
743 }
744
622 if (perf_data_file__open(&inject.output)) {745 if (perf_data_file__open(&inject.output)) {
623 perror("failed to create output file");746 perror("failed to create output file");
624 return -1;747 return -1;
tools/perf/builtin-kmem.c+1−1
@@ -329,7 +329,7 @@ static int build_alloc_func_list(void) · 328 unmodified lines
329 return -EINVAL;329 return -EINVAL;
330 }330 }
331 331
332 kernel_map = machine->vmlinux_maps[MAP__FUNCTION];332 kernel_map = machine__kernel_map(machine);
333 if (map__load(kernel_map, NULL) < 0) {333 if (map__load(kernel_map, NULL) < 0) {
334 pr_err("cannot load kernel map\n");334 pr_err("cannot load kernel map\n");
335 return -ENOENT;335 return -ENOENT;
tools/perf/builtin-kvm.c+0−1
@@ -13,7 +13,6 @@ · 12 unmodified lines
13#include "util/parse-options.h"13#include "util/parse-options.h"
14#include "util/trace-event.h"14#include "util/trace-event.h"
15#include "util/debug.h"15#include "util/debug.h"
16#include <api/fs/debugfs.h>
17#include "util/tool.h"16#include "util/tool.h"
18#include "util/stat.h"17#include "util/stat.h"
19#include "util/top.h"18#include "util/top.h"
tools/perf/builtin-list.c+17−3
@@ -36,7 +36,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) · 35 unmodified lines
36 36
37 setup_pager();37 setup_pager();
38 38
39 if (!raw_dump)39 if (!raw_dump && pager_in_use())
40 printf("\nList of pre-defined events (to be used in -e):\n\n");40 printf("\nList of pre-defined events (to be used in -e):\n\n");
41 41
42 if (argc == 0) {42 if (argc == 0) {
@@ -45,6 +45,8 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) · 2 unmodified lines
45 }45 }
46 46
47 for (i = 0; i < argc; ++i) {47 for (i = 0; i < argc; ++i) {
48 char *sep, *s;
49
48 if (strcmp(argv[i], "tracepoint") == 0)50 if (strcmp(argv[i], "tracepoint") == 0)
49 print_tracepoint_events(NULL, NULL, raw_dump);51 print_tracepoint_events(NULL, NULL, raw_dump);
50 else if (strcmp(argv[i], "hw") == 0 ||52 else if (strcmp(argv[i], "hw") == 0 ||
@@ -60,8 +62,7 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) · 9 unmodified lines
60 print_hwcache_events(NULL, raw_dump);62 print_hwcache_events(NULL, raw_dump);
61 else if (strcmp(argv[i], "pmu") == 0)63 else if (strcmp(argv[i], "pmu") == 0)
62 print_pmu_events(NULL, raw_dump);64 print_pmu_events(NULL, raw_dump);
63 else {65 else if ((sep = strchr(argv[i], ':')) != NULL) {
64 char *sep = strchr(argv[i], ':'), *s;
65 int sep_idx;66 int sep_idx;
66 67
67 if (sep == NULL) {68 if (sep == NULL) {
@@ -76,6 +77,19 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused) · 8 unmodified lines
76 s[sep_idx] = '\0';77 s[sep_idx] = '\0';
77 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);78 print_tracepoint_events(s, s + sep_idx + 1, raw_dump);
78 free(s);79 free(s);
80 } else {
81 if (asprintf(&s, "*%s*", argv[i]) < 0) {
82 printf("Critical: Not enough memory! Trying to continue...\n");
83 continue;
84 }
85 print_symbol_events(s, PERF_TYPE_HARDWARE,
86 event_symbols_hw, PERF_COUNT_HW_MAX, raw_dump);
87 print_symbol_events(s, PERF_TYPE_SOFTWARE,
88 event_symbols_sw, PERF_COUNT_SW_MAX, raw_dump);
89 print_hwcache_events(s, raw_dump);
90 print_pmu_events(s, raw_dump);
91 print_tracepoint_events(NULL, s, raw_dump);
92 free(s);
79 }93 }
80 }94 }
81 return 0;95 return 0;
tools/perf/builtin-probe.c+131−16
@@ -37,10 +37,10 @@ · 36 unmodified lines
37#include "util/strfilter.h"37#include "util/strfilter.h"
38#include "util/symbol.h"38#include "util/symbol.h"
39#include "util/debug.h"39#include "util/debug.h"
40#include <api/fs/debugfs.h>
41#include "util/parse-options.h"40#include "util/parse-options.h"
42#include "util/probe-finder.h"41#include "util/probe-finder.h"
43#include "util/probe-event.h"42#include "util/probe-event.h"
43#include "util/probe-file.h"
44 44
45#define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"45#define DEFAULT_VAR_FILTER "!__k???tab_* & !__crc_*"
46#define DEFAULT_FUNC_FILTER "!_*"46#define DEFAULT_FUNC_FILTER "!_*"
@@ -182,10 +182,8 @@ static int opt_set_target(const struct option *opt, const char *str, · 135 unmodified lines
182 if (str) {182 if (str) {
183 if (!strcmp(opt->long_name, "exec"))183 if (!strcmp(opt->long_name, "exec"))
184 params.uprobes = true;184 params.uprobes = true;
185#ifdef HAVE_DWARF_SUPPORT
186 else if (!strcmp(opt->long_name, "module"))185 else if (!strcmp(opt->long_name, "module"))
187 params.uprobes = false;186 params.uprobes = false;
188#endif
189 else187 else
190 return ret;188 return ret;
191 189
@@ -311,6 +309,119 @@ static void pr_err_with_code(const char *msg, int err) · 119 unmodified lines
311 pr_err("\n");309 pr_err("\n");
312}310}
313 311
312static int perf_add_probe_events(struct perf_probe_event *pevs, int npevs)
313{
314 int ret;
315 int i, k;
316 const char *event = NULL, *group = NULL;
317
318 ret = init_probe_symbol_maps(pevs->uprobes);
319 if (ret < 0)
320 return ret;
321
322 ret = convert_perf_probe_events(pevs, npevs);
323 if (ret < 0)
324 goto out_cleanup;
325
326 ret = apply_perf_probe_events(pevs, npevs);
327 if (ret < 0)
328 goto out_cleanup;
329
330 for (i = k = 0; i < npevs; i++)
331 k += pevs[i].ntevs;
332
333 pr_info("Added new event%s\n", (k > 1) ? "s:" : ":");
334 for (i = 0; i < npevs; i++) {
335 struct perf_probe_event *pev = &pevs[i];
336
337 for (k = 0; k < pev->ntevs; k++) {
338 struct probe_trace_event *tev = &pev->tevs[k];
339
340 /* We use tev's name for showing new events */
341 show_perf_probe_event(tev->group, tev->event, pev,
342 tev->point.module, false);
343
344 /* Save the last valid name */
345 event = tev->event;
346 group = tev->group;
347 }
348 }
349
350 /* Note that it is possible to skip all events because of blacklist */
351 if (event) {
352 /* Show how to use the event. */
353 pr_info("\nYou can now use it in all perf tools, such as:\n\n");
354 pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
355 }
356
357out_cleanup:
358 cleanup_perf_probe_events(pevs, npevs);
359 exit_probe_symbol_maps();
360 return ret;
361}
362
363static int perf_del_probe_events(struct strfilter *filter)
364{
365 int ret, ret2, ufd = -1, kfd = -1;
366 char *str = strfilter__string(filter);
367 struct strlist *klist = NULL, *ulist = NULL;
368 struct str_node *ent;
369
370 if (!str)
371 return -EINVAL;
372
373 pr_debug("Delete filter: \'%s\'\n", str);
374
375 /* Get current event names */
376 ret = probe_file__open_both(&kfd, &ufd, PF_FL_RW);
377 if (ret < 0)
378 goto out;
379
380 klist = strlist__new(NULL, NULL);
381 ulist = strlist__new(NULL, NULL);
382 if (!klist || !ulist) {
383 ret = -ENOMEM;
384 goto out;
385 }
386
387 ret = probe_file__get_events(kfd, filter, klist);
388 if (ret == 0) {
389 strlist__for_each(ent, klist)
390 pr_info("Removed event: %s\n", ent->s);
391
392 ret = probe_file__del_strlist(kfd, klist);
393 if (ret < 0)
394 goto error;
395 }
396
397 ret2 = probe_file__get_events(ufd, filter, ulist);
398 if (ret2 == 0) {
399 strlist__for_each(ent, ulist)
400 pr_info("Removed event: %s\n", ent->s);
401
402 ret2 = probe_file__del_strlist(ufd, ulist);
403 if (ret2 < 0)
404 goto error;
405 }
406
407 if (ret == -ENOENT && ret2 == -ENOENT)
408 pr_debug("\"%s\" does not hit any event.\n", str);
409 /* Note that this is silently ignored */
410 ret = 0;
411
412error:
413 if (kfd >= 0)
414 close(kfd);
415 if (ufd >= 0)
416 close(ufd);
417out:
418 strlist__delete(klist);
419 strlist__delete(ulist);
420 free(str);
421
422 return ret;
423}
424
314static int425static int
315__cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)426__cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
316{427{
@@ -377,9 +488,6 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) · 60 unmodified lines
377 "file", "vmlinux pathname"),488 "file", "vmlinux pathname"),
378 OPT_STRING('s', "source", &symbol_conf.source_prefix,489 OPT_STRING('s', "source", &symbol_conf.source_prefix,
379 "directory", "path to kernel source"),490 "directory", "path to kernel source"),
380 OPT_CALLBACK('m', "module", NULL, "modname|path",
381 "target module name (for online) or path (for offline)",
382 opt_set_target),
383 OPT_BOOLEAN('\0', "no-inlines", &probe_conf.no_inlines,491 OPT_BOOLEAN('\0', "no-inlines", &probe_conf.no_inlines,
384 "Don't search inlined functions"),492 "Don't search inlined functions"),
385#endif493#endif
@@ -396,6 +504,9 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) · 10 unmodified lines
396 opt_set_filter),504 opt_set_filter),
397 OPT_CALLBACK('x', "exec", NULL, "executable|path",505 OPT_CALLBACK('x', "exec", NULL, "executable|path",
398 "target executable name or path", opt_set_target),506 "target executable name or path", opt_set_target),
507 OPT_CALLBACK('m', "module", NULL, "modname|path",
508 "target module name (for online) or path (for offline)",
509 opt_set_target),
399 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,510 OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
400 "Enable symbol demangling"),511 "Enable symbol demangling"),
401 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,512 OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel,
@@ -417,12 +528,12 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) · 15 unmodified lines
417 PARSE_OPT_STOP_AT_NON_OPTION);528 PARSE_OPT_STOP_AT_NON_OPTION);
418 if (argc > 0) {529 if (argc > 0) {
419 if (strcmp(argv[0], "-") == 0) {530 if (strcmp(argv[0], "-") == 0) {
420 pr_warning(" Error: '-' is not supported.\n");531 usage_with_options_msg(probe_usage, options,
421 usage_with_options(probe_usage, options);532 "'-' is not supported.\n");
422 }533 }
423 if (params.command && params.command != 'a') {534 if (params.command && params.command != 'a') {
424 pr_warning(" Error: another command except --add is set.\n");535 usage_with_options_msg(probe_usage, options,
425 usage_with_options(probe_usage, options);536 "another command except --add is set.\n");
426 }537 }
427 ret = parse_probe_event_argv(argc, argv);538 ret = parse_probe_event_argv(argc, argv);
428 if (ret < 0) {539 if (ret < 0) {
@@ -451,8 +562,10 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) · 22 unmodified lines
451 switch (params.command) {562 switch (params.command) {
452 case 'l':563 case 'l':
453 if (params.uprobes) {564 if (params.uprobes) {
454 pr_warning(" Error: Don't use --list with --exec.\n");565 pr_err(" Error: Don't use --list with --exec.\n");
455 usage_with_options(probe_usage, options);566 parse_options_usage(probe_usage, options, "l", true);
567 parse_options_usage(NULL, options, "x", true);
568 return -EINVAL;
456 }569 }
457 ret = show_perf_probe_events(params.filter);570 ret = show_perf_probe_events(params.filter);
458 if (ret < 0)571 if (ret < 0)
@@ -483,7 +596,7 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) · 24 unmodified lines
483 return ret;596 return ret;
484#endif597#endif
485 case 'd':598 case 'd':
486 ret = del_perf_probe_events(params.filter);599 ret = perf_del_probe_events(params.filter);
487 if (ret < 0) {600 if (ret < 0) {
488 pr_err_with_code(" Error: Failed to delete events.", ret);601 pr_err_with_code(" Error: Failed to delete events.", ret);
489 return ret;602 return ret;
@@ -492,11 +605,13 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) · 2 unmodified lines
492 case 'a':605 case 'a':
493 /* Ensure the last given target is used */606 /* Ensure the last given target is used */
494 if (params.target && !params.target_used) {607 if (params.target && !params.target_used) {
495 pr_warning(" Error: -x/-m must follow the probe definitions.\n");608 pr_err(" Error: -x/-m must follow the probe definitions.\n");
496 usage_with_options(probe_usage, options);609 parse_options_usage(probe_usage, options, "m", true);
610 parse_options_usage(NULL, options, "x", true);
611 return -EINVAL;
497 }612 }
498 613
499 ret = add_perf_probe_events(params.events, params.nevents);614 ret = perf_add_probe_events(params.events, params.nevents);
500 if (ret < 0) {615 if (ret < 0) {
501 pr_err_with_code(" Error: Failed to add events.", ret);616 pr_err_with_code(" Error: Failed to add events.", ret);
502 return ret;617 return ret;
tools/perf/builtin-record.c+40−16
@@ -31,6 +31,7 @@ · 30 unmodified lines
31#include "util/auxtrace.h"31#include "util/auxtrace.h"
32#include "util/parse-branch-options.h"32#include "util/parse-branch-options.h"
33#include "util/parse-regs-options.h"33#include "util/parse-regs-options.h"
34#include "util/llvm-utils.h"
34 35
35#include <unistd.h>36#include <unistd.h>
36#include <sched.h>37#include <sched.h>
@@ -49,7 +50,7 @@ struct record { · 12 unmodified lines
49 int realtime_prio;50 int realtime_prio;
50 bool no_buildid;51 bool no_buildid;
51 bool no_buildid_cache;52 bool no_buildid_cache;
52 long samples;53 unsigned long long samples;
53};54};
54 55
55static int record__write(struct record *rec, void *bf, size_t size)56static int record__write(struct record *rec, void *bf, size_t size)
@@ -636,8 +637,29 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) · 580 unmodified lines
636 /*637 /*
637 * Let the child rip638 * Let the child rip
638 */639 */
639 if (forks)640 if (forks) {
641 union perf_event *event;
642
643 event = malloc(sizeof(event->comm) + machine->id_hdr_size);
644 if (event == NULL) {
645 err = -ENOMEM;
646 goto out_child;
647 }
648
649 /*
650 * Some H/W events are generated before COMM event
651 * which is emitted during exec(), so perf script
652 * cannot see a correct process name for those events.
653 * Synthesize COMM event to prevent it.
654 */
655 perf_event__synthesize_comm(tool, event,
656 rec->evlist->workload.pid,
657 process_synthesized_event,
658 machine);
659 free(event);
660
640 perf_evlist__start_workload(rec->evlist);661 perf_evlist__start_workload(rec->evlist);
662 }
641 663
642 if (opts->initial_delay) {664 if (opts->initial_delay) {
643 usleep(opts->initial_delay * 1000);665 usleep(opts->initial_delay * 1000);
@@ -646,7 +668,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) · 2 unmodified lines
646 668
647 auxtrace_snapshot_enabled = 1;669 auxtrace_snapshot_enabled = 1;
648 for (;;) {670 for (;;) {
649 int hits = rec->samples;671 unsigned long long hits = rec->samples;
650 672
651 if (record__mmap_read_all(rec) < 0) {673 if (record__mmap_read_all(rec) < 0) {
652 auxtrace_snapshot_enabled = 0;674 auxtrace_snapshot_enabled = 0;
@@ -989,13 +1011,8 @@ static struct record record = { · 336 unmodified lines
989 },1011 },
990};1012};
991 1013
992#define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace) recording: "1014const char record_callchain_help[] = CALLCHAIN_RECORD_HELP
993 1015 "\n\t\t\t\tDefault: fp";
994#ifdef HAVE_DWARF_UNWIND_SUPPORT
995const char record_callchain_help[] = CALLCHAIN_HELP "fp dwarf lbr";
996#else
997const char record_callchain_help[] = CALLCHAIN_HELP "fp lbr";
998#endif
999 1016
1000/*1017/*
1001 * XXX Will stay a global variable till we fix builtin-script.c to stop messing1018 * XXX Will stay a global variable till we fix builtin-script.c to stop messing
@@ -1043,7 +1060,7 @@ struct option __record_options[] = { · 41 unmodified lines
1043 NULL, "enables call-graph recording" ,1060 NULL, "enables call-graph recording" ,
1044 &record_callchain_opt),1061 &record_callchain_opt),
1045 OPT_CALLBACK(0, "call-graph", &record.opts,1062 OPT_CALLBACK(0, "call-graph", &record.opts,
1046 "mode[,dump_size]", record_callchain_help,1063 "record_mode[,record_size]", record_callchain_help,
1047 &record_parse_callchain_opt),1064 &record_parse_callchain_opt),
1048 OPT_INCR('v', "verbose", &verbose,1065 OPT_INCR('v', "verbose", &verbose,
1049 "be more verbose (show counter open errors, etc)"),1066 "be more verbose (show counter open errors, etc)"),
@@ -1096,6 +1113,12 @@ struct option __record_options[] = { · 46 unmodified lines
1096 "per thread proc mmap processing timeout in ms"),1113 "per thread proc mmap processing timeout in ms"),
1097 OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events,1114 OPT_BOOLEAN(0, "switch-events", &record.opts.record_switch_events,
1098 "Record context switch events"),1115 "Record context switch events"),
1116#ifdef HAVE_LIBBPF_SUPPORT
1117 OPT_STRING(0, "clang-path", &llvm_param.clang_path, "clang path",
1118 "clang binary to use for compiling BPF scriptlets"),
1119 OPT_STRING(0, "clang-opt", &llvm_param.clang_opt, "clang options",
1120 "options passed to clang when compiling BPF scriptlets"),
1121#endif
1099 OPT_END()1122 OPT_END()
1100};1123};
1101 1124
@@ -1119,14 +1142,15 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) · 17 unmodified lines
1119 usage_with_options(record_usage, record_options);1142 usage_with_options(record_usage, record_options);
1120 1143
1121 if (nr_cgroups && !rec->opts.target.system_wide) {1144 if (nr_cgroups && !rec->opts.target.system_wide) {
1122 ui__error("cgroup monitoring only available in"1145 usage_with_options_msg(record_usage, record_options,
1123 " system-wide mode\n");1146 "cgroup monitoring only available in system-wide mode");
1124 usage_with_options(record_usage, record_options);1147
1125 }1148 }
1126 if (rec->opts.record_switch_events &&1149 if (rec->opts.record_switch_events &&
1127 !perf_can_record_switch_events()) {1150 !perf_can_record_switch_events()) {
1128 ui__error("kernel does not support recording context switch events (--switch-events option)\n");1151 ui__error("kernel does not support recording context switch events\n");
1129 usage_with_options(record_usage, record_options);1152 parse_options_usage(record_usage, record_options, "switch-events", 0);
1153 return -EINVAL;
1130 }1154 }
1131 1155
1132 if (!rec->itr) {1156 if (!rec->itr) {
tools/perf/builtin-report.c+55−10
@@ -62,6 +62,7 @@ struct report { · 61 unmodified lines
62 float min_percent;62 float min_percent;
63 u64 nr_entries;63 u64 nr_entries;
64 u64 queue_size;64 u64 queue_size;
65 int socket_filter;
65 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);66 DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
66};67};
67 68
@@ -162,14 +163,21 @@ static int process_sample_event(struct perf_tool *tool, · 94 unmodified lines
162 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))163 if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
163 goto out_put;164 goto out_put;
164 165
165 if (sort__mode == SORT_MODE__BRANCH)166 if (sort__mode == SORT_MODE__BRANCH) {
167 /*
168 * A non-synthesized event might not have a branch stack if
169 * branch stacks have been synthesized (using itrace options).
170 */
171 if (!sample->branch_stack)
172 goto out_put;
166 iter.ops = &hist_iter_branch;173 iter.ops = &hist_iter_branch;
167 else if (rep->mem_mode)174 } else if (rep->mem_mode) {
168 iter.ops = &hist_iter_mem;175 iter.ops = &hist_iter_mem;
169 else if (symbol_conf.cumulate_callchain)176 } else if (symbol_conf.cumulate_callchain) {
170 iter.ops = &hist_iter_cumulative;177 iter.ops = &hist_iter_cumulative;
171 else178 } else {
172 iter.ops = &hist_iter_normal;179 iter.ops = &hist_iter_normal;
180 }
173 181
174 if (al.map != NULL)182 if (al.map != NULL)
175 al.map->dso->hit = 1;183 al.map->dso->hit = 1;
@@ -213,6 +221,15 @@ static int report__setup_sample_type(struct report *rep) · 37 unmodified lines
213 u64 sample_type = perf_evlist__combined_sample_type(session->evlist);221 u64 sample_type = perf_evlist__combined_sample_type(session->evlist);
214 bool is_pipe = perf_data_file__is_pipe(session->file);222 bool is_pipe = perf_data_file__is_pipe(session->file);
215 223
224 if (session->itrace_synth_opts->callchain ||
225 (!is_pipe &&
226 perf_header__has_feat(&session->header, HEADER_AUXTRACE) &&
227 !session->itrace_synth_opts->set))
228 sample_type |= PERF_SAMPLE_CALLCHAIN;
229
230 if (session->itrace_synth_opts->last_branch)
231 sample_type |= PERF_SAMPLE_BRANCH_STACK;
232
216 if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {233 if (!is_pipe && !(sample_type & PERF_SAMPLE_CALLCHAIN)) {
217 if (sort__has_parent) {234 if (sort__has_parent) {
218 ui__error("Selected --sort parent, but no "235 ui__error("Selected --sort parent, but no "
@@ -286,6 +303,7 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report · 67 unmodified lines
286 struct perf_evsel *evsel = hists_to_evsel(hists);303 struct perf_evsel *evsel = hists_to_evsel(hists);
287 char buf[512];304 char buf[512];
288 size_t size = sizeof(buf);305 size_t size = sizeof(buf);
306 int socked_id = hists->socket_filter;
289 307
290 if (symbol_conf.filter_relative) {308 if (symbol_conf.filter_relative) {
291 nr_samples = hists->stats.nr_non_filtered_samples;309 nr_samples = hists->stats.nr_non_filtered_samples;
@@ -326,6 +344,10 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report · 34 unmodified lines
326 ret += fprintf(fp, "\n# Sort order : %s", sort_order ? : default_mem_sort_order);344 ret += fprintf(fp, "\n# Sort order : %s", sort_order ? : default_mem_sort_order);
327 } else345 } else
328 ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);346 ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
347
348 if (socked_id > -1)
349 ret += fprintf(fp, "\n# Processor Socket: %d", socked_id);
350
329 return ret + fprintf(fp, "\n#\n");351 return ret + fprintf(fp, "\n#\n");
330}352}
331 353
@@ -365,7 +387,7 @@ static int perf_evlist__tty_browse_hists(struct perf_evlist *evlist, · 33 unmodified lines
365 387
366static void report__warn_kptr_restrict(const struct report *rep)388static void report__warn_kptr_restrict(const struct report *rep)
367{389{
368 struct map *kernel_map = rep->session->machines.host.vmlinux_maps[MAP__FUNCTION];390 struct map *kernel_map = machine__kernel_map(&rep->session->machines.host);
369 struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL;391 struct kmap *kernel_kmap = kernel_map ? map__kmap(kernel_map) : NULL;
370 392
371 if (kernel_map == NULL ||393 if (kernel_map == NULL ||
@@ -450,6 +472,8 @@ static void report__collapse_hists(struct report *rep) · 78 unmodified lines
450 if (pos->idx == 0)472 if (pos->idx == 0)
451 hists->symbol_filter_str = rep->symbol_filter_str;473 hists->symbol_filter_str = rep->symbol_filter_str;
452 474
475 hists->socket_filter = rep->socket_filter;
476
453 hists__collapse_resort(hists, &prog);477 hists__collapse_resort(hists, &prog);
454 478
455 /* Non-group events are considered as leader */479 /* Non-group events are considered as leader */
@@ -601,6 +625,12 @@ parse_percent_limit(const struct option *opt, const char *str, · 145 unmodified lines
601 return 0;625 return 0;
602}626}
603 627
628#define CALLCHAIN_DEFAULT_OPT "graph,0.5,caller,function"
629
630const char report_callchain_help[] = "Display call graph (stack chain/backtrace):\n\n"
631 CALLCHAIN_REPORT_HELP
632 "\n\t\t\t\tDefault: " CALLCHAIN_DEFAULT_OPT;
633
604int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)634int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
605{635{
606 struct perf_session *session;636 struct perf_session *session;
@@ -609,7 +639,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) · 2 unmodified lines
609 bool has_br_stack = false;639 bool has_br_stack = false;
610 int branch_mode = -1;640 int branch_mode = -1;
611 bool branch_call_mode = false;641 bool branch_call_mode = false;
612 char callchain_default_opt[] = "fractal,0.5,callee";642 char callchain_default_opt[] = CALLCHAIN_DEFAULT_OPT;
613 const char * const report_usage[] = {643 const char * const report_usage[] = {
614 "perf report [<options>]",644 "perf report [<options>]",
615 NULL645 NULL
@@ -635,6 +665,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) · 19 unmodified lines
635 },665 },
636 .max_stack = PERF_MAX_STACK_DEPTH,666 .max_stack = PERF_MAX_STACK_DEPTH,
637 .pretty_printing_style = "normal",667 .pretty_printing_style = "normal",
668 .socket_filter = -1,
638 };669 };
639 const struct option options[] = {670 const struct option options[] = {
640 OPT_STRING('i', "input", &input_name, "file",671 OPT_STRING('i', "input", &input_name, "file",
@@ -668,15 +699,18 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) · 27 unmodified lines
668 " Please refer the man page for the complete list."),699 " Please refer the man page for the complete list."),
669 OPT_STRING('F', "fields", &field_order, "key[,keys...]",700 OPT_STRING('F', "fields", &field_order, "key[,keys...]",
670 "output field(s): overhead, period, sample plus all of sort keys"),701 "output field(s): overhead, period, sample plus all of sort keys"),
671 OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,702 OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
672 "Show sample percentage for different cpu modes"),703 "Show sample percentage for different cpu modes"),
704 OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
705 "Show sample percentage for different cpu modes", PARSE_OPT_HIDDEN),
673 OPT_STRING('p', "parent", &parent_pattern, "regex",706 OPT_STRING('p', "parent", &parent_pattern, "regex",
674 "regex filter to identify parent, see: '--sort parent'"),707 "regex filter to identify parent, see: '--sort parent'"),
675 OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,708 OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
676 "Only display entries with parent-match"),709 "Only display entries with parent-match"),
677 OPT_CALLBACK_DEFAULT('g', "call-graph", &report, "output_type,min_percent[,print_limit],call_order[,branch]",710 OPT_CALLBACK_DEFAULT('g', "call-graph", &report,
678 "Display callchains using output_type (graph, flat, fractal, or none) , min percent threshold, optional print limit, callchain order, key (function or address), add branches. "711 "print_type,threshold[,print_limit],order,sort_key[,branch]",
679 "Default: fractal,0.5,callee,function", &report_parse_callchain_opt, callchain_default_opt),712 report_callchain_help, &report_parse_callchain_opt,
713 callchain_default_opt),
680 OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,714 OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
681 "Accumulate callchains of children and show total overhead as well"),715 "Accumulate callchains of children and show total overhead as well"),
682 OPT_INTEGER(0, "max-stack", &report.max_stack,716 OPT_INTEGER(0, "max-stack", &report.max_stack,
@@ -747,6 +781,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) · 64 unmodified lines
747 "Show full source file name path for source lines"),781 "Show full source file name path for source lines"),
748 OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,782 OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
749 "Show callgraph from reference event"),783 "Show callgraph from reference event"),
784 OPT_INTEGER(0, "socket-filter", &report.socket_filter,
785 "only show processor socket that match with this filter"),
750 OPT_END()786 OPT_END()
751 };787 };
752 struct perf_data_file file = {788 struct perf_data_file file = {
@@ -781,6 +817,12 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused) · 28 unmodified lines
781 817
782 if (report.inverted_callchain)818 if (report.inverted_callchain)
783 callchain_param.order = ORDER_CALLER;819 callchain_param.order = ORDER_CALLER;
820 if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
821 callchain_param.order = ORDER_CALLER;
822
823 if (itrace_synth_opts.callchain &&
824 (int)itrace_synth_opts.callchain_sz > report.max_stack)
825 report.max_stack = itrace_synth_opts.callchain_sz;
784 826
785 if (!input_name || !strlen(input_name)) {827 if (!input_name || !strlen(input_name)) {
786 if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))828 if (!fstat(STDIN_FILENO, &st) && S_ISFIFO(st.st_mode))
@@ -809,6 +851,9 @@ repeat: · 22 unmodified lines
809 has_br_stack = perf_header__has_feat(&session->header,851 has_br_stack = perf_header__has_feat(&session->header,
810 HEADER_BRANCH_STACK);852 HEADER_BRANCH_STACK);
811 853
854 if (itrace_synth_opts.last_branch)
855 has_br_stack = true;
856
812 /*857 /*
813 * Branch mode is a tristate:858 * Branch mode is a tristate:
814 * -1 means default, so decide based on the file having branch data.859 * -1 means default, so decide based on the file having branch data.
tools/perf/builtin-sched.c+2−2
@@ -1728,8 +1728,8 @@ static void setup_sorting(struct perf_sched *sched, const struct option *options · 1727 unmodified lines
1728 for (tok = strtok_r(str, ", ", &tmp);1728 for (tok = strtok_r(str, ", ", &tmp);
1729 tok; tok = strtok_r(NULL, ", ", &tmp)) {1729 tok; tok = strtok_r(NULL, ", ", &tmp)) {
1730 if (sort_dimension__add(tok, &sched->sort_list) < 0) {1730 if (sort_dimension__add(tok, &sched->sort_list) < 0) {
1731 error("Unknown --sort key: `%s'", tok);1731 usage_with_options_msg(usage_msg, options,
1732 usage_with_options(usage_msg, options);1732 "Unknown --sort key: `%s'", tok);
1733 }1733 }
1734 }1734 }
1735 1735
tools/perf/builtin-script.c+104−9
@@ -29,9 +29,12 @@ static bool no_callchain; · 28 unmodified lines
29static bool latency_format;29static bool latency_format;
30static bool system_wide;30static bool system_wide;
31static bool print_flags;31static bool print_flags;
32static bool nanosecs;
32static const char *cpu_list;33static const char *cpu_list;
33static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);34static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
34 35
36unsigned int scripting_max_stack = PERF_MAX_STACK_DEPTH;
37
35enum perf_output_field {38enum perf_output_field {
36 PERF_OUTPUT_COMM = 1U << 0,39 PERF_OUTPUT_COMM = 1U << 0,
37 PERF_OUTPUT_TID = 1U << 1,40 PERF_OUTPUT_TID = 1U << 1,
@@ -48,6 +51,8 @@ enum perf_output_field { · 10 unmodified lines
48 PERF_OUTPUT_SRCLINE = 1U << 12,51 PERF_OUTPUT_SRCLINE = 1U << 12,
49 PERF_OUTPUT_PERIOD = 1U << 13,52 PERF_OUTPUT_PERIOD = 1U << 13,
50 PERF_OUTPUT_IREGS = 1U << 14,53 PERF_OUTPUT_IREGS = 1U << 14,
54 PERF_OUTPUT_BRSTACK = 1U << 15,
55 PERF_OUTPUT_BRSTACKSYM = 1U << 16,
51};56};
52 57
53struct output_option {58struct output_option {
@@ -69,6 +74,8 @@ struct output_option { · 15 unmodified lines
69 {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},74 {.str = "srcline", .field = PERF_OUTPUT_SRCLINE},
70 {.str = "period", .field = PERF_OUTPUT_PERIOD},75 {.str = "period", .field = PERF_OUTPUT_PERIOD},
71 {.str = "iregs", .field = PERF_OUTPUT_IREGS},76 {.str = "iregs", .field = PERF_OUTPUT_IREGS},
77 {.str = "brstack", .field = PERF_OUTPUT_BRSTACK},
78 {.str = "brstacksym", .field = PERF_OUTPUT_BRSTACKSYM},
72};79};
73 80
74/* default set to maintain compatibility with current format */81/* default set to maintain compatibility with current format */
@@ -415,10 +422,84 @@ static void print_sample_start(struct perf_sample *sample, · 340 unmodified lines
415 secs = nsecs / NSECS_PER_SEC;422 secs = nsecs / NSECS_PER_SEC;
416 nsecs -= secs * NSECS_PER_SEC;423 nsecs -= secs * NSECS_PER_SEC;
417 usecs = nsecs / NSECS_PER_USEC;424 usecs = nsecs / NSECS_PER_USEC;
418 printf("%5lu.%06lu: ", secs, usecs);425 if (nanosecs)
426 printf("%5lu.%09llu: ", secs, nsecs);
427 else
428 printf("%5lu.%06lu: ", secs, usecs);
419 }429 }
420}430}
421 431
432static inline char
433mispred_str(struct branch_entry *br)
434{
435 if (!(br->flags.mispred || br->flags.predicted))
436 return '-';
437
438 return br->flags.predicted ? 'P' : 'M';
439}
440
441static void print_sample_brstack(union perf_event *event __maybe_unused,
442 struct perf_sample *sample,
443 struct thread *thread __maybe_unused,
444 struct perf_event_attr *attr __maybe_unused)
445{
446 struct branch_stack *br = sample->branch_stack;
447 u64 i;
448
449 if (!(br && br->nr))
450 return;
451
452 for (i = 0; i < br->nr; i++) {
453 printf(" 0x%"PRIx64"/0x%"PRIx64"/%c/%c/%c/%d ",
454 br->entries[i].from,
455 br->entries[i].to,
456 mispred_str( br->entries + i),
457 br->entries[i].flags.in_tx? 'X' : '-',
458 br->entries[i].flags.abort? 'A' : '-',
459 br->entries[i].flags.cycles);
460 }
461}
462
463static void print_sample_brstacksym(union perf_event *event __maybe_unused,
464 struct perf_sample *sample,
465 struct thread *thread __maybe_unused,
466 struct perf_event_attr *attr __maybe_unused)
467{
468 struct branch_stack *br = sample->branch_stack;
469 struct addr_location alf, alt;
470 u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
471 u64 i, from, to;
472
473 if (!(br && br->nr))
474 return;
475
476 for (i = 0; i < br->nr; i++) {
477
478 memset(&alf, 0, sizeof(alf));
479 memset(&alt, 0, sizeof(alt));
480 from = br->entries[i].from;
481 to = br->entries[i].to;
482
483 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, from, &alf);
484 if (alf.map)
485 alf.sym = map__find_symbol(alf.map, alf.addr, NULL);
486
487 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, to, &alt);
488 if (alt.map)
489 alt.sym = map__find_symbol(alt.map, alt.addr, NULL);
490
491 symbol__fprintf_symname_offs(alf.sym, &alf, stdout);
492 putchar('/');
493 symbol__fprintf_symname_offs(alt.sym, &alt, stdout);
494 printf("/%c/%c/%c/%d ",
495 mispred_str( br->entries + i),
496 br->entries[i].flags.in_tx? 'X' : '-',
497 br->entries[i].flags.abort? 'A' : '-',
498 br->entries[i].flags.cycles);
499 }
500}
501
502
422static void print_sample_addr(union perf_event *event,503static void print_sample_addr(union perf_event *event,
423 struct perf_sample *sample,504 struct perf_sample *sample,
424 struct thread *thread,505 struct thread *thread,
@@ -471,7 +552,7 @@ static void print_sample_bts(union perf_event *event, · 46 unmodified lines
471 }552 }
472 }553 }
473 perf_evsel__print_ip(evsel, sample, al, print_opts,554 perf_evsel__print_ip(evsel, sample, al, print_opts,
474 PERF_MAX_STACK_DEPTH);555 scripting_max_stack);
475 }556 }
476 557
477 /* print branch_to information */558 /* print branch_to information */
@@ -548,12 +629,17 @@ static void process_event(union perf_event *event, struct perf_sample *sample, · 70 unmodified lines
548 629
549 perf_evsel__print_ip(evsel, sample, al,630 perf_evsel__print_ip(evsel, sample, al,
550 output[attr->type].print_ip_opts,631 output[attr->type].print_ip_opts,
551 PERF_MAX_STACK_DEPTH);632 scripting_max_stack);
552 }633 }
553 634
554 if (PRINT_FIELD(IREGS))635 if (PRINT_FIELD(IREGS))
555 print_sample_iregs(event, sample, thread, attr);636 print_sample_iregs(event, sample, thread, attr);
556 637
638 if (PRINT_FIELD(BRSTACK))
639 print_sample_brstack(event, sample, thread, attr);
640 else if (PRINT_FIELD(BRSTACKSYM))
641 print_sample_brstacksym(event, sample, thread, attr);
642
557 printf("\n");643 printf("\n");
558}644}
559 645
@@ -680,7 +766,10 @@ static int process_attr(struct perf_tool *tool, union perf_event *event, · 120 unmodified lines
680 766
681 set_print_ip_opts(&evsel->attr);767 set_print_ip_opts(&evsel->attr);
682 768
683 return perf_evsel__check_attr(evsel, scr->session);769 if (evsel->attr.sample_type)
770 err = perf_evsel__check_attr(evsel, scr->session);
771
772 return err;
684}773}
685 774
686static int process_comm_event(struct perf_tool *tool,775static int process_comm_event(struct perf_tool *tool,
@@ -1672,7 +1761,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · 985 unmodified lines
1672 "comma separated output fields prepend with 'type:'. "1761 "comma separated output fields prepend with 'type:'. "
1673 "Valid types: hw,sw,trace,raw. "1762 "Valid types: hw,sw,trace,raw. "
1674 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"1763 "Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,"
1675 "addr,symoff,period,iregs,flags", parse_output_fields),1764 "addr,symoff,period,iregs,brstack,brstacksym,flags", parse_output_fields),
1676 OPT_BOOLEAN('a', "all-cpus", &system_wide,1765 OPT_BOOLEAN('a', "all-cpus", &system_wide,
1677 "system-wide collection from all CPUs"),1766 "system-wide collection from all CPUs"),
1678 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",1767 OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
@@ -1695,6 +1784,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · 16 unmodified lines
1695 OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events,1784 OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events,
1696 "Show context switch events (if recorded)"),1785 "Show context switch events (if recorded)"),
1697 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),1786 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
1787 OPT_BOOLEAN(0, "ns", &nanosecs,
1788 "Use 9 decimal places when displaying time"),
1698 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",1789 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
1699 "Instruction Tracing options",1790 "Instruction Tracing options",
1700 itrace_parse_synth_opts),1791 itrace_parse_synth_opts),
@@ -1740,6 +1831,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · 39 unmodified lines
1740 }1831 }
1741 }1832 }
1742 1833
1834 if (itrace_synth_opts.callchain &&
1835 itrace_synth_opts.callchain_sz > scripting_max_stack)
1836 scripting_max_stack = itrace_synth_opts.callchain_sz;
1837
1743 /* make sure PERF_EXEC_PATH is set for scripts */1838 /* make sure PERF_EXEC_PATH is set for scripts */
1744 perf_set_argv_exec_path(perf_exec_path());1839 perf_set_argv_exec_path(perf_exec_path());
1745 1840
@@ -1752,9 +1847,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · 6 unmodified lines
1752 rep_script_path = get_script_path(argv[0], REPORT_SUFFIX);1847 rep_script_path = get_script_path(argv[0], REPORT_SUFFIX);
1753 1848
1754 if (!rec_script_path && !rep_script_path) {1849 if (!rec_script_path && !rep_script_path) {
1755 fprintf(stderr, " Couldn't find script %s\n\n See perf"1850 usage_with_options_msg(script_usage, options,
1851 "Couldn't find script `%s'\n\n See perf"
1756 " script -l for available scripts.\n", argv[0]);1852 " script -l for available scripts.\n", argv[0]);
1757 usage_with_options(script_usage, options);
1758 }1853 }
1759 1854
1760 if (is_top_script(argv[0])) {1855 if (is_top_script(argv[0])) {
@@ -1765,10 +1860,10 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) · 4 unmodified lines
1765 rep_args = has_required_arg(rep_script_path);1860 rep_args = has_required_arg(rep_script_path);
1766 rec_args = (argc - 1) - rep_args;1861 rec_args = (argc - 1) - rep_args;
1767 if (rec_args < 0) {1862 if (rec_args < 0) {
1768 fprintf(stderr, " %s script requires options."1863 usage_with_options_msg(script_usage, options,
1864 "`%s' script requires options."
1769 "\n\n See perf script -l for available "1865 "\n\n See perf script -l for available "
1770 "scripts and options.\n", argv[0]);1866 "scripts and options.\n", argv[0]);
1771 usage_with_options(script_usage, options);
1772 }1867 }
1773 }1868 }
1774 1869
tools/perf/builtin-stat.c+82−11
@@ -100,6 +100,8 @@ static struct target target = { · 99 unmodified lines
100 .uid = UINT_MAX,100 .uid = UINT_MAX,
101};101};
102 102
103typedef int (*aggr_get_id_t)(struct cpu_map *m, int cpu);
104
103static int run_count = 1;105static int run_count = 1;
104static bool no_inherit = false;106static bool no_inherit = false;
105static volatile pid_t child_pid = -1;107static volatile pid_t child_pid = -1;
@@ -119,7 +121,7 @@ static unsigned int unit_width = 4; /* strlen("unit") */ · 13 unmodified lines
119static bool forever = false;121static bool forever = false;
120static struct timespec ref_time;122static struct timespec ref_time;
121static struct cpu_map *aggr_map;123static struct cpu_map *aggr_map;
122static int (*aggr_get_id)(struct cpu_map *m, int cpu);124static aggr_get_id_t aggr_get_id;
123 125
124static volatile int done = 0;126static volatile int done = 0;
125 127
@@ -215,7 +217,7 @@ static void read_counters(bool close_counters) · 89 unmodified lines
215 217
216 evlist__for_each(evsel_list, counter) {218 evlist__for_each(evsel_list, counter) {
217 if (read_counter(counter))219 if (read_counter(counter))
218 pr_warning("failed to read counter %s\n", counter->name);220 pr_debug("failed to read counter %s\n", counter->name);
219 221
220 if (perf_stat_process_counter(&stat_config, counter))222 if (perf_stat_process_counter(&stat_config, counter))
221 pr_warning("failed to process counter %s\n", counter->name);223 pr_warning("failed to process counter %s\n", counter->name);
@@ -434,7 +436,7 @@ static void print_noise_pct(double total, double avg) · 212 unmodified lines
434 436
435static void print_noise(struct perf_evsel *evsel, double avg)437static void print_noise(struct perf_evsel *evsel, double avg)
436{438{
437 struct perf_stat *ps;439 struct perf_stat_evsel *ps;
438 440
439 if (run_count == 1)441 if (run_count == 1)
440 return;442 return;
@@ -479,6 +481,7 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr) · 38 unmodified lines
479 csv_sep);481 csv_sep);
480 break;482 break;
481 case AGGR_GLOBAL:483 case AGGR_GLOBAL:
484 case AGGR_UNSET:
482 default:485 default:
483 break;486 break;
484 }487 }
@@ -671,7 +674,7 @@ static void print_aggr_thread(struct perf_evsel *counter, char *prefix) · 186 unmodified lines
671static void print_counter_aggr(struct perf_evsel *counter, char *prefix)674static void print_counter_aggr(struct perf_evsel *counter, char *prefix)
672{675{
673 FILE *output = stat_config.output;676 FILE *output = stat_config.output;
674 struct perf_stat *ps = counter->priv;677 struct perf_stat_evsel *ps = counter->priv;
675 double avg = avg_stats(&ps->res_stats[0]);678 double avg = avg_stats(&ps->res_stats[0]);
676 int scaled = counter->counts->scaled;679 int scaled = counter->counts->scaled;
677 double uval;680 double uval;
@@ -799,6 +802,8 @@ static void print_interval(char *prefix, struct timespec *ts) · 121 unmodified lines
799 case AGGR_GLOBAL:802 case AGGR_GLOBAL:
800 default:803 default:
801 fprintf(output, "# time counts %*s events\n", unit_width, "unit");804 fprintf(output, "# time counts %*s events\n", unit_width, "unit");
805 case AGGR_UNSET:
806 break;
802 }807 }
803 }808 }
804 809
@@ -880,6 +885,7 @@ static void print_counters(struct timespec *ts, int argc, const char **argv) · 75 unmodified lines
880 evlist__for_each(evsel_list, counter)885 evlist__for_each(evsel_list, counter)
881 print_counter(counter, prefix);886 print_counter(counter, prefix);
882 break;887 break;
888 case AGGR_UNSET:
883 default:889 default:
884 break;890 break;
885 }891 }
@@ -940,30 +946,90 @@ static int stat__set_big_num(const struct option *opt __maybe_unused, · 54 unmodified lines
940 return 0;946 return 0;
941}947}
942 948
949static int perf_stat__get_socket(struct cpu_map *map, int cpu)
950{
951 return cpu_map__get_socket(map, cpu, NULL);
952}
953
954static int perf_stat__get_core(struct cpu_map *map, int cpu)
955{
956 return cpu_map__get_core(map, cpu, NULL);
957}
958
959static int cpu_map__get_max(struct cpu_map *map)
960{
961 int i, max = -1;
962
963 for (i = 0; i < map->nr; i++) {
964 if (map->map[i] > max)
965 max = map->map[i];
966 }
967
968 return max;
969}
970
971static struct cpu_map *cpus_aggr_map;
972
973static int perf_stat__get_aggr(aggr_get_id_t get_id, struct cpu_map *map, int idx)
974{
975 int cpu;
976
977 if (idx >= map->nr)
978 return -1;
979
980 cpu = map->map[idx];
981
982 if (cpus_aggr_map->map[cpu] == -1)
983 cpus_aggr_map->map[cpu] = get_id(map, idx);
984
985 return cpus_aggr_map->map[cpu];
986}
987
988static int perf_stat__get_socket_cached(struct cpu_map *map, int idx)
989{
990 return perf_stat__get_aggr(perf_stat__get_socket, map, idx);
991}
992
993static int perf_stat__get_core_cached(struct cpu_map *map, int idx)
994{
995 return perf_stat__get_aggr(perf_stat__get_core, map, idx);
996}
997
943static int perf_stat_init_aggr_mode(void)998static int perf_stat_init_aggr_mode(void)
944{999{
1000 int nr;
1001
945 switch (stat_config.aggr_mode) {1002 switch (stat_config.aggr_mode) {
946 case AGGR_SOCKET:1003 case AGGR_SOCKET:
947 if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) {1004 if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) {
948 perror("cannot build socket map");1005 perror("cannot build socket map");
949 return -1;1006 return -1;
950 }1007 }
951 aggr_get_id = cpu_map__get_socket;1008 aggr_get_id = perf_stat__get_socket_cached;
952 break;1009 break;
953 case AGGR_CORE:1010 case AGGR_CORE:
954 if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) {1011 if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) {
955 perror("cannot build core map");1012 perror("cannot build core map");
956 return -1;1013 return -1;
957 }1014 }
958 aggr_get_id = cpu_map__get_core;1015 aggr_get_id = perf_stat__get_core_cached;
959 break;1016 break;
960 case AGGR_NONE:1017 case AGGR_NONE:
961 case AGGR_GLOBAL:1018 case AGGR_GLOBAL:
962 case AGGR_THREAD:1019 case AGGR_THREAD:
1020 case AGGR_UNSET:
963 default:1021 default:
964 break;1022 break;
965 }1023 }
966 return 0;1024
1025 /*
1026 * The evsel_list->cpus is the base we operate on,
1027 * taking the highest cpu number to be the size of
1028 * the aggregation translate cpumap.
1029 */
1030 nr = cpu_map__get_max(evsel_list->cpus);
1031 cpus_aggr_map = cpu_map__empty_new(nr + 1);
1032 return cpus_aggr_map ? 0 : -ENOMEM;
967}1033}
968 1034
969/*1035/*
@@ -1179,7 +1245,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) · 209 unmodified lines
1179 OPT_STRING(0, "post", &post_cmd, "command",1245 OPT_STRING(0, "post", &post_cmd, "command",
1180 "command to run after to the measured command"),1246 "command to run after to the measured command"),
1181 OPT_UINTEGER('I', "interval-print", &stat_config.interval,1247 OPT_UINTEGER('I', "interval-print", &stat_config.interval,
1182 "print counts at regular interval in ms (>= 100)"),1248 "print counts at regular interval in ms (>= 10)"),
1183 OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode,1249 OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode,
1184 "aggregate counts per processor socket", AGGR_SOCKET),1250 "aggregate counts per processor socket", AGGR_SOCKET),
1185 OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode,1251 OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode,
@@ -1332,9 +1398,14 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) · 146 unmodified lines
1332 thread_map__read_comms(evsel_list->threads);1398 thread_map__read_comms(evsel_list->threads);
1333 1399
1334 if (interval && interval < 100) {1400 if (interval && interval < 100) {
1335 pr_err("print interval must be >= 100ms\n");1401 if (interval < 10) {
1336 parse_options_usage(stat_usage, options, "I", 1);1402 pr_err("print interval must be >= 10ms\n");
1337 goto out;1403 parse_options_usage(stat_usage, options, "I", 1);
1404 goto out;
1405 } else
1406 pr_warning("print interval < 100ms. "
1407 "The overhead percentage could be high in some cases. "
1408 "Please proceed with caution.\n");
1338 }1409 }
1339 1410
1340 if (perf_evlist__alloc_stats(evsel_list, interval))1411 if (perf_evlist__alloc_stats(evsel_list, interval))
tools/perf/builtin-top.c+50−9
@@ -655,7 +655,7 @@ static int symbol_filter(struct map *map, struct symbol *sym) · 654 unmodified lines
655{655{
656 const char *name = sym->name;656 const char *name = sym->name;
657 657
658 if (!map->dso->kernel)658 if (!__map__is_kernel(map))
659 return 0;659 return 0;
660 /*660 /*
661 * ppc64 uses function descriptors and appends a '.' to the661 * ppc64 uses function descriptors and appends a '.' to the
@@ -857,9 +857,12 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx) · 195 unmodified lines
857 * TODO: we don't process guest user from host side857 * TODO: we don't process guest user from host side
858 * except simple counting.858 * except simple counting.
859 */859 */
860 /* Fall thru */
861 default:
862 goto next_event;860 goto next_event;
861 default:
862 if (event->header.type == PERF_RECORD_SAMPLE)
863 goto next_event;
864 machine = &session->machines.host;
865 break;
863 }866 }
864 867
865 868
@@ -952,7 +955,7 @@ static int __cmd_top(struct perf_top *top) · 86 unmodified lines
952 machines__set_symbol_filter(&top->session->machines, symbol_filter);955 machines__set_symbol_filter(&top->session->machines, symbol_filter);
953 956
954 if (!objdump_path) {957 if (!objdump_path) {
955 ret = perf_session_env__lookup_objdump(&top->session->header.env);958 ret = perf_env__lookup_objdump(&top->session->header.env);
956 if (ret)959 if (ret)
957 goto out_delete;960 goto out_delete;
958 }961 }
@@ -961,8 +964,18 @@ static int __cmd_top(struct perf_top *top) · 2 unmodified lines
961 if (ret)964 if (ret)
962 goto out_delete;965 goto out_delete;
963 966
967 if (perf_session__register_idle_thread(top->session) == NULL)
968 goto out_delete;
969
964 machine__synthesize_threads(&top->session->machines.host, &opts->target,970 machine__synthesize_threads(&top->session->machines.host, &opts->target,
965 top->evlist->threads, false, opts->proc_map_timeout);971 top->evlist->threads, false, opts->proc_map_timeout);
972
973 if (sort__has_socket) {
974 ret = perf_env__read_cpu_topology_map(&perf_env);
975 if (ret < 0)
976 goto out_err_cpu_topo;
977 }
978
966 ret = perf_top__start_counters(top);979 ret = perf_top__start_counters(top);
967 if (ret)980 if (ret)
968 goto out_delete;981 goto out_delete;
@@ -1020,6 +1033,14 @@ out_delete: · 51 unmodified lines
1020 top->session = NULL;1033 top->session = NULL;
1021 1034
1022 return ret;1035 return ret;
1036
1037out_err_cpu_topo: {
1038 char errbuf[BUFSIZ];
1039 const char *err = strerror_r(-ret, errbuf, sizeof(errbuf));
1040
1041 ui__error("Could not read the CPU topology map: %s\n", err);
1042 goto out_delete;
1043}
1023}1044}
1024 1045
1025static int1046static int
@@ -1032,8 +1053,22 @@ callchain_opt(const struct option *opt, const char *arg, int unset) · 6 unmodified lines
1032static int1053static int
1033parse_callchain_opt(const struct option *opt, const char *arg, int unset)1054parse_callchain_opt(const struct option *opt, const char *arg, int unset)
1034{1055{
1035 symbol_conf.use_callchain = true;1056 struct record_opts *record = (struct record_opts *)opt->value;
1036 return record_parse_callchain_opt(opt, arg, unset);1057
1058 record->callgraph_set = true;
1059 callchain_param.enabled = !unset;
1060 callchain_param.record_mode = CALLCHAIN_FP;
1061
1062 /*
1063 * --no-call-graph
1064 */
1065 if (unset) {
1066 symbol_conf.use_callchain = false;
1067 callchain_param.record_mode = CALLCHAIN_NONE;
1068 return 0;
1069 }
1070
1071 return parse_callchain_top_opt(arg);
1037}1072}
1038 1073
1039static int perf_top_config(const char *var, const char *value, void *cb)1074static int perf_top_config(const char *var, const char *value, void *cb)
@@ -1058,6 +1093,9 @@ parse_percent_limit(const struct option *opt, const char *arg, · 18 unmodified lines
1058 return 0;1093 return 0;
1059}1094}
1060 1095
1096const char top_callchain_help[] = CALLCHAIN_RECORD_HELP CALLCHAIN_REPORT_HELP
1097 "\n\t\t\t\tDefault: fp,graph,0.5,caller,function";
1098
1061int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)1099int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1062{1100{
1063 char errbuf[BUFSIZ];1101 char errbuf[BUFSIZ];
@@ -1133,11 +1171,11 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) · 69 unmodified lines
1133 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,1171 OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
1134 "Show a column with the number of samples"),1172 "Show a column with the number of samples"),
1135 OPT_CALLBACK_NOOPT('g', NULL, &top.record_opts,1173 OPT_CALLBACK_NOOPT('g', NULL, &top.record_opts,
1136 NULL, "enables call-graph recording",1174 NULL, "enables call-graph recording and display",
1137 &callchain_opt),1175 &callchain_opt),
1138 OPT_CALLBACK(0, "call-graph", &top.record_opts,1176 OPT_CALLBACK(0, "call-graph", &top.record_opts,
1139 "mode[,dump_size]", record_callchain_help,1177 "record_mode[,record_size],print_type,threshold[,print_limit],order,sort_key[,branch]",
1140 &parse_callchain_opt),1178 top_callchain_help, &parse_callchain_opt),
1141 OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,1179 OPT_BOOLEAN(0, "children", &symbol_conf.cumulate_callchain,
1142 "Accumulate callchains of children and show total overhead as well"),1180 "Accumulate callchains of children and show total overhead as well"),
1143 OPT_INTEGER(0, "max-stack", &top.max_stack,1181 OPT_INTEGER(0, "max-stack", &top.max_stack,
@@ -1267,6 +1305,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused) · 123 unmodified lines
1267 perf_hpp__cancel_cumulate();1305 perf_hpp__cancel_cumulate();
1268 }1306 }
1269 1307
1308 if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
1309 callchain_param.order = ORDER_CALLER;
1310
1270 symbol_conf.priv_size = sizeof(struct annotation);1311 symbol_conf.priv_size = sizeof(struct annotation);
1271 1312
1272 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);1313 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
tools/perf/builtin-trace.c+21−10
@@ -17,6 +17,7 @@ · 16 unmodified lines
17 */17 */
18 18
19#include <traceevent/event-parse.h>19#include <traceevent/event-parse.h>
20#include <api/fs/tracing_path.h>
20#include "builtin.h"21#include "builtin.h"
21#include "util/color.h"22#include "util/color.h"
22#include "util/debug.h"23#include "util/debug.h"
@@ -37,6 +38,7 @@ · 14 unmodified lines
37#include <stdlib.h>38#include <stdlib.h>
38#include <sys/mman.h>39#include <sys/mman.h>
39#include <linux/futex.h>40#include <linux/futex.h>
41#include <linux/err.h>
40 42
41/* For older distros: */43/* For older distros: */
42#ifndef MAP_STACK44#ifndef MAP_STACK
@@ -244,13 +246,14 @@ static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void · 201 unmodified lines
244 struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction);246 struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction);
245 247
246 /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */248 /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */
247 if (evsel == NULL)249 if (IS_ERR(evsel))
248 evsel = perf_evsel__newtp("syscalls", direction);250 evsel = perf_evsel__newtp("syscalls", direction);
249 251
250 if (evsel) {252 if (IS_ERR(evsel))
251 if (perf_evsel__init_syscall_tp(evsel, handler))253 return NULL;
252 goto out_delete;254
253 }255 if (perf_evsel__init_syscall_tp(evsel, handler))
256 goto out_delete;
254 257
255 return evsel;258 return evsel;
256 259
@@ -582,6 +585,12 @@ static size_t syscall_arg__scnprintf_futex_op(char *bf, size_t size, struct sysc · 325 unmodified lines
582 585
583#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op586#define SCA_FUTEX_OP syscall_arg__scnprintf_futex_op
584 587
588static const char *bpf_cmd[] = {
589 "MAP_CREATE", "MAP_LOOKUP_ELEM", "MAP_UPDATE_ELEM", "MAP_DELETE_ELEM",
590 "MAP_GET_NEXT_KEY", "PROG_LOAD",
591};
592static DEFINE_STRARRAY(bpf_cmd);
593
585static const char *epoll_ctl_ops[] = { "ADD", "DEL", "MOD", };594static const char *epoll_ctl_ops[] = { "ADD", "DEL", "MOD", };
586static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, 1);595static DEFINE_STRARRAY_OFFSET(epoll_ctl_ops, 1);
587 596
@@ -1008,6 +1017,7 @@ static struct syscall_fmt { · 420 unmodified lines
1008 .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */1017 .arg_scnprintf = { [0] = SCA_FILENAME, /* filename */
1009 [1] = SCA_ACCMODE, /* mode */ }, },1018 [1] = SCA_ACCMODE, /* mode */ }, },
1010 { .name = "arch_prctl", .errmsg = true, .alias = "prctl", },1019 { .name = "arch_prctl", .errmsg = true, .alias = "prctl", },
1020 { .name = "bpf", .errmsg = true, STRARRAY(0, cmd, bpf_cmd), },
1011 { .name = "brk", .hexret = true,1021 { .name = "brk", .hexret = true,
1012 .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, },1022 .arg_scnprintf = { [0] = SCA_HEX, /* brk */ }, },
1013 { .name = "chdir", .errmsg = true,1023 { .name = "chdir", .errmsg = true,
@@ -1704,12 +1714,12 @@ static int trace__read_syscall_info(struct trace *trace, int id) · 690 unmodified lines
1704 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name);1714 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name);
1705 sc->tp_format = trace_event__tp_format("syscalls", tp_name);1715 sc->tp_format = trace_event__tp_format("syscalls", tp_name);
1706 1716
1707 if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) {1717 if (IS_ERR(sc->tp_format) && sc->fmt && sc->fmt->alias) {
1708 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias);1718 snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias);
1709 sc->tp_format = trace_event__tp_format("syscalls", tp_name);1719 sc->tp_format = trace_event__tp_format("syscalls", tp_name);
1710 }1720 }
1711 1721
1712 if (sc->tp_format == NULL)1722 if (IS_ERR(sc->tp_format))
1713 return -1;1723 return -1;
1714 1724
1715 sc->args = sc->tp_format->format.fields;1725 sc->args = sc->tp_format->format.fields;
@@ -2389,7 +2399,8 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); · 673 unmodified lines
2389static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist)2399static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist)
2390{2400{
2391 struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname");2401 struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname");
2392 if (evsel == NULL)2402
2403 if (IS_ERR(evsel))
2393 return false;2404 return false;
2394 2405
2395 if (perf_evsel__field(evsel, "pathname") == NULL) {2406 if (perf_evsel__field(evsel, "pathname") == NULL) {
@@ -2686,11 +2697,11 @@ out_delete_evlist: · 290 unmodified lines
2686 char errbuf[BUFSIZ];2697 char errbuf[BUFSIZ];
2687 2698
2688out_error_sched_stat_runtime:2699out_error_sched_stat_runtime:
2689 debugfs__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime");2700 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "sched", "sched_stat_runtime");
2690 goto out_error;2701 goto out_error;
2691 2702
2692out_error_raw_syscalls:2703out_error_raw_syscalls:
2693 debugfs__strerror_open_tp(errno, errbuf, sizeof(errbuf), "raw_syscalls", "sys_(enter|exit)");2704 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "raw_syscalls", "sys_(enter|exit)");
2694 goto out_error;2705 goto out_error;
2695 2706
2696out_error_mmap:2707out_error_mmap:
tools/perf/config/Makefile+22−1
@@ -106,9 +106,14 @@ ifdef LIBBABELTRACE · 105 unmodified lines
106 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf106 FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
107endif107endif
108 108
109FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
109# include ARCH specific config110# include ARCH specific config
110-include $(src-perf)/arch/$(ARCH)/Makefile111-include $(src-perf)/arch/$(ARCH)/Makefile
111 112
113ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
114 CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
115endif
116
112include $(src-perf)/config/utilities.mak117include $(src-perf)/config/utilities.mak
113 118
114ifeq ($(call get-executable,$(FLEX)),)119ifeq ($(call get-executable,$(FLEX)),)
@@ -233,6 +238,7 @@ ifdef NO_LIBELF · 118 unmodified lines
233 NO_DEMANGLE := 1238 NO_DEMANGLE := 1
234 NO_LIBUNWIND := 1239 NO_LIBUNWIND := 1
235 NO_LIBDW_DWARF_UNWIND := 1240 NO_LIBDW_DWARF_UNWIND := 1
241 NO_LIBBPF := 1
236else242else
237 ifeq ($(feature-libelf), 0)243 ifeq ($(feature-libelf), 0)
238 ifeq ($(feature-glibc), 1)244 ifeq ($(feature-glibc), 1)
@@ -242,13 +248,14 @@ else · 3 unmodified lines
242 LIBC_SUPPORT := 1248 LIBC_SUPPORT := 1
243 endif249 endif
244 ifeq ($(LIBC_SUPPORT),1)250 ifeq ($(LIBC_SUPPORT),1)
245 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);251 msg := $(warning No libelf found, disables 'probe' tool and BPF support in 'perf record', please install elfutils-libelf-devel/libelf-dev);
246 252
247 NO_LIBELF := 1253 NO_LIBELF := 1
248 NO_DWARF := 1254 NO_DWARF := 1
249 NO_DEMANGLE := 1255 NO_DEMANGLE := 1
250 NO_LIBUNWIND := 1256 NO_LIBUNWIND := 1
251 NO_LIBDW_DWARF_UNWIND := 1257 NO_LIBDW_DWARF_UNWIND := 1
258 NO_LIBBPF := 1
252 else259 else
253 ifneq ($(filter s% -static%,$(LDFLAGS),),)260 ifneq ($(filter s% -static%,$(LDFLAGS),),)
254 msg := $(error No static glibc found, please install glibc-static);261 msg := $(error No static glibc found, please install glibc-static);
@@ -305,6 +312,13 @@ ifndef NO_LIBELF · 50 unmodified lines
305 $(call detected,CONFIG_DWARF)312 $(call detected,CONFIG_DWARF)
306 endif # PERF_HAVE_DWARF_REGS313 endif # PERF_HAVE_DWARF_REGS
307 endif # NO_DWARF314 endif # NO_DWARF
315
316 ifndef NO_LIBBPF
317 ifeq ($(feature-bpf), 1)
318 CFLAGS += -DHAVE_LIBBPF_SUPPORT
319 $(call detected,CONFIG_LIBBPF)
320 endif
321 endif # NO_LIBBPF
308endif # NO_LIBELF322endif # NO_LIBELF
309 323
310ifeq ($(ARCH),powerpc)324ifeq ($(ARCH),powerpc)
@@ -320,6 +334,13 @@ ifndef NO_LIBUNWIND · 9 unmodified lines
320 endif334 endif
321endif335endif
322 336
337ifndef NO_LIBBPF
338 ifneq ($(feature-bpf), 1)
339 msg := $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
340 NO_LIBBPF := 1
341 endif
342endif
343
323dwarf-post-unwind := 1344dwarf-post-unwind := 1
324dwarf-post-unwind-text := BUG345dwarf-post-unwind-text := BUG
325 346
tools/perf/perf.c+25−5
@@ -8,14 +8,16 @@ · 7 unmodified lines
8 */8 */
9#include "builtin.h"9#include "builtin.h"
10 10
11#include "util/env.h"
11#include "util/exec_cmd.h"12#include "util/exec_cmd.h"
12#include "util/cache.h"13#include "util/cache.h"
13#include "util/quote.h"14#include "util/quote.h"
14#include "util/run-command.h"15#include "util/run-command.h"
15#include "util/parse-events.h"16#include "util/parse-events.h"
16#include "util/parse-options.h"17#include "util/parse-options.h"
18#include "util/bpf-loader.h"
17#include "util/debug.h"19#include "util/debug.h"
18#include <api/fs/debugfs.h>20#include <api/fs/tracing_path.h>
19#include <pthread.h>21#include <pthread.h>
20 22
21const char perf_usage_string[] =23const char perf_usage_string[] =
@@ -160,6 +162,20 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) · 138 unmodified lines
160 if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version"))162 if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version"))
161 break;163 break;
162 164
165 /*
166 * Shortcut for '-h' and '-v' options to invoke help
167 * and version command.
168 */
169 if (!strcmp(cmd, "-h")) {
170 (*argv)[0] = "--help";
171 break;
172 }
173
174 if (!strcmp(cmd, "-v")) {
175 (*argv)[0] = "--version";
176 break;
177 }
178
163 /*179 /*
164 * Check remaining flags.180 * Check remaining flags.
165 */181 */
@@ -214,7 +230,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) · 48 unmodified lines
214 fprintf(stderr, "No directory given for --debugfs-dir.\n");230 fprintf(stderr, "No directory given for --debugfs-dir.\n");
215 usage(perf_usage_string);231 usage(perf_usage_string);
216 }232 }
217 perf_debugfs_set_path((*argv)[1]);233 tracing_path_set((*argv)[1]);
218 if (envchanged)234 if (envchanged)
219 *envchanged = 1;235 *envchanged = 1;
220 (*argv)++;236 (*argv)++;
@@ -230,7 +246,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) · 9 unmodified lines
230 (*argv)++;246 (*argv)++;
231 (*argc)--;247 (*argc)--;
232 } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {248 } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
233 perf_debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR));249 tracing_path_set(cmd + strlen(CMD_DEBUGFS_DIR));
234 fprintf(stderr, "dir: %s\n", tracing_path);250 fprintf(stderr, "dir: %s\n", tracing_path);
235 if (envchanged)251 if (envchanged)
236 *envchanged = 1;252 *envchanged = 1;
@@ -369,6 +385,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) · 132 unmodified lines
369 385
370 status = p->fn(argc, argv, prefix);386 status = p->fn(argc, argv, prefix);
371 exit_browser(status);387 exit_browser(status);
388 perf_env__exit(&perf_env);
389 bpf__clear();
372 390
373 if (status)391 if (status)
374 return status & 0xff;392 return status & 0xff;
@@ -517,8 +535,10 @@ int main(int argc, const char **argv) · 142 unmodified lines
517 cmd = perf_extract_argv0_path(argv[0]);535 cmd = perf_extract_argv0_path(argv[0]);
518 if (!cmd)536 if (!cmd)
519 cmd = "perf-help";537 cmd = "perf-help";
520 /* get debugfs mount point from /proc/mounts */538
521 perf_debugfs_mount(NULL);539 /* get debugfs/tracefs mount point from /proc/mounts */
540 tracing_path_mount();
541
522 /*542 /*
523 * "perf-xxxx" is the same as "perf xxxx", but we obviously:543 * "perf-xxxx" is the same as "perf xxxx", but we obviously:
524 *544 *
tools/perf/python/twatch.py+20−3
@@ -15,14 +15,14 @@ · 14 unmodified lines
15 15
16import perf16import perf
17 17
18def main():18def main(context_switch = 0, thread = -1):
19 cpus = perf.cpu_map()19 cpus = perf.cpu_map()
20 threads = perf.thread_map()20 threads = perf.thread_map(thread)
21 evsel = perf.evsel(type = perf.TYPE_SOFTWARE,21 evsel = perf.evsel(type = perf.TYPE_SOFTWARE,
22 config = perf.COUNT_SW_DUMMY,22 config = perf.COUNT_SW_DUMMY,
23 task = 1, comm = 1, mmap = 0, freq = 0,23 task = 1, comm = 1, mmap = 0, freq = 0,
24 wakeup_events = 1, watermark = 1,24 wakeup_events = 1, watermark = 1,
25 sample_id_all = 1,25 sample_id_all = 1, context_switch = context_switch,
26 sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)26 sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)
27 27
28 """What we want are just the PERF_RECORD_ lifetime events for threads,28 """What we want are just the PERF_RECORD_ lifetime events for threads,
@@ -48,4 +48,21 @@ def main(): · 19 unmodified lines
48 print event48 print event
49 49
50if __name__ == '__main__':50if __name__ == '__main__':
51 """
52 To test the PERF_RECORD_SWITCH record, pick a pid and replace
53 in the following line.
54
55 Example output:
56
57cpu: 3, pid: 31463, tid: 31593 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31593, switch_out: 1 }
58cpu: 1, pid: 31463, tid: 31489 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31489, switch_out: 1 }
59cpu: 2, pid: 31463, tid: 31496 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31496, switch_out: 1 }
60cpu: 3, pid: 31463, tid: 31491 { type: context_switch, next_prev_pid: 31463, next_prev_tid: 31491, switch_out: 0 }
61
62 It is possible as well to use event.misc & perf.PERF_RECORD_MISC_SWITCH_OUT
63 to figure out if this is a context switch in or out of the monitored threads.
64
65 If bored, please add command line option parsing support for these options :-)
66 """
67 # main(context_switch = 1, thread = 31463)
51 main()68 main()
tools/perf/scripts/python/export-to-postgresql.py+221−0
@@ -61,6 +61,142 @@ import datetime · 60 unmodified lines
61#61#
62# An example of using the database is provided by the script62# An example of using the database is provided by the script
63# call-graph-from-postgresql.py. Refer to that script for details.63# call-graph-from-postgresql.py. Refer to that script for details.
64#
65# Tables:
66#
67# The tables largely correspond to perf tools' data structures. They are largely self-explanatory.
68#
69# samples
70#
71# 'samples' is the main table. It represents what instruction was executing at a point in time
72# when something (a selected event) happened. The memory address is the instruction pointer or 'ip'.
73#
74# calls
75#
76# 'calls' represents function calls and is related to 'samples' by 'call_id' and 'return_id'.
77# 'calls' is only created when the 'calls' option to this script is specified.
78#
79# call_paths
80#
81# 'call_paths' represents all the call stacks. Each 'call' has an associated record in 'call_paths'.
82# 'calls_paths' is only created when the 'calls' option to this script is specified.
83#
84# branch_types
85#
86# 'branch_types' provides descriptions for each type of branch.
87#
88# comm_threads
89#
90# 'comm_threads' shows how 'comms' relates to 'threads'.
91#
92# comms
93#
94# 'comms' contains a record for each 'comm' - the name given to the executable that is running.
95#
96# dsos
97#
98# 'dsos' contains a record for each executable file or library.
99#
100# machines
101#
102# 'machines' can be used to distinguish virtual machines if virtualization is supported.
103#
104# selected_events
105#
106# 'selected_events' contains a record for each kind of event that has been sampled.
107#
108# symbols
109#
110# 'symbols' contains a record for each symbol. Only symbols that have samples are present.
111#
112# threads
113#
114# 'threads' contains a record for each thread.
115#
116# Views:
117#
118# Most of the tables have views for more friendly display. The views are:
119#
120# calls_view
121# call_paths_view
122# comm_threads_view
123# dsos_view
124# machines_view
125# samples_view
126# symbols_view
127# threads_view
128#
129# More examples of browsing the database with psql:
130# Note that some of the examples are not the most optimal SQL query.
131# Note that call information is only available if the script's 'calls' option has been used.
132#
133# Top 10 function calls (not aggregated by symbol):
134#
135# SELECT * FROM calls_view ORDER BY elapsed_time DESC LIMIT 10;
136#
137# Top 10 function calls (aggregated by symbol):
138#
139# SELECT symbol_id,(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,
140# SUM(elapsed_time) AS tot_elapsed_time,SUM(branch_count) AS tot_branch_count
141# FROM calls_view GROUP BY symbol_id ORDER BY tot_elapsed_time DESC LIMIT 10;
142#
143# Note that the branch count gives a rough estimation of cpu usage, so functions
144# that took a long time but have a relatively low branch count must have spent time
145# waiting.
146#
147# Find symbols by pattern matching on part of the name (e.g. names containing 'alloc'):
148#
149# SELECT * FROM symbols_view WHERE name LIKE '%alloc%';
150#
151# Top 10 function calls for a specific symbol (e.g. whose symbol_id is 187):
152#
153# SELECT * FROM calls_view WHERE symbol_id = 187 ORDER BY elapsed_time DESC LIMIT 10;
154#
155# Show function calls made by function in the same context (i.e. same call path) (e.g. one with call_path_id 254):
156#
157# SELECT * FROM calls_view WHERE parent_call_path_id = 254;
158#
159# Show branches made during a function call (e.g. where call_id is 29357 and return_id is 29370 and tid is 29670)
160#
161# SELECT * FROM samples_view WHERE id >= 29357 AND id <= 29370 AND tid = 29670 AND event LIKE 'branches%';
162#
163# Show transactions:
164#
165# SELECT * FROM samples_view WHERE event = 'transactions';
166#
167# Note transaction start has 'in_tx' true whereas, transaction end has 'in_tx' false.
168# Transaction aborts have branch_type_name 'transaction abort'
169#
170# Show transaction aborts:
171#
172# SELECT * FROM samples_view WHERE event = 'transactions' AND branch_type_name = 'transaction abort';
173#
174# To print a call stack requires walking the call_paths table. For example this python script:
175# #!/usr/bin/python2
176#
177# import sys
178# from PySide.QtSql import *
179#
180# if __name__ == '__main__':
181# if (len(sys.argv) < 3):
182# print >> sys.stderr, "Usage is: printcallstack.py <database name> <call_path_id>"
183# raise Exception("Too few arguments")
184# dbname = sys.argv[1]
185# call_path_id = sys.argv[2]
186# db = QSqlDatabase.addDatabase('QPSQL')
187# db.setDatabaseName(dbname)
188# if not db.open():
189# raise Exception("Failed to open database " + dbname + " error: " + db.lastError().text())
190# query = QSqlQuery(db)
191# print " id ip symbol_id symbol dso_id dso_short_name"
192# while call_path_id != 0 and call_path_id != 1:
193# ret = query.exec_('SELECT * FROM call_paths_view WHERE id = ' + str(call_path_id))
194# if not ret:
195# raise Exception("Query failed: " + query.lastError().text())
196# if not query.next():
197# raise Exception("Query failed")
198# print "{0:>6} {1:>10} {2:>9} {3:<30} {4:>6} {5:<30}".format(query.value(0), query.value(1), query.value(2), query.value(3), query.value(4), query.value(5))
199# call_path_id = query.value(6)
64 200
65from PySide.QtSql import *201from PySide.QtSql import *
66 202
@@ -244,6 +380,91 @@ if perf_db_export_calls: · 177 unmodified lines
244 'parent_call_path_id bigint,'380 'parent_call_path_id bigint,'
245 'flags integer)')381 'flags integer)')
246 382
383do_query(query, 'CREATE VIEW machines_view AS '
384 'SELECT '
385 'id,'
386 'pid,'
387 'root_dir,'
388 'CASE WHEN id=0 THEN \'unknown\' WHEN pid=-1 THEN \'host\' ELSE \'guest\' END AS host_or_guest'
389 ' FROM machines')
390
391do_query(query, 'CREATE VIEW dsos_view AS '
392 'SELECT '
393 'id,'
394 'machine_id,'
395 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,'
396 'short_name,'
397 'long_name,'
398 'build_id'
399 ' FROM dsos')
400
401do_query(query, 'CREATE VIEW symbols_view AS '
402 'SELECT '
403 'id,'
404 'name,'
405 '(SELECT short_name FROM dsos WHERE id=dso_id) AS dso,'
406 'dso_id,'
407 'sym_start,'
408 'sym_end,'
409 'CASE WHEN binding=0 THEN \'local\' WHEN binding=1 THEN \'global\' ELSE \'weak\' END AS binding'
410 ' FROM symbols')
411
412do_query(query, 'CREATE VIEW threads_view AS '
413 'SELECT '
414 'id,'
415 'machine_id,'
416 '(SELECT host_or_guest FROM machines_view WHERE id = machine_id) AS host_or_guest,'
417 'process_id,'
418 'pid,'
419 'tid'
420 ' FROM threads')
421
422do_query(query, 'CREATE VIEW comm_threads_view AS '
423 'SELECT '
424 'comm_id,'
425 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
426 'thread_id,'
427 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
428 '(SELECT tid FROM threads WHERE id = thread_id) AS tid'
429 ' FROM comm_threads')
430
431if perf_db_export_calls:
432 do_query(query, 'CREATE VIEW call_paths_view AS '
433 'SELECT '
434 'c.id,'
435 'to_hex(c.ip) AS ip,'
436 'c.symbol_id,'
437 '(SELECT name FROM symbols WHERE id = c.symbol_id) AS symbol,'
438 '(SELECT dso_id FROM symbols WHERE id = c.symbol_id) AS dso_id,'
439 '(SELECT dso FROM symbols_view WHERE id = c.symbol_id) AS dso_short_name,'
440 'c.parent_id,'
441 'to_hex(p.ip) AS parent_ip,'
442 'p.symbol_id AS parent_symbol_id,'
443 '(SELECT name FROM symbols WHERE id = p.symbol_id) AS parent_symbol,'
444 '(SELECT dso_id FROM symbols WHERE id = p.symbol_id) AS parent_dso_id,'
445 '(SELECT dso FROM symbols_view WHERE id = p.symbol_id) AS parent_dso_short_name'
446 ' FROM call_paths c INNER JOIN call_paths p ON p.id = c.parent_id')
447 do_query(query, 'CREATE VIEW calls_view AS '
448 'SELECT '
449 'calls.id,'
450 'thread_id,'
451 '(SELECT pid FROM threads WHERE id = thread_id) AS pid,'
452 '(SELECT tid FROM threads WHERE id = thread_id) AS tid,'
453 '(SELECT comm FROM comms WHERE id = comm_id) AS command,'
454 'call_path_id,'
455 'to_hex(ip) AS ip,'
456 'symbol_id,'
457 '(SELECT name FROM symbols WHERE id = symbol_id) AS symbol,'
458 'call_time,'
459 'return_time,'
460 'return_time - call_time AS elapsed_time,'
461 'branch_count,'
462 'call_id,'
463 'return_id,'
464 'CASE WHEN flags=1 THEN \'no call\' WHEN flags=2 THEN \'no return\' WHEN flags=3 THEN \'no call/return\' ELSE \'\' END AS flags,'
465 'parent_call_path_id'
466 ' FROM calls INNER JOIN call_paths ON call_paths.id = call_path_id')
467
247do_query(query, 'CREATE VIEW samples_view AS '468do_query(query, 'CREATE VIEW samples_view AS '
248 'SELECT '469 'SELECT '
249 'id,'470 'id,'
tools/perf/tests/Build+1−3
@@ -8,7 +8,6 @@ perf-y += openat-syscall-all-cpus.o · 7 unmodified lines
8perf-y += openat-syscall-tp-fields.o8perf-y += openat-syscall-tp-fields.o
9perf-y += mmap-basic.o9perf-y += mmap-basic.o
10perf-y += perf-record.o10perf-y += perf-record.o
11perf-y += rdpmc.o
12perf-y += evsel-roundtrip-name.o11perf-y += evsel-roundtrip-name.o
13perf-y += evsel-tp-sched.o12perf-y += evsel-tp-sched.o
14perf-y += fdarray.o13perf-y += fdarray.o
@@ -33,8 +32,7 @@ perf-y += parse-no-sample-id-all.o · 18 unmodified lines
33perf-y += kmod-path.o32perf-y += kmod-path.o
34perf-y += thread-map.o33perf-y += thread-map.o
35perf-y += llvm.o34perf-y += llvm.o
36 35perf-y += topology.o
37perf-$(CONFIG_X86) += perf-time-to-tsc.o
38 36
39ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))37ifeq ($(ARCH),$(filter $(ARCH),x86 arm arm64))
40perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o38perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
tools/perf/tests/bpf-script-example.c+44−0
@@ -0,0 +1,44 @@
1#ifndef LINUX_VERSION_CODE
2# error Need LINUX_VERSION_CODE
3# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
4#endif
5#define BPF_ANY 0
6#define BPF_MAP_TYPE_ARRAY 2
7#define BPF_FUNC_map_lookup_elem 1
8#define BPF_FUNC_map_update_elem 2
9
10static void *(*bpf_map_lookup_elem)(void *map, void *key) =
11 (void *) BPF_FUNC_map_lookup_elem;
12static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
13 (void *) BPF_FUNC_map_update_elem;
14
15struct bpf_map_def {
16 unsigned int type;
17 unsigned int key_size;
18 unsigned int value_size;
19 unsigned int max_entries;
20};
21
22#define SEC(NAME) __attribute__((section(NAME), used))
23struct bpf_map_def SEC("maps") flip_table = {
24 .type = BPF_MAP_TYPE_ARRAY,
25 .key_size = sizeof(int),
26 .value_size = sizeof(int),
27 .max_entries = 1,
28};
29
30SEC("func=sys_epoll_pwait")
31int bpf_func__sys_epoll_pwait(void *ctx)
32{
33 int ind =0;
34 int *flag = bpf_map_lookup_elem(&flip_table, &ind);
35 int new_flag;
36 if (!flag)
37 return 0;
38 /* flip flag and store back */
39 new_flag = !*flag;
40 bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
41 return new_flag;
42}
43char _license[] SEC("license") = "GPL";
44int _version SEC("version") = LINUX_VERSION_CODE;
tools/perf/tests/builtin-test.c+36−40
@@ -14,10 +14,13 @@ · 13 unmodified lines
14#include "parse-options.h"14#include "parse-options.h"
15#include "symbol.h"15#include "symbol.h"
16 16
17static struct test {17struct test __weak arch_tests[] = {
18 const char *desc;18 {
19 int (*func)(void);19 .func = NULL,
20} tests[] = {20 },
21};
22
23static struct test generic_tests[] = {
21 {24 {
22 .desc = "vmlinux symtab matches kallsyms",25 .desc = "vmlinux symtab matches kallsyms",
23 .func = test__vmlinux_matches_kallsyms,26 .func = test__vmlinux_matches_kallsyms,
@@ -38,12 +41,6 @@ static struct test { · 14 unmodified lines
38 .desc = "parse events tests",41 .desc = "parse events tests",
39 .func = test__parse_events,42 .func = test__parse_events,
40 },43 },
41#if defined(__x86_64__) || defined(__i386__)
42 {
43 .desc = "x86 rdpmc test",
44 .func = test__rdpmc,
45 },
46#endif
47 {44 {
48 .desc = "Validate PERF_RECORD_* events & perf_sample fields",45 .desc = "Validate PERF_RECORD_* events & perf_sample fields",
49 .func = test__PERF_RECORD,46 .func = test__PERF_RECORD,
@@ -104,12 +101,6 @@ static struct test { · 54 unmodified lines
104 .desc = "Test software clock events have valid period values",101 .desc = "Test software clock events have valid period values",
105 .func = test__sw_clock_freq,102 .func = test__sw_clock_freq,
106 },103 },
107#if defined(__x86_64__) || defined(__i386__)
108 {
109 .desc = "Test converting perf time to TSC",
110 .func = test__perf_time_to_tsc,
111 },
112#endif
113 {104 {
114 .desc = "Test object code reading",105 .desc = "Test object code reading",
115 .func = test__code_reading,106 .func = test__code_reading,
@@ -126,14 +117,6 @@ static struct test { · 10 unmodified lines
126 .desc = "Test parsing with no sample_id_all bit set",117 .desc = "Test parsing with no sample_id_all bit set",
127 .func = test__parse_no_sample_id_all,118 .func = test__parse_no_sample_id_all,
128 },119 },
129#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
130#ifdef HAVE_DWARF_UNWIND_SUPPORT
131 {
132 .desc = "Test dwarf unwind",
133 .func = test__dwarf_unwind,
134 },
135#endif
136#endif
137 {120 {
138 .desc = "Test filtering hist entries",121 .desc = "Test filtering hist entries",
139 .func = test__hists_filter,122 .func = test__hists_filter,
@@ -178,12 +161,21 @@ static struct test { · 38 unmodified lines
178 .desc = "Test LLVM searching and compiling",161 .desc = "Test LLVM searching and compiling",
179 .func = test__llvm,162 .func = test__llvm,
180 },163 },
164 {
165 .desc = "Test topology in session",
166 .func = test_session_topology,
167 },
181 {168 {
182 .func = NULL,169 .func = NULL,
183 },170 },
184};171};
185 172
186static bool perf_test__matches(int curr, int argc, const char *argv[])173static struct test *tests[] = {
174 generic_tests,
175 arch_tests,
176};
177
178static bool perf_test__matches(struct test *test, int curr, int argc, const char *argv[])
187{179{
188 int i;180 int i;
189 181
@@ -200,7 +192,7 @@ static bool perf_test__matches(int curr, int argc, const char *argv[]) · 10 unmodified lines
200 continue;192 continue;
201 }193 }
202 194
203 if (strstr(tests[curr].desc, argv[i]))195 if (strstr(test->desc, argv[i]))
204 return true;196 return true;
205 }197 }
206 198
@@ -237,27 +229,31 @@ static int run_test(struct test *test) · 30 unmodified lines
237 return err;229 return err;
238}230}
239 231
232#define for_each_test(j, t) \
233 for (j = 0; j < ARRAY_SIZE(tests); j++) \
234 for (t = &tests[j][0]; t->func; t++)
235
240static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)236static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
241{237{
238 struct test *t;
239 unsigned int j;
242 int i = 0;240 int i = 0;
243 int width = 0;241 int width = 0;
244 242
245 while (tests[i].func) {243 for_each_test(j, t) {
246 int len = strlen(tests[i].desc);244 int len = strlen(t->desc);
247 245
248 if (width < len)246 if (width < len)
249 width = len;247 width = len;
250 ++i;
251 }248 }
252 249
253 i = 0;250 for_each_test(j, t) {
254 while (tests[i].func) {
255 int curr = i++, err;251 int curr = i++, err;
256 252
257 if (!perf_test__matches(curr, argc, argv))253 if (!perf_test__matches(t, curr, argc, argv))
258 continue;254 continue;
259 255
260 pr_info("%2d: %-*s:", i, width, tests[curr].desc);256 pr_info("%2d: %-*s:", i, width, t->desc);
261 257
262 if (intlist__find(skiplist, i)) {258 if (intlist__find(skiplist, i)) {
263 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");259 color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
@@ -265,8 +261,8 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) · 1 unmodified line
265 }261 }
266 262
267 pr_debug("\n--- start ---\n");263 pr_debug("\n--- start ---\n");
268 err = run_test(&tests[curr]);264 err = run_test(t);
269 pr_debug("---- end ----\n%s:", tests[curr].desc);265 pr_debug("---- end ----\n%s:", t->desc);
270 266
271 switch (err) {267 switch (err) {
272 case TEST_OK:268 case TEST_OK:
@@ -287,15 +283,15 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) · 14 unmodified lines
287 283
288static int perf_test__list(int argc, const char **argv)284static int perf_test__list(int argc, const char **argv)
289{285{
286 unsigned int j;
287 struct test *t;
290 int i = 0;288 int i = 0;
291 289
292 while (tests[i].func) {290 for_each_test(j, t) {
293 int curr = i++;291 if (argc > 1 && !strstr(t->desc, argv[1]))
294
295 if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
296 continue;292 continue;
297 293
298 pr_info("%2d: %s\n", i, tests[curr].desc);294 pr_info("%2d: %s\n", ++i, t->desc);
299 }295 }
300 296
301 return 0;297 return 0;
tools/perf/tests/code-reading.c+61−15
@@ -33,20 +33,20 @@ static unsigned int hex(char c) · 32 unmodified lines
33 return c - 'A' + 10;33 return c - 'A' + 10;
34}34}
35 35
36static void read_objdump_line(const char *line, size_t line_len, void **buf,36static size_t read_objdump_line(const char *line, size_t line_len, void *buf,
37 size_t *len)37 size_t len)
38{38{
39 const char *p;39 const char *p;
40 size_t i;40 size_t i, j = 0;
41 41
42 /* Skip to a colon */42 /* Skip to a colon */
43 p = strchr(line, ':');43 p = strchr(line, ':');
44 if (!p)44 if (!p)
45 return;45 return 0;
46 i = p + 1 - line;46 i = p + 1 - line;
47 47
48 /* Read bytes */48 /* Read bytes */
49 while (*len) {49 while (j < len) {
50 char c1, c2;50 char c1, c2;
51 51
52 /* Skip spaces */52 /* Skip spaces */
@@ -65,20 +65,26 @@ static void read_objdump_line(const char *line, size_t line_len, void **buf, · 12 unmodified lines
65 if (i < line_len && line[i] && !isspace(line[i]))65 if (i < line_len && line[i] && !isspace(line[i]))
66 break;66 break;
67 /* Store byte */67 /* Store byte */
68 *(unsigned char *)*buf = (hex(c1) << 4) | hex(c2);68 *(unsigned char *)buf = (hex(c1) << 4) | hex(c2);
69 *buf += 1;69 buf += 1;
70 *len -= 1;70 j++;
71 }71 }
72 /* return number of successfully read bytes */
73 return j;
72}74}
73 75
74static int read_objdump_output(FILE *f, void **buf, size_t *len)76static int read_objdump_output(FILE *f, void *buf, size_t *len, u64 start_addr)
75{77{
76 char *line = NULL;78 char *line = NULL;
77 size_t line_len;79 size_t line_len, off_last = 0;
78 ssize_t ret;80 ssize_t ret;
79 int err = 0;81 int err = 0;
82 u64 addr, last_addr = start_addr;
83
84 while (off_last < *len) {
85 size_t off, read_bytes, written_bytes;
86 unsigned char tmp[BUFSZ];
80 87
81 while (1) {
82 ret = getline(&line, &line_len, f);88 ret = getline(&line, &line_len, f);
83 if (feof(f))89 if (feof(f))
84 break;90 break;
@@ -87,9 +93,33 @@ static int read_objdump_output(FILE *f, void **buf, size_t *len) · 2 unmodified lines
87 err = -1;93 err = -1;
88 break;94 break;
89 }95 }
90 read_objdump_line(line, ret, buf, len);96
97 /* read objdump data into temporary buffer */
98 read_bytes = read_objdump_line(line, ret, tmp, sizeof(tmp));
99 if (!read_bytes)
100 continue;
101
102 if (sscanf(line, "%"PRIx64, &addr) != 1)
103 continue;
104 if (addr < last_addr) {
105 pr_debug("addr going backwards, read beyond section?\n");
106 break;
107 }
108 last_addr = addr;
109
110 /* copy it from temporary buffer to 'buf' according
111 * to address on current objdump line */
112 off = addr - start_addr;
113 if (off >= *len)
114 break;
115 written_bytes = MIN(read_bytes, *len - off);
116 memcpy(buf + off, tmp, written_bytes);
117 off_last = off + written_bytes;
91 }118 }
92 119
120 /* len returns number of bytes that could not be read */
121 *len -= off_last;
122
93 free(line);123 free(line);
94 124
95 return err;125 return err;
@@ -103,7 +133,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf, · 7 unmodified lines
103 FILE *f;133 FILE *f;
104 int ret;134 int ret;
105 135
106 fmt = "%s -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";136 fmt = "%s -z -d --start-address=0x%"PRIx64" --stop-address=0x%"PRIx64" %s";
107 ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,137 ret = snprintf(cmd, sizeof(cmd), fmt, "objdump", addr, addr + len,
108 filename);138 filename);
109 if (ret <= 0 || (size_t)ret >= sizeof(cmd))139 if (ret <= 0 || (size_t)ret >= sizeof(cmd))
@@ -120,7 +150,7 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf, · 10 unmodified lines
120 return -1;150 return -1;
121 }151 }
122 152
123 ret = read_objdump_output(f, &buf, &len);153 ret = read_objdump_output(f, buf, &len, addr);
124 if (len) {154 if (len) {
125 pr_debug("objdump read too few bytes\n");155 pr_debug("objdump read too few bytes\n");
126 if (!ret)156 if (!ret)
@@ -132,6 +162,18 @@ static int read_via_objdump(const char *filename, u64 addr, void *buf, · 5 unmodified lines
132 return ret;162 return ret;
133}163}
134 164
165static void dump_buf(unsigned char *buf, size_t len)
166{
167 size_t i;
168
169 for (i = 0; i < len; i++) {
170 pr_debug("0x%02x ", buf[i]);
171 if (i % 16 == 15)
172 pr_debug("\n");
173 }
174 pr_debug("\n");
175}
176
135static int read_object_code(u64 addr, size_t len, u8 cpumode,177static int read_object_code(u64 addr, size_t len, u8 cpumode,
136 struct thread *thread, struct state *state)178 struct thread *thread, struct state *state)
137{179{
@@ -234,6 +276,10 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, · 96 unmodified lines
234 /* The results should be identical */276 /* The results should be identical */
235 if (memcmp(buf1, buf2, len)) {277 if (memcmp(buf1, buf2, len)) {
236 pr_debug("Bytes read differ from those read by objdump\n");278 pr_debug("Bytes read differ from those read by objdump\n");
279 pr_debug("buf1 (dso):\n");
280 dump_buf(buf1, len);
281 pr_debug("buf2 (objdump):\n");
282 dump_buf(buf2, len);
237 return -1;283 return -1;
238 }284 }
239 pr_debug("Bytes read match those read by objdump\n");285 pr_debug("Bytes read match those read by objdump\n");
@@ -427,7 +473,7 @@ static int do_test_code_reading(bool try_kcore) · 187 unmodified lines
427 symbol_conf.kallsyms_name = "/proc/kallsyms";473 symbol_conf.kallsyms_name = "/proc/kallsyms";
428 474
429 /* Load kernel map */475 /* Load kernel map */
430 map = machine->vmlinux_maps[MAP__FUNCTION];476 map = machine__kernel_map(machine);
431 ret = map__load(map, NULL);477 ret = map__load(map, NULL);
432 if (ret < 0) {478 if (ret < 0) {
433 pr_debug("map__load failed\n");479 pr_debug("map__load failed\n");
tools/perf/tests/dwarf-unwind.c+4−0
@@ -11,6 +11,10 @@ · 10 unmodified lines
11#include "thread.h"11#include "thread.h"
12#include "callchain.h"12#include "callchain.h"
13 13
14#if defined (__x86_64__) || defined (__i386__)
15#include "arch-tests.h"
16#endif
17
14/* For bsearch. We try to unwind functions in shared object. */18/* For bsearch. We try to unwind functions in shared object. */
15#include <stdlib.h>19#include <stdlib.h>
16 20
tools/perf/tests/evsel-tp-sched.c+8−2
@@ -1,3 +1,4 @@
1#include <linux/err.h>
1#include <traceevent/event-parse.h>2#include <traceevent/event-parse.h>
2#include "evsel.h"3#include "evsel.h"
3#include "tests.h"4#include "tests.h"
@@ -36,8 +37,8 @@ int test__perf_evsel__tp_sched_test(void) · 32 unmodified lines
36 struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");37 struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");
37 int ret = 0;38 int ret = 0;
38 39
39 if (evsel == NULL) {40 if (IS_ERR(evsel)) {
40 pr_debug("perf_evsel__new\n");41 pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
41 return -1;42 return -1;
42 }43 }
43 44
@@ -66,6 +67,11 @@ int test__perf_evsel__tp_sched_test(void) · 22 unmodified lines
66 67
67 evsel = perf_evsel__newtp("sched", "sched_wakeup");68 evsel = perf_evsel__newtp("sched", "sched_wakeup");
68 69
70 if (IS_ERR(evsel)) {
71 pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
72 return -1;
73 }
74
69 if (perf_evsel__test_field(evsel, "comm", 16, true))75 if (perf_evsel__test_field(evsel, "comm", 16, true))
70 ret = -1;76 ret = -1;
71 77
tools/perf/tests/hists_filter.c+45−10
@@ -16,30 +16,31 @@ struct sample { · 15 unmodified lines
16 struct thread *thread;16 struct thread *thread;
17 struct map *map;17 struct map *map;
18 struct symbol *sym;18 struct symbol *sym;
19 int socket;
19};20};
20 21
21/* For the numbers, see hists_common.c */22/* For the numbers, see hists_common.c */
22static struct sample fake_samples[] = {23static struct sample fake_samples[] = {
23 /* perf [kernel] schedule() */24 /* perf [kernel] schedule() */
24 { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },25 { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, .socket = 0 },
25 /* perf [perf] main() */26 /* perf [perf] main() */
26 { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, },27 { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, .socket = 0 },
27 /* perf [libc] malloc() */28 /* perf [libc] malloc() */
28 { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },29 { .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, .socket = 0 },
29 /* perf [perf] main() */30 /* perf [perf] main() */
30 { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, /* will be merged */31 { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, .socket = 0 }, /* will be merged */
31 /* perf [perf] cmd_record() */32 /* perf [perf] cmd_record() */
32 { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, },33 { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, .socket = 1 },
33 /* perf [kernel] page_fault() */34 /* perf [kernel] page_fault() */
34 { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },35 { .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, .socket = 1 },
35 /* bash [bash] main() */36 /* bash [bash] main() */
36 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, },37 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, .socket = 2 },
37 /* bash [bash] xmalloc() */38 /* bash [bash] xmalloc() */
38 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, },39 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, .socket = 2 },
39 /* bash [libc] malloc() */40 /* bash [libc] malloc() */
40 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, },41 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_LIBC_MALLOC, .socket = 3 },
41 /* bash [kernel] page_fault() */42 /* bash [kernel] page_fault() */
42 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },43 { .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, .socket = 3 },
43};44};
44 45
45static int add_hist_entries(struct perf_evlist *evlist,46static int add_hist_entries(struct perf_evlist *evlist,
@@ -83,6 +84,7 @@ static int add_hist_entries(struct perf_evlist *evlist, · 37 unmodified lines
83 &sample) < 0)84 &sample) < 0)
84 goto out;85 goto out;
85 86
87 al.socket = fake_samples[i].socket;
86 if (hist_entry_iter__add(&iter, &al,88 if (hist_entry_iter__add(&iter, &al,
87 PERF_MAX_STACK_DEPTH, NULL) < 0) {89 PERF_MAX_STACK_DEPTH, NULL) < 0) {
88 addr_location__put(&al);90 addr_location__put(&al);
@@ -253,6 +255,39 @@ int test__hists_filter(void) · 164 unmodified lines
253 TEST_ASSERT_VAL("Unmatched total period for symbol filter",255 TEST_ASSERT_VAL("Unmatched total period for symbol filter",
254 hists->stats.total_non_filtered_period == 300);256 hists->stats.total_non_filtered_period == 300);
255 257
258 /* remove symbol filter first */
259 hists->symbol_filter_str = NULL;
260 hists__filter_by_symbol(hists);
261
262 /* now applying socket filters */
263 hists->socket_filter = 2;
264 hists__filter_by_socket(hists);
265
266 if (verbose > 2) {
267 pr_info("Histogram for socket filters\n");
268 print_hists_out(hists);
269 }
270
271 /* normal stats should be invariant */
272 TEST_ASSERT_VAL("Invalid nr samples",
273 hists->stats.nr_events[PERF_RECORD_SAMPLE] == 10);
274 TEST_ASSERT_VAL("Invalid nr hist entries",
275 hists->nr_entries == 9);
276 TEST_ASSERT_VAL("Invalid total period",
277 hists->stats.total_period == 1000);
278
279 /* but filter stats are changed */
280 TEST_ASSERT_VAL("Unmatched nr samples for socket filter",
281 hists->stats.nr_non_filtered_samples == 2);
282 TEST_ASSERT_VAL("Unmatched nr hist entries for socket filter",
283 hists->nr_non_filtered_entries == 2);
284 TEST_ASSERT_VAL("Unmatched total period for socket filter",
285 hists->stats.total_non_filtered_period == 200);
286
287 /* remove socket filter first */
288 hists->socket_filter = -1;
289 hists__filter_by_socket(hists);
290
256 /* now applying all filters at once. */291 /* now applying all filters at once. */
257 hists->thread_filter = fake_samples[1].thread;292 hists->thread_filter = fake_samples[1].thread;
258 hists->dso_filter = fake_samples[1].map->dso;293 hists->dso_filter = fake_samples[1].map->dso;
tools/perf/tests/make+3−1
@@ -44,6 +44,7 @@ make_no_libnuma := NO_LIBNUMA=1 · 43 unmodified lines
44make_no_libaudit := NO_LIBAUDIT=144make_no_libaudit := NO_LIBAUDIT=1
45make_no_libbionic := NO_LIBBIONIC=145make_no_libbionic := NO_LIBBIONIC=1
46make_no_auxtrace := NO_AUXTRACE=146make_no_auxtrace := NO_AUXTRACE=1
47make_no_libbpf := NO_LIBBPF=1
47make_tags := tags48make_tags := tags
48make_cscope := cscope49make_cscope := cscope
49make_help := help50make_help := help
@@ -66,7 +67,7 @@ make_static := LDFLAGS=-static · 16 unmodified lines
66make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=167make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
67make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=168make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
68make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=169make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
69make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=170make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
70 71
71# $(run) contains all available tests72# $(run) contains all available tests
72run := make_pure73run := make_pure
@@ -94,6 +95,7 @@ run += make_no_libnuma · 21 unmodified lines
94run += make_no_libaudit95run += make_no_libaudit
95run += make_no_libbionic96run += make_no_libbionic
96run += make_no_auxtrace97run += make_no_auxtrace
98run += make_no_libbpf
97run += make_help99run += make_help
98run += make_doc100run += make_doc
99run += make_perf_o101run += make_perf_o
tools/perf/tests/mmap-basic.c+2−1
@@ -3,6 +3,7 @@ · 2 unmodified lines
3#include "thread_map.h"3#include "thread_map.h"
4#include "cpumap.h"4#include "cpumap.h"
5#include "tests.h"5#include "tests.h"
6#include <linux/err.h>
6 7
7/*8/*
8 * This test will generate random numbers of calls to some getpid syscalls,9 * This test will generate random numbers of calls to some getpid syscalls,
@@ -65,7 +66,7 @@ int test__basic_mmap(void) · 56 unmodified lines
65 66
66 snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);67 snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);
67 evsels[i] = perf_evsel__newtp("syscalls", name);68 evsels[i] = perf_evsel__newtp("syscalls", name);
68 if (evsels[i] == NULL) {69 if (IS_ERR(evsels[i])) {
69 pr_debug("perf_evsel__new\n");70 pr_debug("perf_evsel__new\n");
70 goto out_delete_evlist;71 goto out_delete_evlist;
71 }72 }
tools/perf/tests/openat-syscall-all-cpus.c+6−7
@@ -1,3 +1,5 @@
1#include <api/fs/fs.h>
2#include <linux/err.h>
1#include "evsel.h"3#include "evsel.h"
2#include "tests.h"4#include "tests.h"
3#include "thread_map.h"5#include "thread_map.h"
@@ -14,6 +16,7 @@ int test__openat_syscall_event_on_all_cpus(void) · 10 unmodified lines
14 cpu_set_t cpu_set;16 cpu_set_t cpu_set;
15 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);17 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
16 char sbuf[STRERR_BUFSIZE];18 char sbuf[STRERR_BUFSIZE];
19 char errbuf[BUFSIZ];
17 20
18 if (threads == NULL) {21 if (threads == NULL) {
19 pr_debug("thread_map__new\n");22 pr_debug("thread_map__new\n");
@@ -29,13 +32,9 @@ int test__openat_syscall_event_on_all_cpus(void) · 9 unmodified lines
29 CPU_ZERO(&cpu_set);32 CPU_ZERO(&cpu_set);
30 33
31 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");34 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
32 if (evsel == NULL) {35 if (IS_ERR(evsel)) {
33 if (tracefs_configured())36 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
34 pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");37 pr_debug("%s\n", errbuf);
35 else if (debugfs_configured())
36 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
37 else
38 pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
39 goto out_thread_map_delete;38 goto out_thread_map_delete;
40 }39 }
41 40
tools/perf/tests/openat-syscall-tp-fields.c+3−2
@@ -1,3 +1,4 @@
1#include <linux/err.h>
1#include "perf.h"2#include "perf.h"
2#include "evlist.h"3#include "evlist.h"
3#include "evsel.h"4#include "evsel.h"
@@ -30,7 +31,7 @@ int test__syscall_openat_tp_fields(void) · 26 unmodified lines
30 }31 }
31 32
32 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");33 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
33 if (evsel == NULL) {34 if (IS_ERR(evsel)) {
34 pr_debug("%s: perf_evsel__newtp\n", __func__);35 pr_debug("%s: perf_evsel__newtp\n", __func__);
35 goto out_delete_evlist;36 goto out_delete_evlist;
36 }37 }
@@ -88,7 +89,7 @@ int test__syscall_openat_tp_fields(void) · 51 unmodified lines
88 89
89 err = perf_evsel__parse_sample(evsel, event, &sample);90 err = perf_evsel__parse_sample(evsel, event, &sample);
90 if (err) {91 if (err) {
91 pr_err("Can't parse sample, err = %d\n", err);92 pr_debug("Can't parse sample, err = %d\n", err);
92 goto out_delete_evlist;93 goto out_delete_evlist;
93 }94 }
94 95
tools/perf/tests/openat-syscall.c+6−7
@@ -1,3 +1,5 @@
1#include <api/fs/tracing_path.h>
2#include <linux/err.h>
1#include "thread_map.h"3#include "thread_map.h"
2#include "evsel.h"4#include "evsel.h"
3#include "debug.h"5#include "debug.h"
@@ -10,6 +12,7 @@ int test__openat_syscall_event(void) · 6 unmodified lines
10 unsigned int nr_openat_calls = 111, i;12 unsigned int nr_openat_calls = 111, i;
11 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);13 struct thread_map *threads = thread_map__new(-1, getpid(), UINT_MAX);
12 char sbuf[STRERR_BUFSIZE];14 char sbuf[STRERR_BUFSIZE];
15 char errbuf[BUFSIZ];
13 16
14 if (threads == NULL) {17 if (threads == NULL) {
15 pr_debug("thread_map__new\n");18 pr_debug("thread_map__new\n");
@@ -17,13 +20,9 @@ int test__openat_syscall_event(void) · 1 unmodified line
17 }20 }
18 21
19 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");22 evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
20 if (evsel == NULL) {23 if (IS_ERR(evsel)) {
21 if (tracefs_configured())24 tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
22 pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");25 pr_debug("%s\n", errbuf);
23 else if (debugfs_configured())
24 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
25 else
26 pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
27 goto out_thread_map_delete;26 goto out_thread_map_delete;
28 }27 }
29 28
tools/perf/tests/parse-events.c+33−16
@@ -3,11 +3,11 @@ · 2 unmodified lines
3#include "evsel.h"3#include "evsel.h"
4#include "evlist.h"4#include "evlist.h"
5#include <api/fs/fs.h>5#include <api/fs/fs.h>
6#include <api/fs/tracefs.h>
7#include <api/fs/debugfs.h>
8#include "tests.h"6#include "tests.h"
9#include "debug.h"7#include "debug.h"
8#include "util.h"
10#include <linux/hw_breakpoint.h>9#include <linux/hw_breakpoint.h>
10#include <api/fs/fs.h>
11 11
12#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \12#define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
13 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)13 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
@@ -1260,25 +1260,24 @@ test__checkevent_breakpoint_len_rw_modifier(struct perf_evlist *evlist) · 1246 unmodified lines
1260 return test__checkevent_breakpoint_rw(evlist);1260 return test__checkevent_breakpoint_rw(evlist);
1261}1261}
1262 1262
1263static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
1264{
1265 struct perf_evsel *evsel = perf_evlist__first(evlist);
1266
1267 TEST_ASSERT_VAL("wrong number of entries", 2 == evlist->nr_entries);
1268 TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
1269 TEST_ASSERT_VAL("wrong config",
1270 PERF_COUNT_SW_TASK_CLOCK == evsel->attr.config);
1271 return 0;
1272}
1273
1263static int count_tracepoints(void)1274static int count_tracepoints(void)
1264{1275{
1265 char events_path[PATH_MAX];
1266 struct dirent *events_ent;1276 struct dirent *events_ent;
1267 const char *mountpoint;
1268 DIR *events_dir;1277 DIR *events_dir;
1269 int cnt = 0;1278 int cnt = 0;
1270 1279
1271 mountpoint = tracefs_find_mountpoint();1280 events_dir = opendir(tracing_events_path);
1272 if (mountpoint) {
1273 scnprintf(events_path, PATH_MAX, "%s/events",
1274 mountpoint);
1275 } else {
1276 mountpoint = debugfs_find_mountpoint();
1277 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
1278 mountpoint);
1279 }
1280
1281 events_dir = opendir(events_path);
1282 1281
1283 TEST_ASSERT_VAL("Can't open events dir", events_dir);1282 TEST_ASSERT_VAL("Can't open events dir", events_dir);
1284 1283
@@ -1295,7 +1294,7 @@ static int count_tracepoints(void) · 10 unmodified lines
1295 continue;1294 continue;
1296 1295
1297 scnprintf(sys_path, PATH_MAX, "%s/%s",1296 scnprintf(sys_path, PATH_MAX, "%s/%s",
1298 events_path, events_ent->d_name);1297 tracing_events_path, events_ent->d_name);
1299 1298
1300 sys_dir = opendir(sys_path);1299 sys_dir = opendir(sys_path);
1301 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);1300 TEST_ASSERT_VAL("Can't open sys dir", sys_dir);
@@ -1575,6 +1574,11 @@ static struct evlist_test test__events[] = { · 273 unmodified lines
1575 .check = test__checkevent_exclude_idle_modifier_1,1574 .check = test__checkevent_exclude_idle_modifier_1,
1576 .id = 46,1575 .id = 46,
1577 },1576 },
1577 {
1578 .name = "task-clock:P,cycles",
1579 .check = test__checkevent_precise_max_modifier,
1580 .id = 47,
1581 },
1578};1582};
1579 1583
1580static struct evlist_test test__events_pmu[] = {1584static struct evlist_test test__events_pmu[] = {
@@ -1750,6 +1754,17 @@ static int test_pmu_events(void) · 169 unmodified lines
1750 return ret;1754 return ret;
1751}1755}
1752 1756
1757static void debug_warn(const char *warn, va_list params)
1758{
1759 char msg[1024];
1760
1761 if (!verbose)
1762 return;
1763
1764 vsnprintf(msg, sizeof(msg), warn, params);
1765 fprintf(stderr, " Warning: %s\n", msg);
1766}
1767
1753int test__parse_events(void)1768int test__parse_events(void)
1754{1769{
1755 int ret1, ret2 = 0;1770 int ret1, ret2 = 0;
@@ -1761,6 +1776,8 @@ do { \ · 5 unmodified lines
1761 ret2 = ret1; \1776 ret2 = ret1; \
1762} while (0)1777} while (0)
1763 1778
1779 set_warning_routine(debug_warn);
1780
1764 TEST_EVENTS(test__events);1781 TEST_EVENTS(test__events);
1765 1782
1766 if (test_pmu())1783 if (test_pmu())
tools/perf/tests/tests.h+7−3
@@ -24,13 +24,17 @@ enum { · 23 unmodified lines
24 TEST_SKIP = -2,24 TEST_SKIP = -2,
25};25};
26 26
27struct test {
28 const char *desc;
29 int (*func)(void);
30};
31
27/* Tests */32/* Tests */
28int test__vmlinux_matches_kallsyms(void);33int test__vmlinux_matches_kallsyms(void);
29int test__openat_syscall_event(void);34int test__openat_syscall_event(void);
30int test__openat_syscall_event_on_all_cpus(void);35int test__openat_syscall_event_on_all_cpus(void);
31int test__basic_mmap(void);36int test__basic_mmap(void);
32int test__PERF_RECORD(void);37int test__PERF_RECORD(void);
33int test__rdpmc(void);
34int test__perf_evsel__roundtrip_name_test(void);38int test__perf_evsel__roundtrip_name_test(void);
35int test__perf_evsel__tp_sched_test(void);39int test__perf_evsel__tp_sched_test(void);
36int test__syscall_openat_tp_fields(void);40int test__syscall_openat_tp_fields(void);
@@ -46,7 +50,6 @@ int test__bp_signal(void); · 9 unmodified lines
46int test__bp_signal_overflow(void);50int test__bp_signal_overflow(void);
47int test__task_exit(void);51int test__task_exit(void);
48int test__sw_clock_freq(void);52int test__sw_clock_freq(void);
49int test__perf_time_to_tsc(void);
50int test__code_reading(void);53int test__code_reading(void);
51int test__sample_parsing(void);54int test__sample_parsing(void);
52int test__keep_tracking(void);55int test__keep_tracking(void);
@@ -63,8 +66,9 @@ int test__fdarray__add(void); · 10 unmodified lines
63int test__kmod_path__parse(void);66int test__kmod_path__parse(void);
64int test__thread_map(void);67int test__thread_map(void);
65int test__llvm(void);68int test__llvm(void);
69int test_session_topology(void);
66 70
67#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)71#if defined(__arm__) || defined(__aarch64__)
68#ifdef HAVE_DWARF_UNWIND_SUPPORT72#ifdef HAVE_DWARF_UNWIND_SUPPORT
69struct thread;73struct thread;
70struct perf_sample;74struct perf_sample;
tools/perf/tests/topology.c+115−0
@@ -0,0 +1,115 @@
1#include <string.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include "tests.h"
5#include "util.h"
6#include "session.h"
7#include "evlist.h"
8#include "debug.h"
9
10#define TEMPL "/tmp/perf-test-XXXXXX"
11#define DATA_SIZE 10
12
13static int get_temp(char *path)
14{
15 int fd;
16
17 strcpy(path, TEMPL);
18
19 fd = mkstemp(path);
20 if (fd < 0) {
21 perror("mkstemp failed");
22 return -1;
23 }
24
25 close(fd);
26 return 0;
27}
28
29static int session_write_header(char *path)
30{
31 struct perf_session *session;
32 struct perf_data_file file = {
33 .path = path,
34 .mode = PERF_DATA_MODE_WRITE,
35 };
36
37 session = perf_session__new(&file, false, NULL);
38 TEST_ASSERT_VAL("can't get session", session);
39
40 session->evlist = perf_evlist__new_default();
41 TEST_ASSERT_VAL("can't get evlist", session->evlist);
42
43 perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY);
44 perf_header__set_feat(&session->header, HEADER_NRCPUS);
45
46 session->header.data_size += DATA_SIZE;
47
48 TEST_ASSERT_VAL("failed to write header",
49 !perf_session__write_header(session, session->evlist, file.fd, true));
50
51 perf_session__delete(session);
52
53 return 0;
54}
55
56static int check_cpu_topology(char *path, struct cpu_map *map)
57{
58 struct perf_session *session;
59 struct perf_data_file file = {
60 .path = path,
61 .mode = PERF_DATA_MODE_READ,
62 };
63 int i;
64
65 session = perf_session__new(&file, false, NULL);
66 TEST_ASSERT_VAL("can't get session", session);
67
68 for (i = 0; i < session->header.env.nr_cpus_online; i++) {
69 pr_debug("CPU %d, core %d, socket %d\n", i,
70 session->header.env.cpu[i].core_id,
71 session->header.env.cpu[i].socket_id);
72 }
73
74 for (i = 0; i < map->nr; i++) {
75 TEST_ASSERT_VAL("Core ID doesn't match",
76 (session->header.env.cpu[map->map[i]].core_id == (cpu_map__get_core(map, i, NULL) & 0xffff)));
77
78 TEST_ASSERT_VAL("Socket ID doesn't match",
79 (session->header.env.cpu[map->map[i]].socket_id == cpu_map__get_socket(map, i, NULL)));
80 }
81
82 perf_session__delete(session);
83
84 return 0;
85}
86
87int test_session_topology(void)
88{
89 char path[PATH_MAX];
90 struct cpu_map *map;
91 int ret = -1;
92
93 TEST_ASSERT_VAL("can't get templ file", !get_temp(path));
94
95 pr_debug("templ file: %s\n", path);
96
97 if (session_write_header(path))
98 goto free_path;
99
100 map = cpu_map__new(NULL);
101 if (map == NULL) {
102 pr_debug("failed to get system cpumap\n");
103 goto free_path;
104 }
105
106 if (check_cpu_topology(path, map))
107 goto free_map;
108 ret = 0;
109
110free_map:
111 cpu_map__put(map);
112free_path:
113 unlink(path);
114 return ret;
115}
tools/perf/tests/vmlinux-kallsyms.c+2−2
@@ -68,7 +68,7 @@ int test__vmlinux_matches_kallsyms(void) · 67 unmodified lines
68 * to see if the running kernel was relocated by checking if it has the68 * to see if the running kernel was relocated by checking if it has the
69 * same value in the vmlinux file we load.69 * same value in the vmlinux file we load.
70 */70 */
71 kallsyms_map = machine__kernel_map(&kallsyms, type);71 kallsyms_map = machine__kernel_map(&kallsyms);
72 72
73 /*73 /*
74 * Step 5:74 * Step 5:
@@ -80,7 +80,7 @@ int test__vmlinux_matches_kallsyms(void) · 5 unmodified lines
80 goto out;80 goto out;
81 }81 }
82 82
83 vmlinux_map = machine__kernel_map(&vmlinux, type);83 vmlinux_map = machine__kernel_map(&vmlinux);
84 84
85 /*85 /*
86 * Step 6:86 * Step 6:
tools/perf/trace/strace/groups/file+2−0
@@ -9,6 +9,7 @@ mkdir · 8 unmodified lines
9open9open
10openat10openat
11quotactl11quotactl
12read
12readlink13readlink
13rename14rename
14rmdir15rmdir
@@ -16,3 +17,4 @@ stat · 1 unmodified line
16statfs17statfs
17symlink18symlink
18unlink19unlink
20write
tools/perf/ui/browser.c+14−0
@@ -393,6 +393,7 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs) · 392 unmodified lines
393 393
394 if (browser->use_navkeypressed && !browser->navkeypressed) {394 if (browser->use_navkeypressed && !browser->navkeypressed) {
395 if (key == K_DOWN || key == K_UP ||395 if (key == K_DOWN || key == K_UP ||
396 (browser->columns && (key == K_LEFT || key == K_RIGHT)) ||
396 key == K_PGDN || key == K_PGUP ||397 key == K_PGDN || key == K_PGUP ||
397 key == K_HOME || key == K_END ||398 key == K_HOME || key == K_END ||
398 key == ' ') {399 key == ' ') {
@@ -421,6 +422,18 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs) · 22 unmodified lines
421 browser->seek(browser, -1, SEEK_CUR);422 browser->seek(browser, -1, SEEK_CUR);
422 }423 }
423 break;424 break;
425 case K_RIGHT:
426 if (!browser->columns)
427 goto out;
428 if (browser->horiz_scroll < browser->columns - 1)
429 ++browser->horiz_scroll;
430 break;
431 case K_LEFT:
432 if (!browser->columns)
433 goto out;
434 if (browser->horiz_scroll != 0)
435 --browser->horiz_scroll;
436 break;
424 case K_PGDN:437 case K_PGDN:
425 case ' ':438 case ' ':
426 if (browser->top_idx + browser->rows > browser->nr_entries - 1)439 if (browser->top_idx + browser->rows > browser->nr_entries - 1)
@@ -459,6 +472,7 @@ int ui_browser__run(struct ui_browser *browser, int delay_secs) · 32 unmodified lines
459 browser->seek(browser, -offset, SEEK_END);472 browser->seek(browser, -offset, SEEK_END);
460 break;473 break;
461 default:474 default:
475 out:
462 return key;476 return key;
463 }477 }
464 }478 }
tools/perf/ui/browser.h+1−1
@@ -14,7 +14,7 @@ · 13 unmodified lines
14struct ui_browser {14struct ui_browser {
15 u64 index, top_idx;15 u64 index, top_idx;
16 void *top, *entries;16 void *top, *entries;
17 u16 y, x, width, height, rows;17 u16 y, x, width, height, rows, columns, horiz_scroll;
18 int current_color;18 int current_color;
19 void *priv;19 void *priv;
20 const char *title;20 const char *title;
tools/perf/ui/browsers/annotate.c+7−7
@@ -768,8 +768,8 @@ static int annotate_browser__run(struct annotate_browser *browser, · 767 unmodified lines
768 "UP/DOWN/PGUP\n"768 "UP/DOWN/PGUP\n"
769 "PGDN/SPACE Navigate\n"769 "PGDN/SPACE Navigate\n"
770 "q/ESC/CTRL+C Exit\n\n"770 "q/ESC/CTRL+C Exit\n\n"
771 "-> Go to target\n"771 "ENTER Go to target\n"
772 "<- Exit\n"772 "ESC Exit\n"
773 "H Cycle thru hottest instructions\n"773 "H Cycle thru hottest instructions\n"
774 "j Toggle showing jump to target arrows\n"774 "j Toggle showing jump to target arrows\n"
775 "J Toggle showing number of jump sources on targets\n"775 "J Toggle showing number of jump sources on targets\n"
@@ -1056,7 +1056,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, · 280 unmodified lines
1056 goto out_free_offsets;1056 goto out_free_offsets;
1057 }1057 }
1058 1058
1059 ui_helpline__push("Press <- or ESC to exit");1059 ui_helpline__push("Press ESC to exit");
1060 1060
1061 notes = symbol__annotation(sym);1061 notes = symbol__annotation(sym);
1062 browser.start = map__rip_2objdump(map, sym->start);1062 browser.start = map__rip_2objdump(map, sym->start);
@@ -1125,8 +1125,8 @@ static struct annotate_config { · 62 unmodified lines
1125 ANNOTATE_CFG(jump_arrows),1125 ANNOTATE_CFG(jump_arrows),
1126 ANNOTATE_CFG(show_linenr),1126 ANNOTATE_CFG(show_linenr),
1127 ANNOTATE_CFG(show_nr_jumps),1127 ANNOTATE_CFG(show_nr_jumps),
1128 ANNOTATE_CFG(use_offset),
1129 ANNOTATE_CFG(show_total_period),1128 ANNOTATE_CFG(show_total_period),
1129 ANNOTATE_CFG(use_offset),
1130};1130};
1131 1131
1132#undef ANNOTATE_CFG1132#undef ANNOTATE_CFG
@@ -1152,9 +1152,9 @@ static int annotate__config(const char *var, const char *value, · 19 unmodified lines
1152 sizeof(struct annotate_config), annotate_config__cmp);1152 sizeof(struct annotate_config), annotate_config__cmp);
1153 1153
1154 if (cfg == NULL)1154 if (cfg == NULL)
1155 return -1;1155 ui__warning("%s variable unknown, ignoring...", var);
1156 1156 else
1157 *cfg->value = perf_config_bool(name, value);1157 *cfg->value = perf_config_bool(name, value);
1158 return 0;1158 return 0;
1159}1159}
1160 1160
tools/perf/ui/browsers/hists.c+95−25
@@ -784,11 +784,12 @@ static int hist_browser__show_entry(struct hist_browser *browser, · 783 unmodified lines
784 .size = sizeof(s),784 .size = sizeof(s),
785 .ptr = &arg,785 .ptr = &arg,
786 };786 };
787 int column = 0;
787 788
788 hist_browser__gotorc(browser, row, 0);789 hist_browser__gotorc(browser, row, 0);
789 790
790 perf_hpp__for_each_format(fmt) {791 perf_hpp__for_each_format(fmt) {
791 if (perf_hpp__should_skip(fmt))792 if (perf_hpp__should_skip(fmt) || column++ < browser->b.horiz_scroll)
792 continue;793 continue;
793 794
794 if (current_entry && browser->b.navkeypressed) {795 if (current_entry && browser->b.navkeypressed) {
@@ -861,14 +862,16 @@ static int advance_hpp_check(struct perf_hpp *hpp, int inc) · 66 unmodified lines
861 return hpp->size <= 0;862 return hpp->size <= 0;
862}863}
863 864
864static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists)865static int hists_browser__scnprintf_headers(struct hist_browser *browser, char *buf, size_t size)
865{866{
867 struct hists *hists = browser->hists;
866 struct perf_hpp dummy_hpp = {868 struct perf_hpp dummy_hpp = {
867 .buf = buf,869 .buf = buf,
868 .size = size,870 .size = size,
869 };871 };
870 struct perf_hpp_fmt *fmt;872 struct perf_hpp_fmt *fmt;
871 size_t ret = 0;873 size_t ret = 0;
874 int column = 0;
872 875
873 if (symbol_conf.use_callchain) {876 if (symbol_conf.use_callchain) {
874 ret = scnprintf(buf, size, " ");877 ret = scnprintf(buf, size, " ");
@@ -877,7 +880,7 @@ static int hists__scnprintf_headers(char *buf, size_t size, struct hists *hists) · 2 unmodified lines
877 }880 }
878 881
879 perf_hpp__for_each_format(fmt) {882 perf_hpp__for_each_format(fmt) {
880 if (perf_hpp__should_skip(fmt))883 if (perf_hpp__should_skip(fmt) || column++ < browser->b.horiz_scroll)
881 continue;884 continue;
882 885
883 ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));886 ret = fmt->header(fmt, &dummy_hpp, hists_to_evsel(hists));
@@ -896,7 +899,7 @@ static void hist_browser__show_headers(struct hist_browser *browser) · 12 unmodified lines
896{899{
897 char headers[1024];900 char headers[1024];
898 901
899 hists__scnprintf_headers(headers, sizeof(headers), browser->hists);902 hists_browser__scnprintf_headers(browser, headers, sizeof(headers));
900 ui_browser__gotorc(&browser->b, 0, 0);903 ui_browser__gotorc(&browser->b, 0, 0);
901 ui_browser__set_color(&browser->b, HE_COLORSET_ROOT);904 ui_browser__set_color(&browser->b, HE_COLORSET_ROOT);
902 ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1);905 ui_browser__write_nstring(&browser->b, headers, browser->b.width + 1);
@@ -1261,6 +1264,7 @@ static int hists__browser_title(struct hists *hists, · 358 unmodified lines
1261 int printed;1264 int printed;
1262 const struct dso *dso = hists->dso_filter;1265 const struct dso *dso = hists->dso_filter;
1263 const struct thread *thread = hists->thread_filter;1266 const struct thread *thread = hists->thread_filter;
1267 int socket_id = hists->socket_filter;
1264 unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];1268 unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
1265 u64 nr_events = hists->stats.total_period;1269 u64 nr_events = hists->stats.total_period;
1266 struct perf_evsel *evsel = hists_to_evsel(hists);1270 struct perf_evsel *evsel = hists_to_evsel(hists);
@@ -1314,6 +1318,9 @@ static int hists__browser_title(struct hists *hists, · 47 unmodified lines
1314 if (dso)1318 if (dso)
1315 printed += scnprintf(bf + printed, size - printed,1319 printed += scnprintf(bf + printed, size - printed,
1316 ", DSO: %s", dso->short_name);1320 ", DSO: %s", dso->short_name);
1321 if (socket_id > -1)
1322 printed += scnprintf(bf + printed, size - printed,
1323 ", Processor Socket: %d", socket_id);
1317 if (!is_report_browser(hbt)) {1324 if (!is_report_browser(hbt)) {
1318 struct perf_top *top = hbt->arg;1325 struct perf_top *top = hbt->arg;
1319 1326
@@ -1425,6 +1432,7 @@ struct popup_action { · 105 unmodified lines
1425 struct thread *thread;1432 struct thread *thread;
1426 struct dso *dso;1433 struct dso *dso;
1427 struct map_symbol ms;1434 struct map_symbol ms;
1435 int socket;
1428 1436
1429 int (*fn)(struct hist_browser *browser, struct popup_action *act);1437 int (*fn)(struct hist_browser *browser, struct popup_action *act);
1430};1438};
@@ -1437,7 +1445,7 @@ do_annotate(struct hist_browser *browser, struct popup_action *act) · 6 unmodified lines
1437 struct hist_entry *he;1445 struct hist_entry *he;
1438 int err;1446 int err;
1439 1447
1440 if (!objdump_path && perf_session_env__lookup_objdump(browser->env))1448 if (!objdump_path && perf_env__lookup_objdump(browser->env))
1441 return 0;1449 return 0;
1442 1450
1443 notes = symbol__annotation(act->ms.sym);1451 notes = symbol__annotation(act->ms.sym);
@@ -1488,7 +1496,7 @@ do_zoom_thread(struct hist_browser *browser, struct popup_action *act) · 44 unmodified lines
1488 thread__zput(browser->hists->thread_filter);1496 thread__zput(browser->hists->thread_filter);
1489 ui_helpline__pop();1497 ui_helpline__pop();
1490 } else {1498 } else {
1491 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",1499 ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s(%d) thread\"",
1492 thread->comm_set ? thread__comm_str(thread) : "",1500 thread->comm_set ? thread__comm_str(thread) : "",
1493 thread->tid);1501 thread->tid);
1494 browser->hists->thread_filter = thread__get(thread);1502 browser->hists->thread_filter = thread__get(thread);
@@ -1522,7 +1530,7 @@ add_thread_opt(struct hist_browser *browser, struct popup_action *act, · 27 unmodified lines
1522static int1530static int
1523do_zoom_dso(struct hist_browser *browser, struct popup_action *act)1531do_zoom_dso(struct hist_browser *browser, struct popup_action *act)
1524{1532{
1525 struct dso *dso = act->dso;1533 struct map *map = act->ms.map;
1526 1534
1527 if (browser->hists->dso_filter) {1535 if (browser->hists->dso_filter) {
1528 pstack__remove(browser->pstack, &browser->hists->dso_filter);1536 pstack__remove(browser->pstack, &browser->hists->dso_filter);
@@ -1530,11 +1538,11 @@ do_zoom_dso(struct hist_browser *browser, struct popup_action *act) · 1 unmodified line
1530 browser->hists->dso_filter = NULL;1538 browser->hists->dso_filter = NULL;
1531 ui_helpline__pop();1539 ui_helpline__pop();
1532 } else {1540 } else {
1533 if (dso == NULL)1541 if (map == NULL)
1534 return 0;1542 return 0;
1535 ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"",1543 ui_helpline__fpush("To zoom out press ESC or ENTER + \"Zoom out of %s DSO\"",
1536 dso->kernel ? "the Kernel" : dso->short_name);1544 __map__is_kernel(map) ? "the Kernel" : map->dso->short_name);
1537 browser->hists->dso_filter = dso;1545 browser->hists->dso_filter = map->dso;
1538 perf_hpp__set_elide(HISTC_DSO, true);1546 perf_hpp__set_elide(HISTC_DSO, true);
1539 pstack__push(browser->pstack, &browser->hists->dso_filter);1547 pstack__push(browser->pstack, &browser->hists->dso_filter);
1540 }1548 }
@@ -1546,17 +1554,18 @@ do_zoom_dso(struct hist_browser *browser, struct popup_action *act) · 5 unmodified lines
1546 1554
1547static int1555static int
1548add_dso_opt(struct hist_browser *browser, struct popup_action *act,1556add_dso_opt(struct hist_browser *browser, struct popup_action *act,
1549 char **optstr, struct dso *dso)1557 char **optstr, struct map *map)
1550{1558{
1551 if (dso == NULL)1559 if (map == NULL)
1552 return 0;1560 return 0;
1553 1561
1554 if (asprintf(optstr, "Zoom %s %s DSO",1562 if (asprintf(optstr, "Zoom %s %s DSO",
1555 browser->hists->dso_filter ? "out of" : "into",1563 browser->hists->dso_filter ? "out of" : "into",
1556 dso->kernel ? "the Kernel" : dso->short_name) < 0)1564 __map__is_kernel(map) ? "the Kernel" : map->dso->short_name) < 0)
1557 return 0;1565 return 0;
1558 1566
1559 act->dso = dso;1567 act->ms.map = map;
1568 act->dso = map->dso;
1560 act->fn = do_zoom_dso;1569 act->fn = do_zoom_dso;
1561 return 1;1570 return 1;
1562}1571}
@@ -1672,6 +1681,41 @@ add_exit_opt(struct hist_browser *browser __maybe_unused, · 109 unmodified lines
1672 return 1;1681 return 1;
1673}1682}
1674 1683
1684static int
1685do_zoom_socket(struct hist_browser *browser, struct popup_action *act)
1686{
1687 if (browser->hists->socket_filter > -1) {
1688 pstack__remove(browser->pstack, &browser->hists->socket_filter);
1689 browser->hists->socket_filter = -1;
1690 perf_hpp__set_elide(HISTC_SOCKET, false);
1691 } else {
1692 browser->hists->socket_filter = act->socket;
1693 perf_hpp__set_elide(HISTC_SOCKET, true);
1694 pstack__push(browser->pstack, &browser->hists->socket_filter);
1695 }
1696
1697 hists__filter_by_socket(browser->hists);
1698 hist_browser__reset(browser);
1699 return 0;
1700}
1701
1702static int
1703add_socket_opt(struct hist_browser *browser, struct popup_action *act,
1704 char **optstr, int socket_id)
1705{
1706 if (socket_id < 0)
1707 return 0;
1708
1709 if (asprintf(optstr, "Zoom %s Processor Socket %d",
1710 (browser->hists->socket_filter > -1) ? "out of" : "into",
1711 socket_id) < 0)
1712 return 0;
1713
1714 act->socket = socket_id;
1715 act->fn = do_zoom_socket;
1716 return 1;
1717}
1718
1675static void hist_browser__update_nr_entries(struct hist_browser *hb)1719static void hist_browser__update_nr_entries(struct hist_browser *hb)
1676{1720{
1677 u64 nr_entries = 0;1721 u64 nr_entries = 0;
@@ -1717,14 +1761,16 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 39 unmodified lines
1717 "For multiple event sessions:\n\n" \1761 "For multiple event sessions:\n\n" \
1718 "TAB/UNTAB Switch events\n\n" \1762 "TAB/UNTAB Switch events\n\n" \
1719 "For symbolic views (--sort has sym):\n\n" \1763 "For symbolic views (--sort has sym):\n\n" \
1720 "-> Zoom into DSO/Threads & Annotate current symbol\n" \1764 "ENTER Zoom into DSO/Threads & Annotate current symbol\n" \
1721 "<- Zoom out\n" \1765 "ESC Zoom out\n" \
1722 "a Annotate current symbol\n" \1766 "a Annotate current symbol\n" \
1723 "C Collapse all callchains\n" \1767 "C Collapse all callchains\n" \
1724 "d Zoom into current DSO\n" \1768 "d Zoom into current DSO\n" \
1725 "E Expand all callchains\n" \1769 "E Expand all callchains\n" \
1726 "F Toggle percentage of filtered entries\n" \1770 "F Toggle percentage of filtered entries\n" \
1727 "H Display column headers\n" \1771 "H Display column headers\n" \
1772 "m Display context menu\n" \
1773 "S Zoom into current Processor Socket\n" \
1728 1774
1729 /* help messages are sorted by lexical order of the hotkey */1775 /* help messages are sorted by lexical order of the hotkey */
1730 const char report_help[] = HIST_BROWSER_HELP_COMMON1776 const char report_help[] = HIST_BROWSER_HELP_COMMON
@@ -1755,7 +1801,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 24 unmodified lines
1755 hist_browser__update_nr_entries(browser);1801 hist_browser__update_nr_entries(browser);
1756 }1802 }
1757 1803
1758 browser->pstack = pstack__new(2);1804 browser->pstack = pstack__new(3);
1759 if (browser->pstack == NULL)1805 if (browser->pstack == NULL)
1760 goto out;1806 goto out;
1761 1807
@@ -1764,8 +1810,17 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 2 unmodified lines
1764 memset(options, 0, sizeof(options));1810 memset(options, 0, sizeof(options));
1765 memset(actions, 0, sizeof(actions));1811 memset(actions, 0, sizeof(actions));
1766 1812
1767 perf_hpp__for_each_format(fmt)1813 perf_hpp__for_each_format(fmt) {
1768 perf_hpp__reset_width(fmt, hists);1814 perf_hpp__reset_width(fmt, hists);
1815 /*
1816 * This is done just once, and activates the horizontal scrolling
1817 * code in the ui_browser code, it would be better to have a the
1818 * counter in the perf_hpp code, but I couldn't find doing it here
1819 * works, FIXME by setting this in hist_browser__new, for now, be
1820 * clever 8-)
1821 */
1822 ++browser->b.columns;
1823 }
1769 1824
1770 if (symbol_conf.col_width_list_str)1825 if (symbol_conf.col_width_list_str)
1771 perf_hpp__set_user_width(symbol_conf.col_width_list_str);1826 perf_hpp__set_user_width(symbol_conf.col_width_list_str);
@@ -1773,7 +1828,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 1 unmodified line
1773 while (1) {1828 while (1) {
1774 struct thread *thread = NULL;1829 struct thread *thread = NULL;
1775 struct dso *dso = NULL;1830 struct dso *dso = NULL;
1831 struct map *map = NULL;
1776 int choice = 0;1832 int choice = 0;
1833 int socked_id = -1;
1777 1834
1778 nr_options = 0;1835 nr_options = 0;
1779 1836
@@ -1781,7 +1838,10 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 1 unmodified line
1781 1838
1782 if (browser->he_selection != NULL) {1839 if (browser->he_selection != NULL) {
1783 thread = hist_browser__selected_thread(browser);1840 thread = hist_browser__selected_thread(browser);
1784 dso = browser->selection->map ? browser->selection->map->dso : NULL;1841 map = browser->selection->map;
1842 if (map)
1843 dso = map->dso;
1844 socked_id = browser->he_selection->socket;
1785 }1845 }
1786 switch (key) {1846 switch (key) {
1787 case K_TAB:1847 case K_TAB:
@@ -1824,9 +1884,14 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 36 unmodified lines
1824 actions->thread = thread;1884 actions->thread = thread;
1825 do_zoom_thread(browser, actions);1885 do_zoom_thread(browser, actions);
1826 continue;1886 continue;
1887 case 'S':
1888 actions->socket = socked_id;
1889 do_zoom_socket(browser, actions);
1890 continue;
1827 case '/':1891 case '/':
1828 if (ui_browser__input_window("Symbol to show",1892 if (ui_browser__input_window("Symbol to show",
1829 "Please enter the name of symbol you want to see",1893 "Please enter the name of symbol you want to see.\n"
1894 "To remove the filter later, press / + ENTER.",
1830 buf, "ENTER: OK, ESC: Cancel",1895 buf, "ENTER: OK, ESC: Cancel",
1831 delay_secs * 2) == K_ENTER) {1896 delay_secs * 2) == K_ENTER) {
1832 hists->symbol_filter_str = *buf ? buf : NULL;1897 hists->symbol_filter_str = *buf ? buf : NULL;
@@ -1871,6 +1936,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 38 unmodified lines
1871 continue;1936 continue;
1872 case K_ENTER:1937 case K_ENTER:
1873 case K_RIGHT:1938 case K_RIGHT:
1939 case 'm':
1874 /* menu */1940 /* menu */
1875 break;1941 break;
1876 case K_ESC:1942 case K_ESC:
@@ -1899,9 +1965,11 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, · 22 unmodified lines
1899 * Ditto for thread below.1965 * Ditto for thread below.
1900 */1966 */
1901 do_zoom_dso(browser, actions);1967 do_zoom_dso(browser, actions);
1902 }1968 } else if (top == &browser->hists->thread_filter) {
1903 if (top == &browser->hists->thread_filter)
1904 do_zoom_thread(browser, actions);1969 do_zoom_thread(browser, actions);
1970 } else if (top == &browser->hists->socket_filter) {
1971 do_zoom_socket(browser, actions);
1972 }
1905 continue;1973 continue;
1906 }1974 }
1907 case 'q':1975 case 'q':
@@ -1965,12 +2033,14 @@ skip_annotation: · 57 unmodified lines
1965 nr_options += add_thread_opt(browser, &actions[nr_options],2033 nr_options += add_thread_opt(browser, &actions[nr_options],
1966 &options[nr_options], thread);2034 &options[nr_options], thread);
1967 nr_options += add_dso_opt(browser, &actions[nr_options],2035 nr_options += add_dso_opt(browser, &actions[nr_options],
1968 &options[nr_options], dso);2036 &options[nr_options], map);
1969 nr_options += add_map_opt(browser, &actions[nr_options],2037 nr_options += add_map_opt(browser, &actions[nr_options],
1970 &options[nr_options],2038 &options[nr_options],
1971 browser->selection ?2039 browser->selection ?
1972 browser->selection->map : NULL);2040 browser->selection->map : NULL);
1973 2041 nr_options += add_socket_opt(browser, &actions[nr_options],
2042 &options[nr_options],
2043 socked_id);
1974 /* perf script support */2044 /* perf script support */
1975 if (browser->he_selection) {2045 if (browser->he_selection) {
1976 nr_options += add_script_opt(browser,2046 nr_options += add_script_opt(browser,
tools/perf/ui/browsers/map.c+1−1
@@ -72,7 +72,7 @@ static int map_browser__run(struct map_browser *browser) · 71 unmodified lines
72 int key;72 int key;
73 73
74 if (ui_browser__show(&browser->b, browser->map->dso->long_name,74 if (ui_browser__show(&browser->b, browser->map->dso->long_name,
75 "Press <- or ESC to exit, %s / to search",75 "Press ESC to exit, %s / to search",
76 verbose ? "" : "restart with -v to use") < 0)76 verbose ? "" : "restart with -v to use") < 0)
77 return -1;77 return -1;
78 78
tools/perf/ui/browsers/scripts.c+1−1
@@ -89,7 +89,7 @@ static int script_browser__run(struct perf_script_browser *browser) · 88 unmodified lines
89 int key;89 int key;
90 90
91 if (ui_browser__show(&browser->b, browser->script_name,91 if (ui_browser__show(&browser->b, browser->script_name,
92 "Press <- or ESC to exit") < 0)92 "Press ESC to exit") < 0)
93 return -1;93 return -1;
94 94
95 while (1) {95 while (1) {
tools/perf/ui/hist.c+8−8
@@ -463,27 +463,27 @@ void perf_hpp__init(void) · 462 unmodified lines
463 return;463 return;
464 464
465 if (symbol_conf.cumulate_callchain) {465 if (symbol_conf.cumulate_callchain) {
466 perf_hpp__column_enable(PERF_HPP__OVERHEAD_ACC);466 hpp_dimension__add_output(PERF_HPP__OVERHEAD_ACC);
467 perf_hpp__format[PERF_HPP__OVERHEAD].name = "Self";467 perf_hpp__format[PERF_HPP__OVERHEAD].name = "Self";
468 }468 }
469 469
470 perf_hpp__column_enable(PERF_HPP__OVERHEAD);470 hpp_dimension__add_output(PERF_HPP__OVERHEAD);
471 471
472 if (symbol_conf.show_cpu_utilization) {472 if (symbol_conf.show_cpu_utilization) {
473 perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS);473 hpp_dimension__add_output(PERF_HPP__OVERHEAD_SYS);
474 perf_hpp__column_enable(PERF_HPP__OVERHEAD_US);474 hpp_dimension__add_output(PERF_HPP__OVERHEAD_US);
475 475
476 if (perf_guest) {476 if (perf_guest) {
477 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS);477 hpp_dimension__add_output(PERF_HPP__OVERHEAD_GUEST_SYS);
478 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US);478 hpp_dimension__add_output(PERF_HPP__OVERHEAD_GUEST_US);
479 }479 }
480 }480 }
481 481
482 if (symbol_conf.show_nr_samples)482 if (symbol_conf.show_nr_samples)
483 perf_hpp__column_enable(PERF_HPP__SAMPLES);483 hpp_dimension__add_output(PERF_HPP__SAMPLES);
484 484
485 if (symbol_conf.show_total_period)485 if (symbol_conf.show_total_period)
486 perf_hpp__column_enable(PERF_HPP__PERIOD);486 hpp_dimension__add_output(PERF_HPP__PERIOD);
487 487
488 /* prepend overhead field for backward compatiblity. */488 /* prepend overhead field for backward compatiblity. */
489 list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list;489 list = &perf_hpp__format[PERF_HPP__OVERHEAD].sort_list;
tools/perf/ui/tui/setup.c+4−4
@@ -141,10 +141,6 @@ int ui__init(void) · 140 unmodified lines
141 141
142 SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);142 SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);
143 143
144 ui_helpline__init();
145 ui_browser__init();
146 tui_progress__init();
147
148 signal(SIGSEGV, ui__signal_backtrace);144 signal(SIGSEGV, ui__signal_backtrace);
149 signal(SIGFPE, ui__signal_backtrace);145 signal(SIGFPE, ui__signal_backtrace);
150 signal(SIGINT, ui__signal);146 signal(SIGINT, ui__signal);
@@ -153,6 +149,10 @@ int ui__init(void) · 2 unmodified lines
153 149
154 perf_error__register(&perf_tui_eops);150 perf_error__register(&perf_tui_eops);
155 151
152 ui_helpline__init();
153 ui_browser__init();
154 tui_progress__init();
155
156 hist_browser__init_hpp();156 hist_browser__init_hpp();
157out:157out:
158 return err;158 return err;
tools/perf/util/Build+2−0
@@ -5,6 +5,7 @@ libperf-y += build-id.o · 4 unmodified lines
5libperf-y += config.o5libperf-y += config.o
6libperf-y += ctype.o6libperf-y += ctype.o
7libperf-y += db-export.o7libperf-y += db-export.o
8libperf-y += env.o
8libperf-y += environment.o9libperf-y += environment.o
9libperf-y += event.o10libperf-y += event.o
10libperf-y += evlist.o11libperf-y += evlist.o
@@ -86,6 +87,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-bts.o · 75 unmodified lines
86libperf-y += parse-branch-options.o87libperf-y += parse-branch-options.o
87libperf-y += parse-regs-options.o88libperf-y += parse-regs-options.o
88 89
90libperf-$(CONFIG_LIBBPF) += bpf-loader.o
89libperf-$(CONFIG_LIBELF) += symbol-elf.o91libperf-$(CONFIG_LIBELF) += symbol-elf.o
90libperf-$(CONFIG_LIBELF) += probe-file.o92libperf-$(CONFIG_LIBELF) += probe-file.o
91libperf-$(CONFIG_LIBELF) += probe-event.o93libperf-$(CONFIG_LIBELF) += probe-event.o
tools/perf/util/annotate.c+4−1
@@ -548,8 +548,11 @@ static int __symbol__inc_addr_samples(struct symbol *sym, struct map *map, · 547 unmodified lines
548 548
549 pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));549 pr_debug3("%s: addr=%#" PRIx64 "\n", __func__, map->unmap_ip(map, addr));
550 550
551 if (addr < sym->start || addr >= sym->end)551 if (addr < sym->start || addr >= sym->end) {
552 pr_debug("%s(%d): ERANGE! sym->name=%s, start=%#" PRIx64 ", addr=%#" PRIx64 ", end=%#" PRIx64 "\n",
553 __func__, __LINE__, sym->name, sym->start, addr, sym->end);
552 return -ERANGE;554 return -ERANGE;
555 }
553 556
554 offset = addr - sym->start;557 offset = addr - sym->start;
555 h = annotation__histogram(notes, evidx);558 h = annotation__histogram(notes, evidx);
tools/perf/util/annotate.h+1−1
@@ -122,7 +122,7 @@ struct annotated_source { · 121 unmodified lines
122 struct list_head source;122 struct list_head source;
123 struct source_line *lines;123 struct source_line *lines;
124 int nr_histograms;124 int nr_histograms;
125 int sizeof_sym_hist;125 size_t sizeof_sym_hist;
126 struct cyc_hist *cycles_hist;126 struct cyc_hist *cycles_hist;
127 struct sym_hist histograms[0];127 struct sym_hist histograms[0];
128};128};
tools/perf/util/auxtrace.c+23−1
@@ -926,6 +926,8 @@ s64 perf_event__process_auxtrace(struct perf_tool *tool, · 925 unmodified lines
926#define PERF_ITRACE_DEFAULT_PERIOD 100000926#define PERF_ITRACE_DEFAULT_PERIOD 100000
927#define PERF_ITRACE_DEFAULT_CALLCHAIN_SZ 16927#define PERF_ITRACE_DEFAULT_CALLCHAIN_SZ 16
928#define PERF_ITRACE_MAX_CALLCHAIN_SZ 1024928#define PERF_ITRACE_MAX_CALLCHAIN_SZ 1024
929#define PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ 64
930#define PERF_ITRACE_MAX_LAST_BRANCH_SZ 1024
929 931
930void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)932void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts)
931{933{
@@ -936,6 +938,7 @@ void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts) · 4 unmodified lines
936 synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;938 synth_opts->period_type = PERF_ITRACE_DEFAULT_PERIOD_TYPE;
937 synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;939 synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
938 synth_opts->callchain_sz = PERF_ITRACE_DEFAULT_CALLCHAIN_SZ;940 synth_opts->callchain_sz = PERF_ITRACE_DEFAULT_CALLCHAIN_SZ;
941 synth_opts->last_branch_sz = PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ;
939}942}
940 943
941/*944/*
@@ -950,6 +953,7 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str, · 8 unmodified lines
950 const char *p;953 const char *p;
951 char *endptr;954 char *endptr;
952 bool period_type_set = false;955 bool period_type_set = false;
956 bool period_set = false;
953 957
954 synth_opts->set = true;958 synth_opts->set = true;
955 959
@@ -971,6 +975,7 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str, · 15 unmodified lines
971 p += 1;975 p += 1;
972 if (isdigit(*p)) {976 if (isdigit(*p)) {
973 synth_opts->period = strtoull(p, &endptr, 10);977 synth_opts->period = strtoull(p, &endptr, 10);
978 period_set = true;
974 p = endptr;979 p = endptr;
975 while (*p == ' ' || *p == ',')980 while (*p == ' ' || *p == ',')
976 p += 1;981 p += 1;
@@ -1041,6 +1046,23 @@ int itrace_parse_synth_opts(const struct option *opt, const char *str, · 64 unmodified lines
1041 synth_opts->callchain_sz = val;1046 synth_opts->callchain_sz = val;
1042 }1047 }
1043 break;1048 break;
1049 case 'l':
1050 synth_opts->last_branch = true;
1051 synth_opts->last_branch_sz =
1052 PERF_ITRACE_DEFAULT_LAST_BRANCH_SZ;
1053 while (*p == ' ' || *p == ',')
1054 p += 1;
1055 if (isdigit(*p)) {
1056 unsigned int val;
1057
1058 val = strtoul(p, &endptr, 10);
1059 p = endptr;
1060 if (!val ||
1061 val > PERF_ITRACE_MAX_LAST_BRANCH_SZ)
1062 goto out_err;
1063 synth_opts->last_branch_sz = val;
1064 }
1065 break;
1044 case ' ':1066 case ' ':
1045 case ',':1067 case ',':
1046 break;1068 break;
@@ -1053,7 +1075,7 @@ out: · 6 unmodified lines
1053 if (!period_type_set)1075 if (!period_type_set)
1054 synth_opts->period_type =1076 synth_opts->period_type =
1055 PERF_ITRACE_DEFAULT_PERIOD_TYPE;1077 PERF_ITRACE_DEFAULT_PERIOD_TYPE;
1056 if (!synth_opts->period)1078 if (!period_set)
1057 synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;1079 synth_opts->period = PERF_ITRACE_DEFAULT_PERIOD;
1058 }1080 }
1059 1081
tools/perf/util/auxtrace.h+4−0
@@ -63,7 +63,9 @@ enum itrace_period_type { · 62 unmodified lines
63 * @calls: limit branch samples to calls (can be combined with @returns)63 * @calls: limit branch samples to calls (can be combined with @returns)
64 * @returns: limit branch samples to returns (can be combined with @calls)64 * @returns: limit branch samples to returns (can be combined with @calls)
65 * @callchain: add callchain to 'instructions' events65 * @callchain: add callchain to 'instructions' events
66 * @last_branch: add branch context to 'instruction' events
66 * @callchain_sz: maximum callchain size67 * @callchain_sz: maximum callchain size
68 * @last_branch_sz: branch context size
67 * @period: 'instructions' events period69 * @period: 'instructions' events period
68 * @period_type: 'instructions' events period type70 * @period_type: 'instructions' events period type
69 */71 */
@@ -79,7 +81,9 @@ struct itrace_synth_opts { · 9 unmodified lines
79 bool calls;81 bool calls;
80 bool returns;82 bool returns;
81 bool callchain;83 bool callchain;
84 bool last_branch;
82 unsigned int callchain_sz;85 unsigned int callchain_sz;
86 unsigned int last_branch_sz;
83 unsigned long long period;87 unsigned long long period;
84 enum itrace_period_type period_type;88 enum itrace_period_type period_type;
85};89};
tools/perf/util/bpf-loader.c+352−0
@@ -0,0 +1,352 @@
1/*
2 * bpf-loader.c
3 *
4 * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
5 * Copyright (C) 2015 Huawei Inc.
6 */
7
8#include <bpf/libbpf.h>
9#include <linux/err.h>
10#include "perf.h"
11#include "debug.h"
12#include "bpf-loader.h"
13#include "probe-event.h"
14#include "probe-finder.h" // for MAX_PROBES
15#include "llvm-utils.h"
16
17#define DEFINE_PRINT_FN(name, level) \
18static int libbpf_##name(const char *fmt, ...) \
19{ \
20 va_list args; \
21 int ret; \
22 \
23 va_start(args, fmt); \
24 ret = veprintf(level, verbose, pr_fmt(fmt), args);\
25 va_end(args); \
26 return ret; \
27}
28
29DEFINE_PRINT_FN(warning, 0)
30DEFINE_PRINT_FN(info, 0)
31DEFINE_PRINT_FN(debug, 1)
32
33struct bpf_prog_priv {
34 struct perf_probe_event pev;
35};
36
37struct bpf_object *bpf__prepare_load(const char *filename, bool source)
38{
39 struct bpf_object *obj;
40 static bool libbpf_initialized;
41
42 if (!libbpf_initialized) {
43 libbpf_set_print(libbpf_warning,
44 libbpf_info,
45 libbpf_debug);
46 libbpf_initialized = true;
47 }
48
49 if (source) {
50 int err;
51 void *obj_buf;
52 size_t obj_buf_sz;
53
54 err = llvm__compile_bpf(filename, &obj_buf, &obj_buf_sz);
55 if (err)
56 return ERR_PTR(err);
57 obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename);
58 free(obj_buf);
59 } else
60 obj = bpf_object__open(filename);
61
62 if (!obj) {
63 pr_debug("bpf: failed to load %s\n", filename);
64 return ERR_PTR(-EINVAL);
65 }
66
67 return obj;
68}
69
70void bpf__clear(void)
71{
72 struct bpf_object *obj, *tmp;
73
74 bpf_object__for_each_safe(obj, tmp) {
75 bpf__unprobe(obj);
76 bpf_object__close(obj);
77 }
78}
79
80static void
81bpf_prog_priv__clear(struct bpf_program *prog __maybe_unused,
82 void *_priv)
83{
84 struct bpf_prog_priv *priv = _priv;
85
86 cleanup_perf_probe_events(&priv->pev, 1);
87 free(priv);
88}
89
90static int
91config_bpf_program(struct bpf_program *prog)
92{
93 struct perf_probe_event *pev = NULL;
94 struct bpf_prog_priv *priv = NULL;
95 const char *config_str;
96 int err;
97
98 config_str = bpf_program__title(prog, false);
99 if (!config_str) {
100 pr_debug("bpf: unable to get title for program\n");
101 return -EINVAL;
102 }
103
104 priv = calloc(sizeof(*priv), 1);
105 if (!priv) {
106 pr_debug("bpf: failed to alloc priv\n");
107 return -ENOMEM;
108 }
109 pev = &priv->pev;
110
111 pr_debug("bpf: config program '%s'\n", config_str);
112 err = parse_perf_probe_command(config_str, pev);
113 if (err < 0) {
114 pr_debug("bpf: '%s' is not a valid config string\n",
115 config_str);
116 err = -EINVAL;
117 goto errout;
118 }
119
120 if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) {
121 pr_debug("bpf: '%s': group for event is set and not '%s'.\n",
122 config_str, PERF_BPF_PROBE_GROUP);
123 err = -EINVAL;
124 goto errout;
125 } else if (!pev->group)
126 pev->group = strdup(PERF_BPF_PROBE_GROUP);
127
128 if (!pev->group) {
129 pr_debug("bpf: strdup failed\n");
130 err = -ENOMEM;
131 goto errout;
132 }
133
134 if (!pev->event) {
135 pr_debug("bpf: '%s': event name is missing\n",
136 config_str);
137 err = -EINVAL;
138 goto errout;
139 }
140 pr_debug("bpf: config '%s' is ok\n", config_str);
141
142 err = bpf_program__set_private(prog, priv, bpf_prog_priv__clear);
143 if (err) {
144 pr_debug("Failed to set priv for program '%s'\n", config_str);
145 goto errout;
146 }
147
148 return 0;
149
150errout:
151 if (pev)
152 clear_perf_probe_event(pev);
153 free(priv);
154 return err;
155}
156
157static int bpf__prepare_probe(void)
158{
159 static int err = 0;
160 static bool initialized = false;
161
162 /*
163 * Make err static, so if init failed the first, bpf__prepare_probe()
164 * fails each time without calling init_probe_symbol_maps multiple
165 * times.
166 */
167 if (initialized)
168 return err;
169
170 initialized = true;
171 err = init_probe_symbol_maps(false);
172 if (err < 0)
173 pr_debug("Failed to init_probe_symbol_maps\n");
174 probe_conf.max_probes = MAX_PROBES;
175 return err;
176}
177
178int bpf__probe(struct bpf_object *obj)
179{
180 int err = 0;
181 struct bpf_program *prog;
182 struct bpf_prog_priv *priv;
183 struct perf_probe_event *pev;
184
185 err = bpf__prepare_probe();
186 if (err) {
187 pr_debug("bpf__prepare_probe failed\n");
188 return err;
189 }
190
191 bpf_object__for_each_program(prog, obj) {
192 err = config_bpf_program(prog);
193 if (err)
194 goto out;
195
196 err = bpf_program__get_private(prog, (void **)&priv);
197 if (err || !priv)
198 goto out;
199 pev = &priv->pev;
200
201 err = convert_perf_probe_events(pev, 1);
202 if (err < 0) {
203 pr_debug("bpf_probe: failed to convert perf probe events");
204 goto out;
205 }
206
207 err = apply_perf_probe_events(pev, 1);
208 if (err < 0) {
209 pr_debug("bpf_probe: failed to apply perf probe events");
210 goto out;
211 }
212 }
213out:
214 return err < 0 ? err : 0;
215}
216
217#define EVENTS_WRITE_BUFSIZE 4096
218int bpf__unprobe(struct bpf_object *obj)
219{
220 int err, ret = 0;
221 struct bpf_program *prog;
222 struct bpf_prog_priv *priv;
223
224 bpf_object__for_each_program(prog, obj) {
225 int i;
226
227 err = bpf_program__get_private(prog, (void **)&priv);
228 if (err || !priv)
229 continue;
230
231 for (i = 0; i < priv->pev.ntevs; i++) {
232 struct probe_trace_event *tev = &priv->pev.tevs[i];
233 char name_buf[EVENTS_WRITE_BUFSIZE];
234 struct strfilter *delfilter;
235
236 snprintf(name_buf, EVENTS_WRITE_BUFSIZE,
237 "%s:%s", tev->group, tev->event);
238 name_buf[EVENTS_WRITE_BUFSIZE - 1] = '\0';
239
240 delfilter = strfilter__new(name_buf, NULL);
241 if (!delfilter) {
242 pr_debug("Failed to create filter for unprobing\n");
243 ret = -ENOMEM;
244 continue;
245 }
246
247 err = del_perf_probe_events(delfilter);
248 strfilter__delete(delfilter);
249 if (err) {
250 pr_debug("Failed to delete %s\n", name_buf);
251 ret = err;
252 continue;
253 }
254 }
255 }
256 return ret;
257}
258
259int bpf__load(struct bpf_object *obj)
260{
261 int err;
262
263 err = bpf_object__load(obj);
264 if (err) {
265 pr_debug("bpf: load objects failed\n");
266 return err;
267 }
268 return 0;
269}
270
271int bpf__foreach_tev(struct bpf_object *obj,
272 bpf_prog_iter_callback_t func,
273 void *arg)
274{
275 struct bpf_program *prog;
276 int err;
277
278 bpf_object__for_each_program(prog, obj) {
279 struct probe_trace_event *tev;
280 struct perf_probe_event *pev;
281 struct bpf_prog_priv *priv;
282 int i, fd;
283
284 err = bpf_program__get_private(prog,
285 (void **)&priv);
286 if (err || !priv) {
287 pr_debug("bpf: failed to get private field\n");
288 return -EINVAL;
289 }
290
291 pev = &priv->pev;
292 for (i = 0; i < pev->ntevs; i++) {
293 tev = &pev->tevs[i];
294
295 fd = bpf_program__fd(prog);
296 if (fd < 0) {
297 pr_debug("bpf: failed to get file descriptor\n");
298 return fd;
299 }
300
301 err = (*func)(tev, fd, arg);
302 if (err) {
303 pr_debug("bpf: call back failed, stop iterate\n");
304 return err;
305 }
306 }
307 }
308 return 0;
309}
310
311#define bpf__strerror_head(err, buf, size) \
312 char sbuf[STRERR_BUFSIZE], *emsg;\
313 if (!size)\
314 return 0;\
315 if (err < 0)\
316 err = -err;\
317 emsg = strerror_r(err, sbuf, sizeof(sbuf));\
318 switch (err) {\
319 default:\
320 scnprintf(buf, size, "%s", emsg);\
321 break;
322
323#define bpf__strerror_entry(val, fmt...)\
324 case val: {\
325 scnprintf(buf, size, fmt);\
326 break;\
327 }
328
329#define bpf__strerror_end(buf, size)\
330 }\
331 buf[size - 1] = '\0';
332
333int bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
334 int err, char *buf, size_t size)
335{
336 bpf__strerror_head(err, buf, size);
337 bpf__strerror_entry(EEXIST, "Probe point exist. Try use 'perf probe -d \"*\"'");
338 bpf__strerror_entry(EPERM, "You need to be root, and /proc/sys/kernel/kptr_restrict should be 0\n");
339 bpf__strerror_entry(ENOENT, "You need to check probing points in BPF file\n");
340 bpf__strerror_end(buf, size);
341 return 0;
342}
343
344int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
345 int err, char *buf, size_t size)
346{
347 bpf__strerror_head(err, buf, size);
348 bpf__strerror_entry(EINVAL, "%s: Are you root and runing a CONFIG_BPF_SYSCALL kernel?",
349 emsg)
350 bpf__strerror_end(buf, size);
351 return 0;
352}
tools/perf/util/bpf-loader.h+85−0
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
3 * Copyright (C) 2015, Huawei Inc.
4 */
5#ifndef __BPF_LOADER_H
6#define __BPF_LOADER_H
7
8#include <linux/compiler.h>
9#include <linux/err.h>
10#include <string.h>
11#include "probe-event.h"
12#include "debug.h"
13
14struct bpf_object;
15#define PERF_BPF_PROBE_GROUP "perf_bpf_probe"
16
17typedef int (*bpf_prog_iter_callback_t)(struct probe_trace_event *tev,
18 int fd, void *arg);
19
20#ifdef HAVE_LIBBPF_SUPPORT
21struct bpf_object *bpf__prepare_load(const char *filename, bool source);
22
23void bpf__clear(void);
24
25int bpf__probe(struct bpf_object *obj);
26int bpf__unprobe(struct bpf_object *obj);
27int bpf__strerror_probe(struct bpf_object *obj, int err,
28 char *buf, size_t size);
29
30int bpf__load(struct bpf_object *obj);
31int bpf__strerror_load(struct bpf_object *obj, int err,
32 char *buf, size_t size);
33int bpf__foreach_tev(struct bpf_object *obj,
34 bpf_prog_iter_callback_t func, void *arg);
35#else
36static inline struct bpf_object *
37bpf__prepare_load(const char *filename __maybe_unused,
38 bool source __maybe_unused)
39{
40 pr_debug("ERROR: eBPF object loading is disabled during compiling.\n");
41 return ERR_PTR(-ENOTSUP);
42}
43
44static inline void bpf__clear(void) { }
45
46static inline int bpf__probe(struct bpf_object *obj __maybe_unused) { return 0;}
47static inline int bpf__unprobe(struct bpf_object *obj __maybe_unused) { return 0;}
48static inline int bpf__load(struct bpf_object *obj __maybe_unused) { return 0; }
49
50static inline int
51bpf__foreach_tev(struct bpf_object *obj __maybe_unused,
52 bpf_prog_iter_callback_t func __maybe_unused,
53 void *arg __maybe_unused)
54{
55 return 0;
56}
57
58static inline int
59__bpf_strerror(char *buf, size_t size)
60{
61 if (!size)
62 return 0;
63 strncpy(buf,
64 "ERROR: eBPF object loading is disabled during compiling.\n",
65 size);
66 buf[size - 1] = '\0';
67 return 0;
68}
69
70static inline int
71bpf__strerror_probe(struct bpf_object *obj __maybe_unused,
72 int err __maybe_unused,
73 char *buf, size_t size)
74{
75 return __bpf_strerror(buf, size);
76}
77
78static inline int bpf__strerror_load(struct bpf_object *obj __maybe_unused,
79 int err __maybe_unused,
80 char *buf, size_t size)
81{
82 return __bpf_strerror(buf, size);
83}
84#endif
85#endif
tools/perf/util/callchain.c+39−3
@@ -51,10 +51,12 @@ static int parse_callchain_order(const char *value) · 50 unmodified lines
51{51{
52 if (!strncmp(value, "caller", strlen(value))) {52 if (!strncmp(value, "caller", strlen(value))) {
53 callchain_param.order = ORDER_CALLER;53 callchain_param.order = ORDER_CALLER;
54 callchain_param.order_set = true;
54 return 0;55 return 0;
55 }56 }
56 if (!strncmp(value, "callee", strlen(value))) {57 if (!strncmp(value, "callee", strlen(value))) {
57 callchain_param.order = ORDER_CALLEE;58 callchain_param.order = ORDER_CALLEE;
59 callchain_param.order_set = true;
58 return 0;60 return 0;
59 }61 }
60 return -1;62 return -1;
@@ -77,12 +79,14 @@ static int parse_callchain_sort_key(const char *value) · 16 unmodified lines
77 return -1;79 return -1;
78}80}
79 81
80int82static int
81parse_callchain_report_opt(const char *arg)83__parse_callchain_report_opt(const char *arg, bool allow_record_opt)
82{84{
83 char *tok;85 char *tok;
84 char *endptr;86 char *endptr;
85 bool minpcnt_set = false;87 bool minpcnt_set = false;
88 bool record_opt_set = false;
89 bool try_stack_size = false;
86 90
87 symbol_conf.use_callchain = true;91 symbol_conf.use_callchain = true;
88 92
@@ -100,6 +104,28 @@ parse_callchain_report_opt(const char *arg) · 11 unmodified lines
100 !parse_callchain_order(tok) ||104 !parse_callchain_order(tok) ||
101 !parse_callchain_sort_key(tok)) {105 !parse_callchain_sort_key(tok)) {
102 /* parsing ok - move on to the next */106 /* parsing ok - move on to the next */
107 try_stack_size = false;
108 goto next;
109 } else if (allow_record_opt && !record_opt_set) {
110 if (parse_callchain_record(tok, &callchain_param))
111 goto try_numbers;
112
113 /* assume that number followed by 'dwarf' is stack size */
114 if (callchain_param.record_mode == CALLCHAIN_DWARF)
115 try_stack_size = true;
116
117 record_opt_set = true;
118 goto next;
119 }
120
121try_numbers:
122 if (try_stack_size) {
123 unsigned long size = 0;
124
125 if (get_stack_size(tok, &size) < 0)
126 return -1;
127 callchain_param.dump_size = size;
128 try_stack_size = false;
103 } else if (!minpcnt_set) {129 } else if (!minpcnt_set) {
104 /* try to get the min percent */130 /* try to get the min percent */
105 callchain_param.min_percent = strtod(tok, &endptr);131 callchain_param.min_percent = strtod(tok, &endptr);
@@ -112,7 +138,7 @@ parse_callchain_report_opt(const char *arg) · 6 unmodified lines
112 if (tok == endptr)138 if (tok == endptr)
113 return -1;139 return -1;
114 }140 }
115 141next:
116 arg = NULL;142 arg = NULL;
117 }143 }
118 144
@@ -123,6 +149,16 @@ parse_callchain_report_opt(const char *arg) · 4 unmodified lines
123 return 0;149 return 0;
124}150}
125 151
152int parse_callchain_report_opt(const char *arg)
153{
154 return __parse_callchain_report_opt(arg, false);
155}
156
157int parse_callchain_top_opt(const char *arg)
158{
159 return __parse_callchain_report_opt(arg, true);
160}
161
126int perf_callchain_config(const char *var, const char *value)162int perf_callchain_config(const char *var, const char *value)
127{163{
128 char *endptr;164 char *endptr;
tools/perf/util/callchain.h+26−0
@@ -7,6 +7,30 @@ · 6 unmodified lines
7#include "event.h"7#include "event.h"
8#include "symbol.h"8#include "symbol.h"
9 9
10#define HELP_PAD "\t\t\t\t"
11
12#define CALLCHAIN_HELP "setup and enables call-graph (stack chain/backtrace):\n\n"
13
14#ifdef HAVE_DWARF_UNWIND_SUPPORT
15# define RECORD_MODE_HELP HELP_PAD "record_mode:\tcall graph recording mode (fp|dwarf|lbr)\n"
16#else
17# define RECORD_MODE_HELP HELP_PAD "record_mode:\tcall graph recording mode (fp|lbr)\n"
18#endif
19
20#define RECORD_SIZE_HELP \
21 HELP_PAD "record_size:\tif record_mode is 'dwarf', max size of stack recording (<bytes>)\n" \
22 HELP_PAD "\t\tdefault: 8192 (bytes)\n"
23
24#define CALLCHAIN_RECORD_HELP CALLCHAIN_HELP RECORD_MODE_HELP RECORD_SIZE_HELP
25
26#define CALLCHAIN_REPORT_HELP \
27 HELP_PAD "print_type:\tcall graph printing style (graph|flat|fractal|none)\n" \
28 HELP_PAD "threshold:\tminimum call graph inclusion threshold (<percent>)\n" \
29 HELP_PAD "print_limit:\tmaximum number of call graph entry (<number>)\n" \
30 HELP_PAD "order:\t\tcall graph order (caller|callee)\n" \
31 HELP_PAD "sort_key:\tcall graph sort key (function|address)\n" \
32 HELP_PAD "branch:\t\tinclude last branch info to call graph (branch)\n"
33
10enum perf_call_graph_mode {34enum perf_call_graph_mode {
11 CALLCHAIN_NONE,35 CALLCHAIN_NONE,
12 CALLCHAIN_FP,36 CALLCHAIN_FP,
@@ -63,6 +87,7 @@ struct callchain_param { · 50 unmodified lines
63 double min_percent;87 double min_percent;
64 sort_chain_func_t sort;88 sort_chain_func_t sort;
65 enum chain_order order;89 enum chain_order order;
90 bool order_set;
66 enum chain_key key;91 enum chain_key key;
67 bool branch_callstack;92 bool branch_callstack;
68};93};
@@ -180,6 +205,7 @@ extern const char record_callchain_help[]; · 111 unmodified lines
180extern int parse_callchain_record(const char *arg, struct callchain_param *param);205extern int parse_callchain_record(const char *arg, struct callchain_param *param);
181int parse_callchain_record_opt(const char *arg, struct callchain_param *param);206int parse_callchain_record_opt(const char *arg, struct callchain_param *param);
182int parse_callchain_report_opt(const char *arg);207int parse_callchain_report_opt(const char *arg);
208int parse_callchain_top_opt(const char *arg);
183int perf_callchain_config(const char *var, const char *value);209int perf_callchain_config(const char *var, const char *value);
184 210
185static inline void callchain_cursor_snapshot(struct callchain_cursor *dest,211static inline void callchain_cursor_snapshot(struct callchain_cursor *dest,
tools/perf/util/cpumap.c+52−45
@@ -203,6 +203,23 @@ struct cpu_map *cpu_map__dummy_new(void) · 202 unmodified lines
203 return cpus;203 return cpus;
204}204}
205 205
206struct cpu_map *cpu_map__empty_new(int nr)
207{
208 struct cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);
209
210 if (cpus != NULL) {
211 int i;
212
213 cpus->nr = nr;
214 for (i = 0; i < nr; i++)
215 cpus->map[i] = -1;
216
217 atomic_set(&cpus->refcnt, 1);
218 }
219
220 return cpus;
221}
222
206static void cpu_map__delete(struct cpu_map *map)223static void cpu_map__delete(struct cpu_map *map)
207{224{
208 if (map) {225 if (map) {
@@ -225,32 +242,32 @@ void cpu_map__put(struct cpu_map *map) · 16 unmodified lines
225 cpu_map__delete(map);242 cpu_map__delete(map);
226}243}
227 244
228int cpu_map__get_socket(struct cpu_map *map, int idx)245static int cpu__get_topology_int(int cpu, const char *name, int *value)
229{246{
230 FILE *fp;
231 const char *mnt;
232 char path[PATH_MAX];247 char path[PATH_MAX];
233 int cpu, ret;
234 248
235 if (idx > map->nr)249 snprintf(path, PATH_MAX,
236 return -1;250 "devices/system/cpu/cpu%d/topology/%s", cpu, name);
237 251
238 cpu = map->map[idx];252 return sysfs__read_int(path, value);
253}
239 254
240 mnt = sysfs__mountpoint();255int cpu_map__get_socket_id(int cpu)
241 if (!mnt)256{
242 return -1;257 int value, ret = cpu__get_topology_int(cpu, "physical_package_id", &value);
258 return ret ?: value;
259}
243 260
244 snprintf(path, PATH_MAX,261int cpu_map__get_socket(struct cpu_map *map, int idx, void *data __maybe_unused)
245 "%s/devices/system/cpu/cpu%d/topology/physical_package_id",262{
246 mnt, cpu);263 int cpu;
247 264
248 fp = fopen(path, "r");265 if (idx > map->nr)
249 if (!fp)
250 return -1;266 return -1;
251 ret = fscanf(fp, "%d", &cpu);267
252 fclose(fp);268 cpu = map->map[idx];
253 return ret == 1 ? cpu : -1;269
270 return cpu_map__get_socket_id(cpu);
254}271}
255 272
256static int cmp_ids(const void *a, const void *b)273static int cmp_ids(const void *a, const void *b)
@@ -258,8 +275,9 @@ static int cmp_ids(const void *a, const void *b) · 1 unmodified line
258 return *(int *)a - *(int *)b;275 return *(int *)a - *(int *)b;
259}276}
260 277
261static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,278int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
262 int (*f)(struct cpu_map *map, int cpu))279 int (*f)(struct cpu_map *map, int cpu, void *data),
280 void *data)
263{281{
264 struct cpu_map *c;282 struct cpu_map *c;
265 int nr = cpus->nr;283 int nr = cpus->nr;
@@ -271,7 +289,7 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, · 5 unmodified lines
271 return -1;289 return -1;
272 290
273 for (cpu = 0; cpu < nr; cpu++) {291 for (cpu = 0; cpu < nr; cpu++) {
274 s1 = f(cpus, cpu);292 s1 = f(cpus, cpu, data);
275 for (s2 = 0; s2 < c->nr; s2++) {293 for (s2 = 0; s2 < c->nr; s2++) {
276 if (s1 == c->map[s2])294 if (s1 == c->map[s2])
277 break;295 break;
@@ -284,40 +302,29 @@ static int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res, · 6 unmodified lines
284 /* ensure we process id in increasing order */302 /* ensure we process id in increasing order */
285 qsort(c->map, c->nr, sizeof(int), cmp_ids);303 qsort(c->map, c->nr, sizeof(int), cmp_ids);
286 304
287 atomic_set(&cpus->refcnt, 1);305 atomic_set(&c->refcnt, 1);
288 *res = c;306 *res = c;
289 return 0;307 return 0;
290}308}
291 309
292int cpu_map__get_core(struct cpu_map *map, int idx)310int cpu_map__get_core_id(int cpu)
293{311{
294 FILE *fp;312 int value, ret = cpu__get_topology_int(cpu, "core_id", &value);
295 const char *mnt;313 return ret ?: value;
296 char path[PATH_MAX];314}
297 int cpu, ret, s;315
316int cpu_map__get_core(struct cpu_map *map, int idx, void *data)
317{
318 int cpu, s;
298 319
299 if (idx > map->nr)320 if (idx > map->nr)
300 return -1;321 return -1;
301 322
302 cpu = map->map[idx];323 cpu = map->map[idx];
303 324
304 mnt = sysfs__mountpoint();325 cpu = cpu_map__get_core_id(cpu);
305 if (!mnt)
306 return -1;
307
308 snprintf(path, PATH_MAX,
309 "%s/devices/system/cpu/cpu%d/topology/core_id",
310 mnt, cpu);
311
312 fp = fopen(path, "r");
313 if (!fp)
314 return -1;
315 ret = fscanf(fp, "%d", &cpu);
316 fclose(fp);
317 if (ret != 1)
318 return -1;
319 326
320 s = cpu_map__get_socket(map, idx);327 s = cpu_map__get_socket(map, idx, data);
321 if (s == -1)328 if (s == -1)
322 return -1;329 return -1;
323 330
@@ -332,12 +339,12 @@ int cpu_map__get_core(struct cpu_map *map, int idx) · 8 unmodified lines
332 339
333int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp)340int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp)
334{341{
335 return cpu_map__build_map(cpus, sockp, cpu_map__get_socket);342 return cpu_map__build_map(cpus, sockp, cpu_map__get_socket, NULL);
336}343}
337 344
338int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep)345int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep)
339{346{
340 return cpu_map__build_map(cpus, corep, cpu_map__get_core);347 return cpu_map__build_map(cpus, corep, cpu_map__get_core, NULL);
341}348}
342 349
343/* setup simple routines to easily access node numbers given a cpu number */350/* setup simple routines to easily access node numbers given a cpu number */
tools/perf/util/cpumap.h+8−2
@@ -15,11 +15,14 @@ struct cpu_map { · 14 unmodified lines
15};15};
16 16
17struct cpu_map *cpu_map__new(const char *cpu_list);17struct cpu_map *cpu_map__new(const char *cpu_list);
18struct cpu_map *cpu_map__empty_new(int nr);
18struct cpu_map *cpu_map__dummy_new(void);19struct cpu_map *cpu_map__dummy_new(void);
19struct cpu_map *cpu_map__read(FILE *file);20struct cpu_map *cpu_map__read(FILE *file);
20size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);21size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
21int cpu_map__get_socket(struct cpu_map *map, int idx);22int cpu_map__get_socket_id(int cpu);
22int cpu_map__get_core(struct cpu_map *map, int idx);23int cpu_map__get_socket(struct cpu_map *map, int idx, void *data);
24int cpu_map__get_core_id(int cpu);
25int cpu_map__get_core(struct cpu_map *map, int idx, void *data);
23int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);26int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
24int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);27int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep);
25 28
@@ -85,4 +88,7 @@ static inline int cpu__get_node(int cpu) · 59 unmodified lines
85 return cpunode_map[cpu];88 return cpunode_map[cpu];
86}89}
87 90
91int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
92 int (*f)(struct cpu_map *map, int cpu, void *data),
93 void *data);
88#endif /* __PERF_CPUMAP_H */94#endif /* __PERF_CPUMAP_H */
tools/perf/util/env.c+86−0
@@ -0,0 +1,86 @@
1#include "cpumap.h"
2#include "env.h"
3#include "util.h"
4
5struct perf_env perf_env;
6
7void perf_env__exit(struct perf_env *env)
8{
9 zfree(&env->hostname);
10 zfree(&env->os_release);
11 zfree(&env->version);
12 zfree(&env->arch);
13 zfree(&env->cpu_desc);
14 zfree(&env->cpuid);
15 zfree(&env->cmdline);
16 zfree(&env->cmdline_argv);
17 zfree(&env->sibling_cores);
18 zfree(&env->sibling_threads);
19 zfree(&env->numa_nodes);
20 zfree(&env->pmu_mappings);
21 zfree(&env->cpu);
22}
23
24int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
25{
26 int i;
27
28 /*
29 * If env->cmdline_argv has already been set, do not override it. This allows
30 * a command to set the cmdline, parse args and then call another
31 * builtin function that implements a command -- e.g, cmd_kvm calling
32 * cmd_record.
33 */
34 if (env->cmdline_argv != NULL)
35 return 0;
36
37 /* do not include NULL termination */
38 env->cmdline_argv = calloc(argc, sizeof(char *));
39 if (env->cmdline_argv == NULL)
40 goto out_enomem;
41
42 /*
43 * Must copy argv contents because it gets moved around during option
44 * parsing:
45 */
46 for (i = 0; i < argc ; i++) {
47 env->cmdline_argv[i] = argv[i];
48 if (env->cmdline_argv[i] == NULL)
49 goto out_free;
50 }
51
52 env->nr_cmdline = argc;
53
54 return 0;
55out_free:
56 zfree(&env->cmdline_argv);
57out_enomem:
58 return -ENOMEM;
59}
60
61int perf_env__read_cpu_topology_map(struct perf_env *env)
62{
63 int cpu, nr_cpus;
64
65 if (env->cpu != NULL)
66 return 0;
67
68 if (env->nr_cpus_avail == 0)
69 env->nr_cpus_avail = sysconf(_SC_NPROCESSORS_CONF);
70
71 nr_cpus = env->nr_cpus_avail;
72 if (nr_cpus == -1)
73 return -EINVAL;
74
75 env->cpu = calloc(nr_cpus, sizeof(env->cpu[0]));
76 if (env->cpu == NULL)
77 return -ENOMEM;
78
79 for (cpu = 0; cpu < nr_cpus; ++cpu) {
80 env->cpu[cpu].core_id = cpu_map__get_core_id(cpu);
81 env->cpu[cpu].socket_id = cpu_map__get_socket_id(cpu);
82 }
83
84 env->nr_cpus_avail = nr_cpus;
85 return 0;
86}
tools/perf/util/env.h+44−0
@@ -0,0 +1,44 @@
1#ifndef __PERF_ENV_H
2#define __PERF_ENV_H
3
4struct cpu_topology_map {
5 int socket_id;
6 int core_id;
7};
8
9struct perf_env {
10 char *hostname;
11 char *os_release;
12 char *version;
13 char *arch;
14 int nr_cpus_online;
15 int nr_cpus_avail;
16 char *cpu_desc;
17 char *cpuid;
18 unsigned long long total_mem;
19 unsigned int msr_pmu_type;
20
21 int nr_cmdline;
22 int nr_sibling_cores;
23 int nr_sibling_threads;
24 int nr_numa_nodes;
25 int nr_pmu_mappings;
26 int nr_groups;
27 char *cmdline;
28 const char **cmdline_argv;
29 char *sibling_cores;
30 char *sibling_threads;
31 char *numa_nodes;
32 char *pmu_mappings;
33 struct cpu_topology_map *cpu;
34};
35
36extern struct perf_env perf_env;
37
38void perf_env__exit(struct perf_env *env);
39
40int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
41
42int perf_env__read_cpu_topology_map(struct perf_env *env);
43
44#endif /* __PERF_ENV_H */
tools/perf/util/event.c+15−7
@@ -67,7 +67,8 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len, · 66 unmodified lines
67 char filename[PATH_MAX];67 char filename[PATH_MAX];
68 char bf[4096];68 char bf[4096];
69 int fd;69 int fd;
70 size_t size = 0, n;70 size_t size = 0;
71 ssize_t n;
71 char *nl, *name, *tgids, *ppids;72 char *nl, *name, *tgids, *ppids;
72 73
73 *tgid = -1;74 *tgid = -1;
@@ -167,7 +168,7 @@ static int perf_event__prepare_comm(union perf_event *event, pid_t pid, · 93 unmodified lines
167 return 0;168 return 0;
168}169}
169 170
170static pid_t perf_event__synthesize_comm(struct perf_tool *tool,171pid_t perf_event__synthesize_comm(struct perf_tool *tool,
171 union perf_event *event, pid_t pid,172 union perf_event *event, pid_t pid,
172 perf_event__handler_t process,173 perf_event__handler_t process,
173 struct machine *machine)174 struct machine *machine)
@@ -378,7 +379,7 @@ int perf_event__synthesize_modules(struct perf_tool *tool, · 204 unmodified lines
378 for (pos = maps__first(maps); pos; pos = map__next(pos)) {379 for (pos = maps__first(maps); pos; pos = map__next(pos)) {
379 size_t size;380 size_t size;
380 381
381 if (pos->dso->kernel)382 if (__map__is_kernel(pos))
382 continue;383 continue;
383 384
384 size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));385 size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
@@ -649,12 +650,12 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, · 264 unmodified lines
649 size_t size;650 size_t size;
650 const char *mmap_name;651 const char *mmap_name;
651 char name_buff[PATH_MAX];652 char name_buff[PATH_MAX];
652 struct map *map;653 struct map *map = machine__kernel_map(machine);
653 struct kmap *kmap;654 struct kmap *kmap;
654 int err;655 int err;
655 union perf_event *event;656 union perf_event *event;
656 657
657 if (machine->vmlinux_maps[0] == NULL)658 if (map == NULL)
658 return -1;659 return -1;
659 660
660 /*661 /*
@@ -680,7 +681,6 @@ int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, · 19 unmodified lines
680 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;681 event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
681 }682 }
682 683
683 map = machine->vmlinux_maps[MAP__FUNCTION];
684 kmap = map__kmap(map);684 kmap = map__kmap(map);
685 size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),685 size = snprintf(event->mmap.filename, sizeof(event->mmap.filename),
686 "%s%s", mmap_name, kmap->ref_reloc_sym->name) + 1;686 "%s%s", mmap_name, kmap->ref_reloc_sym->name) + 1;
@@ -1008,7 +1008,7 @@ int perf_event__preprocess_sample(const union perf_event *event, · 321 unmodified lines
1008 * it now.1008 * it now.
1009 */1009 */
1010 if (cpumode == PERF_RECORD_MISC_KERNEL &&1010 if (cpumode == PERF_RECORD_MISC_KERNEL &&
1011 machine->vmlinux_maps[MAP__FUNCTION] == NULL)1011 machine__kernel_map(machine) == NULL)
1012 machine__create_kernel_maps(machine);1012 machine__create_kernel_maps(machine);
1013 1013
1014 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al);1014 thread__find_addr_map(thread, cpumode, MAP__FUNCTION, sample->ip, al);
@@ -1021,6 +1021,14 @@ int perf_event__preprocess_sample(const union perf_event *event, · 6 unmodified lines
1021 1021
1022 al->sym = NULL;1022 al->sym = NULL;
1023 al->cpu = sample->cpu;1023 al->cpu = sample->cpu;
1024 al->socket = -1;
1025
1026 if (al->cpu >= 0) {
1027 struct perf_env *env = machine->env;
1028
1029 if (env && env->cpu)
1030 al->socket = env->cpu[al->cpu].socket_id;
1031 }
1024 1032
1025 if (al->map) {1033 if (al->map) {
1026 struct dso *dso = al->map->dso;1034 struct dso *dso = al->map->dso;
tools/perf/util/event.h+6−0
@@ -257,6 +257,7 @@ struct events_stats { · 256 unmodified lines
257 u64 total_non_filtered_period;257 u64 total_non_filtered_period;
258 u64 total_lost;258 u64 total_lost;
259 u64 total_lost_samples;259 u64 total_lost_samples;
260 u64 total_aux_lost;
260 u64 total_invalid_chains;261 u64 total_invalid_chains;
261 u32 nr_events[PERF_RECORD_HEADER_MAX];262 u32 nr_events[PERF_RECORD_HEADER_MAX];
262 u32 nr_non_filtered_samples;263 u32 nr_non_filtered_samples;
@@ -478,6 +479,11 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, · 215 unmodified lines
478 const struct perf_sample *sample,479 const struct perf_sample *sample,
479 bool swapped);480 bool swapped);
480 481
482pid_t perf_event__synthesize_comm(struct perf_tool *tool,
483 union perf_event *event, pid_t pid,
484 perf_event__handler_t process,
485 struct machine *machine);
486
481int perf_event__synthesize_mmap_events(struct perf_tool *tool,487int perf_event__synthesize_mmap_events(struct perf_tool *tool,
482 union perf_event *event,488 union perf_event *event,
483 pid_t pid, pid_t tgid,489 pid_t pid, pid_t tgid,
tools/perf/util/evlist.c+43−4
@@ -25,6 +25,7 @@ · 24 unmodified lines
25#include <linux/bitops.h>25#include <linux/bitops.h>
26#include <linux/hash.h>26#include <linux/hash.h>
27#include <linux/log2.h>27#include <linux/log2.h>
28#include <linux/err.h>
28 29
29static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx);30static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx);
30static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx);31static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx);
@@ -164,6 +165,13 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry) · 133 unmodified lines
164 __perf_evlist__propagate_maps(evlist, entry);165 __perf_evlist__propagate_maps(evlist, entry);
165}166}
166 167
168void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel)
169{
170 evsel->evlist = NULL;
171 list_del_init(&evsel->node);
172 evlist->nr_entries -= 1;
173}
174
167void perf_evlist__splice_list_tail(struct perf_evlist *evlist,175void perf_evlist__splice_list_tail(struct perf_evlist *evlist,
168 struct list_head *list)176 struct list_head *list)
169{177{
@@ -197,6 +205,20 @@ void perf_evlist__set_leader(struct perf_evlist *evlist) · 27 unmodified lines
197 }205 }
198}206}
199 207
208void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)
209{
210 attr->precise_ip = 3;
211
212 while (attr->precise_ip != 0) {
213 int fd = sys_perf_event_open(attr, 0, -1, -1, 0);
214 if (fd != -1) {
215 close(fd);
216 break;
217 }
218 --attr->precise_ip;
219 }
220}
221
200int perf_evlist__add_default(struct perf_evlist *evlist)222int perf_evlist__add_default(struct perf_evlist *evlist)
201{223{
202 struct perf_event_attr attr = {224 struct perf_event_attr attr = {
@@ -207,13 +229,15 @@ int perf_evlist__add_default(struct perf_evlist *evlist) · 4 unmodified lines
207 229
208 event_attr_init(&attr);230 event_attr_init(&attr);
209 231
232 perf_event_attr__set_max_precise_ip(&attr);
233
210 evsel = perf_evsel__new(&attr);234 evsel = perf_evsel__new(&attr);
211 if (evsel == NULL)235 if (evsel == NULL)
212 goto error;236 goto error;
213 237
214 /* use strdup() because free(evsel) assumes name is allocated */238 /* use asprintf() because free(evsel) assumes name is allocated */
215 evsel->name = strdup("cycles");239 if (asprintf(&evsel->name, "cycles%.*s",
216 if (!evsel->name)240 attr.precise_ip ? attr.precise_ip + 1 : 0, ":ppp") < 0)
217 goto error_free;241 goto error_free;
218 242
219 perf_evlist__add(evlist, evsel);243 perf_evlist__add(evlist, evsel);
@@ -293,7 +317,7 @@ int perf_evlist__add_newtp(struct perf_evlist *evlist, · 73 unmodified lines
293{317{
294 struct perf_evsel *evsel = perf_evsel__newtp(sys, name);318 struct perf_evsel *evsel = perf_evsel__newtp(sys, name);
295 319
296 if (evsel == NULL)320 if (IS_ERR(evsel))
297 return -1;321 return -1;
298 322
299 evsel->handler = handler;323 evsel->handler = handler;
@@ -616,6 +640,21 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id) · 316 unmodified lines
616 return NULL;640 return NULL;
617}641}
618 642
643struct perf_evsel *perf_evlist__id2evsel_strict(struct perf_evlist *evlist,
644 u64 id)
645{
646 struct perf_sample_id *sid;
647
648 if (!id)
649 return NULL;
650
651 sid = perf_evlist__id2sid(evlist, id);
652 if (sid)
653 return sid->evsel;
654
655 return NULL;
656}
657
619static int perf_evlist__event2id(struct perf_evlist *evlist,658static int perf_evlist__event2id(struct perf_evlist *evlist,
620 union perf_event *event, u64 *id)659 union perf_event *event, u64 *id)
621{660{
tools/perf/util/evlist.h+5−0
@@ -73,6 +73,7 @@ void perf_evlist__exit(struct perf_evlist *evlist); · 72 unmodified lines
73void perf_evlist__delete(struct perf_evlist *evlist);73void perf_evlist__delete(struct perf_evlist *evlist);
74 74
75void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);75void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
76void perf_evlist__remove(struct perf_evlist *evlist, struct perf_evsel *evsel);
76int perf_evlist__add_default(struct perf_evlist *evlist);77int perf_evlist__add_default(struct perf_evlist *evlist);
77int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,78int __perf_evlist__add_default_attrs(struct perf_evlist *evlist,
78 struct perf_event_attr *attrs, size_t nr_attrs);79 struct perf_event_attr *attrs, size_t nr_attrs);
@@ -104,6 +105,8 @@ int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mas · 25 unmodified lines
104int perf_evlist__poll(struct perf_evlist *evlist, int timeout);105int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
105 106
106struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);107struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
108struct perf_evsel *perf_evlist__id2evsel_strict(struct perf_evlist *evlist,
109 u64 id);
107 110
108struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);111struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);
109 112
@@ -287,4 +290,6 @@ void perf_evlist__to_front(struct perf_evlist *evlist, · 177 unmodified lines
287 290
288void perf_evlist__set_tracking_event(struct perf_evlist *evlist,291void perf_evlist__set_tracking_event(struct perf_evlist *evlist,
289 struct perf_evsel *tracking_evsel);292 struct perf_evsel *tracking_evsel);
293
294void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr);
290#endif /* __PERF_EVLIST_H */295#endif /* __PERF_EVLIST_H */
tools/perf/util/evsel.c+45−5
@@ -9,10 +9,11 @@ · 8 unmodified lines
9 9
10#include <byteswap.h>10#include <byteswap.h>
11#include <linux/bitops.h>11#include <linux/bitops.h>
12#include <api/fs/debugfs.h>12#include <api/fs/tracing_path.h>
13#include <traceevent/event-parse.h>13#include <traceevent/event-parse.h>
14#include <linux/hw_breakpoint.h>14#include <linux/hw_breakpoint.h>
15#include <linux/perf_event.h>15#include <linux/perf_event.h>
16#include <linux/err.h>
16#include <sys/resource.h>17#include <sys/resource.h>
17#include "asm/bug.h"18#include "asm/bug.h"
18#include "callchain.h"19#include "callchain.h"
@@ -207,6 +208,7 @@ void perf_evsel__init(struct perf_evsel *evsel, · 188 unmodified lines
207 evsel->unit = "";208 evsel->unit = "";
208 evsel->scale = 1.0;209 evsel->scale = 1.0;
209 evsel->evlist = NULL;210 evsel->evlist = NULL;
211 evsel->bpf_fd = -1;
210 INIT_LIST_HEAD(&evsel->node);212 INIT_LIST_HEAD(&evsel->node);
211 INIT_LIST_HEAD(&evsel->config_terms);213 INIT_LIST_HEAD(&evsel->config_terms);
212 perf_evsel__object.init(evsel);214 perf_evsel__object.init(evsel);
@@ -225,11 +227,17 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) · 12 unmodified lines
225 return evsel;227 return evsel;
226}228}
227 229
230/*
231 * Returns pointer with encoded error via <linux/err.h> interface.
232 */
228struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx)233struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx)
229{234{
230 struct perf_evsel *evsel = zalloc(perf_evsel__object.size);235 struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
236 int err = -ENOMEM;
231 237
232 if (evsel != NULL) {238 if (evsel == NULL) {
239 goto out_err;
240 } else {
233 struct perf_event_attr attr = {241 struct perf_event_attr attr = {
234 .type = PERF_TYPE_TRACEPOINT,242 .type = PERF_TYPE_TRACEPOINT,
235 .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |243 .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
@@ -240,8 +248,10 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int · 4 unmodified lines
240 goto out_free;248 goto out_free;
241 249
242 evsel->tp_format = trace_event__tp_format(sys, name);250 evsel->tp_format = trace_event__tp_format(sys, name);
243 if (evsel->tp_format == NULL)251 if (IS_ERR(evsel->tp_format)) {
252 err = PTR_ERR(evsel->tp_format);
244 goto out_free;253 goto out_free;
254 }
245 255
246 event_attr_init(&attr);256 event_attr_init(&attr);
247 attr.config = evsel->tp_format->id;257 attr.config = evsel->tp_format->id;
@@ -254,7 +264,8 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int · 6 unmodified lines
254out_free:264out_free:
255 zfree(&evsel->name);265 zfree(&evsel->name);
256 free(evsel);266 free(evsel);
257 return NULL;267out_err:
268 return ERR_PTR(err);
258}269}
259 270
260const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {271const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {
@@ -642,6 +653,15 @@ static void apply_config_terms(struct perf_evsel *evsel, · 381 unmodified lines
642 case PERF_EVSEL__CONFIG_TERM_STACK_USER:653 case PERF_EVSEL__CONFIG_TERM_STACK_USER:
643 dump_size = term->val.stack_user;654 dump_size = term->val.stack_user;
644 break;655 break;
656 case PERF_EVSEL__CONFIG_TERM_INHERIT:
657 /*
658 * attr->inherit should has already been set by
659 * perf_evsel__config. If user explicitly set
660 * inherit using config terms, override global
661 * opt->no_inherit setting.
662 */
663 attr->inherit = term->val.inherit ? 1 : 0;
664 break;
645 default:665 default:
646 break;666 break;
647 }667 }
@@ -872,6 +892,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) · 224 unmodified lines
872 attr->clockid = opts->clockid;892 attr->clockid = opts->clockid;
873 }893 }
874 894
895 if (evsel->precise_max)
896 perf_event_attr__set_max_precise_ip(attr);
897
875 /*898 /*
876 * Apply event specific term settings,899 * Apply event specific term settings,
877 * it overloads any global configuration.900 * it overloads any global configuration.
@@ -1168,7 +1191,7 @@ static void __p_sample_type(char *buf, size_t size, u64 value) · 290 unmodified lines
1168 bit_name(READ), bit_name(CALLCHAIN), bit_name(ID), bit_name(CPU),1191 bit_name(READ), bit_name(CALLCHAIN), bit_name(ID), bit_name(CPU),
1169 bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW),1192 bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW),
1170 bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER),1193 bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER),
1171 bit_name(IDENTIFIER), bit_name(REGS_INTR),1194 bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC),
1172 { .name = NULL, }1195 { .name = NULL, }
1173 };1196 };
1174#undef bit_name1197#undef bit_name
@@ -1249,6 +1272,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, · 74 unmodified lines
1249 PRINT_ATTRf(bp_type, p_unsigned);1272 PRINT_ATTRf(bp_type, p_unsigned);
1250 PRINT_ATTRn("{ bp_addr, config1 }", bp_addr, p_hex);1273 PRINT_ATTRn("{ bp_addr, config1 }", bp_addr, p_hex);
1251 PRINT_ATTRn("{ bp_len, config2 }", bp_len, p_hex);1274 PRINT_ATTRn("{ bp_len, config2 }", bp_len, p_hex);
1275 PRINT_ATTRf(branch_sample_type, p_unsigned);
1252 PRINT_ATTRf(sample_regs_user, p_hex);1276 PRINT_ATTRf(sample_regs_user, p_hex);
1253 PRINT_ATTRf(sample_stack_user, p_unsigned);1277 PRINT_ATTRf(sample_stack_user, p_unsigned);
1254 PRINT_ATTRf(clockid, p_signed);1278 PRINT_ATTRf(clockid, p_signed);
@@ -1333,6 +1357,22 @@ retry_open: · 78 unmodified lines
1333 err);1357 err);
1334 goto try_fallback;1358 goto try_fallback;
1335 }1359 }
1360
1361 if (evsel->bpf_fd >= 0) {
1362 int evt_fd = FD(evsel, cpu, thread);
1363 int bpf_fd = evsel->bpf_fd;
1364
1365 err = ioctl(evt_fd,
1366 PERF_EVENT_IOC_SET_BPF,
1367 bpf_fd);
1368 if (err && errno != EEXIST) {
1369 pr_err("failed to attach bpf fd %d: %s\n",
1370 bpf_fd, strerror(errno));
1371 err = -EINVAL;
1372 goto out_close;
1373 }
1374 }
1375
1336 set_rlimit = NO_CHANGE;1376 set_rlimit = NO_CHANGE;
1337 1377
1338 /*1378 /*
tools/perf/util/evsel.h+8−2
@@ -43,6 +43,7 @@ enum { · 42 unmodified lines
43 PERF_EVSEL__CONFIG_TERM_TIME,43 PERF_EVSEL__CONFIG_TERM_TIME,
44 PERF_EVSEL__CONFIG_TERM_CALLGRAPH,44 PERF_EVSEL__CONFIG_TERM_CALLGRAPH,
45 PERF_EVSEL__CONFIG_TERM_STACK_USER,45 PERF_EVSEL__CONFIG_TERM_STACK_USER,
46 PERF_EVSEL__CONFIG_TERM_INHERIT,
46 PERF_EVSEL__CONFIG_TERM_MAX,47 PERF_EVSEL__CONFIG_TERM_MAX,
47};48};
48 49
@@ -55,6 +56,7 @@ struct perf_evsel_config_term { · 6 unmodified lines
55 bool time;56 bool time;
56 char *callgraph;57 char *callgraph;
57 u64 stack_user;58 u64 stack_user;
59 bool inherit;
58 } val;60 } val;
59};61};
60 62
@@ -90,9 +92,9 @@ struct perf_evsel { · 29 unmodified lines
90 double scale;92 double scale;
91 const char *unit;93 const char *unit;
92 struct event_format *tp_format;94 struct event_format *tp_format;
95 off_t id_offset;
93 union {96 union {
94 void *priv;97 void *priv;
95 off_t id_offset;
96 u64 db_id;98 u64 db_id;
97 };99 };
98 struct cgroup_sel *cgrp;100 struct cgroup_sel *cgrp;
@@ -111,6 +113,7 @@ struct perf_evsel { · 12 unmodified lines
111 bool system_wide;113 bool system_wide;
112 bool tracking;114 bool tracking;
113 bool per_pkg;115 bool per_pkg;
116 bool precise_max;
114 /* parse modifier helper */117 /* parse modifier helper */
115 int exclude_GH;118 int exclude_GH;
116 int nr_members;119 int nr_members;
@@ -120,6 +123,7 @@ struct perf_evsel { · 3 unmodified lines
120 char *group_name;123 char *group_name;
121 bool cmdline_group_boundary;124 bool cmdline_group_boundary;
122 struct list_head config_terms;125 struct list_head config_terms;
126 int bpf_fd;
123};127};
124 128
125union u64_swap {129union u64_swap {
@@ -130,7 +134,6 @@ union u64_swap { · 4 unmodified lines
130struct cpu_map;134struct cpu_map;
131struct target;135struct target;
132struct thread_map;136struct thread_map;
133struct perf_evlist;
134struct record_opts;137struct record_opts;
135 138
136static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)139static inline struct cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)
@@ -162,6 +165,9 @@ static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr) · 25 unmodified lines
162 165
163struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);166struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
164 167
168/*
169 * Returns pointer with encoded error via <linux/err.h> interface.
170 */
165static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)171static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
166{172{
167 return perf_evsel__newtp_idx(sys, name, 0);173 return perf_evsel__newtp_idx(sys, name, 0);
tools/perf/util/header.c+93−43
@@ -24,9 +24,6 @@ · 23 unmodified lines
24#include "build-id.h"24#include "build-id.h"
25#include "data.h"25#include "data.h"
26 26
27static u32 header_argc;
28static const char **header_argv;
29
30/*27/*
31 * magic2 = "PERFILE2"28 * magic2 = "PERFILE2"
32 * must be a numerical value to let the endianness29 * must be a numerical value to let the endianness
@@ -88,6 +85,9 @@ int write_padded(int fd, const void *bf, size_t count, size_t count_aligned) · 55 unmodified lines
88 return err;85 return err;
89}86}
90 87
88#define string_size(str) \
89 (PERF_ALIGN((strlen(str) + 1), NAME_ALIGN) + sizeof(u32))
90
91static int do_write_string(int fd, const char *str)91static int do_write_string(int fd, const char *str)
92{92{
93 u32 len, olen;93 u32 len, olen;
@@ -135,37 +135,6 @@ static char *do_read_string(int fd, struct perf_header *ph) · 41 unmodified lines
135 return NULL;135 return NULL;
136}136}
137 137
138int
139perf_header__set_cmdline(int argc, const char **argv)
140{
141 int i;
142
143 /*
144 * If header_argv has already been set, do not override it.
145 * This allows a command to set the cmdline, parse args and
146 * then call another builtin function that implements a
147 * command -- e.g, cmd_kvm calling cmd_record.
148 */
149 if (header_argv)
150 return 0;
151
152 header_argc = (u32)argc;
153
154 /* do not include NULL termination */
155 header_argv = calloc(argc, sizeof(char *));
156 if (!header_argv)
157 return -ENOMEM;
158
159 /*
160 * must copy argv contents because it gets moved
161 * around during option parsing
162 */
163 for (i = 0; i < argc ; i++)
164 header_argv[i] = argv[i];
165
166 return 0;
167}
168
169static int write_tracing_data(int fd, struct perf_header *h __maybe_unused,138static int write_tracing_data(int fd, struct perf_header *h __maybe_unused,
170 struct perf_evlist *evlist)139 struct perf_evlist *evlist)
171{140{
@@ -402,8 +371,8 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused, · 230 unmodified lines
402{371{
403 char buf[MAXPATHLEN];372 char buf[MAXPATHLEN];
404 char proc[32];373 char proc[32];
405 u32 i, n;374 u32 n;
406 int ret;375 int i, ret;
407 376
408 /*377 /*
409 * actual atual path to perf binary378 * actual atual path to perf binary
@@ -417,7 +386,7 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused, · 7 unmodified lines
417 buf[ret] = '\0';386 buf[ret] = '\0';
418 387
419 /* account for binary path */388 /* account for binary path */
420 n = header_argc + 1;389 n = perf_env.nr_cmdline + 1;
421 390
422 ret = do_write(fd, &n, sizeof(n));391 ret = do_write(fd, &n, sizeof(n));
423 if (ret < 0)392 if (ret < 0)
@@ -427,8 +396,8 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused, · 3 unmodified lines
427 if (ret < 0)396 if (ret < 0)
428 return ret;397 return ret;
429 398
430 for (i = 0 ; i < header_argc; i++) {399 for (i = 0 ; i < perf_env.nr_cmdline; i++) {
431 ret = do_write_string(fd, header_argv[i]);400 ret = do_write_string(fd, perf_env.cmdline_argv[i]);
432 if (ret < 0)401 if (ret < 0)
433 return ret;402 return ret;
434 }403 }
@@ -441,6 +410,7 @@ static int write_cmdline(int fd, struct perf_header *h __maybe_unused, · 6 unmodified lines
441 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list"410 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list"
442 411
443struct cpu_topo {412struct cpu_topo {
413 u32 cpu_nr;
444 u32 core_sib;414 u32 core_sib;
445 u32 thread_sib;415 u32 thread_sib;
446 char **core_siblings;416 char **core_siblings;
@@ -551,7 +521,7 @@ static struct cpu_topo *build_cpu_topology(void) · 104 unmodified lines
551 return NULL;521 return NULL;
552 522
553 tp = addr;523 tp = addr;
554 524 tp->cpu_nr = nr;
555 addr += sizeof(*tp);525 addr += sizeof(*tp);
556 tp->core_siblings = addr;526 tp->core_siblings = addr;
557 addr += sz;527 addr += sz;
@@ -574,7 +544,7 @@ static int write_cpu_topology(int fd, struct perf_header *h __maybe_unused, · 16 unmodified lines
574{544{
575 struct cpu_topo *tp;545 struct cpu_topo *tp;
576 u32 i;546 u32 i;
577 int ret;547 int ret, j;
578 548
579 tp = build_cpu_topology();549 tp = build_cpu_topology();
580 if (!tp)550 if (!tp)
@@ -598,6 +568,21 @@ static int write_cpu_topology(int fd, struct perf_header *h __maybe_unused, · 17 unmodified lines
598 if (ret < 0)568 if (ret < 0)
599 break;569 break;
600 }570 }
571
572 ret = perf_env__read_cpu_topology_map(&perf_env);
573 if (ret < 0)
574 goto done;
575
576 for (j = 0; j < perf_env.nr_cpus_avail; j++) {
577 ret = do_write(fd, &perf_env.cpu[j].core_id,
578 sizeof(perf_env.cpu[j].core_id));
579 if (ret < 0)
580 return ret;
581 ret = do_write(fd, &perf_env.cpu[j].socket_id,
582 sizeof(perf_env.cpu[j].socket_id));
583 if (ret < 0)
584 return ret;
585 }
601done:586done:
602 free_cpu_topo(tp);587 free_cpu_topo(tp);
603 return ret;588 return ret;
@@ -938,6 +923,7 @@ static void print_cpu_topology(struct perf_header *ph, int fd __maybe_unused, · 334 unmodified lines
938{923{
939 int nr, i;924 int nr, i;
940 char *str;925 char *str;
926 int cpu_nr = ph->env.nr_cpus_online;
941 927
942 nr = ph->env.nr_sibling_cores;928 nr = ph->env.nr_sibling_cores;
943 str = ph->env.sibling_cores;929 str = ph->env.sibling_cores;
@@ -954,6 +940,13 @@ static void print_cpu_topology(struct perf_header *ph, int fd __maybe_unused, · 10 unmodified lines
954 fprintf(fp, "# sibling threads : %s\n", str);940 fprintf(fp, "# sibling threads : %s\n", str);
955 str += strlen(str) + 1;941 str += strlen(str) + 1;
956 }942 }
943
944 if (ph->env.cpu != NULL) {
945 for (i = 0; i < cpu_nr; i++)
946 fprintf(fp, "# CPU %d: Core ID %d, Socket ID %d\n", i,
947 ph->env.cpu[i].core_id, ph->env.cpu[i].socket_id);
948 } else
949 fprintf(fp, "# Core ID and Socket ID information is not available\n");
957}950}
958 951
959static void free_event_desc(struct perf_evsel *events)952static void free_event_desc(struct perf_evsel *events)
@@ -1582,7 +1575,7 @@ error: · 622 unmodified lines
1582 return -1;1575 return -1;
1583}1576}
1584 1577
1585static int process_cpu_topology(struct perf_file_section *section __maybe_unused,1578static int process_cpu_topology(struct perf_file_section *section,
1586 struct perf_header *ph, int fd,1579 struct perf_header *ph, int fd,
1587 void *data __maybe_unused)1580 void *data __maybe_unused)
1588{1581{
@@ -1590,15 +1583,22 @@ static int process_cpu_topology(struct perf_file_section *section __maybe_unused · 1 unmodified line
1590 u32 nr, i;1583 u32 nr, i;
1591 char *str;1584 char *str;
1592 struct strbuf sb;1585 struct strbuf sb;
1586 int cpu_nr = ph->env.nr_cpus_online;
1587 u64 size = 0;
1588
1589 ph->env.cpu = calloc(cpu_nr, sizeof(*ph->env.cpu));
1590 if (!ph->env.cpu)
1591 return -1;
1593 1592
1594 ret = readn(fd, &nr, sizeof(nr));1593 ret = readn(fd, &nr, sizeof(nr));
1595 if (ret != sizeof(nr))1594 if (ret != sizeof(nr))
1596 return -1;1595 goto free_cpu;
1597 1596
1598 if (ph->needs_swap)1597 if (ph->needs_swap)
1599 nr = bswap_32(nr);1598 nr = bswap_32(nr);
1600 1599
1601 ph->env.nr_sibling_cores = nr;1600 ph->env.nr_sibling_cores = nr;
1601 size += sizeof(u32);
1602 strbuf_init(&sb, 128);1602 strbuf_init(&sb, 128);
1603 1603
1604 for (i = 0; i < nr; i++) {1604 for (i = 0; i < nr; i++) {
@@ -1608,6 +1608,7 @@ static int process_cpu_topology(struct perf_file_section *section __maybe_unused · 3 unmodified lines
1608 1608
1609 /* include a NULL character at the end */1609 /* include a NULL character at the end */
1610 strbuf_add(&sb, str, strlen(str) + 1);1610 strbuf_add(&sb, str, strlen(str) + 1);
1611 size += string_size(str);
1611 free(str);1612 free(str);
1612 }1613 }
1613 ph->env.sibling_cores = strbuf_detach(&sb, NULL);1614 ph->env.sibling_cores = strbuf_detach(&sb, NULL);
@@ -1620,6 +1621,7 @@ static int process_cpu_topology(struct perf_file_section *section __maybe_unused · 6 unmodified lines
1620 nr = bswap_32(nr);1621 nr = bswap_32(nr);
1621 1622
1622 ph->env.nr_sibling_threads = nr;1623 ph->env.nr_sibling_threads = nr;
1624 size += sizeof(u32);
1623 1625
1624 for (i = 0; i < nr; i++) {1626 for (i = 0; i < nr; i++) {
1625 str = do_read_string(fd, ph);1627 str = do_read_string(fd, ph);
@@ -1628,13 +1630,57 @@ static int process_cpu_topology(struct perf_file_section *section __maybe_unused · 2 unmodified lines
1628 1630
1629 /* include a NULL character at the end */1631 /* include a NULL character at the end */
1630 strbuf_add(&sb, str, strlen(str) + 1);1632 strbuf_add(&sb, str, strlen(str) + 1);
1633 size += string_size(str);
1631 free(str);1634 free(str);
1632 }1635 }
1633 ph->env.sibling_threads = strbuf_detach(&sb, NULL);1636 ph->env.sibling_threads = strbuf_detach(&sb, NULL);
1637
1638 /*
1639 * The header may be from old perf,
1640 * which doesn't include core id and socket id information.
1641 */
1642 if (section->size <= size) {
1643 zfree(&ph->env.cpu);
1644 return 0;
1645 }
1646
1647 for (i = 0; i < (u32)cpu_nr; i++) {
1648 ret = readn(fd, &nr, sizeof(nr));
1649 if (ret != sizeof(nr))
1650 goto free_cpu;
1651
1652 if (ph->needs_swap)
1653 nr = bswap_32(nr);
1654
1655 if (nr > (u32)cpu_nr) {
1656 pr_debug("core_id number is too big."
1657 "You may need to upgrade the perf tool.\n");
1658 goto free_cpu;
1659 }
1660 ph->env.cpu[i].core_id = nr;
1661
1662 ret = readn(fd, &nr, sizeof(nr));
1663 if (ret != sizeof(nr))
1664 goto free_cpu;
1665
1666 if (ph->needs_swap)
1667 nr = bswap_32(nr);
1668
1669 if (nr > (u32)cpu_nr) {
1670 pr_debug("socket_id number is too big."
1671 "You may need to upgrade the perf tool.\n");
1672 goto free_cpu;
1673 }
1674
1675 ph->env.cpu[i].socket_id = nr;
1676 }
1677
1634 return 0;1678 return 0;
1635 1679
1636error:1680error:
1637 strbuf_release(&sb);1681 strbuf_release(&sb);
1682free_cpu:
1683 zfree(&ph->env.cpu);
1638 return -1;1684 return -1;
1639}1685}
1640 1686
@@ -1737,6 +1783,9 @@ static int process_pmu_mappings(struct perf_file_section *section __maybe_unused · 96 unmodified lines
1737 /* include a NULL character at the end */1783 /* include a NULL character at the end */
1738 strbuf_add(&sb, "", 1);1784 strbuf_add(&sb, "", 1);
1739 1785
1786 if (!strcmp(name, "msr"))
1787 ph->env.msr_pmu_type = type;
1788
1740 free(name);1789 free(name);
1741 pmu_num--;1790 pmu_num--;
1742 }1791 }
@@ -2515,6 +2564,7 @@ int perf_session__read_header(struct perf_session *session) · 772 unmodified lines
2515 return -ENOMEM;2564 return -ENOMEM;
2516 2565
2517 session->evlist->env = &header->env;2566 session->evlist->env = &header->env;
2567 session->machines.host.env = &header->env;
2518 if (perf_data_file__is_pipe(file))2568 if (perf_data_file__is_pipe(file))
2519 return perf_header__read_pipe(session);2569 return perf_header__read_pipe(session);
2520 2570
tools/perf/util/header.h+1−26
@@ -7,7 +7,7 @@ · 6 unmodified lines
7#include <linux/bitmap.h>7#include <linux/bitmap.h>
8#include <linux/types.h>8#include <linux/types.h>
9#include "event.h"9#include "event.h"
10 10#include "env.h"
11 11
12enum {12enum {
13 HEADER_RESERVED = 0, /* always cleared */13 HEADER_RESERVED = 0, /* always cleared */
@@ -66,31 +66,6 @@ struct perf_header; · 52 unmodified lines
66int perf_file_header__read(struct perf_file_header *header,66int perf_file_header__read(struct perf_file_header *header,
67 struct perf_header *ph, int fd);67 struct perf_header *ph, int fd);
68 68
69struct perf_env {
70 char *hostname;
71 char *os_release;
72 char *version;
73 char *arch;
74 int nr_cpus_online;
75 int nr_cpus_avail;
76 char *cpu_desc;
77 char *cpuid;
78 unsigned long long total_mem;
79
80 int nr_cmdline;
81 int nr_sibling_cores;
82 int nr_sibling_threads;
83 int nr_numa_nodes;
84 int nr_pmu_mappings;
85 int nr_groups;
86 char *cmdline;
87 const char **cmdline_argv;
88 char *sibling_cores;
89 char *sibling_threads;
90 char *numa_nodes;
91 char *pmu_mappings;
92};
93
94struct perf_header {69struct perf_header {
95 enum perf_header_version version;70 enum perf_header_version version;
96 bool needs_swap;71 bool needs_swap;
tools/perf/util/hist.c+56−3
@@ -15,6 +15,8 @@ static bool hists__filter_entry_by_thread(struct hists *hists, · 14 unmodified lines
15 struct hist_entry *he);15 struct hist_entry *he);
16static bool hists__filter_entry_by_symbol(struct hists *hists,16static bool hists__filter_entry_by_symbol(struct hists *hists,
17 struct hist_entry *he);17 struct hist_entry *he);
18static bool hists__filter_entry_by_socket(struct hists *hists,
19 struct hist_entry *he);
18 20
19u16 hists__col_len(struct hists *hists, enum hist_column col)21u16 hists__col_len(struct hists *hists, enum hist_column col)
20{22{
@@ -130,6 +132,18 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) · 109 unmodified lines
130 hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL,132 hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL,
131 symlen);133 symlen);
132 }134 }
135
136 if (h->mem_info->iaddr.sym) {
137 symlen = (int)h->mem_info->iaddr.sym->namelen + 4
138 + unresolved_col_width + 2;
139 hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL,
140 symlen);
141 } else {
142 symlen = unresolved_col_width + 4 + 2;
143 hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL,
144 symlen);
145 }
146
133 if (h->mem_info->daddr.map) {147 if (h->mem_info->daddr.map) {
134 symlen = dso__name_len(h->mem_info->daddr.map->dso);148 symlen = dso__name_len(h->mem_info->daddr.map->dso);
135 hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,149 hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
@@ -141,9 +155,12 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h) · 5 unmodified lines
141 } else {155 } else {
142 symlen = unresolved_col_width + 4 + 2;156 symlen = unresolved_col_width + 4 + 2;
143 hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen);157 hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen);
158 hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, symlen);
144 hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);159 hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
145 }160 }
146 161
162 hists__new_col_len(hists, HISTC_CPU, 3);
163 hists__new_col_len(hists, HISTC_SOCKET, 6);
147 hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);164 hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);
148 hists__new_col_len(hists, HISTC_MEM_TLB, 22);165 hists__new_col_len(hists, HISTC_MEM_TLB, 22);
149 hists__new_col_len(hists, HISTC_MEM_SNOOP, 12);166 hists__new_col_len(hists, HISTC_MEM_SNOOP, 12);
@@ -452,6 +469,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists, · 302 unmodified lines
452 .map = al->map,469 .map = al->map,
453 .sym = al->sym,470 .sym = al->sym,
454 },471 },
472 .socket = al->socket,
455 .cpu = al->cpu,473 .cpu = al->cpu,
456 .cpumode = al->cpumode,474 .cpumode = al->cpumode,
457 .ip = al->addr,475 .ip = al->addr,
@@ -690,7 +708,7 @@ iter_finish_normal_entry(struct hist_entry_iter *iter, · 232 unmodified lines
690}708}
691 709
692static int710static int
693iter_prepare_cumulative_entry(struct hist_entry_iter *iter __maybe_unused,711iter_prepare_cumulative_entry(struct hist_entry_iter *iter,
694 struct addr_location *al __maybe_unused)712 struct addr_location *al __maybe_unused)
695{713{
696 struct hist_entry **he_cache;714 struct hist_entry **he_cache;
@@ -702,7 +720,7 @@ iter_prepare_cumulative_entry(struct hist_entry_iter *iter __maybe_unused, · 5 unmodified lines
702 * cumulated only one time to prevent entries more than 100%720 * cumulated only one time to prevent entries more than 100%
703 * overhead.721 * overhead.
704 */722 */
705 he_cache = malloc(sizeof(*he_cache) * (PERF_MAX_STACK_DEPTH + 1));723 he_cache = malloc(sizeof(*he_cache) * (iter->max_stack + 1));
706 if (he_cache == NULL)724 if (he_cache == NULL)
707 return -ENOMEM;725 return -ENOMEM;
708 726
@@ -863,6 +881,8 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, · 154 unmodified lines
863 if (err)881 if (err)
864 return err;882 return err;
865 883
884 iter->max_stack = max_stack_depth;
885
866 err = iter->ops->prepare_entry(iter, al);886 err = iter->ops->prepare_entry(iter, al);
867 if (err)887 if (err)
868 goto out;888 goto out;
@@ -1024,6 +1044,7 @@ static void hists__apply_filters(struct hists *hists, struct hist_entry *he) · 155 unmodified lines
1024 hists__filter_entry_by_dso(hists, he);1044 hists__filter_entry_by_dso(hists, he);
1025 hists__filter_entry_by_thread(hists, he);1045 hists__filter_entry_by_thread(hists, he);
1026 hists__filter_entry_by_symbol(hists, he);1046 hists__filter_entry_by_symbol(hists, he);
1047 hists__filter_entry_by_socket(hists, he);
1027}1048}
1028 1049
1029void hists__collapse_resort(struct hists *hists, struct ui_progress *prog)1050void hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
@@ -1143,7 +1164,7 @@ void hists__output_resort(struct hists *hists, struct ui_progress *prog) · 113 unmodified lines
1143 struct perf_evsel *evsel = hists_to_evsel(hists);1164 struct perf_evsel *evsel = hists_to_evsel(hists);
1144 bool use_callchain;1165 bool use_callchain;
1145 1166
1146 if (evsel && !symbol_conf.show_ref_callgraph)1167 if (evsel && symbol_conf.use_callchain && !symbol_conf.show_ref_callgraph)
1147 use_callchain = evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN;1168 use_callchain = evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN;
1148 else1169 else
1149 use_callchain = symbol_conf.use_callchain;1170 use_callchain = symbol_conf.use_callchain;
@@ -1292,6 +1313,37 @@ void hists__filter_by_symbol(struct hists *hists) · 142 unmodified lines
1292 }1313 }
1293}1314}
1294 1315
1316static bool hists__filter_entry_by_socket(struct hists *hists,
1317 struct hist_entry *he)
1318{
1319 if ((hists->socket_filter > -1) &&
1320 (he->socket != hists->socket_filter)) {
1321 he->filtered |= (1 << HIST_FILTER__SOCKET);
1322 return true;
1323 }
1324
1325 return false;
1326}
1327
1328void hists__filter_by_socket(struct hists *hists)
1329{
1330 struct rb_node *nd;
1331
1332 hists->stats.nr_non_filtered_samples = 0;
1333
1334 hists__reset_filter_stats(hists);
1335 hists__reset_col_len(hists);
1336
1337 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
1338 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1339
1340 if (hists__filter_entry_by_socket(hists, h))
1341 continue;
1342
1343 hists__remove_entry_filter(hists, h, HIST_FILTER__SOCKET);
1344 }
1345}
1346
1295void events_stats__inc(struct events_stats *stats, u32 type)1347void events_stats__inc(struct events_stats *stats, u32 type)
1296{1348{
1297 ++stats->nr_events[0];1349 ++stats->nr_events[0];
@@ -1517,6 +1569,7 @@ static int hists_evsel__init(struct perf_evsel *evsel) · 219 unmodified lines
1517 hists->entries_collapsed = RB_ROOT;1569 hists->entries_collapsed = RB_ROOT;
1518 hists->entries = RB_ROOT;1570 hists->entries = RB_ROOT;
1519 pthread_mutex_init(&hists->lock, NULL);1571 pthread_mutex_init(&hists->lock, NULL);
1572 hists->socket_filter = -1;
1520 return 0;1573 return 0;
1521}1574}
1522 1575
tools/perf/util/hist.h+7−1
@@ -20,6 +20,7 @@ enum hist_filter { · 19 unmodified lines
20 HIST_FILTER__SYMBOL,20 HIST_FILTER__SYMBOL,
21 HIST_FILTER__GUEST,21 HIST_FILTER__GUEST,
22 HIST_FILTER__HOST,22 HIST_FILTER__HOST,
23 HIST_FILTER__SOCKET,
23};24};
24 25
25enum hist_column {26enum hist_column {
@@ -29,6 +30,7 @@ enum hist_column { · 3 unmodified lines
29 HISTC_COMM,30 HISTC_COMM,
30 HISTC_PARENT,31 HISTC_PARENT,
31 HISTC_CPU,32 HISTC_CPU,
33 HISTC_SOCKET,
32 HISTC_SRCLINE,34 HISTC_SRCLINE,
33 HISTC_SRCFILE,35 HISTC_SRCFILE,
34 HISTC_MISPREDICT,36 HISTC_MISPREDICT,
@@ -47,6 +49,7 @@ enum hist_column { · 12 unmodified lines
47 HISTC_MEM_LVL,49 HISTC_MEM_LVL,
48 HISTC_MEM_SNOOP,50 HISTC_MEM_SNOOP,
49 HISTC_MEM_DCACHELINE,51 HISTC_MEM_DCACHELINE,
52 HISTC_MEM_IADDR_SYMBOL,
50 HISTC_TRANSACTION,53 HISTC_TRANSACTION,
51 HISTC_CYCLES,54 HISTC_CYCLES,
52 HISTC_NR_COLS, /* Last entry */55 HISTC_NR_COLS, /* Last entry */
@@ -70,6 +73,7 @@ struct hists { · 17 unmodified lines
70 struct events_stats stats;73 struct events_stats stats;
71 u64 event_stream;74 u64 event_stream;
72 u16 col_len[HISTC_NR_COLS];75 u16 col_len[HISTC_NR_COLS];
76 int socket_filter;
73};77};
74 78
75struct hist_entry_iter;79struct hist_entry_iter;
@@ -87,6 +91,7 @@ struct hist_entry_iter { · 11 unmodified lines
87 int curr;91 int curr;
88 92
89 bool hide_unresolved;93 bool hide_unresolved;
94 int max_stack;
90 95
91 struct perf_evsel *evsel;96 struct perf_evsel *evsel;
92 struct perf_sample *sample;97 struct perf_sample *sample;
@@ -144,11 +149,12 @@ size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp); · 51 unmodified lines
144void hists__filter_by_dso(struct hists *hists);149void hists__filter_by_dso(struct hists *hists);
145void hists__filter_by_thread(struct hists *hists);150void hists__filter_by_thread(struct hists *hists);
146void hists__filter_by_symbol(struct hists *hists);151void hists__filter_by_symbol(struct hists *hists);
152void hists__filter_by_socket(struct hists *hists);
147 153
148static inline bool hists__has_filter(struct hists *hists)154static inline bool hists__has_filter(struct hists *hists)
149{155{
150 return hists->thread_filter || hists->dso_filter ||156 return hists->thread_filter || hists->dso_filter ||
151 hists->symbol_filter_str;157 hists->symbol_filter_str || (hists->socket_filter > -1);
152}158}
153 159
154u16 hists__col_len(struct hists *hists, enum hist_column col);160u16 hists__col_len(struct hists *hists, enum hist_column col);
tools/perf/util/include/dwarf-regs.h+8−0
@@ -5,4 +5,12 @@ · 4 unmodified lines
5const char *get_arch_regstr(unsigned int n);5const char *get_arch_regstr(unsigned int n);
6#endif6#endif
7 7
8#ifdef HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
9/*
10 * Arch should support fetching the offset of a register in pt_regs
11 * by its name. See kernel's regs_query_register_offset in
12 * arch/xxx/kernel/ptrace.c.
13 */
14int regs_query_register_offset(const char *name);
15#endif
8#endif16#endif
tools/perf/util/intel-pt-decoder/Build+12−1
@@ -7,6 +7,17 @@ $(OUTPUT)util/intel-pt-decoder/inat-tables.c: $(inat_tables_script) $(inat_table · 6 unmodified lines
7 $(call rule_mkdir)7 $(call rule_mkdir)
8 @$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@ || rm -f $@8 @$(call echo-cmd,gen)$(AWK) -f $(inat_tables_script) $(inat_tables_maps) > $@ || rm -f $@
9 9
10$(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: util/intel-pt-decoder/inat.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c10$(OUTPUT)util/intel-pt-decoder/intel-pt-insn-decoder.o: util/intel-pt-decoder/intel-pt-insn-decoder.c util/intel-pt-decoder/inat.c $(OUTPUT)util/intel-pt-decoder/inat-tables.c
11 @(test -d ../../kernel -a -d ../../tools -a -d ../perf && (( \
12 diff -B -I'^#include' util/intel-pt-decoder/insn.c ../../arch/x86/lib/insn.c >/dev/null && \
13 diff -B -I'^#include' util/intel-pt-decoder/inat.c ../../arch/x86/lib/inat.c >/dev/null && \
14 diff -B util/intel-pt-decoder/x86-opcode-map.txt ../../arch/x86/lib/x86-opcode-map.txt >/dev/null && \
15 diff -B util/intel-pt-decoder/gen-insn-attr-x86.awk ../../arch/x86/tools/gen-insn-attr-x86.awk >/dev/null && \
16 diff -B -I'^#include' util/intel-pt-decoder/insn.h ../../arch/x86/include/asm/insn.h >/dev/null && \
17 diff -B -I'^#include' util/intel-pt-decoder/inat.h ../../arch/x86/include/asm/inat.h >/dev/null && \
18 diff -B -I'^#include' util/intel-pt-decoder/inat_types.h ../../arch/x86/include/asm/inat_types.h >/dev/null) \
19 || echo "Warning: Intel PT: x86 instruction decoder differs from kernel" >&2 )) || true
20 $(call rule_mkdir)
21 $(call if_changed_dep,cc_o_c)
11 22
12CFLAGS_intel-pt-insn-decoder.o += -I$(OUTPUT)util/intel-pt-decoder -Wno-override-init23CFLAGS_intel-pt-insn-decoder.o += -I$(OUTPUT)util/intel-pt-decoder -Wno-override-init
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c+2−2
@@ -650,7 +650,7 @@ static int intel_pt_calc_cyc_cb(struct intel_pt_pkt_info *pkt_info) · 649 unmodified lines
650 if (data->from_mtc && timestamp < data->timestamp &&650 if (data->from_mtc && timestamp < data->timestamp &&
651 data->timestamp - timestamp < decoder->tsc_slip)651 data->timestamp - timestamp < decoder->tsc_slip)
652 return 1;652 return 1;
653 while (timestamp < data->timestamp)653 if (timestamp < data->timestamp)
654 timestamp += (1ULL << 56);654 timestamp += (1ULL << 56);
655 if (pkt_info->last_packet_type != INTEL_PT_CYC) {655 if (pkt_info->last_packet_type != INTEL_PT_CYC) {
656 if (data->from_mtc)656 if (data->from_mtc)
@@ -1191,7 +1191,7 @@ static void intel_pt_calc_tsc_timestamp(struct intel_pt_decoder *decoder) · 534 unmodified lines
1191 timestamp);1191 timestamp);
1192 timestamp = decoder->timestamp;1192 timestamp = decoder->timestamp;
1193 }1193 }
1194 while (timestamp < decoder->timestamp) {1194 if (timestamp < decoder->timestamp) {
1195 intel_pt_log_to("Wraparound timestamp", timestamp);1195 intel_pt_log_to("Wraparound timestamp", timestamp);
1196 timestamp += (1ULL << 56);1196 timestamp += (1ULL << 56);
1197 decoder->tsc_timestamp = timestamp;1197 decoder->tsc_timestamp = timestamp;
tools/perf/util/intel-pt-decoder/intel-pt-log.c+11−10
@@ -29,18 +29,18 @@ · 28 unmodified lines
29 29
30static FILE *f;30static FILE *f;
31static char log_name[MAX_LOG_NAME];31static char log_name[MAX_LOG_NAME];
32static bool enable_logging;32bool intel_pt_enable_logging;
33 33
34void intel_pt_log_enable(void)34void intel_pt_log_enable(void)
35{35{
36 enable_logging = true;36 intel_pt_enable_logging = true;
37}37}
38 38
39void intel_pt_log_disable(void)39void intel_pt_log_disable(void)
40{40{
41 if (f)41 if (f)
42 fflush(f);42 fflush(f);
43 enable_logging = false;43 intel_pt_enable_logging = false;
44}44}
45 45
46void intel_pt_log_set_name(const char *name)46void intel_pt_log_set_name(const char *name)
@@ -80,7 +80,7 @@ static void intel_pt_print_no_data(uint64_t pos, int indent) · 33 unmodified lines
80 80
81static int intel_pt_log_open(void)81static int intel_pt_log_open(void)
82{82{
83 if (!enable_logging)83 if (!intel_pt_enable_logging)
84 return -1;84 return -1;
85 85
86 if (f)86 if (f)
@@ -91,15 +91,15 @@ static int intel_pt_log_open(void) · 4 unmodified lines
91 91
92 f = fopen(log_name, "w+");92 f = fopen(log_name, "w+");
93 if (!f) {93 if (!f) {
94 enable_logging = false;94 intel_pt_enable_logging = false;
95 return -1;95 return -1;
96 }96 }
97 97
98 return 0;98 return 0;
99}99}
100 100
101void intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len,101void __intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len,
102 uint64_t pos, const unsigned char *buf)102 uint64_t pos, const unsigned char *buf)
103{103{
104 char desc[INTEL_PT_PKT_DESC_MAX];104 char desc[INTEL_PT_PKT_DESC_MAX];
105 105
@@ -111,7 +111,7 @@ void intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len, · 5 unmodified lines
111 fprintf(f, "%s\n", desc);111 fprintf(f, "%s\n", desc);
112}112}
113 113
114void intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip)114void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip)
115{115{
116 char desc[INTEL_PT_INSN_DESC_MAX];116 char desc[INTEL_PT_INSN_DESC_MAX];
117 size_t len = intel_pt_insn->length;117 size_t len = intel_pt_insn->length;
@@ -128,7 +128,8 @@ void intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip) · 10 unmodified lines
128 fprintf(f, "Bad instruction!\n");128 fprintf(f, "Bad instruction!\n");
129}129}
130 130
131void intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn, uint64_t ip)131void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn,
132 uint64_t ip)
132{133{
133 char desc[INTEL_PT_INSN_DESC_MAX];134 char desc[INTEL_PT_INSN_DESC_MAX];
134 135
@@ -142,7 +143,7 @@ void intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn, uint64_t ip) · 7 unmodified lines
142 fprintf(f, "Bad instruction!\n");143 fprintf(f, "Bad instruction!\n");
143}144}
144 145
145void intel_pt_log(const char *fmt, ...)146void __intel_pt_log(const char *fmt, ...)
146{147{
147 va_list args;148 va_list args;
148 149
tools/perf/util/intel-pt-decoder/intel-pt-log.h+32−6
@@ -25,20 +25,46 @@ void intel_pt_log_enable(void); · 24 unmodified lines
25void intel_pt_log_disable(void);25void intel_pt_log_disable(void);
26void intel_pt_log_set_name(const char *name);26void intel_pt_log_set_name(const char *name);
27 27
28void intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len,28void __intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len,
29 uint64_t pos, const unsigned char *buf);29 uint64_t pos, const unsigned char *buf);
30 30
31struct intel_pt_insn;31struct intel_pt_insn;
32 32
33void intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip);33void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip);
34void intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn,34void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn,
35 uint64_t ip);35 uint64_t ip);
36 36
37__attribute__((format(printf, 1, 2)))37__attribute__((format(printf, 1, 2)))
38void intel_pt_log(const char *fmt, ...);38void __intel_pt_log(const char *fmt, ...);
39
40#define intel_pt_log(fmt, ...) \
41 do { \
42 if (intel_pt_enable_logging) \
43 __intel_pt_log(fmt, ##__VA_ARGS__); \
44 } while (0)
45
46#define intel_pt_log_packet(arg, ...) \
47 do { \
48 if (intel_pt_enable_logging) \
49 __intel_pt_log_packet(arg, ##__VA_ARGS__); \
50 } while (0)
51
52#define intel_pt_log_insn(arg, ...) \
53 do { \
54 if (intel_pt_enable_logging) \
55 __intel_pt_log_insn(arg, ##__VA_ARGS__); \
56 } while (0)
57
58#define intel_pt_log_insn_no_data(arg, ...) \
59 do { \
60 if (intel_pt_enable_logging) \
61 __intel_pt_log_insn_no_data(arg, ##__VA_ARGS__); \
62 } while (0)
39 63
40#define x64_fmt "0x%" PRIx6464#define x64_fmt "0x%" PRIx64
41 65
66extern bool intel_pt_enable_logging;
67
42static inline void intel_pt_log_at(const char *msg, uint64_t u)68static inline void intel_pt_log_at(const char *msg, uint64_t u)
43{69{
44 intel_pt_log("%s at " x64_fmt "\n", msg, u);70 intel_pt_log("%s at " x64_fmt "\n", msg, u);
tools/perf/util/intel-pt-decoder/x86-opcode-map.txt+19−5
@@ -353,8 +353,12 @@ AVXcode: 1 · 352 unmodified lines
35317: vmovhps Mq,Vq (v1) | vmovhpd Mq,Vq (66),(v1)35317: vmovhps Mq,Vq (v1) | vmovhpd Mq,Vq (66),(v1)
35418: Grp16 (1A)35418: Grp16 (1A)
35519:35519:
3561a: BNDCL Ev,Gv | BNDCU Ev,Gv | BNDMOV Gv,Ev | BNDLDX Gv,Ev,Gv356# Intel SDM opcode map does not list MPX instructions. For now using Gv for
3571b: BNDCN Ev,Gv | BNDMOV Ev,Gv | BNDMK Gv,Ev | BNDSTX Ev,GV,Gv357# bnd registers and Ev for everything else is OK because the instruction
358# decoder does not use the information except as an indication that there is
359# a ModR/M byte.
3601a: BNDCL Gv,Ev (F3) | BNDCU Gv,Ev (F2) | BNDMOV Gv,Ev (66) | BNDLDX Gv,Ev
3611b: BNDCN Gv,Ev (F2) | BNDMOV Ev,Gv (66) | BNDMK Gv,Ev (F3) | BNDSTX Ev,Gv
3581c:3621c:
3591d:3631d:
3601e:3641e:
@@ -732,6 +736,12 @@ bd: vfnmadd231ss/d Vx,Hx,Wx (66),(v),(v1) · 371 unmodified lines
732be: vfnmsub231ps/d Vx,Hx,Wx (66),(v)736be: vfnmsub231ps/d Vx,Hx,Wx (66),(v)
733bf: vfnmsub231ss/d Vx,Hx,Wx (66),(v),(v1)737bf: vfnmsub231ss/d Vx,Hx,Wx (66),(v),(v1)
734# 0x0f 0x38 0xc0-0xff738# 0x0f 0x38 0xc0-0xff
739c8: sha1nexte Vdq,Wdq
740c9: sha1msg1 Vdq,Wdq
741ca: sha1msg2 Vdq,Wdq
742cb: sha256rnds2 Vdq,Wdq
743cc: sha256msg1 Vdq,Wdq
744cd: sha256msg2 Vdq,Wdq
735db: VAESIMC Vdq,Wdq (66),(v1)745db: VAESIMC Vdq,Wdq (66),(v1)
736dc: VAESENC Vdq,Hdq,Wdq (66),(v1)746dc: VAESENC Vdq,Hdq,Wdq (66),(v1)
737dd: VAESENCLAST Vdq,Hdq,Wdq (66),(v1)747dd: VAESENCLAST Vdq,Hdq,Wdq (66),(v1)
@@ -790,6 +800,7 @@ AVXcode: 3 · 52 unmodified lines
79061: vpcmpestri Vdq,Wdq,Ib (66),(v1)80061: vpcmpestri Vdq,Wdq,Ib (66),(v1)
79162: vpcmpistrm Vdq,Wdq,Ib (66),(v1)80162: vpcmpistrm Vdq,Wdq,Ib (66),(v1)
79263: vpcmpistri Vdq,Wdq,Ib (66),(v1)80263: vpcmpistri Vdq,Wdq,Ib (66),(v1)
803cc: sha1rnds4 Vdq,Wdq,Ib
793df: VAESKEYGEN Vdq,Wdq,Ib (66),(v1)804df: VAESKEYGEN Vdq,Wdq,Ib (66),(v1)
794f0: RORX Gy,Ey,Ib (F2),(v)805f0: RORX Gy,Ey,Ib (F2),(v)
795EndTable806EndTable
@@ -874,7 +885,7 @@ GrpTable: Grp7 · 78 unmodified lines
8742: LGDT Ms | XGETBV (000),(11B) | XSETBV (001),(11B) | VMFUNC (100),(11B) | XEND (101)(11B) | XTEST (110)(11B)8852: LGDT Ms | XGETBV (000),(11B) | XSETBV (001),(11B) | VMFUNC (100),(11B) | XEND (101)(11B) | XTEST (110)(11B)
8753: LIDT Ms8863: LIDT Ms
8764: SMSW Mw/Rv8874: SMSW Mw/Rv
8775:8885: rdpkru (110),(11B) | wrpkru (111),(11B)
8786: LMSW Ew8896: LMSW Ew
8797: INVLPG Mb | SWAPGS (o64),(000),(11B) | RDTSCP (001),(11B)8907: INVLPG Mb | SWAPGS (o64),(000),(11B) | RDTSCP (001),(11B)
880EndTable891EndTable
@@ -888,6 +899,9 @@ EndTable · 7 unmodified lines
888 899
889GrpTable: Grp9900GrpTable: Grp9
8901: CMPXCHG8B/16B Mq/Mdq9011: CMPXCHG8B/16B Mq/Mdq
9023: xrstors
9034: xsavec
9045: xsaves
8916: VMPTRLD Mq | VMCLEAR Mq (66) | VMXON Mq (F3) | RDRAND Rv (11B)9056: VMPTRLD Mq | VMCLEAR Mq (66) | VMXON Mq (F3) | RDRAND Rv (11B)
8927: VMPTRST Mq | VMPTRST Mq (F3) | RDSEED Rv (11B)9067: VMPTRST Mq | VMPTRST Mq (F3) | RDSEED Rv (11B)
893EndTable907EndTable
@@ -932,8 +946,8 @@ GrpTable: Grp15 · 38 unmodified lines
9323: vstmxcsr Md (v1) | WRGSBASE Ry (F3),(11B)9463: vstmxcsr Md (v1) | WRGSBASE Ry (F3),(11B)
9334: XSAVE9474: XSAVE
9345: XRSTOR | lfence (11B)9485: XRSTOR | lfence (11B)
9356: XSAVEOPT | mfence (11B)9496: XSAVEOPT | clwb (66) | mfence (11B)
9367: clflush | sfence (11B)9507: clflush | clflushopt (66) | sfence (11B) | pcommit (66),(11B)
937EndTable951EndTable
938 952
939GrpTable: Grp16953GrpTable: Grp16
tools/perf/util/intel-pt.c+237−29
@@ -22,6 +22,7 @@ · 21 unmodified lines
22#include "../perf.h"22#include "../perf.h"
23#include "session.h"23#include "session.h"
24#include "machine.h"24#include "machine.h"
25#include "sort.h"
25#include "tool.h"26#include "tool.h"
26#include "event.h"27#include "event.h"
27#include "evlist.h"28#include "evlist.h"
@@ -63,6 +64,7 @@ struct intel_pt { · 35 unmodified lines
63 bool data_queued;64 bool data_queued;
64 bool est_tsc;65 bool est_tsc;
65 bool sync_switch;66 bool sync_switch;
67 bool mispred_all;
66 int have_sched_switch;68 int have_sched_switch;
67 u32 pmu_type;69 u32 pmu_type;
68 u64 kernel_start;70 u64 kernel_start;
@@ -115,6 +117,9 @@ struct intel_pt_queue { · 46 unmodified lines
115 void *decoder;117 void *decoder;
116 const struct intel_pt_state *state;118 const struct intel_pt_state *state;
117 struct ip_callchain *chain;119 struct ip_callchain *chain;
120 struct branch_stack *last_branch;
121 struct branch_stack *last_branch_rb;
122 size_t last_branch_pos;
118 union perf_event *event_buf;123 union perf_event *event_buf;
119 bool on_heap;124 bool on_heap;
120 bool stop;125 bool stop;
@@ -675,6 +680,19 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, · 554 unmodified lines
675 goto out_free;680 goto out_free;
676 }681 }
677 682
683 if (pt->synth_opts.last_branch) {
684 size_t sz = sizeof(struct branch_stack);
685
686 sz += pt->synth_opts.last_branch_sz *
687 sizeof(struct branch_entry);
688 ptq->last_branch = zalloc(sz);
689 if (!ptq->last_branch)
690 goto out_free;
691 ptq->last_branch_rb = zalloc(sz);
692 if (!ptq->last_branch_rb)
693 goto out_free;
694 }
695
678 ptq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE);696 ptq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE);
679 if (!ptq->event_buf)697 if (!ptq->event_buf)
680 goto out_free;698 goto out_free;
@@ -720,7 +738,7 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, · 39 unmodified lines
720 738
721 if (!params.period) {739 if (!params.period) {
722 params.period_type = INTEL_PT_PERIOD_INSTRUCTIONS;740 params.period_type = INTEL_PT_PERIOD_INSTRUCTIONS;
723 params.period = 1000;741 params.period = 1;
724 }742 }
725 }743 }
726 744
@@ -732,6 +750,8 @@ static struct intel_pt_queue *intel_pt_alloc_queue(struct intel_pt *pt, · 5 unmodified lines
732 750
733out_free:751out_free:
734 zfree(&ptq->event_buf);752 zfree(&ptq->event_buf);
753 zfree(&ptq->last_branch);
754 zfree(&ptq->last_branch_rb);
735 zfree(&ptq->chain);755 zfree(&ptq->chain);
736 free(ptq);756 free(ptq);
737 return NULL;757 return NULL;
@@ -746,6 +766,8 @@ static void intel_pt_free_queue(void *priv) · 8 unmodified lines
746 thread__zput(ptq->thread);766 thread__zput(ptq->thread);
747 intel_pt_decoder_free(ptq->decoder);767 intel_pt_decoder_free(ptq->decoder);
748 zfree(&ptq->event_buf);768 zfree(&ptq->event_buf);
769 zfree(&ptq->last_branch);
770 zfree(&ptq->last_branch_rb);
749 zfree(&ptq->chain);771 zfree(&ptq->chain);
750 free(ptq);772 free(ptq);
751}773}
@@ -876,6 +898,58 @@ static int intel_pt_setup_queues(struct intel_pt *pt) · 124 unmodified lines
876 return 0;898 return 0;
877}899}
878 900
901static inline void intel_pt_copy_last_branch_rb(struct intel_pt_queue *ptq)
902{
903 struct branch_stack *bs_src = ptq->last_branch_rb;
904 struct branch_stack *bs_dst = ptq->last_branch;
905 size_t nr = 0;
906
907 bs_dst->nr = bs_src->nr;
908
909 if (!bs_src->nr)
910 return;
911
912 nr = ptq->pt->synth_opts.last_branch_sz - ptq->last_branch_pos;
913 memcpy(&bs_dst->entries[0],
914 &bs_src->entries[ptq->last_branch_pos],
915 sizeof(struct branch_entry) * nr);
916
917 if (bs_src->nr >= ptq->pt->synth_opts.last_branch_sz) {
918 memcpy(&bs_dst->entries[nr],
919 &bs_src->entries[0],
920 sizeof(struct branch_entry) * ptq->last_branch_pos);
921 }
922}
923
924static inline void intel_pt_reset_last_branch_rb(struct intel_pt_queue *ptq)
925{
926 ptq->last_branch_pos = 0;
927 ptq->last_branch_rb->nr = 0;
928}
929
930static void intel_pt_update_last_branch_rb(struct intel_pt_queue *ptq)
931{
932 const struct intel_pt_state *state = ptq->state;
933 struct branch_stack *bs = ptq->last_branch_rb;
934 struct branch_entry *be;
935
936 if (!ptq->last_branch_pos)
937 ptq->last_branch_pos = ptq->pt->synth_opts.last_branch_sz;
938
939 ptq->last_branch_pos -= 1;
940
941 be = &bs->entries[ptq->last_branch_pos];
942 be->from = state->from_ip;
943 be->to = state->to_ip;
944 be->flags.abort = !!(state->flags & INTEL_PT_ABORT_TX);
945 be->flags.in_tx = !!(state->flags & INTEL_PT_IN_TX);
946 /* No support for mispredict */
947 be->flags.mispred = ptq->pt->mispred_all;
948
949 if (bs->nr < ptq->pt->synth_opts.last_branch_sz)
950 bs->nr += 1;
951}
952
879static int intel_pt_inject_event(union perf_event *event,953static int intel_pt_inject_event(union perf_event *event,
880 struct perf_sample *sample, u64 type,954 struct perf_sample *sample, u64 type,
881 bool swapped)955 bool swapped)
@@ -890,6 +964,13 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq) · 8 unmodified lines
890 struct intel_pt *pt = ptq->pt;964 struct intel_pt *pt = ptq->pt;
891 union perf_event *event = ptq->event_buf;965 union perf_event *event = ptq->event_buf;
892 struct perf_sample sample = { .ip = 0, };966 struct perf_sample sample = { .ip = 0, };
967 struct dummy_branch_stack {
968 u64 nr;
969 struct branch_entry entries;
970 } dummy_bs;
971
972 if (pt->branches_filter && !(pt->branches_filter & ptq->flags))
973 return 0;
893 974
894 event->sample.header.type = PERF_RECORD_SAMPLE;975 event->sample.header.type = PERF_RECORD_SAMPLE;
895 event->sample.header.misc = PERF_RECORD_MISC_USER;976 event->sample.header.misc = PERF_RECORD_MISC_USER;
@@ -909,8 +990,20 @@ static int intel_pt_synth_branch_sample(struct intel_pt_queue *ptq) · 13 unmodified lines
909 sample.flags = ptq->flags;990 sample.flags = ptq->flags;
910 sample.insn_len = ptq->insn_len;991 sample.insn_len = ptq->insn_len;
911 992
912 if (pt->branches_filter && !(pt->branches_filter & ptq->flags))993 /*
913 return 0;994 * perf report cannot handle events without a branch stack when using
995 * SORT_MODE__BRANCH so make a dummy one.
996 */
997 if (pt->synth_opts.last_branch && sort__mode == SORT_MODE__BRANCH) {
998 dummy_bs = (struct dummy_branch_stack){
999 .nr = 1,
1000 .entries = {
1001 .from = sample.ip,
1002 .to = sample.addr,
1003 },
1004 };
1005 sample.branch_stack = (struct branch_stack *)&dummy_bs;
1006 }
914 1007
915 if (pt->synth_opts.inject) {1008 if (pt->synth_opts.inject) {
916 ret = intel_pt_inject_event(event, &sample,1009 ret = intel_pt_inject_event(event, &sample,
@@ -961,6 +1054,11 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq) · 44 unmodified lines
961 sample.callchain = ptq->chain;1054 sample.callchain = ptq->chain;
962 }1055 }
963 1056
1057 if (pt->synth_opts.last_branch) {
1058 intel_pt_copy_last_branch_rb(ptq);
1059 sample.branch_stack = ptq->last_branch;
1060 }
1061
964 if (pt->synth_opts.inject) {1062 if (pt->synth_opts.inject) {
965 ret = intel_pt_inject_event(event, &sample,1063 ret = intel_pt_inject_event(event, &sample,
966 pt->instructions_sample_type,1064 pt->instructions_sample_type,
@@ -974,6 +1072,9 @@ static int intel_pt_synth_instruction_sample(struct intel_pt_queue *ptq) · 7 unmodified lines
974 pr_err("Intel Processor Trace: failed to deliver instruction event, error %d\n",1072 pr_err("Intel Processor Trace: failed to deliver instruction event, error %d\n",
975 ret);1073 ret);
976 1074
1075 if (pt->synth_opts.last_branch)
1076 intel_pt_reset_last_branch_rb(ptq);
1077
977 return ret;1078 return ret;
978}1079}
979 1080
@@ -1008,6 +1109,11 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq) · 28 unmodified lines
1008 sample.callchain = ptq->chain;1109 sample.callchain = ptq->chain;
1009 }1110 }
1010 1111
1112 if (pt->synth_opts.last_branch) {
1113 intel_pt_copy_last_branch_rb(ptq);
1114 sample.branch_stack = ptq->last_branch;
1115 }
1116
1011 if (pt->synth_opts.inject) {1117 if (pt->synth_opts.inject) {
1012 ret = intel_pt_inject_event(event, &sample,1118 ret = intel_pt_inject_event(event, &sample,
1013 pt->transactions_sample_type,1119 pt->transactions_sample_type,
@@ -1021,6 +1127,9 @@ static int intel_pt_synth_transaction_sample(struct intel_pt_queue *ptq) · 7 unmodified lines
1021 pr_err("Intel Processor Trace: failed to deliver transaction event, error %d\n",1127 pr_err("Intel Processor Trace: failed to deliver transaction event, error %d\n",
1022 ret);1128 ret);
1023 1129
1130 if (pt->synth_opts.callchain)
1131 intel_pt_reset_last_branch_rb(ptq);
1132
1024 return ret;1133 return ret;
1025}1134}
1026 1135
@@ -1116,6 +1225,9 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) · 89 unmodified lines
1116 return err;1225 return err;
1117 }1226 }
1118 1227
1228 if (pt->synth_opts.last_branch)
1229 intel_pt_update_last_branch_rb(ptq);
1230
1119 if (!pt->sync_switch)1231 if (!pt->sync_switch)
1120 return 0;1232 return 0;
1121 1233
@@ -1145,16 +1257,18 @@ static int intel_pt_sample(struct intel_pt_queue *ptq) · 23 unmodified lines
1145 return 0;1257 return 0;
1146}1258}
1147 1259
1148static u64 intel_pt_switch_ip(struct machine *machine, u64 *ptss_ip)1260static u64 intel_pt_switch_ip(struct intel_pt *pt, u64 *ptss_ip)
1149{1261{
1262 struct machine *machine = pt->machine;
1150 struct map *map;1263 struct map *map;
1151 struct symbol *sym, *start;1264 struct symbol *sym, *start;
1152 u64 ip, switch_ip = 0;1265 u64 ip, switch_ip = 0;
1266 const char *ptss;
1153 1267
1154 if (ptss_ip)1268 if (ptss_ip)
1155 *ptss_ip = 0;1269 *ptss_ip = 0;
1156 1270
1157 map = machine__kernel_map(machine, MAP__FUNCTION);1271 map = machine__kernel_map(machine);
1158 if (!map)1272 if (!map)
1159 return 0;1273 return 0;
1160 1274
@@ -1177,8 +1291,13 @@ static u64 intel_pt_switch_ip(struct machine *machine, u64 *ptss_ip) · 16 unmodified lines
1177 if (!switch_ip || !ptss_ip)1291 if (!switch_ip || !ptss_ip)
1178 return 0;1292 return 0;
1179 1293
1294 if (pt->have_sched_switch == 1)
1295 ptss = "perf_trace_sched_switch";
1296 else
1297 ptss = "__perf_event_task_sched_out";
1298
1180 for (sym = start; sym; sym = dso__next_symbol(sym)) {1299 for (sym = start; sym; sym = dso__next_symbol(sym)) {
1181 if (!strcmp(sym->name, "perf_trace_sched_switch")) {1300 if (!strcmp(sym->name, ptss)) {
1182 ip = map->unmap_ip(map, sym->start);1301 ip = map->unmap_ip(map, sym->start);
1183 if (ip >= map->start && ip < map->end) {1302 if (ip >= map->start && ip < map->end) {
1184 *ptss_ip = ip;1303 *ptss_ip = ip;
@@ -1198,11 +1317,11 @@ static int intel_pt_run_decoder(struct intel_pt_queue *ptq, u64 *timestamp) · 13 unmodified lines
1198 1317
1199 if (!pt->kernel_start) {1318 if (!pt->kernel_start) {
1200 pt->kernel_start = machine__kernel_start(pt->machine);1319 pt->kernel_start = machine__kernel_start(pt->machine);
1201 if (pt->per_cpu_mmaps && pt->have_sched_switch &&1320 if (pt->per_cpu_mmaps &&
1321 (pt->have_sched_switch == 1 || pt->have_sched_switch == 3) &&
1202 !pt->timeless_decoding && intel_pt_tracing_kernel(pt) &&1322 !pt->timeless_decoding && intel_pt_tracing_kernel(pt) &&
1203 !pt->sampling_mode) {1323 !pt->sampling_mode) {
1204 pt->switch_ip = intel_pt_switch_ip(pt->machine,1324 pt->switch_ip = intel_pt_switch_ip(pt, &pt->ptss_ip);
1205 &pt->ptss_ip);
1206 if (pt->switch_ip) {1325 if (pt->switch_ip) {
1207 intel_pt_log("switch_ip: %"PRIx64" ptss_ip: %"PRIx64"\n",1326 intel_pt_log("switch_ip: %"PRIx64" ptss_ip: %"PRIx64"\n",
1208 pt->switch_ip, pt->ptss_ip);1327 pt->switch_ip, pt->ptss_ip);
@@ -1387,31 +1506,18 @@ static struct intel_pt_queue *intel_pt_cpu_to_ptq(struct intel_pt *pt, int cpu) · 178 unmodified lines
1387 return NULL;1506 return NULL;
1388}1507}
1389 1508
1390static int intel_pt_process_switch(struct intel_pt *pt,1509static int intel_pt_sync_switch(struct intel_pt *pt, int cpu, pid_t tid,
1391 struct perf_sample *sample)1510 u64 timestamp)
1392{1511{
1393 struct intel_pt_queue *ptq;1512 struct intel_pt_queue *ptq;
1394 struct perf_evsel *evsel;1513 int err;
1395 pid_t tid;
1396 int cpu, err;
1397
1398 evsel = perf_evlist__id2evsel(pt->session->evlist, sample->id);
1399 if (evsel != pt->switch_evsel)
1400 return 0;
1401
1402 tid = perf_evsel__intval(evsel, sample, "next_pid");
1403 cpu = sample->cpu;
1404
1405 intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n",
1406 cpu, tid, sample->time, perf_time_to_tsc(sample->time,
1407 &pt->tc));
1408 1514
1409 if (!pt->sync_switch)1515 if (!pt->sync_switch)
1410 goto out;1516 return 1;
1411 1517
1412 ptq = intel_pt_cpu_to_ptq(pt, cpu);1518 ptq = intel_pt_cpu_to_ptq(pt, cpu);
1413 if (!ptq)1519 if (!ptq)
1414 goto out;1520 return 1;
1415 1521
1416 switch (ptq->switch_state) {1522 switch (ptq->switch_state) {
1417 case INTEL_PT_SS_NOT_TRACING:1523 case INTEL_PT_SS_NOT_TRACING:
@@ -1424,7 +1530,7 @@ static int intel_pt_process_switch(struct intel_pt *pt, · 6 unmodified lines
1424 return 0;1530 return 0;
1425 case INTEL_PT_SS_EXPECTING_SWITCH_EVENT:1531 case INTEL_PT_SS_EXPECTING_SWITCH_EVENT:
1426 if (!ptq->on_heap) {1532 if (!ptq->on_heap) {
1427 ptq->timestamp = perf_time_to_tsc(sample->time,1533 ptq->timestamp = perf_time_to_tsc(timestamp,
1428 &pt->tc);1534 &pt->tc);
1429 err = auxtrace_heap__add(&pt->heap, ptq->queue_nr,1535 err = auxtrace_heap__add(&pt->heap, ptq->queue_nr,
1430 ptq->timestamp);1536 ptq->timestamp);
@@ -1441,10 +1547,76 @@ static int intel_pt_process_switch(struct intel_pt *pt, · 10 unmodified lines
1441 default:1547 default:
1442 break;1548 break;
1443 }1549 }
1444out:1550
1551 return 1;
1552}
1553
1554static int intel_pt_process_switch(struct intel_pt *pt,
1555 struct perf_sample *sample)
1556{
1557 struct perf_evsel *evsel;
1558 pid_t tid;
1559 int cpu, ret;
1560
1561 evsel = perf_evlist__id2evsel(pt->session->evlist, sample->id);
1562 if (evsel != pt->switch_evsel)
1563 return 0;
1564
1565 tid = perf_evsel__intval(evsel, sample, "next_pid");
1566 cpu = sample->cpu;
1567
1568 intel_pt_log("sched_switch: cpu %d tid %d time %"PRIu64" tsc %#"PRIx64"\n",
1569 cpu, tid, sample->time, perf_time_to_tsc(sample->time,
1570 &pt->tc));
1571
1572 ret = intel_pt_sync_switch(pt, cpu, tid, sample->time);
1573 if (ret <= 0)
1574 return ret;
1575
1445 return machine__set_current_tid(pt->machine, cpu, -1, tid);1576 return machine__set_current_tid(pt->machine, cpu, -1, tid);
1446}1577}
1447 1578
1579static int intel_pt_context_switch(struct intel_pt *pt, union perf_event *event,
1580 struct perf_sample *sample)
1581{
1582 bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT;
1583 pid_t pid, tid;
1584 int cpu, ret;
1585
1586 cpu = sample->cpu;
1587
1588 if (pt->have_sched_switch == 3) {
1589 if (!out)
1590 return 0;
1591 if (event->header.type != PERF_RECORD_SWITCH_CPU_WIDE) {
1592 pr_err("Expecting CPU-wide context switch event\n");
1593 return -EINVAL;
1594 }
1595 pid = event->context_switch.next_prev_pid;
1596 tid = event->context_switch.next_prev_tid;
1597 } else {
1598 if (out)
1599 return 0;
1600 pid = sample->pid;
1601 tid = sample->tid;
1602 }
1603
1604 if (tid == -1) {
1605 pr_err("context_switch event has no tid\n");
1606 return -EINVAL;
1607 }
1608
1609 intel_pt_log("context_switch: cpu %d pid %d tid %d time %"PRIu64" tsc %#"PRIx64"\n",
1610 cpu, pid, tid, sample->time, perf_time_to_tsc(sample->time,
1611 &pt->tc));
1612
1613 ret = intel_pt_sync_switch(pt, cpu, tid, sample->time);
1614 if (ret <= 0)
1615 return ret;
1616
1617 return machine__set_current_tid(pt->machine, cpu, pid, tid);
1618}
1619
1448static int intel_pt_process_itrace_start(struct intel_pt *pt,1620static int intel_pt_process_itrace_start(struct intel_pt *pt,
1449 union perf_event *event,1621 union perf_event *event,
1450 struct perf_sample *sample)1622 struct perf_sample *sample)
@@ -1515,6 +1687,9 @@ static int intel_pt_process_event(struct perf_session *session, · 64 unmodified lines
1515 err = intel_pt_process_switch(pt, sample);1687 err = intel_pt_process_switch(pt, sample);
1516 else if (event->header.type == PERF_RECORD_ITRACE_START)1688 else if (event->header.type == PERF_RECORD_ITRACE_START)
1517 err = intel_pt_process_itrace_start(pt, event, sample);1689 err = intel_pt_process_itrace_start(pt, event, sample);
1690 else if (event->header.type == PERF_RECORD_SWITCH ||
1691 event->header.type == PERF_RECORD_SWITCH_CPU_WIDE)
1692 err = intel_pt_context_switch(pt, event, sample);
1518 1693
1519 intel_pt_log("event %s (%u): cpu %d time %"PRIu64" tsc %#"PRIx64"\n",1694 intel_pt_log("event %s (%u): cpu %d time %"PRIu64" tsc %#"PRIx64"\n",
1520 perf_event__name(event->header.type), event->header.type,1695 perf_event__name(event->header.type), event->header.type,
@@ -1700,6 +1875,8 @@ static int intel_pt_synth_events(struct intel_pt *pt, · 179 unmodified lines
1700 pt->instructions_sample_period = attr.sample_period;1875 pt->instructions_sample_period = attr.sample_period;
1701 if (pt->synth_opts.callchain)1876 if (pt->synth_opts.callchain)
1702 attr.sample_type |= PERF_SAMPLE_CALLCHAIN;1877 attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
1878 if (pt->synth_opts.last_branch)
1879 attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
1703 pr_debug("Synthesizing 'instructions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",1880 pr_debug("Synthesizing 'instructions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
1704 id, (u64)attr.sample_type);1881 id, (u64)attr.sample_type);
1705 err = intel_pt_synth_event(session, &attr, id);1882 err = intel_pt_synth_event(session, &attr, id);
@@ -1719,6 +1896,8 @@ static int intel_pt_synth_events(struct intel_pt *pt, · 13 unmodified lines
1719 attr.sample_period = 1;1896 attr.sample_period = 1;
1720 if (pt->synth_opts.callchain)1897 if (pt->synth_opts.callchain)
1721 attr.sample_type |= PERF_SAMPLE_CALLCHAIN;1898 attr.sample_type |= PERF_SAMPLE_CALLCHAIN;
1899 if (pt->synth_opts.last_branch)
1900 attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
1722 pr_debug("Synthesizing 'transactions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",1901 pr_debug("Synthesizing 'transactions' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
1723 id, (u64)attr.sample_type);1902 id, (u64)attr.sample_type);
1724 err = intel_pt_synth_event(session, &attr, id);1903 err = intel_pt_synth_event(session, &attr, id);
@@ -1745,6 +1924,7 @@ static int intel_pt_synth_events(struct intel_pt *pt, · 20 unmodified lines
1745 attr.sample_period = 1;1924 attr.sample_period = 1;
1746 attr.sample_type |= PERF_SAMPLE_ADDR;1925 attr.sample_type |= PERF_SAMPLE_ADDR;
1747 attr.sample_type &= ~(u64)PERF_SAMPLE_CALLCHAIN;1926 attr.sample_type &= ~(u64)PERF_SAMPLE_CALLCHAIN;
1927 attr.sample_type &= ~(u64)PERF_SAMPLE_BRANCH_STACK;
1748 pr_debug("Synthesizing 'branches' event with id %" PRIu64 " sample type %#" PRIx64 "\n",1928 pr_debug("Synthesizing 'branches' event with id %" PRIu64 " sample type %#" PRIx64 "\n",
1749 id, (u64)attr.sample_type);1929 id, (u64)attr.sample_type);
1750 err = intel_pt_synth_event(session, &attr, id);1930 err = intel_pt_synth_event(session, &attr, id);
@@ -1777,6 +1957,28 @@ static struct perf_evsel *intel_pt_find_sched_switch(struct perf_evlist *evlist) · 26 unmodified lines
1777 return NULL;1957 return NULL;
1778}1958}
1779 1959
1960static bool intel_pt_find_switch(struct perf_evlist *evlist)
1961{
1962 struct perf_evsel *evsel;
1963
1964 evlist__for_each(evlist, evsel) {
1965 if (evsel->attr.context_switch)
1966 return true;
1967 }
1968
1969 return false;
1970}
1971
1972static int intel_pt_perf_config(const char *var, const char *value, void *data)
1973{
1974 struct intel_pt *pt = data;
1975
1976 if (!strcmp(var, "intel-pt.mispred-all"))
1977 pt->mispred_all = perf_config_bool(var, value);
1978
1979 return 0;
1980}
1981
1780static const char * const intel_pt_info_fmts[] = {1982static const char * const intel_pt_info_fmts[] = {
1781 [INTEL_PT_PMU_TYPE] = " PMU Type %"PRId64"\n",1983 [INTEL_PT_PMU_TYPE] = " PMU Type %"PRId64"\n",
1782 [INTEL_PT_TIME_SHIFT] = " Time Shift %"PRIu64"\n",1984 [INTEL_PT_TIME_SHIFT] = " Time Shift %"PRIu64"\n",
@@ -1821,6 +2023,8 @@ int intel_pt_process_auxtrace_info(union perf_event *event, · 38 unmodified lines
1821 if (!pt)2023 if (!pt)
1822 return -ENOMEM;2024 return -ENOMEM;
1823 2025
2026 perf_config(intel_pt_perf_config, pt);
2027
1824 err = auxtrace_queues__init(&pt->queues);2028 err = auxtrace_queues__init(&pt->queues);
1825 if (err)2029 if (err)
1826 goto err_free;2030 goto err_free;
@@ -1888,6 +2092,10 @@ int intel_pt_process_auxtrace_info(union perf_event *event, · 61 unmodified lines
1888 pr_err("%s: missing sched_switch event\n", __func__);2092 pr_err("%s: missing sched_switch event\n", __func__);
1889 goto err_delete_thread;2093 goto err_delete_thread;
1890 }2094 }
2095 } else if (pt->have_sched_switch == 2 &&
2096 !intel_pt_find_switch(session->evlist)) {
2097 pr_err("%s: missing context_switch attribute flag\n", __func__);
2098 goto err_delete_thread;
1891 }2099 }
1892 2100
1893 if (session->itrace_synth_opts && session->itrace_synth_opts->set) {2101 if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
tools/perf/util/machine.c+15−14
@@ -35,6 +35,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) · 34 unmodified lines
35 machine->last_match = NULL;35 machine->last_match = NULL;
36 36
37 machine->vdso_info = NULL;37 machine->vdso_info = NULL;
38 machine->env = NULL;
38 39
39 machine->pid = pid;40 machine->pid = pid;
40 41
@@ -624,7 +625,7 @@ size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp) · 583 unmodified lines
624{625{
625 int i;626 int i;
626 size_t printed = 0;627 size_t printed = 0;
627 struct dso *kdso = machine->vmlinux_maps[MAP__FUNCTION]->dso;628 struct dso *kdso = machine__kernel_map(machine)->dso;
628 629
629 if (kdso->has_build_id) {630 if (kdso->has_build_id) {
630 char filename[PATH_MAX];631 char filename[PATH_MAX];
@@ -740,6 +741,7 @@ int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel) · 109 unmodified lines
740 741
741 for (type = 0; type < MAP__NR_TYPES; ++type) {742 for (type = 0; type < MAP__NR_TYPES; ++type) {
742 struct kmap *kmap;743 struct kmap *kmap;
744 struct map *map;
743 745
744 machine->vmlinux_maps[type] = map__new2(start, kernel, type);746 machine->vmlinux_maps[type] = map__new2(start, kernel, type);
745 if (machine->vmlinux_maps[type] == NULL)747 if (machine->vmlinux_maps[type] == NULL)
@@ -748,13 +750,13 @@ int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel) · 2 unmodified lines
748 machine->vmlinux_maps[type]->map_ip =750 machine->vmlinux_maps[type]->map_ip =
749 machine->vmlinux_maps[type]->unmap_ip =751 machine->vmlinux_maps[type]->unmap_ip =
750 identity__map_ip;752 identity__map_ip;
751 kmap = map__kmap(machine->vmlinux_maps[type]);753 map = __machine__kernel_map(machine, type);
754 kmap = map__kmap(map);
752 if (!kmap)755 if (!kmap)
753 return -1;756 return -1;
754 757
755 kmap->kmaps = &machine->kmaps;758 kmap->kmaps = &machine->kmaps;
756 map_groups__insert(&machine->kmaps,759 map_groups__insert(&machine->kmaps, map);
757 machine->vmlinux_maps[type]);
758 }760 }
759 761
760 return 0;762 return 0;
@@ -766,13 +768,13 @@ void machine__destroy_kernel_maps(struct machine *machine) · 5 unmodified lines
766 768
767 for (type = 0; type < MAP__NR_TYPES; ++type) {769 for (type = 0; type < MAP__NR_TYPES; ++type) {
768 struct kmap *kmap;770 struct kmap *kmap;
771 struct map *map = __machine__kernel_map(machine, type);
769 772
770 if (machine->vmlinux_maps[type] == NULL)773 if (map == NULL)
771 continue;774 continue;
772 775
773 kmap = map__kmap(machine->vmlinux_maps[type]);776 kmap = map__kmap(map);
774 map_groups__remove(&machine->kmaps,777 map_groups__remove(&machine->kmaps, map);
775 machine->vmlinux_maps[type]);
776 if (kmap && kmap->ref_reloc_sym) {778 if (kmap && kmap->ref_reloc_sym) {
777 /*779 /*
778 * ref_reloc_sym is shared among all maps, so free just780 * ref_reloc_sym is shared among all maps, so free just
@@ -866,7 +868,7 @@ int machines__create_kernel_maps(struct machines *machines, pid_t pid) · 87 unmodified lines
866int machine__load_kallsyms(struct machine *machine, const char *filename,868int machine__load_kallsyms(struct machine *machine, const char *filename,
867 enum map_type type, symbol_filter_t filter)869 enum map_type type, symbol_filter_t filter)
868{870{
869 struct map *map = machine->vmlinux_maps[type];871 struct map *map = machine__kernel_map(machine);
870 int ret = dso__load_kallsyms(map->dso, filename, map, filter);872 int ret = dso__load_kallsyms(map->dso, filename, map, filter);
871 873
872 if (ret > 0) {874 if (ret > 0) {
@@ -885,7 +887,7 @@ int machine__load_kallsyms(struct machine *machine, const char *filename, · 12 unmodified lines
885int machine__load_vmlinux_path(struct machine *machine, enum map_type type,887int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
886 symbol_filter_t filter)888 symbol_filter_t filter)
887{889{
888 struct map *map = machine->vmlinux_maps[type];890 struct map *map = machine__kernel_map(machine);
889 int ret = dso__load_vmlinux_path(map->dso, map, filter);891 int ret = dso__load_vmlinux_path(map->dso, map, filter);
890 892
891 if (ret > 0)893 if (ret > 0)
@@ -1243,8 +1245,7 @@ static int machine__process_kernel_mmap_event(struct machine *machine, · 351 unmodified lines
1243 /*1245 /*
1244 * preload dso of guest kernel and modules1246 * preload dso of guest kernel and modules
1245 */1247 */
1246 dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],1248 dso__load(kernel, machine__kernel_map(machine), NULL);
1247 NULL);
1248 }1249 }
1249 }1250 }
1250 return 0;1251 return 0;
@@ -1830,7 +1831,7 @@ static int thread__resolve_callchain_sample(struct thread *thread, · 579 unmodified lines
1830 }1831 }
1831 1832
1832check_calls:1833check_calls:
1833 if (chain->nr > PERF_MAX_STACK_DEPTH) {1834 if (chain->nr > PERF_MAX_STACK_DEPTH && (int)chain->nr > max_stack) {
1834 pr_warning("corrupted callchain. skipping...\n");1835 pr_warning("corrupted callchain. skipping...\n");
1835 return 0;1836 return 0;
1836 }1837 }
@@ -1996,7 +1997,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, · 159 unmodified lines
1996 1997
1997int machine__get_kernel_start(struct machine *machine)1998int machine__get_kernel_start(struct machine *machine)
1998{1999{
1999 struct map *map = machine__kernel_map(machine, MAP__FUNCTION);2000 struct map *map = machine__kernel_map(machine);
2000 int err = 0;2001 int err = 0;
2001 2002
2002 /*2003 /*
tools/perf/util/machine.h+8−1
@@ -34,6 +34,7 @@ struct machine { · 33 unmodified lines
34 struct list_head dead_threads;34 struct list_head dead_threads;
35 struct thread *last_match;35 struct thread *last_match;
36 struct vdso_info *vdso_info;36 struct vdso_info *vdso_info;
37 struct perf_env *env;
37 struct dsos dsos;38 struct dsos dsos;
38 struct map_groups kmaps;39 struct map_groups kmaps;
39 struct map *vmlinux_maps[MAP__NR_TYPES];40 struct map *vmlinux_maps[MAP__NR_TYPES];
@@ -47,11 +48,17 @@ struct machine { · 7 unmodified lines
47};48};
48 49
49static inline50static inline
50struct map *machine__kernel_map(struct machine *machine, enum map_type type)51struct map *__machine__kernel_map(struct machine *machine, enum map_type type)
51{52{
52 return machine->vmlinux_maps[type];53 return machine->vmlinux_maps[type];
53}54}
54 55
56static inline
57struct map *machine__kernel_map(struct machine *machine)
58{
59 return __machine__kernel_map(machine, MAP__FUNCTION);
60}
61
55int machine__get_kernel_start(struct machine *machine);62int machine__get_kernel_start(struct machine *machine);
56 63
57static inline u64 machine__kernel_start(struct machine *machine)64static inline u64 machine__kernel_start(struct machine *machine)
tools/perf/util/map.c+14−7
@@ -235,7 +235,7 @@ struct map *map__new2(u64 start, struct dso *dso, enum map_type type) · 234 unmodified lines
235 */235 */
236bool __map__is_kernel(const struct map *map)236bool __map__is_kernel(const struct map *map)
237{237{
238 return map->groups->machine->vmlinux_maps[map->type] == map;238 return __machine__kernel_map(map->groups->machine, map->type) == map;
239}239}
240 240
241static void map__exit(struct map *map)241static void map__exit(struct map *map)
@@ -553,13 +553,9 @@ struct symbol *map_groups__find_symbol(struct map_groups *mg, · 311 unmodified lines
553 return NULL;553 return NULL;
554}554}
555 555
556struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,556struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
557 enum map_type type,557 struct map **mapp, symbol_filter_t filter)
558 const char *name,
559 struct map **mapp,
560 symbol_filter_t filter)
561{558{
562 struct maps *maps = &mg->maps[type];
563 struct symbol *sym;559 struct symbol *sym;
564 struct rb_node *nd;560 struct rb_node *nd;
565 561
@@ -583,6 +579,17 @@ out: · 17 unmodified lines
583 return sym;579 return sym;
584}580}
585 581
582struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
583 enum map_type type,
584 const char *name,
585 struct map **mapp,
586 symbol_filter_t filter)
587{
588 struct symbol *sym = maps__find_symbol_by_name(&mg->maps[type], name, mapp, filter);
589
590 return sym;
591}
592
586int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter)593int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter)
587{594{
588 if (ams->addr < ams->map->start || ams->addr >= ams->map->end) {595 if (ams->addr < ams->map->start || ams->addr >= ams->map->end) {
tools/perf/util/map.h+2−0
@@ -190,6 +190,8 @@ void maps__remove(struct maps *maps, struct map *map); · 189 unmodified lines
190struct map *maps__find(struct maps *maps, u64 addr);190struct map *maps__find(struct maps *maps, u64 addr);
191struct map *maps__first(struct maps *maps);191struct map *maps__first(struct maps *maps);
192struct map *map__next(struct map *map);192struct map *map__next(struct map *map);
193struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name,
194 struct map **mapp, symbol_filter_t filter);
193void map_groups__init(struct map_groups *mg, struct machine *machine);195void map_groups__init(struct map_groups *mg, struct machine *machine);
194void map_groups__exit(struct map_groups *mg);196void map_groups__exit(struct map_groups *mg);
195int map_groups__clone(struct map_groups *mg,197int map_groups__clone(struct map_groups *mg,
tools/perf/util/parse-branch-options.c+1−0
@@ -27,6 +27,7 @@ static const struct branch_mode branch_modes[] = { · 26 unmodified lines
27 BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX),27 BRANCH_OPT("no_tx", PERF_SAMPLE_BRANCH_NO_TX),
28 BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND),28 BRANCH_OPT("cond", PERF_SAMPLE_BRANCH_COND),
29 BRANCH_OPT("ind_jmp", PERF_SAMPLE_BRANCH_IND_JUMP),29 BRANCH_OPT("ind_jmp", PERF_SAMPLE_BRANCH_IND_JUMP),
30 BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL),
30 BRANCH_END31 BRANCH_END
31};32};
32 33
tools/perf/util/parse-events.c+334−40
@@ -1,4 +1,5 @@
1#include <linux/hw_breakpoint.h>1#include <linux/hw_breakpoint.h>
2#include <linux/err.h>
2#include "util.h"3#include "util.h"
3#include "../perf.h"4#include "../perf.h"
4#include "evlist.h"5#include "evlist.h"
@@ -10,8 +11,9 @@ · 5 unmodified lines
10#include "symbol.h"11#include "symbol.h"
11#include "cache.h"12#include "cache.h"
12#include "header.h"13#include "header.h"
14#include "bpf-loader.h"
13#include "debug.h"15#include "debug.h"
14#include <api/fs/debugfs.h>16#include <api/fs/tracing_path.h>
15#include "parse-events-bison.h"17#include "parse-events-bison.h"
16#define YY_EXTRA_TYPE int18#define YY_EXTRA_TYPE int
17#include "parse-events-flex.h"19#include "parse-events-flex.h"
@@ -26,6 +28,8 @@ · 8 unmodified lines
26extern int parse_events_debug;28extern int parse_events_debug;
27#endif29#endif
28int parse_events_parse(void *data, void *scanner);30int parse_events_parse(void *data, void *scanner);
31static int get_config_terms(struct list_head *head_config,
32 struct list_head *head_terms __maybe_unused);
29 33
30static struct perf_pmu_event_symbol *perf_pmu_events_list;34static struct perf_pmu_event_symbol *perf_pmu_events_list;
31/*35/*
@@ -386,32 +390,72 @@ int parse_events_add_cache(struct list_head *list, int *idx, · 354 unmodified lines
386 return add_event(list, idx, &attr, name, NULL);390 return add_event(list, idx, &attr, name, NULL);
387}391}
388 392
393static void tracepoint_error(struct parse_events_error *e, int err,
394 char *sys, char *name)
395{
396 char help[BUFSIZ];
397
398 /*
399 * We get error directly from syscall errno ( > 0),
400 * or from encoded pointer's error ( < 0).
401 */
402 err = abs(err);
403
404 switch (err) {
405 case EACCES:
406 e->str = strdup("can't access trace events");
407 break;
408 case ENOENT:
409 e->str = strdup("unknown tracepoint");
410 break;
411 default:
412 e->str = strdup("failed to add tracepoint");
413 break;
414 }
415
416 tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
417 e->help = strdup(help);
418}
419
389static int add_tracepoint(struct list_head *list, int *idx,420static int add_tracepoint(struct list_head *list, int *idx,
390 char *sys_name, char *evt_name)421 char *sys_name, char *evt_name,
422 struct parse_events_error *err,
423 struct list_head *head_config)
391{424{
392 struct perf_evsel *evsel;425 struct perf_evsel *evsel;
393 426
394 evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);427 evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);
395 if (!evsel)428 if (IS_ERR(evsel)) {
396 return -ENOMEM;429 tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name);
430 return PTR_ERR(evsel);
431 }
397 432
398 list_add_tail(&evsel->node, list);433 if (head_config) {
434 LIST_HEAD(config_terms);
399 435
436 if (get_config_terms(head_config, &config_terms))
437 return -ENOMEM;
438 list_splice(&config_terms, &evsel->config_terms);
439 }
440
441 list_add_tail(&evsel->node, list);
400 return 0;442 return 0;
401}443}
402 444
403static int add_tracepoint_multi_event(struct list_head *list, int *idx,445static int add_tracepoint_multi_event(struct list_head *list, int *idx,
404 char *sys_name, char *evt_name)446 char *sys_name, char *evt_name,
447 struct parse_events_error *err,
448 struct list_head *head_config)
405{449{
406 char evt_path[MAXPATHLEN];450 char evt_path[MAXPATHLEN];
407 struct dirent *evt_ent;451 struct dirent *evt_ent;
408 DIR *evt_dir;452 DIR *evt_dir;
409 int ret = 0;453 int ret = 0, found = 0;
410 454
411 snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);455 snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
412 evt_dir = opendir(evt_path);456 evt_dir = opendir(evt_path);
413 if (!evt_dir) {457 if (!evt_dir) {
414 perror("Can't open event dir");458 tracepoint_error(err, errno, sys_name, evt_name);
415 return -1;459 return -1;
416 }460 }
417 461
@@ -425,7 +469,15 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx, · 7 unmodified lines
425 if (!strglobmatch(evt_ent->d_name, evt_name))469 if (!strglobmatch(evt_ent->d_name, evt_name))
426 continue;470 continue;
427 471
428 ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name);472 found++;
473
474 ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name,
475 err, head_config);
476 }
477
478 if (!found) {
479 tracepoint_error(err, ENOENT, sys_name, evt_name);
480 ret = -1;
429 }481 }
430 482
431 closedir(evt_dir);483 closedir(evt_dir);
@@ -433,15 +485,21 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx, · 1 unmodified line
433}485}
434 486
435static int add_tracepoint_event(struct list_head *list, int *idx,487static int add_tracepoint_event(struct list_head *list, int *idx,
436 char *sys_name, char *evt_name)488 char *sys_name, char *evt_name,
489 struct parse_events_error *err,
490 struct list_head *head_config)
437{491{
438 return strpbrk(evt_name, "*?") ?492 return strpbrk(evt_name, "*?") ?
439 add_tracepoint_multi_event(list, idx, sys_name, evt_name) :493 add_tracepoint_multi_event(list, idx, sys_name, evt_name,
440 add_tracepoint(list, idx, sys_name, evt_name);494 err, head_config) :
495 add_tracepoint(list, idx, sys_name, evt_name,
496 err, head_config);
441}497}
442 498
443static int add_tracepoint_multi_sys(struct list_head *list, int *idx,499static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
444 char *sys_name, char *evt_name)500 char *sys_name, char *evt_name,
501 struct parse_events_error *err,
502 struct list_head *head_config)
445{503{
446 struct dirent *events_ent;504 struct dirent *events_ent;
447 DIR *events_dir;505 DIR *events_dir;
@@ -449,7 +507,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx, · 1 unmodified line
449 507
450 events_dir = opendir(tracing_events_path);508 events_dir = opendir(tracing_events_path);
451 if (!events_dir) {509 if (!events_dir) {
452 perror("Can't open event dir");510 tracepoint_error(err, errno, sys_name, evt_name);
453 return -1;511 return -1;
454 }512 }
455 513
@@ -465,20 +523,135 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx, · 9 unmodified lines
465 continue;523 continue;
466 524
467 ret = add_tracepoint_event(list, idx, events_ent->d_name,525 ret = add_tracepoint_event(list, idx, events_ent->d_name,
468 evt_name);526 evt_name, err, head_config);
469 }527 }
470 528
471 closedir(events_dir);529 closedir(events_dir);
472 return ret;530 return ret;
473}531}
474 532
475int parse_events_add_tracepoint(struct list_head *list, int *idx,533struct __add_bpf_event_param {
476 char *sys, char *event)534 struct parse_events_evlist *data;
535 struct list_head *list;
536};
537
538static int add_bpf_event(struct probe_trace_event *tev, int fd,
539 void *_param)
477{540{
478 if (strpbrk(sys, "*?"))541 LIST_HEAD(new_evsels);
479 return add_tracepoint_multi_sys(list, idx, sys, event);542 struct __add_bpf_event_param *param = _param;
480 else543 struct parse_events_evlist *evlist = param->data;
481 return add_tracepoint_event(list, idx, sys, event);544 struct list_head *list = param->list;
545 struct perf_evsel *pos;
546 int err;
547
548 pr_debug("add bpf event %s:%s and attach bpf program %d\n",
549 tev->group, tev->event, fd);
550
551 err = parse_events_add_tracepoint(&new_evsels, &evlist->idx, tev->group,
552 tev->event, evlist->error, NULL);
553 if (err) {
554 struct perf_evsel *evsel, *tmp;
555
556 pr_debug("Failed to add BPF event %s:%s\n",
557 tev->group, tev->event);
558 list_for_each_entry_safe(evsel, tmp, &new_evsels, node) {
559 list_del(&evsel->node);
560 perf_evsel__delete(evsel);
561 }
562 return err;
563 }
564 pr_debug("adding %s:%s\n", tev->group, tev->event);
565
566 list_for_each_entry(pos, &new_evsels, node) {
567 pr_debug("adding %s:%s to %p\n",
568 tev->group, tev->event, pos);
569 pos->bpf_fd = fd;
570 }
571 list_splice(&new_evsels, list);
572 return 0;
573}
574
575int parse_events_load_bpf_obj(struct parse_events_evlist *data,
576 struct list_head *list,
577 struct bpf_object *obj)
578{
579 int err;
580 char errbuf[BUFSIZ];
581 struct __add_bpf_event_param param = {data, list};
582 static bool registered_unprobe_atexit = false;
583
584 if (IS_ERR(obj) || !obj) {
585 snprintf(errbuf, sizeof(errbuf),
586 "Internal error: load bpf obj with NULL");
587 err = -EINVAL;
588 goto errout;
589 }
590
591 /*
592 * Register atexit handler before calling bpf__probe() so
593 * bpf__probe() don't need to unprobe probe points its already
594 * created when failure.
595 */
596 if (!registered_unprobe_atexit) {
597 atexit(bpf__clear);
598 registered_unprobe_atexit = true;
599 }
600
601 err = bpf__probe(obj);
602 if (err) {
603 bpf__strerror_probe(obj, err, errbuf, sizeof(errbuf));
604 goto errout;
605 }
606
607 err = bpf__load(obj);
608 if (err) {
609 bpf__strerror_load(obj, err, errbuf, sizeof(errbuf));
610 goto errout;
611 }
612
613 err = bpf__foreach_tev(obj, add_bpf_event, &param);
614 if (err) {
615 snprintf(errbuf, sizeof(errbuf),
616 "Attach events in BPF object failed");
617 goto errout;
618 }
619
620 return 0;
621errout:
622 data->error->help = strdup("(add -v to see detail)");
623 data->error->str = strdup(errbuf);
624 return err;
625}
626
627int parse_events_load_bpf(struct parse_events_evlist *data,
628 struct list_head *list,
629 char *bpf_file_name,
630 bool source)
631{
632 struct bpf_object *obj;
633
634 obj = bpf__prepare_load(bpf_file_name, source);
635 if (IS_ERR(obj) || !obj) {
636 char errbuf[BUFSIZ];
637 int err;
638
639 err = obj ? PTR_ERR(obj) : -EINVAL;
640
641 if (err == -ENOTSUP)
642 snprintf(errbuf, sizeof(errbuf),
643 "BPF support is not compiled");
644 else
645 snprintf(errbuf, sizeof(errbuf),
646 "BPF object file '%s' is invalid",
647 bpf_file_name);
648
649 data->error->help = strdup("(add -v to see detail)");
650 data->error->str = strdup(errbuf);
651 return err;
652 }
653
654 return parse_events_load_bpf_obj(data, list, obj);
482}655}
483 656
484static int657static int
@@ -565,9 +738,13 @@ static int check_type_val(struct parse_events_term *term, · 80 unmodified lines
565 return -EINVAL;738 return -EINVAL;
566}739}
567 740
568static int config_term(struct perf_event_attr *attr,741typedef int config_term_func_t(struct perf_event_attr *attr,
569 struct parse_events_term *term,742 struct parse_events_term *term,
570 struct parse_events_error *err)743 struct parse_events_error *err);
744
745static int config_term_common(struct perf_event_attr *attr,
746 struct parse_events_term *term,
747 struct parse_events_error *err)
571{748{
572#define CHECK_TYPE_VAL(type) \749#define CHECK_TYPE_VAL(type) \
573do { \750do { \
@@ -576,12 +753,6 @@ do { \ · 2 unmodified lines
576} while (0)753} while (0)
577 754
578 switch (term->type_term) {755 switch (term->type_term) {
579 case PARSE_EVENTS__TERM_TYPE_USER:
580 /*
581 * Always succeed for sysfs terms, as we dont know
582 * at this point what type they need to have.
583 */
584 return 0;
585 case PARSE_EVENTS__TERM_TYPE_CONFIG:756 case PARSE_EVENTS__TERM_TYPE_CONFIG:
586 CHECK_TYPE_VAL(NUM);757 CHECK_TYPE_VAL(NUM);
587 attr->config = term->val.num;758 attr->config = term->val.num;
@@ -620,10 +791,19 @@ do { \ · 32 unmodified lines
620 case PARSE_EVENTS__TERM_TYPE_STACKSIZE:791 case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
621 CHECK_TYPE_VAL(NUM);792 CHECK_TYPE_VAL(NUM);
622 break;793 break;
794 case PARSE_EVENTS__TERM_TYPE_INHERIT:
795 CHECK_TYPE_VAL(NUM);
796 break;
797 case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
798 CHECK_TYPE_VAL(NUM);
799 break;
623 case PARSE_EVENTS__TERM_TYPE_NAME:800 case PARSE_EVENTS__TERM_TYPE_NAME:
624 CHECK_TYPE_VAL(STR);801 CHECK_TYPE_VAL(STR);
625 break;802 break;
626 default:803 default:
804 err->str = strdup("unknown term");
805 err->idx = term->err_term;
806 err->help = parse_events_formats_error_string(NULL);
627 return -EINVAL;807 return -EINVAL;
628 }808 }
629 809
@@ -631,9 +811,46 @@ do { \ · 1 unmodified line
631#undef CHECK_TYPE_VAL811#undef CHECK_TYPE_VAL
632}812}
633 813
814static int config_term_pmu(struct perf_event_attr *attr,
815 struct parse_events_term *term,
816 struct parse_events_error *err)
817{
818 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER)
819 /*
820 * Always succeed for sysfs terms, as we dont know
821 * at this point what type they need to have.
822 */
823 return 0;
824 else
825 return config_term_common(attr, term, err);
826}
827
828static int config_term_tracepoint(struct perf_event_attr *attr,
829 struct parse_events_term *term,
830 struct parse_events_error *err)
831{
832 switch (term->type_term) {
833 case PARSE_EVENTS__TERM_TYPE_CALLGRAPH:
834 case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
835 case PARSE_EVENTS__TERM_TYPE_INHERIT:
836 case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
837 return config_term_common(attr, term, err);
838 default:
839 if (err) {
840 err->idx = term->err_term;
841 err->str = strdup("unknown term");
842 err->help = strdup("valid terms: call-graph,stack-size\n");
843 }
844 return -EINVAL;
845 }
846
847 return 0;
848}
849
634static int config_attr(struct perf_event_attr *attr,850static int config_attr(struct perf_event_attr *attr,
635 struct list_head *head,851 struct list_head *head,
636 struct parse_events_error *err)852 struct parse_events_error *err,
853 config_term_func_t config_term)
637{854{
638 struct parse_events_term *term;855 struct parse_events_term *term;
639 856
@@ -680,6 +897,12 @@ do { \ · 40 unmodified lines
680 case PARSE_EVENTS__TERM_TYPE_STACKSIZE:897 case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
681 ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num);898 ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num);
682 break;899 break;
900 case PARSE_EVENTS__TERM_TYPE_INHERIT:
901 ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 1 : 0);
902 break;
903 case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
904 ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 0 : 1);
905 break;
683 default:906 default:
684 break;907 break;
685 }908 }
@@ -688,6 +911,27 @@ do { \ · 2 unmodified lines
688 return 0;911 return 0;
689}912}
690 913
914int parse_events_add_tracepoint(struct list_head *list, int *idx,
915 char *sys, char *event,
916 struct parse_events_error *err,
917 struct list_head *head_config)
918{
919 if (head_config) {
920 struct perf_event_attr attr;
921
922 if (config_attr(&attr, head_config, err,
923 config_term_tracepoint))
924 return -EINVAL;
925 }
926
927 if (strpbrk(sys, "*?"))
928 return add_tracepoint_multi_sys(list, idx, sys, event,
929 err, head_config);
930 else
931 return add_tracepoint_event(list, idx, sys, event,
932 err, head_config);
933}
934
691int parse_events_add_numeric(struct parse_events_evlist *data,935int parse_events_add_numeric(struct parse_events_evlist *data,
692 struct list_head *list,936 struct list_head *list,
693 u32 type, u64 config,937 u32 type, u64 config,
@@ -701,7 +945,8 @@ int parse_events_add_numeric(struct parse_events_evlist *data, · 7 unmodified lines
701 attr.config = config;945 attr.config = config;
702 946
703 if (head_config) {947 if (head_config) {
704 if (config_attr(&attr, head_config, data->error))948 if (config_attr(&attr, head_config, data->error,
949 config_term_common))
705 return -EINVAL;950 return -EINVAL;
706 951
707 if (get_config_terms(head_config, &config_terms))952 if (get_config_terms(head_config, &config_terms))
@@ -761,7 +1006,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data, · 53 unmodified lines
761 * Configure hardcoded terms first, no need to check1006 * Configure hardcoded terms first, no need to check
762 * return value when called with fail == 0 ;)1007 * return value when called with fail == 0 ;)
763 */1008 */
764 if (config_attr(&attr, head_config, data->error))1009 if (config_attr(&attr, head_config, data->error, config_term_pmu))
765 return -EINVAL;1010 return -EINVAL;
766 1011
767 if (get_config_terms(head_config, &config_terms))1012 if (get_config_terms(head_config, &config_terms))
@@ -793,6 +1038,11 @@ void parse_events__set_leader(char *name, struct list_head *list) · 25 unmodified lines
793{1038{
794 struct perf_evsel *leader;1039 struct perf_evsel *leader;
795 1040
1041 if (list_empty(list)) {
1042 WARN_ONCE(true, "WARNING: failed to set leader: empty list");
1043 return;
1044 }
1045
796 __perf_evlist__set_leader(list);1046 __perf_evlist__set_leader(list);
797 leader = list_entry(list->next, struct perf_evsel, node);1047 leader = list_entry(list->next, struct perf_evsel, node);
798 leader->group_name = name ? strdup(name) : NULL;1048 leader->group_name = name ? strdup(name) : NULL;
@@ -819,6 +1069,7 @@ struct event_modifier { · 20 unmodified lines
819 int eG;1069 int eG;
820 int eI;1070 int eI;
821 int precise;1071 int precise;
1072 int precise_max;
822 int exclude_GH;1073 int exclude_GH;
823 int sample_read;1074 int sample_read;
824 int pinned;1075 int pinned;
@@ -834,6 +1085,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str, · 9 unmodified lines
834 int eG = evsel ? evsel->attr.exclude_guest : 0;1085 int eG = evsel ? evsel->attr.exclude_guest : 0;
835 int eI = evsel ? evsel->attr.exclude_idle : 0;1086 int eI = evsel ? evsel->attr.exclude_idle : 0;
836 int precise = evsel ? evsel->attr.precise_ip : 0;1087 int precise = evsel ? evsel->attr.precise_ip : 0;
1088 int precise_max = 0;
837 int sample_read = 0;1089 int sample_read = 0;
838 int pinned = evsel ? evsel->attr.pinned : 0;1090 int pinned = evsel ? evsel->attr.pinned : 0;
839 1091
@@ -870,6 +1122,8 @@ static int get_event_modifier(struct event_modifier *mod, char *str, · 30 unmodified lines
870 /* use of precise requires exclude_guest */1122 /* use of precise requires exclude_guest */
871 if (!exclude_GH)1123 if (!exclude_GH)
872 eG = 1;1124 eG = 1;
1125 } else if (*str == 'P') {
1126 precise_max = 1;
873 } else if (*str == 'S') {1127 } else if (*str == 'S') {
874 sample_read = 1;1128 sample_read = 1;
875 } else if (*str == 'D') {1129 } else if (*str == 'D') {
@@ -900,6 +1154,7 @@ static int get_event_modifier(struct event_modifier *mod, char *str, · 24 unmodified lines
900 mod->eG = eG;1154 mod->eG = eG;
901 mod->eI = eI;1155 mod->eI = eI;
902 mod->precise = precise;1156 mod->precise = precise;
1157 mod->precise_max = precise_max;
903 mod->exclude_GH = exclude_GH;1158 mod->exclude_GH = exclude_GH;
904 mod->sample_read = sample_read;1159 mod->sample_read = sample_read;
905 mod->pinned = pinned;1160 mod->pinned = pinned;
@@ -916,7 +1171,7 @@ static int check_modifier(char *str) · 10 unmodified lines
916 char *p = str;1171 char *p = str;
917 1172
918 /* The sizeof includes 0 byte as well. */1173 /* The sizeof includes 0 byte as well. */
919 if (strlen(str) > (sizeof("ukhGHpppSDI") - 1))1174 if (strlen(str) > (sizeof("ukhGHpppPSDI") - 1))
920 return -1;1175 return -1;
921 1176
922 while (*p) {1177 while (*p) {
@@ -955,6 +1210,7 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add) · 32 unmodified lines
955 evsel->attr.exclude_idle = mod.eI;1210 evsel->attr.exclude_idle = mod.eI;
956 evsel->exclude_GH = mod.exclude_GH;1211 evsel->exclude_GH = mod.exclude_GH;
957 evsel->sample_read = mod.sample_read;1212 evsel->sample_read = mod.sample_read;
1213 evsel->precise_max = mod.precise_max;
958 1214
959 if (perf_evsel__is_group_leader(evsel))1215 if (perf_evsel__is_group_leader(evsel))
960 evsel->attr.pinned = mod.pinned;1216 evsel->attr.pinned = mod.pinned;
@@ -1142,6 +1398,11 @@ int parse_events(struct perf_evlist *evlist, const char *str, · 181 unmodified lines
1142 if (!ret) {1398 if (!ret) {
1143 struct perf_evsel *last;1399 struct perf_evsel *last;
1144 1400
1401 if (list_empty(&data.list)) {
1402 WARN_ONCE(true, "WARNING: event parser found nothing");
1403 return -1;
1404 }
1405
1145 perf_evlist__splice_list_tail(evlist, &data.list);1406 perf_evlist__splice_list_tail(evlist, &data.list);
1146 evlist->nr_groups += data.nr_groups;1407 evlist->nr_groups += data.nr_groups;
1147 last = perf_evlist__last(evlist);1408 last = perf_evlist__last(evlist);
@@ -1251,6 +1512,12 @@ foreach_evsel_in_last_glob(struct perf_evlist *evlist, · 103 unmodified lines
1251 struct perf_evsel *last = NULL;1512 struct perf_evsel *last = NULL;
1252 int err;1513 int err;
1253 1514
1515 /*
1516 * Don't return when list_empty, give func a chance to report
1517 * error when it found last == NULL.
1518 *
1519 * So no need to WARN here, let *func do this.
1520 */
1254 if (evlist->nr_entries > 0)1521 if (evlist->nr_entries > 0)
1255 last = perf_evlist__last(evlist);1522 last = perf_evlist__last(evlist);
1256 1523
@@ -1419,7 +1686,7 @@ restart: · 162 unmodified lines
1419 printf(" %-50s [%s]\n", evt_list[evt_i++],1686 printf(" %-50s [%s]\n", evt_list[evt_i++],
1420 event_type_descriptors[PERF_TYPE_TRACEPOINT]);1687 event_type_descriptors[PERF_TYPE_TRACEPOINT]);
1421 }1688 }
1422 if (evt_num)1689 if (evt_num && pager_in_use())
1423 printf("\n");1690 printf("\n");
1424 1691
1425out_free:1692out_free:
@@ -1575,7 +1842,7 @@ restart: · 149 unmodified lines
1575 printf(" %-50s [%s]\n", evt_list[evt_i++],1842 printf(" %-50s [%s]\n", evt_list[evt_i++],
1576 event_type_descriptors[PERF_TYPE_HW_CACHE]);1843 event_type_descriptors[PERF_TYPE_HW_CACHE]);
1577 }1844 }
1578 if (evt_num)1845 if (evt_num && pager_in_use())
1579 printf("\n");1846 printf("\n");
1580 1847
1581out_free:1848out_free:
@@ -1648,7 +1915,7 @@ restart: · 66 unmodified lines
1648 }1915 }
1649 printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[type]);1916 printf(" %-50s [%s]\n", evt_list[evt_i++], event_type_descriptors[type]);
1650 }1917 }
1651 if (evt_num)1918 if (evt_num && pager_in_use())
1652 printf("\n");1919 printf("\n");
1653 1920
1654out_free:1921out_free:
@@ -1689,13 +1956,14 @@ void print_events(const char *event_glob, bool name_only) · 34 unmodified lines
1689 printf(" %-50s [%s]\n",1956 printf(" %-50s [%s]\n",
1690 "cpu/t1=v1[,t2=v2,t3 ...]/modifier",1957 "cpu/t1=v1[,t2=v2,t3 ...]/modifier",
1691 event_type_descriptors[PERF_TYPE_RAW]);1958 event_type_descriptors[PERF_TYPE_RAW]);
1692 printf(" (see 'man perf-list' on how to encode it)\n");1959 if (pager_in_use())
1693 printf("\n");1960 printf(" (see 'man perf-list' on how to encode it)\n\n");
1694 1961
1695 printf(" %-50s [%s]\n",1962 printf(" %-50s [%s]\n",
1696 "mem:<addr>[/len][:access]",1963 "mem:<addr>[/len][:access]",
1697 event_type_descriptors[PERF_TYPE_BREAKPOINT]);1964 event_type_descriptors[PERF_TYPE_BREAKPOINT]);
1698 printf("\n");1965 if (pager_in_use())
1966 printf("\n");
1699 }1967 }
1700 1968
1701 print_tracepoint_events(NULL, NULL, name_only);1969 print_tracepoint_events(NULL, NULL, name_only);
@@ -1811,3 +2079,29 @@ void parse_events_evlist_error(struct parse_events_evlist *data, · 109 unmodified lines
1811 err->str = strdup(str);2079 err->str = strdup(str);
1812 WARN_ONCE(!err->str, "WARNING: failed to allocate error string");2080 WARN_ONCE(!err->str, "WARNING: failed to allocate error string");
1813}2081}
2082
2083/*
2084 * Return string contains valid config terms of an event.
2085 * @additional_terms: For terms such as PMU sysfs terms.
2086 */
2087char *parse_events_formats_error_string(char *additional_terms)
2088{
2089 char *str;
2090 static const char *static_terms = "config,config1,config2,name,"
2091 "period,freq,branch_type,time,"
2092 "call-graph,stack-size\n";
2093
2094 /* valid terms */
2095 if (additional_terms) {
2096 if (!asprintf(&str, "valid terms: %s,%s",
2097 additional_terms, static_terms))
2098 goto fail;
2099 } else {
2100 if (!asprintf(&str, "valid terms: %s", static_terms))
2101 goto fail;
2102 }
2103 return str;
2104
2105fail:
2106 return NULL;
2107}
tools/perf/util/parse-events.h+15−1
@@ -67,6 +67,8 @@ enum { · 66 unmodified lines
67 PARSE_EVENTS__TERM_TYPE_TIME,67 PARSE_EVENTS__TERM_TYPE_TIME,
68 PARSE_EVENTS__TERM_TYPE_CALLGRAPH,68 PARSE_EVENTS__TERM_TYPE_CALLGRAPH,
69 PARSE_EVENTS__TERM_TYPE_STACKSIZE,69 PARSE_EVENTS__TERM_TYPE_STACKSIZE,
70 PARSE_EVENTS__TERM_TYPE_NOINHERIT,
71 PARSE_EVENTS__TERM_TYPE_INHERIT
70};72};
71 73
72struct parse_events_term {74struct parse_events_term {
@@ -118,7 +120,18 @@ int parse_events__modifier_event(struct list_head *list, char *str, bool add); · 45 unmodified lines
118int parse_events__modifier_group(struct list_head *list, char *event_mod);120int parse_events__modifier_group(struct list_head *list, char *event_mod);
119int parse_events_name(struct list_head *list, char *name);121int parse_events_name(struct list_head *list, char *name);
120int parse_events_add_tracepoint(struct list_head *list, int *idx,122int parse_events_add_tracepoint(struct list_head *list, int *idx,
121 char *sys, char *event);123 char *sys, char *event,
124 struct parse_events_error *error,
125 struct list_head *head_config);
126int parse_events_load_bpf(struct parse_events_evlist *data,
127 struct list_head *list,
128 char *bpf_file_name,
129 bool source);
130/* Provide this function for perf test */
131struct bpf_object;
132int parse_events_load_bpf_obj(struct parse_events_evlist *data,
133 struct list_head *list,
134 struct bpf_object *obj);
122int parse_events_add_numeric(struct parse_events_evlist *data,135int parse_events_add_numeric(struct parse_events_evlist *data,
123 struct list_head *list,136 struct list_head *list,
124 u32 type, u64 config,137 u32 type, u64 config,
@@ -155,5 +168,6 @@ int print_hwcache_events(const char *event_glob, bool name_only); · 30 unmodified lines
155extern int is_valid_tracepoint(const char *event_string);168extern int is_valid_tracepoint(const char *event_string);
156 169
157int valid_event_mount(const char *eventfs);170int valid_event_mount(const char *eventfs);
171char *parse_events_formats_error_string(char *additional_terms);
158 172
159#endif /* __PERF_PARSE_EVENTS_H */173#endif /* __PERF_PARSE_EVENTS_H */
tools/perf/util/parse-events.l+10−2
@@ -115,6 +115,8 @@ do { \ · 114 unmodified lines
115group [^,{}/]*[{][^}]*[}][^,{}/]*115group [^,{}/]*[{][^}]*[}][^,{}/]*
116event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*116event_pmu [^,{}/]+[/][^/]*[/][^,{}/]*
117event [^,{}/]+117event [^,{}/]+
118bpf_object .*\.(o|bpf)
119bpf_source .*\.c
118 120
119num_dec [0-9]+121num_dec [0-9]+
120num_hex 0x[a-fA-F0-9]+122num_hex 0x[a-fA-F0-9]+
@@ -122,7 +124,7 @@ num_raw_hex [a-fA-F0-9]+ · 1 unmodified line
122name [a-zA-Z_*?][a-zA-Z0-9_*?.]*124name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
123name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.]*125name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.]*
124/* If you add a modifier you need to update check_modifier() */126/* If you add a modifier you need to update check_modifier() */
125modifier_event [ukhpGHSDI]+127modifier_event [ukhpPGHSDI]+
126modifier_bp [rwx]{1,3}128modifier_bp [rwx]{1,3}
127 129
128%%130%%
@@ -159,6 +161,8 @@ modifier_bp [rwx]{1,3} · 30 unmodified lines
159 }161 }
160 162
161{event_pmu} |163{event_pmu} |
164{bpf_object} |
165{bpf_source} |
162{event} {166{event} {
163 BEGIN(INITIAL);167 BEGIN(INITIAL);
164 REWIND(1);168 REWIND(1);
@@ -174,7 +178,7 @@ modifier_bp [rwx]{1,3} · 9 unmodified lines
174 178
175<config>{179<config>{
176 /*180 /*
177 * Please update formats_error_string any time181 * Please update parse_events_formats_error_string any time
178 * new static term is added.182 * new static term is added.
179 */183 */
180config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }184config { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG); }
@@ -187,6 +191,8 @@ branch_type { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE · 6 unmodified lines
187time { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); }191time { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); }
188call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }192call-graph { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CALLGRAPH); }
189stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }193stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
194inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
195no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
190, { return ','; }196, { return ','; }
191"/" { BEGIN(INITIAL); return '/'; }197"/" { BEGIN(INITIAL); return '/'; }
192{name_minus} { return str(yyscanner, PE_NAME); }198{name_minus} { return str(yyscanner, PE_NAME); }
@@ -264,6 +270,8 @@ r{num_raw_hex} { return raw(yyscanner); } · 71 unmodified lines
264{num_hex} { return value(yyscanner, 16); }270{num_hex} { return value(yyscanner, 16); }
265 271
266{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }272{modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); }
273{bpf_object} { return str(yyscanner, PE_BPF_OBJECT); }
274{bpf_source} { return str(yyscanner, PE_BPF_SOURCE); }
267{name} { return pmu_str_check(yyscanner); }275{name} { return pmu_str_check(yyscanner); }
268"/" { BEGIN(config); return '/'; }276"/" { BEGIN(config); return '/'; }
269- { return '-'; }277- { return '-'; }
tools/perf/util/parse-events.y+69−13
@@ -42,6 +42,7 @@ static inc_group_count(struct list_head *list, · 41 unmodified lines
42%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM42%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
43%token PE_EVENT_NAME43%token PE_EVENT_NAME
44%token PE_NAME44%token PE_NAME
45%token PE_BPF_OBJECT PE_BPF_SOURCE
45%token PE_MODIFIER_EVENT PE_MODIFIER_BP46%token PE_MODIFIER_EVENT PE_MODIFIER_BP
46%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT47%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
47%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP48%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
@@ -53,6 +54,8 @@ static inc_group_count(struct list_head *list, · 5 unmodified lines
53%type <num> PE_RAW54%type <num> PE_RAW
54%type <num> PE_TERM55%type <num> PE_TERM
55%type <str> PE_NAME56%type <str> PE_NAME
57%type <str> PE_BPF_OBJECT
58%type <str> PE_BPF_SOURCE
56%type <str> PE_NAME_CACHE_TYPE59%type <str> PE_NAME_CACHE_TYPE
57%type <str> PE_NAME_CACHE_OP_RESULT60%type <str> PE_NAME_CACHE_OP_RESULT
58%type <str> PE_MODIFIER_EVENT61%type <str> PE_MODIFIER_EVENT
@@ -67,8 +70,10 @@ static inc_group_count(struct list_head *list, · 8 unmodified lines
67%type <head> event_legacy_cache70%type <head> event_legacy_cache
68%type <head> event_legacy_mem71%type <head> event_legacy_mem
69%type <head> event_legacy_tracepoint72%type <head> event_legacy_tracepoint
73%type <tracepoint_name> tracepoint_name
70%type <head> event_legacy_numeric74%type <head> event_legacy_numeric
71%type <head> event_legacy_raw75%type <head> event_legacy_raw
76%type <head> event_bpf_file
72%type <head> event_def77%type <head> event_def
73%type <head> event_mod78%type <head> event_mod
74%type <head> event_name79%type <head> event_name
@@ -84,6 +89,10 @@ static inc_group_count(struct list_head *list, · 9 unmodified lines
84 u64 num;89 u64 num;
85 struct list_head *head;90 struct list_head *head;
86 struct parse_events_term *term;91 struct parse_events_term *term;
92 struct tracepoint_name {
93 char *sys;
94 char *event;
95 } tracepoint_name;
87}96}
88%%97%%
89 98
@@ -198,7 +207,8 @@ event_def: event_pmu | · 108 unmodified lines
198 event_legacy_mem |207 event_legacy_mem |
199 event_legacy_tracepoint sep_dc |208 event_legacy_tracepoint sep_dc |
200 event_legacy_numeric sep_dc |209 event_legacy_numeric sep_dc |
201 event_legacy_raw sep_dc210 event_legacy_raw sep_dc |
211 event_bpf_file
202 212
203event_pmu:213event_pmu:
204PE_NAME '/' event_config '/'214PE_NAME '/' event_config '/'
@@ -368,36 +378,60 @@ PE_PREFIX_MEM PE_VALUE sep_dc · 163 unmodified lines
368}378}
369 379
370event_legacy_tracepoint:380event_legacy_tracepoint:
371PE_NAME '-' PE_NAME ':' PE_NAME381tracepoint_name
372{382{
373 struct parse_events_evlist *data = _data;383 struct parse_events_evlist *data = _data;
384 struct parse_events_error *error = data->error;
374 struct list_head *list;385 struct list_head *list;
375 char sys_name[128];
376 snprintf(&sys_name, 128, "%s-%s", $1, $3);
377 386
378 ALLOC_LIST(list);387 ALLOC_LIST(list);
379 ABORT_ON(parse_events_add_tracepoint(list, &data->idx, &sys_name, $5));388 if (error)
389 error->idx = @1.first_column;
390
391 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
392 error, NULL))
393 return -1;
394
380 $$ = list;395 $$ = list;
381}396}
382|397|
383PE_NAME ':' PE_NAME398tracepoint_name '/' event_config '/'
384{399{
385 struct parse_events_evlist *data = _data;400 struct parse_events_evlist *data = _data;
401 struct parse_events_error *error = data->error;
386 struct list_head *list;402 struct list_head *list;
387 403
388 ALLOC_LIST(list);404 ALLOC_LIST(list);
389 if (parse_events_add_tracepoint(list, &data->idx, $1, $3)) {405 if (error)
390 struct parse_events_error *error = data->error;406 error->idx = @1.first_column;
391 407
392 if (error) {408 if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
393 error->idx = @1.first_column;409 error, $3))
394 error->str = strdup("unknown tracepoint");
395 }
396 return -1;410 return -1;
397 }411
398 $$ = list;412 $$ = list;
399}413}
400 414
415tracepoint_name:
416PE_NAME '-' PE_NAME ':' PE_NAME
417{
418 char sys_name[128];
419 struct tracepoint_name tracepoint;
420
421 snprintf(&sys_name, 128, "%s-%s", $1, $3);
422 tracepoint.sys = &sys_name;
423 tracepoint.event = $5;
424
425 $$ = tracepoint;
426}
427|
428PE_NAME ':' PE_NAME
429{
430 struct tracepoint_name tracepoint = {$1, $3};
431
432 $$ = tracepoint;
433}
434
401event_legacy_numeric:435event_legacy_numeric:
402PE_VALUE ':' PE_VALUE436PE_VALUE ':' PE_VALUE
403{437{
@@ -420,6 +454,28 @@ PE_RAW · 16 unmodified lines
420 $$ = list;454 $$ = list;
421}455}
422 456
457event_bpf_file:
458PE_BPF_OBJECT
459{
460 struct parse_events_evlist *data = _data;
461 struct parse_events_error *error = data->error;
462 struct list_head *list;
463
464 ALLOC_LIST(list);
465 ABORT_ON(parse_events_load_bpf(data, list, $1, false));
466 $$ = list;
467}
468|
469PE_BPF_SOURCE
470{
471 struct parse_events_evlist *data = _data;
472 struct list_head *list;
473
474 ALLOC_LIST(list);
475 ABORT_ON(parse_events_load_bpf(data, list, $1, true));
476 $$ = list;
477}
478
423start_terms: event_config479start_terms: event_config
424{480{
425 struct parse_events_terms *data = _data;481 struct parse_events_terms *data = _data;
tools/perf/util/parse-options.c+133−23
@@ -2,10 +2,13 @@ · 1 unmodified line
2#include "parse-options.h"2#include "parse-options.h"
3#include "cache.h"3#include "cache.h"
4#include "header.h"4#include "header.h"
5#include <linux/string.h>
5 6
6#define OPT_SHORT 17#define OPT_SHORT 1
7#define OPT_UNSET 28#define OPT_UNSET 2
8 9
10static struct strbuf error_buf = STRBUF_INIT;
11
9static int opterror(const struct option *opt, const char *reason, int flags)12static int opterror(const struct option *opt, const char *reason, int flags)
10{13{
11 if (flags & OPT_SHORT)14 if (flags & OPT_SHORT)
@@ -372,7 +375,8 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, · 360 unmodified lines
372}375}
373 376
374static int usage_with_options_internal(const char * const *,377static int usage_with_options_internal(const char * const *,
375 const struct option *, int);378 const struct option *, int,
379 struct parse_opt_ctx_t *);
376 380
377int parse_options_step(struct parse_opt_ctx_t *ctx,381int parse_options_step(struct parse_opt_ctx_t *ctx,
378 const struct option *options,382 const struct option *options,
@@ -396,8 +400,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, · 17 unmodified lines
396 400
397 if (arg[1] != '-') {401 if (arg[1] != '-') {
398 ctx->opt = ++arg;402 ctx->opt = ++arg;
399 if (internal_help && *ctx->opt == 'h')403 if (internal_help && *ctx->opt == 'h') {
400 return usage_with_options_internal(usagestr, options, 0);404 return usage_with_options_internal(usagestr, options, 0, ctx);
405 }
401 switch (parse_short_opt(ctx, options)) {406 switch (parse_short_opt(ctx, options)) {
402 case -1:407 case -1:
403 return parse_options_usage(usagestr, options, arg, 1);408 return parse_options_usage(usagestr, options, arg, 1);
@@ -412,7 +417,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, · 8 unmodified lines
412 check_typos(arg, options);417 check_typos(arg, options);
413 while (ctx->opt) {418 while (ctx->opt) {
414 if (internal_help && *ctx->opt == 'h')419 if (internal_help && *ctx->opt == 'h')
415 return usage_with_options_internal(usagestr, options, 0);420 return usage_with_options_internal(usagestr, options, 0, ctx);
416 arg = ctx->opt;421 arg = ctx->opt;
417 switch (parse_short_opt(ctx, options)) {422 switch (parse_short_opt(ctx, options)) {
418 case -1:423 case -1:
@@ -445,9 +450,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, · 26 unmodified lines
445 450
446 arg += 2;451 arg += 2;
447 if (internal_help && !strcmp(arg, "help-all"))452 if (internal_help && !strcmp(arg, "help-all"))
448 return usage_with_options_internal(usagestr, options, 1);453 return usage_with_options_internal(usagestr, options, 1, ctx);
449 if (internal_help && !strcmp(arg, "help"))454 if (internal_help && !strcmp(arg, "help"))
450 return usage_with_options_internal(usagestr, options, 0);455 return usage_with_options_internal(usagestr, options, 0, ctx);
451 if (!strcmp(arg, "list-opts"))456 if (!strcmp(arg, "list-opts"))
452 return PARSE_OPT_LIST_OPTS;457 return PARSE_OPT_LIST_OPTS;
453 if (!strcmp(arg, "list-cmds"))458 if (!strcmp(arg, "list-cmds"))
@@ -496,7 +501,7 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o · 42 unmodified lines
496{501{
497 struct parse_opt_ctx_t ctx;502 struct parse_opt_ctx_t ctx;
498 503
499 perf_header__set_cmdline(argc, argv);504 perf_env__set_cmdline(&perf_env, argc, argv);
500 505
501 /* build usage string if it's not provided */506 /* build usage string if it's not provided */
502 if (subcommands && !usagestr[0]) {507 if (subcommands && !usagestr[0]) {
@@ -537,9 +542,11 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o · 34 unmodified lines
537 exit(130);542 exit(130);
538 default: /* PARSE_OPT_UNKNOWN */543 default: /* PARSE_OPT_UNKNOWN */
539 if (ctx.argv[0][1] == '-') {544 if (ctx.argv[0][1] == '-') {
540 error("unknown option `%s'", ctx.argv[0] + 2);545 strbuf_addf(&error_buf, "unknown option `%s'",
546 ctx.argv[0] + 2);
541 } else {547 } else {
542 error("unknown switch `%c'", *ctx.opt);548 strbuf_addf(&error_buf, "unknown switch `%c'",
549 *ctx.opt);
543 }550 }
544 usage_with_options(usagestr, options);551 usage_with_options(usagestr, options);
545 }552 }
@@ -642,13 +649,93 @@ static void print_option_help(const struct option *opts, int full) · 96 unmodified lines
642 fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help);649 fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
643}650}
644 651
652static int option__cmp(const void *va, const void *vb)
653{
654 const struct option *a = va, *b = vb;
655 int sa = tolower(a->short_name), sb = tolower(b->short_name), ret;
656
657 if (sa == 0)
658 sa = 'z' + 1;
659 if (sb == 0)
660 sb = 'z' + 1;
661
662 ret = sa - sb;
663
664 if (ret == 0) {
665 const char *la = a->long_name ?: "",
666 *lb = b->long_name ?: "";
667 ret = strcmp(la, lb);
668 }
669
670 return ret;
671}
672
673static struct option *options__order(const struct option *opts)
674{
675 int nr_opts = 0;
676 const struct option *o = opts;
677 struct option *ordered;
678
679 for (o = opts; o->type != OPTION_END; o++)
680 ++nr_opts;
681
682 ordered = memdup(opts, sizeof(*o) * (nr_opts + 1));
683 if (ordered == NULL)
684 goto out;
685
686 qsort(ordered, nr_opts, sizeof(*o), option__cmp);
687out:
688 return ordered;
689}
690
691static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx)
692{
693 int i;
694
695 for (i = 1; i < ctx->argc; ++i) {
696 const char *arg = ctx->argv[i];
697
698 if (arg[0] != '-') {
699 if (arg[1] == '\0') {
700 if (arg[0] == opt->short_name)
701 return true;
702 continue;
703 }
704
705 if (opt->long_name && strcmp(opt->long_name, arg) == 0)
706 return true;
707
708 if (opt->help && strcasestr(opt->help, arg) != NULL)
709 return true;
710
711 continue;
712 }
713
714 if (arg[1] == opt->short_name ||
715 (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0))
716 return true;
717 }
718
719 return false;
720}
721
645int usage_with_options_internal(const char * const *usagestr,722int usage_with_options_internal(const char * const *usagestr,
646 const struct option *opts, int full)723 const struct option *opts, int full,
724 struct parse_opt_ctx_t *ctx)
647{725{
726 struct option *ordered;
727
648 if (!usagestr)728 if (!usagestr)
649 return PARSE_OPT_HELP;729 return PARSE_OPT_HELP;
650 730
651 fprintf(stderr, "\n usage: %s\n", *usagestr++);731 setup_pager();
732
733 if (strbuf_avail(&error_buf)) {
734 fprintf(stderr, " Error: %s\n", error_buf.buf);
735 strbuf_release(&error_buf);
736 }
737
738 fprintf(stderr, "\n Usage: %s\n", *usagestr++);
652 while (*usagestr && **usagestr)739 while (*usagestr && **usagestr)
653 fprintf(stderr, " or: %s\n", *usagestr++);740 fprintf(stderr, " or: %s\n", *usagestr++);
654 while (*usagestr) {741 while (*usagestr) {
@@ -661,11 +748,20 @@ int usage_with_options_internal(const char * const *usagestr, · 6 unmodified lines
661 if (opts->type != OPTION_GROUP)748 if (opts->type != OPTION_GROUP)
662 fputc('\n', stderr);749 fputc('\n', stderr);
663 750
664 for ( ; opts->type != OPTION_END; opts++)751 ordered = options__order(opts);
752 if (ordered)
753 opts = ordered;
754
755 for ( ; opts->type != OPTION_END; opts++) {
756 if (ctx && ctx->argc > 1 && !option__in_argv(opts, ctx))
757 continue;
665 print_option_help(opts, full);758 print_option_help(opts, full);
759 }
666 760
667 fputc('\n', stderr);761 fputc('\n', stderr);
668 762
763 free(ordered);
764
669 return PARSE_OPT_HELP;765 return PARSE_OPT_HELP;
670}766}
671 767
@@ -673,7 +769,22 @@ void usage_with_options(const char * const *usagestr, · 1 unmodified line
673 const struct option *opts)769 const struct option *opts)
674{770{
675 exit_browser(false);771 exit_browser(false);
676 usage_with_options_internal(usagestr, opts, 0);772 usage_with_options_internal(usagestr, opts, 0, NULL);
773 exit(129);
774}
775
776void usage_with_options_msg(const char * const *usagestr,
777 const struct option *opts, const char *fmt, ...)
778{
779 va_list ap;
780
781 exit_browser(false);
782
783 va_start(ap, fmt);
784 strbuf_addv(&error_buf, fmt, ap);
785 va_end(ap);
786
787 usage_with_options_internal(usagestr, opts, 0, NULL);
677 exit(129);788 exit(129);
678}789}
679 790
@@ -684,7 +795,7 @@ int parse_options_usage(const char * const *usagestr, · 4 unmodified lines
684 if (!usagestr)795 if (!usagestr)
685 goto opt;796 goto opt;
686 797
687 fprintf(stderr, "\n usage: %s\n", *usagestr++);798 fprintf(stderr, "\n Usage: %s\n", *usagestr++);
688 while (*usagestr && **usagestr)799 while (*usagestr && **usagestr)
689 fprintf(stderr, " or: %s\n", *usagestr++);800 fprintf(stderr, " or: %s\n", *usagestr++);
690 while (*usagestr) {801 while (*usagestr) {
@@ -698,24 +809,23 @@ int parse_options_usage(const char * const *usagestr, · 7 unmodified lines
698opt:809opt:
699 for ( ; opts->type != OPTION_END; opts++) {810 for ( ; opts->type != OPTION_END; opts++) {
700 if (short_opt) {811 if (short_opt) {
701 if (opts->short_name == *optstr)812 if (opts->short_name == *optstr) {
813 print_option_help(opts, 0);
702 break;814 break;
815 }
703 continue;816 continue;
704 }817 }
705 818
706 if (opts->long_name == NULL)819 if (opts->long_name == NULL)
707 continue;820 continue;
708 821
709 if (!prefixcmp(optstr, opts->long_name))822 if (!prefixcmp(opts->long_name, optstr))
710 break;823 print_option_help(opts, 0);
711 if (!prefixcmp(optstr, "no-") &&824 if (!prefixcmp("no-", optstr) &&
712 !prefixcmp(optstr + 3, opts->long_name))825 !prefixcmp(opts->long_name, optstr + 3))
713 break;826 print_option_help(opts, 0);
714 }827 }
715 828
716 if (opts->type != OPTION_END)
717 print_option_help(opts, 0);
718
719 return PARSE_OPT_HELP;829 return PARSE_OPT_HELP;
720}830}
721 831
tools/perf/util/parse-options.h+5−0
@@ -111,6 +111,7 @@ struct option { · 110 unmodified lines
111#define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) }111#define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) }
112#define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) }112#define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) }
113#define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) }113#define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) }
114#define OPT_BOOLEAN_FLAG(s, l, v, h, f) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h), .flags = (f) }
114#define OPT_BOOLEAN_SET(s, l, v, os, h) \115#define OPT_BOOLEAN_SET(s, l, v, os, h) \
115 { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), \116 { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), \
116 .value = check_vtype(v, bool *), .help = (h), \117 .value = check_vtype(v, bool *), .help = (h), \
@@ -160,6 +161,10 @@ extern int parse_options_subcommand(int argc, const char **argv, · 43 unmodified lines
160 161
161extern NORETURN void usage_with_options(const char * const *usagestr,162extern NORETURN void usage_with_options(const char * const *usagestr,
162 const struct option *options);163 const struct option *options);
164extern NORETURN __attribute__((format(printf,3,4)))
165void usage_with_options_msg(const char * const *usagestr,
166 const struct option *options,
167 const char *fmt, ...);
163 168
164/*----- incremantal advanced APIs -----*/169/*----- incremantal advanced APIs -----*/
165 170
tools/perf/util/pmu.c+17−25
@@ -626,38 +626,26 @@ static int pmu_resolve_param_term(struct parse_events_term *term, · 625 unmodified lines
626 return -1;626 return -1;
627}627}
628 628
629static char *formats_error_string(struct list_head *formats)629static char *pmu_formats_string(struct list_head *formats)
630{630{
631 struct perf_pmu_format *format;631 struct perf_pmu_format *format;
632 char *err, *str;632 char *str;
633 static const char *static_terms = "config,config1,config2,name,"633 struct strbuf buf;
634 "period,freq,branch_type,time,"
635 "call-graph,stack-size\n";
636 unsigned i = 0;634 unsigned i = 0;
637 635
638 if (!asprintf(&str, "valid terms:"))636 if (!formats)
639 return NULL;637 return NULL;
640 638
639 strbuf_init(&buf, 0);
641 /* sysfs exported terms */640 /* sysfs exported terms */
642 list_for_each_entry(format, formats, list) {641 list_for_each_entry(format, formats, list)
643 char c = i++ ? ',' : ' ';642 strbuf_addf(&buf, i++ ? ",%s" : "%s",
644 643 format->name);
645 err = str;
646 if (!asprintf(&str, "%s%c%s", err, c, format->name))
647 goto fail;
648 free(err);
649 }
650 644
651 /* static terms */645 str = strbuf_detach(&buf, NULL);
652 err = str;646 strbuf_release(&buf);
653 if (!asprintf(&str, "%s,%s", err, static_terms))
654 goto fail;
655 647
656 free(err);
657 return str;648 return str;
658fail:
659 free(err);
660 return NULL;
661}649}
662 650
663/*651/*
@@ -693,9 +681,12 @@ static int pmu_config_term(struct list_head *formats, · 29 unmodified lines
693 if (verbose)681 if (verbose)
694 printf("Invalid event/parameter '%s'\n", term->config);682 printf("Invalid event/parameter '%s'\n", term->config);
695 if (err) {683 if (err) {
684 char *pmu_term = pmu_formats_string(formats);
685
696 err->idx = term->err_term;686 err->idx = term->err_term;
697 err->str = strdup("unknown term");687 err->str = strdup("unknown term");
698 err->help = formats_error_string(formats);688 err->help = parse_events_formats_error_string(pmu_term);
689 free(pmu_term);
699 }690 }
700 return -EINVAL;691 return -EINVAL;
701 }692 }
@@ -1017,7 +1008,8 @@ void print_pmu_events(const char *event_glob, bool name_only) · 315 unmodified lines
1017 goto out_enomem;1008 goto out_enomem;
1018 j++;1009 j++;
1019 }1010 }
1020 if (pmu->selectable) {1011 if (pmu->selectable &&
1012 (event_glob == NULL || strglobmatch(pmu->name, event_glob))) {
1021 char *s;1013 char *s;
1022 if (asprintf(&s, "%s//", pmu->name) < 0)1014 if (asprintf(&s, "%s//", pmu->name) < 0)
1023 goto out_enomem;1015 goto out_enomem;
@@ -1035,7 +1027,7 @@ void print_pmu_events(const char *event_glob, bool name_only) · 11 unmodified lines
1035 printf(" %-50s [Kernel PMU event]\n", aliases[j]);1027 printf(" %-50s [Kernel PMU event]\n", aliases[j]);
1036 printed++;1028 printed++;
1037 }1029 }
1038 if (printed)1030 if (printed && pager_in_use())
1039 printf("\n");1031 printf("\n");
1040out_free:1032out_free:
1041 for (j = 0; j < len; j++)1033 for (j = 0; j < len; j++)
tools/perf/util/probe-event.c+122−112
@@ -40,8 +40,7 @@ · 39 unmodified lines
40#include "color.h"40#include "color.h"
41#include "symbol.h"41#include "symbol.h"
42#include "thread.h"42#include "thread.h"
43#include <api/fs/debugfs.h>43#include <api/fs/fs.h>
44#include <api/fs/tracefs.h>
45#include "trace-event.h" /* For __maybe_unused */44#include "trace-event.h" /* For __maybe_unused */
46#include "probe-event.h"45#include "probe-event.h"
47#include "probe-finder.h"46#include "probe-finder.h"
@@ -72,7 +71,7 @@ static char *synthesize_perf_probe_point(struct perf_probe_point *pp); · 24 unmodified lines
72static struct machine *host_machine;71static struct machine *host_machine;
73 72
74/* Initialize symbol maps and path of vmlinux/modules */73/* Initialize symbol maps and path of vmlinux/modules */
75static int init_symbol_maps(bool user_only)74int init_probe_symbol_maps(bool user_only)
76{75{
77 int ret;76 int ret;
78 77
@@ -102,7 +101,7 @@ out: · 23 unmodified lines
102 return ret;101 return ret;
103}102}
104 103
105static void exit_symbol_maps(void)104void exit_probe_symbol_maps(void)
106{105{
107 if (host_machine) {106 if (host_machine) {
108 machine__delete(host_machine);107 machine__delete(host_machine);
@@ -127,17 +126,19 @@ static struct ref_reloc_sym *kernel_get_ref_reloc_sym(void) · 18 unmodified lines
127{126{
128 /* kmap->ref_reloc_sym should be set if host_machine is initialized */127 /* kmap->ref_reloc_sym should be set if host_machine is initialized */
129 struct kmap *kmap;128 struct kmap *kmap;
129 struct map *map = machine__kernel_map(host_machine);
130 130
131 if (map__load(host_machine->vmlinux_maps[MAP__FUNCTION], NULL) < 0)131 if (map__load(map, NULL) < 0)
132 return NULL;132 return NULL;
133 133
134 kmap = map__kmap(host_machine->vmlinux_maps[MAP__FUNCTION]);134 kmap = map__kmap(map);
135 if (!kmap)135 if (!kmap)
136 return NULL;136 return NULL;
137 return kmap->ref_reloc_sym;137 return kmap->ref_reloc_sym;
138}138}
139 139
140static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)140static int kernel_get_symbol_address_by_name(const char *name, u64 *addr,
141 bool reloc, bool reladdr)
141{142{
142 struct ref_reloc_sym *reloc_sym;143 struct ref_reloc_sym *reloc_sym;
143 struct symbol *sym;144 struct symbol *sym;
@@ -146,12 +147,14 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc) · 2 unmodified lines
146 /* ref_reloc_sym is just a label. Need a special fix*/147 /* ref_reloc_sym is just a label. Need a special fix*/
147 reloc_sym = kernel_get_ref_reloc_sym();148 reloc_sym = kernel_get_ref_reloc_sym();
148 if (reloc_sym && strcmp(name, reloc_sym->name) == 0)149 if (reloc_sym && strcmp(name, reloc_sym->name) == 0)
149 return (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr;150 *addr = (reloc) ? reloc_sym->addr : reloc_sym->unrelocated_addr;
150 else {151 else {
151 sym = __find_kernel_function_by_name(name, &map);152 sym = __find_kernel_function_by_name(name, &map);
152 if (sym)153 if (!sym)
153 return map->unmap_ip(map, sym->start) -154 return -ENOENT;
154 ((reloc) ? 0 : map->reloc);155 *addr = map->unmap_ip(map, sym->start) -
156 ((reloc) ? 0 : map->reloc) -
157 ((reladdr) ? map->start : 0);
155 }158 }
156 return 0;159 return 0;
157}160}
@@ -245,12 +248,14 @@ static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) · 87 unmodified lines
245static bool kprobe_blacklist__listed(unsigned long address);248static bool kprobe_blacklist__listed(unsigned long address);
246static bool kprobe_warn_out_range(const char *symbol, unsigned long address)249static bool kprobe_warn_out_range(const char *symbol, unsigned long address)
247{250{
248 u64 etext_addr;251 u64 etext_addr = 0;
252 int ret;
249 253
250 /* Get the address of _etext for checking non-probable text symbol */254 /* Get the address of _etext for checking non-probable text symbol */
251 etext_addr = kernel_get_symbol_address_by_name("_etext", false);255 ret = kernel_get_symbol_address_by_name("_etext", &etext_addr,
256 false, false);
252 257
253 if (etext_addr != 0 && etext_addr < address)258 if (ret == 0 && etext_addr < address)
254 pr_warning("%s is out of .text, skip it.\n", symbol);259 pr_warning("%s is out of .text, skip it.\n", symbol);
255 else if (kprobe_blacklist__listed(address))260 else if (kprobe_blacklist__listed(address))
256 pr_warning("%s is blacklisted function, skip it.\n", symbol);261 pr_warning("%s is blacklisted function, skip it.\n", symbol);
@@ -282,7 +287,7 @@ static int kernel_get_module_dso(const char *module, struct dso **pdso) · 25 unmodified lines
282 return -ENOENT;287 return -ENOENT;
283 }288 }
284 289
285 map = host_machine->vmlinux_maps[MAP__FUNCTION];290 map = machine__kernel_map(host_machine);
286 dso = map->dso;291 dso = map->dso;
287 292
288 vmlinux_name = symbol_conf.vmlinux_name;293 vmlinux_name = symbol_conf.vmlinux_name;
@@ -436,19 +441,22 @@ static char *debuginfo_cache_path; · 147 unmodified lines
436 441
437static struct debuginfo *debuginfo_cache__open(const char *module, bool silent)442static struct debuginfo *debuginfo_cache__open(const char *module, bool silent)
438{443{
439 if ((debuginfo_cache_path && !strcmp(debuginfo_cache_path, module)) ||444 const char *path = module;
440 (!debuginfo_cache_path && !module && debuginfo_cache))445
446 /* If the module is NULL, it should be the kernel. */
447 if (!module)
448 path = "kernel";
449
450 if (debuginfo_cache_path && !strcmp(debuginfo_cache_path, path))
441 goto out;451 goto out;
442 452
443 /* Copy module path */453 /* Copy module path */
444 free(debuginfo_cache_path);454 free(debuginfo_cache_path);
445 if (module) {455 debuginfo_cache_path = strdup(path);
446 debuginfo_cache_path = strdup(module);456 if (!debuginfo_cache_path) {
447 if (!debuginfo_cache_path) {457 debuginfo__delete(debuginfo_cache);
448 debuginfo__delete(debuginfo_cache);458 debuginfo_cache = NULL;
449 debuginfo_cache = NULL;459 goto out;
450 goto out;
451 }
452 }460 }
453 461
454 debuginfo_cache = open_debuginfo(module, silent);462 debuginfo_cache = open_debuginfo(module, silent);
@@ -517,8 +525,10 @@ static int find_perf_probe_point_from_dwarf(struct probe_trace_point *tp, · 62 unmodified lines
517 goto error;525 goto error;
518 addr += stext;526 addr += stext;
519 } else if (tp->symbol) {527 } else if (tp->symbol) {
520 addr = kernel_get_symbol_address_by_name(tp->symbol, false);528 /* If the module is given, this returns relative address */
521 if (addr == 0)529 ret = kernel_get_symbol_address_by_name(tp->symbol, &addr,
530 false, !!tp->module);
531 if (ret != 0)
522 goto error;532 goto error;
523 addr += tp->offset;533 addr += tp->offset;
524 }534 }
@@ -861,11 +871,11 @@ int show_line_range(struct line_range *lr, const char *module, bool user) · 336 unmodified lines
861{871{
862 int ret;872 int ret;
863 873
864 ret = init_symbol_maps(user);874 ret = init_probe_symbol_maps(user);
865 if (ret < 0)875 if (ret < 0)
866 return ret;876 return ret;
867 ret = __show_line_range(lr, module, user);877 ret = __show_line_range(lr, module, user);
868 exit_symbol_maps();878 exit_probe_symbol_maps();
869 879
870 return ret;880 return ret;
871}881}
@@ -943,7 +953,7 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs, · 71 unmodified lines
943 int i, ret = 0;953 int i, ret = 0;
944 struct debuginfo *dinfo;954 struct debuginfo *dinfo;
945 955
946 ret = init_symbol_maps(pevs->uprobes);956 ret = init_probe_symbol_maps(pevs->uprobes);
947 if (ret < 0)957 if (ret < 0)
948 return ret;958 return ret;
949 959
@@ -960,7 +970,7 @@ int show_available_vars(struct perf_probe_event *pevs, int npevs, · 10 unmodified lines
960 970
961 debuginfo__delete(dinfo);971 debuginfo__delete(dinfo);
962out:972out:
963 exit_symbol_maps();973 exit_probe_symbol_maps();
964 return ret;974 return ret;
965}975}
966 976
@@ -1884,8 +1894,12 @@ static int find_perf_probe_point_from_map(struct probe_trace_point *tp, · 917 unmodified lines
1884 goto out;1894 goto out;
1885 sym = map__find_symbol(map, addr, NULL);1895 sym = map__find_symbol(map, addr, NULL);
1886 } else {1896 } else {
1887 if (tp->symbol)1897 if (tp->symbol && !addr) {
1888 addr = kernel_get_symbol_address_by_name(tp->symbol, true);1898 ret = kernel_get_symbol_address_by_name(tp->symbol,
1899 &addr, true, false);
1900 if (ret < 0)
1901 goto out;
1902 }
1889 if (addr) {1903 if (addr) {
1890 addr += tp->offset;1904 addr += tp->offset;
1891 sym = __find_kernel_function(addr, &map);1905 sym = __find_kernel_function(addr, &map);
@@ -2055,7 +2069,7 @@ static void kprobe_blacklist__delete(struct list_head *blacklist) · 163 unmodified lines
2055static int kprobe_blacklist__load(struct list_head *blacklist)2069static int kprobe_blacklist__load(struct list_head *blacklist)
2056{2070{
2057 struct kprobe_blacklist_node *node;2071 struct kprobe_blacklist_node *node;
2058 const char *__debugfs = debugfs_find_mountpoint();2072 const char *__debugfs = debugfs__mountpoint();
2059 char buf[PATH_MAX], *p;2073 char buf[PATH_MAX], *p;
2060 FILE *fp;2074 FILE *fp;
2061 int ret;2075 int ret;
@@ -2181,9 +2195,9 @@ out: · 119 unmodified lines
2181}2195}
2182 2196
2183/* Show an event */2197/* Show an event */
2184static int show_perf_probe_event(const char *group, const char *event,2198int show_perf_probe_event(const char *group, const char *event,
2185 struct perf_probe_event *pev,2199 struct perf_probe_event *pev,
2186 const char *module, bool use_stdout)2200 const char *module, bool use_stdout)
2187{2201{
2188 struct strbuf buf = STRBUF_INIT;2202 struct strbuf buf = STRBUF_INIT;
2189 int ret;2203 int ret;
@@ -2264,7 +2278,7 @@ int show_perf_probe_events(struct strfilter *filter) · 74 unmodified lines
2264 2278
2265 setup_pager();2279 setup_pager();
2266 2280
2267 ret = init_symbol_maps(false);2281 ret = init_probe_symbol_maps(false);
2268 if (ret < 0)2282 if (ret < 0)
2269 return ret;2283 return ret;
2270 2284
@@ -2280,7 +2294,7 @@ int show_perf_probe_events(struct strfilter *filter) · 9 unmodified lines
2280 close(kp_fd);2294 close(kp_fd);
2281 if (up_fd > 0)2295 if (up_fd > 0)
2282 close(up_fd);2296 close(up_fd);
2283 exit_symbol_maps();2297 exit_probe_symbol_maps();
2284 2298
2285 return ret;2299 return ret;
2286}2300}
@@ -2289,36 +2303,41 @@ static int get_new_event_name(char *buf, size_t len, const char *base, · 2 unmodified lines
2289 struct strlist *namelist, bool allow_suffix)2303 struct strlist *namelist, bool allow_suffix)
2290{2304{
2291 int i, ret;2305 int i, ret;
2292 char *p;2306 char *p, *nbase;
2293 2307
2294 if (*base == '.')2308 if (*base == '.')
2295 base++;2309 base++;
2310 nbase = strdup(base);
2311 if (!nbase)
2312 return -ENOMEM;
2313
2314 /* Cut off the dot suffixes (e.g. .const, .isra)*/
2315 p = strchr(nbase, '.');
2316 if (p && p != nbase)
2317 *p = '\0';
2296 2318
2297 /* Try no suffix */2319 /* Try no suffix number */
2298 ret = e_snprintf(buf, len, "%s", base);2320 ret = e_snprintf(buf, len, "%s", nbase);
2299 if (ret < 0) {2321 if (ret < 0) {
2300 pr_debug("snprintf() failed: %d\n", ret);2322 pr_debug("snprintf() failed: %d\n", ret);
2301 return ret;2323 goto out;
2302 }2324 }
2303 /* Cut off the postfixes (e.g. .const, .isra)*/
2304 p = strchr(buf, '.');
2305 if (p && p != buf)
2306 *p = '\0';
2307 if (!strlist__has_entry(namelist, buf))2325 if (!strlist__has_entry(namelist, buf))
2308 return 0;2326 goto out;
2309 2327
2310 if (!allow_suffix) {2328 if (!allow_suffix) {
2311 pr_warning("Error: event \"%s\" already exists. "2329 pr_warning("Error: event \"%s\" already exists. "
2312 "(Use -f to force duplicates.)\n", base);2330 "(Use -f to force duplicates.)\n", buf);
2313 return -EEXIST;2331 ret = -EEXIST;
2332 goto out;
2314 }2333 }
2315 2334
2316 /* Try to add suffix */2335 /* Try to add suffix */
2317 for (i = 1; i < MAX_EVENT_INDEX; i++) {2336 for (i = 1; i < MAX_EVENT_INDEX; i++) {
2318 ret = e_snprintf(buf, len, "%s_%d", base, i);2337 ret = e_snprintf(buf, len, "%s_%d", nbase, i);
2319 if (ret < 0) {2338 if (ret < 0) {
2320 pr_debug("snprintf() failed: %d\n", ret);2339 pr_debug("snprintf() failed: %d\n", ret);
2321 return ret;2340 goto out;
2322 }2341 }
2323 if (!strlist__has_entry(namelist, buf))2342 if (!strlist__has_entry(namelist, buf))
2324 break;2343 break;
@@ -2328,6 +2347,8 @@ static int get_new_event_name(char *buf, size_t len, const char *base, · 3 unmodified lines
2328 ret = -ERANGE;2347 ret = -ERANGE;
2329 }2348 }
2330 2349
2350out:
2351 free(nbase);
2331 return ret;2352 return ret;
2332}2353}
2333 2354
@@ -2400,7 +2421,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, · 66 unmodified lines
2400{2421{
2401 int i, fd, ret;2422 int i, fd, ret;
2402 struct probe_trace_event *tev = NULL;2423 struct probe_trace_event *tev = NULL;
2403 const char *event = NULL, *group = NULL;
2404 struct strlist *namelist;2424 struct strlist *namelist;
2405 2425
2406 fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0));2426 fd = probe_file__open(PF_FL_RW | (pev->uprobes ? PF_FL_UPROBE : 0));
@@ -2416,7 +2436,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, · 9 unmodified lines
2416 }2436 }
2417 2437
2418 ret = 0;2438 ret = 0;
2419 pr_info("Added new event%s\n", (ntevs > 1) ? "s:" : ":");
2420 for (i = 0; i < ntevs; i++) {2439 for (i = 0; i < ntevs; i++) {
2421 tev = &tevs[i];2440 tev = &tevs[i];
2422 /* Skip if the symbol is out of .text or blacklisted */2441 /* Skip if the symbol is out of .text or blacklisted */
@@ -2433,13 +2452,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, · 10 unmodified lines
2433 if (ret < 0)2452 if (ret < 0)
2434 break;2453 break;
2435 2454
2436 /* We use tev's name for showing new events */
2437 show_perf_probe_event(tev->group, tev->event, pev,
2438 tev->point.module, false);
2439 /* Save the last valid name */
2440 event = tev->event;
2441 group = tev->group;
2442
2443 /*2455 /*
2444 * Probes after the first probe which comes from same2456 * Probes after the first probe which comes from same
2445 * user input are always allowed to add suffix, because2457 * user input are always allowed to add suffix, because
@@ -2451,13 +2463,6 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, · 5 unmodified lines
2451 if (ret == -EINVAL && pev->uprobes)2463 if (ret == -EINVAL && pev->uprobes)
2452 warn_uprobe_event_compat(tev);2464 warn_uprobe_event_compat(tev);
2453 2465
2454 /* Note that it is possible to skip all events because of blacklist */
2455 if (ret >= 0 && event) {
2456 /* Show how to use the event. */
2457 pr_info("\nYou can now use it in all perf tools, such as:\n\n");
2458 pr_info("\tperf record -e %s:%s -aR sleep 1\n\n", group, event);
2459 }
2460
2461 strlist__delete(namelist);2466 strlist__delete(namelist);
2462close_out:2467close_out:
2463 close(fd);2468 close(fd);
@@ -2538,7 +2543,8 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, · 74 unmodified lines
2538 goto out;2543 goto out;
2539 }2544 }
2540 2545
2541 if (!pev->uprobes && !pp->retprobe) {2546 /* Note that the symbols in the kmodule are not relocated */
2547 if (!pev->uprobes && !pp->retprobe && !pev->target) {
2542 reloc_sym = kernel_get_ref_reloc_sym();2548 reloc_sym = kernel_get_ref_reloc_sym();
2543 if (!reloc_sym) {2549 if (!reloc_sym) {
2544 pr_warning("Relocated base symbol is not found!\n");2550 pr_warning("Relocated base symbol is not found!\n");
@@ -2575,8 +2581,9 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, · 30 unmodified lines
2575 }2581 }
2576 /* Add one probe point */2582 /* Add one probe point */
2577 tp->address = map->unmap_ip(map, sym->start) + pp->offset;2583 tp->address = map->unmap_ip(map, sym->start) + pp->offset;
2578 /* If we found a wrong one, mark it by NULL symbol */2584
2579 if (!pev->uprobes &&2585 /* Check the kprobe (not in module) is within .text */
2586 if (!pev->uprobes && !pev->target &&
2580 kprobe_warn_out_range(sym->name, tp->address)) {2587 kprobe_warn_out_range(sym->name, tp->address)) {
2581 tp->symbol = NULL; /* Skip it */2588 tp->symbol = NULL; /* Skip it */
2582 skipped++;2589 skipped++;
@@ -2760,63 +2767,71 @@ static int convert_to_probe_trace_events(struct perf_probe_event *pev, · 177 unmodified lines
2760 return find_probe_trace_events_from_map(pev, tevs);2767 return find_probe_trace_events_from_map(pev, tevs);
2761}2768}
2762 2769
2763struct __event_package {2770int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs)
2764 struct perf_probe_event *pev;
2765 struct probe_trace_event *tevs;
2766 int ntevs;
2767};
2768
2769int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
2770{2771{
2771 int i, j, ret;2772 int i, ret;
2772 struct __event_package *pkgs;
2773
2774 ret = 0;
2775 pkgs = zalloc(sizeof(struct __event_package) * npevs);
2776
2777 if (pkgs == NULL)
2778 return -ENOMEM;
2779
2780 ret = init_symbol_maps(pevs->uprobes);
2781 if (ret < 0) {
2782 free(pkgs);
2783 return ret;
2784 }
2785 2773
2786 /* Loop 1: convert all events */2774 /* Loop 1: convert all events */
2787 for (i = 0; i < npevs; i++) {2775 for (i = 0; i < npevs; i++) {
2788 pkgs[i].pev = &pevs[i];
2789 /* Init kprobe blacklist if needed */2776 /* Init kprobe blacklist if needed */
2790 if (!pkgs[i].pev->uprobes)2777 if (!pevs[i].uprobes)
2791 kprobe_blacklist__init();2778 kprobe_blacklist__init();
2792 /* Convert with or without debuginfo */2779 /* Convert with or without debuginfo */
2793 ret = convert_to_probe_trace_events(pkgs[i].pev,2780 ret = convert_to_probe_trace_events(&pevs[i], &pevs[i].tevs);
2794 &pkgs[i].tevs);
2795 if (ret < 0)2781 if (ret < 0)
2796 goto end;2782 return ret;
2797 pkgs[i].ntevs = ret;2783 pevs[i].ntevs = ret;
2798 }2784 }
2799 /* This just release blacklist only if allocated */2785 /* This just release blacklist only if allocated */
2800 kprobe_blacklist__release();2786 kprobe_blacklist__release();
2801 2787
2788 return 0;
2789}
2790
2791int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs)
2792{
2793 int i, ret = 0;
2794
2802 /* Loop 2: add all events */2795 /* Loop 2: add all events */
2803 for (i = 0; i < npevs; i++) {2796 for (i = 0; i < npevs; i++) {
2804 ret = __add_probe_trace_events(pkgs[i].pev, pkgs[i].tevs,2797 ret = __add_probe_trace_events(&pevs[i], pevs[i].tevs,
2805 pkgs[i].ntevs,2798 pevs[i].ntevs,
2806 probe_conf.force_add);2799 probe_conf.force_add);
2807 if (ret < 0)2800 if (ret < 0)
2808 break;2801 break;
2809 }2802 }
2810end:2803 return ret;
2804}
2805
2806void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs)
2807{
2808 int i, j;
2809
2811 /* Loop 3: cleanup and free trace events */2810 /* Loop 3: cleanup and free trace events */
2812 for (i = 0; i < npevs; i++) {2811 for (i = 0; i < npevs; i++) {
2813 for (j = 0; j < pkgs[i].ntevs; j++)2812 for (j = 0; j < pevs[i].ntevs; j++)
2814 clear_probe_trace_event(&pkgs[i].tevs[j]);2813 clear_probe_trace_event(&pevs[i].tevs[j]);
2815 zfree(&pkgs[i].tevs);2814 zfree(&pevs[i].tevs);
2815 pevs[i].ntevs = 0;
2816 clear_perf_probe_event(&pevs[i]);
2816 }2817 }
2817 free(pkgs);2818}
2818 exit_symbol_maps();
2819 2819
2820int add_perf_probe_events(struct perf_probe_event *pevs, int npevs)
2821{
2822 int ret;
2823
2824 ret = init_probe_symbol_maps(pevs->uprobes);
2825 if (ret < 0)
2826 return ret;
2827
2828 ret = convert_perf_probe_events(pevs, npevs);
2829 if (ret == 0)
2830 ret = apply_perf_probe_events(pevs, npevs);
2831
2832 cleanup_perf_probe_events(pevs, npevs);
2833
2834 exit_probe_symbol_maps();
2820 return ret;2835 return ret;
2821}2836}
2822 2837
@@ -2828,8 +2843,6 @@ int del_perf_probe_events(struct strfilter *filter) · 5 unmodified lines
2828 if (!str)2843 if (!str)
2829 return -EINVAL;2844 return -EINVAL;
2830 2845
2831 pr_debug("Delete filter: \'%s\'\n", str);
2832
2833 /* Get current event names */2846 /* Get current event names */
2834 ret = probe_file__open_both(&kfd, &ufd, PF_FL_RW);2847 ret = probe_file__open_both(&kfd, &ufd, PF_FL_RW);
2835 if (ret < 0)2848 if (ret < 0)
@@ -2844,9 +2857,6 @@ int del_perf_probe_events(struct strfilter *filter) · 8 unmodified lines
2844 ret = ret2;2857 ret = ret2;
2845 goto error;2858 goto error;
2846 }2859 }
2847 if (ret == -ENOENT && ret2 == -ENOENT)
2848 pr_debug("\"%s\" does not hit any event.\n", str);
2849 /* Note that this is silently ignored */
2850 ret = 0;2860 ret = 0;
2851 2861
2852error:2862error:
@@ -2881,7 +2891,7 @@ int show_available_funcs(const char *target, struct strfilter *_filter, · 28 unmodified lines
2881 struct map *map;2891 struct map *map;
2882 int ret;2892 int ret;
2883 2893
2884 ret = init_symbol_maps(user);2894 ret = init_probe_symbol_maps(user);
2885 if (ret < 0)2895 if (ret < 0)
2886 return ret;2896 return ret;
2887 2897
@@ -2911,7 +2921,7 @@ end: · 23 unmodified lines
2911 if (user) {2921 if (user) {
2912 map__put(map);2922 map__put(map);
2913 }2923 }
2914 exit_symbol_maps();2924 exit_probe_symbol_maps();
2915 2925
2916 return ret;2926 return ret;
2917}2927}
tools/perf/util/probe-event.h+11−0
@@ -87,6 +87,8 @@ struct perf_probe_event { · 86 unmodified lines
87 bool uprobes; /* Uprobe event flag */87 bool uprobes; /* Uprobe event flag */
88 char *target; /* Target binary */88 char *target; /* Target binary */
89 struct perf_probe_arg *args; /* Arguments */89 struct perf_probe_arg *args; /* Arguments */
90 struct probe_trace_event *tevs;
91 int ntevs;
90};92};
91 93
92/* Line range */94/* Line range */
@@ -108,6 +110,8 @@ struct variable_list { · 15 unmodified lines
108};110};
109 111
110struct map;112struct map;
113int init_probe_symbol_maps(bool user_only);
114void exit_probe_symbol_maps(void);
111 115
112/* Command string to events */116/* Command string to events */
113extern int parse_perf_probe_command(const char *cmd,117extern int parse_perf_probe_command(const char *cmd,
@@ -138,7 +142,14 @@ extern void line_range__clear(struct line_range *lr); · 24 unmodified lines
138extern int line_range__init(struct line_range *lr);142extern int line_range__init(struct line_range *lr);
139 143
140extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);144extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs);
145extern int convert_perf_probe_events(struct perf_probe_event *pevs, int npevs);
146extern int apply_perf_probe_events(struct perf_probe_event *pevs, int npevs);
147extern void cleanup_perf_probe_events(struct perf_probe_event *pevs, int npevs);
141extern int del_perf_probe_events(struct strfilter *filter);148extern int del_perf_probe_events(struct strfilter *filter);
149
150extern int show_perf_probe_event(const char *group, const char *event,
151 struct perf_probe_event *pev,
152 const char *module, bool use_stdout);
142extern int show_perf_probe_events(struct strfilter *filter);153extern int show_perf_probe_events(struct strfilter *filter);
143extern int show_line_range(struct line_range *lr, const char *module,154extern int show_line_range(struct line_range *lr, const char *module,
144 bool user);155 bool user);
tools/perf/util/probe-file.c+38−18
@@ -22,8 +22,7 @@ · 21 unmodified lines
22#include "color.h"22#include "color.h"
23#include "symbol.h"23#include "symbol.h"
24#include "thread.h"24#include "thread.h"
25#include <api/fs/debugfs.h>25#include <api/fs/tracing_path.h>
26#include <api/fs/tracefs.h>
27#include "probe-event.h"26#include "probe-event.h"
28#include "probe-file.h"27#include "probe-file.h"
29#include "session.h"28#include "session.h"
@@ -73,21 +72,11 @@ static void print_both_open_warning(int kerr, int uerr) · 43 unmodified lines
73static int open_probe_events(const char *trace_file, bool readwrite)72static int open_probe_events(const char *trace_file, bool readwrite)
74{73{
75 char buf[PATH_MAX];74 char buf[PATH_MAX];
76 const char *__debugfs;
77 const char *tracing_dir = "";75 const char *tracing_dir = "";
78 int ret;76 int ret;
79 77
80 __debugfs = tracefs_find_mountpoint();
81 if (__debugfs == NULL) {
82 tracing_dir = "tracing/";
83
84 __debugfs = debugfs_find_mountpoint();
85 if (__debugfs == NULL)
86 return -ENOTSUP;
87 }
88
89 ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",78 ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
90 __debugfs, tracing_dir, trace_file);79 tracing_path, tracing_dir, trace_file);
91 if (ret >= 0) {80 if (ret >= 0) {
92 pr_debug("Opening %s write=%d\n", buf, readwrite);81 pr_debug("Opening %s write=%d\n", buf, readwrite);
93 if (readwrite && !probe_event_dry_run)82 if (readwrite && !probe_event_dry_run)
@@ -267,7 +256,6 @@ static int __del_trace_probe_event(int fd, struct str_node *ent) · 173 unmodified lines
267 goto error;256 goto error;
268 }257 }
269 258
270 pr_info("Removed event: %s\n", ent->s);
271 return 0;259 return 0;
272error:260error:
273 pr_warning("Failed to delete event: %s\n",261 pr_warning("Failed to delete event: %s\n",
@@ -275,7 +263,8 @@ error: · 1 unmodified line
275 return ret;263 return ret;
276}264}
277 265
278int probe_file__del_events(int fd, struct strfilter *filter)266int probe_file__get_events(int fd, struct strfilter *filter,
267 struct strlist *plist)
279{268{
280 struct strlist *namelist;269 struct strlist *namelist;
281 struct str_node *ent;270 struct str_node *ent;
@@ -290,12 +279,43 @@ int probe_file__del_events(int fd, struct strfilter *filter) · 8 unmodified lines
290 p = strchr(ent->s, ':');279 p = strchr(ent->s, ':');
291 if ((p && strfilter__compare(filter, p + 1)) ||280 if ((p && strfilter__compare(filter, p + 1)) ||
292 strfilter__compare(filter, ent->s)) {281 strfilter__compare(filter, ent->s)) {
293 ret = __del_trace_probe_event(fd, ent);282 strlist__add(plist, ent->s);
294 if (ret < 0)283 ret = 0;
295 break;
296 }284 }
297 }285 }
298 strlist__delete(namelist);286 strlist__delete(namelist);
299 287
300 return ret;288 return ret;
301}289}
290
291int probe_file__del_strlist(int fd, struct strlist *namelist)
292{
293 int ret = 0;
294 struct str_node *ent;
295
296 strlist__for_each(ent, namelist) {
297 ret = __del_trace_probe_event(fd, ent);
298 if (ret < 0)
299 break;
300 }
301 return ret;
302}
303
304int probe_file__del_events(int fd, struct strfilter *filter)
305{
306 struct strlist *namelist;
307 int ret;
308
309 namelist = strlist__new(NULL, NULL);
310 if (!namelist)
311 return -ENOMEM;
312
313 ret = probe_file__get_events(fd, filter, namelist);
314 if (ret < 0)
315 return ret;
316
317 ret = probe_file__del_strlist(fd, namelist);
318 strlist__delete(namelist);
319
320 return ret;
321}
tools/perf/util/probe-file.h+4−0
@@ -14,5 +14,9 @@ struct strlist *probe_file__get_namelist(int fd); · 13 unmodified lines
14struct strlist *probe_file__get_rawlist(int fd);14struct strlist *probe_file__get_rawlist(int fd);
15int probe_file__add_event(int fd, struct probe_trace_event *tev);15int probe_file__add_event(int fd, struct probe_trace_event *tev);
16int probe_file__del_events(int fd, struct strfilter *filter);16int probe_file__del_events(int fd, struct strfilter *filter);
17int probe_file__get_events(int fd, struct strfilter *filter,
18 struct strlist *plist);
19int probe_file__del_strlist(int fd, struct strlist *namelist);
20
17 21
18#endif22#endif
tools/perf/util/probe-finder.c+54−4
@@ -70,6 +70,7 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg, · 69 unmodified lines
70 if (!dbg->dwfl)70 if (!dbg->dwfl)
71 goto error;71 goto error;
72 72
73 dwfl_report_begin(dbg->dwfl);
73 dbg->mod = dwfl_report_offline(dbg->dwfl, "", "", fd);74 dbg->mod = dwfl_report_offline(dbg->dwfl, "", "", fd);
74 if (!dbg->mod)75 if (!dbg->mod)
75 goto error;76 goto error;
@@ -78,6 +79,8 @@ static int debuginfo__init_offline_dwarf(struct debuginfo *dbg, · 2 unmodified lines
78 if (!dbg->dbg)79 if (!dbg->dbg)
79 goto error;80 goto error;
80 81
82 dwfl_report_end(dbg->dwfl, NULL, NULL);
83
81 return 0;84 return 0;
82error:85error:
83 if (dbg->dwfl)86 if (dbg->dwfl)
@@ -591,6 +594,7 @@ static int find_variable(Dwarf_Die *sc_die, struct probe_finder *pf) · 507 unmodified lines
591/* Convert subprogram DIE to trace point */594/* Convert subprogram DIE to trace point */
592static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod,595static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod,
593 Dwarf_Addr paddr, bool retprobe,596 Dwarf_Addr paddr, bool retprobe,
597 const char *function,
594 struct probe_trace_point *tp)598 struct probe_trace_point *tp)
595{599{
596 Dwarf_Addr eaddr, highaddr;600 Dwarf_Addr eaddr, highaddr;
@@ -634,8 +638,10 @@ static int convert_to_trace_point(Dwarf_Die *sp_die, Dwfl_Module *mod, · 37 unmodified lines
634 /* Return probe must be on the head of a subprogram */638 /* Return probe must be on the head of a subprogram */
635 if (retprobe) {639 if (retprobe) {
636 if (eaddr != paddr) {640 if (eaddr != paddr) {
637 pr_warning("Return probe must be on the head of"641 pr_warning("Failed to find \"%s%%return\",\n"
638 " a real function.\n");642 " because %s is an inlined function and"
643 " has no return point.\n", function,
644 function);
639 return -EINVAL;645 return -EINVAL;
640 }646 }
641 tp->retprobe = true;647 tp->retprobe = true;
@@ -1175,6 +1181,7 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf) · 533 unmodified lines
1175{1181{
1176 struct trace_event_finder *tf =1182 struct trace_event_finder *tf =
1177 container_of(pf, struct trace_event_finder, pf);1183 container_of(pf, struct trace_event_finder, pf);
1184 struct perf_probe_point *pp = &pf->pev->point;
1178 struct probe_trace_event *tev;1185 struct probe_trace_event *tev;
1179 struct perf_probe_arg *args;1186 struct perf_probe_arg *args;
1180 int ret, i;1187 int ret, i;
@@ -1189,7 +1196,7 @@ static int add_probe_trace_event(Dwarf_Die *sc_die, struct probe_finder *pf) · 8 unmodified lines
1189 1196
1190 /* Trace point should be converted from subprogram DIE */1197 /* Trace point should be converted from subprogram DIE */
1191 ret = convert_to_trace_point(&pf->sp_die, tf->mod, pf->addr,1198 ret = convert_to_trace_point(&pf->sp_die, tf->mod, pf->addr,
1192 pf->pev->point.retprobe, &tev->point);1199 pp->retprobe, pp->function, &tev->point);
1193 if (ret < 0)1200 if (ret < 0)
1194 return ret;1201 return ret;
1195 1202
@@ -1319,6 +1326,7 @@ static int add_available_vars(Dwarf_Die *sc_die, struct probe_finder *pf) · 123 unmodified lines
1319{1326{
1320 struct available_var_finder *af =1327 struct available_var_finder *af =
1321 container_of(pf, struct available_var_finder, pf);1328 container_of(pf, struct available_var_finder, pf);
1329 struct perf_probe_point *pp = &pf->pev->point;
1322 struct variable_list *vl;1330 struct variable_list *vl;
1323 Dwarf_Die die_mem;1331 Dwarf_Die die_mem;
1324 int ret;1332 int ret;
@@ -1332,7 +1340,7 @@ static int add_available_vars(Dwarf_Die *sc_die, struct probe_finder *pf) · 7 unmodified lines
1332 1340
1333 /* Trace point should be converted from subprogram DIE */1341 /* Trace point should be converted from subprogram DIE */
1334 ret = convert_to_trace_point(&pf->sp_die, af->mod, pf->addr,1342 ret = convert_to_trace_point(&pf->sp_die, af->mod, pf->addr,
1335 pf->pev->point.retprobe, &vl->point);1343 pp->retprobe, pp->function, &vl->point);
1336 if (ret < 0)1344 if (ret < 0)
1337 return ret;1345 return ret;
1338 1346
@@ -1399,6 +1407,41 @@ int debuginfo__find_available_vars_at(struct debuginfo *dbg, · 60 unmodified lines
1399 return (ret < 0) ? ret : af.nvls;1407 return (ret < 0) ? ret : af.nvls;
1400}1408}
1401 1409
1410/* For the kernel module, we need a special code to get a DIE */
1411static int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs)
1412{
1413 int n, i;
1414 Elf32_Word shndx;
1415 Elf_Scn *scn;
1416 Elf *elf;
1417 GElf_Shdr mem, *shdr;
1418 const char *p;
1419
1420 elf = dwfl_module_getelf(dbg->mod, &dbg->bias);
1421 if (!elf)
1422 return -EINVAL;
1423
1424 /* Get the number of relocations */
1425 n = dwfl_module_relocations(dbg->mod);
1426 if (n < 0)
1427 return -ENOENT;
1428 /* Search the relocation related .text section */
1429 for (i = 0; i < n; i++) {
1430 p = dwfl_module_relocation_info(dbg->mod, i, &shndx);
1431 if (strcmp(p, ".text") == 0) {
1432 /* OK, get the section header */
1433 scn = elf_getscn(elf, shndx);
1434 if (!scn)
1435 return -ENOENT;
1436 shdr = gelf_getshdr(scn, &mem);
1437 if (!shdr)
1438 return -ENOENT;
1439 *offs = shdr->sh_addr;
1440 }
1441 }
1442 return 0;
1443}
1444
1402/* Reverse search */1445/* Reverse search */
1403int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,1446int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr,
1404 struct perf_probe_point *ppt)1447 struct perf_probe_point *ppt)
@@ -1407,9 +1450,16 @@ int debuginfo__find_probe_point(struct debuginfo *dbg, unsigned long addr, · 2 unmodified lines
1407 Dwarf_Addr _addr = 0, baseaddr = 0;1450 Dwarf_Addr _addr = 0, baseaddr = 0;
1408 const char *fname = NULL, *func = NULL, *basefunc = NULL, *tmp;1451 const char *fname = NULL, *func = NULL, *basefunc = NULL, *tmp;
1409 int baseline = 0, lineno = 0, ret = 0;1452 int baseline = 0, lineno = 0, ret = 0;
1453 bool reloc = false;
1410 1454
1455retry:
1411 /* Find cu die */1456 /* Find cu die */
1412 if (!dwarf_addrdie(dbg->dbg, (Dwarf_Addr)addr, &cudie)) {1457 if (!dwarf_addrdie(dbg->dbg, (Dwarf_Addr)addr, &cudie)) {
1458 if (!reloc && debuginfo__get_text_offset(dbg, &baseaddr) == 0) {
1459 addr += baseaddr;
1460 reloc = true;
1461 goto retry;
1462 }
1413 pr_warning("Failed to find debug information for address %lx\n",1463 pr_warning("Failed to find debug information for address %lx\n",
1414 addr);1464 addr);
1415 ret = -EINVAL;1465 ret = -EINVAL;
tools/perf/util/python.c+55−4
@@ -67,6 +67,7 @@ static char pyrf_mmap_event__doc[] = PyDoc_STR("perf mmap event object."); · 66 unmodified lines
67static PyMemberDef pyrf_mmap_event__members[] = {67static PyMemberDef pyrf_mmap_event__members[] = {
68 sample_members68 sample_members
69 member_def(perf_event_header, type, T_UINT, "event type"),69 member_def(perf_event_header, type, T_UINT, "event type"),
70 member_def(perf_event_header, misc, T_UINT, "event misc"),
70 member_def(mmap_event, pid, T_UINT, "event pid"),71 member_def(mmap_event, pid, T_UINT, "event pid"),
71 member_def(mmap_event, tid, T_UINT, "event tid"),72 member_def(mmap_event, tid, T_UINT, "event tid"),
72 member_def(mmap_event, start, T_ULONGLONG, "start of the map"),73 member_def(mmap_event, start, T_ULONGLONG, "start of the map"),
@@ -297,6 +298,43 @@ static PyTypeObject pyrf_sample_event__type = { · 224 unmodified lines
297 .tp_repr = (reprfunc)pyrf_sample_event__repr,298 .tp_repr = (reprfunc)pyrf_sample_event__repr,
298};299};
299 300
301static char pyrf_context_switch_event__doc[] = PyDoc_STR("perf context_switch event object.");
302
303static PyMemberDef pyrf_context_switch_event__members[] = {
304 sample_members
305 member_def(perf_event_header, type, T_UINT, "event type"),
306 member_def(context_switch_event, next_prev_pid, T_UINT, "next/prev pid"),
307 member_def(context_switch_event, next_prev_tid, T_UINT, "next/prev tid"),
308 { .name = NULL, },
309};
310
311static PyObject *pyrf_context_switch_event__repr(struct pyrf_event *pevent)
312{
313 PyObject *ret;
314 char *s;
315
316 if (asprintf(&s, "{ type: context_switch, next_prev_pid: %u, next_prev_tid: %u, switch_out: %u }",
317 pevent->event.context_switch.next_prev_pid,
318 pevent->event.context_switch.next_prev_tid,
319 !!(pevent->event.header.misc & PERF_RECORD_MISC_SWITCH_OUT)) < 0) {
320 ret = PyErr_NoMemory();
321 } else {
322 ret = PyString_FromString(s);
323 free(s);
324 }
325 return ret;
326}
327
328static PyTypeObject pyrf_context_switch_event__type = {
329 PyVarObject_HEAD_INIT(NULL, 0)
330 .tp_name = "perf.context_switch_event",
331 .tp_basicsize = sizeof(struct pyrf_event),
332 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
333 .tp_doc = pyrf_context_switch_event__doc,
334 .tp_members = pyrf_context_switch_event__members,
335 .tp_repr = (reprfunc)pyrf_context_switch_event__repr,
336};
337
300static int pyrf_event__setup_types(void)338static int pyrf_event__setup_types(void)
301{339{
302 int err;340 int err;
@@ -306,6 +344,7 @@ static int pyrf_event__setup_types(void) · 3 unmodified lines
306 pyrf_lost_event__type.tp_new =344 pyrf_lost_event__type.tp_new =
307 pyrf_read_event__type.tp_new =345 pyrf_read_event__type.tp_new =
308 pyrf_sample_event__type.tp_new =346 pyrf_sample_event__type.tp_new =
347 pyrf_context_switch_event__type.tp_new =
309 pyrf_throttle_event__type.tp_new = PyType_GenericNew;348 pyrf_throttle_event__type.tp_new = PyType_GenericNew;
310 err = PyType_Ready(&pyrf_mmap_event__type);349 err = PyType_Ready(&pyrf_mmap_event__type);
311 if (err < 0)350 if (err < 0)
@@ -328,6 +367,9 @@ static int pyrf_event__setup_types(void) · 16 unmodified lines
328 err = PyType_Ready(&pyrf_sample_event__type);367 err = PyType_Ready(&pyrf_sample_event__type);
329 if (err < 0)368 if (err < 0)
330 goto out;369 goto out;
370 err = PyType_Ready(&pyrf_context_switch_event__type);
371 if (err < 0)
372 goto out;
331out:373out:
332 return err;374 return err;
333}375}
@@ -342,6 +384,8 @@ static PyTypeObject *pyrf_event__type[] = { · 8 unmodified lines
342 [PERF_RECORD_FORK] = &pyrf_task_event__type,384 [PERF_RECORD_FORK] = &pyrf_task_event__type,
343 [PERF_RECORD_READ] = &pyrf_read_event__type,385 [PERF_RECORD_READ] = &pyrf_read_event__type,
344 [PERF_RECORD_SAMPLE] = &pyrf_sample_event__type,386 [PERF_RECORD_SAMPLE] = &pyrf_sample_event__type,
387 [PERF_RECORD_SWITCH] = &pyrf_context_switch_event__type,
388 [PERF_RECORD_SWITCH_CPU_WIDE] = &pyrf_context_switch_event__type,
345};389};
346 390
347static PyObject *pyrf_event__new(union perf_event *event)391static PyObject *pyrf_event__new(union perf_event *event)
@@ -349,8 +393,10 @@ static PyObject *pyrf_event__new(union perf_event *event) · 1 unmodified line
349 struct pyrf_event *pevent;393 struct pyrf_event *pevent;
350 PyTypeObject *ptype;394 PyTypeObject *ptype;
351 395
352 if (event->header.type < PERF_RECORD_MMAP ||396 if ((event->header.type < PERF_RECORD_MMAP ||
353 event->header.type > PERF_RECORD_SAMPLE)397 event->header.type > PERF_RECORD_SAMPLE) &&
398 !(event->header.type == PERF_RECORD_SWITCH ||
399 event->header.type == PERF_RECORD_SWITCH_CPU_WIDE))
354 return NULL;400 return NULL;
355 401
356 ptype = pyrf_event__type[event->header.type];402 ptype = pyrf_event__type[event->header.type];
@@ -528,6 +574,7 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevsel, · 171 unmodified lines
528 "exclude_hv",574 "exclude_hv",
529 "exclude_idle",575 "exclude_idle",
530 "mmap",576 "mmap",
577 "context_switch",
531 "comm",578 "comm",
532 "freq",579 "freq",
533 "inherit_stat",580 "inherit_stat",
@@ -553,6 +600,7 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevsel, · 19 unmodified lines
553 exclude_hv = 0,600 exclude_hv = 0,
554 exclude_idle = 0,601 exclude_idle = 0,
555 mmap = 0,602 mmap = 0,
603 context_switch = 0,
556 comm = 0,604 comm = 0,
557 freq = 1,605 freq = 1,
558 inherit_stat = 0,606 inherit_stat = 0,
@@ -565,13 +613,13 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevsel, · 6 unmodified lines
565 int idx = 0;613 int idx = 0;
566 614
567 if (!PyArg_ParseTupleAndKeywords(args, kwargs,615 if (!PyArg_ParseTupleAndKeywords(args, kwargs,
568 "|iKiKKiiiiiiiiiiiiiiiiiiiiiKK", kwlist,616 "|iKiKKiiiiiiiiiiiiiiiiiiiiiiKK", kwlist,
569 &attr.type, &attr.config, &attr.sample_freq,617 &attr.type, &attr.config, &attr.sample_freq,
570 &sample_period, &attr.sample_type,618 &sample_period, &attr.sample_type,
571 &attr.read_format, &disabled, &inherit,619 &attr.read_format, &disabled, &inherit,
572 &pinned, &exclusive, &exclude_user,620 &pinned, &exclusive, &exclude_user,
573 &exclude_kernel, &exclude_hv, &exclude_idle,621 &exclude_kernel, &exclude_hv, &exclude_idle,
574 &mmap, &comm, &freq, &inherit_stat,622 &mmap, &context_switch, &comm, &freq, &inherit_stat,
575 &enable_on_exec, &task, &watermark,623 &enable_on_exec, &task, &watermark,
576 &precise_ip, &mmap_data, &sample_id_all,624 &precise_ip, &mmap_data, &sample_id_all,
577 &attr.wakeup_events, &attr.bp_type,625 &attr.wakeup_events, &attr.bp_type,
@@ -595,6 +643,7 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevsel, · 17 unmodified lines
595 attr.exclude_hv = exclude_hv;643 attr.exclude_hv = exclude_hv;
596 attr.exclude_idle = exclude_idle;644 attr.exclude_idle = exclude_idle;
597 attr.mmap = mmap;645 attr.mmap = mmap;
646 attr.context_switch = context_switch;
598 attr.comm = comm;647 attr.comm = comm;
599 attr.freq = freq;648 attr.freq = freq;
600 attr.inherit_stat = inherit_stat;649 attr.inherit_stat = inherit_stat;
@@ -1019,6 +1068,8 @@ static struct { · 418 unmodified lines
1019 PERF_CONST(RECORD_LOST_SAMPLES),1068 PERF_CONST(RECORD_LOST_SAMPLES),
1020 PERF_CONST(RECORD_SWITCH),1069 PERF_CONST(RECORD_SWITCH),
1021 PERF_CONST(RECORD_SWITCH_CPU_WIDE),1070 PERF_CONST(RECORD_SWITCH_CPU_WIDE),
1071
1072 PERF_CONST(RECORD_MISC_SWITCH_OUT),
1022 { .name = NULL, },1073 { .name = NULL, },
1023};1074};
1024 1075
tools/perf/util/scripting-engines/trace-event-perl.c+1−0
@@ -221,6 +221,7 @@ static void define_event_symbols(struct event_format *event, · 220 unmodified lines
221 break;221 break;
222 case PRINT_BSTRING:222 case PRINT_BSTRING:
223 case PRINT_DYNAMIC_ARRAY:223 case PRINT_DYNAMIC_ARRAY:
224 case PRINT_DYNAMIC_ARRAY_LEN:
224 case PRINT_STRING:225 case PRINT_STRING:
225 case PRINT_BITMASK:226 case PRINT_BITMASK:
226 break;227 break;
tools/perf/util/scripting-engines/trace-event-python.c+2−1
@@ -251,6 +251,7 @@ static void define_event_symbols(struct event_format *event, · 250 unmodified lines
251 /* gcc warns for these? */251 /* gcc warns for these? */
252 case PRINT_BSTRING:252 case PRINT_BSTRING:
253 case PRINT_DYNAMIC_ARRAY:253 case PRINT_DYNAMIC_ARRAY:
254 case PRINT_DYNAMIC_ARRAY_LEN:
254 case PRINT_FUNC:255 case PRINT_FUNC:
255 case PRINT_BITMASK:256 case PRINT_BITMASK:
256 /* we should warn... */257 /* we should warn... */
@@ -318,7 +319,7 @@ static PyObject *python_process_callchain(struct perf_sample *sample, · 61 unmodified lines
318 319
319 if (thread__resolve_callchain(al->thread, evsel,320 if (thread__resolve_callchain(al->thread, evsel,
320 sample, NULL, NULL,321 sample, NULL, NULL,
321 PERF_MAX_STACK_DEPTH) != 0) {322 scripting_max_stack) != 0) {
322 pr_err("Failed to resolve callchain. Skipping\n");323 pr_err("Failed to resolve callchain. Skipping\n");
323 goto exit;324 goto exit;
324 }325 }
tools/perf/util/session.c+16−21
@@ -138,6 +138,8 @@ struct perf_session *perf_session__new(struct perf_data_file *file, · 137 unmodified lines
138 perf_session__set_id_hdr_size(session);138 perf_session__set_id_hdr_size(session);
139 perf_session__set_comm_exec(session);139 perf_session__set_comm_exec(session);
140 }140 }
141 } else {
142 session->machines.host.env = &perf_env;
141 }143 }
142 144
143 if (!file || perf_data_file__is_write(file)) {145 if (!file || perf_data_file__is_write(file)) {
@@ -170,30 +172,13 @@ static void perf_session__delete_threads(struct perf_session *session) · 26 unmodified lines
170 machine__delete_threads(&session->machines.host);172 machine__delete_threads(&session->machines.host);
171}173}
172 174
173static void perf_session_env__exit(struct perf_env *env)
174{
175 zfree(&env->hostname);
176 zfree(&env->os_release);
177 zfree(&env->version);
178 zfree(&env->arch);
179 zfree(&env->cpu_desc);
180 zfree(&env->cpuid);
181
182 zfree(&env->cmdline);
183 zfree(&env->cmdline_argv);
184 zfree(&env->sibling_cores);
185 zfree(&env->sibling_threads);
186 zfree(&env->numa_nodes);
187 zfree(&env->pmu_mappings);
188}
189
190void perf_session__delete(struct perf_session *session)175void perf_session__delete(struct perf_session *session)
191{176{
192 auxtrace__free(session);177 auxtrace__free(session);
193 auxtrace_index__free(&session->auxtrace_index);178 auxtrace_index__free(&session->auxtrace_index);
194 perf_session__destroy_kernel_maps(session);179 perf_session__destroy_kernel_maps(session);
195 perf_session__delete_threads(session);180 perf_session__delete_threads(session);
196 perf_session_env__exit(&session->header.env);181 perf_env__exit(&session->header.env);
197 machines__exit(&session->machines);182 machines__exit(&session->machines);
198 if (session->file)183 if (session->file)
199 perf_data_file__close(session->file);184 perf_data_file__close(session->file);
@@ -1079,11 +1064,11 @@ static int machines__deliver_event(struct machines *machines, · 879 unmodified lines
1079 1064
1080 switch (event->header.type) {1065 switch (event->header.type) {
1081 case PERF_RECORD_SAMPLE:1066 case PERF_RECORD_SAMPLE:
1082 dump_sample(evsel, event, sample);
1083 if (evsel == NULL) {1067 if (evsel == NULL) {
1084 ++evlist->stats.nr_unknown_id;1068 ++evlist->stats.nr_unknown_id;
1085 return 0;1069 return 0;
1086 }1070 }
1071 dump_sample(evsel, event, sample);
1087 if (machine == NULL) {1072 if (machine == NULL) {
1088 ++evlist->stats.nr_unprocessable_samples;1073 ++evlist->stats.nr_unprocessable_samples;
1089 return 0;1074 return 0;
@@ -1116,6 +1101,9 @@ static int machines__deliver_event(struct machines *machines, · 26 unmodified lines
1116 case PERF_RECORD_UNTHROTTLE:1101 case PERF_RECORD_UNTHROTTLE:
1117 return tool->unthrottle(tool, event, sample, machine);1102 return tool->unthrottle(tool, event, sample, machine);
1118 case PERF_RECORD_AUX:1103 case PERF_RECORD_AUX:
1104 if (tool->aux == perf_event__process_aux &&
1105 (event->aux.flags & PERF_AUX_FLAG_TRUNCATED))
1106 evlist->stats.total_aux_lost += 1;
1119 return tool->aux(tool, event, sample, machine);1107 return tool->aux(tool, event, sample, machine);
1120 case PERF_RECORD_ITRACE_START:1108 case PERF_RECORD_ITRACE_START:
1121 return tool->itrace_start(tool, event, sample, machine);1109 return tool->itrace_start(tool, event, sample, machine);
@@ -1323,7 +1311,7 @@ struct thread *perf_session__findnew(struct perf_session *session, pid_t pid) · 201 unmodified lines
1323 return machine__findnew_thread(&session->machines.host, -1, pid);1311 return machine__findnew_thread(&session->machines.host, -1, pid);
1324}1312}
1325 1313
1326static struct thread *perf_session__register_idle_thread(struct perf_session *session)1314struct thread *perf_session__register_idle_thread(struct perf_session *session)
1327{1315{
1328 struct thread *thread;1316 struct thread *thread;
1329 1317
@@ -1361,6 +1349,13 @@ static void perf_session__warn_about_errors(const struct perf_session *session) · 31 unmodified lines
1361 }1349 }
1362 }1350 }
1363 1351
1352 if (session->tool->aux == perf_event__process_aux &&
1353 stats->total_aux_lost != 0) {
1354 ui__warning("AUX data lost %" PRIu64 " times out of %u!\n\n",
1355 stats->total_aux_lost,
1356 stats->nr_events[PERF_RECORD_AUX]);
1357 }
1358
1364 if (stats->nr_unknown_events != 0) {1359 if (stats->nr_unknown_events != 0) {
1365 ui__warning("Found %u unknown events!\n\n"1360 ui__warning("Found %u unknown events!\n\n"
1366 "Is this an older tool processing a perf.data "1361 "Is this an older tool processing a perf.data "
@@ -1805,7 +1800,7 @@ void perf_evsel__print_ip(struct perf_evsel *evsel, struct perf_sample *sample, · 438 unmodified lines
1805 1800
1806 if (thread__resolve_callchain(al->thread, evsel,1801 if (thread__resolve_callchain(al->thread, evsel,
1807 sample, NULL, NULL,1802 sample, NULL, NULL,
1808 PERF_MAX_STACK_DEPTH) != 0) {1803 stack_depth) != 0) {
1809 if (verbose)1804 if (verbose)
1810 error("Failed to resolve callchain. Skipping\n");1805 error("Failed to resolve callchain. Skipping\n");
1811 return;1806 return;
tools/perf/util/session.h+2−0
@@ -89,6 +89,8 @@ struct machine *perf_session__findnew_machine(struct perf_session *session, pid_ · 88 unmodified lines
89}89}
90 90
91struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);91struct thread *perf_session__findnew(struct perf_session *session, pid_t pid);
92struct thread *perf_session__register_idle_thread(struct perf_session *session);
93
92size_t perf_session__fprintf(struct perf_session *session, FILE *fp);94size_t perf_session__fprintf(struct perf_session *session, FILE *fp);
93 95
94size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);96size_t perf_session__fprintf_dsos(struct perf_session *session, FILE *fp);
tools/perf/util/sort.c+70−4
@@ -21,6 +21,7 @@ int sort__need_collapse = 0; · 20 unmodified lines
21int sort__has_parent = 0;21int sort__has_parent = 0;
22int sort__has_sym = 0;22int sort__has_sym = 0;
23int sort__has_dso = 0;23int sort__has_dso = 0;
24int sort__has_socket = 0;
24enum sort_mode sort__mode = SORT_MODE__NORMAL;25enum sort_mode sort__mode = SORT_MODE__NORMAL;
25 26
26 27
@@ -328,8 +329,8 @@ static char *get_srcfile(struct hist_entry *e) · 301 unmodified lines
328 char *sf, *p;329 char *sf, *p;
329 struct map *map = e->ms.map;330 struct map *map = e->ms.map;
330 331
331 sf = get_srcline(map->dso, map__rip_2objdump(map, e->ip),332 sf = __get_srcline(map->dso, map__rip_2objdump(map, e->ip),
332 e->ms.sym, true);333 e->ms.sym, false, true);
333 if (!strcmp(sf, SRCLINE_UNKNOWN))334 if (!strcmp(sf, SRCLINE_UNKNOWN))
334 return no_srcfile;335 return no_srcfile;
335 p = strchr(sf, ':');336 p = strchr(sf, ':');
@@ -421,6 +422,27 @@ struct sort_entry sort_cpu = { · 85 unmodified lines
421 .se_width_idx = HISTC_CPU,422 .se_width_idx = HISTC_CPU,
422};423};
423 424
425/* --sort socket */
426
427static int64_t
428sort__socket_cmp(struct hist_entry *left, struct hist_entry *right)
429{
430 return right->socket - left->socket;
431}
432
433static int hist_entry__socket_snprintf(struct hist_entry *he, char *bf,
434 size_t size, unsigned int width)
435{
436 return repsep_snprintf(bf, size, "%*.*d", width, width-3, he->socket);
437}
438
439struct sort_entry sort_socket = {
440 .se_header = "Socket",
441 .se_cmp = sort__socket_cmp,
442 .se_snprintf = hist_entry__socket_snprintf,
443 .se_width_idx = HISTC_SOCKET,
444};
445
424/* sort keys for branch stacks */446/* sort keys for branch stacks */
425 447
426static int64_t448static int64_t
@@ -632,6 +654,35 @@ static int hist_entry__daddr_snprintf(struct hist_entry *he, char *bf, · 205 unmodified lines
632 width);654 width);
633}655}
634 656
657static int64_t
658sort__iaddr_cmp(struct hist_entry *left, struct hist_entry *right)
659{
660 uint64_t l = 0, r = 0;
661
662 if (left->mem_info)
663 l = left->mem_info->iaddr.addr;
664 if (right->mem_info)
665 r = right->mem_info->iaddr.addr;
666
667 return (int64_t)(r - l);
668}
669
670static int hist_entry__iaddr_snprintf(struct hist_entry *he, char *bf,
671 size_t size, unsigned int width)
672{
673 uint64_t addr = 0;
674 struct map *map = NULL;
675 struct symbol *sym = NULL;
676
677 if (he->mem_info) {
678 addr = he->mem_info->iaddr.addr;
679 map = he->mem_info->iaddr.map;
680 sym = he->mem_info->iaddr.sym;
681 }
682 return _hist_entry__sym_snprintf(map, sym, addr, he->level, bf, size,
683 width);
684}
685
635static int64_t686static int64_t
636sort__dso_daddr_cmp(struct hist_entry *left, struct hist_entry *right)687sort__dso_daddr_cmp(struct hist_entry *left, struct hist_entry *right)
637{688{
@@ -1055,6 +1106,13 @@ struct sort_entry sort_mem_daddr_sym = { · 417 unmodified lines
1055 .se_width_idx = HISTC_MEM_DADDR_SYMBOL,1106 .se_width_idx = HISTC_MEM_DADDR_SYMBOL,
1056};1107};
1057 1108
1109struct sort_entry sort_mem_iaddr_sym = {
1110 .se_header = "Code Symbol",
1111 .se_cmp = sort__iaddr_cmp,
1112 .se_snprintf = hist_entry__iaddr_snprintf,
1113 .se_width_idx = HISTC_MEM_IADDR_SYMBOL,
1114};
1115
1058struct sort_entry sort_mem_daddr_dso = {1116struct sort_entry sort_mem_daddr_dso = {
1059 .se_header = "Data Object",1117 .se_header = "Data Object",
1060 .se_cmp = sort__dso_daddr_cmp,1118 .se_cmp = sort__dso_daddr_cmp,
@@ -1248,6 +1306,7 @@ static struct sort_dimension common_sort_dimensions[] = { · 187 unmodified lines
1248 DIM(SORT_SYM, "symbol", sort_sym),1306 DIM(SORT_SYM, "symbol", sort_sym),
1249 DIM(SORT_PARENT, "parent", sort_parent),1307 DIM(SORT_PARENT, "parent", sort_parent),
1250 DIM(SORT_CPU, "cpu", sort_cpu),1308 DIM(SORT_CPU, "cpu", sort_cpu),
1309 DIM(SORT_SOCKET, "socket", sort_socket),
1251 DIM(SORT_SRCLINE, "srcline", sort_srcline),1310 DIM(SORT_SRCLINE, "srcline", sort_srcline),
1252 DIM(SORT_SRCFILE, "srcfile", sort_srcfile),1311 DIM(SORT_SRCFILE, "srcfile", sort_srcfile),
1253 DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),1312 DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
@@ -1276,6 +1335,7 @@ static struct sort_dimension bstack_sort_dimensions[] = { · 22 unmodified lines
1276 1335
1277static struct sort_dimension memory_sort_dimensions[] = {1336static struct sort_dimension memory_sort_dimensions[] = {
1278 DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym),1337 DIM(SORT_MEM_DADDR_SYMBOL, "symbol_daddr", sort_mem_daddr_sym),
1338 DIM(SORT_MEM_IADDR_SYMBOL, "symbol_iaddr", sort_mem_iaddr_sym),
1279 DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso),1339 DIM(SORT_MEM_DADDR_DSO, "dso_daddr", sort_mem_daddr_dso),
1280 DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked),1340 DIM(SORT_MEM_LOCKED, "locked", sort_mem_locked),
1281 DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb),1341 DIM(SORT_MEM_TLB, "tlb", sort_mem_tlb),
@@ -1517,6 +1577,12 @@ static int __hpp_dimension__add_output(struct hpp_dimension *hd) · 235 unmodified lines
1517 return 0;1577 return 0;
1518}1578}
1519 1579
1580int hpp_dimension__add_output(unsigned col)
1581{
1582 BUG_ON(col >= PERF_HPP__MAX_INDEX);
1583 return __hpp_dimension__add_output(&hpp_sort_dimensions[col]);
1584}
1585
1520int sort_dimension__add(const char *tok)1586int sort_dimension__add(const char *tok)
1521{1587{
1522 unsigned int i;1588 unsigned int i;
@@ -1550,6 +1616,8 @@ int sort_dimension__add(const char *tok) · 27 unmodified lines
1550 1616
1551 } else if (sd->entry == &sort_dso) {1617 } else if (sd->entry == &sort_dso) {
1552 sort__has_dso = 1;1618 sort__has_dso = 1;
1619 } else if (sd->entry == &sort_socket) {
1620 sort__has_socket = 1;
1553 }1621 }
1554 1622
1555 return __sort_dimension__add(sd);1623 return __sort_dimension__add(sd);
@@ -1855,8 +1923,6 @@ static int __setup_output_field(void) · 299 unmodified lines
1855 if (field_order == NULL)1923 if (field_order == NULL)
1856 return 0;1924 return 0;
1857 1925
1858 reset_dimensions();
1859
1860 strp = str = strdup(field_order);1926 strp = str = strdup(field_order);
1861 if (str == NULL) {1927 if (str == NULL) {
1862 error("Not enough memory to setup output fields");1928 error("Not enough memory to setup output fields");
tools/perf/util/sort.h+6−0
@@ -34,6 +34,7 @@ extern int have_ignore_callees; · 33 unmodified lines
34extern int sort__need_collapse;34extern int sort__need_collapse;
35extern int sort__has_parent;35extern int sort__has_parent;
36extern int sort__has_sym;36extern int sort__has_sym;
37extern int sort__has_socket;
37extern enum sort_mode sort__mode;38extern enum sort_mode sort__mode;
38extern struct sort_entry sort_comm;39extern struct sort_entry sort_comm;
39extern struct sort_entry sort_dso;40extern struct sort_entry sort_dso;
@@ -90,6 +91,7 @@ struct hist_entry { · 50 unmodified lines
90 struct comm *comm;91 struct comm *comm;
91 u64 ip;92 u64 ip;
92 u64 transaction;93 u64 transaction;
94 s32 socket;
93 s32 cpu;95 s32 cpu;
94 u8 cpumode;96 u8 cpumode;
95 97
@@ -172,6 +174,7 @@ enum sort_type { · 76 unmodified lines
172 SORT_SYM,174 SORT_SYM,
173 SORT_PARENT,175 SORT_PARENT,
174 SORT_CPU,176 SORT_CPU,
177 SORT_SOCKET,
175 SORT_SRCLINE,178 SORT_SRCLINE,
176 SORT_SRCFILE,179 SORT_SRCFILE,
177 SORT_LOCAL_WEIGHT,180 SORT_LOCAL_WEIGHT,
@@ -198,6 +201,7 @@ enum sort_type { · 20 unmodified lines
198 SORT_MEM_LVL,201 SORT_MEM_LVL,
199 SORT_MEM_SNOOP,202 SORT_MEM_SNOOP,
200 SORT_MEM_DCACHELINE,203 SORT_MEM_DCACHELINE,
204 SORT_MEM_IADDR_SYMBOL,
201};205};
202 206
203/*207/*
@@ -230,4 +234,6 @@ void perf_hpp__set_elide(int idx, bool elide); · 26 unmodified lines
230int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);234int report_parse_ignore_callees_opt(const struct option *opt, const char *arg, int unset);
231 235
232bool is_strict_order(const char *order);236bool is_strict_order(const char *order);
237
238int hpp_dimension__add_output(unsigned col);
233#endif /* __PERF_SORT_H */239#endif /* __PERF_SORT_H */
tools/perf/util/srcline.c+24−5
@@ -149,8 +149,11 @@ static void addr2line_cleanup(struct a2l_data *a2l) · 148 unmodified lines
149 free(a2l);149 free(a2l);
150}150}
151 151
152#define MAX_INLINE_NEST 1024
153
152static int addr2line(const char *dso_name, u64 addr,154static int addr2line(const char *dso_name, u64 addr,
153 char **file, unsigned int *line, struct dso *dso)155 char **file, unsigned int *line, struct dso *dso,
156 bool unwind_inlines)
154{157{
155 int ret = 0;158 int ret = 0;
156 struct a2l_data *a2l = dso->a2l;159 struct a2l_data *a2l = dso->a2l;
@@ -170,6 +173,15 @@ static int addr2line(const char *dso_name, u64 addr, · 13 unmodified lines
170 173
171 bfd_map_over_sections(a2l->abfd, find_address_in_section, a2l);174 bfd_map_over_sections(a2l->abfd, find_address_in_section, a2l);
172 175
176 if (a2l->found && unwind_inlines) {
177 int cnt = 0;
178
179 while (bfd_find_inliner_info(a2l->abfd, &a2l->filename,
180 &a2l->funcname, &a2l->line) &&
181 cnt++ < MAX_INLINE_NEST)
182 ;
183 }
184
173 if (a2l->found && a2l->filename) {185 if (a2l->found && a2l->filename) {
174 *file = strdup(a2l->filename);186 *file = strdup(a2l->filename);
175 *line = a2l->line;187 *line = a2l->line;
@@ -197,7 +209,8 @@ void dso__free_a2l(struct dso *dso) · 21 unmodified lines
197 209
198static int addr2line(const char *dso_name, u64 addr,210static int addr2line(const char *dso_name, u64 addr,
199 char **file, unsigned int *line_nr,211 char **file, unsigned int *line_nr,
200 struct dso *dso __maybe_unused)212 struct dso *dso __maybe_unused,
213 bool unwind_inlines __maybe_unused)
201{214{
202 FILE *fp;215 FILE *fp;
203 char cmd[PATH_MAX];216 char cmd[PATH_MAX];
@@ -254,8 +267,8 @@ void dso__free_a2l(struct dso *dso __maybe_unused) · 50 unmodified lines
254 */267 */
255#define A2L_FAIL_LIMIT 123268#define A2L_FAIL_LIMIT 123
256 269
257char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,270char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
258 bool show_sym)271 bool show_sym, bool unwind_inlines)
259{272{
260 char *file = NULL;273 char *file = NULL;
261 unsigned line = 0;274 unsigned line = 0;
@@ -276,7 +289,7 @@ char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, · 14 unmodified lines
276 if (!strncmp(dso_name, "/tmp/perf-", 10))289 if (!strncmp(dso_name, "/tmp/perf-", 10))
277 goto out;290 goto out;
278 291
279 if (!addr2line(dso_name, addr, &file, &line, dso))292 if (!addr2line(dso_name, addr, &file, &line, dso, unwind_inlines))
280 goto out;293 goto out;
281 294
282 if (asprintf(&srcline, "%s:%u",295 if (asprintf(&srcline, "%s:%u",
@@ -310,3 +323,9 @@ void free_srcline(char *srcline) · 27 unmodified lines
310 if (srcline && strcmp(srcline, SRCLINE_UNKNOWN) != 0)323 if (srcline && strcmp(srcline, SRCLINE_UNKNOWN) != 0)
311 free(srcline);324 free(srcline);
312}325}
326
327char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
328 bool show_sym)
329{
330 return __get_srcline(dso, addr, sym, show_sym, false);
331}
tools/perf/util/stat.c+7−6
@@ -67,7 +67,7 @@ double rel_stddev_stats(double stddev, double avg) · 66 unmodified lines
67bool __perf_evsel_stat__is(struct perf_evsel *evsel,67bool __perf_evsel_stat__is(struct perf_evsel *evsel,
68 enum perf_stat_evsel_id id)68 enum perf_stat_evsel_id id)
69{69{
70 struct perf_stat *ps = evsel->priv;70 struct perf_stat_evsel *ps = evsel->priv;
71 71
72 return ps->id == id;72 return ps->id == id;
73}73}
@@ -84,7 +84,7 @@ static const char *id_str[PERF_STAT_EVSEL_ID__MAX] = { · 10 unmodified lines
84 84
85void perf_stat_evsel_id_init(struct perf_evsel *evsel)85void perf_stat_evsel_id_init(struct perf_evsel *evsel)
86{86{
87 struct perf_stat *ps = evsel->priv;87 struct perf_stat_evsel *ps = evsel->priv;
88 int i;88 int i;
89 89
90 /* ps->id is 0 hence PERF_STAT_EVSEL_ID__NONE by default */90 /* ps->id is 0 hence PERF_STAT_EVSEL_ID__NONE by default */
@@ -100,7 +100,7 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel) · 9 unmodified lines
100void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)100void perf_evsel__reset_stat_priv(struct perf_evsel *evsel)
101{101{
102 int i;102 int i;
103 struct perf_stat *ps = evsel->priv;103 struct perf_stat_evsel *ps = evsel->priv;
104 104
105 for (i = 0; i < 3; i++)105 for (i = 0; i < 3; i++)
106 init_stats(&ps->res_stats[i]);106 init_stats(&ps->res_stats[i]);
@@ -110,7 +110,7 @@ void perf_evsel__reset_stat_priv(struct perf_evsel *evsel) · 3 unmodified lines
110 110
111int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)111int perf_evsel__alloc_stat_priv(struct perf_evsel *evsel)
112{112{
113 evsel->priv = zalloc(sizeof(struct perf_stat));113 evsel->priv = zalloc(sizeof(struct perf_stat_evsel));
114 if (evsel->priv == NULL)114 if (evsel->priv == NULL)
115 return -ENOMEM;115 return -ENOMEM;
116 perf_evsel__reset_stat_priv(evsel);116 perf_evsel__reset_stat_priv(evsel);
@@ -230,7 +230,7 @@ static int check_per_pkg(struct perf_evsel *counter, · 113 unmodified lines
230 if (!(vals->run && vals->ena))230 if (!(vals->run && vals->ena))
231 return 0;231 return 0;
232 232
233 s = cpu_map__get_socket(cpus, cpu);233 s = cpu_map__get_socket(cpus, cpu, NULL);
234 if (s < 0)234 if (s < 0)
235 return -1;235 return -1;
236 236
@@ -272,6 +272,7 @@ process_counter_values(struct perf_stat_config *config, struct perf_evsel *evsel · 35 unmodified lines
272 aggr->ena += count->ena;272 aggr->ena += count->ena;
273 aggr->run += count->run;273 aggr->run += count->run;
274 }274 }
275 case AGGR_UNSET:
275 default:276 default:
276 break;277 break;
277 }278 }
@@ -304,7 +305,7 @@ int perf_stat_process_counter(struct perf_stat_config *config, · 26 unmodified lines
304 struct perf_evsel *counter)305 struct perf_evsel *counter)
305{306{
306 struct perf_counts_values *aggr = &counter->counts->aggr;307 struct perf_counts_values *aggr = &counter->counts->aggr;
307 struct perf_stat *ps = counter->priv;308 struct perf_stat_evsel *ps = counter->priv;
308 u64 *count = counter->counts->aggr.values;309 u64 *count = counter->counts->aggr.values;
309 int i, ret;310 int i, ret;
310 311
tools/perf/util/stat.h+2−1
@@ -20,7 +20,7 @@ enum perf_stat_evsel_id { · 19 unmodified lines
20 PERF_STAT_EVSEL_ID__MAX,20 PERF_STAT_EVSEL_ID__MAX,
21};21};
22 22
23struct perf_stat {23struct perf_stat_evsel {
24 struct stats res_stats[3];24 struct stats res_stats[3];
25 enum perf_stat_evsel_id id;25 enum perf_stat_evsel_id id;
26};26};
@@ -31,6 +31,7 @@ enum aggr_mode { · 4 unmodified lines
31 AGGR_SOCKET,31 AGGR_SOCKET,
32 AGGR_CORE,32 AGGR_CORE,
33 AGGR_THREAD,33 AGGR_THREAD,
34 AGGR_UNSET,
34};35};
35 36
36struct perf_stat_config {37struct perf_stat_config {
tools/perf/util/strbuf.c+15−7
@@ -82,23 +82,22 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len) · 81 unmodified lines
82 strbuf_setlen(sb, sb->len + len);82 strbuf_setlen(sb, sb->len + len);
83}83}
84 84
85void strbuf_addf(struct strbuf *sb, const char *fmt, ...)85void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap)
86{86{
87 int len;87 int len;
88 va_list ap;88 va_list ap_saved;
89 89
90 if (!strbuf_avail(sb))90 if (!strbuf_avail(sb))
91 strbuf_grow(sb, 64);91 strbuf_grow(sb, 64);
92 va_start(ap, fmt);92
93 va_copy(ap_saved, ap);
93 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);94 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
94 va_end(ap);
95 if (len < 0)95 if (len < 0)
96 die("your vsnprintf is broken");96 die("your vsnprintf is broken");
97 if (len > strbuf_avail(sb)) {97 if (len > strbuf_avail(sb)) {
98 strbuf_grow(sb, len);98 strbuf_grow(sb, len);
99 va_start(ap, fmt);99 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved);
100 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);100 va_end(ap_saved);
101 va_end(ap);
102 if (len > strbuf_avail(sb)) {101 if (len > strbuf_avail(sb)) {
103 die("this should not happen, your vsnprintf is broken");102 die("this should not happen, your vsnprintf is broken");
104 }103 }
@@ -106,6 +105,15 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) · 1 unmodified line
106 strbuf_setlen(sb, sb->len + len);105 strbuf_setlen(sb, sb->len + len);
107}106}
108 107
108void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
109{
110 va_list ap;
111
112 va_start(ap, fmt);
113 strbuf_addv(sb, fmt, ap);
114 va_end(ap);
115}
116
109ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint)117ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint)
110{118{
111 size_t oldlen = sb->len;119 size_t oldlen = sb->len;
tools/perf/util/strbuf.h+2−0
@@ -39,6 +39,7 @@ · 38 unmodified lines
39 */39 */
40 40
41#include <assert.h>41#include <assert.h>
42#include <stdarg.h>
42 43
43extern char strbuf_slopbuf[];44extern char strbuf_slopbuf[];
44struct strbuf {45struct strbuf {
@@ -85,6 +86,7 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) { · 40 unmodified lines
85 86
86__attribute__((format(printf,2,3)))87__attribute__((format(printf,2,3)))
87extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);88extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
89extern void strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap);
88 90
89/* XXX: if read fails, any partial read is undone */91/* XXX: if read fails, any partial read is undone */
90extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint);92extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint);
tools/perf/util/symbol-minimal.c+1−1
@@ -337,7 +337,7 @@ int dso__load_sym(struct dso *dso, struct map *map __maybe_unused, · 336 unmodified lines
337 symbol_filter_t filter __maybe_unused,337 symbol_filter_t filter __maybe_unused,
338 int kmodule __maybe_unused)338 int kmodule __maybe_unused)
339{339{
340 unsigned char *build_id[BUILD_ID_SIZE];340 unsigned char build_id[BUILD_ID_SIZE];
341 int ret;341 int ret;
342 342
343 ret = fd__is_64_bit(ss->fd);343 ret = fd__is_64_bit(ss->fd);
tools/perf/util/symbol.c+20−11
@@ -624,7 +624,7 @@ static int map__process_kallsym_symbol(void *arg, const char *name, · 623 unmodified lines
624 * symbols, setting length to 0, and rely on624 * symbols, setting length to 0, and rely on
625 * symbols__fixup_end() to fix it up.625 * symbols__fixup_end() to fix it up.
626 */626 */
627 sym = symbol__new(start, 0, kallsyms2elf_type(type), name);627 sym = symbol__new(start, 0, kallsyms2elf_binding(type), name);
628 if (sym == NULL)628 if (sym == NULL)
629 return -ENOMEM;629 return -ENOMEM;
630 /*630 /*
@@ -680,7 +680,7 @@ static int dso__split_kallsyms_for_kcore(struct dso *dso, struct map *map, · 49 unmodified lines
680 pos->start -= curr_map->start - curr_map->pgoff;680 pos->start -= curr_map->start - curr_map->pgoff;
681 if (pos->end)681 if (pos->end)
682 pos->end -= curr_map->start - curr_map->pgoff;682 pos->end -= curr_map->start - curr_map->pgoff;
683 if (curr_map != map) {683 if (curr_map->dso != map->dso) {
684 rb_erase_init(&pos->rb_node, root);684 rb_erase_init(&pos->rb_node, root);
685 symbols__insert(685 symbols__insert(
686 &curr_map->dso->symbols[curr_map->type],686 &curr_map->dso->symbols[curr_map->type],
@@ -1406,6 +1406,7 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) · 719 unmodified lines
1406 struct symsrc ss_[2];1406 struct symsrc ss_[2];
1407 struct symsrc *syms_ss = NULL, *runtime_ss = NULL;1407 struct symsrc *syms_ss = NULL, *runtime_ss = NULL;
1408 bool kmod;1408 bool kmod;
1409 unsigned char build_id[BUILD_ID_SIZE];
1409 1410
1410 pthread_mutex_lock(&dso->lock);1411 pthread_mutex_lock(&dso->lock);
1411 1412
@@ -1461,6 +1462,14 @@ int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter) · 49 unmodified lines
1461 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||1462 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE ||
1462 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;1463 dso->symtab_type == DSO_BINARY_TYPE__GUEST_KMODULE_COMP;
1463 1464
1465
1466 /*
1467 * Read the build id if possible. This is required for
1468 * DSO_BINARY_TYPE__BUILDID_DEBUGINFO to work
1469 */
1470 if (filename__read_build_id(dso->name, build_id, BUILD_ID_SIZE) > 0)
1471 dso__set_build_id(dso, build_id);
1472
1464 /*1473 /*
1465 * Iterate over candidate debug images.1474 * Iterate over candidate debug images.
1466 * Keep track of "interesting" ones (those which have a symtab, dynsym,1475 * Keep track of "interesting" ones (those which have a symtab, dynsym,
@@ -1607,6 +1616,15 @@ int dso__load_vmlinux_path(struct dso *dso, struct map *map, · 140 unmodified lines
1607 int i, err = 0;1616 int i, err = 0;
1608 char *filename = NULL;1617 char *filename = NULL;
1609 1618
1619 pr_debug("Looking at the vmlinux_path (%d entries long)\n",
1620 vmlinux_path__nr_entries + 1);
1621
1622 for (i = 0; i < vmlinux_path__nr_entries; ++i) {
1623 err = dso__load_vmlinux(dso, map, vmlinux_path[i], false, filter);
1624 if (err > 0)
1625 goto out;
1626 }
1627
1610 if (!symbol_conf.ignore_vmlinux_buildid)1628 if (!symbol_conf.ignore_vmlinux_buildid)
1611 filename = dso__build_id_filename(dso, NULL, 0);1629 filename = dso__build_id_filename(dso, NULL, 0);
1612 if (filename != NULL) {1630 if (filename != NULL) {
@@ -1615,15 +1633,6 @@ int dso__load_vmlinux_path(struct dso *dso, struct map *map, · 2 unmodified lines
1615 goto out;1633 goto out;
1616 free(filename);1634 free(filename);
1617 }1635 }
1618
1619 pr_debug("Looking at the vmlinux_path (%d entries long)\n",
1620 vmlinux_path__nr_entries + 1);
1621
1622 for (i = 0; i < vmlinux_path__nr_entries; ++i) {
1623 err = dso__load_vmlinux(dso, map, vmlinux_path[i], false, filter);
1624 if (err > 0)
1625 break;
1626 }
1627out:1636out:
1628 return err;1637 return err;
1629}1638}
tools/perf/util/symbol.h+1−0
@@ -191,6 +191,7 @@ struct addr_location { · 190 unmodified lines
191 u8 filtered;191 u8 filtered;
192 u8 cpumode;192 u8 cpumode;
193 s32 cpu;193 s32 cpu;
194 s32 socket;
194};195};
195 196
196struct symsrc {197struct symsrc {
tools/perf/util/trace-event-info.c+1−1
@@ -38,7 +38,7 @@ · 37 unmodified lines
38 38
39#include "../perf.h"39#include "../perf.h"
40#include "trace-event.h"40#include "trace-event.h"
41#include <api/fs/debugfs.h>41#include <api/fs/tracing_path.h>
42#include "evsel.h"42#include "evsel.h"
43#include "debug.h"43#include "debug.h"
44 44
tools/perf/util/trace-event.c+13−3
@@ -7,7 +7,9 @@ · 6 unmodified lines
7#include <sys/stat.h>7#include <sys/stat.h>
8#include <fcntl.h>8#include <fcntl.h>
9#include <linux/kernel.h>9#include <linux/kernel.h>
10#include <linux/err.h>
10#include <traceevent/event-parse.h>11#include <traceevent/event-parse.h>
12#include <api/fs/tracing_path.h>
11#include "trace-event.h"13#include "trace-event.h"
12#include "machine.h"14#include "machine.h"
13#include "util.h"15#include "util.h"
@@ -65,6 +67,9 @@ void trace_event__cleanup(struct trace_event *t) · 51 unmodified lines
65 pevent_free(t->pevent);67 pevent_free(t->pevent);
66}68}
67 69
70/*
71 * Returns pointer with encoded error via <linux/err.h> interface.
72 */
68static struct event_format*73static struct event_format*
69tp_format(const char *sys, const char *name)74tp_format(const char *sys, const char *name)
70{75{
@@ -73,12 +78,14 @@ tp_format(const char *sys, const char *name) · 2 unmodified lines
73 char path[PATH_MAX];78 char path[PATH_MAX];
74 size_t size;79 size_t size;
75 char *data;80 char *data;
81 int err;
76 82
77 scnprintf(path, PATH_MAX, "%s/%s/%s/format",83 scnprintf(path, PATH_MAX, "%s/%s/%s/format",
78 tracing_events_path, sys, name);84 tracing_events_path, sys, name);
79 85
80 if (filename__read_str(path, &data, &size))86 err = filename__read_str(path, &data, &size);
81 return NULL;87 if (err)
88 return ERR_PTR(err);
82 89
83 pevent_parse_format(pevent, &event, data, size, sys);90 pevent_parse_format(pevent, &event, data, size, sys);
84 91
@@ -86,11 +93,14 @@ tp_format(const char *sys, const char *name) · 1 unmodified line
86 return event;93 return event;
87}94}
88 95
96/*
97 * Returns pointer with encoded error via <linux/err.h> interface.
98 */
89struct event_format*99struct event_format*
90trace_event__tp_format(const char *sys, const char *name)100trace_event__tp_format(const char *sys, const char *name)
91{101{
92 if (!tevent_initialized && trace_event__init2())102 if (!tevent_initialized && trace_event__init2())
93 return NULL;103 return ERR_PTR(-ENOMEM);
94 104
95 return tp_format(sys, name);105 return tp_format(sys, name);
96}106}
tools/perf/util/trace-event.h+2−0
@@ -78,6 +78,8 @@ struct scripting_ops { · 77 unmodified lines
78 int (*generate_script) (struct pevent *pevent, const char *outfile);78 int (*generate_script) (struct pevent *pevent, const char *outfile);
79};79};
80 80
81extern unsigned int scripting_max_stack;
82
81int script_spec_register(const char *spec, struct scripting_ops *ops);83int script_spec_register(const char *spec, struct scripting_ops *ops);
82 84
83void setup_perl_scripting(void);85void setup_perl_scripting(void);
tools/perf/util/unwind-libunwind.c+12−7
@@ -330,6 +330,7 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi, · 329 unmodified lines
330 struct map *map;330 struct map *map;
331 unw_dyn_info_t di;331 unw_dyn_info_t di;
332 u64 table_data, segbase, fde_count;332 u64 table_data, segbase, fde_count;
333 int ret = -EINVAL;
333 334
334 map = find_map(ip, ui);335 map = find_map(ip, ui);
335 if (!map || !map->dso)336 if (!map || !map->dso)
@@ -348,29 +349,33 @@ find_proc_info(unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi, · 12 unmodified lines
348 di.u.rti.table_data = map->start + table_data;349 di.u.rti.table_data = map->start + table_data;
349 di.u.rti.table_len = fde_count * sizeof(struct table_entry)350 di.u.rti.table_len = fde_count * sizeof(struct table_entry)
350 / sizeof(unw_word_t);351 / sizeof(unw_word_t);
351 return dwarf_search_unwind_table(as, ip, &di, pi,352 ret = dwarf_search_unwind_table(as, ip, &di, pi,
352 need_unwind_info, arg);353 need_unwind_info, arg);
353 }354 }
354 355
355#ifndef NO_LIBUNWIND_DEBUG_FRAME356#ifndef NO_LIBUNWIND_DEBUG_FRAME
356 /* Check the .debug_frame section for unwinding info */357 /* Check the .debug_frame section for unwinding info */
357 if (!read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {358 if (ret < 0 &&
359 !read_unwind_spec_debug_frame(map->dso, ui->machine, &segbase)) {
358 int fd = dso__data_get_fd(map->dso, ui->machine);360 int fd = dso__data_get_fd(map->dso, ui->machine);
359 int is_exec = elf_is_exec(fd, map->dso->name);361 int is_exec = elf_is_exec(fd, map->dso->name);
360 unw_word_t base = is_exec ? 0 : map->start;362 unw_word_t base = is_exec ? 0 : map->start;
363 const char *symfile;
361 364
362 if (fd >= 0)365 if (fd >= 0)
363 dso__data_put_fd(map->dso);366 dso__data_put_fd(map->dso);
364 367
368 symfile = map->dso->symsrc_filename ?: map->dso->name;
369
365 memset(&di, 0, sizeof(di));370 memset(&di, 0, sizeof(di));
366 if (dwarf_find_debug_frame(0, &di, ip, base, map->dso->name,371 if (dwarf_find_debug_frame(0, &di, ip, base, symfile,
367 map->start, map->end))372 map->start, map->end))
368 return dwarf_search_unwind_table(as, ip, &di, pi,373 return dwarf_search_unwind_table(as, ip, &di, pi,
369 need_unwind_info, arg);374 need_unwind_info, arg);
370 }375 }
371#endif376#endif
372 377
373 return -EINVAL;378 return ret;
374}379}
375 380
376static int access_fpreg(unw_addr_space_t __maybe_unused as,381static int access_fpreg(unw_addr_space_t __maybe_unused as,
@@ -461,7 +466,7 @@ static int access_mem(unw_addr_space_t __maybe_unused as, · 84 unmodified lines
461 if (ret) {466 if (ret) {
462 pr_debug("unwind: access_mem %p not inside range"467 pr_debug("unwind: access_mem %p not inside range"
463 " 0x%" PRIx64 "-0x%" PRIx64 "\n",468 " 0x%" PRIx64 "-0x%" PRIx64 "\n",
464 (void *) addr, start, end);469 (void *) (uintptr_t) addr, start, end);
465 *valp = 0;470 *valp = 0;
466 return ret;471 return ret;
467 }472 }
@@ -471,7 +476,7 @@ static int access_mem(unw_addr_space_t __maybe_unused as, · 3 unmodified lines
471 offset = addr - start;476 offset = addr - start;
472 *valp = *(unw_word_t *)&stack->data[offset];477 *valp = *(unw_word_t *)&stack->data[offset];
473 pr_debug("unwind: access_mem addr %p val %lx, offset %d\n",478 pr_debug("unwind: access_mem addr %p val %lx, offset %d\n",
474 (void *) addr, (unsigned long)*valp, offset);479 (void *) (uintptr_t) addr, (unsigned long)*valp, offset);
475 return 0;480 return 0;
476}481}
477 482
tools/perf/util/usage.c+5−0
@@ -50,6 +50,11 @@ void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN) · 49 unmodified lines
50 die_routine = routine;50 die_routine = routine;
51}51}
52 52
53void set_warning_routine(void (*routine)(const char *err, va_list params))
54{
55 warn_routine = routine;
56}
57
53void usage(const char *err)58void usage(const char *err)
54{59{
55 usage_routine(err);60 usage_routine(err);
tools/perf/util/util.c+1−71
@@ -17,7 +17,7 @@ · 16 unmodified lines
17#include "callchain.h"17#include "callchain.h"
18 18
19struct callchain_param callchain_param = {19struct callchain_param callchain_param = {
20 .mode = CHAIN_GRAPH_REL,20 .mode = CHAIN_GRAPH_ABS,
21 .min_percent = 0.5,21 .min_percent = 0.5,
22 .order = ORDER_CALLEE,22 .order = ORDER_CALLEE,
23 .key = CCKEY_FUNCTION23 .key = CCKEY_FUNCTION
@@ -34,9 +34,6 @@ bool test_attr__enabled; · 10 unmodified lines
34bool perf_host = true;34bool perf_host = true;
35bool perf_guest = false;35bool perf_guest = false;
36 36
37char tracing_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing";
38char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";
39
40void event_attr_init(struct perf_event_attr *attr)37void event_attr_init(struct perf_event_attr *attr)
41{38{
42 if (!perf_host)39 if (!perf_host)
@@ -390,73 +387,6 @@ void set_term_quiet_input(struct termios *old) · 347 unmodified lines
390 tcsetattr(0, TCSANOW, &tc);387 tcsetattr(0, TCSANOW, &tc);
391}388}
392 389
393static void set_tracing_events_path(const char *tracing, const char *mountpoint)
394{
395 snprintf(tracing_path, sizeof(tracing_path), "%s/%s",
396 mountpoint, tracing);
397 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
398 mountpoint, tracing, "events");
399}
400
401static const char *__perf_tracefs_mount(const char *mountpoint)
402{
403 const char *mnt;
404
405 mnt = tracefs_mount(mountpoint);
406 if (!mnt)
407 return NULL;
408
409 set_tracing_events_path("", mnt);
410
411 return mnt;
412}
413
414static const char *__perf_debugfs_mount(const char *mountpoint)
415{
416 const char *mnt;
417
418 mnt = debugfs_mount(mountpoint);
419 if (!mnt)
420 return NULL;
421
422 set_tracing_events_path("tracing/", mnt);
423
424 return mnt;
425}
426
427const char *perf_debugfs_mount(const char *mountpoint)
428{
429 const char *mnt;
430
431 mnt = __perf_tracefs_mount(mountpoint);
432 if (mnt)
433 return mnt;
434
435 mnt = __perf_debugfs_mount(mountpoint);
436
437 return mnt;
438}
439
440void perf_debugfs_set_path(const char *mntpt)
441{
442 set_tracing_events_path("tracing/", mntpt);
443}
444
445char *get_tracing_file(const char *name)
446{
447 char *file;
448
449 if (asprintf(&file, "%s/%s", tracing_path, name) < 0)
450 return NULL;
451
452 return file;
453}
454
455void put_tracing_file(char *file)
456{
457 free(file);
458}
459
460int parse_nsec_time(const char *str, u64 *ptime)390int parse_nsec_time(const char *str, u64 *ptime)
461{391{
462 u64 time_sec, time_nsec;392 u64 time_sec, time_nsec;
tools/perf/util/util.h+4−8
@@ -74,8 +74,7 @@ · 73 unmodified lines
74#include <linux/magic.h>74#include <linux/magic.h>
75#include <linux/types.h>75#include <linux/types.h>
76#include <sys/ttydefaults.h>76#include <sys/ttydefaults.h>
77#include <api/fs/debugfs.h>77#include <api/fs/tracing_path.h>
78#include <api/fs/tracefs.h>
79#include <termios.h>78#include <termios.h>
80#include <linux/bitops.h>79#include <linux/bitops.h>
81#include <termios.h>80#include <termios.h>
@@ -83,12 +82,6 @@ · 1 unmodified line
83extern const char *graph_line;82extern const char *graph_line;
84extern const char *graph_dotted_line;83extern const char *graph_dotted_line;
85extern char buildid_dir[];84extern char buildid_dir[];
86extern char tracing_path[];
87extern char tracing_events_path[];
88extern void perf_debugfs_set_path(const char *mountpoint);
89const char *perf_debugfs_mount(const char *mountpoint);
90char *get_tracing_file(const char *name);
91void put_tracing_file(char *file);
92 85
93/* On most systems <limits.h> would have given us this, but86/* On most systems <limits.h> would have given us this, but
94 * not on some systems (e.g. GNU/Hurd).87 * not on some systems (e.g. GNU/Hurd).
@@ -152,6 +145,7 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))) · 57 unmodified lines
152 145
153 146
154extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);147extern void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN);
148extern void set_warning_routine(void (*routine)(const char *err, va_list params));
155 149
156extern int prefixcmp(const char *str, const char *prefix);150extern int prefixcmp(const char *str, const char *prefix);
157extern void set_buildid_dir(const char *dir);151extern void set_buildid_dir(const char *dir);
@@ -321,6 +315,8 @@ struct symbol; · 163 unmodified lines
321extern bool srcline_full_filename;315extern bool srcline_full_filename;
322char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,316char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
323 bool show_sym);317 bool show_sym);
318char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
319 bool show_sym, bool unwind_inlines);
324void free_srcline(char *srcline);320void free_srcline(char *srcline);
325 321
326int filename__read_str(const char *filename, char **buf, size_t *sizep);322int filename__read_str(const char *filename, char **buf, size_t *sizep);
tools/vm/page-types.c+3−3
@@ -42,7 +42,7 @@ · 41 unmodified lines
42#include <sys/mman.h>42#include <sys/mman.h>
43#include "../../include/uapi/linux/magic.h"43#include "../../include/uapi/linux/magic.h"
44#include "../../include/uapi/linux/kernel-page-flags.h"44#include "../../include/uapi/linux/kernel-page-flags.h"
45#include <api/fs/debugfs.h>45#include <api/fs/fs.h>
46 46
47#ifndef MAX_PATH47#ifndef MAX_PATH
48# define MAX_PATH 25648# define MAX_PATH 256
@@ -188,7 +188,7 @@ static int kpageflags_fd; · 139 unmodified lines
188static int opt_hwpoison;188static int opt_hwpoison;
189static int opt_unpoison;189static int opt_unpoison;
190 190
191static char *hwpoison_debug_fs;191static const char *hwpoison_debug_fs;
192static int hwpoison_inject_fd;192static int hwpoison_inject_fd;
193static int hwpoison_forget_fd;193static int hwpoison_forget_fd;
194 194
@@ -487,7 +487,7 @@ static void prepare_hwpoison_fd(void) · 292 unmodified lines
487{487{
488 char buf[MAX_PATH + 1];488 char buf[MAX_PATH + 1];
489 489
490 hwpoison_debug_fs = debugfs_mount(NULL);490 hwpoison_debug_fs = debugfs__mount();
491 if (!hwpoison_debug_fs) {491 if (!hwpoison_debug_fs) {
492 perror("mount debugfs");492 perror("mount debugfs");
493 exit(EXIT_FAILURE);493 exit(EXIT_FAILURE);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t