Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Task I/O accounting operations
0004  */
0005 #ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED
0006 #define __TASK_IO_ACCOUNTING_OPS_INCLUDED
0007 
0008 #include <linux/sched.h>
0009 
0010 #ifdef CONFIG_TASK_IO_ACCOUNTING
0011 static inline void task_io_account_read(size_t bytes)
0012 {
0013     current->ioac.read_bytes += bytes;
0014 }
0015 
0016 /*
0017  * We approximate number of blocks, because we account bytes only.
0018  * A 'block' is 512 bytes
0019  */
0020 static inline unsigned long task_io_get_inblock(const struct task_struct *p)
0021 {
0022     return p->ioac.read_bytes >> 9;
0023 }
0024 
0025 static inline void task_io_account_write(size_t bytes)
0026 {
0027     current->ioac.write_bytes += bytes;
0028 }
0029 
0030 /*
0031  * We approximate number of blocks, because we account bytes only.
0032  * A 'block' is 512 bytes
0033  */
0034 static inline unsigned long task_io_get_oublock(const struct task_struct *p)
0035 {
0036     return p->ioac.write_bytes >> 9;
0037 }
0038 
0039 static inline void task_io_account_cancelled_write(size_t bytes)
0040 {
0041     current->ioac.cancelled_write_bytes += bytes;
0042 }
0043 
0044 static inline void task_io_accounting_init(struct task_io_accounting *ioac)
0045 {
0046     memset(ioac, 0, sizeof(*ioac));
0047 }
0048 
0049 static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
0050                         struct task_io_accounting *src)
0051 {
0052     dst->read_bytes += src->read_bytes;
0053     dst->write_bytes += src->write_bytes;
0054     dst->cancelled_write_bytes += src->cancelled_write_bytes;
0055 }
0056 
0057 #else
0058 
0059 static inline void task_io_account_read(size_t bytes)
0060 {
0061 }
0062 
0063 static inline unsigned long task_io_get_inblock(const struct task_struct *p)
0064 {
0065     return 0;
0066 }
0067 
0068 static inline void task_io_account_write(size_t bytes)
0069 {
0070 }
0071 
0072 static inline unsigned long task_io_get_oublock(const struct task_struct *p)
0073 {
0074     return 0;
0075 }
0076 
0077 static inline void task_io_account_cancelled_write(size_t bytes)
0078 {
0079 }
0080 
0081 static inline void task_io_accounting_init(struct task_io_accounting *ioac)
0082 {
0083 }
0084 
0085 static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
0086                         struct task_io_accounting *src)
0087 {
0088 }
0089 
0090 #endif /* CONFIG_TASK_IO_ACCOUNTING */
0091 
0092 #ifdef CONFIG_TASK_XACCT
0093 static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
0094                         struct task_io_accounting *src)
0095 {
0096     dst->rchar += src->rchar;
0097     dst->wchar += src->wchar;
0098     dst->syscr += src->syscr;
0099     dst->syscw += src->syscw;
0100 }
0101 #else
0102 static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
0103                         struct task_io_accounting *src)
0104 {
0105 }
0106 #endif /* CONFIG_TASK_XACCT */
0107 
0108 static inline void task_io_accounting_add(struct task_io_accounting *dst,
0109                         struct task_io_accounting *src)
0110 {
0111     task_chr_io_accounting_add(dst, src);
0112     task_blk_io_accounting_add(dst, src);
0113 }
0114 #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */