Skip to content

Commit 1d95311

Browse files
oleg-nesterovIngo Molnar
authored andcommitted
perf/core: Don't report zero PIDs for exiting tasks
The exiting/dead task has no PIDs and in this case perf_event_pid/tid() return zero, change them to return -1 to distinguish this case from idle threads. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Arnaldo Carvalho <acme@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20170822155928.GA6892@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 6ae5fa6 commit 1d95311

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

kernel/events/core.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,26 +1249,31 @@ unclone_ctx(struct perf_event_context *ctx)
12491249
return parent_ctx;
12501250
}
12511251

1252-
static u32 perf_event_pid(struct perf_event *event, struct task_struct *p)
1252+
static u32 perf_event_pid_type(struct perf_event *event, struct task_struct *p,
1253+
enum pid_type type)
12531254
{
1255+
u32 nr;
12541256
/*
12551257
* only top level events have the pid namespace they were created in
12561258
*/
12571259
if (event->parent)
12581260
event = event->parent;
12591261

1260-
return task_tgid_nr_ns(p, event->ns);
1262+
nr = __task_pid_nr_ns(p, type, event->ns);
1263+
/* avoid -1 if it is idle thread or runs in another ns */
1264+
if (!nr && !pid_alive(p))
1265+
nr = -1;
1266+
return nr;
12611267
}
12621268

1263-
static u32 perf_event_tid(struct perf_event *event, struct task_struct *p)
1269+
static u32 perf_event_pid(struct perf_event *event, struct task_struct *p)
12641270
{
1265-
/*
1266-
* only top level events have the pid namespace they were created in
1267-
*/
1268-
if (event->parent)
1269-
event = event->parent;
1271+
return perf_event_pid_type(event, p, __PIDTYPE_TGID);
1272+
}
12701273

1271-
return task_pid_nr_ns(p, event->ns);
1274+
static u32 perf_event_tid(struct perf_event *event, struct task_struct *p)
1275+
{
1276+
return perf_event_pid_type(event, p, PIDTYPE_PID);
12721277
}
12731278

12741279
/*

0 commit comments

Comments
 (0)