Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | #ifndef _LINUX_KERNEL_STAT_H |
| 2 | #define _LINUX_KERNEL_STAT_H |
| 3 | |
| 4 | #include <linux/smp.h> |
| 5 | #include <linux/threads.h> |
| 6 | #include <linux/percpu.h> |
| 7 | #include <linux/cpumask.h> |
| 8 | #include <linux/interrupt.h> |
| 9 | #include <linux/sched.h> |
| 10 | #include <asm/irq.h> |
| 11 | #include <asm/cputime.h> |
| 12 | |
| 13 | |
| 14 | enum cpu_usage_stat { |
| 15 | CPUTIME_USER, |
| 16 | CPUTIME_NICE, |
| 17 | CPUTIME_SYSTEM, |
| 18 | CPUTIME_SOFTIRQ, |
| 19 | CPUTIME_IRQ, |
| 20 | CPUTIME_IDLE, |
| 21 | CPUTIME_IOWAIT, |
| 22 | CPUTIME_STEAL, |
| 23 | CPUTIME_GUEST, |
| 24 | CPUTIME_GUEST_NICE, |
| 25 | NR_STATS, |
| 26 | }; |
| 27 | |
| 28 | struct kernel_cpustat { |
| 29 | u64 cpustat[NR_STATS]; |
| 30 | }; |
| 31 | |
| 32 | struct kernel_stat { |
| 33 | #ifndef CONFIG_GENERIC_HARDIRQS |
| 34 | unsigned int irqs[NR_IRQS]; |
| 35 | #endif |
| 36 | unsigned long irqs_sum; |
| 37 | unsigned int softirqs[NR_SOFTIRQS]; |
| 38 | }; |
| 39 | |
| 40 | DECLARE_PER_CPU(struct kernel_stat, kstat); |
| 41 | DECLARE_PER_CPU(struct kernel_cpustat, kernel_cpustat); |
| 42 | |
| 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 | |
| 48 | extern unsigned long long nr_context_switches(void); |
| 49 | |
| 50 | #ifndef CONFIG_GENERIC_HARDIRQS |
| 51 | |
| 52 | struct irq_desc; |
| 53 | |
| 54 | static inline void kstat_incr_irqs_this_cpu(unsigned int irq, |
| 55 | struct irq_desc *desc) |
| 56 | { |
| 57 | __this_cpu_inc(kstat.irqs[irq]); |
| 58 | __this_cpu_inc(kstat.irqs_sum); |
| 59 | } |
| 60 | |
| 61 | static inline unsigned int kstat_irqs_cpu(unsigned int irq, int cpu) |
| 62 | { |
| 63 | return kstat_cpu(cpu).irqs[irq]; |
| 64 | } |
| 65 | #else |
| 66 | #include <linux/irq.h> |
| 67 | extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu); |
| 68 | |
| 69 | #define kstat_incr_irqs_this_cpu(irqno, DESC) \ |
| 70 | do { \ |
| 71 | __this_cpu_inc(*(DESC)->kstat_irqs); \ |
| 72 | __this_cpu_inc(kstat.irqs_sum); \ |
| 73 | } while (0) |
| 74 | |
| 75 | #endif |
| 76 | |
| 77 | static inline void kstat_incr_softirqs_this_cpu(unsigned int irq) |
| 78 | { |
| 79 | __this_cpu_inc(kstat.softirqs[irq]); |
| 80 | } |
| 81 | |
| 82 | static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) |
| 83 | { |
| 84 | return kstat_cpu(cpu).softirqs[irq]; |
| 85 | } |
| 86 | |
| 87 | #ifndef CONFIG_GENERIC_HARDIRQS |
| 88 | static inline unsigned int kstat_irqs(unsigned int irq) |
| 89 | { |
| 90 | unsigned int sum = 0; |
| 91 | int cpu; |
| 92 | |
| 93 | for_each_possible_cpu(cpu) |
| 94 | sum += kstat_irqs_cpu(irq, cpu); |
| 95 | |
| 96 | return sum; |
| 97 | } |
| 98 | #else |
| 99 | extern unsigned int kstat_irqs(unsigned int irq); |
| 100 | #endif |
| 101 | |
| 102 | static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu) |
| 103 | { |
| 104 | return kstat_cpu(cpu).irqs_sum; |
| 105 | } |
| 106 | |
| 107 | extern unsigned long long task_delta_exec(struct task_struct *); |
| 108 | |
| 109 | extern void account_user_time(struct task_struct *, cputime_t, cputime_t); |
| 110 | extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t); |
| 111 | extern void account_steal_time(cputime_t); |
| 112 | extern void account_idle_time(cputime_t); |
| 113 | |
| 114 | extern void account_process_tick(struct task_struct *, int user); |
| 115 | extern void account_steal_ticks(unsigned long ticks); |
| 116 | extern void account_idle_ticks(unsigned long ticks); |
| 117 | |
| 118 | #endif |