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 "Sep 7, 2015"
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);
24 Solaris DDI specific (Solaris DDI).
31 Pointer to a \fBkstat\fR(9S) structure.
40 Pointer to a buffer to copy the snapshot into.
49 Read/Write flag. Possible values are:
53 \fB\fBKSTAT_READ\fR\fR
56 Copy driver statistics from the driver to the buffer.
62 \fB\fBKSTAT_WRITE\fR\fR
65 Copy statistics from the buffer to the driver.
72 The \fBkstat\fR mechanism allows for an optional \fBks_snapshot()\fR function
73 to copy \fBkstat\fR data. This is the routine that is called to marshall the
74 \fBkstat\fR data to be copied to user-land. A driver can opt to use a custom
75 snapshot routine rather than the default snapshot routine; to take advantage of
76 this feature, set the \fBks_snapshot\fR field before calling
77 \fBkstat_install\fR(9F).
80 The \fBks_snapshot()\fR function must have the following structure:
85 xx_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
87 if (rw == KSTAT_WRITE) {
88 /* set the native stats to the values in buf */
89 /* return EACCES if you don't support this */
91 /* copy the kstat-specific data into buf */
101 In general, the \fBks_snapshot()\fR routine might need to refer to
102 provider-private data; for example, it might need a pointer to the provider's
103 raw statistics. The \fBks_private\fR field is available for this purpose. Its
104 use is entirely at the provider's discretion.
107 No \fBkstat\fR locking should be done inside the \fBks_snapshot()\fR routine. The
108 caller will already be holding the \fBkstat\fR's \fBks_lock\fR (to ensure
109 consistent data) and will prevent the \fBkstat\fR from being removed.
113 \fBks_snaptime\fR must be set (via \fBgethrtime\fR(9F)) to timestamp the
119 Data gets copied from the \fBkstat\fR to the buffer on \fBKSTAT_READ\fR, and
120 from the buffer to the \fBkstat\fR on \fBKSTAT_WRITE\fR.
137 If \fBKSTAT_WRITE\fR is not allowed
151 This function is called from user context only.
154 \fBExample 1 \fRNamed \fBkstat\fRs with Long Strings (\fBKSTAT_DATA_STRING\fR)
159 xxx_kstat_snapshot(kstat_t *ksp, void *buf, int rw)
161 if (rw == KSTAT_WRITE) {
164 kstat_named_t *knp = buf;
165 char *end = knp + ksp->ks_ndata;
168 bcopy(ksp->ks_data, buf,
169 sizeof (kstat_named_t) * ksp->ks_ndata);
171 * Now copy the strings to the end of the buffer, and
172 * update the pointers appropriately.
174 for (i = 0; i < ksp->ks_ndata; i++, knp++)
175 if (knp->data_type == KSTAT_DATA_STRING &&
176 KSTAT_NAMED_STR_PTR(knp) != NULL) {
177 bcopy(KSTAT_NAMED_STR_PTR(knp), end,
178 KSTAT_NAMED_STR_BUFLEN(knp));
179 KSTAT_NAMED_STR_PTR(knp) = end;
180 end += KSTAT_NAMED_STR_BUFLEN(knp);
191 \fBks_update\fR(9E), \fBkstat_create\fR(9F), \fBkstat_install\fR(9F),
195 \fIWriting Device Drivers\fR