summaryrefslogtreecommitdiffstats
path: root/tdecore
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-04-13 15:00:45 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-04-13 15:00:45 -0500
commitf146da840f4b74e87fd1bd20958a521abb92a9b8 (patch)
tree2146fed499313650b3a90b3adb636c9b27178fba /tdecore
parent0194f444344d973a905edf3917533e89fb6d2244 (diff)
downloadtdelibs-f146da840f4b74e87fd1bd20958a521abb92a9b8.tar.gz
tdelibs-f146da840f4b74e87fd1bd20958a521abb92a9b8.zip
Add CPU governor detection and setting capability
Diffstat (limited to 'tdecore')
-rw-r--r--tdecore/tdehardwaredevices.cpp40
-rw-r--r--tdecore/tdehardwaredevices.h38
2 files changed, 70 insertions, 8 deletions
diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp
index fcb70cbc2..abeddaf43 100644
--- a/tdecore/tdehardwaredevices.cpp
+++ b/tdecore/tdehardwaredevices.cpp
@@ -887,6 +887,35 @@ void TDECPUDevice::internalSetAvailableFrequencies(TQStringList af) {
m_frequencies = af;
}
+TQStringList &TDECPUDevice::availableGovernors() {
+ return m_governers;
+}
+
+void TDECPUDevice::internalSetAvailableGovernors(TQStringList gp) {
+ m_governers = gp;
+}
+
+bool TDECPUDevice::canSetGovernor() {
+ TQString governornode = systemPath() + "/cpufreq/scaling_governor";
+ int rval = access (governornode.ascii(), W_OK);
+ if (rval == 0) {
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+}
+
+void TDECPUDevice::setGovernor(TQString gv) {
+ TQString governornode = systemPath() + "/cpufreq/scaling_governor";
+ TQFile file( governornode );
+ if ( file.open( IO_WriteOnly ) ) {
+ TQTextStream stream( &file );
+ stream << gv.lower();
+ file.close();
+ }
+}
+
TDESensorDevice::TDESensorDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn) {
}
@@ -1566,6 +1595,7 @@ void TDEHardwareDevices::processModifiedCPUs() {
double trlatency = -1;
TQStringList affectedcpulist;
TQStringList frequencylist;
+ TQStringList governorlist;
if (cpufreq_dir.exists()) {
TQString nodename = cpufreq_dir.path();
nodename.append("/scaling_governor");
@@ -1623,6 +1653,14 @@ void TDEHardwareDevices::processModifiedCPUs() {
frequencylist = TQStringList::split(" ", stream.readLine());
availfreqsfile.close();
}
+ nodename = cpufreq_dir.path();
+ nodename.append("/scaling_available_governors");
+ TQFile availgvrnsfile(nodename);
+ if (availgvrnsfile.open(IO_ReadOnly)) {
+ TQTextStream stream( &availgvrnsfile );
+ governorlist = TQStringList::split(" ", stream.readLine());
+ availgvrnsfile.close();
+ }
}
// Update CPU information structure
@@ -1640,6 +1678,8 @@ void TDEHardwareDevices::processModifiedCPUs() {
cdevice->internalSetDependentProcessors(affectedcpulist);
if (cdevice->availableFrequencies().join(" ") != frequencylist.join(" ")) modified = true;
cdevice->internalSetAvailableFrequencies(frequencylist);
+ if (cdevice->availableGovernors().join(" ") != governorlist.join(" ")) modified = true;
+ cdevice->internalSetAvailableGovernors(governorlist);
}
if (modified) {
diff --git a/tdecore/tdehardwaredevices.h b/tdecore/tdehardwaredevices.h
index c230474a1..a91538896 100644
--- a/tdecore/tdehardwaredevices.h
+++ b/tdecore/tdehardwaredevices.h
@@ -754,55 +754,76 @@ class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice
*/
TQStringList &availableFrequencies();
+ /**
+ * @return a TQStringList with all available governor policies, if available
+ */
+ TQStringList &availableGovernors();
+
+ /**
+ * @return TRUE if permissions allow the CPU governor to be set, FALSE if not
+ */
+ bool canSetGovernor();
+
+ /**
+ * @param gv a TQString with the new CPU governor policy name
+ */
+ void setGovernor(TQString gv);
+
protected:
/**
- * @param a double with the current CPU frequency in MHz, if available
+ * @param fr a double with the current CPU frequency in MHz, if available
* @internal
*/
void internalSetFrequency(double fr);
/**
- * @param a double with the minimum CPU frequency in MHz, if available
+ * @param fr a double with the minimum CPU frequency in MHz, if available
* @internal
*/
void internalSetMinFrequency(double fr);
/**
- * @param a double with the maximum CPU frequency in MHz, if available
+ * @param fr a double with the maximum CPU frequency in MHz, if available
* @internal
*/
void internalSetMaxFrequency(double fr);
/**
- * @param a double with the transition latency in ns, if available
+ * @param tl a double with the transition latency in ns, if available
* @internal
*/
void internalSetTransitionLatency(double tl);
/**
- * @param a TQString with the current CPU governor policy, if available
+ * @param gr a TQString with the current CPU governor policy, if available
* @internal
*/
void internalSetGovernor(TQString gr);
/**
- * @param a TQString with the current CPU scaling driver, if available
+ * @param dr a TQString with the current CPU scaling driver, if available
* @internal
*/
void internalSetScalingDriver(TQString dr);
/**
- * @param a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available
+ * @param dp a TQStringList with the IDs of all processors that are dependent on the frequency/power settings of this one, if available
* @internal
*/
void internalSetDependentProcessors(TQStringList dp);
/**
- * @param a TQStringList with all valid scaling frequencies in Hz, if available
+ * @param af a TQStringList with all valid scaling frequencies in Hz, if available
* @internal
*/
void internalSetAvailableFrequencies(TQStringList af);
+ /**
+ * @param gp a TQStringList with all available governor policies, if available
+ * @internal
+ */
+ void internalSetAvailableGovernors(TQStringList gp);
+
private:
double m_frequency;
double m_minfrequency;
@@ -812,6 +833,7 @@ class TDECORE_EXPORT TDECPUDevice : public TDEGenericDevice
TQString m_scalingdriver;
TQStringList m_tiedprocs;
TQStringList m_frequencies;
+ TQStringList m_governers;
friend class TDEHardwareDevices;
};