Skip to content

Commit

Permalink
perf events: Split out task search into helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Matt Helsley authored and Ingo Molnar committed Sep 15, 2010
1 parent d958077 commit 2ebd4ff
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions kernel/perf_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2ebd4ff

Please sign in to comment.