alisysdelay is used to catch tasks hung in kernel mode and get its stack.

In kernel without CONFIG_PREEMPT enabled, scheduling latency sometimes
may be unacceptable, because some tasks may run too long in kernel mode
without calling cond_sched(). These tasks may be kernel thread, or user
processes that enter kernel mode by syscall.

alisysdelay can catch tasks that have been running continuously for a long time
whithout scheduling, and kernel/user stackes will be printed for these tasks.
The threshold can be user defined.

By default CPU idle stacks are excluded by simply excluding PID 0.



For example,

# alisysdelay -t 10
Sampling at 100 Hz frequency... Hit Ctrl-C to end.

    iowrite16
    iowrite16
    vp_notify
    virtqueue_notify
    start_xmit
    dev_hard_start_xmit
    sch_direct_xmit
    __qdisc_run
    __dev_queue_xmit
    ip_finish_output2
    ip_output
    __tcp_transmit_skb
    tcp_write_xmit
    __tcp_push_pending_frames
    tcp_sendmsg_locked
    tcp_sendmsg
    sock_sendmsg
    sock_write_iter
    __vfs_write
    vfs_write
    ksys_write
    do_syscall_64
    entry_SYSCALL_64_after_hwframe
    __write_nocancel
    -                sshd (4617)

In this case, sshd (PID 4617) is catched for staying in kernel mode
for more than 10us, without rescheduling.



USAGE message:
# alisysdelay -h
usage: alisysdelay.py [-h] [-f FREQUENCY] [-d] [-a] [-t THRESHOLD]
                   [--stack-storage-size STACK_STORAGE_SIZE]

Catch tasks hung in kernel mode and get its stack

optional arguments:
  -h, --help            show this help message and exit
  -f FREQUENCY, --frequency FREQUENCY
                        sample frequency in Hertz (default 100)
  -d, --delimited       insert delimiter between kernel/user stacks
  -a, --annotations     add _[k] annotations to kernel frames
  -t THRESHOLD, --threshold THRESHOLD
                        set the threshold of delay in kernel mode, in us
                        (default 50)
  --stack-storage-size STACK_STORAGE_SIZE
                        the number of unique stack traces that can be stored
                        and displayed (default 16384)

examples:
    ./alisysdelay             # catch tasks hung in kernel mode
    ./alisysdelay -f 99       # catch tasks hung in kernel mode at 99 Hertz
    ./alisysdelay -t 100      # catch tasks that hung in kernel mode for more than 100us
