Skip to contentSkip to conversation

Question: Why the definition of ULONG_CMP_LE is different with time_before?

DISCUSSION Alan Huang 2 participants 3 messages Apr 16, 2023 – Apr 17, 2023 RCU

lore
Share & tools
lore

Alan Huang

author
#0 lore raw

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

#1 lore raw

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_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

author
#2 lore raw

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
Neeraj

Quoted 5 lines · Alan Huang

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