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 <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2025-06-01 18:20:11 +08:00
committed by Donny(董九柱)
parent 197ed9fc94
commit 277626870d
3 changed files with 14 additions and 48 deletions
-6
View File
@@ -78,12 +78,6 @@ void clock_increase_sched_ticks(clock_t ticks);
clock_t clock_get_sched_ticks(void); clock_t clock_get_sched_ticks(void);
/****************************************************************************
* perf_init
****************************************************************************/
void perf_init(void);
#ifdef CONFIG_SCHED_CPULOAD_SYSCLK #ifdef CONFIG_SCHED_CPULOAD_SYSCLK
void cpuload_init(void); void cpuload_init(void);
#endif #endif
-2
View File
@@ -227,8 +227,6 @@ void clock_initialize(void)
clock_inittime(NULL); clock_inittime(NULL);
#endif #endif
perf_init();
#ifdef CONFIG_SCHED_CPULOAD_SYSCLK #ifdef CONFIG_SCHED_CPULOAD_SYSCLK
cpuload_init(); cpuload_init();
#endif #endif
+14 -40
View File
@@ -42,7 +42,7 @@ struct perf_s
struct wdog_s wdog; struct wdog_s wdog;
spinlock_t lock; spinlock_t lock;
unsigned long last; unsigned long last;
unsigned long overflow; clock_t overflow;
clock_t timeout; clock_t timeout;
}; };
@@ -62,33 +62,16 @@ static struct perf_s g_perf;
static void perf_update(wdparm_t arg) 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(); 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 * 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 * perf_gettime
****************************************************************************/ ****************************************************************************/
@@ -100,16 +83,23 @@ clock_t perf_gettime(void)
clock_t now = up_perf_gettime(); clock_t now = up_perf_gettime();
clock_t result; 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();
if (now < perf->last) /* Periodic check for overflow */
wd_start(&perf->wdog, perf->timeout, perf_update, (wdparm_t)perf);
}
else if (now < perf->last)
{ {
perf->overflow++; perf->overflow++;
} }
perf->last = now; perf->last = now;
result = (clock_t)now | \ result = now | (perf->overflow << CONFIG_ARCH_PERF_COUNT_BITWIDTH);
(clock_t)perf->overflow << CONFIG_ARCH_PERF_COUNT_BITWIDTH;
spin_unlock_irqrestore(&perf->lock, flags); spin_unlock_irqrestore(&perf->lock, flags);
return result; return result;
} }
@@ -139,14 +129,6 @@ unsigned long perf_getfreq(void)
#elif defined(CONFIG_ALARM_ARCH) || defined (CONFIG_TIMER_ARCH) || \ #elif defined(CONFIG_ALARM_ARCH) || defined (CONFIG_TIMER_ARCH) || \
defined(CONFIG_ARCH_PERF_EVENTS) defined(CONFIG_ARCH_PERF_EVENTS)
/****************************************************************************
* perf_init
****************************************************************************/
void perf_init(void)
{
}
/**************************************************************************** /****************************************************************************
* perf_gettime * perf_gettime
****************************************************************************/ ****************************************************************************/
@@ -176,14 +158,6 @@ unsigned long perf_getfreq(void)
#else #else
/****************************************************************************
* perf_init
****************************************************************************/
void perf_init(void)
{
}
/**************************************************************************** /****************************************************************************
* perf_gettime * perf_gettime
****************************************************************************/ ****************************************************************************/