xref: /illumos-gate/usr/src/uts/i86pc/sys/comm_page.h (revision 53aa45cdd84363d9e717eb6cb3532bcabae6911b)
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  * Copyright 2025 Oxide Computer Company
15  */
16 
17 #ifndef _COMM_PAGE_H
18 #define	_COMM_PAGE_H
19 
20 #ifndef _ASM
21 #include <sys/types.h>
22 #include <sys/param.h>
23 #include <sys/time.h>
24 #include <sys/sysmacros.h>
25 #endif /* _ASM */
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
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_pad0;
65 	volatile int64_t	cp_hrestime[2];
66 	uint64_t		_cp_pad1[502];	/* pad to page boundary */
67 #if defined(_MACHDEP)
68 	hrtime_t		cp_tsc_sync_tick_delta[NCPU];
69 	/* fill any remaining space in page with padding */
70 #define	_CP_PAD2_SZ	P2ROUNDUP(NCPU, PAGESIZE / sizeof (hrtime_t)) - NCPU
71 	uint64_t		_cp_pad2[_CP_PAD2_SZ];
72 #else
73 	/* length resides in cp_tsc_ncpu */
74 	hrtime_t		cp_tsc_sync_tick_delta[];
75 #endif /* defined(_MACHDEP) */
76 } comm_page_t;
77 
78 #if defined(_KERNEL)
79 extern comm_page_t comm_page;
80 
81 #if defined(_MACHDEP)
82 
83 #include <sys/debug.h>
84 CTASSERT((offsetof(comm_page_t, cp_tsc_sync_tick_delta) & PAGEOFFSET) == 0);
85 CTASSERT((sizeof (comm_page_t) & PAGEOFFSET) == 0);
86 
87 extern hrtime_t tsc_last;
88 extern hrtime_t tsc_hrtime_base;
89 extern hrtime_t tsc_resume_cap;
90 extern uint32_t tsc_type;
91 extern uint32_t tsc_max_delta;
92 extern volatile uint32_t hres_lock;
93 extern uint32_t nsec_scale;
94 extern int64_t hrestime_adj;
95 extern hrtime_t hres_last_tick;
96 extern uint32_t tsc_ncpu;
97 extern volatile timestruc_t hrestime;
98 extern hrtime_t tsc_sync_tick_delta[NCPU];
99 
100 #endif /* defined(_MACHDEP) */
101 #endif /* defined(_KERNEL) */
102 
103 #endif  /* _ASM */
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* _COMM_PAGE_H */
110