All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lin Ming <ming.m.lin@intel.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@elte.hu>,
	Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
	Paul Mundt <lethal@linux-sh.org>,
	"eranian@gmail.com" <eranian@gmail.com>,
	"Gary.Mohr@Bull.com" <Gary.Mohr@bull.com>,
	"arjan@linux.intel.com" <arjan@linux.intel.com>,
	"Zhang, Yanmin" <yanmin_zhang@linux.intel.com>,
	Paul Mackerras <paulus@samba.org>,
	"David S. Miller" <davem@davemloft.net>,
	Russell King <rmk+kernel@arm.linux.org.uk>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Will Deacon <will.deacon@arm.com>,
	Maynard Johnson <mpjohn@us.ibm.com>, Carl Love <carll@us.ibm.com>,
	"greg@kroah.com" <greg@kroah.com>,
	Kay Sievers <kay.sievers@vrfy.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: [RFC][PATCH v2 02/11] perf: core, add pmu register and lookup functions
Date: Wed, 19 May 2010 01:45:02 +0000	[thread overview]
Message-ID: <1274233502.3036.80.camel@localhost> (raw)

And add new api pmu::init_event

Changes log
v2: Use RCU for synchronization (Peter Zijlstra)
v1: add pmu register and lookup functions

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
---
 include/linux/perf_event.h |   11 ++++++
 kernel/perf_event.c        |   73 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 6c01c5f..40809f5 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -549,10 +549,16 @@ struct perf_event;
 
 #define PERF_EVENT_TXN_STARTED 1
 
+#define PMU_TYPE_CPU 0
+#define PMU_TYPE_NODE 1
+
 /**
  * struct pmu - generic performance monitoring unit
  */
 struct pmu {
+	int				id;
+	struct list_head		entry;
+
 	int (*enable)			(struct perf_event *event);
 	void (*disable)			(struct perf_event *event);
 	int (*start)			(struct perf_event *event);
@@ -569,6 +575,8 @@ struct pmu {
 	void (*start_txn)	(struct pmu *pmu);
 	void (*cancel_txn)	(struct pmu *pmu);
 	int  (*commit_txn)	(struct pmu *pmu);
+
+	int  (*init_event)	(struct perf_event *event);
 };
 
 /**
@@ -1013,6 +1021,9 @@ extern int perf_swevent_get_recursion_context(void);
 extern void perf_swevent_put_recursion_context(int rctx);
 extern void perf_event_enable(struct perf_event *event);
 extern void perf_event_disable(struct perf_event *event);
+
+extern int perf_event_register_pmu(struct pmu *pmu);
+extern void perf_event_unregister_pmu(int id);
 #else
 static inline void
 perf_event_task_sched_in(struct task_struct *task)			{ }
diff --git a/kernel/perf_event.c b/kernel/perf_event.c
index ba7a37a..31b032b 100644
--- a/kernel/perf_event.c
+++ b/kernel/perf_event.c
@@ -40,6 +40,12 @@
  */
 static DEFINE_PER_CPU(struct perf_cpu_context, perf_cpu_context);
 
+/*
+ * The list of multiple hw pmus
+ */
+static struct list_head pmus;
+static DEFINE_SPINLOCK(pmus_lock);
+
 int perf_max_events __read_mostly = 1;
 static int perf_reserved_percpu __read_mostly;
 static int perf_overcommit __read_mostly = 1;
@@ -4678,6 +4684,34 @@ static struct pmu *sw_perf_event_init(struct perf_event *event)
 	return pmu;
 }
 
+static struct pmu *perf_event_lookup_pmu(struct perf_event *event)
+{
+	struct pmu *pmu = NULL;
+	int pmu_id = event->attr.type;
+
+	switch (event->attr.type) {
+		case PERF_TYPE_HARDWARE:
+		case PERF_TYPE_HW_CACHE:
+		case PERF_TYPE_RAW:
+			pmu_id = PMU_TYPE_CPU;
+			break;
+
+		/* TBD: will add other pmu type later */
+
+		default:
+			return NULL;
+	}
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(pmu, &pmus, entry) {
+		if (pmu->id == pmu_id)
+			break;
+	}
+	rcu_read_unlock();
+
+	return pmu;
+}
+
 /*
  * Allocate and initialize a event structure
  */
@@ -5635,6 +5669,8 @@ void __init perf_event_init(void)
 	perf_cpu_notify(&perf_cpu_nb, (unsigned long)CPU_ONLINE,
 			(void *)(long)smp_processor_id());
 	register_cpu_notifier(&perf_cpu_nb);
+
+	INIT_LIST_HEAD(&pmus);
 }
 
 static ssize_t perf_show_reserve_percpu(struct sysdev_class *class,
@@ -5734,3 +5770,40 @@ static int __init perf_event_sysfs_init(void)
 				  &perfclass_attr_group);
 }
 device_initcall(perf_event_sysfs_init);
+
+int perf_event_register_pmu(struct pmu *pmu)
+{
+	struct pmu *tmp;
+	int ret = 1;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(tmp, &pmus, entry) {
+		if (tmp->id == pmu->id) {
+			ret = 0;
+			goto err;
+		}
+	}
+	rcu_read_unlock();
+
+	spin_lock(&pmus_lock);
+	list_add_tail_rcu(&pmu->entry, &pmus);
+	spin_unlock(&pmus_lock);
+
+err:
+	return ret;
+}
+
+void perf_event_unregister_pmu(int id)
+{
+	struct pmu *tmp = NULL;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(tmp, &pmus, entry) {
+		if (tmp->id == id)
+			break;
+	}
+	rcu_read_unlock();
+
+	if (tmp)
+		list_del_rcu(&tmp->entry);
+}





             reply	other threads:[~2010-05-18 17:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-19  1:45 Lin Ming [this message]
2010-05-18 18:38 ` [RFC][PATCH v2 02/11] perf: core, add pmu register and lookup functions Cyrill Gorcunov
2010-05-19  2:00   ` Lin Ming

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=1274233502.3036.80.camel@localhost \
    --to=ming.m.lin@intel.com \
    --cc=Gary.Mohr@bull.com \
    --cc=acme@redhat.com \
    --cc=arjan@linux.intel.com \
    --cc=carll@us.ibm.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=davem@davemloft.net \
    --cc=eranian@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=greg@kroah.com \
    --cc=kay.sievers@vrfy.org \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mpjohn@us.ibm.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=will.deacon@arm.com \
    --cc=yanmin_zhang@linux.intel.com \
    /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.