|
3 | 3 | #include <string.h> |
4 | 4 |
|
5 | 5 | #define FF_GPU_MODULE_NAME "GPU" |
6 | | -#define FF_GPU_NUM_FORMAT_ARGS 5 |
| 6 | +#define FF_GPU_NUM_FORMAT_ARGS 6 |
7 | 7 |
|
8 | 8 | static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* result) |
9 | 9 | { |
@@ -39,6 +39,7 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, |
39 | 39 | {FF_FORMAT_ARG_TYPE_STRBUF, &result->name}, |
40 | 40 | {FF_FORMAT_ARG_TYPE_STRBUF, &namePretty}, |
41 | 41 | {FF_FORMAT_ARG_TYPE_STRBUF, &result->driver}, |
| 42 | + {FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature} |
42 | 43 | }); |
43 | 44 |
|
44 | 45 | ffStrbufDestroy(&result->vendor); |
@@ -89,6 +90,26 @@ static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get |
89 | 90 | ffStrbufDestroy(&path); |
90 | 91 | } |
91 | 92 |
|
| 93 | +static double pciGetTemperatur(const FFinstance* instance, uint16_t deviceClass) |
| 94 | +{ |
| 95 | + const FFTempsResult* tempsResult = ffDetectTemps(instance); |
| 96 | + |
| 97 | + for(uint32_t i = 0; i < tempsResult->values.length; i++) |
| 98 | + { |
| 99 | + FFTempValue* tempValue = ffListGet(&tempsResult->values, i); |
| 100 | + |
| 101 | + uint32_t tempClass; |
| 102 | + if(sscanf(tempValue->deviceClass.chars, "%x", &tempClass) != 1) |
| 103 | + continue; |
| 104 | + |
| 105 | + //The kernel exposes the device class multiplied by 256 for some reason |
| 106 | + if(tempClass == deviceClass * 256) |
| 107 | + return tempValue->value; |
| 108 | + } |
| 109 | + |
| 110 | + return 0.0 / 0.0; //NaN |
| 111 | +} |
| 112 | + |
92 | 113 | static bool pciPrintGPUs(FFinstance* instance) |
93 | 114 | { |
94 | 115 | FF_LIBRARY_LOAD(pci, instance->config.libPCI, false, "libpci.so", 4) |
@@ -121,16 +142,22 @@ static bool pciPrintGPUs(FFinstance* instance) |
121 | 142 | FFGPUResult* result = ffListAdd(&results); |
122 | 143 |
|
123 | 144 | ffStrbufInitA(&result->vendor, 256); |
124 | | - ffpci_lookup_name(pacc, result->vendor.chars, (int) result->vendor.allocated -1, PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id); |
| 145 | + ffpci_lookup_name(pacc, result->vendor.chars, (int) ffStrbufGetFree(&result->vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id); |
125 | 146 | ffStrbufRecalculateLength(&result->vendor); |
126 | 147 |
|
127 | 148 | ffStrbufInitA(&result->name, 256); |
128 | | - ffpci_lookup_name(pacc, result->name.chars, (int) result->name.allocated - 1, PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id); |
| 149 | + ffpci_lookup_name(pacc, result->name.chars, (int) ffStrbufGetFree(&result->name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id); |
129 | 150 | ffStrbufRecalculateLength(&result->name); |
130 | 151 |
|
131 | 152 | ffStrbufInit(&result->driver); |
132 | | - if(instance->config.gpu.outputFormat.length > 0) //We only need it for the format string, so don't detect it if it isn't needed |
| 153 | + result->temperature = 0; |
| 154 | + |
| 155 | + //We only need it for the format string, so don't detect it if it isn't needed |
| 156 | + if(instance->config.gpu.outputFormat.length > 0) |
| 157 | + { |
133 | 158 | pciGetDriver(dev, &result->driver, ffpci_get_param); |
| 159 | + result->temperature = pciGetTemperatur(instance, dev->device_class); |
| 160 | + } |
134 | 161 | }; |
135 | 162 | } |
136 | 163 |
|
|
0 commit comments