|
|
Subscribe / Log in / New account

Protecting control dependencies with volatile_if()

Protecting control dependencies with volatile_if()

Posted Jun 20, 2021 0:42 UTC (Sun) by xecycle (subscriber, #140261)
Parent article: Protecting control dependencies with volatile_if()

This sounds very similar to what the broken memory_order_consume is trying to do. Is that thing practically fixable?

Btw I feel a release order would be needed anyway on the write side, this form probably just exploits dependency order on the read side.


to post comments

Protecting control dependencies with volatile_if()

Posted Jun 20, 2021 12:08 UTC (Sun) by Bigos (subscriber, #96807) [Link] (1 responses)

The Linux kernel uses dependent READ_ONCE() in order to implement something akin to memory_order_consume. The assumption is that the compilers will never reorder instructions such as these due to there being a data dependency:

int* ptr = READ_ONCE(slot);
int value = READ_ONCE(ptr);

This article is about cases where there is no data dependency but there is a control dependency. AFAIK most weak-memory-model architectures respect such a dependency if there is a jump instruction in the middle, but the compiler must first not reorder the instructions itself and must actually generate a jump instruction (which is not always obvious as it could be lowered to a cmove-like instruction).

Regarding memory_order_consume (and [[carries_dependency]]), the problem is with ensuring that there is a dependency without involving the type system. If instead load(std::memory_order_consume) returned Dependent<T> and the compiler promised that loads using it are either data or control dependent on the original load then it would be a lot easier to define and implement. I think this is what the following is about:

http://wg21.link/P0750

Protecting control dependencies with volatile_if()

Posted Jun 21, 2021 5:40 UTC (Mon) by xecycle (subscriber, #140261) [Link]

Thanks, very informative; memory_order_consume was considered broken even before the day I first heard of it, so I didn't look into its details and never realized the distinction between data dependency and control dependency.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds