fix(dwt): stop resetting CYCCNT, a counter six modules share
Three of the six DWT CYCCNT users wrote the counter to zero on init: console_log, net_latency_test and ch395f_reuse_bench. Every one of them only ever takes the difference (CYCCNT - t0) against a local snapshot, so the reset bought nothing and instead caused a bogus ~2^32 delta for anyone who sampled across it. That delta trips the task_prof glitch guard (TASK_PROF_GLITCH_CYC = 10 s worth of cycles), which discards the sample, so a whole worst-case measurement could vanish silently. All three call sites now leave the counter alone; the shared contract is "enable only, never reset", documented at each of the six users. The documented behaviour in the link latency test guide (section 4.3) is updated to match. Net source change is three deleted lines, no new executable code. Verification: - grep for a zero assignment to CYCCNT across the tree: no hits left. - Keil build: Code=257932 RO-data=32108 RW-data=2104 ZI-data=152688, 0 errors 0 warnings. - Host unit tests: console_log 153/153, task_prof 27/27, ioboard 100/100, sb_link 164/164. - Four console_log assertions pinned the absolute number of DWT register touches; dropping the reset write lowers it by one, so their expected counts move from 3 to 2 (and 4 to 3 for TC-CONLOG-093). The test text now says why the third write disappeared. - check_doc_links: 6 known issues, unchanged from baseline.
This commit is contained in:
+14
-2
@@ -69,6 +69,12 @@
|
||||
* 再读 DR"清除 ⇒ 永不自愈);引脚悬空只影响发生率,不是必要条件。
|
||||
* 缓解措施与结论不变,仅改注释;机制详见
|
||||
* docs/子系统设计/控制台单写者日志设计.md §9。
|
||||
* 2026-11-16 修正 con_dwt_ensure() 无条件清零 CYCCNT(台架取证发现,见
|
||||
* App/util/task_prof.c 与 Drivers/BSP/IOBOARD/ioboard.c 的契约注释)。
|
||||
* 本模块的超时判据是 (CYCCNT - t0) 差值,t0 是调用时刻的快照,不依赖
|
||||
* 绝对零点;因此清零没有收益,却会让同内核其他三处"在途"差值变成
|
||||
* 接近 2^32 的回绕并被静默丢弃——台架表现为 [PROF2] 的 defi 最坏值
|
||||
* 不完整。改为只在使能 CYCCNTENA 时打开计数,不再清零。
|
||||
*/
|
||||
|
||||
#include "console_log.h"
|
||||
@@ -219,16 +225,22 @@ static uint16_t con_used(void) {
|
||||
* 入口参数:无
|
||||
* 返回值:无
|
||||
* 限定条件:任意上下文可调(幂等;纯寄存器写,不创建任何内核对象)
|
||||
* 函数说明:CoreDebug->DEMCR.TRCENA=1 → DWT->CYCCNT=0 → DWT->CTRL.CYCCNTENA=1;
|
||||
* 函数说明:CoreDebug->DEMCR.TRCENA=1 → DWT->CTRL.CYCCNTENA=1;
|
||||
* 使能成功置 s_con_dwt_up=1(供超时判据选择),失败保持 0(退回 HAL 超时)。
|
||||
* 在 Cortex-M4 上 DWT 恒存在;失败仅可能出现在调试单元被硬件关闭时。
|
||||
* **刻意不清零 CYCCNT**:本模块只用 (CYCCNT - t0) 差值判超时,基准是调用
|
||||
* 时刻抓的快照,不是绝对零点,清零对判据毫无帮助;而 CYCCNT 是全内核共享
|
||||
* 的单一计数器,本仓另有三个使用者同样在取差值——App/util/task_prof.c
|
||||
* (探针最坏值)、Drivers/BSP/IOBOARD/ioboard.c(微秒延时)、
|
||||
* Drivers/BSP/ScreenLink/sb_link.c(组帧耗时)。清零会让它们"在途"的
|
||||
* t0 瞬间失效,差值变成一次接近 2^32 的无符号回绕,被各自的守卫静默丢弃。
|
||||
* 历史上这里确实无条件清零,与上述三处的契约注释直接冲突,2026-11-16 修正。
|
||||
*/
|
||||
static void con_dwt_ensure(void) {
|
||||
if (s_con_dwt_up != 0U) {
|
||||
return;
|
||||
}
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CYCCNT = 0U;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
if ((DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk) != 0U) {
|
||||
s_con_dwt_up = 1U;
|
||||
|
||||
Reference in New Issue
Block a user