Skip to content

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

Closed

Conversation

brosier01
Copy link
Contributor

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.

@zephyrbot zephyrbot added the area: POSIX POSIX API Library label Oct 3, 2024
@zephyrbot zephyrbot requested review from cfriedt and ycsin October 3, 2024 20:35
Copy link

github-actions bot commented Oct 3, 2024

Hello @brosier01, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@cfriedt
Copy link
Member

cfriedt commented Oct 3, 2024

@brosier01 - thanks for the PR 👍

I would make a few suggestions

  1. please keep the PR in draft mode until all tests are passing
  2. please take a look at the most recent implementation attempt
  3. please review the resolved comments in posix: allow for external implementation of option groups #74184 by @keith-packard too.

Thanks!

Comment on lines 12 to 18
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.
Copy link
Member

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.

See e.g.
https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/posix/sys/sysconf.h

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

Comment on lines 9 to 10
default y
depends on POSIX_API
Copy link
Member

@cfriedt cfriedt Oct 3, 2024

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.

Suggested change
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

config POSIX_NUM_PIPES
int "Number of available pipes"
default 2
depends on POSIX_API
Copy link
Member

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.

Suggested change
depends on POSIX_API

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];
Copy link
Member

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.

Copy link
Contributor Author

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

#include <sys/_intsup.h>

#define NUM_PIPES CONFIG_POSIX_NUM_PIPES
#define PIPE_BUFFER_SIZE _POSIX_PIPE_BUF
Copy link
Member

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?

@brosier01 brosier01 marked this pull request as draft October 4, 2024 16:23
@brosier01 brosier01 force-pushed the feature_posix_pipe branch 2 times, most recently from befbc9a to 5f5056f Compare October 5, 2024 19:18
@brosier01 brosier01 marked this pull request as ready for review October 6, 2024 13:53
@brosier01 brosier01 marked this pull request as draft October 6, 2024 13:58
Comment on lines 20 to 22
atomic_t readOpened;
atomic_t writeOpened;
atomic_t isUsed;
Copy link
Member

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

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};
Copy link
Member

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

Suggested change
.ioctl = pipe_ioctl_vmeth};
.ioctl = pipe_ioctl_vmeth,
};

@@ -0,0 +1,124 @@
#include <zephyr/ztest.h>
Copy link
Member

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]>
@brosier01 brosier01 requested review from ycsin and cfriedt November 2, 2024 15:59
Copy link

github-actions bot commented Jan 3, 2025

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.

@github-actions github-actions bot added the Stale label Jan 3, 2025
@github-actions github-actions bot closed this Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: POSIX POSIX API Library Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants