About Jiffies Wrap and Time_after,time_before

Source: Internet
Author: User

There are many variables used in the system to record a monotonically increasing reality, a typical two, one is the serial number of TCP, the other is jiffies, but because the numbers represented in the computer are bounded and unbounded, so any number can not achieve the full meaning of monotonically increasing, they are just around the circle, like a clock , the range is the finite number, the cycle. In fact, whether it is TCP serial number or jiffies, all face a kind of problem, is wrapping the problem. Like when we watch the clock, 1 o'clock, before 11, or after 11? In fact, this question is not as easy to answer as imagined.
We use the char type to describe the solution of this problem briefly. Char is only 8 bits, binary from 00000000 to 11111111, if a char represents jiffies, then when its value has reached 11111111, it will face a jump, that is, return to 0, because 11111111 plus 1, Will get 100000000, but char only 8 bits, resulting in the highest bit overflow, the result is 00000000, this is the 0-point jump, the essential reason is that in the vicinity of the jumping point, the range is not continuous. 11111111 of the decimal is 255, obviously and 0 is not sequential.
However, 11111111 can represent 255, but also 1, while 1 and 0 are continuous! We know that the storage of the data in the computer is not the symbol, the symbol is only in the calculation of the time according to different instructions to give different interpretations, so just need to think of the unsigned jiffies as a signed number, you can solve the jump problem, it is clear that 0 is 1 behind, which is to say, 0 behind 255. Interpreting a signed number as an unsigned number is only a different way of interpreting it, and has no effect on the representation of the data, it only affects the calculation. The signed calculation instruction shifts the range axis to the left by half the range width, thus turning 0 points into a midpoint instead of the left endpoint, solving the 0-point transition problem. However, this only in the latter half of the range of space effective, that is, for char, the system can only correctly recognize the jump after 128, if you test 129 and 1 water more forward, the answer is 129, however if you test 127 and 1 who is more forward, the answer is 1! But this is enough, because for the comparison of Jiffies, the basic is near worth comparison, no one will compare the present and thousands of tens of thousands of years later time.
See Time_after,time_before macro for details.

About Jiffies Wrap and Time_after,time_before

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.