70 lines
1.4 KiB
C
70 lines
1.4 KiB
C
#ifndef _SPECIFIC_COMM_H_
|
|
#define _SPECIFIC_COMM_H_ 1
|
|
|
|
/* Non standard include */
|
|
#include <commtech.h>
|
|
|
|
#define SHARED_SPACE_SIZE (250 * CACHE_LINE_SIZE) // Check with batchSize
|
|
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
|
|
|
|
struct control
|
|
{
|
|
volatile int read;
|
|
volatile int write;
|
|
};
|
|
|
|
struct cons
|
|
{
|
|
int localWrite;
|
|
int nextRead;
|
|
int rBatch;
|
|
};
|
|
|
|
struct prod
|
|
{
|
|
int localRead;
|
|
int nextWrite;
|
|
int wBatch;
|
|
};
|
|
|
|
|
|
struct comm
|
|
{
|
|
struct control ctrl __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
struct prod prod __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
struct cons cons __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
void * volatile *shared_space __attribute__ ((aligned (CACHE_LINE_SIZE))); // Align only to isolate cons on its cache line
|
|
};
|
|
|
|
__BEGIN_DECLS
|
|
|
|
extern __thread struct comm *comm;
|
|
extern const int batchSize;
|
|
|
|
static inline void send(void **addr)
|
|
{
|
|
while (1)
|
|
{
|
|
int afterNextWrite = (comm->prod.nextWrite + 1) % SHARED_SPACE_VOIDPTR;
|
|
if (afterNextWrite == comm->prod.localRead)
|
|
{
|
|
if (afterNextWrite == comm->ctrl.read)
|
|
continue;
|
|
comm->prod.localRead = comm->ctrl.read;
|
|
}
|
|
comm->shared_space[comm->prod.nextWrite] = addr;
|
|
comm->prod.nextWrite = afterNextWrite;
|
|
comm->prod.wBatch++;
|
|
if (comm->prod.wBatch >= batchSize)
|
|
{
|
|
comm->ctrl.write = comm->prod.nextWrite;
|
|
comm->prod.wBatch = 0;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
__END_DECLS
|
|
|
|
#endif
|