blob: 2ec65e12bfed6523266af56113a12fa2e55f1625 [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];
19 unsigned long events[__NFSIOS_COUNTSMAX];
20} ____cacheline_aligned;
21
Chuck Lever34e8f922008-06-12 12:32:25 -040022static inline void nfs_inc_server_stats(struct nfs_server *server,
23 enum nfs_stat_eventcounters stat)
Chuck Leverd9ef5a82006-03-20 13:44:13 -050024{
25 struct nfs_iostats *iostats;
26 int cpu;
27
28 cpu = get_cpu();
Chuck Lever006ea732006-03-20 13:44:14 -050029 iostats = per_cpu_ptr(server->io_stats, cpu);
Chuck Lever34e8f922008-06-12 12:32:25 -040030 iostats->events[stat]++;
Chuck Leverd9ef5a82006-03-20 13:44:13 -050031 put_cpu_no_resched();
32}
33
Chuck Lever34e8f922008-06-12 12:32:25 -040034static inline void nfs_inc_stats(struct inode *inode,
35 enum nfs_stat_eventcounters stat)
Chuck Lever006ea732006-03-20 13:44:14 -050036{
37 nfs_inc_server_stats(NFS_SERVER(inode), stat);
38}
39
Chuck Lever34e8f922008-06-12 12:32:25 -040040static inline void nfs_add_server_stats(struct nfs_server *server,
41 enum nfs_stat_bytecounters stat,
42 unsigned long addend)
Chuck Lever006ea732006-03-20 13:44:14 -050043{
44 struct nfs_iostats *iostats;
45 int cpu;
46
47 cpu = get_cpu();
48 iostats = per_cpu_ptr(server->io_stats, cpu);
49 iostats->bytes[stat] += addend;
50 put_cpu_no_resched();
51}
52
Chuck Lever34e8f922008-06-12 12:32:25 -040053static inline void nfs_add_stats(struct inode *inode,
54 enum nfs_stat_bytecounters stat,
55 unsigned long addend)
Chuck Leverd9ef5a82006-03-20 13:44:13 -050056{
Chuck Lever006ea732006-03-20 13:44:14 -050057 nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
Chuck Leverd9ef5a82006-03-20 13:44:13 -050058}
59
60static inline struct nfs_iostats *nfs_alloc_iostats(void)
61{
62 return alloc_percpu(struct nfs_iostats);
63}
64
65static inline void nfs_free_iostats(struct nfs_iostats *stats)
66{
Trond Myklebust01d0ae82006-03-20 13:44:48 -050067 if (stats != NULL)
68 free_percpu(stats);
Chuck Leverd9ef5a82006-03-20 13:44:13 -050069}
70
Chuck Lever34e8f922008-06-12 12:32:25 -040071#endif /* _NFS_IOSTAT */