samples/kernel/metairq_dispatch/README.html · samples/kernel/metairq_dispatch/README.rst 공식 원문 ↗

Zephyr 3.7.0 · Samples · Kernel · Scheduler

MetaIRQ Thread Priority 시연

Bursty load에서도 MetaIRQ가 cooperative thread까지 preempt하며 일정한 latency를 유지하는지 확인합니다.

Official pathsamples/kernel/metairq_dispatch/README.html
Source filesamples/kernel/metairq_dispatch/README.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

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

Part 1

요약·해설

세 latency 지표, 네 관찰점, timer 요구 사항과 frdm_k64f 전체 출력을 보존합니다.

Dispatch

ISR → MetaIRQ

Workers

Priority -2 to 1

Timer

10+ kHz ideal

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 1BE6A0D0B171391494D1C0565DEE1CEB5E57099235983D070E06AD137E4AE798
.. _samples_scheduler_metairq_dispatch:

MetaIRQ Thread Priority Demonstration
#####################################

Overview
********

This sample demonstrates the use of a thread running at a MetaIRQ
priority level to implement "bottom half" style processing
synchronously with the end of a hardware ISR.  It implements a
simulated "device" that produces messages that need to be dispatched
to asynchronous queues feeding several worker threads, each running at
a different priority.  The dispatch is handled by a MetaIRQ thread fed
via a queue from the device ISR (really just a timer interrupt).

Each message has a random (and non-trivial) amount of processing that
must happen in the worker thread.  This implements a "bursty load"
environment where occasional spikes in load require preemption of
running threads and delay scheduling of lower priority threads.
Messages are accompanied by a timestamp that allows per-message
latencies to be computed at several points:

* The cycle time between message creation in the ISR and receipt by
  the MetaIRQ thread for dispatch.

* The time between ISR and receipt by the worker thread.

* The real time spent processing the message in the worker thread, for
  comparison with the required processing time.  This provides a way
  to measure preemption overhead where the thread is not scheduled.

Aspects to note in the results:

* On average, higher priority (lower numbered) threads have better
  latencies and lower processing delays, as expected.

* Cooperatively scheduled threads have significantly better processing
  delay behavior than preemptible ones, as they can only be preempted
  by the MetaIRQ thread.

* Because of queueing and the bursty load, all worker threads of any
  priority will experience some load-dependent delays, as the CPU
  occasionally has more work to do than time available.

* But, no matter the system load or thread configuration, the MetaIRQ
  thread always runs immediately after the ISR.  It shows reliable,
  constant latency under all circumstances because it can preempt all
  other threads, including cooperative ones that cannot normally be
  preempted.

Requirements
************

This sample should run well on any Zephyr platform that provides
preemption of running threads by interrupts, a working timer driver,
and working log output.  For precision reasons, it produces better
(and more) data on systems with a high timer tick rate (ideally 10+
kHz).

Note that because the test is fundamentally measuring thread
preemption behavior, it does not run without modification on
native_sim platforms. In that emulation environment, threads will
not be preempted except at specific instrumentation points (e.g. in
k_busy_wait()) where they will voluntarily release the CPU.

Building and Running
********************

This application can be built and executed on frdm_k64f as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/kernel/metairq_dispatch
   :board: frdm_k64f
   :goals: build flash
   :compact:

To build for another board, change "frdm_k64f" above to that board's name.

Sample Output
=============

Sample output shown below is from frdm_k64f. The numbers will
look different based upon the clock frequency of the board and other
factors.

Note: The 'real' values may be significantly higher than corresponding 'proc' values
(intended) for non-cooperative threads like T2 and T3 which is attributed to delays
due to thread preemption.


.. code-block:: console

   I: Starting Thread0 at priority -2
   I: Starting Thread1 at priority -1
   II: M0 T0 mirq 4478 disp 7478 proc 24336 real 24613
   I: M8 T0 mirq 4273 disp 86983 proc 9824 real 16753
   I: M10 T0 mirq 4273 disp 495455 proc 21177 real 28273
   I: M11 T0 mirq 4273 disp 981565 proc 48337 real 48918
   I: M14 T0 mirq 4273 disp 1403627 proc 7079 real 7690
   I: M17 T0 mirq 4273 disp 1810028 proc 42143 real 42925
   I: M19 T0 mirq 4273 disp 2369217 proc 42471 real 42925
   I: M20 T0 mirq 4273 disp 2940429 proc 30427 real 30775
   I: M21 T0 mirq 4273 disp 3524151 proc 35871 real 36850
   I: M22 T0 mirq 4273 disp 4042148 proc 33738 real 34420
   I: M23 T0 mirq 4273 disp 4557010 proc 5757 real 6475
   I: M29 T0 mirq 4273 disp 4759422 proc 49748 real 50215
   I: M33 T0 mirq 4273 disp 5218935 proc 32105 real 33205
   I: M35 T0 mirq 4273 disp 5732769 proc 32678 real 33205
   I: M36 T0 mirq 4273 disp 6294586 proc 9303 real 10120
   I: M37 T0 mirq 4273 disp 6819398 proc 29960 real 30775
   I: M40 T0 mirq 3189 disp 7199139 proc 19692 real 21055
   I: M9 T1 mirq 4273 disp 9417562 proc 53844 real 55075
   I: M18 T1 mirq 4273 disp 9522780 proc 4560 real 5260
   I: M25 T1 mirq 4273 disp 9713189 proc 56656 real 57505
   I: M27 T1 mirq 4273 disp 10238978 proc 48347 real 49000
   : Starting Thread2 at priority 0
   I: M1 T2 mirq 4273 disp 12740821 proc 40449 real 41710
   I: M2 T2 mirq 4273 disp 13311098 proc 43926 real 44140
   I: M3 T2 mirq 4273 disp 13824365 proc 41212 real 41710
   I: M4 T2 mirq 4273 disp 14382522 proc 12859 real 13765
   I: M5 T2 mirq 4273 disp 14869754 proc 17303 real 18625
   I: M7 T2 mirq 4273 disp 15368993 proc 10666 real 11335
   I: M15 T2 mirq 4273 disp 15364239 proc 45304 real 46570
   I: M24 T2 mirq 4273 disp 15602017 proc 39637 real 40495
   I: M28 T2 mirq 4273 disp 15989555 proc 24436 real 24700
   I: M30 T2 mirq 4273 disp 16493444 proc 44374 real 45355
   I: M31 T2 mirq 4273 disp 17078141 proc 21947 real 22270
   I: M34 T2 mirq 4273 disp 17555966 proc 47779 real 49000
   I: M39 T2 mirq 4273 disp 17843806 proc 10954 real 11335
   I: Starting Thread3 at priority 1
   I: M6 T3 mirq 4273 disp 20625899 proc 13459 real 13765
   I: M12 T3 mirq 4273 disp 20813171 proc 13534 real 13765
   I: M13 T3 mirq 4273 disp 21334833 proc 37091 real 38065
   I: M16 T3 mirq 4273 disp 21744289 proc 42514 real 42925
   I: M26 T3 mirq 4273 disp 21846939 proc 36261 real 36850
   I: M32 T3 mirq 4273 disp 22207336 proc 49987 real 50215
   I: M38 T3 mirq 4273 disp 22532228 proc 37164 real 38065
   I:         ---------- Latency (cyc) ----------
   I:             Best    Worst     Mean    Stdev
   I: MetaIRQ     4273     4478     4278       32
   I: Thread0     7478  6819398  3190200  2183592
   I: Thread1  9417562 10238978  9723127   316113
   I: Thread2 12740821 17843806 15417286  1525493
   I: Thread3 20625899 22532228 21586385   649911
   I: MetaIRQ Test Complete

Part 3

한국어 전문 번역

개요

이 sample은 MetaIRQ priority level에서 실행되는 thread를 사용해 hardware ISR이 끝나는 시점과 동기화된 bottom half 방식의 처리를 구현하는 방법을 보여줍니다.

Sample은 비동기 queue로 전달해야 할 message를 생성하는 가상 device를 구현합니다. Queue들은 서로 다른 priority에서 실행되는 여러 worker thread에 message를 공급합니다. 실제 device ISR 대신 timer interrupt가 message를 만들고 queue를 통해 MetaIRQ thread에 전달하며, MetaIRQ thread가 dispatch를 담당합니다.

각 message에는 worker thread에서 수행해야 하는 무작위의 작지 않은 processing 양이 들어 있습니다. 이는 간헐적인 load spike가 실행 중인 thread를 preempt하고 낮은 priority thread의 scheduling을 늦추는 bursty load 환경을 만듭니다.

Message에 포함된 timestamp를 사용해 다음 지점의 message별 latency를 계산합니다.

  • ISR에서 message를 만든 시점부터 MetaIRQ thread가 dispatch를 위해 받은 시점까지의 cycle 시간
  • ISR 실행 시점부터 worker thread가 message를 받은 시점까지의 시간
  • Worker thread에서 실제로 message를 처리한 시간. 요구된 processing 시간과 비교하면 thread가 schedule되지 않은 동안 생긴 preemption overhead를 측정할 수 있습니다.

결과에서 확인해야 할 특성은 다음과 같습니다.

  • 예상대로 평균적으로 priority가 높은, 즉 번호가 낮은 thread일수록 latency가 좋고 processing delay가 작습니다.
  • Cooperative scheduling thread는 일반적으로 MetaIRQ thread만 preempt할 수 있으므로 preemptible thread보다 processing delay 동작이 훨씬 좋습니다.
  • Queueing과 bursty load 때문에 CPU가 처리할 수 있는 시간보다 일이 많아지는 순간에는 priority와 관계없이 모든 worker thread가 load-dependent delay를 겪습니다.
  • System load나 thread 설정과 관계없이 MetaIRQ thread는 언제나 ISR 직후 즉시 실행됩니다. 일반적으로 preempt할 수 없는 cooperative thread를 포함해 다른 모든 thread를 preempt할 수 있으므로 모든 상황에서 안정적이고 일정한 latency를 보입니다.

요구 사항

실행 중인 thread를 interrupt가 preempt할 수 있고, timer driver와 log output이 정상 동작하는 모든 Zephyr platform에서 이 sample을 실행할 수 있습니다. 정밀도 때문에 timer tick rate가 높은 system, 이상적으로 10kHz 이상인 system에서 더 많고 좋은 data를 생성합니다.

이 test는 본질적으로 thread preemption 동작을 측정하므로 수정하지 않은 상태로는 native_sim platform에서 실행할 수 없습니다. 해당 emulation 환경에서는 k_busy_wait() 같은 특정 instrumentation point에서 thread가 자발적으로 CPU를 내놓을 때를 제외하면 thread가 preempt되지 않습니다.

Build와 실행

다음과 같이 frdm_k64f에서 application을 build하고 flash할 수 있습니다.

west build -b frdm_k64f samples/kernel/metairq_dispatch
west flash

다른 board용으로 build하려면 위 명령의 frdm_k64f를 해당 board 이름으로 바꾸십시오.

Sample 출력

아래 출력은 frdm_k64f에서 얻은 예입니다. 숫자는 board clock frequency와 다른 요인에 따라 달라집니다.

T2와 T3처럼 non-cooperative인 thread에서는 real 값이 대응하는 proc 값보다 의도대로 상당히 클 수 있습니다. 이는 thread preemption으로 생긴 delay 때문입니다.

I: Starting Thread0 at priority -2
I: Starting Thread1 at priority -1
II: M0 T0 mirq 4478 disp 7478 proc 24336 real 24613
I: M8 T0 mirq 4273 disp 86983 proc 9824 real 16753
I: M10 T0 mirq 4273 disp 495455 proc 21177 real 28273
I: M11 T0 mirq 4273 disp 981565 proc 48337 real 48918
I: M14 T0 mirq 4273 disp 1403627 proc 7079 real 7690
I: M17 T0 mirq 4273 disp 1810028 proc 42143 real 42925
I: M19 T0 mirq 4273 disp 2369217 proc 42471 real 42925
I: M20 T0 mirq 4273 disp 2940429 proc 30427 real 30775
I: M21 T0 mirq 4273 disp 3524151 proc 35871 real 36850
I: M22 T0 mirq 4273 disp 4042148 proc 33738 real 34420
I: M23 T0 mirq 4273 disp 4557010 proc 5757 real 6475
I: M29 T0 mirq 4273 disp 4759422 proc 49748 real 50215
I: M33 T0 mirq 4273 disp 5218935 proc 32105 real 33205
I: M35 T0 mirq 4273 disp 5732769 proc 32678 real 33205
I: M36 T0 mirq 4273 disp 6294586 proc 9303 real 10120
I: M37 T0 mirq 4273 disp 6819398 proc 29960 real 30775
I: M40 T0 mirq 3189 disp 7199139 proc 19692 real 21055
I: M9 T1 mirq 4273 disp 9417562 proc 53844 real 55075
I: M18 T1 mirq 4273 disp 9522780 proc 4560 real 5260
I: M25 T1 mirq 4273 disp 9713189 proc 56656 real 57505
I: M27 T1 mirq 4273 disp 10238978 proc 48347 real 49000
: Starting Thread2 at priority 0
I: M1 T2 mirq 4273 disp 12740821 proc 40449 real 41710
I: M2 T2 mirq 4273 disp 13311098 proc 43926 real 44140
I: M3 T2 mirq 4273 disp 13824365 proc 41212 real 41710
I: M4 T2 mirq 4273 disp 14382522 proc 12859 real 13765
I: M5 T2 mirq 4273 disp 14869754 proc 17303 real 18625
I: M7 T2 mirq 4273 disp 15368993 proc 10666 real 11335
I: M15 T2 mirq 4273 disp 15364239 proc 45304 real 46570
I: M24 T2 mirq 4273 disp 15602017 proc 39637 real 40495
I: M28 T2 mirq 4273 disp 15989555 proc 24436 real 24700
I: M30 T2 mirq 4273 disp 16493444 proc 44374 real 45355
I: M31 T2 mirq 4273 disp 17078141 proc 21947 real 22270
I: M34 T2 mirq 4273 disp 17555966 proc 47779 real 49000
I: M39 T2 mirq 4273 disp 17843806 proc 10954 real 11335
I: Starting Thread3 at priority 1
I: M6 T3 mirq 4273 disp 20625899 proc 13459 real 13765
I: M12 T3 mirq 4273 disp 20813171 proc 13534 real 13765
I: M13 T3 mirq 4273 disp 21334833 proc 37091 real 38065
I: M16 T3 mirq 4273 disp 21744289 proc 42514 real 42925
I: M26 T3 mirq 4273 disp 21846939 proc 36261 real 36850
I: M32 T3 mirq 4273 disp 22207336 proc 49987 real 50215
I: M38 T3 mirq 4273 disp 22532228 proc 37164 real 38065
I:         ---------- Latency (cyc) ----------
I:             Best    Worst     Mean    Stdev
I: MetaIRQ     4273     4478     4278       32
I: Thread0     7478  6819398  3190200  2183592
I: Thread1  9417562 10238978  9723127   316113
I: Thread2 12740821 17843806 15417286  1525493
I: Thread3 20625899 22532228 21586385   649911
I: MetaIRQ Test Complete

Source

출처

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