Commit e78075e8 authored by Xenofon Foukas's avatar Xenofon Foukas

Integrated task manager with system frame and subframe clock and added support...

Integrated task manager with system frame and subframe clock and added support for one task queue per eNB
parent e0c459be
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <stdio.h> #include <stdio.h>
#include "enb_agent_task_manager.h" #include "enb_agent_task_manager.h"
#include "enb_agent_common.c"
/* Util macros */ /* Util macros */
...@@ -74,8 +75,8 @@ void enb_agent_task_destroy(enb_agent_task_t *task) { ...@@ -74,8 +75,8 @@ void enb_agent_task_destroy(enb_agent_task_t *task) {
free(task); free(task);
} }
enb_agent_task_queue_t *enb_agent_task_queue_init(size_t capacity, enb_agent_task_queue_t *enb_agent_task_queue_init(mid_t mod_id, size_t capacity,
int (*cmp)(const enb_agent_task_t *t1, const enb_agent_task_t *t2)) { int (*cmp)(mid_t mod_id, const enb_agent_task_t *t1, const enb_agent_task_t *t2)) {
enb_agent_task_queue_t *queue = NULL; enb_agent_task_queue_t *queue = NULL;
queue = malloc(sizeof(enb_agent_task_queue_t)); queue = malloc(sizeof(enb_agent_task_queue_t));
...@@ -88,6 +89,8 @@ enb_agent_task_queue_t *enb_agent_task_queue_init(size_t capacity, ...@@ -88,6 +89,8 @@ enb_agent_task_queue_t *enb_agent_task_queue_init(size_t capacity,
else else
queue->cmp = cmp; queue->cmp = cmp;
queue->mod_id = mod_id;
queue->first_frame = 0; queue->first_frame = 0;
queue->first_subframe = 0; queue->first_subframe = 0;
...@@ -115,8 +118,8 @@ enb_agent_task_queue_t *enb_agent_task_queue_init(size_t capacity, ...@@ -115,8 +118,8 @@ enb_agent_task_queue_t *enb_agent_task_queue_init(size_t capacity,
return NULL; return NULL;
} }
enb_agent_task_queue_t *enb_agent_task_queue_default_init() { enb_agent_task_queue_t *enb_agent_task_queue_default_init(mid_t mod_id) {
return enb_agent_task_queue_init(DEFAULT_CAPACITY, NULL); return enb_agent_task_queue_init(mod_id, DEFAULT_CAPACITY, NULL);
} }
void enb_agent_task_queue_destroy(enb_agent_task_queue_t *queue) { void enb_agent_task_queue_destroy(enb_agent_task_queue_t *queue) {
...@@ -157,7 +160,7 @@ int enb_agent_task_queue_put(enb_agent_task_queue_t *queue, enb_agent_task_t *ta ...@@ -157,7 +160,7 @@ int enb_agent_task_queue_put(enb_agent_task_queue_t *queue, enb_agent_task_t *ta
i = queue->count; i = queue->count;
queue->count++; queue->count++;
/*Swap elements to maintain heap properties*/ /*Swap elements to maintain heap properties*/
while(i > 0 && queue->cmp(queue->task[i], queue->task[PARENT(i)]) > 0) { while(i > 0 && queue->cmp(queue->mod_id, queue->task[i], queue->task[PARENT(i)]) > 0) {
tmp = queue->task[i]; tmp = queue->task[i];
queue->task[i] = queue->task[PARENT(i)]; queue->task[i] = queue->task[PARENT(i)];
queue->task[PARENT(i)] = tmp; queue->task[PARENT(i)] = tmp;
...@@ -179,11 +182,6 @@ int enb_agent_task_queue_put(enb_agent_task_queue_t *queue, enb_agent_task_t *ta ...@@ -179,11 +182,6 @@ int enb_agent_task_queue_put(enb_agent_task_queue_t *queue, enb_agent_task_t *ta
int enb_agent_task_queue_get_current_task(enb_agent_task_queue_t *queue, enb_agent_task_t **task) { int enb_agent_task_queue_get_current_task(enb_agent_task_queue_t *queue, enb_agent_task_t **task) {
int err_code; int err_code;
/*TODO*/
/* Find current frame and subframe number */
uint16_t curr_frame=1;
uint8_t curr_subframe=1;
if (pthread_mutex_lock(queue->mutex)) { if (pthread_mutex_lock(queue->mutex)) {
/*TODO*/ /*TODO*/
err_code = -1; err_code = -1;
...@@ -195,6 +193,11 @@ int enb_agent_task_queue_get_current_task(enb_agent_task_queue_t *queue, enb_age ...@@ -195,6 +193,11 @@ int enb_agent_task_queue_get_current_task(enb_agent_task_queue_t *queue, enb_age
err_code = HEAP_EMPTY; err_code = HEAP_EMPTY;
goto error; goto error;
} }
/* Find current frame and subframe number */
uint16_t curr_frame=get_current_frame(queue->mod_id);
uint8_t curr_subframe=get_current_subframe(queue->mod_id);
/* If no task is scheduled for the current subframe, return without any task */ /* If no task is scheduled for the current subframe, return without any task */
if(queue->task[0]->frame_num != curr_frame || queue->task[0]->subframe_num != curr_subframe) { if(queue->task[0]->frame_num != curr_frame || queue->task[0]->subframe_num != curr_subframe) {
*task = NULL; *task = NULL;
...@@ -207,6 +210,15 @@ int enb_agent_task_queue_get_current_task(enb_agent_task_queue_t *queue, enb_age ...@@ -207,6 +210,15 @@ int enb_agent_task_queue_get_current_task(enb_agent_task_queue_t *queue, enb_age
/* Restore heap property */ /* Restore heap property */
_enb_agent_task_queue_heapify(queue, 0); _enb_agent_task_queue_heapify(queue, 0);
/*If queue has no element*/
if (queue->count < 1) {
queue->first_frame = 0;
queue->first_subframe = 0;
} else {
queue->first_frame = queue->task[0]->frame_num;
queue->first_subframe = queue->task[0]->subframe_num;
}
if (pthread_mutex_unlock(queue->mutex)) { if (pthread_mutex_unlock(queue->mutex)) {
// LOG_E(MAC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__); // LOG_E(MAC, "%s:%d:%s: fatal error\n", __FILE__, __LINE__, __FUNCTION__);
exit(1); exit(1);
...@@ -228,14 +240,14 @@ void _enb_agent_task_queue_heapify(enb_agent_task_queue_t *queue, size_t idx) { ...@@ -228,14 +240,14 @@ void _enb_agent_task_queue_heapify(enb_agent_task_queue_t *queue, size_t idx) {
r_idx = RIGHT(idx); r_idx = RIGHT(idx);
/* Left child exists, compare left child with its parent */ /* Left child exists, compare left child with its parent */
if (l_idx < queue->count && queue->cmp(queue->task[l_idx], queue->task[idx]) > 0) { if (l_idx < queue->count && queue->cmp(queue->mod_id, queue->task[l_idx], queue->task[idx]) > 0) {
lrg_idx = l_idx; lrg_idx = l_idx;
} else { } else {
lrg_idx = idx; lrg_idx = idx;
} }
/* Right child exists, compare right child with the largest element */ /* Right child exists, compare right child with the largest element */
if (r_idx < queue->count && queue->cmp(queue->task[r_idx], queue->task[lrg_idx]) > 0) { if (r_idx < queue->count && queue->cmp(queue->mod_id, queue->task[r_idx], queue->task[lrg_idx]) > 0) {
lrg_idx = r_idx; lrg_idx = r_idx;
} }
...@@ -266,12 +278,12 @@ int _enb_agent_task_queue_realloc_heap(enb_agent_task_queue_t *queue) { ...@@ -266,12 +278,12 @@ int _enb_agent_task_queue_realloc_heap(enb_agent_task_queue_t *queue) {
return HEAP_NOREALLOC; return HEAP_NOREALLOC;
} }
int _enb_agent_task_queue_cmp(const enb_agent_task_t *t1, const enb_agent_task_t *t2) { int _enb_agent_task_queue_cmp(mid_t mod_id, const enb_agent_task_t *t1, const enb_agent_task_t *t2) {
if ((t1->frame_num == t2->frame_num) && (t1->subframe_num == t2->subframe_num)) if ((t1->frame_num == t2->frame_num) && (t1->subframe_num == t2->subframe_num))
return 0; return 0;
/* TODO: need to get current frame and subframe number */
uint16_t curr_frame = 0; uint16_t curr_frame = get_current_frame(mod_id);
uint8_t curr_subframe = 7; uint8_t curr_subframe = get_current_subframe(mod_id);
int f_offset, sf_offset, tmp1, tmp2; int f_offset, sf_offset, tmp1, tmp2;
...@@ -296,8 +308,3 @@ int _enb_agent_task_queue_cmp(const enb_agent_task_t *t1, const enb_agent_task_t ...@@ -296,8 +308,3 @@ int _enb_agent_task_queue_cmp(const enb_agent_task_t *t1, const enb_agent_task_t
to be the only comparisson parameter in all other cases */ to be the only comparisson parameter in all other cases */
return f_offset*100 + sf_offset; return f_offset*100 + sf_offset;
} }
int main(int argc, char **argv) {
return 0;
}
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include "progran.pb-c.h" #include "progran.pb-c.h"
#include "enb_agent_common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -65,6 +67,7 @@ typedef struct enb_agent_task_s { ...@@ -65,6 +67,7 @@ typedef struct enb_agent_task_s {
* Priority Queue Structure for tasks * Priority Queue Structure for tasks
*/ */
typedef struct enb_agent_task_queue_s { typedef struct enb_agent_task_queue_s {
mid_t mod_id;
/* The amount of allocated memory for agent tasks in the heap*/ /* The amount of allocated memory for agent tasks in the heap*/
volatile size_t capacity; volatile size_t capacity;
/* The actual size of the tasks heap at a certain time */ /* The actual size of the tasks heap at a certain time */
...@@ -76,7 +79,7 @@ typedef struct enb_agent_task_queue_s { ...@@ -76,7 +79,7 @@ typedef struct enb_agent_task_queue_s {
/* An array of prioritized tasks stored in a heap */ /* An array of prioritized tasks stored in a heap */
enb_agent_task_t **task; enb_agent_task_t **task;
/* A pointer to a comparator function, used to prioritize elements */ /* A pointer to a comparator function, used to prioritize elements */
int (*cmp)(const enb_agent_task_t *t1, const enb_agent_task_t *t2); int (*cmp)(mid_t mod_id, const enb_agent_task_t *t1, const enb_agent_task_t *t2);
pthread_mutex_t *mutex; pthread_mutex_t *mutex;
} enb_agent_task_queue_t; } enb_agent_task_queue_t;
...@@ -103,13 +106,13 @@ void enb_agent_task_destroy(enb_agent_task_t *task); ...@@ -103,13 +106,13 @@ void enb_agent_task_destroy(enb_agent_task_t *task);
/** /**
* Allocate initial memory for storing the tasks * Allocate initial memory for storing the tasks
*/ */
enb_agent_task_queue_t *enb_agent_task_queue_init(size_t capacity, enb_agent_task_queue_t *enb_agent_task_queue_init(mid_t mod_id, size_t capacity,
int (*cmp)(const enb_agent_task_t *t1, const enb_agent_task_t *t2)); int (*cmp)(mid_t mod_id, const enb_agent_task_t *t1, const enb_agent_task_t *t2));
/** /**
* Allocate initial memory for storing the tasks using default parameters * Allocate initial memory for storing the tasks using default parameters
*/ */
enb_agent_task_queue_t *enb_agent_task_queue_default_init(); enb_agent_task_queue_t *enb_agent_task_queue_default_init(mid_t mod_id);
/** /**
* De-allocate memory for the tasks queue * De-allocate memory for the tasks queue
...@@ -148,8 +151,9 @@ int _enb_agent_task_queue_realloc_heap(enb_agent_task_queue_t *queue); ...@@ -148,8 +151,9 @@ int _enb_agent_task_queue_realloc_heap(enb_agent_task_queue_t *queue);
* returns 0 if tasks t1, t2 have the same priority * returns 0 if tasks t1, t2 have the same priority
* return negative value if t1 needs to be executed after t2 * return negative value if t1 needs to be executed after t2
* return positive value if t1 preceeds t2 * return positive value if t1 preceeds t2
* Need to give eNB id for the comparisson based on the current frame-subframe
*/ */
int _enb_agent_task_queue_cmp(const enb_agent_task_t *t1, const enb_agent_task_t *t2); int _enb_agent_task_queue_cmp(mid_t mod_id, const enb_agent_task_t *t1, const enb_agent_task_t *t2);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
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 to comment