?? 00000009.htm
字號:
or for all pages (code, stack, data, shared memory, mapped files, <br />shared libraries) to which a process has access (mlockall()). This <br />allows to guarantee that for instance small time-critical daemons stay <br />in memory which can help to guarantee response time of these <br />processes. Under Linux, this (like many other real-time related <br />features) is only allowed for root processes in order to avoid abuse <br />of this feature by normal users in large time-sharing systems. <br />Another application of memory locking are cryptographic computer <br />security programs. Using mlock(), these systems can ensure that an <br />unencrypted secret key or a password which is temporarily stored in a <br />small user space array will never get in contact with the swap device, <br />where under rare circumstances, someone might find the secret bytes <br />even many months later. For these applications, it would be desirable <br />if Linux allowed even non-root processes a small number of mlock()ed <br />pages (e.g. up to four locked pages per non-root process should be <br />ok). <br />Implementation status: Linus has now added full POSIX.1b memory <br />locking support to Linux alpha test kernel version 1.3.43. There exist <br />also libc support and manual pages. So you won't have to apply the <br />POSIX.4_locking patch from Ralf Haller <<a href="mailto:hal@iitb.fhg.de>">hal@iitb.fhg.de></a> any more. <br />Synchronous I/O <br />--------------- <br />Databases, e-mail systems, log daemons, etc. require to be sure that <br />the written piece of data has actually reached the harddisk, because <br />transaction protocols require that a system crash or power failure <br />after the write command can not harm the data any more. POSIX.1b <br />defines the fsync() and O_SYNC mechanisms which Linux 1.2 already has. <br />In addition, there is a very useful new function fdatasync() which <br />requires that the data block is flushed to disk, however which does <br />NOT require that the inode with the latest access/modification time is <br />also flushed each time. With fdatasync(), the inode has only to be <br />written in case the file length, file owner, or permission bits have <br />changed. In database applications with mostly constant file sizes, <br />where you sometimes require an fsync() after each few written blocks, <br />but where you don't care about whether the access times in the inodes <br />on the disc are always 100% up-to-date, fdatasync() could easily <br />double (!) the performance of your system. <br />There is also an msync() function for flushing a range of pages from <br />memory mapped files to the disk. <br />Implementation status: fsync(), fdatasync(), msync(), and O_SYNC are <br />already available. O_DSYNC has not yet been implemented. However <br />fdatasync() in Linux 1.3.55 is currently only an alias for fsync() and <br />therefore not yet any more efficient than fsync(). <br />Timers <br />------ <br />- Instead of the old BSD style gettimeofday()/settimeofday() calls, <br />POSIX.1b defines clock_gettimer(), clock_settimer() and <br />clock_getres(). They offer nanosecond resolution instead of <br />microseconds as with the old BSD calls (at least on Pentiums, a <br />timer resolution much than a microsecond is available). In <br />addition, you can query now the actual resolution of the timer <br />with clock_getres(). <br />- A new function nanosleep() allows to sleep also for less than a <br />second (the old sleep() had only second resolution). In addition, <br />nanosleep won't interfere with SIGALRM and in case of EINTR, it <br />returns the time left, so you can easily continue in a while loop. <br />- POSIX.1b defines also itimers, however instead of what the <br />existing BSD itimers provide, you now can deal with several timers <br />(at least 32 per process) and you have again theoretically up to <br />one nanosecond resolution. The old itimer functions can still <br />easily be implemented in libc for compatibility reasons using new <br />POSIX-style itimer system calls. <br />not not yet been implemented, although much of the functionality is <br />already available in the form of the BSD timers and adding them should <br />be quite easy. Queued signals have to be implemented first for <br />itimers. Nanosleep() is already available in Linux, but at the moment <br />it supports only 10 ms resolution and it can optionally perform short <br />microsecond precision busy waits of up to 2 ms length. <br />Scheduling <br />---------- <br />Linux 1.2 has so far been optimized a lot as a time sharing system, <br />where several people run application programs like editors, compilers, <br />debuggers, X window servers, networking daemons, etc. and do word <br />processing, software development, etc. <br />However there are a lot of applications for which Linux is currently <br />unusable and for which even die-hard Linux enthusiasts have to keep a <br />stand-alone DOS version on their disk. For >90% of these applications, <br />the fact that Linux is incapable of guaranteeing the response time of <br />an application is the major problem. Software for controlling e.g. an <br />EPROM programmer, a robot arm, or an astronomical CCD camera is not <br />realizable under a classic Unix if there is no dedicated real-time <br />controller present in the controlled device. A lot of commercially <br />available hardware has been designed with the real-time "capability" <br />of DOS in mind and has no own microcontroller for time-critical <br />actions. <br />A real-world example: I have myself spent a long frustrating time of <br />trying to implement an interface to a pay-TV decoder for Linux (which <br />emulates a chip card and allows you to watch pay-TV for free :-). In <br />this application, you have to wait for an incoming byte on the serial <br />port, then you have to wait for around 0.7 to 2 ms (never shorter, <br />never longer, otherwise the TV decoder gets a timeout and stops!) <br />before returning an answer byte. It is virtually impossible to <br />implement a user process for this task under Linux 1.2, while it is <br />trivial to do this under DOS. I am looking forward to the day when <br />Linux provides enough real-time support for this application so that I <br />can finally remove MS-DOS from my harddisk. <br />For these and similar real-time applications, POSIX.1b specifies three <br />different schedulers, each with static priorities: <br />SCHED_FIFO A preemptive, priority based scheduler. Each process <br />managed under this scheduling priority possesses the <br />CPU as long as (a) it does not block itself and (b) <br />there comes no interrupt which puts another process <br />into a higher priority wait queue. There exists a FIFO <br />queue for each priority level and every process which <br />gets runnable again is inserted into the queue behind <br />all other processes. This is the most popular <br />scheduler used in typical real-time operating <br />systems. Function sched_yield() allows the process to <br />go to the end of the FIFO queue without blocking. <br />SCHED_RR A preemptive, priority based round robin scheduling <br />strategy with quanta. It is a very similar to <br />SCHED_FIFO, however each process has a time quantum and <br />the process becomes preempted and is inserted at the <br />end of the FIFO for the same priority level if it <br />runs longer than the time quantum and other processes <br />of the same priority level are waiting in the queue. <br />Processes of lower priorities will like in SCHED_FIFO <br />never get the CPU as long as a higher level process <br />is in a ready queue and if a higher priority process <br />becomes ready to run, it also gets the CPU immediately. <br />SCHED_OTHER This is any implementation defined scheduler. Under <br />Linux it is the classic time-sharing scheduler with <br />"nice" values, etc. Under Linux, all SCHED_OTHER <br />processes share the common static priority value 0. <br />For security reasons, only root processes should under Linux be <br />allowed to get any static priority higher than the one for <br />SCHED_OTHER, because if these real-time scheduling mechanisms are <br />abused, the whole system can be blocked. <br />If one is developing a real-time application, it is a very good idea <br />to have a shell with a higher static priority somewhere open in order <br />to be able to kill the tested application in case something goes <br />wrong. You should be aware, that if you use X11, not only the shell, <br />but also the X server, the window manager and xterm will require a <br />higher static priority in order to stop processes blocking the rest of <br />the system. Therefore, testing real-time software will usually better <br />be done on the console. <br />With this POSIX.1b functionality, it is possible to run real-time <br />software under Linux by giving it root permissions and assigning it a <br />SCHED_FIFO strategy and a higher static priority than all other <br />classic SCHED_OTHER Linux processes. In addition, typical real-time <br />application lock their pages with mlockall() into the memory in order <br />
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -