Search code examples
modulelinux-kernelsysfs

Which filesystem to use to expose readings/limits for temperature sensor


I currently have the trouble of some hardware overheating regularly. Looking through the Linux kernel, I found that the thermal sensors are currently fully supported, however the preconfigured limits seem much too high. I am currently looking to modify the kernel module, but I am not sure what would be the best way to modify it. I would like the following:

  • Have a file somewhere, where I can read the current temperature
  • Have a couple of files I can use from userspace to modify the current limits

Now I am not sure what virtual file interface I should use for this. So far I see the following options:

  • Expose all data via the /dev/ filesystem, use ioctl() to modify limits
  • Add the files in sysfs
  • Add the files in debugfs

I am not sure what the pros and cons of each of these methods would be. So far I have looked at sysfs, and it seems that this is not the right way to go. The number of sensors is highly hardware dependent, and I would have to add various hacks to get one file per sensor (or one directory per sensor), possibly adding another kobject for each sensor so I can add files in the resulting directory. Previously the sensor data seemed to have been available through /sys/class/hwmon/hwmon0/device/temp1_input, however it was removed there.

debugfs also does not seem like the right way to go, since I am not so much interested in kernel debugging, but rather providing a nicer way to configure and read the sensors.

devfs however seems like a lot of overkill for such a simple setup.

What would be the best way to expose the sensor data and make the limits configurable through user space?


Solution

  • According to Documentation/hwmon/sysfs-interface, temp[1-*]_max and temp[1-*]_crit are already defined for that pupose and should be implemented read-write when possible. If that is not already the case for your driver, then that is what you want to implement.