From c3aad28ad5f38e81caaa7062f9917f187716bacf Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Tue, 25 Jan 2011 17:21:39 +0100 Subject: [PATCH] [commtech] Add calculation method Add a calculation method which add the value of the first integer of n consecutive cache lines and write the results in one of the integer of these cache lines. Next calculation uses the next n consecutives cache lines and write the result in the next integer. --- communication_techniques/Makefile | 1 + communication_techniques/lancement.sh | 19 +++--- .../src/calculation/calc_line.c | 60 +++++++++++++++++++ 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 communication_techniques/src/calculation/calc_line.c diff --git a/communication_techniques/Makefile b/communication_techniques/Makefile index 52c022a..93dcebf 100644 --- a/communication_techniques/Makefile +++ b/communication_techniques/Makefile @@ -22,6 +22,7 @@ CC=gcc # Files BINNAMES:=c_cache_comm lamport_comm shared_mem_opt_comm none_comm csq_2_comm BINNAMES+=csq_64_comm fast_forward_comm mcringbuffer_comm #pipe_comm jikes_barrier_comm asm_cache_comm +CALCLIBSNAMES:=calc_mat calc_line calc_useless_loop BINS:=$(patsubst %,$(BINDIR)/%,$(BINNAMES)) CALCLIBS:=$(patsubst %,$(LIBDIR)/$(CALCDIR)/lib%.so.1,$(CALCLIBSNAMES)) MAIN_OBJS:=main.o diff --git a/communication_techniques/lancement.sh b/communication_techniques/lancement.sh index 86315c1..7c87fe5 100755 --- a/communication_techniques/lancement.sh +++ b/communication_techniques/lancement.sh @@ -10,7 +10,7 @@ calcDir="calculation" # Param binList="$(ls -1 "${binDir}"| sed '$!s/$/ /' | tr -d '\n')" nbProdList="1" # Nombre de cores producteurs -typeProdList="none matrice useless_loop" # Methode pour produire les valeurs +typeProdList="none useless_loop line matrice" # Methode pour produire les valeurs typeCacheList="L2 Memory" # Niveau de cache partage perfOpt="stat -r 10 -e cycles -e L1-dcache-loads -e L1-dcache-stores -e LLC-load-misses -e LLC-store-misses" @@ -31,6 +31,7 @@ export LD_LIBRARY_PATH function_run () { case $typeProd in "none" ) optTypeProd="" ;; + "line" ) optTypeProd="-c lib/${calcDir}/libcalc_line.so ${argTypeProd}" ;; "matrice" ) optTypeProd="-c lib/${calcDir}/libcalc_mat.so 16" ;; "useless_loop" ) optTypeProd="-c lib/${calcDir}/libcalc_useless_loop.so ${argTypeProd}" ;; * ) exit 1 ;; @@ -68,15 +69,13 @@ for nbProd in $nbProdList ; do for bin in $binList ; do case $typeProd in "useless_loop" ) - case $bin in - "jikes_barrier_comm" | "asm_cache_comm" | "c_cache_comm" ) - for argTypeProd in 1 `seq 5 5 50` ; do - function_run ; - done ;; - * ) - argTypeProd=1 ; - function_run ;; - esac ;; + for argTypeProd in 1 `seq 5 5 50` ; do + function_run ; + done ;; + "line" ) + for argTypeProd in 1 2 4 8 16 32 64 ; do + function_run ; + done ;; "matrice" ) argTypeProd=16 ; function_run ;; diff --git a/communication_techniques/src/calculation/calc_line.c b/communication_techniques/src/calculation/calc_line.c new file mode 100644 index 0000000..9d79dae --- /dev/null +++ b/communication_techniques/src/calculation/calc_line.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include + +/* Non standard include */ +#include + +#define CACHE_SIZE (32 * 1024) + + +static volatile uintptr_t *line_array; +static int write_idx, read_idx; +static int lines_per_calc; + +#define CACHE_LINE_ENTRIES (CACHE_LINE_SIZE / sizeof(*line_array)) + +int init_calc(int lines_per_calc_param) +{ + int i; + + assert(!(CACHE_SIZE % (lines_per_calc_param * CACHE_LINE_SIZE))); + lines_per_calc = lines_per_calc_param; + write_idx = 0; + read_idx = 0; + srand(42); + if (posix_memalign((void **) &line_array, CACHE_LINE_SIZE, CACHE_SIZE)) + { + fprintf(stderr, "calc_line: Unable to allocate memory for random line-sized calculation\n"); + return -1; + } + for (i = 0; i < CACHE_SIZE / sizeof(*line_array); i++) + line_array[i] = rand(); + return 0; +} + +void **do_calc(void) +{ + int next_stop_read_idx, mres, cur_write_idx; + + mres = 0; + next_stop_read_idx = read_idx + lines_per_calc * CACHE_LINE_ENTRIES; + for (; read_idx < next_stop_read_idx; read_idx += CACHE_LINE_ENTRIES) + { + mres += line_array[read_idx]; + line_array[read_idx]++; + } + read_idx %= CACHE_SIZE / sizeof(*line_array); + cur_write_idx = write_idx; + write_idx++; + write_idx %= CACHE_SIZE / sizeof(*line_array); + line_array[cur_write_idx] = mres; + return (void **) &line_array[cur_write_idx]; +} + +int end_calc(void) +{ + free((void *) line_array); + return 0; +}