-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
lib: pure: selectors: for Nuttx, change ioselectors to use "select". #21384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: pure: selectors: for Nuttx, change ioselectors to use "select". #21384
Conversation
d812aab
to
96a0d41
Compare
Isn't epoll with a limit smaller than 1024 the better solution? |
@Araq I guess it depends on the RAM capacity of the board, etc., but it seems to be 255 by default.
If using this value instead of 1024 with "when defined(nuttx):", it may not interfere even with EPOLL. |
Would the following changes be acceptable?
|
Even for MCUs as shown below, LIBC_OPEN_MAX was set to 255 unless config was explicitly changed. https://www.st.com/en/microcontrollers-microprocessors/stm32l476rg.html
It may be safer to set it to "select". |
96a0d41
to
3905702
Compare
…s internal implementation. When I first ported NuttX, used "EPOLL" because "select" seemed to leak memory. However, the number of fd allocated by default in newSelector() is 1024, which is a lot for a small MCU, so I changed the implementation to select. Signed-off-by: Takeyoshi Kikuchi <[email protected]>
3905702
to
a6f8e44
Compare
Yes, exactly. Assuming that it is more efficient for the OS. |
I see. |
I would like to get some input from the NuttX OS internal implementation perspective, so I will discuss this with the NuttX community. |
@Araq They said that a patch was applied last year and that EPOLL is now the fastest. |
I don't understand the question, tbh. Add a |
I found this value in NuttX config.
How about the following changes instead of this pull request? diff --git a/lib/posix/posix_other_consts.nim b/lib/posix/posix_other_consts.nim
index 506c92158..08069fe9a 100644
--- a/lib/posix/posix_other_consts.nim
+++ b/lib/posix/posix_other_consts.nim
@@ -750,3 +750,6 @@ var SEEK_SET* {.importc: "SEEK_SET", header: "<unistd.h>".}: cint
var SEEK_CUR* {.importc: "SEEK_CUR", header: "<unistd.h>".}: cint
var SEEK_END* {.importc: "SEEK_END", header: "<unistd.h>".}: cint
+# <nuttx/config.h>
+when defined(nuttx):
+ var NEPOLL_MAX* {.importc: "CONFIG_FS_NEPOLL_DESCRIPTORS", header: "<nuttx/config.h>".}: cint
diff --git a/lib/pure/ioselects/ioselectors_epoll.nim b/lib/pure/ioselects/ioselectors_epoll.nim
index 8526eb8a3..621fa9a9e 100644
--- a/lib/pure/ioselects/ioselectors_epoll.nim
+++ b/lib/pure/ioselects/ioselectors_epoll.nim
@@ -72,11 +72,16 @@ type
SelectEvent* = ptr SelectEventImpl
proc newSelector*[T](): Selector[T] =
+ proc initialNumFD(): int {.inline.} =
+ when defined(nuttx):
+ result = NEPOLL_MAX
+ else:
+ result = 1024
# Retrieve the maximum fd count (for current OS) via getrlimit()
var maxFD = maxDescriptors()
doAssert(maxFD > 0)
# Start with a reasonable size, checkFd() will grow this on demand
- const numFD = 1024
+ let numFD = initialNumFD()
var epollFD = epoll_create1(O_CLOEXEC)
if epollFD < 0: I am concerned that the initial fd numbers other than NuttX will change from |
That should be fine. |
@Araq |
When I first ported NuttX, used "EPOLL" because "select" seemed to leak memory.
However, the number of fd allocated by default in newSelector() is 1024,
which is a lot for a small MCU, so I changed the implementation to select.
This implementation tested with Jester, on Cortex-A5 platform.