summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp')
-rw-r--r--Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp155
1 files changed, 155 insertions, 0 deletions
diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp
new file mode 100644
index 0000000..807b39a
--- /dev/null
+++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp
@@ -0,0 +1,155 @@
+/*
+ * ResponseTimeAnalysis.cpp
+ *
+ * Created on: 07.11.2010
+ * Author: sven
+ */
+
+#include "ResponseTimeAnalysis.h"
+#ifndef GLOBAL_H_
+ #include "Global.h"
+#endif
+
+#include <iostream>
+#include <cmath>
+#include <map>
+
+ResponseTimeAnalysis::ResponseTimeAnalysis() {
+ // TODO Auto-generated constructor stub
+
+}
+
+ResponseTimeAnalysis::~ResponseTimeAnalysis() {
+ // TODO Auto-generated destructor stub
+}
+bool ResponseTimeAnalysis::analyse(rms_queue& task_queue)
+{
+ bool res = true;
+ unsigned int task_count = 0;
+ vector<Task*> task_set(task_queue.size());
+ while(!task_queue.empty()) {
+ Task* t = task_queue.top();
+ task_set[task_count++] = t;
+ task_queue.pop();
+ }
+ unsigned int c = 0;
+ for(c=0;c<task_set.size();c++) {
+ Task* t = task_set[c];
+ vector<Task*> higherPriorizedTasks(c);
+ for(unsigned int j=0;j<c;j++) {
+ higherPriorizedTasks[j]=task_set[j];
+ }
+ cout << "Task " << t->getName() << " has " << higherPriorizedTasks.size() << " higher priorized tasks: ";
+ for(unsigned int j=0;j<higherPriorizedTasks.size();j++) {
+ cout << higherPriorizedTasks[j]->getName();
+ }
+ cout << endl;
+ unsigned int ri = t->getOrigC();
+ if (c == 0) {
+ cout << "Response Time of Task " << t->getName() << " is " << ri << endl;
+ continue;
+ }
+ do {
+ unsigned int rii = t->getOrigC();
+ for(unsigned int j=0;j<higherPriorizedTasks.size();j++) {
+ Task* h = higherPriorizedTasks[j];
+ double a = ceil(static_cast<double>(ri)/static_cast<double>(h->getOrigP()));
+ double r = a*h->getOrigC();
+// cout << "(Ri)/Tj*Cj = (" << ri << "/" << h->getOrigP() << ")*"<< h->getOrigC() << " = " << r << endl;
+ rii += r;
+ }
+// cout << "Ri = " << rii << endl;
+ if(rii == ri) {
+ break;
+ }
+ ri = rii;
+ } while (1);
+ cout << "Response Time of Task " << t->getName() << " is " << ri << endl;
+ if (ri > static_cast<unsigned int>(t->getOrigD()) ) {
+ cout << "Response time of Task "<< t->getName() << " exceeds D:" << ri << ">" << t->getOrigD() << endl;
+ res = false;
+ break;
+ }
+ }
+ return res;
+}
+void ResponseTimeAnalysis::calcOptimalStaticPriorities(task_set& tasks)
+{
+ unsigned int N = tasks.size();
+ vector<Task*> prios(N);
+ for(unsigned int p=0;p<N;p++) {
+ prios[p]=&tasks[p];
+ }
+ cout << "N: " << N <<endl;
+ bool OK = false;
+ for(unsigned int K=0;K<N;K++)
+ {
+ unsigned int actPrio = K;
+ cout << "Searching Task to run at prio " << actPrio << endl;
+ for(unsigned int Next=K;Next<N;Next++) {
+ swap(prios,K,Next);
+ Task* candidate = prios[K];
+ cout << "candidate: "<< candidate->getName() << " with prio " << actPrio << endl;
+
+ // find tasks with higher priority
+ vector<Task*> higherPrioTasks;
+ unsigned int higherPrioTasksCounter = 0;
+ for(unsigned int taskPrio=actPrio+1;taskPrio<N;taskPrio++) {
+ Task *t = prios[taskPrio];
+ higherPrioTasks.push_back(t);
+ cout << higherPrioTasksCounter << " Added " << t->getName() << " to tasks with higher prio" <<endl;
+ higherPrioTasksCounter++;
+ }
+
+ // RTA
+ int ri = candidate->getOrigC();
+ if(higherPrioTasksCounter > 0) {
+ do {
+ int rii = candidate->getOrigC();
+ for(unsigned int k=0;k<higherPrioTasksCounter;k++)
+ {
+ Task* t = higherPrioTasks[k];
+ double a = ceil(static_cast<double>(ri)/static_cast<double>(t->getOrigP()));
+ double r = a*t->getOrigC();
+ rii += r;
+ }
+ if(rii == ri) {
+ break;
+ }
+ ri = rii;
+ } while(1);
+ }
+ // check response time
+ OK = (ri <= candidate->getOrigD());
+ cout << "Response Time of Task " << candidate->getName() << " is " << ri << " with prio " << actPrio << endl;
+ if(OK) {
+ cout << "Task "<< candidate->getName() << " runs at prio " << actPrio << endl << endl;
+ break;
+ } else {
+ cout << "Task "<< candidate->getName() << " cannot run at prio " << actPrio << endl;
+ }
+ } // inner for loop
+ if(!OK) {
+ cout << "Not schedulable! No task to run at prio " << actPrio << endl;
+ break;
+ }
+ }// outer for loop
+ if(OK) {
+ cout << "Optimal priorities:" << endl;
+ for(unsigned int c=0;c<N;c++) {
+ Task *t = prios[c];
+ if(t) {
+ cout << c << " " << t->getName() << endl;
+ }
+ }
+ }
+}
+void ResponseTimeAnalysis::swap(vector<Task*>& prios,int a,int b)
+{
+ Task *taskA = prios[a];
+ Task *taskB = prios[b];
+ cout << "Swapping " << taskA->getName() << " ("<<a<<") and " << taskB->getName() << " (" <<b<< ")"<< endl;
+ Task* tmpTask = taskA;
+ prios[a] = taskB;
+ prios[b] = tmpTask;
+}