Wednesday, January 15, 2014

Timers and Time Management

When do we need absolute time and when do we need relative time ?

Absolute time is used by the kernel to know the exact time of the day whereas relative time is used by kernel when we need schedule some event for the future(after a fixed time in future, say 10 seconds).For absolute time we have an hardware called RTC(real time clock) whereas to manage relative time we have the hardware called system timer.


How does the Kernel synchronize its timing of events?

To help kernel we have our friend System Timer Hardware. The system timer is preprogrammed to work at a certain frequency. In case of ARM and X86 it is 100 HZ. It means that the system timer issues 100 interrupts in one second to the CPU. These interrupts are also called ticks. We can get the value of system up time by knowing the value number of ticks received by the processor till now.The kernel also knows the frequency of system timer, so it also knows the interval in which it is receiving system timer interrupts. This gives the kernel the fair idea of the time and it helps it to sync events.



What are Jiffies?

They are the global variables that hold the number of ticks that have occurred since the system booted. On boot , the system initializes it to zero and is incremented on receipt of each system timer interrupt.Since there are Hz timer interrupt in a second therefore there are Hz jiffies incremented per second of system time.





  • The jiffies variable is declared in <linux/jiffies.h> 
  • extern unsigned long volatile jiffies;
  • Conversion formula--- jiffies=seconds*Hz.

  • How jiffies are stored internally?
    • The jiffies variable has always been an unsigned long, and therefore 32 bits in size on 32-bit architectures and 64-bits on 64-bit architectures.
    • With a tick rate of 100, a 32-bit jiffies variable would overflow in about 497 days.
    • With HZ increased to 1000, however, that overflow now occurs in just 49.7 days! 
    • If jiffies were stored in a 64-bit variable on all architectures, then for any reasonable HZ value the jiffies variable would never overflow in anyone’s lifetime.
    • A second variable is also defined in <linux/jiffies.h>:          extern u64 jiffies_64;
    • jiffies = jiffies_64;
    • jiffies variable becomes the lower 32 bit of jiffies_64 variable
    • by accessing the lower 32 bits of the jiffies_64 variable we get the value of our jiffies.
    • The function get_jiffies_64() can be used to read the full 64-bit value though such a need is rare.
    • On 64-bit architectures, jiffies_64 and jiffies refer to the same thing. Code can either read jiffies or call get_jiffies_64() as both actions have the same effect.
    • For a 32-bit unsigned integer, the maximum value of jiffy count is 2^32 – 1.Thus, a possible 4294967295 timer ticks can occur before the tick count overflows.
    • When the tick count is equal to this maximum and it is incremented, it wraps around to zero.





    15 comments:

    1. Valuable info. Lucky me I discovered your web site by accident, and I
      am surprised why this accident did not took place earlier!
      I bookmarked it.

      Review my webpage ... Beats By Dre

      ReplyDelete
    2. This self-directed IRA guide to investments covers popular choices like, real estate,
      gold, discount paper, tax liens, and private equity. Rare coins are not ideal investments with
      any IRA however there are several other methods to invest
      in gold using this type of account. Most of
      the time, individuals who are interested in committing big
      amounts of money on secure commodities will often recommend a gold Individual Retirement Account because it not only
      gives individuals with a good chance for their financial
      stability, but also that the price of gold is known to be steadily rising.


      My web-site :: youtube.com/watch?v=uEyBPzQqeUM

      ReplyDelete
    3. You could definitely see your skills in the work
      you write. The sector hopes for even more passionate writers such as you who are not
      afraid to say how they believe. At all times go after your heart.


      Here is my site funny cake topper

      ReplyDelete
    4. Thank you for the good writeup. It in fact was a amusement account it.
      Look advanced to more added agreeable from you! By the way,
      how could we communicate?

      Visit my site ... merry

      ReplyDelete
    5. Everything wrote was very reasonable. However, think on this, suppose
      you composed a catchier post title? I ain't saying your information isn't solid., however what if you added a title that grabbed a person's attention? I mean "Timers and Time Management"
      is kinda boring. You ought to peek at Yahoo's front page and
      watch how they create article headlines to grab people to click.
      You might try adding a video or a pic or two to grab readers interested about what you've written. Just my opinion, it would bring your website a little livelier.


      My homepage: clash of clans hack

      ReplyDelete
    6. Wow, this article is nice, my younger sister is analyzing these kinds of things,
      thus I am going to let know her.

      Here is my page clash of clans

      ReplyDelete
    7. When I initially commented I seem to have clicked on the -Notify me when new comments are added- checkbox and now every time
      a comment is added I recieve 4 emails with the same comment.

      There has to be an easy method you can remove me from that service?
      Thanks!

      Feel free to visit my blog post :: clash

      ReplyDelete
    8. Good replies in return of this query with firm arguments and
      explaining all regqrding that.

      My website: team task management

      ReplyDelete
    9. I'm curious tto find out what blog platform you have been using?
      I'm having some minor security problems with my latest website and
      I'd like to find something more secure. Do you have any solutions?


      Here is my blog online to do list

      ReplyDelete
    10. Woah! I'm really digging the template/theme of this site.
      It's simple, yet effective. A lot of times it's difficult too get that "perfect balance" between user friendliness and appearance.
      I must say you have done a very god jjob with this. Also,
      the blog loads super quick forr me on Chrome. Excellent Blog!


      Have a look at my weblog :: to do list software

      ReplyDelete
    11. Hey! Quick queston that's completely off topic. Do you know how to make
      your site mobile friendly? My blog looks weird whe browsing from my iphone.
      I'm trying to find a template orr plugin that might bbe able to fix this problem.
      If you have any suggestions, please share.Thanks!

      my web-site team task management (http://kristopherskott.com/)

      ReplyDelete
    12. Nice! But what's the deal with everyone at the end of their comment posting their blogs link?

      ReplyDelete
      Replies
      1. looks like they wanna promote their sites ;)

        Delete
      2. Pathetic spammers that's all. Hover over the links and check their destination.

        Delete
    13. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! schedule maker

      ReplyDelete