Skip to contentSkip to conversation

vhost: wake up worker outside spin_lock

PATCH In review Qin Chuanyu 3 participants 3 messages Jun 7, 2013 – Jun 9, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: wake up worker outside spin_lock

the wake_up_process func is included by spin_lock/unlock in vhost_work_queue, but it could be done outside the spin_lock.
I have test it with kernel 3.0.27 and guest suse11-sp2 using iperf, the num as below.
original modified

thread_num  tp(Gbps)   vhost(%)  |  tp(Gbps)     vhost(%)
1           9.59        28.82    |   9.59        27.49
8           9.61        32.92    |   9.62        26.77
64          9.58        46.48    |   9.55        38.99
256         9.6         63.7     |   9.6         52.59
---
 drivers/vhost/vhost.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/vhost/vhost.c +3 -1
index 94dbd25..dcc7a17 100644
@@ -146,9 +146,11 @@ static inline void vhost_work_queue(struct vhost_dev *dev,
 	if (list_empty(&work->node)) {
 		list_add_tail(&work->node, &dev->work_list);
 		work->queue_seq++;
+		spin_unlock_irqrestore(&dev->work_lock, flags);
 		wake_up_process(dev->worker);
+	} else {
+		spin_unlock_irqrestore(&dev->work_lock, flags);
 	}
-	spin_unlock_irqrestore(&dev->work_lock, flags);
 }
 
 void vhost_poll_queue(struct vhost_poll *poll)
Signature · 1 line
1.7.3.1.msysgit.0
#1 lore raw
Quoted 36 lines · Qin Chuanyu

the wake_up_process func is included by spin_lock/unlock in vhost_work_queue,
but it could be done outside the spin_lock.
I have test it with kernel 3.0.27 and guest suse11-sp2 using iperf, the num as below.
original modified

thread_num  tp(Gbps)   vhost(%)  |  tp(Gbps)     vhost(%)
1           9.59        28.82    |   9.59        27.49
8           9.61        32.92    |   9.62        26.77
64          9.58        46.48    |   9.55        38.99
256         9.6         63.7     |   9.6         52.59
---
 drivers/vhost/vhost.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/vhost/vhost.c +3 -1
index 94dbd25..dcc7a17 100644
@@ -146,9 +146,11 @@ static inline void vhost_work_queue(struct vhost_dev
 *dev,
 
        if (list_empty(&work->node)) {
                list_add_tail(&work->node, &dev->work_list);
                work->queue_seq++;
+               spin_unlock_irqrestore(&dev->work_lock, flags);
                wake_up_process(dev->worker);
+       } else {
+               spin_unlock_irqrestore(&dev->work_lock, flags);
        }
-       spin_unlock_irqrestore(&dev->work_lock, flags);
 
Quoted 1 line

}

Hmm, this looks more clearer to me.

drivers/vhost/vhost.c +4 -1
@@ -156,14 +156,17 @@ EXPORT_SYMBOL_GPL(vhost_poll_flush);
 void vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
 {
        unsigned long flags;
+       bool wakeup = false;
 
        spin_lock_irqsave(&dev->work_lock, flags);
        if (list_empty(&work->node)) {
                list_add_tail(&work->node, &dev->work_list);
                work->queue_seq++;
-               wake_up_process(dev->worker);
+               wakeup = true;
        }
        spin_unlock_irqrestore(&dev->work_lock, flags);
+       if (wakeup)
+               wake_up_process(dev->worker);
 }
 
 
Quoted 10 lines

void vhost_poll_queue(struct vhost_poll *poll)
--
1.7.3.1.msysgit.0

--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Asias

#2 lore raw
In reply to Qin Chuanyu
Quoted 22 lines · Qin Chuanyu

the wake_up_process func is included by spin_lock/unlock in vhost_work_queue,
but it could be done outside the spin_lock.
I have test it with kernel 3.0.27 and guest suse11-sp2 using iperf, the num as below.
original modified

thread_num  tp(Gbps)   vhost(%)  |  tp(Gbps)     vhost(%)
1           9.59        28.82    |   9.59        27.49
8           9.61        32.92    |   9.62        26.77
64          9.58        46.48    |   9.55        38.99
256         9.6         63.7     |   9.6         52.59
---
 drivers/vhost/vhost.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/vhost/vhost.c +0 -0
index 94dbd25..dcc7a17 100644

drivers/vhost/vhost.c static inline void vhost_work_queue(struct · line 146

Quoted 1 line
drivers/vhost/vhost.c +0 -0
@@ -146,9 +146,11 @@ static inline void vhost_work_queue(struct
 vhost_dev *dev,

Applied and queued for 3.11, thanks.

This patch is malformed because of the wrapped line above. I've applied this by hand, so just FYI, please see Documentation/email-clients.txt
for some hints on configuring mail properly.

Quoted 15 lines
drivers/vhost/vhost.c +3 -1
 	if (list_empty(&work->node)) {
 		list_add_tail(&work->node, &dev->work_list);
 		work->queue_seq++;
+		spin_unlock_irqrestore(&dev->work_lock, flags);
 		wake_up_process(dev->worker);
+	} else {
+		spin_unlock_irqrestore(&dev->work_lock, flags);
 	}
-	spin_unlock_irqrestore(&dev->work_lock, flags);
 }
 

void vhost_poll_queue(struct vhost_poll *poll)

Signature · 1 line
1.7.3.1.msysgit.0