delayacct.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* delayacct.h - per-task delay accounting
  2. *
  3. * Copyright (C) Shailabh Nagar, IBM Corp. 2006
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef _LINUX_DELAYACCT_H
  17. #define _LINUX_DELAYACCT_H
  18. #include <linux/sched.h>
  19. /*
  20. * Per-task flags relevant to delay accounting
  21. * maintained privately to avoid exhausting similar flags in sched.h:PF_*
  22. * Used to set current->delays->flags
  23. */
  24. #define DELAYACCT_PF_SWAPIN 0x00000001 /* I am doing a swapin */
  25. #define DELAYACCT_PF_BLKIO 0x00000002 /* I am waiting on IO */
  26. #ifdef CONFIG_TASK_DELAY_ACCT
  27. extern int delayacct_on; /* Delay accounting turned on/off */
  28. extern struct kmem_cache *delayacct_cache;
  29. extern void delayacct_init(void);
  30. extern void __delayacct_tsk_init(struct task_struct *);
  31. extern void __delayacct_tsk_exit(struct task_struct *);
  32. extern void __delayacct_blkio_start(void);
  33. extern void __delayacct_blkio_end(void);
  34. extern int __delayacct_add_tsk(struct taskstats *, struct task_struct *);
  35. extern __u64 __delayacct_blkio_ticks(struct task_struct *);
  36. extern void __delayacct_freepages_start(void);
  37. extern void __delayacct_freepages_end(void);
  38. static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
  39. {
  40. if (p->delays)
  41. return (p->delays->flags & DELAYACCT_PF_BLKIO);
  42. else
  43. return 0;
  44. }
  45. static inline void delayacct_set_flag(int flag)
  46. {
  47. if (current->delays)
  48. current->delays->flags |= flag;
  49. }
  50. static inline void delayacct_clear_flag(int flag)
  51. {
  52. if (current->delays)
  53. current->delays->flags &= ~flag;
  54. }
  55. static inline void delayacct_tsk_init(struct task_struct *tsk)
  56. {
  57. /* reinitialize in case parent's non-null pointer was dup'ed*/
  58. tsk->delays = NULL;
  59. if (delayacct_on)
  60. __delayacct_tsk_init(tsk);
  61. }
  62. /* Free tsk->delays. Called from bad fork and __put_task_struct
  63. * where there's no risk of tsk->delays being accessed elsewhere
  64. */
  65. static inline void delayacct_tsk_free(struct task_struct *tsk)
  66. {
  67. if (tsk->delays)
  68. kmem_cache_free(delayacct_cache, tsk->delays);
  69. tsk->delays = NULL;
  70. }
  71. static inline void delayacct_blkio_start(void)
  72. {
  73. delayacct_set_flag(DELAYACCT_PF_BLKIO);
  74. if (current->delays)
  75. __delayacct_blkio_start();
  76. }
  77. static inline void delayacct_blkio_end(void)
  78. {
  79. if (current->delays)
  80. __delayacct_blkio_end();
  81. delayacct_clear_flag(DELAYACCT_PF_BLKIO);
  82. }
  83. static inline int delayacct_add_tsk(struct taskstats *d,
  84. struct task_struct *tsk)
  85. {
  86. if (!delayacct_on || !tsk->delays)
  87. return 0;
  88. return __delayacct_add_tsk(d, tsk);
  89. }
  90. static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
  91. {
  92. if (tsk->delays)
  93. return __delayacct_blkio_ticks(tsk);
  94. return 0;
  95. }
  96. static inline void delayacct_freepages_start(void)
  97. {
  98. if (current->delays)
  99. __delayacct_freepages_start();
  100. }
  101. static inline void delayacct_freepages_end(void)
  102. {
  103. if (current->delays)
  104. __delayacct_freepages_end();
  105. }
  106. #else
  107. static inline void delayacct_set_flag(int flag)
  108. {}
  109. static inline void delayacct_clear_flag(int flag)
  110. {}
  111. static inline void delayacct_init(void)
  112. {}
  113. static inline void delayacct_tsk_init(struct task_struct *tsk)
  114. {}
  115. static inline void delayacct_tsk_free(struct task_struct *tsk)
  116. {}
  117. static inline void delayacct_blkio_start(void)
  118. {}
  119. static inline void delayacct_blkio_end(void)
  120. {}
  121. static inline int delayacct_add_tsk(struct taskstats *d,
  122. struct task_struct *tsk)
  123. { return 0; }
  124. static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
  125. { return 0; }
  126. static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
  127. { return 0; }
  128. static inline void delayacct_freepages_start(void)
  129. {}
  130. static inline void delayacct_freepages_end(void)
  131. {}
  132. #endif /* CONFIG_TASK_DELAY_ACCT */
  133. #endif