Commit e88779c4 authored by Xenofon Foukas's avatar Xenofon Foukas

Added support for lightweight finegrained task timer

parent e78075e8
...@@ -50,7 +50,7 @@ enb_agent_info_t enb_agent_info; ...@@ -50,7 +50,7 @@ enb_agent_info_t enb_agent_info;
char in_ip[40]; char in_ip[40];
static uint16_t in_port; static uint16_t in_port;
//void *send_thread(void *args); void *send_thread(void *args);
void *receive_thread(void *args); void *receive_thread(void *args);
pthread_t new_thread(void *(*f)(void *), void *b); pthread_t new_thread(void *(*f)(void *), void *b);
err_code_t enb_agent_timeout(void* args); err_code_t enb_agent_timeout(void* args);
...@@ -100,20 +100,35 @@ void *enb_agent_task(void *args){ ...@@ -100,20 +100,35 @@ void *enb_agent_task(void *args){
return NULL; return NULL;
} }
/*
void *send_thread(void *args) { void *send_thread(void *args) {
#ifdef TEST_TIMER
msg_context_t *d = args; msg_context_t *d = args;
void *data; void *data;
int size; int size;
int priority; int priority;
struct timeval t1, t2;
long long t;
struct timespec ts;
unsigned int delay = 250*1000;
while(1) {
gettimeofday(&t1, NULL);
enb_agent_sleep_until(&ts, delay);
gettimeofday(&t2, NULL);
t = ((t2.tv_sec * 1000000) + t2.tv_usec) - ((t1.tv_sec * 1000000) + t1.tv_usec);
LOG_I(ENB_AGENT, "Call to sleep_until(%d) took %lld us\n", delay, t);
sleep(1);
}
while (1) { #endif
/* while (1) {
// need logic for the timer, and // need logic for the timer, and
usleep(10); usleep(10);
if (message_put(d->tx_mq, data, size, priority)) goto error; if (message_put(d->tx_mq, data, size, priority)) goto error;
} }*/
return NULL; return NULL;
...@@ -121,7 +136,7 @@ error: ...@@ -121,7 +136,7 @@ error:
printf("receive_thread: there was an error\n"); printf("receive_thread: there was an error\n");
return NULL; return NULL;
} }
*/
void *receive_thread(void *args) { void *receive_thread(void *args) {
msg_context_t *d = args; msg_context_t *d = args;
...@@ -293,10 +308,11 @@ int enb_agent_start(mid_t mod_id, const Enb_properties_array_t* enb_properties){ ...@@ -293,10 +308,11 @@ int enb_agent_start(mid_t mod_id, const Enb_properties_array_t* enb_properties){
enb_agent_create_timer(1, 0, ENB_AGENT_DEFAULT, mod_id, ENB_AGENT_TIMER_TYPE_PERIODIC, enb_agent_timeout,(void*)&timer_args, &timer_id); enb_agent_create_timer(1, 0, ENB_AGENT_DEFAULT, mod_id, ENB_AGENT_TIMER_TYPE_PERIODIC, enb_agent_timeout,(void*)&timer_args, &timer_id);
#endif #endif
// new_thread(send_thread, &shared_ctxt); new_thread(send_thread, &shared_ctxt);
//while (1) pause(); //while (1) pause();
LOG_I(ENB_AGENT,"client ends\n"); LOG_I(ENB_AGENT,"client ends\n");
return 0; return 0;
......
...@@ -476,6 +476,15 @@ struct enb_agent_timer_element_s * get_timer_entry(long timer_id) { ...@@ -476,6 +476,15 @@ struct enb_agent_timer_element_s * get_timer_entry(long timer_id) {
return RB_FIND(enb_agent_map, &timer_instance.enb_agent_head, search); return RB_FIND(enb_agent_map, &timer_instance.enb_agent_head, search);
} }
void enb_agent_sleep_until(struct timespec *ts, int delay) {
ts->tv_nsec += delay;
if(ts->tv_nsec >= 1000*1000*1000){
ts->tv_nsec -= 1000*1000*1000;
ts->tv_sec++;
}
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, ts, NULL);
}
/* /*
int i =0; int i =0;
RB_FOREACH(e, enb_agent_map, &enb_agent_head) { RB_FOREACH(e, enb_agent_map, &enb_agent_head) {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#ifndef ENB_AGENT_COMMON_H_ #ifndef ENB_AGENT_COMMON_H_
#define ENB_AGENT_COMMON_H_ #define ENB_AGENT_COMMON_H_
#include <time.h>
#include "header.pb-c.h" #include "header.pb-c.h"
#include "progran.pb-c.h" #include "progran.pb-c.h"
...@@ -228,6 +229,9 @@ err_code_t enb_agent_process_timeout(long timer_id, void* timer_args); ...@@ -228,6 +229,9 @@ err_code_t enb_agent_process_timeout(long timer_id, void* timer_args);
int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b); int enb_agent_compare_timer(struct enb_agent_timer_element_s *a, struct enb_agent_timer_element_s *b);
/*Specify a delay in nanoseconds to timespec and sleep until then*/
void enb_agent_sleep_until(struct timespec *ts, int delay);
/* RB_PROTOTYPE is for .h files */ /* RB_PROTOTYPE is for .h files */
RB_PROTOTYPE(enb_agent_map, enb_agent_timer_element_s, entry, enb_agent_compare_timer); RB_PROTOTYPE(enb_agent_map, enb_agent_timer_element_s, entry, enb_agent_compare_timer);
......
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