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
rsx: Fix zcull time to not time travel to the future #8048
Conversation
Is there no way to return real time in nanoseconds? I know clock_gettime returns time with ns precision. These workarounds we keep adding are starting to become a burden. My original reason to use subvalue was a quick hack and building off of that was a bad idea in the first place. |
|
I am aware of the limitations of the subvalue, I'm the one who introduced it. We may not need to get 1ns precision for rdtsc to work, it should just make it so that we do not rely on the subvalue too much. Incrementing at a fixed rate was a lazy solution that I did in a few seconds with hopes of fixing it later. |
Invariant TSC doesn't have nanosecond resolution in reality - its "remainder part" is approximated by the CPU after multiplying the value from the stable tick source, which is somewhere 10-100 MHz (so-called "crystal frequency", possibly located on the motherboard). It's multiplied to approach the CPU base clock (for historical reasons), and only looks like it has high resolution, because there is no way to verify its accuracy anyway (unless you have an atomic clock lol). |
It may be true that there might a better fix for this in theory, but right now the bug needs fixing. |
This isn't an urgent fix, we can be more careful with implementation instead of spending time redoing it full later on. This is actually ok-ish, but now there is a wait which is not accounted for which is what bothers me the most. get_timebased_time() is also not cheap, this will cause slowdown if the condition is hit multiple times, which is why I was suggesting trying to use TSC if possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not satisfied with this solution, but doing this correctly is going to be a lot more work. As such, this can be merged as is, I'll implement it correctly later.
When timestamp_subvalue was equal to 1000 the reported time is the next microsecond, which means in comparison to other time reporting features with microsecond accuracy such current flip or vblank time (they use get_system_time()),
rsx::thread::timestamp()
has reported time ahead of the time flip/vblank reported.Even comparisons of two or more values from
rsx::thread::timestamp()
could have indicated such "time traveling". e.g if the first call hadx
value reported from get_system_time() and timestamp sub value that was greater than 1000, so if in the next call torsx::thread::timestamp()
the value reported by get_system_time() is greater thanx
but less thanx
+ subvalue then this is illegal.To fix this, forcefully wait in
rsx::thread::timestamp()
until the next time value is reported.Use the method with highest accuracy ps3 has to get the current time which is
get_timebased_time()
, it is used by PPU mftb and SPU decrementer read. It's fequancy is about 80 times higher than get_system_time().This ensures there won't be "time traveling" in comparison to PPU/SPU time as well.