lkml.org 
[lkml]   [2010]   [May]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH UPDATED 3/3] vhost: apply cpumask and cgroup to vhost pollers
    Apply the cpumask and cgroup of the initializing task to the created
    vhost poller.

    Based on Sridhar Samudrala's patch. Li Zefan spotted a bug in error
    path, fixed.

    Cc: Michael S. Tsirkin <mst@redhat.com>
    Cc: Sridhar Samudrala <samudrala.sridhar@gmail.com>
    Cc: Li Zefan <lizf@cn.fujitsu.com>
    ---
    Updated accordingly. Thanks.

    drivers/vhost/vhost.c | 36 +++++++++++++++++++++++++++++++-----
    1 file changed, 31 insertions(+), 5 deletions(-)

    Index: work/drivers/vhost/vhost.c
    ===================================================================
    --- work.orig/drivers/vhost/vhost.c
    +++ work/drivers/vhost/vhost.c
    @@ -23,6 +23,7 @@
    #include <linux/highmem.h>
    #include <linux/slab.h>
    #include <linux/kthread.h>
    +#include <linux/cgroup.h>

    #include <linux/net.h>
    #include <linux/if_packet.h>
    @@ -176,12 +177,30 @@ repeat:
    long vhost_dev_init(struct vhost_dev *dev,
    struct vhost_virtqueue *vqs, int nvqs)
    {
    - struct task_struct *poller;
    - int i;
    + struct task_struct *poller = NULL;
    + cpumask_var_t mask;
    + int i, ret = -ENOMEM;
    +
    + if (!alloc_cpumask_var(&mask, GFP_KERNEL))
    + goto out;

    poller = kthread_create(vhost_poller, dev, "vhost-%d", current->pid);
    - if (IS_ERR(poller))
    - return PTR_ERR(poller);
    + if (IS_ERR(poller)) {
    + ret = PTR_ERR(poller);
    + goto out;
    + }
    +
    + ret = sched_getaffinity(current->pid, mask);
    + if (ret)
    + goto out;
    +
    + ret = sched_setaffinity(poller->pid, mask);
    + if (ret)
    + goto out;
    +
    + ret = cgroup_attach_task_current_cg(poller);
    + if (ret)
    + goto out;

    dev->vqs = vqs;
    dev->nvqs = nvqs;
    @@ -202,7 +221,14 @@ long vhost_dev_init(struct vhost_dev *de
    vhost_poll_init(&dev->vqs[i].poll,
    dev->vqs[i].handle_kick, POLLIN, dev);
    }
    - return 0;
    +
    + wake_up_process(poller); /* avoid contributing to loadavg */
    + ret = 0;
    +out:
    + if (ret && poller)
    + kthread_stop(poller);
    + free_cpumask_var(mask);
    + return ret;
    }

    /* Caller should have device mutex */

    \
     
     \ /
      Last update: 2010-05-31 09:01    [W:0.023 / U:0.524 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site