From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f173.google.com (mail-pf0-f173.google.com [209.85.192.173]) by dpdk.org (Postfix) with ESMTP id D9E28C386 for ; Thu, 28 Jan 2016 10:53:18 +0100 (CET) Received: by mail-pf0-f173.google.com with SMTP id o185so16444440pfb.1 for ; Thu, 28 Jan 2016 01:53:18 -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=4h57MKb4Vw8lYekTfQphIv0xzzbrm1qCi065effqkDA=; b=KAGV+ldZV/yYPrAStCUKEWImtpppH3mpnge6/4t/unUl73B+XEk5dF2MxL74CfFh37 IWJpgABSfZOOpIa+7xLhJffnWabNBiDmUUAAI70kW7CSuJUi4wfRFQmMuUI+S0G4rdzF g0X+NttAjSGrbXsHGxXqAJUW7PMTXUH9+mwKxo2jADZ1lUOsCCGCmU8y1ro6bH57WIDa /a741QlkvsNpdBng7lYs92oXGkmU6jHvjPW/HhwPDnyPimS4/qaM83xvDpdabTsuqKtG y0MkyULx2NLeK3o3FTmKDzmCfXEUvVW8FKD8QEi2NqLHF8ihEoZE3HBjrhUd1k7+j0GP 9qhA== 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=4h57MKb4Vw8lYekTfQphIv0xzzbrm1qCi065effqkDA=; b=R0zDTw7wQFXYFTGp22R+lBr8+CjXyXYlcz0Dw5JxuEU/6CoL0mxcMHctXRcnv7d5ff AhNR5N5uY6MNr/17RdmZHw6WGHhHJGB3hfYClc6Pfna36HVomifb8ILR43vtrrb6LIOK k6KiGD5ouFG7jig0ISuMa4Hj6BuhLkh5JAeYgaxKxmayw0KOvPpiOSlaN6cUgTweLNBa NqKBT7nrr6+mGrSTAE8L0G6kuuB+SJaSKyY70IKlBzDXE9U0nc4pBeJUdOhyY0X2dA6m L2okDGYoxH58wWIfNfR+PXFRJN9ccbiS5d3A2BeSs0J4Dpi/+5agPtM8bKzLrZGcDC9b 90uQ== X-Gm-Message-State: AG10YOQ14vuYcx+HCb17yMV2OXx3hyFYIbRGI8QZlfHJb+AlHqxrslygIu4Yu0qcTAHWdA== X-Received: by 10.98.74.71 with SMTP id x68mr3140970pfa.80.1453974798322; Thu, 28 Jan 2016 01:53:18 -0800 (PST) Received: from [10.16.129.101] (napt.igel.co.jp. [219.106.231.132]) by smtp.googlemail.com with ESMTPSA id p70sm14914589pfi.96.2016.01.28.01.53.16 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Jan 2016 01:53:17 -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> <56A98140.2000507@igel.co.jp> From: Tetsuya Mukawa Message-ID: <56A9E50A.9050203@igel.co.jp> Date: Thu, 28 Jan 2016 18:53:14 +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 09:53:19 -0000 On 2016/01/28 18:48, Xie, Huawei wrote: > On 1/28/2016 10:47 AM, Tetsuya Mukawa wrote: >> 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. > I think there are two assumptions that all messages are ended with "\n" > and the sizeof(buf) could hold the maximum length of sum of all multiple > messages that QEMU could send at one time. > Otherwise in the last read call of qtest_raw_receive, you might receive > only part of the a message. I've got your point. I will fix above case. Thanks, Tetsuya