Advertisement
Guest User

Untitled

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