Commit 3471b757d0ca63a0e8188c4c96acd1c279a8c737
1 parent
2e1e0641
net: only read from tapfd when we can send
Reduce the number of packets dropped under heavy network traffic by only reading a packet from the tapfd when a client can actually handle it. Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Showing
1 changed file
with
8 additions
and
1 deletions
net.c
@@ -956,6 +956,13 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size) | @@ -956,6 +956,13 @@ static void tap_receive(void *opaque, const uint8_t *buf, int size) | ||
956 | } | 956 | } |
957 | } | 957 | } |
958 | 958 | ||
959 | +static int tap_can_send(void *opaque) | ||
960 | +{ | ||
961 | + TAPState *s = opaque; | ||
962 | + | ||
963 | + return qemu_can_send_packet(s->vc); | ||
964 | +} | ||
965 | + | ||
959 | #ifdef __sun__ | 966 | #ifdef __sun__ |
960 | static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) | 967 | static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) |
961 | { | 968 | { |
@@ -1011,7 +1018,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, | @@ -1011,7 +1018,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, | ||
1011 | s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, | 1018 | s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, |
1012 | NULL, tap_cleanup, s); | 1019 | NULL, tap_cleanup, s); |
1013 | s->vc->fd_readv = tap_receive_iov; | 1020 | s->vc->fd_readv = tap_receive_iov; |
1014 | - qemu_set_fd_handler(s->fd, tap_send, NULL, s); | 1021 | + qemu_set_fd_handler2(s->fd, tap_can_send, tap_send, NULL, s); |
1015 | snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd); | 1022 | snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd); |
1016 | return s; | 1023 | return s; |
1017 | } | 1024 | } |