-
Notifications
You must be signed in to change notification settings - Fork 7.4k
posix: pipe: Implement POSIX-compliant pipes #79393
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
Conversation
Hello @brosier01, and thank you very much for your first pull request to the Zephyr project! |
@brosier01 - thanks for the PR 👍 I would make a few suggestions
Thanks! |
lib/posix/options/Kconfig.pipe
Outdated
config POSIX_NUM_PIPES | ||
int "Number of available pipes" | ||
default 2 | ||
depends on POSIX_API | ||
help | ||
Specify the number of POSIX pipes available in the system. | ||
This value controls how many pipes can be created concurrently. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better if this option was named somewhat more conventionally like other *_MAX
values.
Additionally, you will need a Kconfig option for POSIX_PIPE_BUF
, as well as a feature test macro and sysconf enumeration.
See e.g.
main...cfriedt:zephyr:posix-pipes2
lib/posix/options/Kconfig.pipe
Outdated
default y | ||
depends on POSIX_API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should depend on I guess FDTABLE
and maybe some other options. Kconfig.net
might have some hints.
default y | |
depends on POSIX_API |
Can you please ensure POSIX_PIPE
is selected with CONFIG_POSIX_AEP_REALTIME_DEDICATED
?
Also, below this, please add
if POSIX_PIPE
...
endif
lib/posix/options/Kconfig.pipe
Outdated
config POSIX_NUM_PIPES | ||
int "Number of available pipes" | ||
default 2 | ||
depends on POSIX_API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this dependency as POSIX_API will likely be deprecated soon.
depends on POSIX_API |
lib/posix/options/pipe.c
Outdated
static int pipe_ioctl_vmeth(void *obj, unsigned int request, va_list args); | ||
|
||
struct pipe_desc { | ||
unsigned char __aligned(4) ring_buffer[_POSIX_PIPE_BUF]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zephyr has a ring-buffer implementation. It should be used here as well, I would guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi cfriedt,
My implementation of the posix pipe is based on the ZEPHYR pipe and it needs an aligned(4) buffer to be initialized
lib/posix/options/pipe.c
Outdated
#include <sys/_intsup.h> | ||
|
||
#define NUM_PIPES CONFIG_POSIX_NUM_PIPES | ||
#define PIPE_BUFFER_SIZE _POSIX_PIPE_BUF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be overuse of macros. Maybe consider just using CONFIG_POSIX_PIPE_BUF
?
befbc9a
to
5f5056f
Compare
5f5056f
to
0d21c1a
Compare
lib/posix/options/pipe.c
Outdated
atomic_t readOpened; | ||
atomic_t writeOpened; | ||
atomic_t isUsed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convert these to snake_case
lib/posix/options/pipe.c
Outdated
static struct fd_op_vtable fs_fd_op_vtable = {.read = pipe_read_vmeth, | ||
.write = pipe_write_vmeth, | ||
.close = pipe_close_vmeth, | ||
.ioctl = pipe_ioctl_vmeth}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you put a comma ,
at the end, clang-format will be able to format this nicely for you
.ioctl = pipe_ioctl_vmeth}; | |
.ioctl = pipe_ioctl_vmeth, | |
}; |
@@ -0,0 +1,124 @@ | |||
#include <zephyr/ztest.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs the license identifier
This change introduces a POSIX-compliant pipe feature into Zephyr RTOS. The POSIX_PIPE is required for PSE53 conformance. The pipe implementation includes non-blocking and blocking behavior for pipe read/write operations, adhering to the POSIX standard. The pipe implementation includes atomic synchronization mechanisms to handle multiple readers and writers, ensuring thread safety. Tested using ZTEST framework, validating both blocking and non-blocking behaviors with various pipe buffer sizes. Test cases include handling full and empty pipes, ensuring correct behavior when multiple threads attempt simultaneous reads and writes. Signed-off-by: Bruce Rosier <[email protected]>
0d21c1a
to
574df27
Compare
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
This change introduces a POSIX-compliant pipe feature into Zephyr RTOS. The POSIX_PIPE is required for PSE53 conformance.
The pipe implementation includes non-blocking and blocking behavior for pipe read/write operations, adhering to the POSIX standard. The pipe implementation includes atomic synchronization mechanisms to handle multiple readers and writers, ensuring thread safety.
Tested using ZTEST framework, validating both blocking and non-blocking behaviors with various pipe buffer sizes. Test cases include handling full and empty pipes, ensuring correct behavior when multiple threads attempt simultaneous reads and writes.