From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCiDd-0002ZG-IJ for qemu-devel@nongnu.org; Wed, 08 Jul 2015 01:48:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCiDY-0003Jf-C8 for qemu-devel@nongnu.org; Wed, 08 Jul 2015 01:48:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60850) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCiDY-0003JZ-5I for qemu-devel@nongnu.org; Wed, 08 Jul 2015 01:48:24 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id AF3863CA999 for ; Wed, 8 Jul 2015 05:48:23 +0000 (UTC) Date: Wed, 8 Jul 2015 13:48:20 +0800 From: Fam Zheng Message-ID: <20150708054820.GC22926@ad.nay.redhat.com> References: <1436266737-3859-1-git-send-email-jasowang@redhat.com> <1436266737-3859-2-git-send-email-jasowang@redhat.com> <20150708032210.GB12842@ad.nay.redhat.com> <559CB139.4030908@redhat.com> <20150708054432.GA22926@ad.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150708054432.GA22926@ad.nay.redhat.com> Subject: Re: [Qemu-devel] [PATCH 2/2] tests: test rx recovery from cont List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang Cc: qemu-devel@nongnu.org, stefanha@redhat.com, mst@redhat.com On Wed, 07/08 13:44, Fam Zheng wrote: > On Wed, 07/08 13:12, Jason Wang wrote: > > > > > > On 07/08/2015 11:22 AM, Fam Zheng wrote: > > > On Tue, 07/07 18:58, Jason Wang wrote: > > >> Rx should be recovered after cont. > > >> > > >> Signed-off-by: Jason Wang > > >> --- > > >> tests/virtio-net-test.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > > >> 1 file changed, 48 insertions(+) > > >> > > >> diff --git a/tests/virtio-net-test.c b/tests/virtio-net-test.c > > >> index 97aa442..aeae80c 100644 > > >> --- a/tests/virtio-net-test.c > > >> +++ b/tests/virtio-net-test.c > > >> @@ -138,6 +138,45 @@ static void tx_test(const QVirtioBus *bus, QVirtioDevice *dev, > > >> g_assert_cmpstr(buffer, ==, "TEST"); > > >> } > > >> > > >> +static void rx_stop_cont_test(const QVirtioBus *bus, QVirtioDevice *dev, > > >> + QGuestAllocator *alloc, QVirtQueue *vq, > > >> + int socket) > > >> +{ > > >> + uint64_t req_addr; > > >> + uint32_t free_head; > > >> + char test[] = "TEST"; > > >> + char buffer[64]; > > >> + int len = htonl(sizeof(test)); > > >> + struct iovec iov[] = { > > >> + { > > >> + .iov_base = &len, > > >> + .iov_len = sizeof(len), > > >> + }, { > > >> + .iov_base = test, > > >> + .iov_len = sizeof(test), > > >> + }, > > >> + }; > > >> + int ret; > > >> + > > >> + req_addr = guest_alloc(alloc, 64); > > >> + > > >> + free_head = qvirtqueue_add(vq, req_addr, 64, true, false); > > >> + qvirtqueue_kick(bus, dev, vq, free_head); > > >> + > > >> + qmp("{ 'execute' : 'stop'}"); > > >> + > > >> + ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test)); > > >> + g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len)); > > > Maybe add a small lag here? The next "cont" could be too early that is noticed > > > earlier than the packet. > > > > I'm not sure I get the point of this. But at any case, rx should be > > recovered. (Btw, current qemu.git will fail in this case). > > If 'cont' and the packet land in main loop in the same qemu_poll_ns(), it's > possible that the packet is processed before 'stop'. Sorry, I meant after 'cont'. Fam > > A trick is using qmp commands as barriers: > > qmp("{ 'execute' : 'stop'}"); > > ret = iov_send(socket, iov, 2, 0, sizeof(len) + sizeof(test)); > g_assert_cmpint(ret, ==, sizeof(test) + sizeof(len)); > > /* We could check the status, but this command is more importantly to > * ensure the packet data gets queued in QEMU, before we do 'cont'. > */ > qmp("{ 'execute' : 'query-status'}"); > qmp("{ 'execute' : 'cont'}"); > > Fam > > > > > > > > >> + > > >> + qmp("{ 'execute' : 'cont'}"); > > >> + > > >> + qvirtio_wait_queue_isr(bus, dev, vq, QVIRTIO_NET_TIMEOUT_US); > > >> + memread(req_addr + 12, buffer, sizeof(test)); > > >> + g_assert_cmpstr(buffer, ==, "TEST"); > > >> + > > >> + guest_free(alloc, req_addr); > > >> +} > > >> + > > >> static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev, > > >> QGuestAllocator *alloc, QVirtQueue *rvq, > > >> QVirtQueue *tvq, int socket) > > >> @@ -146,6 +185,13 @@ static void send_recv_test(const QVirtioBus *bus, QVirtioDevice *dev, > > >> tx_test(bus, dev, alloc, tvq, socket); > > >> } > > >> > > >> +static void stop_cont_test(const QVirtioBus *bus, QVirtioDevice *dev, > > >> + QGuestAllocator *alloc, QVirtQueue *rvq, > > >> + QVirtQueue *tvq, int socket) > > >> +{ > > >> + rx_stop_cont_test(bus, dev, alloc, rvq, socket); > > >> +} > > >> + > > >> static void pci_basic(gconstpointer data) > > >> { > > >> QVirtioPCIDevice *dev; > > >> @@ -204,6 +250,8 @@ int main(int argc, char **argv) > > >> g_test_init(&argc, &argv, NULL); > > >> #ifndef _WIN32 > > >> qtest_add_data_func("/virtio/net/pci/basic", send_recv_test, pci_basic); > > >> + qtest_add_data_func("/virtio/net/pci/rx_stop_cont", > > >> + stop_cont_test, pci_basic); > > >> #endif > > >> qtest_add_func("/virtio/net/pci/hotplug", hotplug); > > >> > > >> -- > > >> 2.1.4 > > >> > > >