Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147502
b: refs/heads/master
c: 6ab423e
h: refs/heads/master
v: v3
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed May 25, 2009
1 parent 006fd4c commit 83de5a6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 771d7cde144d87f2d1fbee4da3c6234d61f7e42a
refs/heads/master: 6ab423e0eaca827fbd201ca4ae7d4f8573a366b2
4 changes: 2 additions & 2 deletions trunk/include/linux/perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ extern void perf_counter_task_sched_in(struct task_struct *task, int cpu);
extern void perf_counter_task_sched_out(struct task_struct *task,
struct task_struct *next, int cpu);
extern void perf_counter_task_tick(struct task_struct *task, int cpu);
extern void perf_counter_init_task(struct task_struct *child);
extern int perf_counter_init_task(struct task_struct *child);
extern void perf_counter_exit_task(struct task_struct *child);
extern void perf_counter_do_pending(void);
extern void perf_counter_print_debug(void);
Expand Down Expand Up @@ -631,7 +631,7 @@ perf_counter_task_sched_out(struct task_struct *task,
struct task_struct *next, int cpu) { }
static inline void
perf_counter_task_tick(struct task_struct *task, int cpu) { }
static inline void perf_counter_init_task(struct task_struct *child) { }
static inline int perf_counter_init_task(struct task_struct *child) { }
static inline void perf_counter_exit_task(struct task_struct *child) { }
static inline void perf_counter_do_pending(void) { }
static inline void perf_counter_print_debug(void) { }
Expand Down
6 changes: 5 additions & 1 deletion trunk/kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,

/* Perform scheduler related setup. Assign this task to a CPU. */
sched_fork(p, clone_flags);
perf_counter_init_task(p);

retval = perf_counter_init_task(p);
if (retval)
goto bad_fork_cleanup_policy;

if ((retval = audit_alloc(p)))
goto bad_fork_cleanup_policy;
Expand Down Expand Up @@ -1295,6 +1298,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
bad_fork_cleanup_audit:
audit_free(p);
bad_fork_cleanup_policy:
perf_counter_exit_task(p);
#ifdef CONFIG_NUMA
mpol_put(p->mempolicy);
bad_fork_cleanup_cgroup:
Expand Down
20 changes: 12 additions & 8 deletions trunk/kernel/perf_counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3434,18 +3434,23 @@ void perf_counter_exit_task(struct task_struct *child)
/*
* Initialize the perf_counter context in task_struct
*/
void perf_counter_init_task(struct task_struct *child)
int perf_counter_init_task(struct task_struct *child)
{
struct perf_counter_context *child_ctx, *parent_ctx;
struct perf_counter *counter;
struct task_struct *parent = current;
int inherited_all = 1;
int ret = 0;

child->perf_counter_ctxp = NULL;

mutex_init(&child->perf_counter_mutex);
INIT_LIST_HEAD(&child->perf_counter_list);

parent_ctx = parent->perf_counter_ctxp;
if (likely(!parent_ctx || !parent_ctx->nr_counters))
return 0;

/*
* This is executed from the parent task context, so inherit
* counters that have been marked for cloning.
Expand All @@ -3454,11 +3459,7 @@ void perf_counter_init_task(struct task_struct *child)

child_ctx = kmalloc(sizeof(struct perf_counter_context), GFP_KERNEL);
if (!child_ctx)
return;

parent_ctx = parent->perf_counter_ctxp;
if (likely(!parent_ctx || !parent_ctx->nr_counters))
return;
return -ENOMEM;

__perf_counter_init_context(child_ctx, child);
child->perf_counter_ctxp = child_ctx;
Expand All @@ -3482,8 +3483,9 @@ void perf_counter_init_task(struct task_struct *child)
continue;
}

if (inherit_group(counter, parent,
parent_ctx, child, child_ctx)) {
ret = inherit_group(counter, parent, parent_ctx,
child, child_ctx);
if (ret) {
inherited_all = 0;
break;
}
Expand All @@ -3505,6 +3507,8 @@ void perf_counter_init_task(struct task_struct *child)
}

mutex_unlock(&parent_ctx->mutex);

return ret;
}

static void __cpuinit perf_counter_init_cpu(int cpu)
Expand Down

0 comments on commit 83de5a6

Please sign in to comment.