Part 1
요약·해설
POSIX-1.2017, PSE51~54, Zephyr application 예제와 legacy CONFIG_POSIX_API 대체 방법을 설명합니다.
Single process
Base · PSE51-54
Subprofiles · Options
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
EE79E93C498B41042F5A7EDF6B272BBA94BF221F51C666EBDAD07ADD097141AD
.. _posix_overview:
Overview
########
The Portable Operating System Interface (POSIX) is a family of standards specified by the
`IEEE Computer Society`_ for maintaining compatibility between operating systems. Zephyr
implements a subset of the standard POSIX API specified by `IEEE 1003.1-2017`_ (also known as
POSIX-1.2017).
.. figure:: posix.svg
:align: center
:alt: POSIX Support in Zephyr
POSIX support in Zephyr
.. note::
This page does not document Zephyr's :ref:`POSIX architecture<Posix arch>`, which is used to
run Zephyr as a native application under the host operating system for prototyping,
test, and diagnostic purposes.
With the POSIX support available in Zephyr, an existing POSIX conformant
application can be ported to run on the Zephyr kernel, and therefore leverage
Zephyr features and functionality. Additionally, a library designed to be
POSIX conformant can be ported to Zephyr kernel based applications with no changes.
The POSIX API is an increasingly popular OSAL (operating system abstraction layer) for IoT and
embedded applications, as can be seen in Zephyr, AWS:FreeRTOS, TI-RTOS, and NuttX.
Benefits of POSIX support in Zephyr include:
- Offering a familiar API to non-embedded programmers, especially from Linux
- Enabling reuse (portability) of existing libraries based on POSIX APIs
- Providing an efficient API subset appropriate for small (MCU) embedded systems
.. _posix_subprofiles:
POSIX Subprofiles
=================
While Zephyr supports running multiple :ref:`threads <threads_v2>` (possibly in an
:ref:`SMP <smp_arch>` configuration), as well as
:ref:`Virtual Memory and MMUs <memory_management_api>`, Zephyr code and data normally share a
common address space that is partitioned into separate :ref:`Memory Domains <memory_domain>`. The
Zephyr kernel executable code and the application executable code are typically compiled into the
same binary artifact. From that perspective, Zephyr apps can be seen as running in the context of
a single process.
While multi-purpose operating systems (OS) offer full POSIX conformance, Real-Time Operating
Systems (RTOS) such as Zephyr typically serve a fixed-purpose, have limited hardware resources,
and experience limited user interaction. In such systems, full POSIX conformance can be
impractical and unnecessary.
For that reason, POSIX defined the following :ref:`Application Environment Profiles (AEP)<posix_aep>`
as part of `IEEE 1003.13-2003`_ (also known as POSIX.13-2003). Each AEP adds incrementally more
features over the required :ref:`POSIX System Interfaces <posix_system_interfaces>`.
.. figure:: aep.svg
:align: center
:scale: 150%
:alt: POSIX Application Environment Profiles (AEP)
POSIX Application Environment Profiles (AEP)
* Minimal Realtime System Profile (:ref:`PSE51 <posix_aep_pse51>`)
* Realtime Controller System Profile (:ref:`PSE52 <posix_aep_pse52>`)
* Dedicated Realtime System Profile (:ref:`PSE53 <posix_aep_pse53>`)
* Multi-Purpose Realtime System (PSE54)
POSIX.13-2003 AEP were formalized in 2003 via "Units of Functionality" but the specification is now
inactive (for reference only). Nevertheless, the intent is still captured as part of POSIX-1.2017
via :ref:`Options<posix_options>` and :ref:`Option Groups<posix_option_groups>`.
For more information, please see `IEEE 1003.1-2017, Section E, Subprofiling Considerations`_.
.. _posix_apps:
POSIX Applications in Zephyr
============================
A POSIX app in Zephyr is :ref:`built like any other app<application>` and therefore requires the
usual :file:`prj.conf`, :file:`CMakeLists.txt`, and source code. For example, the app below
leverages the ``nanosleep()`` and ``perror()`` POSIX functions.
.. code-block:: cfg
:caption: `prj.conf` for a simple POSIX app in Zephyr
CONFIG_POSIX_API=y
.. code-block:: c
:caption: A simple app that uses Zephyr's POSIX API
#include <stddef.h>
#include <stdio.h>
#include <time.h>
void megasleep(size_t megaseconds)
{
struct timespec ts = {
.tv_sec = megaseconds * 1000000,
.tv_nsec = 0,
};
printf("See you in a while!\n");
if (nanosleep(&ts, NULL) == -1) {
perror("nanosleep");
}
}
int main()
{
megasleep(42);
return 0;
}
For more examples of POSIX applications, please see the :ref:`POSIX sample applications<posix-samples>`.
.. _posix_config:
Configuration
=============
Like most features in Zephyr, POSIX features are
:ref:`highly configurable<zephyr_intro_configurability>` but disabled by default. Users must
explicitly choose to enable POSIX options via :ref:`Kconfig<kconfig>` selection.
Subprofiles
+++++++++++
Enable one of the Kconfig options below to quickly configure a pre-defined
:ref:`POSIX subprofile <posix_subprofiles>`.
* :kconfig:option:`CONFIG_POSIX_AEP_CHOICE_BASE` (:ref:`Base <posix_system_interfaces_required>`)
* :kconfig:option:`CONFIG_POSIX_AEP_CHOICE_PSE51` (:ref:`PSE51 <posix_aep_pse51>`)
* :kconfig:option:`CONFIG_POSIX_AEP_CHOICE_PSE52` (:ref:`PSE52 <posix_aep_pse52>`)
* :kconfig:option:`CONFIG_POSIX_AEP_CHOICE_PSE53` (:ref:`PSE53 <posix_aep_pse53>`)
Additional POSIX :ref:`Options and Option Groups <posix_option_groups>` may be enabled as needed
via Kconfig (e.g. ``CONFIG_POSIX_C_LIB_EXT=y``). Further fine-tuning may be accomplished via
:ref:`additional POSIX-related Kconfig options <posix_kconfig_options>`.
Subprofiles, Options, and Option Groups should be considered the preferred way to configure POSIX
in Zephyr going forward.
Legacy
++++++
Historically, Zephyr used :kconfig:option:`CONFIG_POSIX_API` to configure a set of POSIX features
that was overloaded and always increasing in size.
* :kconfig:option:`CONFIG_POSIX_API`
The option is now frozen, and can be considered equivalent to the following:
* :kconfig:option:`CONFIG_POSIX_AEP_CHOICE_PSE51`
* :kconfig:option:`CONFIG_POSIX_FD_MGMT`
* :kconfig:option:`CONFIG_POSIX_MESSAGE_PASSING`
* :kconfig:option:`CONFIG_POSIX_NETWORKING`
However, :kconfig:option:`CONFIG_POSIX_API` should be considered legacy and should not be used for
new Zephyr applications.
.. _IEEE: https://www.ieee.org/
.. _IEEE Computer Society: https://www.computer.org/
.. _IEEE 1003.1-2017: https://standards.ieee.org/ieee/1003.1/7101/
.. _IEEE 1003.13-2003: https://standards.ieee.org/ieee/1003.13/3322/
.. _IEEE 1003.1-2017, Section E, Subprofiling Considerations:
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
Part 3
한국어 전문 번역
Portable Operating System Interface(POSIX)는 operating system 사이 compatibility를 유지하기 위해 IEEE Computer Society가 정의한 표준 family입니다. Zephyr는 POSIX-1.2017이라고도 부르는 IEEE 1003.1-2017의 POSIX API subset을 구현합니다.
Zephyr의 POSIX support를 사용하면 기존 POSIX-conformant application을 Zephyr kernel로 port해 Zephyr 기능을 활용할 수 있습니다. POSIX-conformant library도 변경 없이 Zephyr kernel application으로 옮길 수 있습니다.
POSIX API는 Zephyr, AWS FreeRTOS, TI-RTOS, NuttX에서 보듯 IoT와 embedded application용 OS abstraction layer(OSAL)로 널리 사용됩니다.
- 특히 Linux에 익숙한 비embedded programmer에게 친숙한 API를 제공합니다.
- 기존 POSIX API 기반 library를 재사용하고 이식할 수 있습니다.
- 작은 MCU embedded system에 맞는 효율적인 API subset을 제공합니다.
POSIX Subprofiles
Zephyr는 SMP를 포함한 multiple thread와 virtual memory/MMU를 지원하지만 code와 data는 보통 Memory Domain으로 나눈 하나의 address space를 공유합니다. Kernel executable과 application executable도 대개 하나의 binary artifact로 함께 compile되므로 Zephyr app은 single process context에서 실행되는 것으로 볼 수 있습니다.
General-purpose OS는 full POSIX conformance를 제공할 수 있지만 Zephyr 같은 fixed-purpose RTOS는 hardware resource와 user interaction이 제한돼 전체 표준 구현이 비현실적이고 불필요할 수 있습니다.
그래서 POSIX는 POSIX.13-2003의 Application Environment Profile(AEP)을 정의했습니다. 각 profile은 필수 POSIX System Interface 위에 기능을 단계적으로 추가합니다.
- Minimal Realtime System Profile:
PSE51 - Realtime Controller System Profile:
PSE52 - Dedicated Realtime System Profile:
PSE53 - Multi-Purpose Realtime System:
PSE54
POSIX.13-2003 AEP는 Units of Functionality로 formalize됐지만 현재 specification은 inactive reference 상태입니다. 그 의도는 POSIX-1.2017의 Options와 Option Groups에 계속 반영돼 있습니다. 자세한 배경은 IEEE 1003.1-2017 Section E의 Subprofiling Considerations를 참고합니다.
POSIX Applications in Zephyr
Zephyr의 POSIX application도 일반 application과 같은 방식으로 build하므로 prj.conf, CMakeLists.txt와 source code가 필요합니다. 다음 예는 POSIX API를 활성화합니다.
CONFIG_POSIX_API=y
Application은 nanosleep()과 perror()를 일반 C code처럼 사용합니다.
#include <stddef.h>
#include <stdio.h>
#include <time.h>
void megasleep(size_t megaseconds)
{
struct timespec ts = {
.tv_sec = megaseconds * 1000000,
.tv_nsec = 0,
};
printf("See you in a while!\n");
if (nanosleep(&ts, NULL) == -1) {
perror("nanosleep");
}
}
int main()
{
megasleep(42);
return 0;
}
더 많은 예제는 Zephyr POSIX sample application 문서에 있습니다.
Configuration
대부분의 Zephyr 기능처럼 POSIX도 세밀하게 설정할 수 있지만 기본값은 disabled입니다. 필요한 POSIX option을 Kconfig로 명시적으로 선택해야 합니다.
Subprofiles
미리 정의된 POSIX subprofile은 다음 Kconfig choice 중 하나로 빠르게 활성화합니다.
CONFIG_POSIX_AEP_CHOICE_BASE: 필수 System InterfacesCONFIG_POSIX_AEP_CHOICE_PSE51: PSE51CONFIG_POSIX_AEP_CHOICE_PSE52: PSE52CONFIG_POSIX_AEP_CHOICE_PSE53: PSE53
필요하면 CONFIG_POSIX_C_LIB_EXT=y 같은 POSIX Option·Option Group을 더 켜고 추가 POSIX Kconfig option으로 세부 조정합니다. 앞으로는 Subprofile, Option과 Option Group을 Zephyr POSIX 설정의 권장 방식으로 사용해야 합니다.
Legacy
과거의 CONFIG_POSIX_API는 점점 커지는 POSIX 기능 집합을 한 option에 과도하게 묶었습니다. 현재 이 option은 동결됐고 다음 네 option을 함께 켠 것과 같은 것으로 간주합니다.
CONFIG_POSIX_AEP_CHOICE_PSE51CONFIG_POSIX_FD_MGMTCONFIG_POSIX_MESSAGE_PASSINGCONFIG_POSIX_NETWORKING
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.