blob: 733ab62ae14130dc62c8d62e48e45002aa149781 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andrew Morton7c3ab7382006-12-10 02:19:19 -08002/*
3 * Task I/O accounting operations
4 */
5#ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED
6#define __TASK_IO_ACCOUNTING_OPS_INCLUDED
7
Alexey Dobriyane8edc6e2007-05-21 01:22:52 +04008#include <linux/sched.h>
9
Andrew Morton7c3ab7382006-12-10 02:19:19 -080010#ifdef CONFIG_TASK_IO_ACCOUNTING
11static inline void task_io_account_read(size_t bytes)
12{
Andrea Righi940389b2008-07-28 00:48:12 +020013 current->ioac.read_bytes += bytes;
Andrew Morton7c3ab7382006-12-10 02:19:19 -080014}
15
Eric Dumazet6eaeeab2007-05-10 22:22:37 -070016/*
17 * We approximate number of blocks, because we account bytes only.
18 * A 'block' is 512 bytes
19 */
20static inline unsigned long task_io_get_inblock(const struct task_struct *p)
21{
Andrea Righi940389b2008-07-28 00:48:12 +020022 return p->ioac.read_bytes >> 9;
Eric Dumazet6eaeeab2007-05-10 22:22:37 -070023}
24
Andrew Morton7c3ab7382006-12-10 02:19:19 -080025static inline void task_io_account_write(size_t bytes)
26{
Andrea Righi940389b2008-07-28 00:48:12 +020027 current->ioac.write_bytes += bytes;
Andrew Morton7c3ab7382006-12-10 02:19:19 -080028}
29
Eric Dumazet6eaeeab2007-05-10 22:22:37 -070030/*
31 * We approximate number of blocks, because we account bytes only.
32 * A 'block' is 512 bytes
33 */
34static inline unsigned long task_io_get_oublock(const struct task_struct *p)
35{
Andrea Righi940389b2008-07-28 00:48:12 +020036 return p->ioac.write_bytes >> 9;
Eric Dumazet6eaeeab2007-05-10 22:22:37 -070037}
38
Andrew Morton7c3ab7382006-12-10 02:19:19 -080039static inline void task_io_account_cancelled_write(size_t bytes)
40{
Andrea Righi940389b2008-07-28 00:48:12 +020041 current->ioac.cancelled_write_bytes += bytes;
Andrew Morton7c3ab7382006-12-10 02:19:19 -080042}
43
Andrea Righi940389b2008-07-28 00:48:12 +020044static inline void task_io_accounting_init(struct task_io_accounting *ioac)
Andrew Morton7c3ab7382006-12-10 02:19:19 -080045{
Andrea Righi59954772008-07-27 17:29:15 +020046 memset(ioac, 0, sizeof(*ioac));
47}
48
Andrea Righi940389b2008-07-28 00:48:12 +020049static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
50 struct task_io_accounting *src)
Andrea Righi59954772008-07-27 17:29:15 +020051{
Andrea Righi940389b2008-07-28 00:48:12 +020052 dst->read_bytes += src->read_bytes;
53 dst->write_bytes += src->write_bytes;
54 dst->cancelled_write_bytes += src->cancelled_write_bytes;
Andrew Morton7c3ab7382006-12-10 02:19:19 -080055}
56
57#else
58
59static inline void task_io_account_read(size_t bytes)
60{
61}
62
Eric Dumazet6eaeeab2007-05-10 22:22:37 -070063static inline unsigned long task_io_get_inblock(const struct task_struct *p)
64{
65 return 0;
66}
67
Andrew Morton7c3ab7382006-12-10 02:19:19 -080068static inline void task_io_account_write(size_t bytes)
69{
70}
71
Eric Dumazet6eaeeab2007-05-10 22:22:37 -070072static inline unsigned long task_io_get_oublock(const struct task_struct *p)
73{
74 return 0;
75}
76
Andrew Morton7c3ab7382006-12-10 02:19:19 -080077static inline void task_io_account_cancelled_write(size_t bytes)
78{
79}
80
Andrea Righi940389b2008-07-28 00:48:12 +020081static inline void task_io_accounting_init(struct task_io_accounting *ioac)
Andrew Morton7c3ab7382006-12-10 02:19:19 -080082{
83}
84
Andrea Righi940389b2008-07-28 00:48:12 +020085static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
86 struct task_io_accounting *src)
Andrea Righi59954772008-07-27 17:29:15 +020087{
88}
89
90#endif /* CONFIG_TASK_IO_ACCOUNTING */
91
92#ifdef CONFIG_TASK_XACCT
Andrea Righi940389b2008-07-28 00:48:12 +020093static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
94 struct task_io_accounting *src)
Andrea Righi59954772008-07-27 17:29:15 +020095{
Andrea Righi940389b2008-07-28 00:48:12 +020096 dst->rchar += src->rchar;
97 dst->wchar += src->wchar;
98 dst->syscr += src->syscr;
99 dst->syscw += src->syscw;
Jin Qianad4b32c2017-03-02 13:32:59 -0800100 dst->syscfs += src->syscfs;
Andrea Righi59954772008-07-27 17:29:15 +0200101}
102#else
Andrea Righi940389b2008-07-28 00:48:12 +0200103static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
104 struct task_io_accounting *src)
Andrea Righi59954772008-07-27 17:29:15 +0200105{
106}
107#endif /* CONFIG_TASK_XACCT */
108
Andrea Righi940389b2008-07-28 00:48:12 +0200109static inline void task_io_accounting_add(struct task_io_accounting *dst,
110 struct task_io_accounting *src)
Andrea Righi59954772008-07-27 17:29:15 +0200111{
112 task_chr_io_accounting_add(dst, src);
113 task_blk_io_accounting_add(dst, src);
114}
115#endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */