From: Frederic Weisbecker on
On Wed, Jun 16, 2010 at 07:48:00PM +0200, Peter Zijlstra wrote:
> > > +
> > > +struct pmu *perf_init_event(struct perf_event *event)
> > > +{
> > > + struct pmu *pmu;
> > > + int idx;
> > > +
> > > + idx = srcu_read_lock(&pmus_srcu);
> > > + list_for_each_entry_rcu(pmu, &pmus, entry) {
> > > + int ret = pmu->event_init(event);
> > > + if (!ret)
> > > + break;
> > > + if (ret != -ENOENT) {
> > > + pmu = ERR_PTR(ret);
> > > + break;
> > > }
> > > - pmu = &perf_ops_generic;
> > > - break;
> > > }
> > > + srcu_read_unlock(&pmus_srcu, idx);
> >
> >
> >
> > This could use a simple mutex instead of a spinlock + srcu_sync on
> > writer and srcu on reader.
>
> Right, that spinlock needs to be a mutex for sure, a later patch adds an
> allocation under it.
>
> But even with a mutex we need srcu_sync in there to sync against the
> readers.
>
> > That doesn't matter much that said. What I don't understand is
> > why we need to synchronize the writers. Walking the list with
> > list_*_rcu() looks justified once we support boot events, but
> > until then...
>
> Well, the typical unregister user would be a module, if you unregister
> and then dealloc the struct pmu by unloading the module a reader might
> still see a reference to it if you don't srcu_sync it.


Ok, I see what you mean.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Peter Zijlstra on
On Fri, 2010-06-18 at 09:31 +1000, Paul Mackerras wrote:
>
> > @@ -1011,7 +1001,7 @@ static int hw_perf_cache_event(u64 confi
> > return 0;
> > }
> >
> > -struct pmu *hw_perf_event_init(struct perf_event *event)
> > +static int power_pmu_event_init(struct perf_event *event)
>
> How does power_pmu_event_init ever get called now? I don't see any
> other references to it in the patch. Should struct pmu have a
> reference to it?

Uhm yeah.. looks like that went pear-shaped. Fixed it.

---
Index: linux-2.6/arch/powerpc/kernel/perf_event.c
===================================================================
--- linux-2.6.orig/arch/powerpc/kernel/perf_event.c
+++ linux-2.6/arch/powerpc/kernel/perf_event.c
@@ -1125,6 +1125,7 @@ static int power_pmu_event_init(struct p
}

struct pmu power_pmu = {
+ .event_init = power_pmu_event_init,
.enable = power_pmu_enable,
.disable = power_pmu_disable,
.read = power_pmu_read,

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Frederic Weisbecker on
On Thu, Jun 24, 2010 at 04:28:09PM +0200, Peter Zijlstra wrote:
> + if (bp->attr.type != PERF_TYPE_BREAKPOINT)
> + return -ENOENT;
> +
> + err = register_perf_hw_breakpoint(bp);
> + if (err)
> + return err;
> +
> + bp->destroy = bp_perf_event_destroy;



Seems it would make sense to also have destroy in the pmu, it's the same
along every events in the same class right?

But this can be for later.


> +static LIST_HEAD(pmus);
> +static DEFINE_MUTEX(pmus_lock);
> +static struct srcu_struct pmus_srcu;
> +
> +int perf_pmu_register(struct pmu *pmu)
> +{
> + mutex_lock(&pmus_lock);
> + list_add_rcu(&pmu->entry, &pmus);
> + mutex_unlock(&pmus_lock);
> +
> + return 0;
> +}
> +
> +void perf_pmu_unregister(struct pmu *pmu)
> +{
> + mutex_lock(&pmus_lock);
> + list_del_rcu(&pmu->entry);
> + mutex_unlock(&pmus_lock);
>
> - atomic_inc(&perf_swevent_enabled[event_id]);
> - event->destroy = sw_perf_event_destroy;
> + synchronize_srcu(&pmus_srcu);
> +}
> +
> +struct pmu *perf_init_event(struct perf_event *event)
> +{
> + struct pmu *pmu = NULL;
> + int idx;
> +
> + idx = srcu_read_lock(&pmus_srcu);
> + list_for_each_entry_rcu(pmu, &pmus, entry) {
> + int ret = pmu->event_init(event);
> + if (!ret)
> + break;
> + if (ret != -ENOENT) {
> + pmu = ERR_PTR(ret);
> + break;
> }
> - pmu = &perf_ops_generic;
> - break;
> }
> + srcu_read_unlock(&pmus_srcu, idx);
>
> return pmu;
> }



I'm still not sure why all this locking is needed. We don't even
support pmus in modules.

Is there something coming soon that will use this?
I remember something about KVM.

And who will have to use srcu? It seems the event fastpath would
be concerned, right? Will that have an impact on the performances?



> @@ -5743,15 +5742,15 @@ perf_cpu_notify(struct notifier_block *s
> {
> unsigned int cpu = (long)hcpu;
>
> - switch (action) {
> + switch (action & ~CPU_TASKS_FROZEN) {
>
> case CPU_UP_PREPARE:
> - case CPU_UP_PREPARE_FROZEN:
> + case CPU_DOWN_FAILED:
> perf_event_init_cpu(cpu);
> break;
>
> + case CPU_UP_CANCELED:
> case CPU_DOWN_PREPARE:
> - case CPU_DOWN_PREPARE_FROZEN:
> perf_event_exit_cpu(cpu);
> break;



That doesn't seem to be related to this patch initial topic.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Peter Zijlstra on
On Mon, 2010-06-28 at 15:21 +0200, Frederic Weisbecker wrote:
> On Thu, Jun 24, 2010 at 04:28:09PM +0200, Peter Zijlstra wrote:
> > + if (bp->attr.type != PERF_TYPE_BREAKPOINT)
> > + return -ENOENT;
> > +
> > + err = register_perf_hw_breakpoint(bp);
> > + if (err)
> > + return err;
> > +
> > + bp->destroy = bp_perf_event_destroy;

> Seems it would make sense to also have destroy in the pmu, it's the same
> along every events in the same class right?
>
> But this can be for later.

Ah, indeed.

> > +static LIST_HEAD(pmus);
> > +static DEFINE_MUTEX(pmus_lock);
> > +static struct srcu_struct pmus_srcu;
> > +
> > +int perf_pmu_register(struct pmu *pmu)
> > +{
> > + mutex_lock(&pmus_lock);
> > + list_add_rcu(&pmu->entry, &pmus);
> > + mutex_unlock(&pmus_lock);
> > +
> > + return 0;
> > +}
> > +
> > +void perf_pmu_unregister(struct pmu *pmu)
> > +{
> > + mutex_lock(&pmus_lock);
> > + list_del_rcu(&pmu->entry);
> > + mutex_unlock(&pmus_lock);
> >
> > - atomic_inc(&perf_swevent_enabled[event_id]);
> > - event->destroy = sw_perf_event_destroy;
> > + synchronize_srcu(&pmus_srcu);
> > +}
> > +
> > +struct pmu *perf_init_event(struct perf_event *event)
> > +{
> > + struct pmu *pmu = NULL;
> > + int idx;
> > +
> > + idx = srcu_read_lock(&pmus_srcu);
> > + list_for_each_entry_rcu(pmu, &pmus, entry) {
> > + int ret = pmu->event_init(event);
> > + if (!ret)
> > + break;
> > + if (ret != -ENOENT) {
> > + pmu = ERR_PTR(ret);
> > + break;
> > }
> > - pmu = &perf_ops_generic;
> > - break;
> > }
> > + srcu_read_unlock(&pmus_srcu, idx);
> >
> > return pmu;
> > }
>
>
>
> I'm still not sure why all this locking is needed. We don't even
> support pmus in modules.
>
> Is there something coming soon that will use this?
> I remember something about KVM.

Possibly, not sure. We could put the unregister thing in a later patch,
but I wanted to make sure it was sanely possibly and its only a few
lines of code.

> And who will have to use srcu? It seems the event fastpath would
> be concerned, right? Will that have an impact on the performances?

Only event creation like above (perf_init_event) will have to use SRCU,
so not really a hot path.

> > @@ -5743,15 +5742,15 @@ perf_cpu_notify(struct notifier_block *s
> > {
> > unsigned int cpu = (long)hcpu;
> >
> > - switch (action) {
> > + switch (action & ~CPU_TASKS_FROZEN) {
> >
> > case CPU_UP_PREPARE:
> > - case CPU_UP_PREPARE_FROZEN:
> > + case CPU_DOWN_FAILED:
> > perf_event_init_cpu(cpu);
> > break;
> >
> > + case CPU_UP_CANCELED:
> > case CPU_DOWN_PREPARE:
> > - case CPU_DOWN_PREPARE_FROZEN:
> > perf_event_exit_cpu(cpu);
> > break;
>
>
>
> That doesn't seem to be related to this patch initial topic.

Ah indeed, that needs to go live in its own patch.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Frederic Weisbecker on
On Mon, Jun 28, 2010 at 05:16:37PM +0200, Peter Zijlstra wrote:
> > > }
> > > + srcu_read_unlock(&pmus_srcu, idx);
> > >
> > > return pmu;
> > > }
> >
> >
> >
> > I'm still not sure why all this locking is needed. We don't even
> > support pmus in modules.
> >
> > Is there something coming soon that will use this?
> > I remember something about KVM.
>
> Possibly, not sure. We could put the unregister thing in a later patch,
> but I wanted to make sure it was sanely possibly and its only a few
> lines of code.



Ok.


> > And who will have to use srcu? It seems the event fastpath would
> > be concerned, right? Will that have an impact on the performances?
>
> Only event creation like above (perf_init_event) will have to use SRCU,
> so not really a hot path.



Ah I see. The event itself is synchronized against the fast-path using rcu.
And then pmus themselves would be synchronized against events. Right
that makes sense.

But then why RCU (or SRCU, whatever)? I mean parent event creation is
quite rare. And child events won't need to be synchronized as far as the parent
keeps a reference to the pmu.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/