xen-devel.lists.xenproject.org archive mirror
 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: Wei Liu <wei.liu2@citrix.com>
Subject: Re: [PATCH for 4.7 1/4] xen: sched: avoid spuriously re-enabling IRQs in csched2_switch_sched()
Date: Fri, 6 May 2016 15:21:40 +0200	[thread overview]
Message-ID: <1462540900.3355.43.camel@citrix.com> (raw)
In-Reply-To: <572A32BF.5030404@citrix.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 4137 bytes --]

On Wed, 2016-05-04 at 18:34 +0100, George Dunlap wrote:
> On 04/05/16 18:21, Dario Faggioli wrote:
> > 
> > After all, I'm fine with an ASSERT() too, but then I think we
> > should
> > add one to the same effect to csched_switch_sched() too.
> Well an ASSERT() is sort of like a comment, in that if you see
> ASSERT(irqs_disabled()), you know there's no need to save irqs
> because
> they should already disabled.  But it has the advantage that osstest
> will be able to "read" it once we get some proper cpupool tests for
> osstest. :-)
> 
> If we weren't in the feature freeze, I'd definitely favor adding an
> ASSERT to credit1.  As it is, I think either way (adding now or
> waiting
> until the 4.8 development window) should be fine.
> 
Ok, here you go (inline and attached) the patch with ASSERT()-s both in
Credit2 and Credit1 (despite the freeze, I think it's the best thing to
do, see the changelog).

Thanks and Regards,
Dario
--
commit cbabd44e171d0bd2169f1c7100e69a9e48289980
Author: Dario Faggioli <dario.faggioli@citrix.com>
Date:   Tue Apr 26 18:56:56 2016 +0200

    xen: sched: avoid spuriously re-enabling IRQs in csched2_switch_sched()
    
    interrupts are already disabled when calling the hook
    (from schedule_cpu_switch()), so we must use spin_lock()
    and spin_unlock().
    
    Add an ASSERT(), so we will notice if this code and its
    caller get out of sync with respect to disabling interrupts
    (and add one at the same exact occurrence of this pattern
    in Credit1 too)
    
    Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
    ---
    Cc: George Dunlap <george.dunlap@citrix.com>
    Cc: Wei Liu <wei.liu2@citrix.com>
    --
    Changes from v1:
     * add the ASSERT(), as requested by George
     * add the ASSERT in Credit1 too
    --
    For Wei:
     - the Credit2 spin_lock_irq()-->spin_lock() change needs
       to go in, as it fixes a bug;
     - adding the ASSERT was requested during review;
     - adding the ASSERT in Credit1 is not strictly necessary,
       but imptoves code quality and consistency at zero cost
       and risk, so I think we should just go for it now, instead
       of waitign for 4.8 (it's basically like I'm adding a
       comment!).

diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c
index db4d42a..a38a63d 100644
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -615,6 +615,7 @@ csched_switch_sched(struct scheduler *new_ops, unsigned int cpu,
      * schedule_cpu_switch()). It actually may or may not be the 'right'
      * one for this cpu, but that is ok for preventing races.
      */
+    ASSERT(!local_irq_is_enabled());
     spin_lock(&prv->lock);
     init_pdata(prv, pdata, cpu);
     spin_unlock(&prv->lock);
diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c
index f3b62ac..f95e509 100644
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -2238,7 +2238,8 @@ csched2_switch_sched(struct scheduler *new_ops, unsigned int cpu,
      * And owning exactly that one (the lock of the old scheduler of this
      * cpu) is what is necessary to prevent races.
      */
-    spin_lock_irq(&prv->lock);
+    ASSERT(!local_irq_is_enabled());
+    spin_lock(&prv->lock);
 
     idle_vcpu[cpu]->sched_priv = vdata;
 
@@ -2263,7 +2264,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsigned int cpu,
     smp_mb();
     per_cpu(schedule_data, cpu).schedule_lock = &prv->rqd[rqi].lock;
 
-    spin_unlock_irq(&prv->lock);
+    spin_unlock(&prv->lock);
 }
 
 static void
-- 
<<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.1.2: xen-sched-avoid-spuriously-reenable-irqs.patch --]
[-- Type: text/x-patch, Size: 2601 bytes --]

commit cbabd44e171d0bd2169f1c7100e69a9e48289980
Author: Dario Faggioli <dario.faggioli@citrix.com>
Date:   Tue Apr 26 18:56:56 2016 +0200

    xen: sched: avoid spuriously re-enabling IRQs in csched2_switch_sched()
    
    interrupts are already disabled when calling the hook
    (from schedule_cpu_switch()), so we must use spin_lock()
    and spin_unlock().
    
    Add an ASSERT(), so we will notice if this code and its
    caller get out of sync with respect to disabling interrupts
    (and add one at the same exact occurrence of this pattern
    in Credit1 too)
    
    Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
    ---
    Cc: George Dunlap <george.dunlap@citrix.com>
    Cc: Wei Liu <wei.liu2@citrix.com>
    --
    Changes from v1:
     * add the ASSERT(), as requested by George
     * add the ASSERT in Credit1 too
    --
    For Wei:
     - the Credit2 spin_lock_irq()-->spin_lock() change needs
       to go in, as it fixes a bug;
     - adding the ASSERT was requested during review;
     - adding the ASSERT in Credit1 is not strictly necessary,
       but imptoves code quality and consistency at zero cost
       and risk, so I think we should just go for it now, instead
       of waitign for 4.8 (it's basically like I'm adding a
       comment!).

diff --git a/xen/common/sched_credit.c b/xen/common/sched_credit.c
index db4d42a..a38a63d 100644
--- a/xen/common/sched_credit.c
+++ b/xen/common/sched_credit.c
@@ -615,6 +615,7 @@ csched_switch_sched(struct scheduler *new_ops, unsigned int cpu,
      * schedule_cpu_switch()). It actually may or may not be the 'right'
      * one for this cpu, but that is ok for preventing races.
      */
+    ASSERT(!local_irq_is_enabled());
     spin_lock(&prv->lock);
     init_pdata(prv, pdata, cpu);
     spin_unlock(&prv->lock);
diff --git a/xen/common/sched_credit2.c b/xen/common/sched_credit2.c
index f3b62ac..f95e509 100644
--- a/xen/common/sched_credit2.c
+++ b/xen/common/sched_credit2.c
@@ -2238,7 +2238,8 @@ csched2_switch_sched(struct scheduler *new_ops, unsigned int cpu,
      * And owning exactly that one (the lock of the old scheduler of this
      * cpu) is what is necessary to prevent races.
      */
-    spin_lock_irq(&prv->lock);
+    ASSERT(!local_irq_is_enabled());
+    spin_lock(&prv->lock);
 
     idle_vcpu[cpu]->sched_priv = vdata;
 
@@ -2263,7 +2264,7 @@ csched2_switch_sched(struct scheduler *new_ops, unsigned int cpu,
     smp_mb();
     per_cpu(schedule_data, cpu).schedule_lock = &prv->rqd[rqi].lock;
 
-    spin_unlock_irq(&prv->lock);
+    spin_unlock(&prv->lock);
 }
 
 static void

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

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

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

  reply	other threads:[~2016-05-06 13:21 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 [this message]
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
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=1462540900.3355.43.camel@citrix.com \
    --to=dario.faggioli@citrix.com \
    --cc=george.dunlap@citrix.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).