From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <rich.lane@bigswitch.com>
Received: from mail-pf0-f180.google.com (mail-pf0-f180.google.com
 [209.85.192.180]) by dpdk.org (Postfix) with ESMTP id 0821C2BEB
 for <dev@dpdk.org>; Wed, 25 May 2016 23:03:24 +0200 (CEST)
Received: by mail-pf0-f180.google.com with SMTP id f144so8948416pfa.3
 for <dev@dpdk.org>; Wed, 25 May 2016 14:03:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=bigswitch-com.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:date:message-id;
 bh=S0YIGvxxghl2cQjJ3pHF+VBAKjCuW1u+EMU/Dmea9mY=;
 b=ArHXC6NsXqDe0AwuJkw7uzqSWbs3C0wYX2TTibtWRe8S4cpiTSMXe8SFJRo5/n2RMQ
 YNc+bbCY/PapsG22q2ctWUhMzmT60C2au/RZ5/6YMlGMWIoitlMqjAgAYcuIHxkISLaY
 GqMDWgWsjlcDRI+ECfVcS90hr36q6q5qgerKEI5agBTM8ZARPt1Ga7nhWNA4G7YwbTGd
 jZct5l84VMbTueYb9nPcLmsI4tiewdiPEM5ekaT7wdcuNl5JFMTP5/G/zyeva8SBz7do
 a1jdeK+5tc0wP0eimpzkSOtv0JJH7ExWYMMXWx10MoDVt0gjVzaRrxCCMEOD3JvRqFj7
 ktSA==
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;
 bh=S0YIGvxxghl2cQjJ3pHF+VBAKjCuW1u+EMU/Dmea9mY=;
 b=NyhEiM/IKsvk9YIafDmP8RRHvOQUQ5qR0mDtX+QgeVxyoiJjFWOFo1hDkZa9+Mf+84
 nfc8pthgCOdJnsj+c+Fuccru4uN5wCU/VpVOaWgYZvU0lIP8R5+jDoith1rrx8Qb7OKR
 kP/5QSXa+4o/5xFaY/21K1pVFjQ5bRXzgF0fTFSA89bYZ9XfeCZD+Djc+BmCqcDItjNS
 GysrMW5SJGAj7qLLiNyWm3a0xBPl6MLvmoYItqyLa5fNDsGrUuG1mYZbrvqppnOagW6l
 DNjukrICOLCfstQrDkLSSukuG3+wjTccTRNp/vNo0eN3gxb/jacLaZaS6rCHTVhpjURl
 3gMA==
X-Gm-Message-State: ALyK8tLXfp+glVmYNG5U8owUEA6hhC8OddjMvXpea5jDlgibyrcFh+cXyTq+qx6wa97Sjr3d
X-Received: by 10.98.3.4 with SMTP id 4mr8796495pfd.33.1464210203197;
 Wed, 25 May 2016 14:03:23 -0700 (PDT)
Received: from rlane-work.eng.bigswitch.com
 (c-67-188-28-208.hsd1.ca.comcast.net. [67.188.28.208])
 by smtp.gmail.com with ESMTPSA id kb15sm14873318pad.28.2016.05.25.14.03.22
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Wed, 25 May 2016 14:03:22 -0700 (PDT)
From: Rich Lane <rich.lane@bigswitch.com>
To: dev@dpdk.org
Cc: "John W. Linville" <linville@tuxdriver.com>
Date: Wed, 25 May 2016 14:03:20 -0700
Message-Id: <1464210200-91397-1-git-send-email-rich.lane@bigswitch.com>
X-Mailer: git-send-email 1.9.1
Subject: [dpdk-dev] [PATCH] af_packet: add byte counters
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Wed, 25 May 2016 21:03:24 -0000

Signed-off-by: Rich Lane <rich.lane@bigswitch.com>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index f17bd7e..2d7f344 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -78,6 +78,7 @@ struct pkt_rx_queue {
 
 	volatile unsigned long rx_pkts;
 	volatile unsigned long err_pkts;
+	volatile unsigned long rx_bytes;
 };
 
 struct pkt_tx_queue {
@@ -90,6 +91,7 @@ struct pkt_tx_queue {
 
 	volatile unsigned long tx_pkts;
 	volatile unsigned long err_pkts;
+	volatile unsigned long tx_bytes;
 };
 
 struct pmd_internals {
@@ -131,6 +133,7 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	uint8_t *pbuf;
 	struct pkt_rx_queue *pkt_q = queue;
 	uint16_t num_rx = 0;
+	unsigned long num_rx_bytes = 0;
 	unsigned int framecount, framenum;
 
 	if (unlikely(nb_pkts == 0))
@@ -167,9 +170,11 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		/* account for the receive frame */
 		bufs[i] = mbuf;
 		num_rx++;
+		num_rx_bytes += mbuf->pkt_len;
 	}
 	pkt_q->framenum = framenum;
 	pkt_q->rx_pkts += num_rx;
+	pkt_q->rx_bytes += num_rx_bytes;
 	return num_rx;
 }
 
@@ -186,6 +191,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct pollfd pfd;
 	struct pkt_tx_queue *pkt_q = queue;
 	uint16_t num_tx = 0;
+	unsigned long num_tx_bytes = 0;
 	int i;
 
 	if (unlikely(nb_pkts == 0))
@@ -219,6 +225,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		ppd = (struct tpacket2_hdr *) pkt_q->rd[framenum].iov_base;
 
 		num_tx++;
+		num_tx_bytes += mbuf->pkt_len;
 		rte_pktmbuf_free(mbuf);
 	}
 
@@ -229,6 +236,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	pkt_q->framenum = framenum;
 	pkt_q->tx_pkts += num_tx;
 	pkt_q->err_pkts += nb_pkts - num_tx;
+	pkt_q->tx_bytes += num_tx_bytes;
 	return num_tx;
 }
 
@@ -287,13 +295,16 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 {
 	unsigned i, imax;
 	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
+	unsigned long rx_bytes_total = 0, tx_bytes_total = 0;
 	const struct pmd_internals *internal = dev->data->dev_private;
 
 	imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
 	        internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS);
 	for (i = 0; i < imax; i++) {
 		igb_stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts;
+		igb_stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes;
 		rx_total += igb_stats->q_ipackets[i];
+		rx_bytes_total += igb_stats->q_ibytes[i];
 	}
 
 	imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
@@ -301,13 +312,17 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 	for (i = 0; i < imax; i++) {
 		igb_stats->q_opackets[i] = internal->tx_queue[i].tx_pkts;
 		igb_stats->q_errors[i] = internal->tx_queue[i].err_pkts;
+		igb_stats->q_obytes[i] = internal->tx_queue[i].tx_bytes;
 		tx_total += igb_stats->q_opackets[i];
 		tx_err_total += igb_stats->q_errors[i];
+		tx_bytes_total += igb_stats->q_obytes[i];
 	}
 
 	igb_stats->ipackets = rx_total;
+	igb_stats->ibytes = rx_bytes_total;
 	igb_stats->opackets = tx_total;
 	igb_stats->oerrors = tx_err_total;
+	igb_stats->obytes = tx_bytes_total;
 }
 
 static void
@@ -316,12 +331,15 @@ eth_stats_reset(struct rte_eth_dev *dev)
 	unsigned i;
 	struct pmd_internals *internal = dev->data->dev_private;
 
-	for (i = 0; i < internal->nb_queues; i++)
+	for (i = 0; i < internal->nb_queues; i++) {
 		internal->rx_queue[i].rx_pkts = 0;
+		internal->rx_queue[i].rx_bytes = 0;
+	}
 
 	for (i = 0; i < internal->nb_queues; i++) {
 		internal->tx_queue[i].tx_pkts = 0;
 		internal->tx_queue[i].err_pkts = 0;
+		internal->tx_queue[i].tx_bytes = 0;
 	}
 }
 
-- 
1.9.1