diff options
-rw-r--r-- | include/sys/kstat.h | 26 | ||||
-rw-r--r-- | module/spl/spl-kstat.c | 51 |
2 files changed, 70 insertions, 7 deletions
diff --git a/include/sys/kstat.h b/include/sys/kstat.h index e4c88c82b..06379f827 100644 --- a/include/sys/kstat.h +++ b/include/sys/kstat.h @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/time.h> #include <sys/kmem.h> +#include <sys/mutex.h> #define KSTAT_STRLEN 31 @@ -42,7 +43,8 @@ #define KSTAT_TYPE_INTR 2 /* interrupt stats; ks_ndata == 1 */ #define KSTAT_TYPE_IO 3 /* I/O stats; ks_ndata == 1 */ #define KSTAT_TYPE_TIMER 4 /* event timer; ks_ndata >= 1 */ -#define KSTAT_NUM_TYPES 5 +#define KSTAT_TYPE_TXG 5 /* txg sync; ks_ndata >= 1 */ +#define KSTAT_NUM_TYPES 6 #define KSTAT_DATA_CHAR 0 #define KSTAT_DATA_INT32 1 @@ -98,7 +100,7 @@ typedef struct kstat_s { struct proc_dir_entry *ks_proc; /* proc linkage */ kstat_update_t *ks_update; /* dynamic updates */ void *ks_private; /* private data */ - spinlock_t ks_lock; /* kstat data lock */ + kmutex_t ks_lock; /* kstat data lock */ struct list_head ks_list; /* kstat linkage */ } kstat_t; @@ -155,6 +157,26 @@ typedef struct kstat_timer { hrtime_t stop_time; /* previous event stop time */ } kstat_timer_t; +typedef enum kstat_txg_state { + TXG_STATE_OPEN = 1, + TXG_STATE_QUIESCING = 2, + TXG_STATE_SYNCING = 3, + TXG_STATE_COMMITTED = 4, +} kstat_txg_state_t; + +typedef struct kstat_txg { + u_longlong_t txg; /* txg id */ + kstat_txg_state_t state; /* txg state */ + hrtime_t birth; /* birth time stamp */ + u_longlong_t nread; /* number of bytes read */ + u_longlong_t nwritten; /* number of bytes written */ + uint_t reads; /* number of read operations */ + uint_t writes; /* number of write operations */ + hrtime_t open_time; /* open time */ + hrtime_t quiesce_time;/* quiesce time */ + hrtime_t sync_time; /* sync time */ +} kstat_txg_t; + int spl_kstat_init(void); void spl_kstat_fini(void); diff --git a/module/spl/spl-kstat.c b/module/spl/spl-kstat.c index 48fab972b..ea2d67dd4 100644 --- a/module/spl/spl-kstat.c +++ b/module/spl/spl-kstat.c @@ -78,6 +78,14 @@ kstat_seq_show_headers(struct seq_file *f) "name", "events", "elapsed", "min", "max", "start", "stop"); break; + case KSTAT_TYPE_TXG: + seq_printf(f, + "%-8s %-5s %-13s %-12s %-12s %-8s %-8s " + "%-12s %-12s %-12s\n", + "txg", "state", "birth", + "nread", "nwritten", "reads", "writes", + "otime", "qtime", "stime"); + break; default: PANIC("Undefined kstat type %d\n", ksp->ks_type); } @@ -191,6 +199,27 @@ kstat_seq_show_timer(struct seq_file *f, kstat_timer_t *ktp) } static int +kstat_seq_show_txg(struct seq_file *f, kstat_txg_t *ktp) +{ + char state; + + switch (ktp->state) { + case TXG_STATE_OPEN: state = 'O'; break; + case TXG_STATE_QUIESCING: state = 'Q'; break; + case TXG_STATE_SYNCING: state = 'S'; break; + case TXG_STATE_COMMITTED: state = 'C'; break; + default: state = '?'; break; + } + + seq_printf(f, + "%-8llu %-5c %-13llu %-12llu %-12llu %-8u %-8u " + "%12lld %12lld %12lld\n", ktp->txg, state, ktp->birth, + ktp->nread, ktp->nwritten, ktp->reads, ktp->writes, + ktp->open_time, ktp->quiesce_time, ktp->sync_time); + return 0; +} + +static int kstat_seq_show(struct seq_file *f, void *p) { kstat_t *ksp = (kstat_t *)f->private; @@ -216,6 +245,9 @@ kstat_seq_show(struct seq_file *f, void *p) case KSTAT_TYPE_TIMER: rc = kstat_seq_show_timer(f, (kstat_timer_t *)p); break; + case KSTAT_TYPE_TXG: + rc = kstat_seq_show_txg(f, (kstat_txg_t *)p); + break; default: PANIC("Undefined kstat type %d\n", ksp->ks_type); } @@ -252,6 +284,9 @@ kstat_seq_data_addr(kstat_t *ksp, loff_t n) case KSTAT_TYPE_TIMER: rc = ksp->ks_data + n * sizeof(kstat_timer_t); break; + case KSTAT_TYPE_TXG: + rc = ksp->ks_data + n * sizeof(kstat_txg_t); + break; default: PANIC("Undefined kstat type %d\n", ksp->ks_type); } @@ -267,10 +302,11 @@ kstat_seq_start(struct seq_file *f, loff_t *pos) ASSERT(ksp->ks_magic == KS_MAGIC); SENTRY; + mutex_enter(&ksp->ks_lock); + /* Dynamically update kstat, on error existing kstats are used */ (void) ksp->ks_update(ksp, KSTAT_READ); - spin_lock(&ksp->ks_lock); ksp->ks_snaptime = gethrtime(); if (!n) @@ -302,7 +338,7 @@ kstat_seq_stop(struct seq_file *f, void *v) kstat_t *ksp = (kstat_t *)f->private; ASSERT(ksp->ks_magic == KS_MAGIC); - spin_unlock(&ksp->ks_lock); + mutex_exit(&ksp->ks_lock); } static struct seq_operations kstat_seq_ops = { @@ -360,7 +396,7 @@ __kstat_create(const char *ks_module, int ks_instance, const char *ks_name, spin_unlock(&kstat_lock); ksp->ks_magic = KS_MAGIC; - spin_lock_init(&ksp->ks_lock); + mutex_init(&ksp->ks_lock, NULL, MUTEX_DEFAULT, NULL); INIT_LIST_HEAD(&ksp->ks_list); ksp->ks_crtime = gethrtime(); @@ -395,6 +431,10 @@ __kstat_create(const char *ks_module, int ks_instance, const char *ks_name, ksp->ks_ndata = ks_ndata; ksp->ks_data_size = ks_ndata * sizeof(kstat_timer_t); break; + case KSTAT_TYPE_TXG: + ksp->ks_ndata = ks_ndata; + ksp->ks_data_size = ks_ndata * sizeof(kstat_timer_t); + break; default: PANIC("Undefined kstat type %d\n", ksp->ks_type); } @@ -445,11 +485,11 @@ __kstat_install(kstat_t *ksp) if (de_name == NULL) SGOTO(out, rc = -EUNATCH); - spin_lock(&ksp->ks_lock); + mutex_enter(&ksp->ks_lock); ksp->ks_proc = de_name; de_name->proc_fops = &proc_kstat_operations; de_name->data = (void *)ksp; - spin_unlock(&ksp->ks_lock); + mutex_exit(&ksp->ks_lock); out: if (rc) { spin_lock(&kstat_lock); @@ -482,6 +522,7 @@ __kstat_delete(kstat_t *ksp) if (!(ksp->ks_flags & KSTAT_FLAG_VIRTUAL)) kmem_free(ksp->ks_data, ksp->ks_data_size); + mutex_destroy(&ksp->ks_lock); kmem_free(ksp, sizeof(*ksp)); return; |