SHARE
TWEET

Untitled

a guest Apr 8th, 2019 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void enqueue(
  2.   register struct proc *rp  /* this process is now runnable */
  3. )
  4. {
  5. /* Add 'rp' to one of the queues of runnable processes.  This function is
  6.  * responsible for inserting a process into one of the scheduling queues.
  7.  * The mechanism is implemented here.   The actual scheduling policy is
  8.  * defined in sched() and pick_proc().
  9.  *
  10.  * This function can be used x-cpu as it always uses the queues of the cpu the
  11.  * process is assigned to.
  12.  */
  13.   int q = rp->p_priority;           /* scheduling queue to use */
  14.   struct proc **rdy_head, **rdy_tail;
  15.  
  16.   assert(proc_is_runnable(rp));
  17.  
  18.   assert(q >= 0);
  19.  
  20.   rdy_head = get_cpu_var(rp->p_cpu, run_q_head);
  21.   rdy_tail = get_cpu_var(rp->p_cpu, run_q_tail);
  22.  
  23.   /* Now add the process to the queue. */
  24.   if (!rdy_head[q]) {       /* add to empty queue */
  25.       rdy_head[q] = rdy_tail[q] = rp;       /* create a new queue */
  26.       rp->p_nextready = NULL;       /* mark new end */
  27.   }
  28.   else {                    /* add to tail of queue */
  29.       rdy_tail[q]->p_nextready = rp;        /* chain tail of queue */  
  30.       rdy_tail[q] = rp;             /* set new queue tail */
  31.       rp->p_nextready = NULL;       /* mark new end */
  32.   }
  33.  
  34.   if (cpuid == rp->p_cpu) {
  35.       /*
  36.        * enqueueing a process with a higher priority than the current one,
  37.        * it gets preempted. The current process must be preemptible. Testing
  38.        * the priority also makes sure that a process does not preempt itself
  39.        */
  40.       struct proc * p;
  41.       p = get_cpulocal_var(proc_ptr);
  42.       assert(p);
  43.       if((p->p_priority > rp->p_priority) &&
  44.               (priv(p)->s_flags & PREEMPTIBLE))
  45.           RTS_SET(p, RTS_PREEMPTED); /* calls dequeue() */
  46.   }
  47. #ifdef CONFIG_SMP
  48.   /*
  49.    * if the process was enqueued on a different cpu and the cpu is idle, i.e.
  50.    * the time is off, we need to wake up that cpu and let it schedule this new
  51.    * process
  52.    */
  53.   else if (get_cpu_var(rp->p_cpu, cpu_is_idle)) {
  54.       smp_schedule(rp->p_cpu);
  55.   }
  56. #endif
  57.  
  58.   /* Make note of when this process was added to queue */
  59.   read_tsc_64(&(get_cpulocal_var(proc_ptr)->p_accounting.enter_queue));
  60.  
  61.  
  62. #if DEBUG_SANITYCHECKS
  63.   assert(runqueues_ok_local());
  64. #endif
  65. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top