0

In Linux, the xtime variable (a structure of type timespec inside the Linux kernel) stores the current time and date. It has two fields - tv_sec, that stores the number of seconds since January 1, 1970, and tv_nsec, storing the number of nanoseconds that have elapsed within the last second.

The value of xtime is updated as part of the interrupt handling routine for the interrupt generated by the Programmable Interval Timer on board. By default, the Linux kernel programs this to happen every 1 millisecond (called a tick).

I understand that the kernel depends on the interrupt for a plenty of other stuff besides updating the system clock, but why we actually edit the xtime variable on every tick? Isn't it pointless, as we will be basically overwriting it with the same value?

programings
  • 239
  • 1
  • 11
  • It needs to be always current. On what condition would it be worth the cost of a branch to avoid updating it? – Dan D. Jan 05 '19 at 03:51

1 Answers1

0

User programs get current time and date from xtime variable,so it needs to be always updated