xref: /openbmc/linux/fs/nfsd/stats.h (revision 5c816641)
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 	atomic_t	th_cnt;		/* number of available threads */
33 };
34 
35 extern struct nfsd_stats	nfsdstats;
36 
37 extern struct svc_stat		nfsd_svcstats;
38 
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 
60 static inline void nfsd_stats_fh_stale_inc(struct svc_export *exp)
61 {
62 	percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_FH_STALE]);
63 	if (exp)
64 		percpu_counter_inc(&exp->ex_stats.counter[EXP_STATS_FH_STALE]);
65 }
66 
67 static inline void nfsd_stats_io_read_add(struct svc_export *exp, s64 amount)
68 {
69 	percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_READ], amount);
70 	if (exp)
71 		percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_READ], amount);
72 }
73 
74 static inline void nfsd_stats_io_write_add(struct svc_export *exp, s64 amount)
75 {
76 	percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_WRITE], amount);
77 	if (exp)
78 		percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_WRITE], amount);
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 }
95 
96 #endif /* _NFSD_STATS_H */
97