Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Task I/O accounting operations |
| 3 | */ |
| 4 | #ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED |
| 5 | #define __TASK_IO_ACCOUNTING_OPS_INCLUDED |
| 6 | |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 7 | #include <linux/sched.h> |
| 8 | |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 9 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
| 10 | static inline void task_io_account_read(size_t bytes) |
| 11 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 12 | current->ioac.read_bytes += bytes; |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 13 | } |
| 14 | |
Eric Dumazet | 6eaeeab | 2007-05-10 22:22:37 -0700 | [diff] [blame] | 15 | /* |
| 16 | * We approximate number of blocks, because we account bytes only. |
| 17 | * A 'block' is 512 bytes |
| 18 | */ |
| 19 | static inline unsigned long task_io_get_inblock(const struct task_struct *p) |
| 20 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 21 | return p->ioac.read_bytes >> 9; |
Eric Dumazet | 6eaeeab | 2007-05-10 22:22:37 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 24 | static inline void task_io_account_write(size_t bytes) |
| 25 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 26 | current->ioac.write_bytes += bytes; |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 27 | } |
| 28 | |
Eric Dumazet | 6eaeeab | 2007-05-10 22:22:37 -0700 | [diff] [blame] | 29 | /* |
| 30 | * We approximate number of blocks, because we account bytes only. |
| 31 | * A 'block' is 512 bytes |
| 32 | */ |
| 33 | static inline unsigned long task_io_get_oublock(const struct task_struct *p) |
| 34 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 35 | return p->ioac.write_bytes >> 9; |
Eric Dumazet | 6eaeeab | 2007-05-10 22:22:37 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 38 | static inline void task_io_account_cancelled_write(size_t bytes) |
| 39 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 40 | current->ioac.cancelled_write_bytes += bytes; |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 41 | } |
| 42 | |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 43 | static inline void task_io_accounting_init(struct task_io_accounting *ioac) |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 44 | { |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 45 | memset(ioac, 0, sizeof(*ioac)); |
| 46 | } |
| 47 | |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 48 | static inline void task_blk_io_accounting_add(struct task_io_accounting *dst, |
| 49 | struct task_io_accounting *src) |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 50 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 51 | dst->read_bytes += src->read_bytes; |
| 52 | dst->write_bytes += src->write_bytes; |
| 53 | dst->cancelled_write_bytes += src->cancelled_write_bytes; |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | #else |
| 57 | |
| 58 | static inline void task_io_account_read(size_t bytes) |
| 59 | { |
| 60 | } |
| 61 | |
Eric Dumazet | 6eaeeab | 2007-05-10 22:22:37 -0700 | [diff] [blame] | 62 | static inline unsigned long task_io_get_inblock(const struct task_struct *p) |
| 63 | { |
| 64 | return 0; |
| 65 | } |
| 66 | |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 67 | static inline void task_io_account_write(size_t bytes) |
| 68 | { |
| 69 | } |
| 70 | |
Eric Dumazet | 6eaeeab | 2007-05-10 22:22:37 -0700 | [diff] [blame] | 71 | static inline unsigned long task_io_get_oublock(const struct task_struct *p) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 76 | static inline void task_io_account_cancelled_write(size_t bytes) |
| 77 | { |
| 78 | } |
| 79 | |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 80 | static inline void task_io_accounting_init(struct task_io_accounting *ioac) |
Andrew Morton | 7c3ab73 | 2006-12-10 02:19:19 -0800 | [diff] [blame] | 81 | { |
| 82 | } |
| 83 | |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 84 | static inline void task_blk_io_accounting_add(struct task_io_accounting *dst, |
| 85 | struct task_io_accounting *src) |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 86 | { |
| 87 | } |
| 88 | |
| 89 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ |
| 90 | |
| 91 | #ifdef CONFIG_TASK_XACCT |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 92 | static inline void task_chr_io_accounting_add(struct task_io_accounting *dst, |
| 93 | struct task_io_accounting *src) |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 94 | { |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 95 | dst->rchar += src->rchar; |
| 96 | dst->wchar += src->wchar; |
| 97 | dst->syscr += src->syscr; |
| 98 | dst->syscw += src->syscw; |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 99 | } |
| 100 | #else |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 101 | static inline void task_chr_io_accounting_add(struct task_io_accounting *dst, |
| 102 | struct task_io_accounting *src) |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 103 | { |
| 104 | } |
| 105 | #endif /* CONFIG_TASK_XACCT */ |
| 106 | |
Andrea Righi | 940389b | 2008-07-28 00:48:12 +0200 | [diff] [blame] | 107 | static inline void task_io_accounting_add(struct task_io_accounting *dst, |
| 108 | struct task_io_accounting *src) |
Andrea Righi | 5995477 | 2008-07-27 17:29:15 +0200 | [diff] [blame] | 109 | { |
| 110 | task_chr_io_accounting_add(dst, src); |
| 111 | task_blk_io_accounting_add(dst, src); |
| 112 | } |
| 113 | #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */ |