1eda14cbcSMatt Macy /* 2eda14cbcSMatt Macy * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. 3eda14cbcSMatt Macy * Copyright (C) 2007 The Regents of the University of California. 4eda14cbcSMatt Macy * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 5eda14cbcSMatt Macy * Written by Brian Behlendorf <behlendorf1@llnl.gov>. 6eda14cbcSMatt Macy * UCRL-CODE-235197 7eda14cbcSMatt Macy * 8eda14cbcSMatt Macy * This file is part of the SPL, Solaris Porting Layer. 9eda14cbcSMatt Macy * 10eda14cbcSMatt Macy * The SPL is free software; you can redistribute it and/or modify it 11eda14cbcSMatt Macy * under the terms of the GNU General Public License as published by the 12eda14cbcSMatt Macy * Free Software Foundation; either version 2 of the License, or (at your 13eda14cbcSMatt Macy * option) any later version. 14eda14cbcSMatt Macy * 15eda14cbcSMatt Macy * The SPL is distributed in the hope that it will be useful, but WITHOUT 16eda14cbcSMatt Macy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17eda14cbcSMatt Macy * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18eda14cbcSMatt Macy * for more details. 19eda14cbcSMatt Macy * 20eda14cbcSMatt Macy * You should have received a copy of the GNU General Public License along 21eda14cbcSMatt Macy * with the SPL. If not, see <http://www.gnu.org/licenses/>. 22eda14cbcSMatt Macy */ 23eda14cbcSMatt Macy 24eda14cbcSMatt Macy #ifndef _SPL_KSTAT_H 25eda14cbcSMatt Macy #define _SPL_KSTAT_H 262fec3ae8SWarner Losh 27eda14cbcSMatt Macy #include <sys/types.h> 282fec3ae8SWarner Losh #ifndef _STANDALONE 29eda14cbcSMatt Macy #include <sys/sysctl.h> 302fec3ae8SWarner Losh #endif 31eda14cbcSMatt Macy struct list_head {}; 32eda14cbcSMatt Macy #include <sys/mutex.h> 33eda14cbcSMatt Macy #include <sys/proc.h> 34eda14cbcSMatt Macy 35eda14cbcSMatt Macy #define KSTAT_STRLEN 255 36eda14cbcSMatt Macy #define KSTAT_RAW_MAX (128*1024) 37eda14cbcSMatt Macy 38eda14cbcSMatt Macy /* 39eda14cbcSMatt Macy * For reference valid classes are: 40eda14cbcSMatt Macy * disk, tape, net, controller, vm, kvm, hat, streams, kstat, misc 41eda14cbcSMatt Macy */ 42eda14cbcSMatt Macy 43eda14cbcSMatt Macy #define KSTAT_TYPE_RAW 0 /* can be anything; ks_ndata >= 1 */ 44eda14cbcSMatt Macy #define KSTAT_TYPE_NAMED 1 /* name/value pair; ks_ndata >= 1 */ 45eda14cbcSMatt Macy #define KSTAT_TYPE_INTR 2 /* interrupt stats; ks_ndata == 1 */ 46eda14cbcSMatt Macy #define KSTAT_TYPE_IO 3 /* I/O stats; ks_ndata == 1 */ 47eda14cbcSMatt Macy #define KSTAT_TYPE_TIMER 4 /* event timer; ks_ndata >= 1 */ 48eda14cbcSMatt Macy #define KSTAT_NUM_TYPES 5 49eda14cbcSMatt Macy 50eda14cbcSMatt Macy #define KSTAT_DATA_CHAR 0 51eda14cbcSMatt Macy #define KSTAT_DATA_INT32 1 52eda14cbcSMatt Macy #define KSTAT_DATA_UINT32 2 53eda14cbcSMatt Macy #define KSTAT_DATA_INT64 3 54eda14cbcSMatt Macy #define KSTAT_DATA_UINT64 4 55eda14cbcSMatt Macy #define KSTAT_DATA_LONG 5 56eda14cbcSMatt Macy #define KSTAT_DATA_ULONG 6 57eda14cbcSMatt Macy #define KSTAT_DATA_STRING 7 58eda14cbcSMatt Macy #define KSTAT_NUM_DATAS 8 59eda14cbcSMatt Macy 60eda14cbcSMatt Macy #define KSTAT_INTR_HARD 0 61eda14cbcSMatt Macy #define KSTAT_INTR_SOFT 1 62eda14cbcSMatt Macy #define KSTAT_INTR_WATCHDOG 2 63eda14cbcSMatt Macy #define KSTAT_INTR_SPURIOUS 3 64eda14cbcSMatt Macy #define KSTAT_INTR_MULTSVC 4 65eda14cbcSMatt Macy #define KSTAT_NUM_INTRS 5 66eda14cbcSMatt Macy 67eda14cbcSMatt Macy #define KSTAT_FLAG_VIRTUAL 0x01 68eda14cbcSMatt Macy #define KSTAT_FLAG_VAR_SIZE 0x02 69eda14cbcSMatt Macy #define KSTAT_FLAG_WRITABLE 0x04 70eda14cbcSMatt Macy #define KSTAT_FLAG_PERSISTENT 0x08 71eda14cbcSMatt Macy #define KSTAT_FLAG_DORMANT 0x10 72eda14cbcSMatt Macy #define KSTAT_FLAG_INVALID 0x20 73eda14cbcSMatt Macy #define KSTAT_FLAG_LONGSTRINGS 0x40 74eda14cbcSMatt Macy #define KSTAT_FLAG_NO_HEADERS 0x80 75eda14cbcSMatt Macy 76eda14cbcSMatt Macy #define KS_MAGIC 0x9d9d9d9d 77eda14cbcSMatt Macy 78eda14cbcSMatt Macy /* Dynamic updates */ 79eda14cbcSMatt Macy #define KSTAT_READ 0 80eda14cbcSMatt Macy #define KSTAT_WRITE 1 81eda14cbcSMatt Macy 82eda14cbcSMatt Macy struct kstat_s; 83eda14cbcSMatt Macy typedef struct kstat_s kstat_t; 84eda14cbcSMatt Macy 85eda14cbcSMatt Macy typedef int kid_t; /* unique kstat id */ 86eda14cbcSMatt Macy typedef int kstat_update_t(struct kstat_s *, int); /* dynamic update cb */ 87eda14cbcSMatt Macy 88c40487d4SMatt Macy struct seq_file { 89c40487d4SMatt Macy char *sf_buf; 90c40487d4SMatt Macy size_t sf_size; 91c40487d4SMatt Macy }; 92c40487d4SMatt Macy 93c40487d4SMatt Macy void seq_printf(struct seq_file *m, const char *fmt, ...); 94c40487d4SMatt Macy 95c40487d4SMatt Macy 96eda14cbcSMatt Macy typedef struct kstat_module { 97*be181ee2SMartin Matuska char ksm_name[KSTAT_STRLEN]; /* module name */ 98eda14cbcSMatt Macy struct list_head ksm_module_list; /* module linkage */ 99eda14cbcSMatt Macy struct list_head ksm_kstat_list; /* list of kstat entries */ 100eda14cbcSMatt Macy struct proc_dir_entry *ksm_proc; /* proc entry */ 101eda14cbcSMatt Macy } kstat_module_t; 102eda14cbcSMatt Macy 103eda14cbcSMatt Macy typedef struct kstat_raw_ops { 104eda14cbcSMatt Macy int (*headers)(char *buf, size_t size); 105c40487d4SMatt Macy int (*seq_headers)(struct seq_file *); 106eda14cbcSMatt Macy int (*data)(char *buf, size_t size, void *data); 107eda14cbcSMatt Macy void *(*addr)(kstat_t *ksp, loff_t index); 108eda14cbcSMatt Macy } kstat_raw_ops_t; 109eda14cbcSMatt Macy 110eda14cbcSMatt Macy struct kstat_s { 111eda14cbcSMatt Macy int ks_magic; /* magic value */ 112eda14cbcSMatt Macy kid_t ks_kid; /* unique kstat ID */ 113eda14cbcSMatt Macy hrtime_t ks_crtime; /* creation time */ 114eda14cbcSMatt Macy hrtime_t ks_snaptime; /* last access time */ 115*be181ee2SMartin Matuska char ks_module[KSTAT_STRLEN]; /* provider module name */ 116eda14cbcSMatt Macy int ks_instance; /* provider module instance */ 117*be181ee2SMartin Matuska char ks_name[KSTAT_STRLEN]; /* kstat name */ 118*be181ee2SMartin Matuska char ks_class[KSTAT_STRLEN]; /* kstat class */ 119eda14cbcSMatt Macy uchar_t ks_type; /* kstat data type */ 120eda14cbcSMatt Macy uchar_t ks_flags; /* kstat flags */ 121eda14cbcSMatt Macy void *ks_data; /* kstat type-specific data */ 122eda14cbcSMatt Macy uint_t ks_ndata; /* # of data records */ 123eda14cbcSMatt Macy size_t ks_data_size; /* size of kstat data section */ 124eda14cbcSMatt Macy kstat_update_t *ks_update; /* dynamic updates */ 125eda14cbcSMatt Macy void *ks_private; /* private data */ 126c40487d4SMatt Macy void *ks_private1; /* private data */ 127eda14cbcSMatt Macy kmutex_t ks_private_lock; /* kstat private data lock */ 128eda14cbcSMatt Macy kmutex_t *ks_lock; /* kstat data lock */ 129eda14cbcSMatt Macy struct list_head ks_list; /* kstat linkage */ 130eda14cbcSMatt Macy kstat_module_t *ks_owner; /* kstat module linkage */ 131eda14cbcSMatt Macy kstat_raw_ops_t ks_raw_ops; /* ops table for raw type */ 132eda14cbcSMatt Macy char *ks_raw_buf; /* buf used for raw ops */ 133eda14cbcSMatt Macy size_t ks_raw_bufsize; /* size of raw ops buffer */ 1342fec3ae8SWarner Losh #ifndef _STANDALONE 135eda14cbcSMatt Macy struct sysctl_ctx_list ks_sysctl_ctx; 136eda14cbcSMatt Macy struct sysctl_oid *ks_sysctl_root; 1372fec3ae8SWarner Losh #endif /* _STANDALONE */ 138eda14cbcSMatt Macy }; 139eda14cbcSMatt Macy 140eda14cbcSMatt Macy typedef struct kstat_named_s { 141eda14cbcSMatt Macy char name[KSTAT_STRLEN]; /* name of counter */ 142eda14cbcSMatt Macy uchar_t data_type; /* data type */ 143eda14cbcSMatt Macy union { 144eda14cbcSMatt Macy char c[16]; /* 128-bit int */ 145eda14cbcSMatt Macy int32_t i32; /* 32-bit signed int */ 146eda14cbcSMatt Macy uint32_t ui32; /* 32-bit unsigned int */ 147eda14cbcSMatt Macy int64_t i64; /* 64-bit signed int */ 148eda14cbcSMatt Macy uint64_t ui64; /* 64-bit unsigned int */ 149eda14cbcSMatt Macy long l; /* native signed long */ 150eda14cbcSMatt Macy ulong_t ul; /* native unsigned long */ 151eda14cbcSMatt Macy struct { 152eda14cbcSMatt Macy union { 153eda14cbcSMatt Macy char *ptr; /* NULL-term string */ 154eda14cbcSMatt Macy char __pad[8]; /* 64-bit padding */ 155eda14cbcSMatt Macy } addr; 156eda14cbcSMatt Macy uint32_t len; /* # bytes for strlen + '\0' */ 157eda14cbcSMatt Macy } string; 158eda14cbcSMatt Macy } value; 159eda14cbcSMatt Macy } kstat_named_t; 160eda14cbcSMatt Macy 161eda14cbcSMatt Macy #define KSTAT_NAMED_STR_PTR(knptr) ((knptr)->value.string.addr.ptr) 162eda14cbcSMatt Macy #define KSTAT_NAMED_STR_BUFLEN(knptr) ((knptr)->value.string.len) 163eda14cbcSMatt Macy 164eda14cbcSMatt Macy typedef struct kstat_intr { 165eda14cbcSMatt Macy uint_t intrs[KSTAT_NUM_INTRS]; 166eda14cbcSMatt Macy } kstat_intr_t; 167eda14cbcSMatt Macy 168eda14cbcSMatt Macy typedef struct kstat_io { 169eda14cbcSMatt Macy u_longlong_t nread; /* number of bytes read */ 170eda14cbcSMatt Macy u_longlong_t nwritten; /* number of bytes written */ 171eda14cbcSMatt Macy uint_t reads; /* number of read operations */ 172eda14cbcSMatt Macy uint_t writes; /* number of write operations */ 173eda14cbcSMatt Macy hrtime_t wtime; /* cumulative wait (pre-service) time */ 174eda14cbcSMatt Macy hrtime_t wlentime; /* cumulative wait len*time product */ 175eda14cbcSMatt Macy hrtime_t wlastupdate; /* last time wait queue changed */ 176eda14cbcSMatt Macy hrtime_t rtime; /* cumulative run (service) time */ 177eda14cbcSMatt Macy hrtime_t rlentime; /* cumulative run length*time product */ 178eda14cbcSMatt Macy hrtime_t rlastupdate; /* last time run queue changed */ 179eda14cbcSMatt Macy uint_t wcnt; /* count of elements in wait state */ 180eda14cbcSMatt Macy uint_t rcnt; /* count of elements in run state */ 181eda14cbcSMatt Macy } kstat_io_t; 182eda14cbcSMatt Macy 183eda14cbcSMatt Macy typedef struct kstat_timer { 184*be181ee2SMartin Matuska char name[KSTAT_STRLEN]; /* event name */ 185eda14cbcSMatt Macy u_longlong_t num_events; /* number of events */ 186eda14cbcSMatt Macy hrtime_t elapsed_time; /* cumulative elapsed time */ 187eda14cbcSMatt Macy hrtime_t min_time; /* shortest event duration */ 188eda14cbcSMatt Macy hrtime_t max_time; /* longest event duration */ 189eda14cbcSMatt Macy hrtime_t start_time; /* previous event start time */ 190eda14cbcSMatt Macy hrtime_t stop_time; /* previous event stop time */ 191eda14cbcSMatt Macy } kstat_timer_t; 192eda14cbcSMatt Macy 193eda14cbcSMatt Macy int spl_kstat_init(void); 194eda14cbcSMatt Macy void spl_kstat_fini(void); 195eda14cbcSMatt Macy 196eda14cbcSMatt Macy extern void __kstat_set_raw_ops(kstat_t *ksp, 197eda14cbcSMatt Macy int (*headers)(char *buf, size_t size), 198eda14cbcSMatt Macy int (*data)(char *buf, size_t size, void *data), 199eda14cbcSMatt Macy void* (*addr)(kstat_t *ksp, loff_t index)); 200eda14cbcSMatt Macy 201c40487d4SMatt Macy extern void __kstat_set_seq_raw_ops(kstat_t *ksp, 202c40487d4SMatt Macy int (*headers)(struct seq_file *), 203c40487d4SMatt Macy int (*data)(char *buf, size_t size, void *data), 204c40487d4SMatt Macy void* (*addr)(kstat_t *ksp, loff_t index)); 205c40487d4SMatt Macy 206c40487d4SMatt Macy 207eda14cbcSMatt Macy extern kstat_t *__kstat_create(const char *ks_module, int ks_instance, 208eda14cbcSMatt Macy const char *ks_name, const char *ks_class, uchar_t ks_type, 209eda14cbcSMatt Macy uint_t ks_ndata, uchar_t ks_flags); 210eda14cbcSMatt Macy 211eda14cbcSMatt Macy extern void __kstat_install(kstat_t *ksp); 212eda14cbcSMatt Macy extern void __kstat_delete(kstat_t *ksp); 213eda14cbcSMatt Macy 214c40487d4SMatt Macy #define kstat_set_seq_raw_ops(k, h, d, a) \ 215c40487d4SMatt Macy __kstat_set_seq_raw_ops(k, h, d, a) 216eda14cbcSMatt Macy #define kstat_set_raw_ops(k, h, d, a) \ 217eda14cbcSMatt Macy __kstat_set_raw_ops(k, h, d, a) 2182fec3ae8SWarner Losh #ifndef _STANDALONE 219eda14cbcSMatt Macy #define kstat_create(m, i, n, c, t, s, f) \ 220eda14cbcSMatt Macy __kstat_create(m, i, n, c, t, s, f) 221eda14cbcSMatt Macy 222eda14cbcSMatt Macy #define kstat_install(k) __kstat_install(k) 223eda14cbcSMatt Macy #define kstat_delete(k) __kstat_delete(k) 2242fec3ae8SWarner Losh #else 2252fec3ae8SWarner Losh #define kstat_create(m, i, n, c, t, s, f) ((kstat_t *)0) 2262fec3ae8SWarner Losh #define kstat_install(k) 2272fec3ae8SWarner Losh #define kstat_delete(k) 2282fec3ae8SWarner Losh #endif 229eda14cbcSMatt Macy 230eda14cbcSMatt Macy #endif /* _SPL_KSTAT_H */ 231