task_io_accounting_ops.h 2.5 KB

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