요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
======================================
Texas Instruments CPSW ethernet driver
======================================
Multiqueue & CBS & MQPRIO
=========================
The cpsw has 3 CBS shapers for each external ports. This document
describes MQPRIO and CBS Qdisc offload configuration for cpsw driver
based on examples. It potentially can be used in audio video bridging
(AVB) and time sensitive networking (TSN).
The following examples were tested on AM572x EVM and BBB boards.
Test setup
==========
Under consideration two examples with AM572x EVM running cpsw driver
in dual_emac mode.
Several prerequisites:
- TX queues must be rated starting from txq0 that has highest priority
- Traffic classes are used starting from 0, that has highest priority
- CBS shapers should be used with rated queues
- The bandwidth for CBS shapers has to be set a little bit more then
potential incoming rate, thus, rate of all incoming tx queues has
to be a little less
- Real rates can differ, due to discreetness
- Map skb-priority to txq is not enough, also skb-priority to l2 prio
map has to be created with ip or vconfig tool
- Any l2/socket prio (0 - 7) for classes can be used, but for
simplicity default values are used: 3 and 2
- only 2 classes tested: A and B, but checked and can work with more,
maximum allowed 4, but only for 3 rate can be set.
Test setup for examples
=======================
::
+-------------------------------+
|--+ |
| | Workstation0 |
|E | MAC 18:03:73:66:87:42 |
+-----------------------------+ +--|t | |
| | 1 | E | | |h |./tsn_listener -d \ |
| Target board: | 0 | t |--+ |0 | 18:03:73:66:87:42 -i eth0 \|
| AM572x EVM | 0 | h | | | -s 1500 |
| | 0 | 0 | |--+ |
| Only 2 classes: |Mb +---| +-------------------------------+
| class A, class B | |
| | +---| +-------------------------------+
| | 1 | E | |--+ |
| | 0 | t | | | Workstation1 |
| | 0 | h |--+ |E | MAC 20:cf:30:85:7d:fd |
| |Mb | 1 | +--|t | |
+-----------------------------+ |h |./tsn_listener -d \ |
|0 | 20:cf:30:85:7d:fd -i eth0 \|
| | -s 1500 |
|--+ |
+-------------------------------+
Example 1: One port tx AVB configuration scheme for target board
----------------------------------------------------------------
(prints and scheme for AM572x evm, applicable for single port boards)
- tc - traffic class
- txq - transmit queue
- p - priority
- f - fifo (cpsw fifo)
- S - shaper configured
::
+------------------------------------------------------------------+ u
| +---------------+ +---------------+ +------+ +------+ | s
| | | | | | | | | | e
| | App 1 | | App 2 | | Apps | | Apps | | r
| | Class A | | Class B | | Rest | | Rest | |
| | Eth0 | | Eth0 | | Eth0 | | Eth1 | | s
| | VLAN100 | | VLAN100 | | | | | | | | p
| | 40 Mb/s | | 20 Mb/s | | | | | | | | a
| | SO_PRIORITY=3 | | SO_PRIORITY=2 | | | | | | | | c
| | | | | | | | | | | | | | e
| +---|-----------+ +---|-----------+ +---|--+ +---|--+ |
+-----|------------------|------------------|--------|-------------+
+-+ +------------+ | |
| | +-----------------+ +--+
| | | |
+---|-------|-------------|-----------------------|----------------+
| +----+ +----+ +----+ +----+ +----+ |
| | p3 | | p2 | | p1 | | p0 | | p0 | | k
| \ / \ / \ / \ / \ / | e
| \ / \ / \ / \ / \ / | r
| \/ \/ \/ \/ \/ | n
| | | | | | e
| | | +-----+ | | l
| | | | | |
| +----+ +----+ +----+ +----+ | s
| |tc0 | |tc1 | |tc2 | |tc0 | | p
| \ / \ / \ / \ / | a
| \ / \ / \ / \ / | c
| \/ \/ \/ \/ | e
| | | +-----+ | |
| | | | | | |
| | | | | | |
| | | | | | |
| +----+ +----+ +----+ +----+ +----+ |
| |txq0| |txq1| |txq2| |txq3| |txq4| |
| \ / \ / \ / \ / \ / |
| \ / \ / \ / \ / \ / |
| \/ \/ \/ \/ \/ |
| +-|------|------|------|--+ +--|--------------+ |
| | | | | | | Eth0.100 | | Eth1 | |
+---|------|------|------|------------------------|----------------+
| | | | |
p p p p |
3 2 0-1, 4-7 <- L2 priority |
| | | | |
| | | | |
+---|------|------|------|------------------------|----------------+
| | | | | |----------+ |
| +----+ +----+ +----+ +----+ +----+ |
| |dma7| |dma6| |dma5| |dma4| |dma3| |
| \ / \ / \ / \ / \ / | c
| \S / \S / \ / \ / \ / | p
| \/ \/ \/ \/ \/ | s
| | | | +----- | | w
| | | | | | |
| | | | | | | d
| +----+ +----+ +----+p p+----+ | r
| | | | | | |o o| | | i
| | f3 | | f2 | | f0 |r r| f0 | | v
| |tc0 | |tc1 | |tc2 |t t|tc0 | | e
| \CBS / \CBS / \CBS /1 2\CBS / | r
| \S / \S / \ / \ / |
| \/ \/ \/ \/ |
+------------------------------------------------------------------+
1) ::
// Add 4 tx queues, for interface Eth0, and 1 tx queue for Eth1
$ ethtool -L eth0 rx 1 tx 5
rx unmodified, ignoring
2) ::
// Check if num of queues is set correctly:
$ ethtool -l eth0
Channel parameters for eth0:
Pre-set maximums:
RX: 8
TX: 8
Other: 0
Combined: 0
Current hardware settings:
RX: 1
TX: 5
Other: 0
Combined: 0
3) ::
// TX queues must be rated starting from 0, so set bws for tx0 and tx1
// Set rates 40 and 20 Mb/s appropriately.
// Pay attention, real speed can differ a bit due to discreetness.
// Leave last 2 tx queues not rated.
$ echo 40 > /sys/class/net/eth0/queues/tx-0/tx_maxrate
$ echo 20 > /sys/class/net/eth0/queues/tx-1/tx_maxrate
4) ::
// Check maximum rate of tx (cpdma) queues:
$ cat /sys/class/net/eth0/queues/tx-*/tx_maxrate
40
20
0
0
0
5) ::
// Map skb->priority to traffic class:
// 3pri -> tc0, 2pri -> tc1, (0,1,4-7)pri -> tc2
// Map traffic class to transmit queue:
// tc0 -> txq0, tc1 -> txq1, tc2 -> (txq2, txq3)
$ tc qdisc replace dev eth0 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@0 1@1 2@2 hw 1
5a) ::
// As two interface sharing same set of tx queues, assign all traffic
// coming to interface Eth1 to separate queue in order to not mix it
// with traffic from interface Eth0, so use separate txq to send
// packets to Eth1, so all prio -> tc0 and tc0 -> txq4
// Here hw 0, so here still default configuration for eth1 in hw
$ tc qdisc replace dev eth1 handle 100: parent root mqprio num_tc 1 \
map 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 queues 1@4 hw 0
6) ::
// Check classes settings
$ tc -g class show dev eth0
+---(100:ffe2) mqprio
| +---(100:3) mqprio
| +---(100:4) mqprio
|
+---(100:ffe1) mqprio
| +---(100:2) mqprio
|
+---(100:ffe0) mqprio
+---(100:1) mqprio
$ tc -g class show dev eth1
+---(100:ffe0) mqprio
+---(100:5) mqprio
7) ::
// Set rate for class A - 41 Mbit (tc0, txq0) using CBS Qdisc
// Set it +1 Mb for reserve (important!)
// here only idle slope is important, others arg are ignored
// Pay attention, real speed can differ a bit due to discreetness
$ tc qdisc add dev eth0 parent 100:1 cbs locredit -1438 \
hicredit 62 sendslope -959000 idleslope 41000 offload 1
net eth0: set FIFO3 bw = 50
8) ::
// Set rate for class B - 21 Mbit (tc1, txq1) using CBS Qdisc:
// Set it +1 Mb for reserve (important!)
$ tc qdisc add dev eth0 parent 100:2 cbs locredit -1468 \
hicredit 65 sendslope -979000 idleslope 21000 offload 1
net eth0: set FIFO2 bw = 30
9) ::
// Create vlan 100 to map sk->priority to vlan qos
$ ip link add link eth0 name eth0.100 type vlan id 100
8021q: 802.1Q VLAN Support v1.8
8021q: adding VLAN 0 to HW filter on device eth0
8021q: adding VLAN 0 to HW filter on device eth1
net eth0: Adding vlanid 100 to vlan filter
10) ::
// Map skb->priority to L2 prio, 1 to 1
$ ip link set eth0.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
11) ::
// Check egress map for vlan 100
$ cat /proc/net/vlan/eth0.100
[...]
INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0
EGRESS priority mappings: 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
12) ::
// Run your appropriate tools with socket option "SO_PRIORITY"
// to 3 for class A and/or to 2 for class B
// (I took at https://lore.kernel.org/r/[email protected]/)
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p3 -s 1500&
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p2 -s 1500&
13) ::
// run your listener on workstation (should be in same vlan)
// (I took at https://lore.kernel.org/r/[email protected]/)
./tsn_listener -d 18:03:73:66:87:42 -i enp5s0 -s 1500
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39000 kbps
14) ::
// Restore default configuration if needed
$ ip link del eth0.100
$ tc qdisc del dev eth1 root
$ tc qdisc del dev eth0 root
net eth0: Prev FIFO2 is shaped
net eth0: set FIFO3 bw = 0
net eth0: set FIFO2 bw = 0
$ ethtool -L eth0 rx 1 tx 1
Example 2: Two port tx AVB configuration scheme for target board
----------------------------------------------------------------
(prints and scheme for AM572x evm, for dual emac boards only)
::
+------------------------------------------------------------------+ u
| +----------+ +----------+ +------+ +----------+ +----------+ | s
| | | | | | | | | | | | e
| | App 1 | | App 2 | | Apps | | App 3 | | App 4 | | r
| | Class A | | Class B | | Rest | | Class B | | Class A | |
| | Eth0 | | Eth0 | | | | | Eth1 | | Eth1 | | s
| | VLAN100 | | VLAN100 | | | | | VLAN100 | | VLAN100 | | p
| | 40 Mb/s | | 20 Mb/s | | | | | 10 Mb/s | | 30 Mb/s | | a
| | SO_PRI=3 | | SO_PRI=2 | | | | | SO_PRI=3 | | SO_PRI=2 | | c
| | | | | | | | | | | | | | | | | e
| +---|------+ +---|------+ +---|--+ +---|------+ +---|------+ |
+-----|-------------|-------------|---------|-------------|--------+
+-+ +-------+ | +----------+ +----+
| | +-------+------+ | |
| | | | | |
+---|-------|-------------|--------------|-------------|-------|---+
| +----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+ |
| | p3 | | p2 | | p1 | | p0 | | p0 | | p1 | | p2 | | p3 | | k
| \ / \ / \ / \ / \ / \ / \ / \ / | e
| \ / \ / \ / \ / \ / \ / \ / \ / | r
| \/ \/ \/ \/ \/ \/ \/ \/ | n
| | | | | | | | e
| | | +----+ +----+ | | | l
| | | | | | | |
| +----+ +----+ +----+ +----+ +----+ +----+ | s
| |tc0 | |tc1 | |tc2 | |tc2 | |tc1 | |tc0 | | p
| \ / \ / \ / \ / \ / \ / | a
| \ / \ / \ / \ / \ / \ / | c
| \/ \/ \/ \/ \/ \/ | e
| | | +-----+ +-----+ | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | E E | | | | |
| +----+ +----+ +----+ +----+ t t +----+ +----+ +----+ +----+ |
| |txq0| |txq1| |txq4| |txq5| h h |txq6| |txq7| |txq3| |txq2| |
| \ / \ / \ / \ / 0 1 \ / \ / \ / \ / |
| \ / \ / \ / \ / . . \ / \ / \ / \ / |
| \/ \/ \/ \/ 1 1 \/ \/ \/ \/ |
| +-|------|------|------|--+ 0 0 +-|------|------|------|--+ |
| | | | | | | 0 0 | | | | | | |
+---|------|------|------|---------------|------|------|------|----+
| | | | | | | |
p p p p p p p p
3 2 0-1, 4-7 <-L2 pri-> 0-1, 4-7 2 3
| | | | | | | |
| | | | | | | |
+---|------|------|------|---------------|------|------|------|----+
| | | | | | | | | |
| +----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+ |
| |dma7| |dma6| |dma3| |dma2| |dma1| |dma0| |dma4| |dma5| |
| \ / \ / \ / \ / \ / \ / \ / \ / | c
| \S / \S / \ / \ / \ / \ / \S / \S / | p
| \/ \/ \/ \/ \/ \/ \/ \/ | s
| | | | +----- | | | | | w
| | | | | +----+ | | | |
| | | | | | | | | | d
| +----+ +----+ +----+p p+----+ +----+ +----+ | r
| | | | | | |o o| | | | | | | i
| | f3 | | f2 | | f0 |r CPSW r| f3 | | f2 | | f0 | | v
| |tc0 | |tc1 | |tc2 |t t|tc0 | |tc1 | |tc2 | | e
| \CBS / \CBS / \CBS /1 2\CBS / \CBS / \CBS / | r
| \S / \S / \ / \S / \S / \ / |
| \/ \/ \/ \/ \/ \/ |
+------------------------------------------------------------------+
========================================Eth==========================>
1) ::
// Add 8 tx queues, for interface Eth0, but they are common, so are accessed
// by two interfaces Eth0 and Eth1.
$ ethtool -L eth1 rx 1 tx 8
rx unmodified, ignoring
2) ::
// Check if num of queues is set correctly:
$ ethtool -l eth0
Channel parameters for eth0:
Pre-set maximums:
RX: 8
TX: 8
Other: 0
Combined: 0
Current hardware settings:
RX: 1
TX: 8
Other: 0
Combined: 0
3) ::
// TX queues must be rated starting from 0, so set bws for tx0 and tx1 for Eth0
// and for tx2 and tx3 for Eth1. That is, rates 40 and 20 Mb/s appropriately
// for Eth0 and 30 and 10 Mb/s for Eth1.
// Real speed can differ a bit due to discreetness
// Leave last 4 tx queues as not rated
$ echo 40 > /sys/class/net/eth0/queues/tx-0/tx_maxrate
$ echo 20 > /sys/class/net/eth0/queues/tx-1/tx_maxrate
$ echo 30 > /sys/class/net/eth1/queues/tx-2/tx_maxrate
$ echo 10 > /sys/class/net/eth1/queues/tx-3/tx_maxrate
4) ::
// Check maximum rate of tx (cpdma) queues:
$ cat /sys/class/net/eth0/queues/tx-*/tx_maxrate
40
20
30
10
0
0
0
0
5) ::
// Map skb->priority to traffic class for Eth0:
// 3pri -> tc0, 2pri -> tc1, (0,1,4-7)pri -> tc2
// Map traffic class to transmit queue:
// tc0 -> txq0, tc1 -> txq1, tc2 -> (txq4, txq5)
$ tc qdisc replace dev eth0 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@0 1@1 2@4 hw 1
6) ::
// Check classes settings
$ tc -g class show dev eth0
+---(100:ffe2) mqprio
| +---(100:5) mqprio
| +---(100:6) mqprio
|
+---(100:ffe1) mqprio
| +---(100:2) mqprio
|
+---(100:ffe0) mqprio
+---(100:1) mqprio
7) ::
// Set rate for class A - 41 Mbit (tc0, txq0) using CBS Qdisc for Eth0
// here only idle slope is important, others ignored
// Real speed can differ a bit due to discreetness
$ tc qdisc add dev eth0 parent 100:1 cbs locredit -1470 \
hicredit 62 sendslope -959000 idleslope 41000 offload 1
net eth0: set FIFO3 bw = 50
8) ::
// Set rate for class B - 21 Mbit (tc1, txq1) using CBS Qdisc for Eth0
$ tc qdisc add dev eth0 parent 100:2 cbs locredit -1470 \
hicredit 65 sendslope -979000 idleslope 21000 offload 1
net eth0: set FIFO2 bw = 30
9) ::
// Create vlan 100 to map sk->priority to vlan qos for Eth0
$ ip link add link eth0 name eth0.100 type vlan id 100
net eth0: Adding vlanid 100 to vlan filter
10) ::
// Map skb->priority to L2 prio for Eth0.100, one to one
$ ip link set eth0.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
11) ::
// Check egress map for vlan 100
$ cat /proc/net/vlan/eth0.100
[...]
INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0
EGRESS priority mappings: 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
12) ::
// Map skb->priority to traffic class for Eth1:
// 3pri -> tc0, 2pri -> tc1, (0,1,4-7)pri -> tc2
// Map traffic class to transmit queue:
// tc0 -> txq2, tc1 -> txq3, tc2 -> (txq6, txq7)
$ tc qdisc replace dev eth1 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@2 1@3 2@6 hw 1
13) ::
// Check classes settings
$ tc -g class show dev eth1
+---(100:ffe2) mqprio
| +---(100:7) mqprio
| +---(100:8) mqprio
|
+---(100:ffe1) mqprio
| +---(100:4) mqprio
|
+---(100:ffe0) mqprio
+---(100:3) mqprio
14) ::
// Set rate for class A - 31 Mbit (tc0, txq2) using CBS Qdisc for Eth1
// here only idle slope is important, others ignored, but calculated
// for interface speed - 100Mb for eth1 port.
// Set it +1 Mb for reserve (important!)
$ tc qdisc add dev eth1 parent 100:3 cbs locredit -1035 \
hicredit 465 sendslope -69000 idleslope 31000 offload 1
net eth1: set FIFO3 bw = 31
15) ::
// Set rate for class B - 11 Mbit (tc1, txq3) using CBS Qdisc for Eth1
// Set it +1 Mb for reserve (important!)
$ tc qdisc add dev eth1 parent 100:4 cbs locredit -1335 \
hicredit 405 sendslope -89000 idleslope 11000 offload 1
net eth1: set FIFO2 bw = 11
16) ::
// Create vlan 100 to map sk->priority to vlan qos for Eth1
$ ip link add link eth1 name eth1.100 type vlan id 100
net eth1: Adding vlanid 100 to vlan filter
17) ::
// Map skb->priority to L2 prio for Eth1.100, one to one
$ ip link set eth1.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
18) ::
// Check egress map for vlan 100
$ cat /proc/net/vlan/eth1.100
[...]
INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0
EGRESS priority mappings: 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
19) ::
// Run appropriate tools with socket option "SO_PRIORITY" to 3
// for class A and to 2 for class B. For both interfaces
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p2 -s 1500&
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p3 -s 1500&
./tsn_talker -d 20:cf:30:85:7d:fd -i eth1.100 -p2 -s 1500&
./tsn_talker -d 20:cf:30:85:7d:fd -i eth1.100 -p3 -s 1500&
20) ::
// run your listener on workstation (should be in same vlan)
// (I took at https://lore.kernel.org/r/[email protected]/)
./tsn_listener -d 18:03:73:66:87:42 -i enp5s0 -s 1500
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39000 kbps
21) ::
// Restore default configuration if needed
$ ip link del eth1.100
$ ip link del eth0.100
$ tc qdisc del dev eth1 root
net eth1: Prev FIFO2 is shaped
net eth1: set FIFO3 bw = 0
net eth1: set FIFO2 bw = 0
$ tc qdisc del dev eth0 root
net eth0: Prev FIFO2 is shaped
net eth0: set FIFO3 bw = 0
net eth0: set FIFO2 bw = 0
$ ethtool -L eth0 rx 1 tx 1
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
CPSW CBS/MQPRIO 개요와 시험 환경
1-67이 문서는 `GPL-2.0` 라이선스를 따릅니다.
Texas Instruments CPSW Ethernet 드라이버
Multiqueue, CBS와 MQPRIO
CPSW는 외부 포트마다 3개의 CBS shaper를 갖습니다. 이 문서는 예제를 바탕으로 CPSW 드라이버의 MQPRIO와 CBS Qdisc offload 구성을 설명합니다. 이 기능은 AVB(Audio Video Bridging)와 TSN(Time Sensitive Networking)에 활용할 수 있습니다.
예제는 AM572x EVM과 BBB 보드에서 시험되었습니다.
시험 구성
두 예제 모두 AM572x EVM에서 CPSW 드라이버를 `dual_emac` 모드로 실행합니다.
전제 조건
- TX 큐는 우선순위가 가장 높은 `txq0`부터 차례로 rate를 지정해야 합니다.
- Traffic class는 우선순위가 가장 높은 class 0부터 사용합니다.
- CBS shaper는 rate가 지정된 큐에 사용해야 합니다.
- CBS shaper의 bandwidth는 예상 유입 rate보다 약간 크게 설정해야 하므로 모든 유입 TX 큐의 실제 목표 rate 합은 그보다 조금 작아야 합니다.
- 하드웨어 설정값의 이산성 때문에 실제 rate는 요청값과 다를 수 있습니다.
- `skb->priority`를 TX 큐에 매핑하는 것만으로는 충분하지 않습니다. `ip` 또는 `vconfig`로 `skb->priority`와 L2 priority 매핑도 만들어야 합니다.
- class에는 0~7의 어떤 L2/socket priority도 사용할 수 있지만 예제는 단순화를 위해 기본값 3과 2를 사용합니다.
- 시험한 class는 A와 B 두 개입니다. 최대 4개까지 동작할 수 있지만 rate는 그중 3개에만 설정할 수 있습니다.
예제 시험 환경
AM572x EVM의 1Gbps `eth0`은 MAC `18:03:73:66:87:42`인 Workstation0에 연결되고, 100Mbps `eth1`은 MAC `20:cf:30:85:7d:fd`인 Workstation1에 연결됩니다. 각 workstation에서는 목적지 MAC과 인터페이스를 지정한 `tsn_listener`를 1500바이트 크기로 실행합니다.
dual-EMAC의 두 외부 포트와 listener workstation 연결입니다.
.. SPDX-License-Identifier: GPL-2.0
======================================
Texas Instruments CPSW ethernet driver
======================================
Multiqueue & CBS & MQPRIO
=========================
The cpsw has 3 CBS shapers for each external ports. This document
describes MQPRIO and CBS Qdisc offload configuration for cpsw driver
based on examples. It potentially can be used in audio video bridging
(AVB) and time sensitive networking (TSN).
The following examples were tested on AM572x EVM and BBB boards.
Test setup
==========
Under consideration two examples with AM572x EVM running cpsw driver
in dual_emac mode.
Several prerequisites:
- TX queues must be rated starting from txq0 that has highest priority
- Traffic classes are used starting from 0, that has highest priority
- CBS shapers should be used with rated queues
- The bandwidth for CBS shapers has to be set a little bit more then
potential incoming rate, thus, rate of all incoming tx queues has
to be a little less
- Real rates can differ, due to discreetness
- Map skb-priority to txq is not enough, also skb-priority to l2 prio
map has to be created with ip or vconfig tool
- Any l2/socket prio (0 - 7) for classes can be used, but for
simplicity default values are used: 3 and 2
- only 2 classes tested: A and B, but checked and can work with more,
maximum allowed 4, but only for 3 rate can be set.
Test setup for examples
=======================
::
+-------------------------------+
|--+ |
| | Workstation0 |
|E | MAC 18:03:73:66:87:42 |
+-----------------------------+ +--|t | |
| | 1 | E | | |h |./tsn_listener -d \ |
| Target board: | 0 | t |--+ |0 | 18:03:73:66:87:42 -i eth0 \|
| AM572x EVM | 0 | h | | | -s 1500 |
| | 0 | 0 | |--+ |
| Only 2 classes: |Mb +---| +-------------------------------+
| class A, class B | |
| | +---| +-------------------------------+
| | 1 | E | |--+ |
| | 0 | t | | | Workstation1 |
| | 0 | h |--+ |E | MAC 20:cf:30:85:7d:fd |
| |Mb | 1 | +--|t | |
+-----------------------------+ |h |./tsn_listener -d \ |
|0 | 20:cf:30:85:7d:fd -i eth0 \|
| | -s 1500 |
|--+ |
+-------------------------------+
예제 1: 한 포트 TX AVB 구성 구조
68-146예제 1: 대상 보드의 단일 포트 TX AVB 구성
출력과 구조는 AM572x EVM 기준이지만 단일 포트 보드에도 적용할 수 있습니다.
- `tc`: traffic class
- `txq`: transmit queue
- `p`: priority
- `f`: CPSW FIFO
- `S`: shaper가 구성되었음을 뜻함
`eth0.100`에서 App 1(class A)은 40Mb/s와 `SO_PRIORITY=3`, App 2(class B)는 20Mb/s와 `SO_PRIORITY=2`를 사용합니다. 일반 `eth0` 트래픽과 `eth1` 트래픽도 별도 큐 경로를 사용합니다.
사용자 priority부터 CPSW FIFO까지의 경로입니다.
socket priority 3인 VLAN packet이 shaped FIFO로 전달됩니다.
Example 1: One port tx AVB configuration scheme for target board
----------------------------------------------------------------
(prints and scheme for AM572x evm, applicable for single port boards)
- tc - traffic class
- txq - transmit queue
- p - priority
- f - fifo (cpsw fifo)
- S - shaper configured
::
+------------------------------------------------------------------+ u
| +---------------+ +---------------+ +------+ +------+ | s
| | | | | | | | | | e
| | App 1 | | App 2 | | Apps | | Apps | | r
| | Class A | | Class B | | Rest | | Rest | |
| | Eth0 | | Eth0 | | Eth0 | | Eth1 | | s
| | VLAN100 | | VLAN100 | | | | | | | | p
| | 40 Mb/s | | 20 Mb/s | | | | | | | | a
| | SO_PRIORITY=3 | | SO_PRIORITY=2 | | | | | | | | c
| | | | | | | | | | | | | | e
| +---|-----------+ +---|-----------+ +---|--+ +---|--+ |
+-----|------------------|------------------|--------|-------------+
+-+ +------------+ | |
| | +-----------------+ +--+
| | | |
+---|-------|-------------|-----------------------|----------------+
| +----+ +----+ +----+ +----+ +----+ |
| | p3 | | p2 | | p1 | | p0 | | p0 | | k
| \ / \ / \ / \ / \ / | e
| \ / \ / \ / \ / \ / | r
| \/ \/ \/ \/ \/ | n
| | | | | | e
| | | +-----+ | | l
| | | | | |
| +----+ +----+ +----+ +----+ | s
| |tc0 | |tc1 | |tc2 | |tc0 | | p
| \ / \ / \ / \ / | a
| \ / \ / \ / \ / | c
| \/ \/ \/ \/ | e
| | | +-----+ | |
| | | | | | |
| | | | | | |
| | | | | | |
| +----+ +----+ +----+ +----+ +----+ |
| |txq0| |txq1| |txq2| |txq3| |txq4| |
| \ / \ / \ / \ / \ / |
| \ / \ / \ / \ / \ / |
| \/ \/ \/ \/ \/ |
| +-|------|------|------|--+ +--|--------------+ |
| | | | | | | Eth0.100 | | Eth1 | |
+---|------|------|------|------------------------|----------------+
| | | | |
p p p p |
3 2 0-1, 4-7 <- L2 priority |
| | | | |
| | | | |
+---|------|------|------|------------------------|----------------+
| | | | | |----------+ |
| +----+ +----+ +----+ +----+ +----+ |
| |dma7| |dma6| |dma5| |dma4| |dma3| |
| \ / \ / \ / \ / \ / | c
| \S / \S / \ / \ / \ / | p
| \/ \/ \/ \/ \/ | s
| | | | +----- | | w
| | | | | | |
| | | | | | | d
| +----+ +----+ +----+p p+----+ | r
| | | | | | |o o| | | i
| | f3 | | f2 | | f0 |r r| f0 | | v
| |tc0 | |tc1 | |tc2 |t t|tc0 | | e
| \CBS / \CBS / \CBS /1 2\CBS / | r
| \S / \S / \ / \ / |
| \/ \/ \/ \/ |
+------------------------------------------------------------------+
예제 1: 한 포트 구성 절차
147-3041. `eth0`에 TX 큐 4개, `eth1`에 TX 큐 1개를 배정하도록 총 TX 큐를 5개로 설정합니다.
ethtool -L eth0 rx 1 tx 5
2. `ethtool -l eth0`으로 현재 TX 큐 수가 5인지 확인합니다.
3. rate 지정은 `txq0`부터 해야 합니다. class A용 `txq0`은 40Mb/s, class B용 `txq1`은 20Mb/s로 설정하고 나머지 세 큐는 rate를 0으로 둡니다. 실제 속도는 이산성 때문에 약간 다를 수 있습니다.
echo 40 > /sys/class/net/eth0/queues/tx-0/tx_maxrate
echo 20 > /sys/class/net/eth0/queues/tx-1/tx_maxrate
4. 모든 TX 큐의 `tx_maxrate`를 읽어 40, 20, 0, 0, 0인지 확인합니다.
5. `eth0`의 priority 3을 tc0과 txq0, priority 2를 tc1과 txq1, 나머지를 tc2와 txq2~3에 매핑합니다. `hw 1`로 MQPRIO hardware offload를 요청합니다.
tc qdisc replace dev eth0 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@0 1@1 2@2 hw 1
5a. 두 인터페이스가 같은 TX 큐 집합을 공유하므로 `eth1`의 모든 트래픽을 별도 `txq4`로 보냅니다. 모든 priority를 tc0에 넣고 tc0을 txq4에 매핑합니다. `hw 0`이므로 `eth1`의 hardware 설정은 기본 상태를 유지합니다.
tc qdisc replace dev eth1 handle 100: parent root mqprio num_tc 1 \
map 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 queues 1@4 hw 0
6. `tc -g class show dev eth0`과 `eth1`로 MQPRIO class와 queue 매핑을 확인합니다.
7. class A의 목표 40Mb/s보다 1Mb/s 큰 `idleslope 41000`을 tc0/txq0에 CBS Qdisc로 설정합니다. 여기서는 idle slope만 중요하며 나머지 인자는 무시됩니다.
tc qdisc add dev eth0 parent 100:1 cbs locredit -1438 \
hicredit 62 sendslope -959000 idleslope 41000 offload 1
8. class B의 목표 20Mb/s보다 1Mb/s 큰 `idleslope 21000`을 tc1/txq1에 설정합니다.
tc qdisc add dev eth0 parent 100:2 cbs locredit -1468 \
hicredit 65 sendslope -979000 idleslope 21000 offload 1
9. socket priority를 VLAN QoS로 매핑하기 위해 `eth0.100` VLAN 100 인터페이스를 만듭니다.
ip link add link eth0 name eth0.100 type vlan id 100
10. `eth0.100`의 egress map을 0:0부터 7:7까지 일대일로 설정해 skb priority를 L2 priority로 옮깁니다.
ip link set eth0.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
11. `/proc/net/vlan/eth0.100`을 읽어 egress priority map을 확인합니다.
12. class A는 `SO_PRIORITY=3`, class B는 `SO_PRIORITY=2`로 `tsn_talker`를 실행합니다.
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p3 -s 1500&
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p2 -s 1500&
13. 같은 VLAN의 workstation에서 `tsn_listener`를 실행합니다. 예시 측정값은 약 39,012kbps로 class A의 40Mb/s 목표에 가깝습니다.
./tsn_listener -d 18:03:73:66:87:42 -i enp5s0 -s 1500
14. 기본 구성으로 되돌리려면 `eth0.100`을 삭제하고 두 인터페이스의 root Qdisc를 제거한 뒤 TX 큐를 하나로 복원합니다. shaped FIFO의 bandwidth도 0으로 돌아갑니다.
ip link del eth0.100
tc qdisc del dev eth1 root
tc qdisc del dev eth0 root
ethtool -L eth0 rx 1 tx 1
큐 생성부터 복원까지의 의존 순서입니다.
1) ::
// Add 4 tx queues, for interface Eth0, and 1 tx queue for Eth1
$ ethtool -L eth0 rx 1 tx 5
rx unmodified, ignoring
2) ::
// Check if num of queues is set correctly:
$ ethtool -l eth0
Channel parameters for eth0:
Pre-set maximums:
RX: 8
TX: 8
Other: 0
Combined: 0
Current hardware settings:
RX: 1
TX: 5
Other: 0
Combined: 0
3) ::
// TX queues must be rated starting from 0, so set bws for tx0 and tx1
// Set rates 40 and 20 Mb/s appropriately.
// Pay attention, real speed can differ a bit due to discreetness.
// Leave last 2 tx queues not rated.
$ echo 40 > /sys/class/net/eth0/queues/tx-0/tx_maxrate
$ echo 20 > /sys/class/net/eth0/queues/tx-1/tx_maxrate
4) ::
// Check maximum rate of tx (cpdma) queues:
$ cat /sys/class/net/eth0/queues/tx-*/tx_maxrate
40
20
0
0
0
5) ::
// Map skb->priority to traffic class:
// 3pri -> tc0, 2pri -> tc1, (0,1,4-7)pri -> tc2
// Map traffic class to transmit queue:
// tc0 -> txq0, tc1 -> txq1, tc2 -> (txq2, txq3)
$ tc qdisc replace dev eth0 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@0 1@1 2@2 hw 1
5a) ::
// As two interface sharing same set of tx queues, assign all traffic
// coming to interface Eth1 to separate queue in order to not mix it
// with traffic from interface Eth0, so use separate txq to send
// packets to Eth1, so all prio -> tc0 and tc0 -> txq4
// Here hw 0, so here still default configuration for eth1 in hw
$ tc qdisc replace dev eth1 handle 100: parent root mqprio num_tc 1 \
map 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 queues 1@4 hw 0
6) ::
// Check classes settings
$ tc -g class show dev eth0
+---(100:ffe2) mqprio
| +---(100:3) mqprio
| +---(100:4) mqprio
|
+---(100:ffe1) mqprio
| +---(100:2) mqprio
|
+---(100:ffe0) mqprio
+---(100:1) mqprio
$ tc -g class show dev eth1
+---(100:ffe0) mqprio
+---(100:5) mqprio
7) ::
// Set rate for class A - 41 Mbit (tc0, txq0) using CBS Qdisc
// Set it +1 Mb for reserve (important!)
// here only idle slope is important, others arg are ignored
// Pay attention, real speed can differ a bit due to discreetness
$ tc qdisc add dev eth0 parent 100:1 cbs locredit -1438 \
hicredit 62 sendslope -959000 idleslope 41000 offload 1
net eth0: set FIFO3 bw = 50
8) ::
// Set rate for class B - 21 Mbit (tc1, txq1) using CBS Qdisc:
// Set it +1 Mb for reserve (important!)
$ tc qdisc add dev eth0 parent 100:2 cbs locredit -1468 \
hicredit 65 sendslope -979000 idleslope 21000 offload 1
net eth0: set FIFO2 bw = 30
9) ::
// Create vlan 100 to map sk->priority to vlan qos
$ ip link add link eth0 name eth0.100 type vlan id 100
8021q: 802.1Q VLAN Support v1.8
8021q: adding VLAN 0 to HW filter on device eth0
8021q: adding VLAN 0 to HW filter on device eth1
net eth0: Adding vlanid 100 to vlan filter
10) ::
// Map skb->priority to L2 prio, 1 to 1
$ ip link set eth0.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
11) ::
// Check egress map for vlan 100
$ cat /proc/net/vlan/eth0.100
[...]
INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0
EGRESS priority mappings: 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
12) ::
// Run your appropriate tools with socket option "SO_PRIORITY"
// to 3 for class A and/or to 2 for class B
// (I took at https://lore.kernel.org/r/[email protected]/)
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p3 -s 1500&
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p2 -s 1500&
13) ::
// run your listener on workstation (should be in same vlan)
// (I took at https://lore.kernel.org/r/[email protected]/)
./tsn_listener -d 18:03:73:66:87:42 -i enp5s0 -s 1500
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39000 kbps
14) ::
// Restore default configuration if needed
$ ip link del eth0.100
$ tc qdisc del dev eth1 root
$ tc qdisc del dev eth0 root
net eth0: Prev FIFO2 is shaped
net eth0: set FIFO3 bw = 0
net eth0: set FIFO2 bw = 0
$ ethtool -L eth0 rx 1 tx 1
예제 2: 두 포트 TX AVB 구성 구조
305-377예제 2: 대상 보드의 두 포트 TX AVB 구성
출력과 구조는 AM572x EVM dual-EMAC 보드에만 적용됩니다. 두 인터페이스가 공통 TX 큐 8개를 나눠 사용합니다.
`eth0.100`에서는 class A 40Mb/s가 priority 3, class B 20Mb/s가 priority 2를 사용합니다. `eth1.100`에서는 class B 10Mb/s가 priority 3, class A 30Mb/s가 priority 2를 사용합니다.
두 포트가 공유하는 8개 TX/DMA 큐의 배치입니다.
rate가 지정된 큐와 best-effort 큐를 두 포트에 나눕니다.
Example 2: Two port tx AVB configuration scheme for target board
----------------------------------------------------------------
(prints and scheme for AM572x evm, for dual emac boards only)
::
+------------------------------------------------------------------+ u
| +----------+ +----------+ +------+ +----------+ +----------+ | s
| | | | | | | | | | | | e
| | App 1 | | App 2 | | Apps | | App 3 | | App 4 | | r
| | Class A | | Class B | | Rest | | Class B | | Class A | |
| | Eth0 | | Eth0 | | | | | Eth1 | | Eth1 | | s
| | VLAN100 | | VLAN100 | | | | | VLAN100 | | VLAN100 | | p
| | 40 Mb/s | | 20 Mb/s | | | | | 10 Mb/s | | 30 Mb/s | | a
| | SO_PRI=3 | | SO_PRI=2 | | | | | SO_PRI=3 | | SO_PRI=2 | | c
| | | | | | | | | | | | | | | | | e
| +---|------+ +---|------+ +---|--+ +---|------+ +---|------+ |
+-----|-------------|-------------|---------|-------------|--------+
+-+ +-------+ | +----------+ +----+
| | +-------+------+ | |
| | | | | |
+---|-------|-------------|--------------|-------------|-------|---+
| +----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+ |
| | p3 | | p2 | | p1 | | p0 | | p0 | | p1 | | p2 | | p3 | | k
| \ / \ / \ / \ / \ / \ / \ / \ / | e
| \ / \ / \ / \ / \ / \ / \ / \ / | r
| \/ \/ \/ \/ \/ \/ \/ \/ | n
| | | | | | | | e
| | | +----+ +----+ | | | l
| | | | | | | |
| +----+ +----+ +----+ +----+ +----+ +----+ | s
| |tc0 | |tc1 | |tc2 | |tc2 | |tc1 | |tc0 | | p
| \ / \ / \ / \ / \ / \ / | a
| \ / \ / \ / \ / \ / \ / | c
| \/ \/ \/ \/ \/ \/ | e
| | | +-----+ +-----+ | | |
| | | | | | | | | |
| | | | | | | | | |
| | | | | E E | | | | |
| +----+ +----+ +----+ +----+ t t +----+ +----+ +----+ +----+ |
| |txq0| |txq1| |txq4| |txq5| h h |txq6| |txq7| |txq3| |txq2| |
| \ / \ / \ / \ / 0 1 \ / \ / \ / \ / |
| \ / \ / \ / \ / . . \ / \ / \ / \ / |
| \/ \/ \/ \/ 1 1 \/ \/ \/ \/ |
| +-|------|------|------|--+ 0 0 +-|------|------|------|--+ |
| | | | | | | 0 0 | | | | | | |
+---|------|------|------|---------------|------|------|------|----+
| | | | | | | |
p p p p p p p p
3 2 0-1, 4-7 <-L2 pri-> 0-1, 4-7 2 3
| | | | | | | |
| | | | | | | |
+---|------|------|------|---------------|------|------|------|----+
| | | | | | | | | |
| +----+ +----+ +----+ +----+ +----+ +----+ +----+ +----+ |
| |dma7| |dma6| |dma3| |dma2| |dma1| |dma0| |dma4| |dma5| |
| \ / \ / \ / \ / \ / \ / \ / \ / | c
| \S / \S / \ / \ / \ / \ / \S / \S / | p
| \/ \/ \/ \/ \/ \/ \/ \/ | s
| | | | +----- | | | | | w
| | | | | +----+ | | | |
| | | | | | | | | | d
| +----+ +----+ +----+p p+----+ +----+ +----+ | r
| | | | | | |o o| | | | | | | i
| | f3 | | f2 | | f0 |r CPSW r| f3 | | f2 | | f0 | | v
| |tc0 | |tc1 | |tc2 |t t|tc0 | |tc1 | |tc2 | | e
| \CBS / \CBS / \CBS /1 2\CBS / \CBS / \CBS / | r
| \S / \S / \ / \S / \S / \ / |
| \/ \/ \/ \/ \/ \/ |
+------------------------------------------------------------------+
========================================Eth==========================>
예제 2: 공통 큐와 eth0 구성
378-4831. 두 인터페이스가 함께 접근하는 공통 TX 큐를 8개로 설정합니다. 명령은 `eth1`에 실행하지만 `eth0`에서도 같은 하드웨어 설정을 확인할 수 있습니다.
ethtool -L eth1 rx 1 tx 8
2. `ethtool -l eth0`으로 RX 1개, TX 8개인지 확인합니다.
3. rate 지정 큐를 앞에서부터 배치합니다. `eth0`의 txq0/1은 40/20Mb/s, `eth1`의 txq2/3은 30/10Mb/s로 설정하고 나머지 txq4~7은 rate 0으로 둡니다.
echo 40 > /sys/class/net/eth0/queues/tx-0/tx_maxrate
echo 20 > /sys/class/net/eth0/queues/tx-1/tx_maxrate
echo 30 > /sys/class/net/eth1/queues/tx-2/tx_maxrate
echo 10 > /sys/class/net/eth1/queues/tx-3/tx_maxrate
4. 모든 `tx_maxrate`를 읽어 40, 20, 30, 10, 0, 0, 0, 0인지 확인합니다.
5. `eth0`의 priority 3→tc0→txq0, priority 2→tc1→txq1, 나머지 priority→tc2→txq4/5로 MQPRIO를 구성하고 hardware offload를 켭니다.
tc qdisc replace dev eth0 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@0 1@1 2@4 hw 1
6. `tc -g class show dev eth0`으로 tc0/1/2의 큐 배치를 확인합니다.
7. `eth0` class A에 목표보다 1Mb/s 큰 41Mb/s CBS를, 8. class B에 21Mb/s CBS를 설정합니다. 실제 rate는 이산성 때문에 달라질 수 있습니다.
tc qdisc add dev eth0 parent 100:1 cbs locredit -1470 \
hicredit 62 sendslope -959000 idleslope 41000 offload 1
tc qdisc add dev eth0 parent 100:2 cbs locredit -1470 \
hicredit 65 sendslope -979000 idleslope 21000 offload 1
9. `eth0.100` VLAN을 만들고, 10. skb priority와 L2 priority를 0~7 일대일로 매핑합니다.
ip link add link eth0 name eth0.100 type vlan id 100
ip link set eth0.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
11. `/proc/net/vlan/eth0.100`에서 egress map을 확인합니다.
$ cat /proc/net/vlan/eth0.100
[...]
INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0
EGRESS priority mappings: 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
1) ::
// Add 8 tx queues, for interface Eth0, but they are common, so are accessed
// by two interfaces Eth0 and Eth1.
$ ethtool -L eth1 rx 1 tx 8
rx unmodified, ignoring
2) ::
// Check if num of queues is set correctly:
$ ethtool -l eth0
Channel parameters for eth0:
Pre-set maximums:
RX: 8
TX: 8
Other: 0
Combined: 0
Current hardware settings:
RX: 1
TX: 8
Other: 0
Combined: 0
3) ::
// TX queues must be rated starting from 0, so set bws for tx0 and tx1 for Eth0
// and for tx2 and tx3 for Eth1. That is, rates 40 and 20 Mb/s appropriately
// for Eth0 and 30 and 10 Mb/s for Eth1.
// Real speed can differ a bit due to discreetness
// Leave last 4 tx queues as not rated
$ echo 40 > /sys/class/net/eth0/queues/tx-0/tx_maxrate
$ echo 20 > /sys/class/net/eth0/queues/tx-1/tx_maxrate
$ echo 30 > /sys/class/net/eth1/queues/tx-2/tx_maxrate
$ echo 10 > /sys/class/net/eth1/queues/tx-3/tx_maxrate
4) ::
// Check maximum rate of tx (cpdma) queues:
$ cat /sys/class/net/eth0/queues/tx-*/tx_maxrate
40
20
30
10
0
0
0
0
5) ::
// Map skb->priority to traffic class for Eth0:
// 3pri -> tc0, 2pri -> tc1, (0,1,4-7)pri -> tc2
// Map traffic class to transmit queue:
// tc0 -> txq0, tc1 -> txq1, tc2 -> (txq4, txq5)
$ tc qdisc replace dev eth0 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@0 1@1 2@4 hw 1
6) ::
// Check classes settings
$ tc -g class show dev eth0
+---(100:ffe2) mqprio
| +---(100:5) mqprio
| +---(100:6) mqprio
|
+---(100:ffe1) mqprio
| +---(100:2) mqprio
|
+---(100:ffe0) mqprio
+---(100:1) mqprio
7) ::
// Set rate for class A - 41 Mbit (tc0, txq0) using CBS Qdisc for Eth0
// here only idle slope is important, others ignored
// Real speed can differ a bit due to discreetness
$ tc qdisc add dev eth0 parent 100:1 cbs locredit -1470 \
hicredit 62 sendslope -959000 idleslope 41000 offload 1
net eth0: set FIFO3 bw = 50
8) ::
// Set rate for class B - 21 Mbit (tc1, txq1) using CBS Qdisc for Eth0
$ tc qdisc add dev eth0 parent 100:2 cbs locredit -1470 \
hicredit 65 sendslope -979000 idleslope 21000 offload 1
net eth0: set FIFO2 bw = 30
9) ::
// Create vlan 100 to map sk->priority to vlan qos for Eth0
$ ip link add link eth0 name eth0.100 type vlan id 100
net eth0: Adding vlanid 100 to vlan filter
10) ::
// Map skb->priority to L2 prio for Eth0.100, one to one
$ ip link set eth0.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
11) ::
// Check egress map for vlan 100
$ cat /proc/net/vlan/eth0.100
[...]
INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0
EGRESS priority mappings: 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
예제 2: eth1 구성, 시험과 복원
484-58712. `eth1`에서는 priority 3→tc0→txq2, priority 2→tc1→txq3, 나머지 priority→tc2→txq6/7로 MQPRIO를 구성합니다.
tc qdisc replace dev eth1 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@2 1@3 2@6 hw 1
13. `tc -g class show dev eth1`로 class와 queue 매핑을 확인합니다.
14. 100Mb/s `eth1`의 class A 목표 30Mb/s에 1Mb/s 여유를 더한 31Mb/s CBS를 tc0/txq2에 설정합니다. 계산한 `sendslope -69000`, `idleslope 31000`을 사용합니다.
tc qdisc add dev eth1 parent 100:3 cbs locredit -1035 \
hicredit 465 sendslope -69000 idleslope 31000 offload 1
15. class B 목표 10Mb/s에 1Mb/s 여유를 더한 11Mb/s CBS를 tc1/txq3에 설정합니다.
tc qdisc add dev eth1 parent 100:4 cbs locredit -1335 \
hicredit 405 sendslope -89000 idleslope 11000 offload 1
16. `eth1.100` VLAN을 만들고, 17. skb priority와 L2 priority를 일대일로 매핑한 뒤, 18. `/proc/net/vlan/eth1.100`에서 결과를 확인합니다.
ip link add link eth1 name eth1.100 type vlan id 100
ip link set eth1.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
cat /proc/net/vlan/eth1.100
19. 두 인터페이스에서 class A/B에 해당하는 `SO_PRIORITY` 3과 2로 네 개의 `tsn_talker`를 실행합니다.
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p2 -s 1500&
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p3 -s 1500&
./tsn_talker -d 20:cf:30:85:7d:fd -i eth1.100 -p2 -s 1500&
./tsn_talker -d 20:cf:30:85:7d:fd -i eth1.100 -p3 -s 1500&
20. 같은 VLAN의 workstation에서 listener를 실행합니다. 예시 `eth0` class A 측정값은 약 39,012kbps입니다.
./tsn_listener -d 18:03:73:66:87:42 -i enp5s0 -s 1500
21. 기본 구성으로 복원하려면 `eth1.100`, `eth0.100`을 삭제하고 `eth1`, `eth0`의 root Qdisc를 제거합니다. 두 포트의 FIFO3/FIFO2 bandwidth가 0으로 돌아간 뒤 TX 큐를 하나로 설정합니다.
ip link del eth1.100
ip link del eth0.100
tc qdisc del dev eth1 root
tc qdisc del dev eth0 root
ethtool -L eth0 rx 1 tx 1
목표 rate보다 1Mb/s 크게 설정한 idleslope입니다.
12) ::
// Map skb->priority to traffic class for Eth1:
// 3pri -> tc0, 2pri -> tc1, (0,1,4-7)pri -> tc2
// Map traffic class to transmit queue:
// tc0 -> txq2, tc1 -> txq3, tc2 -> (txq6, txq7)
$ tc qdisc replace dev eth1 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@2 1@3 2@6 hw 1
13) ::
// Check classes settings
$ tc -g class show dev eth1
+---(100:ffe2) mqprio
| +---(100:7) mqprio
| +---(100:8) mqprio
|
+---(100:ffe1) mqprio
| +---(100:4) mqprio
|
+---(100:ffe0) mqprio
+---(100:3) mqprio
14) ::
// Set rate for class A - 31 Mbit (tc0, txq2) using CBS Qdisc for Eth1
// here only idle slope is important, others ignored, but calculated
// for interface speed - 100Mb for eth1 port.
// Set it +1 Mb for reserve (important!)
$ tc qdisc add dev eth1 parent 100:3 cbs locredit -1035 \
hicredit 465 sendslope -69000 idleslope 31000 offload 1
net eth1: set FIFO3 bw = 31
15) ::
// Set rate for class B - 11 Mbit (tc1, txq3) using CBS Qdisc for Eth1
// Set it +1 Mb for reserve (important!)
$ tc qdisc add dev eth1 parent 100:4 cbs locredit -1335 \
hicredit 405 sendslope -89000 idleslope 11000 offload 1
net eth1: set FIFO2 bw = 11
16) ::
// Create vlan 100 to map sk->priority to vlan qos for Eth1
$ ip link add link eth1 name eth1.100 type vlan id 100
net eth1: Adding vlanid 100 to vlan filter
17) ::
// Map skb->priority to L2 prio for Eth1.100, one to one
$ ip link set eth1.100 type vlan \
egress 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
18) ::
// Check egress map for vlan 100
$ cat /proc/net/vlan/eth1.100
[...]
INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0
EGRESS priority mappings: 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
19) ::
// Run appropriate tools with socket option "SO_PRIORITY" to 3
// for class A and to 2 for class B. For both interfaces
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p2 -s 1500&
./tsn_talker -d 18:03:73:66:87:42 -i eth0.100 -p3 -s 1500&
./tsn_talker -d 20:cf:30:85:7d:fd -i eth1.100 -p2 -s 1500&
./tsn_talker -d 20:cf:30:85:7d:fd -i eth1.100 -p3 -s 1500&
20) ::
// run your listener on workstation (should be in same vlan)
// (I took at https://lore.kernel.org/r/[email protected]/)
./tsn_listener -d 18:03:73:66:87:42 -i enp5s0 -s 1500
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39012 kbps
Receiving data rate: 39000 kbps
21) ::
// Restore default configuration if needed
$ ip link del eth1.100
$ ip link del eth0.100
$ tc qdisc del dev eth1 root
net eth1: Prev FIFO2 is shaped
net eth1: set FIFO3 bw = 0
net eth1: set FIFO2 bw = 0
$ tc qdisc del dev eth0 root
net eth0: Prev FIFO2 is shaped
net eth0: set FIFO3 bw = 0
net eth0: set FIFO2 bw = 0
$ ethtool -L eth0 rx 1 tx 1
요약·해설
cpsw.rst:1-587CPSW의 CBS shaper는 외부 포트마다 3개뿐이므로 rate를 지정할 class와 큐를 앞쪽부터 배치해야 합니다. MQPRIO는 socket priority를 traffic class와 TX 큐에 연결하고, VLAN egress map은 같은 priority를 L2 PCP로 전달하며, CBS는 각 class의 실제 송신 rate를 hardware FIFO에서 제한합니다.
응용 프로그램의 socket priority가 hardware shaper에 도달하는 순서입니다.
한 포트와 두 포트 예제에서 공통 TX 큐를 사용하는 방식입니다.
각 계층의 설정이 이어졌는지 확인하는 인터페이스입니다.