Commit | Line | Data |
---|---|---|
d9ef5a8c CL |
1 | /* |
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 | * | |
d9ef5a8c CL |
8 | */ |
9 | ||
10 | #ifndef _NFS_IOSTAT | |
11 | #define _NFS_IOSTAT | |
12 | ||
d9ef5a8c CL |
13 | #include <linux/percpu.h> |
14 | #include <linux/cache.h> | |
34e8f928 | 15 | #include <linux/nfs_iostat.h> |
d9ef5a8c CL |
16 | |
17 | struct nfs_iostats { | |
18 | unsigned long long bytes[__NFSIOS_BYTESMAX]; | |
6a51091d DH |
19 | #ifdef CONFIG_NFS_FSCACHE |
20 | unsigned long long fscache[__NFSIOS_FSCACHEMAX]; | |
21 | #endif | |
d9ef5a8c CL |
22 | unsigned long events[__NFSIOS_COUNTSMAX]; |
23 | } ____cacheline_aligned; | |
24 | ||
2e96d286 | 25 | static inline void nfs_inc_server_stats(const struct nfs_server *server, |
34e8f928 | 26 | enum nfs_stat_eventcounters stat) |
d9ef5a8c CL |
27 | { |
28 | struct nfs_iostats *iostats; | |
29 | int cpu; | |
30 | ||
31 | cpu = get_cpu(); | |
006ea73e | 32 | iostats = per_cpu_ptr(server->io_stats, cpu); |
34e8f928 | 33 | iostats->events[stat]++; |
d9ef5a8c CL |
34 | put_cpu_no_resched(); |
35 | } | |
36 | ||
2e96d286 | 37 | static inline void nfs_inc_stats(const struct inode *inode, |
34e8f928 | 38 | enum nfs_stat_eventcounters stat) |
006ea73e CL |
39 | { |
40 | nfs_inc_server_stats(NFS_SERVER(inode), stat); | |
41 | } | |
42 | ||
2e96d286 | 43 | static inline void nfs_add_server_stats(const struct nfs_server *server, |
34e8f928 CL |
44 | enum nfs_stat_bytecounters stat, |
45 | unsigned long addend) | |
d9ef5a8c CL |
46 | { |
47 | struct nfs_iostats *iostats; | |
48 | int cpu; | |
49 | ||
50 | cpu = get_cpu(); | |
006ea73e | 51 | iostats = per_cpu_ptr(server->io_stats, cpu); |
d9ef5a8c CL |
52 | iostats->bytes[stat] += addend; |
53 | put_cpu_no_resched(); | |
54 | } | |
55 | ||
2e96d286 | 56 | static inline void nfs_add_stats(const struct inode *inode, |
34e8f928 CL |
57 | enum nfs_stat_bytecounters stat, |
58 | unsigned long addend) | |
006ea73e CL |
59 | { |
60 | nfs_add_server_stats(NFS_SERVER(inode), stat, addend); | |
61 | } | |
62 | ||
6a51091d DH |
63 | #ifdef CONFIG_NFS_FSCACHE |
64 | static 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 | ||
d9ef5a8c CL |
78 | static inline struct nfs_iostats *nfs_alloc_iostats(void) |
79 | { | |
80 | return alloc_percpu(struct nfs_iostats); | |
81 | } | |
82 | ||
83 | static inline void nfs_free_iostats(struct nfs_iostats *stats) | |
84 | { | |
01d0ae8b TM |
85 | if (stats != NULL) |
86 | free_percpu(stats); | |
d9ef5a8c CL |
87 | } |
88 | ||
34e8f928 | 89 | #endif /* _NFS_IOSTAT */ |