Jiffies counter returns an unsigned integer of size four bytes. when the counter reaches maximum value then it restarts from 0 again. I’ll subtract the latest value with the old value to get the duration. So how should i consider for a case such that when the old value is of maximum value and new value is more than zero so that I’ll get wrong duration?
Jiffies counter returns an unsigned integer of size four bytes. when the counter reaches
Share
You don’t have to do anything, you’ll have the correct duration (as long as you make all your calculations using four bytes unsigned integers). That’s the magic of integer values implemented as fixed-width binary arithmetic.
Here is an example with 8 bits unsigned integers. You can actually see that even when there’s overflow, the difference is still valid.
Your single problem comes when the duration is not small compared to the maximum value of the counter, i.e. when it can be larger than the half of the maximum value.