Exemple #1
0
/*
* wake_up() is called for a new process and when an I/O request completes.
* The current implementation handles basic FIFO scheduling by simply
* marking the process as READY, and calling addReadyProcess to put it in the
* ready queue.  No locks are needed to set the process state as its not possible
* for anyone else to also access it at the same time as wake_up
*
* TO-DO: If the scheduling algorithm is static priority, wake_up() may need
* to preempt the CPU with the lowest priority process to allow it to
* execute the process which just woke up.  However, if any CPU is
* currently running idle, or all of the CPUs are running processes
* with a higher priority than the one which just woke up, wake_up()
* should not preempt any CPUs. To preempt a process, use force_preempt().
* Look in os-sim.h for its prototype and parameters.
*
* THIS FUNCTION IS PARTIALLY COMPLETED - REQUIRES MODIFICATION
*/
extern void wake_up(pcb_t* process) {
  int i, lowest, low_id;
  process->state = PROCESS_READY;
  addReadyProcess(process);
  // loop for processes to evict if static priority mode
  if (alg == StaticPriority) {
    pthread_mutex_lock(&current_mutex);
    low_id = -1;
    lowest = 10;
    // loop through all CPUs
    for (i = 0; i < cpu_count; i++) {
      /* if find IDLE, stop looking */
      if (current[i] == NULL) {
        low_id = -1;
        break;
      }
      // grab the lowest priority available
      if (current[i]->static_priority < lowest) {
        lowest = current[i]->static_priority;
        low_id = i;
      }
    }
    pthread_mutex_unlock(&current_mutex);
    // evict the process if found and lower priority than our process
    if (low_id != -1 && lowest < process->static_priority) {
      force_preempt(low_id);
    }
  }
}
Exemple #2
0
/*
 * wake_up() is the handler called by the simulator when a process's I/O
 * request completes.  It should perform the following tasks:
 *
 *   1. Mark the process as READY, and insert it into the ready queue.
 *
 *   2. If the scheduling algorithm is static priority, wake_up() may need
 *      to preempt the CPU with the lowest priority process to allow it to
 *      execute the process which just woke up.  However, if any CPU is
 *      currently running idle, or all of the CPUs are running processes
 *      with a higher priority than the one which just woke up, wake_up()
 *      should not preempt any CPUs.
 *	To preempt a process, use force_preempt(). Look in os-sim.h for 
 * 	its prototype and the parameters it takes in.
 */
extern void wake_up(pcb_t *process)
{

    // insert into ready_q
    ready_q_push(process);

    // check if the priority of the process is higher than any of
    // the running processes
    if (use_priority) {
        for (int i = 0; i < cpu_count; i++) {
            if (!current[i] || 
                current[i]->static_priority < process->static_priority) {
                force_preempt(i);
            }
        }
    }
}