title: CPU usage discrepancy
body: <p>I have a program for which I need to track how much CPU it is using. Inside the program, I do that by calling <code>clock_gettime(CLOCK_THREAD_CPUTIME_ID,...)</code> once every second and reporting the result.</p>
  <p>I also monitor that thread using the <code>top</code> command.</p>
  <p>While top claims that specific thread is taking 70%-90% of the CPU, <code>clock_gettime</code> only advances about 250ms each second (i.e. ~ 25% CPU usage).</p>
  <p>I am running on Ubuntu Linux 18.04, kernel 5.4.0-72-generic, on Intel X86_64.</p>
  <p>I'll add that I'm also measuring the wall clock time spent outside of my main <code>epoll</code>, i.e. - the wall clock time I'm idle. That shows that I spend ~80% of the time idling on the epoll (i.e. - more or less agrees with my in-thread measurement). On the other hand, I'm having some problems that seem to indicate too high CPU usage by the thread.</p>
  <p>What might be the cause of such a reporting discrepancy? Which one of the two shows the actual usage?</p>
  <p><strong>Clarification</strong>
  I'm using <code>htop</code>, and asking it to separately report different threads. The CPU usage is for the <em>thread</em> in question.</p>