요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
=================
Triggered Buffers
=================
Now that we know what buffers and triggers are let's see how they work together.
IIO triggered buffer setup
==========================
* :c:func:`iio_triggered_buffer_setup` — Setup triggered buffer and pollfunc
* :c:func:`iio_triggered_buffer_cleanup` — Free resources allocated by
:c:func:`iio_triggered_buffer_setup`
* struct iio_buffer_setup_ops — buffer setup related callbacks
A typical triggered buffer setup looks like this::
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);
The important things to notice here are:
* :c:type:`iio_buffer_setup_ops`, the buffer setup functions to be called at
predefined points in the buffer configuration sequence (e.g. before enable,
after disable). If not specified, the IIO core uses the default
iio_triggered_buffer_setup_ops.
* **sensor_iio_pollfunc**, the function that will be used as top half of poll
function. It should do as little processing as possible, because it runs in
interrupt context. The most common operation is recording of the current
timestamp and for this reason one can use the IIO core defined
:c:func:`iio_pollfunc_store_time` function.
* **sensor_trigger_handler**, the function that will be used as bottom half of
the poll function. This runs in the context of a kernel thread and all the
processing takes place here. It usually reads data from the device and
stores it in the internal buffer together with the timestamp recorded in the
top half.
More details
============
.. kernel-doc:: drivers/iio/buffer/industrialio-triggered-buffer.c
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을 담습니다.
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);
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에 저장합니다.
실행 context와 허용되는 processing을 비교합니다.
Configuration의 predefined point에서 setup ops가 호출됩니다.
Triggered buffer kernel API source
66-69Triggered buffer exported API의 kernel-doc source는 `drivers/iio/buffer/industrialio-triggered-buffer.c`입니다.
.. kernel-doc:: drivers/iio/buffer/industrialio-triggered-buffer.c
Exported implementation 위치입니다.
요약과 해설
triggered-buffers.rst:1-69Triggered buffer의 top half는 interrupt context에서 timestamp만 빠르게 기록하고, threaded bottom half가 active channel을 읽어 그 timestamp와 함께 buffer에 push합니다. Setup ops는 enable·disable 경계의 driver callback을 관리합니다.