Subject: Re: Queue with wait-free enqueue, blocking dequeue, splice

From: Mathieu Desnoyers <[email-masked]>
Date: Tue, 21 Oct 2014 12:02:38 +0000 (UTC)

----- Original Message -----
> From: "Mathieu Desnoyers" <[email-masked]>
> To: "Jesper Dangaard Brouer" <[email-masked]>
> Cc: "Paul E. McKenney" <[email-masked]>, [email-masked], "Jamal Hadi Salim" <[email-masked]>
> Sent: Monday, October 20, 2014 8:04:10 PM
> Subject: Re: Queue with wait-free enqueue, blocking dequeue, splice
> 
> ----- Original Message -----
> > From: "Jesper Dangaard Brouer" <[email-masked]>
> > To: "Mathieu Desnoyers" <[email-masked]>
> > Cc: [email-masked], "Paul E. McKenney" <[email-masked]>,
> > [email-masked], "Jamal Hadi Salim"
> > <[email-masked]>
> > Sent: Monday, October 20, 2014 10:02:37 AM
> > Subject: Re: Queue with wait-free enqueue, blocking dequeue, splice
> > 

[...]

> > 
> > AFAIK your queue implementation is a CAS-based, Wait-Free on enqueue,
> > but Lock-Free on dequeue with the potential for waiting/blocking on
> > a enqueue processes.
> >  I'm not 100% sure, that we want this behavior for the qdisc system.
> 
> It's actually xchg-based (not CAS-based). It is indeed wait-free
> in the strictest sense of the term on enqueue (at least on x86,
> some other arch implement xchg using ll/sc, which is not strictly
> wait-free).
> 
> On dequeue, it can busy-wait for a short while that the enqueue
> completes. Note that in kernel, since we disable preemption during
> enqueue, the dequeue does not have to ever block, just busy-looping
> is OK, since the longest thing that could nest over the enqueue
> is possibly an interrupt and softirq. So yes, I guess the dequeue
> would qualify as lock-free.

Scratch this last part about dequeue lock-freedom: dequeue can
busy-wait endlessly long if an enqueue is, for instance, interrupted
by a dequeue operation that would sit within an interrupt handler.
Dequeue is therefore not "lock-free". It is not even obstruction-free.

This just means that you need to be aware of this if you use dequeue
in an execution context that can interrupt enqueue.

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com