2 .\" Copyright (c) 2002, 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 KS_SNAPSHOT 9E "Dec 4, 2002"
8 ks_snapshot \- take a snapshot of kstat data
12 #include <sys/types.h>
13 #include <sys/kstat.h>
15 #include <sys/sunddi.h>
19 \fBint prefix\fR\fB_ks_snapshot\fR(\fBkstat_t *\fR\fIksp\fR, \fBvoid *\fR\fIbuf\fR, \fBint\fR \fIrw\fR);
25 Solaris DDI specific (Solaris DDI).
33 Pointer to a \fBkstat\fR(9S) structure.
42 Pointer to a buffer to copy the snapshot into.
51 Read/Write flag. Possible values are:
55 \fB\fBKSTAT_READ\fR\fR
58 Copy driver statistics from the driver to the buffer.
64 \fB\fBKSTAT_WRITE\fR\fR
67 Copy statistics from the buffer to the driver.
75 The \fBkstat\fR mechanism allows for an optional \fBks_snapshot()\fR function
76 to copy \fBkstat\fR data. This is the routine that is called to marshall the
77 \fBkstat\fR data to be copied to user-land. A driver can opt to use a custom
78 snapshot routine rather than the default snapshot routine; to take advantage of
79 this feature, set the \fBks_snapshot\fR field before calling
80 \fBkstat_install\fR(9F).
83 The \fBks_snapshot()\fR function must have the following structure:
88 xx_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
90 if (rw == KSTAT_WRITE) {
91 /* set the native stats to the values in buf */
92 /* return EACCES if you don't support this */
94 /* copy the kstat-specific data into buf */
104 In general, the \fBks_snapshot()\fR routine might need to refer to
105 provider-private data; for example, it might need a pointer to the provider's
106 raw statistics. The \fBks_private\fR field is available for this purpose. Its
107 use is entirely at the provider's discretion.
110 No \fBkstat\fR locking should be done inside the \fBks_update()\fR routine. The
111 caller will already be holding the \fBkstat\fR's \fBks_lock\fR (to ensure
112 consistent data) and will prevent the \fBkstat\fR from being removed.
116 \fBks_snaptime\fR must be set (via \fBgethrtime\fR(9F)) to timestamp the
122 Data gets copied from the \fBkstat\fR to the buffer on \fBKSTAT_READ\fR, and
123 from the buffer to the \fBkstat\fR on \fBKSTAT_WRITE\fR.
141 If \fBKSTAT_WRITE\fR is not allowed
156 This function is called from user context only.
159 \fBExample 1 \fRNamed \fBkstat\fRs with Long Strings (\fBKSTAT_DATA_STRING\fR)
164 xxx_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
166 if (rw == KSTAT_WRITE) {
169 kstat_named_t *knp = buf;
170 char *end = knp + ksp->ks_ndata;
173 bcopy(ksp->ks_data, buf,
174 sizeof (kstat_named_t) * ksp->ks_ndata);
176 * Now copy the strings to the end of the buffer, and
177 * update the pointers appropriately.
179 for (i = 0; i < ksp->ks_ndata; i++, knp++)
180 if (knp->data_type == KSTAT_DATA_STRING &&
181 KSTAT_NAMED_STR_PTR(knp) != NULL) {
182 bcopy(KSTAT_NAMED_STR_PTR(knp), end,
183 KSTAT_NAMED_STR_BUFLEN(knp));
184 KSTAT_NAMED_STR_PTR(knp) = end;
185 end += KSTAT_NAMED_STR_BUFLEN(knp);
197 \fBks_update\fR(9E), \fBkstat_create\fR(9F), \fBkstat_install\fR(9F),
201 \fIWriting Device Drivers\fR