rt_benchs/communication_techniques/include/fast_forward_comm.h

53 lines
1.1 KiB
C
Raw Normal View History

2010-09-22 18:15:57 +02:00
#ifndef _SPECIFIC_COMM_H_
#define _SPECIFIC_COMM_H_ 1
/* Non standard include */
#include <commtech.h>
#include <assert.h>
#define SHARED_SPACE_SIZE (16 * BUF_SIZE)
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
#ifndef BUF_SIZE
#define BUF_SIZE CACHE_LINE_SIZE
#endif
2010-09-22 18:15:57 +02:00
#define DANGER (2 * BUF_SIZE / sizeof(void *))
#define GOOD (6 * BUF_SIZE / sizeof(void *))
#define ADJUST_FREQ 64
struct channel
2010-09-22 18:15:57 +02:00
{
void * volatile *shared_space;
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
extern int adjust_slip(struct channel *channel);
2010-09-22 18:15:57 +02:00
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 nb_iter = 0;
2010-09-22 18:15:57 +02:00
assert(addr != NULL);
if (nb_iter == ADJUST_FREQ)
{
adjust_slip(channel);
2010-09-22 18:15:57 +02:00
nb_iter = 0;
}
while (1)
{
if (channel->shared_space[channel->head] != NULL)
2010-09-22 18:15:57 +02:00
continue;
channel->shared_space[channel->head] = addr;
channel->head = (channel->head + 1) % SHARED_SPACE_VOIDPTR;
2010-09-22 18:15:57 +02:00
break;
}
}
__END_DECLS
#endif