From: Petri Savolainen <petri.savolai...@linaro.org> Added option to enable checksum insertion at packet output. This can be used to test checksum offload in various packet IO combinations.
Signed-off-by: Petri Savolainen <petri.savolai...@linaro.org> --- /** Email created from pull request 313 (psavol:next-pktout-config) ** https://github.com/Linaro/odp/pull/313 ** Patch: https://github.com/Linaro/odp/pull/313.patch ** Base sha: 4cb02e1caccb9179575e95448fd46979e17d0905 ** Merge commit sha: 5d0d0efcb77baf5b9db803a8a8b89450e27aff38 **/ test/performance/odp_l2fwd.c | 104 +++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/test/performance/odp_l2fwd.c b/test/performance/odp_l2fwd.c index 42d8f49a2..874e6cf67 100644 --- a/test/performance/odp_l2fwd.c +++ b/test/performance/odp_l2fwd.c @@ -92,6 +92,7 @@ static inline int sched_mode(pktin_mode_t in_mode) * Parsed command line application arguments */ typedef struct { + int extra_check; /**< Some extra checks have been enabled */ int cpu_count; int if_count; /**< Number of interfaces to be used */ int addr_count; /**< Number of dst addresses to be used */ @@ -106,6 +107,7 @@ typedef struct { int dst_change; /**< Change destination eth addresses */ int src_change; /**< Change source eth addresses */ int error_check; /**< Check packet errors */ + int chksum; /**< Checksum offload */ int sched_mode; /**< Scheduler mode */ int num_groups; /**< Number of scheduling groups */ } appl_args_t; @@ -292,6 +294,18 @@ static inline int event_queue_send(odp_queue_t queue, odp_packet_t *pkt_tbl, return sent; } +static inline void chksum_insert(odp_packet_t *pkt_tbl, int pkts) +{ + odp_packet_t pkt; + int i; + + for (i = 0; i < pkts; i++) { + pkt = pkt_tbl[i]; + odp_packet_l3_chksum_insert(pkt, 1); + odp_packet_l4_chksum_insert(pkt, 1); + } +} + /** * Packet IO worker thread using scheduled queues * @@ -365,18 +379,23 @@ static int run_worker_sched_mode(void *arg) for (i = 0; i < pkts; i++) pkt_tbl[i] = odp_packet_from_event(ev_tbl[i]); - if (gbl_args->appl.error_check) { - int rx_drops; + if (odp_unlikely(gbl_args->appl.extra_check)) { + if (gbl_args->appl.chksum) + chksum_insert(pkt_tbl, pkts); - /* Drop packets with errors */ - rx_drops = drop_err_pkts(pkt_tbl, pkts); + if (gbl_args->appl.error_check) { + int rx_drops; - if (odp_unlikely(rx_drops)) { - stats->s.rx_drops += rx_drops; - if (pkts == rx_drops) - continue; + /* Drop packets with errors */ + rx_drops = drop_err_pkts(pkt_tbl, pkts); - pkts -= rx_drops; + if (odp_unlikely(rx_drops)) { + stats->s.rx_drops += rx_drops; + if (pkts == rx_drops) + continue; + + pkts -= rx_drops; + } } } @@ -486,18 +505,23 @@ static int run_worker_plain_queue_mode(void *arg) for (i = 0; i < pkts; i++) pkt_tbl[i] = odp_packet_from_event(event[i]); - if (gbl_args->appl.error_check) { - int rx_drops; + if (odp_unlikely(gbl_args->appl.extra_check)) { + if (gbl_args->appl.chksum) + chksum_insert(pkt_tbl, pkts); - /* Drop packets with errors */ - rx_drops = drop_err_pkts(pkt_tbl, pkts); + if (gbl_args->appl.error_check) { + int rx_drops; - if (odp_unlikely(rx_drops)) { - stats->s.rx_drops += rx_drops; - if (pkts == rx_drops) - continue; + /* Drop packets with errors */ + rx_drops = drop_err_pkts(pkt_tbl, pkts); - pkts -= rx_drops; + if (odp_unlikely(rx_drops)) { + stats->s.rx_drops += rx_drops; + if (pkts == rx_drops) + continue; + + pkts -= rx_drops; + } } } @@ -604,18 +628,23 @@ static int run_worker_direct_mode(void *arg) if (odp_unlikely(pkts <= 0)) continue; - if (gbl_args->appl.error_check) { - int rx_drops; + if (odp_unlikely(gbl_args->appl.extra_check)) { + if (gbl_args->appl.chksum) + chksum_insert(pkt_tbl, pkts); + + if (gbl_args->appl.error_check) { + int rx_drops; - /* Drop packets with errors */ - rx_drops = drop_err_pkts(pkt_tbl, pkts); + /* Drop packets with errors */ + rx_drops = drop_err_pkts(pkt_tbl, pkts); - if (odp_unlikely(rx_drops)) { - stats->s.rx_drops += rx_drops; - if (pkts == rx_drops) - continue; + if (odp_unlikely(rx_drops)) { + stats->s.rx_drops += rx_drops; + if (pkts == rx_drops) + continue; - pkts -= rx_drops; + pkts -= rx_drops; + } } } @@ -703,9 +732,17 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, } odp_pktio_config_init(&config); - config.parser.layer = gbl_args->appl.error_check ? + config.parser.layer = gbl_args->appl.extra_check ? ODP_PKTIO_PARSER_LAYER_ALL : ODP_PKTIO_PARSER_LAYER_NONE; + + if (gbl_args->appl.chksum) { + printf("Checksum offload enabled\n"); + config.pktout.bit.ipv4_chksum_ena = 1; + config.pktout.bit.udp_chksum_ena = 1; + config.pktout.bit.tcp_chksum_ena = 1; + } + odp_pktio_config(pktio, &config); odp_pktin_queue_param_init(&pktin_param); @@ -1128,6 +1165,8 @@ static void usage(char *progname) " Requires also the -d flag to be set\n" " -e, --error_check <arg> 0: Don't check packet errors (default)\n" " 1: Check packet errors\n" + " -k, --chksum <arg> 0: Don't use checksum offload (default)\n" + " 1: Use checksum offload\n" " -g, --groups <num> Number of groups to use: 0 ... num\n" " 0: SCHED_GROUP_ALL (default)\n" " num: must not exceed number of interfaces or workers\n" @@ -1162,12 +1201,13 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) {"dst_change", required_argument, NULL, 'd'}, {"src_change", required_argument, NULL, 's'}, {"error_check", required_argument, NULL, 'e'}, + {"chksum", required_argument, NULL, 'k'}, {"groups", required_argument, NULL, 'g'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; - static const char *shortopts = "+c:+t:+a:i:m:o:r:d:s:e:g:h"; + static const char *shortopts = "+c:+t:+a:i:m:o:r:d:s:e:k:g:h"; /* let helper collect its own arguments (e.g. --odph_proc) */ odph_parse_options(argc, argv, shortopts, longopts); @@ -1178,6 +1218,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) appl_args->src_change = 1; /* change eth src address by default */ appl_args->num_groups = 0; /* use default group */ appl_args->error_check = 0; /* don't check packet errors by default */ + appl_args->chksum = 0; /* don't use checksum offload by default */ opterr = 0; /* do not issue errors on helper options */ @@ -1302,6 +1343,9 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) case 'e': appl_args->error_check = atoi(optarg); break; + case 'k': + appl_args->chksum = atoi(optarg); + break; case 'g': appl_args->num_groups = atoi(optarg); break; @@ -1326,6 +1370,8 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) exit(EXIT_FAILURE); } + appl_args->extra_check = appl_args->error_check || appl_args->chksum; + optind = 1; /* reset 'extern optind' from the getopt lib */ }