Commit 6e209dcd authored by Cedric Roux's avatar Cedric Roux

- Fix EFD_SEMAPHORE missing for kernel version < 2.6.30

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4641 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 218b9162
...@@ -83,6 +83,10 @@ const int itti_debug_poll = 0; ...@@ -83,6 +83,10 @@ const int itti_debug_poll = 0;
/* Global message size */ /* Global message size */
#define MESSAGE_SIZE(mESSAGEiD) (sizeof(MessageHeader) + itti_desc.messages_info[mESSAGEiD].size) #define MESSAGE_SIZE(mESSAGEiD) (sizeof(MessageHeader) + itti_desc.messages_info[mESSAGEiD].size)
#if !defined(EFD_SEMAPHORE)
# define KERNEL_VERSION_PRE_2_6_30 1
#endif
typedef enum task_state_s { typedef enum task_state_s {
TASK_STATE_NOT_CONFIGURED, TASK_STATE_STARTING, TASK_STATE_READY, TASK_STATE_ENDED, TASK_STATE_MAX, TASK_STATE_NOT_CONFIGURED, TASK_STATE_STARTING, TASK_STATE_READY, TASK_STATE_ENDED, TASK_STATE_MAX,
} task_state_t; } task_state_t;
...@@ -111,6 +115,10 @@ typedef struct thread_desc_s { ...@@ -111,6 +115,10 @@ typedef struct thread_desc_s {
/* Number of events to monitor */ /* Number of events to monitor */
uint16_t nb_events; uint16_t nb_events;
#if defined(KERNEL_VERSION_PRE_2_6_30)
uint64_t sem_counter;
#endif
/* Array of events monitored by the task. /* Array of events monitored by the task.
* By default only one fd is monitored (the one used to received messages * By default only one fd is monitored (the one used to received messages
* from other tasks). * from other tasks).
...@@ -136,7 +144,7 @@ typedef struct task_desc_s { ...@@ -136,7 +144,7 @@ typedef struct task_desc_s {
typedef struct itti_desc_s { typedef struct itti_desc_s {
thread_desc_t *threads; thread_desc_t *threads;
task_desc_t *tasks; task_desc_t *tasks;
/* Current message number. Incremented every call to send_msg_to_task */ /* Current message number. Incremented every call to send_msg_to_task */
message_number_t message_number __attribute__((aligned(8))); message_number_t message_number __attribute__((aligned(8)));
...@@ -525,7 +533,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t ...@@ -525,7 +533,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
if ((itti_desc.threads[thread_id].events[i].events & EPOLLIN) && if ((itti_desc.threads[thread_id].events[i].events & EPOLLIN) &&
(itti_desc.threads[thread_id].events[i].data.fd == itti_desc.threads[thread_id].task_event_fd)) (itti_desc.threads[thread_id].events[i].data.fd == itti_desc.threads[thread_id].task_event_fd))
{ {
struct message_list_s *message; struct message_list_s *message = NULL;
uint64_t sem_counter; uint64_t sem_counter;
ssize_t read_ret; ssize_t read_ret;
...@@ -533,10 +541,16 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t ...@@ -533,10 +541,16 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
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); DevCheck(read_ret == sizeof(sem_counter), read_ret, sizeof(sem_counter), 0);
#if defined(KERNEL_VERSION_PRE_2_6_30)
/* Store the value of the semaphore counter */
itti_desc.tasks[task_id].sem_counter = sem_counter - 1;
#endif
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); DevParam(task_id, epoll_ret, 0);
} }
DevAssert(message != NULL);
*received_msg = message->msg; *received_msg = message->msg;
free (message); free (message);
return; return;
...@@ -550,6 +564,21 @@ void itti_receive_msg(task_id_t task_id, MessageDef **received_msg) ...@@ -550,6 +564,21 @@ void itti_receive_msg(task_id_t task_id, MessageDef **received_msg)
vcd_signal_dumper_dump_variable_by_name(VCD_SIGNAL_DUMPER_VARIABLE_ITTI_RECV_MSG, 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))); __sync_and_and_fetch (&itti_desc.vcd_receive_msg, ~(1L << task_id)));
#endif #endif
#if defined(KERNEL_VERSION_PRE_2_6_30)
/* Store the value of the semaphore counter */
if (itti_desc.tasks[task_id].sem_counter > 0) {
if (lfds611_queue_dequeue (itti_desc.tasks[task_id].message_queue, (void **) &message) == 0) {
/* No element in list -> this should not happen */
DevParam(task_id, itti_desc.tasks[task_id].sem_counter, 0);
}
DevAssert(message != NULL);
*received_msg = message->msg;
free (message);
itti_desc.tasks[task_id].sem_counter--;
} else
#endif
itti_receive_msg_internal_event_fd(task_id, 0, received_msg); itti_receive_msg_internal_event_fd(task_id, 0, received_msg);
#if defined(OAI_EMU) || defined(RTAI) #if defined(OAI_EMU) || defined(RTAI)
...@@ -769,7 +798,14 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i ...@@ -769,7 +798,14 @@ int itti_init(task_id_t task_max, thread_id_t thread_max, MessagesIds messages_i
DevAssert(0 == 1); DevAssert(0 == 1);
} }
# if defined(KERNEL_VERSION_PRE_2_6_30)
/* SR: for kernel versions < 2.6.30 EFD_SEMAPHORE is not defined.
* A read operation on the event fd will return the 8 byte value.
*/
itti_desc.threads[thread_id].task_event_fd = eventfd(0, 0);
# else
itti_desc.threads[thread_id].task_event_fd = eventfd(0, EFD_SEMAPHORE); itti_desc.threads[thread_id].task_event_fd = eventfd(0, EFD_SEMAPHORE);
# 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)); ITTI_ERROR("eventfd failed: %s\n", strerror(errno));
......
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