Save pstates after applying

This commit is contained in:
jussi 2019-03-12 13:57:07 +02:00
parent fd1fab275b
commit cbdfe7a6a9
7 changed files with 95 additions and 13 deletions

12
amd.cpp
View File

@ -1,6 +1,7 @@
#ifdef AMD #ifdef AMD
#include "gputypes.h" #include "gputypes.h"
#include <tgmath.h> #include <tgmath.h>
#include <QThread>
amd::amd() {} amd::amd() {}
bool amd::setupGPU() bool amd::setupGPU()
@ -244,10 +245,12 @@ QString amd::applySettings(int GPUIndex)
cmd.append("\""); cmd.append("\"");
proc.start(cmd); proc.start(cmd);
proc.waitForFinished(-1); proc.waitForFinished(-1);
QThread::msleep(200);
// If fan mode was changed, check if it was successful // If fan mode was changed, check if it was successful
if (fanModeComboBox->currentIndex() != GPUList[GPUIndex].fanControlMode) { if (fanModeComboBox->currentIndex() != GPUList[GPUIndex].fanControlMode) {
queryGPUFanCtlMode(GPUIndex); queryGPUFanCtlMode(GPUIndex);
qDebug() << "checking combo box" << fanModeComboBox->currentIndex() << GPUList[GPUIndex].fanControlMode;
if (fanModeComboBox->currentIndex() != GPUList[GPUIndex].fanControlMode) { if (fanModeComboBox->currentIndex() != GPUList[GPUIndex].fanControlMode) {
hadErrors = true; hadErrors = true;
errStr.append("Fan mode, "); errStr.append("Fan mode, ");
@ -255,6 +258,15 @@ QString amd::applySettings(int GPUIndex)
} }
} }
// Power limit // Power limit
if (powerLimSlider->value() != latestpowerLimSlider) {
queryGPUPowerLimit(GPUIndex);
if (powerLimSlider->value() * 1000000 != static_cast<int>(GPUList[GPUIndex].powerLim)) {
hadErrors = true;
errStr.append("Power Limit, ");
} else {
latestpowerLimSlider = powerLimSlider->value();
}
}
if (hadErrors) { if (hadErrors) {
errStr.chop(2); errStr.chop(2);

View File

@ -120,13 +120,23 @@ void amdPstateEditor::generateUI(gputypes *newtypes, int GPUIndex)
buttonwidget->setLayout(buttonlo); buttonwidget->setLayout(buttonlo);
llo->addWidget(buttonwidget); llo->addWidget(buttonwidget);
QStatusBar *statusbar = new QStatusBar;
statusBar = statusbar;
QWidget *barwdg = new QWidget;
QVBoxLayout *barlo = new QVBoxLayout;
barlo->addWidget(statusbar);
barwdg->setLayout(barlo);
lower->setLayout(llo); lower->setLayout(llo);
upper->setLayout(ulo); upper->setLayout(ulo);
QVBoxLayout *mainlo = new QVBoxLayout; QVBoxLayout *mainlo = new QVBoxLayout;
mainlo->addWidget(upper); mainlo->addWidget(upper);
mainlo->addWidget(lower); mainlo->addWidget(lower);
mainlo->addWidget(barwdg);
ui->centralWidget->setLayout(mainlo); ui->centralWidget->setLayout(mainlo);
//statusbar->showMessage("test");
} }
bool amdPstateEditor::applyValues() bool amdPstateEditor::applyValues()
{ {
@ -135,11 +145,12 @@ bool amdPstateEditor::applyValues()
QString volt; QString volt;
QString freq; QString freq;
QString cmd = "pkexec /bin/sh -c \""; QString cmd = "pkexec /bin/sh -c \"";
bool changedState = false; // Vector for saving what got applied
QVector <int> changedMemPstates, changedCorePstates;
// Apply core pstates // Apply core pstates
for (int i=0; i<corePstates.size(); i++) { for (int i=0; i<corePstates.size(); i++) {
if ((corePstates[i].freqspinbox->value() != types->GPUList[gpuidx].coreclocks[i]) || (corePstates[i].voltspinbox->value() != types->GPUList[gpuidx].corevolts[i])) { if ((corePstates[i].freqspinbox->value() != types->GPUList[gpuidx].coreclocks[i]) || (corePstates[i].voltspinbox->value() != types->GPUList[gpuidx].corevolts[i])) {
changedState = true; changedCorePstates.append(i);
volt = QString::number(corePstates[i].voltspinbox->value()); volt = QString::number(corePstates[i].voltspinbox->value());
freq = QString::number(corePstates[i].freqspinbox->value()); freq = QString::number(corePstates[i].freqspinbox->value());
cmd.append("echo 's "+ QString::number(i) + " "+ freq +" "+ volt +"' "+"> /sys/class/drm/card"+QString::number(types->GPUList[gpuidx].fsindex)+"/device/pp_od_clk_voltage & "); cmd.append("echo 's "+ QString::number(i) + " "+ freq +" "+ volt +"' "+"> /sys/class/drm/card"+QString::number(types->GPUList[gpuidx].fsindex)+"/device/pp_od_clk_voltage & ");
@ -149,20 +160,34 @@ bool amdPstateEditor::applyValues()
// Apply memory pstates // Apply memory pstates
for (int i=0; i<memPstates.size(); i++) { for (int i=0; i<memPstates.size(); i++) {
if ((memPstates[i].freqspinbox->value() != types->GPUList[gpuidx].memclocks[i]) || (memPstates[i].voltspinbox->value() != types->GPUList[gpuidx].memvolts[i])) { if ((memPstates[i].freqspinbox->value() != types->GPUList[gpuidx].memclocks[i]) || (memPstates[i].voltspinbox->value() != types->GPUList[gpuidx].memvolts[i])) {
changedState = true; changedMemPstates.append(i);
volt = QString::number(memPstates[i].voltspinbox->value()); volt = QString::number(memPstates[i].voltspinbox->value());
freq = QString::number(memPstates[i].freqspinbox->value()); freq = QString::number(memPstates[i].freqspinbox->value());
cmd.append("echo 'm "+ QString::number(i) + " "+ freq +" "+ volt +"' "+"> /sys/class/drm/card"+QString::number(types->GPUList[gpuidx].fsindex)+"/device/pp_od_clk_voltage & "); cmd.append("echo 'm "+ QString::number(i) + " "+ freq +" "+ volt +"' "+"> /sys/class/drm/card"+QString::number(types->GPUList[gpuidx].fsindex)+"/device/pp_od_clk_voltage & ");
qDebug() << cmd; qDebug() << cmd;
} }
} }
if (changedState) { if (!changedMemPstates.isEmpty() || !changedCorePstates.isEmpty()) {
cmd.append("\""); cmd.append("\"");
proc.start(cmd); proc.start(cmd);
proc.waitForFinished(-1); proc.waitForFinished(-1);
if (proc.exitCode() != 0) return false; if (proc.exitCode() != 0) {
statusBar->showMessage("Failed to apply changes.");
return false;
}
}
// Save the values if it was successful
for (int i=0; i<changedMemPstates.size(); i++) {
types->GPUList[gpuidx].memclocks[changedMemPstates[i]] = memPstates[changedMemPstates[i]].freqspinbox->value();
types->GPUList[gpuidx].memvolts[changedMemPstates[i]] = memPstates[changedMemPstates[i]].voltspinbox->value();
} }
for (int i=0; i<changedCorePstates.size(); i++) {
types->GPUList[gpuidx].coreclocks[changedCorePstates[i]] = corePstates[changedCorePstates[i]].freqspinbox->value();
types->GPUList[gpuidx].corevolts[changedCorePstates[i]] = corePstates[changedCorePstates[i]].voltspinbox->value();
}
statusBar->showMessage("Changes applied.");
return true; return true;
} }
bool amdPstateEditor::resetPstates() bool amdPstateEditor::resetPstates()

View File

@ -10,6 +10,7 @@
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include <QProcess> #include <QProcess>
#include <QStatusBar>
#include "gputypes.h" #include "gputypes.h"
namespace Ui { namespace Ui {
@ -39,6 +40,7 @@ private:
}; };
QVector <corePstate> corePstates; QVector <corePstate> corePstates;
QVector <memPstate> memPstates; QVector <memPstate> memPstates;
QStatusBar *statusBar;
gputypes *types; gputypes *types;
int gpuidx; int gpuidx;
private slots: private slots:

View File

@ -6,10 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>713</width> <width>617</width>
<height>550</height> <height>458</height>
<width>600</width>
<height>428</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">

View File

@ -65,12 +65,14 @@ public:
bool overClockAvailable = false; bool overClockAvailable = false;
bool memOverClockAvailable = false; bool memOverClockAvailable = false;
bool powerLimitAvailable = false; bool powerLimitAvailable = false;
bool voltageReadable = false; bool voltageReadable = false;
bool coreClkReadable = false; bool coreClkReadable = false;
bool memClkReadable = false; bool memClkReadable = false;
bool powerDrawReadable = false; bool powerDrawReadable = false;
bool coreUtilReadable = false; bool coreUtilReadable = false;
bool manualFanCtrlAvailable = false; bool manualFanCtrlAvailable = false;
int fanControlMode; int fanControlMode;
int maxVoltageOffset; int maxVoltageOffset;
int minVoltageOffset; int minVoltageOffset;

View File

@ -231,6 +231,39 @@ void MainWindow::setupMonitorTab()
} }
void MainWindow::setupGraphMonitorTab() void MainWindow::setupGraphMonitorTab()
{ {
// Check what is readable and make monitoring structs
if (types->GPUList[currentGPUIndex].voltageReadable) {
monitorCmds monstruct;
monstruct.queryFunc = &gputypes::queryGPUVoltage;
monstruct.displayValue = types->GPUList[currentGPUIndex].displayVoltage;
monitorCmdsList.append(monstruct);
}
if (types->GPUList[currentGPUIndex].powerDrawReadable) {
monitorCmds monstruct;
monstruct.queryFunc = &gputypes::queryGPUPowerDraw;
monstruct.displayValue = types->GPUList[currentGPUIndex].displayPowerDraw;
monitorCmdsList.append(monstruct);
}
if (types->GPUList[currentGPUIndex].coreUtilReadable) {
monitorCmds monstruct;
monstruct.queryFunc = &gputypes::queryGPUUtils;
monstruct.displayValue = types->GPUList[currentGPUIndex].displayCoreUtil;
monitorCmdsList.append(monstruct);
}
if (types->GPUList[currentGPUIndex].coreClkReadable) {
monitorCmds monstruct;
monstruct.queryFunc = &gputypes::queryGPUFrequencies;
monstruct.displayValue = types->GPUList[currentGPUIndex].displayCoreFreq;
monitorCmdsList.append(monstruct);
}
monitorCmds monstruct;
monstruct.queryFunc = &gputypes::queryGPUFanSpeed;
monstruct.displayValue = types->GPUList[currentGPUIndex].displayFanSpeed;
monitorCmdsList.append(monstruct);
types->queryGPUTemp(currentGPUIndex); types->queryGPUTemp(currentGPUIndex);
types->queryGPUPowerDraw(currentGPUIndex); types->queryGPUPowerDraw(currentGPUIndex);
types->queryGPUFrequencies(currentGPUIndex); types->queryGPUFrequencies(currentGPUIndex);
@ -422,13 +455,17 @@ void MainWindow::updateMonitor()
{ {
// Update the values for plots // Update the values for plots
types->queryGPUTemp(currentGPUIndex); types->queryGPUTemp(currentGPUIndex);
types->queryGPUPowerDraw(currentGPUIndex); //types->queryGPUPowerDraw(currentGPUIndex);
types->queryGPUFrequencies(currentGPUIndex); //types->queryGPUFrequencies(currentGPUIndex);
types->queryGPUUtils(currentGPUIndex); //types->queryGPUUtils(currentGPUIndex);
types->queryGPUVoltage(currentGPUIndex); types->queryGPUVoltage(currentGPUIndex);
types->queryGPUFanSpeed(currentGPUIndex); //types->queryGPUFanSpeed(currentGPUIndex);
types->queryGPUUsedVRAM(currentGPUIndex); types->queryGPUUsedVRAM(currentGPUIndex);
for (int i=0; i<monitorCmdsList.size(); i++) {
(*types.*monitorCmdsList[i].queryFunc)(currentGPUIndex);
}
// Remove the last decimal point from power draw to make it take less space on the plot // Remove the last decimal point from power draw to make it take less space on the plot
/*double pwrdraw = types->GPUList[currentGPUIndex].powerDraw; /*double pwrdraw = types->GPUList[currentGPUIndex].powerDraw;
pwrdraw = pwrdraw/10; pwrdraw = pwrdraw/10;
@ -1064,6 +1101,7 @@ void MainWindow::enableFanUpdater()
} }
void MainWindow::on_applyButton_clicked() void MainWindow::on_applyButton_clicked()
{ {
resettimer->stop();
QSettings settings("tuxclocker"); QSettings settings("tuxclocker");
settings.beginGroup("General"); settings.beginGroup("General");
QString prevProfile = settings.value("currentProfile").toString(); QString prevProfile = settings.value("currentProfile").toString();

View File

@ -213,6 +213,11 @@ private:
double latestPointerXcoord; double latestPointerXcoord;
int plotIndex = 0; int plotIndex = 0;
struct monitorCmds {
void (gputypes::*queryFunc)(int);
int displayValue;
};
QVector <monitorCmds> monitorCmdsList;
struct plotCmds struct plotCmds
{ {
QVector <double> vector; QVector <double> vector;