1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
27c3ab738SAndrew Morton /*
37c3ab738SAndrew Morton * Task I/O accounting operations
47c3ab738SAndrew Morton */
57c3ab738SAndrew Morton #ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED
67c3ab738SAndrew Morton #define __TASK_IO_ACCOUNTING_OPS_INCLUDED
77c3ab738SAndrew Morton
8e8edc6e0SAlexey Dobriyan #include <linux/sched.h>
9e8edc6e0SAlexey Dobriyan
107c3ab738SAndrew Morton #ifdef CONFIG_TASK_IO_ACCOUNTING
task_io_account_read(size_t bytes)117c3ab738SAndrew Morton static inline void task_io_account_read(size_t bytes)
127c3ab738SAndrew Morton {
13940389b8SAndrea Righi current->ioac.read_bytes += bytes;
147c3ab738SAndrew Morton }
157c3ab738SAndrew Morton
166eaeeabaSEric Dumazet /*
176eaeeabaSEric Dumazet * We approximate number of blocks, because we account bytes only.
186eaeeabaSEric Dumazet * A 'block' is 512 bytes
196eaeeabaSEric Dumazet */
task_io_get_inblock(const struct task_struct * p)206eaeeabaSEric Dumazet static inline unsigned long task_io_get_inblock(const struct task_struct *p)
216eaeeabaSEric Dumazet {
22940389b8SAndrea Righi return p->ioac.read_bytes >> 9;
236eaeeabaSEric Dumazet }
246eaeeabaSEric Dumazet
task_io_account_write(size_t bytes)257c3ab738SAndrew Morton static inline void task_io_account_write(size_t bytes)
267c3ab738SAndrew Morton {
27940389b8SAndrea Righi current->ioac.write_bytes += bytes;
287c3ab738SAndrew Morton }
297c3ab738SAndrew Morton
306eaeeabaSEric Dumazet /*
316eaeeabaSEric Dumazet * We approximate number of blocks, because we account bytes only.
326eaeeabaSEric Dumazet * A 'block' is 512 bytes
336eaeeabaSEric Dumazet */
task_io_get_oublock(const struct task_struct * p)346eaeeabaSEric Dumazet static inline unsigned long task_io_get_oublock(const struct task_struct *p)
356eaeeabaSEric Dumazet {
36940389b8SAndrea Righi return p->ioac.write_bytes >> 9;
376eaeeabaSEric Dumazet }
386eaeeabaSEric Dumazet
task_io_account_cancelled_write(size_t bytes)397c3ab738SAndrew Morton static inline void task_io_account_cancelled_write(size_t bytes)
407c3ab738SAndrew Morton {
41940389b8SAndrea Righi current->ioac.cancelled_write_bytes += bytes;
427c3ab738SAndrew Morton }
437c3ab738SAndrew Morton
task_io_accounting_init(struct task_io_accounting * ioac)44940389b8SAndrea Righi static inline void task_io_accounting_init(struct task_io_accounting *ioac)
457c3ab738SAndrew Morton {
465995477aSAndrea Righi memset(ioac, 0, sizeof(*ioac));
475995477aSAndrea Righi }
485995477aSAndrea Righi
task_blk_io_accounting_add(struct task_io_accounting * dst,struct task_io_accounting * src)49940389b8SAndrea Righi static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
50940389b8SAndrea Righi struct task_io_accounting *src)
515995477aSAndrea Righi {
52940389b8SAndrea Righi dst->read_bytes += src->read_bytes;
53940389b8SAndrea Righi dst->write_bytes += src->write_bytes;
54940389b8SAndrea Righi dst->cancelled_write_bytes += src->cancelled_write_bytes;
557c3ab738SAndrew Morton }
567c3ab738SAndrew Morton
577c3ab738SAndrew Morton #else
587c3ab738SAndrew Morton
task_io_account_read(size_t bytes)597c3ab738SAndrew Morton static inline void task_io_account_read(size_t bytes)
607c3ab738SAndrew Morton {
617c3ab738SAndrew Morton }
627c3ab738SAndrew Morton
task_io_get_inblock(const struct task_struct * p)636eaeeabaSEric Dumazet static inline unsigned long task_io_get_inblock(const struct task_struct *p)
646eaeeabaSEric Dumazet {
656eaeeabaSEric Dumazet return 0;
666eaeeabaSEric Dumazet }
676eaeeabaSEric Dumazet
task_io_account_write(size_t bytes)687c3ab738SAndrew Morton static inline void task_io_account_write(size_t bytes)
697c3ab738SAndrew Morton {
707c3ab738SAndrew Morton }
717c3ab738SAndrew Morton
task_io_get_oublock(const struct task_struct * p)726eaeeabaSEric Dumazet static inline unsigned long task_io_get_oublock(const struct task_struct *p)
736eaeeabaSEric Dumazet {
746eaeeabaSEric Dumazet return 0;
756eaeeabaSEric Dumazet }
766eaeeabaSEric Dumazet
task_io_account_cancelled_write(size_t bytes)777c3ab738SAndrew Morton static inline void task_io_account_cancelled_write(size_t bytes)
787c3ab738SAndrew Morton {
797c3ab738SAndrew Morton }
807c3ab738SAndrew Morton
task_io_accounting_init(struct task_io_accounting * ioac)81940389b8SAndrea Righi static inline void task_io_accounting_init(struct task_io_accounting *ioac)
825995477aSAndrea Righi {
835995477aSAndrea Righi }
845995477aSAndrea Righi
task_blk_io_accounting_add(struct task_io_accounting * dst,struct task_io_accounting * src)85940389b8SAndrea Righi static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
86940389b8SAndrea Righi struct task_io_accounting *src)
877c3ab738SAndrew Morton {
887c3ab738SAndrew Morton }
897c3ab738SAndrew Morton
907c3ab738SAndrew Morton #endif /* CONFIG_TASK_IO_ACCOUNTING */
915995477aSAndrea Righi
925995477aSAndrea Righi #ifdef CONFIG_TASK_XACCT
task_chr_io_accounting_add(struct task_io_accounting * dst,struct task_io_accounting * src)93940389b8SAndrea Righi static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
94940389b8SAndrea Righi struct task_io_accounting *src)
955995477aSAndrea Righi {
96940389b8SAndrea Righi dst->rchar += src->rchar;
97940389b8SAndrea Righi dst->wchar += src->wchar;
98940389b8SAndrea Righi dst->syscr += src->syscr;
99940389b8SAndrea Righi dst->syscw += src->syscw;
1005995477aSAndrea Righi }
1015995477aSAndrea Righi #else
task_chr_io_accounting_add(struct task_io_accounting * dst,struct task_io_accounting * src)102940389b8SAndrea Righi static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
103940389b8SAndrea Righi struct task_io_accounting *src)
1045995477aSAndrea Righi {
1055995477aSAndrea Righi }
1065995477aSAndrea Righi #endif /* CONFIG_TASK_XACCT */
1075995477aSAndrea Righi
task_io_accounting_add(struct task_io_accounting * dst,struct task_io_accounting * src)108940389b8SAndrea Righi static inline void task_io_accounting_add(struct task_io_accounting *dst,
109940389b8SAndrea Righi struct task_io_accounting *src)
1105995477aSAndrea Righi {
1115995477aSAndrea Righi task_chr_io_accounting_add(dst, src);
1125995477aSAndrea Righi task_blk_io_accounting_add(dst, src);
1135995477aSAndrea Righi }
1147c3ab738SAndrew Morton #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */
115