[Webkit-unassigned] [Bug 243810] New: Watchdog can't work on Mac with m1 chip because wrong thread cpu time.
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Wed Aug 10 20:28:26 PDT 2022
https://bugs.webkit.org/show_bug.cgi?id=243810
Bug ID: 243810
Summary: Watchdog can't work on Mac with m1 chip because wrong
thread cpu time.
Product: WebKit
Version: Other
Hardware: Unspecified
OS: macOS 12
Status: NEW
Severity: Normal
Priority: P2
Component: JavaScriptCore
Assignee: webkit-unassigned at lists.webkit.org
Reporter: yuweishan at 126.com
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.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20220811/021f5e3a/attachment.htm>
More information about the webkit-unassigned
mailing list