Print this page
OS-5804 lxbrand needs support for CLOCK_*_CPUTIME_ID timers

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/brand/lx/syscall/lx_timer.c
          +++ new/usr/src/uts/common/brand/lx/syscall/lx_timer.c
↓ open down ↓ 2 lines elided ↑ open up ↑
   3    3   * Common Development and Distribution License ("CDDL"), version 1.0.
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  
  12   12  /*
  13      - * Copyright 2016 Joyent, Inc.
       13 + * Copyright 2020 Joyent, Inc.
  14   14   */
  15   15  
  16   16  /*
  17   17   * The illumos kernel provides two clock backends: CLOCK_REALTIME, the
  18   18   * adjustable system wall clock; and CLOCK_HIGHRES, the monotonically
  19   19   * increasing time source that is not subject to drift or adjustment.  By
  20   20   * contrast, the Linux kernel is furnished with an overabundance of narrowly
  21   21   * differentiated clock types.
  22   22   *
  23      - * Fortunately, most of the commonly used Linux clock types are either similar
  24      - * enough to the native clock backends that they can be directly mapped, or
  25      - * represent queries to the per-process and per-LWP microstate counters.
       23 + * Fortunately, most of the commonly used Linux clock types are similar
       24 + * enough to the native clock backends that they can be directly mapped.
  26   25   *
       26 + * Unfortunately, while CLOCK_{THREAD,PROCESS}_CPUTIME_ID are *somewhat*
       27 + * implemented in the main illumos kernel as itimers (see setitimer(2)), we
       28 + * would need to entirely bringup of CLOCK_{THREAD,PROCESS}_CPUTIME_ID to
       29 + * implement timer_create() and friends.  For now, we opt to map it to
       30 + * CLOCK_HIGHRES for timer_create() and friends, but continue to emulate
       31 + * more-accurate queries to per-process or per-LWP microstate accounting for
       32 + * getres, gettime, or settime.
       33 + *
  27   34   * CLOCK_BOOTTIME is identical to CLOCK_MONOTONIC, except that it takes into
  28   35   * account time that the system is suspended. Since that is uninteresting to
  29   36   * us, we treat it the same.
  30   37   */
  31   38  
  32   39  #include <sys/time.h>
  33   40  #include <sys/systm.h>
  34   41  #include <sys/cmn_err.h>
  35   42  #include <sys/brand.h>
  36   43  #include <sys/lx_brand.h>
↓ open down ↓ 39 lines elided ↑ open up ↑
  76   83  /*
  77   84   * This backend is not supported, so we provide an emulation handler:
  78   85   */
  79   86  #define EMUL(ntv_id)                                                    \
  80   87          { ntv_id, lx_emul_clock_getres, lx_emul_clock_gettime,          \
  81   88              lx_emul_clock_settime }
  82   89  
  83   90  static lx_clock_backend_t lx_clock_backends[] = {
  84   91          NATIVE(CLOCK_REALTIME),         /* LX_CLOCK_REALTIME */
  85   92          NATIVE(CLOCK_HIGHRES),          /* LX_CLOCK_MONOTONIC */
  86      -        EMUL(CLOCK_PROCESS_CPUTIME_ID), /* LX_CLOCK_PROCESS_CPUTIME_ID */
  87      -        EMUL(CLOCK_THREAD_CPUTIME_ID),  /* LX_CLOCK_THREAD_CPUTIME_ID */
       93 +        EMUL(CLOCK_HIGHRES),            /* LX_CLOCK_PROCESS_CPUTIME_ID */
       94 +        EMUL(CLOCK_HIGHRES),            /* LX_CLOCK_THREAD_CPUTIME_ID */
  88   95          NATIVE(CLOCK_HIGHRES),          /* LX_CLOCK_MONOTONIC_RAW */
  89   96          NATIVE(CLOCK_REALTIME),         /* LX_CLOCK_REALTIME_COARSE */
  90   97          NATIVE(CLOCK_HIGHRES),          /* LX_CLOCK_MONOTONIC_COARSE */
  91   98          NATIVE(CLOCK_HIGHRES)           /* LX_CLOCK_BOOTTIME */
  92   99  };
  93  100  
  94  101  #define LX_CLOCK_MAX \
  95  102          (sizeof (lx_clock_backends) / sizeof (lx_clock_backends[0]))
  96  103  #define LX_CLOCK_BACKEND(clk) (((clk) < LX_CLOCK_MAX && (clk) >= 0) ? \
  97  104          &lx_clock_backends[(clk)] : NULL)
↓ open down ↓ 540 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX