Added ITTI timer support for RTAI builds (timers must only be used from non RT tasks).

Blocked message sending to ended tasks.
Modified lte-softmodem to use ITTI signal handling.
Uniformized lte-softmodem and oaisim with ITTI handling.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4607 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
winckel
2013-12-05 13:03:18 +00:00
parent 4150c634cf
commit ae4b36507f
9 changed files with 145 additions and 77 deletions
+61 -46
View File
@@ -339,54 +339,67 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_ENQUEUE_MESSAGE, VCD_FUNCTION_IN);
#endif
/* We cannot send a message if the task is not running */
DevCheck(itti_desc.threads[destination_thread_id].task_state == TASK_STATE_READY, itti_desc.threads[destination_thread_id].task_state,
TASK_STATE_READY, destination_thread_id);
if (itti_desc.threads[destination_thread_id].task_state == TASK_STATE_ENDED)
{
ITTI_DEBUG("Message %s, number %lu with priority %d can not be sent from %s to queue (%u:%s), ended destination task!\n",
itti_desc.messages_info[message_id].name,
message_number,
priority,
itti_get_task_name(origin_task_id),
destination_task_id,
itti_get_task_name(destination_task_id));
}
else
{
/* We cannot send a message if the task is not running */
DevCheck(itti_desc.threads[destination_thread_id].task_state == TASK_STATE_READY, destination_thread_id,
itti_desc.threads[destination_thread_id].task_state, message_id);
/* Allocate new list element */
new = (message_list_t *) malloc (sizeof(struct message_list_s));
DevAssert(new != NULL);
/* Allocate new list element */
new = (message_list_t *) malloc (sizeof(struct message_list_s));
DevAssert(new != NULL);
/* Fill in members */
new->msg = message;
new->message_number = message_number;
new->message_priority = priority;
/* Fill in members */
new->msg = message;
new->message_number = message_number;
new->message_priority = priority;
/* Enqueue message in destination task queue */
lfds611_queue_enqueue(itti_desc.tasks[destination_task_id].message_queue, new);
/* Enqueue message in destination task queue */
lfds611_queue_enqueue(itti_desc.tasks[destination_task_id].message_queue, new);
#if defined(OAI_EMU) || defined(RTAI)
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_ENQUEUE_MESSAGE, VCD_FUNCTION_OUT);
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_ENQUEUE_MESSAGE, VCD_FUNCTION_OUT);
#endif
#ifdef RTAI
if (itti_desc.threads[TASK_GET_THREAD_ID(origin_task_id)].real_time)
{
/* This is a RT task, increase destination task messages pending counter */
__sync_fetch_and_add (&itti_desc.threads[destination_thread_id].messages_pending, 1);
}
else
#endif
{
/* Only use event fd for tasks, subtasks will pool the queue */
if (TASK_GET_PARENT_TASK_ID(destination_task_id) == TASK_UNKNOWN)
if (itti_desc.threads[TASK_GET_THREAD_ID(origin_task_id)].real_time)
{
ssize_t write_ret;
uint64_t sem_counter = 1;
/* Call to write for an event fd must be of 8 bytes */
write_ret = write (itti_desc.threads[destination_thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
DevCheck(write_ret == sizeof(sem_counter), write_ret, sem_counter, destination_thread_id);
/* This is a RT task, increase destination task messages pending counter */
__sync_fetch_and_add (&itti_desc.threads[destination_thread_id].messages_pending, 1);
}
}
else
#endif
{
/* Only use event fd for tasks, subtasks will pool the queue */
if (TASK_GET_PARENT_TASK_ID(destination_task_id) == TASK_UNKNOWN)
{
ssize_t write_ret;
uint64_t sem_counter = 1;
ITTI_DEBUG("Message %s, number %lu with priority %d successfully sent from %s to queue (%u:%s)\n",
itti_desc.messages_info[message_id].name,
message_number,
priority,
itti_get_task_name(origin_task_id),
destination_task_id,
itti_get_task_name(destination_task_id));
/* Call to write for an event fd must be of 8 bytes */
write_ret = write (itti_desc.threads[destination_thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
DevCheck(write_ret == sizeof(sem_counter), write_ret, sem_counter, destination_thread_id);
}
}
ITTI_DEBUG("Message %s, number %lu with priority %d successfully sent from %s to queue (%u:%s)\n",
itti_desc.messages_info[message_id].name,
message_number,
priority,
itti_get_task_name(origin_task_id),
destination_task_id,
itti_get_task_name(destination_task_id));
}
}
#if defined(OAI_EMU) || defined(RTAI)
@@ -634,6 +647,15 @@ void itti_mark_task_ready(task_id_t task_id)
}
void itti_exit_task(void) {
#if defined(OAI_EMU) || defined(RTAI)
task_id_t task_id = itti_get_current_task_id();
if (task_id > TASK_UNKNOWN)
{
vcd_signal_dumper_dump_variable_by_name(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_RECV_MSG,
__sync_and_and_fetch (&itti_desc.vcd_receive_msg, ~(1L << task_id)));
}
#endif
pthread_exit (NULL);
}
@@ -692,12 +714,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
ITTI_DEBUG("Init: %d tasks, %d threads, %d messages\n", task_max, thread_max, messages_id_max);
#if !defined(RTAI)
/* SR: disable signals module for RTAI (need to harmonize management
* between softmodem and oaisim).
*/
CHECK_INIT_RETURN(signal_init());
#endif
CHECK_INIT_RETURN(signal_mask());
/* Saves threads and messages max values */
itti_desc.task_max = task_max;
@@ -799,9 +816,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
itti_dump_init (messages_definition_xml, dump_file_name);
#ifndef RTAI
CHECK_INIT_RETURN(timer_init ());
#endif
CHECK_INIT_RETURN(timer_init ());
return 0;
}
+18 -7
View File
@@ -48,10 +48,23 @@
#include "assertions.h"
#include "signals.h"
#include "log.h"
#if defined (LOG_D) && defined (LOG_E)
# define SIG_DEBUG(x, args...) LOG_D(EMU, x, ##args)
# define SIG_ERROR(x, args...) LOG_E(EMU, x, ##args)
#endif
#ifndef SIG_DEBUG
# define SIG_DEBUG(x, args...) do { fprintf(stdout, "[SIG][D]"x, ##args); } while(0)
#endif
#ifndef SIG_ERROR
# define SIG_ERROR(x, args...) do { fprintf(stdout, "[SIG][E]"x, ##args); } while(0)
#endif
static sigset_t set;
int signal_init(void)
int signal_mask(void)
{
/* We set the signal mask to avoid threads other than the main thread
* to receive the timer signal. Note that threads created will inherit this
@@ -73,8 +86,6 @@ int signal_init(void)
return 0;
}
extern int timer_handle_signal(siginfo_t *info);
int signal_handle(int *end)
{
int ret;
@@ -113,24 +124,24 @@ int signal_handle(int *end)
/* Dispatch the signal to sub-handlers */
switch(info.si_signo) {
case SIGUSR1:
printf("Received SIGUSR1\n");
SIG_DEBUG("Received SIGUSR1\n");
*end = 1;
break;
case SIGSEGV: /* Fall through */
case SIGABRT:
printf("Received SIGABORT\n");
SIG_DEBUG("Received SIGABORT\n");
backtrace_handle_signal(&info);
break;
case SIGINT:
printf("Received SIGINT\n");
SIG_DEBUG("Received SIGINT\n");
itti_send_terminate_message(TASK_UNKNOWN);
*end = 1;
break;
default:
printf("Received unknown signal %d\n", info.si_signo);
SIG_ERROR("Received unknown signal %d\n", info.si_signo);
break;
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef SIGNALS_H_
#define SIGNALS_H_
int signal_init(void);
int signal_mask(void);
int signal_handle(int *end);
-8
View File
@@ -85,7 +85,6 @@ do { \
int timer_handle_signal(siginfo_t *info)
{
#if !defined(RTAI)
struct timer_elm_s *timer_p;
MessageDef *message_p;
timer_has_expired_t *timer_expired_p;
@@ -127,7 +126,6 @@ int timer_handle_signal(siginfo_t *info)
free(message_p);
return -1;
}
#endif
return 0;
}
@@ -141,7 +139,6 @@ int timer_setup(
void *timer_arg,
long *timer_id)
{
#if !defined(RTAI)
struct sigevent se;
struct itimerspec its;
struct timer_elm_s *timer_p;
@@ -209,9 +206,6 @@ int timer_setup(
pthread_mutex_lock(&timer_desc.timer_list_mutex);
STAILQ_INSERT_TAIL(&timer_desc.timer_queue, timer_p, entries);
pthread_mutex_unlock(&timer_desc.timer_list_mutex);
#else
return -1;
#endif
return 0;
}
@@ -219,7 +213,6 @@ int timer_setup(
int timer_remove(long timer_id)
{
int rc = 0;
#if !defined(RTAI)
struct timer_elm_s *timer_p;
TMR_DEBUG("Removing timer 0x%lx\n", timer_id);
@@ -243,7 +236,6 @@ int timer_remove(long timer_id)
}
free(timer_p);
timer_p = NULL;
#endif
return rc;
}
+4
View File
@@ -31,6 +31,8 @@
#ifndef TIMER_H_
#define TIMER_H_
#include <signal.h>
#define SIGTIMER SIGRTMIN
typedef enum timer_type_s {
@@ -39,6 +41,8 @@ typedef enum timer_type_s {
TIMER_TYPE_MAX,
} timer_type_t;
int timer_handle_signal(siginfo_t *info);
/** \brief Request a new timer
* \param interval_sec timer interval in seconds
* \param interval_us timer interval in micro seconds
+1 -1
View File
@@ -215,7 +215,7 @@ void *eNB_app_task(void *args_p)
if (timer_setup (ENB_REGISTER_RETRY_DELAY, 0, TASK_ENB_APP, INSTANCE_DEFAULT, TIMER_ONE_SHOT,
NULL, &enb_register_retry_timer_id) < 0)
{
LOG_E(ENB_APP, " Can not start eNB register retry timer!\n");
LOG_E(ENB_APP, " Can not start eNB register retry timer, use \"usleep\" instead!\n");
usleep(ENB_REGISTER_RETRY_DELAY * 1000000);
/* Restart the registration process */
+5 -1
View File
@@ -51,6 +51,7 @@
#include <unistd.h>
#include <assert.h>
#include "signals.h"
#if defined(ENABLE_VCD_FIFO)
# include "liblfds611.h"
#endif
@@ -266,6 +267,10 @@ void *vcd_dumper_thread_rt(void *args)
vcd_queue_user_data_t *data;
char binary_string[(sizeof (uint64_t) * BYTE_SIZE) + 1];
# if defined(ENABLE_ITTI)
signal_mask();
# endif
while(1) {
if (lfds611_queue_dequeue(vcd_queue, (void **) &data) == 0) {
/* No element -> sleep a while */
@@ -313,7 +318,6 @@ void *vcd_dumper_thread_rt(void *args)
void vcd_signal_dumper_init(char *filename)
{
if (ouput_vcd) {
// char filename[] = "/tmp/openair_vcd_dump.vcd";
+3
View File
@@ -155,6 +155,9 @@ RTAI_CFLAGS += $(shell rtai-config --lxrt-cflags) -DRTAI
LDFLAGS += -lpthread -lm -lforms
ifeq ($(RTAI),1)
LDFLAGS += $(shell rtai-config --lxrt-ldflags)
ifdef ENABLE_ITTI
LDFLAGS += -lrt
endif
else
LDFLAGS += -lrt
endif
+52 -13
View File
@@ -217,6 +217,7 @@ unsigned int build_rfdc(int dcoff_i_rxfe, int dcoff_q_rxfe)
return (dcoff_i_rxfe + (dcoff_q_rxfe<<8));
}
#if !defined(ENABLE_ITTI)
void signal_handler(int sig)
{
void *array[10];
@@ -235,6 +236,7 @@ void signal_handler(int sig)
oai_exit=1;
}
}
#endif
void exit_fun(const char* s)
{
@@ -480,17 +482,48 @@ void *l2l1_task(void *arg)
free (message_p);
}
itti_receive_msg (TASK_L2L1, &message_p);
switch (ITTI_MSG_ID(message_p)) {
case INITIALIZE_MESSAGE:
/* Start eNB thread */
start_eNB = 1;
break;
case TERMINATE_MESSAGE:
oai_exit=1;
itti_exit_task ();
break;
default:
LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
break;
}
} while (ITTI_MSG_ID(message_p) != INITIALIZE_MESSAGE);
free (message_p);
/* Start eNB thread */
start_eNB = 1;
}
while (!oai_exit)
{
usleep(500000);
}
do {
// Wait for a message
itti_receive_msg (TASK_L2L1, &message_p);
switch (ITTI_MSG_ID(message_p)) {
case TERMINATE_MESSAGE:
oai_exit=1;
itti_exit_task ();
break;
case MESSAGE_TEST:
LOG_I(EMU, "Received %s\n", ITTI_MSG_NAME(message_p));
break;
default:
LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
break;
}
free (message_p);
} while(1);
return NULL;
}
#endif
@@ -1270,26 +1303,23 @@ int main(int argc, char **argv) {
else {
log_set_instance_type (LOG_INSTANCE_ENB);
}
#endif
#if defined(ENABLE_ITTI)
itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info, messages_definition_xml, itti_dump_file);
if (create_tasks(UE_flag ? 0 : 1, UE_flag ? 1 : 0) < 0) {
exit(-1); // need a softer mode
}
// Handle signals until all tasks are terminated
// itti_wait_tasks_end();
#endif
#ifdef NAS_NETLINK
netlink_init();
#endif
#if !defined(ENABLE_ITTI)
// to make a graceful exit when ctrl-c is pressed
signal(SIGSEGV, signal_handler);
signal(SIGINT, signal_handler);
#endif
#ifndef RTAI
check_clock();
@@ -1463,11 +1493,15 @@ int main(int argc, char **argv) {
g_log->log_component[OTG].flag = LOG_HIGH;
g_log->log_component[RRC].level = LOG_INFO;
g_log->log_component[RRC].flag = LOG_HIGH;
#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME)
#if defined(ENABLE_ITTI)
g_log->log_component[EMU].level = LOG_INFO;
g_log->log_component[EMU].flag = LOG_HIGH;
# if defined(ENABLE_USE_MME)
g_log->log_component[S1AP].level = LOG_INFO;
g_log->log_component[S1AP].flag = LOG_HIGH;
g_log->log_component[SCTP].level = LOG_INFO;
g_log->log_component[SCTP].flag = LOG_HIGH;
# endif
#endif
g_log->log_component[ENB_APP].level = LOG_INFO;
g_log->log_component[ENB_APP].flag = LOG_HIGH;
@@ -1864,8 +1898,13 @@ int main(int argc, char **argv) {
// wait for end of program
printf("TYPE <CTRL-C> TO TERMINATE\n");
//getchar();
#if defined(ENABLE_ITTI)
itti_wait_tasks_end();
#else
while (oai_exit==0)
rt_sleep_ns(FRAME_PERIOD);
#endif
// stop threads
#ifdef XFORMS