connectivity/networking/api/net_timeout.html · connectivity/networking/api/net_timeout.rst 공식 원문 ↗

Zephyr 3.7.0 · Connectivity · Networking API

Network Timeout

32-bit millisecond clock의 rollover를 넘어서는 protocol timeout을 안전하게 추적합니다.

Official pathconnectivity/networking/api/net_timeout.html
Source fileconnectivity/networking/api/net_timeout.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

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

Part 1

요약·해설

49일 uptime rollover와 24일 signed delay 경계를 고려해 긴 timeout을 반복 평가하는 방법을 설명합니다.

Clock

32-bit milliseconds

Safe Delay

INT32_MAX

Method

Set · Evaluate · Reschedule

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 FBE87267F6D3A5419445FDD155586D73E9774DAC0DAE5CA0E67B22C162BA930D
.. _net_timeout_interface:

Network Timeout
###############

.. contents::
    :local:
    :depth: 2

Overview
********

Zephyr's network infrastructure mostly uses the millisecond-resolution uptime
clock to track timeouts, with both deadlines and durations measured with
32-bit unsigned values.  The 32-bit value rolls over at 49 days 17 hours 2 minutes
47.296 seconds.

Timeout processing is often affected by latency, so that the time at which the
timeout is checked may be some time after it should have expired.  Handling
this correctly without arbitrary expectations of maximum latency requires that
the maximum delay that can be directly represented be a 31-bit non-negative
number (``INT32_MAX``), which overflows at 24 days 20 hours 31 minutes 23.648
seconds.

Most network timeouts are shorter than the delay rollover, but a few protocols
allow for delays that are represented as unsigned 32-bit values counting
seconds, which corresponds to a 42-bit millisecond count.

The net_timeout API provides a generic timeout mechanism to correctly track
the remaining time for these extended-duration timeouts.

Use
***

The simplest use of this API is:

#. Configure a network timeout using :c:func:`net_timeout_set()`.
#. Use :c:func:`net_timeout_evaluate()` to determine how long it is until the
   timeout occurs.  Schedule a timeout to occur after this delay.
#. When the timeout callback is invoked, use :c:func:`net_timeout_evaluate()`
   again to determine whether the timeout has completed, or whether there is
   additional time remaining.  If the latter, reschedule the callback.
#. While the timeout is running, use :c:func:`net_timeout_remaining` to get
   the number of seconds until the timeout expires.  This may be used to
   explicitly update the timeout, which should be done by canceling any
   pending callback and restarting from step 1 with the new timeout.

The :c:struct:`net_timeout` contains a ``sys_snode_t`` that allows multiple
timeout instances to be aggregated to share a single kernel timer element.
The application must use :c:func:`net_timeout_evaluate()` on all instances to
determine the next timeout event to occur.

:c:func:`net_timeout_deadline()` may be used to reconstruct the full-precision
deadline of the timeout.  This exists primarily for testing but may have use
in some applications, as it does allow a millisecond-resolution calculation of
remaining time.

API Reference
*************

.. doxygengroup:: net_timeout

Part 3

한국어 전문 번역

개요

Zephyr network infrastructure는 대부분 millisecond 해상도의 uptime clock으로 timeout을 추적하며 deadline과 duration을 모두 32-bit unsigned value로 측정합니다. 이 32-bit value는 49일 17시간 2분 47.296초에 rollover됩니다.

Timeout 처리는 latency의 영향을 자주 받으므로 실제 확인 시점이 만료 예정 시점보다 늦을 수 있습니다. 최대 latency에 임의의 상한을 가정하지 않고 이를 올바르게 처리하려면 직접 표현할 수 있는 최대 delay가 31-bit non-negative number인 INT32_MAX여야 합니다. 이 값은 24일 20시간 31분 23.648초에 overflow됩니다.

대부분의 network timeout은 이 delay rollover보다 짧지만, 일부 protocol은 unsigned 32-bit 초 단위 delay를 허용합니다. 이는 millisecond로 42-bit count에 해당합니다.

net_timeout API는 이렇게 긴 timeout의 남은 시간을 올바르게 추적하는 generic timeout mechanism을 제공합니다.

사용법

이 API의 가장 단순한 사용 절차는 다음과 같습니다.

  1. net_timeout_set()으로 network timeout을 설정합니다.
  2. net_timeout_evaluate()로 timeout까지 남은 시간을 계산하고 그 delay 뒤에 실행될 callback을 schedule합니다.
  3. Callback이 호출되면 net_timeout_evaluate()를 다시 사용해 timeout이 끝났는지, 아니면 시간이 더 남았는지 판단합니다. 시간이 남았다면 callback을 다시 schedule합니다.
  4. Timeout 실행 중에는 net_timeout_remaining으로 만료까지 남은 초를 얻습니다. Timeout을 명시적으로 갱신할 때 사용할 수 있으며, pending callback을 취소하고 새 timeout으로 1단계부터 다시 시작해야 합니다.

struct net_timeout에는 여러 timeout instance를 한데 묶어 하나의 kernel timer element를 공유할 수 있게 하는 sys_snode_t가 들어 있습니다. Application은 모든 instance에 net_timeout_evaluate()를 적용해 다음에 발생할 timeout event를 결정해야 합니다.

net_timeout_deadline()은 timeout의 full-precision deadline을 복원하는 데 사용할 수 있습니다. 주된 목적은 test이지만, millisecond 해상도로 남은 시간을 계산할 수 있으므로 일부 application에서도 쓸 수 있습니다.

API Reference

Doxygen group net_timeout이 API reference를 제공합니다.

Source

출처

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