Deleted Added
full compact
cpu_machdep.c (241880) cpu_machdep.c (247454)
1/*-
2 * Copyright (c) 1992 Terrence R. Lambert.
3 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * William Jolitz.
8 *

--- 24 unchanged lines hidden (view full) ---

33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
38 */
39
40#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1992 Terrence R. Lambert.
3 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * William Jolitz.
8 *

--- 24 unchanged lines hidden (view full) ---

33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91
38 */
39
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/sys/i386/i386/machdep.c 241880 2012-10-22 11:57:26Z eadler $");
41__FBSDID("$FreeBSD: head/sys/i386/i386/machdep.c 247454 2013-02-28 10:46:54Z davide $");
42
43#include "opt_apic.h"
44#include "opt_atalk.h"
45#include "opt_atpic.h"
46#include "opt_compat.h"
47#include "opt_cpu.h"
48#include "opt_ddb.h"
49#include "opt_inet.h"

--- 1165 unchanged lines hidden (view full) ---

1215cpu_halt(void)
1216{
1217 HYPERVISOR_shutdown(SHUTDOWN_poweroff);
1218}
1219
1220int scheduler_running;
1221
1222static void
42
43#include "opt_apic.h"
44#include "opt_atalk.h"
45#include "opt_atpic.h"
46#include "opt_compat.h"
47#include "opt_cpu.h"
48#include "opt_ddb.h"
49#include "opt_inet.h"

--- 1165 unchanged lines hidden (view full) ---

1215cpu_halt(void)
1216{
1217 HYPERVISOR_shutdown(SHUTDOWN_poweroff);
1218}
1219
1220int scheduler_running;
1221
1222static void
1223cpu_idle_hlt(int busy)
1223cpu_idle_hlt(sbintime_t sbt)
1224{
1225
1226 scheduler_running = 1;
1227 enable_intr();
1228 idle_block();
1229}
1230
1231#else

--- 4 unchanged lines hidden (view full) ---

1236cpu_halt(void)
1237{
1238 for (;;)
1239 halt();
1240}
1241
1242#endif
1243
1224{
1225
1226 scheduler_running = 1;
1227 enable_intr();
1228 idle_block();
1229}
1230
1231#else

--- 4 unchanged lines hidden (view full) ---

1236cpu_halt(void)
1237{
1238 for (;;)
1239 halt();
1240}
1241
1242#endif
1243
1244void (*cpu_idle_hook)(void) = NULL; /* ACPI idle hook. */
1244void (*cpu_idle_hook)(sbintime_t) = NULL; /* ACPI idle hook. */
1245static int cpu_ident_amdc1e = 0; /* AMD C1E supported. */
1246static int idle_mwait = 1; /* Use MONITOR/MWAIT for short idle. */
1247TUNABLE_INT("machdep.idle_mwait", &idle_mwait);
1248SYSCTL_INT(_machdep, OID_AUTO, idle_mwait, CTLFLAG_RW, &idle_mwait,
1249 0, "Use MONITOR/MWAIT for short idle");
1250
1251#define STATE_RUNNING 0x0
1252#define STATE_MWAIT 0x1
1253#define STATE_SLEEPING 0x2
1254
1255static void
1245static int cpu_ident_amdc1e = 0; /* AMD C1E supported. */
1246static int idle_mwait = 1; /* Use MONITOR/MWAIT for short idle. */
1247TUNABLE_INT("machdep.idle_mwait", &idle_mwait);
1248SYSCTL_INT(_machdep, OID_AUTO, idle_mwait, CTLFLAG_RW, &idle_mwait,
1249 0, "Use MONITOR/MWAIT for short idle");
1250
1251#define STATE_RUNNING 0x0
1252#define STATE_MWAIT 0x1
1253#define STATE_SLEEPING 0x2
1254
1255static void
1256cpu_idle_acpi(int busy)
1256cpu_idle_acpi(sbintime_t sbt)
1257{
1258 int *state;
1259
1260 state = (int *)PCPU_PTR(monitorbuf);
1261 *state = STATE_SLEEPING;
1262
1263 /* See comments in cpu_idle_hlt(). */
1264 disable_intr();
1265 if (sched_runnable())
1266 enable_intr();
1267 else if (cpu_idle_hook)
1257{
1258 int *state;
1259
1260 state = (int *)PCPU_PTR(monitorbuf);
1261 *state = STATE_SLEEPING;
1262
1263 /* See comments in cpu_idle_hlt(). */
1264 disable_intr();
1265 if (sched_runnable())
1266 enable_intr();
1267 else if (cpu_idle_hook)
1268 cpu_idle_hook();
1268 cpu_idle_hook(sbt);
1269 else
1270 __asm __volatile("sti; hlt");
1271 *state = STATE_RUNNING;
1272}
1273
1274#ifndef XEN
1275static void
1269 else
1270 __asm __volatile("sti; hlt");
1271 *state = STATE_RUNNING;
1272}
1273
1274#ifndef XEN
1275static void
1276cpu_idle_hlt(int busy)
1276cpu_idle_hlt(sbintime_t sbt)
1277{
1278 int *state;
1279
1280 state = (int *)PCPU_PTR(monitorbuf);
1281 *state = STATE_SLEEPING;
1282
1283 /*
1284 * Since we may be in a critical section from cpu_idle(), if

--- 25 unchanged lines hidden (view full) ---

1310 */
1311#define MWAIT_C0 0xf0
1312#define MWAIT_C1 0x00
1313#define MWAIT_C2 0x10
1314#define MWAIT_C3 0x20
1315#define MWAIT_C4 0x30
1316
1317static void
1277{
1278 int *state;
1279
1280 state = (int *)PCPU_PTR(monitorbuf);
1281 *state = STATE_SLEEPING;
1282
1283 /*
1284 * Since we may be in a critical section from cpu_idle(), if

--- 25 unchanged lines hidden (view full) ---

1310 */
1311#define MWAIT_C0 0xf0
1312#define MWAIT_C1 0x00
1313#define MWAIT_C2 0x10
1314#define MWAIT_C3 0x20
1315#define MWAIT_C4 0x30
1316
1317static void
1318cpu_idle_mwait(int busy)
1318cpu_idle_mwait(sbintime_t sbt)
1319{
1320 int *state;
1321
1322 state = (int *)PCPU_PTR(monitorbuf);
1323 *state = STATE_MWAIT;
1324
1325 /* See comments in cpu_idle_hlt(). */
1326 disable_intr();

--- 6 unchanged lines hidden (view full) ---

1333 if (*state == STATE_MWAIT)
1334 __asm __volatile("sti; mwait" : : "a" (MWAIT_C1), "c" (0));
1335 else
1336 enable_intr();
1337 *state = STATE_RUNNING;
1338}
1339
1340static void
1319{
1320 int *state;
1321
1322 state = (int *)PCPU_PTR(monitorbuf);
1323 *state = STATE_MWAIT;
1324
1325 /* See comments in cpu_idle_hlt(). */
1326 disable_intr();

--- 6 unchanged lines hidden (view full) ---

1333 if (*state == STATE_MWAIT)
1334 __asm __volatile("sti; mwait" : : "a" (MWAIT_C1), "c" (0));
1335 else
1336 enable_intr();
1337 *state = STATE_RUNNING;
1338}
1339
1340static void
1341cpu_idle_spin(int busy)
1341cpu_idle_spin(sbintime_t sbt)
1342{
1343 int *state;
1344 int i;
1345
1346 state = (int *)PCPU_PTR(monitorbuf);
1347 *state = STATE_RUNNING;
1348
1349 /*

--- 33 unchanged lines hidden (view full) ---

1383 if (cpu_vendor_id == CPU_VENDOR_AMD &&
1384 (cpu_id & 0x00000f00) == 0x00000f00 &&
1385 (cpu_id & 0x0fff0000) >= 0x00040000) {
1386 cpu_ident_amdc1e = 1;
1387 }
1388}
1389
1390#ifdef XEN
1342{
1343 int *state;
1344 int i;
1345
1346 state = (int *)PCPU_PTR(monitorbuf);
1347 *state = STATE_RUNNING;
1348
1349 /*

--- 33 unchanged lines hidden (view full) ---

1383 if (cpu_vendor_id == CPU_VENDOR_AMD &&
1384 (cpu_id & 0x00000f00) == 0x00000f00 &&
1385 (cpu_id & 0x0fff0000) >= 0x00040000) {
1386 cpu_ident_amdc1e = 1;
1387 }
1388}
1389
1390#ifdef XEN
1391void (*cpu_idle_fn)(int) = cpu_idle_hlt;
1391void (*cpu_idle_fn)(sbintime_t) = cpu_idle_hlt;
1392#else
1392#else
1393void (*cpu_idle_fn)(int) = cpu_idle_acpi;
1393void (*cpu_idle_fn)(sbintime_t) = cpu_idle_acpi;
1394#endif
1395
1396void
1397cpu_idle(int busy)
1398{
1399#ifndef XEN
1400 uint64_t msr;
1401#endif
1394#endif
1395
1396void
1397cpu_idle(int busy)
1398{
1399#ifndef XEN
1400 uint64_t msr;
1401#endif
1402 sbintime_t sbt = -1;
1402
1403 CTR2(KTR_SPARE2, "cpu_idle(%d) at %d",
1404 busy, curcpu);
1405#if defined(MP_WATCHDOG) && !defined(XEN)
1406 ap_watchdog(PCPU_GET(cpuid));
1407#endif
1408#ifndef XEN
1409 /* If we are busy - try to use fast methods. */
1410 if (busy) {
1411 if ((cpu_feature2 & CPUID2_MON) && idle_mwait) {
1412 cpu_idle_mwait(busy);
1413 goto out;
1414 }
1415 }
1416#endif
1417
1418 /* If we have time - switch timers into idle mode. */
1419 if (!busy) {
1420 critical_enter();
1403
1404 CTR2(KTR_SPARE2, "cpu_idle(%d) at %d",
1405 busy, curcpu);
1406#if defined(MP_WATCHDOG) && !defined(XEN)
1407 ap_watchdog(PCPU_GET(cpuid));
1408#endif
1409#ifndef XEN
1410 /* If we are busy - try to use fast methods. */
1411 if (busy) {
1412 if ((cpu_feature2 & CPUID2_MON) && idle_mwait) {
1413 cpu_idle_mwait(busy);
1414 goto out;
1415 }
1416 }
1417#endif
1418
1419 /* If we have time - switch timers into idle mode. */
1420 if (!busy) {
1421 critical_enter();
1421 cpu_idleclock();
1422 sbt = cpu_idleclock();
1422 }
1423
1424#ifndef XEN
1425 /* Apply AMD APIC timer C1E workaround. */
1426 if (cpu_ident_amdc1e && cpu_disable_deep_sleep) {
1427 msr = rdmsr(MSR_AMDK8_IPM);
1428 if (msr & AMDK8_CMPHALT)
1429 wrmsr(MSR_AMDK8_IPM, msr & ~AMDK8_CMPHALT);
1430 }
1431#endif
1432
1433 /* Call main idle method. */
1423 }
1424
1425#ifndef XEN
1426 /* Apply AMD APIC timer C1E workaround. */
1427 if (cpu_ident_amdc1e && cpu_disable_deep_sleep) {
1428 msr = rdmsr(MSR_AMDK8_IPM);
1429 if (msr & AMDK8_CMPHALT)
1430 wrmsr(MSR_AMDK8_IPM, msr & ~AMDK8_CMPHALT);
1431 }
1432#endif
1433
1434 /* Call main idle method. */
1434 cpu_idle_fn(busy);
1435 cpu_idle_fn(sbt);
1435
1436 /* Switch timers mack into active mode. */
1437 if (!busy) {
1438 cpu_activeclock();
1439 critical_exit();
1440 }
1441#ifndef XEN
1442out:

--- 2298 unchanged lines hidden ---
1436
1437 /* Switch timers mack into active mode. */
1438 if (!busy) {
1439 cpu_activeclock();
1440 critical_exit();
1441 }
1442#ifndef XEN
1443out:

--- 2298 unchanged lines hidden ---