casaroli opened a new pull request, #21967:
URL: https://github.com/apache/nuttx/pull/21967

   ## Summary
   
   On x86_64 (intel64), `qemu-intel64:knsh_romfs` and `qemu-intel64:nsh` with 
`CONFIG_RTC`, `CONFIG_RTC_HIRES` and the HPET timer 
(`CONFIG_ARCH_INTEL64_HPET_ALARM`) stop at boot. The console prints nothing 
after `Booting from ROM..`. This occurs under QEMU TCG and under KVM.
   
   The high resolution RTC in `intel64_rtc.c` reads the TSC and divides it by 
`g_x86_64_timer_freq / 1000000`. Only the TSC system timers set 
`g_x86_64_timer_freq` (`x86_64_timer_calibrate_freq()`: 
`CONFIG_ARCH_INTEL64_TSC_DEADLINE` and `CONFIG_ARCH_INTEL64_TSC`). With the 
HPET timer it stays 0. `clock_initialize()` -> `clock_inittime()` -> 
`clock_systime_timespec()` -> `up_rtc_gettime()` then divides by zero. The QEMU 
log (`-d int`) shows the divide error (`v=00`) again and again at 
`intel64_rtc.c:103`, with `RSI=0` and `g_x86_64_timer_freq` = 0 in gdb. The 
divide error handler returns to the same instruction, so the CPU never leaves 
it.
   
   This PR stops the build with an `#error` for `CONFIG_RTC_HIRES` without 
`CONFIG_ARCH_INTEL64_HAVE_TSC`, next to the `CONFIG_RTC_FREQUENCY` check in the 
same file. The second commit adds one sentence to the clock source section of 
`Documentation/platforms/x86_64/intel64/index.rst`.
   
   This PR does not calibrate the TSC against the HPET. With 
`CONFIG_RTC_HIRES`, `clock_systime_ticks()` reads the RTC (the TSC), but the 
HPET alarm counts HPET cycles, so the scheduler would use two clocks that must 
stay equal. That is a new feature, not a fix.
   
   ## Impact
   
   Only x86_64 intel64 with `CONFIG_RTC_HIRES` and the HPET timer. These 
configurations built, but did not boot. Now they do not build. No defconfig 
sets `CONFIG_RTC_HIRES` on x86_64, so no CI build changes. With the TSC timers, 
`intel64_rtc.o` is the same as on master. No Kconfig change, no API change, no 
build file change.
   
   ## Testing
   
   QEMU 10.2.2 under KVM (x86_64 Linux host) and QEMU 11.0.0 TCG (macOS host). 
Builds: make, GCC 12.3 in the NuttX CI image (Linux) and x86_64-elf GCC 16.2 
(macOS). All runs turn off `ARCH_INTEL64_HAVE_PCID` and turn on the NSH `date` 
and `sleep` commands. "HPET" means `ARCH_INTEL64_HPET_ALARM` and `INTEL64_HPET` 
instead of the TSC deadline timer. A script types `date`, `sleep 2`, `date`.
   
   | Config | Timer | RTC options | master | this PR |
   |---|---|---|---|---|
   | `knsh_romfs` (kernel) | HPET | `RTC`, `RTC_HIRES` | no NSH prompt (KVM and 
TCG) | build stops: `intel64_rtc.c:60: #error "CONFIG_RTC_HIRES needs a TSC 
system timer"` |
   | `nsh` (flat) | HPET | `RTC`, `RTC_HIRES` | no NSH prompt (KVM and TCG); 
TCG log: divide error at `intel64_rtc.c:103` | build stops with the same 
`#error` |
   | `knsh_romfs` | TSC deadline | `RTC`, `RTC_HIRES` | boots (KVM), `sleep 2` 
OK | the same; `.text` of `nuttx` the same as master |
   | `nsh` | TSC deadline | `RTC`, `RTC_HIRES` | boots (KVM), `sleep 2` OK | 
the same |
   | `knsh_romfs` | HPET | none | boots (KVM and TCG) | the same; `.text` of 
`nuttx` the same as master |
   | `knsh_romfs` | TSC deadline | none | boots (KVM) | the same |
   
   The TSC deadline images do not boot under TCG on the macOS host (also 
`qemu-intel64:nsh` of master without any RTC option), so they ran only under 
KVM. `knsh_romfs` with the APIC timer (`ARCH_INTEL64_TSC`) does not build on 
master and on this PR (`intel64_tsc_oneshot.c`: no member `start_absolute`), 
because `ARCH_INTEL64_TSC` does not select `ONESHOT_COUNT`. This is not related 
to the RTC. x86_64 has no protected build. Not built: CMake (no build file 
change). No CI test covers this: no x86_64 CI configuration sets 
`CONFIG_RTC_HIRES`.
   
   `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]

Reply via email to