From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f174.google.com (mail-pf0-f174.google.com [209.85.192.174]) by dpdk.org (Postfix) with ESMTP id C26FDC166 for ; Thu, 28 Jan 2016 03:47:32 +0100 (CET) Received: by mail-pf0-f174.google.com with SMTP id x125so15385017pfb.0 for ; Wed, 27 Jan 2016 18:47:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=IXgUIzLTmtVHlvB/Bg3PO0f9yagmNEK05N/2LuzPFHw=; b=LjpHwksWHWtqykLZKAj7z80sKQZNd5EpwyOkoDfjzNL3e1FNNRbCFgeLcwqYD28fCY LMyl+1Z3XHknG5t4kkT2HtfA+GGiCRI1jmcrnSf2t2oQrIkeZWtn81axqlojyhpUmJnk ga44QMxzu50CBg8BH+//QRvQHyQEeGskS7TMzMfHD2T1IZK7r20qTE6eR14qZ1neEUE5 1dCd5OX3FWBlP1E3cVHnlT4Pj7uBA8VDET6FxDBJXFL/Wdz+rvKHQzKCBgsfUMAuO+q4 nyHjBgc8JdYmWPUi6ys+cFfvbe6cJnk2zf4Fh3ay4xF6DC84+qxoZF4OxncJ5bATH6de BMUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=IXgUIzLTmtVHlvB/Bg3PO0f9yagmNEK05N/2LuzPFHw=; b=jXV4axak40HBhXdnpC2IVP/LGzd/4OxgQng/g/qa/uMSUrpCWmzUxAwDzA/AFRdnYb yUogwjvCeFQxM80qiWJS0O9D9EYKEnknr7G/vkk4X6wmq02LaV4MMRel2oBAw+ifN7kO MuOL1FVkCLk3Qs0RP5dNO222ubpH8uiW9jo/79GC/N0Uf3iW7qciDyy5zaOL1dESy/J4 wLcvqcQ2efCaY1HjpOsDIS17VPZzaOi6p2jhpUAnXUQRr0ReFsGsLTmYHg1C38WMtbI0 5/pYO6MVf1fWVMXvuoHewFuD7PegD+qPxdFdEDbNVr2Tv6YWTG6cDgFmK1xhF274X/YD 55kw== X-Gm-Message-State: AG10YOR535vUQpjlf1L/20gRTgfPMqwZ5WVdN/vC4uG2RVkMmmDSYPl9/zvKVDXwD9YMmQ== X-Received: by 10.98.71.136 with SMTP id p8mr945001pfi.131.1453949252203; Wed, 27 Jan 2016 18:47:32 -0800 (PST) Received: from [10.16.129.101] (napt.igel.co.jp. [219.106.231.132]) by smtp.googlemail.com with ESMTPSA id 72sm11981606pfk.28.2016.01.27.18.47.30 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 27 Jan 2016 18:47:31 -0800 (PST) To: "Xie, Huawei" , "dev@dpdk.org" , "yuanhan.liu@linux.intel.com" , "Tan, Jianfeng" References: <1453108389-21006-2-git-send-email-mukawa@igel.co.jp> <1453374478-30996-6-git-send-email-mukawa@igel.co.jp> From: Tetsuya Mukawa X-Enigmail-Draft-Status: N1110 Message-ID: <56A98140.2000507@igel.co.jp> Date: Thu, 28 Jan 2016 11:47:28 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [RFC PATCH 5/5] virtio: Extend virtio-net PMD to support container environment X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jan 2016 02:47:33 -0000 On 2016/01/28 0:58, Xie, Huawei wrote: > On 1/21/2016 7:09 PM, Tetsuya Mukawa wrote: > [snip] >> + >> +static int >> +qtest_raw_recv(int fd, char *buf, size_t count) >> +{ >> + size_t len = count; >> + size_t total_len = 0; >> + int ret = 0; >> + >> + while (len > 0) { >> + ret = read(fd, buf, len); >> + if (ret == (int)len) >> + break; >> + if (*(buf + ret - 1) == '\n') >> + break; > The above two lines should be put after the below if block. Yes, it should be so. > >> + if (ret == -1) { >> + if (errno == EINTR) >> + continue; >> + return ret; >> + } >> + total_len += ret; >> + buf += ret; >> + len -= ret; >> + } >> + return total_len + ret; >> +} >> + > [snip] > >> + >> +static void >> +qtest_handle_one_message(struct qtest_session *s, char *buf) >> +{ >> + int ret; >> + >> + if (strncmp(buf, interrupt_message, strlen(interrupt_message)) == 0) { >> + if (rte_atomic16_read(&s->enable_intr) == 0) >> + return; >> + >> + /* relay interrupt to pipe */ >> + ret = write(s->irqfds.writefd, "1", 1); >> + if (ret < 0) >> + rte_panic("cannot relay interrupt\n"); >> + } else { >> + /* relay normal message to pipe */ >> + ret = qtest_raw_send(s->msgfds.writefd, buf, strlen(buf)); >> + if (ret < 0) >> + rte_panic("cannot relay normal message\n"); >> + } >> +} >> + >> +static char * >> +qtest_get_next_message(char *p) >> +{ >> + p = strchr(p, '\n'); >> + if ((p == NULL) || (*(p + 1) == '\0')) >> + return NULL; >> + return p + 1; >> +} >> + >> +static void >> +qtest_close_one_socket(int *fd) >> +{ >> + if (*fd > 0) { >> + close(*fd); >> + *fd = -1; >> + } >> +} >> + >> +static void >> +qtest_close_sockets(struct qtest_session *s) >> +{ >> + qtest_close_one_socket(&s->qtest_socket); >> + qtest_close_one_socket(&s->msgfds.readfd); >> + qtest_close_one_socket(&s->msgfds.writefd); >> + qtest_close_one_socket(&s->irqfds.readfd); >> + qtest_close_one_socket(&s->irqfds.writefd); >> + qtest_close_one_socket(&s->ivshmem_socket); >> +} >> + >> +/* >> + * This thread relays QTest response using pipe. >> + * The function is needed because we need to separate IRQ message from others. >> + */ >> +static void * >> +qtest_event_handler(void *data) { >> + struct qtest_session *s = (struct qtest_session *)data; >> + char buf[1024]; >> + char *p; >> + int ret; >> + >> + for (;;) { >> + memset(buf, 0, sizeof(buf)); >> + ret = qtest_raw_recv(s->qtest_socket, buf, sizeof(buf)); >> + if (ret < 0) { >> + qtest_close_sockets(s); >> + return NULL; >> + } >> + >> + /* may receive multiple messages at the same time */ > From the qtest_raw_recv implementation, if at some point one message is > received by two qtest_raw_recv calls, then is that message discarded? > We could save the last incomplete message in buffer, and combine the > message received next time together. I guess we don't lose replies from QEMU. Please let me describe more. According to the qtest specification, after sending a message, we need to receive a reply like below. APP: ---command---> QEMU APP: <-----------OK---- QEMU But, to handle interrupt message, we need to take care below case. APP: ---command---> QEMU APP: <---interrupt---- QEMU APP: <-----------OK---- QEMU Also, we need to handle a case like multiple threads tries to send a qtest message. Anyway, here is current implementation. So far, we have 3 types of sockets. 1. socket for qtest messaging. 2. socket for relaying normal message. 3. socket for relaying interrupt message. About read direction: The qtest socket is only read by "qtest_event_handler". The handler may receive multiple messages at once. In the case, the handler split messages, and send it to normal message socket or interrupt message socket. About write direction: The qtest socket will be written by below functions. - qtest_raw_in/out - qtest_raw_read/write But all functions that use above functions need to have mutex before sending messages. So all messaging will not be overlapped, then only one thread will read the socket for relaying normal message. Tetsuya