task_io_accounting_ops.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Task I/O accounting operations
  3. */
  4. #ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED
  5. #define __TASK_IO_ACCOUNTING_OPS_INCLUDED
  6. #ifdef CONFIG_TASK_IO_ACCOUNTING
  7. static inline void task_io_account_read(size_t bytes)
  8. {
  9. current->ioac.read_bytes += bytes;
  10. }
  11. /*
  12. * We approximate number of blocks, because we account bytes only.
  13. * A 'block' is 512 bytes
  14. */
  15. static inline unsigned long task_io_get_inblock(const struct task_struct *p)
  16. {
  17. return p->ioac.read_bytes >> 9;
  18. }
  19. static inline void task_io_account_write(size_t bytes)
  20. {
  21. current->ioac.write_bytes += bytes;
  22. }
  23. /*
  24. * We approximate number of blocks, because we account bytes only.
  25. * A 'block' is 512 bytes
  26. */
  27. static inline unsigned long task_io_get_oublock(const struct task_struct *p)
  28. {
  29. return p->ioac.write_bytes >> 9;
  30. }
  31. static inline void task_io_account_cancelled_write(size_t bytes)
  32. {
  33. current->ioac.cancelled_write_bytes += bytes;
  34. }
  35. static inline void task_io_accounting_init(struct task_struct *tsk)
  36. {
  37. memset(&tsk->ioac, 0, sizeof(tsk->ioac));
  38. }
  39. #else
  40. static inline void task_io_account_read(size_t bytes)
  41. {
  42. }
  43. static inline unsigned long task_io_get_inblock(const struct task_struct *p)
  44. {
  45. return 0;
  46. }
  47. static inline void task_io_account_write(size_t bytes)
  48. {
  49. }
  50. static inline unsigned long task_io_get_oublock(const struct task_struct *p)
  51. {
  52. return 0;
  53. }
  54. static inline void task_io_account_cancelled_write(size_t bytes)
  55. {
  56. }
  57. static inline void task_io_accounting_init(struct task_struct *tsk)
  58. {
  59. }
  60. #endif /* CONFIG_TASK_IO_ACCOUNTING */
  61. #endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */