Skip to contentSkip to conversation

slirp: Signal free input buffer space to io-thread

PATCH In review Jan Kiszka 2 participants 2 messages Mar 30, 2012

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 slirp: Signal free input buffer space to io-thread

This massively accelerates slirp reception speed: If data arrives faster than the guest can read it from the input buffer, the file descriptor for the corresponding socket was taken out of the fdset for select. However, the event of the guest reading enough data from the buffer was not signaled. Thus, the io-thread only noticed this change on the next time-driven poll. Fix this by kicking the io-thread as required.

---

Hell, this was really annoying when working with slirp, specifically with KVM irqchip enabled (as it reduces userspace exits). But I never really found the time to dig deep enough. And now it turned out to be so simple! http://thread.gmane.org/gmane.comp.emulators.qemu/141975 was the key for me.

 slirp/sbuf.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
slirp/sbuf.c +6 -0
index 5a1ccbf..637f8fe 100644
@@ -6,6 +6,7 @@
  */
 
 #include <slirp.h>
+#include <main-loop.h>
 
 static void sbappendsb(struct sbuf *sb, struct mbuf *m);
 
@@ -18,6 +19,8 @@ sbfree(struct sbuf *sb)
 void
 sbdrop(struct sbuf *sb, int num)
 {
+    int limit = sb->sb_datalen / 2;
+
 	/*
 	 * We can only drop how much we have
 	 * This should never succeed
@@ -29,6 +32,9 @@ sbdrop(struct sbuf *sb, int num)
 	if(sb->sb_rptr >= sb->sb_data + sb->sb_datalen)
 		sb->sb_rptr -= sb->sb_datalen;
 
+    if (sb->sb_cc < limit && sb->sb_cc + num >= limit) {
+        qemu_notify_event();
+    }
 }
 
 void
Signature · 1 line
1.7.3.4
#1 lore raw

Il 30/03/2012 19:43, Jan Kiszka ha scritto:

Quoted 42 lines

This massively accelerates slirp reception speed: If data arrives faster than the guest can read it from the input buffer, the file descriptor for the corresponding socket was taken out of the fdset for select. However, the event of the guest reading enough data from the buffer was not signaled. Thus, the io-thread only noticed this change on the next time-driven poll. Fix this by kicking the io-thread as required.

---

Hell, this was really annoying when working with slirp, specifically with KVM irqchip enabled (as it reduces userspace exits). But I never really found the time to dig deep enough. And now it turned out to be so simple! http://thread.gmane.org/gmane.comp.emulators.qemu/141975 was the key for me.

 slirp/sbuf.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
slirp/sbuf.c +3 -0
index 5a1ccbf..637f8fe 100644
@@ -6,6 +6,7 @@
  */
 
 #include <slirp.h>
+#include <main-loop.h>
 
 static void sbappendsb(struct sbuf *sb, struct mbuf *m);
 
@@ -18,6 +19,8 @@ sbfree(struct sbuf *sb)
 void
 sbdrop(struct sbuf *sb, int num)
 {
+    int limit = sb->sb_datalen / 2;
+
 	/*
 	 * We can only drop how much we have
 	 * This should never succeed

slirp/sbuf.c sbdrop(struct sbuf *sb, int num) · line 40

Quoted 9 lines
slirp/sbuf.c +3 -0
@@ -29,6 +32,9 @@ sbdrop(struct sbuf *sb, int num)
 	if(sb->sb_rptr >= sb->sb_data + sb->sb_datalen)
 		sb->sb_rptr -= sb->sb_datalen;
 
+    if (sb->sb_cc < limit && sb->sb_cc + num >= limit) {
+        qemu_notify_event();
+    }
 }
 
 void

Looks good!

Paolo