Commit 8c875f2f by Tobias Langer

embb_time_t time stamps

The implementation now uses embb_time_t time stamps instead of uin64_t
time stamps. Thereby time checks now rely on embb internals, instead of
more clumsy comparissons.

Furthermore this allows to use the embb::base::Duration on EMBB level
and thus setting _relative_ deadlines, instead of _absolute_ deadlines
on task creation.
parent bbcf9e23
...@@ -63,6 +63,15 @@ class Time { ...@@ -63,6 +63,15 @@ class Time {
embb_time_in(&rep_, &(duration.rep_)); embb_time_in(&rep_, &(duration.rep_));
} }
#ifdef EMBB_HARD_REALTIME
/**
* Return the internal representation of the current moment in time of the
* MTAPI C interface. This is necessary for communication with the MTAPI
* layer.
*/
embb_time_t GetRepresentation();
#endif /*EMBB_HARD_REALTIME*/
private: private:
/** /**
* Representation of the absolute time point. * Representation of the absolute time point.
......
...@@ -36,6 +36,12 @@ Time::Time() : rep_() { ...@@ -36,6 +36,12 @@ Time::Time() : rep_() {
embb_time_now(&rep_); embb_time_now(&rep_);
} }
#ifdef EMBB_HARD_REALTIME
embb_time_t Time::GetRepresentation() {
return rep_;
}
#endif /*EMBB_HARD_REALTIME*/
} // namespace base } // namespace base
} // namespace embb } // namespace embb
......
...@@ -245,6 +245,9 @@ ...@@ -245,6 +245,9 @@
#include <stdint.h> #include <stdint.h>
#include <embb/base/c/core_set.h> #include <embb/base/c/core_set.h>
#include <embb/base/c/thread.h> #include <embb/base/c/thread.h>
#ifdef EMBB_HARD_REALTIME
#include <embb/base/c/time.h>
#endif /*EMBB_HARD_REALTIME*/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -753,7 +756,7 @@ enum mtapi_task_attributes_enum { ...@@ -753,7 +756,7 @@ enum mtapi_task_attributes_enum {
#define MTAPI_TASK_AFFINITY_SIZE sizeof(mtapi_affinity_t) #define MTAPI_TASK_AFFINITY_SIZE sizeof(mtapi_affinity_t)
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
/** size of the \a MTAPI_TASK_DEADLINE attribute */ /** size of the \a MTAPI_TASK_DEADLINE attribute */
#define MTAPI_TASK_DEADLINE_SIZE sizeof(mtapi_uint64_t) #define MTAPI_TASK_DEADLINE_SIZE sizeof(embb_time_t)
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
...@@ -851,7 +854,7 @@ struct mtapi_task_attributes_struct { ...@@ -851,7 +854,7 @@ struct mtapi_task_attributes_struct {
mtapi_uint_t num_instances; /**< stores MTAPI_TASK_INSTANCES */ mtapi_uint_t num_instances; /**< stores MTAPI_TASK_INSTANCES */
mtapi_uint_t priority; /**< stores MTAPI_TASK_PRIORITY */ mtapi_uint_t priority; /**< stores MTAPI_TASK_PRIORITY */
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
mtapi_uint64_t deadline; /**< stores MTAPI_TASK_DEADLINE */ embb_time_t deadline; /**< stores MTAPI_TASK_DEADLINE */
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
mtapi_affinity_t affinity; /**< stores MTAPI_TASK_AFFINITY */ mtapi_affinity_t affinity; /**< stores MTAPI_TASK_AFFINITY */
void * user_data; /**< stores MTAPI_TASK_USER_DATA */ void * user_data; /**< stores MTAPI_TASK_USER_DATA */
......
...@@ -61,7 +61,7 @@ mtapi_status_t embb_mtapi_attr_get_##TYPE(const TYPE* source, \ ...@@ -61,7 +61,7 @@ mtapi_status_t embb_mtapi_attr_get_##TYPE(const TYPE* source, \
embb_mtapi_attr_implementation(mtapi_uint_t); embb_mtapi_attr_implementation(mtapi_uint_t);
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
embb_mtapi_attr_implementation(mtapi_uint64_t); embb_mtapi_attr_implementation(embb_time_t);
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
embb_mtapi_attr_implementation(mtapi_affinity_t); embb_mtapi_attr_implementation(mtapi_affinity_t);
embb_mtapi_attr_implementation(mtapi_boolean_t); embb_mtapi_attr_implementation(mtapi_boolean_t);
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
#define MTAPI_C_SRC_EMBB_MTAPI_ATTR_H_ #define MTAPI_C_SRC_EMBB_MTAPI_ATTR_H_
#include <embb/mtapi/c/mtapi.h> #include <embb/mtapi/c/mtapi.h>
#ifdef EMBB_HARD_REALTIME
#include <embb/base/c/time.h>
#endif /*EMBB_HARD_REALTIME*/
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -42,7 +45,7 @@ mtapi_status_t embb_mtapi_attr_get_##TYPE(const TYPE* source, \ ...@@ -42,7 +45,7 @@ mtapi_status_t embb_mtapi_attr_get_##TYPE(const TYPE* source, \
embb_mtapi_attr(mtapi_uint_t) embb_mtapi_attr(mtapi_uint_t)
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
embb_mtapi_attr(mtapi_uint64_t); embb_mtapi_attr(embb_time_t);
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
embb_mtapi_attr(mtapi_affinity_t) embb_mtapi_attr(mtapi_affinity_t)
embb_mtapi_attr(mtapi_boolean_t) embb_mtapi_attr(mtapi_boolean_t)
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <embb/mtapi/c/mtapi.h> #include <embb/mtapi/c/mtapi.h>
#include <embb/base/c/atomic.h> #include <embb/base/c/atomic.h>
#include <embb/base/c/time.h>
#include <embb_mtapi_log.h> #include <embb_mtapi_log.h>
#include <embb_mtapi_priority_queue_t.h> #include <embb_mtapi_priority_queue_t.h>
#include <embb_mtapi_task_t.h> #include <embb_mtapi_task_t.h>
...@@ -42,9 +44,9 @@ ...@@ -42,9 +44,9 @@
/* ---- LOCAL HELPERS ------------------------------------------------------ */ /* ---- LOCAL HELPERS ------------------------------------------------------ */
static mtapi_uint64_t get_deadline(mtapi_task_hndl_t node) { static embb_time_t get_deadline(mtapi_task_hndl_t node) {
mtapi_status_t status; mtapi_status_t status;
mtapi_uint64_t deadline; embb_time_t deadline;
mtapi_task_get_attribute( mtapi_task_get_attribute(
node, node,
MTAPI_TASK_DEADLINE, MTAPI_TASK_DEADLINE,
...@@ -53,7 +55,8 @@ static mtapi_uint64_t get_deadline(mtapi_task_hndl_t node) { ...@@ -53,7 +55,8 @@ static mtapi_uint64_t get_deadline(mtapi_task_hndl_t node) {
&status); &status);
if(status != MTAPI_SUCCESS) { if(status != MTAPI_SUCCESS) {
// TODO error handling // TODO error handling
return -1; embb_time_t ret;
return ret;
} }
return deadline; return deadline;
} }
...@@ -103,11 +106,11 @@ embb_mtapi_task_t * embb_mtapi_priority_queue_pop(embb_mtapi_priority_queue_t* t ...@@ -103,11 +106,11 @@ embb_mtapi_task_t * embb_mtapi_priority_queue_pop(embb_mtapi_priority_queue_t* t
embb_mtapi_task_t * task = MTAPI_NULL; embb_mtapi_task_t * task = MTAPI_NULL;
embb_mtapi_task_t * tmp_task = MTAPI_NULL; embb_mtapi_task_t * tmp_task = MTAPI_NULL;
mtapi_uint_t ii; mtapi_uint_t ii;
mtapi_uint64_t deadline = 0; embb_time_t deadline;
mtapi_uint64_t left_deadline = 0; embb_time_t left_deadline;
mtapi_uint64_t right_deadline = 0; embb_time_t right_deadline;
mtapi_uint64_t swap = 0; mtapi_uint64_t swap = 0;
mtapi_uint64_t swap_deadline = 0; embb_time_t swap_deadline;
assert(MTAPI_NULL != that); assert(MTAPI_NULL != that);
...@@ -131,26 +134,28 @@ embb_mtapi_task_t * embb_mtapi_priority_queue_pop(embb_mtapi_priority_queue_t* t ...@@ -131,26 +134,28 @@ embb_mtapi_task_t * embb_mtapi_priority_queue_pop(embb_mtapi_priority_queue_t* t
if(that->task_buffer[ii + 1] != MTAPI_NULL) { if(that->task_buffer[ii + 1] != MTAPI_NULL) {
left_deadline = get_deadline(that->task_buffer[ii + 1]->handle); left_deadline = get_deadline(that->task_buffer[ii + 1]->handle);
} else { } else {
left_deadline = ULLONG_MAX; left_deadline.seconds = ULLONG_MAX;
left_deadline.nanoseconds = ULONG_MAX;
} }
if(that->task_buffer[ii + 2] != MTAPI_NULL) { if(that->task_buffer[ii + 2] != MTAPI_NULL) {
right_deadline = get_deadline(that->task_buffer[ii + 2]->handle); right_deadline = get_deadline(that->task_buffer[ii + 2]->handle);
} else { } else {
right_deadline = ULLONG_MAX; right_deadline.seconds = ULLONG_MAX;
right_deadline.nanoseconds = ULONG_MAX;
} }
/* min Heap, swap with the smaller of both children. */ /* min Heap, swap with the smaller of both children. */
if(left_deadline <= right_deadline) { if(embb_time_compare(&left_deadline, &right_deadline) <= 0) {
swap = ii + 1; swap = ii + 1;
swap_deadline = left_deadline; swap_deadline = left_deadline;
} else if(right_deadline < left_deadline) { } else if(embb_time_compare(&left_deadline, &right_deadline) > 0) {
swap = ii + 2; swap = ii + 2;
swap_deadline = right_deadline; swap_deadline = right_deadline;
} }
/* abort if heap property is restored. */ /* abort if heap property is restored. */
if(deadline <= swap_deadline) { if(embb_time_compare(&deadline, &swap_deadline) <= 0) {
break; break;
} }
...@@ -173,8 +178,8 @@ mtapi_boolean_t embb_mtapi_priority_queue_push( ...@@ -173,8 +178,8 @@ mtapi_boolean_t embb_mtapi_priority_queue_push(
embb_mtapi_task_t * tmp_task = MTAPI_NULL; embb_mtapi_task_t * tmp_task = MTAPI_NULL;
mtapi_uint_t ii; mtapi_uint_t ii;
mtapi_uint_t kk; mtapi_uint_t kk;
mtapi_uint64_t deadline = 0; embb_time_t deadline;
mtapi_uint64_t parent_deadline = 0; embb_time_t parent_deadline;
mtapi_boolean_t result = MTAPI_FALSE; mtapi_boolean_t result = MTAPI_FALSE;
assert(MTAPI_NULL != that); assert(MTAPI_NULL != that);
...@@ -195,7 +200,7 @@ mtapi_boolean_t embb_mtapi_priority_queue_push( ...@@ -195,7 +200,7 @@ mtapi_boolean_t embb_mtapi_priority_queue_push(
parent_deadline = get_deadline(that->task_buffer[ii]->handle); parent_deadline = get_deadline(that->task_buffer[ii]->handle);
/* abort if heap property is restored. */ /* abort if heap property is restored. */
if(deadline >= parent_deadline) { if(embb_time_compare(&deadline, &parent_deadline) >= 0) {
break; break;
} }
......
...@@ -442,7 +442,7 @@ void mtapi_task_get_attribute( ...@@ -442,7 +442,7 @@ void mtapi_task_get_attribute(
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
case MTAPI_TASK_DEADLINE: case MTAPI_TASK_DEADLINE:
local_status = embb_mtapi_attr_get_mtapi_uint64_t( local_status = embb_mtapi_attr_get_embb_time_t(
&local_task->attributes.deadline, attribute, attribute_size); &local_task->attributes.deadline, attribute, attribute_size);
break; break;
......
...@@ -104,7 +104,7 @@ void mtapi_taskattr_set( ...@@ -104,7 +104,7 @@ void mtapi_taskattr_set(
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
case MTAPI_TASK_DEADLINE: case MTAPI_TASK_DEADLINE:
local_status = embb_mtapi_attr_set_mtapi_uint64_t( local_status = embb_mtapi_attr_set_embb_time_t(
&attributes->deadline, attribute, attribute_size); &attributes->deadline, attribute, attribute_size);
break; break;
......
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
#define EMBB_MTAPI_EXECUTION_POLICY_H_ #define EMBB_MTAPI_EXECUTION_POLICY_H_
#include <embb/mtapi/c/mtapi.h> #include <embb/mtapi/c/mtapi.h>
#ifdef EMBB_HARD_REALTIME
#include <embb/base/duration.h>
#include <embb/base/time.h>
#endif /*EMBB_HARD_REALTIME*/
#include <embb/mtapi/internal/cmake_config.h> #include <embb/mtapi/internal/cmake_config.h>
namespace embb { namespace embb {
...@@ -79,10 +83,18 @@ class ExecutionPolicy{ ...@@ -79,10 +83,18 @@ class ExecutionPolicy{
* Constructs an execution policy with the specified priority. * Constructs an execution policy with the specified priority.
* Sets the affinity to all worker threads. * Sets the affinity to all worker threads.
*/ */
template <typename Tick>
explicit ExecutionPolicy( explicit ExecutionPolicy(
mtapi_uint64_t deadline /**< [in] Relative dealine for the embb::base::Duration<Tick> relative_deadline /**< [in] Relative dealine
execution policy. */ for the execution policy.*/
); ) : priority_(DefaultPriority), deadline_(relative_deadline) {
InitializeWithDeadline();
}
/**
* Initialize the ExecutionPolicy object. Necessary to prevent include loops.
*/
void InitializeWithDeadline();
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
/** /**
...@@ -143,7 +155,7 @@ class ExecutionPolicy{ ...@@ -143,7 +155,7 @@ class ExecutionPolicy{
* *
* \return the deadline * \return the deadline
*/ */
mtapi_uint_t GetDeadline() const; embb::base::Time GetDeadline() const;
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
friend class Task; friend class Task;
...@@ -158,9 +170,8 @@ class ExecutionPolicy{ ...@@ -158,9 +170,8 @@ class ExecutionPolicy{
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
/** /**
* Default deadline. * Default deadline.
* Currently set to UULONG_MAX = MAX deadline.
*/ */
static const mtapi_uint64_t DefaultDeadline; static const embb::base::Time DefaultDeadline;
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
/** /**
...@@ -178,7 +189,7 @@ class ExecutionPolicy{ ...@@ -178,7 +189,7 @@ class ExecutionPolicy{
/** /**
* Task Priority. * Task Priority.
*/ */
mtapi_uint64_t deadline_; embb::base::Time deadline_;
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
}; };
......
...@@ -150,11 +150,12 @@ class TaskAttributes { ...@@ -150,11 +150,12 @@ class TaskAttributes {
* \notthreadsafe * \notthreadsafe
*/ */
TaskAttributes & SetDeadline( TaskAttributes & SetDeadline(
mtapi_uint64_t deadline /**< The deadline to set. */ embb::base::Time deadline /**< The deadline to set. */
) { ) {
embb_time_t c_deadline = deadline.GetRepresentation();
mtapi_status_t status; mtapi_status_t status;
mtapi_taskattr_set(&attributes_, MTAPI_TASK_DEADLINE, mtapi_taskattr_set(&attributes_, MTAPI_TASK_DEADLINE,
&deadline, sizeof(deadline), &status); &c_deadline, sizeof(c_deadline), &status);
internal::CheckStatus(status); internal::CheckStatus(status);
return *this; return *this;
} }
......
...@@ -86,14 +86,13 @@ ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority) ...@@ -86,14 +86,13 @@ ExecutionPolicy::ExecutionPolicy(mtapi_uint_t priority)
} }
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
ExecutionPolicy::ExecutionPolicy(mtapi_uint64_t deadline) void ExecutionPolicy::InitializeWithDeadline() {
: priority_(DefaultPriority), deadline_(deadline) { #ifdef MTAPI_CPP_AUTOMATIC_INITIALIZE
#if MTAPI_CPP_AUTOMATIC_INITIALIZE
Node::GetInstance(); // MTAPI has to be initialized Node::GetInstance(); // MTAPI has to be initialized
#endif #endif
mtapi_status_t status; mtapi_status_t status;
mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status); mtapi_affinity_init(&affinity_, MTAPI_TRUE, &status);
if (MTAPI_SUCCESS != status) { if(MTAPI_SUCCESS != status) {
EMBB_THROW(embb::base::ErrorException, EMBB_THROW(embb::base::ErrorException,
"Could not default construct Affinity."); "Could not default construct Affinity.");
} }
...@@ -150,15 +149,13 @@ mtapi_uint_t ExecutionPolicy::GetPriority() const { ...@@ -150,15 +149,13 @@ mtapi_uint_t ExecutionPolicy::GetPriority() const {
} }
#ifdef EMBB_HARD_REALTIME #ifdef EMBB_HARD_REALTIME
mtapi_uint_t ExecutionPolicy::GetDeadline() const { embb::base::Time ExecutionPolicy::GetDeadline() const {
return deadline_; return deadline_;
} }
const embb::base::Time ExecutionPolicy::DefaultDeadline;
#endif /*EMBB_HARD_REALTIME*/ #endif /*EMBB_HARD_REALTIME*/
const mtapi_uint_t ExecutionPolicy::DefaultPriority = 0; 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 mtapi
} // namespace embb } // namespace embb
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment