Bug 240990 - Linuxulator: CLOCK_THREAD_CPUTIME_ID and CLOCK_PROCESS_CPUTIME_ID are missing
Summary: Linuxulator: CLOCK_THREAD_CPUTIME_ID and CLOCK_PROCESS_CPUTIME_ID are missing
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Dmitry Chagin
URL:
Keywords: feature
Depends on:
Blocks: 247219
  Show dependency treegraph
 
Reported: 2019-10-02 00:38 UTC by Alex S
Modified: 2021-04-21 03:32 UTC (History)
3 users (show)

See Also:
koobs: mfc-stable12+
koobs: mfc-stable11-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex S 2019-10-02 00:38:27 UTC
% 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]
Comment 1 Alex S 2019-10-02 00:50:20 UTC
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.
Comment 2 Edward Tomasz Napierala freebsd_committer freebsd_triage 2020-01-08 17:38:34 UTC
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.
Comment 3 commit-hook freebsd_committer freebsd_triage 2020-02-04 05:27:19 UTC
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
Comment 4 commit-hook freebsd_committer freebsd_triage 2020-08-24 14:48:58 UTC
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
Comment 5 Kubilay Kocak freebsd_committer freebsd_triage 2021-04-21 03:32:16 UTC
^Triage: Assign to committer that resolved