Skip to content

Commit 3ba9f93

Browse files
author
Peter Zijlstra
committed
sched,perf,kvm: Fix preemption condition
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> Acked-by: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/r/20210611082838.285099381@infradead.org
1 parent b03fbd4 commit 3ba9f93

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

kernel/events/core.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8682,13 +8682,12 @@ static void perf_event_switch(struct task_struct *task,
86828682
},
86838683
};
86848684

8685-
if (!sched_in && task->state == TASK_RUNNING)
8685+
if (!sched_in && task->on_rq) {
86868686
switch_event.event_id.header.misc |=
86878687
PERF_RECORD_MISC_SWITCH_OUT_PREEMPT;
8688+
}
86888689

8689-
perf_iterate_sb(perf_event_switch_output,
8690-
&switch_event,
8691-
NULL);
8690+
perf_iterate_sb(perf_event_switch_output, &switch_event, NULL);
86928691
}
86938692

86948693
/*

virt/kvm/kvm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5025,7 +5025,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
50255025
{
50265026
struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
50275027

5028-
if (current->state == TASK_RUNNING) {
5028+
if (current->on_rq) {
50295029
WRITE_ONCE(vcpu->preempted, true);
50305030
WRITE_ONCE(vcpu->ready, true);
50315031
}

0 commit comments

Comments
 (0)