All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dario Faggioli <dario.faggioli@citrix.com>
To: George Dunlap <george.dunlap@citrix.com>, xen-devel@lists.xenproject.org
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
	Anshul Makkar <anshul.makkar@citrix.com>
Subject: Re: [PATCH v2 3/7] xen: credit: consider tickled pCPUs as busy.
Date: Fri, 7 Apr 2017 14:53:46 +0200	[thread overview]
Message-ID: <1491569626.3287.11.camel@citrix.com> (raw)
In-Reply-To: <90dc30e6-635c-c3b3-548a-5bcb7aefca3d@citrix.com>


[-- Attachment #1.1: Type: text/plain, Size: 4519 bytes --]

On Fri, 2017-04-07 at 11:56 +0100, George Dunlap wrote:
> On 06/04/17 09:16, Dario Faggioli wrote:
> > Currently, it can happen that __runq_tickle(),
> > running on pCPU 2 because vCPU x woke up, decides
> > to tickle pCPU 3, because it's idle. Just after
> > that, but before pCPU 3 manages to schedule and
> > pick up x, either __runq_tickel() or
> > __csched_cpu_pick(), running on pCPU 6, sees that
> > idle pCPUs are 0, 1 and also 3, and for whatever
> > reason it also chooses 3 for waking up (or
> > migrating) vCPU y.
> > 
> > When pCPU 3 goes through the scheduler, it will
> > pick up, say, vCPU x, and y will sit in its
> > runqueue, even if there are idle pCPUs.
> > 
> > Alleviate this by marking a pCPU to be idle
> > right away when tickling it (like, e.g., it happens
> > in Credit2).
> > 
> > Note that this does not eliminate the race. That
> > is not possible without introducing proper locking
> > for the cpumasks the scheduler uses. It significantly
> > reduces the window during which it can happen, though.
> > 
> > Introduce proper locking for the cpumask can, in
> > theory, be done, and may be investigated in future.
> > It is a significant amount of work to do it properly
> > (e.g., avoiding deadlock), and it is likely to adversely
> > affect scalability, and so it may be a path it is just
> > not worth following.
> > 
> > Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
> > ---
> > Cc: George Dunlap <george.dunlap@eu.citrix.com>
> > Cc: Anshul Makkar <anshul.makkar@citrix.com>
> > ---
> >  xen/common/sched_credit.c |   22 +++++++++++++++++++---
> >  1 file changed, 19 insertions(+), 3 deletions(-)
> > 
> > diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c
> > index 5a3f13f..c753089 100644
> > --- a/xen/common/sched_credit.c
> > +++ b/xen/common/sched_credit.c
> > @@ -489,7 +489,17 @@ static inline void __runq_tickle(struct
> > csched_vcpu *new)
> >                  __trace_var(TRC_CSCHED_TICKLE, 1, sizeof(cpu),
> > &cpu);
> >          }
> >  
> > -        /* Send scheduler interrupts to designated CPUs */
> > +        /*
> > +         * Mark the designated CPUs as busy and send them all the
> > scheduler
> > +         * interrupt. We need the for_each_cpu for dealing with
> > the
> > +         * !opt_tickle_one_idle case. We must use
> > cpumask_clear_cpu() and
> > +         * can't use cpumask_andnot(), because prv->idlers needs
> > atomic access.
> > +         *
> > +         * In the default (and most common) case, when
> > opt_rickle_one_idle is
> > +         * true, the loop does only one step, and only one bit is
> > cleared.
> > +         */
> > +        for_each_cpu(cpu, &mask)
> > +            cpumask_clear_cpu(cpu, prv->idlers);
> >          cpumask_raise_softirq(&mask, SCHEDULE_SOFTIRQ);
> >      }
> >      else
> > @@ -985,6 +995,8 @@ csched_vcpu_acct(struct csched_private *prv,
> > unsigned int cpu)
> >              SCHED_VCPU_STAT_CRANK(svc, migrate_r);
> >              SCHED_STAT_CRANK(migrate_running);
> >              set_bit(_VPF_migrating, &current->pause_flags);
> > +            ASSERT(!cpumask_test_cpu(cpu,
> > +                                     CSCHED_PRIV(per_cpu(scheduler
> > , cpu))->idlers));
> 
> What are these about?  Is this just to double-check that the "idler
> accounting" logic is correct?
>
No, raising the SCHEDULE_SOFTIRQ (which is what we do here, right below
the added ASSERT(), and also in the other place where I added another
one) basically means tickling the cpu we raise it for.

Therefore, according to the very purpose of this patch, we should clear
the bit corresponding to the cpu itself in the idler mask. In practise,
that is not necessary, because it (in both cases) that happens to be
cleared already.

The ASSERT()-s are for both making this explicit, and check/enforce it.

I appreciate it's not that clear, though. I'll add comments.

Thanks and Regards,
Dario
-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-04-07 12:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-06  8:16 [PATCH v2 0/7] xen: sched: improve scalability of Credit1, and optimize a bit both Credit1 and Credit2 Dario Faggioli
2017-04-06  8:16 ` [PATCH v2 1/7] xen: credit1: simplify csched_runq_steal() a little bit Dario Faggioli
2017-04-07 10:45   ` George Dunlap
2017-04-07 11:00     ` Dario Faggioli
2017-04-06  8:16 ` [PATCH v2 2/7] xen: credit: (micro) optimize csched_runq_steal() Dario Faggioli
2017-04-07 10:49   ` George Dunlap
2017-04-07 11:01     ` Dario Faggioli
2017-04-06  8:16 ` [PATCH v2 3/7] xen: credit: consider tickled pCPUs as busy Dario Faggioli
2017-04-07 10:56   ` George Dunlap
2017-04-07 12:53     ` Dario Faggioli [this message]
2017-04-06  8:16 ` [PATCH v2 4/7] xen/tools: tracing: add record for credit1 runqueue stealing Dario Faggioli
2017-04-07 11:01   ` George Dunlap
2017-04-07 13:06     ` Dario Faggioli
2017-04-06  8:16 ` [PATCH v2 5/7] xen: credit1: increase efficiency and scalability of load balancing Dario Faggioli
2017-04-07 14:38   ` George Dunlap
2017-04-07 14:49     ` Dario Faggioli
2017-04-07 15:17       ` George Dunlap
2017-04-07 15:26         ` Dario Faggioli
2017-04-07 15:49           ` Dario Faggioli
2017-04-07 16:25             ` Dario Faggioli
2017-04-06  8:16 ` [PATCH v2 6/7] xen: credit1: treat pCPUs more evenly during balancing Dario Faggioli
2017-04-07 14:44   ` George Dunlap
2017-04-06  8:17 ` [PATCH v2 7/7] xen: credit2: avoid cpumask_any() in pick_cpu() Dario Faggioli
2017-04-07 14:48   ` George Dunlap

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=1491569626.3287.11.camel@citrix.com \
    --to=dario.faggioli@citrix.com \
    --cc=anshul.makkar@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=george.dunlap@eu.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.