kernel_stat.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <asm/irq.h>
  8. #include <asm/cputime.h>
  9. /*
  10. * 'kernel_stat.h' contains the definitions needed for doing
  11. * some kernel statistics (CPU usage, context switches ...),
  12. * used by rstatd/perfmeter
  13. */
  14. struct cpu_usage_stat {
  15. cputime64_t user;
  16. cputime64_t nice;
  17. cputime64_t system;
  18. cputime64_t softirq;
  19. cputime64_t irq;
  20. cputime64_t idle;
  21. cputime64_t iowait;
  22. cputime64_t steal;
  23. cputime64_t guest;
  24. };
  25. struct kernel_stat {
  26. struct cpu_usage_stat cpustat;
  27. #ifndef CONFIG_HAVE_DYN_ARRAY
  28. unsigned int irqs[NR_IRQS];
  29. #endif
  30. };
  31. DECLARE_PER_CPU(struct kernel_stat, kstat);
  32. #define kstat_cpu(cpu) per_cpu(kstat, cpu)
  33. /* Must have preemption disabled for this to be meaningful. */
  34. #define kstat_this_cpu __get_cpu_var(kstat)
  35. extern unsigned long long nr_context_switches(void);
  36. #ifndef CONFIG_HAVE_DYN_ARRAY
  37. #define kstat_irqs_this_cpu(irq) \
  38. (kstat_this_cpu.irqs[irq])
  39. #endif
  40. #ifndef CONFIG_HAVE_DYN_ARRAY
  41. static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
  42. {
  43. return kstat_cpu(cpu).irqs[irq];
  44. }
  45. #else
  46. extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu);
  47. #endif
  48. /*
  49. * Number of interrupts per specific IRQ source, since bootup
  50. */
  51. static inline unsigned int kstat_irqs(unsigned int irq)
  52. {
  53. unsigned int sum = 0;
  54. int cpu;
  55. for_each_possible_cpu(cpu)
  56. sum += kstat_irqs_cpu(irq, cpu);
  57. return sum;
  58. }
  59. extern void account_user_time(struct task_struct *, cputime_t);
  60. extern void account_user_time_scaled(struct task_struct *, cputime_t);
  61. extern void account_system_time(struct task_struct *, int, cputime_t);
  62. extern void account_system_time_scaled(struct task_struct *, cputime_t);
  63. extern void account_steal_time(struct task_struct *, cputime_t);
  64. #endif /* _LINUX_KERNEL_STAT_H */