Skip to content

Commit

Permalink
Retrieving NVM average power budget
Browse files Browse the repository at this point in the history
Conflicts:
	info/v1/machine.go

Signed-off-by: Maciej "Iwan" Iwanowski <maciej.iwanowski@intel.com>
  • Loading branch information
Maciej Iwanowski committed Mar 13, 2020
1 parent 9251e32 commit 6dac579
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions info/v1/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ type MachineInfo struct {
// Memory capacity and number of DIMMs by memory type
MemoryByType map[string]*MemoryInfo `json:"memory_by_type"`

// Average power budget for NVM devices configured in BIOS.
NVMAvgPowerBudget uint `json:"nvm_avg_power_budget"`

// HugePages on this machine.
HugePages []HugePagesInfo `json:"hugepages"`

Expand Down
60 changes: 60 additions & 0 deletions machine/machine_libipmctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// +build libipmctl

package machine

// #cgo pkg-config: libipmctl
// #include <nvm_management.h>
import "C"
import (
"fmt"

"k8s.io/klog"
)

var initializedSuccefully bool

func init() {
err := C.nvm_init()
initializedSuccefully = err == C.NVM_SUCCESS
if !initializedSuccefully {
klog.Warningf("libipmctl initialization failed with status %d", err)
}
}

// GetNVMAvgPowerBudget retrieves configured power budget for NVM devices.
// It uses ipmlibctl to get setting configured in BIOS.
func GetNVMAvgPowerBudget() (uint, error) {
// Fail silently when library cannot be initialized.
if !initializedSuccefully {
return uint(0), nil
}
// Get number of devices on the platform
// see: https://github.com/intel/ipmctl/blob/v01.00.00.3497/src/os/nvm_api/nvm_management.h#L1478
var count C.uint
err := C.nvm_get_number_of_devices(&count)
if err != C.NVM_SUCCESS {
klog.Warningf("Unable to get number of NVM devices. Status code: %d", err)
return uint(0), fmt.Errorf("Unable to get number of NVM devices. Status code: %d", err)
}

// Load basic device information for all the devices
// to obtain UID of the first one.
var devices = make([]C.struct_device_discovery, count)
err = C.nvm_get_devices(&devices[0], C.uchar(count))
if err != C.NVM_SUCCESS {
klog.Warningf("Unable to get all NVM devices. Status code: %d", err)
return uint(0), fmt.Errorf("Unable to get all NVM devices. Status code: %d", err)
}

// Power budget is same for all the devices
// so we can rely on any of them.
var device C.struct_device_details
err = C.nvm_get_device_details(&devices[0].uid[0], &device)
if err != C.NVM_SUCCESS {
uid := C.GoString(&devices[0].uid[0])
klog.Warningf("Unable to get details of NVM device %q. Status code: %d", uid, err)
return uint(0), fmt.Errorf("Unable to get details of NVM device %q. Status code: %d", uid, err)
}

return uint(device.avg_power_budget), nil
}
9 changes: 9 additions & 0 deletions machine/machine_no_libipmctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !libipmctl

package machine

// GetNVMAvgPowerBudget retrieves configured power budget for NVM devices.
// When libipmct is not available zero is returned.
func GetNVMAvgPowerBudget() (uint, error) {
return uint(0), nil
}

0 comments on commit 6dac579

Please sign in to comment.