xen/sched: split scheduler vtable from struct scheduler
PATCH v3 1/1 xen/sched: split scheduler vtable from struct scheduler
struct scheduler currently serves two purposes: it is the static vtable a scheduler backend defines (name, opt_name, sched_id, and all its function pointers), and it is also the per-cpupool runtime object scheduler_alloc() allocates. Being the same type forces scheduler_alloc() to memcpy() the whole vtable into a fresh allocation per cpupool, duplicating identical function pointers across every cpupool using the same scheduler.
Split the vtable out into its own type, struct sched_ops, so it can be shared by every cpupool using a given scheduler instead of copied per cpupool. struct scheduler is left holding only what is actually per-instance: a pointer to the shared sched_ops, plus sched_data and cpupool. scheduler_alloc() now stores a pointer to the matching sched_ops instance instead of copying its fields and uses xzalloc() to zero-initialize the struct. Every accessor in private.h is updated from s->field to s->ops->field to match.
Every in-tree scheduler backend (credit, credit2, rtds, arinc653, null) is converted from struct scheduler to struct sched_ops. Also drop the generic comment in arinc653.c.
A handful of call sites elsewhere read a scheduler's name, opt_name or sched_id directly and are updated to go through ->ops as well.
---
v3:
* fixed whitespace and blank-lines
* mentioned the xzalloc() change and the arinc653 comment removal
* fixed the overlong lines.
--- xen/common/sched/arinc653.c | 9 +--- xen/common/sched/core.c | 51 +++++++++++-------- xen/common/sched/cpupool.c | 7 +-- xen/common/sched/credit.c | 3 +- xen/common/sched/credit2.c | 3 +- xen/common/sched/null.c | 3 +- xen/common/sched/private.h | 98 +++++++++++++++++++------------------ xen/common/sched/rt.c | 3 +- 8 files changed, 90 insertions(+), 87 deletions(-)
xen/common/sched/arinc653.c +1 -8
@@ -702,17 +702,10 @@ a653sched_adjust_global(const struct scheduler *ops, }#endif /* CONFIG_SYSCTL */ -/** -* This structure defines our scheduler for Xen. -* The entries tell Xen where to find our scheduler-specific -* callback functions. -* The symbol must be visible to the rest of Xen at link time. -*/ -static const struct scheduler sched_arinc653_def = { +static const struct sched_ops sched_arinc653_def = { .name ="ARINC 653 Scheduler" , .opt_name ="arinc653" , .sched_id =XEN_SCHEDULER_ARINC653 , - .sched_data =NULL , .init = a653sched_init, .deinit = a653sched_deinit,
xen/common/sched/core.c +30 -21
144 lines not on this page · raw message
xen/common/sched/cpupool.c +4 -3
@@ -338,7 +338,8 @@ static struct cpupool *cpupool_create(unsigned int poolid,spin_unlock (&cpupool_lock);debugtrace_printk ("Created cpupool %u with scheduler %s (%s)\n" , - c->cpupool_id, c->sched->name, c->sched->opt_name); + c->cpupool_id, c->sched->ops->name, + c->sched->ops->opt_name);return c;
@@ -862,7 +863,7 @@ int cpupool_do_sysctl(struct xen_sysctl_cpupool_op *op)if ( c ==NULL )break ; op->cpupool_id = c->cpupool_id; - op->sched_id = c->sched->sched_id; + op->sched_id = c->sched->ops->sched_id; op->n_dom = c->n_dom; ret =cpumask_to_xenctl_bitmap (&op->cpumap, c->cpu_valid);cpupool_put (c);
@@ -1294,7 +1295,7 @@ struct cpupool *__init cpupool_create_pool(unsigned int pool_id, int sched_id)struct cpupool *pool;if ( sched_id <0 ) - sched_id =scheduler_get_default ()->sched_id; + sched_id =scheduler_get_default ()->ops->sched_id; pool =cpupool_create (pool_id, sched_id);
xen/common/sched/credit.c +1 -2
@@ -2277,11 +2277,10 @@ csched_deinit(struct scheduler *ops) } } -static const struct scheduler sched_credit_def = { +static const struct sched_ops sched_credit_def = { .name ="SMP Credit Scheduler" , .opt_name ="credit" , .sched_id =XEN_SCHEDULER_CREDIT , - .sched_data =NULL , .global_init = csched_global_init,
xen/common/sched/credit2.c +1 -2
@@ -4230,11 +4230,10 @@ csched2_deinit(struct scheduler *ops)xfree (prv); } -static const struct scheduler sched_credit2_def = { +static const struct sched_ops sched_credit2_def = { .name ="SMP Credit Scheduler rev2" , .opt_name ="credit2" , .sched_id =XEN_SCHEDULER_CREDIT2 , - .sched_data =NULL , .global_init = csched2_global_init,
xen/common/sched/null.c +1 -2
@@ -1037,11 +1037,10 @@ static void cf_check null_dump(const struct scheduler *ops)spin_unlock_irqrestore (&prv->lock, flags); } -static const struct scheduler sched_null_def = { +static const struct sched_ops sched_null_def = { .name ="null Scheduler" , .opt_name ="null" , .sched_id =XEN_SCHEDULER_NULL , - .sched_data =NULL , .init = null_init, .deinit = null_deinit,
xen/common/sched/private.h +51 -47
233 lines not on this page · raw message
xen/common/sched/rt.c +1 -2
@@ -1617,11 +1617,10 @@ static void cf_check repl_timer_handler(void *data)spin_unlock_irq (&prv->lock); } -static const struct scheduler sched_rtds_def = { +static const struct sched_ops sched_rtds_def = { .name ="SMP RTDS Scheduler" , .opt_name ="rtds" , .sched_id =XEN_SCHEDULER_RTDS , - .sched_data =NULL , .dump_cpu_state = rt_dump_pcpu, .dump_settings = rt_dump,
Signature · 1 line
2.34.1