Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 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 /*            if(entry11 == NULL)
  23.  947             {
  24.  948                 entry11 = entry;
  25.  949                 continue;
  26.  950             }*/
  27.  951            
  28.  952             //Second Chance
  29.  953            
  30.  954             //found a 00 frame first pass
  31.  955             //found a 10 frame second pass
  32.  956             if((!entry->use) && (!entry->dirty))
  33.  957             {
  34.  958                 if(entry00 == NULL)
  35.  959                 {
  36.  960                     entry00 = entry;
  37.  961                 }  
  38.  962                 //tie breaker by last time ran on CPU
  39.  963                 else if(entry00->getTime() > entry->getTime())
  40.  964                 {
  41.  965                     entry00 = entry;
  42.  966                 }  
  43.  967             }  
  44.  968             //ref bit is 1 in first pass, so reset and ignore
  45.  969             //never true in second pass
  46.  970             else if(entry->use)
  47.  971             {
  48.  972                 entry->clearSC();
  49.  973             }  
  50.  974             //frame is 01 first pass
  51.  975             //frame is 11 second pass
  52.  976             else
  53.  977             {
  54.  978                 if(entry11 == NULL)
  55.  979                 {
  56.  980                     entry11 = entry;
  57.  981                 }
  58.  982                 else if(entry11->getTime() > entry->getTime())
  59.  983                 {
  60.  984                     entry11 = entry;
  61.  985                 }
  62.  986             }
  63.  987
  64.  988         }
  65.  989         //we have a 00 (or 10 after second pass), so we're done
  66.  990         if(entry00 != NULL)
  67.  991         {
  68.  992             return entry00->physicalPage;
  69.  993         }
  70.  994         else
  71.  995         {
  72.  996             if(pass == 0)
  73.  997             {
  74.  998                 //save 01 frames
  75.  999                 //entry11 will track 11 frames on next pass
  76. 1000                 entry01 = entry11;
  77. 1001                 pass++;
  78. 1002             }
  79. 1003             else
  80. 1004             {
  81. 1005                 pass++;
  82. 1006             }
  83. 1007         }
  84. 1008     }
  85. 1009     //no 00 or 10 frames in list
  86. 1010
  87. 1011     //we have a 01 frame
  88. 1012     if(entry01 != NULL)
  89. 1013     {
  90. 1014         return entry01->physicalPage;
  91. 1015     }
  92. 1016     //otherwise return the 11 frame
  93. 1017     else
  94. 1018     {
  95. 1019         return entry11 == NULL ? 0 : entry11->physicalPage;
  96. 1020     }
  97. 1021 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement