correct the value of tod_data.origin

tod_data.origin should hold a time when TSC is zero.
This commit is contained in:
NAKAMURA Gou
2016-03-28 22:28:09 +09:00
parent 18add6a9bd
commit a2c29e8abf

View File

@ -208,6 +208,7 @@ static void time_init(void)
{ {
unsigned long tv_sec, tv_nsec; unsigned long tv_sec, tv_nsec;
unsigned long ns_per_kclock; unsigned long ns_per_kclock;
unsigned long tsc;
ihk_mc_get_boot_time(&tv_sec, &tv_nsec); ihk_mc_get_boot_time(&tv_sec, &tv_nsec);
ns_per_kclock = ihk_mc_get_ns_per_tsc(); ns_per_kclock = ihk_mc_get_ns_per_tsc();
@ -217,6 +218,15 @@ static void time_init(void)
if (ns_per_kclock) { if (ns_per_kclock) {
tod_data.clocks_per_sec = (1000L * NS_PER_SEC) / ns_per_kclock; tod_data.clocks_per_sec = (1000L * NS_PER_SEC) / ns_per_kclock;
tsc = rdtsc();
tod_data.origin.tv_sec -= tsc / tod_data.clocks_per_sec;
tod_data.origin.tv_nsec -= NS_PER_SEC * (tsc % tod_data.clocks_per_sec)
/ tod_data.clocks_per_sec;
if (tod_data.origin.tv_nsec < 0) {
--tod_data.origin.tv_sec;
tod_data.origin.tv_nsec += NS_PER_SEC;
}
} }
if (!ns_per_kclock) { if (!ns_per_kclock) {