intelcpu
1.0.0
intel_pstate 드라이버와의 상호 작용을 허용하는 패키지는 CPU 주파수 및 정치를 구동합니다.
intel_pstate 드라이버를 설치하고 활성화해야합니다. 일반적으로 Sandy Bridge 및 이후 CPU의 경우 Linux 커널 4.13에 이미 포함되었습니다 .
Github에서 가져 오십시오.
go get -u https://github.com/gopowersupply/intelcpu문서는 여기에서 찾을 수 있습니다
intel_pstate CPU 성능 스케일링 드라이버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{}) 사용할 수 있습니다.