diff --git a/communication_techniques/include/asm_cache_comm.h b/communication_techniques/include/asm_cache_comm.h index c2027c4..8abfbdd 100644 --- a/communication_techniques/include/asm_cache_comm.h +++ b/communication_techniques/include/asm_cache_comm.h @@ -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"); } diff --git a/communication_techniques/include/common_comm.h b/communication_techniques/include/common_comm.h index 06935c4..2f5d17b 100644 --- a/communication_techniques/include/common_comm.h +++ b/communication_techniques/include/common_comm.h @@ -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); diff --git a/communication_techniques/include/pipe_comm.h b/communication_techniques/include/pipe_comm.h index 5873fb6..c068ef1 100644 --- a/communication_techniques/include/pipe_comm.h +++ b/communication_techniques/include/pipe_comm.h @@ -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 diff --git a/communication_techniques/include/shared_mem_comm.h b/communication_techniques/include/shared_mem_comm.h index 0807f39..81a4cea 100644 --- a/communication_techniques/include/shared_mem_comm.h +++ b/communication_techniques/include/shared_mem_comm.h @@ -7,14 +7,14 @@ #include #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 diff --git a/communication_techniques/include/shared_mem_opt_comm.h b/communication_techniques/include/shared_mem_opt_comm.h index 027fbab..0211040 100644 --- a/communication_techniques/include/shared_mem_opt_comm.h +++ b/communication_techniques/include/shared_mem_opt_comm.h @@ -7,14 +7,14 @@ #include #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 diff --git a/communication_techniques/src/asm_cache.c b/communication_techniques/src/asm_cache.c index 2f48c2e..f4fffb9 100644 --- a/communication_techniques/src/asm_cache.c +++ b/communication_techniques/src/asm_cache.c @@ -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(; ibuf[i]); channel->state = 0; diff --git a/communication_techniques/src/main.c b/communication_techniques/src/main.c index 3c0ba16..cda2943 100644 --- a/communication_techniques/src/main.c +++ b/communication_techniques/src/main.c @@ -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); } diff --git a/communication_techniques/src/pipe.c b/communication_techniques/src/pipe.c index da70d00..d41b091 100644 --- a/communication_techniques/src/pipe.c +++ b/communication_techniques/src/pipe.c @@ -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; diff --git a/communication_techniques/src/shared_mem.c b/communication_techniques/src/shared_mem.c index b6b1d84..9e16140 100644 --- a/communication_techniques/src/shared_mem.c +++ b/communication_techniques/src/shared_mem.c @@ -8,7 +8,7 @@ #include -__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); } diff --git a/communication_techniques/src/shared_mem_opt.c b/communication_techniques/src/shared_mem_opt.c index 5846e78..4b26f34 100644 --- a/communication_techniques/src/shared_mem_opt.c +++ b/communication_techniques/src/shared_mem_opt.c @@ -8,7 +8,7 @@ #include -__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); }