Senior: Disk Driver Section B

Problem: Computer system software must sometimes be designed to run as quickly as possible. This is especially true of large, multitasking and multi-user system like Windows NT. Your challenge is to create an optimized disk drive scheduling routine much like the ones used by advanced operating systems. The program will be a simulation of a disk driver and a hard disk.

Hard disk drives require much more time to read than to write; the hard drive your program will control requires one millisecond to read a megabyte and three milliseconds to write a megabyte. It has a capacity of 1000 megabytes, each designated with a location from 1 to 1000.

Your driver must issue read operations before writes unless a particular write has waited for 500 milliseconds or more, when it must be run before running any more reads. To make matters more complex, when there is a read that overlaps a pending write operation, the read must wait for the write to finish (this is only true if the read was issued after the write). The only time the read does not have to wait for the write is when a single pending write covers the whole read, in which case the transfer takes 0 milliseconds because it is done entirely within memory.

Input: The program must accept commands, each composed of a time delay (in milliseconds from 1 to 100), a command (W = Write, R = Read, D = Done), a location (from 1 to 1000), and a length (from 1 to 1000). It must continue to accept until the Done command is issued.

Output: After accepting the command, the program must summarize the command that has just been queued and display the operations completed since the last command. The time that has elapsed since the last command is the value of the time delay. See sample for clarifications. The program should print the current time before accepting each command.

Sample:

 

Current Time: 0

Enter the command [time delay, command, location, length]: 0,R,1,100

Queued a Read at Time 0(Location 1, Length 100)

Current Time: 0

Enter the command [time delay, command, location, length]: 75,W,500,10

Queued a Write at Time 75 (Location 500, Length 10)

Current Time: 75

Enter the command [time delay, command, location, length]: 200,W,1,10

Queued a Write at Time 275 (Location 1, and Length 10)

Time 100: completed Read started at Time 0 (Location 1, Length 100)

Time 130: completed Write started at Time 100 (Location 500, Length 10)

Current Time: 275

Enter the command [time delay, command, location, length]: 5,R,3,5

Queued a Read at Time 280 (Location 3, and Length 5)

Time 280: completed Read started at Time 275 (Location 3, Length 5)

Current Time: 280

Enter the command [time delay, command, location, length]: 30,R,100,50

Queued a Read at Time 310 (Location 100, and Length 50)

Time 305: completed Write started at Time 275 (Location 1, Length 10)

Current Time: 310

Enter the command [time delay, command, location, length]: 20,W,1,50

Queued a Write at Time 330, (Location 1, Length 50)

Current Time: 330

Enter the command [time delay, command, location, length]: 5,R,75,10

Queued a Read at Time 335, (Location 75, Length 10)

Current Time: 335

Enter the command [time delay, command, location, length]: 5,R,10,100

Queued a Read at Time 340, (Location 10, Length 100)

Current Time: 340

Enter the command [time delay, command, location, length]: 1000,D,0,0

Finishing Simulation at Time 1340

Time 360: completed Read started at Time 310, (Location 100, Length 50)

Time 370: completed Read started at Time 360, (Location 70, Length 10)

Time 520: completed Write started at Time 370, (Location 1, Length 50)

Time 620: completed Read started at Time 520, (Location 10, Length 100)

Time 1340: Simulation Done

Again (Y/n): N

Notice: writes take three times as long as reads and reads are serviced before writes (read queued at time 335 completes before write queued at time 330).

Notice: the read which overlapped the write (read at time 340, write at time 330) was not serviced first.

Notice: a read that was completely contained by a write that had been queued earlier but had not yet completed (read at time 280, write at time 275) was serviced immediately from the write buffer.

Notice: although the sample did not show it, you still must program the 500 ms maximum wait for a write


Last Modified:- 1999, February 11, 03:38 PM by M. Smith