Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_KERNEL_STAT_H
0003 #define _LINUX_KERNEL_STAT_H
0004 
0005 #include <linux/smp.h>
0006 #include <linux/threads.h>
0007 #include <linux/percpu.h>
0008 #include <linux/cpumask.h>
0009 #include <linux/interrupt.h>
0010 #include <linux/sched.h>
0011 #include <linux/vtime.h>
0012 #include <asm/irq.h>
0013 
0014 /*
0015  * 'kernel_stat.h' contains the definitions needed for doing
0016  * some kernel statistics (CPU usage, context switches ...),
0017  * used by rstatd/perfmeter
0018  */
0019 
0020 enum cpu_usage_stat {
0021     CPUTIME_USER,
0022     CPUTIME_NICE,
0023     CPUTIME_SYSTEM,
0024     CPUTIME_SOFTIRQ,
0025     CPUTIME_IRQ,
0026     CPUTIME_IDLE,
0027     CPUTIME_IOWAIT,
0028     CPUTIME_STEAL,
0029     CPUTIME_GUEST,
0030     CPUTIME_GUEST_NICE,
0031 #ifdef CONFIG_SCHED_CORE
0032     CPUTIME_FORCEIDLE,
0033 #endif
0034     NR_STATS,
0035 };
0036 
0037 struct kernel_cpustat {
0038     u64 cpustat[NR_STATS];
0039 };
0040 
0041 struct kernel_stat {
0042     unsigned long irqs_sum;
0043     unsigned int softirqs[NR_SOFTIRQS];
0044 };
0045 
0046 DECLARE_PER_CPU(struct kernel_stat, kstat);
0047 DECLARE_PER_CPU(struct kernel_cpustat, kernel_cpustat);
0048 
0049 /* Must have preemption disabled for this to be meaningful. */
0050 #define kstat_this_cpu this_cpu_ptr(&kstat)
0051 #define kcpustat_this_cpu this_cpu_ptr(&kernel_cpustat)
0052 #define kstat_cpu(cpu) per_cpu(kstat, cpu)
0053 #define kcpustat_cpu(cpu) per_cpu(kernel_cpustat, cpu)
0054 
0055 extern unsigned long long nr_context_switches(void);
0056 
0057 extern unsigned int kstat_irqs_cpu(unsigned int irq, int cpu);
0058 extern void kstat_incr_irq_this_cpu(unsigned int irq);
0059 
0060 static inline void kstat_incr_softirqs_this_cpu(unsigned int irq)
0061 {
0062     __this_cpu_inc(kstat.softirqs[irq]);
0063 }
0064 
0065 static inline unsigned int kstat_softirqs_cpu(unsigned int irq, int cpu)
0066 {
0067        return kstat_cpu(cpu).softirqs[irq];
0068 }
0069 
0070 /*
0071  * Number of interrupts per specific IRQ source, since bootup
0072  */
0073 extern unsigned int kstat_irqs_usr(unsigned int irq);
0074 
0075 /*
0076  * Number of interrupts per cpu, since bootup
0077  */
0078 static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
0079 {
0080     return kstat_cpu(cpu).irqs_sum;
0081 }
0082 
0083 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
0084 extern u64 kcpustat_field(struct kernel_cpustat *kcpustat,
0085               enum cpu_usage_stat usage, int cpu);
0086 extern void kcpustat_cpu_fetch(struct kernel_cpustat *dst, int cpu);
0087 #else
0088 static inline u64 kcpustat_field(struct kernel_cpustat *kcpustat,
0089                  enum cpu_usage_stat usage, int cpu)
0090 {
0091     return kcpustat->cpustat[usage];
0092 }
0093 
0094 static inline void kcpustat_cpu_fetch(struct kernel_cpustat *dst, int cpu)
0095 {
0096     *dst = kcpustat_cpu(cpu);
0097 }
0098 
0099 #endif
0100 
0101 extern void account_user_time(struct task_struct *, u64);
0102 extern void account_guest_time(struct task_struct *, u64);
0103 extern void account_system_time(struct task_struct *, int, u64);
0104 extern void account_system_index_time(struct task_struct *, u64,
0105                       enum cpu_usage_stat);
0106 extern void account_steal_time(u64);
0107 extern void account_idle_time(u64);
0108 extern u64 get_idle_time(struct kernel_cpustat *kcs, int cpu);
0109 
0110 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
0111 static inline void account_process_tick(struct task_struct *tsk, int user)
0112 {
0113     vtime_flush(tsk);
0114 }
0115 #else
0116 extern void account_process_tick(struct task_struct *, int user);
0117 #endif
0118 
0119 extern void account_idle_ticks(unsigned long ticks);
0120 
0121 #ifdef CONFIG_SCHED_CORE
0122 extern void __account_forceidle_time(struct task_struct *tsk, u64 delta);
0123 #endif
0124 
0125 #endif /* _LINUX_KERNEL_STAT_H */