|
@@ -1,7 +1,6 @@
|
|
|
#include <map>
|
|
#include <map>
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
#include "sched_mfq.h"
|
|
#include "sched_mfq.h"
|
|
|
-#include "basesched.h"
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
using namespace std;
|
|
|
|
|
|
|
@@ -40,9 +39,11 @@ uint SchedMFQ::pid_queue(int pid){
|
|
|
if ( v_cola[i].count(pid) == 1) //Solo hay 0/1 key en un map
|
|
if ( v_cola[i].count(pid) == 1) //Solo hay 0/1 key en un map
|
|
|
return i;
|
|
return i;
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
cout << "WHAT THE FUCK " << pid << endl;
|
|
cout << "WHAT THE FUCK " << pid << endl;
|
|
|
for( uint i = 0; i < n_colas; i++ )
|
|
for( uint i = 0; i < n_colas; i++ )
|
|
|
cout << "size cola " << i << " = " << v_cola[i].size() << endl;
|
|
cout << "size cola " << i << " = " << v_cola[i].size() << endl;
|
|
|
|
|
+ */
|
|
|
return 65535; // ??
|
|
return 65535; // ??
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -51,9 +52,9 @@ int SchedMFQ::ready_at(uint qn){
|
|
|
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].begin(); 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){
|
|
if (it->second.state == READY){
|
|
|
- cout << "Me gusta " << it->first << endl;
|
|
|
|
|
|
|
+ //cout << "Me gusta " << it->first << endl;
|
|
|
return it->first;
|
|
return it->first;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -62,7 +63,7 @@ int SchedMFQ::ready_at(uint qn){
|
|
|
}
|
|
}
|
|
|
uint SchedMFQ::next_pid(){
|
|
uint SchedMFQ::next_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);
|
|
|
if (p != -1)
|
|
if (p != -1)
|
|
|
return p; //Algun proceso listo
|
|
return p; //Algun proceso listo
|
|
@@ -72,23 +73,29 @@ uint SchedMFQ::next_pid(){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SchedMFQ::mostrar_estados(){
|
|
void SchedMFQ::mostrar_estados(){
|
|
|
- cout << "RDY: " << READY << ", RNING: " << RUNNING << ", BLK: " << BLOCKED << endl;
|
|
|
|
|
|
|
+ //cout << "RDY: " << READY << ", RNING: " << RUNNING << ", BLK: " << BLOCKED << endl;
|
|
|
for( uint q = 0; q < n_colas; q++ ){
|
|
for( uint q = 0; q < n_colas; q++ ){
|
|
|
- cout << "Cola " << q << ", size: " << v_cola[q].size() << endl;
|
|
|
|
|
|
|
+ //cout << "Cola " << q << ", size: " << v_cola[q].size() << endl;
|
|
|
for (it_type it = v_cola[q].begin(); it != v_cola[q].end(); it++) {
|
|
for (it_type it = v_cola[q].begin(); it != v_cola[q].end(); it++) {
|
|
|
- cout << "PID: " << it->first << ", STATE: " << it->second.state << endl;
|
|
|
|
|
|
|
+ cout << "["<< q <<"]PID: " << it->first << ", STATE: " << it->second.state << endl;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
uint switch_process = 0;
|
|
uint switch_process = 0;
|
|
|
int cur_pid = current_pid(core);
|
|
int cur_pid = current_pid(core);
|
|
|
|
|
+ uint p_q;
|
|
|
|
|
+ //cout << "(start tick) PID at core " << core << " = " << cur_pid << endl;
|
|
|
|
|
+ if (cur_pid == IDLE_TASK){
|
|
|
|
|
+ cur_pid = next_pid();
|
|
|
|
|
+ if (cur_pid != IDLE_TASK){
|
|
|
|
|
+ p_q = pid_queue(cur_pid);
|
|
|
|
|
+ v_cola[p_q][cur_pid].state = RUNNING;
|
|
|
|
|
+ }
|
|
|
|
|
+ return cur_pid;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- cout << "PID at core " << core << " = " << cur_pid << endl;
|
|
|
|
|
- if (cur_pid == IDLE_TASK)
|
|
|
|
|
- return next_pid();
|
|
|
|
|
-
|
|
|
|
|
- uint 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]);
|
|
@@ -100,7 +107,7 @@ int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
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
|
|
|
v_cola[p_q+1][cur_pid]=*cur_process;
|
|
v_cola[p_q+1][cur_pid]=*cur_process;
|
|
|
v_cola[p_q].erase(cur_pid);
|
|
v_cola[p_q].erase(cur_pid);
|
|
@@ -114,24 +121,19 @@ int SchedMFQ::tick(int core, const enum Motivo m) {
|
|
|
case EXIT:
|
|
case EXIT:
|
|
|
switch_process = 1;
|
|
switch_process = 1;
|
|
|
//cout << v_cola[p_q].size() << endl;
|
|
//cout << v_cola[p_q].size() << endl;
|
|
|
- cout << "borro pid: " << cur_pid << endl;
|
|
|
|
|
|
|
+ //cout << "borro pid: " << cur_pid << endl;
|
|
|
v_cola[p_q].erase(cur_pid);
|
|
v_cola[p_q].erase(cur_pid);
|
|
|
//cout << v_cola[p_q].size() << endl;
|
|
//cout << v_cola[p_q].size() << endl;
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- mostrar_estados();
|
|
|
|
|
|
|
+ //mostrar_estados();
|
|
|
|
|
|
|
|
if (switch_process) {
|
|
if (switch_process) {
|
|
|
cur_pid = next_pid();
|
|
cur_pid = next_pid();
|
|
|
- if (cur_pid == IDLE_TASK){
|
|
|
|
|
- cout << "SWITCHING -1 ??? " << endl;
|
|
|
|
|
- return IDLE_TASK;
|
|
|
|
|
|
|
+ if (cur_pid != IDLE_TASK){
|
|
|
|
|
+ p_q = pid_queue(cur_pid);
|
|
|
|
|
+ v_cola[p_q][cur_pid].state = RUNNING;
|
|
|
}
|
|
}
|
|
|
- p_q = pid_queue(cur_pid);
|
|
|
|
|
- process* next_process=&(v_cola[p_q][cur_pid]);
|
|
|
|
|
- next_process->state = RUNNING;
|
|
|
|
|
- return cur_pid;
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return cur_pid;
|
|
return cur_pid;
|
|
|
}
|
|
}
|