|
@@ -1,3 +1,4 @@
|
|
|
|
|
+#include <map>
|
|
|
#include <vector>
|
|
#include <vector>
|
|
|
#include <queue>
|
|
#include <queue>
|
|
|
#include "sched_mfq.h"
|
|
#include "sched_mfq.h"
|
|
@@ -7,22 +8,72 @@ using namespace std;
|
|
|
|
|
|
|
|
SchedMFQ::SchedMFQ(vector<int> argn) {
|
|
SchedMFQ::SchedMFQ(vector<int> argn) {
|
|
|
// MFQ recibe los quantums por parámetro
|
|
// MFQ recibe los quantums por parámetro
|
|
|
-/* llenar */
|
|
|
|
|
|
|
+ n_colas = argn[1];
|
|
|
|
|
+ q_cola = new uint[n_colas];
|
|
|
|
|
+
|
|
|
|
|
+ for( uint i = 0; i < n_colas ;i++ ){
|
|
|
|
|
+ q_cola[i] = argn[2+i];
|
|
|
|
|
+ v_cola.push_back(std::map<int,process>());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SchedMFQ::~SchedMFQ() {
|
|
SchedMFQ::~SchedMFQ() {
|
|
|
-/* llenar */
|
|
|
|
|
|
|
+ delete[] q_cola;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SchedMFQ::load(int pid) {
|
|
void SchedMFQ::load(int pid) {
|
|
|
-/* llenar */
|
|
|
|
|
|
|
+ v_cola[0][pid].state=READY; //Cargo PID en la cola de mayor prioridad
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SchedMFQ::unblock(int pid) {
|
|
void SchedMFQ::unblock(int pid) {
|
|
|
-/* llenar */
|
|
|
|
|
|
|
+ uint p_q=pid_queue(pid);
|
|
|
|
|
+ v_cola[p_q][pid].state = READY;
|
|
|
|
|
+ v_cola[p_q][pid].quantum_count = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if(p_q > 0) { //Hay una cola "peor" para ir; lo llevo
|
|
|
|
|
+ v_cola[p_q-1][pid]=v_cola[p_q][pid];
|
|
|
|
|
+ v_cola[p_q].erase(pid);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+uint SchedMFQ::pid_queue(uint pid){
|
|
|
|
|
+ for( uint i = 0; i < n_colas; i++ )
|
|
|
|
|
+ if ( v_cola[i].count(pid) == 1) //Solo hay 0/1 key en un map
|
|
|
|
|
+ return i;
|
|
|
|
|
+
|
|
|
|
|
+ return 65535; // ??
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
-/* llenar */
|
|
|
|
|
|
|
+ uint switch_process = 0;
|
|
|
|
|
+ uint cur_pid = current_pid(core);
|
|
|
|
|
+
|
|
|
|
|
+ uint p_q = pid_queue(cur_pid);
|
|
|
|
|
+ switch (m) {
|
|
|
|
|
+ case TICK:
|
|
|
|
|
+ v_cola[p_q][cur_pid].quantum_count++;
|
|
|
|
|
+ if (v_cola[p_q][cur_pid].quantum_count >= q_cola[p_q]) {
|
|
|
|
|
+ switch_process = 1;
|
|
|
|
|
+ v_cola[p_q][cur_pid].state = READY;
|
|
|
|
|
+ v_cola[p_q][cur_pid].quantum_count = 0;
|
|
|
|
|
+ if(p_q < n_colas) { //Hay una cola "peor" para ir; lo llevo
|
|
|
|
|
+ v_cola[p_q+1][cur_pid]=v_cola[p_q][cur_pid];
|
|
|
|
|
+ v_cola[p_q].erase(cur_pid);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case BLOCK:
|
|
|
|
|
+ switch_process = 1;
|
|
|
|
|
+ v_cola[p_q][cur_pid].state = BLOCKED;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case EXIT:
|
|
|
|
|
+ switch_process = 1;
|
|
|
|
|
+ v_cola[p_q].erase(cur_pid);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|