1

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?

3
  • The question seems Too broad/Primary opinion-based for me... There is no well-formed border even between sysfs/debugfs. As for /dev, it is dependent, whether device may represent the sensor, which is very subjective. As for me, sysfs is the most suitable place for expose limit of the sensor.
    – Tsyvarev
    Nov 23, 2015 at 16:54
  • @Tsyvarev: Yeah, I wasn't sure if it might not be too broad or elicit too much discussion. I was hoping for some general rules, but as you say I am not even sure about the clear line between sysfs and debugfs. I was not sure if sysfs is the right place because of stackoverflow.com/questions/19529018/… and stackoverflow.com/a/19671817/663957.
    – LiKao
    Nov 23, 2015 at 20:03
  • Questions you refer to don't disallow such things under /sys, they just recommend to use device representation for them. (And this device is something another essence then one under /dev).
    – Tsyvarev
    Nov 23, 2015 at 20:48

2 Answers 2

2

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.

2
  • Thanks for the tip, that really looks like the best place to put that data. As far as I can see for this I have to somehow register the device with the hwmon driver, is that correct?
    – LiKao
    Nov 25, 2015 at 21:45
  • That would be preferable but it is not strictly necessary. Nov 26, 2015 at 10:30
1

No need to expose the file system for the temperature sensors. Register your temperature sensor as thermal zone using thermal framework and you give get /sysfs interface. which can be used from user-space. Go through the below link to know how to access it from user-space.

https://www.lookup2learn.com/post/thermal-management-in-linux

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.