51 lines
1.3 KiB
C
51 lines
1.3 KiB
C
#ifndef _SPECIFIC_COMM_H_
|
|
#define _SPECIFIC_COMM_H_ 1
|
|
|
|
/* Non standard include */
|
|
#include <commtech.h>
|
|
|
|
/* This is not an error, we need this two-macro system */
|
|
#define toString(x) doStringification(x)
|
|
#define doStringification(x) #x
|
|
|
|
__BEGIN_DECLS
|
|
|
|
struct comm_channel
|
|
{
|
|
volatile void *buf[2 * BUF_SIZE / sizeof(void *)] __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
volatile int state __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
int idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
|
|
};
|
|
|
|
struct thread_comm
|
|
{
|
|
struct comm_channel *channel;
|
|
int receiver_idx;
|
|
int unused;
|
|
};
|
|
|
|
extern struct thread_comm *tcomms;
|
|
extern int swap_buffer;
|
|
|
|
int init_thread_comm(struct thread_comm *);
|
|
int end_thread_comm(void);
|
|
static inline void send(void **addr)
|
|
{
|
|
asm volatile("mov %%gs:channel@NTPOFF + 2 *" toString(BUF_SIZE) " + " toString(CACHE_LINE_SIZE) ", %%eax\n\t"
|
|
"mov %0, %%gs:channel@NTPOFF(%%eax)\n\t"
|
|
"addl $4, %%eax\n\t"
|
|
"andl $(2*" toString(BUF_SIZE) "-1), %%eax\n\t"
|
|
"mov %%eax, %%gs:channel@NTPOFF + 2 * " toString(BUF_SIZE)" + " toString(CACHE_LINE_SIZE) "\n\t"
|
|
"test $(" toString(BUF_SIZE) " - 1), %%eax\n\t"
|
|
"mov $2f, %%eax\n\t"
|
|
"jz swap_buffer\n\t"
|
|
"2:"
|
|
:
|
|
: "r"(addr)
|
|
: "%eax");
|
|
}
|
|
|
|
__END_DECLS
|
|
|
|
#endif
|