|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesxhprof-rdtsc-busy-loop (last revision 2013-02-06 23:35 UTC by tstarling)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-10-24 08:25 UTC] kalle@php.net
-Status: Open
+Status: Suspended
[2017-10-24 08:25 UTC] kalle@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 14:00:01 2025 UTC |
Description: ------------ get_cpu_frequency() calibrates RDTSC values by measuring the delta across a usleep(5000) call. On my Intel processor on Linux 3.5, the processor often halts for the majority of those 5 milliseconds. The RDTSC counter is not incremented during the halt. So the resulting calibration is off by a factor of 10 or so. The solution is to do a busy loop instead of a usleep() call. Patch attached. The volatile loop counter prevents the loop from being optimised away, I checked the assembly generated by gcc. I confirmed that with the patch, the reported CPU frequency is consistent with the physical clock frequency, and stable with a standard deviation of 0.007%. Test script: --------------- diff --git a/extension/xhprof.c b/extension/xhprof.c index a053ede..52841d1 100644 --- a/extension/xhprof.c +++ b/extension/xhprof.c @@ -1351,6 +1351,7 @@ static void get_all_cpu_frequencies() { usleep(0); frequency = get_cpu_frequency(); + printf("CPU %d: %g\n", id, frequency); if (frequency == 0.0) { clear_frequencies(); return;