[tip:perf/core] perf: Find task before event alloc

From: tip-bot for Peter Zijlstra
Date: Mon Oct 18 2010 - 15:20:50 EST


Commit-ID: c6be5a5cb62592d9d661899a2aa78236eb00ffa5
Gitweb: http://git.kernel.org/tip/c6be5a5cb62592d9d661899a2aa78236eb00ffa5
Author: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
AuthorDate: Thu, 14 Oct 2010 16:59:46 +0200
Committer: Ingo Molnar <mingo@xxxxxxx>
CommitDate: Mon, 18 Oct 2010 19:58:54 +0200

perf: Find task before event alloc

So that we can pass the task pointer to the event allocation, so that
we can use task associated data during event initialization.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
LKML-Reference: <20101014203625.340789919@xxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxx>
---
kernel/perf_event.c | 23 ++++++++++++-----------
1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index f928878..b21d06a 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -5551,10 +5551,18 @@ SYSCALL_DEFINE5(perf_event_open,
group_leader = NULL;
}

+ if (pid != -1) {
+ task = find_lively_task_by_vpid(pid);
+ if (IS_ERR(task)) {
+ err = PTR_ERR(task);
+ goto err_group_fd;
+ }
+ }
+
event = perf_event_alloc(&attr, cpu, group_leader, NULL, NULL);
if (IS_ERR(event)) {
err = PTR_ERR(event);
- goto err_fd;
+ goto err_task;
}

/*
@@ -5586,21 +5594,13 @@ SYSCALL_DEFINE5(perf_event_open,
}
}

- if (pid != -1) {
- task = find_lively_task_by_vpid(pid);
- if (IS_ERR(task)) {
- err = PTR_ERR(task);
- goto err_group_fd;
- }
- }
-
/*
* Get the target context (task or percpu):
*/
ctx = find_get_context(pmu, task, cpu);
if (IS_ERR(ctx)) {
err = PTR_ERR(ctx);
- goto err_task;
+ goto err_alloc;
}

/*
@@ -5696,12 +5696,13 @@ SYSCALL_DEFINE5(perf_event_open,

err_context:
put_ctx(ctx);
+err_alloc:
+ free_event(event);
err_task:
if (task)
put_task_struct(task);
err_group_fd:
fput_light(group_file, fput_needed);
- free_event(event);
err_fd:
put_unused_fd(event_fd);
return err;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/