温暖的电波  

前言

Linux中实现了不少接口来将调度相关的数据提供给用户;用户通过读取这些数据可对系统调度运行情况有更加客观的认知。这些接口有系统级别的,也有任务级别的;下面对其做一个简单的汇总。

一、系统级别

1.1 /proc/stat

条目 usr nice system idle iowait irq softirq steal guest gest_nice
cpu 各个CPU上nice值不大于0的用户态任务的运行时间总和 各个CPU上nice值大于0的用户态任务的运行时间总和 各个CPU上内核态的运行时间总和,不包括(中断/软中断的时间)。

各个CPU上的idle时间总和(不包括IO阻塞导致的CPU idle时间)

各个CPU上由于任务IO阻塞导致CPU无可运行任务、处于idle的时间总和 各个CPU在中断处理中消耗的时间总和 各个CPU处理软中断的时间总和(包括softirqd) 各个CPU对应的vcpu被抢占的时间总和    

cpu0

~

cpuN

cpuX上nice值不大于0的用户态任务的运行时间 cpuX上nice值大于0的用户态任务的运行时间 cpuX上内核态的运行时间,不包括(中断/软中断的时间)。 cpuX上处于idle的时间(不包括IO阻塞导致的CPU idle时间) cpuX上由于任务IO阻塞导致CPU无可运行任务、处于idle的时间 cpuX在中断处理中消耗的时间 cpuX处理软中断的时间 cpuX对应的vcpu被抢占的时间    
intr 各个中断的产生次数,中断号依次递增,与/proc/interrupts中的中断号依次对应;如果是percpu中断,则各个cpu进行累加求和。
ctxt 系统中各个cpu上任务切换的次数总和
btime 从Epoch(即1970零时)开始到系统启动所经过的时长,单位秒
processes

系统启动以来成功fork()的次数

procs_running 系统中各个CPU上处于就绪/运行状态任务的数量总和
procs_blocked 系统中各个CPU上处于iowait状态任务的数量总和
softirq 各个软中断产生次数总和,软中断号依次递增,与/proc/softirqs一一对应

注:上面的irq时间依赖于CONFIG_IRQ_TIME_ACCOUNTING=y选项,否则该列值为0

1.2 /proc/schedstat

1.2.1 输出如下

cat /proc/schedstat
version 15
timestamp 4310296723
cpu0 0 0 0 0 0 0 504607169912 36216902814 1022719
domain0 00000000,00000000,00000000,0000000f 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
cpu1 0 0 0 0 0 0 499897796316 40485320002 1060195
domain0 00000000,00000000,00000000,0000000f 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
cpu2 0 0 0 0 0 0 542428937445 33304860254 1048057
domain0 00000000,00000000,00000000,0000000f 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
cpu3 0 0 0 0 0 0 488882907681 40532971039 1203926
domain0 00000000,00000000,00000000,0000000f 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1.2.2 结果说明

行1:版本号

行2:时间戳

接下来的信息是各个cpu相关信息,每个cpu可能占据多行,但是一般分为两类:一类是该cpu就绪队列信息,另一类是schedule domain相关参数

信息分类 各列说明
cpuN cpu号, rq->yld_count, 0, rq->sched_count, rq->sched_goidle, rq->ttwu_count, rq->ttwu_local, rq->rq_cpu_time, rq->rq_sched_info.run_delay, rq->rq_sched_info.pcount 
domain0  domain-specific stats不一一列出
......  
domainX  

 

1.3 /proc/sched_debug

todo

二、任务级别

2.1 /proc/pid/status

todo

2.2 /proc/pid/stat

todo

2.3 /proc/pid/sched

todo

2.4 /proc/pid/schedstat

2.4.1 接口依赖

(1)CONFIG_SCHED_INFO=y,否则没有此接口

(2)CONFIG_SCHEDSTATS=y || (CONFIG_TASK_DELAY_ACCT=y && delayacct_on=1) , 否则该接口的输出全0。

 delayacct_on是一个全局变量,默认情况为1;但是如果传递了nodelayacct内核参数则delayacct_on为0.

2.4.2 输出结果

结果输出形式:

$ cat /proc/$$/schedstat
301297002 53907222 203

结果输出的说明:

条目 列1 列2 列3
来源 task->se.sum_exec_runtime task->sched_info.run_delay task->sched_info.pcount
说明 任务的运行时间     任务被强占的时间   任务被强占次数
posted on 2023-08-23 17:31  温暖的电波  阅读(60)  评论(0编辑  收藏  举报