From: tip-bot for Peter Zijlstra <a.p.zijlstra@chello.nl>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, acme@redhat.com, paulus@samba.org,
hpa@zytor.com, mingo@redhat.com, jkacur@redhat.com,
a.p.zijlstra@chello.nl, tglx@linutronix.de,
cjashfor@linux.vnet.ibm.com, mingo@elte.hu
Subject: [tip:perfcounters/core] perf_counter: Propagate inheritance failures down the fork() path
Date: Mon, 25 May 2009 13:04:07 GMT [thread overview]
Message-ID: <tip-6ab423e0eaca827fbd201ca4ae7d4f8573a366b2@git.kernel.org> (raw)
In-Reply-To: <20090525124600.324656474@chello.nl>
Commit-ID: 6ab423e0eaca827fbd201ca4ae7d4f8573a366b2
Gitweb: http://git.kernel.org/tip/6ab423e0eaca827fbd201ca4ae7d4f8573a366b2
Author: Peter Zijlstra <a.p.zijlstra@chello.nl>
AuthorDate: Mon, 25 May 2009 14:45:27 +0200
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Mon, 25 May 2009 14:55:01 +0200
perf_counter: Propagate inheritance failures down the fork() path
Fail fork() when we fail inheritance for some reason (-ENOMEM most likely).
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: John Kacur <jkacur@redhat.com>
LKML-Reference: <20090525124600.324656474@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/linux/perf_counter.h | 4 ++--
kernel/fork.c | 6 +++++-
kernel/perf_counter.c | 20 ++++++++++++--------
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index b1f2bac..d3e85de 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -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);
@@ -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) { }
diff --git a/kernel/fork.c b/kernel/fork.c
index 675e01e..c07c333 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -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;
@@ -1295,6 +1298,7 @@ bad_fork_cleanup_semundo:
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:
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 217dbcc..7a7a144 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -3434,18 +3434,23 @@ again:
/*
* 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.
@@ -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;
@@ -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;
}
@@ -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)
next prev parent reply other threads:[~2009-05-25 13:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-25 12:45 [PATCH 0/5] yet more perf counter patches Peter Zijlstra
2009-05-25 12:45 ` [PATCH 1/5] perf_counter: fix perf-$cmd invokation Peter Zijlstra
2009-05-25 13:03 ` [tip:perfcounters/core] perf_counter: Fix " tip-bot for Peter Zijlstra
2009-05-25 12:45 ` [PATCH 2/5] perf_counter: remove unused ABI bits Peter Zijlstra
2009-05-25 13:03 ` [tip:perfcounters/core] perf_counter: Remove " tip-bot for Peter Zijlstra
2009-05-25 12:45 ` [PATCH 3/5] perf_counter: make pctrl() affect inherited counters too Peter Zijlstra
2009-05-25 13:03 ` [tip:perfcounters/core] perf_counter: Make " tip-bot for Peter Zijlstra
2009-05-25 12:45 ` [PATCH 4/5] perf_counter: propagate inheritance failures down the fork() path Peter Zijlstra
2009-05-25 13:04 ` tip-bot for Peter Zijlstra [this message]
2009-05-25 12:45 ` [PATCH 5/5] perf_counter: fix PERF_COUNTER_CONTEXT_SWITCHES for cpu counters Peter Zijlstra
2009-05-25 13:04 ` [tip:perfcounters/core] perf_counter: Fix " tip-bot for Peter Zijlstra
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-6ab423e0eaca827fbd201ca4ae7d4f8573a366b2@git.kernel.org \
--to=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=hpa@zytor.com \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=paulus@samba.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.