]> git.proxmox.com Git - mirror_spl-debian.git/blame - include/sys/kstat.h
Autoconf --enable-debug-* cleanup
[mirror_spl-debian.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
f1b59d26 30#include <linux/module.h>
f4b37741 31#include <sys/types.h>
32#include <sys/time.h>
04a479f7 33#include <sys/kmem.h>
34#include <sys/proc.h>
f1ca4da6 35
04a479f7 36#define KSTAT_STRLEN 31
f1ca4da6 37
04a479f7 38/* For reference valid classes are:
39 * disk, tape, net, controller, vm, kvm, hat, streams, kstat, misc
40 */
f1ca4da6 41
04a479f7 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 */
f1ca4da6 47#define KSTAT_NUM_TYPES 5
48
f1ca4da6 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 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 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
04a479f7 77typedef int kid_t; /* unique kstat id */
f1ca4da6 78
79typedef struct kstat_s {
04a479f7 80 int ks_magic; /* magic value */
81 kid_t ks_kid; /* unique kstat ID */
82 hrtime_t ks_crtime; /* creation time */
83 hrtime_t ks_snaptime; /* last access time */
84 char ks_module[KSTAT_STRLEN+1]; /* provider module name */
85 int ks_instance; /* provider module instance */
86 char ks_name[KSTAT_STRLEN+1]; /* kstat name */
87 char ks_class[KSTAT_STRLEN+1]; /* kstat class */
88 uchar_t ks_type; /* kstat data type */
89 uchar_t ks_flags; /* kstat flags */
90 void *ks_data; /* kstat type-specific data */
91 uint_t ks_ndata; /* # of type-specific data records */
92 size_t ks_data_size; /* size of kstat data section */
93 struct proc_dir_entry *ks_proc; /* proc linkage */
94 spinlock_t ks_lock; /* kstat data lock */
95 struct list_head ks_list; /* kstat linkage */
f1ca4da6 96} kstat_t;
97
98typedef struct kstat_named_s {
04a479f7 99 char name[KSTAT_STRLEN]; /* name of counter */
100 uchar_t data_type; /* data type */
f1ca4da6 101 union {
04a479f7 102 char c[16]; /* 128-bit int */
103 int32_t i32; /* 32-bit signed int */
104 uint32_t ui32; /* 32-bit unsigned int */
105 int64_t i64; /* 64-bit signed int */
106 uint64_t ui64; /* 64-bit unsigned int */
107 long l; /* native signed long */
108 ulong_t ul; /* native unsigned long */
f1ca4da6 109 struct {
110 union {
04a479f7 111 char *ptr; /* NULL-term string */
112 char __pad[8]; /* 64-bit padding */
f1ca4da6 113 } addr;
04a479f7 114 uint32_t len; /* # bytes for strlen + '\0' */
115 } string;
116 } value;
f1ca4da6 117} kstat_named_t;
118
04a479f7 119#define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.string.addr.ptr)
120#define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.string.len)
121
122typedef struct kstat_intr {
123 uint_t intrs[KSTAT_NUM_INTRS];
124} kstat_intr_t;
125
126typedef struct kstat_io {
127 u_longlong_t nread; /* number of bytes read */
128 u_longlong_t nwritten; /* number of bytes written */
129 uint_t reads; /* number of read operations */
130 uint_t writes; /* number of write operations */
131 hrtime_t wtime; /* cumulative wait (pre-service) time */
132 hrtime_t wlentime; /* cumulative wait length*time product*/
133 hrtime_t wlastupdate; /* last time wait queue changed */
134 hrtime_t rtime; /* cumulative run (service) time */
135 hrtime_t rlentime; /* cumulative run length*time product */
136 hrtime_t rlastupdate; /* last time run queue changed */
137 uint_t wcnt; /* count of elements in wait state */
138 uint_t rcnt; /* count of elements in run state */
139} kstat_io_t;
140
141typedef struct kstat_timer {
142 char name[KSTAT_STRLEN+1]; /* event name */
143 u_longlong_t num_events; /* number of events */
144 hrtime_t elapsed_time; /* cumulative elapsed time */
145 hrtime_t min_time; /* shortest event duration */
146 hrtime_t max_time; /* longest event duration */
147 hrtime_t start_time; /* previous event start time */
148 hrtime_t stop_time; /* previous event stop time */
149} kstat_timer_t;
150
151int kstat_init(void);
152void kstat_fini(void);
153
04a479f7 154extern kstat_t *__kstat_create(const char *ks_module, int ks_instance,
155 const char *ks_name, const char *ks_class,
156 uchar_t ks_type, uint_t ks_ndata,
157 uchar_t ks_flags);
158extern void __kstat_install(kstat_t *ksp);
159extern void __kstat_delete(kstat_t *ksp);
160
161#define kstat_create(m,i,n,c,t,s,f) __kstat_create(m,i,n,c,t,s,f)
162#define kstat_install(k) __kstat_install(k)
163#define kstat_delete(k) __kstat_delete(k)
164
09b414e8 165#endif /* _SPL_KSTAT_H */
f1ca4da6 166