From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932106AbdJJBPO (ORCPT ); Mon, 9 Oct 2017 21:15:14 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7530 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932077AbdJJBPN (ORCPT ); Mon, 9 Oct 2017 21:15:13 -0400 From: Cheng Jian To: , , , CC: , , , Subject: [PATCH] perf/ftrace : Fix repetitious traces when specify a target task Date: Tue, 10 Oct 2017 09:19:39 +0800 Message-ID: <1507598379-148309-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 X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0206.59DC1F1E.0034,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: f335dbfd67ac60f604d6e54ded2dff91 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When use perf to trace the sched_wakeup and 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 events : the parent process does nothing but fork a child process, and then they both quit. perf script : bug_fork 1078 [002] 184.669341: sched:sched_wakeup_new: comm=bug_fork pid=1079 prio=120 target_cpu=000 bug_fork 1078 [002] 184.670128: sched:sched_wakeup_new: comm=bug_fork pid=1079 prio=120 target_cpu=000 bug_fork 1078 [002] 184.670128: sched:sched_wakeup_new: comm=bug_fork pid=1079 prio=120 target_cpu=000 bug_fork 1078 [002] 184.670128: sched:sched_wakeup_new: comm=bug_fork pid=1079 prio=120 target_cpu=000 bug_fork 1078 [002] 184.670128: sched:sched_wakeup_new: comm=bug_fork pid=1079 prio=120 target_cpu=000 but ftrace only show one event: bug_fork-1078 [002] d... 184.889159: sched_wakeup_new: comm=bug_fork pid=1079 prio=120 target_cpu=000 perf script repeat prints wakeup_new events multiple times. These events which trigger this issue not only monitor the current task, but also specify a target task. For example, the sched_wakeup and sched_wakeup_new tracepoint will be caught when the current task wakeup the target task which we traced on. commit e6dab5ffab59 ("perf/trace: Add ability to set a target task for events") has designed a method to trace these events which specify a target task. But there have tow issues when monitoring multithreaded/multiprocess apps. First, it match an event(such as wakeup/wakeup_new/stat_*) at the begin, but the function doesn't return, the event will be matched again because of task != current. Second, due to these events are registered/mmaped at per-cpu or per-thread(--per-thread), so perf_swevent_event will match these events multiple times in the branch(task != current), the number of repetitions is just the number of CPUs or threads. perf_tp_event will only match an event event at a time, so we will return after an event matched. Signed-off-by: Cheng Jian --- kernel/events/core.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index baa134c..5682ead 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7988,12 +7988,16 @@ void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size, /* Use the given event instead of the hlist */ if (event) { - if (perf_tp_event_match(event, &data, regs)) + if (perf_tp_event_match(event, &data, regs)) { perf_swevent_event(event, count, &data, regs); + goto out; + } } else { hlist_for_each_entry_rcu(event, head, hlist_entry) { - if (perf_tp_event_match(event, &data, regs)) + if (perf_tp_event_match(event, &data, regs)) { perf_swevent_event(event, count, &data, regs); + goto out; + } } } @@ -8015,13 +8019,15 @@ void perf_tp_event(u16 event_type, u64 count, void *record, int entry_size, continue; if (event->attr.config != entry->type) continue; - if (perf_tp_event_match(event, &data, regs)) + if (perf_tp_event_match(event, &data, regs)) { perf_swevent_event(event, count, &data, regs); + break; + } } unlock: rcu_read_unlock(); } - +out: perf_swevent_put_recursion_context(rctx); } EXPORT_SYMBOL_GPL(perf_tp_event); -- 1.8.3.1