summaryrefslogtreecommitdiff
path: root/bin
diff options
authorJeremy Szu <jeremy.szu@canonical.com>2021-01-08 00:21:32 +0800
committerJeremy Szu <jeremy.szu@canonical.com>2021-01-08 00:21:32 +0800
commit90125cbb435846c4809d77223393dd54389276e6 (patch)
tree0f9ab2a03dd41d9e31da8e983ed1e5a0f2083fc9 /bin
parent7748fd527657de4b90aedb738191e9500ec0be48 (diff)
parent350ca9e240d4b4c767bb71c1b9f9a4b22b309f2a (diff)
Merge branch 'lp1903653' into HEAD
Diffstat (limited to 'bin')
-rw-r--r--[-rwxr-xr-x]bin/fan_reaction_test.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/bin/fan_reaction_test.py b/bin/fan_reaction_test.py
index c37054b..3b2257e 100755..100644
--- a/bin/fan_reaction_test.py
+++ b/bin/fan_reaction_test.py
@@ -30,20 +30,45 @@ class FanMonitor:
"""Device that reports fan RPM or something correlating to that."""
def __init__(self):
"""Use heuristics to find something that we can read."""
+ self.hwmons = []
self._fan_paths = glob.glob('/sys/class/hwmon/hwmon*/fan*_input')
- if not self._fan_paths:
+ # All entries (except name) under /sys/class/hwmon/hwmon/* are optional
+ # and should only be created in a given driver if the chip has
+ # the feature.
+ # Use fan*_input is because the "thinkpad_hwmon" driver is report
+ # fan_input only. If there is any driver has different implementation
+ # then may need to check other entries in the future.
+ for i in self._fan_paths:
+ device = os.path.join(os.path.dirname(i), 'device')
+ device_path = os.path.realpath(device)
+ # Get the class of pci device of hwmon whether is GPU.
+ if "pci" in device_path:
+ pci_class_path = os.path.join(device, 'class')
+ try:
+ with open(pci_class_path, 'r') as _file:
+ pci_class = _file.read().splitlines()
+ pci_device_class = (
+ int(pci_class[0], base=16) >> 16) & 0xff
+ """Make sure the fan is not on graphic card"""
+ if pci_device_class == 3:
+ continue
+ except OSError:
+ print('Not able to access {}'.format(pci_class_path))
+ continue
+ self.hwmons.append(i)
+ if not self.hwmons:
print('Fan monitoring interface not found in SysFS')
raise SystemExit(0)
def get_rpm(self):
result = {}
- for p in self._fan_paths:
+ for p in self.hwmons:
try:
with open(p, 'rt') as f:
fan_mon_name = os.path.relpath(p, '/sys/class/hwmon')
result[fan_mon_name] = int(f.read())
except OSError:
- print('Fan SysFS node dissappeared ({})'.format(p))
+ print('Fan SysFS node disappeared ({})'.format(p))
return result
def get_average_rpm(self, period):