| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: cpu.c,v 1.195 2020/07/14 00:45:53 yamaguchi Exp $ */ | | 1 | /* $NetBSD: cpu.c,v 1.196 2020/07/28 14:49:55 fcambus Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2000-2020 NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2000-2020 NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Bill Sommerfeld of RedBack Networks Inc, and by Andrew Doran. | | 8 | * by Bill Sommerfeld of RedBack Networks Inc, and by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -52,27 +52,27 @@ | | | @@ -52,27 +52,27 @@ |
52 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 52 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE | | 54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE |
55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
61 | * SUCH DAMAGE. | | 61 | * SUCH DAMAGE. |
62 | */ | | 62 | */ |
63 | | | 63 | |
64 | #include <sys/cdefs.h> | | 64 | #include <sys/cdefs.h> |
65 | __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.195 2020/07/14 00:45:53 yamaguchi Exp $"); | | 65 | __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.196 2020/07/28 14:49:55 fcambus Exp $"); |
66 | | | 66 | |
67 | #include "opt_ddb.h" | | 67 | #include "opt_ddb.h" |
68 | #include "opt_mpbios.h" /* for MPDEBUG */ | | 68 | #include "opt_mpbios.h" /* for MPDEBUG */ |
69 | #include "opt_mtrr.h" | | 69 | #include "opt_mtrr.h" |
70 | #include "opt_multiprocessor.h" | | 70 | #include "opt_multiprocessor.h" |
71 | #include "opt_svs.h" | | 71 | #include "opt_svs.h" |
72 | | | 72 | |
73 | #include "lapic.h" | | 73 | #include "lapic.h" |
74 | #include "ioapic.h" | | 74 | #include "ioapic.h" |
75 | #include "acpica.h" | | 75 | #include "acpica.h" |
76 | #include "hpet.h" | | 76 | #include "hpet.h" |
77 | | | 77 | |
78 | #include <sys/param.h> | | 78 | #include <sys/param.h> |
| @@ -1214,27 +1214,27 @@ cpu_offline_md(void) | | | @@ -1214,27 +1214,27 @@ cpu_offline_md(void) |
1214 | return; | | 1214 | return; |
1215 | } | | 1215 | } |
1216 | | | 1216 | |
1217 | /* XXX joerg restructure and restart CPUs individually */ | | 1217 | /* XXX joerg restructure and restart CPUs individually */ |
1218 | static bool | | 1218 | static bool |
1219 | cpu_stop(device_t dv) | | 1219 | cpu_stop(device_t dv) |
1220 | { | | 1220 | { |
1221 | struct cpu_softc *sc = device_private(dv); | | 1221 | struct cpu_softc *sc = device_private(dv); |
1222 | struct cpu_info *ci = sc->sc_info; | | 1222 | struct cpu_info *ci = sc->sc_info; |
1223 | int err; | | 1223 | int err; |
1224 | | | 1224 | |
1225 | KASSERT((ci->ci_flags & CPUF_PRESENT) != 0); | | 1225 | KASSERT((ci->ci_flags & CPUF_PRESENT) != 0); |
1226 | | | 1226 | |
1227 | if ((ci->ci_flags & CPUF_PRIMARY) != 0) | | 1227 | if (CPU_IS_PRIMARY(ci)) |
1228 | return true; | | 1228 | return true; |
1229 | | | 1229 | |
1230 | if (ci->ci_data.cpu_idlelwp == NULL) | | 1230 | if (ci->ci_data.cpu_idlelwp == NULL) |
1231 | return true; | | 1231 | return true; |
1232 | | | 1232 | |
1233 | sc->sc_wasonline = !(ci->ci_schedstate.spc_flags & SPCF_OFFLINE); | | 1233 | sc->sc_wasonline = !(ci->ci_schedstate.spc_flags & SPCF_OFFLINE); |
1234 | | | 1234 | |
1235 | if (sc->sc_wasonline) { | | 1235 | if (sc->sc_wasonline) { |
1236 | mutex_enter(&cpu_lock); | | 1236 | mutex_enter(&cpu_lock); |
1237 | err = cpu_setstate(ci, false); | | 1237 | err = cpu_setstate(ci, false); |
1238 | mutex_exit(&cpu_lock); | | 1238 | mutex_exit(&cpu_lock); |
1239 | | | 1239 | |
1240 | if (err != 0) | | 1240 | if (err != 0) |
| @@ -1259,27 +1259,27 @@ cpu_suspend(device_t dv, const pmf_qual_ | | | @@ -1259,27 +1259,27 @@ cpu_suspend(device_t dv, const pmf_qual_ |
1259 | return cpu_stop(dv); | | 1259 | return cpu_stop(dv); |
1260 | } | | 1260 | } |
1261 | | | 1261 | |
1262 | static bool | | 1262 | static bool |
1263 | cpu_resume(device_t dv, const pmf_qual_t *qual) | | 1263 | cpu_resume(device_t dv, const pmf_qual_t *qual) |
1264 | { | | 1264 | { |
1265 | struct cpu_softc *sc = device_private(dv); | | 1265 | struct cpu_softc *sc = device_private(dv); |
1266 | struct cpu_info *ci = sc->sc_info; | | 1266 | struct cpu_info *ci = sc->sc_info; |
1267 | int err = 0; | | 1267 | int err = 0; |
1268 | | | 1268 | |
1269 | if ((ci->ci_flags & CPUF_PRESENT) == 0) | | 1269 | if ((ci->ci_flags & CPUF_PRESENT) == 0) |
1270 | return true; | | 1270 | return true; |
1271 | | | 1271 | |
1272 | if ((ci->ci_flags & CPUF_PRIMARY) != 0) | | 1272 | if (CPU_IS_PRIMARY(ci)) |
1273 | goto out; | | 1273 | goto out; |
1274 | | | 1274 | |
1275 | if (ci->ci_data.cpu_idlelwp == NULL) | | 1275 | if (ci->ci_data.cpu_idlelwp == NULL) |
1276 | goto out; | | 1276 | goto out; |
1277 | | | 1277 | |
1278 | if (sc->sc_wasonline) { | | 1278 | if (sc->sc_wasonline) { |
1279 | mutex_enter(&cpu_lock); | | 1279 | mutex_enter(&cpu_lock); |
1280 | err = cpu_setstate(ci, true); | | 1280 | err = cpu_setstate(ci, true); |
1281 | mutex_exit(&cpu_lock); | | 1281 | mutex_exit(&cpu_lock); |
1282 | } | | 1282 | } |
1283 | | | 1283 | |
1284 | out: | | 1284 | out: |
1285 | if (err != 0) | | 1285 | if (err != 0) |
| @@ -1302,27 +1302,27 @@ cpu_shutdown(device_t dv, int how) | | | @@ -1302,27 +1302,27 @@ cpu_shutdown(device_t dv, int how) |
1302 | if ((ci->ci_flags & CPUF_PRESENT) == 0) | | 1302 | if ((ci->ci_flags & CPUF_PRESENT) == 0) |
1303 | return true; | | 1303 | return true; |
1304 | | | 1304 | |
1305 | return cpu_stop(dv); | | 1305 | return cpu_stop(dv); |
1306 | } | | 1306 | } |
1307 | | | 1307 | |
1308 | /* Get the TSC frequency and set it to ci->ci_data.cpu_cc_freq. */ | | 1308 | /* Get the TSC frequency and set it to ci->ci_data.cpu_cc_freq. */ |
1309 | void | | 1309 | void |
1310 | cpu_get_tsc_freq(struct cpu_info *ci) | | 1310 | cpu_get_tsc_freq(struct cpu_info *ci) |
1311 | { | | 1311 | { |
1312 | uint64_t freq = 0, freq_from_cpuid, t0, t1; | | 1312 | uint64_t freq = 0, freq_from_cpuid, t0, t1; |
1313 | int64_t overhead; | | 1313 | int64_t overhead; |
1314 | | | 1314 | |
1315 | if ((ci->ci_flags & CPUF_PRIMARY) != 0 && cpu_hascounter()) { | | 1315 | if (CPU_IS_PRIMARY(ci) && cpu_hascounter()) { |
1316 | /* | | 1316 | /* |
1317 | * If it's the first call of this function, try to get TSC | | 1317 | * If it's the first call of this function, try to get TSC |
1318 | * freq from CPUID by calling cpu_tsc_freq_cpuid(). | | 1318 | * freq from CPUID by calling cpu_tsc_freq_cpuid(). |
1319 | * The function also set lapic_per_second variable if it's | | 1319 | * The function also set lapic_per_second variable if it's |
1320 | * known. This is required for Intel's Comet Lake and newer | | 1320 | * known. This is required for Intel's Comet Lake and newer |
1321 | * processors to set LAPIC timer correctly. | | 1321 | * processors to set LAPIC timer correctly. |
1322 | */ | | 1322 | */ |
1323 | if (ci->ci_data.cpu_cc_freq == 0) | | 1323 | if (ci->ci_data.cpu_cc_freq == 0) |
1324 | freq = freq_from_cpuid = cpu_tsc_freq_cpuid(ci); | | 1324 | freq = freq_from_cpuid = cpu_tsc_freq_cpuid(ci); |
1325 | #if NHPET > 0 | | 1325 | #if NHPET > 0 |
1326 | if (freq == 0) | | 1326 | if (freq == 0) |
1327 | freq = hpet_tsc_freq(); | | 1327 | freq = hpet_tsc_freq(); |
1328 | #endif | | 1328 | #endif |