From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH 4/4] sched: Use the auto-generated list of schedulers Date: Fri, 18 Dec 2015 09:12:04 +0000 Message-ID: <5673CDE4.5000606@citrix.com> References: <1450385974-12732-1-git-send-email-jonathan.creekmore@gmail.com> <1450385974-12732-5-git-send-email-jonathan.creekmore@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a9r57-0007KX-Jq for xen-devel@lists.xenproject.org; Fri, 18 Dec 2015 09:12:09 +0000 In-Reply-To: <1450385974-12732-5-git-send-email-jonathan.creekmore@gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jonathan Creekmore , xen-devel@lists.xenproject.org Cc: George Dunlap , Dario Faggioli List-Id: xen-devel@lists.xenproject.org On 17/12/2015 20:59, Jonathan Creekmore wrote: > Instead of having a manually-curated list of schedulers, use the array > that was auto-generated simply by compiling in the scheduler files as > the sole source of truth of the available schedulers. > > CC: George Dunlap > CC: Dario Faggioli > Signed-off-by: Jonathan Creekmore > --- > xen/common/schedule.c | 24 +++++++----------------- > xen/include/xen/sched-if.h | 5 ----- > 2 files changed, 7 insertions(+), 22 deletions(-) > > diff --git a/xen/common/schedule.c b/xen/common/schedule.c > index 2f98a48..efbd67d 100644 > --- a/xen/common/schedule.c > +++ b/xen/common/schedule.c > @@ -64,20 +64,10 @@ static void poll_timer_fn(void *data); > DEFINE_PER_CPU(struct schedule_data, schedule_data); > DEFINE_PER_CPU(struct scheduler *, scheduler); > > -static const struct scheduler *schedulers[] = { > -#ifdef CONFIG_SCHED_CREDIT > - &sched_credit_def, > -#endif > -#ifdef CONFIG_SCHED_CREDIT2 > - &sched_credit2_def, > -#endif > -#ifdef CONFIG_SCHED_ARINC653 > - &sched_arinc653_def, > -#endif > -#ifdef CONFIG_SCHED_RTDS > - &sched_rtds_def, > -#endif > -}; > +extern const struct scheduler *__schedulers_start[], *__schedulers_end[]; > +#define NUM_SCHEDULERS (((uintptr_t)__schedulers_end-(uintptr_t)__schedulers_start) \ > + / sizeof(struct scheduler *)) > +static const struct scheduler **schedulers = __schedulers_start; You should be able to play some tricks with getting the linker to set a size of a variable it creates, which would hopefully avoid some of this complexity. > > static struct scheduler __read_mostly ops; > > @@ -1468,7 +1458,7 @@ void __init scheduler_init(void) > > open_softirq(SCHEDULE_SOFTIRQ, schedule); > > - for ( i = 0; i < ARRAY_SIZE(schedulers); i++ ) > + for ( i = 0; i < NUM_SCHEDULERS; i++) > { > if ( schedulers[i]->global_init && schedulers[i]->global_init() < 0 ) > schedulers[i] = NULL; > @@ -1479,7 +1469,7 @@ void __init scheduler_init(void) > if ( !ops.name ) > { > printk("Could not find scheduler: %s\n", opt_sched); > - for ( i = 0; i < ARRAY_SIZE(schedulers); i++ ) > + for ( i = 0; i < NUM_SCHEDULERS; i++ ) > if ( schedulers[i] ) > { > ops = *schedulers[i]; > @@ -1599,7 +1589,7 @@ struct scheduler *scheduler_alloc(unsigned int sched_id, int *perr) > int i; > struct scheduler *sched; > > - for ( i = 0; i < ARRAY_SIZE(schedulers); i++ ) > + for ( i = 0; i < NUM_SCHEDULERS; i++ ) > if ( schedulers[i] && schedulers[i]->sched_id == sched_id ) > goto found; > *perr = -ENOENT; > diff --git a/xen/include/xen/sched-if.h b/xen/include/xen/sched-if.h > index 9c6e0f5..66dc9c8 100644 > --- a/xen/include/xen/sched-if.h > +++ b/xen/include/xen/sched-if.h > @@ -165,11 +165,6 @@ struct scheduler { > void (*tick_resume) (const struct scheduler *, unsigned int); > }; > > -extern const struct scheduler sched_credit_def; > -extern const struct scheduler sched_credit2_def; > -extern const struct scheduler sched_arinc653_def; > -extern const struct scheduler sched_rtds_def; > - With these changes, you can make the structures themselves static, which would be a nice tidyup. ~Andrew > #define REGISTER_SCHEDULER(x) static const struct scheduler *x##_entry \ > __used_section(".data.schedulers") = &x; >