DPDK patches and discussions
 help / color / mirror / Atom feed
From: Mohsin Shaikh <mohsinshaikh@niometrics.com>
To: dev@dpdk.org
Cc: akozyrev@mellanox.com
Subject: Re: [dpdk-dev] [Bug 440] net/mlx5: Read of "out_of_buffer" using fopen/fscanf/fclose causing TLB shootdowns due to mmap/munmap
Date: Thu, 9 Apr 2020 12:44:55 +0800	[thread overview]
Message-ID: <34D03F2C-61CD-499B-A258-7165330AF9A2@niometrics.com> (raw)
In-Reply-To: <E993FFAF-3992-466A-B6C0-41DE745D0C42@niometrics.com>

Resending. 

============================================================
commit 89681d3655f27d758537ae01a02d500deee1acd6
Author: Mohsin Shaikh <mohsinshaikh@niometrics.com>
Date:   Thu Apr 9 12:19:45 2020 +0800

    net/mlx5: Use open/read/close for reading ib stat
    
    fgets(3)/fread(3)/fscanf(3) etc. use mmap(2)/munmap(2) which leads to TLB
    shootdown interrupts to all dpdk app cores including RX cores. This can
    cause packet drops. Use read(2)/write(2) instead.
    
    The details can be found here:
    https://bugs.dpdk.org/show_bug.cgi?id=440
    
    Bugzilla ID: 440

diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c
index 205e4fe..91ac933 100644
--- a/drivers/net/mlx5/mlx5_stats.c
+++ b/drivers/net/mlx5/mlx5_stats.c
@@ -8,6 +8,8 @@
 #include <linux/ethtool.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
 
 #include <rte_ethdev_driver.h>
 #include <rte_common.h>
@@ -139,20 +141,22 @@
 static inline void
 mlx5_read_ib_stat(struct mlx5_priv *priv, const char *ctr_name, uint64_t *stat)
 {
-	FILE *file;
+	int fd;
 	if (priv->sh) {
 		MKSTR(path, "%s/ports/%d/hw_counters/%s",
 			  priv->sh->ibdev_path,
 			  priv->ibv_port,
 			  ctr_name);
 
-		file = fopen(path, "rb");
-		if (file) {
-			int n = fscanf(file, "%" SCNu64, stat);
-
-			fclose(file);
-			if (n == 1)
+		fd = open(path, O_RDONLY);
+		if (fd != -1) {
+			char buf[32];
+			ssize_t n = read(fd, buf, sizeof(buf));
+			close(fd);
+			if (n != -1) {
+				sscanf(buf, "%" SCNu64, stat);
 				return;
+			}
 		}
 	}
 	*stat = 0;

============================================================

Thanks,
Mohsin

> On 9 Apr 2020, at 12:26 PM, Mohsin Shaikh <mohsinshaikh@niometrics.com> wrote:
> 
> Hi Alexander,
> 
> Thank you for your quick response. Please find attached the patch for bug 440. 
> 
> - Mohsin
> 
> 
> 
>> On 9 Apr 2020, at 1:07 AM, bugzilla@dpdk.org wrote:
>> 
>> https://bugs.dpdk.org/show_bug.cgi?id=440
>> 
>> Alexander Kozyrev (akozyrev@mellanox.com) changed:
>> 
>>          What    |Removed                     |Added
>> ----------------------------------------------------------------------------
>>    Ever confirmed|0                           |1
>>            Status|UNCONFIRMED                 |CONFIRMED
>>                CC|                            |akozyrev@mellanox.com
>> 
>> --- Comment #1 from Alexander Kozyrev (akozyrev@mellanox.com) ---
>> Hi Mohsin, thank you for the problem description and especially for the patch.
>> Would you mind sending this patch to DPDK mailing list so we can integrate it?
>> The patch looks really good to me. The only small thing I would like to change.
>> Could you please use SCNu64 macro instead of "%lu" in the sscanf function?
>>   sscanf(buf, "%" SCNu64, stat);
>> 
>> -- 
>> You are receiving this mail because:
>> You reported the bug.
> 


      reply	other threads:[~2020-04-09  4:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-440-272@http.bugs.dpdk.org/>
     [not found] ` <bug-440-272-PxGGXr8U9C@http.bugs.dpdk.org/>
2020-04-09  4:26   ` Mohsin Shaikh
2020-04-09  4:44     ` Mohsin Shaikh [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34D03F2C-61CD-499B-A258-7165330AF9A2@niometrics.com \
    --to=mohsinshaikh@niometrics.com \
    --cc=akozyrev@mellanox.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).