diff --git a/cpuid.go b/cpuid.go index 4921bcd..1db2bad 100644 --- a/cpuid.go +++ b/cpuid.go @@ -34,6 +34,8 @@ const ( XenHVM Bhyve Hygon + SiS + RDC ) const ( @@ -177,6 +179,7 @@ var flagNames = map[Flags]string{ type CPUInfo struct { BrandName string // Brand name reported by the CPU VendorID Vendor // Comparable CPU vendor ID + VendorString string // Raw vendor string. Features Flags // Features of the CPU PhysicalCores int // Number of physical processor cores in your CPU. Will be 0 if undetectable. ThreadsPerCore int // Number of threads per physical core. Will be 1 if undetectable. @@ -231,7 +234,7 @@ func Detect() { CPU.ThreadsPerCore = threadsPerCore() CPU.LogicalCores = logicalCores() CPU.PhysicalCores = physicalCores() - CPU.VendorID = vendorID() + CPU.VendorID, CPU.VendorString = vendorID() CPU.Hz = hertz(CPU.BrandName) CPU.cacheSize() } @@ -726,12 +729,14 @@ func brandName() string { func threadsPerCore() int { mfi := maxFunctionID() - if mfi < 0x4 || (vendorID() != Intel && vendorID() != AMD) { + vend, _ := vendorID() + + if mfi < 0x4 || (vend != Intel && vend != AMD) { return 1 } if mfi < 0xb { - if vendorID() != Intel { + if vend != Intel { return 1 } _, b, _, d := cpuid(1) @@ -758,7 +763,8 @@ func threadsPerCore() int { func logicalCores() int { mfi := maxFunctionID() - switch vendorID() { + v, _ := vendorID() + switch v { case Intel: // Use this on old Intel processors if mfi < 0xb { @@ -793,7 +799,8 @@ func familyModel() (int, int) { } func physicalCores() int { - switch vendorID() { + v, _ := vendorID() + switch v { case Intel: return logicalCores() / threadsPerCore() case AMD, Hygon: @@ -828,16 +835,20 @@ var vendorMapping = map[string]Vendor{ "XenVMMXenVMM": XenHVM, "bhyve bhyve ": Bhyve, "HygonGenuine": Hygon, + "Vortex86 SoC": SiS, + "SiS SiS SiS ": SiS, + "RiseRiseRise": SiS, + "Genuine RDC": RDC, } -func vendorID() Vendor { +func vendorID() (Vendor, string) { _, b, c, d := cpuid(0) - v := valAsString(b, d, c) - vend, ok := vendorMapping[string(v)] + v := string(valAsString(b, d, c)) + vend, ok := vendorMapping[v] if !ok { - return Other + return Other, v } - return vend + return vend, v } func cacheLine() int { @@ -860,7 +871,7 @@ func (c *CPUInfo) cacheSize() { c.Cache.L1I = -1 c.Cache.L2 = -1 c.Cache.L3 = -1 - vendor := vendorID() + vendor, _ := vendorID() switch vendor { case Intel: if maxFunctionID() < 4 { @@ -1015,7 +1026,7 @@ func hasSGX(available, lc bool) (rval SGXSupport) { func support() Flags { mfi := maxFunctionID() - vend := vendorID() + vend, _ := vendorID() if mfi < 0x1 { return 0 } @@ -1243,7 +1254,7 @@ func support() Flags { AV_CPU_FLAG_SSE2 and AV_CPU_FLAG_SSE2SLOW are both set in this case so that SSE2 is used unless explicitly disabled by checking AV_CPU_FLAG_SSE2SLOW. */ - if vendorID() != Intel && + if vend != Intel && rval&SSE2 != 0 && (c&0x00000040) == 0 { rval |= SSE2SLOW } @@ -1259,7 +1270,7 @@ func support() Flags { } } - if vendorID() == Intel { + if vend == Intel { family, model := familyModel() if family == 6 && (model == 9 || model == 13 || model == 14) { /* 6/9 (pentium-m "banias"), 6/13 (pentium-m "dothan"), and diff --git a/cpuid_test.go b/cpuid_test.go index dd6db45..a2f39f5 100644 --- a/cpuid_test.go +++ b/cpuid_test.go @@ -11,9 +11,11 @@ import ( // obviously differ on each machine. func TestCPUID(t *testing.T) { n := maxFunctionID() - t.Logf("Max Function:0x%x\n", n) + t.Logf("Max Function:0x%x", n) n = maxExtendedFunction() - t.Logf("Max Extended Function:0x%x\n", n) + t.Logf("Max Extended Function:0x%x", n) + t.Log("VendorString:", CPU.VendorString) + t.Log("VendorID:", CPU.VendorID) t.Log("Name:", CPU.BrandName) t.Log("PhysicalCores:", CPU.PhysicalCores) t.Log("ThreadsPerCore:", CPU.ThreadsPerCore) diff --git a/mockcpu_test.go b/mockcpu_test.go index 605cb57..8bbc5c7 100644 --- a/mockcpu_test.go +++ b/mockcpu_test.go @@ -176,9 +176,11 @@ func TestMocks(t *testing.T) { Detect() t.Log("Name:", CPU.BrandName) n := maxFunctionID() - t.Logf("Max Function:0x%x\n", n) + t.Logf("Max Function:0x%x", n) n = maxExtendedFunction() - t.Logf("Max Extended Function:0x%x\n", n) + t.Logf("Max Extended Function:0x%x", n) + t.Log("VendorString:", CPU.VendorString) + t.Log("VendorID:", CPU.VendorID) t.Log("PhysicalCores:", CPU.PhysicalCores) t.Log("ThreadsPerCore:", CPU.ThreadsPerCore) t.Log("LogicalCores:", CPU.LogicalCores) diff --git a/private/cpuid.go b/private/cpuid.go index d60ac61..12e43f3 100644 --- a/private/cpuid.go +++ b/private/cpuid.go @@ -28,6 +28,8 @@ const ( xenhvm bhyve hygon + sis + rdc ) const ( @@ -171,6 +173,7 @@ var flagNames = map[flags]string{ type cpuInfo struct { brandname string // Brand name reported by the CPU vendorid vendor // Comparable CPU vendor ID + vendorstring string // Raw vendor string. features flags // Features of the CPU physicalcores int // Number of physical processor cores in your CPU. Will be 0 if undetectable. threadspercore int // Number of threads per physical core. Will be 1 if undetectable. @@ -225,7 +228,7 @@ func detect() { cpu.threadspercore = threadsPerCore() cpu.logicalcores = logicalCores() cpu.physicalcores = physicalCores() - cpu.vendorid = vendorID() + cpu.vendorid, cpu.vendorstring = vendorID() cpu.hz = hertz(cpu.brandname) cpu.cacheSize() } @@ -720,12 +723,14 @@ func brandName() string { func threadsPerCore() int { mfi := maxFunctionID() - if mfi < 0x4 || (vendorID() != intel && vendorID() != amd) { + vend, _ := vendorID() + + if mfi < 0x4 || (vend != intel && vend != amd) { return 1 } if mfi < 0xb { - if vendorID() != intel { + if vend != intel { return 1 } _, b, _, d := cpuid(1) @@ -752,7 +757,8 @@ func threadsPerCore() int { func logicalCores() int { mfi := maxFunctionID() - switch vendorID() { + v, _ := vendorID() + switch v { case intel: // Use this on old Intel processors if mfi < 0xb { @@ -787,7 +793,8 @@ func familyModel() (int, int) { } func physicalCores() int { - switch vendorID() { + v, _ := vendorID() + switch v { case intel: return logicalCores() / threadsPerCore() case amd, hygon: @@ -822,16 +829,20 @@ var vendorMapping = map[string]vendor{ "XenVMMXenVMM": xenhvm, "bhyve bhyve ": bhyve, "HygonGenuine": hygon, + "Vortex86 SoC": sis, + "SiS SiS SiS ": sis, + "RiseRiseRise": sis, + "Genuine RDC": rdc, } -func vendorID() vendor { +func vendorID() (vendor, string) { _, b, c, d := cpuid(0) - v := valAsString(b, d, c) - vend, ok := vendorMapping[string(v)] + v := string(valAsString(b, d, c)) + vend, ok := vendorMapping[v] if !ok { - return other + return other, v } - return vend + return vend, v } func cacheLine() int { @@ -854,7 +865,7 @@ func (c *cpuInfo) cacheSize() { c.cache.l1i = -1 c.cache.l2 = -1 c.cache.l3 = -1 - vendor := vendorID() + vendor, _ := vendorID() switch vendor { case intel: if maxFunctionID() < 4 { @@ -1009,7 +1020,7 @@ func hasSGX(available, lc bool) (rval sgxsupport) { func support() flags { mfi := maxFunctionID() - vend := vendorID() + vend, _ := vendorID() if mfi < 0x1 { return 0 } @@ -1237,7 +1248,7 @@ func support() flags { AV_CPU_FLAG_SSE2 and AV_CPU_FLAG_SSE2SLOW are both set in this case so that SSE2 is used unless explicitly disabled by checking AV_CPU_FLAG_SSE2SLOW. */ - if vendorID() != intel && + if vend != intel && rval&sse2 != 0 && (c&0x00000040) == 0 { rval |= sse2slow } @@ -1253,7 +1264,7 @@ func support() flags { } } - if vendorID() == intel { + if vend == intel { family, model := familyModel() if family == 6 && (model == 9 || model == 13 || model == 14) { /* 6/9 (pentium-m "banias"), 6/13 (pentium-m "dothan"), and diff --git a/private/cpuid_test.go b/private/cpuid_test.go index 5351317..e681eaf 100644 --- a/private/cpuid_test.go +++ b/private/cpuid_test.go @@ -13,9 +13,11 @@ import ( // obviously differ on each machine. func TestCPUID(t *testing.T) { n := maxFunctionID() - t.Logf("Max Function:0x%x\n", n) + t.Logf("Max Function:0x%x", n) n = maxExtendedFunction() - t.Logf("Max Extended Function:0x%x\n", n) + t.Logf("Max Extended Function:0x%x", n) + t.Log("VendorString:", cpu.vendorstring) + t.Log("VendorID:", cpu.vendorid) t.Log("Name:", cpu.brandname) t.Log("PhysicalCores:", cpu.physicalcores) t.Log("ThreadsPerCore:", cpu.threadspercore)