From 18ac4ca537b2b2a22e9d5acdd282788a1366927c Mon Sep 17 00:00:00 2001 From: Tobias Langer Date: Tue, 23 Aug 2016 15:02:27 +0200 Subject: [PATCH] Deadline support for EMBB layer The EMBB layer was extended so tasks now can be started with the deadline property. In order to specify a deadline for a task / group of tasks the class ExecutionPolicy must be instanciated. Here the required deadline may be set. --- mtapi_cpp/include/embb/mtapi/execution_policy.h | 34 ++++++++++++++++++++++++++++++++++ mtapi_cpp/include/embb/mtapi/task_attributes.h | 3 +++ mtapi_cpp/src/execution_policy.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/mtapi_cpp/include/embb/mtapi/execution_policy.h b/mtapi_cpp/include/embb/mtapi/execution_policy.h index 19d53ef..78b61c4 100644 --- a/mtapi_cpp/include/embb/mtapi/execution_policy.h +++ b/mtapi_cpp/include/embb/mtapi/execution_policy.h @@ -74,6 +74,17 @@ class ExecutionPolicy{ policy. */ ); +#ifdef EMBB_HARD_REALTIME + /** + * Constructs an execution policy with the specified priority. + * Sets the affinity to all worker threads. + */ + explicit ExecutionPolicy( + mtapi_uint64_t deadline /**< [in] Relative dealine for the + execution policy. */ + ); + +#endif /*EMBB_HARD_REALTIME*/ /** * Constructs an execution policy with the specified affinity. * Sets the priority to the default value. @@ -127,6 +138,14 @@ class ExecutionPolicy{ */ mtapi_uint_t GetPriority() const; +#ifdef EMBB_HARD_REALTIME +/** Returns the deadline + * + * \return the deadline + */ + mtapi_uint_t GetDeadline() const; + +#endif /*EMBB_HARD_REALTIME*/ friend class Task; private: @@ -136,6 +155,14 @@ class ExecutionPolicy{ */ static const mtapi_uint_t DefaultPriority; +#ifdef EMBB_HARD_REALTIME + /** + * Default deadline. + * Currently set to UULONG_MAX = MAX deadline. + */ + static const mtapi_uint64_t DefaultDeadline; + +#endif /*EMBB_HARD_REALTIME*/ /** * Task Affinity. * Maps the affinity of tasks to MTAPI worker threads (not CPU cores). @@ -146,6 +173,13 @@ class ExecutionPolicy{ * Task Priority. */ mtapi_uint_t priority_; +#ifdef EMBB_HARD_REALTIME + + /** + * Task Priority. + */ + mtapi_uint64_t deadline_; +#endif /*EMBB_HARD_REALTIME*/ }; } // namespace mtapi diff --git a/mtapi_cpp/include/embb/mtapi/task_attributes.h b/mtapi_cpp/include/embb/mtapi/task_attributes.h index 07fc7e0..73ac8a7 100644 --- a/mtapi_cpp/include/embb/mtapi/task_attributes.h +++ b/mtapi_cpp/include/embb/mtapi/task_attributes.h @@ -108,6 +108,9 @@ class TaskAttributes { ) { SetPriority(policy.GetPriority()); SetAffinity(policy.GetAffinity()); +#ifdef EMBB_HARD_REALTIME + SetDeadline(policy.GetDeadline()); +#endif /*EMBB_HARD_REALTIME*/ return *this; } diff --git a/mtapi_cpp/src/execution_policy.cc b/mtapi_cpp/src/execution_policy.cc index 8923f18..2910340 100644 --- a/mtapi_cpp/src/execution_policy.cc +++ b/mtapi_cpp/src/execution_policy.cc @@ -34,7 +34,11 @@ namespace embb { namespace mtapi { ExecutionPolicy::ExecutionPolicy() : - priority_(DefaultPriority) { + priority_(DefaultPriority) +#ifdef MTAPI_HARD_REALTIME +, deadline_(DefaultDeadline) +#endif +{ #if MTAPI_CPP_AUTOMATIC_INITIALIZE Node::GetInstance(); // MTAPI has to be initialized #endif @@ -47,7 +51,11 @@ ExecutionPolicy::ExecutionPolicy() : } ExecutionPolicy::ExecutionPolicy(bool initial_affinity, mtapi_uint_t priority) -:priority_(priority) { +:priority_(priority) +#ifdef MTAPI_HARD_REALTIME +, deadline_(DefaultDeadline) +#endif +{ #if MTAPI_CPP_AUTOMATIC_INITIALIZE Node::GetInstance(); // MTAPI has to be initialized #endif @@ -61,7 +69,11 @@ ExecutionPolicy::ExecutionPolicy(bool initial_affinity, mtapi_uint_t priority) } ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority) -:priority_(priority) { +:priority_(priority) +#ifdef MTAPI_HARD_REALTIME +, deadline_(DefaultDeadline) +#endif +{ #if MTAPI_CPP_AUTOMATIC_INITIALIZE Node::GetInstance(); // MTAPI has to be initialized #endif @@ -73,8 +85,27 @@ ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority) } } +#ifdef EMBB_HARD_REALTIME +ExecutionPolicy::ExecutionPolicy(mtapi_uint64_t deadline) +: priority_(DefaultPriority), deadline_(deadline) { +#if MTAPI_CPP_AUTOMATIC_INITIALIZE + Node::GetInstance(); // MTAPI has to be initialized +#endif + mtapi_status_t status; + mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status); + if (MTAPI_SUCCESS != status) { + EMBB_THROW(embb::base::ErrorException, + "Could not default construct Affinity."); + } +} +#endif /*EMBB_HARD_REALTIME*/ + ExecutionPolicy::ExecutionPolicy(bool initial_affinity) -:priority_(DefaultPriority) { +:priority_(DefaultPriority) +#ifdef MTAPI_HARD_REALTIME +, deadline_(DefaultDeadline) +#endif +{ #if MTAPI_CPP_AUTOMATIC_INITIALIZE Node::GetInstance(); // MTAPI has to be initialized #endif @@ -118,7 +149,16 @@ mtapi_uint_t ExecutionPolicy::GetPriority() const { return priority_; } +#ifdef EMBB_HARD_REALTIME +mtapi_uint_t ExecutionPolicy::GetDeadline() const { + return deadline_; +} + +#endif /*EMBB_HARD_REALTIME*/ const mtapi_uint_t ExecutionPolicy::DefaultPriority = 0; +#ifdef EMBB_HARD_REALTIME +const mtapi_uint64_t ExecutionPolicy::DefaultDeadline = ULLONG_MAX; +#endif /*EMBB_HARD_REALTIME*/ } // namespace mtapi } // namespace embb -- libgit2 0.26.0