4 ms·
Gor Nishanov, one of the authors, talks about this in his CppCon2018 talk https://youtu.be/j9tlJAqMV7U https://youtu.be/j9tlJAqMV7U (jump to ~12:33 to skip back
by akubera 8y ago
Gor Nishanov, one of the authors, talks about this in his CppCon2018 talk https://youtu.be/j9tlJAqMV7U https://youtu.be/j9tlJAqMV7U (jump to ~12:33 to skip background).
It amounts to using CPU prefetch instructions with C++ coroutines to simulate hyperthreading in software by scheduling instructions around cache misses (but is potentially better than hyperthreads because it's not limited to 2/core)
- deleted 8y ago[deleted]
- quotemstr 8y ago> but is potentially better than hyperthreads because it's not limited But also potentially worse because hyperthreads schedule only on actual memory waits, whereas this approach puts a suspension point after each prefetch whether or not the target is actually in cache.
- int0x80 8y agoI haven't read the article or video. But regarding prefetching triggerd by software (programmer) instead of by the hw, this is a very informative read, with a lot of numbers and tests/profiles: https://lwn.net/Articles/444336/ https://lwn.net/Articles/444346/
- tuukkah 8y agoYour links show with benchmarks that software prefetching is not always useful, the example being a for loop to traverse a linked list in the Linux kernel. However, the article at hand shows with benchmarks that software prefetching can be very beneficial in common algorithms such as hash probe, binary search, Masstree and Bw-tree, even when concurrency is implemented in a straight-forward way using (stackless) coroutines.
- int0x80 8y agoThe links are not only about a loop. The general conclusion is that making better informed decisions about whether to prefecth or not is very hard and that the CPU will have most of the time way more information to make a good informed decision. It also says that unless you proove by benchmarks that it makes sense, it is probably wrong. Now. This is of course a general case. If you control the whole algo and data structures during the execution, a well crafted prefectch /can/ be beneficial. Again, the general idea of the links I posted is that /generally/ the CPU has more info of the /overall/ system state to make a correct prefetching choice. I think that info/links are usefull/interesting even if they do not apply to the specific case in TFA. Clarifying a bit more: I didn't post that to contradict the article but just to provide a bit of related info.