This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e7c46a9f2f00f7d903238e4299138414544e07b6 Author: Marco Casaroli <[email protected]> AuthorDate: Tue Nov 3 17:27:45 2026 +0100 sched/clock: Use up_perf_*() only when they count. Since #16487 an arch with ARCH_HAVE_PERF_EVENTS always provides up_perf_*(), and arch_alarm.c and arch_timer.c do not. But perf_gettime() still uses up_perf_gettime() with ALARM_ARCH or TIMER_ARCH, also when ARCH_PERF_EVENTS is off. The arch then does not start its counter (up_perf_init() is not called), so perf_gettime() returns a constant and perf_convert() divides by ULONG_MAX. On arm64 (always ALARM_ARCH) with SCHED_CRITMONITOR and without ARCH_PERF_EVENTS, all critmon times are 0. This happens when SCHED_CRITMONITOR is enabled in an existing .config: the "default y" of ARCH_PERF_EVENTS does not change its old value. Use up_perf_*() only with ARCH_PERF_EVENTS, or when arch_alarm.c or arch_timer.c provide them. Else use the system ticks, as the help of ARCH_PERF_EVENTS says. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- sched/clock/clock_perf.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sched/clock/clock_perf.c b/sched/clock/clock_perf.c index 711f0c9d9e5..447645d2629 100644 --- a/sched/clock/clock_perf.c +++ b/sched/clock/clock_perf.c @@ -32,13 +32,24 @@ #include <nuttx/sched.h> #include <nuttx/wdog.h> -#ifndef CONFIG_ARCH_PERF_EVENTS_USER_ACCESS - /**************************************************************************** * Preprocessors ****************************************************************************/ -# if defined(CONFIG_PERF_OVERFLOW_CORRECTION) && ULONG_MAX != UINT64_MAX +/* Use up_perf_*() only when they count: the arch counter runs only with + * ARCH_PERF_EVENTS, and arch_alarm.c or arch_timer.c give up_perf_*() only + * without ARCH_HAVE_PERF_EVENTS. Else use the system ticks. + */ + +#if defined(CONFIG_ARCH_PERF_EVENTS) || \ + (!defined(CONFIG_ARCH_HAVE_PERF_EVENTS) && \ + (defined(CONFIG_ALARM_ARCH) || defined(CONFIG_TIMER_ARCH))) +# define USE_UP_PERF +#endif + +#ifndef CONFIG_ARCH_PERF_EVENTS_USER_ACCESS +# if defined(USE_UP_PERF) && defined(CONFIG_PERF_OVERFLOW_CORRECTION) && \ + ULONG_MAX != UINT64_MAX /**************************************************************************** * Private Types @@ -138,8 +149,7 @@ clock_t perf_gettime(void) return result; } -# elif defined(CONFIG_ALARM_ARCH) || defined (CONFIG_TIMER_ARCH) || \ - defined(CONFIG_ARCH_PERF_EVENTS) +# elif defined(USE_UP_PERF) /**************************************************************************** * perf_gettime @@ -164,8 +174,7 @@ clock_t perf_gettime(void) # endif #endif /* !CONFIG_ARCH_PERF_EVENTS_USER_ACCESS */ -#if defined(CONFIG_ALARM_ARCH) || defined (CONFIG_TIMER_ARCH) || \ - defined(CONFIG_ARCH_PERF_EVENTS) +#ifdef USE_UP_PERF /**************************************************************************** * perf_convert
