|
|
@ -24,29 +24,38 @@ struct channel |
|
|
|
void * volatile *receiver_ptr __attribute__ ((aligned (CACHE_LINE_SIZE))); |
|
|
|
}; |
|
|
|
|
|
|
|
void send1(struct channel *channel, void **addr) |
|
|
|
__attribute__ ((visibility ("hidden"))); |
|
|
|
void send2(struct channel *channel, void **addr) |
|
|
|
__attribute__ ((visibility ("hidden"))); |
|
|
|
|
|
|
|
#ifndef _BATCH_QUEUE_C_ |
|
|
|
#ifndef PAGE_SIZE_HELPER |
|
|
|
#define PAGE_SIZE_HELPER 1 |
|
|
|
uintptr_t _bq_page_mask; |
|
|
|
void * volatile *_bq_end_buf1; |
|
|
|
void * volatile *_bq_end_buf2; |
|
|
|
void (*send_ptr)(struct channel *, void **); |
|
|
|
|
|
|
|
void *create_comm_channel_internal(void); |
|
|
|
static void *create_comm_channel_helper(void) __attribute__ ((unused)); |
|
|
|
|
|
|
|
static void *create_comm_channel_helper(void) |
|
|
|
{ |
|
|
|
int ret; |
|
|
|
struct channel *channel; |
|
|
|
|
|
|
|
ret = sysconf(_SC_PAGESIZE); |
|
|
|
if (ret == -1) |
|
|
|
return NULL; |
|
|
|
_bq_page_mask = ~(ret - 1); |
|
|
|
send_ptr = &send1; |
|
|
|
channel = create_comm_channel_internal(); |
|
|
|
channel->buf_mask = sizeof channel->buf[0] - 1; |
|
|
|
_bq_end_buf1 = channel->buf[0] + |
|
|
|
(sizeof channel->buf[0] / sizeof channel->buf[0][0]); |
|
|
|
_bq_end_buf2 = channel->mapping2->buf[1] + |
|
|
|
(sizeof channel->buf[1] / sizeof channel->buf[1][0]); |
|
|
|
return channel; |
|
|
|
} |
|
|
|
|
|
|
|
#else |
|
|
|
extern unsigned int _bq_page_mask; |
|
|
|
extern uintptr_t _bq_end_buf1; |
|
|
|
extern uintptr_t _bq_end_buf2; |
|
|
|
extern void (*send_ptr)(struct channel *, void **); |
|
|
|
#endif /* PAGE_SIZE_HELPER */ |
|
|
|
|
|
|
|
#define create_comm_channel() create_comm_channel_helper() |
|
|
@ -55,19 +64,30 @@ __BEGIN_DECLS |
|
|
|
|
|
|
|
static inline void send(struct channel *channel, void **addr) |
|
|
|
{ |
|
|
|
uintptr_t sender_ptr_high; |
|
|
|
(*send_ptr)(channel, addr); |
|
|
|
} |
|
|
|
|
|
|
|
void send1(struct channel *channel, void **addr) |
|
|
|
{ |
|
|
|
*channel->sender_ptr++ = addr; |
|
|
|
if (unlikely(channel->sender_ptr == _bq_end_buf1)) |
|
|
|
{ |
|
|
|
while (channel->state); |
|
|
|
channel->state = 1; |
|
|
|
channel->sender_ptr = channel->mapping2->buf[1]; |
|
|
|
send_ptr = &send2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void send2(struct channel *channel, void **addr) |
|
|
|
{ |
|
|
|
*channel->sender_ptr++ = addr; |
|
|
|
if (unlikely(!((uintptr_t) channel->sender_ptr & channel->buf_mask))) |
|
|
|
if (unlikely(channel->sender_ptr == _bq_end_buf2)) |
|
|
|
{ |
|
|
|
while (channel->state); |
|
|
|
channel->state = 1; |
|
|
|
sender_ptr_high = |
|
|
|
(uintptr_t) channel->sender_ptr & _bq_page_mask; |
|
|
|
if ((void *) sender_ptr_high == channel->mapping1) |
|
|
|
channel->sender_ptr = channel->mapping2->buf[1]; |
|
|
|
else |
|
|
|
channel->sender_ptr = channel->mapping1->buf[0]; |
|
|
|
channel->sender_ptr = channel->buf[0]; |
|
|
|
send_ptr = &send1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|