summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-08-01 12:39:39 +1000
committerDamien George <damien@micropython.org>2023-08-07 12:11:40 +1000
commitef71028f77e4a6fc449c64906ebad0a160f35240 (patch)
tree5d57456261db48eecc98d0cccb5428eb46e71cfa /py
parentebc655634650274727c71881e0d36ff738793928 (diff)
extmod/modselect: Add optimisation to use system poll when possible.
A previous commit removed the unix-specific select module implementation and made unix use the common one. This commit adds an optimisation so that the system poll function is used when polling objects that have a file descriptor. With this optimisation enabled, if code registers both file-descriptor-based objects, and non- file-descriptor-based objects with select.poll() then the following occurs: - the system poll is called for all file-descriptor-based objects with a timeout of 1ms - then the bare-metal polling implementation is used for remaining objects, which calls into their ioctl method (which can be in C or Python) In the case where all objects have file descriptors, the system poll is called with the full timeout requested by the caller. That makes it as efficient as possible in the case everything has a file descriptor. Benefits of this approach: - all ports use the same select module implementation - the unix port now supports polling of all objects and matches bare metal implementations - it's still efficient for existing cases where only files and sockets are polled (on unix) - the bare metal implementation does not change - polling of SSL objects will now work on unix by calling in to the ioctl method on SSL objects (this is required for asyncio ssl support) Note that extmod/vfs_posix_file.c has poll disable when the optimisation is enabled, because the code is not reachable when the optimisation is used. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py')
-rw-r--r--py/mpconfig.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index c617f573b..4a15205ae 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -1485,11 +1485,16 @@ typedef double mp_float_t;
#define MICROPY_PY_ERRNO_ERRORCODE (1)
#endif
-// Whether to provide "select" module (baremetal implementation)
+// Whether to provide "select" module
#ifndef MICROPY_PY_SELECT
#define MICROPY_PY_SELECT (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
#endif
+// Whether to enable POSIX optimisations in the "select" module (requires system poll)
+#ifndef MICROPY_PY_SELECT_POSIX_OPTIMISATIONS
+#define MICROPY_PY_SELECT_POSIX_OPTIMISATIONS (0)
+#endif
+
// Whether to enable the select() function in the "select" module (baremetal
// implementation). This is present for compatibility but can be disabled to
// save space.