mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Cache cpuid.HostFeatureSet().
PiperOrigin-RevId: 394261815
This commit is contained in:
@@ -37,6 +37,14 @@ package cpuid
|
||||
// arch/arm64/include/uapi/asm/hwcap.h
|
||||
type Feature int
|
||||
|
||||
// HostFeatureSet returns a FeatureSet that matches that of the host machine.
|
||||
// Callers must not mutate the returned FeatureSet.
|
||||
func HostFeatureSet() *FeatureSet {
|
||||
return hostFeatureSet
|
||||
}
|
||||
|
||||
var hostFeatureSet = getHostFeatureSet()
|
||||
|
||||
// ErrIncompatible is returned by FeatureSet.HostCompatible if fs is not a
|
||||
// subset of the host feature set.
|
||||
type ErrIncompatible struct {
|
||||
|
||||
@@ -230,6 +230,16 @@ type FeatureSet struct {
|
||||
CPURevision uint8
|
||||
}
|
||||
|
||||
// Clone returns a copy of fs.
|
||||
func (fs *FeatureSet) Clone() *FeatureSet {
|
||||
fs2 := *fs
|
||||
fs2.Set = make(map[Feature]bool)
|
||||
for f, b := range fs.Set {
|
||||
fs2.Set[f] = b
|
||||
}
|
||||
return &fs2
|
||||
}
|
||||
|
||||
// CheckHostCompatible returns nil if fs is a subset of the host feature set.
|
||||
// Noop on arm64.
|
||||
func (fs *FeatureSet) CheckHostCompatible() error {
|
||||
@@ -292,9 +302,9 @@ func (fs FeatureSet) WriteCPUInfoTo(cpu uint, b *bytes.Buffer) {
|
||||
fmt.Fprintln(b, "") // The /proc/cpuinfo file ends with an extra newline.
|
||||
}
|
||||
|
||||
// HostFeatureSet uses hwCap to get host values and construct a feature set
|
||||
// getHostFeatureSet uses hwCap to get host values and construct a feature set
|
||||
// that matches that of the host machine.
|
||||
func HostFeatureSet() *FeatureSet {
|
||||
func getHostFeatureSet() *FeatureSet {
|
||||
s := make(map[Feature]bool)
|
||||
|
||||
for f := range arm64FeatureStrings {
|
||||
|
||||
+13
-2
@@ -627,6 +627,17 @@ type FeatureSet struct {
|
||||
CacheLine uint32
|
||||
}
|
||||
|
||||
// Clone returns a copy of fs.
|
||||
func (fs *FeatureSet) Clone() *FeatureSet {
|
||||
fs2 := *fs
|
||||
fs2.Set = make(map[Feature]bool)
|
||||
for f, b := range fs.Set {
|
||||
fs2.Set[f] = b
|
||||
}
|
||||
fs2.Caches = append([]Cache(nil), fs.Caches...)
|
||||
return &fs2
|
||||
}
|
||||
|
||||
// FlagsString prints out supported CPU flags. If cpuinfoOnly is true, it is
|
||||
// equivalent to the "flags" field in /proc/cpuinfo.
|
||||
func (fs *FeatureSet) FlagsString(cpuinfoOnly bool) string {
|
||||
@@ -961,13 +972,13 @@ func (fs *FeatureSet) UseXsaveopt() bool {
|
||||
// HostID executes a native CPUID instruction.
|
||||
func HostID(axArg, cxArg uint32) (ax, bx, cx, dx uint32)
|
||||
|
||||
// HostFeatureSet uses cpuid to get host values and construct a feature set
|
||||
// getHostFeatureSet uses cpuid to get host values and construct a feature set
|
||||
// that matches that of the host machine. Note that there are several places
|
||||
// where there appear to be some unnecessary assignments between register names
|
||||
// (ax, bx, cx, or dx) and featureBlockN variables. This is to explicitly show
|
||||
// where the different feature blocks come from, to make the code easier to
|
||||
// inspect and read.
|
||||
func HostFeatureSet() *FeatureSet {
|
||||
func getHostFeatureSet() *FeatureSet {
|
||||
// eax=0 gets max supported feature and vendor ID.
|
||||
_, bx, cx, dx := HostID(0, 0)
|
||||
vendorID := vendorIDFromRegs(bx, cx, dx)
|
||||
|
||||
Reference in New Issue
Block a user