From patchwork Thu Mar 19 10:14:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 46028 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 20F602153C for ; Thu, 19 Mar 2015 10:15:22 +0000 (UTC) Received: by labgq15 with SMTP id gq15sf11740392lab.0 for ; Thu, 19 Mar 2015 03:15:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=de4nk0ZtnhW9UfmzKCF1PVisEPDCoq9i3j7AFZ3KPr8=; b=IDIcYgJ7XwJXzScEnq/v4WD5wD99VNxTI/JwIy2paMmJip0TgNkiZGRiy7BXlu/DYB 7oCavBQJWJp2MvLOS/ACx6b3TnQ2gmuseNLdVTty+O1lf/CNPOBJCrp3nYZ62CxpFPPe 70b9cac2l+3/JwJDvPlsBNmvSYvu5XuOdQXDvH5S9qlmSf5Vq6TVsad6MB4qXXiGh80i KCHAgNaLZrJkECXeN5Q2b0nWE9uO1FSVo+9gOrp0itHMrsh36P6pYC25RZLEYvi5vg+N 1MQ0IPb3oj7RwelF694VeyUtVSwNgCtkfFIprDgTZIwcN0nJJDq27jgfMTzzXdtdKnLA rl1Q== X-Gm-Message-State: ALoCoQkKNaD/+X4gKVkShA1XDnHVZZ2lG708jKbbHy/mC/wTdPJnKt7FP8x/G5p1ztZgH/2dSLmN X-Received: by 10.152.6.232 with SMTP id e8mr11894498laa.2.1426760120292; Thu, 19 Mar 2015 03:15:20 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.132 with SMTP id i4ls254115lab.25.gmail; Thu, 19 Mar 2015 03:15:19 -0700 (PDT) X-Received: by 10.152.121.33 with SMTP id lh1mr68292144lab.86.1426760119728; Thu, 19 Mar 2015 03:15:19 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id s10si676812lae.17.2015.03.19.03.15.19 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 03:15:19 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbcgn8 with SMTP id gn8so49010798lbc.2 for ; Thu, 19 Mar 2015 03:15:19 -0700 (PDT) X-Received: by 10.112.162.232 with SMTP id yd8mr1680057lbb.41.1426760119620; Thu, 19 Mar 2015 03:15:19 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp281757lbj; Thu, 19 Mar 2015 03:15:18 -0700 (PDT) X-Received: by 10.55.17.76 with SMTP id b73mr142922242qkh.71.1426760117900; Thu, 19 Mar 2015 03:15:17 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id e140si733071qhc.76.2015.03.19.03.15.16 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 03:15:17 -0700 (PDT) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YYXTt-000803-E9; Thu, 19 Mar 2015 10:15:13 +0000 Received: from mail-la0-f46.google.com ([209.85.215.46]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YYXTn-0007zj-EH for lng-odp@lists.linaro.org; Thu, 19 Mar 2015 10:15:07 +0000 Received: by lamx15 with SMTP id x15so58116609lam.3 for ; Thu, 19 Mar 2015 03:15:01 -0700 (PDT) X-Received: by 10.112.144.41 with SMTP id sj9mr68091395lbb.3.1426760101036; Thu, 19 Mar 2015 03:15:01 -0700 (PDT) Received: from localhost.localdomain (ppp91-76-169-66.pppoe.mtu-net.ru. [91.76.169.66]) by mx.google.com with ESMTPSA id g6sm193937lab.2.2015.03.19.03.14.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 03:15:00 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 19 Mar 2015 13:14:49 +0300 Message-Id: <1426760089-14503-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv4] example: l2fwd print packets per second X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Current print in l2fwd is not useful with slow links and also it's hard to say how fast does it work. Print pps and packets drops. Signed-off-by: Maxim Uvarov --- v4: fixed calculation. example/l2fwd/odp_l2fwd.c | 112 +++++++++++++++++++++++++++++++++------------- 1 file changed, 82 insertions(+), 30 deletions(-) diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index d062a72..1691439 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -73,13 +73,24 @@ typedef struct { int if_count; /**< Number of interfaces to be used */ char **if_names; /**< Array of pointers to interface names */ int mode; /**< Packet IO mode */ + int time; /**< Time in seconds to run. */ + int accuracy; /**< Number of seconds to get and print statistics */ } appl_args_t; +static int exit_threads; + +/* speed and stats */ +typedef struct { + uint64_t packets; + uint64_t drops; +} stats_t; + /** * Thread specific arguments */ typedef struct { int src_idx; /**< Source interface identifier */ + stats_t **stats; /**< Per thread packet stats */ } thread_args_t; /** @@ -115,24 +126,24 @@ static void *pktio_queue_thread(void *arg) odp_queue_t outq_def; odp_packet_t pkt; odp_event_t ev; - unsigned long pkt_cnt = 0; - unsigned long err_cnt = 0; + thread_args_t *thr_args = arg; - (void)arg; + stats_t *stats = calloc(1, sizeof(stats_t)); + *thr_args->stats = stats; thr = odp_thread_id(); printf("[%02i] QUEUE mode\n", thr); /* Loop packets */ - for (;;) { + while (!exit_threads) { /* Use schedule to get buf from any input queue */ ev = odp_schedule(NULL, ODP_SCHED_WAIT); pkt = odp_packet_from_event(ev); /* Drop packets with errors */ if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) { - EXAMPLE_ERR("Drop frame - err_cnt:%lu\n", ++err_cnt); + stats->drops += 1; continue; } @@ -141,14 +152,10 @@ static void *pktio_queue_thread(void *arg) /* Enqueue the packet for output */ odp_queue_enq(outq_def, ev); - /* Print packet counts every once in a while */ - if (odp_unlikely(pkt_cnt++ % 100000 == 0)) { - printf(" [%02i] pkt_cnt:%lu\n", thr, pkt_cnt); - fflush(NULL); - } + stats->packets += 1; } -/* unreachable */ + free(stats); return NULL; } @@ -186,15 +193,15 @@ static void *pktio_ifburst_thread(void *arg) thread_args_t *thr_args; int pkts, pkts_ok; odp_packet_t pkt_tbl[MAX_PKT_BURST]; - unsigned long pkt_cnt = 0; - unsigned long err_cnt = 0; - unsigned long tmp = 0; int src_idx, dst_idx; odp_pktio_t pktio_src, pktio_dst; thr = odp_thread_id(); thr_args = arg; + stats_t *stats = calloc(1, sizeof(stats_t)); + *thr_args->stats = stats; + src_idx = thr_args->src_idx; dst_idx = (src_idx % 2 == 0) ? src_idx+1 : src_idx-1; pktio_src = gbl_args->pktios[src_idx]; @@ -208,7 +215,7 @@ static void *pktio_ifburst_thread(void *arg) odp_pktio_to_u64(pktio_src), odp_pktio_to_u64(pktio_dst)); /* Loop packets */ - for (;;) { + while (!exit_threads) { pkts = odp_pktio_recv(pktio_src, pkt_tbl, MAX_PKT_BURST); if (pkts <= 0) continue; @@ -218,26 +225,16 @@ static void *pktio_ifburst_thread(void *arg) if (pkts_ok > 0) odp_pktio_send(pktio_dst, pkt_tbl, pkts_ok); - if (odp_unlikely(pkts_ok != pkts)) { - err_cnt += pkts-pkts_ok; - EXAMPLE_ERR("Dropped frames:%u - err_cnt:%lu\n", - pkts-pkts_ok, err_cnt); - } + if (odp_unlikely(pkts_ok != pkts)) + stats->drops += pkts - pkts_ok; if (pkts_ok == 0) continue; - /* Print packet counts every once in a while */ - tmp += pkts_ok; - if (odp_unlikely(tmp >= 100000 || pkt_cnt == 0)) { - pkt_cnt += tmp; - tmp = 0; - printf(" [%02i] pkt_cnt:%lu\n", thr, pkt_cnt); - fflush(NULL); - } + stats->packets += pkts_ok; } -/* unreachable */ + free(stats); return NULL; } @@ -295,6 +292,40 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, return pktio; } +static void print_speed_stats(int num_workers, stats_t **thr_stats, + int duration, int timeout) +{ + uint64_t pkts, pkts_prev = 0, pps, drops, maximum_pps = 0; + int i, elapsed = 0; + int loop_forever = (duration == 0); + + do { + pkts = 0; + drops = 0; + + sleep(timeout); + + for (i = 0; i < num_workers; i++) { + pkts += thr_stats[i]->packets; + drops += thr_stats[i]->drops; + } + pps = (pkts - pkts_prev) / timeout; + if (pps > maximum_pps) + maximum_pps = pps; + printf("%" PRIu64 " pps, %" PRIu64 " max pps, ", pps, + maximum_pps); + + printf(" %" PRIu64 " total drops\n", drops); + + elapsed += timeout; + pkts_prev = pkts; + } while (loop_forever || (elapsed < duration)); + + printf("TEST RESULT: %" PRIu64 " maximum packets per second.\n", + maximum_pps); + return; +} + /** * ODP L2 forwarding main function */ @@ -391,6 +422,8 @@ int main(int argc, char *argv[]) memset(thread_tbl, 0, sizeof(thread_tbl)); + stats_t **stats = calloc(1, sizeof(stats_t) * num_workers); + /* Create worker threads */ cpu = odp_cpumask_first(&cpumask); for (i = 0; i < num_workers; ++i) { @@ -403,6 +436,7 @@ int main(int argc, char *argv[]) thr_run_func = pktio_queue_thread; gbl_args->thread[i].src_idx = i % gbl_args->appl.if_count; + gbl_args->thread[i].stats = &stats[i]; odp_cpumask_zero(&thd_mask); odp_cpumask_set(&thd_mask, cpu); @@ -412,6 +446,11 @@ int main(int argc, char *argv[]) cpu = odp_cpumask_next(&cpumask, cpu); } + print_speed_stats(num_workers, stats, gbl_args->appl.time, + gbl_args->appl.accuracy); + free(stats); + exit_threads = 1; + /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); @@ -467,16 +506,20 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) int i; static struct option longopts[] = { {"count", required_argument, NULL, 'c'}, + {"time", required_argument, NULL, 't'}, + {"accuracy", required_argument, NULL, 'a'}, {"interface", required_argument, NULL, 'i'}, /* return 'i' */ {"mode", required_argument, NULL, 'm'}, /* return 'm' */ {"help", no_argument, NULL, 'h'}, /* return 'h' */ {NULL, 0, NULL, 0} }; + appl_args->time = 0; /* loop forever if time to run is 0 */ + appl_args->accuracy = 10; /* get and print pps stats each X seconds */ appl_args->mode = -1; /* Invalid, must be changed by parsing */ while (1) { - opt = getopt_long(argc, argv, "+c:i:m:h", + opt = getopt_long(argc, argv, "+c:+t:+a:i:m:h", longopts, &long_index); if (opt == -1) @@ -486,6 +529,12 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) case 'c': appl_args->cpu_count = atoi(optarg); break; + case 't': + appl_args->time = atoi(optarg); + break; + case 'a': + appl_args->accuracy = atoi(optarg); + break; /* parse packet-io interface names */ case 'i': len = strlen(optarg); @@ -612,6 +661,9 @@ static void usage(char *progname) "\n" "Optional OPTIONS\n" " -c, --count CPU count.\n" + " -t, --time Time in seconds to run.\n" + " -a, --accuracy Time in seconds get print statistics\n" + " (default 10 seconds).\n" " -h, --help Display help and exit.\n\n" " environment variables: ODP_PKTIO_DISABLE_SOCKET_MMAP\n" " ODP_PKTIO_DISABLE_SOCKET_MMSG\n"