summaryrefslogtreecommitdiff
path: root/share/man/man4/kstat.4
blob: ba28b6845af4c990bf4507caff68e33e6311f952 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
.\"	$OpenBSD: kstat.4,v 1.3 2022/01/10 07:51:23 dlg Exp $
.\"
.\" Copyright (c) 2022 Jonathan Gray <jsg@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: January 10 2022 $
.Dt KSTAT 4
.Os
.Sh NAME
.Nm kstat
.Nd kernel statistics
.Sh SYNOPSIS
.Cd "pseudo-device kstat"
.Sh DESCRIPTION
The
.Pa /dev/kstat
device exposes kernel statistics (kstats) to userland.
.Sh IOCTLS
The kstat
.Xr ioctl 2
calls are provided in
.In sys/kstat.h .
.Pp
With the exception of
.Dv KSTATIOC_VERSION ,
the kstat
.Xr ioctl 2
calls use the
.Vt kstat_req
structure to request or enumerate kernel
statistic data from the kernel:
.Bd -literal
struct kstat_req {
	unsigned int		 ks_rflags;
#define KSTATIOC_F_IGNVER		(1 << 0)
	/* the current version of the kstat subsystem */
	unsigned int		 ks_version;

	uint64_t		 ks_id;

	char			 ks_provider[KSTAT_STRLEN];
	unsigned int		 ks_instance;
	char			 ks_name[KSTAT_STRLEN];
	unsigned int		 ks_unit;

	struct timespec		 ks_created;
	struct timespec		 ks_updated;
	struct timespec		 ks_interval;
	unsigned int		 ks_type;
	unsigned int		 ks_state;

	void			*ks_data;
	size_t			 ks_datalen;
	unsigned int		 ks_dataver;
};
.Ed
.Pp
The kstat subsystem increments a version number when a kstat is added to or
removed from the subsystem so changes to the set of kstats can be detected.
Programs requesting a kstat must pass the current version in
.Va ks_version .
If the version differs an error will be returned with
.Xr errno 2
set to
.Dv EINVAL
to indicate that the program should resynchronise with the kernel
subsystem.
This check can be disabled by setting the
.Dv KSTATIOC_F_IGNVER
flag in
.Va ks_rflags .
.Pp
The kstat
.Xr ioctl 2
calls are as follows:
.Bl -tag -width Ds
.It Dv KSTATIOC_VERSION Fa "unsigned int"
Get the current version of the set of kernel statistics.
.It Dv KSTATIOC_FIND_ID Fa "struct kstat_req"
Request the kstat identified by
.Va ks_id .
.It Dv KSTATIOC_NFIND_ID Fa "struct kstat_req"
Request a kstat with an identifier greater than or equal to
.Va ks_id .
.It Dv KSTATIOC_FIND_PROVIDER Fa "struct kstat_req"
Request the kstat identified by
.Va ks_provider ,
.Va ks_instance ,
.Va ks_name ,
and
.Va ks_unit .
.It Dv KSTATIOC_NFIND_PROVIDER Fa "struct kstat_req"
Request the kstat or next kstat from the set of kstats ordered by
.Va ks_provider ,
.Va ks_instance ,
.Va ks_name ,
and
.Va ks_unit .
.It Dv KSTATIOC_FIND_NAME Fa "struct kstat_req"
Request the kstat identified by
.Va ks_name ,
.Va ks_unit ,
.Va ks_provider ,
and
.Va ks_instance .
.It Dv KSTATIOC_NFIND_NAME Fa "struct kstat_req"
Request the kstat or next kstat from the set of kstats ordered by
.Va ks_name ,
.Va ks_unit ,
.Va ks_provider ,
and
.Va ks_instance .
.El
.Sh FILES
.Bl -tag -width Pa -compact
.It Pa /dev/kstat
.El
.Sh SEE ALSO
.\".Xr kstat 1 ,
.Xr kstat_create 9 ,
.Xr kstat_kv_init 9
.Sh HISTORY
The
.Nm
device appeared in
.Ox 6.8 .