mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Matt Helsley <matthltc@us.ibm.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, acme@redhat.com, hpa@zytor.com,
	mingo@redhat.com, will.deacon@arm.com, a.p.zijlstra@chello.nl,
	matthltc@us.ibm.com, mahesh@linux.vnet.ibm.com,
	rostedt@goodmis.org, tglx@linutronix.de, mingo@elte.hu,
	greenrd@greenrd.org, prasad@linux.vnet.ibm.com
Subject: [tip:perf/core] perf events: Split out task search into helper
Date: Wed, 15 Sep 2010 10:03:29 GMT	[thread overview]
Message-ID: <tip-2ebd4ffb6d0cb877787b1e42be8485820158857e@git.kernel.org> (raw)
In-Reply-To: <561205417b450b8a4bf7488374541d64b4690431.1284407762.git.matthltc@us.ibm.com>

Commit-ID:  2ebd4ffb6d0cb877787b1e42be8485820158857e
Gitweb:     http://git.kernel.org/tip/2ebd4ffb6d0cb877787b1e42be8485820158857e
Author:     Matt Helsley <matthltc@us.ibm.com>
AuthorDate: Mon, 13 Sep 2010 13:01:19 -0700
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 15 Sep 2010 10:44:00 +0200

perf events: Split out task search into helper

Split out the code which searches for non-exiting tasks into its own
helper. Creating this helper not only makes the code slightly more
readable it prepares to move the search out of find_get_context() in
a subsequent commit.

Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robin Green <greenrd@greenrd.org>
Cc: Prasad <prasad@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
LKML-Reference: <561205417b450b8a4bf7488374541d64b4690431.1284407762.git.matthltc@us.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/perf_event.c |   63 ++++++++++++++++++++++++++++++++------------------
 1 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index 440f9ca..3f5309d 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -2015,6 +2015,43 @@ alloc_perf_context(struct pmu *pmu, struct task_struct *task)
 	return ctx;
 }
 
+static struct task_struct *
+find_lively_task_by_vpid(pid_t vpid)
+{
+	struct task_struct *task;
+	int err;
+
+	rcu_read_lock();
+	if (!vpid)
+		task = current;
+	else
+		task = find_task_by_vpid(vpid);
+	if (task)
+		get_task_struct(task);
+	rcu_read_unlock();
+
+	if (!task)
+		return ERR_PTR(-ESRCH);
+
+	/*
+	 * Can't attach events to a dying task.
+	 */
+	err = -ESRCH;
+	if (task->flags & PF_EXITING)
+		goto errout;
+
+	/* Reuse ptrace permission checks for now. */
+	err = -EACCES;
+	if (!ptrace_may_access(task, PTRACE_MODE_READ))
+		goto errout;
+
+	return task;
+errout:
+	put_task_struct(task);
+	return ERR_PTR(err);
+
+}
+
 static struct perf_event_context *
 find_get_context(struct pmu *pmu, pid_t pid, int cpu)
 {
@@ -2047,29 +2084,9 @@ find_get_context(struct pmu *pmu, pid_t pid, int cpu)
 		return ctx;
 	}
 
-	rcu_read_lock();
-	if (!pid)
-		task = current;
-	else
-		task = find_task_by_vpid(pid);
-	if (task)
-		get_task_struct(task);
-	rcu_read_unlock();
-
-	if (!task)
-		return ERR_PTR(-ESRCH);
-
-	/*
-	 * Can't attach events to a dying task.
-	 */
-	err = -ESRCH;
-	if (task->flags & PF_EXITING)
-		goto errout;
-
-	/* Reuse ptrace permission checks for now. */
-	err = -EACCES;
-	if (!ptrace_may_access(task, PTRACE_MODE_READ))
-		goto errout;
+	task = find_lively_task_by_vpid(pid);
+	if (IS_ERR(task))
+		return (void*)task;
 
 	err = -EINVAL;
 	ctxn = pmu->task_ctx_nr;

  parent reply	other threads:[~2010-09-15 10:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1284408080-2135-1-git-send-email-matthltc@us.ibm.com>
2010-09-13 20:01 ` [PATCH 1/3] hw breakpoints: Fix pid namespace bug Matt Helsley
2010-09-13 20:01   ` [PATCH 2/3] perf events: Split out task search into helper Matt Helsley
2010-09-13 20:01     ` [PATCH 3/3] perf events: Cleanup pid passing Matt Helsley
2010-09-15  8:18       ` Peter Zijlstra
2010-09-15 10:03       ` [tip:perf/core] perf events: Clean up " tip-bot for Matt Helsley
2010-09-22 12:22         ` Peter Zijlstra
2010-09-15 10:03     ` tip-bot for Matt Helsley [this message]
2010-09-15 10:03   ` [tip:perf/core] hw breakpoints: Fix pid namespace bug tip-bot for Matt Helsley
2010-09-15 11:41     ` Frederic Weisbecker
2010-09-15 11:45       ` Ingo Molnar
2010-09-17  8:28   ` [tip:perf/urgent] " tip-bot for Matt Helsley
2010-09-13 20:08 ` [PATCH 0/3] perf_events and hw_breakpoints fix and cleanup Frederic Weisbecker

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=tip-2ebd4ffb6d0cb877787b1e42be8485820158857e@git.kernel.org \
    --to=matthltc@us.ibm.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=greenrd@greenrd.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mahesh@linux.vnet.ibm.com \
    --cc=mingo@elte.hu \
    --cc=mingo@redhat.com \
    --cc=prasad@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@arm.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

Powered by JetHome