<div dir="ltr">(If you've been at the office yesterday, maybe I wouldn't have send the question ;-)<div><br></div><div>You've followed my line of thought (thinking that there's always one CPU active). In some cases I think all CPUs must be asleep (otherwise, my Android's battery would be draining even after I press the power button). Still, two consecutive calls to clock_getttime should give a reasonable result.</div>
<div><br></div><div>However, I can't find the place where the time is adjusted through the hardware clock.</div><div><br></div><div>The thing is, the only architecture I can see clocksource other than jiffies is s390[0], so I assume hardware internal clock is not used in many important architectures. We can only count on the jiffies counter.</div>
<div><br></div><div>The jiffies counter is incremented only by do_timer[1], which is scheduled to run do_timer, which runs on xtime_update, which seems to eventually runs inside an IRQ handler called in a certain frequency in some systems.</div>
<div><br></div><div>While looking at it, it seems that I found the mechanism I was looking for. It looks like the no_sched mechanism, simply lowers the CPU frequency , and calculates the jiffies according to the new frequency while the CPU is idle[2].</div>
<div><br></div><div>I still need to have a second look, but it looks like the CPU is always woken up to count jiffies, but when it's idle it woken up in lower frequencies, is aware to the fact it's idle, and thus is counting more jiffies per tick.</div>
<div><br></div><div>[0] clocksource_register usage: <a href="http://lxr.linux.no/linux+v3.13.5/+ident=61690701">http://lxr.linux.no/linux+v3.13.5/+ident=61690701</a></div><div>[1] jiffies_64 usage: <a href="http://lxr.linux.no/linux+v3.13.5/+ident=59277722">http://lxr.linux.no/linux+v3.13.5/+ident=59277722</a></div>
<div>[2] tick_nohz_* - <a href="http://lxr.linux.no/linux+v3.13.5/kernel/time/tick-sched.c#L52">http://lxr.linux.no/linux+v3.13.5/kernel/time/tick-sched.c#L52</a></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Mar 26, 2014 at 6:45 AM, Shachar Shemesh <span dir="ltr"><<a href="mailto:shachar@shemesh.biz" target="_blank">shachar@shemesh.biz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

  
    
    
  
  <div style="direction:ltr" bgcolor="#FFFFFF" text="#000000">
    <div>Oops!<br>
      <br>
      The "one cpu always active" relates to the "full" tickless, not to
      the idle tickless. Please disregard that answer, except the use of
      the hardware clocks. I believe it is still valid, but I'll need to
      look at the source code.<br>
      <br>
      Shachar<div><div class="h5"><br>
      <br>
      On 26/03/14 06:38, Shachar Shemesh wrote:<br>
    </div></div></div>
    <blockquote type="cite"><div><div class="h5">
      
      
      <div>So I answer this here, and then I get
        a visit in the office with the same question... :-)<br>
        <br>
        On 25/03/14 23:04, Elazar Leibovich wrote:<br>
      </div>
      <blockquote type="cite">
        <div dir="ltr">
          <div>(I'm talking now about MONOTONIC_CLOCK_RAW, not taking
            NTP adjustment into account)</div>
          <div><br>
          </div>
          To my understanding, the basic time counting mechanism at the
          Linux kernel, is the jiffies counter. The way it counts time,
          is by leveraging a CPU interrupt happening at a certain known
          frequency. Every time this interrupt occurs, the interrupt
          handler would increment a counter. By multiplying this counter
          with the IRQ's frequency, we can estimate how much time
          passed.
          <div> <br>
          </div>
          <div>Now, to my understanding, the NO_HZ_IDLE=y configuration,
            would prevent any interrupt on idle CPUs. <br>
          </div>
        </div>
      </blockquote>
      At least for the time being, this does not mean what you think it
      means. See <a href="http://lwn.net/Articles/549580/" target="_blank">http://lwn.net/Articles/549580/</a><br>
      <br>
      Even in full tickless mode (properly referred to as "full"
      tickless mode), the boot CPU is still on a counter. Full
      ticklessness is still some way away.<br>
      <br>
      Even when we do achieve that lofty goal, most CPUs have a hardware
      counter that counts the time. Just like NAPI for network moved
      from an interrupt mode to polling mode for performance's sake, so
      we can do here.<br>
      <blockquote type="cite">
        <div dir="ltr"><br>
          <div>So to my understanding, if all CPUs are idle, nothing is
            going to run on any CPU.</div>
          <div><br>
          </div>
        </div>
      </blockquote>
      No.<br>
      <blockquote type="cite">
        <div dir="ltr">
          <div>Who would count jiffies then? How can we be sure how much
            time passed with no hardware clock (as it is the case in
            some systems), and all CPUs asleep?</div>
        </div>
      </blockquote>
      When we finally move into the utopian full tickless mode, jiffies
      will lose their original meaning. In full tickless mode, there is
      no base frequency for the clock. As such, jiffies become an
      arbitrary number based on which you can decide how much time has
      passed, and can be set to whatever. How low to set them becomes a
      question of power management, then.<br>
      <br>
      Shachar<br>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
Linux-il mailing list
<a href="mailto:Linux-il@cs.huji.ac.il" target="_blank">Linux-il@cs.huji.ac.il</a>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a>
</pre>
    </blockquote>
    <br>
  </div>

<br>_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
<br></blockquote></div><br></div>