delayacct.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #include <linux/slab.h>
  20. /*
  21. * Per-task flags relevant to delay accounting
  22. * maintained privately to avoid exhausting similar flags in sched.h:PF_*
  23. * Used to set current->delays->flags
  24. */
  25. #define DELAYACCT_PF_SWAPIN 0x00000001 /* I am doing a swapin */
  26. #define DELAYACCT_PF_BLKIO 0x00000002 /* I am waiting on IO */
  27. #ifdef CONFIG_TASK_DELAY_ACCT
  28. extern int delayacct_on; /* Delay accounting turned on/off */
  29. extern struct kmem_cache *delayacct_cache;
  30. extern void delayacct_init(void);
  31. extern void __delayacct_tsk_init(struct task_struct *);
  32. extern void __delayacct_tsk_exit(struct task_struct *);
  33. extern void __delayacct_blkio_start(void);
  34. extern void __delayacct_blkio_end(void);
  35. extern int __delayacct_add_tsk(struct taskstats *, struct task_struct *);
  36. extern __u64 __delayacct_blkio_ticks(struct task_struct *);
  37. extern void __delayacct_freepages_start(void);
  38. extern void __delayacct_freepages_end(void);
  39. static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
  40. {
  41. if (p->delays)
  42. return (p->delays->flags & DELAYACCT_PF_BLKIO);
  43. else
  44. return 0;
  45. }
  46. static inline void delayacct_set_flag(int flag)
  47. {
  48. if (current->delays)
  49. current->delays->flags |= flag;
  50. }
  51. static inline void delayacct_clear_flag(int flag)
  52. {
  53. if (current->delays)
  54. current->delays->flags &= ~flag;
  55. }
  56. static inline void delayacct_tsk_init(struct task_struct *tsk)
  57. {
  58. /* reinitialize in case parent's non-null pointer was dup'ed*/
  59. tsk->delays = NULL;
  60. if (delayacct_on)
  61. __delayacct_tsk_init(tsk);
  62. }
  63. /* Free tsk->delays. Called from bad fork and __put_task_struct
  64. * where there's no risk of tsk->delays being accessed elsewhere
  65. */
  66. static inline void delayacct_tsk_free(struct task_struct *tsk)
  67. {
  68. if (tsk->delays)
  69. kmem_cache_free(delayacct_cache, tsk->delays);
  70. tsk->delays = NULL;
  71. }
  72. static inline void delayacct_blkio_start(void)
  73. {
  74. delayacct_set_flag(DELAYACCT_PF_BLKIO);
  75. if (current->delays)
  76. __delayacct_blkio_start();
  77. }
  78. static inline void delayacct_blkio_end(void)
  79. {
  80. if (current->delays)
  81. __delayacct_blkio_end();
  82. delayacct_clear_flag(DELAYACCT_PF_BLKIO);
  83. }
  84. static inline int delayacct_add_tsk(struct taskstats *d,
  85. struct task_struct *tsk)
  86. {
  87. if (!delayacct_on || !tsk->delays)
  88. return 0;
  89. return __delayacct_add_tsk(d, tsk);
  90. }
  91. static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
  92. {
  93. if (tsk->delays)
  94. return __delayacct_blkio_ticks(tsk);
  95. return 0;
  96. }
  97. static inline void delayacct_freepages_start(void)
  98. {
  99. if (current->delays)
  100. __delayacct_freepages_start();
  101. }
  102. static inline void delayacct_freepages_end(void)
  103. {
  104. if (current->delays)
  105. __delayacct_freepages_end();
  106. }
  107. #else
  108. static inline void delayacct_set_flag(int flag)
  109. {}
  110. static inline void delayacct_clear_flag(int flag)
  111. {}
  112. static inline void delayacct_init(void)
  113. {}
  114. static inline void delayacct_tsk_init(struct task_struct *tsk)
  115. {}
  116. static inline void delayacct_tsk_free(struct task_struct *tsk)
  117. {}
  118. static inline void delayacct_blkio_start(void)
  119. {}
  120. static inline void delayacct_blkio_end(void)
  121. {}
  122. static inline int delayacct_add_tsk(struct taskstats *d,
  123. struct task_struct *tsk)
  124. { return 0; }
  125. static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
  126. { return 0; }
  127. static inline int delayacct_is_task_waiting_on_io(struct task_struct *p)
  128. { return 0; }
  129. static inline void delayacct_freepages_start(void)
  130. {}
  131. static inline void delayacct_freepages_end(void)
  132. {}
  133. #endif /* CONFIG_TASK_DELAY_ACCT */
  134. #endif