Просмотр исходного кода

Fix del problema con current_pid

Agustín Cangiani 10 лет назад
Родитель
Сommit
0f2798dcf0
3 измененных файлов с 16 добавлено и 20 удалено
  1. 5 0
      Makefile
  2. 11 19
      sched_sjf.cpp
  3. 0 1
      sched_sjf.h

+ 5 - 0
Makefile

@@ -60,5 +60,10 @@ ejercicio9: all makedir
 	./simusched ejer2.tsk 1 2 99 SchedRR 1 10 | ./graphsched.py > informe/imagenes/ejercicio9_1core_10q.png
 =======
 ejercicio7: all makedir
+<<<<<<< 0fa9b6957eeab616ae3171be3d9667bbfc21917d
 	./simusched ejer7-sjf.tsk 1 2 99 SchedSJF 1 15 10 5
 >>>>>>> Ejercicio 7
+=======
+	./simusched ejer7-sjf.tsk 1 2 99 SchedSJF 1 15 10 5  | ./graphsched.py > informe/imagenes/ejercicio7_1core.png
+	./simusched ejer7-sjf.tsk 2 2 99 SchedSJF 2 15 10 5  | ./graphsched.py > informe/imagenes/ejercicio7_2core.png
+>>>>>>> Fix del problema con current_pid

+ 11 - 19
sched_sjf.cpp

@@ -6,15 +6,12 @@
 using namespace std;
 
 SchedSJF::SchedSJF(vector<int> argn) {
-    // Recibe la cantidad de cores 
-    cout << "Constructor SchedSJF \n";
+    /* Constructor SchedSJF: Recibe la cantidad de cores */
     nucleos = argn[1];
-	firstTick=true;
 
     for (uint i = 2; i < argn.size(); i++) {
         // Cargamos los procesos con un id y una duration
         uint duration = argn[i];
-        //cout << "Loadinggg " << i-2 << " " << duration << "\n";
         p_map[i - 2].duration = duration; 
 	}
 }
@@ -32,27 +29,16 @@ void SchedSJF::load(int pid) {
 void SchedSJF::unblock(int pid) {
     /* SchedSJF solo corre tasks del tipo TaskCPU, entonces no 
     hay acciones especificadas para este método. */
-    cout << "Unblock process with " << pid;
+    cout << "Unblock process con " << pid;
 }
 
 int SchedSJF::tick(int cpu, const enum Motivo m) {
-    /* motivo TICK / BLOCK / EXIT / IDLE_TASK */
     uint cur_pid = current_pid(cpu);
-	if (firstTick){ //FIXME
-		cur_pid=0;
-		firstTick=false;
-	}
 
-    cout << "Inicio tick: cpu " << cpu << " motivo " << m << " curr_pid " << cur_pid << "\n";
-    if (m == TICK) {
-        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;
-    } else {
-        // Caso donde m == EXIT
+    if (cur_pid == IDLE_TASK || m == EXIT) {
+        // Caso donde m == EXIT o cpu IDLE
         if (!pq.empty()) {
+            // Hay más tareas para ejecutar
             int next_pid = pq.top().pid;
             pq.pop();
             return next_pid;
@@ -60,5 +46,11 @@ int SchedSJF::tick(int cpu, const enum Motivo m) {
             // No hay más tareas encoladas, devolver IDLE
             return IDLE_TASK;
         }
+    } else if (m == TICK) {
+        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;
     }
 }

+ 0 - 1
sched_sjf.h

@@ -30,7 +30,6 @@ class SchedSJF : public SchedBase {
 			}	
 		};
 
-		bool firstTick;
 		std::map<int, Process> p_map;  // Mapeo de los procesos
 		typedef std::map<int,Process>::iterator it_type;