From: Mathieu Desnoyers Date: Mon, 22 Jun 2009 01:33:38 +0000 (-0400) Subject: Protect shared affinity table with mutex X-Git-Tag: v0.1~120 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6af882baf4a7cc82167b8e1abba5d6c851e0e6e8;p=userspace-rcu.git Protect shared affinity table with mutex Signed-off-by: Mathieu Desnoyers --- diff --git a/test_mutex.c b/test_mutex.c index 4cf1d32..e824980 100644 --- a/test_mutex.c +++ b/test_mutex.c @@ -98,22 +98,33 @@ static unsigned int cpu_affinities[NR_CPUS]; static unsigned int next_aff = 0; static int use_affinity = 0; +pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; + static void set_affinity(void) { cpu_set_t mask; int cpu; + int ret; if (!use_affinity) return; + ret = pthread_mutex_lock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } cpu = cpu_affinities[next_aff++]; + ret = pthread_mutex_unlock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } CPU_ZERO(&mask); CPU_SET(cpu, &mask); sched_setaffinity(0, sizeof(mask), &mask); } - - /* * returns 0 if test should end. */ diff --git a/test_perthreadlock.c b/test_perthreadlock.c index 5bbe72b..31b7721 100644 --- a/test_perthreadlock.c +++ b/test_perthreadlock.c @@ -102,22 +102,33 @@ static unsigned int cpu_affinities[NR_CPUS]; static unsigned int next_aff = 0; static int use_affinity = 0; +pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; + static void set_affinity(void) { cpu_set_t mask; int cpu; + int ret; if (!use_affinity) return; + ret = pthread_mutex_lock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } cpu = cpu_affinities[next_aff++]; + ret = pthread_mutex_unlock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } CPU_ZERO(&mask); CPU_SET(cpu, &mask); sched_setaffinity(0, sizeof(mask), &mask); } - - /* * returns 0 if test should end. */ diff --git a/test_qsbr.c b/test_qsbr.c index af5ccfd..2617629 100644 --- a/test_qsbr.c +++ b/test_qsbr.c @@ -92,22 +92,33 @@ static unsigned int cpu_affinities[NR_CPUS]; static unsigned int next_aff = 0; static int use_affinity = 0; +pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; + static void set_affinity(void) { cpu_set_t mask; int cpu; + int ret; if (!use_affinity) return; + ret = pthread_mutex_lock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } cpu = cpu_affinities[next_aff++]; + ret = pthread_mutex_unlock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } CPU_ZERO(&mask); CPU_SET(cpu, &mask); sched_setaffinity(0, sizeof(mask), &mask); } - - /* * returns 0 if test should end. */ diff --git a/test_qsbr_gc.c b/test_qsbr_gc.c index 0b2d5df..98094a6 100644 --- a/test_qsbr_gc.c +++ b/test_qsbr_gc.c @@ -101,22 +101,33 @@ static unsigned int cpu_affinities[NR_CPUS]; static unsigned int next_aff = 0; static int use_affinity = 0; +pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; + static void set_affinity(void) { cpu_set_t mask; int cpu; + int ret; if (!use_affinity) return; + ret = pthread_mutex_lock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } cpu = cpu_affinities[next_aff++]; + ret = pthread_mutex_unlock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } CPU_ZERO(&mask); CPU_SET(cpu, &mask); sched_setaffinity(0, sizeof(mask), &mask); } - - /* * returns 0 if test should end. */ diff --git a/test_rwlock.c b/test_rwlock.c index b790901..4cc4c07 100644 --- a/test_rwlock.c +++ b/test_rwlock.c @@ -98,22 +98,33 @@ static unsigned int cpu_affinities[NR_CPUS]; static unsigned int next_aff = 0; static int use_affinity = 0; +pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; + static void set_affinity(void) { cpu_set_t mask; int cpu; + int ret; if (!use_affinity) return; + ret = pthread_mutex_lock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } cpu = cpu_affinities[next_aff++]; + ret = pthread_mutex_unlock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } CPU_ZERO(&mask); CPU_SET(cpu, &mask); sched_setaffinity(0, sizeof(mask), &mask); } - - /* * returns 0 if test should end. */ diff --git a/test_urcu_gc.c b/test_urcu_gc.c index f1cce24..66b714b 100644 --- a/test_urcu_gc.c +++ b/test_urcu_gc.c @@ -105,22 +105,33 @@ static unsigned int cpu_affinities[NR_CPUS]; static unsigned int next_aff = 0; static int use_affinity = 0; +pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; + static void set_affinity(void) { cpu_set_t mask; int cpu; + int ret; if (!use_affinity) return; + ret = pthread_mutex_lock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex lock"); + exit(-1); + } cpu = cpu_affinities[next_aff++]; + ret = pthread_mutex_unlock(&affinity_mutex); + if (ret) { + perror("Error in pthread mutex unlock"); + exit(-1); + } CPU_ZERO(&mask); CPU_SET(cpu, &mask); sched_setaffinity(0, sizeof(mask), &mask); } - - /* * returns 0 if test should end. */