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

NAS-133858 / 25.10 / Make sure CPU temperature is reported for virtual cores #15514

Merged
merged 3 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/freenas/usr/lib/netdata/python.d/cputemp.chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from copy import deepcopy
from third_party import lm_sensors as sensors

from middlewared.utils.cpu import amd_cpu_temperatures, generic_cpu_temperatures, cpu_info

from middlewared.utils.cpu import amd_cpu_temperatures, cpu_info, generic_cpu_temperatures

CPU_TEMPERATURE_FEAT_TYPE = 2

Expand Down Expand Up @@ -77,13 +76,24 @@ def get_data(self):

data = {}
total_temp = 0
cinfo = cpu_info()
for core, temp in cpu_temps.items():
data[f'cpu{core}'] = temp
total_temp += temp
try:
# we follow the paradigm that htop uses
# for filling in the hyper-threaded ids
# temperatures. (i.e. we just copy the
# temp of the parent physical core id)
data[cinfo['ht_map'][f'cpu{core}']] = temp
total_temp += temp
except KeyError:
continue

if total_temp:
data['cpu'] = total_temp / len(data.keys())
return data or ({f'cpu{i}': 0 for i in range(cpu_info()['core_count'])} | {'cpu': 0})
data['cpu'] = total_temp / len(data)

return data or ({f'cpu{i}': 0 for i in range(cinfo['core_count'])} | {'cpu': 0})

def check(self):
try:
Expand Down
8 changes: 4 additions & 4 deletions src/middlewared/middlewared/utils/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class CpuInfo(typing.TypedDict):
physical_core_count: int
"""The total number of physical CPU cores"""
ht_map: dict[str, str]
"""A mapping of hyper-threaded ids to their
parent physical core id
(i.e. {"cpu8": "cpu0", "cpu9": "cpu1"})"""
"""A mapping of physical core ids to their
hyper-threaded ids
(i.e. {"cpu0": "cpu8", "cpu1": "cpu9"})"""


@functools.cache
Expand Down Expand Up @@ -78,7 +78,7 @@ def cpu_info_impl() -> CpuInfo:
# This means `cpu0` is a physical core because
# the `0` in `cpu0` matches the first number
# in the file (0,8)
ht_map[i.name] = f'cpu{pcid}'
ht_map[f'cpu{pcid}'] = i.name
except FileNotFoundError:
continue

Expand Down