Transform the vhost example to two parts: vhost library and example.
cover Transform the vhost example to two parts: vhost library and example.
This transform is to facilitate integration with DPDK accelerated ethernet switch.
Huawei Xie (3):
remove vhost example
vhost library support to facilitate integration with DPDK accelerated
vswitch
This vhost example is based on vhost library. Besides, -
This patch fixes hundreds of 80 character limitation issues.
- Use structure assignment rather than memcpy in get_eth_conf
according to Stephen's comments.
config/common_linuxapp | 7 + examples/vhost/Makefile | 10 +- examples/vhost/eventfd_link/Makefile | 39 - examples/vhost/eventfd_link/eventfd_link.c | 205 --- examples/vhost/eventfd_link/eventfd_link.h | 79 - examples/vhost/libvirt/qemu-wrap.py | 5 +- examples/vhost/main.c | 2205 ++++++++++---------------- examples/vhost/main.h | 85 +- examples/vhost/vhost-net-cdev.c | 367 ----- examples/vhost/vhost-net-cdev.h | 83 - examples/vhost/virtio-net.c | 1165 -------------- examples/vhost/virtio-net.h | 161 -- lib/Makefile | 1 + lib/librte_vhost/Makefile | 48 + lib/librte_vhost/eventfd_link/Makefile | 39 + lib/librte_vhost/eventfd_link/eventfd_link.c | 196 +++ lib/librte_vhost/eventfd_link/eventfd_link.h | 40 + lib/librte_vhost/rte_virtio_net.h | 222 +++ lib/librte_vhost/vhost-net-cdev.c | 394 +++++ lib/librte_vhost/vhost-net-cdev.h | 119 ++ lib/librte_vhost/vhost_rxtx.c | 316 ++++ lib/librte_vhost/virtio-net.c | 1113 +++++++++++++ mk/rte.app.mk | 5 + 23 files changed, 3371 insertions(+), 3533 deletions(-) delete mode 100644 examples/vhost/eventfd_link/Makefile delete mode 100644 examples/vhost/eventfd_link/eventfd_link.c delete mode 100644 examples/vhost/eventfd_link/eventfd_link.h mode change 100755 => 100644 examples/vhost/libvirt/qemu-wrap.py delete mode 100644 examples/vhost/vhost-net-cdev.c delete mode 100644 examples/vhost/vhost-net-cdev.h delete mode 100644 examples/vhost/virtio-net.c delete mode 100644 examples/vhost/virtio-net.h create mode 100644 lib/librte_vhost/Makefile create mode 100644 lib/librte_vhost/eventfd_link/Makefile create mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.c create mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.h create mode 100644 lib/librte_vhost/rte_virtio_net.h create mode 100644 lib/librte_vhost/vhost-net-cdev.c create mode 100644 lib/librte_vhost/vhost-net-cdev.h create mode 100644 lib/librte_vhost/vhost_rxtx.c create mode 100644 lib/librte_vhost/virtio-net.c
Signature · 1 line
1.8.1.4
PATCH 1/3 examples/vhost: remove vhost example
In reply to a message not in the archive--- examples/vhost/Makefile | 60 - examples/vhost/eventfd_link/Makefile | 39 - examples/vhost/eventfd_link/eventfd_link.c | 205 -- examples/vhost/eventfd_link/eventfd_link.h | 79 - examples/vhost/libvirt/qemu-wrap.py | 367 --- examples/vhost/main.c | 3722 ---------------------------- examples/vhost/main.h | 86 - examples/vhost/vhost-net-cdev.c | 367 --- examples/vhost/vhost-net-cdev.h | 83 - examples/vhost/virtio-net.c | 1165 --------- examples/vhost/virtio-net.h | 161 -- 11 files changed, 6334 deletions(-) delete mode 100644 examples/vhost/Makefile delete mode 100644 examples/vhost/eventfd_link/Makefile delete mode 100644 examples/vhost/eventfd_link/eventfd_link.c delete mode 100644 examples/vhost/eventfd_link/eventfd_link.h delete mode 100755 examples/vhost/libvirt/qemu-wrap.py delete mode 100644 examples/vhost/main.c delete mode 100644 examples/vhost/main.h delete mode 100644 examples/vhost/vhost-net-cdev.c delete mode 100644 examples/vhost/vhost-net-cdev.h delete mode 100644 examples/vhost/virtio-net.c delete mode 100644 examples/vhost/virtio-net.h
examples/vhost/Makefile deleted +0 -60
@@ -1,60 +0,0 @@ -# BSD LICENSE -# -# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Intel Corporation nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -ifeq ($(RTE_SDK),) -$(error "Please define RTE_SDK environment variable") -endif - -# Default target, can be overriden by command line or environment -RTE_TARGET ?= x86_64-native-linuxapp-gcc - -include $(RTE_SDK)/mk/rte.vars.mk - -ifneq ($(CONFIG_RTE_EXEC_ENV),"linuxapp") -$(info This application can only operate in a linuxapp environment, \ -please change the definition of the RTE_TARGET environment variable) -all: -else - -# binary name -APP = vhost-switch - -# all source are stored in SRCS-y -#SRCS-y := cusedrv.c loopback-userspace.c -SRCS-y := main.c virtio-net.c vhost-net-cdev.c - -CFLAGS += -O2 -I/usr/local/include -D_FILE_OFFSET_BITS=64 -Wno-unused-parameter -CFLAGS += $(WERROR_FLAGS) -LDFLAGS += -lfuse - -include $(RTE_SDK)/mk/rte.extapp.mk - -endif
examples/vhost/eventfd_link/Makefile deleted +0 -39
@@ -1,39 +0,0 @@ -# BSD LICENSE -# -# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# * Neither the name of Intel Corporation nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -obj-m += eventfd_link.o - - -all: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules - -clean: - make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
examples/vhost/eventfd_link/eventfd_link.c deleted +0 -205
205 lines not on this page · raw message
examples/vhost/eventfd_link/eventfd_link.h deleted +0 -79
79 lines not on this page · raw message
examples/vhost/libvirt/qemu-wrap.py deleted +0 -367
367 lines not on this page · raw message
examples/vhost/main.c deleted +0 -3722
2,250 lines not on this page · raw message
examples/vhost/main.h deleted +0 -86
86 lines not on this page · raw message
examples/vhost/vhost-net-cdev.c deleted +0 -367
367 lines not on this page · raw message
examples/vhost/vhost-net-cdev.h deleted +0 -83
83 lines not on this page · raw message
examples/vhost/virtio-net.c deleted +0 -1165
1,165 lines not on this page · raw message
examples/vhost/virtio-net.h deleted +0 -161
161 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.1.4
Part of the diff is not shown here. View the raw message.
PATCH 2/3 lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitch
In reply to a message not in the archiveThis library is turned off by default so that it doesn't break build on default system. Install fuse development library and turn it on.
--- config/common_linuxapp | 7 + lib/Makefile | 1 + lib/librte_vhost/Makefile | 48 ++ lib/librte_vhost/eventfd_link/Makefile | 39 + lib/librte_vhost/eventfd_link/eventfd_link.c | 196 +++++ lib/librte_vhost/eventfd_link/eventfd_link.h | 40 + lib/librte_vhost/rte_virtio_net.h | 222 +++++ lib/librte_vhost/vhost-net-cdev.c | 394 +++++++++ lib/librte_vhost/vhost-net-cdev.h | 119 +++ lib/librte_vhost/vhost_rxtx.c | 316 ++++++++ lib/librte_vhost/virtio-net.c | 1113 ++++++++++++++++++++++++++ mk/rte.app.mk | 5 + 12 files changed, 2500 insertions(+) create mode 100644 lib/librte_vhost/Makefile create mode 100644 lib/librte_vhost/eventfd_link/Makefile create mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.c create mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.h create mode 100644 lib/librte_vhost/rte_virtio_net.h create mode 100644 lib/librte_vhost/vhost-net-cdev.c create mode 100644 lib/librte_vhost/vhost-net-cdev.h create mode 100644 lib/librte_vhost/vhost_rxtx.c create mode 100644 lib/librte_vhost/virtio-net.c
config/common_linuxapp +7 -0
@@ -390,6 +390,13 @@ CONFIG_RTE_KNI_VHOST_DEBUG_RX=n CONFIG_RTE_KNI_VHOST_DEBUG_TX=n # +# Compile vhost library +# fuse, fuse-devel, kernel-modules-extra packages are needed +# +CONFIG_RTE_LIBRTE_VHOST=n +CONFIG_RTE_LIBRTE_VHOST_DEBUG=n + +# #Compile Xen domain0 support # CONFIG_RTE_LIBRTE_XEN_DOM0=n
lib/Makefile +1 -0
@@ -60,6 +60,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_METER) += librte_meter DIRS-$(CONFIG_RTE_LIBRTE_SCHED) += librte_sched DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs DIRS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += librte_distributor +DIRS-$(CONFIG_RTE_LIBRTE_VHOST) += librte_vhost DIRS-$(CONFIG_RTE_LIBRTE_PORT) += librte_port DIRS-$(CONFIG_RTE_LIBRTE_TABLE) += librte_table DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += librte_pipeline
lib/librte_vhost/Makefile new file +48 -0
48 lines not on this page · raw message
lib/librte_vhost/eventfd_link/Makefile new file +39 -0
@@ -0,0 +1,39 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +obj-m += eventfd_link.o + + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules + +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
lib/librte_vhost/eventfd_link/eventfd_link.c new file +196 -0
196 lines not on this page · raw message
lib/librte_vhost/eventfd_link/eventfd_link.h new file +40 -0
@@ -0,0 +1,40 @@ +/*- +* GPL LICENSE SUMMARY +* +* Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; If not, see <http://www.gnu.org/licenses/>. +* The full GNU General Public License is included in this distribution +* in the file called LICENSE.GPL. +* +* Contact Information: +* Intel Corporation +*/ + +#ifndef _EVENTFD_LINK_H_ +#define _EVENTFD_LINK_H_ + +/* +* ioctl to copy an fd entry in calling process to an fd in a target process +*/ +#define EVENTFD_COPY 1 + +/* +* arguements for the EVENTFD_COPY ioctl +*/ +struct eventfd_copy { +unsigned target_fd;/**< fd in the target pid */ +unsigned source_fd;/**< fd in the calling pid */ +pid_t target_pid;/**< pid of the target pid */ +}; +#endif /* _EVENTFD_LINK_H_ */
lib/librte_vhost/rte_virtio_net.h new file +222 -0
222 lines not on this page · raw message
lib/librte_vhost/vhost-net-cdev.c new file +394 -0
394 lines not on this page · raw message
lib/librte_vhost/vhost-net-cdev.h new file +119 -0
119 lines not on this page · raw message
lib/librte_vhost/vhost_rxtx.c new file +316 -0
316 lines not on this page · raw message
lib/librte_vhost/virtio-net.c new file +1113 -0
1,113 lines not on this page · raw message
mk/rte.app.mk +5 -0
@@ -190,6 +190,11 @@ ifeq ($(CONFIG_RTE_LIBRTE_VIRTIO_PMD),y) LDLIBS += -lrte_pmd_virtio_uio endif +ifeq ($(CONFIG_RTE_LIBRTE_VHOST), y) +LDLIBS += -lrte_vhost +LDLIBS += -lfuse +endif + ifeq ($(CONFIG_RTE_LIBRTE_I40E_PMD),y) LDLIBS += -lrte_pmd_i40e endif
Signature · 1 line
1.8.1.4
PATCH 3/3 examples/vhost: vhost example based on vhost library.
In reply to a message not in the archive--- examples/vhost/Makefile | 52 + examples/vhost/libvirt/qemu-wrap.py | 366 ++++ examples/vhost/main.c | 3145 +++++++++++++++++++++++++++++++++++ examples/vhost/main.h | 109 ++ 4 files changed, 3672 insertions(+) create mode 100644 examples/vhost/Makefile create mode 100644 examples/vhost/libvirt/qemu-wrap.py create mode 100644 examples/vhost/main.c create mode 100644 examples/vhost/main.h
examples/vhost/Makefile new file +52 -0
@@ -0,0 +1,52 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overriden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +# binary name +APP = vhost-switch + +# all source are stored in SRCS-y +#SRCS-y := cusedrv.c loopback-userspace.c +SRCS-y := main.c + +CFLAGS += -O2 -I/usr/local/include -D_FILE_OFFSET_BITS=64 -Wno-unused-parameter +CFLAGS += $(WERROR_FLAGS) +LDFLAGS += -lfuse + +include $(RTE_SDK)/mk/rte.extapp.mk
examples/vhost/libvirt/qemu-wrap.py new file +366 -0
366 lines not on this page · raw message
examples/vhost/main.c new file +3145 -0
2,582 lines not on this page · raw message
examples/vhost/main.h new file +109 -0
109 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.1.4
Part of the diff is not shown here. View the raw message.
Hi Huawei,
2014-09-02 16:55, Huawei Xie:
Quoted 10 lines
This transform is to facilitate integration with DPDK accelerated ethernet switch.
Huawei Xie (3):
remove vhost example
vhost library support to facilitate integration with DPDK accelerated
vswitch
This vhost example is based on vhost library. Besides, -
This patch fixes hundreds of 80 character limitation issues.
- Use structure assignment rather than memcpy inget_eth_conf
according to Stephen's comments.
My previous comment was:
"
It would help if you made a first patch to move existing code, another patch to convert it into a lib, and a last one for the new example.
So it would show how you transform the old example code and would be easier to review.
"
I mean your first patch would be some simple code moving without any change. Git handles move and shows it clearly, so it's really easy to review.
Then your second patch would include the changes you made to make it a library. In this patchset we cannot see them because all is seen as new code.
Thanks
Signature · 1 line
Thomas
Re: [PATCH 2/3] lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitch
In reply to a message not in the archiveHi Huawei,
I added few comments. Mainly those comments are about source code indent.
Quoted 68 lines · Huawei Xie
lib/librte_vhost/rte_virtio_net.h new file +68
-0+ +/** +* Structure contains variables relevant to RX/TX virtqueues. +*/ +struct vhost_virtqueue { +/**< descriptor ring. */ +struct vring_desc *desc; +/**< available ring. */ +struct vring_avail *avail; +/**< used ring. */ +struct vring_used *used; +/**< Size of descriptor ring. */ +uint32_t size; +/**< Backend value to determine if device should be started/stopped. */ +uint32_t backend; +/**< Vhost header length (varies depending on RX merge buffers. */ +uint16_t vhost_hlen; +/**< Last index used on the available ring. */ +volatile uint16_t last_used_idx; +/**< Used for multiple devices reserving buffers. */ +volatile uint16_t last_used_idx_res; +/**< Currently unused as polling mode is enabled. */ +eventfd_t callfd; +/**< Used to notify the guest (trigger interrupt). */ +eventfd_t kickfd; +} __rte_cache_aligned; + +/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct virtio_memory_regions { +/**< Base guest physical address of region. */ +uint64_t guest_phys_address; +/**< End guest physical address of region. */ +uint64_t guest_phys_address_end; +/**< Size of region. */ +uint64_t memory_size; +/**< Base userspace address of region. */ +uint64_t userspace_address; +/**< Offset of region for address translation. */ +uint64_t address_offset; +}; + + +/** +* Memory structure includes region and mapping information. +*/ +struct virtio_memory { +/**< Base QEMU userspace address of the memory file. */ +uint64_t base_address; +/**< Mapped address of memory file in this process's memory space. */ +uint64_t mapped_address; +/**< Total size of memory file. */ +uint64_t mapped_size; +/**< Number of memory regions. */ +uint32_t nregions; +/**< Memory region information. */ +struct virtio_memory_regions regions[0 ]; +}; + +/** +* Device structure contains all configuration information relating to the device. +*/ +struct virtio_net { +/**< Contains all virtqueue information. */ +struct vhost_virtqueue *virtqueue[VIRTIO_QNUM ]; +/**< QEMU memory and memory region information. */
lib/librte_vhost/rte_virtio_net.h line 130
Quoted 10 lines
lib/librte_vhost/rte_virtio_net.h new file +10
-0+struct virtio_memory *mem; +/**< Negotiated feature set. */ +uint64_t features; +/**< Device identifier. */ +uint64_t device_fh; +/**< Device flags, used to check if device is running on data core. */ +uint32_t flags; +void *priv; +} __rte_cache_aligned; +
Above comments of 'vhost_virtqueue', 'struct virtio_memory_regions', 'struct virtio-memory'
and 'struct virtio-net' will break API documentation created by Doxygen. Not to break, I guess those comment need to be placed after variable.
Quoted 11 lines
lib/librte_vhost/vhost-net-cdev.c new file +11
-0+/** +* cuse_info is populated and used to register the cuse device. +* vhost_net_device_ops is passed when the device is registered in main.c. +*/ +int +rte_vhost_driver_register (const char *dev_name) +{ +struct cuse_info cuse_info; +char device_name[PATH_MAX ] ="" ; +char char_device_name[PATH_MAX ] ="" ; +const char *device_argv[] = { device_name };
lib/librte_vhost/vhost-net-cdev.c line 345
Quoted 10 lines
lib/librte_vhost/vhost-net-cdev.c new file +10
-0+ +char fuse_opt_dummy[] =FUSE_OPT_DUMMY ; +char fuse_opt_fore[] =FUSE_OPT_FORE ; +char fuse_opt_nomulti[] =FUSE_OPT_NOMULTI ; +char *fuse_argv[] = {fuse_opt_dummy, fuse_opt_fore, fuse_opt_nomulti}; + +if (access (cuse_device_name,R_OK |W_OK ) <0 ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"Character device %s can't be accessed, maybe not exist\n" , + cuse_device_name);
Need one more indent?
Quoted 99 lines
lib/librte_vhost/virtio-net.c new file +99
-0+/** +* Locate the file containing QEMU's memory space and map it to our address space. +*/ +static int +host_memory_map (struct virtio_net *dev,struct virtio_memory *mem,pid_t pid, +uint64_t addr) +{ +struct dirent *dptr =NULL ; +struct procmap procmap; +DIR *dp =NULL ; +int fd; +int i; +char memfile[PATH_MAX ]; +char mapfile[PATH_MAX ]; +char procdir[PATH_MAX ]; +char resolved_path[PATH_MAX ]; +FILE *fmap; +void *map; +uint8_t found =0 ; +char line[BUFSIZE ]; +char dlm[] ="- : " ; +char *str, *sp, *in[PROCMAP_SZ ]; +char *end =NULL ; + +/* Path where mem files are located. */ +snprintf (procdir,PATH_MAX ,"/proc/%u/fd/" , pid); +/* Maps file used to locate mem file. */ +snprintf (mapfile,PATH_MAX ,"/proc/%u/maps" , pid); + + fmap =fopen (mapfile,"r" ); +if (fmap ==NULL ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to open maps file for pid %d\n" , + dev->device_fh, pid); +return -1 ; + } + +/* Read through maps file until we find out base_address. */ +while (fgets (line,BUFSIZE , fmap) !=0 ) { + str = line; + errno =0 ; +/* Split line in to fields. */ +for (i =0 ; i <PROCMAP_SZ ; i++) { + in[i] =strtok_r (str, &dlm[i], &sp); +if ((in[i] ==NULL ) || (errno !=0 )) { +fclose (fmap); +return -1 ; + } + str =NULL ; + } + +/* Convert/Copy each field as needed. */ + procmap.va_start =strtoull (in[0 ], &end,16 ); +if ((in[0 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.len =strtoull (in[1 ], &end,16 ); +if ((in[1 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.pgoff =strtoull (in[3 ], &end,16 ); +if ((in[3 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.maj =strtoul (in[4 ], &end,16 ); +if ((in[4 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.min =strtoul (in[5 ], &end,16 ); +if ((in[5 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.ino =strtoul (in[6 ], &end,16 ); +if ((in[6 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + +memcpy (&procmap.prot, in[2 ],PROT_SZ ); +memcpy (&procmap.fname, in[7 ],PATH_MAX ); + +if (procmap.va_start == addr) { + procmap.len = procmap.len - procmap.va_start;
lib/librte_vhost/virtio-net.c line 228
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ found =1 ; +break ; + } + } +fclose (fmap); + +if (!found) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to find memory file in pid %d maps file\n" , + dev->device_fh, pid);
Need one more indent?
lib/librte_vhost/virtio-net.c line 392
Quoted 13 lines
lib/librte_vhost/virtio-net.c new file +12
-0+/** +* Searches the configuration core linked list and retrieves the device if it exists. +*/ +static struct virtio_net * +get_device (struct vhost_device_ctx ctx) +{ +struct virtio_net_config_ll *ll_dev; + + ll_dev =get_config_ll_entry (ctx); + +/* If a matching entry is found in the linked list, return the device +* in that entry. */
Need a blank space at start of comment?
Quoted 16 lines
lib/librte_vhost/virtio-net.c new file +16
-0+if (ll_dev) +return &ll_dev->dev; + +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Device not found in linked list.\n" , ctx.fh); +return NULL ; +} + +/** +* Add entry containing a device to the device configuration linked list. +*/ +static void +add_config_ll_entry (struct virtio_net_config_ll *new_ll_dev) +{ +struct virtio_net_config_ll *ll_dev = ll_root; +
lib/librte_vhost/virtio-net.c line 418
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+/* If ll_dev == NULL then this is the first device so go to else */ +if (ll_dev) { +/* If the 1st device_fh != 0 then we insert our device here. */ +if (ll_dev->dev.device_fh !=0 ) { + new_ll_dev->dev.device_fh =0 ; + new_ll_dev->next = ll_dev; + ll_root = new_ll_dev; + }else { +/* Increment through the ll until we find un unused +* device_fh. Insert the device at that entry*/
Need a blank space at end of comment?
Quoted 6 lines
lib/librte_vhost/virtio-net.c new file +5
-0+/** +* Function is called from the CUSE release function. This function will cleanup +* the device and remove it from device configuration linked list. +*/ +static void
lib/librte_vhost/virtio-net.c line 532
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+destroy_device(struct vhost_device_ctx ctx) +{ +struct virtio_net_config_ll *ll_dev_cur_ctx, *ll_dev_last =NULL ; +struct virtio_net_config_ll *ll_dev_cur = ll_root; + +/* Find the linked list entry for the device to be removed. */ + ll_dev_cur_ctx =get_config_ll_entry (ctx); +while (ll_dev_cur !=NULL ) { +/* If the device is found or a device that doesn't exist is +* found then it is removed. */
Need a blank space?
Quoted 17 lines
lib/librte_vhost/virtio-net.c new file +17
-0+/** +* Called from CUSE IOCTL: VHOST_SET_FEATURES +* We receive the negotiated set of features supported by us and the virtio +* device. +*/ +static int +set_features (struct vhost_device_ctx ctx,uint64_t *pu) +{ +struct virtio_net *dev; + + dev =get_device (ctx); +if (dev ==NULL ) +return -1 ; +if (*pu & ~VHOST_FEATURES ) +return -1 ; + +/* Store the negotiated feature list for the device. */
lib/librte_vhost/virtio-net.c line 627
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ dev->features = *pu; + +/* Set the vhost_hlen depending on if VIRTIO_NET_F_MRG_RXBUF is set. */ +if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) { +LOG_DEBUG (VHOST_CONFIG , +"(%" PRIu64") Mergeable RX buffers enabled\n" , dev->device_fh); + dev->virtqueue[VIRTIO_RXQ ]->vhost_hlen = +sizeof (struct virtio_net_hdr_mrg_rxbuf ); + dev->virtqueue[VIRTIO_TXQ ]->vhost_hlen = +sizeof (struct virtio_net_hdr_mrg_rxbuf );
One more indent?
Quoted 54 lines
lib/librte_vhost/virtio-net.c new file +53
-0+/** +* Called from CUSE IOCTL: VHOST_SET_MEM_TABLE +* This function creates and populates the memory structure for the device. +* This includes storing offsets used to translate buffer addresses. +*/ +static int +set_mem_table (struct vhost_device_ctx ctx,const void *mem_regions_addr, +uint32_t nregions) +{ +struct virtio_net *dev; +struct vhost_memory_region *mem_regions; +struct virtio_memory *mem; +uint64_t size = offsetof(struct vhost_memory , regions); +uint32_t regionidx, valid_regions; + + dev =get_device (ctx); +if (dev ==NULL ) +return -1 ; + +if (dev->mem) { +munmap ((void *)(uintptr_t )dev->mem->mapped_address, + (size_t )dev->mem->mapped_size); +free (dev->mem); + } + +/* Malloc the memory structure depending on the number of regions. */ + mem =calloc (1 ,sizeof (struct virtio_memory ) + + (sizeof (struct virtio_memory_regions ) * nregions)); +if (mem ==NULL ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to allocate memory for dev->mem.\n" , + dev->device_fh); +return -1 ; + } + + mem->nregions = nregions; + + mem_regions = (void *)(uintptr_t ) + ((uint64_t )(uintptr_t )mem_regions_addr + size); + +for (regionidx =0 ; regionidx < mem->nregions; regionidx++) { +/* Populate the region structure for each region. */ + mem->regions[regionidx].guest_phys_address = + mem_regions[regionidx].guest_phys_addr; + mem->regions[regionidx].guest_phys_address_end = + mem->regions[regionidx].guest_phys_address + + mem_regions[regionidx].memory_size; + mem->regions[regionidx].memory_size = + mem_regions[regionidx].memory_size; + mem->regions[regionidx].userspace_address = + mem_regions[regionidx].userspace_addr; + + LOG_DEBUG(VHOST_CONFIG,
lib/librte_vhost/virtio-net.c line 703
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+"(%" PRIu64") REGION: %u - GPA: %p - QEMU VA: %p - SIZE " +"(%" PRIu64")\n" , + dev->device_fh, regionidx, + (void *)(uintptr_t ) + mem->regions[regionidx].guest_phys_address, + (void *)(uintptr_t ) + mem->regions[regionidx].userspace_address, + mem->regions[regionidx].memory_size); + +/*set the base address mapping*/
Need a blank space at start and end of comment?
Quoted 7 lines
lib/librte_vhost/virtio-net.c new file +7
-0+if (mem->regions[regionidx].guest_phys_address ==0x0 ) { + mem->base_address = + mem->regions[regionidx].userspace_address; +/* Map VM memory file */ +if (host_memory_map (dev, mem, ctx.pid, + mem->base_address) !=0 ) { +free (mem);
lib/librte_vhost/virtio-net.c line 720
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+return -1 ; + } + } + } + +/* Check that we have a valid base address. */ +if (mem->base_address ==0 ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to find base address of qemu memory " +"file.\n" , dev->device_fh);
One more indent?
lib/librte_vhost/virtio-net.c line 726
Quoted 6 lines
lib/librte_vhost/virtio-net.c new file +6
-0+free (mem); +return -1 ; + } + +/* Check if all of our regions have valid mappings. Usually one does +* not exist in the QEMU memory file. */
Need a blank space?
lib/librte_vhost/virtio-net.c line 737
Quoted 11 lines
lib/librte_vhost/virtio-net.c new file +11
-0+ valid_regions = mem->nregions; +for (regionidx =0 ; regionidx < mem->nregions; regionidx++) { +if ((mem->regions[regionidx].userspace_address < + mem->base_address) || + (mem->regions[regionidx].userspace_address > + (mem->base_address + mem->mapped_size))) + valid_regions--; + } + +/* If a region does not have a valid mapping we rebuild our memory +* struct to contain only valid entries. */
Need a blank space?
lib/librte_vhost/virtio-net.c line 741
Quoted 4 lines
lib/librte_vhost/virtio-net.c new file +4
-0+if (valid_regions != mem->nregions) { + LOG_DEBUG(VHOST_CONFIG, + "(%"PRIu64") Not all memory regions exist in the QEMU mem file." + "Re-populating mem structure\n",
One more indent?
lib/librte_vhost/virtio-net.c line 745
Quoted 4 lines
lib/librte_vhost/virtio-net.c new file +4
-0+ dev->device_fh); + +/* Re-populate the memory structure with only valid regions. +* Invalid regions are over-written with memmove. */
Need a blank space?
Thanks,
Tetsuya
Re: [PATCH 2/3] lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitch
In reply to a message not in the archiveThanks Tetsuya:
Some of them are due to 80 character limitation. Is it ok to break the limitation for better indentation?
Quoted 87 lines
-----Original Message-----
From: Tetsuya.Mukawa [mailto:mukawa-AlSX/UN32fvPDbFq/[email protected]]
Sent: Wednesday, September 03, 2014 11:39 AM
To: Xie, Huawei; [email protected]
Subject: Re: [dpdk-dev] [PATCH 2/3]lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitchHi Huawei,
I added few comments. Mainly those comments are about source code indent.
Quoted 53 lines · Huawei Xie
lib/librte_vhost/rte_virtio_net.h new file +53
-0+ +/** +* Structure contains variables relevant to RX/TX virtqueues. +*/ +struct vhost_virtqueue { +/**< descriptor ring. */ +struct vring_desc *desc; +/**< available ring. */ +struct vring_avail *avail; +/**< used ring. */ +struct vring_used *used; +/**< Size of descriptor ring. */ +uint32_t size; +/**< Backend value to determine if device should be started/stopped. */ +uint32_t backend; +/**< Vhost header length (varies depending on RX merge buffers. */ +uint16_t vhost_hlen; +/**< Last index used on the available ring. */ +volatile uint16_t last_used_idx; +/**< Used for multiple devices reserving buffers. */ +volatile uint16_t last_used_idx_res; +/**< Currently unused as polling mode is enabled. */ +eventfd_t callfd; +/**< Used to notify the guest (trigger interrupt). */ +eventfd_t kickfd; +} __rte_cache_aligned; + +/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct virtio_memory_regions { +/**< Base guest physical address of region. */ +uint64_t guest_phys_address; +/**< End guest physical address of region. */ +uint64_t guest_phys_address_end; +/**< Size of region. */ +uint64_t memory_size; +/**< Base userspace address of region. */ +uint64_t userspace_address; +/**< Offset of region for address translation. */ +uint64_t address_offset; +}; + + +/** +* Memory structure includes region and mapping information. +*/ +struct virtio_memory { +/**< Base QEMU userspace address of the memory file. */ +uint64_t base_address; +/**< Mapped address of memory file in this process's memory space. */ +uint64_t mapped_address;lib/librte_vhost/rte_virtio_net.h
Quoted 10 lines
lib/librte_vhost/rte_virtio_net.h new file +10
-0+/**< Total size of memory file. */ +uint64_t mapped_size; +/**< Number of memory regions. */ +uint32_t nregions; +/**< Memory region information. */ +struct virtio_memory_regions regions[0 ]; +}; + +/** +* Device structure contains all configuration information relating to the device.
Quoted 11 lines
+ */
lib/librte_vhost/rte_virtio_net.h new file +10
-0+struct virtio_net { +/**< Contains all virtqueue information. */ +struct vhost_virtqueue *virtqueue[VIRTIO_QNUM ]; +/**< QEMU memory and memory region information. */ +struct virtio_memory *mem; +/**< Negotiated feature set. */ +uint64_t features; +/**< Device identifier. */ +uint64_t device_fh; +/**< Device flags, used to check if device is running on data core. */
Quoted 8 lines
lib/librte_vhost/rte_virtio_net.h line 130
Quoted 4 lines
lib/librte_vhost/rte_virtio_net.h new file +4
-0+uint32_t flags; +void *priv; +} __rte_cache_aligned; +Above comments of '
vhost_virtqueue', 'structvirtio_memory_regions', 'struct virtio-memory'
and 'struct virtio-net' will break API documentation created by Doxygen. Not to break, I guess those comment need to be placed after variable.
Thanks. I will check doxgen rule. Moved the comment above to avoid 80 character limitation warning.
Quoted 18 lines
Quoted 7 lines
lib/librte_vhost/vhost-net-cdev.c new file +6
-0+/** +* cuse_info is populated and used to register the cuse device. +* vhost_net_device_ops is passed when the device is registered in main.c. +*/ +int +rte_vhost_driver_register (const char *dev_name)lib/librte_vhost/vhost-net-cdev.c
Quoted 10 lines
lib/librte_vhost/vhost-net-cdev.c new file +10
-0+{ +struct cuse_info cuse_info; +char device_name[PATH_MAX ] ="" ; +char char_device_name[PATH_MAX ] ="" ; +const char *device_argv[] = { device_name }; + +char fuse_opt_dummy[] =FUSE_OPT_DUMMY ; +char fuse_opt_fore[] =FUSE_OPT_FORE ; +char fuse_opt_nomulti[] =FUSE_OPT_NOMULTI ; +char *fuse_argv[] = {fuse_opt_dummy, fuse_opt_fore,
fuse_opt_nomulti};
Quoted 6 lines
lib/librte_vhost/vhost-net-cdev.c line 345
Quoted 5 lines
lib/librte_vhost/vhost-net-cdev.c new file +5
-0+ +if (access (cuse_device_name,R_OK |W_OK ) <0 ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"Character device %s can't be accessed, maybe not exist\n" , + cuse_device_name);Need one more indent?
Again to avoid 80 char warning for some lengthy RTE_LOG.
Quoted 149 lines
Quoted 3 lines
+/**
+ * Locate the file containing QEMU's memory space and map it to ouraddress space.
Review
Quoted 3 lines
+ */
(quoted diff) +2
-0+static int +host_memory_map(struct virtio_net *dev, struct virtio_memory *mem, pid_tpid,
Quoted 94 lines
lib/librte_vhost/virtio-net.c new file +94
-0+ uint64_t addr) +{ +struct dirent *dptr =NULL ; +struct procmap procmap; +DIR *dp =NULL ; +int fd; +int i; +char memfile[PATH_MAX ]; +char mapfile[PATH_MAX ]; +char procdir[PATH_MAX ]; +char resolved_path[PATH_MAX ]; +FILE *fmap; +void *map; +uint8_t found =0 ; +char line[BUFSIZE ]; +char dlm[] ="- : " ; +char *str, *sp, *in[PROCMAP_SZ ]; +char *end =NULL ; + +/* Path where mem files are located. */ +snprintf (procdir,PATH_MAX ,"/proc/%u/fd/" , pid); +/* Maps file used to locate mem file. */ +snprintf (mapfile,PATH_MAX ,"/proc/%u/maps" , pid); + + fmap =fopen (mapfile,"r" ); +if (fmap ==NULL ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to open maps file for pid %d\n" , + dev->device_fh, pid); +return -1 ; + } + +/* Read through maps file until we find out base_address. */ +while (fgets (line,BUFSIZE , fmap) !=0 ) { + str = line; + errno =0 ; +/* Split line in to fields. */ +for (i =0 ; i <PROCMAP_SZ ; i++) { + in[i] =strtok_r (str, &dlm[i], &sp); +if ((in[i] ==NULL ) || (errno !=0 )) { +fclose (fmap); +return -1 ; + } + str =NULL ; + } + +/* Convert/Copy each field as needed. */ + procmap.va_start =strtoull (in[0 ], &end,16 ); +if ((in[0 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.len =strtoull (in[1 ], &end,16 ); +if ((in[1 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.pgoff =strtoull (in[3 ], &end,16 ); +if ((in[3 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.maj =strtoul (in[4 ], &end,16 ); +if ((in[4 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.min =strtoul (in[5 ], &end,16 ); +if ((in[5 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.ino =strtoul (in[6 ], &end,16 ); +if ((in[6 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + +memcpy (&procmap.prot, in[2 ],PROT_SZ ); +memcpy (&procmap.fname, in[7 ],PATH_MAX ); + +if (procmap.va_start == addr) { + procmap.len = procmap.len - procmap.va_start;lib/librte_vhost/virtio-net.c line 228
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ found =1 ; +break ; + } + } +fclose (fmap); + +if (!found) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to find memory file in pid %d maps file\n" , + dev->device_fh, pid);Need one more indent?
Quoted 3 lines
+/**
+ * Searches the configuration core linked list and retrieves the device if itexists.
lib/librte_vhost/virtio-net.c line 392
Quoted 10 lines
+ */
lib/librte_vhost/virtio-net.c new file +9
-0+static struct virtio_net * +get_device (struct vhost_device_ctx ctx) +{ +struct virtio_net_config_ll *ll_dev; + + ll_dev =get_config_ll_entry (ctx); + +/* If a matching entry is found in the linked list, return the device +* in that entry. */ Need a blank space at start of comment?
Quoted 19 lines
lib/librte_vhost/virtio-net.c new file +19
-0+if (ll_dev) +return &ll_dev->dev; + +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Device not found in linked list.\n" , ctx.fh); +return NULL ; +} + +/** +* Add entry containing a device to the device configuration linked list. +*/ +static void +add_config_ll_entry (struct virtio_net_config_ll *new_ll_dev) +{ +struct virtio_net_config_ll *ll_dev = ll_root; + +/* If ll_dev == NULL then this is the first device so go to else */ +if (ll_dev) { +/* If the 1st device_fh != 0 then we insert our device here. */
Quoted 8 lines
lib/librte_vhost/virtio-net.c line 418
Quoted 7 lines
lib/librte_vhost/virtio-net.c new file +7
-0+if (ll_dev->dev.device_fh !=0 ) { + new_ll_dev->dev.device_fh =0 ; + new_ll_dev->next = ll_dev; + ll_root = new_ll_dev; + }else { +/* Increment through the ll until we find un unused +* device_fh. Insert the device at that entry*/ Need a blank space at end of comment?
Will fix.
Quoted 5 lines
Quoted 4 lines
+/**
+ * Function is called from the CUSE release function. This function willcleanup
Quoted 14 lines
lib/librte_vhost/virtio-net.c line 532
Quoted 13 lines
+ * the device and remove it from device configuration linked list.
+ */lib/librte_vhost/virtio-net.c new file +11
-0+static void +destroy_device (struct vhost_device_ctx ctx) +{ +struct virtio_net_config_ll *ll_dev_cur_ctx, *ll_dev_last =NULL ; +struct virtio_net_config_ll *ll_dev_cur = ll_root; + +/* Find the linked list entry for the device to be removed. */ + ll_dev_cur_ctx =get_config_ll_entry (ctx); +while (ll_dev_cur !=NULL ) { +/* If the device is found or a device that doesn't exist is +* found then it is removed. */ Need a blank space?
Will fix.
Quoted 88 lines
Quoted 11 lines
lib/librte_vhost/virtio-net.c new file +10
-0+/** +* Called from CUSE IOCTL: VHOST_SET_FEATURES +* We receive the negotiated set of features supported by us and the virtio +* device. +*/ +static int +set_features (struct vhost_device_ctx ctx,uint64_t *pu) +{ +struct virtio_net *dev; +lib/librte_vhost/virtio-net.c
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ dev =get_device (ctx); +if (dev ==NULL ) +return -1 ; +if (*pu & ~VHOST_FEATURES ) +return -1 ; + +/* Store the negotiated feature list for the device. */ + dev->features = *pu; + +/* Set the vhost_hlen depending on if VIRTIO_NET_F_MRG_RXBUF is set. */
lib/librte_vhost/virtio-net.c line 627
Quoted 7 lines
lib/librte_vhost/virtio-net.c new file +7
-0+if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) { +LOG_DEBUG (VHOST_CONFIG , +"(%" PRIu64") Mergeable RX buffers enabled\n" , dev->device_fh); + dev->virtqueue[VIRTIO_RXQ ]->vhost_hlen = +sizeof (struct virtio_net_hdr_mrg_rxbuf ); + dev->virtqueue[VIRTIO_TXQ ]->vhost_hlen = +sizeof (struct virtio_net_hdr_mrg_rxbuf );One more indent?
Quoted 46 lines
lib/librte_vhost/virtio-net.c new file +31
-0+/** + * Called from CUSE IOCTL: VHOST_SET_MEM_TABLE + * This function creates and populates the memory structure for the device. + * This includes storing offsets used to translate buffer addresses. + */ +static int +set_mem_table(struct vhost_device_ctx ctx, const void *mem_regions_addr, + uint32_t nregions) +{ + struct virtio_net *dev; + struct vhost_memory_region *mem_regions; + struct virtio_memory *mem; + uint64_t size = offsetof(struct vhost_memory, regions); + uint32_t regionidx, valid_regions; + + dev = get_device(ctx); + if (dev == NULL) + return -1; + + if (dev->mem) { + munmap((void *)(uintptr_t)dev->mem->mapped_address, + (size_t)dev->mem->mapped_size); + free(dev->mem); + } + + /* Malloc the memory structure depending on the number of regions. */ + mem = calloc(1, sizeof(struct virtio_memory) + + (sizeof(struct virtio_memory_regions) * nregions)); + if (mem == NULL) { + RTE_LOG(ERR, VHOST_CONFIG, + "(%"PRIu64") Failed to allocate memory for dev-mem.\n",
lib/librte_vhost/virtio-net.c new file +13
-0+ dev->device_fh); +return -1 ; + } + + mem->nregions = nregions; + + mem_regions = (void *)(uintptr_t ) + ((uint64_t )(uintptr_t )mem_regions_addr + size); + +for (regionidx =0 ; regionidx < mem->nregions; regionidx++) { +/* Populate the region structure for each region. */ + mem->regions[regionidx].guest_phys_address = + mem_regions[regionidx].guest_phys_addr;lib/librte_vhost/virtio-net.c
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ mem->regions[regionidx].guest_phys_address_end = + mem->regions[regionidx].guest_phys_address + + mem_regions[regionidx].memory_size; + mem->regions[regionidx].memory_size = + mem_regions[regionidx].memory_size; + mem->regions[regionidx].userspace_address = + mem_regions[regionidx].userspace_addr; + +LOG_DEBUG (VHOST_CONFIG , + "(%"PRIu64") REGION: %u - GPA: %p - QEMU VA: %p -SIZE "
Quoted 10 lines
lib/librte_vhost/virtio-net.c line 703
Quoted 9 lines
lib/librte_vhost/virtio-net.c new file +9
-0+"(%" PRIu64")\n" , + dev->device_fh, regionidx, + (void *)(uintptr_t ) + mem->regions[regionidx].guest_phys_address, + (void *)(uintptr_t ) + mem->regions[regionidx].userspace_address, + mem->regions[regionidx].memory_size); + +/*set the base address mapping*/ Need a blank space at start and end of comment?
Thanks for careful review.
Quoted 55 lines
Quoted 8 lines
lib/librte_vhost/virtio-net.c new file +7
-0+if (mem->regions[regionidx].guest_phys_address ==0x0 ) { + mem->base_address = + mem->regions[regionidx].userspace_address; +/* Map VM memory file */ +if (host_memory_map (dev, mem, ctx.pid, + mem->base_address) !=0 ) { +free (mem);lib/librte_vhost/virtio-net.c line 720
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+return -1 ; + } + } + } + +/* Check that we have a valid base address. */ +if (mem->base_address ==0 ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to find base address of qemu memory " +"file.\n" , dev->device_fh);One more indent?
lib/librte_vhost/virtio-net.c line 726
Quoted 6 lines
lib/librte_vhost/virtio-net.c new file +6
-0+free (mem); +return -1 ; + } + +/* Check if all of our regions have valid mappings. Usually one does +* not exist in the QEMU memory file. */ Need a blank space?
lib/librte_vhost/virtio-net.c line 737
Quoted 11 lines
lib/librte_vhost/virtio-net.c new file +11
-0+ valid_regions = mem->nregions; +for (regionidx =0 ; regionidx < mem->nregions; regionidx++) { +if ((mem->regions[regionidx].userspace_address < + mem->base_address) || + (mem->regions[regionidx].userspace_address > + (mem->base_address + mem->mapped_size))) + valid_regions--; + } + +/* If a region does not have a valid mapping we rebuild our memory +* struct to contain only valid entries. */ Need a blank space?
lib/librte_vhost/virtio-net.c
Quoted 3 lines
lib/librte_vhost/virtio-net.c new file +3
-0+ if (valid_regions != mem->nregions) { + LOG_DEBUG(VHOST_CONFIG, + "(%"PRIu64") Not all memory regions exist in the QEMU memfile."
lib/librte_vhost/virtio-net.c line 741
Quoted 1 line
lib/librte_vhost/virtio-net.c new file +1
-0+ "Re-populating mem structure\n",One more indent?
lib/librte_vhost/virtio-net.c line 745
Quoted 4 lines
lib/librte_vhost/virtio-net.c new file +4
-0+ dev->device_fh); + +/* Re-populate the memory structure with only valid regions. +* Invalid regions are over-written with memmove. */ Need a blank space?
Thanks,
Tetsuya
Re: [PATCH 2/3] lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitch
In reply to a message not in the archiveQuoted 2 lines · Huawei
Thanks Tetsuya:
Some of them are due to 80 character limitation. Is it ok to break the limitation for better indentation?
Many of these comments could just be removed or shortened. Often removing comments makes code clearer and less buggy, because there is no risk that comment does not match code.
Re: [PATCH 2/3] lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitch
In reply to a message not in the archiveQuoted 2 lines · Huawei
Thanks Tetsuya:
Some of them are due to 80 character limitation. Is it ok to break the limitation for better indentation?
It's is up to the cording style of dpdk. But, there may be no strict rule in dpdk.
So please use your original cord. :)
Thanks,
Tetsuya
Quoted 445 lines
Quoted 87 lines
-----Original Message-----
From: Tetsuya.Mukawa [mailto:mukawa-AlSX/UN32fvPDbFq/[email protected]]
Sent: Wednesday, September 03, 2014 11:39 AM
To: Xie, Huawei; [email protected]
Subject: Re: [dpdk-dev] [PATCH 2/3]lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitchHi Huawei,
I added few comments. Mainly those comments are about source code indent.
Quoted 53 lines · Huawei Xie
lib/librte_vhost/rte_virtio_net.h new file +53
-0+ +/** +* Structure contains variables relevant to RX/TX virtqueues. +*/ +struct vhost_virtqueue { +/**< descriptor ring. */ +struct vring_desc *desc; +/**< available ring. */ +struct vring_avail *avail; +/**< used ring. */ +struct vring_used *used; +/**< Size of descriptor ring. */ +uint32_t size; +/**< Backend value to determine if device should be started/stopped. */ +uint32_t backend; +/**< Vhost header length (varies depending on RX merge buffers. */ +uint16_t vhost_hlen; +/**< Last index used on the available ring. */ +volatile uint16_t last_used_idx; +/**< Used for multiple devices reserving buffers. */ +volatile uint16_t last_used_idx_res; +/**< Currently unused as polling mode is enabled. */ +eventfd_t callfd; +/**< Used to notify the guest (trigger interrupt). */ +eventfd_t kickfd; +} __rte_cache_aligned; + +/** +* Information relating to memory regions including offsets to +* addresses in QEMUs memory file. +*/ +struct virtio_memory_regions { +/**< Base guest physical address of region. */ +uint64_t guest_phys_address; +/**< End guest physical address of region. */ +uint64_t guest_phys_address_end; +/**< Size of region. */ +uint64_t memory_size; +/**< Base userspace address of region. */ +uint64_t userspace_address; +/**< Offset of region for address translation. */ +uint64_t address_offset; +}; + + +/** +* Memory structure includes region and mapping information. +*/ +struct virtio_memory { +/**< Base QEMU userspace address of the memory file. */ +uint64_t base_address; +/**< Mapped address of memory file in this process's memory space. */ +uint64_t mapped_address;lib/librte_vhost/rte_virtio_net.h
Quoted 10 lines
lib/librte_vhost/rte_virtio_net.h new file +10
-0+/**< Total size of memory file. */ +uint64_t mapped_size; +/**< Number of memory regions. */ +uint32_t nregions; +/**< Memory region information. */ +struct virtio_memory_regions regions[0 ]; +}; + +/** +* Device structure contains all configuration information relating to the device.
Quoted 11 lines
+ */
lib/librte_vhost/rte_virtio_net.h new file +10
-0+struct virtio_net { +/**< Contains all virtqueue information. */ +struct vhost_virtqueue *virtqueue[VIRTIO_QNUM ]; +/**< QEMU memory and memory region information. */ +struct virtio_memory *mem; +/**< Negotiated feature set. */ +uint64_t features; +/**< Device identifier. */ +uint64_t device_fh; +/**< Device flags, used to check if device is running on data core. */ Quoted 8 lines
lib/librte_vhost/rte_virtio_net.h line 130
Quoted 4 lines
lib/librte_vhost/rte_virtio_net.h new file +4
-0+uint32_t flags; +void *priv; +} __rte_cache_aligned; +Above comments of '
vhost_virtqueue', 'structvirtio_memory_regions', 'struct virtio-memory'
and 'struct virtio-net' will break API documentation created by Doxygen. Not to break, I guess those comment need to be placed after variable.Thanks. I will check doxgen rule. Moved the comment above to avoid 80 character limitation warning.
Quoted 17 lines
Quoted 6 lines
lib/librte_vhost/vhost-net-cdev.c new file +6
-0+/** +* cuse_info is populated and used to register the cuse device. +* vhost_net_device_ops is passed when the device is registered in main.c. +*/ +int +rte_vhost_driver_register (const char *dev_name)lib/librte_vhost/vhost-net-cdev.c
Quoted 10 lines
lib/librte_vhost/vhost-net-cdev.c new file +10
-0+{ +struct cuse_info cuse_info; +char device_name[PATH_MAX ] ="" ; +char char_device_name[PATH_MAX ] ="" ; +const char *device_argv[] = { device_name }; + +char fuse_opt_dummy[] =FUSE_OPT_DUMMY ; +char fuse_opt_fore[] =FUSE_OPT_FORE ; +char fuse_opt_nomulti[] =FUSE_OPT_NOMULTI ; +char *fuse_argv[] = {fuse_opt_dummy, fuse_opt_fore,
fuse_opt_nomulti};Quoted 6 lines
lib/librte_vhost/vhost-net-cdev.c line 345
Quoted 5 lines
lib/librte_vhost/vhost-net-cdev.c new file +5
-0+ +if (access (cuse_device_name,R_OK |W_OK ) <0 ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"Character device %s can't be accessed, maybe not exist\n" , + cuse_device_name);Need one more indent?
Again to avoid 80 char warning for some lengthy
RTE_LOG.Quoted 147 lines
Quoted 2 lines
+/**
+ * Locate the file containing QEMU's memory space and map it to ouraddress space.
Review
Quoted 3 lines
+ */
(quoted diff) +2
-0+static int +host_memory_map(struct virtio_net *dev, struct virtio_memory *mem, pid_tpid,
Quoted 94 lines
lib/librte_vhost/virtio-net.c new file +94
-0+ uint64_t addr) +{ +struct dirent *dptr =NULL ; +struct procmap procmap; +DIR *dp =NULL ; +int fd; +int i; +char memfile[PATH_MAX ]; +char mapfile[PATH_MAX ]; +char procdir[PATH_MAX ]; +char resolved_path[PATH_MAX ]; +FILE *fmap; +void *map; +uint8_t found =0 ; +char line[BUFSIZE ]; +char dlm[] ="- : " ; +char *str, *sp, *in[PROCMAP_SZ ]; +char *end =NULL ; + +/* Path where mem files are located. */ +snprintf (procdir,PATH_MAX ,"/proc/%u/fd/" , pid); +/* Maps file used to locate mem file. */ +snprintf (mapfile,PATH_MAX ,"/proc/%u/maps" , pid); + + fmap =fopen (mapfile,"r" ); +if (fmap ==NULL ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to open maps file for pid %d\n" , + dev->device_fh, pid); +return -1 ; + } + +/* Read through maps file until we find out base_address. */ +while (fgets (line,BUFSIZE , fmap) !=0 ) { + str = line; + errno =0 ; +/* Split line in to fields. */ +for (i =0 ; i <PROCMAP_SZ ; i++) { + in[i] =strtok_r (str, &dlm[i], &sp); +if ((in[i] ==NULL ) || (errno !=0 )) { +fclose (fmap); +return -1 ; + } + str =NULL ; + } + +/* Convert/Copy each field as needed. */ + procmap.va_start =strtoull (in[0 ], &end,16 ); +if ((in[0 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.len =strtoull (in[1 ], &end,16 ); +if ((in[1 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.pgoff =strtoull (in[3 ], &end,16 ); +if ((in[3 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.maj =strtoul (in[4 ], &end,16 ); +if ((in[4 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.min =strtoul (in[5 ], &end,16 ); +if ((in[5 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + + procmap.ino =strtoul (in[6 ], &end,16 ); +if ((in[6 ] =='\0' ) || (end ==NULL ) || (*end !='\0' ) || + (errno !=0 )) { +fclose (fmap); +return -1 ; + } + +memcpy (&procmap.prot, in[2 ],PROT_SZ ); +memcpy (&procmap.fname, in[7 ],PATH_MAX ); + +if (procmap.va_start == addr) { + procmap.len = procmap.len - procmap.va_start;lib/librte_vhost/virtio-net.c line 228
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ found =1 ; +break ; + } + } +fclose (fmap); + +if (!found) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to find memory file in pid %d maps file\n" , + dev->device_fh, pid);Need one more indent?
Quoted 2 lines
+/**
+ * Searches the configuration core linked list and retrieves the device if itexists.
lib/librte_vhost/virtio-net.c line 392
Quoted 10 lines
+ */
lib/librte_vhost/virtio-net.c new file +9
-0+static struct virtio_net * +get_device (struct vhost_device_ctx ctx) +{ +struct virtio_net_config_ll *ll_dev; + + ll_dev =get_config_ll_entry (ctx); + +/* If a matching entry is found in the linked list, return the device +* in that entry. */ Need a blank space at start of comment?
Quoted 19 lines
lib/librte_vhost/virtio-net.c new file +19
-0+if (ll_dev) +return &ll_dev->dev; + +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Device not found in linked list.\n" , ctx.fh); +return NULL ; +} + +/** +* Add entry containing a device to the device configuration linked list. +*/ +static void +add_config_ll_entry (struct virtio_net_config_ll *new_ll_dev) +{ +struct virtio_net_config_ll *ll_dev = ll_root; + +/* If ll_dev == NULL then this is the first device so go to else */ +if (ll_dev) { +/* If the 1st device_fh != 0 then we insert our device here. */ Quoted 8 lines
lib/librte_vhost/virtio-net.c line 418
Quoted 7 lines
lib/librte_vhost/virtio-net.c new file +7
-0+if (ll_dev->dev.device_fh !=0 ) { + new_ll_dev->dev.device_fh =0 ; + new_ll_dev->next = ll_dev; + ll_root = new_ll_dev; + }else { +/* Increment through the ll until we find un unused +* device_fh. Insert the device at that entry*/ Need a blank space at end of comment?
Will fix.
Quoted 17 lines
Quoted 2 lines
+/**
+ * Function is called from the CUSE release function. This function willcleanup
lib/librte_vhost/virtio-net.c line 532
Quoted 13 lines
+ * the device and remove it from device configuration linked list.
+ */lib/librte_vhost/virtio-net.c new file +11
-0+static void +destroy_device (struct vhost_device_ctx ctx) +{ +struct virtio_net_config_ll *ll_dev_cur_ctx, *ll_dev_last =NULL ; +struct virtio_net_config_ll *ll_dev_cur = ll_root; + +/* Find the linked list entry for the device to be removed. */ + ll_dev_cur_ctx =get_config_ll_entry (ctx); +while (ll_dev_cur !=NULL ) { +/* If the device is found or a device that doesn't exist is +* found then it is removed. */ Need a blank space?
Will fix.
Quoted 86 lines
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+/** +* Called from CUSE IOCTL: VHOST_SET_FEATURES +* We receive the negotiated set of features supported by us and the virtio +* device. +*/ +static int +set_features (struct vhost_device_ctx ctx,uint64_t *pu) +{ +struct virtio_net *dev; +lib/librte_vhost/virtio-net.c
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ dev =get_device (ctx); +if (dev ==NULL ) +return -1 ; +if (*pu & ~VHOST_FEATURES ) +return -1 ; + +/* Store the negotiated feature list for the device. */ + dev->features = *pu; + +/* Set the vhost_hlen depending on if VIRTIO_NET_F_MRG_RXBUF is set. */
lib/librte_vhost/virtio-net.c line 627
Quoted 7 lines
lib/librte_vhost/virtio-net.c new file +7
-0+if (dev->features & (1 <<VIRTIO_NET_F_MRG_RXBUF )) { +LOG_DEBUG (VHOST_CONFIG , +"(%" PRIu64") Mergeable RX buffers enabled\n" , dev->device_fh); + dev->virtqueue[VIRTIO_RXQ ]->vhost_hlen = +sizeof (struct virtio_net_hdr_mrg_rxbuf ); + dev->virtqueue[VIRTIO_TXQ ]->vhost_hlen = +sizeof (struct virtio_net_hdr_mrg_rxbuf );One more indent?
Quoted 45 lines
lib/librte_vhost/virtio-net.c new file +31
-0+/** + * Called from CUSE IOCTL: VHOST_SET_MEM_TABLE + * This function creates and populates the memory structure for the device. + * This includes storing offsets used to translate buffer addresses. + */ +static int +set_mem_table(struct vhost_device_ctx ctx, const void *mem_regions_addr, + uint32_t nregions) +{ + struct virtio_net *dev; + struct vhost_memory_region *mem_regions; + struct virtio_memory *mem; + uint64_t size = offsetof(struct vhost_memory, regions); + uint32_t regionidx, valid_regions; + + dev = get_device(ctx); + if (dev == NULL) + return -1; + + if (dev->mem) { + munmap((void *)(uintptr_t)dev->mem->mapped_address, + (size_t)dev->mem->mapped_size); + free(dev->mem); + } + + /* Malloc the memory structure depending on the number of regions. */ + mem = calloc(1, sizeof(struct virtio_memory) + + (sizeof(struct virtio_memory_regions) * nregions)); + if (mem == NULL) { + RTE_LOG(ERR, VHOST_CONFIG, + "(%"PRIu64") Failed to allocate memory for dev-mem.\n",
lib/librte_vhost/virtio-net.c new file +13
-0+ dev->device_fh); +return -1 ; + } + + mem->nregions = nregions; + + mem_regions = (void *)(uintptr_t ) + ((uint64_t )(uintptr_t )mem_regions_addr + size); + +for (regionidx =0 ; regionidx < mem->nregions; regionidx++) { +/* Populate the region structure for each region. */ + mem->regions[regionidx].guest_phys_address = + mem_regions[regionidx].guest_phys_addr;lib/librte_vhost/virtio-net.c
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+ mem->regions[regionidx].guest_phys_address_end = + mem->regions[regionidx].guest_phys_address + + mem_regions[regionidx].memory_size; + mem->regions[regionidx].memory_size = + mem_regions[regionidx].memory_size; + mem->regions[regionidx].userspace_address = + mem_regions[regionidx].userspace_addr; + +LOG_DEBUG (VHOST_CONFIG , + "(%"PRIu64") REGION: %u - GPA: %p - QEMU VA: %p -SIZE "
Quoted 10 lines
lib/librte_vhost/virtio-net.c line 703
Quoted 9 lines
lib/librte_vhost/virtio-net.c new file +9
-0+"(%" PRIu64")\n" , + dev->device_fh, regionidx, + (void *)(uintptr_t ) + mem->regions[regionidx].guest_phys_address, + (void *)(uintptr_t ) + mem->regions[regionidx].userspace_address, + mem->regions[regionidx].memory_size); + +/*set the base address mapping*/ Need a blank space at start and end of comment?
Thanks for careful review.
Quoted 54 lines
Quoted 7 lines
lib/librte_vhost/virtio-net.c new file +7
-0+if (mem->regions[regionidx].guest_phys_address ==0x0 ) { + mem->base_address = + mem->regions[regionidx].userspace_address; +/* Map VM memory file */ +if (host_memory_map (dev, mem, ctx.pid, + mem->base_address) !=0 ) { +free (mem);lib/librte_vhost/virtio-net.c line 720
Quoted 10 lines
lib/librte_vhost/virtio-net.c new file +10
-0+return -1 ; + } + } + } + +/* Check that we have a valid base address. */ +if (mem->base_address ==0 ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"(%" PRIu64") Failed to find base address of qemu memory " +"file.\n" , dev->device_fh);One more indent?
lib/librte_vhost/virtio-net.c line 726
Quoted 6 lines
lib/librte_vhost/virtio-net.c new file +6
-0+free (mem); +return -1 ; + } + +/* Check if all of our regions have valid mappings. Usually one does +* not exist in the QEMU memory file. */ Need a blank space?
lib/librte_vhost/virtio-net.c line 737
Quoted 11 lines
lib/librte_vhost/virtio-net.c new file +11
-0+ valid_regions = mem->nregions; +for (regionidx =0 ; regionidx < mem->nregions; regionidx++) { +if ((mem->regions[regionidx].userspace_address < + mem->base_address) || + (mem->regions[regionidx].userspace_address > + (mem->base_address + mem->mapped_size))) + valid_regions--; + } + +/* If a region does not have a valid mapping we rebuild our memory +* struct to contain only valid entries. */ Need a blank space?
lib/librte_vhost/virtio-net.c
Quoted 3 lines
lib/librte_vhost/virtio-net.c new file +3
-0+ if (valid_regions != mem->nregions) { + LOG_DEBUG(VHOST_CONFIG, + "(%"PRIu64") Not all memory regions exist in the QEMU memfile."
lib/librte_vhost/virtio-net.c line 741
Quoted 1 line
lib/librte_vhost/virtio-net.c new file +1
-0+ "Re-populating mem structure\n",One more indent?
lib/librte_vhost/virtio-net.c line 745
Quoted 4 lines
lib/librte_vhost/virtio-net.c new file +4
-0+ dev->device_fh); + +/* Re-populate the memory structure with only valid regions. +* Invalid regions are over-written with memmove. */ Need a blank space?
Thanks,
Tetsuya
Re: [PATCH 2/3] lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitch
In reply to Stephen HemmingerQuoted 9 lines
From: dev [mailto:[email protected]] On Behalf Of Stephen Hemminger
Sent: Wednesday, September 03, 2014 7:02 AM
To: Xie, Huawei
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH 2/3]lib/librte_vhost: vhost library support to facilitate integration with DPDK accelerated vswitchOn Wed, 3 Sep 2014 05:39:24 +0000
"Xie, Huawei" <[email protected]> wrote:
Quoted 6 lines
Quoted 2 lines
Thanks Tetsuya:
Some of them are due to 80 character limitation. Is it ok to break the limitation for better indentation?Many of these comments could just be removed or shortened. Often removing comments makes code clearer and less buggy, because there is no risk that comment does not match code.
If comment string is longer than 80 characters, why just not split comment string into multiline?