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