Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What does the API "getSystemConsumedEnergy" get? #891

Open
baihe-liu opened this issue Dec 13, 2024 · 4 comments
Open

What does the API "getSystemConsumedEnergy" get? #891

baihe-liu opened this issue Dec 13, 2024 · 4 comments

Comments

@baihe-liu
Copy link

I'm trying to use pcm API to get energy consumption, my platform is Tiger Lake.
Could you please tell me what does system consumed energy means in the function "getSystemConsumedEnergy"?

template <class CounterStateType>
uint64 getSystemConsumedEnergy(const CounterStateType& before, const CounterStateType& after)
{
    return after.systemEnergyStatus - before.systemEnergyStatus;
}

I found SystemCounterState.systemEnergyStatus will only be updated by reading from MSR in function PCM::getALLCounterStates
And I got different result using SystemCounterState from 'getSystemCounterState' and 'getALLCounterStates'

================== Energy Consumption by getSystemCounterState  ==================  
[Energy_Monitor] getConsumedJoules: 14.5959 Joules
[Energy_Monitor] getConsumedJoules(0): 10.5076 Joules
[Energy_Monitor] getConsumedJoules(1): 0.000549316 Joules
[Energy_Monitor] getDRAMConsumedJoules: 0 Joules
[Energy_Monitor] getSystemConsumedJoules: 0 Joules
================== Energy Consumption by getALLCounterStates  ==================
[Energy_Monitor] getConsumedJoules: 14.5959 Joules
[Energy_Monitor] getConsumedJoules(0): 0 Joules
[Energy_Monitor] getConsumedJoules(1): 0 Joules
[Energy_Monitor] getDRAMConsumedJoules: 0 Joules
[Energy_Monitor] getSystemConsumedJoules: 7.3775 Joules

The system consumed joules is less that package consumed joules, what does the system consist of?
Thank you.

@rdementi
Copy link
Contributor

Hi,

the value the system energy metric is retrieved from the MSR_PLATFORM_ENERGY_COUNTER register (Intel Software Developer Manual www.intel.com/sdm):
image

Platform vendor and BIOS communicate the system energy value to the CPU MSR register. Could you please also share the output of pcm utility? Here is a sample output from an HP laptop (the platform and BIOS vendor is HP):

image

The metrics of interest are "SYS energy", "CPU energy", "PP0 energy" and "PP1 energy"

@rdementi
Copy link
Contributor

I checked that the "SYS energy" PCM value on my HP laptop is close to the power meter reading at the wall.

@baihe-liu
Copy link
Author

baihe-liu commented Dec 17, 2024

I checked that the "SYS energy" PCM value on my HP laptop is close to the power meter reading at the wall.

Thank you for the information! It helps a lot. @rdementi
Here is my output of pcm utility. I can get this 'SYS energy' by CLI, is there any way to get this metric in code? I think this 'SYS energy' metric you showed me is different from the value in MSR_PLATFORM_ENERGY_COUNTER register, because I found the value in MSR times the energy unit is quite smaller than CPU energy.
image

@rdementi
Copy link
Contributor

rdementi commented Dec 17, 2024

The API used here is getSystemConsumedJoules :

pcm/src/pcm.cpp

Line 342 in aa70ef5

cout << setNextColor() << " SYS energy: " << getSystemConsumedJoules(sstate1, sstate2) << " J;";

The value from the MSR (MSR_SYS_ENERGY_STATUS = MSR_PLATFORM_ENERGY_COUNTER= 0x64D) is multiplied with the unit:

new CounterWidthExtender::MsrHandleCounter(MSR[socketRefCore[0]], MSR_SYS_ENERGY_STATUS, 0x00000000FFFFFFFF), 32, 10000);

systemState.systemEnergyStatus = system_energy_status->read();

uint64 getSystemConsumedEnergy(const CounterStateType& before, const CounterStateType& after)

auto unit = m->getJoulesPerEnergyUnit();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants