From: Alexander Dahl <ada@thorsis.com>
To: 김민수 <m.kim@knu.ac.kr>
Cc: linux-rt-users@vger.kernel.org
Subject: Re: EtherCAT on PREEMPT_RT: send-recv tail ~50-80μs, looking for guidance
Date: Fri, 13 Mar 2026 11:15:36 +0100 [thread overview]
Message-ID: <20260313-icy-nursing-37b1bbeb83a1@thorsis.com> (raw)
In-Reply-To: <C35885A5-1CAD-4373-927A-CBEB7DF116EA@knu.ac.kr>
Hei hei,
Am Fri, Jan 30, 2026 at 02:33:58PM +0900 schrieb 김민수:
> To: linux-rt-users@vger.kernel.org
> Subject: EtherCAT on PREEMPT_RT: send-recv tail ~50-80μs, looking for guidance
>
> --
> Hi all,
>
> I'm working on reducing worst-case EtherCAT send-recv round-trip
> latency on PREEMPT_RT 6.8-rt8, targeting under 50μs. I've done
> ftrace analysis over ~50k cycles and tried two kernel-side fixes,
> but the measured tail (50-80μs) exceeds what my trace can account
> for (~31μs). I'd appreciate help identifying what I'm missing.
>
> == Environment ==
>
> - Kernel: 6.8.0-rt8 (PREEMPT_RT)
> - CPU: Intel, core 3 isolated
> - isolcpus=domain,managed,3 nohz_full=3 rcu_nocbs=3
> - intel_pstate=disable idle=poll intel_idle.max_cstate=0
> - NIC: RTL8168H (r8169 driver), IRQ pinned to CPU3
> - Coalescing off: rx-usecs=0, rx-frames=1
> - EtherCAT master: SOEM (Open EtherCATsociety)
> - SCHED_FIFO 99, pinned to CPU3, 1ms cycle
> - AF_PACKET raw socket (ETH_P_ECAT)
> - Measures send-recv with clock_gettime(CLOCK_MONOTONIC)
>
> == What I've tried ==
>
> Using ftrace (function_graph + sched_switch) on CPU3:
>
> 1) ksoftirqd preemption during NAPI poll
>
> During rtl8169_poll() → napi_gro_receive() → sock_def_readable()
> → wake_up(), SOEM (FIFO 99) preempts ksoftirqd/3 (CFS) mid-poll.
> SOEM then blocks on rt_spin_lock (socket wq_head->lock, held by
> wake_up) → D state ~2μs → returns to ksoftirqd → preempts again
> after recv() completes. Measured overhead: 5.5μs mean, up to 25μs.
>
> Fix: chrt -f -p 99 ksoftirqd/3
>
> Result: D state eliminated, recv() peak improved ~3μs, but
> max got worse (77μs → 88μs).
>
> 2) TX completion IRQ elimination
>
> Each cycle generates two polls: TX IRQ triggers poll#1 (rtl_tx
> cleanup only, ~1.3μs), then RX IRQ triggers poll#2. Gap: 3-13μs.
>
> Fix: Masked TxOK from interrupt enable register.
>
> Result: recv() distribution narrowed, but send-recv unchanged
> (TX poll + gap overlaps with wire delay).
>
> Combined: No improvement beyond H1 alone.
If you see latencies due to ksoftirqd, I assume you don't use threaded
NAPI? Did you try?
Quoting from my own notes here:
NAPI processing mostly happens in eth softirq threads, but not always,
especially with higher system load it might end up in ksoftirqd, which
runs with low priority, and which process priority is not recommended to
be changed (with RT).
Link: https://lwn.net/Articles/833840/
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fdd2f0e5c64
Link: https://lwn.net/Articles/853289/
What we did:
+ # enable napi threads and set realtime priority
+ echo 1 > /sys/class/net/eth0/threaded
+ sleep 1
+ pgrep napi/eth0 | xargs -n 1 chrt --pid 49
That eliminated latency spikes for us, on completely different
hardware though. ^^
Greets
Alex
next prev parent reply other threads:[~2026-03-13 10:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 5:33 EtherCAT on PREEMPT_RT: send-recv tail ~50-80μs, looking for guidance 김민수
2026-03-12 16:15 ` Sebastian Andrzej Siewior
2026-03-13 10:15 ` Alexander Dahl [this message]
2026-03-16 8:00 ` Stephane ANCELOT
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260313-icy-nursing-37b1bbeb83a1@thorsis.com \
--to=ada@thorsis.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=m.kim@knu.ac.kr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox