Commit 4424cffc authored by winckel's avatar winckel

Defined new unified assert for ITTI.

Changed size of largest memory pool items to support some long log message.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4765 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 35c08d81
...@@ -39,38 +39,35 @@ ...@@ -39,38 +39,35 @@
#ifndef ASSERTIONS_H_ #ifndef ASSERTIONS_H_
#define ASSERTIONS_H_ #define ASSERTIONS_H_
#define DevCheck(cOND, vALUE1, vALUE2, vALUE3) \ #define _Assert_(cOND, eXIT, fORMAT, aRGS...) \
do { \ do { \
if (!(cOND)) { \ if (!(cOND)) { \
fprintf(stderr, "%s:%d:%s Assertion `"#cOND"` failed.\n", \ fprintf(stderr, "%s:%d:%s Assertion `"#cOND"` failed!\n" fORMAT, \
__FILE__, __LINE__, __FUNCTION__); \ __FILE__, __LINE__, __FUNCTION__, ##aRGS); \
fprintf(stderr, #vALUE1": %d\n"#vALUE2": %d\n"#vALUE3": %d\n\n", \ if (eXIT != 0) { \
(int)vALUE1, (int)vALUE2, (int)vALUE3); \ display_backtrace(); \
display_backtrace(); \ fflush(stdout); \
exit(EXIT_FAILURE); \ fflush(stderr); \
exit(EXIT_FAILURE); \
} \
} \ } \
} while(0) } while(0)
#define DevParam(vALUE1, vALUE2, vALUE3) \ #define AssertFatal(cOND, fORMAT, aRGS...) _Assert_(cOND, 1, fORMAT, ##aRGS)
DevCheck(0 == 1, vALUE1, vALUE2, vALUE3)
#define DevAssert(cOND) \
do { \
if (!(cOND)) { \
fprintf(stderr, "%s:%d:%s Assertion `"#cOND"` failed.\n", \
__FILE__, __LINE__, __FUNCTION__); \
display_backtrace(); \
exit(EXIT_FAILURE); \
} \
} while(0)
#define DevMessage(mESSAGE) \ #define AssertError(cOND, fORMAT, aRGS...) _Assert_(cOND, 0, fORMAT, ##aRGS)
do { \
fprintf(stderr, "%s:%d:%s Execution interrupted: `"#mESSAGE"`.\n", \
__FILE__, __LINE__, __FUNCTION__); \
display_backtrace(); \ #define DevCheck(cOND, vALUE1, vALUE2, vALUE3) \
exit(EXIT_FAILURE); \ _Assert_(cOND, 1, #vALUE1": %d\n"#vALUE2": %d\n"#vALUE3": %d\n\n", \
} while(0) (int)vALUE1, (int)vALUE2, (int)vALUE3)
#define DevParam(vALUE1, vALUE2, vALUE3) DevCheck(0, vALUE1, vALUE2, vALUE3)
#define DevAssert(cOND) _Assert_(cOND, 1, "")
#define DevMessage(mESSAGE) _Assert_(0, 1, #mESSAGE)
#define CHECK_INIT_RETURN(fCT) \ #define CHECK_INIT_RETURN(fCT) \
do { \ do { \
......
...@@ -204,7 +204,6 @@ void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize ...@@ -204,7 +204,6 @@ void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize
ptr = malloc (size); ptr = malloc (size);
#endif #endif
DevCheck(ptr != NULL, size, origin_task_id, destination_task_id);
#if defined(OAI_EMU) || defined(RTAI) #if defined(OAI_EMU) || defined(RTAI)
if (ptr == NULL) if (ptr == NULL)
{ {
...@@ -214,13 +213,14 @@ void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize ...@@ -214,13 +213,14 @@ void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize
free (statistics); free (statistics);
} }
#endif #endif
AssertFatal (ptr != NULL, "Memory allocation of %ld bytes failed (%d -> %d)\n", size, origin_task_id, destination_task_id);
return ptr; return ptr;
} }
void itti_free(task_id_t task_id, void *ptr) void itti_free(task_id_t task_id, void *ptr)
{ {
DevAssert(ptr != NULL); AssertFatal (ptr != NULL, "Trying to free a NULL pointer (%d)\n", task_id);
#if defined(OAI_EMU) || defined(RTAI) #if defined(OAI_EMU) || defined(RTAI)
memory_pools_free (itti_desc.memory_pools_handle, ptr, task_id); memory_pools_free (itti_desc.memory_pools_handle, ptr, task_id);
...@@ -238,20 +238,20 @@ static inline message_number_t itti_increment_message_number(void) { ...@@ -238,20 +238,20 @@ static inline message_number_t itti_increment_message_number(void) {
} }
static inline uint32_t itti_get_message_priority(MessagesIds message_id) { static inline uint32_t itti_get_message_priority(MessagesIds message_id) {
DevCheck(message_id < itti_desc.messages_id_max, message_id, itti_desc.messages_id_max, 0); AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)\n", message_id, itti_desc.messages_id_max);
return (itti_desc.messages_info[message_id].priority); return (itti_desc.messages_info[message_id].priority);
} }
const char *itti_get_message_name(MessagesIds message_id) { const char *itti_get_message_name(MessagesIds message_id) {
DevCheck(message_id < itti_desc.messages_id_max, message_id, itti_desc.messages_id_max, 0); AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)\n", message_id, itti_desc.messages_id_max);
return (itti_desc.messages_info[message_id].name); return (itti_desc.messages_info[message_id].name);
} }
const char *itti_get_task_name(task_id_t task_id) const char *itti_get_task_name(task_id_t task_id)
{ {
DevCheck(task_id < itti_desc.task_max, task_id, itti_desc.task_max, 0); AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
return (itti_desc.tasks_info[task_id].name); return (itti_desc.tasks_info[task_id].name);
} }
...@@ -288,7 +288,7 @@ int itti_send_broadcast_message(MessageDef *message_p) { ...@@ -288,7 +288,7 @@ int itti_send_broadcast_message(MessageDef *message_p) {
int ret = 0; int ret = 0;
int result; int result;
DevAssert(message_p != NULL); AssertFatal (message_p != NULL, "Trying to broadcast a NULL message\n");
origin_task_id = message_p->ittiMsgHeader.originTaskId; origin_task_id = message_p->ittiMsgHeader.originTaskId;
origin_thread_id = TASK_GET_THREAD_ID(origin_task_id); origin_thread_id = TASK_GET_THREAD_ID(origin_task_id);
...@@ -306,11 +306,10 @@ int itti_send_broadcast_message(MessageDef *message_p) { ...@@ -306,11 +306,10 @@ int itti_send_broadcast_message(MessageDef *message_p) {
/* Skip tasks which are not running */ /* Skip tasks which are not running */
if (itti_desc.threads[thread_id].task_state == TASK_STATE_READY) { if (itti_desc.threads[thread_id].task_state == TASK_STATE_READY) {
new_message_p = itti_malloc (origin_task_id, destination_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)); memcpy (new_message_p, message_p, sizeof(MessageDef));
result = itti_send_msg_to_task (destination_task_id, INSTANCE_DEFAULT, new_message_p); result = itti_send_msg_to_task (destination_task_id, INSTANCE_DEFAULT, new_message_p);
DevCheck(result >= 0, message_p->ittiMsgHeader.messageId, thread_id, destination_task_id); AssertFatal (result >= 0, "Failed to send message %d to thread %d (task %d)\n", message_p->ittiMsgHeader.messageId, thread_id, destination_task_id);
} }
} }
} }
...@@ -323,7 +322,7 @@ inline MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, Messag ...@@ -323,7 +322,7 @@ inline MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, Messag
{ {
MessageDef *temp = NULL; MessageDef *temp = NULL;
DevCheck(message_id < itti_desc.messages_id_max, message_id, itti_desc.messages_id_max, 0); 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) #if defined(OAI_EMU) || defined(RTAI)
vcd_signal_dumper_dump_variable_by_name(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_ALLOC_MSG, size); vcd_signal_dumper_dump_variable_by_name(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_ALLOC_MSG, size);
...@@ -336,7 +335,6 @@ inline MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, Messag ...@@ -336,7 +335,6 @@ inline MessageDef *itti_alloc_new_message_sized(task_id_t origin_task_id, Messag
} }
temp = itti_malloc (origin_task_id, TASK_UNKNOWN, sizeof(MessageHeader) + size); temp = itti_malloc (origin_task_id, TASK_UNKNOWN, sizeof(MessageHeader) + size);
DevAssert(temp != NULL);
temp->ittiMsgHeader.messageId = message_id; temp->ittiMsgHeader.messageId = message_id;
temp->ittiMsgHeader.originTaskId = origin_task_id; temp->ittiMsgHeader.originTaskId = origin_task_id;
...@@ -368,8 +366,8 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me ...@@ -368,8 +366,8 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
__sync_or_and_fetch (&itti_desc.vcd_send_msg, 1L << destination_task_id)); __sync_or_and_fetch (&itti_desc.vcd_send_msg, 1L << destination_task_id));
#endif #endif
DevAssert(message != NULL); AssertFatal (message != NULL, "Message is NULL\n");
DevCheck(destination_task_id < itti_desc.task_max, destination_task_id, itti_desc.task_max, 0); 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);
destination_thread_id = TASK_GET_THREAD_ID(destination_task_id); destination_thread_id = TASK_GET_THREAD_ID(destination_task_id);
message->ittiMsgHeader.destinationTaskId = destination_task_id; message->ittiMsgHeader.destinationTaskId = destination_task_id;
...@@ -377,7 +375,7 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me ...@@ -377,7 +375,7 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
message->ittiMsgHeader.lte_time.frame = itti_desc.lte_time.frame; message->ittiMsgHeader.lte_time.frame = itti_desc.lte_time.frame;
message->ittiMsgHeader.lte_time.slot = itti_desc.lte_time.slot; message->ittiMsgHeader.lte_time.slot = itti_desc.lte_time.slot;
message_id = message->ittiMsgHeader.messageId; message_id = message->ittiMsgHeader.messageId;
DevCheck(message_id < itti_desc.messages_id_max, itti_desc.messages_id_max, message_id, 0); AssertFatal (message_id < itti_desc.messages_id_max, "Message id (%d) is out of range (%d)\n", message_id, itti_desc.messages_id_max);
origin_task_id = ITTI_MSG_ORIGIN_ID(message); origin_task_id = ITTI_MSG_ORIGIN_ID(message);
...@@ -408,12 +406,11 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me ...@@ -408,12 +406,11 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
else else
{ {
/* We cannot send a message if the task is not running */ /* 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, AssertFatal (itti_desc.threads[destination_thread_id].task_state == TASK_STATE_READY, "Cannot send message %d to thread %d, it is not in ready state (%d)\n",
itti_desc.threads[destination_thread_id].task_state, message_id); message_id, destination_thread_id, itti_desc.threads[destination_thread_id].task_state);
/* Allocate new list element */ /* Allocate new list element */
new = (message_list_t *) itti_malloc (origin_task_id, destination_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 */ /* Fill in members */
new->msg = message; new->msg = message;
...@@ -444,7 +441,8 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me ...@@ -444,7 +441,8 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
/* Call to write for an event fd must be of 8 bytes */ /* 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)); 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); AssertFatal (write_ret == sizeof(sem_counter), "Write to task message FD (%d) failed (%ld/%ld)\n",
destination_thread_id, write_ret, sizeof(sem_counter));
} }
} }
...@@ -474,8 +472,7 @@ void itti_subscribe_event_fd(task_id_t task_id, int fd) ...@@ -474,8 +472,7 @@ void itti_subscribe_event_fd(task_id_t task_id, int fd)
thread_id_t thread_id; thread_id_t thread_id;
struct epoll_event event; struct epoll_event event;
DevCheck(task_id < itti_desc.task_max, task_id, itti_desc.task_max, 0); AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
DevCheck(fd >= 0, fd, 0, 0);
thread_id = TASK_GET_THREAD_ID(task_id); thread_id = TASK_GET_THREAD_ID(task_id);
itti_desc.threads[thread_id].nb_events++; itti_desc.threads[thread_id].nb_events++;
...@@ -493,10 +490,9 @@ void itti_subscribe_event_fd(task_id_t task_id, int fd) ...@@ -493,10 +490,9 @@ void itti_subscribe_event_fd(task_id_t task_id, int fd)
if (epoll_ctl(itti_desc.threads[thread_id].epoll_fd, EPOLL_CTL_ADD, fd, if (epoll_ctl(itti_desc.threads[thread_id].epoll_fd, EPOLL_CTL_ADD, fd,
&event) != 0) &event) != 0)
{ {
ITTI_ERROR(" epoll_ctl (EPOLL_CTL_ADD) failed for task %s, fd %d: %s\n",
itti_get_task_name(task_id), fd, strerror(errno));
/* Always assert on this condition */ /* Always assert on this condition */
DevAssert(0 == 1); AssertFatal (0, "epoll_ctl (EPOLL_CTL_ADD) failed for task %s, fd %d: %s\n",
itti_get_task_name(task_id), fd, strerror(errno));
} }
ITTI_DEBUG(ITTI_DEBUG_EVEN_FD, " Successfully subscribed fd %d for task %s\n", fd, itti_get_task_name(task_id)); ITTI_DEBUG(ITTI_DEBUG_EVEN_FD, " Successfully subscribed fd %d for task %s\n", fd, itti_get_task_name(task_id));
...@@ -506,17 +502,16 @@ void itti_unsubscribe_event_fd(task_id_t task_id, int fd) ...@@ -506,17 +502,16 @@ void itti_unsubscribe_event_fd(task_id_t task_id, int fd)
{ {
thread_id_t thread_id; thread_id_t thread_id;
DevCheck(task_id < itti_desc.task_max, task_id, itti_desc.task_max, 0); AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
DevCheck(fd >= 0, fd, 0, 0); AssertFatal (fd >= 0, "File descriptor (%d) is invalid\n", fd);
thread_id = TASK_GET_THREAD_ID(task_id); thread_id = TASK_GET_THREAD_ID(task_id);
/* Add the event fd to the list of monitored events */ /* Add the event fd to the list of monitored events */
if (epoll_ctl(itti_desc.threads[thread_id].epoll_fd, EPOLL_CTL_DEL, fd, NULL) != 0) if (epoll_ctl(itti_desc.threads[thread_id].epoll_fd, EPOLL_CTL_DEL, fd, NULL) != 0)
{ {
ITTI_ERROR(" epoll_ctl (EPOLL_CTL_DEL) failed for task %s and fd %d: %s\n",
itti_get_task_name(task_id), fd, strerror(errno));
/* Always assert on this condition */ /* Always assert on this condition */
DevAssert(0 == 1); AssertFatal (0, "epoll_ctl (EPOLL_CTL_DEL) failed for task %s, fd %d: %s\n",
itti_get_task_name(task_id), fd, strerror(errno));
} }
itti_desc.threads[thread_id].nb_events--; itti_desc.threads[thread_id].nb_events--;
...@@ -529,7 +524,7 @@ int itti_get_events(task_id_t task_id, struct epoll_event **events) ...@@ -529,7 +524,7 @@ int itti_get_events(task_id_t task_id, struct epoll_event **events)
{ {
thread_id_t thread_id; thread_id_t thread_id;
DevCheck(task_id < itti_desc.task_max, task_id, itti_desc.task_max, 0); AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
thread_id = TASK_GET_THREAD_ID(task_id); thread_id = TASK_GET_THREAD_ID(task_id);
*events = itti_desc.threads[thread_id].events; *events = itti_desc.threads[thread_id].events;
...@@ -544,8 +539,8 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t ...@@ -544,8 +539,8 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
int epoll_timeout = 0; int epoll_timeout = 0;
int i; int i;
DevCheck(task_id < itti_desc.task_max, task_id, itti_desc.task_max, 0); AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
DevAssert(received_msg != NULL); AssertFatal (received_msg != NULL, "Received message is NULL\n");
thread_id = TASK_GET_THREAD_ID(task_id); thread_id = TASK_GET_THREAD_ID(task_id);
*received_msg = NULL; *received_msg = NULL;
...@@ -569,9 +564,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t ...@@ -569,9 +564,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
} while (epoll_ret < 0 && errno == EINTR); } while (epoll_ret < 0 && errno == EINTR);
if (epoll_ret < 0) { if (epoll_ret < 0) {
ITTI_ERROR(" epoll_wait failed for task %s: %s\n", AssertFatal (0, "epoll_wait failed for task %s: %s\n", itti_get_task_name(task_id), strerror(errno));
itti_get_task_name(task_id), strerror(errno));
DevAssert(0 == 1);
} }
if (epoll_ret == 0 && polling) { if (epoll_ret == 0 && polling) {
/* No data to read -> return */ /* No data to read -> return */
...@@ -591,7 +584,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t ...@@ -591,7 +584,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
/* Read will always return 1 */ /* Read will always return 1 */
read_ret = read (itti_desc.threads[thread_id].task_event_fd, &sem_counter, sizeof(sem_counter)); read_ret = read (itti_desc.threads[thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
DevCheck(read_ret == sizeof(sem_counter), read_ret, sizeof(sem_counter), 0); AssertFatal (read_ret == sizeof(sem_counter), "Read from task message FD (%d) failed (%ld/%ld)\n", thread_id, read_ret, sizeof(sem_counter));
#if defined(KERNEL_VERSION_PRE_2_6_30) #if defined(KERNEL_VERSION_PRE_2_6_30)
/* Store the value of the semaphore counter */ /* Store the value of the semaphore counter */
...@@ -600,9 +593,9 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t ...@@ -600,9 +593,9 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
if (lfds611_queue_dequeue (itti_desc.tasks[task_id].message_queue, (void **) &message) == 0) { if (lfds611_queue_dequeue (itti_desc.tasks[task_id].message_queue, (void **) &message) == 0) {
/* No element in list -> this should not happen */ /* No element in list -> this should not happen */
DevParam(task_id, epoll_ret, 0); AssertFatal (0, "No message in queue for task %d while there are %d events and some for the messages queue\n", task_id, epoll_ret);
} }
DevAssert(message != NULL); AssertFatal(message != NULL, "Message from message queue is NULL\n");
*received_msg = message->msg; *received_msg = message->msg;
itti_free (ITTI_MSG_ORIGIN_ID(*received_msg), message); itti_free (ITTI_MSG_ORIGIN_ID(*received_msg), message);
/* Mark that the event has been processed */ /* Mark that the event has been processed */
...@@ -644,8 +637,7 @@ void itti_receive_msg(task_id_t task_id, MessageDef **received_msg) ...@@ -644,8 +637,7 @@ void itti_receive_msg(task_id_t task_id, MessageDef **received_msg)
} }
void itti_poll_msg(task_id_t task_id, MessageDef **received_msg) { void itti_poll_msg(task_id_t task_id, MessageDef **received_msg) {
DevCheck(task_id < itti_desc.task_max, task_id, itti_desc.task_max, 0); AssertFatal (task_id < itti_desc.task_max, "Task id (%d) is out of range (%d)\n", task_id, itti_desc.task_max);
DevAssert(received_msg != NULL);
*received_msg = NULL; *received_msg = NULL;
...@@ -678,17 +670,17 @@ int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *ar ...@@ -678,17 +670,17 @@ int itti_create_task(task_id_t task_id, void *(*start_routine)(void *), void *ar
thread_id_t thread_id = TASK_GET_THREAD_ID(task_id); thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
int result; int result;
DevAssert(start_routine != NULL); AssertFatal (start_routine != NULL, "Start routine is NULL\n");
DevCheck(thread_id < itti_desc.thread_max, thread_id, itti_desc.thread_max, 0); AssertFatal (thread_id < itti_desc.thread_max, "Thread id (%d) is out of range (%d)\n", thread_id, itti_desc.thread_max);
DevCheck(itti_desc.threads[thread_id].task_state == TASK_STATE_NOT_CONFIGURED, task_id, thread_id, AssertFatal (itti_desc.threads[thread_id].task_state == TASK_STATE_NOT_CONFIGURED, "Task %d, thread %d state is not correct (%d)\n",
itti_desc.threads[thread_id].task_state); task_id, thread_id, itti_desc.threads[thread_id].task_state);
itti_desc.threads[thread_id].task_state = TASK_STATE_STARTING; itti_desc.threads[thread_id].task_state = TASK_STATE_STARTING;
ITTI_DEBUG(ITTI_DEBUG_INIT, " Creating thread for task %s ...\n", itti_get_task_name(task_id)); ITTI_DEBUG(ITTI_DEBUG_INIT, " Creating thread for task %s ...\n", itti_get_task_name(task_id));
result = pthread_create (&itti_desc.threads[thread_id].task_thread, NULL, start_routine, args_p); result = pthread_create (&itti_desc.threads[thread_id].task_thread, NULL, start_routine, args_p);
DevCheck(result >= 0, task_id, thread_id, result); AssertFatal (result >= 0, "Thread creation for task %d, thread %d failed (%d)\n", task_id, thread_id, result);
itti_desc.created_tasks ++; itti_desc.created_tasks ++;
...@@ -717,14 +709,15 @@ void itti_wait_ready(int wait_tasks) ...@@ -717,14 +709,15 @@ void itti_wait_ready(int wait_tasks)
ITTI_DEBUG(ITTI_DEBUG_INIT, " wait for tasks: %s, created tasks %d, ready tasks %d\n", itti_desc.wait_tasks ? "yes" : "no", ITTI_DEBUG(ITTI_DEBUG_INIT, " wait for tasks: %s, created tasks %d, ready tasks %d\n", itti_desc.wait_tasks ? "yes" : "no",
itti_desc.created_tasks, itti_desc.ready_tasks); itti_desc.created_tasks, itti_desc.ready_tasks);
DevCheck(itti_desc.created_tasks == itti_desc.ready_tasks, itti_desc.created_tasks, itti_desc.ready_tasks, itti_desc.wait_tasks); AssertFatal (itti_desc.created_tasks == itti_desc.ready_tasks, "Number of created tasks (%d) does not match ready tasks (%d), wait task %d\n",
itti_desc.created_tasks, itti_desc.ready_tasks, itti_desc.wait_tasks);
} }
void itti_mark_task_ready(task_id_t task_id) void itti_mark_task_ready(task_id_t task_id)
{ {
thread_id_t thread_id = TASK_GET_THREAD_ID(task_id); thread_id_t thread_id = TASK_GET_THREAD_ID(task_id);
DevCheck(thread_id < itti_desc.thread_max, thread_id, itti_desc.thread_max, 0); AssertFatal (thread_id < itti_desc.thread_max, "Thread id (%d) is out of range (%d)\n", thread_id, itti_desc.thread_max);
/* Register the thread in itti dump */ /* Register the thread in itti dump */
itti_dump_thread_use_ring_buffer(); itti_dump_thread_use_ring_buffer();
...@@ -859,8 +852,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i ...@@ -859,8 +852,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
ret = lfds611_queue_new(&itti_desc.tasks[task_id].message_queue, itti_desc.tasks_info[task_id].queue_size); ret = lfds611_queue_new(&itti_desc.tasks[task_id].message_queue, itti_desc.tasks_info[task_id].queue_size);
if (ret < 0) if (ret < 0)
{ {
ITTI_ERROR(" lfds611_queue_new failed for task %u\n", task_id); AssertFatal (0, "lfds611_queue_new failed for task %s\n", itti_get_task_name(task_id));
DevAssert(0 == 1);
} }
} }
...@@ -871,9 +863,8 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i ...@@ -871,9 +863,8 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
itti_desc.threads[thread_id].epoll_fd = epoll_create1(0); itti_desc.threads[thread_id].epoll_fd = epoll_create1(0);
if (itti_desc.threads[thread_id].epoll_fd == -1) { if (itti_desc.threads[thread_id].epoll_fd == -1) {
ITTI_ERROR(" Failed to create new epoll fd: %s\n", strerror(errno));
/* Always assert on this condition */ /* Always assert on this condition */
DevAssert(0 == 1); AssertFatal (0, "Failed to create new epoll fd: %s\n", strerror(errno));
} }
# if defined(KERNEL_VERSION_PRE_2_6_30) # if defined(KERNEL_VERSION_PRE_2_6_30)
...@@ -886,9 +877,8 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i ...@@ -886,9 +877,8 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
# endif # endif
if (itti_desc.threads[thread_id].task_event_fd == -1) if (itti_desc.threads[thread_id].task_event_fd == -1)
{ {
ITTI_ERROR(" eventfd failed: %s\n", strerror(errno));
/* Always assert on this condition */ /* Always assert on this condition */
DevAssert(0 == 1); AssertFatal (0, " eventfd failed: %s\n", strerror(errno));
} }
itti_desc.threads[thread_id].nb_events = 1; itti_desc.threads[thread_id].nb_events = 1;
...@@ -902,9 +892,8 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i ...@@ -902,9 +892,8 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
if (epoll_ctl(itti_desc.threads[thread_id].epoll_fd, EPOLL_CTL_ADD, if (epoll_ctl(itti_desc.threads[thread_id].epoll_fd, EPOLL_CTL_ADD,
itti_desc.threads[thread_id].task_event_fd, itti_desc.threads[thread_id].events) != 0) itti_desc.threads[thread_id].task_event_fd, itti_desc.threads[thread_id].events) != 0)
{ {
ITTI_ERROR(" epoll_ctl (EPOLL_CTL_ADD) failed: %s\n", strerror(errno));
/* Always assert on this condition */ /* Always assert on this condition */
DevAssert(0 == 1); AssertFatal (0, " epoll_ctl (EPOLL_CTL_ADD) failed: %s\n", strerror(errno));
} }
ITTI_DEBUG(ITTI_DEBUG_EVEN_FD, " Successfully subscribed fd %d for thread %d\n", ITTI_DEBUG(ITTI_DEBUG_EVEN_FD, " Successfully subscribed fd %d for thread %d\n",
...@@ -932,7 +921,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i ...@@ -932,7 +921,7 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
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 + 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 + (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, 1000);
memory_pools_add_pool (itti_desc.memory_pools_handle, 1000, 10000); memory_pools_add_pool (itti_desc.memory_pools_handle, 500, 20000);
{ {
char *statistics = memory_pools_statistics (itti_desc.memory_pools_handle); char *statistics = memory_pools_statistics (itti_desc.memory_pools_handle);
......
...@@ -165,11 +165,11 @@ static int itti_dump_send_message(int sd, itti_dump_queue_item_t *message) ...@@ -165,11 +165,11 @@ static int itti_dump_send_message(int sd, itti_dump_queue_item_t *message)
/* Allocate memory for message header and payload */ /* Allocate memory for message header and payload */
size_t size = sizeof(itti_dump_message_t) + message->data_size; size_t size = sizeof(itti_dump_message_t) + message->data_size;
DevCheck(sd > 0, sd, 0, 0); AssertFatal (sd > 0, "Socket descriptor (%d) is invalid\n", sd);
DevAssert(message != NULL); AssertFatal (message != NULL, "Message is NULL\n");
new_message = calloc(1, size); new_message = calloc(1, size);
DevAssert(new_message != NULL); AssertFatal (new_message != NULL, "New message allocation failed\n");
/* Preparing the header */ /* Preparing the header */
new_message->header.message_size = size; new_message->header.message_size = size;
...@@ -228,8 +228,8 @@ static int itti_dump_send_xml_definition(const int sd, const char *message_defin ...@@ -228,8 +228,8 @@ static int itti_dump_send_xml_definition(const int sd, const char *message_defin
ssize_t bytes_sent = 0, total_sent = 0; ssize_t bytes_sent = 0, total_sent = 0;
uint8_t *data_ptr; uint8_t *data_ptr;
DevCheck(sd > 0, sd, 0, 0); AssertFatal (sd > 0, "Socket descriptor (%d) is invalid\n", sd);
DevAssert(message_definition_xml != NULL); AssertFatal (message_definition_xml != NULL, "Message definition XML is NULL\n");
itti_dump_message_size = sizeof(itti_socket_header_t) + message_definition_xml_length; itti_dump_message_size = sizeof(itti_socket_header_t) + message_definition_xml_length;
...@@ -289,7 +289,7 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa ...@@ -289,7 +289,7 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
{ {
struct lfds611_freelist_element *new_queue_element = NULL; struct lfds611_freelist_element *new_queue_element = NULL;
int overwrite_flag; int overwrite_flag;
DevAssert(new != NULL); AssertFatal (new != NULL, "Message to queue is NULL\n");
#if defined(OAI_EMU) || defined(RTAI) #if defined(OAI_EMU) || defined(RTAI)
vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE, VCD_FUNCTION_IN); vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE, VCD_FUNCTION_IN);
...@@ -324,7 +324,7 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa ...@@ -324,7 +324,7 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
/* Call to write for an event fd must be of 8 bytes */ /* Call to write for an event fd must be of 8 bytes */
write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter)); write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
DevCheck(write_ret == sizeof(sem_counter), write_ret, sem_counter, 0); AssertFatal (write_ret == sizeof(sem_counter), "Write to dump event failed (%ld/%ld)\n", write_ret, sizeof(sem_counter));
} }
#endif #endif
__sync_fetch_and_add (&pending_messages, 1); __sync_fetch_and_add (&pending_messages, 1);
...@@ -405,8 +405,7 @@ static int itti_dump_flush_ring_buffer(int flush_all) ...@@ -405,8 +405,7 @@ static int itti_dump_flush_ring_buffer(int flush_all)
} }
else else
{ {
ITTI_DUMP_DEBUG(0x8, " Dump event with no data\n"); AssertFatal (0, "Dump event with no data\n");
DevMessage("Dump event with no data\n");
} }
} }
else else
...@@ -463,13 +462,13 @@ static int itti_dump_handle_new_connection(int sd, const char *xml_definition, u ...@@ -463,13 +462,13 @@ static int itti_dump_handle_new_connection(int sd, const char *xml_definition, u
ITTI_DUMP_DEBUG(0x2, " Found place to store new connection: %d\n", i); ITTI_DUMP_DEBUG(0x2, " Found place to store new connection: %d\n", i);
DevCheck(i < ITTI_DUMP_MAX_CON, i, ITTI_DUMP_MAX_CON, sd); AssertFatal (i < ITTI_DUMP_MAX_CON, "No more connection available (%d/%d) for socked %d\n", i, ITTI_DUMP_MAX_CON, sd);
ITTI_DUMP_DEBUG(0x2, " Socket %d accepted\n", sd); ITTI_DUMP_DEBUG(0x2, " Socket %d accepted\n", sd);
/* Send the XML message definition */ /* Send the XML message definition */
if (itti_dump_send_xml_definition(sd, xml_definition, xml_definition_length) < 0) { if (itti_dump_send_xml_definition(sd, xml_definition, xml_definition_length) < 0) {
ITTI_DUMP_ERROR(" Failed to send XML definition\n"); AssertError (0, " Failed to send XML definition\n");
close (sd); close (sd);
return -1; return -1;
} }
...@@ -506,7 +505,7 @@ static void *itti_dump_socket(void *arg_p) ...@@ -506,7 +505,7 @@ static void *itti_dump_socket(void *arg_p)
ITTI_DUMP_DEBUG(0x2, " Creating TCP dump socket on port %u\n", ITTI_PORT); ITTI_DUMP_DEBUG(0x2, " Creating TCP dump socket on port %u\n", ITTI_PORT);
message_definition_xml = (char *)arg_p; message_definition_xml = (char *)arg_p;
DevAssert(message_definition_xml != NULL); AssertFatal (message_definition_xml != NULL, "Message definition XML is NULL\n");
message_definition_xml_length = strlen(message_definition_xml) + 1; message_definition_xml_length = strlen(message_definition_xml) + 1;
...@@ -627,7 +626,7 @@ static void *itti_dump_socket(void *arg_p) ...@@ -627,7 +626,7 @@ static void *itti_dump_socket(void *arg_p)
ITTI_DUMP_ERROR(" Failed read for semaphore: %s\n", strerror(errno)); ITTI_DUMP_ERROR(" Failed read for semaphore: %s\n", strerror(errno));
pthread_exit(NULL); pthread_exit(NULL);
} }
DevCheck(read_ret == sizeof(sem_counter), read_ret, sizeof(sem_counter), 0); AssertFatal (read_ret == sizeof(sem_counter), "Failed to read from dump event FD (%ld/%ld)\n", read_ret, sizeof(sem_counter));
#if defined(KERNEL_VERSION_PRE_2_6_30) #if defined(KERNEL_VERSION_PRE_2_6_30)
if (itti_dump_flush_ring_buffer(1) == 0) if (itti_dump_flush_ring_buffer(1) == 0)
#else #else
...@@ -645,7 +644,7 @@ static void *itti_dump_socket(void *arg_p) ...@@ -645,7 +644,7 @@ static void *itti_dump_socket(void *arg_p)
sem_counter = 1; sem_counter = 1;
/* Call to write for an event fd must be of 8 bytes */ /* Call to write for an event fd must be of 8 bytes */
write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter)); write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
DevCheck(write_ret == sizeof(sem_counter), write_ret, sem_counter, 0); AssertFatal (write_ret == sizeof(sem_counter), "Failed to write to dump event FD (%ld/%ld)\n", write_ret, sem_counter);
} }
#endif #endif
} }
...@@ -703,7 +702,7 @@ static void *itti_dump_socket(void *arg_p) ...@@ -703,7 +702,7 @@ static void *itti_dump_socket(void *arg_p)
/* In case we don't find the matching sd in list of known /* In case we don't find the matching sd in list of known
* connections -> assert. * connections -> assert.
*/ */
DevCheck(j < ITTI_DUMP_MAX_CON, j, ITTI_DUMP_MAX_CON, i); AssertFatal (j < ITTI_DUMP_MAX_CON, "Connection index not found (%d/%d) for socked %d\n", j, ITTI_DUMP_MAX_CON, i);
/* Re-initialize the socket to -1 so we can accept new /* Re-initialize the socket to -1 so we can accept new
* incoming connections. * incoming connections.
...@@ -744,8 +743,8 @@ int itti_dump_queue_message(task_id_t sender_task, ...@@ -744,8 +743,8 @@ int itti_dump_queue_message(task_id_t sender_task,
itti_dump_queue_item_t *new; itti_dump_queue_item_t *new;
size_t message_name_length; size_t message_name_length;
DevAssert(message_name != NULL); AssertFatal (message_name != NULL, "Message name is NULL\n");
DevAssert(message_p != NULL); AssertFatal (message_p != NULL, "Message is NULL\n");
#if defined(OAI_EMU) || defined(RTAI) #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); vcd_signal_dumper_dump_function_by_name(VCD_SIGNAL_DUMPER_FUNCTIONS_ITTI_DUMP_ENQUEUE_MESSAGE_MALLOC, VCD_FUNCTION_IN);
...@@ -768,8 +767,7 @@ int itti_dump_queue_message(task_id_t sender_task, ...@@ -768,8 +767,7 @@ int itti_dump_queue_message(task_id_t sender_task,
new->message_number = message_number; new->message_number = message_number;
message_name_length = strlen(message_name) + 1; message_name_length = strlen(message_name) + 1;
DevCheck(message_name_length <= SIGNAL_NAME_LENGTH, message_name_length, AssertError (message_name_length <= SIGNAL_NAME_LENGTH, "Message name too long (%ld/%d)\n", message_name_length, SIGNAL_NAME_LENGTH);
SIGNAL_NAME_LENGTH, 0);
memcpy(new->message_name, message_name, message_name_length); memcpy(new->message_name, message_name, message_name_length);
itti_dump_enqueue_message(new, message_size, ITTI_DUMP_MESSAGE_TYPE); itti_dump_enqueue_message(new, message_size, ITTI_DUMP_MESSAGE_TYPE);
...@@ -824,9 +822,8 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons ...@@ -824,9 +822,8 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
NULL, NULL,
NULL) != 1) NULL) != 1)
{ {
ITTI_DUMP_ERROR(" Failed to create ring buffer...\n");
/* Always assert on this condition */ /* Always assert on this condition */
DevAssert(0 == 1); AssertFatal (0, " Failed to create ring buffer...\n");
} }
#ifdef RTAI #ifdef RTAI
...@@ -837,11 +834,9 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons ...@@ -837,11 +834,9 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
# else # else
itti_dump_queue.event_fd = eventfd(0, EFD_SEMAPHORE); itti_dump_queue.event_fd = eventfd(0, EFD_SEMAPHORE);
# endif # endif
if (itti_dump_queue.event_fd == -1) if (itti_dump_queue.event_fd == -1) {
{
ITTI_DUMP_ERROR(" eventfd failed: %s\n", strerror(errno));
/* Always assert on this condition */ /* Always assert on this condition */
DevAssert(0 == 1); AssertFatal (0, "eventfd failed: %s\n", strerror(errno));
} }
#endif #endif
...@@ -855,26 +850,22 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons ...@@ -855,26 +850,22 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
/* initialized with default attributes */ /* initialized with default attributes */
ret = pthread_attr_init(&itti_dump_queue.attr); ret = pthread_attr_init(&itti_dump_queue.attr);
if (ret < 0) { if (ret < 0) {
ITTI_DUMP_ERROR(" pthread_attr_init failed (%d:%s)\n", errno, strerror(errno)); AssertFatal (0, "pthread_attr_init failed (%d:%s)\n", errno, strerror(errno));
DevAssert(0 == 1);
} }
ret = pthread_attr_setschedpolicy(&itti_dump_queue.attr, SCHED_FIFO); ret = pthread_attr_setschedpolicy(&itti_dump_queue.attr, SCHED_FIFO);
if (ret < 0) { if (ret < 0) {
ITTI_DUMP_ERROR(" pthread_attr_setschedpolicy (SCHED_IDLE) failed (%d:%s)\n", errno, strerror(errno)); AssertFatal (0, "pthread_attr_setschedpolicy (SCHED_IDLE) failed (%d:%s)\n", errno, strerror(errno));
DevAssert(0 == 1);
} }
ret = pthread_attr_setschedparam(&itti_dump_queue.attr, &scheduler_param); ret = pthread_attr_setschedparam(&itti_dump_queue.attr, &scheduler_param);
if (ret < 0) { if (ret < 0) {
ITTI_DUMP_ERROR(" pthread_attr_setschedparam failed (%d:%s)\n", errno, strerror(errno)); AssertFatal (0, "pthread_attr_setschedparam failed (%d:%s)\n", errno, strerror(errno));
DevAssert(0 == 1);
} }
ret = pthread_create(&itti_dump_queue.itti_acceptor_thread, &itti_dump_queue.attr, ret = pthread_create(&itti_dump_queue.itti_acceptor_thread, &itti_dump_queue.attr,
&itti_dump_socket, (void *)messages_definition_xml); &itti_dump_socket, (void *)messages_definition_xml);
if (ret < 0) { if (ret < 0) {
ITTI_DUMP_ERROR(" pthread_create failed (%d:%s)\n", errno, strerror(errno)); AssertFatal (0, "pthread_create failed (%d:%s)\n", errno, strerror(errno));
DevAssert(0 == 1);
} }
return 0; return 0;
......
...@@ -156,7 +156,7 @@ static inline items_group_index_t items_group_get_free_item (items_group_t *item ...@@ -156,7 +156,7 @@ static inline items_group_index_t items_group_get_free_item (items_group_t *item
/* Get index at current position */ /* Get index at current position */
index = items_group->indexes[current]; index = items_group->indexes[current];
DevCheck (index > ITEMS_GROUP_INDEX_INVALID, current, index, 0); AssertError (index > ITEMS_GROUP_INDEX_INVALID, "Index (%d) at current position (%d) is not valid!\n", current, index);
/* Clear index at current position */ /* Clear index at current position */
items_group->indexes[current] = ITEMS_GROUP_INDEX_INVALID; items_group->indexes[current] = ITEMS_GROUP_INDEX_INVALID;
...@@ -225,7 +225,7 @@ static inline void items_group_put_free_item (items_group_t *items_group, items_ ...@@ -225,7 +225,7 @@ static inline void items_group_put_free_item (items_group_t *items_group, items_
} }
} while (next != current); } while (next != current);
DevCheck (current < items_group->number, current, items_group->number, 0); AssertFatal (current < items_group->number, "Current position (%d) is above maximum position (%d)\n", current, items_group->number);
} }
/*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/
...@@ -236,7 +236,7 @@ static inline memory_pools_t *memory_pools_from_handler (memory_pools_handle_t m ...@@ -236,7 +236,7 @@ static inline memory_pools_t *memory_pools_from_handler (memory_pools_handle_t m
/* Recover memory_pools */ /* Recover memory_pools */
memory_pools = (memory_pools_t *) memory_pools_handle; memory_pools = (memory_pools_t *) memory_pools_handle;
/* Sanity check on passed handle */ /* Sanity check on passed handle */
DevAssert (memory_pools->start_mark == POOLS_START_MARK); AssertFatal (memory_pools->start_mark == POOLS_START_MARK, "Handle %p is not a valid memory pools handle, start mark is missing\n", memory_pools_handle);
return (memory_pools); return (memory_pools);
} }
...@@ -251,7 +251,7 @@ static inline memory_pool_item_t *memory_pool_item_from_handler (memory_pool_ite ...@@ -251,7 +251,7 @@ static inline memory_pool_item_t *memory_pool_item_from_handler (memory_pool_ite
memory_pool_item = (memory_pool_item_t *) address; memory_pool_item = (memory_pool_item_t *) address;
/* Sanity check on passed handle */ /* Sanity check on passed handle */
DevAssert (memory_pool_item->start.start_mark == POOL_ITEM_START_MARK); AssertFatal (memory_pool_item->start.start_mark == POOL_ITEM_START_MARK, "Handle %p is not a valid memory pool item handle, start mark is missing\n", memory_pool_item);
return (memory_pool_item); return (memory_pool_item);
} }
...@@ -272,11 +272,11 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number) ...@@ -272,11 +272,11 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number)
memory_pools_t *memory_pools; memory_pools_t *memory_pools;
pool_id_t pool; pool_id_t pool;
DevCheck (pools_number <= MAX_POOLS_NUMBER, pools_number, MAX_POOLS_NUMBER, 0); /* Limit to a reasonable number of pools */ AssertFatal (pools_number <= MAX_POOLS_NUMBER, "Too many memory pools requested (%d/%d)\n", pools_number, MAX_POOLS_NUMBER); /* Limit to a reasonable number of pools */
/* Allocate memory_pools */ /* Allocate memory_pools */
memory_pools = malloc (sizeof(memory_pools_t)); memory_pools = malloc (sizeof(memory_pools_t));
DevAssert (memory_pools != NULL); AssertFatal (memory_pools != NULL, "Memory pools structure allocation failed\n");
/* Initialize memory_pools */ /* Initialize memory_pools */
{ {
...@@ -286,7 +286,7 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number) ...@@ -286,7 +286,7 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number)
/* Allocate pools */ /* Allocate pools */
memory_pools->pools = calloc (pools_number, sizeof(memory_pool_t)); memory_pools->pools = calloc (pools_number, sizeof(memory_pool_t));
DevAssert (memory_pools->pools != NULL); AssertFatal (memory_pools->pools != NULL, "Memory pools allocation failed\n");
/* Initialize pools */ /* Initialize pools */
for (pool = 0; pool < pools_number; pool++) for (pool = 0; pool < pools_number; pool++)
...@@ -317,13 +317,13 @@ char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle) ...@@ -317,13 +317,13 @@ char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle)
{ {
allocated_pool_memory = memory_pools->pools[pool].items_group_free.number * memory_pools->pools[pool].pool_item_size; allocated_pool_memory = memory_pools->pools[pool].items_group_free.number * memory_pools->pools[pool].pool_item_size;
allocated_pools_memory += allocated_pool_memory; allocated_pools_memory += allocated_pool_memory;
printed_chars += sprintf (&statistics[printed_chars], " %2u: %6u, %6u, %6u, %6u, %6u Kbytes\n", printed_chars += sprintf (&statistics[printed_chars], " %2u: %6u, %6lu, %6u, %6u, %6u Kbytes\n",
pool, pool,
memory_pools->pools[pool].items_group_free.number, memory_pools->pools[pool].items_group_free.number,
memory_pools->pools[pool].item_data_number * sizeof(memory_pool_data_t), memory_pools->pools[pool].item_data_number * sizeof(memory_pool_data_t),
memory_pools->pools[pool].items_group_free.minimum + 1, memory_pools->pools[pool].items_group_free.minimum + 1,
memory_pools->pools[pool].items_group_free.current + 1, memory_pools->pools[pool].items_group_free.current + 1,
allocated_pool_memory / (1020)); allocated_pool_memory / (1024));
} }
printed_chars = sprintf (&statistics[printed_chars], "Pools memory %u Kbytes\n", allocated_pools_memory / (1024)); printed_chars = sprintf (&statistics[printed_chars], "Pools memory %u Kbytes\n", allocated_pools_memory / (1024));
...@@ -338,14 +338,14 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p ...@@ -338,14 +338,14 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
items_group_index_t item_index; items_group_index_t item_index;
memory_pool_item_t *memory_pool_item; memory_pool_item_t *memory_pool_item;
DevCheck (pool_items_number <= MAX_POOL_ITEMS_NUMBER, pool_items_number, MAX_POOL_ITEMS_NUMBER, 0); /* Limit to a reasonable number of items */ AssertFatal (pool_items_number <= MAX_POOL_ITEMS_NUMBER, "Too many items for a memory pool (%u/%d)\n", pool_items_number, MAX_POOL_ITEMS_NUMBER); /* Limit to a reasonable number of items */
DevCheck (pool_item_size <= MAX_POOL_ITEM_SIZE, pool_item_size, MAX_POOL_ITEM_SIZE, 0); /* Limit to a reasonable item size */ AssertFatal (pool_item_size <= MAX_POOL_ITEM_SIZE, "Item size is too big for memory pool items (%u/%d)\n", pool_item_size, MAX_POOL_ITEM_SIZE); /* Limit to a reasonable item size */
/* Recover memory_pools */ /* Recover memory_pools */
memory_pools = memory_pools_from_handler (memory_pools_handle); memory_pools = memory_pools_from_handler (memory_pools_handle);
/* Check number of already created pools */ /* Check number of already created pools */
DevAssert (memory_pools->pools_defined < memory_pools->pools_number); AssertFatal (memory_pools->pools_defined < memory_pools->pools_number, "Can not allocate more memory pool (%d)\n", memory_pools->pools_number);
/* Select pool */ /* Select pool */
pool = memory_pools->pools_defined; pool = memory_pools->pools_defined;
...@@ -363,7 +363,7 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p ...@@ -363,7 +363,7 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
/* Allocate free indexes */ /* Allocate free indexes */
memory_pool->items_group_free.indexes = malloc(pool_items_number * sizeof(items_group_index_t)); memory_pool->items_group_free.indexes = malloc(pool_items_number * sizeof(items_group_index_t));
DevAssert (memory_pool->items_group_free.indexes != NULL); AssertFatal (memory_pool->items_group_free.indexes != NULL, "Memory pool indexes allocation failed\n");
/* Initialize free indexes */ /* Initialize free indexes */
for (item_index = 0; item_index < pool_items_number; item_index++) for (item_index = 0; item_index < pool_items_number; item_index++)
...@@ -373,7 +373,7 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p ...@@ -373,7 +373,7 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p
/* Allocate items */ /* Allocate items */
memory_pool->items = calloc (pool_items_number, memory_pool->pool_item_size); memory_pool->items = calloc (pool_items_number, memory_pool->pool_item_size);
DevAssert (memory_pool->items != NULL); AssertFatal (memory_pool->items != NULL, "Memory pool items allocation failed\n");
/* Initialize items */ /* Initialize items */
for (item_index = 0; item_index < pool_items_number; item_index++) for (item_index = 0; item_index < pool_items_number; item_index++)
...@@ -428,7 +428,8 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po ...@@ -428,7 +428,8 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po
/* Convert item index into memory_pool_item address */ /* Convert item index into memory_pool_item address */
memory_pool_item = memory_pool_item_from_index (&memory_pools->pools[pool], item_index); memory_pool_item = memory_pool_item_from_index (&memory_pools->pools[pool], item_index);
/* Sanity check on item status, must be free */ /* Sanity check on item status, must be free */
DevCheck (memory_pool_item->start.item_status == ITEM_STATUS_FREE, memory_pool_item->start.item_status, pool, item_index); AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_FREE, "Item status is not set to free (%d) in pool %u, item %d\n",
memory_pool_item->start.item_status, pool, item_index);
memory_pool_item->start.item_status = ITEM_STATUS_ALLOCATED; memory_pool_item->start.item_status = ITEM_STATUS_ALLOCATED;
memory_pool_item->start.info[0] = info_0; memory_pool_item->start.info[0] = info_0;
...@@ -467,25 +468,26 @@ void memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_i ...@@ -467,25 +468,26 @@ void memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_i
memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle); memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle);
/* Recover pool index */ /* Recover pool index */
pool = memory_pool_item->start.pool_id; pool = memory_pool_item->start.pool_id;
DevCheck (pool < memory_pools->pools_defined, pool, memory_pools->pools_defined, 0); AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)\n", pool, memory_pools->pools_defined);
item_size = memory_pools->pools[pool].item_data_number; item_size = memory_pools->pools[pool].item_data_number;
pool_item_size = memory_pools->pools[pool].pool_item_size; pool_item_size = memory_pools->pools[pool].pool_item_size;
item_index = (((void *) memory_pool_item) - ((void *) memory_pools->pools[pool].items)) / pool_item_size; item_index = (((void *) memory_pool_item) - ((void *) memory_pools->pools[pool].items)) / pool_item_size;
MP_DEBUG(" Free [%2u][%6d]{%6d}, %3u %3u, %p, %p, %p, %u\n", MP_DEBUG(" Free [%2u][%6d]{%6d}, %3u %3u, %p, %p, %p, %lu\n",
pool, item_index, memory_pools->pools[pool].items_group_free.current, pool, item_index, memory_pools->pools[pool].items_group_free.current,
memory_pool_item->start.info[0], memory_pool_item->start.info[1], memory_pool_item->start.info[0], memory_pool_item->start.info[1],
memory_pool_item_handle, memory_pool_item, memory_pool_item_handle, memory_pool_item,
memory_pools->pools[pool].items, item_size * sizeof(memory_pool_data_t)); memory_pools->pools[pool].items, item_size * sizeof(memory_pool_data_t));
/* Sanity check on calculated item index */ /* Sanity check on calculated item index */
DevCheck (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index), memory_pool_item, AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index), "Incorrect memory pool item address (%p, %p) for pool %u, item %d\n",
memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool); memory_pool_item, memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index);
/* Sanity check on end marker, must still be present (no write overflow) */ /* Sanity check on end marker, must still be present (no write overflow) */
DevCheck (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK, pool, 0, 0); AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK, "Memory pool item is corrupted, end mark is not present for pool %u, item %d\n", pool, item_index);
/* Sanity check on item status, must be allocated */ /* Sanity check on item status, must be allocated */
DevCheck (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED, memory_pool_item->start.item_status, pool, item_index); AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED, "Trying to free a non allocated (%x) memory pool item (pool %u, item %d)\n",
memory_pool_item->start.item_status, pool, item_index);
memory_pool_item->start.item_status = ITEM_STATUS_FREE; memory_pool_item->start.item_status = ITEM_STATUS_FREE;
......
...@@ -147,7 +147,7 @@ int timer_setup( ...@@ -147,7 +147,7 @@ int timer_setup(
if (timer_id == NULL) { if (timer_id == NULL) {
return -1; return -1;
} }
DevAssert(type < TIMER_TYPE_MAX); AssertFatal (type < TIMER_TYPE_MAX, "Invalid timer type (%d/%d)\n", type, TIMER_TYPE_MAX);
/* Allocate new timer list element */ /* Allocate new timer list element */
timer_p = malloc(sizeof(struct timer_elm_s)); timer_p = malloc(sizeof(struct timer_elm_s));
......
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