?? 00000009.htm
字號(hào):
to avoid being swapped out. This guarantees that the real-time <br />application can react as soon as possible on any interrupts and that <br />the response time will not be influenced by the complicated normal <br />Linux time-sharing priority mechanisms or by paging. However, please <br />read also the chapter on interrupt dispatch latency below! <br />The new functions are here: <br />sched_setparam(), sched_getparam(), sched_setscheduler(), <br />sched_getscheduler(), sched_yield(), sched_get_priority_max(), <br />sched_get_priority_min(), sched_rr_get_interval(). <br />Implementation status: The sched_*() system calls are now available <br />since Linux 1.3.55 (Markus Kuhn <<a href="mailto:mskuhn@cip.informatik.uni-erlangen.de>).">mskuhn@cip.informatik.uni-erlangen.de>).</a> <br />Although much testing, performance evaluation, and optimization with <br />the real-time scheduler is necessary (especially with regard to "fast <br />interrupt handling, see below), you can already use the sched_*() <br />calls in order to get the processor exclusively. There are also libc <br />and manual pages available. Some earlier work on this was done by <br />David F. Carlson <<a href="mailto:carlson@dot4.com>">carlson@dot4.com></a> in his POSIX.4_scheduler patch <br />against Linux 1.2 (still available on sunsite). <br />Asynchronous I/O (aio) <br />---------------------- <br />POSIX.1b defines a number of functions which allow to send a long list <br />of read/write requests at various seek positions in various files to <br />the kernel with one single lio_listio() system call. While the process <br />continues to execute the next instructions, the kernel will <br />asynchronously read or write the requested pages and will send signals <br />when the task has been completed (if this is desired). <br />This is very nice for a database which knows that it will require a <br />lot of different blocks scattered on a file. It will simply pass a <br />list of the blocks to the kernel, and the kernel can optimize the disk <br />head movement before sending the requests to the device. In addition <br />this minimizes the number of system calls and allows the database to <br />do something else in the meantime (e.g. waiting for the client process <br />sending an abort instruction in which case the database server can <br />cancel the async i/o requests with aio_cancel()). <br />Another important application of aio are multimedia systems like MPEG <br />or sound file players and recorders. These programs want to preload <br />the next few seconds of the data stream from harddisk into locked <br />memory, but also want to continue showing the video on the screen at <br />the same time without any interruptions caused by synchronous I/O. The <br />POSIX.1b async I/O calls provide a nice way for such anticipatory <br />loading. <br />POSIX.1b also defines priorities for asynchronous I/O, i.e. there is a <br />way to tell the kernel that the read request for the MPEG player is <br />more important than the read request of gcc. On a future real-time <br />Linux, you don't want to see any image distortions while watching MPEG <br />video and compiling a kernel at the same time if you gave the MPEG <br />player a higher static priority. <br />New functions in this area are: <br />aio_read(), aio_write(), lio_listio(), aio_suspend(), aio_cancel(), <br />aio_error(), aio_return(), aio_fsync(). <br />Implementation status: Not yet implemented. The aio functions are <br />probably best implemented in libc using kernel threads and the normal <br />synchronous I/O system calls. There has recently been some progress on <br />implementing kernel threads in Linux 1.3 using the clone() system <br />call. Adding priority I/O to Linux might be a more complicated job, <br />because many device drivers would have to be extended by priority wait <br />queues. <br />Implemented options <br />------------------- <br />As POSIX.1b conformance does not require the implementation of all <br />these functions, macros have been specified for <unistd.h> that <br />indicate to application software which of the POSIX.1b functionality <br />is available on this system. This way, portable software can be <br />written that uses real-time features only when they are available. <br />Under the latest Linux kernel and libc development versions, the <br />following POSIX.1b macros have been defined and indicate implemented <br />functions: <br />_POSIX_FSYNC <br />_POSIX_MAPPED_FILES <br />_POSIX_MEMLOCK <br />_POSIX_MEMLOCK_RANGE <br />_POSIX_MEMORY_PROTECTION <br />_POSIX_PRIORITY_SCHEDULING <br />The POSIX.1b options indicated by the following macros have not yet <br />been implemented under Linux: <br />_POSIX_ASYNCHRONOUS_IO <br />_POSIX_MESSAGE_PASSING <br />_POSIX_PRIORITIZED_IO <br />_POSIX_REALTIME_SIGNALS <br />_POSIX_SEMAPHORES <br />_POSIX_SHARED_MEMORY_OBJECTS <br />_POSIX_SYNCHRONIZED_IO <br />_POSIX_TIMERS <br />General real-time problems <br />-------------------------- <br />Apart from implementing new POSIX.1b system calls, there are a number <br />of other problems with the current Linux kernel that have to be solved <br />in order to improve real-time performance. <br />Problem 1: Interrupt dispatch latency <br />A blocked process waiting for the end of some I/O request becomes <br />runnable again when the CPU receives an interrupt from the I/O device <br />that processed the request. The time that passes between the interrupt <br />and the execution of the interrupt handler is called the "interrupt <br />latency". The time that passes between the interrupt and the <br />continuation of the execution of the blocked process is called the <br />"interrupt dispatch latency". We are assuming that the blocked process <br />is the process with the highest priority (the POSIX.1b scheduler <br />system calls allow to ensure this). Many real-time applications <br />require that the interrupt dispatch latency is as short as possible, <br />some applications require even guarantees for the maximum interrupt <br />dispatch latency (e.g. 20 microseconds). <br />At the moment, Linux has basically two types of interrupt handlers: <br />"fast" and "slow" ones. <br />The "slow interrupt handlers" call the scheduler each time immediately <br />after the interrupt has been handled. This guarantees that if the <br />process has become runnable by handling the interrupt and has the <br />highest priority, then it will directly get control over the CPU after <br />the interrupt handler. This ensures a short interrupt dispatch <br />latency, but the cost is that the scheduler is executed for each <br />interrupt, which can cause a system performance degradation for <br />devices with a high interrupt rate (e.g., network controllers). The <br />slow interrupt handler do not disable other interrupts while they are <br />being executed. This ensures a low interrupt latency, because other <br />higher priority interrupts will not be blocked. The "slow" interrupt <br />handler behavior is what you want for real-time applications. <br />The "fast interrupt handlers" only mark in a bitmask that an interrupt <br />has been handled for this device. The scheduler is NOT called after <br />the fast interrupt handler and the process waiting on the interrupt <br />may have to wait up to 1 s / HZ = 10 ms for the next timer interrupt <br />which will call the scheduler again (because the timer interrupt is <br />handled the "slow" way). "Fast" interrupt handlers are those which are <br />installed by the driver by specifying the SA_INTERRUPT option when <br />calling request_irq(). "Fast" interrupt handlers are the reason why <br />for devices like the serial port, the interrupt dispatch latency can <br />easily reach 10 ms and more. "Fast" interrupt handlers disable other <br />interrupts while the handler is being executed. This increases <br />interrupt latency. The Linux "fast" interrupt handlers cause very low <br />interrupt handling overhead, but they can be the cause for a lot of <br />headaches for real-time application developers. <br />See linux/arch/i386/kernel/irq.c, linux/include/asm-i386/irq.h and <br />linux/arch/i386/kernel/entry.S for implementation details of how fast <br />and slow interrupts are handled in Linux. <br />Examples for "slow" Linux 1.3 interrupt drivers with good interrupt <br />dispatch latency are <br />keyboard <br />floppy disk <br />timer <br />sound cards <br />mouse drivers <br />some Ethernet cards <br />Examples for "fast" interrupt drivers with bad interrupt dispatch <br />latency are <br />
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -