task_io_accounting_ops.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Task I/O accounting operations
  4. */
  5. #ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED
  6. #define __TASK_IO_ACCOUNTING_OPS_INCLUDED
  7. #include <linux/sched.h>
  8. #ifdef CONFIG_TASK_IO_ACCOUNTING
  9. static inline void task_io_account_read(size_t bytes)
  10. {
  11. current->ioac.read_bytes += bytes;
  12. }
  13. /*
  14. * We approximate number of blocks, because we account bytes only.
  15. * A 'block' is 512 bytes
  16. */
  17. static inline unsigned long task_io_get_inblock(const struct task_struct *p)
  18. {
  19. return p->ioac.read_bytes >> 9;
  20. }
  21. static inline void task_io_account_write(size_t bytes)
  22. {
  23. current->ioac.write_bytes += bytes;
  24. }
  25. /*
  26. * We approximate number of blocks, because we account bytes only.
  27. * A 'block' is 512 bytes
  28. */
  29. static inline unsigned long task_io_get_oublock(const struct task_struct *p)
  30. {
  31. return p->ioac.write_bytes >> 9;
  32. }
  33. static inline void task_io_account_cancelled_write(size_t bytes)
  34. {
  35. current->ioac.cancelled_write_bytes += bytes;
  36. }
  37. static inline void task_io_accounting_init(struct task_io_accounting *ioac)
  38. {
  39. memset(ioac, 0, sizeof(*ioac));
  40. }
  41. static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
  42. struct task_io_accounting *src)
  43. {
  44. dst->read_bytes += src->read_bytes;
  45. dst->write_bytes += src->write_bytes;
  46. dst->cancelled_write_bytes += src->cancelled_write_bytes;
  47. }
  48. #else
  49. static inline void task_io_account_read(size_t bytes)
  50. {
  51. }
  52. static inline unsigned long task_io_get_inblock(const struct task_struct *p)
  53. {
  54. return 0;
  55. }
  56. static inline void task_io_account_write(size_t bytes)
  57. {
  58. }
  59. static inline unsigned long task_io_get_oublock(const struct task_struct *p)
  60. {
  61. return 0;
  62. }
  63. static inline void task_io_account_cancelled_write(size_t bytes)
  64. {
  65. }
  66. static inline void task_io_accounting_init(struct task_io_accounting *ioac)
  67. {
  68. }
  69. static inline void task_blk_io_accounting_add(struct task_io_accounting *dst,
  70. struct task_io_accounting *src)
  71. {
  72. }
  73. #endif /* CONFIG_TASK_IO_ACCOUNTING */
  74. #ifdef CONFIG_TASK_XACCT
  75. static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
  76. struct task_io_accounting *src)
  77. {
  78. dst->rchar += src->rchar;
  79. dst->wchar += src->wchar;
  80. dst->syscr += src->syscr;
  81. dst->syscw += src->syscw;
  82. dst->syscfs += src->syscfs;
  83. }
  84. #else
  85. static inline void task_chr_io_accounting_add(struct task_io_accounting *dst,
  86. struct task_io_accounting *src)
  87. {
  88. }
  89. #endif /* CONFIG_TASK_XACCT */
  90. static inline void task_io_accounting_add(struct task_io_accounting *dst,
  91. struct task_io_accounting *src)
  92. {
  93. task_chr_io_accounting_add(dst, src);
  94. task_blk_io_accounting_add(dst, src);
  95. }
  96. #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */