casaroli opened a new pull request, #21965: URL: https://github.com/apache/nuttx/pull/21965
## Summary On x86_64 (intel64), `intel64_perf.c` gives `up_perf_*()` from the TSC (`rdtscp`) and converts with `g_x86_64_timer_freq`. Only the TSC DEADLINE and APIC timers set this frequency (`x86_64_timer_calibrate_freq()`). With the HPET timer (`CONFIG_ARCH_INTEL64_HPET_ALARM`) it is 0: `perf_getfreq()` returns 0 and `up_perf_convert()` divides by 0. `CONFIG_ARCH_PERF_EVENTS` is on by default with `SCHED_IRQMONITOR` and `SCHED_CRITMONITOR`, so `qemu-intel64:citest_smp` (HPET, `SCHED_IRQMONITOR`) has it. A read of `/proc/irqs` then divides by 0 in the kernel: in `knsh_romfs` the system hangs, in the flat `nsh` the shell ends with SIGFPE. ostest reports `Performance frequency = 0 Hz`. The second commit selects `ARCH_HAVE_PERF_EVENTS` from `ARCH_INTEL64_HAVE_TSC` (the two TSC timers) instead of from `ARCH_X86_64`. With the HPET timer, `CONFIG_ARCH_PERF_EVENTS` is then not available, and `drivers/timers/arch_alarm.c` gives `up_perf_*()` from the HPET counter with the HPET frequency, as on other architectures without a cycle counter. The first commit fixes `arch/x86_64/src/intel64/Make.defs`, which put `#ifdef CONFIG_ARCH_PERF_EVENTS` around the line that adds `intel64_perf.c`. Make reads a line that starts with `#` as a comment, so the Make build compiled `intel64_perf.c` in every configuration. `CMakeLists.txt` already adds the file only with `CONFIG_ARCH_PERF_EVENTS`. The commit uses `ifeq`, and removes the `CONFIG_ARCH_HAVE_PERF_EVENTS` check inside `intel64_perf.c`, which is then always true. ## Impact x86_64 intel64 only. With the TSC DEADLINE or APIC timer, nothing changes when `CONFIG_ARCH_PERF_EVENTS` is on; when it is off, the Make build no longer compiles the unused `intel64_perf.c`, as the CMake build already does. With the HPET timer, `CONFIG_ARCH_PERF_EVENTS` is not available, and perf events count the HPET. An HPET read is slower than `rdtscp`; ostest under KVM takes the same time as on master (see Testing). All qemu-intel64 defconfigs give the same `make savedefconfig`. No API change. ## Testing QEMU 10.2.2 under KVM, GCC 12.3 in the NuttX CI image, make. "HPET" means `ARCH_INTEL64_HPET_ALARM` and `INTEL64_HPET` instead of the TSC deadline timer. `+mon` means `SCHED_IRQMONITOR` and `ARCH_PERF_EVENTS` on (on this PR `ARCH_PERF_EVENTS` is not available with the HPET); the flat `nsh` also has `SCHED_CRITMONITOR`. | Config | Test | master | this PR | |---|---|---|---| | `knsh_romfs` (kernel), HPET, +mon | `cat /proc/irqs` | no output, the system hangs (divide by zero in a system call) | the IRQ table with times | | `nsh` (flat), HPET, +mon | `cat /proc/irqs` | no output; the shell gets SIGFPE and ends (`ps`: a new `sh`) | the IRQ table with times | | `nsh`, HPET, +mon | ostest | `Performance frequency = 0 Hz`, `WARNING - Performance frequency is invalid`, exit 0 | exit 0 (`ARCH_PERF_EVENTS` not available: the perf test of ostest is skipped) | | `nsh`, HPET, `SCHED_IRQMONITOR` (+ `SCHED_CRITMONITOR`) | ostest time under KVM | 2 min 39 s (2 min 38 s) | 2 min 37 s (2 min 39 s) | | `nsh`, TSC deadline, +mon | `cat /proc/irqs`, ostest | - | IRQ table; `Performance frequency = 2600000000 Hz`, exit 0 | All 17 qemu-intel64 defconfigs build (make) with this PR and the other three intel64 fixes applied, and `make savedefconfig` gives the same defconfig as on master for each. x86_64 has no protected build. Not built: CMake (no CMake file change; the Kconfig change applies to both). No CI test covers this: CI builds the x86_64 defconfigs but runs none of them. `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]
