Optimize ethernet address filling by using word copy. Signed-off-by: Matias Elo <matias....@nokia.com> --- test/performance/odp_l2fwd.c | 57 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 12 deletions(-)
diff --git a/test/performance/odp_l2fwd.c b/test/performance/odp_l2fwd.c index fb5f656..4e371a1 100644 --- a/test/performance/odp_l2fwd.c +++ b/test/performance/odp_l2fwd.c @@ -92,6 +92,14 @@ typedef struct { } thread_args_t; /** + * Optimized type for storing ethernet addresses + */ +typedef union { + uint8_t u8[6]; + uint16_t u16[3]; +} eth_addr_t; + +/** * Grouping of all global data */ typedef struct { @@ -102,9 +110,9 @@ typedef struct { /** Table of pktio handles */ odp_pktio_t pktios[ODP_CONFIG_PKTIO_ENTRIES]; /** Table of port ethernet addresses */ - odph_ethaddr_t port_eth_addr[ODP_CONFIG_PKTIO_ENTRIES]; + eth_addr_t port_eth_addr[ODP_CONFIG_PKTIO_ENTRIES]; /** Table of dst ethernet addresses */ - odph_ethaddr_t dst_eth_addr[ODP_CONFIG_PKTIO_ENTRIES]; + eth_addr_t dst_eth_addr[ODP_CONFIG_PKTIO_ENTRIES]; /** Table of port default output queues */ odp_queue_t outq_def[ODP_CONFIG_PKTIO_ENTRIES]; /** Table of dst ports */ @@ -433,7 +441,7 @@ int main(int argc, char *argv[]) odp_shm_t shm; odp_cpumask_t cpumask; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; - odph_ethaddr_t new_addr; + eth_addr_t new_addr; odp_pktio_t pktio; odp_pool_param_t params; int ret; @@ -508,7 +516,7 @@ int main(int argc, char *argv[]) gbl_args->pktios[i] = pktio; /* Save interface ethernet address */ - if (odp_pktio_mac_addr(pktio, gbl_args->port_eth_addr[i].addr, + if (odp_pktio_mac_addr(pktio, gbl_args->port_eth_addr[i].u8, ODPH_ETHADDR_LEN) != ODPH_ETHADDR_LEN) { LOG_ERR("Error: interface ethernet address unknown\n"); exit(EXIT_FAILURE); @@ -521,9 +529,9 @@ int main(int argc, char *argv[]) /* Save destination eth address */ if (gbl_args->appl.dst_change) { /* 02:00:00:00:00:XX */ - memset(&new_addr, 0, sizeof(odph_ethaddr_t)); - new_addr.addr[0] = 0x02; - new_addr.addr[5] = i; + memset(&new_addr, 0, sizeof(eth_addr_t)); + new_addr.u8[0] = 0x02; + new_addr.u8[5] = i; gbl_args->dst_eth_addr[i] = new_addr; } @@ -615,6 +623,24 @@ static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len) } /** + * Word copy ethernet address + * + * @param to Destination memory address + * @param from Source memory address + */ +static void copy_eth_addr(uint16_t *to, uint16_t *from) +{ + uint16_t fw0, fw1, fw2; + + fw0 = from[0]; + fw1 = from[1]; + fw2 = from[2]; + to[0] = fw0; + to[1] = fw1; + to[2] = fw2; +} + +/** * Fill packets' eth addresses according to the destination port * * @param pkt_tbl Array of packets @@ -626,6 +652,8 @@ static void fill_eth_addrs(odp_packet_t pkt_tbl[], unsigned num, int dst_port) odp_packet_t pkt; odph_ethhdr_t *eth; unsigned i; + uint16_t *to; + uint16_t *from; if (!gbl_args->appl.dst_change && !gbl_args->appl.src_change) return; @@ -635,11 +663,16 @@ static void fill_eth_addrs(odp_packet_t pkt_tbl[], unsigned num, int dst_port) if (odp_packet_has_eth(pkt)) { eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL); - if (gbl_args->appl.src_change) - eth->src = gbl_args->port_eth_addr[dst_port]; - - if (gbl_args->appl.dst_change) - eth->dst = gbl_args->dst_eth_addr[dst_port]; + if (gbl_args->appl.src_change) { + from = gbl_args->port_eth_addr[dst_port].u16; + to = (uint16_t *)eth->src.addr; + copy_eth_addr(to, from); + } + if (gbl_args->appl.dst_change) { + from = gbl_args->dst_eth_addr[dst_port].u16; + to = (uint16_t *)eth->dst.addr; + copy_eth_addr(to, from); + } } } } -- 1.9.1 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp