Beispiel #1
0
void
schedule(void) {
    bool intr_flag;
    struct proc_struct *next;
    local_intr_save(intr_flag);
    {
	cprintf("\n++++++ CURRENT PID = %d ++++++\n", current->pid);
        cprintf("++++++ IN SCHEDULE() ++++++\n");
        current->need_resched = 0;
        if (current->state == PROC_RUNNABLE) {
            cprintf("++++++ CURRENT PID = %d RUNNABLE, CALL ENQUEUE ++++++\n", current->pid);
            sched_class_enqueue(current);
        }
        if ((next = sched_class_pick_next()) != NULL) {
            cprintf("++++++ NEXT PID = %d TO RUN, CALL DEQUEUE ++++++\n", next->pid);
            sched_class_dequeue(next);
        }
        if (next == NULL) {
            next = idleproc;
        }
        next->runs ++;
        if (next != current) {
            proc_run(next);
        }
    }
    local_intr_restore(intr_flag);
}
Beispiel #2
0
void
schedule(void) {
    bool intr_flag;
    struct proc_struct *next;
    local_intr_save(intr_flag);
    {
        current->need_resched = 0;
        if (current->state == PROC_RUNNABLE) {
            cprintf("Timer finished for process pid = %d and push in the queue\n",current->pid);
            sched_class_enqueue(current);
        }
        if ((next = sched_class_pick_next()) != NULL) {
            cprintf("Picks process pid = %d to run and pop from the queue\n",next->pid);
            sched_class_dequeue(next);
        }
        if (next == NULL) {
            cprintf("No runnable process.\n");
            next = idleproc;
        }
        next->runs ++;
        if (next != current) {
            proc_run(next);
        }
    }
    local_intr_restore(intr_flag);
}
Beispiel #3
0
void schedule(void)
{
	bool intr_flag;
	struct proc_struct *next;
	local_intr_save(intr_flag);
	{
		current->need_resched = 0;
		if (current->state == PROC_RUNNABLE)
		{
			sched_class_enqueue(current);
		}
		if ((next = sched_class_pick_next()) != NULL)
		{
			sched_class_dequeue(next);
		}
		if (next == NULL)
		{
			next = idleproc;
		}
		next->runs++;
		if (next != current)
		{
			proc_run(next);
		}
	}
	local_intr_restore(intr_flag);
}
Beispiel #4
0
void
schedule(void) { // 这个用来分配进程的运行
	cprintf("\n==> schedule\n");
    bool intr_flag;
    struct proc_struct *next;
    local_intr_save(intr_flag);
    {
        current->need_resched = 0;
        if (current->state == PROC_RUNNABLE) { // 标记为可以运行
            sched_class_enqueue(current); // 将当前进程放入就绪队列
        }
        if ((next = sched_class_pick_next()) != NULL) { // 选出优先级最高的一个进程
            sched_class_dequeue(next);
        }
        if (next == NULL) {
            next = idleproc; // 如果没有找到就绪的进程,那么继续运行自己
        }
        next->runs ++;
        if (next != current) {
            proc_run(next); // 开始运行
        }
    }
    local_intr_restore(intr_flag);
}
Beispiel #5
0
void
schedule(void) {
  /* schedule in irq ctx is not allowed */
  assert(!ucore_in_interrupt());
  bool intr_flag;
  struct proc_struct *next;
#ifndef MT_SUPPORT
  list_entry_t head;
  int lapic_id = pls_read(lapic_id);
#endif

  local_intr_save(intr_flag);
  int lcpu_count = pls_read(lcpu_count);
  {
    current->need_resched = 0;
#ifndef MT_SUPPORT
    if (current->mm)
    {
      assert(current->mm->lapic == lapic_id);
      current->mm->lapic = -1;
    }
#endif
    if (current->state == PROC_RUNNABLE && current->pid >= lcpu_count) {
      sched_class_enqueue(current);
    }
#ifndef MT_SUPPORT
    list_init(&head);
    while (1)
    {
      next = sched_class_pick_next();
      if (next != NULL) sched_class_dequeue(next);

      if (next && next->mm && next->mm->lapic != -1)
      {
        list_add(&head, &(next->run_link));
      }
      else
      {
        list_entry_t *cur;
        while ((cur = list_next(&head)) != &head)
        {
          list_del_init(cur);
          sched_class_enqueue(le2proc(cur, run_link));
        }

        break;
      }
    }
#else
    next = sched_class_pick_next();
    if (next != NULL)
      sched_class_dequeue(next);
#endif  /* !MT_SUPPORT */
    if (next == NULL) {
      next = idleproc;
    }
    next->runs ++;
    /* Collect information here*/
    if (sched_collect_info) {
      int lcpu_count = pls_read(lcpu_count);
      int lcpu_idx = pls_read(lcpu_idx);
      int loc = sched_info_head[lcpu_idx];
      int prev = sched_info_pid[loc*lcpu_count + lcpu_idx];
      if (next->pid == prev)
        sched_info_times[loc*lcpu_count + lcpu_idx] ++;
      else {
        sched_info_head[lcpu_idx] ++;
        if (sched_info_head[lcpu_idx] >= PGSIZE / sizeof(uint16_t) / lcpu_count)
          sched_info_head[lcpu_idx] = 0;
        loc = sched_info_head[lcpu_idx];
        uint16_t prev_pid = sched_info_pid[loc*lcpu_count + lcpu_idx];
        uint16_t prev_times = sched_info_times[loc*lcpu_count + lcpu_idx];
        if (prev_times > 0 && prev_pid >= lcpu_count + 2)
          sched_slices[lcpu_idx][prev_pid % SLICEPOOL_SIZE] += prev_times;
        sched_info_pid[loc*lcpu_count + lcpu_idx] = next->pid;
        sched_info_times[loc*lcpu_count + lcpu_idx] = 1;
      }
    }
#ifndef MT_SUPPORT
    assert(!next->mm || next->mm->lapic == -1);
    if (next->mm)
      next->mm->lapic = lapic_id;
#endif
    if (next != current) {
#if 0
      kprintf("N %d to %d\n", current->pid, next->pid);
#endif
      proc_run(next);
    }
  }
  local_intr_restore(intr_flag);
}