Re: [PATCH v4 1/7] locking/pvqspinlock: Unconditional PV kick with _Q_SLOW_VAL

From: Peter Zijlstra
Date: Mon Aug 03 2015 - 15:56:51 EST


On Mon, Aug 03, 2015 at 12:09:42PM -0700, Davidlohr Bueso wrote:
> On Mon, 2015-08-03 at 20:37 +0200, Peter Zijlstra wrote:
> > OK, so there's no 'fix'? The patch claims we can loose a wakeup and I
> > just don't see how that is true.
>
> Taking another look, I think you could hit something like this:
>
> CPU0 (lock): CPU1 (unlock):
> pv_wait_head __pv_queued_spin_unlock
> <load ->state> [bogus ->state != halted]

I don't think this can happen, see below, IF you take the slow path, you
_must_ see halted.

> <spin> smp_store_release(&l->locked, 0);
>
> WRITE_ONCE(pn->state, vcpu_halted);
> pv_wait(&l->locked, _Q_SLOW_VAL); if (->state == vcpu_halted)
> pv_kick(node->cpu); <-- missing wakeup, never called
>
> So basically you can miss a wakeup if node->state load is done while the
> locking thread is spinning and hasn't gotten a chance to update the
> state to halted. That would also imply that it occurs right when the
> threshold limit is about to be reached.

pv_wait_head() __pv_queued_spin_unlock()

[S] node->state = halted
[S] hash(lock, node)
MB
[S] ->locked = SLOW
MB
[L] ->locked == SLOW
RMB
[L] node = unhash(lock)
[L] node->state == halted
RELEASE
[S] ->locked = 0

kick(node->cpu)
CLI
[L] ->locked

If we don't see SLOW, nothing to be done. If we do, we _must_ then also
see ->state == halted and will kick.

And note that the load of node->state _cannot_ be pushed up further, it
depends on the load of node, which in turn depends on the load of
->locked.

So I'm still not seeing it. You cannot miss a kick.
--
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/