blob: 9b43dc3d999139c765d41d935953ae6ac42d39d3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Statistics for NFS server.
4 *
5 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
6 */
Christoph Hellwig7f944232014-05-06 19:37:15 +02007#ifndef _NFSD_STATS_H
8#define _NFSD_STATS_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
David Howells616d1ca2012-10-09 09:49:02 +010010#include <uapi/linux/nfsd/stats.h>
Amir Goldsteine567b982021-01-06 09:52:35 +020011#include <linux/percpu_counter.h>
Shankar Anande2b20952006-07-10 04:45:44 -070012
Greg Banks42d671c2009-03-27 02:32:47 +110013
Amir Goldsteine567b982021-01-06 09:52:35 +020014enum {
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 Torvalds1da177e2005-04-16 15:20:36 -070029struct nfsd_stats {
Amir Goldsteine567b982021-01-06 09:52:35 +020030 struct percpu_counter counter[NFSD_STATS_COUNTERS_NUM];
Shankar Anande2b20952006-07-10 04:45:44 -070031
NeilBrown9b6c8c92021-11-29 15:51:25 +110032 atomic_t th_cnt; /* number of available threads */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033};
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035extern struct nfsd_stats nfsdstats;
Amir Goldsteine567b982021-01-06 09:52:35 +020036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037extern struct svc_stat nfsd_svcstats;
38
Amir Goldsteine567b982021-01-06 09:52:35 +020039int nfsd_percpu_counters_init(struct percpu_counter counters[], int num);
40void nfsd_percpu_counters_reset(struct percpu_counter counters[], int num);
41void nfsd_percpu_counters_destroy(struct percpu_counter counters[], int num);
42int nfsd_stat_init(void);
43void nfsd_stat_shutdown(void);
44
45static inline void nfsd_stats_rc_hits_inc(void)
46{
47 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_HITS]);
48}
49
50static inline void nfsd_stats_rc_misses_inc(void)
51{
52 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_MISSES]);
53}
54
55static inline void nfsd_stats_rc_nocache_inc(void)
56{
57 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_RC_NOCACHE]);
58}
59
Amir Goldstein20ad8562021-01-06 09:52:36 +020060static inline void nfsd_stats_fh_stale_inc(struct svc_export *exp)
Amir Goldsteine567b982021-01-06 09:52:35 +020061{
62 percpu_counter_inc(&nfsdstats.counter[NFSD_STATS_FH_STALE]);
Amir Goldstein20ad8562021-01-06 09:52:36 +020063 if (exp)
64 percpu_counter_inc(&exp->ex_stats.counter[EXP_STATS_FH_STALE]);
Amir Goldsteine567b982021-01-06 09:52:35 +020065}
66
Amir Goldstein20ad8562021-01-06 09:52:36 +020067static inline void nfsd_stats_io_read_add(struct svc_export *exp, s64 amount)
Amir Goldsteine567b982021-01-06 09:52:35 +020068{
69 percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_READ], amount);
Amir Goldstein20ad8562021-01-06 09:52:36 +020070 if (exp)
71 percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_READ], amount);
Amir Goldsteine567b982021-01-06 09:52:35 +020072}
73
Amir Goldstein20ad8562021-01-06 09:52:36 +020074static inline void nfsd_stats_io_write_add(struct svc_export *exp, s64 amount)
Amir Goldsteine567b982021-01-06 09:52:35 +020075{
76 percpu_counter_add(&nfsdstats.counter[NFSD_STATS_IO_WRITE], amount);
Amir Goldstein20ad8562021-01-06 09:52:36 +020077 if (exp)
78 percpu_counter_add(&exp->ex_stats.counter[EXP_STATS_IO_WRITE], amount);
Amir Goldsteine567b982021-01-06 09:52:35 +020079}
80
81static inline void nfsd_stats_payload_misses_inc(struct nfsd_net *nn)
82{
83 percpu_counter_inc(&nn->counter[NFSD_NET_PAYLOAD_MISSES]);
84}
85
86static 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
91static 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 Torvalds1da177e2005-04-16 15:20:36 -070095
Christoph Hellwig7f944232014-05-06 19:37:15 +020096#endif /* _NFSD_STATS_H */