iostat.h 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 *  linux/fs/nfs/iostat.h
 *
 *  Declarations for NFS client per-mount statistics
 *
 *  Copyright (C) 2005, 2006 Chuck Lever <cel@netapp.com>
 *
 */

#ifndef _NFS_IOSTAT
#define _NFS_IOSTAT

#include <linux/percpu.h>
#include <linux/cache.h>
15
#include <linux/nfs_iostat.h>
16 17 18

struct nfs_iostats {
	unsigned long long	bytes[__NFSIOS_BYTESMAX];
19 20 21
#ifdef CONFIG_NFS_FSCACHE
	unsigned long long	fscache[__NFSIOS_FSCACHEMAX];
#endif
22 23 24
	unsigned long		events[__NFSIOS_COUNTSMAX];
} ____cacheline_aligned;

25
static inline void nfs_inc_server_stats(const struct nfs_server *server,
26
					enum nfs_stat_eventcounters stat)
27 28 29 30 31
{
	struct nfs_iostats *iostats;
	int cpu;

	cpu = get_cpu();
32
	iostats = per_cpu_ptr(server->io_stats, cpu);
33
	iostats->events[stat]++;
T
Thomas Gleixner 已提交
34
	put_cpu();
35 36
}

37
static inline void nfs_inc_stats(const struct inode *inode,
38
				 enum nfs_stat_eventcounters stat)
39 40 41 42
{
	nfs_inc_server_stats(NFS_SERVER(inode), stat);
}

43
static inline void nfs_add_server_stats(const struct nfs_server *server,
44 45
					enum nfs_stat_bytecounters stat,
					unsigned long addend)
46 47 48 49 50
{
	struct nfs_iostats *iostats;
	int cpu;

	cpu = get_cpu();
51
	iostats = per_cpu_ptr(server->io_stats, cpu);
52
	iostats->bytes[stat] += addend;
T
Thomas Gleixner 已提交
53
	put_cpu();
54 55
}

56
static inline void nfs_add_stats(const struct inode *inode,
57 58
				 enum nfs_stat_bytecounters stat,
				 unsigned long addend)
59 60 61 62
{
	nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
}

63 64 65 66 67 68 69 70 71 72 73
#ifdef CONFIG_NFS_FSCACHE
static inline void nfs_add_fscache_stats(struct inode *inode,
					 enum nfs_stat_fscachecounters stat,
					 unsigned long addend)
{
	struct nfs_iostats *iostats;
	int cpu;

	cpu = get_cpu();
	iostats = per_cpu_ptr(NFS_SERVER(inode)->io_stats, cpu);
	iostats->fscache[stat] += addend;
T
Thomas Gleixner 已提交
74
	put_cpu();
75 76 77
}
#endif

78 79 80 81 82 83 84
static inline struct nfs_iostats *nfs_alloc_iostats(void)
{
	return alloc_percpu(struct nfs_iostats);
}

static inline void nfs_free_iostats(struct nfs_iostats *stats)
{
85 86
	if (stats != NULL)
		free_percpu(stats);
87 88
}

89
#endif /* _NFS_IOSTAT */