Пример #1
0
void
test_mlfqs_load_avg (void)
{
  int i;

  ASSERT (thread_mlfqs);

  start_time = timer_ticks ();
  msg ("Starting %d 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, (void *) i);
    }
  msg ("Starting threads took %d seconds.",
       timer_elapsed (start_time) / TIMER_FREQ);
  thread_set_nice (-20);

  for (i = 0; i < 90; i++)
    {
      int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10);
      int load_avg;
      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
static void
load_thread (void *ti_) 
{
  struct thread_info *ti = ti_;
  int64_t sleep_time = 5 * TIMER_FREQ;
  int64_t spin_time = sleep_time + 30 * TIMER_FREQ;
  int64_t last_time = 0;

  thread_set_nice (ti->nice);
  timer_sleep (sleep_time - timer_elapsed (ti->start_time));
  while (timer_elapsed (ti->start_time) < spin_time) 
    {
      int64_t cur_time = timer_ticks ();
      if (cur_time != last_time)
        ti->tick_count++;
      last_time = cur_time;
    }
}
Пример #3
0
static void
test_mlfqs_fair (int thread_cnt, int nice_min, int nice_step)
{
  struct thread_info info[MAX_THREAD_CNT];
  int64_t start_time;
  int nice;
  int i;

  ASSERT (selected_scheduler == SCH_MLFQS);
  ASSERT (thread_cnt <= MAX_THREAD_CNT);
  ASSERT (nice_min >= -10);
  ASSERT (nice_step >= 0);
  ASSERT (nice_min + nice_step * (thread_cnt - 1) <= 20);

  thread_set_nice (-20);

  start_time = timer_ticks ();
  msg ("Starting %d threads...", thread_cnt);
  nice = nice_min;
  for (i = 0; i < thread_cnt; i++) 
    {
      struct thread_info *ti = &info[i];
      char name[16];

      ti->start_time = start_time;
      ti->tick_count = 0;
      ti->nice = nice;

      snprintf(name, sizeof name, "load %d", i);
      thread_create (name, PRI_DEFAULT, load_thread, ti);

      nice += nice_step;
    }
  msg ("Starting threads took %"PRId64" ticks.", timer_elapsed (start_time));

  msg ("Sleeping 40 seconds to let threads run, please wait...");
  timer_sleep (40 * TIMER_FREQ);
  
  for (i = 0; i < thread_cnt; i++)
    msg ("Thread %d received %d ticks.", i, info[i].tick_count);
}
Пример #4
0
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() );
}