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 //Second Chance
- 947
- 948 //found a 00 frame first pass
- 949 //found a 10 frame second pass
- 950 if((!entry->use) && (!entry->dirty))
- 951 {
- 952 if(entry00 == NULL)
- 953 {
- 954 entry00 = entry;
- 955 }
- 956 //tie breaker by last time ran on CPU
- 957 else
- 958 {
- 959 if(entry00->getTime() > entry->getTime())
- 960 {
- 961 entry00 = entry;
- 962 }
- 963 }
- 964 }
- 965 //ref bit is 1 in first pass, so reset and ignore
- 966 //never true in second pass
- 967 else if(entry->use)
- 968 {
- 969 entry->clearSC();
- 970 }
- 971 //frame is 01 first pass
- 972 //frame is 11 second pass
- 973 else
- 974 {
- 975 if(entry11 == NULL)
- 976 {
- 977 entry11 = entry;
- 978 }
- 979 else if(entry11->getTime() > entry->getTime())
- 980 {
- 981 entry11 = entry;
- 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 //Second Chance
- 947
- 948 //found a 00 frame first pass
- 949 //found a 10 frame second pass
- 950 if((!entry->use) && (!entry->dirty))
- 951 {
- 952 if(entry00 == NULL)
- 953 {
- 954 entry00 = entry;
- 955 }
- 956 //tie breaker by last time ran on CPU
- 957 else
- 958 {
- 959 if(entry00->getTime() > entry->getTime())
- 960 {
- 961 entry00 = entry;
- 962 }
- 963 }
- 964 }
- 965 //ref bit is 1 in first pass, so reset and ignore
- 966 //never true in second pass
- 967 else if(entry->use)
- 968 {
- 969 entry->clearSC();
- 970 }
- 971 //frame is 01 first pass
- 972 //frame is 11 second pass
- 973 else
- 974 {
- 975 if(entry11 == NULL)
- 976 {
- 977 entry11 = entry;
- 978 }
- 979 else if(entry11->getTime() > entry->getTime())
- 980 {
- 981 entry11 = entry;
- 982 }
- 983 }
- 984
- 985 }
- 986 //we have a 00 (or 10 after second pass), so we're done
- 987 if(entry00 != NULL)
- 988 {
- 989 return entry00->physicalPage;
- 990 }
- 991 else
- 992 {
- 993 if(pass == 0)
- 994 {
- 995 //save 01 frames
- 996 //entry11 will track 11 frames on next pass
- 997 entry01 = entry11;
- 998 pass++;
- 999 }
- 1000 else
- 1001 {
- 1002 pass++;
- 1003 }
- 1004 }
- 1005 }
- 1006 //no 00 or 10 frames in list
- 1007
- 1008 //we have a 01 frame
- 1009 if(entry01 != NULL)
- 1010 {
- 1011 return entry01->physicalPage;
- 1012 }
- 1013 //otherwise return the 11 frame
- 1014 else
- 1015 {
- 1016 return entry11 == NULL ? 0 : entry11->physicalPage;
- 1017 }
- 1018 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement