From 31ae2e35caa16dcf4cc1fa2ff5e3c1aa825b5352 Mon Sep 17 00:00:00 2001 From: Jim Somerville Date: Fri, 26 Apr 2019 17:41:04 -0300 Subject: [PATCH] STX: qemu dpdk changes for openvswitch dpdk Signed-off-by: Jim Somerville Signed-off-by: Rafael Falcao [Rebased original changes to the qemu 7.2 version] Signed-off-by: david.liu [Reordered custom DPDK args parsing on QEMU 7.2] Signed-off-by: Thales Elero Cervi --- configure | 27 +++++++++++++++++++ hw/net/virtio-net.c | 5 ++++ softmmu/vl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/configure b/configure index 26c7bc51..c5810ea3 100755 --- a/configure +++ b/configure @@ -853,6 +853,11 @@ for opt do ;; --with-coroutine=*) coroutine="$optarg" ;; + --disable-dpdk) dpdk="no" + ;; + --dpdkdir=*) rte_sdk="$optarg" + dpdk="yes" + ;; --disable-zlib-test) ;; --disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane) @@ -2401,6 +2406,28 @@ if test -n "$gdb_bin"; then fi fi +if test "$dpdk" = "yes"; then + if test "${rte_sdk+set}" != set; then + echo "No dpdkdir given" + exit 1 + fi + echo "dpdk_dir=`eval echo $rte_sdk`" >> $config_host_mak + echo "dpdk_lib_dir=\$(dpdk_dir)/x86_64-default-linuxapp-gcc/lib" >> $config_host_mak_ + echo "dpdk_inc_dir=\$(dpdk_dir)/x86_64-default-linuxapp-gcc/include" >> $config_host_mak + echo "" >> $config_host_mak + echo "dpdk_libs=\$(dpdk_lib_dir)/librte_eal.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/libethdev.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/librte_cmdline.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/librte_hash.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/librte_lpm.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/librte_mbuf.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/librte_mempool.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/librte_ring.a \\" >> $config_host_mak + echo " \$(dpdk_lib_dir)/librte_malloc.a" >> $config_host_mak + LIBS="\$(dpdk_libs) $LIBS" + QEMU_INCLUDES="-I\$(dpdk_inc_dir) $QEMU_INCLUDES" +fi + if test "$container" != no; then echo "ENGINE=$container" >> $config_host_mak fi diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index aba12759..01ca6015 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2,6 +2,7 @@ * Virtio Network Device * * Copyright IBM, Corp. 2007 + * Copyright 2012-2013 Intel Corporation All Rights Reserved. * * Authors: * Anthony Liguori @@ -1671,6 +1672,7 @@ static void receive_header(VirtIONet *n, const struct iovec *iov, int iov_cnt, } } +#if 0 static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) { static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; @@ -1721,6 +1723,7 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) return 0; } +#endif static uint8_t virtio_net_get_hash_type(bool isip4, bool isip6, @@ -1852,8 +1855,10 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, return 0; } + #if 0 if (!receive_filter(n, buf, size)) return size; + #endif offset = i = 0; diff --git a/softmmu/vl.c b/softmmu/vl.c index 333c3be2..039df6c4 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1583,6 +1583,35 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +#ifdef CONFIG_ENABLE_DPDK +static const QEMUOption *quick_scan_opt(int argc, char **argv, int *poptind) +{ + const QEMUOption *popt; + int optind = *poptind; + char *r = argv[optind]; + + loc_set_cmdline(argv, optind, 1); + optind++; + /* Treat --foo the same as -foo. */ + if (r[1] == '-') + r++; + popt = qemu_options; + for(;;) { + /* need to ignore non qemu args, e.g. dpdk args */ + if (!popt->name) { + *poptind = optind; + return NULL; + } + if (!strcmp(popt->name, r + 1)) + break; + popt++; + } + + *poptind = optind; + return popt; +} +#endif + static MachineClass *select_machine(QDict *qdict, Error **errp) { const char *optarg = qdict_get_try_str(qdict, "type"); @@ -2645,6 +2674,40 @@ void qemu_init(int argc, char **argv) bool userconfig = true; FILE *vmstate_dump_file = NULL; +#ifdef CONFIG_ENABLE_DPDK + bool use_dpdk = false; + int retval; + + /* need to check for -enable-dpdk before calling rte_eal_init. If + * it is not found, don't call rte_eal_init */ + optind = 1; + while (optind < argc) { + if (argv[optind][0] != '-') { + /* disk image */ + optind++; + continue; + } else { + const QEMUOption *popt; + popt = quick_scan_opt(argc, argv, &optind); + if (popt) { + switch (popt->index) { + case QEMU_OPTION_enable_dpdk: + use_dpdk = true; + break; + } + } + } + } + + if (use_dpdk) { + if ((retval = rte_eal_init(argc, argv)) < 0) + return -1; + + argc -= retval; + argv += retval; + } +#endif + qemu_add_opts(&qemu_drive_opts); qemu_add_drive_opts(&qemu_legacy_drive_opts); qemu_add_drive_opts(&qemu_common_drive_opts); @@ -3532,6 +3595,9 @@ void qemu_init(int argc, char **argv) cpu_timers_init(); user_register_global_props(); + + extern int rte_eal_init(int argc, char **argv); + replay_configure(icount_opts); configure_rtc(qemu_find_opts_singleton("rtc")); -- 2.34.1