add core pstate writing

This commit is contained in:
jussi 2019-02-20 22:02:04 +02:00
parent 75d1a3d003
commit fbdb4f5c51
3 changed files with 58 additions and 7 deletions

View File

@ -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; i<types->GPUList[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; i<types->GPUList[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; i<corePstates.size(); i++) {
if ((corePstates[i].freqspinbox->value() != 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;
}

View File

@ -8,6 +8,8 @@
#include <QGridLayout>
#include <QSpinBox>
#include <QLabel>
#include <QPushButton>
#include <QProcess>
#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 <corePstate> corePstates;
QVector <memPstate> memPstates;
gputypes *types;
private slots:
bool applyValues();
};
#endif // AMDPSTATEEDITOR_H

View File

@ -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();
}