Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

John Fastabend and committed by
David S. Miller
822b3b2e b65885d2

+80 -12
+8
Documentation/ABI/testing/sysfs-class-net-queues
··· 24 24 Indicates the number of transmit timeout events seen by this 25 25 network interface transmit queue. 26 26 27 + What: /sys/class/<iface>/queues/tx-<queue>/tx_maxrate 28 + Date: March 2015 29 + KernelVersion: 4.1 30 + Contact: netdev@vger.kernel.org 31 + Description: 32 + A Mbps max-rate set for the queue, a value of zero means disabled, 33 + default is disabled. 34 + 27 35 What: /sys/class/<iface>/queues/tx-<queue>/xps_cpus 28 36 Date: November 2010 29 37 KernelVersion: 2.6.38
+9
Documentation/networking/scaling.txt
··· 421 421 with the CPU that processes transmit completions for that queue 422 422 (transmit interrupts). 423 423 424 + Per TX Queue rate limitation: 425 + ============================= 426 + 427 + These are rate-limitation mechanisms implemented by HW, where currently 428 + a max-rate attribute is supported, by setting a Mbps value to 429 + 430 + /sys/class/net/<dev>/queues/tx-<n>/tx_maxrate 431 + 432 + A value of zero means disabled, and this is the default. 424 433 425 434 Further Information 426 435 ===================
+8
include/linux/netdevice.h
··· 587 587 #ifdef CONFIG_BQL 588 588 struct dql dql; 589 589 #endif 590 + unsigned long tx_maxrate; 590 591 } ____cacheline_aligned_in_smp; 591 592 592 593 static inline int netdev_queue_numa_node_read(const struct netdev_queue *q) ··· 1023 1022 * be otherwise expressed by feature flags. The check is called with 1024 1023 * the set of features that the stack has calculated and it returns 1025 1024 * those the driver believes to be appropriate. 1025 + * int (*ndo_set_tx_maxrate)(struct net_device *dev, 1026 + * int queue_index, u32 maxrate); 1027 + * Called when a user wants to set a max-rate limitation of specific 1028 + * TX queue. 1026 1029 */ 1027 1030 struct net_device_ops { 1028 1031 int (*ndo_init)(struct net_device *dev); ··· 1183 1178 netdev_features_t (*ndo_features_check) (struct sk_buff *skb, 1184 1179 struct net_device *dev, 1185 1180 netdev_features_t features); 1181 + int (*ndo_set_tx_maxrate)(struct net_device *dev, 1182 + int queue_index, 1183 + u32 maxrate); 1186 1184 }; 1187 1185 1188 1186 /**
+55 -12
net/core/net-sysfs.c
··· 951 951 return sprintf(buf, "%lu", trans_timeout); 952 952 } 953 953 954 + #ifdef CONFIG_XPS 955 + static 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 + 969 + static 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 + 976 + static 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 + 1003 + static 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 + 954 1008 static struct netdev_queue_attribute queue_trans_timeout = 955 1009 __ATTR(tx_timeout, S_IRUGO, show_trans_timeout, NULL); 956 1010 ··· 1119 1065 #endif /* CONFIG_BQL */ 1120 1066 1121 1067 #ifdef CONFIG_XPS 1122 - static unsigned int get_netdev_queue_index(struct netdev_queue *queue) 1123 - { 1124 - struct net_device *dev = queue->dev; 1125 - unsigned int i; 1126 - 1127 - i = queue - dev->_tx; 1128 - BUG_ON(i >= dev->num_tx_queues); 1129 - 1130 - return i; 1131 - } 1132 - 1133 - 1134 1068 static ssize_t show_xps_map(struct netdev_queue *queue, 1135 1069 struct netdev_queue_attribute *attribute, char *buf) 1136 1070 { ··· 1195 1153 &queue_trans_timeout.attr, 1196 1154 #ifdef CONFIG_XPS 1197 1155 &xps_cpus_attribute.attr, 1156 + &queue_tx_maxrate.attr, 1198 1157 #endif 1199 1158 NULL 1200 1159 };