aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Fastabend <john.r.fastabend@intel.com>2015-03-18 08:57:33 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-18 14:55:18 -0400
commit822b3b2ebfff8e9b3d006086c527738a7ca00cd0 (patch)
treed3e6b25328bf4716982026b04dee8c0d2718a5d5
parentb65885d29d41c7245bbd98769e781f77e8d9ed5b (diff)
net: Add max rate tx queue attribute
This adds a tx_maxrate attribute to the tx queue sysfs entry allowing for max-rate limiting. Along with DCB-ETS and BQL this provides another knob to tune queue performance. The limit units are Mbps. By default it is disabled. To disable the rate limitation after it has been set for a queue, it should be set to zero. Signed-off-by: John Fastabend <john.r.fastabend@intel.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/ABI/testing/sysfs-class-net-queues8
-rw-r--r--Documentation/networking/scaling.txt9
-rw-r--r--include/linux/netdevice.h8
-rw-r--r--net/core/net-sysfs.c67
4 files changed, 80 insertions, 12 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-net-queues b/Documentation/ABI/testing/sysfs-class-net-queues
index 5e9aeb91d355..0c0df91b1516 100644
--- a/Documentation/ABI/testing/sysfs-class-net-queues
+++ b/Documentation/ABI/testing/sysfs-class-net-queues
@@ -24,6 +24,14 @@ Description:
24 Indicates the number of transmit timeout events seen by this 24 Indicates the number of transmit timeout events seen by this
25 network interface transmit queue. 25 network interface transmit queue.
26 26
27What: /sys/class/<iface>/queues/tx-<queue>/tx_maxrate
28Date: March 2015
29KernelVersion: 4.1
30Contact: netdev@vger.kernel.org
31Description:
32 A Mbps max-rate set for the queue, a value of zero means disabled,
33 default is disabled.
34
27What: /sys/class/<iface>/queues/tx-<queue>/xps_cpus 35What: /sys/class/<iface>/queues/tx-<queue>/xps_cpus
28Date: November 2010 36Date: November 2010
29KernelVersion: 2.6.38 37KernelVersion: 2.6.38
diff --git a/Documentation/networking/scaling.txt b/Documentation/networking/scaling.txt
index 99ca40e8e810..cbfac0949635 100644
--- a/Documentation/networking/scaling.txt
+++ b/Documentation/networking/scaling.txt
@@ -421,6 +421,15 @@ best CPUs to share a given queue are probably those that share the cache
421with the CPU that processes transmit completions for that queue 421with the CPU that processes transmit completions for that queue
422(transmit interrupts). 422(transmit interrupts).
423 423
424Per TX Queue rate limitation:
425=============================
426
427These are rate-limitation mechanisms implemented by HW, where currently
428a max-rate attribute is supported, by setting a Mbps value to
429
430/sys/class/net/<dev>/queues/tx-<n>/tx_maxrate
431
432A value of zero means disabled, and this is the default.
424 433
425Further Information 434Further Information
426=================== 435===================
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index dd1d069758be..76c5de4978a8 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -587,6 +587,7 @@ struct netdev_queue {
587#ifdef CONFIG_BQL 587#ifdef CONFIG_BQL
588 struct dql dql; 588 struct dql dql;
589#endif 589#endif
590 unsigned long tx_maxrate;
590} ____cacheline_aligned_in_smp; 591} ____cacheline_aligned_in_smp;
591 592
592static inline int netdev_queue_numa_node_read(const struct netdev_queue *q) 593static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
@@ -1022,6 +1023,10 @@ typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
1022 * be otherwise expressed by feature flags. The check is called with 1023 * be otherwise expressed by feature flags. The check is called with
1023 * the set of features that the stack has calculated and it returns 1024 * the set of features that the stack has calculated and it returns
1024 * those the driver believes to be appropriate. 1025 * those the driver believes to be appropriate.
1026 * int (*ndo_set_tx_maxrate)(struct net_device *dev,
1027 * int queue_index, u32 maxrate);
1028 * Called when a user wants to set a max-rate limitation of specific
1029 * TX queue.
1025 */ 1030 */
1026struct net_device_ops { 1031struct net_device_ops {
1027 int (*ndo_init)(struct net_device *dev); 1032 int (*ndo_init)(struct net_device *dev);
@@ -1178,6 +1183,9 @@ struct net_device_ops {
1178 netdev_features_t (*ndo_features_check) (struct sk_buff *skb, 1183 netdev_features_t (*ndo_features_check) (struct sk_buff *skb,
1179 struct net_device *dev, 1184 struct net_device *dev,
1180 netdev_features_t features); 1185 netdev_features_t features);
1186 int (*ndo_set_tx_maxrate)(struct net_device *dev,
1187 int queue_index,
1188 u32 maxrate);
1181}; 1189};
1182 1190
1183/** 1191/**
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index cf30620a88e1..7e58bd7ec232 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -951,6 +951,60 @@ static ssize_t show_trans_timeout(struct netdev_queue *queue,
951 return sprintf(buf, "%lu", trans_timeout); 951 return sprintf(buf, "%lu", trans_timeout);
952} 952}
953 953
954#ifdef CONFIG_XPS
955static inline unsigned int get_netdev_queue_index(struct netdev_queue *queue)
956{
957 struct net_device *dev = queue->dev;
958 int i;
959
960 for (i = 0; i < dev->num_tx_queues; i++)
961 if (queue == &dev->_tx[i])
962 break;
963
964 BUG_ON(i >= dev->num_tx_queues);
965
966 return i;
967}
968
969static ssize_t show_tx_maxrate(struct netdev_queue *queue,
970 struct netdev_queue_attribute *attribute,
971 char *buf)
972{
973 return sprintf(buf, "%lu\n", queue->tx_maxrate);
974}
975
976static ssize_t set_tx_maxrate(struct netdev_queue *queue,
977 struct netdev_queue_attribute *attribute,
978 const char *buf, size_t len)
979{
980 struct net_device *dev = queue->dev;
981 int err, index = get_netdev_queue_index(queue);
982 u32 rate = 0;
983
984 err = kstrtou32(buf, 10, &rate);
985 if (err < 0)
986 return err;
987
988 if (!rtnl_trylock())
989 return restart_syscall();
990
991 err = -EOPNOTSUPP;
992 if (dev->netdev_ops->ndo_set_tx_maxrate)
993 err = dev->netdev_ops->ndo_set_tx_maxrate(dev, index, rate);
994
995 rtnl_unlock();
996 if (!err) {
997 queue->tx_maxrate = rate;
998 return len;
999 }
1000 return err;
1001}
1002
1003static struct netdev_queue_attribute queue_tx_maxrate =
1004 __ATTR(tx_maxrate, S_IRUGO | S_IWUSR,
1005 show_tx_maxrate, set_tx_maxrate);
1006#endif
1007
954static struct netdev_queue_attribute queue_trans_timeout = 1008static struct netdev_queue_attribute queue_trans_timeout =
955 __ATTR(tx_timeout, S_IRUGO, show_trans_timeout, NULL); 1009 __ATTR(tx_timeout, S_IRUGO, show_trans_timeout, NULL);
956 1010
@@ -1065,18 +1119,6 @@ static struct attribute_group dql_group = {
1065#endif /* CONFIG_BQL */ 1119#endif /* CONFIG_BQL */
1066 1120
1067#ifdef CONFIG_XPS 1121#ifdef CONFIG_XPS
1068static unsigned int get_netdev_queue_index(struct netdev_queue *queue)
1069{
1070 struct net_device *dev = queue->dev;
1071 unsigned int i;
1072
1073 i = queue - dev->_tx;
1074 BUG_ON(i >= dev->num_tx_queues);
1075
1076 return i;
1077}
1078
1079
1080static ssize_t show_xps_map(struct netdev_queue *queue, 1122static ssize_t show_xps_map(struct netdev_queue *queue,
1081 struct netdev_queue_attribute *attribute, char *buf) 1123 struct netdev_queue_attribute *attribute, char *buf)
1082{ 1124{
@@ -1153,6 +1195,7 @@ static struct attribute *netdev_queue_default_attrs[] = {
1153 &queue_trans_timeout.attr, 1195 &queue_trans_timeout.attr,
1154#ifdef CONFIG_XPS 1196#ifdef CONFIG_XPS
1155 &xps_cpus_attribute.attr, 1197 &xps_cpus_attribute.attr,
1198 &queue_tx_maxrate.attr,
1156#endif 1199#endif
1157 NULL 1200 NULL
1158}; 1201};