Commit 71ffb4ee by Tobias Langer

Added interface to set scheduling mode

The node struct was extended so the scheduling mode can be configured on
Node initialization. Therefore the scheduling mode struct was moved from
embb_mtapi_scheduler_t.h to mtapi.h.

The scheduling mode is now another node attribute and can be set as such
on program setup.
parent cb563b60
...@@ -621,6 +621,27 @@ struct mtapi_worker_priority_entry_struct { ...@@ -621,6 +621,27 @@ struct mtapi_worker_priority_entry_struct {
*/ */
typedef struct mtapi_worker_priority_entry_struct mtapi_worker_priority_entry_t; typedef struct mtapi_worker_priority_entry_struct mtapi_worker_priority_entry_t;
#ifdef EMBB_HARD_REALTIME
/**
* Describes the scheduling mode which is used for the tasks of a single node.
*/
enum embb_mtapi_scheduler_mode_enum {
// Victim Higher Priority First. Steal if at least one local queue is empty.
WORK_STEAL_VHPF = 0,
// Local First. Steal if all local queues are empty.
WORK_STEAL_LF = 1,
// Global EDF. No work stealing
GLOBAL_EDF = 2,
NUM_SCHEDULER_MODES
};
/**
* Describes the scheduling mode which is used for the tasks of a single node.
*/
typedef enum embb_mtapi_scheduler_mode_enum embb_mtapi_scheduler_mode_t;
#endif /*EMBB_HARD_REALTIME*/
/** /**
* Node attributes, to be extended for implementation specific attributes * Node attributes, to be extended for implementation specific attributes
*/ */
...@@ -647,6 +668,9 @@ enum mtapi_node_attributes_enum { ...@@ -647,6 +668,9 @@ enum mtapi_node_attributes_enum {
allowed by the node */ allowed by the node */
MTAPI_NODE_REUSE_MAIN_THREAD, /**< reuse main thread as worker */ MTAPI_NODE_REUSE_MAIN_THREAD, /**< reuse main thread as worker */
MTAPI_NODE_WORKER_PRIORITIES /**< set worker priorites */ MTAPI_NODE_WORKER_PRIORITIES /**< set worker priorites */
#ifdef EMBB_HARD_REALTIME
,MTAPI_NODE_SCHEDULER_MODE /**< set mode of nodes scheduler */
#endif /*EMBB_HARD_REALTIME*/
}; };
/** size of the \a MTAPI_NODE_CORE_AFFINITY attribute */ /** size of the \a MTAPI_NODE_CORE_AFFINITY attribute */
#define MTAPI_NODE_CORE_AFFINITY_SIZE sizeof(embb_core_set_t) #define MTAPI_NODE_CORE_AFFINITY_SIZE sizeof(embb_core_set_t)
...@@ -674,6 +698,11 @@ enum mtapi_node_attributes_enum { ...@@ -674,6 +698,11 @@ enum mtapi_node_attributes_enum {
#define MTAPI_NODE_REUSE_MAIN_THREAD_SIZE sizeof(mtapi_boolean_t) #define MTAPI_NODE_REUSE_MAIN_THREAD_SIZE sizeof(mtapi_boolean_t)
/** size of the \a MTAPI_NODE_WORKER_PRIORITIES attribute */ /** size of the \a MTAPI_NODE_WORKER_PRIORITIES attribute */
#define MTAPI_NODE_WORKER_PRIORITIES_SIZE 0 #define MTAPI_NODE_WORKER_PRIORITIES_SIZE 0
#ifdef EMBB_MTAPI_HARD_REALTIME
/** size of the \a MTAPI_NODE_SCHEDULER_MODE attribute */
#define MTAPI_NODE_SCHEDULER_MODE sizeof(embb_mtapi_scheduler_mode_t)
#endif /*EMBB_MTAPI_HARD_REALTIME*/
/* example attribute value */ /* example attribute value */
#define MTAPI_NODE_TYPE_SMP 1 #define MTAPI_NODE_TYPE_SMP 1
...@@ -797,6 +826,10 @@ struct mtapi_node_attributes_struct { ...@@ -797,6 +826,10 @@ struct mtapi_node_attributes_struct {
mtapi_worker_priority_entry_t * worker_priorities; mtapi_worker_priority_entry_t * worker_priorities;
/**< stores /**< stores
MTAPI_NODE_WORKER_PRIORITIES */ MTAPI_NODE_WORKER_PRIORITIES */
#ifdef EMBB_HARD_REALTIME
embb_mtapi_scheduler_mode_t scheduler_mode;
/**< stores MTAPI_NODE_SCHEDULER_MODE */
#endif /*EMBB_HARD_REALTIME*/
}; };
/** /**
...@@ -1049,6 +1082,9 @@ extern mtapi_group_hndl_t MTAPI_GROUP_NONE; ...@@ -1049,6 +1082,9 @@ extern mtapi_group_hndl_t MTAPI_GROUP_NONE;
#define MTAPI_NODE_MAX_JOBS_DEFAULT 256 #define MTAPI_NODE_MAX_JOBS_DEFAULT 256
#define MTAPI_NODE_MAX_ACTIONS_PER_JOB_DEFAULT 4 #define MTAPI_NODE_MAX_ACTIONS_PER_JOB_DEFAULT 4
#define MTAPI_NODE_MAX_PRIORITIES_DEFAULT 4 #define MTAPI_NODE_MAX_PRIORITIES_DEFAULT 4
#ifdef EMBB_HARD_REALTIME
#define MTAPI_NODE_SCHEDULER_MODE_DEFAULT WORK_STEAL_VHPF
#endif /*EMBB_HARD_REALTIME*/
#define MTAPI_JOB_ID_INVALID 0 #define MTAPI_JOB_ID_INVALID 0
#define MTAPI_DOMAIN_ID_INVALID 0 #define MTAPI_DOMAIN_ID_INVALID 0
......
...@@ -137,7 +137,12 @@ void mtapi_initialize( ...@@ -137,7 +137,12 @@ void mtapi_initialize(
if (local_status == MTAPI_SUCCESS) { if (local_status == MTAPI_SUCCESS) {
/* initialize scheduler for local node */ /* initialize scheduler for local node */
#ifdef EMBB_HARD_REALTIME
node->scheduler = embb_mtapi_scheduler_new(
node->attributes.scheduler_mode);
#else
node->scheduler = embb_mtapi_scheduler_new(); node->scheduler = embb_mtapi_scheduler_new();
#endif /*EMBB_HARD_REALTIME*/
if (MTAPI_NULL != node->scheduler) { if (MTAPI_NULL != node->scheduler) {
/* fill information structure */ /* fill information structure */
node->info.mtapi_version = 0x1000; // mtapi version 1.0 node->info.mtapi_version = 0x1000; // mtapi version 1.0
......
...@@ -604,6 +604,23 @@ void embb_mtapi_scheduler_finalize(embb_mtapi_scheduler_t * that) { ...@@ -604,6 +604,23 @@ void embb_mtapi_scheduler_finalize(embb_mtapi_scheduler_t * that) {
embb_atomic_destroy_int(&that->affine_task_counter); embb_atomic_destroy_int(&that->affine_task_counter);
} }
#ifdef EMBB_HARD_REALTIME
embb_mtapi_scheduler_t * embb_mtapi_scheduler_new(
embb_mtapi_scheduler_mode_t mode) {
embb_mtapi_scheduler_t * that =
(embb_mtapi_scheduler_t*)embb_mtapi_alloc_allocate(
sizeof(embb_mtapi_scheduler_t));
if (MTAPI_NULL != that) {
if (MTAPI_FALSE == embb_mtapi_scheduler_initialize_with_mode (that, mode)) {
/* on error delete and return MTAPI_NULL */
embb_mtapi_scheduler_finalize(that);
embb_mtapi_scheduler_delete(that);
return MTAPI_NULL;
}
}
return that;
}
#else
embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() { embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() {
embb_mtapi_scheduler_t * that = embb_mtapi_scheduler_t * that =
(embb_mtapi_scheduler_t*)embb_mtapi_alloc_allocate( (embb_mtapi_scheduler_t*)embb_mtapi_alloc_allocate(
...@@ -618,6 +635,7 @@ embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() { ...@@ -618,6 +635,7 @@ embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() {
} }
return that; return that;
} }
#endif /*EMBB_HARD_REALTIME*/
void embb_mtapi_scheduler_delete(embb_mtapi_scheduler_t * that) { void embb_mtapi_scheduler_delete(embb_mtapi_scheduler_t * that) {
assert(MTAPI_NULL != that); assert(MTAPI_NULL != that);
......
...@@ -48,6 +48,7 @@ typedef int (embb_mtapi_scheduler_worker_func_t)(void * args); ...@@ -48,6 +48,7 @@ typedef int (embb_mtapi_scheduler_worker_func_t)(void * args);
/* ---- CLASS DECLARATION -------------------------------------------------- */ /* ---- CLASS DECLARATION -------------------------------------------------- */
#ifndef EMBB_HARD_REALTIME
/** /**
* \internal * \internal
* Scheduler mode type * Scheduler mode type
...@@ -59,13 +60,9 @@ enum embb_mtapi_scheduler_mode_enum { ...@@ -59,13 +60,9 @@ enum embb_mtapi_scheduler_mode_enum {
WORK_STEAL_VHPF = 0, WORK_STEAL_VHPF = 0,
// Local First. Steal if all local queues are empty. // Local First. Steal if all local queues are empty.
WORK_STEAL_LF = 1, WORK_STEAL_LF = 1,
#ifdef EMBB_HARD_REALTIME
// Global EDF. No work stealing
GLOBAL_EDF = 2,
#endif /*EMBB_HARD_REALTIME*/
NUM_SCHEDULER_MODES NUM_SCHEDULER_MODES
}; };
#endif /*EMBB_MTAPI_HARD_REALTIME*/
/** /**
* Scheduler mode type. * Scheduler mode type.
...@@ -170,13 +167,23 @@ void embb_mtapi_scheduler_execute_task_or_yield( ...@@ -170,13 +167,23 @@ void embb_mtapi_scheduler_execute_task_or_yield(
embb_mtapi_scheduler_t * that, embb_mtapi_scheduler_t * that,
embb_mtapi_node_t * node, embb_mtapi_node_t * node,
embb_mtapi_thread_context_t * thread_context); embb_mtapi_thread_context_t * thread_context);
#ifdef EMBB_HARD_REALTIME
/** /**
* operator new. * operator new.
* \memberof embb_mtapi_scheduler_struct * \memberof embb_mtapi_scheduler_struct
* \returns pointer to the scheduler oder MTAPI_NULL on error * \returns pointer to the scheduler oder MTAPI_NULL on error
*/ */
embb_mtapi_scheduler_t * embb_mtapi_scheduler_new(
embb_mtapi_scheduler_mode_t mode);
#else
/**
* operator new.
* \memberof embb_mtapi_scheduler_struct
* \returns pointer to the scheduler oder MTAPI_NULL on error
*/
embb_mtapi_scheduler_t * embb_mtapi_scheduler_new(); embb_mtapi_scheduler_t * embb_mtapi_scheduler_new();
#endif /*EMBB_HARD_REALTIME*/
/** /**
* operator delete. * operator delete.
......
...@@ -54,6 +54,9 @@ void mtapi_nodeattr_init( ...@@ -54,6 +54,9 @@ void mtapi_nodeattr_init(
attributes->max_priorities = MTAPI_NODE_MAX_PRIORITIES_DEFAULT; attributes->max_priorities = MTAPI_NODE_MAX_PRIORITIES_DEFAULT;
attributes->reuse_main_thread = MTAPI_FALSE; attributes->reuse_main_thread = MTAPI_FALSE;
attributes->worker_priorities = NULL; attributes->worker_priorities = NULL;
#ifdef EMBB_HARD_REALTIME
attributes->scheduler_mode = MTAPI_NODE_SCHEDULER_MODE_DEFAULT;
#endif /*EMBB_HARD_REALTIME*/
embb_core_set_init(&attributes->core_affinity, 1); embb_core_set_init(&attributes->core_affinity, 1);
attributes->num_cores = embb_core_set_count(&attributes->core_affinity); attributes->num_cores = embb_core_set_count(&attributes->core_affinity);
...@@ -155,6 +158,14 @@ void mtapi_nodeattr_set( ...@@ -155,6 +158,14 @@ void mtapi_nodeattr_set(
attributes->worker_priorities = attributes->worker_priorities =
(mtapi_worker_priority_entry_t*)attribute; (mtapi_worker_priority_entry_t*)attribute;
break; break;
#ifdef EMBB_HARD_REALTIME
case MTAPI_NODE_SCHEDULER_MODE:
// TODO error checking missing
local_status = MTAPI_SUCCESS;
attributes->scheduler_mode = *(embb_mtapi_scheduler_mode_t*)attribute;
break;
#endif /*EMBB_HARD_REALTIME*/
default: default:
/* attribute unknown */ /* attribute unknown */
......
...@@ -238,6 +238,24 @@ class NodeAttributes { ...@@ -238,6 +238,24 @@ class NodeAttributes {
return *this; return *this;
} }
#ifdef EMBB_HARD_REALTIME
/**
* Sets the scheduling mode which is applied to schedule tasks on this node.
*
* \returns Reference to this object.
* \notthreadsafe
*/
NodeAttributes & SetSchedulerMode(
embb_mtapi_scheduler_mode_t value /**< The value to set. */
) {
mtapi_status_t status;
mtapi_nodeattr_set(&attributes_, MTAPI_NODE_SCHEDULER_MODE,
&value, sizeof(value), &status);
internal::CheckStatus(status);
return *this;
}
#endif /*EMBB_HARD_REALTIME*/
/** /**
* Enables or disables the reuse of the main thread as a worker. * Enables or disables the reuse of the main thread as a worker.
* *
......
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