Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.84 KB | None | 0 0
  1.  925 int AddrSpace::SC_Choose_Victim (int notMe) {
  2.  926     TranslationEntry *entry = NULL;
  3.  927     TranslationEntry *entry00 = NULL;
  4.  928     TranslationEntry *entry01 = NULL;
  5.  929     TranslationEntry *entry11 = NULL;
  6.  930
  7.  931     //variable for extra pass
  8.  932     int pass = 0;
  9.  933     unsigned int i = 0;
  10.  934     while(pass < 2)
  11.  935     {
  12.  936         for(i = 0; i < numPages; i++)
  13.  937         {
  14.  938             entry = get_page_ptr(i);
  15.  939
  16.  940             //not valid, or a page to ignore
  17.  941             if(!entry->valid || entry->physicalPage == (unsigned int)notMe)
  18.  942             {
  19.  943                 continue;
  20.  944             }
  21.  945
  22.  946             //Second Chance
  23.  947
  24.  948             //found a 00 frame first pass
  25.  949             //found a 10 frame second pass
  26.  950             if((!entry->use) && (!entry->dirty))
  27.  951             {
  28.  952                 if(entry00 == NULL)
  29.  953                 {
  30.  954                     entry00 = entry;
  31.  955                 }
  32.  956                 //tie breaker by last time ran on CPU
  33.  957                 else
  34.  958                 {
  35.  959                     if(entry00->getTime() > entry->getTime())
  36.  960                     {
  37.  961                         entry00 = entry;
  38.  962                     }
  39.  963                 }
  40.  964             }
  41.  965             //ref bit is 1 in first pass, so reset and ignore
  42.  966             //never true in second pass
  43.  967             else if(entry->use)
  44.  968             {
  45.  969                 entry->clearSC();
  46.  970             }
  47.  971             //frame is 01 first pass
  48.  972             //frame is 11 second pass
  49.  973             else
  50.  974             {
  51.  975                 if(entry11 == NULL)
  52.  976                 {
  53.  977                     entry11 = entry;
  54.  978                 }
  55.  979                 else if(entry11->getTime() > entry->getTime())
  56.  980                 {
  57.  981                     entry11 = entry;
  58.  925 int AddrSpace::SC_Choose_Victim (int notMe) {
  59.  926     TranslationEntry *entry = NULL;
  60.  927     TranslationEntry *entry00 = NULL;
  61.  928     TranslationEntry *entry01 = NULL;
  62.  929     TranslationEntry *entry11 = NULL;
  63.  930
  64.  931     //variable for extra pass
  65.  932     int pass = 0;
  66.  933     unsigned int i = 0;
  67.  934     while(pass < 2)
  68.  935     {
  69.  936         for(i = 0; i < numPages; i++)
  70.  937         {
  71.  938             entry = get_page_ptr(i);
  72.  939
  73.  940             //not valid, or a page to ignore
  74.  941             if(!entry->valid || entry->physicalPage == (unsigned int)notMe)
  75.  942             {
  76.  943                 continue;
  77.  944             }
  78.  945
  79.  946             //Second Chance
  80.  947
  81.  948             //found a 00 frame first pass
  82.  949             //found a 10 frame second pass
  83.  950             if((!entry->use) && (!entry->dirty))
  84.  951             {
  85.  952                 if(entry00 == NULL)
  86.  953                 {
  87.  954                     entry00 = entry;
  88.  955                 }
  89.  956                 //tie breaker by last time ran on CPU
  90.  957                 else
  91.  958                 {
  92.  959                     if(entry00->getTime() > entry->getTime())
  93.  960                     {
  94.  961                         entry00 = entry;
  95.  962                     }
  96.  963                 }
  97.  964             }
  98.  965             //ref bit is 1 in first pass, so reset and ignore
  99.  966             //never true in second pass
  100.  967             else if(entry->use)
  101.  968             {
  102.  969                 entry->clearSC();
  103.  970             }
  104.  971             //frame is 01 first pass
  105.  972             //frame is 11 second pass
  106.  973             else
  107.  974             {
  108.  975                 if(entry11 == NULL)
  109.  976                 {
  110.  977                     entry11 = entry;
  111.  978                 }
  112.  979                 else if(entry11->getTime() > entry->getTime())
  113.  980                 {
  114.  981                     entry11 = entry;
  115.  982                 }
  116.  983             }
  117.  984
  118.  985         }
  119.  986         //we have a 00 (or 10 after second pass), so we're done
  120.  987         if(entry00 != NULL)
  121.  988         {
  122.  989             return entry00->physicalPage;
  123.  990         }
  124.  991         else
  125.  992         {
  126.  993             if(pass == 0)
  127.  994             {
  128.  995                 //save 01 frames
  129.  996                 //entry11 will track 11 frames on next pass
  130.  997                 entry01 = entry11;
  131.  998                 pass++;
  132.  999             }
  133. 1000             else
  134. 1001             {
  135. 1002                 pass++;
  136. 1003             }
  137. 1004         }
  138. 1005     }
  139. 1006     //no 00 or 10 frames in list
  140. 1007
  141. 1008     //we have a 01 frame
  142. 1009     if(entry01 != NULL)
  143. 1010     {
  144. 1011         return entry01->physicalPage;
  145. 1012     }
  146. 1013     //otherwise return the 11 frame
  147. 1014     else
  148. 1015     {
  149. 1016         return entry11 == NULL ? 0 : entry11->physicalPage;
  150. 1017     }
  151. 1018 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement