Commit Graph
151 Commits
Author SHA1 Message Date
Aurelien Jarno 6282f6925a Emit missing sensor warning only if SENSORS_SYSFS_ROOT is defined
The lm-sensors library is widely used in various software, which could
be run in VMs where HWMON support may be absent (e.g. cloud kernels in
Debian). To avoid a confusing "/sys: No sensors at /sys/class/hwmon" on
the console or in the logs, only emit the message if the user specifies
an alternative path through SENSORS_SYSFS_ROOT. This behavior mirrors
what is done for the "Not a sysfs mount" message.

Fixes: 89548dab2a ("Add SENSORS_SYSFS_ROOT environment support")
2026-04-21 13:43:41 +02:00
Michael Lettrich 01359701a2 [FIX] ISA sysfs address parsing allow dashes
The ISA sensor chip address is obtained by parsing the hwmon
 `/sysfs` device path. The regular expression extracting the
device address will fail if the device name contains dashes and
sets the address to 0. If  multiple instances of the same
board are plugged into the same system, cards can no longer be
distinguished, because their addresses will be set to 0 incorrectly.

This fix changes the address-parsing regular expression to recognize
device names with dashes.
2026-04-21 13:34:11 +02:00
xaizek 62a9553191 pwm: fix bad scaling due to use of integer type
This fixes commit c1a1f4ff20 ("pwm: Move
scaling factor from sensors prog to library") which didn't account for
return type of `get_type_scaling()` being `int` rather than `double` or
`float`, so the scaling was done by a factor of 2 instead of 2.55, thus
making the result off by quite a lot.

ms: adjust test
2026-04-21 13:24:21 +02:00
Michal Suchanek 89548dab2a Add SENSORS_SYSFS_ROOT environment support
With this the hardcoded /sys location for reading sensor data can be
changed. In particular it makes it possible to tar up the /sys directory
when a problem is encountered, and then reproduce it on another system.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2024-01-07 21:20:39 +01:00
Michal Suchanek 3bbd975860 quantity: Add enumeration type
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2024-01-06 23:05:07 +01:00
Michal Suchanek 297b050d3d sysfs: Add function for determining feature quantity 2023-12-28 13:02:33 +01:00
Michal Suchanek 6fa5cba2e3 sysfs: Do not prescale frequency to MHz
Add autoscaling in the output instead.

Fixes: 54363271 ("libsensors + sensors: Add freq_input support")
2023-12-27 14:57:05 +01:00
Michal Suchanek fceeee0543 sysfs: Multiplier 1 is the default, no need to list it.
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2023-12-27 13:40:53 +01:00
Michal Suchanek c1a1f4ff20 pwm: Move scaling factor from sensors prog to library
Fixes: a6ec549e ("sensors: Add support for pwm sensors")
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2023-12-27 13:17:28 +01:00
Michal Suchanek b76cd8a5f6 sysfs: Specific match has to go before generic match
This is not really a problem when the specific scaling factors happen to
be for factors not matched by a generic match but this may not hold in
general over time.

Fixes: 1bd92120 ("Fill the magnitude field of dynamically generated device entries.")
2023-12-27 13:17:16 +01:00
Michal Suchanek 43b6101bb0 sysfs: Expand filename buffer to quiet warning
The GCC heurisitc says that the buffer can overflow by 2 bytes, expand
it.
2023-12-26 16:35:46 +01:00
Michal Suchanek 82ca61b38a sysfs: remove unused variable
Fixes: e5e053bb ("libsensors: Avoid non-symlink sysfs device entries")
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2023-12-25 19:34:29 +01:00
Michal Suchanek c91425c121 Merge branch 'thomab/freq' of ~/gitea/data/gitea-repositories/hramrach/lm-sensors 2023-12-24 12:28:52 +01:00
hramrach fbdf135806 Merge pull request 'sensors: Add support for rated values' (#358) from cpackham-atlnz/rated-values into master
Reviewed-on: http://localhost:8888/hramrach/lm-sensors/pulls/358
2023-12-24 12:24:56 +01:00
hramrach e7ecb0b92f Merge pull request 'Pwm' (#363) from Wer-Wolf/pwm into master
Reviewed-on: http://localhost:8888/hramrach/lm-sensors/pulls/363
2023-12-24 12:06:18 +01:00
hramrach 9b1a3974bb Merge pull request 'Add support for dev_name formatted like "a000000.wifi"' (#410) from 7217043955/master into master
Reviewed-on: http://localhost:8888/hramrach/lm-sensors/pulls/410
2023-12-24 11:59:38 +01:00
Chen-Yu Tsai c3ce1320aa libsensors: Add support for SENSORS_BUS_TYPE_SDIO
Some SDIO drivers, namely WiFi adapter drivers, include hwmon support.

Add support for parsing the device name, so they don't get treated as
platform / virtual devices.

Signed-off-by: Chen-Yu Tsai <wenst@google.com>
2023-05-08 15:03:26 +08:00
Chen-Yu Tsai e5e053bbb7 libsensors: Avoid non-symlink sysfs device entries
Devices under the MMC / SDIO bus have a "device" entry that is not a
symbolic link; instead it contains the device ID of the SDIO device.
This causes the sysfs parsing code in libsensors to error out, as it
expects all "device" entries be symbolic links to the underlying device.

Check for non-symlink entries before calling realpath() to avoid using
it as a valid device link.

Signed-off-by: Chen-Yu Tsai <wenst@google.com>
2023-05-08 14:38:41 +08:00
7217043955 6da486d741 Add support for dev_name formatted like "a000000.wifi" 2022-09-06 15:48:11 +08:00
Armin Wolf 109b988f1a libsensors: Add support for pwm
Add support for the pwm sensor interface.
This includes support for pwm[1-*], pwm[1-*]_enable,
pwm[1-*]_mode and pwm[1-*]_freq.
2021-08-28 07:58:54 +02:00
Chris Packham 88f6c5ec9b sensors: Add support for rated values
Sysfs attributes for rated values were recently added to the kernel[1].
This adds support for displaying them in lm-sensors.

[1] - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e8e61235

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
2021-08-12 15:07:38 +12:00
thomb 543632712e libsensors + sensors: Add freq_input support 2021-06-21 20:54:18 +02:00
Hoan Tran 00a5fadd2e Add ISA ACPI sensor driver name support
ACPI hwmon sensor driver name has a different format such as
	APMC0D29:00
	APMC0D29:01
compared with DTB. This patch supports this format and gives
the correct device address as below

apm_xgene-isa-0000   => APMC0D29:00
Adapter: ISA adapter
SoC Temperature:  +35.0°C
CPU power:        11.00 W
IO power:         20.00 W

apm_xgene-isa-0001   => APMC0D29:01
Adapter: ISA adapter
SoC Temperature:  +33.0°C
CPU power:        13.00 W
IO power:         23.83 W

Signed-off-by: Hoan Tran <hoan@os.amperecomputing.com>
2020-08-20 18:28:17 +02:00
Ondřej Lysoněk 7e976f1325 libsensors: Treat devices without a known ancestor bus as virtual
Currently only hwmon devices that don't have a parent device are treated
as virtual. Let's extend the concept to hwmon devices, that don't have
a *recognized ancestor* device (hwmon devices that according to the kernel
don't reside on a bus that we recognize). This change is meant to address
cases where a hwmon device has a thermal class device for a parent, but
the thermal class device doesn't have a parent device.

These kind of hwmon devices started appearing in the 4.19 kernel
due to commit f6b6b52ef7a54160c0. It was not reported as a kernel
regression and fixed in the kernel, because according to
Documentation/admin-guide/sysfs-rules.rst, the change was OK to make
(it says "Position of devices along device chain can change").

Fixes #139

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
2018-11-23 12:17:01 +01:00
Ondřej Lysoněk d4cb932567 libsensors: Consider all ancestor devices when determining bus type
Go through all ancestor devices of a hwmon device until we find a device
that resides on a bus that we recognize. This change is meant to address
hwmon devices that don't reside directly on a bus, but have another
device in the middle of the hiearchy. For example:
ACPI device -> thermal device -> hwmon device

These kind of hwmon devices started appearing in the 4.19 kernel
due to commit f6b6b52ef7a54160c0. It was not reported as a kernel
regression and fixed in the kernel, because according to
Documentation/admin-guide/sysfs-rules.rst, the change was OK to make
(it says "Position of devices along device chain can change").

Fixes #133

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
2018-11-23 12:16:52 +01:00
Ondřej Lysoněk 567e6a3b36 libsensors: Pass a resolved device path to sensors_read_one_sysfs_chip
According to Documentation/admin-guide/sysfs-rules.rst, the "device"
link "must never appear in any path as an element". This patch makes
lm_sensors respect that.

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
2018-11-23 11:33:05 +01:00
Ondřej Lysoněk 6ac43308b5 libsensors: Rename a local variable
Rename a local variable to make it consistent with other parts of the
code. The variable is called (more descriptively) "dev_name"
in sensors_read_one_sysfs_chip(), so let's rename it to that.

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
2018-11-23 11:33:05 +01:00
Ondřej Lysoněk 0fbfc3b6e0 libsensors: Refactor bus type identification into a separate function
Refactor bus type identification into a separate function in order to
make the code more readable and easier to maintain.

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
2018-11-23 11:33:05 +01:00
Ondřej Lysoněk 0cb449735f libsensors: Refactor device classification into a separate function
Refactor device classification into a separate function in order to
make the code more readable and easier to maintain.

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
2018-11-23 11:33:05 +01:00
Guenter Roeck 09a60b9065 libsensors: Add support for SENSORS_BUS_TYPE_SCSI
Upcoming kernel drivers may add SCSI bus based sensors.
Add support for it to libsensors.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
2018-08-11 11:59:14 -07:00
Andrew Lunn dcf23676cc sensors: Add support for power min, lcrit, min_alarm, lcrit_alarm
SFP modules measure the transmit power of the lazer. The sensor has
expected minimum values, and alarms when these minimams are reached.
Add support to sensors to print these.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
2018-06-29 12:29:46 -07:00
Andrew Lunn 0880db23b9 Add support for MDIO busses
Marvell Ethernet PHYs can contain a temperature sensor, which the kernel
exports as an HWMON device. The PHY is on an MDIO bus. Add support for
this bus types to libsensors. The sensor is then displayed by sensors(1):

socaipsbus02100000ethernet02188000mdioswitch0mdio01-mdio-1
Adapter: MDIO adapter
temp1:        +54.0°C  (crit = +100.0°C)

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
2017-07-08 20:19:13 -07:00
Jean Delvare f09b1c6483 libsensors: Add support for temp[1-*]_min_hyst and temp[1-*]_lcrit_hyst
Add support for sysfs attributes temp[1-*]_min_hyst (already
implemented by drivers adt7x10, lm77 and lm92) and
temp[1-*]_lcrit_hyst (no known users yet.)
2014-04-22 08:05:14 +00:00
Jean Delvare eb5cf8b2ec Update my e-mail address and copyright years 2014-03-20 10:23:35 +00:00
Jean Delvare c29be769f1 libsensors: Avoid insane memory allocations
While there is no longer a hard limit to the number of sensor of a
given type per chip, I feel a little uncomfortable having no limit at
all on the amount of memory we may try to allocate. Add an arbitrary
safety limit so that a design error or a bug in a hwmon driver can't
result into an insane memory allocation.
2014-01-30 12:45:23 +00:00
Jean Delvare b9361dc088 libsensors: Adjust memory pre-allocation steps
Make memory pre-allocation steps depend on the sensor type. Things like
voltages, temperatures or fans are typically plenty, however vid and
chassis intrusion are typically only a few, and there can only be one
beep_enable by design. This saves a small amount of temporary memory
for cheap.
2014-01-29 14:39:34 +00:00
Jean Delvare 0159202226 libsensors: Get rid of FEATURE_SIZE
max_subfeatures is computed the first time it is needed, we can do
exactly the same with FEATURE_SIZE. Introduce feature_size as a static
variable so that we don't have to recompute it again and again.
2014-01-29 14:11:12 +00:00
Jean Delvare 883f4e49a3 libsensors: Get rid of arbitrary limit on per-type sensor count
When gathering the attributes of each hwmon chip, libsensors uses a
temporary structure in memory to order and group all the attributes
into features. This temporary structure used to be a single array with
room for every possible attribute/subfeature. While simple, this
approach required to predefine a maximum number of per-type sensor
that could be handled.

In order to get rid of this arbitrary limit, which we hit and had to
raise three times already, I changed the temporary structure to an
array of dynamically allocated per-type subattribute arrays. This lets
us not allocate any memory for types which aren't implemented by a
given chip, and more importantly, this lets us reallocate room for
more attributes of a given type as needed.

I decided to allocate chunks of 8 attributes at a time, as this seemed
a good compromise between two frequent reallocations and
over-provisioning. It could be tweaked if needed.

Icing on the cake, I benchmarked this change on two different systems
and it results in performance gains. The total heap usage as reported
by valgrind is down by 50% on average, with peak memory consumption
(as reported by valgrind's massif) also down by 43% on average. The
total instructions count (as reported by valgrind's callgrind) is down
by 11% on average, with measured execution time also down by a few
percents. Valgrind rocks, BTW.

I have some ideas to optimize the memory allocations further, but I do
not expect such a huge gain from them. They may not even improve peak
memory consumption as massif shows the peak is somewhere else now at
least in some cases.
2014-01-29 09:25:31 +00:00
Jean Delvare 18853526ec libsensors: rename function sensors_compute_max
The new function name, sensors_compute_max_sf, better reflects what
the function is actually doing.
2014-01-28 21:47:41 +00:00
Jean Delvare 2252b49e2b libsensors: Increase MAX_SENSORS_PER_TYPE to 33
This is needed to properly support all temperatures reported by the
coretemp driver on recent hardware.
2014-01-14 14:49:04 +00:00
Jean Delvare a3e40509e0 Add support for fan[1-*]_max, fan[1-*]_min_alarm and fan[1-*]_max_alarm
attributes. These are defined in the standard sysfs interface for quite
some time, and at least three drivers (max6650, lm63 and applesmc)
implement them so we should support them.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@6029 7894878c-1315-0410-8ee3-d5d059ff63e0
2012-03-06 07:34:13 +00:00
Jean Delvare ae32c8a919 Upcoming change in sysfs will break the way libsensors detects if
sysfs is mounted. Adjust the implementation so that it still works after
said change.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@6017 7894878c-1315-0410-8ee3-d5d059ff63e0
2012-01-31 12:54:03 +00:00
Guenter Roeck 273102f2c9 Add support for additional sysfs attributes to libsensors and to sensors command
inX_average
inX_lowest
inX_highest
tempX_lowest
tempX_highest
currX_average
currX_lowest
currX_highest




git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@6007 7894878c-1315-0410-8ee3-d5d059ff63e0
2012-01-09 17:30:10 +00:00
Guenter Roeck eaf86b0c49 Added support for SENSORS_SUBFEATURE_FAN_PULSES to libsensors.
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5938 7894878c-1315-0410-8ee3-d5d059ff63e0
2011-03-04 20:37:43 +00:00
Guenter Roeck c618c56023 Added support for humidity sensors to libsensors
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5918 7894878c-1315-0410-8ee3-d5d059ff63e0
2011-02-13 18:55:09 +00:00
Guenter Roeck fb325cf089 Add support for recently added sysfs ABI attributes
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5917 7894878c-1315-0410-8ee3-d5d059ff63e0
2011-02-09 19:25:22 +00:00
Guenter Roeck 443b54b325 Added support for new sysfs attributes
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5898 7894878c-1315-0410-8ee3-d5d059ff63e0
2010-12-14 20:26:27 +00:00
Jean Delvare ff0bfc174d Compute MAX_*_SENSOR_TYPES at build time (#2378).
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5897 7894878c-1315-0410-8ee3-d5d059ff63e0
2010-12-14 09:09:42 +00:00
Jean Delvare a29f126e08 Compute MAX_SUBFEATURES at run-time (#2378).
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5896 7894878c-1315-0410-8ee3-d5d059ff63e0
2010-12-14 09:06:19 +00:00
Jean Delvare 05a24e5bb2 libsensors: Add support for intrusion detection.
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5879 7894878c-1315-0410-8ee3-d5d059ff63e0
2010-11-03 13:00:59 +00:00