kernel_stat.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_SPARSE_IRQ
  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_SPARSE_IRQ
  37. #define kstat_irqs_this_cpu(irq) \
  38. (kstat_this_cpu.irqs[irq])
  39. struct irq_desc;
  40. static inline void kstat_incr_irqs_this_cpu(unsigned int irq,
  41. struct irq_desc *desc)
  42. {
  43. kstat_this_cpu.irqs[irq]++;
  44. }
  45. #endif
  46. #ifndef CONFIG_SPARSE_IRQ
  47. static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
  48. {
  49. return kstat_cpu(cpu).irqs[irq];
  50. }
  51. #else
  52. extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu);
  53. #endif
  54. /*
  55. * Number of interrupts per specific IRQ source, since bootup
  56. */
  57. static inline unsigned int kstat_irqs(unsigned int irq)
  58. {
  59. unsigned int sum = 0;
  60. int cpu;
  61. for_each_possible_cpu(cpu)
  62. sum += kstat_irqs_cpu(irq, cpu);
  63. return sum;
  64. }
  65. extern unsigned long long task_delta_exec(struct task_struct *);
  66. extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
  67. extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
  68. extern void account_steal_time(struct task_struct *, cputime_t);
  69. #endif /* _LINUX_KERNEL_STAT_H */