TSN: Add qdisc based config interface for CBS
Subsystems (5)
Vinicius Costa Gomes
maintainerv7 cover TSN: Add qdisc based config interface for CBS
Hi,
Changes since v6:
- Fixed compilation for 32bit arches;
- Aligned the behaviour of .select_queue() of the mq qdisc to be the same as mqprio;
Changes since v5:
- Fixed comments from Jiri Pirko;
Changes since v4:
- Added a software implementation of the CBS algorithm;
Changes since v3:
- None, only a clean patchset without old patches;
Changes since v2:
- squashed the patch introducing the userspace API into the patch implementing CBS;
Changes since v1:
- Solved the mqprio dependency;
- Fixed a mqprio bug, that caused the inner qdisc to have a wrong dev_queue associated with it;
Changes from the RFC:
- Fixed comments from Henrik Austad;
- Simplified the Qdisc, using the generic implementation of callbacks where possible;
- Small refactor on the driver (igb) code;
This patchset is a proposal of how the Traffic Control subsystem can be used to offload the configuration of the Credit Based Shaper (defined in the IEEE 802.1Q-2014 Section 8.6.8.2) into supported network devices.
As part of this work, we've assessed previous public discussions related to TSN enabling: patches from Henrik Austad (Cisco), the presentation from Eric Mann at Linux Plumbers 2012, patches from Gangfeng Huang (National Instruments) and the current state of the OpenAVNU project (https://github.com/AVnu/OpenAvnu/).
Overview
========
Time-sensitive Networking (TSN) is a set of standards that aim to address resources availability for providing bandwidth reservation and bounded latency on Ethernet based LANs. The proposal described here aims to cover mainly what is needed to enable the following standards:
802.1Qat and 802.1Qav.
The initial target of this work is the Intel i210 NIC, but other controllers' datasheet were also taken into account, like the Renesas RZ/A1H RZ/A1M group and the Synopsis DesignWare Ethernet QoS controller.
Proposal
========
Feature-wise, what is covered here is the configuration interfaces for HW implementations of the Credit-Based shaper (CBS, 802.1Qav). CBS is a per-queue shaper. Given that this feature is related to traffic shaping, and that the traffic control subsystem already provides a queueing discipline that offloads config into the device driver (i.e. mqprio), designing a new qdisc for the specific purpose of offloading the config for the CBS shaper seemed like a good fit.
For steering traffic into the correct queues, we use the socket option SO_PRIORITY and then a mechanism to map priority to traffic classes / Tx queues. The qdisc mqprio is currently used in our tests.
As for the CBS config interface, this patchset is proposing a new qdisc called 'cbs'. Its 'tc' cmd line is:
$ tc qdisc add dev IFACE parent ID cbs locredit N hicredit M sendslope S \
idleslope INote that the parameters for this qdisc are the ones defined by the 802.1Q-2014 spec, so no hardware specific functionality is exposed here.
Per-stream shaping, as defined by IEEE 802.1Q-2014 Section 34.6.1, is not yet covered by this proposal.
Testing this RFC
================
Attached to this cover letter are:
- calculate_cbs_params.py: A Python script to calculate the parameters to the CBS queueing discipline;
- tsn-talker.c: A sample C implementation of the talker side of a stream;
- tsn-listener.c: A sample C implementation of the listener side of a stream;
For testing the patches of this series, you may want to use the attached samples to this cover letter and use the 'mqprio' qdisc to setup the priorities to Tx queues mapping, together with the 'cbs' qdisc to configure the HW shaper of the i210 controller:
1) Setup priorities to traffic classes to hardware queues mapping
$ tc qdisc replace dev ens4 handle 100: parent root mqprio num_tc 3 \
map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 queues 1 at 0 1 at 1 2 at 2 hw 0For a more detailed explanation, see mqprio(8), in short, this command will map traffic with priority 3 to the hardware queue 0, traffic with priority 2 to hardware queue 1, and the rest will be mapped to hardware queues 2 and 3.
2) Check scheme. You want to get the inner qdiscs ID from the bottom up
$ tc -g class show dev ens4
Ex.:
+---(100:3) mqprio
| +---(100:6) mqprio
| +---(100:7) mqprio
|
+---(100:2) mqprio
| +---(100:5) mqprio
|
+---(100:1) mqprio
+---(100:4) mqprio* Here '100:4' is Tx Queue #0 and '100:5' is Tx Queue #1.
3) Calculate CBS parameters for classes A and B. i.e. BW for A is 20Mbps and for B is 10Mbps:
$ calc_cbs_params.py -A 20000 -a 1500 -B 10000 -b 1500
4) Configure CBS for traffic class A (priority 3) as provided by the script:
$ tc qdisc replace dev ens4 parent 100:4 cbs locredit -1470 \
hicredit 30 sendslope -980000 idleslope 200005) Configure CBS for traffic class B (priority 2):
$ tc qdisc replace dev ens4 parent 100:5 cbs \
locredit -1485 hicredit 31 sendslope -990000 idleslope 100006) Run Listener:
$ ./tsn-listener -d 01:AA:AA:AA:AA:AA -i ens4 -s 1500
7) Run Talker for class A (prio 3 here), compiled from samples/tsn/talker.c
$ ./tsn-talker -d 01:AA:AA:AA:AA:AA -i ens4 -p 3 -s 1500
* The bandwidth displayed on the listener output at this stage should be very close to the one configured for class A.
8) You can also run a Talker for class B (prio 2 here and using a different address):
$ ./tsn-talker -d 01:BB:BB:BB:BB:BB -i ens4 -p 2 -s 1500
Authors
=======
- Andre Guedes <[email protected]>
- Ivan Briano <[email protected]>
- Jesus Sanchez-Palencia <[email protected]>
- Vinicius Gomes <[email protected]>
Andre Guedes (1):
igb: Add support for CBS offload
Jesus Sanchez-Palencia (3):
net/sched: Check for null dev_queue on create flow net/sched: Change behavior of mq select_queue() net/sched: Add select_queue() class_ops for mqprio
Vinicius Costa Gomes (2):
net/sched: Introduce Credit Based Shaper (CBS) qdisc net/sched: Add support for HW offloading for CBS
drivers/net/ethernet/intel/igb/e1000_defines.h | 23 ++ drivers/net/ethernet/intel/igb/e1000_regs.h | 8 + drivers/net/ethernet/intel/igb/igb.h | 6 + drivers/net/ethernet/intel/igb/igb_main.c | 347 ++++++++++++++++++++++ include/linux/netdevice.h | 1 + include/net/pkt_sched.h | 9 + include/uapi/linux/pkt_sched.h | 18 ++ net/sched/Kconfig | 11 + net/sched/Makefile | 1 + net/sched/sch_cbs.c | 394 +++++++++++++++++++++++++ net/sched/sch_generic.c | 8 +- net/sched/sch_mq.c | 10 +- net/sched/sch_mqprio.c | 7 + 13 files changed, 833 insertions(+), 10 deletions(-) create mode 100644 net/sched/sch_cbs.c
Annex: Sample files
===================
calc_cbs_params.py
--8<---------------cut here---------------start------------->8--- #!/usr/bin/env python
#
# Copyright (c) 2017, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Intel Corporation nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import argparse
import math
def print_cbs_params_for_class_a(args):
idleslope = args.idleslope_a
sendslope = idleslope - args.link_speed
# According to 802.1Q-2014 spec, Annex L, hiCredit and
# loCredit for SR class A are calculated following the
# equations L-10 and L-12, respectively.
hicredit = math.ceil(idleslope * args.frame_non_sr / args.link_speed) locredit = math.ceil(sendslope * args.frame_a / args.link_speed)
print("tc qdisc add dev <IFNAME> parent <QDISC-ID> cbs idleslope %d sendslope %d hicredit %d locredit %d" % \
(idleslope, sendslope, hicredit, locredit))
def print_cbs_params_for_class_b(args):
idleslope = args.idleslope_b
sendslope = idleslope - args.link_speed
# Annex L doesn't present a straightforward equation to
# calculate hiCredit for Class B so we have to derive it
# based on generic equations presented in that Annex.
#
# L-3 is the primary equation to calculate hiCredit. Section # L.2 states that the 'maxInterferenceSize' for SR class B
# is the maximum burst size for SR class A plus the
# maxInterferenceSize from SR class A (which is equal to the # maximum frame from non-SR traffic).
#
# The maximum burst size for SR class A equation is shown in # L-16. Merging L-16 into L-3 we get the resulting equation
# which calculates hiCredit B (refer to section L.3 in case
# you're not familiar with the legend):
#
# hiCredit B = Rb * ( Mo Ma )
# ---------- + ------
# Ro - Ra Ro
#
hicredit = math.ceil(idleslope * \
((args.frame_non_sr / (args.link_speed - args.idleslope_a)) + \
(args.frame_a / args.link_speed)))
# loCredit B is calculated following equation L-2. locredit = math.ceil(sendslope * args.frame_b / args.link_speed)
print("tc qdisc add dev <IFNAME> parent <QDISC-ID> cbs idleslope %d sendslope %d hicredit %d locredit %d" % \
(idleslope, sendslope, hicredit, locredit))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-S', dest='link_speed', default=1000000.0, type=float,
help='Link speed in kbps')
parser.add_argument('-s', dest='frame_non_sr', default=1500.0, type=float,
help='Maximum frame size from non-SR traffic (MTU size' 'usually')
parser.add_argument('-A', dest='idleslope_a', default=0, type=float,
help='Idleslope for SR class A in kbps')
parser.add_argument('-a', dest='frame_a', default=0, type=float,
help='Maximum frame size for SR class A traffic')
parser.add_argument('-B', dest='idleslope_b', default=0, type=float,
help='Idleslope for SR class B in kbps')
parser.add_argument('-b', dest='frame_b', default=0, type=float,
help='Maximum frame size for SR class B traffic')
args = parser.parse_args()
if args.idleslope_a > 0:
print_cbs_params_for_class_a(args)
if args.idleslope_b > 0:
print_cbs_params_for_class_b(args)
if __name__ == "__main__":
main()
--8<---------------cut here---------------end--------------->8---
tsn-talker.c
--8<---------------cut here---------------start------------->8--- /*
* Copyright (c) 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <alloca.h>
#include <argp.h>
#include <arpa/inet.h>
#include <inttypes.h>
#include <linux/if.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#define MAGIC 0xCC
static uint8_t ifname[IFNAMSIZ];
static uint8_t macaddr[ETH_ALEN];
static int priority = -1;
static size_t size = 1500;
static uint64_t seq;
static int delay = -1;
static struct argp_option options[] = {
{"dst-addr", 'd', "MACADDR", 0, "Stream Destination MAC address" },
{"delay", 'D', "NUM", 0, "Delay (in us) between packet transmission" },
{"ifname", 'i', "IFNAME", 0, "Network Interface" },
{"prio", 'p', "NUM", 0, "SO_PRIORITY to be set in socket" },
{"packet-size", 's', "NUM", 0, "Size of packets to be transmitted" },
{ 0 }
};static error_t parser(int key, char *arg, struct argp_state *state)
{
int res;
switch (key) {
case 'd':
res = sscanf(arg, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
&macaddr[0], &macaddr[1], &macaddr[2],
&macaddr[3], &macaddr[4], &macaddr[5]);
if (res != 6) {
printf("Invalid address\n");
exit(EXIT_FAILURE);
}
break;
case 'D':
delay = atoi(arg);
break;
case 'i':
strncpy(ifname, arg, sizeof(ifname) - 1);
break;
case 'p':
priority = atoi(arg);
break;
case 's':
size = atoi(arg);
break;
}
return 0;
}static struct argp argp = { options, parser };
int main(int argc, char *argv[])
{
int fd, res;
struct ifreq req;
uint8_t *data;
struct sockaddr_ll sk_addr = {
.sll_family = AF_PACKET,
.sll_protocol = htons(ETH_P_TSN),
.sll_halen = ETH_ALEN,
};
argp_parse(&argp, argc, argv, 0, NULL, NULL);
fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_TSN));
if (fd < 0) {
perror("Couldn't open socket");
return 1;
}
strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
res = ioctl(fd, SIOCGIFINDEX, &req);
if (res < 0) {
perror("Couldn't get interface index");
goto err;
}
sk_addr.sll_ifindex = req.ifr_ifindex;
memcpy(&sk_addr.sll_addr, macaddr, ETH_ALEN);
if (priority != -1) {
res = setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority,
sizeof(priority));
if (res < 0) {
perror("Couldn't set priority");
goto err;
}
}
data = alloca(size);
memset(data, MAGIC, size);
printf("Sending packets...\n");
while (1) {
uint64_t *seq_ptr = (uint64_t *) &data[0];
ssize_t n;
*seq_ptr = seq++;
n = sendto(fd, data, size, 0, (struct sockaddr *) &sk_addr,
sizeof(sk_addr));
if (n < 0)
perror("Failed to send data");
if (delay > 0)
usleep(delay);
}
close(fd);
return 0;err:
close(fd); return 1; }
--8<---------------cut here---------------end--------------->8---
tsn-listener.c
--8<---------------cut here---------------start------------->8--- /*
* Copyright (c) 2017, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <alloca.h>
#include <argp.h>
#include <arpa/inet.h>
#include <inttypes.h>
#include <linux/if.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <poll.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/timerfd.h>
#include <unistd.h>
static uint8_t ifname[IFNAMSIZ];
static uint8_t macaddr[ETH_ALEN];
static uint64_t data_count;
static int size = 1500;
static time_t interval = 1;
static bool check_seq = false;
static uint64_t expected_seq;
static struct argp_option options[] = {
{"check-seq", 'c', NULL, 0, "Check sequence number within packet" },
{"dst-addr", 'd', "MACADDR", 0, "Stream Destination MAC address" },
{"ifname", 'i', "IFNAME", 0, "Network Interface" },
{"interval", 'I', "SEC", 0, "Interval between bandwidth reports" },
{"packet-size", 's', "NUM", 0, "Expected packet size" },
{ 0 }
};static error_t parser(int key, char *arg, struct argp_state *state)
{
int res;
switch (key) {
case 'c':
check_seq = true;
break;
case 'd':
res = sscanf(arg, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
&macaddr[0], &macaddr[1], &macaddr[2],
&macaddr[3], &macaddr[4], &macaddr[5]);
if (res != 6) {
printf("Invalid address\n");
exit(EXIT_FAILURE);
}
break;
case 'i':
strncpy(ifname, arg, sizeof(ifname) - 1);
break;
case 'I':
interval = atoi(arg);
break;
case 's':
size = atoi(arg);
break;
}
return 0;
}static struct argp argp = { options, parser };
static int setup_timer(void)
{
int fd, res;
struct itimerspec tspec = { 0 };
fd = timerfd_create(CLOCK_MONOTONIC, 0);
if (fd < 0) {
perror("Couldn't create timer");
return -1;
}
tspec.it_value.tv_sec = interval;
tspec.it_interval.tv_sec = interval;
res = timerfd_settime(fd, 0, &tspec, NULL);
if (res < 0) {
perror("Couldn't set timer");
close(fd);
return -1;
}
return fd;
}static int setup_socket(void)
{
int fd, res;
struct sockaddr_ll sk_addr = {
.sll_family = AF_PACKET,
.sll_protocol = htons(ETH_P_TSN),
};
fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_TSN));
if (fd < 0) {
perror("Couldn't open socket");
return -1;
}
/* If user provided a network interface, bind() to it. */
if (ifname[0] != '\0') {
struct ifreq req;
strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
res = ioctl(fd, SIOCGIFINDEX, &req);
if (res < 0) {
perror("Couldn't get interface index");
goto err;
}
sk_addr.sll_ifindex = req.ifr_ifindex;
res = bind(fd, (struct sockaddr *) &sk_addr, sizeof(sk_addr));
if (res < 0) {
perror("Couldn't bind() to interface");
goto err;
}
}
/* If user provided the stream destination address, set it as multicast
* address.
*/
if (macaddr[0] != '\0') {
struct packet_mreq mreq;
mreq.mr_ifindex = sk_addr.sll_ifindex;
mreq.mr_type = PACKET_MR_MULTICAST;
mreq.mr_alen = ETH_ALEN;
memcpy(&mreq.mr_address, macaddr, ETH_ALEN);
res = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP,
&mreq, sizeof(struct packet_mreq));
if (res < 0) {
perror("Couldn't set PACKET_ADD_MEMBERSHIP");
goto err;
}
}
return fd;err:
close(fd); return -1; }
static void recv_packet(int fd)
{
uint8_t *data = alloca(size);
ssize_t n = recv(fd, data, size, 0);
if (n < 0) {
perror("Failed to receive data");
return;
}
if (n != size)
printf("Size mismatch: expected %d, got %d\n", size, n);
if (check_seq) {
uint64_t *seq = (uint64_t *) &data[0];
/* If 'expected_seq' is equal to zero, it means this is the
* first packet we received so we don't know what sequence
* number to expect.
*/
if (expected_seq == 0)
expected_seq = *seq;
if (*seq != expected_seq) {
printf("Sequence mismatch: expected %llu, got %llu\n",
expected_seq, *seq);
expected_seq = *seq;
}
expected_seq++;
}
data_count += n;
}static void report_bw(int fd)
{
uint64_t expirations;
ssize_t n = read(fd, &expirations, sizeof(uint64_t));
if (n < 0) {
perror("Couldn't read timerfd");
return;
}
if (expirations != 1)
printf("Some went wrong with timerfd\n");
printf("Receiving data rate: %llu kbps\n", (data_count * 8) / (1000 * interval));
data_count = 0;
}int main(int argc, char *argv[])
{
int sk_fd, timer_fd, res;
struct pollfd fds[2];
argp_parse(&argp, argc, argv, 0, NULL, NULL);
sk_fd = setup_socket();
if (sk_fd < 0)
return 1;
timer_fd = setup_timer();
if (timer_fd < 0) {
close(sk_fd);
return 1;
}
fds[0].fd = sk_fd;
fds[0].events = POLLIN;
fds[1].fd = timer_fd;
fds[1].events = POLLIN;
printf("Waiting for packets...\n");
while (1) {
res = poll(fds, 2, -1);
if (res < 0) {
perror("Error on poll()");
goto err;
}
if (fds[0].revents & POLLIN)
recv_packet(fds[0].fd);
if (fds[1].revents & POLLIN) {
report_bw(fds[1].fd);
}
}
close(timer_fd);
close(sk_fd);
return 0;err:
close(timer_fd); close(sk_fd); return 1; }
--8<---------------cut here---------------end--------------->8---
--
2.14.2
Vinicius Costa Gomes
maintainerPATCH v7 1/6 net/sched: Check for null dev_queue on create flow
From: Jesus Sanchez-Palencia <[email protected]>
In qdisc_alloc() the dev_queue pointer was used without any checks being performed. If qdisc_create() gets a null dev_queue pointer, it just passes it along to qdisc_alloc(), leading to a crash. That happens if a root qdisc implements select_queue() and returns a null dev_queue pointer for an "invalid handle", for example, or if the dev_queue associated with the parent qdisc is null.
This patch is in preparation for the next in this series, where select_queue() is being added to mqprio and as it may return a null dev_queue.
--- net/sched/sch_generic.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/sched/sch_generic.c +7 -1
@@ -603,8 +603,14 @@ struct Qdisc *qdisc_alloc(struct netdev_queue *dev_queue,struct Qdisc *sch;unsigned int size =QDISC_ALIGN (sizeof (*sch)) + ops->priv_size;int err = -ENOBUFS ; -struct net_device *dev = dev_queue->dev; +struct net_device *dev; + +if (!dev_queue) { + err = -EINVAL ; + goto errout; + } + dev = dev_queue->dev; p =kzalloc_node (size,GFP_KERNEL ,netdev_queue_numa_node_read (dev_queue));
Signature · 1 line
2.14.2
Vinicius Costa Gomes
maintainerPATCH v7 2/6 net/sched: Change behavior of mq select_queue()
In reply to Vinicius Costa GomesFrom: Jesus Sanchez-Palencia <[email protected]>
Currently, the class_ops select_queue() implementation on sch_mq returns a pointer to netdev_queue #0 when it receives and invalid qdisc id. That can be misleading since all of mq's inner qdiscs are attached to a valid netdev_queue.
Here we fix that by returning NULL when a qdisc id is invalid. This is aligned with how select_queue() is implemented for sch_mqprio in the next patch on this series, keeping a consistent behavior between these two qdiscs.
--- net/sched/sch_mq.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
net/sched/sch_mq.c +1 -9
@@ -130,15 +130,7 @@ static struct netdev_queue *mq_queue_get(struct Qdisc *sch, unsigned long cl)static struct netdev_queue *mq_select_queue (struct Qdisc *sch,struct tcmsg *tcm) { -unsigned int ntx =TC_H_MIN (tcm->tcm_parent); -struct netdev_queue *dev_queue =mq_queue_get (sch, ntx); - -if (!dev_queue) { -struct net_device *dev =qdisc_dev (sch); - -return netdev_get_tx_queue (dev,0 ); - } -return dev_queue; +return mq_queue_get (sch,TC_H_MIN (tcm->tcm_parent)); } static int mq_graft(struct Qdisc *sch, unsigned long cl, struct Qdisc *new,
Signature · 1 line
2.14.2
Vinicius Costa Gomes
maintainerPATCH v7 3/6 net/sched: Add select_queue() class_ops for mqprio
In reply to Vinicius Costa GomesFrom: Jesus Sanchez-Palencia <[email protected]>
When replacing a child qdisc from mqprio, tc_modify_qdisc() must fetch the netdev_queue pointer that the current child qdisc is associated with before creating the new qdisc.
Currently, when using mqprio as root qdisc, the kernel will end up getting the queue #0 pointer from the mqprio (root qdisc), which leaves any new child qdisc with a possibly wrong netdev_queue pointer.
Implementing the Qdisc_class_ops select_queue() on mqprio fixes this issue and avoid an inconsistent state when child qdiscs are replaced.
--- net/sched/sch_mqprio.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/sched/sch_mqprio.c +7 -0
@@ -396,6 +396,12 @@ static void mqprio_walk(struct Qdisc *sch, struct qdisc_walker *arg) } } +static struct netdev_queue *mqprio_select_queue (struct Qdisc *sch, +struct tcmsg *tcm) +{ +return mqprio_queue_get (sch,TC_H_MIN (tcm->tcm_parent)); +} +static const struct Qdisc_class_ops mqprio_class_ops = { .graft = mqprio_graft, .leaf = mqprio_leaf,
@@ -403,6 +409,7 @@ static const struct Qdisc_class_ops mqprio_class_ops = { .walk = mqprio_walk, .dump = mqprio_dump_class, .dump_stats = mqprio_dump_class_stats, + .select_queue = mqprio_select_queue, };static struct Qdisc_ops mqprio_qdisc_ops__read_mostly = {
Signature · 1 line
2.14.2
Vinicius Costa Gomes
maintainerPATCH v7 4/6 net/sched: Introduce Credit Based Shaper (CBS) qdisc
In reply to Vinicius Costa GomesThis queueing discipline implements the shaper algorithm defined by the 802.1Q-2014 Section 8.6.8.2 and detailed in Annex L.
It's primary usage is to apply some bandwidth reservation to user defined traffic classes, which are mapped to different queues via the mqprio qdisc.
Only a simple software implementation is added for now.
--- include/uapi/linux/pkt_sched.h | 18 +++ net/sched/Kconfig | 11 ++ net/sched/Makefile | 1 + net/sched/sch_cbs.c | 314 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 344 insertions(+) create mode 100644 net/sched/sch_cbs.c
include/uapi/linux/pkt_sched.h +18 -0
@@ -871,4 +871,22 @@ struct tc_pie_xstats {__u32 maxq;/* maximum queue size */ __u32 ecn_mark; /* packets marked with ecn*/ }; + +/* CBS */ +struct tc_cbs_qopt { +__u8 offload; +__s32 hicredit; +__s32 locredit; +__s32 idleslope; +__s32 sendslope; +}; + +enum { +TCA_CBS_UNSPEC , +TCA_CBS_PARMS , + __TCA_CBS_MAX, +}; + +#define TCA_CBS_MAX (__TCA_CBS_MAX - 1) +#endif
net/sched/Kconfig +11 -0
@@ -172,6 +172,17 @@ config NET_SCH_TBF To compile this code as a module, choose M here: the module will be called sch_tbf. +config NET_SCH_CBS + tristate "Credit Based Shaper (CBS)" + ---help--- + Say Y here if you want to use the Credit Based Shaper (CBS) packet + scheduling algorithm. + + See the top of <file:net/sched/sch_cbs.c> for more details. + + To compile this code as a module, choose M here: the + module will be called sch_cbs. + config NET_SCH_GRED tristate "Generic Random Early Detection (GRED)" ---help---
net/sched/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_NET_SCH_FQ_CODEL) += sch_fq_codel.o obj-$(CONFIG_NET_SCH_FQ) += sch_fq.o obj-$(CONFIG_NET_SCH_HHF) += sch_hhf.o obj-$(CONFIG_NET_SCH_PIE) += sch_pie.o +obj-$(CONFIG_NET_SCH_CBS) += sch_cbs.o obj-$(CONFIG_NET_CLS_U32) += cls_u32.o obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.o
net/sched/sch_cbs.c new file +314 -0
314 lines not on this page · raw message
Signature · 1 line
2.14.2
Re: [next-queue PATCH v7 4/6] net/sched: Introduce Credit Based Shaper (CBS) qdisc
Quoted 45 lines · Vinicius Costa Gomes
This queueing discipline implements the shaper algorithm defined by the 802.1Q-2014 Section 8.6.8.2 and detailed in Annex L.
It's primary usage is to apply some bandwidth reservation to user defined traffic classes, which are mapped to different queues via the mqprio qdisc.
Only a simple software implementation is added for now.
Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Jesus Sanchez-Palencia <[email protected]>---
net/sched/sch_cbs.c new file +32
-0+/* timediff is in ns, slope is in kbps */ +static s64 timediff_to_credits (s64 timediff,s32 slope) +{ +s64 credits = timediff * slope *BYTES_PER_KBIT ; + +do_div (credits,NSEC_PER_SEC ); + +return credits; +} + +static s64 delay_from_credits (s64 credits,s32 slope) +{ +s64 rate = slope *BYTES_PER_KBIT ; +s64 delay; + +if (unlikely (rate ==0 )) +return S64_MAX ; + + delay = -credits *NSEC_PER_SEC ; +do_div (delay, rate); + +return delay; +} + +static s64 credits_from_len (unsigned int len,s32 slope,s64 port_rate) +{ +/* As do_div() only works on unsigned quantities, convert +* slope to a positive number here, and credits to a negative +* number before returning. +*/ +s64 rate = -slope *BYTES_PER_KBIT ; +s64 credits;
net/sched/sch_cbs.c line 148
Quoted 10 lines
net/sched/sch_cbs.c new file +10
-0+ +if (unlikely (port_rate ==0 )) +return S64_MAX ; + + credits = len * rate; +do_div (credits, port_rate); + +return -credits; +} +
Your mixing of s64 and u64 is disturbing.
do_div() handles u64, not s64.
div64_s64() might be needed in place of do_div()
Vinicius Costa Gomes
maintainerRe: [next-queue PATCH v7 4/6] net/sched: Introduce Credit Based Shaper (CBS) qdisc
Hi,
Eric Dumazet <[email protected]> writes:
[...]
Quoted 6 lines
Your mixing of s64 and u64 is disturbing.
do_div()handles u64, not s64.
div64_s64()might be needed in place ofdo_div()
I wasn't very comfortable about the signal juggling either. Didn't know about div64_s64(), looks much better. Will fix, thanks.
Cheers,
--
Vinicius
Re: [next-queue PATCH v7 4/6] net/sched: Introduce Credit Based Shaper (CBS) qdisc
In reply to Vinicius Costa GomesQuoted 165 lines · Vinicius Costa Gomes
This queueing discipline implements the shaper algorithm defined by the 802.1Q-2014 Section 8.6.8.2 and detailed in Annex L.
It's primary usage is to apply some bandwidth reservation to user defined traffic classes, which are mapped to different queues via the mqprio qdisc.
Only a simple software implementation is added for now.
Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Jesus Sanchez-Palencia <[email protected]>--- include/uapi/linux/pkt_sched.h | 18 +++ net/sched/Kconfig | 11 ++ net/sched/Makefile | 1 + net/sched/sch_cbs.c | 314 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 344 insertions(+) create mode 100644 net/sched/sch_cbs.cinclude/uapi/linux/pkt_sched.h +18
-0@@ -871,4 +871,22 @@ struct tc_pie_xstats {__u32 maxq;/* maximum queue size */ __u32 ecn_mark; /* packets marked with ecn*/ }; + +/* CBS */ +struct tc_cbs_qopt { +__u8 offload; +__s32 hicredit; +__s32 locredit; +__s32 idleslope; +__s32 sendslope; +}; + +enum { +TCA_CBS_UNSPEC , +TCA_CBS_PARMS , + __TCA_CBS_MAX, +}; + +#define TCA_CBS_MAX (__TCA_CBS_MAX - 1) +#endif net/sched/Kconfig +11
-0@@ -172,6 +172,17 @@ config NET_SCH_TBF To compile this code as a module, choose M here: the module will be called sch_tbf. +config NET_SCH_CBS + tristate "Credit Based Shaper (CBS)" + ---help--- + Say Y here if you want to use the Credit Based Shaper (CBS) packet + scheduling algorithm. + + See the top of <file:net/sched/sch_cbs.c> for more details. + + To compile this code as a module, choose M here: the + module will be called sch_cbs. + config NET_SCH_GRED tristate "Generic Random Early Detection (GRED)" ---help---net/sched/Makefile +1
-0@@ -52,6 +52,7 @@ obj-$(CONFIG_NET_SCH_FQ_CODEL) += sch_fq_codel.o obj-$(CONFIG_NET_SCH_FQ) += sch_fq.o obj-$(CONFIG_NET_SCH_HHF) += sch_hhf.o obj-$(CONFIG_NET_SCH_PIE) += sch_pie.o +obj-$(CONFIG_NET_SCH_CBS) += sch_cbs.o obj-$(CONFIG_NET_CLS_U32) += cls_u32.o obj-$(CONFIG_NET_CLS_ROUTE4) += cls_route.onet/sched/sch_cbs.c new file +79
-0@@ -0,0 +1,314 @@ +/* +* net/sched/sch_cbs.c Credit Based Shaper +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +* +* Authors: Vinicius Costa Gomes <[email protected]> +* +*/ + +/* Credit Based Shaper (CBS) +* ========================= +* +* This is a simple rate-limiting shaper aimed at TSN applications on +* systems with known traffic workloads. +* +* Its algorithm is defined by the IEEE 802.1Q-2014 Specification, +* Section 8.6.8.2, and explained in more detail in the Annex L of the +* same specification. +* +* There are four tunables to be considered: +* +* 'idleslope': Idleslope is the rate of credits that is +* accumulated (in kilobits per second) when there is at least +* one packet waiting for transmission. Packets are transmitted +* when the current value of credits is equal or greater than +* zero. When there is no packet to be transmitted the amount of +* credits is set to zero. This is the main tunable of the CBS +* algorithm. +* +* 'sendslope': +* Sendslope is the rate of credits that is depleted (it should be a +* negative number of kilobits per second) when a transmission is +* ocurring. It can be calculated as follows, (IEEE 802.1Q-2014 Section +* 8.6.8.2 item g): +* +* sendslope = idleslope - port_transmit_rate +* +* 'hicredit': Hicredit defines the maximum amount of credits (in +* bytes) that can be accumulated. Hicredit depends on the +* characteristics of interfering traffic, +* 'max_interference_size' is the maximum size of any burst of +* traffic that can delay the transmission of a frame that is +* available for transmission for this traffic class, (IEEE +* 802.1Q-2014 Annex L, Equation L-3): +* +* hicredit = max_interference_size * (idleslope / port_transmit_rate) +* +* 'locredit': Locredit is the minimum amount of credits that can +* be reached. It is a function of the traffic flowing through +* this qdisc (IEEE 802.1Q-2014 Annex L, Equation L-2): +* +* locredit = max_frame_size * (sendslope / port_transmit_rate) +*/ + +#include <linux/module.h> +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/string.h> +#include <linux/errno.h> +#include <linux/skbuff.h> +#include <net/netlink.h> +#include <net/sch_generic.h> +#include <net/pkt_sched.h> + +#define BYTES_PER_KBIT (1000 / 8) + +struct cbs_sched_data { +s64 port_rate;/* in bytes/s */ +s64 last;/* timestamp in ns */ +s64 credits;/* in bytes */ +s32 locredit;/* in bytes */ +s32 hicredit;/* in bytes */ +s32 sendslope;/* in kbits/s */ +s32 idleslope;/* in kbits/s */ +struct qdisc_watchdog watchdog; +int (*enqueue)(struct sk_buff *skb,struct Qdisc *sch);
net/sched/sch_cbs.c line 89
Quoted 10 lines
net/sched/sch_cbs.c new file +10
-0+struct sk_buff *(*dequeue)(struct Qdisc *sch); +}; + +static int cbs_enqueue_soft (struct sk_buff *skb,struct Qdisc *sch) +{ +struct cbs_sched_data *q =qdisc_priv (sch); + +if (sch->q.qlen ==0 && q->credits >0 ) { +/* We need to stop accumulating credits when there's +* no packet enqueued packets and q->credits is
no packet -> no
Quoted 59 lines
net/sched/sch_cbs.c new file +59
-0+* positive. +*/ + q->credits =0 ; + q->last =ktime_get_ns (); + } + +return qdisc_enqueue_tail (skb, sch); +} + +static int cbs_enqueue (struct sk_buff *skb,struct Qdisc *sch, +struct sk_buff **to_free) +{ +struct cbs_sched_data *q =qdisc_priv (sch); + +return q->enqueue (skb, sch); +} + +/* timediff is in ns, slope is in kbps */ +static s64 timediff_to_credits (s64 timediff,s32 slope) +{ +s64 credits = timediff * slope *BYTES_PER_KBIT ; + +do_div (credits,NSEC_PER_SEC ); + +return credits; +} + +static s64 delay_from_credits (s64 credits,s32 slope) +{ +s64 rate = slope *BYTES_PER_KBIT ; +s64 delay; + +if (unlikely (rate ==0 )) +return S64_MAX ; + + delay = -credits *NSEC_PER_SEC ; +do_div (delay, rate); + +return delay; +} + +static s64 credits_from_len (unsigned int len,s32 slope,s64 port_rate) +{ +/* As do_div() only works on unsigned quantities, convert +* slope to a positive number here, and credits to a negative +* number before returning. +*/ +s64 rate = -slope *BYTES_PER_KBIT ; +s64 credits; + +if (unlikely (port_rate ==0 )) +return S64_MAX ; + + credits = len * rate; +do_div (credits, port_rate); + +return -credits; +} +
net/sched/sch_cbs.c line 158
Quoted 10 lines
net/sched/sch_cbs.c new file +10
-0+static struct sk_buff *cbs_dequeue_soft (struct Qdisc *sch) +{ +struct cbs_sched_data *q =qdisc_priv (sch); +s64 now =ktime_get_ns (); +struct sk_buff *skb; +s64 credits; +int len; + +if (q->credits <0 ) { + credits =timediff_to_credits (now - q->last, q->idleslope);
Maybe be better to add small optimization by moving some calculations from data path, I mean, save idle_slope in bytes instead of kbit and converting it for every packet. Both delay_from_credits() and timediff_to_credits() is used only once and with idle_slope only...and both of them converting it.
Same for credits_from_len() and send slope, save it in units of port_rate.
Quoted 159 lines
net/sched/sch_cbs.c new file +156
-0+ + credits = q->credits + credits; + q->credits =min_t (s64, credits, q->hicredit); + +if (q->credits <0 ) { +s64 delay; + + delay =delay_from_credits (q->credits, q->idleslope); +qdisc_watchdog_schedule_ns (&q->watchdog, now + delay); + + q->last = now; + +return NULL ; + } + } + + skb =qdisc_dequeue_head (sch); +if (!skb) +return NULL ; + + len =qdisc_pkt_len (skb); + +/* As sendslope is a negative number, this will decrease the +* amount of q->credits. +*/ + credits =credits_from_len (len, q->sendslope, q->port_rate); + credits += q->credits; + + q->credits =max_t (s64, credits, q->locredit); + q->last = now; + +return skb; +} + +static struct sk_buff *cbs_dequeue (struct Qdisc *sch) +{ +struct cbs_sched_data *q =qdisc_priv (sch); + +return q->dequeue (sch); +} + +static const struct nla_policy cbs_policy[TCA_CBS_MAX +1 ] = { + [TCA_CBS_PARMS ] = { .len =sizeof (struct tc_cbs_qopt ) }, +}; + +static int cbs_change (struct Qdisc *sch,struct nlattr *opt) +{ +struct cbs_sched_data *q =qdisc_priv (sch); +struct net_device *dev =qdisc_dev (sch); +struct nlattr *tb[TCA_CBS_MAX +1 ]; +struct ethtool_link_ksettings ecmd; +struct tc_cbs_qopt *qopt; +s64 link_speed; +int err; + + err =nla_parse_nested (tb,TCA_CBS_MAX , opt, cbs_policy,NULL ); +if (err <0 ) +return err; + +if (!tb[TCA_CBS_PARMS ]) +return -EINVAL ; + + qopt =nla_data (tb[TCA_CBS_PARMS ]); + +if (qopt->offload) +return -EOPNOTSUPP ; + +if (!__ethtool_get_link_ksettings (dev, &ecmd)) + link_speed = ecmd.base.speed; +else + link_speed =SPEED_1000 ; + + q->port_rate = link_speed *1000 *BYTES_PER_KBIT ; + + q->enqueue = cbs_enqueue_soft; + q->dequeue = cbs_dequeue_soft; + + q->hicredit = qopt->hicredit; + q->locredit = qopt->locredit; + q->idleslope = qopt->idleslope; + q->sendslope = qopt->sendslope; + +return 0 ; +} + +static int cbs_init (struct Qdisc *sch,struct nlattr *opt) +{ +struct cbs_sched_data *q =qdisc_priv (sch); + +if (!opt) +return -EINVAL ; + +qdisc_watchdog_init (&q->watchdog, sch); + +return cbs_change (sch, opt); +} + +static void cbs_destroy (struct Qdisc *sch) +{ +struct cbs_sched_data *q =qdisc_priv (sch); + +qdisc_watchdog_cancel (&q->watchdog); +} + +static int cbs_dump (struct Qdisc *sch,struct sk_buff *skb) +{ +struct cbs_sched_data *q =qdisc_priv (sch); +struct tc_cbs_qopt opt = { }; +struct nlattr *nest; + + nest =nla_nest_start (skb,TCA_OPTIONS ); +if (!nest) + goto nla_put_failure; + + opt.hicredit = q->hicredit; + opt.locredit = q->locredit; + opt.sendslope = q->sendslope; + opt.idleslope = q->idleslope; + opt.offload =0 ; + +if (nla_put (skb,TCA_CBS_PARMS ,sizeof (opt), &opt)) + goto nla_put_failure; + +return nla_nest_end (skb, nest); + +nla_put_failure: +nla_nest_cancel (skb, nest); +return -1 ; +} + +static struct Qdisc_ops cbs_qdisc_ops__read_mostly = { + .id ="cbs" , + .priv_size =sizeof (struct cbs_sched_data ), + .enqueue = cbs_enqueue, + .dequeue = cbs_dequeue, + .peek = qdisc_peek_dequeued, + .init = cbs_init, + .reset = qdisc_reset_queue, + .destroy = cbs_destroy, + .change = cbs_change, + .dump = cbs_dump, + .owner =THIS_MODULE , +}; + +static int __init cbs_module_init (void ) +{ +return register_qdisc (&cbs_qdisc_ops); +} + +static void __exit cbs_module_exit(void) +{ +unregister_qdisc (&cbs_qdisc_ops); +} +module_init(cbs_module_init) +module_exit(cbs_module_exit) +MODULE_LICENSE("GPL");Signature · 1 line
2.14.2
Vinicius Costa Gomes
maintainerRe: [next-queue PATCH v7 4/6] net/sched: Introduce Credit Based Shaper (CBS) qdisc
Hi,
Ivan Khoronzhuk <[email protected]> writes:
[...]
Quoted 9 lines
net/sched/sch_cbs.c line 89
Quoted 8 lines
net/sched/sch_cbs.c new file +8
-0+ +static int cbs_enqueue_soft (struct sk_buff *skb,struct Qdisc *sch) +{ +struct cbs_sched_data *q =qdisc_priv (sch); + +if (sch->q.qlen ==0 && q->credits >0 ) { +/* We need to stop accumulating credits when there's +* no packet enqueued packets and q->credits is no packet -> no
Ugh. Fixed.
Quoted 10 lines
Quoted 10 lines
net/sched/sch_cbs.c new file +9
-0+* positive. +*/ + q->credits =0 ; + q->last =ktime_get_ns (); + } + +return qdisc_enqueue_tail (skb, sch); +} +
[...]
Quoted 15 lines
net/sched/sch_cbs.c line 158
Quoted 10 lines
net/sched/sch_cbs.c new file +10
-0+static struct sk_buff *cbs_dequeue_soft (struct Qdisc *sch) +{ +struct cbs_sched_data *q =qdisc_priv (sch); +s64 now =ktime_get_ns (); +struct sk_buff *skb; +s64 credits; +int len; + +if (q->credits <0 ) { + credits =timediff_to_credits (now - q->last, q->idleslope);Maybe be better to add small optimization by moving some calculations from data path, I mean, save
idle_slopein bytes instead of kbit and converting it for every packet. Bothdelay_from_credits()andtimediff_to_credits()is used only once and withidle_slopeonly...and both of them converting it.
Quoted 2 lines
Same for
credits_from_len()and send slope, save it in units ofport_rate.
Done. Thanks.
Cheers,
--
Vinicius
RE: [next-queue PATCH v7 4/6] net/sched: Introduce Credit Based Shaper (CBS) qdisc
In reply to Ivan KhoronzhukFrom: Ivan Khoronzhuk
Quoted 21 lines
Sent: 13 October 2017 20:59
Quoted 19 lines · Vinicius Costa Gomes
This queueing discipline implements the shaper algorithm defined by the 802.1Q-2014 Section 8.6.8.2 and detailed in Annex L.
It's primary usage is to apply some bandwidth reservation to user defined traffic classes, which are mapped to different queues via the mqprio qdisc.
Only a simple software implementation is added for now.
Signed-off-by Vinicius Costa Gomes <[email protected]>Signed-off-by Jesus Sanchez-Palencia <[email protected]>--- include/uapi/linux/pkt_sched.h | 18 +++ net/sched/Kconfig | 11 ++ net/sched/Makefile | 1 + net/sched/sch_cbs.c | 314 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 344 insertions(+) create mode 100644 net/sched/sch_cbs.c
Quoted 12 lines
include/uapi/linux/pkt_sched.h struct tc_pie_xstats { · line 877
Quoted 12 lines
include/uapi/linux/pkt_sched.h +4
-0@@ -871,4 +871,22 @@ struct tc_pie_xstats {__u32 maxq;/* maximum queue size */ __u32 ecn_mark;/* packets marked with ecn*/ }; + +/* CBS */ +struct tc_cbs_qopt { +__u8 offload;
You probably don't want unnamed padding in a uapi structure.
Quoted 5 lines
Quoted 5 lines
include/uapi/linux/pkt_sched.h +5
-0+__s32 hicredit; +__s32 locredit; +__s32 idleslope; +__s32 sendslope; +};
Quoted 8 lines
include/uapi/linux/pkt_sched.h struct tc_pie_xstats { · line 890
Quoted 8 lines
include/uapi/linux/pkt_sched.h +8
-0+ +enum { +TCA_CBS_UNSPEC , +TCA_CBS_PARMS , + __TCA_CBS_MAX, +}; + +#define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
Why not:
TCA_CBS_PARMS, TCA_CBS_NEXT, TCA_CBS_MAX = TCA_CBS_NEXT - 1,
...
David
Vinicius Costa Gomes
maintainerRE: [next-queue PATCH v7 4/6] net/sched: Introduce Credit Based Shaper (CBS) qdisc
Hi David,
David Laight <[email protected]> writes:
[...]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
index
099bf5528fed..41e349df4bf4100644include/uapi/linux/pkt_sched.h +0
-0@@ -871,4 +871,22 @@ struct tc_pie_xstats {__u32 maxq;/* maximum queue size */
Quoted 8 lines
Quoted 6 lines
include/uapi/linux/pkt_sched.h struct tc_pie_xstats { · line 877
Quoted 6 lines
include/uapi/linux/pkt_sched.h +4
-0__u32 ecn_mark;/* packets marked with ecn*/ }; + +/* CBS */ +struct tc_cbs_qopt { +__u8 offload;You probably don't want unnamed padding in a uapi structure.
Yeah, this needs to be fixed.
Quoted 16 lines
Quoted 14 lines
Quoted 4 lines
include/uapi/linux/pkt_sched.h +3
-0+__s32 hicredit; +__s32 locredit; +__s32 idleslope;include/uapi/linux/pkt_sched.h struct tc_pie_xstats { · line 890
Quoted 10 lines
include/uapi/linux/pkt_sched.h +10
-0+__s32 sendslope; +}; + +enum { +TCA_CBS_UNSPEC , +TCA_CBS_PARMS , + __TCA_CBS_MAX, +}; + +#define TCA_CBS_MAX (__TCA_CBS_MAX - 1)Why not:
Quoted 3 lines
TCA_CBS_PARMS, TCA_CBS_NEXT, TCA_CBS_MAX = TCA_CBS_NEXT - 1,
The way it is proposed, at least is consistent with the rest of the file. So, if you don't have any stronger reasons, I'd like to keep it this way.
Quoted 3 lines
...
David
Cheers,
--
Vinicius
Vinicius Costa Gomes
maintainerPATCH v7 5/6 net/sched: Add support for HW offloading for CBS
In reply to Vinicius Costa GomesThis adds support for offloading the CBS algorithm to the controller, if supported. Drivers wanting to support CBS offload must implement the .ndo_setup_tc callback and handle the TC_SETUP_CBS (introduced here) type.
--- include/linux/netdevice.h | 1 + include/net/pkt_sched.h | 9 ++++ net/sched/sch_cbs.c | 104 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 102 insertions(+), 12 deletions(-)
include/linux/netdevice.h +1 -0
@@ -775,6 +775,7 @@ enum tc_setup_type {TC_SETUP_CLSFLOWER ,TC_SETUP_CLSMATCHALL ,TC_SETUP_CLSBPF , + TC_SETUP_CBS, };/* These structures hold the attributes of xdp state that are being passed
include/net/pkt_sched.h +9 -0
@@ -146,4 +146,13 @@ static inline bool is_classid_clsact_egress(u32 classid) TC_H_MIN(classid) == TC_H_MIN(TC_H_MIN_EGRESS); } +struct tc_cbs_qopt_offload { +u8 enable; +s32 queue; +s32 hicredit; +s32 locredit; +s32 idleslope; +s32 sendslope; +}; +#endif
net/sched/sch_cbs.c +92 -12
172 lines not on this page · raw message
Signature · 1 line
2.14.2
Vinicius Costa Gomes
maintainerPATCH v7 6/6 igb: Add support for CBS offload
In reply to Vinicius Costa GomesFrom: Andre Guedes <[email protected]>
This patch adds support for Credit-Based Shaper (CBS) qdisc offload from Traffic Control system. This support enable us to leverage the Forwarding and Queuing for Time-Sensitive Streams (FQTSS) features from Intel i210 Ethernet Controller. FQTSS is the former 802.1Qav standard which was merged into 802.1Q in 2014. It enables traffic prioritization and bandwidth reservation via the Credit-Based Shaper which is implemented in hardware by i210 controller.
The patch introduces the igb_setup_tc() function which implements the support for CBS qdisc hardware offload in the IGB driver. CBS offload is the only traffic control offload supported by the driver at the moment.
FQTSS transmission mode from i210 controller is automatically enabled by the IGB driver when the CBS is enabled for the first hardware queue. Likewise, FQTSS mode is automatically disabled when CBS is disabled for the last hardware queue. Changing FQTSS mode requires NIC reset.
FQTSS feature is supported by i210 controller only.
--- drivers/net/ethernet/intel/igb/e1000_defines.h | 23 ++ drivers/net/ethernet/intel/igb/e1000_regs.h | 8 + drivers/net/ethernet/intel/igb/igb.h | 6 + drivers/net/ethernet/intel/igb/igb_main.c | 347 +++++++++++++++++++++++++ 4 files changed, 384 insertions(+)
drivers/net/ethernet/intel/igb/e1000_defines.h +23 -0
@@ -353,7 +353,18 @@#define E1000_RXPBS_CFG_TS_EN 0x80000000#define I210_RXPBSIZE_DEFAULT 0x000000A2/* RXPBSIZE default */ +#define I210_RXPBSIZE_MASK 0x0000003F +#define I210_RXPBSIZE_PB_32KB 0x00000020#define I210_TXPBSIZE_DEFAULT 0x04000014/* TXPBSIZE default */ +#define I210_TXPBSIZE_MASK 0xC0FFFFFF +#define I210_TXPBSIZE_PB0_8KB (8 << 0) +#define I210_TXPBSIZE_PB1_8KB (8 << 6) +#define I210_TXPBSIZE_PB2_4KB (4 << 12) +#define I210_TXPBSIZE_PB3_4KB (4 << 18) + +#define I210_DTXMXPKTSZ_DEFAULT 0x00000098 + +#define I210_SR_QUEUES_NUM 2/* SerDes Control */ #define E1000_SCTL_DISABLE_SERDES_LOOPBACK 0x0400
@@ -1051,4 +1062,16 @@#define E1000_VLAPQF_P_VALID (_n) (0x1 << (3 + (_n) * 4))#define E1000_VLAPQF_QUEUE_MASK 0x03 +/* TX Qav Control fields */ +#define E1000_TQAVCTRL_XMIT_MODE BIT(0) +#define E1000_TQAVCTRL_DATAFETCHARB BIT(4) +#define E1000_TQAVCTRL_DATATRANARB BIT(8) + +/* TX Qav Credit Control fields */ +#define E1000_TQAVCC_IDLESLOPE_MASK 0xFFFF +#define E1000_TQAVCC_QUEUEMODE BIT(31) + +/* Transmit Descriptor Control fields */ +#define E1000_TXDCTL_PRIORITY BIT(27) +#endif
drivers/net/ethernet/intel/igb/e1000_regs.h +8 -0
@@ -421,6 +421,14 @@ do { \#define E1000_I210_FLA 0x1201C +#define E1000_I210_DTXMXPKTSZ 0x355C + +#define E1000_I210_TXDCTL (_n) (0x0E028 + ((_n) * 0x40)) + +#define E1000_I210_TQAVCTRL 0x3570 +#define E1000_I210_TQAVCC (_n) (0x3004 + ((_n) * 0x40)) +#define E1000_I210_TQAVHC (_n) (0x300C + ((_n) * 0x40)) +#define E1000_INVM_DATA_REG (_n) (0x12120 + 4*(_n))#define E1000_INVM_SIZE 64/* Number of INVM Data Registers */
drivers/net/ethernet/intel/igb/igb.h +6 -0
@@ -281,6 +281,11 @@ struct igb_ring {u16 count;/* number of desc. in the ring */ u8 queue_index;/* logical index of the ring*/ u8 reg_idx;/* physical index of the ring */ +bool cbs_enable;/* indicates if CBS is enabled */ +s32 idleslope;/* idleSlope in kbps */ +s32 sendslope;/* sendSlope in kbps */ +s32 hicredit;/* hiCredit in bytes */ +s32 locredit;/* loCredit in bytes */ /* everything past this point are written often */ u16 next_to_clean;
@@ -621,6 +626,7 @@ struct igb_adapter {#define IGB_FLAG_EEE BIT(14)#define IGB_FLAG_VLAN_PROMISC BIT(15)#define IGB_FLAG_RX_LEGACY BIT(16) +#define IGB_FLAG_FQTSS BIT(17)/* Media Auto Sense */ #define IGB_MAS_ENABLE_0 0X0001
drivers/net/ethernet/intel/igb/igb_main.c +347 -0
389 lines not on this page · raw message
Signature · 1 line
2.14.2