From 54bb7a84d9bd4a48d0cf98ff9d7479deed7a4e6d Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Wed, 22 Nov 2017 00:47:29 +0100 Subject: [PATCH] reduce the number of interrupts in the network driver --- drivers/net/uhyve-net.c | 2 +- tools/uhyve.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/uhyve-net.c b/drivers/net/uhyve-net.c index 4e7428d0a..a19eefe89 100755 --- a/drivers/net/uhyve-net.c +++ b/drivers/net/uhyve-net.c @@ -195,7 +195,7 @@ static void uhyve_netif_poll(void) struct pbuf *p = NULL; struct pbuf *q; - if (uhyve_net_read_sync(uhyve_netif->rx_buf, &len) == 0) + while (uhyve_net_read_sync(uhyve_netif->rx_buf, &len) == 0) { #if ETH_PAD_SIZE len += ETH_PAD_SIZE; /*allow room for Ethernet padding */ diff --git a/tools/uhyve.c b/tools/uhyve.c index 5c1564909..77543968a 100644 --- a/tools/uhyve.c +++ b/tools/uhyve.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -189,6 +190,7 @@ static pthread_barrier_t barrier; static __thread struct kvm_run *run = NULL; static __thread int vcpufd = -1; static __thread uint32_t cpuid = 0; +static sem_t net_sem; int uhyve_argc = -1; int uhyve_envc = -1; @@ -754,6 +756,7 @@ static void* wait_for_packet(void* arg) else if (ret) { uint64_t event_counter = 1; write(efd, &event_counter, sizeof(event_counter)); + sem_wait(&net_sem); } } @@ -771,6 +774,8 @@ static inline void check_network(void) irqfd.gsi = UHYVE_IRQ; kvm_ioctl(vmfd, KVM_IRQFD, &irqfd); + sem_init(&net_sem, 0, 0); + if (pthread_create(&net_thread, NULL, wait_for_packet, NULL)) err(1, "unable to create thread"); } @@ -894,7 +899,10 @@ static int vcpu_loop(void) if (ret > 0) { uhyve_netread->len = ret; uhyve_netread->ret = 0; - } else uhyve_netread->ret = -1; + } else { + uhyve_netread->ret = -1; + sem_post(&net_sem); + } break; }