示例#1
0
void
test_mlfqs_load_60 (void) 
{
  int i;
  
  ASSERT (thread_mlfqs);

  start_time = timer_ticks ();
  msg ("Starting %d niced load threads...", THREAD_CNT);
  for (i = 0; i < THREAD_CNT; i++) 
    {
      char name[16];
      snprintf(name, sizeof name, "load %d", i);
      thread_create (name, PRI_DEFAULT, load_thread, NULL);
    }
  msg ("Starting threads took %d seconds.",
       timer_elapsed (start_time) / TIMER_FREQ);

  for (i = 0; i < 90; i++) 
    {
      int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10);
      int load_avg;
//printf("LIST NUMBER : %d\n", get_list_size ());
      timer_sleep (sleep_until - timer_ticks ());
      load_avg = thread_get_load_avg ();
      msg ("After %d seconds, load average=%d.%02d.",
           i * 2, load_avg / 100, load_avg % 100);
    }
}
示例#2
0
void
test_mlfqs_load_1 (void) 
{
  int64_t start_time;
  int elapsed;
  int load_avg;
  
  ASSERT (thread_mlfqs);

  msg ("spinning for up to 45 seconds, please wait...");

  start_time = timer_ticks ();
  for (;;) 
    {
      load_avg = thread_get_load_avg ();
      ASSERT (load_avg >= 0);
      elapsed = timer_elapsed (start_time) / TIMER_FREQ;
      if (load_avg > 100)
        fail ("load average is %d.%02d "
              "but should be between 0 and 1 (after %d seconds)",
              load_avg / 100, load_avg % 100, elapsed);
      else if (load_avg > 50)
        break;
      else if (elapsed > 45)
        {
        msg ("load average is %d.%02d ", load_avg / 100, load_avg % 100);
        fail ("load average stayed below 0.5 for more than 45 seconds");
        }
    }

  if (elapsed < 38)
    fail ("load average took only %d seconds to rise above 0.5", elapsed);
  msg ("load average rose to 0.5 after %d seconds", elapsed);

  msg ("sleeping for another 10 seconds, please wait...");
  timer_sleep (TIMER_FREQ * 10);

  load_avg = thread_get_load_avg ();
  if (load_avg < 0)
    fail ("load average fell below 0");
  if (load_avg > 50)
    fail ("load average stayed above 0.5 for more than 10 seconds");
  msg ("load average fell back below 0.5 (to %d.%02d)",
       load_avg / 100, load_avg % 100);

  pass ();
}
示例#3
0
文件: zune-test.c 项目: nakulj/cs-402
void
zune_test (void) 
{
	char name[16] = "thread 1 name";
	int priority = 10;
	
	if (thread_mlfqs)
	{
		printf("mlfqs true\n");
	} else {
		printf("mlfqs false\n");
	}

	printf("Initialized. Calling get ready threads: %d \n", get_ready_threads_count());
	thread_create(name, priority, zune_thread_func, NULL);
	printf("1 Thread Created. Calling get ready threads: %d \n", get_ready_threads_count());
	
	printf("Initialized Load Avg: ");
	print_real(thread_get_load_avg());
	thread_calc_load_avg();
	printf("\nRecalculated Load Avg: ");
	print_real(thread_get_load_avg());

	printf("\nInitialized CPU Load: ");
	print_real( thread_get_recent_cpu() );
	thread_all_calc_recent_cpu();
	printf("\nCalculated CPU Load BEFORE set nice: ");
	print_real( thread_get_recent_cpu() );

	thread_set_nice(2);
	thread_all_calc_recent_cpu();

	printf("\nCalculated CPU Load AFTER set nice 2: ");
	print_real( thread_get_recent_cpu() );

	//thread_set_nice(2);
	thread_all_calc_recent_cpu();

	printf("\nCalculated CPU Load AFTER set nice again: ");
	print_real( thread_get_recent_cpu() );
}
示例#4
0
void
test_mlfqs_recent_1 (void) 
{
  int64_t start_time;
  int last_elapsed = 0;
  
  ASSERT (thread_mlfqs);

  do 
    {
      msg ("current %d", thread_get_recent_cpu () / 100);
      msg ("Sleeping 10 seconds to allow recent_cpu to decay, please wait...");
      start_time = timer_ticks ();
      timer_sleep (DIV_ROUND_UP (start_time, TIMER_FREQ) - start_time
                   + 10 * TIMER_FREQ);
    }
  while (thread_get_recent_cpu () > 700);

  start_time = timer_ticks ();
  for (;;) 
    {
      int elapsed = timer_elapsed (start_time);
      if (elapsed % (TIMER_FREQ * 2) == 0 && elapsed > last_elapsed) 
        {
          int recent_cpu = thread_get_recent_cpu ();
          int load_avg = thread_get_load_avg ();
          int elapsed_seconds = elapsed / TIMER_FREQ;
          msg ("After %d seconds, recent_cpu is %d.%02d, load_avg is %d.%02d.",
               elapsed_seconds,
               recent_cpu / 100, recent_cpu % 100,
               load_avg / 100, load_avg % 100);
          if (elapsed_seconds >= 180)
            break;
        } 
      last_elapsed = elapsed;
    }
}