Skip to contentSkip to conversation

Workqueue based vhost work scheduling

RFC PATCH In review Bandan Das 2 participants 3 messages Oct 14, 2013

Subsystems (4)
lore
Share & tools
lore

Bandan Das

author
#0 lore raw

v2 cover Workqueue based vhost work scheduling

This is a followup to RFC posted by Shirley Ma on 22 March 2012 :
NUMA aware scheduling per vhost thread patch [1]. This patch is against 3.12-rc4.

This is a step-down from the previous version in the sense that this patch utilizes the workqueue mechanism instead of creating per-cpu vhost threads, or in other words, the per-cpu threads are completely invisible to vhost as they are the responsibility of the cmwq implementation.

The workqueue implementation [2] maintains a pool of dedicated threads per CPU that are used when work is queued. The user can control certain aspects of the work execution using special flags that can be passed along during the call to alloc_workqueue. Based on this description, the approach is that instead of vhost creating per-cpu thread to address issues pointed out
in RFC v1, we just let the cmwq mechanism do the heavy lifting for us. The end result is that the changes in v2 are substantially smaller compared to v1.

The major changes wrt v1 :
- A module param called cmwq_worker, that when enabled, uses the wq backend
- vhost doesn't manage any per cpu threads anymore, trust wq backend to do the right thing.
- A significant part of v1 was to decide where to run the job - this is gone now for reasons discussed above.

Testing :

As of now, some basic netperf testing varying only the message sizes keeping all other factors constant (to keep it simple) I however agree that this needs more testing for more concrete conclusions.

The host is Nehalem 4 cores x 4 sockets with 4G memory, cpu 0-7 - numa node0 and cpu 8-16 = numa node1.
The host is running 4 guests with -smp 4 and -m 1G to keep it somewhat realistic. netperf in Guest 0 interacts with netserv running in the host for our test results.

Results :

I noticed a common signature in all the tests except UDP_RR -
for small message sizes, the workqueue implementation has a slightly better throughput, however with increase in message size, the throughput degrades slightly compared to the unpatched version. I suspect that the vhost_submission_workfn can be modified to make this better or there could be other factors that I still haven't thought about. Ofcourse, we shouldn't forget the important condition that we are not running on a vhost specific dedicated thread anymore.

UDP_RR however, exhibited better results constantly for the wq version.

I include the figures for just TCP_STREAM and UDP_RR below :

TCP_STREAM

Size Throughput (Without patch) Throughput (With patch)
bytes 10^6bytes/sec 10^6bytes/sec
--------------------------------------------------------------------------

256                2695.22                     2793.14
512                5682.10                     5896.34
1024               7511.18                     7295.96
2048               8197.94                     7564.50
4096               8764.95                     7822.98
8192               8205.89                     8046.49
16384              11495.72                    11101.35

UDP_RR
Size (Without patch) (With patch)
bytes Trans/sec Trans/sec
--------------------------------------------------------------------------

256                10966.77	             14842.16
512                9930.06                   14747.76
1024               10587.85	             14544.10
2048               7172.34		     13790.56
4096               7628.35		     13333.39
8192               5663.10                   11916.82
16384              6807.25		     9994.11

I had already discussed my results with Michael privately, so sorry for the duplicate information, Michael!

[1] http://www.mail-archive.com/[email protected]/msg69868.html
[2] Documentation/workqueue.txt

Bandan Das (1):
Workqueue based vhost workers

 drivers/vhost/net.c   |  25 +++++++++++
 drivers/vhost/vhost.c | 115 +++++++++++++++++++++++++++++++++++++++++++-------
 drivers/vhost/vhost.h |   6 +++
 3 files changed, 130 insertions(+), 16 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

RFC PATCH v2 1/1 Workqueue based vhost workers

---
 drivers/vhost/net.c   |  25 +++++++++++
 drivers/vhost/vhost.c | 115 +++++++++++++++++++++++++++++++++++++++++++-------
 drivers/vhost/vhost.h |   6 +++
 3 files changed, 130 insertions(+), 16 deletions(-)
drivers/vhost/net.c +25 -0
index 831eb4f..f5307d7 100644
@@ -34,6 +34,10 @@ module_param(experimental_zcopytx, int, 0444);
 MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
 		                       " 1 -Enable; 0 - Disable");
 
+static int cmwq_worker;
+module_param(cmwq_worker, int, 0444);
+MODULE_PARM_DESC(cmwq_worker, "Use cmwq for worker threads - Experimental, 1 - Enable; 0 - Disable");
+
 /* Max number of bytes transferred before requeueing the job.
  * Using this limit prevents one virtqueue from starving others. */
 #define VHOST_NET_WEIGHT 0x80000
@@ -694,6 +698,7 @@ static int vhost_net_open(struct inode *inode, struct file *f)
 	}
 
 	dev = &n->dev;
+	dev->use_wq = 0;
 	vqs[VHOST_NET_VQ_TX] = &n->vqs[VHOST_NET_VQ_TX].vq;
 	vqs[VHOST_NET_VQ_RX] = &n->vqs[VHOST_NET_VQ_RX].vq;
 	n->vqs[VHOST_NET_VQ_TX].vq.handle_kick = handle_tx_kick;
@@ -706,6 +711,10 @@ static int vhost_net_open(struct inode *inode, struct file *f)
 		n->vqs[i].vhost_hlen = 0;
 		n->vqs[i].sock_hlen = 0;
 	}
+
+	if (cmwq_worker)
+		dev->use_wq = 1;
+
 	r = vhost_dev_init(dev, vqs, VHOST_NET_VQ_MAX);
 	if (r < 0) {
 		kfree(n);
@@ -1123,14 +1132,30 @@ static struct miscdevice vhost_net_misc = {
 
 static int vhost_net_init(void)
 {
+	int ret = 0;
+
 	if (experimental_zcopytx)
 		vhost_net_enable_zcopy(VHOST_NET_VQ_TX);
+
+	if (cmwq_worker) {
+		ret = vhost_wq_init();
+		if (ret) {
+			pr_info("Enabling wq based vhost workers failed! "
+				 "Switching to device based worker instead\n");
+			cmwq_worker = 0;
+		} else
+		  pr_info("Enabled workqueues based vhost workers\n");
+	}
+
 	return misc_register(&vhost_net_misc);
 }
 module_init(vhost_net_init);
 
 static void vhost_net_exit(void)
 {
+	if (cmwq_worker)
+		vhost_wq_cleanup();
+
 	misc_deregister(&vhost_net_misc);
 }
 module_exit(vhost_net_exit);
drivers/vhost/vhost.c +99 -16

159 lines not on this page · raw message

drivers/vhost/vhost.h +6 -0
index 4465ed5..3f6c147 100644
@@ -125,6 +125,8 @@ struct vhost_dev {
 	spinlock_t work_lock;
 	struct list_head work_list;
 	struct task_struct *worker;
+	int use_wq;
+	struct work_struct qwork;
 };
 
 long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue **vqs, int nvqs);
@@ -161,6 +163,10 @@ bool vhost_enable_notify(struct vhost_dev *, struct vhost_virtqueue *);
 int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
 		    unsigned int log_num, u64 len);
 
+/* Experimental cmwq decls */
+int  vhost_wq_init(void);
+void vhost_wq_cleanup(void);
+
 #define vq_err(vq, fmt, ...) do {                                  \
 		pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
 		if ((vq)->error_ctx)                               \
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [RFC PATCH v2 1/1] Workqueue based vhost workers

drivers/vhost/net.c static struct miscdevice vhost_net_misc = { · line 1148

Quoted 10 lines · On Sun, 13 Oct 2013 21:55:43 -0400 Bandan Das <[email protected]> wrote:
drivers/vhost/net.c +10 -0
+
+	if (cmwq_worker) {
+		ret = vhost_wq_init();
+		if (ret) {
+			pr_info("Enabling wq based vhost workers failed! "
+				 "Switching to device based worker instead\n");
+			cmwq_worker = 0;
+		} else
+		  pr_info("Enabled workqueues based vhost workers\n");
+	}

Why keep two mechanisms (and two potential code paths to maintain) when the only way vhost_wq_init() can fail is if out of memory. You may have needed the messages and this during development but for the final version just do it one way.

If alloc_workqueue fails, then the net_init function should propogate the error code and fail as well.