DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib stat
@ 2020-04-09 20:37 Mohsin Shaikh
  2020-04-09 22:20 ` Alexander Kozyrev
  2020-04-14 14:17 ` Raslan Darawsheh
  0 siblings, 2 replies; 4+ messages in thread
From: Mohsin Shaikh @ 2020-04-09 20:37 UTC (permalink / raw)
  To: dev; +Cc: stable, akozyrev, Mohsin Shaikh

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.

Bugzilla ID: 440
Cc: stable@dpdk.org

Signed-off-by: Mohsin Shaikh <mohsinshaikh@niometrics.com>
---
 drivers/net/mlx5/mlx5_stats.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c
index 7603502..b2c09d8 100644
--- a/drivers/net/mlx5/mlx5_stats.c
+++ b/drivers/net/mlx5/mlx5_stats.c
@@ -3,11 +3,13 @@
  * Copyright 2015 Mellanox Technologies, Ltd
  */
 
+#include <fcntl.h>
 #include <inttypes.h>
 #include <linux/sockios.h>
 #include <linux/ethtool.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include <rte_ethdev_driver.h>
 #include <rte_common.h>
@@ -142,20 +144,23 @@
 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[21] = {'\0'};
+			ssize_t n = read(fd, buf, sizeof(buf));
+
+			close(fd);
+			if (n != -1) {
+				*stat = strtoull(buf, NULL, 10);
 				return;
+			}
 		}
 	}
 	*stat = 0;
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib stat
  2020-04-09 20:37 [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib stat Mohsin Shaikh
@ 2020-04-09 22:20 ` Alexander Kozyrev
  2020-04-13 10:48   ` Slava Ovsiienko
  2020-04-14 14:17 ` Raslan Darawsheh
  1 sibling, 1 reply; 4+ messages in thread
From: Alexander Kozyrev @ 2020-04-09 22:20 UTC (permalink / raw)
  To: Mohsin Shaikh, dev; +Cc: stable

> -----Original Message-----
> From: Mohsin Shaikh <mohsinshaikh@niometrics.com>
> Sent: Thursday, April 9, 2020 16:37
> To: dev@dpdk.org
> Cc: stable@dpdk.org; Alexander Kozyrev <akozyrev@mellanox.com>; Mohsin
> Shaikh <mohsinshaikh@niometrics.com>
> Subject: [PATCH] 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.
> 
> Bugzilla ID: 440
> Cc: stable@dpdk.org
> 
> Signed-off-by: Mohsin Shaikh <mohsinshaikh@niometrics.com>
> ---

Reviewed-by: Alexander Kozyrev <akozyrev@mellanox.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib stat
  2020-04-09 22:20 ` Alexander Kozyrev
@ 2020-04-13 10:48   ` Slava Ovsiienko
  0 siblings, 0 replies; 4+ messages in thread
From: Slava Ovsiienko @ 2020-04-13 10:48 UTC (permalink / raw)
  To: Alexander Kozyrev, Mohsin Shaikh, dev; +Cc: stable

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Alexander Kozyrev
> Sent: Friday, April 10, 2020 1:21
> To: Mohsin Shaikh <mohsinshaikh@niometrics.com>; dev@dpdk.org
> Cc: stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib
> stat
> 
> > -----Original Message-----
> > From: Mohsin Shaikh <mohsinshaikh@niometrics.com>
> > Sent: Thursday, April 9, 2020 16:37
> > To: dev@dpdk.org
> > Cc: stable@dpdk.org; Alexander Kozyrev <akozyrev@mellanox.com>;
> Mohsin
> > Shaikh <mohsinshaikh@niometrics.com>
> > Subject: [PATCH] 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.
> >
> > Bugzilla ID: 440
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Mohsin Shaikh <mohsinshaikh@niometrics.com>
> > ---
> 
> Reviewed-by: Alexander Kozyrev <akozyrev@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>

Thank you, Mohsin for the patch.
Alexander, thank you for the review and test.

With best regards,
Slava


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib stat
  2020-04-09 20:37 [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib stat Mohsin Shaikh
  2020-04-09 22:20 ` Alexander Kozyrev
@ 2020-04-14 14:17 ` Raslan Darawsheh
  1 sibling, 0 replies; 4+ messages in thread
From: Raslan Darawsheh @ 2020-04-14 14:17 UTC (permalink / raw)
  To: Mohsin Shaikh, dev; +Cc: stable, Alexander Kozyrev, Slava Ovsiienko

Hi,


> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Mohsin Shaikh
> Sent: Thursday, April 9, 2020 11:37 PM
> To: dev@dpdk.org
> Cc: stable@dpdk.org; Alexander Kozyrev <akozyrev@mellanox.com>;
> Mohsin Shaikh <mohsinshaikh@niometrics.com>
> Subject: [dpdk-dev] [PATCH] 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.
> 
> Bugzilla ID: 440
> Cc: stable@dpdk.org
> 
> Signed-off-by: Mohsin Shaikh <mohsinshaikh@niometrics.com>
> ---
>  drivers/net/mlx5/mlx5_stats.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.c
> index 7603502..b2c09d8 100644
> --- a/drivers/net/mlx5/mlx5_stats.c
> +++ b/drivers/net/mlx5/mlx5_stats.c
> @@ -3,11 +3,13 @@
>   * Copyright 2015 Mellanox Technologies, Ltd
>   */
> 
> +#include <fcntl.h>
>  #include <inttypes.h>
>  #include <linux/sockios.h>
>  #include <linux/ethtool.h>
>  #include <stdint.h>
>  #include <stdio.h>
> +#include <unistd.h>
> 
>  #include <rte_ethdev_driver.h>
>  #include <rte_common.h>
> @@ -142,20 +144,23 @@
>  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[21] = {'\0'};
> +			ssize_t n = read(fd, buf, sizeof(buf));
> +
> +			close(fd);
> +			if (n != -1) {
> +				*stat = strtoull(buf, NULL, 10);
>  				return;
> +			}
>  		}
>  	}
>  	*stat = 0;
> --
> 1.8.3.1


Patch rebased and applied to next-net-mlx,

Kindest regards
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-14 14:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 20:37 [dpdk-dev] [PATCH] net/mlx5: use open/read/close for reading ib stat Mohsin Shaikh
2020-04-09 22:20 ` Alexander Kozyrev
2020-04-13 10:48   ` Slava Ovsiienko
2020-04-14 14:17 ` Raslan Darawsheh

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).