| 【FIX】: 修复autofuse backend ST并发执行时symlink竞争导致概率性SEGFAULT的问题
Co-authored-by: zhang_shengjie<804425610@qq.com>
# message auto-generated for no-merge-commit merge:
!2904 merge fix_warning into develop
【FIX】: 修复autofuse backend ST并发执行时symlink竞争导致概率性SEGFAULT的问题
Created-by: zhang_shengjie
Commit-by: zhang_shengjie
Merged-by: cann-robot
Description:
# Pull Request
## 描述
### 一、主要解决的问题
#### 1.1 autofuse backend ST 并发执行 SEGFAULT
CTest 并行执行 inductor_topn_test_e2e 和 inductor_topn_concat_test_e2e 等多个测试用例时,inductor_topn_test_e2e 因 SEGFAULT 失败。
**错误信息**:
```
FileExistsError: [Errno 17] File exists: '...pyautofuse.so' -> '...pyautofuse.so'
```
**根因**: PythonPreamble() 函数中 os.symlink 创建符号链接时存在 **TOCTOU(Time-of-check to time-of-use)竞争条件**。多个并行测试共享同一个 autofuse_dir(通过 symlink 指向同一个源目录),当两个测试进程同时执行到 if not os.path.exists() 检查时均返回 False,随后同时调用 os.symlink(),第二个进程抛出 FileExistsError,导致 host_compile 返回非零退出码,测试断言失败后触发 SEGFAULT。
### 二、修改方案
将 PythonPreamble() 中的 TOCTOU 模式:
```python
if not os.path.exists(path):
os.symlink(src, path)
```
替换为异常容忍模式:
```python
try:
os.symlink(src, path)
except FileExistsError:
pass
```
**修改不增加额外耗时**:正常路径下 try 块直接成功,仅在极少数并发冲突时才进入 except 分支。
涉及 5 个测试文件的 PythonPreamble() 函数:
- inductor_topn_test
- inductor_topn_concat_test
- pgo_add_abs_inductor_test
- pgo_add_abs_inductor_concat_test
- inductor_tail_brc_tail_reduce_test
## 变更类型
- [x] 🐛 Bug 修复
- [ ] ✨ 新功能
- [ ] 💄 代码风格更新
- [ ] ♻️ 重构
- [ ] 📦 构建过程或辅助工具的变动
- [ ] 📝 文档内容更新
## 关联的Issue
无
## 如何测试
### 一、测试用例说明
#### 1.1 系统测试
通过 autofuse backend ST 验证,确保并行执行时不再出现 SEGFAULT:
```bash
bash scripts/test/run_autofuse_test.sh \
--ascend_install_path=/home/zhangshengjie/Ascend/latest \
--ascend_3rd_lib_path=/home/zhangshengjie/third_party \
-s -m backend
```
重点观察:
- inductor_topn_test_e2e 不再 SEGFAULT
- inductor_topn_concat_test_e2e 正常通过
- 其他并行执行的 inductor 类测试(pgo_add_abs_inductor 等)正常通过
## 核对清单
- [x] 我的代码遵循了项目的代码风格
- [x] 我已对代码进行了自测
- [x] 我已更新了相关的文档
- [x] 我在标题中使用了合适的类型标签(【FIX】:)
- [x] 我已经详细阅读了贡献指南
## 其他信息
无
### 验证方法
本地编译环境存在预存的 op_desc_utils_ex.cc 编译错误(与本次修改无关),需在 CI 环境或合入最新代码后验证。
### 注意事项
该修复仅解决了并发创建符号链接的竞争问题。PythonPreamble() 在多个测试文件中重复定义,后续可考虑提取为公共代码以减少重复。
See merge request: cann/ge!2904 | 18 天前 |