Commit f2f0e68f authored by Navid Nikaein's avatar Navid Nikaein

Fix the bug in the RB tree, and sanity test for the timer API

parent f7d591f1
This diff is collapsed.
......@@ -95,8 +95,7 @@ int timer_handle_signal(siginfo_t *info)
// LG: To many traces for msc timer:
TMR_DEBUG("Timer with id 0x%lx has expired\n", (long)timer_p->timer);
printf("Timer with id 0x%lx has expired\n", (long)timer_p->timer);
task_id = timer_p->task_id;
instance = timer_p->instance;
message_p = itti_alloc_new_message(TASK_TIMER, TIMER_HAS_EXPIRED);
......@@ -210,11 +209,6 @@ int timer_setup(
type == TIMER_PERIODIC ? "periodic" : "single shot",
*timer_id, interval_sec, interval_us);
printf("Requesting new %s timer with id 0x%lx that expires within "
"%d sec and %d usec\n",
type == TIMER_PERIODIC ? "periodic" : "single shot",
*timer_id, interval_sec, interval_us);
timer_p->timer = timer;
/* Lock the queue and insert the timer at the tail */
......
......@@ -40,6 +40,7 @@
#include "assertions.h"
//#define TEST_TIMER
enb_agent_instance_t enb_agent[NUM_MAX_ENB_AGENT];
msg_context_t shared_ctxt[NUM_MAX_ENB_AGENT];
......@@ -327,8 +328,10 @@ int enb_agent_stop(mid_t mod_id){
err_code_t enb_agent_timeout(void* args){
// enb_agent_timer_args_t *timer_args = calloc(1, sizeof(*timer_args));
//memcpy (timer_args, args, sizeof(*timer_args));
enb_agent_timer_args_t *timer_args = (enb_agent_timer_args_t *) args;
LOG_I(ENB_AGENT, "enb_agent %d timeout\n", timer_args->mod_id);
LOG_I(ENB_AGENT, "eNB action %d ENB flags %d \n", timer_args->cc_actions,timer_args->cc_report_flags);
LOG_I(ENB_AGENT, "UE action %d UE flags %d \n", timer_args->ue_actions,timer_args->ue_report_flags);
......
......@@ -312,25 +312,12 @@ int get_ue_wcqi (mid_t mod_id, mid_t ue_id) {
//struct enb_agent_map agent_map;
/* The timer_id might not be the best choice for the comparison */
int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b){
//if (a->timer_id) return 0;
//if (b->timer_id) return 0;
if (a->timer_id < b->timer_id) return -1;
if (a->timer_id > b->timer_id) return 1;
// equal timers
return 0;
}
RB_GENERATE(enb_agent_map,enb_agent_timer_element_s, entry, enb_agent_compare_timer);
enb_agent_timer_instance_t timer_instance;
err_code_t enb_agent_init_timer(void){
LOG_I(ENB_AGENT, "init RB tree\n");
RB_INIT(&enb_agent_head);
RB_INIT(&timer_instance.enb_agent_head);
/*
struct enb_agent_timer_element_s e;
......@@ -340,6 +327,18 @@ err_code_t enb_agent_init_timer(void){
return PROTOCOL__PROGRAN_ERR__NO_ERR;
}
RB_GENERATE(enb_agent_map,enb_agent_timer_element_s, entry, enb_agent_compare_timer);
/* The timer_id might not be the best choice for the comparison */
int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b){
if (a->timer_id < b->timer_id) return -1;
if (a->timer_id > b->timer_id) return 1;
// equal timers
return 0;
}
err_code_t enb_agent_create_timer(uint32_t interval_sec,
uint32_t interval_usec,
agent_id_t agent_id,
......@@ -349,7 +348,9 @@ err_code_t enb_agent_create_timer(uint32_t interval_sec,
void* timer_args,
long *timer_id){
struct enb_agent_timer_element_s e;
struct enb_agent_timer_element_s *e = calloc(1, sizeof(*e));
DevAssert(e != NULL);
//uint32_t timer_id;
int ret=-1;
......@@ -368,7 +369,7 @@ err_code_t enb_agent_create_timer(uint32_t interval_sec,
timer_args,
timer_id);
e.type = TIMER_ONE_SHOT;
e->type = TIMER_ONE_SHOT;
}
else if (timer_type == ENB_AGENT_TIMER_TYPE_PERIODIC ){
ret = timer_setup(interval_sec,
......@@ -379,32 +380,25 @@ err_code_t enb_agent_create_timer(uint32_t interval_sec,
timer_args,
timer_id);
e.type = TIMER_PERIODIC;
e->type = TIMER_PERIODIC;
}
if (ret < 0 ) {
return TIMER_SETUP_FAILED;
}
e.agent_id = agent_id;
e.instance = instance;
e.state = ENB_AGENT_TIMER_STATE_ACTIVE;
e.timer_id = *timer_id;
e.timer_args = timer_args;
e.cb = cb;
LOG_I(ENB_AGENT,"created a timer with id 0x%lx for agent %d, instance %d \n",
e.timer_id, e.agent_id, e.instance);
RB_INSERT(enb_agent_map, &enb_agent_head, &e);
/*
struct enb_agent_timer_element_s search;
search.timer_id = *timer_id;
printf("search 1: %p (expected %p)\n", RB_FIND(enb_agent_map, &enb_agent_head, &search), &e);
printf("search 1: %p (expected %p)\n", get_timer_entry(e.timer_id), &e);
*/
e->agent_id = agent_id;
e->instance = instance;
e->state = ENB_AGENT_TIMER_STATE_ACTIVE;
e->timer_id = *timer_id;
// e->timer_args = timer_args;
e->cb = cb;
/*element should be a real pointer*/
RB_INSERT(enb_agent_map, &timer_instance.enb_agent_head, e);
LOG_I(ENB_AGENT,"Created a new timer with id 0x%lx for agent %d, instance %d \n",
e->timer_id, e->agent_id, e->instance);
return 0;
}
......@@ -413,7 +407,7 @@ err_code_t enb_agent_destroy_timer(long timer_id){
struct enb_agent_timer_element_s *e = get_timer_entry(timer_id);
if (e != NULL ) {
RB_REMOVE(enb_agent_map, &enb_agent_head, &e);
RB_REMOVE(enb_agent_map, &timer_instance.enb_agent_head, &e);
free(e);
}
......@@ -431,8 +425,8 @@ err_code_t enb_agent_destroy_timers(void){
struct enb_agent_timer_element_s *e = NULL;
RB_FOREACH(e, enb_agent_map, &enb_agent_head) {
RB_REMOVE(enb_agent_map, &enb_agent_head, e);
RB_FOREACH(e, enb_agent_map, &timer_instance.enb_agent_head) {
RB_REMOVE(enb_agent_map, &timer_instance.enb_agent_head, e);
timer_remove(e->timer_id);
free(e);
}
......@@ -443,11 +437,10 @@ err_code_t enb_agent_destroy_timers(void){
struct enb_agent_timer_element_s * get_timer_entry(long timer_id) {
struct enb_agent_timer_element_s search, *e;
memset(&search, 0, sizeof(struct enb_agent_timer_element_s));
search.timer_id = timer_id;
return RB_FIND(enb_agent_map, &enb_agent_head, &search);
struct enb_agent_timer_element_s *search= calloc(1,sizeof(*search));
search->timer_id = timer_id;
return RB_FIND(enb_agent_map, &timer_instance.enb_agent_head, search);
}
/*
......
......@@ -189,10 +189,13 @@ typedef struct enb_agent_timer_element_s{
long timer_id; /* Timer id returned by the timer API*/
enb_agent_timer_callback_t cb;
void* timer_args;
// void* timer_args;
} enb_agent_timer_element_t;
typedef struct enb_agent_timer_instance_s{
RB_HEAD(enb_agent_map, enb_agent_timer_element_s) enb_agent_head;
}enb_agent_timer_instance_t;
err_code_t enb_agent_init_timer(void);
......@@ -214,11 +217,11 @@ err_code_t enb_agent_restart_timer(long *timer_id);
struct enb_agent_timer_element_s * get_timer_entry(long timer_id);
int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b);
err_code_t enb_agent_process_timeout(long timer_id, void* timer_args);
RB_HEAD(enb_agent_map, enb_agent_timer_element_s) enb_agent_head;
int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b);
/* RB_PROTOTYPE is for .h files */
RB_PROTOTYPE(enb_agent_map, enb_agent_timer_element_s, entry, enb_agent_compare_timer);
......
......@@ -141,15 +141,15 @@ void * enb_agent_send_message(xid_t xid,
err_code_t enb_agent_process_timeout(long timer_id, void* timer_args){
struct enb_agent_timer_element_s *e = get_timer_entry(timer_id);
struct enb_agent_timer_element_s *found = get_timer_entry(timer_id);
if (found == NULL ) goto error;
LOG_I(ENB_AGENT, "Found the entry (%p): timer_id is 0x%lx 0x%lx\n", found, timer_id, found->timer_id);
LOG_I(ENB_AGENT, "element %p: timer_id is 0x%lx 0x%lx\n", e, timer_id, e->timer_id);
if (e == NULL ) goto error;
if (timer_args == NULL)
LOG_W(ENB_AGENT,"null timer args\n");
return e->cb(timer_args);
return found->cb(timer_args);
error:
......
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