php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64165 [PATCH] RDTSC calibration totally wrong on Linux
Submitted: 2013-02-06 23:35 UTC Modified: 2017-10-24 08:25 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: tstarling@php.net Assigned:
Status: Suspended Package: xhprof (PECL)
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-02-06 23:35 UTC] tstarling@php.net
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;



Patches

xhprof-rdtsc-busy-loop (last revision 2013-02-06 23:35 UTC by tstarling)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-24 08:25 UTC] kalle@php.net
-Status: Open +Status: Suspended
 [2017-10-24 08:25 UTC] kalle@php.net
This package has not had a release for over 4 years, and the last bit of git activity was over 2 years ago, so I think its safe to say this extension is no longer in active development. If development picks back up, then please re-open this report
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 04:01:26 2019 UTC