Use TDE HW backend to gather standard CPU information

pull/1/head
Timothy Pearson 12 years ago
parent 9ee1344e3a
commit 989ae9f31b

@ -78,36 +78,40 @@ int CPUInfo::getCPUNum() {
int CPUInfo::checkCPUSpeed(){ int CPUInfo::checkCPUSpeed(){
kdDebugFuncOut(trace); kdDebugFuncOut(trace);
TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
bool speed_changed = false; bool speed_changed = false;
int new_value = -1; 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 // first check path for the kernel on-demand-govenour then
// for the use userspace case // for the use userspace case
update_info_cpufreq_speed_changed = false; update_info_cpufreq_speed_changed = false;
cpufreq_speed.clear(); cpufreq_speed.clear();
if (numOfCPUs == -1) if (numOfCPUs == -1) {
numOfCPUs = getCPUNum(); numOfCPUs = hwlist.count();
}
for (int cpu_id=0; cpu_id < numOfCPUs; cpu_id++) { 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; new_value = -1;
fd = open(cpu_device.ascii(), O_RDONLY); if (cdevice) {
if (read(fd, buf, 14) > 0){ new_value = cdevice->frequency();
new_value = strtol(buf, NULL, 10)/1000;
close(fd);
} }
else{ else {
close(fd);
speed_changed = true; speed_changed = true;
// CPU disabeld -> set Freq to -1 // CPU disabled -> set Freq to -1
cpufreq_speed.append(-1); cpufreq_speed.append(-1);
} }
@ -115,8 +119,6 @@ int CPUInfo::checkCPUSpeed(){
speed_changed = true; speed_changed = true;
cpufreq_speed.append(new_value); cpufreq_speed.append(new_value);
} }
cpu_device.replace(TQString::number(cpu_id), TQString::number(cpu_id+1));
} }
if (speed_changed) { if (speed_changed) {
@ -255,33 +257,32 @@ bool CPUInfo::getCPUThrottlingState() {
void CPUInfo::getCPUMaxSpeed() { void CPUInfo::getCPUMaxSpeed() {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
int fd; TDEGenericHardwareList hwlist = m_hwdevices->listByDeviceClass(TDEGenericDeviceType::CPU);
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
cpufreq_max_speed.clear(); cpufreq_max_speed.clear();
if (numOfCPUs == -1) if (numOfCPUs == -1) {
numOfCPUs = getCPUNum(); numOfCPUs = getCPUNum();
}
// while (!access(cpu_device_max, R_OK)) {
for (int cpu_id=0; cpu_id < numOfCPUs; cpu_id++) { 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 (cdevice) {
if (read(fd, buf, 14) > 0){ cpufreq_max_speed.append(cdevice->maxFrequency());
maxfreq = strtol(buf, NULL, 10)/1000; }
cpufreq_max_speed.append(maxfreq); else {
close(fd);
} else {
cpufreq_max_speed.append(-1); cpufreq_max_speed.append(-1);
close(fd);
} }
cpu_device_max.replace(TQString::number(cpu_id), TQString::number(cpu_id+1));
} }
kdDebugFuncOut(trace); kdDebugFuncOut(trace);

Loading…
Cancel
Save