From 9e97e4783f9b20f5d261d12acb4980b1908aa5cd Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 10 Jun 2009 18:40:26 -0400 Subject: [PATCH] Add set affinity -a option to tests Signed-off-by: Mathieu Desnoyers --- runtests.sh | 2 +- test_perthreadlock.c | 26 +++++++++++++++++++++++++- test_qsbr.c | 26 +++++++++++++++++++++++++- test_rwlock.c | 25 ++++++++++++++++++++++++- test_urcu.c | 26 +++++++++++++++++++++++++- 5 files changed, 100 insertions(+), 5 deletions(-) diff --git a/runtests.sh b/runtests.sh index a384418..7b20d26 100755 --- a/runtests.sh +++ b/runtests.sh @@ -4,5 +4,5 @@ for a in test_urcu test_urcu_mb test_qsbr test_rwlock test_perthreadlock; do echo Executing $a - ./${a} $* |grep "total num" + ./${a} $* done diff --git a/test_perthreadlock.c b/test_perthreadlock.c index 3684975..4f46d23 100644 --- a/test_perthreadlock.c +++ b/test_perthreadlock.c @@ -20,6 +20,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include "arch.h" @@ -187,9 +189,12 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); + printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } +cpu_set_t affinity; + int main(int argc, char **argv) { int err; @@ -197,7 +202,8 @@ int main(int argc, char **argv) void *tret; unsigned long long *count_reader, *count_writer; unsigned long long tot_reads = 0, tot_writes = 0; - int i; + int i, a; + int use_affinity = 0; if (argc < 4) { show_usage(argc, argv); @@ -223,6 +229,8 @@ int main(int argc, char **argv) return -1; } + CPU_ZERO(&affinity); + for (i = 4; i < argc; i++) { if (argv[i][0] != '-') continue; @@ -235,6 +243,16 @@ int main(int argc, char **argv) yield_active |= YIELD_WRITE; break; #endif + case 'a': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + a = atoi(argv[++i]); + CPU_SET(a, &affinity); + use_affinity = 1; + printf("Adding CPU %d affinity\n", a); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); @@ -251,6 +269,12 @@ int main(int argc, char **argv) printf("thread %-6s, thread id : %lx, tid %lu\n", "main", pthread_self(), (unsigned long)gettid()); + if (use_affinity + && sched_setaffinity(0, sizeof(affinity), &affinity) < 0) { + perror("sched_setaffinity"); + exit(-1); + } + tid_reader = malloc(sizeof(*tid_reader) * nr_readers); tid_writer = malloc(sizeof(*tid_writer) * nr_writers); count_reader = malloc(sizeof(*count_reader) * nr_readers); diff --git a/test_qsbr.c b/test_qsbr.c index 82521ef..f56234b 100644 --- a/test_qsbr.c +++ b/test_qsbr.c @@ -20,6 +20,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include "arch.h" @@ -226,9 +228,12 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); + printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } +cpu_set_t affinity; + int main(int argc, char **argv) { int err; @@ -236,7 +241,8 @@ int main(int argc, char **argv) void *tret; unsigned long long *count_reader, *count_writer; unsigned long long tot_reads = 0, tot_writes = 0; - int i; + int i, a; + int use_affinity = 0; if (argc < 4) { show_usage(argc, argv); @@ -261,6 +267,8 @@ int main(int argc, char **argv) return -1; } + CPU_ZERO(&affinity); + for (i = 4; i < argc; i++) { if (argv[i][0] != '-') continue; @@ -273,6 +281,16 @@ int main(int argc, char **argv) yield_active |= YIELD_WRITE; break; #endif + case 'a': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + a = atoi(argv[++i]); + CPU_SET(a, &affinity); + use_affinity = 1; + printf("Adding CPU %d affinity\n", a); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); @@ -289,6 +307,12 @@ int main(int argc, char **argv) printf("thread %-6s, thread id : %lx, tid %lu\n", "main", pthread_self(), (unsigned long)gettid()); + if (use_affinity + && sched_setaffinity(0, sizeof(affinity), &affinity) < 0) { + perror("sched_setaffinity"); + exit(-1); + } + test_array = malloc(sizeof(*test_array) * ARRAY_SIZE); tid_reader = malloc(sizeof(*tid_reader) * nr_readers); tid_writer = malloc(sizeof(*tid_writer) * nr_writers); diff --git a/test_rwlock.c b/test_rwlock.c index 1c29d73..0fdaad6 100644 --- a/test_rwlock.c +++ b/test_rwlock.c @@ -20,6 +20,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include "arch.h" @@ -175,9 +177,12 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); + printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } +cpu_set_t affinity; + int main(int argc, char **argv) { int err; @@ -185,7 +190,8 @@ int main(int argc, char **argv) void *tret; unsigned long long *count_reader, *count_writer; unsigned long long tot_reads = 0, tot_writes = 0; - int i; + int i, a; + int use_affinity = 0; if (argc < 4) { show_usage(argc, argv); @@ -211,6 +217,8 @@ int main(int argc, char **argv) return -1; } + CPU_ZERO(&affinity); + for (i = 4; i < argc; i++) { if (argv[i][0] != '-') continue; @@ -223,6 +231,16 @@ int main(int argc, char **argv) yield_active |= YIELD_WRITE; break; #endif + case 'a': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + a = atoi(argv[++i]); + CPU_SET(a, &affinity); + use_affinity = 1; + printf("Adding CPU %d affinity\n", a); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); @@ -238,6 +256,11 @@ int main(int argc, char **argv) printf("Writer delay : %u us.\n", wdelay); printf("thread %-6s, thread id : %lx, tid %lu\n", "main", pthread_self(), (unsigned long)gettid()); + if (use_affinity + && sched_setaffinity(0, sizeof(affinity), &affinity) < 0) { + perror("sched_setaffinity"); + exit(-1); + } tid_reader = malloc(sizeof(*tid_reader) * nr_readers); tid_writer = malloc(sizeof(*tid_writer) * nr_writers); diff --git a/test_urcu.c b/test_urcu.c index 5861281..016fa3f 100644 --- a/test_urcu.c +++ b/test_urcu.c @@ -20,6 +20,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _GNU_SOURCE #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include "arch.h" @@ -227,9 +229,12 @@ void show_usage(int argc, char **argv) printf(" [-r] [-w] (yield reader and/or writer)"); #endif printf(" [-d delay] (writer period (us))"); + printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); } +cpu_set_t affinity; + int main(int argc, char **argv) { int err; @@ -237,7 +242,8 @@ int main(int argc, char **argv) void *tret; unsigned long long *count_reader, *count_writer; unsigned long long tot_reads = 0, tot_writes = 0; - int i; + int i, a; + int use_affinity = 0; if (argc < 4) { show_usage(argc, argv); @@ -262,6 +268,8 @@ int main(int argc, char **argv) return -1; } + CPU_ZERO(&affinity); + for (i = 4; i < argc; i++) { if (argv[i][0] != '-') continue; @@ -274,6 +282,16 @@ int main(int argc, char **argv) yield_active |= YIELD_WRITE; break; #endif + case 'a': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + a = atoi(argv[++i]); + CPU_SET(a, &affinity); + use_affinity = 1; + printf("Adding CPU %d affinity\n", a); + break; case 'd': if (argc < i + 2) { show_usage(argc, argv); @@ -290,6 +308,12 @@ int main(int argc, char **argv) printf("thread %-6s, thread id : %lx, tid %lu\n", "main", pthread_self(), (unsigned long)gettid()); + if (use_affinity + && sched_setaffinity(0, sizeof(affinity), &affinity) < 0) { + perror("sched_setaffinity"); + exit(-1); + } + test_array = malloc(sizeof(*test_array) * ARRAY_SIZE); tid_reader = malloc(sizeof(*tid_reader) * nr_readers); tid_writer = malloc(sizeof(*tid_writer) * nr_writers); -- 2.34.1