diff --git a/Makefile b/Makefile index 5c9d1b4..fe48db6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CFLAGS=-Wall -O2 -g -LDFLAGS=-lhwloc +LDFLAGS=-lsocket processes := $(patsubst tests/%.c,%_processes,$(wildcard tests/*.c)) threads := $(patsubst tests/%.c,%_threads,$(wildcard tests/*.c)) diff --git a/main.c b/main.c index 7e931e4..f2007ff 100644 --- a/main.c +++ b/main.c @@ -10,15 +10,13 @@ #include #include #include -#include #include #include #include -#include -#include +//#include +//#include #include #include -#include #define MAX_TASKS 1024 #define CACHELINE_SIZE 128 @@ -67,10 +65,7 @@ static char *initialise_shared_area(unsigned long size) static void usage(char *command) { - printf("Usage: %s [options]\n\n", command); - printf("\t-s iterations\tNumber of iterations to run\n"); - printf("\t-t tasks\tNumber of threads or processes to run\n"); - printf("\t-m\t\tAffinitize tasks on SMT threads (default cores)\n"); + printf("Usage: %s <-t tasks> <-s iterations>\n\n", command); exit(1); } @@ -79,15 +74,11 @@ struct args void *(*func)(unsigned long long *iterations, unsigned long nr); unsigned long long *arg1; unsigned long arg2; - int poll_fd; }; static void *testcase_trampoline(void *p) { struct args *args = p; - struct pollfd pfd = { args->poll_fd, POLLIN, 0 }; - - poll(&pfd, 1, -1); return args->func(args->arg1, args->arg2); } @@ -103,6 +94,8 @@ void new_task(void *(func)(void *), void *arg) pthread_create(&tid, NULL, func, arg); } +typedef int cpu_set_t; + void new_task_affinity(struct args *args, size_t cpuset_size, cpu_set_t *mask) { @@ -111,7 +104,7 @@ void new_task_affinity(struct args *args, pthread_attr_init(&attr); - pthread_attr_setaffinity_np(&attr, cpuset_size, mask); +// pthread_attr_setaffinity_np(&attr, cpuset_size, mask); pthread_create(&tid, &attr, testcase_trampoline, args); @@ -166,14 +159,16 @@ void new_task(void *(func)(void *), void *arg) pids[nr_pids++] = pid; } +typedef int cpu_set_t; + void new_task_affinity(struct args *args, size_t cpuset_size, cpu_set_t *mask) { - cpu_set_t old_mask; + //cpu_set_t old_mask; int pid; - sched_getaffinity(0, sizeof(old_mask), &old_mask); - sched_setaffinity(0, cpuset_size, mask); +// sched_getaffinity(0, sizeof(old_mask), &old_mask); +// sched_setaffinity(0, cpuset_size, mask); parent_pid = getpid(); @@ -195,7 +190,7 @@ void new_task_affinity(struct args *args, testcase_trampoline(args); } - sched_setaffinity(0, sizeof(old_mask), &old_mask); +// sched_setaffinity(0, sizeof(old_mask), &old_mask); pids[nr_pids++] = pid; } @@ -215,25 +210,19 @@ int main(int argc, char *argv[]) int opt_tasks = 1; int opt_iterations = 0; int iterations = 0; - int i, n; + int i; char *m; static unsigned long long *results[MAX_TASKS]; - hwloc_topology_t topology; + //hwloc_topology_t topology; unsigned long long prev[MAX_TASKS] = {0, }; unsigned long long total = 0; - int fd[2]; - bool smt_affinity = false; while (1) { - signed char c = getopt(argc, argv, "mt:s:h"); + signed char c = getopt(argc, argv, "t:s:h"); if (c < 0) break; switch (c) { - case 'm': - smt_affinity = true; - break; - case 't': opt_tasks = atoi(optarg); if (opt_tasks > MAX_TASKS) { @@ -259,21 +248,15 @@ int main(int argc, char *argv[]) for (i = 0; i < opt_tasks; i++) results[i] = (unsigned long long *)&m[i * CACHELINE_SIZE]; - if (pipe(fd) == -1) { - perror("pipe"); - exit(1); - } - testcase_prepare(opt_tasks); - hwloc_topology_init(&topology); - hwloc_topology_load(topology); +// hwloc_topology_init(&topology); +// hwloc_topology_load(topology); - n = hwloc_get_nbobjs_by_type(topology, - smt_affinity ? HWLOC_OBJ_PU : HWLOC_OBJ_CORE); +// n = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE); for (i = 0; i < opt_tasks; i++) { - hwloc_obj_t obj; - cpu_set_t mask; +// hwloc_obj_t obj; +// cpu_set_t mask; struct args *args; args = malloc(sizeof(struct args)); @@ -284,22 +267,14 @@ int main(int argc, char *argv[]) args->func = testcase; args->arg1 = results[i]; args->arg2 = i; - args->poll_fd = fd[0]; - - obj = hwloc_get_obj_by_type(topology, - smt_affinity ? HWLOC_OBJ_PU : HWLOC_OBJ_CORE, - i % n); - hwloc_cpuset_to_glibc_sched_affinity(topology, - obj->cpuset, &mask, sizeof(mask)); - new_task_affinity(args, sizeof(mask), &mask); - } - if (write(fd[1], &i, 1) != 1) { - perror("write"); - exit(1); +// obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, i % n); +// hwloc_cpuset_to_glibc_sched_affinity(topology, +// obj->cpuset, &mask, sizeof(mask)); + new_task_affinity(args, 0, 0); } - hwloc_topology_destroy(topology); +// hwloc_topology_destroy(topology); printf("testcase:%s\n", testcase_description);