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

acpitz-virtual-0 is gone in newer kernel(s) such as 4.19-rc5 when compared to 4.18.9 #133

Closed
ghost opened this issue Sep 27, 2018 · 11 comments

Comments

@ghost
Copy link

ghost commented Sep 27, 2018

dmesg diff:

-Linux version 4.18.0-rc8-g1ffaddd029c8 (fastnstable@tempshade) (gcc version 8.1.1 20180531 (GCC)) #8 SMP PREEMPT Mon Aug 6 04:26:35 CEST 2018
+Linux version 4.19.0-rc5-g6bf4ca7fbc85 (fastnstable@tempshade) (gcc version 8.2.1 20180831 (GCC)) #9 SMP PREEMPT Tue Sep 25 21:55:49 CEST 2018
-ACPI: Core revision 20180531
+ACPI: Core revision 20180810
+ACPI: Added _OSI(Linux-Lenovo-NV-HDMI-Audio)
-ACPI: Thermal Zone [TZS0] (59 C)
-ACPI: Thermal Zone [TZS1] (47 C)
-ACPI: Battery Slot [BAT0] (battery present)
+ACPI: Thermal Zone [TZS0] (55 C)
+ACPI: Thermal Zone [TZS1] (43 C)
+battery: ACPI: Battery Slot [BAT0] (battery present)

sensors in 4.18.0-rc8:

k10temp-pci-00c3
Adapter: PCI adapter
CPU temp:     +48.1°C  (high = +70.0°C)
                       (crit = +100.0°C, hyst = +99.0°C)

acpitz-virtual-0
Adapter: Virtual device
CPU temp:     +48.0°C  (crit = +98.0°C)
MOBO temp:    +44.0°C  (crit = +126.0°C)

radeon-pci-0008
Adapter: PCI adapter
gfx card:     +48.0°C  (crit = +120.0°C, hyst = +90.0°C)

total 0
drwxr-xr-x 3 root root    0 27.09.2018 04:20 ./
drwxr-xr-x 3 root root    0 27.09.2018 04:20 ../
drwxr-xr-x 2 root root    0 27.09.2018 04:21 power/
-r--r--r-- 1 root root 4096 27.09.2018 04:21 name
lrwxrwxrwx 1 root root    0 27.09.2018 04:20 subsystem -> ../../../../class/hwmon/
-r--r--r-- 1 root root 4096 27.09.2018 04:21 temp1_crit
-r--r--r-- 1 root root 4096 27.09.2018 04:21 temp1_input
-r--r--r-- 1 root root 4096 27.09.2018 04:21 temp2_crit
-r--r--r-- 1 root root 4096 27.09.2018 04:21 temp2_input
-rw-r--r-- 1 root root 4096 27.09.2018 04:21 uevent

sensors in 4.19-rc5 with the below patch:

k10temp-pci-00c3
Adapter: PCI adapter
CPU temp:     +44.9°C  (high = +70.0°C)
                       (crit = +100.0°C, hyst = +99.0°C)

acpitz-acpi-0
Adapter: ACPI interface
temp1:        +44.0°C  (crit = +98.0°C)
temp2:        +42.0°C  (crit = +126.0°C)

radeon-pci-0008
Adapter: PCI adapter
gfx card:     +49.0°C  (crit = +120.0°C, hyst = +90.0°C)

$ ls -la /sys/class/hwmon/hwmon0/
total 0
drwxr-xr-x 3 root root    0 27.09.2018 04:26 ./
drwxr-xr-x 4 root root    0 27.09.2018 04:26 ../
drwxr-xr-x 2 root root    0 27.09.2018 04:42 power/
lrwxrwxrwx 1 root root    0 27.09.2018 04:26 device -> ../../thermal_zone0/
-r--r--r-- 1 root root 4096 27.09.2018 04:26 name
lrwxrwxrwx 1 root root    0 27.09.2018 04:26 subsystem -> ../../../../../class/hwmon/
-r--r--r-- 1 root root 4096 27.09.2018 04:38 temp1_crit
-r--r--r-- 1 root root 4096 27.09.2018 04:38 temp1_input
-r--r--r-- 1 root root 4096 27.09.2018 04:38 temp2_crit
-r--r--r-- 1 root root 4096 27.09.2018 04:38 temp2_input
-rw-r--r-- 1 root root 4096 27.09.2018 04:26 uevent

[...]

lrwxrwxrwx 1 root root 0 27.09.2018 02:59 /sys/class/hwmon/hwmon0/device/device/subsystem -> ../../../../bus/acpi/
lrwxrwxrwx 1 root root 0 27.09.2018 02:59 /sys/class/hwmon/hwmon0/device/subsystem -> ../../../../class/thermal/

poc naive (but working) patch:

diff --git a/lib/sysfs.c b/lib/sysfs.c
index 6a3c8fa8..b10eae4f 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -666,6 +666,10 @@ static int sensors_read_one_sysfs_chip(const char *dev_path,
 		subsys = strrchr(subsys_path, '/') + 1;
 	}
 
+  if (0 == strncmp(subsys,"thermal",8)) {
+    snprintf(linkpath, NAME_MAX, "%s/device", dev_path); // add another "/device" ie. /sys/class/hwmon/hwmon0/device/device/subsystem->../../../../bus/acpi/ is good but /sys/class/hwmon/hwmon0/device/subsystem->../../../../class/thermal/ isn't
+    return sensors_read_one_sysfs_chip(linkpath, dev_name, hwmon_path);
+  } else
 	if ((!subsys || !strcmp(subsys, "i2c")) &&
 	    sscanf(dev_name, "%hd-%x", &entry.chip.bus.nr,
 		   &entry.chip.addr) == 2) {
@olysonek
Copy link
Contributor

Hm, apparently "accessing attributes reached by a symlink pointing to another device, like the "device"-link, is a bug in the application":
https://github.com/torvalds/linux/blob/7876320f88802b22d4e2daf7eb027dd14175a0f8/Documentation/admin-guide/sysfs-rules.rst

But lm_sensors already does that. I have a feeling that fixing this is going to be a lot of fun...

Thanks for the report.

@olysonek
Copy link
Contributor

Ok, I think I know how to fix this. I'll do that during the weekend probably. The key is the "Position of devices along device chain can change." bullet in that document.

@groeck
Copy link
Contributor

groeck commented Oct 7, 2018

Problem is caused by commit f6b6b52ef7a5 ("thermal_hwmon: Pass the originating device down to hwmon_device_register_with_info") in the upstream thermal subsystem code. The thermal subsystem now passes the thermal device as parent to the hwmon subsystem.
lm-sensors needs to know the hwmon parent device type to determine the bus and chip address. The poc above doesn't do that, which could result in problems if there is more than one thermal device in the system. Otherwise it is a step into the right direction.

@olysonek
Copy link
Contributor

olysonek commented Oct 8, 2018

Right. I've hacked up a poc patch for this last week, but I haven't got around to refactor it yet. Sorry for not updating this issue with that.
b24abd4

@kukabu
Copy link

kukabu commented Oct 25, 2018

I have the same issue with Raspberry Pi (BCM2835_THERMAL module).
@olysonek, your patch doesn't work for me.
now I use the workaround:

--- sysfs.c.orig        2018-10-25 08:28:35.055617851 +0400
+++ sysfs.c     2018-10-25 08:29:15.905213226 +0400
@@ -717,6 +717,10 @@
                /* As of kernel 2.6.32, the hid device names don't look good */
                entry.chip.bus.nr = bus;
                entry.chip.addr = id;
+       } else if (subsys && !strcmp(subsys, "thermal")) {
+               entry.chip.bus.type = SENSORS_BUS_TYPE_VIRTUAL;
+               entry.chip.bus.nr = 0;
+               entry.chip.addr = 0;
        } else {
                /* Ignore unknown device */
                err = 0;

@olysonek
Copy link
Contributor

@kukabu Sorry for the late reply. Did you use the whole branch or just the patch I linked? There's one more patch you need: 420c38f

If you used that patch as well, can you please run the following script to find out what the underlying subsystem is? Change /sys/class/hwmon/hwmon4 to the correct hwmon chip.

dev=/sys/class/hwmon/hwmon4
while true; do
	if [ -L "$dev/subsystem" ]; then
		subsystem=$(basename $(readlink "$dev/subsystem"))
		echo "$dev: $subsystem"
	fi
	if [ -L "$dev/device" ]; then
		dev=$(readlink -f "$dev/device")
	else
		break
	fi
done

Btw, what kernel are you running? I don't get any hwmon chips exported on my RPi, even with older kernels (I do have CONFIG_THERMAL_HWMON enabled).

@kukabu
Copy link

kukabu commented Oct 31, 2018

@kukabu Sorry for the late reply. Did you use the whole branch or just the patch I linked? There's one more patch you need: 420c38f

I tried branch wip_fix_sysfs_access, it works for me. Thanks.

If you used that patch as well, can you please run the following script to find out what the underlying subsystem is? Change /sys/class/hwmon/hwmon4 to the correct hwmon chip.

/sys/class/hwmon/hwmon0: hwmon
/sys/devices/virtual/thermal/thermal_zone0: thermal

Btw, what kernel are you running? I don't get any hwmon chips exported on my RPi, even with older kernels (I do have CONFIG_THERMAL_HWMON enabled).

I uses the custom kernel based on rpi-4.19.y branch with workaround https://gist.github.com/kukabu/d2dc9eebd4133846f07fdc692fccec4c

@olysonek
Copy link
Contributor

I tried branch wip_fix_sysfs_access, it works for me. Thanks.

Good, I'll use the idea of that patch then. I'll just try to refactor it.

@olysonek
Copy link
Contributor

olysonek commented Nov 6, 2018

The following branch contains the fix I'd like to use (the last two commits being most significant). I'd appreciate any testing or review.
https://github.com/lm-sensors/lm-sensors/tree/WIP_fix_bus_identification

@kukabu
Copy link

kukabu commented Nov 7, 2018

This branch works for me.

ds3231-i2c-1-68
Adapter: bcm2835 I2C adapter
temp1:        +31.8°C  

cpu_thermal-virtual-0
Adapter: Virtual device
temp1:        +51.9°C  (crit = +80.0°C)

rpi_volt-isa-0000
Adapter: ISA adapter
in0:              N/A  

@ghost
Copy link
Author

ghost commented Nov 12, 2018

The following branch contains the fix I'd like to use (the last two commits being most significant). I'd appreciate any testing or review.
https://github.com/lm-sensors/lm-sensors/tree/WIP_fix_bus_identification

Didn't look at the code, but tested it to work for me with kernel v4.20-rc1
Cheers!


$ sensors
k10temp-pci-00c3
Adapter: PCI adapter
CPU temp:     +53.6°C  (high = +70.0°C)
                       (crit = +100.0°C, hyst = +99.0°C)

acpitz-acpi-0
Adapter: ACPI interface
CPU temp:     +54.0°C  (crit = +98.0°C)
MOBO temp:    +48.0°C  (crit = +126.0°C)

radeon-pci-0008
Adapter: PCI adapter
gfx card:     +51.0°C  (crit = +120.0°C, hyst = +90.0°C)

-----------

$ which sensors
/usr/bin/sensors
-----------

$ pacman -Qo /usr/bin/sensors
/usr/bin/sensors is owned by lm_sensors 3.4.0+5207+778964e8-1
-----------
$ uname -a
Linux z5 4.20.0-rc1-g651022382c7f #19 SMP PREEMPT Mon Nov 5 13:39:05 CET 2018 x86_64 GNU/Linux

commit 778964e85f2f94367ece31ffddf5927a029d503d (HEAD -> makepkg, origin/WIP_fix_bus_identification)

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

No branches or pull requests

3 participants