From c16c06fc9e24d660ee2a0d854fb120acffd02916 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Mon, 8 Oct 2012 09:01:22 +0000 Subject: reduce the difference between i386 and amd64 versions of the speedstep code --- sys/arch/amd64/amd64/est.c | 24 ++++++++++-------------- sys/arch/i386/i386/est.c | 34 +++++++++++++++------------------- 2 files changed, 25 insertions(+), 33 deletions(-) (limited to 'sys') diff --git a/sys/arch/amd64/amd64/est.c b/sys/arch/amd64/amd64/est.c index f000cb98d96..58e0f718d20 100644 --- a/sys/arch/amd64/amd64/est.c +++ b/sys/arch/amd64/amd64/est.c @@ -1,4 +1,4 @@ -/* $OpenBSD: est.c,v 1.28 2012/03/27 07:04:33 jsg Exp $ */ +/* $OpenBSD: est.c,v 1.29 2012/10/08 09:01:21 jsg Exp $ */ /* * Copyright (c) 2003 Michael Eriksson. * All rights reserved. @@ -71,10 +71,6 @@ #include #endif -/* Convert MHz and mV into IDs for passing to the MSR. */ -#define ID16(MHz, mV, bus_clk) \ - ((((MHz * 100 + 50) / bus_clk) << 8) | ((mV ? mV - 700 : 0) >> 4)) - /* Possible bus speeds (multiplied by 100 for rounding) */ #define BUS100 10000 #define BUS133 13333 @@ -293,15 +289,15 @@ est_acpi_pss_changed(struct acpicpu_pss *pss, int npss) if ((acpilist = malloc(sizeof(struct fqlist), M_DEVBUF, M_NOWAIT)) == NULL) { - printf("est_acpi_pss_changed: cannot allocate memory for new" - " est state"); + printf("est_acpi_pss_changed: cannot allocate memory for new " + "est state"); return; } if ((acpilist->table = malloc(sizeof(struct est_op) * npss, M_DEVBUF, M_NOWAIT)) == NULL) { - printf("est_acpi_pss_changed: cannot allocate memory for new" - " operating points"); + printf("est_acpi_pss_changed: cannot allocate memory for new " + "operating points"); free(acpilist, M_DEVBUF); return; } @@ -394,8 +390,8 @@ est_init(struct cpu_info *ci) if ((fake_fqlist = malloc(sizeof(struct fqlist), M_DEVBUF, M_NOWAIT)) == NULL) { - printf("%s: cannot allocate memory for fake list", - cpu_device); + printf("%s: EST: cannot allocate memory for fake " + "list\n", cpu_device); return; } @@ -403,8 +399,8 @@ est_init(struct cpu_info *ci) if ((fake_table = malloc(sizeof(struct est_op) * 3, M_DEVBUF, M_NOWAIT)) == NULL) { free(fake_fqlist, M_DEVBUF); - printf("%s: cannot allocate memory for fake table", - cpu_device); + printf("%s: EST: cannot allocate memory for fake " + "table\n", cpu_device); return; } fake_table[0].ctrl = idhi; @@ -451,7 +447,7 @@ est_init(struct cpu_info *ci) printf(": speeds: "); for (i = 0; i < est_fqlist->n; i++) printf("%d%s", est_fqlist->table[i].mhz, i < est_fqlist->n - 1 - ? ", " : " MHz\n"); + ? ", " : " MHz\n"); cpu_setperf = est_setperf; setperf_prio = 3; diff --git a/sys/arch/i386/i386/est.c b/sys/arch/i386/i386/est.c index ac25b554cdd..5f3a72369bc 100644 --- a/sys/arch/i386/i386/est.c +++ b/sys/arch/i386/i386/est.c @@ -1,4 +1,4 @@ -/* $OpenBSD: est.c,v 1.39 2012/03/27 07:04:33 jsg Exp $ */ +/* $OpenBSD: est.c,v 1.40 2012/10/08 09:01:21 jsg Exp $ */ /* * Copyright (c) 2003 Michael Eriksson. * All rights reserved. @@ -982,7 +982,7 @@ est_acpi_init() == NULL) goto nolist; - if ((acpilist->table = malloc(sizeof( struct est_op) * nstates, + if ((acpilist->table = malloc(sizeof(struct est_op) * nstates, M_DEVBUF, M_NOWAIT)) == NULL) goto notable; @@ -1022,7 +1022,7 @@ est_acpi_pss_changed(struct acpicpu_pss *pss, int npss) return; } - if ((acpilist->table = malloc(sizeof( struct est_op) * npss, + if ((acpilist->table = malloc(sizeof(struct est_op) * npss, M_DEVBUF, M_NOWAIT)) == NULL) { printf("est_acpi_pss_changed: cannot allocate memory for new " "operating points"); @@ -1062,17 +1062,6 @@ est_init(struct cpu_info *ci, int vendor) if (setperf_prio > 3) return; - if ((cpu_ecxfeature & CPUIDECX_EST) == 0) - return; - - msr = rdmsr(MSR_PERF_STATUS); - idhi = (msr >> 32) & 0xffff; - idlo = (msr >> 48) & 0xffff; - cur = msr & 0xffff; - crhi = (idhi >> 8) & 0xff; - crlo = (idlo >> 8) & 0xff; - crcur = (cur >> 8) & 0xff; - #if NACPICPU > 0 est_fqlist = est_acpi_init(); #endif @@ -1092,6 +1081,13 @@ est_init(struct cpu_info *ci, int vendor) * on recent processors so don't do it on anything unknown */ if (est_fqlist == NULL && bus_clock != 0) { + msr = rdmsr(MSR_PERF_STATUS); + idhi = (msr >> 32) & 0xffff; + idlo = (msr >> 48) & 0xffff; + cur = msr & 0xffff; + crhi = (idhi >> 8) & 0xff; + crlo = (idlo >> 8) & 0xff; + crcur = (cur >> 8) & 0xff; /* * Find an entry which matches (vendor, bus_clock, idhi, idlo) */ @@ -1118,12 +1114,12 @@ est_init(struct cpu_info *ci, int vendor) cpu_device, msr); return; } - if (crlo == 0 || crhi == crlo) { + if (crlo == 0 || crhi == crlo) { /* * Don't complain about these cases, and silently - * disable EST: - A lowest clock ratio of 0, which + * disable EST: - A lowest clock ratio of 0, which * seems to happen on all Pentium 4's that report EST. - * - And equal highest and lowest clock ratio, which + * - An equal highest and lowest clock ratio, which * happens on at least the Core 2 Duo X6800, maybe on * newer models too. */ @@ -1138,8 +1134,8 @@ est_init(struct cpu_info *ci, int vendor) if ((fake_fqlist = malloc(sizeof(struct fqlist), M_DEVBUF, M_NOWAIT)) == NULL) { - printf("%s: EST: cannot allocate memory for fake list", - cpu_device); + printf("%s: EST: cannot allocate memory for fake " + "list\n", cpu_device); return; } -- cgit v1.2.3