From 764d3cb096346cfe66cfcf6e15311ebf8c6d42fa Mon Sep 17 00:00:00 2001 From: Martina Maggio <maggio.martina@gmail.com> Date: Mon, 8 Apr 2019 10:54:10 +0200 Subject: [PATCH] parallelizing for real --- artifact/generate_results.sh | 31 +++- artifact/src/sim/main.cpp | 311 +++++++++++++---------------------- 2 files changed, 143 insertions(+), 199 deletions(-) diff --git a/artifact/generate_results.sh b/artifact/generate_results.sh index 1285442..746b581 100755 --- a/artifact/generate_results.sh +++ b/artifact/generate_results.sh @@ -1,6 +1,6 @@ #!/bin/bash MATLABPATH="/usr/local" -MATLABPATH="/Applications/MATLAB_R2017a.app" +#MATLABPATH="/Applications/MATLAB_R2017a.app" MATLABPROGRAM="$MATLABPATH/bin/matlab" round() @@ -46,8 +46,33 @@ make clean cd .. # execute simulator and clean -./simulator +# start all the needed processes +./simulator 5 70 25 & +pid1=$! +./simulator 10 70 25 & +pid2=$! +./simulator 20 70 25 & +pid3=$! +./simulator 5 70 100 & +pid4=$! +./simulator 10 70 100 & +pid5=$! +./simulator 20 70 100 & +pid6=$! +./simulator 5 80 25 & +pid7=$! +# wait for all the needed processes +wait $pid1 +wait $pid2 +wait $pid3 +wait $pid4 +wait $pid5 +wait $pid6 +wait $pid7 +# done with simulator rm -f simulator +echo "------------------------------------------------" +echo "data generation terminated, starting processing" # run matlab script cd matlab @@ -55,6 +80,8 @@ P=\'$R\' export LC_ALL LC_ALL="en_GB.utf8" $MATLABPROGRAM -nodisplay -nosplash -nodesktop -r "run_all_tests_matlab($P);exit;" >/dev/null cd .. +echo "------------------------------------------------" +echo "data processing terminated" # back out of src cd .. diff --git a/artifact/src/sim/main.cpp b/artifact/src/sim/main.cpp index 14e4393..13f23a8 100644 --- a/artifact/src/sim/main.cpp +++ b/artifact/src/sim/main.cpp @@ -47,7 +47,7 @@ vector<double> delays_seq; vector<job> worst_control_seq; sequence_jobs worst_seq; -unsigned int U_ts, ntasks, dm_frac; +unsigned int utilization, ntasks, deadline_miss_load; unsigned int timewindow; unsigned int max_consec_miss_all = 0; @@ -58,13 +58,13 @@ unsigned int max_consec_miss_all = 0; // uses: "RESULTDIR", "N_TASKS", and "U" for folder selection string create_result_path(void) { - unsigned int Uint = U_ts; + unsigned int Uint = utilization; // results are going to be saved in a given folder, like // RESULTDIR/n3_u70_f25 string base_path = string(RESULTDIR) + "/"; string folder_path = "n" + std::to_string(ntasks) + - "_u" + std::to_string(Uint) + "_f" + std::to_string(dm_frac) +"/"; + "_u" + std::to_string(Uint) + "_f" + std::to_string(deadline_miss_load) +"/"; string result_path = base_path + folder_path; const char* path_dir = result_path.c_str(); @@ -475,216 +475,133 @@ void compute_responsetimes() { sequences.push_back(control_jobs); } -void process_ntasks(int i, int ntasks, vector<Task> tasks, vector<Task> hps) { - unsigned int control_task_id = ntasks - 1; - - // utilization {0.7, 0.80} - for (unsigned int u = 0; u <= 1; u++) { - U_ts = 70 + u * 10; - - // wc deadline miss load {25%, 100%} - for (unsigned int d = 0; d <= 1; d++) { - - if (i == 2 && u == 1) continue; - - // EXTRACT TASKSET FROM FILE - tasks.clear(); - hps.clear(); - - dm_frac = 25 + d*75; - - string taskset_path = "../tasksets/"; - string taskset_name = "n" + std::to_string(ntasks) + - "_u" + std::to_string(U_ts) + "taskset_" + std::to_string(dm_frac) + ".csv"; - cout << " Handling " << taskset_name << endl; - - ifstream input_tasklist(taskset_path + taskset_name); - - if (input_tasklist.fail()) - std::cout << "fail to find" << endl; - - while (input_tasklist.peek() == '\n') // skip empty lines - input_tasklist.get(); - - // skip first line - string line; - getline(input_tasklist, line); // read a line from the input file - - // Save taskset data - for (unsigned int l = 0; l < ntasks; l++) { - Task t; - getline(input_tasklist, line); - std::stringstream ss(line); - std::vector<double> vect; - string token; - - for (unsigned int el = 0; el < N_SAMPLESEXTIME * 2 + 2; el++) { - getline(ss, token, ','); - vect.push_back(stod(token.c_str())); - } - - t.task_id = vect.at(0); - t.period = vect.at(1); - for (unsigned int v = 0; v < N_SAMPLESEXTIME; v++) - t.exec_times.push_back(vect.at(2 + v)); - for (unsigned int v = 0; v < N_SAMPLESEXTIME; v++) - t.prob_exec_time.push_back(vect.at(2 + N_SAMPLESEXTIME + v)); - t.wcet = t.exec_times.at(N_SAMPLESEXTIME - 1); - t.bcet = t.exec_times.at(0); - tasks.push_back(t); - } - // skip another line - getline(input_tasklist, line); - // Save control periods - getline(input_tasklist, line); - std::stringstream ss(line); - std::vector<int> vect; - string token; - - while (getline(ss, token, ',')) - vect.push_back(atoi(token.c_str())); +// ******************************************************************* +int main(int argc, char *argv[]) +{ + if (argc != 4) { + cout << "I need 3 parameters: number_of_tasks, utilization, deadline_miss_load" << endl; + exit(-1); + } + + ntasks = strtol(argv[1], nullptr, 0); + utilization = strtol(argv[2], nullptr, 0); + deadline_miss_load = strtol(argv[3], nullptr, 0); + + vector<Task> tasks; + vector<Task> hps; - // Fill hps - for (int x = 1; x < tasks.size(); x++) - hps.push_back(tasks.at(x - 1)); + // Generate periods in bucket + generate_bucket(); - tasks.at(control_task_id).period = INT_MAX; + unsigned int control_task_id = ntasks - 1; - unsigned int T_max = 2000000; - unsigned int T_min = 500000; - unsigned int timegap = 100000; + // EXTRACT TASKSET FROM FILE + tasks.clear(); + hps.clear(); + string taskset_path = "../tasksets/"; + string taskset_name = "n" + std::to_string(ntasks) + + "_u" + std::to_string(utilization) + "taskset_" + std::to_string(deadline_miss_load) + ".csv"; + cout << "- launched result generation for " << taskset_name << endl; + + ifstream input_tasklist(taskset_path + taskset_name); + + if (input_tasklist.fail()) { + cout << "Taskset file not found" << endl; + exit(-1); + } + + while (input_tasklist.peek() == '\n') // skip empty lines + input_tasklist.get(); + // skip first line + string line; + getline(input_tasklist, line); // read a line from the input file + + // Save taskset data + for (unsigned int l = 0; l < ntasks; l++) { + Task t; + getline(input_tasklist, line); + std::stringstream ss(line); + std::vector<double> vect; + string token; + + for (unsigned int el = 0; el < N_SAMPLESEXTIME * 2 + 2; el++) { + getline(ss, token, ','); + vect.push_back(stod(token.c_str())); + } - // ----------------------------- STRATEGY-DEPENDANT PART start - for (int exp_strat = CONT_STRAT; - exp_strat <= SKIP_NEXT_STRAT; - exp_strat++) { + t.task_id = vect.at(0); + t.period = vect.at(1); + for (unsigned int v = 0; v < N_SAMPLESEXTIME; v++) + t.exec_times.push_back(vect.at(2 + v)); + for (unsigned int v = 0; v < N_SAMPLESEXTIME; v++) + t.prob_exec_time.push_back(vect.at(2 + N_SAMPLESEXTIME + v)); + t.wcet = t.exec_times.at(N_SAMPLESEXTIME - 1); + t.bcet = t.exec_times.at(0); + tasks.push_back(t); + } + // skip another line + getline(input_tasklist, line); + // save control periods + getline(input_tasklist, line); + std::stringstream ss(line); + std::vector<int> vect; + string token; - //cout << "------------------------------------------------" << endl; - strategy = static_cast<DM_STRATEGIES>(exp_strat); + while (getline(ss, token, ',')) + vect.push_back(atoi(token.c_str())); - // compute minimum time allowed for each strategy - unsigned int T_min_strat, T_min_appr; + // fill hps + for (int x = 1; x < tasks.size(); x++) + hps.push_back(tasks.at(x - 1)); - //cout << "STRATEGY: "; - //switch (strategy) { + tasks.at(control_task_id).period = INT_MAX; - //case CONT_STRAT: - // cout << "queue(1)" << endl; - // break; + unsigned int T_max = 2000000; + unsigned int T_min = 500000; + unsigned int timegap = 100000; - //case KILL_STRAT: - // cout << "kill" << endl; - // break; - //case SKIP_NEXT_STRAT: - // cout << "skip-next" << endl; - // break; + // ----------------------------- STRATEGY-DEPENDANT PART start + for (int exp_strat = CONT_STRAT; + exp_strat <= SKIP_NEXT_STRAT; + exp_strat++) { - //default: break; + strategy = static_cast<DM_STRATEGIES>(exp_strat); - //} + // compute minimum time allowed for each strategy + unsigned int T_min_strat, T_min_appr; - // compute sequences for each time step + // compute sequences for each time step - for (unsigned int s = 0; s < N_PERIODSTEPS; s++) { - - unsigned int Td = T_min + timegap*s; - - tasks.at(control_task_id).period = Td; - //cout << " - control period " << tasks.at(control_task_id).period << endl; - timewindow = N_JOBS * tasks.at(control_task_id).period; - - // generate worst-case schedule with all - // tasks experiencing WCET - sequences.clear(); - generate_seq_jobs(tasks, false); - compute_responsetimes(); - string filename = create_result_path() + - "wcet_seq_s" + std::to_string(strategy) + - "_t" + std::to_string(Td) + ".csv"; - - write_single_sequence(sequences.at(0), filename); - - // scenario-theoretic part: - // generate sequences for the given case - sequences.clear(); - for (unsigned int n = 0; n < N_TESTS; n++) { - generate_seq_jobs(tasks, true); - compute_responsetimes(); - } - // select worst sequence - sequence_selector(); - //cout << " worst sequence misses " << worst_seq.num_dm << endl; - //cout << " worst sequence consecutive misses " << worst_seq.max_consec_dm << endl; - - // save files to disk - write_sequences_disk(tasks.at(control_task_id).period); - } - } - // ----------------------------- STRATEGY-DEPENDANT PART end - - //cout << "------------------------------------------------" << endl; - } - } -} - -// ******************************************************************* -int main(int argc, char *argv[]) -{ - - int num_numtasks = 3; - int i; - pid_t pid; - unsigned int ntasks_sel[3] = {5, 10, 20}; - - vector<Task> tasks; - vector<Task> hps; - - // Generate periods in bucket - generate_bucket(); - - cout << "------------------------------------------------" << endl; - - // number of tasks {5, 10, 20} - //for (unsigned int i = 0; i <= 2; i++) { - - pid = fork(); - if (pid == 0) { - - i = 0; - ntasks = ntasks_sel[i]; - cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " processing " << ntasks << endl; - process_ntasks(i, ntasks, tasks, hps); - cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " terminated " << ntasks << endl; - exit(0); + for (unsigned int s = 0; s < N_PERIODSTEPS; s++) { + + unsigned int Td = T_min + timegap*s; + + tasks.at(control_task_id).period = Td; + timewindow = N_JOBS * tasks.at(control_task_id).period; + + // generate worst-case schedule with all + // tasks experiencing WCET + sequences.clear(); + generate_seq_jobs(tasks, false); + compute_responsetimes(); + string filename = create_result_path() + "wcet_seq_s" + std::to_string(strategy) + "_t" + std::to_string(Td) + ".csv"; + write_single_sequence(sequences.at(0), filename); + + // scenario-theoretic part: + // generate sequences for the given case + sequences.clear(); + for (unsigned int n = 0; n < N_TESTS; n++) { + generate_seq_jobs(tasks, true); + compute_responsetimes(); + } + // select worst sequence + sequence_selector(); + // save files to disk + write_sequences_disk(tasks.at(control_task_id).period); + } } - else { - pid = fork(); - if (pid == 0) { - - i = 1; - ntasks = ntasks_sel[i]; - cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " processing " << ntasks << endl; - process_ntasks(i, ntasks, tasks, hps); - cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " terminated " << ntasks << endl; - exit(0); - } - else { - pid = fork(); - if (pid == 0) { - - i = 2; - ntasks = ntasks_sel[i]; - cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " processing " << ntasks << endl; - process_ntasks(i, ntasks, tasks, hps); - cout <<"[worker] pid " << getpid() << " from [parent] pid " << getppid() << " terminated " << ntasks << endl; - exit(0); - } - else - for (int thr = 0; thr < 3; thr++) wait(NULL); - } - } return 0; } -- GitLab