From: Cheng Jian <cj.chengjian@huawei.com>
To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
<alexander.shishkin@linux.intel.com>
Cc: <linux-kernel@vger.kernel.org>, <xiexiuqi@huawei.com>,
<huawei.libin@huawei.com>, <cj.chengjian@huawei.com>
Subject: [PATCH] perf/ftrace : Fix repetitious traces when specify a target task
Date: Tue, 10 Oct 2017 09:19:39 +0800 [thread overview]
Message-ID: <1507598379-148309-1-git-send-email-cj.chengjian@huawei.com> (raw)
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 <cj.chengjian@huawei.com>
---
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
next reply other threads:[~2017-10-10 1:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 1:19 Cheng Jian [this message]
2017-10-10 11:33 ` Peter Zijlstra
2017-10-10 12:18 ` chengjian (D)
2017-10-10 13:42 ` Peter Zijlstra
2017-10-10 13:04 ` Peter Zijlstra
2017-10-10 15:21 ` Peter Zijlstra
2017-10-10 16:35 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1507598379-148309-1-git-send-email-cj.chengjian@huawei.com \
--to=cj.chengjian@huawei.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=huawei.libin@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=xiexiuqi@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®