]> git.proxmox.com Git - mirror_zfs.git/blame - include/spl/sys/kstat.h
Fixes for procfs files backed by linked lists
[mirror_zfs.git] / include / spl / sys / kstat.h
CommitLineData
4b393c50 1/*
716154c5
BB
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 22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
4b393c50 23 */
715f6251 24
09b414e8 25#ifndef _SPL_KSTAT_H
5461eefe 26#define _SPL_KSTAT_H
f1ca4da6 27
f1b59d26 28#include <linux/module.h>
f4b37741
BB
29#include <sys/types.h>
30#include <sys/time.h>
04a479f7 31#include <sys/kmem.h>
71c9f0b0 32#include <sys/mutex.h>
a9125891 33#include <sys/proc.h>
f1ca4da6 34
5461eefe
BB
35#define KSTAT_STRLEN 255
36#define KSTAT_RAW_MAX (128*1024)
f1ca4da6 37
5461eefe
BB
38/*
39 * For reference valid classes are:
04a479f7
BB
40 * disk, tape, net, controller, vm, kvm, hat, streams, kstat, misc
41 */
f1ca4da6 42
5461eefe
BB
43#define KSTAT_TYPE_RAW 0 /* can be anything; ks_ndata >= 1 */
44#define KSTAT_TYPE_NAMED 1 /* name/value pair; ks_ndata >= 1 */
45#define KSTAT_TYPE_INTR 2 /* interrupt stats; ks_ndata == 1 */
46#define KSTAT_TYPE_IO 3 /* I/O stats; ks_ndata == 1 */
47#define KSTAT_TYPE_TIMER 4 /* event timer; ks_ndata >= 1 */
48#define KSTAT_NUM_TYPES 5
49
50#define KSTAT_DATA_CHAR 0
51#define KSTAT_DATA_INT32 1
52#define KSTAT_DATA_UINT32 2
53#define KSTAT_DATA_INT64 3
54#define KSTAT_DATA_UINT64 4
55#define KSTAT_DATA_LONG 5
56#define KSTAT_DATA_ULONG 6
57#define KSTAT_DATA_STRING 7
58#define KSTAT_NUM_DATAS 8
59
60#define KSTAT_INTR_HARD 0
61#define KSTAT_INTR_SOFT 1
62#define KSTAT_INTR_WATCHDOG 2
63#define KSTAT_INTR_SPURIOUS 3
64#define KSTAT_INTR_MULTSVC 4
65#define KSTAT_NUM_INTRS 5
66
67#define KSTAT_FLAG_VIRTUAL 0x01
68#define KSTAT_FLAG_VAR_SIZE 0x02
69#define KSTAT_FLAG_WRITABLE 0x04
70#define KSTAT_FLAG_PERSISTENT 0x08
71#define KSTAT_FLAG_DORMANT 0x10
f0ed6c74
TH
72#define KSTAT_FLAG_INVALID 0x20
73#define KSTAT_FLAG_LONGSTRINGS 0x40
74#define KSTAT_FLAG_NO_HEADERS 0x80
5461eefe
BB
75
76#define KS_MAGIC 0x9d9d9d9d
f1ca4da6 77
9a8b7a74 78/* Dynamic updates */
5461eefe
BB
79#define KSTAT_READ 0
80#define KSTAT_WRITE 1
9a8b7a74
BB
81
82struct kstat_s;
56d40a68 83typedef struct kstat_s kstat_t;
9a8b7a74 84
5461eefe
BB
85typedef int kid_t; /* unique kstat id */
86typedef int kstat_update_t(struct kstat_s *, int); /* dynamic update cb */
f1ca4da6 87
f2a745c4 88typedef struct kstat_module {
5461eefe
BB
89 char ksm_name[KSTAT_STRLEN+1]; /* module name */
90 struct list_head ksm_module_list; /* module linkage */
91 struct list_head ksm_kstat_list; /* list of kstat entries */
92 struct proc_dir_entry *ksm_proc; /* proc entry */
f2a745c4
RY
93} kstat_module_t;
94
56d40a68
PS
95typedef struct kstat_raw_ops {
96 int (*headers)(char *buf, size_t size);
97 int (*data)(char *buf, size_t size, void *data);
98 void *(*addr)(kstat_t *ksp, loff_t index);
99} kstat_raw_ops_t;
100
d1261452
JG
101typedef struct kstat_proc_entry {
102 char kpe_name[KSTAT_STRLEN+1]; /* kstat name */
103 char kpe_module[KSTAT_STRLEN+1]; /* provider module name */
104 kstat_module_t *kpe_owner; /* kstat module linkage */
105 struct list_head kpe_list; /* kstat linkage */
106 struct proc_dir_entry *kpe_proc; /* procfs entry */
107} kstat_proc_entry_t;
108
56d40a68 109struct kstat_s {
5461eefe
BB
110 int ks_magic; /* magic value */
111 kid_t ks_kid; /* unique kstat ID */
112 hrtime_t ks_crtime; /* creation time */
113 hrtime_t ks_snaptime; /* last access time */
5461eefe 114 int ks_instance; /* provider module instance */
5461eefe
BB
115 char ks_class[KSTAT_STRLEN+1]; /* kstat class */
116 uchar_t ks_type; /* kstat data type */
117 uchar_t ks_flags; /* kstat flags */
118 void *ks_data; /* kstat type-specific data */
119 uint_t ks_ndata; /* # of data records */
120 size_t ks_data_size; /* size of kstat data section */
5461eefe
BB
121 kstat_update_t *ks_update; /* dynamic updates */
122 void *ks_private; /* private data */
123 kmutex_t ks_private_lock; /* kstat private data lock */
124 kmutex_t *ks_lock; /* kstat data lock */
5461eefe
BB
125 kstat_raw_ops_t ks_raw_ops; /* ops table for raw type */
126 char *ks_raw_buf; /* buf used for raw ops */
127 size_t ks_raw_bufsize; /* size of raw ops buffer */
d1261452 128 kstat_proc_entry_t ks_proc; /* data for procfs entry */
56d40a68 129};
f1ca4da6
BB
130
131typedef struct kstat_named_s {
5461eefe
BB
132 char name[KSTAT_STRLEN]; /* name of counter */
133 uchar_t data_type; /* data type */
134 union {
135 char c[16]; /* 128-bit int */
136 int32_t i32; /* 32-bit signed int */
137 uint32_t ui32; /* 32-bit unsigned int */
138 int64_t i64; /* 64-bit signed int */
139 uint64_t ui64; /* 64-bit unsigned int */
140 long l; /* native signed long */
141 ulong_t ul; /* native unsigned long */
142 struct {
143 union {
144 char *ptr; /* NULL-term string */
145 char __pad[8]; /* 64-bit padding */
146 } addr;
147 uint32_t len; /* # bytes for strlen + '\0' */
148 } string;
149 } value;
f1ca4da6
BB
150} kstat_named_t;
151
5461eefe
BB
152#define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.string.addr.ptr)
153#define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.string.len)
04a479f7
BB
154
155typedef struct kstat_intr {
5461eefe 156 uint_t intrs[KSTAT_NUM_INTRS];
04a479f7
BB
157} kstat_intr_t;
158
159typedef struct kstat_io {
5461eefe
BB
160 u_longlong_t nread; /* number of bytes read */
161 u_longlong_t nwritten; /* number of bytes written */
162 uint_t reads; /* number of read operations */
163 uint_t writes; /* number of write operations */
164 hrtime_t wtime; /* cumulative wait (pre-service) time */
165 hrtime_t wlentime; /* cumulative wait len*time product */
166 hrtime_t wlastupdate; /* last time wait queue changed */
167 hrtime_t rtime; /* cumulative run (service) time */
168 hrtime_t rlentime; /* cumulative run length*time product */
169 hrtime_t rlastupdate; /* last time run queue changed */
170 uint_t wcnt; /* count of elements in wait state */
171 uint_t rcnt; /* count of elements in run state */
04a479f7
BB
172} kstat_io_t;
173
174typedef struct kstat_timer {
5461eefe
BB
175 char name[KSTAT_STRLEN+1]; /* event name */
176 u_longlong_t num_events; /* number of events */
177 hrtime_t elapsed_time; /* cumulative elapsed time */
178 hrtime_t min_time; /* shortest event duration */
179 hrtime_t max_time; /* longest event duration */
180 hrtime_t start_time; /* previous event start time */
181 hrtime_t stop_time; /* previous event stop time */
04a479f7
BB
182} kstat_timer_t;
183
1114ae6a
BB
184int spl_kstat_init(void);
185void spl_kstat_fini(void);
04a479f7 186
56d40a68 187extern void __kstat_set_raw_ops(kstat_t *ksp,
5461eefe
BB
188 int (*headers)(char *buf, size_t size),
189 int (*data)(char *buf, size_t size, void *data),
190 void* (*addr)(kstat_t *ksp, loff_t index));
191
04a479f7 192extern kstat_t *__kstat_create(const char *ks_module, int ks_instance,
5461eefe
BB
193 const char *ks_name, const char *ks_class, uchar_t ks_type,
194 uint_t ks_ndata, uchar_t ks_flags);
195
d1261452
JG
196extern void kstat_proc_entry_init(kstat_proc_entry_t *kpep,
197 const char *module, const char *name);
198extern void kstat_proc_entry_delete(kstat_proc_entry_t *kpep);
199extern void kstat_proc_entry_install(kstat_proc_entry_t *kpep,
200 const struct file_operations *file_ops, void *data);
201
04a479f7
BB
202extern void __kstat_install(kstat_t *ksp);
203extern void __kstat_delete(kstat_t *ksp);
f483a97a
NB
204extern void kstat_waitq_enter(kstat_io_t *);
205extern void kstat_waitq_exit(kstat_io_t *);
206extern void kstat_runq_enter(kstat_io_t *);
207extern void kstat_runq_exit(kstat_io_t *);
04a479f7 208
5461eefe
BB
209#define kstat_set_raw_ops(k, h, d, a) \
210 __kstat_set_raw_ops(k, h, d, a)
211#define kstat_create(m, i, n, c, t, s, f) \
212 __kstat_create(m, i, n, c, t, s, f)
213
214#define kstat_install(k) __kstat_install(k)
215#define kstat_delete(k) __kstat_delete(k)
04a479f7 216
09b414e8 217#endif /* _SPL_KSTAT_H */