Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/numactl/numactl.c
Show First 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | usage(void) | ||||
printf(" numactl [--mempolicy/-l <policy>] [--memdomain/-m " | printf(" numactl [--mempolicy/-l <policy>] [--memdomain/-m " | ||||
"<domain>]\n"); | "<domain>]\n"); | ||||
printf(" [--cpudomain/-c <domain>] <cmd> ...\n"); | printf(" [--cpudomain/-c <domain>] <cmd> ...\n"); | ||||
exit(EX_USAGE); | exit(EX_USAGE); | ||||
} | } | ||||
static int | static int | ||||
set_numa_domain_cpuaffinity(int cpu_domain) | set_numa_domain_cpuaffinity(int cpu_domain, cpuwhich_t which, id_t id) | ||||
{ | { | ||||
cpuset_t set; | cpuset_t set; | ||||
int error; | int error; | ||||
error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_DOMAIN, | error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_DOMAIN, | ||||
cpu_domain, sizeof(set), &set); | cpu_domain, sizeof(set), &set); | ||||
if (error != 0) | if (error != 0) | ||||
err(1, "cpuset_getaffinity"); | err(1, "cpuset_getaffinity"); | ||||
error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, | error = cpuset_setaffinity(CPU_LEVEL_WHICH, which, id, sizeof(set), | ||||
sizeof(set), &set); | &set); | ||||
if (error != 0) | if (error != 0) | ||||
err(1, "cpuset_setaffinity"); | err(1, "cpuset_setaffinity"); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if (argc) { | ||||
} | } | ||||
/* Set current memory process policy, will be inherited */ | /* Set current memory process policy, will be inherited */ | ||||
if (numa_setaffinity(CPU_WHICH_PID, -1, &vd) != 0) | if (numa_setaffinity(CPU_WHICH_PID, -1, &vd) != 0) | ||||
err(1, "numa_setaffinity"); | err(1, "numa_setaffinity"); | ||||
/* If a CPU domain policy was given, include that too */ | /* If a CPU domain policy was given, include that too */ | ||||
if (cpu_domain != -1) | if (cpu_domain != -1) | ||||
(void) set_numa_domain_cpuaffinity(cpu_domain); | (void) set_numa_domain_cpuaffinity(cpu_domain, | ||||
CPU_WHICH_PID, -1); | |||||
errno = 0; | errno = 0; | ||||
execvp(*argv, argv); | execvp(*argv, argv); | ||||
err(errno == ENOENT ? 127 : 126, "%s", *argv); | err(errno == ENOENT ? 127 : 126, "%s", *argv); | ||||
} | } | ||||
/* Figure out which */ | /* Figure out which */ | ||||
if (tid != -1) { | if (tid != -1) { | ||||
Show All 33 Lines | main(int argc, char *argv[]) | ||||
/* Syscall */ | /* Syscall */ | ||||
error = numa_setaffinity(which, id, &vd); | error = numa_setaffinity(which, id, &vd); | ||||
if (error != 0) | if (error != 0) | ||||
err(1, "numa_setaffinity"); | err(1, "numa_setaffinity"); | ||||
/* If a CPU domain policy was given, include that too */ | /* If a CPU domain policy was given, include that too */ | ||||
if (cpu_domain != -1) | if (cpu_domain != -1) | ||||
(void) set_numa_domain_cpuaffinity(cpu_domain); | (void) set_numa_domain_cpuaffinity(cpu_domain, which, id); | ||||
exit(0); | exit(0); | ||||
} | } |