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 
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 
29 struct nfsd_stats {
30 	struct percpu_counter	counter[NFSD_STATS_COUNTERS_NUM];
31 
32 	/* Protected by nfsd_mutex */
33 	unsigned int	th_cnt;		/* number of available threads */
34 };
35 
36 
37 extern struct nfsd_stats	nfsdstats;
38 
39 extern struct svc_stat		nfsd_svcstats;
40 
41 int nfsd_percpu_counters_init(struct percpu_counter counters[], int num);
42 void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num);
43 void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num);
44 int nfsd_stat_init(void);
45 void nfsd_stat_shutdown(void);
46 
nfsd_stats_rc_hits_inc(void)47 static inline void nfsd_stats_rc_hits_inc(void)
48 {
49 	percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_HITS]);
50 }
51 
nfsd_stats_rc_misses_inc(void)52 static inline void nfsd_stats_rc_misses_inc(void)
53 {
54 	percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_MISSES]);
55 }
56 
nfsd_stats_rc_nocache_inc(void)57 static inline void nfsd_stats_rc_nocache_inc(void)
58 {
59 	percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_NOCACHE]);
60 }
61 
nfsd_stats_fh_stale_inc(struct svc_export * exp)62 static inline void nfsd_stats_fh_stale_inc(struct svc_export *exp)
63 {
64 	percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_FH_STALE]);
65 	if (exp)
66 		percpu_counter_inc(&exp->ex_stats.counter[EXP_STATS_FH_STALE]);
67 }
68 
nfsd_stats_io_read_add(struct svc_export * exp,s64 amount)69 static inline void nfsd_stats_io_read_add(struct svc_export *exp, s64 amount)
70 {
71 	percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_READ], amount);
72 	if (exp)
73 		percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_READ], amount);
74 }
75 
nfsd_stats_io_write_add(struct svc_export * exp,s64 amount)76 static inline void nfsd_stats_io_write_add(struct svc_export *exp, s64 amount)
77 {
78 	percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_WRITE], amount);
79 	if (exp)
80 		percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_WRITE], amount);
81 }
82 
nfsd_stats_payload_misses_inc(struct nfsd_net * nn)83 static inline void nfsd_stats_payload_misses_inc(struct nfsd_net *nn)
84 {
85 	percpu_counter_inc(&nn->counter[NFSD_NET_PAYLOAD_MISSES]);
86 }
87 
nfsd_stats_drc_mem_usage_add(struct nfsd_net * nn,s64 amount)88 static inline void nfsd_stats_drc_mem_usage_add(struct nfsd_net *nn, s64 amount)
89 {
90 	percpu_counter_add(&nn->counter[NFSD_NET_DRC_MEM_USAGE], amount);
91 }
92 
nfsd_stats_drc_mem_usage_sub(struct nfsd_net * nn,s64 amount)93 static inline void nfsd_stats_drc_mem_usage_sub(struct nfsd_net *nn, s64 amount)
94 {
95 	percpu_counter_sub(&nn->counter[NFSD_NET_DRC_MEM_USAGE], amount);
96 }
97 
98 #endif /* _NFSD_STATS_H */
99