From mboxrd@z Thu Jan 1 00:00:00 1970 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 935CF223336; Thu, 12 Dec 2024 16:03:33 +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=1734019413; cv=none; b=lL32QTyWSSuM4R8Ztiv1p7Da9D/IbuuR4dfDa6vQd3+Y45dszy0eI3Iqfy3wJI92rOTwjt1LsIg+hcF0dWtotvpPzctiYlOTRzrOm6/0ZSJf6P20/a+nooki+P1yA3JhwZ/tirf+zJR7JRPhzsjD6KJts+EAKmSF8QdzeaSE9cw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734019413; c=relaxed/simple; bh=m8/rMvM8nYbHB8NIyRNFbIhVrDXtnWRdbeMd2qmuOwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VISLZGnqD1p18UAoCP4rYHUgTQpfj8D1qPpl537IteVddsxksMpbxoHjcnRxTarWQdGjY4HcV6+4l0jLvUPeHNGsZnD2KB0leXZ3MA/63bZx8DS9prrk05U/woqXLjSeHxfNBUZTiL31sb+Xd6mJ8RPpUkzhBw5izJM77XxtqUA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cXYSxlrC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cXYSxlrC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC879C4CECE; Thu, 12 Dec 2024 16:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734019413; bh=m8/rMvM8nYbHB8NIyRNFbIhVrDXtnWRdbeMd2qmuOwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cXYSxlrCZJBsoEq60ZgB8fn4LCRmgNLUbBy9n6TTR3oE8LdFcbzcj0zJCS6p2Kuhm MKqHkf3Pl9c50DF7jKvZ4Dz0h1ipboE6pqmIAxQtUsREm/dpxPD/V+Fy3EK+z/H7Un YkiHw7NqCSrfRAAR9ZXZ8LJ3wbV/7CWxnvkk7YdQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Levi Yun , Namhyung Kim , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 6.1 202/772] trace/trace_event_perf: remove duplicate samples on the first tracepoint event Date: Thu, 12 Dec 2024 15:52:27 +0100 Message-ID: <20241212144358.287951943@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144349.797589255@linuxfoundation.org> References: <20241212144349.797589255@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Levi Yun [ 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: bd2b5b12849a ("perf_counter: More aggressive frequency adjustment") Signed-off-by: Levi Yun Acked-by: Namhyung Kim Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin --- 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_perf.c index 61e3a2620fa3c..f2000cf2b3bba 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -356,10 +356,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 = p_event->tp_event; + struct hw_perf_event *hwc = &p_event->hw; if (!(flags & PERF_EF_START)) p_event->hw.state = PERF_HES_STOPPED; + if (is_sampling_event(p_event)) { + hwc->last_period = 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 -- 2.43.0