Posted by Anonymous Tue 27th Mar 2007 17:37 - Syntax is Java - 63 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
/**
-
* DiskSchedulerSSTF.java - shortest-seek-time-first disk scheduler
-
* @author
-
*/
-
-
-
/**
-
* 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();
-
int cylPosition = 0;
-
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;
-
cylPosition = reqPos;
-
}
-
-
}
-
rq_count--;
-
if (rq_count > 0) {
-
if (cylPosition < (rq_count))
-
{
-
.arraycopy (request_queue, cylPosition+1, request_queue, cylPosition, rq_count-cylPosition);
-
}
-
else
-
{
-
.arraycopy (request_queue, 0, request_queue, 0, rq_count);
-
}
-
}
-
-
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/12291
Posted by Anonymous Tue 27th Mar 2007 17:37 - Syntax is Java - 63 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0