rt_benchs/communication_techniques/include/csq_common_comm.h

53 lines
1.1 KiB
C
Raw Permalink Normal View History

#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>
#ifndef BUF_SIZE
#define BUF_SIZE CACHE_LINE_SIZE
#endif
#ifndef SLOTS
2010-09-22 18:15:57 +02:00
#define SLOTS 64 /* Value used in the article, section V.A */
#endif
2010-09-22 18:15:57 +02:00
#define SUB_SLOTS (BUF_SIZE / sizeof(void *))
struct lvl_2
{
void * volatile chunk[SUB_SLOTS];
2010-09-22 18:15:57 +02:00
volatile unsigned int flag : 1;
} __attribute__ ((aligned (CACHE_LINE_SIZE)));
struct channel
2010-09-22 18:15:57 +02:00
{
struct lvl_2 queue[SLOTS] __attribute__ ((aligned (CACHE_LINE_SIZE)));
2011-05-10 13:43:55 +02:00
unsigned int head __attribute__ ((aligned(CACHE_LINE_SIZE)));
unsigned int tail __attribute__ ((aligned(CACHE_LINE_SIZE)));
2010-09-22 18:15:57 +02:00
};
__BEGIN_DECLS
// TODO: Make it send only one data
static inline void send(struct channel *channel, void **addr)
2010-09-22 18:15:57 +02:00
{
2011-05-10 13:43:55 +02:00
static __thread unsigned int chkidx = 0;
2010-09-22 18:15:57 +02:00
// If all slots are full, spin
if (!chkidx)
while (channel->queue[channel->tail].flag);
2010-09-22 18:15:57 +02:00
// Enqueue a data item
channel->queue[channel->tail].chunk[chkidx++] = addr;
2010-09-22 18:15:57 +02:00
if (!(chkidx % SUB_SLOTS))
{
chkidx = 0;
channel->queue[channel->tail].flag = 1;
channel->tail = (channel->tail + 1) % SLOTS;
2010-09-22 18:15:57 +02:00
}
}
__END_DECLS
#endif