Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/nfs/iostat.h |
| 4 | * |
| 5 | * Declarations for NFS client per-mount statistics |
| 6 | * |
| 7 | * Copyright (C) 2005, 2006 Chuck Lever <cel@netapp.com> |
| 8 | * |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef _NFS_IOSTAT |
| 12 | #define _NFS_IOSTAT |
| 13 | |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 14 | #include <linux/percpu.h> |
| 15 | #include <linux/cache.h> |
Chuck Lever | 34e8f92 | 2008-06-12 12:32:25 -0400 | [diff] [blame] | 16 | #include <linux/nfs_iostat.h> |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 17 | |
| 18 | struct nfs_iostats { |
| 19 | unsigned long long bytes[__NFSIOS_BYTESMAX]; |
David Howells | 6a51091 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 20 | #ifdef CONFIG_NFS_FSCACHE |
| 21 | unsigned long long fscache[__NFSIOS_FSCACHEMAX]; |
| 22 | #endif |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 23 | unsigned long events[__NFSIOS_COUNTSMAX]; |
| 24 | } ____cacheline_aligned; |
| 25 | |
Trond Myklebust | 2e96d28 | 2008-06-11 16:42:05 -0400 | [diff] [blame] | 26 | static inline void nfs_inc_server_stats(const struct nfs_server *server, |
Chuck Lever | 34e8f92 | 2008-06-12 12:32:25 -0400 | [diff] [blame] | 27 | enum nfs_stat_eventcounters stat) |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 28 | { |
Christoph Lameter | fce2284 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 29 | this_cpu_inc(server->io_stats->events[stat]); |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 30 | } |
| 31 | |
Trond Myklebust | 2e96d28 | 2008-06-11 16:42:05 -0400 | [diff] [blame] | 32 | static inline void nfs_inc_stats(const struct inode *inode, |
Chuck Lever | 34e8f92 | 2008-06-12 12:32:25 -0400 | [diff] [blame] | 33 | enum nfs_stat_eventcounters stat) |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 34 | { |
| 35 | nfs_inc_server_stats(NFS_SERVER(inode), stat); |
| 36 | } |
| 37 | |
Trond Myklebust | 2e96d28 | 2008-06-11 16:42:05 -0400 | [diff] [blame] | 38 | static inline void nfs_add_server_stats(const struct nfs_server *server, |
Chuck Lever | 34e8f92 | 2008-06-12 12:32:25 -0400 | [diff] [blame] | 39 | enum nfs_stat_bytecounters stat, |
Chuck Lever | dfe52c0 | 2010-05-07 13:34:08 -0400 | [diff] [blame] | 40 | long addend) |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 41 | { |
Christoph Lameter | fce2284 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 42 | this_cpu_add(server->io_stats->bytes[stat], addend); |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 43 | } |
| 44 | |
Trond Myklebust | 2e96d28 | 2008-06-11 16:42:05 -0400 | [diff] [blame] | 45 | static inline void nfs_add_stats(const struct inode *inode, |
Chuck Lever | 34e8f92 | 2008-06-12 12:32:25 -0400 | [diff] [blame] | 46 | enum nfs_stat_bytecounters stat, |
Chuck Lever | dfe52c0 | 2010-05-07 13:34:08 -0400 | [diff] [blame] | 47 | long addend) |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 48 | { |
Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 49 | nfs_add_server_stats(NFS_SERVER(inode), stat, addend); |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 50 | } |
| 51 | |
David Howells | 6a51091 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 52 | #ifdef CONFIG_NFS_FSCACHE |
| 53 | static inline void nfs_add_fscache_stats(struct inode *inode, |
| 54 | enum nfs_stat_fscachecounters stat, |
Chuck Lever | dfe52c0 | 2010-05-07 13:34:08 -0400 | [diff] [blame] | 55 | long addend) |
David Howells | 6a51091 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 56 | { |
Christoph Lameter | fce2284 | 2009-10-03 19:48:22 +0900 | [diff] [blame] | 57 | this_cpu_add(NFS_SERVER(inode)->io_stats->fscache[stat], addend); |
David Howells | 6a51091 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 58 | } |
Li RongQing | e9f456c | 2014-11-23 12:47:41 +0800 | [diff] [blame] | 59 | static inline void nfs_inc_fscache_stats(struct inode *inode, |
| 60 | enum nfs_stat_fscachecounters stat) |
| 61 | { |
| 62 | this_cpu_inc(NFS_SERVER(inode)->io_stats->fscache[stat]); |
| 63 | } |
David Howells | 6a51091 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 64 | #endif |
| 65 | |
Tejun Heo | 003cb60 | 2010-02-02 14:39:01 +0900 | [diff] [blame] | 66 | static inline struct nfs_iostats __percpu *nfs_alloc_iostats(void) |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 67 | { |
| 68 | return alloc_percpu(struct nfs_iostats); |
| 69 | } |
| 70 | |
Tejun Heo | 003cb60 | 2010-02-02 14:39:01 +0900 | [diff] [blame] | 71 | static inline void nfs_free_iostats(struct nfs_iostats __percpu *stats) |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 72 | { |
Trond Myklebust | 01d0ae8 | 2006-03-20 13:44:48 -0500 | [diff] [blame] | 73 | if (stats != NULL) |
| 74 | free_percpu(stats); |
Chuck Lever | d9ef5a8 | 2006-03-20 13:44:13 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Chuck Lever | 34e8f92 | 2008-06-12 12:32:25 -0400 | [diff] [blame] | 77 | #endif /* _NFS_IOSTAT */ |