Skip to content

Commit

Permalink
More cpu stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Jan 28, 2024
1 parent 2cc08ef commit 67789f1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/powerkit_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const QStringList PowerCpu::getFrequencies()
return result;
}

// Legacy, remove?
const QStringList PowerCpu::getAvailableFrequency()
{
QStringList result;
Expand All @@ -144,6 +145,40 @@ const QStringList PowerCpu::getAvailableFrequency()
return result;
}

int PowerCpu::getMinFrequency()
{
return getScalingFrequency(0, 0);
}

int PowerCpu::getMaxFrequency()
{
return getScalingFrequency(0, 1);
}

int PowerCpu::getScalingFrequency(int cpu, int scale)
{
int result = 0;
QString type;
switch (scale) {
case 0:
type = LINUX_CPU_FREQUENCY_MIN;
break;
case 1:
type = LINUX_CPU_FREQUENCY_MAX;
break;
}
QFile freq(QString("%1/cpu%2/%3/%4").arg(LINUX_CPU_SYS,
QString::number(cpu),
LINUX_CPU_DIR,
type));
if (freq.open(QIODevice::ReadOnly|QIODevice::Text)) {
result = freq.readAll().trimmed().toInt();
freq.close();
}
return result;
}

// Legacy, remove?
bool PowerCpu::frequencyExists(const QString &freq)
{
if (freq.isEmpty()) { return false; }
Expand All @@ -152,10 +187,15 @@ bool PowerCpu::frequencyExists(const QString &freq)

bool PowerCpu::setFrequency(const QString &freq, int cpu)
{
if (!frequencyExists(freq)) { return false; }
/*if (!frequencyExists(freq)) { return false; }
if (getGovernor(cpu) != "userspace") {
if (!setGovernor("userspace", cpu)) { return false; }
}
}*/
QString val = freq;
int freqMin = getMinFrequency();
int freqMax = getMaxFrequency();
if (freq.toInt() > freqMax) { val = QString::number(freqMax); }
else if (freq.toInt() < freqMin) { val = QString::number(freqMin); }
QFile file(QString("%1/cpu%2/%3/%4")
.arg(LINUX_CPU_SYS)
.arg(cpu)
Expand All @@ -172,7 +212,7 @@ bool PowerCpu::setFrequency(const QString &freq, int cpu)

bool PowerCpu::setFrequency(const QString &freq)
{
if (!frequencyExists(freq)) { return false; }
//if (!frequencyExists(freq)) { return false; }
bool failed = false;
for (int i=0;i<getTotal();++i) {
if (!setFrequency(freq, i)) { failed = true; }
Expand Down
3 changes: 3 additions & 0 deletions src/powerkit_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class PowerCpu
static const QString getFrequency(int cpu);
static const QStringList getFrequencies();
static const QStringList getAvailableFrequency();
static int getMinFrequency();
static int getMaxFrequency();
static int getScalingFrequency(int cpu, int scale);
static bool frequencyExists(const QString &freq);
static bool setFrequency(const QString &freq, int cpu);
static bool setFrequency(const QString &freq);
Expand Down

0 comments on commit 67789f1

Please sign in to comment.