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

linux: assign CPU temperatures by package/core or CCD #1352

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

leahneukirchen
Copy link

Closes #806.
Closes #1048.
Closes #1176.
Closes #1335.
Addresses #879 (on Linux).

@BenBE BenBE added enhancement Extension or improvement to existing feature Linux 🐧 Linux related issues labels Dec 25, 2023
@leahneukirchen leahneukirchen marked this pull request as draft December 25, 2023 15:46
@leahneukirchen
Copy link
Author

Fixed build without libsensors.

Fixed assignment on RPi.

linux/LibSensors.c Outdated Show resolved Hide resolved
linux/LibSensors.c Outdated Show resolved Hide resolved
linux/LinuxMachine.c Outdated Show resolved Hide resolved
linux/LinuxMachine.c Outdated Show resolved Hide resolved
linux/LinuxMachine.c Outdated Show resolved Hide resolved
@BenBE BenBE added this to the 3.4.0 milestone Dec 26, 2023
@leahneukirchen
Copy link
Author

Note that the cpu are only parsed once, this takes <0.1ms on my machine.

linux/LinuxMachine.c Outdated Show resolved Hide resolved
linux/LinuxMachine.c Outdated Show resolved Hide resolved
linux/LinuxMachine.c Outdated Show resolved Hide resolved
linux/LinuxMachine.c Outdated Show resolved Hide resolved
linux/LibSensors.c Outdated Show resolved Hide resolved
@leahneukirchen
Copy link
Author

I think this is ready to go, should I squash it together sensibly?

@BenBE
Copy link
Member

BenBE commented Jan 17, 2024

I think this is ready to go, should I squash it together sensibly?

As you like. Just took a quick peek at the list of commits and some suggest that they mostly rectify things changed in previous commits of the PR: Those are the prime subjects to squash in the PR right now. So there's not really much to squash together right now AFAICS.

@BenBE BenBE linked an issue Feb 2, 2024 that may be closed by this pull request
@BenBE
Copy link
Member

BenBE commented Feb 2, 2024

@leahneukirchen Anything left to do from your side? If not please mark the PR ready for review. TIA.

@leahneukirchen leahneukirchen marked this pull request as ready for review February 5, 2024 13:30
@@ -603,6 +603,100 @@ static void scanCPUFrequencyFromCPUinfo(LinuxMachine* this) {
}
}

#ifdef HAVE_SENSORS_SENSORS_H
static void LinuxMachine_fetchCPUTopologyFromCPUinfo(LinuxMachine* this) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does similar to scanCPUFrequencyFromCPUinfo() scan /proc/cpuinfo.
Parsing the frequency here should not make a performance difference.
Then scanCPUFrequencyFromSysCPUFreq() can be changed to write its values first to a local array and on success override the frequencies from that array.
Thus /proc/cpuinfo is not scanned multiple times.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we need to move the ifdef HAVE_SENSORS_SENSORS_H into that function, which makes it harder to read I think.

linux/LinuxMachine.c Show resolved Hide resolved
@@ -674,6 +772,13 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
// Initialize CPU count
LinuxMachine_updateCPUcount(this);

#ifdef HAVE_SENSORS_SENSORS_H
// Fetch CPU topology
LinuxMachine_fetchCPUTopologyFromCPUinfo(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe LinuxMachine_fetchCPUTopologyFromCPUinfo() can return whether the topology changed and then LibSensors_countCCDs() and LinuxMachine_assignCCDs() get only called on change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what this means, this code runs only once already?

@fasterit
Copy link
Member

@leahneukirchen Do you want to implement the three review comments from @cgzones ?

@cgzones
Copy link
Member

cgzones commented Apr 18, 2024

I somehow dislike that the sensors are iterated twice: once in LibSensors_countCCDs() and once in LibSensors_getCPUTemperatures().
Do we need to compute the number of ccds beforehand, what about adjusting the CPU data after iterating all sensors (and counting all CCD ones) in LibSensors_getCPUTemperatures() ?

@fasterit
Copy link
Member

I somehow dislike that the sensors are iterated twice: once in LibSensors_countCCDs() and once in LibSensors_getCPUTemperatures(). Do we need to compute the number of ccds beforehand, what about adjusting the CPU data after iterating all sensors (and counting all CCD ones) in LibSensors_getCPUTemperatures() ?

Seconded, libsensors is slow

@eworm-de
Copy link
Contributor

Tested on my notebook with Alder Lake CPU... It shows temperatures for all cores at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Extension or improvement to existing feature Linux 🐧 Linux related issues
Projects
None yet
5 participants