Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 0. 简介
  • 1. 编译linux kernel
  • 2. 启动linux kernel
  • 3. 例子

Was this helpful?

  1. lock_and_lockup_detector

hung_task

0. 简介

The hung task which are bugs that cause the task to be stuck in uninterruptible "D" state indefinitely.

1. 编译linux kernel

打开Hung Tasks detector

## based on linux 5.4 version
$ make x86_64_defconfig
$ make menuconfig
Kernel hacking  --->
    Debug Lockups and Hangs  --->
        [*] Detect Hung Tasks ## CONFIG_DETECT_HUNG_TASK
            (120) Default timeout for hung task detection (in seconds)
            [*]   Panic (Reboot) On Hung Tasks
$ make

2. 启动linux kernel

查看Hung Tasks相关属性

$ cd /proc/sys/kernel/
$ grep . hung*
hung_task_check_count:4194304   ## 检查次数
hung_task_check_interval_secs:0 ## 每隔多长时间检查一次
hung_task_panic:1               ## 当出现hung tasks后, 打印stack信息,同时是否触发panic
hung_task_timeout_secs:120      ## hung tasks后的超时时间
hung_task_warnings:10           ## 警告的次数

3. 例子

## 打上测试hung task的补丁
$ git am 0001-test-hung-task.patch
$ make

加载模块

$ insmod hung_task.ko &
....
$ 
$ [  247.476952] INFO: task insmod:170 blocked for more than 122 seconds.
[  247.480509]       Not tainted 5.4.0 #6
[  247.480635] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[  247.480941] insmod          D14080   170    164 0x80000000
[  247.481363] Call Trace:
[  247.482336]  ? __schedule+0x272/0x5a0
[  247.482586]  ? 0xffffffffc00a1000
[  247.482656]  schedule+0x2a/0x90
[  247.482875]  hungtask_init+0x5/0x1000 [test]
[  247.482996]  do_one_initcall+0x41/0x1df
[  247.483069]  ? _cond_resched+0x10/0x40
[  247.483196]  ? kmem_cache_alloc_trace+0x36/0x1b0
[  247.483403]  do_init_module+0x56/0x1ee
[  247.483501]  load_module+0x1f84/0x2660
[  247.483648]  ? vfs_read+0x10e/0x130
[  247.483728]  ? __do_sys_finit_module+0xba/0xe0
[  247.483811]  __do_sys_finit_module+0xba/0xe0
[  247.483924]  do_syscall_64+0x43/0x120
[  247.484028]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[  247.484338] RIP: 0033:0x7fca40a59839
[  247.484688] Code: Bad RIP value.
[  247.484799] RSP: 002b:00007ffdd61810a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
[  247.485003] RAX: ffffffffffffffda RBX: 000000000000005f RCX: 00007fca40a59839
[  247.485224] RDX: 0000000000000000 RSI: 0000558072398260 RDI: 0000000000000003
[  247.485405] RBP: 0000558072398260 R08: 0000000000000000 R09: 00007fca4094f9d0
[  247.485586] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003
[  247.485755] R13: 00007ffdd6182f49 R14: 0000000000000000 R15: 0000000000000000
[  247.486050] NMI backtrace for cpu 0
[  247.486262] CPU: 0 PID: 16 Comm: khungtaskd Not tainted 5.4.0 #6
[  247.486438] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
[  247.486658] Call Trace:
[  247.486758]  dump_stack+0x50/0x6b
[  247.486850]  nmi_cpu_backtrace+0x89/0x90
[  247.486946]  ? lapic_can_unplug_cpu+0x90/0x90
[  247.487048]  nmi_trigger_cpumask_backtrace+0x82/0xc0
[  247.487190]  watchdog+0x264/0x3b0
[  247.487282]  ? hungtask_pm_notify+0x40/0x40
[  247.487392]  kthread+0x10e/0x130
[  247.487489]  ? kthread_park+0x80/0x80
[  247.487585]  ret_from_fork+0x22/0x40
[  247.487911] Kernel panic - not syncing: hung_task: blocked tasks
[  247.488134] CPU: 0 PID: 16 Comm: khungtaskd Not tainted 5.4.0 #6
[  247.488269] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
[  247.488466] Call Trace:
[  247.488535]  dump_stack+0x50/0x6b
[  247.488622]  panic+0xf3/0x2b8
[  247.488707]  ? ret_from_fork+0x1a/0x40
[  247.488805]  watchdog+0x270/0x3b0
[  247.488895]  ? hungtask_pm_notify+0x40/0x40
[  247.488995]  kthread+0x10e/0x130
[  247.489074]  ? kthread_park+0x80/0x80
[  247.489179]  ret_from_fork+0x22/0x40
[  247.489559] Kernel Offset: 0xce00000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffb                                                                                                                        fffffff)
[  247.489981] ---[ end Kernel panic - not syncing: hung_task: blocked tasks ]---

通过分析panic stack,可知 哪一行内核源码出现hung task.

或者

$ ps -eLf r             ## 查看r状态和D状态的进程
$ cat /proc/<pid>/stack ## 查看D状态的进程 内核stack,可知 哪一行内核源码出现hung task
Previousgeneral_lockNextsoftLockup_hardLockup

Last updated 4 years ago

Was this helpful?

添加

hung task的模拟代码