diff options
| author | songyanchao <[email protected]> | 2022-09-29 06:49:59 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2022-09-29 06:49:59 +0000 |
| commit | 1a2de70fda3d046857033193e9a5c080635124f0 (patch) | |
| tree | a0c6951783011725c16f1a7b4222239e41a87a05 | |
| parent | 3c8a50ef4256dbacc7d1534174333e918cef3201 (diff) | |
🎈 perf(TSG-11429): 优化ethe_egress计数处理流程
优化ethe_egress计数处理流程
| -rw-r--r-- | service/src/node_eth_egress.c | 131 | ||||
| -rw-r--r-- | service/src/node_lb.c | 3 |
2 files changed, 62 insertions, 72 deletions
diff --git a/service/src/node_eth_egress.c b/service/src/node_eth_egress.c index aad521e..36b0c19 100644 --- a/service/src/node_eth_egress.c +++ b/service/src/node_eth_egress.c @@ -26,20 +26,20 @@ st->graph_stat[graph_id].counter += value; \ } while (0) -/* Eth Egress Next Node */ +/* Eth egress next node */ enum { ETH_EGRESS_NEXT_PKT_DROP = 0, ETH_EGRESS_NEXT_MAX }; -/* Eth Egress Stat Struct */ +/* Eth egress stat struct */ struct eth_egress_stat_per_lcore { volatile uint64_t total_pkts; }; -/* Eth Egress Main Struct */ +/* Eth egress main struct */ struct node_eth_egress_main { uint16_t phydev_edges_node_table[MR_PHYDEV_MAX]; @@ -47,33 +47,30 @@ struct node_eth_egress_main struct eth_egress_stat_per_lcore graph_stat[RTE_MAX_LCORE]; }; -/* Global Eth Egress Main */ +/* Global eth egress main */ static struct node_eth_egress_main * global_eth_egress_main = NULL; -/* Device Attribute Table Init */ +/* Device attribute table init */ int edges_node_table_init(struct sc_main * sc, struct node_eth_egress_main * eth_egress_main) { - struct phydev * phydev_iter = NULL; - struct vdev * vdev_iter = NULL; - unsigned int vdev_iterate_helper = 0; - + /* Init edges node table */ for (int phydev_index = 0; phydev_index < MR_PHYDEV_MAX; phydev_index++) eth_egress_main->phydev_edges_node_table[phydev_index] = MR_ETH_EGRESS_INVALID_EDGES_INDEX; for (int shmdev_index = 0; shmdev_index < MR_PHYDEV_MAX; shmdev_index++) eth_egress_main->shmdev_edges_node_table[shmdev_index] = MR_ETH_EGRESS_INVALID_EDGES_INDEX; + /* Fill phydev edges node table */ + struct phydev * phydev_iter = NULL; while (phydev_iterate(sc->phydev_main, &phydev_iter) >= 0) { - uint16_t next_edges_index = MR_ETH_EGRESS_INVALID_EDGES_INDEX; - uint32_t count; char edges_node_name[MR_SYMBOL_MAX]; - char ** __next_edges; - snprintf(edges_node_name, sizeof(edges_node_name), "phydev_tx-%s", phydev_iter->symbol); rte_node_t node_id = rte_node_from_name("eth_egress"); - count = rte_node_edge_get(node_id, NULL); - __next_edges = malloc(count); + uint32_t count = rte_node_edge_get(node_id, NULL); + char ** __next_edges = malloc(count); count = rte_node_edge_get(node_id, __next_edges); + + uint16_t next_edges_index = MR_ETH_EGRESS_INVALID_EDGES_INDEX; for (int edges_index = 0; edges_index < count; edges_index++) { if (strncmp(__next_edges[edges_index], edges_node_name, sizeof(edges_node_name)) != 0) @@ -85,24 +82,25 @@ int edges_node_table_init(struct sc_main * sc, struct node_eth_egress_main * eth if (next_edges_index == MR_ETH_EGRESS_INVALID_EDGES_INDEX) { - MR_ERROR("Eth Egress Init Err,The Phydev '%s' ,Not Find Tx Node Index .", phydev_iter->symbol); + MR_ERROR("Eth egress Init Err,The Phydev '%s' ,Not Find Tx node Index .", phydev_iter->symbol); return RT_ERR; } eth_egress_main->phydev_edges_node_table[phydev_iter->port_id] = next_edges_index; } + /* Fill shmdev edges node table */ + struct vdev * vdev_iter = NULL; + unsigned int vdev_iterate_helper = 0; while (vdev_iterate(sc->vdev_main, &vdev_iter, &vdev_iterate_helper) >= 0) { - uint16_t next_edges_index = MR_ETH_EGRESS_INVALID_EDGES_INDEX; - uint32_t count; char edges_node_name[MR_SYMBOL_MAX]; - char ** __next_edges; - snprintf(edges_node_name, sizeof(edges_node_name), "shmdev_tx-%s", vdev_iter->symbol); rte_node_t node_id = rte_node_from_name("eth_egress"); - count = rte_node_edge_get(node_id, NULL); - __next_edges = malloc(count); + uint32_t count = rte_node_edge_get(node_id, NULL); + char ** __next_edges = malloc(count); count = rte_node_edge_get(node_id, __next_edges); + + uint16_t next_edges_index = MR_ETH_EGRESS_INVALID_EDGES_INDEX; for (int edges_index = 0; edges_index < count; edges_index++) { if (strncmp(__next_edges[edges_index], edges_node_name, sizeof(edges_node_name)) != 0) @@ -114,7 +112,7 @@ int edges_node_table_init(struct sc_main * sc, struct node_eth_egress_main * eth if (next_edges_index == MR_ETH_EGRESS_INVALID_EDGES_INDEX) { - MR_ERROR("Eth Egress Init Err,The Shmdev '%s' ,Not Find Tx Node Index .", vdev_iter->symbol); + MR_ERROR("Eth egress Init Err,The Shmdev '%s' ,Not Find Tx node Index .", vdev_iter->symbol); return RT_ERR; } eth_egress_main->shmdev_edges_node_table[vdev_iter->port_id] = next_edges_index; @@ -122,12 +120,10 @@ int edges_node_table_init(struct sc_main * sc, struct node_eth_egress_main * eth return RT_SUCCESS; } -/* Init Eth Egress */ +/* Init eth egress */ int eth_egress_init(struct sc_main * sc) { - struct node_eth_egress_main * eth_egress_main = NULL; - - eth_egress_main = ZMALLOC(sizeof(struct node_eth_egress_main)); + struct node_eth_egress_main * eth_egress_main = ZMALLOC(sizeof(struct node_eth_egress_main)); MR_VERIFY_MALLOC(eth_egress_main); sc->eth_egress_node_main = eth_egress_main; @@ -136,47 +132,42 @@ int eth_egress_init(struct sc_main * sc) return RT_SUCCESS; } -/************************************** Eth Egress Node **************************************/ -/* Eth Egress Node Init Function */ +/************************************** Eth egress node **************************************/ +/* Eth egress node init function */ static int eth_egress_node_init(const struct rte_graph * graph, struct rte_node * node) { return 0; } -/* Eth Egress Node Process Function */ +/* Eth egress node process function */ static __rte_always_inline uint16_t eth_egress_node_process(struct rte_graph * graph, struct rte_node * node, void ** objs, uint16_t cnt) { - uint16_t n_left_from = 0, last_spec = 0, batch_next_node_index = 0, next_node_index = 0; - rte_graph_t graph_id; - struct rte_mbuf *mbuf, **pkts; - void ** batch_pkts; - struct node_eth_egress_main * eth_egress_main = NULL; - /* Get Pkts Num And Pkts Buffer */ - n_left_from = cnt; - pkts = (struct rte_mbuf **)objs; - batch_pkts = objs; - batch_next_node_index = ETH_EGRESS_NEXT_PKT_DROP; - graph_id = graph->id; - eth_egress_main = global_eth_egress_main; + uint16_t last_spec = 0; + uint16_t n_left_from = cnt; + struct rte_mbuf ** pkts = (struct rte_mbuf **)objs; + void ** batch_pkts = objs; + uint16_t batch_next_node_index = ETH_EGRESS_NEXT_PKT_DROP; + rte_graph_t graph_id = graph->id; + struct node_eth_egress_main * eth_egress_main = global_eth_egress_main; /* Single Packet Processing */ while (n_left_from > 0) { - uint16_t port_egress = MR_ETH_EGRESS_INVALID_PORT_INDEX, max_port_index = MR_ETH_EGRESS_INVALID_PORT_INDEX; - struct private_data * private_ctrlzone = NULL; - uint16_t * edges_node_table = NULL; - mbuf = pkts[0]; + struct rte_mbuf * mbuf = pkts[0]; pkts += 1; n_left_from -= 1; + /* Update total pkts */ MR_ETH_EGRESS_STAT_ADD(eth_egress_main, graph_id, total_pkts, 1); - private_ctrlzone = mrbuf_cz_data(mbuf, MR_NODE_CTRLZONE_ID); - port_egress = private_ctrlzone->port_egress; + struct private_data * private_ctrlzone = mrbuf_cz_data(mbuf, MR_NODE_CTRLZONE_ID); + uint16_t port_egress = private_ctrlzone->port_egress; - /* Get Max Port Index And Edges Table */ + /* Get max port index and edges table */ + uint16_t max_port_index = MR_ETH_EGRESS_INVALID_PORT_INDEX; + uint16_t * edges_node_table = NULL; if (private_ctrlzone->port_egress_is_shmdev) { max_port_index = MR_VDEV_MAX; @@ -188,14 +179,17 @@ static __rte_always_inline uint16_t eth_egress_node_process(struct rte_graph * g edges_node_table = eth_egress_main->phydev_edges_node_table; } + /* Check egress port */ assert(port_egress < max_port_index); - next_node_index = edges_node_table[port_egress]; + + /* Get next node index */ + uint16_t next_node_index = edges_node_table[port_egress]; assert(next_node_index != MR_ETH_EGRESS_INVALID_EDGES_INDEX); - /* Judge The Next Index Whether To Change */ + /* Judge the next index whether to change */ if (unlikely(batch_next_node_index != next_node_index)) { - /* If The Next Index Has Been Changed,Enqueue Last Pkts */ + /* If the next index has been changed,enqueue last pkts */ rte_node_enqueue(graph, node, batch_next_node_index, batch_pkts, last_spec); batch_pkts += last_spec; last_spec = 1; @@ -203,18 +197,18 @@ static __rte_always_inline uint16_t eth_egress_node_process(struct rte_graph * g } else { - /* If The Next Index Not Change, Update The Lasts */ + /* If the next index not change, update the lasts */ last_spec++; } } - /* Process The Remaining Packets */ + /* Process the remaining packets */ if (likely(last_spec > 0)) rte_node_enqueue(graph, node, batch_next_node_index, batch_pkts, last_spec); return cnt; } -/* Eth Egress Node Base */ +/* Eth egress node Base */ static struct rte_node_register eth_egress_node_base = { .process = eth_egress_node_process, .name = "eth_egress", @@ -227,31 +221,28 @@ static struct rte_node_register eth_egress_node_base = { }; RTE_NODE_REGISTER(eth_egress_node_base); -/************************************** Eth Egress Statistics **************************************/ +/************************************** Eth egress statistics **************************************/ cJSON * eth_egress_node_monit_loop(struct sc_main * sc) { - uint32_t graph_id = 0, graph_num = 0; - cJSON *json_root = NULL, *graph_obj = NULL; struct node_eth_egress_main * eth_egress_main = sc->eth_egress_node_main; - unsigned int nr_io_thread = sc->nr_io_thread; - json_root = cJSON_CreateObject(); + unsigned int nr_graph_total = sc->nr_io_thread; + cJSON * json_root = cJSON_CreateObject(); - for (graph_id = 0; graph_id < nr_io_thread; graph_id++) + for (uint32_t graph_id = 0; graph_id < nr_graph_total; graph_id++) { - char graph_index[MR_STRING_MAX]; - uint64_t stats = 0; struct eth_egress_stat_per_lcore * stat_item = ð_egress_main->graph_stat[graph_id]; - stats = stat_item->total_pkts; - if (stats == 0) + if (stat_item->total_pkts == 0) continue; - graph_obj = cJSON_CreateObject(); - cJSON_AddNumberToObject(graph_obj, "total_pkts", stats); - sprintf(graph_index, "graph-%u", graph_num); + + cJSON * graph_obj = cJSON_CreateObject(); + cJSON_AddNumberToObject(graph_obj, "total_pkts", stat_item->total_pkts); + + char graph_index[MR_STRING_MAX] = {}; + sprintf(graph_index, "graph-%u", graph_id); cJSON_AddItemToObject(json_root, graph_index, graph_obj); - graph_num++; } - cJSON_AddNumberToObject(json_root, "total_graph_num", graph_num); + cJSON_AddNumberToObject(json_root, "total_graph_num", nr_graph_total); return json_root; } diff --git a/service/src/node_lb.c b/service/src/node_lb.c index c4a643e..58483aa 100644 --- a/service/src/node_lb.c +++ b/service/src/node_lb.c @@ -846,14 +846,13 @@ static int lb_node_init(const struct rte_graph * graph, struct rte_node * node) static __rte_always_inline uint16_t lb_node_process(struct rte_graph * graph, struct rte_node * node, void ** objs, uint16_t cnt) { - uint16_t last_spec = 0; - /* Set rcu thread online */ struct rte_rcu_qsbr * qsv = global_lb_main->qsv; uint32_t lcore_id = rte_lcore_id(); rte_rcu_qsbr_thread_online(qsv, lcore_id); /* Get pkts num and pkts buffer */ + uint16_t last_spec = 0; uint16_t n_left_from = cnt; struct rte_mbuf ** pkts = (struct rte_mbuf **)objs; void ** batch_pkts = objs; |
