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:
2026-11-16 19:58:44 +08:00
parent e4981aa2f6
commit cc7f17f231
7 changed files with 41 additions and 16 deletions
+5 -5
View File
@@ -953,8 +953,8 @@ static void tc_dwt(void)
"TC-CONLOG-091 DEMCR.TRCENA really gets written (bit number matches core_cm4.h)");
CHECK((g_con_dwt.CTRL & DWT_CTRL_CYCCNTENA_Msk) != 0U,
"TC-CONLOG-092 DWT.CTRL.CYCCNTENA really gets written");
CHECK(tx_is(0U, "ok\r\n") && con_dwt_reads == 4U,
"TC-CONLOG-093 with the channel ready the send loop reads no further CYCCNT (3 from ensure + 1 for t0)");
CHECK(tx_is(0U, "ok\r\n") && con_dwt_reads == 3U,
"TC-CONLOG-093 with the channel ready the send loop reads no further CYCCNT (2 from ensure + 1 for t0; the third write is gone because ensure no longer resets CYCCNT)");
printf("-- TC-CONLOG-094..097 DWT enable failure -> con_tx_counted instruction ceiling --\n");
reset_all();
@@ -965,7 +965,7 @@ static void tc_dwt(void)
CHECK(con_uart_txe_reads == CON_TX_GUARD_MAX,
"TC-CONLOG-095 each byte spins at most CON_TX_GUARD_MAX(20000) times then gives up (bounded, not a dead wait)");
CHECK(con_uart_tx_n == 0U, "TC-CONLOG-096 if the block is not out within the counted ceiling the whole block is abandoned");
CHECK(con_dwt_reads == 3U,
CHECK(con_dwt_reads == 2U,
"TC-CONLOG-097 the counted branch never reads CYCCNT (independent of DWT, hence of any time source)");
printf("-- TC-CONLOG-098..099 the timeout criterion does not use HAL_GetTick --\n");
@@ -992,7 +992,7 @@ static void tc_null_uart(void)
dbg_console_write_raw("boom", 5U);
CHECK(con_uart_tx_n == 0U && con_uart_txe_reads == 0U,
"TC-CONLOG-100 with Instance==NULL not one register is touched (no dereference of address 0)");
CHECK(con_dwt_reads == 3U,
CHECK(con_dwt_reads == 2U,
"TC-CONLOG-101 DWT is still lazily enabled before the short circuit (ensure stays ahead of the NULL check)");
reset_all();
@@ -1084,7 +1084,7 @@ static void tc_counted_paths(void)
dbg_console_write_raw("AB", 2U);
CHECK(s_con_dwt_up == 0U && tx_is(0U, "AB"),
"TC-CONLOG-130 the counted branch sends the whole block and returns success (fallback path did not regress)");
CHECK(con_uart_tc_reads == 1U && con_dwt_reads == 3U && con_tick_reads == 0U,
CHECK(con_uart_tc_reads == 1U && con_dwt_reads == 2U && con_tick_reads == 0U,
"TC-CONLOG-131 the counted branch waits no tick and reads no CYCCNT (zero external time source)");
reset_all();