cpuhelper

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arch

func Arch(cpu CPU) archconst.ArchValue

Arch returns runtime cpu arch value as defined in package arhat.dev/pkg/archconst

func ArchByCPUFeatures

func ArchByCPUFeatures(data CPU) archconst.ArchValue

ArchByCPUFeatures detects runtime cpu arch (value defined in package arhat.dev/pkg/archconst) by inspecting cpu features

return value MAY be empty string if detection failed or unable to determine specific arch value supported archs are: - amd64v{1,2,3,4} - arm64 - armv{6, 7} (linux only) - s390x - ppc64{, le}v{8, 9} - mips64{, le}

func Bits

func Bits() int

Bits returns number of bits in a int for current platform

func LittleEndian

func LittleEndian() bool

LittleEndian returns true when program is running on a little-endian cpu

Types

type CPU added in v0.10.0

type CPU interface{}

func Detect added in v0.10.0

func Detect() CPU

Detect cpu details

type CPUFeatures added in v0.10.0

type CPUFeatures interface{}

type Vendor added in v0.10.0

type Vendor uint32
const (
	Vendor_Unknown Vendor = iota

	// x86 vendor
	Vendor_AMD
	Vendor_VIA
	Vendor_Intel
	Vendor_Transmeta
	Vendor_NSC // National Semiconductor
	Vendor_NexGen
	Vendor_Cyrix
	Vendor_Rise
	Vendor_SiS
	Vendor_DMP
	Vendor_UMC
	Vendor_Hygon
	Vendor_RDC
	Vendor_MCST

	// arm vendor
	Vendor_Ampere
	Vendor_ARM
	Vendor_Broadcom
	Vendor_Cavium
	Vendor_DEC
	Vendor_Fujitsu
	Vendor_Infineon
	Vendor_Motorola
	Vendor_NVIDIA
	Vendor_AMCC
	Vendor_Qualcomm
	Vendor_Marvell
	Vendor_Apple

	// hypervisor
	Vendor_KVM
	Vendor_MSVM
	Vendor_VMware
	Vendor_XenHVM
	Vendor_Bhyve
	Vendor_QEMU
	Vendor_Parallels
	Vendor_QNXVM
	Vendor_ACRN
	Vendor_AppleRosetta2
)

func HypervisorVendor added in v0.10.0

func HypervisorVendor(brand string) Vendor

func (Vendor) String added in v0.10.0

func (vnd Vendor) String() string

type X86 added in v0.10.0

type X86 struct {
	Brand       string
	BrandDetail string

	Stepping    X86Stepping
	Model       X86Model
	Family      X86Family
	ProcessType X86ProcessType

	BrandIndex      uint8
	CacheLineSize   uint16
	MaxLogicalCPUID uint8
	InitialAPICID   uint8

	Features          X86Feature
	ExtendedFeatures1 X86FeatureExtendedBC
	ExtendedFeatures2 X86FeatureExtendedDA
	ExtraFeatures     X86FeatureExtra

	ThermalPowerFeatures             X86ThermalPowerFeature
	ThermalSensorInterruptThresholds int8

	CacheDescriptors []X86CacheDescriptor
}

func (*X86) AllFeatures added in v0.10.0

func (cpu *X86) AllFeatures() (ret []string)

func (*X86) MicroArch added in v0.10.0

func (cpu *X86) MicroArch() (ret int)

MicroArch level (for x86-64) ref: https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels

func (*X86) String added in v0.10.0

func (cpu *X86) String() string

func (*X86) Vendor added in v0.10.0

func (cpu *X86) Vendor() Vendor

Vendor returns predefined Vendor value according to brand name

type X86CacheDescriptor added in v0.10.0

type X86CacheDescriptor struct {
	Level      int8         // Cache level
	CacheType  X86CacheType // Cache type
	CacheName  string       // Name
	CacheSize  int          // in KBytes (of page size for TLB)
	Ways       int16        // Associativity, 0 undefined, 0xFF fully associate
	LineSize   int16        // Cache line size in bytes
	Entries    int32        // number of entries for TLB
	Partioning uint16       // partitioning
}

type X86CacheType added in v0.10.0

type X86CacheType uint8
const (
	X86CacheType_NULL X86CacheType = iota
	X86CacheType_DATA_CACHE
	X86CacheType_INSTRUCTION_CACHE
	X86CacheType_UNIFIED_CACHE
	X86CacheType_TLB
	X86CacheType_DTLB
	X86CacheType_STLB
	X86CacheType_PREFETCH
)

type X86Family added in v0.10.0

type X86Family uint16

type X86Feature added in v0.10.0

type X86Feature uint64
const (
	// leaf1 ecx
	X86Feature_SSE3 X86Feature = 1 << iota
	X86Feature_PCLMULQDQ
	X86Feature_DTES64
	X86Feature_MONITOR
	X86Feature_DSI_CPL
	X86Feature_VMX
	X86Feature_SMX
	X86Feature_EST
	X86Feature_TM2
	X86Feature_SSSE3
	X86Feature_CNXT_ID
	X86Feature_SDBG
	X86Feature_FMA
	X86Feature_CX16
	X86Feature_XTPR
	X86Feature_PDCM

	X86Feature_PCID
	X86Feature_DCA
	X86Feature_SSE4_1
	X86Feature_SSE4_2
	X86Feature_X2APIC
	X86Feature_MOVBE
	X86Feature_POPCNT
	X86Feature_TSC_DEADLINE
	X86Feature_AES
	X86Feature_XSAVE
	X86Feature_OSXSAVE
	X86Feature_AVX
	X86Feature_F16C
	X86Feature_RDRND
	X86Feature_HYPERVISOR

	// leaf1 edx
	X86Feature_FPU
	X86Feature_VME
	X86Feature_DE
	X86Feature_PSE
	X86Feature_TSC
	X86Feature_MSR
	X86Feature_PAE
	X86Feature_MCE
	X86Feature_CX8
	X86Feature_APIC

	X86Feature_SEP // sysenter/sysexit
	X86Feature_MTRR
	X86Feature_PGE
	X86Feature_MCA
	X86Feature_CMOV
	X86Feature_PAT
	X86Feature_PSE_36
	X86Feature_PSN
	X86Feature_CLFSH

	X86Feature_DS
	X86Feature_ACPI
	X86Feature_MMX
	X86Feature_FXSR
	X86Feature_SSE
	X86Feature_SSE2
	X86Feature_SS
	X86Feature_HTT
	X86Feature_TM
	X86Feature_IA64
	X86Feature_PBE
)

func (X86Feature) Features added in v0.10.0

func (feat X86Feature) Features() (ret []string)

func (X86Feature) HasAll added in v0.10.0

func (feat X86Feature) HasAll(features ...X86Feature) bool

func (X86Feature) String added in v0.10.0

func (feat X86Feature) String() string

type X86FeatureExtendedBC added in v0.10.0

type X86FeatureExtendedBC uint64

X86FeatureExtendedBC (leaf7.0 ebx, ecx)

const (
	// leaf7.0 ebx
	X86FeatureExtendedBC_FSGSBASE X86FeatureExtendedBC = 1 << iota
	X86FeatureExtendedBC_IA32_TSC_ADJUST

	X86FeatureExtendedBC_BMI1
	X86FeatureExtendedBC_HLE
	X86FeatureExtendedBC_AVX2

	X86FeatureExtendedBC_SMEP
	X86FeatureExtendedBC_BMI2
	X86FeatureExtendedBC_ERMS
	X86FeatureExtendedBC_INVPCID
	X86FeatureExtendedBC_RTM
	X86FeatureExtendedBC_PQM
	X86FeatureExtendedBC_DFPUCDS
	X86FeatureExtendedBC_MPX
	X86FeatureExtendedBC_PQE
	X86FeatureExtendedBC_AVX512_F
	X86FeatureExtendedBC_AVX512_DQ
	X86FeatureExtendedBC_RDSEED
	X86FeatureExtendedBC_ADX
	X86FeatureExtendedBC_SMAP
	X86FeatureExtendedBC_AVX512_IFMA
	X86FeatureExtendedBC_PCOMMIT
	X86FeatureExtendedBC_CLFLUSHOPT
	X86FeatureExtendedBC_CLWB
	X86FeatureExtendedBC_INTEL_PT // Intel Processor Trace
	X86FeatureExtendedBC_AVX512_PF
	X86FeatureExtendedBC_AVX512_ER
	X86FeatureExtendedBC_AVX512_CD
	X86FeatureExtendedBC_SHA
	X86FeatureExtendedBC_AVX512_BW
	X86FeatureExtendedBC_AVX512_VL

	// leaf7.0 ecx
	X86FeatureExtendedBC_PREFETCHWT1
	X86FeatureExtendedBC_AVX512_VBMI
	X86FeatureExtendedBC_UMIP
	X86FeatureExtendedBC_PKU
	X86FeatureExtendedBC_OSPKE
	X86FeatureExtendedBC_WAITPKG
	X86FeatureExtendedBC_AVX512_VBMI2
	X86FeatureExtendedBC_CETSS
	X86FeatureExtendedBC_GFNI
	X86FeatureExtendedBC_VAES
	X86FeatureExtendedBC_VPCLMULQDQ
	X86FeatureExtendedBC_AVX512_VNNI
	X86FeatureExtendedBC_AVX512_BITALG
	X86FeatureExtendedBC_TME_EN
	X86FeatureExtendedBC_AVX512_VPOPCNTDQ

	X86FeatureExtendedBC_INTEL_5_LEVEL_PAGING
	X86FeatureExtendedBC_MAWAU_0
	X86FeatureExtendedBC_MAWAU_1
	X86FeatureExtendedBC_MAWAU_2
	X86FeatureExtendedBC_MAWAU_3
	X86FeatureExtendedBC_MAWAU_4
	X86FeatureExtendedBC_RDPID
	X86FeatureExtendedBC_KL

	X86FeatureExtendedBC_CLDEMOTE

	X86FeatureExtendedBC_MOVDIRI
	X86FeatureExtendedBC_MOVDIR64B
	X86FeatureExtendedBC_ENQCMD
	X86FeatureExtendedBC_SGX_LC
	X86FeatureExtendedBC_PKS
)

func (X86FeatureExtendedBC) Features added in v0.10.0

func (feat X86FeatureExtendedBC) Features() (ret []string)

func (X86FeatureExtendedBC) HasAll added in v0.10.0

func (feat X86FeatureExtendedBC) HasAll(features ...X86FeatureExtendedBC) bool

func (X86FeatureExtendedBC) String added in v0.10.0

func (feat X86FeatureExtendedBC) String() string

type X86FeatureExtendedDA added in v0.10.0

type X86FeatureExtendedDA uint64

X86FeatureExtendedDA (leaf7.0 edx, leaf7.1 eax)

const (
	X86FeatureExtendedDA_AVX512_4VNNIW X86FeatureExtendedDA
	X86FeatureExtendedDA_AVX512_4FMAPS
	X86FeatureExtendedDA_FSRM

	X86FeatureExtendedDA_AVX512_VP2INTERSECT
	X86FeatureExtendedDA_SRBDS_CTRL
	X86FeatureExtendedDA_MD_CLEAR
	X86FeatureExtendedDA_RTM_ALWAYS_ABORT

	X86FeatureExtendedDA_TSX_FORCE_ABORT
	X86FeatureExtendedDA_SERIALIZE
	X86FeatureExtendedDA_HYBRID
	X86FeatureExtendedDA_TSXLDTRK

	X86FeatureExtendedDA_PCONFIG
	X86FeatureExtendedDA_LBR
	X86FeatureExtendedDA_CET_IBT

	X86FeatureExtendedDA_AMX_BF16
	X86FeatureExtendedDA_AVX512_FP16
	X86FeatureExtendedDA_AMX_TILE
	X86FeatureExtendedDA_AMX_INT8
	X86FeatureExtendedDA_SPEC_CTRL
	X86FeatureExtendedDA_STIBP
	X86FeatureExtendedDA_L1D_FLUSH
	X86FeatureExtendedDA_IA32_ARCH_CAPABILITIES
	X86FeatureExtendedDA_IA32_CORE_CAPABILITIES
	X86FeatureExtendedDA_SSBD

	X86FeatureExtendedDA_AVX512_BF16
)

func (X86FeatureExtendedDA) Features added in v0.10.0

func (feat X86FeatureExtendedDA) Features() (ret []string)

func (X86FeatureExtendedDA) HasAll added in v0.10.0

func (feat X86FeatureExtendedDA) HasAll(features ...X86FeatureExtendedDA) bool

func (X86FeatureExtendedDA) String added in v0.10.0

func (feat X86FeatureExtendedDA) String() string

type X86FeatureExtra added in v0.10.0

type X86FeatureExtra uint64

X86FeatureExtra (leaf0x8000_0001.0 ecx, edx)

const (
	// leaf0x8000_0001.0 ecx
	X86ExtraFeature_LAHF_LM X86FeatureExtra = 1 << iota
	X86ExtraFeature_CMP_LEGACY
	X86ExtraFeature_SVM
	X86ExtraFeature_EXTAPIC
	X86ExtraFeature_CR8_LEGACY
	X86ExtraFeature_ABM
	X86ExtraFeature_SSE4A
	X86ExtraFeature_MISALIGN_SSE
	X86ExtraFeature_3D_NOW_PREFETCH
	X86ExtraFeature_OSVW
	X86ExtraFeature_IBS
	X86ExtraFeature_XOP
	X86ExtraFeature_SKINIT
	X86ExtraFeature_WDT

	X86ExtraFeature_LWP
	X86ExtraFeature_FMA4
	X86ExtraFeature_TCE

	X86ExtraFeature_NODEID_MSR

	X86ExtraFeature_TBM
	X86ExtraFeature_TOPOEXT
	X86ExtraFeature_PERFCTR_CORE
	X86ExtraFeature_PERFCTR_NB

	X86ExtraFeature_DBX
	X86ExtraFeature_PERFTSC
	X86ExtraFeature_PCX_L2I

	// leaf0x8000_0001.0 edx
	X86ExtraFeature_FPU
	X86ExtraFeature_VME
	X86ExtraFeature_DE
	X86ExtraFeature_PSE
	X86ExtraFeature_TSC
	X86ExtraFeature_MSR
	X86ExtraFeature_PAE
	X86ExtraFeature_MCE
	X86ExtraFeature_CX8
	X86ExtraFeature_APIC

	X86ExtraFeature_SYSCALL // syscall/sysret
	X86ExtraFeature_MTRR
	X86ExtraFeature_PGE
	X86ExtraFeature_MCA
	X86ExtraFeature_CMOV
	X86ExtraFeature_PAT
	X86ExtraFeature_PSE36

	X86ExtraFeature_MP
	X86ExtraFeature_NX

	X86ExtraFeature_MMXEXT
	X86ExtraFeature_MMX
	X86ExtraFeature_FXSR
	X86ExtraFeature_FXSR_OPT
	X86ExtraFeature_PDPE1GB
	X86ExtraFeature_RDTSCP

	X86ExtraFeature_LM
	X86ExtraFeature_3D_NOW_EXT
	X86ExtraFeature_3D_NOW
)

func (X86FeatureExtra) Features added in v0.10.0

func (feat X86FeatureExtra) Features() (ret []string)

func (X86FeatureExtra) HasAll added in v0.10.0

func (feat X86FeatureExtra) HasAll(features ...X86FeatureExtra) bool

func (X86FeatureExtra) String added in v0.10.0

func (feat X86FeatureExtra) String() string

type X86Model added in v0.10.0

type X86Model uint8

type X86ProcessType added in v0.10.0

type X86ProcessType uint8

type X86Stepping added in v0.10.0

type X86Stepping uint8

type X86ThermalPowerFeature added in v0.10.0

type X86ThermalPowerFeature uint32
const (
	// eax (31:7 reserved)
	X86ThermalPowerFeature_DigitalThermalSensor X86ThermalPowerFeature = 1 << iota
	X86ThermalPowerFeature_IntelTurboBoost
	X86ThermalPowerFeature_AlwaysRunningAPICTimer

	X86ThermalPowerFeature_PowerLimitNotification
	X86ThermalPowerFeature_ExtendedClockModulationDuty
	X86ThermalPowerFeature_PackageThermalManagement

	// ecx (31:4 reserved)
	X86ThermalPowerFeature_HardwareCoordinationFeedback
	X86ThermalPowerFeature_ACNT2

	X86ThermalPowerFeature_PerformanceEnergyBias
)

func (X86ThermalPowerFeature) Features added in v0.10.0

func (feat X86ThermalPowerFeature) Features() (ret []string)

func (X86ThermalPowerFeature) HasAll added in v0.10.0

func (feat X86ThermalPowerFeature) HasAll(features ...X86ThermalPowerFeature) bool

func (X86ThermalPowerFeature) String added in v0.10.0

func (feat X86ThermalPowerFeature) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL