DPDK patches and discussions
 help / color / mirror / Atom feed
* Ring algorithm with fewer cache misses
@ 2023-06-27  9:35 Morten Brørup
  2023-06-27 10:41 ` Konstantin Ananyev
  0 siblings, 1 reply; 2+ messages in thread
From: Morten Brørup @ 2023-06-27  9:35 UTC (permalink / raw)
  To: honnappa.nagarahalli, konstantin.ananyev, bruce.richardson, Gavin Hu; +Cc: dev

Hi Honnappa, Konstantin, Bruce and Gavin,

You might find this ring algorithm optimization article interesting:
https://rigtorp.se/ringbuffer/


It adds the following optimization:

The single-producer put() operation keeps a cache of the consumer's index. If the cached consumer index indicates that there was still sufficient room in the ring after the previous put() operation, it doesn't need to fetch the actual consumer index, and thus avoids a potential L1 cache miss (because the actual consumer index is written by the consumer threads).

If the cached index doesn't indicate that there is sufficient room in the ring, the operation behaves like without the optimization, i.e. it proceeds to fetch the actual consumer index (and writes it to its cache) and determines if there is sufficient room in the ring.


Similarly, the single-consumer get() operation caches the producer's index to determine if there were still sufficient objects present in the ring after the previous get() operation.


Med venlig hilsen / Kind regards,
-Morten Brørup



^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: Ring algorithm with fewer cache misses
  2023-06-27  9:35 Ring algorithm with fewer cache misses Morten Brørup
@ 2023-06-27 10:41 ` Konstantin Ananyev
  0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Ananyev @ 2023-06-27 10:41 UTC (permalink / raw)
  To: Morten Brørup, honnappa.nagarahalli, bruce.richardson, Gavin Hu; +Cc: dev


Hi Morten,
 
> Hi Honnappa, Konstantin, Bruce and Gavin,
> 
> You might find this ring algorithm optimization article interesting:
> https://rigtorp.se/ringbuffer/
> 
> 
> It adds the following optimization:
> 
> The single-producer put() operation keeps a cache of the consumer's index. If the cached consumer index indicates that there was still
> sufficient room in the ring after the previous put() operation, it doesn't need to fetch the actual consumer index, and thus avoids a
> potential L1 cache miss (because the actual consumer index is written by the consumer threads).
> 
> If the cached index doesn't indicate that there is sufficient room in the ring, the operation behaves like without the optimization, i.e. it
> proceeds to fetch the actual consumer index (and writes it to its cache) and determines if there is sufficient room in the ring.
> 
> 
> Similarly, the single-consumer get() operation caches the producer's index to determine if there were still sufficient objects present in
> the ring after the previous get() operation.
> 

Indeed, that sounds like an interesting idea and worth to explore.
Thinking a bit more - it probably could be extended to classic MP/MC case too -
If we can update cons/prod head and this cached value atomically (CAS64?).
Thanks
Konstantin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-27 10:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-27  9:35 Ring algorithm with fewer cache misses Morten Brørup
2023-06-27 10:41 ` Konstantin Ananyev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).