templexxx / tsc

Get unix time (nanoseconds) in 8ns, 10x faster than stdlib
MIT License
136 stars 5 forks source link

INTEL_FAM6_SKYLAKE_X tsc frequency unstable #3

Closed templexxx closed 4 years ago

templexxx commented 4 years ago

Follow these steps, may help:

  1. Run test, see if TestUnixNanoCmpWallClock could pass

If ok, means tsc could work well at start time. If not ok, tsc should be disabled in INTEL_FAM6_SKYLAKE_X

  1. Run tsc.Calibrate() every few minutes(e.g. 10 mins) in a independent goroutine in background to catch up the wall clock.
templexxx commented 4 years ago

More infos:

I think the Intel family in kernel is not that correctly. Skylake and other xeon scalable CPUs has the same sign, but the behavior of TSC frequency maybe different. (Skylake has issue, but others don't)

I can't just adjust TSC frequency by the sign.

templexxx commented 4 years ago

My question on Intel community: https://community.intel.com/t5/Processors/About-crystal-frequency-slow-down-in-Xeon-non-skylake/m-p/1203891#M45745

templexxx commented 4 years ago

New question in other forum(suggested by Intel member):

https://community.intel.com/t5/Software-Tuning-Performance/About-crystal-frequency-slow-down-in-Xeon-non-skylake/m-p/1204217#M7626

templexxx commented 4 years ago

About detecting microarchitecture on Xeon Scalable: https://community.intel.com/t5/Software-Tuning-Performance/How-to-detect-microarchitecture-on-Xeon-Scalable/m-p/1205162#M7633

templexxx commented 4 years ago

Have found new way to accurate the tsc frequency

wenjianhn commented 3 years ago

Is this related to https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=b511203093489eb1829cb4de86e8214752205ac6 ?

templexxx commented 3 years ago

Is this related to https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=b511203093489eb1829cb4de86e8214752205ac6 ?

Yes, actually the frequency listed by Intel manual is just a referrence. The real crystal frequency should be got by testing, and even with the same CPU family_id & sign_id & stepping_id, the frequency is quite different.

Anyway, I still provide frequency detection by CPU_ID in my other project: https://github.com/templexxx/cpu/blob/master/cpu_x86.go#L216-L257