communication technique benchs: We send addresses

* uintptr_t -> void *
* main send addresses where it has written something in
This commit is contained in:
Thomas Preud'homme 2009-06-16 12:58:30 +02:00 committed by Thomas Preud'homme
parent 12494e2fbc
commit 09bff9869e
10 changed files with 42 additions and 41 deletions

View File

@ -12,7 +12,7 @@
struct communication_channel
{
uintptr_t buf[2 * BUF_SIZE / sizeof(uintptr_t)] __attribute__ ((aligned (CACHE_LINE_SIZE)));
void *buf[2 * BUF_SIZE / sizeof(void *)] __attribute__ ((aligned (CACHE_LINE_SIZE)));
int state __attribute__ ((aligned (CACHE_LINE_SIZE)));
int idx __attribute__ ((aligned (CACHE_LINE_SIZE)));
};
@ -31,7 +31,7 @@ extern struct communication_assoc assoc_root;
__BEGIN_DECLS
struct communication_assoc *create_comm_assoc(void);
static inline void send(uintptr_t value) {
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"
@ -42,7 +42,7 @@ static inline void send(uintptr_t value) {
"jz swap_buffer\n\t"
"2:"
:
: "r"(value)
: "r"(addr)
: "%eax");
}

View File

@ -16,7 +16,7 @@ __BEGIN_DECLS
void add_sender(void);
void remove_sender(void);
volatile int *init_comm(void);
void reception(void (*)(uintptr_t));
void reception(void (*)(void *));
extern int swap_buffer;
void wait_initialization(void);
void discover_new_producers(void);

View File

@ -26,8 +26,8 @@ extern __thread int pipefd[];
extern struct communication_assoc assoc_root;
struct communication_assoc *create_comm_assoc(void);
static inline void send(uintptr_t value) {
write(pipefd[WRITE_IDX], &value, sizeof(uintptr_t));
static inline void send(void *addr) {
write(pipefd[WRITE_IDX], &addr, sizeof(void *));
}
__END_DECLS

View File

@ -7,14 +7,14 @@
#include <common_comm.h>
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
#define SHARED_SPACE_UINTPTR (SHARED_SPACE_SIZE / sizeof(uintptr_t))
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
struct communication_assoc
{
struct communication_assoc *next;
struct communication_assoc *prev;
pthread_t tid;
uintptr_t *shared_space;
void **shared_space;
volatile int *cons_idx;
volatile int *prod_idx;
};
@ -23,15 +23,15 @@ extern struct communication_assoc assoc_root;
__BEGIN_DECLS
extern __thread uintptr_t *shared_space;
extern __thread void **shared_space;
extern __thread volatile int prod_idx;
extern __thread volatile int cons_idx;
struct communication_assoc *create_comm_assoc(void);
static inline void send(uintptr_t value) {
while ((prod_idx + 1) % SHARED_SPACE_UINTPTR == cons_idx);
shared_space[prod_idx] = value;
prod_idx = (prod_idx + 1) % SHARED_SPACE_UINTPTR;
static inline void send(void *addr) {
while ((prod_idx + 1) % SHARED_SPACE_VOIDPTR == cons_idx);
shared_space[prod_idx] = addr;
prod_idx = (prod_idx + 1) % SHARED_SPACE_VOIDPTR;
}
__END_DECLS

View File

@ -7,14 +7,14 @@
#include <common_comm.h>
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
#define SHARED_SPACE_UINTPTR (SHARED_SPACE_SIZE / sizeof(uintptr_t))
#define SHARED_SPACE_VOIDPTR (SHARED_SPACE_SIZE / sizeof(void *))
struct communication_assoc
{
struct communication_assoc *next;
struct communication_assoc *prev;
pthread_t tid;
uintptr_t *shared_space;
void **shared_space;
volatile int *cons_idx;
volatile int *prod_idx;
};
@ -23,21 +23,21 @@ extern struct communication_assoc assoc_root;
__BEGIN_DECLS
extern __thread uintptr_t *shared_space;
extern __thread void **shared_space;
extern __thread volatile int prod_idx;
extern __thread volatile int cons_idx;
struct communication_assoc *create_comm_assoc(void);
static inline void send(uintptr_t value) {
static inline void send(void *addr) {
static __thread int local_cons_idx = 0;
if (likely(((prod_idx + 1) % SHARED_SPACE_UINTPTR) == local_cons_idx))
if (likely(((prod_idx + 1) % SHARED_SPACE_VOIDPTR) == local_cons_idx))
{
while (((prod_idx + 1) % SHARED_SPACE_UINTPTR) == cons_idx);
while (((prod_idx + 1) % SHARED_SPACE_VOIDPTR) == cons_idx);
local_cons_idx = cons_idx;
}
shared_space[prod_idx] = value;
prod_idx = (prod_idx + 1) % SHARED_SPACE_UINTPTR;
shared_space[prod_idx] = addr;
prod_idx = (prod_idx + 1) % SHARED_SPACE_VOIDPTR;
}
__END_DECLS

View File

@ -35,7 +35,7 @@ void _swap_buffer()
: : "m"(dstr));
}
void reception(void (*on_receive)(uintptr_t))
void reception(void (*on_receive)(void *))
{
wait_initialization();
/* printf("Activate the consumer...\n"); */
@ -60,8 +60,8 @@ void reception(void (*on_receive)(uintptr_t))
* the first one (this is done by the modulo)
*/
int i = cur->receiver_idx;
int n = cur->receiver_idx + (BUF_SIZE / sizeof(uintptr_t));
cur->receiver_idx = n % ((2 * BUF_SIZE) / sizeof(uintptr_t));
int n = cur->receiver_idx + (BUF_SIZE / sizeof(void *));
cur->receiver_idx = n % ((2 * BUF_SIZE) / sizeof(void *));
for(; i<n; i++)
on_receive(channel->buf[i]);
channel->state = 0;

View File

@ -147,7 +147,8 @@ int analyse_options(int argc, char *argv[])
void *producer(void *cont_ptr_void)
{
int i, j, k;
int i, j;
uintptr_t k;
volatile int *cont;
cont = *((volatile int **) cont_ptr_void);
@ -173,7 +174,7 @@ void *producer(void *cont_ptr_void)
for(i = 0; i < nb_cache_lines; i++) {
//printf("[%p] Send a new CACHE_LINE\n", (void *) pthread_self());
for(j = 0; j < (CACHE_LINE_SIZE / sizeof(uintptr_t)); j++)
send(k++);
send(&k);
}
print_results();
}
@ -192,7 +193,7 @@ void *producer(void *cont_ptr_void)
return NULL;
}
void onMessage(uintptr_t val)
void onMessage(void *val)
{
//printf("Receive value: %p\n", (void *) val);
}

View File

@ -21,7 +21,7 @@ struct communication_assoc *create_comm_assoc(void)
return assoc;
}
void reception(void (*on_receive)(uintptr_t))
void reception(void (*on_receive)(void *))
{
wait_initialization();
/* printf("Activate the consumer...\n"); */
@ -35,10 +35,10 @@ void reception(void (*on_receive)(uintptr_t))
{
int i;
for(i = 0; i < BUF_SIZE / sizeof(uintptr_t); i++)
for(i = 0; i < BUF_SIZE / sizeof(void *); i++)
{
uintptr_t tmp;
read(cur->pipefd[READ_IDX], &tmp, sizeof(uintptr_t));
void *tmp;
read(cur->pipefd[READ_IDX], &tmp, sizeof(void *));
on_receive(tmp);
}
cur = cur->next;

View File

@ -8,7 +8,7 @@
#include <specific_comm.h>
__thread uintptr_t *shared_space;
__thread void **shared_space;
__thread volatile int cons_idx = 0;
__thread volatile int prod_idx = 0;
@ -16,7 +16,7 @@ struct communication_assoc *create_comm_assoc(void)
{
struct communication_assoc *assoc;
shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE);
shared_space = (void **) malloc(SHARED_SPACE_SIZE);
assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc));
assoc->tid = pthread_self();
assoc->shared_space = shared_space;
@ -25,7 +25,7 @@ struct communication_assoc *create_comm_assoc(void)
return assoc;
}
void reception(void (*on_receive)(uintptr_t))
void reception(void (*on_receive)(void *))
{
wait_initialization();
/* printf("Activate the consumer...\n"); */
@ -39,9 +39,9 @@ void reception(void (*on_receive)(uintptr_t))
{
int cons_idx;
for(cons_idx = *cur->cons_idx; cons_idx != *cur->prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_UINTPTR, *cur->cons_idx = cons_idx)
for(cons_idx = *cur->cons_idx; cons_idx != *cur->prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_VOIDPTR, *cur->cons_idx = cons_idx)
{
uintptr_t tmp;
void *tmp;
tmp = cur->shared_space[cons_idx];
on_receive(tmp);
}

View File

@ -8,7 +8,7 @@
#include <specific_comm.h>
__thread uintptr_t *shared_space;
__thread void **shared_space;
__thread volatile int cons_idx = 0;
__thread volatile int prod_idx = 0;
@ -16,7 +16,7 @@ struct communication_assoc *create_comm_assoc(void)
{
struct communication_assoc *assoc;
shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE);
shared_space = (void **) malloc(SHARED_SPACE_SIZE);
assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc));
assoc->tid = pthread_self();
assoc->shared_space = shared_space;
@ -25,7 +25,7 @@ struct communication_assoc *create_comm_assoc(void)
return assoc;
}
void reception(void (*on_receive)(uintptr_t))
void reception(void (*on_receive)(void *))
{
wait_initialization();
/* printf("Activate the consumer...\n"); */
@ -43,9 +43,9 @@ void reception(void (*on_receive)(uintptr_t))
do
{
prod_idx = *cur->prod_idx;
for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_UINTPTR)
for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_VOIDPTR)
{
uintptr_t tmp;
void *tmp;
tmp = cur->shared_space[cons_idx];
on_receive(tmp);
}