From patchwork Wed Nov 18 09:34:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 56922 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2455841lbb; Wed, 18 Nov 2015 01:36:28 -0800 (PST) X-Received: by 10.55.74.19 with SMTP id x19mr440809qka.28.1447839388653; Wed, 18 Nov 2015 01:36:28 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y128si1579834qka.62.2015.11.18.01.36.28; Wed, 18 Nov 2015 01:36:28 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 145B561DAF; Wed, 18 Nov 2015 09:36:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9CC6461E57; Wed, 18 Nov 2015 09:34:46 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5CF4E61D85; Wed, 18 Nov 2015 09:34:36 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id A235661D83 for ; Wed, 18 Nov 2015 09:34:34 +0000 (UTC) Received: by lfaz4 with SMTP id z4so22512711lfa.0 for ; Wed, 18 Nov 2015 01:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9XhSX5jUy6ytfXZu/KPezyiYNnKnaHI4woyCm8wCACo=; b=twkkmJFkUZjDWNjS62tV27tmJOnVPkDxCycQKBIBkY0TPnMIr5DuoPgGLNslx0QzLO zRy20mcSXhmdD8A3lei8oWC8wTBrlkGgHLztnSMjdZX0z8iWxmwiQOVkbhTwGf5FJEY9 5uwAMWzdbSQnZJMtqKLWjGvrWDB38hWLQXziYFn85auEXRLrKAPkViLO++Oog1teUplJ y+3Wqltc6L0UNARd6F49O7BDDrV+loYU+xBUvtz8ZKR63kB1clD5H1BB7Kl77VhLZ8Pv M8XBhkBxRDZhkjb0Z3L8SMH8aljOZ1Axien7MmFq0gssMhoCaUYTuLy0GJArfJ5ohCnf oFMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9XhSX5jUy6ytfXZu/KPezyiYNnKnaHI4woyCm8wCACo=; b=Bk7ErIXr+ISxrmn3tpGEfx9ppnRi1JXDBp9rISrqyG1oRdZmta9rrVdLachsnBMilh DIHxxj68rFsyesE6hWYy65LdQzQA1uLZb8jtLwFvYpOrkCniawxSfg5Lw8dJ1o8fPYAw TTQ4uvZ60Ks0N4z2fksbdxvFpDPfnQRyb6ot+0oFpr7lsiOPJQmBXY2Xq7xl+Z8TOn9l FIgEs9z1X70RYlxS4T/HpMkl0iS+RvXk+J0YluCh96mOmQ0vA3iqV7scXdUePV57VUZD dE3F+Ahw+AZpXjVYztHM9FKmV0kQGApfFGl+VDH/HvXljqm4LlhMG70j5Bdo+HlsRaqO L/cQ== X-Gm-Message-State: ALoCoQls0sveMVQ/pKI6mVsD3rVXx8CN4m/58BheIHb45/dstPMZ8POxWPjepHLOtWPshg74nuSE X-Received: by 10.25.155.134 with SMTP id d128mr257716lfe.14.1447839273627; Wed, 18 Nov 2015 01:34:33 -0800 (PST) Received: from localhost.localdomain (ppp91-76-161-180.pppoe.mtu-net.ru. [91.76.161.180]) by smtp.gmail.com with ESMTPSA id o199sm297894lfa.12.2015.11.18.01.34.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Nov 2015 01:34:33 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 18 Nov 2015 12:34:25 +0300 Message-Id: <1447839268-20423-3-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447839268-20423-1-git-send-email-maxim.uvarov@linaro.org> References: <1447839268-20423-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 2/5] linux-generic: pktio loop: implement statistics counters X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Signed-off-by: Maxim Uvarov --- platform/linux-generic/pktio/loop.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index ce19add..ec65fd4 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -23,6 +23,8 @@ /* MAC address for the "loop" interface */ static const char pktio_loop_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0x01}; +static int loopback_stats_reset(pktio_entry_t *pktio_entry); + static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool ODP_UNUSED) { @@ -39,6 +41,8 @@ static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, if (pktio_entry->s.pkt_loop.loopq == ODP_QUEUE_INVALID) return -1; + loopback_stats_reset(pktio_entry); + return 0; } @@ -63,8 +67,11 @@ static int loopback_recv(pktio_entry_t *pktio_entry, odp_packet_t pkts[], pkt_hdr = odp_packet_hdr(pkts[i]); packet_parse_reset(pkts[i]); packet_parse_l2(pkt_hdr); + pktio_entry->s.stats.in_octets += odp_packet_len(pkts[i]); } + pktio_entry->s.stats.in_ucast_pkts += nbr; + return nbr; } @@ -74,12 +81,22 @@ static int loopback_send(pktio_entry_t *pktio_entry, odp_packet_t pkt_tbl[], odp_buffer_hdr_t *hdr_tbl[QUEUE_MULTI_MAX]; queue_entry_t *qentry; unsigned i; + int ret; + uint32_t bytes = 0; - for (i = 0; i < len; ++i) + for (i = 0; i < len; ++i) { hdr_tbl[i] = odp_buf_to_hdr(_odp_packet_to_buffer(pkt_tbl[i])); + bytes += odp_packet_len(pkt_tbl[i]); + } qentry = queue_to_qentry(pktio_entry->s.pkt_loop.loopq); - return queue_enq_multi(qentry, hdr_tbl, len, 0); + ret = queue_enq_multi(qentry, hdr_tbl, len, 0); + if (ret > 0) { + pktio_entry->s.stats.out_ucast_pkts += ret; + pktio_entry->s.stats.out_octets += bytes; + } + + return ret; } static int loopback_mtu_get(pktio_entry_t *pktio_entry ODP_UNUSED) @@ -107,6 +124,19 @@ static int loopback_promisc_mode_get(pktio_entry_t *pktio_entry) return pktio_entry->s.pkt_loop.promisc ? 1 : 0; } +static int loopback_stats(pktio_entry_t *pktio_entry, + odp_pktio_stats_t *stats) +{ + memcpy(stats, &pktio_entry->s.stats, sizeof(odp_pktio_stats_t)); + return 0; +} + +static int loopback_stats_reset(pktio_entry_t *pktio_entry ODP_UNUSED) +{ + memset(&pktio_entry->s.stats, 0, sizeof(odp_pktio_stats_t)); + return 0; +} + const pktio_if_ops_t loopback_pktio_ops = { .init = NULL, .term = NULL, @@ -114,6 +144,8 @@ const pktio_if_ops_t loopback_pktio_ops = { .close = loopback_close, .start = NULL, .stop = NULL, + .stats = loopback_stats, + .stats_reset = loopback_stats_reset, .recv = loopback_recv, .send = loopback_send, .mtu_get = loopback_mtu_get,