Extending machine API by NVM memory mode capacity (#2431)

* Extending machine API by NVM memory and app direct mode capacity

Signed-off-by: Katarzyna Kujawa <katarzyna.kujawa@intel.com>
This commit is contained in:
Katarzyna Kujawa 2020-03-18 16:57:25 +01:00 committed by GitHub
parent 59bc6fe2c4
commit e62441a65a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 19 deletions

View File

@ -222,7 +222,13 @@ type MemoryInfo struct {
} }
type NVMInfo struct { type NVMInfo struct {
// Average power budget for NVM devices configured in BIOS. // The total NVM capacity in bytes for memory mode.
MemoryModeCapcity uint64 `json:"memory_mode_capcity"`
//The total NVM capacity in bytes for app direct mode.
AppDirectModeCapcity uint64 `json:"app direct_mode_capcity"`
// Average power budget in watts for NVM devices configured in BIOS.
AvgPowerBudget uint `json:"avg_power_budget"` AvgPowerBudget uint `json:"avg_power_budget"`
} }

View File

@ -77,7 +77,7 @@ func Info(sysFs sysfs.SysFs, fsInfo fs.FsInfo, inHostNamespace bool) (*info.Mach
return nil, err return nil, err
} }
nvmPowerBudget, err := GetNVMAvgPowerBudget() nvmInfo, err := GetNVMInfo()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -124,7 +124,7 @@ func Info(sysFs sysfs.SysFs, fsInfo fs.FsInfo, inHostNamespace bool) (*info.Mach
CpuFrequency: clockSpeed, CpuFrequency: clockSpeed,
MemoryCapacity: memoryCapacity, MemoryCapacity: memoryCapacity,
MemoryByType: memoryByType, MemoryByType: memoryByType,
NVMInfo: info.NVMInfo{AvgPowerBudget: nvmPowerBudget}, NVMInfo: nvmInfo,
HugePages: hugePagesInfo, HugePages: hugePagesInfo,
DiskMap: diskMap, DiskMap: diskMap,
NetworkDevices: netDevices, NetworkDevices: netDevices,

View File

@ -22,25 +22,19 @@ import "C"
import ( import (
"fmt" "fmt"
info "github.com/google/cadvisor/info/v1"
"k8s.io/klog" "k8s.io/klog"
) )
// GetNVMAvgPowerBudget retrieves configured power budget // getNVMAvgPowerBudget retrieves configured power budget
// (in watts) for NVM devices. When libipmct is not available // (in watts) for NVM devices. When libipmct is not available
// zero is returned. // zero is returned.
func GetNVMAvgPowerBudget() (uint, error) { func getNVMAvgPowerBudget() (uint, error) {
// Initialize libipmctl library.
err := C.nvm_init()
if err != C.NVM_SUCCESS {
klog.Warningf("libipmctl initialization failed with status %d", err)
return uint(0), fmt.Errorf("libipmctl initialization failed with status %d", err)
}
defer C.nvm_uninit()
// Get number of devices on the platform // 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 // see: https://github.com/intel/ipmctl/blob/v01.00.00.3497/src/os/nvm_api/nvm_management.h#L1478
var count C.uint var count C.uint
err = C.nvm_get_number_of_devices(&count) err := C.nvm_get_number_of_devices(&count)
if err != C.NVM_SUCCESS { if err != C.NVM_SUCCESS {
klog.Warningf("Unable to get number of NVM devices. Status code: %d", err) 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) return uint(0), fmt.Errorf("Unable to get number of NVM devices. Status code: %d", err)
@ -67,3 +61,38 @@ func GetNVMAvgPowerBudget() (uint, error) {
return uint(device.avg_power_budget / 1000), nil return uint(device.avg_power_budget / 1000), nil
} }
// getNVMCapacities retrieves the total NVM capacity in bytes for memory mode and app direct mode
func getNVMCapacities() (uint64, uint64, error) {
var caps C.struct_device_capacities
err := C.nvm_get_nvm_capacities(&caps)
if err != C.NVM_SUCCESS {
klog.Warningf("Unable to get NVM capacity. Status code: %d", err)
return uint64(0), uint64(0), fmt.Errorf("Unable to get NVM capacity. Status code: %d", err)
}
return uint64(caps.memory_capacity), uint64(caps.app_direct_capacity), nil
}
// GetNVMInfo returns information specific for non-volatile memory modules
func GetNVMInfo() (info.NVMInfo, error) {
nvmInfo := info.NVMInfo{}
// Initialize libipmctl library.
cErr := C.nvm_init()
if cErr != C.NVM_SUCCESS {
klog.Warningf("libipmctl initialization failed with status %d", cErr)
return info.NVMInfo{}, fmt.Errorf("libipmctl initialization failed with status %d", cErr)
}
defer C.nvm_uninit()
var err error
nvmInfo.MemoryModeCapcity, nvmInfo.AppDirectModeCapcity, err = getNVMCapacities()
if err != nil {
return info.NVMInfo{}, fmt.Errorf("Unable to get NVM capacities, err: %s", err)
}
nvmInfo.AvgPowerBudget, err = getNVMAvgPowerBudget()
if err != nil {
return info.NVMInfo{}, fmt.Errorf("Unable to get NVM average power budget, err: %s", err)
}
return nvmInfo, nil
}

View File

@ -16,9 +16,10 @@
package machine package machine
// GetNVMAvgPowerBudget retrieves configured power budget import info "github.com/google/cadvisor/info/v1"
// (in watts) for NVM devices. When libipmct is not available
// zero is returned. // GetNVMInfo returns information specific for non-volatile memory modules.
func GetNVMAvgPowerBudget() (uint, error) { // When libipmct is not available zero value is returned.
return uint(0), nil func GetNVMInfo() (info.NVMInfo, error) {
return info.NVMInfo{}, nil
} }