]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/kstat.h
1ce084729fa15cb41f7b0609d6e26f172d92ae37
[mirror_spl-debian.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 #define DEBUG_KSTAT
9
10 #include <linux/module.h>
11 #include <sys/types.h>
12 #include <sys/time.h>
13 #include <sys/kmem.h>
14 #include <sys/proc.h>
15
16 #define KSTAT_STRLEN 31
17
18 /* For reference valid classes are:
19 * disk, tape, net, controller, vm, kvm, hat, streams, kstat, misc
20 */
21
22 #define KSTAT_TYPE_RAW 0 /* can be anything; ks_ndata >= 1 */
23 #define KSTAT_TYPE_NAMED 1 /* name/value pair; ks_ndata >= 1 */
24 #define KSTAT_TYPE_INTR 2 /* interrupt stats; ks_ndata == 1 */
25 #define KSTAT_TYPE_IO 3 /* I/O stats; ks_ndata == 1 */
26 #define KSTAT_TYPE_TIMER 4 /* event timer; ks_ndata >= 1 */
27 #define KSTAT_NUM_TYPES 5
28
29 #define KSTAT_DATA_CHAR 0
30 #define KSTAT_DATA_INT32 1
31 #define KSTAT_DATA_UINT32 2
32 #define KSTAT_DATA_INT64 3
33 #define KSTAT_DATA_UINT64 4
34 #define KSTAT_DATA_LONG 5
35 #define KSTAT_DATA_ULONG 6
36 #define KSTAT_DATA_STRING 7
37 #define KSTAT_NUM_DATAS 8
38
39 #define KSTAT_INTR_HARD 0
40 #define KSTAT_INTR_SOFT 1
41 #define KSTAT_INTR_WATCHDOG 2
42 #define KSTAT_INTR_SPURIOUS 3
43 #define KSTAT_INTR_MULTSVC 4
44 #define KSTAT_NUM_INTRS 5
45
46 #define KSTAT_FLAG_VIRTUAL 0x01
47 #define KSTAT_FLAG_VAR_SIZE 0x02
48 #define KSTAT_FLAG_WRITABLE 0x04
49 #define KSTAT_FLAG_PERSISTENT 0x08
50 #define KSTAT_FLAG_DORMANT 0x10
51 #define KSTAT_FLAG_UNSUPPORTED (KSTAT_FLAG_VAR_SIZE | KSTAT_FLAG_WRITABLE | \
52 KSTAT_FLAG_PERSISTENT | KSTAT_FLAG_DORMANT)
53
54
55 #define KS_MAGIC 0x9d9d9d9d
56
57 typedef int kid_t; /* unique kstat id */
58
59 typedef struct kstat_s {
60 int ks_magic; /* magic value */
61 kid_t ks_kid; /* unique kstat ID */
62 hrtime_t ks_crtime; /* creation time */
63 hrtime_t ks_snaptime; /* last access time */
64 char ks_module[KSTAT_STRLEN+1]; /* provider module name */
65 int ks_instance; /* provider module instance */
66 char ks_name[KSTAT_STRLEN+1]; /* kstat name */
67 char ks_class[KSTAT_STRLEN+1]; /* kstat class */
68 uchar_t ks_type; /* kstat data type */
69 uchar_t ks_flags; /* kstat flags */
70 void *ks_data; /* kstat type-specific data */
71 uint_t ks_ndata; /* # of type-specific data records */
72 size_t ks_data_size; /* size of kstat data section */
73 struct proc_dir_entry *ks_proc; /* proc linkage */
74 spinlock_t ks_lock; /* kstat data lock */
75 struct list_head ks_list; /* kstat linkage */
76 } kstat_t;
77
78 typedef struct kstat_named_s {
79 char name[KSTAT_STRLEN]; /* name of counter */
80 uchar_t data_type; /* data type */
81 union {
82 char c[16]; /* 128-bit int */
83 int32_t i32; /* 32-bit signed int */
84 uint32_t ui32; /* 32-bit unsigned int */
85 int64_t i64; /* 64-bit signed int */
86 uint64_t ui64; /* 64-bit unsigned int */
87 long l; /* native signed long */
88 ulong_t ul; /* native unsigned long */
89 struct {
90 union {
91 char *ptr; /* NULL-term string */
92 char __pad[8]; /* 64-bit padding */
93 } addr;
94 uint32_t len; /* # bytes for strlen + '\0' */
95 } string;
96 } value;
97 } kstat_named_t;
98
99 #define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.string.addr.ptr)
100 #define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.string.len)
101
102 typedef struct kstat_intr {
103 uint_t intrs[KSTAT_NUM_INTRS];
104 } kstat_intr_t;
105
106 typedef struct kstat_io {
107 u_longlong_t nread; /* number of bytes read */
108 u_longlong_t nwritten; /* number of bytes written */
109 uint_t reads; /* number of read operations */
110 uint_t writes; /* number of write operations */
111 hrtime_t wtime; /* cumulative wait (pre-service) time */
112 hrtime_t wlentime; /* cumulative wait length*time product*/
113 hrtime_t wlastupdate; /* last time wait queue changed */
114 hrtime_t rtime; /* cumulative run (service) time */
115 hrtime_t rlentime; /* cumulative run length*time product */
116 hrtime_t rlastupdate; /* last time run queue changed */
117 uint_t wcnt; /* count of elements in wait state */
118 uint_t rcnt; /* count of elements in run state */
119 } kstat_io_t;
120
121 typedef struct kstat_timer {
122 char name[KSTAT_STRLEN+1]; /* event name */
123 u_longlong_t num_events; /* number of events */
124 hrtime_t elapsed_time; /* cumulative elapsed time */
125 hrtime_t min_time; /* shortest event duration */
126 hrtime_t max_time; /* longest event duration */
127 hrtime_t start_time; /* previous event start time */
128 hrtime_t stop_time; /* previous event stop time */
129 } kstat_timer_t;
130
131 int kstat_init(void);
132 void kstat_fini(void);
133
134 #ifdef DEBUG_KSTAT
135 extern kstat_t *__kstat_create(const char *ks_module, int ks_instance,
136 const char *ks_name, const char *ks_class,
137 uchar_t ks_type, uint_t ks_ndata,
138 uchar_t ks_flags);
139 extern void __kstat_install(kstat_t *ksp);
140 extern void __kstat_delete(kstat_t *ksp);
141
142 #define kstat_create(m,i,n,c,t,s,f) __kstat_create(m,i,n,c,t,s,f)
143 #define kstat_install(k) __kstat_install(k)
144 #define kstat_delete(k) __kstat_delete(k)
145
146 #else
147
148 #define kstat_create(m,i,n,c,t,s,f) (NULL)
149 #define kstat_install(k) ((void)0)
150 #define kstat_delete(k) ((void)0)
151
152 #endif /* DEBUG_KSTAT */
153
154 #ifdef __cplusplus
155 }
156 #endif
157
158 #endif /* _SPL_KSTAT_H */
159