mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
cpuid: cache host cpuid features
HostFeatureSet() returns a fixed set that is initialized at startup. Here results fro the signal_benchmark on the kvm platform: Before: BM_FaultSignalFixup/real_time 8353 ns 8383 ns 94234 After: BM_FaultSignalFixup/real_time 6127 ns 6087 ns 111708 PiperOrigin-RevId: 462012597
This commit is contained in:
@@ -162,13 +162,13 @@ func (fs FeatureSet) query(fn cpuidFunction) (uint32, uint32, uint32, uint32) {
|
||||
return out.Eax, out.Ebx, out.Ecx, out.Edx
|
||||
}
|
||||
|
||||
var hostFeatureSet FeatureSet
|
||||
|
||||
// HostFeatureSet returns a host CPUID.
|
||||
//
|
||||
//go:nosplit
|
||||
func HostFeatureSet() FeatureSet {
|
||||
return FeatureSet{
|
||||
Function: &Native{},
|
||||
}
|
||||
return hostFeatureSet
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -179,7 +179,7 @@ var (
|
||||
// Reads max cpu frequency from host /proc/cpuinfo. Must run before syscall
|
||||
// filter installation. This value is used to create the fake /proc/cpuinfo
|
||||
// from a FeatureSet.
|
||||
func init() {
|
||||
func readMaxCPUFreq() {
|
||||
cpuinfob, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
// Leave it as 0... the VDSO bails out in the same way.
|
||||
@@ -212,4 +212,13 @@ func init() {
|
||||
}
|
||||
}
|
||||
log.Warningf("Could not parse /proc/cpuinfo, it is empty or does not contain cpu MHz")
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
hostFeatureSet = FeatureSet{
|
||||
Function: &Native{},
|
||||
}.Fixed()
|
||||
|
||||
readMaxCPUFreq()
|
||||
}
|
||||
|
||||
@@ -99,7 +99,9 @@ func nestedVirtIsOn(c *vCPU, fs *cpuid.FeatureSet) bool {
|
||||
|
||||
func TestKernelCPUID(t *testing.T) {
|
||||
bluepillTest(t, func(c *vCPU) {
|
||||
fs := cpuid.HostFeatureSet()
|
||||
fs := cpuid.FeatureSet{
|
||||
Function: &cpuid.Native{},
|
||||
}
|
||||
if nestedVirtIsOn(c, &fs) {
|
||||
t.Fatalf("Nested virtualization is enabled")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user