static __initdata unsigned int dom0_nr_pxms;
static __initdata unsigned int dom0_pxms[MAX_NUMNODES] =
{ [0 ... MAX_NUMNODES - 1] = ~0 };
-static __initdata bool dom0_affinity_relaxed;
+bool __initdata dom0_affinity_relaxed;
static int __init parse_dom0_nodes(const char *s)
{
}
custom_param("dom0_nodes", parse_dom0_nodes);
-static cpumask_t __initdata dom0_cpus;
-
-struct vcpu *__init dom0_setup_vcpu(struct domain *d,
- unsigned int vcpu_id,
- unsigned int prev_cpu)
-{
- unsigned int cpu = cpumask_cycle(prev_cpu, &dom0_cpus);
- struct vcpu *v = vcpu_create(d, vcpu_id, cpu);
-
- if ( v )
- {
- if ( pv_shim )
- {
- sched_set_affinity(v, cpumask_of(vcpu_id), cpumask_of(vcpu_id));
- }
- else
- {
- if ( !opt_dom0_vcpus_pin && !dom0_affinity_relaxed )
- sched_set_affinity(v, &dom0_cpus, NULL);
- sched_set_affinity(v, NULL, &dom0_cpus);
- }
- }
-
- return v;
-}
-
+cpumask_t __initdata dom0_cpus;
static nodemask_t __initdata dom0_nodes;
unsigned int __init dom0_max_vcpus(void)
dom0->node_affinity = dom0_nodes;
dom0->auto_node_affinity = !dom0_nr_pxms;
- return dom0_setup_vcpu(dom0, 0,
- cpumask_last(&dom0_cpus) /* so it wraps around to first pcpu */);
+ return vcpu_create(dom0, 0);
}
#ifdef CONFIG_SHADOW_PAGING
#include <xsm/xsm.h>
#include <xen/err.h>
+#ifdef CONFIG_XEN_GUEST
+#include <asm/guest.h>
+#else
+#define pv_shim false
+#endif
+
/* opt_sched: scheduler - default to configured value */
static char __initdata opt_sched[10] = CONFIG_SCHED_DEFAULT;
string_param("sched", opt_sched);
static struct scheduler __read_mostly ops;
+static void sched_set_affinity(
+ struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft);
+
static spinlock_t *
sched_idle_switch_sched(struct scheduler *new_ops, unsigned int cpu,
void *pdata, void *vdata)
return NULL;
}
-int sched_init_vcpu(struct vcpu *v, unsigned int processor)
+static unsigned int sched_select_initial_cpu(const struct vcpu *v)
+{
+ const struct domain *d = v->domain;
+ nodeid_t node;
+ spinlock_t *lock;
+ unsigned long flags;
+ unsigned int cpu_ret, cpu = smp_processor_id();
+ cpumask_t *cpus = cpumask_scratch_cpu(cpu);
+
+ lock = pcpu_schedule_lock_irqsave(cpu, &flags);
+ cpumask_clear(cpus);
+ for_each_node_mask ( node, d->node_affinity )
+ cpumask_or(cpus, cpus, &node_to_cpumask(node));
+ cpumask_and(cpus, cpus, cpupool_domain_cpumask(d));
+ if ( cpumask_empty(cpus) )
+ cpumask_copy(cpus, cpupool_domain_cpumask(d));
+
+ if ( v->vcpu_id == 0 )
+ cpu_ret = cpumask_first(cpus);
+ else
+ {
+ /* We can rely on previous vcpu being available. */
+ ASSERT(!is_idle_domain(d));
+
+ cpu_ret = cpumask_cycle(d->vcpu[v->vcpu_id - 1]->processor, cpus);
+ }
+
+ pcpu_schedule_unlock_irqrestore(lock, flags, cpu);
+
+ return cpu_ret;
+}
+
+int sched_init_vcpu(struct vcpu *v)
{
struct domain *d = v->domain;
struct sched_unit *unit;
+ unsigned int processor;
if ( (unit = sched_alloc_unit(v)) == NULL )
return 1;
+ if ( is_idle_domain(d) )
+ processor = v->vcpu_id;
+ else
+ processor = sched_select_initial_cpu(v);
+
sched_set_res(unit, get_sched_res(processor));
/* Initialise the per-vcpu timers. */
* domain-0 VCPUs, are pinned onto their respective physical CPUs.
*/
if ( is_idle_domain(d) || (is_hardware_domain(d) && opt_dom0_vcpus_pin) )
- sched_set_affinity(v, cpumask_of(processor), &cpumask_all);
+ sched_set_affinity(unit, cpumask_of(processor), &cpumask_all);
else
- sched_set_affinity(v, &cpumask_all, &cpumask_all);
+ sched_set_affinity(unit, &cpumask_all, &cpumask_all);
/* Idle VCPUs are scheduled immediately, so don't put them in runqueue. */
if ( is_idle_domain(d) )
lock = unit_schedule_lock_irq(v->sched_unit);
- sched_set_affinity(v, &cpumask_all, &cpumask_all);
+ sched_set_affinity(v->sched_unit, &cpumask_all, &cpumask_all);
sched_set_res(v->sched_unit, get_sched_res(new_p));
/*
{
if ( v->affinity_broken )
{
- sched_set_affinity(v, unit->cpu_hard_affinity_saved, NULL);
+ sched_set_affinity(unit, unit->cpu_hard_affinity_saved, NULL);
v->affinity_broken = 0;
cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
cpupool_domain_cpumask(d));
if ( cpumask_empty(cpumask_scratch_cpu(cpu)) )
{
printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v);
- sched_set_affinity(v, &cpumask_all, NULL);
+ sched_set_affinity(unit, &cpumask_all, NULL);
cpumask_and(cpumask_scratch_cpu(cpu), unit->cpu_hard_affinity,
cpupool_domain_cpumask(d));
}
printk(XENLOG_DEBUG "Breaking affinity for %pv\n", v);
- sched_set_affinity(v, &cpumask_all, NULL);
+ sched_set_affinity(unit, &cpumask_all, NULL);
}
if ( v->processor != cpu )
* adjust_affinity hook may want to modify the vCPU state. However, when the
* vCPU is being initialized (either for dom0 or domU) there is no risk of
* races, and it's fine to not take the look (we're talking about
- * dom0_setup_vcpu() an sched_init_vcpu()).
+ * sched_setup_dom0_vcpus() an sched_init_vcpu()).
*/
-void sched_set_affinity(
- struct vcpu *v, const cpumask_t *hard, const cpumask_t *soft)
+static void sched_set_affinity(
+ struct sched_unit *unit, const cpumask_t *hard, const cpumask_t *soft)
{
- struct sched_unit *unit = v->sched_unit;
-
- sched_adjust_affinity(dom_scheduler(v->domain), unit, hard, soft);
+ sched_adjust_affinity(dom_scheduler(unit->domain), unit, hard, soft);
if ( hard )
cpumask_copy(unit->cpu_hard_affinity, hard);
*/
if ( which == unit->cpu_hard_affinity )
{
- sched_set_affinity(v, affinity, NULL);
+ sched_set_affinity(unit, affinity, NULL);
}
else
{
ASSERT(which == unit->cpu_soft_affinity);
- sched_set_affinity(v, NULL, affinity);
+ sched_set_affinity(unit, NULL, affinity);
}
vcpu_migrate_start(v);
}
v->affinity_broken &= ~reason;
}
if ( !ret && !v->affinity_broken )
- sched_set_affinity(v, unit->cpu_hard_affinity_saved, NULL);
+ sched_set_affinity(unit, unit->cpu_hard_affinity_saved, NULL);
}
else if ( cpu < nr_cpu_ids )
{
{
cpumask_copy(unit->cpu_hard_affinity_saved,
unit->cpu_hard_affinity);
- sched_set_affinity(v, cpumask_of(cpu), NULL);
+ sched_set_affinity(unit, cpumask_of(cpu), NULL);
}
v->affinity_broken |= reason;
ret = 0;
return 0;
if ( idle_vcpu[cpu] == NULL )
- vcpu_create(idle_vcpu[0]->domain, cpu, cpu);
+ vcpu_create(idle_vcpu[0]->domain, cpu);
else
idle_vcpu[cpu]->sched_unit->res = sr;
BUG_ON(nr_cpu_ids > ARRAY_SIZE(idle_vcpu));
idle_domain->vcpu = idle_vcpu;
idle_domain->max_vcpus = nr_cpu_ids;
- if ( vcpu_create(idle_domain, 0, 0) == NULL )
+ if ( vcpu_create(idle_domain, 0) == NULL )
BUG();
get_sched_res(0)->curr = idle_vcpu[0]->sched_unit;
}
schedule();
}
+#ifdef CONFIG_X86
+void __init sched_setup_dom0_vcpus(struct domain *d)
+{
+ unsigned int i;
+ struct sched_unit *unit;
+
+ for ( i = 1; i < d->max_vcpus; i++ )
+ vcpu_create(d, i);
+
+ for_each_sched_unit ( d, unit )
+ {
+ unsigned int id = unit->unit_id;
+
+ if ( pv_shim )
+ sched_set_affinity(unit, cpumask_of(id), cpumask_of(id));
+ else
+ {
+ if ( !opt_dom0_vcpus_pin && !dom0_affinity_relaxed )
+ sched_set_affinity(unit, &dom0_cpus, NULL);
+ sched_set_affinity(unit, NULL, &dom0_cpus);
+ }
+ }
+
+ domain_update_node_affinity(d);
+}
+#endif
+
#ifdef CONFIG_COMPAT
#include "compat/schedule.c"
#endif