From: Suresh Siddha <suresh.b.siddha@intel.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-arch@vger.kernel.org, Rusty Russell <rusty@rustcorp.com.au>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Ingo Molnar <mingo@kernel.org>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
Tejun Heo <tj@kernel.org>, David Rientjes <rientjes@google.com>,
venki@google.com
Subject: Re: [patch 00/18] SMP: Boot and CPU hotplug refactoring - Part 1
Date: Thu, 03 May 2012 16:42:32 -0700 [thread overview]
Message-ID: <1336088552.28674.457.camel@sbsiddha-desk.sc.intel.com> (raw)
In-Reply-To: <alpine.LFD.2.02.1205031137270.6271@ionos>
On Thu, 2012-05-03 at 11:41 +0200, Thomas Gleixner wrote:
> On Fri, 20 Apr 2012, Suresh Siddha wrote:
> > Also, do we really need the workqueue/kthreadd based allocation? Just
> > like the percpu areas getting allocated for each possible cpu during
> > boot, shouldn't we extend this to the per-cpu idle threads too? So
> > something like the appended should be ok to?
>
> The idea is correct, there are just a few problems :)
>
> > Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
> > ---
> > diff --git a/kernel/cpu.c b/kernel/cpu.c
> > index 05c46ba..a5144ab 100644
> > --- a/kernel/cpu.c
> > +++ b/kernel/cpu.c
> > @@ -303,10 +303,6 @@ static int __cpuinit _cpu_up(unsigned int cpu, int tasks_frozen)
> >
> > cpu_hotplug_begin();
> >
> > - ret = smpboot_prepare(cpu);
> > - if (ret)
> > - goto out;
> > -
>
> If we failed to allocate an idle_thread for this cpu in smp_init()
> then we unconditionally call __cpu_up() with a NULL pointer. That
> might surprise the arch code :)
>
> Aside of that, we now miss to reinitialize the idle thread. We call
> init_idle() once when we allocate the thread, but not after a cpu
> offline operation. That might leave stuff in weird state.
Second one slipped through and wasn't intentional. Anyways your
modifications look good.
While I am here, noticed that we could do 'node' aware idle task struct
allocations. Appended the patch for this. Thanks.
---
From: Suresh Siddha <suresh.b.siddha@intel.com>
Subject: idle: allocate percpu idle taks from the local node
Use the arch specific early_cpu_to_node() to find out the local node for a
given 'cpu' and use that info while allocating memory for that cpu's idle task.
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
---
arch/x86/include/asm/topology.h | 8 +++++---
arch/x86/mm/numa.c | 2 +-
include/asm-generic/topology.h | 4 ++++
include/linux/kthread.h | 9 ++++++++-
kernel/fork.c | 9 ++++++---
kernel/kthread.c | 8 +++-----
6 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index b9676ae..bdbcee2 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -57,12 +57,12 @@ DECLARE_EARLY_PER_CPU(int, x86_cpu_to_node_map);
extern int __cpu_to_node(int cpu);
#define cpu_to_node __cpu_to_node
-extern int early_cpu_to_node(int cpu);
+extern int __early_cpu_to_node(int cpu);
#else /* !CONFIG_DEBUG_PER_CPU_MAPS */
/* Same function but used if called before per_cpu areas are setup */
-static inline int early_cpu_to_node(int cpu)
+static inline int __early_cpu_to_node(int cpu)
{
return early_per_cpu(x86_cpu_to_node_map, cpu);
}
@@ -144,7 +144,7 @@ static inline int numa_node_id(void)
*/
#define numa_node_id numa_node_id
-static inline int early_cpu_to_node(int cpu)
+static inline int __early_cpu_to_node(int cpu)
{
return 0;
}
@@ -153,6 +153,8 @@ static inline void setup_node_to_cpumask_map(void) { }
#endif
+#define early_cpu_to_node(cpu) __early_cpu_to_node(cpu)
+
#include <asm-generic/topology.h>
extern const struct cpumask *cpu_coregroup_mask(int cpu);
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 19d3fa0..142738e 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -734,7 +734,7 @@ EXPORT_SYMBOL(__cpu_to_node);
* Same function as cpu_to_node() but used if called before the
* per_cpu areas are setup.
*/
-int early_cpu_to_node(int cpu)
+int __early_cpu_to_node(int cpu)
{
if (early_per_cpu_ptr(x86_cpu_to_node_map))
return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu];
diff --git a/include/asm-generic/topology.h b/include/asm-generic/topology.h
index fc824e2..9ace6da 100644
--- a/include/asm-generic/topology.h
+++ b/include/asm-generic/topology.h
@@ -73,4 +73,8 @@
#endif /* !CONFIG_NUMA || !CONFIG_HAVE_MEMORYLESS_NODES */
+#ifndef early_cpu_to_node
+#define early_cpu_to_node(cpu) ((void)(cpu), -1)
+#endif
+
#endif /* _ASM_GENERIC_TOPOLOGY_H */
diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 0714b24..c1f05e3 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -40,7 +40,7 @@ void *kthread_data(struct task_struct *k);
int kthreadd(void *unused);
extern struct task_struct *kthreadd_task;
-extern int tsk_fork_get_node(struct task_struct *tsk);
+extern int tsk_fork_get_node(struct task_struct *tsk, int idle_tsk);
/*
* Simple work processor based on kthread.
@@ -131,4 +131,11 @@ bool queue_kthread_work(struct kthread_worker *worker,
void flush_kthread_work(struct kthread_work *work);
void flush_kthread_worker(struct kthread_worker *worker);
+static inline void set_fork_pref_node(int node)
+{
+#ifdef CONFIG_NUMA
+ current->pref_node_fork = node;
+#endif
+}
+
#endif /* _LINUX_KTHREAD_H */
diff --git a/kernel/fork.c b/kernel/fork.c
index ca9a384..108d566 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -253,12 +253,13 @@ int __attribute__((weak)) arch_dup_task_struct(struct task_struct *dst,
return 0;
}
-static struct task_struct *dup_task_struct(struct task_struct *orig)
+static struct task_struct *dup_task_struct(struct task_struct *orig,
+ int idle_tsk)
{
struct task_struct *tsk;
struct thread_info *ti;
unsigned long *stackend;
- int node = tsk_fork_get_node(orig);
+ int node = tsk_fork_get_node(orig, idle_tsk);
int err;
prepare_to_copy(orig);
@@ -1165,7 +1166,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
goto fork_out;
retval = -ENOMEM;
- p = dup_task_struct(current);
+ p = dup_task_struct(current, pid == &init_struct_pid);
if (!p)
goto fork_out;
@@ -1531,6 +1532,8 @@ struct task_struct * __cpuinit fork_idle(int cpu)
struct task_struct *task;
struct pt_regs regs;
+ set_fork_pref_node(early_cpu_to_node(cpu));
+
task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL,
&init_struct_pid, 0);
if (!IS_ERR(task)) {
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 3d3de63..3d74ab1 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -125,10 +125,10 @@ static int kthread(void *_create)
}
/* called from do_fork() to get node information for about to be created task */
-int tsk_fork_get_node(struct task_struct *tsk)
+int tsk_fork_get_node(struct task_struct *tsk, int idle_tsk)
{
#ifdef CONFIG_NUMA
- if (tsk == kthreadd_task)
+ if (tsk == kthreadd_task || idle_tsk)
return tsk->pref_node_fork;
#endif
return numa_node_id();
@@ -138,9 +138,7 @@ static void create_kthread(struct kthread_create_info *create)
{
int pid;
-#ifdef CONFIG_NUMA
- current->pref_node_fork = create->node;
-#endif
+ set_fork_pref_node(create->node);
/* We want our own signal handler (we take no signals by default). */
pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
if (pid < 0) {
next prev parent reply other threads:[~2012-05-03 23:39 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-20 13:05 [patch 00/18] SMP: Boot and CPU hotplug refactoring - Part 1 Thomas Gleixner
2012-04-20 13:05 ` [patch 01/18] m32r: Remove pointless function prototypes Thomas Gleixner
2012-04-20 13:05 ` [patch 02/18] smp: Add task_struct argument to __cpu_up() Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-23 7:58 ` Jesper Nilsson
2012-04-23 7:58 ` Jesper Nilsson
2012-04-20 13:05 ` [patch 03/18] smp: Add generic smpboot facility Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-20 20:07 ` Yinghai Lu
2012-04-20 20:07 ` Yinghai Lu
2012-04-21 2:07 ` Stephen Rothwell
2012-04-21 2:07 ` Stephen Rothwell
2012-04-20 13:05 ` [patch 04/18] smp: Provide generic idle thread allocation Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-20 16:21 ` Sam Ravnborg
2012-04-20 16:21 ` Sam Ravnborg
2012-04-20 18:55 ` Thomas Gleixner
2012-04-20 18:55 ` Thomas Gleixner
2012-04-21 2:20 ` Stephen Rothwell
2012-04-21 2:20 ` Stephen Rothwell
2012-04-21 2:25 ` Frank Rowand
2012-04-21 2:25 ` Frank Rowand
2012-04-20 13:05 ` [patch 05/18] x86: Add task_struct argument to smp_ops.cpu_up Thomas Gleixner
2012-04-20 13:05 ` [patch 06/18] x86: Use generic idle thread allocation Thomas Gleixner
2012-04-20 13:05 ` [patch 07/18] powerpc: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-20 13:05 ` [patch 08/18] ia64: " Thomas Gleixner
2012-04-20 13:05 ` [patch 09/18] arm: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-20 13:05 ` [patch 11/18] hexagon: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-24 16:47 ` Richard Kuo
2012-04-24 16:47 ` Richard Kuo
2012-04-20 13:05 ` [patch 10/18] mips: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-20 13:05 ` [patch 12/18] s390: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-23 7:09 ` Martin Schwidefsky
2012-04-23 7:09 ` Martin Schwidefsky
2012-04-20 13:05 ` [patch 13/18] blackfin: " Thomas Gleixner
2012-04-20 13:05 ` [patch 14/18] cris: " Thomas Gleixner
2012-04-23 7:57 ` Jesper Nilsson
2012-04-23 7:57 ` Jesper Nilsson
2012-04-20 13:05 ` [patch 15/18] sh: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-21 3:18 ` Paul Mundt
2012-04-20 13:05 ` [patch 16/18] alpha: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-20 13:05 ` [patch 17/18] parisc: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-20 13:05 ` [patch 18/18] sparc: " Thomas Gleixner
2012-04-20 13:05 ` Thomas Gleixner
2012-04-22 19:52 ` David Miller
2012-04-20 13:16 ` [patch 00/18] SMP: Boot and CPU hotplug refactoring - Part 1 Thomas Gleixner
2012-04-20 13:21 ` Peter Zijlstra
2012-04-20 13:47 ` Thomas Gleixner
2012-04-21 0:08 ` Suresh Siddha
2012-05-03 9:41 ` Thomas Gleixner
2012-05-03 9:41 ` Thomas Gleixner
2012-05-03 23:42 ` Suresh Siddha [this message]
2012-04-20 15:42 ` Tejun Heo
2012-04-20 15:49 ` Peter Zijlstra
2012-04-20 15:56 ` Thomas Gleixner
2012-04-20 13:56 ` Srivatsa S. Bhat
2012-04-20 14:18 ` Thomas Gleixner
2012-04-24 18:44 ` Konrad Rzeszutek Wilk
2012-05-21 1:42 ` Rusty Russell
2012-05-21 8:25 ` Thomas Gleixner
2012-05-21 8:25 ` Thomas Gleixner
2012-05-22 0:53 ` Rusty Russell
2012-04-20 14:06 ` richard -rw- weinberger
2012-04-20 14:06 ` richard -rw- weinberger
2012-04-20 14:19 ` Thomas Gleixner
2012-04-20 14:27 ` James Bottomley
2012-04-20 17:55 ` Paul E. McKenney
2012-04-20 23:11 ` Venki Pallipadi
2012-04-21 1:04 ` Frank Rowand
2012-04-21 1:55 ` Frank Rowand
2012-04-22 21:01 ` Chris Metcalf
2012-04-22 21:01 ` Chris Metcalf
2012-04-30 8:05 ` Santosh Shilimkar
2012-04-30 8:05 ` Santosh Shilimkar
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=1336088552.28674.457.camel@sbsiddha-desk.sc.intel.com \
--to=suresh.b.siddha@intel.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=rusty@rustcorp.com.au \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=venki@google.com \
/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 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).