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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,7 +1,7 @@
|
||||
#ifndef SIGNALS_H_
|
||||
#define SIGNALS_H_
|
||||
|
||||
int signal_init(void);
|
||||
int signal_mask(void);
|
||||
|
||||
int signal_handle(int *end);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user