imx8: detect cpu lcycles() frequency

This commit is contained in:
cinap_lenrek 2022-07-09 16:06:42 +00:00
parent 2b89cdee02
commit 90f47fadf8
2 changed files with 27 additions and 2 deletions

View file

@ -29,6 +29,9 @@ localclockintr(Ureg *ureg, void *)
void void
clockinit(void) clockinit(void)
{ {
uvlong tstart, tend;
ulong t0, t1;
syswr(PMCR_EL0, 1<<6 | 7); syswr(PMCR_EL0, 1<<6 | 7);
syswr(PMCNTENSET, 1<<31); syswr(PMCNTENSET, 1<<31);
syswr(PMUSERENR_EL0, 1<<2); syswr(PMUSERENR_EL0, 1<<2);
@ -41,8 +44,22 @@ clockinit(void)
freq = sysrd(CNTFRQ_EL0); freq = sysrd(CNTFRQ_EL0);
print("timer frequency %lld Hz\n", freq); print("timer frequency %lld Hz\n", freq);
} }
m->cpuhz = freq; tstart = sysrd(CNTPCT_EL0);
m->cpumhz = (freq + Mhz/2 - 1) / Mhz; do{
t0 = lcycles();
}while(sysrd(CNTPCT_EL0) == tstart);
tend = tstart + (freq/100);
do{
t1 = lcycles();
}while(sysrd(CNTPCT_EL0) < tend);
t1 -= t0;
m->cpuhz = 100 * t1;
m->cpumhz = (m->cpuhz + Mhz/2 - 1) / Mhz;
/*
* we are using virtual counter register CNTVCT_EL0
* instead of the performance counter in userspace.
*/
m->cyclefreq = freq; m->cyclefreq = freq;
intrenable(IRQcntpns, localclockintr, nil, BUSUNKNOWN, "clock"); intrenable(IRQcntpns, localclockintr, nil, BUSUNKNOWN, "clock");

View file

@ -134,6 +134,12 @@ mpinit(void)
spllo(); spllo();
} }
void
cpuidprint(void)
{
iprint("cpu%d: %dMHz ARM Cortex A53\n", m->machno, m->cpumhz);
}
void void
main(void) main(void)
{ {
@ -143,6 +149,7 @@ main(void)
fpuinit(); fpuinit();
intrinit(); intrinit();
clockinit(); clockinit();
cpuidprint();
synccycles(); synccycles();
timersinit(); timersinit();
flushtlb(); flushtlb();
@ -162,6 +169,7 @@ main(void)
fpuinit(); fpuinit();
intrinit(); intrinit();
clockinit(); clockinit();
cpuidprint();
timersinit(); timersinit();
pageinit(); pageinit();
procinit0(); procinit0();