Skip to content

posix: allow for external implementation of option groups #74184

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

cfriedt
Copy link
Member

@cfriedt cfriedt commented Jun 12, 2024

CONFIG_TC_PROVIDES_...

This provides external C libraries with a convenient mechanism for overriding Zephyr's POSIX API, at Option Group granularity.

Each implemented standard POSIX Subprofiing Option Group already has a Kconfig option in Zephyr. This Kconfig option is used to ensure that any appropriate feature test macros are defined (features.h), that any appropriate sysconf() values are returned, and of course to enable compilation of the relevant Zephyr C source files via CMake.

Generally, these existing Kconfig options have the form CONFIG_POSIX_xxxx, where POSIX_xxxx is the name of a standard IEEE 1003.1-2017 Option Group.

We add a number of Kconfig options in Kconfig.toolchain, all of the form CONFIG_TC_PROVIDES_POSIX_xxxx. Selecting these options instruct CMake to bypass the usual rules for compiling Zephyr's implementation of the selected POSIX Option Group.

The TC_PROVIDES Kconfig options are not user configurable, as they are intended to be used primarily by maintainers, and should be selected by a separate Kconfig option.

This is useful, for example, if a specific C library has a smaller, or faster, or more secure version of some POSIX features. Perhaps a vendor has a very specific implementation that is already certified on their device. There could be a number of reasons.

Why only Option Groups? Why not Options?

Subprofiling Option Groups such as POSIX_THREADS_BASE differ from POSIX Options like _POSIX_THREAD_ATTR_STACKADDR in that the Option Group is a mostly autonomous unit of functionality, while Options may just change one aspect of behaviour inside one or more a units of functionality.

The granularity was chosen to be at the Option Group level because implementations are most likely to be cleanly interoperable at Option Group level of abstraction, and because those are the lines officially drawn by IEEE to split up POSIX functionality.

Individual POSIX Options (e.g. _POSIX_THREAD_SAFE_FUNCTIONS) are often not as easily separated from other features that they may be tied to. Moreover, a given function may be required by more than one POSIX Option.

However, we may be able to add similar mechanisms for Options on a case-by-case basis in the future.

@cfriedt cfriedt requested review from keith-packard, galak and ycsin June 12, 2024 16:58
@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch from 349ba9e to 21d736d Compare June 12, 2024 17:02
@cfriedt cfriedt requested a review from stephanosio June 12, 2024 17:02
@cfriedt cfriedt marked this pull request as ready for review June 12, 2024 17:03
@zephyrbot zephyrbot added area: Base OS Base OS Library (lib/os) area: POSIX POSIX API Library area: Samples Samples labels Jun 12, 2024
@cfriedt cfriedt added this to the v3.7.0 milestone Jun 12, 2024
@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch 2 times, most recently from 3a2cffb to b1d303e Compare June 12, 2024 17:19
Copy link
Collaborator

@keith-packard keith-packard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a really nice addition to the environment. Grouping them like this also seems entirely reasonable, and would encourage toolchains to provide complete implementations of an option group rather than cherry-picking individual functions.

@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch from b1d303e to 5aa7ed2 Compare June 12, 2024 20:43
@cfriedt cfriedt requested a review from keith-packard June 12, 2024 20:43
@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch from 5aa7ed2 to 21fcddc Compare June 13, 2024 02:09
@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch from 21fcddc to a172e71 Compare June 14, 2024 01:53
@cfriedt cfriedt requested a review from keith-packard June 14, 2024 01:57
@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch 2 times, most recently from 6a1dc9f to daf5191 Compare June 14, 2024 02:01
keith-packard
keith-packard previously approved these changes Jun 14, 2024
Copy link
Collaborator

@keith-packard keith-packard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add the XSI option groups to this list? Afaict, that would be:

  • CRYPT
  • REALTIME
  • ADVANCED_REALTIME
  • REALTIME_THREADS
  • ADVANCED_REALTIME_THREADS
  • TRACING
  • XSI_STREAMS
  • ENH_I18N
  • SHM

Digging through the POSIX specs to find stuff like this isn't easy; I couldn't find a comprehensive list of things beyond the subprofiling option groups.

Are there dependencies between option groups that we should be validating here? That would require a fairly deep reading of all of these option groups specifications, so I'd be fine with "no" or "maybe later" as answers.

@cfriedt
Copy link
Member Author

cfriedt commented Jun 14, 2024

Do we want to add the XSI option groups to fine with "no" or "maybe later" as answers.

Maybe later is probably safe. If anything, we can say it's a bug to not accurately represent XSI groups.

It's kind of surprising how many option groups there are too.

Also kind of surprising is that there will be another rev to the POSIX spec later this year! It's like the Energizer Bunny!

@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch from e766e33 to d467101 Compare June 15, 2024 00:59
@cfriedt
Copy link
Member Author

cfriedt commented Jun 15, 2024

rebased

@nashif
Copy link
Member

nashif commented Jun 15, 2024

rebased

fix that complaince issue please

Make it easier for external C libraries, toolchains, and
integrators to override Zephyr's implementation of functions and
sybmols on a per-Option-Group basis.

This change adds a number of non-user-configurable Kconfig
options that block internal Cmake rules from building Zephyr's
C sources corresponding to the particular option.

This is useful, for example, if a specific C library has a smaller,
or faster, or more secure  version of some symbols belonging to a
a particular option group.

Signed-off-by: Chris Friedt <[email protected]>
@cfriedt cfriedt force-pushed the posix-pipes-and-custom-option-group-impl branch from d467101 to 925ae8f Compare June 15, 2024 10:34
@aescolar
Copy link
Member

Bulk changing the milestone from everything which did not make it to the v3.7.0 freeze deadline
and which is not labeled as a bug or documentation (or does not appear clearly as only containing
a bug fix or a documentation change).
If you disagree about this change please add the milestone again.

Please note that until rc2 only PRs containing bug fixes, docs and tests can be merged.
After that and until release only bug fixes and docs changes.

Exceptions require approval by the release team and a vote by the TSC.
https://docs.zephyrproject.org/latest/project/release_process.html#stabilization-phase

@aescolar aescolar modified the milestones: v3.7.0, future, v4.0.0 Jun 17, 2024
@cfriedt cfriedt added TSC Topics that need TSC discussion and removed TSC Topics that need TSC discussion labels Jun 17, 2024
@nashif nashif modified the milestones: v4.0.0, v3.7.0 Jun 26, 2024
@nashif nashif merged commit fa9e933 into zephyrproject-rtos:main Jun 26, 2024
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Base OS Base OS Library (lib/os) area: POSIX POSIX API Library area: Samples Samples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants