How to Trace TCP Socket TCP_TX_DELAY Pacing in Linux Using eBPF

High-speed networking environments and content delivery platforms rely on fine-grained transmission pacing to smooth bursty egress traffic, prevent downstream bufferbloat, and emulate realistic network latency in staging environments. In the Linux kernel, the TCP_TX_DELAY socket option allows applications to inject microsecond-level artificial transmission delays per socket. Tracing and verifying packet pacing dynamics using extended Berkeley Packet Filters (eBPF) provides kernel-level validation of transmission queues without disruptive packet captures.

Architecture of Kernel Transmission Delay Pacing

When an application configures TCP_TX_DELAY via setsockopt(), the kernel records the desired delay timestamp inside the socket structure (struct tcp_sock -> tcp_tx_delay). When outbound packets traverse the network stack, the Fair Queueing (FQ) queueing discipline (sch_fq) or Earliest Departure Time (EDT) packet scheduler checks the socket transmission delay.

Instead of dispatching the packet immediately to the network interface controller ring buffer, the kernel schedules departure at a specific future nanosecond timestamp. Verifying whether packets adhere to these pacing targets requires instrumenting kernel transmission functions.

Writing a Dedicated bpftrace Inspection Script

Using bpftrace, we can trace outbound socket scheduling and measure the exact time delta between socket submission and kernel packet departure:

#!/usr/bin/env bpftrace

#include <net/sock.h>
#include <linux/tcp.h>
#include <linux/skbuff.h>

kprobe:tcp_transmit_skb
{
  $sk = (struct sock *)arg0;
  $tp = (struct tcp_sock *)arg0;
  $skb = (struct sk_buff *)arg1;

  if ($tp->tcp_tx_delay > 0) {
    @configured_delay_us[$sk] = $tp->tcp_tx_delay;
    @tx_departures = count();
    @skb_delivery_time = hist($skb->tstamp);
  }
}

interval:s:5
{
  print(@configured_delay_us);
  print(@tx_departures);
  print(@skb_delivery_time);
  clear(@tx_departures);
  clear(@skb_delivery_time);
}

Save this script as trace_tx_delay.bt. It targets tcp_transmit_skb() and extracts active delay parameters alongside skb delivery timestamps.

Executing and Evaluating Kernel Tracing

Run the tracing tool with administrative privileges:

sudo bpftrace trace_tx_delay.bt

Initiate network traffic through an application configured with TCP_TX_DELAY. Evaluate the telemetry output for key indicators:

  • Pacing stability: Check that @configured_delay_us reflects the microsecond duration requested by the user application.
  • EDT timestamp accuracy: Ensure that $skb->tstamp increments consistently relative to kernel monotonic time, confirming that the packet scheduler holds frames until the designated departure slot.
  • Egress queue health: Ensure departure count distributions remain stable without burst cliffs, which would indicate scheduler queue drops under heavy load.

Configuring Host Prerequisites for Accurate Pacing

To ensure TCP_TX_DELAY functions correctly, verify the host network configuration:

  1. Configure the Fair Queueing scheduler on the primary network interface using sudo tc qdisc replace dev eth0 root fq, as default schedulers (such as pfifo_fast) do not honour EDT delivery timestamps.
  2. Verify kernel support by checking sysctl net.ipv4.tcp_fackets and relevant TCP timestamp sysctls.
  3. Ensure network interface hardware offloads do not strip departure timestamps prior to queueing.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.