From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2D3DB460A3; Thu, 16 Jan 2025 17:24:48 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CAEF6402F1; Thu, 16 Jan 2025 17:24:47 +0100 (CET) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by mails.dpdk.org (Postfix) with ESMTP id 7F0054026C for ; Thu, 16 Jan 2025 17:24:46 +0100 (CET) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21634338cfdso28656275ad.2 for ; Thu, 16 Jan 2025 08:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737044685; x=1737649485; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ILGEnRSRWIeUFZHavZTGpKSpHsq7FV68Fe/L5Moy0pE=; b=GUU1AMQaTL5DN7me6XpkRBdAhFIynq/NPWzZjZqJ3lxv/dZWvNdEsPpPodrk5teAwT 1tWE/IoQysOm1jei7mfAAoImU+hnmWf2IJJYlt57RTtsvEBolULnoUz0YIO2SzYKa6/w dASDEBTrJQpe/9Xp/6AmIlasyEPvMdv1AQZPUXX7RjIk83+pH5/+5eovimkMwrY4/Nki gbU7AJwGkB7DCT+QdyprxVbSPhMI6diQUWtU8rWuj9jlpNYkg2Qv0QZYfTfEwICSvNhZ kHg5byjJ2uBEzAf8tT7wRqF/K7bC+4CONq2n0UD5z9/c2IKZR3Nk7mnSzaTjRvfisPev LGig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737044685; x=1737649485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ILGEnRSRWIeUFZHavZTGpKSpHsq7FV68Fe/L5Moy0pE=; b=S/YICBbxv+O5BcW1SknbEBK/lewATbjdAWvciX249dqgcMtmFFeszZnQSOpLCkKl1D hyOUncCL8zujKpb4vDlDAiAjgFsDPQAkl7EVlg8JQBhcgWC/x3lD5RVRSRpbPgM/ennP s+dEbxyjyDyPZOSIZB0Xtji8/IkvZnayAvQ4ao89lBBHCVBXKg4DrkrJhfu4MSW6igtS C2UxH5gJkOXVQzfEu0J9pG6rBtmPWWFnpWA6SNSRxHFkIrkpocxq66fdl1k3ZKWYt6D5 qLPNP2BoyblRD82y+FSZ241zmuczX36zN6mw6BUdllG+FijpM2wrspeu1IV3c3tdsQ0E MO4g== X-Forwarded-Encrypted: i=1; AJvYcCWl+Eq1dTC2d444DP1XlqoPpGd6hjmawnRmmrENTetaQ6IGLjVi9Q69Rz5gh3qZQ8UAGBw=@dpdk.org X-Gm-Message-State: AOJu0Yyrtuwaq4mD/giMYecr1wuS7QAXkgzGpnPwSh3z8UF9jKrlDKs5 RW+TwQ8w0SH2CTMzVk2FpOGFZNsAixA12q1lY8nmQQRtzpp6jcY/Dr1EhKwc1rg= X-Gm-Gg: ASbGncuP2QTbPPO+82g0Ry3mHJR+ZPvUPPUs5XYlnm7CbTbOMLLWLM4s3ZE6xo540Uy LU1RJCCtodd/dSAuGpOTef5CAw5u6vDM/IYjnDGK+8P2nIAIeZ1UAtbbf2JmHgtOfKvORgF+3Cx b1BfUrTGR7a4uZSY5UyQlQ/qzRb8yfHCiSVRoZo2lkdKWH2TLqE4YZ8RWIcSrk0QgGeG0CM4AAW ZUmrJ0W7/BFkVEkwUHDa2bgsBXfz3fdxYaQaSgWkfKLTHGUJHpqqZV46MvwFwl2Bp3g9v02h2dO 9p+UoOHn1c0V87RnaFdRYit6T8HZsj6SiA== X-Google-Smtp-Source: AGHT+IEJJHZAZ8ccyFcQqO9BIBh3LHmy1HrStxQOuPQtpyCVwzHYGupWXEqfBstSolMOZn2g3F5nbg== X-Received: by 2002:a17:902:d2c2:b0:21a:87d1:168a with SMTP id d9443c01a7336-21a87d11b43mr498257035ad.41.1737044685191; Thu, 16 Jan 2025 08:24:45 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d402d61sm2149885ad.229.2025.01.16.08.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jan 2025 08:24:44 -0800 (PST) Date: Thu, 16 Jan 2025 08:24:43 -0800 From: Stephen Hemminger To: Stefan Laesser Cc: "John W. Linville" , Subject: Re: [PATCH] net/af_packet: provide packet drop stats Message-ID: <20250116082443.341e5d89@hermes.local> In-Reply-To: <20250116161703.917279-1-stefan.laesser@omicronenergy.com> References: <20250116161703.917279-1-stefan.laesser@omicronenergy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Thu, 16 Jan 2025 17:17:03 +0100 Stefan Laesser wrote: > The Linux kernel provides the ability to query the packet drop counter > of a socket. This information can be provided when the user requests > stats. > > It is important to note that each call to getsockopt with > PACKET_STATISTICS resets the internal counters. So the caller needs to > keep track of the total count on its own. > > Next, I have added a counter for the case when mbuf couldn't be > allocated. > > Signed-off-by: Stefan Laesser > --- > drivers/net/af_packet/rte_eth_af_packet.c | 32 +++++++++++++++++++++-- > 1 file changed, 30 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c > index ceb8d9356a..a771dd854d 100644 > --- a/drivers/net/af_packet/rte_eth_af_packet.c > +++ b/drivers/net/af_packet/rte_eth_af_packet.c > @@ -58,6 +58,8 @@ struct __rte_cache_aligned pkt_rx_queue { > > volatile unsigned long rx_pkts; > volatile unsigned long rx_bytes; > + volatile unsigned long rx_nombuf; > + volatile unsigned long rx_dropped_pkts; > }; > > struct __rte_cache_aligned pkt_tx_queue { > @@ -145,8 +147,10 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) > > /* allocate the next mbuf */ > mbuf = rte_pktmbuf_alloc(pkt_q->mb_pool); > - if (unlikely(mbuf == NULL)) > + if (unlikely(mbuf == NULL)) { > + pkt_q->rx_nombuf++; > break; > + } > > /* packet will fit in the mbuf, go ahead and receive it */ > rte_pktmbuf_pkt_len(mbuf) = rte_pktmbuf_data_len(mbuf) = ppd->tp_snaplen; > @@ -417,17 +421,37 @@ static int > 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_total = 0, rx_dropped_total = 0, rx_nombuf_total = 0; > + unsigned long 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; > > + struct tpacket_stats iface_stats; > + socklen_t iface_stats_len = sizeof(struct tpacket_stats); This declaration could be moved inside the loop. > + > imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? > internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS); > for (i = 0; i < imax; i++) { > + /* query dropped packets counter from socket */ > + if (internal->rx_queue[i].sockfd != -1 && > + getsockopt(internal->rx_queue[i].sockfd, SOL_PACKET, > + PACKET_STATISTICS, &iface_stats, > + &iface_stats_len) > -1) { > + /* > + * keep total because each call to getsocketopt with PACKET_STATISTICS > + * reset the counter of the socket > + */ > + internal->rx_queue[i].rx_dropped_pkts += iface_stats.tp_drops; > + } > + > igb_stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts; > igb_stats->q_ibytes[i] = internal->rx_queue[i].rx_bytes; > + igb_stats->q_errors[i] = internal->rx_queue[i].rx_dropped_pkts; Dropped packets are not errors; at least most other drivers do not report missed packets as errors. Should be imissed statistic. > + > rx_total += igb_stats->q_ipackets[i]; > rx_bytes_total += igb_stats->q_ibytes[i]; > + rx_dropped_total += igb_stats->q_errors[i]; > + rx_nombuf_total += internal->rx_queue[i].rx_nombuf; > } > > imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ? > @@ -442,6 +466,8 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats) > > igb_stats->ipackets = rx_total; > igb_stats->ibytes = rx_bytes_total; > + igb_stats->imissed = rx_dropped_total; > + igb_stats->rx_nombuf = rx_nombuf_total; > igb_stats->opackets = tx_total; > igb_stats->oerrors = tx_err_total; > igb_stats->obytes = tx_bytes_total; > @@ -457,6 +483,8 @@ eth_stats_reset(struct rte_eth_dev *dev) > for (i = 0; i < internal->nb_queues; i++) { > internal->rx_queue[i].rx_pkts = 0; > internal->rx_queue[i].rx_bytes = 0; > + internal->rx_queue[i].rx_nombuf = 0; > + internal->rx_queue[i].rx_dropped_pkts = 0; > } > > for (i = 0; i < internal->nb_queues; i++) { What about stats reset?