mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
br2: enable taskset, create sched_getaffinity, yet undocumented
This commit is contained in:
2
br2
2
br2
@@ -39,6 +39,8 @@ BR2_TOOLCHAIN_BUILDROOT_WCHAR=y
|
|||||||
# lscpu: TODO not installing?
|
# lscpu: TODO not installing?
|
||||||
BR2_PACKAGE_UTIL_LINUX=y
|
BR2_PACKAGE_UTIL_LINUX=y
|
||||||
BR2_PACKAGE_UTIL_LINUX_BINARIES=y
|
BR2_PACKAGE_UTIL_LINUX_BINARIES=y
|
||||||
|
# taskset
|
||||||
|
BR2_PACKAGE_UTIL_LINUX_SCHEDUTILS=y
|
||||||
|
|
||||||
# Host GDB
|
# Host GDB
|
||||||
BR2_GDB_VERSION="7.11.1"
|
BR2_GDB_VERSION="7.11.1"
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ shift "$(($OPTIND - 1))"
|
|||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
stat="$1"
|
stat="$1"
|
||||||
else
|
else
|
||||||
stat=system.cpu.numCycles
|
stat=system.cpu[0-9]*.numCycles
|
||||||
fi
|
fi
|
||||||
set_common_vars "$arch" true
|
set_common_vars "$arch" true
|
||||||
awk "/^$stat /{ print \$2 }" "${m5out_dir}/stats.txt"
|
awk "/^$stat /{ print \$2 }" "${m5out_dir}/stats.txt"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ These programs can also be compiled and used on host.
|
|||||||
.. link:hello.c[]
|
.. link:hello.c[]
|
||||||
.. link:myinsmod.c[]
|
.. link:myinsmod.c[]
|
||||||
.. link:myrmmod.c[]
|
.. link:myrmmod.c[]
|
||||||
|
.. link:sched_getaffinity.c[]
|
||||||
.. link:usermem.c[]
|
.. link:usermem.c[]
|
||||||
... link:pagemap_dump.c[]
|
... link:pagemap_dump.c[]
|
||||||
.. inits
|
.. inits
|
||||||
|
|||||||
44
kernel_module/user/sched_getaffinity.c
Normal file
44
kernel_module/user/sched_getaffinity.c
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
upstream; https://stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c/50117787#50117787
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user