[SOLVED] reading from hwmon temperature sensor 103
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi,
i'm trying to write a driver which reads from "/sys/class/hwmon/hwmon0/temp1_input" on user space.
The first read is successful, but then from the second read I get only zero values.
Reading from the FD works only when closing and reopening the FD again.
is there a way/example how to read from hwmon without reopening & closing each time the FD?
again, I suggest looking at other apps that tap into the temps of systems and see how they are doing it so you can get a better understanding of what needs to be done, and how.
see post #3
The sysfs filesystem is a pseudo-filesystem which provides an interface to kernel data structures. (More precisely, the files and directories in sysfs provide a view of the kobject structures defined internally within the kernel.) The files under sysfs provide information about devices, kernel modules, filesystems, and other kernel components.
and from the kernel source file /Documentation/filesystems/sysfs.txt mentioned in the SEE ALSO section of the man page
Quote:
Attributes can be exported for kobjects in the form of regular files in the filesystem. Sysfs forwards file I/O operations to methods defined for the attributes, providing a means to read and write kernel attributes.
In line with the *nix philosophy that everything is a file, the information is returned on reading the file. The file needs to be read again to get updated data.
Using pan64's reference, I'd instead not try to read a /sys file and instead try to register a callback or obtain the actual structure from the driver, which contains the relevant information you need.
From the kernel source file /Documentation/filesystems/sysfs.txt with emphasis added by me.
Quote:
sysfs allocates a buffer of size (PAGE_SIZE) and passes it to the
method. Sysfs will call the method exactly once for each read or
write. This forces the following behavior on the method
implementations:
- On read(2), the show() method should fill the entire buffer.
Recall that an attribute should only be exporting one value, or an
array of similar values, so this shouldn't be that expensive.
This allows userspace to do partial reads and forward seeks
arbitrarily over the entire file at will. If userspace seeks back to
zero or does a pread(2) with an offset of '0' the show() method will
be called again, rearmed, to fill the buffer.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.