delayacct.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 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. static inline void delayacct_set_flag(int flag)
  37. {
  38. if (current->delays)
  39. current->delays->flags |= flag;
  40. }
  41. static inline void delayacct_clear_flag(int flag)
  42. {
  43. if (current->delays)
  44. current->delays->flags &= ~flag;
  45. }
  46. static inline void delayacct_tsk_init(struct task_struct *tsk)
  47. {
  48. /* reinitialize in case parent's non-null pointer was dup'ed*/
  49. tsk->delays = NULL;
  50. if (delayacct_on)
  51. __delayacct_tsk_init(tsk);
  52. }
  53. /* Free tsk->delays. Called from bad fork and __put_task_struct
  54. * where there's no risk of tsk->delays being accessed elsewhere
  55. */
  56. static inline void delayacct_tsk_free(struct task_struct *tsk)
  57. {
  58. if (tsk->delays)
  59. kmem_cache_free(delayacct_cache, tsk->delays);
  60. tsk->delays = NULL;
  61. }
  62. static inline void delayacct_blkio_start(void)
  63. {
  64. if (current->delays)
  65. __delayacct_blkio_start();
  66. }
  67. static inline void delayacct_blkio_end(void)
  68. {
  69. if (current->delays)
  70. __delayacct_blkio_end();
  71. }
  72. static inline int delayacct_add_tsk(struct taskstats *d,
  73. struct task_struct *tsk)
  74. {
  75. if (!delayacct_on || !tsk->delays)
  76. return 0;
  77. return __delayacct_add_tsk(d, tsk);
  78. }
  79. static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
  80. {
  81. if (tsk->delays)
  82. return __delayacct_blkio_ticks(tsk);
  83. return 0;
  84. }
  85. #else
  86. static inline void delayacct_set_flag(int flag)
  87. {}
  88. static inline void delayacct_clear_flag(int flag)
  89. {}
  90. static inline void delayacct_init(void)
  91. {}
  92. static inline void delayacct_tsk_init(struct task_struct *tsk)
  93. {}
  94. static inline void delayacct_tsk_free(struct task_struct *tsk)
  95. {}
  96. static inline void delayacct_blkio_start(void)
  97. {}
  98. static inline void delayacct_blkio_end(void)
  99. {}
  100. static inline int delayacct_add_tsk(struct taskstats *d,
  101. struct task_struct *tsk)
  102. { return 0; }
  103. static inline __u64 delayacct_blkio_ticks(struct task_struct *tsk)
  104. { return 0; }
  105. #endif /* CONFIG_TASK_DELAY_ACCT */
  106. #endif