Skip to content

Commit

Permalink
[FIX] CpuCounter Cores detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanieleDeSensi committed Sep 19, 2016
1 parent a84c6d4 commit 8d2c36c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions mammut/energy/energy-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ void CounterCpusLinuxRefresher::run(){

bool CounterCpusLinux::hasCoresCounter(topology::Cpu* cpu){
uint64_t dummy;
return Msr(cpu->getVirtualCore()->getVirtualCoreId()).read(MSR_PP0_ENERGY_STATUS, dummy);
return Msr(cpu->getVirtualCore()->getVirtualCoreId()).read(MSR_PP0_ENERGY_STATUS, dummy) && dummy > 0;
}

bool CounterCpusLinux::hasGraphicCounter(topology::Cpu* cpu){
uint64_t dummy;
return Msr(cpu->getVirtualCore()->getVirtualCoreId()).read(MSR_PP1_ENERGY_STATUS, dummy);
return Msr(cpu->getVirtualCore()->getVirtualCoreId()).read(MSR_PP1_ENERGY_STATUS, dummy) && dummy > 0;
}

bool CounterCpusLinux::hasDramCounter(topology::Cpu* cpu){
uint64_t dummy;
return Msr(cpu->getVirtualCore()->getVirtualCoreId()).read(MSR_DRAM_ENERGY_STATUS, dummy);
return Msr(cpu->getVirtualCore()->getVirtualCoreId()).read(MSR_DRAM_ENERGY_STATUS, dummy) && dummy > 0;
}

bool CounterCpusLinux::isCpuSupported(topology::Cpu* cpu){
Expand Down Expand Up @@ -125,7 +125,7 @@ CounterCpusLinux::CounterCpusLinux():
_lastReadCountersCores(NULL),
_lastReadCountersGraphic(NULL),
_lastReadCountersDram(NULL),
_hasJoulesCores(false),
_hasJoulesCores(false),
_hasJoulesGraphic(false),
_hasJoulesDram(false){
;
Expand Down Expand Up @@ -193,7 +193,7 @@ bool CounterCpusLinux::init(){
_hasJoulesGraphic = true;
for(size_t i = 0; i < _cpus.size(); i++){
if(!hasCoresCounter(_cpus.at(i))){
_hasJoulesCores = false;
_hasJoulesCores = false;
}
if(!hasDramCounter(_cpus.at(i))){
_hasJoulesDram = false;
Expand Down Expand Up @@ -276,13 +276,13 @@ Joules CounterCpusLinux::getJoulesCpu(topology::CpuId cpuId){
}

Joules CounterCpusLinux::getJoulesCores(topology::CpuId cpuId){
if(hasJoulesCores()){
ScopedLock sLock(_lock);
updateCounter(cpuId, _joulesCpus[cpuId].cores, _lastReadCountersCores[cpuId], MSR_PP0_ENERGY_STATUS);
return _joulesCpus[cpuId].cores;
}else{
return 0;
}
if(hasJoulesCores()){
ScopedLock sLock(_lock);
updateCounter(cpuId, _joulesCpus[cpuId].cores, _lastReadCountersCores[cpuId], MSR_PP0_ENERGY_STATUS);
return _joulesCpus[cpuId].cores;
}else{
return 0;
}
}

Joules CounterCpusLinux::getJoulesGraphic(topology::CpuId cpuId){
Expand Down

0 comments on commit 8d2c36c

Please sign in to comment.