Documentation/driver-api/iio/triggered-buffers.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

Triggered Buffers

IIO trigger와 buffer를 연결하는 setup ops, interrupt top half, threaded bottom half와 timestamp push를 설명합니다.

Source pathDocumentation/driver-api/iio/triggered-buffers.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

triggered-buffers.rst:1-69

Triggered buffer의 top half는 interrupt context에서 timestamp만 빠르게 기록하고, threaded bottom half가 active channel을 읽어 그 timestamp와 함께 buffer에 push합니다. Setup ops는 enable·disable 경계의 driver callback을 관리합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 =================
2 Triggered Buffers
3 =================
4
5 Now that we know what buffers and triggers are let's see how they work together.
6
7 IIO triggered buffer setup
8 ==========================
9
10 * :c:func:`iio_triggered_buffer_setup` — Setup triggered buffer and pollfunc
11 * :c:func:`iio_triggered_buffer_cleanup` — Free resources allocated by
12 :c:func:`iio_triggered_buffer_setup`
13 * struct iio_buffer_setup_ops — buffer setup related callbacks
14
15 A typical triggered buffer setup looks like this::
16
17 const struct iio_buffer_setup_ops sensor_buffer_setup_ops = {
18 .preenable = sensor_buffer_preenable,
19 .postenable = sensor_buffer_postenable,
20 .postdisable = sensor_buffer_postdisable,
21 .predisable = sensor_buffer_predisable,
22 };
23
24 irqreturn_t sensor_iio_pollfunc(int irq, void *p)
25 {
26 pf->timestamp = iio_get_time_ns((struct indio_dev *)p);
27 return IRQ_WAKE_THREAD;
28 }
29
30 irqreturn_t sensor_trigger_handler(int irq, void *p)
31 {
32 u16 buf[8];
33 int i = 0;
34
35 /* read data for each active channel */
36 for_each_set_bit(bit, active_scan_mask, masklength)
37 buf[i++] = sensor_get_data(bit)
38
39 iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp);
40
41 iio_trigger_notify_done(trigger);
42 return IRQ_HANDLED;
43 }
44
45 /* setup triggered buffer, usually in probe function */
46 iio_triggered_buffer_setup(indio_dev, sensor_iio_polfunc,
47 sensor_trigger_handler,
48 sensor_buffer_setup_ops);
49
50 The important things to notice here are:
51
52 * :c:type:`iio_buffer_setup_ops`, the buffer setup functions to be called at
53 predefined points in the buffer configuration sequence (e.g. before enable,
54 after disable). If not specified, the IIO core uses the default
55 iio_triggered_buffer_setup_ops.
56 * **sensor_iio_pollfunc**, the function that will be used as top half of poll
57 function. It should do as little processing as possible, because it runs in
58 interrupt context. The most common operation is recording of the current
59 timestamp and for this reason one can use the IIO core defined
60 :c:func:`iio_pollfunc_store_time` function.
61 * **sensor_trigger_handler**, the function that will be used as bottom half of
62 the poll function. This runs in the context of a kernel thread and all the
63 processing takes place here. It usually reads data from the device and
64 stores it in the internal buffer together with the timestamp recorded in the
65 top half.
66
67 More details
68 ============
69 .. kernel-doc:: drivers/iio/buffer/industrialio-triggered-buffer.c
70

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Triggered buffer 개요

1-14

문서 제목은 `Triggered Buffers`입니다. Buffer와 trigger가 함께 동작하는 방법을 설명합니다.

`iio_triggered_buffer_setup`은 triggered buffer와 pollfunc를 설정하고 `iio_triggered_buffer_cleanup`은 setup이 할당한 resource를 해제합니다. `struct iio_buffer_setup_ops`는 buffer setup 관련 callback을 담습니다.

Triggered buffer 구성요소
IIO triggerPoll function top halfThreaded bottom halfActive channel readTimestamp와 함께 IIO buffer pushSetup ops가 enable·disable lifecycle 관리

Trigger event를 timestamped buffer sample로 바꾸는 핵심 object입니다.

Triggered buffer setup 예제

15-49

일반 setup은 `iio_buffer_setup_ops`에 preenable·postenable·postdisable·predisable callback을 배치합니다. Poll function top half는 현재 timestamp를 기록하고 `IRQ_WAKE_THREAD`를 반환합니다.

Threaded handler는 `active_scan_mask`의 각 channel data를 읽어 buffer에 채우고 `iio_push_to_buffers_with_timestamp`로 timestamp와 함께 push합니다. 처리가 끝나면 `iio_trigger_notify_done`으로 trigger에 알리고 `IRQ_HANDLED`를 반환합니다. Probe에서는 이 함수들을 `iio_triggered_buffer_setup`에 전달합니다.

const struct iio_buffer_setup_ops sensor_buffer_setup_ops = {
  .preenable    = sensor_buffer_preenable,
  .postenable   = sensor_buffer_postenable,
  .postdisable  = sensor_buffer_postdisable,
  .predisable   = sensor_buffer_predisable,
};

irqreturn_t sensor_iio_pollfunc(int irq, void *p)
{
    pf->timestamp = iio_get_time_ns((struct indio_dev *)p);
    return IRQ_WAKE_THREAD;
}

irqreturn_t sensor_trigger_handler(int irq, void *p)
{
    u16 buf[8];
    int i = 0;

    /* read data for each active channel */
    for_each_set_bit(bit, active_scan_mask, masklength)
        buf[i++] = sensor_get_data(bit)

    iio_push_to_buffers_with_timestamp(indio_dev, buf, timestamp);

    iio_trigger_notify_done(trigger);
    return IRQ_HANDLED;
}

/* setup triggered buffer, usually in probe function */
iio_triggered_buffer_setup(indio_dev, sensor_iio_polfunc,
                           sensor_trigger_handler,
                           sensor_buffer_setup_ops);
Triggered capture execution
Trigger IRQTop half가 iio_get_time_ns()로 timestamp 저장IRQ_WAKE_THREADBottom half가 active_scan_mask 순회Channel data readiio_push_to_buffers_with_timestamp()iio_trigger_notify_done()

Interrupt top half와 kernel-thread bottom half의 실행 경로입니다.

Setup ops와 poll function 역할

50-65

`iio_buffer_setup_ops`는 buffer configuration sequence의 predefined point, 예를 들어 enable 전이나 disable 후에 호출할 setup function입니다. 지정하지 않으면 IIO core가 기본 `iio_triggered_buffer_setup_ops`를 사용합니다.

`sensor_iio_pollfunc`는 poll function의 top half입니다. Interrupt context에서 실행되므로 processing을 최소화해야 합니다. 가장 흔한 작업은 current timestamp 기록이며 IIO core의 `iio_pollfunc_store_time`을 사용할 수 있습니다.

`sensor_trigger_handler`는 poll function의 bottom half이고 kernel thread context에서 실행됩니다. 모든 processing이 여기서 이루어지며 보통 device data를 읽고 top half에서 기록한 timestamp와 함께 internal buffer에 저장합니다.

Top half와 bottom half
부분Context주요 작업
sensor_iio_pollfuncInterrupt context최소 처리, timestamp 기록
sensor_trigger_handlerKernel threadChannel read, buffer push, completion notify

실행 context와 허용되는 processing을 비교합니다.

Buffer setup callback sequence
predisableBuffer disablepostdisableConfiguration 변경preenableBuffer enablepostenable

Configuration의 predefined point에서 setup ops가 호출됩니다.

Triggered buffer kernel API source

66-69

Triggered buffer exported API의 kernel-doc source는 `drivers/iio/buffer/industrialio-triggered-buffer.c`입니다.

.. kernel-doc:: drivers/iio/buffer/industrialio-triggered-buffer.c
Triggered buffer source
범위Source path
Triggered buffer exportdrivers/iio/buffer/industrialio-triggered-buffer.c

Exported implementation 위치입니다.