task_io_accounting_ops.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_struct *tsk)
  37. {
  38. memset(&tsk->ioac, 0, sizeof(tsk->ioac));
  39. }
  40. #else
  41. static inline void task_io_account_read(size_t bytes)
  42. {
  43. }
  44. static inline unsigned long task_io_get_inblock(const struct task_struct *p)
  45. {
  46. return 0;
  47. }
  48. static inline void task_io_account_write(size_t bytes)
  49. {
  50. }
  51. static inline unsigned long task_io_get_oublock(const struct task_struct *p)
  52. {
  53. return 0;
  54. }
  55. static inline void task_io_account_cancelled_write(size_t bytes)
  56. {
  57. }
  58. static inline void task_io_accounting_init(struct task_struct *tsk)
  59. {
  60. }
  61. #endif /* CONFIG_TASK_IO_ACCOUNTING */
  62. #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */