rt_benchs/communication_techniques/include/csq_comm.h

54 lines
1013 B
C

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