rt_benchs/communication_techniques/include/csq_common_comm.h

53 lines
1.1 KiB
C

#ifndef _CSQ_COMMON_COMM_H_
#define _CSQ_COMMON_COMM_H_ 1
/* Non standard include */
#include <commtech.h>
#ifndef BUF_SIZE
#define BUF_SIZE CACHE_LINE_SIZE
#endif
#ifndef SLOTS
#define SLOTS 64 /* Value used in the article, section V.A */
#endif
#define SUB_SLOTS (BUF_SIZE / sizeof(void *))
struct lvl_2
{
void * volatile chunk[SUB_SLOTS];
volatile unsigned int flag : 1;
} __attribute__ ((aligned (CACHE_LINE_SIZE)));
struct channel
{
struct lvl_2 queue[SLOTS] __attribute__ ((aligned (CACHE_LINE_SIZE)));
int head __attribute__ ((aligned(CACHE_LINE_SIZE)));
int tail __attribute__ ((aligned(CACHE_LINE_SIZE)));
};
__BEGIN_DECLS
// TODO: Make it send only one data
static inline void send(struct channel *channel, void **addr)
{
static __thread int chkidx = 0;
// If all slots are full, spin
if (!chkidx)
while (channel->queue[channel->tail].flag);
// Enqueue a data item
channel->queue[channel->tail].chunk[chkidx++] = addr;
if (!(chkidx % SUB_SLOTS))
{
chkidx = 0;
channel->queue[channel->tail].flag = 1;
channel->tail = (channel->tail + 1) % SLOTS;
}
}
__END_DECLS
#endif