tac0S
Template Affectional Command Operating System
Public Member Functions | List of all 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). More...

#include <disk.h>

Public Member Functions

 Disk (const char *name, VoidFunctionPtr callWhenDone, int callArg)
 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. More...
 
 ~Disk ()
 Disk::~Disk() Clean up disk simulation, by closing the UNIX file representing the disk.
 
void ReadRequest (int sectorNumber, char *data)
 Disk::ReadRequest/WriteRequest Simulate a request to read/write a single disk sector Do the read/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. More...
 
void WriteRequest (int sectorNumber, char *data)
 
void HandleInterrupt ()
 Disk::HandleInterrupt() Called when it is time to invoke the disk interrupt handler, to tell the Nachos kernel that the disk request is done.
 
int ComputeLatency (int newSector, bool writing)
 Disk::ComputeLatency() Return how long will it take to read/write a disk sector, from the current position of the disk head. 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

Constructor & Destructor Documentation

Disk::Disk ( const char *  name,
VoidFunctionPtr  callWhenDone,
int  callArg 
)

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.

Parameters
name– text name of the file simulating the Nachos disk
callWhenDone– interrupt handler to be called when disk read/write request completes
callArg– argument to pass the interrupt handler

Member Function Documentation

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

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.

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

Disk::ReadRequest/WriteRequest Simulate a request to read/write a single disk sector Do the read/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 read/written, not part of a sector.

Parameters
sectorNumber– the disk sector to read/write
data– the bytes to be written, the buffer to hold the incoming bytes

The documentation for this class was generated from the following files: