Exemple #1
0
void page_fault_handler( struct page_table *pt, int page )
{
    page_faults++;
    //printf("page fault on page #%d\n", page);

    int frame, bits;
    page_table_get_entry(pt, page, &frame, &bits);

    if(has_read(bits)) {
        //printf("page #%d was written to\n", page);
        page_table_set_entry(pt, page, frame, bits|PROT_WRITE);

        // DEBUG
        // page_table_print(pt);
        // sleep(1);

        return;
    }

    int unused_frame = next_unused_frame(pt);
    if (unused_frame != NO_UNUSED_FRAMES) {
        //printf("frame #%d is unused\n", unused_frame);
        swap_page(pt, page, unused_frame);
    } else {
        page_algo_handler(pt, page);
    }

    // DEBUG
    // page_table_print(pt);
    // sleep(1);
}
void tpreferences::pre_show(CVideo& /*video*/, twindow& window)
{
	options_grid_ = find_widget<tstacked_widget>(&window, "options", false, true);

	swap_page(window, start_page_, false);

	// Setup campaign list.
	tlistbox& list = find_widget<tlistbox>(&window, "option_list", false);

	list.set_callback_value_change(dialog_callback3<tpreferences, tlistbox, &tpreferences::page_selected>);

	
	for (int index = 0; index <= MAX_PAGE; index ++) {
		// Add list item
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		if (index == GENERAL_PAGE) { 
			list_item["label"] = "icons/icon-general.png";
			list_item_item.insert(std::make_pair("icon", list_item));
			list_item["label"] = _("Prefs section^General");
			list_item_item.insert(std::make_pair("name", list_item));

		} else if (index == DISPLAY_PAGE) {
			list_item["label"] = "icons/icon-display.png";
			list_item_item.insert(std::make_pair("icon", list_item));
			list_item["label"] = _("Prefs section^Display");
			list_item_item.insert(std::make_pair("name", list_item));

		} else if (index == MUSIC_PAGE) {
			list_item["label"] = "icons/icon-music.png";
			list_item_item.insert(std::make_pair("icon", list_item));
			list_item["label"] = _("Prefs section^Sound");
			list_item_item.insert(std::make_pair("name", list_item));

		} else if (index == ADVANCED_PAGE) {
			list_item["label"] = "icons/icon-advanced.png";
			list_item_item.insert(std::make_pair("icon", list_item));
			list_item["label"] = _("Advanced section^Advanced");
			list_item_item.insert(std::make_pair("name", list_item));
		} else if (index == SCENARIO_PAGE) {
			if (!disp_.in_theme() || !resources::controller) {
				continue;
			}
			list_item["label"] = "icons/icon-scenario.png";
			list_item_item.insert(std::make_pair("icon", list_item));
			list_item["label"] = _("Prefs section^Scenario");
			list_item_item.insert(std::make_pair("name", list_item));

		} 

		list.add_row(list_item_item);
	}
}
Exemple #3
0
void custom_handler(struct page_table *pt, int page) {
    int i, frame, bits,
        nframes = page_table_get_nframes(pt),
        rand_count = MAX(1, nframes * CUST_RAND_PCT / 100),
        rand_frames[rand_count];

    for (i = 0; i < rand_count; ++i) {
        rand_frames[i] = lrand48() % nframes;
    }

    for (i = 0; i < rand_count; ++i) {
        page_table_get_entry(pt, ft[rand_frames[i]], &frame, &bits);
        if (!has_write(bits)) {
            swap_page(pt, page, frame);
            return;
        }
    }

    swap_page(pt, page, frame);
}
Exemple #4
0
void texample2::pre_show(CVideo& /*video*/, twindow& window)
{
	// set backgroup image.
	window.canvas()[0].set_variable("background_image",	variant("dialogs/default-background.png"));

	// prepare navigate bar.
	std::vector<std::string> labels;
	labels.push_back(_("Chat"));
	labels.push_back(_("Preferences"));

	navigate_ = find_widget<treport>(&window, "navigate", false, true);
	navigate_->tabbar_init(true, "dusk_tab");
	navigate_->set_boddy(find_widget<twidget>(&window, "main_panel", false, true));
	int index = 0;
	for (std::vector<std::string>::const_iterator it = labels.begin(); it != labels.end(); ++ it) {
		tcontrol* widget = navigate_->create_child(null_str, null_str, reinterpret_cast<void*>(index ++));
		widget->set_label(*it);
		navigate_->insert_child(*widget);
	}
	navigate_->select(start_page_);
	navigate_->replacement_children();

	page_panel_ = find_widget<tstacked_widget>(&window, "main_layers", false, true);
	swap_page(window, start_page_, false);

	// preferences grid
	ttoggle_button* toggle = find_widget<ttoggle_button>(&window, "fullscreen_button", false, true);

#if (defined(__APPLE__) && TARGET_OS_IPHONE) || defined(ANDROID)
	toggle->set_visible(twidget::INVISIBLE);
	find_widget<tbutton>(&window, "video_mode_button", false).set_visible(twidget::INVISIBLE);

#else
	toggle->set_callback_state_change(boost::bind(&texample2::fullscreen_toggled, this, _1));
	toggle->set_value(preferences::fullscreen());

	connect_signal_mouse_left_click(
		find_widget<tbutton>(&window, "video_mode_button", false)
		, boost::bind(
			&texample2::video_mode_button
			, this
			, boost::ref(window)));
#endif

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "change_language_button", false)
			, boost::bind(
				&texample2::set_retval
				, this
				, boost::ref(window)
				, (int)CHANGE_LANGUAGE));
}
Exemple #5
0
void texample2::toggle_report(twidget* widget)
{
	treport* report = treport::get_report(widget);
	if (report != navigate_) {
		// tchat_ has private tabbar, let tchat_ process them.
		tchat_::toggle_report(widget);
		return;
	}
	int page = (int)reinterpret_cast<long>(widget->cookie());
	swap_page(*widget->get_window(), page, true);

	tdialog::toggle_report(widget);
}
Exemple #6
0
void tgame_load::pre_show(CVideo& /*video*/, twindow& window)
{
	find_widget<tminimap>(&window, "minimap", false).set_config(&cache_config_);

	sheet_.insert(std::make_pair(LOCAL_PAGE, find_widget<ttoggle_button>(&window, "local", false, true)));
	sheet_.insert(std::make_pair(NETWORK_PAGE, find_widget<ttoggle_button>(&window, "network", false, true)));
	for (std::map<int, ttoggle_button*>::iterator it = sheet_.begin(); it != sheet_.end(); ++ it) {
		it->second->set_callback_state_change(boost::bind(&tgame_load::sheet_toggled, this, _1));
		it->second->set_data(it->first);
	}

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "delete", false)
			, boost::bind(
				  &tgame_load::delete_button_callback
				, this
				, boost::ref(window)));

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "xmit", false)
			, boost::bind(
				  &tgame_load::xmit_button_callback
				, this
				, boost::ref(window)));

	savegame_list_ = find_widget<tlistbox>(&window, "savegame_list", false, true);
	sheet_.begin()->second->set_value(true);

	swap_page(window, LOCAL_PAGE, false);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(*list, boost::bind(
				  &tgame_load::list_item_clicked
				, *this
				, boost::ref(window)));
#else
	savegame_list_->set_callback_value_change(
			dialog_callback<tgame_load, &tgame_load::list_item_clicked>);
#endif


	if (disp_.in_game()) {
		find_widget<tbutton>(&window, "xmit", false).set_visible(twidget::INVISIBLE);
		find_widget<ttoggle_button>(&window, "local", false).set_visible(twidget::INVISIBLE);
		find_widget<ttoggle_button>(&window, "network", false).set_visible(twidget::INVISIBLE);
	}
}
Exemple #7
0
void tgame_load::sheet_toggled(twidget* widget)
{
	ttoggle_button* toggle = dynamic_cast<ttoggle_button*>(widget);
	int toggled_page = toggle->get_data();

	if (!toggle->get_value()) {
		// At most select one page. recheck it!
		toggle->set_value(true);
	} else {
		for (std::map<int, ttoggle_button*>::iterator it = sheet_.begin(); it != sheet_.end(); ++ it) {
			if (it->second == toggle) {
				continue;
			}
			it->second->set_value(false);
		}
		swap_page(*toggle->get_window(), toggled_page, true);
	}
}
Exemple #8
0
void tgame_load::pre_show(CVideo& /*video*/, twindow& window)
{
	find_widget<tminimap>(&window, "minimap", false).set_config(&cache_config_);

	sheet_.insert(std::make_pair(LOCAL_PAGE, find_widget<ttoggle_button>(&window, "local", false, true)));
	sheet_.insert(std::make_pair(NETWORK_PAGE, find_widget<ttoggle_button>(&window, "network", false, true)));
	for (std::map<int, ttoggle_button*>::iterator it = sheet_.begin(); it != sheet_.end(); ++ it) {
		it->second->set_callback_state_change(boost::bind(&tgame_load::sheet_toggled, this, _1));
		it->second->set_data(it->first);
	}

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "delete", false)
			, boost::bind(
				  &tgame_load::delete_button_callback
				, this
				, boost::ref(window)));

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "xmit", false)
			, boost::bind(
				  &tgame_load::xmit_button_callback
				, this
				, boost::ref(window)));

	page_panel_ = find_widget<tstacked_widget>(&window, "savegame_list", false, true);
	lists_.push_back(find_widget<tlistbox>(&window, "local_list", false, true));
	lists_.push_back(find_widget<tlistbox>(&window, "network_list", false, true));
	for (std::vector<tlistbox*>::const_iterator it = lists_.begin(); it != lists_.end(); ++ it) {
		tlistbox& list = **it;
		list.set_callback_value_change(dialog_callback3<tgame_load, tlistbox, &tgame_load::list_item_clicked>);
	}

	sheet_.begin()->second->set_value(true);

	swap_page(window, LOCAL_PAGE, false);

	if (!allow_network_) {
		find_widget<tbutton>(&window, "xmit", false).set_visible(twidget::INVISIBLE);
		find_widget<ttoggle_button>(&window, "local", false).set_visible(twidget::INVISIBLE);
		find_widget<ttoggle_button>(&window, "network", false).set_visible(twidget::INVISIBLE);
	}
}
void tpreferences::page_selected(twindow& window, tlistbox& list, const int type)
{
	page_ = list.get_selected_row();

	swap_page(window, page_, true);
}
Exemple #10
0
void fifo_handler(struct page_table *pt, int page) {
    swap_page(pt, page, fi++ % page_table_get_nframes(pt));
}
Exemple #11
0
void rand_handler(struct page_table *pt, int page) {
    // Get page of random frame from ft
    int frame = lrand48() % page_table_get_nframes(pt);
    swap_page(pt, page, frame);
}
void pageit(Pentry q[MAXPROCESSES]) { 
    
    /* This file contains the stub for a predictive pager */
    /* You may need to add/remove/modify any part of this file */

    /* Static vars */
    static int initialized = 0;
    static int tick = 1; // artificial time
    static int timestamps[MAXPROCESSES][MAXPROCPAGES]; //help with LRU
    static int hotpage[MAXPROCESSES][MAXPROCPAGES]; //help choosing new page
    static int repeats[MAXPROCESSES][MAXPROCPAGES]; //predict repeating pages
    static int repeatset[MAXPROCESSES][MAXPROCPAGES]; //when to update repeats    
    static int preceeds[MAXPROCESSES][MAXPROCPAGES][MAXPROCPAGES]; //frequency of what comes after what
    static int proc_status[MAXPROCESSES];
    static int predictions[MAXPROCESSES][MAXPROCPAGES];
    static int goodpredict = 0;
    static int miss = 0;
    
    /* Local vars */
 //   int hotpage[MAXPROCESSES][MAXPROCPAGES]; //help choosing new page
 //   int repeatset[MAXPROCESSES][MAXPROCPAGES]; //when to update repeats   
 //   int repeats[MAXPROCESSES][MAXPROCPAGES]; //predict repeating pages
 //   int preceeds[MAXPROCESSES][MAXPROCPAGES][MAXPROCPAGES]; //frequency of what comes after what
  //  int serieslength = 5;
    int series[MAXPROCESSES][serieslength];
    int seriescount[MAXPROCESSES] = { 0 };
    int seriesfull[MAXPROCESSES] = { 0 };
    int proctmp, pagetmp, proc, pc, page, pagepred, nextpg, lastproc, lastpage;  
    int procactive = 0;
    //btw none of these are actually static rn
    int activeq[MAXPROCESSES];
    int goodpredictor[MAXPROCESSES][4] = { { 0 } }; //maybe add a proc dimension
    int bestoption = 0;
    static int missrate[MAXPROCESSES]; //reset every 10 or so...
    static int hitrate[MAXPROCESSES]; //same
    int successrate[MAXPROCESSES];
    static int repeatcount[MAXPROCESSES];
    static int samepage[MAXPROCESSES];
    static int currentpredictor[MAXPROCESSES] = { 1 };
    static int prevpredictor[MAXPROCESSES] = { 1 };
    int prevpage[MAXPROCESSES] = { -1 };
    int prevpred[MAXPROCESSES] = { -1 };
  //  static int pagelock[MAXPROCESSES][MAXPROCPAGES];
	int current;
	static int prediction[MAXPROCESSES][MAXPROCPAGES];
	
    /* initialize static vars on first run */
    if(!initialized){
	/* Init complex static vars here */
	for(proctmp=0; proctmp < MAXPROCESSES; proctmp++){
		missrate[proctmp] = 0;
		hitrate[proctmp] = 0;
		repeatcount[proctmp] = 0;
		samepage[proctmp] = 0;
		proc_status[proctmp] = 0;
	    for(pagetmp=0; pagetmp < MAXPROCPAGES; pagetmp++){
			prediction[proctmp][pagetmp] = 0;
			timestamps[proctmp][pagetmp] = 0; 
			hotpage[proctmp][pagetmp] = 0;
			repeats[proctmp][pagetmp] = 0;
			repeatset[proctmp][pagetmp] = 0;
		//	pagelock[proctmp][pagetmp] = 0;
			for(nextpg=0; nextpg < MAXPROCPAGES; nextpg++){
				preceeds[proctmp][pagetmp][nextpg] = 0;
			}
	    }
	}	
	initialized = 1;
    }
    
    /* TODO: Implement Predictive Paging */
    //init prediction helpers
   
   	for(proctmp=0; proctmp < MAXPROCESSES; proctmp++){
	    for(pagetmp=0; pagetmp < MAXPROCPAGES; pagetmp++){
		//	hotpage[proctmp][pagetmp] = 0;
		//	repeatset[proctmp][pagetmp] = 0;
		//	repeats[proctmp][pagetmp] = 0;
		//	for(nextpg=0; nextpg < MAXPROCPAGES; nextpg++){
		//		preceeds[proctmp][pagetmp][nextpg] = 0;
		//	}		
			if(pagetmp < serieslength)
				series[proctmp][pagetmp] = -1;
	    }
	}	
   
    //select process
    for(proctmp = 0; proctmp < MAXPROCESSES; proctmp++){
		//find active processes and update 
		if(q[proctmp].active){
			activeq[procactive] = proctmp;
			procactive++;
			page = q[proctmp].pc / PAGESIZE;
			timestamps[proctmp][page] = tick;
		}
		else { //swap out any unactive pages
			for(pagetmp = 0; pagetmp < MAXPROCPAGES; pagetmp++){
				if(q[proctmp].pages[pagetmp])
					pageout(proctmp,pagetmp);
			}
		}
	}
	lastproc = 0;
	lastpage = 0;
	int i, j;
	//all active processes
    for(i = 0; i < procactive; i++){
		proc = activeq[i];
		pc = q[proc].pc;
		page = pc / PAGESIZE; //determine current page
		
		//printf("previous proccess %d and previous page %d\n", lastproc, lastpage);
		//printf("current process %d and current page %d\n", proc, page);
		prediction[proc][page] = 0;
		
		if(prevpred[proc] != -1 && page != prevpred[proc]){
			//printf("MISS: current page: %d, previously predicted: %d\n", page, prevpred[proc]);
			miss++;
			missrate[proc]++;
		//	pagelock[proc][prevpred[proc]] = 0;
			goodpredictor[proc][prevpredictor[proc]-1]--;
		}
		else if(page == prevpred[proc]){
			// printf("HIT: current page: %d, previously predicted: %d\n", page, prevpred[proc]);
			 goodpredict++;
			 hitrate[proc]++;
			 goodpredictor[proc][prevpredictor[proc]-1]++; 
		//	 pagelock[proc][page] = 1;
		}
		successrate[proc] = hitrate[proc] - missrate[proc];
	//	printf("success rate: %d\n", successrate[proc]);
		
		//update other pages for LRU
		for(pagetmp = 0; pagetmp < MAXPROCPAGES; pagetmp++){
			timestamps[proc][pagetmp]++;
		}
		//and reset the counter for most recent 
		timestamps[proc][page] = 0;		
		
		//update hotness for choosing a new page
		/*
		if(hotpage[proc][page] > 150){ //hot cap
			for(pagetmp = 0; pagetmp < MAXPROCPAGES; pagetmp++)
				hotpage[proc][pagetmp] = 0;
			hotpage[proc][page] = 5;
		}	
		else hotpage[proc][page]++;
		*/
		hotpage[proc][page]++;
		//update repeats for predicting sequential calls
		if(page == prevpage[proc]){
			if(!repeatset[proc][page]){
				samepage[proc]++;
				repeats[proc][page] = samepage[proc];
			}
			repeatcount[proc]++;
		}
		else if(repeats[proc][prevpage[proc]] > 0){
			repeatset[proc][prevpage[proc]] = 1;
			if(repeats[proc][prevpage[proc]] > 6){ 
				repeats[proc][prevpage[proc]] = 0;
				repeatset[proc][prevpage[proc]] = 0;	
			}
			samepage[proc] = 0;
			repeatcount[proc] = 0;
		}
		//printf("current page: %d repeats %d times\n", page, repeats[proc][page]);	
	
		//update preceeds
		if(prevpage[proc] != -1){
			preceeds[proc][prevpage[proc]][page]++;
			/*
			if(preceeds[proc][prevpage[proc]][page] > 100){
				//reset the frequencies 
				for(pagetmp=0; pagetmp < MAXPROCPAGES; pagetmp++){
					for(nextpg=0; nextpg < MAXPROCPAGES; nextpg++){
						preceeds[proc][pagetmp][nextpg] = 0;
					}	
				preceeds[proc][prevpage[proc]][page] = 5;
				}	
			}
			*/
		//	printf("page %d preceeds %d with frequency of: %d\n", prevpage[proc], page, preceeds[proc][prevpage[proc]][page]); 
		}
	
		//update the series
		if(seriescount[proc] < serieslength){
			series[proc][seriescount[proc]] = page;
			seriescount[proc]++;
			if(seriescount[proc] == serieslength){
				seriescount[proc] = 0;
				seriesfull[proc] = 1;
			}
		}
		else{ //series if full, is it working or not...
			if(successrate[proc] < -1){ //nope - start a new one
				for(pagetmp = 0; pagetmp < MAXPROCPAGES; pagetmp++){
					for(j = 0; j < serieslength; j++){
						series[proc][j] = -1;
					}
				}
				seriescount[proc] = 0;
				seriesfull[proc] = 0;
			}
			//or don't change it
		}
		
		//how's the current method doing
		if(successrate[proc] >= 0){ //good enough	
			//maybe prevpredictor == currentpredictor...
			if(currentpredictor[proc] == 1)
				pagepred = predict_hot(proc, hotpage);	
			else if(currentpredictor[proc] == 2)
				pagepred = predict_repeats(proc, page, repeatcount, repeats);
			else if(currentpredictor[proc] == 3 && seriescount[proc] < serieslength)
				pagepred = predict_series(proc, series, seriescount);
			else
				pagepred = predict_preceeds(proc, page, preceeds);
		}
		if(successrate[proc] < 0){
			//make prediction method decisions here
			if(bestoption <= 5){
				int stop = 0;
				for(pagetmp = 0; (pagetmp < MAXPROCPAGES) && !stop; pagetmp++){
					if(preceeds[proc][page][pagetmp] > 30){
						currentpredictor[proc] = 4; //better chances here
						stop = 1; 
					}
				}
				for(pagetmp = 0; (pagetmp < MAXPROCPAGES) && !stop; pagetmp++){
					if(hotpage[proc][pagetmp] > 50){
						currentpredictor[proc] = 1; //maybe there's a hot page to swap
						stop = 1;
					}
				}
				if(repeats[proc][page] > 1 && !stop){
					 currentpredictor[proc] = 2;
					 stop = 1;
				}
				else if(seriesfull[proc] == 1 && !stop){
					currentpredictor[proc] = 3;
					stop = 1;
				}
				bestoption = goodpredictor[proc][j];
			}
			else{
				for(j = 0; j < 4; j++){
					if(goodpredictor[proc][j] > bestoption){
						bestoption = goodpredictor[proc][j];
						currentpredictor[proc] = j+1;
					}
				}
				if(bestoption > 20){
					for(j = 0; j < 4; j++)
						goodpredictor[proc][j] = 0;
					goodpredictor[proc][j] = 2;
					bestoption = 0;
				}
			}
		//	printf("current best predictor is %d with score %d\n", currentpredictor[proc], bestoption);
			currentpredictor[proc] = 4;
			if(currentpredictor[proc] == 1)
				pagepred = predict_hot(proc, hotpage);
			else if(currentpredictor[proc] == 2)
				pagepred = predict_repeats(proc, page, repeatcount, repeats);
			else if(currentpredictor[proc] == 3 && seriescount[proc] < serieslength)
				pagepred = predict_series(proc, series, seriescount);		
			else
				pagepred = predict_preceeds(proc, page, preceeds);
		}
		//printf("current method: %d\n", currentpredictor[proc]);
		prevpredictor[proc] = currentpredictor[proc];
		timestamps[proc][pagepred] = 0;
		
		if(!q[proc].pages[page]){
			current = 1;		
			swap_page(q, timestamps, proc, page, current, hotpage, prediction);
		}
		if(successrate[proc] >= 20){
			int evictpage, outproc, least;
			nextpg = page;
			for(j = 0; j < 5; j++){
				least = 0;
				for(pagetmp = 0; pagetmp < MAXPROCPAGES; pagetmp++){
					if(!q[proc].pages[pagetmp]) //cant evict page thats not in
						continue;
					if(timestamps[proc][pagetmp] > least){
						least = timestamps[proc][pagetmp];
						evictpage = pagetmp;
						outproc = proc;
					//	hotness = hotpage[proctmp][pagetmp];
					//	printf("current LRU timestamp = %d\n", least);
					}

				}
				//call pageout()
				if(q[outproc].pages[evictpage]){ //can only evict page thats in
					pageout(outproc, evictpage);				
				}
				
				nextpg = predict_preceeds(proc, nextpg, preceeds);
				swap_page(q, timestamps, proc, nextpg, current, hotpage, prediction);
			}
		}
		lastproc = proc;
		lastpage = page;
		prevpage[proc] = page;
		prevpred[proc] = pagepred;
	}
    /* advance time for next pageit iteration */
    tick++;
	//printf("miss count: %d, good predictions: %d\n", miss, goodpredict);
}