From patchwork Fri Mar 13 15:03:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 45786 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 55C64214CB for ; Fri, 13 Mar 2015 15:04:33 +0000 (UTC) Received: by lamq1 with SMTP id q1sf17156088lam.3 for ; Fri, 13 Mar 2015 08:04:32 -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:in-reply-to :references: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=KZUefqMOR8uohG8sX4KCLwi4i28QpVlv6+altxqbzNc=; b=hHhvqkRvhBS5Il9hseK96SavwPEDbSlzOQBLG+3xcjrmlUxUDMbo46NyQHNJjU7F/V wOR7MqPI6HyQbFI7cAw7YVvbLneETE/TDA+F2npYpo8pzwDnOLURB87ypeMMIbsj5XvT lklrsF0+tbHD7vDdkeOzbJUtjNJHR6Xgai7bqEAu8dXv7EiOiXrJ9sxLLMFtNMLkWo40 tsYCq3dOFg0hjWMOUSftfKorAj9NXLeMSBH/Kbi4vAn+PjAXpBZAa/LT8ahkz037//jZ ol8YzfyjB8Fcu67cQMt3se1OaEwOpM6NDRXkkCasn6niV4tEZReeNnx2OV8QOTOesAg7 FQtg== X-Gm-Message-State: ALoCoQk8AXssWSpbHLBFn63ggN3STzNP7CNV/JPXR31vRZKZqnwKcs3cYNLAjhSvqYgm6XiTeRo+ X-Received: by 10.112.202.227 with SMTP id kl3mr552626lbc.2.1426259072315; Fri, 13 Mar 2015 08:04:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.179.4 with SMTP id dc4ls425667lac.73.gmail; Fri, 13 Mar 2015 08:04:32 -0700 (PDT) X-Received: by 10.152.87.199 with SMTP id ba7mr37766784lab.75.1426259072133; Fri, 13 Mar 2015 08:04:32 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id s1si1558331lbf.154.2015.03.13.08.04.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Mar 2015 08:04:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbjb6 with SMTP id b6so23283904lbj.9 for ; Fri, 13 Mar 2015 08:04:32 -0700 (PDT) X-Received: by 10.112.204.197 with SMTP id la5mr43245915lbc.29.1426259072021; Fri, 13 Mar 2015 08:04:32 -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 h5csp973309lbj; Fri, 13 Mar 2015 08:04:31 -0700 (PDT) X-Received: by 10.55.55.78 with SMTP id e75mr50306640qka.77.1426259070517; Fri, 13 Mar 2015 08:04:30 -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 191si2114700qhg.118.2015.03.13.08.04.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 13 Mar 2015 08:04:30 -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 1YWR8V-0001Ov-6H; Fri, 13 Mar 2015 15:04:27 +0000 Received: from mail-la0-f47.google.com ([209.85.215.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YWR87-0001IL-FF for lng-odp@lists.linaro.org; Fri, 13 Mar 2015 15:04:03 +0000 Received: by labgm9 with SMTP id gm9so23210337lab.11 for ; Fri, 13 Mar 2015 08:03:57 -0700 (PDT) X-Received: by 10.112.64.2 with SMTP id k2mr44478401lbs.54.1426259037828; Fri, 13 Mar 2015 08:03:57 -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 i9sm450231lbs.26.2015.03.13.08.03.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Mar 2015 08:03:56 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 13 Mar 2015 18:03:46 +0300 Message-Id: <1426259027-14083-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426259027-14083-1-git-send-email-maxim.uvarov@linaro.org> References: <1426259027-14083-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 1/2] 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.178 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 --- example/l2fwd/odp_l2fwd.c | 98 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 27 deletions(-) diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index d062a72..0299278 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -73,6 +73,8 @@ 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; /** @@ -104,6 +106,15 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args); static void print_info(char *progname, appl_args_t *appl_args); static void usage(char *progname); +/* speed and stats */ +typedef struct { + uint64_t packets[MAX_WORKERS]; + uint64_t drops[MAX_WORKERS]; +} stats_t; + +static stats_t stats; +static int exit_threads; + /** * Packet IO worker thread using ODP queues * @@ -115,8 +126,6 @@ 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; (void)arg; @@ -125,14 +134,14 @@ static void *pktio_queue_thread(void *arg) 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[thr] += 1; continue; } @@ -141,11 +150,7 @@ 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[thr] += 1; } /* unreachable */ @@ -186,9 +191,6 @@ 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; @@ -208,7 +210,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,23 +220,13 @@ 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[thr] += 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[thr] += pkts_ok; } /* unreachable */ @@ -295,6 +287,41 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, return pktio; } +static void print_speed_stats(int num_workers, int duration, int timeout) +{ + stats_t old_stats, new_stats; + uint64_t pps, maximum_pps = 0; + uint64_t errors; + int i; + int elapsed = 0; + + do { + memcpy(&old_stats, &stats, sizeof(stats_t)); + sleep(timeout); + memcpy(&new_stats, &stats, sizeof(stats_t)); + + for (i = 0, pps = 0; i < num_workers; i++) + pps += new_stats.packets[i] - old_stats.packets[i]; + pps = pps / timeout; + if (pps > maximum_pps) + maximum_pps = pps; + + printf("%" PRIu64 " pps, %" PRIu64 " max pps, ", pps, + maximum_pps); + + for (i = 0, errors = 0; i < num_workers; i++) + errors += new_stats.drops[i] - old_stats.drops[i]; + errors = errors / timeout; + + printf(" %" PRIu64 " drops\n", errors); + elapsed += timeout; + } while (elapsed < duration); + + printf("TEST RESULT: %" PRIu64 " maximum packets per second.\n", + maximum_pps); + return; +} + /** * ODP L2 forwarding main function */ @@ -412,6 +439,11 @@ int main(int argc, char *argv[]) cpu = odp_cpumask_next(&cpumask, cpu); } + print_speed_stats(num_workers, gbl_args->appl.time, + gbl_args->appl.accuracy); + + exit_threads = 1; + /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); @@ -467,16 +499,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; + 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 +522,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 +654,8 @@ 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" " -h, --help Display help and exit.\n\n" " environment variables: ODP_PKTIO_DISABLE_SOCKET_MMAP\n" " ODP_PKTIO_DISABLE_SOCKET_MMSG\n"