<div dir="ltr"><div dir="ltr" style="color:rgb(0,0,0);font-size:12.8px">Hey Shuai,<div><br></div><div>Are you pinning the thread to a single core? If not, can you check this (eg. using the taskset command)? I ask because we've seen timestamp counter variations across CPUs in that range in the past (tens of microseconds) on larger server machines. Although it is unlikely to be so prominent on a smaller desktop like the one you're using, it might be worth ruling out.</div><div><br></div><div>Thanks!</div></div><div class="" style="color:rgb(0,0,0);font-size:12.8px"></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 16, 2016 at 6:40 PM, Shuai Zhao <span dir="ltr"><<a href="mailto:zs673@york.ac.uk" target="_blank">zs673@york.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi<div><br></div><div>I found an interesting thing while I trying to get response time of tasks: The CPU time of a task (CLOCK_THREAD_CPUTIME_ID) accounts faster than wall clock (CLOCK_REALTIME) ! </div><div><br></div><div>I noticed that you use the same thing in the rtspin.c so I guess that you may know the answer.<br></div><div><br></div><div>I know that this is a question related to generic Linux or may be the cpu clock speed instead of litmus, but would you please have a look and help me?<br></div><div><br></div><div>The CPU I use is i7 6700k 4.0MHz. But the clock speed is actually 4006 MHz when I cat /proc/cpuinfo. </div><div><br></div><div>Here is the code:</div><div><br></div><div><div>/************* CPU cycle cosuming for 3 threads *************/</div><div>#define NUMS 500</div><div>static int num[NUMS];</div><div>static int loop_once(void) {</div><div><span style="white-space:pre-wrap"> </span>int i, j = 0;</div><div><span style="white-space:pre-wrap"> </span>for (i = 0; i < NUMS; i++)</div><div><span style="white-space:pre-wrap"> </span>j += num[i]++;</div><div><span style="white-space:pre-wrap"> </span>return j;</div><div>}</div><div>/************* CPU cycle cosuming END *************/</div><div><br></div><div>void* run(void *tcontext) {</div><div><span style="white-space:pre-wrap"> </span>struct timespec start, end, start1, end1, sleep = {0,10};</div><div><span style="white-space:pre-wrap"> </span>int i;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>exit_program = 0;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>do {</div><div><span style="white-space:pre-wrap"> </span>nanosleep(&sleep, NULL);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>clock_gettime(CLOCK_REALTIME, &start);</div><div><span style="white-space:pre-wrap"> </span>clock_gettime(CLOCK_THREAD_CPUTIME_ID, &start1);</div><div><br></div><div><br></div><div><span style="white-space:pre-wrap"> </span>for(i = 0; i < loop_times; i++)</div><div><span style="white-space:pre-wrap"> </span>loop_once();</div><div><br></div><div><br></div><div><span style="white-space:pre-wrap"> </span>clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end1);</div><div><span style="white-space:pre-wrap"> </span>clock_gettime(CLOCK_REALTIME, &end);<span style="white-space:pre-wrap"> </span></div><div><br></div><div><span style="white-space:pre-wrap"> </span></div><div><span style="white-space:pre-wrap"> </span>response_time[0][count_first] = (end.tv_sec * 1000000000 + end.tv_nsec) - (start.tv_sec * 1000000000 + start.tv_nsec);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>response_time[1][count_first] = (end1.tv_sec * 1000000000 + end1.tv_nsec) - (start1.tv_sec * 1000000000 + start1.tv_nsec);</div><div><br></div><div><br></div><div><span style="white-space:pre-wrap"> </span>/*finish the program */</div><div><span style="white-space:pre-wrap"> </span>count_first++;</div><div><span style="white-space:pre-wrap"> </span>if (count_first >= 10000)</div><div><span style="white-space:pre-wrap"> </span>exit_program = 1;</div><div><span style="white-space:pre-wrap"> </span>} while (exit_program != 1);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>return NULL;</div><div>}</div></div><div><br></div><div>I basically copies the code from rtspin.c here. In the program I get time stamps of the wall-clock and thread-cpu clock and then let the thread loops for a given times. Then I get time stamps again to check the differences between these two clocks (wallclock - threadcpuclock).</div><div><br></div><div>The difference I expect should be the interval of wall-clock always be bigger than thread cpu clock as there will be timer or reschedule interrupts.</div><div><br></div><div>But on my machine I got amazing results: with the increment of the loop_times, the thread-cpu clock will goes faster than wall clock and I got results like this: (clock 0 is wall clock and clock 1 is thread cpu clock)</div><div><br><img src="cid:ii_153807460e053329" alt="Inline images 1" width="422" height="562"><br><br></div><div>So we can see that the thread cpu clock goes faster than wall clock by 33191 nanosecond when we loop 100000 times and I am shock by this result.</div><div><br></div><div>If the wall clock is greater then it makes sense, but here we have a negative difference. </div><div><br></div><div>One possibility is that the wall clock and the cpu time are accounted by different timers in kernel. But they should all updated based on the HZ, which is 1000 in my case. So I cannot explain the reason why the cpu time in my computer counts faster than the wall clock.</div><div><br></div><div>Thank you in advance for helping and looking forward your reply.</div><div><br></div><div>Best wishes</div><span class="HOEnZb"><font color="#888888"><div>Shuai</div><div><br></div><div><br></div><div><br></div><div><br></div></font></span></div>
<br>_______________________________________________<br>
litmus-dev mailing list<br>
<a href="mailto:litmus-dev@lists.litmus-rt.org">litmus-dev@lists.litmus-rt.org</a><br>
<a href="https://lists.litmus-rt.org/listinfo/litmus-dev" rel="noreferrer" target="_blank">https://lists.litmus-rt.org/listinfo/litmus-dev</a><br>
<br></blockquote></div><br></div>