All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dario Faggioli <dfaggioli@suse.com>
To: Juergen Gross <jgross@suse.com>,
	George Dunlap <George.Dunlap@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Andrew Cooper <Andrew.Cooper3@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>,
	Xen-devel <xen-devel@lists.xenproject.org>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH 2/2] xen: sched: we never get into context_switch() with prev==next
Date: Fri, 26 Apr 2019 14:58:36 +0200	[thread overview]
Message-ID: <7ef54ef1a0d86efd4499e53789434641955c03db.camel@suse.com> (raw)
In-Reply-To: <14e58f7e-305b-9ed9-9217-2b0b489521c7@suse.com>


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

On Tue, 2019-04-23 at 11:56 +0200, Juergen Gross wrote:
> On 23/04/2019 11:50, George Dunlap wrote:
> > 
> > > On Apr 20, 2019, at 4:24 PM, Dario Faggioli <dfaggioli@suse.com>
> > > wrote:
> > > 
> > > We can, therefore, get rid of all the `if`-s testing prev and
> > > next being
> > > different, trading them with an ASSERT() (on ARM, the ASSERT()
> > > was even
> > > already there!)
> > 
> > Keeping in mind that ASSERT() is merely a debugging aid: suppose
> > that testing didn’t discover this, and a bug that violated this
> > assumption slipped into production.  Would the patched code DTRT?
> 
> The unpatched code would already do something wrong: it would clear
> v->is_running (through context_saved()) for the running vcpu,
> potentially leading to all sorts of wrong decisions in the scheduling
> code later.
> 
Exactly! Which basically means it's quite likely that, if we ever get
past the call to:

  return continue_running(prev)  (in schedule.c:schedule())

with next==prev, things will go very wrong, without the `if`-s that
this patch is killing being of much help.

And, yes, this is (micro) optimizing, but it's also an attempt to
improve the code, making it clear, for people paying with
context_switch(), that they don't have to deal with the special case of
prev and next being equal, while right now they may think they do.

Even if we decide to keep the `if`-s, I'd still like to have the ASSERT
() (and a comment explaining why we have both the assertion and the
checks).

I haven't done archaeology to find out when it was (if ever) that it
was ok to call context_switch() with next==prev. I can, and see about
adding what I find in the changelog, if you (George) think it could be
interesting.

Regards
-- 
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)


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

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

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

WARNING: multiple messages have this Message-ID (diff)
From: Dario Faggioli <dfaggioli@suse.com>
To: Juergen Gross <jgross@suse.com>,
	George Dunlap <George.Dunlap@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Andrew Cooper <Andrew.Cooper3@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>,
	Xen-devel <xen-devel@lists.xenproject.org>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH 2/2] xen: sched: we never get into context_switch() with prev==next
Date: Fri, 26 Apr 2019 14:58:36 +0200	[thread overview]
Message-ID: <7ef54ef1a0d86efd4499e53789434641955c03db.camel@suse.com> (raw)
Message-ID: <20190426125836.BtVBjbFTQyT66z5MFgngZu0v-PZGW_ry4UHiDJey9Wg@z> (raw)
In-Reply-To: <14e58f7e-305b-9ed9-9217-2b0b489521c7@suse.com>


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

On Tue, 2019-04-23 at 11:56 +0200, Juergen Gross wrote:
> On 23/04/2019 11:50, George Dunlap wrote:
> > 
> > > On Apr 20, 2019, at 4:24 PM, Dario Faggioli <dfaggioli@suse.com>
> > > wrote:
> > > 
> > > We can, therefore, get rid of all the `if`-s testing prev and
> > > next being
> > > different, trading them with an ASSERT() (on ARM, the ASSERT()
> > > was even
> > > already there!)
> > 
> > Keeping in mind that ASSERT() is merely a debugging aid: suppose
> > that testing didn’t discover this, and a bug that violated this
> > assumption slipped into production.  Would the patched code DTRT?
> 
> The unpatched code would already do something wrong: it would clear
> v->is_running (through context_saved()) for the running vcpu,
> potentially leading to all sorts of wrong decisions in the scheduling
> code later.
> 
Exactly! Which basically means it's quite likely that, if we ever get
past the call to:

  return continue_running(prev)  (in schedule.c:schedule())

with next==prev, things will go very wrong, without the `if`-s that
this patch is killing being of much help.

And, yes, this is (micro) optimizing, but it's also an attempt to
improve the code, making it clear, for people paying with
context_switch(), that they don't have to deal with the special case of
prev and next being equal, while right now they may think they do.

Even if we decide to keep the `if`-s, I'd still like to have the ASSERT
() (and a comment explaining why we have both the assertion and the
checks).

I haven't done archaeology to find out when it was (if ever) that it
was ok to call context_switch() with next==prev. I can, and see about
adding what I find in the changelog, if you (George) think it could be
interesting.

Regards
-- 
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)


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

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

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

  reply	other threads:[~2019-04-26 12:59 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-20 15:24 [PATCH 0/2] xen: sched/Credit2: small and trivial improvements Dario Faggioli
2019-04-20 15:24 ` [Xen-devel] " Dario Faggioli
2019-04-20 15:24 ` [PATCH 1/2] xen: credit2: avoid using cpumask_weight() in hot-paths Dario Faggioli
2019-04-20 15:24   ` [Xen-devel] " Dario Faggioli
2019-04-23  9:44   ` Andrew Cooper
2019-04-23  9:44     ` [Xen-devel] " Andrew Cooper
2019-04-26 13:01     ` Dario Faggioli
2019-04-26 13:01       ` [Xen-devel] " Dario Faggioli
2019-04-23  9:48   ` Andrii Anisov
2019-04-23  9:48     ` [Xen-devel] " Andrii Anisov
2019-04-20 15:24 ` [PATCH 2/2] xen: sched: we never get into context_switch() with prev==next Dario Faggioli
2019-04-20 15:24   ` [Xen-devel] " Dario Faggioli
2019-04-21 17:08   ` Julien Grall
2019-04-21 17:08     ` [Xen-devel] " Julien Grall
2019-04-23  9:13   ` Andrii Anisov
2019-04-23  9:13     ` [Xen-devel] " Andrii Anisov
2019-04-23  9:47     ` Andrew Cooper
2019-04-23  9:47       ` [Xen-devel] " Andrew Cooper
2019-04-23 10:33       ` Andrii Anisov
2019-04-23 10:33         ` [Xen-devel] " Andrii Anisov
2019-04-26 15:13     ` Dario Faggioli
2019-04-26 15:13       ` [Xen-devel] " Dario Faggioli
2019-04-26 16:22       ` Julien Grall
2019-04-26 16:22         ` [Xen-devel] " Julien Grall
2019-04-26 16:26         ` Andrew Cooper
2019-04-26 16:26           ` [Xen-devel] " Andrew Cooper
2019-05-08 10:03       ` Andrii Anisov
2019-05-08 10:03         ` [Xen-devel] " Andrii Anisov
2019-04-23  9:50   ` George Dunlap
2019-04-23  9:50     ` [Xen-devel] " George Dunlap
2019-04-23  9:56     ` Juergen Gross
2019-04-23  9:56       ` [Xen-devel] " Juergen Gross
2019-04-26 12:58       ` Dario Faggioli [this message]
2019-04-26 12:58         ` Dario Faggioli
2019-04-23 10:00   ` Andrew Cooper
2019-04-23 10:00     ` [Xen-devel] " Andrew Cooper

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=7ef54ef1a0d86efd4499e53789434641955c03db.camel@suse.com \
    --to=dfaggioli@suse.com \
    --cc=Andrew.Cooper3@citrix.com \
    --cc=George.Dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=julien.grall@arm.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --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.