From patchwork Fri Sep 13 02:13:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yeo Reum Yun X-Patchwork-Id: 13802940 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 21A1033C8; Fri, 13 Sep 2024 02:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726193634; cv=none; b=ZHhCPjCbE5+hoK/DaRvGo5SVcqq+RuZzoGCu/03/OfuY7yKx/VwX7O3j1PWaLv4Z0Wj6rK7FC0YDGZsVxqcDpPG/4ehELB5DnZtfCXdqiooBXmxce4PiryCU6d3iVca/XukQrEisV2TmFXeTYnKueBfteDGgJDiAZHK25GYLhmM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726193634; c=relaxed/simple; bh=jiLfsDjFmYbTok4lywR7Fe7cmBiUjCh3GrWHROoFkM4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=rOR4BRslnFJqC7EPXG7fYJcdMdBGZ9t8Y8hBhvACDgLF3Kur5hlYeVh4Ta4KnlsObwlS0hmxoJjMvJ8TzhuUiCn0okYlUoIgEOTOYhqxuvloAJNlSNVT0szQBi0ijUIwIE6UKeQURgigIdthmo9bdi7IvspxPIUhsBI7xqNTI4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BCDFFDA7; Thu, 12 Sep 2024 19:14:21 -0700 (PDT) Received: from e129823.cambridge.arm.com (e129823.arm.com [10.1.197.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B781E3F66E; Thu, 12 Sep 2024 19:13:50 -0700 (PDT) From: Levi Yun To: rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, a.p.zijlstra@chello.nl, mingo@elte.hu, mark.rutland@arm.com, james.clark@linaro.org Cc: nd@arm.com, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Levi Yun Subject: [PATCH v2] trace/trace_event_perf: remove duplicate samples on the first tracepoint event Date: Fri, 13 Sep 2024 03:13:47 +0100 Message-Id: <20240913021347.595330-1-yeoreum.yun@arm.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Fixes: bd2b5b12849a ("perf_counter: More aggressive frequency adjustment") Signed-off-by: Levi Yun Acked-by: Namhyung Kim --- Changes in v2: - Fix build error. --- kernel/trace/trace_event_perf.c | 6 ++++++ 1 file changed, 6 insertions(+) -- LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7} diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.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 = 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