aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/vdso.h
blob: d905304ac68a178f6a76b08ae5d214fd3c5a141b (plain) (blame)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*-
 * Copyright 2012 Konstantin Belousov <kib@FreeBSD.ORG>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _SYS_VDSO_H
#define	_SYS_VDSO_H

#include <sys/types.h>
#include <machine/vdso.h>

struct vdso_timehands {
	uint32_t	th_algo;
	uint32_t	th_gen;
	uint64_t	th_scale;
	uint32_t 	th_offset_count;
	uint32_t	th_counter_mask;
	struct bintime	th_offset;
	struct bintime	th_boottime;
	VDSO_TIMEHANDS_MD
};

struct vdso_timekeep {
	uint32_t	tk_ver;
	uint32_t	tk_enabled;
	uint32_t	tk_current;
	struct vdso_timehands	tk_th[];
};

#define	VDSO_TK_CURRENT_BUSY	0xffffffff
#define	VDSO_TK_VER_1		0x1
#define	VDSO_TK_VER_CURR	VDSO_TK_VER_1
#define	VDSO_TH_ALGO_1		0x1

#ifndef _KERNEL

struct timespec;
struct timeval;
struct timezone;

int __vdso_clock_gettime(clockid_t clock_id, struct timespec *ts);
int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz);
u_int __vdso_gettc(const struct vdso_timehands *vdso_th);
int __vdso_gettimekeep(struct vdso_timekeep **tk);

#endif

#ifdef _KERNEL

struct timecounter;

void timekeep_push_vdso(void);

uint32_t tc_fill_vdso_timehands(struct vdso_timehands *vdso_th);

/*
 * The cpu_fill_vdso_timehands() function should fill MD-part of the
 * struct vdso_timehands, which is both machine- and
 * timecounter-depended. The return value should be 1 if fast
 * userspace timecounter is enabled by hardware, and 0 otherwise. The
 * global sysctl enable override is handled by machine-independed code
 * after cpu_fill_vdso_timehands() call is made.
 */
uint32_t cpu_fill_vdso_timehands(struct vdso_timehands *vdso_th,
    struct timecounter *tc);

#define	VDSO_TH_NUM	4

#ifdef COMPAT_FREEBSD32
struct bintime32 {
	uint32_t	sec;
	uint32_t	frac[2];
};

struct vdso_timehands32 {
	uint32_t	th_algo;
	uint32_t	th_gen;
	uint32_t	th_scale[2];
	uint32_t 	th_offset_count;
	uint32_t	th_counter_mask;
	struct bintime32	th_offset;
	struct bintime32	th_boottime;
	VDSO_TIMEHANDS_MD32
};

struct vdso_timekeep32 {
	uint32_t	tk_ver;
	uint32_t	tk_enabled;
	uint32_t	tk_current;
	struct vdso_timehands32	tk_th[];
};

uint32_t tc_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32);
uint32_t cpu_fill_vdso_timehands32(struct vdso_timehands32 *vdso_th32,
    struct timecounter *tc);

#endif
#endif

#endif