Re: [RFC][PATCH 3/8] perf: register pmu implementations

From: Frederic Weisbecker
Date: Fri Jun 18 2010 - 00:52:13 EST


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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/