]>
Commit | Line | Data |
---|---|---|
716154c5 BB |
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>. | |
715f6251 BB |
6 | * UCRL-CODE-235197 |
7 | * | |
716154c5 | 8 | * This file is part of the SPL, Solaris Porting Layer. |
3d6af2dd | 9 | * For details, see <http://zfsonlinux.org/>. |
716154c5 BB |
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. | |
715f6251 | 15 | * |
716154c5 | 16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT |
715f6251 BB |
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 | |
716154c5 BB |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. |
23 | \*****************************************************************************/ | |
715f6251 | 24 | |
09b414e8 BB |
25 | #ifndef _SPL_KSTAT_H |
26 | #define _SPL_KSTAT_H | |
f1ca4da6 | 27 | |
f1b59d26 | 28 | #include <linux/module.h> |
ae4c36ad | 29 | #include <linux/proc_compat.h> |
f4b37741 BB |
30 | #include <sys/types.h> |
31 | #include <sys/time.h> | |
04a479f7 | 32 | #include <sys/kmem.h> |
71c9f0b0 | 33 | #include <sys/mutex.h> |
f1ca4da6 | 34 | |
9df96926 | 35 | #define KSTAT_STRLEN 255 |
56d40a68 | 36 | #define KSTAT_RAW_MAX (128*1024) |
f1ca4da6 | 37 | |
04a479f7 BB |
38 | /* For reference valid classes are: |
39 | * disk, tape, net, controller, vm, kvm, hat, streams, kstat, misc | |
40 | */ | |
f1ca4da6 | 41 | |
04a479f7 BB |
42 | #define KSTAT_TYPE_RAW 0 /* can be anything; ks_ndata >= 1 */ |
43 | #define KSTAT_TYPE_NAMED 1 /* name/value pair; ks_ndata >= 1 */ | |
44 | #define KSTAT_TYPE_INTR 2 /* interrupt stats; ks_ndata == 1 */ | |
45 | #define KSTAT_TYPE_IO 3 /* I/O stats; ks_ndata == 1 */ | |
46 | #define KSTAT_TYPE_TIMER 4 /* event timer; ks_ndata >= 1 */ | |
ce07767f | 47 | #define KSTAT_NUM_TYPES 5 |
f1ca4da6 | 48 | |
f1ca4da6 BB |
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 | |
04a479f7 BB |
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 | |
f1ca4da6 | 65 | |
04a479f7 BB |
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) | |
f1ca4da6 | 73 | |
f1ca4da6 | 74 | |
04a479f7 | 75 | #define KS_MAGIC 0x9d9d9d9d |
f1ca4da6 | 76 | |
9a8b7a74 BB |
77 | /* Dynamic updates */ |
78 | #define KSTAT_READ 0 | |
79 | #define KSTAT_WRITE 1 | |
80 | ||
81 | struct kstat_s; | |
56d40a68 | 82 | typedef struct kstat_s kstat_t; |
9a8b7a74 BB |
83 | |
84 | typedef int kid_t; /* unique kstat id */ | |
85 | typedef int kstat_update_t(struct kstat_s *, int); /* dynamic update cb */ | |
f1ca4da6 | 86 | |
f2a745c4 RY |
87 | typedef struct kstat_module { |
88 | char ksm_name[KSTAT_STRLEN+1]; /* module name */ | |
89 | struct list_head ksm_module_list; /* module linkage */ | |
90 | struct list_head ksm_kstat_list; /* list of kstat entries */ | |
91 | struct proc_dir_entry *ksm_proc; /* proc entry */ | |
92 | } kstat_module_t; | |
93 | ||
56d40a68 PS |
94 | typedef struct kstat_raw_ops { |
95 | int (*headers)(char *buf, size_t size); | |
96 | int (*data)(char *buf, size_t size, void *data); | |
97 | void *(*addr)(kstat_t *ksp, loff_t index); | |
98 | } kstat_raw_ops_t; | |
99 | ||
100 | struct kstat_s { | |
04a479f7 BB |
101 | int ks_magic; /* magic value */ |
102 | kid_t ks_kid; /* unique kstat ID */ | |
103 | hrtime_t ks_crtime; /* creation time */ | |
104 | hrtime_t ks_snaptime; /* last access time */ | |
105 | char ks_module[KSTAT_STRLEN+1]; /* provider module name */ | |
106 | int ks_instance; /* provider module instance */ | |
107 | char ks_name[KSTAT_STRLEN+1]; /* kstat name */ | |
108 | char ks_class[KSTAT_STRLEN+1]; /* kstat class */ | |
109 | uchar_t ks_type; /* kstat data type */ | |
110 | uchar_t ks_flags; /* kstat flags */ | |
111 | void *ks_data; /* kstat type-specific data */ | |
112 | uint_t ks_ndata; /* # of type-specific data records */ | |
113 | size_t ks_data_size; /* size of kstat data section */ | |
114 | struct proc_dir_entry *ks_proc; /* proc linkage */ | |
9a8b7a74 BB |
115 | kstat_update_t *ks_update; /* dynamic updates */ |
116 | void *ks_private; /* private data */ | |
ffbf0e57 CP |
117 | kmutex_t ks_private_lock; /* kstat private data lock */ |
118 | kmutex_t *ks_lock; /* kstat data lock */ | |
04a479f7 | 119 | struct list_head ks_list; /* kstat linkage */ |
f2a745c4 | 120 | kstat_module_t *ks_owner; /* kstat module linkage */ |
56d40a68 PS |
121 | kstat_raw_ops_t ks_raw_ops; /* ops table for raw type */ |
122 | char *ks_raw_buf; /* buf used for raw ops */ | |
123 | size_t ks_raw_bufsize; /* size of raw ops buffer */ | |
124 | }; | |
f1ca4da6 BB |
125 | |
126 | typedef struct kstat_named_s { | |
04a479f7 BB |
127 | char name[KSTAT_STRLEN]; /* name of counter */ |
128 | uchar_t data_type; /* data type */ | |
f1ca4da6 | 129 | union { |
04a479f7 BB |
130 | char c[16]; /* 128-bit int */ |
131 | int32_t i32; /* 32-bit signed int */ | |
132 | uint32_t ui32; /* 32-bit unsigned int */ | |
133 | int64_t i64; /* 64-bit signed int */ | |
134 | uint64_t ui64; /* 64-bit unsigned int */ | |
135 | long l; /* native signed long */ | |
136 | ulong_t ul; /* native unsigned long */ | |
f1ca4da6 BB |
137 | struct { |
138 | union { | |
04a479f7 BB |
139 | char *ptr; /* NULL-term string */ |
140 | char __pad[8]; /* 64-bit padding */ | |
f1ca4da6 | 141 | } addr; |
04a479f7 BB |
142 | uint32_t len; /* # bytes for strlen + '\0' */ |
143 | } string; | |
144 | } value; | |
f1ca4da6 BB |
145 | } kstat_named_t; |
146 | ||
04a479f7 BB |
147 | #define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.string.addr.ptr) |
148 | #define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.string.len) | |
149 | ||
150 | typedef struct kstat_intr { | |
151 | uint_t intrs[KSTAT_NUM_INTRS]; | |
152 | } kstat_intr_t; | |
153 | ||
154 | typedef struct kstat_io { | |
155 | u_longlong_t nread; /* number of bytes read */ | |
156 | u_longlong_t nwritten; /* number of bytes written */ | |
157 | uint_t reads; /* number of read operations */ | |
158 | uint_t writes; /* number of write operations */ | |
159 | hrtime_t wtime; /* cumulative wait (pre-service) time */ | |
160 | hrtime_t wlentime; /* cumulative wait length*time product*/ | |
161 | hrtime_t wlastupdate; /* last time wait queue changed */ | |
162 | hrtime_t rtime; /* cumulative run (service) time */ | |
163 | hrtime_t rlentime; /* cumulative run length*time product */ | |
164 | hrtime_t rlastupdate; /* last time run queue changed */ | |
165 | uint_t wcnt; /* count of elements in wait state */ | |
166 | uint_t rcnt; /* count of elements in run state */ | |
167 | } kstat_io_t; | |
168 | ||
169 | typedef struct kstat_timer { | |
170 | char name[KSTAT_STRLEN+1]; /* event name */ | |
171 | u_longlong_t num_events; /* number of events */ | |
172 | hrtime_t elapsed_time; /* cumulative elapsed time */ | |
173 | hrtime_t min_time; /* shortest event duration */ | |
174 | hrtime_t max_time; /* longest event duration */ | |
175 | hrtime_t start_time; /* previous event start time */ | |
176 | hrtime_t stop_time; /* previous event stop time */ | |
177 | } kstat_timer_t; | |
178 | ||
1114ae6a BB |
179 | int spl_kstat_init(void); |
180 | void spl_kstat_fini(void); | |
04a479f7 | 181 | |
56d40a68 PS |
182 | extern void __kstat_set_raw_ops(kstat_t *ksp, |
183 | int (*headers)(char *buf, size_t size), | |
184 | int (*data)(char *buf, size_t size, void *data), | |
185 | void* (*addr)(kstat_t *ksp, loff_t index)); | |
04a479f7 BB |
186 | extern kstat_t *__kstat_create(const char *ks_module, int ks_instance, |
187 | const char *ks_name, const char *ks_class, | |
188 | uchar_t ks_type, uint_t ks_ndata, | |
189 | uchar_t ks_flags); | |
190 | extern void __kstat_install(kstat_t *ksp); | |
191 | extern void __kstat_delete(kstat_t *ksp); | |
f483a97a NB |
192 | extern void kstat_waitq_enter(kstat_io_t *); |
193 | extern void kstat_waitq_exit(kstat_io_t *); | |
194 | extern void kstat_runq_enter(kstat_io_t *); | |
195 | extern void kstat_runq_exit(kstat_io_t *); | |
04a479f7 | 196 | |
56d40a68 | 197 | #define kstat_set_raw_ops(k,h,d,a) __kstat_set_raw_ops(k,h,d,a) |
04a479f7 BB |
198 | #define kstat_create(m,i,n,c,t,s,f) __kstat_create(m,i,n,c,t,s,f) |
199 | #define kstat_install(k) __kstat_install(k) | |
200 | #define kstat_delete(k) __kstat_delete(k) | |
201 | ||
09b414e8 | 202 | #endif /* _SPL_KSTAT_H */ |