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