Re: [PATCH 09/40] autonuma: introduce kthread_bind_node()

From: Andrea Arcangeli
Date: Wed Jul 04 2012 - 19:17:42 EST


On Sat, Jun 30, 2012 at 12:50:14AM -0400, Konrad Rzeszutek Wilk wrote:
> On Thu, Jun 28, 2012 at 02:55:49PM +0200, Andrea Arcangeli wrote:
> > This function makes it easy to bind the per-node knuma_migrated
> > threads to their respective NUMA nodes. Those threads take memory from
> > the other nodes (in round robin with a incoming queue for each remote
> > node) and they move that memory to their local node.
> >
> > Signed-off-by: Andrea Arcangeli <aarcange@xxxxxxxxxx>
> > ---
> > include/linux/kthread.h | 1 +
> > include/linux/sched.h | 2 +-
> > kernel/kthread.c | 23 +++++++++++++++++++++++
> > 3 files changed, 25 insertions(+), 1 deletions(-)
> >
> > diff --git a/include/linux/kthread.h b/include/linux/kthread.h
> > index 0714b24..e733f97 100644
> > --- a/include/linux/kthread.h
> > +++ b/include/linux/kthread.h
> > @@ -33,6 +33,7 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
> > })
> >
> > void kthread_bind(struct task_struct *k, unsigned int cpu);
> > +void kthread_bind_node(struct task_struct *p, int nid);
> > int kthread_stop(struct task_struct *k);
> > int kthread_should_stop(void);
> > bool kthread_freezable_should_stop(bool *was_frozen);
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index 4059c0f..699324c 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -1792,7 +1792,7 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
> > #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */
> > #define PF_SPREAD_PAGE 0x01000000 /* Spread page cache over cpuset */
> > #define PF_SPREAD_SLAB 0x02000000 /* Spread some slab caches over cpuset */
> > -#define PF_THREAD_BOUND 0x04000000 /* Thread bound to specific cpu */
> > +#define PF_THREAD_BOUND 0x04000000 /* Thread bound to specific cpus */
> > #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */
> > #define PF_MEMPOLICY 0x10000000 /* Non-default NUMA mempolicy */
> > #define PF_MUTEX_TESTER 0x20000000 /* Thread belongs to the rt mutex tester */
> > diff --git a/kernel/kthread.c b/kernel/kthread.c
> > index 3d3de63..48b36f9 100644
> > --- a/kernel/kthread.c
> > +++ b/kernel/kthread.c
> > @@ -234,6 +234,29 @@ void kthread_bind(struct task_struct *p, unsigned int cpu)
> > EXPORT_SYMBOL(kthread_bind);
> >
> > /**
> > + * kthread_bind_node - bind a just-created kthread to the CPUs of a node.
> > + * @p: thread created by kthread_create().
> > + * @nid: node (might not be online, must be possible) for @k to run on.
> > + *
> > + * Description: This function is equivalent to set_cpus_allowed(),
> > + * except that @nid doesn't need to be online, and the thread must be
> > + * stopped (i.e., just returned from kthread_create()).
> > + */
> > +void kthread_bind_node(struct task_struct *p, int nid)
> > +{
> > + /* Must have done schedule() in kthread() before we set_task_cpu */
> > + if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE)) {
> > + WARN_ON(1);
> > + return;
> > + }
> > +
> > + /* It's safe because the task is inactive. */
> > + do_set_cpus_allowed(p, cpumask_of_node(nid));
> > + p->flags |= PF_THREAD_BOUND;
> > +}
> > +EXPORT_SYMBOL(kthread_bind_node);
>
> _GPL ?

/**
* kthread_bind - bind a just-created kthread to a cpu.
* @p: thread created by kthread_create().
* @cpu: cpu (might not be online, must be possible) for @k to run on.
*
* Description: This function is equivalent to set_cpus_allowed(),
* except that @cpu doesn't need to be online, and the thread must be
* stopped (i.e., just returned from kthread_create()).
*/
void kthread_bind(struct task_struct *p, unsigned int cpu)
{
/* Must have done schedule() in kthread() before we set_task_cpu */
if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE)) {
WARN_ON(1);
return;
}

/* It's safe because the task is inactive. */
do_set_cpus_allowed(p, cpumask_of(cpu));
p->flags |= PF_THREAD_BOUND;
}
EXPORT_SYMBOL(kthread_bind);

/**
* kthread_bind_node - bind a just-created kthread to the CPUs of a node.
* @p: thread created by kthread_create().
* @nid: node (might not be online, must be possible) for @k to run on.
*
* Description: This function is equivalent to set_cpus_allowed(),
* except that @nid doesn't need to be online, and the thread must be
* stopped (i.e., just returned from kthread_create()).
*/
void kthread_bind_node(struct task_struct *p, int nid)
{
/* Must have done schedule() in kthread() before we set_task_cpu */
if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE)) {
WARN_ON(1);
return;
}

/* It's safe because the task is inactive. */
do_set_cpus_allowed(p, cpumask_of_node(nid));
p->flags |= PF_THREAD_BOUND;
}
EXPORT_SYMBOL(kthread_bind_node);

The above should explain why it's not _GPL right now. As far as
AutoNUMA is concerned I can drop the EXPORT_SYMBOL completely and not
allow modules to call this. In fact I could have coded this inside
autonuma too.

I can change it to _GPL, drop the EXPORT_SYMBOL or move it inside the
autonuma code, let me know what you prefer. If I hear nothing I won't
make changes.

Thanks,
Andrea
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/