]> granicus.if.org Git - php/commitdiff
Make busy wait busier
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Jul 2019 11:26:59 +0000 (13:26 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Jul 2019 11:35:29 +0000 (13:35 +0200)
Another stab in the dark to fix the intermittent failures of timeout
tests on macos CI: We're using ITIMER_PROF, which means that the
timer counts against user+system time. The "busy" wait loop counts
against real time. Currently it calls microtime() on every iteration.
If that call is implemented as a syscall rather than going through
vDSO or commpage we might be seeing many context switches here which
drive up the real time, but not user or system time.

See if making the loop busier and calling microtime() less helps the
situation.

tests/basic/timeout_config.inc

index 3bd9eeaa708365a5144cb67eba27f2e3c7a92545..5cd156f471f6d3c1bfcc5d206d5f6ebbd6bfcf40 100644 (file)
@@ -2,9 +2,9 @@
 
 $t = 3;
 
-function busy_wait($how_long)
-{
-       $until = microtime(TRUE) + $how_long;
-
-       while ($until > microtime(TRUE));
+function busy_wait($how_long) {
+    $until = microtime(true) + $how_long;
+    do {
+        for ($i = 0; $i < 1000000; $i++);
+    } while ($until > microtime(true));
 }