sst-linux/kernel/trace
Levi Yun cc344fdd0e trace/trace_event_perf: remove duplicate samples on the first tracepoint event
[ Upstream commit afe5960dc208fe069ddaaeb0994d857b24ac19d1 ]

When a tracepoint event is created with attr.freq = 1,
'hwc->period_left' is not initialized correctly. As a result,
in the perf_swevent_overflow() function, when the first time the event occurs,
it calculates the event overflow and the perf_swevent_set_period() returns 3,
this leads to the event are recorded for three duplicate times.

Step to reproduce:
    1. Enable the tracepoint event & starting tracing
         $ echo 1 > /sys/kernel/tracing/events/module/module_free
         $ echo 1 > /sys/kernel/tracing/tracing_on

    2. Record with perf
         $ perf record -a --strict-freq -F 1 -e "module:module_free"

    3. Trigger module_free event.
         $ modprobe -i sunrpc
         $ modprobe -r sunrpc

Result:
     - Trace pipe result:
         $ cat trace_pipe
         modprobe-174509  [003] .....  6504.868896: module_free: sunrpc

     - perf sample:
         modprobe  174509 [003]  6504.868980: module:module_free: sunrpc
         modprobe  174509 [003]  6504.868980: module:module_free: sunrpc
         modprobe  174509 [003]  6504.868980: module:module_free: sunrpc

By setting period_left via perf_swevent_set_period() as other sw_event did,
This problem could be solved.

After patch:
     - Trace pipe result:
         $ cat trace_pipe
         modprobe 1153096 [068] 613468.867774: module:module_free: xfs

     - perf sample
         modprobe 1153096 [068] 613468.867794: module:module_free: xfs

Link: https://lore.kernel.org/20240913021347.595330-1-yeoreum.yun@arm.com
Fixes: bd2b5b1284 ("perf_counter: More aggressive frequency adjustment")
Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-12-14 19:53:35 +01:00
..
rv rv: Update rv_en(dis)able_monitor doc to match kernel-doc 2024-06-12 11:03:52 +02:00
blktrace.c
bpf_trace.c bpf,perf: Fix perf_event_detach_bpf_prog error handling 2024-11-01 01:56:05 +01:00
bpf_trace.h
error_report-traces.c
fgraph.c
fprobe.c
ftrace_internal.h
ftrace.c ftrace: Fix possible use-after-free issue in ftrace_location() 2024-06-12 11:02:54 +02:00
Kconfig tracing: Build event generation tests only as modules 2024-06-27 13:46:18 +02:00
kprobe_event_gen_test.c
Makefile
pid_list.c trace/pid_list: Change gfp flags in pid_list_fill_irq() 2024-08-03 08:49:34 +02:00
pid_list.h
power-traces.c
preemptirq_delay_test.c tracing: Add MODULE_DESCRIPTION() to preemptirq_delay_test 2024-06-27 13:46:23 +02:00
rethook.c
ring_buffer_benchmark.c
ring_buffer.c ring-buffer: Fix a race between readers and resize checks 2024-06-12 11:02:56 +02:00
rpm-traces.c
synth_event_gen_test.c tracing / synthetic: Disable events after testing in synth_event_gen_test_init() 2024-01-01 12:39:07 +00:00
trace_benchmark.c
trace_benchmark.h
trace_boot.c
trace_branch.c
trace_clock.c
trace_dynevent.c
trace_dynevent.h
trace_entries.h
trace_eprobe.c
trace_event_perf.c trace/trace_event_perf: remove duplicate samples on the first tracepoint event 2024-12-14 19:53:35 +01:00
trace_events_filter_test.h
trace_events_filter.c
trace_events_hist.c tracing: Fix uaf issue when open the hist or hist_debug file 2024-01-20 11:50:07 +01:00
trace_events_inject.c
trace_events_synth.c
trace_events_trigger.c tracing/trigger: Fix to return error if failed to alloc snapshot 2024-02-23 09:12:32 +01:00
trace_events_user.c
trace_events.c tracing: hide unused ftrace_event_id_fops 2024-04-17 11:18:26 +02:00
trace_export.c
trace_functions_graph.c
trace_functions.c
trace_hwlat.c tracing/hwlat: Fix a race during cpuhp processing 2024-10-17 15:22:02 +02:00
trace_irqsoff.c
trace_kdb.c
trace_kprobe_selftest.c
trace_kprobe_selftest.h
trace_kprobe.c tracing/kprobes: Fix symbol counting logic by looking at modules as well 2024-01-05 15:18:40 +01:00
trace_mmiotrace.c
trace_nop.c
trace_osnoise.c tracing/timerlat: Fix a race during cpuhp processing 2024-10-17 15:22:02 +02:00
trace_output.c tracing: Remove precision vsnprintf() check from print event 2024-10-17 15:22:10 +02:00
trace_output.h
trace_preemptirq.c
trace_printk.c
trace_probe_kernel.h
trace_probe_tmpl.h
trace_probe.c tracing: Consider the NULL character when validating the event length 2024-11-01 01:56:03 +01:00
trace_probe.h
trace_recursion_record.c
trace_sched_switch.c
trace_sched_wakeup.c
trace_selftest_dynamic.c
trace_selftest.c
trace_seq.c
trace_stack.c
trace_stat.c
trace_stat.h
trace_synth.h
trace_syscalls.c
trace_uprobe.c uprobe: avoid out-of-bounds memory access of fetching args 2024-11-17 15:07:21 +01:00
trace.c tracing: Have saved_cmdlines arrays all in one allocation 2024-10-17 15:22:10 +02:00
trace.h tracing: Fix uaf issue when open the hist or hist_debug file 2024-01-20 11:50:07 +01:00
tracing_map.c tracing: Fix overflow in get_free_elt() 2024-08-14 13:52:59 +02:00
tracing_map.h