linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/core: simpler function for sched_exec migration
@ 2016-09-05  6:20 cheng chao
  2016-09-05 13:11 ` Oleg Nesterov
  2016-09-09  1:39 ` [lkp] [sched/core] 3d26b7622f: BUG: unable to handle kernel NULL pointer dereference at 00000001 kernel test robot
  0 siblings, 2 replies; 12+ messages in thread
From: cheng chao @ 2016-09-05  6:20 UTC (permalink / raw)
  To: mingo, oleg, peterz, tj, akpm, chris; +Cc: linux-kernel, cheng chao

when sched_exec needs migration and CONFIG_PREEMPT_NONE=y,
migration_cpu_stop almost does nothing due to
the caller is !task_on_rq_queued().

currently CONFIG_PREEMPT and CONFIG_PREEMPT_VOLUNTARY work well because
the caller keeps task_on_rq_queued():

1. when CONFIG_PREEMPT=y
  stop_one_cpu
  ->cpu_stop_queue_work
    ->spin_unlock_irqrestore (preempt_enable calls __preempt_schedule)

2. when CONFIG_PREEMPT_VOLUNTARY=y
  stop_one_cpu
  ->wait_for_completion
    ->...
      -->might_sleep() (calls _cond_resched()

stop_one_cpu_sync is introduced here to address this problem,more further
it makes more simpler for CONFIG_PREEMPT=y or CONFIG_PREEMPT_VOLUNTARY=y
when sched_exec needs migration.

Signed-off-by: cheng chao <chengchao@kedacom.com>
---
 include/linux/stop_machine.h |  1 +
 kernel/sched/core.c          |  2 +-
 kernel/stop_machine.c        | 21 +++++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h
index 3cc9632..e4e7d42 100644
--- a/include/linux/stop_machine.h
+++ b/include/linux/stop_machine.h
@@ -28,6 +28,7 @@ struct cpu_stop_work {
 };
 
 int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg);
+void stop_one_cpu_sync(unsigned int cpu, cpu_stop_fn_t fn, void *arg);
 int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void *arg);
 bool stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
 			 struct cpu_stop_work *work_buf);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 556cb07..2fd71e6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2958,7 +2958,7 @@ void sched_exec(void)
 		struct migration_arg arg = { p, dest_cpu };
 
 		raw_spin_unlock_irqrestore(&p->pi_lock, flags);
-		stop_one_cpu(task_cpu(p), migration_cpu_stop, &arg);
+		stop_one_cpu_sync(task_cpu(p), migration_cpu_stop, &arg);
 		return;
 	}
 unlock:
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index 4a1ca5f..24f8637 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -130,6 +130,27 @@ int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
 	return done.ret;
 }
 
+/**
+ * the caller keeps task_on_rq_queued, so it's more suitable for
+ * sched_exec on the case when needs migration
+ */
+void stop_one_cpu_sync(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
+{
+	struct cpu_stop_work work = { .fn = fn, .arg = arg, .done = NULL };
+
+	if (!cpu_stop_queue_work(cpu, &work))
+		return;
+
+#if defined(CONFIG_PREEMPT_NONE) || defined(CONFIG_PREEMPT_VOLUNTARY)
+	/*
+	 * CONFIG_PREEMPT doesn't need call schedule here, because
+	 * preempt_enable already does the similar thing when call
+	 * cpu_stop_queue_work
+	 */
+	schedule();
+#endif
+}
+
 /* This controls the threads on each CPU. */
 enum multi_stop_state {
 	/* Dummy starting state for thread. */
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2016-09-09 10:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-05  6:20 [PATCH] sched/core: simpler function for sched_exec migration cheng chao
2016-09-05 13:11 ` Oleg Nesterov
2016-09-06  2:11   ` chengchao
2016-09-06 15:22     ` Oleg Nesterov
2016-09-07  3:22       ` chengchao
2016-09-07 12:35         ` Oleg Nesterov
2016-09-08  2:17           ` chengchao
2016-09-09 10:05           ` Peter Zijlstra
2016-09-09  1:39 ` [lkp] [sched/core] 3d26b7622f: BUG: unable to handle kernel NULL pointer dereference at 00000001 kernel test robot
2016-09-09  2:04   ` chengchao
2016-09-09  2:26     ` Ye Xiaolong
2016-09-09  2:36       ` chengchao

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).