ethercat-linux/docs/jitter-analysis.md
Tony Cao f0163d8d70 800B PDO variant + long-term stability evidence + analysis docs
- twin_layout_blob_sized generalized: multi-entry TwinCAT line format
  (1 real @240bit + N continuation + remainder entry); 1024B path kept
  byte-identical; 800B = 27 entries verified on hardware
- 800B constants (PAYLOAD/SM 800), deployed as el6695_rt_800b
- 10-min + 5h stability runs: 18M cycles, zero errors, zero mismatches,
  PLC nMismatch frozen over the whole run (monitor_5h.csv evidence)
- docs: 800B plan/design/verification/test-report chapters,
  jitter analysis (NFS rootfs stall primary cause), D2000 dev plan
- scripts: 800B deploy/relink/verify, mismatch-delta, 5h monitor
2026-08-06 01:10:50 +08:00

70 lines
3.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# J1900 实时性能偶发最大抖动分析
> **日期**: 2026-07-28
> **对象**: J1900 (Debian 13, Linux 6.6.135-rt74 PREEMPT_RT) 上 el6695_rt ticker 的周期抖动
> **数据来源**: 1kHz 8B 600s 测试、800B 10 分钟测试、4kHz 测试、800B 5 小时(1800 万周期)测试
---
## 1. 现象
周期抖动(实际周期相对名义周期的偏差)的**均值极小(57µs)**,但偶发数百微秒的最大值:
| 测试 | 样本数 | jitter 均值 | jitter max |
|---|---|---|---|
| 1kHz 8B, 600s | 600,000 | 7.29µs | **10.0µs** |
| 800B, 10 分钟 | 600,000 | 4.89µs | **499.1µs** |
| 4kHz, 120s | 352,917 | 90µs(含滑相) | **1549µs** |
| **800B, 5 小时** | **18,000,000** | **7.39µs** | **41.8µs** |
关键观察:尖峰幅度**不是系统固有属性**——5 小时静默运行(1800 万样本)最大仅 41.8µs,而活动密集的 10 分钟测试出现 499µs。尖峰与并发系统活动强相关。
## 2. 诊断证据
### 2.1 系统环境(J1900 实测)
| 项 | 值 | 影响 |
|---|---|---|
| 根文件系统 | **NFS**:`192.168.68.1:/j1900-node2/rootfs`(TwinCAT PC 做 NFS 服务器) | 一切文件访问走网络 |
| /tmp | tmpfs(内存) | ticker 日志不落盘 ✓ |
| 设备中断 | eth0-rx 30 万次全在 CPU0;ahci/ttyS0 也在 CPU0/1 | ticker 核 CPU2 无设备 IRQ ✓ |
| 调度 | ticker 绑定核 2,SCHED_FIFO 80,mlockall,栈预缺页 | 基础保障已做 |
| dmesg | 无热事件、无异常;sshd 栈深度提示(良性) | 排除过热 |
### 2.2 相关性
尖峰最频繁的测试(10 分钟、4kHz)期间,Windows 侧正密集进行 TwinCAT 构建/激活与 SSH 会话;5 小时静默期几乎无尖峰。
## 3. 原因排序
| # | 原因 | 机理 | 符合度 |
|---|---|---|---|
| 1 | **NFS 根文件系统停顿** | Windows NFS 服务器忙(VS 构建、大文件 I/O)→ J1900 侧触盘进程阻塞 → 网络 softirq、内存回收压力波及 RT 核 | ★★★★ 主因(静默期 max 仅 41.8µs) |
| 2 | **SMI 系统管理中断** | J1900(Bay Trail Atom)BIOS 的 USB legacy / 嵌入式控制器 / 热管理 SMI,100500µs 不可屏蔽、OS 不可见 | ★★★ 次嫌疑(偶发形态吻合,需 hwlatdetect 证实) |
| 3 | **深 C 状态退出** | Bay Trail C6 退出延迟 ~100200µs;周期睡眠偶入深态 | ★★(均值仅 57µs,多数时间为浅态) |
## 4. 验证方法
```bash
# 区分硬件(SMI) vs 软件(NFS/OS)延迟 — 内核 6.6 自带 rtla:
rtla hwlatdetect --cpus 2 --duration 60
# 判定: hwlatdetect 报数百微秒 => SMI/硬件; 干净 => NFS/OS 软件因素
# 辅助: cyclictest 对照(无 EtherCAT 负载时测量裸调度抖动)
cyclictest -m -p 80 -i 1000 -l 60000 -a 2
```
## 5. 缓解建议(按收益排序)
| # | 措施 | 预期效果 |
|---|---|---|
| 1 | gateway 目录与日志移出 NFS(tmpfs 或本地存储) | 消除主因 |
| 2 | BIOS 关闭 USB Legacy、不需要的 EC 功能 | 消 SMI 尖峰 |
| 3 | 内核启动参数 `isolcpus=2,3 nohz_full=2,3 rcu_nocbs=2,3` | 完全隔离 RT 核 |
| 4 | `intel_idle.max_cstate=1` 限制最深 C 状态 | 消 C6 退出尖峰(功耗换延迟) |
| 5 | IRQ 亲和性复核(保持设备 IRQ 远离核 2/3) | 已满足,固化 |
## 6. 结论
J1900 基础实时性良好(均值 57µs,p99 < 10µs,1800 万周期零丢帧)。偶发数百微秒尖峰的主因是 **NFS 根文件系统在 Windows 服务器繁忙时的停顿**;SMI 为次要嫌疑,可用 `rtla hwlatdetect` 一测定论对当前 EL6695 数据通道无实质影响(尖峰只占 ~0.0001%, 1kHz 预算 1ms exec 最大 400µs 仍有富余)。