Skip to content

Commit

Permalink
Add frequency reports in status
Browse files Browse the repository at this point in the history
* Qutefan
- Add GPU frequency in status groupbox
* QNvAPI
- Replace C-style casting
- Replace GPU_GetAllClockFrequencies with GPU_GetAllClocks
* GpuTab
- Add overclocking widgets but hide them as they do nothing now
  • Loading branch information
loathingKernel committed Sep 15, 2017
1 parent 1d7f9a4 commit 1a87afa
Show file tree
Hide file tree
Showing 9 changed files with 605 additions and 241 deletions.
64 changes: 32 additions & 32 deletions platforms/qnvapi/qnvapi.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "qnvapi.h"

QMutex* nvapi_lock = new QMutex(QMutex::Recursive);
static QMutex* nvapi_lock = new QMutex(QMutex::Recursive);

QNvAPI::QNvAPI()
: QLibrary("nvapi"),
Expand All @@ -17,7 +17,7 @@ QNvAPI::QNvAPI()
nvapi_GPU_GetFullName(NULL),
nvapi_GPU_GetEDID(NULL),
nvapi_GPU_GetTachReading(NULL),
nvapi_GPU_GetAllClockFrequencies(NULL),
nvapi_GPU_GetAllClocks(NULL),
nvapi_GPU_GetPstates20(NULL),
nvapi_GPU_GetMemoryInfo(NULL),
nvapi_GPU_GetPCIIdentifiers(NULL),
Expand All @@ -27,36 +27,36 @@ QNvAPI::QNvAPI()
{
QMutexLocker locker(nvapi_lock);

nvapi_QueryInterface = (QNVAPI_QUERYINTERFACE)resolve("nvapi_QueryInterface");
nvapi_QueryInterface = reinterpret_cast<QNVAPI_QUERYINTERFACE>(resolve("nvapi_QueryInterface"));

if(!nvapi_QueryInterface) {
status = NVAPI_LIBRARY_NOT_FOUND;
qDebug("QNvAPI failed to initialize NvAPI_QueryInterface()");
} else {
nvapi_Initialize = (QNVAPI_INITIALIZE) nvapi_QueryInterface(0x0150E828);

nvapi_EnumNvidiaDisplayHandle = (QNVAPI_ENUMNVIDIADISPLAYHANDLE) nvapi_QueryInterface(0x9ABDD40D);
nvapi_EnumPhysicalGPUs = (QNVAPI_ENUMPHYSICALGPUS) nvapi_QueryInterface(0xE5AC921F);

nvapi_GetInterfaceVersionString = (QNVAPI_GETINTERFACEVERSIONSTRING) nvapi_QueryInterface(0x01053FA5);
nvapi_GetDisplayDriverVersion = (QNVAPI_GETDISPLAYDRIVERVERSION) nvapi_QueryInterface(0xF951A4D1);
nvapi_GetPhysicalGPUsFromDisplay = (QNVAPI_GETPHYSICALGPUSFROMDISPLAY) nvapi_QueryInterface(0x34EF9506);
nvapi_GetAssociatedNvidiaDisplayHandle = (QNVAPI_GETASSOCIATEDNVIDIADISPLAYHANDLE) nvapi_QueryInterface(0x35C29134);
nvapi_GetAssociatedDisplayOutputId = (QNVAPI_GETASSOCIATEDDISPLAYOUTPUTID) nvapi_QueryInterface(0xD995937E);

nvapi_GPU_GetThermalSettings = (QNVAPI_GPU_GETTHERMALSETTINGS) nvapi_QueryInterface(0xE3640A56);
nvapi_GPU_GetFullName = (QNVAPI_GPU_GETFULLNAME) nvapi_QueryInterface(0xCEEE8E9F);
nvapi_GPU_GetEDID = (QNVAPI_GPU_GETEDID) nvapi_QueryInterface(0x37D32E69);
nvapi_GPU_GetTachReading = (QNVAPI_GPU_GETTACHREADING) nvapi_QueryInterface(0x5F608315);
nvapi_GPU_GetAllClockFrequencies = (QNVAPI_GPU_GETALLCLOCKFREQUENCIES) nvapi_QueryInterface(0x1BD69F49);
nvapi_GPU_GetPstates20 = (QNVAPI_GPU_GETPSTATES20) nvapi_QueryInterface(0x60DED2ED);
nvapi_GPU_GetMemoryInfo = (QNVAPI_GPU_GETMEMORYINFO) nvapi_QueryInterface(0x774AA982);
nvapi_GPU_GetPCIIdentifiers = (QNVAPI_GPU_GETPCIIDENTIFIERS) nvapi_QueryInterface(0x2DDFB66E);

nvapi_GPU_GetUsages = (QNVAPI_GPU_GETUSAGES) nvapi_QueryInterface(0x189A1FDF);
nvapi_GPU_GetCoolerSettings = (QNVAPI_GPU_GETCOOLERSETTINGS) nvapi_QueryInterface(0xDA141340);

nvapi_GPU_SetCoolerLevels = (QNVAPI_GPU_SETCOOLERLEVELS) nvapi_QueryInterface(0x891FA0AE);
nvapi_Initialize = reinterpret_cast<QNVAPI_INITIALIZE> (nvapi_QueryInterface(0x0150E828));

nvapi_EnumNvidiaDisplayHandle = reinterpret_cast<QNVAPI_ENUMNVIDIADISPLAYHANDLE> (nvapi_QueryInterface(0x9ABDD40D));
nvapi_EnumPhysicalGPUs = reinterpret_cast<QNVAPI_ENUMPHYSICALGPUS> (nvapi_QueryInterface(0xE5AC921F));

nvapi_GetInterfaceVersionString = reinterpret_cast<QNVAPI_GETINTERFACEVERSIONSTRING> (nvapi_QueryInterface(0x01053FA5));
nvapi_GetDisplayDriverVersion = reinterpret_cast<QNVAPI_GETDISPLAYDRIVERVERSION> (nvapi_QueryInterface(0xF951A4D1));
nvapi_GetPhysicalGPUsFromDisplay = reinterpret_cast<QNVAPI_GETPHYSICALGPUSFROMDISPLAY> (nvapi_QueryInterface(0x34EF9506));
nvapi_GetAssociatedNvidiaDisplayHandle = reinterpret_cast<QNVAPI_GETASSOCIATEDNVIDIADISPLAYHANDLE> (nvapi_QueryInterface(0x35C29134));
nvapi_GetAssociatedDisplayOutputId = reinterpret_cast<QNVAPI_GETASSOCIATEDDISPLAYOUTPUTID> (nvapi_QueryInterface(0xD995937E));

nvapi_GPU_GetThermalSettings = reinterpret_cast<QNVAPI_GPU_GETTHERMALSETTINGS> (nvapi_QueryInterface(0xE3640A56));
nvapi_GPU_GetFullName = reinterpret_cast<QNVAPI_GPU_GETFULLNAME> (nvapi_QueryInterface(0xCEEE8E9F));
nvapi_GPU_GetEDID = reinterpret_cast<QNVAPI_GPU_GETEDID> (nvapi_QueryInterface(0x37D32E69));
nvapi_GPU_GetTachReading = reinterpret_cast<QNVAPI_GPU_GETTACHREADING> (nvapi_QueryInterface(0x5F608315));
nvapi_GPU_GetAllClocks = reinterpret_cast<QNVAPI_GPU_GETALLCLOCKS> (nvapi_QueryInterface(0x1BD69F49));
nvapi_GPU_GetPstates20 = reinterpret_cast<QNVAPI_GPU_GETPSTATES20> (nvapi_QueryInterface(0x60DED2ED));
nvapi_GPU_GetMemoryInfo = reinterpret_cast<QNVAPI_GPU_GETMEMORYINFO> (nvapi_QueryInterface(0x774AA982));
nvapi_GPU_GetPCIIdentifiers = reinterpret_cast<QNVAPI_GPU_GETPCIIDENTIFIERS> (nvapi_QueryInterface(0x2DDFB66E));

nvapi_GPU_GetUsages = reinterpret_cast<QNVAPI_GPU_GETUSAGES> (nvapi_QueryInterface(0x189A1FDF));
nvapi_GPU_GetCoolerSettings = reinterpret_cast<QNVAPI_GPU_GETCOOLERSETTINGS> (nvapi_QueryInterface(0xDA141340));

nvapi_GPU_SetCoolerLevels = reinterpret_cast<QNVAPI_GPU_SETCOOLERLEVELS> (nvapi_QueryInterface(0x891FA0AE));
}
}

Expand Down Expand Up @@ -168,12 +168,12 @@ NvAPI_Status QNvAPI::GPU_GetTachReading(NvPhysicalGpuHandle hPhysicalGpu, NvU32*
return status;
}

NvAPI_Status QNvAPI::GPU_GetAllClockFrequencies(__in NvPhysicalGpuHandle hPhysicalGpu, __inout NV_GPU_CLOCK_FREQUENCIES* pClkFreqs)
NvAPI_Status QNvAPI::GPU_GetAllClocks(__in NvPhysicalGpuHandle hPhysicalGpu, __inout NV_GPU_CLOCKS* pClkFreqs)
{
pClkFreqs->version = NV_GPU_CLOCK_FREQUENCIES_VER;
status = nvapi_GPU_GetAllClockFrequencies(hPhysicalGpu, pClkFreqs);
pClkFreqs->version = NV_GPU_CLOCKS_VER;
status = nvapi_GPU_GetAllClocks(hPhysicalGpu, pClkFreqs);
if(status != NVAPI_OK)
qDebug("NvAPI_GPU_GetAllClockFrequencies() failed with status %d", status);
qDebug("NvAPI_GPU_GetAllClocks() failed with status %d", status);
return status;
}

Expand Down Expand Up @@ -245,7 +245,7 @@ bool QNvAPI::isAvailable(void)
nvapi_GPU_GetFullName &&
nvapi_GPU_GetEDID &&
nvapi_GPU_GetTachReading &&
nvapi_GPU_GetAllClockFrequencies &&
nvapi_GPU_GetAllClocks &&
nvapi_GPU_GetPstates20 &&
nvapi_GPU_GetMemoryInfo &&
nvapi_GPU_GetPCIIdentifiers &&
Expand Down
42 changes: 25 additions & 17 deletions platforms/qnvapi/qnvapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@
*
*/

#define NVAPI_MAX_COOLERS_PER_GPU 20
#define NVAPI_MAX_USAGES_PER_GPU 33

#define NV_GPU_USAGES_VER_1 MAKE_NVAPI_VERSION(NV_GPU_USAGES_V1,1)
#define NV_GPU_USAGES_VER NV_GPU_USAGES_VER_1

#define NV_GPU_COOLER_SETTINGS_VER_2 MAKE_NVAPI_VERSION(NV_GPU_COOLER_SETTINGS_V2,2)
#define NV_GPU_COOLER_SETTINGS_VER NV_GPU_COOLER_SETTINGS_VER_2

#define NV_GPU_COOLER_LEVELS_VER_1 MAKE_NVAPI_VERSION(NV_GPU_COOLER_LEVELS_V1,1)
#define NV_GPU_COOLER_LEVELS_VER NV_GPU_COOLER_LEVELS_VER_1

typedef struct {
NvU32 version;
NvU32 usage[NVAPI_MAX_USAGES_PER_GPU];
} NV_GPU_USAGES_V1;
#define NV_GPU_USAGES_VER_1 MAKE_NVAPI_VERSION(NV_GPU_USAGES_V1,1)
typedef NV_GPU_USAGES_V1 NV_GPU_USAGES;
#define NV_GPU_USAGES_VER NV_GPU_USAGES_VER_1


#define NVAPI_MAX_COOLERS_PER_GPU 20
typedef struct {
NvU32 version;
NvU32 count;
Expand All @@ -51,7 +44,10 @@ typedef struct {
NvS32 active;
} cooler[NVAPI_MAX_COOLERS_PER_GPU];
} NV_GPU_COOLER_SETTINGS_V2;
typedef NV_GPU_COOLER_SETTINGS_V2 NV_GPU_COOLER_SETTINGS;
#define NV_GPU_COOLER_SETTINGS_VER_2 MAKE_NVAPI_VERSION(NV_GPU_COOLER_SETTINGS_V2,2)
typedef NV_GPU_COOLER_SETTINGS_V2 NV_GPU_COOLER_SETTINGS;
#define NV_GPU_COOLER_SETTINGS_VER NV_GPU_COOLER_SETTINGS_VER_2


typedef struct {
NvU32 version;
Expand All @@ -60,14 +56,25 @@ typedef struct {
NvS32 policy;
} cooler[NVAPI_MAX_COOLERS_PER_GPU];
} NV_GPU_COOLER_LEVELS_V1;
typedef NV_GPU_COOLER_LEVELS_V1 NV_GPU_COOLER_LEVELS;
#define NV_GPU_COOLER_LEVELS_VER_1 MAKE_NVAPI_VERSION(NV_GPU_COOLER_LEVELS_V1,1)
typedef NV_GPU_COOLER_LEVELS_V1 NV_GPU_COOLER_LEVELS;
#define NV_GPU_COOLER_LEVELS_VER NV_GPU_COOLER_LEVELS_VER_1


typedef struct {
NvU32 version;
NvU32 clock[NVAPI_MAX_GPU_CLOCKS * 9];
} NV_GPU_CLOCKS_V2;
#define NV_GPU_CLOCKS_VER_2 MAKE_NVAPI_VERSION(NV_GPU_CLOCKS_V2,2)
typedef NV_GPU_CLOCKS_V2 NV_GPU_CLOCKS;
#define NV_GPU_CLOCKS_VER NV_GPU_CLOCKS_VER_2


class QNvAPI : public QLibrary
{
public:

#pragma warning(disable : 4351)
//#pragma warning(disable : 4351)
NvAPI_Status status = NVAPI_OK;
NvAPI_ShortString version = {};

Expand All @@ -85,6 +92,7 @@ class QNvAPI : public QLibrary
NV_GPU_THERMAL_SETTINGS thermalSettings;
NV_GPU_COOLER_SETTINGS coolerSettings;
NV_GPU_COOLER_LEVELS coolerLevels;
NV_GPU_CLOCKS clocks;
} NvGPU;
NvGPU gpu[NVAPI_MAX_PHYSICAL_GPUS] = {};

Expand All @@ -106,7 +114,7 @@ class QNvAPI : public QLibrary
NvAPI_Status GPU_GetFullName(NvPhysicalGpuHandle, NvAPI_ShortString);
NvAPI_Status GPU_GetEDID(NvPhysicalGpuHandle, NvU32, NV_EDID*);
NvAPI_Status GPU_GetTachReading(NvPhysicalGpuHandle, NvU32*);
NvAPI_Status GPU_GetAllClockFrequencies(NvPhysicalGpuHandle, NV_GPU_CLOCK_FREQUENCIES*);
NvAPI_Status GPU_GetAllClocks(NvPhysicalGpuHandle, NV_GPU_CLOCKS*);
NvAPI_Status GPU_GetPstates20(NvPhysicalGpuHandle, NV_GPU_PERF_PSTATES20_INFO*);
NvAPI_Status GPU_GetMemoryInfo(NvPhysicalGpuHandle, NV_DISPLAY_DRIVER_MEMORY_INFO*);
NvAPI_Status GPU_GetPCIIdentifiers(NvPhysicalGpuHandle, NvU32*, NvU32*, NvU32*, NvU32*);
Expand Down Expand Up @@ -135,7 +143,7 @@ class QNvAPI : public QLibrary
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETFULLNAME) (NvPhysicalGpuHandle, NvAPI_ShortString);
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETEDID) (NvPhysicalGpuHandle, NvU32, NV_EDID*);
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETTACHREADING) (NvPhysicalGpuHandle, NvU32*);
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETALLCLOCKFREQUENCIES) (NvPhysicalGpuHandle, NV_GPU_CLOCK_FREQUENCIES*);
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETALLCLOCKS) (NvPhysicalGpuHandle, NV_GPU_CLOCKS*);
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETPSTATES20) (NvPhysicalGpuHandle, NV_GPU_PERF_PSTATES20_INFO*);
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETMEMORYINFO) (NvPhysicalGpuHandle, NV_DISPLAY_DRIVER_MEMORY_INFO*);
typedef NvAPI_Status (__cdecl * QNVAPI_GPU_GETPCIIDENTIFIERS) (NvPhysicalGpuHandle, NvU32*, NvU32*, NvU32*, NvU32*);
Expand All @@ -161,7 +169,7 @@ class QNvAPI : public QLibrary
QNVAPI_GPU_GETFULLNAME nvapi_GPU_GetFullName;
QNVAPI_GPU_GETEDID nvapi_GPU_GetEDID;
QNVAPI_GPU_GETTACHREADING nvapi_GPU_GetTachReading;
QNVAPI_GPU_GETALLCLOCKFREQUENCIES nvapi_GPU_GetAllClockFrequencies;
QNVAPI_GPU_GETALLCLOCKS nvapi_GPU_GetAllClocks;
QNVAPI_GPU_GETPSTATES20 nvapi_GPU_GetPstates20;
QNVAPI_GPU_GETMEMORYINFO nvapi_GPU_GetMemoryInfo;
QNVAPI_GPU_GETPCIIDENTIFIERS nvapi_GPU_GetPCIIdentifiers;
Expand Down
31 changes: 25 additions & 6 deletions qutefan/gputab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ GpuTab::GpuTab(QWidget* parent) :
GpuTab::GpuTab(QNvAPI* api, QNvAPI::NvGPU* gpu, QWidget* parent) :
GpuTab(parent)
{
// Hide unfinished UI elements
ui->groupBoxOverclock->hide();
ui->radioButtonGraph->hide();
ui->pushButtonGraph->hide();

mode = AccessMode::nvapi;

nvapi = api;
Expand Down Expand Up @@ -60,8 +65,8 @@ void GpuTab::regulateFan()
nvgpu->status = nvapi->GPU_GetThermalSettings(nvgpu->handle, 0, &nvgpu->thermalSettings);
if(nvMaxTemp < nvgpu->thermalSettings.sensor[0].currentTemp)
nvMaxTemp = nvgpu->thermalSettings.sensor[0].currentTemp;
ui->labelTempValue->setText(QString("%1°C").arg(nvgpu->thermalSettings.sensor[0].currentTemp));
ui->labelTempMax->setText(QString("%1°C").arg(nvMaxTemp));
ui->labelStatusTempCur->setText(QString("%1°C").arg(nvgpu->thermalSettings.sensor[0].currentTemp));
ui->labelStatusTempMax->setText(QString("%1°C").arg(nvMaxTemp));


GpuTab::FanMode mode = getMode();
Expand All @@ -72,6 +77,8 @@ void GpuTab::regulateFan()
NV_GPU_COOLER_LEVELS newCoolerLevels;
newCoolerLevels.cooler[0].policy = 1;
switch(mode) {
case GpuTab::FanMode::Off:
break;
case GpuTab::FanMode::Quiet:
newCoolerLevels.cooler[0].level = nvgpu->coolerSettings.cooler[0].defaultMin;
break;
Expand All @@ -90,8 +97,20 @@ void GpuTab::regulateFan()


nvgpu->status = nvapi->GPU_GetCoolerSettings(nvgpu->handle, 0, &nvgpu->coolerSettings);
if(nvMaxLevel < nvgpu->coolerSettings.cooler[0].currentLevel)
nvMaxLevel = nvgpu->coolerSettings.cooler[0].currentLevel;
ui->labelLevelValue->setText(QString("%1%").arg(nvgpu->coolerSettings.cooler[0].currentLevel));
ui->labelLevelMax->setText(QString("%1%").arg(nvMaxLevel));
if(nvMaxFan < nvgpu->coolerSettings.cooler[0].currentLevel)
nvMaxFan = nvgpu->coolerSettings.cooler[0].currentLevel;
ui->labelStatusFanCur->setText(QString("%1%").arg(nvgpu->coolerSettings.cooler[0].currentLevel));
ui->labelStatusFanMax->setText(QString("%1%").arg(nvMaxFan));
}

void GpuTab::displayStatus()
{
nvgpu->status = nvapi->GPU_GetAllClocks(nvgpu->handle, &nvgpu->clocks);

// for(int i=0; i < NVAPI_MAX_GPU_CLOCKS * 9; i++ )
// qDebug("clock[%d] = %d", i , nvgpu->clocks.clock[i]);

ui->labelStatusCoreCur->setText(QString("%1Mhz").arg(nvgpu->clocks.clock[30]/2000.0f, 0, 'f', 1));
ui->labelStatusMemCur->setText(QString("%1Mhz").arg(nvgpu->clocks.clock[8]/2000.0f, 0, 'f', 1));
ui->labelStatusShaderCur->setText(QString("%1Mhz").arg(nvgpu->clocks.clock[30]/1000.0f, 0, 'f', 1));
}
3 changes: 2 additions & 1 deletion qutefan/gputab.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GpuTab : public QWidget

void setGPUDefaults();
void regulateFan();
void displayStatus();

private:
GpuTab::FanMode getMode();
Expand All @@ -47,7 +48,7 @@ class GpuTab : public QWidget
QNvAPI::NvGPU* nvgpu;
NV_GPU_COOLER_LEVELS nvDefaultCoolerLevels;
NvS32 nvMaxTemp;
NvS32 nvMaxLevel;
NvS32 nvMaxFan;
};

#endif // GPUTAB_H
Loading

0 comments on commit 1a87afa

Please sign in to comment.