From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Praktikum1/Aufgabe1/.cproject | 325 +++++++++++++++++++++ .../Real-Time Systems/Praktikum1/Aufgabe1/.project | 78 +++++ .../Real-Time Systems/Praktikum1/Aufgabe1/Makefile | 49 ++++ .../Praktikum1/Aufgabe1/src/main.cpp | 195 +++++++++++++ .../Praktikum1/Aufgabe2/wcet-analyse.ods | Bin 0 -> 16765 bytes .../Praktikum1/Aufgabe3/.cproject | 235 +++++++++++++++ .../Real-Time Systems/Praktikum1/Aufgabe3/.project | 78 +++++ .../Real-Time Systems/Praktikum1/Aufgabe3/Makefile | 49 ++++ .../Praktikum1/Aufgabe3/src/DMSScheduler.cpp | 57 ++++ .../Praktikum1/Aufgabe3/src/DMSScheduler.h | 37 +++ .../Praktikum1/Aufgabe3/src/EDFScheduler.cpp | 75 +++++ .../Praktikum1/Aufgabe3/src/EDFScheduler.h | 40 +++ .../Praktikum1/Aufgabe3/src/Global.h | 13 + .../Praktikum1/Aufgabe3/src/RMSScheduler.cpp | 64 ++++ .../Praktikum1/Aufgabe3/src/RMSScheduler.h | 40 +++ .../Aufgabe3/src/ResponseTimeAnalysis.cpp | 155 ++++++++++ .../Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.h | 30 ++ .../Praktikum1/Aufgabe3/src/Task.cpp | 81 +++++ .../Praktikum1/Aufgabe3/src/Task.h | 117 ++++++++ .../Praktikum1/Aufgabe3/src/main.cpp | 99 +++++++ .../Praktikum1/Aufgabe3/tasks.txt | 4 + .../Praktikum1/Aufgabe3/tasks.txt.20101107save01 | 4 + 22 files changed, 1825 insertions(+) create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe1/.cproject create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe1/.project create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe1/Makefile create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe1/src/main.cpp create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe2/wcet-analyse.ods create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/.cproject create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/.project create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/Makefile create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.cpp create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.h create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.cpp create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.h create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Global.h create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.cpp create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.h create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.cpp create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/ResponseTimeAnalysis.h create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.cpp create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.h create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt create mode 100644 Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt.20101107save01 (limited to 'Master/Real-Time Systems/Praktikum1') diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe1/.cproject b/Master/Real-Time Systems/Praktikum1/Aufgabe1/.cproject new file mode 100644 index 0000000..bb5f1ad --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe1/.cproject @@ -0,0 +1,325 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +make + +all +true +true +true + + +make + +clean +true +true +true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe1/.project b/Master/Real-Time Systems/Praktikum1/Aufgabe1/.project new file mode 100644 index 0000000..2c30c84 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe1/.project @@ -0,0 +1,78 @@ + + + RTS_P1_1 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe1/Makefile b/Master/Real-Time Systems/Praktikum1/Aufgabe1/Makefile new file mode 100644 index 0000000..e5c163d --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe1/Makefile @@ -0,0 +1,49 @@ +# +# Variables +# +PROJECT_ROOT = . +BUILDDIR = $(PROJECT_ROOT)/build +SOURCEDIR = $(PROJECT_ROOT)/src +INCLUDEDIRS = $(SOURCEDIR) +INCLUDES = $(addprefix -I,$(INCLUDEDIRS)) +LIBNAMES = pthread +LIBS = $(addprefix -l,$(LIBNAMES)) +DEBUGFLAGS = -g +CFLAGS = -Wall -DDEBUG_MODE -DDEBUG +CFLAGS += -DLINUX $(DEBUGFLAGS) +LDFLAGS = $(DEBUGFLAGS) +CC = g++ +LD = g++ + +LINK_TARGET = $(BUILDDIR)/regelungsverfahren + +SOURCES := $(wildcard $(SOURCEDIR)/*.cpp) + +OBJS_TMP := $(foreach srcfile,$(SOURCES),$(srcfile).o) +OBJS := $(foreach tmp,$(OBJS_TMP),$(patsubst $(SOURCEDIR)/%.cpp.o,$(BUILDDIR)/%.o,$(tmp))) + +REBUILDABLES = $(OBJS) $(LINK_TARGET) + +.PHONY: clean +clean : + rm -f $(REBUILDABLES) + rm -f $(BUILDDIR)/* + rmdir $(BUILDDIR) + @echo Clean done + +all : builddir $(LINK_TARGET) + @echo All done + +builddir : + @echo 'Creating build directory' + mkdir -p $(BUILDDIR) + +$(LINK_TARGET) : $(OBJS) + @echo 'Linking file: $@' + $(LD) $(LDFLAGS) $(LIBS) -o $@ $^ + +$(BUILDDIR)/%.o : $(SOURCEDIR)/%.cpp + @echo 'Building file: $<' + $(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $< + + diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe1/src/main.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe1/src/main.cpp new file mode 100644 index 0000000..65eef37 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe1/src/main.cpp @@ -0,0 +1,195 @@ +/* + * main.cpp + * + * Created on: 31.10.2010 + * Author: sven + */ +#include +#include +#include +#include +#include +#include +#include +#include + +// debug printing +#ifdef DEBUG_MODE +#include + #define DEBUG_PRINT(format, args...)\ + {\ + static char message[512];\ + snprintf(message,512,format, ##args);\ + fprintf(stdout, "[%s: %d] : %s\n", __PRETTY_FUNCTION__,__LINE__, message);\ + fflush(stdout);\ + } +#else + #define DEBUG_PRINT(format, args...) +#endif // DEBUG_MODE + +/* + * global variables + */ +sem_t main_block,timer_block; +pthread_t timer_thread; +bool stop_timer_thread = false; +pthread_mutex_t stop_mutex = PTHREAD_MUTEX_INITIALIZER; +// 0 sec +const long TIMER_INTERVAL_SECS = 0; +// 10 msec +const long TIMER_INTERVAL_USECS = 10000; + +struct sigaction timer_action, quit_action; +/* + * function prototypes + */ +void readSensors(); +void initializeClock(); +void initializeMain(); +void WaitForNextCycle(); +void ActuateProcess(); +bool CalculateNewSetValues(); +void Error(); +void* TimerThreadProc(void*); +void timer_handler(int); + +void* TimerThreadProc(void*) { + /** + * Timer code originally from + * http://www.informit.com/articles/article.aspx?p=23618&seqNum=14 + */ + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + bool stop_me = false; + struct itimerval timer; + /* Install timer_handler as the signal handler for SIGALRM. */ + timer_action.sa_handler = timer_handler; + sigemptyset(&timer_action.sa_mask); + timer_action.sa_flags = 0; + sigaction(SIGALRM,&timer_action,NULL); + + /* Configure the timer to expire after + * TIMER_INTERVAL_SECS + TIMER_INTERVAL_USECS... */ + timer.it_value.tv_sec = TIMER_INTERVAL_SECS; + timer.it_value.tv_usec = TIMER_INTERVAL_USECS; + /* ... and every TIMER_INTERVAL_SECS+TIMER_INTERVAL_USECS after that. */ + timer.it_interval.tv_sec = TIMER_INTERVAL_SECS; + timer.it_interval.tv_usec = TIMER_INTERVAL_USECS; + /* If the timer code is ITIMER_REAL, + * the process is sent a SIGALRM signal after the + * specified wall-clock time has elapsed*/ + setitimer (ITIMER_REAL, &timer, NULL); + while(1) { + pthread_mutex_lock(&stop_mutex); + stop_me = stop_timer_thread; + pthread_mutex_unlock(&stop_mutex); + if(stop_me) { + DEBUG_PRINT("exiting thread Process: %d Thread: %lu",(int)getpid(),pthread_self()); + pthread_exit(NULL); + } + DEBUG_PRINT("waiting for timer_handler Process: %d Thread: %lu",(int)getpid(),pthread_self()); + sem_wait(&timer_block); + DEBUG_PRINT("waking up main Process: %d Thread: %lu",(int)getpid(),pthread_self()); + sem_post(&main_block); + } + DEBUG_PRINT("should never happen Process: %d Thread: %lu",(int)getpid(),pthread_self()); + return NULL; +} + +void timer_handler(int signum) { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + static int count = 0; + DEBUG_PRINT("timer expired %d times", ++count); + sem_post(&timer_block); + DEBUG_PRINT("exit"); +} + +void quit_handler(int signum) { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + int semval; + pthread_mutex_lock(&stop_mutex); + stop_timer_thread = true; + pthread_mutex_unlock(&stop_mutex); + sem_getvalue(&timer_block,&semval); + if(semval > 0) { + DEBUG_PRINT("waking up timer thread"); + sem_post(&timer_block); + } + pthread_join(timer_thread,NULL); + DEBUG_PRINT("Joined timer thread"); + //clean up + sem_destroy(&timer_block); + sem_destroy(&main_block); + pthread_mutex_destroy(&stop_mutex); + DEBUG_PRINT("exit"); + exit(EXIT_SUCCESS); +} + +void WaitForNextCycle() { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + sem_wait(&main_block); + DEBUG_PRINT("exit"); +} + +void readSensors() { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + struct timeval tv; + struct timezone tz; + struct tm *tm; + gettimeofday(&tv, &tz); + tm=localtime(&tv.tv_sec); + printf(" %d:%02d:%02d %lu \n", tm->tm_hour, tm->tm_min, + tm->tm_sec, tv.tv_usec); + DEBUG_PRINT("exit"); +} +void Error() { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + DEBUG_PRINT("exit"); +} +bool CalculateNewSetValues() { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + DEBUG_PRINT("exit"); + return true; +} +void ActuateProcess() { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + DEBUG_PRINT("exit"); +} +void initializeClock() +{ + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + pthread_create(&timer_thread,NULL,TimerThreadProc,NULL); + DEBUG_PRINT("exit"); +} + +void initializeMain() { + DEBUG_PRINT("entry Process: %d Thread: %lu",(int)getpid(),pthread_self()); + + /* init semaphore as closed */ + sem_init(&main_block,0,0); + sem_init(&timer_block,0,0); + + /* catch all interesting signals */ + quit_action.sa_handler = quit_handler; + sigemptyset(&quit_action.sa_mask); + quit_action.sa_flags = 0; + sigaction(SIGTERM,&quit_action,NULL); + sigaction(SIGQUIT,&quit_action,NULL); + sigaction(SIGINT,&quit_action,NULL); + sigaction(SIGHUP,&quit_action,NULL); + DEBUG_PRINT("exit"); +} + +int main(int argc, char* argv[]) +{ + initializeMain(); + initializeClock(); + while(1) { + readSensors(); + if(CalculateNewSetValues()) + ActuateProcess(); + else + Error(); + WaitForNextCycle(); + } + return EXIT_SUCCESS; +} diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe2/wcet-analyse.ods b/Master/Real-Time Systems/Praktikum1/Aufgabe2/wcet-analyse.ods new file mode 100644 index 0000000..307f2ea Binary files /dev/null and b/Master/Real-Time Systems/Praktikum1/Aufgabe2/wcet-analyse.ods differ diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/.cproject b/Master/Real-Time Systems/Praktikum1/Aufgabe3/.cproject new file mode 100644 index 0000000..e2c949a --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/.cproject @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +make + +all +true +true +true + + +make + +clean +true +true +true + + + + + + + + + diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/.project b/Master/Real-Time Systems/Praktikum1/Aufgabe3/.project new file mode 100644 index 0000000..9d5687e --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/.project @@ -0,0 +1,78 @@ + + + RTS_P1_3 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/Makefile b/Master/Real-Time Systems/Praktikum1/Aufgabe3/Makefile new file mode 100644 index 0000000..648c711 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/Makefile @@ -0,0 +1,49 @@ +# +# Variables +# +PROJECT_ROOT = . +BUILDDIR = $(PROJECT_ROOT)/build +SOURCEDIR = $(PROJECT_ROOT)/src +INCLUDEDIRS = $(SOURCEDIR) +INCLUDES = $(addprefix -I,$(INCLUDEDIRS)) +LIBNAMES = +LIBS = $(addprefix -l,$(LIBNAMES)) +DEBUGFLAGS = -g +CFLAGS = -Wall -DDEBUG_MODE -DDEBUG +CFLAGS += -DLINUX $(DEBUGFLAGS) +LDFLAGS = $(DEBUGFLAGS) +CC = g++ +LD = g++ + +LINK_TARGET = $(BUILDDIR)/scheduler_sim + +SOURCES := $(wildcard $(SOURCEDIR)/*.cpp) + +OBJS_TMP := $(foreach srcfile,$(SOURCES),$(srcfile).o) +OBJS := $(foreach tmp,$(OBJS_TMP),$(patsubst $(SOURCEDIR)/%.cpp.o,$(BUILDDIR)/%.o,$(tmp))) + +REBUILDABLES = $(OBJS) $(LINK_TARGET) + +.PHONY: clean +clean : + rm -f $(REBUILDABLES) + rm -f $(BUILDDIR)/* + rmdir $(BUILDDIR) + @echo Clean done + +all : builddir $(LINK_TARGET) + @echo All done + +builddir : + @echo 'Creating build directory' + mkdir -p $(BUILDDIR) + +$(LINK_TARGET) : $(OBJS) + @echo 'Linking file: $@' + $(LD) $(LDFLAGS) $(LIBS) -o $@ $^ + +$(BUILDDIR)/%.o : $(SOURCEDIR)/%.cpp + @echo 'Building file: $<' + $(CC) $(CFLAGS) $(INCLUDES) -o $@ -c $< + + diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.cpp new file mode 100644 index 0000000..7c40037 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.cpp @@ -0,0 +1,57 @@ +/* + * DMSScheduler.cpp + * + * Created on: 02.11.2010 + * Author: sven + */ +#ifndef GLOBAL_H_ + #include "Global.h" +#endif + +#include "DMSScheduler.h" +#include + +DMSScheduler::DMSScheduler() { + // TODO Auto-generated constructor stub + +} + +DMSScheduler::~DMSScheduler() { + // TODO Auto-generated destructor stub +} +void DMSScheduler::run(task_set& tasks,int ci) +{ + cout << "D M S" << endl; + for(unsigned int task_count = 0; task_count < tasks.size(); task_count++) + { + m_queue.push(&tasks[task_count]); + } + while (!m_queue.empty()) { + Task* t = m_queue.top(); + t->dump(); + m_queue.pop(); + } + for(int step= 0; step < ci; step++) + { + cout << (step + 1) << " "; + for(unsigned int task_count = 0; task_count < tasks.size(); task_count++) + { + m_queue.push(&tasks[task_count]); + } + bool scheduledAtask = false; + while (!m_queue.empty()) { + Task* t = m_queue.top(); + if(!scheduledAtask && (t->getActC() > 0) ) { + t->execute(); + scheduledAtask = true; + } else { + t->requeue(); + } + m_queue.pop(); + } + if (!scheduledAtask) { + cout << "no task needs to run"; + } + cout << endl; + } +} diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.h b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.h new file mode 100644 index 0000000..95d73a7 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/DMSScheduler.h @@ -0,0 +1,37 @@ +/* + * DMSScheduler.h + * + * Created on: 02.11.2010 + * Author: sven + */ + +#ifndef DMSSCHEDULER_H_ +#define DMSSCHEDULER_H_ +#ifndef TASK_H_ + #include "Task.h" +#endif + +#include + +class DMSComparator; + +typedef priority_queue,DMSComparator> dms_queue; + +class DMSComparator +{ +public: + bool operator()(Task*& a, Task*& b) const + { + return ( b->getOrigD() < a->getOrigD() ); + } +}; +class DMSScheduler { +public: + DMSScheduler(); + virtual ~DMSScheduler(); + void run(task_set&,int); +private: + dms_queue m_queue; +}; + +#endif /* DMSSCHEDULER_H_ */ diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.cpp new file mode 100644 index 0000000..2f3a5c2 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.cpp @@ -0,0 +1,75 @@ +/* + * EDFScheduler.cpp + * + * Created on: 07.11.2010 + * Author: sven + */ + +#include "EDFScheduler.h" +#include +EDFScheduler::EDFScheduler() { + // TODO Auto-generated constructor stub + +} + +EDFScheduler::~EDFScheduler() { + // TODO Auto-generated destructor stub +} +void EDFScheduler::run(task_set& tasks,int ci) +{ + cout << "EDF" << endl; + if(!test(tasks)) { + cout << "Taskset not schedulable!" << endl; + return; + } + for(unsigned int task_count = 0; task_count < tasks.size(); task_count++) + { + m_queue.push(&tasks[task_count]); + } + while (!m_queue.empty()) { + Task* t = m_queue.top(); + t->dump(); + m_queue.pop(); + } + for(int step= 0; step < ci; step++) + { + cout << (step + 1) << " "; + edf_queue edfq; + for(unsigned int task_count = 0; task_count < tasks.size(); task_count++) + { + edfq.push(&tasks[task_count]); + } + bool scheduledAtask = false; + while (!edfq.empty()) { + Task* t = edfq.top(); + if(!scheduledAtask && (t->getActC() > 0) ) { + t->execute(); + scheduledAtask = true; + } else { + t->requeue(); + } + edfq.pop(); + } + if (!scheduledAtask) { + cout << "no task needs to run"; + } + cout << endl; + } +} +bool EDFScheduler::test(task_set& taskset) +{ + bool res = false; + unsigned int sum = 0; + for(unsigned int i=0;i(t.getOrigC()) / static_cast(t.getOrigP()); + if(t.getOrigC() > t.getOrigP()) { + return false; + } + } + if( sum <= 1.0) { + res = true; + } + return res; +} diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.h b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.h new file mode 100644 index 0000000..a790a0f --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/EDFScheduler.h @@ -0,0 +1,40 @@ +/* + * EDFScheduler.h + * + * Created on: 07.11.2010 + * Author: sven + */ + +#ifndef EDFSCHEDULER_H_ +#define EDFSCHEDULER_H_ + +#ifndef TASK_H_ + #include "Task.h" +#endif + +#include + +class EDFComparator; + +typedef priority_queue,EDFComparator> edf_queue; + +class EDFComparator +{ +public: + bool operator()(Task*& a, Task*& b) const + { +// return ( b->getActD() < a->getActD() ); + return ( b->getNextDeadline() < a->getNextDeadline() ); + } +}; +class EDFScheduler { +public: + EDFScheduler(); + virtual ~EDFScheduler(); + void run(task_set&,int); + bool test(task_set&); +private: + edf_queue m_queue; +}; + +#endif /* EDFSCHEDULER_H_ */ diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Global.h b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Global.h new file mode 100644 index 0000000..b2a91ef --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Global.h @@ -0,0 +1,13 @@ +/* + * Global.h + * + * Created on: 31.10.2010 + * Author: sven + */ + +#ifndef GLOBAL_H_ +#define GLOBAL_H_ + +using namespace std; + +#endif /* GLOBAL_H_ */ diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.cpp new file mode 100644 index 0000000..df1bcdd --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.cpp @@ -0,0 +1,64 @@ +/* + * RMSScheduler.cpp + * + * Created on: 02.11.2010 + * Author: sven + */ + +#include "RMSScheduler.h" + +#ifndef RESPONSETIMEANALYSIS_H_ + #include "ResponseTimeAnalysis.h" +#endif + +#include + +RMSScheduler::RMSScheduler() { + // TODO Auto-generated constructor stub + +} + +RMSScheduler::~RMSScheduler() { + // TODO Auto-generated destructor stub +} +void RMSScheduler::run(task_set& tasks,int ci) +{ + cout << "R M S" << endl; + for(unsigned int task_count = 0; task_count < tasks.size(); task_count++) + { + m_queue.push(&tasks[task_count]); + } + ResponseTimeAnalysis rta; + if(!rta.analyse(m_queue)) { + cout << "Task set not runnable. RTA failed" << endl; + return; + } + while (!m_queue.empty()) { + Task* t = m_queue.top(); + t->dump(); + m_queue.pop(); + } + for(int step= 0; step < ci; step++) + { + cout << (step + 1) << " "; + for(unsigned int task_count = 0; task_count < tasks.size(); task_count++) + { + m_queue.push(&tasks[task_count]); + } + bool scheduledAtask = false; + while (!m_queue.empty()) { + Task* t = m_queue.top(); + if(!scheduledAtask && (t->getActC() > 0) ) { + t->execute(); + scheduledAtask = true; + } else { + t->requeue(); + } + m_queue.pop(); + } + if (!scheduledAtask) { + cout << "no task needs to run"; + } + cout << endl; + } +} diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.h b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.h new file mode 100644 index 0000000..5d93fba --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/RMSScheduler.h @@ -0,0 +1,40 @@ +/* + * RMSScheduler.h + * + * Created on: 02.11.2010 + * Author: sven + */ + +#ifndef RMSSCHEDULER_H_ +#define RMSSCHEDULER_H_ + +#ifndef TASK_H_ + #include "Task.h" +#endif + +#include + +class RMSComparator; + +typedef priority_queue,RMSComparator> rms_queue; + +class RMSComparator +{ +public: + bool operator()(Task*& a, Task*& b) const + { + return ( b->getOrigP() < a->getOrigP() ); + } +}; + + +class RMSScheduler { +public: + RMSScheduler(); + virtual ~RMSScheduler(); + void run(task_set&,int); +private: + rms_queue m_queue; +}; + +#endif /* RMSSCHEDULER_H_ */ 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 +#include +#include + +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_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 higherPriorizedTasks(c); + for(unsigned int j=0;jgetName() << " has " << higherPriorizedTasks.size() << " higher priorized tasks: "; + for(unsigned int j=0;jgetName(); + } + 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(ri)/static_cast(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(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 prios(N); + for(unsigned int p=0;pgetName() << " with prio " << actPrio << endl; + + // find tasks with higher priority + vector higherPrioTasks; + unsigned int higherPrioTasksCounter = 0; + for(unsigned int taskPrio=actPrio+1;taskPriogetName() << " to tasks with higher prio" <getOrigC(); + if(higherPrioTasksCounter > 0) { + do { + int rii = candidate->getOrigC(); + for(unsigned int k=0;k(ri)/static_cast(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;cgetName() << endl; + } + } + } +} +void ResponseTimeAnalysis::swap(vector& prios,int a,int b) +{ + Task *taskA = prios[a]; + Task *taskB = prios[b]; + cout << "Swapping " << taskA->getName() << " ("<getName() << " (" < +#include + +class ResponseTimeAnalysis { +public: + ResponseTimeAnalysis(); + virtual ~ResponseTimeAnalysis(); + bool analyse(rms_queue&); + void calcOptimalStaticPriorities(task_set&); + void swap(vector&,int,int); +}; + +#endif /* RESPONSETIMEANALYSIS_H_ */ diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.cpp new file mode 100644 index 0000000..0f3edf8 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.cpp @@ -0,0 +1,81 @@ +/* + * Task.cpp + * + * Created on: 31.10.2010 + * Author: sven + */ + +#include "Task.h" +#include + +Task::Task() { + // TODO Auto-generated constructor stub + +} + +Task::Task(char* name,int c,int p,int d) +:m_Name(name),m_origC(c),m_origP(p),m_origD(d),m_actC(c),m_actD(d) +,m_stepCounter(0),m_absoluteStepCounter(0) +{ +// this->dump(); +} +Task::~Task() { + // TODO Auto-generated destructor stub +} +void Task::dump() const { + cout << "Task: " << m_Name << " " << m_origC << " " + << m_origP << " " << m_origD << endl; +} +void Task::dumpStep() const { + cout << endl << m_Name << " actD " << m_actD << " actC " << m_actC + << " stepcounter " << m_stepCounter; +} +void Task::execute() { +// if (m_actC <= 0) { +// cout << " " << getName() << " execute error: actC <= 0 : " << m_actC << endl; +// } else { +// m_actC--; +// } +// if (m_actD < 0) { +// cout << " " << getName() << " execute error: actD < 0 : " << m_actD; +// } else { +// m_actD--; +// } + m_actC--; + m_actD--; + m_stepCounter++; + m_absoluteStepCounter++; + checkPeriod(); + cout << getName(); +} +void Task::requeue() { +// if (m_actD < 0) { +// cout << " " << getName() << " requeue error: actD < 0 : " << m_actD; +// } else { +// m_actD--; +// } + if(m_actC > 0) { + m_actD--; + } + m_stepCounter++; + m_absoluteStepCounter++; + checkPeriod(); +} +void Task::checkPeriod() { + if(m_stepCounter == m_origP) { + if( (m_actC > 0) && (m_actD > 0) ) { + cout << " deadline miss "; + dumpStep(); + } + m_stepCounter = 0; + m_actC = m_origC; + m_actD = m_origD; + } +} +int Task::getNextDeadline() +{ + double numDeadlines = std::floor(static_cast(m_absoluteStepCounter) / static_cast(m_origD)); + double nextDeadline = m_origD * (numDeadlines+1); + cout << "Next deadline of task " <(nextDeadline); +} diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.h b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.h new file mode 100644 index 0000000..bd8c773 --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/Task.h @@ -0,0 +1,117 @@ +/* + * Task.h + * + * Created on: 31.10.2010 + * Author: sven + */ + +#ifndef TASK_H_ +#define TASK_H_ + +#ifndef GLOBAL_H_ + #include "Global.h" +#endif + +#include +#include +#include + +class Task; + +typedef vector task_set; + +class Task { +public: + Task(); + Task(char*,int,int,int); + virtual ~Task(); + + void dump() const; + void dumpStep() const; + void execute(); + void requeue(); + void checkPeriod(); + + int getStepCounter() const + { + return m_stepCounter; + } + + void setStepCounter(int m_stepCounter) + { + this->m_stepCounter = m_stepCounter; + } + + int getActC() const + { + return m_actC; + } + + int getActD() const + { + return m_actD; + } + + string getName() const + { + return m_Name; + } + + int getOrigC() const + { + return m_origC; + } + + int getOrigD() const + { + return m_origD; + } + + int getOrigP() const + { + return m_origP; + } + + void setActC(int m_actC) + { + this->m_actC = m_actC; + } + + void setActD(int m_actD) + { + this->m_actD = m_actD; + } + + void setName(string m_Name) + { + this->m_Name = m_Name; + } + + void setOrigC(int m_origC) + { + this->m_origC = m_origC; + } + + void setOrigD(int m_origD) + { + this->m_origD = m_origD; + } + + void setOrigP(int m_origP) + { + this->m_origP = m_origP; + } + int getNextDeadline(); + +private: + string m_Name; + int m_origC; + int m_origP; + int m_origD; + int m_actC; + int m_actD; + int m_stepCounter; + int m_absoluteStepCounter; +}; + +#endif /* TASK_H_ */ diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp new file mode 100644 index 0000000..c616f9b --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/src/main.cpp @@ -0,0 +1,99 @@ +/* + * main.cpp + * + * Created on: 31.10.2010 + * Author: sven + */ +#ifndef GLOBAL_H_ + #include "Global.h" +#endif +#ifndef TASK_H_ + #include "Task.h" +#endif +#ifndef RMSSCHEDULER_H_ + #include "RMSScheduler.h" +#endif +#ifndef DMSSCHEDULER_H_ + #include "DMSScheduler.h" +#endif +#ifndef EDFSCHEDULER_H_ + #include "EDFScheduler.h" +#endif +#ifndef RESPONSETIMEANALYSIS_H_ + #include "ResponseTimeAnalysis.h" +#endif + +#include +#include +#include +#include + +const char* TASKS_FILE_NAME = "tasks.txt"; + +int lcm(int,int); +int gcd(int,int); +int load_tasks(const char*,task_set&); + +int main(int argc,char* argv[]) +{ + int ci = 1; + task_set tasks; + load_tasks(TASKS_FILE_NAME,tasks); + for(uint i=0;i> name >> c >> p >> d; + if(name[0] != 0) { + Task t(&name[0],c,p,d); + tasks.push_back(t); + } + } + task_file.close(); + return EXIT_SUCCESS; +} +// Least Common Multiple +int lcm(int a, int b) +{ + return (a*b)/gcd(a, b); +} +// Greatest Common Divisor +int gcd(int a, int b) +{ + if(b == 0) + { + return a; + } + if(a == 0) + { + return b; + } + return gcd(b, a%b); +} diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt b/Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt new file mode 100644 index 0000000..02017ab --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt @@ -0,0 +1,4 @@ +A 1 3 3 +B 1 6 6 +C 1 5 5 +D 2 10 10 \ No newline at end of file diff --git a/Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt.20101107save01 b/Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt.20101107save01 new file mode 100644 index 0000000..40eb8ab --- /dev/null +++ b/Master/Real-Time Systems/Praktikum1/Aufgabe3/tasks.txt.20101107save01 @@ -0,0 +1,4 @@ +A 1 3 3 +B 1 6 6 +C 1 5 5 +D 2 10 9 \ No newline at end of file -- cgit v1.2.3