2011-01-25 17:09:26 +01:00
|
|
|
#ifndef _CSQ_COMMON_COMM_H_
|
|
|
|
#define _CSQ_COMMON_COMM_H_ 1
|
2010-09-22 18:15:57 +02:00
|
|
|
|
|
|
|
/* Non standard include */
|
|
|
|
#include <commtech.h>
|
|
|
|
|
2011-03-02 12:20:47 +01:00
|
|
|
#ifndef BUF_SIZE
|
|
|
|
#define BUF_SIZE CACHE_LINE_SIZE
|
|
|
|
#endif
|
|
|
|
|
2011-01-25 17:09:26 +01:00
|
|
|
#ifndef SLOTS
|
2010-09-22 18:15:57 +02:00
|
|
|
#define SLOTS 64 /* Value used in the article, section V.A */
|
2011-01-25 17:09:26 +01:00
|
|
|
#endif
|
2010-09-22 18:15:57 +02:00
|
|
|
#define SUB_SLOTS (BUF_SIZE / sizeof(void *))
|
|
|
|
|
|
|
|
struct lvl_2
|
|
|
|
{
|
2011-01-13 14:58:13 +01:00
|
|
|
void * volatile chunk[SUB_SLOTS];
|
2010-09-22 18:15:57 +02:00
|
|
|
volatile unsigned int flag : 1;
|
|
|
|
} __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
|
|
|
2011-04-11 16:18:49 +02:00
|
|
|
struct channel
|
2010-09-22 18:15:57 +02:00
|
|
|
{
|
|
|
|
struct lvl_2 queue[SLOTS] __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
2011-04-11 16:18:49 +02:00
|
|
|
int head __attribute__ ((aligned(CACHE_LINE_SIZE)));
|
|
|
|
int tail __attribute__ ((aligned(CACHE_LINE_SIZE)));
|
2010-09-22 18:15:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
// TODO: Make it send only one data
|
2011-04-11 16:18:49 +02:00
|
|
|
static inline void send(struct channel *channel, void **addr)
|
2010-09-22 18:15:57 +02:00
|
|
|
{
|
|
|
|
static __thread int chkidx = 0;
|
|
|
|
|
|
|
|
// If all slots are full, spin
|
|
|
|
if (!chkidx)
|
2011-04-11 16:18:49 +02:00
|
|
|
while (channel->queue[channel->tail].flag);
|
2010-09-22 18:15:57 +02:00
|
|
|
|
|
|
|
// Enqueue a data item
|
2011-04-11 16:18:49 +02:00
|
|
|
channel->queue[channel->tail].chunk[chkidx++] = addr;
|
2010-09-22 18:15:57 +02:00
|
|
|
if (!(chkidx % SUB_SLOTS))
|
|
|
|
{
|
|
|
|
chkidx = 0;
|
2011-04-11 16:18:49 +02:00
|
|
|
channel->queue[channel->tail].flag = 1;
|
|
|
|
channel->tail = (channel->tail + 1) % SLOTS;
|
2010-09-22 18:15:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|