Add a naive L2 shared option for comm techs bench
This commit is contained in:
parent
cc7da2e459
commit
44aacb978e
|
@ -1,3 +1,5 @@
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -17,6 +19,7 @@ static long nb_cache_lines = 0;
|
||||||
static long nb_prod = 0;
|
static long nb_prod = 0;
|
||||||
static long size_buf = 1;
|
static long size_buf = 1;
|
||||||
static char *calculation_lib = NULL;
|
static char *calculation_lib = NULL;
|
||||||
|
static int shared = 0;
|
||||||
|
|
||||||
void usage(char *argv[])
|
void usage(char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -106,6 +109,7 @@ int analyse_options(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 's' :
|
case 's' :
|
||||||
|
shared = 1;
|
||||||
/* TODO: shared L2 cache */
|
/* TODO: shared L2 cache */
|
||||||
break;
|
break;
|
||||||
case '?' :
|
case '?' :
|
||||||
|
@ -129,6 +133,11 @@ int analyse_options(int argc, char *argv[])
|
||||||
fprintf(stderr, "You must give the number of producers\n");
|
fprintf(stderr, "You must give the number of producers\n");
|
||||||
return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +145,20 @@ void *producer(void *unused)
|
||||||
{
|
{
|
||||||
int i, j, k;
|
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());
|
printf("Registering: %p !\n", (void*) pthread_self());
|
||||||
add_sender();
|
add_sender();
|
||||||
k = (uintptr_t) pthread_self();
|
k = (uintptr_t) pthread_self();
|
||||||
|
@ -161,6 +184,20 @@ void onMessage(uintptr_t val)
|
||||||
|
|
||||||
void *receptor(void *a)
|
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);
|
reception(onMessage);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue