From 44aacb978e79a60513d567e0f230c435cbccadaa Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Wed, 10 Jun 2009 23:30:24 +0200 Subject: [PATCH] Add a naive L2 shared option for comm techs bench --- communication_techniques/src/main.c | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/communication_techniques/src/main.c b/communication_techniques/src/main.c index d0c61fe..bceb4a1 100644 --- a/communication_techniques/src/main.c +++ b/communication_techniques/src/main.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE + #include #include #include @@ -17,6 +19,7 @@ static long nb_cache_lines = 0; static long nb_prod = 0; static long size_buf = 1; static char *calculation_lib = NULL; +static int shared = 0; void usage(char *argv[]) { @@ -106,6 +109,7 @@ int analyse_options(int argc, char *argv[]) } break; case 's' : + shared = 1; /* TODO: shared L2 cache */ break; case '?' : @@ -129,6 +133,11 @@ int analyse_options(int argc, char *argv[]) fprintf(stderr, "You must give the number of producers\n"); return -1; } + if (shared && (nb_prod > 1)) + { + fprintf(stderr, "Too many producers to fit with the consumer in processors which share a same cache\n"); + return -1; + } return 0; } @@ -136,6 +145,20 @@ void *producer(void *unused) { int i, j, k; + if (shared) + { + pthread_t tid; + cpu_set_t cpuset; + + tid = pthread_self(); + CPU_ZERO(&cpuset); + CPU_SET(1, &cpuset); + if (pthread_setaffinity_np(tid, sizeof(cpu_set_t), &cpuset)) + { + perror("pthread_setaffinity_np"); + return NULL; + } + } printf("Registering: %p !\n", (void*) pthread_self()); add_sender(); k = (uintptr_t) pthread_self(); @@ -161,6 +184,20 @@ void onMessage(uintptr_t val) void *receptor(void *a) { + if (shared) + { + pthread_t tid; + cpu_set_t cpuset; + + tid = pthread_self(); + CPU_ZERO(&cpuset); + CPU_SET(1, &cpuset); + if (pthread_setaffinity_np(tid, sizeof(cpu_set_t), &cpuset)) + { + perror("pthread_setaffinity_np"); + return NULL; + } + } reception(onMessage); return NULL; }