Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 96 additions & 32 deletions ut_frontend/icache/mainpipe/MainPipe模块验证报告.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| 验证对象 | MainPipe模块 |
| 验证人员 | Gui-Yue |
| 验证时间 | 2025-9 |
| 报告版本 | V0.1 |
| 报告版本 | V0.2 |
| 验证框架 | Toffee测试框架 |

## 2. 验证对象介绍
Expand Down Expand Up @@ -121,7 +121,8 @@ MainPipe 在 S0 阶段依据 WayLookup 返回的命中信息、ITLB 结果以及
- 功能点CP11.2 不访问 DataArray(Way 未命中): Way 未命中时仍会产生 toIData.valid,但 waymask 全零表示数据无效,命中逻辑拒绝本次结果。
- 功能点CP11.3 不访问 DataArray(ITLB 查询失败): ITLB 查询失败时保持访问节奏,toIData.valid 仍为 1,同时向后级传递 ITLB 异常用于后续合并。
- 功能点CP11.4 不访问 DataArray(写忙阻塞): DataArray 正在写忙(toIData.last.ready=0)时阻塞 s0_fire/fetch_req_ready,防止流水推进。
- 测试用例:TC12 test_cp11_dataarray_access — 组合驱动 WayLookup、Fetch 与 DataArray ready,覆盖四种访问分支并核对 toIData/s0_fire 行为。
- 功能点CP11.5 Way 3命中访问: waymask_0=0x8(Way 3命中)时流水线正常推进到S2,s2_waymasks_0_3寄存器被正确赋值。
- 测试用例:TC12 test_cp11_dataarray_access — 组合驱动 WayLookup、Fetch 与 DataArray ready,覆盖五种访问分支并核对 toIData/s0_fire 行为。

### 3.2 Meta ECC 校验 (CP12)
S1 阶段对 WayLookup 带回的 meta 与 ECC 校验码做奇偶校验,确保命中表项的元数据可靠。
Expand Down Expand Up @@ -149,6 +150,7 @@ S1 阶段将物理地址送入 PMP 判断执行权限、MMIO 属性,并在下
功能点CP14.2 仅 ITLB 异常: 仅 ITLB 异常时输出与 s1_itlb_exception 对齐。
功能点CP14.3 仅 PMP 异常: 仅 PMP 异常时输出与 s1_pmp_exception 对齐。
功能点CP14.4 ITLB 与 PMP 同时异常: ITLB 与 PMP 并发时,优先保留 ITLB 异常编码。
功能点CP14.5 增强信号覆盖: 跨行地址下驱动 port1 ITLB异常、backendException、itlb_pbmt非零值、waymask_1=0x8(Way 3)、isForVSnonLeafPTE等信号路径。
测试用例:TC15 test_cp14_exception_merge — 设置不同异常组合,观察合并结果与优先级。

### 3.5 MSHR 匹配和数据选择 (CP15)
Expand All @@ -161,7 +163,7 @@ S1 阶段优先匹配 MSHR 返回的数据,避免重复访问 SRAM 并处理 c
### 3.6 Data ECC 校验 (CP16)
S2 对数据路径做 ECC 校验,决定是否上报 BEU 并标记 s2_data_corrupt。
功能点CP16.1 无 Data ECC 错误: 数据正确且来源 SRAM 时 s2_data_corrupt 维持假。
功能点CP16.2 单 Bank ECC 错误: 单 bank ECC 错误触发 s2_data_corrupt 与错误上报。
功能点CP16.2 单 Bank ECC 错误: 单 bank ECC 错误触发 s2_data_corrupt 与错误上报,包括 bank 0 基本场景、跨行场景以及 bank 6 特定场景(覆盖 s2_bank_corrupt_6 评估路径)
功能点CP16.3 多 Bank ECC 错误: 多 bank ECC 错误同样触发错误上报并记录全部损坏 bank。
功能点CP16.4 ECC 功能关闭: ecc_enable 关闭时忽略所有 Data ECC 错误。
测试用例:TC17 test_cp16_data_ecc_check — 注入单/多 bank 错误及 ecc_enable 关闭场景,验证上报路径。
Expand All @@ -187,17 +189,19 @@ S2 阶段持续监控与 MSHR 的匹配关系,决定 s2_datas 的来源及命
功能点CP19.4 重复请求屏蔽: s2_has_send 防止重复请求,fire 后拉高阻止再次发送。
功能点CP19.5 仅 ITLB/PMP 异常: 仅 ITLB/PMP 异常时保留原异常,不新增 AF。
功能点CP19.6 仅 L2 异常: 仅 L2 corrupt 时输出 AF 异常。
功能点CP19.7 ITLB+L2 同步异常: ITLB 与 L2 同时存在时保持 ITLB 优先。
功能点CP19.7 ITLB+L2 同步异常: ITLB 与 L2 同时存在时保持 ITLB 优先。通过 respStall 控制 s1_fire 使 s2_l2_corrupt 可被置位。
功能点CP19.8 S2 取指完成: 所有端口 s2_should_fetch 为 0 时标记取指完成(s2_fetch_finish)。
测试用例:TC20 test_cp19_miss_request_logic — 覆盖 Miss/异常组合,确认仲裁、去重及异常合并逻辑。
测试用例:TC20b test_cp19_7_itlb_l2_both_priority — 独立DUT实例测试ITLB+L2同时异常场景,避免流水线残留状态干扰。

### 3.10 响应 IFU (CP20)
S2 在数据准备完毕且未被 respStall 阻塞时向 IFU 返回命中数据或异常信息。
功能点CP20.1 正常命中返回: 正常命中时 toIFU.valid 与数据字段正确输出,异常位清零。
功能点CP20.2 异常路径返回: 发生 ITLB/PMP/L2 异常时按端口填充 exception/pmp_mmio/itlb_pbmt。
功能点CP20.3 跨行取指响应: 跨行请求时 doubleline=1,并携带第二路数据及异常状态。
功能点CP20.4 RespStall 阻塞: respStall 拉高时 s2_fire/toIFU.valid 维持低,保留当前状态。
测试用例:TC21 test_cp20_response_ifu — 模拟命中、异常、跨行与 respStall,检查 IFU 接口打包结果。
功能点CP20.5 多地址偏移 bankSel 覆盖: 遍历 startAddr[5:3]=0~7 的8种地址偏移,覆盖 difftest 输出中各 bankSel 分支路径。
测试用例:TC21 test_cp20_response_ifu — 模拟命中、异常、跨行、respStall与多地址偏移,检查 IFU 接口打包结果。

### 3.11 L2 Corrupt 报告 (CP21)
当 L2 补回数据标记 corrupt 时,S2 需额外通过 io.errors(i) 上报,区分单路与双路场景。
Expand Down Expand Up @@ -270,6 +274,7 @@ S2 在数据准备完毕且未被 respStall 阻塞时向 IFU 返回命中数据
| TC18 | test_cp17_metaarray_flush | 验证CP17 MetaArray冲刷功能 |
| TC19 | test_cp18_s2_mshr_match_data_update | 验证CP18 S2阶段MSHR匹配与数据更新功能 |
| TC20 | test_cp19_miss_request_logic | 验证CP19 Miss请求发送逻辑和异常合并功能 |
| TC20b | test_cp19_7_itlb_l2_both_priority | 验证CP19.7 ITLB+L2同时异常场景(独立DUT实例) |
| TC21 | test_cp20_response_ifu | 验证CP20 响应IFU功能 |
| TC22 | test_cp21_l2_corrupt_report | 验证CP21 L2 Corrupt报告功能 |
| TC23 | test_cp22_flush_mechanism | 验证CP22 流水线刷新机制功能 |
Expand Down Expand Up @@ -310,43 +315,85 @@ mainpipe/
## 7. 测试结果分析

### 7.1 测试通过率
- **总测试用例数**: 23
- **通过用例数**: 23
- **总测试用例数**: 24
- **通过用例数**: 24
- **失败用例数**: 0
- **通过率**: 100%

### 7.2 覆盖率分析

#### 7.2.1 行覆盖率
根据覆盖率报告分析:
- **总体覆盖率**: 80.7% (1378/1708行)
- **ICacheMainPipe.v**: 82.1% (906/1104行)
- **ICacheMainPipe_top.sv**: 76.6% (431/563行)
- **ICacheMainPipe.v**: 80.0% (904/1130行)
- **ICacheMainPipe_top.sv**: 26.8% (151/563行)

#### 7.2.2 未覆盖代码分析
未覆盖的19.3%代码主要包括:

**Assertion错误路径 (主要原因)**:
- RTL中设计的assertion检查语句未被触发
- 例如:违反时序约束、非法状态组合的断言
- 这些assertion是为了检测设计错误,正常功能测试不会触发
##### ICacheMainPipe.v 未覆盖行分类(共226行)

ICacheMainPipe.v 中所有可覆盖的正常RTL逻辑行已全部覆盖。剩余226行未覆盖代码可分为两类:

**1. Assertion 错误路径(208行)**

| 行号范围 | 行数 | 描述 |
|----------|------|------|
| 788-797 | 10 | vSetIdx一致性断言(ftq与wayLookup不匹配时触发) |
| 831-852 | 22 | bankSel计数断言 |
| 882-903 | 22 | difftest bankSel计数断言(bank 1) |
| 936-957 | 22 | difftest bankSel计数断言(bank 2) |
| 990-1011 | 22 | difftest bankSel计数断言(bank 3) |
| 1044-1065 | 22 | difftest bankSel计数断言(bank 4) |
| 1098-1119 | 22 | difftest bankSel计数断言(bank 5) |
| 1152-1173 | 22 | difftest bankSel计数断言(bank 6) |
| 1206-1227 | 22 | difftest bankSel计数断言(bank 7) |
| 1260-1281 | 22 | difftest bankSel计数断言(bank 7续) |

这些行位于 `ASSERT_VERBOSE_COND_` / `STOP_COND_` 保护的 assertion 块内,仅在RTL设计违规时触发。正常功能测试不会也不应该触发这些断言路径,属于设计自检代码。

**2. RTL生成工具产生的结构性不可达代码(18行)**

| 行号 | 信号名 | 不可达条件 |
|------|--------|-----------|
| 454 | `s2_bankSel_bankSel_13` | `bankIdxHigh[6:3] > 4'hC` |
| 455 | `s2_bankSel_bankSel_14` | `bankIdxHigh[6:3] > 4'hD` |
| 593 | `bankSel_bankSel_5_13` | `bankIdxHigh[6:3] > 4'hC` |
| 602 | `bankSel_bankSel_6_14` | `bankIdxHigh[6:3] > 4'hD` |
| 629-630 | `bankSel_bankSel_13/14` | `bankIdxHigh[6:3] > 4'hC/D` |
| 650-651 | `bankSel_bankSel_1_13/14` | `bankIdxHigh[6:3] > 4'hC/D` |
| 671-672 | `bankSel_bankSel_2_13/14` | `bankIdxHigh[6:3] > 4'hC/D` |
| 693-694 | `bankSel_bankSel_3_13/14` | `bankIdxHigh[6:3] > 4'hC/D` |
| 714-715 | `bankSel_bankSel_4_13/14` | `bankIdxHigh[6:3] > 4'hC/D` |
| 737 | `bankSel_bankSel_5_14` | `bankIdxHigh[6:3] > 4'hD` |
| 759 | `bankSel_bankSel_6_13` | `bankIdxHigh[6:3] > 4'hC` |
| 783-784 | `bankSel_bankSel_7_13/14` | `bankIdxHigh[6:3] > 4'hC/D` |

**不可达原因分析:**

这18行均为 `bankSel_*_13` 或 `bankSel_*_14` 信号,其条件要求 `_bankSel_bankIdxHigh_T_*[6:3] > 12` 或 `> 13`。根据RTL计算链:

```verilog
wire [6:0] _GEN = {1'h0, s2_req_vaddr_0[5:0]}; // 7-bit, 范围 0~63
wire [6:0] _s2_bankSel_bankIdxHigh_T_1 = 7'(_GEN + 7'h20); // 范围 32~95
// [6:3] 提取: 最小值 = 0100000[6:3] = 4, 最大值 = 1011111[6:3] = 11
```

- `vaddr[5:0]` 为6位地址偏移,范围 0~63
- 加上常数32后,`bankIdxHigh` 范围 32~95
- 取 `[6:3]` 位后,数值范围为 **4~11**
- bankSel_13 要求 `> 12`,bankSel_14 要求 `> 13`
- **最大值11永远无法满足 > 12 的条件**

**异常处理分支**:
- 极端异常情况的处理逻辑
- 多重错误同时发生的处理路径
- 硬件故障检测的错误恢复代码
这是 CIRCT firtool(版本 1.62.1)在将 Chisel/FIRRTL 转换为 Verilog 时产生的冗余逻辑。RTL生成工具为 bank 0~14 统一生成了完整的选择器逻辑,但未对6位地址偏移宽度做常量传播优化,导致 bank 13和14的选择条件成为死代码。这属于RTL生成工具的已知局限,不是验证遗漏。

**初始化代码路径**:
- 部分复位初始化序列
- 调试模式相关的初始化代码
##### ICacheMainPipe_top.sv 未覆盖行分析

**说明**:未覆盖代码大多属于错误检测和异常处理,这些代码在正常功能验证中不应被执行
ICacheMainPipe_top.sv 中大量未覆盖行为 DPI-C 自动生成的 `get_*/set_*` 信号访问函数。这些函数仅在外部通过 DPI-C 接口读写特定信号时被调用,测试框架未直接使用 DPI-C 访问的信号对应的 getter/setter 不会被执行,属于框架生成的桩函数代码

#### 7.2.3 功能覆盖率
- **总体功能覆盖率**: 100%
- **覆盖点总数**: 22 (CP11-CP22)
- **已覆盖点数**: 22
- **API覆盖组数量**: 8
- **覆盖点总数**: 60 (CP11-CP22,共12个覆盖组)
- **已覆盖点数**: 60
- **所有24个测试用例均已通过mark_function进行反标映射**

### 7.3 覆盖率详细分析
功能覆盖率达到100%,说明所有定义的功能点都被充分测试。
Expand Down Expand Up @@ -421,16 +468,30 @@ mainpipe/

#### 7.2.4 覆盖率统计总结

- **总覆盖点数**: 60个 (CP11-CP22)
- **已覆盖数**: 59个
- **功能覆盖率**: 98.33%
- **功能覆盖点总数**: 60个 (CP11-CP22)
- **已覆盖数**: 60个
- **功能覆盖率**: 100%
- **ICacheMainPipe.v 可覆盖行覆盖率**: 100%(排除208行assertion块和18行RTL工具死代码后,所有正常逻辑行已覆盖)

---

## 8. 缺陷分析

### 8.1 发现缺陷
测试过程中未发现功能性缺陷,所有测试用例均通过。

#### 8.1.1 Agent代码属性名Bug(已修复)
**文件**: `agent/mainpipe_agent.py` 第541-542行

**问题**: `monitor_s2_mshr_match_status()` 方法中使用了含非法字符(点号)的Python属性名 `self._debug_mshr_toffee.infoed_detail`,导致 AttributeError,被 try/except 捕获后返回空字典 `{}`,使 CP18 测试中 `s2_MSHR_hits_1` 始终为 False。

**修复**: 将属性名改为合法的 `self._debug_mshr_infoed_detail`。

#### 8.1.2 RTL生成工具冗余代码(RTL侧问题)
**工具**: CIRCT firtool-1.62.1

**问题**: bankSel 逻辑为 bank 0~14 统一生成选择器,但由于 `vaddr[5:0]` 仅6位宽,`bankIdxHigh[6:3]` 最大值为11,bank 13/14 的选择条件 `> 12` / `> 13` 永远无法满足。共产生18行不可达死代码。

**影响**: 不影响功能正确性,仅影响行覆盖率统计。建议RTL团队在后续版本中优化 firtool 的常量传播。

### 8.2 潜在风险点
- 需要持续监控覆盖率报告,确保代码覆盖率满足要求
Expand All @@ -440,8 +501,11 @@ mainpipe/

### 9.1 验证完成度
- √ 所有规划的功能点均已验证(CP11-CP22)
- √ 功能覆盖率达到98.33%
- √ 所有测试用例通过
- √ 功能覆盖率达到100%(60/60 bins)
- √ 所有24个测试用例通过
- √ 所有24个测试用例均已完成反标(mark_function)映射
- √ ICacheMainPipe.v 可覆盖正常逻辑行覆盖率达到100%
- √ 不可覆盖行已分析归因(208行assertion块 + 18行RTL工具死代码)

### 9.2 模块质量评估
MainPipe模块验证充分,功能实现正确,质量良好。模块在各种测试场景下表现稳定,满足设计要求。
Expand Down
4 changes: 2 additions & 2 deletions ut_frontend/icache/mainpipe/agent/mainpipe_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ async def monitor_s2_mshr_match_status(self) -> dict:
signal = self.dut.GetInternalSignal(f"ICacheMainPipe_top.ICacheMainPipe.s2_data_is_from_MSHR_{i}", use_vpi=False)
s2_data_is_from_MSHR.append(signal.value if signal else None)

if not hasattr(self, '_debug_mshr_toffee.infoed_detail'):
self._debug_mshr_toffee.infoed_detail = True
if not hasattr(self, '_debug_mshr_infoed_detail'):
self._debug_mshr_infoed_detail = True

return {
"s2_MSHR_hits_1": s2_MSHR_hits_1.value,
Expand Down
Loading
Loading