diff --git a/examples/skeleton/basicfwd.c b/examples/skeleton/basicfwd.c index 133293cf15b..ffb3ecd4c34 100644 --- a/examples/skeleton/basicfwd.c +++ b/examples/skeleton/basicfwd.c @@ -10,6 +10,19 @@ #include #include #include +#include + +/* TM hierarchy IDs */ +#define TM_SHAPER_PROFILE_ID 0 /* arbitrary user-chosen ID */ +#define TM_SHARED_SHAPER_ID 0 /* unused here */ +#define TM_NODE_ID_ROOT 100 /* > number of RX queues */ +#define TM_NODE_ID_NON_LEAF 246 +#define TM_NODE_ID_QUEUE_BASE 0 /* leaf nodes use queue index 0… */ + +/* Simple single-rate shaper params */ +static struct rte_tm_shaper_params tm_shaper_params = { + .peak = { .rate = 1000000 /* 1 Mbps */} +}; #define RX_RING_SIZE 1024 #define TX_RING_SIZE 1024 @@ -81,6 +94,86 @@ port_init(uint16_t port, struct rte_mempool *mbuf_pool) return retval; } + /********************************************************/ + struct rte_tm_error tm_error; + int status; + + /* 1) Create shaper profile */ + status = rte_tm_shaper_profile_add(port, + TM_SHAPER_PROFILE_ID, + &tm_shaper_params, + &tm_error); + if (status != 0) { + rte_exit(EXIT_FAILURE, + "TM shaper profile add failed: %d\n", status); + } + + /* 2) Add root node (non-leaf) */ + struct rte_tm_node_params root_params = { + .shaper_profile_id = TM_SHAPER_PROFILE_ID, + .shared_shaper_id = TM_SHARED_SHAPER_ID, + .n_shared_shapers = 0, + .nonleaf = { + .n_sp_priorities = 1 + } + }; + status = rte_tm_node_add(port, + TM_NODE_ID_ROOT, + RTE_TM_NODE_ID_NULL, + 0, /* level */ + 1, /* weight (unused for root) */ + 0, /* hierarchy level = 1 */ + &root_params, + &tm_error); + if (status != 0) { + rte_exit(EXIT_FAILURE, + "TM root node add failed: %d\n", status); + } + + /* 2) Add non-leaf node (child of root) */ + status = rte_tm_node_add(port, + TM_NODE_ID_NON_LEAF, + TM_NODE_ID_ROOT, + 0, /* level */ + 1, /* weight (unused for root) */ + 1, /* hierarchy level = 1 */ + &root_params, + &tm_error); + if (status != 0) { + rte_exit(EXIT_FAILURE, + "TM root node add failed: %d\n", status); + } + + /* 3) Add leaf node */ + + struct rte_tm_node_params leaf_params = { + .leaf = { + .cman = RTE_TM_CMAN_TAIL_DROP, + .wred.wred_profile_id = RTE_TM_WRED_PROFILE_ID_NONE + } + }; + status = rte_tm_node_add(port, + TM_NODE_ID_QUEUE_BASE, + TM_NODE_ID_NON_LEAF, + 0, /* priority */ + 1, /* weight */ + 2, /* leaf-level */ + &leaf_params, + &tm_error); + if (status != 0) { + rte_exit(EXIT_FAILURE, + "TM leaf node %u add failed: %d %s\n", q, status, tm_error.message); + } + + /* 4) Commit the hierarchy */ + status = rte_tm_hierarchy_commit(port, /* clear_on_fail = */ 1, &tm_error); + if (status != 0) { + rte_exit(EXIT_FAILURE, + "TM hierarchy commit failed: %d %s\n", status, tm_error.message); + } + + /********************************************************/ + /* Starting Ethernet port. 8< */ retval = rte_eth_dev_start(port); /* >8 End of starting of ethernet port. */