例子:
[86:khungtaskd]Task SettingsProvide:4139 blocked for 120s is causing panic
[86:khungtaskd]Kernel panic - not syncing: hungtask: blocked tasks
__switch_to+0x304
__schedule+0x51c
schedule+0xb0
wait_on_page_bit_common+0x310 //这里等待IO页面操作
wait_on_page_writeback+0xb4
__filemap_fdatawait_range+0x130
f2fs_do_sync_file+0x204
f2fs_sync_file+0x30
查看UFS相关的进程调用栈,可以看到是在等clk_unprepare的锁:
hungtask:name=kworker/u16:2,PID=10357,tgid=11286,tgname=kworker/u16:2,type=8,blocked for 122s,
task:kworker/u16:2 state:D stack: 0 pid:11286 ppid: 2 flags:0x00000008
Workqueue: ufs_clk_gating_0 ufshcd_gate_work.cfi_jt
Call trace:
__switch_to+0x304/0x434
__schedule+0x51c/0x8e4
schedule+0xb0/0x1e4
__mutex_lock+0x630/0xc90
clk_unprepare+0xa0/0x17c
ufs_qcom_phy_disable_ref_clk+0x38/0xac [phy_qcom_ufs]
ufs_qcom_phy_power_off+0x90/0x1c0 [phy_qcom_ufs]
查看持锁进程:两种方法:
1、通过Trace32直接看counter的值0xFFFFFF8265381C37,对应的进程就是0xFFFFFF8265381C30
2、通过log的调用栈中的信息:搜索clk_unprepare,可以看到只有一个是0xc0的指令处
查看调用栈:
Process: kworker/0:0, [affinity: 0x1] cpu: 0 pid: 13047 start: 0xffffff8265381c30
=====================================================
Stack:
__switch_to+0x304
__schedule+0x51c
schedule+0xb0
schedule_hrtimeout_range_clock+0x198
usleep_range+0x6c //这里sleep
spf_core_is_apm_ready[spf_core_dlkm]+0x7c
prm_gpr_send_pkt[audio_prm_dlkm]+0x228
audio_prm_set_lpass_hw_core_req[audio_prm_dlkm]+0x90
lpass_hw_vote_prepare[wcd9xxx_dlkm]+0x68
clk_core_prepare+0x154
clk_prepare+0xc0 //这里持锁
digital_cdc_rsc_mgr_hw_vote_enable[spf_core_dlkm]+0x40
持锁之后,再调sleep就会导致锁无法释放,很容易死锁。