From e03a26cf01061f84109d5b40ed240cb92221c29d Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 9 Jul 2026 08:39:09 +0300 Subject: [PATCH] LibC: Don't ASSERT in `times` Return the current process CPU time as user time. We don't have a way to get system/user time separation or CPU times of child processes --- userspace/libraries/LibC/sys/times.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/userspace/libraries/LibC/sys/times.cpp b/userspace/libraries/LibC/sys/times.cpp index 8818090a..34fd268c 100644 --- a/userspace/libraries/LibC/sys/times.cpp +++ b/userspace/libraries/LibC/sys/times.cpp @@ -1,9 +1,26 @@ #include +#include +#include -#include +static inline clock_t timespec_to_clock_t(const timespec& ts) +{ + static clock_t clock_tick = -1; + if (clock_tick == -1) + clock_tick = sysconf(_SC_CLK_TCK); + + return ts.tv_sec * clock_tick + ts.tv_nsec * clock_tick / 1'000'000'000; +} clock_t times(struct tms* buffer) { - (void)buffer; - ASSERT_NOT_REACHED(); + // FIXME: system time, child times + *buffer = {}; + + timespec ts; + + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); + buffer->tms_utime = timespec_to_clock_t(ts); + + clock_gettime(CLOCK_MONOTONIC, &ts); + return timespec_to_clock_t(ts); }