From patchwork Fri Jan 22 12:07:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 60135 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp628569lbb; Fri, 22 Jan 2016 04:09:48 -0800 (PST) X-Received: by 10.107.40.76 with SMTP id o73mr2994867ioo.157.1453464588166; Fri, 22 Jan 2016 04:09:48 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e19si11808081ioe.101.2016.01.22.04.09.47; Fri, 22 Jan 2016 04:09:48 -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 685EA616CA; Fri, 22 Jan 2016 12:09:47 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=GeNFY+3f; 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 EA985617ED; Fri, 22 Jan 2016 12:07:32 +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 7C6CB616F7; Fri, 22 Jan 2016 12:07:17 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by lists.linaro.org (Postfix) with ESMTPS id 79627616F7 for ; Fri, 22 Jan 2016 12:07:13 +0000 (UTC) Received: by mail-lb0-f179.google.com with SMTP id x4so40333582lbm.0 for ; Fri, 22 Jan 2016 04:07:13 -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=3LjsCHISz3JgIRmCBpQrsiCMBnh2ICeKzyz+J0VYofA=; b=GeNFY+3fwE711vq59Qu42rVUEjGVYhhmR3rVfDLA0L7zwnN4XxRnXKt3lVQnCwUTWF fzs6JTwH12hYKSYU3YNUvdH3aV6DFMUs6x5sH1oMHIw+II7HFoiqsgCv07h73SRRqliS cMsUS+reyssQxlnL/rhXDUIb2V0IF/1et+NIM= 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=3LjsCHISz3JgIRmCBpQrsiCMBnh2ICeKzyz+J0VYofA=; b=Sk0HP7jkJ+O4QWg5hvLUkc+kT6YEGNFFbBuR2iH+P/hfP3VEKOkeZecmswbdUYoYiD 6iNzk4jdRffduzD6uqJUwHTgchMqzCkgrhImeBK93bHlxOfZrgPIwvs6iRO6HbJap4TW RMrR4vR9WJs1vR9uLCA/2SQZGcWBzCWTwGsAQTNARpov1iRuFZUxdjhQAAOvW0YFP6ce wqiuLMjyjWml+aRGkWi8Jehx5xaj6dI7JjpKFNBi/YDcffro1ftQs85Pb/384EZHIE3J 8m9dkSET15TbeyGJSM7L8+GDHQb+Y8xOuRC5k/2KRSrczaTSSFCMIQAqgOMm5FAxTspt UObg== X-Gm-Message-State: AG10YOQ09CyyoOINBYzT75nWvk+HLyPNLVo2xzGWJ/LfGuOr9YTZXKnLtXA5WIxmWbBeFTopRNI= X-Received: by 10.112.64.42 with SMTP id l10mr1082488lbs.137.1453464432285; Fri, 22 Jan 2016 04:07:12 -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 wj2sm828569lbb.5.2016.01.22.04.07.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jan 2016 04:07:11 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 22 Jan 2016 15:07:02 +0300 Message-Id: <1453464424-28454-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453464424-28454-1-git-send-email-maxim.uvarov@linaro.org> References: <1453464424-28454-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv6 3/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 | 42 ++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index 3cb61a8..19c584b 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -24,6 +24,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) { @@ -40,6 +42,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; } @@ -68,8 +72,11 @@ static int loopback_recv(pktio_entry_t *pktio_entry, odp_packet_t pkts[], pkt_hdr = odp_packet_hdr(pkt); packet_parse_reset(pkt_hdr); packet_parse_l2(pkt_hdr); - if (0 > _odp_packet_classifier(pktio_entry, pkt)) + if (0 > _odp_packet_classifier(pktio_entry, pkt)) { pkts[j++] = pkt; + pktio_entry->s.stats.in_octets += + odp_packet_len(pkts[i]); + } } nbr = j; } else { @@ -79,9 +86,13 @@ static int loopback_recv(pktio_entry_t *pktio_entry, odp_packet_t pkts[], pkt_hdr = odp_packet_hdr(pkts[i]); packet_parse_reset(pkt_hdr); 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; } @@ -91,12 +102,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) @@ -124,6 +145,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 = { .name = "loop", .init = NULL, @@ -132,6 +166,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,