From 12494e2fbc1506cfbb6813f0519c99f0c8faff7e Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Fri, 12 Jun 2009 00:44:52 +0200 Subject: [PATCH] More uniformity in communication techniques bench * Only use 2 * BUF_SIZE bytes for shared_memory --- communication_techniques/include/shared_mem_comm.h | 5 +++-- communication_techniques/include/shared_mem_opt_comm.h | 7 ++++--- communication_techniques/src/shared_mem.c | 4 ++-- communication_techniques/src/shared_mem_opt.c | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/communication_techniques/include/shared_mem_comm.h b/communication_techniques/include/shared_mem_comm.h index 61b6cc9..0807f39 100644 --- a/communication_techniques/include/shared_mem_comm.h +++ b/communication_techniques/include/shared_mem_comm.h @@ -7,6 +7,7 @@ #include #define SHARED_SPACE_SIZE (2 * BUF_SIZE) +#define SHARED_SPACE_UINTPTR (SHARED_SPACE_SIZE / sizeof(uintptr_t)) struct communication_assoc { @@ -28,9 +29,9 @@ 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_SIZE == cons_idx); + while ((prod_idx + 1) % SHARED_SPACE_UINTPTR == cons_idx); shared_space[prod_idx] = value; - prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE; + prod_idx = (prod_idx + 1) % SHARED_SPACE_UINTPTR; } __END_DECLS diff --git a/communication_techniques/include/shared_mem_opt_comm.h b/communication_techniques/include/shared_mem_opt_comm.h index c518ea8..027fbab 100644 --- a/communication_techniques/include/shared_mem_opt_comm.h +++ b/communication_techniques/include/shared_mem_opt_comm.h @@ -7,6 +7,7 @@ #include #define SHARED_SPACE_SIZE (2 * BUF_SIZE) +#define SHARED_SPACE_UINTPTR (SHARED_SPACE_SIZE / sizeof(uintptr_t)) struct communication_assoc { @@ -30,13 +31,13 @@ struct communication_assoc *create_comm_assoc(void); static inline void send(uintptr_t value) { static __thread int local_cons_idx = 0; - if (likely(((prod_idx + 1) % SHARED_SPACE_SIZE) == local_cons_idx)) + if (likely(((prod_idx + 1) % SHARED_SPACE_UINTPTR) == local_cons_idx)) { - while (((prod_idx + 1) % SHARED_SPACE_SIZE) == cons_idx); + while (((prod_idx + 1) % SHARED_SPACE_UINTPTR) == cons_idx); local_cons_idx = cons_idx; } shared_space[prod_idx] = value; - prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE; + prod_idx = (prod_idx + 1) % SHARED_SPACE_UINTPTR; } __END_DECLS diff --git a/communication_techniques/src/shared_mem.c b/communication_techniques/src/shared_mem.c index 8f624d8..b6b1d84 100644 --- a/communication_techniques/src/shared_mem.c +++ b/communication_techniques/src/shared_mem.c @@ -16,7 +16,7 @@ struct communication_assoc *create_comm_assoc(void) { struct communication_assoc *assoc; - shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE * sizeof(uintptr_t)); + shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE); assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc)); assoc->tid = pthread_self(); assoc->shared_space = shared_space; @@ -39,7 +39,7 @@ 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_SIZE, *cur->cons_idx = 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) { uintptr_t tmp; tmp = cur->shared_space[cons_idx]; diff --git a/communication_techniques/src/shared_mem_opt.c b/communication_techniques/src/shared_mem_opt.c index 7b154b5..5846e78 100644 --- a/communication_techniques/src/shared_mem_opt.c +++ b/communication_techniques/src/shared_mem_opt.c @@ -16,7 +16,7 @@ struct communication_assoc *create_comm_assoc(void) { struct communication_assoc *assoc; - shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE * sizeof(uintptr_t)); + shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE); assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc)); assoc->tid = pthread_self(); assoc->shared_space = shared_space; @@ -43,7 +43,7 @@ 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_SIZE) + for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_UINTPTR) { uintptr_t tmp; tmp = cur->shared_space[cons_idx];