Posted by Anonymous Tue 27th Mar 2007 17:37 - Syntax is Java - 63 views
Download | New Post | Modify | Hide line numbers
  1. /**
  2. *    DiskSchedulerSSTF.java - shortest-seek-time-first disk scheduler
  3. *    @author
  4. */
  5.  
  6.  
  7. /**
  8. * this class extends DiskSchedulerFIFO to implement a shortest-seek-time-first
  9. * scheduling algorithm.
  10. */
  11. public class DiskSchedulerSSTF extends DiskSchedulerFIFO implements DiskScheduler
  12. {
  13.  
  14.     private int last_cyl = 0;            // last cylinder accessed
  15.     private int max_cyl = 0;            // maximum cylinder value
  16.  
  17.     /**
  18.      * called to initialise the disk scheduler
  19.      *
  20.      * @param ddev underlying disk-device
  21.      */
  22.     public void initScheduler (DiskDevice ddev)//{{{
  23.     {
  24.         /* initialise the DiskSchedulerFIFO */
  25.         super.initScheduler (ddev);
  26.         int[] cylinders = ddev.getGeom();
  27.  
  28.         max_cyl = cylinders[0];
  29.     }
  30.     //}}}
  31.  
  32.  
  33.     /**
  34.      * called to dispatch a request immediately -- directly to the disk-device
  35.      *
  36.      * @param req request to dispatch
  37.      */
  38.     protected synchronized void scheduleRequestNow (DSRequest req)//{{{
  39.     {
  40.         /* dispatch the request immediately */
  41.         super.scheduleRequestNow (req);
  42.         int[] cylinderNo = ddev.getCHS(req.blk);
  43.         last_cyl = cylinderNo[0];
  44.  
  45.     }
  46.     //}}}
  47.  
  48.  
  49.     /**
  50.      * callback to indicate that a previously dispatched request (to the underlying disk device)
  51.      * has been serviced
  52.      */
  53.     protected synchronized void completedRequest ()//{{{
  54.     {
  55.         super.completedRequest();
  56.         int cylPosition = 0;
  57.         if (rq_count > 0)
  58.         {
  59.             /* have more requests pending, so dispatch one immediately */
  60.             DSRequest req = request_queue[0];
  61.             int[] cylNo = ddev.getCHS(req.blk);
  62.             int firstCyl = cylNo[0];
  63.         for (int reqPos = 1; reqPos < request_queue.length; reqPos++)
  64.         {
  65.             DSRequest req2 = request_queue[reqPos];
  66.             int[] nextCylNo = ddev.getCHS(req2.blk);
  67.             int nextCyl = nextCylNo[0];
  68.             int distance = (firstCyl - last_cyl);
  69.             int distance2 = (nextCyl - last_cyl);
  70.         if (distance < distance2)
  71.         {
  72.                 req = req2;
  73.                 firstCyl = nextCyl;
  74.                 cylPosition = reqPos;
  75.         }
  76.  
  77.         }
  78.             rq_count--;
  79.             if (rq_count > 0) {
  80.                 if (cylPosition < (rq_count))
  81.                 {
  82.                     .arraycopy (request_queue, cylPosition+1, request_queue, cylPosition, rq_count-cylPosition);
  83.                 }
  84.                 else
  85.                 {
  86.                     .arraycopy (request_queue, 0, request_queue, 0, rq_count);
  87.                 }
  88.             }
  89.  
  90.             scheduleRequestNow(req);
  91.         }
  92.         else
  93.         {
  94.             /* else that's one less pending request */
  95.             ddev_pending--;
  96.         }
  97.  
  98.         ddev.setDSchedStr("" + ddev_pending + " pending, RQ " + rq_count + "/" + QUEUESIZE);
  99.     }
  100.     //}}}
  101. }
  102.  
  103.  
  104.  

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

 

Comments: 0