]> git.proxmox.com Git - mirror_spl.git/blame - include/sys/kstat.h
Fix depmod warning
[mirror_spl.git] / include / sys / kstat.h
CommitLineData
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 6 * UCRL-CODE-235197
7 *
716154c5
BB
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.
715f6251 15 *
716154c5 16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
715f6251 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 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 30#include <sys/types.h>
31#include <sys/time.h>
04a479f7 32#include <sys/kmem.h>
f1ca4da6 33
04a479f7 34#define KSTAT_STRLEN 31
f1ca4da6 35
04a479f7 36/* For reference valid classes are:
37 * disk, tape, net, controller, vm, kvm, hat, streams, kstat, misc
38 */
f1ca4da6 39
04a479f7 40#define KSTAT_TYPE_RAW 0 /* can be anything; ks_ndata >= 1 */
41#define KSTAT_TYPE_NAMED 1 /* name/value pair; ks_ndata >= 1 */
42#define KSTAT_TYPE_INTR 2 /* interrupt stats; ks_ndata == 1 */
43#define KSTAT_TYPE_IO 3 /* I/O stats; ks_ndata == 1 */
44#define KSTAT_TYPE_TIMER 4 /* event timer; ks_ndata >= 1 */
f1ca4da6 45#define KSTAT_NUM_TYPES 5
46
f1ca4da6 47#define KSTAT_DATA_CHAR 0
48#define KSTAT_DATA_INT32 1
49#define KSTAT_DATA_UINT32 2
50#define KSTAT_DATA_INT64 3
51#define KSTAT_DATA_UINT64 4
04a479f7 52#define KSTAT_DATA_LONG 5
53#define KSTAT_DATA_ULONG 6
54#define KSTAT_DATA_STRING 7
55#define KSTAT_NUM_DATAS 8
56
57#define KSTAT_INTR_HARD 0
58#define KSTAT_INTR_SOFT 1
59#define KSTAT_INTR_WATCHDOG 2
60#define KSTAT_INTR_SPURIOUS 3
61#define KSTAT_INTR_MULTSVC 4
62#define KSTAT_NUM_INTRS 5
f1ca4da6 63
04a479f7 64#define KSTAT_FLAG_VIRTUAL 0x01
65#define KSTAT_FLAG_VAR_SIZE 0x02
66#define KSTAT_FLAG_WRITABLE 0x04
67#define KSTAT_FLAG_PERSISTENT 0x08
68#define KSTAT_FLAG_DORMANT 0x10
69#define KSTAT_FLAG_UNSUPPORTED (KSTAT_FLAG_VAR_SIZE | KSTAT_FLAG_WRITABLE | \
70 KSTAT_FLAG_PERSISTENT | KSTAT_FLAG_DORMANT)
f1ca4da6 71
f1ca4da6 72
04a479f7 73#define KS_MAGIC 0x9d9d9d9d
f1ca4da6 74
04a479f7 75typedef int kid_t; /* unique kstat id */
f1ca4da6 76
77typedef struct kstat_s {
04a479f7 78 int ks_magic; /* magic value */
79 kid_t ks_kid; /* unique kstat ID */
80 hrtime_t ks_crtime; /* creation time */
81 hrtime_t ks_snaptime; /* last access time */
82 char ks_module[KSTAT_STRLEN+1]; /* provider module name */
83 int ks_instance; /* provider module instance */
84 char ks_name[KSTAT_STRLEN+1]; /* kstat name */
85 char ks_class[KSTAT_STRLEN+1]; /* kstat class */
86 uchar_t ks_type; /* kstat data type */
87 uchar_t ks_flags; /* kstat flags */
88 void *ks_data; /* kstat type-specific data */
89 uint_t ks_ndata; /* # of type-specific data records */
90 size_t ks_data_size; /* size of kstat data section */
91 struct proc_dir_entry *ks_proc; /* proc linkage */
92 spinlock_t ks_lock; /* kstat data lock */
93 struct list_head ks_list; /* kstat linkage */
f1ca4da6 94} kstat_t;
95
96typedef struct kstat_named_s {
04a479f7 97 char name[KSTAT_STRLEN]; /* name of counter */
98 uchar_t data_type; /* data type */
f1ca4da6 99 union {
04a479f7 100 char c[16]; /* 128-bit int */
101 int32_t i32; /* 32-bit signed int */
102 uint32_t ui32; /* 32-bit unsigned int */
103 int64_t i64; /* 64-bit signed int */
104 uint64_t ui64; /* 64-bit unsigned int */
105 long l; /* native signed long */
106 ulong_t ul; /* native unsigned long */
f1ca4da6 107 struct {
108 union {
04a479f7 109 char *ptr; /* NULL-term string */
110 char __pad[8]; /* 64-bit padding */
f1ca4da6 111 } addr;
04a479f7 112 uint32_t len; /* # bytes for strlen + '\0' */
113 } string;
114 } value;
f1ca4da6 115} kstat_named_t;
116
04a479f7 117#define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.string.addr.ptr)
118#define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.string.len)
119
120typedef struct kstat_intr {
121 uint_t intrs[KSTAT_NUM_INTRS];
122} kstat_intr_t;
123
124typedef struct kstat_io {
125 u_longlong_t nread; /* number of bytes read */
126 u_longlong_t nwritten; /* number of bytes written */
127 uint_t reads; /* number of read operations */
128 uint_t writes; /* number of write operations */
129 hrtime_t wtime; /* cumulative wait (pre-service) time */
130 hrtime_t wlentime; /* cumulative wait length*time product*/
131 hrtime_t wlastupdate; /* last time wait queue changed */
132 hrtime_t rtime; /* cumulative run (service) time */
133 hrtime_t rlentime; /* cumulative run length*time product */
134 hrtime_t rlastupdate; /* last time run queue changed */
135 uint_t wcnt; /* count of elements in wait state */
136 uint_t rcnt; /* count of elements in run state */
137} kstat_io_t;
138
139typedef struct kstat_timer {
140 char name[KSTAT_STRLEN+1]; /* event name */
141 u_longlong_t num_events; /* number of events */
142 hrtime_t elapsed_time; /* cumulative elapsed time */
143 hrtime_t min_time; /* shortest event duration */
144 hrtime_t max_time; /* longest event duration */
145 hrtime_t start_time; /* previous event start time */
146 hrtime_t stop_time; /* previous event stop time */
147} kstat_timer_t;
148
149int kstat_init(void);
150void kstat_fini(void);
151
04a479f7 152extern kstat_t *__kstat_create(const char *ks_module, int ks_instance,
153 const char *ks_name, const char *ks_class,
154 uchar_t ks_type, uint_t ks_ndata,
155 uchar_t ks_flags);
156extern void __kstat_install(kstat_t *ksp);
157extern void __kstat_delete(kstat_t *ksp);
158
159#define kstat_create(m,i,n,c,t,s,f) __kstat_create(m,i,n,c,t,s,f)
160#define kstat_install(k) __kstat_install(k)
161#define kstat_delete(k) __kstat_delete(k)
162
09b414e8 163#endif /* _SPL_KSTAT_H */