|
|
@@ -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;
|
|
|
}
|
|
|
}
|