Added support for some NVML sensors.
GPU temp sensor and clock reasons.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nvidia-sensors.h"
|
||||
|
||||
int init_nvml()
|
||||
{
|
||||
nvmlReturn_t result;
|
||||
result = nvmlInit_v2();
|
||||
if (result != NVML_SUCCESS) {
|
||||
printf("Could not init NVML: %s\n", nvmlErrorString(result));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void print_nvml_temp(int compact, struct card_info *card)
|
||||
{
|
||||
if (compact)
|
||||
printf(" %3d", get_nvml_temp(card));
|
||||
else
|
||||
printf("GPU1: %+d°C\n", get_nvml_temp(card));
|
||||
}
|
||||
|
||||
void print_nvml_clock_reason(int compact, struct card_info *card)
|
||||
{
|
||||
unsigned long long reasons = get_nvml_clock_reasons(card);
|
||||
int single_reason = 1;
|
||||
|
||||
if (compact)
|
||||
printf(" CLK ");
|
||||
else
|
||||
printf("Clock reasons: ");
|
||||
|
||||
for (int i = 0; i < (sizeof(clock_reason_names) / sizeof(struct clock_reason)); i++) {
|
||||
if (reasons & clock_reason_names[i].mask) {
|
||||
if (!single_reason) {
|
||||
if (compact)
|
||||
printf(",");
|
||||
else
|
||||
printf(", ");
|
||||
}
|
||||
single_reason = 0;
|
||||
|
||||
if (compact)
|
||||
printf("%s", clock_reason_names[i].short_name);
|
||||
else
|
||||
printf("%s", clock_reason_names[i].long_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (single_reason)
|
||||
printf("None");
|
||||
|
||||
if (!compact)
|
||||
printf(" (0x%llx)\n", reasons);
|
||||
}
|
||||
|
||||
unsigned int get_nvml_temp(struct card_info *card)
|
||||
{
|
||||
nvmlReturn_t result;
|
||||
nvmlDevice_t nvml_device;
|
||||
result = nvmlDeviceGetHandleByPciBusId_v2(card->pci_id, &nvml_device);
|
||||
if (result != NVML_SUCCESS) {
|
||||
printf("Failed to get device handle for card at %s: %s\n", card->pci_id, nvmlErrorString(result));
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int temp;
|
||||
result = nvmlDeviceGetTemperature(nvml_device, NVML_TEMPERATURE_GPU, &temp);
|
||||
if (result != NVML_SUCCESS) {
|
||||
printf("Failed to get temperature for card at %s: %s\n", card->pci_id, nvmlErrorString(result));
|
||||
return 0;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
unsigned long long get_nvml_clock_reasons(struct card_info *card)
|
||||
{
|
||||
nvmlReturn_t result;
|
||||
nvmlDevice_t nvml_device;
|
||||
result = nvmlDeviceGetHandleByPciBusId_v2(card->pci_id, &nvml_device);
|
||||
if (result != NVML_SUCCESS) {
|
||||
printf("Failed to get device handle for card at %s: %s\n", card->pci_id, nvmlErrorString(result));
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long long reasons;
|
||||
result = nvmlDeviceGetCurrentClocksEventReasons(nvml_device, &reasons) ;
|
||||
if (result != NVML_SUCCESS) {
|
||||
printf("Failed to get clock reasons for card at %s: %s\n", card->pci_id, nvmlErrorString(result));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return reasons;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user