delayacct.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/taskstats_kern.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. #ifdef CONFIG_TASK_DELAY_ACCT
  27. extern int delayacct_on; /* Delay accounting turned on/off */
  28. extern kmem_cache_t *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. static inline void delayacct_set_flag(int flag)
  36. {
  37. if (current->delays)
  38. current->delays->flags |= flag;
  39. }
  40. static inline void delayacct_clear_flag(int flag)
  41. {
  42. if (current->delays)
  43. current->delays->flags &= ~flag;
  44. }
  45. static inline void delayacct_tsk_init(struct task_struct *tsk)
  46. {
  47. /* reinitialize in case parent's non-null pointer was dup'ed*/
  48. tsk->delays = NULL;
  49. if (unlikely(delayacct_on))
  50. __delayacct_tsk_init(tsk);
  51. }
  52. static inline void delayacct_tsk_exit(struct task_struct *tsk)
  53. {
  54. if (tsk->delays)
  55. __delayacct_tsk_exit(tsk);
  56. }
  57. static inline void delayacct_blkio_start(void)
  58. {
  59. if (current->delays)
  60. __delayacct_blkio_start();
  61. }
  62. static inline void delayacct_blkio_end(void)
  63. {
  64. if (current->delays)
  65. __delayacct_blkio_end();
  66. }
  67. static inline int delayacct_add_tsk(struct taskstats *d,
  68. struct task_struct *tsk)
  69. {
  70. if (likely(!delayacct_on))
  71. return -EINVAL;
  72. if (!tsk->delays)
  73. return 0;
  74. return __delayacct_add_tsk(d, tsk);
  75. }
  76. #else
  77. static inline void delayacct_set_flag(int flag)
  78. {}
  79. static inline void delayacct_clear_flag(int flag)
  80. {}
  81. static inline void delayacct_init(void)
  82. {}
  83. static inline void delayacct_tsk_init(struct task_struct *tsk)
  84. {}
  85. static inline void delayacct_tsk_exit(struct task_struct *tsk)
  86. {}
  87. static inline void delayacct_blkio_start(void)
  88. {}
  89. static inline void delayacct_blkio_end(void)
  90. {}
  91. static inline int delayacct_add_tsk(struct taskstats *d,
  92. struct task_struct *tsk)
  93. { return 0; }
  94. #endif /* CONFIG_TASK_DELAY_ACCT */
  95. #endif