Assignment 5, due Feb 29Solutions
Part of
the homework for 22C:112, Spring 2008
|
Now, consider a system based on a bus architecture comparable to the SCSI bus. On this system, the bus controller has memory-address, word-count and control registers for the DMA transfer, and a device-select register and a device-data register to communicate directly with devices on the bus. To write to an interface register of a particular device on the bus, the program must first select a device register using the bus device-select register, then write the command to that device using the bus device-data register.
Question: Give the program of write operations to device registers required to start a disk operation on the bus-structured disk interface. Group these operations into 6 groups so that each group corresponds to one of the 6 write operations required to start a transfer on the simple disk interface, and document each group accordingly. (0.5 points)
- sector
set bus device select register to disk sector register
set bus device data register to disk sector number
- track
set bus memory address register to disk track register
set bus device data register to disk track number
- cylinder
set bus device select register to disk cylinder register
set bus device data register to disk cylinder number
- starting memory address
set bus memory address register to buffer address
- word count
set bus word count register to buffer size in words
- command
set bus command register to command for bus
set bus device select register to disk command register
set bus device data register to command for disk controllerIt's worth noting that the bus command is sent first, but nothing happens until the disk controller says it is ready. If the disk controller were given its command first, it might try to start a data transfer before the bus controller was ready for it. It is best for the bus controller to be saying "ready" to the disk when the disk has nothing to do, than the disk to be saying "I need to transfer data now!" when the bus is not ready to do so.
a) Outline the code to do a disk-read operation, reading the addressed sector (cylinder, sector, surface) to the user's buffer (address, length). Assume no interrupts, so the program must wait for the ready bit by polling. (0.5 points)
- set disk sector, track and cylinder addresses.
- set disk command register to read.
- wait for done, indicating data is in the silo.
- iteratively copy one sector from the silo data register to the memory buffer.
b) Discuss and evaluate the options for using interrupts with this disk system. Consider, for example, the relative merits for an interrupt that signals "disk transfer done" versus an interrupt signalling readyness to transfer a single byte between the silo and the user's memory, and consider the question of whether silo-user data transfers belong in an interrupt service routine or in interruptable user-level code. (0.5 points)
There is no point in having an interrupt for each byte (or word) of data, since the cost of interrupt service routine entry and exit are likely to exceed the cost of moving one byte to or from the user's memory buffer.
Therefore, the sensible thing to do would be to have an interrupt that signals readyness to transfer a full silo of data. The interrupt service routine would then transfer the entire silo full of data to or from the user buffer in a tight loop. While this loop is running, it might make sense to allow higher priority devices to interrupt.
a) If a disk drive has an onboard cache, is there any need to do disk scheduling? If so, where? (0.5 points)
Yes. The best place to schedule is between the on-board cache and the disk, so the scheduling is done by the disk controller, not by the operating system. Operating system scheduling can only improve performance in this case of the number of pending disk requests exceeds the size of the on-board cache.
b) Design an experiment that a disk user could use to determine empirically the size of the on-board cache on a disk drive. Assume that the operating system has no disk-cache or that any cache behavior in the operating system has been turned off. (0.5 points)
First, of course, you must turn off any software cache in the operating system. Then, run a program that counts the number of disk access per second while scheduling successively larger numbers of reads and writes to different disk sectors. So long as the number of reads and writes is smaller than the cache size, the disk ought to appear very fast. Once the number of reads and writes exceeds the cache capacity, the apparent performance should fall.
c) Is there any way a disk user could measure the difference between a software disk cache implemented by the operating system and a hardware disk cache implemented by the disk controller? If not, why? If so, how? (0.5 points)
No. From the user perspective, a good cache is a good cache. If there is a way to differentiate between caches implemented at different levels in the hierarchy between user and device, it would be very subtle. Such differentiation is far more likely to differentiate between different cache strategies than between different cache locations.