Skip to content
Permalink
Browse files

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
  • Loading branch information...
jcs committed Aug 3, 2019
1 parent 7d01aa5 commit d72f70aa5ac4d8ade3f10d3366ab796d8ea2b9c1
Showing with 19 additions and 6 deletions.
  1. +8 −4 sys/arch/amd64/amd64/lapic.c
  2. +11 −2 sys/arch/amd64/amd64/tsc.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) {
/*
@@ -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);

0 comments on commit d72f70a

Please sign in to comment.
You can’t perform that action at this time.