From patchwork Tue Jan 26 16:00:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 60470 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2047824lbb; Tue, 26 Jan 2016 08:02:46 -0800 (PST) X-Received: by 10.55.26.6 with SMTP id a6mr28816333qka.0.1453824166522; Tue, 26 Jan 2016 08:02:46 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 38si1999429qgj.56.2016.01.26.08.02.44; Tue, 26 Jan 2016 08:02:46 -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 Received: by lists.linaro.org (Postfix, from userid 109) id E327361797; Tue, 26 Jan 2016 16:02:43 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=jjm+zp3g; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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 CBCDF61659; Tue, 26 Jan 2016 16:01:06 +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 0132261749; Tue, 26 Jan 2016 16:00:54 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id 3222D61659 for ; Tue, 26 Jan 2016 16:00:53 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id s81so1647621lfd.0 for ; Tue, 26 Jan 2016 08:00:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y8k6Esu+VrqQDDsp/XvpcVAoEBCZMsR7PamWQD6cYMk=; b=jjm+zp3g3OHMtrQDa/M0q7A+muXD08tTKW/xhJHiVETa8Mvtqj1rjG+DQ81iJq1EMm TOcDxh6hEo0XHV63nMTI8PaOS9nu/0wjRT/jzmSvz0p82G7AGAQNqxNWfjrYoNx/vpCD tKhP6nst38Ua+vhx33s9SXxtrDvCJUK4NwQlY= 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=Y8k6Esu+VrqQDDsp/XvpcVAoEBCZMsR7PamWQD6cYMk=; b=IcjElAkUKDTBffL2sSDqDTpJEm7ylwrkghcSM92dNAqw1+fTwJyhwg3kugLNeg4kQK WuAH8C9hlFUBEZLHo2/g8xQrTKH5HtnCw+9Iutx+XWkhB3d4jbCc2DL3ppIDbbfhJPSB BnoYGWHFMBD9AyQQNZ7icKaeJf4Qq1eiyTfPAKXgm5WE1yShBr8W5E/7LMe4iOJPr1NU bglPqzA9nGA70oNHSR97p+TqC6ny70b4F+8S18iwgrujZFJlpimINYNwYHxuOgJ1Xh7V uIg8QKbZlKz2PrAXEuR/ULpoy6IjBQSJ01JoOSbDkc6rPcBCkJJR6iDK182AXsH7HvlJ 7xtA== X-Gm-Message-State: AG10YOS1icnvO4LsURSXDkew/KVzRQzxkqu8E6SiMQUuV+WOECoj/tzl9NI4Ha860rv1IeYZn5A= X-Received: by 10.25.22.38 with SMTP id m38mr9072127lfi.142.1453824052166; Tue, 26 Jan 2016 08:00:52 -0800 (PST) Received: from localhost.localdomain (ppp91-76-173-134.pppoe.mtu-net.ru. [91.76.173.134]) by smtp.gmail.com with ESMTPSA id f186sm254394lfd.26.2016.01.26.08.00.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Jan 2016 08:00:51 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 26 Jan 2016 19:00:41 +0300 Message-Id: <1453824042-29478-5-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453824042-29478-1-git-send-email-maxim.uvarov@linaro.org> References: <1453824042-29478-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv8 4/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 7da36aa..c22cce0 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -49,6 +49,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; @@ -154,6 +156,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; } @@ -249,6 +253,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; @@ -259,6 +264,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; } @@ -291,7 +297,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; @@ -300,9 +308,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; } @@ -367,10 +378,25 @@ 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 = { .name = "pcap", .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,