Why Doesn't This Call to 'Poll' Block Correctly on a Sysfs Device Attribute File

Why doesn't this call to `poll` block correctly on a sysfs device attribute file?

To quote some more from the comment you quoted:

Once poll/select indicates that the value has changed, you
need to close and re-open the file, or seek to 0 and read again.

But you do nothing with fds.fd.

Also, do a dummy read() before calling poll();
any newly opened file is considered changed.

Using the Linux sysfs_notify call

The blocking poll is from the user side. User code can simply tell the kernel which attributes it's interested in, then block in a poll() until one of them has changed.

The sysfs_notify() is a kernel-side call that releases the user-space poll(). After you adjust your kernel attribute value, just call sysfs_notify() to allow any user-space applications to respond to their outstanding poll().

Think of the poll() as "subscribing" to notices of a change in an attribute of interest, and sysfs_notify() as "publishing" the change to any subscribers.

select(), poll() or epoll() ? for sysfs attribute

I have found something here that may be of help:

GPIO signals have paths like /sys/class/gpio/gpio42/ (for GPIO #42)
and have the following read/write attributes:

"value" ... reads as either 0 (low) or 1 (high). If the GPIO
is configured as an output, this value may be written;
any nonzero value is treated as high.

If the pin can be configured as interrupt-generating interrupt
and if it has been configured to generate interrupts (see the
description of "edge"), you can poll(2) on that file and
poll(2) will return whenever the interrupt was triggered. If
you use poll(2), set the events POLLPRI and POLLERR. If you
use select(2), set the file descriptor in exceptfds. After
poll(2) returns, either lseek(2) to the beginning of the sysfs
file and read the new value or close the file and re-open it
to read the value.

Although it says it's for "gpio42", I'm guessing this may apply to your case to. If it doesn't, make a comment in my answer.

kstrtol causing looping within class attribute

From the documentation:

store() should return the number of bytes used from the buffer. If the
entire buffer has been used, just return the count argument.

So in your case you may write return count;.



Related Topics



Leave a reply



Submit