Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 925 int AddrSpace::SC_Choose_Victim (int notMe) {
- 926 TranslationEntry *entry = NULL;
- 927 TranslationEntry *entry00 = NULL;
- 928 TranslationEntry *entry01 = NULL;
- 929 TranslationEntry *entry11 = NULL;
- 930
- 931 //variable for extra pass
- 932 int pass = 0;
- 933 unsigned int i = 0;
- 934 while(pass < 2)
- 935 {
- 936 for(i = 0; i < numPages; i++)
- 937 {
- 938 entry = get_page_ptr(i);
- 939
- 940 //not valid, or a page to ignore
- 941 if(!entry->valid || entry->physicalPage == (unsigned int)notMe)
- 942 {
- 943 continue;
- 944 }
- 945
- 946 /* if(entry11 == NULL)
- 947 {
- 948 entry11 = entry;
- 949 continue;
- 950 }*/
- 951
- 952 //Second Chance
- 953
- 954 //found a 00 frame first pass
- 955 //found a 10 frame second pass
- 956 if((!entry->use) && (!entry->dirty))
- 957 {
- 958 if(entry00 == NULL)
- 959 {
- 960 entry00 = entry;
- 961 }
- 962 //tie breaker by last time ran on CPU
- 963 else if(entry00->getTime() > entry->getTime())
- 964 {
- 965 entry00 = entry;
- 966 }
- 967 }
- 968 //ref bit is 1 in first pass, so reset and ignore
- 969 //never true in second pass
- 970 else if(entry->use)
- 971 {
- 972 entry->clearSC();
- 973 }
- 974 //frame is 01 first pass
- 975 //frame is 11 second pass
- 976 else
- 977 {
- 978 if(entry11 == NULL)
- 979 {
- 980 entry11 = entry;
- 981 }
- 982 else if(entry11->getTime() > entry->getTime())
- 983 {
- 984 entry11 = entry;
- 985 }
- 986 }
- 987
- 988 }
- 989 //we have a 00 (or 10 after second pass), so we're done
- 990 if(entry00 != NULL)
- 991 {
- 992 return entry00->physicalPage;
- 993 }
- 994 else
- 995 {
- 996 if(pass == 0)
- 997 {
- 998 //save 01 frames
- 999 //entry11 will track 11 frames on next pass
- 1000 entry01 = entry11;
- 1001 pass++;
- 1002 }
- 1003 else
- 1004 {
- 1005 pass++;
- 1006 }
- 1007 }
- 1008 }
- 1009 //no 00 or 10 frames in list
- 1010
- 1011 //we have a 01 frame
- 1012 if(entry01 != NULL)
- 1013 {
- 1014 return entry01->physicalPage;
- 1015 }
- 1016 //otherwise return the 11 frame
- 1017 else
- 1018 {
- 1019 return entry11 == NULL ? 0 : entry11->physicalPage;
- 1020 }
- 1021 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement