Linux-HyperV Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v3 net-next] net: hyperv: Add attributes to show TX indirection table
@ 2020-07-20  7:17 Chi Song
  2020-07-20 15:28 ` Haiyang Zhang
  0 siblings, 1 reply; 2+ messages in thread
From: Chi Song @ 2020-07-20  7:17 UTC (permalink / raw)
  To: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu,
	David S. Miller, Jakub Kicinski
  Cc: linux-hyperv, netdev, linux-kernel

An imbalanced TX indirection table causes netvsc to have low
performance. This table is created and managed during runtime. To help
better diagnose performance issues caused by imbalanced tables, add
device attributes to show the content of TX indirection tables.

Signed-off-by: Chi Song <chisong@microsoft.com>
---
v2: remove RX as it's in ethtool already, show single value in each file,
 and update description.
v3: fix broken format by alpine.

Thank you for comments. Let me know, if I miss something.

---
 drivers/net/hyperv/netvsc_drv.c | 53 +++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 6267f706e8ee..222c2fad9300 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -2370,6 +2370,55 @@ static int netvsc_unregister_vf(struct net_device *vf_netdev)
 	return NOTIFY_OK;
 }
 
+static struct device_attribute dev_attr_netvsc_dev_attrs[VRSS_SEND_TAB_SIZE];
+static struct attribute *netvsc_dev_attrs[VRSS_SEND_TAB_SIZE + 1];
+
+const struct attribute_group netvsc_dev_group = {
+	.name = NULL,
+	.attrs = netvsc_dev_attrs,
+};
+
+static ssize_t tx_indirection_table_show(struct device *dev,
+					 struct device_attribute *dev_attr,
+					 char *buf)
+{
+	struct net_device *ndev = to_net_dev(dev);
+	struct net_device_context *ndc = netdev_priv(ndev);
+	ssize_t offset = 0;
+	int index = dev_attr - dev_attr_netvsc_dev_attrs;
+
+	offset = sprintf(buf, "%u\n", ndc->tx_table[index]);
+
+	return offset;
+}
+
+static void netvsc_attrs_init(void)
+{
+	int i;
+	char buffer[32];
+
+	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++) {
+		sprintf(buffer, "tx_indirection_table_%02u", i);
+		dev_attr_netvsc_dev_attrs[i].attr.name =
+			kstrdup(buffer, GFP_KERNEL);
+		dev_attr_netvsc_dev_attrs[i].attr.mode = 0444;
+		sysfs_attr_init(&dev_attr_netvsc_dev_attrs[i].attr);
+
+		dev_attr_netvsc_dev_attrs[i].show = tx_indirection_table_show;
+		dev_attr_netvsc_dev_attrs[i].store = NULL;
+		netvsc_dev_attrs[i] = &dev_attr_netvsc_dev_attrs[i].attr;
+	}
+	netvsc_dev_attrs[VRSS_SEND_TAB_SIZE] = NULL;
+}
+
+static void netvsc_attrs_exit(void)
+{
+	int i;
+
+	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
+		kfree(dev_attr_netvsc_dev_attrs[i].attr.name);
+}
+
 static int netvsc_probe(struct hv_device *dev,
 			const struct hv_vmbus_device_id *dev_id)
 {
@@ -2396,6 +2445,7 @@ static int netvsc_probe(struct hv_device *dev,
 			   net_device_ctx->msg_enable);
 
 	hv_set_drvdata(dev, net);
+	netvsc_attrs_init();
 
 	INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change);
 
@@ -2410,6 +2460,7 @@ static int netvsc_probe(struct hv_device *dev,
 
 	net->netdev_ops = &device_ops;
 	net->ethtool_ops = &ethtool_ops;
+	net->sysfs_groups[0] = &netvsc_dev_group;
 	SET_NETDEV_DEV(net, &dev->device);
 
 	/* We always need headroom for rndis header */
@@ -2533,6 +2584,7 @@ static int netvsc_remove(struct hv_device *dev)
 
 	rtnl_unlock();
 
+	netvsc_attrs_exit();
 	hv_set_drvdata(dev, NULL);
 
 	free_percpu(ndev_ctx->vf_stats);
@@ -2683,6 +2735,7 @@ static int __init netvsc_drv_init(void)
 		return ret;
 
 	register_netdevice_notifier(&netvsc_netdev_notifier);
+
 	return 0;
 }
 
-- 
2.25.1

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

* RE: [PATCH v3 net-next] net: hyperv: Add attributes to show TX indirection table
  2020-07-20  7:17 [PATCH v3 net-next] net: hyperv: Add attributes to show TX indirection table Chi Song
@ 2020-07-20 15:28 ` Haiyang Zhang
  0 siblings, 0 replies; 2+ messages in thread
From: Haiyang Zhang @ 2020-07-20 15:28 UTC (permalink / raw)
  To: Chi Song, KY Srinivasan, Stephen Hemminger, Wei Liu,
	David S. Miller, Jakub Kicinski
  Cc: linux-hyperv, netdev, linux-kernel



> -----Original Message-----
> From: Chi Song <Song.Chi@microsoft.com>
> Sent: Monday, July 20, 2020 3:17 AM
> To: KY Srinivasan <kys@microsoft.com>; Haiyang Zhang
> <haiyangz@microsoft.com>; Stephen Hemminger <sthemmin@microsoft.com>;
> Wei Liu <wei.liu@kernel.org>; David S. Miller <davem@davemloft.net>; Jakub
> Kicinski <kuba@kernel.org>
> Cc: linux-hyperv@vger.kernel.org; netdev@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: [PATCH v3 net-next] net: hyperv: Add attributes to show TX indirection
> table
> 
> An imbalanced TX indirection table causes netvsc to have low
> performance. This table is created and managed during runtime. To help
> better diagnose performance issues caused by imbalanced tables, add
> device attributes to show the content of TX indirection tables.
> 
> Signed-off-by: Chi Song <chisong@microsoft.com>
> ---
> v2: remove RX as it's in ethtool already, show single value in each file,
>  and update description.
> v3: fix broken format by alpine.
> 
> Thank you for comments. Let me know, if I miss something.
> 
> ---
>  drivers/net/hyperv/netvsc_drv.c | 53 +++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index 6267f706e8ee..222c2fad9300 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -2370,6 +2370,55 @@ static int netvsc_unregister_vf(struct net_device
> *vf_netdev)
>  	return NOTIFY_OK;
>  }
> 
> +static struct device_attribute
> dev_attr_netvsc_dev_attrs[VRSS_SEND_TAB_SIZE];
> +static struct attribute *netvsc_dev_attrs[VRSS_SEND_TAB_SIZE + 1];
> +
> +const struct attribute_group netvsc_dev_group = {
> +	.name = NULL,
> +	.attrs = netvsc_dev_attrs,
> +};
> +
> +static ssize_t tx_indirection_table_show(struct device *dev,
> +					 struct device_attribute *dev_attr,
> +					 char *buf)
> +{
> +	struct net_device *ndev = to_net_dev(dev);
> +	struct net_device_context *ndc = netdev_priv(ndev);
> +	ssize_t offset = 0;
> +	int index = dev_attr - dev_attr_netvsc_dev_attrs;
> +
> +	offset = sprintf(buf, "%u\n", ndc->tx_table[index]);
> +
> +	return offset;
> +}
> +
> +static void netvsc_attrs_init(void)
> +{
> +	int i;
> +	char buffer[32];
> +
> +	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++) {
> +		sprintf(buffer, "tx_indirection_table_%02u", i);
> +		dev_attr_netvsc_dev_attrs[i].attr.name =
> +			kstrdup(buffer, GFP_KERNEL);
> +		dev_attr_netvsc_dev_attrs[i].attr.mode = 0444;
> +		sysfs_attr_init(&dev_attr_netvsc_dev_attrs[i].attr);
> +
> +		dev_attr_netvsc_dev_attrs[i].show = tx_indirection_table_show;
> +		dev_attr_netvsc_dev_attrs[i].store = NULL;
> +		netvsc_dev_attrs[i] = &dev_attr_netvsc_dev_attrs[i].attr;
> +	}
> +	netvsc_dev_attrs[VRSS_SEND_TAB_SIZE] = NULL;
> +}
> +
> +static void netvsc_attrs_exit(void)
> +{
> +	int i;
> +
> +	for (i = 0; i < VRSS_SEND_TAB_SIZE; i++)
> +		kfree(dev_attr_netvsc_dev_attrs[i].attr.name);
> +}
> +
>  static int netvsc_probe(struct hv_device *dev,
>  			const struct hv_vmbus_device_id *dev_id)
>  {
> @@ -2396,6 +2445,7 @@ static int netvsc_probe(struct hv_device *dev,
>  			   net_device_ctx->msg_enable);
> 
>  	hv_set_drvdata(dev, net);
> +	netvsc_attrs_init();

dev_attr_netvsc_dev_attrs is a global array, so it should be initialized 
and cleaned up in netvsc_drv_init/exit(). 
If there are multiple NICs and possible hot add/remove, init/cleaning it in 
netvsc_probe/remove() will cause memory leak, and/or use of freed 
memory.

Thanks,
- Haiyang

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20  7:17 [PATCH v3 net-next] net: hyperv: Add attributes to show TX indirection table Chi Song
2020-07-20 15:28 ` Haiyang Zhang

Linux-HyperV Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hyperv/0 linux-hyperv/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hyperv linux-hyperv/ https://lore.kernel.org/linux-hyperv \
		linux-hyperv@vger.kernel.org
	public-inbox-index linux-hyperv

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hyperv


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git