On the compiling, using and testing of hard time Linux (Rt-preempt Patch) on PC

Source: Internet
Author: User
Tags inheritance min thread uuid

The problem of Vanilla kernel

Linux kernel cannot be preempted in spinlock, IRQ contexts, so the time that a high-priority task wakes up to execution cannot be completely determined. Also, the Linux kernel itself does not handle priority inversion. Rt-preempt Patch is based on the Linux community kernel, plus the associated patches to make Linux meet hard needs. This article describes the practice of the patch on the PC. Our test environment is Ubuntu 10.10, by default, the kernel with Ubuntu 10.10 is:

barry@barry-virtualbox:/lib/modules$ uname-a
2.6.35-32-generic #67-ubuntu SMP Mon Mar 5 19:35:26 UTC-i686 GNU/Li Nux

Install the RT Test Toolset in the Ubuntu 10.10,apt-get install rt-tests, run the Cyclictest test tool in it, and create the SCHED_FIFO thread of the 5 realtime policy by default, priority 76-80, the operating cycle is 1000,1500,2000,2500,3000 microseconds:

barry@barry-virtualbox:~/development/panda/android$ sudo cyclictest-p 80-t5-n 
[sudo] password for Barry: 
policy:fifo:loadavg:9.22 8.57 6.75 11/374 21385 t:0          
 
(20606) p:80 i:1000 C:  18973 Min:     Act:   avg:< c7/>428 Max:   12637
t:1 (20607) p:79 i:1500 C:  12648 Min:     Act:   Avg:  447 Max:   10320
t:2 (20608) p:78 i:2000 C:   9494 Min:     Act:  151 AVG: 383  Max:    9481 t:3
(20609 p:77 i:2500 C:   7589 Min: The     Act:  889 AVG:  393 Max: 12670 t:4 (20610) p:76 i:3000
C:   6325 Min:     notoginseng Act:  167 Avg:  553 Max:   13673

This shows that within Standard Linux, the jitter of RT threads is very unstable, with a minimum value of 26-37 microseconds, an average of 68-889 microseconds, and a maximum of 9481-13673 microseconds.

We still run this test, but in the process of running this test, we introduce more interference, such as MOUNT/DEV/SDB1 ~/development, the result becomes:

barry@barry-virtualbox:~$ sudo cyclictest-p 80-t5-n 
policy:fifo:loadavg:0.14 0.29 0.13 2/308 1908 t:0          
 
(187 4) p:80 i:1000 C:  28521 Min:      0 Act:  440 avg:2095 Max:  331482 t:1
(1875) p:79 i:1500 C:  19014 Mi N:      2 Act:  988 avg:2099 Max:  330503
t:2 (1876) p:78 i:2000 C:  14261 Min:      7 Act:  534 Av g:2096 Max:  329989
t:3 (1877) p:77 i:2500 C:  11409 Min:      4 Act:  554 avg:2073 Max:  328490< C22/>t:4 (1878) p:76 i:3000 C:   9507 Min: The     Act:  avg:2081 Max:  328991

IRQ, SOFTIRQ, and Spinlock introduced during the Mount lead to a significant increase in the maximum jitter or 331482us, fully demonstrating the unpredictability of the operating time of RT threads in the standard Linux kernel (hard-time requirements mean predictable).

If we compile a copy of Kernel, select "Voluntary Kernel preemption (Desktop)", which is similar to the 2.4 unsupported Kernel preemption situation, we run the same case, the uncertainty of time is almost unacceptable to us:

barry@barry-virtualbox:~$ sudo/usr/local/bin/cyclictest-p 80-t5-n
#/dev/cpu_dma_latency set to 0us
policy:f ifo:loadavg:0.23 0.30 0.15 3/247 5086 t:0           
 
(5082) p:80 i:1000 C:   5637 Min: act:15108679 avg:11195196     Max  : 15108679
t:1 (5083) p:80 i:1500 C:   5723 Min:, act:12364955 avg:6389691, max:12364955 t:2
(5084) p:80 i:2000 c:   4821 Min:     act:11119979 avg:8061814 max:11661123 t:3
(5085) p:80 i:2500 C:   3909 Min:
  27 act:11176854 avg:4563549 max:11176854
t:4 (5086) p:80 i:3000 C:   3598 Min:     notoginseng act:9951432 avg:876113 7 max:116026155

Rt-preempt Patch to enable

Rt-preempt Patch's main modifications to Linux kernel include:

Making In-kernel locking-primitives (using spinlocks) preemptible though with reimplementation:

Critical sections protected by i.e. spinlock_t and rwlock_t now are. The creation of non-preemptible sections (in kernel) are still possible with raw_spinlock_t (same APIs like spinlock_t)

Implementing priority inheritance for In-kernel spinlocks and semaphores. For more information on priority inversion and priority inheritance "consultintroduction to priority inversion

Converting interrupt handlers into preemptible kernel threads:the rt-preempt patch treats soft interrupt handlers in Ke Rnel thread context, which are represented by a task_struct like a common process. However It is also the possible to register a IRQ in the kernel context.

Converting the old Linux timer API into separate infrastructures for high resolution kernel timers plus one for timeouts , leading to userspace POSIX timers with the high resolution.

In this experiment, the kernel tree we took with rt-preempt Patch was git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable- Rt.git, with its V3.4-rt-rebase branch, the fully preemptible Kernel preemption model was selected when compiling Kernel:

─────────────────────────preemption Model─────────────────────────┐

││ () No forced preemption (Server)
││ () Voluntary Kernel preemption (Desktop)
││ () preemptible Kernel (low-latency Desktop)
││ () preemptible Kernel (Basic RT)
││ (X) fully preemptible Kernel (RT)

In addition, you need to support tickless and high-precision timer in kernel:

┌───────────────────processor Type and Features─────────────────────────┐
││[*] tickless System (Dynamic Ticks)
││[*] High resolution Timer Support

After make Modules_install, makes install, MKINTRAMFS, we get a RT kernel that can be started in Ubuntu. The specific compilation method may see http://www.linuxidc.com/Linux/2012-01/50749.htm, according to this article modifies the version number and so on information, we run the order to include:

Installing modules

barry@barry-virtualbox:~/development/linux-2.6$ sudo make modules_install ...
.
  INSTALL/LIB/FIRMWARE/WHITEHEAT_LOADER.FW
  INSTALL/LIB/FIRMWARE/WHITEHEAT.FW
  install/lib/firmware/ KEYSPAN_PDA/KEYSPAN_PDA.FW
  INSTALL/LIB/FIRMWARE/KEYSPAN_PDA/XIRCOM_PGS.FW
  install/lib/firmware/cpia2/ Stv0672_vp4.bin
  install/lib/firmware/yam/1200.bin
  install/lib/firmware/yam/9600.bin
  DEPMOD  3.4.11-rt19

Install kernel

barry@barry-virtualbox:~/development/linux-2.6$ sudo make install 
sh/home/barry/development/linux-2.6/arch/ x86/boot/install.sh 3.4.11-rt19 arch/x86/boot/bzimage \
system.map "/boot"

Make INITRD

barry@barry-virtualbox:~/development/linux-2.6$ sudo mkinitramfs 3.4.11-rt19-o/boot/initrd.img-3.4.11-rt19

Modify GRUB Configuration

Add a new startup entry to the grub.conf, imitate the existing menuentry, add a new one, change the relevant version number to 3.4.11-rt19, and we will revise as follows:

 Menuentry ' Ubuntu, with Linux 3.4.11-rt19 '--class ubuntu--class gnu-linux--class GNU--class os {
    recordfail
    Smod part_msdos
    insmod ext2
    set root= ' (HD0,MSDOS1) '
    search--no-floppy--fs-uuid--set a0db5cf0-6ce3-404f-9808-88ce18f0177a
    Linux    /boot/vmlinuz-3.4.11-rt19 root=uuid= a0db5cf0-6ce3-404f-9808-88ce18f0177a ro   Quiet splash
    initrd    /boot/initrd.img-3.4.11-rt19
}

Select 3.4.11-rt19 to boot at boot:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.