% cat gettime_bug.c #define _GNU_SOURCE #include <errno.h> #include <stdio.h> #include <string.h> #include <time.h> int main() { struct timespec t = {.tv_sec = 0, .tv_nsec = 0}; int err1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t); printf("clock_gettime: %d [%s]\n", err1, strerror(errno)); int err2 = clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t); printf("clock_gettime: %d [%s]\n", err2, strerror(errno)); return 0; } % /compat/linux/bin/cc -Wall --sysroot=/compat/linux gettime_bug.c -o gettime_bug % ./gettime_bug clock_gettime: -1 [Invalid argument] clock_gettime: -1 [Invalid argument]
This is necessary for anything based on Chromium, see https://cs.chromium.org/chromium/src/base/time/time_now_posix.cc?l=52&rcl=b6ad4da425c33a31e4e08b67ce070a0c52082358.
This one's weird. There is the code to handle them in sys/compat/linux/linux_time.c, but I have honestly no idea what it's trying to do and why.
A commit references this bug: Author: dchagin Date: Tue Feb 4 05:27:05 UTC 2020 New revision: 357493 URL: https://svnweb.freebsd.org/changeset/base/357493 Log: Fix clock_gettime() and clock_getres() for cpu clocks: - handle the CLOCK_{PROCESS,THREAD}_CPUTIME_ID specified directly; - fix thread id calculation as in the Linuxulator we should convert the user supplied thread id to struct thread * by linux_tdfind(); - fix CPUCLOCK_SCHED case by using kern_{process,thread}_cputime() directly as native get_cputime() used by kern_clock_gettime() uses native tdfind()/pfind() to find proccess/thread. PR: 240990 Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D23341 MFC after: 2 weeks Changes: head/sys/compat/linux/linux_time.c
A commit references this bug: Author: trasz Date: Mon Aug 24 14:48:54 UTC 2020 New revision: 364689 URL: https://svnweb.freebsd.org/changeset/base/364689 Log: MFC r357493 by dchagin: Fix clock_gettime() and clock_getres() for cpu clocks: - handle the CLOCK_{PROCESS,THREAD}_CPUTIME_ID specified directly; - fix thread id calculation as in the Linuxulator we should convert the user supplied thread id to struct thread * by linux_tdfind(); - fix CPUCLOCK_SCHED case by using kern_{process,thread}_cputime() directly as native get_cputime() used by kern_clock_gettime() uses native tdfind()/pfind() to find proccess/thread. PR: 240990 Changes: _U stable/12/ stable/12/sys/compat/linux/linux_time.c
^Triage: Assign to committer that resolved