more amd functionality

This commit is contained in:
jussi 2019-02-14 22:17:02 +02:00
parent 30459629f1
commit 3bc366a7da
3 changed files with 45 additions and 19 deletions

49
amd.cpp
View File

@ -28,8 +28,7 @@ bool amd::setupGPU()
uint32_t major = 0; uint32_t major = 0;
uint32_t minor = 0; uint32_t minor = 0;
amdgpu_device_handle handle; amdgpu_device_handle handle;
dev = &handle; int ret = amdgpu_device_initialize(fd, &major, &minor, &handle);
int ret = amdgpu_device_initialize(fd, &major, &minor, dev);
qDebug() << major; qDebug() << major;
if (ret > -1) { if (ret > -1) {
// Create a gpu object with the correct paremeters // Create a gpu object with the correct paremeters
@ -37,7 +36,7 @@ bool amd::setupGPU()
gpu.fsindex = i; gpu.fsindex = i;
gpu.gputype = Type::AMDGPU; gpu.gputype = Type::AMDGPU;
// Get the hwmon folder name // Get the hwmon folder name
QString monpath = "/sys/class/drm/card0/device/hwmon"; QString monpath = "/sys/class/drm/card"+QString::number(i)+"/device/hwmon";
QDir mondir(monpath); QDir mondir(monpath);
qDebug() << mondir.entryList() << "mondir"; qDebug() << mondir.entryList() << "mondir";
QStringList list = mondir.entryList(); QStringList list = mondir.entryList();
@ -50,11 +49,13 @@ bool amd::setupGPU()
} }
} }
const char *name = amdgpu_get_marketing_name(*dev); const char *name = amdgpu_get_marketing_name(handle);
char tempname[64]; char tempname[64];
strcpy(tempname, name); strcpy(tempname, name);
gpu.name = tempname; gpu.name = tempname;
gpu.dev = &handle;
qDebug() << gpu.name; qDebug() << gpu.name;
gpuCount++;
GPUList.append(gpu); GPUList.append(gpu);
retb = true; retb = true;
@ -79,17 +80,39 @@ void amd::queryGPUNames()
/*for (int i=0; i<GPUList.size(); i++) { /*for (int i=0; i<GPUList.size(); i++) {
if (GPUList[i].gputype == Type::AMDGPU) { if (GPUList[i].gputype == Type::AMDGPU) {
const char *name; const char *name;
name = amdgpu_get_marketing_name(*dev); name = amdgpu_get_marketing_name(*GPUList[GPUIndex].dev);
//strcpy(GPUList[i].name, name); //strcpy(GPUList[i].name, name);
qDebug() << name; qDebug() << name;
} }
}*/ }*/
} }
void amd::queryGPUUIDs(){} void amd::queryGPUUIDs(){}
void amd::queryGPUFeatures(){} void amd::queryGPUFeatures()
{
// Read the pp_od_clk_voltage file and parse output
QRegularExpression numexp("\\d+\\d");
int type = 0;
int breakcount = 0;
for (int i=0; i<gpuCount; i++) {
QString path;
QString line;
if (GPUList[i].gputype == Type::AMDGPU) {
path = "/sys/class/drm/card"+QString::number(GPUList[i].fsindex)+"/device/pp_od_clk_voltage";
QFile tablefile(path);
bool ret = tablefile.open(QFile::ReadOnly | QFile::Text);
if (ret) {
QTextStream str(&tablefile);
while (!str.atEnd() && breakcount < 30) {
breakcount++;
}
tablefile.close();
}
}
}
}
void amd::queryGPUVoltage(int GPUIndex) void amd::queryGPUVoltage(int GPUIndex)
{ {
int ret = amdgpu_query_sensor_info(*dev, int ret = amdgpu_query_sensor_info(*GPUList[GPUIndex].dev,
AMDGPU_INFO_SENSOR_VDDGFX, AMDGPU_INFO_SENSOR_VDDGFX,
sizeof (GPUList[GPUIndex].voltage), sizeof (GPUList[GPUIndex].voltage),
&GPUList[GPUIndex].voltage); &GPUList[GPUIndex].voltage);
@ -97,7 +120,7 @@ void amd::queryGPUVoltage(int GPUIndex)
} }
void amd::queryGPUTemp(int GPUIndex) void amd::queryGPUTemp(int GPUIndex)
{ {
int ret = amdgpu_query_sensor_info(*dev, int ret = amdgpu_query_sensor_info(*GPUList[GPUIndex].dev,
AMDGPU_INFO_SENSOR_GPU_TEMP, AMDGPU_INFO_SENSOR_GPU_TEMP,
sizeof (GPUList[GPUIndex].temp), sizeof (GPUList[GPUIndex].temp),
&GPUList[GPUIndex].temp); &GPUList[GPUIndex].temp);
@ -105,13 +128,13 @@ void amd::queryGPUTemp(int GPUIndex)
} }
void amd::queryGPUFrequencies(int GPUIndex) void amd::queryGPUFrequencies(int GPUIndex)
{ {
int ret = amdgpu_query_sensor_info(*dev, int ret = amdgpu_query_sensor_info(*GPUList[GPUIndex].dev,
AMDGPU_INFO_SENSOR_GFX_SCLK, AMDGPU_INFO_SENSOR_GFX_SCLK,
sizeof (GPUList[GPUIndex].coreFreq), sizeof (GPUList[GPUIndex].coreFreq),
&GPUList[GPUIndex].coreFreq); &GPUList[GPUIndex].coreFreq);
if (ret < 0) qDebug("Failed to query GPU core clock"); if (ret < 0) qDebug("Failed to query GPU core clock");
ret = amdgpu_query_sensor_info(*dev, ret = amdgpu_query_sensor_info(*GPUList[GPUIndex].dev,
AMDGPU_INFO_SENSOR_GFX_MCLK, AMDGPU_INFO_SENSOR_GFX_MCLK,
sizeof (GPUList[GPUIndex].memFreq), sizeof (GPUList[GPUIndex].memFreq),
&GPUList[GPUIndex].memFreq); &GPUList[GPUIndex].memFreq);
@ -136,7 +159,7 @@ void amd::queryGPUVoltageOffset(int GPUIndex){}
void amd::queryGPUUtils(int GPUIndex) void amd::queryGPUUtils(int GPUIndex)
{ {
int ret = amdgpu_query_sensor_info(*dev, int ret = amdgpu_query_sensor_info(*GPUList[GPUIndex].dev,
AMDGPU_INFO_SENSOR_GPU_LOAD, AMDGPU_INFO_SENSOR_GPU_LOAD,
sizeof (GPUList[GPUIndex].coreUtil), sizeof (GPUList[GPUIndex].coreUtil),
&GPUList[GPUIndex].coreUtil); &GPUList[GPUIndex].coreUtil);
@ -144,7 +167,7 @@ void amd::queryGPUUtils(int GPUIndex)
} }
void amd::queryGPUPowerDraw(int GPUIndex) void amd::queryGPUPowerDraw(int GPUIndex)
{ {
int ret = amdgpu_query_sensor_info(*dev, int ret = amdgpu_query_sensor_info(*GPUList[GPUIndex].dev,
AMDGPU_INFO_SENSOR_GPU_AVG_POWER, AMDGPU_INFO_SENSOR_GPU_AVG_POWER,
sizeof (GPUList[GPUIndex].powerDraw), sizeof (GPUList[GPUIndex].powerDraw),
&GPUList[GPUIndex].powerDraw); &GPUList[GPUIndex].powerDraw);
@ -182,7 +205,7 @@ void amd::queryGPUPowerLimitLimits(int GPUIndex)
void amd::queryGPUCurrentMaxClocks(int GPUIndex) void amd::queryGPUCurrentMaxClocks(int GPUIndex)
{ {
amdgpu_gpu_info info; amdgpu_gpu_info info;
int ret = amdgpu_query_gpu_info(*dev, &info); int ret = amdgpu_query_gpu_info(*GPUList[GPUIndex].dev, &info);
if (ret < 0) qDebug("Failed to query GPU maximum clocks"); if (ret < 0) qDebug("Failed to query GPU maximum clocks");
else { else {
uint clock = static_cast<uint>(info.max_engine_clk); uint clock = static_cast<uint>(info.max_engine_clk);

View File

@ -17,6 +17,7 @@
#include <libdrm/amdgpu.h> #include <libdrm/amdgpu.h>
#include <xf86drm.h> #include <xf86drm.h>
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include <QRegularExpressionMatchIterator>
#endif #endif
class gputypes : public QObject class gputypes : public QObject
@ -67,11 +68,14 @@ public:
int totalVRAM; int totalVRAM;
int usedVRAM; int usedVRAM;
#ifdef AMD
// AMD only: // AMD only:
// GPU index in the filesystem eg. card0 // GPU index in the filesystem eg. card0
int fsindex; int fsindex;
// name of the folder in /sys/class/drm/card(n)/device/hwmon // name of the folder in /sys/class/drm/card(n)/device/hwmon
QString hwmonpath; QString hwmonpath;
amdgpu_device_handle *dev;
#endif
}; };
QVector <GPU> GPUList; QVector <GPU> GPUList;
@ -81,9 +85,7 @@ public:
nvmlDevice_t *device; nvmlDevice_t *device;
#endif #endif
#ifdef AMD
amdgpu_device_handle *dev;
#endif
virtual bool setupGPU() = 0; virtual bool setupGPU() = 0;
virtual bool setupGPUSecondary(int GPUIndex) = 0; virtual bool setupGPUSecondary(int GPUIndex) = 0;

View File

@ -30,7 +30,7 @@ MainWindow::MainWindow(QWidget *parent) :
// This is for libxnvctrl // This is for libxnvctrl
types->setupGPU(); types->setupGPU();
// This is for NVML // This is for NVML
/*types->setupGPUSecondary(currentGPUIndex); types->setupGPUSecondary(currentGPUIndex);
types->queryGPUFeatures(); types->queryGPUFeatures();
types->queryGPUFreqOffset(currentGPUIndex); types->queryGPUFreqOffset(currentGPUIndex);
types->queryGPUMemClkOffset(currentGPUIndex); types->queryGPUMemClkOffset(currentGPUIndex);
@ -43,10 +43,11 @@ MainWindow::MainWindow(QWidget *parent) :
for (int i=0; i<types->gpuCount; i++) { for (int i=0; i<types->gpuCount; i++) {
ui->GPUComboBox->addItem("GPU-" + QString::number(i) + ": " + types->GPUList[i].name); ui->GPUComboBox->addItem("GPU-" + QString::number(i) + ": " + types->GPUList[i].name);
} }
/*
loadProfileSettings(); loadProfileSettings();
setupMonitorTab(); setupMonitorTab();
setupGraphMonitorTab(); setupGraphMonitorTab();
*/
// Enable sliders according to GPU properties // Enable sliders according to GPU properties
if (types->GPUList[currentGPUIndex].overClockAvailable) { if (types->GPUList[currentGPUIndex].overClockAvailable) {
@ -118,7 +119,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->voltageSpinBox, SIGNAL(valueChanged(int)), SLOT(resetTimer())); connect(ui->voltageSpinBox, SIGNAL(valueChanged(int)), SLOT(resetTimer()));
connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHandler(int))); connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHandler(int)));
connect(monitorUpdater, SIGNAL(timeout()), SLOT(updateMonitor()));*/ connect(monitorUpdater, SIGNAL(timeout()), SLOT(updateMonitor()));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()