แพ็คเกจเพื่ออนุญาตให้มีปฏิสัมพันธ์กับไดรเวอร์ Intel_Pstate เพื่อขับเคลื่อนความถี่ CPU และการเมือง
ต้องติดตั้งและเปิดใช้งานไดรเวอร์ Intel_pstate โดยปกติ แล้วจะรวมอยู่ในเคอร์เนล Linux 4.13 สำหรับ Sandy Bridge และ CPU ในภายหลัง
รับจาก GitHub:
go get -u https://github.com/gopowersupply/intelcpuเอกสารสามารถพบได้ที่นี่
intel_pstateตัวอย่างง่ายๆในการเปลี่ยนสถานะ turboboost:
cpu := intelcpu . New ()
turbo , _ := cpu . GetTurbo ()
if turbo {
cpu . SetTurbo ( false )
} else {
cpu . SetTurbo ( true )
}ในโครงการจริงขอแนะนำอย่างยิ่งให้ตรวจสอบผู้ขับขี่และสถานะของมัน:
cpu := intelcpu . New ()
if err := cpu . CheckDriver (); err != nil {
// [...] Some troubles or driver not installed
}
status , _ := cpu . GetStatus ()
switch status {
case intelcpu . PStateStatusActive :
// [...] All is ok
case intelcpu . PStateStatusPassive :
// [...] Something wrong, working partially
case intelcpu . PStateStatusOff :
// [...] Driver disabled, nothing to work
}คุณสามารถเปิดใช้งานหรือปิดการใช้งานคอร์บางคอร์ ยกเว้นครั้งแรกแน่นอน:
cpu := intelcpu . New ()
cores , _ := cpu . GetCores ()
for _ , core := range cores {
// First core will return false and its status always will be online
isOfflineAvailable , _ := core . IsOfflineAvailable ()
isOnline , _ := core . IsOnline ()
fmt . Printf ( "Core %d is online: %v" , isOnline )
// If core can be offline then do it
if isOfflineAvailable {
core . SetOnline ( false )
}
}คุณสามารถเปลี่ยนข้อ จำกัด ความถี่ CPU ได้เช่นกัน:
cpu := intelcpu . New ()
cpu . SetMaxPerf ( 0.5 ) // 50% of maxประสิทธิภาพหลักและการเมืองของผู้ว่าราชการสามารถเปลี่ยนแปลงได้:
cpu := intelcpu . New ()
cores , _ := cpu . GetCores ()
for _ , core := range cores {
core . SetGovernor ( intelcpu . CPUGovernorPerformance )
core . SetPreference ( intelcpu . CPUPreferencePerformance )
}วิธีสั้น ๆ :
cpu := intelcpu . New ()
cores , _ := cpu . GetCores ()
cores . SetGovernor ( intelcpu . CPUGovernorPerformance )
cores . SetPreference ( intelcpu . CPUPreferencePerformance ) แพ็คเกจนี้มี CPUError ประเภทข้อผิดพลาดของตัวเอง
คุณสามารถส่งข้อผิดพลาดของแพ็คเกจผ่านฟังก์ชั่นของคุณจากนั้นตรวจจับผ่าน errors.As เช่น:
func ExecUnexpected () error {
// [...] Here your other returns with own errors
cpu := intelcpu . New ()
_ , err := cpu . GetCore ( 20000 )
if err != nil {
return err
}
// [...] Here your other returns with own errors
}
func main () {
err := ExecUnexpected ()
if intelcpu . IsCPUError ( err ) {
// [...] to do anything
} else {
// [...] to do something other
}
} และคุณสามารถใช้ errors.As(err, &intelcpu.CPUError{}) เป็นทางเลือก