Part 1
요약·해설
Memory domain, kernel permission과 ISR→App A→App B→driver 흐름을 설명합니다.
Application A · B
k_msgq · k_queue
Sandboxed processor
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
18ED320CDB563EFFA8F534D3F74E198B14910B4BF87606FB3C6618E8CD70C53F
.. _userspace_prod_consumer:
Producer/consumer
=================
This is a sample application that exercises some user mode concepts.
Overview
********
Consider a "sample driver" which gets incoming data from some unknown source
and generates interrupts with pointers to this data. The application needs
to perform some processing on this data and then write the processed data
back to the driver.
The goal here is to demonstrate:
- Multiple logical applications, each with their own memory domain
- Creation of a sys_heap and assignment to a memory partition
- Use of APIs like ``k_queue_alloc_append()`` which require thread resource
pools to be configured
- Management of permissions for kernel objects and drivers
- Show how application-specific system calls are defined
- Show IPC between ISR and application (using ``k_msgq``) and
application-to-application IPC (using ``k_queue``)
- Show how to create application-specific system calls
In this example, we have an Application A whose job is to talk to the
driver, buffer incoming data, and write it back once processed by
Application B.
Application B simply processes the data. Let's pretend this data is
untrusted and possibly malicious, so Application B is sandboxed from
everything else, with just two queues for sending/receiving data items.
The control loop is as follows:
- Sample driver issues interrupts, invoking its associated callback
function with a fixed-sized data payload.
- App A callback function, in supervisor mode, places the data payload
into a message queue.
- App A monitor thread in user mode waits for data in the message queue.
When it wakes up, copy the data payload into a buffer allocated out
of the shared memory pool, and enqueue this data into a ``k_queue`` being
monitored by application B.
- Application B processing thread waits on new items in the queue. It
then processes the data in-place, and after it's finished it places
the processed data into another queue to be written back to the driver.
- Application A writeback thread monitors the outgoing data queue for
new items containing processed data. As it gets them it will write
such data back to the driver and free the buffer.
We also demonstrate application-defined system calls, in the form of
the ``magic_cookie()`` function.
Sample Output
*************
.. code-block:: console
I:APP A partition: 0x00110000 4096
I:Shared partition: 0x0010e000 4096
I:sample_driver_foo_isr: param=0x00147078 count=0
I:monitor thread got data payload #0
I:sample_driver_foo_isr: param=0x00147078 count=1
I:monitor thread got data payload #1
I:sample_driver_foo_isr: param=0x00147078 count=2
I:monitor thread got data payload #2
I:sample_driver_foo_isr: param=0x00147078 count=3
I:monitor thread got data payload #3
I:sample_driver_foo_isr: param=0x00147078 count=4
I:monitor thread got data payload #4
I:processing payload #1 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=5
I:monitor thread got data payload #5
I:processing payload #2 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=6
I:monitor thread got data payload #6
I:processing payload #3 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=7
I:monitor thread got data payload #7
I:processing payload #4 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=8
I:monitor thread got data payload #8
I:processing payload #5 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=9
I:monitor thread got data payload #9
I:processing payload #6 complete
I:writing processed data blob back to the sample device
I:processing payload #7 complete
I:writing processed data blob back to the sample device
I:processing payload #8 complete
I:writing processed data blob back to the sample device
I:processing payload #9 complete
I:writing processed data blob back to the sample device
I:processing payload #10 complete
I:writing processed data blob back to the sample device
I:SUCCESS
Part 3
한국어 전문 번역
일부 user mode 개념을 실제 흐름으로 시험하는 sample application입니다.
개요
알 수 없는 source에서 incoming data를 받아 그 data를 가리키는 pointer와 함께 interrupt를 발생시키는 sample driver를 가정합니다. Application은 data를 처리한 뒤 처리 결과를 driver에 다시 써야 합니다.
이 sample의 목표는 다음 항목을 보여 주는 것입니다.
- 각자 고유한 memory domain을 가진 여러 logical application
sys_heap생성과 memory partition 할당- Thread resource pool을 설정해야 사용할 수 있는
k_queue_alloc_append()같은 API - Kernel object와 driver permission 관리
- Application 전용 system call 정의 방법
k_msgq를 사용한 ISR과 application 사이 IPC,k_queue를 사용한 application 사이 IPC- Application 전용 system call을 만드는 방법
이 예에서 Application A는 driver와 통신하고 incoming data를 buffer에 보관하며, Application B가 처리한 뒤 그 data를 driver에 다시 씁니다.
Application B는 data 처리만 담당합니다. Data가 신뢰할 수 없고 악의적일 수도 있다고 가정하므로 B는 다른 모든 요소로부터 sandbox되며, data item 송수신을 위한 queue 두 개에만 접근할 수 있습니다.
Control loop는 다음 순서로 동작합니다.
- Sample driver가 고정 크기 data payload와 함께 연결된 callback function을 호출하는 interrupt를 발생시킵니다.
- Supervisor mode에서 실행되는 App A callback function이 data payload를 message queue에 넣습니다.
- User mode의 App A monitor thread가 message queue에서 data를 기다립니다. 깨어나면 shared memory pool에서 할당한 buffer로 payload를 복사하고 Application B가 감시하는
k_queue에 넣습니다. - Application B processing thread가 queue의 새 item을 기다립니다. Data를 제자리에서 처리한 뒤, 완료된 data를 다른 queue에 넣어 driver로 다시 보냅니다.
- Application A writeback thread가 processed data의 outgoing queue를 감시합니다. Item을 받으면 driver에 data를 쓰고 buffer를 해제합니다.
magic_cookie() function을 통해 application-defined system call도 보여 줍니다.
샘플 출력
출력은 App A partition과 shared partition의 address·크기를 먼저 표시합니다. Driver ISR이 payload 0~9를 발생시키면 monitor thread가 이를 받고, processing thread가 순서대로 처리한 뒤 writeback thread가 sample device로 돌려보냅니다. 마지막 SUCCESS는 전체 producer-consumer pipeline이 끝났음을 뜻합니다.
I:APP A partition: 0x00110000 4096
I:Shared partition: 0x0010e000 4096
I:sample_driver_foo_isr: param=0x00147078 count=0
I:monitor thread got data payload #0
I:sample_driver_foo_isr: param=0x00147078 count=1
I:monitor thread got data payload #1
I:sample_driver_foo_isr: param=0x00147078 count=2
I:monitor thread got data payload #2
I:sample_driver_foo_isr: param=0x00147078 count=3
I:monitor thread got data payload #3
I:sample_driver_foo_isr: param=0x00147078 count=4
I:monitor thread got data payload #4
I:processing payload #1 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=5
I:monitor thread got data payload #5
I:processing payload #2 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=6
I:monitor thread got data payload #6
I:processing payload #3 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=7
I:monitor thread got data payload #7
I:processing payload #4 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=8
I:monitor thread got data payload #8
I:processing payload #5 complete
I:writing processed data blob back to the sample device
I:sample_driver_foo_isr: param=0x00147078 count=9
I:monitor thread got data payload #9
I:processing payload #6 complete
I:writing processed data blob back to the sample device
I:processing payload #7 complete
I:writing processed data blob back to the sample device
I:processing payload #8 complete
I:writing processed data blob back to the sample device
I:processing payload #9 complete
I:writing processed data blob back to the sample device
I:processing payload #10 complete
I:writing processed data blob back to the sample device
I:SUCCESS
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.