Add CPU governor detection and setting capability

pull/16/head
Timothy Pearson 13 years ago
parent 0194f44434
commit f146da840f

@ -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) {

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

Loading…
Cancel
Save