title: How is this Calculation working?
body: <p>I have come across this piece of code where nanoseconds since the epoc and since boot has been calculated but I didn't get how?</p>
  
  <p><a href="http://code.metager.de/source/xref/cloudius-systems/osv/arch/aarch64/arm-clock.cc#61" rel="nofollow">http://code.metager.de/source/xref/cloudius-systems/osv/arch/aarch64/arm-clock.cc#61</a></p>
  
  <pre><code> s64 arm_clock::uptime()  
  {
      u64 cntvct;
      asm volatile ("isb; mrs %0, cntvct_el0; isb; " : "=r"(cntvct) :: "memory");
  
      cntvct = ((__uint128_t)cntvct * NANO_PER_SEC) / this-&gt;freq_hz;
      return cntvct; 
  }
  </code></pre>
  
  <p>CNTVCT is cyclic counter register, why is the value of this register divided by CPU frequency and then multiplied by NANO_PER_SEC?</p>
  
  <p>Also, how can Time of day be derived from these nanoseconds?</p>