diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hardware_cpu.cpp | 71 |
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); |