From patchwork Wed Jul 14 23:26:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sridhar Samudrala X-Patchwork-Id: 112104 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6ENRbRJ008541 for ; Wed, 14 Jul 2010 23:27:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754365Ab0GNX0o (ORCPT ); Wed, 14 Jul 2010 19:26:44 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:51118 "EHLO e39.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752665Ab0GNX0n (ORCPT ); Wed, 14 Jul 2010 19:26:43 -0400 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by e39.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o6ENHAGn031186; Wed, 14 Jul 2010 17:17:10 -0600 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id o6ENQemx258276; Wed, 14 Jul 2010 17:26:41 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o6ENQcoH027358; Wed, 14 Jul 2010 17:26:40 -0600 Received: from [9.47.18.19] (w-sridhar.beaverton.ibm.com [9.47.18.19]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o6ENQbcP027273; Wed, 14 Jul 2010 17:26:37 -0600 Subject: Re: [PATCH repost] sched: export sched_set/getaffinity to modules From: Sridhar Samudrala To: "Michael S. Tsirkin" Cc: Oleg Nesterov , Peter Zijlstra , Tejun Heo , Ingo Molnar , netdev , lkml , "kvm@vger.kernel.org" , Andrew Morton , Dmitri Vorobiev , Jiri Kosina , Thomas Gleixner , Andi Kleen In-Reply-To: <20100713110939.GA3446@redhat.com> References: <20100701133956.GD32223@redhat.com> <4C2CA5C5.4040402@kernel.org> <20100701144624.GA11171@redhat.com> <4C2CABF2.2020801@kernel.org> <1277996135.1917.198.camel@laptop> <4C2E2987.9040702@us.ibm.com> <1278094270.1917.288.camel@laptop> <20100702210637.GA12433@redhat.com> <20100704090005.GA8078@redhat.com> <4C3C0EBC.40305@us.ibm.com> <20100713110939.GA3446@redhat.com> Date: Wed, 14 Jul 2010 16:26:36 -0700 Message-Id: <1279149996.32374.5.camel@w-sridhar.beaverton.ibm.com> Mime-Version: 1.0 X-Mailer: Evolution 2.26.3 (2.26.3-1.fc11) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 14 Jul 2010 23:27:38 +0000 (UTC) diff --git a/include/linux/kthread.h b/include/linux/kthread.h index aabc8a1..e0616f0 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -9,6 +9,9 @@ struct task_struct *kthread_create(int (*threadfn)(void *data), const char namefmt[], ...) __attribute__((format(printf, 3, 4))); +struct task_struct *kthread_create_in_current_cg(int (*threadfn)(void *data), + void *data, char *name); + /** * kthread_run - create and wake a thread. * @threadfn: the function to run until signal_pending(current). diff --git a/kernel/kthread.c b/kernel/kthread.c index 83911c7..ea4e737 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -15,6 +15,7 @@ #include #include #include +#include static DEFINE_SPINLOCK(kthread_create_lock); static LIST_HEAD(kthread_create_list); @@ -149,6 +150,42 @@ struct task_struct *kthread_create(int (*threadfn)(void *data), } EXPORT_SYMBOL(kthread_create); +struct task_struct *kthread_create_in_current_cg(int (*threadfn)(void *data), + void *data, char *name) +{ + struct task_struct *worker; + cpumask_var_t mask; + int ret = -ENOMEM; + + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) + goto out_free_mask; + + worker = kthread_create(threadfn, data, "%s-%d", name, current->pid); + if (IS_ERR(worker)) + goto out_free_mask; + + ret = sched_getaffinity(current->pid, mask); + if (ret) + goto out_stop_worker; + + ret = sched_setaffinity(worker->pid, mask); + if (ret) + goto out_stop_worker; + + ret = cgroup_attach_task_current_cg(worker); + if (ret) + goto out_stop_worker; + + return worker; + +out_stop_worker: + kthread_stop(worker); +out_free_mask: + free_cpumask_var(mask); + return ERR_PTR(ret); +} +EXPORT_SYMBOL(kthread_create_in_current_cg); + /** * kthread_bind - bind a just-created kthread to a cpu. * @p: thread created by kthread_create().