mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-28 12:34:26 +01:00
failed sched_getaffinity_threads attempt
Better eigen naming.
This commit is contained in:
18
README.adoc
18
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
|
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:
|
Bibliography:
|
||||||
|
|
||||||
* https://stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c/50117787#50117787
|
* https://stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c/50117787#50117787
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ ifeq ($(BR2_PACKAGE_EIGEN),y)
|
|||||||
# http://lists.busybox.net/pipermail/buildroot/2018-June/222914.html
|
# http://lists.busybox.net/pipermail/buildroot/2018-June/222914.html
|
||||||
#CXXFLAGS_EXTRA += $(shell $(PKG_CONFIG) --cflags eigen3)
|
#CXXFLAGS_EXTRA += $(shell $(PKG_CONFIG) --cflags eigen3)
|
||||||
else
|
else
|
||||||
OUTS := $(filter-out eigen%$(OUT_EXT),$(OUTS))
|
OUTS := $(filter-out eigen_%$(OUT_EXT),$(OUTS))
|
||||||
endif
|
endif
|
||||||
ifeq ($(BR2_PACKAGE_LIBDRM),y)
|
ifeq ($(BR2_PACKAGE_LIBDRM),y)
|
||||||
LIBS += $(shell $(PKG_CONFIG) --libs libdrm)
|
LIBS += $(shell $(PKG_CONFIG) --libs libdrm)
|
||||||
|
|||||||
51
kernel_module/user/sched_getaffinity_threads.c
Normal file
51
kernel_module/user/sched_getaffinity_threads.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* https://github.com/cirosantilli/linux-kernel-module-cheat#gdb-step-debug-multicore */
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <assert.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user