Skip to contentSkip to conversation

docs: gpio: prefer pread(2) for interrupt reading

PATCH In review Huichun Feng 3 participants 7 messages May 14, 2024 – Jun 3, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs: gpio: prefer pread(2) for interrupt reading

In legacy sysfs GPIO, when using poll(2) on the sysfs GPIO value for state change awaiting, a subsequent read(2) is required for consuming the event, which the doc recommends the use of lseek(2) or close-and-reopen to reset the file offset afterwards.

The recommendations however, require at least 2 syscalls to consume the event. Gladly, use of pread(2) require only 1 syscall for the consumption. Let's advertise this usage by prioritizing its placement.

---
 Documentation/driver-api/gpio/legacy.rst   | 6 ++++--
 Documentation/userspace-api/gpio/sysfs.rst | 7 ++++---
 2 files changed, 8 insertions(+), 5 deletions(-)
Documentation/driver-api/gpio/legacy.rst +4 -2
index b6505914791c..c1a083444b0c 100644
@@ -648,8 +648,10 @@ and have the following read/write attributes:
 		poll(2) will return whenever the interrupt was triggered. If
 		you use poll(2), set the events POLLPRI. 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.
+		use pread(2) to read the value at offset zero. Alternatively,
+		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.
 
 	"edge" ... reads as either "none", "rising", "falling", or
 		"both". Write these strings to select the signal edge(s)
Documentation/userspace-api/gpio/sysfs.rst +4 -3
index 116921048b18..bd64896de91a 100644
@@ -97,9 +97,10 @@ and have the following read/write attributes:
 		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.
+		poll(2) returns, use pread(2) to read the value at offset
+		zero. Alternatively, 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.
 
 	"edge" ...
 		reads as either "none", "rising", "falling", or
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Huichun Feng

In legacy sysfs GPIO, when using poll(2) on the sysfs GPIO value for state change awaiting, a subsequent read(2) is required for consuming the event, which the doc recommends the use of lseek(2) or close-and-reopen to reset the file offset afterwards.

The recommendations however, require at least 2 syscalls to consume the event. Gladly, use of pread(2) require only 1 syscall for the consumption. Let's advertise this usage by prioritizing its placement.

LGTM, thanks!

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#2 lore raw
In reply to Huichun Feng

Kindly ping.

Sorry that the last ping wasn't sent in plain text.

Huichun Feng <[email protected]> 於 2024年5月14日 週二 下午12:12寫道:

Quoted 54 lines

In legacy sysfs GPIO, when using poll(2) on the sysfs GPIO value for state change awaiting, a subsequent read(2) is required for consuming the event, which the doc recommends the use of lseek(2) or close-and-reopen to reset the file offset afterwards.

The recommendations however, require at least 2 syscalls to consume the event. Gladly, use of pread(2) require only 1 syscall for the consumption. Let's advertise this usage by prioritizing its placement.

---
 Documentation/driver-api/gpio/legacy.rst   | 6 ++++--
 Documentation/userspace-api/gpio/sysfs.rst | 7 ++++---
 2 files changed, 8 insertions(+), 5 deletions(-)
Documentation/driver-api/gpio/legacy.rst +4 -2
index b6505914791c..c1a083444b0c 100644
@@ -648,8 +648,10 @@ and have the following read/write attributes:
                poll(2) will return whenever the interrupt was triggered. If
                you use poll(2), set the events POLLPRI. 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.
+               use pread(2) to read the value at offset zero. Alternatively,
+               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.
 
        "edge" ... reads as either "none", "rising", "falling", or
                "both". Write these strings to select the signal edge(s)
Documentation/userspace-api/gpio/sysfs.rst +4 -4
index 116921048b18..bd64896de91a 100644
@@ -97,9 +97,10 @@ and have the following read/write attributes:
                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.
+               poll(2) returns, use pread(2) to read the value at offset
+               zero. Alternatively, 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.
 
        "edge" ...
                reads as either "none", "rising", "falling", or
--

2.34.1

#3 lore raw
Quoted 6 lines · Huichun Feng

Kindly ping.

Sorry that the last ping wasn't sent in plain text.

Please don't ping me on the morning of the day after the merge window closes. I don't pick up patches for the next release during the merge window (like most maintainers) and I need some time to catch up on my queue during rc1.

Bart

#4 lore raw
In reply to Huichun Feng
Quoted 6 lines · Huichun Feng

In legacy sysfs GPIO, when using poll(2) on the sysfs GPIO value for state change awaiting, a subsequent read(2) is required for consuming the event, which the doc recommends the use of lseek(2) or close-and-reopen to reset the file offset afterwards.

Quoted 6 lines

The recommendations however, require at least 2 syscalls to consume the event. Gladly, use of pread(2) require only 1 syscall for the consumption. Let's advertise this usage by prioritizing its placement.

---

This doesn't apply on top of gpio/for-next, please rebase and resend.

Bart

#5 lore raw

PATCH 1/1 docs: gpio: prefer pread(2) for interrupt reading

In legacy sysfs GPIO, when using poll(2) on the sysfs GPIO value for state change awaiting, a subsequent read(2) is required for consuming the event, which the doc recommends the use of lseek(2) or close-and-reopen to reset the file offset afterwards.

The recommendations however, require at least 2 syscalls to consume the event. Gladly, use of pread(2) require only 1 syscall for the consumption. Let's advertise this usage by prioritizing its placement.

---
 Documentation/userspace-api/gpio/sysfs.rst | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
Documentation/userspace-api/gpio/sysfs.rst +4 -3
index 116921048..bd64896de 100644
@@ -97,9 +97,10 @@ and have the following read/write attributes:
 		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.
+		poll(2) returns, use pread(2) to read the value at offset
+		zero. Alternatively, 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.
 
 	"edge" ...
 		reads as either "none", "rising", "falling", or
Signature · 1 line
2.34.1
#6 lore raw
Quoted 34 lines · Huichun Feng

In legacy sysfs GPIO, when using poll(2) on the sysfs GPIO value for state change awaiting, a subsequent read(2) is required for consuming the event, which the doc recommends the use of lseek(2) or close-and-reopen to reset the file offset afterwards.

The recommendations however, require at least 2 syscalls to consume the event. Gladly, use of pread(2) require only 1 syscall for the consumption. Let's advertise this usage by prioritizing its placement.

---
 Documentation/userspace-api/gpio/sysfs.rst | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
Documentation/userspace-api/gpio/sysfs.rst +4 -4
index 116921048..bd64896de 100644
@@ -97,9 +97,10 @@ and have the following read/write attributes:
                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.
+               poll(2) returns, use pread(2) to read the value at offset
+               zero. Alternatively, 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.
 
        "edge" ...
                reads as either "none", "rising", "falling", or
--
Quoted 2 lines

2.34.1

Please don't send new versions of a patch as responses in an email thread. Otherwise tools such as b4 cannot tell if it's a new version or part of a larger series. Please always start a new thread with get send-email or - better yet - start using b4 and let it manage the series for you. Please resend this correctly.

Bart