Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_KERNEL_STAT_H |
2 | #define _LINUX_KERNEL_STAT_H | |
3 | ||
1da177e4 LT |
4 | #include <linux/smp.h> |
5 | #include <linux/threads.h> | |
6 | #include <linux/percpu.h> | |
28ef3584 | 7 | #include <linux/cpumask.h> |
aa0ce5bb | 8 | #include <linux/interrupt.h> |
3292beb3 | 9 | #include <linux/sched.h> |
dcbf832e | 10 | #include <linux/vtime.h> |
6859a840 | 11 | #include <asm/irq.h> |
1da177e4 LT |
12 | |
13 | /* | |
14 | * 'kernel_stat.h' contains the definitions needed for doing | |
15 | * some kernel statistics (CPU usage, context switches ...), | |
16 | * used by rstatd/perfmeter | |
17 | */ | |
18 | ||
3292beb3 GC |
19 | enum cpu_usage_stat { |
20 | CPUTIME_USER, | |
21 | CPUTIME_NICE, | |
22 | CPUTIME_SYSTEM, | |
23 | CPUTIME_SOFTIRQ, | |
24 | CPUTIME_IRQ, | |
25 | CPUTIME_IDLE, | |
26 | CPUTIME_IOWAIT, | |
27 | CPUTIME_STEAL, | |
28 | CPUTIME_GUEST, | |
29 | CPUTIME_GUEST_NICE, | |
30 | NR_STATS, | |
31 | }; | |
32 | ||
33 | struct kernel_cpustat { | |
34 | u64 cpustat[NR_STATS]; | |
1da177e4 LT |
35 | }; |
36 | ||
37 | struct kernel_stat { | |
f2c66cd8 | 38 | unsigned long irqs_sum; |
aa0ce5bb | 39 | unsigned int softirqs[NR_SOFTIRQS]; |
1da177e4 LT |
40 | }; |
41 | ||
42 | DECLARE_PER_CPU(struct kernel_stat, kstat); | |
3292beb3 | 43 | DECLARE_PER_CPU(struct kernel_cpustat, kernel_cpustat); |
1da177e4 | 44 | |
1da177e4 | 45 | /* Must have preemption disabled for this to be meaningful. */ |
4a32fea9 CL |
46 | #define kstat_this_cpu this_cpu_ptr(&kstat) |
47 | #define kcpustat_this_cpu this_cpu_ptr(&kernel_cpustat) | |
3292beb3 GC |
48 | #define kstat_cpu(cpu) per_cpu(kstat, cpu) |
49 | #define kcpustat_cpu(cpu) per_cpu(kernel_cpustat, cpu) | |
1da177e4 LT |
50 | |
51 | extern unsigned long long nr_context_switches(void); | |
52 | ||
0b8f1efa | 53 | extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu); |
792d0018 | 54 | extern void kstat_incr_irq_this_cpu(unsigned int irq); |
d52a61c0 | 55 | |
aa0ce5bb KK |
56 | static inline void kstat_incr_softirqs_this_cpu(unsigned int irq) |
57 | { | |
6c9ae009 | 58 | __this_cpu_inc(kstat.softirqs[irq]); |
aa0ce5bb KK |
59 | } |
60 | ||
61 | static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu) | |
62 | { | |
63 | return kstat_cpu(cpu).softirqs[irq]; | |
64 | } | |
65 | ||
1da177e4 LT |
66 | /* |
67 | * Number of interrupts per specific IRQ source, since bootup | |
68 | */ | |
478735e3 | 69 | extern unsigned int kstat_irqs(unsigned int irq); |
c291ee62 | 70 | extern unsigned int kstat_irqs_usr(unsigned int irq); |
1da177e4 | 71 | |
f2c66cd8 KH |
72 | /* |
73 | * Number of interrupts per cpu, since bootup | |
74 | */ | |
75 | static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu) | |
76 | { | |
77 | return kstat_cpu(cpu).irqs_sum; | |
78 | } | |
aa9c4c0f | 79 | |
23244a5c | 80 | extern void account_user_time(struct task_struct *, u64); |
fb8b049c FW |
81 | extern void account_guest_time(struct task_struct *, u64); |
82 | extern void account_system_time(struct task_struct *, int, u64); | |
83 | extern void account_system_index_time(struct task_struct *, u64, | |
c31cc6a5 | 84 | enum cpu_usage_stat); |
be9095ed | 85 | extern void account_steal_time(u64); |
18b43a9b | 86 | extern void account_idle_time(u64); |
79741dd3 | 87 | |
abf917cd | 88 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE |
bcebdf84 FW |
89 | static inline void account_process_tick(struct task_struct *tsk, int user) |
90 | { | |
c8d7dabf | 91 | vtime_flush(tsk); |
bcebdf84 FW |
92 | } |
93 | #else | |
79741dd3 | 94 | extern void account_process_tick(struct task_struct *, int user); |
bcebdf84 FW |
95 | #endif |
96 | ||
79741dd3 | 97 | extern void account_idle_ticks(unsigned long ticks); |
1da177e4 LT |
98 | |
99 | #endif /* _LINUX_KERNEL_STAT_H */ |