blob: a2ab2529b5ca4ee1c1ac2b8e3889e4651bb8f1ac [file] [log] [blame]
Chuck Leverd9ef5a82006-03-20 13:44:13 -05001/*
2 * linux/fs/nfs/iostat.h
3 *
4 * Declarations for NFS client per-mount statistics
5 *
6 * Copyright (C) 2005, 2006 Chuck Lever <cel@netapp.com>
7 *
Chuck Leverd9ef5a82006-03-20 13:44:13 -05008 */
9
10#ifndef _NFS_IOSTAT
11#define _NFS_IOSTAT
12
Chuck Leverd9ef5a82006-03-20 13:44:13 -050013#include <linux/percpu.h>
14#include <linux/cache.h>
Chuck Lever34e8f922008-06-12 12:32:25 -040015#include <linux/nfs_iostat.h>
Chuck Leverd9ef5a82006-03-20 13:44:13 -050016
17struct nfs_iostats {
18 unsigned long long bytes[__NFSIOS_BYTESMAX];
David Howells6a510912009-04-03 16:42:43 +010019#ifdef CONFIG_NFS_FSCACHE
20 unsigned long long fscache[__NFSIOS_FSCACHEMAX];
21#endif
Chuck Leverd9ef5a82006-03-20 13:44:13 -050022 unsigned long events[__NFSIOS_COUNTSMAX];
23} ____cacheline_aligned;
24
Trond Myklebust2e96d282008-06-11 16:42:05 -040025static inline void nfs_inc_server_stats(const struct nfs_server *server,
Chuck Lever34e8f922008-06-12 12:32:25 -040026 enum nfs_stat_eventcounters stat)
Chuck Leverd9ef5a82006-03-20 13:44:13 -050027{
28 struct nfs_iostats *iostats;
29 int cpu;
30
31 cpu = get_cpu();
Chuck Lever006ea732006-03-20 13:44:14 -050032 iostats = per_cpu_ptr(server->io_stats, cpu);
Chuck Lever34e8f922008-06-12 12:32:25 -040033 iostats->events[stat]++;
Chuck Leverd9ef5a82006-03-20 13:44:13 -050034 put_cpu_no_resched();
35}
36
Trond Myklebust2e96d282008-06-11 16:42:05 -040037static inline void nfs_inc_stats(const struct inode *inode,
Chuck Lever34e8f922008-06-12 12:32:25 -040038 enum nfs_stat_eventcounters stat)
Chuck Lever006ea732006-03-20 13:44:14 -050039{
40 nfs_inc_server_stats(NFS_SERVER(inode), stat);
41}
42
Trond Myklebust2e96d282008-06-11 16:42:05 -040043static inline void nfs_add_server_stats(const struct nfs_server *server,
Chuck Lever34e8f922008-06-12 12:32:25 -040044 enum nfs_stat_bytecounters stat,
45 unsigned long addend)
Chuck Lever006ea732006-03-20 13:44:14 -050046{
47 struct nfs_iostats *iostats;
48 int cpu;
49
50 cpu = get_cpu();
51 iostats = per_cpu_ptr(server->io_stats, cpu);
52 iostats->bytes[stat] += addend;
53 put_cpu_no_resched();
54}
55
Trond Myklebust2e96d282008-06-11 16:42:05 -040056static inline void nfs_add_stats(const struct inode *inode,
Chuck Lever34e8f922008-06-12 12:32:25 -040057 enum nfs_stat_bytecounters stat,
58 unsigned long addend)
Chuck Leverd9ef5a82006-03-20 13:44:13 -050059{
Chuck Lever006ea732006-03-20 13:44:14 -050060 nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
Chuck Leverd9ef5a82006-03-20 13:44:13 -050061}
62
David Howells6a510912009-04-03 16:42:43 +010063#ifdef CONFIG_NFS_FSCACHE
64static inline void nfs_add_fscache_stats(struct inode *inode,
65 enum nfs_stat_fscachecounters stat,
66 unsigned long addend)
67{
68 struct nfs_iostats *iostats;
69 int cpu;
70
71 cpu = get_cpu();
72 iostats = per_cpu_ptr(NFS_SERVER(inode)->io_stats, cpu);
73 iostats->fscache[stat] += addend;
74 put_cpu_no_resched();
75}
76#endif
77
Chuck Leverd9ef5a82006-03-20 13:44:13 -050078static inline struct nfs_iostats *nfs_alloc_iostats(void)
79{
80 return alloc_percpu(struct nfs_iostats);
81}
82
83static inline void nfs_free_iostats(struct nfs_iostats *stats)
84{
Trond Myklebust01d0ae82006-03-20 13:44:48 -050085 if (stats != NULL)
86 free_percpu(stats);
Chuck Leverd9ef5a82006-03-20 13:44:13 -050087}
88
Chuck Lever34e8f922008-06-12 12:32:25 -040089#endif /* _NFS_IOSTAT */