Skip to content

Commit 0dfbd93

Browse files
committed
failed sched_getaffinity_threads attempt
Better eigen naming.
1 parent 787b989 commit 0dfbd93

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

README.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,24 @@ and we observe that `info threads` shows the actual correct core on which the pr
19971997

19981998
We should also try it out with kernel modules: https://stackoverflow.com/questions/28347876/set-cpu-affinity-on-a-loadable-linux-kernel-module
19991999

2000+
TODO we then tried:
2001+
2002+
....
2003+
./run -c2 -F '/sched_getaffinity_threads.out'
2004+
....
2005+
2006+
and:
2007+
2008+
....
2009+
./rungdb-user kernel_module-1.0/user/sched_getaffinity_threads.out
2010+
....
2011+
2012+
to switch between two simultaneous live threads with different affinities, it just didn't break on our threads:
2013+
2014+
....
2015+
b main_thread_0
2016+
....
2017+
20002018
Bibliography:
20012019

20022020
* https://stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c/50117787#50117787

kernel_module/user/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ifeq ($(BR2_PACKAGE_EIGEN),y)
1515
# http://lists.busybox.net/pipermail/buildroot/2018-June/222914.html
1616
#CXXFLAGS_EXTRA += $(shell $(PKG_CONFIG) --cflags eigen3)
1717
else
18-
OUTS := $(filter-out eigen%$(OUT_EXT),$(OUTS))
18+
OUTS := $(filter-out eigen_%$(OUT_EXT),$(OUTS))
1919
endif
2020
ifeq ($(BR2_PACKAGE_LIBDRM),y)
2121
LIBS += $(shell $(PKG_CONFIG) --libs libdrm)
File renamed without changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* https://github.com/cirosantilli/linux-kernel-module-cheat#gdb-step-debug-multicore */
2+
3+
#define _GNU_SOURCE
4+
#include <assert.h>
5+
#include <pthread.h>
6+
#include <sched.h>
7+
#include <stdbool.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <unistd.h>
11+
12+
void* main_thread_0(void *arg) {
13+
int i;
14+
cpu_set_t mask;
15+
CPU_ZERO(&mask);
16+
CPU_SET(*((int*)arg), &mask);
17+
sched_setaffinity(0, sizeof(cpu_set_t), &mask);
18+
i = 0;
19+
while (true) {
20+
printf("0 %d\n", i);
21+
sleep(1);
22+
i++;
23+
}
24+
return NULL;
25+
}
26+
27+
void* main_thread_1(void *arg) {
28+
int i;
29+
cpu_set_t mask;
30+
CPU_ZERO(&mask);
31+
CPU_SET(*((int*)arg), &mask);
32+
sched_setaffinity(1, sizeof(cpu_set_t), &mask);
33+
i = 0;
34+
while (true) {
35+
printf("1 %d\n", i);
36+
sleep(1);
37+
i++;
38+
}
39+
return NULL;
40+
}
41+
42+
int main(void) {
43+
enum NUM_THREADS {NUM_THREADS = 2};
44+
pthread_t threads[NUM_THREADS];
45+
int thread_args[NUM_THREADS];
46+
pthread_create(&threads[0], NULL, main_thread_0, (void*)&thread_args[0]);
47+
pthread_create(&threads[1], NULL, main_thread_1, (void*)&thread_args[1]);
48+
pthread_join(threads[0], NULL);
49+
pthread_join(threads[1], NULL);
50+
return EXIT_SUCCESS;
51+
}

0 commit comments

Comments
 (0)