b4d0d230ccfb5 (Thomas Gleixner 2019-05-20 19:08:01 +0200 1) // SPDX-License-Identifier: GPL-2.0-or-later
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 2) /* FS-Cache latency histogram
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 3) *
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 4) * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 5) * Written by David Howells (dhowells@redhat.com)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 6) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 7)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 8) #define FSCACHE_DEBUG_LEVEL THREAD
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 9) #include <linux/module.h>
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 10) #include <linux/proc_fs.h>
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 11) #include <linux/seq_file.h>
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 12) #include "internal.h"
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 13)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 14) atomic_t fscache_obj_instantiate_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 15) atomic_t fscache_objs_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 16) atomic_t fscache_ops_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 17) atomic_t fscache_retrieval_delay_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 18) atomic_t fscache_retrieval_histogram[HZ];
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 19)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 20) /*
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 21) * display the time-taken histogram
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 22) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 23) static int fscache_histogram_show(struct seq_file *m, void *v)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 24) {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 25) unsigned long index;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 26) unsigned n[5], t;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 27)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 28) switch ((unsigned long) v) {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 29) case 1:
3185a88ce3749 (Fabian Frederick 2014-06-04 16:05:39 -0700 30) seq_puts(m, "JIFS SECS OBJ INST OP RUNS OBJ RUNS RETRV DLY RETRIEVLS\n");
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 31) return 0;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 32) case 2:
3185a88ce3749 (Fabian Frederick 2014-06-04 16:05:39 -0700 33) seq_puts(m, "===== ===== ========= ========= ========= ========= =========\n");
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 34) return 0;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 35) default:
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 36) index = (unsigned long) v - 3;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 37) n[0] = atomic_read(&fscache_obj_instantiate_histogram[index]);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 38) n[1] = atomic_read(&fscache_ops_histogram[index]);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 39) n[2] = atomic_read(&fscache_objs_histogram[index]);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 40) n[3] = atomic_read(&fscache_retrieval_delay_histogram[index]);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 41) n[4] = atomic_read(&fscache_retrieval_histogram[index]);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 42) if (!(n[0] | n[1] | n[2] | n[3] | n[4]))
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 43) return 0;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 44)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 45) t = (index * 1000) / HZ;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 46)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 47) seq_printf(m, "%4lu 0.%03u %9u %9u %9u %9u %9u\n",
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 48) index, t, n[0], n[1], n[2], n[3], n[4]);
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 49) return 0;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 50) }
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 51) }
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 52)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 53) /*
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 54) * set up the iterator to start reading from the first line
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 55) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 56) static void *fscache_histogram_start(struct seq_file *m, loff_t *_pos)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 57) {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 58) if ((unsigned long long)*_pos >= HZ + 2)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 59) return NULL;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 60) if (*_pos == 0)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 61) *_pos = 1;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 62) return (void *)(unsigned long) *_pos;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 63) }
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 64)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 65) /*
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 66) * move to the next line
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 67) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 68) static void *fscache_histogram_next(struct seq_file *m, void *v, loff_t *pos)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 69) {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 70) (*pos)++;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 71) return (unsigned long long)*pos > HZ + 2 ?
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 72) NULL : (void *)(unsigned long) *pos;
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 73) }
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 74)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 75) /*
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 76) * clean up after reading
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 77) */
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 78) static void fscache_histogram_stop(struct seq_file *m, void *v)
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 79) {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 80) }
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 81)
fddda2b7b5211 (Christoph Hellwig 2018-04-13 19:44:18 +0200 82) const struct seq_operations fscache_histogram_ops = {
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 83) .start = fscache_histogram_start,
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 84) .stop = fscache_histogram_stop,
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 85) .next = fscache_histogram_next,
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 86) .show = fscache_histogram_show,
7394daa8c61df (David Howells 2009-04-03 16:42:37 +0100 87) };