<div>Hi folks,</div><div><br></div><div>Is there anyone who has researched the mechanism of DPDK ring buffer by any chance? I was trying to understand the multi-producer and muti-consumer scenario, the CAS(compare and swap) operation is not an obstacle to me, and from what I can tell, the method which DPDK adopts is basically lock-free, not wait-free.</div><div><br></div><div>What troubles me is the last wait operation when each core has fulfilled its enqueued objects and then stop there waiting the public structure prod_tail to match its private per core structure prod_head. Only if public <span style="line-height: 1.5;">prod_tail</span><span style="line-height: 1.5;"> equals to its private </span><span style="line-height: 1.5;">prod_head, it will increase the </span><span style="line-height: 1.5;">public </span><span style="line-height: 1.5;">prod_tail to private prod_next. See below, from DPDK programmer guide.</span></div><div><span style="line-height: 1.5;"><br></span></div><div><img src="cid:D908D9B8@8064AB02.BAF21252.96F01252"></div><div><div><font color="#0000ff"><span class="Apple-tab-span" style="white-space:pre">      </span>/*</font></div><div><font color="#0000ff"><span class="Apple-tab-span" style="white-space:pre">        </span> * If there are other enqueues in progress that preceeded us,</font></div><div><font color="#0000ff"><span class="Apple-tab-span" style="white-space:pre">     </span> * we need to wait for them to complete</font></div><div><font color="#0000ff"><span class="Apple-tab-span" style="white-space:pre">   </span> */</font></div><div><font color="#0000ff"><span class="Apple-tab-span" style="white-space:pre">       </span>while (unlikely(r->prod.tail != prod_head))</font></div><div><font color="#0000ff"><span class="Apple-tab-span" style="white-space:pre">            </span>rte_pause();</font></div></div><div><br></div><div>The final position of public prod_tail is the same to public prod_head. That means they have reached to the initial state.</div><div><img src="cid:D908ECAB@8064AB02.BAF21252.96F01252"></div><div><br></div><div>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? I think in a circumstance of heavy workload, it might be very likely that a core enqueues its own data in advance, however, it needs to wait the others to finish enqueueing even though it already has nothing to do at that time. It seems to me that even if we remove the public prod_tail structure, the enqueue operation is still able to work. Because each core has known the exact enqueue position from its private prod_head and prod_next. In another word, we just need to assure the correctness of per core pointer and leave the rest of the enqueue work to that particular core. Those per core pointers they never overlap according to the CAS atomic operation, that is our assumption.</div><div><br></div><div>What do you reckon?</div><div><br></div><div>Regards,</div><div>Bob</div>