-
Notifications
You must be signed in to change notification settings - Fork 7.4k
posix: implement sysconf()
#56670
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
Labels
Comments
There are many reasons to use However, even several internal POSIX function implementations could use it. E.g. the |
This was referenced Apr 8, 2023
This was referenced Jul 5, 2023
sysconf()
awojasinski
added a commit
to awojasinski/zephyr
that referenced
this issue
Jan 30, 2024
The patch introduces basic implementation of sysconf() function. It's based on macro - that means that every function call is resolved at compile time - and is not fully complient with POSIX standard (the errno value is not handled and passing invalid name argument results in compilation error). Treat this commit as a starting point for proper sysconf() implementation. The one introduced in the patch could stay as a defult implementation. sysconf() documentation: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html https://man7.org/linux/man-pages/man3/sysconf.3.html Fixes zephyrproject-rtos#56670 Signed-off-by: Adam Wojasinski <[email protected]>
carlescufi
pushed a commit
that referenced
this issue
Jan 30, 2024
The patch introduces basic implementation of sysconf() function. It's based on macro - that means that every function call is resolved at compile time - and is not fully complient with POSIX standard (the errno value is not handled and passing invalid name argument results in compilation error). Treat this commit as a starting point for proper sysconf() implementation. The one introduced in the patch could stay as a defult implementation. sysconf() documentation: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html https://man7.org/linux/man-pages/man3/sysconf.3.html Fixes #56670 Signed-off-by: Adam Wojasinski <[email protected]>
pdgendt
pushed a commit
to pdgendt/zephyr
that referenced
this issue
Jan 30, 2024
The patch introduces basic implementation of sysconf() function. It's based on macro - that means that every function call is resolved at compile time - and is not fully complient with POSIX standard (the errno value is not handled and passing invalid name argument results in compilation error). Treat this commit as a starting point for proper sysconf() implementation. The one introduced in the patch could stay as a defult implementation. sysconf() documentation: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html https://man7.org/linux/man-pages/man3/sysconf.3.html Fixes zephyrproject-rtos#56670 Signed-off-by: Adam Wojasinski <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Is your enhancement proposal related to a problem? Please describe.
The
sysconf()
utility is actually quite fantastic to have available for any POSIX environment. For the most part, it is used to have a portable way to query standard system limits that do not change after initialization (including those that are compile-time constant).Describe the solution you'd like
An implementaiton of
sysconf()
, possibly with a space-optimized versionThis is one of those interesting cases where you could provide a "small, medium, and large" configuration, cc @stephanosio.
XS: O(1) time, O(1) space
Completed entirely via macros. Not POSIX-ly correct. Would be compile-time const only. Likely would not even compile if an invalid argument is provided, which would be kind of desireable. Would not work for dynamic queries - e.g.
int n; sysconf(n)
.Basically free and carefree. This should probably be the default.
S: O(n) time, O(n) space
Linear search through the n enabled options, where it's possible that n < k, where k is the minimum number of supported sysconf keys. Not POSIX-ly correct. Not able to distinguish between an invalid value and a value that is not supported.
M: O(1) time, O(m) space
LUT made of the m maximum sysconf options that Zephyr supports, where m >= k, the minimum number required to be POSIX-ly correct. This method is able to distinguish between invalid and unsupported arguments.
While this is constant is size, it is spatially unstable if the key-space is sparse. Specifically, that would be the case when the libc did not use a contiguous key space (starting at 0, ideally).
It would probably be desireable in this case to have a
BUILD_ASSERT()
that checks the size of the table (implies the key-space is contiguous).To give an idea of the space requirements, there are currently 125 required sysconf keys. On 64-bit systems, a long is 8 bytes, so this would be 1000 bytes alone.
L: O(log(m)) time, O(m) space
A binary search through the m maximum sysconf options that Zephyr supports. Same definition as above for k. This method is able to distinguish between invalid and unsupported arguments. It supports a sparse set of keys.
The
bsearch()
standard library call can be used here. If keys cannot be sorted at build time in a compile-time const way, then there can be aSYS_INIT()
call that reorders them in RAM, at the expense of RAM.Describe alternatives you've considered
Not implementing the sysconf POSIX feature.
Additional context
https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html
https://man7.org/linux/man-pages/man3/sysconf.3.html
The text was updated successfully, but these errors were encountered: