Skip to content

sched: fix the PREEMPT_ACTIVE check in __trace_sched_switch_state()

Oleg Nesterov lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest1 patch 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1sched: fix the PREEMPT_ACTIVE check in __trace_sched_switch_state()include/trace/events/sched.h+1 -12 replies
1/1sched: make finish_task_switch() return struct rq *kernel/sched/core.c+15 -224 replies

Reviews trailers per patch

None of the 2 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchKirill Tkhai
SeriesR-b
1/1
1/1

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/1] sched: fix the PREEMPT_ACTIVE check in __trace_sched_switch_state()

And note that another caller of task_preempt_count(), set_cpu(), is fine but it doesn't really need this helper.

And afaics we do not need ->saved_preempt_count at all, the trivial patch below makes it unnecessary, we can kill it and all its users.

Not only this will simplify the code, this will make (well, almost) the per-cpu preempt counter arch-agnostic.

Or I missed something?

Do you think this makes sense? If yes, I'll try to make the patches.

Oleg.
---

OBVIOUSLY INCOMPLETE, BREAKS EVERYTHING EXCEPT x86. Just to explain what I mean.

(this depends on !__ARCH_WANT_UNLOCKED_CTXSW, but it was already removed
and x86 doesn't use it anyway).

kernel/sched/core.c +6 -1
@@ -2279,6 +2279,7 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)
 {
 	struct rq *rq = this_rq();
 
+	preempt_count_set(PREEMPT_DISABLED);
 	finish_task_switch(rq, prev);
 
 	/*
@@ -2304,6 +2305,7 @@ context_switch(struct rq *rq, struct task_struct *prev,
 	       struct task_struct *next)
 {
 	struct mm_struct *mm, *oldmm;
+	int pc;
 
 	prepare_task_switch(rq, prev, next);
 
@@ -2338,10 +2340,13 @@ context_switch(struct rq *rq, struct task_struct *prev,
 #endif
 
 	context_tracking_task_switch(prev, next);
+
 	/* Here we just switch the register state and the stack. */
+	pc = this_cpu_read(__preempt_count);
 	switch_to(prev, next, prev);
-
 	barrier();
+	preempt_count_set(pc);
+
 	/*
 	 * this_rq must be evaluated again because prev may have moved
 	 * CPUs since it called schedule(), thus the 'rq' on its stack