From: George Dunlap <george.dunlap@citrix.com>
To: Dario Faggioli <dario.faggioli@citrix.com>,
xen-devel@lists.xenproject.org
Cc: Tianyang Chen <tiche@seas.upenn.edu>,
Wei Liu <wei.liu2@citrix.com>, Meng Xu <mengxu@cis.upenn.edu>
Subject: Re: [PATCH for 4.7 4/4] xen: adopt .deinit_pdata and improve timer handling
Date: Wed, 4 May 2016 16:51:17 +0100 [thread overview]
Message-ID: <572A1A75.5090706@citrix.com> (raw)
In-Reply-To: <146231201861.25631.15476137738176988146.stgit@Solace.fritz.box>
On 03/05/16 22:46, Dario Faggioli wrote:
> The scheduling hooks API is now used properly, and no
> initialization or de-initialization happen in
> alloc/free_pdata any longer.
>
> In fact, just like it is for Credit2, there is no real
> need for implementing alloc_pdata and free_pdata.
>
> This also made it possible to improve the replenishment
> timer handling logic, such that now the timer is always
> kept on one of the pCPU of the scheduler it's servicing.
> Before this commit, in fact, even if the pCPU where the
> timer happened to be initialized at creation time was
> moved to another cpupool, the timer stayed there,
> potentially inferfearing with the new scheduler of the
* interfering
> pCPU itself.
>
> Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
I don't know much about the logic, so I'll wait for Meng Xu to review it.
-George
> --
> Cc: Meng Xu <mengxu@cis.upenn.edu>
> Cc: George Dunlap <george.dunlap@citrix.com>
> Cc: Tianyang Chen <tiche@seas.upenn.edu>
> Cc: Wei Liu <wei.liu2@citrix.com>
> ---
> xen/common/sched_rt.c | 74 ++++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 55 insertions(+), 19 deletions(-)
>
> diff --git a/xen/common/sched_rt.c b/xen/common/sched_rt.c
> index 673fc92..7f8f411 100644
> --- a/xen/common/sched_rt.c
> +++ b/xen/common/sched_rt.c
> @@ -590,6 +590,10 @@ rt_init(struct scheduler *ops)
> if ( prv == NULL )
> return -ENOMEM;
>
> + prv->repl_timer = xzalloc(struct timer);
> + if ( prv->repl_timer == NULL )
> + return -ENOMEM;
> +
> spin_lock_init(&prv->lock);
> INIT_LIST_HEAD(&prv->sdom);
> INIT_LIST_HEAD(&prv->runq);
> @@ -600,12 +604,6 @@ rt_init(struct scheduler *ops)
>
> ops->sched_data = prv;
>
> - /*
> - * The timer initialization will happen later when
> - * the first pcpu is added to this pool in alloc_pdata.
> - */
> - prv->repl_timer = NULL;
> -
> return 0;
> }
>
> @@ -614,7 +612,8 @@ rt_deinit(struct scheduler *ops)
> {
> struct rt_private *prv = rt_priv(ops);
>
> - kill_timer(prv->repl_timer);
> + ASSERT(prv->repl_timer->status == TIMER_STATUS_invalid ||
> + prv->repl_timer->status == TIMER_STATUS_killed);
> xfree(prv->repl_timer);
>
> ops->sched_data = NULL;
> @@ -632,9 +631,19 @@ rt_init_pdata(const struct scheduler *ops, void *pdata, int cpu)
> spinlock_t *old_lock;
> unsigned long flags;
>
> - /* Move the scheduler lock to our global runqueue lock. */
> old_lock = pcpu_schedule_lock_irqsave(cpu, &flags);
>
> + /*
> + * TIMER_STATUS_invalid means we are the first cpu that sees the timer
> + * allocated but not initialized, and so it's up to us to initialize it.
> + */
> + if ( prv->repl_timer->status == TIMER_STATUS_invalid )
> + {
> + init_timer(prv->repl_timer, repl_timer_handler, (void*) ops, cpu);
> + dprintk(XENLOG_DEBUG, "RTDS: timer initialized on cpu %u\n", cpu);
> + }
> +
> + /* Move the scheduler lock to our global runqueue lock. */
> per_cpu(schedule_data, cpu).schedule_lock = &prv->lock;
>
> /* _Not_ pcpu_schedule_unlock(): per_cpu().schedule_lock changed! */
> @@ -659,6 +668,20 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int cpu,
> */
> ASSERT(per_cpu(schedule_data, cpu).schedule_lock != &prv->lock);
>
> + /*
> + * If we are the absolute first cpu being switched toward this
> + * scheduler (in which case we'll see TIMER_STATUS_invalid), or the
> + * first one that is added back to the cpupool that had all its cpus
> + * removed (in which case we'll see TIMER_STATUS_killed), it's our
> + * job to (re)initialize the timer.
> + */
> + if ( prv->repl_timer->status == TIMER_STATUS_invalid ||
> + prv->repl_timer->status == TIMER_STATUS_killed )
> + {
> + init_timer(prv->repl_timer, repl_timer_handler, (void*) new_ops, cpu);
> + dprintk(XENLOG_DEBUG, "RTDS: timer initialized on cpu %u\n", cpu);
> + }
> +
> idle_vcpu[cpu]->sched_priv = vdata;
> per_cpu(scheduler, cpu) = new_ops;
> per_cpu(schedule_data, cpu).sched_priv = NULL; /* no pdata */
> @@ -672,23 +695,36 @@ rt_switch_sched(struct scheduler *new_ops, unsigned int cpu,
> per_cpu(schedule_data, cpu).schedule_lock = &prv->lock;
> }
>
> -static void *
> -rt_alloc_pdata(const struct scheduler *ops, int cpu)
> +static void
> +rt_deinit_pdata(const struct scheduler *ops, void *pcpu, int cpu)
> {
> + unsigned long flags;
> struct rt_private *prv = rt_priv(ops);
>
> - if ( prv->repl_timer == NULL )
> - {
> - /* Allocate the timer on the first cpu of this pool. */
> - prv->repl_timer = xzalloc(struct timer);
> + spin_lock_irqsave(&prv->lock, flags);
>
> - if ( prv->repl_timer == NULL )
> - return ERR_PTR(-ENOMEM);
> + if ( prv->repl_timer->cpu == cpu )
> + {
> + struct cpupool *c = per_cpu(cpupool, cpu);
> + unsigned int new_cpu = cpumask_cycle(cpu, cpupool_online_cpumask(c));
>
> - init_timer(prv->repl_timer, repl_timer_handler, (void *)ops, cpu);
> + /*
> + * Make sure the timer run on one of the cpus that are still available
> + * to this scheduler. If there aren't any left, it means it's the time
> + * to just kill it.
> + */
> + if ( new_cpu >= nr_cpu_ids )
> + {
> + kill_timer(prv->repl_timer);
> + dprintk(XENLOG_DEBUG, "RTDS: timer killed on cpu %d\n", cpu);
> + }
> + else
> + {
> + migrate_timer(prv->repl_timer, new_cpu);
> + }
> }
>
> - return NULL;
> + spin_unlock_irqrestore(&prv->lock, flags);
> }
>
> static void *
> @@ -1433,9 +1469,9 @@ static const struct scheduler sched_rtds_def = {
> .dump_settings = rt_dump,
> .init = rt_init,
> .deinit = rt_deinit,
> - .alloc_pdata = rt_alloc_pdata,
> .init_pdata = rt_init_pdata,
> .switch_sched = rt_switch_sched,
> + .deinit_pdata = rt_deinit_pdata,
> .alloc_domdata = rt_alloc_domdata,
> .free_domdata = rt_free_domdata,
> .init_domain = rt_dom_init,
>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-05-04 15:51 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-03 21:46 [PATCH for 4.7 0/4] Assorted scheduling fixes Dario Faggioli
2016-05-03 21:46 ` [PATCH for 4.7 1/4] xen: sched: avoid spuriously re-enabling IRQs in csched2_switch_sched() Dario Faggioli
2016-05-04 8:48 ` Jan Beulich
2016-05-04 9:08 ` Dario Faggioli
2016-05-04 15:11 ` George Dunlap
2016-05-04 15:58 ` Dario Faggioli
2016-05-04 17:05 ` George Dunlap
2016-05-04 17:21 ` Dario Faggioli
2016-05-04 17:34 ` George Dunlap
2016-05-06 13:21 ` Dario Faggioli
2016-05-06 13:48 ` Wei Liu
2016-05-09 14:42 ` George Dunlap
2016-05-03 21:46 ` [PATCH for 4.7 2/4] xen: sched: fix killing an uninitialized timer in free_pdata Dario Faggioli
2016-05-04 15:25 ` George Dunlap
2016-05-03 21:46 ` [PATCH for 4.7 3/4] xen: credit2: fix 2 (minor) issues in load tracking logic Dario Faggioli
2016-05-04 15:38 ` George Dunlap
2016-05-03 21:46 ` [PATCH for 4.7 4/4] xen: adopt .deinit_pdata and improve timer handling Dario Faggioli
2016-05-04 15:51 ` George Dunlap [this message]
2016-05-04 15:53 ` Meng Xu
2016-05-06 23:05 ` Dario Faggioli
2016-05-07 21:19 ` Meng Xu
2016-05-08 3:12 ` Meng Xu
2016-05-09 8:07 ` Juergen Gross
2016-05-09 13:22 ` Dario Faggioli
2016-05-09 14:08 ` Meng Xu
2016-05-09 14:52 ` Dario Faggioli
2016-05-09 14:58 ` Meng Xu
2016-05-09 14:46 ` George Dunlap
2016-05-09 14:58 ` Wei Liu
2016-05-09 15:35 ` George Dunlap
2016-05-04 1:26 ` [PATCH for 4.7 0/4] Assorted scheduling fixes Konrad Rzeszutek Wilk
2016-05-04 9:06 ` Dario Faggioli
2016-05-05 12:00 ` Julien Grall
2016-05-05 12:38 ` Dario Faggioli
2016-05-04 15:53 ` George Dunlap
2016-05-04 16:04 ` Wei Liu
2016-05-07 21:23 ` Meng Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=572A1A75.5090706@citrix.com \
--to=george.dunlap@citrix.com \
--cc=dario.faggioli@citrix.com \
--cc=mengxu@cis.upenn.edu \
--cc=tiche@seas.upenn.edu \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.