← Documents Documentation/trace/rv/monitor_wip.rst GitHub 원문 ↗

Linux 6.18.37 · Tracing

wip 모니터

per-CPU wip 오토마톤의 preemptive 상태 전이와 preempt_count 및 trace event 사이의 interrupt 비원자성으로 생기는 불일치를 설명합니다.

Source pathDocumentation/trace/rv/monitor_wip.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

monitor_wip.rst:1-55

per-CPU wip 오토마톤의 preemptive 상태 전이와 preempt_count 및 trace event 사이의 interrupt 비원자성으로 생기는 불일치를 설명합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 Monitor wip
2 ===========
3
4 - Name: wip - wakeup in preemptive
5 - Type: per-cpu deterministic automaton
6 - Author: Daniel Bristot de Oliveira <bristot@kernel.org>
7
8 Description
9 -----------
10
11 The wakeup in preemptive (wip) monitor is a sample per-cpu monitor
12 that verifies if the wakeup events always take place with
13 preemption disabled::
14
15 |
16 |
17 v
18 #==================#
19 H preemptive H <+
20 #==================# |
21 | |
22 | preempt_disable | preempt_enable
23 v |
24 sched_waking +------------------+ |
25 +--------------- | | |
26 | | non_preemptive | |
27 +--------------> | | -+
28 +------------------+
29
30 The wakeup event always takes place with preemption disabled because
31 of the scheduler synchronization. However, because the preempt_count
32 and its trace event are not atomic with regard to interrupts, some
33 inconsistencies might happen. For example::
34
35 preempt_disable() {
36 __preempt_count_add(1)
37 -------> smp_apic_timer_interrupt() {
38 preempt_disable()
39 do not trace (preempt count >= 1)
40
41 wake up a thread
42
43 preempt_enable()
44 do not trace (preempt count >= 1)
45 }
46 <------
47 trace_preempt_disable();
48 }
49
50 This problem was reported and discussed here:
51 https://lore.kernel.org/r/cover.1559051152.git.bristot@redhat.com/
52
53 Specification
54 -------------
55 Grapviz Dot file in tools/verification/models/wip.dot
56

3. 한국어 전문 번역

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

설명과 상태 전이

1-29

`wip`은 wakeup in preemptive의 약자이며 Daniel Bristot de Oliveira가 작성한 per-CPU 결정적 오토마톤 예제 monitor이다. wakeup event가 항상 preemption이 비활성화된 상태에서 발생하는지 검증한다.

wip 상태 전이
startpreemptive (initial/final)
preempt_disablenon_preemptive
sched_wakingnon_preemptive self-loop
preempt_enablepreemptive

원문의 ASCII 오토마톤을 초기 상태, 전이 event, self-loop가 드러나는 흐름으로 다시 구성했다.

wip 오토마톤
현재 stateevent다음 state
`preemptive``preempt_disable``non_preemptive`
`non_preemptive``sched_waking``non_preemptive`
`non_preemptive``preempt_enable``preemptive`

각 state에서 관찰하는 event와 다음 state를 정리한다.

Monitor wip
===========

- Name: wip - wakeup in preemptive
- Type: per-cpu deterministic automaton
- Author: Daniel Bristot de Oliveira <bristot@kernel.org>

Description
-----------

The wakeup in preemptive (wip) monitor is a sample per-cpu monitor
that verifies if the wakeup events always take place with
preemption disabled::

                     |
                     |
                     v
                   #==================#
                   H    preemptive    H <+
                   #==================#  |
                     |                   |
                     | preempt_disable   | preempt_enable
                     v                   |
    sched_waking   +------------------+  |
  +--------------- |                  |  |
  |                |  non_preemptive  |  |
  +--------------> |                  | -+
                   +------------------+

interrupt와 trace event의 비원자성

30-52

scheduler 동기화 때문에 wakeup event는 항상 preemption이 비활성화된 상태에서 일어난다. 그러나 `preempt_count` 변경과 해당 trace event 발생은 interrupt에 대해 원자적이지 않으므로 불일치가 생길 수 있다.

예에서는 바깥 `preempt_disable()`이 `__preempt_count_add(1)`로 count를 먼저 올린 뒤 `trace_preempt_disable()`을 호출하기 전에 `smp_apic_timer_interrupt()`가 끼어든다.

interrupt 안의 `preempt_disable()`과 `preempt_enable()`은 preempt count가 이미 1 이상이어서 trace되지 않지만, 그 사이 thread를 깨운다. 결과적으로 실제로는 preemption이 비활성화되었는데 monitor가 그 전이 event를 보지 못한 상태에서 wakeup을 관찰할 수 있다.

  preempt_disable() {
	__preempt_count_add(1)
	------->	smp_apic_timer_interrupt() {
				preempt_disable()
					do not trace (preempt count >= 1)

				wake up a thread

				preempt_enable()
					 do not trace (preempt count >= 1)
			}
	<------
	trace_preempt_disable();
  }

이 문제는 원문 링크 `https://lore.kernel.org/r/cover.1559051152.git.bristot@redhat.com/`에서 보고되고 논의되었다.

trace 불일치 발생 순서
__preempt_count_add(1)preemption 실제 비활성화
timer interrupt 진입중첩 preempt event는 trace하지 않음
wake up a threadwip가 wakeup 관찰
trace_preempt_disable()바깥 event가 뒤늦게 기록

preempt count 갱신과 tracepoint 사이에 interrupt가 끼어들 수 있다.

The wakeup event always takes place with preemption disabled because
of the scheduler synchronization. However, because the preempt_count
and its trace event are not atomic with regard to interrupts, some
inconsistencies might happen. For example::

  preempt_disable() {
	__preempt_count_add(1)
	------->	smp_apic_timer_interrupt() {
				preempt_disable()
					do not trace (preempt count >= 1)

				wake up a thread

				preempt_enable()
					 do not trace (preempt count >= 1)
			}
	<------
	trace_preempt_disable();
  }

This problem was reported and discussed here:
  https://lore.kernel.org/r/cover.1559051152.git.bristot@redhat.com/

명세 위치

53-55

Graphviz Dot 명세 파일은 `tools/verification/models/wip.dot`에 있다. 원문의 `Grapviz` 철자는 원문 보존 영역에 그대로 유지한다.

Specification
-------------
Grapviz Dot file in tools/verification/models/wip.dot