diff options
author | Ondřej Lysoněk <olysonek@redhat.com> | 2018-10-05 17:54:47 +0200 |
---|---|---|
committer | Ondřej Lysoněk <olysonek@redhat.com> | 2018-10-05 17:59:30 +0200 |
commit | c755805cef0c6b90e57c8d29a151452463f516f6 (patch) | |
tree | 7d64ec007c456cc6ce1daa51df8b677ffab746fe /prog | |
parent | 35d2443488f011b17061edf10f9e2173c0379f33 (diff) | |
download | lm-sensors-git-c755805cef0c6b90e57c8d29a151452463f516f6.tar.gz |
Add the find-driver script
The script is meant to identify the driver and kernel module responsible
for exporting a given hardware monitoring chip.
Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
Diffstat (limited to 'prog')
-rw-r--r-- | prog/debug/README | 25 | ||||
-rwxr-xr-x | prog/debug/find-driver | 88 |
2 files changed, 113 insertions, 0 deletions
diff --git a/prog/debug/README b/prog/debug/README new file mode 100644 index 00000000..9e49f9fe --- /dev/null +++ b/prog/debug/README @@ -0,0 +1,25 @@ +This directory contains tools which may help with debugging lm_sensors. + +find-driver +=========== +If the 'sensors' program does not report useful values for certain hardware +monitoring inputs, the problem in most cases is not in lm_sensors. lm_sensors +only reads values exported by the Linux kernel. Finding the driver responsible +for exporting the particular hardware monitoring chip may help to diagnose +the problem further. It is possible that there is a bug in the driver, however +it is even more likely that the input is simply not used on your board. +Nonetheless, identifying the driver may help you identify the piece of hardware +that reports the bogus value. + +This script finds the driver and kernel module responsible for exporting +a hardware monitoring chip in sysfs. It should be given the chip name (as +reported by the 'sensors' program) as argument. For example: + +$ sensors +thinkpad-isa-0000 +Adapter: ISA adapter +fan1: 0 RPM + +$ ./find-driver thinkpad-isa-0000 +Driver: thinkpad_hwmon +Module: thinkpad_acpi diff --git a/prog/debug/find-driver b/prog/debug/find-driver new file mode 100755 index 00000000..0cc001d0 --- /dev/null +++ b/prog/debug/find-driver @@ -0,0 +1,88 @@ +#!/bin/bash +# +# find-driver - find the driver exporting a chip as reported by 'sensors' +# Copyright (C) 2018 Ondřej Lysoněk +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +shopt -s nullglob + +function usage() { + echo "Usage: $0 <chip name>" >&2 + echo >&2 + echo 'Chip name is a string in the format <chip>-<bus>-<address>' >&2 + echo 'as reported by the "sensors" program. For example the chip' >&2 + echo 'name can be "coretemp-isa-0000" or "acpitz-virtual-0".' >&2 +} + +function get_chip() { + echo "$1" | sed -r -e 's/^(.+)-[^-]+-[^-]+$/\1/' +} + +if [ "$#" -lt 1 ]; then + usage + exit 1 +fi +ARG=$1; shift +if [ "$ARG" = "-h" ] || [ "$ARG" = "--help" ]; then + usage + test "$#" -eq 0 + exit +elif [ "$ARG" = "-d" ] || [ "$ARG" = "--debug" ]; then + test "$#" -eq 1 || { usage; exit 1; } + set -x + CHIP=$(get_chip "$1") +else + test "$#" -eq 0 || { usage; exit 1; } + CHIP=$(get_chip "$ARG") +fi + +DEVICE= +for i in /sys/class/hwmon/hwmon*; do + NAME= + if [ -f "$i/name" ]; then + NAME=$(cat "$i/name") + elif [ -L "$i/device" ]; then + TARGET=$(readlink -f "$i/device") + if [ -f "$TARGET/name" ]; then + NAME=$(cat "$TARGET/name") + fi + fi + if [ "$NAME" = "$CHIP" ]; then + DEVICE="$i" + break + fi +done +test -n "$DEVICE" || { echo 'Chip not found.' >&2; exit 1; } + +DRIVER=unknown +MODULE=unknown +while true; do + if [ -L "$DEVICE/driver" ]; then + DRIVER_DIR=$(readlink -f "$DEVICE/driver") + DRIVER=$(basename "$DRIVER_DIR") + if [ -L "$DRIVER_DIR/module" ]; then + MODULE=$(basename $(readlink "$DRIVER_DIR/module")) + fi + break + elif [ -L "$DEVICE/device" ]; then + DEVICE=$(readlink -f "$DEVICE/device") + else + break + fi +done + +echo "Driver: $DRIVER" +echo "Module: $MODULE" |