2 .\" Copyright (c) 2006, Sun Microsystems, Inc., All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH KSTAT_CREATE 9F "Sep 7, 2015"
8 kstat_create \- create and initialize a new kstat
12 #include <sys/types.h>
13 #include <sys/kstat.h>
17 \fBkstat_t *\fR\fBkstat_create\fR(\fBconst char *\fR\fIks_module\fR, \fBint\fR \fIks_instance\fR,
18 \fBconst char *\fR\fIks_name\fR, \fBconst char *\fR\fIks_class\fR, \fBuchar_t\fR \fIks_type\fR,
19 \fBulong_t\fR \fIks_ndata\fR, \fBuchar_t\fR \fIks_flag\fR);
24 Solaris DDI specific (Solaris DDI)
31 The name of the provider's module (such as "\fBsd\fR", "\fBesp\fR", ...). The
32 "\fBcore\fR" kernel uses the name "unix".
38 \fB\fIks_instance\fR\fR
41 The provider's instance number, as from \fBddi_get_instance\fR(9F). Modules
42 which do not have a meaningful instance number should use \fB0\fR.
51 A pointer to a string that uniquely identifies this structure. Only
52 \fBKSTAT_STRLEN \(mi 1\fR characters are significant.
61 The general class that this kstat belongs to. The following classes are
62 currently in use: \fBdisk\fR, \fBtape\fR, \fBnet\fR, \fBcontroller\fR,
63 \fBvm\fR, \fBkvm\fR, \fBhat\fR, \fBstreams\fR, \fBkstat\fR, and \fBmisc\fR.
72 The type of \fBkstat\fR to allocate. Valid types are:
76 \fB\fBKSTAT_TYPE_RAW\fR\fR
79 Raw data; allows more than one data record per \fBkstat\fR.
85 \fB\fBKSTAT_TYPE_NAMED\fR\fR
88 Name=value pairs; allows more than one data record per \fBkstat\fR.
94 \fB\fBKSTAT_TYPE_INTR\fR\fR
97 Interrupt; only one data record per \fBkstat\fR.
103 \fB\fBKSTAT_TYPE_IO\fR\fR
106 \fBI/O\fR; only one data record per \fBkstat\fR.
112 \fB\fBKSTAT_TYPE_TIMER\fR\fR
115 Event timer statistics; allows more than one data record per \fBkstat\fR.
126 The number of type-specific data records to allocate.
135 A bit-field of various flags for this \fBkstat\fR. \fIks_flag\fR is some
140 \fB\fBKSTAT_FLAG_VIRTUAL\fR\fR
143 Tells \fBkstat_create()\fR not to allocate memory for the \fBkstat\fR data
144 section; instead, the driver will set the \fBks_data\fR field to point to the
145 data it wishes to export. This provides a convenient way to export existing
152 \fB\fBKSTAT_FLAG_WRITABLE\fR\fR
155 Makes the \fBkstat\fR data section writable by root.
161 \fB\fBKSTAT_FLAG_PERSISTENT\fR\fR
164 Indicates that this \fBkstat\fR is to be persistent over time. For persistent
165 \fBkstat\fRs, \fBkstat_delete\fR(9F) simply marks the \fBkstat\fR as dormant; a
166 subsequent \fBkstat_create()\fR reactivates the kstat. This feature is provided
167 so that statistics are not lost across driver close/open (such as raw disk
168 \fBI/O\fR on a disk with no mounted partitions.) Note: Persistent \fBkstat\fRs
169 cannot be virtual, since \fBks_data\fR points to garbage as soon as the driver
177 \fBkstat_create()\fR is used in conjunction with \fBkstat_install\fR(9F) to
178 allocate and initialize a \fBkstat\fR(9S) structure. The method is generally as
182 \fBkstat_create()\fR allocates and performs necessary system initialization of
183 a \fBkstat\fR(9S) structure. \fBkstat_create()\fR allocates memory for the
184 entire \fBkstat\fR (header plus data), initializes all header fields,
185 initializes the data section to all zeroes, assigns a unique kstat \fBID\fR
186 (\fBKID\fR), and puts the kstat onto the system's \fBkstat\fR chain. The
187 returned kstat is marked invalid because the provider (caller) has not yet had
188 a chance to initialize the data section.
191 After a successful call to \fBkstat_create()\fR the driver must perform any
192 necessary initialization of the data section (such as setting the name fields
193 in a \fBkstat\fR of type \fBKSTAT_TYPE_NAMED\fR). Virtual \fBkstat\fRs must
194 have the \fBks_data\fR field set at this time. The provider may also set the
195 \fBks_update\fR, \fBks_private\fR, and \fBks_lock\fR fields if necessary.
198 Once the \fBkstat\fR is completely initialized, \fBkstat_install\fR(9F) is used
199 to make the \fBkstat\fR accessible to the outside world.
202 If successful, \fBkstat_create()\fR returns a pointer to the allocated
203 \fBkstat\fR. \fINULL\fR is returned upon failure.
206 \fBkstat_create()\fR can be called from user or kernel context.
209 \fBExample 1 \fRAllocating and Initializing a \fBkstat\fR Structure
214 ksp = kstat_create(module, instance, name, class, type, ndata, flags);
216 /* ... provider initialization, if necessary */
224 \fBkstat\fR(3KSTAT), \fBddi_get_instance\fR(9F), \fBkstat_delete\fR(9F),
225 \fBkstat_install\fR(9F), \fBkstat_named_init\fR(9F), \fBkstat\fR(9S),
226 \fBkstat_named\fR(9S)
229 \fIWriting Device Drivers\fR