diff options
| author | songyanchao <[email protected]> | 2024-04-07 02:09:21 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2024-04-15 06:10:29 +0000 |
| commit | 87aab32d4cee98e59b8a71b81b1959a9823e3d85 (patch) | |
| tree | 9342ce701310b28de531c15a9c08d2a1b21f434b | |
| parent | 9eb77ccde03572cf2e67900c4369446b5166fe0d (diff) | |
🎈 perf: Optimize ef_peer_lookup function for EtherFabric node.
Optimize ef_peer_lookup function for EtherFabric node.
| -rw-r--r-- | service/src/node_etherfabric.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/service/src/node_etherfabric.c b/service/src/node_etherfabric.c index 76e7043..c010e47 100644 --- a/service/src/node_etherfabric.c +++ b/service/src/node_etherfabric.c @@ -384,25 +384,38 @@ int ef_adapter_lookup(struct node_ef_main * ef_main, uint32_t dst_addr, uint16_t return RT_ERR; } -/* ef_peer lookup and add */ -int ef_peer_lookup_and_add(struct rte_hash * ef_peer_hash, struct ef_peer * ef_peers, struct rte_ether_addr * src_addr, - uint32_t ip_src, uint16_t * out_ef_peer_index) +int ef_peer_lookup(struct node_ef_main * ef_main, struct rte_ether_addr * mac_src, uint32_t ip_src) { - union ef_peer_key key = {}; - - key.ip_src = ip_src; - rte_ether_addr_copy(src_addr, &key.mac_src); + for (int i = 0; i < RTE_DIM(ef_main->ef_peers); i++) + { + struct ef_peer * ef_peer_item = &ef_main->ef_peers[i]; + if (ef_peer_item->ef_ip_addr == ip_src && rte_is_same_ether_addr(&ef_peer_item->ef_mac_addr, mac_src)) + { + return i; + } + } + return RT_ERR; +} +/* ef_peer lookup and add */ +int ef_peer_lookup_and_add(struct rte_hash * ef_peer_hash, struct ef_peer * ef_peers, struct rte_ether_addr * mac_src, + uint32_t ip_src) +{ /* Look up the hash table */ - int ret = rte_hash_lookup(ef_peer_hash, (const void *)&key); + // int ret = rte_hash_lookup(ef_peer_hash, (const void *)&key); + int ret = ef_peer_lookup(node_ef_main_get(), mac_src, ip_src); + if (likely(ret >= 0)) { - *out_ef_peer_index = ret; - return RT_SUCCESS; + return ret; } + union ef_peer_key key = {.ip_src = ip_src}; + rte_ether_addr_copy(mac_src, &key.mac_src); + /* Add the new ef_peer */ ret = rte_hash_add_key(ef_peer_hash, (void *)&key); + if (likely(ret >= 0)) { /* Set the ef_peer state */ @@ -423,8 +436,7 @@ int ef_peer_lookup_and_add(struct rte_hash * ef_peer_hash, struct ef_peer * ef_p MR_INFO("Ef Peer add, ip addr:%s, mac addr:%s", str_in_addr, str_mac_addr); } - *out_ef_peer_index = ret; - return RT_SUCCESS; + return ret; } return RT_ERR; @@ -540,10 +552,9 @@ static __rte_always_inline uint16_t ef_ingress_node_process(struct rte_graph * g } /* ef_peer lookup and add */ - uint16_t ef_peer_index = UINT16_MAX; - ret = ef_peer_lookup_and_add(ef_main->ef_peer_hash, ef_main->ef_peers, &outer_ether_hdr->src_addr, - outer_ipv4_hdr->src_addr, &ef_peer_index); - if (unlikely(ret == RT_ERR)) + int ef_peer_index = ef_peer_lookup_and_add(ef_main->ef_peer_hash, ef_main->ef_peers, &outer_ether_hdr->src_addr, + outer_ipv4_hdr->src_addr); + if (unlikely(ef_peer_index == RT_ERR)) { stats.drop_for_ef_peer_add_err++; next_node_index = EF_INGRESS_NEXT_PKT_DROP; |
