xref: /illumos-gate/usr/src/uts/i86pc/sys/comm_page.h (revision c5bab7026b8e0ac44b25ee08507ea360f177d844)
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 
31 #ifndef _ASM
32 
33 /*
34  * x86 comm page
35  *
36  * This struct defines the data format for the "comm page": kernel data made
37  * directly available to userspace for read-only operations.  This enables
38  * facilities such as clock_gettime to operate entirely in userspace without
39  * the need for a trap or fasttrap.
40  *
41  * A note about 32-bit/64-bit compatibility:
42  * The current format of the comm page is designed to be consistent for both
43  * 32-bit and 64-bit programs running in a 64-bit kernel.  On 32-bit kernels,
44  * the comm page is not exposed to userspace due to the difference in
45  * timespec_t sizing.
46  *
47  * This struct is instantiated "by hand" in assembly to preserve the global
48  * symbols it contains.  That layout must be kept in sync with the structure
49  * defined here.
50  * See: "uts/i86pc/ml/comm_page.s"
51  */
52 typedef struct comm_page_s {
53 	hrtime_t		cp_tsc_last;
54 	hrtime_t		cp_tsc_hrtime_base;
55 	hrtime_t		cp_tsc_resume_cap;
56 	uint32_t		cp_tsc_type;
57 	uint32_t		cp_tsc_max_delta;
58 
59 	volatile uint32_t	cp_hres_lock;	/* must be 8-byte aligned */
60 	uint32_t		cp_nsec_scale;
61 	int64_t			cp_hrestime_adj;
62 	hrtime_t		cp_hres_last_tick;
63 	uint32_t		cp_tsc_ncpu;
64 	uint32_t		_cp_pad;
65 	volatile int64_t	cp_hrestime[2];
66 #if defined(_MACHDEP)
67 	hrtime_t		cp_tsc_sync_tick_delta[NCPU];
68 #else
69 	/* length resides in cp_ncpu */
70 	hrtime_t		cp_tsc_sync_tick_delta[];
71 #endif /* defined(_MACHDEP) */
72 } comm_page_t;
73 
74 #if defined(_KERNEL)
75 extern comm_page_t comm_page;
76 
77 #if defined(_MACHDEP)
78 extern hrtime_t tsc_last;
79 extern hrtime_t tsc_hrtime_base;
80 extern hrtime_t tsc_resume_cap;
81 extern uint32_t tsc_type;
82 extern uint32_t tsc_max_delta;
83 extern volatile uint32_t hres_lock;
84 extern uint32_t nsec_scale;
85 extern int64_t hrestime_adj;
86 extern hrtime_t hres_last_tick;
87 extern uint32_t tsc_ncpu;
88 extern volatile timestruc_t hrestime;
89 extern hrtime_t tsc_sync_tick_delta[NCPU];
90 #endif /* defined(_MACHDEP) */
91 #endif /* defined(_KERNEL) */
92 
93 #endif  /* _ASM */
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif /* _COMM_PAGE_H */
100