[dpdk-dev] A question of DPDK ring buffer

Olivier MATZ olivier.matz at 6wind.com
Tue Aug 20 10:22:04 CEST 2013


Hello Ben,

> OK, here is the question: Why DPDK has to maintain that public prod_tail
> structure? Is it really necessary to endure a while loop here?

If you remove this wait loop, you can trigger an issue. Imagine a case
where core 0 wants to add an object in the ring: it does the CAS,
modifying prod_head. At this time it is interrupted for some reason
(maybe by the kernel) before writing the object pointer in the ring,
and thus before the modification of prod_tail.

During this time, core 1 wants to enqueue another object: it does the
CAS, then writes the object pointer, then modifies prod_head (without
waiting the core 0 as we removed the wait loop).

Now the state ring is wrong: it shows 2 objects, but one object pointer
is invalid. If you try to dequeue the objects, it will return an
bad pointer.

Of course, the interruption by the kernel should be avoided as much as
possible, but even without beeing interrupted, a similar scenario can
occur if a core is slower than another to enqueue its data (due to a
cache miss for instance, or because the first core enqueues more
objects than the other).

To convince you, I think you can remove the wait loop and run the ring
test in app/test/test_ring.c, I suppose it won't work.

Regards,
Olivier


More information about the dev mailing list