From owner-svn-src-all@FreeBSD.ORG Tue Dec 14 20:07:51 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BC1BD106566C; Tue, 14 Dec 2010 20:07:51 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A97608FC08; Tue, 14 Dec 2010 20:07:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBEK7pSi029000; Tue, 14 Dec 2010 20:07:51 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBEK7pLd028994; Tue, 14 Dec 2010 20:07:51 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <201012142007.oBEK7pLd028994@svn.freebsd.org> From: Jung-uk Kim Date: Tue, 14 Dec 2010 20:07:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216443 - in head/sys: amd64/amd64 dev/acpica i386/i386 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Dec 2010 20:07:51 -0000 Author: jkim Date: Tue Dec 14 20:07:51 2010 New Revision: 216443 URL: http://svn.freebsd.org/changeset/base/216443 Log: Stop lying about supporting cpu_est_clockrate() when TSC is invariant. This function always returned the nominal frequency instead of current frequency because we use RDTSC instruction to calculate difference in CPU ticks, which is supposedly constant for the case. Now we support cpu_get_nominal_mhz() for the case, instead. Note it should be just enough for most usage cases because cpu_est_clockrate() is often times abused to find maximum frequency of the processor. Modified: head/sys/amd64/amd64/legacy.c head/sys/amd64/amd64/machdep.c head/sys/dev/acpica/acpi_cpu.c head/sys/i386/i386/legacy.c head/sys/i386/i386/machdep.c Modified: head/sys/amd64/amd64/legacy.c ============================================================================== --- head/sys/amd64/amd64/legacy.c Tue Dec 14 20:06:55 2010 (r216442) +++ head/sys/amd64/amd64/legacy.c Tue Dec 14 20:07:51 2010 (r216443) @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -313,9 +314,19 @@ cpu_read_ivar(device_t dev, device_t chi { struct cpu_device *cpdev; - if (index != CPU_IVAR_PCPU) + switch (index) { + case CPU_IVAR_PCPU: + cpdev = device_get_ivars(child); + *result = (uintptr_t)cpdev->cd_pcpu; + break; + case CPU_IVAR_NOMINAL_MHZ: + if (tsc_is_invariant) { + *result = (uintptr_t)(tsc_freq / 1000000); + break; + } + /* FALLTHROUGH */ + default: return (ENOENT); - cpdev = device_get_ivars(child); - *result = (uintptr_t)cpdev->cd_pcpu; + } return (0); } Modified: head/sys/amd64/amd64/machdep.c ============================================================================== --- head/sys/amd64/amd64/machdep.c Tue Dec 14 20:06:55 2010 (r216442) +++ head/sys/amd64/amd64/machdep.c Tue Dec 14 20:07:51 2010 (r216443) @@ -537,6 +537,10 @@ cpu_est_clockrate(int cpu_id, uint64_t * if (pcpu_find(cpu_id) == NULL || rate == NULL) return (EINVAL); + /* If TSC is P-state invariant, DELAY(9) based logic fails. */ + if (tsc_is_invariant) + return (EOPNOTSUPP); + /* If we're booting, trust the rate calibrated moments ago. */ if (cold) { *rate = tsc_freq; Modified: head/sys/dev/acpica/acpi_cpu.c ============================================================================== --- head/sys/dev/acpica/acpi_cpu.c Tue Dec 14 20:06:55 2010 (r216442) +++ head/sys/dev/acpica/acpi_cpu.c Tue Dec 14 20:07:51 2010 (r216443) @@ -44,6 +44,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#if defined(__amd64__) || defined(__i386__) +#include +#endif #include #include @@ -510,6 +513,14 @@ acpi_cpu_read_ivar(device_t dev, device_ case CPU_IVAR_PCPU: *result = (uintptr_t)sc->cpu_pcpu; break; +#if defined(__amd64__) || defined(__i386__) + case CPU_IVAR_NOMINAL_MHZ: + if (tsc_is_invariant) { + *result = (uintptr_t)(tsc_freq / 1000000); + break; + } + /* FALLTHROUGH */ +#endif default: return (ENOENT); } Modified: head/sys/i386/i386/legacy.c ============================================================================== --- head/sys/i386/i386/legacy.c Tue Dec 14 20:06:55 2010 (r216442) +++ head/sys/i386/i386/legacy.c Tue Dec 14 20:07:51 2010 (r216443) @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include #endif +#include #include #include @@ -334,9 +335,19 @@ cpu_read_ivar(device_t dev, device_t chi { struct cpu_device *cpdev; - if (index != CPU_IVAR_PCPU) + switch (index) { + case CPU_IVAR_PCPU: + cpdev = device_get_ivars(child); + *result = (uintptr_t)cpdev->cd_pcpu; + break; + case CPU_IVAR_NOMINAL_MHZ: + if (tsc_is_invariant) { + *result = (uintptr_t)(tsc_freq / 1000000); + break; + } + /* FALLTHROUGH */ + default: return (ENOENT); - cpdev = device_get_ivars(child); - *result = (uintptr_t)cpdev->cd_pcpu; + } return (0); } Modified: head/sys/i386/i386/machdep.c ============================================================================== --- head/sys/i386/i386/machdep.c Tue Dec 14 20:06:55 2010 (r216442) +++ head/sys/i386/i386/machdep.c Tue Dec 14 20:07:51 2010 (r216443) @@ -1131,6 +1131,10 @@ cpu_est_clockrate(int cpu_id, uint64_t * if (!tsc_present) return (EOPNOTSUPP); + /* If TSC is P-state invariant, DELAY(9) based logic fails. */ + if (tsc_is_invariant) + return (EOPNOTSUPP); + /* If we're booting, trust the rate calibrated moments ago. */ if (cold) { *rate = tsc_freq;