diff --git a/core/build.gradle.kts b/core/build.gradle.kts index cd48963..d30d26c 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -25,15 +25,18 @@ kotlin { create("barrier") { defFile(project.file("src/nativeInterop/barrier.def")) headers(project.file("src/nativeInterop/barrier.h")) + compilerOpts.addAll(listOf("-Wall", "-Werror")) } if (affinitySupported) { create("affinity") { defFile(project.file("src/nativeInterop/kaffinity.def")) compilerOpts.add("-D_GNU_SOURCE") + compilerOpts.addAll(listOf("-Wall", "-Werror")) } } create("kpthread") { defFile(project.file("src/nativeInterop/kpthread.def")) + compilerOpts.addAll(listOf("-Wall", "-Werror")) } } } diff --git a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/ThreadlikeRunner.kt b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/ThreadlikeRunner.kt index 25e8b6f..78c8948 100644 --- a/core/src/commonMain/kotlin/org/jetbrains/litmuskt/ThreadlikeRunner.kt +++ b/core/src/commonMain/kotlin/org/jetbrains/litmuskt/ThreadlikeRunner.kt @@ -27,13 +27,6 @@ abstract class ThreadlikeRunner : LitmusRunner() { ): () -> LitmusResult { val threads = List(test.threadCount) { threadlikeProducer() } - affinityMap?.let { map -> - affinityManager?.apply { - for ((i, t) in threads.withIndex()) { - setAffinityAndCheck(t, map.allowedCores(i)) - } - } - } val barrier = barrierProducer(test.threadCount) val contexts = List(threads.size) { i -> @@ -44,6 +37,15 @@ abstract class ThreadlikeRunner : LitmusRunner() { thread.start(context, ::threadFunction) } + // cannot set affinity before thread is started (because pthread_create has not been called yet) + affinityMap?.let { map -> + affinityManager?.apply { + for ((i, t) in threads.withIndex()) { + setAffinityAndCheck(t, map.allowedCores(i)) + } + } + } + return { futures.forEach { it.await() } // await all results threads.forEach { it.dispose() } // stop all "threads" diff --git a/core/src/nativeInterop/kaffinity.def b/core/src/nativeInterop/kaffinity.def index 5a4a8ba..acad8c0 100644 --- a/core/src/nativeInterop/kaffinity.def +++ b/core/src/nativeInterop/kaffinity.def @@ -3,10 +3,12 @@ #include int set_affinity(void* thread, cpu_set_t* set) { - return pthread_setaffinity_np(*((pthread_t*) thread), sizeof(*set), set); + pthread_t pthread = *((pthread_t*) thread); + return pthread_setaffinity_np(pthread, sizeof(*set), set); } int get_affinity(void* thread, cpu_set_t* set) { - return pthread_getaffinity_np(*((pthread_t*) thread), sizeof(*set), set); + pthread_t pthread = *((pthread_t*) thread); + return pthread_getaffinity_np(pthread, sizeof(*set), set); } void cpu_zero(cpu_set_t* set) { @@ -16,7 +18,7 @@ void cpu_set(int cpu, cpu_set_t* set) { CPU_SET(cpu, set); } int cpu_isset(int cpu, cpu_set_t* set) { - CPU_ISSET(cpu, set); + return CPU_ISSET(cpu, set); } int cpu_setsize() { return CPU_SETSIZE;