1 / 33

RTLinux Lab – Introduction Cpre 558

RTLinux Lab – Introduction Cpre 558. Anil anil@iastate.edu. Contents. Real-Time Operating System (RTOS) Vs. General Purpose OS (GPOS) Can Linux provide real-time guarantees? Commercial RTOSs RTLinux Vs. Linux: Architectural comparison RTLinux Vs. Linux: Code perspective

harper
Download Presentation

RTLinux Lab – Introduction Cpre 558

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. RTLinux Lab – IntroductionCpre 558 Anil anil@iastate.edu CprE 458/558: Real-Time Systems (G. Manimaran)

  2. Contents • Real-Time Operating System (RTOS) Vs. General Purpose OS (GPOS) • Can Linux provide real-time guarantees? • Commercial RTOSs • RTLinux Vs. Linux: Architectural comparison • RTLinux Vs. Linux: Code perspective • Get the RTLinux setup ready • Things to Issue and Handling the hard disk • Lab #1: Detailed discussion CprE 458/558: Real-Time Systems (G. Manimaran)

  3. RTOS Vs. GPOS • RTOS • needs deterministic timing behavior • Works under worst case assumptions • GPOS • high throughput and fairness • Optimizes for the average case • Hence, the design objectives of the OSs are different CprE 458/558: Real-Time Systems (G. Manimaran)

  4. Can Linux provide real-time guarantees?-- No!! • Linux • non-preemptible kernel • A system call might take long time to complete • Coarse timer resolution • Tasks can be released only with 10ms precision • Virtual memory • Introduces unpredictable amount of delays • Variable priority • Each task is assigned a priority which varies over the time; this is to achieve fairness CprE 458/558: Real-Time Systems (G. Manimaran)

  5. Can Linux provide real-time guarantees?-- No!! (contd..) • Linux • Linux will batch several operations for efficient use of H/W delaying all tasks • Linux also reorders requests from multiple processes for H/W efficiency • Linux does not preempt low priority task in a system call, instead queues the high priority task • Linux makes high priority tasks to wait for low priority tasks to release resources Therefore, Linux cannot provide real-time guarantees CprE 458/558: Real-Time Systems (G. Manimaran)

  6. Commercial RTOS • RTLinux – Monolithic kernel with loadable modules • QNX – Microkernel approach • VxWorks – Monolithic kernel • LynxOS – Microkernel • ARTS, Spring, KURT, RTAI, etc…. CprE 458/558: Real-Time Systems (G. Manimaran)

  7. RTLinux: Overview • Open source Linux project • Supports x86, PowerPC, Alpha • Available as a patch to the regular Linux kernel • Provides an RT API for developers • Runs Linux kernel as lowest priority process CprE 458/558: Real-Time Systems (G. Manimaran)

  8. Linux Kernel User Processes System libraries Linux kernel Device drivers I/O Hardware Interrupts Hardware CprE 458/558: Real-Time Systems (G. Manimaran)

  9. RTLinux Kernel Linux is executed in the background User Processes Real Time Tasks System libraries Linux kernel Device drivers I/O Software Interrupts Direct h/w access RTLinux Plug-in RT-Scheduler I/O Hardware Interrupts Hardware CprE 458/558: Real-Time Systems (G. Manimaran)

  10. Linux Kernel: code perspective THE controller User Process Kernel Loadable Modules Module M2 service (system call) M1 M2 M2 Linux Monolithic kernel core M3 M4 RAM DISK CprE 458/558: Real-Time Systems (G. Manimaran)

  11. RTLinux Kernel: code perspective THE controller RT Load command RT core Kernel Loadable Modules Load RTcore RTM2 RTM3 Linux Monolithic kernel core M1 M2 RT-Core Module M3 RAM DISK CprE 458/558: Real-Time Systems (G. Manimaran)

  12. Getting RTLinux ready • Configure and compile a fresh Linux kernel (2.4.29) • Download the kernel from http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.29.tar.gz • Patch the RTLinux to the Linux kernel • Recompile the kernel and reboot the system into the new kernel • Configure the RTLinux kernel and compile it CprE 458/558: Real-Time Systems (G. Manimaran)

  13. So, How do we run a RT-application program ? • Step 1: Write the RT-application program as a kernel module • (You are still in Linux) • Step 2: Compile the module and check for errors • (You are still in Linux) • Step 3: Load the RT-Core (or RT Scheduler, etc..) and the RT-application program module • (After this we will be in RTLinux) • Step 4: Now you are in RTLinux!!!! CprE 458/558: Real-Time Systems (G. Manimaran)

  14. Homework • Submission 1: • Give a ten line write-up comparing RTLinux with Linux with at least five differences along with the references. • Submission 2: • Give a ten line write-up comparing RTLinux with two other commercial RTOSs with at least five differences for each of them along with the references. CprE 458/558: Real-Time Systems (G. Manimaran)

  15. Lab Policies • Six assignments in total • First three assignments are mandatory • One of the last three assignments is mandatory • You will be working with a removable hard disk which can be issued from CSG CprE 458/558: Real-Time Systems (G. Manimaran)

  16. Things to Issue • Issue the following from the CSG • Hard disk (one per group) • Key (one per group) • RHEL – WS3 installation DVD (one per group) • You need to download the lab01 tar file (lab01.tgz) from the course website. • The RTLinux lab is in Coover - 1331C CprE 458/558: Real-Time Systems (G. Manimaran)

  17. Handling the hard disk (1) • Shutdown the PC • After the power is off, unlock the existing hard disk and take it out • Insert the hard disk given to you and lock it • Restart the comp • Follow the manual you have downloaded from the course website CprE 458/558: Real-Time Systems (G. Manimaran)

  18. Handling the hard disk (2) • After you are done with the lab: • Shutdown the PC • After the power is off, unlock the hard disk and remove it • Insert the original hard disk and lock it • Leave the Lab CprE 458/558: Real-Time Systems (G. Manimaran)

  19. RTLinux Lab# 1Cpre 558 Anil anil@iastate.edu CprE 458/558: Real-Time Systems (G. Manimaran)

  20. Lab 1: Objectives • Part 1: • Getting the RTLinux lab setup ready • Part 2: • Run a few simple hello-world modules CprE 458/558: Real-Time Systems (G. Manimaran)

  21. Part 1 • Install the RHEL-WS3 using the DVD given to you • Go for the auto-partitioning option • Rest everything is straightforward • Configure and compile fresh Linux kernel (2.4.29) • Patch the RTLinux to the Linux kernel • Recompile the kernel and reboot the system into the new kernel • Load RT-modules • Instructions are provided in the Lab manual CprE 458/558: Real-Time Systems (G. Manimaran)

  22. Part 2 • Boot into the RTLinux kernel compiled in part-1 • The objectives of the part 2 are: • Understanding a simple RTLinux kernel module • With one thread (hello-1) and two threads (hello-2) • Printing from a RTLinux module • rtl_printf (hello-3) • Using rtf_put (RT-FIFO) (hello-4) CprE 458/558: Real-Time Systems (G. Manimaran)

  23. A kernel module Vs. Program • All RT-Tasks are kernel modules. Therefore, we write kernel modules in this lab. • A user program runs in user space and the kernel module runs in the kernel space • A user program starts running at its “main” function • A kernel module starts running at the “init_module” function and exits via “cleanup_module” function • Therefore, for a kernel module “init_module” and ‘cleanup_module” are as necessary as “main” is necessary for a C program CprE 458/558: Real-Time Systems (G. Manimaran)

  24. A typical kernel module Init_module() { ……. Perform your module initiation stuff etc.. } Cleanup_module() { ……. Perform cleanup stuff like destroying the threads, freeing memory, etc.. } CprE 458/558: Real-Time Systems (G. Manimaran)

  25. Hello world Module • Go through the hello world module • Realize the importance of init_module and cleanup_module • Notice the way the thread is created and how it is made periodic • Understand the “pthread_make_periodic” and “pthread_wait” and other interfacing functions CprE 458/558: Real-Time Systems (G. Manimaran)

  26. A typical RTLinux module This function tells the scheduler that I am a periodic task with period “p” Init_module() { For each thread: Choose the priority function //pthread_set_priority(..); Assign the “task_function” to the thread Create the thread //pthread_create(.., task_function,..);} Task_function() { Pthread_make_periodic_np(p); while(1) { Pthread_wait_np(); //perform the task function //for this instance } } Cleanup_module() { ……. Delete the thread //pthread_delete_np(..); } This function tells the scheduler that I am done for this instance and schedule me after “p” units of time CprE 458/558: Real-Time Systems (G. Manimaran)

  27. Hello World 2 • This module creates two threads using a nice “thread_struct” structure to make the initialization easy and compact. • Once again go through the interfacing funcitons • This time put more “rtl_printf” statements and open “/var/log/messages” file to find your output CprE 458/558: Real-Time Systems (G. Manimaran)

  28. RTL_PRINTF: how does it work? Might overflow!! printk Rtl_printf Printk buffer Kernel ring buffer Log file Might overflow!! console syslodg CprE 458/558: Real-Time Systems (G. Manimaran)

  29. Other ways of printing: RTL-FIFO • RTLinux FIFO provides communication mechanisms between RTL threads and Linux task. • A linux process creates the RTL-FIFO buffer which the RTL threads access and write and read from them CprE 458/558: Real-Time Systems (G. Manimaran)

  30. RTL-FIFO • Creating and destroying FIFOS: • Using functions: rtf_create and rtf_destroy • These functions are called from linux process: open(), read(), write(); • Accessing FIFOs from RTL threads • using functions: rtf_put and rtf_get CprE 458/558: Real-Time Systems (G. Manimaran)

  31. Using RTL_FIFO Linux Task: my_readtask RT Task: my_put task rtf_create() open() rtf_put() Time read() rtf_destroy() RTL FIFO CprE 458/558: Real-Time Systems (G. Manimaran)

  32. Submissions • Submission 1: • Submit a five line write-up explaining the working of the two RTL interfacing functions including: • Pthread_make_periodic_np • Pthread_wait_np • Rtf_create,rtf_destroy, rtf_put, rtf_get • Submission 2: • Submit a five line write-up giving at least five differences between a kernel module and a user program. CprE 458/558: Real-Time Systems (G. Manimaran)

  33. Thank You!! CprE 458/558: Real-Time Systems (G. Manimaran)

More Related