示例#1
0
文件: vmsim.cpp 项目: mfso1991/vmsim
int main(int argc, char **argv)
{
	if(argc != 6 && argc != 8)
	{
		cout << "Error: invalid command!\nPlease use ./vmsim –n <numframes> -a <opt|clock|aging|lru> [-r <refresh>] <tracefile>" << endl;
		return 0;
	}
	
	unsigned int nframes; 	/** # of Frames **/
	if(sscanf(argv[2], "%u", &nframes) == -1 || (nframes & (nframes - 1)) || nframes > 64)		/** x &(x-1) produces 0 if x is of the form 2^n. **/ 
	{														
		cout << "Error: invalid argument for frame numbers!\nPlease use 8, 16, 32, or 64 instead." << endl;
		return 0;
	}
	
	string alg(argv[4]); 	/** Algorithm **/
	
	if(alg == "aging")
	{
		unsigned int period; /** Refreshing Period **/
		sscanf(argv[6], "%u", &period);
		run_aging(argv[7], nframes, period); 	/** will be using a priority deque to simulate the physical memory. **/
	}
	else
	{
		if(alg == "opt")
			run_optimal(argv[5], nframes);		/** will be using an unordered_set to simulate the physical memory. **/
		else if(alg == "clock")
			run_clock(argv[5], nframes); 		/** will be using a doubly-linked list to simulate the physical memory. **/
		else if(alg == "lru")
			run_lru(argv[5], nframes);   		/** will be using a stack to simulate the physical memory. **/
		else
		{
			cout << "Error: unrecognised algorithm.\nPlease use opt, clock, aging, or lru instead." << endl;
			return 0;
		}
	}
	
	cout << "\n\nAlgorithm:\t" << alg << endl;
	cout << "Number of frames:\t" << nframes << endl;
	cout << "Total memory accesses:\t" << total_accesses << endl;
	cout << "Total page faults:\t" << page_fault_count << endl;
	cout << "Total writes to disk:\t" << write_to_disk_count << "\n\n" << endl;
	
	return 0;
}
示例#2
0
redraw(void)
{
  /* erase warning line if necessary */
  if ((warntimer <= udcounter) && (warncount > 0))
    {
      /* XFIX */
      W_ClearArea(warnw, 5, 5, W_Textwidth * warncount, W_Textheight);
      warncount = 0;
    }

  run_clock(lastread);         /* for hosers who don't know
              * * * what a Xclock is */
  clearLocal();

#ifdef BEEPLITE
  if (tts_timer)
    {
      static int last_width;

      tts_timer--;
      if (!tts_timer)
  {
    /* timed out */
    W_EraseTTSText(w, TWINSIDE, tts_pos, last_width);
    last_width = 0;
  }
      else if (tts_timer == tts_time - 1 && last_width)
  {
    /* first draw -- erase previous */
    W_EraseTTSText(w, TWINSIDE, tts_pos, last_width);
    /* draw new */
    W_WriteTTSText(w, TWINSIDE, tts_pos, tts_width, lastIn,
       tts_len);
    last_width = tts_width;
  }
      else
  {
    /* regular draw */
    W_WriteTTSText(w, TWINSIDE, tts_pos, tts_width, lastIn, tts_len);
    last_width = tts_width;
  }
    }
#endif

  local();           /* redraw local window */

  /* XFIX */
  W_FlushLineCaches(w);

  if (newDashboard)        /* 6/2/93 LAB */
    if (newDashboard == old_db)
      db_redraw(0);
    else
      redrawTstats();
  else if (newDashboard == old_db)
    stline(0);
  else
    redrawTstats();

  old_db = newDashboard;

  if (W_IsMapped(statwin))
    updateStats();

  /* XFIX: last since its least accurate information */
  map();
}
示例#3
0
redraw()
{
    /* erase warning line if necessary */
    if ((warntimer <= udcounter) && (warncount > 0)) {
	W_ClearArea(warnw, 5, 5, W_Textwidth * warncount, W_Textheight, backColor);
	warncount = 0;
    }

    if (W_FastClear) {
	W_ClearWindow(w);
	clearcount=0;
	clearlcount=0;
    } else {
	/* TSH 2/10/93 */
	while (clearcount) {
	    clearcount--;
	    W_CacheClearArea(w, clearzone[0][clearcount], 
		clearzone[1][clearcount],
		clearzone[2][clearcount], clearzone[3][clearcount]);
	}
	while (clearlcount) {
	    clearlcount--;
	    W_CacheLine(w, clearline[0][clearlcount], clearline[1][clearlcount],
		clearline[2][clearlcount], clearline[3][clearlcount],
		backColor);
	}
	W_FlushClearAreaCache(w);
	W_FlushLineCaches(w);

	while (mclearlcount){
	    mclearlcount--;
	    W_CacheLine(mapw, mclearline[0][mclearlcount], 
		mclearline[1][mclearlcount], mclearline[2][mclearlcount], 
		mclearline[3][mclearlcount],
		backColor);
	}
	while (mclearpcount){
	    mclearpcount--;
	    W_CachePoint(mapw, mclearpoint[0][mclearpcount], 
		mclearpoint[1][mclearpcount], backColor);
	}
	W_FlushLineCaches(mapw);
	W_FlushPointCaches(mapw);
    }

    local();	/* redraw local window */

    if (mapmode) map();

    if (W_IsMapped(statwin)){
	updateStats();
    }

    /* need a status line but we'll make do with the bottom of the local
       display for now */
    if(runclock)
       run_clock(1);	/* isae */
    if(record)
      show_record(1);
    if(playback)
      show_playback(1);

    if(playback && extracting)
       show_extracting(extracting); /* 7/27/93 BM */

    /* W_Flush(); */
}