Skip to content

Commit

Permalink
nvml: suppress NotSupported fan errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnldd committed Aug 11, 2018
1 parent 62d11fb commit 10dbeb8
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions nvml/nvml.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ import (
"unsafe"
)

// NVML result codes
const (
Success = "Success"
Uninitialized = "Uninitialized"
InvalidArgument = "InvalidArgument"
NotSupported = "NotSupported"
NoPermission = "NoPermission"
AlreadyInitialized = "AlreadyInitialized"
NotFound = "NotFound"
InsufficientSize = "InsufficientSize"
InsufficientPower = "InsufficientPower"
DriverNotLoaded = "DriverNotLoaded"
Timeout = "Timeout"
Unknown = "Unknown"
)

type ComputeMode C.nvmlComputeMode_t
type Feature uint
type ECCBitType uint
Expand All @@ -26,31 +42,32 @@ type Result struct {
func (r Result) String() string {
switch r.code {
case 0:
return "Success"
return Success
case 1:
return "Uninitialized"
return Uninitialized
case 2:
return "InvalidArgument"
return InvalidArgument
case 3:
return "NotSupported"
return NotSupported
case 4:
return "NoPermission"
return NoPermission
case 5:
return "AlreadyInitialized"
return AlreadyInitialized
case 6:
return "NotFound"
return NotFound
case 7:
return "InsufficientSize"
return InsufficientSize
case 8:
return "InsufficientPower"
return InsufficientPower
case 9:
return "DriverNotLoaded"
return DriverNotLoaded
case 10:
return "Timeout"
return Timeout
case 99:
return "Unknown"
return Unknown
default:
return Unknown
}
return "UnknownError"
}

func (r Result) Error() string {
Expand Down Expand Up @@ -190,5 +207,11 @@ func DevicePerformanceState(dh DeviceHandle) (PState, error) {
func DeviceFanSpeed(dh DeviceHandle) (uint, error) {
var speed C.uint
r := NewResult(C.nvmlDeviceGetFanSpeed(dh.handle, &speed))
return uint(speed), r
if r != nil {
// Suppress not supported fan speed errors.
if r.Error() != NotSupported {
return uint(speed), r
}
}
return uint(speed), nil
}

0 comments on commit 10dbeb8

Please sign in to comment.