Assignment 5, due Feb 29

Solutions

Part of the homework for 22C:112, Spring 2008
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: On a simple DMA disk interface, you would write the sector, track and cylinder addresses to the corresponding device addresses, then write the starting memory address and word count to the DMA control regisers before writing the disk command that starts the transfer. This involves a minimum of 6 write operations to device registers.

    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)

    1. sector
      set bus device select register to disk sector register
      set bus device data register to disk sector number

    2. track
      set bus memory address register to disk track register
      set bus device data register to disk track number

    3. cylinder
      set bus device select register to disk cylinder register
      set bus device data register to disk cylinder number

    4. starting memory address
      set bus memory address register to buffer address

    5. word count
      set bus word count register to buffer size in words

    6. 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 controller

    It'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.

  2. Background: Some low-performance systems do not have direct-memory-access controllers. On those, the disk transfer typically moves data to a dedicated buffer, sometimes called the silo. The silo address register is typically set to zero by assignment to the command register, and data can be read from or written to consecutive words of the silo by reading or writing the silo data register. During a disk read or write operation, this mechanism is used to transfer data between the silo and disk, while if the program issues a no-op command to the disk, this mechanism can be used to transfer data between the computer and the disk.

    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)

    1. set disk sector, track and cylinder addresses.
    2. set disk command register to read.
    3. wait for done, indicating data is in the silo.
    4. 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.

  3. Background Most modern disk drives incorporate an onboard cache, so when you write to the disk, data is coped to the cache immediately (if there is space), and when you read from the disk, there may be no nead to actually read the disk itself if the desired data is currently available in the cache.

    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.