Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 23 Oct 2018 12:32:18 +0000 (13:32 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 23 Oct 2018 12:32:18 +0000 (13:32 +0100)
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
  ...

141 files changed:
Documentation/admin-guide/kernel-parameters.txt
Documentation/x86/intel_rdt_ui.txt
arch/x86/events/core.c
arch/x86/events/intel/core.c
arch/x86/events/intel/cstate.c
arch/x86/events/intel/pt.c
arch/x86/events/intel/rapl.c
arch/x86/events/msr.c
arch/x86/events/perf_event.h
arch/x86/include/asm/intel-family.h
arch/x86/include/asm/msr-index.h
arch/x86/include/asm/perf_event.h
arch/x86/include/asm/ptrace.h
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/intel_rdt.c
arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
arch/x86/kernel/cpu/intel_rdt_pseudo_lock.c
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c
arch/x86/kernel/kprobes/opt.c
arch/x86/kernel/tsc.c
arch/x86/kernel/tsc_msr.c
arch/x86/platform/atom/punit_atom_debug.c
arch/x86/platform/intel-mid/device_libs/platform_bt.c
drivers/acpi/acpi_lpss.c
drivers/acpi/x86/utils.c
drivers/cpufreq/intel_pstate.c
drivers/edac/pnd2_edac.c
drivers/idle/intel_idle.c
drivers/mmc/host/sdhci-acpi.c
drivers/pci/pci-mid.c
drivers/platform/x86/intel_int0002_vgpio.c
drivers/platform/x86/intel_mid_powerbtn.c
drivers/platform/x86/intel_telemetry_debugfs.c
drivers/platform/x86/intel_telemetry_pltdrv.c
drivers/powercap/intel_rapl.c
drivers/thermal/intel_soc_dts_thermal.c
kernel/events/ring_buffer.c
kernel/kprobes.c
sound/soc/intel/boards/bytcr_rt5651.c
tools/include/linux/bitops.h
tools/include/linux/bits.h [new file with mode: 0644]
tools/include/linux/err.h
tools/lib/subcmd/pager.c
tools/lib/subcmd/pager.h
tools/lib/traceevent/Build
tools/lib/traceevent/event-parse-api.c [new file with mode: 0644]
tools/lib/traceevent/event-parse-local.h [new file with mode: 0644]
tools/lib/traceevent/event-parse.c
tools/lib/traceevent/event-parse.h
tools/lib/traceevent/event-plugin.c
tools/lib/traceevent/parse-filter.c
tools/lib/traceevent/plugin_function.c
tools/lib/traceevent/plugin_hrtimer.c
tools/lib/traceevent/plugin_jbd2.c
tools/lib/traceevent/plugin_kmem.c
tools/lib/traceevent/plugin_kvm.c
tools/lib/traceevent/plugin_mac80211.c
tools/lib/traceevent/plugin_sched_switch.c
tools/lib/traceevent/plugin_scsi.c
tools/lib/traceevent/plugin_xen.c
tools/lib/traceevent/tep_strerror.c [new file with mode: 0644]
tools/lib/traceevent/trace-seq.c
tools/lib/traceevent/trace-seq.h [new file with mode: 0644]
tools/perf/Makefile.perf
tools/perf/arch/arm64/annotate/instructions.c
tools/perf/arch/s390/annotate/instructions.c
tools/perf/builtin-annotate.c
tools/perf/builtin-inject.c
tools/perf/builtin-record.c
tools/perf/builtin-report.c
tools/perf/builtin-script.c
tools/perf/builtin-stat.c
tools/perf/builtin-trace.c
tools/perf/check-headers.sh
tools/perf/command-list.txt
tools/perf/examples/bpf/augmented_syscalls.c
tools/perf/examples/bpf/etcsnoop.c [new file with mode: 0644]
tools/perf/include/bpf/bpf.h
tools/perf/include/bpf/linux/socket.h [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/branch.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/bus.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/cache.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/clock.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/core-imp-def.json [deleted file]
tools/perf/pmu-events/arch/arm64/ampere/emag/exception.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/instruction.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/intrinsic.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/memory.json [new file with mode: 0644]
tools/perf/pmu-events/arch/arm64/ampere/emag/pipeline.json [new file with mode: 0644]
tools/perf/tests/Build
tools/perf/tests/builtin-test.c
tools/perf/tests/evsel-tp-sched.c
tools/perf/tests/shell/record+probe_libc_inet_pton.sh
tools/perf/tests/tests.h
tools/perf/tests/wp.c [new file with mode: 0644]
tools/perf/trace/beauty/Build
tools/perf/trace/beauty/beauty.h
tools/perf/trace/beauty/sockaddr.c [new file with mode: 0644]
tools/perf/util/Build
tools/perf/util/auxtrace.c
tools/perf/util/auxtrace.h
tools/perf/util/bpf-loader.c
tools/perf/util/data-convert-bt.c
tools/perf/util/db-export.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/evsel_fprintf.c
tools/perf/util/header.c
tools/perf/util/header.h
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c
tools/perf/util/intel-pt-decoder/intel-pt-decoder.h
tools/perf/util/intel-pt.c
tools/perf/util/llvm-utils.c
tools/perf/util/map.c
tools/perf/util/mmap.c
tools/perf/util/mmap.h
tools/perf/util/ordered-events.c
tools/perf/util/ordered-events.h
tools/perf/util/python.c
tools/perf/util/s390-cpumsf.c
tools/perf/util/scripting-engines/trace-event-perl.c
tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/util/session.c
tools/perf/util/session.h
tools/perf/util/setup.py
tools/perf/util/sort.c
tools/perf/util/stat-display.c [new file with mode: 0644]
tools/perf/util/stat-shadow.c
tools/perf/util/stat.c
tools/perf/util/stat.h
tools/perf/util/strbuf.c
tools/perf/util/thread-stack.c
tools/perf/util/tool.h
tools/perf/util/trace-event-info.c
tools/perf/util/trace-event-parse.c
tools/perf/util/trace-event-read.c
tools/perf/util/trace-event.c
tools/perf/util/trace-event.h
tools/perf/util/util.c
tools/perf/util/util.h
tools/power/x86/turbostat/turbostat.c

index e9054fd1d0d09a9e34af8b5a9f31298420dbb1cc..4c74a2f4ddfc38c3aaf79fa5f6db10bc524dc78e 100644 (file)
                        causing system reset or hang due to sending
                        INIT from AP to BSP.
 
+       disable_counter_freezing [HW]
+                       Disable Intel PMU counter freezing feature.
+                       The feature only exists starting from
+                       Arch Perfmon v4 (Skylake and newer).
+
        disable_ddw     [PPC/PSERIES]
                        Disable Dynamic DMA Window support. Use this if
                        to workaround buggy firmware.
index f662d3c530e5066f35e1e5744e2b03d0e7feae18..52b10945ff7512f3fdf4647c975244e097405608 100644 (file)
@@ -520,18 +520,24 @@ the pseudo-locked region:
 2) Cache hit and miss measurements using model specific precision counters if
    available. Depending on the levels of cache on the system the pseudo_lock_l2
    and pseudo_lock_l3 tracepoints are available.
-   WARNING: triggering this  measurement uses from two (for just L2
-   measurements) to four (for L2 and L3 measurements) precision counters on
-   the system, if any other measurements are in progress the counters and
-   their corresponding event registers will be clobbered.
 
 When a pseudo-locked region is created a new debugfs directory is created for
 it in debugfs as /sys/kernel/debug/resctrl/<newdir>. A single
 write-only file, pseudo_lock_measure, is present in this directory. The
-measurement on the pseudo-locked region depends on the number, 1 or 2,
-written to this debugfs file. Since the measurements are recorded with the
-tracing infrastructure the relevant tracepoints need to be enabled before the
-measurement is triggered.
+measurement of the pseudo-locked region depends on the number written to this
+debugfs file:
+1 -  writing "1" to the pseudo_lock_measure file will trigger the latency
+     measurement captured in the pseudo_lock_mem_latency tracepoint. See
+     example below.
+2 -  writing "2" to the pseudo_lock_measure file will trigger the L2 cache
+     residency (cache hits and misses) measurement captured in the
+     pseudo_lock_l2 tracepoint. See example below.
+3 -  writing "3" to the pseudo_lock_measure file will trigger the L3 cache
+     residency (cache hits and misses) measurement captured in the
+     pseudo_lock_l3 tracepoint.
+
+All measurements are recorded with the tracing infrastructure. This requires
+the relevant tracepoints to be enabled before the measurement is triggered.
 
 Example of latency debugging interface:
 In this example a pseudo-locked region named "newlock" was created. Here is
index dfb2f7c0d0192bcd16569d03badd498f355accf7..de32741d041a456923ea6c07b0b277f41446428a 100644 (file)
@@ -1033,6 +1033,27 @@ static inline void x86_assign_hw_event(struct perf_event *event,
        }
 }
 
+/**
+ * x86_perf_rdpmc_index - Return PMC counter used for event
+ * @event: the perf_event to which the PMC counter was assigned
+ *
+ * The counter assigned to this performance event may change if interrupts
+ * are enabled. This counter should thus never be used while interrupts are
+ * enabled. Before this function is used to obtain the assigned counter the
+ * event should be checked for validity using, for example,
+ * perf_event_read_local(), within the same interrupt disabled section in
+ * which this counter is planned to be used.
+ *
+ * Return: The index of the performance monitoring counter assigned to
+ * @perf_event.
+ */
+int x86_perf_rdpmc_index(struct perf_event *event)
+{
+       lockdep_assert_irqs_disabled();
+
+       return event->hw.event_base_rdpmc;
+}
+
 static inline int match_prev_assignment(struct hw_perf_event *hwc,
                                        struct cpu_hw_events *cpuc,
                                        int i)
@@ -1584,7 +1605,7 @@ static void __init pmu_check_apic(void)
 
 }
 
-static struct attribute_group x86_pmu_format_group = {
+static struct attribute_group x86_pmu_format_group __ro_after_init = {
        .name = "format",
        .attrs = NULL,
 };
@@ -1631,9 +1652,9 @@ __init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
        struct attribute **new;
        int j, i;
 
-       for (j = 0; a[j]; j++)
+       for (j = 0; a && a[j]; j++)
                ;
-       for (i = 0; b[i]; i++)
+       for (i = 0; b && b[i]; i++)
                j++;
        j++;
 
@@ -1642,9 +1663,9 @@ __init struct attribute **merge_attr(struct attribute **a, struct attribute **b)
                return NULL;
 
        j = 0;
-       for (i = 0; a[i]; i++)
+       for (i = 0; a && a[i]; i++)
                new[j++] = a[i];
-       for (i = 0; b[i]; i++)
+       for (i = 0; b && b[i]; i++)
                new[j++] = b[i];
        new[j] = NULL;
 
@@ -1715,7 +1736,7 @@ static struct attribute *events_attr[] = {
        NULL,
 };
 
-static struct attribute_group x86_pmu_events_group = {
+static struct attribute_group x86_pmu_events_group __ro_after_init = {
        .name = "events",
        .attrs = events_attr,
 };
@@ -2230,7 +2251,7 @@ static struct attribute *x86_pmu_attrs[] = {
        NULL,
 };
 
-static struct attribute_group x86_pmu_attr_group = {
+static struct attribute_group x86_pmu_attr_group __ro_after_init = {
        .attrs = x86_pmu_attrs,
 };
 
@@ -2248,7 +2269,7 @@ static struct attribute *x86_pmu_caps_attrs[] = {
        NULL
 };
 
-static struct attribute_group x86_pmu_caps_group = {
+static struct attribute_group x86_pmu_caps_group __ro_after_init = {
        .name = "caps",
        .attrs = x86_pmu_caps_attrs,
 };
index 035c37481f572a253b08773df44069ab1590de91..0fb8659b20d8d76fd974406873df8416359ab157 100644 (file)
@@ -242,7 +242,7 @@ EVENT_ATTR_STR(mem-loads,   mem_ld_nhm,     "event=0x0b,umask=0x10,ldlat=3");
 EVENT_ATTR_STR(mem-loads,      mem_ld_snb,     "event=0xcd,umask=0x1,ldlat=3");
 EVENT_ATTR_STR(mem-stores,     mem_st_snb,     "event=0xcd,umask=0x2");
 
-static struct attribute *nhm_events_attrs[] = {
+static struct attribute *nhm_mem_events_attrs[] = {
        EVENT_PTR(mem_ld_nhm),
        NULL,
 };
@@ -278,8 +278,6 @@ EVENT_ATTR_STR_HT(topdown-recovery-bubbles.scale, td_recovery_bubbles_scale,
        "4", "2");
 
 static struct attribute *snb_events_attrs[] = {
-       EVENT_PTR(mem_ld_snb),
-       EVENT_PTR(mem_st_snb),
        EVENT_PTR(td_slots_issued),
        EVENT_PTR(td_slots_retired),
        EVENT_PTR(td_fetch_bubbles),
@@ -290,6 +288,12 @@ static struct attribute *snb_events_attrs[] = {
        NULL,
 };
 
+static struct attribute *snb_mem_events_attrs[] = {
+       EVENT_PTR(mem_ld_snb),
+       EVENT_PTR(mem_st_snb),
+       NULL,
+};
+
 static struct event_constraint intel_hsw_event_constraints[] = {
        FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
        FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
@@ -1995,6 +1999,18 @@ static void intel_pmu_nhm_enable_all(int added)
        intel_pmu_enable_all(added);
 }
 
+static void enable_counter_freeze(void)
+{
+       update_debugctlmsr(get_debugctlmsr() |
+                       DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI);
+}
+
+static void disable_counter_freeze(void)
+{
+       update_debugctlmsr(get_debugctlmsr() &
+                       ~DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI);
+}
+
 static inline u64 intel_pmu_get_status(void)
 {
        u64 status;
@@ -2200,59 +2216,15 @@ static void intel_pmu_reset(void)
        local_irq_restore(flags);
 }
 
-/*
- * This handler is triggered by the local APIC, so the APIC IRQ handling
- * rules apply:
- */
-static int intel_pmu_handle_irq(struct pt_regs *regs)
+static int handle_pmi_common(struct pt_regs *regs, u64 status)
 {
        struct perf_sample_data data;
-       struct cpu_hw_events *cpuc;
-       int bit, loops;
-       u64 status;
-       int handled;
-       int pmu_enabled;
-
-       cpuc = this_cpu_ptr(&cpu_hw_events);
-
-       /*
-        * Save the PMU state.
-        * It needs to be restored when leaving the handler.
-        */
-       pmu_enabled = cpuc->enabled;
-       /*
-        * No known reason to not always do late ACK,
-        * but just in case do it opt-in.
-        */
-       if (!x86_pmu.late_ack)
-               apic_write(APIC_LVTPC, APIC_DM_NMI);
-       intel_bts_disable_local();
-       cpuc->enabled = 0;
-       __intel_pmu_disable_all();
-       handled = intel_pmu_drain_bts_buffer();
-       handled += intel_bts_interrupt();
-       status = intel_pmu_get_status();
-       if (!status)
-               goto done;
-
-       loops = 0;
-again:
-       intel_pmu_lbr_read();
-       intel_pmu_ack_status(status);
-       if (++loops > 100) {
-               static bool warned = false;
-               if (!warned) {
-                       WARN(1, "perfevents: irq loop stuck!\n");
-                       perf_event_print_debug();
-                       warned = true;
-               }
-               intel_pmu_reset();
-               goto done;
-       }
+       struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
+       int bit;
+       int handled = 0;
 
        inc_irq_stat(apic_perf_irqs);
 
-
        /*
         * Ignore a range of extra bits in status that do not indicate
         * overflow by themselves.
@@ -2261,7 +2233,7 @@ again:
                    GLOBAL_STATUS_ASIF |
                    GLOBAL_STATUS_LBRS_FROZEN);
        if (!status)
-               goto done;
+               return 0;
        /*
         * In case multiple PEBS events are sampled at the same time,
         * it is possible to have GLOBAL_STATUS bit 62 set indicating
@@ -2331,6 +2303,146 @@ again:
                        x86_pmu_stop(event, 0);
        }
 
+       return handled;
+}
+
+static bool disable_counter_freezing;
+static int __init intel_perf_counter_freezing_setup(char *s)
+{
+       disable_counter_freezing = true;
+       pr_info("Intel PMU Counter freezing feature disabled\n");
+       return 1;
+}
+__setup("disable_counter_freezing", intel_perf_counter_freezing_setup);
+
+/*
+ * Simplified handler for Arch Perfmon v4:
+ * - We rely on counter freezing/unfreezing to enable/disable the PMU.
+ * This is done automatically on PMU ack.
+ * - Ack the PMU only after the APIC.
+ */
+
+static int intel_pmu_handle_irq_v4(struct pt_regs *regs)
+{
+       struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
+       int handled = 0;
+       bool bts = false;
+       u64 status;
+       int pmu_enabled = cpuc->enabled;
+       int loops = 0;
+
+       /* PMU has been disabled because of counter freezing */
+       cpuc->enabled = 0;
+       if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) {
+               bts = true;
+               intel_bts_disable_local();
+               handled = intel_pmu_drain_bts_buffer();
+               handled += intel_bts_interrupt();
+       }
+       status = intel_pmu_get_status();
+       if (!status)
+               goto done;
+again:
+       intel_pmu_lbr_read();
+       if (++loops > 100) {
+               static bool warned;
+
+               if (!warned) {
+                       WARN(1, "perfevents: irq loop stuck!\n");
+                       perf_event_print_debug();
+                       warned = true;
+               }
+               intel_pmu_reset();
+               goto done;
+       }
+
+
+       handled += handle_pmi_common(regs, status);
+done:
+       /* Ack the PMI in the APIC */
+       apic_write(APIC_LVTPC, APIC_DM_NMI);
+
+       /*
+        * The counters start counting immediately while ack the status.
+        * Make it as close as possible to IRET. This avoids bogus
+        * freezing on Skylake CPUs.
+        */
+       if (status) {
+               intel_pmu_ack_status(status);
+       } else {
+               /*
+                * CPU may issues two PMIs very close to each other.
+                * When the PMI handler services the first one, the
+                * GLOBAL_STATUS is already updated to reflect both.
+                * When it IRETs, the second PMI is immediately
+                * handled and it sees clear status. At the meantime,
+                * there may be a third PMI, because the freezing bit
+                * isn't set since the ack in first PMI handlers.
+                * Double check if there is more work to be done.
+                */
+               status = intel_pmu_get_status();
+               if (status)
+                       goto again;
+       }
+
+       if (bts)
+               intel_bts_enable_local();
+       cpuc->enabled = pmu_enabled;
+       return handled;
+}
+
+/*
+ * This handler is triggered by the local APIC, so the APIC IRQ handling
+ * rules apply:
+ */
+static int intel_pmu_handle_irq(struct pt_regs *regs)
+{
+       struct cpu_hw_events *cpuc;
+       int loops;
+       u64 status;
+       int handled;
+       int pmu_enabled;
+
+       cpuc = this_cpu_ptr(&cpu_hw_events);
+
+       /*
+        * Save the PMU state.
+        * It needs to be restored when leaving the handler.
+        */
+       pmu_enabled = cpuc->enabled;
+       /*
+        * No known reason to not always do late ACK,
+        * but just in case do it opt-in.
+        */
+       if (!x86_pmu.late_ack)
+               apic_write(APIC_LVTPC, APIC_DM_NMI);
+       intel_bts_disable_local();
+       cpuc->enabled = 0;
+       __intel_pmu_disable_all();
+       handled = intel_pmu_drain_bts_buffer();
+       handled += intel_bts_interrupt();
+       status = intel_pmu_get_status();
+       if (!status)
+               goto done;
+
+       loops = 0;
+again:
+       intel_pmu_lbr_read();
+       intel_pmu_ack_status(status);
+       if (++loops > 100) {
+               static bool warned;
+
+               if (!warned) {
+                       WARN(1, "perfevents: irq loop stuck!\n");
+                       perf_event_print_debug();
+                       warned = true;
+               }
+               intel_pmu_reset();
+               goto done;
+       }
+
+       handled += handle_pmi_common(regs, status);
+
        /*
         * Repeat if there is more work to be done:
         */
@@ -3350,6 +3462,9 @@ static void intel_pmu_cpu_starting(int cpu)
        if (x86_pmu.version > 1)
                flip_smm_bit(&x86_pmu.attr_freeze_on_smi);
 
+       if (x86_pmu.counter_freezing)
+               enable_counter_freeze();
+
        if (!cpuc->shared_regs)
                return;
 
@@ -3421,6 +3536,9 @@ static void intel_pmu_cpu_dying(int cpu)
        free_excl_cntrs(cpu);
 
        fini_debug_store_on_cpu(cpu);
+
+       if (x86_pmu.counter_freezing)
+               disable_counter_freeze();
 }
 
 static void intel_pmu_sched_task(struct perf_event_context *ctx,
@@ -3725,6 +3843,40 @@ static __init void intel_nehalem_quirk(void)
        }
 }
 
+static bool intel_glp_counter_freezing_broken(int cpu)
+{
+       u32 rev = UINT_MAX; /* default to broken for unknown stepping */
+
+       switch (cpu_data(cpu).x86_stepping) {
+       case 1:
+               rev = 0x28;
+               break;
+       case 8:
+               rev = 0x6;
+               break;
+       }
+
+       return (cpu_data(cpu).microcode < rev);
+}
+
+static __init void intel_glp_counter_freezing_quirk(void)
+{
+       /* Check if it's already disabled */
+       if (disable_counter_freezing)
+               return;
+
+       /*
+        * If the system starts with the wrong ucode, leave the
+        * counter-freezing feature permanently disabled.
+        */
+       if (intel_glp_counter_freezing_broken(raw_smp_processor_id())) {
+               pr_info("PMU counter freezing disabled due to CPU errata,"
+                       "please upgrade microcode\n");
+               x86_pmu.counter_freezing = false;
+               x86_pmu.handle_irq = intel_pmu_handle_irq;
+       }
+}
+
 /*
  * enable software workaround for errata:
  * SNB: BJ122
@@ -3764,8 +3916,6 @@ EVENT_ATTR_STR(cycles-t,  cycles_t,       "event=0x3c,in_tx=1");
 EVENT_ATTR_STR(cycles-ct,      cycles_ct,      "event=0x3c,in_tx=1,in_tx_cp=1");
 
 static struct attribute *hsw_events_attrs[] = {
-       EVENT_PTR(mem_ld_hsw),
-       EVENT_PTR(mem_st_hsw),
        EVENT_PTR(td_slots_issued),
        EVENT_PTR(td_slots_retired),
        EVENT_PTR(td_fetch_bubbles),
@@ -3776,6 +3926,12 @@ static struct attribute *hsw_events_attrs[] = {
        NULL
 };
 
+static struct attribute *hsw_mem_events_attrs[] = {
+       EVENT_PTR(mem_ld_hsw),
+       EVENT_PTR(mem_st_hsw),
+       NULL,
+};
+
 static struct attribute *hsw_tsx_events_attrs[] = {
        EVENT_PTR(tx_start),
        EVENT_PTR(tx_commit),
@@ -3792,13 +3948,6 @@ static struct attribute *hsw_tsx_events_attrs[] = {
        NULL
 };
 
-static __init struct attribute **get_hsw_events_attrs(void)
-{
-       return boot_cpu_has(X86_FEATURE_RTM) ?
-               merge_attr(hsw_events_attrs, hsw_tsx_events_attrs) :
-               hsw_events_attrs;
-}
-
 static ssize_t freeze_on_smi_show(struct device *cdev,
                                  struct device_attribute *attr,
                                  char *buf)
@@ -3875,9 +4024,32 @@ static struct attribute *intel_pmu_attrs[] = {
        NULL,
 };
 
+static __init struct attribute **
+get_events_attrs(struct attribute **base,
+                struct attribute **mem,
+                struct attribute **tsx)
+{
+       struct attribute **attrs = base;
+       struct attribute **old;
+
+       if (mem && x86_pmu.pebs)
+               attrs = merge_attr(attrs, mem);
+
+       if (tsx && boot_cpu_has(X86_FEATURE_RTM)) {
+               old = attrs;
+               attrs = merge_attr(attrs, tsx);
+               if (old != base)
+                       kfree(old);
+       }
+
+       return attrs;
+}
+
 __init int intel_pmu_init(void)
 {
        struct attribute **extra_attr = NULL;
+       struct attribute **mem_attr = NULL;
+       struct attribute **tsx_attr = NULL;
        struct attribute **to_free = NULL;
        union cpuid10_edx edx;
        union cpuid10_eax eax;
@@ -3935,6 +4107,9 @@ __init int intel_pmu_init(void)
                        max((int)edx.split.num_counters_fixed, assume);
        }
 
+       if (version >= 4)
+               x86_pmu.counter_freezing = !disable_counter_freezing;
+
        if (boot_cpu_has(X86_FEATURE_PDCM)) {
                u64 capabilities;
 
@@ -3986,7 +4161,7 @@ __init int intel_pmu_init(void)
                x86_pmu.enable_all = intel_pmu_nhm_enable_all;
                x86_pmu.extra_regs = intel_nehalem_extra_regs;
 
-               x86_pmu.cpu_events = nhm_events_attrs;
+               mem_attr = nhm_mem_events_attrs;
 
                /* UOPS_ISSUED.STALLED_CYCLES */
                intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4004,11 +4179,11 @@ __init int intel_pmu_init(void)
                name = "nehalem";
                break;
 
-       case INTEL_FAM6_ATOM_PINEVIEW:
-       case INTEL_FAM6_ATOM_LINCROFT:
-       case INTEL_FAM6_ATOM_PENWELL:
-       case INTEL_FAM6_ATOM_CLOVERVIEW:
-       case INTEL_FAM6_ATOM_CEDARVIEW:
+       case INTEL_FAM6_ATOM_BONNELL:
+       case INTEL_FAM6_ATOM_BONNELL_MID:
+       case INTEL_FAM6_ATOM_SALTWELL:
+       case INTEL_FAM6_ATOM_SALTWELL_MID:
+       case INTEL_FAM6_ATOM_SALTWELL_TABLET:
                memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
                       sizeof(hw_cache_event_ids));
 
@@ -4021,9 +4196,11 @@ __init int intel_pmu_init(void)
                name = "bonnell";
                break;
 
-       case INTEL_FAM6_ATOM_SILVERMONT1:
-       case INTEL_FAM6_ATOM_SILVERMONT2:
+       case INTEL_FAM6_ATOM_SILVERMONT:
+       case INTEL_FAM6_ATOM_SILVERMONT_X:
+       case INTEL_FAM6_ATOM_SILVERMONT_MID:
        case INTEL_FAM6_ATOM_AIRMONT:
+       case INTEL_FAM6_ATOM_AIRMONT_MID:
                memcpy(hw_cache_event_ids, slm_hw_cache_event_ids,
                        sizeof(hw_cache_event_ids));
                memcpy(hw_cache_extra_regs, slm_hw_cache_extra_regs,
@@ -4042,7 +4219,7 @@ __init int intel_pmu_init(void)
                break;
 
        case INTEL_FAM6_ATOM_GOLDMONT:
-       case INTEL_FAM6_ATOM_DENVERTON:
+       case INTEL_FAM6_ATOM_GOLDMONT_X:
                memcpy(hw_cache_event_ids, glm_hw_cache_event_ids,
                       sizeof(hw_cache_event_ids));
                memcpy(hw_cache_extra_regs, glm_hw_cache_extra_regs,
@@ -4068,7 +4245,8 @@ __init int intel_pmu_init(void)
                name = "goldmont";
                break;
 
-       case INTEL_FAM6_ATOM_GEMINI_LAKE:
+       case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
+               x86_add_quirk(intel_glp_counter_freezing_quirk);
                memcpy(hw_cache_event_ids, glp_hw_cache_event_ids,
                       sizeof(hw_cache_event_ids));
                memcpy(hw_cache_extra_regs, glp_hw_cache_extra_regs,
@@ -4112,7 +4290,7 @@ __init int intel_pmu_init(void)
                x86_pmu.extra_regs = intel_westmere_extra_regs;
                x86_pmu.flags |= PMU_FL_HAS_RSP_1;
 
-               x86_pmu.cpu_events = nhm_events_attrs;
+               mem_attr = nhm_mem_events_attrs;
 
                /* UOPS_ISSUED.STALLED_CYCLES */
                intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4152,6 +4330,7 @@ __init int intel_pmu_init(void)
                x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
 
                x86_pmu.cpu_events = snb_events_attrs;
+               mem_attr = snb_mem_events_attrs;
 
                /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
                intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4192,6 +4371,7 @@ __init int intel_pmu_init(void)
                x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
 
                x86_pmu.cpu_events = snb_events_attrs;
+               mem_attr = snb_mem_events_attrs;
 
                /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
                intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
@@ -4226,10 +4406,12 @@ __init int intel_pmu_init(void)
 
                x86_pmu.hw_config = hsw_hw_config;
                x86_pmu.get_event_constraints = hsw_get_event_constraints;
-               x86_pmu.cpu_events = get_hsw_events_attrs();
+               x86_pmu.cpu_events = hsw_events_attrs;
                x86_pmu.lbr_double_abort = true;
                extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
                        hsw_format_attr : nhm_format_attr;
+               mem_attr = hsw_mem_events_attrs;
+               tsx_attr = hsw_tsx_events_attrs;
                pr_cont("Haswell events, ");
                name = "haswell";
                break;
@@ -4265,10 +4447,12 @@ __init int intel_pmu_init(void)
 
                x86_pmu.hw_config = hsw_hw_config;
                x86_pmu.get_event_constraints = hsw_get_event_constraints;
-               x86_pmu.cpu_events = get_hsw_events_attrs();
+               x86_pmu.cpu_events = hsw_events_attrs;
                x86_pmu.limit_period = bdw_limit_period;
                extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
                        hsw_format_attr : nhm_format_attr;
+               mem_attr = hsw_mem_events_attrs;
+               tsx_attr = hsw_tsx_events_attrs;
                pr_cont("Broadwell events, ");
                name = "broadwell";
                break;
@@ -4324,7 +4508,9 @@ __init int intel_pmu_init(void)
                        hsw_format_attr : nhm_format_attr;
                extra_attr = merge_attr(extra_attr, skl_format_attr);
                to_free = extra_attr;
-               x86_pmu.cpu_events = get_hsw_events_attrs();
+               x86_pmu.cpu_events = hsw_events_attrs;
+               mem_attr = hsw_mem_events_attrs;
+               tsx_attr = hsw_tsx_events_attrs;
                intel_pmu_pebs_data_source_skl(
                        boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X);
                pr_cont("Skylake events, ");
@@ -4357,6 +4543,9 @@ __init int intel_pmu_init(void)
                WARN_ON(!x86_pmu.format_attrs);
        }
 
+       x86_pmu.cpu_events = get_events_attrs(x86_pmu.cpu_events,
+                                             mem_attr, tsx_attr);
+
        if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) {
                WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!",
                     x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC);
@@ -4431,6 +4620,13 @@ __init int intel_pmu_init(void)
                pr_cont("full-width counters, ");
        }
 
+       /*
+        * For arch perfmon 4 use counter freezing to avoid
+        * several MSR accesses in the PMI.
+        */
+       if (x86_pmu.counter_freezing)
+               x86_pmu.handle_irq = intel_pmu_handle_irq_v4;
+
        kfree(to_free);
        return 0;
 }
index 9f8084f18d58e440931f593d42cc825bbc00cfb8..d2e780705c5a2036952417c21ba20308c54dc5c1 100644 (file)
@@ -559,8 +559,8 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {
 
        X86_CSTATES_MODEL(INTEL_FAM6_HASWELL_ULT, hswult_cstates),
 
-       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT1, slm_cstates),
-       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT2, slm_cstates),
+       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT, slm_cstates),
+       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_SILVERMONT_X, slm_cstates),
        X86_CSTATES_MODEL(INTEL_FAM6_ATOM_AIRMONT,     slm_cstates),
 
        X86_CSTATES_MODEL(INTEL_FAM6_BROADWELL_CORE,   snb_cstates),
@@ -581,9 +581,9 @@ static const struct x86_cpu_id intel_cstates_match[] __initconst = {
        X86_CSTATES_MODEL(INTEL_FAM6_XEON_PHI_KNM, knl_cstates),
 
        X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT, glm_cstates),
-       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_DENVERTON, glm_cstates),
+       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT_X, glm_cstates),
 
-       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GEMINI_LAKE, glm_cstates),
+       X86_CSTATES_MODEL(INTEL_FAM6_ATOM_GOLDMONT_PLUS, glm_cstates),
        { },
 };
 MODULE_DEVICE_TABLE(x86cpu, intel_cstates_match);
index 8d016ce5b80dcc0ab1102c0e864bb706297d6de4..3a0aa83cbd0744ce0193f55b1b73178614280c7a 100644 (file)
@@ -95,7 +95,7 @@ static ssize_t pt_cap_show(struct device *cdev,
        return snprintf(buf, PAGE_SIZE, "%x\n", pt_cap_get(cap));
 }
 
-static struct attribute_group pt_cap_group = {
+static struct attribute_group pt_cap_group __ro_after_init = {
        .name   = "caps",
 };
 
index 32f3e9423e99ea40b23ee9196003fc0de2546829..91039ffed63334828717ac4647d2c353d95a39ab 100644 (file)
@@ -777,9 +777,9 @@ static const struct x86_cpu_id rapl_cpu_match[] __initconst = {
        X86_RAPL_MODEL_MATCH(INTEL_FAM6_CANNONLAKE_MOBILE,  skl_rapl_init),
 
        X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT, hsw_rapl_init),
-       X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_DENVERTON, hsw_rapl_init),
+       X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT_X, hsw_rapl_init),
 
-       X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GEMINI_LAKE, hsw_rapl_init),
+       X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT_PLUS, hsw_rapl_init),
        {},
 };
 
index b4771a6ddbc1b6686549ee306d3299d68a8b2e3e..1b9f85abf9bc10c3b058c244b051186cbb8fd309 100644 (file)
@@ -69,14 +69,14 @@ static bool test_intel(int idx)
        case INTEL_FAM6_BROADWELL_GT3E:
        case INTEL_FAM6_BROADWELL_X:
 
-       case INTEL_FAM6_ATOM_SILVERMONT1:
-       case INTEL_FAM6_ATOM_SILVERMONT2:
+       case INTEL_FAM6_ATOM_SILVERMONT:
+       case INTEL_FAM6_ATOM_SILVERMONT_X:
        case INTEL_FAM6_ATOM_AIRMONT:
 
        case INTEL_FAM6_ATOM_GOLDMONT:
-       case INTEL_FAM6_ATOM_DENVERTON:
+       case INTEL_FAM6_ATOM_GOLDMONT_X:
 
-       case INTEL_FAM6_ATOM_GEMINI_LAKE:
+       case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
 
        case INTEL_FAM6_XEON_PHI_KNL:
        case INTEL_FAM6_XEON_PHI_KNM:
index 156286335351a43b6692ab07747e97e1fb97b3b2..adae087cecdda0b6b1aeb78bb51fdb55a61696ed 100644 (file)
@@ -560,9 +560,11 @@ struct x86_pmu {
        struct event_constraint *event_constraints;
        struct x86_pmu_quirk *quirks;
        int             perfctr_second_write;
-       bool            late_ack;
        u64             (*limit_period)(struct perf_event *event, u64 l);
 
+       /* PMI handler bits */
+       unsigned int    late_ack                :1,
+                       counter_freezing        :1;
        /*
         * sysfs attrs
         */
index 7ed08a7c3398dc087a580abe82dd31761a8478f0..0dd6b0f4000e86d80be7b38b29f33bfa9ac61e8f 100644 (file)
@@ -8,9 +8,6 @@
  * The "_X" parts are generally the EP and EX Xeons, or the
  * "Extreme" ones, like Broadwell-E.
  *
- * Things ending in "2" are usually because we have no better
- * name for them.  There's no processor called "SILVERMONT2".
- *
  * While adding a new CPUID for a new microarchitecture, add a new
  * group to keep logically sorted out in chronological order. Within
  * that group keep the CPUID for the variants sorted by model number.
 
 /* "Small Core" Processors (Atom) */
 
-#define INTEL_FAM6_ATOM_PINEVIEW       0x1C
-#define INTEL_FAM6_ATOM_LINCROFT       0x26
-#define INTEL_FAM6_ATOM_PENWELL                0x27
-#define INTEL_FAM6_ATOM_CLOVERVIEW     0x35
-#define INTEL_FAM6_ATOM_CEDARVIEW      0x36
-#define INTEL_FAM6_ATOM_SILVERMONT1    0x37 /* BayTrail/BYT / Valleyview */
-#define INTEL_FAM6_ATOM_SILVERMONT2    0x4D /* Avaton/Rangely */
-#define INTEL_FAM6_ATOM_AIRMONT                0x4C /* CherryTrail / Braswell */
-#define INTEL_FAM6_ATOM_MERRIFIELD     0x4A /* Tangier */
-#define INTEL_FAM6_ATOM_MOOREFIELD     0x5A /* Anniedale */
-#define INTEL_FAM6_ATOM_GOLDMONT       0x5C
-#define INTEL_FAM6_ATOM_DENVERTON      0x5F /* Goldmont Microserver */
-#define INTEL_FAM6_ATOM_GEMINI_LAKE    0x7A
+#define INTEL_FAM6_ATOM_BONNELL                0x1C /* Diamondville, Pineview */
+#define INTEL_FAM6_ATOM_BONNELL_MID    0x26 /* Silverthorne, Lincroft */
+
+#define INTEL_FAM6_ATOM_SALTWELL       0x36 /* Cedarview */
+#define INTEL_FAM6_ATOM_SALTWELL_MID   0x27 /* Penwell */
+#define INTEL_FAM6_ATOM_SALTWELL_TABLET        0x35 /* Cloverview */
+
+#define INTEL_FAM6_ATOM_SILVERMONT     0x37 /* Bay Trail, Valleyview */
+#define INTEL_FAM6_ATOM_SILVERMONT_X   0x4D /* Avaton, Rangely */
+#define INTEL_FAM6_ATOM_SILVERMONT_MID 0x4A /* Merriefield */
+
+#define INTEL_FAM6_ATOM_AIRMONT                0x4C /* Cherry Trail, Braswell */
+#define INTEL_FAM6_ATOM_AIRMONT_MID    0x5A /* Moorefield */
+
+#define INTEL_FAM6_ATOM_GOLDMONT       0x5C /* Apollo Lake */
+#define INTEL_FAM6_ATOM_GOLDMONT_X     0x5F /* Denverton */
+#define INTEL_FAM6_ATOM_GOLDMONT_PLUS  0x7A /* Gemini Lake */
 
 /* Xeon Phi */
 
index 4731f0cf97c5c0058ec41cff870cdc5fef0eec67..80f4a4f38c79ca4c9fe10f26c9748f4804d3b395 100644 (file)
 #define DEBUGCTLMSR_BTS_OFF_OS         (1UL <<  9)
 #define DEBUGCTLMSR_BTS_OFF_USR                (1UL << 10)
 #define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI (1UL << 11)
+#define DEBUGCTLMSR_FREEZE_PERFMON_ON_PMI      (1UL << 12)
 #define DEBUGCTLMSR_FREEZE_IN_SMM_BIT  14
 #define DEBUGCTLMSR_FREEZE_IN_SMM      (1UL << DEBUGCTLMSR_FREEZE_IN_SMM_BIT)
 
index 78241b736f2a04aa4ccac261727ecd8798042cda..8bdf74902293489a031aa300a605447e83b96341 100644 (file)
@@ -278,6 +278,7 @@ struct perf_guest_switch_msr {
 extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr);
 extern void perf_get_x86_pmu_capability(struct x86_pmu_capability *cap);
 extern void perf_check_microcode(void);
+extern int x86_perf_rdpmc_index(struct perf_event *event);
 #else
 static inline struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr)
 {
index 5e58a74bfd3a099dda4472031e0c3c293b2655cc..25f49af1b13c16cf562b6e9e4a4f28f88f87e3ea 100644 (file)
@@ -238,24 +238,52 @@ static inline int regs_within_kernel_stack(struct pt_regs *regs,
                (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
 }
 
+/**
+ * regs_get_kernel_stack_nth_addr() - get the address of the Nth entry on stack
+ * @regs:      pt_regs which contains kernel stack pointer.
+ * @n:         stack entry number.
+ *
+ * regs_get_kernel_stack_nth() returns the address of the @n th entry of the
+ * kernel stack which is specified by @regs. If the @n th entry is NOT in
+ * the kernel stack, this returns NULL.
+ */
+static inline unsigned long *regs_get_kernel_stack_nth_addr(struct pt_regs *regs, unsigned int n)
+{
+       unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
+
+       addr += n;
+       if (regs_within_kernel_stack(regs, (unsigned long)addr))
+               return addr;
+       else
+               return NULL;
+}
+
+/* To avoid include hell, we can't include uaccess.h */
+extern long probe_kernel_read(void *dst, const void *src, size_t size);
+
 /**
  * regs_get_kernel_stack_nth() - get Nth entry of the stack
  * @regs:      pt_regs which contains kernel stack pointer.
  * @n:         stack entry number.
  *
  * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
- * is specified by @regs. If the @n th entry is NOT in the kernel stack,
+ * is specified by @regs. If the @n th entry is NOT in the kernel stack
  * this returns 0.
  */
 static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
                                                      unsigned int n)
 {
-       unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
-       addr += n;
-       if (regs_within_kernel_stack(regs, (unsigned long)addr))
-               return *addr;
-       else
-               return 0;
+       unsigned long *addr;
+       unsigned long val;
+       long ret;
+
+       addr = regs_get_kernel_stack_nth_addr(regs, n);
+       if (addr) {
+               ret = probe_kernel_read(&val, addr, sizeof(val));
+               if (!ret)
+                       return val;
+       }
+       return 0;
 }
 
 #define arch_has_single_step() (1)
index 44c4ef3d989b59b7bd98ebf617f8e5ee1d2a9548..10e5ccfa9278025c3a04ecbbd94e3e2cfe7a1583 100644 (file)
@@ -949,11 +949,11 @@ static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
 }
 
 static const __initconst struct x86_cpu_id cpu_no_speculation[] = {
-       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_CEDARVIEW,   X86_FEATURE_ANY },
-       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_CLOVERVIEW,  X86_FEATURE_ANY },
-       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_LINCROFT,    X86_FEATURE_ANY },
-       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_PENWELL,     X86_FEATURE_ANY },
-       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_PINEVIEW,    X86_FEATURE_ANY },
+       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_SALTWELL,    X86_FEATURE_ANY },
+       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_SALTWELL_TABLET,     X86_FEATURE_ANY },
+       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_BONNELL_MID, X86_FEATURE_ANY },
+       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_SALTWELL_MID,        X86_FEATURE_ANY },
+       { X86_VENDOR_INTEL,     6, INTEL_FAM6_ATOM_BONNELL,     X86_FEATURE_ANY },
        { X86_VENDOR_CENTAUR,   5 },
        { X86_VENDOR_INTEL,     5 },
        { X86_VENDOR_NSC,       5 },
@@ -968,10 +968,10 @@ static const __initconst struct x86_cpu_id cpu_no_meltdown[] = {
 
 /* Only list CPUs which speculate but are non susceptible to SSB */
 static const __initconst struct x86_cpu_id cpu_no_spec_store_bypass[] = {
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT1     },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT      },
        { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_AIRMONT         },
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT    },
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_MERRIFIELD      },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT_X    },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT_MID  },
        { X86_VENDOR_INTEL,     6,      INTEL_FAM6_CORE_YONAH           },
        { X86_VENDOR_INTEL,     6,      INTEL_FAM6_XEON_PHI_KNL         },
        { 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[] = {
 
 static const __initconst struct x86_cpu_id cpu_no_l1tf[] = {
        /* in addition to cpu_no_speculation */
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT1     },
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT    },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT      },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT_X    },
        { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_AIRMONT         },
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_MERRIFIELD      },
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_MOOREFIELD      },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_SILVERMONT_MID  },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_AIRMONT_MID     },
        { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_GOLDMONT        },
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_DENVERTON       },
-       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_GEMINI_LAKE     },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_GOLDMONT_X      },
+       { X86_VENDOR_INTEL,     6,      INTEL_FAM6_ATOM_GOLDMONT_PLUS   },
        { X86_VENDOR_INTEL,     6,      INTEL_FAM6_XEON_PHI_KNL         },
        { X86_VENDOR_INTEL,     6,      INTEL_FAM6_XEON_PHI_KNM         },
        {}
index abb71ac704433cea9f2eca68b8f3ed60566c22da..44272b7107ad97e01558519f25f7aea02f6574ae 100644 (file)
@@ -485,9 +485,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
        size_t tsize;
 
        if (is_llc_occupancy_enabled()) {
-               d->rmid_busy_llc = kcalloc(BITS_TO_LONGS(r->num_rmid),
-                                          sizeof(unsigned long),
-                                          GFP_KERNEL);
+               d->rmid_busy_llc = bitmap_zalloc(r->num_rmid, GFP_KERNEL);
                if (!d->rmid_busy_llc)
                        return -ENOMEM;
                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)
                tsize = sizeof(*d->mbm_total);
                d->mbm_total = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
                if (!d->mbm_total) {
-                       kfree(d->rmid_busy_llc);
+                       bitmap_free(d->rmid_busy_llc);
                        return -ENOMEM;
                }
        }
@@ -504,7 +502,7 @@ static int domain_setup_mon_state(struct rdt_resource *r, struct rdt_domain *d)
                tsize = sizeof(*d->mbm_local);
                d->mbm_local = kcalloc(r->num_rmid, tsize, GFP_KERNEL);
                if (!d->mbm_local) {
-                       kfree(d->rmid_busy_llc);
+                       bitmap_free(d->rmid_busy_llc);
                        kfree(d->mbm_total);
                        return -ENOMEM;
                }
@@ -610,9 +608,16 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
                        cancel_delayed_work(&d->cqm_limbo);
                }
 
+               /*
+                * rdt_domain "d" is going to be freed below, so clear
+                * its pointer from pseudo_lock_region struct.
+                */
+               if (d->plr)
+                       d->plr->d = NULL;
+
                kfree(d->ctrl_val);
                kfree(d->mbps_val);
-               kfree(d->rmid_busy_llc);
+               bitmap_free(d->rmid_busy_llc);
                kfree(d->mbm_total);
                kfree(d->mbm_local);
                kfree(d);
index 0f53049719cd670f3b31a444863f5af378645b7d..27937458c231b62772bf956b1bc584fc030281ba 100644 (file)
@@ -404,8 +404,16 @@ int rdtgroup_schemata_show(struct kernfs_open_file *of,
                        for_each_alloc_enabled_rdt_resource(r)
                                seq_printf(s, "%s:uninitialized\n", r->name);
                } else if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
-                       seq_printf(s, "%s:%d=%x\n", rdtgrp->plr->r->name,
-                                  rdtgrp->plr->d->id, rdtgrp->plr->cbm);
+                       if (!rdtgrp->plr->d) {
+                               rdt_last_cmd_clear();
+                               rdt_last_cmd_puts("Cache domain offline\n");
+                               ret = -ENODEV;
+                       } else {
+                               seq_printf(s, "%s:%d=%x\n",
+                                          rdtgrp->plr->r->name,
+                                          rdtgrp->plr->d->id,
+                                          rdtgrp->plr->cbm);
+                       }
                } else {
                        closid = rdtgrp->closid;
                        for_each_alloc_enabled_rdt_resource(r) {
index f8c260d522ca045f33a675e47a225c908854be5d..815b4e92522ccfffb2864bddb4d67e6efa6e887b 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/debugfs.h>
 #include <linux/kthread.h>
 #include <linux/mman.h>
+#include <linux/perf_event.h>
 #include <linux/pm_qos.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
@@ -26,6 +27,7 @@
 #include <asm/intel_rdt_sched.h>
 #include <asm/perf_event.h>
 
+#include "../../events/perf_event.h" /* For X86_CONFIG() */
 #include "intel_rdt.h"
 
 #define CREATE_TRACE_POINTS
@@ -91,7 +93,7 @@ static u64 get_prefetch_disable_bits(void)
                 */
                return 0xF;
        case INTEL_FAM6_ATOM_GOLDMONT:
-       case INTEL_FAM6_ATOM_GEMINI_LAKE:
+       case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
                /*
                 * SDM defines bits of MSR_MISC_FEATURE_CONTROL register
                 * as:
@@ -106,16 +108,6 @@ static u64 get_prefetch_disable_bits(void)
        return 0;
 }
 
-/*
- * Helper to write 64bit value to MSR without tracing. Used when
- * use of the cache should be restricted and use of registers used
- * for local variables avoided.
- */
-static inline void pseudo_wrmsrl_notrace(unsigned int msr, u64 val)
-{
-       __wrmsr(msr, (u32)(val & 0xffffffffULL), (u32)(val >> 32));
-}
-
 /**
  * pseudo_lock_minor_get - Obtain available minor number
  * @minor: Pointer to where new minor number will be stored
@@ -888,31 +880,14 @@ static int measure_cycles_lat_fn(void *_plr)
        struct pseudo_lock_region *plr = _plr;
        unsigned long i;
        u64 start, end;
-#ifdef CONFIG_KASAN
-       /*
-        * The registers used for local register variables are also used
-        * when KASAN is active. When KASAN is active we use a regular
-        * variable to ensure we always use a valid pointer to access memory.
-        * The cost is that accessing this pointer, which could be in
-        * cache, will be included in the measurement of memory read latency.
-        */
        void *mem_r;
-#else
-#ifdef CONFIG_X86_64
-       register void *mem_r asm("rbx");
-#else
-       register void *mem_r asm("ebx");
-#endif /* CONFIG_X86_64 */
-#endif /* CONFIG_KASAN */
 
        local_irq_disable();
        /*
-        * The wrmsr call may be reordered with the assignment below it.
-        * Call wrmsr as directly as possible to avoid tracing clobbering
-        * local register variable used for memory pointer.
+        * Disable hardware prefetchers.
         */
-       __wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
-       mem_r = plr->kmem;
+       wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
+       mem_r = READ_ONCE(plr->kmem);
        /*
         * Dummy execute of the time measurement to load the needed
         * instructions into the L1 instruction cache.
@@ -934,157 +909,240 @@ static int measure_cycles_lat_fn(void *_plr)
        return 0;
 }
 
-static int measure_cycles_perf_fn(void *_plr)
+/*
+ * Create a perf_event_attr for the hit and miss perf events that will
+ * be used during the performance measurement. A perf_event maintains
+ * a pointer to its perf_event_attr so a unique attribute structure is
+ * created for each perf_event.
+ *
+ * The actual configuration of the event is set right before use in order
+ * to use the X86_CONFIG macro.
+ */
+static struct perf_event_attr perf_miss_attr = {
+       .type           = PERF_TYPE_RAW,
+       .size           = sizeof(struct perf_event_attr),
+       .pinned         = 1,
+       .disabled       = 0,
+       .exclude_user   = 1,
+};
+
+static struct perf_event_attr perf_hit_attr = {
+       .type           = PERF_TYPE_RAW,
+       .size           = sizeof(struct perf_event_attr),
+       .pinned         = 1,
+       .disabled       = 0,
+       .exclude_user   = 1,
+};
+
+struct residency_counts {
+       u64 miss_before, hits_before;
+       u64 miss_after,  hits_after;
+};
+
+static int measure_residency_fn(struct perf_event_attr *miss_attr,
+                               struct perf_event_attr *hit_attr,
+                               struct pseudo_lock_region *plr,
+                               struct residency_counts *counts)
 {
-       unsigned long long l3_hits = 0, l3_miss = 0;
-       u64 l3_hit_bits = 0, l3_miss_bits = 0;
-       struct pseudo_lock_region *plr = _plr;
-       unsigned long long l2_hits, l2_miss;
-       u64 l2_hit_bits, l2_miss_bits;
-       unsigned long i;
-#ifdef CONFIG_KASAN
-       /*
-        * The registers used for local register variables are also used
-        * when KASAN is active. When KASAN is active we use regular variables
-        * at the cost of including cache access latency to these variables
-        * in the measurements.
-        */
+       u64 hits_before = 0, hits_after = 0, miss_before = 0, miss_after = 0;
+       struct perf_event *miss_event, *hit_event;
+       int hit_pmcnum, miss_pmcnum;
        unsigned int line_size;
        unsigned int size;
+       unsigned long i;
        void *mem_r;
-#else
-       register unsigned int line_size asm("esi");
-       register unsigned int size asm("edi");
-#ifdef CONFIG_X86_64
-       register void *mem_r asm("rbx");
-#else
-       register void *mem_r asm("ebx");
-#endif /* CONFIG_X86_64 */
-#endif /* CONFIG_KASAN */
+       u64 tmp;
+
+       miss_event = perf_event_create_kernel_counter(miss_attr, plr->cpu,
+                                                     NULL, NULL, NULL);
+       if (IS_ERR(miss_event))
+               goto out;
+
+       hit_event = perf_event_create_kernel_counter(hit_attr, plr->cpu,
+                                                    NULL, NULL, NULL);
+       if (IS_ERR(hit_event))
+               goto out_miss;
+
+       local_irq_disable();
+       /*
+        * Check any possible error state of events used by performing
+        * one local read.
+        */
+       if (perf_event_read_local(miss_event, &tmp, NULL, NULL)) {
+               local_irq_enable();
+               goto out_hit;
+       }
+       if (perf_event_read_local(hit_event, &tmp, NULL, NULL)) {
+               local_irq_enable();
+               goto out_hit;
+       }
+
+       /*
+        * Disable hardware prefetchers.
+        */
+       wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
+
+       /* Initialize rest of local variables */
+       /*
+        * Performance event has been validated right before this with
+        * interrupts disabled - it is thus safe to read the counter index.
+        */
+       miss_pmcnum = x86_perf_rdpmc_index(miss_event);
+       hit_pmcnum = x86_perf_rdpmc_index(hit_event);
+       line_size = READ_ONCE(plr->line_size);
+       mem_r = READ_ONCE(plr->kmem);
+       size = READ_ONCE(plr->size);
+
+       /*
+        * Read counter variables twice - first to load the instructions
+        * used in L1 cache, second to capture accurate value that does not
+        * include cache misses incurred because of instruction loads.
+        */
+       rdpmcl(hit_pmcnum, hits_before);
+       rdpmcl(miss_pmcnum, miss_before);
+       /*
+        * From SDM: Performing back-to-back fast reads are not guaranteed
+        * to be monotonic.
+        * Use LFENCE to ensure all previous instructions are retired
+        * before proceeding.
+        */
+       rmb();
+       rdpmcl(hit_pmcnum, hits_before);
+       rdpmcl(miss_pmcnum, miss_before);
+       /*
+        * Use LFENCE to ensure all previous instructions are retired
+        * before proceeding.
+        */
+       rmb();
+       for (i = 0; i < size; i += line_size) {
+               /*
+                * Add a barrier to prevent speculative execution of this
+                * loop reading beyond the end of the buffer.
+                */
+               rmb();
+               asm volatile("mov (%0,%1,1), %%eax\n\t"
+                            :
+                            : "r" (mem_r), "r" (i)
+                            : "%eax", "memory");
+       }
+       /*
+        * Use LFENCE to ensure all previous instructions are retired
+        * before proceeding.
+        */
+       rmb();
+       rdpmcl(hit_pmcnum, hits_after);
+       rdpmcl(miss_pmcnum, miss_after);
+       /*
+        * Use LFENCE to ensure all previous instructions are retired
+        * before proceeding.
+        */
+       rmb();
+       /* Re-enable hardware prefetchers */
+       wrmsr(MSR_MISC_FEATURE_CONTROL, 0x0, 0x0);
+       local_irq_enable();
+out_hit:
+       perf_event_release_kernel(hit_event);
+out_miss:
+       perf_event_release_kernel(miss_event);
+out:
+       /*
+        * All counts will be zero on failure.
+        */
+       counts->miss_before = miss_before;
+       counts->hits_before = hits_before;
+       counts->miss_after  = miss_after;
+       counts->hits_after  = hits_after;
+       return 0;
+}
+
+static int measure_l2_residency(void *_plr)
+{
+       struct pseudo_lock_region *plr = _plr;
+       struct residency_counts counts = {0};
 
        /*
         * Non-architectural event for the Goldmont Microarchitecture
         * from Intel x86 Architecture Software Developer Manual (SDM):
         * MEM_LOAD_UOPS_RETIRED D1H (event number)
         * Umask values:
-        *     L1_HIT   01H
         *     L2_HIT   02H
-        *     L1_MISS  08H
         *     L2_MISS  10H
-        *
-        * On Broadwell Microarchitecture the MEM_LOAD_UOPS_RETIRED event
-        * has two "no fix" errata associated with it: BDM35 and BDM100. On
-        * this platform we use the following events instead:
-        *  L2_RQSTS 24H (Documented in https://download.01.org/perfmon/BDW/)
-        *       REFERENCES FFH
-        *       MISS       3FH
-        *  LONGEST_LAT_CACHE 2EH (Documented in SDM)
-        *       REFERENCE 4FH
-        *       MISS      41H
         */
-
-       /*
-        * Start by setting flags for IA32_PERFEVTSELx:
-        *     OS  (Operating system mode)  0x2
-        *     INT (APIC interrupt enable)  0x10
-        *     EN  (Enable counter)         0x40
-        *
-        * Then add the Umask value and event number to select performance
-        * event.
-        */
-
        switch (boot_cpu_data.x86_model) {
        case INTEL_FAM6_ATOM_GOLDMONT:
-       case INTEL_FAM6_ATOM_GEMINI_LAKE:
-               l2_hit_bits = (0x52ULL << 16) | (0x2 << 8) | 0xd1;
-               l2_miss_bits = (0x52ULL << 16) | (0x10 << 8) | 0xd1;
-               break;
-       case INTEL_FAM6_BROADWELL_X:
-               /* On BDW the l2_hit_bits count references, not hits */
-               l2_hit_bits = (0x52ULL << 16) | (0xff << 8) | 0x24;
-               l2_miss_bits = (0x52ULL << 16) | (0x3f << 8) | 0x24;
-               /* On BDW the l3_hit_bits count references, not hits */
-               l3_hit_bits = (0x52ULL << 16) | (0x4f << 8) | 0x2e;
-               l3_miss_bits = (0x52ULL << 16) | (0x41 << 8) | 0x2e;
+       case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
+               perf_miss_attr.config = X86_CONFIG(.event = 0xd1,
+                                                  .umask = 0x10);
+               perf_hit_attr.config = X86_CONFIG(.event = 0xd1,
+                                                 .umask = 0x2);
                break;
        default:
                goto out;
        }
 
-       local_irq_disable();
+       measure_residency_fn(&perf_miss_attr, &perf_hit_attr, plr, &counts);
        /*
-        * Call wrmsr direcly to avoid the local register variables from
-        * being overwritten due to reordering of their assignment with
-        * the wrmsr calls.
+        * If a failure prevented the measurements from succeeding
+        * tracepoints will still be written and all counts will be zero.
         */
-       __wrmsr(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits, 0x0);
-       /* Disable events and reset counters */
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0, 0x0);
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 1, 0x0);
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0, 0x0);
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0 + 1, 0x0);
-       if (l3_hit_bits > 0) {
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 2, 0x0);
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 3, 0x0);
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0 + 2, 0x0);
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_PERFCTR0 + 3, 0x0);
-       }
-       /* Set and enable the L2 counters */
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0, l2_hit_bits);
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 1, l2_miss_bits);
-       if (l3_hit_bits > 0) {
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 2,
-                                     l3_hit_bits);
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 3,
-                                     l3_miss_bits);
-       }
-       mem_r = plr->kmem;
-       size = plr->size;
-       line_size = plr->line_size;
-       for (i = 0; i < size; i += line_size) {
-               asm volatile("mov (%0,%1,1), %%eax\n\t"
-                            :
-                            : "r" (mem_r), "r" (i)
-                            : "%eax", "memory");
-       }
+       trace_pseudo_lock_l2(counts.hits_after - counts.hits_before,
+                            counts.miss_after - counts.miss_before);
+out:
+       plr->thread_done = 1;
+       wake_up_interruptible(&plr->lock_thread_wq);
+       return 0;
+}
+
+static int measure_l3_residency(void *_plr)
+{
+       struct pseudo_lock_region *plr = _plr;
+       struct residency_counts counts = {0};
+
        /*
-        * Call wrmsr directly (no tracing) to not influence
-        * the cache access counters as they are disabled.
+        * On Broadwell Microarchitecture the MEM_LOAD_UOPS_RETIRED event
+        * has two "no fix" errata associated with it: BDM35 and BDM100. On
+        * this platform the following events are used instead:
+        * LONGEST_LAT_CACHE 2EH (Documented in SDM)
+        *       REFERENCE 4FH
+        *       MISS      41H
         */
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0,
-                             l2_hit_bits & ~(0x40ULL << 16));
-       pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 1,
-                             l2_miss_bits & ~(0x40ULL << 16));
-       if (l3_hit_bits > 0) {
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 2,
-                                     l3_hit_bits & ~(0x40ULL << 16));
-               pseudo_wrmsrl_notrace(MSR_ARCH_PERFMON_EVENTSEL0 + 3,
-                                     l3_miss_bits & ~(0x40ULL << 16));
-       }
-       l2_hits = native_read_pmc(0);
-       l2_miss = native_read_pmc(1);
-       if (l3_hit_bits > 0) {
-               l3_hits = native_read_pmc(2);
-               l3_miss = native_read_pmc(3);
+
+       switch (boot_cpu_data.x86_model) {
+       case INTEL_FAM6_BROADWELL_X:
+               /* On BDW the hit event counts references, not hits */
+               perf_hit_attr.config = X86_CONFIG(.event = 0x2e,
+                                                 .umask = 0x4f);
+               perf_miss_attr.config = X86_CONFIG(.event = 0x2e,
+                                                  .umask = 0x41);
+               break;
+       default:
+               goto out;
        }
-       wrmsr(MSR_MISC_FEATURE_CONTROL, 0x0, 0x0);
-       local_irq_enable();
+
+       measure_residency_fn(&perf_miss_attr, &perf_hit_attr, plr, &counts);
        /*
-        * On BDW we count references and misses, need to adjust. Sometimes
-        * the "hits" counter is a bit more than the references, for
-        * example, x references but x + 1 hits. To not report invalid
-        * hit values in this case we treat that as misses eaqual to
-        * references.
+        * If a failure prevented the measurements from succeeding
+        * tracepoints will still be written and all counts will be zero.
         */
-       if (boot_cpu_data.x86_model == INTEL_FAM6_BROADWELL_X)
-               l2_hits -= (l2_miss > l2_hits ? l2_hits : l2_miss);
-       trace_pseudo_lock_l2(l2_hits, l2_miss);
-       if (l3_hit_bits > 0) {
-               if (boot_cpu_data.x86_model == INTEL_FAM6_BROADWELL_X)
-                       l3_hits -= (l3_miss > l3_hits ? l3_hits : l3_miss);
-               trace_pseudo_lock_l3(l3_hits, l3_miss);
+
+       counts.miss_after -= counts.miss_before;
+       if (boot_cpu_data.x86_model == INTEL_FAM6_BROADWELL_X) {
+               /*
+                * On BDW references and misses are counted, need to adjust.
+                * Sometimes the "hits" counter is a bit more than the
+                * references, for example, x references but x + 1 hits.
+                * To not report invalid hit values in this case we treat
+                * that as misses equal to references.
+                */
+               /* First compute the number of cache references measured */
+               counts.hits_after -= counts.hits_before;
+               /* Next convert references to cache hits */
+               counts.hits_after -= min(counts.miss_after, counts.hits_after);
+       } else {
+               counts.hits_after -= counts.hits_before;
        }
 
+       trace_pseudo_lock_l3(counts.hits_after, counts.miss_after);
 out:
        plr->thread_done = 1;
        wake_up_interruptible(&plr->lock_thread_wq);
@@ -1116,6 +1174,11 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel)
                goto out;
        }
 
+       if (!plr->d) {
+               ret = -ENODEV;
+               goto out;
+       }
+
        plr->thread_done = 0;
        cpu = cpumask_first(&plr->d->cpu_mask);
        if (!cpu_online(cpu)) {
@@ -1123,13 +1186,20 @@ static int pseudo_lock_measure_cycles(struct rdtgroup *rdtgrp, int sel)
                goto out;
        }
 
+       plr->cpu = cpu;
+
        if (sel == 1)
                thread = kthread_create_on_node(measure_cycles_lat_fn, plr,
                                                cpu_to_node(cpu),
                                                "pseudo_lock_measure/%u",
                                                cpu);
        else if (sel == 2)
-               thread = kthread_create_on_node(measure_cycles_perf_fn, plr,
+               thread = kthread_create_on_node(measure_l2_residency, plr,
+                                               cpu_to_node(cpu),
+                                               "pseudo_lock_measure/%u",
+                                               cpu);
+       else if (sel == 3)
+               thread = kthread_create_on_node(measure_l3_residency, plr,
                                                cpu_to_node(cpu),
                                                "pseudo_lock_measure/%u",
                                                cpu);
@@ -1173,7 +1243,7 @@ static ssize_t pseudo_lock_measure_trigger(struct file *file,
        buf[buf_size] = '\0';
        ret = kstrtoint(buf, 10, &sel);
        if (ret == 0) {
-               if (sel != 1)
+               if (sel != 1 && sel != 2 && sel != 3)
                        return -EINVAL;
                ret = debugfs_file_get(file->f_path.dentry);
                if (ret)
@@ -1429,6 +1499,11 @@ static int pseudo_lock_dev_mmap(struct file *filp, struct vm_area_struct *vma)
 
        plr = rdtgrp->plr;
 
+       if (!plr->d) {
+               mutex_unlock(&rdtgroup_mutex);
+               return -ENODEV;
+       }
+
        /*
         * Task is required to run with affinity to the cpus associated
         * with the pseudo-locked region. If this is not the case the task
index b140c68bc14ba81b35406d835190428772c91836..f27b8115ffa2ab45a873d2eb789cb234b601595b 100644 (file)
@@ -268,17 +268,27 @@ static int rdtgroup_cpus_show(struct kernfs_open_file *of,
                              struct seq_file *s, void *v)
 {
        struct rdtgroup *rdtgrp;
+       struct cpumask *mask;
        int ret = 0;
 
        rdtgrp = rdtgroup_kn_lock_live(of->kn);
 
        if (rdtgrp) {
-               if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED)
-                       seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
-                                  cpumask_pr_args(&rdtgrp->plr->d->cpu_mask));
-               else
+               if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
+                       if (!rdtgrp->plr->d) {
+                               rdt_last_cmd_clear();
+                               rdt_last_cmd_puts("Cache domain offline\n");
+                               ret = -ENODEV;
+                       } else {
+                               mask = &rdtgrp->plr->d->cpu_mask;
+                               seq_printf(s, is_cpu_list(of) ?
+                                          "%*pbl\n" : "%*pb\n",
+                                          cpumask_pr_args(mask));
+                       }
+               } else {
                        seq_printf(s, is_cpu_list(of) ? "%*pbl\n" : "%*pb\n",
                                   cpumask_pr_args(&rdtgrp->cpu_mask));
+               }
        } else {
                ret = -ENOENT;
        }
@@ -961,7 +971,78 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,
 }
 
 /**
- * rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other
+ * rdt_cdp_peer_get - Retrieve CDP peer if it exists
+ * @r: RDT resource to which RDT domain @d belongs
+ * @d: Cache instance for which a CDP peer is requested
+ * @r_cdp: RDT resource that shares hardware with @r (RDT resource peer)
+ *         Used to return the result.
+ * @d_cdp: RDT domain that shares hardware with @d (RDT domain peer)
+ *         Used to return the result.
+ *
+ * RDT resources are managed independently and by extension the RDT domains
+ * (RDT resource instances) are managed independently also. The Code and
+ * Data Prioritization (CDP) RDT resources, while managed independently,
+ * could refer to the same underlying hardware. For example,
+ * RDT_RESOURCE_L2CODE and RDT_RESOURCE_L2DATA both refer to the L2 cache.
+ *
+ * When provided with an RDT resource @r and an instance of that RDT
+ * resource @d rdt_cdp_peer_get() will return if there is a peer RDT
+ * resource and the exact instance that shares the same hardware.
+ *
+ * Return: 0 if a CDP peer was found, <0 on error or if no CDP peer exists.
+ *         If a CDP peer was found, @r_cdp will point to the peer RDT resource
+ *         and @d_cdp will point to the peer RDT domain.
+ */
+static int rdt_cdp_peer_get(struct rdt_resource *r, struct rdt_domain *d,
+                           struct rdt_resource **r_cdp,
+                           struct rdt_domain **d_cdp)
+{
+       struct rdt_resource *_r_cdp = NULL;
+       struct rdt_domain *_d_cdp = NULL;
+       int ret = 0;
+
+       switch (r->rid) {
+       case RDT_RESOURCE_L3DATA:
+               _r_cdp = &rdt_resources_all[RDT_RESOURCE_L3CODE];
+               break;
+       case RDT_RESOURCE_L3CODE:
+               _r_cdp =  &rdt_resources_all[RDT_RESOURCE_L3DATA];
+               break;
+       case RDT_RESOURCE_L2DATA:
+               _r_cdp =  &rdt_resources_all[RDT_RESOURCE_L2CODE];
+               break;
+       case RDT_RESOURCE_L2CODE:
+               _r_cdp =  &rdt_resources_all[RDT_RESOURCE_L2DATA];
+               break;
+       default:
+               ret = -ENOENT;
+               goto out;
+       }
+
+       /*
+        * When a new CPU comes online and CDP is enabled then the new
+        * RDT domains (if any) associated with both CDP RDT resources
+        * are added in the same CPU online routine while the
+        * rdtgroup_mutex is held. It should thus not happen for one
+        * RDT domain to exist and be associated with its RDT CDP
+        * resource but there is no RDT domain associated with the
+        * peer RDT CDP resource. Hence the WARN.
+        */
+       _d_cdp = rdt_find_domain(_r_cdp, d->id, NULL);
+       if (WARN_ON(!_d_cdp)) {
+               _r_cdp = NULL;
+               ret = -EINVAL;
+       }
+
+out:
+       *r_cdp = _r_cdp;
+       *d_cdp = _d_cdp;
+
+       return ret;
+}
+
+/**
+ * __rdtgroup_cbm_overlaps - Does CBM for intended closid overlap with other
  * @r: Resource to which domain instance @d belongs.
  * @d: The domain instance for which @closid is being tested.
  * @cbm: Capacity bitmask being tested.
@@ -980,8 +1061,8 @@ static int rdtgroup_mode_show(struct kernfs_open_file *of,
  *
  * Return: false if CBM does not overlap, true if it does.
  */
-bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
-                          unsigned long cbm, int closid, bool exclusive)
+static bool __rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
+                                   unsigned long cbm, int closid, bool exclusive)
 {
        enum rdtgrp_mode mode;
        unsigned long ctrl_b;
@@ -1016,6 +1097,41 @@ bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
        return false;
 }
 
+/**
+ * rdtgroup_cbm_overlaps - Does CBM overlap with other use of hardware
+ * @r: Resource to which domain instance @d belongs.
+ * @d: The domain instance for which @closid is being tested.
+ * @cbm: Capacity bitmask being tested.
+ * @closid: Intended closid for @cbm.
+ * @exclusive: Only check if overlaps with exclusive resource groups
+ *
+ * Resources that can be allocated using a CBM can use the CBM to control
+ * the overlap of these allocations. rdtgroup_cmb_overlaps() is the test
+ * for overlap. Overlap test is not limited to the specific resource for
+ * which the CBM is intended though - when dealing with CDP resources that
+ * share the underlying hardware the overlap check should be performed on
+ * the CDP resource sharing the hardware also.
+ *
+ * Refer to description of __rdtgroup_cbm_overlaps() for the details of the
+ * overlap test.
+ *
+ * Return: true if CBM overlap detected, false if there is no overlap
+ */
+bool rdtgroup_cbm_overlaps(struct rdt_resource *r, struct rdt_domain *d,
+                          unsigned long cbm, int closid, bool exclusive)
+{
+       struct rdt_resource *r_cdp;
+       struct rdt_domain *d_cdp;
+
+       if (__rdtgroup_cbm_overlaps(r, d, cbm, closid, exclusive))
+               return true;
+
+       if (rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp) < 0)
+               return false;
+
+       return  __rdtgroup_cbm_overlaps(r_cdp, d_cdp, cbm, closid, exclusive);
+}
+
 /**
  * rdtgroup_mode_test_exclusive - Test if this resource group can be exclusive
  *
@@ -1176,6 +1292,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
        struct rdt_resource *r;
        struct rdt_domain *d;
        unsigned int size;
+       int ret = 0;
        bool sep;
        u32 ctrl;
 
@@ -1186,11 +1303,18 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
        }
 
        if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKED) {
-               seq_printf(s, "%*s:", max_name_width, rdtgrp->plr->r->name);
-               size = rdtgroup_cbm_to_size(rdtgrp->plr->r,
-                                           rdtgrp->plr->d,
-                                           rdtgrp->plr->cbm);
-               seq_printf(s, "%d=%u\n", rdtgrp->plr->d->id, size);
+               if (!rdtgrp->plr->d) {
+                       rdt_last_cmd_clear();
+                       rdt_last_cmd_puts("Cache domain offline\n");
+                       ret = -ENODEV;
+               } else {
+                       seq_printf(s, "%*s:", max_name_width,
+                                  rdtgrp->plr->r->name);
+                       size = rdtgroup_cbm_to_size(rdtgrp->plr->r,
+                                                   rdtgrp->plr->d,
+                                                   rdtgrp->plr->cbm);
+                       seq_printf(s, "%d=%u\n", rdtgrp->plr->d->id, size);
+               }
                goto out;
        }
 
@@ -1220,7 +1344,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
 out:
        rdtgroup_kn_unlock(of->kn);
 
-       return 0;
+       return ret;
 }
 
 /* rdtgroup information files for one cache resource. */
@@ -2354,14 +2478,16 @@ static void cbm_ensure_valid(u32 *_val, struct rdt_resource *r)
  */
 static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
 {
+       struct rdt_resource *r_cdp = NULL;
+       struct rdt_domain *d_cdp = NULL;
        u32 used_b = 0, unused_b = 0;
        u32 closid = rdtgrp->closid;
        struct rdt_resource *r;
        unsigned long tmp_cbm;
        enum rdtgrp_mode mode;
        struct rdt_domain *d;
+       u32 peer_ctl, *ctrl;
        int i, ret;
-       u32 *ctrl;
 
        for_each_alloc_enabled_rdt_resource(r) {
                /*
@@ -2371,6 +2497,7 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
                if (r->rid == RDT_RESOURCE_MBA)
                        continue;
                list_for_each_entry(d, &r->domains, list) {
+                       rdt_cdp_peer_get(r, d, &r_cdp, &d_cdp);
                        d->have_new_ctrl = false;
                        d->new_ctrl = r->cache.shareable_bits;
                        used_b = r->cache.shareable_bits;
@@ -2380,9 +2507,19 @@ static int rdtgroup_init_alloc(struct rdtgroup *rdtgrp)
                                        mode = rdtgroup_mode_by_closid(i);
                                        if (mode == RDT_MODE_PSEUDO_LOCKSETUP)
                                                break;
-                                       used_b |= *ctrl;
+                                       /*
+                                        * If CDP is active include peer
+                                        * domain's usage to ensure there
+                                        * is no overlap with an exclusive
+                                        * group.
+                                        */
+                                       if (d_cdp)
+                                               peer_ctl = d_cdp->ctrl_val[i];
+                                       else
+                                               peer_ctl = 0;
+                                       used_b |= *ctrl | peer_ctl;
                                        if (mode == RDT_MODE_SHAREABLE)
-                                               d->new_ctrl |= *ctrl;
+                                               d->new_ctrl |= *ctrl | peer_ctl;
                                }
                        }
                        if (d->plr && d->plr->cbm > 0)
@@ -2805,6 +2942,13 @@ static int rdtgroup_show_options(struct seq_file *seq, struct kernfs_root *kf)
 {
        if (rdt_resources_all[RDT_RESOURCE_L3DATA].alloc_enabled)
                seq_puts(seq, ",cdp");
+
+       if (rdt_resources_all[RDT_RESOURCE_L2DATA].alloc_enabled)
+               seq_puts(seq, ",cdpl2");
+
+       if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA]))
+               seq_puts(seq, ",mba_MBps");
+
        return 0;
 }
 
index eaf02f2e73005731e28dc22bd5d91d10fd26d2aa..40b16b2706560e409dfe57a9817d2c1832a4a89e 100644 (file)
@@ -179,7 +179,7 @@ optimized_callback(struct optimized_kprobe *op, struct pt_regs *regs)
                opt_pre_handler(&op->kp, regs);
                __this_cpu_write(current_kprobe, NULL);
        }
-       preempt_enable_no_resched();
+       preempt_enable();
 }
 NOKPROBE_SYMBOL(optimized_callback);
 
index 6d5dc5dabfd7ec71532c9a48e00c6a70da950a35..03b7529333a679f1d9b3ac505f04a1bf82de4caf 100644 (file)
@@ -636,7 +636,7 @@ unsigned long native_calibrate_tsc(void)
                case INTEL_FAM6_KABYLAKE_DESKTOP:
                        crystal_khz = 24000;    /* 24.0 MHz */
                        break;
-               case INTEL_FAM6_ATOM_DENVERTON:
+               case INTEL_FAM6_ATOM_GOLDMONT_X:
                        crystal_khz = 25000;    /* 25.0 MHz */
                        break;
                case INTEL_FAM6_ATOM_GOLDMONT:
index 27ef714d886c121caa786a85b6211e92a30d6915..3d0e9aeea7c8ee51856ba4ff958859272d41eaa2 100644 (file)
@@ -59,12 +59,12 @@ static const struct freq_desc freq_desc_ann = {
 };
 
 static const struct x86_cpu_id tsc_msr_cpu_ids[] = {
-       INTEL_CPU_FAM6(ATOM_PENWELL,            freq_desc_pnw),
-       INTEL_CPU_FAM6(ATOM_CLOVERVIEW,         freq_desc_clv),
-       INTEL_CPU_FAM6(ATOM_SILVERMONT1,        freq_desc_byt),
+       INTEL_CPU_FAM6(ATOM_SALTWELL_MID,       freq_desc_pnw),
+       INTEL_CPU_FAM6(ATOM_SALTWELL_TABLET,    freq_desc_clv),
+       INTEL_CPU_FAM6(ATOM_SILVERMONT,         freq_desc_byt),
+       INTEL_CPU_FAM6(ATOM_SILVERMONT_MID,     freq_desc_tng),
        INTEL_CPU_FAM6(ATOM_AIRMONT,            freq_desc_cht),
-       INTEL_CPU_FAM6(ATOM_MERRIFIELD,         freq_desc_tng),
-       INTEL_CPU_FAM6(ATOM_MOOREFIELD,         freq_desc_ann),
+       INTEL_CPU_FAM6(ATOM_AIRMONT_MID,        freq_desc_ann),
        {}
 };
 
index 034813d4ab1e1a2ff3c1d2c1969a61cfd198a3e6..6cb6076223bac8a1dc93d0f4179f24d97815056e 100644 (file)
@@ -115,7 +115,7 @@ static struct dentry *punit_dbg_file;
 
 static int punit_dbgfs_register(struct punit_device *punit_device)
 {
-       static struct dentry *dev_state;
+       struct dentry *dev_state;
 
        punit_dbg_file = debugfs_create_dir("punit_atom", NULL);
        if (!punit_dbg_file)
@@ -143,8 +143,8 @@ static void punit_dbgfs_unregister(void)
          (kernel_ulong_t)&drv_data }
 
 static const struct x86_cpu_id intel_punit_cpu_ids[] = {
-       ICPU(INTEL_FAM6_ATOM_SILVERMONT1, punit_device_byt),
-       ICPU(INTEL_FAM6_ATOM_MERRIFIELD,  punit_device_tng),
+       ICPU(INTEL_FAM6_ATOM_SILVERMONT, punit_device_byt),
+       ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID,  punit_device_tng),
        ICPU(INTEL_FAM6_ATOM_AIRMONT,     punit_device_cht),
        {}
 };
index 5a0483e7bf662cb27044b7684567b644dfe49b81..31dce781364cf2dc3ad2771eec57ca0fae97e354 100644 (file)
@@ -68,7 +68,7 @@ static struct bt_sfi_data tng_bt_sfi_data __initdata = {
        { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (kernel_ulong_t)&ddata }
 
 static const struct x86_cpu_id bt_sfi_cpu_ids[] = {
-       ICPU(INTEL_FAM6_ATOM_MERRIFIELD, tng_bt_sfi_data),
+       ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID, tng_bt_sfi_data),
        {}
 };
 
index 10adb8cb3a3f27c4c563983a827457554686f7d5..b9bda06d344d7eea58fddc3a3a8328868f1c662c 100644 (file)
@@ -314,7 +314,7 @@ static const struct lpss_device_desc bsw_spi_dev_desc = {
 #define ICPU(model)    { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, }
 
 static const struct x86_cpu_id lpss_cpu_ids[] = {
-       ICPU(INTEL_FAM6_ATOM_SILVERMONT1),      /* Valleyview, Bay Trail */
+       ICPU(INTEL_FAM6_ATOM_SILVERMONT),       /* Valleyview, Bay Trail */
        ICPU(INTEL_FAM6_ATOM_AIRMONT),  /* Braswell, Cherry Trail */
        {}
 };
index 06c31ec3cc705d0abb4f86da90e64a3930c2154d..9a8e286dd86fde392751864044ca09be170e0ce8 100644 (file)
@@ -54,7 +54,7 @@ static const struct always_present_id always_present_ids[] = {
         * Bay / Cherry Trail PWM directly poked by GPU driver in win10,
         * but Linux uses a separate PWM driver, harmless if not used.
         */
-       ENTRY("80860F09", "1", ICPU(INTEL_FAM6_ATOM_SILVERMONT1), {}),
+       ENTRY("80860F09", "1", ICPU(INTEL_FAM6_ATOM_SILVERMONT), {}),
        ENTRY("80862288", "1", ICPU(INTEL_FAM6_ATOM_AIRMONT), {}),
        /*
         * The INT0002 device is necessary to clear wakeup interrupt sources
index 2a99e2fd941246905fff42933a72a98b8576ce77..49c0abf2d48f0f3189a7d57585710c2b7514da75 100644 (file)
@@ -1816,7 +1816,7 @@ static const struct pstate_funcs knl_funcs = {
 static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
        ICPU(INTEL_FAM6_SANDYBRIDGE,            core_funcs),
        ICPU(INTEL_FAM6_SANDYBRIDGE_X,          core_funcs),
-       ICPU(INTEL_FAM6_ATOM_SILVERMONT1,       silvermont_funcs),
+       ICPU(INTEL_FAM6_ATOM_SILVERMONT       silvermont_funcs),
        ICPU(INTEL_FAM6_IVYBRIDGE,              core_funcs),
        ICPU(INTEL_FAM6_HASWELL_CORE,           core_funcs),
        ICPU(INTEL_FAM6_BROADWELL_CORE,         core_funcs),
@@ -1833,7 +1833,7 @@ static const struct x86_cpu_id intel_pstate_cpu_ids[] = {
        ICPU(INTEL_FAM6_XEON_PHI_KNL,           knl_funcs),
        ICPU(INTEL_FAM6_XEON_PHI_KNM,           knl_funcs),
        ICPU(INTEL_FAM6_ATOM_GOLDMONT,          core_funcs),
-       ICPU(INTEL_FAM6_ATOM_GEMINI_LAKE,       core_funcs),
+       ICPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS,     core_funcs),
        ICPU(INTEL_FAM6_SKYLAKE_X,              core_funcs),
        {}
 };
index df28b65358d26f26a6ec054222752fb2e497ba5f..903a4f1fadcc394adec7a41ed6c4926694b96047 100644 (file)
@@ -1541,7 +1541,7 @@ static struct dunit_ops dnv_ops = {
 
 static const struct x86_cpu_id pnd2_cpuids[] = {
        { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT, 0, (kernel_ulong_t)&apl_ops },
-       { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_DENVERTON, 0, (kernel_ulong_t)&dnv_ops },
+       { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_GOLDMONT_X, 0, (kernel_ulong_t)&dnv_ops },
        { }
 };
 MODULE_DEVICE_TABLE(x86cpu, pnd2_cpuids);
index 791b8a366e6edaf533b0b66af97ced3250689a54..8b5d85c91e9d4b2ed10d07bf98237c9f6b7eff14 100644 (file)
@@ -1073,14 +1073,14 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
        INTEL_CPU_FAM6(WESTMERE,                idle_cpu_nehalem),
        INTEL_CPU_FAM6(WESTMERE_EP,             idle_cpu_nehalem),
        INTEL_CPU_FAM6(NEHALEM_EX,              idle_cpu_nehalem),
-       INTEL_CPU_FAM6(ATOM_PINEVIEW,           idle_cpu_atom),
-       INTEL_CPU_FAM6(ATOM_LINCROFT,           idle_cpu_lincroft),
+       INTEL_CPU_FAM6(ATOM_BONNELL,            idle_cpu_atom),
+       INTEL_CPU_FAM6(ATOM_BONNELL_MID,        idle_cpu_lincroft),
        INTEL_CPU_FAM6(WESTMERE_EX,             idle_cpu_nehalem),
        INTEL_CPU_FAM6(SANDYBRIDGE,             idle_cpu_snb),
        INTEL_CPU_FAM6(SANDYBRIDGE_X,           idle_cpu_snb),
-       INTEL_CPU_FAM6(ATOM_CEDARVIEW,          idle_cpu_atom),
-       INTEL_CPU_FAM6(ATOM_SILVERMONT1,        idle_cpu_byt),
-       INTEL_CPU_FAM6(ATOM_MERRIFIELD,         idle_cpu_tangier),
+       INTEL_CPU_FAM6(ATOM_SALTWELL,           idle_cpu_atom),
+       INTEL_CPU_FAM6(ATOM_SILVERMONT        idle_cpu_byt),
+       INTEL_CPU_FAM6(ATOM_SILVERMONT_MID,     idle_cpu_tangier),
        INTEL_CPU_FAM6(ATOM_AIRMONT,            idle_cpu_cht),
        INTEL_CPU_FAM6(IVYBRIDGE,               idle_cpu_ivb),
        INTEL_CPU_FAM6(IVYBRIDGE_X,             idle_cpu_ivt),
@@ -1088,7 +1088,7 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
        INTEL_CPU_FAM6(HASWELL_X,               idle_cpu_hsw),
        INTEL_CPU_FAM6(HASWELL_ULT,             idle_cpu_hsw),
        INTEL_CPU_FAM6(HASWELL_GT3E,            idle_cpu_hsw),
-       INTEL_CPU_FAM6(ATOM_SILVERMONT2,        idle_cpu_avn),
+       INTEL_CPU_FAM6(ATOM_SILVERMONT_X,       idle_cpu_avn),
        INTEL_CPU_FAM6(BROADWELL_CORE,          idle_cpu_bdw),
        INTEL_CPU_FAM6(BROADWELL_GT3E,          idle_cpu_bdw),
        INTEL_CPU_FAM6(BROADWELL_X,             idle_cpu_bdw),
@@ -1101,8 +1101,8 @@ static const struct x86_cpu_id intel_idle_ids[] __initconst = {
        INTEL_CPU_FAM6(XEON_PHI_KNL,            idle_cpu_knl),
        INTEL_CPU_FAM6(XEON_PHI_KNM,            idle_cpu_knl),
        INTEL_CPU_FAM6(ATOM_GOLDMONT,           idle_cpu_bxt),
-       INTEL_CPU_FAM6(ATOM_GEMINI_LAKE,        idle_cpu_bxt),
-       INTEL_CPU_FAM6(ATOM_DENVERTON,          idle_cpu_dnv),
+       INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS,      idle_cpu_bxt),
+       INTEL_CPU_FAM6(ATOM_GOLDMONT_X,         idle_cpu_dnv),
        {}
 };
 
@@ -1319,7 +1319,7 @@ static void intel_idle_state_table_update(void)
                ivt_idle_state_table_update();
                break;
        case INTEL_FAM6_ATOM_GOLDMONT:
-       case INTEL_FAM6_ATOM_GEMINI_LAKE:
+       case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
                bxt_idle_state_table_update();
                break;
        case INTEL_FAM6_SKYLAKE_DESKTOP:
index 82c9b9326e9e5635cd570de9c7706c74ac9fffda..057e24f4a620f692add8f632995872f5bcb88500 100644 (file)
@@ -247,7 +247,7 @@ static const struct sdhci_acpi_chip sdhci_acpi_chip_int = {
 static bool sdhci_acpi_byt(void)
 {
        static const struct x86_cpu_id byt[] = {
-               { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 },
+               { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT },
                {}
        };
 
index 314e135014dcd14387dc0ca7b8bdfb7198910baa..30fbe2ea6eab48bad6a974b423a4fe1aefe79224 100644 (file)
@@ -62,8 +62,8 @@ static const struct pci_platform_pm_ops mid_pci_platform_pm = {
  * arch/x86/platform/intel-mid/pwr.c.
  */
 static const struct x86_cpu_id lpss_cpu_ids[] = {
-       ICPU(INTEL_FAM6_ATOM_PENWELL),
-       ICPU(INTEL_FAM6_ATOM_MERRIFIELD),
+       ICPU(INTEL_FAM6_ATOM_SALTWELL_MID),
+       ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID),
        {}
 };
 
index a473dc51b18d6d76d27d2cde2572cfcc42435bc6..e89ad4964dc139daec390560bfcecb145cdd5505 100644 (file)
@@ -60,7 +60,7 @@ static const struct x86_cpu_id int0002_cpu_ids[] = {
 /*
  * Limit ourselves to Cherry Trail for now, until testing shows we
  * need to handle the INT0002 device on Baytrail too.
- *     ICPU(INTEL_FAM6_ATOM_SILVERMONT1),       * Valleyview, Bay Trail *
+ *     ICPU(INTEL_FAM6_ATOM_SILVERMONT),        * Valleyview, Bay Trail *
  */
        ICPU(INTEL_FAM6_ATOM_AIRMONT),          /* Braswell, Cherry Trail */
        {}
index d79fbf924b136823987011664d385e1bdceb927d..5ad44204a9c3c997bf237aacfb1bbb99ab292ef7 100644 (file)
@@ -125,8 +125,8 @@ static const struct mid_pb_ddata mrfld_ddata = {
        { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (kernel_ulong_t)&ddata }
 
 static const struct x86_cpu_id mid_pb_cpu_ids[] = {
-       ICPU(INTEL_FAM6_ATOM_PENWELL,           mfld_ddata),
-       ICPU(INTEL_FAM6_ATOM_MERRIFIELD,        mrfld_ddata),
+       ICPU(INTEL_FAM6_ATOM_SALTWELL_MID,              mfld_ddata),
+       ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID,    mrfld_ddata),
        {}
 };
 
index ffd0474b0531116a308343514950684a250b0b77..cee08f23629245803783734af6229ac18c69e3e6 100644 (file)
@@ -320,7 +320,7 @@ static struct telemetry_debugfs_conf telem_apl_debugfs_conf = {
 
 static const struct x86_cpu_id telemetry_debugfs_cpu_ids[] = {
        TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_debugfs_conf),
-       TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE, telem_apl_debugfs_conf),
+       TELEM_DEBUGFS_CPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS, telem_apl_debugfs_conf),
        {}
 };
 
index 2f889d6c270e85c50fd8296af3636cc216e84ed9..fcc6bee51a422a1c95e205f0d2874fc746ed09e2 100644 (file)
@@ -192,7 +192,7 @@ static struct telemetry_plt_config telem_glk_config = {
 
 static const struct x86_cpu_id telemetry_cpu_ids[] = {
        TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT, telem_apl_config),
-       TELEM_CPU(INTEL_FAM6_ATOM_GEMINI_LAKE, telem_glk_config),
+       TELEM_CPU(INTEL_FAM6_ATOM_GOLDMONT_PLUS, telem_glk_config),
        {}
 };
 
index bb92874b1175ecc5f129c56c19a911f6d206ef0e..6cdb2c14eee4c33db1ec24e3fcfebe62a03b9a5d 100644 (file)
@@ -1157,13 +1157,13 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {
        INTEL_CPU_FAM6(KABYLAKE_DESKTOP,        rapl_defaults_core),
        INTEL_CPU_FAM6(CANNONLAKE_MOBILE,       rapl_defaults_core),
 
-       INTEL_CPU_FAM6(ATOM_SILVERMONT1,        rapl_defaults_byt),
+       INTEL_CPU_FAM6(ATOM_SILVERMONT        rapl_defaults_byt),
        INTEL_CPU_FAM6(ATOM_AIRMONT,            rapl_defaults_cht),
-       INTEL_CPU_FAM6(ATOM_MERRIFIELD,         rapl_defaults_tng),
-       INTEL_CPU_FAM6(ATOM_MOOREFIELD,         rapl_defaults_ann),
+       INTEL_CPU_FAM6(ATOM_SILVERMONT_MID,     rapl_defaults_tng),
+       INTEL_CPU_FAM6(ATOM_AIRMONT_MID,        rapl_defaults_ann),
        INTEL_CPU_FAM6(ATOM_GOLDMONT,           rapl_defaults_core),
-       INTEL_CPU_FAM6(ATOM_GEMINI_LAKE,        rapl_defaults_core),
-       INTEL_CPU_FAM6(ATOM_DENVERTON,          rapl_defaults_core),
+       INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS,      rapl_defaults_core),
+       INTEL_CPU_FAM6(ATOM_GOLDMONT_X,         rapl_defaults_core),
 
        INTEL_CPU_FAM6(XEON_PHI_KNL,            rapl_defaults_hsw_server),
        INTEL_CPU_FAM6(XEON_PHI_KNM,            rapl_defaults_hsw_server),
index 1e47511a6bd5baa0e0db1846d858b8fd2757fb19..d748527d7a38a98737a1f3e4d70e1cbda048a921 100644 (file)
@@ -45,7 +45,7 @@ static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
 }
 
 static const struct x86_cpu_id soc_thermal_ids[] = {
-       { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1, 0,
+       { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, 0,
                BYT_SOC_DTS_APIC_IRQ},
        {}
 };
index 5d3cf407e37469a7b1cafab8c4af303d074bbdf8..4a99370763319dd14d39c7547e4af930779dc38f 100644 (file)
@@ -459,10 +459,20 @@ void perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
        if (size || handle->aux_flags) {
                /*
                 * Only send RECORD_AUX if we have something useful to communicate
+                *
+                * Note: the OVERWRITE records by themselves are not considered
+                * useful, as they don't communicate any *new* information,
+                * aside from the short-lived offset, that becomes history at
+                * the next event sched-in and therefore isn't useful.
+                * The userspace that needs to copy out AUX data in overwrite
+                * mode should know to use user_page::aux_head for the actual
+                * offset. So, from now on we don't output AUX records that
+                * have *only* OVERWRITE flag set.
                 */
 
-               perf_event_aux_event(handle->event, aux_head, size,
-                                    handle->aux_flags);
+               if (handle->aux_flags & ~(u64)PERF_AUX_FLAG_OVERWRITE)
+                       perf_event_aux_event(handle->event, aux_head, size,
+                                            handle->aux_flags);
        }
 
        rb->user_page->aux_head = rb->aux_head;
index ab257be4d92495a52c780d45c519eea608225c9e..90e98e233647f13dda24630567c520aee08c5e49 100644 (file)
@@ -546,8 +546,14 @@ static void do_free_cleaned_kprobes(void)
        struct optimized_kprobe *op, *tmp;
 
        list_for_each_entry_safe(op, tmp, &freeing_list, list) {
-               BUG_ON(!kprobe_unused(&op->kp));
                list_del_init(&op->list);
+               if (WARN_ON_ONCE(!kprobe_unused(&op->kp))) {
+                       /*
+                        * This must not happen, but if there is a kprobe
+                        * still in use, keep it on kprobes hash list.
+                        */
+                       continue;
+               }
                free_aggr_kprobe(&op->kp);
        }
 }
@@ -700,11 +706,11 @@ static void unoptimize_kprobe(struct kprobe *p, bool force)
 }
 
 /* Cancel unoptimizing for reusing */
-static void reuse_unused_kprobe(struct kprobe *ap)
+static int reuse_unused_kprobe(struct kprobe *ap)
 {
        struct optimized_kprobe *op;
+       int ret;
 
-       BUG_ON(!kprobe_unused(ap));
        /*
         * Unused kprobe MUST be on the way of delayed unoptimizing (means
         * there is still a relative jump) and disabled.
@@ -714,8 +720,12 @@ static void reuse_unused_kprobe(struct kprobe *ap)
        /* Enable the probe again */
        ap->flags &= ~KPROBE_FLAG_DISABLED;
        /* Optimize it again (remove from op->list) */
-       BUG_ON(!kprobe_optready(ap));
+       ret = kprobe_optready(ap);
+       if (ret)
+               return ret;
+
        optimize_kprobe(ap);
+       return 0;
 }
 
 /* Remove optimized instructions */
@@ -940,11 +950,16 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt)
 #define kprobe_disarmed(p)                     kprobe_disabled(p)
 #define wait_for_kprobe_optimizer()            do {} while (0)
 
-/* There should be no unused kprobes can be reused without optimization */
-static void reuse_unused_kprobe(struct kprobe *ap)
+static int reuse_unused_kprobe(struct kprobe *ap)
 {
+       /*
+        * If the optimized kprobe is NOT supported, the aggr kprobe is
+        * released at the same time that the last aggregated kprobe is
+        * unregistered.
+        * Thus there should be no chance to reuse unused kprobe.
+        */
        printk(KERN_ERR "Error: There should be no unused kprobe here.\n");
-       BUG_ON(kprobe_unused(ap));
+       return -EINVAL;
 }
 
 static void free_aggr_kprobe(struct kprobe *p)
@@ -1259,8 +1274,6 @@ NOKPROBE_SYMBOL(cleanup_rp_inst);
 /* Add the new probe to ap->list */
 static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)
 {
-       BUG_ON(kprobe_gone(ap) || kprobe_gone(p));
-
        if (p->post_handler)
                unoptimize_kprobe(ap, true);    /* Fall back to normal kprobe */
 
@@ -1318,9 +1331,12 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
                        goto out;
                }
                init_aggr_kprobe(ap, orig_p);
-       } else if (kprobe_unused(ap))
+       } else if (kprobe_unused(ap)) {
                /* This probe is going to die. Rescue it */
-               reuse_unused_kprobe(ap);
+               ret = reuse_unused_kprobe(ap);
+               if (ret)
+                       goto out;
+       }
 
        if (kprobe_gone(ap)) {
                /*
@@ -1704,7 +1720,6 @@ noclean:
        return 0;
 
 disarmed:
-       BUG_ON(!kprobe_disarmed(ap));
        hlist_del_rcu(&ap->hlist);
        return 0;
 }
index f8a68bdb388581b600aabe36d1209124e51c6759..6af02bf879ac5a5eebbc5421210e8aaa92b3a87f 100644 (file)
@@ -787,7 +787,7 @@ static struct snd_soc_card byt_rt5651_card = {
 };
 
 static const struct x86_cpu_id baytrail_cpu_ids[] = {
-       { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT1 }, /* Valleyview */
+       { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT }, /* Valleyview */
        {}
 };
 
index acc704bd3998cf9bb592a240232addca209d7f34..0b0ef3abc966e98c806bf7148d1d3f66fa096102 100644 (file)
@@ -3,8 +3,6 @@
 #define _TOOLS_LINUX_BITOPS_H_
 
 #include <asm/types.h>
-#include <linux/compiler.h>
-
 #ifndef __WORDSIZE
 #define __WORDSIZE (__SIZEOF_LONG__ * 8)
 #endif
 #ifndef BITS_PER_LONG
 # define BITS_PER_LONG __WORDSIZE
 #endif
+#include <linux/bits.h>
+#include <linux/compiler.h>
 
-#define BIT_MASK(nr)           (1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr)           ((nr) / BITS_PER_LONG)
-#define BITS_PER_BYTE          8
 #define BITS_TO_LONGS(nr)      DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 #define BITS_TO_U64(nr)                DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
 #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 (file)
index 0000000..2b7b532
--- /dev/null
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_BITS_H
+#define __LINUX_BITS_H
+#include <asm/bitsperlong.h>
+
+#define BIT(nr)                        (1UL << (nr))
+#define BIT_ULL(nr)            (1ULL << (nr))
+#define BIT_MASK(nr)           (1UL << ((nr) % BITS_PER_LONG))
+#define BIT_WORD(nr)           ((nr) / BITS_PER_LONG)
+#define BIT_ULL_MASK(nr)       (1ULL << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_ULL_WORD(nr)       ((nr) / BITS_PER_LONG_LONG)
+#define BITS_PER_BYTE          8
+
+/*
+ * Create a contiguous bitmask starting at bit position @l and ending at
+ * position @h. For example
+ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
+ */
+#define GENMASK(h, l) \
+       (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+
+#define GENMASK_ULL(h, l) \
+       (((~0ULL) - (1ULL << (l)) + 1) & \
+        (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+
+#endif /* __LINUX_BITS_H */
index 7a8b61ad44cbe0167de1642628d113beae7c91dc..094649667baeea69f88df5f19d9927acc7ad583d 100644 (file)
@@ -52,4 +52,11 @@ static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
        return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
 }
 
+static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
+{
+       if (IS_ERR(ptr))
+               return PTR_ERR(ptr);
+       else
+               return 0;
+}
 #endif /* _LINUX_ERR_H */
index 9997a8805a82d2ffa2f378390781984b7ac6311f..e3d47b59b14d8c9e31b3c5376d34f84b878f270f 100644 (file)
@@ -23,6 +23,13 @@ void pager_init(const char *pager_env)
        subcmd_config.pager_env = pager_env;
 }
 
+static const char *forced_pager;
+
+void force_pager(const char *pager)
+{
+       forced_pager = pager;
+}
+
 static void pager_preexec(void)
 {
        /*
@@ -66,7 +73,9 @@ void setup_pager(void)
        const char *pager = getenv(subcmd_config.pager_env);
        struct winsize sz;
 
-       if (!isatty(1))
+       if (forced_pager)
+               pager = forced_pager;
+       if (!isatty(1) && !forced_pager)
                return;
        if (ioctl(1, TIOCGWINSZ, &sz) == 0)
                pager_columns = sz.ws_col;
index f1a53cf2988045b73ad9d9376028fc62aed2169a..a818964693abd4d1b4008091c0f3ea2b5cefba8d 100644 (file)
@@ -7,5 +7,6 @@ extern void pager_init(const char *pager_env);
 extern void setup_pager(void);
 extern int pager_in_use(void);
 extern int pager_get_columns(void);
+extern void force_pager(const char *);
 
 #endif /* __SUBCMD_PAGER_H */
index c681d0575d167cf746d8ca2a0ae2a17124068e67..ba54bfce0b0b1c14de85c0018304b92e40c59b59 100644 (file)
@@ -4,6 +4,8 @@ libtraceevent-y += trace-seq.o
 libtraceevent-y += parse-filter.o
 libtraceevent-y += parse-utils.o
 libtraceevent-y += kbuffer-parse.o
+libtraceevent-y += tep_strerror.o
+libtraceevent-y += event-parse-api.o
 
 plugin_jbd2-y         += plugin_jbd2.o
 plugin_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 (file)
index 0000000..61f7149
--- /dev/null
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
+ *
+ */
+
+#include "event-parse.h"
+#include "event-parse-local.h"
+#include "event-utils.h"
+
+/**
+ * tep_get_first_event - returns the first event in the events array
+ * @tep: a handle to the tep_handle
+ *
+ * This returns pointer to the first element of the events array
+ * If @tep is NULL, NULL is returned.
+ */
+struct tep_event_format *tep_get_first_event(struct tep_handle *tep)
+{
+       if (tep && tep->events)
+               return tep->events[0];
+
+       return NULL;
+}
+
+/**
+ * tep_get_events_count - get the number of defined events
+ * @tep: a handle to the tep_handle
+ *
+ * This returns number of elements in event array
+ * If @tep is NULL, 0 is returned.
+ */
+int tep_get_events_count(struct tep_handle *tep)
+{
+       if(tep)
+               return tep->nr_events;
+       return 0;
+}
+
+/**
+ * tep_set_flag - set event parser flag
+ * @tep: a handle to the tep_handle
+ * @flag: flag, or combination of flags to be set
+ * can be any combination from enum tep_flag
+ *
+ * This sets a flag or mbination of flags  from enum tep_flag
+  */
+void tep_set_flag(struct tep_handle *tep, int flag)
+{
+       if(tep)
+               tep->flags |= flag;
+}
+
+unsigned short __tep_data2host2(struct tep_handle *pevent, unsigned short data)
+{
+       unsigned short swap;
+
+       if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+               return data;
+
+       swap = ((data & 0xffULL) << 8) |
+               ((data & (0xffULL << 8)) >> 8);
+
+       return swap;
+}
+
+unsigned int __tep_data2host4(struct tep_handle *pevent, unsigned int data)
+{
+       unsigned int swap;
+
+       if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+               return data;
+
+       swap = ((data & 0xffULL) << 24) |
+               ((data & (0xffULL << 8)) << 8) |
+               ((data & (0xffULL << 16)) >> 8) |
+               ((data & (0xffULL << 24)) >> 24);
+
+       return swap;
+}
+
+unsigned long long
+__tep_data2host8(struct tep_handle *pevent, unsigned long long data)
+{
+       unsigned long long swap;
+
+       if (!pevent || pevent->host_bigendian == pevent->file_bigendian)
+               return data;
+
+       swap = ((data & 0xffULL) << 56) |
+               ((data & (0xffULL << 8)) << 40) |
+               ((data & (0xffULL << 16)) << 24) |
+               ((data & (0xffULL << 24)) << 8) |
+               ((data & (0xffULL << 32)) >> 8) |
+               ((data & (0xffULL << 40)) >> 24) |
+               ((data & (0xffULL << 48)) >> 40) |
+               ((data & (0xffULL << 56)) >> 56);
+
+       return swap;
+}
+
+/**
+ * tep_get_header_page_size - get size of the header page
+ * @pevent: a handle to the tep_handle
+ *
+ * This returns size of the header page
+ * If @pevent is NULL, 0 is returned.
+ */
+int tep_get_header_page_size(struct tep_handle *pevent)
+{
+       if(pevent)
+               return pevent->header_page_size_size;
+       return 0;
+}
+
+/**
+ * tep_get_cpus - get the number of CPUs
+ * @pevent: a handle to the tep_handle
+ *
+ * This returns the number of CPUs
+ * If @pevent is NULL, 0 is returned.
+ */
+int tep_get_cpus(struct tep_handle *pevent)
+{
+       if(pevent)
+               return pevent->cpus;
+       return 0;
+}
+
+/**
+ * tep_set_cpus - set the number of CPUs
+ * @pevent: a handle to the tep_handle
+ *
+ * This sets the number of CPUs
+ */
+void tep_set_cpus(struct tep_handle *pevent, int cpus)
+{
+       if(pevent)
+               pevent->cpus = cpus;
+}
+
+/**
+ * tep_get_long_size - get the size of a long integer on the current machine
+ * @pevent: a handle to the tep_handle
+ *
+ * This returns the size of a long integer on the current machine
+ * If @pevent is NULL, 0 is returned.
+ */
+int tep_get_long_size(struct tep_handle *pevent)
+{
+       if(pevent)
+               return pevent->long_size;
+       return 0;
+}
+
+/**
+ * tep_set_long_size - set the size of a long integer on the current machine
+ * @pevent: a handle to the tep_handle
+ * @size: size, in bytes, of a long integer
+ *
+ * This sets the size of a long integer on the current machine
+ */
+void tep_set_long_size(struct tep_handle *pevent, int long_size)
+{
+       if(pevent)
+               pevent->long_size = long_size;
+}
+
+/**
+ * tep_get_page_size - get the size of a memory page on the current machine
+ * @pevent: a handle to the tep_handle
+ *
+ * This returns the size of a memory page on the current machine
+ * If @pevent is NULL, 0 is returned.
+ */
+int tep_get_page_size(struct tep_handle *pevent)
+{
+       if(pevent)
+               return pevent->page_size;
+       return 0;
+}
+
+/**
+ * tep_set_page_size - set the size of a memory page on the current machine
+ * @pevent: a handle to the tep_handle
+ * @_page_size: size of a memory page, in bytes
+ *
+ * This sets the size of a memory page on the current machine
+ */
+void tep_set_page_size(struct tep_handle *pevent, int _page_size)
+{
+       if(pevent)
+               pevent->page_size = _page_size;
+}
+
+/**
+ * tep_is_file_bigendian - get if the file is in big endian order
+ * @pevent: a handle to the tep_handle
+ *
+ * This returns if the file is in big endian order
+ * If @pevent is NULL, 0 is returned.
+ */
+int tep_is_file_bigendian(struct tep_handle *pevent)
+{
+       if(pevent)
+               return pevent->file_bigendian;
+       return 0;
+}
+
+/**
+ * tep_set_file_bigendian - set if the file is in big endian order
+ * @pevent: a handle to the tep_handle
+ * @endian: non zero, if the file is in big endian order
+ *
+ * This sets if the file is in big endian order
+ */
+void tep_set_file_bigendian(struct tep_handle *pevent, enum tep_endian endian)
+{
+       if(pevent)
+               pevent->file_bigendian = endian;
+}
+
+/**
+ * tep_is_host_bigendian - get if the order of the current host is big endian
+ * @pevent: a handle to the tep_handle
+ *
+ * This gets if the order of the current host is big endian
+ * If @pevent is NULL, 0 is returned.
+ */
+int tep_is_host_bigendian(struct tep_handle *pevent)
+{
+       if(pevent)
+               return pevent->host_bigendian;
+       return 0;
+}
+
+/**
+ * tep_set_host_bigendian - set the order of the local host
+ * @pevent: a handle to the tep_handle
+ * @endian: non zero, if the local host has big endian order
+ *
+ * This sets the order of the local host
+ */
+void tep_set_host_bigendian(struct tep_handle *pevent, enum tep_endian endian)
+{
+       if(pevent)
+               pevent->host_bigendian = endian;
+}
+
+/**
+ * tep_is_latency_format - get if the latency output format is configured
+ * @pevent: a handle to the tep_handle
+ *
+ * This gets if the latency output format is configured
+ * If @pevent is NULL, 0 is returned.
+ */
+int tep_is_latency_format(struct tep_handle *pevent)
+{
+       if(pevent)
+               return pevent->latency_format;
+       return 0;
+}
+
+/**
+ * tep_set_latency_format - set the latency output format
+ * @pevent: a handle to the tep_handle
+ * @lat: non zero for latency output format
+ *
+ * This sets the latency output format
+  */
+void tep_set_latency_format(struct tep_handle *pevent, int lat)
+{
+       if(pevent)
+               pevent->latency_format = lat;
+}
diff --git a/tools/lib/traceevent/event-parse-local.h b/tools/lib/traceevent/event-parse-local.h
new file mode 100644 (file)
index 0000000..b9bddde
--- /dev/null
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: LGPL-2.1
+/*
+ * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
+ *
+ */
+
+#ifndef _PARSE_EVENTS_INT_H
+#define _PARSE_EVENTS_INT_H
+
+struct cmdline;
+struct cmdline_list;
+struct func_map;
+struct func_list;
+struct event_handler;
+struct func_resolver;
+
+struct tep_handle {
+       int ref_count;
+
+       int header_page_ts_offset;
+       int header_page_ts_size;
+       int header_page_size_offset;
+       int header_page_size_size;
+       int header_page_data_offset;
+       int header_page_data_size;
+       int header_page_overwrite;
+
+       enum tep_endian file_bigendian;
+       enum tep_endian host_bigendian;
+
+       int latency_format;
+
+       int old_format;
+
+       int cpus;
+       int long_size;
+       int page_size;
+
+       struct cmdline *cmdlines;
+       struct cmdline_list *cmdlist;
+       int cmdline_count;
+
+       struct func_map *func_map;
+       struct func_resolver *func_resolver;
+       struct func_list *funclist;
+       unsigned int func_count;
+
+       struct printk_map *printk_map;
+       struct printk_list *printklist;
+       unsigned int printk_count;
+
+
+       struct tep_event_format **events;
+       int nr_events;
+       struct tep_event_format **sort_events;
+       enum tep_event_sort_type last_type;
+
+       int type_offset;
+       int type_size;
+
+       int pid_offset;
+       int pid_size;
+
+       int pc_offset;
+       int pc_size;
+
+       int flags_offset;
+       int flags_size;
+
+       int ld_offset;
+       int ld_size;
+
+       int print_raw;
+
+       int test_filters;
+
+       int flags;
+
+       struct tep_format_field *bprint_ip_field;
+       struct tep_format_field *bprint_fmt_field;
+       struct tep_format_field *bprint_buf_field;
+
+       struct event_handler *handlers;
+       struct tep_function_handler *func_handlers;
+
+       /* cache */
+       struct tep_event_format *last_event;
+
+       char *trace_clock;
+};
+
+#endif /* _PARSE_EVENTS_INT_H */
index ce1e20227c64d4e0789b6dad21a407988de720d9..3692f29fee464c8f5671a916e787a84869f18e96 100644 (file)
 #include <errno.h>
 #include <stdint.h>
 #include <limits.h>
-#include <linux/string.h>
 #include <linux/time64.h>
 
 #include <netinet/in.h>
 #include "event-parse.h"
+
+#include "event-parse-local.h"
 #include "event-utils.h"
+#include "trace-seq.h"
 
 static const char *input_buf;
 static unsigned long long input_buf_ptr;
@@ -94,7 +96,7 @@ struct tep_function_handler {
 
 static unsigned long long
 process_defined_func(struct trace_seq *s, void *data, int size,
-                    struct event_format *event, struct print_arg *arg);
+                    struct tep_event_format *event, struct tep_print_arg *arg);
 
 static void free_func_handle(struct tep_function_handler *func);
 
@@ -117,9 +119,9 @@ void breakpoint(void)
        x++;
 }
 
-struct print_arg *alloc_arg(void)
+struct tep_print_arg *alloc_arg(void)
 {
-       return calloc(1, sizeof(struct print_arg));
+       return calloc(1, sizeof(struct tep_print_arg));
 }
 
 struct cmdline {
@@ -737,16 +739,16 @@ void tep_print_printk(struct tep_handle *pevent)
        }
 }
 
-static struct event_format *alloc_event(void)
+static struct tep_event_format *alloc_event(void)
 {
-       return calloc(1, sizeof(struct event_format));
+       return calloc(1, sizeof(struct tep_event_format));
 }
 
-static int add_event(struct tep_handle *pevent, struct event_format *event)
+static int add_event(struct tep_handle *pevent, struct tep_event_format *event)
 {
        int i;
-       struct event_format **events = realloc(pevent->events, sizeof(event) *
-                                              (pevent->nr_events + 1));
+       struct tep_event_format **events = realloc(pevent->events, sizeof(event) *
+                                                 (pevent->nr_events + 1));
        if (!events)
                return -1;
 
@@ -769,20 +771,20 @@ static int add_event(struct tep_handle *pevent, struct event_format *event)
        return 0;
 }
 
-static int event_item_type(enum event_type type)
+static int event_item_type(enum tep_event_type type)
 {
        switch (type) {
-       case EVENT_ITEM ... EVENT_SQUOTE:
+       case TEP_EVENT_ITEM ... TEP_EVENT_SQUOTE:
                return 1;
-       case EVENT_ERROR ... EVENT_DELIM:
+       case TEP_EVENT_ERROR ... TEP_EVENT_DELIM:
        default:
                return 0;
        }
 }
 
-static void free_flag_sym(struct print_flag_sym *fsym)
+static void free_flag_sym(struct tep_print_flag_sym *fsym)
 {
-       struct print_flag_sym *next;
+       struct tep_print_flag_sym *next;
 
        while (fsym) {
                next = fsym->next;
@@ -793,60 +795,60 @@ static void free_flag_sym(struct print_flag_sym *fsym)
        }
 }
 
-static void free_arg(struct print_arg *arg)
+static void free_arg(struct tep_print_arg *arg)
 {
-       struct print_arg *farg;
+       struct tep_print_arg *farg;
 
        if (!arg)
                return;
 
        switch (arg->type) {
-       case PRINT_ATOM:
+       case TEP_PRINT_ATOM:
                free(arg->atom.atom);
                break;
-       case PRINT_FIELD:
+       case TEP_PRINT_FIELD:
                free(arg->field.name);
                break;
-       case PRINT_FLAGS:
+       case TEP_PRINT_FLAGS:
                free_arg(arg->flags.field);
                free(arg->flags.delim);
                free_flag_sym(arg->flags.flags);
                break;
-       case PRINT_SYMBOL:
+       case TEP_PRINT_SYMBOL:
                free_arg(arg->symbol.field);
                free_flag_sym(arg->symbol.symbols);
                break;
-       case PRINT_HEX:
-       case PRINT_HEX_STR:
+       case TEP_PRINT_HEX:
+       case TEP_PRINT_HEX_STR:
                free_arg(arg->hex.field);
                free_arg(arg->hex.size);
                break;
-       case PRINT_INT_ARRAY:
+       case TEP_PRINT_INT_ARRAY:
                free_arg(arg->int_array.field);
                free_arg(arg->int_array.count);
                free_arg(arg->int_array.el_size);
                break;
-       case PRINT_TYPE:
+       case TEP_PRINT_TYPE:
                free(arg->typecast.type);
                free_arg(arg->typecast.item);
                break;
-       case PRINT_STRING:
-       case PRINT_BSTRING:
+       case TEP_PRINT_STRING:
+       case TEP_PRINT_BSTRING:
                free(arg->string.string);
                break;
-       case PRINT_BITMASK:
+       case TEP_PRINT_BITMASK:
                free(arg->bitmask.bitmask);
                break;
-       case PRINT_DYNAMIC_ARRAY:
-       case PRINT_DYNAMIC_ARRAY_LEN:
+       case TEP_PRINT_DYNAMIC_ARRAY:
+       case TEP_PRINT_DYNAMIC_ARRAY_LEN:
                free(arg->dynarray.index);
                break;
-       case PRINT_OP:
+       case TEP_PRINT_OP:
                free(arg->op.op);
                free_arg(arg->op.left);
                free_arg(arg->op.right);
                break;
-       case PRINT_FUNC:
+       case TEP_PRINT_FUNC:
                while (arg->func.args) {
                        farg = arg->func.args;
                        arg->func.args = farg->next;
@@ -854,7 +856,7 @@ static void free_arg(struct print_arg *arg)
                }
                break;
 
-       case PRINT_NULL:
+       case TEP_PRINT_NULL:
        default:
                break;
        }
@@ -862,24 +864,24 @@ static void free_arg(struct print_arg *arg)
        free(arg);
 }
 
-static enum event_type get_type(int ch)
+static enum tep_event_type get_type(int ch)
 {
        if (ch == '\n')
-               return EVENT_NEWLINE;
+               return TEP_EVENT_NEWLINE;
        if (isspace(ch))
-               return EVENT_SPACE;
+               return TEP_EVENT_SPACE;
        if (isalnum(ch) || ch == '_')
-               return EVENT_ITEM;
+               return TEP_EVENT_ITEM;
        if (ch == '\'')
-               return EVENT_SQUOTE;
+               return TEP_EVENT_SQUOTE;
        if (ch == '"')
-               return EVENT_DQUOTE;
+               return TEP_EVENT_DQUOTE;
        if (!isprint(ch))
-               return EVENT_NONE;
+               return TEP_EVENT_NONE;
        if (ch == '(' || ch == ')' || ch == ',')
-               return EVENT_DELIM;
+               return TEP_EVENT_DELIM;
 
-       return EVENT_OP;
+       return TEP_EVENT_OP;
 }
 
 static int __read_char(void)
@@ -927,38 +929,38 @@ static int extend_token(char **tok, char *buf, int size)
        return 0;
 }
 
-static enum event_type force_token(const char *str, char **tok);
+static enum tep_event_type force_token(const char *str, char **tok);
 
-static enum event_type __read_token(char **tok)
+static enum tep_event_type __read_token(char **tok)
 {
        char buf[BUFSIZ];
        int ch, last_ch, quote_ch, next_ch;
        int i = 0;
        int tok_size = 0;
-       enum event_type type;
+       enum tep_event_type type;
 
        *tok = NULL;
 
 
        ch = __read_char();
        if (ch < 0)
-               return EVENT_NONE;
+               return TEP_EVENT_NONE;
 
        type = get_type(ch);
-       if (type == EVENT_NONE)
+       if (type == TEP_EVENT_NONE)
                return type;
 
        buf[i++] = ch;
 
        switch (type) {
-       case EVENT_NEWLINE:
-       case EVENT_DELIM:
+       case TEP_EVENT_NEWLINE:
+       case TEP_EVENT_DELIM:
                if (asprintf(tok, "%c", ch) < 0)
-                       return EVENT_ERROR;
+                       return TEP_EVENT_ERROR;
 
                return type;
 
-       case EVENT_OP:
+       case TEP_EVENT_OP:
                switch (ch) {
                case '-':
                        next_ch = __peek_char();
@@ -1001,8 +1003,8 @@ static enum event_type __read_token(char **tok)
                        buf[i++] = __read_char();
                goto out;
 
-       case EVENT_DQUOTE:
-       case EVENT_SQUOTE:
+       case TEP_EVENT_DQUOTE:
+       case TEP_EVENT_SQUOTE:
                /* don't keep quotes */
                i--;
                quote_ch = ch;
@@ -1014,7 +1016,7 @@ static enum event_type __read_token(char **tok)
                                tok_size += BUFSIZ;
 
                                if (extend_token(tok, buf, tok_size) < 0)
-                                       return EVENT_NONE;
+                                       return TEP_EVENT_NONE;
                                i = 0;
                        }
                        last_ch = ch;
@@ -1031,7 +1033,7 @@ static enum event_type __read_token(char **tok)
                 * For strings (double quotes) check the next token.
                 * If it is another string, concatinate the two.
                 */
-               if (type == EVENT_DQUOTE) {
+               if (type == TEP_EVENT_DQUOTE) {
                        unsigned long long save_input_buf_ptr = input_buf_ptr;
 
                        do {
@@ -1044,8 +1046,8 @@ static enum event_type __read_token(char **tok)
 
                goto out;
 
-       case EVENT_ERROR ... EVENT_SPACE:
-       case EVENT_ITEM:
+       case TEP_EVENT_ERROR ... TEP_EVENT_SPACE:
+       case TEP_EVENT_ITEM:
        default:
                break;
        }
@@ -1056,7 +1058,7 @@ static enum event_type __read_token(char **tok)
                        tok_size += BUFSIZ;
 
                        if (extend_token(tok, buf, tok_size) < 0)
-                               return EVENT_NONE;
+                               return TEP_EVENT_NONE;
                        i = 0;
                }
                ch = __read_char();
@@ -1066,9 +1068,9 @@ static enum event_type __read_token(char **tok)
  out:
        buf[i] = 0;
        if (extend_token(tok, buf, tok_size + i + 1) < 0)
-               return EVENT_NONE;
+               return TEP_EVENT_NONE;
 
-       if (type == EVENT_ITEM) {
+       if (type == TEP_EVENT_ITEM) {
                /*
                 * Older versions of the kernel has a bug that
                 * creates invalid symbols and will break the mac80211
@@ -1095,12 +1097,12 @@ static enum event_type __read_token(char **tok)
        return type;
 }
 
-static enum event_type force_token(const char *str, char **tok)
+static enum tep_event_type force_token(const char *str, char **tok)
 {
        const char *save_input_buf;
        unsigned long long save_input_buf_ptr;
        unsigned long long save_input_buf_siz;
-       enum event_type type;
+       enum tep_event_type type;
        
        /* save off the current input pointers */
        save_input_buf = input_buf;
@@ -1125,13 +1127,13 @@ static void free_token(char *tok)
                free(tok);
 }
 
-static enum event_type read_token(char **tok)
+static enum tep_event_type read_token(char **tok)
 {
-       enum event_type type;
+       enum tep_event_type type;
 
        for (;;) {
                type = __read_token(tok);
-               if (type != EVENT_SPACE)
+               if (type != TEP_EVENT_SPACE)
                        return type;
 
                free_token(*tok);
@@ -1139,7 +1141,7 @@ static enum event_type read_token(char **tok)
 
        /* not reached */
        *tok = NULL;
-       return EVENT_NONE;
+       return TEP_EVENT_NONE;
 }
 
 /**
@@ -1151,7 +1153,7 @@ static enum event_type read_token(char **tok)
  *
  * Returns the token type.
  */
-enum event_type tep_read_token(char **tok)
+enum tep_event_type tep_read_token(char **tok)
 {
        return read_token(tok);
 }
@@ -1166,13 +1168,13 @@ void tep_free_token(char *token)
 }
 
 /* no newline */
-static enum event_type read_token_item(char **tok)
+static enum tep_event_type read_token_item(char **tok)
 {
-       enum event_type type;
+       enum tep_event_type type;
 
        for (;;) {
                type = __read_token(tok);
-               if (type != EVENT_SPACE && type != EVENT_NEWLINE)
+               if (type != TEP_EVENT_SPACE && type != TEP_EVENT_NEWLINE)
                        return type;
                free_token(*tok);
                *tok = NULL;
@@ -1180,10 +1182,10 @@ static enum event_type read_token_item(char **tok)
 
        /* not reached */
        *tok = NULL;
-       return EVENT_NONE;
+       return TEP_EVENT_NONE;
 }
 
-static int test_type(enum event_type type, enum event_type expect)
+static int test_type(enum tep_event_type type, enum tep_event_type expect)
 {
        if (type != expect) {
                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)
        return 0;
 }
 
-static int test_type_token(enum event_type type, const char *token,
-                   enum event_type expect, const char *expect_tok)
+static int test_type_token(enum tep_event_type type, const char *token,
+                   enum tep_event_type expect, const char *expect_tok)
 {
        if (type != expect) {
                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,
        return 0;
 }
 
-static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
+static int __read_expect_type(enum tep_event_type expect, char **tok, int newline_ok)
 {
-       enum event_type type;
+       enum tep_event_type type;
 
        if (newline_ok)
                type = read_token(tok);
@@ -1221,15 +1223,15 @@ static int __read_expect_type(enum event_type expect, char **tok, int newline_ok
        return test_type(type, expect);
 }
 
-static int read_expect_type(enum event_type expect, char **tok)
+static int read_expect_type(enum tep_event_type expect, char **tok)
 {
        return __read_expect_type(expect, tok, 1);
 }
 
-static int __read_expected(enum event_type expect, const char *str,
+static int __read_expected(enum tep_event_type expect, const char *str,
                           int newline_ok)
 {
-       enum event_type type;
+       enum tep_event_type type;
        char *token;
        int ret;
 
@@ -1245,12 +1247,12 @@ static int __read_expected(enum event_type expect, const char *str,
        return ret;
 }
 
-static int read_expected(enum event_type expect, const char *str)
+static int read_expected(enum tep_event_type expect, const char *str)
 {
        return __read_expected(expect, str, 1);
 }
 
-static int read_expected_item(enum event_type expect, const char *str)
+static int read_expected_item(enum tep_event_type expect, const char *str)
 {
        return __read_expected(expect, str, 0);
 }
@@ -1259,13 +1261,13 @@ static char *event_read_name(void)
 {
        char *token;
 
-       if (read_expected(EVENT_ITEM, "name") < 0)
+       if (read_expected(TEP_EVENT_ITEM, "name") < 0)
                return NULL;
 
-       if (read_expected(EVENT_OP, ":") < 0)
+       if (read_expected(TEP_EVENT_OP, ":") < 0)
                return NULL;
 
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto fail;
 
        return token;
@@ -1280,13 +1282,13 @@ static int event_read_id(void)
        char *token;
        int id;
 
-       if (read_expected_item(EVENT_ITEM, "ID") < 0)
+       if (read_expected_item(TEP_EVENT_ITEM, "ID") < 0)
                return -1;
 
-       if (read_expected(EVENT_OP, ":") < 0)
+       if (read_expected(TEP_EVENT_OP, ":") < 0)
                return -1;
 
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto fail;
 
        id = strtoul(token, NULL, 0);
@@ -1298,9 +1300,9 @@ static int event_read_id(void)
        return -1;
 }
 
-static int field_is_string(struct format_field *field)
+static int field_is_string(struct tep_format_field *field)
 {
-       if ((field->flags & FIELD_IS_ARRAY) &&
+       if ((field->flags & TEP_FIELD_IS_ARRAY) &&
            (strstr(field->type, "char") || strstr(field->type, "u8") ||
             strstr(field->type, "s8")))
                return 1;
@@ -1308,7 +1310,7 @@ static int field_is_string(struct format_field *field)
        return 0;
 }
 
-static int field_is_dynamic(struct format_field *field)
+static int field_is_dynamic(struct tep_format_field *field)
 {
        if (strncmp(field->type, "__data_loc", 10) == 0)
                return 1;
@@ -1316,7 +1318,7 @@ static int field_is_dynamic(struct format_field *field)
        return 0;
 }
 
-static int field_is_long(struct format_field *field)
+static int field_is_long(struct tep_format_field *field)
 {
        /* includes long long */
        if (strstr(field->type, "long"))
@@ -1327,7 +1329,7 @@ static int field_is_long(struct format_field *field)
 
 static unsigned int type_size(const char *name)
 {
-       /* This covers all FIELD_IS_STRING types. */
+       /* This covers all TEP_FIELD_IS_STRING types. */
        static struct {
                const char *type;
                unsigned int size;
@@ -1353,10 +1355,10 @@ static unsigned int type_size(const char *name)
        return 0;
 }
 
-static int event_read_fields(struct event_format *event, struct format_field **fields)
+static int event_read_fields(struct tep_event_format *event, struct tep_format_field **fields)
 {
-       struct format_field *field = NULL;
-       enum event_type type;
+       struct tep_format_field *field = NULL;
+       enum tep_event_type type;
        char *token;
        char *last_token;
        int count = 0;
@@ -1365,14 +1367,14 @@ static int event_read_fields(struct event_format *event, struct format_field **f
                unsigned int size_dynamic = 0;
 
                type = read_token(&token);
-               if (type == EVENT_NEWLINE) {
+               if (type == TEP_EVENT_NEWLINE) {
                        free_token(token);
                        return count;
                }
 
                count++;
 
-               if (test_type_token(type, token, EVENT_ITEM, "field"))
+               if (test_type_token(type, token, TEP_EVENT_ITEM, "field"))
                        goto fail;
                free_token(token);
 
@@ -1381,17 +1383,17 @@ static int event_read_fields(struct event_format *event, struct format_field **f
                 * The ftrace fields may still use the "special" name.
                 * Just ignore it.
                 */
-               if (event->flags & EVENT_FL_ISFTRACE &&
-                   type == EVENT_ITEM && strcmp(token, "special") == 0) {
+               if (event->flags & TEP_EVENT_FL_ISFTRACE &&
+                   type == TEP_EVENT_ITEM && strcmp(token, "special") == 0) {
                        free_token(token);
                        type = read_token(&token);
                }
 
-               if (test_type_token(type, token, EVENT_OP, ":") < 0)
+               if (test_type_token(type, token, TEP_EVENT_OP, ":") < 0)
                        goto fail;
 
                free_token(token);
-               if (read_expect_type(EVENT_ITEM, &token) < 0)
+               if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                        goto fail;
 
                last_token = token;
@@ -1405,17 +1407,17 @@ static int event_read_fields(struct event_format *event, struct format_field **f
                /* read the rest of the type */
                for (;;) {
                        type = read_token(&token);
-                       if (type == EVENT_ITEM ||
-                           (type == EVENT_OP && strcmp(token, "*") == 0) ||
+                       if (type == TEP_EVENT_ITEM ||
+                           (type == TEP_EVENT_OP && strcmp(token, "*") == 0) ||
                            /*
                             * Some of the ftrace fields are broken and have
                             * an illegal "." in them.
                             */
-                           (event->flags & EVENT_FL_ISFTRACE &&
-                            type == EVENT_OP && strcmp(token, ".") == 0)) {
+                           (event->flags & TEP_EVENT_FL_ISFTRACE &&
+                            type == TEP_EVENT_OP && strcmp(token, ".") == 0)) {
 
                                if (strcmp(token, "*") == 0)
-                                       field->flags |= FIELD_IS_POINTER;
+                                       field->flags |= TEP_FIELD_IS_POINTER;
 
                                if (field->type) {
                                        char *new_type;
@@ -1445,27 +1447,27 @@ static int event_read_fields(struct event_format *event, struct format_field **f
                }
                field->name = field->alias = last_token;
 
-               if (test_type(type, EVENT_OP))
+               if (test_type(type, TEP_EVENT_OP))
                        goto fail;
 
                if (strcmp(token, "[") == 0) {
-                       enum event_type last_type = type;
+                       enum tep_event_type last_type = type;
                        char *brackets = token;
                        char *new_brackets;
                        int len;
 
-                       field->flags |= FIELD_IS_ARRAY;
+                       field->flags |= TEP_FIELD_IS_ARRAY;
 
                        type = read_token(&token);
 
-                       if (type == EVENT_ITEM)
+                       if (type == TEP_EVENT_ITEM)
                                field->arraylen = strtoul(token, NULL, 0);
                        else
                                field->arraylen = 0;
 
                        while (strcmp(token, "]") != 0) {
-                               if (last_type == EVENT_ITEM &&
-                                   type == EVENT_ITEM)
+                               if (last_type == TEP_EVENT_ITEM &&
+                                   type == TEP_EVENT_ITEM)
                                        len = 2;
                                else
                                        len = 1;
@@ -1486,7 +1488,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
                                field->arraylen = strtoul(token, NULL, 0);
                                free_token(token);
                                type = read_token(&token);
-                               if (type == EVENT_NONE) {
+                               if (type == TEP_EVENT_NONE) {
                                        do_warning_event(event, "failed to find token");
                                        goto fail;
                                }
@@ -1509,7 +1511,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
                         * If the next token is not an OP, then it is of
                         * the format: type [] item;
                         */
-                       if (type == EVENT_ITEM) {
+                       if (type == TEP_EVENT_ITEM) {
                                char *new_type;
                                new_type = realloc(field->type,
                                                   strlen(field->type) +
@@ -1543,79 +1545,79 @@ static int event_read_fields(struct event_format *event, struct format_field **f
                }
 
                if (field_is_string(field))
-                       field->flags |= FIELD_IS_STRING;
+                       field->flags |= TEP_FIELD_IS_STRING;
                if (field_is_dynamic(field))
-                       field->flags |= FIELD_IS_DYNAMIC;
+                       field->flags |= TEP_FIELD_IS_DYNAMIC;
                if (field_is_long(field))
-                       field->flags |= FIELD_IS_LONG;
+                       field->flags |= TEP_FIELD_IS_LONG;
 
-               if (test_type_token(type, token,  EVENT_OP, ";"))
+               if (test_type_token(type, token,  TEP_EVENT_OP, ";"))
                        goto fail;
                free_token(token);
 
-               if (read_expected(EVENT_ITEM, "offset") < 0)
+               if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
                        goto fail_expect;
 
-               if (read_expected(EVENT_OP, ":") < 0)
+               if (read_expected(TEP_EVENT_OP, ":") < 0)
                        goto fail_expect;
 
-               if (read_expect_type(EVENT_ITEM, &token))
+               if (read_expect_type(TEP_EVENT_ITEM, &token))
                        goto fail;
                field->offset = strtoul(token, NULL, 0);
                free_token(token);
 
-               if (read_expected(EVENT_OP, ";") < 0)
+               if (read_expected(TEP_EVENT_OP, ";") < 0)
                        goto fail_expect;
 
-               if (read_expected(EVENT_ITEM, "size") < 0)
+               if (read_expected(TEP_EVENT_ITEM, "size") < 0)
                        goto fail_expect;
 
-               if (read_expected(EVENT_OP, ":") < 0)
+               if (read_expected(TEP_EVENT_OP, ":") < 0)
                        goto fail_expect;
 
-               if (read_expect_type(EVENT_ITEM, &token))
+               if (read_expect_type(TEP_EVENT_ITEM, &token))
                        goto fail;
                field->size = strtoul(token, NULL, 0);
                free_token(token);
 
-               if (read_expected(EVENT_OP, ";") < 0)
+               if (read_expected(TEP_EVENT_OP, ";") < 0)
                        goto fail_expect;
 
                type = read_token(&token);
-               if (type != EVENT_NEWLINE) {
+               if (type != TEP_EVENT_NEWLINE) {
                        /* newer versions of the kernel have a "signed" type */
-                       if (test_type_token(type, token, EVENT_ITEM, "signed"))
+                       if (test_type_token(type, token, TEP_EVENT_ITEM, "signed"))
                                goto fail;
 
                        free_token(token);
 
-                       if (read_expected(EVENT_OP, ":") < 0)
+                       if (read_expected(TEP_EVENT_OP, ":") < 0)
                                goto fail_expect;
 
-                       if (read_expect_type(EVENT_ITEM, &token))
+                       if (read_expect_type(TEP_EVENT_ITEM, &token))
                                goto fail;
 
                        if (strtoul(token, NULL, 0))
-                               field->flags |= FIELD_IS_SIGNED;
+                               field->flags |= TEP_FIELD_IS_SIGNED;
 
                        free_token(token);
-                       if (read_expected(EVENT_OP, ";") < 0)
+                       if (read_expected(TEP_EVENT_OP, ";") < 0)
                                goto fail_expect;
 
-                       if (read_expect_type(EVENT_NEWLINE, &token))
+                       if (read_expect_type(TEP_EVENT_NEWLINE, &token))
                                goto fail;
                }
 
                free_token(token);
 
-               if (field->flags & FIELD_IS_ARRAY) {
+               if (field->flags & TEP_FIELD_IS_ARRAY) {
                        if (field->arraylen)
                                field->elementsize = field->size / field->arraylen;
-                       else if (field->flags & FIELD_IS_DYNAMIC)
+                       else if (field->flags & TEP_FIELD_IS_DYNAMIC)
                                field->elementsize = size_dynamic;
-                       else if (field->flags & FIELD_IS_STRING)
+                       else if (field->flags & TEP_FIELD_IS_STRING)
                                field->elementsize = 1;
-                       else if (field->flags & FIELD_IS_LONG)
+                       else if (field->flags & TEP_FIELD_IS_LONG)
                                field->elementsize = event->pevent ?
                                                     event->pevent->long_size :
                                                     sizeof(long);
@@ -1640,18 +1642,18 @@ fail_expect:
        return -1;
 }
 
-static int event_read_format(struct event_format *event)
+static int event_read_format(struct tep_event_format *event)
 {
        char *token;
        int ret;
 
-       if (read_expected_item(EVENT_ITEM, "format") < 0)
+       if (read_expected_item(TEP_EVENT_ITEM, "format") < 0)
                return -1;
 
-       if (read_expected(EVENT_OP, ":") < 0)
+       if (read_expected(TEP_EVENT_OP, ":") < 0)
                return -1;
 
-       if (read_expect_type(EVENT_NEWLINE, &token))
+       if (read_expect_type(TEP_EVENT_NEWLINE, &token))
                goto fail;
        free_token(token);
 
@@ -1672,14 +1674,14 @@ static int event_read_format(struct event_format *event)
        return -1;
 }
 
-static enum event_type
-process_arg_token(struct event_format *event, struct print_arg *arg,
-                 char **tok, enum event_type type);
+static enum tep_event_type
+process_arg_token(struct tep_event_format *event, struct tep_print_arg *arg,
+                 char **tok, enum tep_event_type type);
 
-static enum event_type
-process_arg(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_arg(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       enum event_type type;
+       enum tep_event_type type;
        char *token;
 
        type = read_token(&token);
@@ -1688,32 +1690,32 @@ process_arg(struct event_format *event, struct print_arg *arg, char **tok)
        return process_arg_token(event, arg, tok, type);
 }
 
-static enum event_type
-process_op(struct event_format *event, struct print_arg *arg, char **tok);
+static enum tep_event_type
+process_op(struct tep_event_format *event, struct tep_print_arg *arg, char **tok);
 
 /*
  * For __print_symbolic() and __print_flags, we need to completely
  * evaluate the first argument, which defines what to print next.
  */
-static enum event_type
-process_field_arg(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_field_arg(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       enum event_type type;
+       enum tep_event_type type;
 
        type = process_arg(event, arg, tok);
 
-       while (type == EVENT_OP) {
+       while (type == TEP_EVENT_OP) {
                type = process_op(event, arg, tok);
        }
 
        return type;
 }
 
-static enum event_type
-process_cond(struct event_format *event, struct print_arg *top, char **tok)
+static enum tep_event_type
+process_cond(struct tep_event_format *event, struct tep_print_arg *top, char **tok)
 {
-       struct print_arg *arg, *left, *right;
-       enum event_type type;
+       struct tep_print_arg *arg, *left, *right;
+       enum tep_event_type type;
        char *token = NULL;
 
        arg = alloc_arg();
@@ -1728,7 +1730,7 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok)
                goto out_free;
        }
 
-       arg->type = PRINT_OP;
+       arg->type = TEP_PRINT_OP;
        arg->op.left = left;
        arg->op.right = right;
 
@@ -1736,16 +1738,16 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok)
        type = process_arg(event, left, &token);
 
  again:
-       if (type == EVENT_ERROR)
+       if (type == TEP_EVENT_ERROR)
                goto out_free;
 
        /* Handle other operations in the arguments */
-       if (type == EVENT_OP && strcmp(token, ":") != 0) {
+       if (type == TEP_EVENT_OP && strcmp(token, ":") != 0) {
                type = process_op(event, left, &token);
                goto again;
        }
 
-       if (test_type_token(type, token, EVENT_OP, ":"))
+       if (test_type_token(type, token, TEP_EVENT_OP, ":"))
                goto out_free;
 
        arg->op.op = token;
@@ -1762,14 +1764,14 @@ out_free:
        top->op.right = NULL;
        free_token(token);
        free_arg(arg);
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_array(struct event_format *event, struct print_arg *top, char **tok)
+static enum tep_event_type
+process_array(struct tep_event_format *event, struct tep_print_arg *top, char **tok)
 {
-       struct print_arg *arg;
-       enum event_type type;
+       struct tep_print_arg *arg;
+       enum tep_event_type type;
        char *token = NULL;
 
        arg = alloc_arg();
@@ -1777,12 +1779,12 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
                do_warning_event(event, "%s: not enough memory!", __func__);
                /* '*tok' is set to top->op.op.  No need to free. */
                *tok = NULL;
-               return EVENT_ERROR;
+               return TEP_EVENT_ERROR;
        }
 
        *tok = NULL;
        type = process_arg(event, arg, &token);
-       if (test_type_token(type, token, EVENT_OP, "]"))
+       if (test_type_token(type, token, TEP_EVENT_OP, "]"))
                goto out_free;
 
        top->op.right = arg;
@@ -1796,7 +1798,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
 out_free:
        free_token(token);
        free_arg(arg);
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
 static int get_op_prio(char *op)
@@ -1854,11 +1856,11 @@ static int get_op_prio(char *op)
        }
 }
 
-static int set_op_prio(struct print_arg *arg)
+static int set_op_prio(struct tep_print_arg *arg)
 {
 
        /* single ops are the greatest */
-       if (!arg->op.left || arg->op.left->type == PRINT_NULL)
+       if (!arg->op.left || arg->op.left->type == TEP_PRINT_NULL)
                arg->op.prio = 0;
        else
                arg->op.prio = get_op_prio(arg->op.op);
@@ -1867,17 +1869,17 @@ static int set_op_prio(struct print_arg *arg)
 }
 
 /* Note, *tok does not get freed, but will most likely be saved */
-static enum event_type
-process_op(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_op(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       struct print_arg *left, *right = NULL;
-       enum event_type type;
+       struct tep_print_arg *left, *right = NULL;
+       enum tep_event_type type;
        char *token;
 
        /* the op is passed in via tok */
        token = *tok;
 
-       if (arg->type == PRINT_OP && !arg->op.left) {
+       if (arg->type == TEP_PRINT_OP && !arg->op.left) {
                /* handle single op */
                if (token[1]) {
                        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)
                if (!left)
                        goto out_warn_free;
 
-               left->type = PRINT_NULL;
+               left->type = TEP_PRINT_NULL;
                arg->op.left = left;
 
                right = alloc_arg();
@@ -1922,7 +1924,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
                /* copy the top arg to the left */
                *left = *arg;
 
-               arg->type = PRINT_OP;
+               arg->type = TEP_PRINT_OP;
                arg->op.op = token;
                arg->op.left = left;
                arg->op.prio = 0;
@@ -1956,13 +1958,13 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
                /* copy the top arg to the left */
                *left = *arg;
 
-               arg->type = PRINT_OP;
+               arg->type = TEP_PRINT_OP;
                arg->op.op = token;
                arg->op.left = left;
                arg->op.right = NULL;
 
                if (set_op_prio(arg) == -1) {
-                       event->flags |= EVENT_FL_FAILED;
+                       event->flags |= TEP_EVENT_FL_FAILED;
                        /* arg->op.op (= token) will be freed at out_free */
                        arg->op.op = NULL;
                        goto out_free;
@@ -1973,10 +1975,10 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
 
                /* could just be a type pointer */
                if ((strcmp(arg->op.op, "*") == 0) &&
-                   type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
+                   type == TEP_EVENT_DELIM && (strcmp(token, ")") == 0)) {
                        char *new_atom;
 
-                       if (left->type != PRINT_ATOM) {
+                       if (left->type != TEP_PRINT_ATOM) {
                                do_warning_event(event, "bad pointer type");
                                goto out_free;
                        }
@@ -1999,16 +2001,16 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
                        goto out_warn_free;
 
                type = process_arg_token(event, right, tok, type);
-               if (type == EVENT_ERROR) {
+               if (type == TEP_EVENT_ERROR) {
                        free_arg(right);
                        /* token was freed in process_arg_token() via *tok */
                        token = NULL;
                        goto out_free;
                }
 
-               if (right->type == PRINT_OP &&
+               if (right->type == TEP_PRINT_OP &&
                    get_op_prio(arg->op.op) < get_op_prio(right->op.op)) {
-                       struct print_arg tmp;
+                       struct tep_print_arg tmp;
 
                        /* rotate ops according to the priority */
                        arg->op.right = right->op.left;
@@ -2030,7 +2032,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
 
                *left = *arg;
 
-               arg->type = PRINT_OP;
+               arg->type = TEP_PRINT_OP;
                arg->op.op = token;
                arg->op.left = left;
 
@@ -2041,12 +2043,12 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
 
        } else {
                do_warning_event(event, "unknown op '%s'", token);
-               event->flags |= EVENT_FL_FAILED;
+               event->flags |= TEP_EVENT_FL_FAILED;
                /* the arg is now the left side */
                goto out_free;
        }
 
-       if (type == EVENT_OP && strcmp(*tok, ":") != 0) {
+       if (type == TEP_EVENT_OP && strcmp(*tok, ":") != 0) {
                int prio;
 
                /* higher prios need to be closer to the root */
@@ -2065,34 +2067,34 @@ out_warn_free:
 out_free:
        free_token(token);
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
+static enum tep_event_type
+process_entry(struct tep_event_format *event __maybe_unused, struct tep_print_arg *arg,
              char **tok)
 {
-       enum event_type type;
+       enum tep_event_type type;
        char *field;
        char *token;
 
-       if (read_expected(EVENT_OP, "->") < 0)
+       if (read_expected(TEP_EVENT_OP, "->") < 0)
                goto out_err;
 
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto out_free;
        field = token;
 
-       arg->type = PRINT_FIELD;
+       arg->type = TEP_PRINT_FIELD;
        arg->field.name = field;
 
        if (is_flag_field) {
                arg->field.field = tep_find_any_field(event, arg->field.name);
-               arg->field.field->flags |= FIELD_IS_FLAG;
+               arg->field.field->flags |= TEP_FIELD_IS_FLAG;
                is_flag_field = 0;
        } else if (is_symbolic_field) {
                arg->field.field = tep_find_any_field(event, arg->field.name);
-               arg->field.field->flags |= FIELD_IS_SYMBOLIC;
+               arg->field.field->flags |= TEP_FIELD_IS_SYMBOLIC;
                is_symbolic_field = 0;
        }
 
@@ -2105,14 +2107,14 @@ process_entry(struct event_format *event __maybe_unused, struct print_arg *arg,
        free_token(token);
  out_err:
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static int alloc_and_process_delim(struct event_format *event, char *next_token,
-                                  struct print_arg **print_arg)
+static int alloc_and_process_delim(struct tep_event_format *event, char *next_token,
+                                  struct tep_print_arg **print_arg)
 {
-       struct print_arg *field;
-       enum event_type type;
+       struct tep_print_arg *field;
+       enum tep_event_type type;
        char *token;
        int ret = 0;
 
@@ -2125,7 +2127,7 @@ static int alloc_and_process_delim(struct event_format *event, char *next_token,
 
        type = process_arg(event, field, &token);
 
-       if (test_type_token(type, token, EVENT_DELIM, next_token)) {
+       if (test_type_token(type, token, TEP_EVENT_DELIM, next_token)) {
                errno = EINVAL;
                ret = -1;
                free_arg(field);
@@ -2140,7 +2142,7 @@ out_free_token:
        return ret;
 }
 
-static char *arg_eval (struct print_arg *arg);
+static char *arg_eval (struct tep_print_arg *arg);
 
 static unsigned long long
 eval_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)
  * Try to figure out the type.
  */
 static unsigned long long
-eval_type(unsigned long long val, struct print_arg *arg, int pointer)
+eval_type(unsigned long long val, struct tep_print_arg *arg, int pointer)
 {
-       if (arg->type != PRINT_TYPE) {
+       if (arg->type != TEP_PRINT_TYPE) {
                do_warning("expected type argument");
                return 0;
        }
@@ -2247,22 +2249,22 @@ eval_type(unsigned long long val, struct print_arg *arg, int pointer)
        return eval_type_str(val, arg->typecast.type, pointer);
 }
 
-static int arg_num_eval(struct print_arg *arg, long long *val)
+static int arg_num_eval(struct tep_print_arg *arg, long long *val)
 {
        long long left, right;
        int ret = 1;
 
        switch (arg->type) {
-       case PRINT_ATOM:
+       case TEP_PRINT_ATOM:
                *val = strtoll(arg->atom.atom, NULL, 0);
                break;
-       case PRINT_TYPE:
+       case TEP_PRINT_TYPE:
                ret = arg_num_eval(arg->typecast.item, val);
                if (!ret)
                        break;
                *val = eval_type(*val, arg, 0);
                break;
-       case PRINT_OP:
+       case TEP_PRINT_OP:
                switch (arg->op.op[0]) {
                case '|':
                        ret = arg_num_eval(arg->op.left, &left);
@@ -2365,7 +2367,7 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
                        break;
                case '-':
                        /* check for negative */
-                       if (arg->op.left->type == PRINT_NULL)
+                       if (arg->op.left->type == TEP_PRINT_NULL)
                                left = 0;
                        else
                                ret = arg_num_eval(arg->op.left, &left);
@@ -2377,7 +2379,7 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
                        *val = left - right;
                        break;
                case '+':
-                       if (arg->op.left->type == PRINT_NULL)
+                       if (arg->op.left->type == TEP_PRINT_NULL)
                                left = 0;
                        else
                                ret = arg_num_eval(arg->op.left, &left);
@@ -2400,11 +2402,11 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
                }
                break;
 
-       case PRINT_NULL:
-       case PRINT_FIELD ... PRINT_SYMBOL:
-       case PRINT_STRING:
-       case PRINT_BSTRING:
-       case PRINT_BITMASK:
+       case TEP_PRINT_NULL:
+       case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
+       case TEP_PRINT_STRING:
+       case TEP_PRINT_BSTRING:
+       case TEP_PRINT_BITMASK:
        default:
                do_warning("invalid eval type %d", arg->type);
                ret = 0;
@@ -2413,27 +2415,27 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
        return ret;
 }
 
-static char *arg_eval (struct print_arg *arg)
+static char *arg_eval (struct tep_print_arg *arg)
 {
        long long val;
        static char buf[20];
 
        switch (arg->type) {
-       case PRINT_ATOM:
+       case TEP_PRINT_ATOM:
                return arg->atom.atom;
-       case PRINT_TYPE:
+       case TEP_PRINT_TYPE:
                return arg_eval(arg->typecast.item);
-       case PRINT_OP:
+       case TEP_PRINT_OP:
                if (!arg_num_eval(arg, &val))
                        break;
                sprintf(buf, "%lld", val);
                return buf;
 
-       case PRINT_NULL:
-       case PRINT_FIELD ... PRINT_SYMBOL:
-       case PRINT_STRING:
-       case PRINT_BSTRING:
-       case PRINT_BITMASK:
+       case TEP_PRINT_NULL:
+       case TEP_PRINT_FIELD ... TEP_PRINT_SYMBOL:
+       case TEP_PRINT_STRING:
+       case TEP_PRINT_BSTRING:
+       case TEP_PRINT_BITMASK:
        default:
                do_warning("invalid eval type %d", arg->type);
                break;
@@ -2442,19 +2444,19 @@ static char *arg_eval (struct print_arg *arg)
        return NULL;
 }
 
-static enum event_type
-process_fields(struct event_format *event, struct print_flag_sym **list, char **tok)
+static enum tep_event_type
+process_fields(struct tep_event_format *event, struct tep_print_flag_sym **list, char **tok)
 {
-       enum event_type type;
-       struct print_arg *arg = NULL;
-       struct print_flag_sym *field;
+       enum tep_event_type type;
+       struct tep_print_arg *arg = NULL;
+       struct tep_print_flag_sym *field;
        char *token = *tok;
        char *value;
 
        do {
                free_token(token);
                type = read_token_item(&token);
-               if (test_type_token(type, token, EVENT_OP, "{"))
+               if (test_type_token(type, token, TEP_EVENT_OP, "{"))
                        break;
 
                arg = alloc_arg();
@@ -2464,13 +2466,13 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
                free_token(token);
                type = process_arg(event, arg, &token);
 
-               if (type == EVENT_OP)
+               if (type == TEP_EVENT_OP)
                        type = process_op(event, arg, &token);
 
-               if (type == EVENT_ERROR)
+               if (type == TEP_EVENT_ERROR)
                        goto out_free;
 
-               if (test_type_token(type, token, EVENT_DELIM, ","))
+               if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
                        goto out_free;
 
                field = calloc(1, sizeof(*field));
@@ -2491,7 +2493,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 
                free_token(token);
                type = process_arg(event, arg, &token);
-               if (test_type_token(type, token, EVENT_OP, "}"))
+               if (test_type_token(type, token, TEP_EVENT_OP, "}"))
                        goto out_free_field;
 
                value = arg_eval(arg);
@@ -2508,7 +2510,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 
                free_token(token);
                type = read_token_item(&token);
-       } while (type == EVENT_DELIM && strcmp(token, ",") == 0);
+       } while (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0);
 
        *tok = token;
        return type;
@@ -2520,18 +2522,18 @@ out_free:
        free_token(token);
        *tok = NULL;
 
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_flags(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_flags(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       struct print_arg *field;
-       enum event_type type;
+       struct tep_print_arg *field;
+       enum tep_event_type type;
        char *token = NULL;
 
        memset(arg, 0, sizeof(*arg));
-       arg->type = PRINT_FLAGS;
+       arg->type = TEP_PRINT_FLAGS;
 
        field = alloc_arg();
        if (!field) {
@@ -2542,10 +2544,10 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
        type = process_field_arg(event, field, &token);
 
        /* Handle operations in the first argument */
-       while (type == EVENT_OP)
+       while (type == TEP_EVENT_OP)
                type = process_op(event, field, &token);
 
-       if (test_type_token(type, token, EVENT_DELIM, ","))
+       if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
                goto out_free_field;
        free_token(token);
 
@@ -2557,11 +2559,11 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
                type = read_token_item(&token);
        }
 
-       if (test_type_token(type, token, EVENT_DELIM, ","))
+       if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
                goto out_free;
 
        type = process_fields(event, &arg->flags.flags, &token);
-       if (test_type_token(type, token, EVENT_DELIM, ")"))
+       if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
                goto out_free;
 
        free_token(token);
@@ -2573,18 +2575,18 @@ out_free_field:
 out_free:
        free_token(token);
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_symbols(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       struct print_arg *field;
-       enum event_type type;
+       struct tep_print_arg *field;
+       enum tep_event_type type;
        char *token = NULL;
 
        memset(arg, 0, sizeof(*arg));
-       arg->type = PRINT_SYMBOL;
+       arg->type = TEP_PRINT_SYMBOL;
 
        field = alloc_arg();
        if (!field) {
@@ -2594,13 +2596,13 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
 
        type = process_field_arg(event, field, &token);
 
-       if (test_type_token(type, token, EVENT_DELIM, ","))
+       if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
                goto out_free_field;
 
        arg->symbol.field = field;
 
        type = process_fields(event, &arg->symbol.symbols, &token);
-       if (test_type_token(type, token, EVENT_DELIM, ")"))
+       if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
                goto out_free;
 
        free_token(token);
@@ -2612,12 +2614,12 @@ out_free_field:
 out_free:
        free_token(token);
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_hex_common(struct event_format *event, struct print_arg *arg,
-                  char **tok, enum print_arg_type type)
+static enum tep_event_type
+process_hex_common(struct tep_event_format *event, struct tep_print_arg *arg,
+                  char **tok, enum tep_print_arg_type type)
 {
        memset(arg, 0, sizeof(*arg));
        arg->type = type;
@@ -2635,27 +2637,27 @@ free_field:
        arg->hex.field = NULL;
 out:
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_hex(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_hex(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       return process_hex_common(event, arg, tok, PRINT_HEX);
+       return process_hex_common(event, arg, tok, TEP_PRINT_HEX);
 }
 
-static enum event_type
-process_hex_str(struct event_format *event, struct print_arg *arg,
+static enum tep_event_type
+process_hex_str(struct tep_event_format *event, struct tep_print_arg *arg,
                char **tok)
 {
-       return process_hex_common(event, arg, tok, PRINT_HEX_STR);
+       return process_hex_common(event, arg, tok, TEP_PRINT_HEX_STR);
 }
 
-static enum event_type
-process_int_array(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_int_array(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
        memset(arg, 0, sizeof(*arg));
-       arg->type = PRINT_INT_ARRAY;
+       arg->type = TEP_PRINT_INT_ARRAY;
 
        if (alloc_and_process_delim(event, ",", &arg->int_array.field))
                goto out;
@@ -2676,18 +2678,18 @@ free_field:
        arg->int_array.field = NULL;
 out:
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_dynamic_array(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_dynamic_array(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       struct format_field *field;
-       enum event_type type;
+       struct tep_format_field *field;
+       enum tep_event_type type;
        char *token;
 
        memset(arg, 0, sizeof(*arg));
-       arg->type = PRINT_DYNAMIC_ARRAY;
+       arg->type = TEP_PRINT_DYNAMIC_ARRAY;
 
        /*
         * 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 **
         */
        type = read_token(&token);
        *tok = token;
-       if (type != EVENT_ITEM)
+       if (type != TEP_EVENT_ITEM)
                goto out_free;
 
        /* Find the field */
@@ -2707,13 +2709,13 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
        arg->dynarray.field = field;
        arg->dynarray.index = 0;
 
-       if (read_expected(EVENT_DELIM, ")") < 0)
+       if (read_expected(TEP_EVENT_DELIM, ")") < 0)
                goto out_free;
 
        free_token(token);
        type = read_token_item(&token);
        *tok = token;
-       if (type != EVENT_OP || strcmp(token, "[") != 0)
+       if (type != TEP_EVENT_OP || strcmp(token, "[") != 0)
                return type;
 
        free_token(token);
@@ -2721,14 +2723,14 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
        if (!arg) {
                do_warning_event(event, "%s: not enough memory!", __func__);
                *tok = NULL;
-               return EVENT_ERROR;
+               return TEP_EVENT_ERROR;
        }
 
        type = process_arg(event, arg, &token);
-       if (type == EVENT_ERROR)
+       if (type == TEP_EVENT_ERROR)
                goto out_free_arg;
 
-       if (!test_type_token(type, token, EVENT_OP, "]"))
+       if (!test_type_token(type, token, TEP_EVENT_OP, "]"))
                goto out_free_arg;
 
        free_token(token);
@@ -2740,21 +2742,21 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
  out_free:
        free_token(token);
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
+static enum tep_event_type
+process_dynamic_array_len(struct tep_event_format *event, struct tep_print_arg *arg,
                          char **tok)
 {
-       struct format_field *field;
-       enum event_type type;
+       struct tep_format_field *field;
+       enum tep_event_type type;
        char *token;
 
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto out_free;
 
-       arg->type = PRINT_DYNAMIC_ARRAY_LEN;
+       arg->type = TEP_PRINT_DYNAMIC_ARRAY_LEN;
 
        /* Find the field */
        field = tep_find_field(event, token);
@@ -2764,7 +2766,7 @@ process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
        arg->dynarray.field = field;
        arg->dynarray.index = 0;
 
-       if (read_expected(EVENT_DELIM, ")") < 0)
+       if (read_expected(TEP_EVENT_DELIM, ")") < 0)
                goto out_err;
 
        type = read_token(&token);
@@ -2776,28 +2778,28 @@ process_dynamic_array_len(struct event_format *event, struct print_arg *arg,
        free_token(token);
  out_err:
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_paren(struct event_format *event, struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_paren(struct tep_event_format *event, struct tep_print_arg *arg, char **tok)
 {
-       struct print_arg *item_arg;
-       enum event_type type;
+       struct tep_print_arg *item_arg;
+       enum tep_event_type type;
        char *token;
 
        type = process_arg(event, arg, &token);
 
-       if (type == EVENT_ERROR)
+       if (type == TEP_EVENT_ERROR)
                goto out_free;
 
-       if (type == EVENT_OP)
+       if (type == TEP_EVENT_OP)
                type = process_op(event, arg, &token);
 
-       if (type == EVENT_ERROR)
+       if (type == TEP_EVENT_ERROR)
                goto out_free;
 
-       if (test_type_token(type, token, EVENT_DELIM, ")"))
+       if (test_type_token(type, token, TEP_EVENT_DELIM, ")"))
                goto out_free;
 
        free_token(token);
@@ -2808,13 +2810,13 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
         * this was a typecast.
         */
        if (event_item_type(type) ||
-           (type == EVENT_DELIM && strcmp(token, "(") == 0)) {
+           (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0)) {
 
                /* make this a typecast and contine */
 
                /* prevous must be an atom */
-               if (arg->type != PRINT_ATOM) {
-                       do_warning_event(event, "previous needed to be PRINT_ATOM");
+               if (arg->type != TEP_PRINT_ATOM) {
+                       do_warning_event(event, "previous needed to be TEP_PRINT_ATOM");
                        goto out_free;
                }
 
@@ -2825,7 +2827,7 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
                        goto out_free;
                }
 
-               arg->type = PRINT_TYPE;
+               arg->type = TEP_PRINT_TYPE;
                arg->typecast.type = arg->atom.atom;
                arg->typecast.item = item_arg;
                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)
  out_free:
        free_token(token);
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
 
-static enum event_type
-process_str(struct event_format *event __maybe_unused, struct print_arg *arg,
+static enum tep_event_type
+process_str(struct tep_event_format *event __maybe_unused, struct tep_print_arg *arg,
            char **tok)
 {
-       enum event_type type;
+       enum tep_event_type type;
        char *token;
 
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto out_free;
 
-       arg->type = PRINT_STRING;
+       arg->type = TEP_PRINT_STRING;
        arg->string.string = token;
        arg->string.offset = -1;
 
-       if (read_expected(EVENT_DELIM, ")") < 0)
+       if (read_expected(TEP_EVENT_DELIM, ")") < 0)
                goto out_err;
 
        type = read_token(&token);
@@ -2868,24 +2870,24 @@ process_str(struct event_format *event __maybe_unused, struct print_arg *arg,
        free_token(token);
  out_err:
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg,
-           char **tok)
+static enum tep_event_type
+process_bitmask(struct tep_event_format *event __maybe_unused, struct tep_print_arg *arg,
+               char **tok)
 {
-       enum event_type type;
+       enum tep_event_type type;
        char *token;
 
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto out_free;
 
-       arg->type = PRINT_BITMASK;
+       arg->type = TEP_PRINT_BITMASK;
        arg->bitmask.bitmask = token;
        arg->bitmask.offset = -1;
 
-       if (read_expected(EVENT_DELIM, ")") < 0)
+       if (read_expected(TEP_EVENT_DELIM, ")") < 0)
                goto out_err;
 
        type = read_token(&token);
@@ -2897,7 +2899,7 @@ process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg
        free_token(token);
  out_err:
        *tok = NULL;
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
 static struct tep_function_handler *
@@ -2932,17 +2934,17 @@ static void remove_func_handler(struct tep_handle *pevent, char *func_name)
        }
 }
 
-static enum event_type
-process_func_handler(struct event_format *event, struct tep_function_handler *func,
-                    struct print_arg *arg, char **tok)
+static enum tep_event_type
+process_func_handler(struct tep_event_format *event, struct tep_function_handler *func,
+                    struct tep_print_arg *arg, char **tok)
 {
-       struct print_arg **next_arg;
-       struct print_arg *farg;
-       enum event_type type;
+       struct tep_print_arg **next_arg;
+       struct tep_print_arg *farg;
+       enum tep_event_type type;
        char *token;
        int i;
 
-       arg->type = PRINT_FUNC;
+       arg->type = TEP_PRINT_FUNC;
        arg->func.func = func;
 
        *tok = NULL;
@@ -2953,12 +2955,12 @@ process_func_handler(struct event_format *event, struct tep_function_handler *fu
                if (!farg) {
                        do_warning_event(event, "%s: not enough memory!",
                                         __func__);
-                       return EVENT_ERROR;
+                       return TEP_EVENT_ERROR;
                }
 
                type = process_arg(event, farg, &token);
                if (i < (func->nr_args - 1)) {
-                       if (type != EVENT_DELIM || strcmp(token, ",") != 0) {
+                       if (type != TEP_EVENT_DELIM || strcmp(token, ",") != 0) {
                                do_warning_event(event,
                                        "Error: function '%s()' expects %d arguments but event %s only uses %d",
                                        func->name, func->nr_args,
@@ -2966,7 +2968,7 @@ process_func_handler(struct event_format *event, struct tep_function_handler *fu
                                goto err;
                        }
                } else {
-                       if (type != EVENT_DELIM || strcmp(token, ")") != 0) {
+                       if (type != TEP_EVENT_DELIM || strcmp(token, ")") != 0) {
                                do_warning_event(event,
                                        "Error: function '%s()' only expects %d arguments but event %s has more",
                                        func->name, func->nr_args, event->name);
@@ -2987,11 +2989,11 @@ process_func_handler(struct event_format *event, struct tep_function_handler *fu
 err:
        free_arg(farg);
        free_token(token);
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_function(struct event_format *event, struct print_arg *arg,
+static enum tep_event_type
+process_function(struct tep_event_format *event, struct tep_print_arg *arg,
                 char *token, char **tok)
 {
        struct tep_function_handler *func;
@@ -3043,12 +3045,12 @@ process_function(struct event_format *event, struct print_arg *arg,
 
        do_warning_event(event, "function %s not defined", token);
        free_token(token);
-       return EVENT_ERROR;
+       return TEP_EVENT_ERROR;
 }
 
-static enum event_type
-process_arg_token(struct event_format *event, struct print_arg *arg,
-                 char **tok, enum event_type type)
+static enum tep_event_type
+process_arg_token(struct tep_event_format *event, struct tep_print_arg *arg,
+                 char **tok, enum tep_event_type type)
 {
        char *token;
        char *atom;
@@ -3056,7 +3058,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
        token = *tok;
 
        switch (type) {
-       case EVENT_ITEM:
+       case TEP_EVENT_ITEM:
                if (strcmp(token, "REC") == 0) {
                        free_token(token);
                        type = process_entry(event, arg, &token);
@@ -3070,7 +3072,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
                 * If the next token is a parenthesis, then this
                 * is a function.
                 */
-               if (type == EVENT_DELIM && strcmp(token, "(") == 0) {
+               if (type == TEP_EVENT_DELIM && strcmp(token, "(") == 0) {
                        free_token(token);
                        token = NULL;
                        /* this will free atom. */
@@ -3078,7 +3080,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
                        break;
                }
                /* atoms can be more than one token long */
-               while (type == EVENT_ITEM) {
+               while (type == TEP_EVENT_ITEM) {
                        char *new_atom;
                        new_atom = realloc(atom,
                                           strlen(atom) + strlen(token) + 2);
@@ -3086,7 +3088,7 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
                                free(atom);
                                *tok = NULL;
                                free_token(token);
-                               return EVENT_ERROR;
+                               return TEP_EVENT_ERROR;
                        }
                        atom = new_atom;
                        strcat(atom, " ");
@@ -3095,55 +3097,55 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
                        type = read_token_item(&token);
                }
 
-               arg->type = PRINT_ATOM;
+               arg->type = TEP_PRINT_ATOM;
                arg->atom.atom = atom;
                break;
 
-       case EVENT_DQUOTE:
-       case EVENT_SQUOTE:
-               arg->type = PRINT_ATOM;
+       case TEP_EVENT_DQUOTE:
+       case TEP_EVENT_SQUOTE:
+               arg->type = TEP_PRINT_ATOM;
                arg->atom.atom = token;
                type = read_token_item(&token);
                break;
-       case EVENT_DELIM:
+       case TEP_EVENT_DELIM:
                if (strcmp(token, "(") == 0) {
                        free_token(token);
                        type = process_paren(event, arg, &token);
                        break;
                }
-       case EVENT_OP:
+       case TEP_EVENT_OP:
                /* handle single ops */
-               arg->type = PRINT_OP;
+               arg->type = TEP_PRINT_OP;
                arg->op.op = token;
                arg->op.left = NULL;
                type = process_op(event, arg, &token);
 
                /* On error, the op is freed */
-               if (type == EVENT_ERROR)
+               if (type == TEP_EVENT_ERROR)
                        arg->op.op = NULL;
 
                /* return error type if errored */
                break;
 
-       case EVENT_ERROR ... EVENT_NEWLINE:
+       case TEP_EVENT_ERROR ... TEP_EVENT_NEWLINE:
        default:
                do_warning_event(event, "unexpected type %d", type);
-               return EVENT_ERROR;
+               return TEP_EVENT_ERROR;
        }
        *tok = token;
 
        return type;
 }
 
-static int event_read_print_args(struct event_format *event, struct print_arg **list)
+static int event_read_print_args(struct tep_event_format *event, struct tep_print_arg **list)
 {
-       enum event_type type = EVENT_ERROR;
-       struct print_arg *arg;
+       enum tep_event_type type = TEP_EVENT_ERROR;
+       struct tep_print_arg *arg;
        char *token;
        int args = 0;
 
        do {
-               if (type == EVENT_NEWLINE) {
+               if (type == TEP_EVENT_NEWLINE) {
                        type = read_token_item(&token);
                        continue;
                }
@@ -3157,7 +3159,7 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
 
                type = process_arg(event, arg, &token);
 
-               if (type == EVENT_ERROR) {
+               if (type == TEP_EVENT_ERROR) {
                        free_token(token);
                        free_arg(arg);
                        return -1;
@@ -3166,10 +3168,10 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
                *list = arg;
                args++;
 
-               if (type == EVENT_OP) {
+               if (type == TEP_EVENT_OP) {
                        type = process_op(event, arg, &token);
                        free_token(token);
-                       if (type == EVENT_ERROR) {
+                       if (type == TEP_EVENT_ERROR) {
                                *list = NULL;
                                free_arg(arg);
                                return -1;
@@ -3178,37 +3180,37 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
                        continue;
                }
 
-               if (type == EVENT_DELIM && strcmp(token, ",") == 0) {
+               if (type == TEP_EVENT_DELIM && strcmp(token, ",") == 0) {
                        free_token(token);
                        *list = arg;
                        list = &arg->next;
                        continue;
                }
                break;
-       } while (type != EVENT_NONE);
+       } while (type != TEP_EVENT_NONE);
 
-       if (type != EVENT_NONE && type != EVENT_ERROR)
+       if (type != TEP_EVENT_NONE && type != TEP_EVENT_ERROR)
                free_token(token);
 
        return args;
 }
 
-static int event_read_print(struct event_format *event)
+static int event_read_print(struct tep_event_format *event)
 {
-       enum event_type type;
+       enum tep_event_type type;
        char *token;
        int ret;
 
-       if (read_expected_item(EVENT_ITEM, "print") < 0)
+       if (read_expected_item(TEP_EVENT_ITEM, "print") < 0)
                return -1;
 
-       if (read_expected(EVENT_ITEM, "fmt") < 0)
+       if (read_expected(TEP_EVENT_ITEM, "fmt") < 0)
                return -1;
 
-       if (read_expected(EVENT_OP, ":") < 0)
+       if (read_expected(TEP_EVENT_OP, ":") < 0)
                return -1;
 
-       if (read_expect_type(EVENT_DQUOTE, &token) < 0)
+       if (read_expect_type(TEP_EVENT_DQUOTE, &token) < 0)
                goto fail;
 
  concat:
@@ -3218,11 +3220,11 @@ static int event_read_print(struct event_format *event)
        /* ok to have no arg */
        type = read_token_item(&token);
 
-       if (type == EVENT_NONE)
+       if (type == TEP_EVENT_NONE)
                return 0;
 
        /* Handle concatenation of print lines */
-       if (type == EVENT_DQUOTE) {
+       if (type == TEP_EVENT_DQUOTE) {
                char *cat;
 
                if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0)
@@ -3234,7 +3236,7 @@ static int event_read_print(struct event_format *event)
                goto concat;
        }
                             
-       if (test_type_token(type, token, EVENT_DELIM, ","))
+       if (test_type_token(type, token, TEP_EVENT_DELIM, ","))
                goto fail;
 
        free_token(token);
@@ -3258,10 +3260,10 @@ static int event_read_print(struct event_format *event)
  * Returns a common field from the event by the given @name.
  * This only searchs the common fields and not all field.
  */
-struct format_field *
-tep_find_common_field(struct event_format *event, const char *name)
+struct tep_format_field *
+tep_find_common_field(struct tep_event_format *event, const char *name)
 {
-       struct format_field *format;
+       struct tep_format_field *format;
 
        for (format = event->format.common_fields;
             format; format = format->next) {
@@ -3280,10 +3282,10 @@ tep_find_common_field(struct event_format *event, const char *name)
  * Returns a non-common field by the given @name.
  * This does not search common fields.
  */
-struct format_field *
-tep_find_field(struct event_format *event, const char *name)
+struct tep_format_field *
+tep_find_field(struct tep_event_format *event, const char *name)
 {
-       struct format_field *format;
+       struct tep_format_field *format;
 
        for (format = event->format.fields;
             format; format = format->next) {
@@ -3303,10 +3305,10 @@ tep_find_field(struct event_format *event, const char *name)
  * This searchs the common field names first, then
  * the non-common ones if a common one was not found.
  */
-struct format_field *
-tep_find_any_field(struct event_format *event, const char *name)
+struct tep_format_field *
+tep_find_any_field(struct tep_event_format *event, const char *name)
 {
-       struct format_field *format;
+       struct tep_format_field *format;
 
        format = tep_find_common_field(event, name);
        if (format)
@@ -3330,11 +3332,11 @@ unsigned long long tep_read_number(struct tep_handle *pevent,
        case 1:
                return *(unsigned char *)ptr;
        case 2:
-               return data2host2(pevent, ptr);
+               return tep_data2host2(pevent, ptr);
        case 4:
-               return data2host4(pevent, ptr);
+               return tep_data2host4(pevent, ptr);
        case 8:
-               return data2host8(pevent, ptr);
+               return tep_data2host8(pevent, ptr);
        default:
                /* BUG! */
                return 0;
@@ -3352,7 +3354,7 @@ unsigned long long tep_read_number(struct tep_handle *pevent,
  *
  * Returns 0 on success, -1 otherwise.
  */
-int tep_read_number_field(struct format_field *field, const void *data,
+int tep_read_number_field(struct tep_format_field *field, const void *data,
                          unsigned long long *value)
 {
        if (!field)
@@ -3373,8 +3375,8 @@ int tep_read_number_field(struct format_field *field, const void *data,
 static int get_common_info(struct tep_handle *pevent,
                           const char *type, int *offset, int *size)
 {
-       struct event_format *event;
-       struct format_field *field;
+       struct tep_event_format *event;
+       struct tep_format_field *field;
 
        /*
         * All events should have the same common elements.
@@ -3460,11 +3462,11 @@ static int events_id_cmp(const void *a, const void *b);
  *
  * Returns an event that has a given @id.
  */
-struct event_format *tep_find_event(struct tep_handle *pevent, int id)
+struct tep_event_format *tep_find_event(struct tep_handle *pevent, int id)
 {
-       struct event_format **eventptr;
-       struct event_format key;
-       struct event_format *pkey = &key;
+       struct tep_event_format **eventptr;
+       struct tep_event_format key;
+       struct tep_event_format *pkey = &key;
 
        /* Check cache first */
        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)
  * This returns an event with a given @name and under the system
  * @sys. If @sys is NULL the first event with @name is returned.
  */
-struct event_format *
+struct tep_event_format *
 tep_find_event_by_name(struct tep_handle *pevent,
                       const char *sys, const char *name)
 {
-       struct event_format *event;
+       struct tep_event_format *event;
        int i;
 
        if (pevent->last_event &&
@@ -3521,23 +3523,23 @@ tep_find_event_by_name(struct tep_handle *pevent,
 }
 
 static unsigned long long
-eval_num_arg(void *data, int size, struct event_format *event, struct print_arg *arg)
+eval_num_arg(void *data, int size, struct tep_event_format *event, struct tep_print_arg *arg)
 {
        struct tep_handle *pevent = event->pevent;
        unsigned long long val = 0;
        unsigned long long left, right;
-       struct print_arg *typearg = NULL;
-       struct print_arg *larg;
+       struct tep_print_arg *typearg = NULL;
+       struct tep_print_arg *larg;
        unsigned long offset;
        unsigned int field_size;
 
        switch (arg->type) {
-       case PRINT_NULL:
+       case TEP_PRINT_NULL:
                /* ?? */
                return 0;
-       case PRINT_ATOM:
+       case TEP_PRINT_ATOM:
                return strtoull(arg->atom.atom, NULL, 0);
-       case PRINT_FIELD:
+       case TEP_PRINT_FIELD:
                if (!arg->field.field) {
                        arg->field.field = tep_find_any_field(event, arg->field.name);
                        if (!arg->field.field)
@@ -3548,27 +3550,27 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
                val = tep_read_number(pevent, data + arg->field.field->offset,
                                      arg->field.field->size);
                break;
-       case PRINT_FLAGS:
-       case PRINT_SYMBOL:
-       case PRINT_INT_ARRAY:
-       case PRINT_HEX:
-       case PRINT_HEX_STR:
+       case TEP_PRINT_FLAGS:
+       case TEP_PRINT_SYMBOL:
+       case TEP_PRINT_INT_ARRAY:
+       case TEP_PRINT_HEX:
+       case TEP_PRINT_HEX_STR:
                break;
-       case PRINT_TYPE:
+       case TEP_PRINT_TYPE:
                val = eval_num_arg(data, size, event, arg->typecast.item);
                return eval_type(val, arg, 0);
-       case PRINT_STRING:
-       case PRINT_BSTRING:
-       case PRINT_BITMASK:
+       case TEP_PRINT_STRING:
+       case TEP_PRINT_BSTRING:
+       case TEP_PRINT_BITMASK:
                return 0;
-       case PRINT_FUNC: {
+       case TEP_PRINT_FUNC: {
                struct trace_seq s;
                trace_seq_init(&s);
                val = process_defined_func(&s, data, size, event, arg);
                trace_seq_destroy(&s);
                return val;
        }
-       case PRINT_OP:
+       case TEP_PRINT_OP:
                if (strcmp(arg->op.op, "[") == 0) {
                        /*
                         * 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
 
                        /* handle typecasts */
                        larg = arg->op.left;
-                       while (larg->type == PRINT_TYPE) {
+                       while (larg->type == TEP_PRINT_TYPE) {
                                if (!typearg)
                                        typearg = larg;
                                larg = larg->typecast.item;
@@ -3588,7 +3590,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
                        field_size = pevent->long_size;
 
                        switch (larg->type) {
-                       case PRINT_DYNAMIC_ARRAY:
+                       case TEP_PRINT_DYNAMIC_ARRAY:
                                offset = tep_read_number(pevent,
                                                   data + larg->dynarray.field->offset,
                                                   larg->dynarray.field->size);
@@ -3602,7 +3604,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
                                offset &= 0xffff;
                                offset += right;
                                break;
-                       case PRINT_FIELD:
+                       case TEP_PRINT_FIELD:
                                if (!larg->field.field) {
                                        larg->field.field =
                                                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
                        goto out_warning_op;
                }
                break;
-       case PRINT_DYNAMIC_ARRAY_LEN:
+       case TEP_PRINT_DYNAMIC_ARRAY_LEN:
                offset = tep_read_number(pevent,
                                         data + arg->dynarray.field->offset,
                                         arg->dynarray.field->size);
@@ -3729,7 +3731,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
                 */
                val = (unsigned long long)(offset >> 16);
                break;
-       case PRINT_DYNAMIC_ARRAY:
+       case TEP_PRINT_DYNAMIC_ARRAY:
                /* Without [], we pass the address to the dynamic data */
                offset = tep_read_number(pevent,
                                         data + arg->dynarray.field->offset,
@@ -3861,12 +3863,12 @@ static void print_bitmask_to_seq(struct tep_handle *pevent,
 }
 
 static void print_str_arg(struct trace_seq *s, void *data, int size,
-                         struct event_format *event, const char *format,
-                         int len_arg, struct print_arg *arg)
+                         struct tep_event_format *event, const char *format,
+                         int len_arg, struct tep_print_arg *arg)
 {
        struct tep_handle *pevent = event->pevent;
-       struct print_flag_sym *flag;
-       struct format_field *field;
+       struct tep_print_flag_sym *flag;
+       struct tep_format_field *field;
        struct printk_map *printk;
        long long val, fval;
        unsigned long long addr;
@@ -3876,13 +3878,13 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
        int i, len;
 
        switch (arg->type) {
-       case PRINT_NULL:
+       case TEP_PRINT_NULL:
                /* ?? */
                return;
-       case PRINT_ATOM:
+       case TEP_PRINT_ATOM:
                print_str_to_seq(s, format, len_arg, arg->atom.atom);
                return;
-       case PRINT_FIELD:
+       case TEP_PRINT_FIELD:
                field = arg->field.field;
                if (!field) {
                        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,
                 * and the size is the same as long_size, assume that it
                 * is a pointer.
                 */
-               if (!(field->flags & FIELD_IS_ARRAY) &&
+               if (!(field->flags & TEP_FIELD_IS_ARRAY) &&
                    field->size == pevent->long_size) {
 
                        /* Handle heterogeneous recording and processing
@@ -3939,7 +3941,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                print_str_to_seq(s, format, len_arg, str);
                free(str);
                break;
-       case PRINT_FLAGS:
+       case TEP_PRINT_FLAGS:
                val = eval_num_arg(data, size, event, arg->flags.field);
                print = 0;
                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,
                        trace_seq_printf(s, "0x%llx", val);
                }
                break;
-       case PRINT_SYMBOL:
+       case TEP_PRINT_SYMBOL:
                val = eval_num_arg(data, size, event, arg->symbol.field);
                for (flag = arg->symbol.symbols; flag; flag = flag->next) {
                        fval = eval_flag(flag->value);
@@ -3974,9 +3976,9 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                if (!flag)
                        trace_seq_printf(s, "0x%llx", val);
                break;
-       case PRINT_HEX:
-       case PRINT_HEX_STR:
-               if (arg->hex.field->type == PRINT_DYNAMIC_ARRAY) {
+       case TEP_PRINT_HEX:
+       case TEP_PRINT_HEX_STR:
+               if (arg->hex.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
                        unsigned long offset;
                        offset = tep_read_number(pevent,
                                data + arg->hex.field->dynarray.field->offset,
@@ -3995,19 +3997,19 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                }
                len = eval_num_arg(data, size, event, arg->hex.size);
                for (i = 0; i < len; i++) {
-                       if (i && arg->type == PRINT_HEX)
+                       if (i && arg->type == TEP_PRINT_HEX)
                                trace_seq_putc(s, ' ');
                        trace_seq_printf(s, "%02x", hex[i]);
                }
                break;
 
-       case PRINT_INT_ARRAY: {
+       case TEP_PRINT_INT_ARRAY: {
                void *num;
                int el_size;
 
-               if (arg->int_array.field->type == PRINT_DYNAMIC_ARRAY) {
+               if (arg->int_array.field->type == TEP_PRINT_DYNAMIC_ARRAY) {
                        unsigned long offset;
-                       struct format_field *field =
+                       struct tep_format_field *field =
                                arg->int_array.field->dynarray.field;
                        offset = tep_read_number(pevent,
                                                 data + field->offset,
@@ -4049,43 +4051,43 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                }
                break;
        }
-       case PRINT_TYPE:
+       case TEP_PRINT_TYPE:
                break;
-       case PRINT_STRING: {
+       case TEP_PRINT_STRING: {
                int str_offset;
 
                if (arg->string.offset == -1) {
-                       struct format_field *f;
+                       struct tep_format_field *f;
 
                        f = tep_find_any_field(event, arg->string.string);
                        arg->string.offset = f->offset;
                }
-               str_offset = data2host4(pevent, data + arg->string.offset);
+               str_offset = tep_data2host4(pevent, data + arg->string.offset);
                str_offset &= 0xffff;
                print_str_to_seq(s, format, len_arg, ((char *)data) + str_offset);
                break;
        }
-       case PRINT_BSTRING:
+       case TEP_PRINT_BSTRING:
                print_str_to_seq(s, format, len_arg, arg->string.string);
                break;
-       case PRINT_BITMASK: {
+       case TEP_PRINT_BITMASK: {
                int bitmask_offset;
                int bitmask_size;
 
                if (arg->bitmask.offset == -1) {
-                       struct format_field *f;
+                       struct tep_format_field *f;
 
                        f = tep_find_any_field(event, arg->bitmask.bitmask);
                        arg->bitmask.offset = f->offset;
                }
-               bitmask_offset = data2host4(pevent, data + arg->bitmask.offset);
+               bitmask_offset = tep_data2host4(pevent, data + arg->bitmask.offset);
                bitmask_size = bitmask_offset >> 16;
                bitmask_offset &= 0xffff;
                print_bitmask_to_seq(pevent, s, format, len_arg,
                                     data + bitmask_offset, bitmask_size);
                break;
        }
-       case PRINT_OP:
+       case TEP_PRINT_OP:
                /*
                 * The only op for string should be ? :
                 */
@@ -4099,7 +4101,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
                        print_str_arg(s, data, size, event,
                                      format, len_arg, arg->op.right->op.right);
                break;
-       case PRINT_FUNC:
+       case TEP_PRINT_FUNC:
                process_defined_func(s, data, size, event, arg);
                break;
        default:
@@ -4116,13 +4118,13 @@ out_warning_field:
 
 static unsigned long long
 process_defined_func(struct trace_seq *s, void *data, int size,
-                    struct event_format *event, struct print_arg *arg)
+                    struct tep_event_format *event, struct tep_print_arg *arg)
 {
        struct tep_function_handler *func_handle = arg->func.func;
        struct func_params *param;
        unsigned long long *args;
        unsigned long long ret;
-       struct print_arg *farg;
+       struct tep_print_arg *farg;
        struct trace_seq str;
        struct save_str {
                struct save_str *next;
@@ -4199,9 +4201,9 @@ out_free:
        return ret;
 }
 
-static void free_args(struct print_arg *args)
+static void free_args(struct tep_print_arg *args)
 {
-       struct print_arg *next;
+       struct tep_print_arg *next;
 
        while (args) {
                next = args->next;
@@ -4211,11 +4213,11 @@ static void free_args(struct print_arg *args)
        }
 }
 
-static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event)
+static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, struct tep_event_format *event)
 {
        struct tep_handle *pevent = event->pevent;
-       struct format_field *field, *ip_field;
-       struct print_arg *args, *arg, **next;
+       struct tep_format_field *field, *ip_field;
+       struct tep_print_arg *args, *arg, **next;
        unsigned long long ip, val;
        char *ptr;
        void *bptr;
@@ -4254,7 +4256,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
        arg->next = NULL;
        next = &arg->next;
 
-       arg->type = PRINT_ATOM;
+       arg->type = TEP_PRINT_ATOM;
                
        if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
                goto out_free;
@@ -4342,7 +4344,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
                                        goto out_free;
                                }
                                arg->next = NULL;
-                               arg->type = PRINT_ATOM;
+                               arg->type = TEP_PRINT_ATOM;
                                if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
                                        free(arg);
                                        goto out_free;
@@ -4366,7 +4368,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
                                        goto out_free;
                                }
                                arg->next = NULL;
-                               arg->type = PRINT_BSTRING;
+                               arg->type = TEP_PRINT_BSTRING;
                                arg->string.string = strdup(bptr);
                                if (!arg->string.string)
                                        goto out_free;
@@ -4388,11 +4390,11 @@ out_free:
 
 static char *
 get_bprint_format(void *data, int size __maybe_unused,
-                 struct event_format *event)
+                 struct tep_event_format *event)
 {
        struct tep_handle *pevent = event->pevent;
        unsigned long long addr;
-       struct format_field *field;
+       struct tep_format_field *field;
        struct printk_map *printk;
        char *format;
 
@@ -4423,17 +4425,17 @@ get_bprint_format(void *data, int size __maybe_unused,
 }
 
 static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
-                         struct event_format *event, struct print_arg *arg)
+                         struct tep_event_format *event, struct tep_print_arg *arg)
 {
        unsigned char *buf;
        const char *fmt = "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x";
 
-       if (arg->type == PRINT_FUNC) {
+       if (arg->type == TEP_PRINT_FUNC) {
                process_defined_func(s, data, size, event, arg);
                return;
        }
 
-       if (arg->type != PRINT_FIELD) {
+       if (arg->type != TEP_PRINT_FIELD) {
                trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d",
                                 arg->type);
                return;
@@ -4576,17 +4578,17 @@ static void print_ip6_addr(struct trace_seq *s, char i, unsigned char *buf)
  * %pISpc print an IP address based on sockaddr; p adds port.
  */
 static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i,
-                         void *data, int size, struct event_format *event,
-                         struct print_arg *arg)
+                         void *data, int size, struct tep_event_format *event,
+                         struct tep_print_arg *arg)
 {
        unsigned char *buf;
 
-       if (arg->type == PRINT_FUNC) {
+       if (arg->type == TEP_PRINT_FUNC) {
                process_defined_func(s, data, size, event, arg);
                return 0;
        }
 
-       if (arg->type != PRINT_FIELD) {
+       if (arg->type != TEP_PRINT_FIELD) {
                trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
                return 0;
        }
@@ -4613,8 +4615,8 @@ static int print_ipv4_arg(struct trace_seq *s, const char *ptr, char i,
 }
 
 static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
-                         void *data, int size, struct event_format *event,
-                         struct print_arg *arg)
+                         void *data, int size, struct tep_event_format *event,
+                         struct tep_print_arg *arg)
 {
        char have_c = 0;
        unsigned char *buf;
@@ -4627,12 +4629,12 @@ static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
                rc++;
        }
 
-       if (arg->type == PRINT_FUNC) {
+       if (arg->type == TEP_PRINT_FUNC) {
                process_defined_func(s, data, size, event, arg);
                return rc;
        }
 
-       if (arg->type != PRINT_FIELD) {
+       if (arg->type != TEP_PRINT_FIELD) {
                trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
                return rc;
        }
@@ -4663,8 +4665,8 @@ static int print_ipv6_arg(struct trace_seq *s, const char *ptr, char i,
 }
 
 static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
-                         void *data, int size, struct event_format *event,
-                         struct print_arg *arg)
+                         void *data, int size, struct tep_event_format *event,
+                         struct tep_print_arg *arg)
 {
        char have_c = 0, have_p = 0;
        unsigned char *buf;
@@ -4685,12 +4687,12 @@ static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
                }
        }
 
-       if (arg->type == PRINT_FUNC) {
+       if (arg->type == TEP_PRINT_FUNC) {
                process_defined_func(s, data, size, event, arg);
                return rc;
        }
 
-       if (arg->type != PRINT_FIELD) {
+       if (arg->type != TEP_PRINT_FIELD) {
                trace_seq_printf(s, "ARG TYPE NOT FIELD BUT %d", arg->type);
                return rc;
        }
@@ -4745,8 +4747,8 @@ static int print_ipsa_arg(struct trace_seq *s, const char *ptr, char i,
 }
 
 static int print_ip_arg(struct trace_seq *s, const char *ptr,
-                       void *data, int size, struct event_format *event,
-                       struct print_arg *arg)
+                       void *data, int size, struct tep_event_format *event,
+                       struct tep_print_arg *arg)
 {
        char i = *ptr;  /* 'i' or 'I' */
        char ver;
@@ -4787,22 +4789,22 @@ static int is_printable_array(char *p, unsigned int len)
 }
 
 void tep_print_field(struct trace_seq *s, void *data,
-                    struct format_field *field)
+                    struct tep_format_field *field)
 {
        unsigned long long val;
        unsigned int offset, len, i;
        struct tep_handle *pevent = field->event->pevent;
 
-       if (field->flags & FIELD_IS_ARRAY) {
+       if (field->flags & TEP_FIELD_IS_ARRAY) {
                offset = field->offset;
                len = field->size;
-               if (field->flags & FIELD_IS_DYNAMIC) {
+               if (field->flags & TEP_FIELD_IS_DYNAMIC) {
                        val = tep_read_number(pevent, data + offset, len);
                        offset = val;
                        len = offset >> 16;
                        offset &= 0xffff;
                }
-               if (field->flags & FIELD_IS_STRING &&
+               if (field->flags & TEP_FIELD_IS_STRING &&
                    is_printable_array(data + offset, len)) {
                        trace_seq_printf(s, "%s", (char *)data + offset);
                } else {
@@ -4814,21 +4816,21 @@ void tep_print_field(struct trace_seq *s, void *data,
                                                 *((unsigned char *)data + offset + i));
                        }
                        trace_seq_putc(s, ']');
-                       field->flags &= ~FIELD_IS_STRING;
+                       field->flags &= ~TEP_FIELD_IS_STRING;
                }
        } else {
                val = tep_read_number(pevent, data + field->offset,
                                      field->size);
-               if (field->flags & FIELD_IS_POINTER) {
+               if (field->flags & TEP_FIELD_IS_POINTER) {
                        trace_seq_printf(s, "0x%llx", val);
-               } else if (field->flags & FIELD_IS_SIGNED) {
+               } else if (field->flags & TEP_FIELD_IS_SIGNED) {
                        switch (field->size) {
                        case 4:
                                /*
                                 * If field is long then print it in hex.
                                 * A long usually stores pointers.
                                 */
-                               if (field->flags & FIELD_IS_LONG)
+                               if (field->flags & TEP_FIELD_IS_LONG)
                                        trace_seq_printf(s, "0x%x", (int)val);
                                else
                                        trace_seq_printf(s, "%d", (int)val);
@@ -4843,7 +4845,7 @@ void tep_print_field(struct trace_seq *s, void *data,
                                trace_seq_printf(s, "%lld", val);
                        }
                } else {
-                       if (field->flags & FIELD_IS_LONG)
+                       if (field->flags & TEP_FIELD_IS_LONG)
                                trace_seq_printf(s, "0x%llx", val);
                        else
                                trace_seq_printf(s, "%llu", val);
@@ -4852,9 +4854,9 @@ void tep_print_field(struct trace_seq *s, void *data,
 }
 
 void tep_print_fields(struct trace_seq *s, void *data,
-                     int size __maybe_unused, struct event_format *event)
+                     int size __maybe_unused, struct tep_event_format *event)
 {
-       struct format_field *field;
+       struct tep_format_field *field;
 
        field = event->format.fields;
        while (field) {
@@ -4864,12 +4866,12 @@ void tep_print_fields(struct trace_seq *s, void *data,
        }
 }
 
-static void pretty_print(struct trace_seq *s, void *data, int size, struct event_format *event)
+static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_event_format *event)
 {
        struct tep_handle *pevent = event->pevent;
-       struct print_fmt *print_fmt = &event->print_fmt;
-       struct print_arg *arg = print_fmt->args;
-       struct print_arg *args = NULL;
+       struct tep_print_fmt *print_fmt = &event->print_fmt;
+       struct tep_print_arg *arg = print_fmt->args;
+       struct tep_print_arg *args = NULL;
        const char *ptr = print_fmt->format;
        unsigned long long val;
        struct func_map *func;
@@ -4883,13 +4885,13 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
        int len;
        int ls;
 
-       if (event->flags & EVENT_FL_FAILED) {
+       if (event->flags & TEP_EVENT_FL_FAILED) {
                trace_seq_printf(s, "[FAILED TO PARSE]");
                tep_print_fields(s, data, size, event);
                return;
        }
 
-       if (event->flags & EVENT_FL_ISBPRINT) {
+       if (event->flags & TEP_EVENT_FL_ISBPRINT) {
                bprint_fmt = get_bprint_format(data, size, event);
                args = make_bprint_args(bprint_fmt, data, size, event);
                arg = args;
@@ -4944,7 +4946,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
                                /* The argument is the length. */
                                if (!arg) {
                                        do_warning_event(event, "no argument match");
-                                       event->flags |= EVENT_FL_FAILED;
+                                       event->flags |= TEP_EVENT_FL_FAILED;
                                        goto out_failed;
                                }
                                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
                                if (isalnum(ptr[1]))
                                        ptr++;
 
-                               if (arg->type == PRINT_BSTRING) {
+                               if (arg->type == TEP_PRINT_BSTRING) {
                                        trace_seq_puts(s, arg->string.string);
                                        break;
                                }
@@ -4997,7 +4999,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
                        case 'u':
                                if (!arg) {
                                        do_warning_event(event, "no argument match");
-                                       event->flags |= EVENT_FL_FAILED;
+                                       event->flags |= TEP_EVENT_FL_FAILED;
                                        goto out_failed;
                                }
 
@@ -5007,7 +5009,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
                                /* should never happen */
                                if (len > 31) {
                                        do_warning_event(event, "bad format!");
-                                       event->flags |= EVENT_FL_FAILED;
+                                       event->flags |= TEP_EVENT_FL_FAILED;
                                        len = 31;
                                }
 
@@ -5073,13 +5075,13 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
                                        break;
                                default:
                                        do_warning_event(event, "bad count (%d)", ls);
-                                       event->flags |= EVENT_FL_FAILED;
+                                       event->flags |= TEP_EVENT_FL_FAILED;
                                }
                                break;
                        case 's':
                                if (!arg) {
                                        do_warning_event(event, "no matching argument");
-                                       event->flags |= EVENT_FL_FAILED;
+                                       event->flags |= TEP_EVENT_FL_FAILED;
                                        goto out_failed;
                                }
 
@@ -5089,7 +5091,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
                                /* should never happen */
                                if (len > 31) {
                                        do_warning_event(event, "bad format!");
-                                       event->flags |= EVENT_FL_FAILED;
+                                       event->flags |= TEP_EVENT_FL_FAILED;
                                        len = 31;
                                }
 
@@ -5114,7 +5116,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
                        trace_seq_putc(s, *ptr);
        }
 
-       if (event->flags & EVENT_FL_FAILED) {
+       if (event->flags & TEP_EVENT_FL_FAILED) {
 out_failed:
                trace_seq_printf(s, "[FAILED TO PARSE]");
        }
@@ -5227,7 +5229,7 @@ int tep_data_type(struct tep_handle *pevent, struct tep_record *rec)
  *
  * This returns the event form a given @type;
  */
-struct event_format *tep_data_event_from_type(struct tep_handle *pevent, int type)
+struct tep_event_format *tep_data_event_from_type(struct tep_handle *pevent, int type)
 {
        return tep_find_event(pevent, type);
 }
@@ -5385,16 +5387,16 @@ int tep_cmdline_pid(struct tep_handle *pevent, struct cmdline *cmdline)
  * This parses the raw @data using the given @event information and
  * writes the print format into the trace_seq.
  */
-void tep_event_info(struct trace_seq *s, struct event_format *event,
+void tep_event_info(struct trace_seq *s, struct tep_event_format *event,
                    struct tep_record *record)
 {
        int print_pretty = 1;
 
-       if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
+       if (event->pevent->print_raw || (event->flags & TEP_EVENT_FL_PRINTRAW))
                tep_print_fields(s, record->data, record->size, event);
        else {
 
-               if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
+               if (event->handler && !(event->flags & TEP_EVENT_FL_NOHANDLE))
                        print_pretty = event->handler(s, record, event,
                                                      event->context);
 
@@ -5426,7 +5428,7 @@ static bool is_timestamp_in_us(char *trace_clock, bool use_trace_clock)
  * Returns the associated event for a given record, or NULL if non is
  * is found.
  */
-struct event_format *
+struct tep_event_format *
 tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record)
 {
        int type;
@@ -5451,7 +5453,7 @@ tep_find_event_by_record(struct tep_handle *pevent, struct tep_record *record)
  * Writes the tasks comm, pid and CPU to @s.
  */
 void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
-                         struct event_format *event,
+                         struct tep_event_format *event,
                          struct tep_record *record)
 {
        void *data = record->data;
@@ -5479,7 +5481,7 @@ void tep_print_event_task(struct tep_handle *pevent, struct trace_seq *s,
  * Writes the timestamp of the record into @s.
  */
 void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
-                         struct event_format *event,
+                         struct tep_event_format *event,
                          struct tep_record *record,
                          bool use_trace_clock)
 {
@@ -5529,7 +5531,7 @@ void tep_print_event_time(struct tep_handle *pevent, struct trace_seq *s,
  * Writes the parsing of the record's data to @s.
  */
 void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
-                         struct event_format *event,
+                         struct tep_event_format *event,
                          struct tep_record *record)
 {
        static const char *spaces = "                    "; /* 20 spaces */
@@ -5548,7 +5550,7 @@ void tep_print_event_data(struct tep_handle *pevent, struct trace_seq *s,
 void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
                     struct tep_record *record, bool use_trace_clock)
 {
-       struct event_format *event;
+       struct tep_event_format *event;
 
        event = tep_find_event_by_record(pevent, record);
        if (!event) {
@@ -5570,8 +5572,8 @@ void tep_print_event(struct tep_handle *pevent, struct trace_seq *s,
 
 static int events_id_cmp(const void *a, const void *b)
 {
-       struct event_format * const * ea = a;
-       struct event_format * const * eb = b;
+       struct tep_event_format * const * ea = a;
+       struct tep_event_format * const * eb = b;
 
        if ((*ea)->id < (*eb)->id)
                return -1;
@@ -5584,8 +5586,8 @@ static int events_id_cmp(const void *a, const void *b)
 
 static int events_name_cmp(const void *a, const void *b)
 {
-       struct event_format * const * ea = a;
-       struct event_format * const * eb = b;
+       struct tep_event_format * const * ea = a;
+       struct tep_event_format * const * eb = b;
        int res;
 
        res = strcmp((*ea)->name, (*eb)->name);
@@ -5601,8 +5603,8 @@ static int events_name_cmp(const void *a, const void *b)
 
 static int events_system_cmp(const void *a, const void *b)
 {
-       struct event_format * const * ea = a;
-       struct event_format * const * eb = b;
+       struct tep_event_format * const * ea = a;
+       struct tep_event_format * const * eb = b;
        int res;
 
        res = strcmp((*ea)->system, (*eb)->system);
@@ -5616,9 +5618,9 @@ static int events_system_cmp(const void *a, const void *b)
        return events_id_cmp(a, b);
 }
 
-struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort_type sort_type)
+struct tep_event_format **tep_list_events(struct tep_handle *pevent, enum tep_event_sort_type sort_type)
 {
-       struct event_format **events;
+       struct tep_event_format **events;
        int (*sort)(const void *a, const void *b);
 
        events = pevent->sort_events;
@@ -5637,20 +5639,20 @@ struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort
                pevent->sort_events = events;
 
                /* the internal events are sorted by id */
-               if (sort_type == EVENT_SORT_ID) {
+               if (sort_type == TEP_EVENT_SORT_ID) {
                        pevent->last_type = sort_type;
                        return events;
                }
        }
 
        switch (sort_type) {
-       case EVENT_SORT_ID:
+       case TEP_EVENT_SORT_ID:
                sort = events_id_cmp;
                break;
-       case EVENT_SORT_NAME:
+       case TEP_EVENT_SORT_NAME:
                sort = events_name_cmp;
                break;
-       case EVENT_SORT_SYSTEM:
+       case TEP_EVENT_SORT_SYSTEM:
                sort = events_system_cmp;
                break;
        default:
@@ -5663,12 +5665,12 @@ struct event_format **tep_list_events(struct tep_handle *pevent, enum event_sort
        return events;
 }
 
-static struct format_field **
+static struct tep_format_field **
 get_event_fields(const char *type, const char *name,
-                int count, struct format_field *list)
+                int count, struct tep_format_field *list)
 {
-       struct format_field **fields;
-       struct format_field *field;
+       struct tep_format_field **fields;
+       struct tep_format_field *field;
        int i = 0;
 
        fields = malloc(sizeof(*fields) * (count + 1));
@@ -5701,7 +5703,7 @@ get_event_fields(const char *type, const char *name,
  * Returns an allocated array of fields. The last item in the array is NULL.
  * The array must be freed with free().
  */
-struct format_field **tep_event_common_fields(struct event_format *event)
+struct tep_format_field **tep_event_common_fields(struct tep_event_format *event)
 {
        return get_event_fields("common", event->name,
                                event->format.nr_common,
@@ -5715,14 +5717,14 @@ struct format_field **tep_event_common_fields(struct event_format *event)
  * Returns an allocated array of fields. The last item in the array is NULL.
  * The array must be freed with free().
  */
-struct format_field **tep_event_fields(struct event_format *event)
+struct tep_format_field **tep_event_fields(struct tep_event_format *event)
 {
        return get_event_fields("event", event->name,
                                event->format.nr_fields,
                                event->format.fields);
 }
 
-static void print_fields(struct trace_seq *s, struct print_flag_sym *field)
+static void print_fields(struct trace_seq *s, struct tep_print_flag_sym *field)
 {
        trace_seq_printf(s, "{ %s, %s }", field->value, field->str);
        if (field->next) {
@@ -5732,22 +5734,22 @@ static void print_fields(struct trace_seq *s, struct print_flag_sym *field)
 }
 
 /* for debugging */
-static void print_args(struct print_arg *args)
+static void print_args(struct tep_print_arg *args)
 {
        int print_paren = 1;
        struct trace_seq s;
 
        switch (args->type) {
-       case PRINT_NULL:
+       case TEP_PRINT_NULL:
                printf("null");
                break;
-       case PRINT_ATOM:
+       case TEP_PRINT_ATOM:
                printf("%s", args->atom.atom);
                break;
-       case PRINT_FIELD:
+       case TEP_PRINT_FIELD:
                printf("REC->%s", args->field.name);
                break;
-       case PRINT_FLAGS:
+       case TEP_PRINT_FLAGS:
                printf("__print_flags(");
                print_args(args->flags.field);
                printf(", %s, ", args->flags.delim);
@@ -5757,7 +5759,7 @@ static void print_args(struct print_arg *args)
                trace_seq_destroy(&s);
                printf(")");
                break;
-       case PRINT_SYMBOL:
+       case TEP_PRINT_SYMBOL:
                printf("__print_symbolic(");
                print_args(args->symbol.field);
                printf(", ");
@@ -5767,21 +5769,21 @@ static void print_args(struct print_arg *args)
                trace_seq_destroy(&s);
                printf(")");
                break;
-       case PRINT_HEX:
+       case TEP_PRINT_HEX:
                printf("__print_hex(");
                print_args(args->hex.field);
                printf(", ");
                print_args(args->hex.size);
                printf(")");
                break;
-       case PRINT_HEX_STR:
+       case TEP_PRINT_HEX_STR:
                printf("__print_hex_str(");
                print_args(args->hex.field);
                printf(", ");
                print_args(args->hex.size);
                printf(")");
                break;
-       case PRINT_INT_ARRAY:
+       case TEP_PRINT_INT_ARRAY:
                printf("__print_array(");
                print_args(args->int_array.field);
                printf(", ");
@@ -5790,18 +5792,18 @@ static void print_args(struct print_arg *args)
                print_args(args->int_array.el_size);
                printf(")");
                break;
-       case PRINT_STRING:
-       case PRINT_BSTRING:
+       case TEP_PRINT_STRING:
+       case TEP_PRINT_BSTRING:
                printf("__get_str(%s)", args->string.string);
                break;
-       case PRINT_BITMASK:
+       case TEP_PRINT_BITMASK:
                printf("__get_bitmask(%s)", args->bitmask.bitmask);
                break;
-       case PRINT_TYPE:
+       case TEP_PRINT_TYPE:
                printf("(%s)", args->typecast.type);
                print_args(args->typecast.item);
                break;
-       case PRINT_OP:
+       case TEP_PRINT_OP:
                if (strcmp(args->op.op, ":") == 0)
                        print_paren = 0;
                if (print_paren)
@@ -5833,13 +5835,13 @@ static void parse_header_field(const char *field,
        save_input_buf_ptr = input_buf_ptr;
        save_input_buf_siz = input_buf_siz;
 
-       if (read_expected(EVENT_ITEM, "field") < 0)
+       if (read_expected(TEP_EVENT_ITEM, "field") < 0)
                return;
-       if (read_expected(EVENT_OP, ":") < 0)
+       if (read_expected(TEP_EVENT_OP, ":") < 0)
                return;
 
        /* type */
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto fail;
        free_token(token);
 
@@ -5847,42 +5849,42 @@ static void parse_header_field(const char *field,
         * If this is not a mandatory field, then test it first.
         */
        if (mandatory) {
-               if (read_expected(EVENT_ITEM, field) < 0)
+               if (read_expected(TEP_EVENT_ITEM, field) < 0)
                        return;
        } else {
-               if (read_expect_type(EVENT_ITEM, &token) < 0)
+               if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                        goto fail;
                if (strcmp(token, field) != 0)
                        goto discard;
                free_token(token);
        }
 
-       if (read_expected(EVENT_OP, ";") < 0)
+       if (read_expected(TEP_EVENT_OP, ";") < 0)
                return;
-       if (read_expected(EVENT_ITEM, "offset") < 0)
+       if (read_expected(TEP_EVENT_ITEM, "offset") < 0)
                return;
-       if (read_expected(EVENT_OP, ":") < 0)
+       if (read_expected(TEP_EVENT_OP, ":") < 0)
                return;
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto fail;
        *offset = atoi(token);
        free_token(token);
-       if (read_expected(EVENT_OP, ";") < 0)
+       if (read_expected(TEP_EVENT_OP, ";") < 0)
                return;
-       if (read_expected(EVENT_ITEM, "size") < 0)
+       if (read_expected(TEP_EVENT_ITEM, "size") < 0)
                return;
-       if (read_expected(EVENT_OP, ":") < 0)
+       if (read_expected(TEP_EVENT_OP, ":") < 0)
                return;
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
+       if (read_expect_type(TEP_EVENT_ITEM, &token) < 0)
                goto fail;
        *size = atoi(token);
        free_token(token);
-       if (read_expected(EVENT_OP, ";") < 0)
+       if (read_expected(TEP_EVENT_OP, ";") < 0)
                return;
        type = read_token(&token);
-       if (type != EVENT_NEWLINE) {
+       if (type != TEP_EVENT_NEWLINE) {
                /* newer versions of the kernel have a "signed" type */
-               if (type != EVENT_ITEM)
+               if (type != TEP_EVENT_ITEM)
                        goto fail;
 
                if (strcmp(token, "signed") != 0)
@@ -58