summaryrefslogtreecommitdiff
path: root/usr/src/uts/i86pc/sys/comm_page.h
blob: ea19c856a8aa3531196966af9516f89f8bafe8d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * This file and its contents are supplied under the terms of the
 * Common Development and Distribution License ("CDDL"), version 1.0.
 * You may only use this file in accordance with the terms of version
 * 1.0 of the CDDL.
 *
 * A full copy of the text of the CDDL should have accompanied this
 * source.  A copy of the CDDL is also available via the Internet at
 * http://www.illumos.org/license/CDDL.
 */

/*
 * Copyright 2016 Joyent, Inc.
 */

#ifndef _COMM_PAGE_H
#define	_COMM_PAGE_H

#ifndef _ASM
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#endif /* _ASM */

#ifdef __cplusplus
extern "C" {
#endif

#define	COMM_PAGE_SIZE	PAGESIZE
#define	COMM_PAGE_ALIGN	0x4000

#ifndef _ASM

/*
 * x86 comm page
 *
 * This struct defines the data format for the "comm page": kernel data made
 * directly available to userspace for read-only operations.  This enables
 * facilities such as clock_gettime to operate entirely in userspace without
 * the need for a trap or fasttrap.
 *
 * A note about 32-bit/64-bit compatibility:
 * The current format of the comm page is designed to be consistent for both
 * 32-bit and 64-bit programs running in a 64-bit kernel.  On 32-bit kernels,
 * the comm page is not exposed to userspace due to the difference in
 * timespec_t sizing.
 *
 * This struct is instantiated "by hand" in assembly to preserve the global
 * symbols it contains.  That layout must be kept in sync with the structure
 * defined here.
 * See: "uts/i86pc/ml/comm_page.s"
 */
typedef struct comm_page_s {
	hrtime_t		cp_tsc_last;
	hrtime_t		cp_tsc_hrtime_base;
	hrtime_t		cp_tsc_resume_cap;
	uint32_t		cp_tsc_type;
	uint32_t		cp_tsc_max_delta;

	volatile uint32_t	cp_hres_lock;	/* must be 8-byte aligned */
	uint32_t		cp_nsec_scale;
	int64_t			cp_hrestime_adj;
	hrtime_t		cp_hres_last_tick;
	uint32_t		cp_tsc_ncpu;
	uint32_t		_cp_pad;
	volatile int64_t	cp_hrestime[2];
#if defined(_MACHDEP)
	hrtime_t		cp_tsc_sync_tick_delta[NCPU];
#else
	/* length resides in cp_ncpu */
	hrtime_t		cp_tsc_sync_tick_delta[];
#endif /* defined(_MACHDEP) */
} comm_page_t;

#if defined(_KERNEL)
extern comm_page_t comm_page;

#if defined(_MACHDEP)
extern hrtime_t tsc_last;
extern hrtime_t tsc_hrtime_base;
extern hrtime_t tsc_resume_cap;
extern uint32_t tsc_type;
extern uint32_t tsc_max_delta;
extern volatile uint32_t hres_lock;
extern uint32_t nsec_scale;
extern int64_t hrestime_adj;
extern hrtime_t hres_last_tick;
extern uint32_t tsc_ncpu;
extern volatile timestruc_t hrestime;
extern hrtime_t tsc_sync_tick_delta[NCPU];
#endif /* defined(_MACHDEP) */
#endif /* defined(_KERNEL) */

#endif  /* _ASM */

#ifdef __cplusplus
}
#endif

#endif /* _COMM_PAGE_H */