With this commit the '--dpdk' option doesn't need to be at the beginning of the command line. Furthermode, the code that calls 'rte_eal_init()' can be slightly simplified by using the 'optind' variable. The change is totally backward compatible
Documentation and manpages are updated accordingly. Signed-off-by: Daniele Di Proietto <diproiet...@vmware.com> --- INSTALL.DPDK.md | 14 ++++++++------ lib/netdev-dpdk.c | 41 +++++++++++++++++------------------------ lib/netdev-dpdk.h | 20 +++++++++++++------- vswitchd/ovs-vswitchd.8.in | 9 ++++++--- vswitchd/ovs-vswitchd.c | 11 +++++------ 5 files changed, 49 insertions(+), 46 deletions(-) diff --git a/INSTALL.DPDK.md b/INSTALL.DPDK.md index 4c443e5..72318a8 100644 --- a/INSTALL.DPDK.md +++ b/INSTALL.DPDK.md @@ -77,7 +77,7 @@ Using the DPDK with ovs-vswitchd: 1. Setup system boot Add the following options to the kernel bootline: - + `default_hugepagesz=1GB hugepagesz=1G hugepages=1` 2. Setup DPDK devices: @@ -139,10 +139,12 @@ Using the DPDK with ovs-vswitchd: 5. Start vswitchd: - DPDK configuration arguments can be passed to vswitchd via `--dpdk` - argument. This needs to be first argument passed to vswitchd process. - dpdk arg -c is ignored by ovs-dpdk, but it is a required parameter - for dpdk initialization. + To initialize DPDK support the '--dpdk' option must be used. It is + followed by suboptions that are passed to the DPDK library. The suboptions + list is terminated by `--`: the remaining options are parsed by vswitchd. + + Please not that `-c` and `-n` DPDK suboptions are required (although `-c` + is ignored by OVS) ``` export DB_SOCK=/usr/local/var/run/openvswitch/db.sock @@ -158,7 +160,7 @@ Using the DPDK with ovs-vswitchd: ``` 6. Add bridge & ports - + To use ovs-vswitchd with DPDK, create a bridge with datapath_type "netdev" in the configuration database. For example: diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index aea2016..17ac5e9 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -129,8 +129,6 @@ enum { DPDK_RING_SIZE = 256 }; BUILD_ASSERT_DECL(IS_POW2(DPDK_RING_SIZE)); enum { DRAIN_TSC = 200000ULL }; -static int rte_eal_init_ret = ENODEV; - static struct ovs_mutex dpdk_mutex = OVS_MUTEX_INITIALIZER; /* Contains all 'struct dpdk_dev's. */ @@ -549,8 +547,8 @@ netdev_dpdk_construct(struct netdev *netdev) unsigned int port_no; int err; - if (rte_eal_init_ret) { - return rte_eal_init_ret; + if (!dpdk_is_initialized()) { + return ENODEV; } /* Names always start with "dpdk" */ @@ -1388,8 +1386,8 @@ netdev_dpdk_ring_construct(struct netdev *netdev) unsigned int port_no = 0; int err = 0; - if (rte_eal_init_ret) { - return rte_eal_init_ret; + if (!dpdk_is_initialized()) { + return ENODEV; } ovs_mutex_lock(&dpdk_mutex); @@ -1474,37 +1472,32 @@ unlock_dpdk: NULL, /* rxq_drain */ \ } -int +static bool dpdk_initialized = false; + +void dpdk_init(int argc, char **argv) { int result; - if (argc < 2 || strcmp(argv[1], "--dpdk")) - return 0; - - /* Make sure program name passed to rte_eal_init() is vswitchd. */ - argv[1] = argv[0]; - - argc--; - argv++; - - /* Make sure things are initialized ... */ + /* Initialize DPDK. It uses 'argc' and 'argv' as they are, because + * getopt's 'optind' already points to the right argument. */ result = rte_eal_init(argc, argv); if (result < 0) { ovs_abort(result, "Cannot init EAL\n"); } + /* rte_eal_init() messes with getopt's 'optind'. Restore it */ + optind = result + 1; rte_memzone_dump(stdout); - rte_eal_init_ret = 0; - - if (argc > result) { - argv[result] = argv[0]; - } + dpdk_initialized = true; /* We are called from the main thread here */ thread_set_nonpmd(); +} - return result + 1; +bool dpdk_is_initialized() +{ + return dpdk_initialized; } const struct netdev_class dpdk_class = @@ -1528,7 +1521,7 @@ netdev_dpdk_register(void) { static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; - if (rte_eal_init_ret) { + if (!dpdk_is_initialized()) { return; } diff --git a/lib/netdev-dpdk.h b/lib/netdev-dpdk.h index 694899c..44bd47e 100644 --- a/lib/netdev-dpdk.h +++ b/lib/netdev-dpdk.h @@ -3,6 +3,8 @@ #include <config.h> +#include <stdbool.h> + struct dpif_packet; /* Reserves cpu core 0 for all non-pmd threads. Changing the value of this @@ -25,7 +27,8 @@ struct dpif_packet; #include <rte_launch.h> #include <rte_malloc.h> -int dpdk_init(int argc, char **argv); +void dpdk_init(int argc, char **argv); +bool dpdk_is_initialized(void); void netdev_dpdk_register(void); void free_dpdk_buf(struct dpif_packet *); int pmd_thread_setaffinity_cpu(int cpu); @@ -35,13 +38,16 @@ void thread_set_nonpmd(void); #include "util.h" -static inline int -dpdk_init(int argc, char **argv) +static inline void +dpdk_init(int argc OVS_UNUSED, char **argv OVS_UNUSED) { - if (argc >= 2 && !strcmp(argv[1], "--dpdk")) { - ovs_fatal(0, "DPDK support not built into this copy of Open vSwitch."); - } - return 0; + ovs_fatal(0, "DPDK support not built into this copy of Open vSwitch."); +} + +static inline bool +dpdk_is_initialized(void) +{ + return false; } static inline void diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in index 7f165ea..6add49a 100644 --- a/vswitchd/ovs-vswitchd.8.in +++ b/vswitchd/ovs-vswitchd.8.in @@ -84,9 +84,12 @@ only allow privileged users, such as the superuser, to use it. unavailable or unsuccessful. . .SS "DPDK Options" -.IP "\fB\-\-dpdk\fR" -Initialize \fBovs\-vswitchd\fR DPDK datapath. Refer to INSTALL.DPDK -for details. +.IP "\fB\-\-dpdk\fR [\fIsuboptions\fR] \fB--\fR" +Initialize \fBovs\-vswitchd\fR DPDK driver (OVS must have been built with DPDK +support) passing \fIsuboptions\fR to the DPDK runtime. The \fIsuboptions\fR +list must be terminated by \fB--\fR. Some \fIsuboptions\fR are necessary to +properly initialize the library. Please refer to \fBINSTALL.DPDK.md\fR file +included in the Open vSwitch distribution for details. .SS "Daemon Options" .ds DD \ \fBovs\-vswitchd\fR detaches only after it has connected to the \ diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c index 812c00b..ce811f5 100644 --- a/vswitchd/ovs-vswitchd.c +++ b/vswitchd/ovs-vswitchd.c @@ -71,10 +71,6 @@ main(int argc, char *argv[]) int retval; set_program_name(argv[0]); - retval = dpdk_init(argc,argv); - argc -= retval; - argv += retval; - proctitle_init(argc, argv); service_start(&argc, &argv); remote = parse_options(argc, argv, &unixctl_path); @@ -162,7 +158,7 @@ parse_options(int argc, char *argv[], char **unixctl_pathp) {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT}, {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY}, {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM}, - {"dpdk", required_argument, NULL, OPT_DPDK}, + {"dpdk", no_argument, NULL, OPT_DPDK}, {NULL, 0, NULL, 0}, }; char *short_options = long_options_to_short_options(long_options); @@ -215,7 +211,10 @@ parse_options(int argc, char *argv[], char **unixctl_pathp) exit(EXIT_FAILURE); case OPT_DPDK: - ovs_fatal(0, "--dpdk must be given at beginning of command line."); + if (dpdk_is_initialized()) { + VLOG_FATAL("--dpdk option should appear at most once"); + } + dpdk_init(argc, argv); break; default: -- 2.1.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev