summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-10-11 11:46:21 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-10-11 11:46:21 -0500
commit989ae9f31b5497c833152fe2af55df23695e0b1f (patch)
treecf2cd7f728db56ca87a38ab2c614f4cc04c5417f /src
parent9ee1344e3af28bb6aad821402084c0416c25d35d (diff)
downloadtdepowersave-989ae9f31b5497c833152fe2af55df23695e0b1f.tar.gz
tdepowersave-989ae9f31b5497c833152fe2af55df23695e0b1f.zip
Use TDE HW backend to gather standard CPU information
Diffstat (limited to 'src')
-rw-r--r--src/hardware_cpu.cpp71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/hardware_cpu.cpp b/src/hardware_cpu.cpp
index 5847dd9..69f43d8 100644
--- a/src/hardware_cpu.cpp
+++ b/src/hardware_cpu.cpp
@@ -78,36 +78,40 @@ int CPUInfo::getCPUNum() {
int CPUInfo::checkCPUSpeed(){
kdDebugFuncOut(trace);
+ TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
+
bool speed_changed = false;
int new_value = -1;
- int fd;
- char buf[15];
- TQString cpu_device = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq";
-#ifdef FAKE_CPU
- cpu_device.prepend("/tmp/foo");
-#endif
// first check path for the kernel on-demand-govenour then
// for the use userspace case
update_info_cpufreq_speed_changed = false;
cpufreq_speed.clear();
- if (numOfCPUs == -1)
- numOfCPUs = getCPUNum();
+ if (numOfCPUs == -1) {
+ numOfCPUs = hwlist.count();
+ }
for (int cpu_id=0; cpu_id < numOfCPUs; cpu_id++) {
+ TDECPUDevice* cdevice = NULL;
+ TDEGenericDevice *hwdevice;
+ for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) {
+ TDECPUDevice* possiblecpu = static_cast<TDECPUDevice*>(hwdevice);
+ if (possiblecpu) {
+ if (possiblecpu->coreNumber() == cpu_id) {
+ cdevice = possiblecpu;
+ }
+ }
+ }
new_value = -1;
- fd = open(cpu_device.ascii(), O_RDONLY);
- if (read(fd, buf, 14) > 0){
- new_value = strtol(buf, NULL, 10)/1000;
- close(fd);
+ if (cdevice) {
+ new_value = cdevice->frequency();
}
- else{
- close(fd);
+ else {
speed_changed = true;
- // CPU disabeld -> set Freq to -1
+ // CPU disabled -> set Freq to -1
cpufreq_speed.append(-1);
}
@@ -115,8 +119,6 @@ int CPUInfo::checkCPUSpeed(){
speed_changed = true;
cpufreq_speed.append(new_value);
}
-
- cpu_device.replace(TQString::number(cpu_id), TQString::number(cpu_id+1));
}
if (speed_changed) {
@@ -255,33 +257,32 @@ bool CPUInfo::getCPUThrottlingState() {
void CPUInfo::getCPUMaxSpeed() {
kdDebugFuncIn(trace);
- int fd;
- int maxfreq;
- char buf[15];
- TQString cpu_device_max = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
-#ifdef FAKE_CPU
- cpu_device_max.prepend("/tmp/foo");
-#endif
+ TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
cpufreq_max_speed.clear();
- if (numOfCPUs == -1)
+ if (numOfCPUs == -1) {
numOfCPUs = getCPUNum();
+ }
-// while (!access(cpu_device_max, R_OK)) {
for (int cpu_id=0; cpu_id < numOfCPUs; cpu_id++) {
+ TDECPUDevice* cdevice = NULL;
+ TDEGenericDevice *hwdevice;
+ for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) {
+ TDECPUDevice* possiblecpu = static_cast<TDECPUDevice*>(hwdevice);
+ if (possiblecpu) {
+ if (possiblecpu->coreNumber() == cpu_id) {
+ cdevice = possiblecpu;
+ }
+ }
+ }
- fd = open(cpu_device_max.ascii(), O_RDONLY);
- if (read(fd, buf, 14) > 0){
- maxfreq = strtol(buf, NULL, 10)/1000;
- cpufreq_max_speed.append(maxfreq);
- close(fd);
- } else {
+ if (cdevice) {
+ cpufreq_max_speed.append(cdevice->maxFrequency());
+ }
+ else {
cpufreq_max_speed.append(-1);
- close(fd);
}
-
- cpu_device_max.replace(TQString::number(cpu_id), TQString::number(cpu_id+1));
}
kdDebugFuncOut(trace);