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