From nobody Wed Nov 27 12:29:03 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97F031D0481 for ; Thu, 10 Oct 2024 14:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728570343; cv=none; b=g8HP7snYji8DdL202ZcR5wnEUaM+AyBPkVAlNJ21lBAKkR1IdDsGziro26BSZuV3an/2F60tOeCD8pT+PRXRATwTOLHI/F2UfTzETA7izGhnXZcECcmi8CAsccj8igUexgrA5BwVgoZsr3C43HSMDRt2XgCdtRJzJjlvvjW/bhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728570343; c=relaxed/simple; bh=1yU0bvNVZwBqjEmH0fcUF0qusLzca9JT13UEJ8HWyGE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=EoC24FwmV1zS8ITxUxZ2OdiPPUFVoHO2xMpwC18i/7fWu95aAT7zZG6E6duWGNE4t4Tte1gcGpthv9ouXOF05aOkn41jLbCszxcuraKl/M/FQyRF9K44cIZvsWCJiJvULrY1ZuGoDfOSL1gKPhe0ntuCsj8ZefEoYMqqBhclgLE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21B62C4CED5; Thu, 10 Oct 2024 14:25:43 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1syu6x-00000001HKo-0SlR; Thu, 10 Oct 2024 10:25:51 -0400 Message-ID: <20241010142550.975455451@goodmis.org> User-Agent: quilt/0.68 Date: Thu, 10 Oct 2024 10:25:46 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Levi Yun , Namhyung Kim Subject: [for-next][PATCH 09/10] trace/trace_event_perf: remove duplicate samples on the first tracepoint event References: <20241010142537.255433162@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Levi Yun When a tracepoint event is created with attr.freq =3D 1, 'hwc->period_left' is not initialized correctly. As a result, in the perf_swevent_overflow() function, when the first time the event occu= rs, 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: bd2b5b12849a ("perf_counter: More aggressive frequency adjustment") Signed-off-by: Levi Yun Acked-by: Namhyung Kim Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_event_perf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_per= f.c index 05e791241812..3ff9caa4a71b 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -352,10 +352,16 @@ void perf_uprobe_destroy(struct perf_event *p_event) int perf_trace_add(struct perf_event *p_event, int flags) { struct trace_event_call *tp_event =3D p_event->tp_event; + struct hw_perf_event *hwc =3D &p_event->hw; =20 if (!(flags & PERF_EF_START)) p_event->hw.state =3D PERF_HES_STOPPED; =20 + if (is_sampling_event(p_event)) { + hwc->last_period =3D hwc->sample_period; + perf_swevent_set_period(p_event); + } + /* * If TRACE_REG_PERF_ADD returns false; no custom action was performed * and we need to take the default action of enqueueing our event on --=20 2.45.2