Explorar el Código

mfq basico.. parece andar

David hace 10 años
padre
commit
a695ec3507
Se han modificado 3 ficheros con 31 adiciones y 3 borrados
  1. 6 0
      Makefile
  2. 23 3
      sched_mfq.cpp
  3. 2 0
      sched_mfq.h

+ 6 - 0
Makefile

@@ -51,3 +51,9 @@ ejercicio5: all makedir
 	./simusched ejer2.tsk 1 2 99 SchedRR 1 02 | ./graphsched.py > informe/imagenes/ejercicio5_1core_02q.png
 	./simusched ejer2.tsk 1 2 99 SchedRR 1 05 | ./graphsched.py > informe/imagenes/ejercicio5_1core_05q.png
 	./simusched ejer2.tsk 1 2 99 SchedRR 1 10 | ./graphsched.py > informe/imagenes/ejercicio5_1core_10q.png
+
+
+ejercicio9: all makedir
+	./simusched ejer2.tsk 1 2 99 SchedRR 1 02 | ./graphsched.py > informe/imagenes/ejercicio9_1core_02q.png
+	./simusched ejer2.tsk 1 2 99 SchedRR 1 05 | ./graphsched.py > informe/imagenes/ejercicio9_1core_05q.png
+	./simusched ejer2.tsk 1 2 99 SchedRR 1 10 | ./graphsched.py > informe/imagenes/ejercicio9_1core_10q.png

+ 23 - 3
sched_mfq.cpp

@@ -44,6 +44,26 @@ uint SchedMFQ::pid_queue(uint pid){
 	return 65535; // ??
 }
 
+int SchedMFQ::ready_at(uint qn){
+	if (v_cola[qn].size() == 0)
+		return -1;
+	for (it_type it = v_cola[qn].begin(); it != v_cola[qn].end(); it++) {
+		if (it->second.state == READY)
+			return it->first;
+	}
+	return -1;
+}
+uint SchedMFQ::next_pid(){
+	for( uint q = 0; q < n_colas; q++ ){
+		int p = ready_at(q);
+		if (p!=-1){
+			return p; //Algun proceso listo
+		}
+	}
+
+	return IDLE_TASK;
+	//return 65535;
+}
 
 int SchedMFQ::tick(int core, const enum Motivo m) {
 	uint switch_process = 0;
@@ -73,8 +93,8 @@ int SchedMFQ::tick(int core, const enum Motivo m) {
 		v_cola[p_q].erase(cur_pid);
 		break;
 	}
+	if (switch_process)
+		return next_pid();
 
-
-
-	return 0;
+	return cur_pid;
 }

+ 2 - 0
sched_mfq.h

@@ -23,6 +23,8 @@ class SchedMFQ : public SchedBase {
 			uint quantum_count;
 		};
 
+		int ready_at(uint);
+		uint next_pid();
 		uint pid_queue(uint);
 		uint n_colas;
 		uint* q_cola;