1kstat(9S) Data Structures for Drivers kstat(9S)
2
3
4
6 kstat - kernel statistics structure
7
9 #include <sys/types.h>
10 #include <sys/kstat.h>
11 #include <sys/ddi.h>
12 #include <sys/sunddi.h>
13
14
16 Solaris DDI specific (Solaris DDI)
17
19 Each kernel statistic (kstat) exported by device drivers consists of a
20 header section and a data section. The kstat structure is the header
21 portion of the statistic.
22
23
24 A driver receives a pointer to a kstat structure from a successful call
25 to kstat_create(9F). Drivers should never allocate a kstat structure in
26 any other manner.
27
28
29 After allocation, the driver should perform any further initialization
30 needed before calling kstat_install(9F) to actually export the kstat.
31
33 void *ks_data; /* kstat type-specif. data */
34 ulong_t ks_ndata; /* # of type-specif. data
35 records */
36 ulong_t ks_data_size; /* total size of kstat data
37 section */
38 int (*ks_update)(struct kstat *, int);
39 void *ks_private; /* arbitrary provider-private
40 data */
41 void *ks_lock; /* protects kstat's data */
42
43
44
45 The members of the kstat structure available to examine or set by a
46 driver are as follows:
47
48 ks_data Points to the data portion of the kstat. Either allo‐
49 cated by kstat_create(9F) for the drivers use, or by
50 the driver if it is using virtual kstats.
51
52
53 ks_ndata The number of data records in this kstat. Set by the
54 ks_update(9E) routine.
55
56
57 ks_data_size The amount of data pointed to by ks_data. Set by the
58 ks_update(9E) routine.
59
60
61 ks_update Pointer to a routine that dynamically updates kstat.
62 This is useful for drivers where the underlying device
63 keeps cheap hardware statistics, but where extraction
64 is expensive. Instead of constantly keeping the kstat
65 data section up to date, the driver can supply a
66 ks_update(9E) function that updates the kstat data
67 section on demand. To take advantage of this feature,
68 set the ks_update field before calling
69 kstat_install(9F).
70
71
72 ks_private Is a private field for the driver's use. Often used in
73 ks_update(9E).
74
75
76 ks_lock Is a pointer to a mutex that protects this kstat.
77 kstat data sections are optionally protected by the
78 per-kstat ks_lock. If ks_lock is non-NULL, kstat
79 clients (such as /dev/kstat) will acquire this lock
80 for all of their operations on that kstat. It is up to
81 the kstat provider to decide whether guaranteeing con‐
82 sistent data to kstat clients is sufficiently impor‐
83 tant to justify the locking cost. Note, however, that
84 most statistic updates already occur under one of the
85 provider's mutexes. If the provider sets ks_lock to
86 point to that mutex, then kstat data locking is free.
87 ks_lock is really of type (kmutex_t*) and is declared
88 as (void*) in the kstat header. That way, users do not
89 have to be exposed to all of the kernel's lock-related
90 data structures.
91
92
94 kstat_create(9F)
95
96
97 Writing Device Drivers
98
99
100
101SunOS 5.11 4 Apr 1994 kstat(9S)