mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Prasad <prasad@linux.vnet.ibm.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@elte.hu>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Jiri Slaby <jirislaby@gmail.com>, Li Zefan <lizf@cn.fujitsu.com>,
	Avi Kivity <avi@redhat.com>, Paul Mackerras <paulus@samba.org>,
	Mike Galbraith <efault@gmx.de>,
	Masami Hiramatsu <mhiramat@redhat.com>
Subject: [PATCH 2/5] perf_counter: Export various perf helpers for external users
Date: Thu, 10 Sep 2009 10:29:24 +0200	[thread overview]
Message-ID: <1252571367-25876-3-git-send-email-fweisbec@gmail.com> (raw)
In-Reply-To: <1252571367-25876-1-git-send-email-fweisbec@gmail.com>

Export various perf helpers that initialize, destroy, attach and detach
a perf counter for future external users like the hardware breakpoint api.

The allocation and initialization of a perf counter have been split up
so that an external user can first allocate and then prefill the
counter before initialize it properly.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Prasad <prasad@linux.vnet.ibm.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Jiri Slaby <jirislaby@gmail.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
---
 include/linux/perf_counter.h |   31 +++++++++++++++++
 kernel/perf_counter.c        |   74 +++++++++++++++++++++++++-----------------
 2 files changed, 75 insertions(+), 30 deletions(-)

diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index f557483..1181c24 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -692,9 +692,23 @@ extern int perf_max_counters;
 
 extern const struct pmu *hw_perf_counter_init(struct perf_counter *counter);
 
+extern int
+__perf_counter_init(struct perf_counter *counter,
+		    struct perf_counter_attr *attr,
+		    int cpu,
+		    struct perf_counter_context *ctx,
+		    struct perf_counter *group_leader,
+		    struct perf_counter *parent_counter);
+extern void free_counter(struct perf_counter *counter);
+extern void put_ctx(struct perf_counter_context *ctx);
 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 struct perf_counter_context *find_get_context(pid_t pid, int cpu);
+extern void perf_install_in_context(struct perf_counter_context *ctx,
+				    struct perf_counter *counter,
+				    int cpu);
+extern void perf_counter_remove_from_context(struct perf_counter *counter);
 extern void perf_counter_task_tick(struct task_struct *task, int cpu);
 extern int perf_counter_init_task(struct task_struct *child);
 extern void perf_counter_exit_task(struct task_struct *child);
@@ -799,6 +813,23 @@ static inline void perf_counter_mmap(struct vm_area_struct *vma)	{ }
 static inline void perf_counter_comm(struct task_struct *tsk)		{ }
 static inline void perf_counter_fork(struct task_struct *tsk)		{ }
 static inline void perf_counter_init(void)				{ }
+static inline int
+__perf_counter_init(struct perf_counter *counter,
+		    struct perf_counter_attr *attr,
+		    int cpu,
+		    struct perf_counter_context *ctx,
+		    struct perf_counter *group_leader,
+		    struct perf_counter *parent_counter)	{ return NULL; }
+static inline void free_counter(struct perf_counter *counter)		{ }
+static inline void put_ctx(struct perf_counter_context *ctx)		{ }
+static inline struct perf_counter_context *
+find_get_context(pid_t pid, int cpu)			{ return NULL; }
+static inline void perf_install_in_context(struct perf_counter_context *ctx,
+					   struct perf_counter *counter,
+					   int cpu)			{ }
+static inline void
+perf_counter_remove_from_context(struct perf_counter *counter)		{ }
+
 #endif
 
 #endif /* __KERNEL__ */
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index 400ccf6..de62fab 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -137,7 +137,7 @@ static void free_ctx(struct rcu_head *head)
 	kfree(ctx);
 }
 
-static void put_ctx(struct perf_counter_context *ctx)
+void put_ctx(struct perf_counter_context *ctx)
 {
 	if (atomic_dec_and_test(&ctx->refcount)) {
 		if (ctx->parent_ctx)
@@ -405,7 +405,7 @@ static void __perf_counter_remove_from_context(void *info)
  * When called from perf_counter_exit_task, it's OK because the
  * context has been detached from its task.
  */
-static void perf_counter_remove_from_context(struct perf_counter *counter)
+void perf_counter_remove_from_context(struct perf_counter *counter)
 {
 	struct perf_counter_context *ctx = counter->ctx;
 	struct task_struct *task = ctx->task;
@@ -810,10 +810,9 @@ static void __perf_install_in_context(void *info)
  *
  * Must be called with ctx->mutex held.
  */
-static void
-perf_install_in_context(struct perf_counter_context *ctx,
-			struct perf_counter *counter,
-			int cpu)
+void perf_install_in_context(struct perf_counter_context *ctx,
+			     struct perf_counter *counter,
+			     int cpu)
 {
 	struct task_struct *task = ctx->task;
 
@@ -1558,7 +1557,7 @@ __perf_counter_init_context(struct perf_counter_context *ctx,
 	ctx->task = task;
 }
 
-static struct perf_counter_context *find_get_context(pid_t pid, int cpu)
+struct perf_counter_context *find_get_context(pid_t pid, int cpu)
 {
 	struct perf_counter_context *ctx;
 	struct perf_cpu_context *cpuctx;
@@ -1661,7 +1660,7 @@ static void free_counter_rcu(struct rcu_head *head)
 
 static void perf_pending_sync(struct perf_counter *counter);
 
-static void free_counter(struct perf_counter *counter)
+void free_counter(struct perf_counter *counter)
 {
 	perf_pending_sync(counter);
 
@@ -1676,8 +1675,7 @@ static void free_counter(struct perf_counter *counter)
 	}
 
 	if (counter->pmu->close)
-		if (counter->state != PERF_COUNTER_STATE_UNOPENED)
-			counter->pmu->close(counter);
+		counter->pmu->close(counter);
 
 	if (counter->destroy)
 		counter->destroy(counter);
@@ -4010,26 +4008,18 @@ static const struct pmu *sw_perf_counter_init(struct perf_counter *counter)
 	return pmu;
 }
 
-/*
- * Allocate and initialize a counter structure
- */
-static struct perf_counter *
-perf_counter_alloc(struct perf_counter_attr *attr,
-		   int cpu,
-		   struct perf_counter_context *ctx,
-		   struct perf_counter *group_leader,
-		   struct perf_counter *parent_counter,
-		   gfp_t gfpflags)
+
+int __perf_counter_init(struct perf_counter *counter,
+			struct perf_counter_attr *attr,
+			int cpu,
+			struct perf_counter_context *ctx,
+			struct perf_counter *group_leader,
+			struct perf_counter *parent_counter)
 {
 	const struct pmu *pmu;
-	struct perf_counter *counter;
 	struct hw_perf_counter *hwc;
 	long err;
 
-	counter = kzalloc(sizeof(*counter), gfpflags);
-	if (!counter)
-		return ERR_PTR(-ENOMEM);
-
 	/*
 	 * Single counters are their own group leaders, with an
 	 * empty sibling list:
@@ -4112,10 +4102,8 @@ done:
 
 	if (pmu->open) {
 		err = pmu->open(counter);
-		if (err) {
-			counter->state = PERF_COUNTER_STATE_UNOPENED;
+		if (err)
 			goto fail;
-		}
 	}
 
 	if (!counter->parent) {
@@ -4128,14 +4116,40 @@ done:
 			atomic_inc(&nr_task_counters);
 	}
 
-	return counter;
+	return 0;
 
 fail:
 	if (counter->ns)
 		put_pid_ns(counter->ns);
 	kfree(counter);
 
-	return ERR_PTR(err);
+	return err;
+}
+
+/*
+ * Allocate and initialize a counter structure
+ */
+static struct perf_counter *
+perf_counter_alloc(struct perf_counter_attr *attr,
+		   int cpu,
+		   struct perf_counter_context *ctx,
+		   struct perf_counter *group_leader,
+		   struct perf_counter *parent_counter,
+		   gfp_t gfpflags)
+{
+	int err;
+	struct perf_counter *counter;
+
+	counter = kzalloc(sizeof(*counter), gfpflags);
+	if (!counter)
+		return ERR_PTR(-ENOMEM);
+
+	err = __perf_counter_init(counter, attr, cpu, ctx, group_leader,
+				  parent_counter);
+	if (err)
+		return ERR_PTR(err);
+
+	return counter;
 }
 
 static int perf_copy_attr(struct perf_counter_attr __user *uattr,
-- 
1.6.2.3


  parent reply	other threads:[~2009-09-10  8:29 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-10  8:29 [RFC GIT PULL] hw-breakpoints: Rewrite on top of perf counters Frederic Weisbecker
2009-09-10  8:29 ` [PATCH 1/5] perf_counter: Add open/close pmu callbacks Frederic Weisbecker
2009-09-10 11:22   ` Paul Mackerras
2009-09-10 18:46     ` Frederic Weisbecker
2009-09-10  8:29 ` Frederic Weisbecker [this message]
2009-09-10 11:28   ` [PATCH 2/5] perf_counter: Export various perf helpers for external users Paul Mackerras
2009-09-10 18:43     ` Frederic Weisbecker
2009-09-10  8:29 ` [PATCH 3/5] hw-breakpoints: Rewrite the hw-breakpoints layer on top of perf counters Frederic Weisbecker
2009-09-10 14:25   ` K.Prasad
2009-09-10 18:53     ` Frederic Weisbecker
2009-09-10 21:18       ` Peter Zijlstra
2009-09-14 21:18         ` Frederic Weisbecker
2009-09-14 17:17       ` K.Prasad
2009-09-14 21:33         ` Frederic Weisbecker
2009-09-11 22:09   ` Jan Kiszka
2009-09-14  3:41     ` Frederic Weisbecker
2009-09-14  6:24       ` Jan Kiszka
2009-09-14 18:01         ` Frederic Weisbecker
2009-09-14 17:28   ` K.Prasad
2009-09-14 21:36     ` Frederic Weisbecker
2009-09-10  8:29 ` [PATCH 4/5] hw-breakpoints: Arbitrate access to pmu following registers constraints Frederic Weisbecker
2009-09-10 14:41   ` Daniel Walker
2009-09-10 14:57     ` Peter Zijlstra
2009-09-10 14:59       ` Daniel Walker
2009-09-10 15:02       ` Steven Rostedt
2009-09-10 18:53     ` Frederic Weisbecker
2009-09-10  8:29 ` [PATCH 5/5] ksym_tracer: Remove KSYM_SELFTEST_ENTRY Frederic Weisbecker
2009-09-10 10:09 ` [RFC GIT PULL] hw-breakpoints: Rewrite on top of perf counters Paul Mackerras
2009-09-10 17:23   ` Ingo Molnar
2009-09-10 18:24   ` 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=1252571367-25876-3-git-send-email-fweisbec@gmail.com \
    --to=fweisbec@gmail.com \
    --cc=acme@redhat.com \
    --cc=avi@redhat.com \
    --cc=efault@gmx.de \
    --cc=jan.kiszka@siemens.com \
    --cc=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=prasad@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=stern@rowland.harvard.edu \
    /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