diff options
author | Joshua Stein <jcs@cvs.openbsd.org> | 2019-08-03 14:57:52 +0000 |
---|---|---|
committer | Joshua Stein <jcs@cvs.openbsd.org> | 2019-08-03 14:57:52 +0000 |
commit | 609f17c4c92366068b20c4cedc30b030b38fce98 (patch) | |
tree | 8aa15f194d71a7b9e9d48be8218e57b2dd563013 /sys | |
parent | b89b3d250c206687c9081b01c86a671e626ba4fd (diff) |
If the CPU frequency is available during TSC init, make it available
for lapic timer init to avoid calibrating against the 8254 clock.
Some newer machines are shipping with the 8254 clock gated for power
saving, so it may not be usable.
ok mlarkin
discussed with deraadt
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/amd64/lapic.c | 12 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/tsc.c | 13 |
2 files changed, 19 insertions, 6 deletions
diff --git a/sys/arch/amd64/amd64/lapic.c b/sys/arch/amd64/amd64/lapic.c index 780ca0f7781..31863b2b0ac 100644 --- a/sys/arch/amd64/amd64/lapic.c +++ b/sys/arch/amd64/amd64/lapic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lapic.c,v 1.54 2019/04/23 06:51:04 guenther Exp $ */ +/* $OpenBSD: lapic.c,v 1.55 2019/08/03 14:57:51 jcs Exp $ */ /* $NetBSD: lapic.c,v 1.2 2003/05/08 01:04:35 fvdl Exp $ */ /*- @@ -408,7 +408,7 @@ u_int32_t lapic_tval; /* * this gets us up to a 4GHz busclock.... */ -u_int32_t lapic_per_second; +u_int32_t lapic_per_second = 0; u_int32_t lapic_frac_usec_per_cycle; u_int64_t lapic_frac_cycle_per_usec; u_int32_t lapic_delaytab[26]; @@ -488,6 +488,9 @@ lapic_calibrate_timer(struct cpu_info *ci) u_long s; int i; + if (lapic_per_second) + goto skip_calibration; + if (mp_verbose) printf("%s: calibrating local timer\n", ci->ci_dev->dv_xname); @@ -525,8 +528,9 @@ lapic_calibrate_timer(struct cpu_info *ci) lapic_per_second = tmp; - printf("%s: apic clock running at %lldMHz\n", - ci->ci_dev->dv_xname, tmp / (1000 * 1000)); +skip_calibration: + printf("%s: apic clock running at %dMHz\n", + ci->ci_dev->dv_xname, lapic_per_second / (1000 * 1000)); if (lapic_per_second != 0) { /* diff --git a/sys/arch/amd64/amd64/tsc.c b/sys/arch/amd64/amd64/tsc.c index 0c06f4f7cd2..2710ce162ce 100644 --- a/sys/arch/amd64/amd64/tsc.c +++ b/sys/arch/amd64/amd64/tsc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tsc.c,v 1.11 2019/06/06 19:43:35 kettenis Exp $ */ +/* $OpenBSD: tsc.c,v 1.12 2019/08/03 14:57:51 jcs Exp $ */ /* * Copyright (c) 2016,2017 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2017 Adam Steen <adam@adamsteen.com.au> @@ -35,6 +35,11 @@ int tsc_is_invariant; uint tsc_get_timecount(struct timecounter *tc); +#include "lapic.h" +#if NLAPIC > 0 +extern u_int32_t lapic_per_second; +#endif + struct timecounter tsc_timecounter = { tsc_get_timecount, NULL, ~0u, 0, "tsc", -1000, NULL }; @@ -68,8 +73,12 @@ tsc_freq_cpuid(struct cpu_info *ci) } if (ebx == 0 || eax == 0) count = 0; - else if ((count = (uint64_t)khz * (uint64_t)ebx / eax) != 0) + else if ((count = (uint64_t)khz * (uint64_t)ebx / eax) != 0) { +#if NLAPIC > 0 + lapic_per_second = khz * 1000; +#endif return (count * 1000); + } } return (0); |