All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf: provide PMU when initing events
@ 2011-08-11 11:31 Mark Rutland
  2011-08-11 11:43 ` Peter Zijlstra
  2011-08-14 15:54 ` [tip:perf/core] " tip-bot for Mark Rutland
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Rutland @ 2011-08-11 11:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Will Deacon, Mark Rutland, Ingo Molnar, Peter Zijlstra

Currently, an event's 'pmu' field is set after pmu::event_init() is
called. This means that pmu::event_init() must figure out which struct
pmu the event was initialised from. This makes it difficult to
consolidate common event initialisation code for similar PMUs, and
very difficult to implement drivers for PMUs which can have multiple
instances (e.g. a USB controller PMU, a GPU PMU, etc).

This patch sets the 'pmu' field before initialising the event, allowing
event init code to identify the struct pmu instance easily. In the
event of failure to initialise an event, the event is destroyed via
kfree() without calling perf_event::destroy(), so this shouldn't
result in bad behaviour even if the destroy field was set before
failure to initialise was noted.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Will Deacon <will.deacon@arm.com>
CC: Ingo Molnar <mingo@elte.hu>
CC: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 kernel/events/core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index b8785e2..68c8017 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5715,6 +5715,7 @@ struct pmu *perf_init_event(struct perf_event *event)
 	pmu = idr_find(&pmu_idr, event->attr.type);
 	rcu_read_unlock();
 	if (pmu) {
+		event->pmu = pmu;
 		ret = pmu->event_init(event);
 		if (ret)
 			pmu = ERR_PTR(ret);
@@ -5722,6 +5723,7 @@ struct pmu *perf_init_event(struct perf_event *event)
 	}
 
 	list_for_each_entry_rcu(pmu, &pmus, entry) {
+		event->pmu = pmu;
 		ret = pmu->event_init(event);
 		if (!ret)
 			goto unlock;
@@ -5848,8 +5850,6 @@ done:
 		return ERR_PTR(err);
 	}
 
-	event->pmu = pmu;
-
 	if (!event->parent) {
 		if (event->attach_state & PERF_ATTACH_TASK)
 			jump_label_inc(&perf_sched_events);
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf: provide PMU when initing events
  2011-08-11 11:31 [PATCH] perf: provide PMU when initing events Mark Rutland
@ 2011-08-11 11:43 ` Peter Zijlstra
  2011-08-14 15:54 ` [tip:perf/core] " tip-bot for Mark Rutland
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2011-08-11 11:43 UTC (permalink / raw)
  To: Mark Rutland; +Cc: linux-kernel, Will Deacon, Ingo Molnar

On Thu, 2011-08-11 at 12:31 +0100, Mark Rutland wrote:
> Currently, an event's 'pmu' field is set after pmu::event_init() is
> called. This means that pmu::event_init() must figure out which struct
> pmu the event was initialised from. This makes it difficult to
> consolidate common event initialisation code for similar PMUs, and
> very difficult to implement drivers for PMUs which can have multiple
> instances (e.g. a USB controller PMU, a GPU PMU, etc).
> 
> This patch sets the 'pmu' field before initialising the event, allowing
> event init code to identify the struct pmu instance easily. In the
> event of failure to initialise an event, the event is destroyed via
> kfree() without calling perf_event::destroy(), so this shouldn't
> result in bad behaviour even if the destroy field was set before
> failure to initialise was noted.

I thought there was a reason for things being the way they are, but
since I can't seem to recollect and your argument does make sense to me
I've merged it.

Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:perf/core] perf: provide PMU when initing events
  2011-08-11 11:31 [PATCH] perf: provide PMU when initing events Mark Rutland
  2011-08-11 11:43 ` Peter Zijlstra
@ 2011-08-14 15:54 ` tip-bot for Mark Rutland
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Mark Rutland @ 2011-08-14 15:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, will.deacon,
	mark.rutland, tglx, mingo

Commit-ID:  7e5b2a01d2ca2eae4ef913b59f84341f9a70e206
Gitweb:     http://git.kernel.org/tip/7e5b2a01d2ca2eae4ef913b59f84341f9a70e206
Author:     Mark Rutland <mark.rutland@arm.com>
AuthorDate: Thu, 11 Aug 2011 12:31:20 +0100
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Sun, 14 Aug 2011 11:53:05 +0200

perf: provide PMU when initing events

Currently, an event's 'pmu' field is set after pmu::event_init() is
called. This means that pmu::event_init() must figure out which struct
pmu the event was initialised from. This makes it difficult to
consolidate common event initialisation code for similar PMUs, and
very difficult to implement drivers for PMUs which can have multiple
instances (e.g. a USB controller PMU, a GPU PMU, etc).

This patch sets the 'pmu' field before initialising the event, allowing
event init code to identify the struct pmu instance easily. In the
event of failure to initialise an event, the event is destroyed via
kfree() without calling perf_event::destroy(), so this shouldn't
result in bad behaviour even if the destroy field was set before
failure to initialise was noted.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1313062280-19123-1-git-send-email-mark.rutland@arm.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/events/core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index d4c8542..adc3ef3 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5716,6 +5716,7 @@ struct pmu *perf_init_event(struct perf_event *event)
 	pmu = idr_find(&pmu_idr, event->attr.type);
 	rcu_read_unlock();
 	if (pmu) {
+		event->pmu = pmu;
 		ret = pmu->event_init(event);
 		if (ret)
 			pmu = ERR_PTR(ret);
@@ -5723,6 +5724,7 @@ struct pmu *perf_init_event(struct perf_event *event)
 	}
 
 	list_for_each_entry_rcu(pmu, &pmus, entry) {
+		event->pmu = pmu;
 		ret = pmu->event_init(event);
 		if (!ret)
 			goto unlock;
@@ -5849,8 +5851,6 @@ done:
 		return ERR_PTR(err);
 	}
 
-	event->pmu = pmu;
-
 	if (!event->parent) {
 		if (event->attach_state & PERF_ATTACH_TASK)
 			jump_label_inc(&perf_sched_events);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-14 15:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-11 11:31 [PATCH] perf: provide PMU when initing events Mark Rutland
2011-08-11 11:43 ` Peter Zijlstra
2011-08-14 15:54 ` [tip:perf/core] " tip-bot for Mark Rutland

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.