Posted by M1KU5H Tue 27th Mar 2007 16:53 - Syntax is Java - 62 views
Download | New Post | Modify | Hide line numbers
  1. /**
  2. *    DiskSchedulerSSTF.java - shortest-seek-time-first disk scheduler
  3. *    @author Mikolaj Pukrop
  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.         if (rq_count > 0)
  57.         {
  58.             /* have more requests pending, so dispatch one immediately */
  59.             DSRequest req = request_queue[0];
  60.             int[] cylNo = ddev.getCHS(req.blk);
  61.             int firstCyl = cylNo[0];
  62.         for (int reqPos = 1; reqPos < request_queue.length; reqPos++)
  63.         {
  64.             DSRequest req2 = request_queue[reqPos];
  65.             int[] nextCylNo = ddev.getCHS(req2.blk);
  66.             int nextCyl = nextCylNo[0];
  67.             int distance = (firstCyl - last_cyl);
  68.             int distance2 = (nextCyl - last_cyl);
  69.         if (distance < distance2)
  70.         {
  71.                 req = req2;
  72.                 firstCyl = nextCyl;
  73.                 request_queue[reqPos] = null;
  74.         }
  75.  
  76.         }
  77.  
  78.             scheduleRequestNow(req);
  79.         }
  80.         else
  81.         {
  82.             /* else that's one less pending request */
  83.             ddev_pending--;
  84.         }
  85.  
  86.         ddev.setDSchedStr("" + ddev_pending + " pending, RQ " + rq_count + "/" + QUEUESIZE);
  87.     }
  88.     //}}}
  89. }
  90.  
  91.  
  92.  

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

 

Comments: 0