Posted by M1KU5H Tue 27th Mar 2007 16:53 - Syntax is Java - 62 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
/**
-
* DiskSchedulerSSTF.java - shortest-seek-time-first disk scheduler
-
* @author Mikolaj Pukrop
-
*/
-
-
-
/**
-
* this class extends DiskSchedulerFIFO to implement a shortest-seek-time-first
-
* scheduling algorithm.
-
*/
-
public class DiskSchedulerSSTF extends DiskSchedulerFIFO implements DiskScheduler
-
{
-
-
private int last_cyl = 0; // last cylinder accessed
-
private int max_cyl = 0; // maximum cylinder value
-
-
/**
-
* called to initialise the disk scheduler
-
*
-
* @param ddev underlying disk-device
-
*/
-
public void initScheduler (DiskDevice ddev)//{{{
-
{
-
/* initialise the DiskSchedulerFIFO */
-
super.initScheduler (ddev);
-
int[] cylinders = ddev.getGeom();
-
-
max_cyl = cylinders[0];
-
}
-
//}}}
-
-
-
/**
-
* called to dispatch a request immediately -- directly to the disk-device
-
*
-
* @param req request to dispatch
-
*/
-
protected synchronized void scheduleRequestNow (DSRequest req)//{{{
-
{
-
/* dispatch the request immediately */
-
super.scheduleRequestNow (req);
-
int[] cylinderNo = ddev.getCHS(req.blk);
-
last_cyl = cylinderNo[0];
-
-
}
-
//}}}
-
-
-
/**
-
* callback to indicate that a previously dispatched request (to the underlying disk device)
-
* has been serviced
-
*/
-
protected synchronized void completedRequest ()//{{{
-
{
-
super.completedRequest();
-
if (rq_count > 0)
-
{
-
/* have more requests pending, so dispatch one immediately */
-
DSRequest req = request_queue[0];
-
int[] cylNo = ddev.getCHS(req.blk);
-
int firstCyl = cylNo[0];
-
for (int reqPos = 1; reqPos < request_queue.length; reqPos++)
-
{
-
DSRequest req2 = request_queue[reqPos];
-
int[] nextCylNo = ddev.getCHS(req2.blk);
-
int nextCyl = nextCylNo[0];
-
int distance = (firstCyl - last_cyl);
-
int distance2 = (nextCyl - last_cyl);
-
if (distance < distance2)
-
{
-
req = req2;
-
firstCyl = nextCyl;
-
request_queue[reqPos] = null;
-
}
-
-
}
-
-
scheduleRequestNow(req);
-
}
-
else
-
{
-
/* else that's one less pending request */
-
ddev_pending--;
-
}
-
-
ddev.setDSchedStr("" + ddev_pending + " pending, RQ " + rq_count + "/" + QUEUESIZE);
-
}
-
//}}}
-
}
-
-
-
PermaLink to this entry https://pastebin.co.uk/12290
Posted by M1KU5H Tue 27th Mar 2007 16:53 - Syntax is Java - 62 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0