Commit aa65305f authored by winckel's avatar winckel

Integrated memory pools into ITTI for OAISIM and lte-softmodem targets.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4761 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent c4e45257
......@@ -37,20 +37,21 @@
#include <errno.h>
#include <signal.h>
#include "assertions.h"
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include "liblfds611.h"
#include "intertask_interface.h"
#include "intertask_interface_dump.h"
#ifdef RTAI
# include <rtai_shm.h>
#endif
#include "liblfds611.h"
#include "assertions.h"
#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
......@@ -175,6 +176,8 @@ typedef struct itti_desc_s {
#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;
......@@ -183,18 +186,26 @@ typedef struct itti_desc_s {
static itti_desc_t itti_desc;
void *itti_malloc(task_id_t task_id, ssize_t size)
void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size)
{
void *ptr = NULL;
#ifdef RTAI
// ptr = rt_malloc(size);
ptr = malloc(size);
#if defined(OAI_EMU) || defined(RTAI)
ptr = memory_pools_allocate (itti_desc.memory_pools_handle, size, origin_task_id, destination_task_id);
#else
ptr = malloc(size);
ptr = malloc (size);
#endif
DevCheck(ptr != NULL, size, task_id, 0);
DevCheck(ptr != NULL, size, origin_task_id, destination_task_id);
#if defined(OAI_EMU) || defined(RTAI)
if (ptr == NULL)
{
char *statistics = memory_pools_statistics (itti_desc.memory_pools_handle);
ITTI_ERROR ("\n%s", statistics);
free (statistics);
}
#endif
return ptr;
}
......@@ -202,10 +213,11 @@ void *itti_malloc(task_id_t task_id, ssize_t size)
void itti_free(task_id_t task_id, void *ptr)
{
DevAssert(ptr != NULL);
#ifdef RTAI
free(ptr);
#if defined(OAI_EMU) || defined(RTAI)
memory_pools_free (itti_desc.memory_pools_handle, ptr, task_id);
#else
free(ptr);
free (ptr);
#endif
}
......@@ -285,7 +297,7 @@ int itti_send_broadcast_message(MessageDef *message_p) {
if (thread_id != origin_thread_id) {
/* Skip tasks which are not running */
if (itti_desc.threads[thread_id].task_state == TASK_STATE_READY) {
new_message_p = itti_malloc (origin_task_id, sizeof(MessageDef));
new_message_p = itti_malloc (origin_task_id, destination_task_id, sizeof(MessageDef));
DevAssert(message_p != NULL);
memcpy (new_message_p, message_p, sizeof(MessageDef));
......@@ -294,7 +306,7 @@ int itti_send_broadcast_message(MessageDef *message_p) {
}
}
}
free (message_p);
itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
return ret;
}
......@@ -315,7 +327,7 @@ inline MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, Messag
origin_task_id = itti_get_current_task_id();
}
temp = itti_malloc (origin_task_id, sizeof(MessageHeader) + size);
temp = itti_malloc (origin_task_id, TASK_UNKNOWN, sizeof(MessageHeader) + size);
DevAssert(temp != NULL);
temp->ittiMsgHeader.messageId = message_id;
......@@ -392,7 +404,7 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
itti_desc.threads[destination_thread_id].task_state, message_id);
/* Allocate new list element */
new = (message_list_t *) itti_malloc (origin_task_id, sizeof(struct message_list_s));
new = (message_list_t *) itti_malloc (origin_task_id, destination_task_id, sizeof(struct message_list_s));
DevAssert(new != NULL);
/* Fill in members */
......@@ -610,7 +622,7 @@ void itti_receive_msg(task_id_t task_id, MessageDef **received_msg)
}
DevAssert(message != NULL);
*received_msg = message->msg;
free (message);
itti_free (ITTI_MSG_ORIGIN_ID(*received_msg), message);
itti_desc.threads[task_id].sem_counter--;
} else
......@@ -640,7 +652,7 @@ void itti_poll_msg(task_id_t task_id, MessageDef **received_msg) {
if (lfds611_queue_dequeue (itti_desc.tasks[task_id].message_queue, (void **) &message) == 1)
{
*received_msg = message->msg;
free (message);
itti_free (ITTI_MSG_ORIGIN_ID(*received_msg), message);
}
}
......@@ -907,6 +919,21 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
rt_global_heap_open();
#endif
#if defined(OAI_EMU) || defined(RTAI)
itti_desc.memory_pools_handle = memory_pools_create (4);
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, 1000, 1000);
memory_pools_add_pool (itti_desc.memory_pools_handle, 1000, 10000);
{
char *statistics = memory_pools_statistics (itti_desc.memory_pools_handle);
printf ("%s", statistics);
free (statistics);
}
#endif
#if defined(OAI_EMU) || defined(RTAI)
itti_desc.vcd_poll_msg = 0;
itti_desc.vcd_receive_msg = 0;
......@@ -968,6 +995,15 @@ 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);
printf ("%s", statistics);
free (statistics);
}
#endif
if (ready_tasks > 0) {
ITTI_DEBUG(" Some threads are still running, force exit\n");
exit (0);
......
......@@ -230,7 +230,7 @@ void itti_wait_tasks_end(void);
**/
void itti_send_terminate_message(task_id_t task_id);
void *itti_malloc(task_id_t task_id, ssize_t size);
void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size);
void itti_free(task_id_t task_id, void *ptr);
......
......@@ -230,7 +230,7 @@ void s1ap_eNB_handle_sctp_data_ind(sctp_data_ind_t *sctp_data_ind)
s1ap_eNB_handle_message(sctp_data_ind->assoc_id, sctp_data_ind->stream,
sctp_data_ind->buffer, sctp_data_ind->buffer_length);
free(sctp_data_ind->buffer);
itti_free(TASK_UNKNOWN, sctp_data_ind->buffer);
}
void *s1ap_eNB_task(void *arg)
......
......@@ -13,7 +13,7 @@ int sctp_itti_send_new_message_ind(task_id_t task_id, uint32_t assoc_id, uint8_t
sctp_data_ind_p = &message_p->ittiMsg.sctp_data_ind;
sctp_data_ind_p->buffer = malloc(sizeof(uint8_t) * buffer_length);
sctp_data_ind_p->buffer = itti_malloc(TASK_SCTP, task_id, sizeof(uint8_t) * buffer_length);
/* Copy the buffer */
memcpy((void *)sctp_data_ind_p->buffer, (void *)buffer, buffer_length);
......
......@@ -560,8 +560,7 @@ void *sctp_eNB_task(void *arg)
ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
break;
}
itti_free(TASK_SCTP, received_msg);
itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg);
received_msg = NULL;
}
......
......@@ -45,7 +45,7 @@
#define ITTI_PORT (10006)
/* This is the queue size for signal dumper */
#define ITTI_QUEUE_MAX_ELEMENTS (200 * 1000)
#define ITTI_QUEUE_MAX_ELEMENTS (10 * 1000)
#define ITTI_DUMP_MAX_CON (5) /* Max connections in parallel */
#endif /* INTERTASK_INTERFACE_CONF_H_ */
......@@ -485,7 +485,7 @@ u8 rrc_lite_data_req(u8 eNB_id, u8 UE_id, u32 frame, u8 eNB_flag, unsigned int r
// Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling).
u8 *message_buffer;
message_buffer = itti_malloc (eNB_flag ? TASK_RRC_ENB : TASK_RRC_UE, sdu_size);
message_buffer = itti_malloc (eNB_flag ? TASK_RRC_ENB : TASK_RRC_UE, eNB_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, sdu_size);
memcpy (message_buffer, Buffer, sdu_size);
message_p = itti_alloc_new_message (eNB_flag ? TASK_RRC_ENB : TASK_RRC_UE, RRC_DCCH_DATA_REQ);
......@@ -531,7 +531,7 @@ void rrc_lite_data_ind(u8_t eNB_id, u8_t UE_id, u32 frame, u8 eNB_flag,u32 Srb_i
// Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling).
u8 *message_buffer;
message_buffer = itti_malloc (eNB_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, sdu_size);
message_buffer = itti_malloc (eNB_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, eNB_flag ? TASK_RRC_ENB : TASK_RRC_UE, sdu_size);
memcpy (message_buffer, Buffer, sdu_size);
message_p = itti_alloc_new_message (eNB_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, RRC_DCCH_DATA_IND);
......@@ -542,7 +542,7 @@ void rrc_lite_data_ind(u8_t eNB_id, u8_t UE_id, u32 frame, u8 eNB_flag,u32 Srb_i
RRC_DCCH_DATA_IND (message_p).ue_index = UE_id;
RRC_DCCH_DATA_IND (message_p).eNB_index = eNB_id;
itti_send_msg_to_task ((eNB_flag == 1) ? TASK_RRC_ENB : TASK_RRC_UE, Mod_id, message_p);
itti_send_msg_to_task (eNB_flag ? TASK_RRC_ENB : TASK_RRC_UE, Mod_id, message_p);
}
#else
if (eNB_flag ==1) {
......
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