summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorjeff <jeff@FreeBSD.org>2008-03-02 07:58:42 +0000
committerjeff <jeff@FreeBSD.org>2008-03-02 07:58:42 +0000
commitad2a31513f336da73b206794695829f59113b3a7 (patch)
treea49a50ce8694ae981e503de20b9650bb0f5a1776 /sys/kern
parent0a56287482dbdc42be0a66082c61cf783dd56d5f (diff)
downloadFreeBSD-src-ad2a31513f336da73b206794695829f59113b3a7.zip
FreeBSD-src-ad2a31513f336da73b206794695829f59113b3a7.tar.gz
- Remove the old smp cpu topology specification with a new, more flexible
tree structure that encodes the level of cache sharing and other properties. - Provide several convenience functions for creating one and two level cpu trees as well as a default flat topology. The system now always has some topology. - On i386 and amd64 create a seperate level in the hierarchy for HTT and multi-core cpus. This will allow the scheduler to intelligently load balance non-uniform cores. Presently we don't detect what level of the cache hierarchy is shared at each level in the topology. - Add a mechanism for testing common topologies that have more information than the MD code is able to provide via the kern.smp.topology tunable. This should be considered a debugging tool only and not a stable api. Sponsored by: Nokia
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/sched_ule.c65
-rw-r--r--sys/kern/subr_smp.c202
2 files changed, 189 insertions, 78 deletions
diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
index 4445b05..d17cd58 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -243,7 +243,6 @@ static int tryself = 1;
static int steal_htt = 1;
static int steal_idle = 1;
static int steal_thresh = 2;
-static int topology = 0;
/*
* One thread queue per processor.
@@ -1212,43 +1211,6 @@ tdg_add(struct tdq_group *tdg, struct tdq *tdq)
}
static void
-sched_setup_topology(void)
-{
- struct tdq_group *tdg;
- struct cpu_group *cg;
- int balance_groups;
- struct tdq *tdq;
- int i;
- int j;
-
- topology = 1;
- balance_groups = 0;
- for (i = 0; i < smp_topology->ct_count; i++) {
- cg = &smp_topology->ct_group[i];
- tdg = &tdq_groups[i];
- /*
- * Initialize the group.
- */
- tdg_setup(tdg);
- /*
- * Find all of the group members and add them.
- */
- for (j = 0; j < MAXCPU; j++) {
- if ((cg->cg_mask & (1 << j)) != 0) {
- tdq = TDQ_CPU(j);
- tdq_setup(tdq);
- tdg_add(tdg, tdq);
- }
- }
- if (tdg->tdg_cpus > 1)
- balance_groups = 1;
- }
- tdg_maxid = smp_topology->ct_count - 1;
- if (balance_groups)
- sched_balance_groups();
-}
-
-static void
sched_setup_smp(void)
{
struct tdq_group *tdg;
@@ -1271,25 +1233,6 @@ sched_setup_smp(void)
}
tdg_maxid = cpus - 1;
}
-
-/*
- * Fake a topology with one group containing all CPUs.
- */
-static void
-sched_fake_topo(void)
-{
-#ifdef SCHED_FAKE_TOPOLOGY
- static struct cpu_top top;
- static struct cpu_group group;
-
- top.ct_count = 1;
- top.ct_group = &group;
- group.cg_mask = all_cpus;
- group.cg_count = mp_ncpus;
- group.cg_children = 0;
- smp_topology = &top;
-#endif
-}
#endif
/*
@@ -1303,15 +1246,11 @@ sched_setup(void *dummy)
tdq = TDQ_SELF();
#ifdef SMP
- sched_fake_topo();
/*
* Setup tdqs based on a topology configuration or vanilla SMP based
* on mp_maxid.
*/
- if (smp_topology == NULL)
- sched_setup_smp();
- else
- sched_setup_topology();
+ sched_setup_smp();
balance_tdq = tdq;
sched_balance();
#else
@@ -2692,8 +2631,6 @@ SYSCTL_INT(_kern_sched, OID_AUTO, steal_idle, CTLFLAG_RW, &steal_idle, 0,
"Attempts to steal work from other cores before idling");
SYSCTL_INT(_kern_sched, OID_AUTO, steal_thresh, CTLFLAG_RW, &steal_thresh, 0,
"Minimum load on remote cpu before we'll steal");
-SYSCTL_INT(_kern_sched, OID_AUTO, topology, CTLFLAG_RD, &topology, 0,
- "True when a topology has been specified by the MD code.");
#endif
/* ps compat. All cpu percentages from ULE are weighted. */
diff --git a/sys/kern/subr_smp.c b/sys/kern/subr_smp.c
index fa20e62..9c30a4a 100644
--- a/sys/kern/subr_smp.c
+++ b/sys/kern/subr_smp.c
@@ -68,7 +68,6 @@ int mp_ncpus;
/* export this for libkvm consumers. */
int mp_maxcpus = MAXCPU;
-struct cpu_top *smp_topology;
volatile int smp_started;
u_int mp_maxid;
@@ -90,6 +89,11 @@ int smp_cpus = 1; /* how many cpu's running */
SYSCTL_INT(_kern_smp, OID_AUTO, cpus, CTLFLAG_RD, &smp_cpus, 0,
"Number of CPUs online");
+int smp_topology = 0; /* Which topology we're using. */
+SYSCTL_INT(_kern_smp, OID_AUTO, topology, CTLFLAG_RD, &smp_topology, 0,
+ "Topology override setting; 0 is default provided by hardware.");
+TUNABLE_INT("kern.smp.topology", &smp_topology);
+
#ifdef SMP
/* Enable forwarding of a signal to a process running on a different CPU */
static int forward_signal_enabled = 1;
@@ -385,22 +389,177 @@ smp_rendezvous(void (* setup_func)(void *),
/* release lock */
mtx_unlock_spin(&smp_ipi_mtx);
}
-#else /* !SMP */
-/*
- * Provide dummy SMP support for UP kernels. Modules that need to use SMP
- * APIs will still work using this dummy support.
- */
-static void
-mp_setvariables_for_up(void *dummy)
+static struct cpu_group group[MAXCPU];
+
+struct cpu_group *
+smp_topo(void)
{
- mp_ncpus = 1;
- mp_maxid = PCPU_GET(cpuid);
- all_cpus = PCPU_GET(cpumask);
- KASSERT(PCPU_GET(cpuid) == 0, ("UP must have a CPU ID of zero"));
+ struct cpu_group *top;
+
+ /*
+ * Check for a fake topology request for debugging purposes.
+ */
+ switch (smp_topology) {
+ case 1:
+ /* Dual core with no sharing. */
+ top = smp_topo_1level(CG_SHARE_NONE, 2, 0);
+ break;
+ case 3:
+ /* Dual core with shared L2. */
+ top = smp_topo_1level(CG_SHARE_L2, 2, 0);
+ break;
+ case 4:
+ /* quad core, shared l3 among each package, private l2. */
+ top = smp_topo_1level(CG_SHARE_L3, 4, 0);
+ break;
+ case 5:
+ /* quad core, 2 dualcore parts on each package share l2. */
+ top = smp_topo_2level(CG_SHARE_NONE, 2, CG_SHARE_L2, 2, 0);
+ break;
+ case 6:
+ /* Single-core 2xHTT */
+ top = smp_topo_1level(CG_SHARE_L1, 2, CG_FLAG_HTT);
+ break;
+ case 7:
+ /* quad core with a shared l3, 8 threads sharing L2. */
+ top = smp_topo_2level(CG_SHARE_L3, 4, CG_SHARE_L2, 8,
+ CG_FLAG_THREAD);
+ break;
+ default:
+ /* Default, ask the system what it wants. */
+ top = cpu_topo();
+ break;
+ }
+ /*
+ * Verify the returned topology.
+ */
+ if (top->cg_count != mp_ncpus)
+ panic("Built bad topology at %p. CPU count %d != %d",
+ top, top->cg_count, mp_ncpus);
+ if (top->cg_mask != all_cpus)
+ panic("Built bad topology at %p. CPU mask 0x%X != 0x%X",
+ top, top->cg_mask, all_cpus);
+ return (top);
}
-SYSINIT(cpu_mp_setvariables, SI_SUB_TUNABLES, SI_ORDER_FIRST,
- mp_setvariables_for_up, NULL)
+
+struct cpu_group *
+smp_topo_none(void)
+{
+ struct cpu_group *top;
+
+ top = &group[0];
+ top->cg_parent = NULL;
+ top->cg_child = NULL;
+ top->cg_mask = (1 << mp_ncpus) - 1;
+ top->cg_count = mp_ncpus;
+ top->cg_children = 0;
+ top->cg_level = CG_SHARE_NONE;
+ top->cg_flags = 0;
+
+ return (top);
+}
+
+static int
+smp_topo_addleaf(struct cpu_group *parent, struct cpu_group *child, int share,
+ int count, int flags, int start)
+{
+ cpumask_t mask;
+ int i;
+
+ for (mask = 0, i = 0; i < count; i++, start++)
+ mask |= (1 << start);
+ child->cg_parent = parent;
+ child->cg_child = NULL;
+ child->cg_children = 0;
+ child->cg_level = share;
+ child->cg_count = count;
+ child->cg_flags = flags;
+ child->cg_mask = mask;
+ parent->cg_children++;
+ for (; parent != NULL; parent = parent->cg_parent) {
+ if ((parent->cg_mask & child->cg_mask) != 0)
+ panic("Duplicate children in %p. mask 0x%X child 0x%X",
+ parent, parent->cg_mask, child->cg_mask);
+ parent->cg_mask |= child->cg_mask;
+ parent->cg_count += child->cg_count;
+ }
+
+ return (start);
+}
+
+struct cpu_group *
+smp_topo_1level(int share, int count, int flags)
+{
+ struct cpu_group *child;
+ struct cpu_group *top;
+ int packages;
+ int cpu;
+ int i;
+
+ cpu = 0;
+ top = &group[0];
+ packages = mp_ncpus / count;
+ top->cg_child = child = &group[1];
+ top->cg_level = CG_SHARE_NONE;
+ for (i = 0; i < packages; i++, child++)
+ cpu = smp_topo_addleaf(top, child, share, count, flags, cpu);
+ return (top);
+}
+
+struct cpu_group *
+smp_topo_2level(int l2share, int l2count, int l1share, int l1count,
+ int l1flags)
+{
+ struct cpu_group *top;
+ struct cpu_group *l1g;
+ struct cpu_group *l2g;
+ int cpu;
+ int i;
+ int j;
+
+ cpu = 0;
+ top = &group[0];
+ l2g = &group[1];
+ top->cg_child = l2g;
+ top->cg_level = CG_SHARE_NONE;
+ top->cg_children = mp_ncpus / (l2count * l1count);
+ l1g = l2g + top->cg_children;
+ for (i = 0; i < top->cg_children; i++, l2g++) {
+ l2g->cg_parent = top;
+ l2g->cg_child = l1g;
+ l2g->cg_level = l2share;
+ for (j = 0; j < l2count; j++, l1g++)
+ cpu = smp_topo_addleaf(l2g, l1g, l1share, l1count,
+ l1flags, cpu);
+ }
+ return (top);
+}
+
+
+struct cpu_group *
+smp_topo_find(struct cpu_group *top, int cpu)
+{
+ struct cpu_group *cg;
+ cpumask_t mask;
+ int children;
+ int i;
+
+ mask = (1 << cpu);
+ cg = top;
+ for (;;) {
+ if ((cg->cg_mask & mask) == 0)
+ return (NULL);
+ if (cg->cg_children == 0)
+ return (cg);
+ children = cg->cg_children;
+ for (i = 0, cg = cg->cg_child; i < children; cg++, i++)
+ if ((cg->cg_mask & mask) != 0)
+ break;
+ }
+ return (NULL);
+}
+#else /* !SMP */
void
smp_rendezvous(void (*setup_func)(void *),
@@ -416,4 +575,19 @@ smp_rendezvous(void (*setup_func)(void *),
if (teardown_func != NULL)
teardown_func(arg);
}
+
+/*
+ * Provide dummy SMP support for UP kernels. Modules that need to use SMP
+ * APIs will still work using this dummy support.
+ */
+static void
+mp_setvariables_for_up(void *dummy)
+{
+ mp_ncpus = 1;
+ mp_maxid = PCPU_GET(cpuid);
+ all_cpus = PCPU_GET(cpumask);
+ KASSERT(PCPU_GET(cpuid) == 0, ("UP must have a CPU ID of zero"));
+}
+SYSINIT(cpu_mp_setvariables, SI_SUB_TUNABLES, SI_ORDER_FIRST,
+ mp_setvariables_for_up, NULL)
#endif /* SMP */
OpenPOWER on IntegriCloud