当前Pull Request已关闭, 关闭人@FengHaozhan
变更摘要
本次变更主要为 AICPU 执行增加超时监控能力:在 AICPU 插件接口与运行时 hooks 中新增超时相关的扩展点,在服务侧记录每个执行中任务的起始时间并按配置超时阈值检测,超时后通过新增的 setStreamTimeoutError 回调上报;同时新增 Stars 引擎的监控任务注册机制,使 AICPU 超时检测能够挂载到既有监控线程中周期执行,并将 SetOpExecuteTimeOutV2 的计算结果同步下发给 AICPU 插件。整体上通过 RuntimeThreadAicpuPluginApi、RuntimeThreadAicpuRuntimeHooks、RuntimeThreadAicpuService、StarsEngine 与 runtime_thread_aicpu 适配层串联起「设置超时—记录执行—周期检测—上报流错误」的链路。
主要改动
- 插件接口与运行时 hooks 扩展:
RuntimeThreadAicpuPluginApi新增setExecuteTimeout、monitorExecutionTimeout,RuntimeThreadAicpuRuntimeHooks新增clockGetTimeUs、setStreamTimeoutError,并在HooksAreValid、插件初始化校验与错误日志中同步校验这些新回调。 - 服务侧执行超时监控:
RuntimeThreadAicpuService新增SetExecuteTimeout、BeginExecution、EndExecution、MonitorExecutionTimeout及ExecutingTaskInfo、ExecutionStateGuard、executingTasks_、executionMutex_与原子量executeTimeoutUs_(默认28000000ULL),在MonitorExecutionTimeout中按边界条件判定超时并逐个上报,且同一执行仅上报一次;StreamDestroyed同时清理该流对应的执行记录。 - Stars 引擎监控任务注册机制:
stars.hpp/stars_engine.cc新增RegisterStarsMonitorTask、UnregisterStarsMonitorTask(基于g_starsMonitorTaskMutex去重注册)与RunRegisteredMonitorTasks,并在MonitoringRun的设备存活分支中调用,使注册的监控任务随监控线程周期运行。 - 运行时适配层接入与超时错误上报:
runtime_thread_aicpu.cc中适配器新增SetExecuteTimeout缓存与下发逻辑,在插件加载成功后setExecuteTimeout并注册 Stars 监控任务与流观察者(析构时反注册),新增SetStreamTimeoutError、RuntimeThreadAicpuClockGetTimeUs回调,并通过g_streamErrorMutex保证超时错误TS_ERROR_AICPU_TIMEOUT不被执行失败错误覆盖。 SetOpExecuteTimeOutV2下沉与超时下发: 该方法从api_impl.cc移除,在api_impl_arch5162.cc与api_impl_cpu_kernel.cc中重新实现,并在 arch5162 版本中新增SetRuntimeThreadAicpuExecuteTimeout(runtime_thread_aicpu.hpp声明)调用以把计算后的actualTimeout下发给 AICPU。


Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| pkg_inc | ❌ (0/2)(You can also ask: 张子菁, zhangpengpeng8, yanmingxiang, Reyn52166, 卢煜坤) | ❌ (0/1)(You can also ask: 张子菁, 卢煜坤, 侯延保, 王涛) |
| src/aicpu_sched | ❌ (0/2)(You can also ask: yanmingxiang, 侯延保, 卢煜坤, 张子菁, 王涛) | ❌ (0/1)(You can also ask: ZhaiPeiChao, LiWei79) |
| src/runtime | ❌ (0/2)(You can also ask: liubin1986, Axiaolei, 侯延保, sunnana_004434229, wda1991) | ❌ (0/1)(You can also ask: liubin1986, Henry_ascend, 王涛, YzQnWyx, WangHuiH) |
| tests/ut/aicpu_sched | ❌ (0/2)(You can also ask: yanmingxiang, 张子菁, zhangpengpeng8, 侯延保, 王涛) | ❌ (0/1)(You can also ask: LiWei79, ZhaiPeiChao) |
| tests/ut/runtime | ❌ (0/2)(You can also ask: wda1991, vaceciliachen, YzQnWyx, liubin1986, zhou-wuxiao) | ❌ (0/1)(You can also ask: wangluyao17, WangHuiH, weiying_101, 王涛, 卢煜坤) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
FengHaozhan, thanks for your pull request. All authors of the commits have signed the CLA. 👍


🟡 Medium:在确认 apiSize 足够前读取了新增尾部回调。
setTimeoutValid 和 monitorValid 会先解引用 pluginApi_->setExecuteTimeout / monitorExecutionTimeout,而短表检查要到后面的 apiSize < sizeof(RuntimeThreadAicpuPluginApi) 才执行。若插件返回的确实是旧版或截短表,这里会越过对象边界读取,产生未定义行为;当前短表 UT 只是把完整 g_pluginApi 的 structSize 改小,因此覆盖不到该越界。
建议先计算 apiTableValid = (pluginApi_ != nullptr) && (apiSize >= sizeof(RuntimeThreadAicpuPluginApi)),再通过短路条件读取所有回调,并补一个使用真实短存储的回归用例。


🟡 Medium:这把局部互斥锁没有覆盖 Stream::errCode_ 的全部访问,新增超时上报仍存在数据竞争。
该函数由 Stars 监控线程调用并在这里读写 errCode_;但 Stream::GetError() 会在同步调用线程中直接读取并清零同一个普通 uint32_t,其他 SetErrCode() 调用点也不持有 g_streamErrorMutex。因此这把锁只能串行化两个 RuntimeThread hook,不能为 errCode_ 建立完整的 happens-before 关系,既可能触发 C++ 未定义行为,也可能使这里的错误优先级检查被并发写入破坏。
建议把“按优先级设置错误”下沉为 Stream 自身的同步操作,并让所有读写走同一把锁或原子 CAS;同时增加监控线程与同步线程并发的回归用例。


compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


ExecutionStateGuard 未显式删除拷贝构造:引用成员 service_ 仅使拷贝赋值被隐式删除(引用无法重绑定),拷贝构造仍隐式生成(原样复制引用,ExecutionStateGuard copy = guard; 可编译;类含用户声明析构,属 deprecated
隐式生成,GCC 9+ 在 -Wextra 下有 -Wdeprecated-copy 类告警)。
误拷贝的后果:副本析构会对同一 taskCookie 提前/重复执行 EndExecution——若副本先析构(临时对象/内层作用域),任务被提前移出 executingTasks_,ExecuteKernel 仍在执行而超时监控已失效。
建议 ExecutionStateGuard(const ExecutionStateGuard&) = delete;。


Pull Request
描述
请清晰准确地描述本次 Pull Request 的意图和变更内容。
变更类型
请选择本次引入的变更类型:
关联的Issue
如何测试
描述测试此变更的步骤和前提条件:
1.
2.
核对清单
其他信息
在此添加任何其他关于本次 PR 的说明。