xref: /linux/fs/nfsd/stats.h (revision ae22a94997b8a03dcb3c922857c203246711f9d4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Statistics for NFS server.
4  *
5  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
6  */
7 #ifndef _NFSD_STATS_H
8 #define _NFSD_STATS_H
9 
10 #include <uapi/linux/nfsd/stats.h>
11 #include <linux/percpu_counter.h>
12 
13 int nfsd_percpu_counters_init(struct percpu_counter *counters, int num);
14 void nfsd_percpu_counters_reset(struct percpu_counter *counters, int num);
15 void nfsd_percpu_counters_destroy(struct percpu_counter *counters, int num);
16 int nfsd_stat_counters_init(struct nfsd_net *nn);
17 void nfsd_stat_counters_destroy(struct nfsd_net *nn);
18 void nfsd_proc_stat_init(struct net *net);
19 void nfsd_proc_stat_shutdown(struct net *net);
20 
21 static inline void nfsd_stats_rc_hits_inc(struct nfsd_net *nn)
22 {
23 	percpu_counter_inc(&nn->counter[NFSD_STATS_RC_HITS]);
24 }
25 
26 static inline void nfsd_stats_rc_misses_inc(struct nfsd_net *nn)
27 {
28 	percpu_counter_inc(&nn->counter[NFSD_STATS_RC_MISSES]);
29 }
30 
31 static inline void nfsd_stats_rc_nocache_inc(struct nfsd_net *nn)
32 {
33 	percpu_counter_inc(&nn->counter[NFSD_STATS_RC_NOCACHE]);
34 }
35 
36 static inline void nfsd_stats_fh_stale_inc(struct nfsd_net *nn,
37 					   struct svc_export *exp)
38 {
39 	percpu_counter_inc(&nn->counter[NFSD_STATS_FH_STALE]);
40 	if (exp && exp->ex_stats)
41 		percpu_counter_inc(&exp->ex_stats->counter[EXP_STATS_FH_STALE]);
42 }
43 
44 static inline void nfsd_stats_io_read_add(struct nfsd_net *nn,
45 					  struct svc_export *exp, s64 amount)
46 {
47 	percpu_counter_add(&nn->counter[NFSD_STATS_IO_READ], amount);
48 	if (exp && exp->ex_stats)
49 		percpu_counter_add(&exp->ex_stats->counter[EXP_STATS_IO_READ], amount);
50 }
51 
52 static inline void nfsd_stats_io_write_add(struct nfsd_net *nn,
53 					   struct svc_export *exp, s64 amount)
54 {
55 	percpu_counter_add(&nn->counter[NFSD_STATS_IO_WRITE], amount);
56 	if (exp && exp->ex_stats)
57 		percpu_counter_add(&exp->ex_stats->counter[EXP_STATS_IO_WRITE], amount);
58 }
59 
60 static inline void nfsd_stats_payload_misses_inc(struct nfsd_net *nn)
61 {
62 	percpu_counter_inc(&nn->counter[NFSD_STATS_PAYLOAD_MISSES]);
63 }
64 
65 static inline void nfsd_stats_drc_mem_usage_add(struct nfsd_net *nn, s64 amount)
66 {
67 	percpu_counter_add(&nn->counter[NFSD_STATS_DRC_MEM_USAGE], amount);
68 }
69 
70 static inline void nfsd_stats_drc_mem_usage_sub(struct nfsd_net *nn, s64 amount)
71 {
72 	percpu_counter_sub(&nn->counter[NFSD_STATS_DRC_MEM_USAGE], amount);
73 }
74 
75 #ifdef CONFIG_NFSD_V4
76 static inline void nfsd_stats_wdeleg_getattr_inc(struct nfsd_net *nn)
77 {
78 	percpu_counter_inc(&nn->counter[NFSD_STATS_WDELEG_GETATTR]);
79 }
80 #endif
81 #endif /* _NFSD_STATS_H */
82