一、使能 CONFIG_SCHED_DEBUG 提供的文件
1. /proc/pid/sched 文件
cat显示统计数据,echo清0,无论echo的是啥。
2. /proc/sys/kernel 下的
sched_min_granularity_ns
sched_latency_ns
sched_sync_hint_enable
sched_cstate_aware
sched_wakeup_granularity_ns
sched_tunable_scaling
sched_migration_cost_ns
sched_nr_migrate
sched_time_avg_ms
sched_schedstats
//若使能 CONFIG_IO_SCHED_OPTIMIZE 还有:
io_sched_optimize
//若使能 CONFIG_NUMA_BALANCING 还有:
numa_balancing_scan_delay_ms
numa_balancing_scan_period_min_ms
numa_balancing_scan_period_max_ms
numa_balancing_scan_size_mb
numa_balancing
3. /proc/sched_debug 文件
二、提供启动参数 sched_debug
1. 作用
static int __init sched_debug_setup(char *str) //topology.c { sched_debug_enabled = true; return 0; } early_param("sched_debug", sched_debug_setup); //topology.c sched_init_domains //topology.c partition_sched_domains //topology.c build_sched_domains cpu_attach_domain //sched/topology.c sched_domain_debug //sched/topology.c if (sched_debug_enabled) { printk(KERN_DEBUG "CPU%d attaching sched-domain(s):\n", cpu); for (;;) { if (sched_domain_debug_one(sd, cpu, level, sched_domains_tmpmask)) break; level++; sd = sd->parent; if (!sd) break; } }
三、代码分析
1. 使能后编译住sched/debug.c
msm-4.14/kernel/sched$ cat Makefile
obj-$(CONFIG_SCHED_DEBUG) += debug.o //代码编译上会编译住debug.c
2. deadlne.c中的使用
/proc/sched_debug sched_debug_show //sched/debug.c print_cpu //sched/debug.c print_dl_stats(*m, cpu) //deadline.c print_dl_rq(*m, cpu, *dl_rq)//sched/debug.c
3. sched/core.c 中的使用
sysrq_sched_debug_show() //sched/core.c //调用路径: echo t > /proc/sysrq-trigger sysrq_showstate_op.handler //"show-task-states(t)" 对应的handler回调 sysrq_handle_showstate //sysrq.c fn_show_state //tty/vt/keyboard.c show_state() //sched/debug.h 传参0 sysrq_handle_showstate_blocked //sysrq.c 传参 TASK_UNINTERRUPTIBLE=2,无效 show_state_filter(ustate_filter) //sched/core.c 参数为0才执行 sysrq_sched_debug_show //sched/debug.c 使能 CONFIG_SCHED_DEBUG 才存在 for_each_online_cpu(cpu) print_cpu(NULL, cpu);
echo t > /proc/sysrq-trigger 会触发打印每一个进程的内核栈,如下:
[ 565.347148] (7)[7110:sh]fxp.monlolo S 0 838 1073 4078 623 0x00000000 [ 565.347155] (7)[7110:sh]Call trace: [ 565.347159] (7)[7110:sh] __switch_to+0x118/0x134 [ 565.347161] (7)[7110:sh] __schedule+0x7c0/0xa78 [ 565.347167] (7)[7110:sh] schedule+0x70/0x90 [ 565.347172] (7)[7110:sh] schedule_hrtimeout_range_clock+0xc0/0xe8 [ 565.347174] (7)[7110:sh] schedule_hrtimeout_range+0x10/0x18 [ 565.347180] (7)[7110:sh] SyS_epoll_wait+0x2ac/0x3c4 [ 565.347184] (7)[7110:sh] SyS_epoll_pwait+0x108/0x168 [ 565.347186] (7)[7110:sh] el0_svc_naked+0x34/0x38
若正在运行,会多打印出"running task",打印如下:
[ 565.299661] (4)[7110:sh]UnityMain R running task 0 32556 28 3430 623 0x00000000 [ 565.299664] (4)[7110:sh]Call trace: [ 565.299667] (4)[7110:sh] __switch_to+0x118/0x134 [ 565.299670] (4)[7110:sh] __schedule+0x7c0/0xa78 [ 565.299672] (4)[7110:sh] schedule+0x70/0x90 [ 565.299675] (4)[7110:sh] futex_wait_queue_me+0xbc/0x108 [ 565.299678] (4)[7110:sh] futex_wait+0x104/0x2d0 [ 565.299681] (4)[7110:sh] do_futex+0x114/0x18e4 [ 565.299684] (4)[7110:sh] SyS_futex+0x140/0x1ac [ 565.299687] (4)[7110:sh] el0_svc_naked+0x34/0x38
第一行各字段分别为:p->comm, task_state_to_char(p), "running task"(正在runing的有,sleep的无),0, p->nvcsw, p->nivcsw, p->pid, p->real_parent->pid, task_thread_info(p)->flags
# ps -e| grep fxp.monlolo USER PID PPID VSZ RSS WCHAN ADDR S NAME system 4078 623 7980716 237860 SyS_epoll_wait 0 S com.fxp.monlolo
3. rt.c中的使用
print_rt_stats //rt.c //调用路径: print_cpu //sched/debug.c 同上 print_rt_stats(*m, cpu) //rt.c
四、补充
1. 上面说到了打印内核栈,这里增量两个打印每CPU调用栈和进程用户栈的方法
# echo l > /proc/sysrq-trigger 打印每个CPU当前调用栈
thaw-filesystems(j) show-backtrace-all-active-cpus(l) show-task-states(t) show-blocked-tasks(w)
# debuggerd -b <pid> 打印pid进程所有线程的用户栈
标签:SCHED,show,sched,sh,debug,7110,DEBUG,59,cpu From: https://www.cnblogs.com/hellokitty2/p/17723544.html