Add --tph-stash-objects command line option to configure PCIe TPH cache stash objects for Rx queues. Implement enable/disable logic during packet forwarding start/stop with device capability checks.
Signed-off-by: Chengwen Feng <[email protected]> --- app/test-pmd/parameters.c | 20 ++++++++++ app/test-pmd/testpmd.c | 81 +++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 1 + 3 files changed, 102 insertions(+) diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index ecbd618f00..ae31d9ba4c 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -79,6 +79,8 @@ enum { TESTPMD_OPT_NO_NUMA_NUM, #define TESTPMD_OPT_MP_ANON "mp-anon" TESTPMD_OPT_MP_ANON_NUM, +#define TESTPMD_OPT_TPH_STASH_OBJECTS "tph-stash-objects" + TESTPMD_OPT_TPH_STASH_OBJECTS_NUM, #define TESTPMD_OPT_PORT_NUMA_CONFIG "port-numa-config" TESTPMD_OPT_PORT_NUMA_CONFIG_NUM, #define TESTPMD_OPT_RING_NUMA_CONFIG "ring-numa-config" @@ -289,6 +291,7 @@ static const struct option long_options[] = { NO_ARG(TESTPMD_OPT_NUMA), NO_ARG(TESTPMD_OPT_NO_NUMA), NO_ARG(TESTPMD_OPT_MP_ANON), /* deprecated */ + REQUIRED_ARG(TESTPMD_OPT_TPH_STASH_OBJECTS), REQUIRED_ARG(TESTPMD_OPT_PORT_NUMA_CONFIG), REQUIRED_ARG(TESTPMD_OPT_RING_NUMA_CONFIG), REQUIRED_ARG(TESTPMD_OPT_SOCKET_NUM), @@ -1140,6 +1143,23 @@ launch_args_parse(int argc, char** argv) "native, anon, xmem or xmemhuge\n", optarg); break; + case TESTPMD_OPT_TPH_STASH_OBJECTS_NUM: + if (!strcmp(optarg, "rxdesc")) + tph_stash_objects = RTE_ETH_CACHE_STASH_OBJ_RX_DESC; + else if (!strcmp(optarg, "rxheader")) + tph_stash_objects = RTE_ETH_CACHE_STASH_OBJ_RX_HEADER; + else if (!strcmp(optarg, "rxpayload")) + tph_stash_objects = RTE_ETH_CACHE_STASH_OBJ_RX_PAYLOAD; + else if (!strcmp(optarg, "rxdata")) + tph_stash_objects = RTE_ETH_CACHE_STASH_OBJ_RX_HEADER | + RTE_ETH_CACHE_STASH_OBJ_RX_PAYLOAD; + else if (!strcmp(optarg, "rxall")) + tph_stash_objects = RTE_ETH_CACHE_STASH_OBJ_RX_DESC | + RTE_ETH_CACHE_STASH_OBJ_RX_HEADER | + RTE_ETH_CACHE_STASH_OBJ_RX_PAYLOAD; + else + rte_exit(EXIT_FAILURE, "unknown tph stash mode %s\n", optarg); + break; case TESTPMD_OPT_PORT_NUMA_CONFIG_NUM: if (parse_portnuma_config(optarg)) rte_exit(EXIT_FAILURE, diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index e2569d9e30..10d9218a9c 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -136,6 +136,11 @@ uint8_t socket_num = UMA_NO_CONFIG; */ uint8_t mp_alloc_type = MP_ALLOC_NATIVE; +/* + * PCIE TPH stash objects. + */ +uint64_t tph_stash_objects; + /* * Store specified sockets on which memory pool to be used by ports * is allocated. @@ -2540,6 +2545,77 @@ update_queue_state(portid_t pid) } } +static void +start_tph_stash(void) +{ + struct rte_eth_cache_stash_capability capa; + struct rte_eth_cache_stash_config config; + struct fwd_config *cfg = &cur_fwd_config; + struct fwd_stream *fs; + lcoreid_t lc_id; + streamid_t sm_id; + portid_t pt_id; + int ret; + int i; + + for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) { + pt_id = fwd_ports_ids[i]; + ret = rte_eth_cache_stash_get(pt_id, &capa); + if (ret != 0 || (capa.supported_types & RTE_ETH_CACHE_STASH_TYPE_TPH) == 0) { + fprintf(stderr, "%s: (port %u) don't support tph stash!\n", + __func__, pt_id); + return; + } + if ((capa.supported_objects & tph_stash_objects) != tph_stash_objects) { + fprintf(stderr, "%s: (port %u) don't support objects=0x%lx 0x%lx\n", + __func__, pt_id, tph_stash_objects, capa.supported_objects); + return; + } + memset(&config, 0, sizeof(config)); + config.dev.type = RTE_ETH_CACHE_STASH_TYPE_TPH; + ret = rte_eth_cache_stash_set(pt_id, RTE_ETH_CACHE_STASH_OP_DEV_ENABLE, &config); + if (ret != 0) { + fprintf(stderr, "%s: (port %u) enable tph failed! ret=%d\n", + __func__, pt_id, ret); + return; + } + } + + for (lc_id = 0; lc_id < cfg->nb_fwd_lcores; lc_id++) { + for (sm_id = 0; sm_id < fwd_lcores[lc_id]->stream_nb; sm_id++) { + fs = fwd_streams[fwd_lcores[lc_id]->stream_idx + sm_id]; + memset(&config, 0, sizeof(config)); + config.queue.lcore_id = fwd_lcores_cpuids[lc_id]; + config.queue.queue_id = fs->rx_queue; + config.queue.objects = tph_stash_objects; + ret = rte_eth_cache_stash_set(fs->rx_port, + RTE_ETH_CACHE_STASH_OP_QUEUE_ENABLE, &config); + if (ret != 0) + fprintf(stderr, "%s: (port %u) enable rx-queue=%u cpu=%u stash ret=%d\n", + __func__, fs->rx_port, fs->rx_queue, + fwd_lcores_cpuids[lc_id], ret); + } + } +} + +static void +stop_tph_stash(void) +{ + struct rte_eth_cache_stash_config config; + portid_t pt_id; + int ret; + int i; + + for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) { + pt_id = fwd_ports_ids[i]; + memset(&config, 0, sizeof(config)); + ret = rte_eth_cache_stash_set(pt_id, RTE_ETH_CACHE_STASH_OP_DEV_DISABLE, &config); + if (ret != 0) + fprintf(stderr, "%s: (port %u) disable tph stash ret=%d\n", + __func__, pt_id, ret); + } +} + /* * Launch packet forwarding configuration. */ @@ -2614,6 +2690,9 @@ start_packet_forwarding(int with_tx_first) if(!no_flush_rx) flush_fwd_rx_queues(); + if (tph_stash_objects > 0) + start_tph_stash(); + rxtx_config_display(); fwd_stats_reset(); @@ -2649,6 +2728,8 @@ stop_packet_forwarding(void) fwd_lcores[lc_id]->stopped = 1; printf("\nWaiting for lcores to finish...\n"); rte_eal_mp_wait_lcore(); + if (tph_stash_objects > 0) + stop_tph_stash(); port_fwd_end = cur_fwd_config.fwd_eng->port_fwd_end; if (port_fwd_end != NULL) { for (i = 0; i < cur_fwd_config.nb_fwd_ports; i++) { diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 9b60ebd7fc..4124d40fda 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -535,6 +535,7 @@ extern uint8_t flow_isolate_all; /**< set by "--flow-isolate-all */ extern uint8_t no_flow_flush; /**< set by "--disable-flow-flush" parameter */ extern uint8_t mp_alloc_type; /**< set by "--mp-anon" or "--mp-alloc" parameter */ +extern uint64_t tph_stash_objects; /**< set by "--tph-stash-objects" parameter */ extern uint32_t eth_link_speed; extern uint8_t no_link_check; /**<set by "--disable-link-check" parameter */ extern uint8_t no_device_start; /**<set by "--disable-device-start" parameter */ -- 2.17.1

