kernel_stat.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. unsigned int irqs[NR_IRQS];
  28. };
  29. DECLARE_PER_CPU(struct kernel_stat, kstat);
  30. #define kstat_cpu(cpu) per_cpu(kstat, cpu)
  31. /* Must have preemption disabled for this to be meaningful. */
  32. #define kstat_this_cpu __get_cpu_var(kstat)
  33. extern unsigned long long nr_context_switches(void);
  34. struct irq_desc;
  35. static inline void kstat_incr_irqs_this_cpu(unsigned int irq,
  36. struct irq_desc *desc)
  37. {
  38. kstat_this_cpu.irqs[irq]++;
  39. }
  40. static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
  41. {
  42. return kstat_cpu(cpu).irqs[irq];
  43. }
  44. /*
  45. * Number of interrupts per specific IRQ source, since bootup
  46. */
  47. static inline unsigned int kstat_irqs(unsigned int irq)
  48. {
  49. unsigned int sum = 0;
  50. int cpu;
  51. for_each_possible_cpu(cpu)
  52. sum += kstat_irqs_cpu(irq, cpu);
  53. return sum;
  54. }
  55. extern void account_user_time(struct task_struct *, cputime_t);
  56. extern void account_user_time_scaled(struct task_struct *, cputime_t);
  57. extern void account_system_time(struct task_struct *, int, cputime_t);
  58. extern void account_system_time_scaled(struct task_struct *, cputime_t);
  59. extern void account_steal_time(struct task_struct *, cputime_t);
  60. #endif /* _LINUX_KERNEL_STAT_H */