From 0dfbd93afe6e70cf203bbe05a6160b5b19e174a0 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sun, 22 Jul 2018 19:54:56 +0100 Subject: [PATCH] failed sched_getaffinity_threads attempt Better eigen naming. --- README.adoc | 18 +++++++ kernel_module/user/Makefile | 2 +- .../user/{eigen.cpp => eigen_hello.cpp} | 0 .../user/sched_getaffinity_threads.c | 51 +++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) rename kernel_module/user/{eigen.cpp => eigen_hello.cpp} (100%) create mode 100644 kernel_module/user/sched_getaffinity_threads.c diff --git a/README.adoc b/README.adoc index c59a2d9..fe9c657 100644 --- a/README.adoc +++ b/README.adoc @@ -1997,6 +1997,24 @@ and we observe that `info threads` shows the actual correct core on which the pr We should also try it out with kernel modules: https://stackoverflow.com/questions/28347876/set-cpu-affinity-on-a-loadable-linux-kernel-module +TODO we then tried: + +.... +./run -c2 -F '/sched_getaffinity_threads.out' +.... + +and: + +.... +./rungdb-user kernel_module-1.0/user/sched_getaffinity_threads.out +.... + +to switch between two simultaneous live threads with different affinities, it just didn't break on our threads: + +.... +b main_thread_0 +.... + Bibliography: * https://stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c/50117787#50117787 diff --git a/kernel_module/user/Makefile b/kernel_module/user/Makefile index a579057..4bd51c5 100644 --- a/kernel_module/user/Makefile +++ b/kernel_module/user/Makefile @@ -15,7 +15,7 @@ ifeq ($(BR2_PACKAGE_EIGEN),y) # http://lists.busybox.net/pipermail/buildroot/2018-June/222914.html #CXXFLAGS_EXTRA += $(shell $(PKG_CONFIG) --cflags eigen3) else - OUTS := $(filter-out eigen%$(OUT_EXT),$(OUTS)) + OUTS := $(filter-out eigen_%$(OUT_EXT),$(OUTS)) endif ifeq ($(BR2_PACKAGE_LIBDRM),y) LIBS += $(shell $(PKG_CONFIG) --libs libdrm) diff --git a/kernel_module/user/eigen.cpp b/kernel_module/user/eigen_hello.cpp similarity index 100% rename from kernel_module/user/eigen.cpp rename to kernel_module/user/eigen_hello.cpp diff --git a/kernel_module/user/sched_getaffinity_threads.c b/kernel_module/user/sched_getaffinity_threads.c new file mode 100644 index 0000000..4e56996 --- /dev/null +++ b/kernel_module/user/sched_getaffinity_threads.c @@ -0,0 +1,51 @@ +/* https://github.com/cirosantilli/linux-kernel-module-cheat#gdb-step-debug-multicore */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +void* main_thread_0(void *arg) { + int i; + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(*((int*)arg), &mask); + sched_setaffinity(0, sizeof(cpu_set_t), &mask); + i = 0; + while (true) { + printf("0 %d\n", i); + sleep(1); + i++; + } + return NULL; +} + +void* main_thread_1(void *arg) { + int i; + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(*((int*)arg), &mask); + sched_setaffinity(1, sizeof(cpu_set_t), &mask); + i = 0; + while (true) { + printf("1 %d\n", i); + sleep(1); + i++; + } + return NULL; +} + +int main(void) { + enum NUM_THREADS {NUM_THREADS = 2}; + pthread_t threads[NUM_THREADS]; + int thread_args[NUM_THREADS]; + pthread_create(&threads[0], NULL, main_thread_0, (void*)&thread_args[0]); + pthread_create(&threads[1], NULL, main_thread_1, (void*)&thread_args[1]); + pthread_join(threads[0], NULL); + pthread_join(threads[1], NULL); + return EXIT_SUCCESS; +}