mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-13 20:12:26 +00:00
42 lines
1019 B
C
42 lines
1019 B
C
/* https://cirosantilli.com/linux-kernel-module-cheat#gdb-step-debug-multicore-userland */
|
|
|
|
#define _GNU_SOURCE
|
|
#include <assert.h>
|
|
#include <sched.h> /* sched_getaffinity */
|
|
#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);
|
|
}
|
|
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;
|
|
}
|