You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ji...@apache.org on 2026/01/26 13:14:46 UTC
(nuttx) 03/06: sched/clock: Remove perf_init to simplify the code
This is an automated email from the ASF dual-hosted git repository.
jiuzhudong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 277626870dda349fdc4c300de66aa8d06101fa47
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 1 18:20:11 2025 +0800
sched/clock: Remove perf_init to simplify the code
Remove perf_init() function and automatic initialization call, relying
on static initialization instead to reduce code complexity and avoid
global variable access in perf_update callback.
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
sched/clock/clock.h | 6 -----
sched/clock/clock_initialize.c | 2 --
sched/clock/clock_perf.c | 54 +++++++++++-------------------------------
3 files changed, 14 insertions(+), 48 deletions(-)
diff --git a/sched/clock/clock.h b/sched/clock/clock.h
index dee8d848ee7..a59ce4a8627 100644
--- a/sched/clock/clock.h
+++ b/sched/clock/clock.h
@@ -78,12 +78,6 @@ void clock_increase_sched_ticks(clock_t ticks);
clock_t clock_get_sched_ticks(void);
-/****************************************************************************
- * perf_init
- ****************************************************************************/
-
-void perf_init(void);
-
#ifdef CONFIG_SCHED_CPULOAD_SYSCLK
void cpuload_init(void);
#endif
diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c
index 6305ac0536e..4a6bdff743a 100644
--- a/sched/clock/clock_initialize.c
+++ b/sched/clock/clock_initialize.c
@@ -227,8 +227,6 @@ void clock_initialize(void)
clock_inittime(NULL);
#endif
- perf_init();
-
#ifdef CONFIG_SCHED_CPULOAD_SYSCLK
cpuload_init();
#endif
diff --git a/sched/clock/clock_perf.c b/sched/clock/clock_perf.c
index 646e84fcb2a..1ca3cfc5082 100644
--- a/sched/clock/clock_perf.c
+++ b/sched/clock/clock_perf.c
@@ -42,7 +42,7 @@ struct perf_s
struct wdog_s wdog;
spinlock_t lock;
unsigned long last;
- unsigned long overflow;
+ clock_t overflow;
clock_t timeout;
};
@@ -62,33 +62,16 @@ static struct perf_s g_perf;
static void perf_update(wdparm_t arg)
{
- FAR struct perf_s *perf = &g_perf;
+ FAR struct perf_s *perf = (FAR struct perf_s *)arg;
perf_gettime();
- wd_start_next((FAR struct wdog_s *)arg, perf->timeout, perf_update, arg);
+ wd_start_next(&perf->wdog, perf->timeout, perf_update, arg);
}
/****************************************************************************
* Public Functions
****************************************************************************/
-/****************************************************************************
- * perf_init
- ****************************************************************************/
-
-void perf_init(void)
-{
- FAR struct perf_s *perf = &g_perf;
-
- perf->timeout = (((clock_t)1 << (CONFIG_ARCH_PERF_COUNT_BITWIDTH - 1)) - 1)
- * TICK_PER_SEC / up_perf_getfreq();
- perf->last = up_perf_gettime();
-
- /* Periodic check for overflow */
-
- wd_start(&perf->wdog, perf->timeout, perf_update, (wdparm_t)perf);
-}
-
/****************************************************************************
* perf_gettime
****************************************************************************/
@@ -100,16 +83,23 @@ clock_t perf_gettime(void)
clock_t now = up_perf_gettime();
clock_t result;
- /* Check if overflow */
+ if (perf->timeout == 0)
+ {
+ perf->timeout =
+ ((clock_t)1 << (CONFIG_ARCH_PERF_COUNT_BITWIDTH - 1)) *
+ TICK_PER_SEC / up_perf_getfreq();
+
+ /* Periodic check for overflow */
- if (now < perf->last)
+ wd_start(&perf->wdog, perf->timeout, perf_update, (wdparm_t)perf);
+ }
+ else if (now < perf->last)
{
perf->overflow++;
}
perf->last = now;
- result = (clock_t)now | \
- (clock_t)perf->overflow << CONFIG_ARCH_PERF_COUNT_BITWIDTH;
+ result = now | (perf->overflow << CONFIG_ARCH_PERF_COUNT_BITWIDTH);
spin_unlock_irqrestore(&perf->lock, flags);
return result;
}
@@ -139,14 +129,6 @@ unsigned long perf_getfreq(void)
#elif defined(CONFIG_ALARM_ARCH) || defined (CONFIG_TIMER_ARCH) || \
defined(CONFIG_ARCH_PERF_EVENTS)
-/****************************************************************************
- * perf_init
- ****************************************************************************/
-
-void perf_init(void)
-{
-}
-
/****************************************************************************
* perf_gettime
****************************************************************************/
@@ -176,14 +158,6 @@ unsigned long perf_getfreq(void)
#else
-/****************************************************************************
- * perf_init
- ****************************************************************************/
-
-void perf_init(void)
-{
-}
-
/****************************************************************************
* perf_gettime
****************************************************************************/