|
|
@@ -3,23 +3,83 @@
|
|
|
using namespace std;
|
|
|
|
|
|
SchedRSJF::SchedRSJF(vector<int> argn) {
|
|
|
- // Recibe la cantidad de cores y sus cpu_quantum por parámetro
|
|
|
-/* llenar */
|
|
|
+ /* Constructor SchedRSJF: Recibe la cantidad de
|
|
|
+ cores, sus cpu_quantum y el tiempo de los procesos
|
|
|
+ por parámetro. */
|
|
|
+ nucleos = argn[1];
|
|
|
+ quantums = new uint[nucleos];
|
|
|
+
|
|
|
+ for (uint i = 2; i < argn.size(); i++) {
|
|
|
+ if ((i-2) < nucleos) {
|
|
|
+ // Cargamos los Quantums de cada core
|
|
|
+ quantums[i - 2] = argn[i];
|
|
|
+ } else {
|
|
|
+ // Cargamos los procesos con un id y una duration
|
|
|
+ uint duration = argn[i];
|
|
|
+ p_map[i - 2 - nucleos].duration = duration;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
SchedRSJF::~SchedRSJF() {
|
|
|
-/* llenar */
|
|
|
+ p_map.clear(); // Limpiamos el mapeo de procesos
|
|
|
+ while (!pq.empty()) pq.pop(); // Clean the priority queue
|
|
|
+ delete[] quantums;
|
|
|
}
|
|
|
|
|
|
void SchedRSJF::load(int pid) {
|
|
|
-/* llenar */
|
|
|
+ uint duration = p_map[pid].duration; // Get Process duration
|
|
|
+ pq.push(Process{pid, duration}); // Push the Process to the priority queue
|
|
|
}
|
|
|
|
|
|
void SchedRSJF::unblock(int pid) {
|
|
|
-/* llenar */
|
|
|
+ /* SchedRSJF solo corre tasks del tipo TaskCPU, entonces no
|
|
|
+ hay acciones especificadas para este método. */
|
|
|
+ cout << "Unblock process con " << pid;
|
|
|
+}
|
|
|
+
|
|
|
+int SchedRSJF::next_process(int cur_pid) {
|
|
|
+ p_map[cur_pid].quantum_count = 0; // Limpiamos los quantums usados
|
|
|
+ uint duration = p_map[cur_pid].duration;
|
|
|
+
|
|
|
+ pq.push(Process{cur_pid, duration}); // Encolamos con prioridad
|
|
|
+
|
|
|
+ int next_pid = pq.top().pid; // Obtenemos el siguiente proceso
|
|
|
+ pq.pop();
|
|
|
+
|
|
|
+ return next_pid;
|
|
|
}
|
|
|
|
|
|
int SchedRSJF::tick(int core, const enum Motivo m) {
|
|
|
-/* llenar */
|
|
|
- return 0;
|
|
|
+ uint cur_pid = current_pid(core);
|
|
|
+
|
|
|
+ if (cur_pid == IDLE_TASK || m == EXIT) {
|
|
|
+ // Caso donde m == EXIT o core IDLE
|
|
|
+ if (!pq.empty()) {
|
|
|
+ // Hay más tareas para ejecutar
|
|
|
+ int next_pid = pq.top().pid;
|
|
|
+ pq.pop();
|
|
|
+ return next_pid;
|
|
|
+ } else {
|
|
|
+ // No hay más tareas encoladas, devolver IDLE
|
|
|
+ return IDLE_TASK;
|
|
|
+ }
|
|
|
+ } else if (m == TICK) {
|
|
|
+ p_map[cur_pid].duration -= 1; // Decrementamos la duration del proceso
|
|
|
+ p_map[cur_pid].quantum_count++; // Incrementamos el quantum del proceso
|
|
|
+
|
|
|
+ if (p_map[cur_pid].quantum_count >= quantums[core]) {
|
|
|
+ /* Switch de proceso por desalojo, por otro lado duration
|
|
|
+ siempre va a ser igual o mayor a 1, porque hubiera devuelto
|
|
|
+ EXIT y no TICK */
|
|
|
+ int next_pid = next_process(cur_pid);
|
|
|
+ return next_pid;
|
|
|
+ } else {
|
|
|
+ return cur_pid; // El proceso esta corriendo
|
|
|
+ }
|
|
|
+ } else if (m ==BLOCK) {
|
|
|
+ // Proceso con estado BLOCK, no sucede en este scheduler
|
|
|
+ // pero si pasa lo esperamos hasta que termine
|
|
|
+ return cur_pid;
|
|
|
+ }
|
|
|
}
|