Преглед изворни кода

Merge branch 'master' of ssh://gogs.davidventura.com.ar:443/david/so-tp1

Fabian пре 10 година
родитељ
комит
22231ca552
3 измењених фајлова са 49 додато и 18 уклоњено
  1. 37 14
      sched_mfq.cpp
  2. 1 0
      sched_mfq.h
  3. 11 4
      scripts/batchplotter.py

+ 37 - 14
sched_mfq.cpp

@@ -1,4 +1,5 @@
 #include <map>
+#include <iostream>
 #include <vector>
 #include <queue>
 #include "sched_mfq.h"
@@ -8,11 +9,11 @@ using namespace std;
 
 SchedMFQ::SchedMFQ(vector<int> argn) {
 	// MFQ recibe los quantums por parámetro
-	n_colas = argn[1];
+	n_colas = argn.size()-1;
 	q_cola = new uint[n_colas];
 
 	for( uint i = 0; i < n_colas ;i++ ){
-		q_cola[i] = argn[2+i];
+		q_cola[i] = argn[1+i];
 		v_cola.push_back(std::map<int,process>());
 	}
 }
@@ -41,58 +42,80 @@ uint SchedMFQ::pid_queue(uint pid){
 		if ( v_cola[i].count(pid) == 1) //Solo hay 0/1 key en un map
 			return i;
 
+	cout << "WHAT THE FUCK " << pid << endl;
+	for( uint i = 0; i < n_colas; i++ )
+		cout << "size cola " << i << " = " << v_cola[i].size() << endl;
 	return 65535; // ??
 }
 
 int SchedMFQ::ready_at(uint qn){
 	if (v_cola[qn].size() == 0)
 		return -1;
+
 	for (it_type it = v_cola[qn].begin(); it != v_cola[qn].end(); it++) {
-		if (it->second.state == READY)
+		//cout << "Mirando al pid " << it->first << endl;
+		if (it->second.state == READY){
+			//cout << "Me gusta " << it->first << endl;
 			return it->first;
+		}
 	}
+
 	return -1;
 }
 uint SchedMFQ::next_pid(){
 	for( uint q = 0; q < n_colas; q++ ){
+		//cout << "Mirando en la pila " << q << endl;
 		int p = ready_at(q);
-		if (p!=-1){
+		if (p != -1)
 			return p; //Algun proceso listo
-		}
 	}
 
 	return IDLE_TASK;
-	//return 65535;
 }
 
+void SchedMFQ::mostrar_estados(){
+	for( uint q = 0; q < n_colas; q++ ){
+		cout << "Cola " << q << ", size: " << v_cola[q].size() << endl;
+	}
+}
 int SchedMFQ::tick(int core, const enum Motivo m) {
 	uint switch_process = 0;
-	uint cur_pid = current_pid(core);
+	int cur_pid = current_pid(core);
+
+	cout << "PID at core " << core << " = " << cur_pid << endl;
+	if (cur_pid == IDLE_TASK)
+		return next_pid();
 
 	uint p_q = pid_queue(cur_pid);
-	process cur_process=v_cola[p_q][cur_pid];
+	process* cur_process=&(v_cola[p_q][cur_pid]);
+
 	switch (m) {
 	case TICK:
-		cur_process.quantum_count++;
-		if (cur_process.quantum_count >= q_cola[p_q]) {
+		cur_process->quantum_count++;
+		if (cur_process->quantum_count >= q_cola[p_q]) {
 			switch_process = 1;
-			cur_process.state = READY;
-			cur_process.quantum_count = 0;
+			cur_process->state = READY;
+			cur_process->quantum_count = 0;
 			if(p_q < n_colas) { //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);
 			}
 		}
 		break;
 	case BLOCK:
 		switch_process = 1;
-		cur_process.state = BLOCKED;
+		cur_process->state = BLOCKED;
 		break;
 	case EXIT:
 		switch_process = 1;
+		//cout << v_cola[p_q].size() << endl;
+		//cout << "borro pid: " << cur_pid << endl;
 		v_cola[p_q].erase(cur_pid);
+		//cout << v_cola[p_q].size() << endl;
 		break;
 	}
+	mostrar_estados();
+
 	if (switch_process)
 		return next_pid();
 

+ 1 - 0
sched_mfq.h

@@ -24,6 +24,7 @@ class SchedMFQ : public SchedBase {
 		};
 
 		int ready_at(uint);
+		void mostrar_estados();
 		uint next_pid();
 		uint pid_queue(uint);
 		uint n_colas;

+ 11 - 4
scripts/batchplotter.py

@@ -1,7 +1,9 @@
 #!/usr/bin/env python3
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
 import json
 import numpy as np
 import matplotlib.pyplot as plt
+import os
 import sys
 from subprocess import Popen, PIPE
 from stats import parseData
@@ -41,7 +43,7 @@ def plot(process_data):
     plot_data(0, m_latencies, 'r', 'M. Latency')
     plot_data(1, m_ready, 'g', 'M. Ready')
     plot_data(2, m_cpu, 'b', 'M. CPU')
-    plot_data(3, m_cpuio, '#deadbe', 'M. CPUIO')
+    plot_data(3, m_cpuio, '#deadbe', 'M. CPU+IO')
 
     ax.set_ylabel('Time')
     ax.set_title('title')
@@ -50,14 +52,15 @@ def plot(process_data):
                         for i in range(len(process_data))])
     
     for tick in ax.xaxis.get_major_ticks():
-        tick.label.set_fontsize(8)
+        tick.label.set_fontsize(9)
 
     plt.legend()
     
     plt.tight_layout()
     plt.grid()
-    plt.savefig('out.png')
-    plt.show()
+    filename='out.png'
+    plt.savefig(filename)
+    print("salida: %s" % filename)
 
 
 def meanLatency(pl):
@@ -105,6 +108,10 @@ if len(sys.argv) != 2:
     print("1 arg, json file")
     sys.exit(1)
 
+if not os.path.isfile(sys.argv[1]):
+    print("'%s' no es un archivo / no existe" % sys.argv[1])
+    sys.exit(2)
+    
 try:
     data = open(sys.argv[1]).read()
     j = json.loads(data)