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

Sensors@claudiux: Add cpu power consumption tab #6518

Open
fzamperin opened this issue Oct 21, 2024 · 8 comments
Open

Sensors@claudiux: Add cpu power consumption tab #6518

fzamperin opened this issue Oct 21, 2024 · 8 comments

Comments

@fzamperin
Copy link

fzamperin commented Oct 21, 2024

Applet name and maintainer

Sensors@claudiux @claudiux

What would you like to see?

@claudiux Thanks for this amazing Applet! Being using it for years!

I have a suggestion for a new Feature, I want to measure my CPU power consumption, I have a 13700K and I see that I can get the power consumption in Joules from: /sys/class/powercap/intel-rapl/*/energy_uj. At first I tried to tweak into lm_sensors to see if I can grab this value to make the Applet display it from sensors but it didn't work. Do you think we can work to make this happen? As of right now I just know about Raptor Lake consumption but I think other processors output the power different way.

Let me know if you find that this is interesting somehow. Thanks!

@claudiux
Copy link
Member

@fzamperin
Thanks for your interesting PR.
On my computer, access to this data requires root rights (with sudo). Is there any other way to get it?

@fzamperin
Copy link
Author

I was doing some research but so far didn't find a way to fetch it :/

@fzamperin
Copy link
Author

fzamperin commented Oct 25, 2024

@claudiux After doing an extensive search it's not possible to catch the value without sudo privilege. Can we work this around? I don't know exactly the architecture and environment about applets on cinnamon but I'm willing to help with the implementation.

Other tools like Turbostat only work with root privilegies also.

@claudiux
Copy link
Member

All the solutions I envisage would create a safety problem. I prefer not to implement them. I'll keep thinking about it.

@fzamperin
Copy link
Author

UPDATE

I was able to make this work without sudo, it uses this tool: https://github.com/intel/pcm

I ran a docker container using the pcm tool from intel and was able to fetch the values, so I created this dummy code just to test:

const { Message, Session } = imports.gi.Soup;

const session = new Session();
session.timeout = 2;
const url = 'http://localhost:9738/persecond/1';

function fetchCPUInformation() {
  const message = Message.new('GET', url);
  message.request_headers.append('Accept', 'application/json');
  const result = session.send_and_read(message, null);
  const data = result.get_data();
  const responseString = new TextDecoder('utf-8').decode(data);
  return JSON.parse(responseString);
}

function addWattageToTooltip(tooltips) {
  const result = fetchCPUInformation();
  let joules = result['Uncore Aggregate']['Uncore Counters']['Package Joules Consumed'];

  tooltips.push(`${joules} W`);
}

module.exports = {
  addWattageToTooltip
}

Then added it on the applets.js to see if it works, I'm just not quite sure if this works on other cpus like AMD or ARM

image

@claudiux
Copy link
Member

@fzamperin +1!

Please create a PR including changes in .js scripts and in settings-schema.json.

@claudiux claudiux reopened this Nov 25, 2024
@fzamperin
Copy link
Author

@claudiux After a quick research, I saw that only Intel cpus are supported using the PCM tool, do you want me to create a PR only for Intel? And then we can see how to support AMD or ARM?

Let me know your thoughts.

@claudiux
Copy link
Member

@fzamperin Yes, but please only display these options when PCM tools are available and usable.

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

No branches or pull requests

2 participants