From patchwork Tue Jun 1 09:35:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 103440 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o519anlK024507 for ; Tue, 1 Jun 2010 09:36:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755881Ab0FAJgF (ORCPT ); Tue, 1 Jun 2010 05:36:05 -0400 Received: from hera.kernel.org ([140.211.167.34]:59883 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754640Ab0FAJgB (ORCPT ); Tue, 1 Jun 2010 05:36:01 -0400 Received: from htj.dyndns.org (localhost [127.0.0.1]) by hera.kernel.org (8.14.3/8.14.3) with ESMTP id o519ZGp7030838; Tue, 1 Jun 2010 09:35:16 GMT X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.95.2 at hera.kernel.org Received: from [127.0.0.2] (htj.dyndns.org [127.0.0.2]) by htj.dyndns.org (Postfix) with ESMTPSA id 08EAC1004B20C; Tue, 1 Jun 2010 11:35:16 +0200 (CEST) Message-ID: <4C04D453.9040208@kernel.org> Date: Tue, 01 Jun 2010 11:35:15 +0200 From: Tejun Heo User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: "Michael S. Tsirkin" CC: Oleg Nesterov , Sridhar Samudrala , netdev , lkml , "kvm@vger.kernel.org" , Andrew Morton , Dmitri Vorobiev , Jiri Kosina , Thomas Gleixner , Ingo Molnar , Andi Kleen Subject: [PATCH 3/3] vhost: apply cpumask and cgroup to vhost workers References: <20100527163954.GA21710@redhat.com> <4BFEA434.6080405@kernel.org> <20100527173207.GA21880@redhat.com> <4BFEE216.2070807@kernel.org> <20100528150830.GB21880@redhat.com> <4BFFE742.2060205@kernel.org> <20100530112925.GB27611@redhat.com> <4C02C961.9050606@kernel.org> <20100531152221.GB2987@redhat.com> <4C03D983.9010905@kernel.org> <20100531160020.GC3067@redhat.com> In-Reply-To: <20100531160020.GC3067@redhat.com> X-Enigmail-Version: 1.0.1 X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on hera.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]); Tue, 01 Jun 2010 09:36:49 +0000 (UTC) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.3 (hera.kernel.org [127.0.0.1]); Tue, 01 Jun 2010 09:35:17 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Index: work/drivers/vhost/vhost.c =================================================================== --- work.orig/drivers/vhost/vhost.c +++ work/drivers/vhost/vhost.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -187,11 +188,29 @@ long vhost_dev_init(struct vhost_dev *de struct vhost_virtqueue *vqs, int nvqs) { struct task_struct *worker; - int i; + cpumask_var_t mask; + int i, ret = -ENOMEM; + + if (!alloc_cpumask_var(&mask, GFP_KERNEL)) + goto out_free_mask; worker = kthread_create(vhost_worker, dev, "vhost-%d", current->pid); - if (IS_ERR(worker)) - return PTR_ERR(worker); + if (IS_ERR(worker)) { + ret = PTR_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; dev->vqs = vqs; dev->nvqs = nvqs; @@ -214,7 +233,14 @@ long vhost_dev_init(struct vhost_dev *de } wake_up_process(worker); /* avoid contributing to loadavg */ - return 0; + ret = 0; + goto out_free_mask; + +out_stop_worker: + kthread_stop(worker); +out_free_mask: + free_cpumask_var(mask); + return ret; } /* Caller should have device mutex */