diff mbox

[08/16] tap: insert tap_can_send() into tap_send()

Message ID 00a2a114337c94c23068737bbe99cb044c84bbe6.1268326362.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela March 11, 2010, 4:55 p.m. UTC
This way we can remove the poll test

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 net/tap.c |   27 +++++++++------------------
 1 files changed, 9 insertions(+), 18 deletions(-)

Comments

Anthony Liguori March 17, 2010, 5:52 p.m. UTC | #1
On 03/11/2010 10:55 AM, Juan Quintela wrote:
> This way we can remove the poll test
>
> Signed-off-by: Juan Quintela<quintela@redhat.com>
>    

Won't this cause unnecessary wake ups?

Right now, we use the can_read() poll function to determine whether to 
add an fd to a fdset.  With this patch, we always add the fd to the 
fdset and then we just fail the read.

To eliminate the poll function, we need to change the handlers from 
polling, to noticing when they no longer can be read, and remove the 
read callback entirely.

Regards,

Anthony Liguori

> ---
>   net/tap.c |   27 +++++++++------------------
>   1 files changed, 9 insertions(+), 18 deletions(-)
>
> diff --git a/net/tap.c b/net/tap.c
> index 7a7320c..3ab65a3 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -61,17 +61,15 @@ typedef struct TAPState {
>
>   static int launch_script(const char *setup_script, const char *ifname, int fd);
>
> -static int tap_can_send(void *opaque);
>   static void tap_send(void *opaque);
>   static void tap_writable(void *opaque);
>
>   static void tap_update_fd_handler(TAPState *s)
>   {
> -    qemu_set_fd_handler2(s->fd,
> -                         s->read_poll  ? tap_can_send : NULL,
> -                         s->read_poll  ? tap_send     : NULL,
> -                         s->write_poll ? tap_writable : NULL,
> -                         s);
> +    qemu_set_fd_handler(s->fd,
> +                        s->read_poll  ? tap_send     : NULL,
> +                        s->write_poll ? tap_writable : NULL,
> +                        s);
>   }
>
>   static void tap_read_poll(TAPState *s, int enable)
> @@ -165,13 +163,6 @@ static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
>       return tap_write_packet(s, iov, 1);
>   }
>
> -static int tap_can_send(void *opaque)
> -{
> -    TAPState *s = opaque;
> -
> -    return qemu_can_send_packet(&s->nc);
> -}
> -
>   #ifndef __sun__
>   ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
>   {
> @@ -188,12 +179,10 @@ static void tap_send_completed(VLANClientState *nc, ssize_t len)
>   static void tap_send(void *opaque)
>   {
>       TAPState *s = opaque;
> -    int size;
>
> -    do {
> +    while (qemu_can_send_packet(&s->nc)>  0) {
>           uint8_t *buf = s->buf;
> -
> -        size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
> +        int size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
>           if (size<= 0) {
>               break;
>           }
> @@ -206,8 +195,10 @@ static void tap_send(void *opaque)
>           size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
>           if (size == 0) {
>               tap_read_poll(s, 0);
> +        } else if (size<  0) {
> +            return;
>           }
> -    } while (size>  0&&  qemu_can_send_packet(&s->nc));
> +    }
>   }
>
>   int tap_has_ufo(VLANClientState *nc)
>
diff mbox

Patch

diff --git a/net/tap.c b/net/tap.c
index 7a7320c..3ab65a3 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -61,17 +61,15 @@  typedef struct TAPState {

 static int launch_script(const char *setup_script, const char *ifname, int fd);

-static int tap_can_send(void *opaque);
 static void tap_send(void *opaque);
 static void tap_writable(void *opaque);

 static void tap_update_fd_handler(TAPState *s)
 {
-    qemu_set_fd_handler2(s->fd,
-                         s->read_poll  ? tap_can_send : NULL,
-                         s->read_poll  ? tap_send     : NULL,
-                         s->write_poll ? tap_writable : NULL,
-                         s);
+    qemu_set_fd_handler(s->fd,
+                        s->read_poll  ? tap_send     : NULL,
+                        s->write_poll ? tap_writable : NULL,
+                        s);
 }

 static void tap_read_poll(TAPState *s, int enable)
@@ -165,13 +163,6 @@  static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size)
     return tap_write_packet(s, iov, 1);
 }

-static int tap_can_send(void *opaque)
-{
-    TAPState *s = opaque;
-
-    return qemu_can_send_packet(&s->nc);
-}
-
 #ifndef __sun__
 ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
 {
@@ -188,12 +179,10 @@  static void tap_send_completed(VLANClientState *nc, ssize_t len)
 static void tap_send(void *opaque)
 {
     TAPState *s = opaque;
-    int size;

-    do {
+    while (qemu_can_send_packet(&s->nc) > 0) {
         uint8_t *buf = s->buf;
-
-        size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
+        int size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
         if (size <= 0) {
             break;
         }
@@ -206,8 +195,10 @@  static void tap_send(void *opaque)
         size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
         if (size == 0) {
             tap_read_poll(s, 0);
+        } else if (size < 0) {
+            return;
         }
-    } while (size > 0 && qemu_can_send_packet(&s->nc));
+    }
 }

 int tap_has_ufo(VLANClientState *nc)