|
|
@@ -1,5 +1,6 @@
|
|
|
#include "tasks.h"
|
|
|
#include "stdlib.h"
|
|
|
+#include <algorithm>
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
@@ -20,20 +21,44 @@ void TaskAlterno(int pid, vector<int> params) { // params: ms_pid, ms_io, ms_pid
|
|
|
}
|
|
|
|
|
|
void TaskConsola(int pid, vector<int> params) {
|
|
|
- int calls = params[0];
|
|
|
- int bmin = params[1];
|
|
|
- int bmax = params[2];
|
|
|
+ uint calls = params[0];
|
|
|
+ uint bmin = params[1];
|
|
|
+ uint bmax = params[2];
|
|
|
|
|
|
- for (int i = 0; i < calls; i++) {
|
|
|
+ for (uint i = 0; i < calls; i++) {
|
|
|
uso_CPU(pid, 1);
|
|
|
uso_IO(pid, rand() %(bmax-bmin) + bmin);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void TaskBatch(int total_cpu, int cant_bloqueos) {
|
|
|
- while(cant_bloqueos>0){
|
|
|
- //uso_IO(pid, rand() %(bmax-bmin) + bmin);
|
|
|
- cant_bloqueos--;
|
|
|
+void TaskBatch(int pid, vector<int> params ) {
|
|
|
+ //Tengo que bloquear CPU total_cpu unidades;
|
|
|
+ //esto incluye 1 por cada vez que llamo a uso_IO
|
|
|
+ //Entonces debo bloquear cpu total_cpu - cant_bloqueos
|
|
|
+ //Y si cant_bloqueos > total_cpu ?
|
|
|
+ uint total_cpu = params[0];
|
|
|
+ uint cant_bloqueos = params[1];
|
|
|
+ if (cant_bloqueos>total_cpu)// ???????
|
|
|
+ return;
|
|
|
+
|
|
|
+ vector<int> arr;
|
|
|
+ total_cpu = total_cpu - cant_bloqueos;
|
|
|
+ uint i;
|
|
|
+
|
|
|
+ for(i=0;i<total_cpu;i++)
|
|
|
+ arr.insert(arr.end(),0);
|
|
|
+
|
|
|
+ for(i=0;i<cant_bloqueos;i++)
|
|
|
+ arr.insert(arr.end(),1);
|
|
|
+
|
|
|
+ std::random_shuffle(arr.begin(),arr.end());
|
|
|
+
|
|
|
+ for(i=0; i<arr.size();i++){
|
|
|
+ if(arr[i]==1){
|
|
|
+ uso_IO(pid, 2);
|
|
|
+ } else {
|
|
|
+ uso_CPU(pid, 1); //1 ciclo?
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -45,5 +70,6 @@ void tasks_init(void) {
|
|
|
register_task(TaskCPU, 1);
|
|
|
register_task(TaskIO, 2);
|
|
|
register_task(TaskConsola, 3);
|
|
|
+ register_task(TaskBatch, 2);
|
|
|
register_task(TaskAlterno, -1);
|
|
|
}
|