diff options
| author | songyanchao <[email protected]> | 2024-04-17 03:30:03 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2024-04-17 03:30:03 +0000 |
| commit | e34fea65a2c60692b8390cddb5160e39c92f7d0c (patch) | |
| tree | 6e5d9bd91b601d612190444f383e068c0533acf3 | |
| parent | 5a83f0d644a8564791c531d82a79e1aa4899f882 (diff) | |
🎈 perf: Introduce match result struct for bridge node.
Introduce match result struct for bridge node.
| -rw-r--r-- | service/src/node_bridge.c | 145 |
1 files changed, 86 insertions, 59 deletions
diff --git a/service/src/node_bridge.c b/service/src/node_bridge.c index 7086b5c..a03be99 100644 --- a/service/src/node_bridge.c +++ b/service/src/node_bridge.c @@ -16,14 +16,30 @@ enum BRIDGE_NEXT_MAX }; +/* Bridge pkt match results */ +enum bridge_match_result +{ + BRIDGE_MATCH_MISS = 0, + BRIDGE_MATCH_TO_MASTER, + BRIDGE_MATCH_BROADCAST, + BRIDGE_MATCH_DST_MAC, + BRIDGE_MATCH_MAX +}; + +/* Bridge pkt match results string */ +static const char * bridge_match_result_str[] = {[BRIDGE_MATCH_MISS] = "miss", + [BRIDGE_MATCH_TO_MASTER] = "to master", + [BRIDGE_MATCH_BROADCAST] = "broadcast", + [BRIDGE_MATCH_DST_MAC] = "match dst mac", + [BRIDGE_MATCH_MAX] = "unknown"}; + /* Bridge stats struct */ struct bridge_stats { - volatile uint64_t deal_pkts; - volatile uint64_t to_master_dev; - volatile uint64_t drop_for_miss; - volatile uint64_t broadcast; + volatile uint64_t total_pkts; + volatile uint64_t pkts_per_batch; volatile uint64_t pkt_clone_failed; + volatile uint64_t match_result[BRIDGE_MATCH_MAX]; } __rte_cache_aligned; struct bridge @@ -44,7 +60,7 @@ struct node_bridge_main /* Global bridge main */ static struct node_bridge_main g_bridge_main = {}; -static struct bridge_stats stats_per_graph[RTE_MAX_LCORE]; +static struct bridge_stats stats_per_graph[RTE_MAX_LCORE] = {}; static uint8_t last_bridge_index[RTE_MAX_LCORE][64] = {}; static inline struct node_bridge_main * node_bridge_main_get(void) @@ -211,42 +227,21 @@ int bridge_lookup(struct bridge * bridge, struct rte_ether_hdr * ether_hdr, uint /* Generate and store the trace information for original pkt */ static __rte_always_inline void gen_store_trace_info_original(struct rte_node * node, struct rte_mbuf * mbuf, uint16_t next_node_index, struct bridge_stats * stats, - struct bridge_stats * stats_for_trace) + enum bridge_match_result match_result) { - struct dp_trace_record_meta meta = {.appsym = MR_TRACE_APPSYM, .module = node->name}; - /* Populate the next node infomation */ char str_record[MR_STRING_MAX]; - int len = snprintf(str_record, sizeof(str_record), "next node:%s", node->nodes[next_node_index]->name); + int len = snprintf(str_record, sizeof(str_record), ", rsn:%s", bridge_match_result_str[match_result]); - if (next_node_index == BRIDGE_NEXT_DROP) - { - len += snprintf(str_record + len, sizeof(str_record) - len, ", rsn:match unsuccessful"); - } - else + /* Populate the egress port information */ + if (next_node_index != BRIDGE_NEXT_DROP) { - - if (stats->to_master_dev != stats_for_trace->to_master_dev) - { - stats_for_trace->to_master_dev = stats->to_master_dev; - len += snprintf(str_record + len, sizeof(str_record) - len, ", rsn:to master"); - } - else if (stats->broadcast != stats_for_trace->broadcast) - { - stats_for_trace->broadcast = stats->broadcast; - len += snprintf(str_record + len, sizeof(str_record) - len, ", rsn:broadcast original packet"); - } - else - { - len += snprintf(str_record + len, sizeof(str_record) - len, ", rsn:dst mac match"); - } - - /* Populate the egress port information */ struct mrb_metadata * mrb_meta = mrbuf_cz_data(mbuf, MR_NODE_CTRLZONE_ID); len += snprintf(str_record + len, sizeof(str_record) - len, ", tx:%u", mrb_meta->port_egress); } /* Emit the trace record */ + struct dp_trace_record_meta meta = {.appsym = MR_TRACE_APPSYM, .module = node->name}; dp_trace_record_emit_str(sc_main_get()->trace, mbuf, rte_lcore_id(), &meta, str_record); } @@ -258,13 +253,9 @@ static __rte_always_inline void gen_store_trace_info_clone(struct rte_node * nod /* Populate the next node infomation */ char str_record[MR_STRING_MAX]; - int len = snprintf(str_record, sizeof(str_record), "next node:%s", node->nodes[next_node_index]->name); - - len += snprintf(str_record + len, sizeof(str_record) - len, ", rsn:broadcast cloned packet"); - - /* Populate the egress port information */ struct mrb_metadata * mrb_meta = mrbuf_cz_data(mbuf, MR_NODE_CTRLZONE_ID); - len += snprintf(str_record + len, sizeof(str_record) - len, ", tx:%u", mrb_meta->port_egress); + snprintf(str_record, sizeof(str_record), "next node:%s, rsn:broadcast cloned packet, tx:%u", + node->nodes[next_node_index]->name, mrb_meta->port_egress); /* Emit the trace record */ dp_trace_record_emit_str(sc_main_get()->trace, mbuf, rte_lcore_id(), &meta, str_record); @@ -282,7 +273,7 @@ static __rte_always_inline uint16_t bridge_node_process(struct rte_graph * graph rte_graph_t graph_id = graph->id; struct bridge_stats stats = {}; - struct bridge_stats stats_for_trace = {}; + enum bridge_match_result match_result = BRIDGE_MATCH_MAX; struct sc_main * sc = sc_main_get(); struct node_bridge_main * bridge_main = node_bridge_main_get(); @@ -315,6 +306,7 @@ static __rte_always_inline uint16_t bridge_node_process(struct rte_graph * graph int ret = bridge_lookup(bridge, ether_hdr, &last_bridge_index[graph_id][bridge_index], &egress_port); if (likely(ret == RT_SUCCESS)) { + match_result = BRIDGE_MATCH_DST_MAC; mrb_meta->port_egress = egress_port; goto node_enqueue; } @@ -326,19 +318,23 @@ static __rte_always_inline uint16_t bridge_node_process(struct rte_graph * graph egress_port = bridge->master_port; if (likely((egress_port != port_ingress) && (egress_port != UINT32_MAX))) { - stats.to_master_dev++; + + match_result = BRIDGE_MATCH_TO_MASTER; + stats.match_result[match_result]++; mrb_meta->port_egress = egress_port; goto node_enqueue; } /* Drop pkts */ - stats.drop_for_miss++; + match_result = BRIDGE_MATCH_MISS; + stats.match_result[match_result]++; next_node_index = BRIDGE_NEXT_DROP; goto node_enqueue; } /* Deal broadcast pkt */ - stats.broadcast++; + match_result = BRIDGE_MATCH_BROADCAST; + stats.match_result[match_result]++; uint8_t original_pkt = 1; for (int index = 0; index < bridge->nr_devices; index++) { @@ -384,7 +380,7 @@ static __rte_always_inline uint16_t bridge_node_process(struct rte_graph * graph /* Check if tracing is enabled for the current Mbuf */ if (unlikely(dp_trace_record_can_emit(mbuf))) { - gen_store_trace_info_original(node, mbuf, next_node_index, &stats, &stats_for_trace); + gen_store_trace_info_original(node, mbuf, next_node_index, &stats, match_result); } /* Batch processing */ @@ -409,11 +405,15 @@ static __rte_always_inline uint16_t bridge_node_process(struct rte_graph * graph /* Update graph stats */ struct bridge_stats * graph_stats = &stats_per_graph[graph_id]; - graph_stats->deal_pkts += cnt; - graph_stats->to_master_dev += stats.to_master_dev; - graph_stats->drop_for_miss += stats.drop_for_miss; - graph_stats->broadcast += stats.broadcast; + graph_stats->total_pkts += cnt; + graph_stats->pkts_per_batch = cnt; graph_stats->pkt_clone_failed += stats.pkt_clone_failed; + + for (int i = 0; i < RTE_DIM(stats.match_result); i++) + { + graph_stats->match_result[i] += stats.match_result[i]; + } + return 0; } @@ -434,27 +434,54 @@ RTE_NODE_REGISTER(bridge_node_base); /* Bridge Stat */ cJSON * bridge_node_monit_loop(struct sc_main * sc) { - unsigned int nr_graph_total = sc->nr_io_thread; + unsigned int nr_graphs = sc->nr_io_thread; cJSON * json_root = cJSON_CreateObject(); - for (uint32_t graph_id = 0; graph_id < nr_graph_total; graph_id++) + uint64_t total_pkts[nr_graphs]; + uint64_t pkts_per_batch[nr_graphs]; + uint64_t total_pkt_clone_failed[nr_graphs]; + uint64_t total_match_result[nr_graphs][BRIDGE_MATCH_MAX]; + + for (uint32_t graph_id = 0; graph_id < nr_graphs; graph_id++) { struct bridge_stats * stats = &stats_per_graph[graph_id]; - if (stats->deal_pkts == 0) + if (stats->total_pkts == 0) + { + total_pkts[graph_id] = 0; + pkts_per_batch[graph_id] = 0; + total_pkt_clone_failed[graph_id] = 0; + + memset(total_match_result[graph_id], 0, sizeof(total_match_result[graph_id])); continue; + } + + total_pkts[graph_id] = stats->total_pkts; + pkts_per_batch[graph_id] = stats->pkts_per_batch; + total_pkt_clone_failed[graph_id] = stats->pkt_clone_failed; + + for (int i = 0; i < BRIDGE_MATCH_MAX; i++) + { + total_match_result[graph_id][i] = stats->match_result[i]; + } + } + + cJSON * json_total_pkts = create_uint64_array(total_pkts, nr_graphs); + cJSON_AddItemToObject(json_root, "bridge, total pkts", json_total_pkts); + + cJSON * json_pkts_per_batch = create_uint64_array(pkts_per_batch, nr_graphs); + cJSON_AddItemToObject(json_root, "bridge, pkts per batch", json_pkts_per_batch); - cJSON * graph_obj = cJSON_CreateObject(); - cJSON_AddNumberToObject(graph_obj, "deal_pkts", stats->deal_pkts); - cJSON_AddNumberToObject(graph_obj, "to_master_dev", stats->to_master_dev); - cJSON_AddNumberToObject(graph_obj, "drop_for_miss", stats->drop_for_miss); - cJSON_AddNumberToObject(graph_obj, "broadcast", stats->broadcast); - cJSON_AddNumberToObject(graph_obj, "pkt_clone_failed", stats->pkt_clone_failed); + cJSON * json_clone_failed = create_uint64_array(total_pkt_clone_failed, nr_graphs); + cJSON_AddItemToObject(json_root, "bridge, clone failed", json_clone_failed); + + for (int i = 0; i < BRIDGE_MATCH_MAX - 1; i++) + { + char str_title[MR_STRING_MAX]; + snprintf(str_title, sizeof(str_title), "bridge, %s", bridge_match_result_str[i]); - char graph_index[MR_STRING_MAX]; - snprintf(graph_index, sizeof(graph_index), "graph-%u", graph_id); - cJSON_AddItemToObject(json_root, graph_index, graph_obj); + cJSON * json_pro = create_uint64_array(total_match_result[i], nr_graphs); + cJSON_AddItemToObject(json_root, str_title, json_pro); } - cJSON_AddNumberToObject(json_root, "total_graph_num", nr_graph_total); return json_root; } |
