Commit d64c016f 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 80461219
......@@ -63,6 +63,15 @@ class Time {
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:
/**
* Representation of the absolute time point.
......
......@@ -36,6 +36,12 @@ Time::Time() : rep_() {
embb_time_now(&rep_);
}
#ifdef EMBB_HARD_REALTIME
embb_time_t Time::GetRepresentation() {
return rep_;
}
#endif /*EMBB_HARD_REALTIME*/
} // namespace base
} // namespace embb
......
......@@ -245,6 +245,9 @@
#include <stdint.h>
#include <embb/base/c/core_set.h>
#include <embb/base/c/thread.h>
#ifdef EMBB_HARD_REALTIME
#include <embb/base/c/time.h>
#endif /*EMBB_HARD_REALTIME*/
#ifdef __cplusplus
extern "C" {
......@@ -753,7 +756,7 @@ enum mtapi_task_attributes_enum {
#define MTAPI_TASK_AFFINITY_SIZE sizeof(mtapi_affinity_t)
#ifdef EMBB_HARD_REALTIME
/** 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*/
......@@ -851,7 +854,7 @@ struct mtapi_task_attributes_struct {
mtapi_uint_t num_instances; /**< stores MTAPI_TASK_INSTANCES */
mtapi_uint_t priority; /**< stores MTAPI_TASK_PRIORITY */
#ifdef EMBB_HARD_REALTIME
mtapi_uint64_t deadline; /**< stores MTAPI_TASK_DEADLINE */
embb_time_t deadline; /**< stores MTAPI_TASK_DEADLINE */
#endif /*EMBB_HARD_REALTIME*/
mtapi_affinity_t affinity; /**< stores MTAPI_TASK_AFFINITY */
void * user_data; /**< stores MTAPI_TASK_USER_DATA */
......
......@@ -61,7 +61,7 @@ mtapi_status_t embb_mtapi_attr_get_##TYPE(const TYPE* source, \
embb_mtapi_attr_implementation(mtapi_uint_t);
#ifdef EMBB_HARD_REALTIME
embb_mtapi_attr_implementation(mtapi_uint64_t);
embb_mtapi_attr_implementation(embb_time_t);
#endif /*EMBB_HARD_REALTIME*/
embb_mtapi_attr_implementation(mtapi_affinity_t);
embb_mtapi_attr_implementation(mtapi_boolean_t);
......@@ -28,6 +28,9 @@
#define MTAPI_C_SRC_EMBB_MTAPI_ATTR_H_
#include <embb/mtapi/c/mtapi.h>
#ifdef EMBB_HARD_REALTIME
#include <embb/base/c/time.h>
#endif /*EMBB_HARD_REALTIME*/
#ifdef __cplusplus
extern "C" {
......@@ -42,7 +45,7 @@ mtapi_status_t embb_mtapi_attr_get_##TYPE(const TYPE* source, \
embb_mtapi_attr(mtapi_uint_t)
#ifdef EMBB_HARD_REALTIME
embb_mtapi_attr(mtapi_uint64_t);
embb_mtapi_attr(embb_time_t);
#endif /*EMBB_HARD_REALTIME*/
embb_mtapi_attr(mtapi_affinity_t)
embb_mtapi_attr(mtapi_boolean_t)
......
......@@ -33,6 +33,8 @@
#include <embb/mtapi/c/mtapi.h>
#include <embb/base/c/atomic.h>
#include <embb/base/c/time.h>
#include <embb_mtapi_log.h>
#include <embb_mtapi_priority_queue_t.h>
#include <embb_mtapi_task_t.h>
......@@ -42,9 +44,9 @@
/* ---- 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_uint64_t deadline;
embb_time_t deadline;
mtapi_task_get_attribute(
node,
MTAPI_TASK_DEADLINE,
......@@ -53,7 +55,8 @@ static mtapi_uint64_t get_deadline(mtapi_task_hndl_t node) {
&status);
if(status != MTAPI_SUCCESS) {
// TODO error handling
return -1;
embb_time_t ret;
return ret;
}
return deadline;
}
......@@ -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 * tmp_task = MTAPI_NULL;
mtapi_uint_t ii;
mtapi_uint64_t deadline = 0;
mtapi_uint64_t left_deadline = 0;
mtapi_uint64_t right_deadline = 0;
embb_time_t deadline;
embb_time_t left_deadline;
embb_time_t right_deadline;
mtapi_uint64_t swap = 0;
mtapi_uint64_t swap_deadline = 0;
embb_time_t swap_deadline;
assert(MTAPI_NULL != that);
......@@ -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) {
left_deadline = get_deadline(that->task_buffer[ii + 1]->handle);
} else {
left_deadline = ULLONG_MAX;
left_deadline.seconds = ULLONG_MAX;
left_deadline.nanoseconds = ULONG_MAX;
}
if(that->task_buffer[ii + 2] != MTAPI_NULL) {
right_deadline = get_deadline(that->task_buffer[ii + 2]->handle);
} else {
right_deadline = ULLONG_MAX;
right_deadline.seconds = ULLONG_MAX;
right_deadline.nanoseconds = ULONG_MAX;
}
/* 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_deadline = left_deadline;
} else if(right_deadline < left_deadline) {
} else if(embb_time_compare(&left_deadline, &right_deadline) > 0) {
swap = ii + 2;
swap_deadline = right_deadline;
}
/* abort if heap property is restored. */
if(deadline <= swap_deadline) {
if(embb_time_compare(&deadline, &swap_deadline) <= 0) {
break;
}
......@@ -173,8 +178,8 @@ mtapi_boolean_t embb_mtapi_priority_queue_push(
embb_mtapi_task_t * tmp_task = MTAPI_NULL;
mtapi_uint_t ii;
mtapi_uint_t kk;
mtapi_uint64_t deadline = 0;
mtapi_uint64_t parent_deadline = 0;
embb_time_t deadline;
embb_time_t parent_deadline;
mtapi_boolean_t result = MTAPI_FALSE;
assert(MTAPI_NULL != that);
......@@ -195,7 +200,7 @@ mtapi_boolean_t embb_mtapi_priority_queue_push(
parent_deadline = get_deadline(that->task_buffer[ii]->handle);
/* abort if heap property is restored. */
if(deadline >= parent_deadline) {
if(embb_time_compare(&deadline, &parent_deadline) >= 0) {
break;
}
......
......@@ -441,7 +441,7 @@ void mtapi_task_get_attribute(
#ifdef EMBB_HARD_REALTIME
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);
break;
......
......@@ -104,7 +104,7 @@ void mtapi_taskattr_set(
#ifdef EMBB_HARD_REALTIME
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);
break;
......
......@@ -28,6 +28,10 @@
#define EMBB_MTAPI_EXECUTION_POLICY_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>
namespace embb {
......@@ -79,10 +83,18 @@ class ExecutionPolicy{
* Constructs an execution policy with the specified priority.
* Sets the affinity to all worker threads.
*/
template <typename Tick>
explicit ExecutionPolicy(
mtapi_uint64_t deadline /**< [in] Relative dealine for the
execution policy. */
);
embb::base::Duration<Tick> relative_deadline /**< [in] Relative dealine
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*/
/**
......@@ -143,7 +155,7 @@ class ExecutionPolicy{
*
* \return the deadline
*/
mtapi_uint_t GetDeadline() const;
embb::base::Time GetDeadline() const;
#endif /*EMBB_HARD_REALTIME*/
friend class Task;
......@@ -158,9 +170,8 @@ class ExecutionPolicy{
#ifdef EMBB_HARD_REALTIME
/**
* 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*/
/**
......@@ -178,7 +189,7 @@ class ExecutionPolicy{
/**
* Task Priority.
*/
mtapi_uint64_t deadline_;
embb::base::Time deadline_;
#endif /*EMBB_HARD_REALTIME*/
};
......
......@@ -143,11 +143,12 @@ class TaskAttributes {
* \notthreadsafe
*/
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_taskattr_set(&attributes_, MTAPI_TASK_DEADLINE,
&deadline, sizeof(deadline), &status);
&c_deadline, sizeof(c_deadline), &status);
internal::CheckStatus(status);
return *this;
}
......
......@@ -86,14 +86,13 @@ 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
void ExecutionPolicy::InitializeWithDeadline() {
#ifdef 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) {
if(MTAPI_SUCCESS != status) {
EMBB_THROW(embb::base::ErrorException,
"Could not default construct Affinity.");
}
......@@ -150,15 +149,13 @@ mtapi_uint_t ExecutionPolicy::GetPriority() const {
}
#ifdef EMBB_HARD_REALTIME
mtapi_uint_t ExecutionPolicy::GetDeadline() const {
embb::base::Time ExecutionPolicy::GetDeadline() const {
return deadline_;
}
const embb::base::Time ExecutionPolicy::DefaultDeadline;
#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
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