tag:blogger.com,1999:blog-1016709139053396535.post247534653813481005..comments2024-03-18T17:34:35.079+00:00Comments on A Smackerel of Opinion: combining RAPL and perf to do power calibrationColin Ian Kinghttp://www.blogger.com/profile/06458723239721015750noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-1016709139053396535.post-19900130018675277712016-02-26T15:08:08.440+00:002016-02-26T15:08:08.440+00:00Good questions. The clock tick rate is inferred fr...Good questions. The clock tick rate is inferred from the total number of ticks counted during the sample interval from the CPU user, nice, sys, idle and iowait ticks. Since this theoretically *should* add up to the total ticks during the sample period we don't have to rely on determining the ticks from sysconf() and the total ticks allow us to compute the % share over that (possibly variable) time period too. If I was to divide by the sysconf() tick rate I need to convert that into the exact number of ticks over the sample duration, which is more work and can have jitter of +/- 1 or so ticks of we quantize the sample at the wrong time.Colin Ian Kinghttps://www.blogger.com/profile/06458723239721015750noreply@blogger.comtag:blogger.com,1999:blog-1016709139053396535.post-21730352399729094432016-01-22T16:47:01.280+00:002016-01-22T16:47:01.280+00:00Hi Colin,
Many thanks for the tool, looks very ni...Hi Colin,<br /><br />Many thanks for the tool, looks very nice!<br /><br />I'm studying your code in the hope of learning a bit more about how CPU utilization is tracked by the Linux kernel and how it is calculated by your tool. Here are a couple of questions, I'm for sure missing something about the concepts behind the calculations.<br /><br />It seems that CPU utilization (user, sys, etc.) is computed as: current - past value of CPU time, where the value is got from the /proc/stat fields. I can see from the man that /proc/stat reports<br /><br />"the amount of time, measured in units of USER_HZ (1/100ths of a second on most architectures, use sysconf(_SC_CLK_TCK) to obtain the right value), that the system spent in various states".<br /><br />Questions:<br /><br />1) In your code, I'm not able to find where you normalize the CPU times from /proc/stat with the sysconf(_SC_CLK_TCK) call. It looks like you simply subtract current and past value, then you print it.<br /><br />What am I missing here?<br /><br />2) This is a more general question about the correctness of this approach of calculating CPU utilization, which is AFAIK the standard approach also adopted by sar, vmstat, etc.<br /><br />What about variable frequency CPUs? Is this CPU utilization metric still correct?<br /><br />I can't see how it could be right if we don't take into account the actual frequency of the CPU: the amount of work would be very different at say 1.3 GHZ wrt 2 GHZ. Is the kernel doing special things to keep track of accurate CPU time in this case?<br /><br /><br />That's it! Thanks again for your time and your interesting tools!Anonymoushttps://www.blogger.com/profile/14152101916796502188noreply@blogger.com