Deterministic Ethernet

A control frame that is 20 microseconds late for its slot waits almost a whole 1 ms cycle. Time-aware shaping, LaunchTime and PTP clocks keep it on time.

Drag Frame ready past 18 microseconds and watch the frame miss its gate. Switch LaunchTime on, then skew the clock. Then we build, piece by piece, the clocks, the shaper and the schedule underneath.

You need a rough idea of what an Ethernet frame is (a labelled packet of bytes on a wire) and a little C or shell. We build the rest from zero.

Built from primary sources, not a course: the Linux tc-taprio and tc-etf man pages, the linuxptp project, Fejes, Antal and Kerekes, The TSN Building Blocks in Linux, and the IEEE 802.1 working-group error-budget notes. The full list is in the Field Guide.

Land a frame in its gate

5 µs
0 µs

A model, not a measurement. One control class owns a 20 µs window at the start of every 1,000 µs cycle on a 1 Gbit/s link. Time on the wire is (frame bytes + 20 bytes of preamble and gap) × 8 ns. Clock skew is the talker’s clock minus the switch’s clock.

Chapter 0

The Frame That Waited a Whole Cycle

See why an Ethernet cable that is fast on average can still be late exactly when a robot needs it

A robot arm has a controller in the cabinet and a motor drive in the wrist. Every millisecond the controller sends the drive one small frame: the torque to apply next. The drive expects it at the same moment every cycle. If the frame comes 2 ms late, the arm acts on old news.

That same cable also carries a camera stream, a log upload and a status page. All of them are Ethernet frames: labelled bundles of bytes that cross a wire one at a time. The wire sends one frame at a time. Frames that arrive while it is busy stand in a queue.

Now put numbers on the queue. A full-size frame is 1,518 bytes, and the wire adds 20 more bytes of preamble and gap. That is 1,538 bytes, or 12,304 bits. At 1 Gbit/s the frame takes 12.3 µs. At 100 Mbit/s it takes 123 µs. Our torque frame is 200 bytes and needs 1.76 µs. Yet if it queues behind a video frame, it waits for the whole 12.3 µs first.

One video frame is not the worst case. A switch (the box that forwards frames between cables) can hold a dozen of them ahead of ours. Ordinary Ethernet gives the average a good deal and the worst case nothing. A control loop lives on the worst case.

Give the control frame a slot

The fix is old and simple. Do what a railway does: publish a timetable. Every cycle (a fixed span that repeats, here 1,000 µs) is cut into slots. Each slot belongs to one traffic class, a label that groups frames of the same kind. Control frames get one slot. Video gets another. Everything else gets the rest.

Each class has a gate in front of its queue. A closed gate holds the class’s frames back. An open gate lets them out. A list of “at this time, open these gates” repeats every cycle. This is the time-aware shaper, standardised as IEEE 802.1Qbv, and Chapter 3 builds it.

The control gate opens for 20 µs at the start of each cycle. Nothing else may use the wire then. A 12.3 µs video frame can no longer sit in front of our frame, because the switch refuses to start it unless it finishes before the control gate opens.

The price of a timetable

A timetable is rigid. A frame that is ready one moment after its slot has closed must wait for the next one. Say our frame is ready 20 µs after the cycle starts. The window closed at 20 µs. The frame waits 980 µs, then needs 1.76 µs more. It was on time for a bus that left 20 µs ago.

So the shaper turns “sometimes slow” into “exactly on time or a whole cycle late”. That is a good trade, because you can now reason about it. But it puts two jobs on you. First, the sender must hand the frame to the wire at the right moment. That is LaunchTime, Chapter 4. Second, the sender and the switch must agree what time it is, to within a few microseconds. That is PTP, Chapters 1 and 2.

Try it in the instrument at the top of the page. Move Frame ready past 18 µs: the 1.76 µs frame no longer fits before the window closes. Switch on LaunchTime and the NIC (the network interface card) sends it at the window’s start. Then skew the clock and watch the schedule slip.

How many slots should a cycle have?

One slot per cycle means an average wait of nearly half the cycle for a frame that is ready at a random time. More slots cut the wait. But every slot reserves wire time that no other class can use. This device lets you spend that reservation.

Count the slots, count the wait

The curve shows how long a frame waits if it is ready at each moment of the cycle. Each slot is 20 µs long. Pick how many slots share the 1,000 µs cycle.

Exact for this toy: frames ready at a uniformly random moment, slots of 20 µs spaced 1,000/n µs apart, frame time ignored. With a gap g = 1,000/n − 20 between slots, the average wait is g² / (2 × 1,000/n) and the worst wait is g. Illustrative numbers, not a measurement.

The curve is a sawtooth. Right after a slot closes the wait is longest, then it falls in a straight line to zero at the next slot. Ten slots cut the average wait from 480 µs to 32 µs. They also reserve 20% of the link for control frames that are 200 bytes each. That reservation is the price of a short wait. It is why real schedules pick slots with care.

1 slot: 980² / (2 × 1,000) = 480.2 µs   10 slots: 80² / (2 × 100) = 32 µs

On real hardware. Take two Linux PCs with Intel i225 or i226 network cards and a cable. Send one 200-byte frame every 500 µs with the isochron tool and compare the transmit timestamps with the plan. Fejes, Antal and Kerekes did this on i225-LM cards and report the result in Chapter 4.

The road

  1. PTP on the wire: the clock inside the NIC, and how Linux uses it.
  2. gPTP and profiles: how many hops can a clock cross before the error eats the budget?
  3. The time-aware shaper and taprio: the gate list as a Linux command.
  4. LaunchTime, etf and SO_TXTIME: sending at an exact nanosecond.
  5. Preemption, credit shaping and FRER: three more tools in the TSN box.
  6. Robot and car Ethernet at fleet scale: one switch that forgot to sync.
  7. TSN, EtherCAT or CAN: choosing the right kind of determinism.
  8. Field Guide: numbers, checklist, code and sources.
The control gate is open for the first 20 µs of each 1,000 µs cycle. A 200-byte frame is ready at 25 µs. What happens?

Chapter 1

PTP on the Wire: The Clock Inside the NIC

Follow a time stamp from a cable to the clock your program reads, and find the one step people forget

Two machines, one cable, one schedule. The schedule says “open the control gate at 0 µs of every cycle”. That sentence only works if both machines agree on when 0 is. Each machine keeps time with a crystal oscillator, a tiny quartz part that ticks at a fixed rate. No crystal ticks at exactly the printed rate.

The IEEE 802.1 working group planned for crystals that run up to 100 ppm fast or slow. A ppm is one part in a million. A clock that is 100 ppm fast gains 100 µs every second. That is 8.64 seconds per day. Two such clocks drift apart by up to 200 µs per second. Our control window is 20 µs wide. Free-running clocks lose the schedule in a tenth of a second.

PTP: measure, then correct

PTP is the Precision Time Protocol, IEEE 1588. One clock, the grandmaster, is the reference. Everyone else measures how far off they are and steers toward it. The measuring uses four time stamps from one round trip of small messages.

The grandmaster sends a Sync message and notes when it left: t1. The follower notes when it arrived on its own clock: t2. The follower then sends a delay request at t3 on its clock. The grandmaster notes the arrival at t4. The lesson Time and Sync derives this fully. Here is the result.

offset
How far the follower’s clock is ahead of the grandmaster’s. The follower subtracts it.
t2 − t1
The Sync trip as the follower sees it: true travel time plus the offset.
t4 − t3
The return trip: true travel time minus the offset.
delay
The one-way travel time, assuming both directions take the same time. If they do not, the difference becomes offset error.

t1 = 1,000 ns, t2 = 1,030, t3 = 1,200, t4 = 1,210  →  offset = (30 − 10) / 2 = 10 ns, delay = (30 + 10) / 2 = 20 ns

Where the time stamp is taken

The formula is only as good as the four stamps. Take them in software and each one carries the noise of an interrupt: the driver wakes up, reads the clock, and a few microseconds have passed. Take them in hardware and the NIC stamps the frame as it leaves or enters the wire. The PHC, the PTP hardware clock, is a counter inside the NIC that does exactly this. Linux shows it as a device such as /dev/ptp0.

You check what a NIC can do with ethtool -T eth0. Look for hardware-transmit, hardware-receive and a PTP Hardware Clock number that is not none. The Linux PTP project (linuxptp) also supports software stamping, but the project notes you must ask for it with -S. It is a fallback, not a goal.

Two clocks, two programs

Here is the step people forget. A PTP-capable machine has two clocks that matter. The PHC lives in the NIC. CLOCK_REALTIME is the clock your programs read with clock_gettime. They are different counters. The program ptp4l runs the protocol and steers the PHC. A second program, phc2sys, copies the PHC into the system clock. A third, ts2phc, goes the other way: it feeds the PHC from a pulse-per-second signal, for example from a GNSS receiver.

Watch two clocks settle

Purple is the NIC clock. Blue is the system clock your program reads. The scale is logarithmic: each gridline is ten times larger. Switch the stamping mode and the second program, and watch both lines.

Illustrative model. The start offset is 100 µs and the servo settles in a few seconds. Hardware stamps add about 30 ns of noise and software stamps about 5 µs; the system clock free-runs at 50 ppm (50 µs per second) when phc2sys is off. These are made-up round numbers to show the shape, not measurements.

With phc2sys stopped the system clock walks away at 50 µs every second, while ptp4l happily reports a tiny offset for the NIC. After ten seconds that is 500 µs: far outside a 20 µs window. Everything looks “synced”, and nothing is.

shell# 1. does this NIC stamp in hardware?
$ ethtool -T eth0
# look for: hardware-transmit, hardware-receive, PTP Hardware Clock: 0

# 2. run the protocol and steer the NIC clock (gPTP profile ships with linuxptp)
$ sudo ptp4l -i eth0 -f gPTP.cfg -m

# 3. copy the NIC clock into the clock your programs read
$ sudo phc2sys -s eth0 -c CLOCK_REALTIME -w -m

# 4. ask ptp4l what it believes (stepsRemoved, offsetFromMaster, meanPathDelay)
$ pmc -u -b 0 'GET CURRENT_DATA_SET'

The symptom is “ptp4l says offset 20 ns but my timestamps disagree by milliseconds”. The measurement is to compare the two clocks directly. The fix is to run phc2sys, and to check that it did not exit.

Boundary and transparent clocks

Switches sit between machines. A switch that ignores PTP adds a random queueing delay to every Sync message. So PTP networks use switches that take part. They come in two kinds, and linuxptp implements both.

Clock typeWhat it does with a Sync messageCost
Ordinary clockAn end station with one port. It follows or leads.None. It is the endpoint.
Boundary clockEnds the protocol on each port. It follows upstream, then leads downstream with its own fresh messages.Runs a clock servo per switch.
Transparent clockPasses the message on, and adds how long it sat inside the switch to a field in the message.Needs a hardware stamp at every port.

For gPTP, the profile this lesson uses in Chapter 2, every switch must be a boundary or transparent clock. A switch that is neither ends the sync. Chapter 6 shows what that does to a fleet.

On real hardware. On a Linux PC with an Intel i210, i225 or i226 card, run the four commands above and stop phc2sys. Read date +%s%N on both machines at the same instant and watch the difference grow by tens of microseconds per second. On an STM32 Nucleo-H563ZI, find the Ethernet chapter of the reference manual and check that the MAC lists IEEE 1588 time stamping before you plan a design around it.

ptp4l reports an offset of 20 ns on a robot’s NIC. A log from the control program is 300 µs ahead of the grandmaster. What do you check first?

Chapter 2

gPTP and the Error Budget

Count how many hops a clock can cross before small errors add up to a missed gate

A mobile robot has a lidar, four cameras, a compute box and a motor controller. They sit behind three small switches, daisy-chained to save cable. The grandmaster clock lives on the compute box. The last camera is four hops away. Each hop passes time along, and each hop is a little wrong.

The question is simple: how wrong is the last node? Add the small errors and compare the sum with what the schedule can bear. This chapter shows the sum. It also names the profile that makes the sum small.

What gPTP changes

Plain PTP offers many options: different transports, different message rates, switches that may ignore it. A profile is a fixed set of choices that makes devices from different makers work together. gPTP, the generalised PTP, is the profile in IEEE 802.1AS. It is the one TSN uses.

gPTP makes four choices. It runs directly on Ethernet frames (layer 2), not on IP. It needs every switch on the path to be a boundary or transparent clock, so no device ignores it. It measures every link’s delay with a peer delay exchange, which happens on each link whether or not a Sync is passing. And it uses a numbered domain so that several time scales can share one network.

Peer delay is the same four-stamp trick as Chapter 1, but across one link. A node sends Pdelay_Req at t1. Its neighbour stamps arrival at t2, answers with Pdelay_Resp at t3, and the first node stamps that arrival at t4. The link delay is half of the round trip minus the neighbour’s turnaround time: ((t4 − t1) − (t3 − t2)) / 2. The node also compares the neighbour’s clock rate with its own, a number called the neighbour rate ratio.

Why measure every link ahead of time? Because it takes the guessing out of a hop. When the Sync arrives, the node already knows the link delay and the switch’s residence time. It adds them to a running total as the message travels. A link whose measured delay is too large is not used. For copper links the common threshold is 800 ns, which vendor documents give for 100BASE-TX and 1000BASE-T, citing a draft 802.1AS corrigendum.

The budget, in numbers

Where did “1 µs over 7 hops” come from? From a 2009 set of slides by Geoffrey Garner for the IEEE 802.1 AVB task group. They list the assumptions a network must meet to reach the goal. The goal came from digital audio: AES11 asks for sync at about this level. The network is at most 7 hops across. Local crystals are within 100 ppm.

The slides then list what each hop may add. For 100 Mbit/s Ethernet the PHY (the chip that drives the wire) delays the two directions by slightly different amounts. A design can measure and cancel most of that, but 86 ns per hop remains. The clock that stamps frames ticks in steps, which adds up to 40 ns per hop. Seven hops give 602 ns plus 280 ns plus 7 ns for other terms.

7 hops: 7 × 86 = 602 ns  +  7 × 40 = 280 ns  +  7 ns  =  889 ns  →  margin 1,000 − 889 = 111 ns

The slides give a second case: gigabit links with a 125 MHz stamping clock. Their rounding is finer (8 ns per hop) but the PHY term is worse (120 ns per hop). The total is 840 + 56 + 7 = 903 ns, a margin of 97 ns. Both cases pass with 7 hops. Both are close to the limit.

Climb the hop ladder

Each bar is the worst-case error at that hop. The dashed line is the 1,000 ns budget. Choose a case, drag the hop count, then give one node software time stamps.

7

The per-hop terms and the 7-hop totals (889 ns and 903 ns, margins 111 ns and 97 ns) are from Garner’s January 2009 slides. Hop counts other than 7 extend the same per-hop sums in a straight line, plus the fixed 7 ns: that is our extrapolation, not the standard’s. The software-stamp error of 5,000 ns is illustrative.

Drag past 7 hops and the bars cross the line at hop 8 in both cases. Under these assumptions the budget does not stretch to eight hops. Real systems use better hardware than the 2009 assumptions, and vendors state their own numbers. But the lesson stays: errors add per hop, so shorter chains give more margin.

When one node cheats

Now the failure. One camera in the fleet has a NIC with no hardware time stamping. It still runs ptp4l. It still reports “synced”. But its stamps carry the noise of an interrupt. Fejes, Antal and Kerekes measured software receive stamps that strayed up to 15 µs from the plan in their test, against nanoseconds for hardware. That eats most of a 20 µs window before any other delay is counted.

The error stays on that node, so the rest of the fleet looks healthy. The symptom is one camera whose frames always miss the video gate. The measurement is ethtool -T on that node: no hardware-transmit. The fix is a different NIC, or a different slot.

Profiles for cars

A car is a harder network than a lab bench. It mixes safety-critical and comfort traffic, and it must keep working when a link fails. IEEE project P802.1DG defines a TSN profile for automotive in-vehicle Ethernet. Its authorisation request was approved in February 2019. A profile like this says which TSN tools a car must use and which settings they take. Check the IEEE 802.1 project page for its current status.

On real hardware. Connect an STM32 Nucleo-H563ZI (or any board whose manual lists IEEE 1588 stamping) and a Linux PC through a gPTP switch. Run pmc -u -b 0 'GET TIME_STATUS_NP' on the PC and watch master_offset settle. Then add one more switch and compare. Repeat per hop.

Under the 100 Mbit/s case, 7 hops add up to 889 ns of worst-case error. What happens at 8 hops, extending the same per-hop terms?

Chapter 3

The Time-Aware Shaper and taprio

Write a gate schedule as a Linux command and see why every switch on the path must keep the same time

You are the network designer for the robot from Chapter 2. You have three kinds of traffic: torque commands every millisecond, a camera stream, and everything else. You must write down who may use the wire and when. This chapter writes that down, first as a picture and then as a command.

The gate control list

Each egress port (the side of a switch or NIC where frames leave) has one queue per traffic class. The standard IEEE 802.1Qbv puts a gate between each queue and the wire. A table called the gate control list says which gates are open during each stretch of time. The table repeats forever.

Each row of the table has two things: a set of open gates, and how long the row lasts. The sum of the row times is the cycle time. The Linux man page for tc-taprio says exactly this: the cycle time is the sum of all the intervals of the entries in the schedule.

Our schedule has three rows. Row one opens the control gate for 20 µs. Row two opens the video gate for 400 µs. Row three opens the best-effort gate for 580 µs. They add up to 1,000 µs. Only one gate is open at a time, so one class owns the wire at any moment.

The guard band

A gate that closes mid-frame would cut the frame in half. So the shaper follows a rule: it starts a frame only if the frame can finish before its gate closes. The unusable time at the end of each window is the guard band. Its size is the transmit time of the largest frame that class may send.

Look at the cost for our schedule. The best-effort window is the last row, and the control window follows it. Best-effort frames may be 1,518 bytes. At 1 Gbit/s a frame takes 12.3 µs. So the shaper stops starting best-effort frames 12.3 µs before the cycle ends, and the wire sits idle for up to that long. That is 1.2% of the cycle. At 100 Mbit/s the same guard band is 123 µs, which is 12.3% of the cycle. Slow links pay dearly. Chapter 5 shows how frame preemption shrinks this cost.

guard band = (1,518 + 20) × 8 bits / link rate   1 Gbit/s: 12.3 µs (1.2%)   100 Mbit/s: 123.0 µs (12.3%)

As a Linux command

Linux calls its time-aware shaper taprio, a queueing discipline (qdisc, the kernel’s name for the code that orders frames before the NIC). Here is our schedule written for it.

shell# 3 traffic classes; priority 3 -> TC0 (control), priority 2 -> TC1 (video), the rest -> TC2
$ sudo tc qdisc replace dev eth0 parent root handle 100 taprio \
    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 \
    base-time 0 \
    sched-entry S 01 20000 \
    sched-entry S 02 400000 \
    sched-entry S 04 580000 \
    flags 0x2
# cycle = 20,000 + 400,000 + 580,000 ns = 1,000,000 ns = 1 ms

Read it line by line. num_tc 3 makes three classes. map sends each of the 16 frame priorities to a class. queues 1@0 1@1 2@2 gives class 0 one hardware queue starting at queue 0, class 1 one queue at queue 1, and class 2 two queues starting at queue 2. Each sched-entry is a command S (set gates), a gate mask, and a length in nanoseconds. In the mask, bit N opens class N, so 01 opens only the control class.

The flag 0x2 asks for full offload: the NIC runs the table in hardware. The flag 0x1 asks for txtime-assist, which uses software and the etf qdisc of Chapter 4. They cannot be combined. In full offload you leave out clockid, because the clock is the NIC’s own PHC.

Why the cycle must be PTP-aligned

The command gives base-time 0. The man page explains that when the base time is in the past, the schedule starts at the base time plus a whole number of cycles, the smallest one that lies in the future. So with a 1 ms cycle and base time 0, every window opens on a whole millisecond of PTP time. Two machines running the same command open their gates at the same instant, as long as their PHCs agree. That is the only reason their schedules line up.

Now see what skew does along a path. A control frame leaves switch 1 at the start of its window, travels, and reaches switch 2. Switch 2 has its own gate. Each hop spends a little time forwarding the frame. If the clocks agree, the frame meets an open gate at each hop. If switch 2 runs ahead, its gate has already closed.

Send a frame down four gates

Each row is one switch. Teal is its control window in true time. The orange block is the frame. Set how far each switch’s clock drifts from the one before it, and how long the window is.

0 µs
20 µs

A model. The 200-byte frame needs 1.76 µs on a 1 Gbit/s wire, and each hop adds a 3 µs delay for forwarding and the wire (an illustrative figure). A negative skew means the next switch’s clock runs ahead, so its window opens earlier in true time. The 1,000 µs cycle is the one from Chapter 0.

Set the skew to −5 µs. Hop 2 still catches the frame. Hop 4 does not: its window ended at 5 µs and the frame arrives at 9 µs. The frame waits a whole cycle at hop 4, and the trip takes about 987 µs, because hop 4’s next window opens at 985 µs of true time. Make the window wider and it fits again. That is the real trade: a wide window absorbs skew but takes more of the link from other classes.

Now the symptom as an engineer meets it. Frames arrive on time most cycles, but a few miss. The same ones miss every time, at the same offset into the cycle. The measurement is to take hardware transmit stamps and reduce them modulo the cycle time. If they cluster at a window’s edge, your clocks disagree with your table. The fix is to check pmc on every node, and check that all gate lists share one cycle and one base time.

On real hardware. Use two PCs with Intel i225 or i226 cards and a cable. Run tc -d qdisc show dev eth0 to see the schedule, apply the command on both, then use isochron to send a 200-byte frame every cycle and read the transmit stamps. Move one PC’s PHC with phc_ctl by 10 µs and watch the stamps move out of the window.

A schedule has intervals of 20,000, 400,000 and 580,000 ns. A best-effort frame of 1,518 bytes is ready 5 µs before its gate closes on a 1 Gbit/s link. What does the shaper do?

Chapter 4

LaunchTime, etf and SO_TXTIME

Hand the NIC a frame and the exact nanosecond to send it, so the program no longer has to be on time

The gate opens at 0. Your control program wakes up at 0 and calls sendto. The frame still has a long way to go. The call enters the kernel. The data is copied. The frame passes the qdisc and the driver. The NIC fetches it by DMA (direct memory access, the card reading RAM on its own). Each step takes a variable time. The frame leaves the wire a little after 0, and “a little” changes every cycle.

Fejes, Antal and Kerekes measured this on Intel i225-LM cards, with a 500 µs cycle and a program that slept until the planned moment and then sent. For 80 percent of the frames, the software transmit stamp fell within 1.5 µs of the plan. The worst frame in their sample was off by 3.5 µs. On the receive side the worst software stamp differed by 15 µs.

3.5 µs is small. It is also larger than the gap that matters when a window is 4 µs wide. A window that narrow is not strange: it is how you fit many slots in one cycle.

Send it early, and say when

The fix moves the timing out of the program. The program hands over the frame early, with a label that says “put this on the wire at time T”. A queue holds the frame until T is near. At the right moment something releases it. If that something is the NIC’s own hardware clock, the wire time is exact to the NIC’s clock.

Linux gives you three parts. SO_TXTIME is a socket option that lets a program attach a transmit time to each frame, using a control message called SCM_TXTIME that holds a 64-bit count of nanoseconds. etf, the earliest-txtime-first qdisc, keeps frames in a tree sorted by that time. And LaunchTime is the NIC feature that releases the frame at its time. You switch it on with the offload flag.

c/* 1. tell the kernel this socket carries transmit times, measured on CLOCK_TAI */
struct sock_txtime cfg = { .clockid = CLOCK_TAI, .flags = SOF_TXTIME_REPORT_ERRORS };
setsockopt(fd, SOL_SOCKET, SO_TXTIME, &cfg, sizeof(cfg));

/* 2. for each frame, attach "send at this nanosecond" as a control message */
char ctrl[CMSG_SPACE(sizeof(uint64_t))] = {0};
struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1,
                     .msg_control = ctrl, .msg_controllen = sizeof(ctrl) };
struct cmsghdr *cm = CMSG_FIRSTHDR(&msg);
cm->cmsg_level = SOL_SOCKET;
cm->cmsg_type  = SCM_TXTIME;
cm->cmsg_len   = CMSG_LEN(sizeof(uint64_t));
*(uint64_t *)CMSG_DATA(cm) = txtime_ns;     /* e.g. next window start, in TAI ns */
sendmsg(fd, &msg, 0);
shell# put etf under a classful qdisc, on the control class's queue (from tc-etf(8))
$ sudo tc qdisc replace dev eth0 parent 100:1 etf \
    clockid CLOCK_TAI delta 300000 offload

Two details of etf decide whether this works. First, delta is a margin for scheduler latency: etf wakes up at the frame’s time minus delta, and passes the frame down. With delta 300,000 ns, that is 300 µs early. Second, a frame whose time is already past is dropped. So the program must hand over each frame earlier than delta before its time. If your control loop runs at 1 kHz and sends the frame for cycle n+2 during cycle n+1, there is a whole cycle of margin.

When taprio runs in txtime-assist mode (flag 0x1), it sets the transmit times itself and relies on etf below it. The man page asks that its txtime-delay, the longest time a frame may spend between taprio and the NIC, be larger than the etf delta.

What the NIC adds

Not every NIC has LaunchTime. The Linux igb driver added it for the Intel i210 in 2018. The igc driver added etf offload for the i225 in Linux 5.8, and later patches describe launch time on the i226. Always check the driver and the card, not just the model name.

With LaunchTime on the i225-LM, the same authors report a very different picture: in their sample the average difference between plan and the wire was 5 ns and the worst was 11 ns.

Send 100 frames, count the misses

Each dot is one cycle: how late the frame left its planned moment. The line is the latest start that still fits the window. Narrow the window and compare the two ways of sending.

4 µs

Illustrative samples shaped to two numbers from Fejes, Antal and Kerekes on i225-LM cards: sleep-and-send, 80% of frames within 1.5 µs and the worst at 3.5 µs; LaunchTime, 5 ns on average and 11 ns at worst. The dots are seeded random draws, and we count every delay as late, which is the harsh case. The frame is 200 bytes and needs 1.76 µs.

At a 4 µs window, the line sits at 2.24 µs. In this sample sleeping misses it for 14 frames in a hundred, and each miss costs a full 1,000 µs cycle. LaunchTime never touches the line. The count in the read-out is the point: 14 late frames in a hundred is a 1 kHz control loop that glitches about 140 times a second.

The symptom of a bad setup is easy to confuse with this. You run etf on a NIC that has no LaunchTime, or you forget offload. The command is accepted. The frames are now released by a kernel timer, and the jitter returns to the microseconds of the software path. The measurement is a hardware transmit stamp against the planned time. The fix is a card that supports it, and a driver that reports it.

On real hardware. Take two PCs with Intel i225 or i226 cards. Use the isochron tool, once with sleep-and-send and once with SO_TXTIME and etf offload, at a 500 µs cycle. Compare the hardware transmit stamps against the plan for 10,000 frames. On a micro-controller, the same idea is a timer-triggered DMA to the MAC; check the reference manual for a transmit-time or timestamp-trigger feature.

A program sets txtime to 200 µs from now, and etf has delta 300 µs. What happens?

Chapter 5

Preemption, Credit Shaping and FRER

Learn three more TSN tools, each fixing one problem the gate schedule leaves open

The time-aware shaper solves the big problem: it gives control frames a slot. But it leaves three smaller problems. A large frame in flight still blocks an urgent one. A busy stream can still hog its slot. And a cut cable still loses frames. Three more standards address these, one each.

Frame preemption: stop a big frame to send a small one

Chapter 3 showed the guard band: the wire sits idle before a window so a big frame cannot spill into it. Frame preemption removes most of that idle time. A MAC (the part of the NIC that builds frames) can pause a long frame in the middle, send an urgent one, and then resume the long one. The two standards are IEEE 802.1Qbu, which says which traffic may interrupt, and IEEE 802.3br, which defines how a frame is split.

Traffic on the express MAC may interrupt. Traffic on the preemptable MAC may be paused. A paused frame goes out in pieces called fragments, each with a small header and check value. Fejes, Antal and Kerekes give the worst case without it: on a 100 Mbit/s link with a 9,000-byte MTU, one frame takes 720 µs, while a 64-byte urgent frame needs only 5.12 µs.

The cut is not free. Documents from Intel and Texas Instruments say a preemptable frame must have sent at least 60 bytes before the cut, and at least 64 bytes must remain to send afterwards. So a frame shorter than 124 bytes is never cut. These are rules from vendor documentation of the standards; check the standard text before you design around the exact numbers.

This changes the guard band of Chapter 3. With preemption, the largest frame that cannot be cut is 123 bytes, so the shaper only has to reserve the time of a 123-byte frame before a window. At 1 Gbit/s that is (123 + 20) × 8 bits / 1 Gbit/s = 1.14 µs, not 12.3 µs. The idle cost of a gate edge falls by a factor of about eleven. The price is a MAC that supports the feature at both ends of every link.

Credit-based shaper: no stream may hog the slot

The credit-based shaper (CBS), IEEE 802.1Qav, spaces out frames of one stream. Think of a bucket of credit. While a frame is waiting, credit fills at a rate called the idleslope. While a frame is sent, credit drains at the sendslope. A frame may start only when credit is not negative.

The slopes follow from the link rate. The tc-cbs man page gives sendslope = idleslope − port rate. On a 1 Gbit/s port with an idleslope of 20 Mbit/s, the sendslope is −980 Mbit/s. A 1,500-byte frame lasts 12 µs, and drains 980 Mbit/s × 12 µs = 11,760 bits, or 1,470 bytes, of credit. That is the man page’s locredit of −1470. Then credit refills at 20 Mbit/s: 11,760 bits / 20 Mbit/s = 588 µs.

frame 12 µs + refill 588 µs = 600 µs between frames  →  1,500 B × 8 / 600 µs = 20 Mbit/s, the idleslope

FRER: send everything twice

A cut cable loses frames for as long as it takes to detect the cut and reroute. FRER, frame replication and elimination for reliability (IEEE 802.1CB), sends each frame along two different paths at once. The sender adds a sequence number in a tag. The receiver keeps the first copy of each number and drops the second. If one path fails, the other copy still arrives, with no gap and no re-send.

The sequence number is what makes this work. Without it, the receiver cannot tell a duplicate from a new frame that happens to look the same. The sender stamps frame 7 on both paths. The receiver sees 7 twice and passes it up once. Copies that arrive late, after a newer number has already been passed, are also dropped. The cost is double the traffic for every protected stream, so teams protect only the streams that cannot lose a frame.

Try each tool on its own problem

1 µs

Take the preemption view with the tool off. A 1,518-byte frame starts at 0. The urgent frame is ready at 1 µs but waits until 12.3 µs. Turn preemption on. The big frame has already sent more than 60 bytes, so the urgent frame goes at once, at 1 µs, and finishes at 2.8 µs. The big frame ends only 1.8 µs later than before. Preemption cut the urgent frame’s wait from 11.3 µs to none.

On the FRER view, turn recovery off. Every frame before the cut arrives twice, and your application sees 12 deliveries for 8 frames. Duplicates are the bug that appears when a team adds redundancy and forgets the elimination step. A robot that applies a torque command twice is not a hypothetical.

On real hardware. For CBS, apply the man page example on an i225 and confirm with tc -s qdisc show. For FRER you need switches that implement 802.1CB; vendors such as Microchip document their configuration. For preemption, use a switch or MAC whose data sheet lists 802.3br and look for its express and preemptable counters.

A 1 Gbit/s port has a CBS idleslope of 20 Mbit/s. A 1,500-byte frame is sent. About how long until the next frame of that class may start?

Chapter 6

Robot and Car Ethernet at Fleet Scale

Meet the thin cables that carry TSN in vehicles, and see how one misconfigured switch strands a whole branch

Cable is heavy, costly and breaks. A car has kilometres of it. A mobile robot flexes it at every joint. The standard Ethernet cable has four twisted pairs of copper, and a thick connector at each end. For many sensors that is too much.

One pair is enough

100BASE-T1 (IEEE 802.3bw) runs 100 Mbit/s over a single twisted pair. 10BASE-T1S (IEEE 802.3cg, 2019) runs 10 Mbit/s over one pair too, and it can share that pair among several nodes. Both speak ordinary Ethernet frames, so the same software stack, and the same TSN tools, work on top. Industry notes describe 10BASE-T1S as a way to replace older buses such as CAN for sensors and actuators.

Sharing one pair among eight nodes raises an old problem: who talks when? Classic shared Ethernet used collisions and backoff, which gives no bound on delay. 10BASE-T1S offers an optional fix called PLCA, physical layer collision avoidance. One node (number 0) sends a beacon that starts a cycle. Each node then gets one turn, in order. A node with nothing to say lets its turn pass quickly.

That gives a bound. Suppose all eight nodes send one minimum frame of 64 bytes in a cycle. Each frame needs (64 + 20) × 8 bits / 10 Mbit/s = 67.2 µs on the wire. Eight of them take about 538 µs. So a node waits at most about one such cycle for its turn. This ignores the beacon and the small gaps between turns, so treat it as a lower bound on the cycle.

(64 + 20) × 8 / 10 Mbit/s = 67.2 µs per frame  →  8 nodes × 67.2 = 537.6 µs (before beacon and gaps)

The fleet problem

A lab has one robot and one engineer who knows every switch. A fleet has fifty robots, three switch models and a firmware rollout in progress. The time-aware schedule from Chapter 3 only works if every switch on every path takes part in gPTP, with the same domain, the same cycle and sane link delays. One switch that does not breaks everything behind it.

Recall the rule from Chapter 2: a gPTP network needs every switch to be a boundary clock or a transparent clock. A switch that forwards Sync messages like any other frame adds random queueing delay. Neighbours also measure a link delay on each cable; if it exceeds a threshold (800 ns for 100BASE-TX and 1000BASE-T copper in the working-group draft), the port declares itself not gPTP-capable and stops participating.

What happens downstream? The nodes lose their reference. Each falls back to its own crystal, which the 802.1 working group assumed could be up to 100 ppm off. 100 ppm is 100 µs of drift each second. Control windows are 20 µs wide. After a quarter of a second the node is outside its gate.

Plan what to log before the first failure. For each node, export three numbers: the offset from the grandmaster, the measured mean path delay to the neighbour, and whether the port still counts as gPTP-capable. A drifting path delay often points to a bad cable or a changed PHY before the offset moves. A flag that flips to “not capable” tells you the switch has stopped taking part.

Break one switch

The grandmaster feeds three switches in a chain. Two nodes hang off each switch. Turn gPTP off on a switch, then drag time forward to see which nodes drift out of their gates.

1 s

Illustrative. Each stranded node free-runs at its own crystal rate, between 40 and 100 ppm fast or slow (seeded; the 100 ppm bound is the working-group assumption from Chapter 2). Synchronised nodes are shown as under 1 µs. A frame is judged with the Chapter 0 model: a 200-byte frame, a 20 µs window, LaunchTime on.

Turn off switch 2 and set the time to one second. Switch 1’s nodes are fine. Switch 2’s two nodes and switch 3’s two nodes, four in all, have lost their reference. All four show offsets of 40 to 100 µs after one second. Those that run behind the grid arrive after their gate and wait a whole cycle; those that run ahead arrive early and wait, which hides the fault but delays the frame.

The symptom on the robot is odd: some units miss deadlines, some do not, and it changes with the firmware batch. The measurement is to ask every node for its offset from the grandmaster, for example with pmc on Linux, and to export the number to a dashboard. A node whose offset is above a few microseconds is an island. The fix is to treat switch configuration as code: keep one golden config, diff each switch against it, and alarm on drift in the gPTP, VLAN and gate-schedule settings.

pythondef find_islands(offsets_ns, limit_ns=1000):
    """offsets_ns: {node: offset from grandmaster in ns, or None if not reporting}."""
    return sorted(n for n, o in offsets_ns.items()
                  if o is None or abs(o) > limit_ns)

On real hardware. Build a three-switch chain with a managed switch that lists gPTP in its data sheet. Disable gPTP on the middle switch, read pmc -u -b 0 'GET TIME_STATUS_NP' on a PC behind it, and watch master_offset grow. An STM32 Nucleo-H563ZI on the far end shows the same drift if you log its PHC offset over serial.

A node behind a switch that does not take part in gPTP free-runs on a crystal that is 80 ppm off. How far has its clock drifted after 0.5 seconds?

Chapter 7

TSN, EtherCAT or CAN: Choosing Determinism

Compare three ways to make a wire predictable and pick the one that fits the hardware you already have

You are building a robot arm with twelve joints and a head with four cameras. The joints need a torque update every millisecond. The cameras need hundreds of megabits. Someone on the team says “put it all on TSN”. Someone else says “the drives speak EtherCAT”. A third says “CAN is enough for the little sensors”. All three are right about something.

The three differ in how they make timing predictable. That is the useful way to compare them.

Arbitration: CAN

On a CAN bus (controller area network) all nodes share two wires. Each message starts with an identifier, a number that also acts as its priority. When two nodes start together, the lower number wins and the other backs off, without losing a bit. So the most urgent message waits at most for the frame already in progress.

How long is that? The longest classic CAN frame with 8 data bytes and a standard identifier is 135 bits when worst-case stuffing and the pause between frames are counted (a figure in the Linux kernel’s CAN length table). At 1 Mbit/s that is 135 µs. Lower-priority messages wait for everything above them. CAN has no clock sync of its own, and its frames carry 8 bytes (64 with CAN FD). It is cheap, tough and good for small, slow data.

On the fly: EtherCAT

EtherCAT turns the usual idea inside out. A master sends one Ethernet frame that travels down a line of devices. Each device reads the bytes meant for it and writes its own into the same frame as it passes, a trick called processing on the fly. The frame returns to the master carrying everyone’s data. Nothing queues, because only the master sends.

Sources describe cycle times of 100 µs or less. For timing across devices, EtherCAT uses distributed clocks: every device keeps a hardware clock, and the master aligns them. Descriptions put the sync across devices below 1 µs, with vendors reporting tens of nanoseconds in machines; these come from secondary sources, so check the ETG documents for the figure you rely on. The price is a rigid structure: one master, a line or ring, and devices that implement EtherCAT.

Here is a worked limit. Twelve joints each send one 8-byte CAN frame every millisecond on a 1 Mbit/s bus. One frame is 111 bits with no stuffing, so 111 µs. Twelve frames need 1,332 µs, more than the 1,000 µs cycle. With the 135-bit worst case they need 1,620 µs. The bus cannot carry the load, however well it arbitrates. That is the number that moves the joints to EtherCAT.

Scheduled: TSN

TSN is what the rest of this lesson built. It keeps ordinary switched Ethernet and adds clocks (gPTP), gates (Qbv), and optional tools. Its strength is mixing: control, camera and IT traffic share one network, and each class gets guarantees. Its price is the work you saw: clocks on every hop, a schedule that must be consistent, and NICs and switches with the right features.

Pick the determinism for the job

Answer three questions about your robot. The bars add up points from the reasoning in this chapter. They are a rule of thumb, not a standard.

What shares the cable?

What hardware will you buy?

How is it wired?

Rule of thumb, not a measurement. Each answer adds or removes points for each option, from the reasoning in the text: EtherCAT gains with servo drives and chains and loses with mixed traffic; TSN gains with mixed traffic, switched stars and general Ethernet devices; CAN gains with tiny sensors and shared buses and loses with mixed traffic. The 135-bit CAN frame is from the Linux kernel CAN length table; the EtherCAT cycle figure is a secondary source.

Try the robot from the opening. Control only, EtherCAT drives, a daisy chain: EtherCAT wins by a wide margin. Switch to control, video and IT with any Ethernet device on a switched star: TSN wins. Pick tiny sensors on a shared bus and CAN leads. No single answer fits a whole robot, and that is why robots have more than one network.

OptionWhat bounds the delayClock syncFits when
CANPriority arbitration: wait for one frame, up to 135 µs at 1 Mbit/sNone built inSmall messages, cheap nodes, a shared bus
EtherCATOne master, one frame through every deviceDistributed clocks in hardwareServo drives and I/O in a line, cycles of 100 µs or so
TSNGates on a shared schedulegPTP on every hopMixed traffic on one switched network

The failure to avoid is a choice made for fashion. A team picks TSN for the joints because it is the newer standard. Then they find the drives they want speak EtherCAT, and the TSN drive list is short. The symptom is weeks spent on a gateway. The measurement is to list the interface of every part you plan to buy before you pick a network. The fix is to use what the hardware speaks for the joints, and TSN for the rest. The lesson CAN and EtherCAT in firmware goes deeper on the other two.

On real hardware. Put an STM32 Nucleo board with a CAN transceiver on a bus at 1 Mbit/s and send 8-byte frames with two different identifiers at once. Capture with a logic analyser: the lower identifier always wins. Compare the frame length on the scope with the 111-bit minimum and the 135-bit worst case.

Your arm’s servo drives only speak EtherCAT, and nothing else shares that cable. What should carry the joints?

Chapter 8

Field Guide

Keep the numbers, the checklist and a schedule checker, and know where each one came from

Here is the lesson in one paragraph. A switch opens a gate for each class of traffic on a repeating schedule. A frame that misses its gate waits a whole cycle. LaunchTime puts a frame on the wire at an exact time. Both rest on clocks that agree: PTP on the NIC, gPTP on every hop, phc2sys into the system clock. Preemption, credit shaping and FRER add smaller guarantees. EtherCAT and CAN solve the same problem in other ways. Pick what your hardware speaks.

The numbers, with their sources

NumberWhat it isSource and status
12.3 µs / 123.0 µsA 1,518-byte frame plus 20 bytes of preamble and gap at 1 Gbit/s / 100 Mbit/sArithmetic: 1,538 × 8 bits / rate
1 µs over 7 hopsThe 802.1AS time-sync goal, from digital audio needs (AES11)Garner, IEEE 802.1 AVB, Jan 2009 slides
86 + 40 ns per hop, 889 ns, margin 111 nsPHY asymmetry plus stamp granularity at 7 hops (100 Mbit/s case); GbE 125 MHz case is 120 + 8 ns and 97 nsGarner, Jan 2009 slides
100 ppmAssumed free-run crystal accuracy: 100 µs of drift per secondGarner, Jan 2009 slides
800 nsLink delay above which a copper port is not gPTP-capableExtreme Networks gPTP docs, citing a draft 802.1AS corrigendum
1.5 µs / 3.5 µs; 5 ns / 11 nsSleep-and-send: 80% within 1.5 µs, worst 3.5 µs. LaunchTime: average 5 ns, worst 11 nsFejes, Antal, Kerekes, arXiv:2211.14138, i225-LM, 500 µs cycle
720 µs / 5.12 µsA 9,000-byte frame vs a 64-byte frame at 100 Mbit/sSame paper; arithmetic checks
locredit −1470, hicredit 30, sendslope −980000CBS for idleslope 20 Mbit/s on 1 Gbit/s, 1,500-byte framestc-cbs(8) man page; arithmetic checks
60 B sent, 64 B left; under 124 B never cutPreemption fragment ruleVendor docs (Intel, TI); confirm in IEEE 802.3br
135 bitsLongest classic CAN frame, 8 data bytes, with stuffing and pauseLinux kernel include/linux/can/length.h
537.6 µs8 nodes each sending one 64-byte frame on 10BASE-T1S, before beacon and gapsArithmetic, illustrative

Not verified, so not printed as fact: how often job postings name TSN, gPTP or PTP; Wi-Fi time-sensitive features; and 5G bridging to TSN. We could not open a primary source for them in this pass. P802.1DG, the automotive TSN profile, had its authorisation approved in February 2019; check IEEE for its current status.

The checklist

  1. Stamps. ethtool -T on every NIC shows hardware transmit and receive.
  2. Hops. Every switch is a boundary or transparent clock. pmc offsets stay under your budget.
  3. Clocks. ptp4l runs on the NIC, phc2sys runs on the host, and you know which clock each program reads.
  4. Schedule. Every node uses the same cycle and base time. The cycle equals the sum of the entries.
  5. Guard band. You counted the idle time before each window, and decided whether preemption pays for itself.
  6. LaunchTime. The driver supports it, offload is on, delta is larger than your scheduling latency, and every txtime lies in the future.
  7. Redundancy. Every replicated stream has an elimination point.
  8. Network choice. You listed what your drives and sensors speak before you chose.
  9. Fleet. You diff every switch against one golden config and alarm on stranded nodes.

Check a taprio schedule

Edit the command. The checker reads each sched-entry and base-time and reports the cycle, the windows and the guard-band cost.

A teaching checker, not a tool for production. It reads only sched-entry and base-time, counts 20 bytes of preamble and gap per frame, and treats the chosen frame size as the largest frame in every class.

The same checker as Python, the form you would put in a test:

pythonimport re

def check_taprio(cmd, rate_mbps=1000, frame_bytes=1518):
    """Return (cycle_ns, problems) for a tc taprio command string."""
    entries = [(m.group(2), int(m.group(3)))
               for m in re.finditer(r"sched-entry\s+([SHR])\s+(\w+)\s+(\d+)", cmd)]
    base = re.search(r"base-time\s+(\d+)", cmd)
    cycle = sum(ns for _, ns in entries)                  # cycle = sum of the intervals
    frame_ns = (frame_bytes + 20) * 8 * 1000 / rate_mbps     # bits / (Mbit/s) = ns x 1/1000
    problems = []
    if not entries:
        return 0, ["no sched-entry lines"]
    for i, (mask, ns) in enumerate(entries, 1):
        if ns < frame_ns:                                 # a frame must finish before its gate closes
            problems.append(f"entry {i}: {ns} ns is shorter than one frame ({frame_ns:.0f} ns)")
    if base and int(base.group(1)) % cycle:
        problems.append("base-time is not a multiple of the cycle: use the same value on every node")
    return cycle, problems

Where this sits

This lesson is the network half of two stories. For time, Time and Sync derives the four-stamp maths, Lamport Clocks shows the logical-time side, and Syncing Many MCUs puts clocks on micro-controllers. For the buses, CAN and EtherCAT covers the fieldbuses in firmware. For the hosts, Linux networking for robots, Real-Time Linux, and multi-camera links show where these frames start and end. For how the robot’s sensors and actuators meet in software, see Sensor and Actuator Integration and Real-Time Performance. The planned lessons on deterministic scheduling inside the kernel and on fleet observability are not built yet.

Sources

  1. Linux manual pages tc-taprio(8), tc-etf(8) and tc-cbs(8).
  2. F. Fejes, P. Antal, M. Kerekes, The TSN Building Blocks in Linux, 2022.
  3. G. Garner, Assumptions for error sources in 802.1AS time synchronization, IEEE 802.1 AVB, January 2009.
  4. The linuxptp project; the Meinberg article Five-minute facts about packet timing.
  5. Extreme Networks gPTP documentation, for the neighbor propagation delay threshold (800 ns).
  6. Linux kernel commits adding Launchtime to igb (i210) and ETF offload to igc (i225), and include/linux/can/length.h.
  7. IEEE 802.1 project page for P802.1DG; the IEEE 802.1Qbv, 802.1Qbu, 802.3br, 802.1CB, 802.3bw and 802.3cg standards themselves, which we read only through secondary sources and which you should open before you rely on the details.
The takeaway. A schedule is only as good as the clocks under it and the frame that arrives in its slot. Build the clock first, then the gates, then the launch time, and measure all three on real hardware.

Next, try Present to explain the cycle out loud, or Teach to draw the gate list on a whiteboard. Then go back to the gate instrument and break it with what you know now.

A taprio entry opens a gate for 8 µs, and the class sends 1,518-byte frames on a 1 Gbit/s link. What does the checker report?
Deterministic Ethernet: PTP, gPTP, TSN, LaunchTime
Fejes, Antal, Kerekes: The TSN Building Blocks in Linux · Back to Gleams