Skip to content

Commit 8d059b0

Browse files
Alexander Duyckdavem330
authored andcommitted
net: Add sysfs value to determine queue traffic class
Add a sysfs attribute for a Tx queue that allows us to determine the traffic class for a given queue. This will allow us to more easily determine this in the future. It is needed as XPS will take the traffic class for a group of queues into account in order to avoid pulling traffic from one traffic class into another. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9cf1f6a commit 8d059b0

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,7 @@ int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
19201920
return 0;
19211921
}
19221922

1923+
int netdev_txq_to_tc(struct net_device *dev, unsigned int txq);
19231924
void netdev_reset_tc(struct net_device *dev);
19241925
int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset);
19251926
int netdev_set_num_tc(struct net_device *dev, u8 num_tc);

net/core/dev.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,23 @@ static void netif_setup_tc(struct net_device *dev, unsigned int txq)
19481948
}
19491949
}
19501950

1951+
int netdev_txq_to_tc(struct net_device *dev, unsigned int txq)
1952+
{
1953+
if (dev->num_tc) {
1954+
struct netdev_tc_txq *tc = &dev->tc_to_txq[0];
1955+
int i;
1956+
1957+
for (i = 0; i < TC_MAX_QUEUE; i++, tc++) {
1958+
if ((txq - tc->offset) < tc->count)
1959+
return i;
1960+
}
1961+
1962+
return -1;
1963+
}
1964+
1965+
return 0;
1966+
}
1967+
19511968
#ifdef CONFIG_XPS
19521969
static DEFINE_MUTEX(xps_map_mutex);
19531970
#define xmap_dereference(P) \

net/core/net-sysfs.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,6 @@ static ssize_t show_trans_timeout(struct netdev_queue *queue,
10241024
return sprintf(buf, "%lu", trans_timeout);
10251025
}
10261026

1027-
#ifdef CONFIG_XPS
10281027
static unsigned int get_netdev_queue_index(struct netdev_queue *queue)
10291028
{
10301029
struct net_device *dev = queue->dev;
@@ -1036,6 +1035,21 @@ static unsigned int get_netdev_queue_index(struct netdev_queue *queue)
10361035
return i;
10371036
}
10381037

1038+
static ssize_t show_traffic_class(struct netdev_queue *queue,
1039+
struct netdev_queue_attribute *attribute,
1040+
char *buf)
1041+
{
1042+
struct net_device *dev = queue->dev;
1043+
int index = get_netdev_queue_index(queue);
1044+
int tc = netdev_txq_to_tc(dev, index);
1045+
1046+
if (tc < 0)
1047+
return -EINVAL;
1048+
1049+
return sprintf(buf, "%u\n", tc);
1050+
}
1051+
1052+
#ifdef CONFIG_XPS
10391053
static ssize_t show_tx_maxrate(struct netdev_queue *queue,
10401054
struct netdev_queue_attribute *attribute,
10411055
char *buf)
@@ -1078,6 +1092,9 @@ static struct netdev_queue_attribute queue_tx_maxrate =
10781092
static struct netdev_queue_attribute queue_trans_timeout =
10791093
__ATTR(tx_timeout, S_IRUGO, show_trans_timeout, NULL);
10801094

1095+
static struct netdev_queue_attribute queue_traffic_class =
1096+
__ATTR(traffic_class, S_IRUGO, show_traffic_class, NULL);
1097+
10811098
#ifdef CONFIG_BQL
10821099
/*
10831100
* Byte queue limits sysfs structures and functions.
@@ -1263,6 +1280,7 @@ static struct netdev_queue_attribute xps_cpus_attribute =
12631280

12641281
static struct attribute *netdev_queue_default_attrs[] = {
12651282
&queue_trans_timeout.attr,
1283+
&queue_traffic_class.attr,
12661284
#ifdef CONFIG_XPS
12671285
&xps_cpus_attribute.attr,
12681286
&queue_tx_maxrate.attr,

0 commit comments

Comments
 (0)