]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
7c3ab738 AM |
2 | /* |
3 | * Task I/O accounting operations | |
4 | */ | |
5 | #ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED | |
6 | #define __TASK_IO_ACCOUNTING_OPS_INCLUDED | |
7 | ||
e8edc6e0 AD |
8 | #include <linux/sched.h> |
9 | ||
7c3ab738 AM |
10 | #ifdef CONFIG_TASK_IO_ACCOUNTING |
11 | static inline void task_io_account_read(size_t bytes) | |
12 | { | |
940389b8 | 13 | current->ioac.read_bytes += bytes; |
7c3ab738 AM |
14 | } |
15 | ||
6eaeeaba ED |
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 | { | |
940389b8 | 22 | return p->ioac.read_bytes >> 9; |
6eaeeaba ED |
23 | } |
24 | ||
7c3ab738 AM |
25 | static inline void task_io_account_write(size_t bytes) |
26 | { | |
940389b8 | 27 | current->ioac.write_bytes += bytes; |
7c3ab738 AM |
28 | } |
29 | ||
6eaeeaba ED |
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 | { | |
940389b8 | 36 | return p->ioac.write_bytes >> 9; |
6eaeeaba ED |
37 | } |
38 | ||
7c3ab738 AM |
39 | static inline void task_io_account_cancelled_write(size_t bytes) |
40 | { | |
940389b8 | 41 | current->ioac.cancelled_write_bytes += bytes; |
7c3ab738 AM |
42 | } |
43 | ||
940389b8 | 44 | static inline void task_io_accounting_init(struct task_io_accounting *ioac) |
7c3ab738 | 45 | { |
5995477a AR |
46 | memset(ioac, 0, sizeof(*ioac)); |
47 | } | |
48 | ||
940389b8 AR |
49 | static inline void task_blk_io_accounting_add(struct task_io_accounting *dst, |
50 | struct task_io_accounting *src) | |
5995477a | 51 | { |
940389b8 AR |
52 | dst->read_bytes += src->read_bytes; |
53 | dst->write_bytes += src->write_bytes; | |
54 | dst->cancelled_write_bytes += src->cancelled_write_bytes; | |
7c3ab738 AM |
55 | } |
56 | ||
57 | #else | |
58 | ||
59 | static inline void task_io_account_read(size_t bytes) | |
60 | { | |
61 | } | |
62 | ||
6eaeeaba ED |
63 | static inline unsigned long task_io_get_inblock(const struct task_struct *p) |
64 | { | |
65 | return 0; | |
66 | } | |
67 | ||
7c3ab738 AM |
68 | static inline void task_io_account_write(size_t bytes) |
69 | { | |
70 | } | |
71 | ||
6eaeeaba ED |
72 | static inline unsigned long task_io_get_oublock(const struct task_struct *p) |
73 | { | |
74 | return 0; | |
75 | } | |
76 | ||
7c3ab738 AM |
77 | static inline void task_io_account_cancelled_write(size_t bytes) |
78 | { | |
79 | } | |
80 | ||
940389b8 | 81 | static inline void task_io_accounting_init(struct task_io_accounting *ioac) |
5995477a AR |
82 | { |
83 | } | |
84 | ||
940389b8 AR |
85 | static inline void task_blk_io_accounting_add(struct task_io_accounting *dst, |
86 | struct task_io_accounting *src) | |
7c3ab738 AM |
87 | { |
88 | } | |
89 | ||
5995477a AR |
90 | #endif /* CONFIG_TASK_IO_ACCOUNTING */ |
91 | ||
92 | #ifdef CONFIG_TASK_XACCT | |
940389b8 AR |
93 | static inline void task_chr_io_accounting_add(struct task_io_accounting *dst, |
94 | struct task_io_accounting *src) | |
5995477a | 95 | { |
940389b8 AR |
96 | dst->rchar += src->rchar; |
97 | dst->wchar += src->wchar; | |
98 | dst->syscr += src->syscr; | |
99 | dst->syscw += src->syscw; | |
5995477a AR |
100 | } |
101 | #else | |
940389b8 AR |
102 | static inline void task_chr_io_accounting_add(struct task_io_accounting *dst, |
103 | struct task_io_accounting *src) | |
5995477a AR |
104 | { |
105 | } | |
106 | #endif /* CONFIG_TASK_XACCT */ | |
107 | ||
940389b8 AR |
108 | static inline void task_io_accounting_add(struct task_io_accounting *dst, |
109 | struct task_io_accounting *src) | |
5995477a AR |
110 | { |
111 | task_chr_io_accounting_add(dst, src); | |
112 | task_blk_io_accounting_add(dst, src); | |
113 | } | |
114 | #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */ |