2 .\" Copyright (c) 2000, 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 9S "Apr 4, 1994"
8 kstat \- kernel statistics structure
12 #include <sys/types.h>
13 #include <sys/kstat.h>
15 #include <sys/sunddi.h>
21 Solaris DDI specific (Solaris DDI)
25 Each kernel statistic (\fBkstat\fR) exported by device drivers consists of a
26 header section and a data section. The \fBkstat\fR structure is the header
27 portion of the statistic.
30 A driver receives a pointer to a \fBkstat\fR structure from a successful call
31 to \fBkstat_create\fR(9F). Drivers should never allocate a \fBkstat\fR
32 structure in any other manner.
35 After allocation, the driver should perform any further initialization needed
36 before calling \fBkstat_install\fR(9F) to actually export the \fBkstat\fR.
41 void *ks_data; /* kstat type-specif. data */
42 ulong_t ks_ndata; /* # of type-specif. data
44 ulong_t ks_data_size; /* total size of kstat data
46 int (*ks_update)(struct kstat *, int);
47 void *ks_private; /* arbitrary provider-private
49 void *ks_lock; /* protects kstat's data */
55 The members of the \fBkstat\fR structure available to examine or set by a
56 driver are as follows:
63 Points to the data portion of the \fBkstat\fR. Either allocated by
64 \fBkstat_create\fR(9F) for the drivers use, or by the driver if it is using
74 The number of data records in this \fBkstat\fR. Set by the \fBks_update\fR(9E)
81 \fB\fBks_data_size\fR \fR
84 The amount of data pointed to by \fBks_data\fR. Set by the \fBks_update\fR(9E)
91 \fB\fBks_update\fR \fR
94 Pointer to a routine that dynamically updates \fBkstat\fR. This is useful for
95 drivers where the underlying device keeps cheap hardware statistics, but where
96 extraction is expensive. Instead of constantly keeping the \fBkstat\fR data
97 section up to date, the driver can supply a \fBks_update\fR(9E) function that
98 updates the \fBkstat\fR data section on demand. To take advantage of this
99 feature, set the \fBks_update\fR field before calling \fBkstat_install\fR(9F).
105 \fB\fBks_private\fR \fR
108 Is a private field for the driver's use. Often used in \fBks_update\fR(9E).
117 Is a pointer to a mutex that protects this \fBkstat\fR. \fBkstat\fR data
118 sections are optionally protected by the per-\fBkstat\fR \fBks_lock\fR. If
119 \fBks_lock\fR is non-\fINULL\fR, \fBkstat\fR clients (such as \fB/dev/kstat\fR)
120 will acquire this lock for all of their operations on that \fBkstat\fR. It is
121 up to the \fBkstat\fR provider to decide whether guaranteeing consistent data
122 to \fBkstat\fR clients is sufficiently important to justify the locking cost.
123 Note, however, that most statistic updates already occur under one of the
124 provider's mutexes. If the provider sets \fBks_lock\fR to point to that mutex,
125 then \fBkstat\fR data locking is free. \fBks_lock\fR is really of type
126 \fB(kmutex_t*)\fR and is declared as \fB(void*)\fR in the \fBkstat\fR header.
127 That way, users do not have to be exposed to all of the kernel's lock-related
134 \fBkstat_create\fR(9F)
137 \fIWriting Device Drivers\fR