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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
'\" te
.\" Copyright (c) 2006, Sun Microsystems, Inc., All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH KSTAT_CREATE 9F "Sep 7, 2015"
.SH NAME
kstat_create \- create and initialize a new kstat
.SH SYNOPSIS
.nf
#include <sys/types.h>
#include <sys/kstat.h>
\fBkstat_t *\fR\fBkstat_create\fR(\fBconst char *\fR\fIks_module\fR, \fBint\fR \fIks_instance\fR,
\fBconst char *\fR\fIks_name\fR, \fBconst char *\fR\fIks_class\fR, \fBuchar_t\fR \fIks_type\fR,
\fBulong_t\fR \fIks_ndata\fR, \fBuchar_t\fR \fIks_flag\fR);
.fi
.SH INTERFACE LEVEL
illumos DDI specific (illumos DDI)
.SH PARAMETERS
.ne 2
.na
\fB\fIks_module\fR\fR
.ad
.RS 15n
The name of the provider's module (such as "\fBsd\fR", "\fBesp\fR", ...). The
"\fBcore\fR" kernel uses the name "unix".
.RE
.sp
.ne 2
.na
\fB\fIks_instance\fR\fR
.ad
.RS 15n
The provider's instance number, as from \fBddi_get_instance\fR(9F). Modules
which do not have a meaningful instance number should use \fB0\fR.
.RE
.sp
.ne 2
.na
\fB\fIks_name\fR\fR
.ad
.RS 15n
A pointer to a string that uniquely identifies this structure. Only
\fBKSTAT_STRLEN \(mi 1\fR characters are significant.
.RE
.sp
.ne 2
.na
\fB\fIks_class\fR\fR
.ad
.RS 15n
The general class that this kstat belongs to. The following classes are
currently in use: \fBdisk\fR, \fBtape\fR, \fBnet\fR, \fBcontroller\fR,
\fBvm\fR, \fBkvm\fR, \fBhat\fR, \fBstreams\fR, \fBkstat\fR, and \fBmisc\fR.
.RE
.sp
.ne 2
.na
\fB\fIks_type\fR\fR
.ad
.RS 15n
The type of \fBkstat\fR to allocate. Valid types are:
.sp
.ne 2
.na
\fB\fBKSTAT_TYPE_RAW\fR\fR
.ad
.RS 20n
Raw data; allows more than one data record per \fBkstat\fR.
.RE
.sp
.ne 2
.na
\fB\fBKSTAT_TYPE_NAMED\fR\fR
.ad
.RS 20n
Name=value pairs; allows more than one data record per \fBkstat\fR.
.RE
.sp
.ne 2
.na
\fB\fBKSTAT_TYPE_INTR\fR\fR
.ad
.RS 20n
Interrupt; only one data record per \fBkstat\fR.
.RE
.sp
.ne 2
.na
\fB\fBKSTAT_TYPE_IO\fR\fR
.ad
.RS 20n
\fBI/O\fR; only one data record per \fBkstat\fR.
.RE
.sp
.ne 2
.na
\fB\fBKSTAT_TYPE_TIMER\fR\fR
.ad
.RS 20n
Event timer statistics; allows more than one data record per \fBkstat\fR.
.RE
.RE
.sp
.ne 2
.na
\fB\fIks_ndata\fR\fR
.ad
.RS 15n
The number of type-specific data records to allocate.
.RE
.sp
.ne 2
.na
\fB\fIks_flag\fR\fR
.ad
.RS 15n
A bit-field of various flags for this \fBkstat\fR. \fIks_flag\fR is some
combination of:
.sp
.ne 2
.na
\fB\fBKSTAT_FLAG_VIRTUAL\fR\fR
.ad
.RS 25n
Tells \fBkstat_create()\fR not to allocate memory for the \fBkstat\fR data
section; instead, the driver will set the \fBks_data\fR field to point to the
data it wishes to export. This provides a convenient way to export existing
data structures.
.RE
.sp
.ne 2
.na
\fB\fBKSTAT_FLAG_WRITABLE\fR\fR
.ad
.RS 25n
Makes the \fBkstat\fR data section writable by root.
.RE
.sp
.ne 2
.na
\fB\fBKSTAT_FLAG_PERSISTENT\fR\fR
.ad
.RS 25n
Indicates that this \fBkstat\fR is to be persistent over time. For persistent
\fBkstat\fRs, \fBkstat_delete\fR(9F) simply marks the \fBkstat\fR as dormant; a
subsequent \fBkstat_create()\fR reactivates the kstat. This feature is provided
so that statistics are not lost across driver close/open (such as raw disk
\fBI/O\fR on a disk with no mounted partitions.) Note: Persistent \fBkstat\fRs
cannot be virtual, since \fBks_data\fR points to garbage as soon as the driver
goes away.
.RE
.RE
.SH DESCRIPTION
\fBkstat_create()\fR is used in conjunction with \fBkstat_install\fR(9F) to
allocate and initialize a \fBkstat\fR(9S) structure. The method is generally as
follows:
.sp
.LP
\fBkstat_create()\fR allocates and performs necessary system initialization of
a \fBkstat\fR(9S) structure. \fBkstat_create()\fR allocates memory for the
entire \fBkstat\fR (header plus data), initializes all header fields,
initializes the data section to all zeroes, assigns a unique kstat \fBID\fR
(\fBKID\fR), and puts the kstat onto the system's \fBkstat\fR chain. The
returned kstat is marked invalid because the provider (caller) has not yet had
a chance to initialize the data section.
.sp
.LP
After a successful call to \fBkstat_create()\fR the driver must perform any
necessary initialization of the data section (such as setting the name fields
in a \fBkstat\fR of type \fBKSTAT_TYPE_NAMED\fR). Virtual \fBkstat\fRs must
have the \fBks_data\fR field set at this time. The provider may also set the
\fBks_update\fR, \fBks_private\fR, and \fBks_lock\fR fields if necessary.
.sp
.LP
Once the \fBkstat\fR is completely initialized, \fBkstat_install\fR(9F) is used
to make the \fBkstat\fR accessible to the outside world.
.SH RETURN VALUES
If successful, \fBkstat_create()\fR returns a pointer to the allocated
\fBkstat\fR. \fINULL\fR is returned upon failure.
.SH CONTEXT
\fBkstat_create()\fR can be called from user or kernel context.
.SH EXAMPLES
\fBExample 1 \fRAllocating and Initializing a \fBkstat\fR Structure
.sp
.in +2
.nf
pkstat_t *ksp;
ksp = kstat_create(module, instance, name, class, type, ndata, flags);
if (ksp) {
/* ... provider initialization, if necessary */
kstat_install(ksp);
}
.fi
.in -2
.SH SEE ALSO
.BR kstat (3KSTAT),
.BR ddi_get_instance (9F),
.BR kstat_delete (9F),
.BR kstat_install (9F),
.BR kstat_named_init (9F),
.BR kstat (9S),
.BR kstat_named (9S)
.sp
.LP
\fIWriting Device Drivers\fR
|