develop/languages/c/common_libc.html · develop/languages/c/common_libc.rst 공식 원문 ↗

Zephyr 3.7.0 · Develop · Languages · C

공통 C library code

여러 C library에서 공유하는 Zephyr의 시간·동적 memory 관리 구현과 설정 방법을 설명합니다.

Official pathdevelop/languages/c/common_libc.html
Source filedevelop/languages/c/common_libc.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

time()과 clock_gettime() 연결, 공통 malloc heap의 userspace partition, MMU별 기본 크기, calloc·reallocarray option과 thread safety를 다룹니다.

시간

time · clock_gettime

Heap

.bss · Partition · MMU

안전

Thread-safe · malloc.c

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 46540B1A7E128655F3B9EA6A7AA0C7A5D1AD51FBE89C8E789CED0540FA1899D6
.. _c_library_common:

Common C library code
#####################

Zephyr provides some C library functions that are designed to be used in
conjunction with multiple C libraries. These either provide functions not
available in multiple C libraries or are designed to replace functionality
in the C library with code better suited for use in the Zephyr environment

Time function
*************

This provides an implementation of the standard C function, :c:func:`time`,
relying on the Zephyr function, :c:func:`clock_gettime`. This function can
be enabled by selecting :kconfig:option:`COMMON_LIBC_TIME`.

Dynamic Memory Management
*************************

The common dynamic memory management implementation can be enabled by
selecting the :kconfig:option:`CONFIG_COMMON_LIBC_MALLOC` in the
application configuration file.

The common C library internally uses the :ref:`kernel memory heap API
<heap_v2>` to manage the memory heap used by the standard dynamic memory
management interface functions such as :c:func:`malloc` and :c:func:`free`.

The internal memory heap is normally located in the ``.bss`` section. When
userspace is enabled, however, it is placed in a dedicated memory partition
called ``z_malloc_partition``, which can be accessed from the user mode
threads. The size of the internal memory heap is specified by the
:kconfig:option:`CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE`.

The default heap size for applications using the common C library is zero
(no heap). For other C library users, if there is an MMU present, then the
default heap is 16kB. Otherwise, the heap uses all available memory.

There are also separate controls to select :c:func:`calloc`
(:kconfig:option:`COMMON_LIBC_CALLOC`) and :c:func:`reallocarray`
(:kconfig:option:`COMMON_LIBC_REALLOCARRAY`). Both of these are enabled by
default as that doesn't impact memory usage in applications not using them.

The standard dynamic memory management interface functions implemented by
the common C library are thread safe and may be simultaneously called by
multiple threads. These functions are implemented in
:file:`lib/libc/common/source/stdlib/malloc.c`.

Part 3

한국어 전문 번역

공통 C library code

Zephyr는 여러 C library와 함께 사용할 수 있도록 설계한 일부 C library function을 제공합니다. 여러 C library에 공통으로 없는 function을 보충하거나, 기존 C library 기능을 Zephyr 환경에 더 알맞은 code로 대체합니다.

시간 function

Zephyr의 clock_gettime() function을 바탕으로 표준 C function time()을 구현합니다. COMMON_LIBC_TIME Kconfig option을 선택하면 이 function을 활성화할 수 있습니다.

동적 memory 관리

Application configuration file에서 CONFIG_COMMON_LIBC_MALLOC을 선택하면 공통 동적 memory 관리 구현을 활성화할 수 있습니다.

공통 C library는 내부적으로 kernel memory heap API를 사용해 malloc()과 free() 같은 표준 동적 memory 관리 interface function이 사용하는 memory heap을 관리합니다.

내부 memory heap은 보통 .bss section에 있습니다. 그러나 userspace를 활성화하면 user mode thread가 접근할 수 있는 z_malloc_partition 전용 memory partition에 배치됩니다. 내부 memory heap 크기는 CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE로 지정합니다.

공통 C library를 사용하는 application의 기본 heap 크기는 0, 즉 heap 없음입니다. 다른 C library 사용자는 MMU가 있으면 기본 heap이 16kB이고, MMU가 없으면 사용할 수 있는 memory 전체를 heap으로 사용합니다.

calloc()은 COMMON_LIBC_CALLOC, reallocarray()는 COMMON_LIBC_REALLOCARRAY라는 별도 option으로 선택할 수 있습니다. 사용하지 않는 application의 memory 사용량에는 영향을 주지 않으므로 두 option 모두 기본으로 활성화됩니다.

공통 C library가 구현한 표준 동적 memory 관리 interface function은 thread safe하며 여러 thread가 동시에 호출할 수 있습니다. 구현 source는 lib/libc/common/source/stdlib/malloc.c입니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.