1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2016 Joyent, Inc.
  14  */
  15 
  16 #ifndef _COMM_PAGE_H
  17 #define _COMM_PAGE_H
  18 
  19 #ifndef _ASM
  20 #include <sys/types.h>
  21 #include <sys/param.h>
  22 #include <sys/time.h>
  23 #endif /* _ASM */
  24 
  25 #ifdef __cplusplus
  26 extern "C" {
  27 #endif
  28 
  29 #define COMM_PAGE_SIZE  PAGESIZE
  30 #define COMM_PAGE_ALIGN 0x4000
  31 
  32 #ifndef _ASM
  33 
  34 /*
  35  * x86 comm page
  36  *
  37  * This struct defines the data format for the "comm page": kernel data made
  38  * directly available to userspace for read-only operations.  This enables
  39  * facilities such as clock_gettime to operate entirely in userspace without
  40  * the need for a trap or fasttrap.
  41  *
  42  * A note about 32-bit/64-bit compatibility:
  43  * The current format of the comm page is designed to be consistent for both
  44  * 32-bit and 64-bit programs running in a 64-bit kernel.  On 32-bit kernels,
  45  * the comm page is not exposed to userspace due to the difference in
  46  * timespec_t sizing.
  47  *
  48  * This struct is instantiated "by hand" in assembly to preserve the global
  49  * symbols it contains.  That layout must be kept in sync with the structure
  50  * defined here.
  51  * See: "uts/i86pc/ml/comm_page.s"
  52  */
  53 typedef struct comm_page_s {
  54         hrtime_t                cp_tsc_last;
  55         hrtime_t                cp_tsc_hrtime_base;
  56         hrtime_t                cp_tsc_resume_cap;
  57         uint32_t                cp_tsc_type;
  58         uint32_t                cp_tsc_max_delta;
  59 
  60         volatile uint32_t       cp_hres_lock;   /* must be 8-byte aligned */
  61         uint32_t                cp_nsec_scale;
  62         int64_t                 cp_hrestime_adj;
  63         hrtime_t                cp_hres_last_tick;
  64         uint32_t                cp_tsc_ncpu;
  65         uint32_t                _cp_pad;
  66         volatile int64_t        cp_hrestime[2];
  67 #if defined(_MACHDEP)
  68         hrtime_t                cp_tsc_sync_tick_delta[NCPU];
  69 #else
  70         /* length resides in cp_ncpu */
  71         hrtime_t                cp_tsc_sync_tick_delta[];
  72 #endif /* defined(_MACHDEP) */
  73 } comm_page_t;
  74 
  75 #if defined(_KERNEL)
  76 extern comm_page_t comm_page;
  77 
  78 #if defined(_MACHDEP)
  79 extern hrtime_t tsc_last;
  80 extern hrtime_t tsc_hrtime_base;
  81 extern hrtime_t tsc_resume_cap;
  82 extern uint32_t tsc_type;
  83 extern uint32_t tsc_max_delta;
  84 extern volatile uint32_t hres_lock;
  85 extern uint32_t nsec_scale;
  86 extern int64_t hrestime_adj;
  87 extern hrtime_t hres_last_tick;
  88 extern uint32_t tsc_ncpu;
  89 extern volatile timestruc_t hrestime;
  90 extern hrtime_t tsc_sync_tick_delta[NCPU];
  91 #endif /* defined(_MACHDEP) */
  92 #endif /* defined(_KERNEL) */
  93 
  94 #endif  /* _ASM */
  95 
  96 #ifdef __cplusplus
  97 }
  98 #endif
  99 
 100 #endif /* _COMM_PAGE_H */