mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-25 18:55:24 -06:00
start adding NVXCtrl code
This commit is contained in:
parent
a2e56302db
commit
57017386a3
@ -5,6 +5,7 @@
|
||||
#include "newprofile.h"
|
||||
#include "monitor.h"
|
||||
#include "plotwidget.h"
|
||||
#include "nvidia.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
@ -59,6 +60,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
|
||||
connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHandler(int)));
|
||||
connect(monitorUpdater, SIGNAL(timeout()), SLOT(updateMonitor()));
|
||||
|
||||
nvidia nv;
|
||||
nv.setupXNVCtrl();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
177
nvidia.cpp
Normal file
177
nvidia.cpp
Normal file
@ -0,0 +1,177 @@
|
||||
#include "nvidia.h"
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "NVCtrl/NVCtrlLib.h"
|
||||
|
||||
nvidia::nvidia(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
bool nvidia::setupXNVCtrl()
|
||||
{
|
||||
// Open the x-server connection and check if the extension exists
|
||||
dpy = XOpenDisplay(nullptr);
|
||||
Bool ret;
|
||||
int *event_basep = nullptr;
|
||||
int *error_basep = nullptr;
|
||||
|
||||
ret = XNVCTRLQueryExtension(dpy,
|
||||
event_basep,
|
||||
error_basep);
|
||||
qDebug() << ret;
|
||||
|
||||
queryGPUCount();
|
||||
queryGPUNames();
|
||||
queryGPUUIDs();
|
||||
queryGPUFeatures();
|
||||
return ret;
|
||||
}
|
||||
void nvidia::queryGPUCount()
|
||||
{
|
||||
Bool ret;
|
||||
ret = XNVCTRLQueryTargetCount(dpy, NV_CTRL_TARGET_TYPE_GPU, &gpuCount);
|
||||
if (!ret) {
|
||||
qDebug() << "Failed to query amount of GPUs";
|
||||
}
|
||||
// Create an appropriate number of GPU objects
|
||||
for (int i=0; i<gpuCount; i++) {
|
||||
GPU gpu;
|
||||
GPUList.append(gpu);
|
||||
}
|
||||
qDebug() << gpuCount;
|
||||
}
|
||||
void nvidia::queryGPUNames()
|
||||
{
|
||||
Bool ret;
|
||||
for (int i=0; i<gpuCount; i++) {
|
||||
ret = XNVCTRLQueryTargetStringAttribute(dpy,
|
||||
NV_CTRL_TARGET_TYPE_GPU,
|
||||
i,
|
||||
0,
|
||||
NV_CTRL_STRING_PRODUCT_NAME,
|
||||
&GPUList[i].name);
|
||||
if (!ret) {
|
||||
qDebug() << "Failed to query GPU Name";
|
||||
}
|
||||
qDebug() << GPUList[i].name;
|
||||
}
|
||||
}
|
||||
void nvidia::queryGPUUIDs()
|
||||
{
|
||||
Bool ret;
|
||||
for (int i=0; i<gpuCount; i++) {
|
||||
ret = XNVCTRLQueryTargetStringAttribute(dpy,
|
||||
NV_CTRL_TARGET_TYPE_GPU,
|
||||
i,
|
||||
0,
|
||||
NV_CTRL_STRING_GPU_UUID,
|
||||
&GPUList[i].uuid);
|
||||
if (!ret) {
|
||||
qDebug() << "Failed to query GPU UUID";
|
||||
}
|
||||
qDebug() << GPUList[i].uuid;
|
||||
}
|
||||
}
|
||||
void nvidia::queryGPUFeatures()
|
||||
{
|
||||
// Query static features related to the GPU such as maximum offsets here
|
||||
Bool ret;
|
||||
NVCTRLAttributeValidValuesRec values;
|
||||
for (int i=0; i<gpuCount; i++) {
|
||||
ret = XNVCTRLQueryValidTargetAttributeValues(dpy,
|
||||
NV_CTRL_TARGET_TYPE_GPU,
|
||||
i,
|
||||
0,
|
||||
NV_CTRL_GPU_OVER_VOLTAGE_OFFSET,
|
||||
&values);
|
||||
qDebug() << values.u.range.max << values.permissions << "value";
|
||||
|
||||
GPUList[i].maxVoltageOffset = values.u.range.max;
|
||||
}
|
||||
|
||||
queryGPUVoltage(0);
|
||||
queryGPUTemp(0);
|
||||
queryGPUFrequency(0);
|
||||
queryGPUFanSpeed(0);
|
||||
//assignFanSpeed(0, 60);
|
||||
}
|
||||
void nvidia::queryGPUVoltage(int GPUIndex)
|
||||
{
|
||||
Bool ret;
|
||||
ret = XNVCTRLQueryTargetAttribute(dpy,
|
||||
NV_CTRL_TARGET_TYPE_GPU,
|
||||
GPUIndex,
|
||||
0,
|
||||
NV_CTRL_GPU_CURRENT_CORE_VOLTAGE,
|
||||
&GPUList[GPUIndex].voltage);
|
||||
if (!ret) {
|
||||
qDebug() << "Couldn't query voltage for GPU";
|
||||
}
|
||||
qDebug() << GPUList[GPUIndex].voltage;
|
||||
}
|
||||
void nvidia::queryGPUTemp(int GPUIndex)
|
||||
{
|
||||
Bool ret;
|
||||
ret = XNVCTRLQueryTargetAttribute(dpy,
|
||||
NV_CTRL_TARGET_TYPE_THERMAL_SENSOR,
|
||||
GPUIndex,
|
||||
0,
|
||||
NV_CTRL_THERMAL_SENSOR_READING,
|
||||
&GPUList[GPUIndex].temp);
|
||||
qDebug() << GPUList[GPUIndex].temp;
|
||||
}
|
||||
void nvidia::queryGPUFrequency(int GPUIndex)
|
||||
{
|
||||
Bool ret;
|
||||
int packedInt = 0;
|
||||
int mem = 0;
|
||||
int core = 0;
|
||||
ret = XNVCTRLQueryTargetAttribute(dpy,
|
||||
NV_CTRL_TARGET_TYPE_GPU,
|
||||
GPUIndex,
|
||||
0,
|
||||
NV_CTRL_GPU_CURRENT_CLOCK_FREQS,
|
||||
&packedInt);
|
||||
// The function returns a 32-bit packed integer, GPU Clock is the upper 16 and Memory Clock lower 16
|
||||
mem = (packedInt) & 0xFFFF;
|
||||
core = (packedInt & (0xFFFF << (32 - 16))) >> (32 - 16);
|
||||
qDebug() << GPUList[GPUIndex].coreFreq << "freq" << core << mem;
|
||||
GPUList[GPUIndex].coreFreq = core;
|
||||
GPUList[GPUIndex].memFreq = mem;
|
||||
}
|
||||
void nvidia::queryGPUFanSpeed(int GPUIndex)
|
||||
{
|
||||
Bool ret;
|
||||
ret = XNVCTRLQueryTargetAttribute(dpy,
|
||||
NV_CTRL_TARGET_TYPE_COOLER,
|
||||
GPUIndex,
|
||||
0,
|
||||
NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL,
|
||||
&GPUList[GPUIndex].fanSpeed);
|
||||
|
||||
qDebug() << GPUList[GPUIndex].fanSpeed;
|
||||
}
|
||||
bool nvidia::assignFanSpeed(int GPUIndex, int targetValue)
|
||||
{
|
||||
Bool ret;
|
||||
ret = XNVCTRLSetTargetAttributeAndGetStatus(dpy,
|
||||
NV_CTRL_TARGET_TYPE_COOLER,
|
||||
GPUIndex,
|
||||
0,
|
||||
NV_CTRL_THERMAL_COOLER_LEVEL,
|
||||
targetValue);
|
||||
return ret;
|
||||
}
|
||||
/*bool nvidia::setup()
|
||||
{
|
||||
dpy = XOpenDisplay(nullptr);
|
||||
int *temp;
|
||||
XNVCTRLQueryTargetAttribute(dpy,
|
||||
NV_CTRL_TARGET_TYPE_THERMAL_SENSOR,
|
||||
0,
|
||||
0,
|
||||
NV_CTRL_THERMAL_SENSOR_READING,
|
||||
temp);
|
||||
qDebug() << temp;
|
||||
return true;
|
||||
}*/
|
51
nvidia.h
Normal file
51
nvidia.h
Normal file
@ -0,0 +1,51 @@
|
||||
#ifndef NVIDIA_H
|
||||
#define NVIDIA_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QtX11Extras/QX11Info>
|
||||
|
||||
class nvidia : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit nvidia(QObject *parent = nullptr);
|
||||
|
||||
struct GPU
|
||||
{
|
||||
bool status;
|
||||
int index;
|
||||
char *name;
|
||||
char *uuid;
|
||||
bool overVoltAvailable;
|
||||
bool overClockAvailable;
|
||||
int maxVoltageOffset;
|
||||
|
||||
int coreFreq;
|
||||
int memFreq;
|
||||
int temp;
|
||||
int voltage;
|
||||
int fanSpeed;
|
||||
};
|
||||
QVector <GPU> GPUList;
|
||||
int gpuCount = 0;
|
||||
private:
|
||||
Display *dpy;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
bool setupXNVCtrl();
|
||||
void queryGPUCount();
|
||||
void queryGPUNames();
|
||||
void queryGPUUIDs();
|
||||
void queryGPUFeatures();
|
||||
void queryGPUVoltage(int GPUIndex);
|
||||
void queryGPUTemp(int GPUIndex);
|
||||
void queryGPUFrequency(int GPUIndex);
|
||||
void queryGPUFanSpeed(int GPUIndex);
|
||||
|
||||
bool assignFanSpeed(int GPUIndex, int targetValue);
|
||||
private slots:
|
||||
};
|
||||
|
||||
#endif // NVIDIA_H
|
@ -34,7 +34,7 @@ SOURCES += \
|
||||
newprofile.cpp \
|
||||
monitor.cpp \
|
||||
plotwidget.cpp \
|
||||
#nvidia.cpp
|
||||
nvidia.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@ -43,16 +43,16 @@ HEADERS += \
|
||||
newprofile.h \
|
||||
monitor.h \
|
||||
plotwidget.h \
|
||||
#nvidia.h
|
||||
nvidia.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui \
|
||||
editprofile.ui \
|
||||
newprofile.ui
|
||||
|
||||
#INCLUDEPATH += "/usr/lib"
|
||||
INCLUDEPATH += "/usr/lib"
|
||||
|
||||
#LIBS += -lXext -lXNVCtrl -lX11
|
||||
LIBS += -lXext -lXNVCtrl -lX11
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
|
Loading…
Reference in New Issue
Block a user