21 June 2011

Hang a linux box with relatime process?

A runnable SCHED_FIFO task continues to run until it blocks or explicitly yields the processor; it has no timeslice and can run indefinitely.
A SCHED_RR is identical to SCHED_FIFO except that each process can run only until it exhausts a predetermined timeslice.

/proc/sys/kernel/sched_rt_runtime_us: A global limit on how much time realtime scheduling may use.

Since 2.6.25 kernel, the default values for sched_rt_period_us (1000000 or 1s) and sched_rt_runtime_us (950000 or 0.95s). This gives 0.05s to be used by SCHED_OTHER (non-RT tasks). In other words, the group scheduler is configured, by default, to reserve 5% of the CPU for non-SCHED_FIFO tasks.

Download testrt.c
root permission is required to execute this!!!

# gcc -o testrt testrt.c -lrt -Wall
# ./testrt
using realtime, priority: 20

# echo 1000000 > /proc/sys/kernel/sched_rt_runtime_us

system is hang!!!
Download simple-module.c
Download Makefile.mod
# mv Makefile.mod Makefile
# make
# insmod ./simple-module.ko

# cat /proc/getprio
==> [120:120:120:0] [1000] [0x00402100] systemd [1][0]
==> [120:120:120:0] [1000] [0x8020A040] kthreadd [2][0]
==> [120:120:120:0] [1000] [0x8420A040] ksoftirqd/0 [3][2]
==> [120:120:120:0] [1000] [0x8420A060] kworker/u:0 [5][2]
==> [100:100:100:0] [1000] [0x8420A040] khelper [6][2]
==> [120:120:120:0] [1000] [0x8020A040] sync_supers [95][2]
==> [120:120:120:0] [1000] [0x80A0A040] bdi-default [97][2]
==> [100:100:100:0] [1000] [0x8420A040] kblockd [99][2]
==> [100:100:100:0] [1000] [0x8420A040] ata_sff [255][2]
==> [100:100:100:0] [1000] [0x8420A040] md [261][2]
==> [120:120:120:0] [1000] [0x8420A060] kworker/0:1 [359][2]
==> [120:120:120:0] [1000] [0x80A4A840] kswapd0 [370][2]
...
==> [79:120:79:20] [1000] [0x00400100] testrt [3264][2463]
...

Reference:
http://lwn.net/Articles/296419/
http://book.chinaunix.net/special/ebook/Linux_Kernel_Development/0672327201/ch04lev1sec4.html
http://www.kernel.org/doc/Documentation/scheduler/sched-rt-group.txt
https://rt.wiki.kernel.org/index.php/Squarewave-example

No comments:

Post a Comment