Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Jun 2011 21:41:06 +0000 (UTC)
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r223211 - head/sys/x86/x86
Message-ID:  <201106172141.p5HLf6Rx009154@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jkim
Date: Fri Jun 17 21:41:06 2011
New Revision: 223211
URL: http://svn.freebsd.org/changeset/base/223211

Log:
  Teach the compiler how to shift TSC value efficiently.  As noted in r220631,
  some times compiler inserts redundant instructions to preserve unused upper
  32 bits even when it is casted to a 32-bit value.  Unfortunately, it seems
  the problem becomes more serious when it is shifted, especially on amd64.

Modified:
  head/sys/x86/x86/tsc.c

Modified: head/sys/x86/x86/tsc.c
==============================================================================
--- head/sys/x86/x86/tsc.c	Fri Jun 17 21:31:13 2011	(r223210)
+++ head/sys/x86/x86/tsc.c	Fri Jun 17 21:41:06 2011	(r223211)
@@ -461,7 +461,7 @@ init_TSC_tc(void)
 		tsc_timecounter.tc_quality = 1000;
 
 init:
-	for (shift = 0; shift < 32 && (tsc_freq >> shift) > max_freq; shift++)
+	for (shift = 0; shift < 31 && (tsc_freq >> shift) > max_freq; shift++)
 		;
 	if (shift > 0) {
 		tsc_timecounter.tc_get_timecount = tsc_get_timecount_low;
@@ -579,6 +579,9 @@ tsc_get_timecount(struct timecounter *tc
 static u_int
 tsc_get_timecount_low(struct timecounter *tc)
 {
+	uint32_t rv;
 
-	return (rdtsc() >> (int)(intptr_t)tc->tc_priv);
+	__asm __volatile("rdtsc; shrd %%cl, %%edx, %0"
+	: "=a" (rv) : "c" ((int)(intptr_t)tc->tc_priv) : "edx");
+	return (rv);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106172141.p5HLf6Rx009154>