Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933268AbeAOMbB (ORCPT + 1 other); Mon, 15 Jan 2018 07:31:01 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:4200 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932657AbeAOMa6 (ORCPT ); Mon, 15 Jan 2018 07:30:58 -0500 From: Cheng Jian To: , , , , , , , , CC: , Subject: [PATCH v2] perf/trace : Fix repetitious traces of perf on tracepoint Date: Mon, 15 Jan 2018 20:36:44 +0800 Message-ID: <1516019804-6908-1-git-send-email-cj.chengjian@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: When i use perf to trace the sched_wakeup_new tracepoint, there is a bug that output the same event repetitiously. It can be reproduced by : perf record -e sched:sched_wakeup_new ./bug_fork bug_fork is an demo that can generating wakeup_new event, parent process does nothing but fork a child process, and then they both quit. There are 4 processors in this machine. before this patch, perf script(perf-1058, parent-1059, child-1060) : bug_fork 1059 [001] 62.913666: sched:sched_wakeup_new: comm=bug_fork pid=1060 prio=120 target_cpu=002 bug_fork 1059 [001] 62.913680: sched:sched_wakeup_new: comm=bug_fork pid=1060 prio=120 target_cpu=002 bug_fork 1059 [001] 62.913689: sched:sched_wakeup_new: comm=bug_fork pid=1060 prio=120 target_cpu=002 bug_fork 1059 [001] 62.913698: sched:sched_wakeup_new: comm=bug_fork pid=1060 prio=120 target_cpu=002 bug_fork 1059 [001] 62.913705: sched:sched_wakeup_new: comm=bug_fork pid=1060 prio=120 target_cpu=002 but ftrace report this event only once : bug_fork-1059 [002] d... 62.913666: sched_wakeup_new: comm=bug_fork pid=1060 prio=120 target_cpu=002 perf script print wakeup_new event multiple times. These events which trigger this issue all specify a target process. commit e6dab5ffab59 ("perf/trace: Add ability to set a target task for events") has designed a method to trace these events. For example, the sched_wakeup and sched_wakeup_new tracepoint will be caught when the current task wakeup a target task. If we trace both of them and task(waken) != current(wakee), it will match this event at the beginning for tracing current task, and then match again for tracing the waken task. But these events are registered at all cpus most of the time, so these events will be matched nr_cpu times in this branch. We just forcus on the task thread here, so check the cpu number of this event and task. after this patch, perf script(perf-1039, parent-1040, child-1041): bug_fork 1040 [002] 36.535963: sched:sched_wakeup_new: comm=bug_fork pid=1041 prio=120 target_cpu=003 bug_fork 1040 [002] 36.536079: sched:sched_wakeup_new: comm=bug_fork pid=1041 prio=120 target_cpu=003 match it twice, an match for tracing current(parent) and an match for task(child). Signed-off-by: Cheng Jian --- kernel/events/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 4df5b69..a199c03 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7924,6 +7924,8 @@ void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size, continue; if (event->attr.config != entry->type) continue; + if (event->cpu != task_cpu(task) && event->cpu != -1) + continue; if (perf_tp_event_match(event, &data, regs)) perf_swevent_event(event, count, &data, regs); } -- 1.8.3.1