1
0
Fork 0
forked from nuttx/nuttx-update

arch/arm64: Modify the method for obtaining the CPU frequency

Summary:
1、cntfrq_el0 is used to store the timer frequency, which may
   be different from the CPU frequency.
2、Do not use up_perf interface for SMP.

Signed-off-by: wangming9 <wangming9@xiaomi.com>
This commit is contained in:
wangming9 2023-10-27 11:22:07 +08:00 committed by GUIDINGLI
parent e9b77833e3
commit fa96350574
7 changed files with 28 additions and 8 deletions

View file

@ -202,6 +202,5 @@ void arm64_boot_el1_init(void)
void arm64_boot_primary_c_routine(void)
{
arm64_chip_boot();
up_perf_init(NULL);
nx_start();
}

View file

@ -232,7 +232,5 @@ void arm64_boot_secondary_c_routine(void)
arm64_gic_secondary_init();
up_perf_init(NULL);
arm64_smp_init_top();
}

View file

@ -28,12 +28,20 @@
#ifdef CONFIG_ARCH_PERF_EVENTS
/****************************************************************************
* Private Data
****************************************************************************/
static unsigned long g_cpu_freq = ULONG_MAX;
/****************************************************************************
* Public Functions
****************************************************************************/
void up_perf_init(void *arg)
{
g_cpu_freq = (unsigned long)(uintptr_t)arg;
pmu_ccntr_ccfiltr_config(PMCCFILTR_EL0_NSH);
pmu_cntr_control_config(PMCR_EL0_C | PMCR_EL0_E);
pmu_cntr_trap_control(PMUSERENR_EL0_EN);
@ -43,7 +51,7 @@ void up_perf_init(void *arg)
unsigned long up_perf_getfreq(void)
{
return read_sysreg(cntfrq_el0);
return g_cpu_freq;
}
unsigned long up_perf_gettime(void)
@ -54,10 +62,9 @@ unsigned long up_perf_gettime(void)
void up_perf_convert(unsigned long elapsed, struct timespec *ts)
{
unsigned long left;
unsigned long cpu_freq = read_sysreg(cntfrq_el0);
ts->tv_sec = elapsed / cpu_freq;
left = elapsed - ts->tv_sec * cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * left / cpu_freq;
ts->tv_sec = elapsed / g_cpu_freq;
left = elapsed - ts->tv_sec * g_cpu_freq;
ts->tv_nsec = NSEC_PER_SEC * left / g_cpu_freq;
}
#endif

View file

@ -182,4 +182,8 @@ void arm64_chip_boot(void)
arm64_earlyserialinit();
#endif
#ifdef CONFIG_ARCH_PERF_EVENTS
up_perf_init((void *)CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
#endif
}

View file

@ -170,6 +170,10 @@ void arm64_chip_boot(void)
arm64_earlyserialinit();
#endif
#ifdef CONFIG_ARCH_PERF_EVENTS
up_perf_init((void *)CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
#endif
}
#if defined(CONFIG_NET) && !defined(CONFIG_NETDEV_LATEINIT)

View file

@ -112,4 +112,8 @@ void arm64_chip_boot(void)
arm64_earlyserialinit();
#endif
#ifdef CONFIG_ARCH_PERF_EVENTS
up_perf_init((void *)CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
#endif
}

View file

@ -195,6 +195,10 @@ void arm64_chip_boot(void)
arm64_earlyserialinit();
#endif
#ifdef CONFIG_ARCH_PERF_EVENTS
up_perf_init((void *)CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC);
#endif
}
#if defined(CONFIG_NET) && !defined(CONFIG_NETDEV_LATEINIT)