Page MenuHomeFreeBSD

PowerPC: Switch to more accurate unit to avoid division rounding
ClosedPublic

Authored by pdk_semihalf.com on Feb 19 2018, 12:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 4, 6:04 PM
Unknown Object (File)
Sat, Sep 27, 10:08 PM
Unknown Object (File)
Thu, Sep 25, 11:41 PM
Unknown Object (File)
Tue, Sep 23, 8:43 AM
Unknown Object (File)
Tue, Sep 16, 8:56 PM
Unknown Object (File)
Aug 30 2025, 11:35 PM
Unknown Object (File)
Aug 3 2025, 9:44 AM
Unknown Object (File)
Aug 2 2025, 8:55 PM
Subscribers
None

Details

Summary

On POWER8 architecture there is a timer with 512Mhz frequency.
It has about 1,95ns period, but it is rounded to 1ns which is not accurate.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

I think this breaks 32-bit builds since ps_per_tick is too small there. I think it needs to be bumped to uint64_t.

Changed type of ps_per_tick to uint64_t

This revision was not accepted when it landed; it landed in state Needs Review.Feb 20 2018, 7:31 AM
This revision was automatically updated to reflect the committed changes.

Just a comment on uint64_t: ps is 10^12, which is 36 bits to represent 1s, so switching to uint64_t will gives the most safety, especially given that the howmany macro isn't careful about overflow. Since it's just used in DELAY, and we know n for delay is usually small except in some crazy old ISA drivers, it likely worked or closely worked with 32-bit types. It wouldn't hit problems until several hundred or maybe thousand milliseconds if the back of the envelop numbers I just ran are right....
I'd be tempted in DELAY to s/u_quad_t/uint64_t/g since the quad name for that type is discouraged, but it's not a bug deal either way.
Quibbles aside, this was a good change before the change to 64-bit, and is a better change with that change as clocks will only get faster from here.