vhost related configuration and per port memory are netdev-dpdk configuration items.
dpdk-stub.c and netdev-dpdk.c are never linked together, so we can move those bits out of the generic dpdk code. The dpdk_* accessors for those configuration items are then not needed anymore and we can simply reference local variables. Signed-off-by: David Marchand <[email protected]> --- lib/dpdk-stub.c | 24 ----------- lib/dpdk.c | 101 --------------------------------------------- lib/dpdk.h | 4 -- lib/netdev-dpdk.c | 102 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 94 insertions(+), 137 deletions(-) diff --git a/lib/dpdk-stub.c b/lib/dpdk-stub.c index 3eee1f485c..58ebf6cb62 100644 --- a/lib/dpdk-stub.c +++ b/lib/dpdk-stub.c @@ -49,30 +49,6 @@ dpdk_detach_thread(void) { } -const char * -dpdk_get_vhost_sock_dir(void) -{ - return NULL; -} - -bool -dpdk_vhost_iommu_enabled(void) -{ - return false; -} - -bool -dpdk_vhost_postcopy_enabled(void) -{ - return false; -} - -bool -dpdk_per_port_memory(void) -{ - return false; -} - bool dpdk_available(void) { diff --git a/lib/dpdk.c b/lib/dpdk.c index d909974f91..240babc03e 100644 --- a/lib/dpdk.c +++ b/lib/dpdk.c @@ -19,7 +19,6 @@ #include <stdio.h> #include <sys/types.h> -#include <sys/stat.h> #include <getopt.h> #include <rte_cpuflags.h> @@ -47,40 +46,9 @@ VLOG_DEFINE_THIS_MODULE(dpdk); static FILE *log_stream = NULL; /* Stream for DPDK log redirection */ -static char *vhost_sock_dir = NULL; /* Location of vhost-user sockets */ -static bool vhost_iommu_enabled = false; /* Status of vHost IOMMU support */ -static bool vhost_postcopy_enabled = false; /* Status of vHost POSTCOPY - * support. */ -static bool per_port_memory = false; /* Status of per port memory support */ - /* Indicates successful initialization of DPDK. */ static atomic_bool dpdk_initialized = ATOMIC_VAR_INIT(false); -static int -process_vhost_flags(char *flag, const char *default_val, int size, - const struct smap *ovs_other_config, - char **new_val) -{ - const char *val; - int changed = 0; - - val = smap_get(ovs_other_config, flag); - - /* Process the vhost-sock-dir flag if it is provided, otherwise resort to - * default value. - */ - if (val && (strlen(val) <= size)) { - changed = 1; - *new_val = xstrdup(val); - VLOG_INFO("User-provided %s in use: %s", flag, *new_val); - } else { - VLOG_INFO("No %s provided - defaulting to %s", flag, default_val); - *new_val = xstrdup(default_val); - } - - return changed; -} - static bool args_contains(const struct svec *args, const char *value) { @@ -345,11 +313,9 @@ malloc_dump_stats_wrapper(FILE *stream) static bool dpdk_init__(const struct smap *ovs_other_config) { - char *sock_dir_subcomponent; char **argv = NULL; int result; bool auto_determine = true; - int err = 0; struct ovs_numa_dump *affinity = NULL; struct svec args = SVEC_EMPTY_INITIALIZER; @@ -361,49 +327,6 @@ dpdk_init__(const struct smap *ovs_other_config) rte_openlog_stream(log_stream); } - if (process_vhost_flags("vhost-sock-dir", ovs_rundir(), - NAME_MAX, ovs_other_config, - &sock_dir_subcomponent)) { - struct stat s; - if (!strstr(sock_dir_subcomponent, "..")) { - vhost_sock_dir = xasprintf("%s/%s", ovs_rundir(), - sock_dir_subcomponent); - - err = stat(vhost_sock_dir, &s); - if (err) { - VLOG_ERR("vhost-user sock directory '%s' does not exist.", - vhost_sock_dir); - } - } else { - vhost_sock_dir = xstrdup(ovs_rundir()); - VLOG_ERR("vhost-user sock directory request '%s/%s' has invalid" - "characters '..' - using %s instead.", - ovs_rundir(), sock_dir_subcomponent, ovs_rundir()); - } - free(sock_dir_subcomponent); - } else { - vhost_sock_dir = sock_dir_subcomponent; - } - - vhost_iommu_enabled = smap_get_bool(ovs_other_config, - "vhost-iommu-support", false); - VLOG_INFO("IOMMU support for vhost-user-client %s.", - vhost_iommu_enabled ? "enabled" : "disabled"); - - vhost_postcopy_enabled = smap_get_bool(ovs_other_config, - "vhost-postcopy-support", false); - if (vhost_postcopy_enabled && memory_locked()) { - VLOG_WARN("vhost-postcopy-support and mlockall are not compatible."); - vhost_postcopy_enabled = false; - } - VLOG_INFO("POSTCOPY support for vhost-user-client %s.", - vhost_postcopy_enabled ? "enabled" : "disabled"); - - per_port_memory = smap_get_bool(ovs_other_config, - "per-port-memory", false); - VLOG_INFO("Per port memory for DPDK devices %s.", - per_port_memory ? "enabled" : "disabled"); - svec_add(&args, ovs_get_program_name()); construct_dpdk_args(ovs_other_config, &args); @@ -558,30 +481,6 @@ dpdk_init(const struct smap *ovs_other_config) atomic_store_relaxed(&dpdk_initialized, enabled); } -const char * -dpdk_get_vhost_sock_dir(void) -{ - return vhost_sock_dir; -} - -bool -dpdk_vhost_iommu_enabled(void) -{ - return vhost_iommu_enabled; -} - -bool -dpdk_vhost_postcopy_enabled(void) -{ - return vhost_postcopy_enabled; -} - -bool -dpdk_per_port_memory(void) -{ - return per_port_memory; -} - bool dpdk_available(void) { diff --git a/lib/dpdk.h b/lib/dpdk.h index 64ebca47d6..1b790e682e 100644 --- a/lib/dpdk.h +++ b/lib/dpdk.h @@ -38,10 +38,6 @@ struct ovsrec_open_vswitch; void dpdk_init(const struct smap *ovs_other_config); bool dpdk_attach_thread(unsigned cpu); void dpdk_detach_thread(void); -const char *dpdk_get_vhost_sock_dir(void); -bool dpdk_vhost_iommu_enabled(void); -bool dpdk_vhost_postcopy_enabled(void); -bool dpdk_per_port_memory(void); bool dpdk_available(void); void print_dpdk_version(void); void dpdk_status(const struct ovsrec_open_vswitch *); diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 0dd655507b..0ed7e855f1 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -24,6 +24,7 @@ #include <unistd.h> #include <linux/virtio_net.h> #include <sys/socket.h> +#include <sys/stat.h> #include <linux/if.h> #include <rte_bus_pci.h> @@ -78,6 +79,12 @@ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); COVERAGE_DEFINE(vhost_tx_contention); COVERAGE_DEFINE(vhost_notification); +static char *vhost_sock_dir = NULL; /* Location of vhost-user sockets */ +static bool vhost_iommu_enabled = false; /* Status of vHost IOMMU support */ +static bool vhost_postcopy_enabled = false; /* Status of vHost POSTCOPY + * support. */ +static bool per_port_memory = false; /* Status of per port memory support */ + #define DPDK_PORT_WATCHDOG_INTERVAL 5 #define OVS_CACHE_LINE_SIZE CACHE_LINE_SIZE @@ -915,7 +922,7 @@ netdev_dpdk_mempool_configure(struct netdev_dpdk *dev) uint32_t buf_size = dpdk_buf_size(dev->requested_mtu); struct dpdk_mp *dmp; int ret = 0; - bool per_port_mp = dpdk_per_port_memory(); + bool per_port_mp = per_port_memory; /* With shared memory we do not need to configure a mempool if the MTU * and socket ID have not changed, the previous configuration is still @@ -1379,7 +1386,7 @@ netdev_dpdk_vhost_construct(struct netdev *netdev) /* Take the name of the vhost-user port and append it to the location where * the socket is to be created, then register the socket. */ - dev->vhost_id = xasprintf("%s/%s", dpdk_get_vhost_sock_dir(), name); + dev->vhost_id = xasprintf("%s/%s", vhost_sock_dir, name); dev->vhost_driver_flags &= ~RTE_VHOST_USER_CLIENT; @@ -5102,12 +5109,12 @@ netdev_dpdk_vhost_client_reconfigure(struct netdev *netdev) vhost_flags |= RTE_VHOST_USER_LINEARBUF_SUPPORT; /* Enable IOMMU support, if explicitly requested. */ - if (dpdk_vhost_iommu_enabled()) { + if (vhost_iommu_enabled) { vhost_flags |= RTE_VHOST_USER_IOMMU_SUPPORT; } /* Enable POSTCOPY support, if explicitly requested. */ - if (dpdk_vhost_postcopy_enabled()) { + if (vhost_postcopy_enabled) { vhost_flags |= RTE_VHOST_USER_POSTCOPY_SUPPORT; } @@ -5389,8 +5396,18 @@ netdev_dpdk_rte_flow_tunnel_item_release(struct netdev *netdev, #endif /* ALLOW_EXPERIMENTAL_API */ static void -parse_user_mempools_list(const char *mtus) +parse_mempool_config(const struct smap *ovs_other_config) +{ + per_port_memory = smap_get_bool(ovs_other_config, + "per-port-memory", false); + VLOG_INFO("Per port memory for DPDK devices %s.", + per_port_memory ? "enabled" : "disabled"); +} + +static void +parse_user_mempools_list(const struct smap *ovs_other_config) { + const char *mtus = smap_get(ovs_other_config, "shared-mempool-config"); char *list, *copy, *key, *value; int error = 0; @@ -5438,6 +5455,75 @@ parse_user_mempools_list(const char *mtus) free(copy); } +static int +process_vhost_flags(char *flag, const char *default_val, int size, + const struct smap *ovs_other_config, + char **new_val) +{ + const char *val; + int changed = 0; + + val = smap_get(ovs_other_config, flag); + + /* Process the vhost-sock-dir flag if it is provided, otherwise resort to + * default value. + */ + if (val && (strlen(val) <= size)) { + changed = 1; + *new_val = xstrdup(val); + VLOG_INFO("User-provided %s in use: %s", flag, *new_val); + } else { + VLOG_INFO("No %s provided - defaulting to %s", flag, default_val); + *new_val = xstrdup(default_val); + } + + return changed; +} + +static void +parse_vhost_config(const struct smap *ovs_other_config) +{ + char *sock_dir_subcomponent; + + if (process_vhost_flags("vhost-sock-dir", ovs_rundir(), + NAME_MAX, ovs_other_config, + &sock_dir_subcomponent)) { + struct stat s; + + if (!strstr(sock_dir_subcomponent, "..")) { + vhost_sock_dir = xasprintf("%s/%s", ovs_rundir(), + sock_dir_subcomponent); + + if (stat(vhost_sock_dir, &s)) { + VLOG_ERR("vhost-user sock directory '%s' does not exist.", + vhost_sock_dir); + } + } else { + vhost_sock_dir = xstrdup(ovs_rundir()); + VLOG_ERR("vhost-user sock directory request '%s/%s' has invalid" + "characters '..' - using %s instead.", + ovs_rundir(), sock_dir_subcomponent, ovs_rundir()); + } + free(sock_dir_subcomponent); + } else { + vhost_sock_dir = sock_dir_subcomponent; + } + + vhost_iommu_enabled = smap_get_bool(ovs_other_config, + "vhost-iommu-support", false); + VLOG_INFO("IOMMU support for vhost-user-client %s.", + vhost_iommu_enabled ? "enabled" : "disabled"); + + vhost_postcopy_enabled = smap_get_bool(ovs_other_config, + "vhost-postcopy-support", false); + if (vhost_postcopy_enabled && memory_locked()) { + VLOG_WARN("vhost-postcopy-support and mlockall are not compatible."); + vhost_postcopy_enabled = false; + } + VLOG_INFO("POSTCOPY support for vhost-user-client %s.", + vhost_postcopy_enabled ? "enabled" : "disabled"); +} + #define NETDEV_DPDK_CLASS_COMMON \ .is_pmd = true, \ .alloc = netdev_dpdk_alloc, \ @@ -5523,10 +5609,10 @@ static const struct netdev_class dpdk_vhost_client_class = { void netdev_dpdk_register(const struct smap *ovs_other_config) { - const char *mempoolcfg = smap_get(ovs_other_config, - "shared-mempool-config"); + parse_mempool_config(ovs_other_config); + parse_user_mempools_list(ovs_other_config); + parse_vhost_config(ovs_other_config); - parse_user_mempools_list(mempoolcfg); netdev_register_provider(&dpdk_class); netdev_register_provider(&dpdk_vhost_class); netdev_register_provider(&dpdk_vhost_client_class); -- 2.37.2 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
