Write real-time applications in Linux

Source: Internet
Author: User
Write real-time applications in Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. Real-time programs in the user space need services provided by the Linux kernel, including process scheduling, inter-process communication, and performance improvement. Let's analyze various system calls (these services provided by the kernel for user programs are very helpful to real-time application developers ). These system calls can be used to restrict the operating environment.

There are a total of 208 system calls in the Linux kernel. system calls are usually used indirectly through Library Routines. These Library Routines and System Call habits use the same name, but sometimes it is mapped to alternative system calls. For example, the signal library routine in the gun c library (2.6.23) in Linux maps to the sigaction system call.

Real-time applications may call almost all system calls. The most interesting calls are exit (2), fork (2), exec (2), and kill (2) pipe (2), brk (2), getrususage (2), mmap (2), setitimer (2), ipc (2) (it has three forms: semget (), shmget (), msgget (), clone (), mlockall (2), and sched_setscheduler (2 ). Most of these calls are described in "UNIX advanced environment programming" by W. Richard Stevens or "POSIX 4: real-world programming" by Bill O. Gallmeister. Clone () is a Linux-specific call. Most other system calls are compatible with Unix system calls. However, please read the relevant help to find the minor differences.

Real-time applications on Linux are also closely related to POSIX thread calls, such as pthread_create () and pthread_mutex_lock () routines. The implementation of these functions already exists in Linux, and the most commonly used is the implementation from the gun c library. These functions, known as Linux threads, are called Based on the clone () system and scheduled by the Linux scheduler. However, some POSIX functions are only valid for POSIX Threads (such as sem_wait () and cannot be used in Linux processes.

Applications Running in common Linux systems may be quite slow in non-ideal conditions, because they are affected by many conditions, especially resource contention, these resources include synchronization primitives, memory, CPU, bus, CPU cache, and interrupt controller.

Applications can use many methods to reduce resource contention. For synchronization mechanisms, such as mutex variables and semaphores, they should be used less in the program; Priority inherited versions should be used; relatively fast implementation should be adopted; and stay time in the critical section should be reduced. CPU contention is affected by the priority. For example, non-preemptible kernel can be considered as a typical discard priority. Bus competition generally does not take a long time, so you don't need to pay too much attention to it, but it is determined by your hardware. Do you have a clock that takes 70 milliseconds to respond or hold the bus? The competition for high-speed cache is affected by the switching frequency and a large amount of random data or commands.

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.