Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Disk Class Reference

The following class defines a physical disk I/O device. The disk has a single surface, split up into "tracks", and each track split up into "sectors" (the same number of sectors on each track, and each sector has the same number of bytes of storage). Addressing is by sector number -- each sector on the disk is given a unique number: track * SectorsPerTrack + offset within a track. As with other I/O devices, the raw physical disk is an asynchronous device -- requests to read or write portions of the disk return immediately, and an interrupt is invoked later to signal that the operation completed. The physical disk is in fact simulated via operations on a UNIX file. To make life a little more realistic, the simulated time for each operation reflects a "track buffer" -- RAM to store the contents of the current track as the disk head passes by. The idea is that the disk always transfers to the track buffer, in case that data is requested later on. This has the benefit of eliminating the need for "skip-sector" scheduling -- a read request which comes in shortly after the head has passed the beginning of the sector can be satisfied more quickly, because its contents are in the track buffer. Most disks these days now come with a track buffer. The track buffer simulation can be disabled by compiling with -DNOTRACKBUF. More...

#include <disk.h>

Inheritance diagram for Disk::

CallBackObj List of all members.

Public Methods

 Disk (char *name, CallBackObj *toCall)
 Create a simulated disk. Invoke toCall->CallBack() when each request completes. More...

 ~Disk ()
 Deallocate the disk. More...

void ReadRequest (int sectorNumber, char *data)
 Read a single disk sector. These routines send a request to the disk and return immediately. Only one request allowed at a time! More...

void WriteRequest (int sectorNumber, char *data)
 Write a single disk sector. These routines send a request to the disk and return immediately. Only one request allowed at a time! More...

void CallBack ()
 Invoked when disk request finishes. In turn calls, callWhenDone. More...

int ComputeLatency (int newSector, bool writing)
 Return how long a request to newSector will take: (seek + rotational delay + transfer). More...


Private Methods

int TimeToSeek (int newSector, int *rotate)
 time to get to the new track. More...

int ModuloDiff (int to, int from)
 # sectors between to and from. More...

void UpdateLast (int newSector)

Private Attributes

int fileno
 UNIX file number for simulated disk. More...

CallBackObjcallWhenDone
 Invoke when any disk request finishes. More...

bool active
 Is a disk operation in progress? More...

int lastSector
 The previous disk request. More...

int bufferInit
 When the track buffer started being loaded. More...


Detailed Description

The following class defines a physical disk I/O device. The disk has a single surface, split up into "tracks", and each track split up into "sectors" (the same number of sectors on each track, and each sector has the same number of bytes of storage). Addressing is by sector number -- each sector on the disk is given a unique number: track * SectorsPerTrack + offset within a track. As with other I/O devices, the raw physical disk is an asynchronous device -- requests to read or write portions of the disk return immediately, and an interrupt is invoked later to signal that the operation completed. The physical disk is in fact simulated via operations on a UNIX file. To make life a little more realistic, the simulated time for each operation reflects a "track buffer" -- RAM to store the contents of the current track as the disk head passes by. The idea is that the disk always transfers to the track buffer, in case that data is requested later on. This has the benefit of eliminating the need for "skip-sector" scheduling -- a read request which comes in shortly after the head has passed the beginning of the sector can be satisfied more quickly, because its contents are in the track buffer. Most disks these days now come with a track buffer. The track buffer simulation can be disabled by compiling with -DNOTRACKBUF.

Definition at line 56 of file disk.h.


Constructor & Destructor Documentation

Disk::Disk ( char * name,
CallBackObj * toCall )
 

Create a simulated disk. Invoke toCall->CallBack() when each request completes.

Disk::Disk() Initialize a simulated disk. Open the UNIX file (creating it if it doesn't exist), and check the magic number to make sure it's ok to treat it as Nachos disk storage.

"name" -- text name of the file simulating the Nachos disk "toCall" -- object to call when disk read/write request completes

Definition at line 39 of file disk.cc.

Disk::~Disk ( )
 

Deallocate the disk.

Disk::~Disk() Clean up disk simulation, by closing the UNIX file representing the disk.

Definition at line 71 of file disk.cc.


Member Function Documentation

void Disk::CallBack ( ) [virtual]
 

Invoked when disk request finishes. In turn calls, callWhenDone.

Disk::CallBack() Called by the machine simulation when the disk interrupt occurs.

Reimplemented from CallBackObj.

Definition at line 174 of file disk.cc.

int Disk::ComputeLatency ( int newSector,
bool writing )
 

Return how long a request to newSector will take: (seek + rotational delay + transfer).

Disk::ComputeLatency() Return how long will it take to read/write a disk sector, from the current position of the disk head.

Latency = seek time + rotational latency + transfer time Disk seeks at one track per SeekTime ticks (cf. stats.h) and rotates at one sector per RotationTime ticks

To find the rotational latency, we first must figure out where the disk head will be after the seek (if any). We then figure out how long it will take to rotate completely past newSector after that point.

The disk also has a "track buffer"; the disk continuously reads the contents of the current disk track into the buffer. This allows read requests to the current track to be satisfied more quickly. The contents of the track buffer are discarded after every seek to a new track.

Definition at line 245 of file disk.cc.

Referenced by ReadRequest(), and WriteRequest().

int Disk::ModuloDiff ( int to,
int from ) [private]
 

# sectors between to and from.

Disk::ModuloDiff() Return number of sectors of rotational delay between target sector "to" and current sector position "from"

Definition at line 215 of file disk.cc.

Referenced by ComputeLatency().

void Disk::ReadRequest ( int sectorNumber,
char * data )
 

Read a single disk sector. These routines send a request to the disk and return immediately. Only one request allowed at a time!

Disk::ReadRequest Simulate a request to read a single disk sector Do the read immediately to the UNIX file Set up an interrupt handler to be called later, that will notify the caller when the simulator says the operation has completed.

Note that a disk only allows an entire sector to be read, not part of a sector.

"sectorNumber" -- the disk sector to read

"data" -- the buffer to hold the incoming bytes

Definition at line 113 of file disk.cc.

Referenced by SynchDisk::ReadSector().

int Disk::TimeToSeek ( int newSector,
int * rotate ) [private]
 

time to get to the new track.

Disk::TimeToSeek() Returns how long it will take to position the disk head over the correct track on the disk. Since when we finish seeking, we are likely to be in the middle of a sector that is rotating past the head, we also return how long until the head is at the next sector boundary.

Disk seeks at one track per SeekTime ticks (cf. stats.h) and rotates at one sector per RotationTime ticks

Definition at line 192 of file disk.cc.

Referenced by ComputeLatency(), and UpdateLast().

void Disk::UpdateLast ( int newSector ) [private]
 

Disk::UpdateLast Keep track of the most recently requested sector. So we can know what is in the track buffer.

Definition at line 274 of file disk.cc.

Referenced by ReadRequest(), and WriteRequest().

void Disk::WriteRequest ( int sectorNumber,
char * data )
 

Write a single disk sector. These routines send a request to the disk and return immediately. Only one request allowed at a time!

Disk::WriteRequest Simulate a request to write a single disk sector Do the write immediately to the UNIX file Set up an interrupt handler to be called later, that will notify the caller when the simulator says the operation has completed.

Note that a disk only allows an entire sector to be written, not part of a sector.

"sectorNumber" -- the disk sector to write

"data" -- the bytes to be written

Definition at line 149 of file disk.cc.

Referenced by SynchDisk::WriteSector().


Member Data Documentation

bool Disk::active [private]
 

Is a disk operation in progress?

Definition at line 85 of file disk.h.

int Disk::bufferInit [private]
 

When the track buffer started being loaded.

Definition at line 87 of file disk.h.

CallBackObj * Disk::callWhenDone [private]
 

Invoke when any disk request finishes.

Definition at line 84 of file disk.h.

int Disk::fileno [private]
 

UNIX file number for simulated disk.

Definition at line 83 of file disk.h.

int Disk::lastSector [private]
 

The previous disk request.

Definition at line 86 of file disk.h.


The documentation for this class was generated from the following files:
Generated at Wed Jul 4 11:32:23 2001 for Nachos by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001