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

Linux 6.18.37 · Tracing

결정적 오토마타

결정적 오토마타의 5-튜플 정의, wip 상태 전이, O(1) C transition matrix, Graphviz DOT와 dot2c 변환을 설명합니다.

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

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

1. 요약·해설

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

요약·해설

deterministic_automata.rst:1-184

결정적 오토마타의 5-튜플 정의, wip 상태 전이, O(1) C transition matrix, Graphviz DOT와 dot2c 변환을 설명합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 Deterministic Automata
2 ======================
3
4 Formally, a deterministic automaton, denoted by G, is defined as a quintuple:
5
6 *G* = { *X*, *E*, *f*, x\ :subscript:`0`, X\ :subscript:`m` }
7
8 where:
9
10 - *X* is the set of states;
11 - *E* is the finite set of events;
12 - x\ :subscript:`0` is the initial state;
13 - X\ :subscript:`m` (subset of *X*) is the set of marked (or final) states.
14 - *f* : *X* x *E* -> *X* $ is the transition function. It defines the state
15 transition in the occurrence of an event from *E* in the state *X*. In the
16 special case of deterministic automata, the occurrence of the event in *E*
17 in a state in *X* has a deterministic next state from *X*.
18
19 For example, a given automaton named 'wip' (wakeup in preemptive) can
20 be defined as:
21
22 - *X* = { ``preemptive``, ``non_preemptive``}
23 - *E* = { ``preempt_enable``, ``preempt_disable``, ``sched_waking``}
24 - x\ :subscript:`0` = ``preemptive``
25 - X\ :subscript:`m` = {``preemptive``}
26 - *f* =
27 - *f*\ (``preemptive``, ``preempt_disable``) = ``non_preemptive``
28 - *f*\ (``non_preemptive``, ``sched_waking``) = ``non_preemptive``
29 - *f*\ (``non_preemptive``, ``preempt_enable``) = ``preemptive``
30
31 One of the benefits of this formal definition is that it can be presented
32 in multiple formats. For example, using a *graphical representation*, using
33 vertices (nodes) and edges, which is very intuitive for *operating system*
34 practitioners, without any loss.
35
36 The previous 'wip' automaton can also be represented as::
37
38 preempt_enable
39 +---------------------------------+
40 v |
41 #============# preempt_disable +------------------+
42 --> H preemptive H -----------------> | non_preemptive |
43 #============# +------------------+
44 ^ |
45 | sched_waking |
46 +--------------+
47
48 Deterministic Automaton in C
49 ----------------------------
50
51 In the paper "Efficient formal verification for the Linux kernel",
52 the authors present a simple way to represent an automaton in C that can
53 be used as regular code in the Linux kernel.
54
55 For example, the 'wip' automata can be presented as (augmented with comments)::
56
57 /* enum representation of X (set of states) to be used as index */
58 enum states {
59 preemptive = 0,
60 non_preemptive,
61 state_max
62 };
63
64 #define INVALID_STATE state_max
65
66 /* enum representation of E (set of events) to be used as index */
67 enum events {
68 preempt_disable = 0,
69 preempt_enable,
70 sched_waking,
71 event_max
72 };
73
74 struct automaton {
75 char *state_names[state_max]; // X: the set of states
76 char *event_names[event_max]; // E: the finite set of events
77 unsigned char function[state_max][event_max]; // f: transition function
78 unsigned char initial_state; // x_0: the initial state
79 bool final_states[state_max]; // X_m: the set of marked states
80 };
81
82 struct automaton aut = {
83 .state_names = {
84 "preemptive",
85 "non_preemptive"
86 },
87 .event_names = {
88 "preempt_disable",
89 "preempt_enable",
90 "sched_waking"
91 },
92 .function = {
93 { non_preemptive, INVALID_STATE, INVALID_STATE },
94 { INVALID_STATE, preemptive, non_preemptive },
95 },
96 .initial_state = preemptive,
97 .final_states = { 1, 0 },
98 };
99
100 The *transition function* is represented as a matrix of states (lines) and
101 events (columns), and so the function *f* : *X* x *E* -> *X* can be solved
102 in O(1). For example::
103
104 next_state = automaton_wip.function[curr_state][event];
105
106 Graphviz .dot format
107 --------------------
108
109 The Graphviz open-source tool can produce the graphical representation
110 of an automaton using the (textual) DOT language as the source code.
111 The DOT format is widely used and can be converted to many other formats.
112
113 For example, this is the 'wip' model in DOT::
114
115 digraph state_automaton {
116 {node [shape = circle] "non_preemptive"};
117 {node [shape = plaintext, style=invis, label=""] "__init_preemptive"};
118 {node [shape = doublecircle] "preemptive"};
119 {node [shape = circle] "preemptive"};
120 "__init_preemptive" -> "preemptive";
121 "non_preemptive" [label = "non_preemptive"];
122 "non_preemptive" -> "non_preemptive" [ label = "sched_waking" ];
123 "non_preemptive" -> "preemptive" [ label = "preempt_enable" ];
124 "preemptive" [label = "preemptive"];
125 "preemptive" -> "non_preemptive" [ label = "preempt_disable" ];
126 { rank = min ;
127 "__init_preemptive";
128 "preemptive";
129 }
130 }
131
132 This DOT format can be transformed into a bitmap or vectorial image
133 using the dot utility, or into an ASCII art using graph-easy. For
134 instance::
135
136 $ dot -Tsvg -o wip.svg wip.dot
137 $ graph-easy wip.dot > wip.txt
138
139 dot2c
140 -----
141
142 dot2c is a utility that can parse a .dot file containing an automaton as
143 in the example above and automatically convert it to the C representation
144 presented in [3].
145
146 For example, having the previous 'wip' model into a file named 'wip.dot',
147 the following command will transform the .dot file into the C
148 representation (previously shown) in the 'wip.h' file::
149
150 $ dot2c wip.dot > wip.h
151
152 The 'wip.h' content is the code sample in section 'Deterministic Automaton
153 in C'.
154
155 Remarks
156 -------
157
158 The automata formalism allows modeling discrete event systems (DES) in
159 multiple formats, suitable for different applications/users.
160
161 For example, the formal description using set theory is better suitable
162 for automata operations, while the graphical format for human interpretation;
163 and computer languages for machine execution.
164
165 References
166 ----------
167
168 Many textbooks cover automata formalism. For a brief introduction see::
169
170 O'Regan, Gerard. Concise guide to software engineering. Springer,
171 Cham, 2017.
172
173 For a detailed description, including operations, and application on Discrete
174 Event Systems (DES), see::
175
176 Cassandras, Christos G., and Stephane Lafortune, eds. Introduction to discrete
177 event systems. Boston, MA: Springer US, 2008.
178
179 For the C representation in kernel, see::
180
181 De Oliveira, Daniel Bristot; Cucinotta, Tommaso; De Oliveira, Romulo
182 Silva. Efficient formal verification for the Linux kernel. In:
183 International Conference on Software Engineering and Formal Methods.
184 Springer, Cham, 2019. p. 315-332.
185

3. 한국어 전문 번역

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

형식 정의와 wip 예제

1-47

형식적으로 `G`로 나타내는 결정적 오토마타는 5-튜플 `G = { X, E, f, x₀, Xₘ }`로 정의한다.

결정적 오토마타 5-튜플
기호정의
`X`state의 집합
`E`유한한 event 집합
`x₀`initial state
`Xₘ ⊆ X`marked 또는 final state의 집합
`f: X × E → X`state X에서 event E가 발생했을 때의 state transition function

상태, event, initial·final state와 transition function으로 모델을 정의한다.

결정적 오토마타에서는 어떤 state에서 특정 event가 발생하면 다음 state가 하나로 결정된다.

`wip`(wakeup in preemptive) 오토마타는 state `preemptive`, `non_preemptive`, event `preempt_enable`, `preempt_disable`, `sched_waking`을 갖는다. initial·marked state는 모두 `preemptive`다.

wip transition function
현재 stateevent다음 state
`preemptive``preempt_disable``non_preemptive`
`non_preemptive``sched_waking``non_preemptive`
`non_preemptive``preempt_enable``preemptive`

세 event가 두 state 사이에서 허용하는 transition이다.

형식 정의의 장점은 정보를 잃지 않고 여러 표현으로 나타낼 수 있다는 것이다. 예를 들어 정점과 간선으로 된 그래프는 운영체제 실무자가 직관적으로 이해하기 좋다.

wip 상태 그래프
startpreemptive (initial·final)
preempt_disablenon_preemptive
sched_wakingnon_preemptive self-loop
preempt_enablepreemptive

원문의 ASCII 오토마타를 초기·final state와 event 간선으로 구조화했다.

Deterministic Automata
======================

Formally, a deterministic automaton, denoted by G, is defined as a quintuple:

        *G* = { *X*, *E*, *f*, x\ :subscript:`0`, X\ :subscript:`m` }

where:

- *X* is the set of states;
- *E* is the finite set of events;
- x\ :subscript:`0` is the initial state;
- X\ :subscript:`m` (subset of *X*) is the set of marked (or final) states.
- *f* : *X* x *E* -> *X* $ is the transition function. It defines the state
  transition in the occurrence of an event from *E* in the state *X*. In the
  special case of deterministic automata, the occurrence of the event in *E*
  in a state in *X* has a deterministic next state from *X*.

For example, a given automaton named 'wip' (wakeup in preemptive) can
be defined as:

- *X* = { ``preemptive``, ``non_preemptive``}
- *E* = { ``preempt_enable``, ``preempt_disable``, ``sched_waking``}
- x\ :subscript:`0` = ``preemptive``
- X\ :subscript:`m` = {``preemptive``}
- *f* =
   - *f*\ (``preemptive``, ``preempt_disable``) = ``non_preemptive``
   - *f*\ (``non_preemptive``, ``sched_waking``) = ``non_preemptive``
   - *f*\ (``non_preemptive``, ``preempt_enable``) = ``preemptive``

One of the benefits of this formal definition is that it can be presented
in multiple formats. For example, using a *graphical representation*, using
vertices (nodes) and edges, which is very intuitive for *operating system*
practitioners, without any loss.

The previous 'wip' automaton can also be represented as::

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

C 표현

48-105

논문 ‘Efficient formal verification for the Linux kernel’은 Linux kernel에서 일반 코드처럼 사용할 수 있는 간단한 C 오토마타 표현을 제시한다.

`wip`에서는 `enum states`와 `enum events`가 각각 `X`와 `E`를 배열 index로 바꾸며 `INVALID_STATE`는 정의되지 않은 transition을 표시한다. `struct automaton`은 state·event 이름, 2차원 transition matrix, initial state, final state bitmap을 보관한다.

  /* enum representation of X (set of states) to be used as index */
  enum states {
	preemptive = 0,
	non_preemptive,
	state_max
  };

  #define INVALID_STATE state_max

  /* enum representation of E (set of events) to be used as index */
  enum events {
	preempt_disable = 0,
	preempt_enable,
	sched_waking,
	event_max
  };

  struct automaton {
	char *state_names[state_max];                   // X: the set of states
	char *event_names[event_max];                   // E: the finite set of events
	unsigned char function[state_max][event_max];   // f: transition function
	unsigned char initial_state;                    // x_0: the initial state
	bool final_states[state_max];                   // X_m: the set of marked states
  };

  struct automaton aut = {
	.state_names = {
		"preemptive",
		"non_preemptive"
	},
	.event_names = {
		"preempt_disable",
		"preempt_enable",
		"sched_waking"
	},
	.function = {
		{ non_preemptive,  INVALID_STATE,  INVALID_STATE },
		{  INVALID_STATE,     preemptive, non_preemptive },
	},
	.initial_state = preemptive,
	.final_states = { 1, 0 },
  };
C 구조체와 형식 요소 대응
C field형식 요소용도
`state_names[]``X`state 이름
`event_names[]``E`event 이름
`function[][]``f`state×event transition matrix
`initial_state``x₀`시작 state
`final_states[]``Xₘ`marked state 표시

수학적 5-튜플을 정적 C 데이터로 직접 표현한다.

transition function은 행이 state, 열이 event인 matrix다. 따라서 `f: X × E → X`는 배열 index 한 번으로 O(1)에 계산할 수 있다.

  next_state = automaton_wip.function[curr_state][event];
O(1) transition 조회
curr_statematrix row
eventmatrix column
function[curr_state][event]next_state

현재 state와 event를 두 index로 사용해 다음 state를 바로 얻는다.

Deterministic Automaton in C
----------------------------

In the paper "Efficient formal verification for the Linux kernel",
the authors present a simple way to represent an automaton in C that can
be used as regular code in the Linux kernel.

For example, the 'wip' automata can be presented as (augmented with comments)::

  /* enum representation of X (set of states) to be used as index */
  enum states {
	preemptive = 0,
	non_preemptive,
	state_max
  };

  #define INVALID_STATE state_max

  /* enum representation of E (set of events) to be used as index */
  enum events {
	preempt_disable = 0,
	preempt_enable,
	sched_waking,
	event_max
  };

  struct automaton {
	char *state_names[state_max];                   // X: the set of states
	char *event_names[event_max];                   // E: the finite set of events
	unsigned char function[state_max][event_max];   // f: transition function
	unsigned char initial_state;                    // x_0: the initial state
	bool final_states[state_max];                   // X_m: the set of marked states
  };

  struct automaton aut = {
	.state_names = {
		"preemptive",
		"non_preemptive"
	},
	.event_names = {
		"preempt_disable",
		"preempt_enable",
		"sched_waking"
	},
	.function = {
		{ non_preemptive,  INVALID_STATE,  INVALID_STATE },
		{  INVALID_STATE,     preemptive, non_preemptive },
	},
	.initial_state = preemptive,
	.final_states = { 1, 0 },
  };

The *transition function* is represented as a matrix of states (lines) and
events (columns), and so the function *f* : *X* x *E* -> *X* can be solved
in O(1). For example::

  next_state = automaton_wip.function[curr_state][event];

Graphviz DOT 형식

106-138

Graphviz open-source 도구는 텍스트 DOT 언어를 source code로 사용해 오토마타의 그래픽 표현을 만들 수 있다. DOT는 널리 쓰이며 다양한 형식으로 변환할 수 있다.

`wip` DOT 모델은 보이지 않는 initial node, double-circle final state, 일반 state와 event label이 붙은 edge로 같은 오토마타를 표현한다.

  digraph state_automaton {
        {node [shape = circle] "non_preemptive"};
        {node [shape = plaintext, style=invis, label=""] "__init_preemptive"};
        {node [shape = doublecircle] "preemptive"};
        {node [shape = circle] "preemptive"};
        "__init_preemptive" -> "preemptive";
        "non_preemptive" [label = "non_preemptive"];
        "non_preemptive" -> "non_preemptive" [ label = "sched_waking" ];
        "non_preemptive" -> "preemptive" [ label = "preempt_enable" ];
        "preemptive" [label = "preemptive"];
        "preemptive" -> "non_preemptive" [ label = "preempt_disable" ];
        { rank = min ;
                "__init_preemptive";
                "preemptive";
        }
  }
DOT 요소와 wip 의미
DOT 요소wip 의미
`__init_preemptive` plaintext invisinitial 진입점
`preemptive` doublecirclemarked·final state
`non_preemptive` circle일반 state
edge `label`transition을 일으키는 event

노드 모양과 간선 label이 오토마타의 형식 요소를 나타낸다.

`dot` utility로 bitmap 또는 vector image를 만들고 `graph-easy`로 ASCII art를 만들 수 있다.

  $ dot -Tsvg -o wip.svg wip.dot
  $ graph-easy wip.dot > wip.txt
DOT 출력 변환
wip.dotdot -Tsvg
wip.svgvector image
wip.dotgraph-easy
wip.txtASCII art

동일한 텍스트 모델을 시각 또는 텍스트 표현으로 렌더링한다.

Graphviz .dot format
--------------------

The Graphviz open-source tool can produce the graphical representation
of an automaton using the (textual) DOT language as the source code.
The DOT format is widely used and can be converted to many other formats.

For example, this is the 'wip' model in DOT::

  digraph state_automaton {
        {node [shape = circle] "non_preemptive"};
        {node [shape = plaintext, style=invis, label=""] "__init_preemptive"};
        {node [shape = doublecircle] "preemptive"};
        {node [shape = circle] "preemptive"};
        "__init_preemptive" -> "preemptive";
        "non_preemptive" [label = "non_preemptive"];
        "non_preemptive" -> "non_preemptive" [ label = "sched_waking" ];
        "non_preemptive" -> "preemptive" [ label = "preempt_enable" ];
        "preemptive" [label = "preemptive"];
        "preemptive" -> "non_preemptive" [ label = "preempt_disable" ];
        { rank = min ;
                "__init_preemptive";
                "preemptive";
        }
  }

This DOT format can be transformed into a bitmap or vectorial image
using the dot utility, or into an ASCII art using graph-easy. For
instance::

  $ dot -Tsvg -o wip.svg wip.dot
  $ graph-easy wip.dot > wip.txt

dot2c 변환

139-154

`dot2c`는 앞 예제와 같은 오토마타를 담은 `.dot` 파일을 해석해 앞 절의 C 표현으로 자동 변환하는 utility다.

`wip.dot` 파일을 다음 명령으로 변환하면 C 표현을 담은 `wip.h`가 생성된다.

  $ dot2c wip.dot > wip.h

생성된 `wip.h` 내용은 ‘Deterministic Automaton in C’ 절의 code sample과 같다.

dot2c 생성 경로
wip.dotdot2c parser
state·event·edge 분석transition matrix 생성
wip.hkernel C representation

사람이 편집하는 DOT 모델을 kernel에서 사용할 정적 C 데이터로 바꾼다.

dot2c
-----

dot2c is a utility that can parse a .dot file containing an automaton as
in the example above and automatically convert it to the C representation
presented in [3].

For example, having the previous 'wip' model into a file named 'wip.dot',
the following command will transform the .dot file into the C
representation (previously shown) in the 'wip.h' file::

  $ dot2c wip.dot > wip.h

The 'wip.h' content is the code sample in section 'Deterministic Automaton
in C'.

비고와 참고 문헌

155-184

오토마타 형식론은 discrete event system(DES)을 여러 형식으로 모델링할 수 있게 하며, 각 표현은 서로 다른 응용과 사용자에게 적합하다.

집합론을 사용한 형식 기술은 오토마타 연산에 적합하고, 그래픽 형식은 사람이 해석하기 좋으며, computer language 표현은 machine execution에 적합하다.

표현 형식별 용도
표현주요 용도
집합론 5-튜플형식 분석과 오토마타 연산
상태 그래프·DOT사람의 설계·검토
C 구조체·matrixkernel에서 O(1) 실행

같은 오토마타를 목적에 따라 다른 손실 없는 표현으로 선택한다.

간단한 입문 자료로 Gerard O'Regan의 ‘Concise guide to software engineering’(Springer, 2017)을 제시한다. DES의 연산과 응용을 포함한 상세 자료로 Cassandras와 Lafortune의 ‘Introduction to discrete event systems’(Springer US, 2008)을 제시한다.

kernel C 표현은 Daniel Bristot de Oliveira, Tommaso Cucinotta, Romulo Silva de Oliveira의 ‘Efficient formal verification for the Linux kernel’(SEFM 2019, pp. 315-332)을 참조한다.

Many textbooks cover automata formalism. For a brief introduction see::

  O'Regan, Gerard. Concise guide to software engineering. Springer,
  Cham, 2017.

For a detailed description, including operations, and application on Discrete
Event Systems (DES), see::

  Cassandras, Christos G., and Stephane Lafortune, eds. Introduction to discrete
  event systems. Boston, MA: Springer US, 2008.

For the C representation in kernel, see::

  De Oliveira, Daniel Bristot; Cucinotta, Tommaso; De Oliveira, Romulo
  Silva. Efficient formal verification for the Linux kernel. In:
  International Conference on Software Engineering and Formal Methods.
  Springer, Cham, 2019. p. 315-332.
Remarks
-------

The automata formalism allows modeling discrete event systems (DES) in
multiple formats, suitable for different applications/users.

For example, the formal description using set theory is better suitable
for automata operations, while the graphical format for human interpretation;
and computer languages for machine execution.

References
----------

Many textbooks cover automata formalism. For a brief introduction see::

  O'Regan, Gerard. Concise guide to software engineering. Springer,
  Cham, 2017.

For a detailed description, including operations, and application on Discrete
Event Systems (DES), see::

  Cassandras, Christos G., and Stephane Lafortune, eds. Introduction to discrete
  event systems. Boston, MA: Springer US, 2008.

For the C representation in kernel, see::

  De Oliveira, Daniel Bristot; Cucinotta, Tommaso; De Oliveira, Romulo
  Silva. Efficient formal verification for the Linux kernel. In:
  International Conference on Software Engineering and Formal Methods.
  Springer, Cham, 2019. p. 315-332.