public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Jens Axboe <axboe@kernel.dk>, Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@redhat.com>,
	dm-devel@redhat.com, "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Jason Wessel <jason.wessel@windriver.com>,
	Daniel Thompson <daniel.thompson@linaro.org>,
	Douglas Anderson <dianders@chromium.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>
Subject: [PATCH 3/6] sched,perf,kvm: Fix preemption condition
Date: Wed, 02 Jun 2021 15:12:28 +0200	[thread overview]
Message-ID: <20210602133040.398289363@infradead.org> (raw)
In-Reply-To: 20210602131225.336600299@infradead.org

When ran from the sched-out path (preempt_notifier or perf_event),
p->state is irrelevant to determine preemption. You can get preempted
with !task_is_running() just fine.

The right indicator for preemption is if the task is still on the
runqueue in the sched-out path.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/events/core.c |    7 +++----
 virt/kvm/kvm_main.c  |    2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8568,13 +8568,12 @@ static void perf_event_switch(struct tas
 		},
 	};
 
-	if (!sched_in && task->state == TASK_RUNNING)
+	if (!sched_in && current->on_rq) {
 		switch_event.event_id.header.misc |=
 				PERF_RECORD_MISC_SWITCH_OUT_PREEMPT;
+	}
 
-	perf_iterate_sb(perf_event_switch_output,
-		       &switch_event,
-		       NULL);
+	perf_iterate_sb(perf_event_switch_output, &switch_event, NULL);
 }
 
 /*
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -4869,7 +4869,7 @@ static void kvm_sched_out(struct preempt
 {
 	struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
 
-	if (current->state == TASK_RUNNING) {
+	if (current->on_rq) {
 		WRITE_ONCE(vcpu->preempted, true);
 		WRITE_ONCE(vcpu->ready, true);
 	}



  parent reply	other threads:[~2021-06-02 13:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-02 13:12 [PATCH 0/6] sched: Cleanup task_struct::state Peter Zijlstra
2021-06-02 13:12 ` [PATCH 1/6] sched: Unbreak wakeups Peter Zijlstra
2021-06-02 13:58   ` Greg Kroah-Hartman
     [not found]   ` <20210602133040.271625424-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2021-06-02 14:47     ` Will Deacon
2021-06-02 19:43   ` Davidlohr Bueso
2021-06-02 13:12 ` [PATCH 2/6] sched: Introduce task_is_running() Peter Zijlstra
2021-06-02 14:59   ` Will Deacon
2021-06-02 16:46     ` Peter Zijlstra
2021-06-02 23:15   ` Davidlohr Bueso
2021-06-02 13:12 ` Peter Zijlstra [this message]
2021-06-02 13:59   ` [PATCH 3/6] sched,perf,kvm: Fix preemption condition Mathieu Desnoyers
2021-06-02 14:10     ` Peter Zijlstra
     [not found]       ` <YLeRVQbXt2hCiO8f-Nxj+rRp3nVydTX5a5knrm8zTDFooKrT+cvkQGrU6aU0@public.gmane.org>
2021-06-02 14:30         ` Mark Rutland
     [not found]   ` <20210602133040.398289363-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2021-06-02 14:15     ` Mathieu Desnoyers
2021-06-02 14:23       ` Peter Zijlstra
2021-06-02 13:12 ` [PATCH 4/6] sched: Add get_current_state() Peter Zijlstra
     [not found]   ` <20210602133040.461908001-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2021-06-02 14:01     ` Mathieu Desnoyers
2021-06-02 14:12       ` Peter Zijlstra
2021-06-02 15:02   ` Will Deacon
2021-06-02 13:12 ` [PATCH 5/6] sched,timer: Use __set_current_state() Peter Zijlstra
     [not found]   ` <20210602133040.524487671-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2021-06-02 15:06     ` Will Deacon
2021-06-02 19:54   ` Davidlohr Bueso
2021-06-03  6:39     ` Peter Zijlstra
2021-06-18 20:42   ` Thomas Gleixner
2021-06-02 13:12 ` [PATCH 6/6] sched: Change task_struct::state Peter Zijlstra
     [not found]   ` <20210602133040.587042016-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2021-06-02 14:06     ` Mathieu Desnoyers
2021-06-02 14:20       ` Peter Zijlstra
2021-06-02 15:10     ` Will Deacon
2021-06-07 10:45   ` Daniel Thompson
     [not found]     ` <20210607104500.sopvslejuoxwzhrs-DWWWtol72k3/PtFMR13I2A@public.gmane.org>
2021-06-07 11:10       ` Peter Zijlstra

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=20210602133040.398289363@infradead.org \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=agk@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=axboe@kernel.dk \
    --cc=balbi@kernel.org \
    --cc=bp@alien8.de \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=daniel.thompson@linaro.org \
    --cc=davem@davemloft.net \
    --cc=dianders@chromium.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=dm-devel@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=hpa@zytor.com \
    --cc=jason.wessel@windriver.com \
    --cc=juri.lelli@redhat.com \
    --cc=kuba@kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=mark.rutland@arm.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=snitzer@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=x86@kernel.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