Re: [PATCH 4/6] kvm tools: Add rwlock wrapper

Avi Kivity
2011-05-28T18:12:26Z

On 05/27/2011 02:07 PM, Ingo Molnar wrote:
> * Ingo Molnar<mingo@elte.hu> wrote:
>
> > > This code is very much tied with the kernel scheduler. [...]
> >
> > It would not be particularly complex to enable user-space to
> > request a callback on context switch events.
> >
> > I was thinking on and off about allowing perf events to generate a
> > per sampling event notification signal on specific events, such as
> > page faults or context switches.
>
> I was thinking about that on and off so loudly that Peter implemented
> it long ago via fasync support on the perf event fd! :-)
>
> So if you set a notification signal via fcntl(F_SETOWN) on the
> scheduler context switch event fd, the user-space RCU code will get a
> signal on every context switch.
>

Context switches are completely uninteresting for userspace rcu:

rcu_read_lock();
---> context switch

have we learned anything from that? no. User code is always
preemptible and migratable. If rcu_read_lock() prevented migration
somehow, then we'd know that a context switch means we've started a
grace period for this thread. But it doesn't, so we don't.

What's needed are explicit notifications about grace periods. For the
vcpu threads, calling KVM_VCPU_RUN seems like a good point. For I/O
threads, completion of processing of an event is also a good point.

--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.