New technique in communication techniques bench
* shared_mem become shared_mem_opt * Apparition of shared_mem (no optimisation)
This commit is contained in:
parent
91c3ce6ca4
commit
e6912c4048
|
@ -18,7 +18,7 @@ LDFLAGS=-L$(LIBDIR) -L$(LOCALDIR)/$(PAPIHIGHLEVELLIBDIR) -Wl,-rpath-link,$(HOME)
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
BINNAMES=asm_cache_comm c_cache_comm pipe_comm shared_mem_comm
|
BINNAMES=asm_cache_comm c_cache_comm pipe_comm shared_mem_comm shared_mem_opt_comm
|
||||||
BINS=$(patsubst %, $(BINDIR)/%, $(BINNAMES))
|
BINS=$(patsubst %, $(BINDIR)/%, $(BINNAMES))
|
||||||
MAIN_OBJS=main.o common.o
|
MAIN_OBJS=main.o common.o
|
||||||
COMMON_LIB_OBJS=common.o
|
COMMON_LIB_OBJS=common.o
|
||||||
|
|
|
@ -28,13 +28,7 @@ extern __thread int cons_idx;
|
||||||
|
|
||||||
struct communication_assoc *create_comm_assoc(void);
|
struct communication_assoc *create_comm_assoc(void);
|
||||||
static inline void send(uintptr_t value) {
|
static inline void send(uintptr_t value) {
|
||||||
static __thread int local_cons_idx = 0;
|
while ((prod_idx + 1) % SHARED_SPACE_SIZE == cons_idx);
|
||||||
|
|
||||||
if (likely(((prod_idx + 1) % SHARED_SPACE_SIZE) == local_cons_idx))
|
|
||||||
{
|
|
||||||
while (((prod_idx + 1) % SHARED_SPACE_SIZE) == cons_idx);
|
|
||||||
local_cons_idx = cons_idx;
|
|
||||||
}
|
|
||||||
shared_space[prod_idx] = value;
|
shared_space[prod_idx] = value;
|
||||||
prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE;
|
prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef __COMM_H_
|
||||||
|
#define __COMM_H_ 1
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Non standard include */
|
||||||
|
#include <common_comm.h>
|
||||||
|
|
||||||
|
#define SHARED_SPACE_SIZE (2 * BUF_SIZE)
|
||||||
|
|
||||||
|
struct communication_assoc
|
||||||
|
{
|
||||||
|
struct communication_assoc *next;
|
||||||
|
struct communication_assoc *prev;
|
||||||
|
pthread_t tid;
|
||||||
|
uintptr_t *shared_space;
|
||||||
|
int *cons_idx;
|
||||||
|
int *prod_idx;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct communication_assoc assoc_root;
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
extern __thread uintptr_t *shared_space;
|
||||||
|
extern __thread int prod_idx;
|
||||||
|
extern __thread int cons_idx;
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
while (((prod_idx + 1) % SHARED_SPACE_SIZE) == cons_idx);
|
||||||
|
local_cons_idx = cons_idx;
|
||||||
|
}
|
||||||
|
shared_space[prod_idx] = value;
|
||||||
|
prod_idx = (prod_idx + 1) % SHARED_SPACE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
|
@ -37,20 +37,14 @@ void reception(void (*on_receive)(uintptr_t))
|
||||||
cur = assoc_root.next;
|
cur = assoc_root.next;
|
||||||
while(cur != &assoc_root)
|
while(cur != &assoc_root)
|
||||||
{
|
{
|
||||||
int cons_idx, prod_idx;
|
int cons_idx;
|
||||||
|
|
||||||
cons_idx = *cur->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)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
prod_idx = *cur->prod_idx;
|
uintptr_t tmp;
|
||||||
for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_SIZE)
|
tmp = cur->shared_space[cons_idx];
|
||||||
{
|
on_receive(tmp);
|
||||||
uintptr_t tmp;
|
}
|
||||||
tmp = cur->shared_space[cons_idx];
|
|
||||||
on_receive(tmp);
|
|
||||||
}
|
|
||||||
} while (prod_idx != *cur->prod_idx);
|
|
||||||
*cur->cons_idx = cons_idx;
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/* Non standard include */
|
||||||
|
#include <common_comm.h>
|
||||||
|
#include <specific_comm.h>
|
||||||
|
|
||||||
|
|
||||||
|
__thread uintptr_t *shared_space;
|
||||||
|
__thread int cons_idx = 0;
|
||||||
|
__thread int prod_idx = 0;
|
||||||
|
|
||||||
|
struct communication_assoc *create_comm_assoc(void)
|
||||||
|
{
|
||||||
|
struct communication_assoc *assoc;
|
||||||
|
|
||||||
|
shared_space = (uintptr_t *) malloc(SHARED_SPACE_SIZE * sizeof(uintptr_t));
|
||||||
|
assoc = (struct communication_assoc *) malloc(sizeof(struct communication_assoc));
|
||||||
|
assoc->tid = pthread_self();
|
||||||
|
assoc->shared_space = shared_space;
|
||||||
|
assoc->cons_idx = &cons_idx;
|
||||||
|
assoc->prod_idx = &prod_idx;
|
||||||
|
return assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reception(void (*on_receive)(uintptr_t))
|
||||||
|
{
|
||||||
|
wait_initialization();
|
||||||
|
/* printf("Activate the consumer...\n"); */
|
||||||
|
while(cont)
|
||||||
|
{
|
||||||
|
struct communication_assoc *cur;
|
||||||
|
|
||||||
|
discover_new_producers();
|
||||||
|
cur = assoc_root.next;
|
||||||
|
while(cur != &assoc_root)
|
||||||
|
{
|
||||||
|
int cons_idx, prod_idx;
|
||||||
|
|
||||||
|
cons_idx = *cur->cons_idx;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
prod_idx = *cur->prod_idx;
|
||||||
|
for(; cons_idx != prod_idx; cons_idx = (cons_idx + 1) % SHARED_SPACE_SIZE)
|
||||||
|
{
|
||||||
|
uintptr_t tmp;
|
||||||
|
tmp = cur->shared_space[cons_idx];
|
||||||
|
on_receive(tmp);
|
||||||
|
}
|
||||||
|
} while (prod_idx != *cur->prod_idx);
|
||||||
|
*cur->cons_idx = cons_idx;
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue