On 10/21/2015 14:12, Matias Elo wrote:
Optimize ethernet address filling by using word copy.
Signed-off-by: Matias Elo <matias....@nokia.com>
---
test/performance/odp_l2fwd.c | 50 +++++++++++++++++++++++++++++++++-----------
1 file changed, 38 insertions(+), 12 deletions(-)
diff --git a/test/performance/odp_l2fwd.c b/test/performance/odp_l2fwd.c
index 5332b9a..969604f 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 */
@@ -435,7 +443,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;
@@ -510,7 +518,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);
@@ -523,9 +531,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;
}
@@ -628,6 +636,9 @@ 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 *dw;
+ uint16_t *sw;
+ uint16_t sw0, sw1, sw2;
if (!gbl_args->appl.dst_change && !gbl_args->appl.src_change)
return;
@@ -637,11 +648,26 @@ 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) {
+ sw = gbl_args->port_eth_addr[dst_port].u16;
+ dw = (uint16_t *)eth->src.addr;
+ sw0 = sw[0];
+ sw1 = sw[1];
+ sw2 = sw[2];
+ dw[0] = sw0;
+ dw[1] = sw1;
+ dw[2] = sw2;
+ }
+ if (gbl_args->appl.dst_change) {
+ sw = gbl_args->dst_eth_addr[dst_port].u16;
+ dw = (uint16_t *)eth->dst.addr;
+ sw0 = sw[0];
+ sw1 = sw[1];
+ sw2 = sw[2];
+ dw[0] = sw0;
+ dw[1] = sw1;
+ dw[2] = sw2;
that is better to put to some helper, to not duplicate code.
btw, did you test such copy on le and be?
Maxim.
+ }
}
}
}
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp