casaroli opened a new pull request, #21942: URL: https://github.com/apache/nuttx/pull/21942
## Summary On x86_64 (intel64), `intel64_rtc.c` has only the `CONFIG_RTC_HIRES` counter of the TSC. This counter starts at 0 at each boot. Without `CONFIG_RTC_HIRES`, a configuration with `CONFIG_RTC` does not link (`qemu-intel64:nsh` with `CONFIG_RTC` and `CONFIG_RTC_DATETIME`): ``` sched/clock/clock_initialize.c:87:(.text.clock_basetime+0x2): undefined reference to `up_rtc_getdatetime' sched/clock/clock_settime.c:99:(.text.clock_settime+0xa5): undefined reference to `g_rtc_enabled' sched/clock/clock_settime.c:117:(.text.clock_settime+0xb4): undefined reference to `up_rtc_settime' ``` Without `CONFIG_RTC_DATETIME`, `up_rtc_time()` is missing instead. Without `CONFIG_RTC`, the system starts at `CONFIG_START_YEAR` at each boot. This PR uses the CMOS clock of the PC (MC146818, I/O ports 0x70 and 0x71) when `CONFIG_RTC` is set and `CONFIG_RTC_HIRES` is not. `up_rtc_getdatetime()` (with `CONFIG_RTC_DATETIME`) or `up_rtc_time()` reads the date and the time, and `up_rtc_settime()` sets them. The code reads the registers when no update is in progress, and reads them again until two reads are the same. It reads BCD and binary mode, 12-hour and 24-hour mode, and the century register (0x32) when it gives 19 or 20. It uses the existing `g_rtc_lock`. QEMU gives the date and the time of the host in this clock. The `CONFIG_RTC_HIRES` code does not change. With `CONFIG_RTC_ARCH`, `drivers/timers/arch_rtc.c` defines `g_rtc_enabled`, so this file does not define it then (as `arch/risc-v/src/qemu-rv/qemu_rv_rtc.c`). The second commit adds an RTC section to `Documentation/platforms/x86_64/intel64/index.rst`. ## Impact Only x86_64 intel64 with `CONFIG_RTC` and without `CONFIG_RTC_HIRES`. These configurations did not link before. No `qemu-intel64` defconfig sets `CONFIG_RTC` (all 17 checked after `make olddefconfig`), so no CI build changes: in these configurations `intel64_rtc.o` is empty, the same as on master. No new Kconfig option. No API change. No build file change. ## Testing QEMU TCG, 1 CPU, `-machine pc,hpet=on -rtc base=utc`, x86_64-elf GCC 16.2, make. For TCG, the runs set `ARCH_INTEL64_HPET_ALARM` and `INTEL64_HPET` instead of the TSC deadline timer, and turn off `ARCH_INTEL64_HAVE_PCID`. They also set `BOARDCTL_RESET` and turn on the NSH `date`, `sleep` and `reboot` commands. A script types `date`, `date -s "Jan 02 03:04:05 2031"`, `date`, `sleep 2`, `reboot`, and `date` after the second boot. QEMU keeps the CMOS clock through the reset. | Config | RTC options | master | this PR | |---|---|---|---| | `knsh_romfs` (kernel) | `RTC`, `RTC_DATETIME` | link fails | boot: `Tue, Nov 17 09:45:51 2026` (host UTC 09:45:51); after reboot: `Thu, Jan 02 03:04:07 2031` | | `knsh_romfs` | `RTC` | link fails (`up_rtc_time`) | boot: host time; after reboot: `Thu, Jan 02 03:04:07 2031` | | `knsh_romfs` | `RTC`, `RTC_DATETIME`, `RTC_DRIVER`, `RTC_ARCH` | not built | boot: host time; after reboot: `Thu, Jan 02 03:04:07 2031` | | `nsh` (flat) | `RTC`, `RTC_DATETIME` | link fails | boot: host time; after reboot: `Thu, Jan 02 03:04:07 2031` | | `nsh` | `RTC` | not built | boot: host time; after reboot: `Thu, Jan 02 03:04:07 2031` | | `knsh_romfs`, `nsh` | none | boot: `Thu, Mar 03 00:00:00 2011`; after reboot: 2011 again | the same as master; `intel64_rtc.o` and `nuttx` sizes the same as master | | `knsh_romfs`, `nsh` | `RTC`, `RTC_HIRES` | builds | builds; `objdump -d` of `intel64_rtc.o` the same as master | These CI configurations also build on this PR: `qemu-intel64:ostest`, `citest_smp`, `nsh_pci`, `nsh_pci_smp`, `knsh_romfs_pci`. x86_64 has no protected build. Not run: KVM, real PC hardware, and the binary and 12-hour modes (the CMOS clock of QEMU is in BCD and 24-hour mode). Not built: CMake (no build file changes). No CI test covers this: no x86_64 CI configuration sets `CONFIG_RTC`, and no test in apps compares the date with the clock of the host. `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]
