more amd functionality

This commit is contained in:
jussi 2019-02-14 16:36:10 +02:00
parent 41438d23b4
commit 30459629f1
2 changed files with 73 additions and 7 deletions

78
amd.cpp
View File

@ -36,16 +36,39 @@ bool amd::setupGPU()
GPU gpu;
gpu.fsindex = i;
gpu.gputype = Type::AMDGPU;
// Get the hwmon folder name
QString monpath = "/sys/class/drm/card0/device/hwmon";
QDir mondir(monpath);
qDebug() << mondir.entryList() << "mondir";
QStringList list = mondir.entryList();
for (int i=0; i<list.size(); i++) {
if (list[i].contains("hwmon")) {
qDebug() << list[i];
gpu.hwmonpath = monpath+"/"+list[i];
qDebug() << gpu.hwmonpath;
break;
}
}
const char *name = amdgpu_get_marketing_name(*dev);
char tempname[64];
strcpy(tempname, name);
gpu.name = tempname;
qDebug() << gpu.name;
GPUList.append(gpu);
retb = true;
}
}
}
if (!retb) {
qDebug("No AMD GPUs using amdgpu found");
} else {
queryGPUNames();
queryGPUTemp(0);
queryGPUPowerLimit(0);
queryGPUFanSpeed(0);
queryGPUPowerLimitLimits(0);
}
return retb;
}
@ -53,14 +76,14 @@ bool amd::setupGPUSecondary(int GPUIndex){return true;}
void amd::queryGPUCount(){}
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) {
const char *name;
name = amdgpu_get_marketing_name(*dev);
//strcpy(GPUList[i].name, name);
qDebug() << name;
}
}
}*/
}
void amd::queryGPUUIDs(){}
void amd::queryGPUFeatures(){}
@ -94,7 +117,18 @@ void amd::queryGPUFrequencies(int GPUIndex)
&GPUList[GPUIndex].memFreq);
if (ret < 0) qDebug("Failed to query GPU memory clock");
}
void amd::queryGPUFanSpeed(int GPUIndex){}
void amd::queryGPUFanSpeed(int GPUIndex)
{
QFile pwmfile(GPUList[GPUIndex].hwmonpath+"/pwm1");
bool ret = pwmfile.open(QFile::ReadOnly | QFile::Text);
if (ret) {
QString fanspeed = pwmfile.readLine().trimmed();
double percspeed = (fanspeed.toDouble()/255)*100;
GPUList[GPUIndex].fanSpeed = static_cast<int>(percspeed);
qDebug() << GPUList[GPUIndex].fanSpeed << "fanspeed";
}
else qDebug("Failed to query fan speed");
}
void amd::queryGPUUsedVRAM(int GPUIndex){}
void amd::queryGPUFreqOffset(int GPUIndex){}
void amd::queryGPUMemClkOffset(int GPUIndex){}
@ -116,8 +150,35 @@ void amd::queryGPUPowerDraw(int GPUIndex)
&GPUList[GPUIndex].powerDraw);
if (ret < 0) qDebug("failed to query GPU power draw");
}
void amd::queryGPUPowerLimit(int GPUIndex){}
void amd::queryGPUPowerLimitLimits(int GPUIndex){}
void amd::queryGPUPowerLimit(int GPUIndex)
{
QFile pcapfile(GPUList[GPUIndex].hwmonpath+"/power1_cap");
bool ret = pcapfile.open(QFile::ReadOnly | QFile::Text);
if (ret) {
QString pcap = pcapfile.readLine();
GPUList[GPUIndex].powerLim = static_cast<uint>(pcap.toInt()/1000000);
qDebug() << GPUList[GPUIndex].powerLim << "current power limit";
}
else qDebug("Failed to query power limit");
}
void amd::queryGPUPowerLimitLimits(int GPUIndex)
{
QFile maxpcapfile(GPUList[GPUIndex].hwmonpath+"/power1_cap_max");
bool ret = maxpcapfile.open(QFile::ReadOnly | QFile::Text);
if (ret) {
QString maxpcap = maxpcapfile.readLine();
GPUList[GPUIndex].maxPowerLim = static_cast<uint>(maxpcap.toInt()/1000000);
qDebug() << GPUList[GPUIndex].maxPowerLim << "max power limit";
}
QFile mincapfile(GPUList[GPUIndex].hwmonpath+"/power1_cap_min");
ret = mincapfile.open(QFile::ReadOnly | QFile::Text);
if (ret) {
QString minpcap = mincapfile.readLine();
GPUList[GPUIndex].minPowerLim = static_cast<uint>(minpcap.toInt()/1000000);
qDebug() << GPUList[GPUIndex].minPowerLim << "min power limit";
}
}
void amd::queryGPUCurrentMaxClocks(int GPUIndex)
{
amdgpu_gpu_info info;
@ -134,7 +195,10 @@ void amd::queryGPUCurrentMaxClocks(int GPUIndex)
void amd::queryGPUPowerLimitAvailability(int GPUIndex){}
bool amd::assignGPUFanSpeed(int GPUIndex, int targetValue){}
bool amd::assignGPUFanCtlMode(int GPUIndex, bool manual){}
bool amd::assignGPUFanCtlMode(int GPUIndex, bool manual)
{
}
bool amd::assignGPUFreqOffset(int GPUIndex, int targetValue){}
bool amd::assignGPUMemClockOffset(int GPUIndex, int targetValue){}
bool amd::assignGPUVoltageOffset(int GPUIndex, int targetValue){}

View File

@ -70,6 +70,8 @@ public:
// AMD only:
// GPU index in the filesystem eg. card0
int fsindex;
// name of the folder in /sys/class/drm/card(n)/device/hwmon
QString hwmonpath;
};
QVector <GPU> GPUList;