RHEL-RT RTAppDevelHowto

From RHEL-RT

Jump to: navigation, search

Contents

RT Application Development

This page holds tips related to enhancing and developing RT Applications.


In general, try to use POSIX defined APIs. The C library and the Linux kernel developers work very hard to ensure that they are compliant with POSIX standards and almost all the work for latency reduction in the RHEL-RT kernel has centered around POSIX (particularly pthreads).


Memory Related tips

This article, Build an RT-application, has valuable information on why Page Faults are a problem and how to minimize or avoid it. That information will boost your RT application.

In order to better use the techniques explained in the article you may profile your application, using tools available in the system or instrumenting your code with getrusage, to better understand the memory allocation needs and other datails that may not be visible during wallclock or eyeball debugging sessions.

Latency tips

The signal processing code in the Linux kernel is very complex since it carries a lot of baggage from how signals have evolved over the years of UNIX programming. For a concise summary of this, read Ulrich Drepper's page on the Requirements of the POSIX signal model. This complexity translates into many code paths that can increase latency when processing signals. Avoid this by not using signals to transmit high-frequency event notifications between threads.


So, if you shouldn't use signals, how should you transmit event notifications between threads? Use the pthread defined synchronization primitives: mutexes, condition variables, or barriers. These are all designed to synchronize thread interaction.


For example, what if you want to notify a thread (or group of threads) that a timer event has expired? A traditional UNIX approach to this would be to set up a SIGALRM signal handler and then use the alarm(2) system call to cause a SIGALRM to be delivered after a specified interval. A more sophisticated approach might use the setitimer(2) system call, but would still depend on delivering SIGALRM for notification.


Instead of using a signal, use a dedicated thread to measure the desired interval and when the interval expires, notify the worker threads using a pthread primitive such as a condition variable or a barrier.

Realtime Priorities

Refer to this page for suggestions on setting priorities of realtime processes. Be very careful if attempting to prioritize application processes higher than kernel services. For example, that could lead to system hangs if it needs to execute page fault handlers set at lower priority.

RHEL-RT SchedPrioHowto

References