|
@@ -47,24 +47,29 @@ uint SchedMFQ::pid_queue(int pid){
|
|
|
return 65535; // ??
|
|
return 65535; // ??
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int SchedMFQ::ready_at(uint qn){
|
|
|
|
|
|
|
+int SchedMFQ::ready_at(uint qn, int cur_pid){
|
|
|
if (v_cola[qn].size() == 0)
|
|
if (v_cola[qn].size() == 0)
|
|
|
return -1;
|
|
return -1;
|
|
|
|
|
|
|
|
- for (it_type it = v_cola[qn].begin(); it != v_cola[qn].end(); it++) {
|
|
|
|
|
|
|
+ for (it_type it = ++v_cola[qn].find(cur_pid); it != v_cola[qn].end(); it++) {
|
|
|
//cout << "Mirando al pid " << it->first << endl;
|
|
//cout << "Mirando al pid " << it->first << endl;
|
|
|
- if (it->second.state == READY){
|
|
|
|
|
- //cout << "Me gusta " << it->first << endl;
|
|
|
|
|
|
|
+ if (it->second.state == READY)
|
|
|
|
|
+ return it->first;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (it_type it = v_cola[qn].begin(); it != v_cola[qn].find(cur_pid); it++) {
|
|
|
|
|
+ //cout << "Mirando al pid " << it->first << endl;
|
|
|
|
|
+ if (it->second.state == READY)
|
|
|
return it->first;
|
|
return it->first;
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ if(v_cola[qn][cur_pid].state==READY)
|
|
|
|
|
+ return cur_pid;
|
|
|
|
|
|
|
|
- return -1;
|
|
|
|
|
|
|
+ return IDLE_TASK;
|
|
|
}
|
|
}
|
|
|
-uint SchedMFQ::next_pid(){
|
|
|
|
|
|
|
+uint SchedMFQ::next_pid(int cur_pid){
|
|
|
for( uint q = 0; q < n_colas; q++ ){
|
|
for( uint q = 0; q < n_colas; q++ ){
|
|
|
//cout << "Mirando en la pila " << q << endl;
|
|
//cout << "Mirando en la pila " << q << endl;
|
|
|
- int p = ready_at(q);
|
|
|
|
|
|
|
+ int p = ready_at(q,cur_pid);
|
|
|
if (p != -1)
|
|
if (p != -1)
|
|
|
return p; //Algun proceso listo
|
|
return p; //Algun proceso listo
|
|
|
}
|
|
}
|
|
@@ -86,8 +91,8 @@ int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
int cur_pid = current_pid(core);
|
|
int cur_pid = current_pid(core);
|
|
|
uint p_q;
|
|
uint p_q;
|
|
|
//cout << "(start tick) PID at core " << core << " = " << cur_pid << endl;
|
|
//cout << "(start tick) PID at core " << core << " = " << cur_pid << endl;
|
|
|
- if (cur_pid == IDLE_TASK){
|
|
|
|
|
- cur_pid = next_pid();
|
|
|
|
|
|
|
+ if (cur_pid == IDLE_TASK){ //FIXME repito el codigo abajo en switch_process
|
|
|
|
|
+ cur_pid = next_pid(cur_pid);
|
|
|
if (cur_pid != IDLE_TASK){
|
|
if (cur_pid != IDLE_TASK){
|
|
|
p_q = pid_queue(cur_pid);
|
|
p_q = pid_queue(cur_pid);
|
|
|
v_cola[p_q][cur_pid].state = RUNNING;
|
|
v_cola[p_q][cur_pid].state = RUNNING;
|
|
@@ -96,7 +101,7 @@ int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
p_q = pid_queue(cur_pid);
|
|
p_q = pid_queue(cur_pid);
|
|
|
- if (p_q == 65535) //FIXME
|
|
|
|
|
|
|
+ if (p_q == 65535) //FIXME ?
|
|
|
return IDLE_TASK;
|
|
return IDLE_TASK;
|
|
|
process* cur_process=&(v_cola[p_q][cur_pid]);
|
|
process* cur_process=&(v_cola[p_q][cur_pid]);
|
|
|
|
|
|
|
@@ -104,13 +109,17 @@ int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
case TICK:
|
|
case TICK:
|
|
|
cur_process->quantum_count++;
|
|
cur_process->quantum_count++;
|
|
|
if (cur_process->quantum_count >= q_cola[p_q]) {
|
|
if (cur_process->quantum_count >= q_cola[p_q]) {
|
|
|
|
|
+ cout << "pid: " << cur_pid << " con q >" << q_cola[p_q] << endl;
|
|
|
switch_process = 1;
|
|
switch_process = 1;
|
|
|
cur_process->state = READY;
|
|
cur_process->state = READY;
|
|
|
cur_process->quantum_count = 0;
|
|
cur_process->quantum_count = 0;
|
|
|
//cout << "Marcando a cur_pid("<< cur_pid<<") como READY (>quantum)" << endl;
|
|
//cout << "Marcando a cur_pid("<< cur_pid<<") como READY (>quantum)" << endl;
|
|
|
- if(p_q < n_colas - 1) { //Hay una cola "peor" para ir; lo llevo
|
|
|
|
|
|
|
+ if(p_q < (n_colas - 1)) { //Hay una cola "peor" para ir; lo llevo
|
|
|
|
|
+ mostrar_estados();
|
|
|
v_cola[p_q+1][cur_pid]=*cur_process;
|
|
v_cola[p_q+1][cur_pid]=*cur_process;
|
|
|
|
|
+ cout << "Moviendo pid: " << cur_pid << " a cola con q=" << q_cola[p_q+1] << endl;
|
|
|
v_cola[p_q].erase(cur_pid);
|
|
v_cola[p_q].erase(cur_pid);
|
|
|
|
|
+ mostrar_estados();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
@@ -129,7 +138,7 @@ int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
//mostrar_estados();
|
|
//mostrar_estados();
|
|
|
|
|
|
|
|
if (switch_process) {
|
|
if (switch_process) {
|
|
|
- cur_pid = next_pid();
|
|
|
|
|
|
|
+ cur_pid = next_pid(cur_pid);
|
|
|
if (cur_pid != IDLE_TASK){
|
|
if (cur_pid != IDLE_TASK){
|
|
|
p_q = pid_queue(cur_pid);
|
|
p_q = pid_queue(cur_pid);
|
|
|
v_cola[p_q][cur_pid].state = RUNNING;
|
|
v_cola[p_q][cur_pid].state = RUNNING;
|