⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 implement

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
📖 第 1 页 / 共 3 页
字号:
However, if the swapping device mustalso be used for file storage,the swapping traffic severelyimpacts the file system traffic.It is exactly these small systemsthat tend to double usage of limited diskresources..NH 2Synchronization and scheduling.PPProcess synchronization is accomplished by having processeswait for events.Events are represented by arbitrary integers.By convention,events are chosen to be addresses oftables associated with those events.For example, a process that is waiting forany of its children to terminate will waitfor an event that is the address ofits own process table entry.When a process terminates,it signals the event represented byits parent's process table entry.Signaling an event on which no processis waiting has no effect.Similarly,signaling an event on which many processesare waiting will wake all of them up.This differs considerably fromDijkstra's P and Vsynchronization operations,.[dijkstra sequential processes 1968.]in thatno memory is associated with events.Thus there need be no allocation of eventsprior to their use.Events exist simply by being used..PPOn the negative side,because there is no memory associated with events,no notion of ``how much''can be signaled via the event mechanism.For example,processes that want memory mightwait on an event associated withmemory allocation.When any amount of memory becomes available,the event would be signaled.All the competing processes would then wakeup to fight over the new memory.(In reality,the swapping process is the only processthat waits for primary memory to become available.).PPIf an event occursbetween the time a process decidesto wait for that event and thetime that process enters the wait state,thenthe process will wait on an event that hasalready happened (and may never happen again).This race condition happens because there is no memory associated withthe event to indicate that the event has occurred;the only action of an event is to change a set of processesfrom wait state to run state.This problem is relieved largelyby the fact that process switching canonly occur in the kernel by explicit callsto the event-wait mechanism.If the event in question is signaled by anotherprocess,then there is no problem.But if the event is signaled by a hardwareinterrupt,then special care must be taken.These synchronization races pose the biggestproblem when.UXis adapted to multiple-processor configurations..[hawley meyer multiprocessing unix.].PPThe event-wait code in the kernelis like a co-routine linkage.At any time,all but one of the processes has called event-wait.The remaining process is the one currently executing.When it calls event-wait,a process whose event has been signaledis selected and that processreturns from its call to event-wait..PPWhich of the runable processes is to run next?Associated with each process is a priority.The priority of a system process is assigned by the codeissuing the wait on an event.This is roughly equivalent to the responsethat one would expect on such an event.Disk events have high priority,teletype events are low,and time-of-day events are very low.(From observation,the difference in system process prioritieshas little or no performance impact.)All user-process priorities are lower than thelowest system priority.User-process priorities are assignedby an algorithm based on therecent ratio of the amount of compute time to real time consumedby the process.A process that has used a lot ofcompute time in the last real-timeunit is assigned a low user priority.Because interactive processes are characterizedby low ratios of compute to real time,interactive response is maintained without anyspecial arrangements..PPThe scheduling algorithm simply picksthe process with the highest priority,thuspicking all system processes first anduser processes second.The compute-to-real-time ratio is updatedevery second.Thus,all other things being equal,looping user processes will bescheduled round-robin with a1-second quantum.A high-priority process waking up willpreempt a running, low-priority process.The scheduling algorithm has a very desirablenegative feedback character.If a process uses its high priorityto hog the computer,its priority will drop.At the same time, if a low-priorityprocess is ignored for a long time,its priority will rise..NHI/O SYSTEM.PPThe I/O systemis broken into two completely separate systems:the block I/O system and the character I/O system.In retrospect,the names should have been ``structured I/O''and ``unstructured I/O,'' respectively;while the term ``block I/O'' has some meaning,``character I/O'' is a complete misnomer..PPDevices are characterized by a major device number,a minor device number, anda class (block or character).For each class,there is an array of entry points into the device drivers.The major device number is used to index the arraywhen calling the code for a particular device driver.The minor device number is passed to thedevice driver as an argument.The minor number has no significance otherthan that attributed to it by the driver.Usually,the driver uses the minor number to accessone of several identical physical devices..PPThe use of the array of entry points(configuration table)as the only connection between thesystem code and the device drivers isvery important.Early versions of the system had a muchless formal connection with the drivers,so that it was extremely hard to handcraftdifferently configured systems.Now it is possible to create newdevice drivers in an average of a few hours.The configuration table in most casesis created automatically by a programthat reads the system's parts list..NH 2Block I/O system.PPThe model block I/O device consistsof randomly addressed, secondarymemory blocks of 512 bytes each.The blocks are uniformly addressed0, 1, .\|.\|. up to the size of the device.The block device driver has the job ofemulating this model on aphysical device..PPThe block I/O devices are accessedthrough a layer of buffering software.The system maintains a list of buffers(typically between 10 and 70)each assigned a device name anda device address.This buffer pool constitutes a data cachefor the block devices.On a read request,the cache is searched for the desired block.If the block is found,the data are made available to therequester without any physical I/O.If the block is not in the cache,the least recently used block in the cache is renamed,the correct device driver is called tofill up the renamed buffer, and then thedata are made available.Write requests are handled in an analogous manner.The correct buffer is foundand relabeled if necessary.The write is performed simply by markingthe buffer as ``dirty.''The physical I/O is then deferred untilthe buffer is renamed..PPThe benefits in reduction of physical I/Oof this scheme are substantial,especially considering the file system implementation.There are,however,some drawbacks.The asynchronous nature of thealgorithm makes error reportingand meaningful user error handlingalmost impossible.The cavalier approach to I/O errorhandling in the.UXsystem is partly due to the asynchronousnature of the block I/O system.A second problem is in the delayed writes.If the system stops unexpectedly,it is almost certain that there is alot of logically complete,but physically incomplete,I/O in the buffers.There is a system primitive toflush all outstanding I/O activityfrom the buffers.Periodic use of this primitive helps,but does not solve, the problem.Finally,the associativity in the bufferscan alter the physical I/O sequencefrom that of the logical I/O sequence.This means that there are timeswhen data structures on disk are inconsistent,even though the software is carefulto perform I/O in the correct order.On non-random devices,notably magnetic tape,the inversions of writes can be disastrous.The problem with magnetic tapes is ``cured'' byallowing only one outstanding write requestper drive..NH 2Character I/O system.PPThe character I/O system consists of alldevices that do not fall into the block I/O model.This includes the ``classical'' character devicessuch as communications lines, paper tape, andline printers.It also includes magnetic tape and disks whenthey are not used in a stereotyped way,for example, 80-byte physical records on tapeand track-at-a-time disk copies.In short,the character I/O interfacemeans ``everything other than block.''I/O requests from the user are sent to thedevice driver essentially unaltered.The implementation of these requests is, of course,up to the device driver.There are guidelines and conventionsto help the implementation ofcertain types of device drivers..NH 3Disk drivers.PPDisk drivers are implementedwith a queue of transaction records.Each record holds a read/write flag,a primary memory address,a secondary memory address, anda transfer byte count.Swapping is accomplished by passingsuch a record to the swapping device driver.The block I/O interface is implemented bypassing such records with requests tofill and empty system buffers.The character I/O interface to the diskdrivers create a transaction record thatpoints directly into the user area.The routine that creates this record also insuresthat the user is not swapped during thisI/O transaction.Thus by implementing the general disk driver,it is possible to use the diskas a block device,a character device, and a swap device.The only really disk-specific code in normaldisk drivers is the pre-sort of transactions tominimize latency for a particular device, andthe actual issuing of the I/O request..NH 3Character lists.PPReal character-oriented devices maybe implemented using the commoncode to handle character lists.A character list is a queue of characters.One routine puts a character on a queue.Another gets a character from a queue.It is also possible to ask how manycharacters are currently on a queue.Storage for all queues in the system comesfrom a single common pool.Putting a character on a queue will allocatespace from the common pool and link thecharacter onto the data structure defining the queue.Getting a character from a queue returnsthe corresponding space to the pool..PPA typical character-output device(paper tape punch, for example)is implemented by passing charactersfrom the user onto a character queue untilsome maximum number of characters is on the queue.The I/O is prodded to start assoon as there is anything on the queueand, once started,it is sustained by hardware completion interrupts.Each time there is a completion interrupt,the driver gets the next character from the queueand sends it to the hardware.The number of characters on the queue is checked and,as the count falls through some intermediate level,an event (the queue address) is signaled.The process that is passing characters fromthe user to the queue can be waiting on the event, andrefill the queue to its maximumwhen the event occurs..PPA typical character input device(for example, a paper tape reader)is handled in a very similar manner..PPAnother class of character devices is the terminals.A terminal is represented by threecharacter queues.There are two input queues (raw and canonical)and an output queue.Characters going to the output of a terminalare handled by common code exactly as describedabove.The main difference is that there is also codeto interpret the output stream as.UC  ASCIIcharacters and to perform some translations,e.g., escapes for deficient terminals.Another common aspect of terminals is codeto insert real-time delay after certain control characters..PPInput on terminals is a little different.Characters are collected from the terminal andplaced on a raw input queue.Some device-dependent code conversion andescape interpretation is handled here.When a line is complete in the raw queue,an event is signaled.The code catching this signal then copies aline from the raw queue to a canonical queueperforming the character erase and line kill editing.User read requests on terminals can bedirected at either the raw or canonical queues..NH 3Other character devices.PPFinally,there are devices that fit no general category.These devices are set up as character I/O drivers.An example is a driver that reads and writesunmapped primary memory as an I/O device.Some devices are toofast to be treated a character at time,but do not fit the disk I/O mold.Examples are fast communications lines andfast line printers.These devices either have their own buffersor ``borrow'' block I/O buffers for a while andthen give them back..NHTHE FILE SYSTEM.PPIn the.UXsystem,a file is a (one-dimensional) array of bytes.No other structure of files is implied by thesystem.Files are attached anywhere(and possibly multiply)onto a hierarchy of directories.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -