summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-10-23 08:32:18 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-10-23 08:32:18 -0400
commitc05f3642f4304dd081876e77a68555b6aba4483f (patch)
tree915baf10c3518d162c00e62b5d855cf92282ed79
parent0200fbdd431519d730b5d399a12840ec832b27cc (diff)
parentdda93b45389f025fd3422d22cc31cc1ea6040305 (diff)
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "The main updates in this cycle were: - Lots of perf tooling changes too voluminous to list (big perf trace and perf stat improvements, lots of libtraceevent reorganization, etc.), so I'll list the authors and refer to the changelog for details: Benjamin Peterson, Jérémie Galarneau, Kim Phillips, Peter Zijlstra, Ravi Bangoria, Sangwon Hong, Sean V Kelley, Steven Rostedt, Thomas Gleixner, Ding Xiang, Eduardo Habkost, Thomas Richter, Andi Kleen, Sanskriti Sharma, Adrian Hunter, Tzvetomir Stoyanov, Arnaldo Carvalho de Melo, Jiri Olsa. ... with the bulk of the changes written by Jiri Olsa, Tzvetomir Stoyanov and Arnaldo Carvalho de Melo. - Continued intel_rdt work with a focus on playing well with perf events. This also imported some non-perf RDT work due to dependencies. (Reinette Chatre) - Implement counter freezing for Arch Perfmon v4 (Skylake and newer). This allows to speed up the PMI handler by avoiding unnecessary MSR writes and make it more accurate. (Andi Kleen) - kprobes cleanups and simplification (Masami Hiramatsu) - Intel Goldmont PMU updates (Kan Liang) - ... plus misc other fixes and updates" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (155 commits) kprobes/x86: Use preempt_enable() in optimized_callback() x86/intel_rdt: Prevent pseudo-locking from using stale pointers kprobes, x86/ptrace.h: Make regs_get_kernel_stack_nth() not fault on bad stack perf/x86/intel: Export mem events only if there's PEBS support x86/cpu: Drop pointless static qualifier in punit_dev_state_show() x86/intel_rdt: Fix initial allocation to consider CDP x86/intel_rdt: CBM overlap should also check for overlap with CDP peer x86/intel_rdt: Introduce utility to obtain CDP peer tools lib traceevent, perf tools: Move struct tep_handler definition in a local header file tools lib traceevent: Separate out tep_strerror() for strerror_r() issues perf python: More portable way to make CFLAGS work with clang perf python: Make clang_has_option() work on Python 3 perf tools: Free temporary 'sys' string in read_event_files() perf tools: Avoid double free in read_event_file() perf tools: Free 'printk' string in parse_ftrace_printk() perf tools: Cleanup trace-event-info 'tdata' leak perf strbuf: Match va_{add,copy} with va_end perf test: S390 does not support watchpoints in test 22 perf auxtrace: Include missing asm/bitsperlong.h to get BITS_PER_LONG tools include: Adopt linux/bits.h ...
-rw-r--r--Documentation/admin-guide/kernel-parameters.txt5
-rw-r--r--Documentation/x86/intel_rdt_ui.txt22
-rw-r--r--arch/x86/events/core.c37
-rw-r--r--arch/x86/events/intel/core.c346
-rw-r--r--arch/x86/events/intel/cstate.c8
-rw-r--r--arch/x86/events/intel/pt.c2
-rw-r--r--arch/x86/events/intel/rapl.c4
-rw-r--r--arch/x86/events/msr.c8
-rw-r--r--arch/x86/events/perf_event.h4
-rw-r--r--arch/x86/include/asm/intel-family.h33
-rw-r--r--arch/x86/include/asm/msr-index.h1
-rw-r--r--arch/x86/include/asm/perf_event.h1
-rw-r--r--arch/x86/include/asm/ptrace.h42
-rw-r--r--arch/x86/kernel/cpu/common.c28
-rw-r--r--arch/x86/kernel/cpu/intel_rdt.c17
-rw-r--r--arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c12
-rw-r--r--arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c385
-rw-r--r--arch/x86/kernel/cpu/intel_rdt_rdtgroup.c176
-rw-r--r--arch/x86/kernel/kprobes/opt.c2
-rw-r--r--arch/x86/kernel/tsc.c2
-rw-r--r--arch/x86/kernel/tsc_msr.c10
-rw-r--r--arch/x86/platform/atom/punit_atom_debug.c6
-rw-r--r--arch/x86/platform/intel-mid/device_libs/platform_bt.c2
-rw-r--r--drivers/acpi/acpi_lpss.c2
-rw-r--r--drivers/acpi/x86/utils.c2
-rw-r--r--drivers/cpufreq/intel_pstate.c4
-rw-r--r--drivers/edac/pnd2_edac.c2
-rw-r--r--drivers/idle/intel_idle.c18
-rw-r--r--drivers/mmc/host/sdhci-acpi.c2
-rw-r--r--drivers/pci/pci-mid.c4
-rw-r--r--drivers/platform/x86/intel_int0002_vgpio.c2
-rw-r--r--drivers/platform/x86/intel_mid_powerbtn.c4
-rw-r--r--drivers/platform/x86/intel_telemetry_debugfs.c2
-rw-r--r--drivers/platform/x86/intel_telemetry_pltdrv.c2
-rw-r--r--drivers/powercap/intel_rapl.c10
-rw-r--r--drivers/thermal/intel_soc_dts_thermal.c2
-rw-r--r--kernel/events/ring_buffer.c14
-rw-r--r--kernel/kprobes.c39
-rw-r--r--sound/soc/intel/boards/bytcr_rt5651.c2
-rw-r--r--tools/include/linux/bitops.h7
-rw-r--r--tools/include/linux/bits.h26
-rw-r--r--tools/include/linux/err.h7
-rw-r--r--tools/lib/subcmd/pager.c11
-rw-r--r--tools/lib/subcmd/pager.h1
-rw-r--r--tools/lib/traceevent/Build2
-rw-r--r--tools/lib/traceevent/event-parse-api.c275
-rw-r--r--tools/lib/traceevent/event-parse-local.h92
-rw-r--r--tools/lib/traceevent/event-parse.c1217
-rw-r--r--tools/lib/traceevent/event-parse.h782
-rw-r--r--tools/lib/traceevent/event-plugin.c20
-rw-r--r--tools/lib/traceevent/parse-filter.c647
-rw-r--r--tools/lib/traceevent/plugin_function.c3
-rw-r--r--tools/lib/traceevent/plugin_hrtimer.c5
-rw-r--r--tools/lib/traceevent/plugin_jbd2.c1
-rw-r--r--tools/lib/traceevent/plugin_kmem.c5
-rw-r--r--tools/lib/traceevent/plugin_kvm.c15
-rw-r--r--tools/lib/traceevent/plugin_mac80211.c7
-rw-r--r--tools/lib/traceevent/plugin_sched_switch.c11
-rw-r--r--tools/lib/traceevent/plugin_scsi.c1
-rw-r--r--tools/lib/traceevent/plugin_xen.c1
-rw-r--r--tools/lib/traceevent/tep_strerror.c53
-rw-r--r--tools/lib/traceevent/trace-seq.c2
-rw-r--r--tools/lib/traceevent/trace-seq.h55
-rw-r--r--tools/perf/Makefile.perf4
-rw-r--r--tools/perf/arch/arm64/annotate/instructions.c59
-rw-r--r--tools/perf/arch/s390/annotate/instructions.c2
-rw-r--r--tools/perf/builtin-annotate.c7
-rw-r--r--tools/perf/builtin-inject.c40
-rw-r--r--tools/perf/builtin-record.c53
-rw-r--r--tools/perf/builtin-report.c11
-rw-r--r--tools/perf/builtin-script.c110
-rw-r--r--tools/perf/builtin-stat.c1463
-rw-r--r--tools/perf/builtin-trace.c179
-rwxr-xr-xtools/perf/check-headers.sh1
-rw-r--r--tools/perf/command-list.txt1
-rw-r--r--tools/perf/examples/bpf/augmented_syscalls.c154
-rw-r--r--tools/perf/examples/bpf/etcsnoop.c80
-rw-r--r--tools/perf/include/bpf/bpf.h3
-rw-r--r--tools/perf/include/bpf/linux/socket.h24
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/branch.json23
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/bus.json26
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/cache.json191
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/clock.json20
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json32
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/exception.json50
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/instruction.json89
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/intrinsic.json14
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/memory.json29
-rw-r--r--tools/perf/pmu-events/arch/arm64/ampere/emag/pipeline.json50
-rw-r--r--tools/perf/tests/Build1
-rw-r--r--tools/perf/tests/builtin-test.c10
-rw-r--r--tools/perf/tests/evsel-tp-sched.c4
-rwxr-xr-xtools/perf/tests/shell/record+probe_libc_inet_pton.sh2
-rw-r--r--tools/perf/tests/tests.h4
-rw-r--r--tools/perf/tests/wp.c241
-rw-r--r--tools/perf/trace/beauty/Build1
-rw-r--r--tools/perf/trace/beauty/beauty.h34
-rw-r--r--tools/perf/trace/beauty/sockaddr.c76
-rw-r--r--tools/perf/util/Build1
-rw-r--r--tools/perf/util/auxtrace.c30
-rw-r--r--tools/perf/util/auxtrace.h41
-rw-r--r--tools/perf/util/bpf-loader.c2
-rw-r--r--tools/perf/util/data-convert-bt.c58
-rw-r--r--tools/perf/util/db-export.c22
-rw-r--r--tools/perf/util/evsel.c39
-rw-r--r--tools/perf/util/evsel.h11
-rw-r--r--tools/perf/util/evsel_fprintf.c2
-rw-r--r--tools/perf/util/header.c24
-rw-r--r--tools/perf/util/header.h17
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-decoder.c34
-rw-r--r--tools/perf/util/intel-pt-decoder/intel-pt-decoder.h2
-rw-r--r--tools/perf/util/intel-pt.c5
-rw-r--r--tools/perf/util/llvm-utils.c2
-rw-r--r--tools/perf/util/map.c15
-rw-r--r--tools/perf/util/mmap.c6
-rw-r--r--tools/perf/util/mmap.h2
-rw-r--r--tools/perf/util/ordered-events.c87
-rw-r--r--tools/perf/util/ordered-events.h37
-rw-r--r--tools/perf/util/python.c20
-rw-r--r--tools/perf/util/s390-cpumsf.c94
-rw-r--r--tools/perf/util/scripting-engines/trace-event-perl.c66
-rw-r--r--tools/perf/util/scripting-engines/trace-event-python.c100
-rw-r--r--tools/perf/util/session.c75
-rw-r--r--tools/perf/util/session.h5
-rw-r--r--tools/perf/util/setup.py16
-rw-r--r--tools/perf/util/sort.c22
-rw-r--r--tools/perf/util/stat-display.c1166
-rw-r--r--tools/perf/util/stat-shadow.c147
-rw-r--r--tools/perf/util/stat.c100
-rw-r--r--tools/perf/util/stat.h77
-rw-r--r--tools/perf/util/strbuf.c10
-rw-r--r--tools/perf/util/thread-stack.c51
-rw-r--r--tools/perf/util/tool.h7
-rw-r--r--tools/perf/util/trace-event-info.c2
-rw-r--r--tools/perf/util/trace-event-parse.c44
-rw-r--r--tools/perf/util/trace-event-read.c15
-rw-r--r--tools/perf/util/trace-event.c8
-rw-r--r--tools/perf/util/trace-event.h21
-rw-r--r--tools/perf/util/util.c2
-rw-r--r--tools/perf/util/util.h2
-rw-r--r--tools/power/x86/turbostat/turbostat.c46
141 files changed, 6261 insertions, 3870 deletions
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index e9054fd1d0d0..4c74a2f4ddfc 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -856,6 +856,11 @@
856 causing system reset or hang due to sending 856 causing system reset or hang due to sending
857 INIT from AP to BSP. 857 INIT from AP to BSP.
858 858
859 disable_counter_freezing [HW]
860 Disable Intel PMU counter freezing feature.
861 The feature only exists starting from
862 Arch Perfmon v4 (Skylake and newer).
863
859 disable_ddw [PPC/PSERIES] 864 disable_ddw [PPC/PSERIES]
860 Disable Dynamic DMA Window support. Use this if 865 Disable Dynamic DMA Window support. Use this if
861 to workaround buggy firmware. 866 to workaround buggy firmware.
diff --git a/Documentation/x86/intel_rdt_ui.txt b/Documentation/x86/intel_rdt_ui.txt
index f662d3c530e5..52b10945ff75 100644
--- a/Documentation/x86/intel_rdt_ui.txt
+++ b/Documentation/x86/intel_rdt_ui.txt
@@ -520,18 +520,24 @@ the pseudo-locked region:
5202) Cache hit and miss measurements using model specific precision counters if 5202) Cache hit and miss measurements using model specific precision counters if
521 available. Depending on the levels of cache on the system the pseudo_lock_l2 521 available. Depending on the levels of cache on the system the pseudo_lock_l2
522 and pseudo_lock_l3 tracepoints are available. 522 and pseudo_lock_l3 tracepoints are available.
523 WARNING: triggering this measurement uses from two (for just L2
524 measurements) to four (for L2 and L3 measurements) precision counters on
525 the system, if any other measurements are in progress the counters and
526 their corresponding event registers will be clobbered.
527 523
528When a pseudo-locked region is created a new debugfs directory is created for 524When a pseudo-locked region is created a new debugfs directory is created for
529it in debugfs as /sys/kernel/debug/resctrl/<newdir>. A single 525it in debugfs as /sys/kernel/debug/resctrl/<newdir>. A single
530write-only file, pseudo_lock_measure, is present in this directory. The 526write-only file, pseudo_lock_measure, is present in this directory. The
531measurement on the pseudo-locked region depends on the number, 1 or 2, 527measurement of the pseudo-locked region depends on the number written to this
532written to this debugfs file. Since the measurements are recorded with the 528debugfs file:
533tracing infrastructure the relevant tracepoints need to be enabled before the 5291 - writing "1" to the pseudo_lock_measure file will trigger the latency
534measurement is triggered. 530 measurement captured in the pseudo_lock_mem_latency tracepoint. See
531 example below.
5322 - writing "2" to the pseudo_lock_measure file will trigger the L2 cache
533 residency (cache hits and misses) measurement captured in the
534 pseudo_lock_l2 tracepoint. See example below.
5353 - writing "3" to the pseudo_lock_measure file will trigger the L3 cache
536 residency (cache hits and misses) measurement captured in the
537 pseudo_lock_l3 tracepoint.
538
539All measurements are recorded with the tracing infrastructure. This requires
540the relevant tracepoints to be enabled before the measurement is triggered.
535 541
536Example of latency debugging interface: 542Example of latency debugging interface:
537In this example a pseudo-locked region named "newlock" was created. Here is 543In this example a pseudo-locked region named "newlock" was created. Here is
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index dfb2f7c0d019..de32741d041a 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1033,6 +1033,27 @@ static inline void x86_assign_hw_event(struct perf_event *event,
1033 } 1033 }
1034} 1034}
1035 1035
1036/**
1037 * x86_perf_rdpmc_index - Return PMC counter used for event
1038 * @event: the perf_event to which the PMC counter was assigned
1039 *
1040 * The counter assigned to this performance event may change if interrupts
1041 * are enabled. This counter should thus never be used while interrupts are
1042 * enabled. Before this function is used to obtain the assigned counter the
1043 * event should be checked for validity using, for example,
1044 * perf_event_read_local(), within the same interrupt disabled section in
1045 * which this counter is planned to be used.
1046 *
1047 * Return: The index of the performance monitoring counter assigned to
1048 * @perf_event.
1049 */
1050int x86_perf_rdpmc_index(struct perf_event *event)
1051{
1052 lockdep_assert_irqs_disabled();
1053
1054 return event->hw.event_base_rdpmc;
1055}
1056
1036static inline int match_prev_assignment(struct hw_perf_event *hwc, 1057static inline int match_prev_assignment(struct hw_perf_event *hwc,
1037 struct cpu_hw_events *cpuc, 1058 struct cpu_hw_events *cpuc,
1038 int i) 1059 int i)
@@ -1584,7 +1605,7 @@ static void __init pmu_check_apic(void)
1584 1605
1585} 1606}
1586 1607
1587static struct attribute_group x86_pmu_format_group = { 1608static struct attribute_group x86_pmu_format_group __ro_after_init = {
1588 .name = "format", 1609 .name = "format",
1589 .attrs = NULL, 1610 .attrs = NULL,
1590}; 1611};
@@ -1631,9 +1652,9 @@ __init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
1631 struct attribute **new; 1652 struct attribute **new;
1632 int j, i; 1653 int j, i;
1633 1654
1634 for (j = 0; a[j]; j++) 1655 for (j = 0; a && a[j]; j++)
1635 ; 1656 ;
1636 for (i = 0; b[i]; i++) 1657 for (i = 0; b && b[i]; i++)
1637 j++; 1658 j++;
1638 j++; 1659 j++;
1639 1660
@@ -1642,9 +1663,9 @@ __init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
1642 return NULL; 1663 return NULL;
1643 1664
1644 j = 0; 1665 j = 0;
1645 for (i = 0; a[i]; i++) 1666 for (i = 0; a && a[i]; i++)
1646 new[j++] = a[i]; 1667 new[j++] = a[i];
1647 for (i = 0; b[i]; i++) 1668 for (i = 0; b && b[i]; i++)
1648 new[j++] = b[i]; 1669 new[j++] = b[i];
1649 new[j] = NULL; 1670 new[j] = NULL;
1650 1671
@@ -1715,7 +1736,7 @@ static struct attribute *events_attr[] = {
1715 NULL, 1736 NULL,
1716}; 1737};
1717 1738
1718static struct attribute_group x86_pmu_events_group = { 1739static struct attribute_group x86_pmu_events_group __ro_after_init = {
1719 .name = "events", 1740 .name = "events",
1720 .attrs = events_attr, 1741 .attrs = events_attr,
1721}; 1742};
@@ -2230,7 +2251,7 @@ static struct attribute *x86_pmu_attrs[] = {
2230 NULL, 2251 NULL,
2231}; 2252};
2232 2253
2233static struct attribute_group x86_pmu_attr_group = { 2254static struct attribute_group x86_pmu_attr_group __ro_after_init = {
2234 .attrs = x86_pmu_attrs, 2255 .attrs = x86_pmu_attrs,
2235}; 2256};
2236 2257
@@ -2248,7 +2269,7 @@ static struct attribute *x86_pmu_caps_attrs[] = {
2248 NULL 2269 NULL
2249}; 2270};
2250 2271
2251static struct attribute_group x86_pmu_caps_group = { 2272static struct attribute_group x86_pmu_caps_group __ro_after_init = {
2252 .name = "caps", 2273 .name = "caps",
2253 .attrs = x86_pmu_caps_attrs, 2274 .attrs = x86_pmu_caps_attrs,
2254}; 2275};
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 035c37481f57..0fb8659b20d8 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -242,7 +242,7 @@ EVENT_ATTR_STR(mem-loads, mem_ld_nhm, "event=0x0b,umask=0x10,ldlat=3");
242EVENT_ATTR_STR(mem-loads, mem_ld_snb, "event=0xcd,umask=0x1,ldlat=3"); 242EVENT_ATTR_STR(mem-loads, mem_ld_snb, "event=0xcd,umask=0x1,ldlat=3");
243EVENT_ATTR_STR(mem-stores, mem_st_snb, "event=0xcd,umask=0x2"); 243EVENT_ATTR_STR(mem-stores, mem_st_snb, "event=0xcd,umask=0x2");
244 244
245static struct attribute *nhm_events_attrs[] = { 245static struct attribute *nhm_mem_events_attrs[] = {
246 EVENT_PTR(mem_ld_nhm), 246 EVENT_PTR(mem_ld_nhm),
247 NULL, 247 NULL,
248}; 248};
@@ -278,8 +278,6 @@ EVENT_ATTR_STR_HT(topdown-recovery-bubbles.scale, td_recovery_bubbles_scale,
278 "4", "2"); 278 "4", "2");
279 279
280static struct attribute *snb_events_attrs[] = { 280static struct attribute *snb_events_attrs[] = {
281 EVENT_PTR(mem_ld_snb),
282 EVENT_PTR(mem_st_snb),
283 EVENT_PTR(td_slots_issued), 281 EVENT_PTR(td_slots_issued),
284 EVENT_PTR(td_slots_retired), 282 EVENT_PTR(td_slots_retired),
285 EVENT_PTR(td_fetch_bubbles), 283 EVENT_PTR(td_fetch_bubbles),
@@ -290,6 +288,12 @@ static struct attribute *snb_events_attrs[] = {
290 NULL, 288 NULL,
291}; 289};
292 290
291static struct attribute *snb_mem_events_attrs[] = {
292 EVENT_PTR(mem_ld_snb),
293 EVENT_PTR(mem_st_snb),
294 NULL,
295};
296
293static struct event_constraint intel_hsw_event_constraints[] = { 297static struct event_constraint intel_hsw_event_constraints[] = {
294 FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ 298 FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
295 FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ 299 FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
@@ -1995,6 +1999,18 @@ static void intel_pmu_nhm_enable_all(int added)
1995 intel_pmu_enable_all(added); 1999 intel_pmu_enable_all(added);
1996} 2000}
1997 2001
2002static void enable_counter_freeze(void)
2003{
2004 update_debugctlmsr(get_debugctlmsr() |
2005 DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI);
2006}
2007
2008static void disable_counter_freeze(void)
2009{
2010 update_debugctlmsr(get_debugctlmsr() &
2011 ~DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI);
2012}
2013
1998static inline u64 intel_pmu_get_status(void) 2014static inline u64 intel_pmu_get_status(void)
1999{ 2015{
2000 u64 status; 2016 u64 status;
@@ -2200,59 +2216,15 @@ static void intel_pmu_reset(void)
2200 local_irq_restore(flags); 2216 local_irq_restore(flags);
2201} 2217}
2202 2218
2203/* 2219static int handle_pmi_common(struct pt_regs *regs, u64 status)
2204 * This handler is triggered by the local APIC, so the APIC IRQ handling
2205 * rules apply:
2206 */
2207static int intel_pmu_handle_irq(struct pt_regs *regs)
2208{ 2220{
2209 struct perf_sample_data data; 2221 struct perf_sample_data data;
2210 struct cpu_hw_events *cpuc; 2222 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2211 int bit, loops; 2223 int bit;
2212 u64 status; 2224 int handled = 0;
2213 int handled;
2214 int pmu_enabled;
2215
2216 cpuc = this_cpu_ptr(&cpu_hw_events);
2217
2218 /*
2219 * Save the PMU state.
2220 * It needs to be restored when leaving the handler.
2221 */
2222 pmu_enabled = cpuc->enabled;
2223 /*
2224 * No known reason to not always do late ACK,
2225 * but just in case do it opt-in.
2226 */
2227 if (!x86_pmu.late_ack)
2228 apic_write(APIC_LVTPC, APIC_DM_NMI);
2229 intel_bts_disable_local();
2230 cpuc->enabled = 0;
2231 __intel_pmu_disable_all();
2232 handled = intel_pmu_drain_bts_buffer();
2233 handled += intel_bts_interrupt();
2234 status = intel_pmu_get_status();
2235 if (!status)
2236 goto done;
2237
2238 loops = 0;
2239again:
2240 intel_pmu_lbr_read();
2241 intel_pmu_ack_status(status);
2242 if (++loops > 100) {
2243 static bool warned = false;
2244 if (!warned) {
2245 WARN(1, "perfevents: irq loop stuck!\n");
2246 perf_event_print_debug();
2247 warned = true;
2248 }
2249 intel_pmu_reset();
2250 goto done;
2251 }
2252 2225
2253 inc_irq_stat(apic_perf_irqs); 2226 inc_irq_stat(apic_perf_irqs);
2254 2227
2255
2256 /* 2228 /*
2257 * Ignore a range of extra bits in status that do not indicate 2229 * Ignore a range of extra bits in status that do not indicate
2258 * overflow by themselves. 2230 * overflow by themselves.
@@ -2261,7 +2233,7 @@ again:
2261 GLOBAL_STATUS_ASIF | 2233 GLOBAL_STATUS_ASIF |
2262 GLOBAL_STATUS_LBRS_FROZEN); 2234 GLOBAL_STATUS_LBRS_FROZEN);
2263 if (!status) 2235 if (!status)
2264 goto done; 2236 return 0;
2265 /* 2237 /*
2266 * In case multiple PEBS events are sampled at the same time, 2238 * In case multiple PEBS events are sampled at the same time,
2267 * it is possible to have GLOBAL_STATUS bit 62 set indicating 2239 * it is possible to have GLOBAL_STATUS bit 62 set indicating
@@ -2331,6 +2303,146 @@ again:
2331 x86_pmu_stop(event, 0); 2303 x86_pmu_stop(event, 0);
2332 } 2304 }
2333 2305
2306 return handled;
2307}
2308
2309static bool disable_counter_freezing;
2310static int __init intel_perf_counter_freezing_setup(char *s)
2311{
2312 disable_counter_freezing = true;
2313 pr_info("Intel PMU Counter freezing feature disabled\n");
2314 return 1;
2315}
2316__setup("disable_counter_freezing", intel_perf_counter_freezing_setup);
2317
2318/*
2319 * Simplified handler for Arch Perfmon v4:
2320 * - We rely on counter freezing/unfreezing to enable/disable the PMU.
2321 * This is done automatically on PMU ack.
2322 * - Ack the PMU only after the APIC.
2323 */
2324
2325static int intel_pmu_handle_irq_v4(struct pt_regs *regs)
2326{
2327 struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
2328 int handled = 0;
2329 bool bts = false;
2330 u64 status;
2331 int pmu_enabled = cpuc->enabled;
2332 int loops = 0;
2333
2334 /* PMU has been disabled because of counter freezing */
2335 cpuc->enabled = 0;
2336 if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) {
2337 bts = true;
2338 intel_bts_disable_local();
2339 handled = intel_pmu_drain_bts_buffer();
2340 handled += intel_bts_interrupt();
2341 }
2342 status = intel_pmu_get_status();
2343 if (!status)
2344 goto done;
2345again:
2346 intel_pmu_lbr_read();
2347 if (++loops > 100) {
2348 static bool warned;
2349
2350 if (!warned) {
2351 WARN(1, "perfevents: irq loop stuck!\n");
2352 perf_event_print_debug();
2353 warned = true;
2354 }
2355 intel_pmu_reset();
2356 goto done;
2357 }
2358
2359
2360 handled += handle_pmi_common(regs, status);
2361done:
2362 /* Ack the PMI in the APIC */
2363 apic_write(APIC_LVTPC, APIC_DM_NMI);
2364
2365 /*
2366 * The counters start counting immediately while ack the status.
2367 * Make it as close as possible to IRET. This avoids bogus
2368 * freezing on Skylake CPUs.
2369 */
2370 if (status) {
2371 intel_pmu_ack_status(status);
2372 } else {
2373 /*
2374 * CPU may issues two PMIs very close to each other.
2375 * When the PMI handler services the first one, the
2376 * GLOBAL_STATUS is already updated to reflect both.
2377 * When it IRETs, the second PMI is immediately
2378 * handled and it sees clear status. At the meantime,
2379 * there may be a third PMI, because the freezing bit
2380 * isn't set since the ack in first PMI handlers.
2381 * Double check if there is more work to be done.
2382 */
2383 status = intel_pmu_get_status();
2384 if (status)
2385 goto again;
2386 }
2387
2388 if (bts)
2389 intel_bts_enable_local();
2390 cpuc->enabled = pmu_enabled;
2391 return handled;
2392}
2393
2394/*
2395 * This handler is triggered by the local APIC, so the APIC IRQ handling
2396 * rules apply:
2397 */
2398static int intel_pmu_handle_irq(struct pt_regs *regs)
2399{
2400 struct cpu_hw_events *cpuc;
2401 int loops;
2402 u64 status;
2403 int handled;
2404 int pmu_enabled;
2405
2406 cpuc = this_cpu_ptr(&cpu_hw_events);
2407
2408 /*
2409 * Save the PMU state.
2410 * It needs to be restored when leaving the handler.
2411 */
2412 pmu_enabled = cpuc->enabled;
2413 /*
2414 * No known reason to not always do late ACK,
2415 * but just in case do it opt-in.
2416 */
2417 if (!x86_pmu.late_ack)
2418 apic_write(APIC_LVTPC, APIC_DM_NMI);
2419 intel_bts_disable_local();
2420 cpuc->enabled = 0;
2421 __intel_pmu_disable_all();
2422 handled = intel_pmu_drain_bts_buffer();
2423 handled += intel_bts_interrupt();
2424 status = intel_pmu_get_status();
2425 if (!status)
2426 goto done;
2427
2428 loops = 0;
2429again:
2430 intel_pmu_lbr_read();
2431 intel_pmu_ack_status(status);
2432 if (++loops > 100) {
2433 static bool warned;
2434
2435 if (!warned) {
2436 WARN(1, "perfevents: irq loop stuck!\n");
2437 perf_event_print_debug();
2438 warned = true;
2439 }
2440 intel_pmu_reset();
2441 goto done;
2442 }
2443
2444 handled += handle_pmi_common(regs, status);
2445
2334 /* 2446 /*
2335 * Repeat if there is more work to be done: 2447 * Repeat if there is more work to be done:
2336 */ 2448 */
@@ -3350,6 +3462,9 @@ static void intel_pmu_cpu_starting(int cpu)
3350 if (x86_pmu.version > 1) 3462 if (x86_pmu.version > 1)
3351 flip_smm_bit(&x86_pmu.attr_freeze_on_smi); 3463 flip_smm_bit(&x86_pmu.attr_freeze_on_smi);
3352 3464
3465 if (x86_pmu.counter_freezing)
3466 enable_counter_freeze();
3467
3353 if (!cpuc->shared_regs) 3468 if (!cpuc->shared_regs)
3354 return; 3469 return;
3355 3470
@@ -3421,6 +3536,9 @@ static void intel_pmu_cpu_dying(int cpu)
3421 free_excl_cntrs(cpu); 3536 free_excl_cntrs(cpu);
3422 3537
3423 fini_debug_store_on_cpu(cpu); 3538 fini_debug_store_on_cpu(cpu);
3539
3540 if (x86_pmu.counter_freezing)
3541 disable_counter_freeze();
3424} 3542}
3425 3543
3426static void intel_pmu_sched_task(struct perf_event_context *ctx, 3544static void intel_pmu_sched_task(struct perf_event_context *ctx,
@@ -3725,6 +3843,40 @@ static __init void intel_nehalem_quirk(void)
3725 } 3843 }
3726} 3844}
3727 3845
3846static bool intel_glp_counter_freezing_broken(int cpu)
3847{
3848 u32 rev = UINT_MAX; /* default to broken for unknown stepping */
3849
3850 switch (cpu_data(cpu).x86_stepping) {
3851 case 1:
3852 rev = 0x28;
3853 break;
3854 case 8:
3855 rev = 0x6;
3856 break;
3857 }
3858
3859 return (cpu_data(cpu).microcode < rev);
3860}
3861
3862static __init void intel_glp_counter_freezing_quirk(void)
3863{
3864 /* Check if it's already disabled */
3865 if (disable_counter_freezing)
3866 return;
3867
3868 /*
3869 * If the system starts with the wrong ucode, leave the
3870 * counter-freezing feature permanently disabled.
3871 */
3872 if (intel_glp_counter_freezing_broken(raw_smp_processor_id())) {
3873 pr_info("PMU counter freezing disabled due to CPU errata,"
3874 "please upgrade microcode\n");
3875 x86_pmu.counter_freezing = false;
3876 x86_pmu.handle_irq = intel_pmu_handle_irq;
3877 }
3878}
3879
3728/* 3880/*
3729 * enable software workaround for errata: 3881 * enable software workaround for errata:
3730 * SNB: BJ122 3882 * SNB: BJ122
@@ -3764,8 +3916,6 @@ EVENT_ATTR_STR(cycles-t, cycles_t, "event=0x3c,in_tx=1");
3764EVENT_ATTR_STR(cycles-ct, cycles_ct, "event=0x3c,in_tx=1,in_tx_cp=1"); 3916EVENT_ATTR_STR(cycles-ct, cycles_ct, "event=0x3c,in_tx=1,in_tx_cp=1");
3765 3917
3766static struct attribute *hsw_events_attrs[] = { 3918static struct attribute *hsw_events_attrs[] = {
3767 EVENT_PTR(mem_ld_hsw),
3768 EVENT_PTR(mem_st_hsw),
3769 EVENT_PTR(td_slots_issued), 3919 EVENT_PTR(td_slots_issued),
3770 EVENT_PTR(td_slots_retired), 3920 EVENT_PTR(td_slots_retired),
3771 EVENT_PTR(td_fetch_bubbles), 3921 EVENT_PTR(td_fetch_bubbles),
@@ -3776,6 +3926,12 @@ static struct attribute *hsw_events_attrs[] = {
3776 NULL 3926 NULL
3777}; 3927};
3778 3928
3929static struct attribute *hsw_mem_events_attrs[] = {
3930 EVENT_PTR(mem_ld_hsw),
3931 EVENT_PTR(mem_st_hsw),
3932 NULL,
3933};
3934
3779static struct attribute *hsw_tsx_events_attrs[] = { 3935static struct attribute *hsw_tsx_events_attrs[] = {
3780 EVENT_PTR(tx_start), 3936 EVENT_PTR(tx_start),
3781 EVENT_PTR(tx_commit), 3937 EVENT_PTR(tx_commit),
@@ -3792,13 +3948,6 @@ static struct attribute *hsw_tsx_events_attrs[] = {
3792 NULL 3948 NULL
3793}; 3949};
3794 3950
3795static __init struct attribute **get_hsw_events_attrs(void)
3796{
3797 return boot_cpu_has(X86_FEATURE_RTM) ?
3798 merge_attr(hsw_events_attrs, hsw_tsx_events_attrs) :
3799 hsw_events_attrs;
3800}
3801
3802static ssize_t freeze_on_smi_show(struct device *cdev, 3951static ssize_t freeze_on_smi_show(struct device *cdev,
3803 struct device_attribute *attr, 3952 struct device_attribute *attr,
3804 char *buf) 3953 char *buf)
@@ -3875,9 +4024,32 @@ static struct attribute *intel_pmu_attrs[] = {
3875 NULL, 4024 NULL,
3876}; 4025};
3877 4026
4027static __init struct attribute **
4028get_events_attrs(struct attribute **base,
4029 struct attribute **mem,
4030 struct attribute **tsx)
4031{
4032 struct attribute **attrs = base;
4033 struct attribute **old;
4034
4035 if (mem && x86_pmu.pebs)
4036 attrs = merge_attr(attrs, mem);
4037
4038 if (tsx && boot_cpu_has(X86_FEATURE_RTM)) {
4039 old = attrs;
4040 attrs = merge_attr(attrs, tsx);
4041 if (old != base)
4042 kfree(old);
4043 }
4044
4045 return attrs;
4046}
4047
3878__init int intel_pmu_init(void) 4048__init int intel_pmu_init(void)
3879{ 4049{
3880 struct attribute **extra_attr = NULL; 4050 struct attribute **extra_attr = NULL;
4051 struct attribute **mem_attr = NULL;
4052 struct attribute **tsx_attr = NULL;
3881 struct attribute **to_free = NULL; 4053 struct attribute **to_free = NULL;
3882 union cpuid10_edx edx; 4054 union cpuid10_edx edx;
3883 union cpuid10_eax eax; 4055 union cpuid10_eax eax;
@@ -3935,6 +4107,9 @@ __init int intel_pmu_init(void)
3935 max((int)edx.split.num_counters_fixed, assume); 4107 max((int)edx.split.num_counters_fixed, assume);
3936 } 4108 }
3937 4109
4110 if (version >= 4)
4111 x86_pmu.counter_freezing = !disable_counter_freezing;
4112
3938 if (boot_cpu_has(X86_FEATURE_PDCM)) { 4113 if (boot_cpu_has(X86_FEATURE_PDCM)) {
3939 u64 capabilities; 4114 u64 capabilities;
3940 4115
@@ -3986,7 +4161,7 @@ __init int intel_pmu_init(void)
3986 x86_pmu.enable_all = intel_pmu_nhm_enable_all; 4161 x86_pmu.enable_all = intel_pmu_nhm_enable_all;
3987 x86_pmu.extra_regs = intel_nehalem_extra_regs; 4162 x86_pmu.extra_regs = intel_nehalem_extra_regs;
3988 4163
3989 x86_pmu.cpu_events = nhm_events_attrs; 4164 mem_attr = nhm_mem_events_attrs;
3990 4165
3991 /* UOPS_ISSUED.STALLED_CYCLES */ 4166 /* UOPS_ISSUED.STALLED_CYCLES */
3992 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 4167 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4004,11 +4179,11 @@ __init int intel_pmu_init(void)
4004 name = "nehalem"; 4179 name = "nehalem";
4005 break; 4180 break;
4006 4181
4007 case INTEL_FAM6_ATOM_PINEVIEW: 4182 case INTEL_FAM6_ATOM_BONNELL:
4008 case INTEL_FAM6_ATOM_LINCROFT: 4183 case INTEL_FAM6_ATOM_BONNELL_MID:
4009 case INTEL_FAM6_ATOM_PENWELL: 4184 case INTEL_FAM6_ATOM_SALTWELL:
4010 case INTEL_FAM6_ATOM_CLOVERVIEW: 4185 case INTEL_FAM6_ATOM_SALTWELL_MID:
4011 case INTEL_FAM6_ATOM_CEDARVIEW: 4186 case INTEL_FAM6_ATOM_SALTWELL_TABLET:
4012 memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, 4187 memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
4013 sizeof(hw_cache_event_ids)); 4188 sizeof(hw_cache_event_ids));
4014 4189
@@ -4021,9 +4196,11 @@ __init int intel_pmu_init(void)
4021 name = "bonnell"; 4196 name = "bonnell";
4022 break; 4197 break;
4023 4198
4024 case INTEL_FAM6_ATOM_SILVERMONT1: 4199 case INTEL_FAM6_ATOM_SILVERMONT:
4025 case INTEL_FAM6_ATOM_SILVERMONT2: 4200 case INTEL_FAM6_ATOM_SILVERMONT_X:
4201 case INTEL_FAM6_ATOM_SILVERMONT_MID:
4026 case INTEL_FAM6_ATOM_AIRMONT: 4202 case INTEL_FAM6_ATOM_AIRMONT:
4203 case INTEL_FAM6_ATOM_AIRMONT_MID:
4027 memcpy(hw_cache_event_ids, slm_hw_cache_event_ids, 4204 memcpy(hw_cache_event_ids, slm_hw_cache_event_ids,
4028 sizeof(hw_cache_event_ids)); 4205 sizeof(hw_cache_event_ids));
4029 memcpy(hw_cache_extra_regs, slm_hw_cache_extra_regs, 4206 memcpy(hw_cache_extra_regs, slm_hw_cache_extra_regs,
@@ -4042,7 +4219,7 @@ __init int intel_pmu_init(void)
4042 break; 4219 break;
4043 4220
4044 case INTEL_FAM6_ATOM_GOLDMONT: 4221 case INTEL_FAM6_ATOM_GOLDMONT:
4045 case INTEL_FAM6_ATOM_DENVERTON: 4222 case INTEL_FAM6_ATOM_GOLDMONT_X:
4046 memcpy(hw_cache_event_ids, glm_hw_cache_event_ids, 4223 memcpy(hw_cache_event_ids, glm_hw_cache_event_ids,
4047 sizeof(hw_cache_event_ids)); 4224 sizeof(hw_cache_event_ids));
4048 memcpy(hw_cache_extra_regs, glm_hw_cache_extra_regs, 4225 memcpy(hw_cache_extra_regs, glm_hw_cache_extra_regs,
@@ -4068,7 +4245,8 @@ __init int intel_pmu_init(void)
4068 name = "goldmont"; 4245 name = "goldmont";
4069 break; 4246 break;
4070 4247
4071 case INTEL_FAM6_ATOM_GEMINI_LAKE: 4248 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
4249 x86_add_quirk(intel_glp_counter_freezing_quirk);
4072 memcpy(hw_cache_event_ids, glp_hw_cache_event_ids, 4250 memcpy(hw_cache_event_ids, glp_hw_cache_event_ids,
4073 sizeof(hw_cache_event_ids)); 4251 sizeof(hw_cache_event_ids));
4074 memcpy(hw_cache_extra_regs, glp_hw_cache_extra_regs, 4252 memcpy(hw_cache_extra_regs, glp_hw_cache_extra_regs,
@@ -4112,7 +4290,7 @@ __init int intel_pmu_init(void)
4112 x86_pmu.extra_regs = intel_westmere_extra_regs; 4290 x86_pmu.extra_regs = intel_westmere_extra_regs;
4113 x86_pmu.flags |= PMU_FL_HAS_RSP_1; 4291 x86_pmu.flags |= PMU_FL_HAS_RSP_1;
4114 4292
4115 x86_pmu.cpu_events = nhm_events_attrs; 4293 mem_attr = nhm_mem_events_attrs;
4116 4294
4117 /* UOPS_ISSUED.STALLED_CYCLES */ 4295 /* UOPS_ISSUED.STALLED_CYCLES */
4118 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 4296 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4152,6 +4330,7 @@ __init int intel_pmu_init(void)
4152 x86_pmu.flags |= PMU_FL_NO_HT_SHARING; 4330 x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
4153 4331
4154 x86_pmu.cpu_events = snb_events_attrs; 4332 x86_pmu.cpu_events = snb_events_attrs;
4333 mem_attr = snb_mem_events_attrs;
4155 4334
4156 /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */ 4335 /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
4157 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 4336 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4192,6 +4371,7 @@ __init int intel_pmu_init(void)
4192 x86_pmu.flags |= PMU_FL_NO_HT_SHARING; 4371 x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
4193 4372
4194 x86_pmu.cpu_events = snb_events_attrs; 4373 x86_pmu.cpu_events = snb_events_attrs;
4374 mem_attr = snb_mem_events_attrs;
4195 4375
4196 /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */ 4376 /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
4197 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 4377 intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4226,10 +4406,12 @@ __init int intel_pmu_init(void)
4226 4406
4227 x86_pmu.hw_config = hsw_hw_config; 4407 x86_pmu.hw_config = hsw_hw_config;
4228 x86_pmu.get_event_constraints = hsw_get_event_constraints; 4408 x86_pmu.get_event_constraints = hsw_get_event_constraints;
4229 x86_pmu.cpu_events = get_hsw_events_attrs(); 4409 x86_pmu.cpu_events = hsw_events_attrs;
4230 x86_pmu.lbr_double_abort = true; 4410 x86_pmu.lbr_double_abort = true;
4231 extra_attr = boot_cpu_has(X86_FEATURE_RTM) ? 4411 extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
4232 hsw_format_attr : nhm_format_attr; 4412 hsw_format_attr : nhm_format_attr;
4413 mem_attr = hsw_mem_events_attrs;
4414 tsx_attr = hsw_tsx_events_attrs;
4233 pr_cont("Haswell events, "); 4415 pr_cont("Haswell events, ");
4234 name = "haswell"; 4416 name = "haswell";
4235 break; 4417 break;
@@ -4265,10 +4447,12 @@ __init int intel_pmu_init(void)
4265 4447
4266 x86_pmu.hw_config = hsw_hw_config; 4448 x86_pmu.hw_config = hsw_hw_config;
4267 x86_pmu.get_event_constraints = hsw_get_event_constraints; 4449 x86_pmu.get_event_constraints = hsw_get_event_constraints;
4268 x86_pmu.cpu_events = get_hsw_events_attrs(); 4450 x86_pmu.cpu_events = hsw_events_attrs;
4269 x86_pmu.limit_period = bdw_limit_period; 4451 x86_pmu.limit_period = bdw_limit_period;
4270 extra_attr = boot_cpu_has(X86_FEATURE_RTM) ? 4452 extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
4271 hsw_format_attr : nhm_format_attr; 4453 hsw_format_attr : nhm_format_attr;
4454 mem_attr = hsw_mem_events_attrs;
4455 tsx_attr = hsw_tsx_events_attrs;
4272 pr_cont("Broadwell events, "); 4456 pr_cont("Broadwell events, ");
4273 name = "broadwell"; 4457 name = "broadwell";
4274 break; 4458 break;
@@ -4324,7 +4508,9 @@ __init int intel_pmu_init(void)
4324 hsw_format_attr : nhm_format_attr; 4508 hsw_format_attr : nhm_format_attr;
4325 extra_attr = merge_attr(extra_attr, skl_format_attr); 4509 extra_attr = merge_attr(extra_attr, skl_format_attr);
4326 to_free = extra_attr; 4510 to_free = extra_attr;
4327 x86_pmu.cpu_events = get_hsw_events_attrs(); 4511 x86_pmu.cpu_events = hsw_events_attrs;
4512 mem_attr = hsw_mem_events_attrs;
4513 tsx_attr = hsw_tsx_events_attrs;
4328 intel_pmu_pebs_data_source_skl( 4514 intel_pmu_pebs_data_source_skl(
4329 boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X); 4515 boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X);
4330 pr_cont("Skylake events, "); 4516 pr_cont("Skylake events, ");
@@ -4357,6 +4543,9 @@ __init int intel_pmu_init(void)
4357 WARN_ON(!x86_pmu.format_attrs); 4543 WARN_ON(!x86_pmu.format_attrs);
4358 } 4544 }
4359 4545
4546 x86_pmu.cpu_events = get_events_attrs(x86_pmu.cpu_events,
4547 mem_attr, tsx_attr);
4548
4360 if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) { 4549 if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) {
4361 WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", 4550 WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!",
4362 x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC); 4551 x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC);
@@ -4431,6 +4620,13 @@ __init int intel_pmu_init(void)
4431 pr_cont("full-width counters, "); 4620 pr_cont("full-width counters, ");
4432 } 4621 }
4433 4622
4623 /*
4624 * For arch perfmon 4 use counter freezing to avoid
4625 * several MSR accesses in the PMI.
4626 */
4627 if (x86_pmu.counter_freezing)
4628 x86_pmu.handle_irq = intel_pmu_handle_irq_v4;
4629
4434 kfree(to_free); 4630 kfree(to_free);
4435 return 0; 4631 return 0;
4436} 4632}
diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c
index 9f8084f18d58..d2e780705c5a 100644
--- a/arch/x86/events/intel/cstate.c
+++ b/arch/x86/events/intel/cstate.c
@@ -559,8 +559,8 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {
559 559
560 X86_CSTATES_MODEL(INTEL_FAM6_HASWELL_ULT, hswult_cstates), 560 X86_CSTATES_MODEL(INTEL_FAM6_HASWELL_ULT, hswult_cstates),
561 561
562 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT1, slm_cstates), 562 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT, slm_cstates),
563 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT2, slm_cstates), 563 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT_X, slm_cstates),
564 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_AIRMONT, slm_cstates), 564 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_AIRMONT, slm_cstates),
565 565
566 X86_CSTATES_MODEL(INTEL_FAM6_BROADWELL_CORE, snb_cstates), 566 X86_CSTATES_MODEL(INTEL_FAM6_BROADWELL_CORE, snb_cstates),
@@ -581,9 +581,9 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {
581 X86_CSTATES_MODEL(INTEL_FAM6_XEON_PHI_KNM, knl_cstates), 581 X86_CSTATES_MODEL(INTEL_FAM6_XEON_PHI_KNM, knl_cstates),
582 582
583 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT, glm_cstates), 583 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT, glm_cstates),
584 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_DENVERTON, glm_cstates), 584 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT_X, glm_cstates),
585 585
586 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GEMINI_LAKE, glm_cstates), 586 X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT_PLUS, glm_cstates),
587 { }, 587 { },
588}; 588};
589MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match); 589MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match);
diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 8d016ce5b80d..3a0aa83cbd07 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -95,7 +95,7 @@ static ssize_t pt_cap_show(struct device *cdev,
95 return snprintf(buf, PAGE_SIZE, "%x\n", pt_cap_get(cap)); 95 return snprintf(buf, PAGE_SIZE, "%x\n", pt_cap_get(cap));
96} 96}
97 97
98static struct attribute_group pt_cap_group = { 98static struct attribute_group pt_cap_group __ro_after_init = {
99 .name = "caps", 99 .name = "caps",
100}; 100};
101 101
diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index 32f3e9423e99..91039ffed633 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -777,9 +777,9 @@ static const struct x86_cpu_id rapl_cpu_match[] __initconst = {
777 X86_RAPL_MODEL_MATCH(INTEL_FAM6_CANNONLAKE_MOBILE, skl_rapl_init), 777 X86_RAPL_MODEL_MATCH(INTEL_FAM6_CANNONLAKE_MOBILE, skl_rapl_init),
778 778
779 X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT, hsw_rapl_init), 779 X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT, hsw_rapl_init),
780 X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_DENVERTON, hsw_rapl_init), 780 X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT_X, hsw_rapl_init),
781 781
782 X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GEMINI_LAKE, hsw_rapl_init), 782 X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT_PLUS, hsw_rapl_init),
783 {}, 783 {},
784}; 784};
785 785
diff --git a/arch/x86/events/msr.c b/arch/x86/events/msr.c
index b4771a6ddbc1..1b9f85abf9bc 100644
--- a/arch/x86/events/msr.c
+++ b/arch/x86/events/msr.c
@@ -69,14 +69,14 @@ static bool test_intel(int idx)
69 case INTEL_FAM6_BROADWELL_GT3E: 69 case INTEL_FAM6_BROADWELL_GT3E:
70 case INTEL_FAM6_BROADWELL_X: 70 case INTEL_FAM6_BROADWELL_X:
71 71
72 case INTEL_FAM6_ATOM_SILVERMONT1: 72 case INTEL_FAM6_ATOM_SILVERMONT:
73 case INTEL_FAM6_ATOM_SILVERMONT2: 73 case INTEL_FAM6_ATOM_SILVERMONT_X:
74 case INTEL_FAM6_ATOM_AIRMONT: 74 case INTEL_FAM6_ATOM_AIRMONT:
75 75
76 case INTEL_FAM6_ATOM_GOLDMONT: 76 case INTEL_FAM6_ATOM_GOLDMONT:
77 case INTEL_FAM6_ATOM_DENVERTON: 77 case INTEL_FAM6_ATOM_GOLDMONT_X:
78 78
79 case INTEL_FAM6_ATOM_GEMINI_LAKE: 79 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
80 80
81 case INTEL_FAM6_XEON_PHI_KNL: 81 case INTEL_FAM6_XEON_PHI_KNL:
82 case INTEL_FAM6_XEON_PHI_KNM: 82 case INTEL_FAM6_XEON_PHI_KNM:
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 156286335351..adae087cecdd 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -560,9 +560,11 @@ struct x86_pmu {
560 struct event_constraint *event_constraints; 560 struct event_constraint *event_constraints;
561 struct x86_pmu_quirk *quirks; 561 struct x86_pmu_quirk *quirks;
562 int perfctr_second_write; 562 int perfctr_second_write;
563 bool late_ack;
564 u64 (*limit_period)(struct perf_event *event, u64 l); 563 u64 (*limit_period)(struct perf_event *event, u64 l);
565 564
565 /* PMI handler bits */
566 unsigned int late_ack :1,
567 counter_freezing :1;
566 /* 568 /*
567 * sysfs attrs 569 * sysfs attrs
568 */ 570 */
diff --git a/arch/x86/include/asm/intel-family.h b/arch/x86/include/asm/intel-family.h
index 7ed08a7c3398..0dd6b0f4000e 100644
--- a/arch/x86/include/asm/intel-family.h
+++ b/arch/x86/include/asm/intel-family.h
@@ -8,9 +8,6 @@
8 * The "_X" parts are generally the EP and EX Xeons, or the 8 * The "_X" parts are generally the EP and EX Xeons, or the
9 * "Extreme" ones, like Broadwell-E. 9 * "Extreme" ones, like Broadwell-E.
10 * 10 *
11 * Things ending in "2" are usually because we have no better
12 * name for them. There's no processor called "SILVERMONT2".
13 *
14 * While adding a new CPUID for a new microarchitecture, add a new 11 * While adding a new CPUID for a new microarchitecture, add a new
15 * group to keep logically sorted out in chronological order. Within 12 * group to keep logically sorted out in chronological order. Within
16 * that group keep the CPUID for the variants sorted by model number. 13 * that group keep the CPUID for the variants sorted by model number.
@@ -57,19 +54,23 @@
57 54
58/* "Small Core" Processors (Atom) */ 55/* "Small Core" Processors (Atom) */
59 56
60#define INTEL_FAM6_ATOM_PINEVIEW 0x1C 57#define INTEL_FAM6_ATOM_BONNELL 0x1C /* Diamondville, Pineview */
61#define INTEL_FAM6_ATOM_LINCROFT 0x26 58#define INTEL_FAM6_ATOM_BONNELL_MID 0x26 /* Silverthorne, Lincroft */
62#define INTEL_FAM6_ATOM_PENWELL 0x27 59
63#define INTEL_FAM6_ATOM_CLOVERVIEW 0x35 60#define INTEL_FAM6_ATOM_SALTWELL 0x36 /* Cedarview */
64#define INTEL_FAM6_ATOM_CEDARVIEW 0x36 61#define INTEL_FAM6_ATOM_SALTWELL_MID 0x27 /* Penwell */
65#define INTEL_FAM6_ATOM_SILVERMONT1 0x37 /* BayTrail/BYT / Valleyview */ 62#define INTEL_FAM6_ATOM_SALTWELL_TABLET 0x35 /* Cloverview */
66#define INTEL_FAM6_ATOM_SILVERMONT2 0x4D /* Avaton/Rangely */ 63
67#define INTEL_FAM6_ATOM_AIRMONT 0x4C /* CherryTrail / Braswell */ 64#define INTEL_FAM6_ATOM_SILVERMONT 0x37 /* Bay Trail, Valleyview */
68#define INTEL_FAM6_ATOM_MERRIFIELD 0x4A /* Tangier */ 65#define INTEL_FAM6_ATOM_SILVERMONT_X 0x4D /* Avaton, Rangely */
69#define INTEL_FAM6_ATOM_MOOREFIELD 0x5A /* Anniedale */ 66#define INTEL_FAM6_ATOM_SILVERMONT_MID 0x4A /* Merriefield */
70#define INTEL_FAM6_ATOM_GOLDMONT 0x5C 67
71#define INTEL_FAM6_ATOM_DENVERTON 0x5F /* Goldmont Microserver */ 68#define INTEL_FAM6_ATOM_AIRMONT 0x4C /* Cherry Trail, Braswell */
72#define INTEL_FAM6_ATOM_GEMINI_LAKE 0x7A 69#define INTEL_FAM6_ATOM_AIRMONT_MID 0x5A /* Moorefield */
70
71#define INTEL_FAM6_ATOM_GOLDMONT 0x5C /* Apollo Lake */
72#define INTEL_FAM6_ATOM_GOLDMONT_X 0x5F /* Denverton */
73#define INTEL_FAM6_ATOM_GOLDMONT_PLUS 0x7A /* Gemini Lake */
73 74
74/* Xeon Phi */ 75/* Xeon Phi */
75 76
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 4731f0cf97c5..80f4a4f38c79 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -164,6 +164,7 @@
164#define DEBUGCTLMSR_BTS_OFF_OS (1UL << 9) 164#define DEBUGCTLMSR_BTS_OFF_OS (1UL << 9)
165#define DEBUGCTLMSR_BTS_OFF_USR (1UL << 10) 165#define DEBUGCTLMSR_BTS_OFF_USR (1UL << 10)
166#define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI (1UL << 11) 166#define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI (1UL << 11)
167#define DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI (1UL << 12)
167#define DEBUGCTLMSR_FREEZE_IN_SMM_BIT 14 168#define DEBUGCTLMSR_FREEZE_IN_SMM_BIT 14
168#define DEBUGCTLMSR_FREEZE_IN_SMM (1UL << DEBUGCTLMSR_FREEZE_IN_SMM_BIT) 169#define DEBUGCTLMSR_FREEZE_IN_SMM (1UL << DEBUGCTLMSR_FREEZE_IN_SMM_BIT)
169 170
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
index 78241b736f2a..8bdf74902293 100644
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -278,6 +278,7 @@ struct perf_guest_switch_msr {
278extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr); 278extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr);
279extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap); 279extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap);
280extern void perf_check_microcode(void); 280extern void perf_check_microcode(void);
281extern int x86_perf_rdpmc_index(struct perf_event *event);
281#else 282#else
282static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) 283static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr)
283{ 284{
diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
index 5e58a74bfd3a..25f49af1b13c 100644
--- a/arch/x86/include/asm/ptrace.h
+++ b/arch/x86/include/asm/ptrace.h
@@ -239,23 +239,51 @@ static inline int regs_within_kernel_stack(struct pt_regs *regs,
239} 239}
240 240
241/** 241/**
242 * regs_get_kernel_stack_nth_addr() - get the address of the Nth entry on stack
243 * @regs: pt_regs which contains kernel stack pointer.
244 * @n: stack entry number.
245 *
246 * regs_get_kernel_stack_nth() returns the address of the @n th entry of the
247 * kernel stack which is specified by @regs. If the @n th entry is NOT in
248 * the kernel stack, this returns NULL.
249 */
250static inline unsigned long *regs_get_kernel_stack_nth_addr(struct pt_regs *regs, unsigned int n)
251{
252 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
253
254 addr += n;
255 if (regs_within_kernel_stack(regs, (unsigned long)addr))
256 return addr;
257 else
258 return NULL;
259}
260
261/* To avoid include hell, we can't include uaccess.h */
262extern long probe_kernel_read(void *dst, const void *src, size_t size);
263
264/**
242 * regs_get_kernel_stack_nth() - get Nth entry of the stack 265 * regs_get_kernel_stack_nth() - get Nth entry of the stack
243 * @regs: pt_regs which contains kernel stack pointer. 266 * @regs: pt_regs which contains kernel stack pointer.
244 * @n: stack entry number. 267 * @n: stack entry number.
245 * 268 *
246 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which 269 * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
247 * is specified by @regs. If the @n th entry is NOT in the kernel stack, 270 * is specified by @regs. If the @n th entry is NOT in the kernel stack
248 * this returns 0. 271 * this returns 0.
249 */ 272 */
250static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, 273static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
251 unsigned int n) 274 unsigned int n)
252{ 275{
253 unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs); 276 unsigned long *addr;
254 addr += n; 277 unsigned long val;
255 if (regs_within_kernel_stack(regs, (unsigned long)addr)) 278 long ret;
256 return *addr; 279
257 else 280 addr = regs_get_kernel_stack_nth_addr(regs, n);
258 return 0; 281 if (addr) {
282 ret = probe_kernel_read(&val, addr, sizeof(val));
283 if (!ret)
284 return val;
285 }
286 return 0;
259} 287}
260 288
261#define arch_has_single_step() (1) 289#define arch_has_single_step() (1)
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 44c4ef3d989b..10e5ccfa9278 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -949,11 +949,11 @@ static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
949} 949}
950 950
951static const __initconst struct x86_cpu_id cpu_no_speculation[] = { 951static const __initconst struct x86_cpu_id cpu_no_speculation[] = {
952 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CEDARVIEW, X86_FEATURE_ANY }, 952 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SALTWELL, X86_FEATURE_ANY },
953 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_CLOVERVIEW, X86_FEATURE_ANY }, 953 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SALTWELL_TABLET, X86_FEATURE_ANY },
954 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_LINCROFT, X86_FEATURE_ANY }, 954 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_BONNELL_MID, X86_FEATURE_ANY },
955 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PENWELL, X86_FEATURE_ANY }, 955 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SALTWELL_MID, X86_FEATURE_ANY },
956 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_PINEVIEW, X86_FEATURE_ANY }, 956 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_BONNELL, X86_FEATURE_ANY },
957 { X86_VENDOR_CENTAUR, 5 }, 957 { X86_VENDOR_CENTAUR, 5 },
958 { X86_VENDOR_INTEL, 5 }, 958 { X86_VENDOR_INTEL, 5 },
959 { X86_VENDOR_NSC, 5 }, 959 { X86_VENDOR_NSC, 5 },
@@ -968,10 +968,10 @@ static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
968 968
969/* Only list CPUs which speculate but are non susceptible to SSB */ 969/* Only list CPUs which speculate but are non susceptible to SSB */
970static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = { 970static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = {
971 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, 971 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT },
972 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT }, 972 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT },
973 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT2 }, 973 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT_X },
974 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_MERRIFIELD }, 974 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT_MID },
975 { X86_VENDOR_INTEL, 6, INTEL_FAM6_CORE_YONAH }, 975 { X86_VENDOR_INTEL, 6, INTEL_FAM6_CORE_YONAH },
976 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNL }, 976 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNL },
977 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNM }, 977 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNM },
@@ -984,14 +984,14 @@ static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = {
984 984
985static const __initconst struct x86_cpu_id cpu_no_l1tf[] = { 985static const __initconst struct x86_cpu_id cpu_no_l1tf[] = {
986 /* in addition to cpu_no_speculation */ 986 /* in addition to cpu_no_speculation */
987 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, 987 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT },
988 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT2 }, 988 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT_X },
989 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT }, 989 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT },
990 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_MERRIFIELD }, 990 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT_MID },
991 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_MOOREFIELD }, 991 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_AIRMONT_MID },
992 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT }, 992 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT },
993 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_DENVERTON }, 993 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT_X },
994 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GEMINI_LAKE }, 994 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT_PLUS },
995 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNL }, 995 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNL },
996 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNM }, 996 { X86_VENDOR_INTEL, 6, INTEL_FAM6_XEON_PHI_KNM },
997 {} 997 {}
diff --git a/arch/x86/kernel/cpu/intel_rdt.c b/arch/x86/kernel/cpu/intel_rdt.c
index abb71ac70443..44272b7107ad 100644
--- a/arch/x86/kernel/cpu/intel_rdt.c
+++ b/arch/x86/kernel/cpu/intel_rdt.c
@@ -485,9 +485,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
485 size_t tsize; 485 size_t tsize;
486 486
487 if (is_llc_occupancy_enabled()) { 487 if (is_llc_occupancy_enabled()) {
488 d->rmid_busy_llc = kcalloc(BITS_TO_LONGS(r->num_rmid), 488 d->rmid_busy_llc = bitmap_zalloc(r->num_rmid, GFP_KERNEL);
489 sizeof(unsigned long),
490 GFP_KERNEL);
491 if (!d->rmid_busy_llc) 489 if (!d->rmid_busy_llc)
492 return -ENOMEM; 490 return -ENOMEM;
493 INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo); 491 INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
@@ -496,7 +494,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
496 tsize = sizeof(*d->mbm_total); 494 tsize = sizeof(*d->mbm_total);
497 d->mbm_total = kcalloc(r->num_rmid, tsize, GFP_KERNEL); 495 d->mbm_total = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
498 if (!d->mbm_total) { 496 if (!d->mbm_total) {
499 kfree(d->rmid_busy_llc); 497 bitmap_free(d->rmid_busy_llc);
500 return -ENOMEM; 498 return -ENOMEM;
501 } 499 }
502 } 500 }
@@ -504,7 +502,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
504 tsize = sizeof(*d->mbm_local); 502 tsize = sizeof(*d->mbm_local);
505 d->mbm_local = kcalloc(r->num_rmid, tsize, GFP_KERNEL); 503 d->mbm_local = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
506 if (!d->mbm_local) { 504 if (!d->mbm_local) {
507 kfree(d->rmid_busy_llc); 505 bitmap_free(d->rmid_busy_llc);
508 kfree(d->mbm_total); 506 kfree(d->mbm_total);
509 return -ENOMEM; 507 return -ENOMEM;
510 } 508 }
@@ -610,9 +608,16 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
610 cancel_delayed_work(&d->cqm_limbo); 608 cancel_delayed_work(&d->cqm_limbo);
611 } 609 }
612 610
611 /*
612 * rdt_domain "d" is going to be freed below, so clear
613 * its pointer from pseudo_lock_region struct.
614 */
615 if (d->plr)
616 d->plr->d = NULL;
617
613 kfree(d->ctrl_val); 618 kfree(d->ctrl_val);
614 kfree(d->mbps_val); 619 kfree(d->mbps_val);
615 kfree(d->rmid_busy_llc); 620 bitmap_free(d->rmid_busy_llc);
616 kfree(d->mbm_total); 621 kfree(d->mbm_total);
617 kfree(d->mbm_local); 622 kfree(d->mbm_local);
618 kfree(d); 623 kfree(d);
diff --git a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
index 0f53049719cd..27937458c231 100644
--- a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
+++ b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
@@ -404,8 +404,16 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
404 for_each_alloc_enabled_rdt_resource(r) 404 for_each_alloc_enabled_rdt_resource(r)
405 seq_printf(s, "%s:uninitialized\n", r->name); 405 seq_printf(s, "%s:uninitialized\n", r->name);
406 } else if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) { 406 } else if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
407 seq_printf(s, "%s:%d=%x\n", rdtgrp->plr->r->name, 407 if (!rdtgrp->plr->d) {
408 rdtgrp->plr->d->id, rdtgrp->plr->cbm); 408 rdt_last_cmd_clear();
409 rdt_last_cmd_puts("Cache domain offline\n");
410 ret = -ENODEV;
411 } else {
412 seq_printf(s, "%s:%d=%x\n",
413 rdtgrp->plr->r->name,
414 rdtgrp->plr->d->id,
415 rdtgrp->plr->cbm);
416 }
409 } else { 417 } else {
410 closid = rdtgrp->closid; 418 closid = rdtgrp->closid;
411 for_each_alloc_enabled_rdt_resource(r) { 419 for_each_alloc_enabled_rdt_resource(r) {
diff --git a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
index f8c260d522ca..815b4e92522c 100644
--- a/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
+++ b/arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
@@ -17,6 +17,7 @@
17#include <linux/debugfs.h> 17#include <linux/debugfs.h>
18#include <linux/kthread.h> 18#include <linux/kthread.h>
19#include <linux/mman.h> 19#include <linux/mman.h>
20#include <linux/perf_event.h>
20#include <linux/pm_qos.h> 21#include <linux/pm_qos.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
22#include <linux/uaccess.h> 23#include <linux/uaccess.h>
@@ -26,6 +27,7 @@
26#include <asm/intel_rdt_sched.h> 27#include <asm/intel_rdt_sched.h>
27#include <asm/perf_event.h> 28#include <asm/perf_event.h>
28 29
30#include "../../events/perf_event.h" /* For X86_CONFIG() */
29#include "intel_rdt.h" 31#include "intel_rdt.h"
30 32
31#define CREATE_TRACE_POINTS 33#define CREATE_TRACE_POINTS
@@ -91,7 +93,7 @@ static u64 get_prefetch_disable_bits(void)
91 */ 93 */
92 return 0xF; 94 return 0xF;
93 case INTEL_FAM6_ATOM_GOLDMONT: 95 case INTEL_FAM6_ATOM_GOLDMONT:
94 case INTEL_FAM6_ATOM_GEMINI_LAKE: 96 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
95 /* 97 /*
96 * SDM defines bits of MSR_MISC_FEATURE_CONTROL register 98 * SDM defines bits of MSR_MISC_FEATURE_CONTROL register
97 * as: 99 * as:
@@ -106,16 +108,6 @@ static u64 get_prefetch_disable_bits(void)
106 return 0; 108 return 0;
107} 109}
108 110
109/*
110 * Helper to write 64bit value to MSR without tracing. Used when
111 * use of the cache should be restricted and use of registers used
112 * for local variables avoided.
113 */
114static inline void pseudo_wrmsrl_notrace(unsigned int msr, u64 val)
115{
116 __wrmsr(msr, (u32)(val & 0xffffffffULL), (u32)(val >> 32));
117}
118
119/** 111/**
120 * pseudo_lock_minor_get - Obtain available minor number 112 * pseudo_lock_minor_get - Obtain available minor number
121 * @minor: Pointer to where new minor number will be stored 113 * @minor: Pointer to where new minor number will be stored
@@ -888,31 +880,14 @@ static int measure_cycles_lat_fn(void *_plr)
888 struct pseudo_lock_region *plr = _plr; 880 struct pseudo_lock_region *plr = _plr;
889 unsigned long i; 881 unsigned long i;
890 u64 start, end; 882 u64 start, end;
891#ifdef CONFIG_KASAN
892 /*
893 * The registers used for local register variables are also used
894 * when KASAN is active. When KASAN is active we use a regular
895 * variable to ensure we always use a valid pointer to access memory.
896 * The cost is that accessing this pointer, which could be in
897 * cache, will be included in the measurement of memory read latency.
898 */
899 void *mem_r; 883 void *mem_r;
900#else
901#ifdef CONFIG_X86_64
902 register void *mem_r asm("rbx");
903#else
904 register void *mem_r asm("ebx");
905#endif /* CONFIG_X86_64 */
906#endif /* CONFIG_KASAN */
907 884
908 local_irq_disable(); 885 local_irq_disable();
909 /* 886 /*
910 * The wrmsr call may be reordered with the assignment below it. 887 * Disable hardware prefetchers.
911 * Call wrmsr as directly as possible to avoid tracing clobbering
912 * local register variable used for memory pointer.
913 */ 888 */
914 __wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0); 889 wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
915 mem_r = plr->kmem; 890 mem_r = READ_ONCE(plr->kmem);
916 /* 891 /*
917 * Dummy execute of the time measurement to load the needed 892 * Dummy execute of the time measurement to load the needed
918 * instructions into the L1 instruction cache. 893 * instructions into the L1 instruction cache.
@@ -934,157 +909,240 @@ static int measure_cycles_lat_fn(void *_plr)
934 return 0; 909 return 0;
935} 910}
936 911
937static int measure_cycles_perf_fn(void *_plr) 912/*
913 * Create a perf_event_attr for the hit and miss perf events that will
914 * be used during the performance measurement. A perf_event maintains
915 * a pointer to its perf_event_attr so a unique attribute structure is
916 * created for each perf_event.
917 *
918 * The actual configuration of the event is set right before use in order
919 * to use the X86_CONFIG macro.
920 */
921static struct perf_event_attr perf_miss_attr = {
922 .type = PERF_TYPE_RAW,
923 .size = sizeof(struct perf_event_attr),
924 .pinned = 1,
925 .disabled = 0,
926 .exclude_user = 1,
927};
928
929static struct perf_event_attr perf_hit_attr = {
930 .type = PERF_TYPE_RAW,
931 .size = sizeof(struct perf_event_attr),
932 .pinned = 1,
933 .disabled = 0,
934 .exclude_user = 1,
935};
936
937struct residency_counts {
938 u64 miss_before, hits_before;
939 u64 miss_after, hits_after;
940};
941
942static int measure_residency_fn(struct perf_event_attr *miss_attr,
943 struct perf_event_attr *hit_attr,
944 struct pseudo_lock_region *plr,
945 struct residency_counts *counts)
938{ 946{
939 unsigned long long l3_hits = 0, l3_miss = 0; 947 u64 hits_before = 0, hits_after = 0, miss_before = 0, miss_after = 0;
940 u64 l3_hit_bits = 0, l3_miss_bits = 0; 948 struct perf_event *miss_event, *hit_event;
941 struct pseudo_lock_region *plr = _plr; 949 int hit_pmcnum, miss_pmcnum;
942 unsigned long long l2_hits, l2_miss;
943 u64 l2_hit_bits, l2_miss_bits;
944 unsigned long i;
945#ifdef CONFIG_KASAN
946 /*
947 * The registers used for local register variables are also used
948 * when KASAN is active. When KASAN is active we use regular variables
949 * at the cost of including cache access latency to these variables
950 * in the measurements.
951 */
952 unsigned int line_size; 950 unsigned int line_size;
953 unsigned int size; 951 unsigned int size;
952 unsigned long i;
954 void *mem_r; 953 void *mem_r;
955#else 954 u64 tmp;
956 register unsigned int line_size asm("esi"); 955
957 register unsigned int size asm("edi"); 956 miss_event = perf_event_create_kernel_counter(miss_attr, plr->cpu,
958#ifdef CONFIG_X86_64 957 NULL, NULL, NULL);
959 register void *mem_r asm("rbx"); 958 if (IS_ERR(miss_event))
960#else 959 goto out;
961 register void *mem_r asm("ebx"); 960
962#endif /* CONFIG_X86_64 */ 961 hit_event = perf_event_create_kernel_counter(hit_attr, plr->cpu,
963#endif /* CONFIG_KASAN */ 962 NULL, NULL, NULL);
963 if (IS_ERR(hit_event))
964 goto out_miss;
965
966 local_irq_disable();
967 /*
968 * Check any possible error state of events used by performing
969 * one local read.
970 */
971 if (perf_event_read_local(miss_event, &tmp, NULL, NULL)) {
972 local_irq_enable();
973 goto out_hit;
974 }
975 if (perf_event_read_local(hit_event, &tmp, NULL, NULL)) {
976 local_irq_enable();
977 goto out_hit;
978 }
979
980 /*
981 * Disable hardware prefetchers.
982 */
983 wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
984
985 /* Initialize rest of local variables */
986 /*
987 * Performance event has been validated right before this with
988 * interrupts disabled - it is thus safe to read the counter index.
989 */
990 miss_pmcnum = x86_perf_rdpmc_index(miss_event);
991 hit_pmcnum = x86_perf_rdpmc_index(hit_event);
992 line_size = READ_ONCE(plr->line_size);
993 mem_r = READ_ONCE(plr->kmem);
994 size = READ_ONCE(plr->size);
995
996 /*
997 * Read counter variables twice - first to load the instructions
998 * used in L1 cache, second to capture accurate value that does not
999 * include cache misses incurred because of instruction loads.
1000 */
1001 rdpmcl(hit_pmcnum, hits_before);
1002 rdpmcl(miss_pmcnum, miss_before);
1003 /*
1004 * From SDM: Performing back-to-back fast reads are not guaranteed
1005 * to be monotonic.
1006 * Use LFENCE to ensure all previous instructions are retired
1007 * before proceeding.
1008 */
1009 rmb();
1010 rdpmcl(hit_pmcnum, hits_before);
1011 rdpmcl(miss_pmcnum, miss_before);
1012 /*
1013 * Use LFENCE to ensure all previous instructions are retired
1014 * before proceeding.
1015 */
1016 rmb();
1017 for (i = 0; i < size; i += line_size) {
1018 /*
1019 * Add a barrier to prevent speculative execution of this
1020 * loop reading beyond the end of the buffer.
1021 */
1022 rmb();
1023 asm volatile("mov (%0,%1,1), %%eax\n\t"
1024 :
1025 : "r" (mem_r), "r" (i)
1026 : "%eax", "memory");
1027 }
1028 /*
1029 * Use LFENCE to ensure all previous instructions are retired
1030 * before proceeding.
1031 */
1032 rmb();
1033 rdpmcl(hit_pmcnum, hits_after);
1034 rdpmcl(miss_pmcnum, miss_after);
1035 /*
1036 * Use LFENCE to ensure all previous instructions are retired
1037 * before proceeding.
1038 */
1039 rmb();
1040 /* Re-enable hardware prefetchers */
1041 wrmsr(MSR_MISC_FEATURE_CONTROL, 0x0, 0x0);
1042 local_irq_enable();
1043out_hit:
1044 perf_event_release_kernel(hit_event);
1045out_miss:
1046 perf_event_release_kernel(miss_event);
1047out:
1048 /*
1049 * All counts will be zero on failure.
1050 */
1051 counts->miss_before = miss_before;
1052 counts->hits_before = hits_before;
1053 counts->miss_after = miss_after;
1054 counts->hits_after = hits_after;
1055 return 0;
1056}
1057
1058static int measure_l2_residency(void *_plr)
1059{
1060 struct pseudo_lock_region *plr = _plr;
1061 struct residency_counts counts = {0};
964 1062
965 /* 1063 /*
966 * Non-architectural event for the Goldmont Microarchitecture 1064 * Non-architectural event for the Goldmont Microarchitecture
967 * from Intel x86 Architecture Software Developer Manual (SDM): 1065 * from Intel x86 Architecture Software Developer Manual (SDM):
968 * MEM_LOAD_UOPS_RETIRED D1H (event number) 1066 * MEM_LOAD_UOPS_RETIRED D1H (event number)
969 * Umask values: 1067 * Umask values:
970 * L1_HIT 01H
971 * L2_HIT 02H 1068 * L2_HIT 02H
972 * L1_MISS 08H
973 * L2_MISS 10H 1069 * L2_MISS 10H
974 *
975 * On Broadwell Microarchitecture the MEM_LOAD_UOPS_RETIRED event
976 * has two "no fix" errata associated with it: BDM35 and BDM100. On
977 * this platform we use the following events instead:
978 * L2_RQSTS 24H (Documented in https://download.01.org/perfmon/BDW/)
979 * REFERENCES FFH
980 * MISS 3FH
981 * LONGEST_LAT_CACHE 2EH (Documented in SDM)
982 * REFERENCE 4FH
983 * MISS 41H
984 */ 1070 */
985
986 /*
987 * Start by setting flags for IA32_PERFEVTSELx:
988 * OS (Operating system mode) 0x2
989 * INT (APIC interrupt enable) 0x10
990 * EN (Enable counter) 0x40
991 *
992 * Then add the Umask value and event number to select performance
993 * event.
994 */
995
996 switch (boot_cpu_data.x86_model) { 1071 switch (boot_cpu_data.x86_model) {
997 case INTEL_FAM6_ATOM_GOLDMONT: 1072 case INTEL_FAM6_ATOM_GOLDMONT:
998 case INTEL_FAM6_ATOM_GEMINI_LAKE: 1073 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
999 l2_hit_bits = (0x52ULL << 16) | (0x2 << 8) | 0xd1; 1074 perf_miss_attr.config = X86_CONFIG(.event = 0xd1,
1000 l2_miss_bits = (0x52ULL << 16) | (0x10 << 8) | 0xd1; 1075 .umask = 0x10);
1001 break; 1076 perf_hit_attr.config = X86_CONFIG(.event = 0xd1,
1002 case INTEL_FAM6_BROADWELL_X: 1077 .umask = 0x2);
1003 /* On BDW the l2_hit_bits count references, not hits */
1004 l2_hit_bits = (0x52ULL << 16) | (0xff << 8) | 0x24;
1005 l2_miss_bits = (0x52ULL << 16) | (0x3f << 8) | 0x24;
1006 /* On BDW the l3_hit_bits count references, not hits */
1007 l3_hit_bits = (0x52ULL << 16) | (0x4f << 8) | 0x2e;
1008 l3_miss_bits = (0x52ULL << 16) | (0x41 << 8) | 0x2e;
1009 break; 1078 break;
1010 default: 1079 default:
1011 goto out; 1080 goto out;
1012 } 1081 }
1013 1082
1014 local_irq_disable(); 1083 measure_residency_fn(&perf_miss_attr, &perf_hit_attr, plr, &counts);
1015 /* 1084 /*
1016 * Call wrmsr direcly to avoid the local register variables from 1085 * If a failure prevented the measurements from succeeding
1017 * being overwritten due to reordering of their assignment with 1086 * tracepoints will still be written and all counts will be zero.
1018 * the wrmsr calls.
1019 */ 1087 */
1020 __wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0); 1088 trace_pseudo_lock_l2(counts.hits_after - counts.hits_before,
1021 /* Disable events and reset counters */ 1089 counts.miss_after - counts.miss_before);
1022 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0, 0x0); 1090out:
1023 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 1, 0x0); 1091 plr->thread_done = 1;
1024 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0, 0x0); 1092 wake_up_interruptible(&plr->lock_thread_wq);
1025 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0 + 1, 0x0); 1093 return 0;
1026 if (l3_hit_bits > 0) { 1094}
1027 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 2, 0x0); 1095
1028 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 3, 0x0); 1096static int measure_l3_residency(void *_plr)
1029 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0 + 2, 0x0); 1097{
1030 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0 + 3, 0x0); 1098 struct pseudo_lock_region *plr = _plr;
1031 } 1099 struct residency_counts counts = {0};
1032 /* Set and enable the L2 counters */ 1100
1033 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0, l2_hit_bits);
1034 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 1, l2_miss_bits);
1035 if (l3_hit_bits > 0) {
1036 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 2,
1037 l3_hit_bits);
1038 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 3,
1039 l3_miss_bits);
1040 }
1041 mem_r = plr->kmem;
1042 size = plr->size;
1043 line_size = plr->line_size;
1044 for (i = 0; i < size; i += line_size) {
1045 asm volatile("mov (%0,%1,1), %%eax\n\t"
1046 :
1047 : "r" (mem_r), "r" (i)
1048 : "%eax", "memory");
1049 }
1050 /* 1101 /*
1051 * Call wrmsr directly (no tracing) to not influence 1102 * On Broadwell Microarchitecture the MEM_LOAD_UOPS_RETIRED event
1052 * the cache access counters as they are disabled. 1103 * has two "no fix" errata associated with it: BDM35 and BDM100. On
1104 * this platform the following events are used instead:
1105 * LONGEST_LAT_CACHE 2EH (Documented in SDM)
1106 * REFERENCE 4FH
1107 * MISS 41H
1053 */ 1108 */
1054 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0, 1109
1055 l2_hit_bits & ~(0x40ULL << 16)); 1110 switch (boot_cpu_data.x86_model) {
1056 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 1, 1111 case INTEL_FAM6_BROADWELL_X:
1057 l2_miss_bits & ~(0x40ULL << 16)); 1112 /* On BDW the hit event counts references, not hits */
1058 if (l3_hit_bits > 0) { 1113 perf_hit_attr.config = X86_CONFIG(.event = 0x2e,
1059 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 2, 1114 .umask = 0x4f);
1060 l3_hit_bits & ~(0x40ULL << 16)); 1115 perf_miss_attr.config = X86_CONFIG(.event = 0x2e,
1061 pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 3, 1116 .umask = 0x41);
1062 l3_miss_bits & ~(0x40ULL << 16)); 1117 break;
1063 } 1118 default:
1064 l2_hits = native_read_pmc(0); 1119 goto out;
1065 l2_miss = native_read_pmc(1);
1066 if (l3_hit_bits > 0) {
1067 l3_hits = native_read_pmc(2);
1068 l3_miss = native_read_pmc(3);
1069 } 1120 }
1070 wrmsr(MSR_MISC_FEATURE_CONTROL, 0x0, 0x0); 1121
1071 local_irq_enable(); 1122 measure_residency_fn(&perf_miss_attr, &perf_hit_attr, plr, &counts);
1072 /* 1123 /*
1073 * On BDW we count references and misses, need to adjust. Sometimes 1124 * If a failure prevented the measurements from succeeding
1074 * the "hits" counter is a bit more than the references, for 1125 * tracepoints will still be written and all counts will be zero.
1075 * example, x references but x + 1 hits. To not report invalid
1076 * hit values in this case we treat that as misses eaqual to
1077 * references.
1078 */ 1126 */
1079 if (boot_cpu_data.x86_model == INTEL_FAM6_BROADWELL_X) 1127
1080 l2_hits -= (l2_miss > l2_hits ? l2_hits : l2_miss); 1128 counts.miss_after -= counts.miss_before;
1081 trace_pseudo_lock_l2(l2_hits, l2_miss); 1129 if (boot_cpu_data.x86_model == INTEL_FAM6_BROADWELL_X) {
1082 if (l3_hit_bits > 0) { 1130 /*
1083 if (boot_cpu_data.x86_model == INTEL_FAM6_BROADWELL_X) 1131 * On BDW references and misses are counted, need to adjust.
1084 l3_hits -= (l3_miss > l3_hits ? l3_hits : l3_miss); 1132 * Sometimes the "hits" counter is a bit more than the
1085 trace_pseudo_lock_l3(l3_hits, l3_miss); 1133 * references, for example, x references but x + 1 hits.
1134 * To not report invalid hit values in this case we treat
1135 * that as misses equal to references.
1136 */
1137 /* First compute the number of cache references measured */
1138 counts.hits_after -= counts.hits_before;
1139 /* Next convert references to cache hits */
1140 counts.hits_after -= min(counts.miss_after, counts.hits_after);
1141 } else {
1142 counts.hits_after -= counts.hits_before;
1086 } 1143 }
1087 1144
1145 trace_pseudo_lock_l3(counts.hits_after, counts.miss_after);
1088out: 1146out:
1089 plr->thread_done = 1; 1147 plr->thread_done = 1;
1090 wake_up_interruptible(&plr->lock_thread_wq); 1148 wake_up_interruptible(&plr->lock_thread_wq);
@@ -1116,6 +1174,11 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel)
1116 goto out; 1174 goto out;
1117 } 1175 }
1118 1176
1177 if (!plr->d) {
1178 ret = -ENODEV;
1179 goto out;
1180 }
1181
1119 plr->thread_done = 0; 1182 plr->thread_done = 0;
1120 cpu = cpumask_first(&plr->d->cpu_mask); 1183 cpu = cpumask_first(&plr->d->cpu_mask);
1121 if (!cpu_online(cpu)) { 1184 if (!cpu_online(cpu)) {
@@ -1123,13 +1186,20 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel)
1123 goto out; 1186 goto out;
1124 } 1187 }
1125 1188
1189 plr->cpu = cpu;
1190
1126 if (sel == 1) 1191 if (sel == 1)
1127 thread = kthread_create_on_node(measure_cycles_lat_fn, plr, 1192 thread = kthread_create_on_node(measure_cycles_lat_fn, plr,
1128 cpu_to_node(cpu), 1193 cpu_to_node(cpu),
1129 "pseudo_lock_measure/%u", 1194 "pseudo_lock_measure/%u",
1130 cpu); 1195 cpu);
1131 else if (sel == 2) 1196 else if (sel == 2)
1132 thread = kthread_create_on_node(measure_cycles_perf_fn, plr, 1197 thread = kthread_create_on_node(measure_l2_residency, plr,
1198 cpu_to_node(cpu),
1199 "pseudo_lock_measure/%u",
1200 cpu);
1201 else if (sel == 3)
1202 thread = kthread_create_on_node(measure_l3_residency, plr,
1133 cpu_to_node(cpu), 1203 cpu_to_node(cpu),
1134 "pseudo_lock_measure/%u", 1204 "pseudo_lock_measure/%u",
1135 cpu); 1205 cpu);
@@ -1173,7 +1243,7 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
1173 buf[buf_size] = '\0'; 1243 buf[buf_size] = '\0';
1174 ret = kstrtoint(buf, 10, &sel); 1244 ret = kstrtoint(buf, 10, &sel);
1175 if (ret == 0) { 1245 if (ret == 0) {
1176 if (sel != 1) 1246 if (sel != 1 && sel != 2 && sel != 3)
1177 return -EINVAL; 1247 return -EINVAL;
1178 ret = debugfs_file_get(file->f_path.dentry); 1248 ret = debugfs_file_get(file->f_path.dentry);
1179 if (ret) 1249 if (ret)
@@ -1429,6 +1499,11 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)
1429 1499
1430 plr = rdtgrp->plr; 1500 plr = rdtgrp->plr;
1431 1501
1502 if (!plr->d) {
1503 mutex_unlock(&rdtgroup_mutex);
1504 return -ENODEV;
1505 }
1506
1432 /* 1507 /*
1433 * Task is required to run with affinity to the cpus associated 1508 * Task is required to run with affinity to the cpus associated
1434 * with the pseudo-locked region. If this is not the case the task 1509 * with the pseudo-locked region. If this is not the case the task
diff --git a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
index b140c68bc14b..f27b8115ffa2 100644
--- a/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
+++ b/arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
@@ -268,17 +268,27 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
268 struct seq_file *s, void *v) 268 struct seq_file *s, void *v)
269{ 269{
270 struct rdtgroup *rdtgrp; 270 struct rdtgroup *rdtgrp;
271 struct cpumask *mask;
271 int ret = 0; 272 int ret = 0;
272 273
273 rdtgrp = rdtgroup_kn_lock_live(of->kn); 274 rdtgrp = rdtgroup_kn_lock_live(of->kn);
274 275
275 if (rdtgrp) { 276 if (rdtgrp) {
276 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) 277 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
277 seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n", 278 if (!rdtgrp->plr->d) {
278 cpumask_pr_args(&rdtgrp->plr->d->cpu_mask)); 279 rdt_last_cmd_clear();
279 else 280 rdt_last_cmd_puts("Cache domain offline\n");
281 ret = -ENODEV;
282 } else {
283 mask = &rdtgrp->plr->d->cpu_mask;
284 seq_printf(s, is_cpu_list(of) ?
285 "%*pbl\n" : "%*pb\n",
286 cpumask_pr_args(mask));
287 }
288 } else {
280 seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n", 289 seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
281 cpumask_pr_args(&rdtgrp->cpu_mask)); 290 cpumask_pr_args(&rdtgrp->cpu_mask));
291 }
282 } else { 292 } else {
283 ret = -ENOENT; 293 ret = -ENOENT;
284 } 294 }
@@ -961,7 +971,78 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,
961} 971}
962 972
963/** 973/**
964 * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other 974 * rdt_cdp_peer_get - Retrieve CDP peer if it exists
975 * @r: RDT resource to which RDT domain @d belongs
976 * @d: Cache instance for which a CDP peer is requested
977 * @r_cdp: RDT resource that shares hardware with @r (RDT resource peer)
978 * Used to return the result.
979 * @d_cdp: RDT domain that shares hardware with @d (RDT domain peer)
980 * Used to return the result.
981 *
982 * RDT resources are managed independently and by extension the RDT domains
983 * (RDT resource instances) are managed independently also. The Code and
984 * Data Prioritization (CDP) RDT resources, while managed independently,
985 * could refer to the same underlying hardware. For example,
986 * RDT_RESOURCE_L2CODE and RDT_RESOURCE_L2DATA both refer to the L2 cache.
987 *
988 * When provided with an RDT resource @r and an instance of that RDT
989 * resource @d rdt_cdp_peer_get() will return if there is a peer RDT
990 * resource and the exact instance that shares the same hardware.
991 *
992 * Return: 0 if a CDP peer was found, <0 on error or if no CDP peer exists.
993 * If a CDP peer was found, @r_cdp will point to the peer RDT resource
994 * and @d_cdp will point to the peer RDT domain.
995 */
996static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d,
997 struct rdt_resource **r_cdp,
998 struct rdt_domain **d_cdp)
999{
1000 struct rdt_resource *_r_cdp = NULL;
1001 struct rdt_domain *_d_cdp = NULL;
1002 int ret = 0;
1003
1004 switch (r->rid) {
1005 case RDT_RESOURCE_L3DATA:
1006 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE];
1007 break;
1008 case RDT_RESOURCE_L3CODE:
1009 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3DATA];
1010 break;
1011 case RDT_RESOURCE_L2DATA:
1012 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2CODE];
1013 break;
1014 case RDT_RESOURCE_L2CODE:
1015 _r_cdp = &rdt_resources_all[RDT_RESOURCE_L2DATA];
1016 break;
1017 default:
1018 ret = -ENOENT;
1019 goto out;
1020 }
1021
1022 /*
1023 * When a new CPU comes online and CDP is enabled then the new
1024 * RDT domains (if any) associated with both CDP RDT resources
1025 * are added in the same CPU online routine while the
1026 * rdtgroup_mutex is held. It should thus not happen for one
1027 * RDT domain to exist and be associated with its RDT CDP
1028 * resource but there is no RDT domain associated with the
1029 * peer RDT CDP resource. Hence the WARN.
1030 */
1031 _d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
1032 if (WARN_ON(!_d_cdp)) {
1033 _r_cdp = NULL;
1034 ret = -EINVAL;
1035 }
1036
1037out:
1038 *r_cdp = _r_cdp;
1039 *d_cdp = _d_cdp;
1040
1041 return ret;
1042}
1043
1044/**
1045 * __rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other
965 * @r: Resource to which domain instance @d belongs. 1046 * @r: Resource to which domain instance @d belongs.
966 * @d: The domain instance for which @closid is being tested. 1047 * @d: The domain instance for which @closid is being tested.
967 * @cbm: Capacity bitmask being tested. 1048 * @cbm: Capacity bitmask being tested.
@@ -980,8 +1061,8 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,
980 * 1061 *
981 * Return: false if CBM does not overlap, true if it does. 1062 * Return: false if CBM does not overlap, true if it does.
982 */ 1063 */
983bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d, 1064static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
984 unsigned long cbm, int closid, bool exclusive) 1065 unsigned long cbm, int closid, bool exclusive)
985{ 1066{
986 enum rdtgrp_mode mode; 1067 enum rdtgrp_mode mode;
987 unsigned long ctrl_b; 1068 unsigned long ctrl_b;
@@ -1017,6 +1098,41 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
1017} 1098}
1018 1099
1019/** 1100/**
1101 * rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware
1102 * @r: Resource to which domain instance @d belongs.
1103 * @d: The domain instance for which @closid is being tested.
1104 * @cbm: Capacity bitmask being tested.
1105 * @closid: Intended closid for @cbm.
1106 * @exclusive: Only check if overlaps with exclusive resource groups
1107 *
1108 * Resources that can be allocated using a CBM can use the CBM to control
1109 * the overlap of these allocations. rdtgroup_cmb_overlaps() is the test
1110 * for overlap. Overlap test is not limited to the specific resource for
1111 * which the CBM is intended though - when dealing with CDP resources that
1112 * share the underlying hardware the overlap check should be performed on
1113 * the CDP resource sharing the hardware also.
1114 *
1115 * Refer to description of __rdtgroup_cbm_overlaps() for the details of the
1116 * overlap test.
1117 *
1118 * Return: true if CBM overlap detected, false if there is no overlap
1119 */
1120bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
1121 unsigned long cbm, int closid, bool exclusive)
1122{
1123 struct rdt_resource *r_cdp;
1124 struct rdt_domain *d_cdp;
1125
1126 if (__rdtgroup_cbm_overlaps(r, d, cbm, closid, exclusive))
1127 return true;
1128
1129 if (rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp) < 0)
1130 return false;
1131
1132 return __rdtgroup_cbm_overlaps(r_cdp, d_cdp, cbm, closid, exclusive);
1133}
1134
1135/**
1020 * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive 1136 * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive
1021 * 1137 *
1022 * An exclusive resource group implies that there should be no sharing of 1138 * An exclusive resource group implies that there should be no sharing of
@@ -1176,6 +1292,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
1176 struct rdt_resource *r; 1292 struct rdt_resource *r;
1177 struct rdt_domain *d; 1293 struct rdt_domain *d;
1178 unsigned int size; 1294 unsigned int size;
1295 int ret = 0;
1179 bool sep; 1296 bool sep;
1180 u32 ctrl; 1297 u32 ctrl;
1181 1298
@@ -1186,11 +1303,18 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
1186 } 1303 }
1187 1304
1188 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) { 1305 if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
1189 seq_printf(s, "%*s:", max_name_width, rdtgrp->plr->r->name); 1306 if (!rdtgrp->plr->d) {
1190 size = rdtgroup_cbm_to_size(rdtgrp->plr->r, 1307 rdt_last_cmd_clear();
1191 rdtgrp->plr->d, 1308 rdt_last_cmd_puts("Cache domain offline\n");
1192 rdtgrp->plr->cbm); 1309 ret = -ENODEV;
1193 seq_printf(s, "%d=%u\n", rdtgrp->plr->d->id, size); 1310 } else {
1311 seq_printf(s, "%*s:", max_name_width,
1312 rdtgrp->plr->r->name);
1313 size = rdtgroup_cbm_to_size(rdtgrp->plr->r,
1314 rdtgrp->plr->d,
1315 rdtgrp->plr->cbm);
1316 seq_printf(s, "%d=%u\n", rdtgrp->plr->d->id, size);
1317 }
1194 goto out; 1318 goto out;
1195 } 1319 }
1196 1320
@@ -1220,7 +1344,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
1220out: 1344out:
1221 rdtgroup_kn_unlock(of->kn); 1345 rdtgroup_kn_unlock(of->kn);
1222 1346
1223 return 0; 1347 return ret;
1224} 1348}
1225 1349
1226/* rdtgroup information files for one cache resource. */ 1350/* rdtgroup information files for one cache resource. */
@@ -2354,14 +2478,16 @@ static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r)
2354 */ 2478 */
2355static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp) 2479static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
2356{ 2480{
2481 struct rdt_resource *r_cdp = NULL;
2482 struct rdt_domain *d_cdp = NULL;
2357 u32 used_b = 0, unused_b = 0; 2483 u32 used_b = 0, unused_b = 0;
2358 u32 closid = rdtgrp->closid; 2484 u32 closid = rdtgrp->closid;
2359 struct rdt_resource *r; 2485 struct rdt_resource *r;
2360 unsigned long tmp_cbm; 2486 unsigned long tmp_cbm;
2361 enum rdtgrp_mode mode; 2487 enum rdtgrp_mode mode;
2362 struct rdt_domain *d; 2488 struct rdt_domain *d;
2489 u32 peer_ctl, *ctrl;
2363 int i, ret; 2490 int i, ret;
2364 u32 *ctrl;
2365 2491
2366 for_each_alloc_enabled_rdt_resource(r) { 2492 for_each_alloc_enabled_rdt_resource(r) {
2367 /* 2493 /*
@@ -2371,6 +2497,7 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
2371 if (r->rid == RDT_RESOURCE_MBA) 2497 if (r->rid == RDT_RESOURCE_MBA)
2372 continue; 2498 continue;
2373 list_for_each_entry(d, &r->domains, list) { 2499 list_for_each_entry(d, &r->domains, list) {
2500 rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp);
2374 d->have_new_ctrl = false; 2501 d->have_new_ctrl = false;
2375 d->new_ctrl = r->cache.shareable_bits; 2502 d->new_ctrl = r->cache.shareable_bits;
2376 used_b = r->cache.shareable_bits; 2503 used_b = r->cache.shareable_bits;
@@ -2380,9 +2507,19 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
2380 mode = rdtgroup_mode_by_closid(i); 2507 mode = rdtgroup_mode_by_closid(i);
2381 if (mode == RDT_MODE_PSEUDO_LOCKSETUP) 2508 if (mode == RDT_MODE_PSEUDO_LOCKSETUP)
2382 break; 2509 break;
2383 used_b |= *ctrl; 2510 /*
2511 * If CDP is active include peer
2512 * domain's usage to ensure there
2513 * is no overlap with an exclusive
2514 * group.
2515 */
2516 if (d_cdp)
2517 peer_ctl = d_cdp->ctrl_val[i];
2518 else
2519 peer_ctl = 0;
2520 used_b |= *ctrl | peer_ctl;
2384 if (mode == RDT_MODE_SHAREABLE) 2521 if (mode == RDT_MODE_SHAREABLE)
2385 d->new_ctrl |= *ctrl; 2522 d->new_ctrl |= *ctrl | peer_ctl;
2386 } 2523 }
2387 } 2524 }
2388 if (d->plr && d->plr->cbm > 0) 2525 if (d->plr && d->plr->cbm > 0)
@@ -2805,6 +2942,13 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
2805{ 2942{
2806 if (rdt_resources_all[RDT_RESOURCE_L3DATA].alloc_enabled) 2943 if (rdt_resources_all[RDT_RESOURCE_L3DATA].alloc_enabled)
2807 seq_puts(seq, ",cdp"); 2944 seq_puts(seq, ",cdp");
2945
2946 if (rdt_resources_all[RDT_RESOURCE_L2DATA].alloc_enabled)
2947 seq_puts(seq, ",cdpl2");
2948
2949 if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA]))
2950 seq_puts(seq, ",mba_MBps");
2951
2808 return 0; 2952 return 0;
2809} 2953}
2810 2954
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index eaf02f2e7300..40b16b270656 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -179,7 +179,7 @@ optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
179 opt_pre_handler(&op->kp, regs); 179 opt_pre_handler(&op->kp, regs);
180 __this_cpu_write(current_kprobe, NULL); 180 __this_cpu_write(current_kprobe, NULL);
181 } 181 }
182 preempt_enable_no_resched(); 182 preempt_enable();
183} 183}
184NOKPROBE_SYMBOL(optimized_callback); 184NOKPROBE_SYMBOL(optimized_callback);
185 185
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 6d5dc5dabfd7..03b7529333a6 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -636,7 +636,7 @@ unsigned long native_calibrate_tsc(void)
636 case INTEL_FAM6_KABYLAKE_DESKTOP: 636 case INTEL_FAM6_KABYLAKE_DESKTOP:
637 crystal_khz = 24000; /* 24.0 MHz */ 637 crystal_khz = 24000; /* 24.0 MHz */
638 break; 638 break;
639 case INTEL_FAM6_ATOM_DENVERTON: 639 case INTEL_FAM6_ATOM_GOLDMONT_X:
640 crystal_khz = 25000; /* 25.0 MHz */ 640 crystal_khz = 25000; /* 25.0 MHz */
641 break; 641 break;
642 case INTEL_FAM6_ATOM_GOLDMONT: 642 case INTEL_FAM6_ATOM_GOLDMONT:
diff --git a/arch/x86/kernel/tsc_msr.c b/arch/x86/kernel/tsc_msr.c
index 27ef714d886c..3d0e9aeea7c8 100644
--- a/arch/x86/kernel/tsc_msr.c
+++ b/arch/x86/kernel/tsc_msr.c
@@ -59,12 +59,12 @@ static const struct freq_desc freq_desc_ann = {
59}; 59};
60 60
61static const struct x86_cpu_id tsc_msr_cpu_ids[] = { 61static const struct x86_cpu_id tsc_msr_cpu_ids[] = {
62 INTEL_CPU_FAM6(ATOM_PENWELL, freq_desc_pnw), 62 INTEL_CPU_FAM6(ATOM_SALTWELL_MID, freq_desc_pnw),
63 INTEL_CPU_FAM6(ATOM_CLOVERVIEW, freq_desc_clv), 63 INTEL_CPU_FAM6(ATOM_SALTWELL_TABLET, freq_desc_clv),
64 INTEL_CPU_FAM6(ATOM_SILVERMONT1, freq_desc_byt), 64 INTEL_CPU_FAM6(ATOM_SILVERMONT, freq_desc_byt),
65 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, freq_desc_tng),
65 INTEL_CPU_FAM6(ATOM_AIRMONT, freq_desc_cht), 66 INTEL_CPU_FAM6(ATOM_AIRMONT, freq_desc_cht),
66 INTEL_CPU_FAM6(ATOM_MERRIFIELD, freq_desc_tng), 67 INTEL_CPU_FAM6(ATOM_AIRMONT_MID, freq_desc_ann),
67 INTEL_CPU_FAM6(ATOM_MOOREFIELD, freq_desc_ann),
68 {} 68 {}
69}; 69};
70 70
diff --git a/arch/x86/platform/atom/punit_atom_debug.c b/arch/x86/platform/atom/punit_atom_debug.c
index 034813d4ab1e..6cb6076223ba 100644
--- a/arch/x86/platform/atom/punit_atom_debug.c
+++ b/arch/x86/platform/atom/punit_atom_debug.c
@@ -115,7 +115,7 @@ static struct dentry *punit_dbg_file;
115 115
116static int punit_dbgfs_register(struct punit_device *punit_device) 116static int punit_dbgfs_register(struct punit_device *punit_device)
117{ 117{
118 static struct dentry *dev_state; 118 struct dentry *dev_state;
119 119
120 punit_dbg_file = debugfs_create_dir("punit_atom", NULL); 120 punit_dbg_file = debugfs_create_dir("punit_atom", NULL);
121 if (!punit_dbg_file) 121 if (!punit_dbg_file)
@@ -143,8 +143,8 @@ static void punit_dbgfs_unregister(void)
143 (kernel_ulong_t)&drv_data } 143 (kernel_ulong_t)&drv_data }
144 144
145static const struct x86_cpu_id intel_punit_cpu_ids[] = { 145static const struct x86_cpu_id intel_punit_cpu_ids[] = {
146 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, punit_device_byt), 146 ICPU(INTEL_FAM6_ATOM_SILVERMONT, punit_device_byt),
147 ICPU(INTEL_FAM6_ATOM_MERRIFIELD, punit_device_tng), 147 ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID, punit_device_tng),
148 ICPU(INTEL_FAM6_ATOM_AIRMONT, punit_device_cht), 148 ICPU(INTEL_FAM6_ATOM_AIRMONT, punit_device_cht),
149 {} 149 {}
150}; 150};
diff --git a/arch/x86/platform/intel-mid/device_libs/platform_bt.c b/arch/x86/platform/intel-mid/device_libs/platform_bt.c
index 5a0483e7bf66..31dce781364c 100644
--- a/arch/x86/platform/intel-mid/device_libs/platform_bt.c
+++ b/arch/x86/platform/intel-mid/device_libs/platform_bt.c
@@ -68,7 +68,7 @@ static struct bt_sfi_data tng_bt_sfi_data __initdata = {
68 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (kernel_ulong_t)&ddata } 68 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (kernel_ulong_t)&ddata }
69 69
70static const struct x86_cpu_id bt_sfi_cpu_ids[] = { 70static const struct x86_cpu_id bt_sfi_cpu_ids[] = {
71 ICPU(INTEL_FAM6_ATOM_MERRIFIELD, tng_bt_sfi_data), 71 ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID, tng_bt_sfi_data),
72 {} 72 {}
73}; 73};
74 74
diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 10adb8cb3a3f..b9bda06d344d 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -314,7 +314,7 @@ static const struct lpss_device_desc bsw_spi_dev_desc = {
314#define ICPU(model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, } 314#define ICPU(model) { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
315 315
316static const struct x86_cpu_id lpss_cpu_ids[] = { 316static const struct x86_cpu_id lpss_cpu_ids[] = {
317 ICPU(INTEL_FAM6_ATOM_SILVERMONT1), /* Valleyview, Bay Trail */ 317 ICPU(INTEL_FAM6_ATOM_SILVERMONT), /* Valleyview, Bay Trail */
318 ICPU(INTEL_FAM6_ATOM_AIRMONT), /* Braswell, Cherry Trail */ 318 ICPU(INTEL_FAM6_ATOM_AIRMONT), /* Braswell, Cherry Trail */
319 {} 319 {}
320}; 320};
diff --git a/drivers/acpi/x86/utils.c b/drivers/acpi/x86/utils.c
index 06c31ec3cc70..9a8e286dd86f 100644
--- a/drivers/acpi/x86/utils.c
+++ b/drivers/acpi/x86/utils.c
@@ -54,7 +54,7 @@ static const struct always_present_id always_present_ids[] = {
54 * Bay / Cherry Trail PWM directly poked by GPU driver in win10, 54 * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
55 * but Linux uses a separate PWM driver, harmless if not used. 55 * but Linux uses a separate PWM driver, harmless if not used.
56 */ 56 */
57 ENTRY("80860F09", "1", ICPU(INTEL_FAM6_ATOM_SILVERMONT1), {}), 57 ENTRY("80860F09", "1", ICPU(INTEL_FAM6_ATOM_SILVERMONT), {}),
58 ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {}), 58 ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {}),
59 /* 59 /*
60 * The INT0002 device is necessary to clear wakeup interrupt sources 60 * The INT0002 device is necessary to clear wakeup interrupt sources
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 2a99e2fd9412..49c0abf2d48f 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -1816,7 +1816,7 @@ static const struct pstate_funcs knl_funcs = {
1816static const struct x86_cpu_id intel_pstate_cpu_ids[] = { 1816static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
1817 ICPU(INTEL_FAM6_SANDYBRIDGE, core_funcs), 1817 ICPU(INTEL_FAM6_SANDYBRIDGE, core_funcs),
1818 ICPU(INTEL_FAM6_SANDYBRIDGE_X, core_funcs), 1818 ICPU(INTEL_FAM6_SANDYBRIDGE_X, core_funcs),
1819 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, silvermont_funcs), 1819 ICPU(INTEL_FAM6_ATOM_SILVERMONT, silvermont_funcs),
1820 ICPU(INTEL_FAM6_IVYBRIDGE, core_funcs), 1820 ICPU(INTEL_FAM6_IVYBRIDGE, core_funcs),
1821 ICPU(INTEL_FAM6_HASWELL_CORE, core_funcs), 1821 ICPU(INTEL_FAM6_HASWELL_CORE, core_funcs),
1822 ICPU(INTEL_FAM6_BROADWELL_CORE, core_funcs), 1822 ICPU(INTEL_FAM6_BROADWELL_CORE, core_funcs),
@@ -1833,7 +1833,7 @@ static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
1833 ICPU(INTEL_FAM6_XEON_PHI_KNL, knl_funcs), 1833 ICPU(INTEL_FAM6_XEON_PHI_KNL, knl_funcs),
1834 ICPU(INTEL_FAM6_XEON_PHI_KNM, knl_funcs), 1834 ICPU(INTEL_FAM6_XEON_PHI_KNM, knl_funcs),
1835 ICPU(INTEL_FAM6_ATOM_GOLDMONT, core_funcs), 1835 ICPU(INTEL_FAM6_ATOM_GOLDMONT, core_funcs),
1836 ICPU(INTEL_FAM6_ATOM_GEMINI_LAKE, core_funcs), 1836 ICPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS, core_funcs),
1837 ICPU(INTEL_FAM6_SKYLAKE_X, core_funcs), 1837 ICPU(INTEL_FAM6_SKYLAKE_X, core_funcs),
1838 {} 1838 {}
1839}; 1839};
diff --git a/drivers/edac/pnd2_edac.c b/drivers/edac/pnd2_edac.c
index df28b65358d2..903a4f1fadcc 100644
--- a/drivers/edac/pnd2_edac.c
+++ b/drivers/edac/pnd2_edac.c
@@ -1541,7 +1541,7 @@ static struct dunit_ops dnv_ops = {
1541 1541
1542static const struct x86_cpu_id pnd2_cpuids[] = { 1542static const struct x86_cpu_id pnd2_cpuids[] = {
1543 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT, 0, (kernel_ulong_t)&apl_ops }, 1543 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT, 0, (kernel_ulong_t)&apl_ops },
1544 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_DENVERTON, 0, (kernel_ulong_t)&dnv_ops }, 1544 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT_X, 0, (kernel_ulong_t)&dnv_ops },
1545 { } 1545 { }
1546}; 1546};
1547MODULE_DEVICE_TABLE(x86cpu, pnd2_cpuids); 1547MODULE_DEVICE_TABLE(x86cpu, pnd2_cpuids);
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 791b8a366e6e..8b5d85c91e9d 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -1073,14 +1073,14 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
1073 INTEL_CPU_FAM6(WESTMERE, idle_cpu_nehalem), 1073 INTEL_CPU_FAM6(WESTMERE, idle_cpu_nehalem),
1074 INTEL_CPU_FAM6(WESTMERE_EP, idle_cpu_nehalem), 1074 INTEL_CPU_FAM6(WESTMERE_EP, idle_cpu_nehalem),
1075 INTEL_CPU_FAM6(NEHALEM_EX, idle_cpu_nehalem), 1075 INTEL_CPU_FAM6(NEHALEM_EX, idle_cpu_nehalem),
1076 INTEL_CPU_FAM6(ATOM_PINEVIEW, idle_cpu_atom), 1076 INTEL_CPU_FAM6(ATOM_BONNELL, idle_cpu_atom),
1077 INTEL_CPU_FAM6(ATOM_LINCROFT, idle_cpu_lincroft), 1077 INTEL_CPU_FAM6(ATOM_BONNELL_MID, idle_cpu_lincroft),
1078 INTEL_CPU_FAM6(WESTMERE_EX, idle_cpu_nehalem), 1078 INTEL_CPU_FAM6(WESTMERE_EX, idle_cpu_nehalem),
1079 INTEL_CPU_FAM6(SANDYBRIDGE, idle_cpu_snb), 1079 INTEL_CPU_FAM6(SANDYBRIDGE, idle_cpu_snb),
1080 INTEL_CPU_FAM6(SANDYBRIDGE_X, idle_cpu_snb), 1080 INTEL_CPU_FAM6(SANDYBRIDGE_X, idle_cpu_snb),
1081 INTEL_CPU_FAM6(ATOM_CEDARVIEW, idle_cpu_atom), 1081 INTEL_CPU_FAM6(ATOM_SALTWELL, idle_cpu_atom),
1082 INTEL_CPU_FAM6(ATOM_SILVERMONT1, idle_cpu_byt), 1082 INTEL_CPU_FAM6(ATOM_SILVERMONT, idle_cpu_byt),
1083 INTEL_CPU_FAM6(ATOM_MERRIFIELD, idle_cpu_tangier), 1083 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, idle_cpu_tangier),
1084 INTEL_CPU_FAM6(ATOM_AIRMONT, idle_cpu_cht), 1084 INTEL_CPU_FAM6(ATOM_AIRMONT, idle_cpu_cht),
1085 INTEL_CPU_FAM6(IVYBRIDGE, idle_cpu_ivb), 1085 INTEL_CPU_FAM6(IVYBRIDGE, idle_cpu_ivb),
1086 INTEL_CPU_FAM6(IVYBRIDGE_X, idle_cpu_ivt), 1086 INTEL_CPU_FAM6(IVYBRIDGE_X, idle_cpu_ivt),
@@ -1088,7 +1088,7 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
1088 INTEL_CPU_FAM6(HASWELL_X, idle_cpu_hsw), 1088 INTEL_CPU_FAM6(HASWELL_X, idle_cpu_hsw),
1089 INTEL_CPU_FAM6(HASWELL_ULT, idle_cpu_hsw), 1089 INTEL_CPU_FAM6(HASWELL_ULT, idle_cpu_hsw),
1090 INTEL_CPU_FAM6(HASWELL_GT3E, idle_cpu_hsw), 1090 INTEL_CPU_FAM6(HASWELL_GT3E, idle_cpu_hsw),
1091 INTEL_CPU_FAM6(ATOM_SILVERMONT2, idle_cpu_avn), 1091 INTEL_CPU_FAM6(ATOM_SILVERMONT_X, idle_cpu_avn),
1092 INTEL_CPU_FAM6(BROADWELL_CORE, idle_cpu_bdw), 1092 INTEL_CPU_FAM6(BROADWELL_CORE, idle_cpu_bdw),
1093 INTEL_CPU_FAM6(BROADWELL_GT3E, idle_cpu_bdw), 1093 INTEL_CPU_FAM6(BROADWELL_GT3E, idle_cpu_bdw),
1094 INTEL_CPU_FAM6(BROADWELL_X, idle_cpu_bdw), 1094 INTEL_CPU_FAM6(BROADWELL_X, idle_cpu_bdw),
@@ -1101,8 +1101,8 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
1101 INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl), 1101 INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl),
1102 INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl), 1102 INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl),
1103 INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt), 1103 INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt),
1104 INTEL_CPU_FAM6(ATOM_GEMINI_LAKE, idle_cpu_bxt), 1104 INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS, idle_cpu_bxt),
1105 INTEL_CPU_FAM6(ATOM_DENVERTON, idle_cpu_dnv), 1105 INTEL_CPU_FAM6(ATOM_GOLDMONT_X, idle_cpu_dnv),
1106 {} 1106 {}
1107}; 1107};
1108 1108
@@ -1319,7 +1319,7 @@ static void intel_idle_state_table_update(void)
1319 ivt_idle_state_table_update(); 1319 ivt_idle_state_table_update();
1320 break; 1320 break;
1321 case INTEL_FAM6_ATOM_GOLDMONT: 1321 case INTEL_FAM6_ATOM_GOLDMONT:
1322 case INTEL_FAM6_ATOM_GEMINI_LAKE: 1322 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
1323 bxt_idle_state_table_update(); 1323 bxt_idle_state_table_update();
1324 break; 1324 break;
1325 case INTEL_FAM6_SKYLAKE_DESKTOP: 1325 case INTEL_FAM6_SKYLAKE_DESKTOP:
diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index 82c9b9326e9e..057e24f4a620 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -247,7 +247,7 @@ static const struct sdhci_acpi_chip sdhci_acpi_chip_int = {
247static bool sdhci_acpi_byt(void) 247static bool sdhci_acpi_byt(void)
248{ 248{
249 static const struct x86_cpu_id byt[] = { 249 static const struct x86_cpu_id byt[] = {
250 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, 250 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT },
251 {} 251 {}
252 }; 252 };
253 253
diff --git a/drivers/pci/pci-mid.c b/drivers/pci/pci-mid.c
index 314e135014dc..30fbe2ea6eab 100644
--- a/drivers/pci/pci-mid.c
+++ b/drivers/pci/pci-mid.c
@@ -62,8 +62,8 @@ static const struct pci_platform_pm_ops mid_pci_platform_pm = {
62 * arch/x86/platform/intel-mid/pwr.c. 62 * arch/x86/platform/intel-mid/pwr.c.
63 */ 63 */
64static const struct x86_cpu_id lpss_cpu_ids[] = { 64static const struct x86_cpu_id lpss_cpu_ids[] = {
65 ICPU(INTEL_FAM6_ATOM_PENWELL), 65 ICPU(INTEL_FAM6_ATOM_SALTWELL_MID),
66 ICPU(INTEL_FAM6_ATOM_MERRIFIELD), 66 ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID),
67 {} 67 {}
68}; 68};
69 69
diff --git a/drivers/platform/x86/intel_int0002_vgpio.c b/drivers/platform/x86/intel_int0002_vgpio.c
index a473dc51b18d..e89ad4964dc1 100644
--- a/drivers/platform/x86/intel_int0002_vgpio.c
+++ b/drivers/platform/x86/intel_int0002_vgpio.c
@@ -60,7 +60,7 @@ static const struct x86_cpu_id int0002_cpu_ids[] = {
60/* 60/*
61 * Limit ourselves to Cherry Trail for now, until testing shows we 61 * Limit ourselves to Cherry Trail for now, until testing shows we
62 * need to handle the INT0002 device on Baytrail too. 62 * need to handle the INT0002 device on Baytrail too.
63 * ICPU(INTEL_FAM6_ATOM_SILVERMONT1), * Valleyview, Bay Trail * 63 * ICPU(INTEL_FAM6_ATOM_SILVERMONT), * Valleyview, Bay Trail *
64 */ 64 */
65 ICPU(INTEL_FAM6_ATOM_AIRMONT), /* Braswell, Cherry Trail */ 65 ICPU(INTEL_FAM6_ATOM_AIRMONT), /* Braswell, Cherry Trail */
66 {} 66 {}
diff --git a/drivers/platform/x86/intel_mid_powerbtn.c b/drivers/platform/x86/intel_mid_powerbtn.c
index d79fbf924b13..5ad44204a9c3 100644
--- a/drivers/platform/x86/intel_mid_powerbtn.c
+++ b/drivers/platform/x86/intel_mid_powerbtn.c
@@ -125,8 +125,8 @@ static const struct mid_pb_ddata mrfld_ddata = {
125 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (kernel_ulong_t)&ddata } 125 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (kernel_ulong_t)&ddata }
126 126
127static const struct x86_cpu_id mid_pb_cpu_ids[] = { 127static const struct x86_cpu_id mid_pb_cpu_ids[] = {
128 ICPU(INTEL_FAM6_ATOM_PENWELL, mfld_ddata), 128 ICPU(INTEL_FAM6_ATOM_SALTWELL_MID, mfld_ddata),
129 ICPU(INTEL_FAM6_ATOM_MERRIFIELD, mrfld_ddata), 129 ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID, mrfld_ddata),
130 {} 130 {}
131}; 131};
132 132
diff --git a/drivers/platform/x86/intel_telemetry_debugfs.c b/drivers/platform/x86/intel_telemetry_debugfs.c
index ffd0474b0531..cee08f236292 100644
--- a/drivers/platform/x86/intel_telemetry_debugfs.c
+++ b/drivers/platform/x86/intel_telemetry_debugfs.c
@@ -320,7 +320,7 @@ static struct telemetry_debugfs_conf telem_apl_debugfs_conf = {
320 320
321static const struct x86_cpu_id telemetry_debugfs_cpu_ids[] = { 321static const struct x86_cpu_id telemetry_debugfs_cpu_ids[] = {
322 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_debugfs_conf), 322 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_debugfs_conf),
323 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE, telem_apl_debugfs_conf), 323 TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS, telem_apl_debugfs_conf),
324 {} 324 {}
325}; 325};
326 326
diff --git a/drivers/platform/x86/intel_telemetry_pltdrv.c b/drivers/platform/x86/intel_telemetry_pltdrv.c
index 2f889d6c270e..fcc6bee51a42 100644
--- a/drivers/platform/x86/intel_telemetry_pltdrv.c
+++ b/drivers/platform/x86/intel_telemetry_pltdrv.c
@@ -192,7 +192,7 @@ static struct telemetry_plt_config telem_glk_config = {
192 192
193static const struct x86_cpu_id telemetry_cpu_ids[] = { 193static const struct x86_cpu_id telemetry_cpu_ids[] = {
194 TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_config), 194 TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_config),
195 TELEM_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE, telem_glk_config), 195 TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS, telem_glk_config),
196 {} 196 {}
197}; 197};
198 198
diff --git a/drivers/powercap/intel_rapl.c b/drivers/powercap/intel_rapl.c
index bb92874b1175..6cdb2c14eee4 100644
--- a/drivers/powercap/intel_rapl.c
+++ b/drivers/powercap/intel_rapl.c
@@ -1157,13 +1157,13 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {
1157 INTEL_CPU_FAM6(KABYLAKE_DESKTOP, rapl_defaults_core), 1157 INTEL_CPU_FAM6(KABYLAKE_DESKTOP, rapl_defaults_core),
1158 INTEL_CPU_FAM6(CANNONLAKE_MOBILE, rapl_defaults_core), 1158 INTEL_CPU_FAM6(CANNONLAKE_MOBILE, rapl_defaults_core),
1159 1159
1160 INTEL_CPU_FAM6(ATOM_SILVERMONT1, rapl_defaults_byt), 1160 INTEL_CPU_FAM6(ATOM_SILVERMONT, rapl_defaults_byt),
1161 INTEL_CPU_FAM6(ATOM_AIRMONT, rapl_defaults_cht), 1161 INTEL_CPU_FAM6(ATOM_AIRMONT, rapl_defaults_cht),
1162 INTEL_CPU_FAM6(ATOM_MERRIFIELD, rapl_defaults_tng), 1162 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, rapl_defaults_tng),
1163 INTEL_CPU_FAM6(ATOM_MOOREFIELD, rapl_defaults_ann), 1163 INTEL_CPU_FAM6(ATOM_AIRMONT_MID, rapl_defaults_ann),
1164 INTEL_CPU_FAM6(ATOM_GOLDMONT, rapl_defaults_core), 1164 INTEL_CPU_FAM6(ATOM_GOLDMONT, rapl_defaults_core),
1165 INTEL_CPU_FAM6(ATOM_GEMINI_LAKE, rapl_defaults_core), 1165 INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS, rapl_defaults_core),
1166 INTEL_CPU_FAM6(ATOM_DENVERTON, rapl_defaults_core), 1166 INTEL_CPU_FAM6(ATOM_GOLDMONT_X, rapl_defaults_core),
1167 1167
1168 INTEL_CPU_FAM6(XEON_PHI_KNL, rapl_defaults_hsw_server), 1168 INTEL_CPU_FAM6(XEON_PHI_KNL, rapl_defaults_hsw_server),
1169 INTEL_CPU_FAM6(XEON_PHI_KNM, rapl_defaults_hsw_server), 1169 INTEL_CPU_FAM6(XEON_PHI_KNM, rapl_defaults_hsw_server),
diff --git a/drivers/thermal/intel_soc_dts_thermal.c b/drivers/thermal/intel_soc_dts_thermal.c
index 1e47511a6bd5..d748527d7a38 100644
--- a/drivers/thermal/intel_soc_dts_thermal.c
+++ b/drivers/thermal/intel_soc_dts_thermal.c
@@ -45,7 +45,7 @@ static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
45} 45}
46 46
47static const struct x86_cpu_id soc_thermal_ids[] = { 47static const struct x86_cpu_id soc_thermal_ids[] = {
48 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1, 0, 48 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, 0,
49 BYT_SOC_DTS_APIC_IRQ}, 49 BYT_SOC_DTS_APIC_IRQ},
50 {} 50 {}
51}; 51};
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 5d3cf407e374..4a9937076331 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -459,10 +459,20 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
459 if (size || handle->aux_flags) { 459 if (size || handle->aux_flags) {
460 /* 460 /*
461 * Only send RECORD_AUX if we have something useful to communicate 461 * Only send RECORD_AUX if we have something useful to communicate
462 *
463 * Note: the OVERWRITE records by themselves are not considered
464 * useful, as they don't communicate any *new* information,
465 * aside from the short-lived offset, that becomes history at
466 * the next event sched-in and therefore isn't useful.
467 * The userspace that needs to copy out AUX data in overwrite
468 * mode should know to use user_page::aux_head for the actual
469 * offset. So, from now on we don't output AUX records that
470 * have *only* OVERWRITE flag set.
462 */ 471 */
463 472
464 perf_event_aux_event(handle->event, aux_head, size, 473 if (handle->aux_flags & ~(u64)PERF_AUX_FLAG_OVERWRITE)
465 handle->aux_flags); 474 perf_event_aux_event(handle->event, aux_head, size,
475 handle->aux_flags);
466 } 476 }
467 477
468 rb->user_page->aux_head = rb->aux_head; 478 rb->user_page->aux_head = rb->aux_head;
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index ab257be4d924..90e98e233647 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -546,8 +546,14 @@ static void do_free_cleaned_kprobes(void)
546 struct optimized_kprobe *op, *tmp; 546 struct optimized_kprobe *op, *tmp;
547 547
548 list_for_each_entry_safe(op, tmp, &freeing_list, list) { 548 list_for_each_entry_safe(op, tmp, &freeing_list, list) {
549 BUG_ON(!kprobe_unused(&op->kp));
550 list_del_init(&op->list); 549 list_del_init(&op->list);
550 if (WARN_ON_ONCE(!kprobe_unused(&op->kp))) {
551 /*
552 * This must not happen, but if there is a kprobe
553 * still in use, keep it on kprobes hash list.
554 */
555 continue;
556 }
551 free_aggr_kprobe(&op->kp); 557 free_aggr_kprobe(&op->kp);
552 } 558 }
553} 559}
@@ -700,11 +706,11 @@ static void unoptimize_kprobe(struct kprobe *p, bool force)
700} 706}
701 707
702/* Cancel unoptimizing for reusing */ 708/* Cancel unoptimizing for reusing */
703static void reuse_unused_kprobe(struct kprobe *ap) 709static int reuse_unused_kprobe(struct kprobe *ap)
704{ 710{
705 struct optimized_kprobe *op; 711 struct optimized_kprobe *op;
712 int ret;
706 713
707 BUG_ON(!kprobe_unused(ap));
708 /* 714 /*
709 * Unused kprobe MUST be on the way of delayed unoptimizing (means 715 * Unused kprobe MUST be on the way of delayed unoptimizing (means
710 * there is still a relative jump) and disabled. 716 * there is still a relative jump) and disabled.
@@ -714,8 +720,12 @@ static void reuse_unused_kprobe(struct kprobe *ap)
714 /* Enable the probe again */ 720 /* Enable the probe again */
715 ap->flags &= ~KPROBE_FLAG_DISABLED; 721 ap->flags &= ~KPROBE_FLAG_DISABLED;
716 /* Optimize it again (remove from op->list) */ 722 /* Optimize it again (remove from op->list) */
717 BUG_ON(!kprobe_optready(ap)); 723 ret = kprobe_optready(ap);
724 if (ret)
725 return ret;
726
718 optimize_kprobe(ap); 727 optimize_kprobe(ap);
728 return 0;
719} 729}
720 730
721/* Remove optimized instructions */ 731/* Remove optimized instructions */
@@ -940,11 +950,16 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt)
940#define kprobe_disarmed(p) kprobe_disabled(p) 950#define kprobe_disarmed(p) kprobe_disabled(p)
941#define wait_for_kprobe_optimizer() do {} while (0) 951#define wait_for_kprobe_optimizer() do {} while (0)
942 952
943/* There should be no unused kprobes can be reused without optimization */ 953static int reuse_unused_kprobe(struct kprobe *ap)
944static void reuse_unused_kprobe(struct kprobe *ap)
945{ 954{
955 /*
956 * If the optimized kprobe is NOT supported, the aggr kprobe is
957 * released at the same time that the last aggregated kprobe is
958 * unregistered.
959 * Thus there should be no chance to reuse unused kprobe.
960 */
946 printk(KERN_ERR "Error: There should be no unused kprobe here.\n"); 961 printk(KERN_ERR "Error: There should be no unused kprobe here.\n");
947 BUG_ON(kprobe_unused(ap)); 962 return -EINVAL;
948} 963}
949 964
950static void free_aggr_kprobe(struct kprobe *p) 965static void free_aggr_kprobe(struct kprobe *p)
@@ -1259,8 +1274,6 @@ NOKPROBE_SYMBOL(cleanup_rp_inst);
1259/* Add the new probe to ap->list */ 1274/* Add the new probe to ap->list */
1260static int add_new_kprobe(struct kprobe *ap, struct kprobe *p) 1275static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)
1261{ 1276{
1262 BUG_ON(kprobe_gone(ap) || kprobe_gone(p));
1263
1264 if (p->post_handler) 1277 if (p->post_handler)
1265 unoptimize_kprobe(ap, true); /* Fall back to normal kprobe */ 1278 unoptimize_kprobe(ap, true); /* Fall back to normal kprobe */
1266 1279
@@ -1318,9 +1331,12 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
1318 goto out; 1331 goto out;
1319 } 1332 }
1320 init_aggr_kprobe(ap, orig_p); 1333 init_aggr_kprobe(ap, orig_p);
1321 } else if (kprobe_unused(ap)) 1334 } else if (kprobe_unused(ap)) {
1322 /* This probe is going to die. Rescue it */ 1335 /* This probe is going to die. Rescue it */
1323 reuse_unused_kprobe(ap); 1336 ret = reuse_unused_kprobe(ap);
1337 if (ret)
1338 goto out;
1339 }
1324 1340
1325 if (kprobe_gone(ap)) { 1341 if (kprobe_gone(ap)) {
1326 /* 1342 /*
@@ -1704,7 +1720,6 @@ noclean:
1704 return 0; 1720 return 0;
1705 1721
1706disarmed: 1722disarmed:
1707 BUG_ON(!kprobe_disarmed(ap));
1708 hlist_del_rcu(&ap->hlist); 1723 hlist_del_rcu(&ap->hlist);
1709 return 0; 1724 return 0;
1710} 1725}
diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
index f8a68bdb3885..6af02bf879ac 100644
--- a/sound/soc/intel/boards/bytcr_rt5651.c
+++ b/sound/soc/intel/boards/bytcr_rt5651.c
@@ -787,7 +787,7 @@ static struct snd_soc_card byt_rt5651_card = {
787}; 787};
788 788
789static const struct x86_cpu_id baytrail_cpu_ids[] = { 789static const struct x86_cpu_id baytrail_cpu_ids[] = {
790 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, /* Valleyview */ 790 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT }, /* Valleyview */
791 {} 791 {}
792}; 792};
793 793
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index acc704bd3998..0b0ef3abc966 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -3,8 +3,6 @@
3#define _TOOLS_LINUX_BITOPS_H_ 3#define _TOOLS_LINUX_BITOPS_H_
4 4
5#include <asm/types.h> 5#include <asm/types.h>
6#include <linux/compiler.h>
7
8#ifndef __WORDSIZE 6#ifndef __WORDSIZE
9#define __WORDSIZE (__SIZEOF_LONG__ * 8) 7#define __WORDSIZE (__SIZEOF_LONG__ * 8)
10#endif 8#endif
@@ -12,10 +10,9 @@
12#ifndef BITS_PER_LONG 10#ifndef BITS_PER_LONG
13# define BITS_PER_LONG __WORDSIZE 11# define BITS_PER_LONG __WORDSIZE
14#endif 12#endif
13#include <linux/bits.h>
14#include <linux/compiler.h>
15 15
16#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
17#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
18#define BITS_PER_BYTE 8
19#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) 16#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
20#define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64)) 17#define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
21#define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) 18#define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))
diff --git a/tools/include/linux/bits.h b/tools/include/linux/bits.h
new file mode 100644
index 000000000000..2b7b532c1d51
--- /dev/null
+++ b/tools/include/linux/bits.h
@@ -0,0 +1,26 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __LINUX_BITS_H
3#define __LINUX_BITS_H
4#include <asm/bitsperlong.h>
5
6#define BIT(nr) (1UL << (nr))
7#define BIT_ULL(nr) (1ULL << (nr))
8#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
9#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
10#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
11#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
12#define BITS_PER_BYTE 8
13
14/*
15 * Create a contiguous bitmask starting at bit position @l and ending at
16 * position @h. For example
17 * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
18 */
19#define GENMASK(h, l) \
20 (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
21
22#define GENMASK_ULL(h, l) \
23 (((~0ULL) - (1ULL << (l)) + 1) & \
24 (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
25
26#endif /* __LINUX_BITS_H */
diff --git a/tools/include/linux/err.h b/tools/include/linux/err.h
index 7a8b61ad44cb..094649667bae 100644
--- a/tools/include/linux/err.h
+++ b/tools/include/linux/err.h
@@ -52,4 +52,11 @@ static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
52 return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr); 52 return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
53} 53}
54 54
55static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
56{
57 if (IS_ERR(ptr))
58 return PTR_ERR(ptr);
59 else
60 return 0;
61}
55#endif /* _LINUX_ERR_H */ 62#endif /* _LINUX_ERR_H */
diff --git a/tools/lib/subcmd/pager.c b/tools/lib/subcmd/pager.c
index 9997a8805a82..e3d47b59b14d 100644
--- a/tools/lib/subcmd/pager.c
+++ b/tools/lib/subcmd/pager.c
@@ -23,6 +23,13 @@ void pager_init(const char *pager_env)
23 subcmd_config.pager_env = pager_env; 23 subcmd_config.pager_env = pager_env;
24} 24}
25 25
26static const char *forced_pager;
27
28void force_pager(const char *pager)
29{
30 forced_pager = pager;
31}
32
26static void pager_preexec(void) 33static void pager_preexec(void)
27{ 34{
28 /* 35 /*
@@ -66,7 +73,9 @@ void setup_pager(void)
66 const char *pager = getenv(subcmd_config.pager_env); 73 const char *pager = getenv(subcmd_config.pager_env);
67 struct winsize sz; 74 struct winsize sz;
68 75
69 if (!isatty(1)) 76 if (forced_pager)
77 pager = forced_pager;
78 if (!isatty(1) && !forced_pager)
70 return; 79 return;
71 if (ioctl(1, TIOCGWINSZ, &sz) == 0) 80 if (ioctl(1, TIOCGWINSZ, &sz) == 0)
72 pager_columns = sz.ws_col; 81 pager_columns = sz.ws_col;
diff --git a/tools/lib/subcmd/pager.h b/tools/lib/subcmd/pager.h
index f1a53cf29880..a818964693ab 100644
--- a/tools/lib/subcmd/pager.h
+++ b/tools/lib/subcmd/pager.h
@@ -7,5 +7,6 @@ extern void pager_init(const char *pager_env);
7extern void setup_pager(void); 7extern void setup_pager(void);
8extern int pager_in_use(void); 8extern int pager_in_use(void);
9extern int pager_get_columns(void); 9extern int pager_get_columns(void);
10extern void force_pager(const char *);
10 11
11#endif /* __SUBCMD_PAGER_H */ 12#endif /* __SUBCMD_PAGER_H */
diff --git a/tools/lib/traceevent/Build b/tools/lib/traceevent/Build
index c681d0575d16..ba54bfce0b0b 100644
--- a/tools/lib/traceevent/Build
+++ b/tools/lib/traceevent/Build
@@ -4,6 +4,8 @@ libtraceevent-y += trace-seq.o
4libtraceevent-y += parse-filter.o 4libtraceevent-y += parse-filter.o
5libtraceevent-y += parse-utils.o 5libtraceevent-y += parse-utils.o
6libtraceevent-y += kbuffer-parse.o 6libtraceevent-y += kbuffer-parse.o
7libtraceevent-y += tep_strerror.o
8libtraceevent-y += event-parse-api.o
7 9
8plugin_jbd2-y += plugin_jbd2.o 10plugin_jbd2-y += plugin_jbd2.o
9plugin_hrtimer-y += plugin_hrtimer.o 11plugin_hrtimer-y += plugin_hrtimer.o
diff --git a/tools/lib/traceevent/event-parse-api.c b/tools/lib/traceevent/event-parse-api.c
new file mode 100644
index 000000000000..61f7149085ee
--- /dev/null
+++ b/tools/lib/traceevent/event-parse-api.c
@@ -0,0 +1,275 @@
1// SPDX-License-Identifier: LGPL-2.1
2/*
3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 *
5 */
6
7#include "event-parse.h"
8#include "event-parse-local.h"
9#include "event-utils.h"
10
11/**
12 * tep_get_first_event - returns the first event in the events array
13 * @tep: a handle to the tep_handle
14 *
15 * This returns pointer to the first element of the events array
16 * If @tep is NULL, NULL is returned.
17 */
18struct tep_event_format *tep_get_first_event(struct tep_handle *tep)
19{
20 if (tep && tep->events)
21 return tep->events[0];
22
23 return NULL;
24}
25
26/**
27 * tep_get_events_count - get the number of defined events
28 * @tep: a handle to the tep_handle
29 *
30 * This returns number of elements in event array
31 * If @tep is NULL, 0 is returned.
32 */
33int tep_get_events_count(struct tep_handle *tep)
34{
35 if(tep)
36 return tep->nr_events;
37 return 0;
38}
39
40/**
41 * tep_set_flag - set event parser flag
42 * @tep: a handle to the tep_handle
43 * @flag: flag, or combination of flags to be set
44 * can be any combination from enum tep_flag
45 *
46 * This sets a flag or mbination of flags from enum tep_flag
47 */
48void tep_set_flag(struct tep_handle *tep, int flag)
49{
50 if(tep)
51 tep->flags |= flag;
52}
53
54unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data)
55{
56 unsigned short swap;
57
58 if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
59 return data;
60
61 swap = ((data & 0xffULL) << 8) |
62 ((data & (0xffULL << 8)) >> 8);
63
64 return swap;
65}
66
67unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data)
68{
69 unsigned int swap;
70
71 if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
72 return data;
73
74 swap = ((data & 0xffULL) << 24) |
75 ((data & (0xffULL << 8)) << 8) |
76 ((data & (0xffULL << 16)) >> 8) |
77 ((data & (0xffULL << 24)) >> 24);
78
79 return swap;
80}
81
82unsigned long long
83__tep_data2host8(struct tep_handle *pevent, unsigned long long data)
84{
85 unsigned long long swap;
86
87 if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
88 return data;
89
90 swap = ((data & 0xffULL) << 56) |
91 ((data & (0xffULL << 8)) << 40) |
92 ((data & (0xffULL << 16)) << 24) |
93 ((data & (0xffULL << 24)) << 8) |
94 ((data & (0xffULL << 32)) >> 8) |
95 ((data & (0xffULL << 40)) >> 24) |
96 ((data & (0xffULL << 48)) >> 40) |
97 ((data & (0xffULL << 56)) >> 56);
98
99 return swap;
100}
101
102/**
103 * tep_get_header_page_size - get size of the header page
104 * @pevent: a handle to the tep_handle
105 *
106 * This returns size of the header page
107 * If @pevent is NULL, 0 is returned.
108 */
109int tep_get_header_page_size(struct tep_handle *pevent)
110{
111 if(pevent)
112 return pevent->header_page_size_size;
113 return 0;
114}
115
116/**
117 * tep_get_cpus - get the number of CPUs
118 * @pevent: a handle to the tep_handle
119 *
120 * This returns the number of CPUs
121 * If @pevent is NULL, 0 is returned.
122 */
123int tep_get_cpus(struct tep_handle *pevent)
124{
125 if(pevent)
126 return pevent->cpus;
127 return 0;
128}
129
130/**
131 * tep_set_cpus - set the number of CPUs
132 * @pevent: a handle to the tep_handle
133 *
134 * This sets the number of CPUs
135 */
136void tep_set_cpus(struct tep_handle *pevent, int cpus)
137{
138 if(pevent)
139 pevent->cpus = cpus;
140}
141
142/**
143 * tep_get_long_size - get the size of a long integer on the current machine
144 * @pevent: a handle to the tep_handle
145 *
146 * This returns the size of a long integer on the current machine
147 * If @pevent is NULL, 0 is returned.
148 */
149int tep_get_long_size(struct tep_handle *pevent)
150{
151 if(pevent)
152 return pevent->long_size;
153 return 0;
154}
155
156/**
157 * tep_set_long_size - set the size of a long integer on the current machine
158 * @pevent: a handle to the tep_handle
159 * @size: size, in bytes, of a long integer
160 *
161 * This sets the size of a long integer on the current machine
162 */
163void tep_set_long_size(struct tep_handle *pevent, int long_size)
164{
165 if(pevent)
166 pevent->long_size = long_size;
167}
168
169/**
170 * tep_get_page_size - get the size of a memory page on the current machine
171 * @pevent: a handle to the tep_handle
172 *
173 * This returns the size of a memory page on the current machine
174 * If @pevent is NULL, 0 is returned.
175 */
176int tep_get_page_size(struct tep_handle *pevent)
177{
178 if(pevent)
179 return pevent->page_size;
180 return 0;
181}
182
183/**
184 * tep_set_page_size - set the size of a memory page on the current machine
185 * @pevent: a handle to the tep_handle
186 * @_page_size: size of a memory page, in bytes
187 *
188 * This sets the size of a memory page on the current machine
189 */
190void tep_set_page_size(struct tep_handle *pevent, int _page_size)
191{
192 if(pevent)
193 pevent->page_size = _page_size;
194}
195
196/**
197 * tep_is_file_bigendian - get if the file is in big endian order
198 * @pevent: a handle to the tep_handle
199 *
200 * This returns if the file is in big endian order
201 * If @pevent is NULL, 0 is returned.
202 */
203int tep_is_file_bigendian(struct tep_handle *pevent)
204{
205 if(pevent)
206 return pevent->file_bigendian;
207 return 0;
208}
209
210/**
211 * tep_set_file_bigendian - set if the file is in big endian order
212 * @pevent: a handle to the tep_handle
213 * @endian: non zero, if the file is in big endian order
214 *
215 * This sets if the file is in big endian order
216 */
217void tep_set_file_bigendian(struct tep_handle *pevent, enum tep_endian endian)
218{
219 if(pevent)
220 pevent->file_bigendian = endian;
221}
222
223/**
224 * tep_is_host_bigendian - get if the order of the current host is big endian
225 * @pevent: a handle to the tep_handle
226 *
227 * This gets if the order of the current host is big endian
228 * If @pevent is NULL, 0 is returned.
229 */
230int tep_is_host_bigendian(struct tep_handle *pevent)
231{
232 if(pevent)
233 return pevent->host_bigendian;
234 return 0;
235}
236
237/**
238 * tep_set_host_bigendian - set the order of the local host
239 * @pevent: a handle to the tep_handle
240 * @endian: non zero, if the local host has big endian order
241 *
242 * This sets the order of the local host
243 */
244void tep_set_host_bigendian(struct tep_handle *pevent, enum tep_endian endian)
245{
246 if(pevent)
247 pevent->host_bigendian = endian;
248}
249
250/**
251 * tep_is_latency_format - get if the latency output format is configured
252 * @pevent: a handle to the tep_handle
253 *
254 * This gets if the latency output format is configured
255 * If @pevent is NULL, 0 is returned.
256 */
257int tep_is_latency_format(struct tep_handle *pevent)
258{
259 if(pevent)
260 return pevent->latency_format;
261 return 0;
262}
263
264/**
265 * tep_set_latency_format - set the latency output format
266 * @pevent: a handle to the tep_handle
267 * @lat: non zero for latency output format
268 *
269 * This sets the latency output format
270 */
271void tep_set_latency_format(struct tep_handle *pevent, int lat)
272{
273 if(pevent)
274 pevent->latency_format = lat;
275}
diff --git a/tools/lib/traceevent/event-parse-local.h b/tools/lib/traceevent/event-parse-local.h
new file mode 100644
index 000000000000..b9bddde577f8
--- /dev/null
+++ b/tools/lib/traceevent/event-parse-local.h
@@ -0,0 +1,92 @@
1// SPDX-License-Identifier: LGPL-2.1
2/*
3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 *
5 */
6
7#ifndef _PARSE_EVENTS_INT_H
8#define _PARSE_EVENTS_INT_H
9
10struct cmdline;
11struct cmdline_list;
12struct func_map;
13struct func_list;
14struct event_handler;
15struct func_resolver;
16
17struct tep_handle {
18 int ref_count;
19
20 int header_page_ts_offset;
21 int header_page_ts_size;
22 int header_page_size_offset;
23 int header_page_size_size;
24 int header_page_data_offset;
25 int header_page_data_size;
26 int header_page_overwrite;
27
28 enum tep_endian file_bigendian;
29 enum tep_endian host_bigendian;
30
31 int latency_format;
32
33 int old_format;
34
35 int cpus;
36 int long_size;
37 int page_size;
38
39 struct cmdline *cmdlines;
40 struct cmdline_list *cmdlist;
41 int cmdline_count;
42
43 struct func_map *func_map;
44 struct func_resolver *func_resolver;
45 struct func_list *funclist;
46 unsigned int func_count;
47
48 struct printk_map *printk_map;
49 struct printk_list *printklist;
50 unsigned int printk_count;
51
52
53 struct tep_event_format **events;
54 int nr_events;
55 struct tep_event_format **sort_events;
56 enum tep_event_sort_type last_type;
57
58 int type_offset;
59 int type_size;
60
61 int pid_offset;
62 int pid_size;
63
64 int pc_offset;
65 int pc_size;
66
67 int flags_offset;
68 int flags_size;
69
70 int ld_offset;
71 int ld_size;
72
73 int print_raw;
74
75 int test_filters;
76
77 int flags;
78
79 struct tep_format_field *bprint_ip_field;
80 struct tep_format_field *bprint_fmt_field;
81 struct tep_format_field *bprint_buf_field;
82
83 struct event_handler *handlers;
84 struct tep_function_handler *func_handlers;
85
86 /* cache */
87 struct tep_event_format *last_event;
88
89 char *trace_clock;
90};
91
92#endif /* _PARSE_EVENTS_INT_H */
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index ce1e20227c64..3692f29fee46 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -18,12 +18,14 @@
18#include <errno.h> 18#include <errno.h>
19#include <stdint.h> 19#include <stdint.h>
20#include <limits.h> 20#include <limits.h>
21#include <linux/string.h>
22#include <linux/time64.h> 21#include <linux/time64.h>
23 22
24#include <netinet/in.h> 23#include <netinet/in.h>
25#include "event-parse.h" 24#include "event-parse.h"
25
26#include "event-parse-local.h"
26#include "event-utils.h" 27#include "event-utils.h"
28#include "trace-seq.h"
27 29
28static const char *input_buf; 30static const char *input_buf;
29static unsigned long long input_buf_ptr; 31static unsigned long long input_buf_ptr;
@@ -94,7 +96,7 @@ struct tep_function_handler {
94 96
95static unsigned long long 97static unsigned long long
96process_defined_func(struct trace_seq *s, void *data, int size, 98process_defined_func(struct trace_seq *s, void *data, int size,
97 struct event_format *event, struct print_arg *arg); 99 struct tep_event_format *event, struct tep_print_arg *arg);
98 100
99static void free_func_handle(struct tep_function_handler *func); 101static void free_func_handle(struct tep_function_handler *func);
100 102
@@ -117,9 +119,9 @@ void breakpoint(void)
117 x++; 119 x++;
118} 120}
119 121
120struct print_arg *alloc_arg(void) 122struct tep_print_arg *alloc_arg(void)
121{ 123{
122 return calloc(1, sizeof(struct print_arg)); 124 return calloc(1, sizeof(struct tep_print_arg));
123} 125}
124 126
125struct cmdline { 127struct cmdline {
@@ -737,16 +739,16 @@ void tep_print_printk(struct tep_handle *pevent)
737 } 739 }
738} 740}
739 741
740static struct event_format *alloc_event(void) 742static struct tep_event_format *alloc_event(void)
741{ 743{
742 return calloc(1, sizeof(struct event_format)); 744 return calloc(1, sizeof(struct tep_event_format));
743} 745}
744 746
745static int add_event(struct tep_handle *pevent, struct event_format *event) 747static int add_event(struct tep_handle *pevent, struct tep_event_format *event)
746{ 748{
747 int i; 749 int i;
748 struct event_format **events = realloc(pevent->events, sizeof(event) * 750 struct tep_event_format **events = realloc(pevent->events, sizeof(event) *
749 (pevent->nr_events + 1)); 751 (pevent->nr_events + 1));
750 if (!events) 752 if (!events)
751 return -1; 753 return -1;
752 754
@@ -769,20 +771,20 @@ static int add_event(struct tep_handle *pevent, struct event_format *event)
769 return 0; 771 return 0;
770} 772}
771 773
772static int event_item_type(enum event_type type) 774static int event_item_type(enum tep_event_type type)
773{ 775{
774 switch (type) { 776 switch (type) {
775 case EVENT_ITEM ... EVENT_SQUOTE: 777 case TEP_EVENT_ITEM ... TEP_EVENT_SQUOTE:
776 return 1; 778 return 1;
777 case EVENT_ERROR ... EVENT_DELIM: 779 case TEP_EVENT_ERROR ... TEP_EVENT_DELIM:
778 default: 780 default:
779 return 0; 781 return 0;
780 } 782 }
781} 783}
782 784
783static void free_flag_sym(struct print_flag_sym *fsym) 785static void free_flag_sym(struct tep_print_flag_sym *fsym)
784{ 786{
785 struct print_flag_sym *next; 787 struct tep_print_flag_sym *next;
786 788
787 while (fsym) { 789 while (fsym) {
788 next = fsym->next; 790 next = fsym->next;
@@ -793,60 +795,60 @@ static void free_flag_sym(struct print_flag_sym *fsym)
793 } 795 }
794} 796}
795 797
796static void free_arg(struct print_arg *arg) 798static void free_arg(struct tep_print_arg *arg)
797{ 799{
798 struct print_arg *farg; 800 struct tep_print_arg *farg;
799 801
800 if (!arg) 802 if (!arg)
801 return; 803 return;
802 804
803 switch (arg->type) { 805 switch (arg->type) {
804 case PRINT_ATOM: 806 case TEP_PRINT_ATOM:
805 free(arg->atom.atom); 807 free(arg->atom.atom);
806 break; 808 break;
807 case PRINT_FIELD: 809 case TEP_PRINT_FIELD:
808 free(arg->field.name); 810 free(arg->field.name);
809 break; 811 break;
810 case PRINT_FLAGS: 812 case TEP_PRINT_FLAGS:
811 free_arg(arg->flags.field); 813 free_arg(arg->flags.field);
812 free(arg->flags.delim); 814 free(arg->flags.delim);
813 free_flag_sym(arg->flags.flags); 815 free_flag_sym(arg->flags.flags);
814 break; 816 break;
815 case PRINT_SYMBOL: 817 case TEP_PRINT_SYMBOL:
816 free_arg(arg->symbol.field); 818 free_arg(arg->symbol.field);
817 free_flag_sym(arg->symbol.symbols); 819 free_flag_sym(arg->symbol.symbols);
818 break; 820 break;
819 case PRINT_HEX: 821 case TEP_PRINT_HEX:
820 case PRINT_HEX_STR: 822 case TEP_PRINT_HEX_STR:
821 free_arg(arg->hex.field); 823 free_arg(arg->hex.field);
822 free_arg(arg->hex.size); 824 free_arg(arg->hex.size);
823 break; 825 break;
824 case PRINT_INT_ARRAY: 826 case TEP_PRINT_INT_ARRAY:
825 free_arg(arg->int_array.field); 827 free_arg(arg->int_array.field);
826 free_arg(arg->int_array.count); 828 free_arg(arg->int_array.count);
827 free_arg(arg->int_array.el_size); 829 free_arg(arg->int_array.el_size);
828 break; 830 break;
829 case PRINT_TYPE: 831 case TEP_PRINT_TYPE:
830 free(arg->typecast.type); 832 free(arg->typecast.type);
831 free_arg(arg->typecast.item); 833 free_arg(arg->typecast.item);
832 break; 834 break;
833 case PRINT_STRING: 835 case TEP_PRINT_STRING:
834 case PRINT_BSTRING: 836 case TEP_PRINT_BSTRING:
835 free(arg->string.string); 837 free(arg->string.string);
836 break; 838 break;
837 case PRINT_BITMASK: 839 case TEP_PRINT_BITMASK:
838 free(arg->bitmask.bitmask); 840 free(arg->bitmask.bitmask);
839 break; 841 break;
840 case PRINT_DYNAMIC_ARRAY: 842 case TEP_PRINT_DYNAMIC_ARRAY:
841 case PRINT_DYNAMIC_ARRAY_LEN: 843 case TEP_PRINT_DYNAMIC_ARRAY_LEN:
842 free(arg->dynarray.index); 844 free(arg->dynarray.index);
843 break; 845 break;
844 case PRINT_OP: 846 case TEP_PRINT_OP:
845 free(arg->op.op); 847 free(arg->op.op);
846 free_arg(arg->op.left); 848 free_arg(arg->op.left);
847 free_arg(arg->op.right); 849 free_arg(arg->op.right);
848 break; 850 break;
849 case PRINT_FUNC: 851 case TEP_PRINT_FUNC:
850 while (arg->func.args) { 852 while (arg->func.args) {
851 farg = arg->func.args; 853 farg = arg->func.args;
852 arg->func.args = farg->next; 854 arg->func.args = farg->next;
@@ -854,7 +856,7 @@ static void free_arg(struct print_arg *arg)
854 } 856 }
855 break; 857 break;
856 858
857 case PRINT_NULL: 859 case TEP_PRINT_NULL:
858 default: 860 default:
859 break; 861 break;
860 } 862 }
@@ -862,24 +864,24 @@ static void free_arg(struct print_arg *arg)
862 free(arg); 864 free(arg);
863} 865}
864 866
865static enum event_type get_type(int ch) 867static enum tep_event_type get_type(int ch)
866{ 868{
867 if (ch == '\n') 869 if (ch == '\n')
868 return EVENT_NEWLINE; 870 return TEP_EVENT_NEWLINE;
869 if (isspace(ch)) 871 if (isspace(ch))
870 return EVENT_SPACE; 872 return TEP_EVENT_SPACE;
871 if (isalnum(ch) || ch == '_') 873 if (isalnum(ch) || ch == '_')
872 return EVENT_ITEM; 874 return TEP_EVENT_ITEM;
873 if (ch == '\'') 875 if (ch == '\'')
874 return EVENT_SQUOTE; 876 return TEP_EVENT_SQUOTE;
875 if (ch == '"') 877 if (ch == '"')
876 return EVENT_DQUOTE; 878 return TEP_EVENT_DQUOTE;
877 if (!isprint(ch)) 879 if (!isprint(ch))
878 return EVENT_NONE; 880 return TEP_EVENT_NONE;
879 if (ch == '(' || ch == ')' || ch == ',') 881 if (ch == '(' || ch == ')' || ch == ',')
880 return EVENT_DELIM; 882 return TEP_EVENT_DELIM;
881 883
882 return EVENT_OP; 884 return TEP_EVENT_OP;
883} 885}
884 886
885static int __read_char(void) 887static int __read_char(void)
@@ -927,38 +929,38 @@ static int extend_token(char **tok, char *buf, int size)
927 return 0; 929 return 0;
928} 930}
929 931
930static enum event_type force_token(const char *str, char **tok); 932static enum tep_event_type force_token(const char *str, char **tok);
931 933
932static enum event_type __read_token(char **tok) 934static enum tep_event_type __read_token(char **tok)
933{ 935{
934 char buf[BUFSIZ]; 936 char buf[BUFSIZ];
935 int ch, last_ch, quote_ch, next_ch; 937 int ch, last_ch, quote_ch, next_ch;
936 int i = 0; 938 int i = 0;
937 int tok_size = 0; 939 int tok_size = 0;
938 enum event_type type; 940 enum tep_event_type type;
939 941
940 *tok = NULL; 942 *tok = NULL;
941 943
942 944
943 ch = __read_char(); 945 ch = __read_char();
944 if (ch < 0) 946 if (ch < 0)
945 return EVENT_NONE; 947 return TEP_EVENT_NONE;
946 948
947 type = get_type(ch); 949 type = get_type(ch);
948 if (type == EVENT_NONE) 950 if (type == TEP_EVENT_NONE)
949 return type; 951 return type;
950 952
951 buf[i++] = ch; 953 buf[i++] = ch;
952 954
953 switch (type) { 955 switch (type) {
954 case EVENT_NEWLINE: 956 case TEP_EVENT_NEWLINE:
955 case EVENT_DELIM: 957 case TEP_EVENT_DELIM:
956 if (asprintf(tok, "%c", ch) < 0) 958 if (asprintf(tok, "%c", ch) < 0)
957 return EVENT_ERROR; 959 return TEP_EVENT_ERROR;
958 960
959 return type; 961 return type;
960 962
961 case EVENT_OP: 963 case TEP_EVENT_OP:
962 switch (ch) { 964 switch (ch) {
963 case '-': 965 case '-':
964 next_ch = __peek_char(); 966 next_ch = __peek_char();
@@ -1001,8 +1003,8 @@ static enum event_type __read_token(char **tok)
1001 buf[i++] = __read_char(); 1003 buf[i++] = __read_char();
1002 goto out; 1004 goto out;
1003 1005
1004 case EVENT_DQUOTE: 1006 case TEP_EVENT_DQUOTE:
1005 case EVENT_SQUOTE: 1007 case TEP_EVENT_SQUOTE:
1006 /* don't keep quotes */ 1008 /* don't keep quotes */
1007 i--; 1009 i--;
1008 quote_ch = ch; 1010 quote_ch = ch;
@@ -1014,7 +1016,7 @@ static enum event_type __read_token(char **tok)
1014 tok_size += BUFSIZ; 1016 tok_size += BUFSIZ;
1015 1017
1016 if (extend_token(tok, buf, tok_size) < 0) 1018 if (extend_token(tok, buf, tok_size) < 0)
1017 return EVENT_NONE; 1019 return TEP_EVENT_NONE;
1018 i = 0; 1020 i = 0;
1019 } 1021 }
1020 last_ch = ch; 1022 last_ch = ch;
@@ -1031,7 +1033,7 @@ static enum event_type __read_token(char **tok)
1031 * For strings (double quotes) check the next token. 1033 * For strings (double quotes) check the next token.
1032 * If it is another string, concatinate the two. 1034 * If it is another string, concatinate the two.
1033 */ 1035 */
1034 if (type == EVENT_DQUOTE) { 1036 if (type == TEP_EVENT_DQUOTE) {
1035 unsigned long long save_input_buf_ptr = input_buf_ptr; 1037 unsigned long long save_input_buf_ptr = input_buf_ptr;
1036 1038
1037 do { 1039 do {
@@ -1044,8 +1046,8 @@ static enum event_type __read_token(char **tok)
1044 1046
1045 goto out; 1047 goto out;
1046 1048
1047 case EVENT_ERROR ... EVENT_SPACE: 1049 case TEP_EVENT_ERROR ... TEP_EVENT_SPACE:
1048 case EVENT_ITEM: 1050 case TEP_EVENT_ITEM:
1049 default: 1051 default:
1050 break; 1052 break;
1051 } 1053 }
@@ -1056,7 +1058,7 @@ static enum event_type __read_token(char **tok)
1056 tok_size += BUFSIZ; 1058 tok_size += BUFSIZ;
1057 1059
1058 if (extend_token(tok, buf, tok_size) < 0) 1060 if (extend_token(tok, buf, tok_size) < 0)
1059 return EVENT_NONE; 1061 return TEP_EVENT_NONE;
1060 i = 0; 1062 i = 0;
1061 } 1063 }
1062 ch = __read_char(); 1064 ch = __read_char();
@@ -1066,9 +1068,9 @@ static enum event_type __read_token(char **tok)
1066 out: 1068 out:
1067 buf[i] = 0; 1069 buf[i] = 0;
1068 if (extend_token(tok, buf, tok_size + i + 1) < 0) 1070 if (extend_token(tok, buf, tok_size + i + 1) < 0)
1069 return EVENT_NONE; 1071 return TEP_EVENT_NONE;
1070 1072
1071 if (type == EVENT_ITEM) { 1073 if (type == TEP_EVENT_ITEM) {
1072 /* 1074 /*
1073 * Older versions of the kernel has a bug that 1075 * Older versions of the kernel has a bug that
1074 * creates invalid symbols and will break the mac80211 1076 * creates invalid symbols and will break the mac80211
@@ -1095,12 +1097,12 @@ static enum event_type __read_token(char **tok)
1095 return type; 1097 return type;
1096} 1098}
1097 1099
1098static enum event_type force_token(const char *str, char **tok) 1100static enum tep_event_type force_token(const char *str, char **tok)
1099{ 1101{
1100 const char *save_input_buf; 1102 const char *save_input_buf;
1101 unsigned long long save_input_buf_ptr; 1103 unsigned long long save_input_buf_ptr;
1102 unsigned long long save_input_buf_siz; 1104 unsigned long long save_input_buf_siz;
1103 enum event_type type; 1105 enum tep_event_type type;
1104 1106
1105 /* save off the current input pointers */ 1107 /* save off the current input pointers */
1106 save_input_buf = input_buf; 1108 save_input_buf = input_buf;
@@ -1125,13 +1127,13 @@ static void free_token(char *tok)
1125 free(tok); 1127 free(tok);
1126} 1128}
1127 1129
1128static enum event_type read_token(char **tok) 1130static enum tep_event_type read_token(char **tok)
1129{ 1131{
1130 enum event_type type; 1132 enum tep_event_type type;
1131 1133
1132 for (;;) { 1134 for (;;) {
1133 type = __read_token(tok); 1135 type = __read_token(tok);
1134 if (type != EVENT_SPACE) 1136 if (type != TEP_EVENT_SPACE)
1135 return type; 1137 return type;
1136 1138
1137 free_token(*tok); 1139 free_token(*tok);
@@ -1139,7 +1141,7 @@ static enum event_type read_token(char **tok)
1139 1141
1140 /* not reached */ 1142 /* not reached */
1141 *tok = NULL; 1143 *tok = NULL;
1142 return EVENT_NONE; 1144 return TEP_EVENT_NONE;
1143} 1145}
1144 1146
1145/** 1147/**
@@ -1151,7 +1153,7 @@ static enum event_type read_token(char **tok)
1151 * 1153 *
1152 * Returns the token type. 1154 * Returns the token type.
1153 */ 1155 */
1154enum event_type tep_read_token(char **tok) 1156enum tep_event_type tep_read_token(char **tok)
1155{ 1157{
1156 return read_token(tok); 1158 return read_token(tok);
1157} 1159}
@@ -1166,13 +1168,13 @@ void tep_free_token(char *token)
1166} 1168}
1167 1169
1168/* no newline */ 1170/* no newline */
1169static enum event_type read_token_item(char **tok) 1171static enum tep_event_type read_token_item(char **tok)
1170{ 1172{
1171 enum event_type type; 1173 enum tep_event_type type;
1172 1174
1173 for (;;) { 1175 for (;;) {
1174 type = __read_token(tok); 1176 type = __read_token(tok);
1175 if (type != EVENT_SPACE && type != EVENT_NEWLINE) 1177 if (type != TEP_EVENT_SPACE && type != TEP_EVENT_NEWLINE)
1176 return type; 1178 return type;
1177 free_token(*tok); 1179 free_token(*tok);
1178 *tok = NULL; 1180 *tok = NULL;
@@ -1180,10 +1182,10 @@ static enum event_type read_token_item(char **tok)
1180 1182
1181 /* not reached */ 1183 /* not reached */
1182 *tok = NULL; 1184 *tok = NULL;
1183 return EVENT_NONE; 1185 return TEP_EVENT_NONE;
1184} 1186}
1185 1187
1186static int test_type(enum event_type type, enum event_type expect) 1188static int test_type(enum tep_event_type type, enum tep_event_type expect)
1187{ 1189{
1188 if (type != expect) { 1190 if (type != expect) {
1189 do_warning("Error: expected type %d but read %d", 1191 do_warning("Error: expected type %d but read %d",
@@ -1193,8 +1195,8 @@ static int test_type(enum event_type type, enum event_type expect)
1193 return 0; 1195 return 0;
1194} 1196}
1195 1197
1196static int test_type_token(enum event_type type, const char *token, 1198static int test_type_token(enum tep_event_type type, const char *token,
1197 enum event_type expect, const char *expect_tok) 1199 enum tep_event_type expect, const char *expect_tok)
1198{ 1200{
1199 if (type != expect) { 1201 if (type != expect) {
1200 do_warning("Error: expected type %d but read %d", 1202 do_warning("Error: expected type %d but read %d",
@@ -1210,9 +1212,9 @@ static int test_type_token(enum event_type type, const char *token,
1210 return 0; 1212 return 0;
1211} 1213}
1212 1214
1213static int __read_expect_type(enum event_type expect, char **tok, int newline_ok) 1215static int __read_expect_type(enum tep_event_type expect, char **tok, int newline_ok)
1214{ 1216{
1215 enum event_type type; 1217 enum tep_event_type type;
1216 1218
1217 if (newline_ok) 1219 if (newline_ok)
1218 type = read_token(tok); 1220 type = read_token(tok);
@@ -1221,15 +1223,15 @@ static int __read_expect_type(enum event_type expect, char **tok, int newline_ok
1221 return test_type(type, expect); 1223 return test_type(type, expect);
1222} 1224}
1223 1225
1224static int read_expect_type(enum event_type expect, char **tok) 1226static int read_expect_type(enum tep_event_type expect, char **tok)
1225{ 1227{
1226 return __read_expect_type(expect, tok, 1); 1228 return __read_expect_type(expect, tok, 1);
1227} 1229}
1228 1230
1229static int __read_expected(enum event_type expect, const char *str, 1231static int __read_expected(enum tep_event_type expect, const char *str,
1230 int newline_ok) 1232 int newline_ok)
1231{ 1233{
1232 enum event_type type; 1234 enum tep_event_type type;
1233 char *token; 1235 char *token;
1234 int ret; 1236 int ret;
1235 1237
@@ -1245,12 +1247,12 @@ static int __read_expected(enum event_type expect, const char *str,
1245 return ret; 1247 return ret;
1246} 1248}
1247 1249
1248static int read_expected(enum event_type expect, const char *str) 1250static int read_expected(enum tep_event_type expect, const char *str)
1249{ 1251{
1250 return __read_expected(expect, str, 1); 1252 return __read_expected(expect, str, 1);
1251} 1253}
1252 1254
1253static int read_expected_item(enum event_type expect, const char *str) 1255static int read_expected_item(enum tep_event_type expect, const char *str)
1254{ 1256{
1255 return __read_expected(expect, str, 0); 1257 return __read_expected(expect, str, 0);
1256} 1258}
@@ -1259,13 +1261,13 @@ static char *event_read_name(void)
1259{ 1261{
1260 char *token; 1262 char *token;
1261 1263
1262 if (read_expected(EVENT_ITEM, "name") < 0) 1264 if (read_expected(TEP_EVENT_ITEM, "name") < 0)
1263 return NULL; 1265 return NULL;
1264 1266
1265 if (read_expected(EVENT_OP, ":") < 0) 1267 if (read_expected(TEP_EVENT_OP, ":") < 0)
1266 return NULL; 1268 return NULL;
1267 1269
1268 if (read_expect_type(EVENT_ITEM, &token) < 0) 1270 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
1269 goto fail; 1271 goto fail;
1270 1272
1271 return token; 1273 return token;
@@ -1280,13 +1282,13 @@ static int event_read_id(void)
1280 char *token; 1282 char *token;
1281 int id; 1283 int id;
1282 1284
1283 if (read_expected_item(EVENT_ITEM, "ID") < 0) 1285 if (read_expected_item(TEP_EVENT_ITEM, "ID") < 0)
1284 return -1; 1286 return -1;
1285 1287
1286 if (read_expected(EVENT_OP, ":") < 0) 1288 if (read_expected(TEP_EVENT_OP, ":") < 0)
1287 return -1; 1289 return -1;
1288 1290
1289 if (read_expect_type(EVENT_ITEM, &token) < 0) 1291 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
1290 goto fail; 1292 goto fail;
1291 1293
1292 id = strtoul(token, NULL, 0); 1294 id = strtoul(token, NULL, 0);
@@ -1298,9 +1300,9 @@ static int event_read_id(void)
1298 return -1; 1300 return -1;
1299} 1301}
1300 1302
1301static int field_is_string(struct format_field *field) 1303static int field_is_string(struct tep_format_field *field)
1302{ 1304{
1303 if ((field->flags & FIELD_IS_ARRAY) && 1305 if ((field->flags & TEP_FIELD_IS_ARRAY) &&
1304 (strstr(field->type, "char") || strstr(field->type, "u8") || 1306 (strstr(field->type, "char") || strstr(field->type, "u8") ||
1305 strstr(field->type, "s8"))) 1307 strstr(field->type, "s8")))
1306 return 1; 1308 return 1;
@@ -1308,7 +1310,7 @@ static int field_is_string(struct format_field *field)
1308 return 0; 1310 return 0;
1309} 1311}
1310 1312
1311static int field_is_dynamic(struct format_field *field) 1313static int field_is_dynamic(struct tep_format_field *field)
1312{ 1314{
1313 if (strncmp(field->type, "__data_loc", 10) == 0) 1315 if (strncmp(field->type, "__data_loc", 10) == 0)
1314 return 1; 1316 return 1;
@@ -1316,7 +1318,7 @@ static int field_is_dynamic(struct format_field *field)
1316 return 0; 1318 return 0;
1317} 1319}
1318 1320
1319static int field_is_long(struct format_field *field) 1321static int field_is_long(struct tep_format_field *field)
1320{ 1322{
1321 /* includes long long */ 1323 /* includes long long */
1322 if (strstr(field->type, "long")) 1324 if (strstr(field->type, "long"))
@@ -1327,7 +1329,7 @@ static int field_is_long(struct format_field *field)
1327 1329
1328static unsigned int type_size(const char *name) 1330static unsigned int type_size(const char *name)
1329{ 1331{
1330 /* This covers all FIELD_IS_STRING types. */ 1332 /* This covers all TEP_FIELD_IS_STRING types. */
1331 static struct { 1333 static struct {
1332 const char *type; 1334 const char *type;
1333 unsigned int size; 1335 unsigned int size;
@@ -1353,10 +1355,10 @@ static unsigned int type_size(const char *name)
1353 return 0; 1355 return 0;
1354} 1356}
1355 1357
1356static int event_read_fields(struct event_format *event, struct format_field **fields) 1358static int event_read_fields(struct tep_event_format *event, struct tep_format_field **fields)
1357{ 1359{
1358 struct format_field *field = NULL; 1360 struct tep_format_field *field = NULL;
1359 enum event_type type; 1361 enum tep_event_type type;
1360 char *token; 1362 char *token;
1361 char *last_token; 1363 char *last_token;
1362 int count = 0; 1364 int count = 0;
@@ -1365,14 +1367,14 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1365 unsigned int size_dynamic = 0; 1367 unsigned int size_dynamic = 0;
1366 1368
1367 type = read_token(&token); 1369 type = read_token(&token);
1368 if (type == EVENT_NEWLINE) { 1370 if (type == TEP_EVENT_NEWLINE) {
1369 free_token(token); 1371 free_token(token);
1370 return count; 1372 return count;
1371 } 1373 }
1372 1374
1373 count++; 1375 count++;
1374 1376
1375 if (test_type_token(type, token, EVENT_ITEM, "field")) 1377 if (test_type_token(type, token, TEP_EVENT_ITEM, "field"))
1376 goto fail; 1378 goto fail;
1377 free_token(token); 1379 free_token(token);
1378 1380
@@ -1381,17 +1383,17 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1381 * The ftrace fields may still use the "special" name. 1383 * The ftrace fields may still use the "special" name.
1382 * Just ignore it. 1384 * Just ignore it.
1383 */ 1385 */
1384 if (event->flags & EVENT_FL_ISFTRACE && 1386 if (event->flags & TEP_EVENT_FL_ISFTRACE &&
1385 type == EVENT_ITEM && strcmp(token, "special") == 0) { 1387 type == TEP_EVENT_ITEM && strcmp(token, "special") == 0) {
1386 free_token(token); 1388 free_token(token);
1387 type = read_token(&token); 1389 type = read_token(&token);
1388 } 1390 }
1389 1391
1390 if (test_type_token(type, token, EVENT_OP, ":") < 0) 1392 if (test_type_token(type, token, TEP_EVENT_OP, ":") < 0)
1391 goto fail; 1393 goto fail;
1392 1394
1393 free_token(token); 1395 free_token(token);
1394 if (read_expect_type(EVENT_ITEM, &token) < 0) 1396 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
1395 goto fail; 1397 goto fail;
1396 1398
1397 last_token = token; 1399 last_token = token;
@@ -1405,17 +1407,17 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1405 /* read the rest of the type */ 1407 /* read the rest of the type */
1406 for (;;) { 1408 for (;;) {
1407 type = read_token(&token); 1409 type = read_token(&token);
1408 if (type == EVENT_ITEM || 1410 if (type == TEP_EVENT_ITEM ||
1409 (type == EVENT_OP && strcmp(token, "*") == 0) || 1411 (type == TEP_EVENT_OP && strcmp(token, "*") == 0) ||
1410 /* 1412 /*
1411 * Some of the ftrace fields are broken and have 1413 * Some of the ftrace fields are broken and have
1412 * an illegal "." in them. 1414 * an illegal "." in them.
1413 */ 1415 */
1414 (event->flags & EVENT_FL_ISFTRACE && 1416 (event->flags & TEP_EVENT_FL_ISFTRACE &&
1415 type == EVENT_OP && strcmp(token, ".") == 0)) { 1417 type == TEP_EVENT_OP && strcmp(token, ".") == 0)) {
1416 1418
1417 if (strcmp(token, "*") == 0) 1419 if (strcmp(token, "*") == 0)
1418 field->flags |= FIELD_IS_POINTER; 1420 field->flags |= TEP_FIELD_IS_POINTER;
1419 1421
1420 if (field->type) { 1422 if (field->type) {
1421 char *new_type; 1423 char *new_type;
@@ -1445,27 +1447,27 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1445 } 1447 }
1446 field->name = field->alias = last_token; 1448 field->name = field->alias = last_token;
1447 1449
1448 if (test_type(type, EVENT_OP)) 1450 if (test_type(type, TEP_EVENT_OP))
1449 goto fail; 1451 goto fail;
1450 1452
1451 if (strcmp(token, "[") == 0) { 1453 if (strcmp(token, "[") == 0) {
1452 enum event_type last_type = type; 1454 enum tep_event_type last_type = type;
1453 char *brackets = token; 1455 char *brackets = token;
1454 char *new_brackets; 1456 char *new_brackets;
1455 int len; 1457 int len;
1456 1458
1457 field->flags |= FIELD_IS_ARRAY; 1459 field->flags |= TEP_FIELD_IS_ARRAY;
1458 1460
1459 type = read_token(&token); 1461 type = read_token(&token);
1460 1462
1461 if (type == EVENT_ITEM) 1463 if (type == TEP_EVENT_ITEM)
1462 field->arraylen = strtoul(token, NULL, 0); 1464 field->arraylen = strtoul(token, NULL, 0);
1463 else 1465 else
1464 field->arraylen = 0; 1466 field->arraylen = 0;
1465 1467
1466 while (strcmp(token, "]") != 0) { 1468 while (strcmp(token, "]") != 0) {
1467 if (last_type == EVENT_ITEM && 1469 if (last_type == TEP_EVENT_ITEM &&
1468 type == EVENT_ITEM) 1470 type == TEP_EVENT_ITEM)
1469 len = 2; 1471 len = 2;
1470 else 1472 else
1471 len = 1; 1473 len = 1;
@@ -1486,7 +1488,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1486 field->arraylen = strtoul(token, NULL, 0); 1488 field->arraylen = strtoul(token, NULL, 0);
1487 free_token(token); 1489 free_token(token);
1488 type = read_token(&token); 1490 type = read_token(&token);
1489 if (type == EVENT_NONE) { 1491 if (type == TEP_EVENT_NONE) {
1490 do_warning_event(event, "failed to find token"); 1492 do_warning_event(event, "failed to find token");
1491 goto fail; 1493 goto fail;
1492 } 1494 }
@@ -1509,7 +1511,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1509 * If the next token is not an OP, then it is of 1511 * If the next token is not an OP, then it is of
1510 * the format: type [] item; 1512 * the format: type [] item;
1511 */ 1513 */
1512 if (type == EVENT_ITEM) { 1514 if (type == TEP_EVENT_ITEM) {
1513 char *new_type; 1515 char *new_type;
1514 new_type = realloc(field->type, 1516 new_type = realloc(field->type,
1515 strlen(field->type) + 1517 strlen(field->type) +
@@ -1543,79 +1545,79 @@ static int event_read_fields(struct event_format *event, struct format_field **f
1543 } 1545 }
1544 1546
1545 if (field_is_string(field)) 1547 if (field_is_string(field))
1546 field->flags |= FIELD_IS_STRING; 1548 field->flags |= TEP_FIELD_IS_STRING;
1547 if (field_is_dynamic(field)) 1549 if (field_is_dynamic(field))
1548 field->flags |= FIELD_IS_DYNAMIC; 1550 field->flags |= TEP_FIELD_IS_DYNAMIC;
1549 if (field_is_long(field)) 1551 if (field_is_long(field))
1550 field->flags |= FIELD_IS_LONG; 1552 field->flags |= TEP_FIELD_IS_LONG;
1551 1553
1552 if (test_type_token(type, token, EVENT_OP, ";")) 1554 if (test_type_token(type, token, TEP_EVENT_OP, ";"))
1553 goto fail; 1555 goto fail;
1554 free_token(token); 1556 free_token(token);
1555 1557
1556 if (read_expected(EVENT_ITEM, "offset") < 0) 1558 if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
1557 goto fail_expect; 1559 goto fail_expect;
1558 1560
1559 if (read_expected(EVENT_OP, ":") < 0) 1561 if (read_expected(TEP_EVENT_OP, ":") < 0)
1560 goto fail_expect; 1562 goto fail_expect;
1561 1563
1562 if (read_expect_type(EVENT_ITEM, &token)) 1564 if (read_expect_type(TEP_EVENT_ITEM, &token))
1563 goto fail; 1565 goto fail;
1564 field->offset = strtoul(token, NULL, 0); 1566 field->offset = strtoul(token, NULL, 0);
1565 free_token(token); 1567 free_token(token);
1566 1568
1567 if (read_expected(EVENT_OP, ";") < 0) 1569 if (read_expected(TEP_EVENT_OP, ";") < 0)
1568 goto fail_expect; 1570 goto fail_expect;
1569 1571
1570 if (read_expected(EVENT_ITEM, "size") < 0) 1572 if (read_expected(TEP_EVENT_ITEM, "size") < 0)
1571 goto fail_expect; 1573 goto fail_expect;
1572 1574
1573 if (read_expected(EVENT_OP, ":") < 0) 1575 if (read_expected(TEP_EVENT_OP, ":") < 0)
1574 goto fail_expect; 1576 goto fail_expect;
1575 1577
1576 if (read_expect_type(EVENT_ITEM, &token)) 1578 if (read_expect_type(TEP_EVENT_ITEM, &token))
1577 goto fail; 1579 goto fail;
1578 field->size = strtoul(token, NULL, 0); 1580 field->size = strtoul(token, NULL, 0);
1579 free_token(token); 1581 free_token(token);
1580 1582
1581 if (read_expected(EVENT_OP, ";") < 0) 1583 if (read_expected(TEP_EVENT_OP, ";") < 0)
1582 goto fail_expect; 1584 goto fail_expect;
1583 1585
1584 type = read_token(&token); 1586 type = read_token(&token);
1585 if (type != EVENT_NEWLINE) { 1587 if (type != TEP_EVENT_NEWLINE) {
1586 /* newer versions of the kernel have a "signed" type */ 1588 /* newer versions of the kernel have a "signed" type */
1587 if (test_type_token(type, token, EVENT_ITEM, "signed")) 1589 if (test_type_token(type, token, TEP_EVENT_ITEM, "signed"))
1588 goto fail; 1590 goto fail;
1589 1591
1590 free_token(token); 1592 free_token(token);
1591 1593
1592 if (read_expected(EVENT_OP, ":") < 0) 1594 if (read_expected(TEP_EVENT_OP, ":") < 0)
1593 goto fail_expect; 1595 goto fail_expect;
1594 1596
1595 if (read_expect_type(EVENT_ITEM, &token)) 1597 if (read_expect_type(TEP_EVENT_ITEM, &token))
1596 goto fail; 1598 goto fail;
1597 1599
1598 if (strtoul(token, NULL, 0)) 1600 if (strtoul(token, NULL, 0))
1599 field->flags |= FIELD_IS_SIGNED; 1601 field->flags |= TEP_FIELD_IS_SIGNED;
1600 1602
1601 free_token(token); 1603 free_token(token);
1602 if (read_expected(EVENT_OP, ";") < 0) 1604 if (read_expected(TEP_EVENT_OP, ";") < 0)
1603 goto fail_expect; 1605 goto fail_expect;
1604 1606
1605 if (read_expect_type(EVENT_NEWLINE, &token)) 1607 if (read_expect_type(TEP_EVENT_NEWLINE, &token))
1606 goto fail; 1608 goto fail;
1607 } 1609 }
1608 1610
1609 free_token(token); 1611 free_token(token);
1610 1612
1611 if (field->flags & FIELD_IS_ARRAY) { 1613 if (field->flags & TEP_FIELD_IS_ARRAY) {
1612 if (field->arraylen) 1614 if (field->arraylen)
1613 field->elementsize = field->size / field->arraylen; 1615 field->elementsize = field->size / field->arraylen;
1614 else if (field->flags & FIELD_IS_DYNAMIC) 1616 else if (field->flags & TEP_FIELD_IS_DYNAMIC)
1615 field->elementsize = size_dynamic; 1617 field->elementsize = size_dynamic;
1616 else if (field->flags & FIELD_IS_STRING) 1618 else if (field->flags & TEP_FIELD_IS_STRING)
1617 field->elementsize = 1; 1619 field->elementsize = 1;
1618 else if (field->flags & FIELD_IS_LONG) 1620 else if (field->flags & TEP_FIELD_IS_LONG)
1619 field->elementsize = event->pevent ? 1621 field->elementsize = event->pevent ?
1620 event->pevent->long_size : 1622 event->pevent->long_size :
1621 sizeof(long); 1623 sizeof(long);
@@ -1640,18 +1642,18 @@ fail_expect:
1640 return -1; 1642 return -1;
1641} 1643}
1642 1644
1643static int event_read_format(struct event_format *event) 1645static int event_read_format(struct tep_event_format *event)
1644{ 1646{
1645 char *token; 1647 char *token;
1646 int ret; 1648 int ret;
1647 1649
1648 if (read_expected_item(EVENT_ITEM, "format") < 0) 1650 if (read_expected_item(TEP_EVENT_ITEM, "format") < 0)
1649 return -1; 1651 return -1;
1650 1652
1651 if (read_expected(EVENT_OP, ":") < 0) 1653 if (read_expected(TEP_EVENT_OP, ":") < 0)
1652 return -1; 1654 return -1;
1653 1655
1654 if (read_expect_type(EVENT_NEWLINE, &token)) 1656 if (read_expect_type(TEP_EVENT_NEWLINE, &token))
1655 goto fail; 1657 goto fail;
1656 free_token(token); 1658 free_token(token);
1657 1659
@@ -1672,14 +1674,14 @@ static int event_read_format(struct event_format *event)
1672 return -1; 1674 return -1;
1673} 1675}
1674 1676
1675static enum event_type 1677static enum tep_event_type
1676process_arg_token(struct event_format *event, struct print_arg *arg, 1678process_arg_token(struct tep_event_format *event, struct tep_print_arg *arg,
1677 char **tok, enum event_type type); 1679 char **tok, enum tep_event_type type);
1678 1680
1679static enum event_type 1681static enum tep_event_type
1680process_arg(struct event_format *event, struct print_arg *arg, char **tok) 1682process_arg(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
1681{ 1683{
1682 enum event_type type; 1684 enum tep_event_type type;
1683 char *token; 1685 char *token;
1684 1686
1685 type = read_token(&token); 1687 type = read_token(&token);
@@ -1688,32 +1690,32 @@ process_arg(struct event_format *event, struct print_arg *arg, char **tok)
1688 return process_arg_token(event, arg, tok, type); 1690 return process_arg_token(event, arg, tok, type);
1689} 1691}
1690 1692
1691static enum event_type 1693static enum tep_event_type
1692process_op(struct event_format *event, struct print_arg *arg, char **tok); 1694process_op(struct tep_event_format *event, struct tep_print_arg *arg, char **tok);
1693 1695
1694/* 1696/*
1695 * For __print_symbolic() and __print_flags, we need to completely 1697 * For __print_symbolic() and __print_flags, we need to completely
1696 * evaluate the first argument, which defines what to print next. 1698 * evaluate the first argument, which defines what to print next.
1697 */ 1699 */
1698static enum event_type 1700static enum tep_event_type
1699process_field_arg(struct event_format *event, struct print_arg *arg, char **tok) 1701process_field_arg(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
1700{ 1702{
1701 enum event_type type; 1703 enum tep_event_type type;
1702 1704
1703 type = process_arg(event, arg, tok); 1705 type = process_arg(event, arg, tok);
1704 1706
1705 while (type == EVENT_OP) { 1707 while (type == TEP_EVENT_OP) {
1706 type = process_op(event, arg, tok); 1708 type = process_op(event, arg, tok);
1707 } 1709 }
1708 1710
1709 return type; 1711 return type;
1710} 1712}
1711 1713
1712static enum event_type 1714static enum tep_event_type
1713process_cond(struct event_format *event, struct print_arg *top, char **tok) 1715process_cond(struct tep_event_format *event, struct tep_print_arg *top, char **tok)
1714{ 1716{
1715 struct print_arg *arg, *left, *right; 1717 struct tep_print_arg *arg, *left, *right;
1716 enum event_type type; 1718 enum tep_event_type type;
1717 char *token = NULL; 1719 char *token = NULL;
1718 1720
1719 arg = alloc_arg(); 1721 arg = alloc_arg();
@@ -1728,7 +1730,7 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok)
1728 goto out_free; 1730 goto out_free;
1729 } 1731 }
1730 1732
1731 arg->type = PRINT_OP; 1733 arg->type = TEP_PRINT_OP;
1732 arg->op.left = left; 1734 arg->op.left = left;
1733 arg->op.right = right; 1735 arg->op.right = right;
1734 1736
@@ -1736,16 +1738,16 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok)
1736 type = process_arg(event, left, &token); 1738 type = process_arg(event, left, &token);
1737 1739
1738 again: 1740 again:
1739 if (type == EVENT_ERROR) 1741 if (type == TEP_EVENT_ERROR)
1740 goto out_free; 1742 goto out_free;
1741 1743
1742 /* Handle other operations in the arguments */ 1744 /* Handle other operations in the arguments */
1743 if (type == EVENT_OP && strcmp(token, ":") != 0) { 1745 if (type == TEP_EVENT_OP && strcmp(token, ":") != 0) {
1744 type = process_op(event, left, &token); 1746 type = process_op(event, left, &token);
1745 goto again; 1747 goto again;
1746 } 1748 }
1747 1749
1748 if (test_type_token(type, token, EVENT_OP, ":")) 1750 if (test_type_token(type, token, TEP_EVENT_OP, ":"))
1749 goto out_free; 1751 goto out_free;
1750 1752
1751 arg->op.op = token; 1753 arg->op.op = token;
@@ -1762,14 +1764,14 @@ out_free:
1762 top->op.right = NULL; 1764 top->op.right = NULL;
1763 free_token(token); 1765 free_token(token);
1764 free_arg(arg); 1766 free_arg(arg);
1765 return EVENT_ERROR; 1767 return TEP_EVENT_ERROR;
1766} 1768}
1767 1769
1768static enum event_type 1770static enum tep_event_type
1769process_array(struct event_format *event, struct print_arg *top, char **tok) 1771process_array(struct tep_event_format *event, struct tep_print_arg *top, char **tok)
1770{ 1772{
1771 struct print_arg *arg; 1773 struct tep_print_arg *arg;
1772 enum event_type type; 1774 enum tep_event_type type;
1773 char *token = NULL; 1775 char *token = NULL;
1774 1776
1775 arg = alloc_arg(); 1777 arg = alloc_arg();
@@ -1777,12 +1779,12 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
1777 do_warning_event(event, "%s: not enough memory!", __func__); 1779 do_warning_event(event, "%s: not enough memory!", __func__);
1778 /* '*tok' is set to top->op.op. No need to free. */ 1780 /* '*tok' is set to top->op.op. No need to free. */
1779 *tok = NULL; 1781 *tok = NULL;
1780 return EVENT_ERROR; 1782 return TEP_EVENT_ERROR;
1781 } 1783 }
1782 1784
1783 *tok = NULL; 1785 *tok = NULL;
1784 type = process_arg(event, arg, &token); 1786 type = process_arg(event, arg, &token);
1785 if (test_type_token(type, token, EVENT_OP, "]")) 1787 if (test_type_token(type, token, TEP_EVENT_OP, "]"))
1786 goto out_free; 1788 goto out_free;
1787 1789
1788 top->op.right = arg; 1790 top->op.right = arg;
@@ -1796,7 +1798,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
1796out_free: 1798out_free:
1797 free_token(token); 1799 free_token(token);
1798 free_arg(arg); 1800 free_arg(arg);
1799 return EVENT_ERROR; 1801 return TEP_EVENT_ERROR;
1800} 1802}
1801 1803
1802static int get_op_prio(char *op) 1804static int get_op_prio(char *op)
@@ -1854,11 +1856,11 @@ static int get_op_prio(char *op)
1854 } 1856 }
1855} 1857}
1856 1858
1857static int set_op_prio(struct print_arg *arg) 1859static int set_op_prio(struct tep_print_arg *arg)
1858{ 1860{
1859 1861
1860 /* single ops are the greatest */ 1862 /* single ops are the greatest */
1861 if (!arg->op.left || arg->op.left->type == PRINT_NULL) 1863 if (!arg->op.left || arg->op.left->type == TEP_PRINT_NULL)
1862 arg->op.prio = 0; 1864 arg->op.prio = 0;
1863 else 1865 else
1864 arg->op.prio = get_op_prio(arg->op.op); 1866 arg->op.prio = get_op_prio(arg->op.op);
@@ -1867,17 +1869,17 @@ static int set_op_prio(struct print_arg *arg)
1867} 1869}
1868 1870
1869/* Note, *tok does not get freed, but will most likely be saved */ 1871/* Note, *tok does not get freed, but will most likely be saved */
1870static enum event_type 1872static enum tep_event_type
1871process_op(struct event_format *event, struct print_arg *arg, char **tok) 1873process_op(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
1872{ 1874{
1873 struct print_arg *left, *right = NULL; 1875 struct tep_print_arg *left, *right = NULL;
1874 enum event_type type; 1876 enum tep_event_type type;
1875 char *token; 1877 char *token;
1876 1878
1877 /* the op is passed in via tok */ 1879 /* the op is passed in via tok */
1878 token = *tok; 1880 token = *tok;
1879 1881
1880 if (arg->type == PRINT_OP && !arg->op.left) { 1882 if (arg->type == TEP_PRINT_OP && !arg->op.left) {
1881 /* handle single op */ 1883 /* handle single op */
1882 if (token[1]) { 1884 if (token[1]) {
1883 do_warning_event(event, "bad op token %s", token); 1885 do_warning_event(event, "bad op token %s", token);
@@ -1900,7 +1902,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1900 if (!left) 1902 if (!left)
1901 goto out_warn_free; 1903 goto out_warn_free;
1902 1904
1903 left->type = PRINT_NULL; 1905 left->type = TEP_PRINT_NULL;
1904 arg->op.left = left; 1906 arg->op.left = left;
1905 1907
1906 right = alloc_arg(); 1908 right = alloc_arg();
@@ -1922,7 +1924,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1922 /* copy the top arg to the left */ 1924 /* copy the top arg to the left */
1923 *left = *arg; 1925 *left = *arg;
1924 1926
1925 arg->type = PRINT_OP; 1927 arg->type = TEP_PRINT_OP;
1926 arg->op.op = token; 1928 arg->op.op = token;
1927 arg->op.left = left; 1929 arg->op.left = left;
1928 arg->op.prio = 0; 1930 arg->op.prio = 0;
@@ -1956,13 +1958,13 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1956 /* copy the top arg to the left */ 1958 /* copy the top arg to the left */
1957 *left = *arg; 1959 *left = *arg;
1958 1960
1959 arg->type = PRINT_OP; 1961 arg->type = TEP_PRINT_OP;
1960 arg->op.op = token; 1962 arg->op.op = token;
1961 arg->op.left = left; 1963 arg->op.left = left;
1962 arg->op.right = NULL; 1964 arg->op.right = NULL;
1963 1965
1964 if (set_op_prio(arg) == -1) { 1966 if (set_op_prio(arg) == -1) {
1965 event->flags |= EVENT_FL_FAILED; 1967 event->flags |= TEP_EVENT_FL_FAILED;
1966 /* arg->op.op (= token) will be freed at out_free */ 1968 /* arg->op.op (= token) will be freed at out_free */
1967 arg->op.op = NULL; 1969 arg->op.op = NULL;
1968 goto out_free; 1970 goto out_free;
@@ -1973,10 +1975,10 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1973 1975
1974 /* could just be a type pointer */ 1976 /* could just be a type pointer */
1975 if ((strcmp(arg->op.op, "*") == 0) && 1977 if ((strcmp(arg->op.op, "*") == 0) &&
1976 type == EVENT_DELIM && (strcmp(token, ")") == 0)) { 1978 type == TEP_EVENT_DELIM && (strcmp(token, ")") == 0)) {
1977 char *new_atom; 1979 char *new_atom;
1978 1980
1979 if (left->type != PRINT_ATOM) { 1981 if (left->type != TEP_PRINT_ATOM) {
1980 do_warning_event(event, "bad pointer type"); 1982 do_warning_event(event, "bad pointer type");
1981 goto out_free; 1983 goto out_free;
1982 } 1984 }
@@ -1999,16 +2001,16 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
1999 goto out_warn_free; 2001 goto out_warn_free;
2000 2002
2001 type = process_arg_token(event, right, tok, type); 2003 type = process_arg_token(event, right, tok, type);
2002 if (type == EVENT_ERROR) { 2004 if (type == TEP_EVENT_ERROR) {
2003 free_arg(right); 2005 free_arg(right);
2004 /* token was freed in process_arg_token() via *tok */ 2006 /* token was freed in process_arg_token() via *tok */
2005 token = NULL; 2007 token = NULL;
2006 goto out_free; 2008 goto out_free;
2007 } 2009 }
2008 2010
2009 if (right->type == PRINT_OP && 2011 if (right->type == TEP_PRINT_OP &&
2010 get_op_prio(arg->op.op) < get_op_prio(right->op.op)) { 2012 get_op_prio(arg->op.op) < get_op_prio(right->op.op)) {
2011 struct print_arg tmp; 2013 struct tep_print_arg tmp;
2012 2014
2013 /* rotate ops according to the priority */ 2015 /* rotate ops according to the priority */
2014 arg->op.right = right->op.left; 2016 arg->op.right = right->op.left;
@@ -2030,7 +2032,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
2030 2032
2031 *left = *arg; 2033 *left = *arg;
2032 2034
2033 arg->type = PRINT_OP; 2035 arg->type = TEP_PRINT_OP;
2034 arg->op.op = token; 2036 arg->op.op = token;
2035 arg->op.left = left; 2037 arg->op.left = left;
2036 2038
@@ -2041,12 +2043,12 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
2041 2043
2042 } else { 2044 } else {
2043 do_warning_event(event, "unknown op '%s'", token); 2045 do_warning_event(event, "unknown op '%s'", token);
2044 event->flags |= EVENT_FL_FAILED; 2046 event->flags |= TEP_EVENT_FL_FAILED;
2045 /* the arg is now the left side */ 2047 /* the arg is now the left side */
2046 goto out_free; 2048 goto out_free;
2047 } 2049 }
2048 2050
2049 if (type == EVENT_OP && strcmp(*tok, ":") != 0) { 2051 if (type == TEP_EVENT_OP && strcmp(*tok, ":") != 0) {
2050 int prio; 2052 int prio;
2051 2053
2052 /* higher prios need to be closer to the root */ 2054 /* higher prios need to be closer to the root */
@@ -2065,34 +2067,34 @@ out_warn_free:
2065out_free: 2067out_free:
2066 free_token(token); 2068 free_token(token);
2067 *tok = NULL; 2069 *tok = NULL;
2068 return EVENT_ERROR; 2070 return TEP_EVENT_ERROR;
2069} 2071}
2070 2072
2071static enum event_type 2073static enum tep_event_type
2072process_entry(struct event_format *event __maybe_unused, struct print_arg *arg, 2074process_entry(struct tep_event_format *event __maybe_unused, struct tep_print_arg *arg,
2073 char **tok) 2075 char **tok)
2074{ 2076{
2075 enum event_type type; 2077 enum tep_event_type type;
2076 char *field; 2078 char *field;
2077 char *token; 2079 char *token;
2078 2080
2079 if (read_expected(EVENT_OP, "->") < 0) 2081 if (read_expected(TEP_EVENT_OP, "->") < 0)
2080 goto out_err; 2082 goto out_err;
2081 2083
2082 if (read_expect_type(EVENT_ITEM, &token) < 0) 2084 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
2083 goto out_free; 2085 goto out_free;
2084 field = token; 2086 field = token;
2085 2087
2086 arg->type = PRINT_FIELD; 2088 arg->type = TEP_PRINT_FIELD;
2087 arg->field.name = field; 2089 arg->field.name = field;
2088 2090
2089 if (is_flag_field) { 2091 if (is_flag_field) {
2090 arg->field.field = tep_find_any_field(event, arg->field.name); 2092 arg->field.field = tep_find_any_field(event, arg->field.name);
2091 arg->field.field->flags |= FIELD_IS_FLAG; 2093 arg->field.field->flags |= TEP_FIELD_IS_FLAG;
2092 is_flag_field = 0; 2094 is_flag_field = 0;
2093 } else if (is_symbolic_field) { 2095 } else if (is_symbolic_field) {
2094 arg->field.field = tep_find_any_field(event, arg->field.name); 2096 arg->field.field = tep_find_any_field(event, arg->field.name);
2095 arg->field.field->flags |= FIELD_IS_SYMBOLIC; 2097 arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC;
2096 is_symbolic_field = 0; 2098 is_symbolic_field = 0;
2097 } 2099 }
2098 2100
@@ -2105,14 +2107,14 @@ process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
2105 free_token(token); 2107 free_token(token);
2106 out_err: 2108 out_err:
2107 *tok = NULL; 2109 *tok = NULL;
2108 return EVENT_ERROR; 2110 return TEP_EVENT_ERROR;
2109} 2111}
2110 2112
2111static int alloc_and_process_delim(struct event_format *event, char *next_token, 2113static int alloc_and_process_delim(struct tep_event_format *event, char *next_token,
2112 struct print_arg **print_arg) 2114 struct tep_print_arg **print_arg)
2113{ 2115{
2114 struct print_arg *field; 2116 struct tep_print_arg *field;
2115 enum event_type type; 2117 enum tep_event_type type;
2116 char *token; 2118 char *token;
2117 int ret = 0; 2119 int ret = 0;
2118 2120
@@ -2125,7 +2127,7 @@ static int alloc_and_process_delim(struct event_format *event, char *next_token,
2125 2127
2126 type = process_arg(event, field, &token); 2128 type = process_arg(event, field, &token);
2127 2129
2128 if (test_type_token(type, token, EVENT_DELIM, next_token)) { 2130 if (test_type_token(type, token, TEP_EVENT_DELIM, next_token)) {
2129 errno = EINVAL; 2131 errno = EINVAL;
2130 ret = -1; 2132 ret = -1;
2131 free_arg(field); 2133 free_arg(field);
@@ -2140,7 +2142,7 @@ out_free_token:
2140 return ret; 2142 return ret;
2141} 2143}
2142 2144
2143static char *arg_eval (struct print_arg *arg); 2145static char *arg_eval (struct tep_print_arg *arg);
2144 2146
2145static unsigned long long 2147static unsigned long long
2146eval_type_str(unsigned long long val, const char *type, int pointer) 2148eval_type_str(unsigned long long val, const char *type, int pointer)
@@ -2237,9 +2239,9 @@ eval_type_str(unsigned long long val, const char *type, int pointer)
2237 * Try to figure out the type. 2239 * Try to figure out the type.
2238 */ 2240 */
2239static unsigned long long 2241static unsigned long long
2240eval_type(unsigned long long val, struct print_arg *arg, int pointer) 2242eval_type(unsigned long long val, struct tep_print_arg *arg, int pointer)
2241{ 2243{
2242 if (arg->type != PRINT_TYPE) { 2244 if (arg->type != TEP_PRINT_TYPE) {
2243 do_warning("expected type argument"); 2245 do_warning("expected type argument");
2244 return 0; 2246 return 0;
2245 } 2247 }
@@ -2247,22 +2249,22 @@ eval_type(unsigned long long val, struct print_arg *arg, int pointer)
2247 return eval_type_str(val, arg->typecast.type, pointer); 2249 return eval_type_str(val, arg->typecast.type, pointer);
2248} 2250}
2249 2251
2250static int arg_num_eval(struct print_arg *arg, long long *val) 2252static int arg_num_eval(struct tep_print_arg *arg, long long *val)
2251{ 2253{
2252 long long left, right; 2254 long long left, right;
2253 int ret = 1; 2255 int ret = 1;
2254 2256
2255 switch (arg->type) { 2257 switch (arg->type) {
2256 case PRINT_ATOM: 2258 case TEP_PRINT_ATOM:
2257 *val = strtoll(arg->atom.atom, NULL, 0); 2259 *val = strtoll(arg->atom.atom, NULL, 0);
2258 break; 2260 break;
2259 case PRINT_TYPE: 2261 case TEP_PRINT_TYPE:
2260 ret = arg_num_eval(arg->typecast.item, val); 2262 ret = arg_num_eval(arg->typecast.item, val);
2261 if (!ret) 2263 if (!ret)
2262 break; 2264 break;
2263 *val = eval_type(*val, arg, 0); 2265 *val = eval_type(*val, arg, 0);
2264 break; 2266 break;
2265 case PRINT_OP: 2267 case TEP_PRINT_OP:
2266 switch (arg->op.op[0]) { 2268 switch (arg->op.op[0]) {
2267 case '|': 2269 case '|':
2268 ret = arg_num_eval(arg->op.left, &left); 2270 ret = arg_num_eval(arg->op.left, &left);
@@ -2365,7 +2367,7 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
2365 break; 2367 break;
2366 case '-': 2368 case '-':
2367 /* check for negative */ 2369 /* check for negative */
2368 if (arg->op.left->type == PRINT_NULL) 2370 if (arg->op.left->type == TEP_PRINT_NULL)
2369 left = 0; 2371 left = 0;
2370 else 2372 else
2371 ret = arg_num_eval(arg->op.left, &left); 2373 ret = arg_num_eval(arg->op.left, &left);
@@ -2377,7 +2379,7 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
2377 *val = left - right; 2379 *val = left - right;
2378 break; 2380 break;
2379 case '+': 2381 case '+':
2380 if (arg->op.left->type == PRINT_NULL) 2382 if (arg->op.left->type == TEP_PRINT_NULL)
2381 left = 0; 2383 left = 0;
2382 else 2384 else
2383 ret = arg_num_eval(arg->op.left, &left); 2385 ret = arg_num_eval(arg->op.left, &left);
@@ -2400,11 +2402,11 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
2400 } 2402 }
2401 break; 2403 break;
2402 2404
2403 case PRINT_NULL: 2405 case TEP_PRINT_NULL:
2404 case PRINT_FIELD ... PRINT_SYMBOL: 2406 case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
2405 case PRINT_STRING: 2407 case TEP_PRINT_STRING:
2406 case PRINT_BSTRING: 2408 case TEP_PRINT_BSTRING:
2407 case PRINT_BITMASK: 2409 case TEP_PRINT_BITMASK:
2408 default: 2410 default:
2409 do_warning("invalid eval type %d", arg->type); 2411 do_warning("invalid eval type %d", arg->type);
2410 ret = 0; 2412 ret = 0;
@@ -2413,27 +2415,27 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
2413 return ret; 2415 return ret;
2414} 2416}
2415 2417
2416static char *arg_eval (struct print_arg *arg) 2418static char *arg_eval (struct tep_print_arg *arg)
2417{ 2419{
2418 long long val; 2420 long long val;
2419 static char buf[20]; 2421 static char buf[20];
2420 2422
2421 switch (arg->type) { 2423 switch (arg->type) {
2422 case PRINT_ATOM: 2424 case TEP_PRINT_ATOM:
2423 return arg->atom.atom; 2425 return arg->atom.atom;
2424 case PRINT_TYPE: 2426 case TEP_PRINT_TYPE:
2425 return arg_eval(arg->typecast.item); 2427 return arg_eval(arg->typecast.item);
2426 case PRINT_OP: 2428 case TEP_PRINT_OP:
2427 if (!arg_num_eval(arg, &val)) 2429 if (!arg_num_eval(arg, &val))
2428 break; 2430 break;
2429 sprintf(buf, "%lld", val); 2431 sprintf(buf, "%lld", val);
2430 return buf; 2432 return buf;
2431 2433
2432 case PRINT_NULL: 2434 case TEP_PRINT_NULL:
2433 case PRINT_FIELD ... PRINT_SYMBOL: 2435 case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
2434 case PRINT_STRING: 2436 case TEP_PRINT_STRING:
2435 case PRINT_BSTRING: 2437 case TEP_PRINT_BSTRING:
2436 case PRINT_BITMASK: 2438 case TEP_PRINT_BITMASK:
2437 default: 2439 default:
2438 do_warning("invalid eval type %d", arg->type); 2440 do_warning("invalid eval type %d", arg->type);
2439 break; 2441 break;
@@ -2442,19 +2444,19 @@ static char *arg_eval (struct print_arg *arg)
2442 return NULL; 2444 return NULL;
2443} 2445}
2444 2446
2445static enum event_type 2447static enum tep_event_type
2446process_fields(struct event_format *event, struct print_flag_sym **list, char **tok) 2448process_fields(struct tep_event_format *event, struct tep_print_flag_sym **list, char **tok)
2447{ 2449{
2448 enum event_type type; 2450 enum tep_event_type type;
2449 struct print_arg *arg = NULL; 2451 struct tep_print_arg *arg = NULL;
2450 struct print_flag_sym *field; 2452 struct tep_print_flag_sym *field;
2451 char *token = *tok; 2453 char *token = *tok;
2452 char *value; 2454 char *value;
2453 2455
2454 do { 2456 do {
2455 free_token(token); 2457 free_token(token);
2456 type = read_token_item(&token); 2458 type = read_token_item(&token);
2457 if (test_type_token(type, token, EVENT_OP, "{")) 2459 if (test_type_token(type, token, TEP_EVENT_OP, "{"))
2458 break; 2460 break;
2459 2461
2460 arg = alloc_arg(); 2462 arg = alloc_arg();
@@ -2464,13 +2466,13 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
2464 free_token(token); 2466 free_token(token);
2465 type = process_arg(event, arg, &token); 2467 type = process_arg(event, arg, &token);
2466 2468
2467 if (type == EVENT_OP) 2469 if (type == TEP_EVENT_OP)
2468 type = process_op(event, arg, &token); 2470 type = process_op(event, arg, &token);
2469 2471
2470 if (type == EVENT_ERROR) 2472 if (type == TEP_EVENT_ERROR)
2471 goto out_free; 2473 goto out_free;
2472 2474
2473 if (test_type_token(type, token, EVENT_DELIM, ",")) 2475 if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
2474 goto out_free; 2476 goto out_free;
2475 2477
2476 field = calloc(1, sizeof(*field)); 2478 field = calloc(1, sizeof(*field));
@@ -2491,7 +2493,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
2491 2493
2492 free_token(token); 2494 free_token(token);
2493 type = process_arg(event, arg, &token); 2495 type = process_arg(event, arg, &token);
2494 if (test_type_token(type, token, EVENT_OP, "}")) 2496 if (test_type_token(type, token, TEP_EVENT_OP, "}"))
2495 goto out_free_field; 2497 goto out_free_field;
2496 2498
2497 value = arg_eval(arg); 2499 value = arg_eval(arg);
@@ -2508,7 +2510,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
2508 2510
2509 free_token(token); 2511 free_token(token);
2510 type = read_token_item(&token); 2512 type = read_token_item(&token);
2511 } while (type == EVENT_DELIM && strcmp(token, ",") == 0); 2513 } while (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0);
2512 2514
2513 *tok = token; 2515 *tok = token;
2514 return type; 2516 return type;
@@ -2520,18 +2522,18 @@ out_free:
2520 free_token(token); 2522 free_token(token);
2521 *tok = NULL; 2523 *tok = NULL;
2522 2524
2523 return EVENT_ERROR; 2525 return TEP_EVENT_ERROR;
2524} 2526}
2525 2527
2526static enum event_type 2528static enum tep_event_type
2527process_flags(struct event_format *event, struct print_arg *arg, char **tok) 2529process_flags(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
2528{ 2530{
2529 struct print_arg *field; 2531 struct tep_print_arg *field;
2530 enum event_type type; 2532 enum tep_event_type type;
2531 char *token = NULL; 2533 char *token = NULL;
2532 2534
2533 memset(arg, 0, sizeof(*arg)); 2535 memset(arg, 0, sizeof(*arg));
2534 arg->type = PRINT_FLAGS; 2536 arg->type = TEP_PRINT_FLAGS;
2535 2537
2536 field = alloc_arg(); 2538 field = alloc_arg();
2537 if (!field) { 2539 if (!field) {
@@ -2542,10 +2544,10 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
2542 type = process_field_arg(event, field, &token); 2544 type = process_field_arg(event, field, &token);
2543 2545
2544 /* Handle operations in the first argument */ 2546 /* Handle operations in the first argument */
2545 while (type == EVENT_OP) 2547 while (type == TEP_EVENT_OP)
2546 type = process_op(event, field, &token); 2548 type = process_op(event, field, &token);
2547 2549
2548 if (test_type_token(type, token, EVENT_DELIM, ",")) 2550 if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
2549 goto out_free_field; 2551 goto out_free_field;
2550 free_token(token); 2552 free_token(token);
2551 2553
@@ -2557,11 +2559,11 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
2557 type = read_token_item(&token); 2559 type = read_token_item(&token);
2558 } 2560 }
2559 2561
2560 if (test_type_token(type, token, EVENT_DELIM, ",")) 2562 if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
2561 goto out_free; 2563 goto out_free;
2562 2564
2563 type = process_fields(event, &arg->flags.flags, &token); 2565 type = process_fields(event, &arg->flags.flags, &token);
2564 if (test_type_token(type, token, EVENT_DELIM, ")")) 2566 if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
2565 goto out_free; 2567 goto out_free;
2566 2568
2567 free_token(token); 2569 free_token(token);
@@ -2573,18 +2575,18 @@ out_free_field:
2573out_free: 2575out_free:
2574 free_token(token); 2576 free_token(token);
2575 *tok = NULL; 2577 *tok = NULL;
2576 return EVENT_ERROR; 2578 return TEP_EVENT_ERROR;
2577} 2579}
2578 2580
2579static enum event_type 2581static enum tep_event_type
2580process_symbols(struct event_format *event, struct print_arg *arg, char **tok) 2582process_symbols(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
2581{ 2583{
2582 struct print_arg *field; 2584 struct tep_print_arg *field;
2583 enum event_type type; 2585 enum tep_event_type type;
2584 char *token = NULL; 2586 char *token = NULL;
2585 2587
2586 memset(arg, 0, sizeof(*arg)); 2588 memset(arg, 0, sizeof(*arg));
2587 arg->type = PRINT_SYMBOL; 2589 arg->type = TEP_PRINT_SYMBOL;
2588 2590
2589 field = alloc_arg(); 2591 field = alloc_arg();
2590 if (!field) { 2592 if (!field) {
@@ -2594,13 +2596,13 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
2594 2596
2595 type = process_field_arg(event, field, &token); 2597 type = process_field_arg(event, field, &token);
2596 2598
2597 if (test_type_token(type, token, EVENT_DELIM, ",")) 2599 if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
2598 goto out_free_field; 2600 goto out_free_field;
2599 2601
2600 arg->symbol.field = field; 2602 arg->symbol.field = field;
2601 2603
2602 type = process_fields(event, &arg->symbol.symbols, &token); 2604 type = process_fields(event, &arg->symbol.symbols, &token);
2603 if (test_type_token(type, token, EVENT_DELIM, ")")) 2605 if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
2604 goto out_free; 2606 goto out_free;
2605 2607
2606 free_token(token); 2608 free_token(token);
@@ -2612,12 +2614,12 @@ out_free_field:
2612out_free: 2614out_free:
2613 free_token(token); 2615 free_token(token);
2614 *tok = NULL; 2616 *tok = NULL;
2615 return EVENT_ERROR; 2617 return TEP_EVENT_ERROR;
2616} 2618}
2617 2619
2618static enum event_type 2620static enum tep_event_type
2619process_hex_common(struct event_format *event, struct print_arg *arg, 2621process_hex_common(struct tep_event_format *event, struct tep_print_arg *arg,
2620 char **tok, enum print_arg_type type) 2622 char **tok, enum tep_print_arg_type type)
2621{ 2623{
2622 memset(arg, 0, sizeof(*arg)); 2624 memset(arg, 0, sizeof(*arg));
2623 arg->type = type; 2625 arg->type = type;
@@ -2635,27 +2637,27 @@ free_field:
2635 arg->hex.field = NULL; 2637 arg->hex.field = NULL;
2636out: 2638out:
2637 *tok = NULL; 2639 *tok = NULL;
2638 return EVENT_ERROR; 2640 return TEP_EVENT_ERROR;
2639} 2641}
2640 2642
2641static enum event_type 2643static enum tep_event_type
2642process_hex(struct event_format *event, struct print_arg *arg, char **tok) 2644process_hex(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
2643{ 2645{
2644 return process_hex_common(event, arg, tok, PRINT_HEX); 2646 return process_hex_common(event, arg, tok, TEP_PRINT_HEX);
2645} 2647}
2646 2648
2647static enum event_type 2649static enum tep_event_type
2648process_hex_str(struct event_format *event, struct print_arg *arg, 2650process_hex_str(struct tep_event_format *event, struct tep_print_arg *arg,
2649 char **tok) 2651 char **tok)
2650{ 2652{
2651 return process_hex_common(event, arg, tok, PRINT_HEX_STR); 2653 return process_hex_common(event, arg, tok, TEP_PRINT_HEX_STR);
2652} 2654}
2653 2655
2654static enum event_type 2656static enum tep_event_type
2655process_int_array(struct event_format *event, struct print_arg *arg, char **tok) 2657process_int_array(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
2656{ 2658{
2657 memset(arg, 0, sizeof(*arg)); 2659 memset(arg, 0, sizeof(*arg));
2658 arg->type = PRINT_INT_ARRAY; 2660 arg->type = TEP_PRINT_INT_ARRAY;
2659 2661
2660 if (alloc_and_process_delim(event, ",", &arg->int_array.field)) 2662 if (alloc_and_process_delim(event, ",", &arg->int_array.field))
2661 goto out; 2663 goto out;
@@ -2676,18 +2678,18 @@ free_field:
2676 arg->int_array.field = NULL; 2678 arg->int_array.field = NULL;
2677out: 2679out:
2678 *tok = NULL; 2680 *tok = NULL;
2679 return EVENT_ERROR; 2681 return TEP_EVENT_ERROR;
2680} 2682}
2681 2683
2682static enum event_type 2684static enum tep_event_type
2683process_dynamic_array(struct event_format *event, struct print_arg *arg, char **tok) 2685process_dynamic_array(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
2684{ 2686{
2685 struct format_field *field; 2687 struct tep_format_field *field;
2686 enum event_type type; 2688 enum tep_event_type type;
2687 char *token; 2689 char *token;
2688 2690
2689 memset(arg, 0, sizeof(*arg)); 2691 memset(arg, 0, sizeof(*arg));
2690 arg->type = PRINT_DYNAMIC_ARRAY; 2692 arg->type = TEP_PRINT_DYNAMIC_ARRAY;
2691 2693
2692 /* 2694 /*
2693 * The item within the parenthesis is another field that holds 2695 * The item within the parenthesis is another field that holds
@@ -2695,7 +2697,7 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
2695 */ 2697 */
2696 type = read_token(&token); 2698 type = read_token(&token);
2697 *tok = token; 2699 *tok = token;
2698 if (type != EVENT_ITEM) 2700 if (type != TEP_EVENT_ITEM)
2699 goto out_free; 2701 goto out_free;
2700 2702
2701 /* Find the field */ 2703 /* Find the field */
@@ -2707,13 +2709,13 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
2707 arg->dynarray.field = field; 2709 arg->dynarray.field = field;
2708 arg->dynarray.index = 0; 2710 arg->dynarray.index = 0;
2709 2711
2710 if (read_expected(EVENT_DELIM, ")") < 0) 2712 if (read_expected(TEP_EVENT_DELIM, ")") < 0)
2711 goto out_free; 2713 goto out_free;
2712 2714
2713 free_token(token); 2715 free_token(token);
2714 type = read_token_item(&token); 2716 type = read_token_item(&token);
2715 *tok = token; 2717 *tok = token;
2716 if (type != EVENT_OP || strcmp(token, "[") != 0) 2718 if (type != TEP_EVENT_OP || strcmp(token, "[") != 0)
2717 return type; 2719 return type;
2718 2720
2719 free_token(token); 2721 free_token(token);
@@ -2721,14 +2723,14 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
2721 if (!arg) { 2723 if (!arg) {
2722 do_warning_event(event, "%s: not enough memory!", __func__); 2724 do_warning_event(event, "%s: not enough memory!", __func__);
2723 *tok = NULL; 2725 *tok = NULL;
2724 return EVENT_ERROR; 2726 return TEP_EVENT_ERROR;
2725 } 2727 }
2726 2728
2727 type = process_arg(event, arg, &token); 2729 type = process_arg(event, arg, &token);
2728 if (type == EVENT_ERROR) 2730 if (type == TEP_EVENT_ERROR)
2729 goto out_free_arg; 2731 goto out_free_arg;
2730 2732
2731 if (!test_type_token(type, token, EVENT_OP, "]")) 2733 if (!test_type_token(type, token, TEP_EVENT_OP, "]"))
2732 goto out_free_arg; 2734 goto out_free_arg;
2733 2735
2734 free_token(token); 2736 free_token(token);
@@ -2740,21 +2742,21 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
2740 out_free: 2742 out_free:
2741 free_token(token); 2743 free_token(token);
2742 *tok = NULL; 2744 *tok = NULL;
2743 return EVENT_ERROR; 2745 return TEP_EVENT_ERROR;
2744} 2746}
2745 2747
2746static enum event_type 2748static enum tep_event_type
2747process_dynamic_array_len(struct event_format *event, struct print_arg *arg, 2749process_dynamic_array_len(struct tep_event_format *event, struct tep_print_arg *arg,
2748 char **tok) 2750 char **tok)
2749{ 2751{
2750 struct format_field *field; 2752 struct tep_format_field *field;
2751 enum event_type type; 2753 enum tep_event_type type;
2752 char *token; 2754 char *token;
2753 2755
2754 if (read_expect_type(EVENT_ITEM, &token) < 0) 2756 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
2755 goto out_free; 2757 goto out_free;
2756 2758
2757 arg->type = PRINT_DYNAMIC_ARRAY_LEN; 2759 arg->type = TEP_PRINT_DYNAMIC_ARRAY_LEN;
2758 2760
2759 /* Find the field */ 2761 /* Find the field */
2760 field = tep_find_field(event, token); 2762 field = tep_find_field(event, token);
@@ -2764,7 +2766,7 @@ process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
2764 arg->dynarray.field = field; 2766 arg->dynarray.field = field;
2765 arg->dynarray.index = 0; 2767 arg->dynarray.index = 0;
2766 2768
2767 if (read_expected(EVENT_DELIM, ")") < 0) 2769 if (read_expected(TEP_EVENT_DELIM, ")") < 0)
2768 goto out_err; 2770 goto out_err;
2769 2771
2770 type = read_token(&token); 2772 type = read_token(&token);
@@ -2776,28 +2778,28 @@ process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
2776 free_token(token); 2778 free_token(token);
2777 out_err: 2779 out_err:
2778 *tok = NULL; 2780 *tok = NULL;
2779 return EVENT_ERROR; 2781 return TEP_EVENT_ERROR;
2780} 2782}
2781 2783
2782static enum event_type 2784static enum tep_event_type
2783process_paren(struct event_format *event, struct print_arg *arg, char **tok) 2785process_paren(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
2784{ 2786{
2785 struct print_arg *item_arg; 2787 struct tep_print_arg *item_arg;
2786 enum event_type type; 2788 enum tep_event_type type;
2787 char *token; 2789 char *token;
2788 2790
2789 type = process_arg(event, arg, &token); 2791 type = process_arg(event, arg, &token);
2790 2792
2791 if (type == EVENT_ERROR) 2793 if (type == TEP_EVENT_ERROR)
2792 goto out_free; 2794 goto out_free;
2793 2795
2794 if (type == EVENT_OP) 2796 if (type == TEP_EVENT_OP)
2795 type = process_op(event, arg, &token); 2797 type = process_op(event, arg, &token);
2796 2798
2797 if (type == EVENT_ERROR) 2799 if (type == TEP_EVENT_ERROR)
2798 goto out_free; 2800 goto out_free;
2799 2801
2800 if (test_type_token(type, token, EVENT_DELIM, ")")) 2802 if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
2801 goto out_free; 2803 goto out_free;
2802 2804
2803 free_token(token); 2805 free_token(token);
@@ -2808,13 +2810,13 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
2808 * this was a typecast. 2810 * this was a typecast.
2809 */ 2811 */
2810 if (event_item_type(type) || 2812 if (event_item_type(type) ||
2811 (type == EVENT_DELIM && strcmp(token, "(") == 0)) { 2813 (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0)) {
2812 2814
2813 /* make this a typecast and contine */ 2815 /* make this a typecast and contine */
2814 2816
2815 /* prevous must be an atom */ 2817 /* prevous must be an atom */
2816 if (arg->type != PRINT_ATOM) { 2818 if (arg->type != TEP_PRINT_ATOM) {
2817 do_warning_event(event, "previous needed to be PRINT_ATOM"); 2819 do_warning_event(event, "previous needed to be TEP_PRINT_ATOM");
2818 goto out_free; 2820 goto out_free;
2819 } 2821 }
2820 2822
@@ -2825,7 +2827,7 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
2825 goto out_free; 2827 goto out_free;
2826 } 2828 }
2827 2829
2828 arg->type = PRINT_TYPE; 2830 arg->type = TEP_PRINT_TYPE;
2829 arg->typecast.type = arg->atom.atom; 2831 arg->typecast.type = arg->atom.atom;
2830 arg->typecast.item = item_arg; 2832 arg->typecast.item = item_arg;
2831 type = process_arg_token(event, item_arg, &token, type); 2833 type = process_arg_token(event, item_arg, &token, type);
@@ -2838,25 +2840,25 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
2838 out_free: 2840 out_free:
2839 free_token(token); 2841 free_token(token);
2840 *tok = NULL; 2842 *tok = NULL;
2841 return EVENT_ERROR; 2843 return TEP_EVENT_ERROR;
2842} 2844}
2843 2845
2844 2846
2845static enum event_type 2847static enum tep_event_type
2846process_str(struct event_format *event __maybe_unused, struct print_arg *arg, 2848process_str(struct tep_event_format *event __maybe_unused, struct tep_print_arg *arg,
2847 char **tok) 2849 char **tok)
2848{ 2850{
2849 enum event_type type; 2851 enum tep_event_type type;
2850 char *token; 2852 char *token;
2851 2853
2852 if (read_expect_type(EVENT_ITEM, &token) < 0) 2854 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
2853 goto out_free; 2855 goto out_free;
2854 2856
2855 arg->type = PRINT_STRING; 2857 arg->type = TEP_PRINT_STRING;
2856 arg->string.string = token; 2858 arg->string.string = token;
2857 arg->string.offset = -1; 2859 arg->string.offset = -1;
2858 2860
2859 if (read_expected(EVENT_DELIM, ")") < 0) 2861 if (read_expected(TEP_EVENT_DELIM, ")") < 0)
2860 goto out_err; 2862 goto out_err;
2861 2863
2862 type = read_token(&token); 2864 type = read_token(&token);
@@ -2868,24 +2870,24 @@ process_str(struct event_format *event __maybe_unused, struct print_arg *arg,
2868 free_token(token); 2870 free_token(token);
2869 out_err: 2871 out_err:
2870 *tok = NULL; 2872 *tok = NULL;
2871 return EVENT_ERROR; 2873 return TEP_EVENT_ERROR;
2872} 2874}
2873 2875
2874static enum event_type 2876static enum tep_event_type
2875process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg, 2877process_bitmask(struct tep_event_format *event __maybe_unused, struct tep_print_arg *arg,
2876 char **tok) 2878 char **tok)
2877{ 2879{
2878 enum event_type type; 2880 enum tep_event_type type;
2879 char *token; 2881 char *token;
2880 2882
2881 if (read_expect_type(EVENT_ITEM, &token) < 0) 2883 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
2882 goto out_free; 2884 goto out_free;
2883 2885
2884 arg->type = PRINT_BITMASK; 2886 arg->type = TEP_PRINT_BITMASK;
2885 arg->bitmask.bitmask = token; 2887 arg->bitmask.bitmask = token;
2886 arg->bitmask.offset = -1; 2888 arg->bitmask.offset = -1;
2887 2889
2888 if (read_expected(EVENT_DELIM, ")") < 0) 2890 if (read_expected(TEP_EVENT_DELIM, ")") < 0)
2889 goto out_err; 2891 goto out_err;
2890 2892
2891 type = read_token(&token); 2893 type = read_token(&token);
@@ -2897,7 +2899,7 @@ process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg
2897 free_token(token); 2899 free_token(token);
2898 out_err: 2900 out_err:
2899 *tok = NULL; 2901 *tok = NULL;
2900 return EVENT_ERROR; 2902 return TEP_EVENT_ERROR;
2901} 2903}
2902 2904
2903static struct tep_function_handler * 2905static struct tep_function_handler *
@@ -2932,17 +2934,17 @@ static void remove_func_handler(struct tep_handle *pevent, char *func_name)
2932 } 2934 }
2933} 2935}
2934 2936
2935static enum event_type 2937static enum tep_event_type
2936process_func_handler(struct event_format *event, struct tep_function_handler *func, 2938process_func_handler(struct tep_event_format *event, struct tep_function_handler *func,
2937 struct print_arg *arg, char **tok) 2939 struct tep_print_arg *arg, char **tok)
2938{ 2940{
2939 struct print_arg **next_arg; 2941 struct tep_print_arg **next_arg;
2940 struct print_arg *farg; 2942 struct tep_print_arg *farg;
2941 enum event_type type; 2943 enum tep_event_type type;
2942 char *token; 2944 char *token;
2943 int i; 2945 int i;
2944 2946
2945 arg->type = PRINT_FUNC; 2947 arg->type = TEP_PRINT_FUNC;
2946 arg->func.func = func; 2948 arg->func.func = func;
2947 2949
2948 *tok = NULL; 2950 *tok = NULL;
@@ -2953,12 +2955,12 @@ process_func_handler(struct event_format *event, struct tep_function_handler *fu
2953 if (!farg) { 2955 if (!farg) {
2954 do_warning_event(event, "%s: not enough memory!", 2956 do_warning_event(event, "%s: not enough memory!",
2955 __func__); 2957 __func__);
2956 return EVENT_ERROR; 2958 return TEP_EVENT_ERROR;
2957 } 2959 }
2958 2960
2959 type = process_arg(event, farg, &token); 2961 type = process_arg(event, farg, &token);
2960 if (i < (func->nr_args - 1)) { 2962 if (i < (func->nr_args - 1)) {
2961 if (type != EVENT_DELIM || strcmp(token, ",") != 0) { 2963 if (type != TEP_EVENT_DELIM || strcmp(token, ",") != 0) {
2962 do_warning_event(event, 2964 do_warning_event(event,
2963 "Error: function '%s()' expects %d arguments but event %s only uses %d", 2965 "Error: function '%s()' expects %d arguments but event %s only uses %d",
2964 func->name, func->nr_args, 2966 func->name, func->nr_args,
@@ -2966,7 +2968,7 @@ process_func_handler(struct event_format *event, struct tep_function_handler *fu
2966 goto err; 2968 goto err;
2967 } 2969 }
2968 } else { 2970 } else {
2969 if (type != EVENT_DELIM || strcmp(token, ")") != 0) { 2971 if (type != TEP_EVENT_DELIM || strcmp(token, ")") != 0) {
2970 do_warning_event(event, 2972 do_warning_event(event,
2971 "Error: function '%s()' only expects %d arguments but event %s has more", 2973 "Error: function '%s()' only expects %d arguments but event %s has more",
2972 func->name, func->nr_args, event->name); 2974 func->name, func->nr_args, event->name);
@@ -2987,11 +2989,11 @@ process_func_handler(struct event_format *event, struct tep_function_handler *fu
2987err: 2989err:
2988 free_arg(farg); 2990 free_arg(farg);
2989 free_token(token); 2991 free_token(token);
2990 return EVENT_ERROR; 2992 return TEP_EVENT_ERROR;
2991} 2993}
2992 2994
2993static enum event_type 2995static enum tep_event_type
2994process_function(struct event_format *event, struct print_arg *arg, 2996process_function(struct tep_event_format *event, struct tep_print_arg *arg,
2995 char *token, char **tok) 2997 char *token, char **tok)
2996{ 2998{
2997 struct tep_function_handler *func; 2999 struct tep_function_handler *func;
@@ -3043,12 +3045,12 @@ process_function(struct event_format *event, struct print_arg *arg,
3043 3045
3044 do_warning_event(event, "function %s not defined", token); 3046 do_warning_event(event, "function %s not defined", token);
3045 free_token(token); 3047 free_token(token);
3046 return EVENT_ERROR; 3048 return TEP_EVENT_ERROR;
3047} 3049}
3048 3050
3049static enum event_type 3051static enum tep_event_type
3050process_arg_token(struct event_format *event, struct print_arg *arg, 3052process_arg_token(struct tep_event_format *event, struct tep_print_arg *arg,
3051 char **tok, enum event_type type) 3053 char **tok, enum tep_event_type type)
3052{ 3054{
3053 char *token; 3055 char *token;
3054 char *atom; 3056 char *atom;
@@ -3056,7 +3058,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
3056 token = *tok; 3058 token = *tok;
3057 3059
3058 switch (type) { 3060 switch (type) {
3059 case EVENT_ITEM: 3061 case TEP_EVENT_ITEM:
3060 if (strcmp(token, "REC") == 0) { 3062 if (strcmp(token, "REC") == 0) {
3061 free_token(token); 3063 free_token(token);
3062 type = process_entry(event, arg, &token); 3064 type = process_entry(event, arg, &token);
@@ -3070,7 +3072,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
3070 * If the next token is a parenthesis, then this 3072 * If the next token is a parenthesis, then this
3071 * is a function. 3073 * is a function.
3072 */ 3074 */
3073 if (type == EVENT_DELIM && strcmp(token, "(") == 0) { 3075 if (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0) {
3074 free_token(token); 3076 free_token(token);
3075 token = NULL; 3077 token = NULL;
3076 /* this will free atom. */ 3078 /* this will free atom. */
@@ -3078,7 +3080,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
3078 break; 3080 break;
3079 } 3081 }
3080 /* atoms can be more than one token long */ 3082 /* atoms can be more than one token long */
3081 while (type == EVENT_ITEM) { 3083 while (type == TEP_EVENT_ITEM) {
3082 char *new_atom; 3084 char *new_atom;
3083 new_atom = realloc(atom, 3085 new_atom = realloc(atom,
3084 strlen(atom) + strlen(token) + 2); 3086 strlen(atom) + strlen(token) + 2);
@@ -3086,7 +3088,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
3086 free(atom); 3088 free(atom);
3087 *tok = NULL; 3089 *tok = NULL;
3088 free_token(token); 3090 free_token(token);
3089 return EVENT_ERROR; 3091 return TEP_EVENT_ERROR;
3090 } 3092 }
3091 atom = new_atom; 3093 atom = new_atom;
3092 strcat(atom, " "); 3094 strcat(atom, " ");
@@ -3095,55 +3097,55 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
3095 type = read_token_item(&token); 3097 type = read_token_item(&token);
3096 } 3098 }
3097 3099
3098 arg->type = PRINT_ATOM; 3100 arg->type = TEP_PRINT_ATOM;
3099 arg->atom.atom = atom; 3101 arg->atom.atom = atom;
3100 break; 3102 break;
3101 3103
3102 case EVENT_DQUOTE: 3104 case TEP_EVENT_DQUOTE:
3103 case EVENT_SQUOTE: 3105 case TEP_EVENT_SQUOTE:
3104 arg->type = PRINT_ATOM; 3106 arg->type = TEP_PRINT_ATOM;
3105 arg->atom.atom = token; 3107 arg->atom.atom = token;
3106 type = read_token_item(&token); 3108 type = read_token_item(&token);
3107 break; 3109 break;
3108 case EVENT_DELIM: 3110 case TEP_EVENT_DELIM:
3109 if (strcmp(token, "(") == 0) { 3111 if (strcmp(token, "(") == 0) {
3110 free_token(token); 3112 free_token(token);
3111 type = process_paren(event, arg, &token); 3113 type = process_paren(event, arg, &token);
3112 break; 3114 break;
3113 } 3115 }
3114 case EVENT_OP: 3116 case TEP_EVENT_OP:
3115 /* handle single ops */ 3117 /* handle single ops */
3116 arg->type = PRINT_OP; 3118 arg->type = TEP_PRINT_OP;
3117 arg->op.op = token; 3119 arg->op.op = token;
3118 arg->op.left = NULL; 3120 arg->op.left = NULL;
3119 type = process_op(event, arg, &token); 3121 type = process_op(event, arg, &token);
3120 3122
3121 /* On error, the op is freed */ 3123 /* On error, the op is freed */
3122 if (type == EVENT_ERROR) 3124 if (type == TEP_EVENT_ERROR)
3123 arg->op.op = NULL; 3125 arg->op.op = NULL;
3124 3126
3125 /* return error type if errored */ 3127 /* return error type if errored */
3126 break; 3128 break;
3127 3129
3128 case EVENT_ERROR ... EVENT_NEWLINE: 3130 case TEP_EVENT_ERROR ... TEP_EVENT_NEWLINE:
3129 default: 3131 default:
3130 do_warning_event(event, "unexpected type %d", type); 3132 do_warning_event(event, "unexpected type %d", type);
3131 return EVENT_ERROR; 3133 return TEP_EVENT_ERROR;
3132 } 3134 }
3133 *tok = token; 3135 *tok = token;
3134 3136
3135 return type; 3137 return type;
3136} 3138}
3137 3139
3138static int event_read_print_args(struct event_format *event, struct print_arg **list) 3140static int event_read_print_args(struct tep_event_format *event, struct tep_print_arg **list)
3139{ 3141{
3140 enum event_type type = EVENT_ERROR; 3142 enum tep_event_type type = TEP_EVENT_ERROR;
3141 struct print_arg *arg; 3143 struct tep_print_arg *arg;
3142 char *token; 3144 char *token;
3143 int args = 0; 3145 int args = 0;
3144 3146
3145 do { 3147 do {
3146 if (type == EVENT_NEWLINE) { 3148 if (type == TEP_EVENT_NEWLINE) {
3147 type = read_token_item(&token); 3149 type = read_token_item(&token);
3148 continue; 3150 continue;
3149 } 3151 }
@@ -3157,7 +3159,7 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
3157 3159
3158 type = process_arg(event, arg, &token); 3160 type = process_arg(event, arg, &token);
3159 3161
3160 if (type == EVENT_ERROR) { 3162 if (type == TEP_EVENT_ERROR) {
3161 free_token(token); 3163 free_token(token);
3162 free_arg(arg); 3164 free_arg(arg);
3163 return -1; 3165 return -1;
@@ -3166,10 +3168,10 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
3166 *list = arg; 3168 *list = arg;
3167 args++; 3169 args++;
3168 3170
3169 if (type == EVENT_OP) { 3171 if (type == TEP_EVENT_OP) {
3170 type = process_op(event, arg, &token); 3172 type = process_op(event, arg, &token);
3171 free_token(token); 3173 free_token(token);
3172 if (type == EVENT_ERROR) { 3174 if (type == TEP_EVENT_ERROR) {
3173 *list = NULL; 3175 *list = NULL;
3174 free_arg(arg); 3176 free_arg(arg);
3175 return -1; 3177 return -1;
@@ -3178,37 +3180,37 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
3178 continue; 3180 continue;
3179 } 3181 }
3180 3182
3181 if (type == EVENT_DELIM && strcmp(token, ",") == 0) { 3183 if (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0) {
3182 free_token(token); 3184 free_token(token);
3183 *list = arg; 3185 *list = arg;
3184 list = &arg->next; 3186 list = &arg->next;
3185 continue; 3187 continue;
3186 } 3188 }
3187 break; 3189 break;
3188 } while (type != EVENT_NONE); 3190 } while (type != TEP_EVENT_NONE);
3189 3191
3190 if (type != EVENT_NONE && type != EVENT_ERROR) 3192 if (type != TEP_EVENT_NONE && type != TEP_EVENT_ERROR)
3191 free_token(token); 3193 free_token(token);
3192 3194
3193 return args; 3195 return args;
3194} 3196}
3195 3197
3196static int event_read_print(struct event_format *event) 3198static int event_read_print(struct tep_event_format *event)
3197{ 3199{
3198 enum event_type type; 3200 enum tep_event_type type;
3199 char *token; 3201 char *token;
3200 int ret; 3202 int ret;
3201 3203
3202 if (read_expected_item(EVENT_ITEM, "print") < 0) 3204 if (read_expected_item(TEP_EVENT_ITEM, "print") < 0)
3203 return -1; 3205 return -1;
3204 3206
3205 if (read_expected(EVENT_ITEM, "fmt") < 0) 3207 if (read_expected(TEP_EVENT_ITEM, "fmt") < 0)
3206 return -1; 3208 return -1;
3207 3209
3208 if (read_expected(EVENT_OP, ":") < 0) 3210 if (read_expected(TEP_EVENT_OP, ":") < 0)
3209 return -1; 3211 return -1;
3210 3212
3211 if (read_expect_type(EVENT_DQUOTE, &token) < 0) 3213 if (read_expect_type(TEP_EVENT_DQUOTE, &token) < 0)
3212 goto fail; 3214 goto fail;
3213 3215
3214 concat: 3216 concat:
@@ -3218,11 +3220,11 @@ static int event_read_print(struct event_format *event)
3218 /* ok to have no arg */ 3220 /* ok to have no arg */
3219 type = read_token_item(&token); 3221 type = read_token_item(&token);
3220 3222
3221 if (type == EVENT_NONE) 3223 if (type == TEP_EVENT_NONE)
3222 return 0; 3224 return 0;
3223 3225
3224 /* Handle concatenation of print lines */ 3226 /* Handle concatenation of print lines */
3225 if (type == EVENT_DQUOTE) { 3227 if (type == TEP_EVENT_DQUOTE) {
3226 char *cat; 3228 char *cat;
3227 3229
3228 if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0) 3230 if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0)
@@ -3234,7 +3236,7 @@ static int event_read_print(struct event_format *event)
3234 goto concat; 3236 goto concat;
3235 } 3237 }
3236 3238
3237 if (test_type_token(type, token, EVENT_DELIM, ",")) 3239 if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
3238 goto fail; 3240 goto fail;
3239 3241
3240 free_token(token); 3242 free_token(token);
@@ -3258,10 +3260,10 @@ static int event_read_print(struct event_format *event)
3258 * Returns a common field from the event by the given @name. 3260 * Returns a common field from the event by the given @name.
3259 * This only searchs the common fields and not all field. 3261 * This only searchs the common fields and not all field.
3260 */ 3262 */
3261struct format_field * 3263struct tep_format_field *
3262tep_find_common_field(struct event_format *event, const char *name) 3264tep_find_common_field(struct tep_event_format *event, const char *name)
3263{ 3265{
3264 struct format_field *format; 3266 struct tep_format_field *format;
3265 3267
3266 for (format = event->format.common_fields; 3268 for (format = event->format.common_fields;
3267 format; format = format->next) { 3269 format; format = format->next) {
@@ -3280,10 +3282,10 @@ tep_find_common_field(struct event_format *event, const char *name)
3280 * Returns a non-common field by the given @name. 3282 * Returns a non-common field by the given @name.
3281 * This does not search common fields. 3283 * This does not search common fields.
3282 */ 3284 */
3283struct format_field * 3285struct tep_format_field *
3284tep_find_field(struct event_format *event, const char *name) 3286tep_find_field(struct tep_event_format *event, const char *name)
3285{ 3287{
3286 struct format_field *format; 3288 struct tep_format_field *format;
3287 3289
3288 for (format = event->format.fields; 3290 for (format = event->format.fields;
3289 format; format = format->next) { 3291 format; format = format->next) {
@@ -3303,10 +3305,10 @@ tep_find_field(struct event_format *event, const char *name)
3303 * This searchs the common field names first, then 3305 * This searchs the common field names first, then
3304 * the non-common ones if a common one was not found. 3306 * the non-common ones if a common one was not found.
3305 */ 3307 */
3306struct format_field * 3308struct tep_format_field *
3307tep_find_any_field(struct event_format *event, const char *name) 3309tep_find_any_field(struct tep_event_format *event, const char *name)
3308{ 3310{
3309 struct format_field *format; 3311 struct tep_format_field *format;
3310 3312
3311 format = tep_find_common_field(event, name); 3313 format = tep_find_common_field(event, name);
3312 if (format) 3314 if (format)
@@ -3330,11 +3332,11 @@ unsigned long long tep_read_number(struct tep_handle *pevent,
3330 case 1: 3332 case 1:
3331 return *(unsigned char *)ptr; 3333 return *(unsigned char *)ptr;
3332 case 2: 3334 case 2:
3333 return data2host2(pevent, ptr); 3335 return tep_data2host2(pevent, ptr);
3334 case 4: 3336 case 4:
3335 return data2host4(pevent, ptr); 3337 return tep_data2host4(pevent, ptr);
3336 case 8: 3338 case 8:
3337 return data2host8(pevent, ptr); 3339 return tep_data2host8(pevent, ptr);
3338 default: 3340 default:
3339 /* BUG! */ 3341 /* BUG! */
3340 return 0; 3342 return 0;
@@ -3352,7 +3354,7 @@ unsigned long long tep_read_number(struct tep_handle *pevent,
3352 * 3354 *
3353 * Returns 0 on success, -1 otherwise. 3355 * Returns 0 on success, -1 otherwise.
3354 */ 3356 */
3355int tep_read_number_field(struct format_field *field, const void *data, 3357int tep_read_number_field(struct tep_format_field *field, const void *data,
3356 unsigned long long *value) 3358 unsigned long long *value)
3357{ 3359{
3358 if (!field) 3360 if (!field)
@@ -3373,8 +3375,8 @@ int tep_read_number_field(struct format_field *field, const void *data,
3373static int get_common_info(struct tep_handle *pevent, 3375static int get_common_info(struct tep_handle *pevent,
3374 const char *type, int *offset, int *size) 3376 const char *type, int *offset, int *size)
3375{ 3377{
3376 struct event_format *event; 3378 struct tep_event_format *event;
3377 struct format_field *field; 3379 struct tep_format_field *field;
3378 3380
3379 /* 3381 /*
3380 * All events should have the same common elements. 3382 * All events should have the same common elements.
@@ -3460,11 +3462,11 @@ static int events_id_cmp(const void *a, const void *b);
3460 * 3462 *
3461 * Returns an event that has a given @id. 3463 * Returns an event that has a given @id.
3462 */ 3464 */
3463struct event_format *tep_find_event(struct tep_handle *pevent, int id) 3465struct tep_event_format *tep_find_event(struct tep_handle *pevent, int id)
3464{ 3466{
3465 struct event_format **eventptr; 3467 struct tep_event_format **eventptr;
3466 struct event_format key; 3468 struct tep_event_format key;
3467 struct event_format *pkey = &key; 3469 struct tep_event_format *pkey = &key;
3468 3470
3469 /* Check cache first */ 3471 /* Check cache first */
3470 if (pevent->last_event && pevent->last_event->id == id) 3472 if (pevent->last_event && pevent->last_event->id == id)
@@ -3492,11 +3494,11 @@ struct event_format *tep_find_event(struct tep_handle *pevent, int id)
3492 * This returns an event with a given @name and under the system 3494 * This returns an event with a given @name and under the system
3493 * @sys. If @sys is NULL the first event with @name is returned. 3495 * @sys. If @sys is NULL the first event with @name is returned.
3494 */ 3496 */
3495struct event_format * 3497struct tep_event_format *
3496tep_find_event_by_name(struct tep_handle *pevent, 3498tep_find_event_by_name(struct tep_handle *pevent,
3497 const char *sys, const char *name) 3499 const char *sys, const char *name)
3498{ 3500{
3499 struct event_format *event; 3501 struct tep_event_format *event;
3500 int i; 3502 int i;
3501 3503
3502 if (pevent->last_event && 3504 if (pevent->last_event &&
@@ -3521,23 +3523,23 @@ tep_find_event_by_name(struct tep_handle *pevent,
3521} 3523}
3522 3524
3523static unsigned long long 3525static unsigned long long
3524eval_num_arg(void *data, int size, struct event_format *event, struct print_arg *arg) 3526eval_num_arg(void *data, int size, struct tep_event_format *event, struct tep_print_arg *arg)
3525{ 3527{
3526 struct tep_handle *pevent = event->pevent; 3528 struct tep_handle *pevent = event->pevent;
3527 unsigned long long val = 0; 3529 unsigned long long val = 0;
3528 unsigned long long left, right; 3530 unsigned long long left, right;
3529 struct print_arg *typearg = NULL; 3531 struct tep_print_arg *typearg = NULL;
3530 struct print_arg *larg; 3532 struct tep_print_arg *larg;
3531 unsigned long offset; 3533 unsigned long offset;
3532 unsigned int field_size; 3534 unsigned int field_size;
3533 3535
3534 switch (arg->type) { 3536 switch (arg->type) {
3535 case PRINT_NULL: 3537 case TEP_PRINT_NULL:
3536 /* ?? */ 3538 /* ?? */
3537 return 0; 3539 return 0;
3538 case PRINT_ATOM: 3540 case TEP_PRINT_ATOM:
3539 return strtoull(arg->atom.atom, NULL, 0); 3541 return strtoull(arg->atom.atom, NULL, 0);
3540 case PRINT_FIELD: 3542 case TEP_PRINT_FIELD:
3541 if (!arg->field.field) { 3543 if (!arg->field.field) {
3542 arg->field.field = tep_find_any_field(event, arg->field.name); 3544 arg->field.field = tep_find_any_field(event, arg->field.name);
3543 if (!arg->field.field) 3545 if (!arg->field.field)
@@ -3548,27 +3550,27 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3548 val = tep_read_number(pevent, data + arg->field.field->offset, 3550 val = tep_read_number(pevent, data + arg->field.field->offset,
3549 arg->field.field->size); 3551 arg->field.field->size);
3550 break; 3552 break;
3551 case PRINT_FLAGS: 3553 case TEP_PRINT_FLAGS:
3552 case PRINT_SYMBOL: 3554 case TEP_PRINT_SYMBOL:
3553 case PRINT_INT_ARRAY: 3555 case TEP_PRINT_INT_ARRAY:
3554 case PRINT_HEX: 3556 case TEP_PRINT_HEX:
3555 case PRINT_HEX_STR: 3557 case TEP_PRINT_HEX_STR:
3556 break; 3558 break;
3557 case PRINT_TYPE: 3559 case TEP_PRINT_TYPE:
3558 val = eval_num_arg(data, size, event, arg->typecast.item); 3560 val = eval_num_arg(data, size, event, arg->typecast.item);
3559 return eval_type(val, arg, 0); 3561 return eval_type(val, arg, 0);
3560 case PRINT_STRING: 3562 case TEP_PRINT_STRING:
3561 case PRINT_BSTRING: 3563 case TEP_PRINT_BSTRING:
3562 case PRINT_BITMASK: 3564 case TEP_PRINT_BITMASK:
3563 return 0; 3565 return 0;
3564 case PRINT_FUNC: { 3566 case TEP_PRINT_FUNC: {
3565 struct trace_seq s; 3567 struct trace_seq s;
3566 trace_seq_init(&s); 3568 trace_seq_init(&s);
3567 val = process_defined_func(&s, data, size, event, arg); 3569 val = process_defined_func(&s, data, size, event, arg);
3568 trace_seq_destroy(&s); 3570 trace_seq_destroy(&s);
3569 return val; 3571 return val;
3570 } 3572 }
3571 case PRINT_OP: 3573 case TEP_PRINT_OP:
3572 if (strcmp(arg->op.op, "[") == 0) { 3574 if (strcmp(arg->op.op, "[") == 0) {
3573 /* 3575 /*
3574 * Arrays are special, since we don't want 3576 * Arrays are special, since we don't want
@@ -3578,7 +3580,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3578 3580
3579 /* handle typecasts */ 3581 /* handle typecasts */
3580 larg = arg->op.left; 3582 larg = arg->op.left;
3581 while (larg->type == PRINT_TYPE) { 3583 while (larg->type == TEP_PRINT_TYPE) {
3582 if (!typearg) 3584 if (!typearg)
3583 typearg = larg; 3585 typearg = larg;
3584 larg = larg->typecast.item; 3586 larg = larg->typecast.item;
@@ -3588,7 +3590,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3588 field_size = pevent->long_size; 3590 field_size = pevent->long_size;
3589 3591
3590 switch (larg->type) { 3592 switch (larg->type) {
3591 case PRINT_DYNAMIC_ARRAY: 3593 case TEP_PRINT_DYNAMIC_ARRAY:
3592 offset = tep_read_number(pevent, 3594 offset = tep_read_number(pevent,
3593 data + larg->dynarray.field->offset, 3595 data + larg->dynarray.field->offset,
3594 larg->dynarray.field->size); 3596 larg->dynarray.field->size);
@@ -3602,7 +3604,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3602 offset &= 0xffff; 3604 offset &= 0xffff;
3603 offset += right; 3605 offset += right;
3604 break; 3606 break;
3605 case PRINT_FIELD: 3607 case TEP_PRINT_FIELD:
3606 if (!larg->field.field) { 3608 if (!larg->field.field) {
3607 larg->field.field = 3609 larg->field.field =
3608 tep_find_any_field(event, larg->field.name); 3610 tep_find_any_field(event, larg->field.name);
@@ -3718,7 +3720,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3718 goto out_warning_op; 3720 goto out_warning_op;
3719 } 3721 }
3720 break; 3722 break;
3721 case PRINT_DYNAMIC_ARRAY_LEN: 3723 case TEP_PRINT_DYNAMIC_ARRAY_LEN:
3722 offset = tep_read_number(pevent, 3724 offset = tep_read_number(pevent,
3723 data + arg->dynarray.field->offset, 3725 data + arg->dynarray.field->offset,
3724 arg->dynarray.field->size); 3726 arg->dynarray.field->size);
@@ -3729,7 +3731,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
3729 */ 3731 */
3730 val = (unsigned long long)(offset >> 16); 3732 val = (unsigned long long)(offset >> 16);
3731 break; 3733 break;
3732 case PRINT_DYNAMIC_ARRAY: 3734 case TEP_PRINT_DYNAMIC_ARRAY:
3733 /* Without [], we pass the address to the dynamic data */ 3735 /* Without [], we pass the address to the dynamic data */
3734 offset = tep_read_number(pevent, 3736 offset = tep_read_number(pevent,
3735 data + arg->dynarray.field->offset, 3737 data + arg->dynarray.field->offset,
@@ -3861,12 +3863,12 @@ static void print_bitmask_to_seq(struct tep_handle *pevent,
3861} 3863}
3862 3864
3863static void print_str_arg(struct trace_seq *s, void *data, int size, 3865static void print_str_arg(struct trace_seq *s, void *data, int size,
3864 struct event_format *event, const char *format, 3866 struct tep_event_format *event, const char *format,
3865 int len_arg, struct print_arg *arg) 3867 int len_arg, struct tep_print_arg *arg)
3866{ 3868{
3867 struct tep_handle *pevent = event->pevent; 3869 struct tep_handle *pevent = event->pevent;
3868 struct print_flag_sym *flag; 3870 struct tep_print_flag_sym *flag;
3869 struct format_field *field; 3871 struct tep_format_field *field;
3870 struct printk_map *printk; 3872 struct printk_map *printk;
3871 long long val, fval; 3873 long long val, fval;
3872 unsigned long long addr; 3874 unsigned long long addr;
@@ -3876,13 +3878,13 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3876 int i, len; 3878 int i, len;
3877 3879
3878 switch (arg->type) { 3880 switch (arg->type) {
3879 case PRINT_NULL: 3881 case TEP_PRINT_NULL:
3880 /* ?? */ 3882 /* ?? */
3881 return; 3883 return;
3882 case PRINT_ATOM: 3884 case TEP_PRINT_ATOM:
3883 print_str_to_seq(s, format, len_arg, arg->atom.atom); 3885 print_str_to_seq(s, format, len_arg, arg->atom.atom);
3884 return; 3886 return;
3885 case PRINT_FIELD: 3887 case TEP_PRINT_FIELD:
3886 field = arg->field.field; 3888 field = arg->field.field;
3887 if (!field) { 3889 if (!field) {
3888 field = tep_find_any_field(event, arg->field.name); 3890 field = tep_find_any_field(event, arg->field.name);
@@ -3900,7 +3902,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3900 * and the size is the same as long_size, assume that it 3902 * and the size is the same as long_size, assume that it
3901 * is a pointer. 3903 * is a pointer.
3902 */ 3904 */
3903 if (!(field->flags & FIELD_IS_ARRAY) && 3905 if (!(field->flags & TEP_FIELD_IS_ARRAY) &&
3904 field->size == pevent->long_size) { 3906 field->size == pevent->long_size) {
3905 3907
3906 /* Handle heterogeneous recording and processing 3908 /* Handle heterogeneous recording and processing
@@ -3939,7 +3941,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3939 print_str_to_seq(s, format, len_arg, str); 3941 print_str_to_seq(s, format, len_arg, str);
3940 free(str); 3942 free(str);
3941 break; 3943 break;
3942 case PRINT_FLAGS: 3944 case TEP_PRINT_FLAGS:
3943 val = eval_num_arg(data, size, event, arg->flags.field); 3945 val = eval_num_arg(data, size, event, arg->flags.field);
3944 print = 0; 3946 print = 0;
3945 for (flag = arg->flags.flags; flag; flag = flag->next) { 3947 for (flag = arg->flags.flags; flag; flag = flag->next) {
@@ -3962,7 +3964,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3962 trace_seq_printf(s, "0x%llx", val); 3964 trace_seq_printf(s, "0x%llx", val);
3963 } 3965 }
3964 break; 3966 break;
3965 case PRINT_SYMBOL: 3967 case TEP_PRINT_SYMBOL:
3966 val = eval_num_arg(data, size, event, arg->symbol.field); 3968 val = eval_num_arg(data, size, event, arg->symbol.field);
3967 for (flag = arg->symbol.symbols; flag; flag = flag->next) { 3969 for (flag = arg->symbol.symbols; flag; flag = flag->next) {
3968 fval = eval_flag(flag->value); 3970 fval = eval_flag(flag->value);
@@ -3974,9 +3976,9 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3974 if (!flag) 3976 if (!flag)
3975 trace_seq_printf(s, "0x%llx", val); 3977 trace_seq_printf(s, "0x%llx", val);
3976 break; 3978 break;
3977 case PRINT_HEX: 3979 case TEP_PRINT_HEX:
3978 case PRINT_HEX_STR: 3980 case TEP_PRINT_HEX_STR:
3979 if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) { 3981 if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
3980 unsigned long offset; 3982 unsigned long offset;
3981 offset = tep_read_number(pevent, 3983 offset = tep_read_number(pevent,
3982 data + arg->hex.field->dynarray.field->offset, 3984 data + arg->hex.field->dynarray.field->offset,
@@ -3995,19 +3997,19 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
3995 } 3997 }
3996 len = eval_num_arg(data, size, event, arg->hex.size); 3998 len = eval_num_arg(data, size, event, arg->hex.size);
3997 for (i = 0; i < len; i++) { 3999 for (i = 0; i < len; i++) {
3998 if (i && arg->type == PRINT_HEX) 4000 if (i && arg->type == TEP_PRINT_HEX)
3999 trace_seq_putc(s, ' '); 4001 trace_seq_putc(s, ' ');
4000 trace_seq_printf(s, "%02x", hex[i]); 4002 trace_seq_printf(s, "%02x", hex[i]);
4001 } 4003 }
4002 break; 4004 break;
4003 4005
4004 case PRINT_INT_ARRAY: { 4006 case TEP_PRINT_INT_ARRAY: {
4005 void *num; 4007 void *num;
4006 int el_size; 4008 int el_size;
4007 4009
4008 if (arg->int_array.field->type == PRINT_DYNAMIC_ARRAY) { 4010 if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
4009 unsigned long offset; 4011 unsigned long offset;
4010 struct format_field *field = 4012 struct tep_format_field *field =
4011 arg->int_array.field->dynarray.field; 4013 arg->int_array.field->dynarray.field;
4012 offset = tep_read_number(pevent, 4014 offset = tep_read_number(pevent,
4013 data + field->offset, 4015 data + field->offset,
@@ -4049,43 +4051,43 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
4049 } 4051 }
4050 break; 4052 break;
4051 } 4053 }
4052 case PRINT_TYPE: 4054 case TEP_PRINT_TYPE:
4053 break; 4055 break;
4054 case PRINT_STRING: { 4056 case TEP_PRINT_STRING: {
4055 int str_offset; 4057 int str_offset;
4056 4058
4057 if (arg->string.offset == -1) { 4059 if (arg->string.offset == -1) {
4058 struct format_field *f; 4060 struct tep_format_field *f;
4059 4061
4060 f = tep_find_any_field(event, arg->string.string); 4062 f = tep_find_any_field(event, arg->string.string);
4061 arg->string.offset = f->offset; 4063 arg->string.offset = f->offset;
4062 } 4064 }
4063 str_offset = data2host4(pevent, data + arg->string.offset); 4065 str_offset = tep_data2host4(pevent, data + arg->string.offset);
4064 str_offset &= 0xffff; 4066 str_offset &= 0xffff;
4065 print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset); 4067 print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset);
4066 break; 4068 break;
4067 } 4069 }
4068 case PRINT_BSTRING: 4070 case TEP_PRINT_BSTRING:
4069 print_str_to_seq(s, format, len_arg, arg->string.string); 4071 print_str_to_seq(s, format, len_arg, arg->string.string);
4070 break; 4072 break;
4071 case PRINT_BITMASK: { 4073 case TEP_PRINT_BITMASK: {
4072 int bitmask_offset; 4074 int bitmask_offset;
4073 int bitmask_size; 4075 int bitmask_size;
4074 4076
4075 if (arg->bitmask.offset == -1) { 4077 if (arg->bitmask.offset == -1) {
4076 struct format_field *f; 4078 struct tep_format_field *f;
4077 4079
4078 f = tep_find_any_field(event, arg->bitmask.bitmask); 4080 f = tep_find_any_field(event, arg->bitmask.bitmask);
4079 arg->bitmask.offset = f->offset; 4081 arg->bitmask.offset = f->offset;
4080 } 4082 }
4081 bitmask_offset = data2host4(pevent, data + arg->bitmask.offset); 4083 bitmask_offset = tep_data2host4(pevent, data + arg->bitmask.offset);
4082 bitmask_size = bitmask_offset >> 16; 4084 bitmask_size = bitmask_offset >> 16;
4083 bitmask_offset &= 0xffff; 4085 bitmask_offset &= 0xffff;
4084 print_bitmask_to_seq(pevent, s, format, len_arg, 4086 print_bitmask_to_seq(pevent, s, format, len_arg,
4085 data + bitmask_offset, bitmask_size); 4087 data + bitmask_offset, bitmask_size);
4086 break; 4088 break;
4087 } 4089 }
4088 case PRINT_OP: 4090 case TEP_PRINT_OP:
4089 /* 4091 /*
4090 * The only op for string should be ? : 4092 * The only op for string should be ? :
4091 */ 4093 */
@@ -4099,7 +4101,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
4099 print_str_arg(s, data, size, event, 4101 print_str_arg(s, data, size, event,
4100 format, len_arg, arg->op.right->op.right); 4102 format, len_arg, arg->op.right->op.right);
4101 break; 4103 break;
4102 case PRINT_FUNC: 4104 case TEP_PRINT_FUNC:
4103 process_defined_func(s, data, size, event, arg); 4105 process_defined_func(s, data, size, event, arg);
4104 break; 4106 break;
4105 default: 4107 default:
@@ -4116,13 +4118,13 @@ out_warning_field:
4116 4118
4117static unsigned long long 4119static unsigned long long
4118process_defined_func(struct trace_seq *s, void *data, int size, 4120process_defined_func(struct trace_seq *s, void *data, int size,
4119 struct event_format *event, struct print_arg *arg) 4121 struct tep_event_format *event, struct tep_print_arg *arg)
4120{ 4122{
4121 struct tep_function_handler *func_handle = arg->func.func; 4123 struct tep_function_handler *func_handle = arg->func.func;
4122 struct func_params *param; 4124 struct func_params *param;
4123 unsigned long long *args; 4125 unsigned long long *args;
4124 unsigned long long ret; 4126 unsigned long long ret;
4125 struct print_arg *farg; 4127 struct tep_print_arg *farg;
4126 struct trace_seq str; 4128 struct trace_seq str;
4127 struct save_str { 4129 struct save_str {
4128 struct save_str *next; 4130 struct save_str *next;
@@ -4199,9 +4201,9 @@ out_free:
4199 return ret; 4201 return ret;
4200} 4202}
4201 4203
4202static void free_args(struct print_arg *args) 4204static void free_args(struct tep_print_arg *args)
4203{ 4205{
4204 struct print_arg *next; 4206 struct tep_print_arg *next;
4205 4207
4206 while (args) { 4208 while (args) {
4207 next = args->next; 4209 next = args->next;
@@ -4211,11 +4213,11 @@ static void free_args(struct print_arg *args)
4211 } 4213 }
4212} 4214}
4213 4215
4214static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event) 4216static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, struct tep_event_format *event)
4215{ 4217{
4216 struct tep_handle *pevent = event->pevent; 4218 struct tep_handle *pevent = event->pevent;
4217 struct format_field *field, *ip_field; 4219 struct tep_format_field *field, *ip_field;
4218 struct print_arg *args, *arg, **next; 4220 struct tep_print_arg *args, *arg, **next;
4219 unsigned long long ip, val; 4221 unsigned long long ip, val;
4220 char *ptr; 4222 char *ptr;
4221 void *bptr; 4223 void *bptr;
@@ -4254,7 +4256,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
4254 arg->next = NULL; 4256 arg->next = NULL;
4255 next = &arg->next; 4257 next = &arg->next;
4256 4258
4257 arg->type = PRINT_ATOM; 4259 arg->type = TEP_PRINT_ATOM;
4258 4260
4259 if (asprintf(&arg->atom.atom, "%lld", ip) < 0) 4261 if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
4260 goto out_free; 4262 goto out_free;
@@ -4342,7 +4344,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
4342 goto out_free; 4344 goto out_free;
4343 } 4345 }
4344 arg->next = NULL; 4346 arg->next = NULL;
4345 arg->type = PRINT_ATOM; 4347 arg->type = TEP_PRINT_ATOM;
4346 if (asprintf(&arg->atom.atom, "%lld", val) < 0) { 4348 if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
4347 free(arg); 4349 free(arg);
4348 goto out_free; 4350 goto out_free;
@@ -4366,7 +4368,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
4366 goto out_free; 4368 goto out_free;
4367 } 4369 }
4368 arg->next = NULL; 4370 arg->next = NULL;
4369 arg->type = PRINT_BSTRING; 4371 arg->type = TEP_PRINT_BSTRING;
4370 arg->string.string = strdup(bptr); 4372 arg->string.string = strdup(bptr);
4371 if (!arg->string.string) 4373 if (!arg->string.string)
4372 goto out_free; 4374 goto out_free;
@@ -4388,11 +4390,11 @@ out_free:
4388 4390
4389static char * 4391static char *
4390get_bprint_format(void *data, int size __maybe_unused, 4392get_bprint_format(void *data, int size __maybe_unused,
4391 struct event_format *event) 4393 struct tep_event_format *event)
4392{ 4394{
4393 struct tep_handle *pevent = event->pevent; 4395 struct tep_handle *pevent = event->pevent;
4394 unsigned long long addr; 4396 unsigned long long addr;
4395 struct format_field *field; 4397 struct tep_format_field *field;
4396 struct printk_map *printk; 4398 struct printk_map *printk;
4397 char *format; 4399 char *format;
4398 4400
@@ -4423,17 +4425,17 @@ get_bprint_format(void *data, int size __maybe_unused,
4423} 4425}
4424 4426
4425static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size, 4427static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
4426 struct event_format *event, struct print_arg *arg) 4428 struct tep_event_format *event, struct tep_print_arg *arg)
4427{ 4429{
4428 unsigned char *buf; 4430 unsigned char *buf;
4429 const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x"; 4431 const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
4430 4432
4431 if (arg->type == PRINT_FUNC) { 4433 if (arg->type == TEP_PRINT_FUNC) {
4432 process_defined_func(s, data, size, event, arg); 4434 process_defined_func(s, data, size, event, arg);
4433 return; 4435 return;
4434 } 4436 }
4435 4437
4436 if (arg->type != PRINT_FIELD) { 4438 if (arg->type != TEP_PRINT_FIELD) {
4437 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", 4439 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d",
4438 arg->type); 4440 arg->type);
4439 return; 4441 return;
@@ -4576,17 +4578,17 @@ static void print_ip6_addr(struct trace_seq *s, char i, unsigned char *buf)
4576 * %pISpc print an IP address based on sockaddr; p adds port. 4578 * %pISpc print an IP address based on sockaddr; p adds port.
4577 */ 4579 */
4578static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i, 4580static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i,
4579 void *data, int size, struct event_format *event, 4581 void *data, int size, struct tep_event_format *event,
4580 struct print_arg *arg) 4582 struct tep_print_arg *arg)
4581{ 4583{
4582 unsigned char *buf; 4584 unsigned char *buf;
4583 4585
4584 if (arg->type == PRINT_FUNC) { 4586 if (arg->type == TEP_PRINT_FUNC) {
4585 process_defined_func(s, data, size, event, arg); 4587 process_defined_func(s, data, size, event, arg);
4586 return 0; 4588 return 0;
4587 } 4589 }
4588 4590
4589 if (arg->type != PRINT_FIELD) { 4591 if (arg->type != TEP_PRINT_FIELD) {
4590 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); 4592 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
4591 return 0; 4593 return 0;
4592 } 4594 }
@@ -4613,8 +4615,8 @@ static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i,
4613} 4615}
4614 4616
4615static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i, 4617static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
4616 void *data, int size, struct event_format *event, 4618 void *data, int size, struct tep_event_format *event,
4617 struct print_arg *arg) 4619 struct tep_print_arg *arg)
4618{ 4620{
4619 char have_c = 0; 4621 char have_c = 0;
4620 unsigned char *buf; 4622 unsigned char *buf;
@@ -4627,12 +4629,12 @@ static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
4627 rc++; 4629 rc++;
4628 } 4630 }
4629 4631
4630 if (arg->type == PRINT_FUNC) { 4632 if (arg->type == TEP_PRINT_FUNC) {
4631 process_defined_func(s, data, size, event, arg); 4633 process_defined_func(s, data, size, event, arg);
4632 return rc; 4634 return rc;
4633 } 4635 }
4634 4636
4635 if (arg->type != PRINT_FIELD) { 4637 if (arg->type != TEP_PRINT_FIELD) {
4636 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); 4638 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
4637 return rc; 4639 return rc;
4638 } 4640 }
@@ -4663,8 +4665,8 @@ static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
4663} 4665}
4664 4666
4665static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i, 4667static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
4666 void *data, int size, struct event_format *event, 4668 void *data, int size, struct tep_event_format *event,
4667 struct print_arg *arg) 4669 struct tep_print_arg *arg)
4668{ 4670{
4669 char have_c = 0, have_p = 0; 4671 char have_c = 0, have_p = 0;
4670 unsigned char *buf; 4672 unsigned char *buf;
@@ -4685,12 +4687,12 @@ static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
4685 } 4687 }
4686 } 4688 }
4687 4689
4688 if (arg->type == PRINT_FUNC) { 4690 if (arg->type == TEP_PRINT_FUNC) {
4689 process_defined_func(s, data, size, event, arg); 4691 process_defined_func(s, data, size, event, arg);
4690 return rc; 4692 return rc;
4691 } 4693 }
4692 4694
4693 if (arg->type != PRINT_FIELD) { 4695 if (arg->type != TEP_PRINT_FIELD) {
4694 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type); 4696 trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
4695 return rc; 4697 return rc;
4696 } 4698 }
@@ -4745,8 +4747,8 @@ static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
4745} 4747}
4746 4748
4747static int print_ip_arg(struct trace_seq *s, const char *ptr, 4749static int print_ip_arg(struct trace_seq *s, const char *ptr,
4748 void *data, int size, struct event_format *event, 4750 void *data, int size, struct tep_event_format *event,
4749 struct print_arg *arg) 4751 struct tep_print_arg *arg)
4750{ 4752{
4751 char i = *ptr; /* 'i' or 'I' */ 4753 char i = *ptr; /* 'i' or 'I' */
4752 char ver; 4754 char ver;
@@ -4787,22 +4789,22 @@ static int is_printable_array(char *p, unsigned int len)
4787} 4789}
4788 4790
4789void tep_print_field(struct trace_seq *s, void *data, 4791void tep_print_field(struct trace_seq *s, void *data,
4790 struct format_field *field) 4792 struct tep_format_field *field)
4791{ 4793{
4792 unsigned long long val; 4794 unsigned long long val;
4793 unsigned int offset, len, i; 4795 unsigned int offset, len, i;
4794 struct tep_handle *pevent = field->event->pevent; 4796 struct tep_handle *pevent = field->event->pevent;
4795 4797
4796 if (field->flags & FIELD_IS_ARRAY) { 4798 if (field->flags & TEP_FIELD_IS_ARRAY) {
4797 offset = field->offset; 4799 offset = field->offset;
4798 len = field->size; 4800 len = field->size;
4799 if (field->flags & FIELD_IS_DYNAMIC) { 4801 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
4800 val = tep_read_number(pevent, data + offset, len); 4802 val = tep_read_number(pevent, data + offset, len);
4801 offset = val; 4803 offset = val;
4802 len = offset >> 16; 4804 len = offset >> 16;
4803 offset &= 0xffff; 4805 offset &= 0xffff;
4804 } 4806 }
4805 if (field->flags & FIELD_IS_STRING && 4807 if (field->flags & TEP_FIELD_IS_STRING &&
4806 is_printable_array(data + offset, len)) { 4808 is_printable_array(data + offset, len)) {
4807 trace_seq_printf(s, "%s", (char *)data + offset); 4809 trace_seq_printf(s, "%s", (char *)data + offset);
4808 } else { 4810 } else {
@@ -4814,21 +4816,21 @@ void tep_print_field(struct trace_seq *s, void *data,
4814 *((unsigned char *)data + offset + i)); 4816 *((unsigned char *)data + offset + i));
4815 } 4817 }
4816 trace_seq_putc(s, ']'); 4818 trace_seq_putc(s, ']');
4817 field->flags &= ~FIELD_IS_STRING; 4819 field->flags &= ~TEP_FIELD_IS_STRING;
4818 } 4820 }
4819 } else { 4821 } else {
4820 val = tep_read_number(pevent, data + field->offset, 4822 val = tep_read_number(pevent, data + field->offset,
4821 field->size); 4823 field->size);
4822 if (field->flags & FIELD_IS_POINTER) { 4824 if (field->flags & TEP_FIELD_IS_POINTER) {
4823 trace_seq_printf(s, "0x%llx", val); 4825 trace_seq_printf(s, "0x%llx", val);
4824 } else if (field->flags & FIELD_IS_SIGNED) { 4826 } else if (field->flags & TEP_FIELD_IS_SIGNED) {
4825 switch (field->size) { 4827 switch (field->size) {
4826 case 4: 4828 case 4:
4827 /* 4829 /*
4828 * If field is long then print it in hex. 4830 * If field is long then print it in hex.
4829 * A long usually stores pointers. 4831 * A long usually stores pointers.
4830 */ 4832 */
4831 if (field->flags & FIELD_IS_LONG) 4833 if (field->flags & TEP_FIELD_IS_LONG)
4832 trace_seq_printf(s, "0x%x", (int)val); 4834 trace_seq_printf(s, "0x%x", (int)val);
4833 else 4835 else
4834 trace_seq_printf(s, "%d", (int)val); 4836 trace_seq_printf(s, "%d", (int)val);
@@ -4843,7 +4845,7 @@ void tep_print_field(struct trace_seq *s, void *data,
4843 trace_seq_printf(s, "%lld", val); 4845 trace_seq_printf(s, "%lld", val);
4844 } 4846 }
4845 } else { 4847 } else {
4846 if (field->flags & FIELD_IS_LONG) 4848 if (field->flags & TEP_FIELD_IS_LONG)
4847 trace_seq_printf(s, "0x%llx", val); 4849 trace_seq_printf(s, "0x%llx", val);
4848 else 4850 else
4849 trace_seq_printf(s, "%llu", val); 4851 trace_seq_printf(s, "%llu", val);
@@ -4852,9 +4854,9 @@ void tep_print_field(struct trace_seq *s, void *data,
4852} 4854}
4853 4855
4854void tep_print_fields(struct trace_seq *s, void *data, 4856void tep_print_fields(struct trace_seq *s, void *data,
4855 int size __maybe_unused, struct event_format *event) 4857 int size __maybe_unused, struct tep_event_format *event)
4856{ 4858{
4857 struct format_field *field; 4859 struct tep_format_field *field;
4858 4860
4859 field = event->format.fields; 4861 field = event->format.fields;
4860 while (field) { 4862 while (field) {
@@ -4864,12 +4866,12 @@ void tep_print_fields(struct trace_seq *s, void *data,
4864 } 4866 }
4865} 4867}
4866 4868
4867static void pretty_print(struct trace_seq *s, void *data, int size, struct event_format *event) 4869static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_event_format *event)
4868{ 4870{
4869 struct tep_handle *pevent = event->pevent; 4871 struct tep_handle *pevent = event->pevent;
4870 struct print_fmt *print_fmt = &event->print_fmt; 4872 struct tep_print_fmt *print_fmt = &event->print_fmt;
4871 struct print_arg *arg = print_fmt->args; 4873 struct tep_print_arg *arg = print_fmt->args;
4872 struct print_arg *args = NULL; 4874 struct tep_print_arg *args = NULL;
4873 const char *ptr = print_fmt->format; 4875 const char *ptr = print_fmt->format;
4874 unsigned long long val; 4876 unsigned long long val;
4875 struct func_map *func; 4877 struct func_map *func;
@@ -4883,13 +4885,13 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4883 int len; 4885 int len;
4884 int ls; 4886 int ls;
4885 4887
4886 if (event->flags & EVENT_FL_FAILED) { 4888 if (event->flags & TEP_EVENT_FL_FAILED) {
4887 trace_seq_printf(s, "[FAILED TO PARSE]"); 4889 trace_seq_printf(s, "[FAILED TO PARSE]");
4888 tep_print_fields(s, data, size, event); 4890 tep_print_fields(s, data, size, event);
4889 return; 4891 return;
4890 } 4892 }
4891 4893
4892 if (event->flags & EVENT_FL_ISBPRINT) { 4894 if (event->flags & TEP_EVENT_FL_ISBPRINT) {
4893 bprint_fmt = get_bprint_format(data, size, event); 4895 bprint_fmt = get_bprint_format(data, size, event);
4894 args = make_bprint_args(bprint_fmt, data, size, event); 4896 args = make_bprint_args(bprint_fmt, data, size, event);
4895 arg = args; 4897 arg = args;
@@ -4944,7 +4946,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4944 /* The argument is the length. */ 4946 /* The argument is the length. */
4945 if (!arg) { 4947 if (!arg) {
4946 do_warning_event(event, "no argument match"); 4948 do_warning_event(event, "no argument match");
4947 event->flags |= EVENT_FL_FAILED; 4949 event->flags |= TEP_EVENT_FL_FAILED;
4948 goto out_failed; 4950 goto out_failed;
4949 } 4951 }
4950 len_arg = eval_num_arg(data, size, event, arg); 4952 len_arg = eval_num_arg(data, size, event, arg);
@@ -4966,7 +4968,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4966 if (isalnum(ptr[1])) 4968 if (isalnum(ptr[1]))
4967 ptr++; 4969 ptr++;
4968 4970
4969 if (arg->type == PRINT_BSTRING) { 4971 if (arg->type == TEP_PRINT_BSTRING) {
4970 trace_seq_puts(s, arg->string.string); 4972 trace_seq_puts(s, arg->string.string);
4971 break; 4973 break;
4972 } 4974 }
@@ -4997,7 +4999,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
4997 case 'u': 4999 case 'u':
4998 if (!arg) { 5000 if (!arg) {
4999 do_warning_event(event, "no argument match"); 5001 do_warning_event(event, "no argument match");
5000 event->flags |= EVENT_FL_FAILED; 5002 event->flags |= TEP_EVENT_FL_FAILED;
5001 goto out_failed; 5003 goto out_failed;
5002 } 5004 }
5003 5005
@@ -5007,7 +5009,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
5007 /* should never happen */ 5009 /* should never happen */
5008 if (len > 31) { 5010 if (len > 31) {
5009 do_warning_event(event, "bad format!"); 5011 do_warning_event(event, "bad format!");
5010 event->flags |= EVENT_FL_FAILED; 5012 event->flags |= TEP_EVENT_FL_FAILED;
5011 len = 31; 5013 len = 31;
5012 } 5014 }
5013 5015
@@ -5073,13 +5075,13 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
5073 break; 5075 break;
5074 default: 5076 default:
5075 do_warning_event(event, "bad count (%d)", ls); 5077 do_warning_event(event, "bad count (%d)", ls);
5076 event->flags |= EVENT_FL_FAILED; 5078 event->flags |= TEP_EVENT_FL_FAILED;
5077 } 5079 }
5078 break; 5080 break;
5079 case 's': 5081 case 's':
5080 if (!arg) { 5082 if (!arg) {
5081 do_warning_event(event, "no matching argument"); 5083 do_warning_event(event, "no matching argument");
5082 event->flags |= EVENT_FL_FAILED; 5084 event->flags |= TEP_EVENT_FL_FAILED;
5083 goto out_failed; 5085 goto out_failed;
5084 } 5086 }
5085 5087
@@ -5089,7 +5091,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
5089 /* should never happen */ 5091 /* should never happen */
5090 if (len > 31) { 5092 if (len > 31) {
5091 do_warning_event(event, "bad format!"); 5093 do_warning_event(event, "bad format!");
5092 event->flags |= EVENT_FL_FAILED; 5094 event->flags |= TEP_EVENT_FL_FAILED;
5093 len = 31; 5095 len = 31;
5094 } 5096 }
5095 5097
@@ -5114,7 +5116,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
5114 trace_seq_putc(s, *ptr); 5116 trace_seq_putc(s, *ptr);
5115 } 5117 }
5116 5118
5117 if (event->flags & EVENT_FL_FAILED) { 5119 if (event->flags & TEP_EVENT_FL_FAILED) {
5118out_failed: 5120out_failed:
5119 trace_seq_printf(s, "[FAILED TO PARSE]"); 5121 trace_seq_printf(s, "[FAILED TO PARSE]");
5120 } 5122 }
@@ -5227,7 +5229,7 @@ int tep_data_type(struct tep_handle *pevent, struct tep_record *rec)
5227 * 5229 *
5228 * This returns the event form a given @type; 5230 * This returns the event form a given @type;
5229 */ 5231 */
5230struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type) 5232struct tep_event_format *tep_data_event_from_type(struct tep_handle *pevent, int type)
5231{ 5233{
5232 return tep_find_event(pevent, type); 5234 return tep_find_event(pevent, type);
5233} 5235}
@@ -5385,16 +5387,16 @@ int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline)
5385 * This parses the raw @data using the given @event information and 5387 * This parses the raw @data using the given @event information and
5386 * writes the print format into the trace_seq. 5388 * writes the print format into the trace_seq.
5387 */ 5389 */
5388void tep_event_info(struct trace_seq *s, struct event_format *event, 5390void tep_event_info(struct trace_seq *s, struct tep_event_format *event,
5389 struct tep_record *record) 5391 struct tep_record *record)
5390{ 5392{
5391 int print_pretty = 1; 5393 int print_pretty = 1;
5392 5394
5393 if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW)) 5395 if (event->pevent->print_raw || (event->flags & TEP_EVENT_FL_PRINTRAW))
5394 tep_print_fields(s, record->data, record->size, event); 5396 tep_print_fields(s, record->data, record->size, event);
5395 else { 5397 else {
5396 5398
5397 if (event->handler && !(event->flags & EVENT_FL_NOHANDLE)) 5399 if (event->handler && !(event->flags & TEP_EVENT_FL_NOHANDLE))
5398 print_pretty = event->handler(s, record, event, 5400 print_pretty = event->handler(s, record, event,
5399 event->context); 5401 event->context);
5400 5402
@@ -5426,7 +5428,7 @@ static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
5426 * Returns the associated event for a given record, or NULL if non is 5428 * Returns the associated event for a given record, or NULL if non is
5427 * is found. 5429 * is found.
5428 */ 5430 */
5429struct event_format * 5431struct tep_event_format *
5430tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record) 5432tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record)
5431{ 5433{
5432 int type; 5434 int type;
@@ -5451,7 +5453,7 @@ tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record)
5451 * Writes the tasks comm, pid and CPU to @s. 5453 * Writes the tasks comm, pid and CPU to @s.
5452 */ 5454 */
5453void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s, 5455void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
5454 struct event_format *event, 5456 struct tep_event_format *event,
5455 struct tep_record *record) 5457 struct tep_record *record)
5456{ 5458{
5457 void *data = record->data; 5459 void *data = record->data;
@@ -5479,7 +5481,7 @@ void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
5479 * Writes the timestamp of the record into @s. 5481 * Writes the timestamp of the record into @s.
5480 */ 5482 */
5481void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s, 5483void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
5482 struct event_format *event, 5484 struct tep_event_format *event,
5483 struct tep_record *record, 5485 struct tep_record *record,
5484 bool use_trace_clock) 5486 bool use_trace_clock)
5485{ 5487{
@@ -5529,7 +5531,7 @@ void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
5529 * Writes the parsing of the record's data to @s. 5531 * Writes the parsing of the record's data to @s.
5530 */ 5532 */
5531void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s, 5533void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
5532 struct event_format *event, 5534 struct tep_event_format *event,
5533 struct tep_record *record) 5535 struct tep_record *record)
5534{ 5536{
5535 static const char *spaces = " "; /* 20 spaces */ 5537 static const char *spaces = " "; /* 20 spaces */
@@ -5548,7 +5550,7 @@ void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
5548void tep_print_event(struct tep_handle *pevent, struct trace_seq *s, 5550void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
5549 struct tep_record *record, bool use_trace_clock) 5551 struct tep_record *record, bool use_trace_clock)
5550{ 5552{
5551 struct event_format *event; 5553 struct tep_event_format *event;
5552 5554
5553 event = tep_find_event_by_record(pevent, record); 5555 event = tep_find_event_by_record(pevent, record);
5554 if (!event) { 5556 if (!event) {
@@ -5570,8 +5572,8 @@ void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
5570 5572
5571static int events_id_cmp(const void *a, const void *b) 5573static int events_id_cmp(const void *a, const void *b)
5572{ 5574{
5573 struct event_format * const * ea = a; 5575 struct tep_event_format * const * ea = a;
5574 struct event_format * const * eb = b; 5576 struct tep_event_format * const * eb = b;
5575 5577
5576 if ((*ea)->id < (*eb)->id) 5578 if ((*ea)->id < (*eb)->id)
5577 return -1; 5579 return -1;
@@ -5584,8 +5586,8 @@ static int events_id_cmp(const void *a, const void *b)
5584 5586
5585static int events_name_cmp(const void *a, const void *b) 5587static int events_name_cmp(const void *a, const void *b)
5586{ 5588{
5587 struct event_format * const * ea = a; 5589 struct tep_event_format * const * ea = a;
5588 struct event_format * const * eb = b; 5590 struct tep_event_format * const * eb = b;
5589 int res; 5591 int res;
5590 5592
5591 res = strcmp((*ea)->name, (*eb)->name); 5593 res = strcmp((*ea)->name, (*eb)->name);
@@ -5601,8 +5603,8 @@ static int events_name_cmp(const void *a, const void *b)
5601 5603
5602static int events_system_cmp(const void *a, const void *b) 5604static int events_system_cmp(const void *a, const void *b)
5603{ 5605{
5604 struct event_format * const * ea = a; 5606 struct tep_event_format * const * ea = a;
5605 struct event_format * const * eb = b; 5607 struct tep_event_format * const * eb = b;
5606 int res; 5608 int res;
5607 5609
5608 res = strcmp((*ea)->system, (*eb)->system); 5610 res = strcmp((*ea)->system, (*eb)->system);
@@ -5616,9 +5618,9 @@ static int events_system_cmp(const void *a, const void *b)
5616 return events_id_cmp(a, b); 5618 return events_id_cmp(a, b);
5617} 5619}
5618 5620
5619struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type sort_type) 5621struct tep_event_format **tep_list_events(struct tep_handle *pevent, enum tep_event_sort_type sort_type)
5620{ 5622{
5621 struct event_format **events; 5623 struct tep_event_format **events;
5622 int (*sort)(const void *a, const void *b); 5624 int (*sort)(const void *a, const void *b);
5623 5625
5624 events = pevent->sort_events; 5626 events = pevent->sort_events;
@@ -5637,20 +5639,20 @@ struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort
5637 pevent->sort_events = events; 5639 pevent->sort_events = events;
5638 5640
5639 /* the internal events are sorted by id */ 5641 /* the internal events are sorted by id */
5640 if (sort_type == EVENT_SORT_ID) { 5642 if (sort_type == TEP_EVENT_SORT_ID) {
5641 pevent->last_type = sort_type; 5643 pevent->last_type = sort_type;
5642 return events; 5644 return events;
5643 } 5645 }
5644 } 5646 }
5645 5647
5646 switch (sort_type) { 5648 switch (sort_type) {
5647 case EVENT_SORT_ID: 5649 case TEP_EVENT_SORT_ID:
5648 sort = events_id_cmp; 5650 sort = events_id_cmp;
5649 break; 5651 break;
5650 case EVENT_SORT_NAME: 5652 case TEP_EVENT_SORT_NAME:
5651 sort = events_name_cmp; 5653 sort = events_name_cmp;
5652 break; 5654 break;
5653 case EVENT_SORT_SYSTEM: 5655 case TEP_EVENT_SORT_SYSTEM:
5654 sort = events_system_cmp; 5656 sort = events_system_cmp;
5655 break; 5657 break;
5656 default: 5658 default:
@@ -5663,12 +5665,12 @@ struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort
5663 return events; 5665 return events;
5664} 5666}
5665 5667
5666static struct format_field ** 5668static struct tep_format_field **
5667get_event_fields(const char *type, const char *name, 5669get_event_fields(const char *type, const char *name,
5668 int count, struct format_field *list) 5670 int count, struct tep_format_field *list)
5669{ 5671{
5670 struct format_field **fields; 5672 struct tep_format_field **fields;
5671 struct format_field *field; 5673 struct tep_format_field *field;
5672 int i = 0; 5674 int i = 0;
5673 5675
5674 fields = malloc(sizeof(*fields) * (count + 1)); 5676 fields = malloc(sizeof(*fields) * (count + 1));
@@ -5701,7 +5703,7 @@ get_event_fields(const char *type, const char *name,
5701 * Returns an allocated array of fields. The last item in the array is NULL. 5703 * Returns an allocated array of fields. The last item in the array is NULL.
5702 * The array must be freed with free(). 5704 * The array must be freed with free().
5703 */ 5705 */
5704struct format_field **tep_event_common_fields(struct event_format *event) 5706struct tep_format_field **tep_event_common_fields(struct tep_event_format *event)
5705{ 5707{
5706 return get_event_fields("common", event->name, 5708 return get_event_fields("common", event->name,
5707 event->format.nr_common, 5709 event->format.nr_common,
@@ -5715,14 +5717,14 @@ struct format_field **tep_event_common_fields(struct event_format *event)
5715 * Returns an allocated array of fields. The last item in the array is NULL. 5717 * Returns an allocated array of fields. The last item in the array is NULL.
5716 * The array must be freed with free(). 5718 * The array must be freed with free().
5717 */ 5719 */
5718struct format_field **tep_event_fields(struct event_format *event) 5720struct tep_format_field **tep_event_fields(struct tep_event_format *event)
5719{ 5721{
5720 return get_event_fields("event", event->name, 5722 return get_event_fields("event", event->name,
5721 event->format.nr_fields, 5723 event->format.nr_fields,
5722 event->format.fields); 5724 event->format.fields);
5723} 5725}
5724 5726
5725static void print_fields(struct trace_seq *s, struct print_flag_sym *field) 5727static void print_fields(struct trace_seq *s, struct tep_print_flag_sym *field)
5726{ 5728{
5727 trace_seq_printf(s, "{ %s, %s }", field->value, field->str); 5729 trace_seq_printf(s, "{ %s, %s }", field->value, field->str);
5728 if (field->next) { 5730 if (field->next) {
@@ -5732,22 +5734,22 @@ static void print_fields(struct trace_seq *s, struct print_flag_sym *field)
5732} 5734}
5733 5735
5734/* for debugging */ 5736/* for debugging */
5735static void print_args(struct print_arg *args) 5737static void print_args(struct tep_print_arg *args)
5736{ 5738{
5737 int print_paren = 1; 5739 int print_paren = 1;
5738 struct trace_seq s; 5740 struct trace_seq s;
5739 5741
5740 switch (args->type) { 5742 switch (args->type) {
5741 case PRINT_NULL: 5743 case TEP_PRINT_NULL:
5742 printf("null"); 5744 printf("null");
5743 break; 5745 break;
5744 case PRINT_ATOM: 5746 case TEP_PRINT_ATOM:
5745 printf("%s", args->atom.atom); 5747 printf("%s", args->atom.atom);
5746 break; 5748 break;
5747 case PRINT_FIELD: 5749 case TEP_PRINT_FIELD:
5748 printf("REC->%s", args->field.name); 5750 printf("REC->%s", args->field.name);
5749 break; 5751 break;
5750 case PRINT_FLAGS: 5752 case TEP_PRINT_FLAGS:
5751 printf("__print_flags("); 5753 printf("__print_flags(");
5752 print_args(args->flags.field); 5754 print_args(args->flags.field);
5753 printf(", %s, ", args->flags.delim); 5755 printf(", %s, ", args->flags.delim);
@@ -5757,7 +5759,7 @@ static void print_args(struct print_arg *args)
5757 trace_seq_destroy(&s); 5759 trace_seq_destroy(&s);
5758 printf(")"); 5760 printf(")");
5759 break; 5761 break;
5760 case PRINT_SYMBOL: 5762 case TEP_PRINT_SYMBOL:
5761 printf("__print_symbolic("); 5763 printf("__print_symbolic(");
5762 print_args(args->symbol.field); 5764 print_args(args->symbol.field);
5763 printf(", "); 5765 printf(", ");
@@ -5767,21 +5769,21 @@ static void print_args(struct print_arg *args)
5767 trace_seq_destroy(&s); 5769 trace_seq_destroy(&s);
5768 printf(")"); 5770 printf(")");
5769 break; 5771 break;
5770 case PRINT_HEX: 5772 case TEP_PRINT_HEX:
5771 printf("__print_hex("); 5773 printf("__print_hex(");
5772 print_args(args->hex.field); 5774 print_args(args->hex.field);
5773 printf(", "); 5775 printf(", ");
5774 print_args(args->hex.size); 5776 print_args(args->hex.size);
5775 printf(")"); 5777 printf(")");
5776 break; 5778 break;
5777 case PRINT_HEX_STR: 5779 case TEP_PRINT_HEX_STR:
5778 printf("__print_hex_str("); 5780 printf("__print_hex_str(");
5779 print_args(args->hex.field); 5781 print_args(args->hex.field);
5780 printf(", "); 5782 printf(", ");
5781 print_args(args->hex.size); 5783 print_args(args->hex.size);
5782 printf(")"); 5784 printf(")");
5783 break; 5785 break;
5784 case PRINT_INT_ARRAY: 5786 case TEP_PRINT_INT_ARRAY:
5785 printf("__print_array("); 5787 printf("__print_array(");
5786 print_args(args->int_array.field); 5788 print_args(args->int_array.field);
5787 printf(", "); 5789 printf(", ");
@@ -5790,18 +5792,18 @@ static void print_args(struct print_arg *args)
5790 print_args(args->int_array.el_size); 5792 print_args(args->int_array.el_size);
5791 printf(")"); 5793 printf(")");
5792 break; 5794 break;
5793 case PRINT_STRING: 5795 case TEP_PRINT_STRING:
5794 case PRINT_BSTRING: 5796 case TEP_PRINT_BSTRING:
5795 printf("__get_str(%s)", args->string.string); 5797 printf("__get_str(%s)", args->string.string);
5796 break; 5798 break;
5797 case PRINT_BITMASK: 5799 case TEP_PRINT_BITMASK:
5798 printf("__get_bitmask(%s)", args->bitmask.bitmask); 5800 printf("__get_bitmask(%s)", args->bitmask.bitmask);
5799 break; 5801 break;
5800 case PRINT_TYPE: 5802 case TEP_PRINT_TYPE:
5801 printf("(%s)", args->typecast.type); 5803 printf("(%s)", args->typecast.type);
5802 print_args(args->typecast.item); 5804 print_args(args->typecast.item);
5803 break; 5805 break;
5804 case PRINT_OP: 5806 case TEP_PRINT_OP:
5805 if (strcmp(args->op.op, ":") == 0) 5807 if (strcmp(args->op.op, ":") == 0)
5806 print_paren = 0; 5808 print_paren = 0;
5807 if (print_paren) 5809 if (print_paren)
@@ -5833,13 +5835,13 @@ static void parse_header_field(const char *field,
5833 save_input_buf_ptr = input_buf_ptr; 5835 save_input_buf_ptr = input_buf_ptr;
5834 save_input_buf_siz = input_buf_siz; 5836 save_input_buf_siz = input_buf_siz;
5835 5837
5836 if (read_expected(EVENT_ITEM, "field") < 0) 5838 if (read_expected(TEP_EVENT_ITEM, "field") < 0)
5837 return; 5839 return;
5838 if (read_expected(EVENT_OP, ":") < 0) 5840 if (read_expected(TEP_EVENT_OP, ":") < 0)
5839 return; 5841 return;
5840 5842
5841 /* type */ 5843 /* type */
5842 if (read_expect_type(EVENT_ITEM, &token) < 0) 5844 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
5843 goto fail; 5845 goto fail;
5844 free_token(token); 5846 free_token(token);
5845 5847
@@ -5847,42 +5849,42 @@ static void parse_header_field(const char *field,
5847 * If this is not a mandatory field, then test it first. 5849 * If this is not a mandatory field, then test it first.
5848 */ 5850 */
5849 if (mandatory) { 5851 if (mandatory) {
5850 if (read_expected(EVENT_ITEM, field) < 0) 5852 if (read_expected(TEP_EVENT_ITEM, field) < 0)
5851 return; 5853 return;
5852 } else { 5854 } else {
5853 if (read_expect_type(EVENT_ITEM, &token) < 0) 5855 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
5854 goto fail; 5856 goto fail;
5855 if (strcmp(token, field) != 0) 5857 if (strcmp(token, field) != 0)
5856 goto discard; 5858 goto discard;
5857 free_token(token); 5859 free_token(token);
5858 } 5860 }
5859 5861
5860 if (read_expected(EVENT_OP, ";") < 0) 5862 if (read_expected(TEP_EVENT_OP, ";") < 0)
5861 return; 5863 return;
5862 if (read_expected(EVENT_ITEM, "offset") < 0) 5864 if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
5863 return; 5865 return;
5864 if (read_expected(EVENT_OP, ":") < 0) 5866 if (read_expected(TEP_EVENT_OP, ":") < 0)
5865 return; 5867 return;
5866 if (read_expect_type(EVENT_ITEM, &token) < 0) 5868 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
5867 goto fail; 5869 goto fail;
5868 *offset = atoi(token); 5870 *offset = atoi(token);
5869 free_token(token); 5871 free_token(token);
5870 if (read_expected(EVENT_OP, ";") < 0) 5872 if (read_expected(TEP_EVENT_OP, ";") < 0)
5871 return; 5873 return;
5872 if (read_expected(EVENT_ITEM, "size") < 0) 5874 if (read_expected(TEP_EVENT_ITEM, "size") < 0)
5873 return; 5875 return;
5874 if (read_expected(EVENT_OP, ":") < 0) 5876 if (read_expected(TEP_EVENT_OP, ":") < 0)
5875 return; 5877 return;
5876 if (read_expect_type(EVENT_ITEM, &token) < 0) 5878 if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
5877 goto fail; 5879 goto fail;
5878 *size = atoi(token); 5880 *size = atoi(token);
5879 free_token(token); 5881 free_token(token);
5880 if (read_expected(EVENT_OP, ";") < 0) 5882 if (read_expected(TEP_EVENT_OP, ";") < 0)
5881 return; 5883 return;
5882 type = read_token(&token); 5884 type = read_token(&token);
5883 if (type != EVENT_NEWLINE) { 5885 if (type != TEP_EVENT_NEWLINE) {
5884 /* newer versions of the kernel have a "signed" type */ 5886 /* newer versions of the kernel have a "signed" type */
5885 if (type != EVENT_ITEM) 5887 if (type != TEP_EVENT_ITEM)
5886 goto fail; 5888 goto fail;
5887 5889
5888 if (strcmp(token, "signed") != 0) 5890 if (strcmp(token, "signed") != 0)
@@ -5890,17 +5892,17 @@ static void parse_header_field(const char *field,
5890 5892
5891 free_token(token); 5893 free_token(token);
5892 5894
5893 if (read_expected(EVENT_OP, ":") < 0) 5895 if (read_expected(TEP_EVENT_OP, ":") < 0)
5894 return; 5896 return;
5895 5897
5896 if (read_expect_type(EVENT_ITEM, &token)) 5898 if (read_expect_type(TEP_EVENT_ITEM, &token))
5897 goto fail; 5899 goto fail;
5898 5900
5899 free_token(token); 5901 free_token(token);
5900 if (read_expected(EVENT_OP, ";") < 0) 5902 if (read_expected(TEP_EVENT_OP, ";") < 0)
5901 return; 5903 return;
5902 5904
5903 if (read_expect_type(EVENT_NEWLINE, &token)) 5905 if (read_expect_type(TEP_EVENT_NEWLINE, &token))
5904 goto fail; 5906 goto fail;
5905 } 5907 }
5906 fail: 5908 fail:
@@ -5957,7 +5959,7 @@ int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long si
5957 return 0; 5959 return 0;
5958} 5960}
5959 5961
5960static int event_matches(struct event_format *event, 5962static int event_matches(struct tep_event_format *event,
5961 int id, const char *sys_name, 5963 int id, const char *sys_name,
5962 const char *event_name) 5964 const char *event_name)
5963{ 5965{
@@ -5980,7 +5982,7 @@ static void free_handler(struct event_handler *handle)
5980 free(handle); 5982 free(handle);
5981} 5983}
5982 5984
5983static int find_event_handle(struct tep_handle *pevent, struct event_format *event) 5985static int find_event_handle(struct tep_handle *pevent, struct tep_event_format *event)
5984{ 5986{
5985 struct event_handler *handle, **next; 5987 struct event_handler *handle, **next;
5986 5988
@@ -6021,11 +6023,11 @@ static int find_event_handle(struct tep_handle *pevent, struct event_format *eve
6021 * 6023 *
6022 * /sys/kernel/debug/tracing/events/.../.../format 6024 * /sys/kernel/debug/tracing/events/.../.../format
6023 */ 6025 */
6024enum tep_errno __tep_parse_format(struct event_format **eventp, 6026enum tep_errno __tep_parse_format(struct tep_event_format **eventp,
6025 struct tep_handle *pevent, const char *buf, 6027 struct tep_handle *pevent, const char *buf,
6026 unsigned long size, const char *sys) 6028 unsigned long size, const char *sys)
6027{ 6029{
6028 struct event_format *event; 6030 struct tep_event_format *event;
6029 int ret; 6031 int ret;
6030 6032
6031 init_input_buf(buf, size); 6033 init_input_buf(buf, size);
@@ -6042,10 +6044,10 @@ enum tep_errno __tep_parse_format(struct event_format **eventp,
6042 } 6044 }
6043 6045
6044 if (strcmp(sys, "ftrace") == 0) { 6046 if (strcmp(sys, "ftrace") == 0) {
6045 event->flags |= EVENT_FL_ISFTRACE; 6047 event->flags |= TEP_EVENT_FL_ISFTRACE;
6046 6048
6047 if (strcmp(event->name, "bprint") == 0) 6049 if (strcmp(event->name, "bprint") == 0)
6048 event->flags |= EVENT_FL_ISBPRINT; 6050 event->flags |= TEP_EVENT_FL_ISBPRINT;
6049 } 6051 }
6050 6052
6051 event->id = event_read_id(); 6053 event->id = event_read_id();
@@ -6088,22 +6090,22 @@ enum tep_errno __tep_parse_format(struct event_format **eventp,
6088 goto event_parse_failed; 6090 goto event_parse_failed;
6089 } 6091 }
6090 6092
6091 if (!ret && (event->flags & EVENT_FL_ISFTRACE)) { 6093 if (!ret && (event->flags & TEP_EVENT_FL_ISFTRACE)) {
6092 struct format_field *field; 6094 struct tep_format_field *field;
6093 struct print_arg *arg, **list; 6095 struct tep_print_arg *arg, **list;
6094 6096
6095 /* old ftrace had no args */ 6097 /* old ftrace had no args */
6096 list = &event->print_fmt.args; 6098 list = &event->print_fmt.args;
6097 for (field = event->format.fields; field; field = field->next) { 6099 for (field = event->format.fields; field; field = field->next) {
6098 arg = alloc_arg(); 6100 arg = alloc_arg();
6099 if (!arg) { 6101 if (!arg) {
6100 event->flags |= EVENT_FL_FAILED; 6102 event->flags |= TEP_EVENT_FL_FAILED;
6101 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED; 6103 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
6102 } 6104 }
6103 arg->type = PRINT_FIELD; 6105 arg->type = TEP_PRINT_FIELD;
6104 arg->field.name = strdup(field->name); 6106 arg->field.name = strdup(field->name);
6105 if (!arg->field.name) { 6107 if (!arg->field.name) {
6106 event->flags |= EVENT_FL_FAILED; 6108 event->flags |= TEP_EVENT_FL_FAILED;
6107 free_arg(arg); 6109 free_arg(arg);
6108 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED; 6110 return TEP_ERRNO__OLD_FTRACE_ARG_FAILED;
6109 } 6111 }
@@ -6117,7 +6119,7 @@ enum tep_errno __tep_parse_format(struct event_format **eventp,
6117 return 0; 6119 return 0;
6118 6120
6119 event_parse_failed: 6121 event_parse_failed:
6120 event->flags |= EVENT_FL_FAILED; 6122 event->flags |= TEP_EVENT_FL_FAILED;
6121 return ret; 6123 return ret;
6122 6124
6123 event_alloc_failed: 6125 event_alloc_failed:
@@ -6130,12 +6132,12 @@ enum tep_errno __tep_parse_format(struct event_format **eventp,
6130 6132
6131static enum tep_errno 6133static enum tep_errno
6132__parse_event(struct tep_handle *pevent, 6134__parse_event(struct tep_handle *pevent,
6133 struct event_format **eventp, 6135 struct tep_event_format **eventp,
6134 const char *buf, unsigned long size, 6136 const char *buf, unsigned long size,
6135 const char *sys) 6137 const char *sys)
6136{ 6138{
6137 int ret = __tep_parse_format(eventp, pevent, buf, size, sys); 6139 int ret = __tep_parse_format(eventp, pevent, buf, size, sys);
6138 struct event_format *event = *eventp; 6140 struct tep_event_format *event = *eventp;
6139 6141
6140 if (event == NULL) 6142 if (event == NULL)
6141 return ret; 6143 return ret;
@@ -6172,7 +6174,7 @@ event_add_failed:
6172 * /sys/kernel/debug/tracing/events/.../.../format 6174 * /sys/kernel/debug/tracing/events/.../.../format
6173 */ 6175 */
6174enum tep_errno tep_parse_format(struct tep_handle *pevent, 6176enum tep_errno tep_parse_format(struct tep_handle *pevent,
6175 struct event_format **eventp, 6177 struct tep_event_format **eventp,
6176 const char *buf, 6178 const char *buf,
6177 unsigned long size, const char *sys) 6179 unsigned long size, const char *sys)
6178{ 6180{
@@ -6196,40 +6198,11 @@ enum tep_errno tep_parse_format(struct tep_handle *pevent,
6196enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf, 6198enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
6197 unsigned long size, const char *sys) 6199 unsigned long size, const char *sys)
6198{ 6200{
6199 struct event_format *event = NULL; 6201 struct tep_event_format *event = NULL;
6200 return __parse_event(pevent, &event, buf, size, sys); 6202 return __parse_event(pevent, &event, buf, size, sys);
6201} 6203}
6202 6204
6203#undef _PE 6205int get_field_val(struct trace_seq *s, struct tep_format_field *field,
6204#define _PE(code, str) str
6205static const char * const tep_error_str[] = {
6206 TEP_ERRORS
6207};
6208#undef _PE
6209
6210int tep_strerror(struct tep_handle *pevent __maybe_unused,
6211 enum tep_errno errnum, char *buf, size_t buflen)
6212{
6213 int idx;
6214 const char *msg;
6215
6216 if (errnum >= 0) {
6217 str_error_r(errnum, buf, buflen);
6218 return 0;
6219 }
6220
6221 if (errnum <= __TEP_ERRNO__START ||
6222 errnum >= __TEP_ERRNO__END)
6223 return -1;
6224
6225 idx = errnum - __TEP_ERRNO__START - 1;
6226 msg = tep_error_str[idx];
6227 snprintf(buf, buflen, "%s", msg);
6228
6229 return 0;
6230}
6231
6232int get_field_val(struct trace_seq *s, struct format_field *field,
6233 const char *name, struct tep_record *record, 6206 const char *name, struct tep_record *record,
6234 unsigned long long *val, int err) 6207 unsigned long long *val, int err)
6235{ 6208{
@@ -6262,11 +6235,11 @@ int get_field_val(struct trace_seq *s, struct format_field *field,
6262 * 6235 *
6263 * On failure, it returns NULL. 6236 * On failure, it returns NULL.
6264 */ 6237 */
6265void *tep_get_field_raw(struct trace_seq *s, struct event_format *event, 6238void *tep_get_field_raw(struct trace_seq *s, struct tep_event_format *event,
6266 const char *name, struct tep_record *record, 6239 const char *name, struct tep_record *record,
6267 int *len, int err) 6240 int *len, int err)
6268{ 6241{
6269 struct format_field *field; 6242 struct tep_format_field *field;
6270 void *data = record->data; 6243 void *data = record->data;
6271 unsigned offset; 6244 unsigned offset;
6272 int dummy; 6245 int dummy;
@@ -6287,7 +6260,7 @@ void *tep_get_field_raw(struct trace_seq *s, struct event_format *event,
6287 len = &dummy; 6260 len = &dummy;
6288 6261
6289 offset = field->offset; 6262 offset = field->offset;
6290 if (field->flags & FIELD_IS_DYNAMIC) { 6263 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
6291 offset = tep_read_number(event->pevent, 6264 offset = tep_read_number(event->pevent,
6292 data + offset, field->size); 6265 data + offset, field->size);
6293 *len = offset >> 16; 6266 *len = offset >> 16;
@@ -6309,11 +6282,11 @@ void *tep_get_field_raw(struct trace_seq *s, struct event_format *event,
6309 * 6282 *
6310 * Returns 0 on success -1 on field not found. 6283 * Returns 0 on success -1 on field not found.
6311 */ 6284 */
6312int tep_get_field_val(struct trace_seq *s, struct event_format *event, 6285int tep_get_field_val(struct trace_seq *s, struct tep_event_format *event,
6313 const char *name, struct tep_record *record, 6286 const char *name, struct tep_record *record,
6314 unsigned long long *val, int err) 6287 unsigned long long *val, int err)
6315{ 6288{
6316 struct format_field *field; 6289 struct tep_format_field *field;
6317 6290
6318 if (!event) 6291 if (!event)
6319 return -1; 6292 return -1;
@@ -6334,11 +6307,11 @@ int tep_get_field_val(struct trace_seq *s, struct event_format *event,
6334 * 6307 *
6335 * Returns 0 on success -1 on field not found. 6308 * Returns 0 on success -1 on field not found.
6336 */ 6309 */
6337int tep_get_common_field_val(struct trace_seq *s, struct event_format *event, 6310int tep_get_common_field_val(struct trace_seq *s, struct tep_event_format *event,
6338 const char *name, struct tep_record *record, 6311 const char *name, struct tep_record *record,
6339 unsigned long long *val, int err) 6312 unsigned long long *val, int err)
6340{ 6313{
6341 struct format_field *field; 6314 struct tep_format_field *field;
6342 6315
6343 if (!event) 6316 if (!event)
6344 return -1; 6317 return -1;
@@ -6359,11 +6332,11 @@ int tep_get_common_field_val(struct trace_seq *s, struct event_format *event,
6359 * 6332 *
6360 * Returns 0 on success -1 on field not found. 6333 * Returns 0 on success -1 on field not found.
6361 */ 6334 */
6362int tep_get_any_field_val(struct trace_seq *s, struct event_format *event, 6335int tep_get_any_field_val(struct trace_seq *s, struct tep_event_format *event,
6363 const char *name, struct tep_record *record, 6336 const char *name, struct tep_record *record,
6364 unsigned long long *val, int err) 6337 unsigned long long *val, int err)
6365{ 6338{
6366 struct format_field *field; 6339 struct tep_format_field *field;
6367 6340
6368 if (!event) 6341 if (!event)
6369 return -1; 6342 return -1;
@@ -6385,10 +6358,10 @@ int tep_get_any_field_val(struct trace_seq *s, struct event_format *event,
6385 * Returns: 0 on success, -1 field not found, or 1 if buffer is full. 6358 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
6386 */ 6359 */
6387int tep_print_num_field(struct trace_seq *s, const char *fmt, 6360int tep_print_num_field(struct trace_seq *s, const char *fmt,
6388 struct event_format *event, const char *name, 6361 struct tep_event_format *event, const char *name,
6389 struct tep_record *record, int err) 6362 struct tep_record *record, int err)
6390{ 6363{
6391 struct format_field *field = tep_find_field(event, name); 6364 struct tep_format_field *field = tep_find_field(event, name);
6392 unsigned long long val; 6365 unsigned long long val;
6393 6366
6394 if (!field) 6367 if (!field)
@@ -6417,10 +6390,10 @@ int tep_print_num_field(struct trace_seq *s, const char *fmt,
6417 * Returns: 0 on success, -1 field not found, or 1 if buffer is full. 6390 * Returns: 0 on success, -1 field not found, or 1 if buffer is full.
6418 */ 6391 */
6419int tep_print_func_field(struct trace_seq *s, const char *fmt, 6392int tep_print_func_field(struct trace_seq *s, const char *fmt,
6420 struct event_format *event, const char *name, 6393 struct tep_event_format *event, const char *name,
6421 struct tep_record *record, int err) 6394 struct tep_record *record, int err)
6422{ 6395{
6423 struct format_field *field = tep_find_field(event, name); 6396 struct tep_format_field *field = tep_find_field(event, name);
6424 struct tep_handle *pevent = event->pevent; 6397 struct tep_handle *pevent = event->pevent;
6425 unsigned long long val; 6398 unsigned long long val;
6426 struct func_map *func; 6399 struct func_map *func;
@@ -6577,11 +6550,11 @@ int tep_unregister_print_function(struct tep_handle *pevent,
6577 return -1; 6550 return -1;
6578} 6551}
6579 6552
6580static struct event_format *search_event(struct tep_handle *pevent, int id, 6553static struct tep_event_format *search_event(struct tep_handle *pevent, int id,
6581 const char *sys_name, 6554 const char *sys_name,
6582 const char *event_name) 6555 const char *event_name)
6583{ 6556{
6584 struct event_format *event; 6557 struct tep_event_format *event;
6585 6558
6586 if (id >= 0) { 6559 if (id >= 0) {
6587 /* search by id */ 6560 /* search by id */
@@ -6621,7 +6594,7 @@ int tep_register_event_handler(struct tep_handle *pevent, int id,
6621 const char *sys_name, const char *event_name, 6594 const char *sys_name, const char *event_name,
6622 tep_event_handler_func func, void *context) 6595 tep_event_handler_func func, void *context)
6623{ 6596{
6624 struct event_format *event; 6597 struct tep_event_format *event;
6625 struct event_handler *handle; 6598 struct event_handler *handle;
6626 6599
6627 event = search_event(pevent, id, sys_name, event_name); 6600 event = search_event(pevent, id, sys_name, event_name);
@@ -6705,7 +6678,7 @@ int tep_unregister_event_handler(struct tep_handle *pevent, int id,
6705 const char *sys_name, const char *event_name, 6678 const char *sys_name, const char *event_name,
6706 tep_event_handler_func func, void *context) 6679 tep_event_handler_func func, void *context)
6707{ 6680{
6708 struct event_format *event; 6681 struct tep_event_format *event;
6709 struct event_handler *handle; 6682 struct event_handler *handle;
6710 struct event_handler **next; 6683 struct event_handler **next;
6711 6684
@@ -6757,7 +6730,7 @@ void tep_ref(struct tep_handle *pevent)
6757 pevent->ref_count++; 6730 pevent->ref_count++;
6758} 6731}
6759 6732
6760void tep_free_format_field(struct format_field *field) 6733void tep_free_format_field(struct tep_format_field *field)
6761{ 6734{
6762 free(field->type); 6735 free(field->type);
6763 if (field->alias != field->name) 6736 if (field->alias != field->name)
@@ -6766,9 +6739,9 @@ void tep_free_format_field(struct format_field *field)
6766 free(field); 6739 free(field);
6767} 6740}
6768 6741
6769static void free_format_fields(struct format_field *field) 6742static void free_format_fields(struct tep_format_field *field)
6770{ 6743{
6771 struct format_field *next; 6744 struct tep_format_field *next;
6772 6745
6773 while (field) { 6746 while (field) {
6774 next = field->next; 6747 next = field->next;
@@ -6777,13 +6750,13 @@ static void free_format_fields(struct format_field *field)
6777 } 6750 }
6778} 6751}
6779 6752
6780static void free_formats(struct format *format) 6753static void free_formats(struct tep_format *format)
6781{ 6754{
6782 free_format_fields(format->common_fields); 6755 free_format_fields(format->common_fields);
6783 free_format_fields(format->fields); 6756 free_format_fields(format->fields);
6784} 6757}
6785 6758
6786void tep_free_format(struct event_format *event) 6759void tep_free_format(struct tep_event_format *event)
6787{ 6760{
6788 free(event->name); 6761 free(event->name);
6789 free(event->system); 6762 free(event->system);
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 44b7c2d41f9f..16bf4c890b6f 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -26,17 +26,12 @@
26#include <regex.h> 26#include <regex.h>
27#include <string.h> 27#include <string.h>
28 28
29#include "trace-seq.h"
30
29#ifndef __maybe_unused 31#ifndef __maybe_unused
30#define __maybe_unused __attribute__((unused)) 32#define __maybe_unused __attribute__((unused))
31#endif 33#endif
32 34
33/* ----------------------- trace_seq ----------------------- */
34
35
36#ifndef TRACE_SEQ_BUF_SIZE
37#define TRACE_SEQ_BUF_SIZE 4096
38#endif
39
40#ifndef DEBUG_RECORD 35#ifndef DEBUG_RECORD
41#define DEBUG_RECORD 0 36#define DEBUG_RECORD 0
42#endif 37#endif
@@ -59,51 +54,14 @@ struct tep_record {
59#endif 54#endif
60}; 55};
61 56
62enum trace_seq_fail { 57/* ----------------------- tep ----------------------- */
63 TRACE_SEQ__GOOD,
64 TRACE_SEQ__BUFFER_POISONED,
65 TRACE_SEQ__MEM_ALLOC_FAILED,
66};
67
68/*
69 * Trace sequences are used to allow a function to call several other functions
70 * to create a string of data to use (up to a max of PAGE_SIZE).
71 */
72
73struct trace_seq {
74 char *buffer;
75 unsigned int buffer_size;
76 unsigned int len;
77 unsigned int readpos;
78 enum trace_seq_fail state;
79};
80
81void trace_seq_init(struct trace_seq *s);
82void trace_seq_reset(struct trace_seq *s);
83void trace_seq_destroy(struct trace_seq *s);
84
85extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
86 __attribute__ ((format (printf, 2, 3)));
87extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
88 __attribute__ ((format (printf, 2, 0)));
89
90extern int trace_seq_puts(struct trace_seq *s, const char *str);
91extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
92
93extern void trace_seq_terminate(struct trace_seq *s);
94
95extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
96extern int trace_seq_do_printf(struct trace_seq *s);
97
98
99/* ----------------------- pevent ----------------------- */
100 58
101struct tep_handle; 59struct tep_handle;
102struct event_format; 60struct tep_event_format;
103 61
104typedef int (*tep_event_handler_func)(struct trace_seq *s, 62typedef int (*tep_event_handler_func)(struct trace_seq *s,
105 struct tep_record *record, 63 struct tep_record *record,
106 struct event_format *event, 64 struct tep_event_format *event,
107 void *context); 65 void *context);
108 66
109typedef int (*tep_plugin_load_func)(struct tep_handle *pevent); 67typedef int (*tep_plugin_load_func)(struct tep_handle *pevent);
@@ -172,20 +130,20 @@ struct tep_plugin_option {
172#define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS) 130#define TEP_PLUGIN_OPTIONS_NAME MAKE_STR(TEP_PLUGIN_OPTIONS)
173#define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS) 131#define TEP_PLUGIN_ALIAS_NAME MAKE_STR(TEP_PLUGIN_ALIAS)
174 132
175enum format_flags { 133enum tep_format_flags {
176 FIELD_IS_ARRAY = 1, 134 TEP_FIELD_IS_ARRAY = 1,
177 FIELD_IS_POINTER = 2, 135 TEP_FIELD_IS_POINTER = 2,
178 FIELD_IS_SIGNED = 4, 136 TEP_FIELD_IS_SIGNED = 4,
179 FIELD_IS_STRING = 8, 137 TEP_FIELD_IS_STRING = 8,
180 FIELD_IS_DYNAMIC = 16, 138 TEP_FIELD_IS_DYNAMIC = 16,
181 FIELD_IS_LONG = 32, 139 TEP_FIELD_IS_LONG = 32,
182 FIELD_IS_FLAG = 64, 140 TEP_FIELD_IS_FLAG = 64,
183 FIELD_IS_SYMBOLIC = 128, 141 TEP_FIELD_IS_SYMBOLIC = 128,
184}; 142};
185 143
186struct format_field { 144struct tep_format_field {
187 struct format_field *next; 145 struct tep_format_field *next;
188 struct event_format *event; 146 struct tep_event_format *event;
189 char *type; 147 char *type;
190 char *name; 148 char *name;
191 char *alias; 149 char *alias;
@@ -196,169 +154,169 @@ struct format_field {
196 unsigned long flags; 154 unsigned long flags;
197}; 155};
198 156
199struct format { 157struct tep_format {
200 int nr_common; 158 int nr_common;
201 int nr_fields; 159 int nr_fields;
202 struct format_field *common_fields; 160 struct tep_format_field *common_fields;
203 struct format_field *fields; 161 struct tep_format_field *fields;
204}; 162};
205 163
206struct print_arg_atom { 164struct tep_print_arg_atom {
207 char *atom; 165 char *atom;
208}; 166};
209 167
210struct print_arg_string { 168struct tep_print_arg_string {
211 char *string; 169 char *string;
212 int offset; 170 int offset;
213}; 171};
214 172
215struct print_arg_bitmask { 173struct tep_print_arg_bitmask {
216 char *bitmask; 174 char *bitmask;
217 int offset; 175 int offset;
218}; 176};
219 177
220struct print_arg_field { 178struct tep_print_arg_field {
221 char *name; 179 char *name;
222 struct format_field *field; 180 struct tep_format_field *field;
223}; 181};
224 182
225struct print_flag_sym { 183struct tep_print_flag_sym {
226 struct print_flag_sym *next; 184 struct tep_print_flag_sym *next;
227 char *value; 185 char *value;
228 char *str; 186 char *str;
229}; 187};
230 188
231struct print_arg_typecast { 189struct tep_print_arg_typecast {
232 char *type; 190 char *type;
233 struct print_arg *item; 191 struct tep_print_arg *item;
234}; 192};
235 193
236struct print_arg_flags { 194struct tep_print_arg_flags {
237 struct print_arg *field; 195 struct tep_print_arg *field;
238 char *delim; 196 char *delim;
239 struct print_flag_sym *flags; 197 struct tep_print_flag_sym *flags;
240}; 198};
241 199
242struct print_arg_symbol { 200struct tep_print_arg_symbol {
243 struct print_arg *field; 201 struct tep_print_arg *field;
244 struct print_flag_sym *symbols; 202 struct tep_print_flag_sym *symbols;
245}; 203};
246 204
247struct print_arg_hex { 205struct tep_print_arg_hex {
248 struct print_arg *field; 206 struct tep_print_arg *field;
249 struct print_arg *size; 207 struct tep_print_arg *size;
250}; 208};
251 209
252struct print_arg_int_array { 210struct tep_print_arg_int_array {
253 struct print_arg *field; 211 struct tep_print_arg *field;
254 struct print_arg *count; 212 struct tep_print_arg *count;
255 struct print_arg *el_size; 213 struct tep_print_arg *el_size;
256}; 214};
257 215
258struct print_arg_dynarray { 216struct tep_print_arg_dynarray {
259 struct format_field *field; 217 struct tep_format_field *field;
260 struct print_arg *index; 218 struct tep_print_arg *index;
261}; 219};
262 220
263struct print_arg; 221struct tep_print_arg;
264 222
265struct print_arg_op { 223struct tep_print_arg_op {
266 char *op; 224 char *op;
267 int prio; 225 int prio;
268 struct print_arg *left; 226 struct tep_print_arg *left;
269 struct print_arg *right; 227 struct tep_print_arg *right;
270}; 228};
271 229
272struct tep_function_handler; 230struct tep_function_handler;
273 231
274struct print_arg_func { 232struct tep_print_arg_func {
275 struct tep_function_handler *func; 233 struct tep_function_handler *func;
276 struct print_arg *args; 234 struct tep_print_arg *args;
277}; 235};
278 236
279enum print_arg_type { 237enum tep_print_arg_type {
280 PRINT_NULL, 238 TEP_PRINT_NULL,
281 PRINT_ATOM, 239 TEP_PRINT_ATOM,
282 PRINT_FIELD, 240 TEP_PRINT_FIELD,
283 PRINT_FLAGS, 241 TEP_PRINT_FLAGS,
284 PRINT_SYMBOL, 242 TEP_PRINT_SYMBOL,
285 PRINT_HEX, 243 TEP_PRINT_HEX,
286 PRINT_INT_ARRAY, 244 TEP_PRINT_INT_ARRAY,
287 PRINT_TYPE, 245 TEP_PRINT_TYPE,
288 PRINT_STRING, 246 TEP_PRINT_STRING,
289 PRINT_BSTRING, 247 TEP_PRINT_BSTRING,
290 PRINT_DYNAMIC_ARRAY, 248 TEP_PRINT_DYNAMIC_ARRAY,
291 PRINT_OP, 249 TEP_PRINT_OP,
292 PRINT_FUNC, 250 TEP_PRINT_FUNC,
293 PRINT_BITMASK, 251 TEP_PRINT_BITMASK,
294 PRINT_DYNAMIC_ARRAY_LEN, 252 TEP_PRINT_DYNAMIC_ARRAY_LEN,
295 PRINT_HEX_STR, 253 TEP_PRINT_HEX_STR,
296}; 254};
297 255
298struct print_arg { 256struct tep_print_arg {
299 struct print_arg *next; 257 struct tep_print_arg *next;
300 enum print_arg_type type; 258 enum tep_print_arg_type type;
301 union { 259 union {
302 struct print_arg_atom atom; 260 struct tep_print_arg_atom atom;
303 struct print_arg_field field; 261 struct tep_print_arg_field field;
304 struct print_arg_typecast typecast; 262 struct tep_print_arg_typecast typecast;
305 struct print_arg_flags flags; 263 struct tep_print_arg_flags flags;
306 struct print_arg_symbol symbol; 264 struct tep_print_arg_symbol symbol;
307 struct print_arg_hex hex; 265 struct tep_print_arg_hex hex;
308 struct print_arg_int_array int_array; 266 struct tep_print_arg_int_array int_array;
309 struct print_arg_func func; 267 struct tep_print_arg_func func;
310 struct print_arg_string string; 268 struct tep_print_arg_string string;
311 struct print_arg_bitmask bitmask; 269 struct tep_print_arg_bitmask bitmask;
312 struct print_arg_op op; 270 struct tep_print_arg_op op;
313 struct print_arg_dynarray dynarray; 271 struct tep_print_arg_dynarray dynarray;
314 }; 272 };
315}; 273};
316 274
317struct print_fmt { 275struct tep_print_fmt {
318 char *format; 276 char *format;
319 struct print_arg *args; 277 struct tep_print_arg *args;
320}; 278};
321 279
322struct event_format { 280struct tep_event_format {
323 struct tep_handle *pevent; 281 struct tep_handle *pevent;
324 char *name; 282 char *name;
325 int id; 283 int id;
326 int flags; 284 int flags;
327 struct format format; 285 struct tep_format format;
328 struct print_fmt print_fmt; 286 struct tep_print_fmt print_fmt;
329 char *system; 287 char *system;
330 tep_event_handler_func handler; 288 tep_event_handler_func handler;
331 void *context; 289 void *context;
332}; 290};
333 291
334enum { 292enum {
335 EVENT_FL_ISFTRACE = 0x01, 293 TEP_EVENT_FL_ISFTRACE = 0x01,
336 EVENT_FL_ISPRINT = 0x02, 294 TEP_EVENT_FL_ISPRINT = 0x02,
337 EVENT_FL_ISBPRINT = 0x04, 295 TEP_EVENT_FL_ISBPRINT = 0x04,
338 EVENT_FL_ISFUNCENT = 0x10, 296 TEP_EVENT_FL_ISFUNCENT = 0x10,
339 EVENT_FL_ISFUNCRET = 0x20, 297 TEP_EVENT_FL_ISFUNCRET = 0x20,
340 EVENT_FL_NOHANDLE = 0x40, 298 TEP_EVENT_FL_NOHANDLE = 0x40,
341 EVENT_FL_PRINTRAW = 0x80, 299 TEP_EVENT_FL_PRINTRAW = 0x80,
342 300
343 EVENT_FL_FAILED = 0x80000000 301 TEP_EVENT_FL_FAILED = 0x80000000
344}; 302};
345 303
346enum event_sort_type { 304enum tep_event_sort_type {
347 EVENT_SORT_ID, 305 TEP_EVENT_SORT_ID,
348 EVENT_SORT_NAME, 306 TEP_EVENT_SORT_NAME,
349 EVENT_SORT_SYSTEM, 307 TEP_EVENT_SORT_SYSTEM,
350}; 308};
351 309
352enum event_type { 310enum tep_event_type {
353 EVENT_ERROR, 311 TEP_EVENT_ERROR,
354 EVENT_NONE, 312 TEP_EVENT_NONE,
355 EVENT_SPACE, 313 TEP_EVENT_SPACE,
356 EVENT_NEWLINE, 314 TEP_EVENT_NEWLINE,
357 EVENT_OP, 315 TEP_EVENT_OP,
358 EVENT_DELIM, 316 TEP_EVENT_DELIM,
359 EVENT_ITEM, 317 TEP_EVENT_ITEM,
360 EVENT_DQUOTE, 318 TEP_EVENT_DQUOTE,
361 EVENT_SQUOTE, 319 TEP_EVENT_SQUOTE,
362}; 320};
363 321
364typedef unsigned long long (*tep_func_handler)(struct trace_seq *s, 322typedef unsigned long long (*tep_func_handler)(struct trace_seq *s,
@@ -431,12 +389,12 @@ enum tep_errno {
431}; 389};
432#undef _PE 390#undef _PE
433 391
434struct plugin_list; 392struct tep_plugin_list;
435 393
436#define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1)) 394#define INVALID_PLUGIN_LIST_OPTION ((char **)((unsigned long)-1))
437 395
438struct plugin_list *tep_load_plugins(struct tep_handle *pevent); 396struct tep_plugin_list *tep_load_plugins(struct tep_handle *pevent);
439void tep_unload_plugins(struct plugin_list *plugin_list, 397void tep_unload_plugins(struct tep_plugin_list *plugin_list,
440 struct tep_handle *pevent); 398 struct tep_handle *pevent);
441char **tep_plugin_list_options(void); 399char **tep_plugin_list_options(void);
442void tep_plugin_free_options_list(char **list); 400void tep_plugin_free_options_list(char **list);
@@ -445,156 +403,25 @@ int tep_plugin_add_options(const char *name,
445void tep_plugin_remove_options(struct tep_plugin_option *options); 403void tep_plugin_remove_options(struct tep_plugin_option *options);
446void tep_print_plugins(struct trace_seq *s, 404void tep_print_plugins(struct trace_seq *s,
447 const char *prefix, const char *suffix, 405 const char *prefix, const char *suffix,
448 const struct plugin_list *list); 406 const struct tep_plugin_list *list);
449
450struct cmdline;
451struct cmdline_list;
452struct func_map;
453struct func_list;
454struct event_handler;
455struct func_resolver;
456 407
408/* tep_handle */
457typedef char *(tep_func_resolver_t)(void *priv, 409typedef char *(tep_func_resolver_t)(void *priv,
458 unsigned long long *addrp, char **modp); 410 unsigned long long *addrp, char **modp);
411void tep_set_flag(struct tep_handle *tep, int flag);
412unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data);
413unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data);
414unsigned long long
415__tep_data2host8(struct tep_handle *pevent, unsigned long long data);
459 416
460struct tep_handle { 417#define tep_data2host2(pevent, ptr) __tep_data2host2(pevent, *(unsigned short *)(ptr))
461 int ref_count; 418#define tep_data2host4(pevent, ptr) __tep_data2host4(pevent, *(unsigned int *)(ptr))
462 419#define tep_data2host8(pevent, ptr) \
463 int header_page_ts_offset;
464 int header_page_ts_size;
465 int header_page_size_offset;
466 int header_page_size_size;
467 int header_page_data_offset;
468 int header_page_data_size;
469 int header_page_overwrite;
470
471 int file_bigendian;
472 int host_bigendian;
473
474 int latency_format;
475
476 int old_format;
477
478 int cpus;
479 int long_size;
480 int page_size;
481
482 struct cmdline *cmdlines;
483 struct cmdline_list *cmdlist;
484 int cmdline_count;
485
486 struct func_map *func_map;
487 struct func_resolver *func_resolver;
488 struct func_list *funclist;
489 unsigned int func_count;
490
491 struct printk_map *printk_map;
492 struct printk_list *printklist;
493 unsigned int printk_count;
494
495
496 struct event_format **events;
497 int nr_events;
498 struct event_format **sort_events;
499 enum event_sort_type last_type;
500
501 int type_offset;
502 int type_size;
503
504 int pid_offset;
505 int pid_size;
506
507 int pc_offset;
508 int pc_size;
509
510 int flags_offset;
511 int flags_size;
512
513 int ld_offset;
514 int ld_size;
515
516 int print_raw;
517
518 int test_filters;
519
520 int flags;
521
522 struct format_field *bprint_ip_field;
523 struct format_field *bprint_fmt_field;
524 struct format_field *bprint_buf_field;
525
526 struct event_handler *handlers;
527 struct tep_function_handler *func_handlers;
528
529 /* cache */
530 struct event_format *last_event;
531
532 char *trace_clock;
533};
534
535static inline void tep_set_flag(struct tep_handle *pevent, int flag)
536{
537 pevent->flags |= flag;
538}
539
540static inline unsigned short
541__data2host2(struct tep_handle *pevent, unsigned short data)
542{
543 unsigned short swap;
544
545 if (pevent->host_bigendian == pevent->file_bigendian)
546 return data;
547
548 swap = ((data & 0xffULL) << 8) |
549 ((data & (0xffULL << 8)) >> 8);
550
551 return swap;
552}
553
554static inline unsigned int
555__data2host4(struct tep_handle *pevent, unsigned int data)
556{
557 unsigned int swap;
558
559 if (pevent->host_bigendian == pevent->file_bigendian)
560 return data;
561
562 swap = ((data & 0xffULL) << 24) |
563 ((data & (0xffULL << 8)) << 8) |
564 ((data & (0xffULL << 16)) >> 8) |
565 ((data & (0xffULL << 24)) >> 24);
566
567 return swap;
568}
569
570static inline unsigned long long
571__data2host8(struct tep_handle *pevent, unsigned long long data)
572{
573 unsigned long long swap;
574
575 if (pevent->host_bigendian == pevent->file_bigendian)
576 return data;
577
578 swap = ((data & 0xffULL) << 56) |
579 ((data & (0xffULL << 8)) << 40) |
580 ((data & (0xffULL << 16)) << 24) |
581 ((data & (0xffULL << 24)) << 8) |
582 ((data & (0xffULL << 32)) >> 8) |
583 ((data & (0xffULL << 40)) >> 24) |
584 ((data & (0xffULL << 48)) >> 40) |
585 ((data & (0xffULL << 56)) >> 56);
586
587 return swap;
588}
589
590#define data2host2(pevent, ptr) __data2host2(pevent, *(unsigned short *)(ptr))
591#define data2host4(pevent, ptr) __data2host4(pevent, *(unsigned int *)(ptr))
592#define data2host8(pevent, ptr) \
593({ \ 420({ \
594 unsigned long long __val; \ 421 unsigned long long __val; \
595 \ 422 \
596 memcpy(&__val, (ptr), sizeof(unsigned long long)); \ 423 memcpy(&__val, (ptr), sizeof(unsigned long long)); \
597 __data2host8(pevent, __val); \ 424 __tep_data2host8(pevent, __val); \
598}) 425})
599 426
600static inline int tep_host_bigendian(void) 427static inline int tep_host_bigendian(void)
@@ -627,14 +454,14 @@ int tep_register_print_string(struct tep_handle *pevent, const char *fmt,
627int tep_pid_is_registered(struct tep_handle *pevent, int pid); 454int tep_pid_is_registered(struct tep_handle *pevent, int pid);
628 455
629void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s, 456void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
630 struct event_format *event, 457 struct tep_event_format *event,
631 struct tep_record *record); 458 struct tep_record *record);
632void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s, 459void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
633 struct event_format *event, 460 struct tep_event_format *event,
634 struct tep_record *record, 461 struct tep_record *record,
635 bool use_trace_clock); 462 bool use_trace_clock);
636void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s, 463void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
637 struct event_format *event, 464 struct tep_event_format *event,
638 struct tep_record *record); 465 struct tep_record *record);
639void tep_print_event(struct tep_handle *pevent, struct trace_seq *s, 466void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
640 struct tep_record *record, bool use_trace_clock); 467 struct tep_record *record, bool use_trace_clock);
@@ -645,32 +472,32 @@ int tep_parse_header_page(struct tep_handle *pevent, char *buf, unsigned long si
645enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf, 472enum tep_errno tep_parse_event(struct tep_handle *pevent, const char *buf,
646 unsigned long size, const char *sys); 473 unsigned long size, const char *sys);
647enum tep_errno tep_parse_format(struct tep_handle *pevent, 474enum tep_errno tep_parse_format(struct tep_handle *pevent,
648 struct event_format **eventp, 475 struct tep_event_format **eventp,
649 const char *buf, 476 const char *buf,
650 unsigned long size, const char *sys); 477 unsigned long size, const char *sys);
651void tep_free_format(struct event_format *event); 478void tep_free_format(struct tep_event_format *event);
652void tep_free_format_field(struct format_field *field); 479void tep_free_format_field(struct tep_format_field *field);
653 480
654void *tep_get_field_raw(struct trace_seq *s, struct event_format *event, 481void *tep_get_field_raw(struct trace_seq *s, struct tep_event_format *event,
655 const char *name, struct tep_record *record, 482 const char *name, struct tep_record *record,
656 int *len, int err); 483 int *len, int err);
657 484
658int tep_get_field_val(struct trace_seq *s, struct event_format *event, 485int tep_get_field_val(struct trace_seq *s, struct tep_event_format *event,
659 const char *name, struct tep_record *record, 486 const char *name, struct tep_record *record,
660 unsigned long long *val, int err); 487 unsigned long long *val, int err);
661int tep_get_common_field_val(struct trace_seq *s, struct event_format *event, 488int tep_get_common_field_val(struct trace_seq *s, struct tep_event_format *event,
662 const char *name, struct tep_record *record, 489 const char *name, struct tep_record *record,
663 unsigned long long *val, int err); 490 unsigned long long *val, int err);
664int tep_get_any_field_val(struct trace_seq *s, struct event_format *event, 491int tep_get_any_field_val(struct trace_seq *s, struct tep_event_format *event,
665 const char *name, struct tep_record *record, 492 const char *name, struct tep_record *record,
666 unsigned long long *val, int err); 493 unsigned long long *val, int err);
667 494
668int tep_print_num_field(struct trace_seq *s, const char *fmt, 495int tep_print_num_field(struct trace_seq *s, const char *fmt,
669 struct event_format *event, const char *name, 496 struct tep_event_format *event, const char *name,
670 struct tep_record *record, int err); 497 struct tep_record *record, int err);
671 498
672int tep_print_func_field(struct trace_seq *s, const char *fmt, 499int tep_print_func_field(struct trace_seq *s, const char *fmt,
673 struct event_format *event, const char *name, 500 struct tep_event_format *event, const char *name,
674 struct tep_record *record, int err); 501 struct tep_record *record, int err);
675 502
676int tep_register_event_handler(struct tep_handle *pevent, int id, 503int tep_register_event_handler(struct tep_handle *pevent, int id,
@@ -686,29 +513,30 @@ int tep_register_print_function(struct tep_handle *pevent,
686int tep_unregister_print_function(struct tep_handle *pevent, 513int tep_unregister_print_function(struct tep_handle *pevent,
687 tep_func_handler func, char *name); 514 tep_func_handler func, char *name);
688 515
689struct format_field *tep_find_common_field(struct event_format *event, const char *name); 516struct tep_format_field *tep_find_common_field(struct tep_event_format *event, const char *name);
690struct format_field *tep_find_field(struct event_format *event, const char *name); 517struct tep_format_field *tep_find_field(struct tep_event_format *event, const char *name);
691struct format_field *tep_find_any_field(struct event_format *event, const char *name); 518struct tep_format_field *tep_find_any_field(struct tep_event_format *event, const char *name);
692 519
693const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr); 520const char *tep_find_function(struct tep_handle *pevent, unsigned long long addr);
694unsigned long long 521unsigned long long
695tep_find_function_address(struct tep_handle *pevent, unsigned long long addr); 522tep_find_function_address(struct tep_handle *pevent, unsigned long long addr);
696unsigned long long tep_read_number(struct tep_handle *pevent, const void *ptr, int size); 523unsigned long long tep_read_number(struct tep_handle *pevent, const void *ptr, int size);
697int tep_read_number_field(struct format_field *field, const void *data, 524int tep_read_number_field(struct tep_format_field *field, const void *data,
698 unsigned long long *value); 525 unsigned long long *value);
699 526
700struct event_format *tep_find_event(struct tep_handle *pevent, int id); 527struct tep_event_format *tep_get_first_event(struct tep_handle *tep);
528int tep_get_events_count(struct tep_handle *tep);
529struct tep_event_format *tep_find_event(struct tep_handle *pevent, int id);
701 530
702struct event_format * 531struct tep_event_format *
703tep_find_event_by_name(struct tep_handle *pevent, const char *sys, const char *name); 532tep_find_event_by_name(struct tep_handle *pevent, const char *sys, const char *name);
704 533struct tep_event_format *
705struct event_format *
706tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record); 534tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record);
707 535
708void tep_data_lat_fmt(struct tep_handle *pevent, 536void tep_data_lat_fmt(struct tep_handle *pevent,
709 struct trace_seq *s, struct tep_record *record); 537 struct trace_seq *s, struct tep_record *record);
710int tep_data_type(struct tep_handle *pevent, struct tep_record *rec); 538int tep_data_type(struct tep_handle *pevent, struct tep_record *rec);
711struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type); 539struct tep_event_format *tep_data_event_from_type(struct tep_handle *pevent, int type);
712int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec); 540int tep_data_pid(struct tep_handle *pevent, struct tep_record *rec);
713int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec); 541int tep_data_preempt_count(struct tep_handle *pevent, struct tep_record *rec);
714int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec); 542int tep_data_flags(struct tep_handle *pevent, struct tep_record *rec);
@@ -719,77 +547,35 @@ struct cmdline *tep_data_pid_from_comm(struct tep_handle *pevent, const char *co
719int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline); 547int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline);
720 548
721void tep_print_field(struct trace_seq *s, void *data, 549void tep_print_field(struct trace_seq *s, void *data,
722 struct format_field *field); 550 struct tep_format_field *field);
723void tep_print_fields(struct trace_seq *s, void *data, 551void tep_print_fields(struct trace_seq *s, void *data,
724 int size __maybe_unused, struct event_format *event); 552 int size __maybe_unused, struct tep_event_format *event);
725void tep_event_info(struct trace_seq *s, struct event_format *event, 553void tep_event_info(struct trace_seq *s, struct tep_event_format *event,
726 struct tep_record *record); 554 struct tep_record *record);
727int tep_strerror(struct tep_handle *pevent, enum tep_errno errnum, 555int tep_strerror(struct tep_handle *pevent, enum tep_errno errnum,
728 char *buf, size_t buflen); 556 char *buf, size_t buflen);
729 557
730struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type); 558struct tep_event_format **tep_list_events(struct tep_handle *pevent, enum tep_event_sort_type);
731struct format_field **tep_event_common_fields(struct event_format *event); 559struct tep_format_field **tep_event_common_fields(struct tep_event_format *event);
732struct format_field **tep_event_fields(struct event_format *event); 560struct tep_format_field **tep_event_fields(struct tep_event_format *event);
733 561
734static inline int tep_get_cpus(struct tep_handle *pevent) 562enum tep_endian {
735{ 563 TEP_LITTLE_ENDIAN = 0,
736 return pevent->cpus; 564 TEP_BIG_ENDIAN
737} 565};
738 566int tep_get_cpus(struct tep_handle *pevent);
739static inline void tep_set_cpus(struct tep_handle *pevent, int cpus) 567void tep_set_cpus(struct tep_handle *pevent, int cpus);
740{ 568int tep_get_long_size(struct tep_handle *pevent);
741 pevent->cpus = cpus; 569void tep_set_long_size(struct tep_handle *pevent, int long_size);
742} 570int tep_get_page_size(struct tep_handle *pevent);
743 571void tep_set_page_size(struct tep_handle *pevent, int _page_size);
744static inline int tep_get_long_size(struct tep_handle *pevent) 572int tep_is_file_bigendian(struct tep_handle *pevent);
745{ 573void tep_set_file_bigendian(struct tep_handle *pevent, enum tep_endian endian);
746 return pevent->long_size; 574int tep_is_host_bigendian(struct tep_handle *pevent);
747} 575void tep_set_host_bigendian(struct tep_handle *pevent, enum tep_endian endian);
748 576int tep_is_latency_format(struct tep_handle *pevent);
749static inline void tep_set_long_size(struct tep_handle *pevent, int long_size) 577void tep_set_latency_format(struct tep_handle *pevent, int lat);
750{ 578int tep_get_header_page_size(struct tep_handle *pevent);
751 pevent->long_size = long_size;
752}
753
754static inline int tep_get_page_size(struct tep_handle *pevent)
755{
756 return pevent->page_size;
757}
758
759static inline void tep_set_page_size(struct tep_handle *pevent, int _page_size)
760{
761 pevent->page_size = _page_size;
762}
763
764static inline int tep_is_file_bigendian(struct tep_handle *pevent)
765{
766 return pevent->file_bigendian;
767}
768
769static inline void tep_set_file_bigendian(struct tep_handle *pevent, int endian)
770{
771 pevent->file_bigendian = endian;
772}
773
774static inline int tep_is_host_bigendian(struct tep_handle *pevent)
775{
776 return pevent->host_bigendian;
777}
778
779static inline void tep_set_host_bigendian(struct tep_handle *pevent, int endian)
780{
781 pevent->host_bigendian = endian;
782}
783
784static inline int tep_is_latency_format(struct tep_handle *pevent)
785{
786 return pevent->latency_format;
787}
788
789static inline void tep_set_latency_format(struct tep_handle *pevent, int lat)
790{
791 pevent->latency_format = lat;
792}
793 579
794struct tep_handle *tep_alloc(void); 580struct tep_handle *tep_alloc(void);
795void tep_free(struct tep_handle *pevent); 581void tep_free(struct tep_handle *pevent);
@@ -798,7 +584,7 @@ void tep_unref(struct tep_handle *pevent);
798 584
799/* access to the internal parser */ 585/* access to the internal parser */
800void tep_buffer_init(const char *buf, unsigned long long size); 586void tep_buffer_init(const char *buf, unsigned long long size);
801enum event_type tep_read_token(char **tok); 587enum tep_event_type tep_read_token(char **tok);
802void tep_free_token(char *token); 588void tep_free_token(char *token);
803int tep_peek_char(void); 589int tep_peek_char(void);
804const char *tep_get_input_buf(void); 590const char *tep_get_input_buf(void);
@@ -810,136 +596,136 @@ void tep_print_printk(struct tep_handle *pevent);
810 596
811/* ----------------------- filtering ----------------------- */ 597/* ----------------------- filtering ----------------------- */
812 598
813enum filter_boolean_type { 599enum tep_filter_boolean_type {
814 FILTER_FALSE, 600 TEP_FILTER_FALSE,
815 FILTER_TRUE, 601 TEP_FILTER_TRUE,
816}; 602};
817 603
818enum filter_op_type { 604enum tep_filter_op_type {
819 FILTER_OP_AND = 1, 605 TEP_FILTER_OP_AND = 1,
820 FILTER_OP_OR, 606 TEP_FILTER_OP_OR,
821 FILTER_OP_NOT, 607 TEP_FILTER_OP_NOT,
822}; 608};
823 609
824enum filter_cmp_type { 610enum tep_filter_cmp_type {
825 FILTER_CMP_NONE, 611 TEP_FILTER_CMP_NONE,
826 FILTER_CMP_EQ, 612 TEP_FILTER_CMP_EQ,
827 FILTER_CMP_NE, 613 TEP_FILTER_CMP_NE,
828 FILTER_CMP_GT, 614 TEP_FILTER_CMP_GT,
829 FILTER_CMP_LT, 615 TEP_FILTER_CMP_LT,
830 FILTER_CMP_GE, 616 TEP_FILTER_CMP_GE,
831 FILTER_CMP_LE, 617 TEP_FILTER_CMP_LE,
832 FILTER_CMP_MATCH, 618 TEP_FILTER_CMP_MATCH,
833 FILTER_CMP_NOT_MATCH, 619 TEP_FILTER_CMP_NOT_MATCH,
834 FILTER_CMP_REGEX, 620 TEP_FILTER_CMP_REGEX,
835 FILTER_CMP_NOT_REGEX, 621 TEP_FILTER_CMP_NOT_REGEX,
836}; 622};
837 623
838enum filter_exp_type { 624enum tep_filter_exp_type {
839 FILTER_EXP_NONE, 625 TEP_FILTER_EXP_NONE,
840 FILTER_EXP_ADD, 626 TEP_FILTER_EXP_ADD,
841 FILTER_EXP_SUB, 627 TEP_FILTER_EXP_SUB,
842 FILTER_EXP_MUL, 628 TEP_FILTER_EXP_MUL,
843 FILTER_EXP_DIV, 629 TEP_FILTER_EXP_DIV,
844 FILTER_EXP_MOD, 630 TEP_FILTER_EXP_MOD,
845 FILTER_EXP_RSHIFT, 631 TEP_FILTER_EXP_RSHIFT,
846 FILTER_EXP_LSHIFT, 632 TEP_FILTER_EXP_LSHIFT,
847 FILTER_EXP_AND, 633 TEP_FILTER_EXP_AND,
848 FILTER_EXP_OR, 634 TEP_FILTER_EXP_OR,
849 FILTER_EXP_XOR, 635 TEP_FILTER_EXP_XOR,
850 FILTER_EXP_NOT, 636 TEP_FILTER_EXP_NOT,
851}; 637};
852 638
853enum filter_arg_type { 639enum tep_filter_arg_type {
854 FILTER_ARG_NONE, 640 TEP_FILTER_ARG_NONE,
855 FILTER_ARG_BOOLEAN, 641 TEP_FILTER_ARG_BOOLEAN,
856 FILTER_ARG_VALUE, 642 TEP_FILTER_ARG_VALUE,
857 FILTER_ARG_FIELD, 643 TEP_FILTER_ARG_FIELD,
858 FILTER_ARG_EXP, 644 TEP_FILTER_ARG_EXP,
859 FILTER_ARG_OP, 645 TEP_FILTER_ARG_OP,
860 FILTER_ARG_NUM, 646 TEP_FILTER_ARG_NUM,
861 FILTER_ARG_STR, 647 TEP_FILTER_ARG_STR,
862}; 648};
863 649
864enum filter_value_type { 650enum tep_filter_value_type {
865 FILTER_NUMBER, 651 TEP_FILTER_NUMBER,
866 FILTER_STRING, 652 TEP_FILTER_STRING,
867 FILTER_CHAR 653 TEP_FILTER_CHAR
868}; 654};
869 655
870struct fliter_arg; 656struct tep_filter_arg;
871 657
872struct filter_arg_boolean { 658struct tep_filter_arg_boolean {
873 enum filter_boolean_type value; 659 enum tep_filter_boolean_type value;
874}; 660};
875 661
876struct filter_arg_field { 662struct tep_filter_arg_field {
877 struct format_field *field; 663 struct tep_format_field *field;
878}; 664};
879 665
880struct filter_arg_value { 666struct tep_filter_arg_value {
881 enum filter_value_type type; 667 enum tep_filter_value_type type;
882 union { 668 union {
883 char *str; 669 char *str;
884 unsigned long long val; 670 unsigned long long val;
885 }; 671 };
886}; 672};
887 673
888struct filter_arg_op { 674struct tep_filter_arg_op {
889 enum filter_op_type type; 675 enum tep_filter_op_type type;
890 struct filter_arg *left; 676 struct tep_filter_arg *left;
891 struct filter_arg *right; 677 struct tep_filter_arg *right;
892}; 678};
893 679
894struct filter_arg_exp { 680struct tep_filter_arg_exp {
895 enum filter_exp_type type; 681 enum tep_filter_exp_type type;
896 struct filter_arg *left; 682 struct tep_filter_arg *left;
897 struct filter_arg *right; 683 struct tep_filter_arg *right;
898}; 684};
899 685
900struct filter_arg_num { 686struct tep_filter_arg_num {
901 enum filter_cmp_type type; 687 enum tep_filter_cmp_type type;
902 struct filter_arg *left; 688 struct tep_filter_arg *left;
903 struct filter_arg *right; 689 struct tep_filter_arg *right;
904}; 690};
905 691
906struct filter_arg_str { 692struct tep_filter_arg_str {
907 enum filter_cmp_type type; 693 enum tep_filter_cmp_type type;
908 struct format_field *field; 694 struct tep_format_field *field;
909 char *val; 695 char *val;
910 char *buffer; 696 char *buffer;
911 regex_t reg; 697 regex_t reg;
912}; 698};
913 699
914struct filter_arg { 700struct tep_filter_arg {
915 enum filter_arg_type type; 701 enum tep_filter_arg_type type;
916 union { 702 union {
917 struct filter_arg_boolean boolean; 703 struct tep_filter_arg_boolean boolean;
918 struct filter_arg_field field; 704 struct tep_filter_arg_field field;
919 struct filter_arg_value value; 705 struct tep_filter_arg_value value;
920 struct filter_arg_op op; 706 struct tep_filter_arg_op op;
921 struct filter_arg_exp exp; 707 struct tep_filter_arg_exp exp;
922 struct filter_arg_num num; 708 struct tep_filter_arg_num num;
923 struct filter_arg_str str; 709 struct tep_filter_arg_str str;
924 }; 710 };
925}; 711};
926 712
927struct filter_type { 713struct tep_filter_type {
928 int event_id; 714 int event_id;
929 struct event_format *event; 715 struct tep_event_format *event;
930 struct filter_arg *filter; 716 struct tep_filter_arg *filter;
931}; 717};
932 718
933#define TEP_FILTER_ERROR_BUFSZ 1024 719#define TEP_FILTER_ERROR_BUFSZ 1024
934 720
935struct event_filter { 721struct tep_event_filter {
936 struct tep_handle *pevent; 722 struct tep_handle *pevent;
937 int filters; 723 int filters;
938 struct filter_type *event_filters; 724 struct tep_filter_type *event_filters;
939 char error_buffer[TEP_FILTER_ERROR_BUFSZ]; 725 char error_buffer[TEP_FILTER_ERROR_BUFSZ];
940}; 726};
941 727
942struct event_filter *tep_filter_alloc(struct tep_handle *pevent); 728struct tep_event_filter *tep_filter_alloc(struct tep_handle *pevent);
943 729
944/* for backward compatibility */ 730/* for backward compatibility */
945#define FILTER_NONE TEP_ERRNO__NO_FILTER 731#define FILTER_NONE TEP_ERRNO__NO_FILTER
@@ -947,45 +733,45 @@ struct event_filter *tep_filter_alloc(struct tep_handle *pevent);
947#define FILTER_MISS TEP_ERRNO__FILTER_MISS 733#define FILTER_MISS TEP_ERRNO__FILTER_MISS
948#define FILTER_MATCH TEP_ERRNO__FILTER_MATCH 734#define FILTER_MATCH TEP_ERRNO__FILTER_MATCH
949 735
950enum filter_trivial_type { 736enum tep_filter_trivial_type {
951 FILTER_TRIVIAL_FALSE, 737 TEP_FILTER_TRIVIAL_FALSE,
952 FILTER_TRIVIAL_TRUE, 738 TEP_FILTER_TRIVIAL_TRUE,
953 FILTER_TRIVIAL_BOTH, 739 TEP_FILTER_TRIVIAL_BOTH,
954}; 740};
955 741
956enum tep_errno tep_filter_add_filter_str(struct event_filter *filter, 742enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
957 const char *filter_str); 743 const char *filter_str);
958 744
959enum tep_errno tep_filter_match(struct event_filter *filter, 745enum tep_errno tep_filter_match(struct tep_event_filter *filter,
960 struct tep_record *record); 746 struct tep_record *record);
961 747
962int tep_filter_strerror(struct event_filter *filter, enum tep_errno err, 748int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
963 char *buf, size_t buflen); 749 char *buf, size_t buflen);
964 750
965int tep_event_filtered(struct event_filter *filter, 751int tep_event_filtered(struct tep_event_filter *filter,
966 int event_id); 752 int event_id);
967 753
968void tep_filter_reset(struct event_filter *filter); 754void tep_filter_reset(struct tep_event_filter *filter);
969 755
970int tep_filter_clear_trivial(struct event_filter *filter, 756int tep_filter_clear_trivial(struct tep_event_filter *filter,
971 enum filter_trivial_type type); 757 enum tep_filter_trivial_type type);
972 758
973void tep_filter_free(struct event_filter *filter); 759void tep_filter_free(struct tep_event_filter *filter);
974 760
975char *tep_filter_make_string(struct event_filter *filter, int event_id); 761char *tep_filter_make_string(struct tep_event_filter *filter, int event_id);
976 762
977int tep_filter_remove_event(struct event_filter *filter, 763int tep_filter_remove_event(struct tep_event_filter *filter,
978 int event_id); 764 int event_id);
979 765
980int tep_filter_event_has_trivial(struct event_filter *filter, 766int tep_filter_event_has_trivial(struct tep_event_filter *filter,
981 int event_id, 767 int event_id,
982 enum filter_trivial_type type); 768 enum tep_filter_trivial_type type);
983 769
984int tep_filter_copy(struct event_filter *dest, struct event_filter *source); 770int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source);
985 771
986int tep_update_trivial(struct event_filter *dest, struct event_filter *source, 772int tep_update_trivial(struct tep_event_filter *dest, struct tep_event_filter *source,
987 enum filter_trivial_type type); 773 enum tep_filter_trivial_type type);
988 774
989int tep_filter_compare(struct event_filter *filter1, struct event_filter *filter2); 775int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2);
990 776
991#endif /* _PARSE_EVENTS_H */ 777#endif /* _PARSE_EVENTS_H */
diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index f17e25097e1e..e74f16c88398 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -14,7 +14,9 @@
14#include <unistd.h> 14#include <unistd.h>
15#include <dirent.h> 15#include <dirent.h>
16#include "event-parse.h" 16#include "event-parse.h"
17#include "event-parse-local.h"
17#include "event-utils.h" 18#include "event-utils.h"
19#include "trace-seq.h"
18 20
19#define LOCAL_PLUGIN_DIR ".traceevent/plugins" 21#define LOCAL_PLUGIN_DIR ".traceevent/plugins"
20 22
@@ -30,8 +32,8 @@ static struct trace_plugin_options {
30 char *value; 32 char *value;
31} *trace_plugin_options; 33} *trace_plugin_options;
32 34
33struct plugin_list { 35struct tep_plugin_list {
34 struct plugin_list *next; 36 struct tep_plugin_list *next;
35 char *name; 37 char *name;
36 void *handle; 38 void *handle;
37}; 39};
@@ -258,7 +260,7 @@ void tep_plugin_remove_options(struct tep_plugin_option *options)
258 */ 260 */
259void tep_print_plugins(struct trace_seq *s, 261void tep_print_plugins(struct trace_seq *s,
260 const char *prefix, const char *suffix, 262 const char *prefix, const char *suffix,
261 const struct plugin_list *list) 263 const struct tep_plugin_list *list)
262{ 264{
263 while (list) { 265 while (list) {
264 trace_seq_printf(s, "%s%s%s", prefix, list->name, suffix); 266 trace_seq_printf(s, "%s%s%s", prefix, list->name, suffix);
@@ -270,9 +272,9 @@ static void
270load_plugin(struct tep_handle *pevent, const char *path, 272load_plugin(struct tep_handle *pevent, const char *path,
271 const char *file, void *data) 273 const char *file, void *data)
272{ 274{
273 struct plugin_list **plugin_list = data; 275 struct tep_plugin_list **plugin_list = data;
274 tep_plugin_load_func func; 276 tep_plugin_load_func func;
275 struct plugin_list *list; 277 struct tep_plugin_list *list;
276 const char *alias; 278 const char *alias;
277 char *plugin; 279 char *plugin;
278 void *handle; 280 void *handle;
@@ -416,20 +418,20 @@ load_plugins(struct tep_handle *pevent, const char *suffix,
416 free(path); 418 free(path);
417} 419}
418 420
419struct plugin_list* 421struct tep_plugin_list*
420tep_load_plugins(struct tep_handle *pevent) 422tep_load_plugins(struct tep_handle *pevent)
421{ 423{
422 struct plugin_list *list = NULL; 424 struct tep_plugin_list *list = NULL;
423 425
424 load_plugins(pevent, ".so", load_plugin, &list); 426 load_plugins(pevent, ".so", load_plugin, &list);
425 return list; 427 return list;
426} 428}
427 429
428void 430void
429tep_unload_plugins(struct plugin_list *plugin_list, struct tep_handle *pevent) 431tep_unload_plugins(struct tep_plugin_list *plugin_list, struct tep_handle *pevent)
430{ 432{
431 tep_plugin_unload_func func; 433 tep_plugin_unload_func func;
432 struct plugin_list *list; 434 struct tep_plugin_list *list;
433 435
434 while (plugin_list) { 436 while (plugin_list) {
435 list = plugin_list; 437 list = plugin_list;
diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c
index e76154c02ee7..ed87cb56713d 100644
--- a/tools/lib/traceevent/parse-filter.c
+++ b/tools/lib/traceevent/parse-filter.c
@@ -11,22 +11,23 @@
11#include <sys/types.h> 11#include <sys/types.h>
12 12
13#include "event-parse.h" 13#include "event-parse.h"
14#include "event-parse-local.h"
14#include "event-utils.h" 15#include "event-utils.h"
15 16
16#define COMM "COMM" 17#define COMM "COMM"
17#define CPU "CPU" 18#define CPU "CPU"
18 19
19static struct format_field comm = { 20static struct tep_format_field comm = {
20 .name = "COMM", 21 .name = "COMM",
21}; 22};
22 23
23static struct format_field cpu = { 24static struct tep_format_field cpu = {
24 .name = "CPU", 25 .name = "CPU",
25}; 26};
26 27
27struct event_list { 28struct event_list {
28 struct event_list *next; 29 struct event_list *next;
29 struct event_format *event; 30 struct tep_event_format *event;
30}; 31};
31 32
32static void show_error(char *error_buf, const char *fmt, ...) 33static void show_error(char *error_buf, const char *fmt, ...)
@@ -61,15 +62,15 @@ static void free_token(char *token)
61 tep_free_token(token); 62 tep_free_token(token);
62} 63}
63 64
64static enum event_type read_token(char **tok) 65static enum tep_event_type read_token(char **tok)
65{ 66{
66 enum event_type type; 67 enum tep_event_type type;
67 char *token = NULL; 68 char *token = NULL;
68 69
69 do { 70 do {
70 free_token(token); 71 free_token(token);
71 type = tep_read_token(&token); 72 type = tep_read_token(&token);
72 } while (type == EVENT_NEWLINE || type == EVENT_SPACE); 73 } while (type == TEP_EVENT_NEWLINE || type == TEP_EVENT_SPACE);
73 74
74 /* If token is = or ! check to see if the next char is ~ */ 75 /* If token is = or ! check to see if the next char is ~ */
75 if (token && 76 if (token &&
@@ -79,7 +80,7 @@ static enum event_type read_token(char **tok)
79 *tok = malloc(3); 80 *tok = malloc(3);
80 if (*tok == NULL) { 81 if (*tok == NULL) {
81 free_token(token); 82 free_token(token);
82 return EVENT_ERROR; 83 return TEP_EVENT_ERROR;
83 } 84 }
84 sprintf(*tok, "%c%c", *token, '~'); 85 sprintf(*tok, "%c%c", *token, '~');
85 free_token(token); 86 free_token(token);
@@ -94,8 +95,8 @@ static enum event_type read_token(char **tok)
94 95
95static int filter_cmp(const void *a, const void *b) 96static int filter_cmp(const void *a, const void *b)
96{ 97{
97 const struct filter_type *ea = a; 98 const struct tep_filter_type *ea = a;
98 const struct filter_type *eb = b; 99 const struct tep_filter_type *eb = b;
99 100
100 if (ea->event_id < eb->event_id) 101 if (ea->event_id < eb->event_id)
101 return -1; 102 return -1;
@@ -106,11 +107,11 @@ static int filter_cmp(const void *a, const void *b)
106 return 0; 107 return 0;
107} 108}
108 109
109static struct filter_type * 110static struct tep_filter_type *
110find_filter_type(struct event_filter *filter, int id) 111find_filter_type(struct tep_event_filter *filter, int id)
111{ 112{
112 struct filter_type *filter_type; 113 struct tep_filter_type *filter_type;
113 struct filter_type key; 114 struct tep_filter_type key;
114 115
115 key.event_id = id; 116 key.event_id = id;
116 117
@@ -122,10 +123,10 @@ find_filter_type(struct event_filter *filter, int id)
122 return filter_type; 123 return filter_type;
123} 124}
124 125
125static struct filter_type * 126static struct tep_filter_type *
126add_filter_type(struct event_filter *filter, int id) 127add_filter_type(struct tep_event_filter *filter, int id)
127{ 128{
128 struct filter_type *filter_type; 129 struct tep_filter_type *filter_type;
129 int i; 130 int i;
130 131
131 filter_type = find_filter_type(filter, id); 132 filter_type = find_filter_type(filter, id);
@@ -165,9 +166,9 @@ add_filter_type(struct event_filter *filter, int id)
165 * tep_filter_alloc - create a new event filter 166 * tep_filter_alloc - create a new event filter
166 * @pevent: The pevent that this filter is associated with 167 * @pevent: The pevent that this filter is associated with
167 */ 168 */
168struct event_filter *tep_filter_alloc(struct tep_handle *pevent) 169struct tep_event_filter *tep_filter_alloc(struct tep_handle *pevent)
169{ 170{
170 struct event_filter *filter; 171 struct tep_event_filter *filter;
171 172
172 filter = malloc(sizeof(*filter)); 173 filter = malloc(sizeof(*filter));
173 if (filter == NULL) 174 if (filter == NULL)
@@ -180,44 +181,44 @@ struct event_filter *tep_filter_alloc(struct tep_handle *pevent)
180 return filter; 181 return filter;
181} 182}
182 183
183static struct filter_arg *allocate_arg(void) 184static struct tep_filter_arg *allocate_arg(void)
184{ 185{
185 return calloc(1, sizeof(struct filter_arg)); 186 return calloc(1, sizeof(struct tep_filter_arg));
186} 187}
187 188
188static void free_arg(struct filter_arg *arg) 189static void free_arg(struct tep_filter_arg *arg)
189{ 190{
190 if (!arg) 191 if (!arg)
191 return; 192 return;
192 193
193 switch (arg->type) { 194 switch (arg->type) {
194 case FILTER_ARG_NONE: 195 case TEP_FILTER_ARG_NONE:
195 case FILTER_ARG_BOOLEAN: 196 case TEP_FILTER_ARG_BOOLEAN:
196 break; 197 break;
197 198
198 case FILTER_ARG_NUM: 199 case TEP_FILTER_ARG_NUM:
199 free_arg(arg->num.left); 200 free_arg(arg->num.left);
200 free_arg(arg->num.right); 201 free_arg(arg->num.right);
201 break; 202 break;
202 203
203 case FILTER_ARG_EXP: 204 case TEP_FILTER_ARG_EXP:
204 free_arg(arg->exp.left); 205 free_arg(arg->exp.left);
205 free_arg(arg->exp.right); 206 free_arg(arg->exp.right);
206 break; 207 break;
207 208
208 case FILTER_ARG_STR: 209 case TEP_FILTER_ARG_STR:
209 free(arg->str.val); 210 free(arg->str.val);
210 regfree(&arg->str.reg); 211 regfree(&arg->str.reg);
211 free(arg->str.buffer); 212 free(arg->str.buffer);
212 break; 213 break;
213 214
214 case FILTER_ARG_VALUE: 215 case TEP_FILTER_ARG_VALUE:
215 if (arg->value.type == FILTER_STRING || 216 if (arg->value.type == TEP_FILTER_STRING ||
216 arg->value.type == FILTER_CHAR) 217 arg->value.type == TEP_FILTER_CHAR)
217 free(arg->value.str); 218 free(arg->value.str);
218 break; 219 break;
219 220
220 case FILTER_ARG_OP: 221 case TEP_FILTER_ARG_OP:
221 free_arg(arg->op.left); 222 free_arg(arg->op.left);
222 free_arg(arg->op.right); 223 free_arg(arg->op.right);
223 default: 224 default:
@@ -228,7 +229,7 @@ static void free_arg(struct filter_arg *arg)
228} 229}
229 230
230static int add_event(struct event_list **events, 231static int add_event(struct event_list **events,
231 struct event_format *event) 232 struct tep_event_format *event)
232{ 233{
233 struct event_list *list; 234 struct event_list *list;
234 235
@@ -242,7 +243,7 @@ static int add_event(struct event_list **events,
242 return 0; 243 return 0;
243} 244}
244 245
245static int event_match(struct event_format *event, 246static int event_match(struct tep_event_format *event,
246 regex_t *sreg, regex_t *ereg) 247 regex_t *sreg, regex_t *ereg)
247{ 248{
248 if (sreg) { 249 if (sreg) {
@@ -258,7 +259,7 @@ static enum tep_errno
258find_event(struct tep_handle *pevent, struct event_list **events, 259find_event(struct tep_handle *pevent, struct event_list **events,
259 char *sys_name, char *event_name) 260 char *sys_name, char *event_name)
260{ 261{
261 struct event_format *event; 262 struct tep_event_format *event;
262 regex_t ereg; 263 regex_t ereg;
263 regex_t sreg; 264 regex_t sreg;
264 int match = 0; 265 int match = 0;
@@ -333,11 +334,11 @@ static void free_events(struct event_list *events)
333} 334}
334 335
335static enum tep_errno 336static enum tep_errno
336create_arg_item(struct event_format *event, const char *token, 337create_arg_item(struct tep_event_format *event, const char *token,
337 enum event_type type, struct filter_arg **parg, char *error_str) 338 enum tep_event_type type, struct tep_filter_arg **parg, char *error_str)
338{ 339{
339 struct format_field *field; 340 struct tep_format_field *field;
340 struct filter_arg *arg; 341 struct tep_filter_arg *arg;
341 342
342 arg = allocate_arg(); 343 arg = allocate_arg();
343 if (arg == NULL) { 344 if (arg == NULL) {
@@ -347,11 +348,11 @@ create_arg_item(struct event_format *event, const char *token,
347 348
348 switch (type) { 349 switch (type) {
349 350
350 case EVENT_SQUOTE: 351 case TEP_EVENT_SQUOTE:
351 case EVENT_DQUOTE: 352 case TEP_EVENT_DQUOTE:
352 arg->type = FILTER_ARG_VALUE; 353 arg->type = TEP_FILTER_ARG_VALUE;
353 arg->value.type = 354 arg->value.type =
354 type == EVENT_DQUOTE ? FILTER_STRING : FILTER_CHAR; 355 type == TEP_EVENT_DQUOTE ? TEP_FILTER_STRING : TEP_FILTER_CHAR;
355 arg->value.str = strdup(token); 356 arg->value.str = strdup(token);
356 if (!arg->value.str) { 357 if (!arg->value.str) {
357 free_arg(arg); 358 free_arg(arg);
@@ -359,11 +360,11 @@ create_arg_item(struct event_format *event, const char *token,
359 return TEP_ERRNO__MEM_ALLOC_FAILED; 360 return TEP_ERRNO__MEM_ALLOC_FAILED;
360 } 361 }
361 break; 362 break;
362 case EVENT_ITEM: 363 case TEP_EVENT_ITEM:
363 /* if it is a number, then convert it */ 364 /* if it is a number, then convert it */
364 if (isdigit(token[0])) { 365 if (isdigit(token[0])) {
365 arg->type = FILTER_ARG_VALUE; 366 arg->type = TEP_FILTER_ARG_VALUE;
366 arg->value.type = FILTER_NUMBER; 367 arg->value.type = TEP_FILTER_NUMBER;
367 arg->value.val = strtoull(token, NULL, 0); 368 arg->value.val = strtoull(token, NULL, 0);
368 break; 369 break;
369 } 370 }
@@ -377,12 +378,12 @@ create_arg_item(struct event_format *event, const char *token,
377 field = &cpu; 378 field = &cpu;
378 } else { 379 } else {
379 /* not a field, Make it false */ 380 /* not a field, Make it false */
380 arg->type = FILTER_ARG_BOOLEAN; 381 arg->type = TEP_FILTER_ARG_BOOLEAN;
381 arg->boolean.value = FILTER_FALSE; 382 arg->boolean.value = TEP_FILTER_FALSE;
382 break; 383 break;
383 } 384 }
384 } 385 }
385 arg->type = FILTER_ARG_FIELD; 386 arg->type = TEP_FILTER_ARG_FIELD;
386 arg->field.field = field; 387 arg->field.field = field;
387 break; 388 break;
388 default: 389 default:
@@ -394,82 +395,82 @@ create_arg_item(struct event_format *event, const char *token,
394 return 0; 395 return 0;
395} 396}
396 397
397static struct filter_arg * 398static struct tep_filter_arg *
398create_arg_op(enum filter_op_type btype) 399create_arg_op(enum tep_filter_op_type btype)
399{ 400{
400 struct filter_arg *arg; 401 struct tep_filter_arg *arg;
401 402
402 arg = allocate_arg(); 403 arg = allocate_arg();
403 if (!arg) 404 if (!arg)
404 return NULL; 405 return NULL;
405 406
406 arg->type = FILTER_ARG_OP; 407 arg->type = TEP_FILTER_ARG_OP;
407 arg->op.type = btype; 408 arg->op.type = btype;
408 409
409 return arg; 410 return arg;
410} 411}
411 412
412static struct filter_arg * 413static struct tep_filter_arg *
413create_arg_exp(enum filter_exp_type etype) 414create_arg_exp(enum tep_filter_exp_type etype)
414{ 415{
415 struct filter_arg *arg; 416 struct tep_filter_arg *arg;
416 417
417 arg = allocate_arg(); 418 arg = allocate_arg();
418 if (!arg) 419 if (!arg)
419 return NULL; 420 return NULL;
420 421
421 arg->type = FILTER_ARG_EXP; 422 arg->type = TEP_FILTER_ARG_EXP;
422 arg->exp.type = etype; 423 arg->exp.type = etype;
423 424
424 return arg; 425 return arg;
425} 426}
426 427
427static struct filter_arg * 428static struct tep_filter_arg *
428create_arg_cmp(enum filter_cmp_type ctype) 429create_arg_cmp(enum tep_filter_cmp_type ctype)
429{ 430{
430 struct filter_arg *arg; 431 struct tep_filter_arg *arg;
431 432
432 arg = allocate_arg(); 433 arg = allocate_arg();
433 if (!arg) 434 if (!arg)
434 return NULL; 435 return NULL;
435 436
436 /* Use NUM and change if necessary */ 437 /* Use NUM and change if necessary */
437 arg->type = FILTER_ARG_NUM; 438 arg->type = TEP_FILTER_ARG_NUM;
438 arg->num.type = ctype; 439 arg->num.type = ctype;
439 440
440 return arg; 441 return arg;
441} 442}
442 443
443static enum tep_errno 444static enum tep_errno
444add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str) 445add_right(struct tep_filter_arg *op, struct tep_filter_arg *arg, char *error_str)
445{ 446{
446 struct filter_arg *left; 447 struct tep_filter_arg *left;
447 char *str; 448 char *str;
448 int op_type; 449 int op_type;
449 int ret; 450 int ret;
450 451
451 switch (op->type) { 452 switch (op->type) {
452 case FILTER_ARG_EXP: 453 case TEP_FILTER_ARG_EXP:
453 if (op->exp.right) 454 if (op->exp.right)
454 goto out_fail; 455 goto out_fail;
455 op->exp.right = arg; 456 op->exp.right = arg;
456 break; 457 break;
457 458
458 case FILTER_ARG_OP: 459 case TEP_FILTER_ARG_OP:
459 if (op->op.right) 460 if (op->op.right)
460 goto out_fail; 461 goto out_fail;
461 op->op.right = arg; 462 op->op.right = arg;
462 break; 463 break;
463 464
464 case FILTER_ARG_NUM: 465 case TEP_FILTER_ARG_NUM:
465 if (op->op.right) 466 if (op->op.right)
466 goto out_fail; 467 goto out_fail;
467 /* 468 /*
468 * The arg must be num, str, or field 469 * The arg must be num, str, or field
469 */ 470 */
470 switch (arg->type) { 471 switch (arg->type) {
471 case FILTER_ARG_VALUE: 472 case TEP_FILTER_ARG_VALUE:
472 case FILTER_ARG_FIELD: 473 case TEP_FILTER_ARG_FIELD:
473 break; 474 break;
474 default: 475 default:
475 show_error(error_str, "Illegal rvalue"); 476 show_error(error_str, "Illegal rvalue");
@@ -481,20 +482,20 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
481 * convert this to a string or regex. 482 * convert this to a string or regex.
482 */ 483 */
483 switch (arg->value.type) { 484 switch (arg->value.type) {
484 case FILTER_CHAR: 485 case TEP_FILTER_CHAR:
485 /* 486 /*
486 * A char should be converted to number if 487 * A char should be converted to number if
487 * the string is 1 byte, and the compare 488 * the string is 1 byte, and the compare
488 * is not a REGEX. 489 * is not a REGEX.
489 */ 490 */
490 if (strlen(arg->value.str) == 1 && 491 if (strlen(arg->value.str) == 1 &&
491 op->num.type != FILTER_CMP_REGEX && 492 op->num.type != TEP_FILTER_CMP_REGEX &&
492 op->num.type != FILTER_CMP_NOT_REGEX) { 493 op->num.type != TEP_FILTER_CMP_NOT_REGEX) {
493 arg->value.type = FILTER_NUMBER; 494 arg->value.type = TEP_FILTER_NUMBER;
494 goto do_int; 495 goto do_int;
495 } 496 }
496 /* fall through */ 497 /* fall through */
497 case FILTER_STRING: 498 case TEP_FILTER_STRING:
498 499
499 /* convert op to a string arg */ 500 /* convert op to a string arg */
500 op_type = op->num.type; 501 op_type = op->num.type;
@@ -508,16 +509,16 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
508 * If left arg was a field not found then 509 * If left arg was a field not found then
509 * NULL the entire op. 510 * NULL the entire op.
510 */ 511 */
511 if (left->type == FILTER_ARG_BOOLEAN) { 512 if (left->type == TEP_FILTER_ARG_BOOLEAN) {
512 free_arg(left); 513 free_arg(left);
513 free_arg(arg); 514 free_arg(arg);
514 op->type = FILTER_ARG_BOOLEAN; 515 op->type = TEP_FILTER_ARG_BOOLEAN;
515 op->boolean.value = FILTER_FALSE; 516 op->boolean.value = TEP_FILTER_FALSE;
516 break; 517 break;
517 } 518 }
518 519
519 /* Left arg must be a field */ 520 /* Left arg must be a field */
520 if (left->type != FILTER_ARG_FIELD) { 521 if (left->type != TEP_FILTER_ARG_FIELD) {
521 show_error(error_str, 522 show_error(error_str,
522 "Illegal lvalue for string comparison"); 523 "Illegal lvalue for string comparison");
523 return TEP_ERRNO__ILLEGAL_LVALUE; 524 return TEP_ERRNO__ILLEGAL_LVALUE;
@@ -525,15 +526,15 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
525 526
526 /* Make sure this is a valid string compare */ 527 /* Make sure this is a valid string compare */
527 switch (op_type) { 528 switch (op_type) {
528 case FILTER_CMP_EQ: 529 case TEP_FILTER_CMP_EQ:
529 op_type = FILTER_CMP_MATCH; 530 op_type = TEP_FILTER_CMP_MATCH;
530 break; 531 break;
531 case FILTER_CMP_NE: 532 case TEP_FILTER_CMP_NE:
532 op_type = FILTER_CMP_NOT_MATCH; 533 op_type = TEP_FILTER_CMP_NOT_MATCH;
533 break; 534 break;
534 535
535 case FILTER_CMP_REGEX: 536 case TEP_FILTER_CMP_REGEX:
536 case FILTER_CMP_NOT_REGEX: 537 case TEP_FILTER_CMP_NOT_REGEX:
537 ret = regcomp(&op->str.reg, str, REG_ICASE|REG_NOSUB); 538 ret = regcomp(&op->str.reg, str, REG_ICASE|REG_NOSUB);
538 if (ret) { 539 if (ret) {
539 show_error(error_str, 540 show_error(error_str,
@@ -548,7 +549,7 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
548 return TEP_ERRNO__ILLEGAL_STRING_CMP; 549 return TEP_ERRNO__ILLEGAL_STRING_CMP;
549 } 550 }
550 551
551 op->type = FILTER_ARG_STR; 552 op->type = TEP_FILTER_ARG_STR;
552 op->str.type = op_type; 553 op->str.type = op_type;
553 op->str.field = left->field.field; 554 op->str.field = left->field.field;
554 op->str.val = strdup(str); 555 op->str.val = strdup(str);
@@ -573,12 +574,12 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
573 574
574 break; 575 break;
575 576
576 case FILTER_NUMBER: 577 case TEP_FILTER_NUMBER:
577 578
578 do_int: 579 do_int:
579 switch (op->num.type) { 580 switch (op->num.type) {
580 case FILTER_CMP_REGEX: 581 case TEP_FILTER_CMP_REGEX:
581 case FILTER_CMP_NOT_REGEX: 582 case TEP_FILTER_CMP_NOT_REGEX:
582 show_error(error_str, 583 show_error(error_str,
583 "Op not allowed with integers"); 584 "Op not allowed with integers");
584 return TEP_ERRNO__ILLEGAL_INTEGER_CMP; 585 return TEP_ERRNO__ILLEGAL_INTEGER_CMP;
@@ -605,35 +606,35 @@ add_right(struct filter_arg *op, struct filter_arg *arg, char *error_str)
605 return TEP_ERRNO__SYNTAX_ERROR; 606 return TEP_ERRNO__SYNTAX_ERROR;
606} 607}
607 608
608static struct filter_arg * 609static struct tep_filter_arg *
609rotate_op_right(struct filter_arg *a, struct filter_arg *b) 610rotate_op_right(struct tep_filter_arg *a, struct tep_filter_arg *b)
610{ 611{
611 struct filter_arg *arg; 612 struct tep_filter_arg *arg;
612 613
613 arg = a->op.right; 614 arg = a->op.right;
614 a->op.right = b; 615 a->op.right = b;
615 return arg; 616 return arg;
616} 617}
617 618
618static enum tep_errno add_left(struct filter_arg *op, struct filter_arg *arg) 619static enum tep_errno add_left(struct tep_filter_arg *op, struct tep_filter_arg *arg)
619{ 620{
620 switch (op->type) { 621 switch (op->type) {
621 case FILTER_ARG_EXP: 622 case TEP_FILTER_ARG_EXP:
622 if (arg->type == FILTER_ARG_OP) 623 if (arg->type == TEP_FILTER_ARG_OP)
623 arg = rotate_op_right(arg, op); 624 arg = rotate_op_right(arg, op);
624 op->exp.left = arg; 625 op->exp.left = arg;
625 break; 626 break;
626 627
627 case FILTER_ARG_OP: 628 case TEP_FILTER_ARG_OP:
628 op->op.left = arg; 629 op->op.left = arg;
629 break; 630 break;
630 case FILTER_ARG_NUM: 631 case TEP_FILTER_ARG_NUM:
631 if (arg->type == FILTER_ARG_OP) 632 if (arg->type == TEP_FILTER_ARG_OP)
632 arg = rotate_op_right(arg, op); 633 arg = rotate_op_right(arg, op);
633 634
634 /* left arg of compares must be a field */ 635 /* left arg of compares must be a field */
635 if (arg->type != FILTER_ARG_FIELD && 636 if (arg->type != TEP_FILTER_ARG_FIELD &&
636 arg->type != FILTER_ARG_BOOLEAN) 637 arg->type != TEP_FILTER_ARG_BOOLEAN)
637 return TEP_ERRNO__INVALID_ARG_TYPE; 638 return TEP_ERRNO__INVALID_ARG_TYPE;
638 op->num.left = arg; 639 op->num.left = arg;
639 break; 640 break;
@@ -652,91 +653,91 @@ enum op_type {
652}; 653};
653 654
654static enum op_type process_op(const char *token, 655static enum op_type process_op(const char *token,
655 enum filter_op_type *btype, 656 enum tep_filter_op_type *btype,
656 enum filter_cmp_type *ctype, 657 enum tep_filter_cmp_type *ctype,
657 enum filter_exp_type *etype) 658 enum tep_filter_exp_type *etype)
658{ 659{
659 *btype = FILTER_OP_NOT; 660 *btype = TEP_FILTER_OP_NOT;
660 *etype = FILTER_EXP_NONE; 661 *etype = TEP_FILTER_EXP_NONE;
661 *ctype = FILTER_CMP_NONE; 662 *ctype = TEP_FILTER_CMP_NONE;
662 663
663 if (strcmp(token, "&&") == 0) 664 if (strcmp(token, "&&") == 0)
664 *btype = FILTER_OP_AND; 665 *btype = TEP_FILTER_OP_AND;
665 else if (strcmp(token, "||") == 0) 666 else if (strcmp(token, "||") == 0)
666 *btype = FILTER_OP_OR; 667 *btype = TEP_FILTER_OP_OR;
667 else if (strcmp(token, "!") == 0) 668 else if (strcmp(token, "!") == 0)
668 return OP_NOT; 669 return OP_NOT;
669 670
670 if (*btype != FILTER_OP_NOT) 671 if (*btype != TEP_FILTER_OP_NOT)
671 return OP_BOOL; 672 return OP_BOOL;
672 673
673 /* Check for value expressions */ 674 /* Check for value expressions */
674 if (strcmp(token, "+") == 0) { 675 if (strcmp(token, "+") == 0) {
675 *etype = FILTER_EXP_ADD; 676 *etype = TEP_FILTER_EXP_ADD;
676 } else if (strcmp(token, "-") == 0) { 677 } else if (strcmp(token, "-") == 0) {
677 *etype = FILTER_EXP_SUB; 678 *etype = TEP_FILTER_EXP_SUB;
678 } else if (strcmp(token, "*") == 0) { 679 } else if (strcmp(token, "*") == 0) {
679 *etype = FILTER_EXP_MUL; 680 *etype = TEP_FILTER_EXP_MUL;
680 } else if (strcmp(token, "/") == 0) { 681 } else if (strcmp(token, "/") == 0) {
681 *etype = FILTER_EXP_DIV; 682 *etype = TEP_FILTER_EXP_DIV;
682 } else if (strcmp(token, "%") == 0) { 683 } else if (strcmp(token, "%") == 0) {
683 *etype = FILTER_EXP_MOD; 684 *etype = TEP_FILTER_EXP_MOD;
684 } else if (strcmp(token, ">>") == 0) { 685 } else if (strcmp(token, ">>") == 0) {
685 *etype = FILTER_EXP_RSHIFT; 686 *etype = TEP_FILTER_EXP_RSHIFT;
686 } else if (strcmp(token, "<<") == 0) { 687 } else if (strcmp(token, "<<") == 0) {
687 *etype = FILTER_EXP_LSHIFT; 688 *etype = TEP_FILTER_EXP_LSHIFT;
688 } else if (strcmp(token, "&") == 0) { 689 } else if (strcmp(token, "&") == 0) {
689 *etype = FILTER_EXP_AND; 690 *etype = TEP_FILTER_EXP_AND;
690 } else if (strcmp(token, "|") == 0) { 691 } else if (strcmp(token, "|") == 0) {
691 *etype = FILTER_EXP_OR; 692 *etype = TEP_FILTER_EXP_OR;
692 } else if (strcmp(token, "^") == 0) { 693 } else if (strcmp(token, "^") == 0) {
693 *etype = FILTER_EXP_XOR; 694 *etype = TEP_FILTER_EXP_XOR;
694 } else if (strcmp(token, "~") == 0) 695 } else if (strcmp(token, "~") == 0)
695 *etype = FILTER_EXP_NOT; 696 *etype = TEP_FILTER_EXP_NOT;
696 697
697 if (*etype != FILTER_EXP_NONE) 698 if (*etype != TEP_FILTER_EXP_NONE)
698 return OP_EXP; 699 return OP_EXP;
699 700
700 /* Check for compares */ 701 /* Check for compares */
701 if (strcmp(token, "==") == 0) 702 if (strcmp(token, "==") == 0)
702 *ctype = FILTER_CMP_EQ; 703 *ctype = TEP_FILTER_CMP_EQ;
703 else if (strcmp(token, "!=") == 0) 704 else if (strcmp(token, "!=") == 0)
704 *ctype = FILTER_CMP_NE; 705 *ctype = TEP_FILTER_CMP_NE;
705 else if (strcmp(token, "<") == 0) 706 else if (strcmp(token, "<") == 0)
706 *ctype = FILTER_CMP_LT; 707 *ctype = TEP_FILTER_CMP_LT;
707 else if (strcmp(token, ">") == 0) 708 else if (strcmp(token, ">") == 0)
708 *ctype = FILTER_CMP_GT; 709 *ctype = TEP_FILTER_CMP_GT;
709 else if (strcmp(token, "<=") == 0) 710 else if (strcmp(token, "<=") == 0)
710 *ctype = FILTER_CMP_LE; 711 *ctype = TEP_FILTER_CMP_LE;
711 else if (strcmp(token, ">=") == 0) 712 else if (strcmp(token, ">=") == 0)
712 *ctype = FILTER_CMP_GE; 713 *ctype = TEP_FILTER_CMP_GE;
713 else if (strcmp(token, "=~") == 0) 714 else if (strcmp(token, "=~") == 0)
714 *ctype = FILTER_CMP_REGEX; 715 *ctype = TEP_FILTER_CMP_REGEX;
715 else if (strcmp(token, "!~") == 0) 716 else if (strcmp(token, "!~") == 0)
716 *ctype = FILTER_CMP_NOT_REGEX; 717 *ctype = TEP_FILTER_CMP_NOT_REGEX;
717 else 718 else
718 return OP_NONE; 719 return OP_NONE;
719 720
720 return OP_CMP; 721 return OP_CMP;
721} 722}
722 723
723static int check_op_done(struct filter_arg *arg) 724static int check_op_done(struct tep_filter_arg *arg)
724{ 725{
725 switch (arg->type) { 726 switch (arg->type) {
726 case FILTER_ARG_EXP: 727 case TEP_FILTER_ARG_EXP:
727 return arg->exp.right != NULL; 728 return arg->exp.right != NULL;
728 729
729 case FILTER_ARG_OP: 730 case TEP_FILTER_ARG_OP:
730 return arg->op.right != NULL; 731 return arg->op.right != NULL;
731 732
732 case FILTER_ARG_NUM: 733 case TEP_FILTER_ARG_NUM:
733 return arg->num.right != NULL; 734 return arg->num.right != NULL;
734 735
735 case FILTER_ARG_STR: 736 case TEP_FILTER_ARG_STR:
736 /* A string conversion is always done */ 737 /* A string conversion is always done */
737 return 1; 738 return 1;
738 739
739 case FILTER_ARG_BOOLEAN: 740 case TEP_FILTER_ARG_BOOLEAN:
740 /* field not found, is ok */ 741 /* field not found, is ok */
741 return 1; 742 return 1;
742 743
@@ -752,14 +753,14 @@ enum filter_vals {
752}; 753};
753 754
754static enum tep_errno 755static enum tep_errno
755reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child, 756reparent_op_arg(struct tep_filter_arg *parent, struct tep_filter_arg *old_child,
756 struct filter_arg *arg, char *error_str) 757 struct tep_filter_arg *arg, char *error_str)
757{ 758{
758 struct filter_arg *other_child; 759 struct tep_filter_arg *other_child;
759 struct filter_arg **ptr; 760 struct tep_filter_arg **ptr;
760 761
761 if (parent->type != FILTER_ARG_OP && 762 if (parent->type != TEP_FILTER_ARG_OP &&
762 arg->type != FILTER_ARG_OP) { 763 arg->type != TEP_FILTER_ARG_OP) {
763 show_error(error_str, "can not reparent other than OP"); 764 show_error(error_str, "can not reparent other than OP");
764 return TEP_ERRNO__REPARENT_NOT_OP; 765 return TEP_ERRNO__REPARENT_NOT_OP;
765 } 766 }
@@ -804,7 +805,7 @@ reparent_op_arg(struct filter_arg *parent, struct filter_arg *old_child,
804} 805}
805 806
806/* Returns either filter_vals (success) or tep_errno (failfure) */ 807/* Returns either filter_vals (success) or tep_errno (failfure) */
807static int test_arg(struct filter_arg *parent, struct filter_arg *arg, 808static int test_arg(struct tep_filter_arg *parent, struct tep_filter_arg *arg,
808 char *error_str) 809 char *error_str)
809{ 810{
810 int lval, rval; 811 int lval, rval;
@@ -812,16 +813,16 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
812 switch (arg->type) { 813 switch (arg->type) {
813 814
814 /* bad case */ 815 /* bad case */
815 case FILTER_ARG_BOOLEAN: 816 case TEP_FILTER_ARG_BOOLEAN:
816 return FILTER_VAL_FALSE + arg->boolean.value; 817 return FILTER_VAL_FALSE + arg->boolean.value;
817 818
818 /* good cases: */ 819 /* good cases: */
819 case FILTER_ARG_STR: 820 case TEP_FILTER_ARG_STR:
820 case FILTER_ARG_VALUE: 821 case TEP_FILTER_ARG_VALUE:
821 case FILTER_ARG_FIELD: 822 case TEP_FILTER_ARG_FIELD:
822 return FILTER_VAL_NORM; 823 return FILTER_VAL_NORM;
823 824
824 case FILTER_ARG_EXP: 825 case TEP_FILTER_ARG_EXP:
825 lval = test_arg(arg, arg->exp.left, error_str); 826 lval = test_arg(arg, arg->exp.left, error_str);
826 if (lval != FILTER_VAL_NORM) 827 if (lval != FILTER_VAL_NORM)
827 return lval; 828 return lval;
@@ -830,7 +831,7 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
830 return rval; 831 return rval;
831 return FILTER_VAL_NORM; 832 return FILTER_VAL_NORM;
832 833
833 case FILTER_ARG_NUM: 834 case TEP_FILTER_ARG_NUM:
834 lval = test_arg(arg, arg->num.left, error_str); 835 lval = test_arg(arg, arg->num.left, error_str);
835 if (lval != FILTER_VAL_NORM) 836 if (lval != FILTER_VAL_NORM)
836 return lval; 837 return lval;
@@ -839,14 +840,14 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
839 return rval; 840 return rval;
840 return FILTER_VAL_NORM; 841 return FILTER_VAL_NORM;
841 842
842 case FILTER_ARG_OP: 843 case TEP_FILTER_ARG_OP:
843 if (arg->op.type != FILTER_OP_NOT) { 844 if (arg->op.type != TEP_FILTER_OP_NOT) {
844 lval = test_arg(arg, arg->op.left, error_str); 845 lval = test_arg(arg, arg->op.left, error_str);
845 switch (lval) { 846 switch (lval) {
846 case FILTER_VAL_NORM: 847 case FILTER_VAL_NORM:
847 break; 848 break;
848 case FILTER_VAL_TRUE: 849 case FILTER_VAL_TRUE:
849 if (arg->op.type == FILTER_OP_OR) 850 if (arg->op.type == TEP_FILTER_OP_OR)
850 return FILTER_VAL_TRUE; 851 return FILTER_VAL_TRUE;
851 rval = test_arg(arg, arg->op.right, error_str); 852 rval = test_arg(arg, arg->op.right, error_str);
852 if (rval != FILTER_VAL_NORM) 853 if (rval != FILTER_VAL_NORM)
@@ -856,7 +857,7 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
856 error_str); 857 error_str);
857 858
858 case FILTER_VAL_FALSE: 859 case FILTER_VAL_FALSE:
859 if (arg->op.type == FILTER_OP_AND) 860 if (arg->op.type == TEP_FILTER_OP_AND)
860 return FILTER_VAL_FALSE; 861 return FILTER_VAL_FALSE;
861 rval = test_arg(arg, arg->op.right, error_str); 862 rval = test_arg(arg, arg->op.right, error_str);
862 if (rval != FILTER_VAL_NORM) 863 if (rval != FILTER_VAL_NORM)
@@ -877,18 +878,18 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
877 break; 878 break;
878 879
879 case FILTER_VAL_TRUE: 880 case FILTER_VAL_TRUE:
880 if (arg->op.type == FILTER_OP_OR) 881 if (arg->op.type == TEP_FILTER_OP_OR)
881 return FILTER_VAL_TRUE; 882 return FILTER_VAL_TRUE;
882 if (arg->op.type == FILTER_OP_NOT) 883 if (arg->op.type == TEP_FILTER_OP_NOT)
883 return FILTER_VAL_FALSE; 884 return FILTER_VAL_FALSE;
884 885
885 return reparent_op_arg(parent, arg, arg->op.left, 886 return reparent_op_arg(parent, arg, arg->op.left,
886 error_str); 887 error_str);
887 888
888 case FILTER_VAL_FALSE: 889 case FILTER_VAL_FALSE:
889 if (arg->op.type == FILTER_OP_AND) 890 if (arg->op.type == TEP_FILTER_OP_AND)
890 return FILTER_VAL_FALSE; 891 return FILTER_VAL_FALSE;
891 if (arg->op.type == FILTER_OP_NOT) 892 if (arg->op.type == TEP_FILTER_OP_NOT)
892 return FILTER_VAL_TRUE; 893 return FILTER_VAL_TRUE;
893 894
894 return reparent_op_arg(parent, arg, arg->op.left, 895 return reparent_op_arg(parent, arg, arg->op.left,
@@ -904,8 +905,8 @@ static int test_arg(struct filter_arg *parent, struct filter_arg *arg,
904} 905}
905 906
906/* Remove any unknown event fields */ 907/* Remove any unknown event fields */
907static int collapse_tree(struct filter_arg *arg, 908static int collapse_tree(struct tep_filter_arg *arg,
908 struct filter_arg **arg_collapsed, char *error_str) 909 struct tep_filter_arg **arg_collapsed, char *error_str)
909{ 910{
910 int ret; 911 int ret;
911 912
@@ -919,7 +920,7 @@ static int collapse_tree(struct filter_arg *arg,
919 free_arg(arg); 920 free_arg(arg);
920 arg = allocate_arg(); 921 arg = allocate_arg();
921 if (arg) { 922 if (arg) {
922 arg->type = FILTER_ARG_BOOLEAN; 923 arg->type = TEP_FILTER_ARG_BOOLEAN;
923 arg->boolean.value = ret == FILTER_VAL_TRUE; 924 arg->boolean.value = ret == FILTER_VAL_TRUE;
924 } else { 925 } else {
925 show_error(error_str, "Failed to allocate filter arg"); 926 show_error(error_str, "Failed to allocate filter arg");
@@ -939,19 +940,19 @@ static int collapse_tree(struct filter_arg *arg,
939} 940}
940 941
941static enum tep_errno 942static enum tep_errno
942process_filter(struct event_format *event, struct filter_arg **parg, 943process_filter(struct tep_event_format *event, struct tep_filter_arg **parg,
943 char *error_str, int not) 944 char *error_str, int not)
944{ 945{
945 enum event_type type; 946 enum tep_event_type type;
946 char *token = NULL; 947 char *token = NULL;
947 struct filter_arg *current_op = NULL; 948 struct tep_filter_arg *current_op = NULL;
948 struct filter_arg *current_exp = NULL; 949 struct tep_filter_arg *current_exp = NULL;
949 struct filter_arg *left_item = NULL; 950 struct tep_filter_arg *left_item = NULL;
950 struct filter_arg *arg = NULL; 951 struct tep_filter_arg *arg = NULL;
951 enum op_type op_type; 952 enum op_type op_type;
952 enum filter_op_type btype; 953 enum tep_filter_op_type btype;
953 enum filter_exp_type etype; 954 enum tep_filter_exp_type etype;
954 enum filter_cmp_type ctype; 955 enum tep_filter_cmp_type ctype;
955 enum tep_errno ret; 956 enum tep_errno ret;
956 957
957 *parg = NULL; 958 *parg = NULL;
@@ -960,9 +961,9 @@ process_filter(struct event_format *event, struct filter_arg **parg,
960 free(token); 961 free(token);
961 type = read_token(&token); 962 type = read_token(&token);
962 switch (type) { 963 switch (type) {
963 case EVENT_SQUOTE: 964 case TEP_EVENT_SQUOTE:
964 case EVENT_DQUOTE: 965 case TEP_EVENT_DQUOTE:
965 case EVENT_ITEM: 966 case TEP_EVENT_ITEM:
966 ret = create_arg_item(event, token, type, &arg, error_str); 967 ret = create_arg_item(event, token, type, &arg, error_str);
967 if (ret < 0) 968 if (ret < 0)
968 goto fail; 969 goto fail;
@@ -987,7 +988,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
987 arg = NULL; 988 arg = NULL;
988 break; 989 break;
989 990
990 case EVENT_DELIM: 991 case TEP_EVENT_DELIM:
991 if (*token == ',') { 992 if (*token == ',') {
992 show_error(error_str, "Illegal token ','"); 993 show_error(error_str, "Illegal token ','");
993 ret = TEP_ERRNO__ILLEGAL_TOKEN; 994 ret = TEP_ERRNO__ILLEGAL_TOKEN;
@@ -1054,7 +1055,7 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1054 } 1055 }
1055 break; 1056 break;
1056 1057
1057 case EVENT_OP: 1058 case TEP_EVENT_OP:
1058 op_type = process_op(token, &btype, &ctype, &etype); 1059 op_type = process_op(token, &btype, &ctype, &etype);
1059 1060
1060 /* All expect a left arg except for NOT */ 1061 /* All expect a left arg except for NOT */
@@ -1139,14 +1140,14 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1139 if (ret < 0) 1140 if (ret < 0)
1140 goto fail_syntax; 1141 goto fail_syntax;
1141 break; 1142 break;
1142 case EVENT_NONE: 1143 case TEP_EVENT_NONE:
1143 break; 1144 break;
1144 case EVENT_ERROR: 1145 case TEP_EVENT_ERROR:
1145 goto fail_alloc; 1146 goto fail_alloc;
1146 default: 1147 default:
1147 goto fail_syntax; 1148 goto fail_syntax;
1148 } 1149 }
1149 } while (type != EVENT_NONE); 1150 } while (type != TEP_EVENT_NONE);
1150 1151
1151 if (!current_op && !current_exp) 1152 if (!current_op && !current_exp)
1152 goto fail_syntax; 1153 goto fail_syntax;
@@ -1179,8 +1180,8 @@ process_filter(struct event_format *event, struct filter_arg **parg,
1179} 1180}
1180 1181
1181static enum tep_errno 1182static enum tep_errno
1182process_event(struct event_format *event, const char *filter_str, 1183process_event(struct tep_event_format *event, const char *filter_str,
1183 struct filter_arg **parg, char *error_str) 1184 struct tep_filter_arg **parg, char *error_str)
1184{ 1185{
1185 int ret; 1186 int ret;
1186 1187
@@ -1196,19 +1197,19 @@ process_event(struct event_format *event, const char *filter_str,
1196 if (*parg == NULL) 1197 if (*parg == NULL)
1197 return TEP_ERRNO__MEM_ALLOC_FAILED; 1198 return TEP_ERRNO__MEM_ALLOC_FAILED;
1198 1199
1199 (*parg)->type = FILTER_ARG_BOOLEAN; 1200 (*parg)->type = TEP_FILTER_ARG_BOOLEAN;
1200 (*parg)->boolean.value = FILTER_FALSE; 1201 (*parg)->boolean.value = TEP_FILTER_FALSE;
1201 } 1202 }
1202 1203
1203 return 0; 1204 return 0;
1204} 1205}
1205 1206
1206static enum tep_errno 1207static enum tep_errno
1207filter_event(struct event_filter *filter, struct event_format *event, 1208filter_event(struct tep_event_filter *filter, struct tep_event_format *event,
1208 const char *filter_str, char *error_str) 1209 const char *filter_str, char *error_str)
1209{ 1210{
1210 struct filter_type *filter_type; 1211 struct tep_filter_type *filter_type;
1211 struct filter_arg *arg; 1212 struct tep_filter_arg *arg;
1212 enum tep_errno ret; 1213 enum tep_errno ret;
1213 1214
1214 if (filter_str) { 1215 if (filter_str) {
@@ -1222,8 +1223,8 @@ filter_event(struct event_filter *filter, struct event_format *event,
1222 if (arg == NULL) 1223 if (arg == NULL)
1223 return TEP_ERRNO__MEM_ALLOC_FAILED; 1224 return TEP_ERRNO__MEM_ALLOC_FAILED;
1224 1225
1225 arg->type = FILTER_ARG_BOOLEAN; 1226 arg->type = TEP_FILTER_ARG_BOOLEAN;
1226 arg->boolean.value = FILTER_TRUE; 1227 arg->boolean.value = TEP_FILTER_TRUE;
1227 } 1228 }
1228 1229
1229 filter_type = add_filter_type(filter, event->id); 1230 filter_type = add_filter_type(filter, event->id);
@@ -1237,7 +1238,7 @@ filter_event(struct event_filter *filter, struct event_format *event,
1237 return 0; 1238 return 0;
1238} 1239}
1239 1240
1240static void filter_init_error_buf(struct event_filter *filter) 1241static void filter_init_error_buf(struct tep_event_filter *filter)
1241{ 1242{
1242 /* clear buffer to reset show error */ 1243 /* clear buffer to reset show error */
1243 tep_buffer_init("", 0); 1244 tep_buffer_init("", 0);
@@ -1253,7 +1254,7 @@ static void filter_init_error_buf(struct event_filter *filter)
1253 * negative error code. Use tep_filter_strerror() to see 1254 * negative error code. Use tep_filter_strerror() to see
1254 * actual error message in case of error. 1255 * actual error message in case of error.
1255 */ 1256 */
1256enum tep_errno tep_filter_add_filter_str(struct event_filter *filter, 1257enum tep_errno tep_filter_add_filter_str(struct tep_event_filter *filter,
1257 const char *filter_str) 1258 const char *filter_str)
1258{ 1259{
1259 struct tep_handle *pevent = filter->pevent; 1260 struct tep_handle *pevent = filter->pevent;
@@ -1351,7 +1352,7 @@ enum tep_errno tep_filter_add_filter_str(struct event_filter *filter,
1351 return rtn; 1352 return rtn;
1352} 1353}
1353 1354
1354static void free_filter_type(struct filter_type *filter_type) 1355static void free_filter_type(struct tep_filter_type *filter_type)
1355{ 1356{
1356 free_arg(filter_type->filter); 1357 free_arg(filter_type->filter);
1357} 1358}
@@ -1365,7 +1366,7 @@ static void free_filter_type(struct filter_type *filter_type)
1365 * 1366 *
1366 * Returns 0 if message was filled successfully, -1 if error 1367 * Returns 0 if message was filled successfully, -1 if error
1367 */ 1368 */
1368int tep_filter_strerror(struct event_filter *filter, enum tep_errno err, 1369int tep_filter_strerror(struct tep_event_filter *filter, enum tep_errno err,
1369 char *buf, size_t buflen) 1370 char *buf, size_t buflen)
1370{ 1371{
1371 if (err <= __TEP_ERRNO__START || err >= __TEP_ERRNO__END) 1372 if (err <= __TEP_ERRNO__START || err >= __TEP_ERRNO__END)
@@ -1393,10 +1394,10 @@ int tep_filter_strerror(struct event_filter *filter, enum tep_errno err,
1393 * Returns 1: if an event was removed 1394 * Returns 1: if an event was removed
1394 * 0: if the event was not found 1395 * 0: if the event was not found
1395 */ 1396 */
1396int tep_filter_remove_event(struct event_filter *filter, 1397int tep_filter_remove_event(struct tep_event_filter *filter,
1397 int event_id) 1398 int event_id)
1398{ 1399{
1399 struct filter_type *filter_type; 1400 struct tep_filter_type *filter_type;
1400 unsigned long len; 1401 unsigned long len;
1401 1402
1402 if (!filter->filters) 1403 if (!filter->filters)
@@ -1428,7 +1429,7 @@ int tep_filter_remove_event(struct event_filter *filter,
1428 * 1429 *
1429 * Removes all filters from a filter and resets it. 1430 * Removes all filters from a filter and resets it.
1430 */ 1431 */
1431void tep_filter_reset(struct event_filter *filter) 1432void tep_filter_reset(struct tep_event_filter *filter)
1432{ 1433{
1433 int i; 1434 int i;
1434 1435
@@ -1440,7 +1441,7 @@ void tep_filter_reset(struct event_filter *filter)
1440 filter->event_filters = NULL; 1441 filter->event_filters = NULL;
1441} 1442}
1442 1443
1443void tep_filter_free(struct event_filter *filter) 1444void tep_filter_free(struct tep_event_filter *filter)
1444{ 1445{
1445 tep_unref(filter->pevent); 1446 tep_unref(filter->pevent);
1446 1447
@@ -1449,14 +1450,14 @@ void tep_filter_free(struct event_filter *filter)
1449 free(filter); 1450 free(filter);
1450} 1451}
1451 1452
1452static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg); 1453static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg);
1453 1454
1454static int copy_filter_type(struct event_filter *filter, 1455static int copy_filter_type(struct tep_event_filter *filter,
1455 struct event_filter *source, 1456 struct tep_event_filter *source,
1456 struct filter_type *filter_type) 1457 struct tep_filter_type *filter_type)
1457{ 1458{
1458 struct filter_arg *arg; 1459 struct tep_filter_arg *arg;
1459 struct event_format *event; 1460 struct tep_event_format *event;
1460 const char *sys; 1461 const char *sys;
1461 const char *name; 1462 const char *name;
1462 char *str; 1463 char *str;
@@ -1478,7 +1479,7 @@ static int copy_filter_type(struct event_filter *filter,
1478 if (arg == NULL) 1479 if (arg == NULL)
1479 return -1; 1480 return -1;
1480 1481
1481 arg->type = FILTER_ARG_BOOLEAN; 1482 arg->type = TEP_FILTER_ARG_BOOLEAN;
1482 if (strcmp(str, "TRUE") == 0) 1483 if (strcmp(str, "TRUE") == 0)
1483 arg->boolean.value = 1; 1484 arg->boolean.value = 1;
1484 else 1485 else
@@ -1507,7 +1508,7 @@ static int copy_filter_type(struct event_filter *filter,
1507 * 1508 *
1508 * Returns 0 on success and -1 if not all filters were copied 1509 * Returns 0 on success and -1 if not all filters were copied
1509 */ 1510 */
1510int tep_filter_copy(struct event_filter *dest, struct event_filter *source) 1511int tep_filter_copy(struct tep_event_filter *dest, struct tep_event_filter *source)
1511{ 1512{
1512 int ret = 0; 1513 int ret = 0;
1513 int i; 1514 int i;
@@ -1533,14 +1534,14 @@ int tep_filter_copy(struct event_filter *dest, struct event_filter *source)
1533 * Returns 0 on success and -1 if there was a problem updating, but 1534 * Returns 0 on success and -1 if there was a problem updating, but
1534 * events may have still been updated on error. 1535 * events may have still been updated on error.
1535 */ 1536 */
1536int tep_update_trivial(struct event_filter *dest, struct event_filter *source, 1537int tep_update_trivial(struct tep_event_filter *dest, struct tep_event_filter *source,
1537 enum filter_trivial_type type) 1538 enum tep_filter_trivial_type type)
1538{ 1539{
1539 struct tep_handle *src_pevent; 1540 struct tep_handle *src_pevent;
1540 struct tep_handle *dest_pevent; 1541 struct tep_handle *dest_pevent;
1541 struct event_format *event; 1542 struct tep_event_format *event;
1542 struct filter_type *filter_type; 1543 struct tep_filter_type *filter_type;
1543 struct filter_arg *arg; 1544 struct tep_filter_arg *arg;
1544 char *str; 1545 char *str;
1545 int i; 1546 int i;
1546 1547
@@ -1554,10 +1555,10 @@ int tep_update_trivial(struct event_filter *dest, struct event_filter *source,
1554 for (i = 0; i < dest->filters; i++) { 1555 for (i = 0; i < dest->filters; i++) {
1555 filter_type = &dest->event_filters[i]; 1556 filter_type = &dest->event_filters[i];
1556 arg = filter_type->filter; 1557 arg = filter_type->filter;
1557 if (arg->type != FILTER_ARG_BOOLEAN) 1558 if (arg->type != TEP_FILTER_ARG_BOOLEAN)
1558 continue; 1559 continue;
1559 if ((arg->boolean.value && type == FILTER_TRIVIAL_FALSE) || 1560 if ((arg->boolean.value && type == TEP_FILTER_TRIVIAL_FALSE) ||
1560 (!arg->boolean.value && type == FILTER_TRIVIAL_TRUE)) 1561 (!arg->boolean.value && type == TEP_FILTER_TRIVIAL_TRUE))
1561 continue; 1562 continue;
1562 1563
1563 event = filter_type->event; 1564 event = filter_type->event;
@@ -1592,10 +1593,10 @@ int tep_update_trivial(struct event_filter *dest, struct event_filter *source,
1592 * 1593 *
1593 * Returns 0 on success and -1 if there was a problem. 1594 * Returns 0 on success and -1 if there was a problem.
1594 */ 1595 */
1595int tep_filter_clear_trivial(struct event_filter *filter, 1596int tep_filter_clear_trivial(struct tep_event_filter *filter,
1596 enum filter_trivial_type type) 1597 enum tep_filter_trivial_type type)
1597{ 1598{
1598 struct filter_type *filter_type; 1599 struct tep_filter_type *filter_type;
1599 int count = 0; 1600 int count = 0;
1600 int *ids = NULL; 1601 int *ids = NULL;
1601 int i; 1602 int i;
@@ -1611,14 +1612,14 @@ int tep_filter_clear_trivial(struct event_filter *filter,
1611 int *new_ids; 1612 int *new_ids;
1612 1613
1613 filter_type = &filter->event_filters[i]; 1614 filter_type = &filter->event_filters[i];
1614 if (filter_type->filter->type != FILTER_ARG_BOOLEAN) 1615 if (filter_type->filter->type != TEP_FILTER_ARG_BOOLEAN)
1615 continue; 1616 continue;
1616 switch (type) { 1617 switch (type) {
1617 case FILTER_TRIVIAL_FALSE: 1618 case TEP_FILTER_TRIVIAL_FALSE:
1618 if (filter_type->filter->boolean.value) 1619 if (filter_type->filter->boolean.value)
1619 continue; 1620 continue;
1620 break; 1621 break;
1621 case FILTER_TRIVIAL_TRUE: 1622 case TEP_FILTER_TRIVIAL_TRUE:
1622 if (!filter_type->filter->boolean.value) 1623 if (!filter_type->filter->boolean.value)
1623 continue; 1624 continue;
1624 default: 1625 default:
@@ -1654,11 +1655,11 @@ int tep_filter_clear_trivial(struct event_filter *filter,
1654 * Returns 1 if the event contains a matching trivial type 1655 * Returns 1 if the event contains a matching trivial type
1655 * otherwise 0. 1656 * otherwise 0.
1656 */ 1657 */
1657int tep_filter_event_has_trivial(struct event_filter *filter, 1658int tep_filter_event_has_trivial(struct tep_event_filter *filter,
1658 int event_id, 1659 int event_id,
1659 enum filter_trivial_type type) 1660 enum tep_filter_trivial_type type)
1660{ 1661{
1661 struct filter_type *filter_type; 1662 struct tep_filter_type *filter_type;
1662 1663
1663 if (!filter->filters) 1664 if (!filter->filters)
1664 return 0; 1665 return 0;
@@ -1668,25 +1669,25 @@ int tep_filter_event_has_trivial(struct event_filter *filter,
1668 if (!filter_type) 1669 if (!filter_type)
1669 return 0; 1670 return 0;
1670 1671
1671 if (filter_type->filter->type != FILTER_ARG_BOOLEAN) 1672 if (filter_type->filter->type != TEP_FILTER_ARG_BOOLEAN)
1672 return 0; 1673 return 0;
1673 1674
1674 switch (type) { 1675 switch (type) {
1675 case FILTER_TRIVIAL_FALSE: 1676 case TEP_FILTER_TRIVIAL_FALSE:
1676 return !filter_type->filter->boolean.value; 1677 return !filter_type->filter->boolean.value;
1677 1678
1678 case FILTER_TRIVIAL_TRUE: 1679 case TEP_FILTER_TRIVIAL_TRUE:
1679 return filter_type->filter->boolean.value; 1680 return filter_type->filter->boolean.value;
1680 default: 1681 default:
1681 return 1; 1682 return 1;
1682 } 1683 }
1683} 1684}
1684 1685
1685static int test_filter(struct event_format *event, struct filter_arg *arg, 1686static int test_filter(struct tep_event_format *event, struct tep_filter_arg *arg,
1686 struct tep_record *record, enum tep_errno *err); 1687 struct tep_record *record, enum tep_errno *err);
1687 1688
1688static const char * 1689static const char *
1689get_comm(struct event_format *event, struct tep_record *record) 1690get_comm(struct tep_event_format *event, struct tep_record *record)
1690{ 1691{
1691 const char *comm; 1692 const char *comm;
1692 int pid; 1693 int pid;
@@ -1697,8 +1698,8 @@ get_comm(struct event_format *event, struct tep_record *record)
1697} 1698}
1698 1699
1699static unsigned long long 1700static unsigned long long
1700get_value(struct event_format *event, 1701get_value(struct tep_event_format *event,
1701 struct format_field *field, struct tep_record *record) 1702 struct tep_format_field *field, struct tep_record *record)
1702{ 1703{
1703 unsigned long long val; 1704 unsigned long long val;
1704 1705
@@ -1716,7 +1717,7 @@ get_value(struct event_format *event,
1716 1717
1717 tep_read_number_field(field, record->data, &val); 1718 tep_read_number_field(field, record->data, &val);
1718 1719
1719 if (!(field->flags & FIELD_IS_SIGNED)) 1720 if (!(field->flags & TEP_FIELD_IS_SIGNED))
1720 return val; 1721 return val;
1721 1722
1722 switch (field->size) { 1723 switch (field->size) {
@@ -1733,11 +1734,11 @@ get_value(struct event_format *event,
1733} 1734}
1734 1735
1735static unsigned long long 1736static unsigned long long
1736get_arg_value(struct event_format *event, struct filter_arg *arg, 1737get_arg_value(struct tep_event_format *event, struct tep_filter_arg *arg,
1737 struct tep_record *record, enum tep_errno *err); 1738 struct tep_record *record, enum tep_errno *err);
1738 1739
1739static unsigned long long 1740static unsigned long long
1740get_exp_value(struct event_format *event, struct filter_arg *arg, 1741get_exp_value(struct tep_event_format *event, struct tep_filter_arg *arg,
1741 struct tep_record *record, enum tep_errno *err) 1742 struct tep_record *record, enum tep_errno *err)
1742{ 1743{
1743 unsigned long long lval, rval; 1744 unsigned long long lval, rval;
@@ -1753,37 +1754,37 @@ get_exp_value(struct event_format *event, struct filter_arg *arg,
1753 } 1754 }
1754 1755
1755 switch (arg->exp.type) { 1756 switch (arg->exp.type) {
1756 case FILTER_EXP_ADD: 1757 case TEP_FILTER_EXP_ADD:
1757 return lval + rval; 1758 return lval + rval;
1758 1759
1759 case FILTER_EXP_SUB: 1760 case TEP_FILTER_EXP_SUB:
1760 return lval - rval; 1761 return lval - rval;
1761 1762
1762 case FILTER_EXP_MUL: 1763 case TEP_FILTER_EXP_MUL:
1763 return lval * rval; 1764 return lval * rval;
1764 1765
1765 case FILTER_EXP_DIV: 1766 case TEP_FILTER_EXP_DIV:
1766 return lval / rval; 1767 return lval / rval;
1767 1768
1768 case FILTER_EXP_MOD: 1769 case TEP_FILTER_EXP_MOD:
1769 return lval % rval; 1770 return lval % rval;
1770 1771
1771 case FILTER_EXP_RSHIFT: 1772 case TEP_FILTER_EXP_RSHIFT:
1772 return lval >> rval; 1773 return lval >> rval;
1773 1774
1774 case FILTER_EXP_LSHIFT: 1775 case TEP_FILTER_EXP_LSHIFT:
1775 return lval << rval; 1776 return lval << rval;
1776 1777
1777 case FILTER_EXP_AND: 1778 case TEP_FILTER_EXP_AND:
1778 return lval & rval; 1779 return lval & rval;
1779 1780
1780 case FILTER_EXP_OR: 1781 case TEP_FILTER_EXP_OR:
1781 return lval | rval; 1782 return lval | rval;
1782 1783
1783 case FILTER_EXP_XOR: 1784 case TEP_FILTER_EXP_XOR:
1784 return lval ^ rval; 1785 return lval ^ rval;
1785 1786
1786 case FILTER_EXP_NOT: 1787 case TEP_FILTER_EXP_NOT:
1787 default: 1788 default:
1788 if (!*err) 1789 if (!*err)
1789 *err = TEP_ERRNO__INVALID_EXP_TYPE; 1790 *err = TEP_ERRNO__INVALID_EXP_TYPE;
@@ -1792,21 +1793,21 @@ get_exp_value(struct event_format *event, struct filter_arg *arg,
1792} 1793}
1793 1794
1794static unsigned long long 1795static unsigned long long
1795get_arg_value(struct event_format *event, struct filter_arg *arg, 1796get_arg_value(struct tep_event_format *event, struct tep_filter_arg *arg,
1796 struct tep_record *record, enum tep_errno *err) 1797 struct tep_record *record, enum tep_errno *err)
1797{ 1798{
1798 switch (arg->type) { 1799 switch (arg->type) {
1799 case FILTER_ARG_FIELD: 1800 case TEP_FILTER_ARG_FIELD:
1800 return get_value(event, arg->field.field, record); 1801 return get_value(event, arg->field.field, record);
1801 1802
1802 case FILTER_ARG_VALUE: 1803 case TEP_FILTER_ARG_VALUE:
1803 if (arg->value.type != FILTER_NUMBER) { 1804 if (arg->value.type != TEP_FILTER_NUMBER) {
1804 if (!*err) 1805 if (!*err)
1805 *err = TEP_ERRNO__NOT_A_NUMBER; 1806 *err = TEP_ERRNO__NOT_A_NUMBER;
1806 } 1807 }
1807 return arg->value.val; 1808 return arg->value.val;
1808 1809
1809 case FILTER_ARG_EXP: 1810 case TEP_FILTER_ARG_EXP:
1810 return get_exp_value(event, arg, record, err); 1811 return get_exp_value(event, arg, record, err);
1811 1812
1812 default: 1813 default:
@@ -1816,7 +1817,7 @@ get_arg_value(struct event_format *event, struct filter_arg *arg,
1816 return 0; 1817 return 0;
1817} 1818}
1818 1819
1819static int test_num(struct event_format *event, struct filter_arg *arg, 1820static int test_num(struct tep_event_format *event, struct tep_filter_arg *arg,
1820 struct tep_record *record, enum tep_errno *err) 1821 struct tep_record *record, enum tep_errno *err)
1821{ 1822{
1822 unsigned long long lval, rval; 1823 unsigned long long lval, rval;
@@ -1832,22 +1833,22 @@ static int test_num(struct event_format *event, struct filter_arg *arg,
1832 } 1833 }
1833 1834
1834 switch (arg->num.type) { 1835 switch (arg->num.type) {
1835 case FILTER_CMP_EQ: 1836 case TEP_FILTER_CMP_EQ:
1836 return lval == rval; 1837 return lval == rval;
1837 1838
1838 case FILTER_CMP_NE: 1839 case TEP_FILTER_CMP_NE:
1839 return lval != rval; 1840 return lval != rval;
1840 1841
1841 case FILTER_CMP_GT: 1842 case TEP_FILTER_CMP_GT:
1842 return lval > rval; 1843 return lval > rval;
1843 1844
1844 case FILTER_CMP_LT: 1845 case TEP_FILTER_CMP_LT:
1845 return lval < rval; 1846 return lval < rval;
1846 1847
1847 case FILTER_CMP_GE: 1848 case TEP_FILTER_CMP_GE:
1848 return lval >= rval; 1849 return lval >= rval;
1849 1850
1850 case FILTER_CMP_LE: 1851 case TEP_FILTER_CMP_LE:
1851 return lval <= rval; 1852 return lval <= rval;
1852 1853
1853 default: 1854 default:
@@ -1857,9 +1858,9 @@ static int test_num(struct event_format *event, struct filter_arg *arg,
1857 } 1858 }
1858} 1859}
1859 1860
1860static const char *get_field_str(struct filter_arg *arg, struct tep_record *record) 1861static const char *get_field_str(struct tep_filter_arg *arg, struct tep_record *record)
1861{ 1862{
1862 struct event_format *event; 1863 struct tep_event_format *event;
1863 struct tep_handle *pevent; 1864 struct tep_handle *pevent;
1864 unsigned long long addr; 1865 unsigned long long addr;
1865 const char *val = NULL; 1866 const char *val = NULL;
@@ -1867,11 +1868,11 @@ static const char *get_field_str(struct filter_arg *arg, struct tep_record *reco
1867 char hex[64]; 1868 char hex[64];
1868 1869
1869 /* If the field is not a string convert it */ 1870 /* If the field is not a string convert it */
1870 if (arg->str.field->flags & FIELD_IS_STRING) { 1871 if (arg->str.field->flags & TEP_FIELD_IS_STRING) {
1871 val = record->data + arg->str.field->offset; 1872 val = record->data + arg->str.field->offset;
1872 size = arg->str.field->size; 1873 size = arg->str.field->size;
1873 1874
1874 if (arg->str.field->flags & FIELD_IS_DYNAMIC) { 1875 if (arg->str.field->flags & TEP_FIELD_IS_DYNAMIC) {
1875 addr = *(unsigned int *)val; 1876 addr = *(unsigned int *)val;
1876 val = record->data + (addr & 0xffff); 1877 val = record->data + (addr & 0xffff);
1877 size = addr >> 16; 1878 size = addr >> 16;
@@ -1893,7 +1894,7 @@ static const char *get_field_str(struct filter_arg *arg, struct tep_record *reco
1893 pevent = event->pevent; 1894 pevent = event->pevent;
1894 addr = get_value(event, arg->str.field, record); 1895 addr = get_value(event, arg->str.field, record);
1895 1896
1896 if (arg->str.field->flags & (FIELD_IS_POINTER | FIELD_IS_LONG)) 1897 if (arg->str.field->flags & (TEP_FIELD_IS_POINTER | TEP_FIELD_IS_LONG))
1897 /* convert to a kernel symbol */ 1898 /* convert to a kernel symbol */
1898 val = tep_find_function(pevent, addr); 1899 val = tep_find_function(pevent, addr);
1899 1900
@@ -1907,7 +1908,7 @@ static const char *get_field_str(struct filter_arg *arg, struct tep_record *reco
1907 return val; 1908 return val;
1908} 1909}
1909 1910
1910static int test_str(struct event_format *event, struct filter_arg *arg, 1911static int test_str(struct tep_event_format *event, struct tep_filter_arg *arg,
1911 struct tep_record *record, enum tep_errno *err) 1912 struct tep_record *record, enum tep_errno *err)
1912{ 1913{
1913 const char *val; 1914 const char *val;
@@ -1918,17 +1919,17 @@ static int test_str(struct event_format *event, struct filter_arg *arg,
1918 val = get_field_str(arg, record); 1919 val = get_field_str(arg, record);
1919 1920
1920 switch (arg->str.type) { 1921 switch (arg->str.type) {
1921 case FILTER_CMP_MATCH: 1922 case TEP_FILTER_CMP_MATCH:
1922 return strcmp(val, arg->str.val) == 0; 1923 return strcmp(val, arg->str.val) == 0;
1923 1924
1924 case FILTER_CMP_NOT_MATCH: 1925 case TEP_FILTER_CMP_NOT_MATCH:
1925 return strcmp(val, arg->str.val) != 0; 1926 return strcmp(val, arg->str.val) != 0;
1926 1927
1927 case FILTER_CMP_REGEX: 1928 case TEP_FILTER_CMP_REGEX:
1928 /* Returns zero on match */ 1929 /* Returns zero on match */
1929 return !regexec(&arg->str.reg, val, 0, NULL, 0); 1930 return !regexec(&arg->str.reg, val, 0, NULL, 0);
1930 1931
1931 case FILTER_CMP_NOT_REGEX: 1932 case TEP_FILTER_CMP_NOT_REGEX:
1932 return regexec(&arg->str.reg, val, 0, NULL, 0); 1933 return regexec(&arg->str.reg, val, 0, NULL, 0);
1933 1934
1934 default: 1935 default:
@@ -1938,19 +1939,19 @@ static int test_str(struct event_format *event, struct filter_arg *arg,
1938 } 1939 }
1939} 1940}
1940 1941
1941static int test_op(struct event_format *event, struct filter_arg *arg, 1942static int test_op(struct tep_event_format *event, struct tep_filter_arg *arg,
1942 struct tep_record *record, enum tep_errno *err) 1943 struct tep_record *record, enum tep_errno *err)
1943{ 1944{
1944 switch (arg->op.type) { 1945 switch (arg->op.type) {
1945 case FILTER_OP_AND: 1946 case TEP_FILTER_OP_AND:
1946 return test_filter(event, arg->op.left, record, err) && 1947 return test_filter(event, arg->op.left, record, err) &&
1947 test_filter(event, arg->op.right, record, err); 1948 test_filter(event, arg->op.right, record, err);
1948 1949
1949 case FILTER_OP_OR: 1950 case TEP_FILTER_OP_OR:
1950 return test_filter(event, arg->op.left, record, err) || 1951 return test_filter(event, arg->op.left, record, err) ||
1951 test_filter(event, arg->op.right, record, err); 1952 test_filter(event, arg->op.right, record, err);
1952 1953
1953 case FILTER_OP_NOT: 1954 case TEP_FILTER_OP_NOT:
1954 return !test_filter(event, arg->op.right, record, err); 1955 return !test_filter(event, arg->op.right, record, err);
1955 1956
1956 default: 1957 default:
@@ -1960,7 +1961,7 @@ static int test_op(struct event_format *event, struct filter_arg *arg,
1960 } 1961 }
1961} 1962}
1962 1963
1963static int test_filter(struct event_format *event, struct filter_arg *arg, 1964static int test_filter(struct tep_event_format *event, struct tep_filter_arg *arg,
1964 struct tep_record *record, enum tep_errno *err) 1965 struct tep_record *record, enum tep_errno *err)
1965{ 1966{
1966 if (*err) { 1967 if (*err) {
@@ -1971,22 +1972,22 @@ static int test_filter(struct event_format *event, struct filter_arg *arg,
1971 } 1972 }
1972 1973
1973 switch (arg->type) { 1974 switch (arg->type) {
1974 case FILTER_ARG_BOOLEAN: 1975 case TEP_FILTER_ARG_BOOLEAN:
1975 /* easy case */ 1976 /* easy case */
1976 return arg->boolean.value; 1977 return arg->boolean.value;
1977 1978
1978 case FILTER_ARG_OP: 1979 case TEP_FILTER_ARG_OP:
1979 return test_op(event, arg, record, err); 1980 return test_op(event, arg, record, err);
1980 1981
1981 case FILTER_ARG_NUM: 1982 case TEP_FILTER_ARG_NUM:
1982 return test_num(event, arg, record, err); 1983 return test_num(event, arg, record, err);
1983 1984
1984 case FILTER_ARG_STR: 1985 case TEP_FILTER_ARG_STR:
1985 return test_str(event, arg, record, err); 1986 return test_str(event, arg, record, err);
1986 1987
1987 case FILTER_ARG_EXP: 1988 case TEP_FILTER_ARG_EXP:
1988 case FILTER_ARG_VALUE: 1989 case TEP_FILTER_ARG_VALUE:
1989 case FILTER_ARG_FIELD: 1990 case TEP_FILTER_ARG_FIELD:
1990 /* 1991 /*
1991 * Expressions, fields and values evaluate 1992 * Expressions, fields and values evaluate
1992 * to true if they return non zero 1993 * to true if they return non zero
@@ -2008,9 +2009,9 @@ static int test_filter(struct event_format *event, struct filter_arg *arg,
2008 * Returns 1 if filter found for @event_id 2009 * Returns 1 if filter found for @event_id
2009 * otherwise 0; 2010 * otherwise 0;
2010 */ 2011 */
2011int tep_event_filtered(struct event_filter *filter, int event_id) 2012int tep_event_filtered(struct tep_event_filter *filter, int event_id)
2012{ 2013{
2013 struct filter_type *filter_type; 2014 struct tep_filter_type *filter_type;
2014 2015
2015 if (!filter->filters) 2016 if (!filter->filters)
2016 return 0; 2017 return 0;
@@ -2032,11 +2033,11 @@ int tep_event_filtered(struct event_filter *filter, int event_id)
2032 * NO_FILTER - if no filters exist 2033 * NO_FILTER - if no filters exist
2033 * otherwise - error occurred during test 2034 * otherwise - error occurred during test
2034 */ 2035 */
2035enum tep_errno tep_filter_match(struct event_filter *filter, 2036enum tep_errno tep_filter_match(struct tep_event_filter *filter,
2036 struct tep_record *record) 2037 struct tep_record *record)
2037{ 2038{
2038 struct tep_handle *pevent = filter->pevent; 2039 struct tep_handle *pevent = filter->pevent;
2039 struct filter_type *filter_type; 2040 struct tep_filter_type *filter_type;
2040 int event_id; 2041 int event_id;
2041 int ret; 2042 int ret;
2042 enum tep_errno err = 0; 2043 enum tep_errno err = 0;
@@ -2059,7 +2060,7 @@ enum tep_errno tep_filter_match(struct event_filter *filter,
2059 return ret ? TEP_ERRNO__FILTER_MATCH : TEP_ERRNO__FILTER_MISS; 2060 return ret ? TEP_ERRNO__FILTER_MATCH : TEP_ERRNO__FILTER_MISS;
2060} 2061}
2061 2062
2062static char *op_to_str(struct event_filter *filter, struct filter_arg *arg) 2063static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg)
2063{ 2064{
2064 char *str = NULL; 2065 char *str = NULL;
2065 char *left = NULL; 2066 char *left = NULL;
@@ -2070,10 +2071,10 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
2070 int val; 2071 int val;
2071 2072
2072 switch (arg->op.type) { 2073 switch (arg->op.type) {
2073 case FILTER_OP_AND: 2074 case TEP_FILTER_OP_AND:
2074 op = "&&"; 2075 op = "&&";
2075 /* fall through */ 2076 /* fall through */
2076 case FILTER_OP_OR: 2077 case TEP_FILTER_OP_OR:
2077 if (!op) 2078 if (!op)
2078 op = "||"; 2079 op = "||";
2079 2080
@@ -2094,8 +2095,8 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
2094 right_val = 0; 2095 right_val = 0;
2095 2096
2096 if (left_val >= 0) { 2097 if (left_val >= 0) {
2097 if ((arg->op.type == FILTER_OP_AND && !left_val) || 2098 if ((arg->op.type == TEP_FILTER_OP_AND && !left_val) ||
2098 (arg->op.type == FILTER_OP_OR && left_val)) { 2099 (arg->op.type == TEP_FILTER_OP_OR && left_val)) {
2099 /* Just return left value */ 2100 /* Just return left value */
2100 str = left; 2101 str = left;
2101 left = NULL; 2102 left = NULL;
@@ -2105,10 +2106,10 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
2105 /* just evaluate this. */ 2106 /* just evaluate this. */
2106 val = 0; 2107 val = 0;
2107 switch (arg->op.type) { 2108 switch (arg->op.type) {
2108 case FILTER_OP_AND: 2109 case TEP_FILTER_OP_AND:
2109 val = left_val && right_val; 2110 val = left_val && right_val;
2110 break; 2111 break;
2111 case FILTER_OP_OR: 2112 case TEP_FILTER_OP_OR:
2112 val = left_val || right_val; 2113 val = left_val || right_val;
2113 break; 2114 break;
2114 default: 2115 default:
@@ -2119,8 +2120,8 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
2119 } 2120 }
2120 } 2121 }
2121 if (right_val >= 0) { 2122 if (right_val >= 0) {
2122 if ((arg->op.type == FILTER_OP_AND && !right_val) || 2123 if ((arg->op.type == TEP_FILTER_OP_AND && !right_val) ||
2123 (arg->op.type == FILTER_OP_OR && right_val)) { 2124 (arg->op.type == TEP_FILTER_OP_OR && right_val)) {
2124 /* Just return right value */ 2125 /* Just return right value */
2125 str = right; 2126 str = right;
2126 right = NULL; 2127 right = NULL;
@@ -2135,7 +2136,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
2135 asprintf(&str, "(%s) %s (%s)", left, op, right); 2136 asprintf(&str, "(%s) %s (%s)", left, op, right);
2136 break; 2137 break;
2137 2138
2138 case FILTER_OP_NOT: 2139 case TEP_FILTER_OP_NOT:
2139 op = "!"; 2140 op = "!";
2140 right = arg_to_str(filter, arg->op.right); 2141 right = arg_to_str(filter, arg->op.right);
2141 if (!right) 2142 if (!right)
@@ -2163,7 +2164,7 @@ static char *op_to_str(struct event_filter *filter, struct filter_arg *arg)
2163 return str; 2164 return str;
2164} 2165}
2165 2166
2166static char *val_to_str(struct event_filter *filter, struct filter_arg *arg) 2167static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg)
2167{ 2168{
2168 char *str = NULL; 2169 char *str = NULL;
2169 2170
@@ -2172,12 +2173,12 @@ static char *val_to_str(struct event_filter *filter, struct filter_arg *arg)
2172 return str; 2173 return str;
2173} 2174}
2174 2175
2175static char *field_to_str(struct event_filter *filter, struct filter_arg *arg) 2176static char *field_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg)
2176{ 2177{
2177 return strdup(arg->field.field->name); 2178 return strdup(arg->field.field->name);
2178} 2179}
2179 2180
2180static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg) 2181static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg)
2181{ 2182{
2182 char *lstr; 2183 char *lstr;
2183 char *rstr; 2184 char *rstr;
@@ -2190,34 +2191,34 @@ static char *exp_to_str(struct event_filter *filter, struct filter_arg *arg)
2190 goto out; 2191 goto out;
2191 2192
2192 switch (arg->exp.type) { 2193 switch (arg->exp.type) {
2193 case FILTER_EXP_ADD: 2194 case TEP_FILTER_EXP_ADD:
2194 op = "+"; 2195 op = "+";
2195 break; 2196 break;
2196 case FILTER_EXP_SUB: 2197 case TEP_FILTER_EXP_SUB:
2197 op = "-"; 2198 op = "-";
2198 break; 2199 break;
2199 case FILTER_EXP_MUL: 2200 case TEP_FILTER_EXP_MUL:
2200 op = "*"; 2201 op = "*";
2201 break; 2202 break;
2202 case FILTER_EXP_DIV: 2203 case TEP_FILTER_EXP_DIV:
2203 op = "/"; 2204 op = "/";
2204 break; 2205 break;
2205 case FILTER_EXP_MOD: 2206 case TEP_FILTER_EXP_MOD:
2206 op = "%"; 2207 op = "%";
2207 break; 2208 break;
2208 case FILTER_EXP_RSHIFT: 2209 case TEP_FILTER_EXP_RSHIFT:
2209 op = ">>"; 2210 op = ">>";
2210 break; 2211 break;
2211 case FILTER_EXP_LSHIFT: 2212 case TEP_FILTER_EXP_LSHIFT:
2212 op = "<<"; 2213 op = "<<";
2213 break; 2214 break;
2214 case FILTER_EXP_AND: 2215 case TEP_FILTER_EXP_AND:
2215 op = "&"; 2216 op = "&";
2216 break; 2217 break;
2217 case FILTER_EXP_OR: 2218 case TEP_FILTER_EXP_OR:
2218 op = "|"; 2219 op = "|";
2219 break; 2220 break;
2220 case FILTER_EXP_XOR: 2221 case TEP_FILTER_EXP_XOR:
2221 op = "^"; 2222 op = "^";
2222 break; 2223 break;
2223 default: 2224 default:
@@ -2233,7 +2234,7 @@ out:
2233 return str; 2234 return str;
2234} 2235}
2235 2236
2236static char *num_to_str(struct event_filter *filter, struct filter_arg *arg) 2237static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg)
2237{ 2238{
2238 char *lstr; 2239 char *lstr;
2239 char *rstr; 2240 char *rstr;
@@ -2246,26 +2247,26 @@ static char *num_to_str(struct event_filter *filter, struct filter_arg *arg)
2246 goto out; 2247 goto out;
2247 2248
2248 switch (arg->num.type) { 2249 switch (arg->num.type) {
2249 case FILTER_CMP_EQ: 2250 case TEP_FILTER_CMP_EQ:
2250 op = "=="; 2251 op = "==";
2251 /* fall through */ 2252 /* fall through */
2252 case FILTER_CMP_NE: 2253 case TEP_FILTER_CMP_NE:
2253 if (!op) 2254 if (!op)
2254 op = "!="; 2255 op = "!=";
2255 /* fall through */ 2256 /* fall through */
2256 case FILTER_CMP_GT: 2257 case TEP_FILTER_CMP_GT:
2257 if (!op) 2258 if (!op)
2258 op = ">"; 2259 op = ">";
2259 /* fall through */ 2260 /* fall through */
2260 case FILTER_CMP_LT: 2261 case TEP_FILTER_CMP_LT:
2261 if (!op) 2262 if (!op)
2262 op = "<"; 2263 op = "<";
2263 /* fall through */ 2264 /* fall through */
2264 case FILTER_CMP_GE: 2265 case TEP_FILTER_CMP_GE:
2265 if (!op) 2266 if (!op)
2266 op = ">="; 2267 op = ">=";
2267 /* fall through */ 2268 /* fall through */
2268 case FILTER_CMP_LE: 2269 case TEP_FILTER_CMP_LE:
2269 if (!op) 2270 if (!op)
2270 op = "<="; 2271 op = "<=";
2271 2272
@@ -2283,24 +2284,24 @@ out:
2283 return str; 2284 return str;
2284} 2285}
2285 2286
2286static char *str_to_str(struct event_filter *filter, struct filter_arg *arg) 2287static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg)
2287{ 2288{
2288 char *str = NULL; 2289 char *str = NULL;
2289 char *op = NULL; 2290 char *op = NULL;
2290 2291
2291 switch (arg->str.type) { 2292 switch (arg->str.type) {
2292 case FILTER_CMP_MATCH: 2293 case TEP_FILTER_CMP_MATCH:
2293 op = "=="; 2294 op = "==";
2294 /* fall through */ 2295 /* fall through */
2295 case FILTER_CMP_NOT_MATCH: 2296 case TEP_FILTER_CMP_NOT_MATCH:
2296 if (!op) 2297 if (!op)
2297 op = "!="; 2298 op = "!=";
2298 /* fall through */ 2299 /* fall through */
2299 case FILTER_CMP_REGEX: 2300 case TEP_FILTER_CMP_REGEX:
2300 if (!op) 2301 if (!op)
2301 op = "=~"; 2302 op = "=~";
2302 /* fall through */ 2303 /* fall through */
2303 case FILTER_CMP_NOT_REGEX: 2304 case TEP_FILTER_CMP_NOT_REGEX:
2304 if (!op) 2305 if (!op)
2305 op = "!~"; 2306 op = "!~";
2306 2307
@@ -2315,31 +2316,31 @@ static char *str_to_str(struct event_filter *filter, struct filter_arg *arg)
2315 return str; 2316 return str;
2316} 2317}
2317 2318
2318static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg) 2319static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg *arg)
2319{ 2320{
2320 char *str = NULL; 2321 char *str = NULL;
2321 2322
2322 switch (arg->type) { 2323 switch (arg->type) {
2323 case FILTER_ARG_BOOLEAN: 2324 case TEP_FILTER_ARG_BOOLEAN:
2324 asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE"); 2325 asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE");
2325 return str; 2326 return str;
2326 2327
2327 case FILTER_ARG_OP: 2328 case TEP_FILTER_ARG_OP:
2328 return op_to_str(filter, arg); 2329 return op_to_str(filter, arg);
2329 2330
2330 case FILTER_ARG_NUM: 2331 case TEP_FILTER_ARG_NUM:
2331 return num_to_str(filter, arg); 2332 return num_to_str(filter, arg);
2332 2333
2333 case FILTER_ARG_STR: 2334 case TEP_FILTER_ARG_STR:
2334 return str_to_str(filter, arg); 2335 return str_to_str(filter, arg);
2335 2336
2336 case FILTER_ARG_VALUE: 2337 case TEP_FILTER_ARG_VALUE:
2337 return val_to_str(filter, arg); 2338 return val_to_str(filter, arg);
2338 2339
2339 case FILTER_ARG_FIELD: 2340 case TEP_FILTER_ARG_FIELD:
2340 return field_to_str(filter, arg); 2341 return field_to_str(filter, arg);
2341 2342
2342 case FILTER_ARG_EXP: 2343 case TEP_FILTER_ARG_EXP:
2343 return exp_to_str(filter, arg); 2344 return exp_to_str(filter, arg);
2344 2345
2345 default: 2346 default:
@@ -2359,9 +2360,9 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg)
2359 * NULL is returned if no filter is found or allocation failed. 2360 * NULL is returned if no filter is found or allocation failed.
2360 */ 2361 */
2361char * 2362char *
2362tep_filter_make_string(struct event_filter *filter, int event_id) 2363tep_filter_make_string(struct tep_event_filter *filter, int event_id)
2363{ 2364{
2364 struct filter_type *filter_type; 2365 struct tep_filter_type *filter_type;
2365 2366
2366 if (!filter->filters) 2367 if (!filter->filters)
2367 return NULL; 2368 return NULL;
@@ -2383,10 +2384,10 @@ tep_filter_make_string(struct event_filter *filter, int event_id)
2383 * 1 if the two filters hold the same content. 2384 * 1 if the two filters hold the same content.
2384 * 0 if they do not. 2385 * 0 if they do not.
2385 */ 2386 */
2386int tep_filter_compare(struct event_filter *filter1, struct event_filter *filter2) 2387int tep_filter_compare(struct tep_event_filter *filter1, struct tep_event_filter *filter2)
2387{ 2388{
2388 struct filter_type *filter_type1; 2389 struct tep_filter_type *filter_type1;
2389 struct filter_type *filter_type2; 2390 struct tep_filter_type *filter_type2;
2390 char *str1, *str2; 2391 char *str1, *str2;
2391 int result; 2392 int result;
2392 int i; 2393 int i;
@@ -2409,8 +2410,8 @@ int tep_filter_compare(struct event_filter *filter1, struct event_filter *filter
2409 if (filter_type1->filter->type != filter_type2->filter->type) 2410 if (filter_type1->filter->type != filter_type2->filter->type)
2410 break; 2411 break;
2411 switch (filter_type1->filter->type) { 2412 switch (filter_type1->filter->type) {
2412 case FILTER_TRIVIAL_FALSE: 2413 case TEP_FILTER_TRIVIAL_FALSE:
2413 case FILTER_TRIVIAL_TRUE: 2414 case TEP_FILTER_TRIVIAL_TRUE:
2414 /* trivial types just need the type compared */ 2415 /* trivial types just need the type compared */
2415 continue; 2416 continue;
2416 default: 2417 default:
diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c
index 424747475d37..528acc75d81a 100644
--- a/tools/lib/traceevent/plugin_function.c
+++ b/tools/lib/traceevent/plugin_function.c
@@ -23,6 +23,7 @@
23 23
24#include "event-parse.h" 24#include "event-parse.h"
25#include "event-utils.h" 25#include "event-utils.h"
26#include "trace-seq.h"
26 27
27static struct func_stack { 28static struct func_stack {
28 int size; 29 int size;
@@ -123,7 +124,7 @@ static int add_and_get_index(const char *parent, const char *child, int cpu)
123} 124}
124 125
125static int function_handler(struct trace_seq *s, struct tep_record *record, 126static int function_handler(struct trace_seq *s, struct tep_record *record,
126 struct event_format *event, void *context) 127 struct tep_event_format *event, void *context)
127{ 128{
128 struct tep_handle *pevent = event->pevent; 129 struct tep_handle *pevent = event->pevent;
129 unsigned long long function; 130 unsigned long long function;
diff --git a/tools/lib/traceevent/plugin_hrtimer.c b/tools/lib/traceevent/plugin_hrtimer.c
index b43bfec565d8..9aa05b4ca811 100644
--- a/tools/lib/traceevent/plugin_hrtimer.c
+++ b/tools/lib/traceevent/plugin_hrtimer.c
@@ -23,10 +23,11 @@
23#include <string.h> 23#include <string.h>
24 24
25#include "event-parse.h" 25#include "event-parse.h"
26#include "trace-seq.h"
26 27
27static int timer_expire_handler(struct trace_seq *s, 28static int timer_expire_handler(struct trace_seq *s,
28 struct tep_record *record, 29 struct tep_record *record,
29 struct event_format *event, void *context) 30 struct tep_event_format *event, void *context)
30{ 31{
31 trace_seq_printf(s, "hrtimer="); 32 trace_seq_printf(s, "hrtimer=");
32 33
@@ -46,7 +47,7 @@ static int timer_expire_handler(struct trace_seq *s,
46 47
47static int timer_start_handler(struct trace_seq *s, 48static int timer_start_handler(struct trace_seq *s,
48 struct tep_record *record, 49 struct tep_record *record,
49 struct event_format *event, void *context) 50 struct tep_event_format *event, void *context)
50{ 51{
51 trace_seq_printf(s, "hrtimer="); 52 trace_seq_printf(s, "hrtimer=");
52 53
diff --git a/tools/lib/traceevent/plugin_jbd2.c b/tools/lib/traceevent/plugin_jbd2.c
index 45a9acd19640..a5e34135dd6a 100644
--- a/tools/lib/traceevent/plugin_jbd2.c
+++ b/tools/lib/traceevent/plugin_jbd2.c
@@ -22,6 +22,7 @@
22#include <string.h> 22#include <string.h>
23 23
24#include "event-parse.h" 24#include "event-parse.h"
25#include "trace-seq.h"
25 26
26#define MINORBITS 20 27#define MINORBITS 20
27#define MINORMASK ((1U << MINORBITS) - 1) 28#define MINORMASK ((1U << MINORBITS) - 1)
diff --git a/tools/lib/traceevent/plugin_kmem.c b/tools/lib/traceevent/plugin_kmem.c
index 73966b05abce..1beb4eaddfdf 100644
--- a/tools/lib/traceevent/plugin_kmem.c
+++ b/tools/lib/traceevent/plugin_kmem.c
@@ -22,11 +22,12 @@
22#include <string.h> 22#include <string.h>
23 23
24#include "event-parse.h" 24#include "event-parse.h"
25#include "trace-seq.h"
25 26
26static int call_site_handler(struct trace_seq *s, struct tep_record *record, 27static int call_site_handler(struct trace_seq *s, struct tep_record *record,
27 struct event_format *event, void *context) 28 struct tep_event_format *event, void *context)
28{ 29{
29 struct format_field *field; 30 struct tep_format_field *field;
30 unsigned long long val, addr; 31 unsigned long long val, addr;
31 void *data = record->data; 32 void *data = record->data;
32 const char *func; 33 const char *func;
diff --git a/tools/lib/traceevent/plugin_kvm.c b/tools/lib/traceevent/plugin_kvm.c
index 1d0d15906225..d13c22846fa9 100644
--- a/tools/lib/traceevent/plugin_kvm.c
+++ b/tools/lib/traceevent/plugin_kvm.c
@@ -23,6 +23,7 @@
23#include <stdint.h> 23#include <stdint.h>
24 24
25#include "event-parse.h" 25#include "event-parse.h"
26#include "trace-seq.h"
26 27
27#ifdef HAVE_UDIS86 28#ifdef HAVE_UDIS86
28 29
@@ -248,7 +249,7 @@ static const char *find_exit_reason(unsigned isa, int val)
248} 249}
249 250
250static int print_exit_reason(struct trace_seq *s, struct tep_record *record, 251static int print_exit_reason(struct trace_seq *s, struct tep_record *record,
251 struct event_format *event, const char *field) 252 struct tep_event_format *event, const char *field)
252{ 253{
253 unsigned long long isa; 254 unsigned long long isa;
254 unsigned long long val; 255 unsigned long long val;
@@ -269,7 +270,7 @@ static int print_exit_reason(struct trace_seq *s, struct tep_record *record,
269} 270}
270 271
271static int kvm_exit_handler(struct trace_seq *s, struct tep_record *record, 272static int kvm_exit_handler(struct trace_seq *s, struct tep_record *record,
272 struct event_format *event, void *context) 273 struct tep_event_format *event, void *context)
273{ 274{
274 unsigned long long info1 = 0, info2 = 0; 275 unsigned long long info1 = 0, info2 = 0;
275 276
@@ -292,7 +293,7 @@ static int kvm_exit_handler(struct trace_seq *s, struct tep_record *record,
292 293
293static int kvm_emulate_insn_handler(struct trace_seq *s, 294static int kvm_emulate_insn_handler(struct trace_seq *s,
294 struct tep_record *record, 295 struct tep_record *record,
295 struct event_format *event, void *context) 296 struct tep_event_format *event, void *context)
296{ 297{
297 unsigned long long rip, csbase, len, flags, failed; 298 unsigned long long rip, csbase, len, flags, failed;
298 int llen; 299 int llen;
@@ -331,7 +332,7 @@ static int kvm_emulate_insn_handler(struct trace_seq *s,
331 332
332 333
333static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct tep_record *record, 334static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct tep_record *record,
334 struct event_format *event, void *context) 335 struct tep_event_format *event, void *context)
335{ 336{
336 if (print_exit_reason(s, record, event, "exit_code") < 0) 337 if (print_exit_reason(s, record, event, "exit_code") < 0)
337 return -1; 338 return -1;
@@ -345,7 +346,7 @@ static int kvm_nested_vmexit_inject_handler(struct trace_seq *s, struct tep_reco
345} 346}
346 347
347static int kvm_nested_vmexit_handler(struct trace_seq *s, struct tep_record *record, 348static int kvm_nested_vmexit_handler(struct trace_seq *s, struct tep_record *record,
348 struct event_format *event, void *context) 349 struct tep_event_format *event, void *context)
349{ 350{
350 tep_print_num_field(s, "rip %llx ", event, "rip", record, 1); 351 tep_print_num_field(s, "rip %llx ", event, "rip", record, 1);
351 352
@@ -371,7 +372,7 @@ union kvm_mmu_page_role {
371}; 372};
372 373
373static int kvm_mmu_print_role(struct trace_seq *s, struct tep_record *record, 374static int kvm_mmu_print_role(struct trace_seq *s, struct tep_record *record,
374 struct event_format *event, void *context) 375 struct tep_event_format *event, void *context)
375{ 376{
376 unsigned long long val; 377 unsigned long long val;
377 static const char *access_str[] = { 378 static const char *access_str[] = {
@@ -418,7 +419,7 @@ static int kvm_mmu_print_role(struct trace_seq *s, struct tep_record *record,
418 419
419static int kvm_mmu_get_page_handler(struct trace_seq *s, 420static int kvm_mmu_get_page_handler(struct trace_seq *s,
420 struct tep_record *record, 421 struct tep_record *record,
421 struct event_format *event, void *context) 422 struct tep_event_format *event, void *context)
422{ 423{
423 unsigned long long val; 424 unsigned long long val;
424 425
diff --git a/tools/lib/traceevent/plugin_mac80211.c b/tools/lib/traceevent/plugin_mac80211.c
index de50a5316203..da3855e7b86f 100644
--- a/tools/lib/traceevent/plugin_mac80211.c
+++ b/tools/lib/traceevent/plugin_mac80211.c
@@ -22,13 +22,14 @@
22#include <string.h> 22#include <string.h>
23 23
24#include "event-parse.h" 24#include "event-parse.h"
25#include "trace-seq.h"
25 26
26#define INDENT 65 27#define INDENT 65
27 28
28static void print_string(struct trace_seq *s, struct event_format *event, 29static void print_string(struct trace_seq *s, struct tep_event_format *event,
29 const char *name, const void *data) 30 const char *name, const void *data)
30{ 31{
31 struct format_field *f = tep_find_field(event, name); 32 struct tep_format_field *f = tep_find_field(event, name);
32 int offset; 33 int offset;
33 int length; 34 int length;
34 35
@@ -59,7 +60,7 @@ static void print_string(struct trace_seq *s, struct event_format *event,
59 60
60static int drv_bss_info_changed(struct trace_seq *s, 61static int drv_bss_info_changed(struct trace_seq *s,
61 struct tep_record *record, 62 struct tep_record *record,
62 struct event_format *event, void *context) 63 struct tep_event_format *event, void *context)
63{ 64{
64 void *data = record->data; 65 void *data = record->data;
65 66
diff --git a/tools/lib/traceevent/plugin_sched_switch.c b/tools/lib/traceevent/plugin_sched_switch.c
index eecb4bd95c11..77882272672f 100644
--- a/tools/lib/traceevent/plugin_sched_switch.c
+++ b/tools/lib/traceevent/plugin_sched_switch.c
@@ -22,6 +22,7 @@
22#include <string.h> 22#include <string.h>
23 23
24#include "event-parse.h" 24#include "event-parse.h"
25#include "trace-seq.h"
25 26
26static void write_state(struct trace_seq *s, int val) 27static void write_state(struct trace_seq *s, int val)
27{ 28{
@@ -44,7 +45,7 @@ static void write_state(struct trace_seq *s, int val)
44 trace_seq_putc(s, 'R'); 45 trace_seq_putc(s, 'R');
45} 46}
46 47
47static void write_and_save_comm(struct format_field *field, 48static void write_and_save_comm(struct tep_format_field *field,
48 struct tep_record *record, 49 struct tep_record *record,
49 struct trace_seq *s, int pid) 50 struct trace_seq *s, int pid)
50{ 51{
@@ -66,9 +67,9 @@ static void write_and_save_comm(struct format_field *field,
66 67
67static int sched_wakeup_handler(struct trace_seq *s, 68static int sched_wakeup_handler(struct trace_seq *s,
68 struct tep_record *record, 69 struct tep_record *record,
69 struct event_format *event, void *context) 70 struct tep_event_format *event, void *context)
70{ 71{
71 struct format_field *field; 72 struct tep_format_field *field;
72 unsigned long long val; 73 unsigned long long val;
73 74
74 if (tep_get_field_val(s, event, "pid", record, &val, 1)) 75 if (tep_get_field_val(s, event, "pid", record, &val, 1))
@@ -95,9 +96,9 @@ static int sched_wakeup_handler(struct trace_seq *s,
95 96
96static int sched_switch_handler(struct trace_seq *s, 97static int sched_switch_handler(struct trace_seq *s,
97 struct tep_record *record, 98 struct tep_record *record,
98 struct event_format *event, void *context) 99 struct tep_event_format *event, void *context)
99{ 100{
100 struct format_field *field; 101 struct tep_format_field *field;
101 unsigned long long val; 102 unsigned long long val;
102 103
103 if (tep_get_field_val(s, event, "prev_pid", record, &val, 1)) 104 if (tep_get_field_val(s, event, "prev_pid", record, &val, 1))
diff --git a/tools/lib/traceevent/plugin_scsi.c b/tools/lib/traceevent/plugin_scsi.c
index 5ec346f6b842..4eba25cc1431 100644
--- a/tools/lib/traceevent/plugin_scsi.c
+++ b/tools/lib/traceevent/plugin_scsi.c
@@ -3,6 +3,7 @@
3#include <string.h> 3#include <string.h>
4#include <inttypes.h> 4#include <inttypes.h>
5#include "event-parse.h" 5#include "event-parse.h"
6#include "trace-seq.h"
6 7
7typedef unsigned long sector_t; 8typedef unsigned long sector_t;
8typedef uint64_t u64; 9typedef uint64_t u64;
diff --git a/tools/lib/traceevent/plugin_xen.c b/tools/lib/traceevent/plugin_xen.c
index b2acbd6e9c86..bc0496e4c296 100644
--- a/tools/lib/traceevent/plugin_xen.c
+++ b/tools/lib/traceevent/plugin_xen.c
@@ -3,6 +3,7 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
5#include "event-parse.h" 5#include "event-parse.h"
6#include "trace-seq.h"
6 7
7#define __HYPERVISOR_set_trap_table 0 8#define __HYPERVISOR_set_trap_table 0
8#define __HYPERVISOR_mmu_update 1 9#define __HYPERVISOR_mmu_update 1
diff --git a/tools/lib/traceevent/tep_strerror.c b/tools/lib/traceevent/tep_strerror.c
new file mode 100644
index 000000000000..4ac26445b2f6
--- /dev/null
+++ b/tools/lib/traceevent/tep_strerror.c
@@ -0,0 +1,53 @@
1// SPDX-License-Identifier: LGPL-2.1
2#undef _GNU_SOURCE
3#include <string.h>
4#include <stdio.h>
5
6#include "event-parse.h"
7
8#undef _PE
9#define _PE(code, str) str
10static const char * const tep_error_str[] = {
11 TEP_ERRORS
12};
13#undef _PE
14
15/*
16 * The tools so far have been using the strerror_r() GNU variant, that returns
17 * a string, be it the buffer passed or something else.
18 *
19 * But that, besides being tricky in cases where we expect that the function
20 * using strerror_r() returns the error formatted in a provided buffer (we have
21 * to check if it returned something else and copy that instead), breaks the
22 * build on systems not using glibc, like Alpine Linux, where musl libc is
23 * used.
24 *
25 * So, introduce yet another wrapper, str_error_r(), that has the GNU
26 * interface, but uses the portable XSI variant of strerror_r(), so that users
27 * rest asured that the provided buffer is used and it is what is returned.
28 */
29int tep_strerror(struct tep_handle *tep __maybe_unused,
30 enum tep_errno errnum, char *buf, size_t buflen)
31{
32 const char *msg;
33 int idx;
34
35 if (!buflen)
36 return 0;
37
38 if (errnum >= 0) {
39 int err = strerror_r(errnum, buf, buflen);
40 buf[buflen - 1] = 0;
41 return err;
42 }
43
44 if (errnum <= __TEP_ERRNO__START ||
45 errnum >= __TEP_ERRNO__END)
46 return -1;
47
48 idx = errnum - __TEP_ERRNO__START - 1;
49 msg = tep_error_str[idx];
50 snprintf(buf, buflen, "%s", msg);
51
52 return 0;
53}
diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index e3bac4543d3b..8ff1d55954d1 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -3,6 +3,8 @@
3 * Copyright (C) 2009 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> 3 * Copyright (C) 2009 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 * 4 *
5 */ 5 */
6#include "trace-seq.h"
7
6#include <stdio.h> 8#include <stdio.h>
7#include <stdlib.h> 9#include <stdlib.h>
8#include <string.h> 10#include <string.h>
diff --git a/tools/lib/traceevent/trace-seq.h b/tools/lib/traceevent/trace-seq.h
new file mode 100644
index 000000000000..d68ec69f8d1a
--- /dev/null
+++ b/tools/lib/traceevent/trace-seq.h
@@ -0,0 +1,55 @@
1// SPDX-License-Identifier: LGPL-2.1
2/*
3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 *
5 */
6
7#ifndef _TRACE_SEQ_H
8#define _TRACE_SEQ_H
9
10#include <stdarg.h>
11#include <stdio.h>
12
13/* ----------------------- trace_seq ----------------------- */
14
15#ifndef TRACE_SEQ_BUF_SIZE
16#define TRACE_SEQ_BUF_SIZE 4096
17#endif
18
19enum trace_seq_fail {
20 TRACE_SEQ__GOOD,
21 TRACE_SEQ__BUFFER_POISONED,
22 TRACE_SEQ__MEM_ALLOC_FAILED,
23};
24
25/*
26 * Trace sequences are used to allow a function to call several other functions
27 * to create a string of data to use (up to a max of PAGE_SIZE).
28 */
29
30struct trace_seq {
31 char *buffer;
32 unsigned int buffer_size;
33 unsigned int len;
34 unsigned int readpos;
35 enum trace_seq_fail state;
36};
37
38void trace_seq_init(struct trace_seq *s);
39void trace_seq_reset(struct trace_seq *s);
40void trace_seq_destroy(struct trace_seq *s);
41
42extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
43 __attribute__ ((format (printf, 2, 3)));
44extern int trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
45 __attribute__ ((format (printf, 2, 0)));
46
47extern int trace_seq_puts(struct trace_seq *s, const char *str);
48extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
49
50extern void trace_seq_terminate(struct trace_seq *s);
51
52extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
53extern int trace_seq_do_printf(struct trace_seq *s);
54
55#endif /* _TRACE_SEQ_H */
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 0be411695379..2f3bf025e305 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -779,7 +779,9 @@ endif
779ifndef NO_LIBBPF 779ifndef NO_LIBBPF
780 $(call QUIET_INSTALL, bpf-headers) \ 780 $(call QUIET_INSTALL, bpf-headers) \
781 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'; \ 781 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'; \
782 $(INSTALL) include/bpf/*.h -t '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf' 782 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf/linux'; \
783 $(INSTALL) include/bpf/*.h -t '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'; \
784 $(INSTALL) include/bpf/linux/*.h -t '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf/linux'
783 $(call QUIET_INSTALL, bpf-examples) \ 785 $(call QUIET_INSTALL, bpf-examples) \
784 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'; \ 786 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'; \
785 $(INSTALL) examples/bpf/*.c -t '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf' 787 $(INSTALL) examples/bpf/*.c -t '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arch/arm64/annotate/instructions.c
index 6688977e4ac7..76c6345a57d5 100644
--- a/tools/perf/arch/arm64/annotate/instructions.c
+++ b/tools/perf/arch/arm64/annotate/instructions.c
@@ -8,6 +8,63 @@ struct arm64_annotate {
8 jump_insn; 8 jump_insn;
9}; 9};
10 10
11static int arm64_mov__parse(struct arch *arch __maybe_unused,
12 struct ins_operands *ops,
13 struct map_symbol *ms __maybe_unused)
14{
15 char *s = strchr(ops->raw, ','), *target, *endptr;
16
17 if (s == NULL)
18 return -1;
19
20 *s = '\0';
21 ops->source.raw = strdup(ops->raw);
22 *s = ',';
23
24 if (ops->source.raw == NULL)
25 return -1;
26
27 target = ++s;
28 ops->target.raw = strdup(target);
29 if (ops->target.raw == NULL)
30 goto out_free_source;
31
32 ops->target.addr = strtoull(target, &endptr, 16);
33 if (endptr == target)
34 goto out_free_target;
35
36 s = strchr(endptr, '<');
37 if (s == NULL)
38 goto out_free_target;
39 endptr = strchr(s + 1, '>');
40 if (endptr == NULL)
41 goto out_free_target;
42
43 *endptr = '\0';
44 *s = ' ';
45 ops->target.name = strdup(s);
46 *s = '<';
47 *endptr = '>';
48 if (ops->target.name == NULL)
49 goto out_free_target;
50
51 return 0;
52
53out_free_target:
54 zfree(&ops->target.raw);
55out_free_source:
56 zfree(&ops->source.raw);
57 return -1;
58}
59
60static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
61 struct ins_operands *ops);
62
63static struct ins_ops arm64_mov_ops = {
64 .parse = arm64_mov__parse,
65 .scnprintf = mov__scnprintf,
66};
67
11static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const char *name) 68static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const char *name)
12{ 69{
13 struct arm64_annotate *arm = arch->priv; 70 struct arm64_annotate *arm = arch->priv;
@@ -21,7 +78,7 @@ static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch, const
21 else if (!strcmp(name, "ret")) 78 else if (!strcmp(name, "ret"))
22 ops = &ret_ops; 79 ops = &ret_ops;
23 else 80 else
24 return NULL; 81 ops = &arm64_mov_ops;
25 82
26 arch__associate_ins_ops(arch, name, ops); 83 arch__associate_ins_ops(arch, name, ops);
27 return ops; 84 return ops;
diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch/s390/annotate/instructions.c
index cee4e2f7c057..de0dd66dbb48 100644
--- a/tools/perf/arch/s390/annotate/instructions.c
+++ b/tools/perf/arch/s390/annotate/instructions.c
@@ -100,8 +100,6 @@ out_free_source:
100 return -1; 100 return -1;
101} 101}
102 102
103static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
104 struct ins_operands *ops);
105 103
106static struct ins_ops s390_mov_ops = { 104static struct ins_ops s390_mov_ops = {
107 .parse = s390_mov__parse, 105 .parse = s390_mov__parse,
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 830481b8db26..93d679eaf1f4 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -283,12 +283,11 @@ out_put:
283 return ret; 283 return ret;
284} 284}
285 285
286static int process_feature_event(struct perf_tool *tool, 286static int process_feature_event(struct perf_session *session,
287 union perf_event *event, 287 union perf_event *event)
288 struct perf_session *session)
289{ 288{
290 if (event->feat.feat_id < HEADER_LAST_FEATURE) 289 if (event->feat.feat_id < HEADER_LAST_FEATURE)
291 return perf_event__process_feature(tool, event, session); 290 return perf_event__process_feature(session, event);
292 return 0; 291 return 0;
293} 292}
294 293
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index a3b346359ba0..eda41673c4f3 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -86,12 +86,10 @@ static int perf_event__drop_oe(struct perf_tool *tool __maybe_unused,
86} 86}
87#endif 87#endif
88 88
89static int perf_event__repipe_op2_synth(struct perf_tool *tool, 89static int perf_event__repipe_op2_synth(struct perf_session *session,
90 union perf_event *event, 90 union perf_event *event)
91 struct perf_session *session
92 __maybe_unused)
93{ 91{
94 return perf_event__repipe_synth(tool, event); 92 return perf_event__repipe_synth(session->tool, event);
95} 93}
96 94
97static int perf_event__repipe_attr(struct perf_tool *tool, 95static int perf_event__repipe_attr(struct perf_tool *tool,
@@ -133,10 +131,10 @@ static int copy_bytes(struct perf_inject *inject, int fd, off_t size)
133 return 0; 131 return 0;
134} 132}
135 133
136static s64 perf_event__repipe_auxtrace(struct perf_tool *tool, 134static s64 perf_event__repipe_auxtrace(struct perf_session *session,
137 union perf_event *event, 135 union perf_event *event)
138 struct perf_session *session)
139{ 136{
137 struct perf_tool *tool = session->tool;
140 struct perf_inject *inject = container_of(tool, struct perf_inject, 138 struct perf_inject *inject = container_of(tool, struct perf_inject,
141 tool); 139 tool);
142 int ret; 140 int ret;
@@ -174,9 +172,8 @@ static s64 perf_event__repipe_auxtrace(struct perf_tool *tool,
174#else 172#else
175 173
176static s64 174static s64
177perf_event__repipe_auxtrace(struct perf_tool *tool __maybe_unused, 175perf_event__repipe_auxtrace(struct perf_session *session __maybe_unused,
178 union perf_event *event __maybe_unused, 176 union perf_event *event __maybe_unused)
179 struct perf_session *session __maybe_unused)
180{ 177{
181 pr_err("AUX area tracing not supported\n"); 178 pr_err("AUX area tracing not supported\n");
182 return -EINVAL; 179 return -EINVAL;
@@ -362,26 +359,24 @@ static int perf_event__repipe_exit(struct perf_tool *tool,
362 return err; 359 return err;
363} 360}
364 361
365static int perf_event__repipe_tracing_data(struct perf_tool *tool, 362static int perf_event__repipe_tracing_data(struct perf_session *session,
366 union perf_event *event, 363 union perf_event *event)
367 struct perf_session *session)
368{ 364{
369 int err; 365 int err;
370 366
371 perf_event__repipe_synth(tool, event); 367 perf_event__repipe_synth(session->tool, event);
372 err = perf_event__process_tracing_data(tool, event, session); 368 err = perf_event__process_tracing_data(session, event);
373 369
374 return err; 370 return err;
375} 371}
376 372
377static int perf_event__repipe_id_index(struct perf_tool *tool, 373static int perf_event__repipe_id_index(struct perf_session *session,
378 union perf_event *event, 374 union perf_event *event)
379 struct perf_session *session)
380{ 375{
381 int err; 376 int err;
382 377
383 perf_event__repipe_synth(tool, event); 378 perf_event__repipe_synth(session->tool, event);
384 err = perf_event__process_id_index(tool, event, session); 379 err = perf_event__process_id_index(session, event);
385 380
386 return err; 381 return err;
387} 382}
@@ -803,7 +798,8 @@ int cmd_inject(int argc, const char **argv)
803 "kallsyms pathname"), 798 "kallsyms pathname"),
804 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"), 799 OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"),
805 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts, 800 OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts,
806 NULL, "opts", "Instruction Tracing options", 801 NULL, "opts", "Instruction Tracing options\n"
802 ITRACE_HELP,
807 itrace_parse_synth_opts), 803 itrace_parse_synth_opts),
808 OPT_BOOLEAN(0, "strip", &inject.strip, 804 OPT_BOOLEAN(0, "strip", &inject.strip,
809 "strip non-synthesized events (use with --itrace)"), 805 "strip non-synthesized events (use with --itrace)"),
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 22ebeb92ac51..0980dfe3396b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -106,9 +106,12 @@ static bool switch_output_time(struct record *rec)
106 trigger_is_ready(&switch_output_trigger); 106 trigger_is_ready(&switch_output_trigger);
107} 107}
108 108
109static int record__write(struct record *rec, void *bf, size_t size) 109static int record__write(struct record *rec, struct perf_mmap *map __maybe_unused,
110 void *bf, size_t size)
110{ 111{
111 if (perf_data__write(rec->session->data, bf, size) < 0) { 112 struct perf_data_file *file = &rec->session->data->file;
113
114 if (perf_data_file__write(file, bf, size) < 0) {
112 pr_err("failed to write perf data, error: %m\n"); 115 pr_err("failed to write perf data, error: %m\n");
113 return -1; 116 return -1;
114 } 117 }
@@ -127,15 +130,15 @@ static int process_synthesized_event(struct perf_tool *tool,
127 struct machine *machine __maybe_unused) 130 struct machine *machine __maybe_unused)
128{ 131{
129 struct record *rec = container_of(tool, struct record, tool); 132 struct record *rec = container_of(tool, struct record, tool);
130 return record__write(rec, event, event->header.size); 133 return record__write(rec, NULL, event, event->header.size);
131} 134}
132 135
133static int record__pushfn(void *to, void *bf, size_t size) 136static int record__pushfn(struct perf_mmap *map, void *to, void *bf, size_t size)
134{ 137{
135 struct record *rec = to; 138 struct record *rec = to;
136 139
137 rec->samples++; 140 rec->samples++;
138 return record__write(rec, bf, size); 141 return record__write(rec, map, bf, size);
139} 142}
140 143
141static volatile int done; 144static volatile int done;
@@ -170,6 +173,7 @@ static void record__sig_exit(void)
170#ifdef HAVE_AUXTRACE_SUPPORT 173#ifdef HAVE_AUXTRACE_SUPPORT
171 174
172static int record__process_auxtrace(struct perf_tool *tool, 175static int record__process_auxtrace(struct perf_tool *tool,
176 struct perf_mmap *map,
173 union perf_event *event, void *data1, 177 union perf_event *event, void *data1,
174 size_t len1, void *data2, size_t len2) 178 size_t len1, void *data2, size_t len2)
175{ 179{
@@ -197,21 +201,21 @@ static int record__process_auxtrace(struct perf_tool *tool,
197 if (padding) 201 if (padding)
198 padding = 8 - padding; 202 padding = 8 - padding;
199 203
200 record__write(rec, event, event->header.size); 204 record__write(rec, map, event, event->header.size);
201 record__write(rec, data1, len1); 205 record__write(rec, map, data1, len1);
202 if (len2) 206 if (len2)
203 record__write(rec, data2, len2); 207 record__write(rec, map, data2, len2);
204 record__write(rec, &pad, padding); 208 record__write(rec, map, &pad, padding);
205 209
206 return 0; 210 return 0;
207} 211}
208 212
209static int record__auxtrace_mmap_read(struct record *rec, 213static int record__auxtrace_mmap_read(struct record *rec,
210 struct auxtrace_mmap *mm) 214 struct perf_mmap *map)
211{ 215{
212 int ret; 216 int ret;
213 217
214 ret = auxtrace_mmap__read(mm, rec->itr, &rec->tool, 218 ret = auxtrace_mmap__read(map, rec->itr, &rec->tool,
215 record__process_auxtrace); 219 record__process_auxtrace);
216 if (ret < 0) 220 if (ret < 0)
217 return ret; 221 return ret;
@@ -223,11 +227,11 @@ static int record__auxtrace_mmap_read(struct record *rec,
223} 227}
224 228
225static int record__auxtrace_mmap_read_snapshot(struct record *rec, 229static int record__auxtrace_mmap_read_snapshot(struct record *rec,
226 struct auxtrace_mmap *mm) 230 struct perf_mmap *map)
227{ 231{
228 int ret; 232 int ret;
229 233
230 ret = auxtrace_mmap__read_snapshot(mm, rec->itr, &rec->tool, 234 ret = auxtrace_mmap__read_snapshot(map, rec->itr, &rec->tool,
231 record__process_auxtrace, 235 record__process_auxtrace,
232 rec->opts.auxtrace_snapshot_size); 236 rec->opts.auxtrace_snapshot_size);
233 if (ret < 0) 237 if (ret < 0)
@@ -245,13 +249,12 @@ static int record__auxtrace_read_snapshot_all(struct record *rec)
245 int rc = 0; 249 int rc = 0;
246 250
247 for (i = 0; i < rec->evlist->nr_mmaps; i++) { 251 for (i = 0; i < rec->evlist->nr_mmaps; i++) {
248 struct auxtrace_mmap *mm = 252 struct perf_mmap *map = &rec->evlist->mmap[i];
249 &rec->evlist->mmap[i].auxtrace_mmap;
250 253
251 if (!mm->base) 254 if (!map->auxtrace_mmap.base)
252 continue; 255 continue;
253 256
254 if (record__auxtrace_mmap_read_snapshot(rec, mm) != 0) { 257 if (record__auxtrace_mmap_read_snapshot(rec, map) != 0) {
255 rc = -1; 258 rc = -1;
256 goto out; 259 goto out;
257 } 260 }
@@ -295,7 +298,7 @@ static int record__auxtrace_init(struct record *rec)
295 298
296static inline 299static inline
297int record__auxtrace_mmap_read(struct record *rec __maybe_unused, 300int record__auxtrace_mmap_read(struct record *rec __maybe_unused,
298 struct auxtrace_mmap *mm __maybe_unused) 301 struct perf_mmap *map __maybe_unused)
299{ 302{
300 return 0; 303 return 0;
301} 304}
@@ -529,17 +532,17 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli
529 return 0; 532 return 0;
530 533
531 for (i = 0; i < evlist->nr_mmaps; i++) { 534 for (i = 0; i < evlist->nr_mmaps; i++) {
532 struct auxtrace_mmap *mm = &maps[i].auxtrace_mmap; 535 struct perf_mmap *map = &maps[i];
533 536
534 if (maps[i].base) { 537 if (map->base) {
535 if (perf_mmap__push(&maps[i], rec, record__pushfn) != 0) { 538 if (perf_mmap__push(map, rec, record__pushfn) != 0) {
536 rc = -1; 539 rc = -1;
537 goto out; 540 goto out;
538 } 541 }
539 } 542 }
540 543
541 if (mm->base && !rec->opts.auxtrace_snapshot_mode && 544 if (map->auxtrace_mmap.base && !rec->opts.auxtrace_snapshot_mode &&
542 record__auxtrace_mmap_read(rec, mm) != 0) { 545 record__auxtrace_mmap_read(rec, map) != 0) {
543 rc = -1; 546 rc = -1;
544 goto out; 547 goto out;
545 } 548 }
@@ -550,7 +553,7 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli
550 * at least one event. 553 * at least one event.
551 */ 554 */
552 if (bytes_written != rec->bytes_written) 555 if (bytes_written != rec->bytes_written)
553 rc = record__write(rec, &finished_round_event, sizeof(finished_round_event)); 556 rc = record__write(rec, NULL, &finished_round_event, sizeof(finished_round_event));
554 557
555 if (overwrite) 558 if (overwrite)
556 perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_EMPTY); 559 perf_evlist__toggle_bkw_mmap(evlist, BKW_MMAP_EMPTY);
@@ -758,7 +761,7 @@ static int record__synthesize(struct record *rec, bool tail)
758 * We need to synthesize events first, because some 761 * We need to synthesize events first, because some
759 * features works on top of them (on report side). 762 * features works on top of them (on report side).
760 */ 763 */
761 err = perf_event__synthesize_attrs(tool, session, 764 err = perf_event__synthesize_attrs(tool, rec->evlist,
762 process_synthesized_event); 765 process_synthesized_event);
763 if (err < 0) { 766 if (err < 0) {
764 pr_err("Couldn't synthesize attrs.\n"); 767 pr_err("Couldn't synthesize attrs.\n");
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index b2188e623e22..257c9c18cb7e 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -201,14 +201,13 @@ static void setup_forced_leader(struct report *report,
201 perf_evlist__force_leader(evlist); 201 perf_evlist__force_leader(evlist);
202} 202}
203 203
204static int process_feature_event(struct perf_tool *tool, 204static int process_feature_event(struct perf_session *session,
205 union perf_event *event, 205 union perf_event *event)
206 struct perf_session *session __maybe_unused)
207{ 206{
208 struct report *rep = container_of(tool, struct report, tool); 207 struct report *rep = container_of(session->tool, struct report, tool);
209 208
210 if (event->feat.feat_id < HEADER_LAST_FEATURE) 209 if (event->feat.feat_id < HEADER_LAST_FEATURE)
211 return perf_event__process_feature(tool, event, session); 210 return perf_event__process_feature(session, event);
212 211
213 if (event->feat.feat_id != HEADER_LAST_FEATURE) { 212 if (event->feat.feat_id != HEADER_LAST_FEATURE) {
214 pr_err("failed: wrong feature ID: %" PRIu64 "\n", 213 pr_err("failed: wrong feature ID: %" PRIu64 "\n",
@@ -1106,7 +1105,7 @@ int cmd_report(int argc, const char **argv)
1106 OPT_CALLBACK(0, "percentage", NULL, "relative|absolute", 1105 OPT_CALLBACK(0, "percentage", NULL, "relative|absolute",
1107 "how to display percentage of filtered entries", parse_filter_percentage), 1106 "how to display percentage of filtered entries", parse_filter_percentage),
1108 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", 1107 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
1109 "Instruction Tracing options", 1108 "Instruction Tracing options\n" ITRACE_HELP,
1110 itrace_parse_synth_opts), 1109 itrace_parse_synth_opts),
1111 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename, 1110 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
1112 "Show full source file name path for source lines"), 1111 "Show full source file name path for source lines"),
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index ba481d73f910..4da5e32b9e03 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -406,9 +406,10 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
406 PERF_OUTPUT_WEIGHT)) 406 PERF_OUTPUT_WEIGHT))
407 return -EINVAL; 407 return -EINVAL;
408 408
409 if (PRINT_FIELD(SYM) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR)) { 409 if (PRINT_FIELD(SYM) &&
410 !(evsel->attr.sample_type & (PERF_SAMPLE_IP|PERF_SAMPLE_ADDR))) {
410 pr_err("Display of symbols requested but neither sample IP nor " 411 pr_err("Display of symbols requested but neither sample IP nor "
411 "sample address\nis selected. Hence, no addresses to convert " 412 "sample address\navailable. Hence, no addresses to convert "
412 "to symbols.\n"); 413 "to symbols.\n");
413 return -EINVAL; 414 return -EINVAL;
414 } 415 }
@@ -417,10 +418,9 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
417 "selected.\n"); 418 "selected.\n");
418 return -EINVAL; 419 return -EINVAL;
419 } 420 }
420 if (PRINT_FIELD(DSO) && !PRINT_FIELD(IP) && !PRINT_FIELD(ADDR) && 421 if (PRINT_FIELD(DSO) &&
421 !PRINT_FIELD(BRSTACK) && !PRINT_FIELD(BRSTACKSYM) && !PRINT_FIELD(BRSTACKOFF)) { 422 !(evsel->attr.sample_type & (PERF_SAMPLE_IP|PERF_SAMPLE_ADDR))) {
422 pr_err("Display of DSO requested but no address to convert. Select\n" 423 pr_err("Display of DSO requested but no address to convert.\n");
423 "sample IP, sample address, brstack, brstacksym, or brstackoff.\n");
424 return -EINVAL; 424 return -EINVAL;
425 } 425 }
426 if (PRINT_FIELD(SRCLINE) && !PRINT_FIELD(IP)) { 426 if (PRINT_FIELD(SRCLINE) && !PRINT_FIELD(IP)) {
@@ -1115,6 +1115,7 @@ static int perf_sample__fprintf_callindent(struct perf_sample *sample,
1115 const char *name = NULL; 1115 const char *name = NULL;
1116 static int spacing; 1116 static int spacing;
1117 int len = 0; 1117 int len = 0;
1118 int dlen = 0;
1118 u64 ip = 0; 1119 u64 ip = 0;
1119 1120
1120 /* 1121 /*
@@ -1141,6 +1142,12 @@ static int perf_sample__fprintf_callindent(struct perf_sample *sample,
1141 ip = sample->ip; 1142 ip = sample->ip;
1142 } 1143 }
1143 1144
1145 if (PRINT_FIELD(DSO) && !(PRINT_FIELD(IP) || PRINT_FIELD(ADDR))) {
1146 dlen += fprintf(fp, "(");
1147 dlen += map__fprintf_dsoname(al->map, fp);
1148 dlen += fprintf(fp, ")\t");
1149 }
1150
1144 if (name) 1151 if (name)
1145 len = fprintf(fp, "%*s%s", (int)depth * 4, "", name); 1152 len = fprintf(fp, "%*s%s", (int)depth * 4, "", name);
1146 else if (ip) 1153 else if (ip)
@@ -1159,7 +1166,7 @@ static int perf_sample__fprintf_callindent(struct perf_sample *sample,
1159 if (len < spacing) 1166 if (len < spacing)
1160 len += fprintf(fp, "%*s", spacing - len, ""); 1167 len += fprintf(fp, "%*s", spacing - len, "");
1161 1168
1162 return len; 1169 return len + dlen;
1163} 1170}
1164 1171
1165static int perf_sample__fprintf_insn(struct perf_sample *sample, 1172static int perf_sample__fprintf_insn(struct perf_sample *sample,
@@ -1255,6 +1262,18 @@ static struct {
1255 {0, NULL} 1262 {0, NULL}
1256}; 1263};
1257 1264
1265static const char *sample_flags_to_name(u32 flags)
1266{
1267 int i;
1268
1269 for (i = 0; sample_flags[i].name ; i++) {
1270 if (sample_flags[i].flags == flags)
1271 return sample_flags[i].name;
1272 }
1273
1274 return NULL;
1275}
1276
1258static int perf_sample__fprintf_flags(u32 flags, FILE *fp) 1277static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
1259{ 1278{
1260 const char *chars = PERF_IP_FLAG_CHARS; 1279 const char *chars = PERF_IP_FLAG_CHARS;
@@ -1264,11 +1283,20 @@ static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
1264 char str[33]; 1283 char str[33];
1265 int i, pos = 0; 1284 int i, pos = 0;
1266 1285
1267 for (i = 0; sample_flags[i].name ; i++) { 1286 name = sample_flags_to_name(flags & ~PERF_IP_FLAG_IN_TX);
1268 if (sample_flags[i].flags == (flags & ~PERF_IP_FLAG_IN_TX)) { 1287 if (name)
1269 name = sample_flags[i].name; 1288 return fprintf(fp, " %-15s%4s ", name, in_tx ? "(x)" : "");
1270 break; 1289
1271 } 1290 if (flags & PERF_IP_FLAG_TRACE_BEGIN) {
1291 name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_BEGIN));
1292 if (name)
1293 return fprintf(fp, " tr strt %-7s%4s ", name, in_tx ? "(x)" : "");
1294 }
1295
1296 if (flags & PERF_IP_FLAG_TRACE_END) {
1297 name = sample_flags_to_name(flags & ~(PERF_IP_FLAG_IN_TX | PERF_IP_FLAG_TRACE_END));
1298 if (name)
1299 return fprintf(fp, " tr end %-7s%4s ", name, in_tx ? "(x)" : "");
1272 } 1300 }
1273 1301
1274 for (i = 0; i < n; i++, flags >>= 1) { 1302 for (i = 0; i < n; i++, flags >>= 1) {
@@ -1281,10 +1309,7 @@ static int perf_sample__fprintf_flags(u32 flags, FILE *fp)
1281 } 1309 }
1282 str[pos] = 0; 1310 str[pos] = 0;
1283 1311
1284 if (name) 1312 return fprintf(fp, " %-19s ", str);
1285 return fprintf(fp, " %-7s%4s ", name, in_tx ? "(x)" : "");
1286
1287 return fprintf(fp, " %-11s ", str);
1288} 1313}
1289 1314
1290struct printer_data { 1315struct printer_data {
@@ -1544,7 +1569,8 @@ struct metric_ctx {
1544 FILE *fp; 1569 FILE *fp;
1545}; 1570};
1546 1571
1547static void script_print_metric(void *ctx, const char *color, 1572static void script_print_metric(struct perf_stat_config *config __maybe_unused,
1573 void *ctx, const char *color,
1548 const char *fmt, 1574 const char *fmt,
1549 const char *unit, double val) 1575 const char *unit, double val)
1550{ 1576{
@@ -1562,7 +1588,8 @@ static void script_print_metric(void *ctx, const char *color,
1562 fprintf(mctx->fp, " %s\n", unit); 1588 fprintf(mctx->fp, " %s\n", unit);
1563} 1589}
1564 1590
1565static void script_new_line(void *ctx) 1591static void script_new_line(struct perf_stat_config *config __maybe_unused,
1592 void *ctx)
1566{ 1593{
1567 struct metric_ctx *mctx = ctx; 1594 struct metric_ctx *mctx = ctx;
1568 1595
@@ -1608,7 +1635,7 @@ static void perf_sample__fprint_metric(struct perf_script *script,
1608 evsel_script(evsel)->val = val; 1635 evsel_script(evsel)->val = val;
1609 if (evsel_script(evsel->leader)->gnum == evsel->leader->nr_members) { 1636 if (evsel_script(evsel->leader)->gnum == evsel->leader->nr_members) {
1610 for_each_group_member (ev2, evsel->leader) { 1637 for_each_group_member (ev2, evsel->leader) {
1611 perf_stat__print_shadow_stats(ev2, 1638 perf_stat__print_shadow_stats(&stat_config, ev2,
1612 evsel_script(ev2)->val, 1639 evsel_script(ev2)->val,
1613 sample->cpu, 1640 sample->cpu,
1614 &ctx, 1641 &ctx,
@@ -2489,6 +2516,8 @@ parse:
2489 output[j].fields &= ~all_output_options[i].field; 2516 output[j].fields &= ~all_output_options[i].field;
2490 else 2517 else
2491 output[j].fields |= all_output_options[i].field; 2518 output[j].fields |= all_output_options[i].field;
2519 output[j].user_set = true;
2520 output[j].wildcard_set = true;
2492 } 2521 }
2493 } 2522 }
2494 } else { 2523 } else {
@@ -2499,7 +2528,8 @@ parse:
2499 rc = -EINVAL; 2528 rc = -EINVAL;
2500 goto out; 2529 goto out;
2501 } 2530 }
2502 output[type].fields |= all_output_options[i].field; 2531 output[type].user_set = true;
2532 output[type].wildcard_set = true;
2503 } 2533 }
2504 } 2534 }
2505 2535
@@ -2963,9 +2993,8 @@ static void script__setup_sample_type(struct perf_script *script)
2963 } 2993 }
2964} 2994}
2965 2995
2966static int process_stat_round_event(struct perf_tool *tool __maybe_unused, 2996static int process_stat_round_event(struct perf_session *session,
2967 union perf_event *event, 2997 union perf_event *event)
2968 struct perf_session *session)
2969{ 2998{
2970 struct stat_round_event *round = &event->stat_round; 2999 struct stat_round_event *round = &event->stat_round;
2971 struct perf_evsel *counter; 3000 struct perf_evsel *counter;
@@ -2979,9 +3008,8 @@ static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
2979 return 0; 3008 return 0;
2980} 3009}
2981 3010
2982static int process_stat_config_event(struct perf_tool *tool __maybe_unused, 3011static int process_stat_config_event(struct perf_session *session __maybe_unused,
2983 union perf_event *event, 3012 union perf_event *event)
2984 struct perf_session *session __maybe_unused)
2985{ 3013{
2986 perf_event__read_stat_config(&stat_config, &event->stat_config); 3014 perf_event__read_stat_config(&stat_config, &event->stat_config);
2987 return 0; 3015 return 0;
@@ -3007,10 +3035,10 @@ static int set_maps(struct perf_script *script)
3007} 3035}
3008 3036
3009static 3037static
3010int process_thread_map_event(struct perf_tool *tool, 3038int process_thread_map_event(struct perf_session *session,
3011 union perf_event *event, 3039 union perf_event *event)
3012 struct perf_session *session __maybe_unused)
3013{ 3040{
3041 struct perf_tool *tool = session->tool;
3014 struct perf_script *script = container_of(tool, struct perf_script, tool); 3042 struct perf_script *script = container_of(tool, struct perf_script, tool);
3015 3043
3016 if (script->threads) { 3044 if (script->threads) {
@@ -3026,10 +3054,10 @@ int process_thread_map_event(struct perf_tool *tool,
3026} 3054}
3027 3055
3028static 3056static
3029int process_cpu_map_event(struct perf_tool *tool __maybe_unused, 3057int process_cpu_map_event(struct perf_session *session,
3030 union perf_event *event, 3058 union perf_event *event)
3031 struct perf_session *session __maybe_unused)
3032{ 3059{
3060 struct perf_tool *tool = session->tool;
3033 struct perf_script *script = container_of(tool, struct perf_script, tool); 3061 struct perf_script *script = container_of(tool, struct perf_script, tool);
3034 3062
3035 if (script->cpus) { 3063 if (script->cpus) {
@@ -3044,21 +3072,21 @@ int process_cpu_map_event(struct perf_tool *tool __maybe_unused,
3044 return set_maps(script); 3072 return set_maps(script);
3045} 3073}
3046 3074
3047static int process_feature_event(struct perf_tool *tool, 3075static int process_feature_event(struct perf_session *session,
3048 union perf_event *event, 3076 union perf_event *event)
3049 struct perf_session *session)
3050{ 3077{
3051 if (event->feat.feat_id < HEADER_LAST_FEATURE) 3078 if (event->feat.feat_id < HEADER_LAST_FEATURE)
3052 return perf_event__process_feature(tool, event, session); 3079 return perf_event__process_feature(session, event);
3053 return 0; 3080 return 0;
3054} 3081}
3055 3082
3056#ifdef HAVE_AUXTRACE_SUPPORT 3083#ifdef HAVE_AUXTRACE_SUPPORT
3057static int perf_script__process_auxtrace_info(struct perf_tool *tool, 3084static int perf_script__process_auxtrace_info(struct perf_session *session,
3058 union perf_event *event, 3085 union perf_event *event)
3059 struct perf_session *session)
3060{ 3086{
3061 int ret = perf_event__process_auxtrace_info(tool, event, session); 3087 struct perf_tool *tool = session->tool;
3088
3089 int ret = perf_event__process_auxtrace_info(session, event);
3062 3090
3063 if (ret == 0) { 3091 if (ret == 0) {
3064 struct perf_script *script = container_of(tool, struct perf_script, tool); 3092 struct perf_script *script = container_of(tool, struct perf_script, tool);
@@ -3193,7 +3221,7 @@ int cmd_script(int argc, const char **argv)
3193 OPT_BOOLEAN(0, "ns", &nanosecs, 3221 OPT_BOOLEAN(0, "ns", &nanosecs,
3194 "Use 9 decimal places when displaying time"), 3222 "Use 9 decimal places when displaying time"),
3195 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", 3223 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
3196 "Instruction Tracing options", 3224 "Instruction Tracing options\n" ITRACE_HELP,
3197 itrace_parse_synth_opts), 3225 itrace_parse_synth_opts),
3198 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename, 3226 OPT_BOOLEAN(0, "full-source-path", &srcline_full_filename,
3199 "Show full source file name path for source lines"), 3227 "Show full source file name path for source lines"),
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index d097b5b47eb8..b86aba1c8028 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -88,8 +88,6 @@
88#include "sane_ctype.h" 88#include "sane_ctype.h"
89 89
90#define DEFAULT_SEPARATOR " " 90#define DEFAULT_SEPARATOR " "
91#define CNTR_NOT_SUPPORTED "<not supported>"
92#define CNTR_NOT_COUNTED "<not counted>"
93#define FREEZE_ON_SMI_PATH "devices/cpu/freeze_on_smi" 91#define FREEZE_ON_SMI_PATH "devices/cpu/freeze_on_smi"
94 92
95static void print_counters(struct timespec *ts, int argc, const char **argv); 93static void print_counters(struct timespec *ts, int argc, const char **argv);
@@ -137,54 +135,30 @@ static const char *smi_cost_attrs = {
137 135
138static struct perf_evlist *evsel_list; 136static struct perf_evlist *evsel_list;
139 137
140static struct rblist metric_events;
141
142static struct target target = { 138static struct target target = {
143 .uid = UINT_MAX, 139 .uid = UINT_MAX,
144}; 140};
145 141
146typedef int (*aggr_get_id_t)(struct cpu_map *m, int cpu);
147
148#define METRIC_ONLY_LEN 20 142#define METRIC_ONLY_LEN 20
149 143
150static int run_count = 1;
151static bool no_inherit = false;
152static volatile pid_t child_pid = -1; 144static volatile pid_t child_pid = -1;
153static bool null_run = false;
154static int detailed_run = 0; 145static int detailed_run = 0;
155static bool transaction_run; 146static bool transaction_run;
156static bool topdown_run = false; 147static bool topdown_run = false;
157static bool smi_cost = false; 148static bool smi_cost = false;
158static bool smi_reset = false; 149static bool smi_reset = false;
159static bool big_num = true;
160static int big_num_opt = -1; 150static int big_num_opt = -1;
161static const char *csv_sep = NULL;
162static bool csv_output = false;
163static bool group = false; 151static bool group = false;
164static const char *pre_cmd = NULL; 152static const char *pre_cmd = NULL;
165static const char *post_cmd = NULL; 153static const char *post_cmd = NULL;
166static bool sync_run = false; 154static bool sync_run = false;
167static unsigned int initial_delay = 0;
168static unsigned int unit_width = 4; /* strlen("unit") */
169static bool forever = false; 155static bool forever = false;
170static bool metric_only = false;
171static bool force_metric_only = false; 156static bool force_metric_only = false;
172static bool no_merge = false;
173static bool walltime_run_table = false;
174static struct timespec ref_time; 157static struct timespec ref_time;
175static struct cpu_map *aggr_map;
176static aggr_get_id_t aggr_get_id;
177static bool append_file; 158static bool append_file;
178static bool interval_count; 159static bool interval_count;
179static bool interval_clear;
180static const char *output_name; 160static const char *output_name;
181static int output_fd; 161static int output_fd;
182static int print_free_counters_hint;
183static int print_mixed_hw_group_error;
184static u64 *walltime_run;
185static bool ru_display = false;
186static struct rusage ru_data;
187static unsigned int metric_only_len = METRIC_ONLY_LEN;
188 162
189struct perf_stat { 163struct perf_stat {
190 bool record; 164 bool record;
@@ -204,15 +178,15 @@ static struct perf_stat perf_stat;
204static volatile int done = 0; 178static volatile int done = 0;
205 179
206static struct perf_stat_config stat_config = { 180static struct perf_stat_config stat_config = {
207 .aggr_mode = AGGR_GLOBAL, 181 .aggr_mode = AGGR_GLOBAL,
208 .scale = true, 182 .scale = true,
183 .unit_width = 4, /* strlen("unit") */
184 .run_count = 1,
185 .metric_only_len = METRIC_ONLY_LEN,
186 .walltime_nsecs_stats = &walltime_nsecs_stats,
187 .big_num = true,
209}; 188};
210 189
211static bool is_duration_time(struct perf_evsel *evsel)
212{
213 return !strcmp(evsel->name, "duration_time");
214}
215
216static inline void diff_timespec(struct timespec *r, struct timespec *a, 190static inline void diff_timespec(struct timespec *r, struct timespec *a,
217 struct timespec *b) 191 struct timespec *b)
218{ 192{
@@ -236,66 +210,6 @@ static void perf_stat__reset_stats(void)
236 perf_stat__reset_shadow_per_stat(&stat_config.stats[i]); 210 perf_stat__reset_shadow_per_stat(&stat_config.stats[i]);
237} 211}
238 212
239static int create_perf_stat_counter(struct perf_evsel *evsel)
240{
241 struct perf_event_attr *attr = &evsel->attr;
242 struct perf_evsel *leader = evsel->leader;
243
244 if (stat_config.scale) {
245 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
246 PERF_FORMAT_TOTAL_TIME_RUNNING;
247 }
248
249 /*
250 * The event is part of non trivial group, let's enable
251 * the group read (for leader) and ID retrieval for all
252 * members.
253 */
254 if (leader->nr_members > 1)
255 attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
256
257 attr->inherit = !no_inherit;
258
259 /*
260 * Some events get initialized with sample_(period/type) set,
261 * like tracepoints. Clear it up for counting.
262 */
263 attr->sample_period = 0;
264
265 /*
266 * But set sample_type to PERF_SAMPLE_IDENTIFIER, which should be harmless
267 * while avoiding that older tools show confusing messages.
268 *
269 * However for pipe sessions we need to keep it zero,
270 * because script's perf_evsel__check_attr is triggered
271 * by attr->sample_type != 0, and we can't run it on
272 * stat sessions.
273 */
274 if (!(STAT_RECORD && perf_stat.data.is_pipe))
275 attr->sample_type = PERF_SAMPLE_IDENTIFIER;
276
277 /*
278 * Disabling all counters initially, they will be enabled
279 * either manually by us or by kernel via enable_on_exec
280 * set later.
281 */
282 if (perf_evsel__is_group_leader(evsel)) {
283 attr->disabled = 1;
284
285 /*
286 * In case of initial_delay we enable tracee
287 * events manually.
288 */
289 if (target__none(&target) && !initial_delay)
290 attr->enable_on_exec = 1;
291 }
292
293 if (target__has_cpu(&target) && !target__has_per_thread(&target))
294 return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
295
296 return perf_evsel__open_per_thread(evsel, evsel_list->threads);
297}
298
299static int process_synthesized_event(struct perf_tool *tool __maybe_unused, 213static int process_synthesized_event(struct perf_tool *tool __maybe_unused,
300 union perf_event *event, 214 union perf_event *event,
301 struct perf_sample *sample __maybe_unused, 215 struct perf_sample *sample __maybe_unused,
@@ -428,15 +342,15 @@ static void process_interval(void)
428 342
429static void enable_counters(void) 343static void enable_counters(void)
430{ 344{
431 if (initial_delay) 345 if (stat_config.initial_delay)
432 usleep(initial_delay * USEC_PER_MSEC); 346 usleep(stat_config.initial_delay * USEC_PER_MSEC);
433 347
434 /* 348 /*
435 * We need to enable counters only if: 349 * We need to enable counters only if:
436 * - we don't have tracee (attaching to task or cpu) 350 * - we don't have tracee (attaching to task or cpu)
437 * - we have initial delay configured 351 * - we have initial delay configured
438 */ 352 */
439 if (!target__none(&target) || initial_delay) 353 if (!target__none(&target) || stat_config.initial_delay)
440 perf_evlist__enable(evsel_list); 354 perf_evlist__enable(evsel_list);
441} 355}
442 356
@@ -464,80 +378,6 @@ static void workload_exec_failed_signal(int signo __maybe_unused, siginfo_t *inf
464 workload_exec_errno = info->si_value.sival_int; 378 workload_exec_errno = info->si_value.sival_int;
465} 379}
466 380
467static int perf_stat_synthesize_config(bool is_pipe)
468{
469 int err;
470
471 if (is_pipe) {
472 err = perf_event__synthesize_attrs(NULL, perf_stat.session,
473 process_synthesized_event);
474 if (err < 0) {
475 pr_err("Couldn't synthesize attrs.\n");
476 return err;
477 }
478 }
479
480 err = perf_event__synthesize_extra_attr(NULL,
481 evsel_list,
482 process_synthesized_event,
483 is_pipe);
484
485 err = perf_event__synthesize_thread_map2(NULL, evsel_list->threads,
486 process_synthesized_event,
487 NULL);
488 if (err < 0) {
489 pr_err("Couldn't synthesize thread map.\n");
490 return err;
491 }
492
493 err = perf_event__synthesize_cpu_map(NULL, evsel_list->cpus,
494 process_synthesized_event, NULL);
495 if (err < 0) {
496 pr_err("Couldn't synthesize thread map.\n");
497 return err;
498 }
499
500 err = perf_event__synthesize_stat_config(NULL, &stat_config,
501 process_synthesized_event, NULL);
502 if (err < 0) {
503 pr_err("Couldn't synthesize config.\n");
504 return err;
505 }
506
507 return 0;
508}
509
510#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
511
512static int __store_counter_ids(struct perf_evsel *counter)
513{
514 int cpu, thread;
515
516 for (cpu = 0; cpu < xyarray__max_x(counter->fd); cpu++) {
517 for (thread = 0; thread < xyarray__max_y(counter->fd);
518 thread++) {
519 int fd = FD(counter, cpu, thread);
520
521 if (perf_evlist__id_add_fd(evsel_list, counter,
522 cpu, thread, fd) < 0)
523 return -1;
524 }
525 }
526
527 return 0;
528}
529
530static int store_counter_ids(struct perf_evsel *counter)
531{
532 struct cpu_map *cpus = counter->cpus;
533 struct thread_map *threads = counter->threads;
534
535 if (perf_evsel__alloc_id(counter, cpus->nr, threads->nr))
536 return -ENOMEM;
537
538 return __store_counter_ids(counter);
539}
540
541static bool perf_evsel__should_store_id(struct perf_evsel *counter) 381static bool perf_evsel__should_store_id(struct perf_evsel *counter)
542{ 382{
543 return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID; 383 return STAT_RECORD || counter->attr.read_format & PERF_FORMAT_ID;
@@ -609,7 +449,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
609 449
610 evlist__for_each_entry(evsel_list, counter) { 450 evlist__for_each_entry(evsel_list, counter) {
611try_again: 451try_again:
612 if (create_perf_stat_counter(counter) < 0) { 452 if (create_perf_stat_counter(counter, &stat_config, &target) < 0) {
613 453
614 /* Weak group failed. Reset the group. */ 454 /* Weak group failed. Reset the group. */
615 if ((errno == EINVAL || errno == EBADF) && 455 if ((errno == EINVAL || errno == EBADF) &&
@@ -664,11 +504,11 @@ try_again:
664 counter->supported = true; 504 counter->supported = true;
665 505
666 l = strlen(counter->unit); 506 l = strlen(counter->unit);
667 if (l > unit_width) 507 if (l > stat_config.unit_width)
668 unit_width = l; 508 stat_config.unit_width = l;
669 509
670 if (perf_evsel__should_store_id(counter) && 510 if (perf_evsel__should_store_id(counter) &&
671 store_counter_ids(counter)) 511 perf_evsel__store_ids(counter, evsel_list))
672 return -1; 512 return -1;
673 } 513 }
674 514
@@ -699,7 +539,8 @@ try_again:
699 if (err < 0) 539 if (err < 0)
700 return err; 540 return err;
701 541
702 err = perf_stat_synthesize_config(is_pipe); 542 err = perf_stat_synthesize_config(&stat_config, NULL, evsel_list,
543 process_synthesized_event, is_pipe);
703 if (err < 0) 544 if (err < 0)
704 return err; 545 return err;
705 } 546 }
@@ -724,7 +565,7 @@ try_again:
724 break; 565 break;
725 } 566 }
726 } 567 }
727 wait4(child_pid, &status, 0, &ru_data); 568 wait4(child_pid, &status, 0, &stat_config.ru_data);
728 569
729 if (workload_exec_errno) { 570 if (workload_exec_errno) {
730 const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg)); 571 const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
@@ -752,8 +593,8 @@ try_again:
752 593
753 t1 = rdclock(); 594 t1 = rdclock();
754 595
755 if (walltime_run_table) 596 if (stat_config.walltime_run_table)
756 walltime_run[run_idx] = t1 - t0; 597 stat_config.walltime_run[run_idx] = t1 - t0;
757 598
758 update_stats(&walltime_nsecs_stats, t1 - t0); 599 update_stats(&walltime_nsecs_stats, t1 - t0);
759 600
@@ -795,1105 +636,14 @@ static int run_perf_stat(int argc, const char **argv, int run_idx)
795 return ret; 636 return ret;
796} 637}
797 638
798static void print_running(u64 run, u64 ena)
799{
800 if (csv_output) {
801 fprintf(stat_config.output, "%s%" PRIu64 "%s%.2f",
802 csv_sep,
803 run,
804 csv_sep,
805 ena ? 100.0 * run / ena : 100.0);
806 } else if (run != ena) {
807 fprintf(stat_config.output, " (%.2f%%)", 100.0 * run / ena);
808 }
809}
810
811static void print_noise_pct(double total, double avg)
812{
813 double pct = rel_stddev_stats(total, avg);
814
815 if (csv_output)
816 fprintf(stat_config.output, "%s%.2f%%", csv_sep, pct);
817 else if (pct)
818 fprintf(stat_config.output, " ( +-%6.2f%% )", pct);
819}
820
821static void print_noise(struct perf_evsel *evsel, double avg)
822{
823 struct perf_stat_evsel *ps;
824
825 if (run_count == 1)
826 return;
827
828 ps = evsel->stats;
829 print_noise_pct(stddev_stats(&ps->res_stats[0]), avg);
830}
831
832static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
833{
834 switch (stat_config.aggr_mode) {
835 case AGGR_CORE:
836 fprintf(stat_config.output, "S%d-C%*d%s%*d%s",
837 cpu_map__id_to_socket(id),
838 csv_output ? 0 : -8,
839 cpu_map__id_to_cpu(id),
840 csv_sep,
841 csv_output ? 0 : 4,
842 nr,
843 csv_sep);
844 break;
845 case AGGR_SOCKET:
846 fprintf(stat_config.output, "S%*d%s%*d%s",
847 csv_output ? 0 : -5,
848 id,
849 csv_sep,
850 csv_output ? 0 : 4,
851 nr,
852 csv_sep);
853 break;
854 case AGGR_NONE:
855 fprintf(stat_config.output, "CPU%*d%s",
856 csv_output ? 0 : -4,
857 perf_evsel__cpus(evsel)->map[id], csv_sep);
858 break;
859 case AGGR_THREAD:
860 fprintf(stat_config.output, "%*s-%*d%s",
861 csv_output ? 0 : 16,
862 thread_map__comm(evsel->threads, id),
863 csv_output ? 0 : -8,
864 thread_map__pid(evsel->threads, id),
865 csv_sep);
866 break;
867 case AGGR_GLOBAL:
868 case AGGR_UNSET:
869 default:
870 break;
871 }
872}
873
874struct outstate {
875 FILE *fh;
876 bool newline;
877 const char *prefix;
878 int nfields;
879 int id, nr;
880 struct perf_evsel *evsel;
881};
882
883#define METRIC_LEN 35
884
885static void new_line_std(void *ctx)
886{
887 struct outstate *os = ctx;
888
889 os->newline = true;
890}
891
892static void do_new_line_std(struct outstate *os)
893{
894 fputc('\n', os->fh);
895 fputs(os->prefix, os->fh);
896 aggr_printout(os->evsel, os->id, os->nr);
897 if (stat_config.aggr_mode == AGGR_NONE)
898 fprintf(os->fh, " ");
899 fprintf(os->fh, " ");
900}
901
902static void print_metric_std(void *ctx, const char *color, const char *fmt,
903 const char *unit, double val)
904{
905 struct outstate *os = ctx;
906 FILE *out = os->fh;
907 int n;
908 bool newline = os->newline;
909
910 os->newline = false;
911
912 if (unit == NULL || fmt == NULL) {
913 fprintf(out, "%-*s", METRIC_LEN, "");
914 return;
915 }
916
917 if (newline)
918 do_new_line_std(os);
919
920 n = fprintf(out, " # ");
921 if (color)
922 n += color_fprintf(out, color, fmt, val);
923 else
924 n += fprintf(out, fmt, val);
925 fprintf(out, " %-*s", METRIC_LEN - n - 1, unit);
926}
927
928static void new_line_csv(void *ctx)
929{
930 struct outstate *os = ctx;
931 int i;
932
933 fputc('\n', os->fh);
934 if (os->prefix)
935 fprintf(os->fh, "%s%s", os->prefix, csv_sep);
936 aggr_printout(os->evsel, os->id, os->nr);
937 for (i = 0; i < os->nfields; i++)
938 fputs(csv_sep, os->fh);
939}
940
941static void print_metric_csv(void *ctx,
942 const char *color __maybe_unused,
943 const char *fmt, const char *unit, double val)
944{
945 struct outstate *os = ctx;
946 FILE *out = os->fh;
947 char buf[64], *vals, *ends;
948
949 if (unit == NULL || fmt == NULL) {
950 fprintf(out, "%s%s", csv_sep, csv_sep);
951 return;
952 }
953 snprintf(buf, sizeof(buf), fmt, val);
954 ends = vals = ltrim(buf);
955 while (isdigit(*ends) || *ends == '.')
956 ends++;
957 *ends = 0;
958 while (isspace(*unit))
959 unit++;
960 fprintf(out, "%s%s%s%s", csv_sep, vals, csv_sep, unit);
961}
962
963/* Filter out some columns that don't work well in metrics only mode */
964
965static bool valid_only_metric(const char *unit)
966{
967 if (!unit)
968 return false;
969 if (strstr(unit, "/sec") ||
970 strstr(unit, "hz") ||
971 strstr(unit, "Hz") ||
972 strstr(unit, "CPUs utilized"))
973 return false;
974 return true;
975}
976
977static const char *fixunit(char *buf, struct perf_evsel *evsel,
978 const char *unit)
979{
980 if (!strncmp(unit, "of all", 6)) {
981 snprintf(buf, 1024, "%s %s", perf_evsel__name(evsel),
982 unit);
983 return buf;
984 }
985 return unit;
986}
987
988static void print_metric_only(void *ctx, const char *color, const char *fmt,
989 const char *unit, double val)
990{
991 struct outstate *os = ctx;
992 FILE *out = os->fh;
993 char buf[1024], str[1024];
994 unsigned mlen = metric_only_len;
995
996 if (!valid_only_metric(unit))
997 return;
998 unit = fixunit(buf, os->evsel, unit);
999 if (mlen < strlen(unit))
1000 mlen = strlen(unit) + 1;
1001
1002 if (color)
1003 mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1;
1004
1005 color_snprintf(str, sizeof(str), color ?: "", fmt, val);
1006 fprintf(out, "%*s ", mlen, str);
1007}
1008
1009static void print_metric_only_csv(void *ctx, const char *color __maybe_unused,
1010 const char *fmt,
1011 const char *unit, double val)
1012{
1013 struct outstate *os = ctx;
1014 FILE *out = os->fh;
1015 char buf[64], *vals, *ends;
1016 char tbuf[1024];
1017
1018 if (!valid_only_metric(unit))
1019 return;
1020 unit = fixunit(tbuf, os->evsel, unit);
1021 snprintf(buf, sizeof buf, fmt, val);
1022 ends = vals = ltrim(buf);
1023 while (isdigit(*ends) || *ends == '.')
1024 ends++;
1025 *ends = 0;
1026 fprintf(out, "%s%s", vals, csv_sep);
1027}
1028
1029static void new_line_metric(void *ctx __maybe_unused)
1030{
1031}
1032
1033static void print_metric_header(void *ctx, const char *color __maybe_unused,
1034 const char *fmt __maybe_unused,
1035 const char *unit, double val __maybe_unused)
1036{
1037 struct outstate *os = ctx;
1038 char tbuf[1024];
1039
1040 if (!valid_only_metric(unit))
1041 return;
1042 unit = fixunit(tbuf, os->evsel, unit);
1043 if (csv_output)
1044 fprintf(os->fh, "%s%s", unit, csv_sep);
1045 else
1046 fprintf(os->fh, "%*s ", metric_only_len, unit);
1047}
1048
1049static int first_shadow_cpu(struct perf_evsel *evsel, int id)
1050{
1051 int i;
1052
1053 if (!aggr_get_id)
1054 return 0;
1055
1056 if (stat_config.aggr_mode == AGGR_NONE)
1057 return id;
1058
1059 if (stat_config.aggr_mode == AGGR_GLOBAL)
1060 return 0;
1061
1062 for (i = 0; i < perf_evsel__nr_cpus(evsel); i++) {
1063 int cpu2 = perf_evsel__cpus(evsel)->map[i];
1064
1065 if (aggr_get_id(evsel_list->cpus, cpu2) == id)
1066 return cpu2;
1067 }
1068 return 0;
1069}
1070
1071static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)
1072{
1073 FILE *output = stat_config.output;
1074 double sc = evsel->scale;
1075 const char *fmt;
1076
1077 if (csv_output) {
1078 fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s";
1079 } else {
1080 if (big_num)
1081 fmt = floor(sc) != sc ? "%'18.2f%s" : "%'18.0f%s";
1082 else
1083 fmt = floor(sc) != sc ? "%18.2f%s" : "%18.0f%s";
1084 }
1085
1086 aggr_printout(evsel, id, nr);
1087
1088 fprintf(output, fmt, avg, csv_sep);
1089
1090 if (evsel->unit)
1091 fprintf(output, "%-*s%s",
1092 csv_output ? 0 : unit_width,
1093 evsel->unit, csv_sep);
1094
1095 fprintf(output, "%-*s", csv_output ? 0 : 25, perf_evsel__name(evsel));
1096
1097 if (evsel->cgrp)
1098 fprintf(output, "%s%s", csv_sep, evsel->cgrp->name);
1099}
1100
1101static bool is_mixed_hw_group(struct perf_evsel *counter)
1102{
1103 struct perf_evlist *evlist = counter->evlist;
1104 u32 pmu_type = counter->attr.type;
1105 struct perf_evsel *pos;
1106
1107 if (counter->nr_members < 2)
1108 return false;
1109
1110 evlist__for_each_entry(evlist, pos) {
1111 /* software events can be part of any hardware group */
1112 if (pos->attr.type == PERF_TYPE_SOFTWARE)
1113 continue;
1114 if (pmu_type == PERF_TYPE_SOFTWARE) {
1115 pmu_type = pos->attr.type;
1116 continue;
1117 }
1118 if (pmu_type != pos->attr.type)
1119 return true;
1120 }
1121
1122 return false;
1123}
1124
1125static void printout(int id, int nr, struct perf_evsel *counter, double uval,
1126 char *prefix, u64 run, u64 ena, double noise,
1127 struct runtime_stat *st)
1128{
1129 struct perf_stat_output_ctx out;
1130 struct outstate os = {
1131 .fh = stat_config.output,
1132 .prefix = prefix ? prefix : "",
1133 .id = id,
1134 .nr = nr,
1135 .evsel = counter,
1136 };
1137 print_metric_t pm = print_metric_std;
1138 void (*nl)(void *);
1139
1140 if (metric_only) {
1141 nl = new_line_metric;
1142 if (csv_output)
1143 pm = print_metric_only_csv;
1144 else
1145 pm = print_metric_only;
1146 } else
1147 nl = new_line_std;
1148
1149 if (csv_output && !metric_only) {
1150 static int aggr_fields[] = {
1151 [AGGR_GLOBAL] = 0,
1152 [AGGR_THREAD] = 1,
1153 [AGGR_NONE] = 1,
1154 [AGGR_SOCKET] = 2,
1155 [AGGR_CORE] = 2,
1156 };
1157
1158 pm = print_metric_csv;
1159 nl = new_line_csv;
1160 os.nfields = 3;
1161 os.nfields += aggr_fields[stat_config.aggr_mode];
1162 if (counter->cgrp)
1163 os.nfields++;
1164 }
1165 if (run == 0 || ena == 0 || counter->counts->scaled == -1) {
1166 if (metric_only) {
1167 pm(&os, NULL, "", "", 0);
1168 return;
1169 }
1170 aggr_printout(counter, id, nr);
1171
1172 fprintf(stat_config.output, "%*s%s",
1173 csv_output ? 0 : 18,
1174 counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED,
1175 csv_sep);
1176
1177 if (counter->supported) {
1178 print_free_counters_hint = 1;
1179 if (is_mixed_hw_group(counter))
1180 print_mixed_hw_group_error = 1;
1181 }
1182
1183 fprintf(stat_config.output, "%-*s%s",
1184 csv_output ? 0 : unit_width,
1185 counter->unit, csv_sep);
1186
1187 fprintf(stat_config.output, "%*s",
1188 csv_output ? 0 : -25,
1189 perf_evsel__name(counter));
1190
1191 if (counter->cgrp)
1192 fprintf(stat_config.output, "%s%s",
1193 csv_sep, counter->cgrp->name);
1194
1195 if (!csv_output)
1196 pm(&os, NULL, NULL, "", 0);
1197 print_noise(counter, noise);
1198 print_running(run, ena);
1199 if (csv_output)
1200 pm(&os, NULL, NULL, "", 0);
1201 return;
1202 }
1203
1204 if (!metric_only)
1205 abs_printout(id, nr, counter, uval);
1206
1207 out.print_metric = pm;
1208 out.new_line = nl;
1209 out.ctx = &os;
1210 out.force_header = false;
1211
1212 if (csv_output && !metric_only) {
1213 print_noise(counter, noise);
1214 print_running(run, ena);
1215 }
1216
1217 perf_stat__print_shadow_stats(counter, uval,
1218 first_shadow_cpu(counter, id),
1219 &out, &metric_events, st);
1220 if (!csv_output && !metric_only) {
1221 print_noise(counter, noise);
1222 print_running(run, ena);
1223 }
1224}
1225
1226static void aggr_update_shadow(void)
1227{
1228 int cpu, s2, id, s;
1229 u64 val;
1230 struct perf_evsel *counter;
1231
1232 for (s = 0; s < aggr_map->nr; s++) {
1233 id = aggr_map->map[s];
1234 evlist__for_each_entry(evsel_list, counter) {
1235 val = 0;
1236 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
1237 s2 = aggr_get_id(evsel_list->cpus, cpu);
1238 if (s2 != id)
1239 continue;
1240 val += perf_counts(counter->counts, cpu, 0)->val;
1241 }
1242 perf_stat__update_shadow_stats(counter, val,
1243 first_shadow_cpu(counter, id),
1244 &rt_stat);
1245 }
1246 }
1247}
1248
1249static void uniquify_event_name(struct perf_evsel *counter)
1250{
1251 char *new_name;
1252 char *config;
1253
1254 if (counter->uniquified_name ||
1255 !counter->pmu_name || !strncmp(counter->name, counter->pmu_name,
1256 strlen(counter->pmu_name)))
1257 return;
1258
1259 config = strchr(counter->name, '/');
1260 if (config) {
1261 if (asprintf(&new_name,
1262 "%s%s", counter->pmu_name, config) > 0) {
1263 free(counter->name);
1264 counter->name = new_name;
1265 }
1266 } else {
1267 if (asprintf(&new_name,
1268 "%s [%s]", counter->name, counter->pmu_name) > 0) {
1269 free(counter->name);
1270 counter->name = new_name;
1271 }
1272 }
1273
1274 counter->uniquified_name = true;
1275}
1276
1277static void collect_all_aliases(struct perf_evsel *counter,
1278 void (*cb)(struct perf_evsel *counter, void *data,
1279 bool first),
1280 void *data)
1281{
1282 struct perf_evsel *alias;
1283
1284 alias = list_prepare_entry(counter, &(evsel_list->entries), node);
1285 list_for_each_entry_continue (alias, &evsel_list->entries, node) {
1286 if (strcmp(perf_evsel__name(alias), perf_evsel__name(counter)) ||
1287 alias->scale != counter->scale ||
1288 alias->cgrp != counter->cgrp ||
1289 strcmp(alias->unit, counter->unit) ||
1290 perf_evsel__is_clock(alias) != perf_evsel__is_clock(counter))
1291 break;
1292 alias->merged_stat = true;
1293 cb(alias, data, false);
1294 }
1295}
1296
1297static bool collect_data(struct perf_evsel *counter,
1298 void (*cb)(struct perf_evsel *counter, void *data,
1299 bool first),
1300 void *data)
1301{
1302 if (counter->merged_stat)
1303 return false;
1304 cb(counter, data, true);
1305 if (no_merge)
1306 uniquify_event_name(counter);
1307 else if (counter->auto_merge_stats)
1308 collect_all_aliases(counter, cb, data);
1309 return true;
1310}
1311
1312struct aggr_data {
1313 u64 ena, run, val;
1314 int id;
1315 int nr;
1316 int cpu;
1317};
1318
1319static void aggr_cb(struct perf_evsel *counter, void *data, bool first)
1320{
1321 struct aggr_data *ad = data;
1322 int cpu, s2;
1323
1324 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
1325 struct perf_counts_values *counts;
1326
1327 s2 = aggr_get_id(perf_evsel__cpus(counter), cpu);
1328 if (s2 != ad->id)
1329 continue;
1330 if (first)
1331 ad->nr++;
1332 counts = perf_counts(counter->counts, cpu, 0);
1333 /*
1334 * When any result is bad, make them all to give
1335 * consistent output in interval mode.
1336 */
1337 if (counts->ena == 0 || counts->run == 0 ||
1338 counter->counts->scaled == -1) {
1339 ad->ena = 0;
1340 ad->run = 0;
1341 break;
1342 }
1343 ad->val += counts->val;
1344 ad->ena += counts->ena;
1345 ad->run += counts->run;
1346 }
1347}
1348
1349static void print_aggr(char *prefix)
1350{
1351 FILE *output = stat_config.output;
1352 struct perf_evsel *counter;
1353 int s, id, nr;
1354 double uval;
1355 u64 ena, run, val;
1356 bool first;
1357
1358 if (!(aggr_map || aggr_get_id))
1359 return;
1360
1361 aggr_update_shadow();
1362
1363 /*
1364 * With metric_only everything is on a single line.
1365 * Without each counter has its own line.
1366 */
1367 for (s = 0; s < aggr_map->nr; s++) {
1368 struct aggr_data ad;
1369 if (prefix && metric_only)
1370 fprintf(output, "%s", prefix);
1371
1372 ad.id = id = aggr_map->map[s];
1373 first = true;
1374 evlist__for_each_entry(evsel_list, counter) {
1375 if (is_duration_time(counter))
1376 continue;
1377
1378 ad.val = ad.ena = ad.run = 0;
1379 ad.nr = 0;
1380 if (!collect_data(counter, aggr_cb, &ad))
1381 continue;
1382 nr = ad.nr;
1383 ena = ad.ena;
1384 run = ad.run;
1385 val = ad.val;
1386 if (first && metric_only) {
1387 first = false;
1388 aggr_printout(counter, id, nr);
1389 }
1390 if (prefix && !metric_only)
1391 fprintf(output, "%s", prefix);
1392
1393 uval = val * counter->scale;
1394 printout(id, nr, counter, uval, prefix, run, ena, 1.0,
1395 &rt_stat);
1396 if (!metric_only)
1397 fputc('\n', output);
1398 }
1399 if (metric_only)
1400 fputc('\n', output);
1401 }
1402}
1403
1404static int cmp_val(const void *a, const void *b)
1405{
1406 return ((struct perf_aggr_thread_value *)b)->val -
1407 ((struct perf_aggr_thread_value *)a)->val;
1408}
1409
1410static struct perf_aggr_thread_value *sort_aggr_thread(
1411 struct perf_evsel *counter,
1412 int nthreads, int ncpus,
1413 int *ret)
1414{
1415 int cpu, thread, i = 0;
1416 double uval;
1417 struct perf_aggr_thread_value *buf;
1418
1419 buf = calloc(nthreads, sizeof(struct perf_aggr_thread_value));
1420 if (!buf)
1421 return NULL;
1422
1423 for (thread = 0; thread < nthreads; thread++) {
1424 u64 ena = 0, run = 0, val = 0;
1425
1426 for (cpu = 0; cpu < ncpus; cpu++) {
1427 val += perf_counts(counter->counts, cpu, thread)->val;
1428 ena += perf_counts(counter->counts, cpu, thread)->ena;
1429 run += perf_counts(counter->counts, cpu, thread)->run;
1430 }
1431
1432 uval = val * counter->scale;
1433
1434 /*
1435 * Skip value 0 when enabling --per-thread globally,
1436 * otherwise too many 0 output.
1437 */
1438 if (uval == 0.0 && target__has_per_thread(&target))
1439 continue;
1440
1441 buf[i].counter = counter;
1442 buf[i].id = thread;
1443 buf[i].uval = uval;
1444 buf[i].val = val;
1445 buf[i].run = run;
1446 buf[i].ena = ena;
1447 i++;
1448 }
1449
1450 qsort(buf, i, sizeof(struct perf_aggr_thread_value), cmp_val);
1451
1452 if (ret)
1453 *ret = i;
1454
1455 return buf;
1456}
1457
1458static void print_aggr_thread(struct perf_evsel *counter, char *prefix)
1459{
1460 FILE *output = stat_config.output;
1461 int nthreads = thread_map__nr(counter->threads);
1462 int ncpus = cpu_map__nr(counter->cpus);
1463 int thread, sorted_threads, id;
1464 struct perf_aggr_thread_value *buf;
1465
1466 buf = sort_aggr_thread(counter, nthreads, ncpus, &sorted_threads);
1467 if (!buf) {
1468 perror("cannot sort aggr thread");
1469 return;
1470 }
1471
1472 for (thread = 0; thread < sorted_threads; thread++) {
1473 if (prefix)
1474 fprintf(output, "%s", prefix);
1475
1476 id = buf[thread].id;
1477 if (stat_config.stats)
1478 printout(id, 0, buf[thread].counter, buf[thread].uval,
1479 prefix, buf[thread].run, buf[thread].ena, 1.0,
1480 &stat_config.stats[id]);
1481 else
1482 printout(id, 0, buf[thread].counter, buf[thread].uval,
1483 prefix, buf[thread].run, buf[thread].ena, 1.0,
1484 &rt_stat);
1485 fputc('\n', output);
1486 }
1487
1488 free(buf);
1489}
1490
1491struct caggr_data {
1492 double avg, avg_enabled, avg_running;
1493};
1494
1495static void counter_aggr_cb(struct perf_evsel *counter, void *data,
1496 bool first __maybe_unused)
1497{
1498 struct caggr_data *cd = data;
1499 struct perf_stat_evsel *ps = counter->stats;
1500
1501 cd->avg += avg_stats(&ps->res_stats[0]);
1502 cd->avg_enabled += avg_stats(&ps->res_stats[1]);
1503 cd->avg_running += avg_stats(&ps->res_stats[2]);
1504}
1505
1506/*
1507 * Print out the results of a single counter:
1508 * aggregated counts in system-wide mode
1509 */
1510static void print_counter_aggr(struct perf_evsel *counter, char *prefix)
1511{
1512 FILE *output = stat_config.output;
1513 double uval;
1514 struct caggr_data cd = { .avg = 0.0 };
1515
1516 if (!collect_data(counter, counter_aggr_cb, &cd))
1517 return;
1518
1519 if (prefix && !metric_only)
1520 fprintf(output, "%s", prefix);
1521
1522 uval = cd.avg * counter->scale;
1523 printout(-1, 0, counter, uval, prefix, cd.avg_running, cd.avg_enabled,
1524 cd.avg, &rt_stat);
1525 if (!metric_only)
1526 fprintf(output, "\n");
1527}
1528
1529static void counter_cb(struct perf_evsel *counter, void *data,
1530 bool first __maybe_unused)
1531{
1532 struct aggr_data *ad = data;
1533
1534 ad->val += perf_counts(counter->counts, ad->cpu, 0)->val;
1535 ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena;
1536 ad->run += perf_counts(counter->counts, ad->cpu, 0)->run;
1537}
1538
1539/*
1540 * Print out the results of a single counter:
1541 * does not use aggregated count in system-wide
1542 */
1543static void print_counter(struct perf_evsel *counter, char *prefix)
1544{
1545 FILE *output = stat_config.output;
1546 u64 ena, run, val;
1547 double uval;
1548 int cpu;
1549
1550 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
1551 struct aggr_data ad = { .cpu = cpu };
1552
1553 if (!collect_data(counter, counter_cb, &ad))
1554 return;
1555 val = ad.val;
1556 ena = ad.ena;
1557 run = ad.run;
1558
1559 if (prefix)
1560 fprintf(output, "%s", prefix);
1561
1562 uval = val * counter->scale;
1563 printout(cpu, 0, counter, uval, prefix, run, ena, 1.0,
1564 &rt_stat);
1565
1566 fputc('\n', output);
1567 }
1568}
1569
1570static void print_no_aggr_metric(char *prefix)
1571{
1572 int cpu;
1573 int nrcpus = 0;
1574 struct perf_evsel *counter;
1575 u64 ena, run, val;
1576 double uval;
1577
1578 nrcpus = evsel_list->cpus->nr;
1579 for (cpu = 0; cpu < nrcpus; cpu++) {
1580 bool first = true;
1581
1582 if (prefix)
1583 fputs(prefix, stat_config.output);
1584 evlist__for_each_entry(evsel_list, counter) {
1585 if (is_duration_time(counter))
1586 continue;
1587 if (first) {
1588 aggr_printout(counter, cpu, 0);
1589 first = false;
1590 }
1591 val = perf_counts(counter->counts, cpu, 0)->val;
1592 ena = perf_counts(counter->counts, cpu, 0)->ena;
1593 run = perf_counts(counter->counts, cpu, 0)->run;
1594
1595 uval = val * counter->scale;
1596 printout(cpu, 0, counter, uval, prefix, run, ena, 1.0,
1597 &rt_stat);
1598 }
1599 fputc('\n', stat_config.output);
1600 }
1601}
1602
1603static int aggr_header_lens[] = {
1604 [AGGR_CORE] = 18,
1605 [AGGR_SOCKET] = 12,
1606 [AGGR_NONE] = 6,
1607 [AGGR_THREAD] = 24,
1608 [AGGR_GLOBAL] = 0,
1609};
1610
1611static const char *aggr_header_csv[] = {
1612 [AGGR_CORE] = "core,cpus,",
1613 [AGGR_SOCKET] = "socket,cpus",
1614 [AGGR_NONE] = "cpu,",
1615 [AGGR_THREAD] = "comm-pid,",
1616 [AGGR_GLOBAL] = ""
1617};
1618
1619static void print_metric_headers(const char *prefix, bool no_indent)
1620{
1621 struct perf_stat_output_ctx out;
1622 struct perf_evsel *counter;
1623 struct outstate os = {
1624 .fh = stat_config.output
1625 };
1626
1627 if (prefix)
1628 fprintf(stat_config.output, "%s", prefix);
1629
1630 if (!csv_output && !no_indent)
1631 fprintf(stat_config.output, "%*s",
1632 aggr_header_lens[stat_config.aggr_mode], "");
1633 if (csv_output) {
1634 if (stat_config.interval)
1635 fputs("time,", stat_config.output);
1636 fputs(aggr_header_csv[stat_config.aggr_mode],
1637 stat_config.output);
1638 }
1639
1640 /* Print metrics headers only */
1641 evlist__for_each_entry(evsel_list, counter) {
1642 if (is_duration_time(counter))
1643 continue;
1644 os.evsel = counter;
1645 out.ctx = &os;
1646 out.print_metric = print_metric_header;
1647 out.new_line = new_line_metric;
1648 out.force_header = true;
1649 os.evsel = counter;
1650 perf_stat__print_shadow_stats(counter, 0,
1651 0,
1652 &out,
1653 &metric_events,
1654 &rt_stat);
1655 }
1656 fputc('\n', stat_config.output);
1657}
1658
1659static void print_interval(char *prefix, struct timespec *ts)
1660{
1661 FILE *output = stat_config.output;
1662 static int num_print_interval;
1663
1664 if (interval_clear)
1665 puts(CONSOLE_CLEAR);
1666
1667 sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
1668
1669 if ((num_print_interval == 0 && !csv_output) || interval_clear) {
1670 switch (stat_config.aggr_mode) {
1671 case AGGR_SOCKET:
1672 fprintf(output, "# time socket cpus");
1673 if (!metric_only)
1674 fprintf(output, " counts %*s events\n", unit_width, "unit");
1675 break;
1676 case AGGR_CORE:
1677 fprintf(output, "# time core cpus");
1678 if (!metric_only)
1679 fprintf(output, " counts %*s events\n", unit_width, "unit");
1680 break;
1681 case AGGR_NONE:
1682 fprintf(output, "# time CPU ");
1683 if (!metric_only)
1684 fprintf(output, " counts %*s events\n", unit_width, "unit");
1685 break;
1686 case AGGR_THREAD:
1687 fprintf(output, "# time comm-pid");
1688 if (!metric_only)
1689 fprintf(output, " counts %*s events\n", unit_width, "unit");
1690 break;
1691 case AGGR_GLOBAL:
1692 default:
1693 fprintf(output, "# time");
1694 if (!metric_only)
1695 fprintf(output, " counts %*s events\n", unit_width, "unit");
1696 case AGGR_UNSET:
1697 break;
1698 }
1699 }
1700
1701 if ((num_print_interval == 0 || interval_clear) && metric_only)
1702 print_metric_headers(" ", true);
1703 if (++num_print_interval == 25)
1704 num_print_interval = 0;
1705}
1706
1707static void print_header(int argc, const char **argv)
1708{
1709 FILE *output = stat_config.output;
1710 int i;
1711
1712 fflush(stdout);
1713
1714 if (!csv_output) {
1715 fprintf(output, "\n");
1716 fprintf(output, " Performance counter stats for ");
1717 if (target.system_wide)
1718 fprintf(output, "\'system wide");
1719 else if (target.cpu_list)
1720 fprintf(output, "\'CPU(s) %s", target.cpu_list);
1721 else if (!target__has_task(&target)) {
1722 fprintf(output, "\'%s", argv ? argv[0] : "pipe");
1723 for (i = 1; argv && (i < argc); i++)
1724 fprintf(output, " %s", argv[i]);
1725 } else if (target.pid)
1726 fprintf(output, "process id \'%s", target.pid);
1727 else
1728 fprintf(output, "thread id \'%s", target.tid);
1729
1730 fprintf(output, "\'");
1731 if (run_count > 1)
1732 fprintf(output, " (%d runs)", run_count);
1733 fprintf(output, ":\n\n");
1734 }
1735}
1736
1737static int get_precision(double num)
1738{
1739 if (num > 1)
1740 return 0;
1741
1742 return lround(ceil(-log10(num)));
1743}
1744
1745static void print_table(FILE *output, int precision, double avg)
1746{
1747 char tmp[64];
1748 int idx, indent = 0;
1749
1750 scnprintf(tmp, 64, " %17.*f", precision, avg);
1751 while (tmp[indent] == ' ')
1752 indent++;
1753
1754 fprintf(output, "%*s# Table of individual measurements:\n", indent, "");
1755
1756 for (idx = 0; idx < run_count; idx++) {
1757 double run = (double) walltime_run[idx] / NSEC_PER_SEC;
1758 int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5);
1759
1760 fprintf(output, " %17.*f (%+.*f) ",
1761 precision, run, precision, run - avg);
1762
1763 for (h = 0; h < n; h++)
1764 fprintf(output, "#");
1765
1766 fprintf(output, "\n");
1767 }
1768
1769 fprintf(output, "\n%*s# Final result:\n", indent, "");
1770}
1771
1772static double timeval2double(struct timeval *t)
1773{
1774 return t->tv_sec + (double) t->tv_usec/USEC_PER_SEC;
1775}
1776
1777static void print_footer(void)
1778{
1779 double avg = avg_stats(&walltime_nsecs_stats) / NSEC_PER_SEC;
1780 FILE *output = stat_config.output;
1781 int n;
1782
1783 if (!null_run)
1784 fprintf(output, "\n");
1785
1786 if (run_count == 1) {
1787 fprintf(output, " %17.9f seconds time elapsed", avg);
1788
1789 if (ru_display) {
1790 double ru_utime = timeval2double(&ru_data.ru_utime);
1791 double ru_stime = timeval2double(&ru_data.ru_stime);
1792
1793 fprintf(output, "\n\n");
1794 fprintf(output, " %17.9f seconds user\n", ru_utime);
1795 fprintf(output, " %17.9f seconds sys\n", ru_stime);
1796 }
1797 } else {
1798 double sd = stddev_stats(&walltime_nsecs_stats) / NSEC_PER_SEC;
1799 /*
1800 * Display at most 2 more significant
1801 * digits than the stddev inaccuracy.
1802 */
1803 int precision = get_precision(sd) + 2;
1804
1805 if (walltime_run_table)
1806 print_table(output, precision, avg);
1807
1808 fprintf(output, " %17.*f +- %.*f seconds time elapsed",
1809 precision, avg, precision, sd);
1810
1811 print_noise_pct(sd, avg);
1812 }
1813 fprintf(output, "\n\n");
1814
1815 if (print_free_counters_hint &&
1816 sysctl__read_int("kernel/nmi_watchdog", &n) >= 0 &&
1817 n > 0)
1818 fprintf(output,
1819"Some events weren't counted. Try disabling the NMI watchdog:\n"
1820" echo 0 > /proc/sys/kernel/nmi_watchdog\n"
1821" perf stat ...\n"
1822" echo 1 > /proc/sys/kernel/nmi_watchdog\n");
1823
1824 if (print_mixed_hw_group_error)
1825 fprintf(output,
1826 "The events in group usually have to be from "
1827 "the same PMU. Try reorganizing the group.\n");
1828}
1829
1830static void print_counters(struct timespec *ts, int argc, const char **argv) 639static void print_counters(struct timespec *ts, int argc, const char **argv)
1831{ 640{
1832 int interval = stat_config.interval;
1833 struct perf_evsel *counter;
1834 char buf[64], *prefix = NULL;
1835
1836 /* Do not print anything if we record to the pipe. */ 641 /* Do not print anything if we record to the pipe. */
1837 if (STAT_RECORD && perf_stat.data.is_pipe) 642 if (STAT_RECORD && perf_stat.data.is_pipe)
1838 return; 643 return;
1839 644
1840 if (interval) 645 perf_evlist__print_counters(evsel_list, &stat_config, &target,
1841 print_interval(prefix = buf, ts); 646 ts, argc, argv);
1842 else
1843 print_header(argc, argv);
1844
1845 if (metric_only) {
1846 static int num_print_iv;
1847
1848 if (num_print_iv == 0 && !interval)
1849 print_metric_headers(prefix, false);
1850 if (num_print_iv++ == 25)
1851 num_print_iv = 0;
1852 if (stat_config.aggr_mode == AGGR_GLOBAL && prefix)
1853 fprintf(stat_config.output, "%s", prefix);
1854 }
1855
1856 switch (stat_config.aggr_mode) {
1857 case AGGR_CORE:
1858 case AGGR_SOCKET:
1859 print_aggr(prefix);
1860 break;
1861 case AGGR_THREAD:
1862 evlist__for_each_entry(evsel_list, counter) {
1863 if (is_duration_time(counter))
1864 continue;
1865 print_aggr_thread(counter, prefix);
1866 }
1867 break;
1868 case AGGR_GLOBAL:
1869 evlist__for_each_entry(evsel_list, counter) {
1870 if (is_duration_time(counter))
1871 continue;
1872 print_counter_aggr(counter, prefix);
1873 }
1874 if (metric_only)
1875 fputc('\n', stat_config.output);
1876 break;
1877 case AGGR_NONE:
1878 if (metric_only)
1879 print_no_aggr_metric(prefix);
1880 else {
1881 evlist__for_each_entry(evsel_list, counter) {
1882 if (is_duration_time(counter))
1883 continue;
1884 print_counter(counter, prefix);
1885 }
1886 }
1887 break;
1888 case AGGR_UNSET:
1889 default:
1890 break;
1891 }
1892
1893 if (!interval && !csv_output)
1894 print_footer();
1895
1896 fflush(stat_config.output);
1897} 647}
1898 648
1899static volatile int signr = -1; 649static volatile int signr = -1;
@@ -1950,7 +700,7 @@ static int enable_metric_only(const struct option *opt __maybe_unused,
1950 const char *s __maybe_unused, int unset) 700 const char *s __maybe_unused, int unset)
1951{ 701{
1952 force_metric_only = true; 702 force_metric_only = true;
1953 metric_only = !unset; 703 stat_config.metric_only = !unset;
1954 return 0; 704 return 0;
1955} 705}
1956 706
@@ -1958,7 +708,7 @@ static int parse_metric_groups(const struct option *opt,
1958 const char *str, 708 const char *str,
1959 int unset __maybe_unused) 709 int unset __maybe_unused)
1960{ 710{
1961 return metricgroup__parse_groups(opt, str, &metric_events); 711 return metricgroup__parse_groups(opt, str, &stat_config.metric_events);
1962} 712}
1963 713
1964static const struct option stat_options[] = { 714static const struct option stat_options[] = {
@@ -1969,7 +719,7 @@ static const struct option stat_options[] = {
1969 parse_events_option), 719 parse_events_option),
1970 OPT_CALLBACK(0, "filter", &evsel_list, "filter", 720 OPT_CALLBACK(0, "filter", &evsel_list, "filter",
1971 "event filter", parse_filter), 721 "event filter", parse_filter),
1972 OPT_BOOLEAN('i', "no-inherit", &no_inherit, 722 OPT_BOOLEAN('i', "no-inherit", &stat_config.no_inherit,
1973 "child tasks do not inherit counters"), 723 "child tasks do not inherit counters"),
1974 OPT_STRING('p', "pid", &target.pid, "pid", 724 OPT_STRING('p', "pid", &target.pid, "pid",
1975 "stat events on existing process id"), 725 "stat events on existing process id"),
@@ -1982,11 +732,11 @@ static const struct option stat_options[] = {
1982 OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"), 732 OPT_BOOLEAN('c', "scale", &stat_config.scale, "scale/normalize counters"),
1983 OPT_INCR('v', "verbose", &verbose, 733 OPT_INCR('v', "verbose", &verbose,
1984 "be more verbose (show counter open errors, etc)"), 734 "be more verbose (show counter open errors, etc)"),
1985 OPT_INTEGER('r', "repeat", &run_count, 735 OPT_INTEGER('r', "repeat", &stat_config.run_count,
1986 "repeat command and print average + stddev (max: 100, forever: 0)"), 736 "repeat command and print average + stddev (max: 100, forever: 0)"),
1987 OPT_BOOLEAN(0, "table", &walltime_run_table, 737 OPT_BOOLEAN(0, "table", &stat_config.walltime_run_table,
1988 "display details about each run (only with -r option)"), 738 "display details about each run (only with -r option)"),
1989 OPT_BOOLEAN('n', "null", &null_run, 739 OPT_BOOLEAN('n', "null", &stat_config.null_run,
1990 "null run - dont start any counters"), 740 "null run - dont start any counters"),
1991 OPT_INCR('d', "detailed", &detailed_run, 741 OPT_INCR('d', "detailed", &detailed_run,
1992 "detailed run - start a lot of events"), 742 "detailed run - start a lot of events"),
@@ -1999,8 +749,8 @@ static const struct option stat_options[] = {
1999 "list of cpus to monitor in system-wide"), 749 "list of cpus to monitor in system-wide"),
2000 OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, 750 OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode,
2001 "disable CPU count aggregation", AGGR_NONE), 751 "disable CPU count aggregation", AGGR_NONE),
2002 OPT_BOOLEAN(0, "no-merge", &no_merge, "Do not merge identical named events"), 752 OPT_BOOLEAN(0, "no-merge", &stat_config.no_merge, "Do not merge identical named events"),
2003 OPT_STRING('x', "field-separator", &csv_sep, "separator", 753 OPT_STRING('x', "field-separator", &stat_config.csv_sep, "separator",
2004 "print counts with custom separator"), 754 "print counts with custom separator"),
2005 OPT_CALLBACK('G', "cgroup", &evsel_list, "name", 755 OPT_CALLBACK('G', "cgroup", &evsel_list, "name",
2006 "monitor event in cgroup name only", parse_cgroups), 756 "monitor event in cgroup name only", parse_cgroups),
@@ -2017,7 +767,7 @@ static const struct option stat_options[] = {
2017 "(overhead is possible for values <= 100ms)"), 767 "(overhead is possible for values <= 100ms)"),
2018 OPT_INTEGER(0, "interval-count", &stat_config.times, 768 OPT_INTEGER(0, "interval-count", &stat_config.times,
2019 "print counts for fixed number of times"), 769 "print counts for fixed number of times"),
2020 OPT_BOOLEAN(0, "interval-clear", &interval_clear, 770 OPT_BOOLEAN(0, "interval-clear", &stat_config.interval_clear,
2021 "clear screen in between new interval"), 771 "clear screen in between new interval"),
2022 OPT_UINTEGER(0, "timeout", &stat_config.timeout, 772 OPT_UINTEGER(0, "timeout", &stat_config.timeout,
2023 "stop workload and print counts after a timeout period in ms (>= 10ms)"), 773 "stop workload and print counts after a timeout period in ms (>= 10ms)"),
@@ -2027,9 +777,9 @@ static const struct option stat_options[] = {
2027 "aggregate counts per physical processor core", AGGR_CORE), 777 "aggregate counts per physical processor core", AGGR_CORE),
2028 OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode, 778 OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode,
2029 "aggregate counts per thread", AGGR_THREAD), 779 "aggregate counts per thread", AGGR_THREAD),
2030 OPT_UINTEGER('D', "delay", &initial_delay, 780 OPT_UINTEGER('D', "delay", &stat_config.initial_delay,
2031 "ms to wait before starting measurement after program start"), 781 "ms to wait before starting measurement after program start"),
2032 OPT_CALLBACK_NOOPT(0, "metric-only", &metric_only, NULL, 782 OPT_CALLBACK_NOOPT(0, "metric-only", &stat_config.metric_only, NULL,
2033 "Only print computed metrics. No raw values", enable_metric_only), 783 "Only print computed metrics. No raw values", enable_metric_only),
2034 OPT_BOOLEAN(0, "topdown", &topdown_run, 784 OPT_BOOLEAN(0, "topdown", &topdown_run,
2035 "measure topdown level 1 statistics"), 785 "measure topdown level 1 statistics"),
@@ -2041,12 +791,14 @@ static const struct option stat_options[] = {
2041 OPT_END() 791 OPT_END()
2042}; 792};
2043 793
2044static int perf_stat__get_socket(struct cpu_map *map, int cpu) 794static int perf_stat__get_socket(struct perf_stat_config *config __maybe_unused,
795 struct cpu_map *map, int cpu)
2045{ 796{
2046 return cpu_map__get_socket(map, cpu, NULL); 797 return cpu_map__get_socket(map, cpu, NULL);
2047} 798}
2048 799
2049static int perf_stat__get_core(struct cpu_map *map, int cpu) 800static int perf_stat__get_core(struct perf_stat_config *config __maybe_unused,
801 struct cpu_map *map, int cpu)
2050{ 802{
2051 return cpu_map__get_core(map, cpu, NULL); 803 return cpu_map__get_core(map, cpu, NULL);
2052} 804}
@@ -2063,9 +815,8 @@ static int cpu_map__get_max(struct cpu_map *map)
2063 return max; 815 return max;
2064} 816}
2065 817
2066static struct cpu_map *cpus_aggr_map; 818static int perf_stat__get_aggr(struct perf_stat_config *config,
2067 819 aggr_get_id_t get_id, struct cpu_map *map, int idx)
2068static int perf_stat__get_aggr(aggr_get_id_t get_id, struct cpu_map *map, int idx)
2069{ 820{
2070 int cpu; 821 int cpu;
2071 822
@@ -2074,20 +825,22 @@ static int perf_stat__get_aggr(aggr_get_id_t get_id, struct cpu_map *map, int id
2074 825
2075 cpu = map->map[idx]; 826 cpu = map->map[idx];
2076 827
2077 if (cpus_aggr_map->map[cpu] == -1) 828 if (config->cpus_aggr_map->map[cpu] == -1)
2078 cpus_aggr_map->map[cpu] = get_id(map, idx); 829 config->cpus_aggr_map->map[cpu] = get_id(config, map, idx);
2079 830
2080 return cpus_aggr_map->map[cpu]; 831 return config->cpus_aggr_map->map[cpu];
2081} 832}
2082 833
2083static int perf_stat__get_socket_cached(struct cpu_map *map, int idx) 834static int perf_stat__get_socket_cached(struct perf_stat_config *config,
835 struct cpu_map *map, int idx)
2084{ 836{
2085 return perf_stat__get_aggr(perf_stat__get_socket, map, idx); 837 return perf_stat__get_aggr(config, perf_stat__get_socket, map, idx);
2086} 838}
2087 839
2088static int perf_stat__get_core_cached(struct cpu_map *map, int idx) 840static int perf_stat__get_core_cached(struct perf_stat_config *config,
841 struct cpu_map *map, int idx)
2089{ 842{
2090 return perf_stat__get_aggr(perf_stat__get_core, map, idx); 843 return perf_stat__get_aggr(config, perf_stat__get_core, map, idx);
2091} 844}
2092 845
2093static int perf_stat_init_aggr_mode(void) 846static int perf_stat_init_aggr_mode(void)
@@ -2096,18 +849,18 @@ static int perf_stat_init_aggr_mode(void)
2096 849
2097 switch (stat_config.aggr_mode) { 850 switch (stat_config.aggr_mode) {
2098 case AGGR_SOCKET: 851 case AGGR_SOCKET:
2099 if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) { 852 if (cpu_map__build_socket_map(evsel_list->cpus, &stat_config.aggr_map)) {
2100 perror("cannot build socket map"); 853 perror("cannot build socket map");
2101 return -1; 854 return -1;
2102 } 855 }
2103 aggr_get_id = perf_stat__get_socket_cached; 856 stat_config.aggr_get_id = perf_stat__get_socket_cached;
2104 break; 857 break;
2105 case AGGR_CORE: 858 case AGGR_CORE:
2106 if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) { 859 if (cpu_map__build_core_map(evsel_list->cpus, &stat_config.aggr_map)) {
2107 perror("cannot build core map"); 860 perror("cannot build core map");
2108 return -1; 861 return -1;
2109 } 862 }
2110 aggr_get_id = perf_stat__get_core_cached; 863 stat_config.aggr_get_id = perf_stat__get_core_cached;
2111 break; 864 break;
2112 case AGGR_NONE: 865 case AGGR_NONE:
2113 case AGGR_GLOBAL: 866 case AGGR_GLOBAL:
@@ -2123,16 +876,16 @@ static int perf_stat_init_aggr_mode(void)
2123 * the aggregation translate cpumap. 876 * the aggregation translate cpumap.
2124 */ 877 */
2125 nr = cpu_map__get_max(evsel_list->cpus); 878 nr = cpu_map__get_max(evsel_list->cpus);
2126 cpus_aggr_map = cpu_map__empty_new(nr + 1); 879 stat_config.cpus_aggr_map = cpu_map__empty_new(nr + 1);
2127 return cpus_aggr_map ? 0 : -ENOMEM; 880 return stat_config.cpus_aggr_map ? 0 : -ENOMEM;
2128} 881}
2129 882
2130static void perf_stat__exit_aggr_mode(void) 883static void perf_stat__exit_aggr_mode(void)
2131{ 884{
2132 cpu_map__put(aggr_map); 885 cpu_map__put(stat_config.aggr_map);
2133 cpu_map__put(cpus_aggr_map); 886 cpu_map__put(stat_config.cpus_aggr_map);
2134 aggr_map = NULL; 887 stat_config.aggr_map = NULL;
2135 cpus_aggr_map = NULL; 888 stat_config.cpus_aggr_map = NULL;
2136} 889}
2137 890
2138static inline int perf_env__get_cpu(struct perf_env *env, struct cpu_map *map, int idx) 891static inline int perf_env__get_cpu(struct perf_env *env, struct cpu_map *map, int idx)
@@ -2190,12 +943,14 @@ static int perf_env__build_core_map(struct perf_env *env, struct cpu_map *cpus,
2190 return cpu_map__build_map(cpus, corep, perf_env__get_core, env); 943 return cpu_map__build_map(cpus, corep, perf_env__get_core, env);
2191} 944}
2192 945
2193static int perf_stat__get_socket_file(struct cpu_map *map, int idx) 946static int perf_stat__get_socket_file(struct perf_stat_config *config __maybe_unused,
947 struct cpu_map *map, int idx)
2194{ 948{
2195 return perf_env__get_socket(map, idx, &perf_stat.session->header.env); 949 return perf_env__get_socket(map, idx, &perf_stat.session->header.env);
2196} 950}
2197 951
2198static int perf_stat__get_core_file(struct cpu_map *map, int idx) 952static int perf_stat__get_core_file(struct perf_stat_config *config __maybe_unused,
953 struct cpu_map *map, int idx)
2199{ 954{
2200 return perf_env__get_core(map, idx, &perf_stat.session->header.env); 955 return perf_env__get_core(map, idx, &perf_stat.session->header.env);
2201} 956}
@@ -2206,18 +961,18 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
2206 961
2207 switch (stat_config.aggr_mode) { 962 switch (stat_config.aggr_mode) {
2208 case AGGR_SOCKET: 963 case AGGR_SOCKET:
2209 if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) { 964 if (perf_env__build_socket_map(env, evsel_list->cpus, &stat_config.aggr_map)) {
2210 perror("cannot build socket map"); 965 perror("cannot build socket map");
2211 return -1; 966 return -1;
2212 } 967 }
2213 aggr_get_id = perf_stat__get_socket_file; 968 stat_config.aggr_get_id = perf_stat__get_socket_file;
2214 break; 969 break;
2215 case AGGR_CORE: 970 case AGGR_CORE:
2216 if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) { 971 if (perf_env__build_core_map(env, evsel_list->cpus, &stat_config.aggr_map)) {
2217 perror("cannot build core map"); 972 perror("cannot build core map");
2218 return -1; 973 return -1;
2219 } 974 }
2220 aggr_get_id = perf_stat__get_core_file; 975 stat_config.aggr_get_id = perf_stat__get_core_file;
2221 break; 976 break;
2222 case AGGR_NONE: 977 case AGGR_NONE:
2223 case AGGR_GLOBAL: 978 case AGGR_GLOBAL:
@@ -2401,7 +1156,7 @@ static int add_default_attributes(void)
2401 struct parse_events_error errinfo; 1156 struct parse_events_error errinfo;
2402 1157
2403 /* Set attrs if no event is selected and !null_run: */ 1158 /* Set attrs if no event is selected and !null_run: */
2404 if (null_run) 1159 if (stat_config.null_run)
2405 return 0; 1160 return 0;
2406 1161
2407 if (transaction_run) { 1162 if (transaction_run) {
@@ -2414,7 +1169,7 @@ static int add_default_attributes(void)
2414 struct option opt = { .value = &evsel_list }; 1169 struct option opt = { .value = &evsel_list };
2415 1170
2416 return metricgroup__parse_groups(&opt, "transaction", 1171 return metricgroup__parse_groups(&opt, "transaction",
2417 &metric_events); 1172 &stat_config.metric_events);
2418 } 1173 }
2419 1174
2420 if (pmu_have_event("cpu", "cycles-ct") && 1175 if (pmu_have_event("cpu", "cycles-ct") &&
@@ -2452,7 +1207,7 @@ static int add_default_attributes(void)
2452 if (pmu_have_event("msr", "aperf") && 1207 if (pmu_have_event("msr", "aperf") &&
2453 pmu_have_event("msr", "smi")) { 1208 pmu_have_event("msr", "smi")) {
2454 if (!force_metric_only) 1209 if (!force_metric_only)
2455 metric_only = true; 1210 stat_config.metric_only = true;
2456 err = parse_events(evsel_list, smi_cost_attrs, &errinfo); 1211 err = parse_events(evsel_list, smi_cost_attrs, &errinfo);
2457 } else { 1212 } else {
2458 fprintf(stderr, "To measure SMI cost, it needs " 1213 fprintf(stderr, "To measure SMI cost, it needs "
@@ -2483,7 +1238,7 @@ static int add_default_attributes(void)
2483 } 1238 }
2484 1239
2485 if (!force_metric_only) 1240 if (!force_metric_only)
2486 metric_only = true; 1241 stat_config.metric_only = true;
2487 if (topdown_filter_events(topdown_attrs, &str, 1242 if (topdown_filter_events(topdown_attrs, &str,
2488 arch_topdown_check_group(&warn)) < 0) { 1243 arch_topdown_check_group(&warn)) < 0) {
2489 pr_err("Out of memory\n"); 1244 pr_err("Out of memory\n");
@@ -2580,7 +1335,7 @@ static int __cmd_record(int argc, const char **argv)
2580 if (output_name) 1335 if (output_name)
2581 data->file.path = output_name; 1336 data->file.path = output_name;
2582 1337
2583 if (run_count != 1 || forever) { 1338 if (stat_config.run_count != 1 || forever) {
2584 pr_err("Cannot use -r option with perf stat record.\n"); 1339 pr_err("Cannot use -r option with perf stat record.\n");
2585 return -1; 1340 return -1;
2586 } 1341 }
@@ -2599,9 +1354,8 @@ static int __cmd_record(int argc, const char **argv)
2599 return argc; 1354 return argc;
2600} 1355}
2601 1356
2602static int process_stat_round_event(struct perf_tool *tool __maybe_unused, 1357static int process_stat_round_event(struct perf_session *session,
2603 union perf_event *event, 1358 union perf_event *event)
2604 struct perf_session *session)
2605{ 1359{
2606 struct stat_round_event *stat_round = &event->stat_round; 1360 struct stat_round_event *stat_round = &event->stat_round;
2607 struct perf_evsel *counter; 1361 struct perf_evsel *counter;
@@ -2626,10 +1380,10 @@ static int process_stat_round_event(struct perf_tool *tool __maybe_unused,
2626} 1380}
2627 1381
2628static 1382static
2629int process_stat_config_event(struct perf_tool *tool, 1383int process_stat_config_event(struct perf_session *session,
2630 union perf_event *event, 1384 union perf_event *event)
2631 struct perf_session *session __maybe_unused)
2632{ 1385{
1386 struct perf_tool *tool = session->tool;
2633 struct perf_stat *st = container_of(tool, struct perf_stat, tool); 1387 struct perf_stat *st = container_of(tool, struct perf_stat, tool);
2634 1388
2635 perf_event__read_stat_config(&stat_config, &event->stat_config); 1389 perf_event__read_stat_config(&stat_config, &event->stat_config);
@@ -2669,10 +1423,10 @@ static int set_maps(struct perf_stat *st)
2669} 1423}
2670 1424
2671static 1425static
2672int process_thread_map_event(struct perf_tool *tool, 1426int process_thread_map_event(struct perf_session *session,
2673 union perf_event *event, 1427 union perf_event *event)
2674 struct perf_session *session __maybe_unused)
2675{ 1428{
1429 struct perf_tool *tool = session->tool;
2676 struct perf_stat *st = container_of(tool, struct perf_stat, tool); 1430 struct perf_stat *st = container_of(tool, struct perf_stat, tool);
2677 1431
2678 if (st->threads) { 1432 if (st->threads) {
@@ -2688,10 +1442,10 @@ int process_thread_map_event(struct perf_tool *tool,
2688} 1442}
2689 1443
2690static 1444static
2691int process_cpu_map_event(struct perf_tool *tool, 1445int process_cpu_map_event(struct perf_session *session,
2692 union perf_event *event, 1446 union perf_event *event)
2693 struct perf_session *session __maybe_unused)
2694{ 1447{
1448 struct perf_tool *tool = session->tool;
2695 struct perf_stat *st = container_of(tool, struct perf_stat, tool); 1449 struct perf_stat *st = container_of(tool, struct perf_stat, tool);
2696 struct cpu_map *cpus; 1450 struct cpu_map *cpus;
2697 1451
@@ -2853,12 +1607,12 @@ int cmd_stat(int argc, const char **argv)
2853 perf_stat__collect_metric_expr(evsel_list); 1607 perf_stat__collect_metric_expr(evsel_list);
2854 perf_stat__init_shadow_stats(); 1608 perf_stat__init_shadow_stats();
2855 1609
2856 if (csv_sep) { 1610 if (stat_config.csv_sep) {
2857 csv_output = true; 1611 stat_config.csv_output = true;
2858 if (!strcmp(csv_sep, "\\t")) 1612 if (!strcmp(stat_config.csv_sep, "\\t"))
2859 csv_sep = "\t"; 1613 stat_config.csv_sep = "\t";
2860 } else 1614 } else
2861 csv_sep = DEFAULT_SEPARATOR; 1615 stat_config.csv_sep = DEFAULT_SEPARATOR;
2862 1616
2863 if (argc && !strncmp(argv[0], "rec", 3)) { 1617 if (argc && !strncmp(argv[0], "rec", 3)) {
2864 argc = __cmd_record(argc, argv); 1618 argc = __cmd_record(argc, argv);
@@ -2883,17 +1637,17 @@ int cmd_stat(int argc, const char **argv)
2883 goto out; 1637 goto out;
2884 } 1638 }
2885 1639
2886 if (metric_only && stat_config.aggr_mode == AGGR_THREAD) { 1640 if (stat_config.metric_only && stat_config.aggr_mode == AGGR_THREAD) {
2887 fprintf(stderr, "--metric-only is not supported with --per-thread\n"); 1641 fprintf(stderr, "--metric-only is not supported with --per-thread\n");
2888 goto out; 1642 goto out;
2889 } 1643 }
2890 1644
2891 if (metric_only && run_count > 1) { 1645 if (stat_config.metric_only && stat_config.run_count > 1) {
2892 fprintf(stderr, "--metric-only is not supported with -r\n"); 1646 fprintf(stderr, "--metric-only is not supported with -r\n");
2893 goto out; 1647 goto out;
2894 } 1648 }
2895 1649
2896 if (walltime_run_table && run_count <= 1) { 1650 if (stat_config.walltime_run_table && stat_config.run_count <= 1) {
2897 fprintf(stderr, "--table is only supported with -r\n"); 1651 fprintf(stderr, "--table is only supported with -r\n");
2898 parse_options_usage(stat_usage, stat_options, "r", 1); 1652 parse_options_usage(stat_usage, stat_options, "r", 1);
2899 parse_options_usage(NULL, stat_options, "table", 0); 1653 parse_options_usage(NULL, stat_options, "table", 0);
@@ -2931,7 +1685,7 @@ int cmd_stat(int argc, const char **argv)
2931 /* 1685 /*
2932 * let the spreadsheet do the pretty-printing 1686 * let the spreadsheet do the pretty-printing
2933 */ 1687 */
2934 if (csv_output) { 1688 if (stat_config.csv_output) {
2935 /* User explicitly passed -B? */ 1689 /* User explicitly passed -B? */
2936 if (big_num_opt == 1) { 1690 if (big_num_opt == 1) {
2937 fprintf(stderr, "-B option not supported with -x\n"); 1691 fprintf(stderr, "-B option not supported with -x\n");
@@ -2939,9 +1693,9 @@ int cmd_stat(int argc, const char **argv)
2939 parse_options_usage(NULL, stat_options, "x", 1); 1693 parse_options_usage(NULL, stat_options, "x", 1);
2940 goto out; 1694 goto out;
2941 } else /* Nope, so disable big number formatting */ 1695 } else /* Nope, so disable big number formatting */
2942 big_num = false; 1696 stat_config.big_num = false;
2943 } else if (big_num_opt == 0) /* User passed --no-big-num */ 1697 } else if (big_num_opt == 0) /* User passed --no-big-num */
2944 big_num = false; 1698 stat_config.big_num = false;
2945 1699
2946 setup_system_wide(argc); 1700 setup_system_wide(argc);
2947 1701
@@ -2949,21 +1703,21 @@ int cmd_stat(int argc, const char **argv)
2949 * Display user/system times only for single 1703 * Display user/system times only for single
2950 * run and when there's specified tracee. 1704 * run and when there's specified tracee.
2951 */ 1705 */
2952 if ((run_count == 1) && target__none(&target)) 1706 if ((stat_config.run_count == 1) && target__none(&target))
2953 ru_display = true; 1707 stat_config.ru_display = true;
2954 1708
2955 if (run_count < 0) { 1709 if (stat_config.run_count < 0) {
2956 pr_err("Run count must be a positive number\n"); 1710 pr_err("Run count must be a positive number\n");
2957 parse_options_usage(stat_usage, stat_options, "r", 1); 1711 parse_options_usage(stat_usage, stat_options, "r", 1);
2958 goto out; 1712 goto out;
2959 } else if (run_count == 0) { 1713 } else if (stat_config.run_count == 0) {
2960 forever = true; 1714 forever = true;
2961 run_count = 1; 1715 stat_config.run_count = 1;
2962 } 1716 }
2963 1717
2964 if (walltime_run_table) { 1718 if (stat_config.walltime_run_table) {
2965 walltime_run = zalloc(run_count * sizeof(walltime_run[0])); 1719 stat_config.walltime_run = zalloc(stat_config.run_count * sizeof(stat_config.walltime_run[0]));
2966 if (!walltime_run) { 1720 if (!stat_config.walltime_run) {
2967 pr_err("failed to setup -r option"); 1721 pr_err("failed to setup -r option");
2968 goto out; 1722 goto out;
2969 } 1723 }
@@ -3066,6 +1820,17 @@ int cmd_stat(int argc, const char **argv)
3066 goto out; 1820 goto out;
3067 1821
3068 /* 1822 /*
1823 * Set sample_type to PERF_SAMPLE_IDENTIFIER, which should be harmless
1824 * while avoiding that older tools show confusing messages.
1825 *
1826 * However for pipe sessions we need to keep it zero,
1827 * because script's perf_evsel__check_attr is triggered
1828 * by attr->sample_type != 0, and we can't run it on
1829 * stat sessions.
1830 */
1831 stat_config.identifier = !(STAT_RECORD && perf_stat.data.is_pipe);
1832
1833 /*
3069 * We dont want to block the signals - that would cause 1834 * We dont want to block the signals - that would cause
3070 * child tasks to inherit that and Ctrl-C would not work. 1835 * child tasks to inherit that and Ctrl-C would not work.
3071 * What we want is for Ctrl-C to work in the exec()-ed 1836 * What we want is for Ctrl-C to work in the exec()-ed
@@ -3079,8 +1844,8 @@ int cmd_stat(int argc, const char **argv)
3079 signal(SIGABRT, skip_signal); 1844 signal(SIGABRT, skip_signal);
3080 1845
3081 status = 0; 1846 status = 0;
3082 for (run_idx = 0; forever || run_idx < run_count; run_idx++) { 1847 for (run_idx = 0; forever || run_idx < stat_config.run_count; run_idx++) {
3083 if (run_count != 1 && verbose > 0) 1848 if (stat_config.run_count != 1 && verbose > 0)
3084 fprintf(output, "[ perf stat: executing run #%d ... ]\n", 1849 fprintf(output, "[ perf stat: executing run #%d ... ]\n",
3085 run_idx + 1); 1850 run_idx + 1);
3086 1851
@@ -3132,7 +1897,7 @@ int cmd_stat(int argc, const char **argv)
3132 perf_stat__exit_aggr_mode(); 1897 perf_stat__exit_aggr_mode();
3133 perf_evlist__free_stats(evsel_list); 1898 perf_evlist__free_stats(evsel_list);
3134out: 1899out:
3135 free(walltime_run); 1900 free(stat_config.walltime_run);
3136 1901
3137 if (smi_cost && smi_reset) 1902 if (smi_cost && smi_reset)
3138 sysfs__write_int(FREEZE_ON_SMI_PATH, 0); 1903 sysfs__write_int(FREEZE_ON_SMI_PATH, 0);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 22ab8e67c760..90289f31dd87 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -181,7 +181,7 @@ static int __tp_field__init_uint(struct tp_field *field, int size, int offset, b
181 return 0; 181 return 0;
182} 182}
183 183
184static int tp_field__init_uint(struct tp_field *field, struct format_field *format_field, bool needs_swap) 184static int tp_field__init_uint(struct tp_field *field, struct tep_format_field *format_field, bool needs_swap)
185{ 185{
186 return __tp_field__init_uint(field, format_field->size, format_field->offset, needs_swap); 186 return __tp_field__init_uint(field, format_field->size, format_field->offset, needs_swap);
187} 187}
@@ -198,7 +198,7 @@ static int __tp_field__init_ptr(struct tp_field *field, int offset)
198 return 0; 198 return 0;
199} 199}
200 200
201static int tp_field__init_ptr(struct tp_field *field, struct format_field *format_field) 201static int tp_field__init_ptr(struct tp_field *field, struct tep_format_field *format_field)
202{ 202{
203 return __tp_field__init_ptr(field, format_field->offset); 203 return __tp_field__init_ptr(field, format_field->offset);
204} 204}
@@ -214,7 +214,7 @@ static int perf_evsel__init_tp_uint_field(struct perf_evsel *evsel,
214 struct tp_field *field, 214 struct tp_field *field,
215 const char *name) 215 const char *name)
216{ 216{
217 struct format_field *format_field = perf_evsel__field(evsel, name); 217 struct tep_format_field *format_field = perf_evsel__field(evsel, name);
218 218
219 if (format_field == NULL) 219 if (format_field == NULL)
220 return -1; 220 return -1;
@@ -230,7 +230,7 @@ static int perf_evsel__init_tp_ptr_field(struct perf_evsel *evsel,
230 struct tp_field *field, 230 struct tp_field *field,
231 const char *name) 231 const char *name)
232{ 232{
233 struct format_field *format_field = perf_evsel__field(evsel, name); 233 struct tep_format_field *format_field = perf_evsel__field(evsel, name);
234 234
235 if (format_field == NULL) 235 if (format_field == NULL)
236 return -1; 236 return -1;
@@ -288,6 +288,13 @@ static int perf_evsel__init_augmented_syscall_tp_args(struct perf_evsel *evsel)
288 return __tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64)); 288 return __tp_field__init_ptr(&sc->args, sc->id.offset + sizeof(u64));
289} 289}
290 290
291static int perf_evsel__init_augmented_syscall_tp_ret(struct perf_evsel *evsel)
292{
293 struct syscall_tp *sc = evsel->priv;
294
295 return __tp_field__init_uint(&sc->ret, sizeof(u64), sc->id.offset + sizeof(u64), evsel->needs_swap);
296}
297
291static int perf_evsel__init_raw_syscall_tp(struct perf_evsel *evsel, void *handler) 298static int perf_evsel__init_raw_syscall_tp(struct perf_evsel *evsel, void *handler)
292{ 299{
293 evsel->priv = malloc(sizeof(struct syscall_tp)); 300 evsel->priv = malloc(sizeof(struct syscall_tp));
@@ -498,16 +505,6 @@ static const char *clockid[] = {
498}; 505};
499static DEFINE_STRARRAY(clockid); 506static DEFINE_STRARRAY(clockid);
500 507
501static const char *socket_families[] = {
502 "UNSPEC", "LOCAL", "INET", "AX25", "IPX", "APPLETALK", "NETROM",
503 "BRIDGE", "ATMPVC", "X25", "INET6", "ROSE", "DECnet", "NETBEUI",
504 "SECURITY", "KEY", "NETLINK", "PACKET", "ASH", "ECONET", "ATMSVC",
505 "RDS", "SNA", "IRDA", "PPPOX", "WANPIPE", "LLC", "IB", "CAN", "TIPC",
506 "BLUETOOTH", "IUCV", "RXRPC", "ISDN", "PHONET", "IEEE802154", "CAIF",
507 "ALG", "NFC", "VSOCK",
508};
509static DEFINE_STRARRAY(socket_families);
510
511static size_t syscall_arg__scnprintf_access_mode(char *bf, size_t size, 508static size_t syscall_arg__scnprintf_access_mode(char *bf, size_t size,
512 struct syscall_arg *arg) 509 struct syscall_arg *arg)
513{ 510{
@@ -631,6 +628,8 @@ static struct syscall_fmt {
631} syscall_fmts[] = { 628} syscall_fmts[] = {
632 { .name = "access", 629 { .name = "access",
633 .arg = { [1] = { .scnprintf = SCA_ACCMODE, /* mode */ }, }, }, 630 .arg = { [1] = { .scnprintf = SCA_ACCMODE, /* mode */ }, }, },
631 { .name = "bind",
632 .arg = { [1] = { .scnprintf = SCA_SOCKADDR, /* umyaddr */ }, }, },
634 { .name = "bpf", 633 { .name = "bpf",
635 .arg = { [0] = STRARRAY(cmd, bpf_cmd), }, }, 634 .arg = { [0] = STRARRAY(cmd, bpf_cmd), }, },
636 { .name = "brk", .hexret = true, 635 { .name = "brk", .hexret = true,
@@ -645,6 +644,8 @@ static struct syscall_fmt {
645 [4] = { .name = "tls", .scnprintf = SCA_HEX, }, }, }, 644 [4] = { .name = "tls", .scnprintf = SCA_HEX, }, }, },
646 { .name = "close", 645 { .name = "close",
647 .arg = { [0] = { .scnprintf = SCA_CLOSE_FD, /* fd */ }, }, }, 646 .arg = { [0] = { .scnprintf = SCA_CLOSE_FD, /* fd */ }, }, },
647 { .name = "connect",
648 .arg = { [1] = { .scnprintf = SCA_SOCKADDR, /* servaddr */ }, }, },
648 { .name = "epoll_ctl", 649 { .name = "epoll_ctl",
649 .arg = { [1] = STRARRAY(op, epoll_ctl_ops), }, }, 650 .arg = { [1] = STRARRAY(op, epoll_ctl_ops), }, },
650 { .name = "eventfd2", 651 { .name = "eventfd2",
@@ -801,7 +802,8 @@ static struct syscall_fmt {
801 { .name = "sendmsg", 802 { .name = "sendmsg",
802 .arg = { [2] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, }, 803 .arg = { [2] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, },
803 { .name = "sendto", 804 { .name = "sendto",
804 .arg = { [3] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ }, }, }, 805 .arg = { [3] = { .scnprintf = SCA_MSG_FLAGS, /* flags */ },
806 [4] = { .scnprintf = SCA_SOCKADDR, /* addr */ }, }, },
805 { .name = "set_tid_address", .errpid = true, }, 807 { .name = "set_tid_address", .errpid = true, },
806 { .name = "setitimer", 808 { .name = "setitimer",
807 .arg = { [0] = STRARRAY(which, itimers), }, }, 809 .arg = { [0] = STRARRAY(which, itimers), }, },
@@ -830,6 +832,7 @@ static struct syscall_fmt {
830 .arg = { [2] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, 832 .arg = { [2] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, },
831 { .name = "tkill", 833 { .name = "tkill",
832 .arg = { [1] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, }, 834 .arg = { [1] = { .scnprintf = SCA_SIGNUM, /* sig */ }, }, },
835 { .name = "umount2", .alias = "umount", },
833 { .name = "uname", .alias = "newuname", }, 836 { .name = "uname", .alias = "newuname", },
834 { .name = "unlinkat", 837 { .name = "unlinkat",
835 .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, }, 838 .arg = { [0] = { .scnprintf = SCA_FDAT, /* dfd */ }, }, },
@@ -856,13 +859,15 @@ static struct syscall_fmt *syscall_fmt__find(const char *name)
856/* 859/*
857 * is_exit: is this "exit" or "exit_group"? 860 * is_exit: is this "exit" or "exit_group"?
858 * is_open: is this "open" or "openat"? To associate the fd returned in sys_exit with the pathname in sys_enter. 861 * is_open: is this "open" or "openat"? To associate the fd returned in sys_exit with the pathname in sys_enter.
862 * args_size: sum of the sizes of the syscall arguments, anything after that is augmented stuff: pathname for openat, etc.
859 */ 863 */
860struct syscall { 864struct syscall {
861 struct event_format *tp_format; 865 struct tep_event_format *tp_format;
862 int nr_args; 866 int nr_args;
867 int args_size;
863 bool is_exit; 868 bool is_exit;
864 bool is_open; 869 bool is_open;
865 struct format_field *args; 870 struct tep_format_field *args;
866 const char *name; 871 const char *name;
867 struct syscall_fmt *fmt; 872 struct syscall_fmt *fmt;
868 struct syscall_arg_fmt *arg_fmt; 873 struct syscall_arg_fmt *arg_fmt;
@@ -1095,11 +1100,21 @@ static void thread__set_filename_pos(struct thread *thread, const char *bf,
1095 ttrace->filename.entry_str_pos = bf - ttrace->entry_str; 1100 ttrace->filename.entry_str_pos = bf - ttrace->entry_str;
1096} 1101}
1097 1102
1103static size_t syscall_arg__scnprintf_augmented_string(struct syscall_arg *arg, char *bf, size_t size)
1104{
1105 struct augmented_arg *augmented_arg = arg->augmented.args;
1106
1107 return scnprintf(bf, size, "%.*s", augmented_arg->size, augmented_arg->value);
1108}
1109
1098static size_t syscall_arg__scnprintf_filename(char *bf, size_t size, 1110static size_t syscall_arg__scnprintf_filename(char *bf, size_t size,
1099 struct syscall_arg *arg) 1111 struct syscall_arg *arg)
1100{ 1112{
1101 unsigned long ptr = arg->val; 1113 unsigned long ptr = arg->val;
1102 1114
1115 if (arg->augmented.args)
1116 return syscall_arg__scnprintf_augmented_string(arg, bf, size);
1117
1103 if (!arg->trace->vfs_getname) 1118 if (!arg->trace->vfs_getname)
1104 return scnprintf(bf, size, "%#x", ptr); 1119 return scnprintf(bf, size, "%#x", ptr);
1105 1120
@@ -1142,11 +1157,9 @@ static void sig_handler(int sig)
1142 interrupted = sig == SIGINT; 1157 interrupted = sig == SIGINT;
1143} 1158}
1144 1159
1145static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, 1160static size_t trace__fprintf_comm_tid(struct trace *trace, struct thread *thread, FILE *fp)
1146 u64 duration, bool duration_calculated, u64 tstamp, FILE *fp)
1147{ 1161{
1148 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); 1162 size_t printed = 0;
1149 printed += fprintf_duration(duration, duration_calculated, fp);
1150 1163
1151 if (trace->multiple_threads) { 1164 if (trace->multiple_threads) {
1152 if (trace->show_comm) 1165 if (trace->show_comm)
@@ -1157,6 +1170,14 @@ static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thre
1157 return printed; 1170 return printed;
1158} 1171}
1159 1172
1173static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread,
1174 u64 duration, bool duration_calculated, u64 tstamp, FILE *fp)
1175{
1176 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp);
1177 printed += fprintf_duration(duration, duration_calculated, fp);
1178 return printed + trace__fprintf_comm_tid(trace, thread, fp);
1179}
1180
1160static int trace__process_event(struct trace *trace, struct machine *machine, 1181static int trace__process_event(struct trace *trace, struct machine *machine,
1161 union perf_event *event, struct perf_sample *sample) 1182 union perf_event *event, struct perf_sample *sample)
1162{ 1183{
@@ -1258,10 +1279,12 @@ static int syscall__alloc_arg_fmts(struct syscall *sc, int nr_args)
1258 1279
1259static int syscall__set_arg_fmts(struct syscall *sc) 1280static int syscall__set_arg_fmts(struct syscall *sc)
1260{ 1281{
1261 struct format_field *field; 1282 struct tep_format_field *field, *last_field = NULL;
1262 int idx = 0, len; 1283 int idx = 0, len;
1263 1284
1264 for (field = sc->args; field; field = field->next, ++idx) { 1285 for (field = sc->args; field; field = field->next, ++idx) {
1286 last_field = field;
1287
1265 if (sc->fmt && sc->fmt->arg[idx].scnprintf) 1288 if (sc->fmt && sc->fmt->arg[idx].scnprintf)
1266 continue; 1289 continue;
1267 1290
@@ -1270,7 +1293,7 @@ static int syscall__set_arg_fmts(struct syscall *sc)
1270 strcmp(field->name, "path") == 0 || 1293 strcmp(field->name, "path") == 0 ||
1271 strcmp(field->name, "pathname") == 0)) 1294 strcmp(field->name, "pathname") == 0))
1272 sc->arg_fmt[idx].scnprintf = SCA_FILENAME; 1295 sc->arg_fmt[idx].scnprintf = SCA_FILENAME;
1273 else if (field->flags & FIELD_IS_POINTER) 1296 else if (field->flags & TEP_FIELD_IS_POINTER)
1274 sc->arg_fmt[idx].scnprintf = syscall_arg__scnprintf_hex; 1297 sc->arg_fmt[idx].scnprintf = syscall_arg__scnprintf_hex;
1275 else if (strcmp(field->type, "pid_t") == 0) 1298 else if (strcmp(field->type, "pid_t") == 0)
1276 sc->arg_fmt[idx].scnprintf = SCA_PID; 1299 sc->arg_fmt[idx].scnprintf = SCA_PID;
@@ -1292,6 +1315,9 @@ static int syscall__set_arg_fmts(struct syscall *sc)
1292 } 1315 }
1293 } 1316 }
1294 1317
1318 if (last_field)
1319 sc->args_size = last_field->offset + last_field->size;
1320
1295 return 0; 1321 return 0;
1296} 1322}
1297 1323
@@ -1472,14 +1498,18 @@ static size_t syscall__scnprintf_val(struct syscall *sc, char *bf, size_t size,
1472} 1498}
1473 1499
1474static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size, 1500static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
1475 unsigned char *args, struct trace *trace, 1501 unsigned char *args, void *augmented_args, int augmented_args_size,
1476 struct thread *thread) 1502 struct trace *trace, struct thread *thread)
1477{ 1503{
1478 size_t printed = 0; 1504 size_t printed = 0;
1479 unsigned long val; 1505 unsigned long val;
1480 u8 bit = 1; 1506 u8 bit = 1;
1481 struct syscall_arg arg = { 1507 struct syscall_arg arg = {
1482 .args = args, 1508 .args = args,
1509 .augmented = {
1510 .size = augmented_args_size,
1511 .args = augmented_args,
1512 },
1483 .idx = 0, 1513 .idx = 0,
1484 .mask = 0, 1514 .mask = 0,
1485 .trace = trace, 1515 .trace = trace,
@@ -1495,7 +1525,7 @@ static size_t syscall__scnprintf_args(struct syscall *sc, char *bf, size_t size,
1495 ttrace->ret_scnprintf = NULL; 1525 ttrace->ret_scnprintf = NULL;
1496 1526
1497 if (sc->args != NULL) { 1527 if (sc->args != NULL) {
1498 struct format_field *field; 1528 struct tep_format_field *field;
1499 1529
1500 for (field = sc->args; field; 1530 for (field = sc->args; field;
1501 field = field->next, ++arg.idx, bit <<= 1) { 1531 field = field->next, ++arg.idx, bit <<= 1) {
@@ -1654,6 +1684,17 @@ static int trace__fprintf_sample(struct trace *trace, struct perf_evsel *evsel,
1654 return printed; 1684 return printed;
1655} 1685}
1656 1686
1687static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sample, int *augmented_args_size)
1688{
1689 void *augmented_args = NULL;
1690
1691 *augmented_args_size = sample->raw_size - sc->args_size;
1692 if (*augmented_args_size > 0)
1693 augmented_args = sample->raw_data + sc->args_size;
1694
1695 return augmented_args;
1696}
1697
1657static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, 1698static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
1658 union perf_event *event __maybe_unused, 1699 union perf_event *event __maybe_unused,
1659 struct perf_sample *sample) 1700 struct perf_sample *sample)
@@ -1663,6 +1704,8 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
1663 size_t printed = 0; 1704 size_t printed = 0;
1664 struct thread *thread; 1705 struct thread *thread;
1665 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; 1706 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
1707 int augmented_args_size = 0;
1708 void *augmented_args = NULL;
1666 struct syscall *sc = trace__syscall_info(trace, evsel, id); 1709 struct syscall *sc = trace__syscall_info(trace, evsel, id);
1667 struct thread_trace *ttrace; 1710 struct thread_trace *ttrace;
1668 1711
@@ -1686,13 +1729,24 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
1686 1729
1687 if (!(trace->duration_filter || trace->summary_only || trace->min_stack)) 1730 if (!(trace->duration_filter || trace->summary_only || trace->min_stack))
1688 trace__printf_interrupted_entry(trace); 1731 trace__printf_interrupted_entry(trace);
1689 1732 /*
1733 * If this is raw_syscalls.sys_enter, then it always comes with the 6 possible
1734 * arguments, even if the syscall being handled, say "openat", uses only 4 arguments
1735 * this breaks syscall__augmented_args() check for augmented args, as we calculate
1736 * syscall->args_size using each syscalls:sys_enter_NAME tracefs format file,
1737 * so when handling, say the openat syscall, we end up getting 6 args for the
1738 * raw_syscalls:sys_enter event, when we expected just 4, we end up mistakenly
1739 * thinking that the extra 2 u64 args are the augmented filename, so just check
1740 * here and avoid using augmented syscalls when the evsel is the raw_syscalls one.
1741 */
1742 if (evsel != trace->syscalls.events.sys_enter)
1743 augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size);
1690 ttrace->entry_time = sample->time; 1744 ttrace->entry_time = sample->time;
1691 msg = ttrace->entry_str; 1745 msg = ttrace->entry_str;
1692 printed += scnprintf(msg + printed, trace__entry_str_size - printed, "%s(", sc->name); 1746 printed += scnprintf(msg + printed, trace__entry_str_size - printed, "%s(", sc->name);
1693 1747
1694 printed += syscall__scnprintf_args(sc, msg + printed, trace__entry_str_size - printed, 1748 printed += syscall__scnprintf_args(sc, msg + printed, trace__entry_str_size - printed,
1695 args, trace, thread); 1749 args, augmented_args, augmented_args_size, trace, thread);
1696 1750
1697 if (sc->is_exit) { 1751 if (sc->is_exit) {
1698 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) { 1752 if (!(trace->duration_filter || trace->summary_only || trace->failure_only || trace->min_stack)) {
@@ -1723,7 +1777,8 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct perf_evsel *evse
1723 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1; 1777 int id = perf_evsel__sc_tp_uint(evsel, id, sample), err = -1;
1724 struct syscall *sc = trace__syscall_info(trace, evsel, id); 1778 struct syscall *sc = trace__syscall_info(trace, evsel, id);
1725 char msg[1024]; 1779 char msg[1024];
1726 void *args; 1780 void *args, *augmented_args = NULL;
1781 int augmented_args_size;
1727 1782
1728 if (sc == NULL) 1783 if (sc == NULL)
1729 return -1; 1784 return -1;
@@ -1738,7 +1793,8 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct perf_evsel *evse
1738 goto out_put; 1793 goto out_put;
1739 1794
1740 args = perf_evsel__sc_tp_ptr(evsel, args, sample); 1795 args = perf_evsel__sc_tp_ptr(evsel, args, sample);
1741 syscall__scnprintf_args(sc, msg, sizeof(msg), args, trace, thread); 1796 augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size);
1797 syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread);
1742 fprintf(trace->output, "%s", msg); 1798 fprintf(trace->output, "%s", msg);
1743 err = 0; 1799 err = 0;
1744out_put: 1800out_put:
@@ -2022,6 +2078,7 @@ static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel,
2022 union perf_event *event __maybe_unused, 2078 union perf_event *event __maybe_unused,
2023 struct perf_sample *sample) 2079 struct perf_sample *sample)
2024{ 2080{
2081 struct thread *thread = machine__findnew_thread(trace->host, sample->pid, sample->tid);
2025 int callchain_ret = 0; 2082 int callchain_ret = 0;
2026 2083
2027 if (sample->callchain) { 2084 if (sample->callchain) {
@@ -2039,13 +2096,31 @@ static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel,
2039 if (trace->trace_syscalls) 2096 if (trace->trace_syscalls)
2040 fprintf(trace->output, "( ): "); 2097 fprintf(trace->output, "( ): ");
2041 2098
2099 if (thread)
2100 trace__fprintf_comm_tid(trace, thread, trace->output);
2101
2102 if (evsel == trace->syscalls.events.augmented) {
2103 int id = perf_evsel__sc_tp_uint(evsel, id, sample);
2104 struct syscall *sc = trace__syscall_info(trace, evsel, id);
2105
2106 if (sc) {
2107 fprintf(trace->output, "%s(", sc->name);
2108 trace__fprintf_sys_enter(trace, evsel, sample);
2109 fputc(')', trace->output);
2110 goto newline;
2111 }
2112
2113 /*
2114 * XXX: Not having the associated syscall info or not finding/adding
2115 * the thread should never happen, but if it does...
2116 * fall thru and print it as a bpf_output event.
2117 */
2118 }
2119
2042 fprintf(trace->output, "%s:", evsel->name); 2120 fprintf(trace->output, "%s:", evsel->name);
2043 2121
2044 if (perf_evsel__is_bpf_output(evsel)) { 2122 if (perf_evsel__is_bpf_output(evsel)) {
2045 if (evsel == trace->syscalls.events.augmented) 2123 bpf_output__fprintf(trace, sample);
2046 trace__fprintf_sys_enter(trace, evsel, sample);
2047 else
2048 bpf_output__fprintf(trace, sample);
2049 } else if (evsel->tp_format) { 2124 } else if (evsel->tp_format) {
2050 if (strncmp(evsel->tp_format->name, "sys_enter_", 10) || 2125 if (strncmp(evsel->tp_format->name, "sys_enter_", 10) ||
2051 trace__fprintf_sys_enter(trace, evsel, sample)) { 2126 trace__fprintf_sys_enter(trace, evsel, sample)) {
@@ -2055,12 +2130,14 @@ static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel,
2055 } 2130 }
2056 } 2131 }
2057 2132
2133newline:
2058 fprintf(trace->output, "\n"); 2134 fprintf(trace->output, "\n");
2059 2135
2060 if (callchain_ret > 0) 2136 if (callchain_ret > 0)
2061 trace__fprintf_callchain(trace, sample); 2137 trace__fprintf_callchain(trace, sample);
2062 else if (callchain_ret < 0) 2138 else if (callchain_ret < 0)
2063 pr_err("Problem processing %s callchain, skipping...\n", perf_evsel__name(evsel)); 2139 pr_err("Problem processing %s callchain, skipping...\n", perf_evsel__name(evsel));
2140 thread__put(thread);
2064out: 2141out:
2065 return 0; 2142 return 0;
2066} 2143}
@@ -3276,12 +3353,8 @@ int cmd_trace(int argc, const char **argv)
3276 goto out; 3353 goto out;
3277 } 3354 }
3278 3355
3279 if (evsel) { 3356 if (evsel)
3280 if (perf_evsel__init_augmented_syscall_tp(evsel) ||
3281 perf_evsel__init_augmented_syscall_tp_args(evsel))
3282 goto out;
3283 trace.syscalls.events.augmented = evsel; 3357 trace.syscalls.events.augmented = evsel;
3284 }
3285 3358
3286 err = bpf__setup_stdout(trace.evlist); 3359 err = bpf__setup_stdout(trace.evlist);
3287 if (err) { 3360 if (err) {
@@ -3326,6 +3399,34 @@ int cmd_trace(int argc, const char **argv)
3326 } 3399 }
3327 } 3400 }
3328 3401
3402 /*
3403 * If we are augmenting syscalls, then combine what we put in the
3404 * __augmented_syscalls__ BPF map with what is in the
3405 * syscalls:sys_exit_FOO tracepoints, i.e. just like we do without BPF,
3406 * combining raw_syscalls:sys_enter with raw_syscalls:sys_exit.
3407 *
3408 * We'll switch to look at two BPF maps, one for sys_enter and the
3409 * other for sys_exit when we start augmenting the sys_exit paths with
3410 * buffers that are being copied from kernel to userspace, think 'read'
3411 * syscall.
3412 */
3413 if (trace.syscalls.events.augmented) {
3414 evsel = trace.syscalls.events.augmented;
3415
3416 if (perf_evsel__init_augmented_syscall_tp(evsel) ||
3417 perf_evsel__init_augmented_syscall_tp_args(evsel))
3418 goto out;
3419 evsel->handler = trace__sys_enter;
3420
3421 evlist__for_each_entry(trace.evlist, evsel) {
3422 if (strstarts(perf_evsel__name(evsel), "syscalls:sys_exit_")) {
3423 perf_evsel__init_augmented_syscall_tp(evsel);
3424 perf_evsel__init_augmented_syscall_tp_ret(evsel);
3425 evsel->handler = trace__sys_exit;
3426 }
3427 }
3428 }
3429
3329 if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) 3430 if ((argc >= 1) && (strcmp(argv[0], "record") == 0))
3330 return trace__record(&trace, argc-1, &argv[1]); 3431 return trace__record(&trace, argc-1, &argv[1]);
3331 3432
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 466540ee8ea7..c72cc73a6b09 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -14,6 +14,7 @@ include/uapi/linux/sched.h
14include/uapi/linux/stat.h 14include/uapi/linux/stat.h
15include/uapi/linux/vhost.h 15include/uapi/linux/vhost.h
16include/uapi/sound/asound.h 16include/uapi/sound/asound.h
17include/linux/bits.h
17include/linux/hash.h 18include/linux/hash.h
18include/uapi/linux/hw_breakpoint.h 19include/uapi/linux/hw_breakpoint.h
19arch/x86/include/asm/disabled-features.h 20arch/x86/include/asm/disabled-features.h
diff --git a/tools/perf/command-list.txt b/tools/perf/command-list.txt
index 2d0caf20ff3a..bc6c585f74fc 100644
--- a/tools/perf/command-list.txt
+++ b/tools/perf/command-list.txt
@@ -30,3 +30,4 @@ perf-test mainporcelain common
30perf-timechart mainporcelain common 30perf-timechart mainporcelain common
31perf-top mainporcelain common 31perf-top mainporcelain common
32perf-trace mainporcelain audit 32perf-trace mainporcelain audit
33perf-version mainporcelain common
diff --git a/tools/perf/examples/bpf/augmented_syscalls.c b/tools/perf/examples/bpf/augmented_syscalls.c
index 69a31386d8cd..2ae44813ef2d 100644
--- a/tools/perf/examples/bpf/augmented_syscalls.c
+++ b/tools/perf/examples/bpf/augmented_syscalls.c
@@ -1,6 +1,6 @@
1// SPDX-License-Identifier: GPL-2.0 1// SPDX-License-Identifier: GPL-2.0
2/* 2/*
3 * Augment the openat syscall with the contents of the filename pointer argument. 3 * Augment syscalls with the contents of the pointer arguments.
4 * 4 *
5 * Test it with: 5 * Test it with:
6 * 6 *
@@ -10,15 +10,14 @@
10 * the last one should be the one for '/etc/passwd'. 10 * the last one should be the one for '/etc/passwd'.
11 * 11 *
12 * This matches what is marshalled into the raw_syscall:sys_enter payload 12 * This matches what is marshalled into the raw_syscall:sys_enter payload
13 * expected by the 'perf trace' beautifiers, and can be used by them unmodified, 13 * expected by the 'perf trace' beautifiers, and can be used by them, that will
14 * which will be done as that feature is implemented in the next csets, for now 14 * check if perf_sample->raw_data is more than what is expected for each
15 * it will appear in a dump done by the default tracepoint handler in 'perf trace', 15 * syscalls:sys_{enter,exit}_SYSCALL tracepoint, uing the extra data as the
16 * that uses bpf_output__fprintf() to just dump those contents, as done with 16 * contents of pointer arguments.
17 * the bpf-output event associated with the __bpf_output__ map declared in
18 * tools/perf/include/bpf/stdio.h.
19 */ 17 */
20 18
21#include <stdio.h> 19#include <stdio.h>
20#include <linux/socket.h>
22 21
23struct bpf_map SEC("maps") __augmented_syscalls__ = { 22struct bpf_map SEC("maps") __augmented_syscalls__ = {
24 .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, 23 .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
@@ -27,6 +26,44 @@ struct bpf_map SEC("maps") __augmented_syscalls__ = {
27 .max_entries = __NR_CPUS__, 26 .max_entries = __NR_CPUS__,
28}; 27};
29 28
29struct syscall_exit_args {
30 unsigned long long common_tp_fields;
31 long syscall_nr;
32 long ret;
33};
34
35struct augmented_filename {
36 unsigned int size;
37 int reserved;
38 char value[256];
39};
40
41#define augmented_filename_syscall(syscall) \
42struct augmented_enter_##syscall##_args { \
43 struct syscall_enter_##syscall##_args args; \
44 struct augmented_filename filename; \
45}; \
46int syscall_enter(syscall)(struct syscall_enter_##syscall##_args *args) \
47{ \
48 struct augmented_enter_##syscall##_args augmented_args = { .filename.reserved = 0, }; \
49 unsigned int len = sizeof(augmented_args); \
50 probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \
51 augmented_args.filename.size = probe_read_str(&augmented_args.filename.value, \
52 sizeof(augmented_args.filename.value), \
53 args->filename_ptr); \
54 if (augmented_args.filename.size < sizeof(augmented_args.filename.value)) { \
55 len -= sizeof(augmented_args.filename.value) - augmented_args.filename.size; \
56 len &= sizeof(augmented_args.filename.value) - 1; \
57 } \
58 perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, \
59 &augmented_args, len); \
60 return 0; \
61} \
62int syscall_exit(syscall)(struct syscall_exit_args *args) \
63{ \
64 return 1; /* 0 as soon as we start copying data returned by the kernel, e.g. 'read' */ \
65}
66
30struct syscall_enter_openat_args { 67struct syscall_enter_openat_args {
31 unsigned long long common_tp_fields; 68 unsigned long long common_tp_fields;
32 long syscall_nr; 69 long syscall_nr;
@@ -36,20 +73,101 @@ struct syscall_enter_openat_args {
36 long mode; 73 long mode;
37}; 74};
38 75
39struct augmented_enter_openat_args { 76augmented_filename_syscall(openat);
40 struct syscall_enter_openat_args args; 77
41 char filename[64]; 78struct syscall_enter_open_args {
79 unsigned long long common_tp_fields;
80 long syscall_nr;
81 char *filename_ptr;
82 long flags;
83 long mode;
84};
85
86augmented_filename_syscall(open);
87
88struct syscall_enter_inotify_add_watch_args {
89 unsigned long long common_tp_fields;
90 long syscall_nr;
91 long fd;
92 char *filename_ptr;
93 long mask;
94};
95
96augmented_filename_syscall(inotify_add_watch);
97
98struct statbuf;
99
100struct syscall_enter_newstat_args {
101 unsigned long long common_tp_fields;
102 long syscall_nr;
103 char *filename_ptr;
104 struct stat *statbuf;
42}; 105};
43 106
44int syscall_enter(openat)(struct syscall_enter_openat_args *args) 107augmented_filename_syscall(newstat);
45{ 108
46 struct augmented_enter_openat_args augmented_args; 109#ifndef _K_SS_MAXSIZE
110#define _K_SS_MAXSIZE 128
111#endif
47 112
48 probe_read(&augmented_args.args, sizeof(augmented_args.args), args); 113#define augmented_sockaddr_syscall(syscall) \
49 probe_read_str(&augmented_args.filename, sizeof(augmented_args.filename), args->filename_ptr); 114struct augmented_enter_##syscall##_args { \
50 perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, 115 struct syscall_enter_##syscall##_args args; \
51 &augmented_args, sizeof(augmented_args)); 116 struct sockaddr_storage addr; \
52 return 1; 117}; \
118int syscall_enter(syscall)(struct syscall_enter_##syscall##_args *args) \
119{ \
120 struct augmented_enter_##syscall##_args augmented_args; \
121 unsigned long addrlen = sizeof(augmented_args.addr); \
122 probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \
123/* FIXME_CLANG_OPTIMIZATION_THAT_ACCESSES_USER_CONTROLLED_ADDRLEN_DESPITE_THIS_CHECK */ \
124/* if (addrlen > augmented_args.args.addrlen) */ \
125/* addrlen = augmented_args.args.addrlen; */ \
126/* */ \
127 probe_read(&augmented_args.addr, addrlen, args->addr_ptr); \
128 perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, \
129 &augmented_args, \
130 sizeof(augmented_args) - sizeof(augmented_args.addr) + addrlen); \
131 return 0; \
132} \
133int syscall_exit(syscall)(struct syscall_exit_args *args) \
134{ \
135 return 1; /* 0 as soon as we start copying data returned by the kernel, e.g. 'read' */ \
53} 136}
54 137
138struct sockaddr;
139
140struct syscall_enter_bind_args {
141 unsigned long long common_tp_fields;
142 long syscall_nr;
143 long fd;
144 struct sockaddr *addr_ptr;
145 unsigned long addrlen;
146};
147
148augmented_sockaddr_syscall(bind);
149
150struct syscall_enter_connect_args {
151 unsigned long long common_tp_fields;
152 long syscall_nr;
153 long fd;
154 struct sockaddr *addr_ptr;
155 unsigned long addrlen;
156};
157
158augmented_sockaddr_syscall(connect);
159
160struct syscall_enter_sendto_args {
161 unsigned long long common_tp_fields;
162 long syscall_nr;
163 long fd;
164 void *buff;
165 long len;
166 unsigned long flags;
167 struct sockaddr *addr_ptr;
168 long addr_len;
169};
170
171augmented_sockaddr_syscall(sendto);
172
55license(GPL); 173license(GPL);
diff --git a/tools/perf/examples/bpf/etcsnoop.c b/tools/perf/examples/bpf/etcsnoop.c
new file mode 100644
index 000000000000..b59e8812ee8c
--- /dev/null
+++ b/tools/perf/examples/bpf/etcsnoop.c
@@ -0,0 +1,80 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Augment the filename syscalls with the contents of the filename pointer argument
4 * filtering only those that do not start with /etc/.
5 *
6 * Test it with:
7 *
8 * perf trace -e tools/perf/examples/bpf/augmented_syscalls.c cat /etc/passwd > /dev/null
9 *
10 * It'll catch some openat syscalls related to the dynamic linked and
11 * the last one should be the one for '/etc/passwd'.
12 *
13 * This matches what is marshalled into the raw_syscall:sys_enter payload
14 * expected by the 'perf trace' beautifiers, and can be used by them unmodified,
15 * which will be done as that feature is implemented in the next csets, for now
16 * it will appear in a dump done by the default tracepoint handler in 'perf trace',
17 * that uses bpf_output__fprintf() to just dump those contents, as done with
18 * the bpf-output event associated with the __bpf_output__ map declared in
19 * tools/perf/include/bpf/stdio.h.
20 */
21
22#include <stdio.h>
23
24struct bpf_map SEC("maps") __augmented_syscalls__ = {
25 .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
26 .key_size = sizeof(int),
27 .value_size = sizeof(u32),
28 .max_entries = __NR_CPUS__,
29};
30
31struct augmented_filename {
32 int size;
33 int reserved;
34 char value[64];
35};
36
37#define augmented_filename_syscall_enter(syscall) \
38struct augmented_enter_##syscall##_args { \
39 struct syscall_enter_##syscall##_args args; \
40 struct augmented_filename filename; \
41}; \
42int syscall_enter(syscall)(struct syscall_enter_##syscall##_args *args) \
43{ \
44 char etc[6] = "/etc/"; \
45 struct augmented_enter_##syscall##_args augmented_args = { .filename.reserved = 0, }; \
46 probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \
47 augmented_args.filename.size = probe_read_str(&augmented_args.filename.value, \
48 sizeof(augmented_args.filename.value), \
49 args->filename_ptr); \
50 if (__builtin_memcmp(augmented_args.filename.value, etc, 4) != 0) \
51 return 0; \
52 perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, \
53 &augmented_args, \
54 (sizeof(augmented_args) - sizeof(augmented_args.filename.value) + \
55 augmented_args.filename.size)); \
56 return 0; \
57}
58
59struct syscall_enter_openat_args {
60 unsigned long long common_tp_fields;
61 long syscall_nr;
62 long dfd;
63 char *filename_ptr;
64 long flags;
65 long mode;
66};
67
68augmented_filename_syscall_enter(openat);
69
70struct syscall_enter_open_args {
71 unsigned long long common_tp_fields;
72 long syscall_nr;
73 char *filename_ptr;
74 long flags;
75 long mode;
76};
77
78augmented_filename_syscall_enter(open);
79
80license(GPL);
diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h
index 47897d65e799..52b6d87fe822 100644
--- a/tools/perf/include/bpf/bpf.h
+++ b/tools/perf/include/bpf/bpf.h
@@ -26,6 +26,9 @@ struct bpf_map {
26#define syscall_enter(name) \ 26#define syscall_enter(name) \
27 SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name 27 SEC("syscalls:sys_enter_" #name) syscall_enter_ ## name
28 28
29#define syscall_exit(name) \
30 SEC("syscalls:sys_exit_" #name) syscall_exit_ ## name
31
29#define license(name) \ 32#define license(name) \
30char _license[] SEC("license") = #name; \ 33char _license[] SEC("license") = #name; \
31int _version SEC("version") = LINUX_VERSION_CODE; 34int _version SEC("version") = LINUX_VERSION_CODE;
diff --git a/tools/perf/include/bpf/linux/socket.h b/tools/perf/include/bpf/linux/socket.h
new file mode 100644
index 000000000000..7f844568dab8
--- /dev/null
+++ b/tools/perf/include/bpf/linux/socket.h
@@ -0,0 +1,24 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2#ifndef _UAPI_LINUX_SOCKET_H
3#define _UAPI_LINUX_SOCKET_H
4
5/*
6 * Desired design of maximum size and alignment (see RFC2553)
7 */
8#define _K_SS_MAXSIZE 128 /* Implementation specific max size */
9#define _K_SS_ALIGNSIZE (__alignof__ (struct sockaddr *))
10 /* Implementation specific desired alignment */
11
12typedef unsigned short __kernel_sa_family_t;
13
14struct __kernel_sockaddr_storage {
15 __kernel_sa_family_t ss_family; /* address family */
16 /* Following field(s) are implementation specific */
17 char __data[_K_SS_MAXSIZE - sizeof(unsigned short)];
18 /* space to achieve desired size, */
19 /* _SS_MAXSIZE value minus size of ss_family */
20} __attribute__ ((aligned(_K_SS_ALIGNSIZE))); /* force desired alignment */
21
22#define sockaddr_storage __kernel_sockaddr_storage
23
24#endif /* _UAPI_LINUX_SOCKET_H */
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/branch.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/branch.json
new file mode 100644
index 000000000000..abc98b018446
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/branch.json
@@ -0,0 +1,23 @@
1[
2 {
3 "ArchStdEvent": "BR_IMMED_SPEC",
4 },
5 {
6 "ArchStdEvent": "BR_RETURN_SPEC",
7 },
8 {
9 "ArchStdEvent": "BR_INDIRECT_SPEC",
10 },
11 {
12 "PublicDescription": "Mispredicted or not predicted branch speculatively executed",
13 "EventCode": "0x10",
14 "EventName": "BR_MIS_PRED",
15 "BriefDescription": "Branch mispredicted"
16 },
17 {
18 "PublicDescription": "Predictable branch speculatively executed",
19 "EventCode": "0x12",
20 "EventName": "BR_PRED",
21 "BriefDescription": "Predictable branch"
22 },
23]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/bus.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/bus.json
new file mode 100644
index 000000000000..687b2629e1d1
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/bus.json
@@ -0,0 +1,26 @@
1[
2 {
3 "ArchStdEvent": "BUS_ACCESS_RD",
4 },
5 {
6 "ArchStdEvent": "BUS_ACCESS_WR",
7 },
8 {
9 "ArchStdEvent": "BUS_ACCESS_SHARED",
10 },
11 {
12 "ArchStdEvent": "BUS_ACCESS_NOT_SHARED",
13 },
14 {
15 "ArchStdEvent": "BUS_ACCESS_NORMAL",
16 },
17 {
18 "ArchStdEvent": "BUS_ACCESS_PERIPH",
19 },
20 {
21 "PublicDescription": "Bus access",
22 "EventCode": "0x19",
23 "EventName": "BUS_ACCESS",
24 "BriefDescription": "Bus access"
25 },
26]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/cache.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/cache.json
new file mode 100644
index 000000000000..df9201434cb6
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/cache.json
@@ -0,0 +1,191 @@
1[
2 {
3 "ArchStdEvent": "L1D_CACHE_RD",
4 },
5 {
6 "ArchStdEvent": "L1D_CACHE_WR",
7 },
8 {
9 "ArchStdEvent": "L1D_CACHE_REFILL_RD",
10 },
11 {
12 "ArchStdEvent": "L1D_CACHE_INVAL",
13 },
14 {
15 "ArchStdEvent": "L1D_TLB_REFILL_RD",
16 },
17 {
18 "ArchStdEvent": "L1D_TLB_REFILL_WR",
19 },
20 {
21 "ArchStdEvent": "L2D_CACHE_RD",
22 },
23 {
24 "ArchStdEvent": "L2D_CACHE_WR",
25 },
26 {
27 "ArchStdEvent": "L2D_CACHE_REFILL_RD",
28 },
29 {
30 "ArchStdEvent": "L2D_CACHE_REFILL_WR",
31 },
32 {
33 "ArchStdEvent": "L2D_CACHE_WB_VICTIM",
34 },
35 {
36 "ArchStdEvent": "L2D_CACHE_WB_CLEAN",
37 },
38 {
39 "ArchStdEvent": "L2D_CACHE_INVAL",
40 },
41 {
42 "PublicDescription": "Level 1 instruction cache refill",
43 "EventCode": "0x01",
44 "EventName": "L1I_CACHE_REFILL",
45 "BriefDescription": "L1I cache refill"
46 },
47 {
48 "PublicDescription": "Level 1 instruction TLB refill",
49 "EventCode": "0x02",
50 "EventName": "L1I_TLB_REFILL",
51 "BriefDescription": "L1I TLB refill"
52 },
53 {
54 "PublicDescription": "Level 1 data cache refill",
55 "EventCode": "0x03",
56 "EventName": "L1D_CACHE_REFILL",
57 "BriefDescription": "L1D cache refill"
58 },
59 {
60 "PublicDescription": "Level 1 data cache access",
61 "EventCode": "0x04",
62 "EventName": "L1D_CACHE_ACCESS",
63 "BriefDescription": "L1D cache access"
64 },
65 {
66 "PublicDescription": "Level 1 data TLB refill",
67 "EventCode": "0x05",
68 "EventName": "L1D_TLB_REFILL",
69 "BriefDescription": "L1D TLB refill"
70 },
71 {
72 "PublicDescription": "Level 1 instruction cache access",
73 "EventCode": "0x14",
74 "EventName": "L1I_CACHE_ACCESS",
75 "BriefDescription": "L1I cache access"
76 },
77 {
78 "PublicDescription": "Level 2 data cache access",
79 "EventCode": "0x16",
80 "EventName": "L2D_CACHE_ACCESS",
81 "BriefDescription": "L2D cache access"
82 },
83 {
84 "PublicDescription": "Level 2 data refill",
85 "EventCode": "0x17",
86 "EventName": "L2D_CACHE_REFILL",
87 "BriefDescription": "L2D cache refill"
88 },
89 {
90 "PublicDescription": "Level 2 data cache, Write-Back",
91 "EventCode": "0x18",
92 "EventName": "L2D_CACHE_WB",
93 "BriefDescription": "L2D cache Write-Back"
94 },
95 {
96 "PublicDescription": "Level 1 data TLB access. This event counts any load or store operation which accesses the data L1 TLB",
97 "EventCode": "0x25",
98 "EventName": "L1D_TLB_ACCESS",
99 "BriefDescription": "L1D TLB access"
100 },
101 {
102 "PublicDescription": "Level 1 instruction TLB access. This event counts any instruction fetch which accesses the instruction L1 TLB",
103 "EventCode": "0x26",
104 "EventName": "L1I_TLB_ACCESS",
105 "BriefDescription": "L1I TLB access"
106 },
107 {
108 "PublicDescription": "Level 2 access to data TLB that caused a page table walk. This event counts on any data access which causes L2D_TLB_REFILL to count",
109 "EventCode": "0x34",
110 "EventName": "L2D_TLB_ACCESS",
111 "BriefDescription": "L2D TLB access"
112 },
113 {
114 "PublicDescription": "Level 2 access to instruciton TLB that caused a page table walk. This event counts on any instruciton access which causes L2I_TLB_REFILL to count",
115 "EventCode": "0x35",
116 "EventName": "L2I_TLB_ACCESS",
117 "BriefDescription": "L2D TLB access"
118 },
119 {
120 "PublicDescription": "Branch target buffer misprediction",
121 "EventCode": "0x102",
122 "EventName": "BTB_MIS_PRED",
123 "BriefDescription": "BTB misprediction"
124 },
125 {
126 "PublicDescription": "ITB miss",
127 "EventCode": "0x103",
128 "EventName": "ITB_MISS",
129 "BriefDescription": "ITB miss"
130 },
131 {
132 "PublicDescription": "DTB miss",
133 "EventCode": "0x104",
134 "EventName": "DTB_MISS",
135 "BriefDescription": "DTB miss"
136 },
137 {
138 "PublicDescription": "Level 1 data cache late miss",
139 "EventCode": "0x105",
140 "EventName": "L1D_CACHE_LATE_MISS",
141 "BriefDescription": "L1D cache late miss"
142 },
143 {
144 "PublicDescription": "Level 1 data cache prefetch request",
145 "EventCode": "0x106",
146 "EventName": "L1D_CACHE_PREFETCH",
147 "BriefDescription": "L1D cache prefetch"
148 },
149 {
150 "PublicDescription": "Level 2 data cache prefetch request",
151 "EventCode": "0x107",
152 "EventName": "L2D_CACHE_PREFETCH",
153 "BriefDescription": "L2D cache prefetch"
154 },
155 {
156 "PublicDescription": "Level 1 stage 2 TLB refill",
157 "EventCode": "0x111",
158 "EventName": "L1_STAGE2_TLB_REFILL",
159 "BriefDescription": "L1 stage 2 TLB refill"
160 },
161 {
162 "PublicDescription": "Page walk cache level-0 stage-1 hit",
163 "EventCode": "0x112",
164 "EventName": "PAGE_WALK_L0_STAGE1_HIT",
165 "BriefDescription": "Page walk, L0 stage-1 hit"
166 },
167 {
168 "PublicDescription": "Page walk cache level-1 stage-1 hit",
169 "EventCode": "0x113",
170 "EventName": "PAGE_WALK_L1_STAGE1_HIT",
171 "BriefDescription": "Page walk, L1 stage-1 hit"
172 },
173 {
174 "PublicDescription": "Page walk cache level-2 stage-1 hit",
175 "EventCode": "0x114",
176 "EventName": "PAGE_WALK_L2_STAGE1_HIT",
177 "BriefDescription": "Page walk, L2 stage-1 hit"
178 },
179 {
180 "PublicDescription": "Page walk cache level-1 stage-2 hit",
181 "EventCode": "0x115",
182 "EventName": "PAGE_WALK_L1_STAGE2_HIT",
183 "BriefDescription": "Page walk, L1 stage-2 hit"
184 },
185 {
186 "PublicDescription": "Page walk cache level-2 stage-2 hit",
187 "EventCode": "0x116",
188 "EventName": "PAGE_WALK_L2_STAGE2_HIT",
189 "BriefDescription": "Page walk, L2 stage-2 hit"
190 },
191]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/clock.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/clock.json
new file mode 100644
index 000000000000..38cd1f1a70dc
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/clock.json
@@ -0,0 +1,20 @@
1[
2 {
3 "PublicDescription": "The number of core clock cycles",
4 "EventCode": "0x11",
5 "EventName": "CPU_CYCLES",
6 "BriefDescription": "Clock cycles"
7 },
8 {
9 "PublicDescription": "FSU clocking gated off cycle",
10 "EventCode": "0x101",
11 "EventName": "FSU_CLOCK_OFF_CYCLES",
12 "BriefDescription": "FSU clocking gated off cycle"
13 },
14 {
15 "PublicDescription": "Wait state cycle",
16 "EventCode": "0x110",
17 "EventName": "Wait_CYCLES",
18 "BriefDescription": "Wait state cycle"
19 },
20]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json
deleted file mode 100644
index bc03c06c3918..000000000000
--- a/tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json
+++ /dev/null
@@ -1,32 +0,0 @@
1[
2 {
3 "ArchStdEvent": "L1D_CACHE_RD",
4 },
5 {
6 "ArchStdEvent": "L1D_CACHE_WR",
7 },
8 {
9 "ArchStdEvent": "L1D_CACHE_REFILL_RD",
10 },
11 {
12 "ArchStdEvent": "L1D_CACHE_REFILL_WR",
13 },
14 {
15 "ArchStdEvent": "L1D_TLB_REFILL_RD",
16 },
17 {
18 "ArchStdEvent": "L1D_TLB_REFILL_WR",
19 },
20 {
21 "ArchStdEvent": "L1D_TLB_RD",
22 },
23 {
24 "ArchStdEvent": "L1D_TLB_WR",
25 },
26 {
27 "ArchStdEvent": "BUS_ACCESS_RD",
28 },
29 {
30 "ArchStdEvent": "BUS_ACCESS_WR",
31 }
32]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/exception.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/exception.json
new file mode 100644
index 000000000000..3720dc28a15f
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/exception.json
@@ -0,0 +1,50 @@
1[
2 {
3 "ArchStdEvent": "EXC_UNDEF",
4 },
5 {
6 "ArchStdEvent": "EXC_SVC",
7 },
8 {
9 "ArchStdEvent": "EXC_PABORT",
10 },
11 {
12 "ArchStdEvent": "EXC_DABORT",
13 },
14 {
15 "ArchStdEvent": "EXC_IRQ",
16 },
17 {
18 "ArchStdEvent": "EXC_FIQ",
19 },
20 {
21 "ArchStdEvent": "EXC_HVC",
22 },
23 {
24 "ArchStdEvent": "EXC_TRAP_PABORT",
25 },
26 {
27 "ArchStdEvent": "EXC_TRAP_DABORT",
28 },
29 {
30 "ArchStdEvent": "EXC_TRAP_OTHER",
31 },
32 {
33 "ArchStdEvent": "EXC_TRAP_IRQ",
34 },
35 {
36 "ArchStdEvent": "EXC_TRAP_FIQ",
37 },
38 {
39 "PublicDescription": "Exception taken",
40 "EventCode": "0x09",
41 "EventName": "EXC_TAKEN",
42 "BriefDescription": "Exception taken"
43 },
44 {
45 "PublicDescription": "Instruction architecturally executed, condition check pass, exception return",
46 "EventCode": "0x0a",
47 "EventName": "EXC_RETURN",
48 "BriefDescription": "Exception return"
49 },
50]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/instruction.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/instruction.json
new file mode 100644
index 000000000000..82cf753e6472
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/instruction.json
@@ -0,0 +1,89 @@
1[
2 {
3 "ArchStdEvent": "LD_SPEC",
4 },
5 {
6 "ArchStdEvent": "ST_SPEC",
7 },
8 {
9 "ArchStdEvent": "LDST_SPEC",
10 },
11 {
12 "ArchStdEvent": "DP_SPEC",
13 },
14 {
15 "ArchStdEvent": "ASE_SPEC",
16 },
17 {
18 "ArchStdEvent": "VFP_SPEC",
19 },
20 {
21 "ArchStdEvent": "PC_WRITE_SPEC",
22 },
23 {
24 "ArchStdEvent": "CRYPTO_SPEC",
25 },
26 {
27 "ArchStdEvent": "ISB_SPEC",
28 },
29 {
30 "ArchStdEvent": "DSB_SPEC",
31 },
32 {
33 "ArchStdEvent": "DMB_SPEC",
34 },
35 {
36 "ArchStdEvent": "RC_LD_SPEC",
37 },
38 {
39 "ArchStdEvent": "RC_ST_SPEC",
40 },
41 {
42 "PublicDescription": "Instruction architecturally executed, software increment",
43 "EventCode": "0x00",
44 "EventName": "SW_INCR",
45 "BriefDescription": "Software increment"
46 },
47 {
48 "PublicDescription": "Instruction architecturally executed",
49 "EventCode": "0x08",
50 "EventName": "INST_RETIRED",
51 "BriefDescription": "Instruction retired"
52 },
53 {
54 "PublicDescription": "Instruction architecturally executed, condition code check pass, write to CONTEXTIDR",
55 "EventCode": "0x0b",
56 "EventName": "CID_WRITE_RETIRED",
57 "BriefDescription": "Write to CONTEXTIDR"
58 },
59 {
60 "PublicDescription": "Operation speculatively executed",
61 "EventCode": "0x1b",
62 "EventName": "INST_SPEC",
63 "BriefDescription": "Speculatively executed"
64 },
65 {
66 "PublicDescription": "Instruction architecturally executed (condition check pass), write to TTBR",
67 "EventCode": "0x1c",
68 "EventName": "TTBR_WRITE_RETIRED",
69 "BriefDescription": "Instruction executed, TTBR write"
70 },
71 {
72 "PublicDescription": "Instruction architecturally executed, branch. This event counts all branches, taken or not. This excludes exception entries, debug entries and CCFAIL branches",
73 "EventCode": "0x21",
74 "EventName": "BR_RETIRED",
75 "BriefDescription": "Branch retired"
76 },
77 {
78 "PublicDescription": "Instruction architecturally executed, mispredicted branch. This event counts any branch counted by BR_RETIRED which is not correctly predicted and causes a pipeline flush",
79 "EventCode": "0x22",
80 "EventName": "BR_MISPRED_RETIRED",
81 "BriefDescription": "Mispredicted branch retired"
82 },
83 {
84 "PublicDescription": "Operation speculatively executed, NOP",
85 "EventCode": "0x100",
86 "EventName": "NOP_SPEC",
87 "BriefDescription": "Speculatively executed, NOP"
88 },
89]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/intrinsic.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/intrinsic.json
new file mode 100644
index 000000000000..2aecc5c2347d
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/intrinsic.json
@@ -0,0 +1,14 @@
1[
2 {
3 "ArchStdEvent": "LDREX_SPEC",
4 },
5 {
6 "ArchStdEvent": "STREX_PASS_SPEC",
7 },
8 {
9 "ArchStdEvent": "STREX_FAIL_SPEC",
10 },
11 {
12 "ArchStdEvent": "STREX_SPEC",
13 },
14]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/memory.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/memory.json
new file mode 100644
index 000000000000..08508697b318
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/memory.json
@@ -0,0 +1,29 @@
1[
2 {
3 "ArchStdEvent": "MEM_ACCESS_RD",
4 },
5 {
6 "ArchStdEvent": "MEM_ACCESS_WR",
7 },
8 {
9 "ArchStdEvent": "UNALIGNED_LD_SPEC",
10 },
11 {
12 "ArchStdEvent": "UNALIGNED_ST_SPEC",
13 },
14 {
15 "ArchStdEvent": "UNALIGNED_LDST_SPEC",
16 },
17 {
18 "PublicDescription": "Data memory access",
19 "EventCode": "0x13",
20 "EventName": "MEM_ACCESS",
21 "BriefDescription": "Memory access"
22 },
23 {
24 "PublicDescription": "Local memory error. This event counts any correctable or uncorrectable memory error (ECC or parity) in the protected core RAMs",
25 "EventCode": "0x1a",
26 "EventName": "MEM_ERROR",
27 "BriefDescription": "Memory error"
28 },
29]
diff --git a/tools/perf/pmu-events/arch/arm64/ampere/emag/pipeline.json b/tools/perf/pmu-events/arch/arm64/ampere/emag/pipeline.json
new file mode 100644
index 000000000000..e2087de586bf
--- /dev/null
+++ b/tools/perf/pmu-events/arch/arm64/ampere/emag/pipeline.json
@@ -0,0 +1,50 @@
1[
2 {
3 "PublicDescription": "Decode starved for instruction cycle",
4 "EventCode": "0x108",
5 "EventName": "DECODE_STALL",
6 "BriefDescription": "Decode starved"
7 },
8 {
9 "PublicDescription": "Op dispatch stalled cycle",
10 "EventCode": "0x109",
11 "EventName": "DISPATCH_STALL",
12 "BriefDescription": "Dispatch stalled"
13 },
14 {
15 "PublicDescription": "IXA Op non-issue",
16 "EventCode": "0x10a",
17 "EventName": "IXA_STALL",
18 "BriefDescription": "IXA stalled"
19 },
20 {
21 "PublicDescription": "IXB Op non-issue",
22 "EventCode": "0x10b",
23 "EventName": "IXB_STALL",
24 "BriefDescription": "IXB stalled"
25 },
26 {
27 "PublicDescription": "BX Op non-issue",
28 "EventCode": "0x10c",
29 "EventName": "BX_STALL",
30 "BriefDescription": "BX stalled"
31 },
32 {
33 "PublicDescription": "LX Op non-issue",
34 "EventCode": "0x10d",
35 "EventName": "LX_STALL",
36 "BriefDescription": "LX stalled"
37 },
38 {
39 "PublicDescription": "SX Op non-issue",
40 "EventCode": "0x10e",
41 "EventName": "SX_STALL",
42 "BriefDescription": "SX stalled"
43 },
44 {
45 "PublicDescription": "FX Op non-issue",
46 "EventCode": "0x10f",
47 "EventName": "FX_STALL",
48 "BriefDescription": "FX stalled"
49 },
50]
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 6c108fa79ae3..0b2b8305c965 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -21,6 +21,7 @@ perf-y += python-use.o
21perf-y += bp_signal.o 21perf-y += bp_signal.o
22perf-y += bp_signal_overflow.o 22perf-y += bp_signal_overflow.o
23perf-y += bp_account.o 23perf-y += bp_account.o
24perf-y += wp.o
24perf-y += task-exit.o 25perf-y += task-exit.o
25perf-y += sw-clock.o 26perf-y += sw-clock.o
26perf-y += mmap-thread-lookup.o 27perf-y += mmap-thread-lookup.o
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index d7a5e1b9aa6f..12c09e0ece71 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -121,6 +121,16 @@ static struct test generic_tests[] = {
121 .is_supported = test__bp_signal_is_supported, 121 .is_supported = test__bp_signal_is_supported,
122 }, 122 },
123 { 123 {
124 .desc = "Watchpoint",
125 .func = test__wp,
126 .is_supported = test__wp_is_supported,
127 .subtest = {
128 .skip_if_fail = false,
129 .get_nr = test__wp_subtest_get_nr,
130 .get_desc = test__wp_subtest_get_desc,
131 },
132 },
133 {
124 .desc = "Number of exit events of a simple workload", 134 .desc = "Number of exit events of a simple workload",
125 .func = test__task_exit, 135 .func = test__task_exit,
126 }, 136 },
diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c
index 699561fa512c..5f8501c68da4 100644
--- a/tools/perf/tests/evsel-tp-sched.c
+++ b/tools/perf/tests/evsel-tp-sched.c
@@ -8,7 +8,7 @@
8static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name, 8static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,
9 int size, bool should_be_signed) 9 int size, bool should_be_signed)
10{ 10{
11 struct format_field *field = perf_evsel__field(evsel, name); 11 struct tep_format_field *field = perf_evsel__field(evsel, name);
12 int is_signed; 12 int is_signed;
13 int ret = 0; 13 int ret = 0;
14 14
@@ -17,7 +17,7 @@ static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,
17 return -1; 17 return -1;
18 } 18 }
19 19
20 is_signed = !!(field->flags | FIELD_IS_SIGNED); 20 is_signed = !!(field->flags | TEP_FIELD_IS_SIGNED);
21 if (should_be_signed && !is_signed) { 21 if (should_be_signed && !is_signed) {
22 pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n", 22 pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n",
23 evsel->name, name, is_signed, should_be_signed); 23 evsel->name, name, is_signed, should_be_signed);
diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
index 3013ac8f83d0..cab7b0aea6ea 100755
--- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
+++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
@@ -48,7 +48,7 @@ trace_libc_inet_pton_backtrace() {
48 *) 48 *)
49 eventattr='max-stack=3' 49 eventattr='max-stack=3'
50 echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected 50 echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected
51 echo ".*\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" >> $expected 51 echo ".*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$" >> $expected
52 ;; 52 ;;
53 esac 53 esac
54 54
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index a9760e790563..b82f55fcc294 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -59,6 +59,9 @@ int test__python_use(struct test *test, int subtest);
59int test__bp_signal(struct test *test, int subtest); 59int test__bp_signal(struct test *test, int subtest);
60int test__bp_signal_overflow(struct test *test, int subtest); 60int test__bp_signal_overflow(struct test *test, int subtest);
61int test__bp_accounting(struct test *test, int subtest); 61int test__bp_accounting(struct test *test, int subtest);
62int test__wp(struct test *test, int subtest);
63const char *test__wp_subtest_get_desc(int subtest);
64int test__wp_subtest_get_nr(void);
62int test__task_exit(struct test *test, int subtest); 65int test__task_exit(struct test *test, int subtest);
63int test__mem(struct test *test, int subtest); 66int test__mem(struct test *test, int subtest);
64int test__sw_clock_freq(struct test *test, int subtest); 67int test__sw_clock_freq(struct test *test, int subtest);
@@ -106,6 +109,7 @@ int test__unit_number__scnprint(struct test *test, int subtest);
106int test__mem2node(struct test *t, int subtest); 109int test__mem2node(struct test *t, int subtest);
107 110
108bool test__bp_signal_is_supported(void); 111bool test__bp_signal_is_supported(void);
112bool test__wp_is_supported(void);
109 113
110#if defined(__arm__) || defined(__aarch64__) 114#if defined(__arm__) || defined(__aarch64__)
111#ifdef HAVE_DWARF_UNWIND_SUPPORT 115#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/wp.c b/tools/perf/tests/wp.c
new file mode 100644
index 000000000000..f89e6806557b
--- /dev/null
+++ b/tools/perf/tests/wp.c
@@ -0,0 +1,241 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <stdlib.h>
3#include <sys/ioctl.h>
4#include <linux/hw_breakpoint.h>
5#include "tests.h"
6#include "debug.h"
7#include "cloexec.h"
8
9#define WP_TEST_ASSERT_VAL(fd, text, val) \
10do { \
11 long long count; \
12 wp_read(fd, &count, sizeof(long long)); \
13 TEST_ASSERT_VAL(text, count == val); \
14} while (0)
15
16volatile u64 data1;
17volatile u8 data2[3];
18
19static int wp_read(int fd, long long *count, int size)
20{
21 int ret = read(fd, count, size);
22
23 if (ret != size) {
24 pr_debug("failed to read: %d\n", ret);
25 return -1;
26 }
27 return 0;
28}
29
30static void get__perf_event_attr(struct perf_event_attr *attr, int wp_type,
31 void *wp_addr, unsigned long wp_len)
32{
33 memset(attr, 0, sizeof(struct perf_event_attr));
34 attr->type = PERF_TYPE_BREAKPOINT;
35 attr->size = sizeof(struct perf_event_attr);
36 attr->config = 0;
37 attr->bp_type = wp_type;
38 attr->bp_addr = (unsigned long)wp_addr;
39 attr->bp_len = wp_len;
40 attr->sample_period = 1;
41 attr->sample_type = PERF_SAMPLE_IP;
42 attr->exclude_kernel = 1;
43 attr->exclude_hv = 1;
44}
45
46static int __event(int wp_type, void *wp_addr, unsigned long wp_len)
47{
48 int fd;
49 struct perf_event_attr attr;
50
51 get__perf_event_attr(&attr, wp_type, wp_addr, wp_len);
52 fd = sys_perf_event_open(&attr, 0, -1, -1,
53 perf_event_open_cloexec_flag());
54 if (fd < 0)
55 pr_debug("failed opening event %x\n", attr.bp_type);
56
57 return fd;
58}
59
60static int wp_ro_test(void)
61{
62 int fd;
63 unsigned long tmp, tmp1 = rand();
64
65 fd = __event(HW_BREAKPOINT_R, (void *)&data1, sizeof(data1));
66 if (fd < 0)
67 return -1;
68
69 tmp = data1;
70 WP_TEST_ASSERT_VAL(fd, "RO watchpoint", 1);
71
72 data1 = tmp1 + tmp;
73 WP_TEST_ASSERT_VAL(fd, "RO watchpoint", 1);
74
75 close(fd);
76 return 0;
77}
78
79static int wp_wo_test(void)
80{
81 int fd;
82 unsigned long tmp, tmp1 = rand();
83
84 fd = __event(HW_BREAKPOINT_W, (void *)&data1, sizeof(data1));
85 if (fd < 0)
86 return -1;
87
88 tmp = data1;
89 WP_TEST_ASSERT_VAL(fd, "WO watchpoint", 0);
90
91 data1 = tmp1 + tmp;
92 WP_TEST_ASSERT_VAL(fd, "WO watchpoint", 1);
93
94 close(fd);
95 return 0;
96}
97
98static int wp_rw_test(void)
99{
100 int fd;
101 unsigned long tmp, tmp1 = rand();
102
103 fd = __event(HW_BREAKPOINT_R | HW_BREAKPOINT_W, (void *)&data1,
104 sizeof(data1));
105 if (fd < 0)
106 return -1;
107
108 tmp = data1;
109 WP_TEST_ASSERT_VAL(fd, "RW watchpoint", 1);
110
111 data1 = tmp1 + tmp;
112 WP_TEST_ASSERT_VAL(fd, "RW watchpoint", 2);
113
114 close(fd);
115 return 0;
116}
117
118static int wp_modify_test(void)
119{
120 int fd, ret;
121 unsigned long tmp = rand();
122 struct perf_event_attr new_attr;
123
124 fd = __event(HW_BREAKPOINT_W, (void *)&data1, sizeof(data1));
125 if (fd < 0)
126 return -1;
127
128 data1 = tmp;
129 WP_TEST_ASSERT_VAL(fd, "Modify watchpoint", 1);
130
131 /* Modify watchpoint with disabled = 1 */
132 get__perf_event_attr(&new_attr, HW_BREAKPOINT_W, (void *)&data2[0],
133 sizeof(u8) * 2);
134 new_attr.disabled = 1;
135 ret = ioctl(fd, PERF_EVENT_IOC_MODIFY_ATTRIBUTES, &new_attr);
136 if (ret < 0) {
137 pr_debug("ioctl(PERF_EVENT_IOC_MODIFY_ATTRIBUTES) failed\n");
138 close(fd);
139 return ret;
140 }
141
142 data2[1] = tmp; /* Not Counted */
143 WP_TEST_ASSERT_VAL(fd, "Modify watchpoint", 1);
144
145 /* Enable the event */
146 ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
147 if (ret < 0) {
148 pr_debug("Failed to enable event\n");
149 close(fd);
150 return ret;
151 }
152
153 data2[1] = tmp; /* Counted */
154 WP_TEST_ASSERT_VAL(fd, "Modify watchpoint", 2);
155
156 data2[2] = tmp; /* Not Counted */
157 WP_TEST_ASSERT_VAL(fd, "Modify watchpoint", 2);
158
159 close(fd);
160 return 0;
161}
162
163static bool wp_ro_supported(void)
164{
165#if defined (__x86_64__) || defined (__i386__)
166 return false;
167#else
168 return true;
169#endif
170}
171
172static void wp_ro_skip_msg(void)
173{
174#if defined (__x86_64__) || defined (__i386__)
175 pr_debug("Hardware does not support read only watchpoints.\n");
176#endif
177}
178
179static struct {
180 const char *desc;
181 int (*target_func)(void);
182 bool (*is_supported)(void);
183 void (*skip_msg)(void);
184} wp_testcase_table[] = {
185 {
186 .desc = "Read Only Watchpoint",
187 .target_func = &wp_ro_test,
188 .is_supported = &wp_ro_supported,
189 .skip_msg = &wp_ro_skip_msg,
190 },
191 {
192 .desc = "Write Only Watchpoint",
193 .target_func = &wp_wo_test,
194 },
195 {
196 .desc = "Read / Write Watchpoint",
197 .target_func = &wp_rw_test,
198 },
199 {
200 .desc = "Modify Watchpoint",
201 .target_func = &wp_modify_test,
202 },
203};
204
205int test__wp_subtest_get_nr(void)
206{
207 return (int)ARRAY_SIZE(wp_testcase_table);
208}
209
210const char *test__wp_subtest_get_desc(int i)
211{
212 if (i < 0 || i >= (int)ARRAY_SIZE(wp_testcase_table))
213 return NULL;
214 return wp_testcase_table[i].desc;
215}
216
217int test__wp(struct test *test __maybe_unused, int i)
218{
219 if (i < 0 || i >= (int)ARRAY_SIZE(wp_testcase_table))
220 return TEST_FAIL;
221
222 if (wp_testcase_table[i].is_supported &&
223 !wp_testcase_table[i].is_supported()) {
224 wp_testcase_table[i].skip_msg();
225 return TEST_SKIP;
226 }
227
228 return !wp_testcase_table[i].target_func() ? TEST_OK : TEST_FAIL;
229}
230
231/* The s390 so far does not have support for
232 * instruction breakpoint using the perf_event_open() system call.
233 */
234bool test__wp_is_supported(void)
235{
236#if defined(__s390x__)
237 return false;
238#else
239 return true;
240#endif
241}
diff --git a/tools/perf/trace/beauty/Build b/tools/perf/trace/beauty/Build
index f528ba35e140..c3b0afd67760 100644
--- a/tools/perf/trace/beauty/Build
+++ b/tools/perf/trace/beauty/Build
@@ -7,5 +7,6 @@ endif
7libperf-y += kcmp.o 7libperf-y += kcmp.o
8libperf-y += pkey_alloc.o 8libperf-y += pkey_alloc.o
9libperf-y += prctl.o 9libperf-y += prctl.o
10libperf-y += sockaddr.o
10libperf-y += socket.o 11libperf-y += socket.o
11libperf-y += statx.o 12libperf-y += statx.o
diff --git a/tools/perf/trace/beauty/beauty.h b/tools/perf/trace/beauty/beauty.h
index 9615af5d412b..2570152d3909 100644
--- a/tools/perf/trace/beauty/beauty.h
+++ b/tools/perf/trace/beauty/beauty.h
@@ -30,9 +30,36 @@ struct thread;
30 30
31size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size); 31size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_t size);
32 32
33extern struct strarray strarray__socket_families;
34
35/**
36 * augmented_arg: extra payload for syscall pointer arguments
37
38 * If perf_sample->raw_size is more than what a syscall sys_enter_FOO puts,
39 * then its the arguments contents, so that we can show more than just a
40 * pointer. This will be done initially with eBPF, the start of that is at the
41 * tools/perf/examples/bpf/augmented_syscalls.c example for the openat, but
42 * will eventually be done automagically caching the running kernel tracefs
43 * events data into an eBPF C script, that then gets compiled and its .o file
44 * cached for subsequent use. For char pointers like the ones for 'open' like
45 * syscalls its easy, for the rest we should use DWARF or better, BTF, much
46 * more compact.
47 *
48 * @size: 8 if all we need is an integer, otherwise all of the augmented arg.
49 * @int_arg: will be used for integer like pointer contents, like 'accept's 'upeer_addrlen'
50 * @value: u64 aligned, for structs, pathnames
51 */
52struct augmented_arg {
53 int size;
54 int int_arg;
55 u64 value[];
56};
57
33/** 58/**
34 * @val: value of syscall argument being formatted 59 * @val: value of syscall argument being formatted
35 * @args: All the args, use syscall_args__val(arg, nth) to access one 60 * @args: All the args, use syscall_args__val(arg, nth) to access one
61 * @augmented_args: Extra data that can be collected, for instance, with eBPF for expanding the pathname for open, etc
62 * @augmented_args_size: augmented_args total payload size
36 * @thread: tid state (maps, pid, tid, etc) 63 * @thread: tid state (maps, pid, tid, etc)
37 * @trace: 'perf trace' internals: all threads, etc 64 * @trace: 'perf trace' internals: all threads, etc
38 * @parm: private area, may be an strarray, for instance 65 * @parm: private area, may be an strarray, for instance
@@ -43,6 +70,10 @@ size_t pid__scnprintf_fd(struct trace *trace, pid_t pid, int fd, char *bf, size_
43struct syscall_arg { 70struct syscall_arg {
44 unsigned long val; 71 unsigned long val;
45 unsigned char *args; 72 unsigned char *args;
73 struct {
74 struct augmented_arg *args;
75 int size;
76 } augmented;
46 struct thread *thread; 77 struct thread *thread;
47 struct trace *trace; 78 struct trace *trace;
48 void *parm; 79 void *parm;
@@ -106,6 +137,9 @@ size_t syscall_arg__scnprintf_prctl_arg2(char *bf, size_t size, struct syscall_a
106size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg); 137size_t syscall_arg__scnprintf_prctl_arg3(char *bf, size_t size, struct syscall_arg *arg);
107#define SCA_PRCTL_ARG3 syscall_arg__scnprintf_prctl_arg3 138#define SCA_PRCTL_ARG3 syscall_arg__scnprintf_prctl_arg3
108 139
140size_t syscall_arg__scnprintf_sockaddr(char *bf, size_t size, struct syscall_arg *arg);
141#define SCA_SOCKADDR syscall_arg__scnprintf_sockaddr
142
109size_t syscall_arg__scnprintf_socket_protocol(char *bf, size_t size, struct syscall_arg *arg); 143size_t syscall_arg__scnprintf_socket_protocol(char *bf, size_t size, struct syscall_arg *arg);
110#define SCA_SK_PROTO syscall_arg__scnprintf_socket_protocol 144#define SCA_SK_PROTO syscall_arg__scnprintf_socket_protocol
111 145
diff --git a/tools/perf/trace/beauty/sockaddr.c b/tools/perf/trace/beauty/sockaddr.c
new file mode 100644
index 000000000000..71a79f72d9d9
--- /dev/null
+++ b/tools/perf/trace/beauty/sockaddr.c
@@ -0,0 +1,76 @@
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
3
4#include "trace/beauty/beauty.h"
5#include <sys/socket.h>
6#include <sys/types.h>
7#include <sys/un.h>
8#include <arpa/inet.h>
9
10static const char *socket_families[] = {
11 "UNSPEC", "LOCAL", "INET", "AX25", "IPX", "APPLETALK", "NETROM",
12 "BRIDGE", "ATMPVC", "X25", "INET6", "ROSE", "DECnet", "NETBEUI",
13 "SECURITY", "KEY", "NETLINK", "PACKET", "ASH", "ECONET", "ATMSVC",
14 "RDS", "SNA", "IRDA", "PPPOX", "WANPIPE", "LLC", "IB", "CAN", "TIPC",
15 "BLUETOOTH", "IUCV", "RXRPC", "ISDN", "PHONET", "IEEE802154", "CAIF",
16 "ALG", "NFC", "VSOCK",
17};
18DEFINE_STRARRAY(socket_families);
19
20static size_t af_inet__scnprintf(struct sockaddr *sa, char *bf, size_t size)
21{
22 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
23 char tmp[16];
24 return scnprintf(bf, size, ", port: %d, addr: %s", ntohs(sin->sin_port),
25 inet_ntop(sin->sin_family, &sin->sin_addr, tmp, sizeof(tmp)));
26}
27
28static size_t af_inet6__scnprintf(struct sockaddr *sa, char *bf, size_t size)
29{
30 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
31 u32 flowinfo = ntohl(sin6->sin6_flowinfo);
32 char tmp[512];
33 size_t printed = scnprintf(bf, size, ", port: %d, addr: %s", ntohs(sin6->sin6_port),
34 inet_ntop(sin6->sin6_family, &sin6->sin6_addr, tmp, sizeof(tmp)));
35 if (flowinfo != 0)
36 printed += scnprintf(bf + printed, size - printed, ", flowinfo: %lu", flowinfo);
37 if (sin6->sin6_scope_id != 0)
38 printed += scnprintf(bf + printed, size - printed, ", scope_id: %lu", sin6->sin6_scope_id);
39
40 return printed;
41}
42
43static size_t af_local__scnprintf(struct sockaddr *sa, char *bf, size_t size)
44{
45 struct sockaddr_un *sun = (struct sockaddr_un *)sa;
46 return scnprintf(bf, size, ", path: %s", sun->sun_path);
47}
48
49static size_t (*af_scnprintfs[])(struct sockaddr *sa, char *bf, size_t size) = {
50 [AF_LOCAL] = af_local__scnprintf,
51 [AF_INET] = af_inet__scnprintf,
52 [AF_INET6] = af_inet6__scnprintf,
53};
54
55static size_t syscall_arg__scnprintf_augmented_sockaddr(struct syscall_arg *arg, char *bf, size_t size)
56{
57 struct sockaddr *sa = (struct sockaddr *)arg->augmented.args;
58 char family[32];
59 size_t printed;
60
61 strarray__scnprintf(&strarray__socket_families, family, sizeof(family), "%d", sa->sa_family);
62 printed = scnprintf(bf, size, "{ .family: %s", family);
63
64 if (sa->sa_family < ARRAY_SIZE(af_scnprintfs) && af_scnprintfs[sa->sa_family])
65 printed += af_scnprintfs[sa->sa_family](sa, bf + printed, size - printed);
66
67 return printed + scnprintf(bf + printed, size - printed, " }");
68}
69
70size_t syscall_arg__scnprintf_sockaddr(char *bf, size_t size, struct syscall_arg *arg)
71{
72 if (arg->augmented.args)
73 return syscall_arg__scnprintf_augmented_sockaddr(arg, bf, size);
74
75 return scnprintf(bf, size, "%#x", arg->val);
76}
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 7efe15b9618d..ecd9f9ceda77 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -73,6 +73,7 @@ libperf-y += vdso.o
73libperf-y += counts.o 73libperf-y += counts.o
74libperf-y += stat.o 74libperf-y += stat.o
75libperf-y += stat-shadow.o 75libperf-y += stat-shadow.o
76libperf-y += stat-display.o
76libperf-y += record.o 77libperf-y += record.o
77libperf-y += srcline.o 78libperf-y += srcline.o
78libperf-y += data.o 79libperf-y += data.o
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index db1511359c5e..c4617bcfd521 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -906,9 +906,8 @@ out_free:
906 return err; 906 return err;
907} 907}
908 908
909int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused, 909int perf_event__process_auxtrace_info(struct perf_session *session,
910 union perf_event *event, 910 union perf_event *event)
911 struct perf_session *session)
912{ 911{
913 enum auxtrace_type type = event->auxtrace_info.type; 912 enum auxtrace_type type = event->auxtrace_info.type;
914 913
@@ -932,9 +931,8 @@ int perf_event__process_auxtrace_info(struct perf_tool *tool __maybe_unused,
932 } 931 }
933} 932}
934 933
935s64 perf_event__process_auxtrace(struct perf_tool *tool, 934s64 perf_event__process_auxtrace(struct perf_session *session,
936 union perf_event *event, 935 union perf_event *event)
937 struct perf_session *session)
938{ 936{
939 s64 err; 937 s64 err;
940 938
@@ -950,7 +948,7 @@ s64 perf_event__process_auxtrace(struct perf_tool *tool,
950 if (!session->auxtrace || event->header.type != PERF_RECORD_AUXTRACE) 948 if (!session->auxtrace || event->header.type != PERF_RECORD_AUXTRACE)
951 return -EINVAL; 949 return -EINVAL;
952 950
953 err = session->auxtrace->process_auxtrace_event(session, event, tool); 951 err = session->auxtrace->process_auxtrace_event(session, event, session->tool);
954 if (err < 0) 952 if (err < 0)
955 return err; 953 return err;
956 954
@@ -1185,9 +1183,8 @@ void events_stats__auxtrace_error_warn(const struct events_stats *stats)
1185 } 1183 }
1186} 1184}
1187 1185
1188int perf_event__process_auxtrace_error(struct perf_tool *tool __maybe_unused, 1186int perf_event__process_auxtrace_error(struct perf_session *session,
1189 union perf_event *event, 1187 union perf_event *event)
1190 struct perf_session *session)
1191{ 1188{
1192 if (auxtrace__dont_decode(session)) 1189 if (auxtrace__dont_decode(session))
1193 return 0; 1190 return 0;
@@ -1196,11 +1193,12 @@ int perf_event__process_auxtrace_error(struct perf_tool *tool __maybe_unused,
1196 return 0; 1193 return 0;
1197} 1194}
1198 1195
1199static int __auxtrace_mmap__read(struct auxtrace_mmap *mm, 1196static int __auxtrace_mmap__read(struct perf_mmap *map,
1200 struct auxtrace_record *itr, 1197 struct auxtrace_record *itr,
1201 struct perf_tool *tool, process_auxtrace_t fn, 1198 struct perf_tool *tool, process_auxtrace_t fn,
1202 bool snapshot, size_t snapshot_size) 1199 bool snapshot, size_t snapshot_size)
1203{ 1200{
1201 struct auxtrace_mmap *mm = &map->auxtrace_mmap;
1204 u64 head, old = mm->prev, offset, ref; 1202 u64 head, old = mm->prev, offset, ref;
1205 unsigned char *data = mm->base; 1203 unsigned char *data = mm->base;
1206 size_t size, head_off, old_off, len1, len2, padding; 1204 size_t size, head_off, old_off, len1, len2, padding;
@@ -1287,7 +1285,7 @@ static int __auxtrace_mmap__read(struct auxtrace_mmap *mm,
1287 ev.auxtrace.tid = mm->tid; 1285 ev.auxtrace.tid = mm->tid;
1288 ev.auxtrace.cpu = mm->cpu; 1286 ev.auxtrace.cpu = mm->cpu;
1289 1287
1290 if (fn(tool, &ev, data1, len1, data2, len2)) 1288 if (fn(tool, map, &ev, data1, len1, data2, len2))
1291 return -1; 1289 return -1;
1292 1290
1293 mm->prev = head; 1291 mm->prev = head;
@@ -1306,18 +1304,18 @@ static int __auxtrace_mmap__read(struct auxtrace_mmap *mm,
1306 return 1; 1304 return 1;
1307} 1305}
1308 1306
1309int auxtrace_mmap__read(struct auxtrace_mmap *mm, struct auxtrace_record *itr, 1307int auxtrace_mmap__read(struct perf_mmap *map, struct auxtrace_record *itr,
1310 struct perf_tool *tool, process_auxtrace_t fn) 1308 struct perf_tool *tool, process_auxtrace_t fn)
1311{ 1309{
1312 return __auxtrace_mmap__read(mm, itr, tool, fn, false, 0); 1310 return __auxtrace_mmap__read(map, itr, tool, fn, false, 0);
1313} 1311}
1314 1312
1315int auxtrace_mmap__read_snapshot(struct auxtrace_mmap *mm, 1313int auxtrace_mmap__read_snapshot(struct perf_mmap *map,
1316 struct auxtrace_record *itr, 1314 struct auxtrace_record *itr,
1317 struct perf_tool *tool, process_auxtrace_t fn, 1315 struct perf_tool *tool, process_auxtrace_t fn,
1318 size_t snapshot_size) 1316 size_t snapshot_size)
1319{ 1317{
1320 return __auxtrace_mmap__read(mm, itr, tool, fn, true, snapshot_size); 1318 return __auxtrace_mmap__read(map, itr, tool, fn, true, snapshot_size);
1321} 1319}
1322 1320
1323/** 1321/**
diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
index 71fc3bd74299..d88f6e9eb461 100644
--- a/tools/perf/util/auxtrace.h
+++ b/tools/perf/util/auxtrace.h
@@ -23,6 +23,7 @@
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/perf_event.h> 24#include <linux/perf_event.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <asm/bitsperlong.h>
26 27
27#include "../perf.h" 28#include "../perf.h"
28#include "event.h" 29#include "event.h"
@@ -33,6 +34,7 @@ union perf_event;
33struct perf_session; 34struct perf_session;
34struct perf_evlist; 35struct perf_evlist;
35struct perf_tool; 36struct perf_tool;
37struct perf_mmap;
36struct option; 38struct option;
37struct record_opts; 39struct record_opts;
38struct auxtrace_info_event; 40struct auxtrace_info_event;
@@ -434,13 +436,14 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
434 bool per_cpu); 436 bool per_cpu);
435 437
436typedef int (*process_auxtrace_t)(struct perf_tool *tool, 438typedef int (*process_auxtrace_t)(struct perf_tool *tool,
439 struct perf_mmap *map,
437 union perf_event *event, void *data1, 440 union perf_event *event, void *data1,
438 size_t len1, void *data2, size_t len2); 441 size_t len1, void *data2, size_t len2);
439 442
440int auxtrace_mmap__read(struct auxtrace_mmap *mm, struct auxtrace_record *itr, 443int auxtrace_mmap__read(struct perf_mmap *map, struct auxtrace_record *itr,
441 struct perf_tool *tool, process_auxtrace_t fn); 444 struct perf_tool *tool, process_auxtrace_t fn);
442 445
443int auxtrace_mmap__read_snapshot(struct auxtrace_mmap *mm, 446int auxtrace_mmap__read_snapshot(struct perf_mmap *map,
444 struct auxtrace_record *itr, 447 struct auxtrace_record *itr,
445 struct perf_tool *tool, process_auxtrace_t fn, 448 struct perf_tool *tool, process_auxtrace_t fn,
446 size_t snapshot_size); 449 size_t snapshot_size);
@@ -517,15 +520,12 @@ int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr,
517 struct perf_tool *tool, 520 struct perf_tool *tool,
518 struct perf_session *session, 521 struct perf_session *session,
519 perf_event__handler_t process); 522 perf_event__handler_t process);
520int perf_event__process_auxtrace_info(struct perf_tool *tool, 523int perf_event__process_auxtrace_info(struct perf_session *session,
521 union perf_event *event, 524 union perf_event *event);
522 struct perf_session *session); 525s64 perf_event__process_auxtrace(struct perf_session *session,
523s64 perf_event__process_auxtrace(struct perf_tool *tool, 526 union perf_event *event);
524 union perf_event *event, 527int perf_event__process_auxtrace_error(struct perf_session *session,
525 struct perf_session *session); 528 union perf_event *event);
526int perf_event__process_auxtrace_error(struct perf_tool *tool,
527 union perf_event *event,
528 struct perf_session *session);
529int itrace_parse_synth_opts(const struct option *opt, const char *str, 529int itrace_parse_synth_opts(const struct option *opt, const char *str,
530 int unset); 530 int unset);
531void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts); 531void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts);
@@ -577,6 +577,23 @@ static inline void auxtrace__free(struct perf_session *session)
577 return session->auxtrace->free(session); 577 return session->auxtrace->free(session);
578} 578}
579 579
580#define ITRACE_HELP \
581" i: synthesize instructions events\n" \
582" b: synthesize branches events\n" \
583" c: synthesize branches events (calls only)\n" \
584" r: synthesize branches events (returns only)\n" \
585" x: synthesize transactions events\n" \
586" w: synthesize ptwrite events\n" \
587" p: synthesize power events\n" \
588" e: synthesize error events\n" \
589" d: create a debug log\n" \
590" g[len]: synthesize a call chain (use with i or x)\n" \
591" l[len]: synthesize last branch entries (use with i or x)\n" \
592" sNUMBER: skip initial number of events\n" \
593" PERIOD[ns|us|ms|i|t]: specify period to sample stream\n" \
594" concatenate multiple options. Default is ibxwpe or cewp\n"
595
596
580#else 597#else
581 598
582static inline struct auxtrace_record * 599static inline struct auxtrace_record *
@@ -717,6 +734,8 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
717 struct perf_evlist *evlist, int idx, 734 struct perf_evlist *evlist, int idx,
718 bool per_cpu); 735 bool per_cpu);
719 736
737#define ITRACE_HELP ""
738
720#endif 739#endif
721 740
722#endif 741#endif
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 47aac41349a2..f9ae1a993806 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1615,7 +1615,7 @@ struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const cha
1615int bpf__setup_stdout(struct perf_evlist *evlist) 1615int bpf__setup_stdout(struct perf_evlist *evlist)
1616{ 1616{
1617 struct perf_evsel *evsel = bpf__setup_output_event(evlist, "__bpf_stdout__"); 1617 struct perf_evsel *evsel = bpf__setup_output_event(evlist, "__bpf_stdout__");
1618 return IS_ERR(evsel) ? PTR_ERR(evsel) : 0; 1618 return PTR_ERR_OR_ZERO(evsel);
1619} 1619}
1620 1620
1621#define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START) 1621#define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START)
diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-convert-bt.c
index abd38abf1d91..2a36fab76994 100644
--- a/tools/perf/util/data-convert-bt.c
+++ b/tools/perf/util/data-convert-bt.c
@@ -182,20 +182,20 @@ err_put_field:
182} 182}
183 183
184static struct bt_ctf_field_type* 184static struct bt_ctf_field_type*
185get_tracepoint_field_type(struct ctf_writer *cw, struct format_field *field) 185get_tracepoint_field_type(struct ctf_writer *cw, struct tep_format_field *field)
186{ 186{
187 unsigned long flags = field->flags; 187 unsigned long flags = field->flags;
188 188
189 if (flags & FIELD_IS_STRING) 189 if (flags & TEP_FIELD_IS_STRING)
190 return cw->data.string; 190 return cw->data.string;
191 191
192 if (!(flags & FIELD_IS_SIGNED)) { 192 if (!(flags & TEP_FIELD_IS_SIGNED)) {
193 /* unsigned long are mostly pointers */ 193 /* unsigned long are mostly pointers */
194 if (flags & FIELD_IS_LONG || flags & FIELD_IS_POINTER) 194 if (flags & TEP_FIELD_IS_LONG || flags & TEP_FIELD_IS_POINTER)
195 return cw->data.u64_hex; 195 return cw->data.u64_hex;
196 } 196 }
197 197
198 if (flags & FIELD_IS_SIGNED) { 198 if (flags & TEP_FIELD_IS_SIGNED) {
199 if (field->size == 8) 199 if (field->size == 8)
200 return cw->data.s64; 200 return cw->data.s64;
201 else 201 else
@@ -287,7 +287,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
287 struct bt_ctf_event_class *event_class, 287 struct bt_ctf_event_class *event_class,
288 struct bt_ctf_event *event, 288 struct bt_ctf_event *event,
289 struct perf_sample *sample, 289 struct perf_sample *sample,
290 struct format_field *fmtf) 290 struct tep_format_field *fmtf)
291{ 291{
292 struct bt_ctf_field_type *type; 292 struct bt_ctf_field_type *type;
293 struct bt_ctf_field *array_field; 293 struct bt_ctf_field *array_field;
@@ -304,10 +304,10 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
304 name = fmtf->alias; 304 name = fmtf->alias;
305 offset = fmtf->offset; 305 offset = fmtf->offset;
306 len = fmtf->size; 306 len = fmtf->size;
307 if (flags & FIELD_IS_STRING) 307 if (flags & TEP_FIELD_IS_STRING)
308 flags &= ~FIELD_IS_ARRAY; 308 flags &= ~TEP_FIELD_IS_ARRAY;
309 309
310 if (flags & FIELD_IS_DYNAMIC) { 310 if (flags & TEP_FIELD_IS_DYNAMIC) {
311 unsigned long long tmp_val; 311 unsigned long long tmp_val;
312 312
313 tmp_val = tep_read_number(fmtf->event->pevent, 313 tmp_val = tep_read_number(fmtf->event->pevent,
@@ -317,7 +317,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
317 offset &= 0xffff; 317 offset &= 0xffff;
318 } 318 }
319 319
320 if (flags & FIELD_IS_ARRAY) { 320 if (flags & TEP_FIELD_IS_ARRAY) {
321 321
322 type = bt_ctf_event_class_get_field_by_name( 322 type = bt_ctf_event_class_get_field_by_name(
323 event_class, name); 323 event_class, name);
@@ -338,7 +338,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
338 type = get_tracepoint_field_type(cw, fmtf); 338 type = get_tracepoint_field_type(cw, fmtf);
339 339
340 for (i = 0; i < n_items; i++) { 340 for (i = 0; i < n_items; i++) {
341 if (flags & FIELD_IS_ARRAY) 341 if (flags & TEP_FIELD_IS_ARRAY)
342 field = bt_ctf_field_array_get_field(array_field, i); 342 field = bt_ctf_field_array_get_field(array_field, i);
343 else 343 else
344 field = bt_ctf_field_create(type); 344 field = bt_ctf_field_create(type);
@@ -348,7 +348,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
348 return -1; 348 return -1;
349 } 349 }
350 350
351 if (flags & FIELD_IS_STRING) 351 if (flags & TEP_FIELD_IS_STRING)
352 ret = string_set_value(field, data + offset + i * len); 352 ret = string_set_value(field, data + offset + i * len);
353 else { 353 else {
354 unsigned long long value_int; 354 unsigned long long value_int;
@@ -357,7 +357,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
357 fmtf->event->pevent, 357 fmtf->event->pevent,
358 data + offset + i * len, len); 358 data + offset + i * len, len);
359 359
360 if (!(flags & FIELD_IS_SIGNED)) 360 if (!(flags & TEP_FIELD_IS_SIGNED))
361 ret = bt_ctf_field_unsigned_integer_set_value( 361 ret = bt_ctf_field_unsigned_integer_set_value(
362 field, value_int); 362 field, value_int);
363 else 363 else
@@ -369,7 +369,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
369 pr_err("failed to set file value %s\n", name); 369 pr_err("failed to set file value %s\n", name);
370 goto err_put_field; 370 goto err_put_field;
371 } 371 }
372 if (!(flags & FIELD_IS_ARRAY)) { 372 if (!(flags & TEP_FIELD_IS_ARRAY)) {
373 ret = bt_ctf_event_set_payload(event, name, field); 373 ret = bt_ctf_event_set_payload(event, name, field);
374 if (ret) { 374 if (ret) {
375 pr_err("failed to set payload %s\n", name); 375 pr_err("failed to set payload %s\n", name);
@@ -378,7 +378,7 @@ static int add_tracepoint_field_value(struct ctf_writer *cw,
378 } 378 }
379 bt_ctf_field_put(field); 379 bt_ctf_field_put(field);
380 } 380 }
381 if (flags & FIELD_IS_ARRAY) { 381 if (flags & TEP_FIELD_IS_ARRAY) {
382 ret = bt_ctf_event_set_payload(event, name, array_field); 382 ret = bt_ctf_event_set_payload(event, name, array_field);
383 if (ret) { 383 if (ret) {
384 pr_err("Failed add payload array %s\n", name); 384 pr_err("Failed add payload array %s\n", name);
@@ -396,10 +396,10 @@ err_put_field:
396static int add_tracepoint_fields_values(struct ctf_writer *cw, 396static int add_tracepoint_fields_values(struct ctf_writer *cw,
397 struct bt_ctf_event_class *event_class, 397 struct bt_ctf_event_class *event_class,
398 struct bt_ctf_event *event, 398 struct bt_ctf_event *event,
399 struct format_field *fields, 399 struct tep_format_field *fields,
400 struct perf_sample *sample) 400 struct perf_sample *sample)
401{ 401{
402 struct format_field *field; 402 struct tep_format_field *field;
403 int ret; 403 int ret;
404 404
405 for (field = fields; field; field = field->next) { 405 for (field = fields; field; field = field->next) {
@@ -417,8 +417,8 @@ static int add_tracepoint_values(struct ctf_writer *cw,
417 struct perf_evsel *evsel, 417 struct perf_evsel *evsel,
418 struct perf_sample *sample) 418 struct perf_sample *sample)
419{ 419{
420 struct format_field *common_fields = evsel->tp_format->format.common_fields; 420 struct tep_format_field *common_fields = evsel->tp_format->format.common_fields;
421 struct format_field *fields = evsel->tp_format->format.fields; 421 struct tep_format_field *fields = evsel->tp_format->format.fields;
422 int ret; 422 int ret;
423 423
424 ret = add_tracepoint_fields_values(cw, event_class, event, 424 ret = add_tracepoint_fields_values(cw, event_class, event,
@@ -970,7 +970,7 @@ out:
970 970
971static int event_class_add_field(struct bt_ctf_event_class *event_class, 971static int event_class_add_field(struct bt_ctf_event_class *event_class,
972 struct bt_ctf_field_type *type, 972 struct bt_ctf_field_type *type,
973 struct format_field *field) 973 struct tep_format_field *field)
974{ 974{
975 struct bt_ctf_field_type *t = NULL; 975 struct bt_ctf_field_type *t = NULL;
976 char *name; 976 char *name;
@@ -1009,10 +1009,10 @@ static int event_class_add_field(struct bt_ctf_event_class *event_class,
1009} 1009}
1010 1010
1011static int add_tracepoint_fields_types(struct ctf_writer *cw, 1011static int add_tracepoint_fields_types(struct ctf_writer *cw,
1012 struct format_field *fields, 1012 struct tep_format_field *fields,
1013 struct bt_ctf_event_class *event_class) 1013 struct bt_ctf_event_class *event_class)
1014{ 1014{
1015 struct format_field *field; 1015 struct tep_format_field *field;
1016 int ret; 1016 int ret;
1017 1017
1018 for (field = fields; field; field = field->next) { 1018 for (field = fields; field; field = field->next) {
@@ -1030,15 +1030,15 @@ static int add_tracepoint_fields_types(struct ctf_writer *cw,
1030 * type and don't care that it is an array. What we don't 1030 * type and don't care that it is an array. What we don't
1031 * support is an array of strings. 1031 * support is an array of strings.
1032 */ 1032 */
1033 if (flags & FIELD_IS_STRING) 1033 if (flags & TEP_FIELD_IS_STRING)
1034 flags &= ~FIELD_IS_ARRAY; 1034 flags &= ~TEP_FIELD_IS_ARRAY;
1035 1035
1036 if (flags & FIELD_IS_ARRAY) 1036 if (flags & TEP_FIELD_IS_ARRAY)
1037 type = bt_ctf_field_type_array_create(type, field->arraylen); 1037 type = bt_ctf_field_type_array_create(type, field->arraylen);
1038 1038
1039 ret = event_class_add_field(event_class, type, field); 1039 ret = event_class_add_field(event_class, type, field);
1040 1040
1041 if (flags & FIELD_IS_ARRAY) 1041 if (flags & TEP_FIELD_IS_ARRAY)
1042 bt_ctf_field_type_put(type); 1042 bt_ctf_field_type_put(type);
1043 1043
1044 if (ret) { 1044 if (ret) {
@@ -1055,8 +1055,8 @@ static int add_tracepoint_types(struct ctf_writer *cw,
1055 struct perf_evsel *evsel, 1055 struct perf_evsel *evsel,
1056 struct bt_ctf_event_class *class) 1056 struct bt_ctf_event_class *class)
1057{ 1057{
1058 struct format_field *common_fields = evsel->tp_format->format.common_fields; 1058 struct tep_format_field *common_fields = evsel->tp_format->format.common_fields;
1059 struct format_field *fields = evsel->tp_format->format.fields; 1059 struct tep_format_field *fields = evsel->tp_format->format.fields;
1060 int ret; 1060 int ret;
1061 1061
1062 ret = add_tracepoint_fields_types(cw, common_fields, class); 1062 ret = add_tracepoint_fields_types(cw, common_fields, class);
@@ -1578,7 +1578,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
1578{ 1578{
1579 struct perf_session *session; 1579 struct perf_session *session;
1580 struct perf_data data = { 1580 struct perf_data data = {
1581 .file.path = input, 1581 .file = { .path = input, .fd = -1 },
1582 .mode = PERF_DATA_MODE_READ, 1582 .mode = PERF_DATA_MODE_READ,
1583 .force = opts->force, 1583 .force = opts->force,
1584 }; 1584 };
diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c
index 7123746edcf4..69fbb0a72d0c 100644
--- a/tools/perf/util/db-export.c
+++ b/tools/perf/util/db-export.c
@@ -463,6 +463,28 @@ int db_export__branch_types(struct db_export *dbe)
463 if (err) 463 if (err)
464 break; 464 break;
465 } 465 }
466
467 /* Add trace begin / end variants */
468 for (i = 0; branch_types[i].name ; i++) {
469 const char *name = branch_types[i].name;
470 u32 type = branch_types[i].branch_type;
471 char buf[64];
472
473 if (type == PERF_IP_FLAG_BRANCH ||
474 (type & (PERF_IP_FLAG_TRACE_BEGIN | PERF_IP_FLAG_TRACE_END)))
475 continue;
476
477 snprintf(buf, sizeof(buf), "trace begin / %s", name);
478 err = db_export__branch_type(dbe, type | PERF_IP_FLAG_TRACE_BEGIN, buf);
479 if (err)
480 break;
481
482 snprintf(buf, sizeof(buf), "%s / trace end", name);
483 err = db_export__branch_type(dbe, type | PERF_IP_FLAG_TRACE_END, buf);
484 if (err)
485 break;
486 }
487
466 return err; 488 return err;
467} 489}
468 490
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e596ae358c4d..29d7b97f66fb 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2685,7 +2685,7 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
2685 return 0; 2685 return 0;
2686} 2686}
2687 2687
2688struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name) 2688struct tep_format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name)
2689{ 2689{
2690 return tep_find_field(evsel->tp_format, name); 2690 return tep_find_field(evsel->tp_format, name);
2691} 2691}
@@ -2693,7 +2693,7 @@ struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *nam
2693void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample, 2693void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
2694 const char *name) 2694 const char *name)
2695{ 2695{
2696 struct format_field *field = perf_evsel__field(evsel, name); 2696 struct tep_format_field *field = perf_evsel__field(evsel, name);
2697 int offset; 2697 int offset;
2698 2698
2699 if (!field) 2699 if (!field)
@@ -2701,7 +2701,7 @@ void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
2701 2701
2702 offset = field->offset; 2702 offset = field->offset;
2703 2703
2704 if (field->flags & FIELD_IS_DYNAMIC) { 2704 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
2705 offset = *(int *)(sample->raw_data + field->offset); 2705 offset = *(int *)(sample->raw_data + field->offset);
2706 offset &= 0xffff; 2706 offset &= 0xffff;
2707 } 2707 }
@@ -2709,7 +2709,7 @@ void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample,
2709 return sample->raw_data + offset; 2709 return sample->raw_data + offset;
2710} 2710}
2711 2711
2712u64 format_field__intval(struct format_field *field, struct perf_sample *sample, 2712u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample,
2713 bool needs_swap) 2713 bool needs_swap)
2714{ 2714{
2715 u64 value; 2715 u64 value;
@@ -2751,7 +2751,7 @@ u64 format_field__intval(struct format_field *field, struct perf_sample *sample,
2751u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, 2751u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
2752 const char *name) 2752 const char *name)
2753{ 2753{
2754 struct format_field *field = perf_evsel__field(evsel, name); 2754 struct tep_format_field *field = perf_evsel__field(evsel, name);
2755 2755
2756 if (!field) 2756 if (!field)
2757 return 0; 2757 return 0;
@@ -2943,3 +2943,32 @@ struct perf_env *perf_evsel__env(struct perf_evsel *evsel)
2943 return evsel->evlist->env; 2943 return evsel->evlist->env;
2944 return NULL; 2944 return NULL;
2945} 2945}
2946
2947static int store_evsel_ids(struct perf_evsel *evsel, struct perf_evlist *evlist)
2948{
2949 int cpu, thread;
2950
2951 for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) {
2952 for (thread = 0; thread < xyarray__max_y(evsel->fd);
2953 thread++) {
2954 int fd = FD(evsel, cpu, thread);
2955
2956 if (perf_evlist__id_add_fd(evlist, evsel,
2957 cpu, thread, fd) < 0)
2958 return -1;
2959 }
2960 }
2961
2962 return 0;
2963}
2964
2965int perf_evsel__store_ids(struct perf_evsel *evsel, struct perf_evlist *evlist)
2966{
2967 struct cpu_map *cpus = evsel->cpus;
2968 struct thread_map *threads = evsel->threads;
2969
2970 if (perf_evsel__alloc_id(evsel, cpus->nr, threads->nr))
2971 return -ENOMEM;
2972
2973 return store_evsel_ids(evsel, evlist);
2974}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 163c960614d3..4107c39f4a54 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -102,7 +102,7 @@ struct perf_evsel {
102 char *name; 102 char *name;
103 double scale; 103 double scale;
104 const char *unit; 104 const char *unit;
105 struct event_format *tp_format; 105 struct tep_event_format *tp_format;
106 off_t id_offset; 106 off_t id_offset;
107 struct perf_stat_evsel *stats; 107 struct perf_stat_evsel *stats;
108 void *priv; 108 void *priv;
@@ -211,7 +211,7 @@ static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *
211 211
212struct perf_evsel *perf_evsel__new_cycles(bool precise); 212struct perf_evsel *perf_evsel__new_cycles(bool precise);
213 213
214struct event_format *event_format__new(const char *sys, const char *name); 214struct tep_event_format *event_format__new(const char *sys, const char *name);
215 215
216void perf_evsel__init(struct perf_evsel *evsel, 216void perf_evsel__init(struct perf_evsel *evsel,
217 struct perf_event_attr *attr, int idx); 217 struct perf_event_attr *attr, int idx);
@@ -296,11 +296,11 @@ static inline char *perf_evsel__strval(struct perf_evsel *evsel,
296 return perf_evsel__rawptr(evsel, sample, name); 296 return perf_evsel__rawptr(evsel, sample, name);
297} 297}
298 298
299struct format_field; 299struct tep_format_field;
300 300
301u64 format_field__intval(struct format_field *field, struct perf_sample *sample, bool needs_swap); 301u64 format_field__intval(struct tep_format_field *field, struct perf_sample *sample, bool needs_swap);
302 302
303struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name); 303struct tep_format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
304 304
305#define perf_evsel__match(evsel, t, c) \ 305#define perf_evsel__match(evsel, t, c) \
306 (evsel->attr.type == PERF_TYPE_##t && \ 306 (evsel->attr.type == PERF_TYPE_##t && \
@@ -481,4 +481,5 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr,
481 481
482struct perf_env *perf_evsel__env(struct perf_evsel *evsel); 482struct perf_env *perf_evsel__env(struct perf_evsel *evsel);
483 483
484int perf_evsel__store_ids(struct perf_evsel *evsel, struct perf_evlist *evlist);
484#endif /* __PERF_EVSEL_H */ 485#endif /* __PERF_EVSEL_H */
diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprintf.c
index 06dfb027879d..0d0a4c6f368b 100644
--- a/tools/perf/util/evsel_fprintf.c
+++ b/tools/perf/util/evsel_fprintf.c
@@ -73,7 +73,7 @@ int perf_evsel__fprintf(struct perf_evsel *evsel,
73 } 73 }
74 74
75 if (details->trace_fields) { 75 if (details->trace_fields) {
76 struct format_field *field; 76 struct tep_format_field *field;
77 77
78 if (evsel->attr.type != PERF_TYPE_TRACEPOINT) { 78 if (evsel->attr.type != PERF_TYPE_TRACEPOINT) {
79 printed += comma_fprintf(fp, &first, " (not a tracepoint)"); 79 printed += comma_fprintf(fp, &first, " (not a tracepoint)");
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 3cadc252dd89..1ec1d9bc2d63 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3206,7 +3206,7 @@ static int read_attr(int fd, struct perf_header *ph,
3206static int perf_evsel__prepare_tracepoint_event(struct perf_evsel *evsel, 3206static int perf_evsel__prepare_tracepoint_event(struct perf_evsel *evsel,
3207 struct tep_handle *pevent) 3207 struct tep_handle *pevent)
3208{ 3208{
3209 struct event_format *event; 3209 struct tep_event_format *event;
3210 char bf[128]; 3210 char bf[128];
3211 3211
3212 /* already prepared */ 3212 /* already prepared */
@@ -3448,10 +3448,10 @@ int perf_event__synthesize_features(struct perf_tool *tool,
3448 return ret; 3448 return ret;
3449} 3449}
3450 3450
3451int perf_event__process_feature(struct perf_tool *tool, 3451int perf_event__process_feature(struct perf_session *session,
3452 union perf_event *event, 3452 union perf_event *event)
3453 struct perf_session *session __maybe_unused)
3454{ 3453{
3454 struct perf_tool *tool = session->tool;
3455 struct feat_fd ff = { .fd = 0 }; 3455 struct feat_fd ff = { .fd = 0 };
3456 struct feature_event *fe = (struct feature_event *)event; 3456 struct feature_event *fe = (struct feature_event *)event;
3457 int type = fe->header.type; 3457 int type = fe->header.type;
@@ -3637,13 +3637,13 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp)
3637} 3637}
3638 3638
3639int perf_event__synthesize_attrs(struct perf_tool *tool, 3639int perf_event__synthesize_attrs(struct perf_tool *tool,
3640 struct perf_session *session, 3640 struct perf_evlist *evlist,
3641 perf_event__handler_t process) 3641 perf_event__handler_t process)
3642{ 3642{
3643 struct perf_evsel *evsel; 3643 struct perf_evsel *evsel;
3644 int err = 0; 3644 int err = 0;
3645 3645
3646 evlist__for_each_entry(session->evlist, evsel) { 3646 evlist__for_each_entry(evlist, evsel) {
3647 err = perf_event__synthesize_attr(tool, &evsel->attr, evsel->ids, 3647 err = perf_event__synthesize_attr(tool, &evsel->attr, evsel->ids,
3648 evsel->id, process); 3648 evsel->id, process);
3649 if (err) { 3649 if (err) {
@@ -3856,9 +3856,8 @@ int perf_event__synthesize_tracing_data(struct perf_tool *tool, int fd,
3856 return aligned_size; 3856 return aligned_size;
3857} 3857}
3858 3858
3859int perf_event__process_tracing_data(struct perf_tool *tool __maybe_unused, 3859int perf_event__process_tracing_data(struct perf_session *session,
3860 union perf_event *event, 3860 union perf_event *event)
3861 struct perf_session *session)
3862{ 3861{
3863 ssize_t size_read, padding, size = event->tracing_data.size; 3862 ssize_t size_read, padding, size = event->tracing_data.size;
3864 int fd = perf_data__fd(session->data); 3863 int fd = perf_data__fd(session->data);
@@ -3924,9 +3923,8 @@ int perf_event__synthesize_build_id(struct perf_tool *tool,
3924 return err; 3923 return err;
3925} 3924}
3926 3925
3927int perf_event__process_build_id(struct perf_tool *tool __maybe_unused, 3926int perf_event__process_build_id(struct perf_session *session,
3928 union perf_event *event, 3927 union perf_event *event)
3929 struct perf_session *session)
3930{ 3928{
3931 __event_process_build_id(&event->build_id, 3929 __event_process_build_id(&event->build_id,
3932 event->build_id.filename, 3930 event->build_id.filename,
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 6d7fe44aadc0..e17903caa71d 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -116,15 +116,14 @@ int perf_event__synthesize_extra_attr(struct perf_tool *tool,
116 perf_event__handler_t process, 116 perf_event__handler_t process,
117 bool is_pipe); 117 bool is_pipe);
118 118
119int perf_event__process_feature(struct perf_tool *tool, 119int perf_event__process_feature(struct perf_session *session,
120 union perf_event *event, 120 union perf_event *event);
121 struct perf_session *session);
122 121
123int perf_event__synthesize_attr(struct perf_tool *tool, 122int perf_event__synthesize_attr(struct perf_tool *tool,
124 struct perf_event_attr *attr, u32 ids, u64 *id, 123 struct perf_event_attr *attr, u32 ids, u64 *id,
125 perf_event__handler_t process); 124 perf_event__handler_t process);
126int perf_event__synthesize_attrs(struct perf_tool *tool, 125int perf_event__synthesize_attrs(struct perf_tool *tool,
127 struct perf_session *session, 126 struct perf_evlist *evlist,
128 perf_event__handler_t process); 127 perf_event__handler_t process);
129int perf_event__synthesize_event_update_unit(struct perf_tool *tool, 128int perf_event__synthesize_event_update_unit(struct perf_tool *tool,
130 struct perf_evsel *evsel, 129 struct perf_evsel *evsel,
@@ -148,17 +147,15 @@ size_t perf_event__fprintf_event_update(union perf_event *event, FILE *fp);
148int perf_event__synthesize_tracing_data(struct perf_tool *tool, 147int perf_event__synthesize_tracing_data(struct perf_tool *tool,
149 int fd, struct perf_evlist *evlist, 148 int fd, struct perf_evlist *evlist,
150 perf_event__handler_t process); 149 perf_event__handler_t process);
151int perf_event__process_tracing_data(struct perf_tool *tool, 150int perf_event__process_tracing_data(struct perf_session *session,
152 union perf_event *event, 151 union perf_event *event);
153 struct perf_session *session);
154 152
155int perf_event__synthesize_build_id(struct perf_tool *tool, 153int perf_event__synthesize_build_id(struct perf_tool *tool,
156 struct dso *pos, u16 misc, 154 struct dso *pos, u16 misc,
157 perf_event__handler_t process, 155 perf_event__handler_t process,
158 struct machine *machine); 156 struct machine *machine);
159int perf_event__process_build_id(struct perf_tool *tool, 157int perf_event__process_build_id(struct perf_session *session,
160 union perf_event *event, 158 union perf_event *event);
161 struct perf_session *session);
162bool is_perf_magic(u64 magic); 159bool is_perf_magic(u64 magic);
163 160
164#define NAME_ALIGN 64 161#define NAME_ALIGN 64
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
index d404bed7003a..58f6a9ceb590 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
@@ -1165,7 +1165,7 @@ static int intel_pt_walk_tip(struct intel_pt_decoder *decoder)
1165 decoder->pge = false; 1165 decoder->pge = false;
1166 decoder->continuous_period = false; 1166 decoder->continuous_period = false;
1167 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; 1167 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
1168 decoder->state.to_ip = 0; 1168 decoder->state.type |= INTEL_PT_TRACE_END;
1169 return 0; 1169 return 0;
1170 } 1170 }
1171 if (err == INTEL_PT_RETURN) 1171 if (err == INTEL_PT_RETURN)
@@ -1179,9 +1179,13 @@ static int intel_pt_walk_tip(struct intel_pt_decoder *decoder)
1179 decoder->continuous_period = false; 1179 decoder->continuous_period = false;
1180 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; 1180 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
1181 decoder->state.from_ip = decoder->ip; 1181 decoder->state.from_ip = decoder->ip;
1182 decoder->state.to_ip = 0; 1182 if (decoder->packet.count == 0) {
1183 if (decoder->packet.count != 0) 1183 decoder->state.to_ip = 0;
1184 } else {
1185 decoder->state.to_ip = decoder->last_ip;
1184 decoder->ip = decoder->last_ip; 1186 decoder->ip = decoder->last_ip;
1187 }
1188 decoder->state.type |= INTEL_PT_TRACE_END;
1185 } else { 1189 } else {
1186 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; 1190 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
1187 decoder->state.from_ip = decoder->ip; 1191 decoder->state.from_ip = decoder->ip;
@@ -1208,7 +1212,8 @@ static int intel_pt_walk_tip(struct intel_pt_decoder *decoder)
1208 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC; 1212 decoder->pkt_state = INTEL_PT_STATE_IN_SYNC;
1209 decoder->ip = to_ip; 1213 decoder->ip = to_ip;
1210 decoder->state.from_ip = decoder->ip; 1214 decoder->state.from_ip = decoder->ip;
1211 decoder->state.to_ip = 0; 1215 decoder->state.to_ip = to_ip;
1216 decoder->state.type |= INTEL_PT_TRACE_END;
1212 return 0; 1217 return 0;
1213 } 1218 }
1214 intel_pt_log_at("ERROR: Conditional branch when expecting indirect branch", 1219 intel_pt_log_at("ERROR: Conditional branch when expecting indirect branch",
@@ -1640,14 +1645,15 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
1640 1645
1641 case INTEL_PT_TIP_PGD: 1646 case INTEL_PT_TIP_PGD:
1642 decoder->state.from_ip = decoder->ip; 1647 decoder->state.from_ip = decoder->ip;
1643 decoder->state.to_ip = 0; 1648 if (decoder->packet.count == 0) {
1644 if (decoder->packet.count != 0) { 1649 decoder->state.to_ip = 0;
1650 } else {
1645 intel_pt_set_ip(decoder); 1651 intel_pt_set_ip(decoder);
1646 intel_pt_log("Omitting PGD ip " x64_fmt "\n", 1652 decoder->state.to_ip = decoder->ip;
1647 decoder->ip);
1648 } 1653 }
1649 decoder->pge = false; 1654 decoder->pge = false;
1650 decoder->continuous_period = false; 1655 decoder->continuous_period = false;
1656 decoder->state.type |= INTEL_PT_TRACE_END;
1651 return 0; 1657 return 0;
1652 1658
1653 case INTEL_PT_TIP_PGE: 1659 case INTEL_PT_TIP_PGE:
@@ -1661,6 +1667,7 @@ static int intel_pt_walk_fup_tip(struct intel_pt_decoder *decoder)
1661 intel_pt_set_ip(decoder); 1667 intel_pt_set_ip(decoder);
1662 decoder->state.to_ip = decoder->ip; 1668 decoder->state.to_ip = decoder->ip;
1663 } 1669 }
1670 decoder->state.type |= INTEL_PT_TRACE_BEGIN;
1664 return 0; 1671 return 0;
1665 1672
1666 case INTEL_PT_TIP: 1673 case INTEL_PT_TIP:
@@ -1739,6 +1746,7 @@ next:
1739 intel_pt_set_ip(decoder); 1746 intel_pt_set_ip(decoder);
1740 decoder->state.from_ip = 0; 1747 decoder->state.from_ip = 0;
1741 decoder->state.to_ip = decoder->ip; 1748 decoder->state.to_ip = decoder->ip;
1749 decoder->state.type |= INTEL_PT_TRACE_BEGIN;
1742 return 0; 1750 return 0;
1743 } 1751 }
1744 1752
@@ -2077,9 +2085,13 @@ static int intel_pt_walk_to_ip(struct intel_pt_decoder *decoder)
2077 decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD; 2085 decoder->pge = decoder->packet.type != INTEL_PT_TIP_PGD;
2078 if (intel_pt_have_ip(decoder)) 2086 if (intel_pt_have_ip(decoder))
2079 intel_pt_set_ip(decoder); 2087 intel_pt_set_ip(decoder);
2080 if (decoder->ip) 2088 if (!decoder->ip)
2081 return 0; 2089 break;
2082 break; 2090 if (decoder->packet.type == INTEL_PT_TIP_PGE)
2091 decoder->state.type |= INTEL_PT_TRACE_BEGIN;
2092 if (decoder->packet.type == INTEL_PT_TIP_PGD)
2093 decoder->state.type |= INTEL_PT_TRACE_END;
2094 return 0;
2083 2095
2084 case INTEL_PT_FUP: 2096 case INTEL_PT_FUP:
2085 if (intel_pt_have_ip(decoder)) 2097 if (intel_pt_have_ip(decoder))
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
index 51c18d67f4ca..ed088d4726ba 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
@@ -37,6 +37,8 @@ enum intel_pt_sample_type {
37 INTEL_PT_EX_STOP = 1 << 6, 37 INTEL_PT_EX_STOP = 1 << 6,
38 INTEL_PT_PWR_EXIT = 1 << 7, 38 INTEL_PT_PWR_EXIT = 1 << 7,
39 INTEL_PT_CBR_CHG = 1 << 8, 39 INTEL_PT_CBR_CHG = 1 << 8,
40 INTEL_PT_TRACE_BEGIN = 1 << 9,
41 INTEL_PT_TRACE_END = 1 << 10,
40}; 42};
41 43
42enum intel_pt_period_type { 44enum intel_pt_period_type {
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index aec68908d604..48c1d415c6b0 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -908,6 +908,11 @@ static void intel_pt_sample_flags(struct intel_pt_queue *ptq)
908 ptq->insn_len = ptq->state->insn_len; 908 ptq->insn_len = ptq->state->insn_len;
909 memcpy(ptq->insn, ptq->state->insn, INTEL_PT_INSN_BUF_SZ); 909 memcpy(ptq->insn, ptq->state->insn, INTEL_PT_INSN_BUF_SZ);
910 } 910 }
911
912 if (ptq->state->type & INTEL_PT_TRACE_BEGIN)
913 ptq->flags |= PERF_IP_FLAG_TRACE_BEGIN;
914 if (ptq->state->type & INTEL_PT_TRACE_END)
915 ptq->flags |= PERF_IP_FLAG_TRACE_END;
911} 916}
912 917
913static int intel_pt_setup_queue(struct intel_pt *pt, 918static int intel_pt_setup_queue(struct intel_pt *pt,
diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 19262f98cd4e..5b0b60f00275 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -19,7 +19,7 @@
19#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \ 19#define CLANG_BPF_CMD_DEFAULT_TEMPLATE \
20 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\ 20 "$CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS "\
21 "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \ 21 "-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE " \
22 "$CLANG_OPTIONS $KERNEL_INC_OPTIONS $PERF_BPF_INC_OPTIONS " \ 22 "$CLANG_OPTIONS $PERF_BPF_INC_OPTIONS $KERNEL_INC_OPTIONS " \
23 "-Wno-unused-value -Wno-pointer-sign " \ 23 "-Wno-unused-value -Wno-pointer-sign " \
24 "-working-directory $WORKING_DIR " \ 24 "-working-directory $WORKING_DIR " \
25 "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE" 25 "-c \"$CLANG_SOURCE\" -target bpf $CLANG_EMIT_LLVM -O2 -o - $LLVM_OPTIONS_PIPE"
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index 6a6929f208b4..354e54550d2b 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -320,12 +320,11 @@ int map__load(struct map *map)
320 build_id__sprintf(map->dso->build_id, 320 build_id__sprintf(map->dso->build_id,
321 sizeof(map->dso->build_id), 321 sizeof(map->dso->build_id),
322 sbuild_id); 322 sbuild_id);
323 pr_warning("%s with build id %s not found", 323 pr_debug("%s with build id %s not found", name, sbuild_id);
324 name, sbuild_id);
325 } else 324 } else
326 pr_warning("Failed to open %s", name); 325 pr_debug("Failed to open %s", name);
327 326
328 pr_warning(", continuing without symbols\n"); 327 pr_debug(", continuing without symbols\n");
329 return -1; 328 return -1;
330 } else if (nr == 0) { 329 } else if (nr == 0) {
331#ifdef HAVE_LIBELF_SUPPORT 330#ifdef HAVE_LIBELF_SUPPORT
@@ -334,12 +333,11 @@ int map__load(struct map *map)
334 333
335 if (len > sizeof(DSO__DELETED) && 334 if (len > sizeof(DSO__DELETED) &&
336 strcmp(name + real_len + 1, DSO__DELETED) == 0) { 335 strcmp(name + real_len + 1, DSO__DELETED) == 0) {
337 pr_warning("%.*s was updated (is prelink enabled?). " 336 pr_debug("%.*s was updated (is prelink enabled?). "
338 "Restart the long running apps that use it!\n", 337 "Restart the long running apps that use it!\n",
339 (int)real_len, name); 338 (int)real_len, name);
340 } else { 339 } else {
341 pr_warning("no symbols found in %s, maybe install " 340 pr_debug("no symbols found in %s, maybe install a debug package?\n", name);
342 "a debug package?\n", name);
343 } 341 }
344#endif 342#endif
345 return -1; 343 return -1;
@@ -712,8 +710,7 @@ static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp
712 if (verbose >= 2) { 710 if (verbose >= 2) {
713 711
714 if (use_browser) { 712 if (use_browser) {
715 pr_warning("overlapping maps in %s " 713 pr_debug("overlapping maps in %s (disable tui for more info)\n",
716 "(disable tui for more info)\n",
717 map->dso->name); 714 map->dso->name);
718 } else { 715 } else {
719 fputs("overlapping maps:\n", fp); 716 fputs("overlapping maps:\n", fp);
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
index 215f69f41672..cdb95b3a1213 100644
--- a/tools/perf/util/mmap.c
+++ b/tools/perf/util/mmap.c
@@ -281,7 +281,7 @@ int perf_mmap__read_init(struct perf_mmap *map)
281} 281}
282 282
283int perf_mmap__push(struct perf_mmap *md, void *to, 283int perf_mmap__push(struct perf_mmap *md, void *to,
284 int push(void *to, void *buf, size_t size)) 284 int push(struct perf_mmap *map, void *to, void *buf, size_t size))
285{ 285{
286 u64 head = perf_mmap__read_head(md); 286 u64 head = perf_mmap__read_head(md);
287 unsigned char *data = md->base + page_size; 287 unsigned char *data = md->base + page_size;
@@ -300,7 +300,7 @@ int perf_mmap__push(struct perf_mmap *md, void *to,
300 size = md->mask + 1 - (md->start & md->mask); 300 size = md->mask + 1 - (md->start & md->mask);
301 md->start += size; 301 md->start += size;
302 302
303 if (push(to, buf, size) < 0) { 303 if (push(md, to, buf, size) < 0) {
304 rc = -1; 304 rc = -1;
305 goto out; 305 goto out;
306 } 306 }
@@ -310,7 +310,7 @@ int perf_mmap__push(struct perf_mmap *md, void *to,
310 size = md->end - md->start; 310 size = md->end - md->start;
311 md->start += size; 311 md->start += size;
312 312
313 if (push(to, buf, size) < 0) { 313 if (push(md, to, buf, size) < 0) {
314 rc = -1; 314 rc = -1;
315 goto out; 315 goto out;
316 } 316 }
diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
index 05a6d47c7956..e603314dc792 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -93,7 +93,7 @@ union perf_event *perf_mmap__read_forward(struct perf_mmap *map);
93union perf_event *perf_mmap__read_event(struct perf_mmap *map); 93union perf_event *perf_mmap__read_event(struct perf_mmap *map);
94 94
95int perf_mmap__push(struct perf_mmap *md, void *to, 95int perf_mmap__push(struct perf_mmap *md, void *to,
96 int push(void *to, void *buf, size_t size)); 96 int push(struct perf_mmap *map, void *to, void *buf, size_t size));
97 97
98size_t perf_mmap__mmap_len(struct perf_mmap *map); 98size_t perf_mmap__mmap_len(struct perf_mmap *map);
99 99
diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
index bad9e0296e9a..1904e7f6ec84 100644
--- a/tools/perf/util/ordered-events.c
+++ b/tools/perf/util/ordered-events.c
@@ -80,14 +80,20 @@ static union perf_event *dup_event(struct ordered_events *oe,
80 return oe->copy_on_queue ? __dup_event(oe, event) : event; 80 return oe->copy_on_queue ? __dup_event(oe, event) : event;
81} 81}
82 82
83static void free_dup_event(struct ordered_events *oe, union perf_event *event) 83static void __free_dup_event(struct ordered_events *oe, union perf_event *event)
84{ 84{
85 if (event && oe->copy_on_queue) { 85 if (event) {
86 oe->cur_alloc_size -= event->header.size; 86 oe->cur_alloc_size -= event->header.size;
87 free(event); 87 free(event);
88 } 88 }
89} 89}
90 90
91static void free_dup_event(struct ordered_events *oe, union perf_event *event)
92{
93 if (oe->copy_on_queue)
94 __free_dup_event(oe, event);
95}
96
91#define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct ordered_event)) 97#define MAX_SAMPLE_BUFFER (64 * 1024 / sizeof(struct ordered_event))
92static struct ordered_event *alloc_event(struct ordered_events *oe, 98static struct ordered_event *alloc_event(struct ordered_events *oe,
93 union perf_event *event) 99 union perf_event *event)
@@ -95,21 +101,49 @@ static struct ordered_event *alloc_event(struct ordered_events *oe,
95 struct list_head *cache = &oe->cache; 101 struct list_head *cache = &oe->cache;
96 struct ordered_event *new = NULL; 102 struct ordered_event *new = NULL;
97 union perf_event *new_event; 103 union perf_event *new_event;
104 size_t size;
98 105
99 new_event = dup_event(oe, event); 106 new_event = dup_event(oe, event);
100 if (!new_event) 107 if (!new_event)
101 return NULL; 108 return NULL;
102 109
110 /*
111 * We maintain the following scheme of buffers for ordered
112 * event allocation:
113 *
114 * to_free list -> buffer1 (64K)
115 * buffer2 (64K)
116 * ...
117 *
118 * Each buffer keeps an array of ordered events objects:
119 * buffer -> event[0]
120 * event[1]
121 * ...
122 *
123 * Each allocated ordered event is linked to one of
124 * following lists:
125 * - time ordered list 'events'
126 * - list of currently removed events 'cache'
127 *
128 * Allocation of the ordered event uses the following order
129 * to get the memory:
130 * - use recently removed object from 'cache' list
131 * - use available object in current allocation buffer
132 * - allocate new buffer if the current buffer is full
133 *
134 * Removal of ordered event object moves it from events to
135 * the cache list.
136 */
137 size = sizeof(*oe->buffer) + MAX_SAMPLE_BUFFER * sizeof(*new);
138
103 if (!list_empty(cache)) { 139 if (!list_empty(cache)) {
104 new = list_entry(cache->next, struct ordered_event, list); 140 new = list_entry(cache->next, struct ordered_event, list);
105 list_del(&new->list); 141 list_del(&new->list);
106 } else if (oe->buffer) { 142 } else if (oe->buffer) {
107 new = oe->buffer + oe->buffer_idx; 143 new = &oe->buffer->event[oe->buffer_idx];
108 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER) 144 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER)
109 oe->buffer = NULL; 145 oe->buffer = NULL;
110 } else if (oe->cur_alloc_size < oe->max_alloc_size) { 146 } else if ((oe->cur_alloc_size + size) < oe->max_alloc_size) {
111 size_t size = MAX_SAMPLE_BUFFER * sizeof(*new);
112
113 oe->buffer = malloc(size); 147 oe->buffer = malloc(size);
114 if (!oe->buffer) { 148 if (!oe->buffer) {
115 free_dup_event(oe, new_event); 149 free_dup_event(oe, new_event);
@@ -122,11 +156,11 @@ static struct ordered_event *alloc_event(struct ordered_events *oe,
122 oe->cur_alloc_size += size; 156 oe->cur_alloc_size += size;
123 list_add(&oe->buffer->list, &oe->to_free); 157 list_add(&oe->buffer->list, &oe->to_free);
124 158
125 /* First entry is abused to maintain the to_free list. */ 159 oe->buffer_idx = 1;
126 oe->buffer_idx = 2; 160 new = &oe->buffer->event[0];
127 new = oe->buffer + 1;
128 } else { 161 } else {
129 pr("allocation limit reached %" PRIu64 "B\n", oe->max_alloc_size); 162 pr("allocation limit reached %" PRIu64 "B\n", oe->max_alloc_size);
163 return NULL;
130 } 164 }
131 165
132 new->event = new_event; 166 new->event = new_event;
@@ -300,15 +334,38 @@ void ordered_events__init(struct ordered_events *oe, ordered_events__deliver_t d
300 oe->deliver = deliver; 334 oe->deliver = deliver;
301} 335}
302 336
337static void
338ordered_events_buffer__free(struct ordered_events_buffer *buffer,
339 unsigned int max, struct ordered_events *oe)
340{
341 if (oe->copy_on_queue) {
342 unsigned int i;
343
344 for (i = 0; i < max; i++)
345 __free_dup_event(oe, buffer->event[i].event);
346 }
347
348 free(buffer);
349}
350
303void ordered_events__free(struct ordered_events *oe) 351void ordered_events__free(struct ordered_events *oe)
304{ 352{
305 while (!list_empty(&oe->to_free)) { 353 struct ordered_events_buffer *buffer, *tmp;
306 struct ordered_event *event;
307 354
308 event = list_entry(oe->to_free.next, struct ordered_event, list); 355 if (list_empty(&oe->to_free))
309 list_del(&event->list); 356 return;
310 free_dup_event(oe, event->event); 357
311 free(event); 358 /*
359 * Current buffer might not have all the events allocated
360 * yet, we need to free only allocated ones ...
361 */
362 list_del(&oe->buffer->list);
363 ordered_events_buffer__free(oe->buffer, oe->buffer_idx, oe);
364
365 /* ... and continue with the rest */
366 list_for_each_entry_safe(buffer, tmp, &oe->to_free, list) {
367 list_del(&buffer->list);
368 ordered_events_buffer__free(buffer, MAX_SAMPLE_BUFFER, oe);
312 } 369 }
313} 370}
314 371
diff --git a/tools/perf/util/ordered-events.h b/tools/perf/util/ordered-events.h
index 8c7a2948593e..1338d5c345dc 100644
--- a/tools/perf/util/ordered-events.h
+++ b/tools/perf/util/ordered-events.h
@@ -25,23 +25,28 @@ struct ordered_events;
25typedef int (*ordered_events__deliver_t)(struct ordered_events *oe, 25typedef int (*ordered_events__deliver_t)(struct ordered_events *oe,
26 struct ordered_event *event); 26 struct ordered_event *event);
27 27
28struct ordered_events_buffer {
29 struct list_head list;
30 struct ordered_event event[0];
31};
32
28struct ordered_events { 33struct ordered_events {
29 u64 last_flush; 34 u64 last_flush;
30 u64 next_flush; 35 u64 next_flush;
31 u64 max_timestamp; 36 u64 max_timestamp;
32 u64 max_alloc_size; 37 u64 max_alloc_size;
33 u64 cur_alloc_size; 38 u64 cur_alloc_size;
34 struct list_head events; 39 struct list_head events;
35 struct list_head cache; 40 struct list_head cache;
36 struct list_head to_free; 41 struct list_head to_free;
37 struct ordered_event *buffer; 42 struct ordered_events_buffer *buffer;
38 struct ordered_event *last; 43 struct ordered_event *last;
39 ordered_events__deliver_t deliver; 44 ordered_events__deliver_t deliver;
40 int buffer_idx; 45 int buffer_idx;
41 unsigned int nr_events; 46 unsigned int nr_events;
42 enum oe_flush last_flush_type; 47 enum oe_flush last_flush_type;
43 u32 nr_unordered_events; 48 u32 nr_unordered_events;
44 bool copy_on_queue; 49 bool copy_on_queue;
45}; 50};
46 51
47int ordered_events__queue(struct ordered_events *oe, union perf_event *event, 52int ordered_events__queue(struct ordered_events *oe, union perf_event *event,
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index ce501ba14b08..50150dfc0cdf 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -340,7 +340,7 @@ static bool is_tracepoint(struct pyrf_event *pevent)
340} 340}
341 341
342static PyObject* 342static PyObject*
343tracepoint_field(struct pyrf_event *pe, struct format_field *field) 343tracepoint_field(struct pyrf_event *pe, struct tep_format_field *field)
344{ 344{
345 struct tep_handle *pevent = field->event->pevent; 345 struct tep_handle *pevent = field->event->pevent;
346 void *data = pe->sample.raw_data; 346 void *data = pe->sample.raw_data;
@@ -348,28 +348,28 @@ tracepoint_field(struct pyrf_event *pe, struct format_field *field)
348 unsigned long long val; 348 unsigned long long val;
349 unsigned int offset, len; 349 unsigned int offset, len;
350 350
351 if (field->flags & FIELD_IS_ARRAY) { 351 if (field->flags & TEP_FIELD_IS_ARRAY) {
352 offset = field->offset; 352 offset = field->offset;
353 len = field->size; 353 len = field->size;
354 if (field->flags & FIELD_IS_DYNAMIC) { 354 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
355 val = tep_read_number(pevent, data + offset, len); 355 val = tep_read_number(pevent, data + offset, len);
356 offset = val; 356 offset = val;
357 len = offset >> 16; 357 len = offset >> 16;
358 offset &= 0xffff; 358 offset &= 0xffff;
359 } 359 }
360 if (field->flags & FIELD_IS_STRING && 360 if (field->flags & TEP_FIELD_IS_STRING &&
361 is_printable_array(data + offset, len)) { 361 is_printable_array(data + offset, len)) {
362 ret = _PyUnicode_FromString((char *)data + offset); 362 ret = _PyUnicode_FromString((char *)data + offset);
363 } else { 363 } else {
364 ret = PyByteArray_FromStringAndSize((const char *) data + offset, len); 364 ret = PyByteArray_FromStringAndSize((const char *) data + offset, len);
365 field->flags &= ~FIELD_IS_STRING; 365 field->flags &= ~TEP_FIELD_IS_STRING;
366 } 366 }
367 } else { 367 } else {
368 val = tep_read_number(pevent, data + field->offset, 368 val = tep_read_number(pevent, data + field->offset,
369 field->size); 369 field->size);
370 if (field->flags & FIELD_IS_POINTER) 370 if (field->flags & TEP_FIELD_IS_POINTER)
371 ret = PyLong_FromUnsignedLong((unsigned long) val); 371 ret = PyLong_FromUnsignedLong((unsigned long) val);
372 else if (field->flags & FIELD_IS_SIGNED) 372 else if (field->flags & TEP_FIELD_IS_SIGNED)
373 ret = PyLong_FromLong((long) val); 373 ret = PyLong_FromLong((long) val);
374 else 374 else
375 ret = PyLong_FromUnsignedLong((unsigned long) val); 375 ret = PyLong_FromUnsignedLong((unsigned long) val);
@@ -383,10 +383,10 @@ get_tracepoint_field(struct pyrf_event *pevent, PyObject *attr_name)
383{ 383{
384 const char *str = _PyUnicode_AsString(PyObject_Str(attr_name)); 384 const char *str = _PyUnicode_AsString(PyObject_Str(attr_name));
385 struct perf_evsel *evsel = pevent->evsel; 385 struct perf_evsel *evsel = pevent->evsel;
386 struct format_field *field; 386 struct tep_format_field *field;
387 387
388 if (!evsel->tp_format) { 388 if (!evsel->tp_format) {
389 struct event_format *tp_format; 389 struct tep_event_format *tp_format;
390 390
391 tp_format = trace_event__tp_format_id(evsel->attr.config); 391 tp_format = trace_event__tp_format_id(evsel->attr.config);
392 if (!tp_format) 392 if (!tp_format)
@@ -1240,7 +1240,7 @@ static struct {
1240static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel, 1240static PyObject *pyrf__tracepoint(struct pyrf_evsel *pevsel,
1241 PyObject *args, PyObject *kwargs) 1241 PyObject *args, PyObject *kwargs)
1242{ 1242{
1243 struct event_format *tp_format; 1243 struct tep_event_format *tp_format;
1244 static char *kwlist[] = { "sys", "name", NULL }; 1244 static char *kwlist[] = { "sys", "name", NULL };
1245 char *sys = NULL; 1245 char *sys = NULL;
1246 char *name = NULL; 1246 char *name = NULL;
diff --git a/tools/perf/util/s390-cpumsf.c b/tools/perf/util/s390-cpumsf.c
index d2c78ffd9fee..a2eeebbfb25f 100644
--- a/tools/perf/util/s390-cpumsf.c
+++ b/tools/perf/util/s390-cpumsf.c
@@ -147,6 +147,9 @@
147#include <linux/bitops.h> 147#include <linux/bitops.h>
148#include <linux/log2.h> 148#include <linux/log2.h>
149 149
150#include <sys/stat.h>
151#include <sys/types.h>
152
150#include "cpumap.h" 153#include "cpumap.h"
151#include "color.h" 154#include "color.h"
152#include "evsel.h" 155#include "evsel.h"
@@ -159,6 +162,7 @@
159#include "auxtrace.h" 162#include "auxtrace.h"
160#include "s390-cpumsf.h" 163#include "s390-cpumsf.h"
161#include "s390-cpumsf-kernel.h" 164#include "s390-cpumsf-kernel.h"
165#include "config.h"
162 166
163struct s390_cpumsf { 167struct s390_cpumsf {
164 struct auxtrace auxtrace; 168 struct auxtrace auxtrace;
@@ -170,6 +174,8 @@ struct s390_cpumsf {
170 u32 pmu_type; 174 u32 pmu_type;
171 u16 machine_type; 175 u16 machine_type;
172 bool data_queued; 176 bool data_queued;
177 bool use_logfile;
178 char *logdir;
173}; 179};
174 180
175struct s390_cpumsf_queue { 181struct s390_cpumsf_queue {
@@ -177,6 +183,7 @@ struct s390_cpumsf_queue {
177 unsigned int queue_nr; 183 unsigned int queue_nr;
178 struct auxtrace_buffer *buffer; 184 struct auxtrace_buffer *buffer;
179 int cpu; 185 int cpu;
186 FILE *logfile;
180}; 187};
181 188
182/* Display s390 CPU measurement facility basic-sampling data entry */ 189/* Display s390 CPU measurement facility basic-sampling data entry */
@@ -595,6 +602,12 @@ static int s390_cpumsf_run_decoder(struct s390_cpumsf_queue *sfq,
595 buffer->use_size = buffer->size; 602 buffer->use_size = buffer->size;
596 buffer->use_data = buffer->data; 603 buffer->use_data = buffer->data;
597 } 604 }
605 if (sfq->logfile) { /* Write into log file */
606 size_t rc = fwrite(buffer->data, buffer->size, 1,
607 sfq->logfile);
608 if (rc != 1)
609 pr_err("Failed to write auxiliary data\n");
610 }
598 } else 611 } else
599 buffer = sfq->buffer; 612 buffer = sfq->buffer;
600 613
@@ -606,6 +619,13 @@ static int s390_cpumsf_run_decoder(struct s390_cpumsf_queue *sfq,
606 return -ENOMEM; 619 return -ENOMEM;
607 buffer->use_size = buffer->size; 620 buffer->use_size = buffer->size;
608 buffer->use_data = buffer->data; 621 buffer->use_data = buffer->data;
622
623 if (sfq->logfile) { /* Write into log file */
624 size_t rc = fwrite(buffer->data, buffer->size, 1,
625 sfq->logfile);
626 if (rc != 1)
627 pr_err("Failed to write auxiliary data\n");
628 }
609 } 629 }
610 pr_debug4("%s queue_nr:%d buffer:%" PRId64 " offset:%#" PRIx64 " size:%#zx rest:%#zx\n", 630 pr_debug4("%s queue_nr:%d buffer:%" PRId64 " offset:%#" PRIx64 " size:%#zx rest:%#zx\n",
611 __func__, sfq->queue_nr, buffer->buffer_nr, buffer->offset, 631 __func__, sfq->queue_nr, buffer->buffer_nr, buffer->offset,
@@ -640,6 +660,23 @@ s390_cpumsf_alloc_queue(struct s390_cpumsf *sf, unsigned int queue_nr)
640 sfq->sf = sf; 660 sfq->sf = sf;
641 sfq->queue_nr = queue_nr; 661 sfq->queue_nr = queue_nr;
642 sfq->cpu = -1; 662 sfq->cpu = -1;
663 if (sf->use_logfile) {
664 char *name;
665 int rc;
666
667 rc = (sf->logdir)
668 ? asprintf(&name, "%s/aux.smp.%02x",
669 sf->logdir, queue_nr)
670 : asprintf(&name, "aux.smp.%02x", queue_nr);
671 if (rc > 0)
672 sfq->logfile = fopen(name, "w");
673 if (sfq->logfile == NULL) {
674 pr_err("Failed to open auxiliary log file %s,"
675 "continue...\n", name);
676 sf->use_logfile = false;
677 }
678 free(name);
679 }
643 return sfq; 680 return sfq;
644} 681}
645 682
@@ -850,8 +887,16 @@ static void s390_cpumsf_free_queues(struct perf_session *session)
850 struct auxtrace_queues *queues = &sf->queues; 887 struct auxtrace_queues *queues = &sf->queues;
851 unsigned int i; 888 unsigned int i;
852 889
853 for (i = 0; i < queues->nr_queues; i++) 890 for (i = 0; i < queues->nr_queues; i++) {
891 struct s390_cpumsf_queue *sfq = (struct s390_cpumsf_queue *)
892 queues->queue_array[i].priv;
893
894 if (sfq != NULL && sfq->logfile) {
895 fclose(sfq->logfile);
896 sfq->logfile = NULL;
897 }
854 zfree(&queues->queue_array[i].priv); 898 zfree(&queues->queue_array[i].priv);
899 }
855 auxtrace_queues__free(queues); 900 auxtrace_queues__free(queues);
856} 901}
857 902
@@ -864,6 +909,7 @@ static void s390_cpumsf_free(struct perf_session *session)
864 auxtrace_heap__free(&sf->heap); 909 auxtrace_heap__free(&sf->heap);
865 s390_cpumsf_free_queues(session); 910 s390_cpumsf_free_queues(session);
866 session->auxtrace = NULL; 911 session->auxtrace = NULL;
912 free(sf->logdir);
867 free(sf); 913 free(sf);
868} 914}
869 915
@@ -877,17 +923,55 @@ static int s390_cpumsf_get_type(const char *cpuid)
877 923
878/* Check itrace options set on perf report command. 924/* Check itrace options set on perf report command.
879 * Return true, if none are set or all options specified can be 925 * Return true, if none are set or all options specified can be
880 * handled on s390. 926 * handled on s390 (currently only option 'd' for logging.
881 * Return false otherwise. 927 * Return false otherwise.
882 */ 928 */
883static bool check_auxtrace_itrace(struct itrace_synth_opts *itops) 929static bool check_auxtrace_itrace(struct itrace_synth_opts *itops)
884{ 930{
931 bool ison = false;
932
885 if (!itops || !itops->set) 933 if (!itops || !itops->set)
886 return true; 934 return true;
887 pr_err("No --itrace options supported\n"); 935 ison = itops->inject || itops->instructions || itops->branches ||
936 itops->transactions || itops->ptwrites ||
937 itops->pwr_events || itops->errors ||
938 itops->dont_decode || itops->calls || itops->returns ||
939 itops->callchain || itops->thread_stack ||
940 itops->last_branch;
941 if (!ison)
942 return true;
943 pr_err("Unsupported --itrace options specified\n");
888 return false; 944 return false;
889} 945}
890 946
947/* Check for AUXTRACE dump directory if it is needed.
948 * On failure print an error message but continue.
949 * Return 0 on wrong keyword in config file and 1 otherwise.
950 */
951static int s390_cpumsf__config(const char *var, const char *value, void *cb)
952{
953 struct s390_cpumsf *sf = cb;
954 struct stat stbuf;
955 int rc;
956
957 if (strcmp(var, "auxtrace.dumpdir"))
958 return 0;
959 sf->logdir = strdup(value);
960 if (sf->logdir == NULL) {
961 pr_err("Failed to find auxtrace log directory %s,"
962 " continue with current directory...\n", value);
963 return 1;
964 }
965 rc = stat(sf->logdir, &stbuf);
966 if (rc == -1 || !S_ISDIR(stbuf.st_mode)) {
967 pr_err("Missing auxtrace log directory %s,"
968 " continue with current directory...\n", value);
969 free(sf->logdir);
970 sf->logdir = NULL;
971 }
972 return 1;
973}
974
891int s390_cpumsf_process_auxtrace_info(union perf_event *event, 975int s390_cpumsf_process_auxtrace_info(union perf_event *event,
892 struct perf_session *session) 976 struct perf_session *session)
893{ 977{
@@ -906,6 +990,9 @@ int s390_cpumsf_process_auxtrace_info(union perf_event *event,
906 err = -EINVAL; 990 err = -EINVAL;
907 goto err_free; 991 goto err_free;
908 } 992 }
993 sf->use_logfile = session->itrace_synth_opts->log;
994 if (sf->use_logfile)
995 perf_config(s390_cpumsf__config, sf);
909 996
910 err = auxtrace_queues__init(&sf->queues); 997 err = auxtrace_queues__init(&sf->queues);
911 if (err) 998 if (err)
@@ -940,6 +1027,7 @@ err_free_queues:
940 auxtrace_queues__free(&sf->queues); 1027 auxtrace_queues__free(&sf->queues);
941 session->auxtrace = NULL; 1028 session->auxtrace = NULL;
942err_free: 1029err_free:
1030 free(sf->logdir);
943 free(sf); 1031 free(sf);
944 return err; 1032 return err;
945} 1033}
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index 45484f0f7292..89cb887648f9 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -99,7 +99,7 @@ static void define_symbolic_value(const char *ev_name,
99 LEAVE; 99 LEAVE;
100} 100}
101 101
102static void define_symbolic_values(struct print_flag_sym *field, 102static void define_symbolic_values(struct tep_print_flag_sym *field,
103 const char *ev_name, 103 const char *ev_name,
104 const char *field_name) 104 const char *field_name)
105{ 105{
@@ -157,7 +157,7 @@ static void define_flag_value(const char *ev_name,
157 LEAVE; 157 LEAVE;
158} 158}
159 159
160static void define_flag_values(struct print_flag_sym *field, 160static void define_flag_values(struct tep_print_flag_sym *field,
161 const char *ev_name, 161 const char *ev_name,
162 const char *field_name) 162 const char *field_name)
163{ 163{
@@ -189,62 +189,62 @@ static void define_flag_field(const char *ev_name,
189 LEAVE; 189 LEAVE;
190} 190}
191 191
192static void define_event_symbols(struct event_format *event, 192static void define_event_symbols(struct tep_event_format *event,
193 const char *ev_name, 193 const char *ev_name,
194 struct print_arg *args) 194 struct tep_print_arg *args)
195{ 195{
196 if (args == NULL) 196 if (args == NULL)
197 return; 197 return;
198 198
199 switch (args->type) { 199 switch (args->type) {
200 case PRINT_NULL: 200 case TEP_PRINT_NULL:
201 break; 201 break;
202 case PRINT_ATOM: 202 case TEP_PRINT_ATOM:
203 define_flag_value(ev_name, cur_field_name, "0", 203 define_flag_value(ev_name, cur_field_name, "0",
204 args->atom.atom); 204 args->atom.atom);
205 zero_flag_atom = 0; 205 zero_flag_atom = 0;
206 break; 206 break;
207 case PRINT_FIELD: 207 case TEP_PRINT_FIELD:
208 free(cur_field_name); 208 free(cur_field_name);
209 cur_field_name = strdup(args->field.name); 209 cur_field_name = strdup(args->field.name);
210 break; 210 break;
211 case PRINT_FLAGS: 211 case TEP_PRINT_FLAGS:
212 define_event_symbols(event, ev_name, args->flags.field); 212 define_event_symbols(event, ev_name, args->flags.field);
213 define_flag_field(ev_name, cur_field_name, args->flags.delim); 213 define_flag_field(ev_name, cur_field_name, args->flags.delim);
214 define_flag_values(args->flags.flags, ev_name, cur_field_name); 214 define_flag_values(args->flags.flags, ev_name, cur_field_name);
215 break; 215 break;
216 case PRINT_SYMBOL: 216 case TEP_PRINT_SYMBOL:
217 define_event_symbols(event, ev_name, args->symbol.field); 217 define_event_symbols(event, ev_name, args->symbol.field);
218 define_symbolic_field(ev_name, cur_field_name); 218 define_symbolic_field(ev_name, cur_field_name);
219 define_symbolic_values(args->symbol.symbols, ev_name, 219 define_symbolic_values(args->symbol.symbols, ev_name,
220 cur_field_name); 220 cur_field_name);
221 break; 221 break;
222 case PRINT_HEX: 222 case TEP_PRINT_HEX:
223 case PRINT_HEX_STR: 223 case TEP_PRINT_HEX_STR:
224 define_event_symbols(event, ev_name, args->hex.field); 224 define_event_symbols(event, ev_name, args->hex.field);
225 define_event_symbols(event, ev_name, args->hex.size); 225 define_event_symbols(event, ev_name, args->hex.size);
226 break; 226 break;
227 case PRINT_INT_ARRAY: 227 case TEP_PRINT_INT_ARRAY:
228 define_event_symbols(event, ev_name, args->int_array.field); 228 define_event_symbols(event, ev_name, args->int_array.field);
229 define_event_symbols(event, ev_name, args->int_array.count); 229 define_event_symbols(event, ev_name, args->int_array.count);
230 define_event_symbols(event, ev_name, args->int_array.el_size); 230 define_event_symbols(event, ev_name, args->int_array.el_size);
231 break; 231 break;
232 case PRINT_BSTRING: 232 case TEP_PRINT_BSTRING:
233 case PRINT_DYNAMIC_ARRAY: 233 case TEP_PRINT_DYNAMIC_ARRAY:
234 case PRINT_DYNAMIC_ARRAY_LEN: 234 case TEP_PRINT_DYNAMIC_ARRAY_LEN:
235 case PRINT_STRING: 235 case TEP_PRINT_STRING:
236 case PRINT_BITMASK: 236 case TEP_PRINT_BITMASK:
237 break; 237 break;
238 case PRINT_TYPE: 238 case TEP_PRINT_TYPE:
239 define_event_symbols(event, ev_name, args->typecast.item); 239 define_event_symbols(event, ev_name, args->typecast.item);
240 break; 240 break;
241 case PRINT_OP: 241 case TEP_PRINT_OP:
242 if (strcmp(args->op.op, ":") == 0) 242 if (strcmp(args->op.op, ":") == 0)
243 zero_flag_atom = 1; 243 zero_flag_atom = 1;
244 define_event_symbols(event, ev_name, args->op.left); 244 define_event_symbols(event, ev_name, args->op.left);
245 define_event_symbols(event, ev_name, args->op.right); 245 define_event_symbols(event, ev_name, args->op.right);
246 break; 246 break;
247 case PRINT_FUNC: 247 case TEP_PRINT_FUNC:
248 default: 248 default:
249 pr_err("Unsupported print arg type\n"); 249 pr_err("Unsupported print arg type\n");
250 /* we should warn... */ 250 /* we should warn... */
@@ -338,8 +338,8 @@ static void perl_process_tracepoint(struct perf_sample *sample,
338 struct addr_location *al) 338 struct addr_location *al)
339{ 339{
340 struct thread *thread = al->thread; 340 struct thread *thread = al->thread;
341 struct event_format *event = evsel->tp_format; 341 struct tep_event_format *event = evsel->tp_format;
342 struct format_field *field; 342 struct tep_format_field *field;
343 static char handler[256]; 343 static char handler[256];
344 unsigned long long val; 344 unsigned long long val;
345 unsigned long s, ns; 345 unsigned long s, ns;
@@ -388,9 +388,9 @@ static void perl_process_tracepoint(struct perf_sample *sample,
388 /* common fields other than pid can be accessed via xsub fns */ 388 /* common fields other than pid can be accessed via xsub fns */
389 389
390 for (field = event->format.fields; field; field = field->next) { 390 for (field = event->format.fields; field; field = field->next) {
391 if (field->flags & FIELD_IS_STRING) { 391 if (field->flags & TEP_FIELD_IS_STRING) {
392 int offset; 392 int offset;
393 if (field->flags & FIELD_IS_DYNAMIC) { 393 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
394 offset = *(int *)(data + field->offset); 394 offset = *(int *)(data + field->offset);
395 offset &= 0xffff; 395 offset &= 0xffff;
396 } else 396 } else
@@ -399,7 +399,7 @@ static void perl_process_tracepoint(struct perf_sample *sample,
399 } else { /* FIELD_IS_NUMERIC */ 399 } else { /* FIELD_IS_NUMERIC */
400 val = read_size(event, data + field->offset, 400 val = read_size(event, data + field->offset,
401 field->size); 401 field->size);
402 if (field->flags & FIELD_IS_SIGNED) { 402 if (field->flags & TEP_FIELD_IS_SIGNED) {
403 XPUSHs(sv_2mortal(newSViv(val))); 403 XPUSHs(sv_2mortal(newSViv(val)));
404 } else { 404 } else {
405 XPUSHs(sv_2mortal(newSVuv(val))); 405 XPUSHs(sv_2mortal(newSVuv(val)));
@@ -537,8 +537,8 @@ static int perl_stop_script(void)
537 537
538static int perl_generate_script(struct tep_handle *pevent, const char *outfile) 538static int perl_generate_script(struct tep_handle *pevent, const char *outfile)
539{ 539{
540 struct event_format *event = NULL; 540 struct tep_event_format *event = NULL;
541 struct format_field *f; 541 struct tep_format_field *f;
542 char fname[PATH_MAX]; 542 char fname[PATH_MAX];
543 int not_first, count; 543 int not_first, count;
544 FILE *ofp; 544 FILE *ofp;
@@ -646,11 +646,11 @@ sub print_backtrace\n\
646 count++; 646 count++;
647 647
648 fprintf(ofp, "%s=", f->name); 648 fprintf(ofp, "%s=", f->name);
649 if (f->flags & FIELD_IS_STRING || 649 if (f->flags & TEP_FIELD_IS_STRING ||
650 f->flags & FIELD_IS_FLAG || 650 f->flags & TEP_FIELD_IS_FLAG ||
651 f->flags & FIELD_IS_SYMBOLIC) 651 f->flags & TEP_FIELD_IS_SYMBOLIC)
652 fprintf(ofp, "%%s"); 652 fprintf(ofp, "%%s");
653 else if (f->flags & FIELD_IS_SIGNED) 653 else if (f->flags & TEP_FIELD_IS_SIGNED)
654 fprintf(ofp, "%%d"); 654 fprintf(ofp, "%%d");
655 else 655 else
656 fprintf(ofp, "%%u"); 656 fprintf(ofp, "%%u");
@@ -668,7 +668,7 @@ sub print_backtrace\n\
668 if (++count % 5 == 0) 668 if (++count % 5 == 0)
669 fprintf(ofp, "\n\t "); 669 fprintf(ofp, "\n\t ");
670 670
671 if (f->flags & FIELD_IS_FLAG) { 671 if (f->flags & TEP_FIELD_IS_FLAG) {
672 if ((count - 1) % 5 != 0) { 672 if ((count - 1) % 5 != 0) {
673 fprintf(ofp, "\n\t "); 673 fprintf(ofp, "\n\t ");
674 count = 4; 674 count = 4;
@@ -678,7 +678,7 @@ sub print_backtrace\n\
678 event->name); 678 event->name);
679 fprintf(ofp, "\"%s\", $%s)", f->name, 679 fprintf(ofp, "\"%s\", $%s)", f->name,
680 f->name); 680 f->name);
681 } else if (f->flags & FIELD_IS_SYMBOLIC) { 681 } else if (f->flags & TEP_FIELD_IS_SYMBOLIC) {
682 if ((count - 1) % 5 != 0) { 682 if ((count - 1) % 5 != 0) {
683 fprintf(ofp, "\n\t "); 683 fprintf(ofp, "\n\t ");
684 count = 4; 684 count = 4;
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index dfc6093f118c..69aa93d4ee99 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -193,7 +193,7 @@ static void try_call_object(const char *handler_name, PyObject *args)
193 call_object(handler, args, handler_name); 193 call_object(handler, args, handler_name);
194} 194}
195 195
196static void define_value(enum print_arg_type field_type, 196static void define_value(enum tep_print_arg_type field_type,
197 const char *ev_name, 197 const char *ev_name,
198 const char *field_name, 198 const char *field_name,
199 const char *field_value, 199 const char *field_value,
@@ -204,7 +204,7 @@ static void define_value(enum print_arg_type field_type,
204 unsigned long long value; 204 unsigned long long value;
205 unsigned n = 0; 205 unsigned n = 0;
206 206
207 if (field_type == PRINT_SYMBOL) 207 if (field_type == TEP_PRINT_SYMBOL)
208 handler_name = "define_symbolic_value"; 208 handler_name = "define_symbolic_value";
209 209
210 t = PyTuple_New(4); 210 t = PyTuple_New(4);
@@ -223,8 +223,8 @@ static void define_value(enum print_arg_type field_type,
223 Py_DECREF(t); 223 Py_DECREF(t);
224} 224}
225 225
226static void define_values(enum print_arg_type field_type, 226static void define_values(enum tep_print_arg_type field_type,
227 struct print_flag_sym *field, 227 struct tep_print_flag_sym *field,
228 const char *ev_name, 228 const char *ev_name,
229 const char *field_name) 229 const char *field_name)
230{ 230{
@@ -235,7 +235,7 @@ static void define_values(enum print_arg_type field_type,
235 define_values(field_type, field->next, ev_name, field_name); 235 define_values(field_type, field->next, ev_name, field_name);
236} 236}
237 237
238static void define_field(enum print_arg_type field_type, 238static void define_field(enum tep_print_arg_type field_type,
239 const char *ev_name, 239 const char *ev_name,
240 const char *field_name, 240 const char *field_name,
241 const char *delim) 241 const char *delim)
@@ -244,10 +244,10 @@ static void define_field(enum print_arg_type field_type,
244 PyObject *t; 244 PyObject *t;
245 unsigned n = 0; 245 unsigned n = 0;
246 246
247 if (field_type == PRINT_SYMBOL) 247 if (field_type == TEP_PRINT_SYMBOL)
248 handler_name = "define_symbolic_field"; 248 handler_name = "define_symbolic_field";
249 249
250 if (field_type == PRINT_FLAGS) 250 if (field_type == TEP_PRINT_FLAGS)
251 t = PyTuple_New(3); 251 t = PyTuple_New(3);
252 else 252 else
253 t = PyTuple_New(2); 253 t = PyTuple_New(2);
@@ -256,7 +256,7 @@ static void define_field(enum print_arg_type field_type,
256 256
257 PyTuple_SetItem(t, n++, _PyUnicode_FromString(ev_name)); 257 PyTuple_SetItem(t, n++, _PyUnicode_FromString(ev_name));
258 PyTuple_SetItem(t, n++, _PyUnicode_FromString(field_name)); 258 PyTuple_SetItem(t, n++, _PyUnicode_FromString(field_name));
259 if (field_type == PRINT_FLAGS) 259 if (field_type == TEP_PRINT_FLAGS)
260 PyTuple_SetItem(t, n++, _PyUnicode_FromString(delim)); 260 PyTuple_SetItem(t, n++, _PyUnicode_FromString(delim));
261 261
262 try_call_object(handler_name, t); 262 try_call_object(handler_name, t);
@@ -264,54 +264,54 @@ static void define_field(enum print_arg_type field_type,
264 Py_DECREF(t); 264 Py_DECREF(t);
265} 265}
266 266
267static void define_event_symbols(struct event_format *event, 267static void define_event_symbols(struct tep_event_format *event,
268 const char *ev_name, 268 const char *ev_name,
269 struct print_arg *args) 269 struct tep_print_arg *args)
270{ 270{
271 if (args == NULL) 271 if (args == NULL)
272 return; 272 return;
273 273
274 switch (args->type) { 274 switch (args->type) {
275 case PRINT_NULL: 275 case TEP_PRINT_NULL:
276 break; 276 break;
277 case PRINT_ATOM: 277 case TEP_PRINT_ATOM:
278 define_value(PRINT_FLAGS, ev_name, cur_field_name, "0", 278 define_value(TEP_PRINT_FLAGS, ev_name, cur_field_name, "0",
279 args->atom.atom); 279 args->atom.atom);
280 zero_flag_atom = 0; 280 zero_flag_atom = 0;
281 break; 281 break;
282 case PRINT_FIELD: 282 case TEP_PRINT_FIELD:
283 free(cur_field_name); 283 free(cur_field_name);
284 cur_field_name = strdup(args->field.name); 284 cur_field_name = strdup(args->field.name);
285 break; 285 break;
286 case PRINT_FLAGS: 286 case TEP_PRINT_FLAGS:
287 define_event_symbols(event, ev_name, args->flags.field); 287 define_event_symbols(event, ev_name, args->flags.field);
288 define_field(PRINT_FLAGS, ev_name, cur_field_name, 288 define_field(TEP_PRINT_FLAGS, ev_name, cur_field_name,
289 args->flags.delim); 289 args->flags.delim);
290 define_values(PRINT_FLAGS, args->flags.flags, ev_name, 290 define_values(TEP_PRINT_FLAGS, args->flags.flags, ev_name,
291 cur_field_name); 291 cur_field_name);
292 break; 292 break;
293 case PRINT_SYMBOL: 293 case TEP_PRINT_SYMBOL:
294 define_event_symbols(event, ev_name, args->symbol.field); 294 define_event_symbols(event, ev_name, args->symbol.field);
295 define_field(PRINT_SYMBOL, ev_name, cur_field_name, NULL); 295 define_field(TEP_PRINT_SYMBOL, ev_name, cur_field_name, NULL);
296 define_values(PRINT_SYMBOL, args->symbol.symbols, ev_name, 296 define_values(TEP_PRINT_SYMBOL, args->symbol.symbols, ev_name,
297 cur_field_name); 297 cur_field_name);
298 break; 298 break;
299 case PRINT_HEX: 299 case TEP_PRINT_HEX:
300 case PRINT_HEX_STR: 300 case TEP_PRINT_HEX_STR:
301 define_event_symbols(event, ev_name, args->hex.field); 301 define_event_symbols(event, ev_name, args->hex.field);
302 define_event_symbols(event, ev_name, args->hex.size); 302 define_event_symbols(event, ev_name, args->hex.size);
303 break; 303 break;
304 case PRINT_INT_ARRAY: 304 case TEP_PRINT_INT_ARRAY:
305 define_event_symbols(event, ev_name, args->int_array.field); 305 define_event_symbols(event, ev_name, args->int_array.field);
306 define_event_symbols(event, ev_name, args->int_array.count); 306 define_event_symbols(event, ev_name, args->int_array.count);
307 define_event_symbols(event, ev_name, args->int_array.el_size); 307 define_event_symbols(event, ev_name, args->int_array.el_size);
308 break; 308 break;
309 case PRINT_STRING: 309 case TEP_PRINT_STRING:
310 break; 310 break;
311 case PRINT_TYPE: 311 case TEP_PRINT_TYPE:
312 define_event_symbols(event, ev_name, args->typecast.item); 312 define_event_symbols(event, ev_name, args->typecast.item);
313 break; 313 break;
314 case PRINT_OP: 314 case TEP_PRINT_OP:
315 if (strcmp(args->op.op, ":") == 0) 315 if (strcmp(args->op.op, ":") == 0)
316 zero_flag_atom = 1; 316 zero_flag_atom = 1;
317 define_event_symbols(event, ev_name, args->op.left); 317 define_event_symbols(event, ev_name, args->op.left);
@@ -319,11 +319,11 @@ static void define_event_symbols(struct event_format *event,
319 break; 319 break;
320 default: 320 default:
321 /* gcc warns for these? */ 321 /* gcc warns for these? */
322 case PRINT_BSTRING: 322 case TEP_PRINT_BSTRING:
323 case PRINT_DYNAMIC_ARRAY: 323 case TEP_PRINT_DYNAMIC_ARRAY:
324 case PRINT_DYNAMIC_ARRAY_LEN: 324 case TEP_PRINT_DYNAMIC_ARRAY_LEN:
325 case PRINT_FUNC: 325 case TEP_PRINT_FUNC:
326 case PRINT_BITMASK: 326 case TEP_PRINT_BITMASK:
327 /* we should warn... */ 327 /* we should warn... */
328 return; 328 return;
329 } 329 }
@@ -332,10 +332,10 @@ static void define_event_symbols(struct event_format *event,
332 define_event_symbols(event, ev_name, args->next); 332 define_event_symbols(event, ev_name, args->next);
333} 333}
334 334
335static PyObject *get_field_numeric_entry(struct event_format *event, 335static PyObject *get_field_numeric_entry(struct tep_event_format *event,
336 struct format_field *field, void *data) 336 struct tep_format_field *field, void *data)
337{ 337{
338 bool is_array = field->flags & FIELD_IS_ARRAY; 338 bool is_array = field->flags & TEP_FIELD_IS_ARRAY;
339 PyObject *obj = NULL, *list = NULL; 339 PyObject *obj = NULL, *list = NULL;
340 unsigned long long val; 340 unsigned long long val;
341 unsigned int item_size, n_items, i; 341 unsigned int item_size, n_items, i;
@@ -353,7 +353,7 @@ static PyObject *get_field_numeric_entry(struct event_format *event,
353 353
354 val = read_size(event, data + field->offset + i * item_size, 354 val = read_size(event, data + field->offset + i * item_size,
355 item_size); 355 item_size);
356 if (field->flags & FIELD_IS_SIGNED) { 356 if (field->flags & TEP_FIELD_IS_SIGNED) {
357 if ((long long)val >= LONG_MIN && 357 if ((long long)val >= LONG_MIN &&
358 (long long)val <= LONG_MAX) 358 (long long)val <= LONG_MAX)
359 obj = _PyLong_FromLong(val); 359 obj = _PyLong_FromLong(val);
@@ -790,11 +790,11 @@ static void python_process_tracepoint(struct perf_sample *sample,
790 struct perf_evsel *evsel, 790 struct perf_evsel *evsel,
791 struct addr_location *al) 791 struct addr_location *al)
792{ 792{
793 struct event_format *event = evsel->tp_format; 793 struct tep_event_format *event = evsel->tp_format;
794 PyObject *handler, *context, *t, *obj = NULL, *callchain; 794 PyObject *handler, *context, *t, *obj = NULL, *callchain;
795 PyObject *dict = NULL, *all_entries_dict = NULL; 795 PyObject *dict = NULL, *all_entries_dict = NULL;
796 static char handler_name[256]; 796 static char handler_name[256];
797 struct format_field *field; 797 struct tep_format_field *field;
798 unsigned long s, ns; 798 unsigned long s, ns;
799 unsigned n = 0; 799 unsigned n = 0;
800 int pid; 800 int pid;
@@ -867,22 +867,22 @@ static void python_process_tracepoint(struct perf_sample *sample,
867 unsigned int offset, len; 867 unsigned int offset, len;
868 unsigned long long val; 868 unsigned long long val;
869 869
870 if (field->flags & FIELD_IS_ARRAY) { 870 if (field->flags & TEP_FIELD_IS_ARRAY) {
871 offset = field->offset; 871 offset = field->offset;
872 len = field->size; 872 len = field->size;
873 if (field->flags & FIELD_IS_DYNAMIC) { 873 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
874 val = tep_read_number(scripting_context->pevent, 874 val = tep_read_number(scripting_context->pevent,
875 data + offset, len); 875 data + offset, len);
876 offset = val; 876 offset = val;
877 len = offset >> 16; 877 len = offset >> 16;
878 offset &= 0xffff; 878 offset &= 0xffff;
879 } 879 }
880 if (field->flags & FIELD_IS_STRING && 880 if (field->flags & TEP_FIELD_IS_STRING &&
881 is_printable_array(data + offset, len)) { 881 is_printable_array(data + offset, len)) {
882 obj = _PyUnicode_FromString((char *) data + offset); 882 obj = _PyUnicode_FromString((char *) data + offset);
883 } else { 883 } else {
884 obj = PyByteArray_FromStringAndSize((const char *) data + offset, len); 884 obj = PyByteArray_FromStringAndSize((const char *) data + offset, len);
885 field->flags &= ~FIELD_IS_STRING; 885 field->flags &= ~TEP_FIELD_IS_STRING;
886 } 886 }
887 } else { /* FIELD_IS_NUMERIC */ 887 } else { /* FIELD_IS_NUMERIC */
888 obj = get_field_numeric_entry(event, field, data); 888 obj = get_field_numeric_entry(event, field, data);
@@ -1590,8 +1590,8 @@ static int python_stop_script(void)
1590 1590
1591static int python_generate_script(struct tep_handle *pevent, const char *outfile) 1591static int python_generate_script(struct tep_handle *pevent, const char *outfile)
1592{ 1592{
1593 struct event_format *event = NULL; 1593 struct tep_event_format *event = NULL;
1594 struct format_field *f; 1594 struct tep_format_field *f;
1595 char fname[PATH_MAX]; 1595 char fname[PATH_MAX];
1596 int not_first, count; 1596 int not_first, count;
1597 FILE *ofp; 1597 FILE *ofp;
@@ -1686,12 +1686,12 @@ static int python_generate_script(struct tep_handle *pevent, const char *outfile
1686 count++; 1686 count++;
1687 1687
1688 fprintf(ofp, "%s=", f->name); 1688 fprintf(ofp, "%s=", f->name);
1689 if (f->flags & FIELD_IS_STRING || 1689 if (f->flags & TEP_FIELD_IS_STRING ||
1690 f->flags & FIELD_IS_FLAG || 1690 f->flags & TEP_FIELD_IS_FLAG ||
1691 f->flags & FIELD_IS_ARRAY || 1691 f->flags & TEP_FIELD_IS_ARRAY ||
1692 f->flags & FIELD_IS_SYMBOLIC) 1692 f->flags & TEP_FIELD_IS_SYMBOLIC)
1693 fprintf(ofp, "%%s"); 1693 fprintf(ofp, "%%s");
1694 else if (f->flags & FIELD_IS_SIGNED) 1694 else if (f->flags & TEP_FIELD_IS_SIGNED)
1695 fprintf(ofp, "%%d"); 1695 fprintf(ofp, "%%d");
1696 else 1696 else
1697 fprintf(ofp, "%%u"); 1697 fprintf(ofp, "%%u");
@@ -1709,7 +1709,7 @@ static int python_generate_script(struct tep_handle *pevent, const char *outfile
1709 if (++count % 5 == 0) 1709 if (++count % 5 == 0)
1710 fprintf(ofp, "\n\t\t"); 1710 fprintf(ofp, "\n\t\t");
1711 1711
1712 if (f->flags & FIELD_IS_FLAG) { 1712 if (f->flags & TEP_FIELD_IS_FLAG) {
1713 if ((count - 1) % 5 != 0) { 1713 if ((count - 1) % 5 != 0) {
1714 fprintf(ofp, "\n\t\t"); 1714 fprintf(ofp, "\n\t\t");
1715 count = 4; 1715 count = 4;
@@ -1719,7 +1719,7 @@ static int python_generate_script(struct tep_handle *pevent, const char *outfile
1719 event->name); 1719 event->name);
1720 fprintf(ofp, "\"%s\", %s)", f->name, 1720 fprintf(ofp, "\"%s\", %s)", f->name,
1721 f->name); 1721 f->name);
1722 } else if (f->flags & FIELD_IS_SYMBOLIC) { 1722 } else if (f->flags & TEP_FIELD_IS_SYMBOLIC) {
1723 if ((count - 1) % 5 != 0) { 1723 if ((count - 1) % 5 != 0) {
1724 fprintf(ofp, "\n\t\t"); 1724 fprintf(ofp, "\n\t\t");
1725 count = 4; 1725 count = 4;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 8b9369303561..7d2c8ce6cfad 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -199,12 +199,10 @@ void perf_session__delete(struct perf_session *session)
199 free(session); 199 free(session);
200} 200}
201 201
202static int process_event_synth_tracing_data_stub(struct perf_tool *tool 202static int process_event_synth_tracing_data_stub(struct perf_session *session
203 __maybe_unused, 203 __maybe_unused,
204 union perf_event *event 204 union perf_event *event
205 __maybe_unused, 205 __maybe_unused)
206 struct perf_session *session
207 __maybe_unused)
208{ 206{
209 dump_printf(": unhandled!\n"); 207 dump_printf(": unhandled!\n");
210 return 0; 208 return 0;
@@ -277,10 +275,8 @@ static int skipn(int fd, off_t n)
277 return 0; 275 return 0;
278} 276}
279 277
280static s64 process_event_auxtrace_stub(struct perf_tool *tool __maybe_unused, 278static s64 process_event_auxtrace_stub(struct perf_session *session __maybe_unused,
281 union perf_event *event, 279 union perf_event *event)
282 struct perf_session *session
283 __maybe_unused)
284{ 280{
285 dump_printf(": unhandled!\n"); 281 dump_printf(": unhandled!\n");
286 if (perf_data__is_pipe(session->data)) 282 if (perf_data__is_pipe(session->data))
@@ -288,9 +284,8 @@ static s64 process_event_auxtrace_stub(struct perf_tool *tool __maybe_unused,
288 return event->auxtrace.size; 284 return event->auxtrace.size;
289} 285}
290 286
291static int process_event_op2_stub(struct perf_tool *tool __maybe_unused, 287static int process_event_op2_stub(struct perf_session *session __maybe_unused,
292 union perf_event *event __maybe_unused, 288 union perf_event *event __maybe_unused)
293 struct perf_session *session __maybe_unused)
294{ 289{
295 dump_printf(": unhandled!\n"); 290 dump_printf(": unhandled!\n");
296 return 0; 291 return 0;
@@ -298,9 +293,8 @@ static int process_event_op2_stub(struct perf_tool *tool __maybe_unused,
298 293
299 294
300static 295static
301int process_event_thread_map_stub(struct perf_tool *tool __maybe_unused, 296int process_event_thread_map_stub(struct perf_session *session __maybe_unused,
302 union perf_event *event __maybe_unused, 297 union perf_event *event __maybe_unused)
303 struct perf_session *session __maybe_unused)
304{ 298{
305 if (dump_trace) 299 if (dump_trace)
306 perf_event__fprintf_thread_map(event, stdout); 300 perf_event__fprintf_thread_map(event, stdout);
@@ -310,9 +304,8 @@ int process_event_thread_map_stub(struct perf_tool *tool __maybe_unused,
310} 304}
311 305
312static 306static
313int process_event_cpu_map_stub(struct perf_tool *tool __maybe_unused, 307int process_event_cpu_map_stub(struct perf_session *session __maybe_unused,
314 union perf_event *event __maybe_unused, 308 union perf_event *event __maybe_unused)
315 struct perf_session *session __maybe_unused)
316{ 309{
317 if (dump_trace) 310 if (dump_trace)
318 perf_event__fprintf_cpu_map(event, stdout); 311 perf_event__fprintf_cpu_map(event, stdout);
@@ -322,9 +315,8 @@ int process_event_cpu_map_stub(struct perf_tool *tool __maybe_unused,
322} 315}
323 316
324static 317static
325int process_event_stat_config_stub(struct perf_tool *tool __maybe_unused, 318int process_event_stat_config_stub(struct perf_session *session __maybe_unused,
326 union perf_event *event __maybe_unused, 319 union perf_event *event __maybe_unused)
327 struct perf_session *session __maybe_unused)
328{ 320{
329 if (dump_trace) 321 if (dump_trace)
330 perf_event__fprintf_stat_config(event, stdout); 322 perf_event__fprintf_stat_config(event, stdout);
@@ -333,10 +325,8 @@ int process_event_stat_config_stub(struct perf_tool *tool __maybe_unused,
333 return 0; 325 return 0;
334} 326}
335 327
336static int process_stat_stub(struct perf_tool *tool __maybe_unused, 328static int process_stat_stub(struct perf_session *perf_session __maybe_unused,
337 union perf_event *event __maybe_unused, 329 union perf_event *event)
338 struct perf_session *perf_session
339 __maybe_unused)
340{ 330{
341 if (dump_trace) 331 if (dump_trace)
342 perf_event__fprintf_stat(event, stdout); 332 perf_event__fprintf_stat(event, stdout);
@@ -345,10 +335,8 @@ static int process_stat_stub(struct perf_tool *tool __maybe_unused,
345 return 0; 335 return 0;
346} 336}
347 337
348static int process_stat_round_stub(struct perf_tool *tool __maybe_unused, 338static int process_stat_round_stub(struct perf_session *perf_session __maybe_unused,
349 union perf_event *event __maybe_unused, 339 union perf_event *event)
350 struct perf_session *perf_session
351 __maybe_unused)
352{ 340{
353 if (dump_trace) 341 if (dump_trace)
354 perf_event__fprintf_stat_round(event, stdout); 342 perf_event__fprintf_stat_round(event, stdout);
@@ -1374,37 +1362,37 @@ static s64 perf_session__process_user_event(struct perf_session *session,
1374 case PERF_RECORD_HEADER_TRACING_DATA: 1362 case PERF_RECORD_HEADER_TRACING_DATA:
1375 /* setup for reading amidst mmap */ 1363 /* setup for reading amidst mmap */
1376 lseek(fd, file_offset, SEEK_SET); 1364 lseek(fd, file_offset, SEEK_SET);
1377 return tool->tracing_data(tool, event, session); 1365 return tool->tracing_data(session, event);
1378 case PERF_RECORD_HEADER_BUILD_ID: 1366 case PERF_RECORD_HEADER_BUILD_ID:
1379 return tool->build_id(tool, event, session); 1367 return tool->build_id(session, event);
1380 case PERF_RECORD_FINISHED_ROUND: 1368 case PERF_RECORD_FINISHED_ROUND:
1381 return tool->finished_round(tool, event, oe); 1369 return tool->finished_round(tool, event, oe);
1382 case PERF_RECORD_ID_INDEX: 1370 case PERF_RECORD_ID_INDEX:
1383 return tool->id_index(tool, event, session); 1371 return tool->id_index(session, event);
1384 case PERF_RECORD_AUXTRACE_INFO: 1372 case PERF_RECORD_AUXTRACE_INFO:
1385 return tool->auxtrace_info(tool, event, session); 1373 return tool->auxtrace_info(session, event);
1386 case PERF_RECORD_AUXTRACE: 1374 case PERF_RECORD_AUXTRACE:
1387 /* setup for reading amidst mmap */ 1375 /* setup for reading amidst mmap */
1388 lseek(fd, file_offset + event->header.size, SEEK_SET); 1376 lseek(fd, file_offset + event->header.size, SEEK_SET);
1389 return tool->auxtrace(tool, event, session); 1377 return tool->auxtrace(session, event);
1390 case PERF_RECORD_AUXTRACE_ERROR: 1378 case PERF_RECORD_AUXTRACE_ERROR:
1391 perf_session__auxtrace_error_inc(session, event); 1379 perf_session__auxtrace_error_inc(session, event);
1392 return tool->auxtrace_error(tool, event, session); 1380 return tool->auxtrace_error(session, event);
1393 case PERF_RECORD_THREAD_MAP: 1381 case PERF_RECORD_THREAD_MAP:
1394 return tool->thread_map(tool, event, session); 1382 return tool->thread_map(session, event);
1395 case PERF_RECORD_CPU_MAP: 1383 case PERF_RECORD_CPU_MAP:
1396 return tool->cpu_map(tool, event, session); 1384 return tool->cpu_map(session, event);
1397 case PERF_RECORD_STAT_CONFIG: 1385 case PERF_RECORD_STAT_CONFIG:
1398 return tool->stat_config(tool, event, session); 1386 return tool->stat_config(session, event);
1399 case PERF_RECORD_STAT: 1387 case PERF_RECORD_STAT:
1400 return tool->stat(tool, event, session); 1388 return tool->stat(session, event);
1401 case PERF_RECORD_STAT_ROUND: 1389 case PERF_RECORD_STAT_ROUND:
1402 return tool->stat_round(tool, event, session); 1390 return tool->stat_round(session, event);
1403 case PERF_RECORD_TIME_CONV: 1391 case PERF_RECORD_TIME_CONV:
1404 session->time_conv = event->time_conv; 1392 session->time_conv = event->time_conv;
1405 return tool->time_conv(tool, event, session); 1393 return tool->time_conv(session, event);
1406 case PERF_RECORD_HEADER_FEATURE: 1394 case PERF_RECORD_HEADER_FEATURE:
1407 return tool->feature(tool, event, session); 1395 return tool->feature(session, event);
1408 default: 1396 default:
1409 return -EINVAL; 1397 return -EINVAL;
1410 } 1398 }
@@ -2133,9 +2121,8 @@ out:
2133 return err; 2121 return err;
2134} 2122}
2135 2123
2136int perf_event__process_id_index(struct perf_tool *tool __maybe_unused, 2124int perf_event__process_id_index(struct perf_session *session,
2137 union perf_event *event, 2125 union perf_event *event)
2138 struct perf_session *session)
2139{ 2126{
2140 struct perf_evlist *evlist = session->evlist; 2127 struct perf_evlist *evlist = session->evlist;
2141 struct id_index_event *ie = &event->id_index; 2128 struct id_index_event *ie = &event->id_index;
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index da40b4b380ca..d96eccd7d27f 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -120,9 +120,8 @@ int perf_session__deliver_synth_event(struct perf_session *session,
120 union perf_event *event, 120 union perf_event *event,
121 struct perf_sample *sample); 121 struct perf_sample *sample);
122 122
123int perf_event__process_id_index(struct perf_tool *tool, 123int perf_event__process_id_index(struct perf_session *session,
124 union perf_event *event, 124 union perf_event *event);
125 struct perf_session *session);
126 125
127int perf_event__synthesize_id_index(struct perf_tool *tool, 126int perf_event__synthesize_id_index(struct perf_tool *tool,
128 perf_event__handler_t process, 127 perf_event__handler_t process,
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 1942f6dd24f6..63f758c655d5 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -5,16 +5,18 @@ from subprocess import Popen, PIPE
5from re import sub 5from re import sub
6 6
7def clang_has_option(option): 7def clang_has_option(option):
8 return [o for o in Popen(['clang', option], stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ] 8 return [o for o in Popen(['clang', option], stderr=PIPE).stderr.readlines() if b"unknown argument" in o] == [ ]
9 9
10cc = getenv("CC") 10cc = getenv("CC")
11if cc == "clang": 11if cc == "clang":
12 from _sysconfigdata import build_time_vars 12 from distutils.sysconfig import get_config_vars
13 build_time_vars["CFLAGS"] = sub("-specs=[^ ]+", "", build_time_vars["CFLAGS"]) 13 vars = get_config_vars()
14 if not clang_has_option("-mcet"): 14 for var in ('CFLAGS', 'OPT'):
15 build_time_vars["CFLAGS"] = sub("-mcet", "", build_time_vars["CFLAGS"]) 15 vars[var] = sub("-specs=[^ ]+", "", vars[var])
16 if not clang_has_option("-fcf-protection"): 16 if not clang_has_option("-mcet"):
17 build_time_vars["CFLAGS"] = sub("-fcf-protection", "", build_time_vars["CFLAGS"]) 17 vars[var] = sub("-mcet", "", vars[var])
18 if not clang_has_option("-fcf-protection"):
19 vars[var] = sub("-fcf-protection", "", vars[var])
18 20
19from distutils.core import setup, Extension 21from distutils.core import setup, Extension
20 22
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index b284276ec963..f96c005b3c41 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -1884,7 +1884,7 @@ static int __sort_dimension__add_hpp_output(struct sort_dimension *sd,
1884struct hpp_dynamic_entry { 1884struct hpp_dynamic_entry {
1885 struct perf_hpp_fmt hpp; 1885 struct perf_hpp_fmt hpp;
1886 struct perf_evsel *evsel; 1886 struct perf_evsel *evsel;
1887 struct format_field *field; 1887 struct tep_format_field *field;
1888 unsigned dynamic_len; 1888 unsigned dynamic_len;
1889 bool raw_trace; 1889 bool raw_trace;
1890}; 1890};
@@ -1899,7 +1899,7 @@ static int hde_width(struct hpp_dynamic_entry *hde)
1899 if (namelen > len) 1899 if (namelen > len)
1900 len = namelen; 1900 len = namelen;
1901 1901
1902 if (!(hde->field->flags & FIELD_IS_STRING)) { 1902 if (!(hde->field->flags & TEP_FIELD_IS_STRING)) {
1903 /* length for print hex numbers */ 1903 /* length for print hex numbers */
1904 fieldlen = hde->field->size * 2 + 2; 1904 fieldlen = hde->field->size * 2 + 2;
1905 } 1905 }
@@ -1915,7 +1915,7 @@ static void update_dynamic_len(struct hpp_dynamic_entry *hde,
1915 struct hist_entry *he) 1915 struct hist_entry *he)
1916{ 1916{
1917 char *str, *pos; 1917 char *str, *pos;
1918 struct format_field *field = hde->field; 1918 struct tep_format_field *field = hde->field;
1919 size_t namelen; 1919 size_t namelen;
1920 bool last = false; 1920 bool last = false;
1921 1921
@@ -2000,7 +2000,7 @@ static int __sort__hde_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
2000 struct hpp_dynamic_entry *hde; 2000 struct hpp_dynamic_entry *hde;
2001 size_t len = fmt->user_len; 2001 size_t len = fmt->user_len;
2002 char *str, *pos; 2002 char *str, *pos;
2003 struct format_field *field; 2003 struct tep_format_field *field;
2004 size_t namelen; 2004 size_t namelen;
2005 bool last = false; 2005 bool last = false;
2006 int ret; 2006 int ret;
@@ -2060,7 +2060,7 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,
2060 struct hist_entry *a, struct hist_entry *b) 2060 struct hist_entry *a, struct hist_entry *b)
2061{ 2061{
2062 struct hpp_dynamic_entry *hde; 2062 struct hpp_dynamic_entry *hde;
2063 struct format_field *field; 2063 struct tep_format_field *field;
2064 unsigned offset, size; 2064 unsigned offset, size;
2065 2065
2066 hde = container_of(fmt, struct hpp_dynamic_entry, hpp); 2066 hde = container_of(fmt, struct hpp_dynamic_entry, hpp);
@@ -2071,7 +2071,7 @@ static int64_t __sort__hde_cmp(struct perf_hpp_fmt *fmt,
2071 } 2071 }
2072 2072
2073 field = hde->field; 2073 field = hde->field;
2074 if (field->flags & FIELD_IS_DYNAMIC) { 2074 if (field->flags & TEP_FIELD_IS_DYNAMIC) {
2075 unsigned long long dyn; 2075 unsigned long long dyn;
2076 2076
2077 tep_read_number_field(field, a->raw_data, &dyn); 2077 tep_read_number_field(field, a->raw_data, &dyn);
@@ -2117,7 +2117,7 @@ static void hde_free(struct perf_hpp_fmt *fmt)
2117} 2117}
2118 2118
2119static struct hpp_dynamic_entry * 2119static struct hpp_dynamic_entry *
2120__alloc_dynamic_entry(struct perf_evsel *evsel, struct format_field *field, 2120__alloc_dynamic_entry(struct perf_evsel *evsel, struct tep_format_field *field,
2121 int level) 2121 int level)
2122{ 2122{
2123 struct hpp_dynamic_entry *hde; 2123 struct hpp_dynamic_entry *hde;
@@ -2252,7 +2252,7 @@ static struct perf_evsel *find_evsel(struct perf_evlist *evlist, char *event_nam
2252} 2252}
2253 2253
2254static int __dynamic_dimension__add(struct perf_evsel *evsel, 2254static int __dynamic_dimension__add(struct perf_evsel *evsel,
2255 struct format_field *field, 2255 struct tep_format_field *field,
2256 bool raw_trace, int level) 2256 bool raw_trace, int level)
2257{ 2257{
2258 struct hpp_dynamic_entry *hde; 2258 struct hpp_dynamic_entry *hde;
@@ -2270,7 +2270,7 @@ static int __dynamic_dimension__add(struct perf_evsel *evsel,
2270static int add_evsel_fields(struct perf_evsel *evsel, bool raw_trace, int level) 2270static int add_evsel_fields(struct perf_evsel *evsel, bool raw_trace, int level)
2271{ 2271{
2272 int ret; 2272 int ret;
2273 struct format_field *field; 2273 struct tep_format_field *field;
2274 2274
2275 field = evsel->tp_format->format.fields; 2275 field = evsel->tp_format->format.fields;
2276 while (field) { 2276 while (field) {
@@ -2305,7 +2305,7 @@ static int add_all_matching_fields(struct perf_evlist *evlist,
2305{ 2305{
2306 int ret = -ESRCH; 2306 int ret = -ESRCH;
2307 struct perf_evsel *evsel; 2307 struct perf_evsel *evsel;
2308 struct format_field *field; 2308 struct tep_format_field *field;
2309 2309
2310 evlist__for_each_entry(evlist, evsel) { 2310 evlist__for_each_entry(evlist, evsel) {
2311 if (evsel->attr.type != PERF_TYPE_TRACEPOINT) 2311 if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
@@ -2327,7 +2327,7 @@ static int add_dynamic_entry(struct perf_evlist *evlist, const char *tok,
2327{ 2327{
2328 char *str, *event_name, *field_name, *opt_name; 2328 char *str, *event_name, *field_name, *opt_name;
2329 struct perf_evsel *evsel; 2329 struct perf_evsel *evsel;
2330 struct format_field *field; 2330 struct tep_format_field *field;
2331 bool raw_trace = symbol_conf.raw_trace; 2331 bool raw_trace = symbol_conf.raw_trace;
2332 int ret = 0; 2332 int ret = 0;
2333 2333
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
new file mode 100644
index 000000000000..e7b4c44ebb62
--- /dev/null
+++ b/tools/perf/util/stat-display.c
@@ -0,0 +1,1166 @@
1#include <stdio.h>
2#include <inttypes.h>
3#include <linux/time64.h>
4#include <math.h>
5#include "evlist.h"
6#include "evsel.h"
7#include "stat.h"
8#include "top.h"
9#include "thread_map.h"
10#include "cpumap.h"
11#include "string2.h"
12#include "sane_ctype.h"
13#include "cgroup.h"
14#include <math.h>
15#include <api/fs/fs.h>
16
17#define CNTR_NOT_SUPPORTED "<not supported>"
18#define CNTR_NOT_COUNTED "<not counted>"
19
20static bool is_duration_time(struct perf_evsel *evsel)
21{
22 return !strcmp(evsel->name, "duration_time");
23}
24
25static void print_running(struct perf_stat_config *config,
26 u64 run, u64 ena)
27{
28 if (config->csv_output) {
29 fprintf(config->output, "%s%" PRIu64 "%s%.2f",
30 config->csv_sep,
31 run,
32 config->csv_sep,
33 ena ? 100.0 * run / ena : 100.0);
34 } else if (run != ena) {
35 fprintf(config->output, " (%.2f%%)", 100.0 * run / ena);
36 }
37}
38
39static void print_noise_pct(struct perf_stat_config *config,
40 double total, double avg)
41{
42 double pct = rel_stddev_stats(total, avg);
43
44 if (config->csv_output)
45 fprintf(config->output, "%s%.2f%%", config->csv_sep, pct);
46 else if (pct)
47 fprintf(config->output, " ( +-%6.2f%% )", pct);
48}
49
50static void print_noise(struct perf_stat_config *config,
51 struct perf_evsel *evsel, double avg)
52{
53 struct perf_stat_evsel *ps;
54
55 if (config->run_count == 1)
56 return;
57
58 ps = evsel->stats;
59 print_noise_pct(config, stddev_stats(&ps->res_stats[0]), avg);
60}
61
62static void aggr_printout(struct perf_stat_config *config,
63 struct perf_evsel *evsel, int id, int nr)
64{
65 switch (config->aggr_mode) {
66 case AGGR_CORE:
67 fprintf(config->output, "S%d-C%*d%s%*d%s",
68 cpu_map__id_to_socket(id),
69 config->csv_output ? 0 : -8,
70 cpu_map__id_to_cpu(id),
71 config->csv_sep,
72 config->csv_output ? 0 : 4,
73 nr,
74 config->csv_sep);
75 break;
76 case AGGR_SOCKET:
77 fprintf(config->output, "S%*d%s%*d%s",
78 config->csv_output ? 0 : -5,
79 id,
80 config->csv_sep,
81 config->csv_output ? 0 : 4,
82 nr,
83 config->csv_sep);
84 break;
85 case AGGR_NONE:
86 fprintf(config->output, "CPU%*d%s",
87 config->csv_output ? 0 : -4,
88 perf_evsel__cpus(evsel)->map[id], config->csv_sep);
89 break;
90 case AGGR_THREAD:
91 fprintf(config->output, "%*s-%*d%s",
92 config->csv_output ? 0 : 16,
93 thread_map__comm(evsel->threads, id),
94 config->csv_output ? 0 : -8,
95 thread_map__pid(evsel->threads, id),
96 config->csv_sep);
97 break;
98 case AGGR_GLOBAL:
99 case AGGR_UNSET:
100 default:
101 break;
102 }
103}
104
105struct outstate {
106 FILE *fh;
107 bool newline;
108 const char *prefix;
109 int nfields;
110 int id, nr;
111 struct perf_evsel *evsel;
112};
113
114#define METRIC_LEN 35
115
116static void new_line_std(struct perf_stat_config *config __maybe_unused,
117 void *ctx)
118{
119 struct outstate *os = ctx;
120
121 os->newline = true;
122}
123
124static void do_new_line_std(struct perf_stat_config *config,
125 struct outstate *os)
126{
127 fputc('\n', os->fh);
128 fputs(os->prefix, os->fh);
129 aggr_printout(config, os->evsel, os->id, os->nr);
130 if (config->aggr_mode == AGGR_NONE)
131 fprintf(os->fh, " ");
132 fprintf(os->fh, " ");
133}
134
135static void print_metric_std(struct perf_stat_config *config,
136 void *ctx, const char *color, const char *fmt,
137 const char *unit, double val)
138{
139 struct outstate *os = ctx;
140 FILE *out = os->fh;
141 int n;
142 bool newline = os->newline;
143
144 os->newline = false;
145
146 if (unit == NULL || fmt == NULL) {
147 fprintf(out, "%-*s", METRIC_LEN, "");
148 return;
149 }
150
151 if (newline)
152 do_new_line_std(config, os);
153
154 n = fprintf(out, " # ");
155 if (color)
156 n += color_fprintf(out, color, fmt, val);
157 else
158 n += fprintf(out, fmt, val);
159 fprintf(out, " %-*s", METRIC_LEN - n - 1, unit);
160}
161
162static void new_line_csv(struct perf_stat_config *config, void *ctx)
163{
164 struct outstate *os = ctx;
165 int i;
166
167 fputc('\n', os->fh);
168 if (os->prefix)
169 fprintf(os->fh, "%s%s", os->prefix, config->csv_sep);
170 aggr_printout(config, os->evsel, os->id, os->nr);
171 for (i = 0; i < os->nfields; i++)
172 fputs(config->csv_sep, os->fh);
173}
174
175static void print_metric_csv(struct perf_stat_config *config __maybe_unused,
176 void *ctx,
177 const char *color __maybe_unused,
178 const char *fmt, const char *unit, double val)
179{
180 struct outstate *os = ctx;
181 FILE *out = os->fh;
182 char buf[64], *vals, *ends;
183
184 if (unit == NULL || fmt == NULL) {
185 fprintf(out, "%s%s", config->csv_sep, config->csv_sep);
186 return;
187 }
188 snprintf(buf, sizeof(buf), fmt, val);
189 ends = vals = ltrim(buf);
190 while (isdigit(*ends) || *ends == '.')
191 ends++;
192 *ends = 0;
193 while (isspace(*unit))
194 unit++;
195 fprintf(out, "%s%s%s%s", config->csv_sep, vals, config->csv_sep, unit);
196}
197
198/* Filter out some columns that don't work well in metrics only mode */
199
200static bool valid_only_metric(const char *unit)
201{
202 if (!unit)
203 return false;
204 if (strstr(unit, "/sec") ||
205 strstr(unit, "hz") ||
206 strstr(unit, "Hz") ||
207 strstr(unit, "CPUs utilized"))
208 return false;
209 return true;
210}
211
212static const char *fixunit(char *buf, struct perf_evsel *evsel,
213 const char *unit)
214{
215 if (!strncmp(unit, "of all", 6)) {
216 snprintf(buf, 1024, "%s %s", perf_evsel__name(evsel),
217 unit);
218 return buf;
219 }
220 return unit;
221}
222
223static void print_metric_only(struct perf_stat_config *config,
224 void *ctx, const char *color, const char *fmt,
225 const char *unit, double val)
226{
227 struct outstate *os = ctx;
228 FILE *out = os->fh;
229 char buf[1024], str[1024];
230 unsigned mlen = config->metric_only_len;
231
232 if (!valid_only_metric(unit))
233 return;
234 unit = fixunit(buf, os->evsel, unit);
235 if (mlen < strlen(unit))
236 mlen = strlen(unit) + 1;
237
238 if (color)
239 mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1;
240
241 color_snprintf(str, sizeof(str), color ?: "", fmt, val);
242 fprintf(out, "%*s ", mlen, str);
243}
244
245static void print_metric_only_csv(struct perf_stat_config *config __maybe_unused,
246 void *ctx, const char *color __maybe_unused,
247 const char *fmt,
248 const char *unit, double val)
249{
250 struct outstate *os = ctx;
251 FILE *out = os->fh;
252 char buf[64], *vals, *ends;
253 char tbuf[1024];
254
255 if (!valid_only_metric(unit))
256 return;
257 unit = fixunit(tbuf, os->evsel, unit);
258 snprintf(buf, sizeof buf, fmt, val);
259 ends = vals = ltrim(buf);
260 while (isdigit(*ends) || *ends == '.')
261 ends++;
262 *ends = 0;
263 fprintf(out, "%s%s", vals, config->csv_sep);
264}
265
266static void new_line_metric(struct perf_stat_config *config __maybe_unused,
267 void *ctx __maybe_unused)
268{
269}
270
271static void print_metric_header(struct perf_stat_config *config,
272 void *ctx, const char *color __maybe_unused,
273 const char *fmt __maybe_unused,
274 const char *unit, double val __maybe_unused)
275{
276 struct outstate *os = ctx;
277 char tbuf[1024];
278
279 if (!valid_only_metric(unit))
280 return;
281 unit = fixunit(tbuf, os->evsel, unit);
282 if (config->csv_output)
283 fprintf(os->fh, "%s%s", unit, config->csv_sep);
284 else
285 fprintf(os->fh, "%*s ", config->metric_only_len, unit);
286}
287
288static int first_shadow_cpu(struct perf_stat_config *config,
289 struct perf_evsel *evsel, int id)
290{
291 struct perf_evlist *evlist = evsel->evlist;
292 int i;
293
294 if (!config->aggr_get_id)
295 return 0;
296
297 if (config->aggr_mode == AGGR_NONE)
298 return id;
299
300 if (config->aggr_mode == AGGR_GLOBAL)
301 return 0;
302
303 for (i = 0; i < perf_evsel__nr_cpus(evsel); i++) {
304 int cpu2 = perf_evsel__cpus(evsel)->map[i];
305
306 if (config->aggr_get_id(config, evlist->cpus, cpu2) == id)
307 return cpu2;
308 }
309 return 0;
310}
311
312static void abs_printout(struct perf_stat_config *config,
313 int id, int nr, struct perf_evsel *evsel, double avg)
314{
315 FILE *output = config->output;
316 double sc = evsel->scale;
317 const char *fmt;
318
319 if (config->csv_output) {
320 fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s";
321 } else {
322 if (config->big_num)
323 fmt = floor(sc) != sc ? "%'18.2f%s" : "%'18.0f%s";
324 else
325 fmt = floor(sc) != sc ? "%18.2f%s" : "%18.0f%s";
326 }
327
328 aggr_printout(config, evsel, id, nr);
329
330 fprintf(output, fmt, avg, config->csv_sep);
331
332 if (evsel->unit)
333 fprintf(output, "%-*s%s",
334 config->csv_output ? 0 : config->unit_width,
335 evsel->unit, config->csv_sep);
336
337 fprintf(output, "%-*s", config->csv_output ? 0 : 25, perf_evsel__name(evsel));
338
339 if (evsel->cgrp)
340 fprintf(output, "%s%s", config->csv_sep, evsel->cgrp->name);
341}
342
343static bool is_mixed_hw_group(struct perf_evsel *counter)
344{
345 struct perf_evlist *evlist = counter->evlist;
346 u32 pmu_type = counter->attr.type;
347 struct perf_evsel *pos;
348
349 if (counter->nr_members < 2)
350 return false;
351
352 evlist__for_each_entry(evlist, pos) {
353 /* software events can be part of any hardware group */
354 if (pos->attr.type == PERF_TYPE_SOFTWARE)
355 continue;
356 if (pmu_type == PERF_TYPE_SOFTWARE) {
357 pmu_type = pos->attr.type;
358 continue;
359 }
360 if (pmu_type != pos->attr.type)
361 return true;
362 }
363
364 return false;
365}
366
367static void printout(struct perf_stat_config *config, int id, int nr,
368 struct perf_evsel *counter, double uval,
369 char *prefix, u64 run, u64 ena, double noise,
370 struct runtime_stat *st)
371{
372 struct perf_stat_output_ctx out;
373 struct outstate os = {
374 .fh = config->output,
375 .prefix = prefix ? prefix : "",
376 .id = id,
377 .nr = nr,
378 .evsel = counter,
379 };
380 print_metric_t pm = print_metric_std;
381 new_line_t nl;
382
383 if (config->metric_only) {
384 nl = new_line_metric;
385 if (config->csv_output)
386 pm = print_metric_only_csv;
387 else
388 pm = print_metric_only;
389 } else
390 nl = new_line_std;
391
392 if (config->csv_output && !config->metric_only) {
393 static int aggr_fields[] = {
394 [AGGR_GLOBAL] = 0,
395 [AGGR_THREAD] = 1,
396 [AGGR_NONE] = 1,
397 [AGGR_SOCKET] = 2,
398 [AGGR_CORE] = 2,
399 };
400
401 pm = print_metric_csv;
402 nl = new_line_csv;
403 os.nfields = 3;
404 os.nfields += aggr_fields[config->aggr_mode];
405 if (counter->cgrp)
406 os.nfields++;
407 }
408 if (run == 0 || ena == 0 || counter->counts->scaled == -1) {
409 if (config->metric_only) {
410 pm(config, &os, NULL, "", "", 0);
411 return;
412 }
413 aggr_printout(config, counter, id, nr);
414
415 fprintf(config->output, "%*s%s",
416 config->csv_output ? 0 : 18,
417 counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED,
418 config->csv_sep);
419
420 if (counter->supported) {
421 config->print_free_counters_hint = 1;
422 if (is_mixed_hw_group(counter))
423 config->print_mixed_hw_group_error = 1;
424 }
425
426 fprintf(config->output, "%-*s%s",
427 config->csv_output ? 0 : config->unit_width,
428 counter->unit, config->csv_sep);
429
430 fprintf(config->output, "%*s",
431 config->csv_output ? 0 : -25,
432 perf_evsel__name(counter));
433
434 if (counter->cgrp)
435 fprintf(config->output, "%s%s",
436 config->csv_sep, counter->cgrp->name);
437
438 if (!config->csv_output)
439 pm(config, &os, NULL, NULL, "", 0);
440 print_noise(config, counter, noise);
441 print_running(config, run, ena);
442 if (config->csv_output)
443 pm(config, &os, NULL, NULL, "", 0);
444 return;
445 }
446
447 if (!config->metric_only)
448 abs_printout(config, id, nr, counter, uval);
449
450 out.print_metric = pm;
451 out.new_line = nl;
452 out.ctx = &os;
453 out.force_header = false;
454
455 if (config->csv_output && !config->metric_only) {
456 print_noise(config, counter, noise);
457 print_running(config, run, ena);
458 }
459
460 perf_stat__print_shadow_stats(config, counter, uval,
461 first_shadow_cpu(config, counter, id),
462 &out, &config->metric_events, st);
463 if (!config->csv_output && !config->metric_only) {
464 print_noise(config, counter, noise);
465 print_running(config, run, ena);
466 }
467}
468
469static void aggr_update_shadow(struct perf_stat_config *config,
470 struct perf_evlist *evlist)
471{
472 int cpu, s2, id, s;
473 u64 val;
474 struct perf_evsel *counter;
475
476 for (s = 0; s < config->aggr_map->nr; s++) {
477 id = config->aggr_map->map[s];
478 evlist__for_each_entry(evlist, counter) {
479 val = 0;
480 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
481 s2 = config->aggr_get_id(config, evlist->cpus, cpu);
482 if (s2 != id)
483 continue;
484 val += perf_counts(counter->counts, cpu, 0)->val;
485 }
486 perf_stat__update_shadow_stats(counter, val,
487 first_shadow_cpu(config, counter, id),
488 &rt_stat);
489 }
490 }
491}
492
493static void uniquify_event_name(struct perf_evsel *counter)
494{
495 char *new_name;
496 char *config;
497
498 if (counter->uniquified_name ||
499 !counter->pmu_name || !strncmp(counter->name, counter->pmu_name,
500 strlen(counter->pmu_name)))
501 return;
502
503 config = strchr(counter->name, '/');
504 if (config) {
505 if (asprintf(&new_name,
506 "%s%s", counter->pmu_name, config) > 0) {
507 free(counter->name);
508 counter->name = new_name;
509 }
510 } else {
511 if (asprintf(&new_name,
512 "%s [%s]", counter->name, counter->pmu_name) > 0) {
513 free(counter->name);
514 counter->name = new_name;
515 }
516 }
517
518 counter->uniquified_name = true;
519}
520
521static void collect_all_aliases(struct perf_stat_config *config, struct perf_evsel *counter,
522 void (*cb)(struct perf_stat_config *config, struct perf_evsel *counter, void *data,
523 bool first),
524 void *data)
525{
526 struct perf_evlist *evlist = counter->evlist;
527 struct perf_evsel *alias;
528
529 alias = list_prepare_entry(counter, &(evlist->entries), node);
530 list_for_each_entry_continue (alias, &evlist->entries, node) {
531 if (strcmp(perf_evsel__name(alias), perf_evsel__name(counter)) ||
532 alias->scale != counter->scale ||
533 alias->cgrp != counter->cgrp ||
534 strcmp(alias->unit, counter->unit) ||
535 perf_evsel__is_clock(alias) != perf_evsel__is_clock(counter))
536 break;
537 alias->merged_stat = true;
538 cb(config, alias, data, false);
539 }
540}
541
542static bool collect_data(struct perf_stat_config *config, struct perf_evsel *counter,
543 void (*cb)(struct perf_stat_config *config, struct perf_evsel *counter, void *data,
544 bool first),
545 void *data)
546{
547 if (counter->merged_stat)
548 return false;
549 cb(config, counter, data, true);
550 if (config->no_merge)
551 uniquify_event_name(counter);
552 else if (counter->auto_merge_stats)
553 collect_all_aliases(config, counter, cb, data);
554 return true;
555}
556
557struct aggr_data {
558 u64 ena, run, val;
559 int id;
560 int nr;
561 int cpu;
562};
563
564static void aggr_cb(struct perf_stat_config *config,
565 struct perf_evsel *counter, void *data, bool first)
566{
567 struct aggr_data *ad = data;
568 int cpu, s2;
569
570 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
571 struct perf_counts_values *counts;
572
573 s2 = config->aggr_get_id(config, perf_evsel__cpus(counter), cpu);
574 if (s2 != ad->id)
575 continue;
576 if (first)
577 ad->nr++;
578 counts = perf_counts(counter->counts, cpu, 0);
579 /*
580 * When any result is bad, make them all to give
581 * consistent output in interval mode.
582 */
583 if (counts->ena == 0 || counts->run == 0 ||
584 counter->counts->scaled == -1) {
585 ad->ena = 0;
586 ad->run = 0;
587 break;
588 }
589 ad->val += counts->val;
590 ad->ena += counts->ena;
591 ad->run += counts->run;
592 }
593}
594
595static void print_aggr(struct perf_stat_config *config,
596 struct perf_evlist *evlist,
597 char *prefix)
598{
599 bool metric_only = config->metric_only;
600 FILE *output = config->output;
601 struct perf_evsel *counter;
602 int s, id, nr;
603 double uval;
604 u64 ena, run, val;
605 bool first;
606
607 if (!(config->aggr_map || config->aggr_get_id))
608 return;
609
610 aggr_update_shadow(config, evlist);
611
612 /*
613 * With metric_only everything is on a single line.
614 * Without each counter has its own line.
615 */
616 for (s = 0; s < config->aggr_map->nr; s++) {
617 struct aggr_data ad;
618 if (prefix && metric_only)
619 fprintf(output, "%s", prefix);
620
621 ad.id = id = config->aggr_map->map[s];
622 first = true;
623 evlist__for_each_entry(evlist, counter) {
624 if (is_duration_time(counter))
625 continue;
626
627 ad.val = ad.ena = ad.run = 0;
628 ad.nr = 0;
629 if (!collect_data(config, counter, aggr_cb, &ad))
630 continue;
631 nr = ad.nr;
632 ena = ad.ena;
633 run = ad.run;
634 val = ad.val;
635 if (first && metric_only) {
636 first = false;
637 aggr_printout(config, counter, id, nr);
638 }
639 if (prefix && !metric_only)
640 fprintf(output, "%s", prefix);
641
642 uval = val * counter->scale;
643 printout(config, id, nr, counter, uval, prefix,
644 run, ena, 1.0, &rt_stat);
645 if (!metric_only)
646 fputc('\n', output);
647 }
648 if (metric_only)
649 fputc('\n', output);
650 }
651}
652
653static int cmp_val(const void *a, const void *b)
654{
655 return ((struct perf_aggr_thread_value *)b)->val -
656 ((struct perf_aggr_thread_value *)a)->val;
657}
658
659static struct perf_aggr_thread_value *sort_aggr_thread(
660 struct perf_evsel *counter,
661 int nthreads, int ncpus,
662 int *ret,
663 struct target *_target)
664{
665 int cpu, thread, i = 0;
666 double uval;
667 struct perf_aggr_thread_value *buf;
668
669 buf = calloc(nthreads, sizeof(struct perf_aggr_thread_value));
670 if (!buf)
671 return NULL;
672
673 for (thread = 0; thread < nthreads; thread++) {
674 u64 ena = 0, run = 0, val = 0;
675
676 for (cpu = 0; cpu < ncpus; cpu++) {
677 val += perf_counts(counter->counts, cpu, thread)->val;
678 ena += perf_counts(counter->counts, cpu, thread)->ena;
679 run += perf_counts(counter->counts, cpu, thread)->run;
680 }
681
682 uval = val * counter->scale;
683
684 /*
685 * Skip value 0 when enabling --per-thread globally,
686 * otherwise too many 0 output.
687 */
688 if (uval == 0.0 && target__has_per_thread(_target))
689 continue;
690
691 buf[i].counter = counter;
692 buf[i].id = thread;
693 buf[i].uval = uval;
694 buf[i].val = val;
695 buf[i].run = run;
696 buf[i].ena = ena;
697 i++;
698 }
699
700 qsort(buf, i, sizeof(struct perf_aggr_thread_value), cmp_val);
701
702 if (ret)
703 *ret = i;
704
705 return buf;
706}
707
708static void print_aggr_thread(struct perf_stat_config *config,
709 struct target *_target,
710 struct perf_evsel *counter, char *prefix)
711{
712 FILE *output = config->output;
713 int nthreads = thread_map__nr(counter->threads);
714 int ncpus = cpu_map__nr(counter->cpus);
715 int thread, sorted_threads, id;
716 struct perf_aggr_thread_value *buf;
717
718 buf = sort_aggr_thread(counter, nthreads, ncpus, &sorted_threads, _target);
719 if (!buf) {
720 perror("cannot sort aggr thread");
721 return;
722 }
723
724 for (thread = 0; thread < sorted_threads; thread++) {
725 if (prefix)
726 fprintf(output, "%s", prefix);
727
728 id = buf[thread].id;
729 if (config->stats)
730 printout(config, id, 0, buf[thread].counter, buf[thread].uval,
731 prefix, buf[thread].run, buf[thread].ena, 1.0,
732 &config->stats[id]);
733 else
734 printout(config, id, 0, buf[thread].counter, buf[thread].uval,
735 prefix, buf[thread].run, buf[thread].ena, 1.0,
736 &rt_stat);
737 fputc('\n', output);
738 }
739
740 free(buf);
741}
742
743struct caggr_data {
744 double avg, avg_enabled, avg_running;
745};
746
747static void counter_aggr_cb(struct perf_stat_config *config __maybe_unused,
748 struct perf_evsel *counter, void *data,
749 bool first __maybe_unused)
750{
751 struct caggr_data *cd = data;
752 struct perf_stat_evsel *ps = counter->stats;
753
754 cd->avg += avg_stats(&ps->res_stats[0]);
755 cd->avg_enabled += avg_stats(&ps->res_stats[1]);
756 cd->avg_running += avg_stats(&ps->res_stats[2]);
757}
758
759/*
760 * Print out the results of a single counter:
761 * aggregated counts in system-wide mode
762 */
763static void print_counter_aggr(struct perf_stat_config *config,
764 struct perf_evsel *counter, char *prefix)
765{
766 bool metric_only = config->metric_only;
767 FILE *output = config->output;
768 double uval;
769 struct caggr_data cd = { .avg = 0.0 };
770
771 if (!collect_data(config, counter, counter_aggr_cb, &cd))
772 return;
773
774 if (prefix && !metric_only)
775 fprintf(output, "%s", prefix);
776
777 uval = cd.avg * counter->scale;
778 printout(config, -1, 0, counter, uval, prefix, cd.avg_running, cd.avg_enabled,
779 cd.avg, &rt_stat);
780 if (!metric_only)
781 fprintf(output, "\n");
782}
783
784static void counter_cb(struct perf_stat_config *config __maybe_unused,
785 struct perf_evsel *counter, void *data,
786 bool first __maybe_unused)
787{
788 struct aggr_data *ad = data;
789
790 ad->val += perf_counts(counter->counts, ad->cpu, 0)->val;
791 ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena;
792 ad->run += perf_counts(counter->counts, ad->cpu, 0)->run;
793}
794
795/*
796 * Print out the results of a single counter:
797 * does not use aggregated count in system-wide
798 */
799static void print_counter(struct perf_stat_config *config,
800 struct perf_evsel *counter, char *prefix)
801{
802 FILE *output = config->output;
803 u64 ena, run, val;
804 double uval;
805 int cpu;
806
807 for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
808 struct aggr_data ad = { .cpu = cpu };
809
810 if (!collect_data(config, counter, counter_cb, &ad))
811 return;
812 val = ad.val;
813 ena = ad.ena;
814 run = ad.run;
815
816 if (prefix)
817 fprintf(output, "%s", prefix);
818
819 uval = val * counter->scale;
820 printout(config, cpu, 0, counter, uval, prefix, run, ena, 1.0,
821 &rt_stat);
822
823 fputc('\n', output);
824 }
825}
826
827static void print_no_aggr_metric(struct perf_stat_config *config,
828 struct perf_evlist *evlist,
829 char *prefix)
830{
831 int cpu;
832 int nrcpus = 0;
833 struct perf_evsel *counter;
834 u64 ena, run, val;
835 double uval;
836
837 nrcpus = evlist->cpus->nr;
838 for (cpu = 0; cpu < nrcpus; cpu++) {
839 bool first = true;
840
841 if (prefix)
842 fputs(prefix, config->output);
843 evlist__for_each_entry(evlist, counter) {
844 if (is_duration_time(counter))
845 continue;
846 if (first) {
847 aggr_printout(config, counter, cpu, 0);
848 first = false;
849 }
850 val = perf_counts(counter->counts, cpu, 0)->val;
851 ena = perf_counts(counter->counts, cpu, 0)->ena;
852 run = perf_counts(counter->counts, cpu, 0)->run;
853
854 uval = val * counter->scale;
855 printout(config, cpu, 0, counter, uval, prefix, run, ena, 1.0,
856 &rt_stat);
857 }
858 fputc('\n', config->output);
859 }
860}
861
862static int aggr_header_lens[] = {
863 [AGGR_CORE] = 18,
864 [AGGR_SOCKET] = 12,
865 [AGGR_NONE] = 6,
866 [AGGR_THREAD] = 24,
867 [AGGR_GLOBAL] = 0,
868};
869
870static const char *aggr_header_csv[] = {
871 [AGGR_CORE] = "core,cpus,",
872 [AGGR_SOCKET] = "socket,cpus",
873 [AGGR_NONE] = "cpu,",
874 [AGGR_THREAD] = "comm-pid,",
875 [AGGR_GLOBAL] = ""
876};
877
878static void print_metric_headers(struct perf_stat_config *config,
879 struct perf_evlist *evlist,
880 const char *prefix, bool no_indent)
881{
882 struct perf_stat_output_ctx out;
883 struct perf_evsel *counter;
884 struct outstate os = {
885 .fh = config->output
886 };
887
888 if (prefix)
889 fprintf(config->output, "%s", prefix);
890
891 if (!config->csv_output && !no_indent)
892 fprintf(config->output, "%*s",
893 aggr_header_lens[config->aggr_mode], "");
894 if (config->csv_output) {
895 if (config->interval)
896 fputs("time,", config->output);
897 fputs(aggr_header_csv[config->aggr_mode], config->output);
898 }
899
900 /* Print metrics headers only */
901 evlist__for_each_entry(evlist, counter) {
902 if (is_duration_time(counter))
903 continue;
904 os.evsel = counter;
905 out.ctx = &os;
906 out.print_metric = print_metric_header;
907 out.new_line = new_line_metric;
908 out.force_header = true;
909 os.evsel = counter;
910 perf_stat__print_shadow_stats(config, counter, 0,
911 0,
912 &out,
913 &config->metric_events,
914 &rt_stat);
915 }
916 fputc('\n', config->output);
917}
918
919static void print_interval(struct perf_stat_config *config,
920 struct perf_evlist *evlist,
921 char *prefix, struct timespec *ts)
922{
923 bool metric_only = config->metric_only;
924 unsigned int unit_width = config->unit_width;
925 FILE *output = config->output;
926 static int num_print_interval;
927
928 if (config->interval_clear)
929 puts(CONSOLE_CLEAR);
930
931 sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, config->csv_sep);
932
933 if ((num_print_interval == 0 && !config->csv_output) || config->interval_clear) {
934 switch (config->aggr_mode) {
935 case AGGR_SOCKET:
936 fprintf(output, "# time socket cpus");
937 if (!metric_only)
938 fprintf(output, " counts %*s events\n", unit_width, "unit");
939 break;
940 case AGGR_CORE:
941 fprintf(output, "# time core cpus");
942 if (!metric_only)
943 fprintf(output, " counts %*s events\n", unit_width, "unit");
944 break;
945 case AGGR_NONE:
946 fprintf(output, "# time CPU ");
947 if (!metric_only)
948 fprintf(output, " counts %*s events\n", unit_width, "unit");
949 break;
950 case AGGR_THREAD:
951 fprintf(output, "# time comm-pid");
952 if (!metric_only)
953 fprintf(output, " counts %*s events\n", unit_width, "unit");
954 break;
955 case AGGR_GLOBAL:
956 default:
957 fprintf(output, "# time");
958 if (!metric_only)
959 fprintf(output, " counts %*s events\n", unit_width, "unit");
960 case AGGR_UNSET:
961 break;
962 }
963 }
964
965 if ((num_print_interval == 0 || config->interval_clear) && metric_only)
966 print_metric_headers(config, evlist, " ", true);
967 if (++num_print_interval == 25)
968 num_print_interval = 0;
969}
970
971static void print_header(struct perf_stat_config *config,
972 struct target *_target,
973 int argc, const char **argv)
974{
975 FILE *output = config->output;
976 int i;
977
978 fflush(stdout);
979
980 if (!config->csv_output) {
981 fprintf(output, "\n");
982 fprintf(output, " Performance counter stats for ");
983 if (_target->system_wide)
984 fprintf(output, "\'system wide");
985 else if (_target->cpu_list)
986 fprintf(output, "\'CPU(s) %s", _target->cpu_list);
987 else if (!target__has_task(_target)) {
988 fprintf(output, "\'%s", argv ? argv[0] : "pipe");
989 for (i = 1; argv && (i < argc); i++)
990 fprintf(output, " %s", argv[i]);
991 } else if (_target->pid)
992 fprintf(output, "process id \'%s", _target->pid);
993 else
994 fprintf(output, "thread id \'%s", _target->tid);
995
996 fprintf(output, "\'");
997 if (config->run_count > 1)
998 fprintf(output, " (%d runs)", config->run_count);
999 fprintf(output, ":\n\n");
1000 }
1001}
1002
1003static int get_precision(double num)
1004{
1005 if (num > 1)
1006 return 0;
1007
1008 return lround(ceil(-log10(num)));
1009}
1010
1011static void print_table(struct perf_stat_config *config,
1012 FILE *output, int precision, double avg)
1013{
1014 char tmp[64];
1015 int idx, indent = 0;
1016
1017 scnprintf(tmp, 64, " %17.*f", precision, avg);
1018 while (tmp[indent] == ' ')
1019 indent++;
1020
1021 fprintf(output, "%*s# Table of individual measurements:\n", indent, "");
1022
1023 for (idx = 0; idx < config->run_count; idx++) {
1024 double run = (double) config->walltime_run[idx] / NSEC_PER_SEC;
1025 int h, n = 1 + abs((int) (100.0 * (run - avg)/run) / 5);
1026
1027 fprintf(output, " %17.*f (%+.*f) ",
1028 precision, run, precision, run - avg);
1029
1030 for (h = 0; h < n; h++)
1031 fprintf(output, "#");
1032
1033 fprintf(output, "\n");
1034 }
1035
1036 fprintf(output, "\n%*s# Final result:\n", indent, "");
1037}
1038
1039static double timeval2double(struct timeval *t)
1040{
1041 return t->tv_sec + (double) t->tv_usec/USEC_PER_SEC;
1042}
1043
1044static void print_footer(struct perf_stat_config *config)
1045{
1046 double avg = avg_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC;
1047 FILE *output = config->output;
1048 int n;
1049
1050 if (!config->null_run)
1051 fprintf(output, "\n");
1052
1053 if (config->run_count == 1) {
1054 fprintf(output, " %17.9f seconds time elapsed", avg);
1055
1056 if (config->ru_display) {
1057 double ru_utime = timeval2double(&config->ru_data.ru_utime);
1058 double ru_stime = timeval2double(&config->ru_data.ru_stime);
1059
1060 fprintf(output, "\n\n");
1061 fprintf(output, " %17.9f seconds user\n", ru_utime);
1062 fprintf(output, " %17.9f seconds sys\n", ru_stime);
1063 }
1064 } else {
1065 double sd = stddev_stats(config->walltime_nsecs_stats) / NSEC_PER_SEC;
1066 /*
1067 * Display at most 2 more significant
1068 * digits than the stddev inaccuracy.
1069 */
1070 int precision = get_precision(sd) + 2;
1071
1072 if (config->walltime_run_table)
1073 print_table(config, output, precision, avg);
1074
1075 fprintf(output, " %17.*f +- %.*f seconds time elapsed",
1076 precision, avg, precision, sd);
1077
1078 print_noise_pct(config, sd, avg);
1079 }
1080 fprintf(output, "\n\n");
1081
1082 if (config->print_free_counters_hint &&
1083 sysctl__read_int("kernel/nmi_watchdog", &n) >= 0 &&
1084 n > 0)
1085 fprintf(output,
1086"Some events weren't counted. Try disabling the NMI watchdog:\n"
1087" echo 0 > /proc/sys/kernel/nmi_watchdog\n"
1088" perf stat ...\n"
1089" echo 1 > /proc/sys/kernel/nmi_watchdog\n");
1090
1091 if (config->print_mixed_hw_group_error)
1092 fprintf(output,
1093 "The events in group usually have to be from "
1094 "the same PMU. Try reorganizing the group.\n");
1095}
1096
1097void
1098perf_evlist__print_counters(struct perf_evlist *evlist,
1099 struct perf_stat_config *config,
1100 struct target *_target,
1101 struct timespec *ts,
1102 int argc, const char **argv)
1103{
1104 bool metric_only = config->metric_only;
1105 int interval = config->interval;
1106 struct perf_evsel *counter;
1107 char buf[64], *prefix = NULL;
1108
1109 if (interval)
1110 print_interval(config, evlist, prefix = buf, ts);
1111 else
1112 print_header(config, _target, argc, argv);
1113
1114 if (metric_only) {
1115 static int num_print_iv;
1116
1117 if (num_print_iv == 0 && !interval)
1118 print_metric_headers(config, evlist, prefix, false);
1119 if (num_print_iv++ == 25)
1120 num_print_iv = 0;
1121 if (config->aggr_mode == AGGR_GLOBAL && prefix)
1122 fprintf(config->output, "%s", prefix);
1123 }
1124
1125 switch (config->aggr_mode) {
1126 case AGGR_CORE:
1127 case AGGR_SOCKET:
1128 print_aggr(config, evlist, prefix);
1129 break;
1130 case AGGR_THREAD:
1131 evlist__for_each_entry(evlist, counter) {
1132 if (is_duration_time(counter))
1133 continue;
1134 print_aggr_thread(config, _target, counter, prefix);
1135 }
1136 break;
1137 case AGGR_GLOBAL:
1138 evlist__for_each_entry(evlist, counter) {
1139 if (is_duration_time(counter))
1140 continue;
1141 print_counter_aggr(config, counter, prefix);
1142 }
1143 if (metric_only)
1144 fputc('\n', config->output);
1145 break;
1146 case AGGR_NONE:
1147 if (metric_only)
1148 print_no_aggr_metric(config, evlist, prefix);
1149 else {
1150 evlist__for_each_entry(evlist, counter) {
1151 if (is_duration_time(counter))
1152 continue;
1153 print_counter(config, counter, prefix);
1154 }
1155 }
1156 break;
1157 case AGGR_UNSET:
1158 default:
1159 break;
1160 }
1161
1162 if (!interval && !config->csv_output)
1163 print_footer(config);
1164
1165 fflush(config->output);
1166}
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 99990f5f2512..8ad32763cfff 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -410,7 +410,8 @@ static double runtime_stat_n(struct runtime_stat *st,
410 return v->stats.n; 410 return v->stats.n;
411} 411}
412 412
413static void print_stalled_cycles_frontend(int cpu, 413static void print_stalled_cycles_frontend(struct perf_stat_config *config,
414 int cpu,
414 struct perf_evsel *evsel, double avg, 415 struct perf_evsel *evsel, double avg,
415 struct perf_stat_output_ctx *out, 416 struct perf_stat_output_ctx *out,
416 struct runtime_stat *st) 417 struct runtime_stat *st)
@@ -427,13 +428,14 @@ static void print_stalled_cycles_frontend(int cpu,
427 color = get_ratio_color(GRC_STALLED_CYCLES_FE, ratio); 428 color = get_ratio_color(GRC_STALLED_CYCLES_FE, ratio);
428 429
429 if (ratio) 430 if (ratio)
430 out->print_metric(out->ctx, color, "%7.2f%%", "frontend cycles idle", 431 out->print_metric(config, out->ctx, color, "%7.2f%%", "frontend cycles idle",
431 ratio); 432 ratio);
432 else 433 else
433 out->print_metric(out->ctx, NULL, NULL, "frontend cycles idle", 0); 434 out->print_metric(config, out->ctx, NULL, NULL, "frontend cycles idle", 0);
434} 435}
435 436
436static void print_stalled_cycles_backend(int cpu, 437static void print_stalled_cycles_backend(struct perf_stat_config *config,
438 int cpu,
437 struct perf_evsel *evsel, double avg, 439 struct perf_evsel *evsel, double avg,
438 struct perf_stat_output_ctx *out, 440 struct perf_stat_output_ctx *out,
439 struct runtime_stat *st) 441 struct runtime_stat *st)
@@ -449,10 +451,11 @@ static void print_stalled_cycles_backend(int cpu,
449 451
450 color = get_ratio_color(GRC_STALLED_CYCLES_BE, ratio); 452 color = get_ratio_color(GRC_STALLED_CYCLES_BE, ratio);
451 453
452 out->print_metric(out->ctx, color, "%7.2f%%", "backend cycles idle", ratio); 454 out->print_metric(config, out->ctx, color, "%7.2f%%", "backend cycles idle", ratio);
453} 455}
454 456
455static void print_branch_misses(int cpu, 457static void print_branch_misses(struct perf_stat_config *config,
458 int cpu,
456 struct perf_evsel *evsel, 459 struct perf_evsel *evsel,
457 double avg, 460 double avg,
458 struct perf_stat_output_ctx *out, 461 struct perf_stat_output_ctx *out,
@@ -469,10 +472,11 @@ static void print_branch_misses(int cpu,
469 472
470 color = get_ratio_color(GRC_CACHE_MISSES, ratio); 473 color = get_ratio_color(GRC_CACHE_MISSES, ratio);
471 474
472 out->print_metric(out->ctx, color, "%7.2f%%", "of all branches", ratio); 475 out->print_metric(config, out->ctx, color, "%7.2f%%", "of all branches", ratio);
473} 476}
474 477
475static void print_l1_dcache_misses(int cpu, 478static void print_l1_dcache_misses(struct perf_stat_config *config,
479 int cpu,
476 struct perf_evsel *evsel, 480 struct perf_evsel *evsel,
477 double avg, 481 double avg,
478 struct perf_stat_output_ctx *out, 482 struct perf_stat_output_ctx *out,
@@ -490,10 +494,11 @@ static void print_l1_dcache_misses(int cpu,
490 494
491 color = get_ratio_color(GRC_CACHE_MISSES, ratio); 495 color = get_ratio_color(GRC_CACHE_MISSES, ratio);
492 496
493 out->print_metric(out->ctx, color, "%7.2f%%", "of all L1-dcache hits", ratio); 497 out->print_metric(config, out->ctx, color, "%7.2f%%", "of all L1-dcache hits", ratio);
494} 498}
495 499
496static void print_l1_icache_misses(int cpu, 500static void print_l1_icache_misses(struct perf_stat_config *config,
501 int cpu,
497 struct perf_evsel *evsel, 502 struct perf_evsel *evsel,
498 double avg, 503 double avg,
499 struct perf_stat_output_ctx *out, 504 struct perf_stat_output_ctx *out,
@@ -510,10 +515,11 @@ static void print_l1_icache_misses(int cpu,
510 ratio = avg / total * 100.0; 515 ratio = avg / total * 100.0;
511 516
512 color = get_ratio_color(GRC_CACHE_MISSES, ratio); 517 color = get_ratio_color(GRC_CACHE_MISSES, ratio);
513 out->print_metric(out->ctx, color, "%7.2f%%", "of all L1-icache hits", ratio); 518 out->print_metric(config, out->ctx, color, "%7.2f%%", "of all L1-icache hits", ratio);
514} 519}
515 520
516static void print_dtlb_cache_misses(int cpu, 521static void print_dtlb_cache_misses(struct perf_stat_config *config,
522 int cpu,
517 struct perf_evsel *evsel, 523 struct perf_evsel *evsel,
518 double avg, 524 double avg,
519 struct perf_stat_output_ctx *out, 525 struct perf_stat_output_ctx *out,
@@ -529,10 +535,11 @@ static void print_dtlb_cache_misses(int cpu,
529 ratio = avg / total * 100.0; 535 ratio = avg / total * 100.0;
530 536
531 color = get_ratio_color(GRC_CACHE_MISSES, ratio); 537 color = get_ratio_color(GRC_CACHE_MISSES, ratio);
532 out->print_metric(out->ctx, color, "%7.2f%%", "of all dTLB cache hits", ratio); 538 out->print_metric(config, out->ctx, color, "%7.2f%%", "of all dTLB cache hits", ratio);
533} 539}
534 540
535static void print_itlb_cache_misses(int cpu, 541static void print_itlb_cache_misses(struct perf_stat_config *config,
542 int cpu,
536 struct perf_evsel *evsel, 543 struct perf_evsel *evsel,
537 double avg, 544 double avg,
538 struct perf_stat_output_ctx *out, 545 struct perf_stat_output_ctx *out,
@@ -548,10 +555,11 @@ static void print_itlb_cache_misses(int cpu,
548 ratio = avg / total * 100.0; 555 ratio = avg / total * 100.0;
549 556
550 color = get_ratio_color(GRC_CACHE_MISSES, ratio); 557 color = get_ratio_color(GRC_CACHE_MISSES, ratio);
551 out->print_metric(out->ctx, color, "%7.2f%%", "of all iTLB cache hits", ratio); 558 out->print_metric(config, out->ctx, color, "%7.2f%%", "of all iTLB cache hits", ratio);
552} 559}
553 560
554static void print_ll_cache_misses(int cpu, 561static void print_ll_cache_misses(struct perf_stat_config *config,
562 int cpu,
555 struct perf_evsel *evsel, 563 struct perf_evsel *evsel,
556 double avg, 564 double avg,
557 struct perf_stat_output_ctx *out, 565 struct perf_stat_output_ctx *out,
@@ -567,7 +575,7 @@ static void print_ll_cache_misses(int cpu,
567 ratio = avg / total * 100.0; 575 ratio = avg / total * 100.0;
568 576
569 color = get_ratio_color(GRC_CACHE_MISSES, ratio); 577 color = get_ratio_color(GRC_CACHE_MISSES, ratio);
570 out->print_metric(out->ctx, color, "%7.2f%%", "of all LL-cache hits", ratio); 578 out->print_metric(config, out->ctx, color, "%7.2f%%", "of all LL-cache hits", ratio);
571} 579}
572 580
573/* 581/*
@@ -674,7 +682,8 @@ static double td_be_bound(int ctx, int cpu, struct runtime_stat *st)
674 return sanitize_val(1.0 - sum); 682 return sanitize_val(1.0 - sum);
675} 683}
676 684
677static void print_smi_cost(int cpu, struct perf_evsel *evsel, 685static void print_smi_cost(struct perf_stat_config *config,
686 int cpu, struct perf_evsel *evsel,
678 struct perf_stat_output_ctx *out, 687 struct perf_stat_output_ctx *out,
679 struct runtime_stat *st) 688 struct runtime_stat *st)
680{ 689{
@@ -694,11 +703,12 @@ static void print_smi_cost(int cpu, struct perf_evsel *evsel,
694 703
695 if (cost > 10) 704 if (cost > 10)
696 color = PERF_COLOR_RED; 705 color = PERF_COLOR_RED;
697 out->print_metric(out->ctx, color, "%8.1f%%", "SMI cycles%", cost); 706 out->print_metric(config, out->ctx, color, "%8.1f%%", "SMI cycles%", cost);
698 out->print_metric(out->ctx, NULL, "%4.0f", "SMI#", smi_num); 707 out->print_metric(config, out->ctx, NULL, "%4.0f", "SMI#", smi_num);
699} 708}
700 709
701static void generic_metric(const char *metric_expr, 710static void generic_metric(struct perf_stat_config *config,
711 const char *metric_expr,
702 struct perf_evsel **metric_events, 712 struct perf_evsel **metric_events,
703 char *name, 713 char *name,
704 const char *metric_name, 714 const char *metric_name,
@@ -737,20 +747,21 @@ static void generic_metric(const char *metric_expr,
737 const char *p = metric_expr; 747 const char *p = metric_expr;
738 748
739 if (expr__parse(&ratio, &pctx, &p) == 0) 749 if (expr__parse(&ratio, &pctx, &p) == 0)
740 print_metric(ctxp, NULL, "%8.1f", 750 print_metric(config, ctxp, NULL, "%8.1f",
741 metric_name ? 751 metric_name ?
742 metric_name : 752 metric_name :
743 out->force_header ? name : "", 753 out->force_header ? name : "",
744 ratio); 754 ratio);
745 else 755 else
746 print_metric(ctxp, NULL, NULL, 756 print_metric(config, ctxp, NULL, NULL,
747 out->force_header ? 757 out->force_header ?
748 (metric_name ? metric_name : name) : "", 0); 758 (metric_name ? metric_name : name) : "", 0);
749 } else 759 } else
750 print_metric(ctxp, NULL, NULL, "", 0); 760 print_metric(config, ctxp, NULL, NULL, "", 0);
751} 761}
752 762
753void perf_stat__print_shadow_stats(struct perf_evsel *evsel, 763void perf_stat__print_shadow_stats(struct perf_stat_config *config,
764 struct perf_evsel *evsel,
754 double avg, int cpu, 765 double avg, int cpu,
755 struct perf_stat_output_ctx *out, 766 struct perf_stat_output_ctx *out,
756 struct rblist *metric_events, 767 struct rblist *metric_events,
@@ -769,10 +780,10 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
769 780
770 if (total) { 781 if (total) {
771 ratio = avg / total; 782 ratio = avg / total;
772 print_metric(ctxp, NULL, "%7.2f ", 783 print_metric(config, ctxp, NULL, "%7.2f ",
773 "insn per cycle", ratio); 784 "insn per cycle", ratio);
774 } else { 785 } else {
775 print_metric(ctxp, NULL, NULL, "insn per cycle", 0); 786 print_metric(config, ctxp, NULL, NULL, "insn per cycle", 0);
776 } 787 }
777 788
778 total = runtime_stat_avg(st, STAT_STALLED_CYCLES_FRONT, 789 total = runtime_stat_avg(st, STAT_STALLED_CYCLES_FRONT,
@@ -783,20 +794,20 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
783 ctx, cpu)); 794 ctx, cpu));
784 795
785 if (total && avg) { 796 if (total && avg) {
786 out->new_line(ctxp); 797 out->new_line(config, ctxp);
787 ratio = total / avg; 798 ratio = total / avg;
788 print_metric(ctxp, NULL, "%7.2f ", 799 print_metric(config, ctxp, NULL, "%7.2f ",
789 "stalled cycles per insn", 800 "stalled cycles per insn",
790 ratio); 801 ratio);
791 } else if (have_frontend_stalled) { 802 } else if (have_frontend_stalled) {
792 print_metric(ctxp, NULL, NULL, 803 print_metric(config, ctxp, NULL, NULL,
793 "stalled cycles per insn", 0); 804 "stalled cycles per insn", 0);
794 } 805 }
795 } else if (perf_evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES)) { 806 } else if (perf_evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES)) {
796 if (runtime_stat_n(st, STAT_BRANCHES, ctx, cpu) != 0) 807 if (runtime_stat_n(st, STAT_BRANCHES, ctx, cpu) != 0)
797 print_branch_misses(cpu, evsel, avg, out, st); 808 print_branch_misses(config, cpu, evsel, avg, out, st);
798 else 809 else
799 print_metric(ctxp, NULL, NULL, "of all branches", 0); 810 print_metric(config, ctxp, NULL, NULL, "of all branches", 0);
800 } else if ( 811 } else if (
801 evsel->attr.type == PERF_TYPE_HW_CACHE && 812 evsel->attr.type == PERF_TYPE_HW_CACHE &&
802 evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1D | 813 evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1D |
@@ -804,9 +815,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
804 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { 815 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) {
805 816
806 if (runtime_stat_n(st, STAT_L1_DCACHE, ctx, cpu) != 0) 817 if (runtime_stat_n(st, STAT_L1_DCACHE, ctx, cpu) != 0)
807 print_l1_dcache_misses(cpu, evsel, avg, out, st); 818 print_l1_dcache_misses(config, cpu, evsel, avg, out, st);
808 else 819 else
809 print_metric(ctxp, NULL, NULL, "of all L1-dcache hits", 0); 820 print_metric(config, ctxp, NULL, NULL, "of all L1-dcache hits", 0);
810 } else if ( 821 } else if (
811 evsel->attr.type == PERF_TYPE_HW_CACHE && 822 evsel->attr.type == PERF_TYPE_HW_CACHE &&
812 evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1I | 823 evsel->attr.config == ( PERF_COUNT_HW_CACHE_L1I |
@@ -814,9 +825,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
814 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { 825 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) {
815 826
816 if (runtime_stat_n(st, STAT_L1_ICACHE, ctx, cpu) != 0) 827 if (runtime_stat_n(st, STAT_L1_ICACHE, ctx, cpu) != 0)
817 print_l1_icache_misses(cpu, evsel, avg, out, st); 828 print_l1_icache_misses(config, cpu, evsel, avg, out, st);
818 else 829 else
819 print_metric(ctxp, NULL, NULL, "of all L1-icache hits", 0); 830 print_metric(config, ctxp, NULL, NULL, "of all L1-icache hits", 0);
820 } else if ( 831 } else if (
821 evsel->attr.type == PERF_TYPE_HW_CACHE && 832 evsel->attr.type == PERF_TYPE_HW_CACHE &&
822 evsel->attr.config == ( PERF_COUNT_HW_CACHE_DTLB | 833 evsel->attr.config == ( PERF_COUNT_HW_CACHE_DTLB |
@@ -824,9 +835,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
824 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { 835 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) {
825 836
826 if (runtime_stat_n(st, STAT_DTLB_CACHE, ctx, cpu) != 0) 837 if (runtime_stat_n(st, STAT_DTLB_CACHE, ctx, cpu) != 0)
827 print_dtlb_cache_misses(cpu, evsel, avg, out, st); 838 print_dtlb_cache_misses(config, cpu, evsel, avg, out, st);
828 else 839 else
829 print_metric(ctxp, NULL, NULL, "of all dTLB cache hits", 0); 840 print_metric(config, ctxp, NULL, NULL, "of all dTLB cache hits", 0);
830 } else if ( 841 } else if (
831 evsel->attr.type == PERF_TYPE_HW_CACHE && 842 evsel->attr.type == PERF_TYPE_HW_CACHE &&
832 evsel->attr.config == ( PERF_COUNT_HW_CACHE_ITLB | 843 evsel->attr.config == ( PERF_COUNT_HW_CACHE_ITLB |
@@ -834,9 +845,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
834 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { 845 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) {
835 846
836 if (runtime_stat_n(st, STAT_ITLB_CACHE, ctx, cpu) != 0) 847 if (runtime_stat_n(st, STAT_ITLB_CACHE, ctx, cpu) != 0)
837 print_itlb_cache_misses(cpu, evsel, avg, out, st); 848 print_itlb_cache_misses(config, cpu, evsel, avg, out, st);
838 else 849 else
839 print_metric(ctxp, NULL, NULL, "of all iTLB cache hits", 0); 850 print_metric(config, ctxp, NULL, NULL, "of all iTLB cache hits", 0);
840 } else if ( 851 } else if (
841 evsel->attr.type == PERF_TYPE_HW_CACHE && 852 evsel->attr.type == PERF_TYPE_HW_CACHE &&
842 evsel->attr.config == ( PERF_COUNT_HW_CACHE_LL | 853 evsel->attr.config == ( PERF_COUNT_HW_CACHE_LL |
@@ -844,9 +855,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
844 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { 855 ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) {
845 856
846 if (runtime_stat_n(st, STAT_LL_CACHE, ctx, cpu) != 0) 857 if (runtime_stat_n(st, STAT_LL_CACHE, ctx, cpu) != 0)
847 print_ll_cache_misses(cpu, evsel, avg, out, st); 858 print_ll_cache_misses(config, cpu, evsel, avg, out, st);
848 else 859 else
849 print_metric(ctxp, NULL, NULL, "of all LL-cache hits", 0); 860 print_metric(config, ctxp, NULL, NULL, "of all LL-cache hits", 0);
850 } else if (perf_evsel__match(evsel, HARDWARE, HW_CACHE_MISSES)) { 861 } else if (perf_evsel__match(evsel, HARDWARE, HW_CACHE_MISSES)) {
851 total = runtime_stat_avg(st, STAT_CACHEREFS, ctx, cpu); 862 total = runtime_stat_avg(st, STAT_CACHEREFS, ctx, cpu);
852 863
@@ -854,32 +865,32 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
854 ratio = avg * 100 / total; 865 ratio = avg * 100 / total;
855 866
856 if (runtime_stat_n(st, STAT_CACHEREFS, ctx, cpu) != 0) 867 if (runtime_stat_n(st, STAT_CACHEREFS, ctx, cpu) != 0)
857 print_metric(ctxp, NULL, "%8.3f %%", 868 print_metric(config, ctxp, NULL, "%8.3f %%",
858 "of all cache refs", ratio); 869 "of all cache refs", ratio);
859 else 870 else
860 print_metric(ctxp, NULL, NULL, "of all cache refs", 0); 871 print_metric(config, ctxp, NULL, NULL, "of all cache refs", 0);
861 } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) { 872 } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) {
862 print_stalled_cycles_frontend(cpu, evsel, avg, out, st); 873 print_stalled_cycles_frontend(config, cpu, evsel, avg, out, st);
863 } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_BACKEND)) { 874 } else if (perf_evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_BACKEND)) {
864 print_stalled_cycles_backend(cpu, evsel, avg, out, st); 875 print_stalled_cycles_backend(config, cpu, evsel, avg, out, st);
865 } else if (perf_evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) { 876 } else if (perf_evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) {
866 total = runtime_stat_avg(st, STAT_NSECS, 0, cpu); 877 total = runtime_stat_avg(st, STAT_NSECS, 0, cpu);
867 878
868 if (total) { 879 if (total) {
869 ratio = avg / total; 880 ratio = avg / total;
870 print_metric(ctxp, NULL, "%8.3f", "GHz", ratio); 881 print_metric(config, ctxp, NULL, "%8.3f", "GHz", ratio);
871 } else { 882 } else {
872 print_metric(ctxp, NULL, NULL, "Ghz", 0); 883 print_metric(config, ctxp, NULL, NULL, "Ghz", 0);
873 } 884 }
874 } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX)) { 885 } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX)) {
875 total = runtime_stat_avg(st, STAT_CYCLES, ctx, cpu); 886 total = runtime_stat_avg(st, STAT_CYCLES, ctx, cpu);
876 887
877 if (total) 888 if (total)
878 print_metric(ctxp, NULL, 889 print_metric(config, ctxp, NULL,
879 "%7.2f%%", "transactional cycles", 890 "%7.2f%%", "transactional cycles",
880 100.0 * (avg / total)); 891 100.0 * (avg / total));
881 else 892 else
882 print_metric(ctxp, NULL, NULL, "transactional cycles", 893 print_metric(config, ctxp, NULL, NULL, "transactional cycles",
883 0); 894 0);
884 } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX_CP)) { 895 } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX_CP)) {
885 total = runtime_stat_avg(st, STAT_CYCLES, ctx, cpu); 896 total = runtime_stat_avg(st, STAT_CYCLES, ctx, cpu);
@@ -888,10 +899,10 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
888 if (total2 < avg) 899 if (total2 < avg)
889 total2 = avg; 900 total2 = avg;
890 if (total) 901 if (total)
891 print_metric(ctxp, NULL, "%7.2f%%", "aborted cycles", 902 print_metric(config, ctxp, NULL, "%7.2f%%", "aborted cycles",
892 100.0 * ((total2-avg) / total)); 903 100.0 * ((total2-avg) / total));
893 else 904 else
894 print_metric(ctxp, NULL, NULL, "aborted cycles", 0); 905 print_metric(config, ctxp, NULL, NULL, "aborted cycles", 0);
895 } else if (perf_stat_evsel__is(evsel, TRANSACTION_START)) { 906 } else if (perf_stat_evsel__is(evsel, TRANSACTION_START)) {
896 total = runtime_stat_avg(st, STAT_CYCLES_IN_TX, 907 total = runtime_stat_avg(st, STAT_CYCLES_IN_TX,
897 ctx, cpu); 908 ctx, cpu);
@@ -900,10 +911,10 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
900 ratio = total / avg; 911 ratio = total / avg;
901 912
902 if (runtime_stat_n(st, STAT_CYCLES_IN_TX, ctx, cpu) != 0) 913 if (runtime_stat_n(st, STAT_CYCLES_IN_TX, ctx, cpu) != 0)
903 print_metric(ctxp, NULL, "%8.0f", 914 print_metric(config, ctxp, NULL, "%8.0f",
904 "cycles / transaction", ratio); 915 "cycles / transaction", ratio);
905 else 916 else
906 print_metric(ctxp, NULL, NULL, "cycles / transaction", 917 print_metric(config, ctxp, NULL, NULL, "cycles / transaction",
907 0); 918 0);
908 } else if (perf_stat_evsel__is(evsel, ELISION_START)) { 919 } else if (perf_stat_evsel__is(evsel, ELISION_START)) {
909 total = runtime_stat_avg(st, STAT_CYCLES_IN_TX, 920 total = runtime_stat_avg(st, STAT_CYCLES_IN_TX,
@@ -912,33 +923,33 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
912 if (avg) 923 if (avg)
913 ratio = total / avg; 924 ratio = total / avg;
914 925
915 print_metric(ctxp, NULL, "%8.0f", "cycles / elision", ratio); 926 print_metric(config, ctxp, NULL, "%8.0f", "cycles / elision", ratio);
916 } else if (perf_evsel__is_clock(evsel)) { 927 } else if (perf_evsel__is_clock(evsel)) {
917 if ((ratio = avg_stats(&walltime_nsecs_stats)) != 0) 928 if ((ratio = avg_stats(&walltime_nsecs_stats)) != 0)
918 print_metric(ctxp, NULL, "%8.3f", "CPUs utilized", 929 print_metric(config, ctxp, NULL, "%8.3f", "CPUs utilized",
919 avg / (ratio * evsel->scale)); 930 avg / (ratio * evsel->scale));
920 else 931 else
921 print_metric(ctxp, NULL, NULL, "CPUs utilized", 0); 932 print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0);
922 } else if (perf_stat_evsel__is(evsel, TOPDOWN_FETCH_BUBBLES)) { 933 } else if (perf_stat_evsel__is(evsel, TOPDOWN_FETCH_BUBBLES)) {
923 double fe_bound = td_fe_bound(ctx, cpu, st); 934 double fe_bound = td_fe_bound(ctx, cpu, st);
924 935
925 if (fe_bound > 0.2) 936 if (fe_bound > 0.2)
926 color = PERF_COLOR_RED; 937 color = PERF_COLOR_RED;
927 print_metric(ctxp, color, "%8.1f%%", "frontend bound", 938 print_metric(config, ctxp, color, "%8.1f%%", "frontend bound",
928 fe_bound * 100.); 939 fe_bound * 100.);
929 } else if (perf_stat_evsel__is(evsel, TOPDOWN_SLOTS_RETIRED)) { 940 } else if (perf_stat_evsel__is(evsel, TOPDOWN_SLOTS_RETIRED)) {
930 double retiring = td_retiring(ctx, cpu, st); 941 double retiring = td_retiring(ctx, cpu, st);
931 942
932 if (retiring > 0.7) 943 if (retiring > 0.7)
933 color = PERF_COLOR_GREEN; 944 color = PERF_COLOR_GREEN;
934 print_metric(ctxp, color, "%8.1f%%", "retiring", 945 print_metric(config, ctxp, color, "%8.1f%%", "retiring",
935 retiring * 100.); 946 retiring * 100.);
936 } else if (perf_stat_evsel__is(evsel, TOPDOWN_RECOVERY_BUBBLES)) { 947 } else if (perf_stat_evsel__is(evsel, TOPDOWN_RECOVERY_BUBBLES)) {
937 double bad_spec = td_bad_spec(ctx, cpu, st); 948 double bad_spec = td_bad_spec(ctx, cpu, st);
938 949
939 if (bad_spec > 0.1) 950 if (bad_spec > 0.1)
940 color = PERF_COLOR_RED; 951 color = PERF_COLOR_RED;
941 print_metric(ctxp, color, "%8.1f%%", "bad speculation", 952 print_metric(config, ctxp, color, "%8.1f%%", "bad speculation",
942 bad_spec * 100.); 953 bad_spec * 100.);
943 } else if (perf_stat_evsel__is(evsel, TOPDOWN_SLOTS_ISSUED)) { 954 } else if (perf_stat_evsel__is(evsel, TOPDOWN_SLOTS_ISSUED)) {
944 double be_bound = td_be_bound(ctx, cpu, st); 955 double be_bound = td_be_bound(ctx, cpu, st);
@@ -955,12 +966,12 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
955 if (be_bound > 0.2) 966 if (be_bound > 0.2)
956 color = PERF_COLOR_RED; 967 color = PERF_COLOR_RED;
957 if (td_total_slots(ctx, cpu, st) > 0) 968 if (td_total_slots(ctx, cpu, st) > 0)
958 print_metric(ctxp, color, "%8.1f%%", name, 969 print_metric(config, ctxp, color, "%8.1f%%", name,
959 be_bound * 100.); 970 be_bound * 100.);
960 else 971 else
961 print_metric(ctxp, NULL, NULL, name, 0); 972 print_metric(config, ctxp, NULL, NULL, name, 0);
962 } else if (evsel->metric_expr) { 973 } else if (evsel->metric_expr) {
963 generic_metric(evsel->metric_expr, evsel->metric_events, evsel->name, 974 generic_metric(config, evsel->metric_expr, evsel->metric_events, evsel->name,
964 evsel->metric_name, avg, cpu, out, st); 975 evsel->metric_name, avg, cpu, out, st);
965 } else if (runtime_stat_n(st, STAT_NSECS, 0, cpu) != 0) { 976 } else if (runtime_stat_n(st, STAT_NSECS, 0, cpu) != 0) {
966 char unit = 'M'; 977 char unit = 'M';
@@ -975,9 +986,9 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
975 unit = 'K'; 986 unit = 'K';
976 } 987 }
977 snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit); 988 snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit);
978 print_metric(ctxp, NULL, "%8.3f", unit_buf, ratio); 989 print_metric(config, ctxp, NULL, "%8.3f", unit_buf, ratio);
979 } else if (perf_stat_evsel__is(evsel, SMI_NUM)) { 990 } else if (perf_stat_evsel__is(evsel, SMI_NUM)) {
980 print_smi_cost(cpu, evsel, out, st); 991 print_smi_cost(config, cpu, evsel, out, st);
981 } else { 992 } else {
982 num = 0; 993 num = 0;
983 } 994 }
@@ -987,12 +998,12 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
987 998
988 list_for_each_entry (mexp, &me->head, nd) { 999 list_for_each_entry (mexp, &me->head, nd) {
989 if (num++ > 0) 1000 if (num++ > 0)
990 out->new_line(ctxp); 1001 out->new_line(config, ctxp);
991 generic_metric(mexp->metric_expr, mexp->metric_events, 1002 generic_metric(config, mexp->metric_expr, mexp->metric_events,
992 evsel->name, mexp->metric_name, 1003 evsel->name, mexp->metric_name,
993 avg, cpu, out, st); 1004 avg, cpu, out, st);
994 } 1005 }
995 } 1006 }
996 if (num == 0) 1007 if (num == 0)
997 print_metric(ctxp, NULL, NULL, NULL, 0); 1008 print_metric(config, ctxp, NULL, NULL, NULL, 0);
998} 1009}
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index a0061e0b0fad..4d40515307b8 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -374,9 +374,8 @@ int perf_stat_process_counter(struct perf_stat_config *config,
374 return 0; 374 return 0;
375} 375}
376 376
377int perf_event__process_stat_event(struct perf_tool *tool __maybe_unused, 377int perf_event__process_stat_event(struct perf_session *session,
378 union perf_event *event, 378 union perf_event *event)
379 struct perf_session *session)
380{ 379{
381 struct perf_counts_values count; 380 struct perf_counts_values count;
382 struct stat_event *st = &event->stat; 381 struct stat_event *st = &event->stat;
@@ -435,3 +434,98 @@ size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp)
435 434
436 return ret; 435 return ret;
437} 436}
437
438int create_perf_stat_counter(struct perf_evsel *evsel,
439 struct perf_stat_config *config,
440 struct target *target)
441{
442 struct perf_event_attr *attr = &evsel->attr;
443 struct perf_evsel *leader = evsel->leader;
444
445 if (config->scale) {
446 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
447 PERF_FORMAT_TOTAL_TIME_RUNNING;
448 }
449
450 /*
451 * The event is part of non trivial group, let's enable
452 * the group read (for leader) and ID retrieval for all
453 * members.
454 */
455 if (leader->nr_members > 1)
456 attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP;
457
458 attr->inherit = !config->no_inherit;
459
460 /*
461 * Some events get initialized with sample_(period/type) set,
462 * like tracepoints. Clear it up for counting.
463 */
464 attr->sample_period = 0;
465
466 if (config->identifier)
467 attr->sample_type = PERF_SAMPLE_IDENTIFIER;
468
469 /*
470 * Disabling all counters initially, they will be enabled
471 * either manually by us or by kernel via enable_on_exec
472 * set later.
473 */
474 if (perf_evsel__is_group_leader(evsel)) {
475 attr->disabled = 1;
476
477 /*
478 * In case of initial_delay we enable tracee
479 * events manually.
480 */
481 if (target__none(target) && !config->initial_delay)
482 attr->enable_on_exec = 1;
483 }
484
485 if (target__has_cpu(target) && !target__has_per_thread(target))
486 return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
487
488 return perf_evsel__open_per_thread(evsel, evsel->threads);
489}
490
491int perf_stat_synthesize_config(struct perf_stat_config *config,
492 struct perf_tool *tool,
493 struct perf_evlist *evlist,
494 perf_event__handler_t process,
495 bool attrs)
496{
497 int err;
498
499 if (attrs) {
500 err = perf_event__synthesize_attrs(tool, evlist, process);
501 if (err < 0) {
502 pr_err("Couldn't synthesize attrs.\n");
503 return err;
504 }
505 }
506
507 err = perf_event__synthesize_extra_attr(tool, evlist, process,
508 attrs);
509
510 err = perf_event__synthesize_thread_map2(tool, evlist->threads,
511 process, NULL);
512 if (err < 0) {
513 pr_err("Couldn't synthesize thread map.\n");
514 return err;
515 }
516
517 err = perf_event__synthesize_cpu_map(tool, evlist->cpus,
518 process, NULL);
519 if (err < 0) {
520 pr_err("Couldn't synthesize thread map.\n");
521 return err;
522 }
523
524 err = perf_event__synthesize_stat_config(tool, config, process, NULL);
525 if (err < 0) {
526 pr_err("Couldn't synthesize config.\n");
527 return err;
528 }
529
530 return 0;
531}
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 36efb986f7fc..2f9c9159a364 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -4,8 +4,14 @@
4 4
5#include <linux/types.h> 5#include <linux/types.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <sys/types.h>
8#include <sys/time.h>
9#include <sys/resource.h>
10#include <sys/wait.h>
7#include "xyarray.h" 11#include "xyarray.h"
8#include "rblist.h" 12#include "rblist.h"
13#include "perf.h"
14#include "event.h"
9 15
10struct stats { 16struct stats {
11 double n, mean, M2; 17 double n, mean, M2;
@@ -84,15 +90,42 @@ struct runtime_stat {
84 struct rblist value_list; 90 struct rblist value_list;
85}; 91};
86 92
93typedef int (*aggr_get_id_t)(struct perf_stat_config *config,
94 struct cpu_map *m, int cpu);
95
87struct perf_stat_config { 96struct perf_stat_config {
88 enum aggr_mode aggr_mode; 97 enum aggr_mode aggr_mode;
89 bool scale; 98 bool scale;
90 FILE *output; 99 bool no_inherit;
91 unsigned int interval; 100 bool identifier;
92 unsigned int timeout; 101 bool csv_output;
93 int times; 102 bool interval_clear;
94 struct runtime_stat *stats; 103 bool metric_only;
95 int stats_num; 104 bool null_run;
105 bool ru_display;
106 bool big_num;
107 bool no_merge;
108 bool walltime_run_table;
109 FILE *output;
110 unsigned int interval;
111 unsigned int timeout;
112 unsigned int initial_delay;
113 unsigned int unit_width;
114 unsigned int metric_only_len;
115 int times;
116 int run_count;
117 int print_free_counters_hint;
118 int print_mixed_hw_group_error;
119 struct runtime_stat *stats;
120 int stats_num;
121 const char *csv_sep;
122 struct stats *walltime_nsecs_stats;
123 struct rusage ru_data;
124 struct cpu_map *aggr_map;
125 aggr_get_id_t aggr_get_id;
126 struct cpu_map *cpus_aggr_map;
127 u64 *walltime_run;
128 struct rblist metric_events;
96}; 129};
97 130
98void update_stats(struct stats *stats, u64 val); 131void update_stats(struct stats *stats, u64 val);
@@ -130,9 +163,10 @@ bool __perf_evsel_stat__is(struct perf_evsel *evsel,
130extern struct runtime_stat rt_stat; 163extern struct runtime_stat rt_stat;
131extern struct stats walltime_nsecs_stats; 164extern struct stats walltime_nsecs_stats;
132 165
133typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit, 166typedef void (*print_metric_t)(struct perf_stat_config *config,
167 void *ctx, const char *color, const char *unit,
134 const char *fmt, double val); 168 const char *fmt, double val);
135typedef void (*new_line_t )(void *ctx); 169typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx);
136 170
137void runtime_stat__init(struct runtime_stat *st); 171void runtime_stat__init(struct runtime_stat *st);
138void runtime_stat__exit(struct runtime_stat *st); 172void runtime_stat__exit(struct runtime_stat *st);
@@ -148,7 +182,8 @@ struct perf_stat_output_ctx {
148 bool force_header; 182 bool force_header;
149}; 183};
150 184
151void perf_stat__print_shadow_stats(struct perf_evsel *evsel, 185void perf_stat__print_shadow_stats(struct perf_stat_config *config,
186 struct perf_evsel *evsel,
152 double avg, int cpu, 187 double avg, int cpu,
153 struct perf_stat_output_ctx *out, 188 struct perf_stat_output_ctx *out,
154 struct rblist *metric_events, 189 struct rblist *metric_events,
@@ -164,11 +199,25 @@ int perf_stat_process_counter(struct perf_stat_config *config,
164struct perf_tool; 199struct perf_tool;
165union perf_event; 200union perf_event;
166struct perf_session; 201struct perf_session;
167int perf_event__process_stat_event(struct perf_tool *tool, 202int perf_event__process_stat_event(struct perf_session *session,
168 union perf_event *event, 203 union perf_event *event);
169 struct perf_session *session);
170 204
171size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); 205size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp);
172size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); 206size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp);
173size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); 207size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp);
208
209int create_perf_stat_counter(struct perf_evsel *evsel,
210 struct perf_stat_config *config,
211 struct target *target);
212int perf_stat_synthesize_config(struct perf_stat_config *config,
213 struct perf_tool *tool,
214 struct perf_evlist *evlist,
215 perf_event__handler_t process,
216 bool attrs);
217void
218perf_evlist__print_counters(struct perf_evlist *evlist,
219 struct perf_stat_config *config,
220 struct target *_target,
221 struct timespec *ts,
222 int argc, const char **argv);
174#endif 223#endif
diff --git a/tools/perf/util/strbuf.c b/tools/perf/util/strbuf.c
index 3d1cf5bf7f18..9005fbe0780e 100644
--- a/tools/perf/util/strbuf.c
+++ b/tools/perf/util/strbuf.c
@@ -98,19 +98,25 @@ static int strbuf_addv(struct strbuf *sb, const char *fmt, va_list ap)
98 98
99 va_copy(ap_saved, ap); 99 va_copy(ap_saved, ap);
100 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 100 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap);
101 if (len < 0) 101 if (len < 0) {
102 va_end(ap_saved);
102 return len; 103 return len;
104 }
103 if (len > strbuf_avail(sb)) { 105 if (len > strbuf_avail(sb)) {
104 ret = strbuf_grow(sb, len); 106 ret = strbuf_grow(sb, len);
105 if (ret) 107 if (ret) {
108 va_end(ap_saved);
106 return ret; 109 return ret;
110 }
107 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved); 111 len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap_saved);
108 va_end(ap_saved); 112 va_end(ap_saved);
109 if (len > strbuf_avail(sb)) { 113 if (len > strbuf_avail(sb)) {
110 pr_debug("this should not happen, your vsnprintf is broken"); 114 pr_debug("this should not happen, your vsnprintf is broken");
115 va_end(ap_saved);
111 return -EINVAL; 116 return -EINVAL;
112 } 117 }
113 } 118 }
119 va_end(ap_saved);
114 return strbuf_setlen(sb, sb->len + len); 120 return strbuf_setlen(sb, sb->len + len);
115} 121}
116 122
diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c
index dd17d6a38d3a..c091635bf7dc 100644
--- a/tools/perf/util/thread-stack.c
+++ b/tools/perf/util/thread-stack.c
@@ -36,6 +36,7 @@
36 * @branch_count: the branch count when the entry was created 36 * @branch_count: the branch count when the entry was created
37 * @cp: call path 37 * @cp: call path
38 * @no_call: a 'call' was not seen 38 * @no_call: a 'call' was not seen
39 * @trace_end: a 'call' but trace ended
39 */ 40 */
40struct thread_stack_entry { 41struct thread_stack_entry {
41 u64 ret_addr; 42 u64 ret_addr;
@@ -44,6 +45,7 @@ struct thread_stack_entry {
44 u64 branch_count; 45 u64 branch_count;
45 struct call_path *cp; 46 struct call_path *cp;
46 bool no_call; 47 bool no_call;
48 bool trace_end;
47}; 49};
48 50
49/** 51/**
@@ -112,7 +114,8 @@ static struct thread_stack *thread_stack__new(struct thread *thread,
112 return ts; 114 return ts;
113} 115}
114 116
115static int thread_stack__push(struct thread_stack *ts, u64 ret_addr) 117static int thread_stack__push(struct thread_stack *ts, u64 ret_addr,
118 bool trace_end)
116{ 119{
117 int err = 0; 120 int err = 0;
118 121
@@ -124,6 +127,7 @@ static int thread_stack__push(struct thread_stack *ts, u64 ret_addr)
124 } 127 }
125 } 128 }
126 129
130 ts->stack[ts->cnt].trace_end = trace_end;
127 ts->stack[ts->cnt++].ret_addr = ret_addr; 131 ts->stack[ts->cnt++].ret_addr = ret_addr;
128 132
129 return err; 133 return err;
@@ -150,6 +154,18 @@ static void thread_stack__pop(struct thread_stack *ts, u64 ret_addr)
150 } 154 }
151} 155}
152 156
157static void thread_stack__pop_trace_end(struct thread_stack *ts)
158{
159 size_t i;
160
161 for (i = ts->cnt; i; ) {
162 if (ts->stack[--i].trace_end)
163 ts->cnt = i;
164 else
165 return;
166 }
167}
168
153static bool thread_stack__in_kernel(struct thread_stack *ts) 169static bool thread_stack__in_kernel(struct thread_stack *ts)
154{ 170{
155 if (!ts->cnt) 171 if (!ts->cnt)
@@ -254,10 +270,19 @@ int thread_stack__event(struct thread *thread, u32 flags, u64 from_ip,
254 ret_addr = from_ip + insn_len; 270 ret_addr = from_ip + insn_len;
255 if (ret_addr == to_ip) 271 if (ret_addr == to_ip)
256 return 0; /* Zero-length calls are excluded */ 272 return 0; /* Zero-length calls are excluded */
257 return thread_stack__push(thread->ts, ret_addr); 273 return thread_stack__push(thread->ts, ret_addr,
258 } else if (flags & PERF_IP_FLAG_RETURN) { 274 flags & PERF_IP_FLAG_TRACE_END);
259 if (!from_ip) 275 } else if (flags & PERF_IP_FLAG_TRACE_BEGIN) {
260 return 0; 276 /*
277 * If the caller did not change the trace number (which would
278 * have flushed the stack) then try to make sense of the stack.
279 * Possibly, tracing began after returning to the current
280 * address, so try to pop that. Also, do not expect a call made
281 * when the trace ended, to return, so pop that.
282 */
283 thread_stack__pop(thread->ts, to_ip);
284 thread_stack__pop_trace_end(thread->ts);
285 } else if ((flags & PERF_IP_FLAG_RETURN) && from_ip) {
261 thread_stack__pop(thread->ts, to_ip); 286 thread_stack__pop(thread->ts, to_ip);
262 } 287 }
263 288
@@ -332,7 +357,7 @@ void call_return_processor__free(struct call_return_processor *crp)
332 357
333static int thread_stack__push_cp(struct thread_stack *ts, u64 ret_addr, 358static int thread_stack__push_cp(struct thread_stack *ts, u64 ret_addr,
334 u64 timestamp, u64 ref, struct call_path *cp, 359 u64 timestamp, u64 ref, struct call_path *cp,
335 bool no_call) 360 bool no_call, bool trace_end)
336{ 361{
337 struct thread_stack_entry *tse; 362 struct thread_stack_entry *tse;
338 int err; 363 int err;
@@ -350,6 +375,7 @@ static int thread_stack__push_cp(struct thread_stack *ts, u64 ret_addr,
350 tse->branch_count = ts->branch_count; 375 tse->branch_count = ts->branch_count;
351 tse->cp = cp; 376 tse->cp = cp;
352 tse->no_call = no_call; 377 tse->no_call = no_call;
378 tse->trace_end = trace_end;
353 379
354 return 0; 380 return 0;
355} 381}
@@ -423,7 +449,7 @@ static int thread_stack__bottom(struct thread *thread, struct thread_stack *ts,
423 return -ENOMEM; 449 return -ENOMEM;
424 450
425 return thread_stack__push_cp(thread->ts, ip, sample->time, ref, cp, 451 return thread_stack__push_cp(thread->ts, ip, sample->time, ref, cp,
426 true); 452 true, false);
427} 453}
428 454
429static int thread_stack__no_call_return(struct thread *thread, 455static int thread_stack__no_call_return(struct thread *thread,
@@ -455,7 +481,7 @@ static int thread_stack__no_call_return(struct thread *thread,
455 if (!cp) 481 if (!cp)
456 return -ENOMEM; 482 return -ENOMEM;
457 return thread_stack__push_cp(ts, 0, sample->time, ref, 483 return thread_stack__push_cp(ts, 0, sample->time, ref,
458 cp, true); 484 cp, true, false);
459 } 485 }
460 } else if (thread_stack__in_kernel(ts) && sample->ip < ks) { 486 } else if (thread_stack__in_kernel(ts) && sample->ip < ks) {
461 /* Return to userspace, so pop all kernel addresses */ 487 /* Return to userspace, so pop all kernel addresses */
@@ -480,7 +506,7 @@ static int thread_stack__no_call_return(struct thread *thread,
480 return -ENOMEM; 506 return -ENOMEM;
481 507
482 err = thread_stack__push_cp(ts, sample->addr, sample->time, ref, cp, 508 err = thread_stack__push_cp(ts, sample->addr, sample->time, ref, cp,
483 true); 509 true, false);
484 if (err) 510 if (err)
485 return err; 511 return err;
486 512
@@ -500,7 +526,7 @@ static int thread_stack__trace_begin(struct thread *thread,
500 526
501 /* Pop trace end */ 527 /* Pop trace end */
502 tse = &ts->stack[ts->cnt - 1]; 528 tse = &ts->stack[ts->cnt - 1];
503 if (tse->cp->sym == NULL && tse->cp->ip == 0) { 529 if (tse->trace_end) {
504 err = thread_stack__call_return(thread, ts, --ts->cnt, 530 err = thread_stack__call_return(thread, ts, --ts->cnt,
505 timestamp, ref, false); 531 timestamp, ref, false);
506 if (err) 532 if (err)
@@ -529,7 +555,7 @@ static int thread_stack__trace_end(struct thread_stack *ts,
529 ret_addr = sample->ip + sample->insn_len; 555 ret_addr = sample->ip + sample->insn_len;
530 556
531 return thread_stack__push_cp(ts, ret_addr, sample->time, ref, cp, 557 return thread_stack__push_cp(ts, ret_addr, sample->time, ref, cp,
532 false); 558 false, true);
533} 559}
534 560
535int thread_stack__process(struct thread *thread, struct comm *comm, 561int thread_stack__process(struct thread *thread, struct comm *comm,
@@ -579,6 +605,7 @@ int thread_stack__process(struct thread *thread, struct comm *comm,
579 ts->last_time = sample->time; 605 ts->last_time = sample->time;
580 606
581 if (sample->flags & PERF_IP_FLAG_CALL) { 607 if (sample->flags & PERF_IP_FLAG_CALL) {
608 bool trace_end = sample->flags & PERF_IP_FLAG_TRACE_END;
582 struct call_path_root *cpr = ts->crp->cpr; 609 struct call_path_root *cpr = ts->crp->cpr;
583 struct call_path *cp; 610 struct call_path *cp;
584 u64 ret_addr; 611 u64 ret_addr;
@@ -596,7 +623,7 @@ int thread_stack__process(struct thread *thread, struct comm *comm,
596 if (!cp) 623 if (!cp)
597 return -ENOMEM; 624 return -ENOMEM;
598 err = thread_stack__push_cp(ts, ret_addr, sample->time, ref, 625 err = thread_stack__push_cp(ts, ret_addr, sample->time, ref,
599 cp, false); 626 cp, false, trace_end);
600 } else if (sample->flags & PERF_IP_FLAG_RETURN) { 627 } else if (sample->flags & PERF_IP_FLAG_RETURN) {
601 if (!sample->ip || !sample->addr) 628 if (!sample->ip || !sample->addr)
602 return 0; 629 return 0;
diff --git a/tools/perf/util/tool.h b/tools/perf/util/tool.h
index 183c91453522..56e4ca54020a 100644
--- a/tools/perf/util/tool.h
+++ b/tools/perf/util/tool.h
@@ -26,15 +26,12 @@ typedef int (*event_attr_op)(struct perf_tool *tool,
26 union perf_event *event, 26 union perf_event *event,
27 struct perf_evlist **pevlist); 27 struct perf_evlist **pevlist);
28 28
29typedef int (*event_op2)(struct perf_tool *tool, union perf_event *event, 29typedef int (*event_op2)(struct perf_session *session, union perf_event *event);
30 struct perf_session *session); 30typedef s64 (*event_op3)(struct perf_session *session, union perf_event *event);
31 31
32typedef int (*event_oe)(struct perf_tool *tool, union perf_event *event, 32typedef int (*event_oe)(struct perf_tool *tool, union perf_event *event,
33 struct ordered_events *oe); 33 struct ordered_events *oe);
34 34
35typedef s64 (*event_op3)(struct perf_tool *tool, union perf_event *event,
36 struct perf_session *session);
37
38enum show_feature_header { 35enum show_feature_header {
39 SHOW_FEAT_NO_HEADER = 0, 36 SHOW_FEAT_NO_HEADER = 0,
40 SHOW_FEAT_HEADER, 37 SHOW_FEAT_HEADER,
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index 7b0ca7cbb7de..8ad8e755127b 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -531,12 +531,14 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
531 "/tmp/perf-XXXXXX"); 531 "/tmp/perf-XXXXXX");
532 if (!mkstemp(tdata->temp_file)) { 532 if (!mkstemp(tdata->temp_file)) {
533 pr_debug("Can't make temp file"); 533 pr_debug("Can't make temp file");
534 free(tdata);
534 return NULL; 535 return NULL;
535 } 536 }
536 537
537 temp_fd = open(tdata->temp_file, O_RDWR); 538 temp_fd = open(tdata->temp_file, O_RDWR);
538 if (temp_fd < 0) { 539 if (temp_fd < 0) {
539 pr_debug("Can't read '%s'", tdata->temp_file); 540 pr_debug("Can't read '%s'", tdata->temp_file);
541 free(tdata);
540 return NULL; 542 return NULL;
541 } 543 }
542 544
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index e76214f8d596..32e558a65af3 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -33,14 +33,15 @@ static int get_common_field(struct scripting_context *context,
33 int *offset, int *size, const char *type) 33 int *offset, int *size, const char *type)
34{ 34{
35 struct tep_handle *pevent = context->pevent; 35 struct tep_handle *pevent = context->pevent;
36 struct event_format *event; 36 struct tep_event_format *event;
37 struct format_field *field; 37 struct tep_format_field *field;
38 38
39 if (!*size) { 39 if (!*size) {
40 if (!pevent->events) 40
41 event = tep_get_first_event(pevent);
42 if (!event)
41 return 0; 43 return 0;
42 44
43 event = pevent->events[0];
44 field = tep_find_common_field(event, type); 45 field = tep_find_common_field(event, type);
45 if (!field) 46 if (!field)
46 return 0; 47 return 0;
@@ -94,9 +95,9 @@ int common_pc(struct scripting_context *context)
94} 95}
95 96
96unsigned long long 97unsigned long long
97raw_field_value(struct event_format *event, const char *name, void *data) 98raw_field_value(struct tep_event_format *event, const char *name, void *data)
98{ 99{
99 struct format_field *field; 100 struct tep_format_field *field;
100 unsigned long long val; 101 unsigned long long val;
101 102
102 field = tep_find_any_field(event, name); 103 field = tep_find_any_field(event, name);
@@ -108,12 +109,12 @@ raw_field_value(struct event_format *event, const char *name, void *data)
108 return val; 109 return val;
109} 110}
110 111
111unsigned long long read_size(struct event_format *event, void *ptr, int size) 112unsigned long long read_size(struct tep_event_format *event, void *ptr, int size)
112{ 113{
113 return tep_read_number(event->pevent, ptr, size); 114 return tep_read_number(event->pevent, ptr, size);
114} 115}
115 116
116void event_format__fprintf(struct event_format *event, 117void event_format__fprintf(struct tep_event_format *event,
117 int cpu, void *data, int size, FILE *fp) 118 int cpu, void *data, int size, FILE *fp)
118{ 119{
119 struct tep_record record; 120 struct tep_record record;
@@ -130,7 +131,7 @@ void event_format__fprintf(struct event_format *event,
130 trace_seq_destroy(&s); 131 trace_seq_destroy(&s);
131} 132}
132 133
133void event_format__print(struct event_format *event, 134void event_format__print(struct tep_event_format *event,
134 int cpu, void *data, int size) 135 int cpu, void *data, int size)
135{ 136{
136 return event_format__fprintf(event, cpu, data, size, stdout); 137 return event_format__fprintf(event, cpu, data, size, stdout);
@@ -158,6 +159,7 @@ void parse_ftrace_printk(struct tep_handle *pevent,
158 printk = strdup(fmt+1); 159 printk = strdup(fmt+1);
159 line = strtok_r(NULL, "\n", &next); 160 line = strtok_r(NULL, "\n", &next);
160 tep_register_print_string(pevent, printk, addr); 161 tep_register_print_string(pevent, printk, addr);
162 free(printk);
161 } 163 }
162} 164}
163 165
@@ -188,29 +190,33 @@ int parse_event_file(struct tep_handle *pevent,
188 return tep_parse_event(pevent, buf, size, sys); 190 return tep_parse_event(pevent, buf, size, sys);
189} 191}
190 192
191struct event_format *trace_find_next_event(struct tep_handle *pevent, 193struct tep_event_format *trace_find_next_event(struct tep_handle *pevent,
192 struct event_format *event) 194 struct tep_event_format *event)
193{ 195{
194 static int idx; 196 static int idx;
197 int events_count;
198 struct tep_event_format *all_events;
195 199
196 if (!pevent || !pevent->events) 200 all_events = tep_get_first_event(pevent);
201 events_count = tep_get_events_count(pevent);
202 if (!pevent || !all_events || events_count < 1)
197 return NULL; 203 return NULL;
198 204
199 if (!event) { 205 if (!event) {
200 idx = 0; 206 idx = 0;
201 return pevent->events[0]; 207 return all_events;
202 } 208 }
203 209
204 if (idx < pevent->nr_events && event == pevent->events[idx]) { 210 if (idx < events_count && event == (all_events + idx)) {
205 idx++; 211 idx++;
206 if (idx == pevent->nr_events) 212 if (idx == events_count)
207 return NULL; 213 return NULL;
208 return pevent->events[idx]; 214 return (all_events + idx);
209 } 215 }
210 216
211 for (idx = 1; idx < pevent->nr_events; idx++) { 217 for (idx = 1; idx < events_count; idx++) {
212 if (event == pevent->events[idx - 1]) 218 if (event == (all_events + (idx - 1)))
213 return pevent->events[idx]; 219 return (all_events + idx);
214 } 220 }
215 return NULL; 221 return NULL;
216} 222}
diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c
index 3dfc1db6b25b..76f12c705ef9 100644
--- a/tools/perf/util/trace-event-read.c
+++ b/tools/perf/util/trace-event-read.c
@@ -102,7 +102,7 @@ static unsigned int read4(struct tep_handle *pevent)
102 102
103 if (do_read(&data, 4) < 0) 103 if (do_read(&data, 4) < 0)
104 return 0; 104 return 0;
105 return __data2host4(pevent, data); 105 return __tep_data2host4(pevent, data);
106} 106}
107 107
108static unsigned long long read8(struct tep_handle *pevent) 108static unsigned long long read8(struct tep_handle *pevent)
@@ -111,7 +111,7 @@ static unsigned long long read8(struct tep_handle *pevent)
111 111
112 if (do_read(&data, 8) < 0) 112 if (do_read(&data, 8) < 0)
113 return 0; 113 return 0;
114 return __data2host8(pevent, data); 114 return __tep_data2host8(pevent, data);
115} 115}
116 116
117static char *read_string(void) 117static char *read_string(void)
@@ -241,7 +241,7 @@ static int read_header_files(struct tep_handle *pevent)
241 * The commit field in the page is of type long, 241 * The commit field in the page is of type long,
242 * use that instead, since it represents the kernel. 242 * use that instead, since it represents the kernel.
243 */ 243 */
244 tep_set_long_size(pevent, pevent->header_page_size_size); 244 tep_set_long_size(pevent, tep_get_header_page_size(pevent));
245 } 245 }
246 free(header_page); 246 free(header_page);
247 247
@@ -297,10 +297,8 @@ static int read_event_file(struct tep_handle *pevent, char *sys,
297 } 297 }
298 298
299 ret = do_read(buf, size); 299 ret = do_read(buf, size);
300 if (ret < 0) { 300 if (ret < 0)
301 free(buf);
302 goto out; 301 goto out;
303 }
304 302
305 ret = parse_event_file(pevent, buf, size, sys); 303 ret = parse_event_file(pevent, buf, size, sys);
306 if (ret < 0) 304 if (ret < 0)
@@ -349,9 +347,12 @@ static int read_event_files(struct tep_handle *pevent)
349 for (x=0; x < count; x++) { 347 for (x=0; x < count; x++) {
350 size = read8(pevent); 348 size = read8(pevent);
351 ret = read_event_file(pevent, sys, size); 349 ret = read_event_file(pevent, sys, size);
352 if (ret) 350 if (ret) {
351 free(sys);
353 return ret; 352 return ret;
353 }
354 } 354 }
355 free(sys);
355 } 356 }
356 return 0; 357 return 0;
357} 358}
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
index 58bb72f266f3..95664b2f771e 100644
--- a/tools/perf/util/trace-event.c
+++ b/tools/perf/util/trace-event.c
@@ -72,12 +72,12 @@ void trace_event__cleanup(struct trace_event *t)
72/* 72/*
73 * Returns pointer with encoded error via <linux/err.h> interface. 73 * Returns pointer with encoded error via <linux/err.h> interface.
74 */ 74 */
75static struct event_format* 75static struct tep_event_format*
76tp_format(const char *sys, const char *name) 76tp_format(const char *sys, const char *name)
77{ 77{
78 char *tp_dir = get_events_file(sys); 78 char *tp_dir = get_events_file(sys);
79 struct tep_handle *pevent = tevent.pevent; 79 struct tep_handle *pevent = tevent.pevent;
80 struct event_format *event = NULL; 80 struct tep_event_format *event = NULL;
81 char path[PATH_MAX]; 81 char path[PATH_MAX];
82 size_t size; 82 size_t size;
83 char *data; 83 char *data;
@@ -102,7 +102,7 @@ tp_format(const char *sys, const char *name)
102/* 102/*
103 * Returns pointer with encoded error via <linux/err.h> interface. 103 * Returns pointer with encoded error via <linux/err.h> interface.
104 */ 104 */
105struct event_format* 105struct tep_event_format*
106trace_event__tp_format(const char *sys, const char *name) 106trace_event__tp_format(const char *sys, const char *name)
107{ 107{
108 if (!tevent_initialized && trace_event__init2()) 108 if (!tevent_initialized && trace_event__init2())
@@ -111,7 +111,7 @@ trace_event__tp_format(const char *sys, const char *name)
111 return tp_format(sys, name); 111 return tp_format(sys, name);
112} 112}
113 113
114struct event_format *trace_event__tp_format_id(int id) 114struct tep_event_format *trace_event__tp_format_id(int id)
115{ 115{
116 if (!tevent_initialized && trace_event__init2()) 116 if (!tevent_initialized && trace_event__init2())
117 return ERR_PTR(-ENOMEM); 117 return ERR_PTR(-ENOMEM);
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 40204ec3a7a2..f024d73bfc40 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -3,6 +3,7 @@
3#define _PERF_UTIL_TRACE_EVENT_H 3#define _PERF_UTIL_TRACE_EVENT_H
4 4
5#include <traceevent/event-parse.h> 5#include <traceevent/event-parse.h>
6#include <traceevent/trace-seq.h>
6#include "parse-events.h" 7#include "parse-events.h"
7 8
8struct machine; 9struct machine;
@@ -10,28 +11,28 @@ struct perf_sample;
10union perf_event; 11union perf_event;
11struct perf_tool; 12struct perf_tool;
12struct thread; 13struct thread;
13struct plugin_list; 14struct tep_plugin_list;
14 15
15struct trace_event { 16struct trace_event {
16 struct tep_handle *pevent; 17 struct tep_handle *pevent;
17 struct plugin_list *plugin_list; 18 struct tep_plugin_list *plugin_list;
18}; 19};
19 20
20int trace_event__init(struct trace_event *t); 21int trace_event__init(struct trace_event *t);
21void trace_event__cleanup(struct trace_event *t); 22void trace_event__cleanup(struct trace_event *t);
22int trace_event__register_resolver(struct machine *machine, 23int trace_event__register_resolver(struct machine *machine,
23 tep_func_resolver_t *func); 24 tep_func_resolver_t *func);
24struct event_format* 25struct tep_event_format*
25trace_event__tp_format(const char *sys, const char *name); 26trace_event__tp_format(const char *sys, const char *name);
26 27
27struct event_format *trace_event__tp_format_id(int id); 28struct tep_event_format *trace_event__tp_format_id(int id);
28 29
29int bigendian(void); 30int bigendian(void);
30 31
31void event_format__fprintf(struct event_format *event, 32void event_format__fprintf(struct tep_event_format *event,
32 int cpu, void *data, int size, FILE *fp); 33 int cpu, void *data, int size, FILE *fp);
33 34
34void event_format__print(struct event_format *event, 35void event_format__print(struct tep_event_format *event,
35 int cpu, void *data, int size); 36 int cpu, void *data, int size);
36 37
37int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size); 38int parse_ftrace_file(struct tep_handle *pevent, char *buf, unsigned long size);
@@ -39,7 +40,7 @@ int parse_event_file(struct tep_handle *pevent,
39 char *buf, unsigned long size, char *sys); 40 char *buf, unsigned long size, char *sys);
40 41
41unsigned long long 42unsigned long long
42raw_field_value(struct event_format *event, const char *name, void *data); 43raw_field_value(struct tep_event_format *event, const char *name, void *data);
43 44
44void parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size); 45void parse_proc_kallsyms(struct tep_handle *pevent, char *file, unsigned int size);
45void parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size); 46void parse_ftrace_printk(struct tep_handle *pevent, char *file, unsigned int size);
@@ -47,9 +48,9 @@ void parse_saved_cmdline(struct tep_handle *pevent, char *file, unsigned int siz
47 48
48ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe); 49ssize_t trace_report(int fd, struct trace_event *tevent, bool repipe);
49 50
50struct event_format *trace_find_next_event(struct tep_handle *pevent, 51struct tep_event_format *trace_find_next_event(struct tep_handle *pevent,
51 struct event_format *event); 52 struct tep_event_format *event);
52unsigned long long read_size(struct event_format *event, void *ptr, int size); 53unsigned long long read_size(struct tep_event_format *event, void *ptr, int size);
53unsigned long long eval_flag(const char *flag); 54unsigned long long eval_flag(const char *flag);
54 55
55int read_tracing_data(int fd, struct list_head *pattrs); 56int read_tracing_data(int fd, struct list_head *pattrs);
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index eac5b858a371..093352e93d50 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -221,7 +221,7 @@ out:
221 return err; 221 return err;
222} 222}
223 223
224static int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size) 224int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size)
225{ 225{
226 void *ptr; 226 void *ptr;
227 loff_t pgoff; 227 loff_t pgoff;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index dc58254a2b69..14508ee7707a 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -6,6 +6,7 @@
6/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */ 6/* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
7#define _DEFAULT_SOURCE 1 7#define _DEFAULT_SOURCE 1
8 8
9#include <fcntl.h>
9#include <stdbool.h> 10#include <stdbool.h>
10#include <stddef.h> 11#include <stddef.h>
11#include <stdlib.h> 12#include <stdlib.h>
@@ -35,6 +36,7 @@ bool lsdir_no_dot_filter(const char *name, struct dirent *d);
35int copyfile(const char *from, const char *to); 36int copyfile(const char *from, const char *to);
36int copyfile_mode(const char *from, const char *to, mode_t mode); 37int copyfile_mode(const char *from, const char *to, mode_t mode);
37int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi); 38int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi);
39int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size);
38 40
39ssize_t readn(int fd, void *buf, size_t n); 41ssize_t readn(int fd, void *buf, size_t n);
40ssize_t writen(int fd, const void *buf, size_t n); 42ssize_t writen(int fd, const void *buf, size_t n);
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 980bd9d20646..328f62e6ea02 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2082,7 +2082,7 @@ int has_turbo_ratio_group_limits(int family, int model)
2082 switch (model) { 2082 switch (model) {
2083 case INTEL_FAM6_ATOM_GOLDMONT: 2083 case INTEL_FAM6_ATOM_GOLDMONT:
2084 case INTEL_FAM6_SKYLAKE_X: 2084 case INTEL_FAM6_SKYLAKE_X:
2085 case INTEL_FAM6_ATOM_DENVERTON: 2085 case INTEL_FAM6_ATOM_GOLDMONT_X:
2086 return 1; 2086 return 1;
2087 } 2087 }
2088 return 0; 2088 return 0;
@@ -3149,9 +3149,9 @@ int probe_nhm_msrs(unsigned int family, unsigned int model)
3149 pkg_cstate_limits = skx_pkg_cstate_limits; 3149 pkg_cstate_limits = skx_pkg_cstate_limits;
3150 has_misc_feature_control = 1; 3150 has_misc_feature_control = 1;
3151 break; 3151 break;
3152 case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ 3152 case INTEL_FAM6_ATOM_SILVERMONT: /* BYT */
3153 no_MSR_MISC_PWR_MGMT = 1; 3153 no_MSR_MISC_PWR_MGMT = 1;
3154 case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ 3154 case INTEL_FAM6_ATOM_SILVERMONT_X: /* AVN */
3155 pkg_cstate_limits = slv_pkg_cstate_limits; 3155 pkg_cstate_limits = slv_pkg_cstate_limits;
3156 break; 3156 break;
3157 case INTEL_FAM6_ATOM_AIRMONT: /* AMT */ 3157 case INTEL_FAM6_ATOM_AIRMONT: /* AMT */
@@ -3163,8 +3163,8 @@ int probe_nhm_msrs(unsigned int family, unsigned int model)
3163 pkg_cstate_limits = phi_pkg_cstate_limits; 3163 pkg_cstate_limits = phi_pkg_cstate_limits;
3164 break; 3164 break;
3165 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 3165 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
3166 case INTEL_FAM6_ATOM_GEMINI_LAKE: 3166 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
3167 case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 3167 case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */
3168 pkg_cstate_limits = bxt_pkg_cstate_limits; 3168 pkg_cstate_limits = bxt_pkg_cstate_limits;
3169 break; 3169 break;
3170 default: 3170 default:
@@ -3193,9 +3193,9 @@ int has_slv_msrs(unsigned int family, unsigned int model)
3193 return 0; 3193 return 0;
3194 3194
3195 switch (model) { 3195 switch (model) {
3196 case INTEL_FAM6_ATOM_SILVERMONT1: 3196 case INTEL_FAM6_ATOM_SILVERMONT:
3197 case INTEL_FAM6_ATOM_MERRIFIELD: 3197 case INTEL_FAM6_ATOM_SILVERMONT_MID:
3198 case INTEL_FAM6_ATOM_MOOREFIELD: 3198 case INTEL_FAM6_ATOM_AIRMONT_MID:
3199 return 1; 3199 return 1;
3200 } 3200 }
3201 return 0; 3201 return 0;
@@ -3207,7 +3207,7 @@ int is_dnv(unsigned int family, unsigned int model)
3207 return 0; 3207 return 0;
3208 3208
3209 switch (model) { 3209 switch (model) {
3210 case INTEL_FAM6_ATOM_DENVERTON: 3210 case INTEL_FAM6_ATOM_GOLDMONT_X:
3211 return 1; 3211 return 1;
3212 } 3212 }
3213 return 0; 3213 return 0;
@@ -3724,8 +3724,8 @@ double get_tdp(unsigned int model)
3724 return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units; 3724 return ((msr >> 0) & RAPL_POWER_GRANULARITY) * rapl_power_units;
3725 3725
3726 switch (model) { 3726 switch (model) {
3727 case INTEL_FAM6_ATOM_SILVERMONT1: 3727 case INTEL_FAM6_ATOM_SILVERMONT:
3728 case INTEL_FAM6_ATOM_SILVERMONT2: 3728 case INTEL_FAM6_ATOM_SILVERMONT_X:
3729 return 30.0; 3729 return 30.0;
3730 default: 3730 default:
3731 return 135.0; 3731 return 135.0;
@@ -3791,7 +3791,7 @@ void rapl_probe(unsigned int family, unsigned int model)
3791 } 3791 }
3792 break; 3792 break;
3793 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 3793 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
3794 case INTEL_FAM6_ATOM_GEMINI_LAKE: 3794 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
3795 do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO; 3795 do_rapl = RAPL_PKG | RAPL_PKG_POWER_INFO;
3796 if (rapl_joules) 3796 if (rapl_joules)
3797 BIC_PRESENT(BIC_Pkg_J); 3797 BIC_PRESENT(BIC_Pkg_J);
@@ -3850,8 +3850,8 @@ void rapl_probe(unsigned int family, unsigned int model)
3850 BIC_PRESENT(BIC_RAMWatt); 3850 BIC_PRESENT(BIC_RAMWatt);
3851 } 3851 }
3852 break; 3852 break;
3853 case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ 3853 case INTEL_FAM6_ATOM_SILVERMONT: /* BYT */
3854 case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ 3854 case INTEL_FAM6_ATOM_SILVERMONT_X: /* AVN */
3855 do_rapl = RAPL_PKG | RAPL_CORES; 3855 do_rapl = RAPL_PKG | RAPL_CORES;
3856 if (rapl_joules) { 3856 if (rapl_joules) {
3857 BIC_PRESENT(BIC_Pkg_J); 3857 BIC_PRESENT(BIC_Pkg_J);
@@ -3861,7 +3861,7 @@ void rapl_probe(unsigned int family, unsigned int model)
3861 BIC_PRESENT(BIC_CorWatt); 3861 BIC_PRESENT(BIC_CorWatt);
3862 } 3862 }
3863 break; 3863 break;
3864 case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 3864 case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */
3865 do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO | RAPL_CORES_ENERGY_STATUS; 3865 do_rapl = RAPL_PKG | RAPL_DRAM | RAPL_DRAM_POWER_INFO | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_PKG_POWER_INFO | RAPL_CORES_ENERGY_STATUS;
3866 BIC_PRESENT(BIC_PKG__); 3866 BIC_PRESENT(BIC_PKG__);
3867 BIC_PRESENT(BIC_RAM__); 3867 BIC_PRESENT(BIC_RAM__);
@@ -3884,7 +3884,7 @@ void rapl_probe(unsigned int family, unsigned int model)
3884 return; 3884 return;
3885 3885
3886 rapl_power_units = 1.0 / (1 << (msr & 0xF)); 3886 rapl_power_units = 1.0 / (1 << (msr & 0xF));
3887 if (model == INTEL_FAM6_ATOM_SILVERMONT1) 3887 if (model == INTEL_FAM6_ATOM_SILVERMONT)
3888 rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000; 3888 rapl_energy_units = 1.0 * (1 << (msr >> 8 & 0x1F)) / 1000000;
3889 else 3889 else
3890 rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F)); 3890 rapl_energy_units = 1.0 / (1 << (msr >> 8 & 0x1F));
@@ -4141,8 +4141,8 @@ int has_snb_msrs(unsigned int family, unsigned int model)
4141 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ 4141 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
4142 case INTEL_FAM6_SKYLAKE_X: /* SKX */ 4142 case INTEL_FAM6_SKYLAKE_X: /* SKX */
4143 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 4143 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
4144 case INTEL_FAM6_ATOM_GEMINI_LAKE: 4144 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
4145 case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 4145 case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */
4146 return 1; 4146 return 1;
4147 } 4147 }
4148 return 0; 4148 return 0;
@@ -4174,7 +4174,7 @@ int has_hsw_msrs(unsigned int family, unsigned int model)
4174 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 4174 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
4175 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */ 4175 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
4176 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 4176 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
4177 case INTEL_FAM6_ATOM_GEMINI_LAKE: 4177 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
4178 return 1; 4178 return 1;
4179 } 4179 }
4180 return 0; 4180 return 0;
@@ -4209,8 +4209,8 @@ int is_slm(unsigned int family, unsigned int model)
4209 if (!genuine_intel) 4209 if (!genuine_intel)
4210 return 0; 4210 return 0;
4211 switch (model) { 4211 switch (model) {
4212 case INTEL_FAM6_ATOM_SILVERMONT1: /* BYT */ 4212 case INTEL_FAM6_ATOM_SILVERMONT: /* BYT */
4213 case INTEL_FAM6_ATOM_SILVERMONT2: /* AVN */ 4213 case INTEL_FAM6_ATOM_SILVERMONT_X: /* AVN */
4214 return 1; 4214 return 1;
4215 } 4215 }
4216 return 0; 4216 return 0;
@@ -4581,11 +4581,11 @@ void process_cpuid()
4581 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 4581 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
4582 crystal_hz = 24000000; /* 24.0 MHz */ 4582 crystal_hz = 24000000; /* 24.0 MHz */
4583 break; 4583 break;
4584 case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 4584 case INTEL_FAM6_ATOM_GOLDMONT_X: /* DNV */
4585 crystal_hz = 25000000; /* 25.0 MHz */ 4585 crystal_hz = 25000000; /* 25.0 MHz */
4586 break; 4586 break;
4587 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 4587 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
4588 case INTEL_FAM6_ATOM_GEMINI_LAKE: 4588 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
4589 crystal_hz = 19200000; /* 19.2 MHz */ 4589 crystal_hz = 19200000; /* 19.2 MHz */
4590 break; 4590 break;
4591 default: 4591 default: