]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/kstat.h
06379f827e9e4433d9c230e9d52755496a92dc3d
[mirror_spl-debian.git] / include / sys / kstat.h
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
24
25 #ifndef _SPL_KSTAT_H
26 #define _SPL_KSTAT_H
27
28 #include <linux/module.h>
29 #include <linux/proc_compat.h>
30 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <sys/kmem.h>
33 #include <sys/mutex.h>
34
35 #define KSTAT_STRLEN 31
36
37 /* For reference valid classes are:
38 * disk, tape, net, controller, vm, kvm, hat, streams, kstat, misc
39 */
40
41 #define KSTAT_TYPE_RAW 0 /* can be anything; ks_ndata >= 1 */
42 #define KSTAT_TYPE_NAMED 1 /* name/value pair; ks_ndata >= 1 */
43 #define KSTAT_TYPE_INTR 2 /* interrupt stats; ks_ndata == 1 */
44 #define KSTAT_TYPE_IO 3 /* I/O stats; ks_ndata == 1 */
45 #define KSTAT_TYPE_TIMER 4 /* event timer; ks_ndata >= 1 */
46 #define KSTAT_TYPE_TXG 5 /* txg sync; ks_ndata >= 1 */
47 #define KSTAT_NUM_TYPES 6
48
49 #define KSTAT_DATA_CHAR 0
50 #define KSTAT_DATA_INT32 1
51 #define KSTAT_DATA_UINT32 2
52 #define KSTAT_DATA_INT64 3
53 #define KSTAT_DATA_UINT64 4
54 #define KSTAT_DATA_LONG 5
55 #define KSTAT_DATA_ULONG 6
56 #define KSTAT_DATA_STRING 7
57 #define KSTAT_NUM_DATAS 8
58
59 #define KSTAT_INTR_HARD 0
60 #define KSTAT_INTR_SOFT 1
61 #define KSTAT_INTR_WATCHDOG 2
62 #define KSTAT_INTR_SPURIOUS 3
63 #define KSTAT_INTR_MULTSVC 4
64 #define KSTAT_NUM_INTRS 5
65
66 #define KSTAT_FLAG_VIRTUAL 0x01
67 #define KSTAT_FLAG_VAR_SIZE 0x02
68 #define KSTAT_FLAG_WRITABLE 0x04
69 #define KSTAT_FLAG_PERSISTENT 0x08
70 #define KSTAT_FLAG_DORMANT 0x10
71 #define KSTAT_FLAG_UNSUPPORTED (KSTAT_FLAG_VAR_SIZE | KSTAT_FLAG_WRITABLE | \
72 KSTAT_FLAG_PERSISTENT | KSTAT_FLAG_DORMANT)
73
74
75 #define KS_MAGIC 0x9d9d9d9d
76
77 /* Dynamic updates */
78 #define KSTAT_READ 0
79 #define KSTAT_WRITE 1
80
81 struct kstat_s;
82
83 typedef int kid_t; /* unique kstat id */
84 typedef int kstat_update_t(struct kstat_s *, int); /* dynamic update cb */
85
86 typedef struct kstat_s {
87 int ks_magic; /* magic value */
88 kid_t ks_kid; /* unique kstat ID */
89 hrtime_t ks_crtime; /* creation time */
90 hrtime_t ks_snaptime; /* last access time */
91 char ks_module[KSTAT_STRLEN+1]; /* provider module name */
92 int ks_instance; /* provider module instance */
93 char ks_name[KSTAT_STRLEN+1]; /* kstat name */
94 char ks_class[KSTAT_STRLEN+1]; /* kstat class */
95 uchar_t ks_type; /* kstat data type */
96 uchar_t ks_flags; /* kstat flags */
97 void *ks_data; /* kstat type-specific data */
98 uint_t ks_ndata; /* # of type-specific data records */
99 size_t ks_data_size; /* size of kstat data section */
100 struct proc_dir_entry *ks_proc; /* proc linkage */
101 kstat_update_t *ks_update; /* dynamic updates */
102 void *ks_private; /* private data */
103 kmutex_t ks_lock; /* kstat data lock */
104 struct list_head ks_list; /* kstat linkage */
105 } kstat_t;
106
107 typedef struct kstat_named_s {
108 char name[KSTAT_STRLEN]; /* name of counter */
109 uchar_t data_type; /* data type */
110 union {
111 char c[16]; /* 128-bit int */
112 int32_t i32; /* 32-bit signed int */
113 uint32_t ui32; /* 32-bit unsigned int */
114 int64_t i64; /* 64-bit signed int */
115 uint64_t ui64; /* 64-bit unsigned int */
116 long l; /* native signed long */
117 ulong_t ul; /* native unsigned long */
118 struct {
119 union {
120 char *ptr; /* NULL-term string */
121 char __pad[8]; /* 64-bit padding */
122 } addr;
123 uint32_t len; /* # bytes for strlen + '\0' */
124 } string;
125 } value;
126 } kstat_named_t;
127
128 #define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.string.addr.ptr)
129 #define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.string.len)
130
131 typedef struct kstat_intr {
132 uint_t intrs[KSTAT_NUM_INTRS];
133 } kstat_intr_t;
134
135 typedef struct kstat_io {
136 u_longlong_t nread; /* number of bytes read */
137 u_longlong_t nwritten; /* number of bytes written */
138 uint_t reads; /* number of read operations */
139 uint_t writes; /* number of write operations */
140 hrtime_t wtime; /* cumulative wait (pre-service) time */
141 hrtime_t wlentime; /* cumulative wait length*time product*/
142 hrtime_t wlastupdate; /* last time wait queue changed */
143 hrtime_t rtime; /* cumulative run (service) time */
144 hrtime_t rlentime; /* cumulative run length*time product */
145 hrtime_t rlastupdate; /* last time run queue changed */
146 uint_t wcnt; /* count of elements in wait state */
147 uint_t rcnt; /* count of elements in run state */
148 } kstat_io_t;
149
150 typedef struct kstat_timer {
151 char name[KSTAT_STRLEN+1]; /* event name */
152 u_longlong_t num_events; /* number of events */
153 hrtime_t elapsed_time; /* cumulative elapsed time */
154 hrtime_t min_time; /* shortest event duration */
155 hrtime_t max_time; /* longest event duration */
156 hrtime_t start_time; /* previous event start time */
157 hrtime_t stop_time; /* previous event stop time */
158 } kstat_timer_t;
159
160 typedef enum kstat_txg_state {
161 TXG_STATE_OPEN = 1,
162 TXG_STATE_QUIESCING = 2,
163 TXG_STATE_SYNCING = 3,
164 TXG_STATE_COMMITTED = 4,
165 } kstat_txg_state_t;
166
167 typedef struct kstat_txg {
168 u_longlong_t txg; /* txg id */
169 kstat_txg_state_t state; /* txg state */
170 hrtime_t birth; /* birth time stamp */
171 u_longlong_t nread; /* number of bytes read */
172 u_longlong_t nwritten; /* number of bytes written */
173 uint_t reads; /* number of read operations */
174 uint_t writes; /* number of write operations */
175 hrtime_t open_time; /* open time */
176 hrtime_t quiesce_time;/* quiesce time */
177 hrtime_t sync_time; /* sync time */
178 } kstat_txg_t;
179
180 int spl_kstat_init(void);
181 void spl_kstat_fini(void);
182
183 extern kstat_t *__kstat_create(const char *ks_module, int ks_instance,
184 const char *ks_name, const char *ks_class,
185 uchar_t ks_type, uint_t ks_ndata,
186 uchar_t ks_flags);
187 extern void __kstat_install(kstat_t *ksp);
188 extern void __kstat_delete(kstat_t *ksp);
189
190 #define kstat_create(m,i,n,c,t,s,f) __kstat_create(m,i,n,c,t,s,f)
191 #define kstat_install(k) __kstat_install(k)
192 #define kstat_delete(k) __kstat_delete(k)
193
194 #endif /* _SPL_KSTAT_H */