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

Added device address in temperature sensors dict #2304

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

a13ssandr0
Copy link

Summary

  • OS: KUbuntu 23.04
  • Bug fix: yes
  • Type: core
  • Fixes: Added device address in temperature sensors dict

Description

Some systems, like mine, may have multiple temperature devices, like two nvme SSDs, both under the same name, in my case 'nvme'. lm-sensors solves this problem adding, at the end of the device name, interface name, root bridge number (bus number) and device number.
I solved the problem getting the address from /sys/class/hwmon/hwmonX/device/address when present, it existed for my two SSDs and on another PC with only one nvme SSD, so I think every PCIe device with sensors (discovered by the system) will have this file.

psutil.sensors_temperatures() before this fix:

{'nvme': [shwtemp(label='Composite', current=46.85, high=84.85, critical=84.85),
          shwtemp(label='Sensor 1', current=46.85, high=65261.85, critical=65261.85),
          shwtemp(label='Sensor 2', current=47.85, high=65261.85, critical=65261.85),
          shwtemp(label='Composite', current=39.85, high=81.85, critical=84.85),
          shwtemp(label='Sensor 1', current=39.85, high=65261.85, critical=65261.85),
          shwtemp(label='Sensor 2', current=42.85, high=65261.85, critical=65261.85)],
 'coretemp': [shwtemp(label='Package id 0', current=36.0, high=88.0, critical=98.0),
              shwtemp(label='Core 12', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 13', current=34.0, high=88.0, critical=98.0),
              shwtemp(label='Core 0', current=36.0, high=88.0, critical=98.0),
              shwtemp(label='Core 1', current=34.0, high=88.0, critical=98.0),
              shwtemp(label='Core 2', current=36.0, high=88.0, critical=98.0),
              shwtemp(label='Core 3', current=34.0, high=88.0, critical=98.0),
              shwtemp(label='Core 5', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 6', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 10', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 11', current=36.0, high=88.0, critical=98.0)],
 'nct6798': [shwtemp(label='SYSTIN', current=35.0, high=80.0, critical=80.0),
             shwtemp(label='PCH_CPU_TEMP', current=0.0, high=None, critical=None),
             shwtemp(label='CPUTIN', current=40.0, high=80.0, critical=80.0),
             shwtemp(label='AUXTIN0', current=50.5, high=None, critical=None),
             shwtemp(label='AUXTIN1', current=16.0, high=None, critical=None),
             shwtemp(label='AUXTIN2', current=25.0, high=None, critical=None),
             shwtemp(label='AUXTIN3', current=64.0, high=None, critical=None),
             shwtemp(label='PECI Agent 0 Calibration', current=40.0, high=None, critical=None),
             shwtemp(label='PCH_CHIP_CPU_MAX_TEMP', current=0.0, high=None, critical=None),
             shwtemp(label='PCH_CHIP_TEMP', current=0.0, high=None, critical=None)]}

psutil.sensors_temperatures() after this fix:

{'nvme-b400': [shwtemp(label='Composite', current=46.85, high=84.85, critical=84.85),
               shwtemp(label='Sensor 1', current=46.85, high=65261.85, critical=65261.85),
               shwtemp(label='Sensor 2', current=47.85, high=65261.85, critical=65261.85)],
 'nvme-b300': [shwtemp(label='Composite', current=39.85, high=81.85, critical=84.85),
               shwtemp(label='Sensor 1', current=39.85, high=65261.85, critical=65261.85),
               shwtemp(label='Sensor 2', current=42.85, high=65261.85, critical=65261.85)],
 'coretemp': [shwtemp(label='Package id 0', current=36.0, high=88.0, critical=98.0),
              shwtemp(label='Core 12', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 13', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 0', current=36.0, high=88.0, critical=98.0),
              shwtemp(label='Core 1', current=34.0, high=88.0, critical=98.0),
              shwtemp(label='Core 2', current=36.0, high=88.0, critical=98.0),
              shwtemp(label='Core 3', current=34.0, high=88.0, critical=98.0),
              shwtemp(label='Core 5', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 6', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 10', current=35.0, high=88.0, critical=98.0),
              shwtemp(label='Core 11', current=36.0, high=88.0, critical=98.0)],
 'nct6798': [shwtemp(label='SYSTIN', current=35.0, high=80.0, critical=80.0),
             shwtemp(label='PCH_CPU_TEMP', current=0.0, high=None, critical=None),
             shwtemp(label='CPUTIN', current=40.0, high=80.0, critical=80.0),
             shwtemp(label='AUXTIN0', current=50.5, high=None, critical=None),
             shwtemp(label='AUXTIN1', current=16.0, high=None, critical=None),
             shwtemp(label='AUXTIN2', current=25.0, high=None, critical=None),
             shwtemp(label='AUXTIN3', current=64.0, high=None, critical=None),
             shwtemp(label='PECI Agent 0 Calibration', current=40.0, high=None, critical=None),
             shwtemp(label='PCH_CHIP_CPU_MAX_TEMP', current=0.0, high=None, critical=None),
             shwtemp(label='PCH_CHIP_TEMP', current=0.0, high=None, critical=None)]}

@@ -1345,6 +1345,18 @@ def sensors_temperatures():
current = float(bcat(path)) / 1000.0
path = os.path.join(os.path.dirname(base), 'name')
unit_name = cat(path).strip()

address = os.path.join(os.path.dirname(base), 'device', 'address')
Copy link
Owner

Choose a reason for hiding this comment

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

What's the content of this file? Can you paste it here? The parsing logic that you apply later on:

unit_name += '-' + ''.join(cat(address).strip().split(':')[1:3]).split('.')[0]

...looks a bit convoluted, so I'd like to simplify it if possible.

Copy link
Author

Choose a reason for hiding this comment

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

Of course, I have two files:

  • /sys/class/hwmon/hwmon0/device/address containing
    0000:b3:00.0
  • /sys/class/hwmon/hwmon1/device/address containing
    0000:b4:00.0

These correspond to the PCIe locations of my SSDs (more about pcie addressing here https://dassencio.org/75)

domain:bus:device.function
0000  :b3 :00    .0

The line you asked me about:

  1. takes the content of the file (stripping any white-spaces)
cat(address).strip()
# '0000:b3:00.0'
  1. splits the content at each :
cat(address).strip().split(':')
# ['0000', 'b3', '00.0']
  1. discards the domain number (quite always zero), takes the second and third part of the address (bus, device and function number)
cat(address).strip().split(':')[1:3]
# ['b3', '00.0']
  1. joins them together
''.join(cat(address).strip().split(':')[1:3])
# 'b300.0'
  1. splits the string at the . and then takes only the first part (function number is not needed since SSDs will only have one function, ones with more are not likely to have more sensors on different functions)
''.join(cat(address).strip().split(':')[1:3]).split('.')[0]
# 'b300'
  1. finally appends the address to the unit name separated by a -
unit_name += '-' + ''.join(cat(address).strip().split(':')[1:3]).split('.')[0]

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

Successfully merging this pull request may close these issues.

2 participants