Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time is slow #54

Open
trasz opened this issue Oct 5, 2017 · 10 comments
Open

Time is slow #54

trasz opened this issue Oct 5, 2017 · 10 comments
Labels

Comments

@trasz
Copy link
Contributor

trasz commented Oct 5, 2017

With stock CheriBSD and Qemu, ystem time is mostly ok, except twice as slow as it should be:

# while :; do date; sleep 10; done                  
Thu Oct  5 13:06:40 UTC 2017                        
Thu Oct  5 13:06:50 UTC 2017
Thu Oct  5 13:07:00 UTC 2017
Thu Oct  5 13:07:11 UTC 2017
Thu Oct  5 13:07:21 UTC 2017
Thu Oct  5 13:07:31 UTC 2017
Thu Oct  5 13:07:41 UTC 2017
Thu Oct  5 13:07:51 UTC 2017

Each line takes exactly 20 seconds to display (as far as I've been able to measure it with a stopwatch).

@trasz trasz added the bug label Oct 5, 2017
@trasz
Copy link
Contributor Author

trasz commented Oct 5, 2017

(There is also what seems to be a separate issue, where time goes all over the place, along with "vmstat -i" showing the rate for clock0 to be around 700 instead of the usual 92, but it's harder to reproduce.)

@rmn30
Copy link
Contributor

rmn30 commented Oct 5, 2017 via email

@trasz
Copy link
Contributor Author

trasz commented Oct 5, 2017

That's what Robert mentioned to me as well. Still, I think it's good to have a ticket for tracking this particular issue until it's fixed.

@Jerryxia32
Copy link

The spec of our MIPS reference implementation says the count register should increment at half the issue width times the clock frequency, in this case 0.5 * clock freq, but the FPGA implementation increments the count register at the same frequency as the CPU clock. So unless the two implementations agree on each other or FreeBSD treats the two targets differently with respect to the clock, it is not easy to solve.

@davidchisnall
Copy link
Member

Maybe FreeBSD startup code should read the count register, run 100 ssnops, read the count register, and see if the value is 50, or 100 more?

@rwatson
Copy link
Member

rwatson commented Oct 5, 2017

Does Qemu actually pass through a host cycle count, or does it simply count instruction issues rather than having some other notion of cycle?

(Passing through host cycles might be a problem given the small scope of the MIPS cycle counter and the impact of host context switches -- and often ISA-level simulators simply report commit count/2 as the cycle count as a result. It would be good to confirm what Qemu does before drawing too many conclusions about remedies.)

@trasz
Copy link
Contributor Author

trasz commented Oct 9, 2017

According to http://www.cs.tau.ac.il/~afek/MipsInstructionSetReference.pdf, there's the CCRes returned by rdhwr, which defines how often the counter gets incremented. Judging by the code, Qemu seems to set it to 2, which means "CC register increments every second CPU cycle".

@trasz
Copy link
Contributor Author

trasz commented Oct 9, 2017

Should be fixed by CTSRD-CHERI/cheribsd@8b576af.

@trasz trasz closed this as completed Oct 9, 2017
@arichardson
Copy link
Member

It looks like this changed in b79c3d9

@trasz
Copy link
Contributor Author

trasz commented Oct 10, 2017

Good catch. Indeed, backing out b79c3d9 (and CTSRD-CHERI/cheribsd@8b576af) fixes the problem. It also fixes #55.

I have no idea why, though. There's something weird going on there; for some reason putting some CPU load on the guest results in timer interrupts firing faster, with and without that change.

@trasz trasz reopened this Oct 10, 2017
trasz referenced this issue Oct 10, 2017
The MIPS Count register is incremented every 2 cycles, not every
cycle (according to sys/mips/include/clock.h).

Also, instead of using muldiv64() to convert from ticks to nanoseconds:
	y = muldiv64(x, get_ticks_per_sec(), TIMER_FREQ)
where y = number of system ticks and x = device ticks we can just do:
	y = x * 10ns (for 100Mhz clock)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants