kernel_stat.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef _LINUX_KERNEL_STAT_H
  2. #define _LINUX_KERNEL_STAT_H
  3. #include <linux/smp.h>
  4. #include <linux/threads.h>
  5. #include <linux/percpu.h>
  6. #include <linux/cpumask.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/sched.h>
  9. #include <linux/vtime.h>
  10. #include <asm/irq.h>
  11. #include <asm/cputime.h>
  12. /*
  13. * 'kernel_stat.h' contains the definitions needed for doing
  14. * some kernel statistics (CPU usage, context switches ...),
  15. * used by rstatd/perfmeter
  16. */
  17. enum cpu_usage_stat {
  18. CPUTIME_USER,
  19. CPUTIME_NICE,
  20. CPUTIME_SYSTEM,
  21. CPUTIME_SOFTIRQ,
  22. CPUTIME_IRQ,
  23. CPUTIME_IDLE,
  24. CPUTIME_IOWAIT,
  25. CPUTIME_STEAL,
  26. CPUTIME_GUEST,
  27. CPUTIME_GUEST_NICE,
  28. NR_STATS,
  29. };
  30. struct kernel_cpustat {
  31. u64 cpustat[NR_STATS];
  32. };
  33. struct kernel_stat {
  34. #ifndef CONFIG_GENERIC_HARDIRQS
  35. unsigned int irqs[NR_IRQS];
  36. #endif
  37. unsigned long irqs_sum;
  38. unsigned int softirqs[NR_SOFTIRQS];
  39. };
  40. DECLARE_PER_CPU(struct kernel_stat, kstat);
  41. DECLARE_PER_CPU(struct kernel_cpustat, kernel_cpustat);
  42. /* Must have preemption disabled for this to be meaningful. */
  43. #define kstat_this_cpu (&__get_cpu_var(kstat))
  44. #define kcpustat_this_cpu (&__get_cpu_var(kernel_cpustat))
  45. #define kstat_cpu(cpu) per_cpu(kstat, cpu)
  46. #define kcpustat_cpu(cpu) per_cpu(kernel_cpustat, cpu)
  47. extern unsigned long long nr_context_switches(void);
  48. #ifndef CONFIG_GENERIC_HARDIRQS
  49. struct irq_desc;
  50. static inline void kstat_incr_irqs_this_cpu(unsigned int irq,
  51. struct irq_desc *desc)
  52. {
  53. __this_cpu_inc(kstat.irqs[irq]);
  54. __this_cpu_inc(kstat.irqs_sum);
  55. }
  56. static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
  57. {
  58. return kstat_cpu(cpu).irqs[irq];
  59. }
  60. #else
  61. #include <linux/irq.h>
  62. extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu);
  63. #define kstat_incr_irqs_this_cpu(irqno, DESC) \
  64. do { \
  65. __this_cpu_inc(*(DESC)->kstat_irqs); \
  66. __this_cpu_inc(kstat.irqs_sum); \
  67. } while (0)
  68. #endif
  69. static inline void kstat_incr_softirqs_this_cpu(unsigned int irq)
  70. {
  71. __this_cpu_inc(kstat.softirqs[irq]);
  72. }
  73. static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu)
  74. {
  75. return kstat_cpu(cpu).softirqs[irq];
  76. }
  77. /*
  78. * Number of interrupts per specific IRQ source, since bootup
  79. */
  80. #ifndef CONFIG_GENERIC_HARDIRQS
  81. static inline unsigned int kstat_irqs(unsigned int irq)
  82. {
  83. unsigned int sum = 0;
  84. int cpu;
  85. for_each_possible_cpu(cpu)
  86. sum += kstat_irqs_cpu(irq, cpu);
  87. return sum;
  88. }
  89. #else
  90. extern unsigned int kstat_irqs(unsigned int irq);
  91. #endif
  92. /*
  93. * Number of interrupts per cpu, since bootup
  94. */
  95. static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
  96. {
  97. return kstat_cpu(cpu).irqs_sum;
  98. }
  99. /*
  100. * Lock/unlock the current runqueue - to extract task statistics:
  101. */
  102. extern unsigned long long task_delta_exec(struct task_struct *);
  103. extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
  104. extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
  105. extern void account_steal_time(cputime_t);
  106. extern void account_idle_time(cputime_t);
  107. #ifdef CONFIG_VIRT_CPU_ACCOUNTING
  108. static inline void account_process_tick(struct task_struct *tsk, int user)
  109. {
  110. vtime_account_user(tsk);
  111. }
  112. #else
  113. extern void account_process_tick(struct task_struct *, int user);
  114. #endif
  115. extern void account_steal_ticks(unsigned long ticks);
  116. extern void account_idle_ticks(unsigned long ticks);
  117. #endif /* _LINUX_KERNEL_STAT_H */