Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Mar 2019 16:43:28 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r345190 - in head/sys: amd64/amd64 i386/i386
Message-ID:  <201903151643.x2FGhSKT037956@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Fri Mar 15 16:43:28 2019
New Revision: 345190
URL: https://svnweb.freebsd.org/changeset/base/345190

Log:
  Provide deterministic (and somewhat useful) value for RDPID result,
  and for %ecx after RDTSCP.
  
  Initialize TSC_AUX MSR with CPUID.  It allows for userspace to cheaply
  identify CPU it was executed on some time ago, which is sometimes useful.
  
  Note: The values returned might be changed in future.
  
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week

Modified:
  head/sys/amd64/amd64/initcpu.c
  head/sys/i386/i386/initcpu.c

Modified: head/sys/amd64/amd64/initcpu.c
==============================================================================
--- head/sys/amd64/amd64/initcpu.c	Fri Mar 15 16:39:05 2019	(r345189)
+++ head/sys/amd64/amd64/initcpu.c	Fri Mar 15 16:43:28 2019	(r345190)
@@ -265,6 +265,10 @@ initializecpu(void)
 		init_via();
 		break;
 	}
+
+	if ((amd_feature & AMDID_RDTSCP) != 0 ||
+	    (cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0)
+		wrmsr(MSR_TSC_AUX, PCPU_GET(cpuid));
 }
 
 void

Modified: head/sys/i386/i386/initcpu.c
==============================================================================
--- head/sys/i386/i386/initcpu.c	Fri Mar 15 16:39:05 2019	(r345189)
+++ head/sys/i386/i386/initcpu.c	Fri Mar 15 16:43:28 2019	(r345190)
@@ -749,6 +749,9 @@ initializecpu(void)
 		msr = rdmsr(MSR_EFER) | EFER_NXE;
 		wrmsr(MSR_EFER, msr);
 	}
+	if ((amd_feature & AMDID_RDTSCP) != 0 ||
+	    (cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0)
+		wrmsr(MSR_TSC_AUX, PCPU_GET(cpuid));
 }
 
 void



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