Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Statistics for NFS server. |
| 4 | * |
| 5 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> |
| 6 | */ |
Christoph Hellwig | 7f94423 | 2014-05-06 19:37:15 +0200 | [diff] [blame] | 7 | #ifndef _NFSD_STATS_H |
| 8 | #define _NFSD_STATS_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
David Howells | 616d1ca | 2012-10-09 09:49:02 +0100 | [diff] [blame] | 10 | #include <uapi/linux/nfsd/stats.h> |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 11 | #include <linux/percpu_counter.h> |
Shankar Anand | e2b2095 | 2006-07-10 04:45:44 -0700 | [diff] [blame] | 12 | |
Greg Banks | 42d671c | 2009-03-27 02:32:47 +1100 | [diff] [blame] | 13 | |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 14 | enum { |
| 15 | NFSD_STATS_RC_HITS, /* repcache hits */ |
| 16 | NFSD_STATS_RC_MISSES, /* repcache misses */ |
| 17 | NFSD_STATS_RC_NOCACHE, /* uncached reqs */ |
| 18 | NFSD_STATS_FH_STALE, /* FH stale error */ |
| 19 | NFSD_STATS_IO_READ, /* bytes returned to read requests */ |
| 20 | NFSD_STATS_IO_WRITE, /* bytes passed in write requests */ |
| 21 | #ifdef CONFIG_NFSD_V4 |
| 22 | NFSD_STATS_FIRST_NFS4_OP, /* count of individual nfsv4 operations */ |
| 23 | NFSD_STATS_LAST_NFS4_OP = NFSD_STATS_FIRST_NFS4_OP + LAST_NFS4_OP, |
| 24 | #define NFSD_STATS_NFS4_OP(op) (NFSD_STATS_FIRST_NFS4_OP + (op)) |
| 25 | #endif |
| 26 | NFSD_STATS_COUNTERS_NUM |
| 27 | }; |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | struct nfsd_stats { |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 30 | struct percpu_counter counter[NFSD_STATS_COUNTERS_NUM]; |
Shankar Anand | e2b2095 | 2006-07-10 04:45:44 -0700 | [diff] [blame] | 31 | |
NeilBrown | 9b6c8c9 | 2021-11-29 15:51:25 +1100 | [diff] [blame] | 32 | atomic_t th_cnt; /* number of available threads */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | extern struct nfsd_stats nfsdstats; |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | extern struct svc_stat nfsd_svcstats; |
| 38 | |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 39 | int nfsd_percpu_counters_init(struct percpu_counter counters[], int num); |
| 40 | void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num); |
| 41 | void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num); |
| 42 | int nfsd_stat_init(void); |
| 43 | void nfsd_stat_shutdown(void); |
| 44 | |
| 45 | static inline void nfsd_stats_rc_hits_inc(void) |
| 46 | { |
| 47 | percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_HITS]); |
| 48 | } |
| 49 | |
| 50 | static inline void nfsd_stats_rc_misses_inc(void) |
| 51 | { |
| 52 | percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_MISSES]); |
| 53 | } |
| 54 | |
| 55 | static inline void nfsd_stats_rc_nocache_inc(void) |
| 56 | { |
| 57 | percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_NOCACHE]); |
| 58 | } |
| 59 | |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 60 | static inline void nfsd_stats_fh_stale_inc(struct svc_export *exp) |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 61 | { |
| 62 | percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_FH_STALE]); |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 63 | if (exp) |
| 64 | percpu_counter_inc(&exp->ex_stats.counter[EXP_STATS_FH_STALE]); |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 65 | } |
| 66 | |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 67 | static inline void nfsd_stats_io_read_add(struct svc_export *exp, s64 amount) |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 68 | { |
| 69 | percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_READ], amount); |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 70 | if (exp) |
| 71 | percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_READ], amount); |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 74 | static inline void nfsd_stats_io_write_add(struct svc_export *exp, s64 amount) |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 75 | { |
| 76 | percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_WRITE], amount); |
Amir Goldstein | 20ad856 | 2021-01-06 09:52:36 +0200 | [diff] [blame] | 77 | if (exp) |
| 78 | percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_WRITE], amount); |
Amir Goldstein | e567b98 | 2021-01-06 09:52:35 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static inline void nfsd_stats_payload_misses_inc(struct nfsd_net *nn) |
| 82 | { |
| 83 | percpu_counter_inc(&nn->counter[NFSD_NET_PAYLOAD_MISSES]); |
| 84 | } |
| 85 | |
| 86 | static inline void nfsd_stats_drc_mem_usage_add(struct nfsd_net *nn, s64 amount) |
| 87 | { |
| 88 | percpu_counter_add(&nn->counter[NFSD_NET_DRC_MEM_USAGE], amount); |
| 89 | } |
| 90 | |
| 91 | static inline void nfsd_stats_drc_mem_usage_sub(struct nfsd_net *nn, s64 amount) |
| 92 | { |
| 93 | percpu_counter_sub(&nn->counter[NFSD_NET_DRC_MEM_USAGE], amount); |
| 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Christoph Hellwig | 7f94423 | 2014-05-06 19:37:15 +0200 | [diff] [blame] | 96 | #endif /* _NFSD_STATS_H */ |