Create a cpuset mask for each NUMA domain that is available in the

kernel via the global cpuset_domain[] array. To export these to userland,
add a CPU_WHICH_DOMAIN level that can be used to fetch the mask for a
specific domain. Add a -d flag to cpuset(1) that can be used to fetch
the mask for a given domain.

Differential Revision:	https://reviews.freebsd.org/D1232
Submitted by:	jeff (kernel bits)
Reviewed by:	adrian, jeff
This commit is contained in:
jhb 2015-01-08 15:53:13 +00:00
parent 7b0cd0edc9
commit 06e75f0dba
6 changed files with 49 additions and 19 deletions

View File

@ -56,6 +56,10 @@ __FBSDID("$FreeBSD$");
#include <sys/interrupt.h> #include <sys/interrupt.h>
#include <vm/uma.h> #include <vm/uma.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
#include <vm/vm_param.h>
#include <vm/vm_phys.h>
#ifdef DDB #ifdef DDB
#include <ddb/ddb.h> #include <ddb/ddb.h>
@ -113,6 +117,7 @@ SYSCTL_INT(_kern_sched, OID_AUTO, cpusetsize, CTLFLAG_RD,
SYSCTL_NULL_INT_PTR, sizeof(cpuset_t), "sizeof(cpuset_t)"); SYSCTL_NULL_INT_PTR, sizeof(cpuset_t), "sizeof(cpuset_t)");
cpuset_t *cpuset_root; cpuset_t *cpuset_root;
cpuset_t cpuset_domain[MAXMEMDOM];
/* /*
* Acquire a reference to a cpuset, all pointers must be tracked with refs. * Acquire a reference to a cpuset, all pointers must be tracked with refs.
@ -457,6 +462,7 @@ cpuset_which(cpuwhich_t which, id_t id, struct proc **pp, struct thread **tdp,
return (0); return (0);
} }
case CPU_WHICH_IRQ: case CPU_WHICH_IRQ:
case CPU_WHICH_DOMAIN:
return (0); return (0);
default: default:
return (EINVAL); return (EINVAL);
@ -810,7 +816,8 @@ out:
/* /*
* Creates the cpuset for thread0. We make two sets: * Creates system-wide cpusets and the cpuset for thread0 including two
* sets:
* *
* 0 - The root set which should represent all valid processors in the * 0 - The root set which should represent all valid processors in the
* system. It is initially created with a mask of all processors * system. It is initially created with a mask of all processors
@ -856,6 +863,10 @@ cpuset_thread0(void)
*/ */
cpuset_unr = new_unrhdr(2, INT_MAX, NULL); cpuset_unr = new_unrhdr(2, INT_MAX, NULL);
/* MD Code is responsible for initializing sets if vm_ndomains > 1. */
if (vm_ndomains == 1)
CPU_COPY(&all_cpus, &cpuset_domain[0]);
return (set); return (set);
} }
@ -1010,6 +1021,7 @@ sys_cpuset_getid(struct thread *td, struct cpuset_getid_args *uap)
case CPU_WHICH_JAIL: case CPU_WHICH_JAIL:
break; break;
case CPU_WHICH_IRQ: case CPU_WHICH_IRQ:
case CPU_WHICH_DOMAIN:
return (EINVAL); return (EINVAL);
} }
switch (uap->level) { switch (uap->level) {
@ -1073,6 +1085,7 @@ sys_cpuset_getaffinity(struct thread *td, struct cpuset_getaffinity_args *uap)
case CPU_WHICH_JAIL: case CPU_WHICH_JAIL:
break; break;
case CPU_WHICH_IRQ: case CPU_WHICH_IRQ:
case CPU_WHICH_DOMAIN:
error = EINVAL; error = EINVAL;
goto out; goto out;
} }
@ -1104,6 +1117,12 @@ sys_cpuset_getaffinity(struct thread *td, struct cpuset_getaffinity_args *uap)
case CPU_WHICH_IRQ: case CPU_WHICH_IRQ:
error = intr_getaffinity(uap->id, mask); error = intr_getaffinity(uap->id, mask);
break; break;
case CPU_WHICH_DOMAIN:
if (uap->id >= vm_ndomains)
error = ESRCH;
else
CPU_COPY(&cpuset_domain[uap->id], mask);
break;
} }
break; break;
default: default:
@ -1182,6 +1201,7 @@ sys_cpuset_setaffinity(struct thread *td, struct cpuset_setaffinity_args *uap)
case CPU_WHICH_JAIL: case CPU_WHICH_JAIL:
break; break;
case CPU_WHICH_IRQ: case CPU_WHICH_IRQ:
case CPU_WHICH_DOMAIN:
error = EINVAL; error = EINVAL;
goto out; goto out;
} }

View File

@ -76,6 +76,7 @@
#define CPU_WHICH_CPUSET 3 /* Specifies a set id. */ #define CPU_WHICH_CPUSET 3 /* Specifies a set id. */
#define CPU_WHICH_IRQ 4 /* Specifies an irq #. */ #define CPU_WHICH_IRQ 4 /* Specifies an irq #. */
#define CPU_WHICH_JAIL 5 /* Specifies a jail id. */ #define CPU_WHICH_JAIL 5 /* Specifies a jail id. */
#define CPU_WHICH_DOMAIN 6 /* Specifies a NUMA domain id. */
/* /*
* Reserved cpuset identifiers. * Reserved cpuset identifiers.

View File

@ -85,6 +85,7 @@ extern int mp_ncpus;
extern volatile int smp_started; extern volatile int smp_started;
extern cpuset_t all_cpus; extern cpuset_t all_cpus;
extern cpuset_t cpuset_domain[MAXMEMDOM]; /* CPUs in each NUMA domain. */
/* /*
* Macro allowing us to determine whether a CPU is absent at any given * Macro allowing us to determine whether a CPU is absent at any given

View File

@ -342,7 +342,7 @@ srat_walk_table(acpi_subtable_handler *handler, void *arg)
} }
/* /*
* Setup per-CPU ACPI IDs. * Setup per-CPU domain IDs.
*/ */
static void static void
srat_set_cpus(void *dummy) srat_set_cpus(void *dummy)
@ -363,6 +363,7 @@ srat_set_cpus(void *dummy)
panic("SRAT: CPU with APIC ID %u is not known", panic("SRAT: CPU with APIC ID %u is not known",
pc->pc_apic_id); pc->pc_apic_id);
pc->pc_domain = cpu->domain; pc->pc_domain = cpu->domain;
CPU_SET(i, &cpuset_domain[cpu->domain]);
if (bootverbose) if (bootverbose)
printf("SRAT: CPU %u has memory domain %d\n", i, printf("SRAT: CPU %u has memory domain %d\n", i,
cpu->domain); cpu->domain);

View File

@ -46,12 +46,13 @@
.Fl C .Fl C
.Fl p Ar pid .Fl p Ar pid
.Nm .Nm
.Op Fl cr .Op Fl c
.Op Fl l Ar cpu-list .Op Fl l Ar cpu-list
.Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq .Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq
.Nm .Nm
.Op Fl cgir .Fl g
.Op Fl j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq .Op Fl cir
.Op Fl d Ar domain | j Ar jailid | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .Nm
@ -62,7 +63,7 @@ about processor binding, sets, and available processors in the system.
.Nm .Nm
requires a target to modify or query. requires a target to modify or query.
The target may be specified as a command, process id, thread id, a The target may be specified as a command, process id, thread id, a
cpuset id, an irq or a jail id. cpuset id, an irq, a jail id, or a NUMA domain.
Using Using
.Fl g .Fl g
the target's set id or mask may be queried. the target's set id or mask may be queried.
@ -108,6 +109,8 @@ Create a new cpuset and assign the target process to that set.
.It Fl c .It Fl c
The requested operation should reference the cpuset available via the The requested operation should reference the cpuset available via the
target specifier. target specifier.
.It Fl d Ar domain
Specifies a NUMA domain id as the target of the operation.
.It Fl g .It Fl g
Causes Causes
.Nm .Nm

View File

@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
static int Cflag; static int Cflag;
static int cflag; static int cflag;
static int dflag;
static int gflag; static int gflag;
static int iflag; static int iflag;
static int jflag; static int jflag;
@ -161,7 +162,8 @@ printset(cpuset_t *mask)
printf("\n"); printf("\n");
} }
static const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq", "jail" }; static const char *whichnames[] = { NULL, "tid", "pid", "cpuset", "irq", "jail",
"domain" };
static const char *levelnames[] = { NULL, " root", " cpuset", "" }; static const char *levelnames[] = { NULL, " root", " cpuset", "" };
static void static void
@ -206,17 +208,20 @@ main(int argc, char *argv[])
level = CPU_LEVEL_WHICH; level = CPU_LEVEL_WHICH;
which = CPU_WHICH_PID; which = CPU_WHICH_PID;
id = pid = tid = setid = -1; id = pid = tid = setid = -1;
while ((ch = getopt(argc, argv, "Ccgij:l:p:rs:t:x:")) != -1) { while ((ch = getopt(argc, argv, "Ccd:gij:l:p:rs:t:x:")) != -1) {
switch (ch) { switch (ch) {
case 'C': case 'C':
Cflag = 1; Cflag = 1;
break; break;
case 'c': case 'c':
if (rflag)
usage();
cflag = 1; cflag = 1;
level = CPU_LEVEL_CPUSET; level = CPU_LEVEL_CPUSET;
break; break;
case 'd':
dflag = 1;
which = CPU_WHICH_DOMAIN;
id = atoi(optarg);
break;
case 'g': case 'g':
gflag = 1; gflag = 1;
break; break;
@ -238,8 +243,6 @@ main(int argc, char *argv[])
id = pid = atoi(optarg); id = pid = atoi(optarg);
break; break;
case 'r': case 'r':
if (cflag)
usage();
level = CPU_LEVEL_ROOT; level = CPU_LEVEL_ROOT;
rflag = 1; rflag = 1;
break; break;
@ -268,7 +271,7 @@ main(int argc, char *argv[])
if (argc || Cflag || lflag) if (argc || Cflag || lflag)
usage(); usage();
/* Only one identity specifier. */ /* Only one identity specifier. */
if (jflag + xflag + sflag + pflag + tflag > 1) if (dflag + jflag + xflag + sflag + pflag + tflag > 1)
usage(); usage();
if (iflag) if (iflag)
printsetid(); printsetid();
@ -276,13 +279,13 @@ main(int argc, char *argv[])
printaffinity(); printaffinity();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
if (iflag) if (dflag || iflag || rflag)
usage(); usage();
/* /*
* The user wants to run a command with a set and possibly cpumask. * The user wants to run a command with a set and possibly cpumask.
*/ */
if (argc) { if (argc) {
if (Cflag | pflag | rflag | tflag | xflag | jflag) if (Cflag || pflag || tflag || xflag || jflag)
usage(); usage();
if (sflag) { if (sflag) {
if (cpuset_setid(CPU_WHICH_PID, -1, setid)) if (cpuset_setid(CPU_WHICH_PID, -1, setid))
@ -303,9 +306,9 @@ main(int argc, char *argv[])
/* /*
* We're modifying something that presently exists. * We're modifying something that presently exists.
*/ */
if (Cflag && (sflag || rflag || !pflag || tflag || xflag || jflag)) if (Cflag && (jflag || !pflag || sflag || tflag || xflag))
usage(); usage();
if (!lflag && (cflag || rflag)) if (!lflag && cflag)
usage(); usage();
if (!lflag && !(Cflag || sflag)) if (!lflag && !(Cflag || sflag))
usage(); usage();
@ -354,8 +357,9 @@ usage(void)
fprintf(stderr, fprintf(stderr,
" cpuset [-c] [-l cpu-list] -C -p pid\n"); " cpuset [-c] [-l cpu-list] -C -p pid\n");
fprintf(stderr, fprintf(stderr,
" cpuset [-cr] [-l cpu-list] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n"); " cpuset [-c] [-l cpu-list] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n");
fprintf(stderr, fprintf(stderr,
" cpuset [-cgir] [-j jailid | -p pid | -t tid | -s setid | -x irq]\n"); " cpuset -g [-cir] [-d domain | -j jailid | -p pid | -t tid | -s setid |\n"
" -x irq]\n");
exit(1); exit(1);
} }