A
This commit is contained in:
jussi 2018-12-22 19:11:45 +02:00
parent 45ac973040
commit 68072b25d4
3 changed files with 219 additions and 322 deletions

View File

@ -26,8 +26,8 @@ MainWindow::MainWindow(QWidget *parent) :
ui->memClkSlider->setRange(defMemClk + minMemClkOfsInt, defMemClk + maxMemClkOfsInt);
ui->memClkSpinBox->setRange(defMemClk + minMemClkOfsInt, defMemClk + maxMemClkOfsInt);
ui->memClkSlider->setValue(curMaxMemClkInt);
ui->memClkSpinBox->setValue(curMaxMemClkInt);
ui->memClkSlider->setValue(defMemClk + memClkOfsInt);
ui->memClkSpinBox->setValue(defMemClk + memClkOfsInt);
ui->voltageSlider->setRange(voltInt + minVoltOfsInt, voltInt + maxVoltOfsInt);
ui->voltageSpinBox->setRange(voltInt + minVoltOfsInt, voltInt + maxVoltOfsInt);
@ -41,8 +41,13 @@ MainWindow::MainWindow(QWidget *parent) :
QTimer *fanUpdateTimer = new QTimer(this);
connect(fanUpdateTimer, SIGNAL(timeout()), this, SLOT(fanSpeedUpdater()));
connect(fanUpdateTimer, SIGNAL(timeout()), this, SLOT(tempUpdater()));
//connect(fanUpdateTimer, SIGNAL(timeout()), this, SLOT(tempUpdater()));
fanUpdateTimer->start(2000);
connect(ui->frequencySpinBox, SIGNAL(valueChanged(int)), SLOT(resetTimer()));
connect(ui->powerLimSpinBox, SIGNAL(valueChanged(int)), SLOT(resetTimer()));
connect(ui->memClkSpinBox, SIGNAL(valueChanged(int)), SLOT(resetTimer()));
connect(ui->voltageSpinBox, SIGNAL(valueChanged(int)), SLOT(resetTimer()));
}
MainWindow::~MainWindow()
@ -162,22 +167,44 @@ void MainWindow::tempUpdater()
generateFanPoint();
}
}
void MainWindow::resetTimer()
{
// If a value has been changed this timer will start. When the apply button has been pressed, this gets cancelled
connect(resettimer, SIGNAL(timeout()), SLOT(resetChanges()));
resettimer->stop();
resettimer->setSingleShot(true);
resettimer->start(10000);
}
void MainWindow::resetChanges()
{
// If the settings haven't been applied in 10 seconds, reset all values to their latest values
ui->frequencySlider->setValue(defCoreClk + latestClkOfs);
ui->frequencySpinBox->setValue(defCoreClk + latestClkOfs);
ui->powerLimSlider->setValue(latestPowerLim);
ui->powerLimSpinBox->setValue(latestPowerLim);
ui->voltageSlider->setValue(voltInt + latestVoltOfs);
ui->voltageSpinBox->setValue(voltInt + latestVoltOfs);
ui->memClkSlider->setValue(curMaxMemClkInt);
ui->memClkSpinBox->setValue(curMaxMemClkInt);
ui->memClkSlider->setValue(defMemClk + latestMemClkOfs);
ui->memClkSpinBox->setValue(defMemClk + latestMemClkOfs);
qDebug() << "timer";
}
void MainWindow::queryGPUSettings()
{
QString volt;
QProcess process;
process.start(nvVoltQ);
process.waitForFinished(-1);
volt = process.readLine();
volt.chop(1);
voltInt = volt.toInt()/1000;
voltInt = process.readLine().toInt()/1000;
QString voltOfs;
process.start(nvVoltOfsQ);
process.waitForFinished(-1);
voltOfs = process.readLine();
voltOfs.chop(1);
voltOfsInt = voltOfs.toInt()/1000;
voltOfsInt = process.readLine().toInt()/1000;
latestVoltOfs = voltOfsInt;
defVolt = voltInt - voltOfsInt;
@ -197,56 +224,26 @@ void MainWindow::queryGPUSettings()
coreFreqOfs = process.readLine();
coreFreqOfs.chop(1);
coreFreqOfsInt = coreFreqOfs.toInt();
latestClkOfs = coreFreqOfsInt;
QString curMaxClk;
process.start(nvCurMaxClkQ);
process.waitForFinished(-1);
curMaxClkInt = process.readLine().toInt();
qDebug() << curMaxClkInt;
QString maxPowerLim;
process.start(nvMaxPowerLimQ);
process.waitForFinished(-1);
for (int i=0; i<process.size(); i++) {
QString output = process.readLine();
if (!output.contains("power")) {
maxPowerLim = output;
break;
}
}
maxPowerLim.chop(3);
maxPowerLimInt = maxPowerLim.toDouble();
qDebug() << maxPowerLimInt;
maxPowerLimInt = process.readLine().toInt();
QString minPowerLim;
process.start(nvMinPowerLimQ);
process.waitForFinished(-1);
for (int i=0; i<process.size(); i++) {
QString output = process.readLine();
if (!output.contains("power")) {
minPowerLim = output;
break;
}
}
minPowerLim.chop(3);
minPowerLimInt = minPowerLim.toDouble();
qDebug() << minPowerLimInt;
minPowerLimInt = process.readLine().toInt();
QString curPowerLim;
process.start(nvCurPowerLimQ);
process.waitForFinished(-1);
for (int i=0; i<process.size(); i++) {
QString output = process.readLine();
if (!output.contains("power")) {
curPowerLim = output;
break;
}
}
curPowerLim.chop(3);
curPowerLimInt = curPowerLim.toDouble();
qDebug() << curPowerLimInt;
curPowerLimInt = process.readLine().toInt();
latestPowerLim = curPowerLimInt;
QString clockLimits;
process.start(nvClockLimQ);
process.waitForFinished(-1);
for (int i=0; i<2; i++) {
@ -270,22 +267,15 @@ void MainWindow::queryGPUSettings()
maxMemClkOfsInt = line.toInt()/2;
}
}
qDebug() << minMemClkOfsInt << maxMemClkOfsInt;
process.start(nvCurMaxMemClkQ);
process.waitForFinished(-1);
curMaxMemClkInt = process.readLine().toInt();
qDebug() << curMaxMemClkInt;
process.start(nvCurMemClkOfsQ);
process.waitForFinished(-1);
memClkOfsInt = process.readLine().toInt()/2;
qDebug() << memClkOfsInt;
process.start(nvFanQ);
process.waitForFinished(-1);
fanSpeed = process.readLine().toInt();
qDebug() << fanSpeed;
latestMemClkOfs = memClkOfsInt;
// Since the maximum core clock reported is the same on negative offsets as on 0 offset add a check here
if (0 >= coreFreqOfsInt) {
@ -298,40 +288,56 @@ void MainWindow::queryGPUSettings()
void MainWindow::applyGPUSettings()
{
QProcess process;
int offsetValue = ui->frequencySlider->value() - defCoreClk;
int offsetValue;
int powerLimit;
QString input = nvCoreClkSet;
input.append(QString::number(offsetValue));
qDebug() << input;
process.start(input);
process.waitForFinished(-1);
offsetValue = ui->memClkSlider->value() - defMemClk;
input = nvMemClkSet;
input.append(QString::number(offsetValue*2));
qDebug() << input;
process.start(input);
process.waitForFinished(-1);
int powerLimit = ui->powerLimSlider->value();
input = nvPowerLimSet;
if (!isRoot) {
input.append(QString::number(powerLimit) +"'\"");
input.prepend("/bin/sh -c \"kdesu -c ");
if (latestClkOfs != ui->frequencySlider->value() - defCoreClk) {
offsetValue = ui->frequencySlider->value() - defCoreClk;
QString input = nvCoreClkSet;
input.append(QString::number(offsetValue));
qDebug() << input;
process.start(input);
process.waitForFinished(-1);
} else {
input.append(QString::number(powerLimit));
process.start(input);
process.waitForFinished(-1);
qDebug() << "ran as root";
latestClkOfs = ui->frequencySlider->value() - defCoreClk;
}
offsetValue = ui->voltageSlider->value() - defVolt;
input = nvVoltageSet;
input.append(QString::number(offsetValue*1000));
qDebug() << input;
process.start(input);
process.waitForFinished(-1);
if (latestMemClkOfs != ui->memClkSlider->value() - defMemClk) {
offsetValue = ui->memClkSlider->value() - defMemClk;
input = nvMemClkSet;
input.append(QString::number(offsetValue*2));
qDebug() << input;
process.start(input);
process.waitForFinished(-1);
latestMemClkOfs = ui->memClkSlider->value() - defMemClk;
}
if (latestPowerLim != ui->powerLimSlider->value()) {
powerLimit = ui->powerLimSlider->value();
input = nvPowerLimSet;
if (!isRoot) {
input.append(QString::number(powerLimit) +"'\"");
input.prepend("/bin/sh -c \"kdesu -c ");
process.start(input);
process.waitForFinished(-1);
} else {
input.append(QString::number(powerLimit));
process.start(input);
process.waitForFinished(-1);
qDebug() << "ran as root";
}
latestPowerLim = ui->powerLimSlider->value();
}
if (latestVoltOfs != ui->voltageSlider->value() - defVolt) {
offsetValue = ui->voltageSlider->value() - defVolt;
input = nvVoltageSet;
input.append(QString::number(offsetValue*1000));
qDebug() << input;
process.start(input);
process.waitForFinished(-1);
latestVoltOfs = ui->voltageSlider->value() - defVolt;
}
resettimer->stop();
}
void MainWindow::loadProfileSettings()
{
@ -380,8 +386,8 @@ void MainWindow::on_newProfile_closed()
}
void MainWindow::saveProfileSettings()
{
QSettings settings;
QSettings settings("nvfancurve");
settings.beginGroup(currentProfile);
}

View File

@ -20,20 +20,20 @@ public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
QString currentProfile;
QString nvFanQ = "nvidia-settings -q GPUCurrentFanSpeed -t";
QString nvFanQ = "/bin/sh -c \"nvidia-smi --query-gpu=fan.speed --format=csv | egrep -o '[1-9]{1,4}'\"";
QString nvVoltQ = "nvidia-settings -q GPUCurrentCoreVoltage -t";
QString nvVoltOfsQ = "nvidia-settings -q GPUOverVoltageOffset -t";
QString nvVoltOfsLimQ = "/bin/sh -c \"nvidia-settings -a GPUOverVoltageOffset=99999999 | egrep -o '[0-9]{1,9}'\"";
QString nvCoreClkOfsQ = "nvidia-settings -q GPUGraphicsClockOffset[3] -t";
QString nvCurMaxClkQ = "/bin/sh -c \"nvidia-smi --query-supported-clocks=gr --format=csv | egrep -o '[0-9]{2,9}'\"";
QString nvMaxPowerLimQ = "nvidia-smi --query-gpu=power.max_limit --format=csv";
QString nvMinPowerLimQ = "nvidia-smi --query-gpu=power.min_limit --format=csv";
QString nvCurPowerLimQ = "nvidia-smi --query-gpu=power.limit --format=csv";
QString nvMaxPowerLimQ = "/bin/sh -c \"nvidia-smi --query-gpu=power.max_limit --format=csv | egrep -o '[0-9]{1,7}'\"";
QString nvMinPowerLimQ = "/bin/sh -c \"nvidia-smi --query-gpu=power.min_limit --format=csv | egrep -o '[0-9]{1,7}'\"";
QString nvCurPowerLimQ = "/bin/sh -c \"nvidia-smi --query-gpu=power.limit --format=csv | egrep -o '[0-9]{1,7}'\"";
QString nvClockLimQ = "/bin/sh -c \"nvidia-settings -a GPUGraphicsClockOffset[3]=999999 | egrep -o '[-0-9]{2,9}'\"";
QString nvMemClkLimQ = "/bin/sh -c \"nvidia-settings -a GPUMemoryTransferRateOffset[3]=999999 | egrep -o '[-0-9]{2,9}'\"";
QString nvCurMaxMemClkQ = "/bin/sh -c \"nvidia-smi --query-supported-clocks=mem --format=csv | egrep -o '[0-9]{2,9}'\"";
QString nvCurMemClkOfsQ = "nvidia-settings -q GPUMemoryTransferRateOffset[3] -t";
QString nvTempQ = "nvidia-settings -q ThermalSensorReading -t";
QString nvTempQ = "/bin/sh -c \"nvidia-smi --query-gpu=temperature.gpu --format=csv | egrep -o '[1-9]{1,4}'\"";
QString nvCoreClkSet = "nvidia-settings -a GPUGraphicsClockOffset[3]=";
QString nvMemClkSet = "nvidia-settings -a GPUMemoryTransferRateOffset[3]=";
@ -73,6 +73,11 @@ public:
int defMemClk;
int defVolt;
int latestClkOfs;
int latestPowerLim;
int latestMemClkOfs;
int latestVoltOfs;
bool isRoot;
public slots:
void saveProfileSettings();
@ -117,10 +122,14 @@ private slots:
void checkForRoot();
void tempUpdater();
void enableFanControl();
void resetChanges();
void resetTimer();
private:
Ui::MainWindow *ui;
bool noProfiles = true;
QVector <int> compXPoints, compYPoints;
QTimer *resettimer = new QTimer(this);
};
#endif // MAINWINDOW_H

View File

@ -6,250 +6,132 @@
<rect>
<x>0</x>
<y>0</y>
<width>513</width>
<height>762</height>
<width>384</width>
<height>590</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QComboBox" name="profileComboBox">
<property name="geometry">
<rect>
<x>340</x>
<y>650</y>
<width>151</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>testinappi</string>
</property>
</widget>
<widget class="QSlider" name="frequencySlider">
<property name="geometry">
<rect>
<x>70</x>
<y>560</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSpinBox" name="frequencySpinBox">
<property name="geometry">
<rect>
<x>350</x>
<y>560</y>
<width>71</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="newProfile">
<property name="geometry">
<rect>
<x>300</x>
<y>650</y>
<width>31</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
<widget class="QSlider" name="powerLimSlider">
<property name="geometry">
<rect>
<x>70</x>
<y>501</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSpinBox" name="powerLimSpinBox">
<property name="geometry">
<rect>
<x>350</x>
<y>500</y>
<width>71</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QSpinBox" name="memClkSpinBox">
<property name="geometry">
<rect>
<x>350</x>
<y>440</y>
<width>71</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QSlider" name="memClkSlider">
<property name="geometry">
<rect>
<x>70</x>
<y>440</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSlider" name="voltageSlider">
<property name="geometry">
<rect>
<x>70</x>
<y>381</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSpinBox" name="voltageSpinBox">
<property name="geometry">
<rect>
<x>350</x>
<y>380</y>
<width>71</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="clockFreqLabel">
<property name="geometry">
<rect>
<x>70</x>
<y>530</y>
<width>191</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Clock Frequency (MHz)</string>
</property>
</widget>
<widget class="QLabel" name="powerLimLabel">
<property name="geometry">
<rect>
<x>70</x>
<y>470</y>
<width>141</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Power Limit (W)</string>
</property>
</widget>
<widget class="QLabel" name="memClockLabel">
<property name="geometry">
<rect>
<x>70</x>
<y>410</y>
<width>151</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Memory Clock (MHz)</string>
</property>
</widget>
<widget class="QLabel" name="voltgeLabel">
<property name="geometry">
<rect>
<x>70</x>
<y>350</y>
<width>141</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Voltage (mV)</string>
</property>
</widget>
<widget class="QSlider" name="fanSlider">
<property name="geometry">
<rect>
<x>70</x>
<y>320</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QSpinBox" name="fanSpinBox">
<property name="geometry">
<rect>
<x>351</x>
<y>319</y>
<width>71</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>70</x>
<y>290</y>
<width>131</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Fan Speed (%)</string>
</property>
</widget>
<widget class="QPushButton" name="applyButton">
<property name="geometry">
<rect>
<x>175</x>
<y>650</y>
<width>101</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Apply changes</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>testinappi</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Fan Speed (%)</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QSlider" name="fanSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QSpinBox" name="fanSpinBox"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="voltgeLabel">
<property name="text">
<string>Voltage (mV)</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QSlider" name="voltageSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QSpinBox" name="voltageSpinBox"/>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="memClockLabel">
<property name="text">
<string>Memory Clock (MHz)</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QSlider" name="memClkSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QSpinBox" name="memClkSpinBox"/>
</item>
<item row="7" column="0" colspan="2">
<widget class="QLabel" name="powerLimLabel">
<property name="text">
<string>Power Limit (W)</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="3">
<widget class="QSlider" name="powerLimSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="3">
<widget class="QSpinBox" name="powerLimSpinBox"/>
</item>
<item row="9" column="0" colspan="2">
<widget class="QLabel" name="clockFreqLabel">
<property name="text">
<string>Clock Frequency (MHz)</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="3">
<widget class="QSlider" name="frequencySlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="10" column="3">
<widget class="QSpinBox" name="frequencySpinBox"/>
</item>
<item row="11" column="1">
<widget class="QPushButton" name="applyButton">
<property name="text">
<string>Apply changes</string>
</property>
</widget>
</item>
<item row="11" column="2">
<widget class="QPushButton" name="newProfile">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="11" column="3">
<widget class="QComboBox" name="profileComboBox"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>513</width>
<width>384</width>
<height>28</height>
</rect>
</property>