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