> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 构建与设置 — RTC Testbench

## **构建与设置**

### 使用 meta-rtc 编译

按照 QLI 2.0 同步步骤操作，然后添加 `meta-rtc` 层：

```bash theme={null}
# 1. Sync QLI 2.0 (see https://dragonwingdocs.qualcomm.com/Key-Documents/Yocto-Guide/build-qualcomm-linux)

# 2. Clone meta-rtc
git clone https://github.com/IIOTSS/meta-rtc.git

# 3. Copy the KAS overlay
cp meta-rtc/meta-rtc.yml meta-qcom/ci/meta-rtc.yml

# 4. Build with RT kernel and meta-rtc
kas build meta-qcom/ci/iq-9075-evk.yml \
          :meta-qcom/ci/qcom-distro.yml \
          :meta-qcom/ci/linux-qcom-rt-6.18.yml \
          :meta-qcom/ci/meta-rtc.yml
```

| KAS 覆盖文件 | 用途 |
| - | - |
| `iq-9075-evk.yml` | 板卡 / 机器配置 |
| `qcom-distro.yml` | 基础发行版配置 |
| `linux-qcom-rt-6.18.yml` | PREEMPT\_RT 6.18 内核 |
| `meta-rtc.yml` | OPC/UA 二进制文件、测试脚本和配置 |

***

### 验证 RT 启动

刷机后，确认两台设备均使用正确的 RT 内核命令行启动。CPU 3–7 必须处于隔离状态：

```bash theme={null}
cat /proc/cmdline
```

预期输出：

```
root=PARTLABEL=rootfs rw rootwait console=ttyMSM0,115200 qcom_scm.download_mode=1 \
  isolcpus=3-7 irqaffinity=0-2 rcu_nocbs=3-7 rcupdate.rcu_expedited=1 cpuidle.off=1
```

***

### 设置脚本权限

每次刷机后在**两台**设备上运行：

```bash theme={null}
chmod +x /usr/share/rtc-testbench/tests/common/postboot.sh
chmod +x /usr/share/rtc-testbench/tests/common/ptp.sh
chmod +x /usr/share/rtc-testbench/tests/opcua_qcom_emac/mirror.sh
chmod +x /usr/share/rtc-testbench/tests/opcua_qcom_emac/flow.sh
chmod +x /usr/share/rtc-testbench/tests/opcua_qcom_emac/ref.sh
```

***

### 运行 postboot.sh

每次启动后、启动 PTP 之前，在**两台**设备上运行：

```bash theme={null}
/usr/share/rtc-testbench/tests/common/postboot.sh
```

该脚本会应用所有无法在 initscripts 阶段设置的 RT 调优。它会：

| 操作 | 原因 |
| - | - |
| 禁用内核跟踪 | 消除跟踪开销 |
| 禁用定时器迁移 | 防止定时器回调迁移到 RT CPU |
| 将工作队列绑定到 CPU 0–2 | 使内核工作远离 RT 隔离的 CPU |
| 禁用所有 CPU 空闲状态 | 消除 C 状态重新进入延迟 |
| 将 CPU 频率调节器设置为 `performance` | 防止 P 状态切换 |
| 设置 `sched_rt_runtime_us = -1` | 取消 RT 调度带宽上限 |
| 将所有 IRQ 绑定到 CPU 0–2 | 防止中断投递到 RT CPU |
| 移除 WiFi 模块（`ath11k`、`mac80211`） | 曾观察到 `cfg80211_wiphy_work` 在系统维护 CPU 上突发运行并干扰 NAPI 调度 |
| 终止 `redis-server`、`containerd` | 消除 PM/I/O 噪声 |
| 禁用以太网 MAC 的运行时 PM | 防止测试期间发生设备 PM 切换 |
| 禁用 UFS 控制器的运行时 PM 以及时钟门控/缩放 | 防止 `ufshcd_gate_work` 阻塞 RT CPU |
| 禁用所有 SCSI 设备/主机的运行时 PM | 曾观察到 `jbd2` 在 RT CPU 上触发 SCSI PM 唤醒 |
| 将 `end0` 硬件 IRQ 绑定到 CPU 6（掩码 `0x40`） | 使网卡 IRQ 投递与 `flow.sh` 绑定的 NAPI 线程位于同一 CPU |

***

### 启动 PTP 同步

在**两台**设备上同时运行：

```bash theme={null}
/usr/share/rtc-testbench/tests/common/ptp.sh
```

* 默认使用接口 `end0`
* 将 `ptp4l` 绑定到 CPU 1，`phc2sys` 绑定到 CPU 2，两者均为 `SCHED_FIFO 98`
* 使用 802.1AS-2011 端站配置文件（`gPTP_qcom_emac.cfg`）
* 日志：`/var/log/ptp4l_run.log` 和 `/var/log/phc2sys_run.log`

> [!WARNING]
>
> 在两台设备上启动 `ptp.sh` 后，请等待 **5 分钟**再继续。这样可以让 PTP 时钟偏移完全收敛。请勿跳过或缩短此等待时间。

***

> [card] [测试执行](https://dragonwingdocs-staging.qualcomm.com/zh/Suites/Industrial-Edge-Suite/rtc-testbench-execution.md)
>
> 配置对端 MAC、运行 mirror/reference、解读结果

> [card] [参考文件](https://dragonwingdocs-staging.qualcomm.com/zh/Suites/Industrial-Edge-Suite/rtc-testbench-reference.md)
>
> postboot.sh、ptp.sh 和 gPTP 配置的完整源码
