mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-13 20:12:26 +00:00
Rationale: we already had a non buildroot build system, maintaining both will be hard, and having short paths is more awesome.
43 lines
1.0 KiB
C
43 lines
1.0 KiB
C
/* https://github.com/cirosantilli/linux-kernel-module-cheat#gdb-step-debug-multicore */
|
|
|
|
#define _GNU_SOURCE
|
|
#include <assert.h>
|
|
#include <sched.h>
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
void print_affinity() {
|
|
cpu_set_t mask;
|
|
long nproc, i;
|
|
|
|
if (sched_getaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
|
|
perror("sched_getaffinity");
|
|
assert(false);
|
|
} else {
|
|
nproc = sysconf(_SC_NPROCESSORS_ONLN);
|
|
printf("sched_getaffinity = ");
|
|
for (i = 0; i < nproc; i++) {
|
|
printf("%d ", CPU_ISSET(i, &mask));
|
|
}
|
|
printf("\n");
|
|
}
|
|
}
|
|
|
|
int main(void) {
|
|
cpu_set_t mask;
|
|
|
|
print_affinity();
|
|
printf("sched_getcpu = %d\n", sched_getcpu());
|
|
CPU_ZERO(&mask);
|
|
CPU_SET(0, &mask);
|
|
if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
|
|
perror("sched_setaffinity");
|
|
assert(false);
|
|
}
|
|
print_affinity();
|
|
printf("sched_getcpu = %d\n", sched_getcpu());
|
|
return EXIT_SUCCESS;
|
|
}
|