|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Memory ordering question in the shutdown deferral code
Hi, On 23/09/2020 23:57, Stefano Stabellini wrote: On Mon, 21 Sep 2020, Julien Grall wrote:On 21/09/2020 13:55, Durrant, Paul wrote:(+ Xen-devel) Sorry I forgot to CC xen-devel. On 21/09/2020 12:38, Julien Grall wrote: Thank you for writing a simpler example. It allowed me to find a litmus (see [1]) and now I understood why it works. See more below. I think it is (theoretically) possible for thread#1 to be at 1) and about to do 2), while thread#2 goes ahead and does 1) 2) 3). Well it is not that theoritical :). There are many reasons where this situation can happen. To only cite a few:
- Threads may run on the same pCPUs
- The pCPU running the threads may get interrupted
- The data modified is not in the L1 cache, there will be delay to
access it.
By the time thread#1 does 2), thread#2 has already completed the entire sequence. If thread#2 has already done 2), and thread#1 is about to do 3), then I think we are guaranteed that thread#1 will see the new value of B. > Or is this the core of the issue we are discussing? No you are right. I got confused because smp_mb() doesn't guarantee when the write/read is completed. So I blindly assumed that the ordering would be done just at the processor level. Instead, the ordering is done at the innershareable level (e.g between all the processors) as we are using dmb ish. Assuming A and B are initialized to 0 and we are writing 1, then there is no way for both thread to read 0. In which case, the existing shutdown code is fine. Cheers,[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/memory-model/litmus-tests/SB+fencembonceonces.litmus -- Julien Grall
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |