getAvgPowerBudget retrieves configured power budget (in watts) for NVM devices. When libipmctl is not available zero is returned.
()
| 50 | // (in watts) for NVM devices. When libipmctl is not available |
| 51 | // zero is returned. |
| 52 | func getAvgPowerBudget() (uint, error) { |
| 53 | // Get number of devices on the platform |
| 54 | // see: https://github.com/intel/ipmctl/blob/v01.00.00.3497/src/os/nvm_api/nvm_management.h#L1478 |
| 55 | count := C.uint(0) |
| 56 | err := C.nvm_get_number_of_devices(&count) |
| 57 | if err != C.NVM_SUCCESS { |
| 58 | klog.Warningf("Unable to get number of NVM devices. Status code: %d", err) |
| 59 | return uint(0), fmt.Errorf("Unable to get number of NVM devices. Status code: %d", err) |
| 60 | } |
| 61 | |
| 62 | if count == 0 { |
| 63 | klog.V(4).Infof("There are no NVM devices.") |
| 64 | return uint(0), nil |
| 65 | } |
| 66 | |
| 67 | // Load basic device information for all the devices |
| 68 | // to obtain UID of the first one. |
| 69 | devices := make([]C.struct_device_discovery, count) |
| 70 | err = C.nvm_get_devices(&devices[0], C.uchar(count)) |
| 71 | if err != C.NVM_SUCCESS { |
| 72 | klog.Warningf("Unable to get all NVM devices. Status code: %d", err) |
| 73 | return uint(0), fmt.Errorf("Unable to get all NVM devices. Status code: %d", err) |
| 74 | } |
| 75 | |
| 76 | // Power budget is same for all the devices |
| 77 | // so we can rely on any of them. |
| 78 | device := C.struct_device_details{} |
| 79 | err = C.nvm_get_device_details(&devices[0].uid[0], &device) |
| 80 | if err != C.NVM_SUCCESS { |
| 81 | uid := C.GoString(&devices[0].uid[0]) |
| 82 | klog.Warningf("Unable to get details of NVM device %q. Status code: %d", uid, err) |
| 83 | return uint(0), fmt.Errorf("Unable to get details of NVM device %q. Status code: %d", uid, err) |
| 84 | } |
| 85 | |
| 86 | return uint(device.avg_power_budget / 1000), nil |
| 87 | } |
| 88 | |
| 89 | // getCapacities retrieves the total NVM capacity in bytes for memory mode and app direct mode |
| 90 | func getCapacities() (uint64, uint64, error) { |