From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756445AbdHYL5b (ORCPT ); Fri, 25 Aug 2017 07:57:31 -0400 Received: from terminus.zytor.com ([65.50.211.136]:43335 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756332AbdHYL53 (ORCPT ); Fri, 25 Aug 2017 07:57:29 -0400 Date: Fri, 25 Aug 2017 04:53:55 -0700 From: tip-bot for Oleg Nesterov Message-ID: Cc: hpa@zytor.com, tglx@linutronix.de, peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, oleg@redhat.com, acme@kernel.org Reply-To: tglx@linutronix.de, hpa@zytor.com, peterz@infradead.org, mingo@kernel.org, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, oleg@redhat.com, acme@kernel.org In-Reply-To: <20170822155928.GA6892@redhat.com> References: <20170822155928.GA6892@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf/core: Don't report zero PIDs for exiting tasks Git-Commit-ID: 1d953111b648e48923171c3c9cf17be2250544fa X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 1d953111b648e48923171c3c9cf17be2250544fa Gitweb: http://git.kernel.org/tip/1d953111b648e48923171c3c9cf17be2250544fa Author: Oleg Nesterov AuthorDate: Tue, 22 Aug 2017 17:59:28 +0200 Committer: Ingo Molnar CommitDate: Fri, 25 Aug 2017 11:04:17 +0200 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 Signed-off-by: Peter Zijlstra (Intel) Cc: Arnaldo Carvalho Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20170822155928.GA6892@redhat.com Signed-off-by: Ingo Molnar --- kernel/events/core.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 1ac5015..b411321 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -1249,26 +1249,31 @@ unclone_ctx(struct perf_event_context *ctx) return parent_ctx; } -static u32 perf_event_pid(struct perf_event *event, struct task_struct *p) +static u32 perf_event_pid_type(struct perf_event *event, struct task_struct *p, + enum pid_type type) { + u32 nr; /* * only top level events have the pid namespace they were created in */ if (event->parent) event = event->parent; - return task_tgid_nr_ns(p, event->ns); + nr = __task_pid_nr_ns(p, type, event->ns); + /* avoid -1 if it is idle thread or runs in another ns */ + if (!nr && !pid_alive(p)) + nr = -1; + return nr; } -static u32 perf_event_tid(struct perf_event *event, struct task_struct *p) +static u32 perf_event_pid(struct perf_event *event, struct task_struct *p) { - /* - * only top level events have the pid namespace they were created in - */ - if (event->parent) - event = event->parent; + return perf_event_pid_type(event, p, __PIDTYPE_TGID); +} - return task_pid_nr_ns(p, event->ns); +static u32 perf_event_tid(struct perf_event *event, struct task_struct *p) +{ + return perf_event_pid_type(event, p, PIDTYPE_PID); } /*