From patchwork Fri Mar 6 13:45:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 45482 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9EDD8214A0 for ; Fri, 6 Mar 2015 13:46:02 +0000 (UTC) Received: by lbvn10 with SMTP id n10sf3133199lbv.1 for ; Fri, 06 Mar 2015 05:46:01 -0800 (PST) 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=7Vbq7RYRWTGdzvmQdSRerJRG0/Iudm6bNrGn6J4vfnA=; b=i/OIr7yKgyqYBtTKN/4Sp13vx9Se5twF50Ve9l4t0tcdBLDF+ldeKv68s/9MjZIK7S /qRVV2S/sN+rB36IxpmzmzuxZkVrEYyhXEM6FCs+NKiMvTtewGxOBnndwH5gc2eyplzH h8WyutwZ6lpfnLL0FOuspRfcJlzh9cRmEwqpBdrs2Ze6MPFo4ESizcUIZMAbqqHCp7nK XeSeVOqB/Klsdd/H1xu+Rm2nTbQTrES2xKbzOu8IqlsNx+yCi/Q4xKWi8OkFu+MWVqrz DfDNs+mv5O+xRcyRgxK9/vjRNVTPYv8CxCA6MLtgAJ+e97RGFwAsIPNIehpuyK+J/5uL Nv/Q== X-Gm-Message-State: ALoCoQl3ibbQKR/ogw1lMfdcsNk2Z8SJjJmeHc2+IuZ4uyVwxlejWZah82mwjvKcpj4S+wa+137E X-Received: by 10.180.91.76 with SMTP id cc12mr2785673wib.7.1425649561554; Fri, 06 Mar 2015 05:46:01 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.140 with SMTP id ay12ls85773lab.2.gmail; Fri, 06 Mar 2015 05:46:01 -0800 (PST) X-Received: by 10.112.126.130 with SMTP id my2mr13072769lbb.55.1425649561171; Fri, 06 Mar 2015 05:46:01 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id le5si7117560lac.120.2015.03.06.05.46.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 05:46:01 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbiz12 with SMTP id z12so34787710lbi.5 for ; Fri, 06 Mar 2015 05:46:01 -0800 (PST) X-Received: by 10.112.185.66 with SMTP id fa2mr12555675lbc.117.1425649561002; Fri, 06 Mar 2015 05:46:01 -0800 (PST) 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 h5csp1142911lbj; Fri, 6 Mar 2015 05:46:00 -0800 (PST) X-Received: by 10.140.150.21 with SMTP id 21mr19735955qhw.69.1425649559715; Fri, 06 Mar 2015 05:45:59 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id s30si9204455qge.45.2015.03.06.05.45.58 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 06 Mar 2015 05:45:59 -0800 (PST) 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 1YTsZg-0007dJ-L9; Fri, 06 Mar 2015 13:45:56 +0000 Received: from mail-lb0-f177.google.com ([209.85.217.177]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YTsZa-0007dD-On for lng-odp@lists.linaro.org; Fri, 06 Mar 2015 13:45:50 +0000 Received: by lbvn10 with SMTP id n10so3714708lbv.1 for ; Fri, 06 Mar 2015 05:45:44 -0800 (PST) X-Received: by 10.152.10.179 with SMTP id j19mr13319267lab.102.1425649544204; Fri, 06 Mar 2015 05:45:44 -0800 (PST) Received: from maxim-Aspire-VN7-791.Dlink (broadband-46-188-125-102.2com.net. [46.188.125.102]) by mx.google.com with ESMTPSA id lf3sm1829670lbc.2.2015.03.06.05.45.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 05:45:43 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 6 Mar 2015 16:45:36 +0300 Message-Id: <1425649536-6580-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCH] 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.181 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 | 67 ++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/example/l2fwd/odp_l2fwd.c b/example/l2fwd/odp_l2fwd.c index d062a72..71c2fc5 100644 --- a/example/l2fwd/odp_l2fwd.c +++ b/example/l2fwd/odp_l2fwd.c @@ -104,6 +104,14 @@ 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; + /** * Packet IO worker thread using ODP queues * @@ -115,8 +123,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; @@ -132,7 +138,7 @@ static void *pktio_queue_thread(void *arg) /* 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 +147,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 +188,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; @@ -218,23 +217,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 +284,34 @@ 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 old_stats; + stats_t new_stats; + uint64_t old; + uint64_t new; + int i; + int timeout = 10; + + while (1) { + memcpy(&old_stats, &stats, sizeof(stats_t)); + sleep(timeout); + memcpy(&new_stats, &stats, sizeof(stats_t)); + + for (i = old = new = 0; i < num_workers; i++) { + old += old_stats.packets[i]; + new += new_stats.packets[i]; + } + printf(" %" PRIu64 " pps, ", (new - old) / timeout); + + for (i = old = new = 0; i < num_workers; i++) { + old += old_stats.drops[i]; + new += new_stats.drops[i]; + } + printf(" %" PRIu64 " drops\n", (new - old) / timeout); + } +} + /** * ODP L2 forwarding main function */ @@ -412,6 +429,8 @@ int main(int argc, char *argv[]) cpu = odp_cpumask_next(&cpumask, cpu); } + print_speed_stats(num_workers); + /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers);