From c4665093cdb0a8122d9640b6f5b3acd627918f32 Mon Sep 17 00:00:00 2001 From: Chenmin Sun Date: Mon, 6 Jul 2020 08:20:39 +0800 Subject: interface: support configuring RSS steering queues This patch adds the RSS steering queues set interface, and it's implementation in DPDK device: /* Interface to set rss queues of the interface */ typedef clib_error_t *(vnet_interface_rss_queues_set_t) (struct vnet_main_t * vnm, struct vnet_hw_interface_t * hi, clib_bitmap_t *bitmap); This patch also introduces a command line to set the RSS queues: set interface rss queues > To display the rss queues, use "show hardware-interfaces" Below is the example to configure rss queues for interface Gig0: vpp# set interface rss queues Gig0 list 0,2,4-7 vpp# show hardware-interfaces brief Name Idx Link Hardware VirtualFunctionEthernet18/1/0 1 down VirtualFunctionEthernet18/1/0 Link speed: unknown RSS queues: 0 2 4 5 6 7 local0 0 down local0 Link speed: unknown vpp# Users can also configure the rss queues on a dpdk interface in startup.conf: dpdk { dev 0000:18:01.0 { rss-queues 0,2,5-7 } } Type: feature Signed-off-by: Chenmin Sun Change-Id: I1835595a1c54016a84eabee9fd62ce137935385d --- src/plugins/dpdk/device/device.c | 104 +++++++++++++++++++++++++++++++++++++++ src/plugins/dpdk/device/dpdk.h | 2 +- src/plugins/dpdk/device/init.c | 82 +++++++++++++++++------------- src/vnet/devices/devices.c | 2 - src/vnet/interface.c | 36 ++++++++++++++ src/vnet/interface.h | 12 +++++ src/vnet/interface_cli.c | 83 +++++++++++++++++++++++++++++++ src/vnet/interface_format.c | 26 ++++++++++ src/vnet/interface_funcs.h | 5 ++ src/vpp/conf/startup.conf | 4 ++ 10 files changed, 320 insertions(+), 36 deletions(-) diff --git a/src/plugins/dpdk/device/device.c b/src/plugins/dpdk/device/device.c index 09a1c2f2fdf..e58dd6f4228 100644 --- a/src/plugins/dpdk/device/device.c +++ b/src/plugins/dpdk/device/device.c @@ -584,6 +584,109 @@ done: return err; } +static clib_error_t * +dpdk_interface_set_rss_queues (struct vnet_main_t *vnm, + struct vnet_hw_interface_t *hi, + clib_bitmap_t * bitmap) +{ + dpdk_main_t *xm = &dpdk_main; + u32 hw_if_index = hi->hw_if_index; + vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); + dpdk_device_t *xd = vec_elt_at_index (xm->devices, hw->dev_instance); + clib_error_t *err = 0; + struct rte_eth_rss_reta_entry64 *reta_conf = NULL; + struct rte_eth_dev_info dev_info; + u16 *reta = NULL; + u16 *valid_queue = NULL; + u16 valid_queue_count = 0; + uint32_t i, j; + uint32_t ret; + + rte_eth_dev_info_get (xd->port_id, &dev_info); + + /* parameter check */ + if (clib_bitmap_count_set_bits (bitmap) == 0) + { + err = clib_error_return (0, "must assign at least one valid rss queue"); + goto done; + } + + if (clib_bitmap_count_set_bits (bitmap) > dev_info.nb_rx_queues) + { + err = clib_error_return (0, "too many rss queues"); + goto done; + } + + /* new RETA */ + reta = clib_mem_alloc (dev_info.reta_size * sizeof (*reta)); + if (reta == NULL) + { + err = clib_error_return (0, "clib_mem_alloc failed"); + goto done; + } + + clib_memset (reta, 0, dev_info.reta_size * sizeof (*reta)); + + valid_queue_count = 0; + /* *INDENT-OFF* */ + clib_bitmap_foreach (i, bitmap, ({ + if (i >= dev_info.nb_rx_queues) + { + err = clib_error_return (0, "illegal queue number"); + goto done; + } + reta[valid_queue_count++] = i; + })); + /* *INDENT-ON* */ + + valid_queue = reta; + for (i = valid_queue_count, j = 0; i < dev_info.reta_size; i++, j++) + { + j = j % valid_queue_count; + reta[i] = valid_queue[j]; + } + + /* update reta table */ + reta_conf = + (struct rte_eth_rss_reta_entry64 *) clib_mem_alloc (dev_info.reta_size / + RTE_RETA_GROUP_SIZE * + sizeof (*reta_conf)); + if (reta_conf == NULL) + { + err = clib_error_return (0, "clib_mem_alloc failed"); + goto done; + } + + clib_memset (reta_conf, 0, + dev_info.reta_size / RTE_RETA_GROUP_SIZE * + sizeof (*reta_conf)); + + for (i = 0; i < dev_info.reta_size; i++) + { + uint32_t reta_id = i / RTE_RETA_GROUP_SIZE; + uint32_t reta_pos = i % RTE_RETA_GROUP_SIZE; + + reta_conf[reta_id].mask = UINT64_MAX; + reta_conf[reta_id].reta[reta_pos] = reta[i]; + } + + ret = + rte_eth_dev_rss_reta_update (xd->port_id, reta_conf, dev_info.reta_size); + if (ret) + { + err = clib_error_return (0, "rte_eth_dev_rss_reta_update err %d", ret); + goto done; + } + +done: + if (reta) + clib_mem_free (reta); + if (reta_conf) + clib_mem_free (reta_conf); + + return err; +} + /* *INDENT-OFF* */ VNET_DEVICE_CLASS (dpdk_device_class) = { .name = "dpdk", @@ -600,6 +703,7 @@ VNET_DEVICE_CLASS (dpdk_device_class) = { .mac_addr_add_del_function = dpdk_add_del_mac_address, .format_flow = format_dpdk_flow, .flow_ops_function = dpdk_flow_ops_fn, + .set_rss_queues_function = dpdk_interface_set_rss_queues, }; /* *INDENT-ON* */ diff --git a/src/plugins/dpdk/device/dpdk.h b/src/plugins/dpdk/device/dpdk.h index 963bc811ee1..40f9dce0c05 100644 --- a/src/plugins/dpdk/device/dpdk.h +++ b/src/plugins/dpdk/device/dpdk.h @@ -260,6 +260,7 @@ typedef struct clib_bitmap_t * workers; u8 tso; u8 *devargs; + clib_bitmap_t *rss_queues; #define DPDK_DEVICE_TSO_DEFAULT 0 #define DPDK_DEVICE_TSO_OFF 1 @@ -373,7 +374,6 @@ typedef struct void dpdk_device_setup (dpdk_device_t * xd); void dpdk_device_start (dpdk_device_t * xd); void dpdk_device_stop (dpdk_device_t * xd); - int dpdk_port_state_callback (dpdk_portid_t port_id, enum rte_eth_event_type type, void *param, void *ret_param); diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c index 9d4aeed6924..81803ab1cb4 100644 --- a/src/plugins/dpdk/device/init.c +++ b/src/plugins/dpdk/device/init.c @@ -616,7 +616,6 @@ dpdk_lib_init (dpdk_main_t * dm) /* assign interface to input thread */ int q; - error = ethernet_register_interface (dm->vnet_main, dpdk_device_class.index, xd->device_index, /* ethernet address */ addr, @@ -759,10 +758,20 @@ dpdk_lib_init (dpdk_main_t * dm) dpdk_device_setup (xd); + /* rss queues should be configured after dpdk_device_setup() */ + if (devconf->rss_queues != NULL) + { + if (vnet_hw_interface_set_rss_queues + (vnet_get_main (), hi, devconf->rss_queues)) + { + clib_warning ("%s: Failed to set rss queues", hi->name); + } + } + if (vec_len (xd->errors)) - dpdk_log_err ("setup failed for device %U. Errors:\n %U", - format_dpdk_device_name, i, - format_dpdk_device_errors, xd); + dpdk_log_err ("setup failed for device %U. Errors:\n %U", + format_dpdk_device_name, i, + format_dpdk_device_errors, xd); /* * A note on Cisco VIC (PMD_ENIC) and VLAN: @@ -789,38 +798,39 @@ dpdk_lib_init (dpdk_main_t * dm) * otherwise in the startup config. */ - vlan_off = rte_eth_dev_get_vlan_offload (xd->port_id); - if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON) - { - vlan_off |= ETH_VLAN_STRIP_OFFLOAD; - if (rte_eth_dev_set_vlan_offload (xd->port_id, vlan_off) >= 0) - dpdk_log_info ("VLAN strip enabled for interface\n"); - else - dpdk_log_warn ("VLAN strip cannot be supported by interface\n"); - xd->port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_STRIP; - } - else - { - if (vlan_off & ETH_VLAN_STRIP_OFFLOAD) - { - vlan_off &= ~ETH_VLAN_STRIP_OFFLOAD; - if (rte_eth_dev_set_vlan_offload (xd->port_id, vlan_off) >= 0) - dpdk_log_warn ("set VLAN offload failed\n"); - } - xd->port_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP; - } + vlan_off = rte_eth_dev_get_vlan_offload (xd->port_id); + if (devconf->vlan_strip_offload == DPDK_DEVICE_VLAN_STRIP_ON) + { + vlan_off |= ETH_VLAN_STRIP_OFFLOAD; + if (rte_eth_dev_set_vlan_offload (xd->port_id, vlan_off) >= 0) + dpdk_log_info ("VLAN strip enabled for interface\n"); + else + dpdk_log_warn ("VLAN strip cannot be supported by interface\n"); + xd->port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_VLAN_STRIP; + } + else + { + if (vlan_off & ETH_VLAN_STRIP_OFFLOAD) + { + vlan_off &= ~ETH_VLAN_STRIP_OFFLOAD; + if (rte_eth_dev_set_vlan_offload (xd->port_id, vlan_off) >= 0) + dpdk_log_warn ("set VLAN offload failed\n"); + } + xd->port_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP; + } - if (hi) - hi->max_packet_bytes = xd->port_conf.rxmode.max_rx_pkt_len - - sizeof (ethernet_header_t); - else - dpdk_log_warn ("hi NULL"); + if (hi) + hi->max_packet_bytes = xd->port_conf.rxmode.max_rx_pkt_len + - sizeof (ethernet_header_t); + else + dpdk_log_warn ("hi NULL"); - if (dm->conf->no_multi_seg) - mtu = mtu > ETHER_MAX_LEN ? ETHER_MAX_LEN : mtu; + if (dm->conf->no_multi_seg) + mtu = mtu > ETHER_MAX_LEN ? ETHER_MAX_LEN : mtu; + + rte_eth_dev_set_mtu (xd->port_id, mtu); +} - rte_eth_dev_set_mtu (xd->port_id, mtu); - } /* *INDENT-ON* */ return 0; @@ -1094,6 +1104,9 @@ dpdk_device_config (dpdk_config_main_t * conf, vlib_pci_addr_t pci_addr, } else if (unformat (input, "devargs %s", &devconf->devargs)) ; + else if (unformat (input, "rss-queues %U", + unformat_bitmap_list, &devconf->rss_queues)) + ; else { error = clib_error_return (0, "unknown input `%U'", @@ -1416,6 +1429,9 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input) /* copy tso config from default device */ _(devargs) + /* copy rss_queues config from default device */ + _(rss_queues) + /* add DPDK EAL whitelist/blacklist entry */ if (num_whitelisted > 0 && devconf->is_blacklisted == 0) { diff --git a/src/vnet/devices/devices.c b/src/vnet/devices/devices.c index e78c5cbe45b..cfce2ac2856 100644 --- a/src/vnet/devices/devices.c +++ b/src/vnet/devices/devices.c @@ -341,8 +341,6 @@ vnet_hw_interface_get_rx_mode (vnet_main_t * vnm, u32 hw_if_index, return VNET_API_ERROR_INVALID_INTERFACE; } - - static clib_error_t * vnet_device_init (vlib_main_t * vm) { diff --git a/src/vnet/interface.c b/src/vnet/interface.c index 6d5b3561f19..18c7696e9a4 100644 --- a/src/vnet/interface.c +++ b/src/vnet/interface.c @@ -1692,6 +1692,42 @@ default_update_adjacency (vnet_main_t * vnm, u32 sw_if_index, u32 ai) } } +clib_error_t * +vnet_hw_interface_set_rss_queues (vnet_main_t * vnm, + vnet_hw_interface_t * hi, + clib_bitmap_t * bitmap) +{ + clib_error_t *error = 0; + vnet_device_class_t *dev_class = + vnet_get_device_class (vnm, hi->dev_class_index); + + if (dev_class->set_rss_queues_function) + { + if (clib_bitmap_count_set_bits (bitmap) == 0) + { + error = clib_error_return (0, + "must assign at least one valid rss queue"); + goto done; + } + + error = dev_class->set_rss_queues_function (vnm, hi, bitmap); + } + else + { + error = clib_error_return (0, + "setting rss queues is not supported on this interface"); + } + + if (!error) + { + clib_bitmap_free (hi->rss_queues); + hi->rss_queues = clib_bitmap_dup (bitmap); + } + +done: + return error; +} + int collect_detailed_interface_stats_flag = 0; void diff --git a/src/vnet/interface.h b/src/vnet/interface.h index 07da2617d71..895ce2e9279 100644 --- a/src/vnet/interface.h +++ b/src/vnet/interface.h @@ -88,6 +88,11 @@ typedef clib_error_t *(vnet_interface_set_l2_mode_function_t) (struct vnet_main_t * vnm, struct vnet_hw_interface_t * hi, i32 l2_if_adjust); +/* Interface to set rss queues of the interface */ +typedef clib_error_t *(vnet_interface_rss_queues_set_t) + (struct vnet_main_t * vnm, struct vnet_hw_interface_t * hi, + clib_bitmap_t * bitmap); + typedef enum { VNET_FLOW_DEV_OP_ADD_FLOW, @@ -273,6 +278,10 @@ typedef struct _vnet_device_class /* Function to add/delete additional MAC addresses */ vnet_interface_add_del_mac_address_function_t *mac_addr_add_del_function; + + /* Interface to set rss queues of the interface */ + vnet_interface_rss_queues_set_t *set_rss_queues_function; + } vnet_device_class_t; #ifndef CLIB_MARCH_VARIANT @@ -601,6 +610,9 @@ typedef struct vnet_hw_interface_t /* numa node that hardware device connects to */ u8 numa_node; + /* rss queues bitmap */ + clib_bitmap_t *rss_queues; + /* trace */ i32 n_trace; diff --git a/src/vnet/interface_cli.c b/src/vnet/interface_cli.c index bee813f5874..28f24ae3977 100644 --- a/src/vnet/interface_cli.c +++ b/src/vnet/interface_cli.c @@ -1886,6 +1886,89 @@ VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = { }; /* *INDENT-ON* */ +clib_error_t * +set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index, + clib_bitmap_t * bitmap) +{ + vnet_main_t *vnm = vnet_get_main (); + vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); + + return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap); +} + +static clib_error_t * +set_interface_rss_queues_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + unformat_input_t _line_input, *line_input = &_line_input; + vnet_main_t *vnm = vnet_get_main (); + u32 hw_if_index = (u32) ~ 0; + clib_bitmap_t *bitmap = NULL; + + if (!unformat_user (input, unformat_line_input, line_input)) + return 0; + + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + { + if (unformat + (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) + ; + else + if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap)) + ; + else + { + error = clib_error_return (0, "parse error: '%U'", + format_unformat_error, line_input); + unformat_free (line_input); + goto done; + } + } + + unformat_free (line_input); + + if (hw_if_index == (u32) ~ 0) + { + error = clib_error_return (0, "please specify valid interface name"); + goto done; + } + + if (bitmap == NULL) + { + error = clib_error_return (0, "please specify the valid rss queues"); + goto done; + } + + error = set_interface_rss_queues (vm, hw_if_index, bitmap); + +done: + if (bitmap) + clib_bitmap_free (bitmap); + + return (error); +} + +/*? + * This command is used to set the rss queues of a given interface + * Not all the interfaces support this operation. + * To display the current rss queues, use the command + * 'show hardware-interfaces'. + * + * @cliexpar + * Example of how to set the rss queues to 0,2-5,7 of an interface: + * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7} + * @cliexend +?*/ +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = { + .path = "set interface rss queues", + .short_help = "set interface rss queues >", + .function = set_interface_rss_queues_fn, +}; +/* *INDENT-ON* */ + static u8 * format_vnet_pcap (u8 * s, va_list * args) { diff --git a/src/vnet/interface_format.c b/src/vnet/interface_format.c index 8278102c644..2b691a66071 100644 --- a/src/vnet/interface_format.c +++ b/src/vnet/interface_format.c @@ -130,6 +130,26 @@ format_vnet_hw_interface_link_speed (u8 * s, va_list * args) return format (s, "%u Kbps", link_speed); } +u8 * +format_vnet_hw_interface_rss_queues (u8 * s, va_list * args) +{ + clib_bitmap_t *bitmap = va_arg (*args, clib_bitmap_t *); + int i; + + if (bitmap == NULL) + return s; + + if (bitmap) + { + /* *INDENT-OFF* */ + clib_bitmap_foreach (i, bitmap, ({ + s = format (s, "%u ", i); + })); + /* *INDENT-ON* */ + } + + return s; +} u8 * format_vnet_hw_interface (u8 * s, va_list * args) @@ -172,6 +192,12 @@ format_vnet_hw_interface (u8 * s, va_list * args) s = format (s, "\n%ULink speed: %U", format_white_space, indent + 2, format_vnet_hw_interface_link_speed, hi->link_speed); + if (hi->rss_queues) + { + s = format (s, "\n%URSS queues: %U", format_white_space, indent + 2, + format_vnet_hw_interface_rss_queues, hi->rss_queues); + } + if (verbose) { if (hw_class->format_device) diff --git a/src/vnet/interface_funcs.h b/src/vnet/interface_funcs.h index 7d9c098b118..8f589d1d6dd 100644 --- a/src/vnet/interface_funcs.h +++ b/src/vnet/interface_funcs.h @@ -431,6 +431,11 @@ int vnet_sw_interface_stats_collect_enable_disable (u32 sw_if_index, void vnet_sw_interface_ip_directed_broadcast (vnet_main_t * vnm, u32 sw_if_index, u8 enable); +/* set interface rss queues */ +clib_error_t *vnet_hw_interface_set_rss_queues (vnet_main_t * vnm, + vnet_hw_interface_t * hi, + clib_bitmap_t * bitmap); + /* Formats sw/hw interface. */ format_function_t format_vnet_hw_interface; format_function_t format_vnet_hw_interface_rx_mode; diff --git a/src/vpp/conf/startup.conf b/src/vpp/conf/startup.conf index 86b73f7a77b..56610e2e315 100644 --- a/src/vpp/conf/startup.conf +++ b/src/vpp/conf/startup.conf @@ -110,6 +110,10 @@ cpu { ## device specific init args ## Default is NULL # devargs safe-mode-support=1,pipeline-mode-support=1 + + ## rss-queues + ## set valid rss steering queues + # rss-queues 0,2,5-7 # } ## Whitelist specific interface by specifying PCI address -- cgit 1.2.3-korg