]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/kstat.h
0b6ce0583e3c12e86d987aa6762c551a2b445e6e
[mirror_spl.git] / include / sys / kstat.h
1 #ifndef _SPL_KSTAT_H
2 #define _SPL_KSTAT_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <linux/module.h>
9 #include <sys/types.h>
10 #include <sys/time.h>
11
12 /* XXX - The minimum functionality here is stubbed out but nothing works. */
13
14 #define KSTAT_STRLEN 31 /* 30 chars + NULL; must be 16 * n - 1 */
15
16 #define KSTAT_TYPE_RAW 0 /* can be anything */
17 /* ks_ndata >= 1 */
18 #define KSTAT_TYPE_NAMED 1 /* name/value pair */
19 /* ks_ndata >= 1 */
20 #define KSTAT_TYPE_INTR 2 /* interrupt statistics */
21 /* ks_ndata == 1 */
22 #define KSTAT_TYPE_IO 3 /* I/O statistics */
23 /* ks_ndata == 1 */
24 #define KSTAT_TYPE_TIMER 4 /* event timer */
25 /* ks_ndata >= 1 */
26
27 #define KSTAT_NUM_TYPES 5
28
29
30 #define KSTAT_DATA_CHAR 0
31 #define KSTAT_DATA_INT32 1
32 #define KSTAT_DATA_UINT32 2
33 #define KSTAT_DATA_INT64 3
34 #define KSTAT_DATA_UINT64 4
35
36
37 #define KSTAT_FLAG_VIRTUAL 0x01
38 #define KSTAT_FLAG_VAR_SIZE 0x02
39 #define KSTAT_FLAG_WRITABLE 0x04
40 #define KSTAT_FLAG_PERSISTENT 0x08
41 #define KSTAT_FLAG_DORMANT 0x10
42 #define KSTAT_FLAG_INVALID 0x2
43
44
45 typedef int kid_t; /* unique kstat id */
46
47 typedef struct kstat_s {
48 /*
49 * Fields relevant to both kernel and user
50 */
51 hrtime_t ks_crtime; /* creation time (from gethrtime()) */
52 struct kstat_s *ks_next; /* kstat chain linkage */
53 kid_t ks_kid; /* unique kstat ID */
54 char ks_module[KSTAT_STRLEN]; /* provider module name */
55 uchar_t ks_resv; /* reserved, currently just padding */
56 int ks_instance; /* provider module's instance */
57 char ks_name[KSTAT_STRLEN]; /* kstat name */
58 uchar_t ks_type; /* kstat data type */
59 char ks_class[KSTAT_STRLEN]; /* kstat class */
60 uchar_t ks_flags; /* kstat flags */
61 void *ks_data; /* kstat type-specific data */
62 uint_t ks_ndata; /* # of type-specific data records */
63 size_t ks_data_size; /* total size of kstat data section */
64 hrtime_t ks_snaptime; /* time of last data shapshot */
65 /*
66 * Fields relevant to kernel only
67 */
68 int (*ks_update)(struct kstat *, int); /* dynamic update */
69 void *ks_private; /* arbitrary provider-private data */
70 int (*ks_snapshot)(struct kstat *, void *, int);
71 void *ks_lock; /* protects this kstat's data */
72 } kstat_t;
73
74 typedef struct kstat_named_s {
75 char name[KSTAT_STRLEN]; /* name of counter */
76 uchar_t data_type; /* data type */
77 union {
78 char c[16]; /* enough for 128-bit ints */
79 int32_t i32;
80 uint32_t ui32;
81 struct {
82 union {
83 char *ptr; /* NULL-term string */
84 char __pad[8]; /* 64-bit padding */
85 } addr;
86 uint32_t len; /* # bytes for strlen + '\0' */
87 } str;
88 /*
89 * The int64_t and uint64_t types are not valid for a maximally conformant
90 * 32-bit compilation environment (cc -Xc) using compilers prior to the
91 * introduction of C99 conforming compiler (reference ISO/IEC 9899:1990).
92 * In these cases, the visibility of i64 and ui64 is only permitted for
93 * 64-bit compilation environments or 32-bit non-maximally conformant
94 * C89 or C90 ANSI C compilation environments (cc -Xt and cc -Xa). In the
95 * C99 ANSI C compilation environment, the long long type is supported.
96 * The _INT64_TYPE is defined by the implementation (see sys/int_types.h).
97 */
98 int64_t i64;
99 uint64_t ui64;
100 long l;
101 ulong_t ul;
102
103 /* These structure members are obsolete */
104
105 longlong_t ll;
106 u_longlong_t ull;
107 float f;
108 double d;
109 } value; /* value of counter */
110 } kstat_named_t;
111
112
113 static __inline__ kstat_t *
114 kstat_create(const char *ks_module, int ks_instance, const char *ks_name,
115 const char *ks_class, uchar_t ks_type, uint_t ks_ndata,
116 uchar_t ks_flags)
117 {
118 return NULL;
119 }
120
121 static __inline__ void
122 kstat_install(kstat_t *ksp)
123 {
124 return;
125 }
126
127 static __inline__ void
128 kstat_delete(kstat_t *ksp)
129 {
130 return;
131 }
132
133 /* FIXME - NONE OF THIS IS ATOMIC, IT SHOULD BE. For the moment this is
134 * OK since it is only used for the noncritical kstat counters, and we
135 * are only doing testing on x86_86 platform where the entire counter
136 * will be updated with one instruction. */
137 static __inline__ void
138 atomic_inc_64(volatile uint64_t *target)
139 {
140 (*target)++;
141 }
142
143 static __inline__ void
144 atomic_dec_64(volatile uint64_t *target)
145 {
146 (*target)--;
147 }
148
149 static __inline__ uint64_t
150 atomic_add_64(volatile uint64_t *target, uint64_t delta)
151 {
152 uint64_t rc = *target;
153 *target += delta;
154 return rc;
155 }
156
157 static __inline__ uint64_t
158 atomic_add_64_nv(volatile uint64_t *target, uint64_t delta)
159 {
160 *target += delta;
161 return *target;
162 }
163
164 static __inline__ uint64_t
165 atomic_cas_64(volatile uint64_t *target, uint64_t cmp,
166 uint64_t newval)
167 {
168 uint64_t rc = *target;
169
170 if (*target == cmp)
171 *target = newval;
172
173 return rc;
174 }
175
176 #ifdef __cplusplus
177 }
178 #endif
179
180 #endif /* _SPL_KSTAT_H */
181