title: Why udelay and ndelay is not accurate in linux kernel?
body: <p>I make a function like this</p>
  
  <pre><code>trace_printk("111111");
  udelay(4000);
  trace_printk("222222");
  </code></pre>
  
  <p>and the log shows it's 4.01 ms , it'OK</p>
  
  <p>But when i call like this</p>
  
  <pre><code>trace_printk("111111");
  ndelay(10000);
  ndelay(10000);
  ndelay(10000);
  ndelay(10000);
  ....
  ....//totally 400 ndelay calls
  trace_printk("222222");
  </code></pre>
  
  <p>the log will shows 4.7 ms. It's not acceptable.
  Why the error of ndelay is so huge like this?</p>
  
  <p>Look deep in the kernel code i found the implemention of this two functions</p>
  
  <pre><code>void __udelay(unsigned long usecs)
  {
      __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
  }
  
  void __ndelay(unsigned long nsecs)
  {
      __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
  }
  </code></pre>
  
  <p>I thought udelay will be 1000 times than ndelay, but it's not, why?</p>