Question: Why the definition of ULONG_CMP_LE is different with time_before?
Hi,
I noticed that the definition of ULONG_CMP_LE in rcupdate.h is different with time_before.
I can’t figure it out that why their definition is different. Does the two definition are the same thing?
Thanks,
Alan
Hi Alan,
The reason for a different implementation looks to be due to the fact that the C standard does not specify the result of an operation that
overflows a signed integer. This is described in lwn article: https://lwn.net/Articles/511259/ . On 32-bit systems, overflow would be common for counters used by RCU. So, RCU subsystem uses unsigned integers checks - ULONG_CMP_GE , ULONG_CMP_LT , to avoid any compiler optimization, which would cause results of these checks to have a different result, in the event of counter overflows.
Thanks
Neeraj
Quoted 11 lines · Alan Huang
Hi,
I noticed that the definition of
ULONG_CMP_LEinrcupdate.his different withtime_before.I can’t figure it out that why their definition is different. Does the two definition are the same thing?
Thanks,
Alan
Hi Neeraj,
Thank you for your explanation!
The lwn article is very helpful to me!
Thanks,
Alan
Quoted 18 lines
2023年4月17日 下午1:28,Neeraj Upadhyay <[email protected]> 写道:
Hi Alan,
The reason for a different implementation looks to be due to the fact that the C standard does not specify the result of an operation that
overflows a signed integer. This is described in lwn article: https://lwn.net/Articles/511259/ . On 32-bit systems, overflow would be common for counters used by RCU. So, RCU subsystem uses unsigned integers checks -ULONG_CMP_GE,ULONG_CMP_LT, to avoid any compiler optimization, which would cause results of these checks to have a different result, in the event of counter overflows.Thanks
NeerajQuoted 5 lines · Alan Huang
Hi,
I noticed that the definition ofULONG_CMP_LEinrcupdate.his different withtime_before. I can’t figure it out that why their definition is different. Does the two definition are the same thing? Thanks,
Alan