merge the latest develop branch into issue289
This commit is contained in:
@@ -31,10 +31,6 @@
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#ifdef RTAI
|
||||
# include <rtai_shm.h>
|
||||
#endif
|
||||
|
||||
#if !defined(TRUE)
|
||||
#define TRUE 1
|
||||
#endif
|
||||
@@ -45,11 +41,6 @@
|
||||
#include "intertask_interface.h"
|
||||
#include "intertask_interface_dump.h"
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
# include "memory_pools.h"
|
||||
# include "vcd_signal_dumper.h"
|
||||
#endif
|
||||
|
||||
#if T_TRACER
|
||||
#include "T.h"
|
||||
#endif
|
||||
@@ -67,14 +58,6 @@
|
||||
#include "log.h"
|
||||
#endif
|
||||
|
||||
#ifdef RTAI
|
||||
# include <rtai.h>
|
||||
# include <rtai_fifos.h>
|
||||
# define FIFO_PRINTF_MAX_STRING_SIZE 1000
|
||||
# define FIFO_PRINTF_NO 62
|
||||
# define FIFO_PRINTF_SIZE 65536
|
||||
#endif
|
||||
|
||||
/* ITTI DEBUG groups */
|
||||
#define ITTI_DEBUG_POLL (1<<0)
|
||||
#define ITTI_DEBUG_SEND (1<<1)
|
||||
@@ -86,22 +69,12 @@
|
||||
|
||||
const int itti_debug = (ITTI_DEBUG_ISSUES | ITTI_DEBUG_MP_STATISTICS);
|
||||
|
||||
/* Don't flush if using RTAI */
|
||||
#ifdef RTAI
|
||||
# define ITTI_DEBUG(m, x, args...) do { if ((m) & itti_debug) rt_log_debug (x, ##args); } while(0);
|
||||
#else
|
||||
# define ITTI_DEBUG(m, x, args...) do { if ((m) & itti_debug) {fprintf(stdout, "[ITTI][D]"x, ##args); fflush (stdout);} } while(0);
|
||||
#endif
|
||||
#define ITTI_ERROR(x, args...) do { fprintf(stdout, "[ITTI][E]"x, ##args); fflush (stdout); } while(0);
|
||||
|
||||
/* Global message size */
|
||||
#define MESSAGE_SIZE(mESSAGEiD) (sizeof(MessageHeader) + itti_desc.messages_info[mESSAGEiD].size)
|
||||
|
||||
#ifdef RTAI
|
||||
# define ITTI_MEM_PAGE_SIZE (1024)
|
||||
# define ITTI_MEM_SIZE (16 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
typedef enum task_state_s {
|
||||
TASK_STATE_NOT_CONFIGURED, TASK_STATE_STARTING, TASK_STATE_READY, TASK_STATE_ENDED, TASK_STATE_MAX,
|
||||
} task_state_t;
|
||||
@@ -140,13 +113,11 @@ typedef struct thread_desc_s {
|
||||
|
||||
int epoll_nb_events;
|
||||
|
||||
//#ifdef RTAI
|
||||
/* Flag to mark real time thread */
|
||||
unsigned real_time;
|
||||
|
||||
/* Counter to indicate from RTAI threads that messages are pending for the thread */
|
||||
/* Counter to indicate that messages are pending for the thread */
|
||||
unsigned messages_pending;
|
||||
//#endif
|
||||
} thread_desc_t;
|
||||
|
||||
typedef struct task_desc_s {
|
||||
@@ -178,17 +149,6 @@ typedef struct itti_desc_s {
|
||||
volatile uint32_t created_tasks;
|
||||
volatile uint32_t ready_tasks;
|
||||
volatile int wait_tasks;
|
||||
#ifdef RTAI
|
||||
pthread_t rt_relay_thread;
|
||||
#endif
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
memory_pools_handle_t memory_pools_handle;
|
||||
|
||||
uint64_t vcd_poll_msg;
|
||||
uint64_t vcd_receive_msg;
|
||||
uint64_t vcd_send_msg;
|
||||
#endif
|
||||
} itti_desc_t;
|
||||
|
||||
static itti_desc_t itti_desc;
|
||||
@@ -197,20 +157,8 @@ void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize
|
||||
{
|
||||
void *ptr = NULL;
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
ptr = memory_pools_allocate (itti_desc.memory_pools_handle, size, origin_task_id, destination_task_id);
|
||||
|
||||
if (ptr == NULL) {
|
||||
char *statistics = memory_pools_statistics (itti_desc.memory_pools_handle);
|
||||
|
||||
ITTI_ERROR (" Memory pools statistics:\n%s", statistics);
|
||||
free (statistics);
|
||||
}
|
||||
|
||||
#else
|
||||
ptr = malloc (size);
|
||||
if (ptr) memset(ptr,0,size);
|
||||
#endif
|
||||
|
||||
AssertFatal (ptr != NULL, "Memory allocation of %d bytes failed (%d -> %d)!\n", (int) size, origin_task_id, destination_task_id);
|
||||
|
||||
@@ -222,13 +170,7 @@ int itti_free(task_id_t task_id, void *ptr)
|
||||
int result = EXIT_SUCCESS;
|
||||
AssertFatal (ptr != NULL, "Trying to free a NULL pointer (%d)!\n", task_id);
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
result = memory_pools_free (itti_desc.memory_pools_handle, ptr, task_id);
|
||||
|
||||
AssertError (result == EXIT_SUCCESS, {}, "Failed to free memory at %p (%d)!\n", ptr, task_id);
|
||||
#else
|
||||
free (ptr);
|
||||
#endif
|
||||
|
||||
return (result);
|
||||
}
|
||||
@@ -284,27 +226,6 @@ static task_id_t itti_get_current_task_id(void)
|
||||
return TASK_UNKNOWN;
|
||||
}
|
||||
|
||||
#ifdef RTAI
|
||||
static void rt_log_debug(char *format, ...)
|
||||
{
|
||||
task_id_t task_id;
|
||||
va_list args;
|
||||
char log_buffer[FIFO_PRINTF_MAX_STRING_SIZE];
|
||||
int len;
|
||||
|
||||
task_id = itti_get_current_task_id ();
|
||||
len = snprintf(log_buffer, FIFO_PRINTF_MAX_STRING_SIZE-1, "[ITTI][D][%s]", itti_get_task_name(task_id));
|
||||
va_start(args, format);
|
||||
len += vsnprintf(&log_buffer[len], FIFO_PRINTF_MAX_STRING_SIZE-1-len, format, args);
|
||||
va_end (args);
|
||||
|
||||
if (task_id != TASK_UNKNOWN)
|
||||
fwrite(log_buffer, len, 1, stdout);
|
||||
else
|
||||
rtf_put (FIFO_PRINTF_NO, log_buffer, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
void itti_update_lte_time(uint32_t frame, uint8_t slot)
|
||||
{
|
||||
itti_desc.lte_time.frame = frame;
|
||||
@@ -361,10 +282,6 @@ MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, MessagesIds m
|
||||
|
||||
AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)!\n", message_id, itti_desc.messages_id_max);
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_ALLOC_MSG, size);
|
||||
#endif
|
||||
|
||||
if (origin_task_id == TASK_UNKNOWN) {
|
||||
/* Try to identify real origin task ID */
|
||||
origin_task_id = itti_get_current_task_id();
|
||||
@@ -376,10 +293,6 @@ MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, MessagesIds m
|
||||
temp->ittiMsgHeader.originTaskId = origin_task_id;
|
||||
temp->ittiMsgHeader.ittiMsgSize = size;
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_ALLOC_MSG, 0);
|
||||
#endif
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
@@ -397,11 +310,6 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
|
||||
message_number_t message_number;
|
||||
uint32_t message_id;
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_SEND_MSG,
|
||||
__sync_or_and_fetch (&itti_desc.vcd_send_msg, 1L << destination_task_id));
|
||||
#endif
|
||||
|
||||
AssertFatal (message != NULL, "Message is NULL!\n");
|
||||
AssertFatal (destination_task_id < itti_desc.task_max, "Destination task id (%d) is out of range (%d)\n", destination_task_id, itti_desc.task_max);
|
||||
|
||||
@@ -424,11 +332,6 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
|
||||
sizeof(MessageHeader) + message->ittiMsgHeader.ittiMsgSize);
|
||||
|
||||
if (destination_task_id != TASK_UNKNOWN) {
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_ENQUEUE_MESSAGE, VCD_FUNCTION_IN);
|
||||
|
||||
memory_pools_set_info (itti_desc.memory_pools_handle, message, 1, destination_task_id);
|
||||
#endif
|
||||
|
||||
if (itti_desc.threads[destination_thread_id].task_state == TASK_STATE_ENDED) {
|
||||
ITTI_DEBUG(ITTI_DEBUG_ISSUES, " Message %s, number %lu with priority %d can not be sent from %s to queue (%u:%s), ended destination task!\n",
|
||||
@@ -476,17 +379,6 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
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) {
|
||||
@@ -514,11 +406,6 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
|
||||
AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
|
||||
}
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_SEND_MSG,
|
||||
__sync_and_and_fetch (&itti_desc.vcd_send_msg, ~(1L << destination_task_id)));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -670,17 +557,9 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
|
||||
|
||||
void itti_receive_msg(task_id_t task_id, MessageDef **received_msg)
|
||||
{
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
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
|
||||
|
||||
itti_receive_msg_internal_event_fd(task_id, 0, received_msg);
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_RECV_MSG,
|
||||
__sync_or_and_fetch (&itti_desc.vcd_receive_msg, 1L << task_id));
|
||||
#endif
|
||||
}
|
||||
|
||||
void itti_poll_msg(task_id_t task_id, MessageDef **received_msg)
|
||||
@@ -689,11 +568,6 @@ void itti_poll_msg(task_id_t task_id, MessageDef **received_msg)
|
||||
|
||||
*received_msg = NULL;
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_POLL_MSG,
|
||||
__sync_or_and_fetch (&itti_desc.vcd_poll_msg, 1L << task_id));
|
||||
#endif
|
||||
|
||||
{
|
||||
struct message_list_s *message;
|
||||
|
||||
@@ -710,10 +584,6 @@ void itti_poll_msg(task_id_t task_id, MessageDef **received_msg)
|
||||
ITTI_DEBUG(ITTI_DEBUG_POLL, " No message in queue[(%u:%s)]\n", task_id, itti_get_task_name(task_id));
|
||||
}
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_POLL_MSG,
|
||||
__sync_and_and_fetch (&itti_desc.vcd_poll_msg, ~(1L << task_id)));
|
||||
#endif
|
||||
}
|
||||
|
||||
int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *args_p)
|
||||
@@ -745,7 +615,6 @@ int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *ar
|
||||
return 0;
|
||||
}
|
||||
|
||||
//#ifdef RTAI
|
||||
void itti_set_task_real_time(task_id_t task_id)
|
||||
{
|
||||
thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
|
||||
@@ -754,7 +623,6 @@ void itti_set_task_real_time(task_id_t task_id)
|
||||
|
||||
itti_desc.threads[thread_id].real_time = TRUE;
|
||||
}
|
||||
//#endif
|
||||
|
||||
void itti_wait_ready(int wait_tasks)
|
||||
{
|
||||
@@ -782,15 +650,6 @@ void itti_mark_task_ready(task_id_t task_id)
|
||||
/* Mark the thread as using LFDS queue */
|
||||
lfds611_queue_use(itti_desc.tasks[task_id].message_queue);
|
||||
|
||||
#ifdef RTAI
|
||||
/* Assign low priority to created threads */
|
||||
{
|
||||
struct sched_param sched_param;
|
||||
sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO) + 1;
|
||||
sched_setscheduler(0, SCHED_FIFO, &sched_param);
|
||||
}
|
||||
#endif
|
||||
|
||||
itti_desc.threads[thread_id].task_state = TASK_STATE_READY;
|
||||
itti_desc.ready_tasks ++;
|
||||
|
||||
@@ -803,15 +662,6 @@ 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);
|
||||
}
|
||||
|
||||
@@ -827,45 +677,6 @@ void itti_terminate_tasks(task_id_t task_id)
|
||||
pthread_exit (NULL);
|
||||
}
|
||||
|
||||
#ifdef RTAI
|
||||
static void *itti_rt_relay_thread(void *arg)
|
||||
{
|
||||
thread_id_t thread_id;
|
||||
unsigned pending_messages;
|
||||
|
||||
while (itti_desc.running) {
|
||||
usleep (200); // Poll for messages a little more than 2 time by slot to get a small latency between RT and other tasks
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_RELAY_THREAD, VCD_FUNCTION_IN);
|
||||
#endif
|
||||
|
||||
/* Checks for all non real time tasks if they have pending messages */
|
||||
for (thread_id = THREAD_FIRST; thread_id < itti_desc.thread_max; thread_id++) {
|
||||
if ((itti_desc.threads[thread_id].task_state == TASK_STATE_READY)
|
||||
&& (itti_desc.threads[thread_id].real_time == FALSE)) {
|
||||
pending_messages = __sync_fetch_and_and (&itti_desc.threads[thread_id].messages_pending, 0);
|
||||
|
||||
if (pending_messages > 0) {
|
||||
ssize_t write_ret;
|
||||
eventfd_t sem_counter = pending_messages;
|
||||
|
||||
/* Call to write for an event fd must be of 8 bytes */
|
||||
write_ret = write (itti_desc.threads[thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
|
||||
DevCheck(write_ret == sizeof(sem_counter), write_ret, sem_counter, thread_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_RELAY_THREAD, VCD_FUNCTION_OUT);
|
||||
#endif
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_id_max, const task_info_t *tasks_info,
|
||||
const message_info_t *messages_info, const char * const messages_definition_xml, const char * const dump_file_name)
|
||||
{
|
||||
@@ -946,45 +757,12 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
|
||||
ITTI_DEBUG(ITTI_DEBUG_EVEN_FD, " Successfully subscribed fd %d for thread %d\n",
|
||||
itti_desc.threads[thread_id].task_event_fd, thread_id);
|
||||
|
||||
#ifdef RTAI
|
||||
itti_desc.threads[thread_id].real_time = FALSE;
|
||||
itti_desc.threads[thread_id].messages_pending = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
itti_desc.running = 1;
|
||||
itti_desc.wait_tasks = 0;
|
||||
itti_desc.created_tasks = 0;
|
||||
itti_desc.ready_tasks = 0;
|
||||
#ifdef RTAI
|
||||
/* Start RT relay thread */
|
||||
DevAssert(pthread_create (&itti_desc.rt_relay_thread, NULL, itti_rt_relay_thread, NULL) >= 0);
|
||||
|
||||
rt_global_heap_open();
|
||||
#endif
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
itti_desc.memory_pools_handle = memory_pools_create (5);
|
||||
memory_pools_add_pool (itti_desc.memory_pools_handle, 1000 + ITTI_QUEUE_MAX_ELEMENTS, 50);
|
||||
memory_pools_add_pool (itti_desc.memory_pools_handle, 1000 + (2 * ITTI_QUEUE_MAX_ELEMENTS), 100);
|
||||
memory_pools_add_pool (itti_desc.memory_pools_handle, 10000, 1000);
|
||||
memory_pools_add_pool (itti_desc.memory_pools_handle, 400, 20050);
|
||||
memory_pools_add_pool (itti_desc.memory_pools_handle, 100, 30050);
|
||||
|
||||
{
|
||||
char *statistics = memory_pools_statistics (itti_desc.memory_pools_handle);
|
||||
|
||||
ITTI_DEBUG(ITTI_DEBUG_MP_STATISTICS, " Memory pools statistics:\n%s", statistics);
|
||||
free (statistics);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
itti_desc.vcd_poll_msg = 0;
|
||||
itti_desc.vcd_receive_msg = 0;
|
||||
itti_desc.vcd_send_msg = 0;
|
||||
#endif
|
||||
|
||||
itti_dump_init (messages_definition_xml, dump_file_name);
|
||||
|
||||
CHECK_INIT_RETURN(timer_init ());
|
||||
@@ -1047,15 +825,6 @@ void itti_wait_tasks_end(void)
|
||||
|
||||
itti_desc.running = 0;
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
{
|
||||
char *statistics = memory_pools_statistics (itti_desc.memory_pools_handle);
|
||||
|
||||
ITTI_DEBUG(ITTI_DEBUG_MP_STATISTICS, " Memory pools statistics:\n%s", statistics);
|
||||
free (statistics);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ready_tasks > 0) {
|
||||
ITTI_DEBUG(ITTI_DEBUG_ISSUES, " Some threads are still running, force exit\n");
|
||||
exit (0);
|
||||
|
||||
@@ -27,10 +27,6 @@
|
||||
|
||||
#include <sys/epoll.h>
|
||||
|
||||
#ifdef RTAI
|
||||
# include <rtai_sem.h>
|
||||
#endif
|
||||
|
||||
#ifndef INTERTASK_INTERFACE_H_
|
||||
#define INTERTASK_INTERFACE_H_
|
||||
|
||||
@@ -155,12 +151,10 @@ int itti_create_task(task_id_t task_id,
|
||||
void *(*start_routine) (void *),
|
||||
void *args_p);
|
||||
|
||||
//#ifdef RTAI
|
||||
/** \brief Mark the task as a real time task
|
||||
* \param task_id task to mark as real time
|
||||
**/
|
||||
void itti_set_task_real_time(task_id_t task_id);
|
||||
//#endif
|
||||
|
||||
/** \brief Indicates to ITTI if newly created tasks should wait for all tasks to be ready
|
||||
* \param wait_tasks non 0 to make new created tasks to wait, 0 to let created tasks to run
|
||||
|
||||
@@ -51,23 +51,14 @@
|
||||
#include "intertask_interface.h"
|
||||
#include "intertask_interface_dump.h"
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
#include "vcd_signal_dumper.h"
|
||||
#endif
|
||||
|
||||
#if T_TRACER
|
||||
#include "T.h"
|
||||
#endif
|
||||
|
||||
static const int itti_dump_debug = 0; // 0x8 | 0x4 | 0x2;
|
||||
|
||||
#ifdef RTAI
|
||||
# define ITTI_DUMP_DEBUG(m, x, args...) do { if ((m) & itti_dump_debug) rt_printk("[ITTI_DUMP][D]"x, ##args); } \
|
||||
while(0)
|
||||
#else
|
||||
# define ITTI_DUMP_DEBUG(m, x, args...) do { if ((m) & itti_dump_debug) fprintf(stdout, "[ITTI_DUMP][D]"x, ##args); } \
|
||||
while(0)
|
||||
#endif
|
||||
#define ITTI_DUMP_ERROR(x, args...) do { fprintf(stdout, "[ITTI_DUMP][E]"x, ##args); } \
|
||||
while(0)
|
||||
|
||||
@@ -99,13 +90,8 @@ typedef struct itti_desc_s {
|
||||
|
||||
int nb_connected;
|
||||
|
||||
#ifndef RTAI
|
||||
/* Event fd used to notify new messages (semaphore) */
|
||||
int event_fd;
|
||||
#else
|
||||
unsigned long messages_in_queue __attribute__((aligned(8)));
|
||||
#endif
|
||||
|
||||
int itti_listen_socket;
|
||||
|
||||
itti_client_desc_t itti_clients[ITTI_DUMP_MAX_CON];
|
||||
@@ -194,9 +180,7 @@ static int itti_dump_fwrite_message(itti_dump_queue_item_t *message)
|
||||
fwrite (&new_message_header, sizeof(itti_dump_message_t), 1, dump_file);
|
||||
fwrite (message->data, message->data_size, 1, dump_file);
|
||||
fwrite (&itti_dump_message_type_end, sizeof(itti_message_types_t), 1, dump_file);
|
||||
// #if !defined(RTAI)
|
||||
fflush (dump_file);
|
||||
// #endif
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -280,10 +264,6 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
|
||||
int overwrite_flag;
|
||||
AssertFatal (new != NULL, "Message to queue is NULL!\n");
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE, VCD_FUNCTION_IN);
|
||||
#endif
|
||||
|
||||
new->message_type = message_type;
|
||||
new->message_size = message_size;
|
||||
|
||||
@@ -303,9 +283,6 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
|
||||
lfds611_ringbuffer_put_write_element(itti_dump_queue.itti_message_queue, new_queue_element);
|
||||
|
||||
if (overwrite_flag == 0) {
|
||||
#ifdef RTAI
|
||||
__sync_fetch_and_add (&itti_dump_queue.messages_in_queue, 1);
|
||||
#else
|
||||
{
|
||||
ssize_t write_ret;
|
||||
eventfd_t sem_counter = 1;
|
||||
@@ -314,25 +291,18 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
|
||||
write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
|
||||
AssertFatal (write_ret == sizeof(sem_counter), "Write to dump event failed (%d/%d)!\n", (int) write_ret, (int) sizeof(sem_counter));
|
||||
}
|
||||
#endif
|
||||
// add one to pending_messages, atomically
|
||||
__sync_fetch_and_add (&pending_messages, 1);
|
||||
}
|
||||
|
||||
ITTI_DUMP_DEBUG (0x2, " Added element to queue %p %p, pending %u, type %u\n", new_queue_element, new, pending_messages, message_type);
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE, VCD_FUNCTION_OUT);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void itti_dump_socket_exit(void)
|
||||
{
|
||||
#ifndef RTAI
|
||||
close(itti_dump_queue.event_fd);
|
||||
#endif
|
||||
close(itti_dump_queue.itti_listen_socket);
|
||||
|
||||
/* Leave the thread as we detected end signal */
|
||||
@@ -346,10 +316,6 @@ static int itti_dump_flush_ring_buffer(int flush_all)
|
||||
int j;
|
||||
int consumer;
|
||||
|
||||
#ifdef RTAI
|
||||
unsigned long number_of_messages;
|
||||
#endif
|
||||
|
||||
/* Check if there is a least one consumer */
|
||||
consumer = 0;
|
||||
|
||||
@@ -365,18 +331,6 @@ static int itti_dump_flush_ring_buffer(int flush_all)
|
||||
}
|
||||
|
||||
if (consumer > 0) {
|
||||
#ifdef RTAI
|
||||
number_of_messages = itti_dump_queue.messages_in_queue;
|
||||
|
||||
ITTI_DUMP_DEBUG(0x4, "%lu elements in queue\n", number_of_messages);
|
||||
|
||||
if (number_of_messages == 0) {
|
||||
return (consumer);
|
||||
}
|
||||
|
||||
__sync_sub_and_fetch(&itti_dump_queue.messages_in_queue, number_of_messages);
|
||||
#endif
|
||||
|
||||
do {
|
||||
/* Acquire the ring element */
|
||||
lfds611_ringbuffer_get_read_element(itti_dump_queue.itti_message_queue, &element);
|
||||
@@ -419,9 +373,6 @@ static int itti_dump_flush_ring_buffer(int flush_all)
|
||||
lfds611_ringbuffer_put_read_element(itti_dump_queue.itti_message_queue, element);
|
||||
}
|
||||
} while(flush_all
|
||||
#ifdef RTAI
|
||||
&& --number_of_messages
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
@@ -478,9 +429,6 @@ static void *itti_dump_socket(void *arg_p)
|
||||
struct sockaddr_in servaddr; /* socket address structure */
|
||||
|
||||
struct timeval *timeout_p = NULL;
|
||||
#ifdef RTAI
|
||||
struct timeval timeout;
|
||||
#endif
|
||||
|
||||
ITTI_DUMP_DEBUG(0x2, " Creating TCP dump socket on port %u\n", ITTI_PORT);
|
||||
|
||||
@@ -536,15 +484,11 @@ static void *itti_dump_socket(void *arg_p)
|
||||
/* Add the listener */
|
||||
FD_SET(itti_listen_socket, &read_set);
|
||||
|
||||
#ifndef RTAI
|
||||
/* Add the event fd */
|
||||
FD_SET(itti_dump_queue.event_fd, &read_set);
|
||||
|
||||
/* Max of both sd */
|
||||
max_sd = itti_listen_socket > itti_dump_queue.event_fd ? itti_listen_socket : itti_dump_queue.event_fd;
|
||||
#else
|
||||
max_sd = itti_listen_socket;
|
||||
#endif
|
||||
|
||||
itti_dump_queue.itti_listen_socket = itti_listen_socket;
|
||||
|
||||
@@ -557,14 +501,7 @@ static void *itti_dump_socket(void *arg_p)
|
||||
int i;
|
||||
|
||||
memcpy(&working_set, &read_set, sizeof(read_set));
|
||||
#ifdef RTAI
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 100000;
|
||||
|
||||
timeout_p = &timeout;
|
||||
#else
|
||||
timeout_p = NULL;
|
||||
#endif
|
||||
|
||||
/* No timeout: select blocks till a new event has to be handled
|
||||
* on sd's.
|
||||
@@ -592,8 +529,6 @@ static void *itti_dump_socket(void *arg_p)
|
||||
if (FD_ISSET(i, &working_set)) {
|
||||
desc_ready -= 1;
|
||||
|
||||
#ifndef RTAI
|
||||
|
||||
if (i == itti_dump_queue.event_fd) {
|
||||
/* Notification of new element to dump from other tasks */
|
||||
eventfd_t sem_counter;
|
||||
@@ -613,7 +548,6 @@ static void *itti_dump_socket(void *arg_p)
|
||||
if (itti_dump_running) {
|
||||
ITTI_DUMP_DEBUG (0x4, " No messages consumers, waiting ...\n");
|
||||
usleep(100 * 1000);
|
||||
#ifndef RTAI
|
||||
{
|
||||
ssize_t write_ret;
|
||||
|
||||
@@ -622,7 +556,6 @@ static void *itti_dump_socket(void *arg_p)
|
||||
write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
|
||||
AssertFatal (write_ret == sizeof(sem_counter), "Failed to write to dump event FD (%d/%d)!\n", (int) write_ret, (int) sem_counter);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
itti_dump_socket_exit();
|
||||
}
|
||||
@@ -630,7 +563,6 @@ static void *itti_dump_socket(void *arg_p)
|
||||
ITTI_DUMP_DEBUG(0x1, " Write element to file\n");
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (i == itti_listen_socket) {
|
||||
do {
|
||||
client_socket = accept(itti_listen_socket, NULL, NULL);
|
||||
@@ -719,21 +651,9 @@ int itti_dump_queue_message(task_id_t sender_task,
|
||||
AssertFatal (message_name != NULL, "Message name is NULL!\n");
|
||||
AssertFatal (message_p != NULL, "Message is NULL!\n");
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE_MALLOC, VCD_FUNCTION_IN);
|
||||
#endif
|
||||
new = itti_malloc(sender_task, TASK_MAX, sizeof(itti_dump_queue_item_t));
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE_MALLOC, VCD_FUNCTION_OUT);
|
||||
#endif
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE_MALLOC, VCD_FUNCTION_IN);
|
||||
#endif
|
||||
new->data = itti_malloc(sender_task, TASK_MAX, message_size);
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE_MALLOC, VCD_FUNCTION_OUT);
|
||||
#endif
|
||||
|
||||
memcpy(new->data, message_p, message_size);
|
||||
new->data_size = message_size;
|
||||
@@ -791,9 +711,6 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
|
||||
AssertFatal (0, " Failed to create ring buffer!\n");
|
||||
}
|
||||
|
||||
#ifdef RTAI
|
||||
itti_dump_queue.messages_in_queue = 0;
|
||||
#else
|
||||
itti_dump_queue.event_fd = eventfd(0, EFD_SEMAPHORE);
|
||||
|
||||
if (itti_dump_queue.event_fd == -1) {
|
||||
@@ -801,8 +718,6 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
|
||||
AssertFatal (0, "eventfd failed: %s!\n", strerror(errno));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
itti_dump_queue.nb_connected = 0;
|
||||
|
||||
for(i = 0; i < ITTI_DUMP_MAX_CON; i++) {
|
||||
|
||||
@@ -27,11 +27,7 @@
|
||||
#ifndef _ITTI_TYPES_H_
|
||||
#define _ITTI_TYPES_H_
|
||||
|
||||
#ifdef USER_MODE
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <linux/types.h>
|
||||
#endif
|
||||
|
||||
#define CHARS_TO_UINT32(c1, c2, c3, c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1))
|
||||
|
||||
|
||||
@@ -19,15 +19,8 @@
|
||||
* contact@openairinterface.org
|
||||
*/
|
||||
|
||||
#ifdef RTAI
|
||||
# include <rtai_shm.h>
|
||||
#endif
|
||||
|
||||
#include "assertions.h"
|
||||
#include "memory_pools.h"
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
# include "vcd_signal_dumper.h"
|
||||
#endif
|
||||
|
||||
#if T_TRACER
|
||||
#include <string.h>
|
||||
@@ -37,18 +30,8 @@
|
||||
/*------------------------------------------------------------------------------*/
|
||||
const static int mp_debug = 0;
|
||||
|
||||
#ifdef RTAI
|
||||
# define MP_DEBUG(x, args...) do { if (mp_debug) rt_printk("[MP][D]"x, ##args); } \
|
||||
while(0)
|
||||
#else
|
||||
# define MP_DEBUG(x, args...) do { if (mp_debug) fprintf(stdout, "[MP][D]"x, ##args); fflush (stdout); } \
|
||||
while(0)
|
||||
#endif
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
uint64_t vcd_mp_alloc;
|
||||
uint64_t vcd_mp_free;
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
#ifndef CHARS_TO_UINT32
|
||||
@@ -414,11 +397,6 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
|
||||
pool_id_t pool;
|
||||
items_group_index_t item_index = ITEMS_GROUP_INDEX_INVALID;
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_MP_ALLOC,
|
||||
__sync_or_and_fetch (&vcd_mp_alloc, 1L << info_0));
|
||||
#endif
|
||||
|
||||
/* Recover memory_pools */
|
||||
memory_pools = memory_pools_from_handler (memory_pools_handle);
|
||||
AssertError (memory_pools != NULL, {}, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle);
|
||||
@@ -464,11 +442,6 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
|
||||
MP_DEBUG(" Alloc [--][------]{------}, %3u %3u, %6u, failed!\n", info_0, info_1, item_size);
|
||||
}
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_MP_ALLOC,
|
||||
__sync_and_and_fetch (&vcd_mp_alloc, ~(1L << info_0)));
|
||||
#endif
|
||||
|
||||
return memory_pool_item_handle;
|
||||
}
|
||||
|
||||
@@ -493,11 +466,6 @@ int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_it
|
||||
|
||||
info_1 = memory_pool_item->start.info[1];
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_MP_FREE,
|
||||
__sync_or_and_fetch (&vcd_mp_free, 1L << info_1));
|
||||
#endif
|
||||
|
||||
/* Recover pool index */
|
||||
pool = memory_pool_item->start.pool_id;
|
||||
AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)!\n", pool, memory_pools->pools_defined);
|
||||
@@ -531,11 +499,6 @@ int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_it
|
||||
|
||||
AssertError (result == EXIT_SUCCESS, {}, "Failed to free memory pool item (pool %u, item %d)!\n", pool, item_index);
|
||||
|
||||
#if defined(OAI_EMU) || defined(RTAI)
|
||||
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLE_MP_FREE,
|
||||
__sync_and_and_fetch (&vcd_mp_free, ~(1L << info_1)));
|
||||
#endif
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user