From patchwork Wed Nov 18 09:34:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 56923 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2456056lbb; Wed, 18 Nov 2015 01:37:01 -0800 (PST) X-Received: by 10.55.52.142 with SMTP id b136mr426564qka.100.1447839420995; Wed, 18 Nov 2015 01:37:00 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 43si1589356qgc.61.2015.11.18.01.37.00; Wed, 18 Nov 2015 01:37:00 -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 A186A61D81; Wed, 18 Nov 2015 09:37:00 +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 EEA2061E55; Wed, 18 Nov 2015 09:34:53 +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 79FDF61D85; Wed, 18 Nov 2015 09:34:37 +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 8CA2661D81 for ; Wed, 18 Nov 2015 09:34:35 +0000 (UTC) Received: by lfaz4 with SMTP id z4so22512965lfa.0 for ; Wed, 18 Nov 2015 01:34:34 -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=Ds+LcC7bmrKJqdL+BN9CE55yOqJFddEHx1pUB1AXKvk=; b=mGnZ6Xro2gUV1+b0W63113pWYp8xJUs89oaGdXWr4xGtkzqDW2+ACe5nRrHw26cPNJ vwlZBxJQSHQsMCLpP3tsL9LgX0+PC0DWekb+5lP2ZJJ2cYAtZdrKE4mVUcZia9KkYVGi TfE/xIssu7puNVvT/P7n98U8rZvOeuPSHCAULfS6JfTVK6+uq6CS9ZViIFDGcjh+Tlgq vEU9SHteZfM65lITB6z8OFCtfKbOkdqCjnwzAxSCOImizAaRHalBlkWpN8o4cMdjevpD mPefwu1UBp4d1EevXPY0Ox0/HdOX3fsxfChmjcP5kzHliwQ+RjcVKezi71ktM7OaKKJw aoDQ== 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=Ds+LcC7bmrKJqdL+BN9CE55yOqJFddEHx1pUB1AXKvk=; b=ShFBEf7kWAhdXrTSwMgeVe1BFdyL8HAc/bFG/WljMNM/yVpb7a/U4++mb4bXKiAwFX rCWf/O7ATtIcga3PqnusJmr+D9OA2i9pNT/W9+hzoZ/9sohzZnH8G0MGuFAgRrMwOHFA 5Gt30DYtIaZxKGUrviZs7kxVgd/0CIxzhiNJ3XBnVLrLCBLnW6DexDbaU1XHe5mRTPkU HuaWEDjTaiHP7jB/KNST1HIj/J5ZT4/VofmN7A/salW+J7EC1ppcTDNw7Ai80ItI5+mz gQ5jdneNVzFN4y+awJylqCESAQ636UvbnNPVfYV1CnHt25aRY1BQyw59ybFRnXtFlJE3 mqQg== X-Gm-Message-State: ALoCoQnAHLYxSH9dleQjtzW67McRYZQxNS+rQ+RXWcj72YkJUaKKbAK2TS22nSWlzV2y0o3rFV3Q X-Received: by 10.25.14.209 with SMTP id 200mr226384lfo.117.1447839274512; Wed, 18 Nov 2015 01:34:34 -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.33 (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:26 +0300 Message-Id: <1447839268-20423-4-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 3/5] linux-generic: pcap: implement pktio 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/pcap.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 0817bf5..34cd73c 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -51,6 +51,8 @@ #define PKTIO_PCAP_MTU (64 * 1024) static const char pcap_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0x04}; +static int pcapif_stats_reset(pktio_entry_t *pktio_entry); + static int _pcapif_parse_devname(pkt_pcap_t *pcap, const char *devname) { char *tok; @@ -156,6 +158,8 @@ static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, if (ret == 0 && (!pcap->rx && !pcap->tx_dump)) ret = -1; + (void)pcapif_stats_reset(pktio_entry); + return ret; } @@ -251,6 +255,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, odp_packet_t pkts[], } packet_parse_l2(pkt_hdr); + pktio_entry->s.stats.in_octets += pkt_hdr->frame_len; pkts[i] = pkt; pkt = ODP_PACKET_INVALID; @@ -261,6 +266,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, odp_packet_t pkts[], if (pkt != ODP_PACKET_INVALID) odp_packet_free(pkt); + pktio_entry->s.stats.in_ucast_pkts += i; return i; } @@ -293,7 +299,9 @@ static int pcapif_send_pkt(pktio_entry_t *pktio_entry, odp_packet_t pkts[], ODP_ASSERT(pktio_entry->s.state == STATE_START); for (i = 0; i < len; ++i) { - if (odp_packet_len(pkts[i]) > PKTIO_PCAP_MTU) { + int pkt_len = odp_packet_len(pkts[i]); + + if (pkt_len > PKTIO_PCAP_MTU) { if (i == 0) return -1; break; @@ -302,9 +310,12 @@ static int pcapif_send_pkt(pktio_entry_t *pktio_entry, odp_packet_t pkts[], if (_pcapif_dump_pkt(pcap, pkts[i]) != 0) break; + pktio_entry->s.stats.out_octets += pkt_len; odp_packet_free(pkts[i]); } + pktio_entry->s.stats.out_ucast_pkts += i; + return i; } @@ -369,9 +380,24 @@ static int pcapif_promisc_mode_get(pktio_entry_t *pktio_entry) return pktio_entry->s.pkt_pcap.promisc; } +static int pcapif_stats_reset(pktio_entry_t *pktio_entry) +{ + memset(&pktio_entry->s.stats, 0, sizeof(odp_pktio_stats_t)); + return 0; +} + +static int pcapif_stats(pktio_entry_t *pktio_entry, + odp_pktio_stats_t *stats) +{ + memcpy(stats, &pktio_entry->s.stats, sizeof(odp_pktio_stats_t)); + return 0; +} + const pktio_if_ops_t pcap_pktio_ops = { .open = pcapif_init, .close = pcapif_close, + .stats = pcapif_stats, + .stats_reset = pcapif_stats_reset, .recv = pcapif_recv_pkt, .send = pcapif_send_pkt, .mtu_get = pcapif_mtu_get,