From fbdb4f5c51880026958c012047b2515ae6e7b79b Mon Sep 17 00:00:00 2001 From: jussi Date: Wed, 20 Feb 2019 22:02:04 +0200 Subject: [PATCH] add core pstate writing --- amdpstateeditor.cpp | 44 +++++++++++++++++++++++++++++++++++++++----- amdpstateeditor.h | 19 ++++++++++++++++++- mainwindow.cpp | 2 +- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/amdpstateeditor.cpp b/amdpstateeditor.cpp index 769aad6..caafd49 100644 --- a/amdpstateeditor.cpp +++ b/amdpstateeditor.cpp @@ -12,13 +12,18 @@ amdPstateEditor::~amdPstateEditor() { delete ui; } -void amdPstateEditor::generateUI(gputypes *types) +void amdPstateEditor::grabPointer(gputypes *newtypes) +{ + types = newtypes; +} +void amdPstateEditor::generateUI() { QWidget *lower = new QWidget; QWidget *upper = new QWidget; QHBoxLayout *ulo = new QHBoxLayout; QHBoxLayout *llo = new QHBoxLayout; for (int i=0; iGPUList[0].coreclocks.size(); i++) { + corePstate state; QGridLayout *glo = new QGridLayout; QLabel *voltlabel = new QLabel; QLabel *freqlabel = new QLabel; @@ -53,10 +58,14 @@ void amdPstateEditor::generateUI(gputypes *types) glo->addWidget(voltspinbox, 3, 1); QWidget *freqsliderowdg = new QWidget; freqsliderowdg->setLayout(glo); - llo->addWidget(freqsliderowdg); + ulo->addWidget(freqsliderowdg); + + state.voltspinbox = voltspinbox; + state.freqspinbox = freqspinbox; } for (int i=0; iGPUList[0].memclocks.size(); i++) { + memPstate state; QGridLayout *glo = new QGridLayout; QLabel *voltlabel = new QLabel; QLabel *freqlabel = new QLabel; @@ -91,13 +100,38 @@ void amdPstateEditor::generateUI(gputypes *types) glo->addWidget(voltspinbox, 3, 1); QWidget *freqsliderowdg = new QWidget; freqsliderowdg->setLayout(glo); - ulo->addWidget(freqsliderowdg); + llo->addWidget(freqsliderowdg); + state.voltspinbox = voltspinbox; + state.freqspinbox = freqspinbox; + memPstates.append(state); } - lower->setLayout(ulo); - upper->setLayout(llo); + // Add an apply button + QPushButton *applyButton = new QPushButton; + connect(applyButton, SIGNAL(clicked()), SLOT(applyValues())); + applyButton->setText("Apply values"); + llo->addWidget(applyButton); + + lower->setLayout(llo); + upper->setLayout(ulo); QVBoxLayout *mainlo = new QVBoxLayout(this); mainlo->addWidget(upper); mainlo->addWidget(lower); ui->centralWidget->setLayout(mainlo); } +bool amdPstateEditor::applyValues() +{ + qDebug("Applying values"); + for (int i=0; ivalue() != types->GPUList[0].coreclocks[i]) || (corePstates[i].voltspinbox->value() != types->GPUList[0].corevolts[i])) { + QProcess proc; + QString volt = QString::number(corePstates[i].freqspinbox->value()); + QString freq = QString::number(corePstates[i].voltspinbox->value()); + proc.start("pkexec echo \"s "+ volt +" "+ freq +"\" "+"> /sys/class/drm/card"+QString::number(types->GPUList[0].fsindex)+"/device/pp_od_clk_voltage"); + proc.waitForFinished(); + } + } + + + return true; +} diff --git a/amdpstateeditor.h b/amdpstateeditor.h index 06f5be1..7d3d239 100644 --- a/amdpstateeditor.h +++ b/amdpstateeditor.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "gputypes.h" namespace Ui { @@ -21,10 +23,25 @@ class amdPstateEditor : public QDialog public: explicit amdPstateEditor(QWidget *parent = nullptr); ~amdPstateEditor(); - void generateUI(gputypes *types); + void grabPointer(gputypes *newtypes); + void generateUI(); private: Ui::amdPstateEditor *ui; + // These are used for getting the values out of the sliders when applying, only a slider or spinbox is required, since they are synced + struct memPstate { + QSpinBox *voltspinbox; + QSpinBox *freqspinbox; + }; + struct corePstate { + QSpinBox *voltspinbox; + QSpinBox *freqspinbox; + }; + QVector corePstates; + QVector memPstates; + gputypes *types; +private slots: + bool applyValues(); }; #endif // AMDPSTATEEDITOR_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 757c363..155a347 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1113,7 +1113,7 @@ void MainWindow::on_GPUComboBox_currentIndexChanged(int index) void MainWindow::on_amdPstateButton_pressed() { amdPstateEditor *ps = new amdPstateEditor; - ps->generateUI(types); + ps->grabPointer(types); ps->setModal(true); ps->exec(); }