Skip to contentSkip to conversation

MIPS: move idle task creation to work queue

PATCH Superseded [email protected] 2 participants 2 messages Feb 12, 2011 MIPS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: move idle task creation to work queue

From: Maksim Rayskiy <[email protected]>

To avoid forking usertask when creating an idle task, move fork_idle to a work queue.
This is a small improvement to previous commit 467f0b8.

---

Ralf, this is per your suggestion. The code is mostly copy-pasted from arch/x86/kernel/smpboot.c

 arch/mips/kernel/smp.c |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)
arch/mips/kernel/smp.c +26 -6
index 4593916..98bd504 100644
@@ -193,6 +193,21 @@ void __devinit smp_prepare_boot_cpu(void)
  */
 static struct task_struct *cpu_idle_thread[NR_CPUS];
 
+struct create_idle {
+	struct work_struct work;
+	struct task_struct *idle;
+	struct completion done;
+	int cpu;
+};
+
+static void __cpuinit do_fork_idle(struct work_struct *work)
+{
+	struct create_idle *c_idle =
+		container_of(work, struct create_idle, work);
+	c_idle->idle = fork_idle(c_idle->cpu);
+	complete(&c_idle->done);
+}
+
 int __cpuinit __cpu_up(unsigned int cpu)
 {
 	struct task_struct *idle;
@@ -203,16 +218,21 @@ int __cpuinit __cpu_up(unsigned int cpu)
 	 * Linux can schedule processes on this slave.
 	 */
 	if (!cpu_idle_thread[cpu]) {
-		idle = fork_idle(cpu);
-		cpu_idle_thread[cpu] = idle;
+		/* Schedule work item to avoid forking user task.
+		   Ported from x86 */
+		struct create_idle c_idle = {
+			.cpu	= cpu,
+			.done	= COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
+		};
+
+		INIT_WORK_ONSTACK(&c_idle.work, do_fork_idle);
+		schedule_work(&c_idle.work);
+		wait_for_completion(&c_idle.done);
+		idle = cpu_idle_thread[cpu] = c_idle.idle;
 
 		if (IS_ERR(idle))
 			panic(KERN_ERR "Fork failed for CPU %d", cpu);
 
-		if (idle->mm) {
-			mmput(idle->mm);
-			idle->mm = NULL;
-		}
 	} else {
 		idle = cpu_idle_thread[cpu];
 		init_idle(idle, cpu);
Signature · 1 line
1.7.3.2
#1 lore raw

Hello.

Quoted 5 lines · On 12-02-2011 6:22, [email protected] wrote:

From: Maksim Rayskiy <[email protected]>

To avoid forking usertask when creating an idle task, move fork_idle to a work queue.
This is a small improvement to previous commit 467f0b8.

Linus akss to also specify the commit summary in parens.

Quoted 1 line

[...]

Quoted 9 lines
arch/mips/kernel/smp.c +1 -0
index 4593916..98bd504 100644
@@ -193,6 +193,21 @@ void __devinit smp_prepare_boot_cpu(void)
   */
  static struct task_struct *cpu_idle_thread[NR_CPUS];
 
+struct create_idle {

arch/mips/kernel/smp.c void __devinit smp_prepare_boot_cpu(void) · line 206

Quoted 10 lines
arch/mips/kernel/smp.c +10 -0
+	struct work_struct work;
+	struct task_struct *idle;
+	struct completion done;
+	int cpu;
+};
+
+static void __cpuinit do_fork_idle(struct work_struct *work)
+{
+	struct create_idle *c_idle =
+		container_of(work, struct create_idle, work);

Empty line wouldn't hurt here...

Quoted 8 lines
arch/mips/kernel/smp.c +4 -0
+	c_idle->idle = fork_idle(c_idle->cpu);
+	complete(&c_idle->done);
+}
+
  int __cpuinit __cpu_up(unsigned int cpu)
  {
  	struct task_struct *idle;

arch/mips/kernel/smp.c int __cpuinit __cpu_up(unsigned int cpu) · line 222

Quoted 7 lines
arch/mips/kernel/smp.c +2 -2
@@ -203,16 +218,21 @@ int __cpuinit __cpu_up(unsigned int cpu)
  	 * Linux can schedule processes on this slave.
  	 */
  	if (!cpu_idle_thread[cpu]) {
-		idle = fork_idle(cpu);
-		cpu_idle_thread[cpu] = idle;
+		/* Schedule work item to avoid forking user task.
+		   Ported from x86 */

The preferred style of multi-line comments is this:

/*
* bla
* bla
*/

WBR, Sergei