All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Zhao Chenhui <chenhui.zhao@freescale.com>
Cc: linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	tglx@linutronix.de, leoli@freescale.com, scottwood@freescale.com,
	Priyanka.Jain@freescale.com
Subject: Re: [PATCH][RFC] kernel/cpu: do not change the cpus_allowed of the current task when unplugging cpus
Date: Fri, 14 Jun 2013 17:29:17 +0200	[thread overview]
Message-ID: <20130614152917.GA8597@linutronix.de> (raw)
In-Reply-To: <20130609095942.GA8548@localhost.localdomain>

* Zhao Chenhui | 2013-06-09 17:59:42 [+0800]:

>No. _cpu_down() on mainline do not change the cpus_allowed.
My bad.

>The problem is that the task which turned off cpu2 (for instance)
>can not run on cpu2 again after cpu2 is turned on, because cpu2 has been
>removed from the cpus_allowed of the task.
>
>The task can put himself back on cpu2 throuhg the system call,
>but I think applications should not do this work and do not care which cpu
>it is running on in most time.

The mask needs to be changed because you may not be on the CPU while it
is going down. What do you think about:

Subject: [PATCH] kernel/hotplug: restore original cpu mask oncpu/down

If a task which is allowed to run only on CPU X puts CPU Y down then it
will be allowed on all CPUs but the on CPU Y after it comes back from
kernel. This patch ensures that we don't lose the initial setting unless
the CPU the task is running is going down.

Cc: stable-rt@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/cpu.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 3acf17d..f5ad8e1 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -545,6 +545,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 		.hcpu = hcpu,
 	};
 	cpumask_var_t cpumask;
+	cpumask_var_t cpumask_org;
 
 	if (num_online_cpus() == 1)
 		return -EBUSY;
@@ -555,6 +556,12 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 	/* Move the downtaker off the unplug cpu */
 	if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
 		return -ENOMEM;
+	if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL))  {
+		free_cpumask_var(cpumask);
+		return -ENOMEM;
+	}
+
+	cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
 	cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
 	set_cpus_allowed_ptr(current, cpumask);
 	free_cpumask_var(cpumask);
@@ -563,7 +570,8 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 	if (mycpu == cpu) {
 		printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
 		migrate_enable();
-		return -EBUSY;
+		err = -EBUSY;
+		goto restore_cpus;
 	}
 
 	cpu_hotplug_begin();
@@ -622,6 +630,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 	cpu_hotplug_done();
 	if (!err)
 		cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
+restore_cpus:
+	set_cpus_allowed_ptr(current, cpumask_org);
+	free_cpumask_var(cpumask_org);
 	return err;
 }
 
-- 
1.7.10.4


>
>-Chenhui

Sebastian

  reply	other threads:[~2013-06-14 15:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-16 10:17 [PATCH][RFC] kernel/cpu: do not change the cpus_allowed of the current task when unplugging cpus Zhao Chenhui
2013-06-07  9:05 ` Sebastian Andrzej Siewior
2013-06-09  9:59   ` Zhao Chenhui
2013-06-14 15:29     ` Sebastian Andrzej Siewior [this message]
2013-06-17 10:48       ` Zhao Chenhui
2013-06-17 11:49         ` Sebastian Andrzej Siewior

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=20130614152917.GA8597@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=Priyanka.Jain@freescale.com \
    --cc=chenhui.zhao@freescale.com \
    --cc=leoli@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=scottwood@freescale.com \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.