NEW243810
Watchdog can't work on Mac with m1 chip because wrong thread cpu time.
https://bugs.webkit.org/show_bug.cgi?id=243810
Summary Watchdog can't work on Mac with m1 chip because wrong thread cpu time.
Vincent.yu
Reported 2022-08-10 20:28:26 PDT
Watchdog.cpp use CPUTime::forCurrentThread, which use clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts), to get the cpu clock of thread. But on Mac with m1, the clock_gettime(CLOCK_THREAD_CPUTIME_ID) is always incredibly small. Here is the test code: ``` double CPUTime() { struct timespec ts; int ret = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); return ts.tv_sec + ts.tv_nsec/1000.0/1000.0/1000.0; } double RealTime() { struct timespec ts; int ret = clock_gettime(CLOCK_MONOTONIC, &ts); return ts.tv_sec + ts.tv_nsec/1000.0/1000.0/1000.0; } void longTask() { double begin = RealTime(); double limit = 1.0; static double g_result = 0; while (1) { for (int i=0; i<1000000; i++) { g_result = sin(g_result+5); } double now = RealTime(); if (now - begin >= limit) break; } return; } void testClocks() { double t1, t0, cpuTimeCost, realTimeCost; t0 = CPUTime(); longTask(); t1 = CPUTime(); cpuTimeCost = t1 - t0; double t10 = RealTime(); longTask(); double t11 = RealTime(); realTimeCost = t11 - t10; NSLog(@"\nthread cpu: %lfs\nreal: %lfs", cpuTimeCost, realTimeCost); return; } ``` It will output: ``` thread cpu: 0.024395s real: 1.006627s ``` Only the M1 chip has this problem. On Mac with Intel, these two clocks are almost the same.
Attachments
Radar WebKit Bug Importer
Comment 1 2022-08-17 20:29:17 PDT
Note You need to log in before you can comment on or make changes to this bug.