casaroli opened a new pull request, #21644: URL: https://github.com/apache/nuttx/pull/21644
## Summary With `CONFIG_DEBUG_SCHED`, `INITIAL_SYSTEM_TIMER_TICKS` starts the tick counter 5 seconds before `UINT32_MAX`, to test the 32-bit wrap early. `/proc/uptime` subtracts this value from `clock_systime_ticks()`. With `CONFIG_ALARM_ARCH`, `CONFIG_TIMER_ARCH` or `CONFIG_RTC_HIRES`, `clock_systime_ticks()` reads the arch timer or the RTC. These start at 0 and do not use the software counter. Thus the subtraction in `/proc/uptime` goes below 0 and wraps: `/proc/uptime` shows `184467440737052` (cut to the line length, with no newline). Every arm64, sim and `rv-virt` configuration with `CONFIG_DEBUG_SCHED` shows this, for example the default `qemu-armv8a:knsh` and `qemu-armv8a:nsh`. With the software counter, the counter starts at the offset, but `sysinfo()` did not subtract it. The NSH `uptime` command shows the `sysinfo()` value: about 497 days after boot at 100 ticks per second. The busy-wait rate in `/proc/critmon` also divided by the offset. This PR has two commits: - `include/nuttx/clock.h`: set `INITIAL_SYSTEM_TIMER_TICKS` only when `clock_systime_ticks()` reads the software counter (no `CONFIG_SCHED_TICKLESS`, `CONFIG_ALARM_ARCH`, `CONFIG_TIMER_ARCH` or `CONFIG_RTC_HIRES`). The wrap test stays on for the configurations that use the software counter. - `sched`: subtract `INITIAL_SYSTEM_TIMER_TICKS` in `sysinfo()` and in the `/proc/critmon` busy-wait rate, as `/proc/uptime` does. The arch timer does not get the offset: `clock_systime_ticks()` returns its count as it is, and with `CONFIG_SCHED_TICKLESS_ALARM` the wdog code gives these absolute values back to `up_alarm_tick_start()` (`sched/wdog/wdog.h`). An offset there must be added and removed in every timer source, which is a different change. ## Impact - Only configurations with `CONFIG_DEBUG_SCHED` change. Without it, `INITIAL_SYSTEM_TIMER_TICKS` is 0 and the code is the same (0 bytes, see below). - With an arch timer or a hi-res RTC: `/proc/uptime` shows the time since boot. The tick counter, `CLOCK_MONOTONIC`, `CLOCK_BOOTTIME`, `sysinfo()` and the timers do not change (they did not use the offset). - With the software counter: the counter, `CLOCK_MONOTONIC`, `CLOCK_BOOTTIME` and the wrap test do not change. `sysinfo()` uptime, NSH `uptime` and `uptime -s` show the time since boot. The `/proc/critmon` busy-wait rate is computed over the time since boot. - The code is the same in flat, protected and kernel builds, on every architecture. No documentation describes the initial tick value, so there is no documentation change. ## Testing Test program: it prints `/proc/uptime`, `sysinfo()`, `CLOCK_MONOTONIC` and `CLOCK_BOOTTIME`. PASS if `/proc/uptime` is in 0..86400 s and `sysinfo()` agrees with it within 1 s. With `wrap`, it also sleeps 6 s and checks that the tick count went above `UINT32_MAX`. Then NSH `uptime`, `cat /proc/uptime` and `ostest`. | Configuration | Build | Tick source | master | this PR | |---|---|---|---|---| | `qemu-armv8a:knsh` (arm64, QEMU HVF) | kernel | arch timer (`ALARM_ARCH`) | `/proc/uptime` = `184467440737052`: FAIL | `0.01`, `sysinfo` 0; `cat /proc/uptime` `2.08`: PASS | | `qemu-armv8a:nsh` (arm64, QEMU HVF) | flat | arch timer (`ALARM_ARCH`) | `/proc/uptime` = `184467440737052`: FAIL | `0.00`, `sysinfo` 0; `cat /proc/uptime` `2.06`: PASS | | `mps2-an500:knsh` (Cortex-M7, QEMU TCG) | protected | arch timer (`TIMER_ARCH`) | `/proc/uptime` = `184467440737052`: FAIL | `0.01`, `sysinfo` 0; `cat /proc/uptime` `3.41`: PASS | | `lm3s6965-ek:qemu-flat` + `CONFIG_DEBUG_SCHED` (Cortex-M3, QEMU TCG), `wrap` | flat | software counter | `/proc/uptime` 0.01 s, `sysinfo` 42949668 s, NSH `uptime` "up 497 days, 2:28": FAIL | `sysinfo` 0, after 6 s 6; NSH `uptime` "up 0:00": PASS | On `lm3s6965-ek:qemu-flat` the wrap test still works with this PR: the tick count goes from 4294966796 to 4294967397 (above `UINT32_MAX`) during the 6 s sleep, and the sleep, `/proc/uptime` and `CLOCK_MONOTONIC` stay correct. ostest: status 0 on master and with this PR on `qemu-armv8a:knsh`, `qemu-armv8a:nsh` and `mps2-an500:knsh`. On `lm3s6965-ek:qemu-flat` (64 KB RAM) the waitpid test cannot start its third child and ostest ends with status 256, at the same place on master and with this PR. Size: `lm3s6965-ek:qemu-flat` (no `CONFIG_DEBUG_SCHED`): text 251312, data 1600, bss 18624 on master and with this PR (0 bytes). With `CONFIG_DEBUG_SCHED`: +8 bytes text (the subtraction in `sysinfo()`). Builds: `lm3s6965-ek:qemu-flat` + `CONFIG_DEBUG_SCHED` + `CONFIG_SCHED_CRITMONITOR` (`SCHED_CRITMONITOR_MAXTIME_BUSYWAIT=0`, so that `fs_procfscritmon.c` compiles) with `EXTRAFLAGS=-Werror`: pass, no warnings. CMake: `qemu-armv8a:nsh` + `CONFIG_SCHED_CRITMONITOR`: pass. checkpatch: `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
