diff --git a/.gitignore b/.gitignore index d30354c..b413bc3 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,6 @@ docs/ # vendor 아래의 파일은 위 규칙에 걸려도 전부 추적함. cargo가 크레이트의 모든 # 파일을 체크섬으로 확인하므로 하나라도 빠지면 오프라인 빌드가 실패함 !vendor/** + +# Lean build output +proofs/lean/.lake/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5f9218c..4992b94 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -92,9 +92,9 @@ $ cargo build -p k0-kernel --features console --offline $ tools/qemu-boot-test.sh # boot under QEMU and check the self-tests ``` -`tools/host-test.sh` runs the tests of `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-vault` and `k0-term` on any host (377 tests on an AArch64 host, 289 elsewhere). `k0-slice` has 9 tests: they run the rule that decides whether a tick cuts the running task on a model of the scheduler. It runs `k0-vault` twice, with and without the algorithm feature `vault-ed25519`, which gives 20 and 11 tests. It runs `k0-term` with and without the vault feature, which gives 24 and 21 tests. The tests of `k0-mm` contain AArch64 inline assembly, so they only run on an AArch64 host (Apple Silicon or Linux arm64). The script runs them for both the 4 KiB and the 16 KiB granule. +`tools/host-test.sh` runs the tests of `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-part`, `k0-vault` and `k0-term` on any host (415 tests on an AArch64 host, 327 elsewhere). `k0-slice` has 9 tests: they run the rule that decides whether a tick cuts the running task on a model of the scheduler. `k0-part` has 36 tests: they run the scheduler's decisions under a time partition table on a model of the kernel, check the arithmetic of tick instants, and compare the Rust code with the recorded results of a Lean model (see "Changing the scheduler core" below). It runs `k0-vault` twice, with and without the algorithm feature `vault-ed25519`, which gives 20 and 11 tests. It runs `k0-term` with and without the vault feature, which gives 24 and 21 tests. The tests of `k0-mm` contain AArch64 inline assembly, so they only run on an AArch64 host (Apple Silicon or Linux arm64). The script runs them for both the 4 KiB and the 16 KiB granule. -`tools/qemu-boot-test.sh` boots the debug kernel, checks the boot log line by line in a fixed order, fails on any error marker, and stops QEMU as soon as the root task reports `root: sched tests pass`. Besides the pass lines, it expects `k0: kernel reserve ` before the `k0: untyped ` lines, `k0: idle (waiting for a timeout)` and `root: timeout tests pass` after `root: teardown tests pass`, and `root: kernel reserve tests pass` after `root: revocation tests pass`. Any line that starts with `k0: all tasks` is a failure. It also counts the timer tick lines between `root: teardown tests pass` and `root: timeout tests pass` and wants at least 4, because EL0 has no clock and this is how the lower bound of a timeout is checked. The timeout tests wait for real ticks, so a boot takes about 4 seconds longer than it did before. The time slice test runs twice (a task that got the CPU by `YIELD`, then one that got it by blocking) and takes about 4 seconds in all where the preemption test it replaced took about 1. It also expects `root: slice test yield pass` and `root: slice test block pass`, in this order, before `root: preempt test pass`. Set `K0_BOOT_TIMEOUT` (seconds) on slow machines. It reads the serial port, so it needs an image with a console driver. To test an image without console, use `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty` and `K0_BOOT_CONSOLE_PAGE`, which are described in "Testing an image without console" in [USAGE.md](USAGE.md#testing-an-image-without-console). +`tools/qemu-boot-test.sh` boots the debug kernel, checks the boot log line by line in a fixed order, fails on any error marker, and stops QEMU as soon as the root task reports `root: sched tests pass`. Besides the pass lines, it expects `k0: kernel reserve ` before the `k0: untyped ` lines, `k0: idle (waiting for a timeout)` and `root: timeout tests pass` after `root: teardown tests pass`, and `root: kernel reserve tests pass` after `root: revocation tests pass`. Any line that starts with `k0: all tasks` is a failure. It also counts the timer tick lines between `root: teardown tests pass` and `root: timeout tests pass` and wants at least 4, because EL0 has no clock and this is how the lower bound of a timeout is checked. The timeout tests wait for real ticks, so a boot takes about 4 seconds longer than it did before. The time slice test runs twice (a task that got the CPU by `YIELD`, then one that got it by blocking) and takes about 4 seconds in all where the preemption test it replaced took about 1. It also expects `root: slice test yield pass` and `root: slice test block pass`, in this order, before `root: preempt test pass`. After that come `root: partition refusal pass` and `root: partition window pass`, and `root: partition sealed` comes before `root: sched tests pass`. The time partition test lets a table of 9 ticks run one round, so it adds about 15 seconds to every boot. If the host stalls QEMU for more than a second during it, the test runs once more and the script reports `boot-test: partition window retries: 1` without failing. `tools/boot-matrix.sh` runs such a boot row again and fails it when the second run needed the retry too. Set `K0_BOOT_TIMEOUT` (seconds) on slow machines. It reads the serial port, so it needs an image with a console driver. To test an image without console, use `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty` and `K0_BOOT_CONSOLE_PAGE`, which are described in "Testing an image without console" in [USAGE.md](USAGE.md#testing-an-image-without-console). An image with the signing oracle (`vault` or `vault-ed25519`) has two more intended faults, so it prints 8 `k0: task fault` lines instead of 6. Run the test with `K0_BOOT_FAULTS=8` and require `root: oracle tests pass` with `K0_BOOT_REQUIRE`. The boot matrix has the rows `vault`, `vault-max`, `vault-el2`, `vault-16k`, `vault-no-alg`, `hvf-vault` and the static check `vault-symbols` for it, and 82 rows in total on a Mac with HVF and 71 in CI. The rows `input-*` and `term-*` cover console input and the terminal. A terminal image prints two more `k0: task fault` lines (8 without the vault, 10 with it), and `tools/term-test.py ` runs its scripted serial session. [USAGE.md](USAGE.md) describes the rows. @@ -130,6 +130,7 @@ In the following table, you can see where each area is tested. | `k0-efi` memory plan from the UEFI memory map, DTB rewrite, independent check, ACPI table reader and tree synthesis | yes, plus fuzzing | yes, through the `uefi-*` rows of the boot matrix | | `loader` (UEFI application: firmware calls, cache flush, MMU off, jump) | no | yes, through the `uefi-*` rows, plus the static check `tools/pe-check.py` | | `k0-mm` page tables and W^X attributes | yes, on AArch64 hosts | yes | +| `k0-slice` tick rule and `k0-part` scheduling decisions, table decoding and tick arithmetic | yes, including the comparison with the recorded results of the Lean model | yes, through the slice test and the partition test, by the order of events only | | `k0-arch`, `k0-task`, `k0-sched`, `k0-ipc` | no | yes | `k0-arch` assembles with ELF-only directives and the scheduler and IPC paths read system registers, so they are only exercised by booting. If you change them, extend the root task self-tests in `userspace/root-task/src/main.rs` and add the new pass line to the expected list in `tools/qemu-boot-test.sh`. @@ -153,6 +154,15 @@ With `-p k0-efi` it runs three more fuzzers, which work the same way. The UEFI m `K0_FUZZ_ITERS`, `K0_FUZZ_SEED` and `K0_FUZZ_CASE` work the same for all of them. `K0_FUZZ_SEED` changes the base seed. Different base seeds give unrelated streams of cases. When a case fails, the test prints a `K0_FUZZ_CASE=0x...` value. Run the same command with that variable set to replay only that case and dump the input. +### Changing the scheduler core + +`crates/k0-part` holds every scheduling decision (`Core`) and the arithmetic of tick instants (`clock`). `proofs/lean` holds Lean 4 proofs about a model of it, and `crates/k0-part/src/model_vectors.txt` holds 1600 event scripts with the result the model gives for each. The host test `core_gives_the_lines_of_the_lean_model_on_every_recorded_script` runs those scripts through the real `Core` and fails when the two differ. CI runs that test. CI does not run the proofs. + +> [!IMPORTANT] +> If you change what `Core` does, make the same change in `proofs/lean/K0Part.lean`, get `lake build` to pass again, and write the hashes again from the model. Never edit a hash by hand to make the test pass. [proofs/lean/README.md](proofs/lean/README.md) has the steps under "When the Rust code or the model changes on purpose". + +The proofs are about the model, not about the Rust code. Do not describe a change as proved because the Lean files build. `k0-sched`, `k0-ipc` and the kernel binary have no host tests, and no test sees the guard, the hold before the return to EL0 or the TLB flush at a change of domain, so a change there needs a careful review and a description of how you checked it. + ### Running exactly what CI runs CI builds the container image from `ci/Dockerfile` and then runs the tests inside it with networking disabled. This proves that building and testing need nothing outside the repository. You can run it as follows: @@ -163,11 +173,13 @@ $ docker run --rm --network none k0-ci tools/host-test.sh $ docker run --rm --network none k0-ci tools/boot-matrix.sh ``` +The CI job has a limit of 45 minutes. With the time partition test in every boot, a run is estimated at about 30 minutes. That is an estimate, not a measurement on CI. + Run this from **a clean checkout**, because the build context is the working directory. The following list describes how the image is made. - **Base image**: it is pinned by the digest of its multi-architecture index (`debian:bookworm@sha256:...`). - **Rust toolchain**: the image does not use rustup. `ci/install-toolchain.py` pins the SHA-256 of the Rust 1.89.0 channel manifest and checks every package it installs (rustc, cargo, rust-std for the host and for `aarch64-unknown-none-softfloat` and `aarch64-unknown-uefi`, rust-src and llvm-tools) against the hashes in that manifest. A mismatch fails the image build. -- **Build context**: `.dockerignore` is an allowlist, so nothing enters the image unless it is listed there. **A new top-level file or directory** that the build or the tests need must be added to it. `.git` is kept in the image. +- **Build context**: `.dockerignore` is an allowlist, so nothing enters the image unless it is listed there. **A new top-level file or directory** that the build or the tests need must be added to it. `.git` is kept in the image. `proofs/` is not listed, so the Lean files are not in the image. > [!NOTE] > Not everything is pinned. The versions of the Debian packages float (apt checks them with the archive keys inside the pinned base image), and so do the GitHub runner images. The GitHub Actions used by the workflows are pinned by commit hash. diff --git a/CONTRIBUTING_KR.md b/CONTRIBUTING_KR.md index 9f4bc41..eaed06a 100644 --- a/CONTRIBUTING_KR.md +++ b/CONTRIBUTING_KR.md @@ -94,9 +94,9 @@ $ cargo build -p k0-kernel --features console --offline $ tools/qemu-boot-test.sh # QEMU 부팅과 자가 테스트 확인 ``` -`tools/host-test.sh`는 `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-vault`, `k0-term`의 테스트를 어느 호스트에서나 실행합니다(AArch64 호스트에서 377개, 그 밖에서 289개). `k0-slice`는 9개이며, 틱이 실행 중인 태스크를 끊을지 정하는 규칙을 스케줄러 모델로 검사합니다. `k0-vault`는 알고리즘 feature `vault-ed25519`를 포함한 경우와 포함하지 않은 경우로 두 번 실행하며, 각각 20개와 11개입니다. `k0-term`도 `vault` feature를 포함한 경우와 포함하지 않은 경우로 실행하며, 각각 24개와 21개입니다. `k0-mm` 테스트는 AArch64 인라인 어셈블리를 포함하기 때문에 AArch64 호스트(Apple Silicon 또는 Linux arm64)에서만 실행되며, 스크립트가 4 KiB와 16 KiB 그래뉼 두 구성으로 모두 돌립니다. +`tools/host-test.sh`는 `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-part`, `k0-vault`, `k0-term`의 테스트를 어느 호스트에서나 실행합니다(AArch64 호스트에서 415개, 그 밖에서 327개). `k0-slice`는 9개이며, 틱이 실행 중인 태스크를 끊을지 정하는 규칙을 스케줄러 모델로 검사합니다. `k0-part`는 36개입니다. 시간 분할 표가 있을 때의 스케줄러 판정을 커널 모델 위에서 실행하고, 틱 시각의 산술을 검사하고, Rust 코드를 Lean 모델의 기록된 결과와 비교합니다(뒤의 "스케줄러 코어를 바꿀 때" 참고). `k0-vault`는 알고리즘 feature `vault-ed25519`를 포함한 경우와 포함하지 않은 경우로 두 번 실행하며, 각각 20개와 11개입니다. `k0-term`도 `vault` feature를 포함한 경우와 포함하지 않은 경우로 실행하며, 각각 24개와 21개입니다. `k0-mm` 테스트는 AArch64 인라인 어셈블리를 포함하기 때문에 AArch64 호스트(Apple Silicon 또는 Linux arm64)에서만 실행되며, 스크립트가 4 KiB와 16 KiB 그래뉼 두 구성으로 모두 돌립니다. -`tools/qemu-boot-test.sh`는 디버그 커널을 부팅하고 부팅 로그를 정해진 순서대로 한 줄씩 확인합니다. 에러 표식이 하나라도 나오면 실패하고, 루트 태스크가 `root: sched tests pass`를 출력하면 곧바로 QEMU를 종료합니다. 통과 줄 외에도 `k0: untyped ` 줄보다 앞의 `k0: kernel reserve `, `root: teardown tests pass` 뒤의 `k0: idle (waiting for a timeout)`와 `root: timeout tests pass`, `root: revocation tests pass` 뒤의 `root: kernel reserve tests pass`를 기대합니다. `k0: all tasks`로 시작하는 줄은 모두 실패입니다. `root: teardown tests pass`와 `root: timeout tests pass` 사이의 타이머 틱 줄도 세어 4개 이상을 요구하는데, EL0에는 시계가 없어서 이것이 타임아웃의 하한을 확인하는 방법이기 때문입니다. 타임아웃 테스트는 실제 틱을 기다리므로 부팅 한 번이 이전보다 약 4초 더 걸립니다. 시간 조각 테스트는 두 번(`YIELD`로 CPU를 받은 태스크, 기다림으로 받은 태스크) 실행해 합계 약 4초가 걸리며, 이를 대신한 이전 선점 테스트는 약 1초가 걸렸습니다. `root: preempt test pass`보다 앞에 `root: slice test yield pass`와 `root: slice test block pass`가 이 순서로 나오는 것도 기대합니다. 느린 환경에서는 `K0_BOOT_TIMEOUT`(초)을 늘려 주세요. 직렬 포트를 읽기 때문에 콘솔 드라이버가 있는 이미지가 필요합니다. 콘솔 없는 이미지를 시험하려면 [USAGE_KR.md](USAGE_KR.md#콘솔-없는-이미지-시험)의 "콘솔 없는 이미지 시험"에 설명된 `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty`, `K0_BOOT_CONSOLE_PAGE`를 사용하세요. +`tools/qemu-boot-test.sh`는 디버그 커널을 부팅하고 부팅 로그를 정해진 순서대로 한 줄씩 확인합니다. 에러 표식이 하나라도 나오면 실패하고, 루트 태스크가 `root: sched tests pass`를 출력하면 곧바로 QEMU를 종료합니다. 통과 줄 외에도 `k0: untyped ` 줄보다 앞의 `k0: kernel reserve `, `root: teardown tests pass` 뒤의 `k0: idle (waiting for a timeout)`와 `root: timeout tests pass`, `root: revocation tests pass` 뒤의 `root: kernel reserve tests pass`를 기대합니다. `k0: all tasks`로 시작하는 줄은 모두 실패입니다. `root: teardown tests pass`와 `root: timeout tests pass` 사이의 타이머 틱 줄도 세어 4개 이상을 요구하는데, EL0에는 시계가 없어서 이것이 타임아웃의 하한을 확인하는 방법이기 때문입니다. 타임아웃 테스트는 실제 틱을 기다리므로 부팅 한 번이 이전보다 약 4초 더 걸립니다. 시간 조각 테스트는 두 번(`YIELD`로 CPU를 받은 태스크, 기다림으로 받은 태스크) 실행해 합계 약 4초가 걸리며, 이를 대신한 이전 선점 테스트는 약 1초가 걸렸습니다. `root: preempt test pass`보다 앞에 `root: slice test yield pass`와 `root: slice test block pass`가 이 순서로 나오는 것도 기대합니다. 그 뒤에 `root: partition refusal pass`와 `root: partition window pass`가 나오고, `root: partition sealed`는 `root: sched tests pass`보다 앞에 나옵니다. 시간 분할 테스트는 9틱짜리 표를 한 바퀴 돌리므로 부팅마다 약 15초를 더합니다. 그 도중에 호스트가 QEMU를 1초 넘게 멈춰 세우면 테스트가 한 번 더 실행되고, 스크립트는 실패로 처리하지 않고 `boot-test: partition window retries: 1`을 보고합니다. `tools/boot-matrix.sh`는 그런 부팅 행을 다시 실행하고, 두 번째 실행에서도 재시도가 필요했으면 그 행을 실패로 처리합니다. 느린 환경에서는 `K0_BOOT_TIMEOUT`(초)을 늘려 주세요. 직렬 포트를 읽기 때문에 콘솔 드라이버가 있는 이미지가 필요합니다. 콘솔 없는 이미지를 시험하려면 [USAGE_KR.md](USAGE_KR.md#콘솔-없는-이미지-시험)의 "콘솔 없는 이미지 시험"에 설명된 `K0_BOOT_MEMLOG`, `K0_BOOT_SERIAL=empty`, `K0_BOOT_CONSOLE_PAGE`를 사용하세요. 서명 오라클이 있는 이미지(`vault` 또는 `vault-ed25519`)는 일부러 일으키는 폴트가 두 번 더 있어 `k0: task fault` 줄이 6개가 아니라 8개이므로 `K0_BOOT_FAULTS=8`이 필요하고, `root: oracle tests pass`를 `K0_BOOT_REQUIRE`로 요구하세요. 부팅 매트릭스에는 이를 위한 행 `vault`, `vault-max`, `vault-el2`, `vault-16k`, `vault-no-alg`, `hvf-vault`와 정적 검사 `vault-symbols`가 있으며, 행렬은 HVF가 있는 Mac에서 82행, CI에서 71행입니다. 행 `input-*`와 `term-*`는 콘솔 입력과 터미널을 다룹니다. 터미널 이미지는 `k0: task fault` 줄이 두 개 더 나오며(볼트 없이 8개, 볼트와 함께 10개), `tools/term-test.py <이미지>`가 정해진 직렬 세션을 실행합니다. 행의 내용은 [USAGE_KR.md](USAGE_KR.md)에 있습니다. @@ -132,6 +132,7 @@ $ tools/qemu-boot-test.sh target/aarch64-unknown-none-softfloat/debug/k0-kernel. | `k0-efi` UEFI 메모리 맵에서의 메모리 계획, DTB 재작성, 독립 검증, ACPI 테이블 읽기와 트리 합성 | 있음, 퍼징 포함 | 있음, 부팅 매트릭스의 `uefi-*` 행으로 | | `loader` (UEFI 애플리케이션: 펌웨어 호출, 캐시 비우기, MMU 끄기, 점프) | 없음 | 있음, `uefi-*` 행과 정적 검사 `tools/pe-check.py`로 | | `k0-mm` 페이지 테이블과 W^X 속성 | AArch64 호스트에서 있음 | 있음 | +| `k0-slice` 틱 규칙, `k0-part` 스케줄링 판정과 표 디코딩과 틱 산술 | 있음, Lean 모델의 기록된 결과와의 비교 포함 | 있음, 시간 조각 테스트와 시간 분할 테스트로, 사건의 순서만으로 | | `k0-arch`, `k0-task`, `k0-sched`, `k0-ipc` | 없음 | 있음 | `k0-arch`는 ELF 전용 어셈블러 지시어를 사용하고 스케줄러와 IPC 경로는 시스템 레지스터를 읽기 때문에 부팅으로만 검증됩니다. 이 부분을 바꿨다면 `userspace/root-task/src/main.rs`의 자가 테스트를 늘리고, 새 통과 줄을 `tools/qemu-boot-test.sh`의 기대 목록에 추가해 주세요. @@ -155,6 +156,15 @@ $ K0_FUZZ_ITERS=5000000 cargo test --release --offline --target "$host" -p k0-bo `K0_FUZZ_ITERS`, `K0_FUZZ_SEED`, `K0_FUZZ_CASE`는 세 퍼저 모두에 똑같이 적용됩니다. `K0_FUZZ_SEED`로 기준 시드를 바꿀 수 있습니다. 기준 시드가 다르면 케이스 열이 서로 무관합니다. 케이스가 실패하면 테스트가 `K0_FUZZ_CASE=0x...` 값을 출력합니다. 같은 명령에 이 변수를 지정하면 그 케이스만 재현하고 입력을 덤프합니다. +### 스케줄러 코어를 바꿀 때 + +`crates/k0-part`에는 모든 스케줄링 판정(`Core`)과 틱 시각의 산술(`clock`)이 있습니다. `proofs/lean`에는 그 모델에 대한 Lean 4 증명이 있고, `crates/k0-part/src/model_vectors.txt`에는 사건 스크립트 1600개와 각 스크립트에 대해 모델이 낸 결과가 있습니다. 호스트 테스트 `core_gives_the_lines_of_the_lean_model_on_every_recorded_script`는 이 스크립트들을 실제 `Core`에 넣어 실행하고, 둘이 다르면 실패합니다. CI는 이 테스트를 실행합니다. CI는 증명을 실행하지 않습니다. + +> [!IMPORTANT] +> `Core`가 하는 일을 바꾼다면 `proofs/lean/K0Part.lean`에도 같은 변경을 하고, `lake build`가 다시 통과하게 한 뒤, 모델에서 해시를 다시 만들어 주세요. 테스트를 통과시키려고 해시를 손으로 고치면 안 됩니다. 절차는 [proofs/lean/README.md](proofs/lean/README.md)(영문)의 "When the Rust code or the model changes on purpose"에 있습니다. + +증명은 모델에 대한 것이지 Rust 코드에 대한 것이 아닙니다. Lean 파일이 빌드된다는 이유로 변경이 증명됐다고 설명하지 마세요. `k0-sched`, `k0-ipc`, 커널 바이너리에는 호스트 테스트가 없습니다. 보호 구간, EL0로 돌아가기 전의 대기, 도메인이 바뀔 때의 TLB 비우기는 어떤 테스트도 보지 못합니다. 그래서 이 부분을 바꾸는 변경에는 꼼꼼한 리뷰와, 어떻게 확인했는지에 대한 설명이 필요합니다. + ### CI와 같은 방식으로 실행 CI는 `ci/Dockerfile`로 컨테이너 이미지를 빌드한 뒤 네트워크를 끊은 컨테이너 안에서 테스트를 돌립니다. 빌드와 테스트에 저장소 밖의 무엇도 필요하지 않다는 것을 이 방식으로 증명합니다. @@ -167,11 +177,13 @@ $ docker run --rm --network none k0-ci tools/host-test.sh $ docker run --rm --network none k0-ci tools/boot-matrix.sh ``` +CI 작업의 제한 시간은 45분입니다. 모든 부팅에 시간 분할 테스트가 들어가면서 한 번 실행에 약 30분이 걸릴 것으로 추정합니다. 이는 추정이며 CI에서 측정한 값이 아닙니다. + 빌드 컨텍스트는 작업 디렉터리이므로 **깨끗한 체크아웃에서 실행**해 주세요. 이미지는 다음과 같이 만들어집니다. - **베이스 이미지**: 멀티 아키텍처 인덱스의 다이제스트(`debian:bookworm@sha256:...`)로 고정되어 있습니다. - **Rust 툴체인**: 이미지에서는 rustup을 사용하지 않습니다. `ci/install-toolchain.py`가 Rust 1.89.0 채널 매니페스트의 SHA-256을 고정해 두고, 설치하는 모든 패키지(rustc, cargo, 호스트용과 `aarch64-unknown-none-softfloat`·`aarch64-unknown-uefi`용 rust-std, rust-src, llvm-tools)를 그 매니페스트의 해시와 대조합니다. 하나라도 다르면 이미지 빌드가 실패합니다. -- **빌드 컨텍스트**: `.dockerignore`는 허용 목록이므로, 목록에 없는 것은 이미지에 들어가지 않습니다. 빌드나 테스트에 필요한 **새 최상위 파일 또는 디렉터리**는 이 목록에 추가해야 합니다. `.git`은 이미지에 포함됩니다. +- **빌드 컨텍스트**: `.dockerignore`는 허용 목록이므로, 목록에 없는 것은 이미지에 들어가지 않습니다. 빌드나 테스트에 필요한 **새 최상위 파일 또는 디렉터리**는 이 목록에 추가해야 합니다. `.git`은 이미지에 포함됩니다. `proofs/`는 목록에 없으므로 Lean 파일은 이미지에 들어가지 않습니다. > [!NOTE] > 모든 것이 고정되어 있지는 않습니다. Debian 패키지의 버전은 고정되지 않았고(apt는 고정된 베이스 이미지 안의 아카이브 키로 검증합니다), GitHub 러너 이미지도 마찬가지입니다. 워크플로가 사용하는 GitHub Actions는 커밋 해시로 고정되어 있습니다. diff --git a/Cargo.lock b/Cargo.lock index d9ba5b8..7483765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,6 +121,7 @@ version = "0.1.0" dependencies = [ "k0-abi", "k0-conin", + "k0-part", ] [[package]] @@ -189,13 +190,20 @@ dependencies = [ "k0-cap", ] +[[package]] +name = "k0-part" +version = "0.1.0" +dependencies = [ + "k0-slice", +] + [[package]] name = "k0-sched" version = "0.1.0" dependencies = [ "k0-arch", "k0-mm", - "k0-slice", + "k0-part", "k0-task", ] diff --git a/Cargo.toml b/Cargo.toml index 78be90f..4b51950 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "crates/k0-efi", "crates/k0-conin", "crates/k0-slice", + "crates/k0-part", "userspace/root-task", "userspace/k0-vault", "userspace/k0-term", @@ -33,6 +34,7 @@ default-members = [ "crates/k0-efi", "crates/k0-conin", "crates/k0-slice", + "crates/k0-part", "userspace/root-task", ] diff --git a/INTRODUCTION.md b/INTRODUCTION.md index 3c8c726..fc554bc 100644 --- a/INTRODUCTION.md +++ b/INTRODUCTION.md @@ -10,7 +10,7 @@ This document explains in plain words what K0 is, what it can do today and what ## What K0 is -An operating system kernel is the program that controls the hardware and decides what every other program may do. Most kernels are large and do many jobs themselves. K0 is a **microkernel**: it does only the few jobs that must be done inside the kernel and leaves everything else to ordinary programs. The kernel side is about 11,800 lines of Rust and assembly (comments included, tests excluded). It is small enough to read from start to end. +An operating system kernel is the program that controls the hardware and decides what every other program may do. Most kernels are large and do many jobs themselves. K0 is a **microkernel**: it does only the few jobs that must be done inside the kernel and leaves everything else to ordinary programs. The kernel and the crates it links are about 15,400 lines of Rust and assembly (comments included, tests and build scripts excluded). It is small enough to read from start to end. The most important of those jobs is keeping programs apart. Think of a dormitory. Each room is a block of memory, each key opens one thing, and the kernel is the caretaker. A resident can open only the doors they hold a key for. A copy cannot be turned into a stronger key, and when a key is taken back, every copy made from it stops working too. In K0 these keys are called **capabilities**. The idea comes from the seL4 kernel. @@ -35,6 +35,7 @@ In the following table, you can find the words used in this document. | **Endpoint** | A mailbox through which tasks exchange messages (IPC) | | **System call** | A request that a program makes to the kernel | | **Interrupt** | A signal from the hardware, such as a timer, that makes the processor stop and run the kernel | +| **Domain** | A group of tasks that gets its own fixed windows of processor time when a time partition table is set | | **Terminal** | A screen on the serial line where a person types commands and reads the answers. In K0 one ordinary task provides it | ## Goals @@ -47,7 +48,7 @@ K0 is meant to become the isolation core of high-security systems. The targets a - **Research base**: formal verification and certification research > [!NOTE] -> Only a first small step exists: the optional signing oracle and the operator terminal that drives it over the serial line, both described under "What works today". The rest does not work yet. Today K0 is a research platform: it boots and checks its own security properties, but by default it does no useful work of its own yet. +> Only first small steps exist: the optional signing oracle, the operator terminal that drives it over the serial line, and fixed time partitions that no image uses yet. They are described under "What works today". The rest does not work yet. Today K0 is a research platform: it boots and checks its own security properties, but by default it does no useful work of its own yet. ## What works today @@ -132,6 +133,10 @@ These features only add and are not in `default`, so **every build command must Memory is placed on an address space's map only by showing that address space's key (MAP, UNMAP). Keys carry rights (read, write, execute). A mailbox key can carry a tag that tells the receiver who sent a message (badge). Keys can be copied with the same or fewer rights, or moved between slots (CAP_COPY, CAP_MOVE). - **Running tasks**: a task is tied to one key ring and one address space when it is set up (TCB_CONFIGURE) and then started (TCB_RESUME). Tasks take turns, and a timer interrupts a task that runs too long (round-robin scheduling with timer preemption). A task that was switched in between two timer ticks gets a full period: the first tick it meets does not cut it, so it runs at least one period and at most two before the timer takes the CPU away. This stops a task from using `YIELD` shortly before a tick to shorten the turn of the next task. A task can give up its turn (YIELD) or finish (EXIT). +- **Time partitions**: every task belongs to one of 8 groups called domains. A timetable of up to 16 entries (the time partition table) says which domain may use the processor in which seconds, and it repeats. A domain runs only in its own windows of that table. When a domain has nothing to run in its window, the processor waits, and the time is not given to another domain. Before a tick at which the domain changes, the kernel takes the timer interrupt 25 ms early, does the switch and then waits for the instant of the tick. The next domain starts at that instant, to within the wait loop and the way out of the kernel, as long as the kernel work that was under way and the switch fit in the 25 ms. + - **Who sets it**: one key that the root task gets at boot (the control capability `PartCtl`) allows setting the table (PART_SET_TABLE) and putting a task that has not run yet into a domain (PART_SET_DOMAIN). The key cannot be copied, and deleting it fixes the table and the domains until the next boot. + - **Without a table**: there is one domain, and tasks take turns as described above. + - **Not used by any image yet**: the root task tries the mechanism in a self-test at every boot and then deletes the key. Every image built today therefore runs with one domain. What the partitions do and do not protect against is in [SECURITY.md](SECURITY.md) and [design/en/scheduling.md](design/en/scheduling.md#time-partitions). - **Messages**: tasks exchange short messages that travel in processor registers. The sender waits until the receiver takes the message (synchronous IPC: SEND, RECV, CALL, REPLY_RECV). Sending needs the write right on the mailbox key and receiving needs the read right. The receiver learns the tag of the sender's key, and the right to reply can be used only once. - **Timeouts**: every one of these calls can carry a time limit, counted in timer ticks (one tick is one second). If no partner arrives in time, the call returns an error (`TIMEOUT`, or `REPLY_TIMEOUT` when a `CALL` was delivered but no reply came). Without a limit a task waits as long as it takes. The wait lasts at least the given number of ticks and may be a little longer. The limit says when the task becomes ready again, not when it runs. - **Idle**: when no task can run, the kernel no longer stops. It waits for the next interrupt, wakes tasks whose time limit has passed and carries on. If nothing can ever wake a task, the machine stays idle and the boot log says `k0: all tasks stopped (none ready, no timeout pending)`. That line appears only when there is neither a timed waiter nor a task waiting for console input. A terminal image prints nothing there, because waiting for input is its normal state. @@ -271,8 +276,8 @@ What it does not stop: Still open: - A task that waits without a timeout can wait forever if its partner never acts. Timeouts are used per call, so a server that must stay responsive has to give one on every wait. - - There is no priority and no CPU budget. Tasks take turns, and a task that holds a lot of free memory can create many tasks and shrink everyone else's share. A task that never yields or blocks keeps at least 1/N of the CPU among N ready tasks in the long run. This was checked in a model by search with up to 6 tasks and by tests on the host, it is not proven, and N grows with every task that is created. - - The scheduler leaks timing. A task still changes when, and for how long, another task runs by choosing when to yield or block. This has not been analysed. K0 gives no real-time or latency promise: the tick is one second and the kernel cannot be interrupted. The one-to-two periods per turn describe this version, not an interface. + - There is no priority and no CPU budget. Tasks take turns, and a task that holds a lot of free memory can create many tasks and shrink everyone else's share. A task that never yields or blocks keeps at least 1/N of the CPU among N ready tasks in the long run. This was checked in a model by search with up to 6 tasks and by tests on the host. A machine-checked proof exists for a model of one domain, not for the code and not for several domains. N grows with every task that is created. + - The scheduler leaks timing between tasks of one domain. A task still changes when, and for how long, another task of its domain runs by choosing when to yield or block. This has not been analysed. Time partitions are the mechanism against this between domains, but no image puts tasks into more than one domain yet, and the mechanism has limits of its own (see [SECURITY.md](SECURITY.md)). K0 gives no real-time or latency promise: the tick is one second and the kernel cannot be interrupted. The one-to-two periods per turn describe this version, not an interface. - The kernel cannot be interrupted while it handles a system call. A long call, such as taking back a key to a large block of memory, delays every other task and every timeout. - A fatal error inside the kernel, or an error from the hardware that the kernel cannot attribute to one task, still stops the whole machine. - The lines the kernel prints when a task ends (a crash, an exit, an unknown system call) share 4 KiB of the boot log and can no longer fill the kernel part. A task that can create tasks can still push such lines of other tasks out of the log. @@ -298,6 +303,7 @@ Missing features: - **Multicore**: only one processor core is used. - **Device access**: programs cannot access hardware devices (device memory and interrupts). - **Loading new executable code after boot**: this is the flip side of the write-or-run rule. Executable memory exists only for the root task image, so a confined task runs code from that image. +- **A use for the time partitions**: the mechanism exists and is tested at every boot, but no image puts its tasks into more than one domain yet. Putting the signing oracle's vault into a domain of its own is future work. - **Multi-level key lookup and ASIDs**: multi-level key lookup and hardware address space tags (ASIDs) do not exist. Today every switch to another address space empties the processor's cache of memory map lookups (the TLB). - **More for the signing oracle**: the oracle has the following limits today. - No persistence: the key lives only in memory and is gone after a reboot or ZEROIZE. @@ -326,13 +332,13 @@ Missing protection and assurance: - **Availability guarantees**: see the previous section. Several ways to block other tasks remain. - **DMA isolation**: some devices read and write memory directly, without the processor (DMA). Once devices are handed to programs, a memory map for devices (an IOMMU, such as the SMMU on ARM) has to stop such a device from reading all memory. Nothing for this exists yet. -- **Side channels**: secrets can leak through timing or through caches the processor shares, rather than by direct access. A few such leaks are closed (programs cannot read the hardware counters, and the TLB is emptied whenever the address space changes). Timeouts give programs a clock, but it is as coarse as one timer tick. Whether that can help an attack has not been analysed. There is no general defence against cache or timing side channels, and they have not been analysed. +- **Side channels**: secrets can leak through timing or through caches the processor shares, rather than by direct access. A few such leaks are closed (programs cannot read the hardware counters, and the TLB is emptied whenever the address space or the domain changes). Timeouts give programs a clock, but it is as coarse as one timer tick. Whether that can help an attack has not been analysed. Time partitions deal with one channel only, the one between domains that goes through the scheduler, and caches and branch predictors are not emptied when the domain changes. There is no general defence against cache or timing side channels, and they have not been analysed. - **Waiting senders**: taking a key back does not cancel a sender already waiting at the mailbox. Its message is still delivered once. - **Basis of assurance**: assurance comes from testing only. - Unit tests and fuzzing (feeding random, broken input to find crashes) on the build machine - Self-tests at boot in QEMU and in a hypervisor guest on real Apple cores - There is no formal proof (a mathematical proof that the code does what it should), and nothing has run on a real board. + There is no formal proof of the code (a mathematical proof that the code does what it should), and nothing has run on a real board. The repository does hold machine-checked proofs (Lean 4, in `proofs/lean`) about a **model** of the time partition scheduler. They are proofs about that model, not about the Rust code, and they are not run in CI. What ties the code to the model is a test: 1600 recorded event scripts are run through the Rust code on the build machine, and the result is compared with what the model gave. ## Where the code lives @@ -345,17 +351,19 @@ In the following table, you can find the contents of each path in the repository | `crates/k0-arch` | Handling of errors, system calls and interrupts (exceptions), entering and leaving user mode, interrupt controller and timer, PAC and PAN, the boot log and the optional console drivers | | `crates/k0-conin` | The receive logic of console input (the ring and the loss mark), tested on the host with a fake UART | | `crates/k0-slice` | The rule that decides whether a timer tick cuts the running task, tested on the host with a model of the scheduler | +| `crates/k0-part` | Every scheduling decision: which domain runs at which tick under the time partition table, and which task of it runs. Also the arithmetic of tick instants. It touches no hardware and is tested on the host | | `crates/k0-boot` | Device tree parser, the built-in root task image and its integrity check, PAC key derivation, the search for the boot memory window (shared with the loader) | | `crates/k0-efi` | The loader's logic without `unsafe` code: planning RAM from the UEFI memory map, rewriting the firmware device tree, an independent re-check of the result, and the check of the kernel image header. It runs the kernel's own device tree code on the result before the jump | | `crates/k0-cap` | Keys and their rights, key rings, the derivation list, untyped memory, retype, revoke and delete | | `crates/k0-mm` | Kernel page tables, turning memory maps on (MMU), program address spaces and their registry | | `crates/k0-task` | Tasks with their key ring and address space, mailboxes, loading the root task | -| `crates/k0-sched` | Round-robin scheduler, which asks `k0-slice` at every tick | +| `crates/k0-sched` | The kernel side of the scheduler: one ready queue and one list of timed waiters per domain, and the installed task. The decisions are made by `k0-part` | | `crates/k0-ipc` | Synchronous messages | | `loader/` | The UEFI application (`k0-loader`, target `aarch64-unknown-uefi`) that embeds a built kernel image and starts it: UEFI calls, the flow, and the final cache flush, MMU off and jump | | `userspace/root-task` | The first program and its self-tests, and the wiring and self-test of the signing oracle (`oracle.rs`), and the start of the terminal service (`service.rs`) | | `userspace/k0-term` | The operator terminal: line editing, command parsing and the requests to the vault | | `userspace/k0-vault` | The signing oracle service: protocol and fixed policy, the request handling, and the boundary around the crypto crate | | `tools/` | QEMU runner (also for `.efi` files), boot test, boot matrix, terminal session test (`term-test.py`), boot log reader, host test, loader build (`build-loader.sh`), PE and instruction order check (`pe-check.py`), device tree editor for hostile boot input (`fdt-patch.py`) | +| `proofs/lean` | Lean 4 proofs about a model of the time partition scheduler, and the program that computes the model's results for the recorded event scripts. Not run in CI | | `ci/` | The CI build and test image (`Dockerfile`) and the threat model (`threat_model.md`) | | `vendor/` | Third-party crates kept in the repository (`sha2`, `ed25519-dalek` and their dependencies) | diff --git a/INTRODUCTION_KR.md b/INTRODUCTION_KR.md index 244c352..285bf37 100644 --- a/INTRODUCTION_KR.md +++ b/INTRODUCTION_KR.md @@ -10,7 +10,7 @@ ## K0는 무엇인가 -운영체제 커널은 하드웨어를 다루고, 다른 모든 프로그램이 무엇을 할 수 있는지 정하는 프로그램입니다. 대부분의 커널은 크고 많은 일을 직접 합니다. K0는 **마이크로커널**이라서 커널 안에서만 할 수 있는 몇 가지 일만 하고, 나머지는 일반 프로그램에 맡깁니다. 커널 쪽 코드는 주석을 포함하고 테스트를 제외하면 Rust와 어셈블리 약 11,800줄입니다. 처음부터 끝까지 읽을 수 있는 크기입니다. +운영체제 커널은 하드웨어를 다루고, 다른 모든 프로그램이 무엇을 할 수 있는지 정하는 프로그램입니다. 대부분의 커널은 크고 많은 일을 직접 합니다. K0는 **마이크로커널**이라서 커널 안에서만 할 수 있는 몇 가지 일만 하고, 나머지는 일반 프로그램에 맡깁니다. 커널과 커널에 링크되는 크레이트의 코드는 주석을 포함하고 테스트와 빌드 스크립트를 제외하면 Rust와 어셈블리 약 15,400줄입니다. 처음부터 끝까지 읽을 수 있는 크기입니다. 그 일 가운데 가장 중요한 것은 프로그램끼리 떼어 놓는 것입니다. 기숙사를 떠올려 보세요. 방 하나는 메모리 한 덩어리, 열쇠 하나는 무언가 하나를 여는 도구, 커널은 관리인입니다. 입주자는 열쇠를 가진 문만 열 수 있습니다. 복사한 열쇠를 더 강한 열쇠로 바꿀 수 없고, 열쇠를 회수당하면 거기서 복사한 열쇠도 전부 쓸 수 없게 됩니다. K0에서는 이 열쇠를 **케이퍼빌리티**라고 부릅니다. 이 생각은 seL4 커널에서 왔습니다. @@ -35,6 +35,7 @@ | **엔드포인트** | 태스크끼리 메시지를 주고받는 우편함(IPC)입니다 | | **시스템 콜** | 프로그램이 커널에 하는 요청입니다 | | **인터럽트** | 타이머 같은 하드웨어가 보내는 신호입니다. 프로세서가 하던 일을 멈추고 커널을 실행하게 합니다 | +| **도메인** | 태스크의 묶음입니다. 시간 분할 표를 정하면 도메인마다 프로세서 시간에서 자기만의 고정된 창을 받습니다 | | **터미널** | 시리얼 줄로 사람이 명령을 입력하고 답을 읽는 화면입니다. K0에서는 일반 태스크 하나가 맡습니다 | ## 목표 @@ -47,7 +48,7 @@ K0는 고보안 시스템의 격리 코어가 되는 것을 목표로 합니다. - **연구용 기반**: 정형 검증과 인증 연구 > [!NOTE] -> 첫 작은 걸음만 있습니다. "지금 동작하는 것"에 적은 선택 사항인 서명 오라클과, 그것을 시리얼 줄로 다루는 운영자 터미널입니다. 나머지는 아직 동작하지 않습니다. 지금의 K0는 연구용 플랫폼으로, 부팅해서 자신의 보안 성질을 스스로 확인하지만 기본값으로는 아직 그 자체로 쓸모 있는 일을 하지는 않습니다. +> 첫 작은 걸음들만 있습니다. 선택 사항인 서명 오라클, 그것을 시리얼 줄로 다루는 운영자 터미널, 그리고 아직 어떤 이미지도 사용하지 않는 고정 시간 분할입니다. 이들은 "지금 동작하는 것"에 적었습니다. 나머지는 아직 동작하지 않습니다. 지금의 K0는 연구용 플랫폼으로, 부팅해서 자신의 보안 성질을 스스로 확인하지만 기본값으로는 아직 그 자체로 쓸모 있는 일을 하지는 않습니다. ## 지금 동작하는 것 @@ -132,6 +133,10 @@ K0는 고보안 시스템의 격리 코어가 되는 것을 목표로 합니다. 메모리는 그 주소 공간의 열쇠를 보여 줘야만 그 주소 공간의 지도에 올릴 수 있습니다(MAP, UNMAP). 열쇠에는 권한(읽기, 쓰기, 실행)이 있습니다. 우편함 열쇠에는 누가 보냈는지 받는 쪽에 알려 주는 표식(배지)을 붙일 수 있습니다. 열쇠는 권한을 그대로 두거나 줄여서 복사하거나, 다른 슬롯으로 옮길 수 있습니다(CAP_COPY, CAP_MOVE). - **태스크 실행**: 태스크는 준비할 때 열쇠고리 하나와 주소 공간 하나에 묶이고(TCB_CONFIGURE) 그다음 시작됩니다(TCB_RESUME). 태스크는 차례를 돌아가며 실행되고, 너무 오래 도는 태스크는 타이머가 끊습니다(타이머 선점이 있는 라운드 로빈 스케줄링). 두 타이머 틱 사이에 실행을 넘겨받은 태스크는 한 주기를 온전히 받습니다. 처음 만나는 틱은 그 태스크를 끊지 않으므로, 타이머가 CPU를 빼앗기 전에 최소 한 주기, 많아야 두 주기을 실행합니다. 이렇게 해서 태스크가 틱 직전에 `YIELD`를 호출해 다음 태스크의 차례를 줄이는 일을 막습니다. 태스크는 자기 차례를 양보하거나(YIELD) 끝낼 수 있습니다(EXIT). +- **시간 분할**: 모든 태스크는 도메인이라고 부르는 8개 묶음 가운데 하나에 속합니다. 항목이 최대 16개인 시간표(시간 분할 표)가 어느 도메인이 어느 초에 프로세서를 사용할 수 있는지 정하고, 이 표는 되풀이됩니다. 도메인은 그 표에 있는 자기 창에서만 실행됩니다. 도메인이 자기 창에서 실행할 것이 없으면 프로세서는 기다리며, 그 시간은 다른 도메인에 넘어가지 않습니다. 도메인이 바뀌는 틱 앞에서는 커널이 타이머 인터럽트를 25 ms 일찍 받아 전환을 하고, 그런 다음 그 틱의 시각이 될 때까지 기다립니다. 그때 하고 있던 커널 작업과 전환이 그 25 ms 안에 들어가는 한, 다음 도메인은 기다리는 루프와 커널에서 나가는 길만큼의 오차 안에서 그 시각에 시작합니다. + - **누가 정하나**: 루트 태스크가 부팅 때 받는 열쇠 하나(제어 케이퍼빌리티 `PartCtl`)가 있어야 표를 정하고(PART_SET_TABLE), 아직 실행된 적 없는 태스크를 도메인에 넣을 수 있습니다(PART_SET_DOMAIN). 이 열쇠는 복사할 수 없고, 지우면 표와 도메인이 다음 부팅까지 고정됩니다. + - **표가 없을 때**: 도메인은 하나이고, 태스크는 위에 적은 대로 차례를 돌아가며 실행됩니다. + - **아직 어떤 이미지도 사용하지 않습니다**: 루트 태스크가 부팅할 때마다 자가 테스트에서 이 메커니즘을 시험해 본 뒤 열쇠를 지웁니다. 그래서 지금 빌드하는 모든 이미지는 도메인 하나로 실행됩니다. 시간 분할이 무엇을 막고 무엇을 막지 못하는지는 [SECURITY_KR.md](SECURITY_KR.md)와 [design/kr/scheduling_KR.md](design/kr/scheduling_KR.md#시간-분할)에 있습니다. - **메시지**: 태스크는 프로세서 레지스터에 담긴 짧은 메시지를 주고받습니다. 보내는 쪽은 받는 쪽이 메시지를 가져갈 때까지 기다립니다(동기 IPC: SEND, RECV, CALL, REPLY_RECV). 보내려면 우편함 열쇠에 쓰기 권한이, 받으려면 읽기 권한이 있어야 합니다. 받는 쪽은 보낸 쪽 열쇠의 표식을 알게 되고, 답장할 권리는 한 번만 사용할 수 있습니다. - **타임아웃**: 이 호출들은 모두 제한 시간을 줄 수 있습니다. 단위는 타이머 틱입니다(1틱은 1초). 제한 시간 안에 상대가 오지 않으면 호출이 오류(`TIMEOUT`, 또는 `CALL`이 전달됐지만 답이 오지 않은 경우 `REPLY_TIMEOUT`)로 돌아옵니다. 제한 시간을 주지 않으면 태스크는 필요한 만큼 계속 기다립니다. 기다리는 시간은 준 틱 수 이상이며 조금 더 길 수 있습니다. 제한 시간은 태스크가 다시 준비 상태가 되는 때를 정할 뿐, 실행되는 때를 정하지는 않습니다. - **대기 상태**: 실행할 수 있는 태스크가 없어도 커널은 더 이상 멈추지 않습니다. 다음 인터럽트를 기다리다가, 제한 시간이 지난 태스크를 깨우고 계속 진행합니다. 태스크를 깨울 수 있는 것이 아무것도 없으면 기계는 대기 상태로 남고, 부트 로그에 `k0: all tasks stopped (none ready, no timeout pending)`이 찍힙니다. 시간 제한이 걸린 대기도, 콘솔 입력을 기다리는 태스크도 없을 때만 이 줄이 찍힙니다. 터미널 이미지는 입력을 기다리는 것이 정상이라 아무것도 출력하지 않습니다. @@ -272,8 +277,8 @@ K0는 고보안 시스템의 격리 코어가 되는 것을 목표로 합니다. 아직 열려 있는 부분은 다음과 같습니다. - 타임아웃 없이 기다리는 태스크는 상대가 끝내 행동하지 않으면 영원히 기다릴 수 있습니다. 타임아웃은 호출마다 주는 것이라서, 계속 응답해야 하는 서버는 모든 대기에 타임아웃을 줘야 합니다. - - 우선순위와 CPU 예산이 없습니다. 태스크는 돌아가며 실행되고, 빈 메모리를 많이 가진 태스크는 태스크를 많이 만들어 다른 태스크의 몫을 줄일 수 있습니다. 양보하거나 기다리지 않는 태스크는 준비된 태스크가 N개일 때 오래 보면 CPU의 1/N 이상을 가집니다. 이는 최대 6개 태스크까지 모델에서 탐색으로 확인하고 호스트 테스트로 검사한 것이며, 증명한 것이 아니고, 태스크를 만들 때마다 N이 커집니다. - - 스케줄러를 통한 타이밍 채널이 열려 있습니다. 태스크는 양보하거나 기다릴 시점을 골라 다른 태스크가 언제, 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. 이는 분석하지 않았습니다. K0는 실시간 또는 지연 시간에 대한 약속을 하지 않습니다. 틱은 1초이고 커널은 중단할 수 없습니다. 한 번에 한 주기에서 두 주기라는 값은 이 버전의 동작이며 인터페이스가 아닙니다. + - 우선순위와 CPU 예산이 없습니다. 태스크는 돌아가며 실행되고, 빈 메모리를 많이 가진 태스크는 태스크를 많이 만들어 다른 태스크의 몫을 줄일 수 있습니다. 양보하거나 기다리지 않는 태스크는 준비된 태스크가 N개일 때 오래 보면 CPU의 1/N 이상을 가집니다. 이는 최대 6개 태스크까지 모델에서 탐색으로 확인하고 호스트 테스트로 검사한 것입니다. 기계가 검사한 증명은 도메인 하나의 모델에 대해서만 있고, 코드에 대해서도 도메인이 여럿인 경우에 대해서도 없습니다. 태스크를 만들 때마다 N이 커집니다. + - 스케줄러를 통한 타이밍 채널이 한 도메인의 태스크 사이에서 열려 있습니다. 태스크는 양보하거나 기다릴 시점을 골라 자기 도메인의 다른 태스크가 언제, 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. 이는 분석하지 않았습니다. 도메인 사이에서는 시간 분할이 이를 막는 메커니즘입니다. 하지만 태스크를 둘 이상의 도메인에 넣는 이미지는 아직 없고, 이 메커니즘에는 그 자체의 한계가 있습니다([SECURITY_KR.md](SECURITY_KR.md) 참고). K0는 실시간 또는 지연 시간에 대한 약속을 하지 않습니다. 틱은 1초이고 커널은 중단할 수 없습니다. 한 번에 한 주기에서 두 주기라는 값은 이 버전의 동작이며 인터페이스가 아닙니다. - 커널은 시스템 콜을 처리하는 동안 중단할 수 없습니다. 큰 메모리 블록의 열쇠를 회수하는 것 같은 긴 호출은 다른 모든 태스크와 모든 타임아웃을 늦춥니다. - 커널 안의 치명적 오류, 또는 커널이 한 태스크의 탓으로 돌릴 수 없는 하드웨어 오류는 여전히 기계 전체를 멈춥니다. - 태스크가 끝날 때 커널이 내는 줄(충돌, 종료, 알 수 없는 시스템 콜)은 부트 로그의 4 KiB를 나눠 쓰며, 더는 커널 부분을 채우지 못합니다. 태스크를 만들 수 있는 태스크는 여전히 다른 태스크의 그런 줄을 로그에서 밀어낼 수 있습니다. @@ -299,6 +304,7 @@ K0는 고보안 시스템의 격리 코어가 되는 것을 목표로 합니다. - **멀티코어**: 여러 프로세서 코어입니다. 지금은 코어 하나만 사용합니다. - **장치 접근**: 프로그램이 하드웨어 장치를 쓰게 해 주는 기능입니다(장치 메모리와 인터럽트). - **부팅 뒤 새 실행 코드 적재**: 쓰기와 실행을 함께 허용하지 않는 규칙의 대가입니다. 실행 가능한 메모리는 루트 태스크 이미지에만 있어서 격리된 태스크도 그 이미지의 코드를 실행합니다. +- **시간 분할의 쓰임새**: 메커니즘은 있고 부팅할 때마다 테스트하지만, 태스크를 둘 이상의 도메인에 넣는 이미지는 아직 없습니다. 서명 오라클의 볼트를 자기만의 도메인에 두는 것은 앞으로 할 일입니다. - **여러 단계의 열쇠 조회와 ASID**: 여러 단계의 열쇠 조회, 하드웨어 주소 공간 표식(ASID)입니다. 지금은 다른 주소 공간으로 바꿀 때마다 프로세서가 메모리 지도 조회 결과를 담아 두는 캐시(TLB)를 전부 비웁니다. - **서명 오라클의 남은 한계**: 오라클에는 지금 다음 한계가 있습니다. - 영속성이 없습니다. 키는 메모리에만 있고 재부팅이나 ZEROIZE 뒤에는 사라집니다. @@ -327,13 +333,13 @@ K0는 고보안 시스템의 격리 코어가 되는 것을 목표로 합니다. - **가용성 보장**: 앞 절을 참고하세요. 다른 태스크를 막는 길이 여럿 남아 있습니다. - **DMA 격리**: 어떤 장치는 프로세서를 거치지 않고 메모리를 직접 읽고 씁니다(DMA). 장치를 프로그램에 넘기게 되면, 장치용 메모리 지도(IOMMU, 예를 들어 ARM의 SMMU)로 그런 장치가 메모리 전체를 읽지 못하게 막아야 합니다. 이를 위한 것은 아직 없습니다. -- **사이드 채널**: 직접 읽지 않고 실행 시간이나 프로세서가 함께 사용하는 캐시를 통해 비밀이 새는 길입니다. 몇 가지는 막혀 있지만(프로그램은 하드웨어 카운터를 읽을 수 없고, 주소 공간이 바뀔 때마다 TLB를 비움), 타임아웃은 프로그램에 타이머 틱 한 번 정도로 거친 시계를 줍니다. 이것이 공격에 도움이 될 수 있는지는 분석하지 않았습니다. 캐시나 실행 시간을 이용한 사이드 채널 전반에 대한 대책은 없고 분석도 하지 않았습니다. +- **사이드 채널**: 직접 읽지 않고 실행 시간이나 프로세서가 함께 사용하는 캐시를 통해 비밀이 새는 길입니다. 몇 가지는 막혀 있지만(프로그램은 하드웨어 카운터를 읽을 수 없고, 주소 공간이나 도메인이 바뀔 때마다 TLB를 비움), 타임아웃은 프로그램에 타이머 틱 한 번 정도로 거친 시계를 줍니다. 이것이 공격에 도움이 될 수 있는지는 분석하지 않았습니다. 시간 분할은 채널 하나만 다룹니다. 도메인 사이에서 스케줄러를 거치는 채널입니다. 도메인이 바뀔 때 캐시와 분기 예측기는 비우지 않습니다. 캐시나 실행 시간을 이용한 사이드 채널 전반에 대한 대책은 없고 분석도 하지 않았습니다. - **대기 중인 송신자**: 열쇠를 회수해도 이미 우편함 앞에서 기다리던 송신자는 취소되지 않습니다. 그 메시지는 한 번 전달됩니다. - **보증의 근거**: 보증은 테스트에서만 나옵니다. - 빌드한 컴퓨터에서의 단위 테스트와 퍼징(무작위로 망가뜨린 입력을 넣어 충돌을 찾는 방법) - QEMU와, 실제 Apple 코어 위의 하이퍼바이저 게스트에서 부팅할 때의 자가 테스트 - 코드가 해야 할 일을 한다는 수학적 증명(정형 증명)은 없고, 실제 보드에서 돌려 본 적도 없습니다. + 코드가 해야 할 일을 한다는 수학적 증명(코드에 대한 정형 증명)은 없고, 실제 보드에서 돌려 본 적도 없습니다. 저장소에는 시간 분할 스케줄러의 **모델**에 대한 기계 검사 증명(Lean 4, `proofs/lean`)이 들어 있습니다. 이것은 그 모델에 대한 증명이지 Rust 코드에 대한 증명이 아니며, CI에서 실행하지 않습니다. 코드를 모델에 묶어 주는 것은 테스트입니다. 기록해 둔 사건 스크립트 1600개를 빌드한 컴퓨터에서 Rust 코드에 넣어 실행하고, 그 결과를 모델이 낸 결과와 비교합니다. ## 코드가 있는 곳 @@ -346,17 +352,19 @@ K0는 고보안 시스템의 격리 코어가 되는 것을 목표로 합니다. | `crates/k0-arch` | 에러, 시스템 콜, 인터럽트 처리(예외), 사용자 모드 진입과 복귀, 인터럽트 컨트롤러와 타이머, PAC과 PAN, 부트 로그와 선택적 콘솔 드라이버 | | `crates/k0-conin` | 콘솔 입력의 수신 논리(링과 유실 표시). 가짜 UART로 호스트에서 테스트합니다 | | `crates/k0-slice` | 타이머 틱이 실행 중인 태스크를 끊을지 정하는 규칙. 스케줄러 모델로 호스트에서 테스트합니다 | +| `crates/k0-part` | 모든 스케줄링 판정. 시간 분할 표에 따라 어느 틱에 어느 도메인이 실행되는지, 그 도메인의 어느 태스크가 실행되는지를 정합니다. 틱 시각의 산술도 여기에 있습니다. 하드웨어를 건드리지 않으며 호스트에서 테스트합니다 | | `crates/k0-boot` | 디바이스 트리 파서, 내장된 루트 태스크 이미지와 무결성 검사, PAC 키 파생, 부트 메모리 창 탐색(로더와 공유) | | `crates/k0-efi` | `unsafe` 없는 로더의 논리. UEFI 메모리 맵에서 RAM 계획, 펌웨어 디바이스 트리 고쳐 쓰기, 결과의 독립적인 재검사, 커널 이미지 헤더 검사. 점프 전에 결과에 커널 자신의 디바이스 트리 코드를 돌려 봅니다 | | `crates/k0-cap` | 열쇠와 권한, 열쇠고리, 파생 목록, untyped 메모리, retype, revoke와 delete | | `crates/k0-mm` | 커널 페이지 테이블, 메모리 지도 켜기(MMU), 프로그램 주소 공간과 그 등록부 | | `crates/k0-task` | 열쇠고리와 주소 공간에 묶인 태스크, 우편함, 루트 태스크 적재 | -| `crates/k0-sched` | 라운드 로빈 스케줄러. 틱마다 `k0-slice`에 묻습니다 | +| `crates/k0-sched` | 스케줄러의 커널 쪽. 도메인마다 준비 큐 하나와 기한이 있는 대기자 목록 하나를 두고, 설치된 태스크를 유지합니다. 판정은 `k0-part`가 내립니다 | | `crates/k0-ipc` | 동기 메시지 | | `loader/` | 빌드된 커널 이미지를 품고 시작시키는 UEFI 응용 프로그램(`k0-loader`, 타겟 `aarch64-unknown-uefi`). UEFI 호출, 흐름, 마지막의 캐시 비우기·MMU 끄기·점프 | | `userspace/root-task` | 첫 프로그램과 자가 테스트, 서명 오라클의 연결과 자가 테스트(`oracle.rs`), 터미널 서비스의 시작(`service.rs`) | | `userspace/k0-term` | 운영자 터미널. 줄 편집, 명령 해석, 볼트로 보내는 요청 | | `userspace/k0-vault` | 서명 오라클 서비스. 프로토콜과 고정 정책, 요청 처리, 암호 크레이트를 감싸는 경계 | | `tools/` | QEMU 러너(`.efi`도 지원), 부팅 테스트, 부팅 매트릭스, 터미널 대화 테스트(`term-test.py`), 부트 로그 읽기, 호스트 테스트, 로더 빌드(`build-loader.sh`), PE와 명령 순서 검사(`pe-check.py`), 적대적인 부팅 입력을 만드는 디바이스 트리 편집(`fdt-patch.py`) | +| `proofs/lean` | 시간 분할 스케줄러의 모델에 대한 Lean 4 증명, 그리고 기록해 둔 사건 스크립트에 대해 모델의 결과를 계산하는 프로그램. CI에서 실행하지 않습니다 | | `ci/` | CI 빌드·테스트 이미지(`Dockerfile`)와 위협 모델(`threat_model.md`) | | `vendor/` | 저장소 안에 함께 넣어 둔 서드파티 크레이트(`sha2`, `ed25519-dalek`과 그 의존성) | diff --git a/README.md b/README.md index 48112e4..4a531bb 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ K0 is a small operating system kernel for 64-bit ARM (AArch64) computers. It is - **Wiped before reuse**: memory is filled with zeros every time it is handed out again. - **Write or run, never both**: no memory is writable and executable at the same time. The flip side is that no new code can become executable after boot, so programs cannot load new code. - **Distrust of boot input**: the hardware description handed over at boot is checked as if an attacker wrote it. +- **Fixed time partitions**: programs can be put into groups (domains) that run only in their own windows of a repeating timetable, and time that a group does not use is not given to another group. The mechanism is always in the kernel and is tested at every boot, but no image uses more than one domain yet. Machine-checked proofs (Lean 4) come with it. They are about a model of the scheduler, not about the code. See [INTRODUCTION.md](INTRODUCTION.md). - **Optional signing oracle**: a build option adds a task that signs messages for other tasks and never gives out its key. It is off by default, the Ed25519 implementation is unvalidated, and it keeps one key in memory only. See [INTRODUCTION.md](INTRODUCTION.md). - **Optional operator terminal**: a build option adds a screen on the serial line where a person types commands. It can make the signing oracle's key, read the public key and erase the key, but it cannot sign. It is off by default. @@ -70,6 +71,7 @@ In the following table, you can find the documents in this repository. The desig | [USAGE.md](USAGE.md) | Setting up, building, running and testing | | [SECURITY.md](SECURITY.md) | Isolation model, known advisories, reporting a vulnerability | | [Design notes](design/en/README.md) | How each part of the kernel works and why it was built that way | +| [Lean proofs](proofs/lean/README.md) | What is proved about a model of the time partition scheduler, what is not, and how to check it | | [CONTRIBUTING.md](CONTRIBUTING.md) | How to contribute | ## Contributing diff --git a/README_KR.md b/README_KR.md index ac1bd08..89067e3 100644 --- a/README_KR.md +++ b/README_KR.md @@ -33,6 +33,7 @@ K0는 64비트 ARM(AArch64) 컴퓨터용 작은 운영체제 커널입니다. Ru - **재사용 전 소거**: 메모리를 다시 내줄 때마다 0으로 채웁니다. - **쓰기와 실행은 동시에 불가**: 어떤 메모리도 쓰기와 실행이 동시에 되지 않습니다. 그 대가로 부팅 뒤에는 새 코드를 실행 가능하게 만들 수 없어서, 프로그램이 새 코드를 불러올 수 없습니다. - **부팅 입력 불신**: 부팅 때 넘겨받는 하드웨어 설명은 공격자가 작성한 것처럼 검사합니다. +- **고정 시간 분할**: 프로그램을 묶음(도메인)으로 나눌 수 있습니다. 도메인은 되풀이되는 시간표에서 자기 창에서만 실행되고, 한 도메인이 사용하지 않은 시간은 다른 도메인에 넘어가지 않습니다. 이 메커니즘은 항상 커널에 들어 있고 부팅할 때마다 테스트하지만, 도메인을 둘 이상 사용하는 이미지는 아직 없습니다. 기계가 검사한 증명(Lean 4)이 함께 들어 있습니다. 이 증명은 스케줄러의 모델에 대한 것이며 코드에 대한 것이 아닙니다. [INTRODUCTION_KR.md](INTRODUCTION_KR.md)를 참고하세요. - **선택 사항인 서명 오라클**: 빌드 옵션으로 다른 태스크를 위해 메시지에 서명하고 키는 절대 내주지 않는 태스크를 추가합니다. 기본값은 꺼짐이고, Ed25519 구현은 검증받지 않았으며, 키는 하나를 메모리에만 둡니다. [INTRODUCTION_KR.md](INTRODUCTION_KR.md)를 참고하세요. - **선택 사항인 운영자 터미널**: 빌드 옵션으로 시리얼 줄에서 사람이 명령을 입력하는 화면을 추가합니다. 서명 오라클의 키를 만들고, 공개 키를 읽고, 키를 지울 수 있지만 서명은 할 수 없습니다. 기본값은 꺼짐입니다. @@ -70,6 +71,7 @@ $ cargo run -p k0-kernel --features console,terminal,vault-ed25519 | [USAGE_KR.md](USAGE_KR.md) | 준비, 빌드, 실행, 테스트 | | [SECURITY_KR.md](SECURITY_KR.md) | 격리 모델, 알려진 어드바이저리, 취약점 신고 | | [설계 문서](design/kr/README.md) | 커널의 각 부분이 어떻게 동작하고 왜 그렇게 만들었는지 | +| [Lean 증명](proofs/lean/README.md)(영문) | 시간 분할 스케줄러의 모델에 대해 증명한 것과 증명하지 않은 것, 그리고 확인하는 방법 | | [CONTRIBUTING_KR.md](CONTRIBUTING_KR.md) | 기여 방법 | ## 기여 diff --git a/SECURITY.md b/SECURITY.md index 375cd60..3d346a4 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -47,7 +47,7 @@ Treat every task as fully trusted in those versions. ### The current `main` branch (unreleased) -The current `main` branch contains task isolation. No release or tag contains it yet, and its system call ABI is incompatible with `v0.1.0` (bootinfo layout version 4). +The current `main` branch contains task isolation. No release or tag contains it yet, and its system call ABI is incompatible with `v0.1.0` (bootinfo layout version 5). It is also incompatible with a root task built for an earlier state of `main`: the layout version went from 4 to 5 with the time partitions, and the first untyped slot moved from 5 to 6. A confined task has the following properties: @@ -63,11 +63,11 @@ What is still NOT provided on `main`: - **Availability**: isolation does not cover it. The kernel no longer halts when every task is blocked, a task can bound its own waits with a timeout (GHSA-q99x-2wrv-358p, see "Known advisories"), and the two kernel tables for alias mappings and address spaces can no longer be exhausted. The following is still open: - A task that waits without a timeout can wait forever if its partner never acts. A timeout is opt-in per call, so a server or the root task that must stay responsive has to give a timeout on every wait. - - A timeout says when a task becomes ready, not when it runs. There is no priority and no CPU budget: a CPU-bound task uses its whole turn and nothing caps it. The scheduler is round-robin with a tick of one second. A task that holds `Untyped` memory can create many tasks and dilute the share of every other task, because with N ready tasks the bound below is 1/N and N grows with every task created. - - Taking the CPU from the next task by yielding or blocking just before the tick is addressed on `main`. `YIELD` needs no capability, and before this change the next task then got only the rest of that period, while the yielding task was back at the head of the queue for the next full period (two CPU-bound tasks in QEMU: the other task fell from about 52 % to 8 % to 11 % of the CPU, and to 3.5 % when the kernel measured time with the counter). The rule now: a task that gets the CPU between two ticks (the previous task yielded, blocked, exited or was killed, or the kernel was idle and woke up for something other than a tick) is not preempted by the first tick it meets. A task is therefore not cut before it has run one full period, and a task that never yields or blocks keeps at least 1/N of the CPU with N ready tasks. That bound was checked by search in a model of the scheduler (up to 6 tasks) and by host tests (`crates/k0-slice`), and it was seen in QEMU (with the attacker yielding at 90 % of the period, the other task had 53.8 % to 54.9 %). It is not a proof and not a budget. A self-test at every boot (`root: slice test yield pass`, `root: slice test block pass`) checks that such a task is not cut at its first tick, on the yield path and on the block path. - - Timing channels through the scheduler are open. A task still changes when, and now also for how long, another task runs by choosing when to yield or block. This has not been analysed, and closing it would need fixed time partitions, which K0 does not have. + - A timeout says when a task becomes ready, not when it runs. There is no priority and no CPU budget: a CPU-bound task uses its whole turn and nothing caps it. The scheduler is round-robin with a tick of one second, inside each time partition domain. Every image built today has one domain. A task that holds `Untyped` memory can create many tasks and dilute the share of every other task of its domain, because with N ready tasks the bound below is 1/N and N grows with every task created. + - Taking the CPU from the next task by yielding or blocking just before the tick is addressed on `main`. `YIELD` needs no capability, and before this change the next task then got only the rest of that period, while the yielding task was back at the head of the queue for the next full period (two CPU-bound tasks in QEMU: the other task fell from about 52 % to 8 % to 11 % of the CPU, and to 3.5 % when the kernel measured time with the counter). The rule now: a task that gets the CPU between two ticks (the previous task yielded, blocked, exited or was killed, or the kernel was idle and woke up for something other than a tick) is not preempted by the first tick it meets. A task is therefore not cut before it has run one full period, and a task that never yields or blocks keeps at least 1/N of the CPU with N ready tasks. That bound was checked by search in a model of the scheduler (up to 6 tasks) and by host tests (`crates/k0-slice`), and it was seen in QEMU (with the attacker yielding at 90 % of the period, the other task had 53.8 % to 54.9 %). A Lean theorem states it for a model of one domain. It is not a proof about the Rust code, there is no such statement for a table with several domains, and it is not a budget. Under a time partition table the end of a window takes the CPU whatever the rule says, and the rule then holds on the domain's own windows put end to end. A self-test at every boot (`root: slice test yield pass`, `root: slice test block pass`) checks that such a task is not cut at its first tick, on the yield path and on the block path. + - The timing channel through the scheduler is open between tasks of one domain. A task still changes when, and for how long, another task of its domain runs by choosing when to yield or block. This has not been analysed. Between domains, fixed time partitions close this one channel, with the limits listed under "Fixed time partitions". Every image built today runs with one domain, so in those images the channel is open between all tasks. - There is no real-time or latency promise. The kernel is not preemptible and the tick is one second. A task that becomes ready with k tasks to run before it (the running one included) now starts within k + 1 tick periods, where it used to start within k, so a wait can be up to one tick longer. A caller and a server that exchange calls behind one CPU-bound task needed 2 ticks per round trip in the model and need 4 now. A run of one to two periods and a wait of k + 1 periods describe this version of the scheduler and are not an interface. - - Some mistakes in connecting the rule to the scheduler would be seen by no test on the real kernel: the tick's own switch passing the wrong entry kind, the idle loop reporting the wrong thing about a tick, and the entry kind at the hand-off to the root task. They change how long a task runs before it is cut, not its share. The host model covers the rule for these cases, not the kernel's use of it. The boot test does catch the old rule and a wrong entry kind on the yield path or the block path. + - The kernel no longer chooses the entry kind of a task. It names the event, and one piece of code that is tested on the host (`crates/k0-part`) chooses. The three mistakes that no test on the real kernel would have seen (the tick's own switch, the wait loop's report of a tick, the entry kind at the hand-off to the root task) are therefore covered by host tests of that code. What no test sees now is listed under "Fixed time partitions": the guard, the hold before the return to EL0, the TLB flush at a change of domain and the console rule under a table. The queues and timed lists around that code (`crates/k0-sched`, `crates/k0-ipc`) have no host tests and are covered by the boot test and by review. - The measurements used an attacker whose yield point was set for it from a loop count that the root task measured. What an attacker needs to find that point by itself was not measured. Everything ran in QEMU (TCG and HVF), nothing on hardware. - The kernel is not preemptible. A long system call, for example `CAP_REVOKE` on an `Untyped` with many objects, delays every other task and every timeout. An `Untyped` capability cannot be split or capped, so a task that is given one can do this with all of it. Hand `Untyped` only to a task that is trusted with the availability of the whole system. The root task gives none to the terminal or the vault. - A `k0_arch::fatal` or a kernel panic still stops the machine, and so does an SError taken from EL0. @@ -85,13 +85,46 @@ What is still NOT provided on `main`: - **Source of output**: kernel output and task output share one boot log, and in an image built with a console driver also one console. A line does not say who wrote it. A task that holds a `Console` capability with the write right can print a line that starts with `k0:`. The kernel replaces control bytes and limits how much of the boot log task output may use, but nothing that reads the console or the log, including `tools/qemu-boot-test.sh`, can treat a `k0:` line printed after `k0: entering root task (el0)` as written by the kernel. This includes the `k0: console drivers [...]` line (see "Optional console output"). - **Trap to EL2**: isolation covers confidentiality and integrity, not availability. A trap to EL2 after the kernel has stepped down to EL1 parks the whole machine by design. - **Entry at EL2**: entry at EL2 relies on the firmware contract that Linux also uses: an EL3 firmware must enable the fine-grained-trap and HCRX controls when those features exist. -- **Root task**: the root task is still trusted and holds the initial `Untyped` capabilities, and `write_bootinfo` still exposes their physical addresses to it. In an image with the signing oracle it also builds the vault and could read the vault's memory (see "The signing oracle"). In an image with the feature `terminal` it also starts the terminal task and is not restarted if the terminal or the vault dies. +- **Root task**: the root task is still trusted and holds the initial `Untyped` capabilities, and `write_bootinfo` still exposes their physical addresses to it. It also holds the control capability of the time partitions until it deletes it at the end of its self-tests. In an image with the signing oracle it also builds the vault and could read the vault's memory (see "The signing oracle"). In an image with the feature `terminal` it also starts the terminal task and is not restarted if the terminal or the vault dies. > [!WARNING] > Even on `main`, treat running untrusted code as experimental. The availability limits above still apply. The isolation is exercised by the host tests and the boot self-tests. Isolation bypasses on `main` are welcome reports. +## Fixed time partitions + +The current `main` branch has a domain scheduler that is always compiled in. Every task belongs to one of 8 domains, and a table of up to 16 entries says which domain may use the CPU at which tick. The tick is 1 second. A domain runs only in its own windows of the table. Time that is left over in a window is not given to another domain: the CPU waits. [design/en/scheduling.md](design/en/scheduling.md#time-partitions) describes the mechanism. + +> [!NOTE] +> No image uses more than one domain yet. The root task tries the mechanism in a self-test at every boot and then deletes the control capability, so every image built today runs sealed with one domain, and the claim below protects nothing in those images. Putting the key vault in a domain of its own is future work. + +What the partitions claim: + +- **The claim**: fixed time partitions close the channel between domains that goes through the scheduler. With a table set, which task of a domain runs, in which order and at which tick does not depend on what the tasks of other domains do, as long as the domains share no kernel object and within the limits below. This is not a claim about timing channels in general. +- **Start of a window**: on a tick that changes the domain, the timer interrupt is taken one fortieth of a tick (25 ms) early, the switch work is done, and the kernel holds until the tick instant before the next domain runs. The next domain starts at the tick instant, to within the spin and the exit path, as long as the kernel path in flight and the switch work fit in the guard. +- **One exit**: every return from an exception to EL0 passes one function (`k0_leave`). It halts the kernel unless the task it returns to is the running task of the running domain, and then it holds until the tick instant. +- **TLB**: it is flushed at every change of domain. +- **Timeouts**: deadlines are global tick numbers and are served only when the owner's domain runs. Under a table a timeout can fire late and never early. +- **Authority**: one capability, `PartCtl`, which the root task gets at boot in slot 5 of its CNode. It cannot be copied. The system calls `PART_SET_TABLE` (17) and `PART_SET_DOMAIN` (18) need it. A new table takes effect two ticks after the last processed tick and must contain the caller's own domain. A task gets the domain of the task that configured it, and its domain can be changed only before it first runs. Deleting the capability seals the table and the domains until the next boot. +- **No table set**: there is one domain, and the scheduler makes the same decision as before for the same sequence of events, when no tick is skipped. +- **Console input**: under a table a byte is handed to a waiting reader only while the reader's domain runs. + +The limits are as follows. They are part of the claim. + +1. A kernel path that is longer than the guard and is in flight when the guard starts delays the start of the next window. `CAP_REVOKE` and large deletes are such paths. The kernel is not preemptible. +2. Caches and branch predictors are not flushed at a change of domain. +3. The time of console input interrupts, and of the UART work in the tick handler, lands in whichever domain runs. +4. Kernel state other than the scheduler is shared: the UART and the boot log, the single console waiter slot (a second reader gets `BUSY`), and the kernel memory pools. +5. The tick number follows the counter, and skipped ticks are not replayed. A stall longer than a tick therefore skips windows. +6. Endpoints shared across domains are channels by design. So are other capability operations on an object shared with another domain: deleting or revoking an endpoint its tasks wait on, the end of a task that holds its reply, `TCB_RESUME` of one of its tasks, and deleting one of its TCBs. +7. A task that is woken by console input inside the guard of an empty incoming window starts at the tick instant and still skips its first tick rotation. The effect stays inside its own domain. +8. No test sees the guard, the hold or the TLB flush, because EL0 cannot time anything: a kernel without them passes every test. The console rule under a table has no test. These rest on review. +9. The proofs are about a model. `proofs/lean` holds Lean 4 proofs about an abstract model of the scheduler, which are not run in CI. They are not proofs about the Rust code. The link to the code is a host test that runs 1600 recorded scripts through the Rust code and compares each with the model's result, and that test is in CI. +10. Real hardware was not tested. Everything ran in QEMU (TCG and HVF). The one timing measurement is from one development machine: the tick handler was entered 2 to 5 ms after the start of the guard under TCG and 5 to 31 microseconds after it under HVF. + +Inside one domain nothing changed: a task still changes when, and for how long, another task of its domain runs by choosing when to yield or block. + ## The UEFI loader `loader/` is a UEFI application that embeds a built kernel and starts it with the usual boot contract, and `crates/k0-efi` holds its logic. The kernel does not change. What the loader does and why it exists are in [design/en/uefi.md](design/en/uefi.md). The security-relevant facts: @@ -197,7 +230,7 @@ What the kernel does with input: - **Receive path**: the kernel's UART driver puts received bytes into a ring of 256 bytes. The kernel never interprets a byte. Loss (a FIFO overrun, a break, a framing or parity error) is marked on the byte after the hole. - **Reading input**: `CONSOLE_READ` (system call 16). The caller names a `Console` slot and flags (`NONBLOCK`, `FLUSH`, a timeout in ticks in bits 63..32, other bits refused with `BAD_FLAGS`). It returns one byte per call. Only one task can wait at a time, and a second reader gets `BUSY`. The read right is meant for one task: every holder takes bytes from the same ring, so a second holder can take input that was meant for the first, or occupy the wait. It returns `NO_DEVICE` when there is no input path or it was turned off. A waiter whose capability is deleted, revoked or moved wakes at once with `REVOKED`. A woken reader goes to the end of the ready queue, so input does not preempt. -- **Console capability rights**: R (read input) and W (write output). `CAP_COPY` can only remove them. The root task's capability has W, and R only in images with `console-input`. `bootinfo::VERSION` is 4. +- **Console capability rights**: R (read input) and W (write output). `CAP_COPY` can only remove them. The root task's capability has W, and R only in images with `console-input`. The rights came with `bootinfo::VERSION` 4, and the version is 5 now. - **Output filter**: unchanged, except that a `Console` capability with R (the terminal's) may also emit backspace (0x08). Every other control byte is still printed as `?`. - **Receive interrupts stay off** until a task first reads console input with the right. That first read discards what the device holds, and the periodic `k0: tick N` lines stop after one line `k0: tick lines off (console input in use)`. Ticks, preemption and timeouts keep working. - **Bound on interrupt work**: when the ring is full, the kernel masks the UART's receive interrupt itself and reopens it after the reader has taken half of the ring. Under a flood of bytes the interrupt rate is therefore bounded by the reader. A character with a break, framing or parity error uses no place in the ring, so it has its own bound: after 256 such characters in one tick the kernel masks the receive interrupt until the next tick. Bytes that arrive in between wait in the device FIFO and are marked as lost if it overruns. The same drain also runs once per tick, so input still arrives, up to a tick late, when the interrupt does not. @@ -215,7 +248,7 @@ The limits are as follows: 1. The serial line is as trusted as whoever can reach it. The operator can erase the key, which is a denial of service by design. 2. The kernel's receive code runs at EL1. It is small and never interprets bytes, but it is kernel code driven by an outside party. A user-space driver needs device and interrupt delegation, which K0 does not have. -3. An outside party can now cause interrupts while tasks run, bounded by the reader for bytes and by 256 per tick for characters with a line error. The reader learns arrival times finer than the tick, and other tasks can notice the stolen time. This is a timing channel that has not been analysed. +3. An outside party can now cause interrupts while tasks run, bounded by the reader for bytes and by 256 per tick for characters with a line error. The reader learns arrival times finer than the tick, and other tasks can notice the stolen time. This is a timing channel that has not been analysed, and fixed time partitions do not close it. 4. Input waits behind running tasks. There are no priorities, so the latency is up to a tick per ready task, plus one more tick when the running task got the CPU between two ticks. 5. A 16550 console has no input. The SBSA UART path, FIFO overruns and the receive timeout interrupt are not exercised by QEMU, and host tests with a fake UART (`crates/k0-conin`) are their only coverage. The cut-off for an interrupt line that fires without a UART cause is covered by host tests only. 6. No test measures kernel time under a flood on a machine. The bounds are argued from the gate and the per-tick count and shown in host tests. The terminal test sends 2000 breaks under QEMU and checks only that the input path is not cut off and answers again. That step runs on QEMU 8.0 or later, so CI (QEMU 7.2) does not run it: an older QEMU puts a break into its PL011 receive FIFO without checking the depth, and breaks pile up there while the kernel keeps the interrupt masked. @@ -289,7 +322,7 @@ You can report a problem in the following ways: - **Preferred**: open a draft security advisory at . - **Alternative**: email the maintainer at . Include the affected commit hash, the platform (QEMU machine and CPU model, hypervisor, or board), the entry level (EL1 or EL2), the page size (4 KiB or 16 KiB), the `k0: platform ...` line from the boot log, and a reproduction if you have one. -Isolation gaps in `v0.1.0` and earlier commits, and the availability and resource limits listed under "What is still NOT provided on `main`", are already known and **do not need to be filed again**. Isolation bypasses on the current `main` branch are welcome, for example a task reaching another task's memory or capabilities, a revoked capability that keeps working, or a stale mapping that survives unmap, revoke or address space destruction. Reports about the signing oracle are welcome, for example a key disclosure to a client, a policy bypass, or a reply that reaches the wrong caller. Reports about the serial input path and the operator terminal are welcome too, for example a byte stream that makes the kernel misbehave, a wake-up of the wrong task, or an operator operation beyond the four listed. Reports about the UEFI loader are welcome too, for example a memory map or device tree that makes it hand the kernel memory that firmware still uses, or a refusal that does not happen. Reports about anything else, including boot-time memory map validation, exception handling, scheduler policy, and IPC state machines, are welcome. +Isolation gaps in `v0.1.0` and earlier commits, and the availability and resource limits listed under "What is still NOT provided on `main`", are already known and **do not need to be filed again**. Isolation bypasses on the current `main` branch are welcome, for example a task reaching another task's memory or capabilities, a revoked capability that keeps working, or a stale mapping that survives unmap, revoke or address space destruction. Reports about the signing oracle are welcome, for example a key disclosure to a client, a policy bypass, or a reply that reaches the wrong caller. Reports about the serial input path and the operator terminal are welcome too, for example a byte stream that makes the kernel misbehave, a wake-up of the wrong task, or an operator operation beyond the four listed. Reports about the UEFI loader are welcome too, for example a memory map or device tree that makes it hand the kernel memory that firmware still uses, or a refusal that does not happen. Reports about the time partitions are welcome too, for example a task that changes which task of another domain runs, or at which tick, without sharing an object with it, a table or a domain that is set without the control capability, or a system call sequence that halts the kernel on the new paths. The limits listed under "Fixed time partitions" are known and do not need to be filed again. Reports about anything else, including boot-time memory map validation, exception handling, scheduler policy, and IPC state machines, are welcome. ## Scope diff --git a/SECURITY_KR.md b/SECURITY_KR.md index 9b7eff1..128a341 100644 --- a/SECURITY_KR.md +++ b/SECURITY_KR.md @@ -47,7 +47,7 @@ K0는 **정식 릴리즈 전 단계의 연구용 마이크로커널**입니다. ### 현재 `main` 브랜치(릴리즈 전) -현재 `main` 브랜치에는 태스크 격리가 들어 있습니다. 아직 어떤 릴리즈나 태그에도 포함되지 않았고, 시스템 콜 ABI가 `v0.1.0`과 호환되지 않습니다(bootinfo 레이아웃 버전 4). +현재 `main` 브랜치에는 태스크 격리가 들어 있습니다. 아직 어떤 릴리즈나 태그에도 포함되지 않았고, 시스템 콜 ABI가 `v0.1.0`과 호환되지 않습니다(bootinfo 레이아웃 버전 5). 이전 상태의 `main`에 맞춰 빌드한 루트 태스크와도 호환되지 않습니다. 시간 분할이 들어오면서 레이아웃 버전이 4에서 5로 올라갔고, 첫 untyped 슬롯이 5에서 6으로 옮겨 갔습니다. 격리된 태스크의 성질은 다음과 같습니다. @@ -63,11 +63,11 @@ K0는 **정식 릴리즈 전 단계의 연구용 마이크로커널**입니다. - **가용성**: 격리는 가용성을 다루지 않습니다. 모든 태스크가 블록되어도 커널은 더 이상 멈추지 않고, 태스크는 타임아웃으로 자신의 대기를 제한할 수 있으며(GHSA-q99x-2wrv-358p, "알려진 어드바이저리" 참고), 별칭 매핑과 주소 공간을 위한 두 커널 테이블은 더 이상 소진되지 않습니다. 다음은 아직 열려 있습니다. - 타임아웃 없이 기다리는 태스크는 상대가 움직이지 않으면 영원히 기다릴 수 있습니다. 타임아웃은 호출마다 선택하는 기능이므로, 응답성을 유지해야 하는 서버나 루트 태스크는 모든 대기에 타임아웃을 지정해야 합니다. - - 타임아웃은 태스크가 언제 준비 상태가 되는지를 정할 뿐, 언제 실행되는지는 정하지 않습니다. 우선순위와 CPU 예산이 없으며, CPU를 많이 쓰는 태스크는 자기 차례를 모두 쓰고 이를 막는 것은 없습니다. 스케줄러는 틱이 1초인 라운드 로빈입니다. `Untyped` 메모리를 가진 태스크는 태스크를 많이 만들어 다른 모든 태스크의 몫을 희석시킬 수 있습니다. 준비된 태스크가 N개일 때 아래의 하한은 1/N이고, 태스크를 만들 때마다 N이 커지기 때문입니다. - - 틱 직전에 양보하거나 블록해서 다음 태스크의 CPU를 빼앗는 문제는 `main`에서 대응했습니다. `YIELD`는 케이퍼빌리티가 필요 없고, 이 변경 전에는 다음 태스크가 그 주기의 나머지만 받은 반면 양보한 태스크는 다음 주기 전체에서 큐의 맨 앞으로 돌아왔습니다(QEMU에서 CPU를 쓰는 태스크 둘일 때 상대 태스크의 몫이 약 52 %에서 8 %~11 %로, 커널이 카운터로 시간을 재면 3.5 %로 떨어졌습니다). 지금의 규칙은 다음과 같습니다. 두 틱 사이에 CPU를 받은 태스크(이전 태스크가 양보했거나, 블록했거나, 종료되었거나 강제 종료된 경우, 또는 커널이 유휴 상태에서 틱이 아닌 것 때문에 깨어난 경우)는 처음 만나는 틱에 선점되지 않습니다. 따라서 태스크는 한 주기를 온전히 실행하기 전에는 잘리지 않으며, 양보하거나 블록하지 않는 태스크는 준비된 태스크가 N개일 때 CPU의 1/N 이상을 가집니다. 이 하한은 스케줄러 모델에 대한 탐색(최대 6개 태스크)과 호스트 테스트(`crates/k0-slice`)로 확인했고 QEMU에서도 관찰했습니다(공격자가 주기의 90 %에서 양보할 때 상대 태스크는 53.8 %~54.9 %를 가졌습니다). 증명이 아니며 예산도 아닙니다. 부팅할 때마다 실행하는 자체 테스트(`root: slice test yield pass`, `root: slice test block pass`)가 이런 태스크가 첫 틱에서 끊기지 않는지를 양보 경로와 블록 경로에서 확인합니다. - - 스케줄러를 통한 타이밍 채널은 열려 있습니다. 태스크는 양보하거나 블록하는 시점을 골라 다른 태스크가 언제, 그리고 이제는 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. 이것은 분석하지 않았으며, 닫으려면 고정 시간 분할이 필요한데 K0에는 없습니다. + - 타임아웃은 태스크가 언제 준비 상태가 되는지를 정할 뿐, 언제 실행되는지는 정하지 않습니다. 우선순위와 CPU 예산이 없으며, CPU를 많이 쓰는 태스크는 자기 차례를 모두 쓰고 이를 막는 것은 없습니다. 스케줄러는 시간 분할 도메인 각각의 안에서 틱이 1초인 라운드 로빈입니다. 지금 빌드하는 모든 이미지는 도메인이 하나입니다. `Untyped` 메모리를 가진 태스크는 태스크를 많이 만들어 자기 도메인에 있는 다른 모든 태스크의 몫을 희석시킬 수 있습니다. 준비된 태스크가 N개일 때 아래의 하한은 1/N이고, 태스크를 만들 때마다 N이 커지기 때문입니다. + - 틱 직전에 양보하거나 블록해서 다음 태스크의 CPU를 빼앗는 문제는 `main`에서 대응했습니다. `YIELD`는 케이퍼빌리티가 필요 없고, 이 변경 전에는 다음 태스크가 그 주기의 나머지만 받은 반면 양보한 태스크는 다음 주기 전체에서 큐의 맨 앞으로 돌아왔습니다(QEMU에서 CPU를 쓰는 태스크 둘일 때 상대 태스크의 몫이 약 52 %에서 8 %~11 %로, 커널이 카운터로 시간을 재면 3.5 %로 떨어졌습니다). 지금의 규칙은 다음과 같습니다. 두 틱 사이에 CPU를 받은 태스크(이전 태스크가 양보했거나, 블록했거나, 종료되었거나 강제 종료된 경우, 또는 커널이 유휴 상태에서 틱이 아닌 것 때문에 깨어난 경우)는 처음 만나는 틱에 선점되지 않습니다. 따라서 태스크는 한 주기를 온전히 실행하기 전에는 잘리지 않으며, 양보하거나 블록하지 않는 태스크는 준비된 태스크가 N개일 때 CPU의 1/N 이상을 가집니다. 이 하한은 스케줄러 모델에 대한 탐색(최대 6개 태스크)과 호스트 테스트(`crates/k0-slice`)로 확인했고 QEMU에서도 관찰했습니다(공격자가 주기의 90 %에서 양보할 때 상대 태스크는 53.8 %~54.9 %를 가졌습니다). Lean 정리 하나가 도메인 하나의 모델에 대해 이 하한을 진술합니다. 이것은 Rust 코드에 대한 증명이 아니고, 도메인이 여럿인 표에 대해서는 그런 진술이 없으며, 예산도 아닙니다. 시간 분할 표가 있으면 창의 끝은 이 규칙이 무엇이라 하든 CPU를 가져가고, 규칙은 그 도메인의 창을 이어 붙인 시간 위에서 성립합니다. 부팅할 때마다 실행하는 자체 테스트(`root: slice test yield pass`, `root: slice test block pass`)가 이런 태스크가 첫 틱에서 끊기지 않는지를 양보 경로와 블록 경로에서 확인합니다. + - 스케줄러를 통한 타이밍 채널은 한 도메인의 태스크 사이에서 열려 있습니다. 태스크는 양보하거나 블록하는 시점을 골라 자기 도메인의 다른 태스크가 언제, 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. 이것은 분석하지 않았습니다. 도메인 사이에서는 고정 시간 분할이 이 채널 하나를 닫으며, 그 한계는 "고정 시간 분할" 절에 나열했습니다. 지금 빌드하는 모든 이미지는 도메인 하나로 실행되므로, 그런 이미지에서는 이 채널이 모든 태스크 사이에 열려 있습니다. - 실시간이나 지연 시간에 대한 약속은 없습니다. 커널은 선점되지 않고 틱은 1초입니다. 자기보다 먼저 실행될 태스크가 k개(실행 중인 태스크 포함)일 때 준비된 태스크는 이제 k + 1 틱 주기 안에 시작하며, 전에는 k 주기 안에 시작했으므로 대기가 최대 한 틱 길어질 수 있습니다. CPU를 쓰는 태스크 하나 뒤에서 호출과 응답을 주고받는 호출자와 서버는 모델에서 왕복당 2틱이 걸렸고 이제는 4틱이 걸립니다. 한 번에 한 주기에서 두 주기를 실행한다는 것과 k + 1 주기를 기다린다는 수치는 이 버전의 스케줄러를 설명할 뿐 인터페이스가 아닙니다. - - 규칙을 스케줄러에 연결하는 과정의 일부 실수는 실제 커널에 대한 어떤 테스트로도 발견되지 않습니다. 틱 자신의 전환이 잘못된 진입 종류를 넘기는 경우, 유휴 루프가 틱에 대해 잘못 보고하는 경우, 루트 태스크로 넘기는 시점의 진입 종류입니다. 이것은 태스크의 몫이 아니라 잘리기 전까지 실행되는 시간에 영향을 줍니다. 호스트 모델은 이 경우들에 대한 규칙을 검증할 뿐 커널이 규칙을 쓰는 방식은 검증하지 않습니다. 부팅 테스트는 이전 규칙과, 양보 경로나 블록 경로의 잘못된 진입 종류는 잡아냅니다. + - 커널은 더 이상 태스크의 진입 종류를 고르지 않습니다. 커널은 사건의 이름만 알리고, 호스트에서 테스트하는 코드 한 곳(`crates/k0-part`)이 진입 종류를 고릅니다. 그래서 실제 커널에 대한 어떤 테스트로도 발견되지 않던 세 가지 실수(틱 자신의 전환, 대기 루프가 틱에 대해 하는 보고, 루트 태스크로 넘기는 시점의 진입 종류)는 이제 그 코드의 호스트 테스트가 다룹니다. 지금 어떤 테스트도 보지 못하는 것은 "고정 시간 분할" 절에 나열했습니다. 보호 구간, EL0로 돌아가기 전의 대기, 도메인이 바뀔 때의 TLB 비우기, 표가 있을 때의 콘솔 규칙입니다. 그 코드를 둘러싼 큐와 기한 목록(`crates/k0-sched`, `crates/k0-ipc`)에는 호스트 테스트가 없으며, 부팅 테스트와 리뷰로 확인합니다. - 측정에 쓴 공격자는 루트 태스크가 잰 루프 횟수로 양보 시점을 미리 맞춰 준 공격자입니다. 공격자가 그 시점을 스스로 찾는 데 무엇이 필요한지는 측정하지 않았습니다. 모든 실행은 QEMU(TCG와 HVF)에서 했고 하드웨어에서는 실행하지 않았습니다. - 커널은 선점되지 않습니다. 긴 시스템 콜(예: 오브젝트가 많은 `Untyped`에 대한 `CAP_REVOKE`)은 다른 모든 태스크와 모든 타임아웃을 지연시킵니다. `Untyped` 케이퍼빌리티는 나누거나 상한을 걸 수 없으므로, 이것을 받은 태스크는 그 전체로 이 일을 할 수 있습니다. `Untyped`는 시스템 전체의 가용성을 맡길 수 있는 태스크에만 넘기세요. 루트 태스크는 터미널과 볼트에 `Untyped`를 주지 않습니다. - `k0_arch::fatal`이나 커널 패닉은 여전히 기계를 멈추며, EL0에서 발생한 SError도 마찬가지입니다. @@ -85,13 +85,46 @@ K0는 **정식 릴리즈 전 단계의 연구용 마이크로커널**입니다. - **출력의 출처**: 커널 출력과 태스크 출력은 부트 로그 하나를 함께 사용합니다. 콘솔 드라이버를 포함해 빌드한 이미지에서는 콘솔 하나도 함께 사용합니다. 줄에는 누가 썼는지 표시가 없습니다. 쓰기 권한이 있는 `Console` 케이퍼빌리티를 가진 태스크는 `k0:`로 시작하는 줄을 출력할 수 있습니다. 커널은 제어 바이트를 바꾸고 태스크 출력이 부트 로그에서 차지할 수 있는 양을 제한합니다. 그래도 콘솔이나 로그를 읽는 쪽은 `tools/qemu-boot-test.sh`를 포함해 누구도 `k0: entering root task (el0)` 뒤에 나온 `k0:` 줄을 커널이 쓴 것으로 믿을 수 없습니다. `k0: console drivers [...]` 줄도 여기에 포함됩니다("선택적 콘솔 출력" 참고). - **EL2 트랩**: 격리는 기밀성과 무결성을 다루고 가용성은 다루지 않습니다. 커널이 EL1로 내려온 뒤 EL2로 트랩이 오면 설계상 기계 전체를 멈춥니다. - **EL2 진입**: EL2 진입은 Linux와 같은 펌웨어 약속을 전제로 합니다. EL3 펌웨어는 세분화된 트랩과 HCRX 제어 기능이 있으면 이를 켜 주어야 합니다. -- **루트 태스크**: 루트 태스크는 여전히 신뢰 대상이며 최초의 `Untyped` 케이퍼빌리티를 가지고, `write_bootinfo`는 그 물리 주소를 루트 태스크에 계속 노출합니다. 서명 오라클이 있는 이미지에서는 루트 태스크가 볼트도 만들며 볼트의 메모리를 읽을 수 있습니다("서명 오라클" 참고). feature `terminal`이 있는 이미지에서는 터미널 태스크도 시작하며, 터미널이나 볼트가 죽어도 다시 시작하지 않습니다. +- **루트 태스크**: 루트 태스크는 여전히 신뢰 대상이며 최초의 `Untyped` 케이퍼빌리티를 가지고, `write_bootinfo`는 그 물리 주소를 루트 태스크에 계속 노출합니다. 루트 태스크는 시간 분할의 제어 케이퍼빌리티도 가지며, 자가 테스트의 끝에서 이를 삭제할 때까지 가집니다. 서명 오라클이 있는 이미지에서는 루트 태스크가 볼트도 만들며 볼트의 메모리를 읽을 수 있습니다("서명 오라클" 참고). feature `terminal`이 있는 이미지에서는 터미널 태스크도 시작하며, 터미널이나 볼트가 죽어도 다시 시작하지 않습니다. > [!WARNING] > `main`에서도 신뢰하지 않는 코드의 실행은 실험적인 것으로 취급하세요. 위의 가용성 한계는 그대로 적용됩니다. 격리는 호스트 테스트와 부팅 자가 검증으로 검증합니다. `main`의 격리 우회는 언제든 환영하는 신고입니다. +## 고정 시간 분할 + +현재 `main` 브랜치에는 항상 컴파일되어 들어가는 도메인 스케줄러가 있습니다. 모든 태스크는 8개 도메인 가운데 하나에 속하고, 항목이 최대 16개인 표가 어느 틱에 어느 도메인이 CPU를 사용할 수 있는지 정합니다. 틱은 1초입니다. 도메인은 표에 있는 자기 창에서만 실행됩니다. 창에서 남는 시간은 다른 도메인에 넘겨주지 않으며, 그동안 CPU는 기다립니다. 메커니즘은 [design/kr/scheduling_KR.md](design/kr/scheduling_KR.md#시간-분할)에서 설명합니다. + +> [!NOTE] +> 도메인을 둘 이상 사용하는 이미지는 아직 없습니다. 루트 태스크가 부팅할 때마다 자가 테스트에서 이 메커니즘을 시험해 본 뒤 제어 케이퍼빌리티를 삭제하므로, 지금 빌드하는 모든 이미지는 도메인 하나로 봉인된 채 실행됩니다. 그런 이미지에서는 다음에 적은 주장이 아무것도 보호하지 않습니다. 키 볼트를 자기만의 도메인에 두는 것은 앞으로 할 일입니다. + +시간 분할이 주장하는 것은 다음과 같습니다. + +- **주장**: 고정 시간 분할은 도메인 사이에서 스케줄러를 거치는 채널을 닫습니다. 표가 정해져 있으면 한 도메인의 어느 태스크가 어떤 순서로 어느 틱에 실행되는지는 다른 도메인의 태스크가 무엇을 하는지에 달려 있지 않습니다. 단, 도메인들이 커널 오브젝트를 공유하지 않을 때, 그리고 뒤에 나열한 한계 안에서만 그렇습니다. 타이밍 채널 전반에 대한 주장이 아닙니다. +- **창의 시작**: 도메인이 바뀌는 틱에서는 타이머 인터럽트를 틱의 40분의 1(25 ms)만큼 일찍 받고, 전환 작업을 한 다음, 커널이 틱 시각까지 기다렸다가 다음 도메인을 실행합니다. 진행 중이던 커널 경로와 전환 작업이 보호 구간 안에 들어가는 한, 다음 도메인은 스핀과 복귀 경로만큼의 오차 안에서 틱 시각에 시작합니다. +- **출구 하나**: 예외에서 EL0로 돌아가는 모든 길은 함수 하나(`k0_leave`)를 지납니다. 이 함수는 돌아갈 태스크가 도는 도메인의 실행 중인 태스크가 아니면 커널을 정지시키고, 그다음 틱 시각까지 기다립니다. +- **TLB**: 도메인이 바뀔 때마다 비웁니다. +- **타임아웃**: 기한은 전역 틱 번호이며, 대기자의 도메인이 돌 때에만 처리됩니다. 표가 있을 때 타임아웃은 늦게 끝날 수는 있어도 일찍 끝나지는 않습니다. +- **권한**: 케이퍼빌리티 하나, `PartCtl`입니다. 루트 태스크가 부팅 때 자기 CNode의 슬롯 5로 받습니다. 복사할 수 없습니다. 시스템 콜 `PART_SET_TABLE`(17)과 `PART_SET_DOMAIN`(18)에 이 케이퍼빌리티가 필요합니다. 새 표는 마지막으로 처리한 틱의 두 틱 뒤에 효력이 생기며, 호출자 자신의 도메인이 들어 있어야 합니다. 태스크는 자신을 구성한 태스크의 도메인을 받고, 그 도메인은 태스크가 처음 실행되기 전에만 바꿀 수 있습니다. 이 케이퍼빌리티를 삭제하면 표와 도메인이 다음 부팅까지 봉인됩니다. +- **표를 정하지 않은 경우**: 도메인은 하나이고, 틱을 건너뛰지 않는 한 스케줄러는 같은 사건 순서에 대해 이전과 같은 판정을 내립니다. +- **콘솔 입력**: 표가 있을 때 바이트는 읽는 쪽의 도메인이 도는 동안에만 기다리는 읽는 쪽에 전달됩니다. + +한계는 다음과 같습니다. 이 한계는 주장의 일부입니다. + +1. 보호 구간보다 길고 보호 구간이 시작될 때 진행 중이던 커널 경로는 다음 창의 시작을 늦춥니다. `CAP_REVOKE`와 큰 삭제가 그런 경로입니다. 커널은 선점되지 않습니다. +2. 캐시와 분기 예측기는 도메인이 바뀔 때 비우지 않습니다. +3. 콘솔 입력 인터럽트의 시간, 그리고 틱 핸들러가 하는 UART 작업의 시간은 그때 돌고 있는 도메인에 떨어집니다. +4. 스케줄러 이외의 커널 상태는 공유됩니다. UART와 부트 로그, 하나뿐인 콘솔 대기자 슬롯(두 번째 읽는 쪽은 `BUSY`를 받음), 커널 메모리 풀입니다. +5. 틱 번호는 카운터를 따르며, 건너뛴 틱은 다시 재생하지 않습니다. 그래서 한 틱보다 긴 멈춤은 창을 건너뜁니다. +6. 도메인 사이에 공유한 엔드포인트는 설계상 채널입니다. 다른 도메인과 공유한 오브젝트에 대한 그 밖의 케이퍼빌리티 연산도 마찬가지입니다. 그 도메인의 태스크가 기다리는 엔드포인트의 삭제나 revoke, 그 도메인의 태스크에게 돌려줄 응답 자격을 쥔 태스크의 종료, 그 도메인의 태스크에 대한 `TCB_RESUME`, 그 도메인의 TCB 삭제가 그렇습니다. +7. 들어오는 창이 비어 있을 때 그 보호 구간 안에서 콘솔 입력으로 깨어난 태스크는 틱 시각에 시작하면서도 처음 맞는 틱의 순환을 건너뜁니다. 이 영향은 그 태스크 자신의 도메인 안에 머뭅니다. +8. 보호 구간, 틱 시각까지의 대기, TLB 비우기는 어떤 테스트도 보지 못합니다. EL0는 어떤 시간도 잴 수 없기 때문입니다. 이것들이 없는 커널도 모든 테스트를 통과합니다. 표가 있을 때의 콘솔 규칙에는 테스트가 없습니다. 이 부분은 리뷰에 기대고 있습니다. +9. 증명은 모델에 대한 것입니다. `proofs/lean`에는 스케줄러의 추상 모델에 대한 Lean 4 증명이 있고, CI에서 실행하지 않습니다. Rust 코드에 대한 증명이 아닙니다. 코드와 모델을 잇는 것은 호스트 테스트 하나입니다. 기록해 둔 스크립트 1600개를 Rust 코드에 넣어 실행하고 각각을 모델의 결과와 비교하며, 이 테스트는 CI에서 실행됩니다. +10. 실제 하드웨어에서는 테스트하지 않았습니다. 모든 실행은 QEMU(TCG와 HVF)에서 했습니다. 시간 측정은 개발용 기계 한 대에서 한 것 하나뿐입니다. 틱 핸들러에 진입한 시점은 TCG에서 보호 구간이 시작되고 2~5 ms 뒤, HVF에서 5~31마이크로초 뒤였습니다. + +도메인 하나 안에서는 달라진 것이 없습니다. 태스크는 양보하거나 블록하는 시점을 골라 자기 도메인의 다른 태스크가 언제, 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. + ## UEFI 로더 `loader/`는 빌드된 커널을 품고 평소의 부팅 약속대로 시작시키는 UEFI 응용 프로그램이고, `crates/k0-efi`가 그 논리를 담습니다. 커널은 바뀌지 않았습니다. 로더가 하는 일과 있는 이유는 [design/kr/uefi_KR.md](design/kr/uefi_KR.md)에 있습니다. 보안과 관련된 사실은 다음과 같습니다. @@ -197,7 +230,7 @@ $ grep -a 'k0: console drivers' <이미지 파일> - **수신 경로**: 커널의 UART 드라이버가 받은 바이트를 256바이트 링에 넣습니다. 커널은 바이트를 해석하지 않습니다. 손실(FIFO 오버런, 브레이크, 프레이밍 또는 패리티 오류)은 구멍 뒤의 바이트에 표시합니다. - **입력 읽기**: `CONSOLE_READ`(시스템 콜 16번). 호출자가 `Console` 슬롯과 플래그(`NONBLOCK`, `FLUSH`, 63..32비트의 틱 단위 타임아웃, 그 밖의 비트는 `BAD_FLAGS`로 거부)를 지정합니다. 호출마다 한 바이트를 돌려줍니다. 한 번에 한 태스크만 기다릴 수 있고 두 번째 읽는 쪽은 `BUSY`를 받습니다. 읽기 권한은 한 태스크가 쓰도록 만든 것입니다. 권한을 가진 태스크는 모두 같은 링에서 바이트를 가져가므로, 두 번째 태스크가 첫 번째 태스크에게 갈 입력을 가져가거나 기다리는 자리를 차지할 수 있습니다. 입력 경로가 없거나 꺼져 있으면 `NO_DEVICE`를 돌려줍니다. 기다리던 태스크의 케이퍼빌리티가 삭제, revoke 또는 이동되면 즉시 `REVOKED`로 깨어납니다. 깨어난 읽는 쪽은 준비 큐의 맨 뒤로 가므로 입력은 선점하지 않습니다. -- **Console 케이퍼빌리티의 권한**: R(입력 읽기)과 W(출력 쓰기)입니다. `CAP_COPY`는 이를 줄이기만 할 수 있습니다. 루트 태스크의 케이퍼빌리티는 W를 가지며, R은 `console-input`이 있는 이미지에서만 가집니다. `bootinfo::VERSION`은 4입니다. +- **Console 케이퍼빌리티의 권한**: R(입력 읽기)과 W(출력 쓰기)입니다. `CAP_COPY`는 이를 줄이기만 할 수 있습니다. 루트 태스크의 케이퍼빌리티는 W를 가지며, R은 `console-input`이 있는 이미지에서만 가집니다. 이 권한은 `bootinfo::VERSION` 4에서 생겼고, 지금 버전은 5입니다. - **출력 필터**: 바뀌지 않았습니다. 다만 R이 있는 `Console` 케이퍼빌리티(터미널의 것)는 백스페이스(0x08)도 내보낼 수 있습니다. 다른 제어 바이트는 여전히 `?`로 출력됩니다. - **수신 인터럽트는 꺼진 채로 둡니다**: 어떤 태스크가 권한을 가지고 처음 콘솔 입력을 읽을 때까지입니다. 그 첫 읽기가 장치에 있던 것을 버리고, 주기적인 `k0: tick N` 줄은 `k0: tick lines off (console input in use)` 한 줄을 남기고 멈춥니다. 틱, 선점, 타임아웃은 계속 동작합니다. - **인터럽트 작업의 상한**: 링이 가득 차면 커널이 UART의 수신 인터럽트를 스스로 마스크하고, 읽는 쪽이 링의 절반을 가져간 뒤 다시 엽니다. 따라서 바이트가 폭주해도 인터럽트 빈도는 읽는 쪽이 정하는 만큼으로 제한됩니다. 브레이크, 프레이밍 오류, 패리티 오류가 난 문자는 링의 자리를 쓰지 않으므로 따로 상한을 둡니다. 한 틱 동안 그런 문자가 256개 들어오면 커널은 다음 틱까지 수신 인터럽트를 마스크합니다. 그 사이에 온 바이트는 장치의 FIFO에서 기다리고, FIFO가 넘치면 유실로 표시됩니다. 같은 비우기가 틱마다 한 번 더 실행되므로, 인터럽트가 오지 않아도 입력은 최대 한 틱 늦게 도착합니다. @@ -215,7 +248,7 @@ $ grep -a 'k0: console drivers' <이미지 파일> 1. 직렬 회선은 그 회선에 닿을 수 있는 쪽만큼만 신뢰할 수 있습니다. 운영자는 키를 지울 수 있으며, 이는 설계상의 서비스 거부입니다. 2. 커널의 수신 코드는 EL1에서 실행됩니다. 작고 바이트를 해석하지 않지만, 외부 당사자가 구동하는 커널 코드입니다. 사용자 공간 드라이버에는 장치와 인터럽트의 위임이 필요한데, K0에는 이것이 없습니다. -3. 외부 당사자가 이제 태스크 실행 중에 인터럽트를 일으킬 수 있으며, 그 빈도는 바이트에 대해서는 읽는 쪽이, 선로 오류가 난 문자에 대해서는 틱당 256개라는 상한이 제한합니다. 읽는 쪽은 틱보다 정밀한 도착 시각을 알게 되고, 다른 태스크는 빼앗긴 시간을 알아챌 수 있습니다. 이것은 분석하지 않은 타이밍 채널입니다. +3. 외부 당사자가 이제 태스크 실행 중에 인터럽트를 일으킬 수 있으며, 그 빈도는 바이트에 대해서는 읽는 쪽이, 선로 오류가 난 문자에 대해서는 틱당 256개라는 상한이 제한합니다. 읽는 쪽은 틱보다 정밀한 도착 시각을 알게 되고, 다른 태스크는 빼앗긴 시간을 알아챌 수 있습니다. 이것은 분석하지 않은 타이밍 채널이며, 고정 시간 분할은 이 채널을 닫지 않습니다. 4. 입력은 실행 중인 태스크 뒤에서 기다립니다. 우선순위가 없으므로 지연은 준비된 태스크마다 최대 한 틱이고, 실행 중인 태스크가 두 틱 사이에 CPU를 받았다면 한 틱이 더 붙습니다. 5. 16550 콘솔에는 입력이 없습니다. SBSA UART 경로, FIFO 오버런, 수신 타임아웃 인터럽트는 QEMU에서 실행되지 않으며, 가짜 UART를 쓰는 호스트 테스트(`crates/k0-conin`)가 유일한 검증입니다. UART 원인 없이 발생하는 인터럽트 회선을 끊는 동작도 호스트 테스트로만 검증합니다. 6. 기계에서 폭주 중의 커널 시간을 측정한 테스트는 없습니다. 상한은 게이트와 틱당 개수에서 논증하고 호스트 테스트로 보입니다. 터미널 테스트는 QEMU에서 브레이크를 2000번 보내고, 입력 경로가 끊기지 않고 다시 답하는지만 확인합니다. 이 단계는 QEMU 8.0부터만 실행하므로 CI(QEMU 7.2)에서는 실행되지 않습니다. 그 전의 QEMU는 브레이크를 PL011 수신 FIFO에 넣을 때 깊이를 확인하지 않는데, 커널이 인터럽트를 마스크해 둔 동안 브레이크가 거기에 쌓이기 때문입니다. @@ -289,7 +322,7 @@ $ grep -a 'k0: console drivers' <이미지 파일> - **권장**: 에서 draft advisory를 작성하세요. - **대안**: 메인테이너 에게 메일을 보내세요. 영향을 받는 커밋 해시, 플랫폼(QEMU 머신과 CPU 모델, 하이퍼바이저 또는 보드), 진입 단계(EL1 또는 EL2), 페이지 크기(4 KiB 또는 16 KiB), 부트 로그의 `k0: platform ...` 줄, 재현 방법이 있으면 포함해 주세요. -`v0.1.0` 이하의 격리 공백과, "`main`에서도 여전히 제공하지 않는 것"에 적은 가용성·자원 한계는 이미 알려진 문제이기 때문에 **다시 신고하실 필요는 없습니다**. 현재 `main` 브랜치의 격리 우회는 환영합니다. 예를 들어 한 태스크가 다른 태스크의 메모리나 케이퍼빌리티에 닿는 경우, revoke된 케이퍼빌리티가 계속 동작하는 경우, unmap·revoke·주소 공간 파괴 뒤에도 낡은 매핑이 남는 경우입니다. 서명 오라클에 관한 신고도 환영합니다. 예를 들어 클라이언트에 키가 노출되는 경우, 정책 우회, 엉뚱한 호출자에게 응답이 가는 경우입니다. 직렬 입력 경로와 운영자 터미널에 관한 신고도 환영합니다. 예를 들어 커널을 오동작하게 만드는 바이트 열, 엉뚱한 태스크를 깨우는 경우, 나열한 네 가지를 넘는 운영자 연산입니다. UEFI 로더에 관한 신고도 환영합니다. 예를 들어 펌웨어가 아직 쓰는 메모리를 커널에 넘기게 만드는 메모리 맵이나 디바이스 트리, 일어나야 할 거부가 일어나지 않는 경우입니다. 그 외의 문제, 예를 들어 부팅 시 메모리 맵 검증, 예외 처리, 스케줄러 정책, IPC 상태 기계에 관한 신고는 언제든 환영합니다. +`v0.1.0` 이하의 격리 공백과, "`main`에서도 여전히 제공하지 않는 것"에 적은 가용성·자원 한계는 이미 알려진 문제이기 때문에 **다시 신고하실 필요는 없습니다**. 현재 `main` 브랜치의 격리 우회는 환영합니다. 예를 들어 한 태스크가 다른 태스크의 메모리나 케이퍼빌리티에 닿는 경우, revoke된 케이퍼빌리티가 계속 동작하는 경우, unmap·revoke·주소 공간 파괴 뒤에도 낡은 매핑이 남는 경우입니다. 서명 오라클에 관한 신고도 환영합니다. 예를 들어 클라이언트에 키가 노출되는 경우, 정책 우회, 엉뚱한 호출자에게 응답이 가는 경우입니다. 직렬 입력 경로와 운영자 터미널에 관한 신고도 환영합니다. 예를 들어 커널을 오동작하게 만드는 바이트 열, 엉뚱한 태스크를 깨우는 경우, 나열한 네 가지를 넘는 운영자 연산입니다. UEFI 로더에 관한 신고도 환영합니다. 예를 들어 펌웨어가 아직 쓰는 메모리를 커널에 넘기게 만드는 메모리 맵이나 디바이스 트리, 일어나야 할 거부가 일어나지 않는 경우입니다. 시간 분할에 관한 신고도 환영합니다. 예를 들어 오브젝트를 공유하지 않으면서 다른 도메인의 어느 태스크가 실행되는지 또는 어느 틱에 실행되는지를 바꾸는 태스크, 제어 케이퍼빌리티 없이 정해지는 표나 도메인, 새 경로에서 커널을 정지시키는 시스템 콜 순서입니다. "고정 시간 분할" 절에 나열한 한계는 이미 알려진 것이므로 다시 신고하실 필요가 없습니다. 그 외의 문제, 예를 들어 부팅 시 메모리 맵 검증, 예외 처리, 스케줄러 정책, IPC 상태 기계에 관한 신고는 언제든 환영합니다. ## 범위 diff --git a/USAGE.md b/USAGE.md index f89727b..b871ed3 100644 --- a/USAGE.md +++ b/USAGE.md @@ -87,18 +87,21 @@ The following table lists the lines that an image with a console driver prints, | `root: ... pass` | One group of self-tests passed | | `root: secret at 0x...`, then `k0: task fault ... far 0x...` with the same address | A confined task tried to read memory that only the root task may see, and it was stopped at exactly that address | | `k0: task fault ...` and `k0: unknown syscall 65535, killing task` | Rule violations that the tests cause on purpose. Each one stops only the task that broke the rule. A normal run has exactly 6 `k0: task fault` lines and 1 `k0: unknown syscall` line. An image built with a `vault` feature has 8 `k0: task fault` lines | -| `k0: kernel reserve tables + address space entries = bytes in ranges` | The kernel set aside memory at the top of each range it hands out, for its own page tables and for the list of address spaces. It is printed before the `k0: untyped` lines. On QEMU virt with 512 MiB it reads `262 tables + 130130 address space entries = 0x206000 bytes in 3 ranges`. The entry count depends on the image size | +| `k0: kernel reserve tables + address space entries = bytes in ranges` | The kernel set aside memory at the top of each range it hands out, for its own page tables and for the list of address spaces. It is printed before the `k0: untyped` lines. On QEMU virt with 512 MiB it reads `262 tables + 130124 address space entries = 0x206000 bytes in 3 ranges`. The entry count depends on the image size | | `k0: memory + not handed out ()` | A memory range was too small to hold its own share of that reserve, the share could not be mapped, or the range holds no whole page, so the kernel did not hand the range out. The boot continues. A normal run on QEMU virt does not print it | | `root: timeout tests pass` | The self-tests of IPC timeouts passed | | `root: slice test yield pass` and `root: slice test block pass` | A task that got the CPU between two ticks (by `YIELD`, or after the previous task blocked) was not cut by the first tick it met. They come before `root: preempt test pass` | | `root: preempt test pass` | A task that never yields is still cut by the timer | +| `root: partition refusal pass` | The two system calls of the time partitions refused every wrong request (a wrong capability, a malformed table, a table without the caller's domain, a domain out of range, a task that has already run, a copy of the control capability) | +| `root: partition window pass` | The root task set a time partition table of 9 ticks, let it run one round and found the tasks of the domains in the expected order. It takes about 13 seconds. `root: partition window retry` before it means that the host stalled QEMU for more than a second and the test ran once more | +| `root: partition sealed` | The root task deleted the control capability of the time partitions. From here on the image runs with one domain and nothing can set a table until the next boot | | `root: kernel reserve tests pass` | The self-tests of the kernel reserve passed (300 address spaces alive at once, and frames made from untyped memory across many page table blocks) | | `root: oracle tests pass` | The self-tests of the signing oracle passed. Only an image built with a `vault` feature prints it (see "Signing oracle" below) | | `root: oracle made no key (boot seed has no entropy)` | The vault refused to make a key because the boot seed was too weak. Only an image built with a `vault` feature can print it, and then `root: oracle tests pass` does not follow | | `root: sched tests pass` | The last group of self-tests passed | | `k0: idle (waiting for a timeout)` | Every task was waiting and at least one wait had a time limit, so the kernel waited for the next interrupt instead of stopping. It is printed at most once per boot | | `k0: all tasks stopped (none ready, no timeout pending)` | Every task is waiting and no wait has a time limit. Nothing can wake a task today, so the machine stays idle. A normal run never prints it, and the boot test treats it as a failure. It is printed at most once per boot | -| `k0: tick N` | The kernel is still running | +| `k0: tick N` | The kernel is still running. The lines pause while the partition window test runs (on QEMU virt the log goes from `k0: tick 6` to `k0: tick 19`), because the kernel prints no periodic tick line while a table that names a domain other than the root domain is set or pending | Lines such as `root: FAIL`, `k0: FATAL`, `k0: PANIC` or `k0: EXCEPTION` mean that **something went wrong**. The automatic boot test described under "Testing automatically" checks the whole list for you. @@ -410,9 +413,9 @@ $ tools/qemu-boot-test.sh # boot in QEMU and che $ tools/boot-matrix.sh # boot every supported configuration (builds the 16 KiB, pinned and UEFI loader images too) ``` -- `tools/host-test.sh` runs the 377 host tests (289 on other hosts): small tests of single parts of the kernel (unit tests) as ordinary programs on your computer. It also does **fuzzing**: it feeds the device tree parser and the UEFI loader's planning code random, broken input to find crashes. The 377 are 15 (`k0-abi`), 52 (`k0-cap`), 85 (`k0-boot`), 33 (`k0-efi`), 19 (`k0-conin`), 9 (`k0-slice`, the rule that decides whether a tick cuts the running task, run on a model of the scheduler), 31 (`k0-vault`, which is 20 with Ed25519 and 11 without), 45 (`k0-term`, which is 24 with the vault feature and 21 without) and 44 for each of the two page sizes (`k0-mm`). The memory management tests use ARM instructions, so they run only on an ARM computer (an Apple Silicon Mac or Linux arm64), and the count on other hosts leaves out those 88. -- `tools/qemu-boot-test.sh` boots the kernel and reads the log line by line in a fixed order. It fails on any error line, checks the exact number of intentional fault lines, and stops QEMU when it is done. The root task's timeout tests wait for real timer ticks, so a boot takes about 4 seconds longer than it did before they existed. The time slice test adds two runs of about 4 seconds in total where the preemption test it replaced took about 1. The test also counts the tick lines between `root: teardown tests pass` and `root: timeout tests pass` and wants at least 4, which is how it checks that a timeout does not end early. It prints `boot-test: pass` on success and saves the full log in `target/qemu-boot-test.log`. It takes the machine from the `K0_QEMU_*` variables above. It accepts `K0_BOOT_REUSE=skip` for memory layouts that have no untyped region of the right size, where the root task skips its reuse test. It reads the kernel lines from the **serial port**, so it needs an image with a console driver. For an image without one, see "Testing an image without console" below. If the serial log has no kernel line, it prints a hint about a kernel built without a console feature. -- `tools/boot-matrix.sh` boots the kernel in **each** configuration that K0 calls supported and checks the result. It boots QEMU virt with GICv3 and GICv2 at EL1 and EL2, and also three CPU models, 4 cores, the 16 KiB image, other load addresses, `xlnx-versal-virt`, a pinned image and the images with the signing oracle. It also checks statically that the image does not touch the physical timer. The matrix has 82 rows on a Mac with HVF and 71 in CI. You can name single rows as arguments. CI runs it. +- `tools/host-test.sh` runs the 415 host tests (327 on other hosts): small tests of single parts of the kernel (unit tests) as ordinary programs on your computer. It also does **fuzzing**: it feeds the device tree parser and the UEFI loader's planning code random, broken input to find crashes. The 415 are 15 (`k0-abi`), 54 (`k0-cap`), 85 (`k0-boot`), 33 (`k0-efi`), 19 (`k0-conin`), 9 (`k0-slice`, the rule that decides whether a tick cuts the running task, run on a model of the scheduler), 36 (`k0-part`, the scheduler's decisions under a time partition table and the arithmetic of tick instants, including a comparison with the recorded results of a Lean model), 31 (`k0-vault`, which is 20 with Ed25519 and 11 without), 45 (`k0-term`, which is 24 with the vault feature and 21 without) and 44 for each of the two page sizes (`k0-mm`). The memory management tests use ARM instructions, so they run only on an ARM computer (an Apple Silicon Mac or Linux arm64), and the count on other hosts leaves out those 88. +- `tools/qemu-boot-test.sh` boots the kernel and reads the log line by line in a fixed order. It fails on any error line, checks the exact number of intentional fault lines, and stops QEMU when it is done. The root task's timeout tests wait for real timer ticks, so a boot takes about 4 seconds longer than it did before they existed. The time slice test adds two runs of about 4 seconds in total where the preemption test it replaced took about 1. The time partition test adds about 15 seconds, because it lets a table of 9 ticks run one round, so a boot test now takes about 25 seconds. Just before its verdict it also prints `boot-test: partition window retries: N`, the number of times the window test had to run again because the host stalled QEMU. The script does not judge by that number. The test also counts the tick lines between `root: teardown tests pass` and `root: timeout tests pass` and wants at least 4, which is how it checks that a timeout does not end early. It prints `boot-test: pass` on success and saves the full log in `target/qemu-boot-test.log`. It takes the machine from the `K0_QEMU_*` variables above. It accepts `K0_BOOT_REUSE=skip` for memory layouts that have no untyped region of the right size, where the root task skips its reuse test. It reads the kernel lines from the **serial port**, so it needs an image with a console driver. For an image without one, see "Testing an image without console" below. If the serial log has no kernel line, it prints a hint about a kernel built without a console feature. +- `tools/boot-matrix.sh` boots the kernel in **each** configuration that K0 calls supported and checks the result. It boots QEMU virt with GICv3 and GICv2 at EL1 and EL2, and also three CPU models, 4 cores, the 16 KiB image, other load addresses, `xlnx-versal-virt`, a pinned image and the images with the signing oracle. It also checks statically that the image does not touch the physical timer. The matrix has 82 rows on a Mac with HVF and 71 in CI. You can name single rows as arguments. CI runs it. When the window test of a boot row needed its retry, the matrix runs that row once more and fails it if the second run needed the retry too (`matrix: FAIL (the window test needed its retry in two runs)`). The console rows check the console features. The following table lists the console rows and what they check. @@ -495,6 +498,24 @@ $ K0_QEMU_CPU=max K0_BOOT_REQUIRE='rndr=on|k0: pac=on bti=present pan=on' \ GitHub also runs these tests automatically on every pull request and every push to `main` (CI), on x86-64 and ARM64 Linux, inside sealed build environments (containers) with networking turned off, and runs a longer fuzzing campaign every week. To fuzz the device tree parser yourself or to run exactly what CI runs, see [CONTRIBUTING.md](CONTRIBUTING.md). +### Checking the Lean proofs + +`proofs/lean` holds Lean 4 proofs about a model of the time partition scheduler. They are not part of the three tools above and CI does not run them. What CI does run is the host test that compares the Rust code with the recorded results of the model (in `k0-part`, part of `tools/host-test.sh`). + +> [!IMPORTANT] +> These are proofs about a model, not about the Rust code. [proofs/lean/README.md](proofs/lean/README.md) says what each theorem states and what the model leaves out. + +To check them you need `elan`, the Lean toolchain manager. It fetches the pinned toolchain (`leanprover/lean4:v4.35.0`) the first time, which needs the network once. You can enter the following: + +```sh +$ cd proofs/lean +$ lake build +$ lake env leanchecker K0Part K0Share K0ShareWide K0Bridge K0Close +$ lake exe vectors --check ../../crates/k0-part/src/model_vectors.txt +``` + +`lake build` must end without an error, a warning or a `sorry`. `leanchecker` must print nothing. The last command must end with `scripts: 1600, differing from the model: 0`. + ## When something goes wrong The following table lists what to do for each problem. @@ -506,6 +527,8 @@ The following table lists what to do for each problem. | The terminal stays blank after `cargo run -p k0-kernel` without features | The image has no console driver and prints nothing. Build with `--features console`, or use `cargo virt` | | `runner: this kernel has no console driver and prints nothing here (build with --features console to see output)` | The image was built without a console feature, or the runner found `k0: console drivers [none]` in it. Build with `--features console` to see output, or read the boot log from memory | | `boot-test: the serial log has no kernel line` | The same cause: a kernel built without a console feature writes nothing to the serial port. Build with `--features console`, or judge the log in guest memory with `K0_BOOT_MEMLOG=` | +| `root: partition window retry` appears, or `matrix: ran the window test twice, running the row again` | The host stalled QEMU for more than a second during the time partition test, so a tick was skipped and the test ran once more. One retry is not a failure. If it happens in two runs in a row, treat it as a defect. Keep the computer from sleeping during a long run | +| `root: FAIL partition: window order wrong twice` | The time partition window test found the wrong order of events in both of its runs. The line `root: partition window log ` before it shows what it saw, and [design/en/scheduling.md](design/en/scheduling.md#the-partition-test-at-boot) explains the test | | `boot-test` fails on a line that starts with `k0: all tasks` | Every task is waiting and no wait has a time limit, so nothing can wake a task. In the normal self-tests this does not happen. If you changed the root task, give each wait a timeout | | `k0: memory + not handed out ()` appears in the boot log | The kernel found a memory range that is too small for its own reserve, whose reserve it could not map, or that holds no whole page. It left that range out and kept booting. The range is simply not usable as untyped memory. Check the memory size and the load address you gave QEMU | | `root: oracle made no key (boot seed has no entropy)` appears, or `root: oracle tests pass` is missing | The boot seed held fewer than 32 `rng-seed` bytes and no RNDR. Use a machine whose device tree has an `rng-seed`, as QEMU virt does, or a CPU with RNDR (`K0_QEMU_CPU=max`) | diff --git a/USAGE_KR.md b/USAGE_KR.md index 373b600..43d2784 100644 --- a/USAGE_KR.md +++ b/USAGE_KR.md @@ -87,18 +87,21 @@ $ grep -a 'k0: console drivers' <이미지 파일> | `root: ... pass` | 자가 테스트 한 묶음이 통과함 | | `root: secret at 0x...` 다음에 같은 주소의 `k0: task fault ... far 0x...` | 격리된 태스크가 루트 태스크만 볼 수 있는 메모리를 읽으려다 정확히 그 주소에서 멈춤 | | `k0: task fault ...`와 `k0: unknown syscall 65535, killing task` | 테스트가 일부러 일으킨 규칙 위반. 매번 규칙을 어긴 태스크만 멈춤. 정상 실행에서는 `k0: task fault` 줄이 정확히 6개, `k0: unknown syscall` 줄이 1개 나옴. `vault` feature를 포함해 빌드한 이미지에서는 `k0: task fault` 줄이 8개 나옴 | -| `k0: kernel reserve tables + address space entries = bytes in ranges` | 커널이 넘겨 주는 메모리 범위마다 맨 위에 자기 페이지 테이블과 주소 공간 목록용 메모리를 따로 떼어 둠. `k0: untyped` 줄보다 먼저 출력됨. QEMU virt 512 MiB에서는 `262 tables + 130130 address space entries = 0x206000 bytes in 3 ranges`로 나오며, 항목 수는 이미지 크기에 따라 달라짐 | +| `k0: kernel reserve tables + address space entries = bytes in ranges` | 커널이 넘겨 주는 메모리 범위마다 맨 위에 자기 페이지 테이블과 주소 공간 목록용 메모리를 따로 떼어 둠. `k0: untyped` 줄보다 먼저 출력됨. QEMU virt 512 MiB에서는 `262 tables + 130124 address space entries = 0x206000 bytes in 3 ranges`로 나오며, 항목 수는 이미지 크기에 따라 달라짐 | | `k0: memory + not handed out ()` | 메모리 범위가 너무 작아 그 예비 몫을 담지 못하거나, 몫을 매핑하지 못하거나, 온전한 페이지가 하나도 없어서 커널이 그 범위를 넘겨 주지 않음. 부팅은 계속됨. QEMU virt의 정상 실행에서는 나오지 않음 | | `root: timeout tests pass` | IPC 타임아웃 자가 테스트가 통과함 | | `root: slice test yield pass`, `root: slice test block pass` | 두 틱 사이에 CPU를 받은 태스크(`YIELD` 또는 앞선 태스크가 기다림)가 처음 만난 틱에 끊기지 않았음. `root: preempt test pass`보다 앞에 나옴 | | `root: preempt test pass` | 양보하지 않는 태스크는 여전히 타이머가 끊음 | +| `root: partition refusal pass` | 시간 분할의 두 시스템 콜이 잘못된 요청을 모두 거부함(틀린 케이퍼빌리티, 형식이 틀린 표, 호출자의 도메인이 없는 표, 범위 밖의 도메인, 이미 실행된 태스크, 제어 케이퍼빌리티의 복사) | +| `root: partition window pass` | 루트 태스크가 9틱짜리 시간 분할 표를 정해 한 바퀴 돌렸고, 각 도메인의 태스크가 기대한 순서로 실행됨. 약 13초가 걸림. 이 줄 앞에 `root: partition window retry`가 나오면 호스트가 QEMU를 1초 넘게 멈춰 세워서 테스트가 한 번 더 실행된 것임 | +| `root: partition sealed` | 루트 태스크가 시간 분할의 제어 케이퍼빌리티를 삭제함. 여기부터 이미지는 도메인 하나로 실행되고, 다음 부팅까지 어떤 것도 표를 정할 수 없음 | | `root: kernel reserve tests pass` | 커널 예비 공간 자가 테스트가 통과함(주소 공간 300개를 동시에 유지, 여러 페이지 테이블 블록에 걸친 untyped 메모리에서 프레임 생성) | | `root: oracle tests pass` | 서명 오라클 자가 테스트가 통과함. `vault` feature를 포함해 빌드한 이미지만 출력함(뒤의 "서명 오라클" 참고) | | `root: oracle made no key (boot seed has no entropy)` | 부트 시드가 약해서 볼트가 키 생성을 거부함. `vault` feature를 포함해 빌드한 이미지만 출력할 수 있으며, 이때 `root: oracle tests pass`는 뒤따르지 않음 | | `root: sched tests pass` | 마지막 자가 테스트 묶음이 통과함 | | `k0: idle (waiting for a timeout)` | 모든 태스크가 기다리는 중이고 시간 제한이 있는 대기가 하나 이상이어서, 커널이 멈추지 않고 다음 인터럽트를 기다림. 부팅당 최대 한 번 출력됨 | | `k0: all tasks stopped (none ready, no timeout pending)` | 모든 태스크가 기다리는 중이고 시간 제한이 있는 대기가 없음. 지금은 태스크를 깨울 수 있는 것이 없어서 머신은 유휴 상태로 남음. 정상 실행에서는 나오지 않고, 부팅 테스트는 이 줄을 실패로 처리함. 부팅당 최대 한 번 출력됨 | -| `k0: tick N` | 커널이 아직 돌고 있음 | +| `k0: tick N` | 커널이 아직 돌고 있음. 시간 분할 창 테스트가 실행되는 동안에는 이 줄이 잠시 멈춤(QEMU virt에서는 로그가 `k0: tick 6`에서 `k0: tick 19`로 넘어감). 루트 도메인이 아닌 도메인이 적힌 시간 분할 표가 정해져 있는 동안에는 커널이 주기적인 틱 줄을 출력하지 않기 때문임 | `root: FAIL`, `k0: FATAL`, `k0: PANIC`, `k0: EXCEPTION` 같은 줄은 **문제가 생겼다는 뜻**입니다. "자동 테스트"에서 설명하는 부팅 테스트가 전체 목록을 대신 확인해 줍니다. @@ -410,9 +413,9 @@ $ tools/qemu-boot-test.sh # QEMU에서 부팅하 $ tools/boot-matrix.sh # 지원하는 구성을 전부 부팅(16 KiB 이미지, 고정 이미지, UEFI 로더 이미지도 빌드함) ``` -- `tools/host-test.sh`는 호스트 테스트 377개를 실행합니다(그 밖의 호스트에서는 289개). 커널의 부분 하나하나를 내 컴퓨터에서 일반 프로그램처럼 돌리는 작은 테스트(단위 테스트)입니다. **퍼징**도 합니다. 디바이스 트리 파서와 UEFI 로더의 계획 코드에 무작위로 망가뜨린 입력을 넣어 충돌을 찾는 방법입니다. 377개는 `k0-abi` 15개, `k0-cap` 52개, `k0-boot` 85개, `k0-efi` 33개, `k0-conin` 19개, `k0-slice` 9개(틱이 실행 중인 태스크를 끊을지 정하는 규칙을 스케줄러 모델로 검사), `k0-vault` 31개(Ed25519를 포함하면 20개, 없으면 11개), `k0-term` 45개(`vault` feature를 포함하면 24개, 없으면 21개), `k0-mm` 44개씩 두 페이지 크기분입니다. 메모리 관리 테스트는 ARM 명령을 사용하므로 ARM 컴퓨터(Apple Silicon Mac이나 Linux arm64)에서만 돌고, 그 밖의 호스트의 개수는 그 88개를 뺀 것입니다. -- `tools/qemu-boot-test.sh`는 커널을 부팅하고, 로그를 정해진 순서대로 한 줄씩 확인합니다. 에러 줄이 하나라도 나오면 실패하고, 일부러 일으킨 폴트 줄의 개수를 정확히 맞춘 뒤 QEMU를 끕니다. 루트 태스크의 타임아웃 테스트는 실제 타이머 틱을 기다리므로, 부팅 한 번이 그 테스트가 생기기 전보다 약 4초 더 걸립니다. 시간 조각 테스트는 두 번 실행해 합계 약 4초가 걸리며, 이를 대신한 이전 선점 테스트는 약 1초가 걸렸습니다. `root: teardown tests pass`와 `root: timeout tests pass` 사이의 틱 줄도 세어 4개 이상을 요구하는데, 이것이 타임아웃이 일찍 끝나지 않는지 확인하는 방법입니다. 성공하면 `boot-test: pass`를 출력하고 전체 로그를 `target/qemu-boot-test.log`에 남깁니다. 머신은 앞의 `K0_QEMU_*` 변수에서 가져옵니다. 맞는 크기의 untyped 영역이 없는 메모리 배치에서는 루트 태스크가 재사용 시험을 건너뛰므로, 그때는 `K0_BOOT_REUSE=skip`을 받습니다. 커널 줄을 **직렬 포트**에서 읽으므로 콘솔 드라이버가 있는 이미지가 필요합니다. 콘솔 없는 이미지는 뒤의 "콘솔 없는 이미지 시험"을 보세요. 직렬 로그에 커널 줄이 하나도 없으면 콘솔 feature 없이 빌드한 커널이 아닌지 알려 주는 힌트를 출력합니다. -- `tools/boot-matrix.sh`는 K0가 지원한다고 말하는 **구성마다** 커널을 부팅해서 결과를 확인합니다. GICv3와 GICv2의 QEMU virt를 EL1과 EL2에서 부팅하고, CPU 모델 세 가지, 코어 4개, 16 KiB 이미지, 다른 적재 주소, `xlnx-versal-virt`, 고정 이미지, 서명 오라클이 있는 이미지도 부팅합니다. 이미지가 물리 타이머를 건드리지 않는지는 정적으로 검사합니다. 행렬은 HVF가 있는 Mac에서 82행, CI에서 71행입니다. 행 이름을 인자로 주면 그 행만 돌립니다. CI가 이것을 실행합니다. +- `tools/host-test.sh`는 호스트 테스트 415개를 실행합니다(그 밖의 호스트에서는 327개). 커널의 부분 하나하나를 내 컴퓨터에서 일반 프로그램처럼 돌리는 작은 테스트(단위 테스트)입니다. **퍼징**도 합니다. 디바이스 트리 파서와 UEFI 로더의 계획 코드에 무작위로 망가뜨린 입력을 넣어 충돌을 찾는 방법입니다. 415개는 `k0-abi` 15개, `k0-cap` 54개, `k0-boot` 85개, `k0-efi` 33개, `k0-conin` 19개, `k0-slice` 9개(틱이 실행 중인 태스크를 끊을지 정하는 규칙을 스케줄러 모델로 검사), `k0-part` 36개(시간 분할 표가 있을 때의 스케줄러 판정과 틱 시각의 산술을 검사하고, Lean 모델의 기록된 결과와도 비교), `k0-vault` 31개(Ed25519를 포함하면 20개, 없으면 11개), `k0-term` 45개(`vault` feature를 포함하면 24개, 없으면 21개), `k0-mm` 44개씩 두 페이지 크기분입니다. 메모리 관리 테스트는 ARM 명령을 사용하므로 ARM 컴퓨터(Apple Silicon Mac이나 Linux arm64)에서만 돌고, 그 밖의 호스트의 개수는 그 88개를 뺀 것입니다. +- `tools/qemu-boot-test.sh`는 커널을 부팅하고, 로그를 정해진 순서대로 한 줄씩 확인합니다. 에러 줄이 하나라도 나오면 실패하고, 일부러 일으킨 폴트 줄의 개수를 정확히 맞춘 뒤 QEMU를 끕니다. 루트 태스크의 타임아웃 테스트는 실제 타이머 틱을 기다리므로, 부팅 한 번이 그 테스트가 생기기 전보다 약 4초 더 걸립니다. 시간 조각 테스트는 두 번 실행해 합계 약 4초가 걸리며, 이를 대신한 이전 선점 테스트는 약 1초가 걸렸습니다. 시간 분할 테스트는 9틱짜리 표를 한 바퀴 돌리므로 약 15초를 더하고, 그래서 부팅 테스트 한 번은 이제 약 25초가 걸립니다. 판정 직전에는 `boot-test: partition window retries: N`도 출력합니다. 호스트가 QEMU를 멈춰 세워서 창 테스트를 다시 실행해야 했던 횟수입니다. 스크립트는 이 수로 판정하지 않습니다. `root: teardown tests pass`와 `root: timeout tests pass` 사이의 틱 줄도 세어 4개 이상을 요구하는데, 이것이 타임아웃이 일찍 끝나지 않는지 확인하는 방법입니다. 성공하면 `boot-test: pass`를 출력하고 전체 로그를 `target/qemu-boot-test.log`에 남깁니다. 머신은 앞의 `K0_QEMU_*` 변수에서 가져옵니다. 맞는 크기의 untyped 영역이 없는 메모리 배치에서는 루트 태스크가 재사용 시험을 건너뛰므로, 그때는 `K0_BOOT_REUSE=skip`을 받습니다. 커널 줄을 **직렬 포트**에서 읽으므로 콘솔 드라이버가 있는 이미지가 필요합니다. 콘솔 없는 이미지는 뒤의 "콘솔 없는 이미지 시험"을 보세요. 직렬 로그에 커널 줄이 하나도 없으면 콘솔 feature 없이 빌드한 커널이 아닌지 알려 주는 힌트를 출력합니다. +- `tools/boot-matrix.sh`는 K0가 지원한다고 말하는 **구성마다** 커널을 부팅해서 결과를 확인합니다. GICv3와 GICv2의 QEMU virt를 EL1과 EL2에서 부팅하고, CPU 모델 세 가지, 코어 4개, 16 KiB 이미지, 다른 적재 주소, `xlnx-versal-virt`, 고정 이미지, 서명 오라클이 있는 이미지도 부팅합니다. 이미지가 물리 타이머를 건드리지 않는지는 정적으로 검사합니다. 행렬은 HVF가 있는 Mac에서 82행, CI에서 71행입니다. 행 이름을 인자로 주면 그 행만 돌립니다. CI가 이것을 실행합니다. 부팅 행의 창 테스트가 재시도를 했으면 행렬은 그 행을 한 번 더 돌리고, 두 번째 실행도 재시도를 했으면 그 행을 실패로 처리합니다(`matrix: FAIL (the window test needed its retry in two runs)`). 콘솔 행은 콘솔 feature를 확인합니다. 다음 표는 콘솔 행과 확인하는 내용입니다. @@ -495,6 +498,24 @@ $ K0_QEMU_CPU=max K0_BOOT_REQUIRE='rndr=on|k0: pac=on bti=present pan=on' \ GitHub도 풀 리퀘스트와 `main` 푸시가 있을 때마다 이 테스트를 자동으로 돌립니다(CI). x86-64와 ARM64 Linux에서, 네트워크를 끈 밀폐된 빌드 환경(컨테이너) 안에서 돌리고, 매주 더 긴 퍼징도 돌립니다. 디바이스 트리 파서를 직접 퍼징하거나 CI와 똑같이 돌리는 방법은 [CONTRIBUTING_KR.md](CONTRIBUTING_KR.md)에 있습니다. +### Lean 증명 확인 + +`proofs/lean`에는 시간 분할 스케줄러의 모델에 대한 Lean 4 증명이 들어 있습니다. 앞의 세 도구에 포함되지 않으며 CI도 실행하지 않습니다. CI가 실행하는 것은 Rust 코드를 모델의 기록된 결과와 비교하는 호스트 테스트입니다(`k0-part`에 있으며 `tools/host-test.sh`의 일부). + +> [!IMPORTANT] +> 이것은 모델에 대한 증명이지 Rust 코드에 대한 증명이 아닙니다. 각 정리가 무엇을 진술하고 모델이 무엇을 빼놓았는지는 [proofs/lean/README.md](proofs/lean/README.md)(영문)에 있습니다. + +확인하려면 Lean 툴체인 관리자 `elan`이 필요합니다. `elan`은 처음 실행할 때 고정된 툴체인(`leanprover/lean4:v4.35.0`)을 내려받으므로 네트워크가 한 번 필요합니다. 다음과 같이 입력할 수 있습니다. + +```sh +$ cd proofs/lean +$ lake build +$ lake env leanchecker K0Part K0Share K0ShareWide K0Bridge K0Close +$ lake exe vectors --check ../../crates/k0-part/src/model_vectors.txt +``` + +`lake build`는 에러, 경고, `sorry` 없이 끝나야 합니다. `leanchecker`는 아무것도 출력하지 않아야 합니다. 마지막 명령은 `scripts: 1600, differing from the model: 0`으로 끝나야 합니다. + ## 문제가 생기면 다음 표는 증상별 해결 방법입니다. @@ -506,6 +527,8 @@ GitHub도 풀 리퀘스트와 `main` 푸시가 있을 때마다 이 테스트를 | feature 없이 `cargo run -p k0-kernel`을 하면 터미널이 빈 채로 있음 | 이미지에 콘솔 드라이버가 없어서 아무것도 출력하지 않습니다. `--features console`로 빌드하거나 `cargo virt`를 사용하세요 | | `runner: this kernel has no console driver and prints nothing here (build with --features console to see output)` | 이미지를 콘솔 feature 없이 빌드했거나, 러너가 이미지에서 `k0: console drivers [none]` 줄을 찾았습니다. 출력을 보려면 `--features console`로 빌드하거나 메모리에서 부트 로그를 읽으세요 | | `boot-test: the serial log has no kernel line` | 같은 원인입니다. 콘솔 feature 없이 빌드한 커널은 직렬 포트에 아무것도 쓰지 않습니다. `--features console`로 빌드하거나 `K0_BOOT_MEMLOG=<적재 주소>`로 게스트 메모리의 로그를 판정하세요 | +| `root: partition window retry`가 나오거나 `matrix: ran the window test twice, running the row again`이 나옴 | 시간 분할 테스트 도중에 호스트가 QEMU를 1초 넘게 멈춰 세워서 틱 하나를 건너뛰었고, 테스트가 한 번 더 실행됐습니다. 재시도 한 번은 실패가 아닙니다. 두 번의 실행에서 연달아 일어나면 결함으로 보세요. 긴 실행 동안에는 컴퓨터가 잠들지 않게 하세요 | +| `root: FAIL partition: window order wrong twice` | 시간 분할 창 테스트가 두 번의 실행 모두에서 사건의 순서가 틀린 것을 봤습니다. 그 앞의 `root: partition window log ` 줄이 테스트가 본 것을 보여 주고, 테스트는 [design/kr/scheduling_KR.md](design/kr/scheduling_KR.md#부팅-때의-시간-분할-테스트)에서 설명합니다 | | `boot-test`가 `k0: all tasks`로 시작하는 줄에서 실패함 | 모든 태스크가 기다리는 중인데 시간 제한이 있는 대기가 없어서 태스크를 깨울 수 있는 것이 없습니다. 기본 자가 테스트에서는 일어나지 않습니다. 루트 태스크를 바꿨다면 대기마다 타임아웃을 지정하세요 | | 부트 로그에 `k0: memory + not handed out ()`가 나옴 | 커널이 자기 예비 공간을 담기에 너무 작거나, 그 몫을 매핑하지 못하거나, 온전한 페이지가 하나도 없는 메모리 범위를 찾았습니다. 그 범위를 제외하고 부팅을 계속했으며, 해당 범위는 untyped 메모리로 쓸 수 없습니다. QEMU에 준 메모리 크기와 적재 주소를 확인하세요 | | `root: oracle made no key (boot seed has no entropy)`가 나오거나 `root: oracle tests pass`가 없음 | 부트 시드에 `rng-seed` 바이트가 32개보다 적고 RNDR도 없었음. QEMU virt처럼 디바이스 트리에 `rng-seed`가 있는 머신이나 RNDR이 있는 CPU(`K0_QEMU_CPU=max`)를 사용하세요 | diff --git a/assets/exception-paths.svg b/assets/exception-paths.svg index ace34e4..f26d63c 100644 --- a/assets/exception-paths.svg +++ b/assets/exception-paths.svg @@ -64,7 +64,7 @@ Like a system call Acknowledge - Timer: re-arm 1 s, tick + Timer: arm the next tick, tick k0_preempt Expires timeouts first diff --git a/assets/exception-paths_KR.svg b/assets/exception-paths_KR.svg index 3d7fa43..83446d1 100644 --- a/assets/exception-paths_KR.svg +++ b/assets/exception-paths_KR.svg @@ -64,7 +64,7 @@ 시스템 콜과 같은 방식 인터럽트 확인 - 타이머: 1초 뒤 재설정, tick + 타이머: 다음 틱 설정, tick k0_preempt 먼저 타임아웃 만료 diff --git a/assets/time-partitions.svg b/assets/time-partitions.svg new file mode 100644 index 0000000..4536618 --- /dev/null +++ b/assets/time-partitions.svg @@ -0,0 +1,84 @@ + + Time partition windows and the guard + A table of three entries gives domain 1 one tick, domain 0 one tick and domain 2 two ticks, and then repeats. A domain runs only in its windows, and when it has nothing ready the CPU waits. Before a tick that changes the domain, the timer interrupt is taken one fortieth of a tick early, the kernel does the switch work and holds, and the next domain starts at the tick instant. + + + + A table of three entries, repeated + (domain 1, 1 tick) (domain 0, 1 tick) (domain 2, 2 ticks) + + + a task of the domain runs + + nothing ready in the domain: the CPU waits + + guard before a change of domain + + + domain 1 + + + + domain 0 + + CPU waits + + + + domain 2 + one window of 2 ticks + + + + domain 1 + + + + + + + + + tick n + n + 1 + n + 2 + n + 3 (same domain) + n + 4 + n + 5 + + + + + One change of domain, enlarged + + a task of domain 1 runs + + switch work + + hold + + a task of domain 0 runs + + + + + guard: 1/40 of a tick (25 ms) + timer interrupt, taken early + tick instant: the next domain starts + + Switch work: the tick rule is applied to the running task and it is parked in its own queue, the TLB is flushed, + the due waiters of the next domain are woken and its first task is installed. Then the kernel holds. + diff --git a/assets/time-partitions_KR.svg b/assets/time-partitions_KR.svg new file mode 100644 index 0000000..4499dc5 --- /dev/null +++ b/assets/time-partitions_KR.svg @@ -0,0 +1,84 @@ + + 시간 분할의 창과 보호 구간 + 항목 셋짜리 표가 도메인 1에 1틱, 도메인 0에 1틱, 도메인 2에 2틱을 주고 되풀이됩니다. 도메인은 자기 창에서만 실행되고, 준비된 태스크가 없으면 CPU는 기다립니다. 도메인이 바뀌는 틱 앞에서는 타이머 인터럽트를 틱의 40분의 1만큼 일찍 받아 커널이 전환 작업을 마치고 기다리며, 다음 도메인은 틱 시각에 시작합니다. + + + + 항목 셋짜리 표, 되풀이됨 + (도메인 1, 1틱) (도메인 0, 1틱) (도메인 2, 2틱) + + + 그 도메인의 태스크가 실행됨 + + 도메인에 준비된 태스크 없음: CPU는 기다림 + + 도메인이 바뀌기 전의 보호 구간 + + + 도메인 1 + + + + 도메인 0 + + CPU 대기 + + + + 도메인 2 + 2틱짜리 창 하나 + + + + 도메인 1 + + + + + + + + + 틱 n + n + 1 + n + 2 + n + 3 (같은 도메인) + n + 4 + n + 5 + + + + + 도메인이 바뀌는 자리 하나를 확대 + + 도메인 1의 태스크 실행 + + 전환 작업 + + 대기 + + 도메인 0의 태스크 실행 + + + + + 보호 구간: 틱의 1/40 (25 ms) + 일찍 받은 타이머 인터럽트 + 틱 시각: 다음 도메인이 시작 + + 전환 작업: 실행 중이던 태스크에 틱 규칙을 적용해 자기 도메인의 큐에 세우고, TLB를 비우고, + 다음 도메인의 기한이 지난 대기자를 깨우고 첫 태스크를 설치합니다. 그다음 커널은 틱 시각까지 기다립니다. + diff --git a/ci/threat_model.md b/ci/threat_model.md index e960cc9..cbedf2e 100644 --- a/ci/threat_model.md +++ b/ci/threat_model.md @@ -10,7 +10,9 @@ Trust boundaries, from least to most trusted: 1. **EL0 code via system calls (`svc`).** Every register a task passes to the kernel is attacker controlled: capability slot indices, virtual addresses, permission bits, sizes, object types, badges and message words. This is the primary attack surface. Entry path: `crates/k0-arch/src/vectors.S` (`__lower_common`) -> `crates/k0-arch/src/usermode.rs` (`el0_sync`) -> `kernel/src/syscall.rs` (`k0_syscall` and the `sys_*` functions). Slot arguments are resolved only in the calling task's own CNode. 2. **EL0 faults.** Data and instruction aborts, undefined instructions, trapped system register and FP/SIMD accesses, `brk` and alignment faults all reach `k0_fault` in `kernel/src/syscall.rs`, which must only kill the faulting task. -3. **Timer interrupts** taken at EL1 and from EL0 (`irq_current`, `irq_lower`), which drive preemption in `crates/k0-sched` (the decision whether a tick cuts the running task is `crates/k0-slice`, called through `on_tick`) and the expiry of IPC timeouts (`k0_ipc::expire_timeouts`, run on every tick, also from the idle loop). +3. **Timer interrupts** taken at EL1 and from EL0 (`irq_current`, `irq_lower`), which drive preemption, the time partition table and the expiry of IPC timeouts. The tick number is computed from the counter (`k0_part::clock::fire`, called from `timer_tick` in `crates/k0-arch/src/irq.rs`), so a late handler skips numbers. Every scheduling decision is in `crates/k0-part` (type `Core`: which domain runs at a tick, and, with the tick rule of `crates/k0-slice`, whether the tick cuts the running task). `crates/k0-sched` holds the queues around it and is called through `on_tick` from EL0 and `poll` from the wait loop. `k0_ipc::expire_timeouts` runs for the running domain only, at every tick of its window and from the wait loop. Before a tick that changes the domain the timer is armed 25 ms early (`guard_next`), and every return from an exception to EL0 ends in `k0_leave` in `kernel/src/syscall.rs`, which checks the task and holds until the tick instant (`hold_until_due`). + + The two system calls of the time partitions, `PART_SET_TABLE` and `PART_SET_DOMAIN` (`sys_part_set_table`, `sys_part_set_domain`), take their arguments in registers only. They need the capability `PartCtl`, which the root task holds in slot 5 until it deletes it at the end of its self-tests (`partition::seal`). The table decoder is `Table::decode` in `crates/k0-part/src/lib.rs`. 4. **The device tree blob (DTB)** that the boot chain passes in `x0`. Nothing reads it before the MMU is on. `kernel_main` in `kernel/src/main.rs` maps it read-only (`map_dtb`), then `crates/k0-boot/src/fdt.rs` reads the memory map and `crates/k0-boot/src/platform.rs` finds the console, the interrupt controller and the timer interrupt, both on the shared walker `crates/k0-boot/src/fdt/walk.rs`. The results become the physical memory map (`k0_cap::bootstrap`) and the device mappings, after `Platform::validate` has checked the devices against the memory map (`bring_up_platform` in `kernel/src/main.rs`). The boot chain is trusted to load an authentic kernel image, but the DTB code must still be total: no panic, no out-of-bounds read, no integer overflow on any input, and no device range that overlaps memory handed to user space. 5. **The root task image** is embedded in the kernel at build time together with its SHA-256 (`crates/k0-boot/build.rs`, `verify_root_task`). It is part of the trusted computing base today. The hash detects corruption, not a malicious image; signature verification is a documented TODO. @@ -30,7 +32,7 @@ Highest value, all in scope: - `crates/k0-mm`: page table construction, the table pool (`Pool::map_page` and its rollback), the boot-time reserve of alias tables and address space entries (`alias_tables_for`, `reserve_tables`), W^X enforcement, user mapping validation, the user page table walkers and the address space registry (id and generation per address space, stale mapping records). - `crates/k0-arch`: exception vectors and user context save/restore (`vectors.S`, `usermode.rs`), hardening (`hardening.rs`: PAC, BTI, PAN, `CPACR_EL1`), the GICv2 and GICv3 drivers and the timer (`irq.rs`), the console drivers and the boot log (`earlycon.rs`, `earlycon/uart.rs`), cache and TLB maintenance. The entry code and the EL2 setup are in `kernel/src/arch/aarch64/boot.S`. - `crates/k0-ipc`: endpoint state machine, send, receive, call, reply, `abort_reply`. -- `crates/k0-sched` and `crates/k0-task`: run queue, `kill_current`, TCB state, the list of timed waiters (`arm_timeout`, `disarm_timeout`, `expired`). +- `crates/k0-part`, `crates/k0-sched` and `crates/k0-task`: the scheduling decisions and the table decoder (`Core`, `Table::decode`), the arithmetic of tick instants (`clock`), one ready queue and one list of timed waiters per domain (`arm_timeout`, `disarm_timeout`, `expired`), `kill_current`, TCB state including the domain byte. Reports that are welcome: a task that runs outside the window of its domain, a task that changes which task of another domain runs or at which tick without an object shared with it, a table or a domain set without `PartCtl`, a copy of `PartCtl`, and a system call sequence that reaches a `k0: FATAL` on these paths (for example `returning to a task outside its window`, `task queued outside its domain`, `timeout list corrupt`). - `crates/k0-boot`: FDT walker and memory parser, platform discovery and validation (`platform.rs`), the boot window search (`boot_window` in `window.rs`, shared by the kernel and the loader), root task flattening and verification at build time and at boot. - `crates/k0-abi`: system call numbers and ABI structures shared with user space. - `crates/k0-efi` and `loader/`: the memory policy (`memmap.rs`: only `EfiConventionalMemory`, `EfiLoaderCode` and `EfiLoaderData` with the WB attribute and without RUNTIME, SP or NV are RAM; overlaps and unknown types are not RAM; the firmware device tree's own memory nodes, reservations and discovered devices are cut out), the device tree rewriter (`fdtw.rs`), the independent verifier (`verify.rs`), the composition and self-check (`prepare.rs`), the image header check (`image.rs`), the UEFI bindings and flow (`loader/src/efi.rs`, `load.rs`), the `ExitBootServices` retry, wiping and freeing on a refusal, the entropy handling, and the cache flush, MMU-off trampoline and jump (`handoff.rs`). @@ -50,10 +52,10 @@ Lower value: - Build: `cargo build -p k0-kernel --features console --offline` (generic 4 KiB image with console, dev profile with debug info; `panic = "abort"` in every profile). Input and output are Cargo features that only add and are never in `default`, so every command names them. The operator terminal image is `cargo build -p k0-kernel --features console,terminal,vault-ed25519`, and `cargo run -p k0-kernel --features console,terminal,vault-ed25519` boots it under QEMU with the serial port on the terminal (QEMU's own escape key is Ctrl-A, so it never reaches K0 there). `tools/term-test.py ` boots an image with QEMU's serial port on pipes and runs a scripted session (every command and error, a line that is too long, 200 kB without a line end, 2000 lines in a row, a serial break), and `tools/qemu-boot-test.sh` takes `K0_BOOT_INPUT=on|off` and `K0_BOOT_SERVICE=vault|plain|none`. `cargo build -p k0-kernel --offline` builds an image without console: it has no UART driver, never maps the console page and prints nothing on the serial port, and `tools/qemu-boot-test.sh` cannot judge it from the serial log (it prints a hint). All feature sets write the same ELF path, so give an image without console its own directory, for example `--target-dir target/quiet`. The 16 KiB image is `cargo build -p k0-kernel --offline --no-default-features --features granule-16k,console --target-dir target/g16`. It boots only on a CPU model with 16 KiB pages: `K0_QEMU_CPU=max tools/qemu-boot-test.sh target/g16/aarch64-unknown-none-softfloat/debug/k0-kernel`. `grep -a 'k0: console drivers' ` tells which I/O an image was built with. - Run: `tools/qemu-virt-runner.sh target/aarch64-unknown-none-softfloat/debug/k0-kernel`, which is what `cargo virt` (alias of `cargo run -p k0-kernel --features console`) does. A plain `cargo run -p k0-kernel` boots the image without console, and the runner then prints `runner: this kernel has no console driver and prints nothing here (build with --features console to see output)`. It converts the ELF to a raw image with `llvm-objcopy` and boots `qemu-system-aarch64 -machine virt,gic-version=3 -cpu cortex-a72 -smp 1 -m 512M -nographic`. `K0_QEMU_MACHINE`, `K0_QEMU_CPU`, `K0_QEMU_SMP` and `K0_QEMU_MEM` change the machine, for example `K0_QEMU_MACHINE=virt,gic-version=2` or `K0_QEMU_MACHINE=virt,gic-version=3,virtualization=on` (entry at EL2). `tools/boot-matrix.sh` runs every configuration that K0 calls supported. The kernel never exits: once the root task finishes its self-tests it yields forever and an image with a console driver prints `k0: tick N` on the console once a second (every image logs only the first 4 tick lines in the boot log). Wrap every run in `timeout`, or use `tools/qemu-boot-test.sh`, which checks the expected log lines in order, requires an exact number of `k0: task fault` lines and exactly one `k0: unknown syscall` line, and stops QEMU once they appear. -- A healthy boot log is in `/src/bootcheck.log`, captured when this image was built. The lines that matter are `k0: w^x checks pass`, `k0: user w^x checks pass`, `root: retype/map tests pass`, `root: child exit test pass`, `root: ipc tests pass`, `root: fault isolation tests pass`, `root: preempt test pass`, `root: isolation tests pass`, `root: violation tests pass`, `root: teardown tests pass`, `root: timeout tests pass`, `root: revocation tests pass`, `root: kernel reserve tests pass` and `root: sched tests pass`. Every image also prints `k0: dtb seeds wiped B` (40B on QEMU virt) and `root: boot seed from rng-seed bytes ...`. An image built with the feature `vault` also prints `root: oracle tests pass` and two more `k0: task fault` lines (8 instead of 6). An image built with the feature `terminal` shows two more `k0: task fault` lines than the same image without it (the hostile wiring checks: 8 in total without `vault`, 10 with it), `root: terminal wiring holds` and `root: service started`. An image with `console-input` prints `k0: console input on (pl011 irq 33)` or `k0: console input off ()` and `root: console input tests pass`. When a task first reads console input the `k0: tick N` lines stop after `k0: tick lines off (console input in use)`. -- Reproducers: the root task (`userspace/root-task/src/main.rs`) is the only EL0 image and already contains the test harness and thin `sys*` wrappers around `svc`. Add a test there; when the reproducer needs its own thread, build a task with its own CNode and address space (`RETYPE`, `TCB_CONFIGURE`, `TCB_RESUME`), which then runs code from the root task image, rebuild and run. `crates/k0-boot/build.rs` rebuilds and re-embeds the root task automatically. +- A healthy boot log is in `/src/bootcheck.log`, captured when this image was built. The lines that matter are `k0: w^x checks pass`, `k0: user w^x checks pass`, `root: retype/map tests pass`, `root: child exit test pass`, `root: ipc tests pass`, `root: fault isolation tests pass`, `root: preempt test pass`, `root: partition refusal pass`, `root: partition window pass`, `root: isolation tests pass`, `root: violation tests pass`, `root: teardown tests pass`, `root: timeout tests pass`, `root: revocation tests pass`, `root: kernel reserve tests pass`, `root: partition sealed` and `root: sched tests pass`. The partition window test lets a table of 9 ticks run one round, so a boot takes about 15 seconds longer than it did, and the periodic `k0: tick N` lines pause while a table is set. A line `root: partition window retry` means that the host stalled QEMU for more than a second and the window test ran once more; that alone is not a finding. Every image also prints `k0: dtb seeds wiped B` (40B on QEMU virt) and `root: boot seed from rng-seed bytes ...`. An image built with the feature `vault` also prints `root: oracle tests pass` and two more `k0: task fault` lines (8 instead of 6). An image built with the feature `terminal` shows two more `k0: task fault` lines than the same image without it (the hostile wiring checks: 8 in total without `vault`, 10 with it), `root: terminal wiring holds` and `root: service started`. An image with `console-input` prints `k0: console input on (pl011 irq 33)` or `k0: console input off ()` and `root: console input tests pass`. When a task first reads console input the `k0: tick N` lines stop after `k0: tick lines off (console input in use)`. +- Reproducers: the root task (`userspace/root-task/src/main.rs`) is the only EL0 image and already contains the test harness and thin `sys*` wrappers around `svc`. For the time partitions the wrappers are `part_set_table` and `part_set_domain`, and `userspace/root-task/src/partition.rs` is the existing test. The root task deletes `PartCtl` in `partition::seal()`, so a reproducer that needs a table must run before that call. EL0 has no clock, so a reproducer has to show its point by the order of events, as that test does. Add a test there; when the reproducer needs its own thread, build a task with its own CNode and address space (`RETYPE`, `TCB_CONFIGURE`, `TCB_RESUME`), which then runs code from the root task image, rebuild and run. `crates/k0-boot/build.rs` rebuilds and re-embeds the root task automatically. - UEFI loader: `cargo build -p k0-kernel --features console --offline`, then `tools/build-loader.sh`, which embeds that kernel into the loader, prints `build-loader: embedding a kernel with: k0: console drivers [...]` so that nobody embeds a silent kernel unknowingly, and prints the path (`.efi`). `tools/qemu-virt-runner.sh .efi` boots it through EDK2 with `-machine virt,gic-version=3,acpi=off` (firmware from `K0_QEMU_FIRMWARE`, else Homebrew's `edk2-aarch64-code.fd`, else `/usr/share/AAVMF/AAVMF_CODE.fd`, which is the Debian package in this image). `K0_QEMU_ESP=1` boots it from a FAT drive instead of `-kernel`, and `K0_QEMU_EXTRA` passes extra QEMU arguments. `tools/qemu-boot-test.sh .efi` judges the run from the loader's first line, `k0-loader: start`, so firmware messages before it do not count. The loader prints `k0-loader: ...` lines before the kernel's, and a refusal reads `k0-loader: refused: `. `K0_QEMU_MACHINE=virt,gic-version=3` (ACPI on, no device tree) boots through the static tables. `tools/pe-check.py .efi` checks the PE form and the order of the cache and MMU instructions. `K0_LOADER_FEATURES=refuse-halt tools/build-loader.sh` builds a loader that parks instead of returning to the firmware. The UEFI rows of `tools/boot-matrix.sh` (`uefi-*`) cover GICv2 and GICv3 at EL1 and EL2, the max CPU, 4 cores, the 16 KiB image, a firmware RNG, the FAT drive, the ACPI rows (`uefi-acpi-*`) and the refusals. -- Host tests: `tools/host-test.sh` runs the unit tests of `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-vault` and `k0-term` on any host and those of `k0-mm` on AArch64 hosts. `k0-cap` includes a model test over random retype, copy, move, delete and revoke sequences, and `k0-mm` runs the real user page table walkers and the address space registry. The DTB parser has a deterministic mutation fuzzer: `K0_FUZZ_ITERS=5000000 cargo test --release --offline --target "$(rustc -vV | sed -n 's/^host: //p')" -p k0-boot fuzz -- --nocapture`. A failing case prints `K0_FUZZ_CASE=0x...`, which replays it and dumps the input. The fuzzer's DTB builder in `crates/k0-boot/src/fdt/builder.rs` is a convenient way to write a crafted DTB for a reproducer. `k0-efi` has three more deterministic fuzzers (`fuzz_plan_with_random_maps`, `fuzz_rewrite_with_mutated_trees`, `fuzz_prepare_end_to_end`) with the same `K0_FUZZ_ITERS`, `K0_FUZZ_SEED` and `K0_FUZZ_CASE` variables: run them with `-p k0-efi fuzz`. The unit tests of `k0-efi` use measured firmware memory maps as vectors; a crafted memory map or firmware DTB is the natural reproducer for the loader. +- Host tests: `tools/host-test.sh` runs the unit tests of `k0-abi`, `k0-cap`, `k0-boot`, `k0-efi`, `k0-conin`, `k0-slice`, `k0-part`, `k0-vault` and `k0-term` on any host and those of `k0-mm` on AArch64 hosts. `k0-part` runs the real scheduling core on a model of the kernel, and one of its tests (`core_gives_the_lines_of_the_lean_model_on_every_recorded_script`) compares it with 1600 recorded results of a Lean model. The Lean files themselves (`proofs/lean`) are not in this image, and they are proofs about a model, not about the Rust code. `k0-sched`, `k0-ipc` and the kernel binary have no host tests. `k0-cap` includes a model test over random retype, copy, move, delete and revoke sequences, and `k0-mm` runs the real user page table walkers and the address space registry. The DTB parser has a deterministic mutation fuzzer: `K0_FUZZ_ITERS=5000000 cargo test --release --offline --target "$(rustc -vV | sed -n 's/^host: //p')" -p k0-boot fuzz -- --nocapture`. A failing case prints `K0_FUZZ_CASE=0x...`, which replays it and dumps the input. The fuzzer's DTB builder in `crates/k0-boot/src/fdt/builder.rs` is a convenient way to write a crafted DTB for a reproducer. `k0-efi` has three more deterministic fuzzers (`fuzz_plan_with_random_maps`, `fuzz_rewrite_with_mutated_trees`, `fuzz_prepare_end_to_end`) with the same `K0_FUZZ_ITERS`, `K0_FUZZ_SEED` and `K0_FUZZ_CASE` variables: run them with `-p k0-efi fuzz`. The unit tests of `k0-efi` use measured firmware memory maps as vectors; a crafted memory map or firmware DTB is the natural reproducer for the loader. - PAC, PAN and RNDR paths: the default `cortex-a72` model has none of them. `tools/qemu-boot-test.sh target/aarch64-unknown-none-softfloat/debug/k0-kernel -cpu max` (an image built with `--features console`) boots on a CPU that has all three. - A boot that the kernel refuses before it has a console prints nothing, and an image without a console feature prints nothing on the serial port at all. The reason is in the boot log in memory: start QEMU with `K0_QEMU_MONITOR=` and read it with `tools/boot-log.py ` (the load address on QEMU `virt` is `0x40080000`). - Debugging: append `-s -S` to the runner (`tools/qemu-virt-runner.sh -s -S`) and attach with `gdb-multiarch target/aarch64-unknown-none-softfloat/debug/k0-kernel -ex 'target remote :1234'`. `-d int,guest_errors` prints exception traces. `llvm-objdump -d` (from the pinned toolchain, linked into `/usr/local/bin`) disassembles both images. @@ -67,6 +69,7 @@ Rate by what EL0 code can do to EL1 or, on the current `main` branch, to another - **High**: memory-safety bugs in kernel code reachable from EL0, with or without a demonstrated exploit (out-of-bounds index, integer overflow or truncation in size or address arithmetic, stale raw pointers, aliasing `&mut`, unsound `unsafe`); a system call or fault sequence that halts the whole system (kernel panic, `exception_fatal`, an unbounded loop with interrupts masked, or a scheduler that cannot continue); missing TLB or cache maintenance that lets a task keep using memory after it was unmapped or retyped; kernel register or memory contents leaking to EL0 (registers not restored or cleared on the return path, uninitialised memory handed out by `retype` or `map`); checks that a race between the timer interrupt and a system call can bypass. - **Loader findings** are rated by what the kernel ends up trusting. **Critical**: a memory map or firmware device tree that makes the loader pass the kernel a RAM range that includes memory firmware still uses (runtime or boot services memory, MMIO, a reservation) so that it can reach user space, or that makes the loader start a kernel image that fails its own check. **High**: memory-safety bugs in the loader, a refusal that is skipped (the loader boots on input it should refuse), or an `ExitBootServices` path that leaves the system in an undefined state. **Medium**: a panic or an overly cautious refusal on a valid map, a leak of memory the loader should have wiped, a plan that loses RAM beyond the stated policy. Findings that need hostile firmware are Low (see "Anything to leave alone"). - **Input findings** are rated by what an outside party on the serial line gains. **Critical**: a byte stream or timing that gives code execution or memory access at EL1, or that makes a task do more than the operator's four operations. **High**: a stream that halts the machine or lets kernel work in interrupt context grow without the reader's bound; a wake-up or a byte delivered to a task that does not hold the read right. **Medium**: a stream that wedges the terminal or the input path until reboot. The lack of authentication on the serial line and the operator's power to erase the key are known (see "Anything to leave alone"). +- **Time partition findings** use the levels above. Setting a table or a domain without `PartCtl`, or copying `PartCtl`, is a bypass of a capability check (Critical). A system call sequence that halts the kernel on the scheduler paths is High, and so is a task that runs outside the window of its domain. A task that changes which task of another domain runs, in which order or at which tick, without an object shared with that domain and outside the known limits (see "Anything to leave alone"), is Medium. - **Medium**: malformed DTB input that panics, reads out of bounds, produces an unsafe memory map or gets a device mapped over memory that is handed out (the boot chain is trusted, so cap these at Medium unless they give code execution); exhaustion of kernel resources (for example untyped memory, TCB or endpoint objects; the kernel page tables and the address space registry are reserved at boot and no longer run out) by a single task that denies service to others without halting the kernel; scheduler starvation; mistakes in `write_bootinfo` beyond the known physical address exposure. - **Low**: problems that need a misbehaving root task to trigger; `build.rs` issues with trusted source inputs; console formatting and diagnostic wording; hardening that is missing but has no exploitable consequence today. - A root-cause analysis plus a patch is welcome at every level. A reproducer counts for more than a severity argument. @@ -83,8 +86,9 @@ These are known, tracked in `SECURITY.md`, and are not new findings: - No isolation between tasks in `v0.1.0` and earlier commits: one static root CNode, one address space, no capability derivation tree, no `MINT`, no `revoke`, no capability transfer over IPC (GHSA-vmpv-qc49-3p6r). Findings that only apply to those versions are not new. The current `main` branch (unreleased) has per-task CNodes and address spaces, rights, badges, a derivation list and revocation, so isolation bypasses there ARE in scope. EL0 reaching EL1 memory is always in scope. - Known limits of isolation on `main`: no fault delivery to a handler, no notifications, no capability transfer over IPC, a single core, and a sender already queued on an endpoint still delivers once after its capability is revoked. Availability is not protected in general (see below). New executable code cannot be loaded after boot by design, so a confined task runs code from the root task image. -- Availability limits (GHSA-q99x-2wrv-358p is still listed as affecting 0.1.0 and earlier, with no fixed version; `main` contains a change that addresses its subject). The kernel no longer halts when every task is blocked: it idles and prints `k0: idle (waiting for a timeout)` or `k0: all tasks stopped (none ready, no timeout pending)` once. A task can bound its own waits with the timeout in the upper 32 bits of `x1` (scheduler ticks of 1 second; `TIMEOUT`, `REPLY_TIMEOUT`, `BAD_FLAGS`). Still known: a wait without a timeout can last forever if the partner never acts; a timeout says when a task becomes ready, not when it runs (round-robin with a tick of one second, no priority or CPU budget, so a task with `Untyped` memory can dilute everybody's share by creating tasks, which stays known); the kernel is not preemptible, so a long system call such as `CAP_REVOKE` on an `Untyped` with many objects delays every task and every timeout; `k0_arch::fatal`, a kernel panic and an SError from EL0 stop the machine; the lines the kernel prints when a task ends share 4 KiB of the boot log and no longer reach its kernel part, but a task that can create tasks can still push such lines of other tasks out of the log. -- Scheduler timing, addressed on `main`: taking the CPU from the next task by calling `YIELD` (no capability needed) or blocking just before the tick. A task that gets the CPU between two ticks is no longer preempted by the first tick it meets (`crates/k0-slice`, used by `on_tick` and `resume_from_idle` in `crates/k0-sched`), so it is not cut before it has run one full period, and with N ready tasks a task that never yields or blocks keeps at least 1/N of the CPU. This was checked by search in a model (up to 6 tasks) and by host tests, not proven, and a self-test at every boot (`root: slice test yield pass`, `root: slice test block pass`) covers the kernel's use of it. A report that breaks this is still welcome. Known limits that stay: the share has no budget and N grows with every task created; the timing channel through the scheduler is open (a task changes when, and for how long, another task runs by choosing when to yield or block, and this has not been analysed); there is no latency promise (a task that becomes ready can wait up to one tick longer than before); three connections of the rule to the scheduler (the tick's own switch, the idle loop's report of a tick, the entry kind at the hand-off to the root task) are covered only by the host model and by no test on the real kernel, so a report that one of them is wrong is still welcome, as a latency finding; the measurements ran in QEMU only, with an attacker whose yield point was set for it. +- Availability limits (GHSA-q99x-2wrv-358p is still listed as affecting 0.1.0 and earlier, with no fixed version; `main` contains a change that addresses its subject). The kernel no longer halts when every task is blocked: it idles and prints `k0: idle (waiting for a timeout)` or `k0: all tasks stopped (none ready, no timeout pending)` once. A task can bound its own waits with the timeout in the upper 32 bits of `x1` (scheduler ticks of 1 second; `TIMEOUT`, `REPLY_TIMEOUT`, `BAD_FLAGS`). Still known: a wait without a timeout can last forever if the partner never acts; a timeout says when a task becomes ready, not when it runs (round-robin inside a domain with a tick of one second, no priority or CPU budget, so a task with `Untyped` memory can dilute the share of everybody in its domain by creating tasks, which stays known; under a time partition table a timeout can also fire late, when the waiter's domain next runs); the kernel is not preemptible, so a long system call such as `CAP_REVOKE` on an `Untyped` with many objects delays every task and every timeout; `k0_arch::fatal`, a kernel panic and an SError from EL0 stop the machine; the lines the kernel prints when a task ends share 4 KiB of the boot log and no longer reach its kernel part, but a task that can create tasks can still push such lines of other tasks out of the log. +- Scheduler timing, addressed on `main`: taking the CPU from the next task by calling `YIELD` (no capability needed) or blocking just before the tick. A task that gets the CPU between two ticks is no longer preempted by the first tick it meets (`crates/k0-slice`, used by `Core` in `crates/k0-part`), so with one domain it is not cut before it has run one full period, and with N ready tasks a task that never yields or blocks keeps at least 1/N of the CPU. This was checked by search in a model (up to 6 tasks) and by host tests. A Lean theorem states the bound for a model of one domain, which is not a proof about the Rust code, and a self-test at every boot (`root: slice test yield pass`, `root: slice test block pass`) covers the kernel's use of it. A report that breaks this is still welcome. Known limits that stay: the share has no budget and N grows with every task created; the timing channel through the scheduler is open between tasks of one domain (a task changes when, and for how long, another task of its domain runs by choosing when to yield or block, and this has not been analysed), and every image built today has one domain; there is no latency promise (a task that becomes ready can wait up to one tick longer than before); under a time partition table the end of a window takes the CPU whatever the rule says; the measurements ran in QEMU only, with an attacker whose yield point was set for it. The kernel no longer passes an entry kind to the scheduler, so the three connections that only a host model covered before (the tick's own switch, the wait loop's report of a tick, the entry kind at the hand-off to the root task) are now decided inside `Core` and covered by the host tests of `k0-part`. A report that one of them is wrong is still welcome. +- Fixed time partitions, all in `SECURITY.md` under "Fixed time partitions". The claim is that they close the channel between domains that goes through the scheduler, and nothing more. No image uses more than one domain yet: the root task deletes `PartCtl` at the end of its self-tests, so every image built today runs sealed with one domain. Known limits, not new findings: a kernel path longer than the guard (25 ms) that is in flight when the guard starts delays the start of the next window (`CAP_REVOKE`, large deletes); caches and branch predictors are not flushed at a change of domain (the TLB is); the time of console input interrupts and of the UART work in the tick handler lands in whichever domain runs; the UART, the boot log, the single console waiter slot (`BUSY`) and the kernel memory pools are shared between domains; a stall longer than a tick skips windows, because tick numbers follow the counter and skipped ticks are not replayed; an endpoint shared across domains is a channel by design, and so is every other capability operation on an object shared with another domain (deleting or revoking an endpoint its tasks wait on, the end of a task that holds its reply, `TCB_RESUME`, deleting its TCB); a task woken by console input inside the guard of an empty incoming window starts at the tick instant and still skips its first tick rotation, inside its own domain; no test sees the guard, the hold or the TLB flush, because EL0 cannot time anything, and the console rule under a table has no test; the Lean proofs are about a model; nothing ran on real hardware. A table must contain the caller's domain, a task in a domain that no table names never runs, and a timeout fires late when the waiter's domain is not running: all three are by design. The system call ABI changed with this (`bootinfo::VERSION` 5, first untyped slot 6), so a root task built for an earlier `main` does not run. - EL0 still cannot read a hardware counter or timer. Timeouts give it a clock as coarse as the scheduler tick; whether that can be amplified into a timing source for cache or speculation attacks has not been analysed. - The kernel tables are sized at boot: alias page tables and address space entries are reserved from the top of every range handed out as `Untyped` (`k0: kernel reserve ...` line), so `RETYPE` no longer fails with `KERNEL_RESOURCE` for lack of tables and the number of address spaces is limited only by memory. The 40-table static pool is used only during boot. - DTB memory regions are not bounded by the physical address width (GHSA-hj3f-38h9-hrpj). The current `main` branch stops the boot on such a region; the advisory itself is still a draft. diff --git a/crates/k0-abi/src/lib.rs b/crates/k0-abi/src/lib.rs index 66050a9..4cf30d4 100644 --- a/crates/k0-abi/src/lib.rs +++ b/crates/k0-abi/src/lib.rs @@ -137,6 +137,25 @@ pub mod syscall { /// 바이트를 해석하지 않습니다. 기다리는 동안 그 케이퍼빌리티를 잃으면 /// REVOKED로 깨어납니다 pub const CONSOLE_READ: u64 = 16; + /// 시간 분할 표를 정함 + /// + /// x0 = PartCtl 슬롯, x1 = 항목 수(1-16), x2-x5 = 항목. 항목 i는 레지스터 + /// x(2 + i / 4)의 비트 16 * (i % 4)부터 16비트이고 값은 + /// `(틱 수 << 8) | 도메인`입니다. 틱 수는 1-255, 도메인은 0-7이며 쓰지 않는 + /// 비트는 전부 0이어야 합니다. 표는 항목 순서대로 돌고 끝나면 처음으로 + /// 돌아갑니다. 같은 도메인이 이어지는 항목은 한 창입니다. 표에 없는 + /// 도메인의 태스크는 실행되지 않습니다. 새 표는 호출한 틱의 두 틱 뒤에 + /// 0번 항목부터 효력이 생기고, 그 전에 다시 부르면 나중 것이 남습니다. + /// 호출한 태스크 자신의 도메인이 표에 없으면 거부됩니다. 형식이 틀리면 + /// x0 = BAD_TABLE, 성공 시 x0 = 0 + pub const PART_SET_TABLE: u64 = 17; + /// 아직 실행된 적 없는 태스크의 도메인을 정함 + /// + /// x0 = PartCtl 슬롯, x1 = TCB 슬롯, x2 = 도메인(0-7). TCB는 구성을 마치고 + /// 아직 시작하지 않은 상태(Stopped)여야 합니다. 태스크는 TCB_CONFIGURE를 + /// 부른 태스크의 도메인을 물려받으므로, 다른 도메인에 두려면 이 호출이 + /// 필요합니다. 도메인이 표에 있는지는 보지 않습니다. 성공 시 x0 = 0 + pub const PART_SET_DOMAIN: u64 = 18; } /// CONSOLE_READ의 플래그(x1)와 결과(x2) 모듈입니다. @@ -280,6 +299,10 @@ pub mod err { pub const BUSY: i64 = -23; /// 이 이미지나 이 기계에 콘솔 입력 경로가 없거나, 커널이 그 경로를 껐음 pub const NO_DEVICE: i64 = -24; + /// 시간 분할 표의 형식이 틀렸거나 호출한 태스크의 도메인이 표에 없음 + pub const BAD_TABLE: i64 = -25; + /// 도메인 번호가 범위 밖임 + pub const BAD_DOMAIN: i64 = -26; } /// 커널이 루트 태스크에 RO로 매핑해 주는 bootinfo 페이지 모듈입니다. @@ -295,7 +318,10 @@ pub mod bootinfo { /// /// 버전 4부터 Console 케이퍼빌리티에 권한 비트가 있습니다(R = 입력 읽기, /// W = 출력). 디스크립터의 `rights`가 그 값을 알립니다 - pub const VERSION: u64 = 4; + /// + /// 버전 5부터 슬롯 5에 시간 분할 제어 케이퍼빌리티(PartCtl)가 있고, 처음 + /// 비어 있는 슬롯은 그만큼 뒤로 갑니다 + pub const VERSION: u64 = 5; /// 루트 태스크의 진입 레지스터 x4로 오는 시드 정보에서, 시드에 들어간 /// `rng-seed` 바이트 수를 담는 비트 @@ -320,6 +346,9 @@ pub mod bootinfo { pub const CONSOLE: u64 = 3; /// 루트 CNode 자신(복사와 이동의 목적지로 쓰임) pub const CNODE: u64 = 4; + /// 시간 분할 제어. 분할 표와 태스크의 도메인을 정하는 권한이며 + /// 복사할 수 없습니다. 삭제하면 그 뒤로는 아무도 바꾸지 못합니다 + pub const PART_CTL: u64 = 5; } /// bootinfo 페이지 선두의 헤더 구조체입니다. @@ -361,6 +390,7 @@ pub mod bootinfo { pub const ENDPOINT: u64 = 6; pub const CONSOLE: u64 = 7; pub const CNODE: u64 = 8; + pub const PART_CTL: u64 = 9; } } diff --git a/crates/k0-abi/src/tests.rs b/crates/k0-abi/src/tests.rs index e6b6c81..6085374 100644 --- a/crates/k0-abi/src/tests.rs +++ b/crates/k0-abi/src/tests.rs @@ -30,6 +30,8 @@ fn syscall_numbers_are_unique_and_dense() { syscall::CAP_DELETE, syscall::CAP_REVOKE, syscall::CONSOLE_READ, + syscall::PART_SET_TABLE, + syscall::PART_SET_DOMAIN, ]; assert_unique(&nrs.map(i128::from)); for (i, nr) in nrs.iter().enumerate() { @@ -64,6 +66,8 @@ fn error_codes_are_unique_and_negative() { err::BAD_FLAGS, err::BUSY, err::NO_DEVICE, + err::BAD_TABLE, + err::BAD_DOMAIN, ]; assert_unique(&errs.map(i128::from)); for e in errs { @@ -107,7 +111,7 @@ fn rights_are_distinct_bits() { #[test] fn fixed_boot_slots_skip_the_null_slot() { use bootinfo::slot::*; - let slots = [TCB, ADDR_SPACE, CONSOLE, CNODE]; + let slots = [TCB, ADDR_SPACE, CONSOLE, CNODE, PART_CTL]; assert_unique(&slots.map(i128::from)); for (i, s) in slots.iter().enumerate() { assert_eq!(*s, i as u64 + 1); @@ -150,7 +154,7 @@ fn console_read_flag_bits_are_all_accounted_for() { #[test] fn bootinfo_layout_is_stable() { - assert_eq!(bootinfo::VERSION, 4); + assert_eq!(bootinfo::VERSION, 5); assert_eq!(bootinfo::SEED_RNG_SEED_BYTES & bootinfo::SEED_RNDR, 0); assert_eq!(size_of::(), 32); assert_eq!(offset_of!(bootinfo::Header, version), 0); @@ -175,7 +179,7 @@ fn bootinfo_page_is_aligned_for_both_granules() { fn cap_kinds_are_unique() { use bootinfo::cap_kind::*; let kinds = [ - EMPTY, TCB, ADDR_SPACE, UNTYPED, FRAME, PAGE_TABLE, ENDPOINT, CONSOLE, CNODE, + EMPTY, TCB, ADDR_SPACE, UNTYPED, FRAME, PAGE_TABLE, ENDPOINT, CONSOLE, CNODE, PART_CTL, ]; assert_unique(&kinds.map(i128::from)); assert_eq!(EMPTY, 0); diff --git a/crates/k0-arch/Cargo.toml b/crates/k0-arch/Cargo.toml index ba1c618..0d4dcf7 100644 --- a/crates/k0-arch/Cargo.toml +++ b/crates/k0-arch/Cargo.toml @@ -19,4 +19,5 @@ console-input = ["dep:k0-conin"] [dependencies] k0-abi = { path = "../k0-abi" } +k0-part = { path = "../k0-part" } k0-conin = { path = "../k0-conin", optional = true } diff --git a/crates/k0-arch/src/irq.rs b/crates/k0-arch/src/irq.rs index 04c215e..fab8b2f 100644 --- a/crates/k0-arch/src/irq.rs +++ b/crates/k0-arch/src/irq.rs @@ -18,9 +18,19 @@ //! 틱 주기는 1초입니다. 틱은 선점 신호이면서 IPC 타임아웃의 단위이고, EL0가 //! 얻을 수 있는 유일한 시간 정보입니다(EL0는 카운터와 타이머 레지스터를 읽지 //! 못함). 주기를 줄이면 EL0에 더 정밀한 시계를 주게 되므로, 주기를 바꾸는 -//! 것은 성능 조정이 아니라 사이드 채널에 관한 결정입니다. 틱은 처리된 횟수를 -//! 세는 것이지 흐른 시간을 재는 것이 아닙니다. 커널이 인터럽트를 막은 채 -//! 한 주기보다 오래 실행되면 그 사이의 틱은 한 번으로 셉니다. +//! 것은 성능 조정이 아니라 사이드 채널에 관한 결정입니다. +//! +//! 틱 n의 시각은 부팅 때 읽은 카운터 값에 n 주기를 더한 값으로 정해져 있고, +//! 타이머는 그 절대 시각에 맞춰 겁니다. 그래서 틱의 시각은 핸들러가 얼마나 +//! 늦게 돌았는지와 무관하고 밀리지 않습니다. 틱 번호도 카운터가 정합니다. +//! 커널이 인터럽트를 막은 채 한 주기보다 오래 실행되면 지나간 번호는 +//! 건너뛰고, 스케줄러는 도착한 번호 하나만 봅니다. 이 산술은 k0-part의 +//! `clock` 모듈에 있고 호스트에서 시험합니다. +//! +//! 시간 분할에서 도메인이 바뀌는 틱은 보호 구간만큼 일찍 인터럽트를 겁니다 +//! ([guard_next]). 전환 작업을 그 구간 안에서 마치고 [hold_until_due]가 틱의 +//! 예정 시각까지 기다린 뒤에 다음 도메인이 실행되므로, 구간보다 짧은 커널 +//! 경로는 다음 도메인의 시작 시각을 움직이지 못합니다. //! //! # Errors //! 하드웨어가 기술과 다르거나, 타이머 PPI를 이 보안 상태에서 쓸 수 없거나, @@ -87,6 +97,12 @@ static GICC: AtomicUsize = AtomicUsize::new(0); static TIMER_INTID: AtomicU32 = AtomicU32::new(0); static TIMER_HZ: AtomicU64 = AtomicU64::new(0); static TICKS: AtomicU64 = AtomicU64::new(0); +/// 틱 0의 시각(초기화 때 읽은 카운터 값). 틱 n은 여기에 n 주기를 더한 시각 +static T0: AtomicU64 = AtomicU64::new(0); +/// 다음 틱의 비교값을 예정 시각보다 얼마나 일찍 걸었는지(0이면 제때) +static EARLY: AtomicU64 = AtomicU64::new(0); +/// 분할 표가 기본이 아닌 동안에는 틱 줄을 내지 않음(틱 처리 시간을 줄임) +static PARTITIONED: core::sync::atomic::AtomicBool = core::sync::atomic::AtomicBool::new(false); /// 디스트리뷰터 레지스터의 가상 주소(콘솔의 SPI를 켜고 끄는 데 씀) #[cfg(feature = "console-input")] static GICD: AtomicUsize = AtomicUsize::new(0); @@ -668,22 +684,54 @@ pub fn counter_hz(dt_hz: u32) -> Result { } } -fn timer_arm(interval: u64) { - // SAFETY: EL1 가상 타이머 재장전과 활성화 (IMASK=0) +/// 가상 카운터의 지금 값을 읽는 함수입니다. +fn counter_now() -> u64 { + let now: u64; + // SAFETY: CNTVCT_EL0 읽기는 부작용이 없음. 앞의 isb는 그 앞 명령들이 + // 끝난 뒤의 값을 읽게 함 + unsafe { asm!("isb", "mrs {}, cntvct_el0", out(reg) now, options(nomem, nostack)) }; + now +} + +/// 타이머를 절대 시각에 거는 함수입니다. +fn timer_set(cval: u64) { + // SAFETY: EL1 가상 타이머의 비교값 설정과 활성화 (IMASK=0). 비교값이 + // 앞으로 가면 레벨 인터럽트의 원인이 사라지고, 뒤의 isb가 그 + // 결과를 완료 통지 전에 반영함 unsafe { asm!( - "msr cntv_tval_el0, {i}", + "msr cntv_cval_el0, {v}", "msr cntv_ctl_el0, {c}", - i = in(reg) interval, + "isb", + v = in(reg) cval, c = in(reg) 1u64, options(nomem, nostack), ); } } -fn timer_tick() { - let n = TICKS.load(Ordering::Relaxed) + 1; +/// 타이머 인터럽트를 처리하는 함수입니다. 틱이었으면 true를 줍니다. +/// +/// 걸어 둔 시각보다 이른 인터럽트는 틱으로 세지 않고 같은 시각을 다시 겁니다. +fn timer_tick() -> bool { + use k0_part::clock; + let hz = TIMER_HZ.load(Ordering::Relaxed); + let t0 = T0.load(Ordering::Relaxed); + let last = TICKS.load(Ordering::Relaxed); + let early = EARLY.load(Ordering::Relaxed); + let n = match clock::fire(counter_now(), t0, hz, last, early) { + clock::Fire::Spurious => { + timer_set(clock::due(t0, hz, last.saturating_add(1)).saturating_sub(early)); + return false; + } + clock::Fire::Tick(n) => n, + }; TICKS.store(n, Ordering::Relaxed); + // 다음 틱을 먼저 검(레벨 인터럽트의 원인 제거도 겸함). 뒤에 하는 일의 + // 길이가 다음 틱의 시각에 영향을 주지 않음. 보호 구간은 스케줄러가 이 + // 틱을 처리한 뒤에 guard_next로 다시 정함 + EARLY.store(0, Ordering::Relaxed); + timer_set(clock::due(t0, hz, n.saturating_add(1))); // 수신 인터럽트가 오지 않는 UART(수신 타임아웃이 없거나 번호가 조용히 // 틀린 경우)에서도 입력이 늦게나마 도착하게 틱마다 한 번 들여다봄. 오류 // 문자를 버릴 만큼 버려 막아 둔 수신 인터럽트도 여기서 다시 열림. 닫혀 @@ -696,22 +744,75 @@ fn timer_tick() { let quiet = QUIET_TICKS.load(Ordering::Relaxed); #[cfg(not(feature = "console-input"))] let quiet = false; - // 틱은 끝없이 이어지므로 처음 몇 줄만 로그에 남김 - if quiet { - } else if n <= LOGGED_TICKS { - let _ = writeln!(EarlyCon, "k0: tick {n}"); - } else { - // 콘솔 드라이버가 없는 빌드에는 쓸 곳이 없으므로 서식 작업도 하지 않음 + if !quiet { + // 처음 몇 틱은 로그에 남김. 번호를 건너뛰었어도 빠짐없이 적음 + let mut k = last.saturating_add(1); + while k <= n && k <= LOGGED_TICKS { + let _ = writeln!(EarlyCon, "k0: tick {k}"); + k += 1; + } + // 틱은 끝없이 이어지므로 그 뒤로는 콘솔에만 냄. 콘솔 드라이버가 없는 + // 빌드에는 쓸 곳이 없으므로 서식 작업도 하지 않음 #[cfg(any(feature = "console-pl011", feature = "console-16550"))] - let _ = writeln!(ConsoleOnly, "k0: tick {n}"); + if n > LOGGED_TICKS && !PARTITIONED.load(Ordering::Relaxed) { + let _ = writeln!(ConsoleOnly, "k0: tick {n}"); + } + } + true +} + +/// 다음 틱의 인터럽트를 보호 구간만큼 일찍 걸지 정하는 함수입니다. +/// +/// 스케줄러가 틱 하나를 처리한 뒤와 분할 표가 바뀐 뒤에 부릅니다. 다음 틱에서 +/// 도메인이 바뀌면 `true`를 넘깁니다. +/// +/// # Arguments +/// `early` - 다음 틱을 일찍 걸지 여부 +pub fn guard_next(early: bool) { + use k0_part::clock; + let hz = TIMER_HZ.load(Ordering::Relaxed); + let by = if early { clock::guard(hz) } else { 0 }; + let next = TICKS.load(Ordering::Relaxed).saturating_add(1); + EARLY.store(by, Ordering::Relaxed); + timer_set(clock::due(T0.load(Ordering::Relaxed), hz, next).saturating_sub(by)); +} + +/// 마지막으로 처리한 틱의 예정 시각이 될 때까지 기다리는 함수입니다. +/// +/// EL0로 돌아가기 직전에 부릅니다. 틱을 일찍 받은 경우가 아니면 이미 지난 +/// 시각이므로 곧바로 돌아옵니다. +pub fn hold_until_due() { + use k0_part::clock; + let hz = TIMER_HZ.load(Ordering::Relaxed); + let t0 = T0.load(Ordering::Relaxed); + let n = TICKS.load(Ordering::Relaxed); + while !clock::reached(counter_now(), t0, hz, n) { + core::hint::spin_loop(); } - // 1초 주기 재장전 (레벨 인터럽트의 원인 제거도 겸함) - timer_arm(TIMER_HZ.load(Ordering::Relaxed)); } -/// 부팅 뒤로 지나간 타이머 틱 수를 주는 함수입니다. +/// 분할 표가 기본이 아닌지를 알려 두는 함수입니다. 그동안에는 틱 줄을 내지 +/// 않습니다. +/// +/// # Arguments +/// `on` - 분할 표가 기본이 아니면 true +pub fn set_partitioned(on: bool) { + PARTITIONED.store(on, Ordering::Relaxed); +} + +/// 이 코어의 인터럽트를 전부 막는 함수입니다. 다시 열지 않습니다. +/// +/// 루트 태스크로 넘어가기 직전에 스케줄러가 부릅니다. 그 뒤로 커널은 예외로만 +/// 실행되고 예외 진입은 마스크된 채 시작하므로, 막힌 동안 걸린 틱은 EL0에 +/// 들어간 직후에 평소의 틱 사건으로 들어옵니다. +pub fn mask_all() { + // SAFETY: DAIF의 마스크 비트를 세우는 것은 메모리와 스택을 건드리지 않음 + unsafe { asm!("msr DAIFSet, #0xf", options(nomem, nostack)) }; +} + +/// 마지막으로 처리한 타이머 틱의 번호를 주는 함수입니다. /// -/// IPC 타임아웃의 기한이 이 값을 기준으로 정해집니다. +/// IPC 타임아웃의 기한과 분할 표의 위치가 이 값을 기준으로 정해집니다. pub fn ticks() -> u64 { TICKS.load(Ordering::Relaxed) } @@ -876,8 +977,12 @@ pub unsafe fn init(_vectors: &Vectors, gic: &Gic, intid: u32, hz: u64) -> Result }, } TIMER_INTID.store(intid, Ordering::Relaxed); + // 주기와 틱 0의 시각을 먼저 적고 첫 틱을 검. 마스크를 여는 것은 그 뒤임 TIMER_HZ.store(hz, Ordering::Relaxed); - timer_arm(hz); + let t0 = counter_now(); + T0.store(t0, Ordering::Relaxed); + EARLY.store(0, Ordering::Relaxed); + timer_set(k0_part::clock::due(t0, hz, 1)); // SAFETY: 벡터와 GIC가 준비된 뒤의 IRQ + SError(A) 언마스크 // SError를 계속 마스크하면 커널 실행 중의 시스템 오류가 조용히 // pending으로 쌓였다가 EL0 진입 후 엉뚱한 문맥에서 터짐 @@ -918,6 +1023,12 @@ unsafe extern "C" { /// 마친 뒤에만 호출됩니다. fn k0_preempt(); + /// EL0로 돌아가기 직전의 마지막 확인, 커널 바이너리가 정의함 (링크 계약) + /// + /// # Safety + /// [k0_preempt]와 같고, 핸들러가 할 일을 전부 마친 뒤에 호출됩니다. + fn k0_leave(); + /// 콘솔 입력이 도착했을 때 기다리는 태스크를 깨우는 정책, 커널 바이너리가 /// 정의함 (링크 계약) /// @@ -948,9 +1059,13 @@ fn dispatch_irq() -> u8 { let iar = gicv3::ack(); match iar & 0xFF_FFFF { id if id == timer => { - timer_tick(); + let tick = timer_tick(); gicv3::eoi(iar); - EV_TICK + if tick { + EV_TICK + } else { + 0 + } } #[cfg(feature = "console-input")] id if id == console => { @@ -968,10 +1083,14 @@ fn dispatch_irq() -> u8 { let iar = unsafe { read32(cpu + gicv2::GICC_IAR) }; match u64::from(iar & 0x3FF) { id if id == timer => { - timer_tick(); + let tick = timer_tick(); // SAFETY: 승인에서 받은 값 그대로 완료 통지 unsafe { write32(cpu + gicv2::GICC_EOIR, iar) }; - EV_TICK + if tick { + EV_TICK + } else { + 0 + } } #[cfg(feature = "console-input")] id if id == console => { @@ -1014,7 +1133,8 @@ extern "C" fn fiq_current() { /// /// 타이머 틱이면 커널의 선점 정책을 부릅니다. 복귀는 벡터의 /// `__user_restore`가 (선점 정책이 갱신했을 수 있는) 현재 컨텍스트를 -/// 복원하며 수행합니다. +/// 복원하며 수행합니다. 어떤 인터럽트였든 돌아가기 직전에 커널의 마지막 +/// 확인을 거칩니다. #[unsafe(no_mangle)] extern "C" fn irq_lower(_ctx: &mut crate::usermode::Context) { let events = dispatch_irq(); @@ -1027,6 +1147,8 @@ extern "C" fn irq_lower(_ctx: &mut crate::usermode::Context) { // SAFETY: 벡터가 사용자 컨텍스트 저장을 마친 EL0 IRQ 경로임 unsafe { k0_preempt() }; } + // SAFETY: 같은 경로이고 핸들러의 일이 끝남 + unsafe { k0_leave() }; } /// 사용자 공간(EL0) 실행 중 FIQ 벡터가 사용하는 디스패처 함수입니다. diff --git a/crates/k0-arch/src/usermode.rs b/crates/k0-arch/src/usermode.rs index 0f3d717..ccff51d 100644 --- a/crates/k0-arch/src/usermode.rs +++ b/crates/k0-arch/src/usermode.rs @@ -80,6 +80,12 @@ unsafe extern "C" { /// `ctx`는 `__current_context`가 가리키는 유효한 컨텍스트이고 `esr` / /// `far`는 벡터 진입 직후 읽은 신드롬입니다. fn k0_fault(ctx: &mut Context, esr: u64, far: u64); + + /// EL0로 돌아가기 직전의 마지막 확인, 커널 바이너리가 정의함 (링크 계약) + /// + /// # Safety + /// EL0에서 진입한 예외의 핸들러가 할 일을 전부 마친 뒤에만 호출됩니다. + fn k0_leave(); } /// 벡터가 저장/복원할 현재 태스크 컨텍스트를 지정하는 함수입니다. @@ -132,7 +138,13 @@ extern "C" fn el0_sync(ctx: &mut Context) { // SAFETY: ctx는 벡터가 방금 저장한 현재 컨텍스트 0x15 => unsafe { k0_syscall(ctx) }, // EL0의 WFI/WFE 트랩(SCTLR nTWI/nTWE=0): 양보로 취급하고 다음 명령으로 - 0x01 => ctx.elr += 4, + // 스케줄러의 상태는 바뀌지 않지만, EL0로 돌아가는 길은 하나도 빠짐없이 + // 마지막 확인을 지나게 함 + 0x01 => { + ctx.elr += 4; + // SAFETY: 벡터가 컨텍스트 저장을 마친 EL0 동기 예외의 끝임 + unsafe { k0_leave() }; + } // 그 외 동기 예외(폴트)는 그 태스크의 결함이므로 커널의 격리 정책으로 _ => { let far: u64; diff --git a/crates/k0-boot/build.rs b/crates/k0-boot/build.rs index 8e12e32..5c9a0a3 100644 --- a/crates/k0-boot/build.rs +++ b/crates/k0-boot/build.rs @@ -37,13 +37,14 @@ const MAX_FLAT_SIZE: u64 = 1024 * 1024; /// /// 커널은 이미지 프레임마다 Frame 케이퍼빌리티 하나를 루트 CNode에 넣고 /// bootinfo 페이지에 디스크립터 하나를 씁니다. 4KiB 그래뉼에서 bootinfo -/// 페이지는 (4096 - 32) / 32 = 127개의 디스크립터를 담고, 그중 5개는 고정 +/// 페이지는 (4096 - 32) / 32 = 127개의 디스크립터를 담고, 그중 6개는 고정 /// 슬롯(null 포함)입니다. untyped는 메모리 구간 8개에 예약 구간(커널이 넣는 /// 고정 4개와 DTB의 32개)이 하나씩 쪼갤 때마다 하나씩 늘어 최대 44개입니다. -/// 남는 78개 안쪽으로 잡아, 넘치는 이미지는 부팅이 아니라 빌드에서 실패하게 -/// 합니다. 이 계산의 입력이 바뀌면(k0-boot의 구간 상한, 커널의 고정 예약 수) +/// 남는 77개 안쪽으로 잡아, 넘치는 이미지는 부팅이 아니라 빌드에서 실패하게 +/// 합니다. 이 계산의 입력이 바뀌면(k0-boot의 구간 상한, 커널의 고정 예약 수, +/// 고정 슬롯의 수) /// 이 값도 다시 계산해야 하고, 부팅 시의 넘침 검사가 마지막 방어선입니다. -const MAX_IMAGE_FRAMES_4K: u64 = 78; +const MAX_IMAGE_FRAMES_4K: u64 = 77; /// SHA-256 해시를 고정 크기 배열로 계산하는 함수입니다. /// diff --git a/crates/k0-cap/Cargo.toml b/crates/k0-cap/Cargo.toml index 06d36e7..b200c33 100644 --- a/crates/k0-cap/Cargo.toml +++ b/crates/k0-cap/Cargo.toml @@ -5,9 +5,4 @@ edition.workspace = true license.workspace = true publish.workspace = true -# 루트 CNode를 1024슬롯으로 만듦. 자가 검증 뒤에 서비스를 새로 띄우는 이미지 -# (터미널)가 켬. 주지 않으면 512슬롯 그대로임 -[features] -root-cnode-1024 = [] - [dependencies] diff --git a/crates/k0-cap/src/lib.rs b/crates/k0-cap/src/lib.rs index 52ce06e..197a2ec 100644 --- a/crates/k0-cap/src/lib.rs +++ b/crates/k0-cap/src/lib.rs @@ -39,12 +39,9 @@ pub const SLOT_SIZE: usize = 64; /// 루트 CNode의 슬롯 수 /// -/// 자가 검증 뒤에 서비스(볼트와 터미널)를 새로 띄우는 이미지는 주소 공간 둘을 -/// 더 만들 슬롯이 필요하므로 feature `root-cnode-1024`로 두 배를 받습니다. -/// 그 밖의 이미지는 그대로입니다. -#[cfg(not(feature = "root-cnode-1024"))] -pub const ROOT_CNODE_SLOTS: usize = 512; -#[cfg(feature = "root-cnode-1024")] +/// 모든 이미지가 같은 값을 씁니다. 자가 검증이 쓰는 슬롯은 루트 태스크 +/// 이미지의 프레임 수에 비례해 늘어나므로, 이미지가 커져도 모자라지 않게 +/// 넉넉히 잡습니다. pub const ROOT_CNODE_SLOTS: usize = 1024; /// 파생 깊이 상한, 초과하는 복사는 거부됩니다 @@ -79,6 +76,7 @@ const KIND_ENDPOINT: u64 = 5; const KIND_CNODE: u64 = 6; const KIND_ADDR_SPACE: u64 = 7; const KIND_CONSOLE: u64 = 8; +const KIND_PART_CTL: u64 = 9; /// 물리 메모리 구간 하나를 나타내는 구조체입니다. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -147,6 +145,9 @@ pub enum Cap { /// 커널 콘솔에 대한 권한(오브젝트 없음), `rights`의 W가 출력이고 R이 /// 입력 읽기 Console { rights: u8 }, + /// 시간 분할 제어 권한(오브젝트 없음). 분할 표와 태스크의 도메인을 정할 수 + /// 있고 복사할 수 없음 + PartCtl, } /// 재분류로 만들 수 있는 커널 오브젝트 종류를 나타내는 열거형입니다. @@ -293,6 +294,7 @@ fn encode(cap: &Cap) -> [u64; 4] { Cap::CNode { base, slots } => [base | KIND_CNODE, *slots, 0, 0], Cap::AddrSpace { root_pa, asid } => [root_pa | KIND_ADDR_SPACE, *asid, 0, 0], Cap::Console { rights } => [KIND_CONSOLE | (u64::from(*rights) << RIGHTS_SHIFT), 0, 0, 0], + Cap::PartCtl => [KIND_PART_CTL, 0, 0, 0], } } @@ -415,6 +417,13 @@ fn decode(w: &[u64; 4]) -> Result, CapError> { } Cap::Console { rights } } + KIND_PART_CTL => { + let tail_zero = w[1] == 0 && w[2] == 0 && w[3] == 0; + if rights != 0 || mapped || base != 0 || !tail_zero { + return Err(CapError::Corrupt); + } + Cap::PartCtl + } _ => return Err(CapError::Corrupt), }; Ok(Some(Entry { @@ -787,7 +796,9 @@ unsafe fn plan_copy( return Err(CapError::Occupied); } let cap = match e.cap { - Cap::Untyped { .. } | Cap::PageTable { .. } => return Err(CapError::NotCopyable), + Cap::Untyped { .. } | Cap::PageTable { .. } | Cap::PartCtl => { + return Err(CapError::NotCopyable) + } Cap::Frame { base, rights, .. } => { if badge != 0 { return Err(CapError::BadBadge); @@ -834,7 +845,9 @@ unsafe fn plan_copy( } Cap::Console { rights } } - other => { + // 종류를 하나씩 적음. 새 종류를 더하면 여기서 컴파일이 멈추므로 복사 + // 규칙을 정하지 않은 채 복사 가능해지는 일이 없음 + other @ (Cap::Tcb { .. } | Cap::CNode { .. } | Cap::AddrSpace { .. }) => { // 배지는 엔드포인트 전용. 다른 종류의 워드에 사용자 값이 섞이면 // asid나 매핑 기록을 위조하는 길이 됨 if badge != 0 { @@ -1111,8 +1124,10 @@ pub mod boot_slot { pub const ADDR_SPACE: u64 = 2; pub const CONSOLE: u64 = 3; pub const CNODE: u64 = 4; + /// 시간 분할 제어 + pub const PART_CTL: u64 = 5; /// untyped가 시작되는 슬롯 - pub const FIRST_DYNAMIC: u64 = 5; + pub const FIRST_DYNAMIC: u64 = 6; } /// 부트스트랩이 루트 CNode에 넣을 고정 오브젝트들을 담는 구조체입니다. @@ -1184,6 +1199,7 @@ pub unsafe fn bootstrap( slots: cnode.len() as u64, }, ), + (boot_slot::PART_CTL, Cap::PartCtl), ]; for (index, cap) in fixed { let slot = cnode.slot(index).ok_or(CapError::OutOfSlots)?; diff --git a/crates/k0-cap/src/tests.rs b/crates/k0-cap/src/tests.rs index 61bfc04..ec1df45 100644 --- a/crates/k0-cap/src/tests.rs +++ b/crates/k0-cap/src/tests.rs @@ -3,6 +3,8 @@ use super::*; use std::collections::{BTreeMap, BTreeSet}; const G: u64 = 4096; +/// 첫 untyped가 들어가는 슬롯 +const UT: usize = boot_slot::FIRST_DYNAMIC as usize; const BOOT: BootObjects = BootObjects { tcb: 0x7000_0000, @@ -174,7 +176,7 @@ fn malformed_words_are_rejected_not_interpreted() { let bad: [[u64; 4]; 14] = [ [0, 1, 0, 0], [0, 0, 0, 9], - [9, 0, 0, 0], + [10, 0, 0, 0], [15, 0, 0, 0], [KIND_TCB | 1 << 11, 0, 0, 0], [KIND_TCB | 1 << 48, 0, 0, 0], @@ -262,9 +264,10 @@ fn fixed_slots_come_first() { slots: 64 } ); + assert_eq!(cap_at(c, 5), Cap::PartCtl); assert_eq!(untypeds(c, 64), vec![(0x4000_0000, 0x10_0000, 0)]); - assert_eq!(next, 6); - for i in 1..6 { + assert_eq!(next, 7); + for i in 1..7 { let e = get(c, i).unwrap(); assert!(e.original && !e.bound); unsafe { @@ -422,7 +425,7 @@ fn slot_lookup_rejects_null_and_out_of_range() { #[test] fn retype_carves_aligned_objects_in_order() { let (c, next) = filled(&[r(0x4000_0000, 8 * G)], &[]); - let ut = unsafe { c.add(5) }; + let ut = unsafe { c.add(UT) }; let mut seen = Vec::new(); let kinds = [ ObjKind::Frame, @@ -476,7 +479,7 @@ fn retype_carves_aligned_objects_in_order() { #[test] fn retyped_frames_never_carry_execute() { let (c, next) = filled(&[r(0x4000_0000, 8 * G)], &[]); - unsafe { retype(c.add(5), c.add(next as usize), ObjKind::Frame, G, ok_prep) }.unwrap(); + unsafe { retype(c.add(UT), c.add(next as usize), ObjKind::Frame, G, ok_prep) }.unwrap(); let Cap::Frame { rights: got, .. } = cap_at(c, next as usize) else { panic!() }; @@ -493,7 +496,7 @@ fn retyped_frames_never_carry_execute() { fn retype_rounds_unaligned_watermark_up() { let (c, next) = filled(&[r(0x1800, 0x4000)], &[]); let n = next as usize; - let ut = unsafe { c.add(5) }; + let ut = unsafe { c.add(UT) }; let mut at = 0; unsafe { retype(ut, c.add(n), ObjKind::Frame, G, |pa| { @@ -519,7 +522,7 @@ fn retype_rounds_unaligned_watermark_up() { fn failed_prep_leaves_state_unchanged() { let (c, next) = filled(&[r(0x10000, 4 * G)], &[]); let n = next as usize; - let ut = unsafe { c.add(5) }; + let ut = unsafe { c.add(UT) }; assert_eq!( unsafe { retype(ut, c.add(n), ObjKind::Tcb, G, |_| None) }, Err(CapError::PrepFailed) @@ -542,18 +545,18 @@ fn failed_prep_leaves_state_unchanged() { fn retype_rejects_bad_sources_and_destinations_without_prep() { let (c, next) = filled(&[r(0x10000, 4 * G)], &[]); let n = next as usize; - unsafe { retype(c.add(5), c.add(n), ObjKind::Frame, G, ok_prep) }.unwrap(); + unsafe { retype(c.add(UT), c.add(n), ObjKind::Frame, G, ok_prep) }.unwrap(); let never = |_| -> Option { panic!("prep must not run") }; - for src in [1, 2, 3, 4, n, n + 1] { + for src in [1, 2, 3, 4, boot_slot::PART_CTL as usize, n, n + 1] { assert_eq!( unsafe { retype(c.add(src), c.add(n + 2), ObjKind::Frame, G, never) }, Err(CapError::NotUntyped), "source {src}" ); } - for dest in [1, 5, n] { + for dest in [1, 5, UT, n] { assert_eq!( - unsafe { retype(c.add(5), c.add(dest), ObjKind::Frame, G, never) }, + unsafe { retype(c.add(UT), c.add(dest), ObjKind::Frame, G, never) }, Err(CapError::Occupied), "dest {dest}" ); @@ -611,7 +614,7 @@ fn random_retypes_never_overlap() { .map(|i| r(i * 0x100_0000 + rng.below(4) * 0x800, granule * (1 + rng.below(12)))) .collect(); let (c, next) = filled(&memory, &[]); - let sources: Vec = (5..next as usize).collect(); + let sources: Vec = (UT..next as usize).collect(); let mut dest = next as usize; let mut carved: Vec = Vec::new(); for _ in 0..40 { @@ -680,6 +683,48 @@ fn console_rights_only_shrink() { } } +#[test] +fn the_partition_control_cannot_be_copied() { + let (c, _) = filled(&[r(0x4000_0000, 16 * G)], &[]); + let at = boot_slot::PART_CTL as usize; + unsafe { + assert_eq!(cap_at(c, at), Cap::PartCtl); + // 권한을 어떻게 고르든, 배지가 있든 없든 복사본은 생기지 않음 + for mask in [0, rights::R, rights::W, rights::ALL] { + for badge in [0, 7] { + assert_eq!(copy(c.add(at), c.add(30), mask, badge, false), Err(CapError::NotCopyable)); + } + } + assert_eq!(get(c, 30), None); + // 이동은 되고, 옮겨 간 자리에서도 복사는 안 됨 + move_cap(c.add(at), c.add(31)).unwrap(); + assert_eq!(get(c, at), None); + assert_eq!(cap_at(c, 31), Cap::PartCtl); + assert_eq!(copy(c.add(31), c.add(30), rights::ALL, 0, false), Err(CapError::NotCopyable)); + // 삭제하면 어디에도 남지 않음 + let mut log = Log::default(); + delete(c.add(31), &mut log).unwrap(); + for i in 1..48 { + assert!(get(c, i).is_none_or(|e| e.cap != Cap::PartCtl)); + } + } +} + +#[test] +fn a_partition_control_word_carries_nothing_else() { + let w = [KIND_PART_CTL, 0, 0, 0]; + assert_eq!(decode(&w).unwrap().unwrap().cap, Cap::PartCtl); + // 권한 비트, 오브젝트 주소, 매핑 기록, 꼬리 워드가 있으면 손상으로 봄 + for rights in 1u64..8 { + assert_eq!(decode(&[w[0] | rights << RIGHTS_SHIFT, 0, 0, 0]), Err(CapError::Corrupt)); + } + assert_eq!(decode(&[w[0] | 0x1000, 0, 0, 0]), Err(CapError::Corrupt)); + assert_eq!(decode(&[w[0] | FLAG_MAPPED, 0, 0, 0]), Err(CapError::Corrupt)); + assert_eq!(decode(&[w[0], 1, 0, 0]), Err(CapError::Corrupt)); + assert_eq!(decode(&[w[0], 0, 1, 0]), Err(CapError::Corrupt)); + assert_eq!(decode(&[w[0], 0, 0, 1]), Err(CapError::Corrupt)); +} + #[test] fn a_console_word_without_rights_or_with_execute_is_corrupt() { for rights in [0u64, 4, 5, 6, 7] { @@ -700,7 +745,7 @@ fn a_console_word_without_rights_or_with_execute_is_corrupt() { fn copy_rules_per_kind() { let (c, next) = filled(&[r(0x4000_0000, 16 * G)], &[]); let n = next as usize; - let ut = unsafe { c.add(5) }; + let ut = unsafe { c.add(UT) }; unsafe { retype(ut, c.add(n), ObjKind::Frame, G, ok_prep).unwrap(); retype(ut, c.add(n + 1), ObjKind::PageTable, G, ok_prep).unwrap(); @@ -759,7 +804,7 @@ fn a_copy_never_inherits_the_mapping_record() { level: 3, }); unsafe { - retype(c.add(5), c.add(n), ObjKind::Frame, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::Frame, G, ok_prep).unwrap(); update( c.add(n), Cap::Frame { @@ -787,8 +832,8 @@ fn update_only_changes_watermark_and_mapping() { let (c, next) = filled(&[r(0x4000_0000, 16 * G)], &[]); let n = next as usize; unsafe { - retype(c.add(5), c.add(n), ObjKind::Frame, G, ok_prep).unwrap(); - retype(c.add(5), c.add(n + 1), ObjKind::Endpoint, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::Frame, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n + 1), ObjKind::Endpoint, G, ok_prep).unwrap(); let frame = |base, rights| Cap::Frame { base, rights, @@ -814,8 +859,8 @@ fn update_only_changes_watermark_and_mapping() { size: 16 * G, used, }; - assert_eq!(update(c.add(5), ut(17 * G)), Err(CapError::Corrupt)); - update(c.add(5), ut(3 * G)).unwrap(); + assert_eq!(update(c.add(UT), ut(17 * G)), Err(CapError::Corrupt)); + update(c.add(UT), ut(3 * G)).unwrap(); assert_eq!(untypeds(c, 64), vec![(0x4000_0000, 16 * G, 3 * G)]); } } @@ -826,7 +871,7 @@ fn move_keeps_the_subtree_attached() { let n = next as usize; let other = node(16); unsafe { - retype(c.add(5), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); copy(c.add(n), c.add(20), rights::ALL, 1, false).unwrap(); copy(c.add(20), c.add(21), rights::ALL, 0, false).unwrap(); // 가운데 노드를 다른 CNode로 옮김 @@ -834,7 +879,7 @@ fn move_keeps_the_subtree_attached() { assert_eq!(move_cap(c.add(20), other.add(4)), Err(CapError::Empty)); assert_eq!(move_cap(c.add(n), other.add(3)), Err(CapError::Occupied)); // untyped도 옮길 수는 있고, 옮긴 뒤에도 자손이 붙어 있음 - move_cap(c.add(5), other.add(5)).unwrap(); + move_cap(c.add(UT), other.add(5)).unwrap(); assert!(has_descendants(other.add(5))); let mut log = Log::default(); @@ -856,7 +901,7 @@ fn delete_removes_descendants_and_finalizes_only_with_the_original() { let (c, next) = filled(&[r(0x4000_0000, 16 * G)], &[]); let n = next as usize; unsafe { - retype(c.add(5), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); copy(c.add(n), c.add(20), rights::ALL, 0, false).unwrap(); copy(c.add(20), c.add(21), rights::ALL, 0, false).unwrap(); copy(c.add(n), c.add(22), rights::ALL, 0, false).unwrap(); @@ -882,7 +927,7 @@ fn delete_removes_descendants_and_finalizes_only_with_the_original() { assert!(!log.removed[2].1); assert!(log.removed[3].1, "the original is the last cap of its object"); assert_eq!(get(c, 22), None); - assert!(!has_descendants(c.add(5))); + assert!(!has_descendants(c.add(UT))); } } @@ -892,26 +937,26 @@ fn revoking_an_ancestor_may_report_the_original_before_its_copies() { let n = next as usize; let mut log = Log::default(); unsafe { - retype(c.add(5), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); copy(c.add(n), c.add(20), rights::ALL, 3, false).unwrap(); copy(c.add(20), c.add(21), rights::ALL, 0, false).unwrap(); // 조상(untyped)의 회수는 리스트 순서대로 지움: 원본이 먼저, 복사본이 나중. // 콜백 구현은 이 순서를 견뎌야 하고, 반환 시점에는 전부 사라져 있어야 함 - revoke(c.add(5), &mut log).unwrap(); + revoke(c.add(UT), &mut log).unwrap(); } let order: Vec = log.removed.iter().map(|x| x.1).collect(); assert_eq!(order, vec![true, false, false]); for i in [n, 20, 21] { assert_eq!(get(c, i), None); } - assert!(!unsafe { has_descendants(c.add(5)) }); + assert!(!unsafe { has_descendants(c.add(UT)) }); } #[test] fn untyped_memory_is_reused_only_when_nothing_is_left() { let (c, next) = filled(&[r(0x4000_0000, 4 * G)], &[]); let n = next as usize; - let ut = unsafe { c.add(5) }; + let ut = unsafe { c.add(UT) }; let mut log = Log::default(); unsafe { for i in 0..4 { @@ -954,8 +999,8 @@ fn destroying_a_cnode_deletes_what_it_holds() { let mut log = Log::default(); unsafe { // 첫 untyped에서 CNode, 둘째 untyped에서 엔드포인트 - retype(c.add(5), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); - retype(c.add(6), c.add(n + 1), ObjKind::Endpoint, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); + retype(c.add(UT + 1), c.add(n + 1), ObjKind::Endpoint, G, ok_prep).unwrap(); log.containers.insert(0x4000_0000, (inner, 64)); // 엔드포인트의 원본을 CNode 안으로 옮기고 바깥에 복사본을 둠 move_cap(c.add(n + 1), inner.add(9)).unwrap(); @@ -965,7 +1010,7 @@ fn destroying_a_cnode_deletes_what_it_holds() { // 첫 untyped만 회수: CNode가 종료되면서 안에 든 케이퍼빌리티가 전부 // 삭제되고, 그중 원본이던 엔드포인트도 종료되어 바깥 복사본이 사라짐 - revoke(c.add(5), &mut log).unwrap(); + revoke(c.add(UT), &mut log).unwrap(); assert_eq!(get(c, n), None); assert_eq!(get(c, 30), None); for i in 0..64 { @@ -974,7 +1019,7 @@ fn destroying_a_cnode_deletes_what_it_holds() { } assert!(get(c, 3).is_some(), "the console original outside survives"); assert!(!has_descendants(c.add(3))); - assert!(!has_descendants(c.add(6)), "the endpoint in the other untyped is gone"); + assert!(!has_descendants(c.add(UT + 1)), "the endpoint in the other untyped is gone"); let originals: Vec = log.removed.iter().filter(|x| x.1).map(|x| x.0).collect(); assert_eq!(originals.len(), 2); assert!(matches!(originals[0], Cap::CNode { .. })); @@ -989,7 +1034,7 @@ fn bound_copies_are_reported_and_cannot_move() { let tcb = node(3); let mut log = Log::default(); unsafe { - retype(c.add(5), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); copy(c.add(n), tcb.add(1), rights::ALL, 0, true).unwrap(); assert!(get(tcb, 1).unwrap().bound); assert_eq!(move_cap(tcb.add(1), c.add(40)), Err(CapError::NotCopyable)); @@ -1011,9 +1056,9 @@ fn a_pair_copy_is_all_or_nothing() { let n = next as usize; let tcb = node(3); unsafe { - retype(c.add(5), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); - retype(c.add(5), c.add(n + 1), ObjKind::AddrSpace, G, ok_prep).unwrap(); - retype(c.add(5), c.add(n + 2), ObjKind::PageTable, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n + 1), ObjKind::AddrSpace, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n + 2), ObjKind::PageTable, G, ok_prep).unwrap(); // 둘째가 복사 불가, 비어 있음, 깊이 초과인 경우 첫째도 들어가지 않음 assert_eq!( @@ -1063,9 +1108,9 @@ fn derivation_depth_is_bounded() { (*c.add(3)).depth = MAX_DEPTH; assert_eq!(copy(c.add(3), c.add(20), rights::ALL, 0, false), Err(CapError::TooDeep)); assert_eq!(get(c, 20), None); - (*c.add(5)).depth = MAX_DEPTH; + (*c.add(UT)).depth = MAX_DEPTH; assert_eq!( - retype(c.add(5), c.add(20), ObjKind::Frame, G, |_| panic!("prep must not run")), + retype(c.add(UT), c.add(20), ObjKind::Frame, G, |_| panic!("prep must not run")), Err(CapError::TooDeep) ); (*c.add(3)).depth = u64::MAX; @@ -1079,7 +1124,7 @@ fn broken_links_stop_the_operation() { let n = next as usize; let mut log = Log::default(); unsafe { - retype(c.add(5), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::Endpoint, G, ok_prep).unwrap(); copy(c.add(n), c.add(20), rights::ALL, 0, false).unwrap(); // 자식의 역링크를 망가뜨림 (*c.add(20)).prev = c.add(3) as u64; @@ -1097,7 +1142,7 @@ fn a_container_whose_null_slot_is_used_is_refused() { let inner = node(8); let mut log = Log::default(); unsafe { - retype(c.add(5), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); + retype(c.add(UT), c.add(n), ObjKind::CNode, G, ok_prep).unwrap(); (*inner).aux = 1; log.containers.insert(0x4000_0000, (inner, 8)); assert_eq!(delete(c.add(n), &mut log), Err(CapError::Corrupt)); @@ -1180,6 +1225,7 @@ fn ident(cap: &Cap) -> (u8, u64) { match *cap { Cap::Untyped { base, .. } => (0, base), Cap::Console { .. } => (1, 0), + Cap::PartCtl => (3, 0), Cap::Frame { base, .. } | Cap::PageTable { base, .. } | Cap::Tcb { base } @@ -1703,7 +1749,7 @@ fn self_holding(granule: u64) -> (World, *mut Slot, *mut Slot, *mut Slot, u64, u let mut w = World::with(granule, 16); let root = w.root(); unsafe { - let ut = root.add(5); + let ut = root.add(UT); let (c_pa, c) = w.make(ut, root.add(10), ObjKind::CNode); copy(root.add(10), root.add(11), rights::ALL, 0, false).unwrap(); move_cap(root.add(10), c.add(3)).unwrap(); @@ -1766,20 +1812,20 @@ fn a_cnode_holding_its_own_original_delete_first_and_other_orders() { assert!(w.objs.contains(&(2, c_pa)), "orphaned self-holding CNode is still alive"); assert!(w.torn.contains(&(t as u64))); let root = w.root(); - revoke(root.add(5), &mut w).unwrap(); + revoke(root.add(UT), &mut w).unwrap(); w.check(); assert!(!w.objs.contains(&(2, c_pa)) && !w.objs.contains(&(2, e_pa))); - assert!(!has_descendants(root.add(5))); + assert!(!has_descendants(root.add(UT))); } // 모든 것이 살아 있는 채로 untyped를 바로 회수 let (mut w, _c, _c_copy, _e_copy, c_pa, _e_pa, _t) = self_holding(g); unsafe { let root = w.root(); - revoke(root.add(5), &mut w).unwrap(); + revoke(root.add(UT), &mut w).unwrap(); w.check(); assert!(!w.objs.contains(&(2, c_pa))); // 그 메모리는 처음부터 다시 나감 - let (pa, _) = w.make(root.add(5), root.add(20), ObjKind::Frame); + let (pa, _) = w.make(root.add(UT), root.add(20), ObjKind::Frame); assert_eq!(pa, 0x4000_0000); w.check(); } @@ -1787,10 +1833,10 @@ fn a_cnode_holding_its_own_original_delete_first_and_other_orders() { let (mut w, _c, _c_copy, _e_copy, c_pa, _e_pa, _t) = self_holding(g); unsafe { let root = w.root(); - delete(root.add(5), &mut w).unwrap(); + delete(root.add(UT), &mut w).unwrap(); w.check(); assert!(!w.objs.contains(&(2, c_pa))); - assert!(read(root.add(5)).unwrap().is_none()); + assert!(read(root.add(UT)).unwrap().is_none()); } } } @@ -1801,10 +1847,10 @@ fn an_untyped_parked_inside_a_cnode_carved_from_it() { let mut w = World::with(g, 16); let root = w.root(); unsafe { - let (c_pa, c) = w.make(root.add(5), root.add(10), ObjKind::CNode); - let (f_pa, _) = w.make(root.add(5), root.add(11), ObjKind::Frame); + let (c_pa, c) = w.make(root.add(UT), root.add(10), ObjKind::CNode); + let (f_pa, _) = w.make(root.add(UT), root.add(11), ObjKind::Frame); // untyped 자신을, 거기서 떼어 만든 CNode 안에 넣음 - move_cap(root.add(5), c.add(7)).unwrap(); + move_cap(root.add(UT), c.add(7)).unwrap(); w.check(); // 그 슬롯으로 회수: CNode가 죽고, 그 안을 비우면서 untyped 케이퍼빌리티도 삭제됨 revoke(c.add(7), &mut w).unwrap(); @@ -1816,8 +1862,8 @@ fn an_untyped_parked_inside_a_cnode_carved_from_it() { let mut w = World::with(g, 16); let root = w.root(); unsafe { - let (c_pa, c) = w.make(root.add(5), root.add(10), ObjKind::CNode); - move_cap(root.add(5), c.add(7)).unwrap(); + let (c_pa, c) = w.make(root.add(UT), root.add(10), ObjKind::CNode); + move_cap(root.add(UT), c.add(7)).unwrap(); move_cap(root.add(10), c.add(8)).unwrap(); w.check(); delete(c.add(7), &mut w).unwrap(); @@ -1833,8 +1879,8 @@ fn two_cnodes_holding_each_others_original() { let mut w = World::with(4096, 16); let root = w.root(); unsafe { - let (a_pa, a) = w.make(root.add(5), root.add(10), ObjKind::CNode); - let (b_pa, b) = w.make(root.add(5), root.add(11), ObjKind::CNode); + let (a_pa, a) = w.make(root.add(UT), root.add(10), ObjKind::CNode); + let (b_pa, b) = w.make(root.add(UT), root.add(11), ObjKind::CNode); copy(root.add(10), root.add(12), rights::ALL, 0, false).unwrap(); copy(root.add(11), root.add(13), rights::ALL, 0, false).unwrap(); // A의 원본은 B에, B의 원본은 A에 둠 @@ -1852,13 +1898,13 @@ fn two_cnodes_holding_each_others_original() { w.check(); // 둘 다 루트에서 닿지 않음. untyped로만 되찾을 수 있음 assert!(w.objs.contains(&(2, a_pa)) && w.objs.contains(&(2, b_pa))); - revoke(root.add(5), &mut w).unwrap() + revoke(root.add(UT), &mut w).unwrap() } _ => { delete(root.add(12), &mut w).unwrap(); delete(root.add(13), &mut w).unwrap(); w.check(); - revoke(root.add(5), &mut w).unwrap() + revoke(root.add(UT), &mut w).unwrap() } } w.check(); @@ -1874,7 +1920,7 @@ fn cnodes_nested_through_cnodes_with_tcbs_bound_across_levels() { let mut w = World::with(4096, 3 * DEPTH as u64 + 8); let root = w.root(); unsafe { - let ut = root.add(5); + let ut = root.add(UT); // i번째 층: CNode_i의 원본은 CNode_{i-1}의 1번 슬롯에 있음. CNode_i의 2번 // 슬롯에는 TCB의 원본이 있고, 그 TCB의 묶인 슬롯에는 CNode_i와 CNode_i의 // 3번 슬롯에 있는 주소 공간의 사본이 있음 diff --git a/crates/k0-ipc/src/console.rs b/crates/k0-ipc/src/console.rs index df1e2a0..3470a67 100644 --- a/crates/k0-ipc/src/console.rs +++ b/crates/k0-ipc/src/console.rs @@ -164,7 +164,14 @@ pub fn waiting() -> bool { /// 대기자가 그사이 케이퍼빌리티를 잃었으면 바이트를 쓰지 않고 REVOKED로 /// 깨웁니다. 깨울 까닭이 없으면 아무 일도 하지 않습니다. /// +/// 바이트는 대기자의 도메인이 도는 동안에만 전달합니다. 다른 도메인이 도는 +/// 중이면 바이트는 버퍼에 남고, 대기자의 도메인이 도는 틱에서 전달됩니다. +/// 그래서 입력이 언제 들어왔는지가 다른 도메인의 창 안에서 대기자의 큐를 +/// 바꾸지 않습니다. 케이퍼빌리티를 잃었거나 입력 경로가 꺼진 것은 바이트가 +/// 아니라 상태의 변화이므로 어느 도메인이 돌든 곧바로 알립니다. +/// /// # Arguments +/// `window` - 지금 도는 도메인 /// `current_ctx` - 현재 태스크의 컨텍스트가 살아 있는 참조. 대기 루프에서는 /// 블록된 현재 태스크가 대기자일 수 있고, 그때는 반환값을 이 /// 참조로 써야 함. 실행 중이던 태스크를 끊고 들어온 문맥에서는 @@ -173,7 +180,7 @@ pub fn waiting() -> bool { /// # Safety /// 스케줄러에 배타적으로 접근할 수 있는 커널 문맥(시스템 콜, EL0에서 들어온 /// 인터럽트의 끝, 대기 루프)에서만 불러야 합니다. -pub unsafe fn wake(mut current_ctx: Option<&mut Context>) { +pub unsafe fn wake(window: k0_sched::Domain, mut current_ctx: Option<&mut Context>) { let t = waiter(); if t.is_null() { return; @@ -190,6 +197,8 @@ pub unsafe fn wake(mut current_ctx: Option<&mut Context>) { Some((err::REVOKED as u64, 0, 0)) } else if off { Some((err::NO_DEVICE as u64, 0, 0)) + } else if k0_sched::domain_of(t) != window { + None } else { conin::pop().map(|(b, lost)| (0, u64::from(b), if lost { flag::LOST } else { 0 })) }; diff --git a/crates/k0-ipc/src/lib.rs b/crates/k0-ipc/src/lib.rs index 063a41a..022d7e0 100644 --- a/crates/k0-ipc/src/lib.rs +++ b/crates/k0-ipc/src/lib.rs @@ -409,9 +409,12 @@ pub fn sys_reply_recv(ctx: &mut Context) -> bool { /// 응답을 기다리고 있었으면 응답을 쥔 태스크의 자격을 지우고 REPLY_TIMEOUT /// 으로 깨웁니다. 그 태스크의 뒤늦은 응답은 받을 상대가 없어 건너뜁니다. /// 링크가 상태와 맞지 않으면 종료 처리와 똑같이 손상으로 보고 정지합니다. -/// 틱마다 한 번 부릅니다. +/// 그 도메인이 도는 틱마다 한 번 부릅니다. 다른 도메인의 대기자는 건드리지 +/// 않으며, 그 도메인이 도는 틱에서 깨어납니다(기한보다 늦을 수는 있어도 이를 +/// 수는 없음). /// /// # Arguments +/// `d` - 지금 도는 도메인 /// `now` - 지금의 틱 수 /// `current_ctx` - 현재 태스크의 컨텍스트에 대한 참조를 호출자가 쥐고 있으면 /// 그 참조. 실행할 태스크가 없어 대기 중일 때는 현재 태스크 자신이 기한을 @@ -421,12 +424,12 @@ pub fn sys_reply_recv(ctx: &mut Context) -> bool { /// # Safety /// EL0에서 진입한 예외의 핸들러(단일 코어, DAIF 마스크)에서만 호출해야 하고, /// `current_ctx`가 `Some`이면 현재 태스크의 컨텍스트여야 합니다. -pub unsafe fn expire_timeouts(now: u64, mut current_ctx: Option<&mut Context>) { +pub unsafe fn expire_timeouts(d: k0_sched::Domain, now: u64, mut current_ctx: Option<&mut Context>) { // SAFETY: 함수 계약대로 접근이 배타적이고, 기한 목록에는 블록된 태스크만 // 있으며 그 상태가 말하는 큐와 링크는 이 크레이트가 유지함 unsafe { let cur = k0_sched::current(); - k0_sched::expired(now, |t| { + k0_sched::expired(d, now, |t| { let status = match (*t).state { TaskState::BlockedSend | TaskState::BlockedRecv | TaskState::BlockedCall => { let ep = (*t).blocked_on as *mut Endpoint; diff --git a/crates/k0-part/Cargo.toml b/crates/k0-part/Cargo.toml new file mode 100644 index 0000000..fb223b3 --- /dev/null +++ b/crates/k0-part/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "k0-part" +version.workspace = true +edition.workspace = true +license.workspace = true +publish.workspace = true + +[dependencies] +k0-slice = { path = "../k0-slice" } diff --git a/crates/k0-part/src/clock.rs b/crates/k0-part/src/clock.rs new file mode 100644 index 0000000..8b13011 --- /dev/null +++ b/crates/k0-part/src/clock.rs @@ -0,0 +1,95 @@ +//! 틱 시각의 산술을 담는 모듈입니다. +//! +//! # Features +//! 틱 n의 예정 시각은 `t0 + n * period`이고 카운터만으로 정해집니다. 타이머 +//! 인터럽트가 왔을 때 그것이 몇 번째 틱인지, 비교값보다 이른 인터럽트인지를 +//! 여기서 판정합니다. 레지스터를 읽고 쓰는 일은 k0-arch가 하고 이 모듈은 +//! 하드웨어에 닿지 않으므로 호스트에서 시험합니다. +//! +//! 도메인이 바뀌는 틱은 보호 구간([guard])만큼 일찍 인터럽트를 겁니다. 전환 +//! 작업은 그 구간 안에서 끝내고, 예정 시각([due])이 될 때까지 기다렸다가 +//! 다음 도메인을 시작합니다. 그래서 구간보다 짧은 커널 경로는 다음 도메인의 +//! 시작 시각을 움직이지 못합니다. + +/// 타이머 인터럽트 하나에 대한 판정입니다. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Fire { + /// 걸어 둔 시각보다 일찍 온 인터럽트. 틱이 아니므로 비교값만 다시 겁니다 + Spurious, + /// 이 번호의 틱. 처리가 한 주기 넘게 늦었으면 번호가 여럿 건너뜁니다 + Tick(u64), +} + +/// 보호 구간의 길이를 주는 함수입니다. 주기의 1/40입니다. +/// +/// # Arguments +/// `period` - 틱 주기(카운터 단위) +pub const fn guard(period: u64) -> u64 { + period / 40 +} + +/// 틱 `n`의 예정 시각을 카운터 값으로 주는 함수입니다. +/// +/// 카운터의 범위를 넘으면 최댓값에 머뭅니다. 그런 틱은 [fire]가 틱으로 치지 +/// 않으므로 앞당겨지는 일 없이 틱이 멈출 뿐입니다. +/// +/// # Arguments +/// `t0` - 틱 0의 시각 +/// `period` - 틱 주기(카운터 단위) +/// `n` - 틱 번호 +pub const fn due(t0: u64, period: u64, n: u64) -> u64 { + match due_in_range(t0, period, n) { + Some(v) => v, + None => u64::MAX, + } +} + +/// 틱 `n`의 예정 시각이 카운터의 범위 안에 있으면 그 값을 주는 함수입니다. +const fn due_in_range(t0: u64, period: u64, n: u64) -> Option { + match n.checked_mul(period) { + Some(d) => t0.checked_add(d), + None => None, + } +} + +/// 타이머 인터럽트가 몇 번째 틱인지 판정하는 함수입니다. +/// +/// 번호는 카운터가 정합니다. 다음 틱을 건 시각보다 이르면 틱이 아니고, 한 +/// 주기 넘게 늦었으면 지나간 번호를 건너뛰어 카운터가 가리키는 번호를 줍니다. +/// +/// # Arguments +/// `now` - 지금의 카운터 값 +/// `t0` - 틱 0의 시각 +/// `period` - 틱 주기(카운터 단위) +/// `last` - 마지막으로 처리한 틱의 번호 +/// `early` - 다음 틱의 비교값을 예정 시각보다 얼마나 일찍 걸었는지(걸지 +/// 않았으면 0) +pub const fn fire(now: u64, t0: u64, period: u64, last: u64, early: u64) -> Fire { + // 번호가 더 오를 수 없거나 다음 틱의 시각이 카운터의 범위 밖이면 틱은 없음 + let Some(next) = last.checked_add(1) else { + return Fire::Spurious; + }; + let Some(armed) = due_in_range(t0, period, next) else { + return Fire::Spurious; + }; + if period == 0 || now < armed.saturating_sub(early) { + return Fire::Spurious; + } + let by_counter = now.saturating_sub(t0) / period; + if by_counter > next { + Fire::Tick(by_counter) + } else { + Fire::Tick(next) + } +} + +/// 틱 `n`의 예정 시각이 지났는지 알려 주는 함수입니다. +/// +/// # Arguments +/// `now` - 지금의 카운터 값 +/// `t0` - 틱 0의 시각 +/// `period` - 틱 주기(카운터 단위) +/// `n` - 틱 번호 +pub const fn reached(now: u64, t0: u64, period: u64, n: u64) -> bool { + now >= due(t0, period, n) +} diff --git a/crates/k0-part/src/clock_tests.rs b/crates/k0-part/src/clock_tests.rs new file mode 100644 index 0000000..37c066e --- /dev/null +++ b/crates/k0-part/src/clock_tests.rs @@ -0,0 +1,562 @@ +//! 틱 시각의 산술([crate::clock])을 기준과 견주어 검증하는 테스트 모듈입니다. +//! +//! 기준은 clock.rs와 따로 적었습니다. clock.rs는 u64의 포화 연산으로 적었고 기준은 +//! u128 위에서 넘침을 `min`으로 자르는 방식으로 적었으므로 같은 줄을 베낀 것이 +//! 아닙니다. 작은 수는 격자로 전부 돌리고 큰 수는 무작위와 경계값 격자로 돌립니다. +//! +//! 속성은 함수로 받습니다. 진짜 [fire]와 일부러 틀리게 만든 사본([Break])이 같은 +//! 속성 함수를 거치므로, 사본이 걸리는지는 `tests::deliberate_breaks_are_caught`가 +//! 확인합니다. +//! +//! 모형이 다루지 않는 것은 카운터 레지스터를 읽고 쓰는 일과 인터럽트가 실제로 +//! 언제 오는지입니다. 여기서는 카운터 값이 순서대로 주어진다고만 봅니다. + +use crate::clock::{Fire, due, fire, guard, reached}; + +const MAX: u64 = u64::MAX; + +/// 카운터 값 5개를 받아 틱을 판정하는 함수의 모양입니다. `(now, t0, period, last, early)` +type FireFn<'a> = &'a dyn Fn(u64, u64, u64, u64, u64) -> Fire; + +/// 일부러 틀리게 만든 판정입니다. 한 번에 하나만 틀립니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum Break { + /// 틱 번호를 카운터가 아니라 마지막 번호 + 1로 정함 + LastPlusOne, + /// 비교값보다 이른 인터럽트도 틱으로 침 + SpuriousIgnored, + /// 일찍 건 만큼의 앞당김을 무시함 + EarlyIgnored, + /// 다음 틱의 시각이 카운터 범위를 넘어도 최댓값으로 잘라 틱으로 침 + SaturatedRangeTicks, + /// 번호가 더 오를 수 없어도(last가 최댓값) 틱으로 침 + LastMaxTicks, +} + +pub(crate) const ALL_BREAKS: [Break; 5] = [ + Break::LastPlusOne, + Break::SpuriousIgnored, + Break::EarlyIgnored, + Break::SaturatedRangeTicks, + Break::LastMaxTicks, +]; + +fn broken(v: Break, now: u64, t0: u64, period: u64, last: u64, early: u64) -> Fire { + let next = last.saturating_add(1); + if v != Break::LastMaxTicks && last == MAX { + return Fire::Spurious; + } + if v != Break::SaturatedRangeTicks && o_due_exact(t0, period, next).is_none() { + return Fire::Spurious; + } + let by_counter = if period == 0 { 0 } else { now.saturating_sub(t0) / period }; + let lo = match v { + Break::EarlyIgnored => due(t0, period, next), + _ => due(t0, period, next).saturating_sub(early), + }; + if v != Break::SpuriousIgnored && (period == 0 || now < lo) { + return Fire::Spurious; + } + match v { + Break::LastPlusOne => Fire::Tick(next), + _ => Fire::Tick(by_counter.max(next)), + } +} + +/// 진짜 [fire]와 사본이 속성 함수에 같은 모양으로 들어가게 하는 함수입니다. +pub(crate) fn caught(v: Break) -> bool { + properties(&|a, b, c, d, e| broken(v, a, b, c, d, e), true).is_err() +} + +/// 기준의 틱 `n` 예정 시각입니다. 넘치면 u64의 최댓값에서 멈춥니다. +fn o_due(t0: u64, p: u64, n: u64) -> u64 { + let v = t0 as u128 + n as u128 * p as u128; + v.min(MAX as u128) as u64 +} + +/// 기준의 틱 `n` 예정 시각입니다. 카운터의 범위를 넘으면 None입니다. +fn o_due_exact(t0: u64, p: u64, n: u64) -> Option { + let v = t0 as u128 + n as u128 * p as u128; + if v > MAX as u128 { None } else { Some(v as u64) } +} + +/// 기준의 판정입니다. 주기가 0이거나 번호가 더 오를 수 없거나 다음 틱의 시각이 +/// 카운터의 범위를 넘으면 틱이 없으므로 Spurious입니다. +fn o_fire(now: u64, t0: u64, p: u64, last: u64, early: u64) -> Fire { + if p == 0 || last == MAX { + return Fire::Spurious; + } + let next = last + 1; + let Some(due_next) = o_due_exact(t0, p, next) else { + return Fire::Spurious; + }; + let armed = due_next.saturating_sub(early); + if now < armed { + return Fire::Spurious; + } + let by = if now >= t0 { (now - t0) / p } else { 0 }; + Fire::Tick(by.max(next)) +} + +/// 작은 수의 격자로 기준과 견줍니다. +fn grid(f: FireFn) -> Result<(), String> { + for t0 in 0..6u64 { + for p in 0..7u64 { + for last in 0..7u64 { + for early in 0..8u64 { + for now in 0..60u64 { + let (got, want) = (f(now, t0, p, last, early), o_fire(now, t0, p, last, early)); + if got != want { + return Err(format!( + "now {now} t0 {t0} period {p} last {last} early {early}: got {got:?} want {want:?}" + )); + } + } + } + } + } + } + Ok(()) +} + +/// 걸어 둔 시각의 바로 앞과 바로 뒤에서 Spurious가 갈립니다. +fn armed_edge(f: FireFn) -> Result<(), String> { + for t0 in [0u64, 3, 1000] { + for p in 1..=50u64 { + for last in [0u64, 1, 5, 40] { + for early in [0u64, 1, p / 40, p / 2, p - 1, p] { + let armed = o_due(t0, p, last + 1).saturating_sub(early); + if armed > 0 && f(armed - 1, t0, p, last, early) != Fire::Spurious { + return Err(format!("one count before the armed instant: t0 {t0} p {p} last {last} early {early}")); + } + if matches!(f(armed, t0, p, last, early), Fire::Spurious) { + return Err(format!("at the armed instant: t0 {t0} p {p} last {last} early {early}")); + } + } + } + } + } + Ok(()) +} + +/// 처리가 3.5주기 늦으면 카운터가 가리키는 번호에 내립니다. +fn late(f: FireFn) -> Result<(), String> { + for t0 in [0u64, 7, 1_000_000] { + for p in 2..=40u64 { + for last in [0u64, 1, 9, 100] { + let next = last + 1; + let now = o_due(t0, p, next) + 7 * p / 2; + if f(now, t0, p, last, 0) != Fire::Tick(next + 3) { + return Err(format!("3.5 periods late: t0 {t0} p {p} last {last} got {:?}", f(now, t0, p, last, 0))); + } + // 정확히 3주기 늦거나 4주기 직전 + if f(o_due(t0, p, next) + 3 * p, t0, p, last, 0) != Fire::Tick(next + 3) { + return Err(format!("3 periods late: t0 {t0} p {p} last {last}")); + } + if f(o_due(t0, p, next) + 4 * p - 1, t0, p, last, 0) != Fire::Tick(next + 3) { + return Err(format!("just before 4 periods late: t0 {t0} p {p} last {last}")); + } + } + } + } + Ok(()) +} + +/// 값이 u64의 끝에 가까운 곳의 경계 격자입니다. 패닉 없이 기준과 같아야 합니다. +fn near_max(f: FireFn) -> Result<(), String> { + let vals = |extra: &[u64]| { + let mut v = vec![0u64, 1, 2, 3, 39, 40, 41, 1000, MAX / 40, MAX / 3, MAX / 2, MAX - 3, MAX - 2, MAX - 1, MAX]; + v.extend_from_slice(extra); + v + }; + for &t0 in &vals(&[]) { + for &p in &vals(&[1 << 32, 1 << 40, 24_000_000]) { + for &last in &vals(&[MAX / p.max(1), (MAX / p.max(1)).saturating_sub(1)]) { + for &early in &[0u64, 1, guard(p), p / 2, MAX] { + for &now in &vals(&[t0.saturating_add(p), t0.saturating_sub(1)]) { + let (got, want) = (f(now, t0, p, last, early), o_fire(now, t0, p, last, early)); + if got != want { + return Err(format!( + "now {now} t0 {t0} period {p} last {last} early {early}: got {got:?} want {want:?}" + )); + } + } + } + } + } + } + Ok(()) +} + +struct Rng(u64); + +impl Rng { + fn next(&mut self) -> u64 { + self.0 = self.0.wrapping_add(0x9E37_79B9_7F4A_7C15); + let mut z = self.0; + z = (z ^ (z >> 30)).wrapping_mul(0xBF58_476D_1CE4_E5B9); + z = (z ^ (z >> 27)).wrapping_mul(0x94D0_49BB_1331_11EB); + z ^ (z >> 31) + } + + /// 크기를 가리지 않고 고르게 나오도록 비트 수를 먼저 정한 수입니다. + fn wide(&mut self) -> u64 { + match self.next() % 8 { + 0 => MAX - self.next() % 8, + 1 => self.next() % 8, + _ => self.next() >> (self.next() % 64), + } + } +} + +/// 큰 수를 무작위로 기준과 견줍니다. +fn random(f: FireFn, n: u64) -> Result<(), String> { + let mut r = Rng(0x1234_5678); + for _ in 0..n { + let (now, t0, p, last, early) = (r.wide(), r.wide(), r.wide(), r.wide(), r.wide()); + // 걸어 둔 시각 근처의 값도 만든다 + let near = o_due(t0, p, last.saturating_add(1)).saturating_sub(early); + for now in [now, near.saturating_sub(1), near, near.saturating_add(1), near.saturating_add(r.wide() % 1000)] { + let (got, want) = (f(now, t0, p, last, early), o_fire(now, t0, p, last, early)); + if got != want { + return Err(format!("now {now} t0 {t0} period {p} last {last} early {early}: got {got:?} want {want:?}")); + } + } + } + Ok(()) +} + +/// 카운터가 줄지 않는 열에 처리기가 하는 대로(틱이면 마지막 번호를 갱신하고 앞당김을 +/// 없앰, 보호 구간이 필요하면 다시 거는 것을 흉내 냄) 적용해 번호의 성질을 봅니다. +fn drive(f: FireFn, n: u64) -> Result<(), String> { + let mut r = Rng(0xFEED); + for case in 0..n { + let p = 1 + r.next() % 1000; + let t0 = r.next() % 5000; + let mut last = r.next() % 4; + let mut early = 0u64; + let mut now = t0 + r.next() % (3 * p); + let mut seen: Vec = Vec::new(); + for _ in 0..200 { + let step = match r.next() % 6 { + 0 => 0, + 1 => 1 + r.next() % 3, + 2 => p / 2, + 3 => p, + 4 => p + p / 2 + r.next() % p, + _ => 3 * p + p / 2, + }; + now = now.saturating_add(step); + match f(now, t0, p, last, early) { + Fire::Spurious => { + // 이른 인터럽트: 걸어 둔 시각보다 정말로 이르다 + let armed = o_due_exact(t0, p, last + 1).map(|d| d.saturating_sub(early)); + if let Some(armed) = armed + && now >= armed + { + return Err(format!("case {case}: Spurious at {now} but armed at {armed}")); + } + } + Fire::Tick(k) => { + if k <= last { + return Err(format!("case {case}: index {k} not after {last}")); + } + if seen.contains(&k) { + return Err(format!("case {case}: index {k} repeated")); + } + let by_counter = (now - t0) / p; + if k < by_counter { + return Err(format!("case {case}: index {k} but the counter says {by_counter} at {now}")); + } + if k > last + 1 && k != by_counter { + return Err(format!("case {case}: jump to {k} but the counter says {by_counter}")); + } + // 번호가 예정 시각(앞당김만큼 일찍은 허용)보다 이르게 처리되지 않았다 + if now < o_due(t0, p, k).saturating_sub(early) { + return Err(format!("case {case}: index {k} taken at {now} before its time")); + } + seen.push(k); + last = k; + early = if r.next() % 2 == 0 { guard(p) } else { 0 }; + } + } + } + } + Ok(()) +} + +/// 카운터가 u64의 끝까지 오르는 열에서 번호의 성질과 기준과의 일치를 봅니다. +/// +/// 틱의 번호는 마지막 번호보다 언제나 크고 되풀이되지 않으며, 번호가 최댓값에 +/// 닿은 뒤에는 틱이 다시 오지 않습니다. 틱으로 친 번호의 예정 시각은 카운터의 +/// 범위 안에 있습니다. +fn drive_top(f: FireFn) -> Result<(), String> { + let mut r = Rng(0xA11CE); + let periods = [1u64, 2, 3, 40, 1 << 20, 1 << 32, 1 << 40, MAX / 3, MAX / 2, MAX]; + let origins = [0u64, 1, 1000, MAX / 2, MAX - 1000, MAX - 5, MAX]; + for case in 0..30_000u64 { + let p = periods[(r.next() % periods.len() as u64) as usize]; + let t0 = origins[(r.next() % origins.len() as u64) as usize]; + let top = MAX / p; + let starts = [0, 5, top.saturating_sub(3), top.saturating_sub(1), top, top.saturating_add(1), MAX - 3, MAX - 1]; + let mut last = starts[(r.next() % starts.len() as u64) as usize]; + let mut early = 0u64; + let mut now = match r.next() % 3 { + 0 => 0, + 1 => t0, + _ => t0.saturating_add(r.next() % (3 * p.min(1 << 61))), + }; + let mut seen: Vec = Vec::new(); + for i in 0..40 { + let step = match r.next() % 7 { + 0 => 0, + 1 => 1, + 2 => p, + 3 => p.saturating_add(1), + 4 => r.wide(), + 5 => MAX / 2, + _ => MAX, + }; + now = now.saturating_add(step); + if i == 39 { + now = MAX; + } + let got = f(now, t0, p, last, early); + let want = o_fire(now, t0, p, last, early); + if got != want { + return Err(format!( + "case {case}: now {now} t0 {t0} period {p} last {last} early {early}: got {got:?} want {want:?}" + )); + } + if let Fire::Tick(k) = got { + if last == MAX { + return Err(format!("case {case}: a tick after the index reached the top")); + } + if k <= last || seen.contains(&k) { + return Err(format!("case {case}: index {k} after {last} goes back or repeats")); + } + if o_due_exact(t0, p, k).is_none() { + return Err(format!("case {case}: index {k} has no due instant in the counter range")); + } + seen.push(k); + last = k; + early = if r.next() % 2 == 0 { guard(p) } else { 0 }; + } + } + } + Ok(()) +} + +/// 모든 속성입니다. 가벼운 쪽(`quick`)은 깨뜨리기 시험이 씁니다. +pub(crate) fn properties(f: FireFn, quick: bool) -> Result<(), String> { + grid(f).map_err(|e| format!("grid: {e}"))?; + armed_edge(f).map_err(|e| format!("armed edge: {e}"))?; + late(f).map_err(|e| format!("late: {e}"))?; + near_max(f).map_err(|e| format!("near max: {e}"))?; + random(f, if quick { 20_000 } else { 400_000 }).map_err(|e| format!("random: {e}"))?; + drive(f, if quick { 200 } else { 3000 }).map_err(|e| format!("sequence: {e}"))?; + drive_top(f).map_err(|e| format!("sequence to the top: {e}"))?; + Ok(()) +} + +#[test] +fn fire_matches_the_independent_oracle() { + properties(&fire, false).unwrap(); +} + +#[test] +fn a_copy_without_a_break_passes_and_each_break_fails() { + properties(&|a, b, c, d, e| fire(a, b, c, d, e), true).unwrap(); + for v in ALL_BREAKS { + let r = properties(&|a, b, c, d, e| broken(v, a, b, c, d, e), true); + println!("{v:?}: {r:?}"); + assert!(r.is_err(), "{v:?} passed the clock properties"); + } +} + +#[test] +fn spurious_exactly_before_the_armed_instant() { + for (t0, p, last, early) in [(0u64, 100u64, 0u64, 0u64), (0, 100, 0, 25), (50, 40, 7, 1), (50, 40, 7, 39)] { + let armed = due(t0, p, last + 1) - early; + for now in 0..armed { + assert_eq!(fire(now, t0, p, last, early), Fire::Spurious, "now {now} armed {armed}"); + } + assert_eq!(fire(armed, t0, p, last, early), Fire::Tick(last + 1)); + assert!(matches!(fire(armed + 1, t0, p, last, early), Fire::Tick(_))); + } +} + +#[test] +fn now_exactly_at_due_and_one_count_before_due_minus_early() { + let (t0, p, last) = (1000u64, 600u64, 9u64); + let d = due(t0, p, 10); + assert_eq!(d, 7000); + assert_eq!(fire(d, t0, p, last, 0), Fire::Tick(10)); + assert_eq!(fire(d - 1, t0, p, last, 0), Fire::Spurious); + let g = guard(p); + assert_eq!(g, 15); + assert_eq!(fire(d - g, t0, p, last, g), Fire::Tick(10)); + assert_eq!(fire(d - g - 1, t0, p, last, g), Fire::Spurious); + // 일찍 걸었어도 예정 시각 뒤의 인터럽트는 같은 번호의 틱이다 + assert_eq!(fire(d, t0, p, last, g), Fire::Tick(10)); + // 일찍 받은 틱의 번호는 카운터가 가리키는 이전 번호로 내려가지 않는다 + assert_eq!((d - g - t0) / p, 9); + assert_eq!(fire(d - g, t0, p, last, g), Fire::Tick(10)); +} + +#[test] +fn period_zero_never_panics_and_never_ticks() { + for t0 in [0u64, 1, MAX] { + for last in [0u64, 5, MAX] { + for early in [0u64, 1, MAX] { + for now in [0u64, 1, 1000, MAX - 1, MAX] { + assert_eq!(fire(now, t0, 0, last, early), Fire::Spurious); + } + } + } + } + assert_eq!(due(7, 0, 12345), 7); + assert!(reached(7, 7, 0, 12345)); + assert!(!reached(6, 7, 0, 12345)); + assert_eq!(guard(0), 0); +} + +#[test] +fn values_near_the_top_do_not_wrap_to_an_earlier_instant() { + // 예정 시각은 번호에 대해 줄지 않고 t0보다 이르지 않다 + for t0 in [0u64, 1, MAX / 2, MAX - 5, MAX] { + for p in [1u64, 2, 40, 1 << 32, MAX / 3, MAX / 2, MAX - 1, MAX] { + let mut prev = t0; + for n in [0u64, 1, 2, 3, 100, MAX / 2, MAX - 1, MAX] { + let d = due(t0, p, n); + assert!(d >= t0, "due below t0: t0 {t0} p {p} n {n}"); + assert_eq!(d, o_due(t0, p, n)); + assert!(d >= prev, "due went back: t0 {t0} p {p} n {n}"); + prev = d; + } + } + } + // 예정 시각은 범위를 넘으면 최댓값에 머문다 + assert_eq!(due(MAX - 1, 1 << 40, 5), MAX); + assert_eq!(due(MAX, 1, 1), MAX); + assert_eq!(due(0, MAX, 1), MAX); + assert_eq!(due(0, MAX, 2), MAX); + // 다음 틱의 시각이 범위를 넘으면 카운터가 최댓값이어도 틱이 아니다 + assert_eq!(fire(MAX - 1, MAX - 1, 1 << 40, 4, 0), Fire::Spurious); + assert_eq!(fire(MAX, MAX, 1, 0, 0), Fire::Spurious); + // 시각이 범위 안이면 앞당김이 아무리 커도 틱이다(비교값은 0으로 잘림) + assert_eq!(fire(MAX, MAX - 1, 1, 0, MAX), Fire::Tick(1)); + // 결함 보고의 두 입력: 곱이 넘침, 번호가 더 오를 수 없음 + assert_eq!(fire(MAX, 0, 1 << 40, (1 << 24) - 1, 0), Fire::Spurious); + assert_eq!(fire(MAX, 0, 1, MAX, 0), Fire::Spurious); + // 곱이 범위 안에 마지막으로 드는 번호는 틱이다(2^24 - 1번의 시각은 2^64 - 2^40) + assert_eq!(due(0, 1 << 40, (1 << 24) - 1), MAX - ((1 << 40) - 1)); + assert_eq!(fire(MAX, 0, 1 << 40, (1 << 24) - 2, 0), Fire::Tick((1 << 24) - 1)); + assert_eq!(fire(MAX - ((1 << 40) - 1) - 1, 0, 1 << 40, (1 << 24) - 2, 0), Fire::Spurious); + // t0가 크면 합이 먼저 넘친다 + assert_eq!(fire(MAX, MAX, 1, 0, 0), Fire::Spurious); + assert_eq!(fire(MAX - 1, MAX - 1, 1, 0, 0), Fire::Spurious); + assert_eq!(fire(MAX, MAX - 1, 1, 0, 0), Fire::Tick(1)); + // 시각이 범위 끝에 닿는 번호는 틱이고, 그 번호 다음은 더 오를 수 없다 + assert_eq!(fire(MAX - 1, 0, 1, MAX - 2, 0), Fire::Tick(MAX - 1)); + assert_eq!(fire(MAX, 0, 1, MAX - 1, 0), Fire::Tick(MAX)); + assert_eq!(fire(MAX - 1, 0, 1, MAX - 1, 0), Fire::Spurious); + for early in [0u64, 1, MAX] { + assert_eq!(fire(MAX, 0, 1, MAX, early), Fire::Spurious); + assert_eq!(fire(MAX, 7, 3, MAX, early), Fire::Spurious); + } + // 번호는 건너뛰어 끝에 닿을 수 있고, 그 뒤에는 틱이 없다 + assert_eq!(fire(MAX, 0, 1, 5, 0), Fire::Tick(MAX)); + assert_eq!(fire(MAX, 0, 1, MAX, 0), Fire::Spurious); + // 큰 t0에서 now가 t0보다 이르면 번호는 다음 번호 이하로 내려가지 않는다 + assert_eq!(fire(0, MAX / 2, 1000, 3, MAX), Fire::Tick(4)); +} + +#[test] +fn reached_agrees_with_due() { + for t0 in 0..5u64 { + for p in 0..5u64 { + for n in 0..6u64 { + for now in 0..40u64 { + assert_eq!(reached(now, t0, p, n), now >= o_due(t0, p, n), "now {now} t0 {t0} p {p} n {n}"); + } + } + } + } + // 앞당김이 없을 때 fire가 틱이 되는 것은 다음 번호의 예정 시각에 닿은 것과 같다 + let mut r = Rng(99); + for _ in 0..200_000 { + let (now, t0, p, last) = (r.wide(), r.wide(), r.wide(), r.wide() % (MAX - 1)); + if p == 0 { + continue; + } + let ticks = !matches!(fire(now, t0, p, last, 0), Fire::Spurious); + // 시각이 카운터의 범위를 넘는 번호는 reached가 최댓값에서 참이어도 틱이 아니다 + let in_range = o_due_exact(t0, p, last + 1).is_some(); + assert_eq!(ticks, in_range && reached(now, t0, p, last + 1), "now {now} t0 {t0} p {p} last {last}"); + if !in_range { + assert_eq!(due(t0, p, last + 1), MAX); + assert_eq!(fire(MAX, t0, p, last, 0), Fire::Spurious); + } + let d = due(t0, p, last + 1); + assert_eq!(reached(now, t0, p, last + 1), now >= d); + if d > 0 { + assert!(!reached(d - 1, t0, p, last + 1)); + } + assert!(reached(d, t0, p, last + 1)); + } +} + +#[test] +fn guard_is_a_fortieth_of_the_period() { + for p in 0..=5000u64 { + let g = guard(p); + // 독립된 식 40g <= p < 40g + 40 + assert!(40 * g <= p && p < 40 * g + 40, "p {p} g {g}"); + if p > 0 { + assert!(g < p); + } + } + assert_eq!(guard(39), 0); + assert_eq!(guard(40), 1); + assert_eq!(guard(24_000_000), 600_000); + assert_eq!(guard(MAX), MAX / 40); + // 앞당긴 비교값은 앞 번호의 예정 시각보다 늦다(앞 번호와 헷갈리지 않음) + for p in [40u64, 41, 1000, 24_000_000, 1 << 40] { + for n in 1..4u64 { + assert!(due(5, p, n + 1) - guard(p) > due(5, p, n)); + } + } +} + +#[test] +fn the_index_never_goes_back_or_repeats_over_any_counter_sequence() { + drive(&fire, 6000).unwrap(); + // 작은 수의 모든 비감소 열이 아니라 모든 두 걸음 열을 격자로 본다 + for p in 1..=6u64 { + for t0 in 0..4u64 { + for last in 0..4u64 { + for early in 0..=p { + for a in 0..40u64 { + for b in a..40u64 { + let mut l = last; + let mut e = early; + let mut prev: Option = None; + for now in [a, b] { + if let Fire::Tick(k) = fire(now, t0, p, l, e) { + assert!(k > l); + if let Some(q) = prev { + assert!(k > q); + } + prev = Some(k); + l = k; + e = 0; + } + } + } + } + } + } + } + } +} diff --git a/crates/k0-part/src/lib.rs b/crates/k0-part/src/lib.rs new file mode 100644 index 0000000..8f85abd --- /dev/null +++ b/crates/k0-part/src/lib.rs @@ -0,0 +1,506 @@ +//! 시간 분할 표에 따라 어느 도메인이 CPU를 쓰는지 정하고 그 안의 태스크 전환을 +//! 판정하는 크레이트입니다. +//! +//! # Features +//! 태스크는 도메인에 속하고, 표(Table)가 "어느 도메인이 몇 틱 동안 도는가"를 +//! 정합니다. 이 크레이트는 스케줄링 판정을 전부 담고 하드웨어와 준비 큐에는 +//! 닿지 않습니다. 준비 큐, 현재 태스크 설치, 기한 목록은 [Env]를 통해 커널이 +//! 맡으므로 호스트 테스트가 같은 코드를 가짜 환경 위에서 돌립니다. +//! +//! 규칙은 다음과 같습니다. +//! +//! - 틱 번호 n에서 도는 도메인은 표와 n만으로 정해집니다. 다른 도메인의 +//! 태스크가 무엇을 하든 바뀌지 않습니다. +//! - 도메인의 창이 열려 있는데 그 도메인에 준비된 태스크가 없으면 CPU는 +//! 놉니다. 다른 도메인에 넘어가지 않습니다(남는 시간의 양도 없음). +//! - 깨어나는 태스크는 자기 도메인의 큐에만 들어갑니다. 깨우는 일은 이 +//! 크레이트의 사건이 아니며 커널이 `Env::push`에 태스크 자신의 도메인을 +//! 넘겨 합니다. +//! - 도메인 안에서는 k0-slice의 틱 규칙이 그대로 쓰입니다. 창의 경계에서는 +//! 도는 태스크에 규칙을 한 번 적용한 뒤 자기 도메인 큐에 세워 두고, 그 +//! 도메인의 다음 창에서 큐 순서대로 다시 들어옵니다. +//! - 표를 바꾸면 현재 틱 + 2에서 표의 0번 항목부터 효력이 생깁니다. +//! +//! 틱이 늦게 처리되어 번호가 여럿 건너뛰어도 사건은 한 번이고, 도는 도메인은 +//! 도착한 번호로 정해집니다. +//! +//! 이 크레이트가 주장하는 것은 "도메인 사이에서 스케줄러를 거치는 채널을 +//! 닫는다"까지입니다. 캐시, 예측기, 커널 경로의 길이 같은 다른 채널은 다루지 +//! 않습니다. 도메인이 공유하기로 한 오브젝트(엔드포인트 등)를 통한 깨움도 +//! 일부러 연 채널이라 주장 밖입니다. +//! +//! # Examples +//! ```rust,ignore +//! let mut core: Core = Core::new(); +//! core.start(&mut env, first); +//! core.set_table(table); +//! let next = core.tick(&mut env); +//! ``` + +#![cfg_attr(not(test), no_std)] +#![forbid(unsafe_code)] + +use k0_slice::{Entry, Slice, Verdict}; + +pub mod clock; + +#[cfg(test)] +mod clock_tests; +#[cfg(test)] +mod model_tests; +#[cfg(test)] +mod tests; + +/// 도메인의 최대 개수 +pub const MAX_DOMAINS: usize = 8; + +/// 표 항목의 최대 개수 +pub const MAX_ENTRIES: usize = 16; + +/// 창 하나의 최대 길이(틱) +pub const MAX_WINDOW: u32 = 255; + +/// 태스크가 속하는 도메인의 번호를 담는 구조체입니다. +/// +/// 값은 항상 [MAX_DOMAINS]보다 작습니다. 0번은 루트 태스크의 도메인입니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct Domain(u8); + +impl Domain { + /// 부팅 때 루트 태스크가 속하는 도메인 + pub const ROOT: Domain = Domain(0); + + /// 번호가 범위 안일 때만 도메인을 만드는 함수입니다. + /// + /// # Arguments + /// `id` - 도메인 번호(0 이상 [MAX_DOMAINS] 미만) + pub const fn new(id: u8) -> Option { + if (id as usize) < MAX_DOMAINS { Some(Domain(id)) } else { None } + } + + /// 도메인 번호를 주는 함수입니다. + pub const fn id(self) -> u8 { + self.0 + } + + /// 도메인별 배열의 첨자로 쓸 값을 주는 함수입니다. + pub const fn index(self) -> usize { + self.0 as usize + } +} + +/// 표를 읽거나 만들 때 거절된 까닭을 나타내는 열거형입니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum TableError { + /// 항목 수가 0이거나 [MAX_ENTRIES]보다 큼 + Count, + /// 창의 길이가 0이거나 [MAX_WINDOW]보다 큼 + Window, + /// 도메인 번호가 [MAX_DOMAINS] 이상임 + Domain, + /// 쓰지 않는 비트가 0이 아님 + Reserved, +} + +/// 도메인이 도는 순서와 길이를 담은 되풀이 표를 나타내는 구조체입니다. +/// +/// 항목은 (도메인, 틱 수)이고 표는 0번 항목부터 차례로 돌다가 끝나면 처음으로 +/// 돌아갑니다. 만들 때 모든 항목이 검증되므로 이 타입의 값은 언제나 올바릅니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Table { + dom: [u8; MAX_ENTRIES], + ticks: [u8; MAX_ENTRIES], + len: u8, + cycle: u16, +} + +impl Table { + /// 도메인 0 하나가 1틱씩 도는 기본 표입니다. 오늘의 스케줄러와 같습니다. + pub const DEFAULT: Table = Table { + dom: [0; MAX_ENTRIES], + ticks: { + let mut t = [0; MAX_ENTRIES]; + t[0] = 1; + t + }, + len: 1, + cycle: 1, + }; + + /// 항목 목록에서 표를 만드는 함수입니다. + /// + /// # Arguments + /// `entries` - (도메인, 틱 수) 목록 + /// + /// # Errors + /// 항목 수가 0이거나 [MAX_ENTRIES]보다 크면 [TableError::Count], 틱 수가 0이거나 + /// [MAX_WINDOW]보다 크면 [TableError::Window]입니다. + pub fn from_entries(entries: &[(Domain, u32)]) -> Result { + if entries.is_empty() || entries.len() > MAX_ENTRIES { + return Err(TableError::Count); + } + let mut t = Table { dom: [0; MAX_ENTRIES], ticks: [0; MAX_ENTRIES], len: 0, cycle: 0 }; + for (i, &(d, w)) in entries.iter().enumerate() { + if w == 0 || w > MAX_WINDOW { + return Err(TableError::Window); + } + t.dom[i] = d.0; + t.ticks[i] = w as u8; + t.cycle += w as u16; + } + t.len = entries.len() as u8; + Ok(t) + } + + /// 시스템 콜의 레지스터에서 표를 읽는 함수입니다. + /// + /// 항목 i는 `regs[i / 4]`의 `16 * (i % 4)`번째 비트에서 시작하는 16비트이고 + /// 값은 `(틱 수 << 8) | 도메인`입니다. 틱 수는 1 이상 255 이하, 도메인은 0 + /// 이상 7 이하이며 `count` 뒤의 칸은 모두 0이어야 합니다. + /// + /// # Arguments + /// `count` - 항목 수(x1) + /// `regs` - 항목이 든 레지스터 x2부터 x5 + /// + /// # Errors + /// 항목 수가 범위 밖이면 [TableError::Count], 그다음 순서대로 항목마다 도메인이 + /// 범위 밖이면 [TableError::Domain], 틱 수가 0이면 [TableError::Window], 마지막으로 + /// `count` 뒤의 칸이 0이 아니면 [TableError::Reserved]입니다. + pub fn decode(count: u64, regs: [u64; 4]) -> Result { + if count == 0 || count > MAX_ENTRIES as u64 { + return Err(TableError::Count); + } + let slot = |i: usize| ((regs[i / 4] >> (16 * (i % 4))) & 0xffff) as u16; + let count = count as usize; + let mut t = Table { dom: [0; MAX_ENTRIES], ticks: [0; MAX_ENTRIES], len: count as u8, cycle: 0 }; + for i in 0..count { + let v = slot(i); + let (d, w) = ((v & 0xff) as u8, (v >> 8) as u8); + if d as usize >= MAX_DOMAINS { + return Err(TableError::Domain); + } + if w == 0 { + return Err(TableError::Window); + } + t.dom[i] = d; + t.ticks[i] = w; + t.cycle += w as u16; + } + for i in count..MAX_ENTRIES { + if slot(i) != 0 { + return Err(TableError::Reserved); + } + } + Ok(t) + } + + /// 표에 그 도메인의 창이 하나라도 있는지 알려 주는 함수입니다. + pub fn contains(&self, d: Domain) -> bool { + self.dom[..self.len as usize].contains(&d.0) + } + + /// 표에 루트 도메인밖에 없는지 알려 주는 함수입니다. 그런 표는 창의 길이와 + /// 상관없이 오늘의 스케줄러와 똑같이 움직입니다. + pub fn is_default(&self) -> bool { + self.dom[..self.len as usize].iter().all(|&d| d == 0) + } + + /// 항목 수를 주는 함수입니다. + pub fn len(&self) -> usize { + self.len as usize + } + + /// 항목이 없는지 알려 주는 함수입니다. 올바른 표에서는 언제나 false입니다. + pub fn is_empty(&self) -> bool { + self.len == 0 + } + + /// i번 항목을 주는 함수입니다. + /// + /// # Arguments + /// `i` - 항목 번호 + pub fn entry(&self, i: usize) -> Option<(Domain, u32)> { + if i < self.len as usize { Some((Domain(self.dom[i]), self.ticks[i] as u32)) } else { None } + } + + /// 표 한 바퀴의 틱 수를 주는 함수입니다. + pub fn cycle(&self) -> u32 { + self.cycle as u32 + } + + /// 표가 시작한 틱에서 `offset`틱 뒤에 도는 도메인을 주는 함수입니다. + /// + /// # Arguments + /// `offset` - 표의 0번 항목이 시작한 틱부터 센 틱 수 + pub fn domain_at(&self, offset: u64) -> Domain { + let mut r = offset % self.cycle as u64; + for i in 0..self.len as usize { + if r < self.ticks[i] as u64 { + return Domain(self.dom[i]); + } + r -= self.ticks[i] as u64; + } + Domain::ROOT + } +} + +/// 스케줄러가 커널에 요구하는 동작을 모은 트레이트입니다. +/// +/// 준비 큐는 도메인마다 하나이고 이 크레이트는 큐의 내용을 모릅니다. 태스크는 +/// `T`로 표현되며 도메인은 태스크 자신(TCB)에서 읽습니다. +pub trait Env { + /// 지금까지 센 틱 번호를 주는 함수입니다. + fn now(&self) -> u64; + /// 태스크가 속한 도메인을 주는 함수입니다. + fn domain(&self, t: T) -> Domain; + /// 태스크를 Ready로 두고 도메인 큐의 뒤에 넣는 함수입니다. + fn push(&mut self, d: Domain, t: T); + /// 태스크를 Ready로 두고 도메인 큐의 앞에 넣는 함수입니다. + fn push_front(&mut self, d: Domain, t: T); + /// 도메인 큐의 앞에서 태스크를 꺼내는 함수입니다. + fn pop(&mut self, d: Domain) -> Option; + /// 태스크를 Running으로 두고 현재 태스크, 문맥, 주소 공간을 바꾸는 함수입니다. + fn run(&mut self, t: T); + /// 창의 경계에서 새 도메인에 들어갈 때 부르는 함수입니다(TLB 비우기). + fn enter_domain(&mut self, d: Domain); + /// 그 도메인의 일만 하는 함수입니다. 콘솔 입력으로 깨울 태스크를 먼저, 그다음 + /// 기한이 지난 대기자를 깨웁니다. 다른 도메인에는 손대지 않습니다. + fn serve(&mut self, d: Domain, now: u64); +} + +/// 사건을 처리한 뒤 CPU가 할 일을 나타내는 열거형입니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Next { + /// 이 태스크가 실행 중이거나 막 실행됨 + Run(T), + /// 실행할 태스크가 없으니 인터럽트를 기다림 + Idle, +} + +/// 도메인 표, 도는 도메인, 현재 태스크, 틱 규칙의 상태를 담은 구조체입니다. +/// +/// 사건 함수 말고는 상태를 바꾸는 길이 없습니다. 커널은 CPU를 받은 경위(틱의 +/// 판정인지 틱 사이인지)를 직접 고르지 않고 사건의 이름으로 알립니다. +pub struct Core { + table: Table, + epoch: u64, + pending: Option<(Table, u64)>, + seen: u64, + rd: Domain, + running: Option, + slice: Slice, +} + +impl Core { + /// 기본 표와 빈 상태로 시작하는 함수입니다. + pub const fn new() -> Self { + Self { + table: Table::DEFAULT, + epoch: 0, + pending: None, + seen: 0, + rd: Domain::ROOT, + running: None, + slice: Slice::new(), + } + } + + /// 틱 `k`에서 도는 도메인을 주는 함수입니다. 상태는 바꾸지 않습니다. + fn plan_at(&self, k: u64) -> Domain { + if let Some((t, s)) = &self.pending + && k >= *s + { + return t.domain_at(k - *s); + } + self.table.domain_at(k.saturating_sub(self.epoch)) + } + + /// 시작 틱이 `n` 이하인 보류 표를 표로 올리는 함수입니다. + fn advance(&mut self, n: u64) { + if let Some((t, s)) = self.pending + && s <= n + { + self.table = t; + self.epoch = s; + self.pending = None; + } + } + + fn status(&self) -> Next { + match self.running { + Some(c) => Next::Run(c), + None => Next::Idle, + } + } + + /// 현재 태스크를 바꾸는 유일한 자리입니다. 경위를 인자로 받아 면제를 대입합니다. + fn switch>(&mut self, env: &mut E, x: T, how: Entry) { + self.slice.entered(how); + self.running = Some(x); + env.run(x); + } + + /// 도메인 `d`의 큐 앞을 틱의 판정으로 들여보내는 함수입니다. + fn enter>(&mut self, env: &mut E, d: Domain) -> Next { + match env.pop(d) { + Some(x) => { + self.switch(env, x, Entry::Tick); + Next::Run(x) + } + None => Next::Idle, + } + } + + /// 루트 태스크로 제어권을 넘길 때 부르는 함수입니다. + /// + /// 루트 태스크는 주기의 중간에 들어오므로 첫 틱 하나를 넘깁니다. 표는 기본 + /// 표이고 도는 도메인은 루트입니다. + /// + /// # Arguments + /// `first` - 첫 태스크 + pub fn start>(&mut self, env: &mut E, first: T) { + *self = Self::new(); + self.seen = env.now(); + self.epoch = self.seen; + self.switch(env, first, Entry::Between); + } + + /// 현재 태스크가 CPU를 내놓을 때(YIELD) 부르는 함수입니다. + /// + /// 같은 도메인에 준비된 다른 태스크가 있으면 현재 태스크를 큐 뒤에 세우고 + /// 큐 앞을 틱 사이의 전환으로 실행합니다. 없으면 아무 일도 없고 면제도 + /// 새로 생기지 않습니다. + pub fn yield_now>(&mut self, env: &mut E) { + let Some(c) = self.running else { return }; + if let Some(x) = env.pop(self.rd) { + env.push(self.rd, c); + self.switch(env, x, Entry::Between); + } + } + + /// 현재 태스크가 블록되거나 종료되거나 폴트로 떠난 뒤에 부르는 함수입니다. + /// + /// 떠난 태스크는 호출자가 이미 깨울 주체에 걸어 두었어야 합니다. 같은 + /// 도메인에 준비된 태스크가 있으면 틱 사이의 전환으로 실행하고, 없으면 + /// [Next::Idle]입니다(다른 도메인으로 넘어가지 않음). + pub fn block>(&mut self, env: &mut E) -> Next { + self.running = None; + match env.pop(self.rd) { + Some(x) => { + self.switch(env, x, Entry::Between); + Next::Run(x) + } + None => Next::Idle, + } + } + + /// EL0에서 틱이 들어왔을 때 부르는 함수입니다. + /// + /// 틱 번호가 마지막으로 처리한 것보다 크지 않으면 새로운 일이 없으므로 현재 + /// 상태만 돌려줍니다. 번호가 여럿 건너뛰어도 사건은 한 번입니다. + pub fn tick>(&mut self, env: &mut E) -> Next { + let n = env.now(); + if n <= self.seen { + return self.status(); + } + self.advance(n); + let old = self.rd; + let new = self.table.domain_at(n - self.epoch); + self.seen = n; + if new == old { + env.serve(old, n); + return match self.running { + Some(c) => match self.slice.on_tick() { + Verdict::Keep => Next::Run(c), + Verdict::Rotate => match env.pop(old) { + Some(x) => { + env.push(old, c); + self.switch(env, x, Entry::Tick); + Next::Run(x) + } + None => Next::Run(c), + }, + }, + None => self.enter(env, old), + }; + } + if let Some(c) = self.running.take() { + match self.slice.on_tick() { + Verdict::Keep => env.push_front(old, c), + Verdict::Rotate => match env.pop(old) { + Some(x) => { + env.push(old, c); + env.push_front(old, x); + } + None => env.push_front(old, c), + }, + } + } + self.rd = new; + env.enter_domain(new); + env.serve(new, n); + self.enter(env, new) + } + + /// 실행할 태스크 없이 기다리는 루프가 인터럽트를 받은 뒤에 부르는 함수입니다. + /// + /// 틱 번호가 새로 올랐으면 틱 사건과 같습니다. 아니면(콘솔 입력) 도는 + /// 도메인의 일을 하고, 준비된 태스크가 생겼으면 틱 사이의 전환으로 + /// 실행합니다. + pub fn poll>(&mut self, env: &mut E) -> Next { + let n = env.now(); + if n > self.seen { + return self.tick(env); + } + env.serve(self.rd, n); + if self.running.is_some() { + return self.status(); + } + match env.pop(self.rd) { + Some(x) => { + self.switch(env, x, Entry::Between); + Next::Run(x) + } + None => Next::Idle, + } + } + + /// 새 표를 보류시키는 함수입니다. 마지막으로 처리한 틱의 두 틱 뒤에 0번 + /// 항목부터 효력이 생깁니다. + /// + /// 그 전에 한 번 더 부르면 앞의 표는 버려집니다. 이미 효력이 생긴 표는 + /// 새 표의 시작 틱까지 그대로입니다. 시작 틱은 이 구조체가 처리한 틱에서 + /// 구하므로 부르는 쪽이 틱 번호를 넘길 일이 없습니다. 바로 다음 틱은 언제나 + /// 지금의 계획대로 가므로, 그 틱을 일찍 받도록 이미 걸어 둔 타이머는 이 + /// 호출이 보류 표를 갈아 끼울 때만 달라집니다(부른 쪽이 호출 뒤에 + /// [Core::next_tick_switches]를 다시 물어야 함). + /// + /// # Arguments + /// `t` - 새 표 + pub fn set_table(&mut self, t: Table) { + self.pending = Some((t, self.seen.saturating_add(2))); + } + + /// 마지막으로 처리한 틱 다음 틱에서 도메인이 바뀌는지 알려 주는 함수입니다. + /// + /// 커널이 그 틱을 일찍 받도록 타이머를 앞당길지 정하는 데 씁니다. + pub fn next_tick_switches(&self) -> bool { + self.plan_at(self.seen.saturating_add(1)) != self.rd + } + + /// 지금 도는 도메인을 주는 함수입니다. + pub fn running_domain(&self) -> Domain { + self.rd + } + + /// 표나 보류 표가 기본 표가 아닌지 알려 주는 함수입니다. + pub fn partitioned(&self) -> bool { + !self.table.is_default() || self.pending.is_some_and(|(t, _)| !t.is_default()) + } +} + +impl Default for Core { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/k0-part/src/model_tests.rs b/crates/k0-part/src/model_tests.rs new file mode 100644 index 0000000..894d201 --- /dev/null +++ b/crates/k0-part/src/model_tests.rs @@ -0,0 +1,367 @@ +//! Lean 모형이 낸 결과와 진짜 Core를 맞대는 테스트 모듈입니다. +//! +//! `model_vectors.txt`의 한 줄은 사건 대본 하나와, Lean 모형 `K0Part.step`이 그 +//! 대본에 낸 결과의 해시입니다(`proofs/lean/ModelVectors.lean`이 계산함). 이 +//! 모듈은 같은 대본을 고치지 않은 `Core`에 넣고, 부팅 직후와 사건마다 상태를 +//! 한 줄로 적어 해시를 견줍니다. CI에는 Lean이 없으므로 Rust 코드와 기록된 모형의 +//! 결과가 갈라지면 이 테스트가 알립니다. +//! +//! 대본은 `;`로 나눈 칸 여덟 개입니다. 이름, 부팅 틱, 태스크 0번부터의 도메인, +//! 첫 태스크, 준비된 태스크, 대기자(`번호@기한` 또는 `번호@-`), 사건, 해시입니다. +//! 사건은 `tN` 틱, `pN` 대기 루프의 poll, `y` 양보, `b-`와 `bN` 블록(기한 없음과 +//! 기한 N), `wT` 같은 도메인 태스크를 깨움, `xT` 다른 도메인 태스크를 깨움, +//! `sD:W,...` 표 바꾸기입니다. 블록과 깨움은 실행 중인 태스크의 행동입니다. 실행 +//! 중인 태스크가 없을 때 `w`와 `x`는 아무 일도 하지 않고, `y`와 `b`는 Core를 +//! 그대로 부릅니다. 모형은 그때 아무 일도 하지 않으므로 `b`는 두 쪽이 다르게 +//! 다루는 하나뿐인 입력이고, 그때 도는 도메인의 큐가 비어 있어서 결과가 같습니다. +//! +//! 상태 한 줄은 `seen=N tbl=D:W,... ep=N pend=시작/D:W,... rd=D cur=T q=[..|..] +//! wl=[..|..] nx=B`입니다. 보류 표가 없으면 `pend=-`, 현재 태스크에 면제가 있으면 +//! `cur=T*`, 실행 중인 태스크가 없으면 `cur=-`입니다. `q`와 `wl`은 도메인 0부터 +//! 7까지의 준비 큐와 대기 목록을 `|`로 나눈 것이고 `nx`는 +//! [Core::next_tick_switches]입니다. +//! +//! 해시는 FNV-1a 64비트입니다. 줄을 차례로, 줄마다 줄바꿈 바이트 하나를 붙여 +//! 넣습니다. 14695981039346656037(0xcbf29ce484222325)에서 시작해 바이트마다 먼저 +//! XOR하고 1099511628211(0x100000001b3)을 곱합니다(2^64로 나눈 나머지). 파일을 +//! 작게 두려는 것일 뿐 보안 수단이 아닙니다. +//! +//! 이것은 테스트이지 증명이 아닙니다. 통과가 뜻하는 것은 "기록된 대본에서 Core와 +//! 모형이 같은 줄을 냈다"까지입니다. [Host]는 목록으로 적은 Env이고 커널의 실제 +//! 큐(TCB에 링크를 둔 목록)가 아닙니다. Core나 모형을 일부러 바꿨다면 +//! `proofs/lean/README.md`의 절차대로 해시를 다시 만듭니다. + +use std::collections::{BTreeMap, VecDeque}; + +use k0_slice::Verdict; + +use super::*; + +const VECTORS: &str = include_str!("model_vectors.txt"); + +/// FNV-1a 64비트의 시작값 +const BASIS: u64 = 0xcbf2_9ce4_8422_2325; + +/// 어느 갈래를 몇 번 지났는지 세는 표 +type Cover = BTreeMap; + +/// 파일의 대본이 지나는 갈래의 전부입니다. +/// +/// 앞쪽은 "사건, 직전에 태스크가 실행 중이었는지(run, idle): 그 사건에서 일어난 +/// 일"입니다. 일어난 일은 Core가 Env에 한 호출의 순서이고 empty는 빈 큐에서 +/// 꺼내려 한 것입니다. 깨움과 표 바꾸기에는 호출이 없으므로 결과를 적습니다. +/// 뒤쪽은 대본에 든 입력의 종류입니다. +const NEED: [&str; 47] = [ + // 이미 처리한 번호의 틱 + "tick again run:", "tick again idle:", + // 같은 도메인의 틱: 면제로 유지, 교대, 혼자라 유지, 대기 중 진입, 계속 대기 + "tick run: serve", "tick run: serve pop push run", "tick run: serve empty", + "tick idle: serve pop run", "tick idle: serve empty", + // 창의 경계: 세워 두기(면제, 교대, 혼자, 태스크 없음)와 새 도메인 진입(있음, 없음) + "tick run: front enter serve pop run", "tick run: front enter serve empty", + "tick run: pop push front enter serve pop run", "tick run: pop push front enter serve empty", + "tick run: empty front enter serve pop run", "tick run: empty front enter serve empty", + "tick idle: enter serve pop run", "tick idle: enter serve empty", + // 새 틱이 없는 poll, 양보, 블록 + "poll run: serve", "poll idle: serve pop run", "poll idle: serve empty", + "yield run: pop push run", "yield run: empty", "yield idle:", + "block run: pop run", "block run: empty", "block idle: empty", + // 깨움: 기다리던 태스크, 기다리지 않는 태스크, 대상이 아니라 무시, 대기 중이라 무시 + "wake run: woke", "wake run: not waiting", "wake run:", "wake idle:", + "wakeX run: woke", "wakeX run: not waiting", "wakeX run:", "wakeX idle:", + // 표 바꾸기: 보류 표가 없을 때, 같은 틱에 한 번 더, 다음 틱에 한 번 더 + "set run: first", "set run: same tick", "set run: next tick", + "set idle: first", "set idle: same tick", "set idle: next tick", + // 입력의 종류 + "poll with a new tick", "jump", "table starts", "table starts late", "one-domain table", + "next tick from the pending table", "two waiters at once", "deadline in the past", "ten idle events", +]; + +fn num(s: &str) -> u64 { + s.parse().unwrap_or_else(|_| panic!("bad number '{s}'")) +} + +fn domain(s: &str) -> Domain { + u8::try_from(num(s)).ok().and_then(Domain::new).unwrap_or_else(|| panic!("bad domain '{s}'")) +} + +fn deadline(s: &str) -> Option { + (s != "-").then(|| num(s)) +} + +fn table(s: &str) -> Table { + let entry = |e: &str| { + let (d, w) = e.split_once(':').expect("table entry"); + (domain(d), u32::try_from(num(w)).expect("window")) + }; + Table::from_entries(&s.split(',').map(entry).collect::>()).expect("table") +} + +fn count(cover: &mut Cover, on: bool, key: &str) { + *cover.entry(key.to_string()).or_default() += u32::from(on); +} + +fn join(items: impl Iterator, sep: &str) -> String { + items.map(|x| x.to_string()).collect::>().join(sep) +} + +/// Env를 목록으로 적은 것입니다. 준비 큐와 대기 목록이 도메인마다 하나씩입니다. +/// +/// 대기자는 기다리기 시작한 순서대로 있고 기한은 틱 번호입니다(없으면 None). +/// `did`는 사건 하나에서 일어난 일을 차례로 적은 것이고 `woke`는 그 사건에서 +/// 기한이 지나 깨어난 대기자의 수입니다. 둘은 갈래를 세는 데만 씁니다. +struct Host { + now: u64, + dom: Vec, + q: Vec>, + wl: Vec)>>, + did: String, + woke: usize, +} + +impl Host { + fn dom(&self, t: u64) -> usize { + self.dom[t as usize].index() + } + + /// 깨우는 쪽(커널의 enqueue)이 하는 일입니다. Core의 사건이 아니며, 기다리던 + /// 태스크를 자기 도메인 큐의 뒤에 넣는 것이 전부입니다. + fn wake(&mut self, t: u64) { + let d = self.dom(t); + let waiting = self.wl[d].iter().any(|w| w.0 == t); + if waiting { + self.wl[d].retain(|w| w.0 != t); + self.q[d].push_back(t); + } + self.did += if waiting { " woke" } else { " not waiting" }; + } +} + +impl Env for Host { + fn now(&self) -> u64 { + self.now + } + + fn domain(&self, t: u64) -> Domain { + self.dom[t as usize] + } + + fn push(&mut self, d: Domain, t: u64) { + self.q[d.index()].push_back(t); + self.did += " push"; + } + + fn push_front(&mut self, d: Domain, t: u64) { + self.q[d.index()].push_front(t); + self.did += " front"; + } + + fn pop(&mut self, d: Domain) -> Option { + let x = self.q[d.index()].pop_front(); + self.did += if x.is_some() { " pop" } else { " empty" }; + x + } + + fn run(&mut self, _: u64) { + self.did += " run"; + } + + fn enter_domain(&mut self, _: Domain) { + self.did += " enter"; + } + + fn serve(&mut self, d: Domain, now: u64) { + let due = |w: &(u64, Option)| w.1.is_some_and(|k| k <= now); + let (q, wl) = (&mut self.q[d.index()], &mut self.wl[d.index()]); + self.woke += wl.iter().filter(|w| due(w)).count(); + // 커널의 순서: 늦게 기다리기 시작한 대기자부터 큐에 들어감 + // (k0_sched::arm_timeout은 목록의 머리에 걸고 k0_sched::expired는 머리부터 봄) + q.extend(wl.iter().rev().filter(|w| due(w)).map(|w| w.0)); + wl.retain(|w| !due(w)); + self.did += " serve"; + } +} + +/// 상태 한 줄을 적는 함수입니다. `ModelVectors.lean`의 `showSt`와 같은 글을 냅니다. +fn line(core: &Core, h: &Host) -> String { + let table = |t: &Table| join((0..t.len()).map(|i| format!("{}:{}", t.dom[i], t.ticks[i])), ","); + let pend = core.pending.map_or("-".to_string(), |(t, s)| format!("{s}/{}", table(&t))); + // 면제는 k0-slice 안의 값이라 사본에 틱을 한 번 물어서 읽음 + let mut probe = core.slice; + let cur = match core.running { + Some(c) if probe.on_tick() == Verdict::Keep => format!("{c}*"), + Some(c) => c.to_string(), + None => "-".to_string(), + }; + let waiter = |&(t, d): &(u64, Option)| d.map_or(format!("{t}@-"), |k| format!("{t}@{k}")); + let q = join(h.q.iter().map(|q| join(q.iter(), " ")), "|"); + let wl = join(h.wl.iter().map(|l| join(l.iter().map(waiter), " ")), "|"); + let (seen, tbl, ep, rd) = (core.seen, table(&core.table), core.epoch, core.rd.id()); + let nx = u8::from(core.next_tick_switches()); + format!("seen={seen} tbl={tbl} ep={ep} pend={pend} rd={rd} cur={cur} q=[{q}] wl=[{wl}] nx={nx}") +} + +/// 사건 하나(`tok`, 모듈 설명의 표기)를 Core에 넣고 지난 갈래를 세는 함수입니다. +fn step(core: &mut Core, h: &mut Host, tok: &str, cover: &mut Cover) { + let (seen, running) = (core.seen, core.running); + let pending = core.pending.map(|(_, start)| start); + let rd = core.rd; + h.did.clear(); + h.woke = 0; + let (kind, arg) = tok.split_at(1); + let name = match kind { + "t" | "p" => { + let n = num(arg); + h.now = n; + let r = if kind == "p" { core.poll(h) } else { core.tick(h) }; + assert_eq!(r, core.status(), "the returned value must name the running task"); + count(cover, n > seen && kind == "p", "poll with a new tick"); + count(cover, n > seen + 1, "jump"); + count(cover, pending == Some(n), "table starts"); + count(cover, pending.is_some_and(|s| s < n), "table starts late"); + match kind { + _ if n > seen => "tick", + "p" => "poll", + _ => "tick again", + } + } + "y" if arg.is_empty() => { + core.yield_now(h); + "yield" + } + "b" => { + // 떠나는 태스크는 Core를 부르기 전에 대기 목록에 걸려 있어야 함 + if let Some(c) = running { + let (d, dl) = (h.dom(c), deadline(arg)); + h.wl[d].push((c, dl)); + count(cover, dl.is_some_and(|k| k <= seen), "deadline in the past"); + } + let r = core.block(h); + assert_eq!(r, core.status(), "the returned value must name the running task"); + "block" + } + "w" | "x" => { + // 깨움은 실행 중인 태스크의 행동이고 w는 같은 도메인, x는 다른 도메인만 깨움 + let t = num(arg); + let own = h.dom(t) == core.rd.index(); + if running.is_some() && own == (kind == "w") { + h.wake(t); + } + if kind == "w" { "wake" } else { "wakeX" } + } + "s" => { + let t = table(arg); + h.did += match pending { + None => " first", + Some(s) if s == seen + 2 => " same tick", + Some(_) => " next tick", + }; + count(cover, (0..t.len()).all(|i| t.dom[i] == t.dom[0]), "one-domain table"); + core.set_table(t); + "set" + } + _ => panic!("bad event '{tok}'"), + }; + count(cover, h.woke >= 2, "two waiters at once"); + count(cover, core.pending.is_some_and(|(_, s)| s == core.seen + 1), "next tick from the pending table"); + // 해시는 상태 줄만 덮으므로, 도메인이 바뀔 때만 그리고 바뀔 때마다 환경에 + // 알렸는지는 여기서 따로 봄 + assert_eq!(h.did.contains(" enter"), core.rd != rd, "the environment hears of every domain change and of nothing else: {tok}"); + let was = if running.is_some() { "run" } else { "idle" }; + count(cover, true, &format!("{name} {was}:{}", h.did)); +} + +/// 대본 한 줄(해시를 뺀 일곱 칸)을 Core에 넣고 부팅 직후와 사건마다의 상태 줄을 +/// (사건의 글, 줄)로 돌려주는 함수입니다. +fn run<'a>(f: &[&'a str], cover: &mut Cover) -> Vec<(&'a str, String)> { + let waiter = |w: &str| { + let (t, d) = w.split_once('@').expect("waiter"); + (num(t), deadline(d)) + }; + let dom: Vec = f[2].split_whitespace().map(domain).collect(); + let (q, wl) = (vec![VecDeque::new(); MAX_DOMAINS], vec![Vec::new(); MAX_DOMAINS]); + let mut h = Host { now: num(f[1]), dom, q, wl, did: String::new(), woke: 0 }; + for t in f[4].split_whitespace().map(num) { + let d = h.dom(t); + h.q[d].push_back(t); + } + for w in f[5].split_whitespace().map(waiter) { + let d = h.dom(w.0); + h.wl[d].push(w); + } + let mut core: Core = Core::new(); + core.start(&mut h, num(f[3])); + let mut out = vec![("boot", line(&core, &h))]; + let mut idle = 0; + for tok in f[6].split_whitespace() { + step(&mut core, &mut h, tok, cover); + out.push((tok, line(&core, &h))); + idle = if core.running.is_none() { idle + 1 } else { 0 }; + count(cover, idle == 10, "ten idle events"); + } + out +} + +/// FNV-1a 64비트를 바이트열만큼 진행하는 함수입니다. +fn fnv(h: u64, bytes: &[u8]) -> u64 { + bytes.iter().fold(h, |h, &b| (h ^ u64::from(b)).wrapping_mul(0x0100_0000_01b3)) +} + +/// 글에 든 대본을 모두 돌리는 함수입니다. 대본의 수와, 해시가 모형과 다른 +/// 대본마다 대본과 다시 계산한 줄을 적은 보고를 돌려줍니다. +fn check(text: &str, cover: &mut Cover) -> (usize, Vec) { + let mut bad = Vec::new(); + let scripts: Vec<&str> = text.lines().filter(|l| !l.is_empty() && !l.starts_with('#')).collect(); + for l in &scripts { + let f: Vec<&str> = l.split(';').collect(); + assert_eq!(f.len(), 8, "a script has eight fields: {l}"); + let lines = run(&f, cover); + let got = lines.iter().fold(BASIS, |h, (_, l)| fnv(fnv(h, l.as_bytes()), b"\n")); + if format!("{got:016x}") != f[7] { + let shown = join(lines.iter().map(|(tok, l)| format!(" {tok} -> {l}\n")), ""); + bad.push(format!("the model gives {}, Core gives {got:016x} on the script\n{l}\n{shown}", f[7])); + } + } + (scripts.len(), bad) +} + +#[test] +fn core_gives_the_lines_of_the_lean_model_on_every_recorded_script() { + let mut cover = Cover::new(); + let (n, bad) = check(VECTORS, &mut cover); + let first = bad[..bad.len().min(3)].join("\n"); + assert!(bad.is_empty(), "{} of {n} scripts differ from the Lean model, the first ones:\n{first}", bad.len()); + println!("{n} scripts, {cover:#?}"); + // 줄이 빠진 파일을 통과시키지 않음. 대본을 다시 만들어 수가 달라지면 여기도 고침 + assert_eq!(n, 1600, "the file must hold every recorded script"); + for key in NEED { + let hits = cover.get(key).copied().unwrap_or(0); + assert!(hits >= 100, "the scripts must reach '{key}' many times: {hits}"); + } + for key in cover.keys() { + assert!(NEED.contains(&key.as_str()), "a path that the list does not name: '{key}'"); + } +} + +#[test] +fn a_wrong_hash_and_a_changed_script_are_reported() { + let line = VECTORS.lines().find(|l| !l.is_empty() && !l.starts_with('#')).unwrap(); + let (body, hash) = line.rsplit_once(';').unwrap(); + let mut cover = Cover::new(); + assert_eq!(check(line, &mut cover).1.len(), 0); + // 해시의 마지막 자리를 바꿈 + let digit = if hash.ends_with('0') { '1' } else { '0' }; + let (n, bad) = check(&format!("{body};{}{digit}", &hash[..15]), &mut cover); + assert_eq!((n, bad.len()), (1, 1)); + assert!(bad[0].contains(body) && bad[0].contains(" boot -> seen="), "the report must show the script and its lines"); + // 마지막 사건을 뺌 + let shorter = body.rsplit_once(' ').unwrap().0; + assert_eq!(check(&format!("{shorter};{hash}"), &mut cover).1.len(), 1); +} + +#[test] +fn the_hash_is_fnv_1a_64() { + assert_eq!(fnv(BASIS, b""), 0xcbf2_9ce4_8422_2325); + assert_eq!(fnv(BASIS, b"a"), 0xaf63_dc4c_8601_ec8c); + assert_eq!(fnv(BASIS, b"foobar"), 0x8594_4171_f739_67e8); +} diff --git a/crates/k0-part/src/model_vectors.txt b/crates/k0-part/src/model_vectors.txt new file mode 100644 index 0000000..db96d25 --- /dev/null +++ b/crates/k0-part/src/model_vectors.txt @@ -0,0 +1,1636 @@ +# Recorded results of the Lean model K0Part.step for the host test in +# model_tests.rs. GENERATED: the hashes are written by `lake exe vectors` +# in proofs/lean, never by hand. proofs/lean/README.md says how to check +# the file against the model and what to do after a deliberate change of +# Core or of the model. +# +# One script per line, fields separated by ';': +# id ; boot tick ; domain of task 0, 1, ... ; first task ; ready tasks ; +# waiting tasks as tid@deadline or tid@- ; events ; hash +# Events: tN tick, pN poll, y yield, b- and bN block, wT wake, xT wakeX, +# sD:W,D:W,... set_table. +# The hash is the model's result: FNV-1a 64 over the canonical lines of the +# script (the boot state, then the state after every event), every line +# followed by a newline. proofs/lean/ModelVectors.lean defines the line and +# the hash. +# +# The scripts are random scripts of the differential harness that compared +# Core with K0Part.step (the harness is not in the repository): seeds +# 20261115 to 20261120, one for each kind below, every script cut to +# 16, 24, 32, 48 or 80 events, none with a deadline 0. +# 941 of the 1600 were chosen to raise the count of every path of +# Core::tick, poll, yield_now, block and set_table and of both wake events +# (the goal was 300, and 120 for the paths that only kind i reaches); +# the others were taken in turn from the kinds m, k, p, t, e. The test +# counts the paths and fails below 100 of each. +# The letter of an id is the kind of script: +# m any order of events, tick indexes never go back (422 scripts) +# k only the call patterns of the kernel (325 scripts) +# p as k, and poll while a task runs (222 scripts) +# t as k, and tick while nothing runs, repeated tick indexes (252 scripts) +# e as k, and set_table while nothing runs, tables without the running domain (209 scripts) +# i as m, and yield, block and wakes while nothing runs (170 scripts) +# The kernel raises none of the events that kind i adds. They are here +# because nothing else reaches the early return of Core::yield_now. A block +# while nothing runs is the one event the two sides treat differently: Core +# looks into the queue, which is empty then, and the model does nothing. +m0;2;0;0;;;t6 t7 t8 x0 t9 s0:4,1:1,2:1,1:1,3:2,0:1,2:3,1:3 t10 w0 b8 s1:1,3:2 t11 p11 s1:2 t12 s2:3 t13;29ac2e99b0e81f7e +m1;0;0 2 2;0;2;;s2:2,3:1 w2 t35 t36 y s0:2,5:2 y t37 p38 t38 s1:1,1:34 t45 p46 p47 t48 t49 s2:1 s3:1,0:2 p49 t50 s0:1,7:123 t91 s1:3 p91;ea1b3085880af64f +m2;841;0 0 3;0;;1@843;t841 t842 w0 s2:1,0:1 b- p843 p844 p844 p844 p848 p848 t851 w0 p851 b- w1 t852 s0:1,3:6,3:120 s0:1,2:1 s2:1 p856 p857 t862 s1:1 p862 p863 s0:1,0:8 s0:2,1:3,3:4,4:1 s3:1 t864 s5:3,0:1,1:251,3:1,5:1,2:1,3:85,3:4,7:1,5:1,2:1,0:25,1:2,0:1 s2:1,1:4;f91c90a53dfb4860 +m3;4;0;0;;;t45 w0 t46 y s7:2,5:1 s2:1,0:1 t49 t53 x0 p56 t90 p91 x0 t92 p92 p93 w0 x0 t97 t98 t99 y t100 p101 t102 t111 y t111 t112 p113 t117 t118 p118 p122 t123 b123 p170 p184 p185 t186 t190 t191 t192 t193 t194;56336ade89524f28 +m7;3;0 1 0 1;0;1 3;;t5 t6 t7 t8 y y t9 t10 t14 w0 t19 t20 t25 t26 t27 t28 w0 x0 t33 t38 t39 t40 b44 p40 p41 t42 p42 p43 t48 t49 s0:3,0:6 t50;140b1276e1bac933 +m8;0;0 3 2 2 1;0;2 4;1@-;t1 t1 s1:2,2:1 p6 t7 x2 s2:1 x1 x2 t8 t9 x2 w1 x4 t11 t12 t13 s3:2 t16 t17 s7:3 b17 s0:2,1:1,0:1,1:1 p17 s0:5,1:2 s2:3,1:2,3:1,1:6 s3:2,4:4 t18 t19 s3:1 p20 t21 t22 s0:1,0:1 t23 s1:8 t26 y t31 s2:3 b34;da8902cc8c4b7f38 +m9;0;0 2 0 3 2 3 0 1;0;1 6 4 2;5@- 7@5;t2 y w1 w3 p5 p5 t57 t58 s2:1 p59 x7 w4 w1 w1 t60 x5 t95 x2 w5 s2:1,2:1,4:2,2:2 w5 w4 t96 w2 t97 t98 p102 t104 x4 w1 p105 t106 p107 t108 t109 t109 w7 w5 x3 x2 w7 s2:3,2:1 t110 t135 t136 s0:1,0:1,0:1,0:2,0:1,0:68,0:3 w3 t137 p137 w5 t138 w6 p138 x5 w3 w2 y t139 s0:2,0:1 t140;9c1416fba6d727f8 +m11;0;0 0 0;0;;2@5 1@-;w1 t1 y t2 t3 t4 x0 t5 t5 w0 t5 t6 w0 s1:193,0:1,0:1,1:2 w1 x1 w1 t7 t27 p27 p31 p32 t36 t37;7e76630043ceea25 +m12;2;0 0 2 1;0;3 1 2;;t3 t4 s2:154 t5 s2:1,2:3,0:2,2:2 x1 t6 t7 t8 y y x2 t9 w3 x3 y t10 y t11 y s3:3,1:2,1:2 y y t12 y b10 s0:1,2:2,6:1,2:7,1:1 y t13 p13 y y;756fb75342bf569a +m14;5;0 1 1 0 1 1;0;3;2@3 1@-;w2 t6 y t7 t8 t9 t10 t11 w5 y b- t13 p14 p15 t16 t50 y t51 t52 t53 p55 t56 b55 p57 t58 t59 p59 t60 t61 p61 b66 p61 p61 p61 p61 p61 p61 t62 p62 p65 p65 t66 b- p70 s4:1,0:1;f02490dc29b8b5ed +m15;0;0 1 0 0 1 1 2 2 0;0;5 4 6 1 7 8 2;;t5 s6:1 t6 y t7 t8 s2:1 t9 p10 t11 t15 y t16 y s2:1,0:2,2:1,2:2,4:1,2:2,0:1,1:1,1:6,0:2,0:2,1:2,1:3,2:2 t17;45d7f074589ef815 +m16;0;0 0 0 0 0 0 0 0;0;6 5 4 2 3 1;7@-;b- b- b1 t3 b3 b4 t4 t5 b- b8 t6 t7 t8 b7 b7 s0:1,0:4 t9 b12 t14 t15 t16 b22 s0:1,0:2 b-;888f5059c9ded2e1 +m17;2;0;0;;;w0 t3 w0 b- t4 p4 p5 p10 t11 t12 t14 p14 t16 t34 p34 t35 p36 p36 p36 t37 t38 p38 s5:1 p43 p44 p47 t48 s0:2 t49 t50 p50 s4:1;29f67644f98212b1 +m18;0;0 1 1;0;2;1@-;s2:1,0:1 t34 p35 x0 y p36 p36 s7:2,2:110,1:1 p36 p37 y t37 t38 p39 t40 p40 p41 t41 p41 t42 p42 s5:3,1:1,1:3,1:7 t43 p43 p44 p44 t45 p45 p45 t46 p46;f9b3154aae374c32 +m19;0;0 2 2 2;0;2;3@-;y t1 b3 p1 p6 t7 t8 x2 p9 t10 t11 p12 t13 t14 b18 p15 p15 t16 t17 t18 s0:1 s0:3,0:1,2:1 x3 b- t19 t21 t22 t23 p27 s2:118,1:2 p28 p29 t30 t31 t31 p31 t31 p31 s5:2 t32 t81 t81 p82;effce12db3c21bc1 +m20;1;0 3 3 3;0;3 1;2@9;y t2 s1:2,2:1,1:2 t6 s0:1,4:1,2:204,0:2,1:3,0:2,3:3,3:6,4:2 p9 t13 p18 p18 t19 t46 t47 s1:1,1:1 t51 t52 t53;04b0dd63390204ac +m21;0;0;0;;;y t1 t6 t7 y y w0 t12 w0 b- t13 p14 p15 p15 t16 p17 s4:1,0:2,0:1,0:2,0:1,0:1,3:1,0:1,0:1,6:2,0:3 t17 p17 s0:169,0:1,0:2,0:2,0:1,5:1,0:3 s0:3,4:1 t21 p22 t23;5d23c81a5ca9606a +m22;907;0 0 0 0 0;0;;3@905 4@906;p908 t909 t911 t913 x3 t913 t914 t915 t916 t917 b917 w1 b915 b- p917 w0 t918 t919 y b919 t919 x4 y t920 w4 p921 t922 t922 t923 t924 p925 t925;1996ba9732690c44 +m24;4;0 1 0 1;0;2;1@-;b7 t7 b7 b8 t8 b6 x2 x1 y t10 y t11 w0 b- b13 p12 p12 p14 b20 p15 s0:3,0:1,0:1 t16 p16 t17 p17 p17 t18 p19 p20 t21 x1 b21 p23 b24 t24 p27 b32 p28 p28 p28 p32 b- s0:3,1:1,7:1 p32 p34 t35 p35 t36 s4:2,1:1,4:1 p37 p38 p38 t39 t40 y;c7b810c7ef6f2b47 +m26;0;0 1 0;0;1;;x1 t57 t60 s4:2,1:2,0:5,1:1 t60 t61 t62 p62 p62 t66 t67 t71 s1:1,2:43,0:1 y t75 t76 t77 p77 p78 p79 p79 p79 p79 p80;07d879c856e8c364 +m27;0;0 0 0;0;2;1@-;t1 t1 b4 w2 y t2 x1 s7:1,0:146,2:1,6:3,0:1,0:1,2:1,0:129,0:2,0:2,0:3,0:1,0:1,0:3,3:1 y b4 t3 p3 t4 t5 y t14 p15 y b21 t16 y y w1 t18 t18 b22 t19 w0 t20 w1 t20 t21;8fcc1a2fb9cfe798 +m28;0;0 0 1 0 0 0 1 1;0;4 3 1 2;6@2;t1 t2 t3 y t4 t5 b4 t5 b6 t6 s0:1,0:2,0:2,0:252,0:3,0:2,0:1,0:2,0:2,0:6,0:2,0:1,0:1,0:2,0:1,0:1 w2 t7 s0:1,0:1,1:1 b7 x6 b7 t9 t10 w7 t11 t12 t13 b15 s0:1 t15 s1:1 s6:2,4:1 t16 s1:1 s0:1,1:3,0:1 t17 t18 t19 p21 t22 x2 t23 t24 t25 p26 t26 w2 p26 x1 t26 x4 b28;151f6d481c12f993 +m29;2;0 1 1 2 2 3;0;5;2@- 3@1;s0:134 x2 t49 s0:3,1:3,2:1,7:1,0:1,1:43,7:2,1:2,3:4,0:6,1:2,1:2,3:1,2:1,1:2,0:1 s0:1,2:2,1:2 b47 p50 s1:1 t51 t51 s2:1,1:1 b50 s2:1,6:243 t52 t53 y t53 y t53 t54 t55 p56 p57 p57 p58 t103 t104 s5:2,1:3 p105 p106 p107 s3:5,3:2 p107 p107 t108 s1:4,1:1 t109 s0:2 t110 s7:2,0:2,3:1,6:3,4:2,0:1,1:2,5:1,1:3,1:1,2:1,1:1,3:1,6:1 t111 t112 p113 s0:1 t114 t115 t150 t151 t156 t157 p157 t158 b157 p158 p158 x4 t162 t163 s3:3,1:5,0:1,0:3,3:1,2:1,3:52 y s3:1 t164 p170 y t171 p171 p171 t175 t176 y t179;59a347145cbf9227 +m30;3;0 2;0;;1@1;p4 t5 t6 b8 p7 p7 p7 p67 p71 t72 p72 t75 t76 t77 y t81;12798744c56cd646 +m32;0;0 2 1 2 2;0;4;2@-;x3 b6 t0 t1 p2 s0:1,0:1,0:1,0:7,0:1,0:1,0:5 p53 t57 t57 p58 t59 b64 t60 t61 t62 t63 p64 t69 t70 w4 t71 t72 p72 t73 t74 t109 b- s2:1,1:2,1:1,7:3,2:2 p109 p111 t113 p114;4cf1fc10d4ef68b0 +m33;4;0 1 0 0 0 1;0;5 2 1 4;3@8;p4 x4 y t7 t8 x0 y s1:3,0:2 s1:1 t9 t10 t11 t12 t15 y t15 w2 y y p16 y x1 x4 b22 w1 p16 s1:8,3:3,0:1 t17 s1:3 t18 t19 y p20 w0 t21 s1:1,6:1,1:3 p21 p21 y y p22 p22;bcfa3edcb2cc60cb +m34;0;0 1 0 0 0 1 2;0;4;5@4 2@- 3@6;s2:2,1:2,0:7 t1 t6 b4 t7 t8 b9 t9 t10 w2 t11 t12 t13 p13 p14 t15 b19 t16 t17 w1 s6:2,2:6,0:2 y t18 t19 t20 p21 p22 p22 p22 p23 p23 p24 p24 t25 p25 p26 p26 p27 t28 p28 t31 t35 p35 t36 t40 p40 p43 t44 p44 s4:2,2:1,1:1,5:1 t45 s7:6,2:2 t46 s2:1,1:1,0:2 t47 t48 t49 b- p50 t50 y b- w0 b56 b48 w4 t51 w1 b54 t52 t54 t55 p55;5da058c5c912ea0f +m35;0;0 2;0;1;;t1 s0:1,0:1,1:2 s3:1,3:2,3:2,3:1 y t11 p11 p11 t12 t13 s2:5,3:2,1:8,2:1,3:1,0:3 p13 p14 t17 w1 y b21;3af436e451f09a20 +m36;1;0 1 0 2 2;0;2;;t2 t3 b6 y w2 s1:3 b- x3 y b2 t4 t5 p31 p31 t35 p38 t38 t39 t40 t74 t75 p76 p77 t80;554362b4a970cfd6 +m37;0;0 0 1 2 1 1;0;2 3 5;1@6 4@7;t1 b- t1 p6 b- t11 t12 p13 p13 t14 t14 t15 p15 p16 p21 s2:3,1:4,6:1,2:183,2:1,0:3,7:1,0:1,1:3,0:3,1:1 t22 s1:1,2:7 t23 t24 s1:7,1:1 t25 s5:2,0:1 b- t83 t84 s0:224,1:3,2:1,2:1 t85 s1:1 p87 y t88;adc67ca584249f21 +m38;5;0 0;0;;;t6 t10 x1 p12 p12 x0 t12 t17 t21 t25 t29 s2:1 t30 s1:1,1:1,1:1,0:1,3:1,3:1,1:1,1:2,3:49,0:2,1:3,1:1,1:2,3:2,2:2,1:1 t31 t32 p33 p36 p36 s2:1 p36 t37 s1:2,0:1 t38 s1:231 s0:1 p48 y t49 x0 t50 b51 p50 t51 s2:7,2:2 t52 y t53 p54 s5:1,3:1,6:3 s1:2,2:1,3:1,3:3,0:1,3:1 p54 s1:1 t55 s0:1,1:1,3:1,3:8,2:3,3:1;0112f34162453b97 +m39;0;0 0 0 0 0 0 0 0 0 0;0;6 1 7 5 8;9@- 4@-;b- p5 t5 b6 t6 b4 b- b8 t7 t8 b13 t12 x9 t17 b21 b- t18 t19 b17 s1:1,1:1,4:3 t20 s4:1,1:1 t24 p24 t26 t27 s0:3,3:2,1:1,2:1,0:2,1:1,1:1,2:3 t29 y t30 t34 p34 s0:1 p34 p34 t35 t36 x2 b38 x4 b34 t40 s1:2,1:2 t41 s0:2,1:2 t42 s1:2 t43 t44 p44 p44 p44 p45 t45 t46 p47 p47 t52 t53 t54 p54 p55 t59 p60 p60 p60 t60 t64 t65 s1:3 s1:1,0:1 s1:1,1:1,1:4,0:1,1:1,1:1,0:2,1:2,0:1,0:3,1:1 t66 s0:128 s5:6 t67 t68 t68 t71;4d35bcfeb1c6c39e +m40;0;0 0;0;1;;x0 p0 t1 s0:1,0:1 p1 t2 p3 p4 s2:62 s4:3,0:3,1:2,0:1,1:7,0:2,1:1 s2:2,1:2,1:1 y t5 p6 p7 s7:2,0:1,2:1;3479a44e05a63fa7 +m41;3;0 3 1 2 1 3 1 3 0 2;0;6 7 2 1 9;4@- 8@8 3@1;s3:2 w8 w9 x4 x6 p4 w1 w4 x3 p4 w0 p4 x7 s3:1,0:2,3:1,2:1 t5 x9 s1:1 w1 w3 x6 x8 p9 s3:2 p9;9207b072faf4daed +m42;0;0 0 0 1;0;1;2@5;p2 t3 x3 t3 t4 t5 t6 b4 t7 p7 b- t8 x1 w0 b14 t9 b10 t10 t11 t16 b17 b17 t20 s1:6 p21 t22 p22 t23 s1:1,1:4,1:1,0:1,1:1,6:4,0:2,1:2,1:1,0:3,1:85,0:8 t24 t29 p29;1d20f6c95a50860a +m43;1;0 0 2 1 1 1;0;;3@5 2@1 5@8 4@-;b- t2 p26 s1:3 t27 s2:2,7:1,0:2 t28 t29 x2 t30 t31 p31 t89 t90 b- p90 p90 s2:3 t91 s1:1,0:3 t92 t93 b97 p94 t95 p95 s5:2,0:1,1:1,2:3,2:1,0:1,0:1,0:1,2:1,5:2,1:1 t96 s2:2,1:2 t97 s1:2,0:2,0:2 t98 t99 b- w4 t104 t105 t106 w1 t107 p107 p112 t115 p119 t120 p120 t121 s0:1,2:3;272c78062a50c29f +m44;0;0 2 3;0;2;;b2 t1 s2:3 t2 w0 t2 s1:2,2:2,3:1,0:1,3:3,0:1,0:2,3:2,1:4 b4 p2 t3 t3 p4 p5 s6:2,0:1,4:1,1:1,2:1,0:1,7:1,1:1,1:1,3:1,0:2,2:2,2:3,6:4,0:2 s5:2 p5 t5 t6 s2:1,3:3,2:3 s7:7,0:2 p6 s0:2 p7 t8 x0 w1 s3:2,1:1,5:3 t9 b- t10 b11 p10 s4:1,2:1,3:2 s0:2,0:5 p11 t14 t16 t17 p22 s2:1 p27 p28 p29 s1:3,0:2,2:1 s1:5,3:2 p30 s0:2,0:2,0:1,0:1 p31 s3:3,1:102,1:166,4:8,2:1,0:3,5:3 t78 t79 p84 t85 s3:115 p86 t87 s3:149 t88 t89 b- p89 p90 t91 p92 s3:1 s3:1,0:1,2:1,2:3,3:1,3:6,6:122,4:1,3:1,0:1,3:3,2:2,1:2,3:1,1:1 t93 p97 p98 s2:3,0:1,2:2 t99 p99 p100 p100 p104 s5:1,2:2,0:2 t105 t106 p106 s3:1,2:2,1:6,7:4,1:3,2:103,0:1,0:1,3:1,1:3,2:1,0:2,0:1;db19ab1de346979a +m45;3;0;0;;;t4 p4 t5 x0 x0 p5 t6 t7 w0 x0 t8 x0 t13 x0 x0 t15;a8aaf18fa7179790 +m46;2;0 0 0 0 0 0 0 0 0 0;0;2 3 4 8 1 9 6;5@9 7@8;w5 y t3 b- w7 s0:1 x9 w2 y t7 y t8 s0:3,0:4,0:8,0:1,0:1,0:1,0:1,0:1,0:1,0:3,0:4,0:1 t9 t9 p9 y x2 w0 x7 w1 w8 w9 b10;1a2d03c1606efaaf +m47;348;0;0;;;t349 s0:1 b352 s1:103 p350 p354 t355 p355 p355 t355 p355 t356 t357 t358 p358 p358 p359 t362 p366 t367 t370 p370 t371 s0:2,0:2 s2:1 t372 s0:1,2:1 s0:1,7:1,3:1,1:2,0:1,2:1,7:1,3:1,0:123,1:2 t373 t374 w0;d186a8080141bca4 +m48;0;0 1 1;0;;1@5;x2 t1 x1 t2 y t2 x1 t3 p3 y t4 x0 x2 x2 t5 y t6 x1 y t31 y x0 t32 x0 x1 y t33 x0 t34 b33 t59 x2 x2 t60 x0 x2 w0 t61 w2 t62 p63 t64 x2 x2 t66 x2 b68 t69;8cbe6fdba8101f96 +m49;0;0 0;0;1;;t5 t6 t7 s2:2,0:2 s0:1,0:2,6:1,1:1,0:1,4:1,0:43,3:2,0:1,7:82 t8 t9 t13 p14 t19 s2:1 s1:1,1:1 t20 s3:2 t21 t22 p23 p23 s0:2,3:2 t24 t25 s0:1,0:1,2:2,1:3,2:1,0:1,0:3 t26 t30 p31 t32 p32 t33 t38 s0:2 s4:2,2:1,2:1,0:2 s2:3,1:3,3:1,7:2 t39 s4:1,0:2,0:3 s0:1 t40;f8237dc09b43c170 +m50;2;0;0;;;t3 y y t7 s6:1,6:3,6:3,6:1,6:1,6:3,6:190,6:3 t8 t11 p12 p12 t17 p19 t20 s0:3,1:1 t21 s4:2,1:1 t22;0c5586e0af607cc1 +m51;4;0 2 2 1 0 2;0;5 4 1;;t5 s0:2,0:1,2:3,2:1,7:1,0:1,0:1,1:1,1:1,1:1,0:1 s1:1,1:4,1:2,1:2 t6 s0:2,0:2 t7 s1:1,1:2,2:217 t8 t9 t10 t10 s2:2,1:2,1:2,2:1,2:2,0:1,2:1,2:3,2:3,2:1,2:1,2:3,4:1,4:1 s2:2,0:1 t11 p11 p11 t16 b16 t17 w2 w3 t18 t21 y;b1411f2eea485752 +m52;3;0 0 0;0;1;2@-;t4 t5 w1 y t6 t7 t8 w0 y w2 t9 t13 t13 y y y b16 b16 y y y y t14 t15 t16 t17 b19 p22 y t23 t24 t25;90741707b20c7e06 +m53;0;0 0 0;0;2;;t1 t2 t3 t4 t7 p8 t8 x2 b13 t9 t12 b11 p12 t13 t14 t19 t20 t21 t26 p26 t29 x1 p29 s2:2,0:3 s0:5,4:1 p30 t35 t36 p36 p37 t38 b37 w0 w1 t39 t39 t39 t40 t41 b- w2 t42 p42 p43 b- x0 x2 x1;6e67965d36273833 +m54;2;0 0 0 0 0;0;4;2@- 1@2 3@2;t3 t52 t53 t54 x3 t55 t56 t61 y x4 t62 x2 p62 b60 t63 s0:3,0:1,0:2 t65 y s7:3 s0:1,0:1 t66 t67 w2 t68 p72 w1 t73 s3:1,0:4 s0:1,0:3,0:2,1:1 t74 s0:247 s0:1 t75 t76 t77 t78 t79 b82 p79 p83 s0:2,0:2,0:194,0:5 t84 s0:1 t85 b- p86 t87 t88 t89 w4 y t90 t91 t92 x3 y b92 t93 p101 t102 b- t103 p153 t154 t155 t156 y t157 t160 t161 y w4 t216 t232 s0:1,0:1 t233 s0:1,0:1 t234 t235 t239;fad65f92c5731147 +m55;0;0 0 0 0 0;0;2;1@6 4@5;t1 t2 w4 t3 w0 p3 t8 s0:2,3:1 t12 t13 t14 s0:2,1:1,1:8,6:3 t15 s1:2,4:2,7:4 t16 s1:8;260587f5a4f1644d +m56;3;0 1 0 0 1 0 0;0;4 6 2 1;3@-;b- y b2 t4 t5 t6 b6 t6 s1:1,1:1 t7 w6 t8 t9 t10 t11 b12 b11 s0:1,0:1,0:1 t12 s0:1 t13 t14 t15 t16;5463d883fa26c46b +m57;0;0 0 0 0;0;1 3 2;;y y y y t1 t1 b3 y b- p2 y s0:2,0:1 p3 t4 b- y y t5 x2 t6 y s6:3,1:3,3:1 x2 t7 t8 p8 t11 p12 t13 t14 t31 p31;ddbbe7cb62095c12 +m58;459;0;0;;;p459 t460 t461 p461 t462 t463 b- p463 p464 p465 t466 t467 s0:2,5:2 t468 s1:69,0:2 t469 s1:1 t470 t471 s1:1 s0:1,4:1,1:3,0:116,0:1,0:3,1:1,1:1,1:1,0:7,5:1,1:3,0:4,1:3 s1:3,1:5,0:2,0:1 t472 s1:1 s1:1,1:1,0:1 t473 t474 p474 p475 p475 p478 t479 p480 p480 t520 p520 p521 p525 t526;edc47ddb44aa09e7 +m59;0;0 0 1 1 2;0;4 1;;t1 x3 y x3 t2 s2:1,1:1 x1 b- b- p2 t3 p3 s2:1 t4 s0:2,6:2,2:1,2:2,1:1,2:1,2:1,2:1 p8 t9 s2:1,0:1 s0:1 t10 s2:1 s0:1,0:1,2:1 t11 t12 p14 b17 t15 t16 s1:1,2:3 s1:7,1:7,1:1 t17 s0:3,2:1,0:1 s0:1,4:3,2:3,2:2 t18 t19 s0:129,1:1 p24 p25 p29 s2:1,1:204,1:3 p29 p48 p50 p54 t55 p56 p59 p62 p63 s1:1 t64 s0:1,6:1,0:3,0:2 s4:1,1:2,5:1,7:168 p64 t65 p65 s2:1,0:2 p66 p67 t68 t69 t70 x0 b- p71 b69 s2:2 t72 s1:8,1:1 x2 x1 t73 p74 s1:2,1:1 t75 s1:1,2:1,2:2,1:1 s0:6,0:1 t76 s3:3 t77;ddb459eb8f6b2be0 +m60;0;0 0 1 1 0 0;0;2 1;3@-;t53 w5 t54 s4:1 t55 s0:1,0:1,0:1,0:8,1:2,0:2,0:1,0:7,2:80,0:2,1:1,7:3,0:1 t56 s1:3,1:3 t57 t58 t59 s0:1,0:1 t60 s0:1 t61 s0:2;e6de649a27752143 +m61;0;0;0;;;b- p0 p0 p1 p2 p2 p3 p3 p3 t4 t5 t5 t6 t7 t8 p8 p8 p8 p8 t8 t9 p9 p9 p9;c244a8c2cdab8b46 +m62;3;0 1 0 1 1 1 1 0 0;0;7 8 6 4;5@8 3@9;b7 s1:2,0:2,0:1 s2:1,0:2 p3 t8 s1:1,1:8,4:1,1:1,1:3,1:1,1:22,1:1,0:1,2:1,0:120,3:1,1:2 t9 b8 w7 t10 p10 b10 b13 t11 b14 p11 b16 t12 b14 p12 p12 s0:1,3:2 s0:2,4:1 t12 p12 p13 s1:1 p14 s0:1,1:2,7:1,0:4 t15 t16 s5:1,1:1,6:1,0:1,7:1,1:1;10b8842316a9a899 +m63;4;0 3 1 2;0;;3@- 1@7 2@11;x1 y t5 t6 t6 t7 t8 t13 t60 x2 b60 t61 y t79 t79 s1:1,3:1 b79 t80 y t85 w2 t90 t91 t101 t102 x2 t102 t103 w2 t104 t104 w2 t105 t107 t119 y y t123 w3 y t125 b124 t130 t131 t132 t135 t136 t137;f1bc4fdae458f79d +m64;4;0 2 0 0 1 2 0;0;3 2;1@- 5@- 6@9;t5 y b4 y s2:1,1:1 t6 t7 t8 p37 p37 t38 p39 t40 t41 p83 p83 p104 p105 p106 s2:1,2:2,1:2 p107 p108 t109 t110 p110 t110 t115 p115 t116 t117 t122 t123 p124 t125 p125 p145 t146 p147 p147 t148 p148 t151 p151 p152 t153 p154 p154 p154 t155 t156 p156 p157 t158 t159 p160 t160;ca0af59f763ed90e +m65;0;0 0 3 3;0;;;w1 s0:3,0:3,0:1,0:102 t1 b5 p1 p1 s1:5,1:1 p2 s0:1,1:2 t3 p3 p3 p3 t4 p4 s7:1,0:1;10069003647a0d40 +m67;992;0 3 2 2;0;;2@- 1@996;t993 t994 t1005 b- p1010 t1015 s3:4,3:4,0:1,2:2 t1016 p1016 p1017 x2 y y t1018 b1016 s5:1,1:3 t1019 t1020 p1020 t1023 p1026 t1027 t1028 s3:1,3:8,3:1,5:3,0:118,7:1,3:1,4:1,1:1,3:2,6:1,3:1,2:1,3:1 s1:1,5:5 s3:3 s0:1,3:3,0:3,0:118,2:1,3:2,2:1,1:2 t1029 s0:7,3:1,2:2 t1030 t1031 t1032;5a40b32c37ed60bc +m68;0;0 0 2 2 2 1 1 2 1 0;0;1 6 2 7 9 3;5@1 8@-;t1 p1 x5 t2 w4 t5 b6 t5 t6 w3 p6 y p6 w1 p6 t7 t10 t11 t12 t17 p17 b15 t18 x8 t19 t20 x9 p20 t22 t23 w8 t27 t28 t28 p30 b- p30 t31 p31 x6 t32 s4:5 p32 t33 b36 y t37 s6:2,0:1,2:1;5023a3f2948180e7 +m69;783;0 0 0 0;0;1 2;;x2 t783 t784 t787 p787 p789 t828 t829 b827 s0:1,1:1,0:2,7:2 t830 w2 t831 t831 t832 s3:2,2:85 p833 t876 p877 t878 t879 p880 t881 t882 p886 t887 t888 p888 t889 p893 p894 p894 p894 p894 t894 p894 t895 t896 t897 t898 p898 p898 s1:1 t899 t902 p903 p903 t904 t908 s2:1 t909 t910 t911 t911 t912 p912 t913 t914 p914 p916 s1:2 p918 p919 t922 t922 t926 p927 t928 p929 p930 p930 p930 p931 p936 p937 p938 t940 p940 t941 p941;0a2a8a6b2246e1ae +m71;5;0 1 1 1 1 1;0;5 4 1 3;2@-;t6 t6 p10 y s0:1,0:1 t11 s0:1,0:1,0:1 y x2 b9 t13 p13 y s1:2 w3 p14 t15 t20 w2 s1:1 t21 s1:2,0:1,1:3,0:1,2:2,7:7,0:1,1:88,0:2,1:2,0:3 p21 p22;ba202ce1b5e5a0c6 +m75;0;0 0;0;1;;t1 w1 t4 w1 y t5 t6 t7 y t10 t11 t14 s0:1,6:1 w1 y t18;3e5d54839064e323 +m76;2;0 0 0;0;2;;t3 w1 y t4 t24 p25 y p26 p27 p27 s0:3,0:1,0:2,6:1,1:2,0:1,6:2,7:1,5:1,0:1,0:2,2:3,0:1,0:1,0:2 t28 p31 p33 p33 s0:1 y b32 p37 w2 p39 t40 t41 y;121397c5e01b6e2b +m78;0;0 0;0;;1@-;t1 t1 w1 y t2 t3 y t7 t8 t9 t10 t15 y y b- b14 p16 t20 w0 t20 t21 s3:2,3:2,1:1,2:2,4:1,3:2,1:2,0:7,2:1,3:3 w1 y t35 t35 t36 t37 t38 y y t39 t43 p43 p43 p44 t45 p50 p84 s2:2 y t85 y t86 t87 t88 t88 p88;00c41945742ff2a1 +m79;3;0 3 1 1 0 0 0 2;0;4 5 3;6@- 1@2 2@-;t4 y t4 t5 t9 y y x5 t10 t11 t12 w1 t13 y t14 t15 t16 y t17 b22 t18 y y t19 y w5 s0:1,0:7,0:1 y t20 s2:1,3:3 t21 t22 s2:3,2:2 t23 t28 p28 p29 p29 p30 s1:3 t31 s0:177,2:1,3:3 t31 t33 t33 t34 t35 b39 t36 t37 t38 t39 t40 y t41 t43 x4 t44 t45 t50 t50 t50 y t51 t52 t74 t76 t80;00390ead30b7a467 +m80;0;0 1 1 0;0;3 2;1@-;t1 t2 x1 s0:2,1:14 t7 t67 x3 p67 t68 p68 w0 t69 s0:1,0:1 t69 x1 t71;ab3be82d2329ee0a +m81;5;0 0 0 0 0 0 0;0;2 5;4@12 1@12;t6 t7 t7 t8 p9 w0 x6 y s0:1,1:7 x2 t10 t11 t12 p12 t12 p54 t55 p60 t60 t61 p62 t63 t64 t65;b450b0461c19bae2 +m82;5;0 0 0 0;0;2;1@-;t6 b8 b8 p11 y b17 t12 w1 t13 t14 s3:1 t15 s3:1,3:3 t16 t17 p18 t19 t20 t21 t22 p23 t24 t25 p26 p26 t27 p30 p30 t31 p32 p37 t38;b2f0c02e3a39f24b +m83;0;0;0;;;b- p0 p0 p0 p0 p2 s1:2,1:1 s0:1,0:2,0:3,2:28 t3 s7:1,1:1 s1:2 t4 t5 t24 t25 t26 p26 p26 p26 p26 t27 t28 t79 p84 p84 t85 s3:1,0:1 s2:2,1:1,6:1,0:1 p86 t87 p87 t88 t91 t92 p93 p96 t97 t98 p98 t99 p100 p101 t106 s1:1,1:1 s0:5 t107 s0:1 s2:1;ff4fbd4a419f5917 +m84;5;0;0;;;w0 p5 t6 w0 b8 p6 t7 p11 y w0 w0 b16 p16 p19 t20 t21 w0 b24 p21 p24 p24 t25 b- p25 s1:2,1:2,1:1,1:2,1:2,1:1,1:2 p25 p28 p29 t30 s1:2,1:5 p31 p32 p33 p37 p37 p37 p37 t38 p38 p39 t40 p40 t41 p41 p42 p44 p49 p49 p50 t51 s0:2 t52 p52 p53 p53 t54 s4:2 p54 s0:2,1:1 t54 p55 s1:2,1:1,1:1,1:1,1:1,1:4,1:1,1:1,1:1,1:1,1:3,1:80,1:2,1:1,1:1,1:1 p55 p56 p57 p69 p70 p70 p71 p71;e27e3e41d2ae390c +m85;0;0 1 1 0 0 1 0 0 0;0;2 5 8 7 1;6@- 4@- 3@-;p0 t2 t3 b6 b- t3 b- p8 t9 b- p11 p11 p11 s6:1,7:6,1:1 t11 p12;77fb1e3d925538e6 +m86;0;0 1 3 0 3 3 0;0;5 3 1 2 4;6@2;t4 t5 w5 t6 w5 t6 t7 y s2:1,3:2,2:1,5:2,1:140,1:1,3:1,0:2,3:1,1:1,2:1 s1:1,1:2 t8 s3:2,2:1,1:1 s2:2,1:2 t9 t10 p14 t15 p15 p16 t17 t18 t19 t20 s1:1;47120877d44137fc +m87;0;0 1 0 0 1 0 1 0 0;0;7 2 4 3 1 5 8;6@-;t1 b- y y t2 b- y t3 y x6 t4 t5 t9 b12 b7 b12 t9 t59 t60 b- b66 b- b66 s0:1,4:1 p60 t61 t62 p62 p62 p62 t63 p63;a482aa6182d580b0 +m89;3;0 0 1;0;1 2;;t4 w2 t5 p32 p32 t33 p34 y p35 y y y b- t36 p37 b41 p42 p42 y p42 t46 t47 x0 p47 x2 s2:1,2:91,2:1,2:1,2:1,2:2,2:1,2:1,2:2,2:213,2:1,2:1,2:2,2:1,2:1,2:2 y p47 b45 t48 p52 s0:1 t57 t57 p57 t58 y b58 s0:3,3:7,1:1,7:2,7:1,1:1,7:2,1:3,6:2,2:3,1:3,2:3,2:2,2:1,0:3 t59 y t61 t62 t63 p64 p64 p64 t65 t66;cc6a08eaa4709884 +m90;534;0 0 1 0 0 0;0;2 1;5@- 3@540;y s2:2,1:2,2:1,1:60,2:1,1:181 s0:1 t535 s2:2,1:1 s2:1 t536 t537 p537 s0:7,2:2,1:3,0:2,2:2,1:3,2:3,2:1,1:1,2:1,1:1,0:2,1:1,2:1,2:2,6:1 p537 t541 s1:6,2:2,6:1 s2:1,2:1,2:2 t542 w0;043e332fcacf4b99 +m91;3;0 0 0 0 0 0 0 0 0 0;0;8 1 6;9@- 5@- 3@3 4@11;t4 t5 y t6 y y t7 y y t8 y y s0:1,0:1,0:2,0:1 p8 p11 t12 t13 t14 t15 t16 t20 t21 y b-;cafaace6ab867b12 +m92;0;0 0 0 0 0 0 0 0 0 0;0;4 1 3 6 9;5@- 7@7;t1 t2 t3 t4 t5 t6 x1 t11 w0 y t12 t14 t18 t19 y t20 x1 x1 s1:1 b- t21 t22 t27 p28 t29 t33 p33 p35 p36 p39 t40 t41;172bfaf79439dd53 +m93;4;0;0;;;t5 p6 b- t10 t11 t14 s0:2,1:3 p15 p16 p16 s0:2,1:1,1:2,7:1 s1:1,0:2,0:3 s0:4,0:3 s3:3,0:2,7:8,1:202,1:3,1:2,1:1,1:6,0:2,4:1,1:3,7:2,0:2,5:3,3:1,0:2 p16 s1:3 p16 t17 t18 p18 p18 p18 s0:2,1:1,1:1 t19 s2:1,1:1,1:68 p19 p19 t30 t31 p31 t31 p31 s0:82 p32 p32 p32 p33 s0:2,1:1,1:1,1:3,0:3,0:1,0:1,2:2,1:2,0:2,1:1,1:1,1:1,0:2,0:1 p33 s1:2,3:2,1:1,0:2 t36 p37 s0:1 p37 p37 t67 p68 p68;382f0707159d344a +m95;3;0 1 0 0 0;0;4 1 3 2;;t4 t5 y s1:1,7:1,0:1,1:1,0:1,1:1,5:1,1:1,1:2,1:1,4:3,0:1,0:1,1:2,3:1 t6 w3 y w3 t6 t7 b- t9 w4 s0:1,0:3 s0:1 t10;545095b0b9714ce8 +m96;0;0 0 1 0 0 1 2 0 1;0;2 5 7 4 1;6@- 3@4 8@-;s1:2,1:1 t1 s1:3,2:1,0:2 t2 s3:1,1:1,1:1,0:1 t3 t4 p4 p4 t5 t6 t22 b28 p22 t23 t24 t25 t26 s0:1,0:1,0:1,0:1,0:3,0:1,0:2 t27 t28 p28 s2:3,0:1,6:1 t42;51976c8c2208326e +m98;0;0 0 0 0 0 0 0 0 0;0;2 1 6;5@1;x8 t0 t1 t4 t4 t5 t9 t9 y s1:84,1:1,1:123 t10 t15 p15 t16 s4:1,1:1,1:1 p16 s2:2,2:1 t17 s0:1,0:2 t18 s0:1 t19 t20 y y b19 t21 t22 y t23 y t28 p28 t29 p34 p34 y b35 s7:1,6:2 t35 y y b38 t36 p36 t37 p37 p39;92f9eba9198d3caf +m99;0;0 1 1 1 0 1 1 0;0;1 3;;w6 b- s0:1,0:2,1:81,1:2,0:2,2:1 p0 t0 p3 t3 t4 p5 b6 b3 t5 s1:1 t6 s1:1,0:1 w4 t6 t7 t8 w0 t10 y w0 t43 t43 p44 w2 w4 b45 t45 t46 b- x0 b- p46 p47 t52 t53 w7 s0:2,0:2 t54 s0:1,0:3 t55 t56 b54 s0:2 p57 p58 t59 x3 b- t116 p121 t122 t123 p126 p126 t127 t128 p128 t129 p129 t130 t130 t131 p132 t146 p150 p203 p203 p208 s1:1 s4:5 p210 s0:1,1:3 t211 t214 x4 t215 t216;a2991f2c6d274328 +m101;0;0 1 0 0 0;0;2 3;4@7 1@6;x1 s0:2,0:2,0:1,1:1 t1 s1:8,0:1 t2 s7:1 t3 t4 p4 p11 t13 p14 t15 p15 p16 t17 s1:2,1:1,0:1,1:2,1:3,0:1,0:3 s0:5,0:1,0:1 t18 s3:3 s1:1,1:2 t19 t20 p21;f70f7bc65ca6d137 +m102;0;0 2;0;;;t2 s1:1,1:1 s2:1,1:8,2:7 t3 t4 t4 t5 t6 t7 p7 t8 t9 s0:1 s0:1,2:1,1:1,2:1 t10 s1:2 s0:1,7:2 t11 t12 t13 p14 p14 t15 t16 t17 t17 p17 p22 s2:2,3:2 s2:1,7:8 t23 s0:1,1:2;2bb9469272ec99ea +m103;2;0 0 1 1 2;0;4 1 3;;t52 t53 x3 w0 t54 w0 y s1:1,2:1 w3 x1 x1 w3 t55 x2 t56 x1 p56 w3 t73 w4 x0 w1 w1 x3 w0 t76 x0 y w1 t76 w1 w1 t86 w1 b89 t87 t87 t89 b92 p89 p90 s1:3,0:1 w4 w4 w3 p90 x2 p92;62e059c3ea516b0e +m104;4;0 3 3 1 0 2 1 0;0;2 5 1 6 3;7@-;b- t5 p5 s5:118,5:1 t6 s3:1,3:5 t7 s2:202 t8 t9 t10 t11 s2:1,2:1 t12 s2:1,5:1,3:1,1:1,0:1,3:1,3:1 t13 b- p18 s7:1,0:1,0:2 s3:1,2:2 t19 b- b22 s6:8,2:3,0:2 t20 p20 t21 p22 t23 t23 p23 s1:3 t24 s1:2,2:2,2:3,1:1,0:3,1:1,6:7,4:1,3:1,0:2,6:2,0:1,1:2,2:1,3:1 t25 s3:1,0:1,1:246 t26 t27 x0 t29 p29 x7 b34 t31 t32 p33 t34 s1:1 y y y p35 t36 y y t37 x2 s2:4 y p38 t39 t40 p41 p77 t78 t79 p79 p79 t81 p81 s2:1,2:2,2:2 s3:1,3:4,3:3 t82 s2:2,3:1,3:154,3:2,3:3,3:3,1:1,1:2,2:1,3:1,1:1,1:2 s2:2,1:2 t83 t84;eac31d76e43c7f03 +m105;0;0 0 1 2 0 1 0 3 3 3;0;6 4 9 2 7 5;1@- 8@-;x8 y t1 t2 b8 t6 x8 x2 x2 t7 t8 t9 t10 w5 b12 b12;3fd431f1accea325 +m106;3;0;0;;;b3 p4 s1:1,3:2,1:1,1:8,0:1,1:1,1:1,0:2,0:8,7:1,0:6,7:2,0:178 s1:2,1:2,1:3 t5 t10 t11 p11 p11 p11 p11 p12 p12 p12 p15 p16 s0:1 p16 p19 t20 b- p20 s1:5,0:1,1:1,1:1,0:1,0:1,1:2,3:3,1:1,5:1,1:2,0:237,0:3,1:1 t21;c3e908e16d82a7df +m107;0;0 0 0 0 0 0 0 0 0;0;5 3 4;6@7 1@-;t1 s1:3,1:1,0:68,1:1,1:1,2:3,1:1,0:3,0:189,4:3,2:2,3:2,1:2,3:1,2:1,2:1 w6 t2 p3 s0:3 t4 p5 s0:3,0:4,0:3,0:2 p5 y b8 y t6 t11 t12 x3 t14 p14 p14 b- t15 s1:1,2:3,1:2 w6 t22 t23 p24 p25 t26 s2:3,0:3,0:2,0:3 p26 t27;a4af5ad23ef1d00e +m109;3;0 3 3 1 3;0;;2@10 1@6;t4 t9 t10 y s2:142,1:2 s5:1,6:1,1:1,1:1,7:1 t11 s0:98,2:2,2:1 s2:1,0:2,1:1,6:6 t12 t13 t14 b19 t17 p17 p18 t20 p23 t24 y w4 x0 t25 t26 p27 t28 t29 t29 t33 p34 t35 y t35 t35 w3 s0:1,0:1,0:3 t36 s2:1 t37 t38 p39 t40 s3:1,1:1 s1:7,3:2,0:1 t41 p41 t45 p45 t46 p50 t52 t53 t54 p58 t62 t67;311768579ebf4b8e +m110;0;0 3 2 0 2 3 3 1;0;4 6 1;5@- 3@8 2@8;p0 y t1 y w4 p2 w6 y w3 t3 t4 t5 b11 t6 t8 w3;9d459371fad8a591 +m112;664;0 0 0 0 0 0;0;2 5 4 1;;x2 y x1 b663 x3 x2 p665 t666 p668 t668 w3 t668 x1 x3 s0:1,0:7 x4 t669 x1 t670 t671 x3 s0:2,0:1 b673 x4 y t672 y x4 w5 s0:2,0:1,0:2,0:2,0:8,0:1,0:1,0:2,0:1,0:3 w4 y;c6ce1feb8a2fd989 +m113;1;0 0 0 0 0;0;3 4 1;2@-;t1 s0:3,0:1,0:1,0:1 s1:1,0:8 t2 t5 t6 t7 t8 t9 t14 t15 t16 t19 t20 t21 s0:1,0:4,1:2 p26 x3 t27 t28 t29 t38 t42 p43 p43 t44 s1:7 t45 t46 t47 t99 p100 s0:3,1:1,1:1,1:5,4:2,1:1 t101 t102 s1:190 y t103 y t104 p104 t105 t106 t107 t107 t108 t165 p166;49dfc0105b2b6c8f +m115;2;0 0 1 1 0 0 1 0;0;5 1 4 6 7;2@-;t3 w0 t8 y t9 w7 w2 t10 w3 t15 s1:1,0:2,1:2 s0:2,0:2 t16 s1:1,1:1,4:1 s0:1,1:6,1:1,1:2,0:1,1:1,0:1,0:1,1:3,0:1,1:2,0:1,1:1 t17;35c57f11e85b8a8e +m117;1;0 0 0 0 0 0 0 0;0;7 2 5 1 6;4@2 3@-;t2 b1 t3 t4 w3 w2 b6 x6 w2 x6 b3 b8 b6 t6 p6 b- x5 w4 b- b6 b7 t7 b8 y s0:1 t9 b- t10 y b10 b- b9;cf57cd6010228491 +m118;0;0 0 3 3 3 0 1;0;3 2;6@- 4@- 1@-;x6 y t0 t0 y t1 p1 y p2 w1 w6 t3 w1 x4 w0 b7 t4 b- p4 p5 t6 p7 w0 t10 y b- p11 w1 t16 x1 w5 t17 t18 t19 b- p20 p22 y t23 b- p23 p24 p74 t77 t90 t145 t150 p150;6c80ed4d97681cf4 +m119;0;0 0 1 0 1;0;2 1;4@7;t1 t2 t2 t3 y y t5 s0:2 w2 y t29 w0 y t30 t31 y y p32 s2:3,2:8,0:3,1:1,2:2,1:3,0:1,0:1,2:1,0:1,2:2,3:2,1:1 s2:3 x1 t32 s2:8,5:7 y t33 t34 p34 s0:219,0:1 p34 t35 s2:3,5:1 p39 p39 t40 t41 s0:1,0:1,1:1 p41 p41 p62 x4 y y y s6:1 y y y y y w0 y y x2 y y s1:1,2:2,1:1,0:1,0:3,0:1,1:1,2:3,0:1,0:3,0:2,1:1,4:1,6:2 y t64 x4 y y w2 x3 y t65 p65 p65 p65 p65 p69 t70 w4 t71 w4 p72 t73 w3 x1 x3 t74;6367749e70df73ee +m120;4;0 2 0;0;2 1;;b2 t5 b4 s3:1 t6 s0:1 t7 w2 t8 b10 t9 b13 p9 p10 s3:1,2:60,2:176,2:8,0:2,2:2,0:1,4:3,0:1,3:3,0:1,0:2,1:4,6:2,3:1,1:3 t11;f3c3531dfd20d5c7 +m122;5;0 1 1 0 1 1 1 1 3 1;0;4 5 7;3@- 6@7 2@- 9@4 8@11;y t6 t7 b- p7 p7 t9 s5:2,2:1,1:2,2:2 t10 t11 p11 p11 t12 t13 t14 t15 t16 p16 p20 p21 x0 t21 t21 t22 t23 s3:2,0:2 s7:123,7:3,7:8 p24 p24 t25 t26 p26;1902eb8a1237e9c9 +m123;0;0 3 2;0;;2@-;t1 t2 t3 t4 t8 x2 t13 t14 b- s0:1 t15 s6:8,6:1,5:2,7:1,3:1,7:3,1:184,0:1,1:1,2:226,2:1,1:1,0:2,7:2,3:2,7:1 t16 t17 p17 t18 p19 t22 t23 t28 t29 s0:1 s1:1,1:1 t30 s2:2,2:3,2:1,0:2,2:3,3:2,2:2,3:2,0:8,0:1,4:3,3:1,6:7,1:2 s1:2 t31 t32 p32 p32 t33 p34 t35 p35 t43 p43 p46 t47 p47 t47 p47 t50 t101 p101 p101 p101 t102 p103;7c3a7f0dd0703629 +m124;0;0 2 0;0;2 1;;t4 t5 b4 t6 b- y b10 s4:1,1:2 p10 t13 p17 t18 t20 p21 p22 p23 p24 t25 t43 p44 p45 t46 s2:1,2:214,2:2 t47 p48 y t49 b- p50 p50 p76 p76 s3:1 p77 p77 p77 t78 t79 t80 p80 p99 p99 p99 t100 p100 p101 t102 t107 p107 t108 t109 p109 t110 p115 s1:247,0:75,1:2 p115 p116 p117 t118 p118 p119 p120 t121 t122 p122 p122 p122 p178 t194 t195 t196 p196 p198 t202 p202 s5:2 t202 p203 s2:1,4:1 p203;bd9b82e3c4e2cf6e +m125;0;0 1 0 2 1 1 2 1 2 0;0;1 4 6 9 8;7@7 5@2 2@-;t1 p1 x9 x7 t2 s7:1,2:1,2:3 t3 x9 x8 t4 t5 t6 t6 t7 t8 s2:4,1:6;06f06524becbee8e +m126;0;0 2 1 1 0 1 1 1 2 1;0;4 2 9 1 3 7;5@- 6@2 8@-;y b5 y t1 t2 t3 b- p3 p3 p3 t4 t5 w0 s0:2,0:1,1:2,5:2 t6 s2:1,0:1,0:2,0:1,2:1,2:1,1:1,2:1,0:8,1:1 b11 s2:2,2:1 t7 b9 p7 t8 y t9;b804f233c9564efc +m127;2;0 3 1 0 1 1 0 1;0;2 4 5 3;7@8 6@-;y b- t3 x6 t4 b- p5 p7 s2:2,0:5,2:1 s0:2,2:1,3:1 t8 p9 p11 t12 s5:1,6:3 p13 t14 p14 p14 p16 p17 p17 t18 t19 t20 t24 p24 t26 p26 p26 p27 p27;2f225059fa10ce66 +m128;1;0 1 0 0 0 0 0 0;0;5 6 1 4;7@7 3@6 2@-;t2 p2 p55 p55 t55 t56 t61 p61 w4 p61 p62 b63 t63 s1:56,1:3,1:1 t64 t65 t66 b71 p66 p66 p66 s0:4,1:1,7:2 s0:3 p123 t123 t124 b125 w2 x1 b126 s3:1,2:1,1:1 b130 b127 t125 t127 p132 p132 p132 p132 p132 p132 t133 p133 t134 p134 t134 b- p139;ecbbe4a08be3b949 +m129;0;0 1 0 1;0;1 2 3;;t1 p1 b- p3 t4 x2 t7 b- p7 t8 t9 p9 t10 t13 p14 p19 t24 t28 p29 t30 t31 p32 t33 t34 p43 p43 p44 p44 p104 p105 t106 p111 t113 p114 p114 p114 p114 t115 p118 t119 p124 t170 t171 t172 t173 t174 p174 t174 p179 p180 p181 p181 t181 p181 p186 t191 p191 p192 p192 p192 t193 p194 p198 p199 t200 t201 t201 p201 p206 t206 t206 p206 p206 t207 p258 p259 t259 p260 t261 t262;db17d3cffda72b7c +m130;0;0 1 1;0;2 1;;t1 t2 w2 p6 w1 b6 t7 x2 t8 t9 w0 t10 t11 t12 t16 t17;ffea191e7b95fc9b +m132;0;0 1;0;;1@-;t2 b- t6 t7 p8 p12 t13 t14 p14 t15 p16 t17 p20 t22 t27 t28 p33 p33 p34 p34 p35 p35 t36 p37 p38 p38 p39 t40 t40 t41 p41 t41;9c8e188c9c517c23 +m133;0;0 2 0 0;0;1;2@4;w3 b4 t1 p1 t3 p7 t8 t9 s0:1 t10 t11 p12 s0:1 t13 p14 p14 t19 t20 p21 t22 x1 t22 b27 b20 p22 t25 t26 t27 t28 t33 p34 w2 y p34 t39 t42 y w1 b48 p42 t44 t68 w1 t69;6b11f9d555ae7151 +m134;0;0;0;;;t0 t1 t2 t3 t4 s1:1,0:3 s0:1,7:1 t8 t9 p9 t69 t70 t73 t74 t75 t76 t77 t78 t79 p80 t81 t82 y w0 t83 t84 t85 t86 t88 t89 t90 t91 p95 s1:2,1:1,1:1 t96 s2:1 w0 x0 y t97 t98 t100 s0:3,6:3,1:1,2:2,2:2,1:2,0:1,2:1,0:2,1:1,2:8,1:1,2:2 t101 t106 p106 t107 p108 p108 t109 p109 p109 t110 p114 p115 t116 t117 w0 t117 t120 t121 p123 t124 t126 p128 p128 p129 s2:1,1:2 t130 t131 t132 p132 p136 p136 t137 p138 p139 t140 p140 t141;c5a017c2eb96c8d7 +m135;0;0 0 0 0 0;0;2 3 1;4@4;s2:3,0:1,0:3 t2 t7 y w0 t8 t9 t14 w0 x3 t19 s0:1 t20 s0:8,0:3,0:3 x4 b22;5543c9800b52c38e +m136;0;0 1;0;1;;x1 t1 p2 x0 t3 t4 t5 w1 w1 w0 b- t6 p6 t7 p11 p12 t16 p17 t18 p18 p43 t44 t49 t50;37c56d017cc9fc69 +m137;0;0 0 0 0 1 0 0 0 0 0;0;2 1 4 5 6 3;9@3;t1 p2 t3 t4 t5 t6 t7 t8 s5:1 t9 w6 t10 s2:1,1:1,2:7,1:1,2:2,0:2,1:1,2:2,2:2,0:2,3:1,1:1 t11 s0:7 t12 t13 p14 x7 t15 p17 p22 x4 t23 b22 t24 t25 t26 p26 p27 t28 x7;d68cac375a8be2f8 +m139;0;0 0;0;;1@7;t4 x0 y b2 t29 t31 y y y t32 s1:1 t33 b36 w1 y t33 w1 b37 p34 p34 p34 p35 t36 p37 s0:48,0:1,1:1,1:1 t38 p38 t39 w0 y t40 b- w1 t41 b40 w0 x1 y t41 t42 b43 t42 s3:1,3:78,3:1,3:2 y w1 t43;c6b7dd9a849907a4 +m140;3;0 1 0 0 2 2;0;1;2@-;t6 p6 s2:2,0:1,0:1,0:1 y t7 t8 p9 p14 t15 t63 t64 p64 t65 p65 t66 t67;b2c90b579d3919d4 +m142;0;0;0;;;t1 w0 w0 p2 t3 s1:2,2:1 t4 w0 t5 p5 t6 t6 p7 p7 s0:1,1:1,0:1,1:1 s1:1,1:1,1:1 s1:2,3:1 s1:2,1:1 s1:2,0:1,0:1 t8 p8 s7:1 s2:8,1:3 t9 p10 p10 p10 t11 p11 p12;7a63fadf4c236279 +m143;0;0 2 3;0;2;;b6 p18 t19 t20 t21 t22 t25 t26 t27 t28 t29 t30 t31 s2:1,3:2 t32 t33 p36 p37 y t38 s2:1 t39 t40 p41 t42 p42 s2:3,2:1 p43 p44 s1:1,3:2,0:1,3:3,3:3,1:2,1:1 p44 t46 t47 b48 p47 t48 t49 t50 t51 y s7:1,3:1,1:3,1:1,0:1 t52 t53 p57 s0:1,0:1,2:1 t57 p58 p58;29ba6d62f57a15f9 +m144;85;0 1 0 1 0 0 1 1;0;5 7 4;3@90 6@-;t90 b93 b91 y b88 p90 s1:1 x6 x3 s0:2 b95 t90 p90 p91 b- p93 t93 b92 s1:2,1:1 t98 t99 w6 b105 s0:2 t100 t101 t102 t103 y t104 t108 w1 w0 x6 p112 b- t113 y b112 p113 b116 t114 t115 t116 y b117 t119 t120 s1:2,0:1,1:2,0:1,1:1,7:1,1:1,1:1,1:1,7:1,1:1,1:3 w3 s1:3 p121 t122 y t125 s1:2 w2 t126 t127 t128 w5 t130 w0 t131 t132 b134 s4:1,1:2 p132 t133 t134 s1:1,1:2 p134;c1f4d40724e77b90 +m145;0;0 0 0 0 0 0;0;2;3@6;t1 t2 t3 t4 t4 s0:1,1:1,2:2,1:2,0:71,2:1,2:1,1:238,0:1,0:1,0:1,2:1,2:1,1:1,2:7,1:1 p8 s1:1,1:100,1:1 p9 s0:1,1:2 t10 s2:2,1:2 p10 s2:3,2:1,0:1 t11 p11;db6ee9587c48caab +m146;0;0 0;0;;;t1 t5 x1 p10 t11 b17 s0:1,1:1 p12 p13 p14 p15 s5:1,4:1 t16 s1:1 t17 s1:2 t18 t19 s1:1,1:1,1:1 t20 s0:1,0:5,0:196,1:1,5:1,5:8,0:1 t21 t22 x0;fd5566149b1484fc +m147;2;0 0 0 0 0 0 0;0;6 4;2@2;w2 w1 t3 t4 t8 y s0:1,0:2 s0:2,0:1,0:252 w5 s0:221,0:1,0:2,0:1,0:1,0:1,0:3,0:2,0:3,0:4,0:1,0:1 w5 w0 y s0:4,0:1 b8 t11 w2 y t12 t15 w0 y t16 t17 t18 t19 t20 s0:2,0:6,0:1 w4 y y t23;da9c2b04ddd577d2 +m151;0;0 0 0 0 0;0;2 1;3@1;b- s0:1,0:1,1:1 t1 t2 t3 s4:1,2:1,5:2 t3 p3 s1:1,3:2 p3 t4 p4 p4 p4 t5 s1:2 p5 t6 p7 s3:2,0:96 p7 t8 p8 s5:1,1:1,2:3;46899a8f2835d62a +m152;0;0 1 1 1 1 1 3 2 3 3;0;7 9 6 4;5@- 1@3 8@-;t2 t3 t4 t5 t6 s0:1 t7 t8 w3 t9 b- t13 p13 t18 p18 t19 t22 t23 p23 p24 t25 t26 p27 p30 t31 p32 p32 p35 p35 t36 p37 p37;d21bf2257ab0fb8f +m153;3;0 0 1 1;0;2;;x3 t4 b10 p5 p5 p5 t10 s1:1,1:2,1:1,7:2,1:5,1:1,0:1,1:1,0:1,1:2,1:1,1:2,1:1,1:2 b- s1:1,0:2,0:8 t11 s7:1,0:1 t12 t13 s4:12 s1:3,1:2,0:2 p14 p14 p15 b15 t15 p16 b18 t17 p18 t19 b19 t20 p22 y t23 b- p23 p23 s4:2,0:1,1:1 t24 s0:1,0:3 t25 p25 t26 p26 t27 t29 p29 t30;12e21f01c6206d13 +m154;5;0 0 0 0 0 0 0 0 0 0;0;3 1 6 5 7 4;2@- 8@9;t24 w2 w2 t25 x3 s1:1,2:1 t26 s5:1,1:1 t27 s1:2 t28 t29 p29 t30 p30 t31 t32 p33 t50 t51 p51 p54 p58 t59 p59 p60 t61 s2:1,1:1 s1:3,5:2,1:1 t62 s2:3,6:2 s0:3,5:1,2:1,0:2 t63 t64 w4 p64 s1:2,1:1,3:2 y s1:1,0:3 w6 t65 t70 p72 p72 w1;c57a411a061f0d41 +m155;0;0 2 0 2 2;0;3 2 4;1@5;t0 p0 s2:3,1:1 t1 x1 w0 t2 b- t6 b10 t27 b28 b- t28 x1 b-;c4a646b7a5405d35 +m157;0;0 0 2 1;0;3;2@- 1@8;t1 t1 t2 t4 t5 t6 b8 p6 p7 p7 t8 b13 t10 t11 t12 y b14 t13 t14 t15 t16 x2 s1:1,0:67 t17 t18 w0 s0:2,0:1 s2:2,2:3 t19 s0:1 s0:1,0:1,0:1,0:154,0:1,0:1,0:2,0:1,0:1,0:6,0:1,0:1,0:1 t20;36563f39212f5fc8 +m158;0;0;0;;;s4:1,0:1,1:1,1:2,1:1,2:1 t1 s0:1,1:1 p1 p3 s6:2,6:1,6:3 p3 x0 t4 p5 p5 t6 t7 t8 p9 p13 p13 p13 t15 p75 t76 p81 s1:225,0:1 p81 t82 p83 p86 p88 p89 p89 p90 s1:1,1:2,3:3,0:1,1:1,1:3 t90 p91 p92 p95 p95 t96 t96 s1:1,1:2,0:2 p96 t99 t100 p101 x0 y w0 s0:4,0:2,0:2,0:2;36776f5411123410 +m160;1;0 1 0 0 1 1 1;0;4 1 3;;t2 t7 p8 w6 p8 s1:1 s0:1,1:1 s1:2,0:2,0:1,5:1,0:1,0:2,5:2,1:2,1:2,0:2,1:2,1:3,1:3,1:1,1:1,1:2 b10 b- t9 p9 p9 p9 t10 x2;9ebed3958ac67dc0 +m161;4;0 1;0;1;;y t5 p6 t7 x0 s1:3,1:2,4:1 p12 t59 t60 t61 t62 t63 t64 s1:1 t65 x1 t66 t66 b72 t67 t68 t69 t70 p70;af47f7b65908544e +m162;0;0 2 3 0 0 0;0;1 2;4@3 5@2;t1 t2 t2 p3 x0 t4 p4 w5 p4 t4 x4 s0:8,0:1,0:1,1:1 t5 s3:1,1:1,2:1 t6 t7 x3 t12 p14 p15 w2 w3 t16 t70 x2 t71 p72 t73 p73 x0 b74 p74;8220f1136f8a6dae +m163;0;0 2 0;0;1 2;;y y t2 t22 y y t23 y y s2:1 s2:1,6:2 b- y t24 t26 t27 t28 t30 t31 y y y x2 t32 p37 y x2 t38 s1:3 s1:1,0:1 t40 t41 t42 s0:1,2:1,0:1 t43 s0:1,1:1,1:1 t44 s1:6,0:2,0:1 t45 t46 t48 p48 s2:2,2:1 p48 t49 t49 t49 t50;4ac45e9cf281ffbc +m164;2;0;0;;;t3 t12 w0 w0 b18 t12 s2:4,2:2,2:1,2:1,2:2,2:2,2:2 t12 p29 t30 p31 p31 t32 p32 p33 p33 p34 p36 s0:2,3:2,1:1,5:1 p36 p37 p38 b37 t39 s1:1,5:2 t40 s0:1,0:1 t40 t45 b45 t45 p45 t46 w0 w0 t47 t48 t49 t50 x0 t51 t69 t70 t71 b74 t72 s4:3 t73 p73 s2:1,2:2,1:1 t74 s0:3,0:2,0:2,0:2 t75 t76 t77 b75 t78 b81 t79 p79 t82 b- p82 p82 p83 s0:1,0:134,1:1,2:2 t84 s0:1,0:6,6:1 t85 s2:1,1:1,2:1,2:2 t86 t87 p87 t88 p88;b5da28ab5e9106ae +m165;3;0 1 0 0 1 1 0 1;0;7 6 3;1@8 5@1;t23 w5 b25 s1:222,1:1,1:5 x5 t24 t44 t65 b- s1:3 t66 y t67 y w5 t67;cd0ee5ccb792130e +m166;0;0 2 1 1;0;2 1;;b- t5 t6 p7 t8 s2:4,1:1,0:1,1:1,0:3 p13 t14 b15 p14 t15 p15 p15 p29 t30 b- p30 p30 p30 t31 p32 t37 p37 p38;5fa90a688bfc7189 +m167;0;0 0 0;0;1;2@-;t2 p4 t5 t6 s0:1 s2:8,1:5,1:1 t7 s2:1,2:3,2:1 s2:2,0:1,0:3,0:1 t8 t9 t43 t44 p45 t48 x1 b47 p48 t49 t49 t49 p50 t51 p52 p73 p74 p74 y w2 s1:204,0:1,2:2 b73 s0:1,5:1,5:215,1:1;359342c58d41ba64 +m169;0;0 1 0 2 1 1 0 0 0 2;0;6 3 2 5 4 1 8;9@-;t22 y t23 b29 s1:3 t24 s2:3 t25 s0:6,0:2,0:2 t26 t27 t30 w4 t31 p36 w0 t37 y t37 t39 b- p67 x9 t68 t69 t70 t71 p71 t72 w8 t73 t74 t75 p77 t78 b77 t79 s1:1,0:3 w0 x4 t80 t81 x0;321ecad682e2c087 +m170;5;0 0 0 0 0 0 0 0;0;5 7;6@- 1@- 4@-;x6 t6 t7 y t8 y s1:2 b10 t8 y t9 t10 p10 s0:1,1:3,1:1,4:1,7:1,0:1,1:4,0:8,1:2,0:1,1:2,0:3 t11 t12;08d1872bb13da5e5 +m171;0;0 0 0 0 0 0 0 0 0 0;0;3 2 8 5 7;4@- 9@2;x1 t0 t2 s0:1,0:1,0:1 p2 t3 w4 t4 t4 p4 p4 t59 x9 p60 t111 s0:1,0:1 t112 s1:1,0:2 x1 t113 w6 t114 p115 t119;7a5da57fcc285499 +m172;0;0 2 2;0;2;1@3;w2 p0 t57 p58 t59 y t60 s1:1 y w2 y t61 y y t62 p63 s1:3 p68 t69 p69 p70 t71 p71 p74 p74 t76 p81 p82 t86 t87 t91 p92;b452799f8484e45d +m173;0;0 0 0 0 2 1 2 2;0;7;2@- 5@5 1@-;t1 w2 t2 t3 b- t7 t8 x5 b- p9 p10 t11 t12 s6:5,6:1,6:1,6:213 s1:82,2:1,7:1 t13 s5:1 s1:17,0:2,0:1,1:1,1:1,2:1,7:1,0:1,2:1,0:2,1:204,0:243,1:1,2:2 t14 t15 b15 s4:2,4:1,4:3 t16 b- t19 p19 t20 s3:1 s2:1 p22 y b26 p23 p23 p27 t28 y s1:8,2:1,1:1,2:1 t29 s1:1,5:1,0:2 t30 s0:3 t31 t32 t35 s2:2,0:1 p36 p40;7be9328b3a4dde6d +m174;0;0;0;;;t1 t2 b5 s1:1,1:2,0:1,0:1,2:4,1:2,1:1,0:1,0:1 t3 s1:1,1:6,0:2,0:1,1:3,1:8,1:3,6:2,0:1,1:2,0:2,0:1,3:1,0:1 t4 p5 t6 t8 s0:1 s5:7,0:2,0:1 t9 t10 t11 p12 p12 p12 p13 p18 b19 t19 t24 t25 t26 s1:3,1:1,0:1 t27 t27 t28 p29 p29 s1:2,1:1,0:1,1:3,7:92,1:3 t30 s1:3,1:1 p32 p35 t36 t36 p37 p41 s2:7,5:2 s0:1,0:2,0:1,0:1,0:1,0:2,0:2,0:2,0:2,0:1,0:1,0:2,0:147,0:3,0:1,0:1 p42 p42 s0:3,0:3,0:1,0:1,0:1,0:1,0:2,0:1,0:2 p42 t43 p43 t44 t45 t46 w0 t47 p47 t48 t49 w0 t75 t76 t77 p77;ac40fcfeecf1f8a9 +m176;0;0 0 0;0;1 2;;t1 t3 y t3 t5 y t6 t6 t8 w2 b9 t8 y t9 t10 t11 t12 t13 t14 y t15 y t16 t20;c10de51310f9a651 +m178;175;0 2;0;1;;b177 p175 s2:1,2:1,3:1 p178 t178 y t179 t180 t185 t186 y t186 t187 t191 t192 w1 t194 t194 t195 b196 p195 t196 t197 p198 b- p199 p200 p242 p242 p242 t243 p243 t244 s2:1,2:3,2:1,3:1,2:1,4:2,2:1,2:1,3:6,1:1,1:2,1:1,2:3,3:1,0:8 t245 p245 s0:2,1:2 t249 t250 t251 w1 b251 p251 b256 t252 t253 p256 x1;c91121e554967cb4 +m179;0;0 2 0 1;0;;3@-;y y y t1 s0:1 y y y y t2 y y y y y y t28 y t29 t30 t31 y y y y y y t32 y t33 y t34 t35 t36 x2 s1:2,2:3,1:1 y t39 p39 p40 p43 p43 t44 t45 p47 p48 p48 t48 p48 s0:3,1:1 p49;77200f436e846498 +m205;0;0 0 0;0;1;2@5;p0 y y p1 p1 p2 t5 y s5:6,2:1,1:1 t8 p8 p8 p8 p9 p9 p13;661513e159d75ecb +m235;0;0 2 0 2;0;3 2;;t1 t3 p4 w2 s2:2,2:5,2:1 y w1 p4 t34 x1 y t35 t36 p36 y t37;5e15719e506daf68 +m280;3;0 0 0 0 0 0 0;0;2;1@- 5@5 4@8 6@- 3@-;t3 y t4 b7 t9 t13 t14 b18 t15 b- w6 t67 t74 t75 t102 t103;2b59783e74ac0df8 +m281;0;0;0;;;y t1 t2 w0 w0 b4 p5 t8 t9 t9 t10 y t10 t11 t11 y b11 p11 t12 t13 w0 t14 t15 y;963faead1d1fb1f0 +m300;0;0 1 0 2 2 0 0 0;0;1 7 4 5 2 3;6@2;x0 b- t1 y s2:2,0:3,2:1 t2 p2 t3 b4 y y t4 s7:8 t5 s0:1,2:1,1:2,0:1,0:2,2:2,0:1,2:1,1:2,2:2,2:1,2:1,1:1,2:1,0:1,7:2 t6;93c0c3a7a439e26f +m305;0;0 3 2;0;1;2@7;t1 t1 t2 y x0 t3 t4 t5 s0:4,3:2,2:1 t6 b5 p6 p6 y b- t7;ca391e45a2dc0b1a +m322;0;0 0 0 0 0 0 0 0;0;1 2 3 7 5;4@4 6@-;t1 t2 w6 t3 b3 b- b1 y x0 t4 x4 x5 t5 t6 b10 b- s0:195,0:1,0:2 p10 t11 t12 b15 t13 w4 y p13 y t14 y x1 y y t69;2279c6f37111cd9b +m336;0;0 0 0 0 0;0;3 1;2@8 4@7;t1 t2 s0:1,0:1,0:1 t3 b7 t8 b- s1:1,0:1,0:1 t9 s2:1,0:1 t10 t11 t12 t13 s6:1 t14 s0:6 s0:1,0:2 s0:2,6:1,0:1 t15 p20 t21 t22 p23;5e16a96484152f76 +m350;0;0 1 1 1 1 0;0;3;5@1 1@- 2@5 4@-;x1 y t3 t4 t5 t6 w2 b4 t7 b6 t7 t8 x4 t26 x5 b26;44e026eea2b70237 +m359;3;0 0 0 1 0 2;0;5 2 1;4@1;b3 t4 p4 p4 t4 t56 t59 b57 x5 s1:5,2:2,2:2 b61 b64 b- t60 b58 p61 t62 p62 p62 t66 t67 s0:1,1:1 t68 b68 p68 p68 t68 b- t69 b68 b67 b- p69 w1 b69;8b1b3ca99ffc62d0 +m367;0;0 2 1 1 0 1 0 1 2 1;0;4 6 2 9 8;5@7 1@2;x6 t0 p0 x1 t1 x5 x8 x2 s0:1,2:110,1:2 t2 x7 x4 p2 x5 s0:255,1:2,0:2,0:1 b2 x9 s1:2,2:7,6:1,3:1,1:1,2:1,0:3,4:3,2:8,2:1,7:2,0:6 p3 x6 t4 w7 t5 b5 w4 p10 t11 t11 t12 t13 p13 p13;357303e5c25168e4 +m370;0;0 1 0 1 0 2 1 1;0;1 6 4 7 2 3;5@-;b6 x6 x1 b- w6 b- p0 t1 p7 b5 p7 b6 t8 b9 t9 t10;2f7fc2c46868e2c3 +m380;0;0;0;;;t1 b3 t2 t3 b- p5 t6 t7 t8 t9 p9 p9 t10 p10 p10 p11;9b70203f56e7688b +m395;3;0 0 0 1 0 0 0 0;0;4 3 6 7 5;1@9;x5 x5 s0:8,5:1,0:1,0:1,0:1,0:2,5:3,1:3 b4 b4 t38 t39 p39 p39 t40 p40 p40 p40 p41 t42 b44;68cf52c2a1980d75 +m405;0;0 0 0 0 0 1 1 0;0;3;5@-;b3 t0 t1 s1:8 x5 x2 y x2 x4 t2 t3 x0 t4 p8 x4 w1;23e7d1e401eebe55 +m411;3;0 0;0;1;;p3 w1 w0 t4 b8 t6 x1 t7 s1:149,1:1,0:1,0:1 s3:2,3:2,3:3 t8 x1 t9 t10 t11 t12 t12 t13 p18 p19 t19 t20 t25 t26;25d3598a1240a347 +m420;2;0 0 0 0 0 0 0 0 0;0;7 8 2 5;3@6 4@3 1@7 6@-;w7 t7 t8 w2 t10 x3 t11 w6 t12 t13 t15 t16 t17 t33 t34 t35;a4b3d5fac666f42f +m430;1;0 0 0;0;;;t2 t6 b8 t7 p8 b13 p8 p8 p9 t10 t11 p11 p12 p12 t12 p13;47047d4f47b505e5 +m435;4;0;0;;;t5 t6 x0 t7 t8 b- t9 t10 t13 p14 t15 p15 p15 p15 p16 p35;d7254cd392eadfb5 +m472;2;0 2 2 1 2 0 1 2 2;0;5 3 1;2@10 8@1 6@2 4@-;w3 t3 t4 s2:2 p4 y y s2:1,1:1 w0 p12 t13 t14 y b- t15 p15 t60 t61 t63 w3 b- t64 y s3:3,4:1,0:6 t65 y b63 t66 p67 s0:1 p67 t68;2da95ad074e504db +m566;5;0;0;;;t7 w0 t8 t38 s0:1,1:1 s0:1,1:1,0:2,1:7 b42 t42 b40 p42 w0 t43 t46 t48 p48 t49 p49 p50 p50 p50 t51 w0 w0 y;9ae06ad3c85ba76d +m573;0;0 1 0 0 2 2 0 2 1;0;2 8 6 7 4;3@-;w3 t1 s1:1,0:1,0:1 t2 s2:2,2:1,2:1 t3 t4 t5 t6 t7 t8 y t9 t10 t13 t14 t15 t16 t20 t25 s1:1,0:1,0:1 t26 b26 t31 t32 y x5 t32 t33 b32 p34 t35 b38 t36 b35 p37 t41 y t42 s0:5 t43 s2:2,2:1,2:1 t44 s0:1,1:1,0:1,2:3,0:3,0:1 t45 t46 y y;16e534cecf202b20 +m585;0;0;0;;;t0 p4 p4 w0 w0 t5 b5 t6 p6 t7 p8 t9 p9 b7 p9 t11;cac71aea1adc007c +m596;5;0 0 0 0 0 0 0 0 0;0;4 5 7;6@5 3@8 1@6 2@12;y p8 s0:2,0:1 w1 x0 y x1 t10 t15 b15 t16 b21 y t17 y y w0 y b19 t18 p19 t23 y x3;48cfea6a6876ad2c +m601;0;0 0 0 0 0 1 0 2 0 0;0;5 1 6 9;3@- 8@- 7@- 4@7;b- t5 w0 b11 b- b11 y b4 p6 p7 t10 w9 b9 b16 b13 t11 w5 w6 b14 w4 b10 b- t15 p15;2e458fbec686f1e1 +m617;5;0 1 1 2 2 0 2 2 2 0;0;9 8 3 1;2@- 7@5 4@-;b8 t6 t11 y t12 s2:1,0:1 t13 b13 t14 t15 t16 b16 x2 t19 w1 t20 t21 t22 p24 t25 t25 w8 t26 t27 t28 t29 t30 t31 y t32 t33 t34;4d2b3d8656ecf677 +m640;3;0 1 0;0;2 1;;t5 y t6 p6 y t11 t12 t13 s5:1 s2:3,5:8,1:2 w0 t14 b- t15 p15 s1:2,2:1;1659fa202922932f +m686;0;0 0 0 0 0 0 0 0 0;0;7 3 1;2@3 8@3 6@2;p1 t1 s1:1,0:1 t5 p5 s1:8,0:1,0:3 t6 s0:1,3:1 t7 t8 s0:7,0:1 t9 p9 p9 t13 y t14 y t15 t16 b- y b- t17;83abb3bb9cef905d +m693;4;0 2 3 0 2;0;3 4;1@9;b6 x3 b6 s2:2,0:1 p29 t29 t30 t31 p58 b60 t59 t60 b62 t61 t62 s2:2,2:2 x1 t62 s2:2,0:1,2:2,0:1 t62 x4 p62 t63 t64 t65 b71 x2 t66 t67 x0 t68 t69 x3 t69 t70 b- p70 p70 t71 t76 t76 p77 b77 t78 x2 y t79 p80;a2f3281f9c6802cb +m695;3;0 0 2;0;1;2@5;b8 b9 p4 p4 s0:3 t5 t6 t7 t7 p23 t24 b- t25 t25 t26 s2:1,2:1;0f4abe8dc2bb44b0 +m715;0;0 2;0;1;;b- p0 p0 p0 p45 p49 p49 p50 t51 p51 p51 p51 p55 t56 p57 p57;9a9b9dfecf6fb8a3 +m735;0;0 0 1 2 0;0;3;1@-;t1 x4 b5 t2 s2:116,2:8,1:2 s0:2 s0:1,2:2 t3 p5 b4 s0:4,2:3,1:1 p5 t6 s2:2 b- p7;cde7b1f28b0c269c +m817;492;0 1 0;0;1;;x0 t493 t543 y s1:2,1:2,3:3,0:3,1:1,0:2,0:1 t544 w1 t545 s0:1,0:1,1:3,1:1,0:1,0:3,0:1,0:2,0:6,1:1,1:1,5:1,1:1,1:1,0:1,0:3 t546 s1:2 t547 b- t548 p548 t549 p550 p550 s0:2 t551 s0:2,0:251,0:1,0:3,0:2,0:1,0:1,0:2,0:1,0:1,0:1,0:1,0:1,0:1,0:1,0:2 t552 s0:2,0:1,6:3 t553 t554 x1 b553 s0:1,0:1,0:1,1:3 p556 b- p560 t561;ea60e0324fe5dea9 +m846;4;0 0 0 0 1 0 1 0 1 1;0;9 4 3;1@4 2@3 8@- 5@-;b2 b- t8 t9 x8 t10 t11 t12 t13 x7 t13 w5 y x2 t14 x3 x0 p15 x0 s0:8,0:2 b19 x9 t16 t17;23aabe40d1cc1684 +m855;390;0 1 0 1 0;0;1 2;4@397 3@389;b396 t391 b392 t392 t394 p395 b400 t395 p397 t398 y p402 b- b400 b- p402;fd17b5c87e5b6464 +m863;0;0 2 0 1 3 2 2 0 3 0;0;1 8 3 9;2@6 6@- 5@8;p0 b5 t1 b2 t2 b6 t3 p4 p5 t6 w2 t7 b6 y t8 y x7 b- b12 t9 t10 p11 b12 t11 t15 b- b14 t16 t17 b16 t21 t22 b-;63701bb072fe2c63 +m903;1;0 0 2;0;2 1;;s0:1,1:1,2:2 t1 w1 t2 w1 t3 w0 w1 t4 p5 t6 s2:2,0:1 t6 w1 w0 w1 t7 b11 t8 t9 w1 b13 t10 t11 p11 p12 p12 p13 b13 t14 w0;353422bc43576158 +m1014;724;0 0;0;1;;t725 t726 x0 t727 w0 x0 s3:90,3:1,3:2,3:1 t728 s1:1 t729 s0:1 t730 t731 w0 t734 t735 s1:1,3:1 t736 s3:1,3:1 t737 t738 p739 p739 p778 p779 t780 s3:2,0:1,2:1 t781 s2:1 t782 t783 p783 p836 s1:3,1:1,2:1 t837 s0:2,3:1 t838 s3:4,3:1 t839 t840 p841 t842;8453559c57801cc5 +m1051;0;0;0;;;y x0 t1 y y y b1 t2 t3 b- p5 t6 p45 p45 s1:2,1:1 t46 t46 t46 p46 t57 t58 t58 p58 t60;58f7193f1f398c73 +m1112;1;0 1 1 1 1 0;0;4;1@- 2@5;t2 p2 t4 y t4 w1 w3 w5 t5 p5 t6 t9 p10 t14 p15 b19 p15 s1:2,1:1 p20 t21 b27 w1 b20 y b27 p25 t26 t26 y p26 b24 t27;b7ec93b42a3bbb5c +m1135;5;0 1;0;;;b- p6 t7 p8 t13 t18 p18 p21 p21 t22 p22 t22 p23 s1:1 t24 t25;ed808cde7211fe3b +m1137;0;0 2 2;0;1 2;;t1 x2 t2 t3 s1:1,2:1,2:1,3:1,0:1,1:7,1:2 w2 t4 t5 s0:1,2:7 t6 s1:1 t7 s1:1,6:1 t8 t9 s2:1,1:1,1:2,2:3 t10 s4:2,0:1,1:3,3:1,1:1,1:3,0:1,2:1,0:2,1:3,0:1,1:255,1:1,6:2 t11 s1:1,1:1 t12 t13 t14 p14 p14 p14 p14 p15 t16 t17 p21 p63;38d2f33058cb16b8 +m1157;3;0 0 0 1 2 2 1 3 1 3;0;7 6 4;2@7 9@9 5@9 8@4 1@3;t4 t5 p5 t6 t7 b6 s0:2,2:2,3:2,0:1,4:1 w1 t8 y p9 y t10 y t11 y s1:1,1:1 t12 s1:2,0:5 y t12 t13 y p17 t19 p19 y p19 t20 p22 t25 t28;20d2460549f7c991 +m1167;0;0 1;0;1;;x1 b- p1 t1 s7:1,0:1,0:2 p4 t5 s1:1,7:5 t6 s1:1 t7 t8 t10 b9 p10 y b8 t34 s0:1,2:3 t38 p38 t43 t44 p44 p44 t45 t46 p46 t47 s2:2,0:1 t48 p48;506b8cdda091274d +m1180;0;0;0;;;b- t2 t3 p4 p8 p9 p9 t10 t11 t12 t12 t13 p13 t14 t18 p21;0451698a36682f48 +m1207;0;0;0;;;t1 t2 w0 b8 t3 t4 p4 t5 t6 p6 p6 t7 t11 x0 w0 w0 t12 s1:2 t13 s2:1,3:1 t14 s0:2 t15 t16 s7:2,1:3 t17 s7:2 t18 t19 t20;92754ac31f545945 +m1210;1;0;0;;;t2 p2 t3 t4 b- t4 t4 t5 t8 t8 p9 t10 p11 p66 p71 p71;1d73df569b15895d +m1212;0;0 0 0 0 0 0 0;0;1 6 3 5;;t1 b- t2 t3 t4 y s3:3,3:1,3:1 t5 s2:1,1:3,0:2 t6 s0:1,1:1 t7 t8 w3 x5 b6 t9 p9 t10 t11 p11 t12 b- t13 p13 p14 w3 w1 t16 w0 p21 p25;ebd2caa780ccc319 +m1218;3;0 1 0 0 1 0 0 0 0;0;3 1;4@8 5@- 8@5 6@2 2@-;t4 y t5 p6 t7 s1:1,1:8 t8 s6:2,1:1 t9 s0:1,0:2 t10 t11 s1:2 t12 s2:2,0:1 t13 s0:2,1:1,2:1 t14 t15 t16 s2:2 t17 s1:2,4:3 y s0:1,1:3,1:2,1:2,0:2,1:1 t48 y p49 x6 t50 t51 t52 y t53 t54 s0:1 t55 s2:2 t56 s0:3,1:237,1:1 t57 t58 t59 t60 t60 t61 x2 t62;722c113fec058f53 +m1231;0;0 1 1 1 0 1 0 0;0;1 2 5;6@4 3@- 4@1;b4 p1 x3 y b- s1:2,0:1 t6 t10 t11 t12 w2 t51 t52 b- t53 t54 b58 t55 y t55 b54 t56 p56 p56;1a970c060715fd62 +m1245;2;0 2;0;;;t3 y b- p3 p6 p7 t8 t9 p18 t19 p19 p19 p19 s6:1,1:2 p19 t24;ac322eb66ac67c9f +m1260;0;0;0;;;s1:1 b- t1 p1 p1 t2 t3 t4 t9 t10 p10 t11 s1:2 t12 s1:3,1:1 t13;a3aa7e336f585833 +m1302;816;0 1 0;0;;1@- 2@818;b821 t817 t820 t821 t822 w0 t823 t828 t829 p829 t829 t885 p885 w1 w2 t886 t887 y t888 y b887 b888 p889 b889 t890 t891 b895 t892 b892 t926 p927 t928;34b61adbfa9cdd86 +m1310;0;0 0 0 0;0;1;2@4;y p0 w3 p0 w3 t0 t0 t1 y x0 t2 b2 b1 t3 t4 t5;ede115cedc54ef0f +m1407;3;0;0;;;p4 x0 t5 b4 s0:1 t6 s0:5 t7 t8 b- s0:1,3:195,0:1,0:2 p9 t10 t11 s1:1 s0:3 t12 s0:51,5:1,0:142,0:1 t13 s0:3,5:254 t14 t15 p16 p58 p62 t63 t64 s0:1,0:2 t65 s0:1 t66 s0:233,0:36;e99c852ba5e871c3 +m1410;4;0 3 3 1 2 1 1 1;0;3 7 4;5@- 2@8 6@-;t9 t10 t11 t21 b22 p24 t29 t30 w0 t31 t34 t34 t35 b35 t35 p35;92282da37a4e7f66 +m1435;0;0 0 1 0 0;0;2 4;1@- 3@-;s2:1 t1 s2:1,0:8 t2 t3 t4 w3 p60 w3 p60 t61 p61 t62 t63 t64 s1:1,3:1,1:6,0:1,0:1,2:39,2:3,5:1,7:1,2:2,3:3,2:1,1:1,2:1,0:2,0:2;2d36631fd09b4d67 +m1456;0;0 1 0;0;1;;x1 x0 p0 x0 s2:1,0:1 t1 x2 x1 t2 p3 t4 t5 t6 t10 p11 y p11 t64 s1:7 s2:229,1:1,2:1,2:1,0:2,2:2,0:2,0:3,0:2,2:1,3:1 t65 s1:3,6:1,1:3 s0:1,1:2,1:3 t66;d89a5c48a2846bc6 +m1482;4;0 0 0 0 0 0 0 0 0 0;0;6 7 9 5;3@- 4@3 8@9;b9 b2 b- w1 y b5 t5 b5 t6 b4 b8 b5 t7 b13 x1 t8 b11 t9 t10 b- t11 t34 w7 b- b33 t39 y w6 t44 s0:7 w3 x9;a639fa0fbf1578cd +m1501;0;0 1;0;;;x0 t1 t2 y t3 p7 t8 x0 y s0:2,1:1,3:2 s1:2,1:5,0:1 t51 t51 t52 p52 p52 s0:5,1:1,1:1 p80 p82 t83 t84 t86 t87 t87;75d26c515ae86b16 +m1530;0;0 0 0 0 0 0;0;4 2 3;;t1 t2 y t3 s3:5,4:2,5:2 t4 y w0 x3 t4 t48 p48 t49 t50 p50 p51;fb87b651074361c2 +m1533;0;0 0 1 1;0;3 2 1;;y t1 s6:1 t2 s0:1,1:1 y x3 y t3 t4 y t5 b10 t6 x3 b- t7 t8 y s1:7,0:2,0:1,1:1 t9 s1:1 t10 s1:1,0:1,0:2,1:2,1:2,0:2 t11 t12 t12 s6:1,0:6,1:1,1:1,1:2,3:2 y t13 x2 w0 y b13 p14 t17 t17 t17 t18 t20 p24 y y t25 t26 p29 t30;bc31df376b4b5c4b +m1580;4;0 0 0;0;1;2@12;t5 b6 b- p5 t6 b6 t7 x1 x1 b5 p7 x1 p12 b14 t16 t17;a81407b043d24d6c +m1617;0;0 3 1 1 2;0;3 4 1;;w0 b4 t1 p1 p1 p2 p3 t4 w2 t5 t6 t7 t7 b- p7 t7 t11 t12 p12 p16 p18 t18 p18 p18 t19 p19 p19 p19 t19 p20 t20 p20;b18e8e50ffcb2034 +m1633;0;0 0 0 0 0 0;0;5;3@- 4@4;t1 x0 t2 b8 b1 p2 t2 y t3 t8 b- t8 y t8 t9 t9 b7 s0:2,4:7 t10 s0:1,7:2,7:1 b- b10 p10 y y x1 w4 b8 t11 y b- y t16 y x0 t17 p17;86672fdb50087493 +m1671;0;0 0 0 2;0;1;2@2 3@-;b5 t34 b39 t35 b40 b41 t36 p36 p36 p36 p41 t42 p47 t48 t49 t50 t51 t52 t53 t53 x0 w0 b52 t56;efafb3c84501080a +m1680;0;0;0;;;t1 t2 x0 w0 t3 x0 b6 p4 t5 p5 s1:175,1:1 t6 s1:1,1:1 t7 s7:1,6:1 t8;e80b8b40554db9d0 +m1686;2;0;0;;;t2 t3 t5 t10 b10 p10 x0 y t10 s1:1,0:3 t11 y t12 t60 t61 y t62 b- s1:1 t63 s1:2,3:6 p63 p63 t64;a79986a38eb7f36a +m1691;0;0 2 2 3 1 2 1 0;0;3;2@2 7@- 6@- 4@6;w1 t1 x4 y t2 y t3 t4 t5 t6 s1:1 x2 t7 t8 y t9 t10 t11 t12 w6 t13 t15 p15 x7;3bb2f7a025c8aed2 +m1695;0;0 0 1 1 1 0 1;0;4 2 6;;x4 y p1 t1 y b- p1 s0:1,0:3,0:1,0:1,0:4,0:1,0:1,0:1,0:1,0:1,0:3,0:1,0:1,0:2,0:1,0:2 s1:2,0:1 p2 t3 t4 w6 t5 p6 t7;1c1bbaec3748b4d2 +m1731;1;0 0 1 2 3 2 3 0;0;7 6;4@- 3@- 5@-;t2 t3 t3 x4 t4 s3:1,0:1,0:2 t5 b3 t6 t7 t8 w6 t67 x3 t68 t69 x5 t70 t71 t76 w7 t77 t77 w3;fbf7655f0aabd4c2 +m1810;0;0 1 1 1 1 1 1;0;5 2 1 4 3;6@-;w2 t1 t2 b- p2 s1:2,1:3,0:4,7:1,0:245,6:1,1:3,0:2,0:3,2:1,0:1,1:3,1:80,0:1,1:17,7:3 t3 p3 t4 t5 t9 t10 t11 p11 t12 t13;70c33e3fd843e8f4 +m1837;1;0 0 0 1 1 1 0 1;0;6 5 4;2@- 7@- 1@- 3@3;y p2 s1:1 s0:5 p2 s3:1,0:1,1:1,1:3 p3 t4 p58 p59 w1 t113 p114 p115 t116 p117 w7 p117 b123 x7 t118 p123 p123 b- w3 p124 t125 p125 p125 p125 t126 x7;1d2d611b928c5c3b +m1842;1;0 0 0 0 0 0 0 0;0;1 3 4;2@4 7@7;b6 t1 s3:1 x3 t2 w1 b3 b- x0 t3 p7 t7 t8 p8 p8 t9 s3:1,3:1,0:2,2:4 t10 s1:2,0:1 t11 t12 t13 p13 t14 y x4 t14 b20 t15 t16 s0:4,1:4,0:1 t16;290d66a8b0b7ca36 +m1862;0;0 0 0 0 0 0 0;0;6 5;1@- 4@- 2@1 3@7;t1 w3 b- p1 y b7 w1 t5 t6 b7 t6 b6 y b6 y s0:2 w5 y t7 b- s6:1,0:1 y x5 x0 y y t8 w4 b- t42 b48 y;63661fcfdb342ed2 +m1886;1;0;0;;;t5 t6 t7 t8 x0 x0 t9 w0 t10 y t11 t12 t15 t16 s0:1,0:1,0:1,7:7,0:2,1:1,3:1,0:2,0:2,0:1,0:1,0:2,0:3 s0:2,0:2,0:2,0:2,0:6,0:5,5:2,0:3,0:3,0:3,0:1,0:3,6:1,0:1,6:1,0:1 s0:1 y s0:2,3:2,0:1,0:2,0:1,0:2,0:1,0:1,0:1,0:1,0:6,0:234,0:1,0:1,0:1,0:3 t17 s6:1,0:1 t18 s5:2,0:3,0:2,0:3,4:3,0:3,0:2,0:2,0:2,0:1,0:2,0:2,2:3 t19;1bd2d4a03378e7e7 +m1891;0;0 1 1 1 1;0;2;1@4 3@2;b- t1 t1 s1:2 s1:3,0:1 t2 s0:1,0:1,0:1 s1:1,1:5 t3 t4 w1 t5 t10 w3 x0 t11 t11 t12 t13 y t14 s0:1,0:255,0:8,1:1 t15 s4:1,1:2;d9747f819f36bd20 +m1892;5;0;0;;;x0 s1:1,0:135,1:1,1:3 s1:1,0:1 x0 t6 w0 b10 s1:1,1:1,0:8 t7 s1:5 t8 s1:3 t9 s0:1,0:1,1:10,1:1,1:1,1:2,0:1,7:3,1:1,1:2,0:3,1:1 t10 t11 s0:1 t12 s0:2 t13 s0:2 s0:1,0:1,0:1,0:3,0:1,0:2 t13 p13 t14 p15 x0 t20 x0 t20 w0 t22;9798cdbbfc64d891 +m1925;0;0 1;0;;1@8;b- t1 p1 t2 t3 p4 t5 t6 p6 t7 t8 s3:1,3:33 p9 t10 p10 p11;ef2e0138f7fb9199 +m1940;915;0 0 0 0 0 0 0 0 0;0;5 4 7 6;1@- 3@915 2@918;b913 x3 s0:1,0:3,0:1,0:6 x0 x8 b914 y t916 y x2 t917 b920 t918 t919 t919 x7;45c61b23480976e6 +m1951;0;0;0;;;t1 t2 t3 t4 t5 t6 w0 s1:1,0:2,0:2,1:1 w0 x0 y x0 b6 p6 x0 t7 t8 p8 t9 t10 t11 w0 x0 x0;68911145952819f5 +m1973;3;0 0 1 1 0 1 1 1 1;0;7 6 5 4 1;3@5;b- b4 b8 s4:2,1:1 t4 t5 p5 t6 t7 t8 p12 s0:1,1:1,5:3 t13 y y t14 t15 y b15 p15 t74 t74 y b78 t75 b81 t75 b73 p120 y t121 t122 t123 p123 s1:1 p123 p123 p123 p124 t128 b132 t129 s1:3,7:1 t130 w4 t131 t131 b-;4d386a5da9117aaf +m1982;0;0;0;;;t1 t44 y t45 y s0:1,0:1,0:1 s2:236,2:3,7:8,7:3 t46 s0:1,0:1 s6:3,2:1 t47 s2:1,1:70,7:1 t48 s2:1,1:7 t49 t50 t50 p50 s2:1,0:1,0:1 s2:1,5:2,2:3,2:2,0:1,0:2,2:1,0:2,1:1,1:2 t51 p51 s2:2,4:3,1:1,2:1 t52 s0:1,2:2,2:3 s1:1,2:1 t53 p53 s0:1,1:1 t54 s2:2,5:2,3:1,2:1 t55;4af01fe6bc8b52ad +m1990;2;0 0 0;0;;2@-;t3 b- t4 t5 t6 p6 t7 p7 t7 p7 p8 t12 p12 t13 t46 p46;1c26d91caeb1f097 +m1995;3;0 1 1 1 0 1 1;0;5 1 6 3;4@- 2@8;s1:1,1:3,1:2,5:1,1:1,1:1,6:2,1:1,1:4,1:3,1:3,0:1,0:1 t4 s0:1,1:1 t5 t6 t7 b13 t8 t9 s0:2,7:1,1:1,1:1 b8 t10 t10 b- p10 t11;beeaab13160f2698 +m2000;4;0 0 0 1 0;0;1 4;;w3 t9 b- s6:1,1:1,2:3 t69 p70 p71 p71 p72 t73 p73 p74 t75 p77 p82 p85;cf431e556e695207 +m2006;5;0 1 1 1 1 0 1 0;0;3 2 4 7;1@11 6@10;t6 b6 y b- t6 p7 b12 t9 t10 t11 t12 b- p14 p15 t16 t17 p17 t18 t19 p22 t23 t23 p27 t28;7b69a729764f8a02 +m2015;4;0 0;0;;1@11;t5 s4:184,2:1,1:1,6:2,0:4,1:2,0:1,2:1 x1 t6 x1 t7 p7 t8 t9 t13 t14 p14 t14 p15 p15 t15;1d8124adcfdb0c3f +m2042;3;0 0 0 0 0 0;0;3 1;5@9 4@- 2@-;t4 t5 p5 p5 p9 t10 t11 y t12 t15 t16 p16 b16 y t17 t18 s1:2,1:3,1:1 t19 s1:1,1:2,5:58 t20 s0:1,1:3 t21 t22 b26 t24 p28 p28 t29 p30 s0:1,1:5,1:3,0:6 b- t31;9177f769d82c92fb +m2102;231;0 1 0 1 0 1 0 1 1 0;0;2 6 4 5;8@- 1@- 3@- 9@-;x1 t232 x8 s1:1,0:1,1:1 t235 t236 x1 t237 w8 x4 x9 t238 t243 b- x7 t243 t244 w8 b- y y w4 y t244 t245 w4 w8 y w3 t249 t250 t250;4e163b38596367da +m2106;1;0 0 0 0 0;0;1;4@3 3@5;t2 b5 y p2 p6 t7 p7 t8 t12 p12 t13 y y y t14 t15 t16 w0 t17 t18 t19 p19 x4 t20;e719a77c2bbd5c2c +m2136;0;0 1 0 0 0;0;3;2@8;x4 t29 b35 x0 b34 b34 t30 p31 t32 t33 t38 t39 t40 b- t40 t41 t42 t43 t44 b- t45 x3 p46 w0;f4f5bcfbad7fae77 +m2146;3;0 3 3 0 0 0;0;5 1 3;4@1;w3 s6:7,0:2 t4 s7:2,2:2,0:1 t5 s2:2,0:2 b6 p5 p5 x3 t6 t7 t8 p8 t67 t70 t71 t72 s1:1,2:1 t73 x0 w5 s2:1,2:3,2:1,2:4 p74;04ec37544183b9ad +m2175;3;0 1 1 0 0 1 0;0;2 4 6 3;;t4 s7:8 t5 t6 p6 p6 t6 t7 t12 t12 t13 t14 s0:8,1:1 t15 s0:3,1:2,1:1 t16;cbbbfcb5fa5296fb +m2191;0;0 0 0;0;;;t1 w2 t2 x0 w1 x1 p6 s1:3,3:1 s3:1,3:1 t7 s3:1,0:3 s2:1,0:2 t8 t9 p10 t12 p12 p12 t16 t17 t18 t19 p20 t21;891720ae8383c603 +m2205;5;0 0 0;0;1;2@-;x2 b- p6 x1 t7 t8 w0 t9 b9 b10 p9 b- p10 y b- t11;0042998dfa94600f +m2278;5;0 0 0 0 1 1 1;0;3 2 1 4;6@13;s1:3,6:3,1:1,0:1,0:1,0:2,0:2,0:1 p5 p9 p10 t11 p12 t13 t14 p15 t17 t36 t36 t39 t40 t42 p44 t45 t48 b- b- t49 t50 t51 b53 t52 p97 y t98 t98 s0:1,0:1 t99 w1 p99 p99 t100 s0:1 t105 b109 s1:2,0:1,1:1 b106 y t106 x6 p106 w3 w1 b109 p106;92486df2f4a6860c +m2306;2;0 0 2 1 1 0 2 1;0;4;5@- 7@5 6@3 3@3;t2 s5:6,2:2 t3 s1:2,0:2 b5 p3 t4 p4 p4 t4 t5 t6 x6 y t7 t41 x5 s2:1 y y t45 t46 y t47;220a7c4fee9f7e36 +m2346;0;0 0 1 0 0 0 1 1;0;1 6 7 4;2@-;p5 t6 b6 y t7 t8 t9 p9 t9 p12 s0:1,1:3 p30 t31 y t34 s1:1,0:1,1:1,0:1 y b35 w0 s1:1,7:136 t35 s6:2,1:5,0:1 t36 t37;826626feb9203c7b +m2373;0;0 0 1 1 1 0 1 1 0 1;0;1 4 8 7 9;5@- 2@1;t0 t1 w5 t2 p56 y w1 b61 x2 b- x4 x3 x1 s1:1,1:1,6:1,1:2 b60 t57 x2 t57 t60 p60 s1:1,1:1,1:3,1:1 p61 t62 b64 b64 s0:1,4:1,1:2,1:3,1:2,7:2,7:1,2:2,1:2,1:1,0:2 t63 s0:1,1:1,1:1 t64 t65 t66 b71 y t67 b66 w2 b66 t68 y b66 t73 x5 b73 b74 w0 b72 p73 t74;c259f41859cb3b5a +m2405;0;0;0;;;w0 s3:8,1:8 t1 s1:1,3:1,0:2 t2 s2:1,4:3 t3 t4 t5 s0:1,0:1 p6 t7 t8 t32 w0 t33;22d210a7b5ddbc66 +m2426;3;0 3 2 2;0;2;;y t4 t9 p26 t27 t28 t29 t29 s1:1,2:1 w0 b- p29 p29 t29 t29 t30 p31 p32 t33 p37 p39 p39 t40 t72;c8118a1a64cf17eb +m2449;0;0 0 0 0 0 0 0 0 0;0;5 1 7 2 8 6 3;;t5 x4 t6 b12 b7 t7 t8 w5 x4 s0:3 t9 w3 y w4 b- w2 x3 w6 p13 w3 w1 t14 y t17 y t18 b22 y t19 t20 t21 w7 w3 y w0 y b- s0:2,0:1 w0 x1 t22 t23 b- t72 b- t73 b- y y t89 t90 w5 w2 w8 w5 t91 s3:1,0:1 w5 b92 t107 t108 b114 t109 p110 b114 t111 p111 p112 y t113 p113 p113 p114 b116 t115 t116 t120 p145 p146 y;bac84d0a0203e3a1 +m2463;0;0 0 0;0;2;1@7;t1 t2 b3 b- t3 t8 t9 t10 t11 t12 t13 t14 w1 t15 b16 b- p15 t15 t16 y w1 b- s2:3 b18 p17 t18 t19 p23 p23 p23 p24 t25 s3:1,1:1,2:1,0:2 p25 t25 t26 t29 s1:1,1:7 p29 t35 p35 s2:1,2:1,2:1,1:1,0:1,1:2,7:2,0:1,0:1,0:2 t35 p35 t36 t36 t37 t38;8b31e5ffaa843009 +m2465;0;0 0 0 0 0 0;0;5 1 2 4 3;;t1 y b- t2 p2 t6 y t7 b- b6 y b5 y b11 b12 p8;dfdce069410bb06c +m2466;1;0 1 0 0 0 0 1 1 1 0;0;6 3 8 1;9@- 5@-;t1 t2 t3 t3 p3 t4 t5 t10 w5 t11 t11 b15 x4 b16 t14 w9 p15 w5 b- t15 t15 t15 t16 b-;f6d542ef969d3dc2 +m2475;850;0 0 0;0;2;1@-;s0:2 s1:1 t850 p850 y s3:1,4:2,0:2,0:1,6:2,0:1,0:2,1:1,1:3,0:1,0:1,1:1,0:1,3:1,1:1,1:6 t851 t852 p852 t857 x1 w1 t858 p859 t863 p863;6ce741501c9dd93a +m2518;0;0 1 0 1 0 1 0;0;4;1@2 6@8 2@2 3@6;p0 x0 t1 y t2 t3 s1:1,0:1,1:1 p3 t23 x4 t23 y x4 t24 b22 x3 t24 t25 t26 b- x2 t27 t28 y t29 p30 w3 p30 x1 t31 t32 x6 s0:2 t33 b- t34 t35 t36 x3 p36 t37 t38 b- p38 p38 t39 x1 p40;2e9ef2a2fd8902b5 +m2532;4;0 1 1 0 0 0 1 0;0;5 1 7 6 2;4@6;t5 y b6 t6 s1:2 b- w2 s1:6,0:1,0:1,1:170 t7 y t8 y w4 b9 t8 s0:1,0:4 s7:229,4:7 t9 s0:2,0:32,2:1 s0:1,1:3,3:2 t10 t11 b10 w0 w0 t12 w5 w2 w4 t17 w7 x6;f21a2ad4ac6f725a +m2555;0;0 0 2 2 2 2;0;3 5;2@- 4@1;t1 t3 y y t4 b5 t5 t6 t8 t9 t11 x2 y x4 t12 s0:1,0:1;ced5b472dec1152a +m2615;4;0 0 0;0;2 1;;t5 s1:1 t7 p7 t7 p8 p8 p8 t9 p9 t55 t57 p57 t57 t58 p62;1ce4f7f1a7b0a0e7 +m2625;0;0 2 2 0 0;0;4 2;3@-;s2:2 y t1 w3 b1 t2 w4 t3 w2 w3 t8 t8 t9 s0:3,1:1,1:2,0:2,1:2,0:1,2:2,0:167,7:1,1:1,2:1,1:2,0:3,1:2,0:3,1:2 t10 t45;c8885caee08bf906 +m2633;0;0 1;0;;;t1 t28 w0 w0 t32 t33 w1 x1 t34 x0 x0 x1 w0 t35 w1 w1 t36 x1 p36 x0 x1 x0 x0 w1 x0 x0 x1 t37 t38 y w1 x1 w0 x0 w0 w1 x1 w1 x1 w1 t39 x1 x1 x1 t42 w1 x0 t43;325d746cc194b57e +m2655;0;0 2 1 0 2 2;0;2 1 3;5@-;b- s2:238,3:1 t1 x5 t2 w5 y t6 t7 t8 t9 t10 w5 w2 x0 s0:1;752e97d8c30cd38a +m2707;803;0 1 1 2 0 3 1 3;0;3;2@809 4@- 6@805 1@- 7@801 5@811;w4 t804 t805 t806 x2 t848 t850 b852 y b853 t851 p852 p852 t852 t856 x6 w3 x7 b854 b860 p856 y w0 t857 w7 t857 t858 w7 x5 x1 s1:1,1:1 t859;1dcf943ac6c06d9c +m2750;0;0 0;0;;1@-;w0 b- p1 p2 t7 t7 p7 p7 t8 t9 p10 p11 p12 t17 t22 t23;b6aabc48ab6e9bca +m2806;370;0 1 0;0;1;;t371 y y t372 s1:1 t373 s2:2,1:2,1:2,0:1 t374 s1:1,1:8,1:1 t375 t376 t377 s0:2,0:4 s7:5 t378 s1:1,1:1,1:2,0:2,0:3,0:1,0:3,1:1,0:112,4:1,5:1,0:2,0:3,0:1,0:1,1:1 s4:1,0:1 t379 t380 s0:2,0:2,1:1,1:2,1:1,0:1,1:7,3:1,1:1,1:2,1:2,6:3,0:1,5:1,1:2 t381 s1:1 t382 s0:7,1:2,1:1,1:1,7:3,0:1,0:2,1:1,6:1,0:3,0:2,1:1,1:1,0:3,6:3,0:1;6a2ee896ce3b3831 +m2807;0;0;0;;;t1 t2 b8 p6 p6 s3:2,2:1,1:3,0:1,2:2,2:1,2:1,1:1 p7 p7 p7 p12 p13 p13 p14 t15 p15 p15 p16 p16 p16 t17 p17 t18 p18 p19 t27 t28 p88 p89 t90 t91 p91 t92;d82db6909f2131e4 +m2819;0;0 3 3 1 3;0;2 4;1@7 3@-;t5 x2 y x3 x1 b8 p6 t9 t10 y t11 t12 y x0 p12 s1:1,1:1 t13 s6:76,2:3,4:6 t14 t15 p16 s1:1,3:2,1:2,4:5,1:255,0:4,1:1,0:2,2:2,2:1,1:2,2:3,2:2 t17 p17 p17 p17 p17 t18 t19 t20 y t23 t27 p31 y p31 t31 x4 t34 w2 p35 y t36 t37 w0 t38 t39 x3 t42 w4 y y t43 t44 t45 t46 y p46 t47 y x4 y b47 p47 x2 x2 b- p49 s1:2,0:1,1:1 s0:2,1:3 t51 p52 y s3:2 y x3 w4 t53 t54 t55;815cbaf6af64d7d9 +m2820;0;0 2;0;1;;t2 x0 t3 b- p3 t4 t9 p10 p10 p13 p14 p15 p15 t16 p17 p18;929e9ff96e2161af +m2841;1;0 2 1 1 2 0 0 1 1;0;7 1 2 8 4;6@-;t2 s0:2,1:1,1:2,2:2 t5 t6 t7 y t8 b13 p8 b12 t9 y t10 b- t11 b16 s0:168 s2:2 p12 t13 t14 t17 t18 b-;a5b8d1bc8b76aa24 +m2871;0;0 2 1 2 2 0 1 0 0;0;7 2;4@- 5@5 1@- 8@6 6@6 3@8;t4 t5 x6 p6 t7 x3 x4 p7 t7 b- x1 t8 t8 p13 x0 t14 t15 t15 t16 b19 t17 t18 t19 p20;3d44b6541846dba3 +m2918;1;0;0;;;p6 p7 p7 s4:255 t8 s1:1,0:1,0:1 t11 t12 p13 t14 x0 t15 p16 t16 s0:1,1:2,2:2,1:5 s1:8,1:1 t17 s2:1,2:1,2:2 s1:3,4:1 t18 t19 p20 s1:1,0:1,0:1 s1:1,0:2 t21 s4:2,1:1 s2:3,1:1,0:1,1:2 t22 t23 p23 t25 p26 s0:3,0:109 t27 s1:1,1:2 y y t28 p28 t29 p30 t31 s2:1,1:1,1:8 t32 s0:5 t33 s1:2,1:1,1:2,1:3,1:250,1:1,1:70,1:3,1:1,1:1,1:1,1:38 t34;daafc51c4cf18cc7 +m2938;0;0 0;0;1;;p0 y p0 p1 t2 t7 w0 p7 y p8 p9 p9 t10 y t11 p11 b- t12 b10 t13 p38 w0 p38 y p38 b36 p39 s4:2,0:1,0:2 y t40 w1 t41 p42 t45 b43 t46 t46 p46 p47 t48 p48 t49 b- s0:255,0:1 t50 s0:2,0:6,0:3,0:1,0:2,0:1,0:3 t51 t52;56a9e41cef59a3c3 +m2949;3;0 1 1 0 2;0;4 2;1@-;y t3 p4 t5 p5 x0 y t6 b7 t9 t10 x1 x1 x4 t11 y x4 t12 x2 x0 x1 p15 t16 t17 y t18 t19 p20 t21 x4 x0 y x0 x1 y p22 x4 y x4 t23 x2 x3 t24 t25 y x3 t26 x4 x0 x0 x1 x2 p26 x0 y;3f1fc69007c6377c +m2960;0;0 0 1;0;1;;t4 s0:2 s3:1 w1 t5 x2 t6 p6 t7 p7 p7 p7 p8 p58 p106 p106;5b78dc54211f55a5 +m2980;0;0 0 0;0;2;;t1 t2 s0:2,0:1 s3:1,1:2,1:1,0:2 b2 t3 b3 w2 t4 p4 p5 p6 t7 p8 t9 b9;e57b11a8da84664b +m2986;1;0 1 0 0 1 1 2 2 0 0;0;9 3 4 6;8@4 1@-;w8 t2 b- b- y y t3 p3 b1 b3 p3 b8 b- p3 p3 t4 t5 t6 p6 s1:1,1:1 p7 t8 y b6;39e0df30434d8256 +m3107;0;0 2 2 2 3 3 3 0 2 0;0;6 7 4 3 1 9;8@6 2@-;y t1 p1 p1 y t2 w4 y p2 y p3 t4 p5 w3 p6 p7 y x1 y y p7 y p7 t8 y p12 p12 p12 p12 p17 p17 y;d3256749432b5b57 +m3115;0;0 0 0;0;2 1;;t1 t2 w1 s1:237,2:1 p3 s5:2,2:2 t4 s1:6,1:5 t5 t6 s2:1,0:1 t7 s1:1 t8 s0:2,0:8 t9;44c619980678974c +m3116;4;0 0;0;;;t5 t9 x1 t12 x1 t13 b16 p14 s6:8 t15 t16 p16 t17 t33 t34 t35 p35 t35 p37 t39 t39 p39 t40 p41;316902ca1a5af297 +m3138;1;0;0;;;t2 b- p4 p5 p5 t50 t51 t55 p58 p99 t99 p99 p99 p100 t100 t100 t101 p102 p103 p103 p103 p103 t103 p104 p104 p104 p105 p105 p108 p109 t110 p110 p111 p114 t115 p116 t117 p117 p118 t119 p119 p120 t123 p128 p129 t134 p135 p135;bc97c43d6ed7e939 +m3150;0;0 1 0 0 0;0;3 2;1@-;t1 t2 p2 b1 b2 p2 p6 b- t11 y p11 y b12 t11 t12 b11;ec0cded79905b59a +m3166;4;0 0 2;0;1;2@10;x2 t8 t12 w2 t12 t13 t14 p14 b- b12 p14 x2 y t15 w0 t15 w1 t16 y x1 t18 x0 w2 t19;e7e33fa5a3ac5267 +m3175;205;0 2 2 1 3;0;3;1@-;y x3 t206 t207 p212 t213 b213 p214 b214 p214 t215 b216 t216 b217 p220 t221;227ccc0efa775ed4 +m3184;5;0 0 1 1 1 1 0;0;1 2;5@9 4@- 6@-;t6 s1:2,0:1,1:1 y t7 t8 x6 x6 t9 p9 t10 w3 b- x4 t13 y p14 p14 t15 b17 t16 t17 t19 p19 t20 y t21 p26 t28 x0 p28 y b- b26 b30 p28 s3:8,0:1 b29 p30 s0:93 t31 t32 x4 x1 b34 t33 b33 x2 b31 t34 t35 t36 s0:1,0:49,1:1,4:2 y y b37 b38 t37 p37 t38 x5 x0 p39 b- p40 t40 y;2ba6dac09f8c6e4c +m3185;0;0;0;;;b- p1 s0:2 p1 p3 p4 t5 s0:3 p6 t7 t8 p11 p14 p14 p15 p15;68307668468de0a5 +m3195;2;0;0;;;w0 s5:3 t7 s1:1,5:1,0:1 t8 p11 w0 b9 t12 s1:1 s0:1,0:6 p12 p12 p12 s0:1,1:1 p12;d163bf9d9458d044 +m3235;3;0;0;;;b9 t4 p4 t5 p6 p6 s0:1 p6 t7 p7 p11 s2:2,0:1 s0:1 b- t12 p12;5e92263798aec5fc +m3237;5;0 2 1;0;;1@9 2@10;p20 t21 x2 t21 s1:1,0:1 s4:1,1:1 t22 s2:2,7:4,2:2,5:2 s0:1,2:1,2:2,6:2,0:1,1:1,0:1,5:2,5:2,1:1,2:1,1:4,1:4 t23 t24 t29 p29 p30 p30 x1 t31 b31 p31 t32 b32 p32 b35 p33 t34 p87 b92 t88 t89 p89 p90 p91;f9659d5ffd0bcc8a +m3295;4;0;0;;;s7:2,0:1 w0 w0 t6 t7 p8 t11 w0 y y p15 t16 t17 t21 p22 t23;cb451af7a2f6a7b4 +m3304;662;0 0 0 0 0;0;;4@668 3@661 1@-;t663 y x1 y t664 w4 t667 t670 x3 t671 x4 y b- s7:1 x1 t675 t676 t677 t682 t683 s5:2,0:1 p687 x3 t688 t689 s1:1,1:207,1:1 p689 p690 y t691 p695 t696 s6:1,0:2,5:2,7:1 p696 p697 p698 p699 t700 t760 y p760 t761 p762 p762 t762 s0:1,1:5;99b1161ea48a1138 +m3312;4;0 1 1 0 0 1 0 1 0 1;0;4 1 8;2@- 5@- 9@8 6@-;t5 t7 y y s0:3 s1:2,1:1 t22 t23 y x6 t24 t25 t53 t54 s1:1 t55 t56 t57 x1 y t58 t59 s0:1,2:1,0:2 t60 b- t60 t61 t62 p63 p63 t64 s1:1;495410de7e812c01 +m3330;0;0 3;0;;;t1 t2 t3 t7 t9 b8 p9 t10 t11 t12 t14 t15 y t16 b- t17;855b2960ca66920f +m3335;1;0 1 1 0 1;0;3 4;1@2 2@-;p1 p2 p3 b- w3 t4 t8 t12 b- p46 b45 p46 b52 p47 s0:1,1:1 s2:2,0:1;70145914d9964dd6 +m3340;2;0 1 1 1;0;1 2;;t3 y t4 t5 y s0:1,1:1 t6 s4:1 t7 s1:1,0:3 t8 t9 t10 t11 b11 p11;0964edd300d62abf +m3380;0;0;0;;;b- t1 p2 t3 t5 p6 s0:2,0:1 t7 p8 p8 t9 p10 p10 p10 p10 p10;3aedd962a9e8766d +m3405;5;0;0;;;t43 b41 p43 s0:2,0:1,3:1 t44 t45 b- t45 p45 p45 t46 p47 p47 p47 t48 p49;d164c7e579363bb1 +m3411;5;0 0 1 0;0;1 2;3@5;t25 p29 w3 x2 t30 b32 p31 y y w2 p31 w2 y b33 b31 p89 t91 t91 w0 t92 s1:35,1:1 b98 y b94;f7313d2d3c119233 +m3436;506;0 0 2 0 2 1 0 1;0;2 6;7@508 3@510 5@- 4@504 1@510;p506 b- s2:2,0:2 t507 b511 p507 p510 b510 p510 t511 w0 w0 p513 b519 t514 w7 t515 p515 b513 b- t516 t517 b519 p518;5bd7aa759afd33fe +m3441;3;0 1;0;;;y b2 p4 y t5 y t6 t10 t11 y t12 t13 p13 t14 t15 y t16 y w1 t17 b23 t17 p19 t19;9f2b119372d04e42 +m3457;0;0;0;;;t52 t52 s1:2,0:3 b53 p53 t54 t55 p55 t55 t57 t58 t59 p59 p59 p116 t117 t118 t122 t123 t124 p126 t127 t128 t129 p130 t131 t132 t133 p133 y t134 t134;f2f2ca51000d2c7c +m3471;0;0 0;0;;1@-;t1 t2 t3 t4 b3 p4 w1 t7 y b- t8 t13 w1 t14 s0:1 y t18 t69 s0:1,0:1,0:1 b- w1 t70 t71 t85;14c7986ea00957dc +m3475;5;0 0 1;0;1;;p6 y t9 b- p11 y b- t12 p15 t16 p41 p41 p41 t42 p97 p98;6186b25ff85884e7 +m3491;0;0;0;;;t5 w0 x0 w0 x0 w0 x0 t6 s0:2 s1:2,1:1 t7 s0:1,1:1,1:2 s1:2,1:3,1:2 t8 t9 t9 p10 p11 s0:2 t12 s0:1,0:186 t13 t13 s1:1;09e9c8483a1347bd +m3501;0;0;0;;;b1 t1 b5 p2 t3 t4 p5 b3 t6 b12 t8 p8 p8 p8 t9 p12 y b15 p12 t14 p17 t18 b17 t19;48da135af2a45fb2 +m3511;4;0 2 0 1 2 0 1;0;4 2 3 6;5@5;t5 y p6 w5 b11 t7 t8 y y t9 s2:1,3:3,2:1 t10 t11 w6 t13 p13 t13 p28 t28 p29 t29 s4:2,4:5 t30 y;57a0879362568a06 +m3531;0;0 2 1 1 2 2 0 2 0 0;0;4 2 1 8;6@- 7@5 5@-;w6 s4:1 t0 t1 s0:1,0:1,1:2 s2:1,0:1 y p1 b- t2 t3 y t38 b38 t39 t40 s1:2 s2:2,0:1,0:5,0:2 t41 t42 w1 t43 w5 t43;09b5ca1189856020 +m3545;3;0 0 0 0 0 0 0;0;3 6;1@- 2@8 5@5 4@-;t4 p4 y t33 t34 t35 t36 p36 w1 w2 w4 w5 x4 s0:4,0:1,0:1,0:1,0:1,0:1,0:2,0:1,0:1,0:1,0:1,0:2,0:1,0:1,0:2,0:2 p37 t37;01539068d6214caf +m3553;0;0;0;;;y w0 x0 p43 t44 x0 t44 b- p44 t45 p46 t47 t48 t49 t49 t54 p55 p55 p56 t56 p59 t61 t62 p66 p66 p67 t68 p68 p68 t69 p85 t112 t112 t113 t114 p118 p118 t119 p119 p121 p121 p121 p121 t126 p126 t127;a24493be599354d0 +m3560;989;0 0 0 0 0 0 0 0;0;2;1@988 7@996 6@991 3@987 5@988;b992 p1023 b1025 t1024 b1024 b1027 t1025 t1026 p1029 y t1030 w0 b- t1031 b1034 b1032;9b2fa301088171c4 +m3561;0;0 3;0;;1@-;p0 b- p0 p1 t1 t2 p2 p2 t3 t8 p8 p9 t10 t10 t11 t12 t13 t14 s1:1 p19 p23 t28 p28 p28;9a445553018b6b39 +m3590;4;0;0;;;t5 t6 t6 x0 b- t7 p12 p13 p13 p13 t14 t19 t24 p24 t24 t25;b8c794d6e975d2ea +m3622;2;0 1 1 0 0;0;2 3 1;;w1 p7 b- t8 t13 t15 t16 t17 x3 b- t17 s0:2,6:1 t18 t20 t21 p22 s1:1,0:2 t23 p24 b24 t25 t26 t29 p30 b- y w1 y t31 s0:1 t32 s1:1,3:2;d46c7e2c975bc02b +m3722;0;0 0 0 0 0 0 0 0 0;0;3 2 5;4@- 7@7 6@6;p54 w4 t54 p58 t59 t60 b- y t61 t62 p62 y p62 p62 b60 t63 p63 p64 w4 p64 p65 y t66 t66 y t66 t67 y b67 b68 p68 p69;4a7a548c7252a74b +m3736;0;0 1 1 0 1 0 1 0;0;2 5 1;4@8;s0:1,0:1,0:1,0:2,0:1,0:1,0:1,0:2,0:2,0:3,0:1,0:1,0:1,0:3,0:1,0:1 b3 s1:1,0:3,1:2,1:7,1:2,1:1,0:2,4:1,0:3,0:1,1:1,1:2,7:3,1:1,1:1,1:2 t1 p2 t3 t4 s6:2,0:27,0:2 s0:1,0:2 t5 t10 t11 t12 w4 s4:2 t13 t14 p14 p14 s0:1,0:3,5:1,1:1,4:1,1:2,7:1,0:2,0:1,0:2,3:1,7:3,7:1,4:1 p15 t20 t21 t22;ce6e91342d8735ef +m3740;0;0 0 0 0 0 0 0;0;1 3 6 4 2;5@-;t5 b4 b8 b7 t6 y t7 t8 b9 b6 w0 b6 b8 t9 t10 t15;ab851490496dc690 +m3756;3;0 0 3 2;0;1 3;2@-;x2 t4 b- b- s2:1,2:1,2:1 t5 s1:2,6:2,5:1,1:8 t6 s3:2,7:1 t7 s3:4,3:2,0:1 s4:1 t8 s1:1,3:1 t9 s1:3,2:1,2:1 t10 t11 p12 s6:1 s2:1,7:1,2:1 t13 p13 s1:3;79ba377b345063bb +m3785;0;0 2 1 0 1 1 2;0;5 6 2 3 1;4@-;y t0 y s3:1,0:2 t1 y t6 t7 t7 y x4 t8 p8 t9 s0:1,2:2 t13;9c1615024ef7bfbe +m3825;1;0 0 1 2;0;;1@4 3@- 2@1;b6 s2:1 p1 s2:1 t2 p2 p3 t4 s0:20 p6 p13 b12 b12 s5:1,0:2 p14 t15;b3a3d464aaaee401 +m3854;0;0 0 0 0 0 0 0 0;0;6 1;5@7 2@5 3@1 4@- 7@-;x2 s0:1 s0:1,5:3,2:1 t1 s5:1,7:1,0:1 s0:1 t2 t3 x6 t6 x1 x6 t7 t8 y p8 t9 y x2 x4 s5:2,0:1 x7 x7 y x4 x6 p10 x2 x3 y t11 p12 p12 p12 t13 t18 t19 t19 x7 x5 t24 p25 x3 p25 p25 x5 x2 t26 t27 t28 y y t30 t69 t70 x5 y t71;8058753c24490bdb +m3884;3;0 0 0 1 2;0;4 3 1;2@10;t5 s0:1,0:2,0:3 t6 t7 t9 t10 t11 t12 t13 y w3 t14 b12 t24 y t25 x4 t26 b- t27 b31 t28 t33 b35 t34 t35 t36 s0:5,2:2,4:1 t39 p39 b41 t40 y w2 y p41 y t42 t43 t44 y t47 p48 s1:1 p49 s2:1,1:1 t50 t51 t52 t53 p53 b- p54 t55 p59 t60 b60 p60 y t61 p62 x4 t63 t64 t65 t66 p67 t72 t73 t74 t75 s3:1,0:3 s1:1,3:1,3:3,2:1,2:1,2:1,3:5,1:4,0:2 t76 t85 t86 t87 s1:1 t88 p88;bcbaff537ae6085b +m3900;0;0 0 0 0;0;2 1;;t1 t2 t3 p4 t7 t8 t9 w1 t10 t11 s1:8 t12 s2:1,3:3,1:7 t13 s2:4,1:3 t14;43cabb6d23023fba +m3927;0;0 1 0;0;2;;t3 t6 t8 y t9 p16 t17 t18 y p22 t23 t24 x1 y t25 t26 t27 t28 t29 y w2 t30 t31 p69 s1:2 w1 s0:2,4:1,0:2 s7:1,3:1 s7:2,1:5 t70 s1:255 s0:1,0:1,0:2;c63310b218f28803 +m3986;349;0 0 0 1 1 1 0 1 0 1;0;1;9@352 6@- 8@352 5@352 4@349 2@-;w2 t349 x9 t350 b349 t352 b- t353 t353 s0:2,1:1 t354 w2 t355 t356 b359 x8 w1 t357 b355 t358 t359 t359 t360 s1:3,1:3;672615fea6befe86 +m4016;0;0;0;;;w0 y t1 w0 t2 x0 t4 t5 w0 b11 p6 t7 t8 t9 t10 p10 p10 p11 t14 w0 b13 p14 w0 x0;66ad280d4681e5e8 +m4021;727;0 0;0;;1@727;t728 p729 t730 t731 w0 y w1 t732 w0 t733 y w0 s2:1 s2:218,0:48,2:96,3:6,1:2,5:1,1:1,3:1,3:3,1:1,1:3,1:1,0:3,2:2,0:2,2:2 w1 t734 t735 p735 t736 s2:1,2:5,1:1,0:1,0:1,1:1,5:2,0:1,1:7 t737 p738 s1:1,0:1,3:1,1:1,7:2,3:1,3:5,2:2,1:3,5:1,3:1,3:1,0:8,1:1,1:2,3:1 s6:1;de71f44b03783a1d +m4031;2;0 0 0 0;0;2 1;3@1;s1:2,4:1,1:1,5:1,0:1,2:1,7:1,0:2,3:1,0:6,1:2,3:1,0:3,3:1,1:1,2:1 s0:2,2:1,1:5,1:1,1:1,3:7,3:2,4:1,0:1,1:1,3:3,0:1,6:2,1:1,2:2,0:1 b- t3 t4 t9 p9 p10 p10 p10 t12 s0:3,0:5 s5:1,5:3 t14 p15 t16 t17 p18 p18 p19 p20 t20 p20 s3:1,2:1,3:1,1:2,1:2,0:2,1:1,4:1,1:1,0:2,2:245,6:2,2:250,3:1;17978464463ed424 +m4062;0;0 0 2 0 2;0;3 4 1;;t0 y t0 w2 t0 y w2 w0 t0 t0 p0 t1 t2 t4 p5 x4 t6 x1 t7 y t7 t8 w4 y t8 y y b14 t9 t9 w4 x1;88c8a703a45033ae +m4070;0;0 0 0 1;0;1 2;3@-;t1 t5 x0 s0:1 t6 b- t6 y w2 s1:2 s3:2,0:169 b- w1 t8 s2:1,0:2 t9;eb89a0b5de36279c +m4076;3;0 3 3;0;2 1;;p3 b- p18 t19 t20 t21 s3:2,0:3,7:2 t23 y w2 s1:2,3:1 t75 y t76 t77 t79 t108 p140 p140 p140 p141 y t145 t146;48fcd0c0c95318f1 +m4106;0;0 2 1 2 0 2;0;5 3 2;;s2:1,1:2,4:1 b3 p1 t2 w5 w3 y w5 t4 w1 w4 b6 p5 t6 x1 w1 y p6 w5 w4 p6 t11 w0 s2:1,0:2;a6fd8518563a434e +m4180;0;0 0 0 0 0;0;4 2;3@- 1@3;b- b- s0:5,1:2 b- t1 t2 p3 t5 t6 t8 p9 t12 w2 t13 b- t14;6390f49767334314 +m4181;0;0 1 2 0;0;1 3 2;;b4 t2 w0 t3 b- s0:1,0:7,2:7,5:1 b3 p3 b- p4 p4 p9 p10 p11 p11 t12 p17 t19 x0 y b19 t20 p21 t22;fe5a04774a07d0ed +m4182;5;0 0 0 0 0 0 0 0;0;6 7 4;1@- 5@7 2@-;b- w1 t6 t7 b12 b12 t12 w2 w3 b12 t12 b12 t15 w4 b- t16 b22 y w5 b19 y t19 t21 s0:3 x7 b- t21 t22 t23 t24 t25 p26;92ffdb54b1f3a262 +m4240;0;0 3 1 0 2;0;3 1;;y w3 s1:1 t1 b6 w3 t1 t2 t7 p8 t9 p14 t18 p18 t19 p20;b4cf04ff5a66536d +m4259;2;0;0;;;t2 t3 t7 t8 t9 y t10 x0 t10 t11 t12 b14 p13 t14 t15 p15 s1:1,1:2 t16 t17 t18 p20 p21 s0:1,1:1 p53 y t54 p55 t56 p56 p59 p60 p60 t61 t85 t85 w0 t86 t88 p93 t94 t95 t96 t97 t98 p103 t104 p104 p104 p105 p105;1110927aa10cee83 +m4263;0;0 0 0 0 0 0 0;0;3 1;2@8;p0 x1 x4 x1 x2 s0:1,0:132 t2 t3 s0:1 x2 x0 t4 p8 p9 y s1:3,0:1,3:1,4:1,1:1,2:2,3:1,1:255,1:1,0:3,1:1,0:2 t10 p10 t11 t12 p12 s2:224 s6:1,6:1,6:2,6:237,6:2,6:1,6:3,6:1,6:2,6:1,6:7 p13 t14 p14 p14 s1:1,1:2 p14 p15 t16 p16 p16 p16 p16 t16 t17 s1:3 t20 t25 t26 t27 p29 s0:2,1:1;a9ef4aadfb277c03 +m4281;0;0 1 3 3 2 1 2 3;0;3 1 6 4;2@- 5@4 7@-;x4 p0 x2 t48 t49 t49 t50 x7 t55 x4 w4 y t56 t57 w0 w1 x5 w2 t58 t59 t64 t67 x7 t68;c31e6d42b17f9f5c +m4292;0;0 0 0 0;0;3;2@1;y y t4 x1 y t5 b3 b6 t6 t10 t14 b- y t18 b20 x2 s1:2,0:1 b20 p18 p18 t19 p75 t76 t77 p77 t77 p81 p83 t83 t84 p84 p84;c3aef3caadfc135a +m4335;0;0 1 1 0 0;0;2 3;4@7;y t0 s1:2,1:3,0:2,0:1 t0 t1 y t2 b2 s1:3,2:3 p2 b- p3 p4 p4 p4 t5;82f95054b0299beb +m4345;0;0 0 0 0;0;1 2;;t2 x3 t3 s0:1,5:2,5:1,0:239,1:1,0:1,1:2,0:1,1:1,4:1,0:1,1:2,0:239,5:1,0:2,0:1 t6 t7 t19 s1:6 t20 b- p20 s1:175 b- x3 x2 t20;31fcf8d961889599 +m4351;0;0 0 0 0 0 2;0;5 4;3@6 2@8;t1 p1 b3 b- p34 t35 y b37 t36 t37 t38 y t39 t42 w2 t43 y y y x5 y y y y;654adbc6f177cb6a +m4353;4;0 0 0 0;0;2;1@12;y t5 y p5 p5 t6 s5:1,0:2 b8 w0 b12 t7 w3 w3 b7 t8 t11 p12 b12 t20 p20 t21 y b25 y t22 y w3 w1 t23 t24 y t26 p26 s0:1 t27 s3:1 t28 t29 t30 p30 s3:2,1:2,1:2 p30 t31 t32 t33 s1:1 p34 t35;8ad37c80cae41f51 +m4370;2;0 0 0 0 1 0 1;0;3 4 2;5@3 6@8;s6:3,4:1 t3 b- x0 t4 p5 t6 p6 t6 t7 t8 t9 t9 p10 p11 p12;fe71893f885cafe9 +m4386;0;0;0;;;t1 y y y p2 t4 t5 y b3 s0:193,1:1,0:1,1:1 p5 y y y p6 y t7 t8 y t9 y p19 y t20;003740738a1783e5 +m4403;0;0 0 0;0;;1@8;w2 t1 t6 t7 p8 p9 p9 t10 y p11 p11 p12 t13 x0 t14 p14 y t15 p16 w0 w1 b- t17 t18 w1 p19 p22 t27 t28 t29 p29 t37 t38 p39 p42 t43 t44 t46 b- p65 y p83 p83 x0 p83 p84 x2 t85;58dd44bbb07c7177 +m4407;0;0 1 0 0 0 1 1;0;4 3 5 1;2@-;t57 w2 y t58 t63 w1 x1 t64 t65 s1:2,7:1,4:3,0:2 t68 x2 x2 t69 p69 t69 t69 t70 p70 s1:7,1:1,7:1 t71 s7:6,1:1,3:1,1:1 t72 t73 p73 t74 t75 p75 t79 t82 p82 t82;6107db5cb28774a4 +m4411;2;0 0 0 0;0;3;1@3;y t3 s7:2,2:1 b- t4 t5 t5 p6 p7 t8 p11 s2:1,1:2 p11 p11 t15 t15 p19 t20 p23 t24 p26 p31 t32 s0:1,2:4;998337e4c2bb5743 +m4473;5;0 0 2 2 1;0;3 1;2@6;y t6 t10 x2 p11 t12 t14 y x2 x4 x4 x1 t15 y x4 x1 x2 t17 p18 x3 p21 y x2 x2 x3 x4 t22 t23 b- x4 y x4 t49 s0:7,2:3 t50 s1:2,7:1,2:1,2:2 t54 t57 y t59 p60 p61 p61 x1 t62 t63 t63 x4;10772c76e52faca5 +m4482;910;0 1 3 0 3 1;0;3 5 1;2@911;t911 t912 t914 s1:2,1:2,3:2 t914 t915 t916 t917 s0:2,4:1 t918 t919 t922 b922 b926 s3:3 p923 b921 p923 w4 s1:2 b- s3:3 p923 p924 t925 p925 b923 p925 b- t926 t954 t967;9ec33e62ff6f423f +m4531;198;0 0 2 2 1 0 1 0 2 1;0;6 1 5;8@197 7@- 4@- 9@199 2@-;w7 b- w0 x2 t200 x4 t201 x5 w6 w3 b- t202 t207 w5 b207 b209 p226 y x9 x8 w1 b- x6 w5;e6334dec9e66721b +m4600;0;0;0;;;s3:194,0:2,3:5 t1 t2 t3 t4 t9 s2:1,3:3,3:1 s1:2,2:1 t10 s3:1,3:169,3:3,1:5,2:3,0:1,1:1,0:3,3:2,3:3 s2:1,2:1,1:2,3:1,0:1,4:7,0:255 t11 t12 s6:1 s1:3 p12;00b1cb9bd0863881 +m4603;0;0;0;;;t1 t2 t5 t6 s3:1,7:1,2:7,0:1,2:1,4:2,1:1,1:1,2:1,2:3,4:2,5:1 t7 t8 t8 t9 t10 p11 t12 p15 p15 t16 p16 p16 p17 b17 t20 t21 t22 p25 t26 t27 t28 p29 p30 t31 p31 t32 t33 t34 p36 p37 t38 t39 t41 p41 p41 t45 p46 t47 p54 p54 t54 p54 t55;ba0856414adec0ba +m4617;0;0 2;0;;;s0:1 s2:1,2:2,2:2,2:3 y w1 s2:6,1:2 t2 t7 t8 p8 p42 t42 t43 p44 t45 t45 t45 t46 p46 p51 t52 t53 p53 t54 t55 t56 p56 t56 s1:1,1:2 t57 t58 t59 t60;74fa3f860baa9957 +m4631;1;0 2 2 0 2 1 3 1 2 1;0;9 2;4@5 7@2 8@-;t2 y y t5 t5 y x3 t5 x8 x2 p6 t7 t8 x7 w1 w4 y x8 s1:1,0:1 y x4 x7 t9 t12;8f32788260eb0d9e +m4635;0;0 1 0 0 0;0;3 2 4;1@4;w1 t2 w2 t3 t6 t7 x0 t7 p7 y w0 s1:82,1:2 y y y t12;17732f202dc98664 +m4669;803;0 0 0 0 0 0 0 0 0 0;0;6 4;3@805 5@- 8@- 9@-;t804 b803 b804 t805 t808 b807 b808 y t811 b809 y t837 b842 t838 b843 y t839 y t839 x2 y b844 y t841 b839 p841 t842 y y w9 t877 b882 y b877 y p879 s0:6,0:4 y w8;8426e4bde4081799 +m4704;1;0 0 1 1 1 0 1 1 1;0;1 2;4@- 7@5 8@- 6@4 5@7;s1:2,1:2,0:1 s0:1,0:2,1:2,6:1 t2 y b4 t3 b1 p3 t4 b7 y y y b7 t5 p5 p5 s1:1,0:3 t8 p8 t9 y y t40 t41 t41 y w3 w1 y x0 b46 y y y y t42 y y t43 y b44 t44 y b- y w0 y y y w2 w1 t45 y y t49 y w5 y y t50 y b- y p50 s0:2 p50 y w8 w1 t51 x4 y t52 y s2:8,2:1 s0:2,1:1 y y t67;94006350b0008346 +m4721;1;0 1;0;1;;t2 t3 s1:1,1:1,1:2 t6 p6 w0 b5 p6 w1 y t7 w1 y x1 t8 t9 t10 x1 t11 w1 t16 p16 s0:3,1:1 s1:2,1:1;4facf900adf7f3c6 +m4760;5;0 0 0 0 0 0;0;3 5;1@11 4@- 2@8;p6 t7 b6 t62 t63 y t65 b- p70 b68 t74 p74 b74 t96 t97 b-;3450db3942c7f9c4 +m4806;3;0 0 0 0 0 0 0 0 0;0;3 7;2@- 5@- 4@6 1@6 8@11;x7 x6 b- t37 p41 x4 p41 x0 t42 b46 x4 x1 p42 p42 w8 x2 p43 x6 w2 b- w0 p44 b44 w1;8582892b133cc357 +m4825;0;0 1 1 1;0;;1@- 2@4;t1 t2 t3 y t5 b4 t5 t6 t6 t16 b- t16 p17 t19 s0:2,0:1 t20;ed59d98ef878b390 +m4847;2;0 0 1 0 2 1 0 1;0;3 4;6@4 7@- 5@7;b6 y p5 x5 x4 b8 b11 p6 b6 p7 b- p7 p7 t8 t8 b6 p9 t10 b12 p10 t47 p47 b52 b52 t48 p49 t50 p54 b52 b- p54 b-;1fc1555732b9907a +m4862;5;0 1 0 0 0 0 0;0;6 5 3 1;4@3 2@-;t6 t7 t8 w6 b10 t9 b9 b13 x5 b9 x6 b15 t22 t23 b28 b23 s0:2,7:1,1:2,0:1 t24 s1:2,0:2,0:1,1:1 b25 x4 x6 p24 t26 b25 t27 b- p27 p27 s1:1 t28 s0:3;5215379517efb2c7 +m4863;4;0 0 0 0 0 0 0 0 0 0;0;5 6 2 7 4 3 1;8@-;b- p4 s0:1,3:1,1:1 s0:6,1:1 t5 s1:1,4:1,1:1 s6:1,0:2,5:1,0:3,0:1,0:1,0:2,6:1,1:2,0:3,0:2,0:5,1:2,1:115 t6 t7 p8 t9 b8 b9 b10 b9 s0:2,1:1 t9 t10 p11 t12 t15 t16 p16 p17 t18 b18 p18 p19 p19 t20 t21 b23 b- b24 y y t22 t24 y x7 b30 b24 t25 p26 t27 b- y b33;098dad8938bac43c +m4865;0;0 0;0;1;;t1 y t2 p41 t42 b42 y p42 t43 b- s0:1,0:1,0:7 x0 x0 b41 p43 t44;185d8dfe05aa9891 +m4872;0;0 2 1 0 0 2 2;0;6 3;1@- 4@2 5@7;b2 y y p0 w4 w2 t1 t2 t3 t4 b10 b10 t6 t7 t8 y y b10 p8 p8 t58 b64 b62 t59 t60 b62 p61 p61 t62 y t63 x1;9b49d92419f9306b +m4915;0;0 1 0 0 1;0;4 2 3;;s6:1 t1 x0 x1 s1:1,1:2 t2 p5 s0:2 t6 s1:2 t7 s1:1,2:2 t8 x1 p55 p55;450914c183429dfc +m4950;0;0 3;0;1;;s1:1,1:1 t1 s1:73 t2 s1:6,1:2 t3 t4 p4 t9 p9 t38 t39 t43 p43 t44 p44;101e83bf754785f1 +m4966;1;0 0 0 0 1 1 0 1;0;5 2 4;3@5 1@- 7@- 6@-;b5 b- t2 p3 t4 p5 s1:1,1:2,1:1,1:1 y w1 t52 w7 b55 b52 x2 y y b56 t53 b52 p56 b60 t56 t57 w4;6ee33361fe5e054b +m4971;2;0 3 0 0 0;0;2 3;1@9;b2 b- t3 s0:1,0:1,0:1 w3 y x1 x4 w1 y x4 x4 t8 y t9 x2 b9 y b7 p9 w2 t10 x4 p11;000a772b0af85867 +m5030;2;0 1;0;;;w0 t3 t4 y b10 p4 p4 p4 p5 t6 t7 t8 s2:1 t9 s0:1,0:2,0:1 t10;8223b40d5f447654 +m5040;1;0 0 0 0 0 0 0 0;0;4 7;5@7 3@1 2@5 1@5;t1 x4 t2 t3 t4 y t5 t5 b- b8 x4 b6 b7 t11 b15 b12;0b13b5fc3fc0e976 +m5044;2;0 0 1 1 2 0 2 1 2 0;0;9 2 5 6 7 3 4 8;;t3 s2:3,2:1 s2:1,4:8 t4 s2:1,1:2,0:3,1:1 s1:1,2:2 t5 t6 t7 t19 t20 t21 t22 t23 b29 t24 t25 t26 b- t27 w1 t28 t29 t30 x0 s2:1,0:1,7:1,2:2 p31 x1 t32 x2 p32 w6 b33 t33 w4 b37 t34 p34 p34 p64 p64 s1:2,1:1,1:5 p64 s1:207,1:5,0:1,0:1,1:169,1:1,1:1,0:1,1:1,2:1,2:2,0:1,1:3,0:3 t65 t66 s0:3,2:1,2:2,2:1 s0:1 t67 s1:2 s0:2,2:2,7:1 t68 t69 t74 t75 t78 p78 s1:2,2:2 p78 p83 b89 t88 t89 w3 w9 t138 t139 t140 t141 b144 w1 x9 t142 t143 s2:1,1:1,0:25 t144 w6 t145 t146 t147;fe778a2c3a9dfd98 +m5053;5;0 2 1 0 1 2 2 0 1;0;6 5 4;8@3 3@11;t6 p8 y t9 s1:1,6:1,2:1,7:2 y t10 p11 p11 t11 b16 x3 t12 p13 y t37 t38 b42 y t39 p40 t42 t43 t43 x4 t44 p44 p44 p44 s0:1,0:3,4:1 p44 t45 p46 y t47 x0 x2 t48 x6 t49 s2:2,1:1 x4 s7:1,3:3,4:2,0:2 b55 s2:1,0:1 b47 p50 p51;0622fa764b7b5c5d +m5060;0;0 0 2 1 2 1;0;;2@5 4@2 1@-;w0 x2 t1 w3 t1 t2 t38 x4 t39 t40 t41 x0 t42 w1 b- t43;993a15c09d110eac +m5075;0;0 2 0 1 1 1 0 0 2;0;4 3 5;8@-;p0 p1 y t2 x8 y y t3 b2 p3 p3 x8 p3 t4 t5 s4:2,0:1,0:1;a3f70346ef4d359e +m5091;0;0 1 2 0 0;0;1 2;4@- 3@1;x3 t5 s0:1,0:1,1:3,2:2 y t6 t7 x1 b5 x1 t8 t8 b7 b9 t9 x3 t11 t13 y y x0 x4 t14 t15 b19;d07b5a99d9177a6b +m5111;1;0 1 0 0;0;3;1@3 2@-;b- t2 b7 t3 p3 p4 t5 t6 p6 p7 t8 b11 p9 t12 y t13 y w0 t14 b13 b- p14 t16 w2;6e0bae43e3096972 +m5130;0;0;0;;;w0 w0 w0 s2:1,0:3 b- p0 p1 p42 t88 p89 t90 t91 p91 t92 p93 t94;16a42df5aed61cf1 +m5131;5;0 1 0;0;;2@-;t6 t7 s0:1,0:1 s0:3 t8 t9 s0:1,5:2,1:2,1:5,0:1,4:255,0:148,0:1,5:1,0:1,0:7,0:2,1:2 s0:2,5:1,1:119,0:1 t10 s0:2,0:30,1:1 t11 t12 b- p25 s0:2,0:1,1:1 s1:1,0:115,1:44,0:2 t26 s1:1,3:93 t27 s1:1 t28 t29 t30 s2:1,2:1,2:1;dc190b1fc6e421ed +m5156;0;0 1 0 2 2 0 1 1 2;0;5 4 3 2;8@-;t1 p1 y x5 s0:1,2:3 t6 t11 y b11 t12 t13 p13 s0:1 s1:1,0:1,0:2 t14 s5:1,0:1,3:4 s2:1 t15 t16 t17 b20 p17 b- t18;d6900d7a16a5a7e4 +m5180;0;0 0 0 0;0;1;2@7 3@2;w2 t4 b9 t8 b12 w3 b- w1 x1 w2 b7 x0 t9 w0 w1 t10;4432decb91ecb2fc +m5194;0;0;0;;;b- t1 t2 p4 p5 t6 t7 t8 p8 p9 p9 t12 t13 t14 t17 t18 p19 t20 t21 t21 t22 p22 p23 t24 p27 t27 p31 t32 t32 p35 t36 p37 p37 t38 t39 p40 p40 t41 t78 t78 t78 p83 t84 t85 p85 p89 t90 p90 t90 s4:2,0:1,1:3 t91 s1:2,1:1 t95 p96 p98 p98 t99 p102 p102 s0:3,0:1 t103 s0:3 t104 s0:3,1:6,0:1,1:1 t105 t106 t107 p107 t111 p111 p111 p111 t112 t113 p113 s0:1,1:1,0:1 p114 p114 p115 p115;ccc273b22fca1c54 +m5211;0;0 1 0 0 1 2 0;0;2 6;4@-;t5 t6 t7 t9 w4 t10 t11 t12 w4 s0:1,0:2,0:1,0:1,0:1,0:1,0:2,0:1,0:4,0:1,0:1,0:1,0:1,0:1,0:1 s0:1,2:1 t13 t14 b12 t15 p16 b18 p16 t16 t17 t18 t19 t20 p20;12e98762b7e8ef14 +m5246;2;0 2 0;0;1;2@1;y s2:1 s1:2 t6 t7 t8 p8 p8 s0:2,2:1,4:3,0:1 p9 t10 t15 p15 t17 b- p17 t18 y b17 p18 t19 b- p20 p22;e4695d1100a9fd89 +m5257;0;0 1 2 1 2 2 0 2 1;0;2 1 5;8@1 7@- 4@- 6@1;p1 p2 t35 p35 t36 b38 p36 s2:2,2:2 t37 p37 t42 t43 s7:1 t44 s1:1,0:1 t45 b48 b46 t45 s0:6,2:3 t46 s7:8,1:1 t47 s0:1,3:1 t48 t49 w0 p49 t50 p51 t52 p53;d86aa9150b9c32d6 +m5295;0;0 0;0;1;;x1 t3 x1 x0 y t4 w0 s2:3,2:2 t5 y t7 p7 s0:2 t8 s2:2,1:2 t9;99ac4e8bc4030b34 +m5375;0;0;0;;;y t15 t16 x0 b- t17 t18 t19 t20 t21 t79 t79 t80 t80 t81 p81;e1269daa42cb8c02 +m5400;2;0 0;0;;1@7;t2 t3 x1 b9 t4 t5 t64 p65 w1 t66 p67 t71 p74 t75 t76 b-;8dc31858d41a84de +m5413;2;0;0;;;t3 b9 p4 t5 t6 t6 p7 s0:1,1:71 t8 s1:1,1:2 s4:14,0:1,1:2 t9 s1:8,0:2,0:1,1:3 t10 t11 p11 t12 s2:26 t13 p14 t15 p15 s1:1 t16 s0:1 t17 s0:3,0:1 t18 t19 t19 b19 p19 b18 p19;a3c50f02b5bd12aa +m5415;0;0;0;;;t4 t5 t6 p16 x0 p39 x0 x0 t39 y t39 t40 x0 b38 p40 y;ff899073758b129a +m5417;0;0 1 0 1 2 0 0 2;0;3 2 5;7@8;t1 t2 s2:1,0:2 w1 t2 t24 b28 t25 t30 t31 b- p31 t32 x7 p33 y w3 b- w0 w5 x0 t34 y t35 t36 x3 t37 t38 t39 x5 s2:3,2:3 t40;a87faf271242d4ef +m5428;406;0 1 0 0;0;;1@414 3@411;t426 w1 p426 p427 p483 p483 t484 t485 y t529 t529 p529 w2 p530 y t533 t533 w2 s0:1,0:1,1:1 t534 s0:1 t535 s0:1,0:1,2:3,1:1,1:1,0:7,0:255,1:2,1:1,1:1,0:2 t536 t537 p537 w0 t538 p539 t540 t541 p598 b599 y t599 t603 t604 t605 y t606 t606 t633 t634 t635 t636 y p637 p637;211ca6f64cd72db6 +m5432;4;0 1 1 0 1 0 1 0 0;0;3 8 7 2 1;4@12;b- s1:1,1:2,0:2,1:2,1:2,1:2,1:1,5:1,0:1 w8 t4 t5 b- b- w0 b- t7 b- t8 p10 w3 w3 w7 b8 s1:1 t11 t12 w7 p16 b22 p16 t17 t18 t19 b- t20 p21 p21 p21;16aba98344062f0d +m5435;2;0 0;0;;1@3;p2 t3 p4 w0 b- p5 t7 t8 y w1 w0 b11 t9 b9 p14 y;5e747ab86d6389dc +m5450;0;0 3 2 1 2 3 0 2 3;0;1 4 2 8;3@1 7@2;t1 t32 t33 t37 y x2 y w7 w8 t38 t39 w1 t40 b39 p40 b-;75039729914cbebb +m5452;0;0;0;;;t3 p3 y y t4 t5 p10 y p10 y s2:1,1:8 s5:1,2:3,5:3 t11 s7:1,3:89,2:1,1:201,2:2,1:1,1:2,1:46,0:1,2:2,2:1,0:7,3:1,0:1 s2:1 t12 t13 p14 p14 t15 p16 s2:1 t17 s1:1 t18 t19 t20 s0:2,1:4,7:4,2:2,3:1,0:1,1:3,3:2,3:1,2:141,0:255,1:1 s3:1,3:1,3:3,0:1 t21 s2:192,2:1,2:3 s1:2,1:1,1:2;ed1e2dfd648d7e05 +m5482;0;0 0;0;1;;t1 b- t3 b- t3 p3 p3 p3 t4 t5 s0:8,2:1,6:2 t6 p6 p12 p12 p12 t13 t13 t14 s1:2,5:3 p15 p37 p37 p39 s2:1 s2:1,0:2,1:2,3:2,0:3,2:2,0:1,1:1,1:1,6:5,6:2,2:1,1:1,1:1 p40 t41 t41 t42 s0:2,4:2,1:1 p42;0d59db012ed6e72b +m5522;4;0 0 0 0 0 0 0 0;0;7 4 3;1@8;p5 w5 b3 b5 t6 t7 x6 t8 b12 w7 t11 b9 t11 w0 t15 w5 b- t16 b15 b15 b- p16 b- t17 t18 s0:1,1:4,0:1,0:1 b21 w1 y b20 b- t19;5fe839b719d6999c +m5537;0;0 1 0 0 3 0 0 3;0;1 3 4 5;2@-;t1 b1 b7 s3:1,1:1 b6 p3 t3 t4 p4 t5 s1:1,1:1 t6 s0:3,2:3,0:1,1:25 t6 y x1 t7 t8 p8 p9 t36 w5 p40 p41 p42 p42 t43 t44 p44 t45 p45 p45;0f577149e30b98b4 +m5539;0;0 1 1;0;2 1;;w2 b6 t1 p6 t7 t8 b12 p8 t13 b12 p13 w2 p13 t14 t15 s0:2,1:2 t16 b14 p20 t21 s2:1,3:3 s3:2,2:3,0:1,2:1 x0 w0 p23 t24 p24 t25 p25 p25 s0:1 p26 p26 p29 b28 s6:20,1:2,4:1,6:4 p29 w0 b33 t29 p31 p32 p32;1bbb2948b9f8d677 +m5560;3;0 0;0;;1@-;w1 t4 w1 t5 b- b5 t10 t11 t12 p12 t13 x0 w0 b11 p13 w1;6ddfc1d02d49d0dc +m5624;0;0;0;;;t4 t5 t6 p7 w0 s0:1,0:1,0:5,0:1,2:5,0:4,0:1,0:1,0:1 t8 y t9 p9 p9 t10 t11 s0:2,1:1 w0 t12 x0 t12 t13 w0 w0 p16 t17 t18 p19 t20 t25 t26 y b24 t27 t29 t30 t31 t33 t33 t34 t40 t44 t45 t46 t47 t48 p48 p48 p48 p48 t50 x0 t55 t56 t57 p57 p58 t59 t60 t61 t62 y t63 p64 t66 t67 p67 p68 x0 b66 p68 t68 p68 t69 t70 t71 t72 t73 t74 p75 t76 t77 t104;92ced1fe516d9357 +m5650;0;0 0 1;0;2;1@3;b2 p1 s1:1,2:1,0:2,0:1 t1 t2 b5 p2 p5 t6 x0 s2:3,2:1,2:3 b4 y b4 p7 b7;c17fe04d32015d56 +m5651;0;0;0;;;t1 y t2 b2 p3 t4 b8 t5 p5 t6 p7 t8 b14 p12 p12 t13 t13 t13 p14 t15 t15 b13 t16 t20;a03ac7e0abaac580 +m5657;0;0;0;;;y y t1 y y b1 s7:1,0:1,0:1 p2 y b2 p4 b4 s0:1 t4 p4 t4 y t5 y b- p9 p14 p18 p19 t20 p21 p21 t21 p23 t25 p29 t31;3d95aca38acf7883 +m5665;1;0 0 2;0;1;2@9;t2 b5 t4 t5 b- t6 w1 p6 w0 w2 w2 t7 w1 b6 s1:1 t10;cc2743d7c39b51b4 +m5670;2;0 0 0 2 2;0;3;4@9;b1 p3 p3 t4 p4 b3 p4 t4 p4 w0 t5 t5 t6 t7 y b7;a7f7020c7aaad8ac +m5680;3;0 1 1 0 0 1 1 1;0;7 1 6;2@7 5@-;x5 t4 y t5 p6 t7 y x2 p7 y t8 y x6 y x4 t11;9c0246e36ad5b4ee +m5702;0;0;0;;;w0 t1 s1:255,1:3 t2 s0:1 t3 t4 s0:3,1:2,1:1,0:2 t5 s1:1 w0 w0 s0:1,0:2,1:2 s1:1,0:1 t6 s0:2,0:1,0:2,0:1,0:173,0:2,0:1,0:2,0:2,0:8,0:1,0:3,0:1,0:5,0:3,0:206 s1:3,0:1,1:194 t7 t8 p8 p8 p13 t14 t15 s0:1 s1:144,4:1,1:5 s0:1 t16 s1:1,3:5,0:1 s0:2,0:155 t17 t18;74da993b5a2dc7e2 +m5717;0;0 0 0 0 1 1 1 1;0;1 7 3;4@- 5@-;x4 s0:8,1:1 w5 t1 t2 x0 x3 p2 t3 y b- x5 t4 t5 s1:2,1:3 s1:2,1:1,1:1,1:2 b- b9 p5 t6 p6 p7 y x0 p11 s1:1,0:242 t12 x0 b18 t17 t52 x5;8a40fa5e97f53ea5 +m5738;3;0;0;;;t25 x0 w0 w0 s0:1 t25 w0 t26 w0 t27 w0 p27 t28 w0 x0 b28 p28 w0 b30 p33 w0 w0 t34 x0 x0 t35 t36 x0 x0 t37 t38 t39 p40 b42 p40 t41 t42 w0 w0 w0 b40 p42 x0 t43 p43 x0 t44 w0;77e803e3120d94ff +m5741;0;0 0 0 0 0 0 0 0 0 0;0;6 1 8 5;2@- 3@3 9@4 4@3;b- s1:1,0:2,1:1,0:129 t1 w8 x3 t2 p2 p7 x4 t8 t9 x2 t10 t11 t12 y x8 t13 w0 t14 s0:1,0:1,1:1 w8 s5:1,0:1 w2;e6aaab71550ac9ef +m5757;551;0;0;;;b- t552 t577 t578 t579 t581 t582 p583 t583 p585 p636 t637 p638 s2:1,2:188 t639 t640 p645 t646 t647 p647 t648 t649 t649 p650 p691 t691 p695 t696 t696 s0:1,3:1,1:1,0:8 t697 s3:2;d84fb55f3e7d7690 +m5812;75;0 1 0 0 3 0 0;0;6 4 2 3 1;5@-;t76 x4 t77 y t82 t87 y t88 s1:3,1:1,1:1,2:3,2:1 y x4 t92 s0:1,3:1 t93 t94 t95 t100 y p100 y t100 x3 t101 t102 y t102 s3:2,3:1 t103 x3 s7:1,1:2 s2:2,3:1,1:3 b105;10a833b85a0ac262 +m5854;0;0 0 1 0 1;0;3 4 1 2;;t1 t1 y t2 t3 b5 w1 w0 s7:1,0:1 b5 x4 t4 t5 p5 p6 b4 y t7 t8 t11 t64 t65 p65 p65 p66 x4 b65 t67 p68 b69 b71 w3;68386ee21d252dfe +m5857;0;0 0;0;;;t4 x1 w0 w1 t5 t8 s0:2,0:1,7:1 t9 t11 t12 p12 y y y t13 p13 t14 y s2:2,3:1 t15 s1:3 t16 t17 t17 s1:2,1:1 p18 p19 p19 t19 p19 p20 t20;d3c59817798fa24c +m5896;5;0 0;0;1;;t9 b13 b15 p10 s0:1,0:1,7:161 p11 t12 t16 t17 p18 s0:3,6:25,0:3 t19 s2:1,0:218,1:1,2:1,0:1,0:1,0:25 t20 t21 p45 t46 b50 b48 p100 t101 w0 w1 p101;fec0bfa80358f22e +m5926;5;0 0 0 0 0 0 0 0 0;0;7 5 1;2@4 3@- 6@12 8@-;x8 s4:2,6:2,0:1 s0:2,0:149 b- b4 b6 t8 b9 y s0:1,0:108 p8 b6 t13 y x5 t13 b- b- y t13 s5:1,0:1 t14 t42 t43;0f9b34c6ce59c721 +m5931;2;0 2 1 2 1 3;0;3 4 2 5 1;;s2:8,2:1 y t45 t45 t47 y y y t49 t50 y s0:2,1:1 t51 y t52 b51 t53 y t54 p54 y t55 t56 s5:223,3:5;48219f891fbda49a +m5953;5;0 0 2 1 0 1 2 2;0;2 6 1;4@4 3@12 7@-;s1:1,2:2 t6 s6:1,1:1 w1 s5:3,5:2,5:1 y t6 s7:1,1:2 t7 x2 w1 t8 t8 t9 t10 p10 p11 p12 t13 y y s0:2,0:1 x7 b19 s0:2 s0:88,0:2 s1:1,1:1 t14 s0:1,1:244 t15 s0:1,0:255 t16 t17 y t18 x3 b16 b- t19 b17 w1 t20 s1:52,1:1,2:237 s0:2,0:1,2:1 t21 s6:1,6:1 t22 t23;3c5c9013820be363 +m5955;898;0;0;;;s0:1,1:111,3:1 s5:1 b903 t899 t899 t902 s4:2,3:1 t903 t903 t904 s0:1 s3:1 t905 t906 s1:1,3:1,3:1 t907;34d51c10e817e526 +m5966;0;0 0 0 0 0 0 0;0;4;6@- 3@8;x1 t1 s2:2,0:1 t2 t3 p3 t5 t6 t7 p8 t13 p14 b12 t15 t19 t20 t21 p22 p22 p22 t23 t28 p28 p28;3d279b795c05493c +m5986;3;0 1 0 0 1 1 1;0;5 2;4@4 3@- 6@6 1@9;b8 t4 p4 x5 b3 t4 t5 t6 t9 b8 b14 t10 b- t11 t12 p13 p14 t15 b- t15 t15 t16 p17 p17;774c1a5573a13dcd +k0;0;0 1 0;0;1;;x1 b3 p0 p1 p1 p5 t58 t60 b- p63 p122 p122 p123 p123 p123 p123;421f87b73ef55ab7 +k1;0;0 2 0 2 2;0;4 1;2@5 3@7;t1 b2 p1 p1 p2 b1 p16 t20 t23 t24 x3 w0 t58 b- t59 s2:1,1:1,2:7,2:1,1:2,0:1 t60 s0:171 w3 y t61 t62 w0 x4;2ac0d71143e8a813 +k2;3;0 1 1 0 0;0;1;2@6 3@- 4@7;y w4 s0:1 w1 w3 t4 w3 y t8 s0:4 t9 w2 t10 w1 t11 s1:4,2:1,0:7 t12 s0:1 t13 t14 y t15 w2 w0 t18 t19 w1 w0 t20 w1 t59 s0:1,1:1;c6f58af942ed41ff +k3;404;0 0 0 0 0 0 0 0 0 0;0;9 8 4 1 7;2@- 5@-;s0:1,2:1 x5 t447 p448 s0:6,3:1,3:1 t449 p449 p454 s1:1,0:6 x6 t455 x0 t456 p456 p457 t458 w5 t461 t466 s0:1,0:3,0:5 t467 s3:6,3:2,3:1,3:1,3:1,3:2,0:2,3:1,3:1 y t468 t472 p476 p477 p477 p478 p478 p479 p479 p480 p480 p482 t483 t484 p484 p489 p489 p489 p494 p495 p496 p496 p500 w0 x3;9c87c6ae9240669a +k5;3;0 0 0 0 0 0 0;0;4 1;2@- 6@- 3@- 5@10;w1 w6 w2 w4 w1 w3 x6 t32 b32 s0:1,0:2 t33 s0:2,0:1,0:2,0:2 b32 t34 t35 t36;2e1113e0feec8b81 +k6;0;0 0 0 3;0;;3@7 2@-;t4 s2:4,0:1 s0:1,5:1,5:1,3:5,3:4,1:2,0:1,0:1,7:136,3:1,3:1 s3:12,1:1,0:1,2:3 y s0:2,1:3,0:2 y y t5 y s0:6 s0:2,3:1,2:2 y t9 t10 p10 p11 p11 p11 p15 p15 p39 w3 t40;c71a05b536fc5a2c +k7;0;0 1 0 0 1 1;0;3 1;4@5;w0 t4 t5 x4 t6 t7 t8 t9 t14 y y s1:2,1:2,0:2,2:1 t15 s0:1,0:1,0:2 t16 s0:1,3:1 t17 t18 b22 t46 y w0 t47 p48 t49 p50 w5 t51 p53 p57 p57 p57;88b025f9906d89d4 +k8;0;0 0 0;0;1;2@-;y t1 y t3 x2 t4 b- t7 w0 s6:3,0:2,1:3,1:3 t8 b8 p9 p9 p10 p11 p11 p11 p11 p11 p12 w1 t14 p14 p15 p15 p15 p16 p17 p17 p18 p19 p22 p22 p22 p22 p23 s0:2 t24 s0:1,1:1 t25 p26 t28 t32 t36 t37 p37 p40;9a6b4e881f46fb24 +k9;0;0 0 0 0;0;1 2;3@-;s0:1,1:1 t1 s0:2 t2 t3 t5 t6 s2:253,0:3,5:1 t7 s0:3 t8 s0:1 t9 t10 t11 y s0:1,0:145,0:2 w3 s0:3,0:5,1:2,0:1,1:1,2:167,7:1 w0 x1 y y x2 w0 b11 t12 x3 t13 t14 x1 x0 b19 w0 w2 s0:3 w2 s0:2,2:1,2:2 t15 b21 t17 s0:4,2:150,2:1,5:1,2:1 t18 p18 p18 p22 w2 t27 p53 p53 p56 p56 p57 p62 p64 p64 p64 p65 p66 p67 p67 p126 p126 p127 p127 p127 p131 p131 p131 p132 p133 p134 p134 p134 p135 p135 p136 p136 p136 p136;14da60e504c67b3e +k10;135;0 0 3;0;1;;t136 t189 w0 t190 w1 y s0:1 t191 s6:1,6:2,6:1,6:3,6:2,6:1,6:1,6:4,6:1,6:1,0:1 w2 t192 w0 t193 p198 p198 p198;63c50dbf683d9ea8 +k11;0;0 0 0;0;2 1;;t5 y b6 t6 t7 b- t8 x2 t9 t13 t14 t15 s0:1,0:2,0:2,1:1 t16 t21 y t22 p22 p22 p22 p22 p23 t26 x1;411db3f5ee356147 +k12;0;0 0 0 0 0 0;0;4 1 2;3@8;t1 b2 t2 b3 t3 t4 b- t9 b8 w2 b14 x5 b10 b14 b9 p11 b12 b12 t15 x3 w0 t16 s3:1,0:1,3:2,3:234,3:1,3:1,3:228,3:1,3:2,3:1 t20 p21 p22 p23 p23 p23 p37 p38 p38;65db2462469f5962 +k14;0;0 0 0;0;2;;t1 x0 w2 t6 y y y y t8 t9 s0:1,0:1 y y y y t10 t11 t14 y y t15 t20 t25 x0 x2 x0 y y t26 y y y t27 b- y t28 w1 y x0 w0 s0:1,1:2 y;13c50580b68922c4 +k16;975;0 0 0 3 0 0;0;4 3 1 5 2;;t976 y t980 y t984 y t989 t1045 b1043 t1046 t1047 y y t1052 t1067 s0:1,0:1,0:2 t1068 s0:1,0:2,0:1 t1069 s0:1,0:3 t1070 t1071 t1072 t1073;f8da0e5299c59dd8 +k18;0;0 0 0 0;0;1 2;;t1 b- y t2 t3 s5:1,6:1,0:6,0:1,0:1,0:1,1:171,0:3,2:1,0:1 t4 t5 p6 p11 w0 t16 p16 p18 p20 p59 p59 p62 p62 p62 p63 p65 p70 p71 p71 p71 p71 p71 p72 p72 p72 p72 p72 p73 p74 p75 p75 p75 p75 p77 p77 p124 p125 p125 p125 p125 p125 p126;49a26898a6a219fa +k21;0;0;0;;;t5 b5 p5 y t9 t11 t12 y t13 s0:1,6:1 w0 t17 y t18 p18 p20 p20 p21 t22 p23 t24 p24 p25 t28;01a7484b226584cf +k22;0;0 1 2;0;1 2;;w1 t1 t2 t3 y y x1 t4 w1 y y b3 p4 b- p4 p4 p5 p6 p6 p6 p6 p7 p7 p8 p8 p9 p9 p9 p10 p11 p11 p13;c6aeea16ef39d3ee +k23;4;0 0;0;1;;b2 b2 p7 w1 b13 s1:1,3:2,2:1,5:2,7:3,3:3,0:2,3:186,1:1,1:2,0:1,6:1 t8 t12 p13 p13 p13 p14 p15 p15 p15 p16 p20 p20 p21 t22 t23 p23 p24 p25 p30 p31 p31 p32 p32 p35;0ee9230822b8b5d0 +k24;0;0 0 0;0;2;1@-;t4 y b3 t5 t6 s0:1,6:1 y y b5 t7 t8 b8 b- p8 y t9 p12 y b17 p13 p14 p14 p14 p14 p14 p15 p16 p17 p17 p18 t20 y s0:3 s0:2 t21 p26 t86 y s0:2,0:2 s0:1 t87 b- p87 p88 p89 p89 p122 p122 p123 p123 p123 p123 p123 p123 p123 p123 p123 p124 p125 p125 p125 p125 p126 p126 p126 p126 p126 p126;996b775d77d547d2 +k25;0;0 0 0;0;1;;t4 t5 b10 y s0:1,0:3 t6 t7 t11 x1 s0:8,0:2 s0:1,2:3 t12 b16 t13 w1 b-;7955b31a6a508e64 +k26;2;0 0 0 0 0 0 0;0;6 4 2 3 1;5@3;y t3 y s0:2,0:5 t4 s0:8 t5 s0:7,0:1 t6 t7 y t8 y y b- t12 t15 t16 w6 y w6 y s3:6,0:3,0:2,0:1,0:1,0:2,0:118,0:2,0:1,0:1,0:2,0:2,0:1,0:1,0:1,0:2 y;5f1cf34dbcb83deb +k27;3;0 2 0;0;1;2@-;t6 t7 y t8 t9 t13 t14 t15 t16 t17 b- p18 p19 p19 p20 p20 p21 p53 p53 p53 p53 p54 p55 p55 p55 p55 p55 p56 p77 p77 p79 p80;a2c3f22d3b530498 +k28;0;0;0;;;y b- p0 p0 p0 p0 p1 p1 p1 p2 p3 p4 p4 p5 p6 p7 p7 p7 p8 p9 p9 p9 p10 p11 p12 p13 p15 p16 p17 p17 p18 p20 p21 p22 p22 p24 p24 p24 p27 p27 p27 p27 p28 p28 p33 p33 p34 p35;9b408b3c5fc5fba6 +k30;0;0 0 0 0 0 0 0 0 0 0;0;5 4 2 7;3@- 6@-;w3 t1 t2 s0:2 t3 y y t4 y t5 t6 y b4 t7 t8 t9;835b6a4905157f0e +k31;0;0;0;;;t1 t2 s0:1,1:1 y y x0 t3 t4 y s1:8,0:1 t6 p6 p7 p8 p8 p8 p11 p11 p12 p13 p13 p13 p18 p18;06b8ec521172b79e +k32;3;0 0 2 2 1 1 0 2 2 2;0;8 6 2 4;3@9 5@4 1@4;w1 t4 t7 s0:3 t8 s2:1,0:2,3:5 t9 s0:201 t10 t11 t13 x3 t14 s0:1 t15 x7 t16 t17 x5 t20 t24 w3 t26 t27 t29 t31 s0:1 t32 s2:3,0:1 t33 s0:8 t34;72f03f2d6b97b241 +k33;0;0 1;0;;1@7;y t1 y y b4 p1 p2 p3 p4 y t9 y t10 x1 t11 y b14 p11 p12 p13 p43 b41 p44 x0 t45 t48 t49 x0 t50 y t55 t56 t58 y t59 t60 b- p60 p61 p61 p62 p62 p63 p63 p63 p63 p63 p63;74f6f1fcb57003d9 +k34;0;0;0;;;x0 t1 b- p2 p3 p3 p24 p24 p24 p25 p25 p25 p25 p26 p27 p27 p27 p27 p28 p28 p30 p43 p44 p44 p45 p46 p46 p47 p47 p52 p53 p69 p69 p72 p72 p72 p73 p75 p76 p80 p80 p80 p81 p82 p82 p82 p82 p83 p83 p85 p135 p136 p136 p137 p138 p139 p139 p140 p141 p163 p163 p163 p163 p168 p168 p168 p170 p171 p171 p171 p172 p173 p203 p205 p207 p208 p208 p209 p209 p209;8c8425b1d7e9d411 +k36;3;0 0 0 0 0 0;0;;1@5 2@- 3@11;w4 b- p3 p3 p4 p4 p7 x4 y s1:1,4:2,1:1,1:154,1:2,0:1 y y y y s0:2,1:1 y y y t8 t9 s0:1,0:1,0:1,1:1,7:6,0:4,0:2,0:99,1:1,0:1,1:2,0:3,0:1,0:2,0:1 y s0:1 t10;a76f63d482b6001c +k37;0;0 0 0 0 1;0;1 3 4;;t1 t2 w2 t3 t7 s2:5,3:1,0:1 s0:1,2:1,2:1,2:3,1:1,1:1,2:1 t8 s0:2,1:2 s0:2 t9 t10 t69 t70 t71 b69 t72 t76 b76 t77 w3 t78 w2 t79 y t80 x3 t81 b82 b- y t82;24e03bf443a340c1 +k38;0;0 2;0;1;;t2 t3 t4 t9 y t39 w1 b41 p40 p40 p40 p40 p41 t42 x1 t43 t47 t48 s1:1,1:3,2:3,0:1 t49 s0:1,0:24,0:5 t50 s6:1,0:8,0:1,0:3 t51 t52 p56 t57 b57 p57 t58 b59 p59 b62 p59 p59 p59 p59 p59 p59 p64 t111 b109 p111 b116 p112 p112 p112 p113;38e5003013ad60c9 +k40;0;0;0;;;w0 s0:2,1:1,3:1,0:1 t1 s0:6,2:3 t2 t3 t4 t5 s2:41,6:3,4:1,0:2,1:1,2:1,1:1 s0:1,1:1 y t6 w0 b- p6 p10;84975868f5d9125f +k41;0;0 2 0 2 1 2 2 1 2 1;0;3 9 4 2 7 6 1;8@-;s2:1,7:2,1:1,0:1 t1 b3 s2:3,0:1,0:1 t2 t42 s0:2,1:2 b47 t43 x0 t47 t50 t63 t108 b107 t110 t111 b112 w4 t114 b- w8 t117 b116;cdba4cf359c388cf +k42;4;0;0;;;b7 p4 p5 p5 p5 p5 p6 p11 y b17 p11 p11 p11 p12 p17 t18 b21 p19 p19 p19 p20 p21 b- p21 p21 p26 p26 p26 p26 p26 p26 p27;b6b22e8a3c3b3b84 +k44;572;0 2;0;;1@-;t573 x1 x1 t574 t575 x1 x1 x0 s0:2,3:3,0:1,1:1 w1 x0 x1 t576 t577 x1 x1 t578 t581 p585 b584 p586 p586 p587 p589 y t590 p592 t593 p594 p594 p594 p596 t597 p598 x0 t599 x0 w1 x1 t603 b602 p604 p604 p605 t606 b605 p606 x0 x1 t607 p607 p608 p608 p608 p609 p609 p614 p616 p616 p616 p617 t621 p622 p622 p622 p623 p623 p624 x1 x1 t625 p626 x0 t627 w1 s1:1,1:1,2:7,3:60,5:1,2:1,2:1,2:1,2:1,2:1,3:192,0:2,1:1,6:1;adcff9d99c4f9aa3 +k45;0;0 0 0 0 0 0 0 0 0;0;6 8 5 1;3@- 4@- 2@-;s0:1,0:2,0:1 t1 s0:2 t2 s0:1,0:1,0:4 t3 t4 t5 s0:1,4:1,1:3 w3 s0:3,0:1 b3 t10 s6:3,0:4,0:1,0:1,0:3,4:1,0:1,0:1,0:3,0:2,5:3,0:3,0:1,0:1 s0:1,0:1 t11;69cf7e98e0c60308 +k46;0;0;0;;;x0 w0 w0 t1 t4 t5 w0 t6 w0 t7 w0 x0 s0:1 s0:1,0:1,0:1 t8 s1:2,0:2 s0:3 t9 t10 y t12 t13 w0 t17;0901ae78c226b18d +k47;0;0 1 1 1;0;1;;t4 t8 t9 t10 t44 w3 t45 t46 t47 s0:1 t48 t66 x2 t67 t68 t81 t114 t118 t120 t121 t122 t123 t124 t125 t126 t130 t131 t132 t133 t136 b- p136;a2e6d560da840160 +k48;4;0;0;;;t5 t6 s2:1,0:1 t7 s2:1,7:1,0:1 t8 t9 p10 p11 b10 p11 t12 p69 p119 t120 p120 p120 p125 w0 w0 t126 p127 p127 p128 x0 t129 p130 p131 t132 p136 p137 x0 w0 b137 p140 t141 p141 p141 p142 p143 t144 p144 p145 p146 b- p147 p147 p147;31a30fb5aa191668 +k49;4;0;0;;;t8 y s0:1,1:2,0:2 s1:1,0:15,0:1 y y x0 x0 t9 t10 p10 p15 t16 t21 x0 t22 x0 b- p27 p28 p29 p29 p30 p31 p31 p31 p32 p32 p32 p34 p34 p35 p36 p36 p37 p37 p37 p40 p41 p41 p73 p75 p75 p76 p76 p76 p76 p104 p104 p108 p111 p111 p112 p113 p114 p115 p115 p116 p117 p117 p117 p117 p117 p118 p123 p123 p123 p123 p123 p127 p127 p128 p128 p132 p132 p149 p151 p152 p152 p152;ec18161f9712f777 +k52;950;0 0 1 1 1 0 2 2 0 0;0;5 9 6 8 3;4@948 1@- 2@955;t951 y y t952 t954 y y w1 w8 t955 w6 w8 t956 y t957 t958 s2:1,2:1,0:2 t959 s3:2,0:1 w9 t960 t1018 p1018 p1018 p1018 p1018 p1018 p1019 p1019 p1020 s0:1 t1021;347a5283e2356e16 +k53;289;0 0 0 0 1 0 1 1 0 0;0;5 2 8 9;1@- 7@294 3@291 6@295 4@-;b291 x2 y x4 t290 t294 b- x6 t297 t300 t301 t302 b303 s0:6 w3 t304 b306 t305 t306 b305 s0:3 t307 s0:3,0:1 t308 t309 t310 b310 t311 w5 t312 t314 t315 t316 t317 b323 x7 t318 t321 t322 t327 t328 t333 y x2 b333 t334 s5:1,5:5,5:2,5:2,5:1,5:3,5:2,5:2,5:3,5:1,5:1,5:2,0:1,5:1,5:1,5:1 s2:3,2:2,2:3,2:1,2:2,2:1,2:1,2:1,2:1,0:3,2:1,2:6;b3d6c7efdde3f353 +k54;0;0 1 0 1 0 0;0;4 1 3;5@-;w3 y t2 t3 x2 b- x4 b- p8 p9 p14 p14 p15 p15 p16 p21 p21 p21 p21 p21 p21 p22 p22 p22 p23 p23 p43 p44 p44 p44 p44 p45 p45 p46 p46 p46 p50 p50 p50 p53 p56 p57 p57 p57 p72 p73 p73 p73 p78 p79 p83 p83 p83 p84 p85 p88 p89 p94 p95 p95 p95 p95 p95 p96 p96 p97 p97;d8a2b45d18167629 +k56;0;0 0 0 0;0;3 2;;t1 t2 t3 t50 y t52 t53 w3 t57 t59 t60 y t61 t62 t63 x2 t64 t65 t66 y t67 y b- t68;57bac88fef2f2552 +k57;224;0 0 0 0 0 0 0;0;5 2 4;6@- 3@226;t276 t277 t278 t279 b283 t280 y t281 x5 y b282 x0 t286 y t287 w6 w5 w2 x2 w3 t288 t289 y y t294 y t295 t296 t297 y y x4;1417900cc1e1cbc2 +k60;3;0 1;0;;1@9;t7 w0 t8 t9 w1 t11 w1 x0 w0 t15 w0 w0 t16 t17 w0 w0;1ee0a5b991120d52 +k61;919;0 0 1 1 0 2 2 0;0;6 4 3 5 7;2@922 1@-;t920 w4 t923 b925 t924 y t971 b- t974 b977 y b979 p974 p975 p975 p975 p976 p976 p1017 s1:1,1:3,0:223,2:2 y y y b1021;34ee0a59a2c20c5a +k63;689;0 1;0;;;t690 t695 t696 t701 t702 t706 t708 t709 t710 w1 t711 b710 p712 t713 t714 x0 t715 t720 t721 t722 t723 t724 s1:1,0:3 t742 p742 p742 p742 p744 t745 s4:1,0:1,7:6 t764 b765 p764 p764 p764 p764 p764 p765 p765 p765 p765 p766 p766 p766 p766 p767 p767 p767;253294a5629721a7 +k64;2;0 1 0 0 1 1 1 0 1;0;6 2 7 3;4@- 5@6;t7 t9 x5 b- b13 t14 b- x4 t16 t17 w3 t18 t19 t23 t24 t25 b26 t29 t33 b- t34 s0:3,1:2,1:1,5:1,0:1,0:3,1:1,0:1,1:1,0:2,1:3,0:4,0:3,1:2,1:1,0:101 x8 t35 t39 s0:3,0:1,1:5,0:1 t43 t44 t45 t46 w5 t47 t50 t51 b49 t52 t54 s0:7,5:1,0:1 s0:1,0:1,3:1,1:1 s0:1 s1:2,1:3,1:1,1:1,4:1,1:1,1:1,0:2,0:1,0:2,0:1,6:2 t55 s0:1,1:8,1:1,1:1,0:2 s0:1,1:1 t56 t57 t58 x2 b57 t59 t60 s1:1 t61 t66 w7 t67 w7 b71 t70 x6 b72 t71 t72 t73 b71 t74 t75 t76 b78 t77 w5 t78 w2 b- b- t79 t80 t81 t85 w6;1bd8bcb38c7cb0a0 +k65;0;0 0 0 0 0 0 0;0;4 2;3@2 6@6 1@-;s2:3,2:2,0:2 t1 s4:1,0:3 t2 s0:1,1:1,0:159,0:2 t3 t4 y t5 p5 p5 p5 p5 p5 p49 t50;f7b4a6a485dce67b +k66;808;0 0 0 2 0 2 1 0 2 2;0;9 7 4 1;6@-;t855 b854 b853 t859 y t860 s2:1,2:1,2:90,2:8,2:1,0:2 t861 s2:1,0:1 t862 s2:1,0:2 t863 t864 t865 t866 t867 b867 p868 b- w0 t869 t870 t871 b874;1cbbb00f896779fa +k67;0;0 0 0 0 1;0;4 1;2@8;t1 t6 y t8 b10 w0 w4 t9 t10 t11 y t12 t13 t18 w2 b22 t22 w4 y t27 t28 t29 t30 b36 t34 b33 y t35 w0 w3 y x0;5f698da4450e9d48 +k69;2;0 0 0 0 1 0 0 0;0;4 2 7 1 5;6@9;t3 x0 t4 t5 t6 t7 y x7 t8 t10 y y t11 t12 t13 y t14 s0:124,1:3,0:2,1:1,1:1,0:1,1:1,0:3,0:1,1:1,1:2,1:1 t15 s1:1,0:3 t16 t19 t20 s0:2,1:1,0:4,5:1 t21 s1:4 t23 x2 t24 t56 y y x4 x7 t57 t58 t59 t60 t61 t62 t63 t64 t65 x7 t66 t67 s1:3,0:242 t68 t70;8d0c380afa5506bf +k70;0;0 0 0 0 0 0 0 0;0;5 3 6 2;7@-;b6 t1 b5 b3 b7 t2 t4 t5 b8 b4 s5:3,0:1 b5 p5 t6 w2 b10;e81900a4a31ca97b +k72;0;0 3;0;;1@1;b3 p0 p1 p27 s0:2,2:2,2:1,1:1,3:1,0:1,3:1,3:1,2:1,1:1,3:1,1:1,0:92,2:1,0:1 b32 p27 p27 p27 p28 p30 p30 p31 p31 p31 p32 p33 p33 p33 p33 p33 p33 p38 x0 t42 p42 p42 p42 p43 t44 w1 s0:9,3:147;db262afde7d90299 +k74;0;0 2 2;0;2 1;;w0 t4 b4 p5 t45 t46 t47 t48 t53 t77 t78 b81 p78 p78 p80 p83 t84 t85 t86 t87 x0 t90 t91 w0 t92 x1 t94 t95 t97 x0 t98 x1 t100 t101 s3:2,0:1;fdca47bd551845e0 +k75;0;0 3;0;;;t1 t2 b- p4 p5 p5 p5 p8 p8 p9 p9 p9 p9 p10 p10 p14;766d8138796d3cec +k76;0;0 0 0 0 0 0;0;3 1 2;5@- 4@-;y y t2 t3 t4 s0:4 t5 w5 t6 b8 t7 t8 y t9 t13 b16 t14 t15 w3 t20 t51 s1:1,0:2 t56 p57;b6b98ea6751cdcaa +k77;3;0 1 2 2 1;0;4;1@3 2@3;t5 x2 t6 w4 t7 t12 t13 t17 t18 t19 x4 t20 b23 p38 t76 t77 t78 t79 x1 t80 b- p81 p81 p81 p81 p81 p81 p86 p86 p87 p87 p87;018002ce9306aa50 +k78;4;0 0 1 0 1 1 0 1 1;0;5 3 6;4@- 8@8 7@8 2@9;t5 t6 w4 t11 w7 t12 y t14 x8 b- t15 b18 b21 p15 p15 p16 p19 b23 p19 p19 p19 p20 p20 p21 w1 x5 t52 y x6 y t56 b58 t57 s0:1 t58 s0:2,0:2 t59 s7:3,0:1 t60 t61 p64 b63 w0 x6 w0 b- b65 p65;4eba0fc6589bc8a9 +k80;0;0 0 0 0 0 0 0;0;2 1 6 5;3@-;b- t2 s0:3,0:1 t3 t4 x1 t6 b8 t11 t12 t13 y t14 t18 t19 w0;056613ac7e715e48 +k81;0;0 2;0;1;;b6 p5 p8 t54 w1 s2:2,0:2 s7:1,0:1 w1 x1 w0 w1 t55 w0 y y t60 p61 s1:2,0:1,0:1 w1 w1 w0 x0 y w0;b626a4d9dd658e56 +k82;0;0 0 0 0 0 0 0 0 0 0;0;1 8 6 2 3;7@3 4@5;y s1:2,0:1,1:1 s1:82,0:1,1:3,1:1 t5 p9 p10 p11 p11 p11 p15 p15 p18 p18 p19 p19 p22 p22 p22 p23 p23 p23 p24 p77 p77 p80 p81 p82 p83 p84 w1 t85 p86;0f9d9dbb8600179f +k83;4;0 0 0 0 0 0 0 0 0;0;2 7 8 1;4@2 5@4 3@-;w5 t5 t6 w3 w4 b- w2 y t34 w7 y t35 y w3 y y y y b39 w0 b40 t36 x7 t37 w8 b38 y t38 x2 y b- t39 w0 y x6 w7 b42 t52 t53 s0:8,1:3 t54 b59 y t58 w4 y t59 y;abae2079230095ac +k85;2;0;0;;;t6 x0 x0 x0 b- p6 p7 p8 p9 p9 p12 p12 p12 p12 p14 p15;2bbe0756a05d9ee9 +k87;0;0;0;;;s0:2 t1 t2 t3 t4 t6 t7 y t36 t37 b35 p41 t42 w0 t43 t44 t45 y t59 y w0 s0:2,0:3 t60 w0 s1:2,0:1,1:2,0:1,0:1,6:1,0:7,0:2,7:69,1:2,1:2,0:1,0:1 t61 t62 p62 p63 p63 p64 t68;f70d5b0493b034d7 +k88;0;0 2 1 2 2 2 1 1 1;0;5 4 3 2;6@- 7@-;t1 t20 y t21 b24 p21 p22 p22 p22 p22 p22 p23 p23 p24 w5 b23 p25 x6 b- p25 p26 p26 p27 p28 p30 p33 p33 p33 p33 p33 p34 p35 p36 p43 p44 p48 p48 p50 p50 p51 p52 p53 p53 p53 p53 p54 p56 p56;6e661c8bc2e6a1cd +k89;5;0 0 0 0 0;0;3 2 4 1;;t6 t7 t8 t12 t13 x4 y t14 t49 t50 t51 t52 x1 y y t57 y t59 t60 t63 y y t64 y t65 t66 b- b64 x4 b- y t71 y s0:3 y t72 t73 t82 t84 t85 t86 t87 s0:6 y t88 t89 b93 t90 x3 x3 y t91 x4 x0 t92 t137 y y y y y t138 t139 t140 y y y t141 b- x3 s0:1,0:6,0:1,0:1 t143 b145 t144 t148 t149 y t150 t151 y;069d45d3b2d617b1 +k90;178;0 0;0;1;;t181 x0 s0:3 y t182 y t183 b- y s0:2,7:2 w1 x1 t184 t185 s0:2,0:1,0:8 x0;ddceab587ea6d458 +k91;2;0 0 0 3 1 1 3 0 2;0;2 4 1;5@- 8@5 3@- 6@-;t3 b6 b- t4 t5 x5 t7 t10 y t11 b- t12 t13 y b- p14 p14 p14 p14 p14 p15 p15 p15 p16;67e4b1e7be5cfba6 +k92;0;0 3 2 1 3 3 1 1 3;0;8 1 4 6;2@-;t4 s4:2,0:3,1:1,1:1,3:1,2:2,2:2,2:2,2:1,3:1,5:1,2:2 t5 s0:1,2:2,2:2,0:1,3:1,1:2,0:1,7:4,1:1,3:103,0:1,0:2,3:1,3:1,1:2,7:2 t6 s0:2,4:1 t7 t8 t16 p17 w5 s0:2,2:1 b19 p17 p17 p18 p19 t20 t21 p21 p22 s0:3 y t23 t28 t29 s0:2,5:1 s0:3 t32 t33 b31;725d12aff07f05c7 +k93;1;0 1 1;0;;;t2 t3 w2 y b1 p3 w1 w1 w1 x2 t4 b- p5 p6 p6 p6 p6 p7 p8 p8 p8 p8 p9 p14 p15 p15 p16 p16 p17 p18 p18 p19 p24 p24 p29 p30 p31 p31 p32 p32 p33 p34 p35 p36 p37 p38 p39 p40;fb2eeb29d1e27945 +k94;0;0 2 3 0 2 0 2 1;0;2;4@7 1@4 5@2 7@- 6@7;y b4 p1 p1 p2 s0:3,6:1,0:1,2:1,3:2,0:1,1:1,0:1,3:1,0:1,0:2,1:3 t5 s0:1,5:1 s0:1 t6 s0:1,0:3,0:1 s0:1,2:213 t7 p8 b13 s0:2,1:3 b7 p8 x7 b- p9 s1:1,2:223 y t10 t14 s2:1,3:2,3:2,4:1,0:1,3:3,0:1,3:3 t15 w1 b21 w0 w7 w6 w2 b15 w1 w0 t16 b18 t17 t21 p25 x0 s5:1,3:2 w0 b- p57 p57 p57 p57 p57 p61 p65 p72 p73 p75 p76 p77 p81 p81 p82 p82 p83 p83 p84 p85 p87 p87 p87 p87 p87 p115 p119 p119 p119 p122 p127 p127 p127;8224f1d36fc4c264 +k95;3;0 1 2 2 2 2 3 2 3;0;8 2 5 6 3;1@-;x5 s0:1,2:3,2:1 t4 s1:2,3:2,0:1 x1 y x8 b4 p4 b- p4 p4 p5 p6 t7 t8;7121ad61cac1a041 +k96;4;0 2 0 1 1 2 1 2 1 1;0;6 7 5;3@- 1@10 8@5;b- p4 p5 p5 p6 p6 p6 p7 p8 p8 p8 p9 p9 p10 p10 p10 p10 p10 p11 p15 p16 p16 p16 p16;7ccffbc69e68715e +k97;0;0 2 0 1 0 0 2 2 1;0;6 4 8 7;2@2 1@3;x1 t52 t54 t59 t60 y w8 x8 t61 t62 w1 t63 t64 t65 t105 t106 w7 w1 t107 w7 w5 s2:98,2:3,0:2 w6 t111 t113 t114 b- t117 x8 w1 t118 t119;09388bce43b182b0 +k98;3;0 1 0 0;0;;3@11;s0:1 y y t7 t8 t9 t10 t33 t34 t35 y y y y t36 t37 y w2 t40 y t41 b39 t44 t45 s0:1 t46 s0:1,0:1 t47 t48 t49;dca4171d03f46be6 +k99;0;0 2 2 1;0;3 2;1@-;w2 t1 w2 t3 t4 t9 t41 s0:1,1:4 s2:6,0:52 t43 x1 y x3 t46 t47 x1 t49 b- p50 p51 p51 p51 p51 p52 p52 p52 p52 p52 p56 p59;e7d63b659590c9ac +k100;0;0 1 1 1 0 0 1 0 1 1;0;2 1 9;4@- 7@6 3@-;w4 x2 t1 x3 t2 t3 w7 t4 x4 w2 b5 t6 w7 t7 t10 s0:1;397ef1f52a79cbaa +k101;1;0 0 1 0 0 0;0;5 4;3@- 2@9;b4 b- b- p2 p3 p3 p3 p4 s0:6,0:1,1:1 t5 s0:6,0:1 t6 s0:1,0:2 t7 t8 t9 b12 p13 y t14 t15 t16 b19 p16;744b60d1c548cda0 +k103;2;0 2 0 0 2 2 3 2 2 0;0;6 4 3 2 7;;t3 x6 t4 t5 t6 t11 w5 t12 y t13 t14 s0:1,3:1,3:2 y t15 w2 t16 t17 t20 t21 y y y b19 p22 t27 b- p27 p27 p28 w3 t32 t36 y w9 t37 p37 p38 p38 p38 p38 p39 p39 p40 x4 x6 t44 t45 b-;3624b4d45efca3ed +k105;0;0 0 0 0 0 0;0;;3@- 5@-;t1 s0:1,4:8 s0:8 t2 t6 x4 t7 t8 t9 t14 t15 t17 t18 t19 b- p20;ad41a6a8744004ba +k106;0;0 1 1;0;2;;t14 t15 b- p18 p18 p18 p19 p20 p20 p21 p22 p22 p22 p24 p24 p24 p24 p24 p26 p27 p28 p28 p28 p28;ca5100767dadcdd9 +k107;5;0 2 0 1 1 1 1 3 2;0;3 2 5 4 8;6@7 1@- 7@-;b- s1:167,1:1,1:1,0:1 s0:2,1:2,1:2 t6 s3:2,0:2 s2:2,0:2 t7 t8 w0 y s1:4,2:1 t9 s1:1,3:1,2:2,1:2,2:1,1:2,3:2,1:1,1:1,2:2,2:1,2:5,2:1,2:132,3:1 t10 s0:1 t11 t12 s0:1 s0:1 t13 s0:3,2:1,3:2 t18 t19 p19 p19 p20 p21 w0 s0:3,4:1,3:1,3:1,3:7,7:3,1:6,6:3,3:1,3:1,1:1,7:2 y s0:1,5:188,3:1,1:1,1:2,0:3,3:3 t25;a9f57943ef620dcc +k109;0;0 0 0 0 0;0;3 1;2@-;y b5 t1 w3 s7:1,0:3 s0:2,0:1 x1 b5 t2 x4 t3 t6 b- b12 t7 t8 b13 p8 p9 p10 p10 p11 p12 t13 t16 b14 t17 y b- b19 p17 p22 t67 b73 p67 p68 p68 p68 p68 p69 p70 p71 p71 p72 p73 y t74 t77 t78 t79 b-;ad2b73aaf633672d +k110;0;0 2 1;0;1 2;;t1 t2 x1 t3 t4 w0 x1 x1 t5 y t6 y x2 s1:1,0:2,5:8,0:2,2:1,0:1 x1 b4;80e131fdbce24c1a +k111;0;0 1 0;0;;1@- 2@-;t48 s0:1,0:1 t49 t75 t76 t78 b79 p79 s7:1,1:1,0:1 s6:2,1:3,1:3,0:3 t80 s1:2,1:1,0:1 s0:1,0:2,0:1,0:2 t81 t82 t83 x1 b86 p83 p84 p85 p85 p85 p85;402b46a566cebe08 +k112;0;0;0;;;t1 t2 b3 p2 p5 b7 p6 p6 p7 t8 w0 t13 t14 b15 p15 t18 w0 t19 s0:3,4:1 b- p21 p22 p22 p23 p24 p24 p27 p27 p29 p29 p30 p33;abe701b9fbe67d42 +k113;0;0 1;0;;;y t1 w0 s0:1,6:2 t2 s0:2,1:1,4:3,2:2,0:2,3:1,0:1,1:1,0:1,3:1,1:2 t3 s0:1 t4 t5 s0:2 y t6 t22 w0 t23 t24 t25 s0:2,1:1,4:2,0:1 t26 s1:1,1:1,0:1,5:130 t27 t28 p28 p33 p33 p34 p35 p66 p67 p70 p71 p72 p73 p76 p76 p79 p81 p86 p86 p86 p86 p87 p88 p117 p117 p122 p127;5901bbeedf51d392 +k114;5;0 0;0;;;t6 x0 t7 x1 w0 x1 x0 b6 p9 x1 b14 p9 p9 p23 x0 t24 t26 x1 t27 s0:1,0:1 t28 t29 x1 t30 t31 w0 t35 x1 t37 t42 t43 t44 t49 t54 x1 t55 t56 t57 x0 x1;ede96d7e97a7dc2a +k115;0;0 0 1 0 2 2 2;0;2 6 3 5;;x1 t1 s0:1,2:2 s0:2,3:1 t2 t3 t4 x0 w6 w0 t5 p6 x6 x6 t11 p12;1109588ad6ca3455 +k116;0;0 3 2 2;0;3;;t1 y y w3 w0 y y w3 t2 t7 t8 y y y t9 w0 y t10 t11 y t12 x1 w2 w3;f29745acafbb5da5 +k118;721;0 0 0 0 0 0 0 0;0;4 3 2 7 1;6@728;t722 t723 y b724 t725 y b727 y w6 t726 x5 s0:1,0:2 w0 w0 w3 b- t727 t728 w1 b734 w0 s0:1,1:1 w0 t729 y b727 w7 w2 t734 t735 p735 p735 p736 y y b737 y t737 p737 p738 s1:1,0:2 w4 t741 y y y b740 w2;985ac41464a40a76 +k119;0;0 1 2 0 2 3 1;0;6 1;4@-;x4 t1 x5 w4 s1:1,0:5 s0:2 t2 s0:3,3:3,3:1,1:2,3:2 s3:1,0:3 t3 t4 p4 p5 t6 t33 t34 y t35 t36 p36 p68 p68 p68 p69 x0 x4 w2 t70 t71 t72 p72 p72 p73 w4 t76 p76 p77 y t78 b- p78 p79 p79 p106 p145 p146 p150 p151 p151 p151 p152 p154 p157 p158 p158 p160 p160 p161 p185 p193 p194 p194 p195 p196 p196 p252 p252 p253 p254 p255 p255 p255 p255 p255 p256 p256 p257 p313 p314 p315;09b57f6fe65d0384 +k120;0;0 3 2 2 2 1;0;3 2 5;4@- 1@3;y t1 t5 s3:6,0:2 t6 s7:1,0:2,1:1,3:1 t7 t8 p9 x2 b- p10 p11 s0:27,1:1,2:3 w4 s1:1,0:3;a6dc5c41a174756a +k121;1;0 1;0;1;;y y t2 t7 y t8 t9 t10 s2:1,0:199 t11 x1 w0 t15 y w1 y w1 w1 s2:1,2:1,0:1,1:1 w1 t16 b14 p17 p19;ef6af7d5d57d0129 +k123;1;0 0 0 0;0;2;3@6;t2 b8 t3 t7 y y t8 y b6 t9 y t14 y w0 t15 w1 b13 w2 w2 t16 y y y w0 t17 y s0:2 w1 y y w0 t18 t22 t23 y t24 y y t26 s0:1 t27 y t28 x1 s0:2,0:2,1:1 t29 s0:1,0:82 t30;10423703ea21f7b3 +k124;5;0 1 0 0 0 0 1 1;0;4 7 3;6@9;t6 b- b5 t7 b- s0:1 t8 s0:1 t9 t10 b10 p10 t11 s0:1,2:1 t12 s0:1 t13 t14 b17 p18 b- p18 p18 p18 p20 p20 p20 p20 p20 p21 p21 p21 p22 p22 p22 p23 p23 p24 p24 p25 p26 p26 p27 p28 p28 p28 p28 p28 p28 p28 p28 p28 p28 p29 p30 p31 p31 p31 p32 p33 p33 p33 p35 p35 p35 p35 p35 p36 p37 p37 p37 p37 p38 p38 p41 p42 p43 p48 p48 p48;9da521382841d49e +k125;0;0 0 1 0 1 0 1 1;0;7 5 2 6 1;4@- 3@-;t1 s0:58 t3 b7 b1 t4 s0:2,4:1 s0:2 t5 w3 t6 x4 b5 t7 t8 t10;62c068a29b8e4589 +k126;0;0 3 1;0;;2@-;t1 b1 p2 t3 s0:47,3:200 b- p3 p6 p8 p9 p9 p10 p10 p11 p12 p62 p67 p67 p106 p111 p112 p114 p114 p114;05b720c00217cc53 +k127;4;0 1 0 0 0 0 1 0;0;3 4 1 6;2@-;b3 x2 t5 b4 t6 x4 x4 b8 t7 t10 x4 b- x1 s1:1,1:71,0:1,1:1 s1:6,1:3,0:1 t11 s0:1 s1:1,0:1,0:1,0:1,4:2,0:1,0:3,2:1,0:2,0:225,0:1,1:1,1:2,5:2,7:3,1:1 t12 t13 t14 x1 x5 b13 y x2 t15 t16 x5 y x6 x2;125930db134bbcbe +k128;377;0 0 0 0 0 0 0;0;5 4 1;2@384 6@-;t382 b383 s0:242,0:8 s0:1,0:1,0:1 w3 s0:2,0:246 b- t383 y s0:1,0:1 b- b382 b381 p385 t386 x2 t390 y t391 y w1 y t392 y s0:1,7:1 s0:1,0:2,0:6 t393 t394 s0:1 x6 t395 t396 y t397 t401 s0:27 t402 t403 b- t404 t405 x4 x3 t406 x1 t407 t408 t409;2edca6ed667f814f +k129;501;0 0 0;0;;1@-;t502 w1 t503 x1 t506 b504 t507 t508 b- s0:3,0:64,0:1,0:1 b508 p508 w1 t509 b509 p509 t510 t513 t514 t517 t518 t519 t521 t525 y s1:1,0:1 t526 s5:1,0:1,0:1,0:1 t527 s0:1,1:1 t528 t529 w0 t531 w2 w2 t532 p533 b- w2 t534 p535 y w0 w1 y t576 p577 y w2 s7:1,0:2 t578 p578 p583 w0 t584 t585 p585 p586 s0:1 t587 s0:2,0:1 t588 p589 y s0:3 t590 s0:4,1:3,1:2 t591 s1:2,1:2,3:1,0:1 t592 t593 p593 p595 p595 p598 t599 p600;2406b0d3e7dabd6c +k130;0;0 0 0;0;1;2@-;t3 x0 x2 x1 x2 t4 x1 b- t5 t6 b4 p6 t11 y t13 x0;fdfc961133437427 +k131;0;0;0;;;y t1 y t2 x0 x0 y y x0 t7 b6 p7 s0:2 x0 y x0 y s0:2 x0 w0 x0 t8 b7 p48;0209d808278735bb +k132;4;0 1 0 1 1 1 0;0;2;6@7 3@8;w6 x3 t46 t49 t50 t51 t56 y t57 t62 w4 s2:1,0:2 t63 s7:1,1:1,0:1,1:1 t64 t65 p66 s1:2,0:1,0:2,5:6,1:1,0:1,1:2,1:2,0:8,1:1,1:1,3:1,6:1,0:1,0:2,3:38 s1:1,1:8 y t67 t70 y t71 t76 y t77 y s5:2,1:3 t78 t79 p79;d2a7d77ca3fbdb01 +k133;0;0 2 0 1 2 0;0;1 2;3@5 5@- 4@-;y s0:4 t1 t3 t4 y t5 w5 t6 t7 w0 y t8 t13 t14 t15 t16 t17 y t20 y t21 b24 t22 w5 t23 y t25 y t81 x3 t82;b055a5f43a1f7012 +k134;0;0 0 1;0;1 2;;t3 w1 t7 t9 x1 x1 y b- y x2 x1 t10 t12 s0:2 t14 t66 s1:2,0:1,1:1,1:1,1:1,0:1 t70 t71 y x1 x1 t74 t93 t94 b98 p94 p99 b102 p99 p100 p100 p104 b105 p105 b103 t106 b108 p106 p106 p111 x1 b113 p112 t115 t116 t117 b- p117 p119 b- s1:1,1:1,1:3,0:1,1:8,0:1,0:2,4:22,0:1,0:4,1:6,1:1 t121 p122 p125 p126 t127 p127 p127 p127 p132 p132 p136 t138 p141 p142 p142 p145 p145 p147 p148 p149;fbaa9ed6954a1dfd +k135;0;0 3 0 2 1 2;0;5 4;2@6 3@- 1@8;t1 t2 b5 p2 p3 p4 p4 p4 p5 t6 t7 y t8 y s3:2,3:2,3:1,0:1 s0:2,4:1,1:144;058c8db3f248b588 +k137;0;0 1 1 1 0 1 1 0;0;2 6 3;7@- 4@2;x3 t1 s0:1,7:2,1:1,1:152,5:75,6:1 w1 t2 t3 t4 p4 p4 p4 p7 x4 x3 w3 t8 b7 x1 t9 s6:2,6:1,6:1,1:2 t10 t11 p11 p12 p12 p12 p12 p13 p13 p18 p19 p23 p24;3bd932ea526d3316 +k138;0;0 3;0;1;;y t1 t2 t34 t35 b- p35 p35 p36 p36 p36 p37 p38 p39 p40 p41 p41 p44 p45 p46 p46 p46 p46 p46 p46 p47 p48 p53 p58 p58 p59 p60 p60 p60 p60 p64 p65 p91 p91 p91 p92 p93 p93 p95 p95 p96 p96 p98;f3b8f98aca0338e9 +k139;0;0 1 0 0 0 1 1 0;0;3 2 4 1;6@- 7@- 5@-;t1 w7 t2 t3 b- t5 s0:1,0:2 b10 b- b11 t6 b5 p6 b8 p7 p7 p8 t9 y s1:3,1:1,1:2,0:2 w2 t12 b11 p13 s1:1,0:2,1:2 t14 t15 b15 p18 b- p18 p19 p22 w7 b20 t23 p23 p23 p24 p25 p30 p30 p30 p33 p34 p35 p35 p35 p35 p35 p36 t37 t38 p38 p39 p39 p39 p39 p40 p40 p43 p44 p47 t52 y t53 p55 p55 p58 p58 p59 p89 p89 p90 p91 s0:1 t92 t93 t97 t100;55fd620d8420ab3a +k140;866;0 1 0 1 0 0 0 1;0;7 4;2@870 5@-;t867 t868 b- w2 w5 t869 t870 t871 t872 t873 t874 t875 w4 t876 s1:3,0:1,1:3 t877;77cc684c5ca8f250 +k141;215;0 0 0 0 0 0 0 0 0 0;0;9 3 1 8 6 7;2@214 4@215;t219 b222 t220 y w7 t222 w8 t223 s0:1,5:2 t227 p232 p232 p232 p233 p233 p233 p233 p233 p234 w1 y t235 p236 p236;45c8fe5880308a8d +k142;0;0;0;;;t1 t2 x0 t33 t38 t39 t44 t46 t66 t67 t68 s0:1,0:1,1:3,5:1,1:2,2:3,2:1,5:5,0:1,1:1,1:2,1:2,1:1,4:1,1:2 t69 t70 t71 t74 p102 p103 p103 p104 p104 p104 p104 p108 p108 p109 p110 p111 p111 p112 p117 p121;df25801d3819a6e4 +k143;0;0 2 1 1;0;2 1 3;;t1 y y t4 b10 p17 y x1 b22 p17 p18 p18 p19 p19 p19 p19 p19 p24 t28 t29 b32 p30 p31 p31 p31 p31 p31 p31 p31 p32 t33 y t35 t39 t41 y s1:1,0:1,0:1,1:1 t42 y t44 t45 y b49 p46 t47 w3 t49 b49;2b357832b2c6be05 +k144;3;0;0;;;s0:1,0:2,2:2,0:2,6:3,1:1,0:2,4:2,0:2 t8 p9 p11 w0 t12 p12 p16 t20 w0 s0:3 y b19 p25 s7:2,0:1 x0 b30 p25 p25 p25 p45 p45 p45 p47 t48 p52 p52 p56 t59 t64 p65 y x0 y w0 t67 p104 b106 p104 p105 p105 p106 p110 t111 p111 p112 p113 t114 p114 p114 p114 p114 p114 p116 b118 p117 p135 p136 p136 p136 p137 s6:2,0:3 w0 s0:1,1:2,0:1,1:1 t138 p138 p139 s1:1,0:1,0:2 t143 s0:2,1:2 t144 s2:3,0:1 t145 p146 p148;5ffa17c3ed392403 +k145;0;0 1 0 1 0;0;4;3@-;t59 t60 x0 t64 x3 t65 s1:7,0:3 s0:2,5:1,0:3,1:2,0:1,0:1 x0 w0 t66 b72 t67 b- p68 p70;04ab51f2ff0fffe0 +k146;5;0 0 2 0 1;0;2 3;1@4 4@4;w1 w1 t6 t46 t47 t52 t53 t54 s0:1,0:2,0:2 t55 w3 b56 b61 t56 s0:2 t57 b55 t61 b- b67 s2:2,0:7,2:2 t62 s0:3,1:1,2:1 t63;0478cbc422f1c21f +k147;3;0 0 0 0 1 1 0 1 0;0;3 1 2 7 4 8;5@7;t4 b9 t5 t6 t7 s1:2,0:2,0:1,0:1 t8 x3 s1:1,0:1,1:3 s0:1 t9 w2 t10 t13 t16 b- t17 t22 t27 t28 x5 b- b- t32 t36 t37 x2 t38 t39 t40 x5 t41;6bbe747b3cbaffc4 +k148;0;0 1 0 1 1 1 0 1 1;0;7 6 5;8@6;y t1 b- t3 b2 p4 b8 p4 p4 p6 p6 p8 t9 t13 b15 p15 t20 s0:3 t21 t22 t23 t24 t25 b25 p25 t26 t27 t28 b31 p29 p30 p33 t34 w6 s7:2,2:1,0:1 t35 s1:1,5:1,0:2,1:2,1:2 t36 t37 t38 p43 b41 t44 t45 t46 p47 s1:2,0:2,0:1 b48;d571c20137e8ab36 +k149;4;0 0 1 1 0 0 0 1 1 0;0;1 5 2;4@11 8@- 3@2;t5 s0:3,0:3,0:1 x8 s0:3,1:1 t6 s0:3 t7 t8 t11 x2 t12 b12 t13 t14 t15 s0:2 t16 s5:1,0:3 t17 t18 p18 p18 p18 p19 t20 x3 t21 t22 p24 t25 t27 t28 t33 b36 t34 p35 b33 s1:1,0:2 t36 t80 t81 t82 b- t83 t84 t85 t86 x9 x2 t87 x9 t88 x4 t89 t90 t92 t95 t96 t97 t98 t99 t100 t101 t102 t103 s1:3,1:1 t104 t134 t135 s1:3,4:2,6:2,1:1,5:58,0:3,1:2 t136 s0:2,0:1,0:1,0:3,1:1,1:1,1:1,0:2,0:2,1:87,1:1,1:1,1:1 t137 s1:1,5:1 t138 t139 t140 p141 b139 b140;40d51d59caea585f +k150;0;0 0 0 0;0;1 3 2;;t1 t2 t3 t8 t10 s0:1,1:1 t11 b14 x2 t14 t15 p16 t17 p21 p21 p21;a2fa39b12d37a646 +k151;2;0 2 0 1 3 3 2;0;4 1 5;2@- 3@-;t7 t8 t9 t10 t11 t12 s2:2,3:2,0:1,2:56 w2 s3:2,2:3,0:1,3:3 b- b14 p12 p13 p14 t15 t16 b- p16 p16 p17 p18 p19 s0:1,2:1,1:1 s2:1,0:1;e2f6366dca35bbe0 +k152;942;0 0;0;;1@-;t943 t944 t945 t946 t947 t948 t951 t952 y t955 s0:1,0:1 t956 s0:3,0:1,0:2,0:3 t957 s0:64,0:1,0:1 t958 t959 x0 t960 t965 t966 t967 t972 t973 x0 t974 t975 t976 b978 p980 x1 t981;1a3ecd17c4340837 +k153;0;0 0 1 0 0 3 2 0 2 0;0;1 2 3 8 5;9@7;t1 s4:2,0:3,3:3,2:1 b- b2 y t2 t3 p4 p5 s2:1,5:1,2:1,1:1,1:1,2:2,0:2,4:2,1:1,0:1,3:1,7:2 b- t7 t8 p9 t10 x9 x0 y b- p11 p12 t14 b- x2 t15 t16 p16 p16 p17 p18 x1 t19 t22 p22 p22 p22 p23 x7 t24 p60 y t61 b62 p62 y t63 t64 p64;e24708239ad1b1c7 +k154;0;0 0 0 0 0 0 0 0 0;0;3 8 4 5 2 6;1@4 7@-;x6 y x2 t38 t39 t43 b47 s2:27,0:1,1:2 t44 y x7 t45 p46 p46 p46 p46 p47 p48 p48 p48 p49 p50 p50 p55 p55 p55 p55 p114 p117 p120 p120 p120 p120 p124 p127 p127 p174 p178 p178 p178 p178 p178 p178 p178;b500d7a27a48be24 +k156;4;0 0 0;0;2;;y s0:12,1:2,1:1 s1:1,1:1,0:3,1:1,1:4,1:2,4:2,1:1,0:3,0:121,1:1 t5 y s1:245,0:1 y t10 p10 p10 p10 p11 p11 p49 p50 p54 p54 p59 p59 p60 p61 p61 p66 p66;1082b75144d19582 +k157;13;0 0 0 1 0 0 1;0;5 3 6 2;1@15;y t14 t15 t16 t21 y b19 y y s0:3 b25 t22 t26 s1:1,0:3 s0:1 w1 b- x5 t37 s2:1,0:3 t38 t43 p43 p44 t45 t46 t47 p48 y b- s0:2,2:1 t49;003bca1d2c0a8fca +k158;0;0 1 1 3 1 2 3;0;2 6 1 3;;x6 w0 x2 t8 b11 p8 p8 p8 p8 p9 p9 p10 p10 p10 p15 b15 p15 t16 t17 w0 s0:1 y b21 p18 p19 p64 s2:1,2:1,0:1,1:4 b- p64 p64 p65 p66 p66 p66 p66 p67 p67 p68 p72 x0 x3 t77 t78 b84 w2 b78 t79 t80;8dc543e18e0715c8 +k160;3;0 0 0 0 0 0 0 0 0;0;1 2 7 6 8 4 3;5@2;t4 t5 t6 t11 t64 x2 t65 b- t66 b66 x3 w8 t67 t68 b- t69;0b39259a508a08f4 +k161;0;0;0;;;x0 b3 p1 p1 p1 p5 x0 b8 p5 p5 p6 p6 p6 p41 b40 p42 t43 y x0 b- p43 p45 p46 p46;ef93ecdfb608aa50 +k162;0;0 2 2 2 1 2 2 2;0;4 6 7 2;1@7 5@-;t1 t2 t6 t7 t8 s5:1,1:1,0:1 b- p12 p63 p63 p64 p64 p64 p66 p71 b- p71 p71 p124 p124 p124 p125 p125 p125 p125 p126 p126 p126 p127 p127 p127 p127;6812eec81a427fc1 +k163;899;0 1 1 0 0 0 1 1;0;2 5 4 7 6;;t900 t903 w4 t904 t908 t912 t913 t914 t915 t916 t918 x2 t919 t920 t921 w3 w4 t926 t927 w3 t928 s1:2,0:1 t930 t933 w6 w4 t934 t935 w1 t936 s1:1,6:1 w1 t937 t938 t939 p939 p939 p939 p939 p940 t941 p941 p941;5d25589ab88a694b +k164;0;0 0 0 0 0;0;3 2 4;1@-;t1 t3 w1 t4 s0:1,1:2,0:1,3:2 y s0:1 t5 s4:6,1:1,1:1,0:2 t6 t7 p7 p8 p9 p9 p10 p10 p11 p11 p11 p11 p11 p12 p12 p12 p12 p15 t28 p29 p29 p29 p29 p30 p35 t36 t37 p38 p38 p41 p41 p41 p42 p42 p42 p43 p44 p46 t47 p47 p47 p47 p47 p50 p50 p50 p51 p51 p52 p101 p154 p154 p154 p154 p159 p159 p160 p161 p161 p162 p197 p199 p199 p199 p215 t219 p219 p220 p220 p220 p221;df3d90b423bb1433 +k165;5;0 1 1 0 1 1 2 0 1;0;2 6 8 7;4@12;w6 t6 w3 t9 t10 w2 t11 w5 w4 t12 t13 w3 x3 t14 b15 x4;56350a3731d7e4a2 +k166;0;0;0;;;w0 y w0 t1 w0 t2 w0 w0 t3 b5 p4 p4 p5 w0 w0 t6 w0 w0 t7 y t8 w0 t9 s0:1;baf333632fc83403 +k169;3;0 0 0 2;0;3;1@6;b- p3 p3 p4 p4 p6 s0:2 t7 t9 t10 t11 t12 y y t13 t14 y t15 t16 s5:3,0:1 t17 t18 p19 p22 p22 p22 p22 p23 p24 p28 p28 p29 s0:2,1:1,1:1 s0:3,1:6,0:1 t30 p31 t32 y s1:2,0:1 b36 p33 p34 p35 p36 b38 p36 p37 p37 p39 s0:3 t40 p41 w1 t42 t46 t47 y y t48 t71 t72 s0:45 s0:2 t73 s0:3 s0:2,2:3 t74 t75 x1 t76 t77 t78 t79 y t80 t85 t86 t87 b90 p87;f4ee440f606f96bf +k172;5;0 0 3 1 0 3 2 1 3;0;8 1 5;2@9 4@3 3@-;t9 b7 b13 b9 p9 b- b11 p9 p9 p9 p9 p11 w6 w1 t30 y b30 b- p30 b33 p30 p30 p30 p31 p32 p33 y b33 p35 w1 b40 b-;c7c22f36f44b69cd +k173;0;0 0 1 0 0;0;2;3@- 1@- 4@8;b3 p0 p0 p3 t4 x2 s0:1 t5 s0:3 t8 t13 t14 w3 t17 y x1 s0:2,6:4,5:2 s1:2,0:8,0:2,4:1,1:1,1:1,1:1,5:1,7:134,6:1,2:2,0:1,0:1,1:1,0:3 t18 s0:1 s0:1,0:2 t19 t20 t24 w4 w2 y t25 y w1 t29 t32 s0:1 t34 w4 w2 b- y t35 t36 t37 y w1 t38 s0:2 s1:1,0:3 t39 y;1d8eb61e02a5e9c1 +k175;0;0 0 0 0;0;1;3@1;t1 w2 y t2 x2 y t3 x1 t8 t11 s0:1 t12 s0:6 t13 s3:237,0:1 t14;52318b20ddf355c1 +k177;5;0 3;0;1;;t6 t7 w0 t8 t9 w0 w1 y x1 w1 w1 t10 b15 p10 p10 p10 p10 p10 p13 p14 p14 p14 p14 p17 x0 t18 s2:3,0:8 s0:1 t19 s1:1,0:1 s0:8,0:1 t20;ec7e1b6fe6e1d791 +k178;0;0 0 1 1;0;3 2;1@5;t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t38 t39 t40 t41 t42 t43 t44 t45 t46 x0 t51 w0 t52 t53 w3 t55 t56 w3 t57 t60 t61 t62 b66 y t63 y t64 w1 t65 t66 t67 t68 x0 w2 t71 t72 t73;32d0ffd954c0ee15 +k179;0;0 0 0 0 0 0 0 0;0;4 5 1 6;3@- 2@8 7@-;b6 x7 t5 x6 w0 t6 t7 t10 t11 t12 t13 x4 t18 s0:3,5:2,1:6 t19 s0:8,0:2 x3 t20 x2 w4 s0:1,6:2 t50 p50 p51 p51 p52 x6 b54 t53 p53 p53 p54 p55 b60 t56 p56 p57 p62 p66 p66 p67 x7 t68 p69 p69 p69 p69 p69 p72;d59f4e8682a7f3aa +k180;3;0 0 3 3 2 3 3 1 0;0;8 1 7 5;6@- 2@10;w1 x2 b4 b7 t4 t5 t6 t7 y t8 t9 t10 y t15 t16 t17;1ad17f35a652a33a +k185;0;0 1;0;1;;x0 t1 t2 t3 b2 p3 t8 t9 x1 b14 p9 p10 p10 p10 p11 p11;e7fa64d7c53c17d0 +k210;0;0 1 0 0 1 0 0 1;0;2 5;7@6 4@- 3@1;t3 t4 b7 x4 b6 b4 b2 p4 y y w2 b5 t5 w5 w1 b-;43a268986f7bf363 +k281;4;0 2 1 1 0 1 1 1;0;2 4 7;6@3 3@- 5@- 1@5;x5 b4 b6 p8 x6 x4 s0:2 t9 w1 t12 x3 t13 x6 t14 x1 t15 s0:1,0:6 t16 t17 s5:3,2:2,0:1 t18 x3 b22 x1;e667317b73ca688d +k292;4;0 0 0 0 0;0;1 2;3@-;x0 t5 w3 t6 y t7 s0:1,3:1 x1 t8 x2 t9 t10 p11 y t12 p15 w2 b19 w1 y y t34 p34 p34 p35 t36 p36 p36 p39 t40 p40 p41;557fc451f517f375 +k321;0;0 0 0 0;0;2 1;3@3;b5 w3 t1 t2 y t7 t8 s0:2,0:2,1:1 y t9 t11 s0:2,2:1,1:1,1:1 t12 b18 b18 b11 b13 p12 b10 p12 b17 p13 s7:1,1:2,1:2,0:2 t14;7e05813cc0f25058 +k327;2;0;0;;;x0 s3:3,0:1 s1:1,3:2,0:1 t3 s0:1 s0:1,5:1 t4 t5 t6 p6 p6 p6 p6 p7 b7 p7 b7 p7 y t8 p12 p12 p17 x0 t18 p26 p27 t28 p28 p53 b- p53;094dc93d4b4e2c79 +k360;0;0 1 1 1 2 0 0;0;5 3;;t1 t2 s1:3,0:1 t3 b3 y t4 y t9 t10 t15 b21 t16 t17 s2:2,2:1,1:1 t18;00040cb8e4eb727b +k390;0;0 0 1 3 2;0;1 4;3@7;t1 b- b1 p1 t2 x3 x2 t3 t7 w0 t8 t9 s0:1 t12 t13 t14;87cfce4d2e2399f5 +k420;0;0 1 0 0;0;1 2 3;;x2 w1 t1 x3 y t2 t3 b3 b6 s0:6 y b4 p4 s7:5,0:1,0:3 t5 t6;f2aac60e2f8ae4ed +k441;0;0 2 1;0;2 1;;y y b1 p0 p0 p0 p1 b2 p1 p1 p4 t6 x0 b4 p6 y t7 b8 p7 p11 t12 w1 b11 p12;13572a7b392069d2 +k455;0;0 1 1 1 0 0 0 1 1;0;8 1 7;3@- 5@8 4@-;b5 p43 y b43 b- p43 t44 w5 t45 b- p56 p56 p56 p56 p57 p57;316b1031c6fbd607 +k471;0;0 1 0;0;1;2@1;s1:2,0:2 w2 t7 b6 p8 s0:2,0:1,0:2 t12 s0:2 w0 x1 w1 t15 y w1 t16 b17 w2 w1 t17 s0:1,2:2 t22 y t23 p30;c06cd1641e868873 +k493;0;0 1 0;0;2;;w0 s0:2,2:1,1:1 x2 t1 s2:2,1:1,0:2 t2 s1:3,1:1,0:2 x0 t3 x0 y x0 b1 x1 b3 p3 t4 p5 p6 p6 p7 p7 p8 x1 x1 t10 p10 p11 p15 x1 b- t18 p18 p18 p18 p18 p23 p27 y x2 t30 p31 p35 p36 p37 p37 p37 p37;c14be99e7f9c6dfd +k497;2;0 1 0;0;;;t6 t9 y y w2 y t13 y t15 x0 w2 t16 b15 p16 t17 w0 t18 t19 t20 x2 x1 t21 t22 y y t23 y t81 x2 y b- p82;9b0db79ca04b9596 +k560;0;0 1 0;0;;2@5;y t5 s2:3,0:5 b8 b- p5 p6 p6 p7 p8 p8 p8 p8 p8 p9 p44;3ad9bc5eaeb77992 +k565;2;0 1 0;0;2;1@-;t3 s0:1,3:1,0:2,1:3 t32 p32 p33 x1 t34 p35 t36 t37 b37 p37 t38 y t39 t40;c61804c500b6900d +k570;0;0;0;;;t4 t5 t6 b- p6 p9 p10 p16 p16 p17 p17 p17 p17 p22 p23 p23;2e22be93a3d91394 +k600;0;0 2 2 0 1;0;4;1@8 3@-;t3 w2 t4 x1 s3:1,0:2,1:7,0:2,0:2,1:1,2:1,3:1,2:1,3:1,3:1,0:6,3:71,0:4,0:1,1:1 b- p5 p5 p20 t24 p26 p27 p28 p29 p29 p29;06aa7c06a611e36a +k616;0;0 1 0;0;;;t1 t3 y y w2 t4 t6 y y t9 y y t10 t14 t15 b14 p15 y t16 y b22 p17 p19 p19;af4c14fee909723c +k628;0;0 3 3 2 0 0 3 0 1;0;7 3 2 4 1;6@-;y t1 s0:2,1:2,3:3 y t2 y t3 t4 s3:6,2:1,0:1 y y t5 p5 p5 p8 s3:1,0:1 t12 y t13 t14 t18 b- t19 t20 s3:2,3:2,2:4,2:1,5:3,0:1,1:2,1:2,1:1,2:2,6:3,2:2,2:3,2:3,1:1 s3:6,2:1,1:1 t21 y t22 t27 y t52 y y y y y y y y t53 p53 p54 y t55 t56 t57 t58;61c2b5ad54d6bf13 +k631;4;0 0 0 0 0 0;0;1 2;5@- 3@8 4@-;b- t6 s0:4 s0:7,0:3 t7 t8 b8 s0:230 b- b13 p10 b8 p11 b10 p14 b15 b14 p16 b16 b21 p16 b15 p16 b22;2443f477696d0ce6 +k633;0;0 0 0 2 1 1 1 2 2;0;5 4 8 2;7@-;t1 x7 b- w2 t2 w0 t3 s1:1,0:7,1:1 t4 s2:1,2:1,0:1 t5 b4 t6 t7 w0 w0 t12 s6:1,2:1,6:1,6:1,6:1,6:1,6:1,6:3,6:2,6:1,6:144 s2:2,0:1 w2 t13 w1 t14 t19 t21 w4 w2 y t22 t23 w1 t24 t25 t26 b32 t29 t30 t31 w2 y t32 t36 t37 y t38 w1 t42 t45;f109a3869938d0ad +k650;2;0 0 0 0;0;2;3@10;t3 b2 b- p3 b- p3 p3 p4 p5 p6 p20 y b- p20 p20 p20;7ac42918c1f58238 +k665;0;0 1 1;0;1 2;;t5 t6 t7 b5 p7 t8 t9 t10 t11 w0 t12 b- p16 p17 p17 p17;6ca85182bc4cf65d +k670;0;0 1 0 1 0 1 1;0;2 1;6@3 4@-;t1 x6 b4 y x0 t2 y x6 y t3 t4 b10 x2 b3 p4 y;4a52f36250382e6c +k674;0;0 0 0 0;0;2 1;3@-;s0:1 t1 b1 w2 w0 t4 s0:3,1:3 t5 s1:2,1:1,0:3 t6 t7 p8 p13 p13 p13 p13 p16 t17 b16 t18 w0 b17 s1:2,0:2 t19 p20 p21 p22 t23 t25 p26 w2 t27 x2 t28 p28 p29 p29 p29 p30 b- w1 s0:1,1:3,0:7,1:1 w3 t33 p33 p34 p36 s0:1,1:1,6:1 s3:1,1:1,0:2,1:2 b40 t50 p51 p51 p52 b- w3 s1:3,3:2,0:4,0:1,1:1,4:1,5:1 s1:5,1:4,0:1 b50 b- y b- p52 t53 b51 p53 b52 p53 w0 w0 t54 p54 p55 p55 p56 p74 p99 p99 p99 p99;a386b8f93de3f4e9 +k680;0;0 3;0;;1@2;s0:1 t1 t2 b- p3 p7 p8 p13 p17 p17 p17 p17 p18 p18 p18 p19;ab91f3c2c572c5a0 +k708;2;0 2 0 2 1;0;2;4@- 3@5;b6 b4 p3 p4 s0:5 s0:1 b- p4 p4 p4 p4 p4 p4 p4 p5 p6 w2 x2 t7 b- t8 b7 p8 y w2 b7 t9 s0:2,1:3,0:7,1:233,2:8,2:3,7:2,0:1,0:11,2:2,1:1,4:1,1:1 t10 t11 w4 t12 w4 w3 t13 p14 p15 p15 p16 w3 b20 x4 b14 p16 t20 t21 x3 x4;19c6b9018f7bcf53 +k735;2;0 1 1 0 0 0 1;0;4 1;2@4 6@3 5@8;t3 w5 x2 t4 y t5 t6 w0 w1 t7 b10 t53 x2 x6 t54 t55;f965450d5f50cc65 +k751;290;0 0 2 2 1;0;2 1;3@298;t291 t292 t293 t295 s0:1,3:1 t296 s0:1,2:2,0:1 t297 t298 y t299 y t301 t347 t348 y t351 t352 t353 x1 w2 b352 x0 t354;9800b959589de77b +k757;0;0 2 2 0 0 2;0;2 3 1 4;5@-;t2 b- t3 w1 b7 w0 y y t4 b- b7 p4 p7 t11 b11 w4 b15 x5 y s2:1,2:1,5:1,0:1,1:32 b14 p12 w5 y t13 b13 y t14 y t15 p15 p16;93f453337d7379ce +k788;3;0 0 0 0 0;0;2 1;4@-;t8 t9 t10 t11 t12 t13 t14 t15 t17 y x3 y t18 t19 t20 t21 y t22 b20 y x1 x1 t23 b29 t28 t29 t30 x1 b- t31 t32 b- t33 x0 t34 b32 p34 t35 b33 p35 t39 t43 t44 y t45 w4 y w3;0fb7835609e4c923 +k790;0;0 0 0 0 0 0;0;2 5 1 3 4;;t1 t2 y s0:1 s0:3,1:1,0:1 t3 w4 t4 b8 t6 b- y x0 t7 p7 p11;61bd08e7cd9f1a88 +k816;1;0 2 2 1 2 1 1 2 0 0;0;9 6 2 4 1 3;5@- 7@-;t2 s0:3,2:1,2:5,2:3,2:1,2:2,2:2,2:2,2:3,2:7,2:1,2:1,2:1 w4 t3 s2:1,3:1,0:1 w6 t4 t5 t6 p6 p6 p6 p6 p7 y b- w0 x6 t8 y s2:2,0:3 t13 b14 t14;2eee31deb8af2a0f +k821;0;0 0 1 0 1 1 1 1;0;2 3 5;4@5 1@1;t1 t2 b- t3 t4 t5 b5 y b8 p5 b5 p6 b- p6 p6 p7 p7 p7 p12 x4 y y t15 b-;ca4226564e919e36 +k822;0;0 0 0;0;;;t1 t2 t3 b8 p3 p4 p4 p5 p6 p6 p6 p7 p7 p7 p11 s0:2,1:1 t12 t13 t14 t15 p17 t18 p22 w0 t24 p25 t26 t27 p27 p27 p27;34294303b55f904e +k853;0;0 1 0 1 0 0 0;0;2 1 6 4;5@-;t1 b6 t2 t4 y b8 x0 b9 t5 x4 b- p8 b- b8 p8 y x4 y b11 p8 p13 b- t14 t15 b15 p15 y y t16 y x5 x4 x1 t18 t19 b20 p21 t22 s1:1,4:2,0:2,1:1 s1:1,0:1,1:1,1:3 s0:1 t23 s1:1,0:1 s0:2 t24 t25 t26 x6;e1cc30c8f0cdb318 +k880;2;0 0 0;0;2 1;;s0:2,1:2,0:3 t3 s2:2,1:1,2:1,2:1,1:2,2:1,2:3,6:1,2:2,0:1,1:1,1:1,1:2,2:1,2:2,2:6 t4 s0:3 t5 t6 t9 t10 s0:2 t11 s0:1 t12 t13 b17 t14;91be901f7fdb4b2d +k897;0;0 0;0;1;;x0 x0 b3 b2 p1 p1 p1 p1 p2 t3 t4 w1 x0 w1 b3 b- p4 t35 s0:2 b35 p35 b35 p36 y y b- p40 p41 p41 p41 p41 p43;0df6f0d3eeb5527a +k898;1;0 0 0 0 0 0;0;1 4;5@9 2@7 3@8;b1 b2 t2 y b- b7 t6 s1:2,0:1,5:4,3:2 t7 b6 b11 b13 p7 b- p7 p7 p7 p9 p9 p12 p13 p14 p14 p14 p14 p15 p15 p16 p17 p17 p18 p19 t20 p21 p22 p22 p23 p23 p24 p24 p25 p25 p25 p25 p26 p26 p27 p43;5aaea3a4fe40f4cb +k922;3;0 0 0 0 0 0 0;0;1 6 5 4;;x6 s0:1,0:1,5:2,0:1 t4 t5 t6 t7 p8 p10 t11 t12 p16 t17 p18 p19 t20 y t25 t26 t27 p28 p29 t30 t31 y t32 p37 p38 p39 t40 t41 y t42;14ae1017eaf0b684 +k965;0;0;0;;;t1 b- p1 p1 p4 p5 p6 p7 p7 p8 p8 p9 p9 p10 p10 p11;07b234cc457277f2 +k985;2;0;0;;;y b1 p2 w0 b6 p2 p59 t60 w0 y t61 t65 t66 t67 t68 b70;f247fa3157d7c752 +k1003;4;0 2 1 1 2 2 0 0 0 1;0;2 5 4 7 1 9 6;8@8 3@8;b7 t5 t6 b5 b- p7 t11 b11 x3 y b17 w4 b16 p13 b13 p13 t14 t15 t16 w4 t17 b15 b- b15 p17 b21 b23 p18 p22 b23 p22 p23 t24 y t25 w7 b23 t26 b- b26 b- p26 b26 p27 b25 p28 w8 b-;3643d1c5f54af6ea +k1027;5;0 0 0 0 0 0 0 0 0 0;0;9 8;1@- 3@9 7@4 5@-;y y b3 y b5 b7 p6 t7 y t8 b10 b- y t9 t14 t17 y t18 b24 t19 b- t20 x2 t21 t23 t24 w5 y b26 t25 x9 t26;663d29fb5c94b17e +k1030;0;0 0 0 1 1 1 0 1 1;0;5 4 1 7;2@7 3@1 8@7 6@-;t1 b6 y w4 w6 b- b5 p2 p2 p7 b12 t8 t9 b12 y b10;c89ad6617008bea3 +k1040;0;0;0;;;t3 b- p4 p4 p5 p6 p7 p8 p9 p10 p10 p10 p10 p10 p11 p11;94e0994b7825054d +k1050;0;0 0 0;0;2;1@-;y y y t1 t2 y y b8 y b2 p2 t3 t6 y t7 y;eb495538da2389a0 +k1051;5;0 1 2 2 1 1 2 1 2 0;0;7 9 6 3 5;4@- 2@12 1@-;t6 s1:3,0:2,2:2,2:2,2:1,2:3,5:1 t7 s2:1,0:2 t8 t9 w5 b13 t10 t12 b13 w6 t13 t14 t15 y y w0 t20 w8 t21 b26 t22 t24;5a16378e3d1efdda +k1062;4;0 0 0 0 0 0 0 0 0;0;1;5@- 2@9 8@8;y t5 t6 w8 t7 t8 s0:1,4:2 t9 b- t14 p17 p18 p18 p19 t20 p20 p20 p21 p21 p22 y t24 p29 p29 p30 p30 p30 p31 t36 p63 p67 t68;320f74faf8b32847 +k1065;0;0;0;;;t1 s0:1 t2 s1:83,1:1,0:2 t3 t4 p5 p5 p5 p6 p6 p7 p7 p8 p9 p9;09745d0c93dc0e17 +k1091;0;0 1 0 1 0;0;3 2;;y t1 t2 x3 t3 t4 t7 b6 t10 y b11 s4:255,1:1,0:1 t11 t12 p12 p12 p13 p13 p14 p15 p16 p16 p17 p18;50a700d3b5695ab8 +k1110;0;0;0;;;s1:1,0:1 t1 s1:2,2:1,1:1,1:1,2:2,1:1,0:3,2:1,2:1,3:2,1:1,0:2,6:2,7:1,4:1,2:5 t2 s0:2 t3 t4 x0 y y t7 t8 t10 t11 t15 t20;680b7087a078fdc6 +k1168;0;0 1 1 0 1 0 0 1 0 0;0;7 4 1 9 6;8@3 3@4 5@3;s0:2,0:37 s4:4,1:1,0:1,1:3,0:1,0:1,1:2,0:2,0:1,1:3,0:1 s0:178,1:242 t1 s1:8,0:1,0:1,0:2 s1:3,0:2 y t2 t3 w2 s1:1 s4:1,1:1 t5 p5 p10 t13 p14 y x5 y t15 p18 y x3 y y x8 y s5:2,0:1,1:1 y t19 p45 p45 p49 p51 y t52 p52 p52 p52 p52 p52 p56 p58 y t59 s1:1,0:1 b-;ae1230524ff41cb3 +k1180;0;0 1;0;1;;t1 t6 y y y b- p9 p10 p10 p10 p10 p13 p13 p16 p17 p22;bd6a0d55d20b8637 +k1186;3;0;0;;;t4 t5 b4 p5 t6 b7 p6 p7 b5 p8 t9 t10 y b8 p11 t12 b- p12 p13 p13 p13 p14 p17 p42;30a72e65006ccc70 +k1190;0;0 1 1 0 1 1;0;;1@- 5@4 2@-;w0 t4 b8 p5 p9 b10 p10 t11 t12 y t13 b12 p13 s0:1,1:3 t14 s0:1;3521d10ac49f5d31 +k1194;0;0 0 0 2 0 0;0;4 5 2 1;;y b- t1 x1 t2 s0:1 s2:2,0:1,2:1 t6 t7 p8 p8 p8 p9 p10 y t11 p12 p13 p16 p17 p17 p17 p18 w4 w0 b17 y t19 p20 p20 p27 p28 p29 p29 p30 y t31 p36 p37 p37 p39 p39 p39 p39 p40 p41 p41 p69 p69 p73 p73 p74 w4 b- x5 s6:1,2:1,0:1 t75 p82 p82 p131 p136 p136 p136 p136 p137 p137 p137 p137 p137 p137 p137 p137 p139 p139 p149 p149 p149 p149 p150 w0;b5af71ba57162776 +k1197;0;0 0 2 2 1;0;3 2 4;1@-;t1 t2 t3 t4 s1:3,0:1,1:3 t5 t9 t10 t15 t16 t18 t19 y y t20 s1:2 t21 s2:1,1:1 x1 b24 p24 t25 t26 t30 t34 s0:1,1:1 t35 t36 t38 x3 t39 t40;a1901627af400ef9 +k1200;1;0 1 0 0 1 0 0 0 1;0;2 8 6 4;3@5 7@2 5@6;t61 w2 s0:11,0:1,0:2,0:3,0:3 t62 w1 y w8 t63 t64 t66 t67 w6 t69 w2 w0 w3;d5ef1c1fabc4f7e1 +k1216;912;0 1 1 1 0 1 0;0;2 5 4 3;1@913 6@-;t913 t914 t915 s4:2,0:2 s0:1,0:1 t916 s1:2,0:1,0:1 x1 y t917 w3 y x4 t918 t919 t920 t923 y t924 t929 b- w4 s2:1,0:2,1:1 w4;cefe12b424d81f27 +k1285;277;0 2 1 1;0;1;2@285;t278 y t282 s2:3,2:1,0:1,6:1 t283 t284 t285 t286 t287 x1 t288 t291 t294 b297 p294 p294;a2c0c178b75b2951 +k1286;4;0 1 0 0 0 0 1;0;5 1 4;3@- 2@10 6@9;w3 x6 t5 s0:1,6:1 t6 t8 p8 p9 w4 t10 p13 b11 t14 p14 p15 t20 p20 p20 p23 t24 p26 p27 t28 p28;f04623669e9a3eb8 +k1294;0;0 0 0 1 1 1 1;0;2 5 4 3 6;;t1 t2 s0:63 b7 t3 t4 t5 s1:1,1:2,0:1 t6 s3:2,0:1,0:1,1:1,0:2,1:1 t8 p8 p8 p55 t56 p59 t60 t61 t62 b61 t63 t66 t69 y t73 p73 p73 p76 t81 p81 p82 t87 t88 p88 p89 p89 p90 s0:2,1:1 s0:1 t91 s1:2,0:1 s0:6,1:1 t92 t93 s0:2,1:3 t94 y t107 b108 t112 s0:1,1:1,0:1,0:1 s1:1,0:1 t117 b- t118 y x0 t119 t120 t121 t122 t124 y t125 t126 x1 t131 b135;2e93055763924575 +k1302;0;0 0 0 0 0 0 0 0 0 0;0;7 6 8 3;9@5 5@1 4@2;s0:2,0:2,2:1,0:2 t1 b1 t4 b4 t5 b10 t7 w6 t8 w5 t9 w3 b- t13 p14 y x9 t15 w5 b15 t16 t17 t18 t19 t77 b78 t81 b83 b- b87 b-;4ff60a14a1b77706 +k1318;0;0 0 0 2 0 2 0 0 1;0;8 6 4 2 3;1@- 7@5;w1 y t1 s3:3,2:6,1:2,0:1,1:2,1:3,0:1 t2 s0:1 b- t3 s0:1,1:3 s0:1,1:1,0:2 t4 s5:1,0:2,4:3 s1:1,0:1,2:3,0:1 t5 t6 t7 x2 y x3 y w1 y t12 y t13 t18 b23 p18 p19 t38 x8 x4 t41 y t42 t43 y b46 y t46 y t47 t48 t50 y w4 y t51;9d22328a0f21a022 +k1320;0;0 1 1 1 1;0;1;4@-;t1 t6 t7 t8 b11 p8 p13 w2 t14 t15 t16 t17 t18 s1:1,0:1 b18 p18;8bb33178c460c99c +k1337;0;0 0 0 0 0 0 0;0;1;3@2 5@-;t1 t3 t18 t19 y y s6:2,0:1 t20 x1 y y y t22 p22 p23 t36 p36 p36 p36 p36 p37 p37 p37 p38 y b37 t39 p40 p40 p41 x1 t42;1b5602ac0aefd44f +k1354;3;0 0 0 0 0 0 0 0 0 0;0;3 2 7 9 6;1@- 8@4 4@3 5@10;y y b- t4 t8 t10 t11 x5 y t12 t17 t18 y y t19 b21 b21 y x8 b19 y b18 t20 t21 b21 b23 b19 t26 y y t27 t28 x9 y b33 t30 b28 t31 y s3:1,0:7 s2:2,2:7,2:1,2:6,1:1,3:1,0:1,3:2,2:3,2:1,3:2 t32 s1:3,2:3,0:1,3:2,1:1,1:1,1:1,0:1,4:4 s3:1,2:2,0:1,6:1 t33 t34 p34 p37 y t41 p44 p44;f3358920bac43522 +k1357;2;0 1 0 1 0 0;0;;3@3 2@2 4@6;b4 p2 w4 y t7 b- t8 x3 w4 b- b10 s1:1,0:1,1:3 t12 y t13 x0 t26 t31 b- t32 t37 b43 p38 p38 p39 p39 p40 p41 t42 p42 p42 p42;a783c8d62bd7334a +k1366;3;0 3 1 3;0;1;3@1 2@-;y t4 t5 s0:2 t6 s3:1,0:240 t7 s0:2 t8 t9 w3 b7 p9 t10 x1 t11 t16 t17 t20 w0 y t24 t25 y;f5f90b71b8e940ff +k1380;4;0 1 0 1 0;0;3 1;4@6 2@10;t5 b6 p6 t7 b9 t8 b8 p37 y y t40 t41 t42 t43 w2 t45;19fc83e06902a122 +k1395;0;0 2 2 3 0;0;4;3@- 2@3;w3 b- x2 w0 w3 w0 t1 t2 t3 w1 w4 x3 w2 t8 t11 b17;5d2fe0be3b3dc6ed +k1400;0;0 0 2 1 0 2 2 0 0 0;0;3 6 2 7 5;9@- 8@2 4@6 1@-;x3 b6 b- p0 p1 p2 t3 b8 p3 p3 p4 p8 b10 t9 t13 t14;195c6b343ddc2fee +k1411;3;0 1 1 2 3 0 3 3 1;0;4 5 2 8;7@-;s1:2,3:2,0:1,0:1 t4 w4 t5 t9 t10 t13 t14 t15 b21 w4 t18 b24 y t20 t21 y t65 y t66 t69 w2 b72 t70;3801ea1aa26e811e +k1450;2;0 0 1 0 1 0 1;0;2 4 3;5@7;y x6 y t3 t4 x5 s3:1,0:1 t5 t7 x5 t11 t13 t14 p15 y t16;ae4d620afe8baab5 +k1466;0;0 0 0;0;;1@-;s5:2,1:1,0:2 y x2 t1 w1 w2 b7 w0 b5 w1 t2 p2 p2 p2 p2 p4 p5 b5 b11 p5 t9 p13 p16 s1:2,1:1,1:1,0:1;6d1890e25e1cc719 +k1491;0;0 1 0 2 0 0 0 1;0;1 6 7;3@-;y s2:1,2:1,0:1 y t1 t2 p2 p2 p3 p3 p4 w0 t7 t46 b- w6 w4 t51 p52 b55 s0:1,2:2 t53 p53 p54 b54;0fbb69317b79c0f6 +k1508;373;0 0 0 0 0 0;0;1 3;4@375;t406 t409 y t410 x5 y t411 x0 t413 s0:1,3:1 y t414 t415 t416 p417 t418 p418 p423 t424 p425 t426 p430 p430 p435 t440 p441 y t497 t498 p499 t500 p501 t502 p503 t504 p504 p509 b515 b- t564 p564 p564 p565 t566 p566 p566 p566;0ad6c6b08a1b27f9 +k1511;0;0 2;0;1;;t1 x1 t28 x0 t29 t30 x0 b29 p30 t31 t32 t33 t34 t35 x0 t36 t86 t88 t89 t90 t91 t92 t93 b91;917c7d02b3b930aa +k1544;1;0 0 0 0;0;2 3;;y s0:1 t2 s0:2 t3 s0:1,2:1 t4 t5 t6 p7 b- t8 p8 p8 p11 t12 p13 t14 p15 t40 p43 t44 p74 p77 y x3 b79 y t78 p80 p85 y t86 p86 p87 t88 p88 p89 t90 p91 w3 s2:1,0:2,6:2,2:1,1:1,4:3 s1:2,0:1,1:2,3:1 t92 p93 p97 p98 p102 p102 p102 p102 p107 t108 p109 p109 p110 p110 p110 p111 p113 t117 p118 p118 p118 p119 t179 y t180 p180 p181 p182 p184 p184 p184 p184 p185 t186 p186 p186 p190;bc33d8b6994c9b55 +k1555;5;0;0;;;b7 p5 p5 p5 p5 p5 p5 p5 p6 p6 p6 p10 y y t11 t14;98bf769421ebd6eb +k1561;5;0 1;0;1;;t6 s1:1,1:1,0:1 t7 t8 s1:1,0:6 t11 b11 p12 w1 b12 p12 w0 t13 y t14 y t18 b- p19 p19 p20 p21 p21 p21;646f687f26a9c28d +k1570;3;0 0 3;0;1;2@10;t4 t5 x2 s3:2,2:3,3:6,1:1,0:190,2:2,0:2,3:1,2:1,2:3,3:1,4:1,2:2,0:8,2:1,1:3 t6 s0:1 t7 t8 t9 y t10 t12 t13 t18 t19 b20;77fa6a4fa6cbb722 +k1571;0;0 0 0 0 1 0 1;0;2 6;3@5 1@-;x2 b5 b5 p3 p3 p3 p4 p4 p6 x2 b- y t7 x3 t8 y b14 b7 p8 t9 t10 t11 t15 t16;6fcf08cb8ed10d2a +k1596;3;0 0 0 0 1 0 0 1 1 0;0;1 6 4 8 9 7;5@1 2@1;s1:2,1:1,0:2 b6 t7 y t8 y t9 t10 y s1:1,0:2 t26 t27 t28 b- t29 t30 t33 t34 w4 t35 s0:5,1:2 t36 t39 t42;0fc52fe98d5bab04 +k1598;107;0 1 1 1 0 0 1;0;2 1;4@106 5@-;t108 s0:2 y x5 t109 y y x0 x6 t111 w3 t112 x6 t115 s1:1,0:3 t116 y x5 w5 b114 t121 s1:1 x1 b119 t122 y b- t123 t124 t125 s1:3,2:148 y t126 t127 s1:66 x5 t128 t133 w1 w2 t136 t137 w0 x2 s1:2,1:3,1:2,1:2,5:1,0:2 x6 t139 t140;16bc011809fd149d +k1602;0;0 2 0 2;0;1 2;3@6;b2 s0:1 t1 s1:1,0:1,1:1,4:1,2:1,0:1,1:2,2:1,0:3 t2 s0:1,2:1 t3 t4 y y y x3 y t5 s2:3,0:1 s2:1,0:1,0:1 t6 b11 t7 x1 s1:1,2:1 y x0 x1 y y t8 t9 p9 p9 p9 p10;c16a4a146b116a34 +k1617;4;0 1 0 0 1 1 0 1;0;4 6 1 5 3;;w4 s1:1,0:2 t5 t9 y t10 t14 w2 b- t15 t16 t17 w3 s1:193,0:2 w3 b22 s0:2,1:3 t18 y w0 t19 t21 y t22 t23 t26 b29 t30 s0:1,0:1 t31 t32 t33;8de671031ee95dae +k1638;0;0 0 0 0 0 0 1;0;4 2 5;3@3 1@-;w1 t1 w3 t2 t3 b2 w0 t6 w5 t7 x4 w1 t10 x0 w0 t13 t14 x0 w2 t16 t17 b22 y t18 s0:1,1:1 t19 t20 t21 p22 b20 t59 p60 y w3 x3 w6 w1 w2 t61 p61 p65 p66 x1 w2 w1 t67 p71 p108;0daba4930d73ba03 +k1643;1;0 1 2 2;0;1 2;3@5;t5 t9 t10 t12 x2 w3 x3 t13 w0 s2:1,0:1 w3 w2 w1 t14 t15 y w2 t16 t17 b20 s2:1,0:2,0:1,0:2 w3 t18 s0:7 s0:1,1:2 t19 s0:175,2:1 s2:1,2:1 t20 t21 b- s2:1 w3 t22 w0 t23 t24 s2:1,1:171 t25 t26 w2 b25 s2:1,1:1 s2:1,0:1 t27 t28 t29 t32;76b570f807dfa5ba +k1650;2;0 1 0 0;0;3;;b- b2 p2 t4 t5 t9 b14 p10 p10 p11 p12 p13 p13 p13 p13 p18;338e0bf662e70e2e +k1651;0;0 3;0;;;t1 t3 x1 x1 b3 p3 t4 t7 b6 p8 x1 y y t9 t10 b10 p11 b- p16 p16 p16 p19 p19 p20;409eec3a999380ce +k1669;261;0 3 2 2 2 0 1 3 3;0;7 2 1 3 5 4;6@263 8@-;t262 t265 t266 t267 t268 t269 t274 t275 y t276 t277 t278 w8 w3 y t279 t280 t284 t285 b291 t286 t291 t293 t294 t295 w6 t298 s0:1,2:3,1:2,1:1 s1:3,0:2 t299 s1:3,3:1,0:2 s3:2,2:1,0:1,3:1,3:1,7:1,2:6 t300 t301 t302 y t303 t304 y t305 t335 t340 t341 b339 x6 t342 t347 t351 t352 y t353 y w8 t354 w8 s3:1,3:2 t355 b361 t356 t357 t358 t359 w8 t360 t363 t364 y t365 b369 b365 t367 t368 t369 t373 t374 t375 x2 t376 t424 t425;40458c44dd3fa9c0 +k1703;3;0 2 0 0 1 1 1 1 3 0;0;5 6 2 9 4;7@- 3@- 1@-;b8 b3 b9 p5 b8 p6 p6 p7 p7 p7 p7 p7 p7 p8 b10 y x7 s0:1 b6 p11 t12 x1 b- x4 t16 w2 b- b- b17 p21 x1 t22 b21 p22;30986f888827d262 +k1715;2;0 1 0;0;2;1@-;t38 b- b43 p66 t70 b68 p71 b69 p72 b72 p72 b78 p72 p72 p72 p72;4fff8703e370d362 +k1721;4;0 2 1;0;1 2;;w2 w2 t5 b5 p5 t6 x2 w1 t7 t8 t12 s2:1,0:3,2:1,1:1 t13 t14 w2 t15 t18 w1 t19 w1 t20 w1 t21 w2;33cc53f31552051a +k1736;441;0 0 0 0 0 0;0;4 3 1 5;;t442 b- b443 b441 b443 y y y w4 s0:3,0:1 s0:2,0:2 b- b447 p443 w4 s0:1,0:4 s0:1,0:1 b442 y b442 x4 b449 p443 b-;a774b5b6d5d3f5b4 +k1760;567;0 0 0 1 0 3 1 2 2;0;2 7 4 5 8;6@569 1@566;t593 s2:2,0:1,0:3,2:1,2:1,0:1,3:3,0:1,2:2,4:7,1:1,0:1,4:228,1:1,3:3 t594 b593 b596 t595 w2 t596 x4 b597 t597 t598 t599 b599 x2 x6;27f3156a268ad049 +k1764;966;0 1 1 2 1 0 1 0 2;0;4 7 3 8 6;5@964 1@973;s0:2,1:1,0:1,2:2 t967 s0:1,1:1 t968 s2:1,0:1 t969 t970 b- b970 p1015 b1019 b1017 t1017 b1022 t1018 y w3 t1019 t1020 t1021 w2 t1022 b1023 y t1023 t1024 b1025 y y t1025 y y s0:1,2:1 b1031 y b1024 y y y t1026 y t1027 b- y t1028 b1030;69e5116881fc3840 +k1793;0;0 3 3 0 2 1 2 0;0;2;6@- 7@8 3@2 1@1;x6 w6 b6 p0 p0 p0 p15 t16 x7 x1 t17 s3:1,0:2,1:1 b22 x1 w6 x0 t21 s0:3,3:2 y t22 p24 x5 t25 b- t26 t27 x0 y t28 y x0 t31 w2 y t32 t33 t34 b39 b32 x4 t35 b38 x6 t36 t37 t39 t40 t41;f7a17fb3442f391b +k1795;515;0 1 1 1 1 1 1;0;5 6 1;2@- 4@515 3@515;t518 b523 p518 p518 p519 p520 p520 p520 p523 w3 b521 p523 t524 b522 p524 y;9ba7c2a495f2205f +k1850;0;0;0;;;b- p41 p42 p42 p43 p43 p46 p66 p71 p72 p72 p73 p73 p74 p74 p75;6c9f49d374dd55f2 +k1851;0;0 2 0 2 0;0;2;3@- 4@7;t1 y t5 b- y y s0:1,1:2,2:2 x3 b- p6 p7 b6 p7 t8 p8 p8 p9 p9 p9 p10 y t11 y t12;0abcae6a6b6bceae +k1940;0;0 0 0 0 0 0 0 0;0;2 4;6@6 1@- 3@6 7@- 5@6;x3 b- b4 b3 p0 p1 p1 p1 p1 p5 t6 t46 b- b48 b48 t47;98421d426d1c2cd2 +k1960;0;0 1;0;;1@6;w0 w0 b- p1 p6 p9 p10 p11 p12 p12 p13 p13 p13 p63 p63 p64;0521829976ca9111 +k1985;0;0 1;0;1;;t1 t3 b- p4 p4 p4 p5 p6 p52 p52 p53 p57 p58 p58 p58 p59;f707752fa8f61781 +k1991;3;0 0;0;1;;t4 b8 b2 p4 b4 p4 t5 t6 w0 s2:2,0:1 t7 x1 t8 p9 p13 b18 t14 p19 t23 p23 p23 p24 p24 p24;5c63ec8387948663 +k1993;5;0 2 2 0 0 0 1;0;1 4 2;3@- 5@-;t6 y y t7 b6 s1:1,0:1 b- p8 t9 p9 p10 y t11 p12 t13 p13 p52 x3 t53 p54 t55 p55 p56 x6 t57 p58 t59 p60 t64 b65 p64 p64 p65 p65 p86 t87;9ebae392f61d4236 +k2022;0;0;0;;;s1:1,0:1 y x0 t1 t2 p5 t6 p6 p6 p6 p6 p6 p7 s0:3,1:1,1:1,1:2 t13 p13 p14 p19 p20 p25 t26 p26 p27 p27 p28 p30 y t31 t32 s0:1,6:2,0:1 t33 p34;0647dd8ce4f920a7 +k2036;3;0 0;0;1;;t4 w0 s0:1,7:1,0:2,2:1 s1:3,1:3,6:2,1:1,1:1,2:1,1:1,0:2,6:1,1:1 b2 t17 p17 p18 t19 y y t20 p21 p26 p27 p27 p31 p34 y t35 s1:1,0:3 s1:1,0:1 y b-;8f3a470698b6b6c6 +k2040;4;0 1 2 3 3 0 3 3 1;0;7 4 2 6 1;3@7 5@-;t5 t6 b4 p6 t7 t8 t12 b15 p13 p13 p14 p71 t72 s0:1 s0:2 t73;bd2fa1f3a47c6c5e +k2045;0;0;0;;;y t1 y t2 t7 b- p20 p25 p25 p25 p44 p44 p45 p47 p47 p47;e7c3e2759dc473b6 +k2100;4;0 0;0;1;;b- t5 b- p10 p11 p12 p13 p13 p17 p18 p18 p18 p18 p18 p19 p23;117a8a5ef8ecbf9c +k2106;0;0 0 0 0 0 0 0 0 0;0;8 7 1 2 3;6@-;t1 w5 w3 t2 w1 s4:1,0:1 s4:1,1:3,0:1 w5 t3 b9 t4 p5 p5 p5 p5 p6 p7 p8 y s0:1,2:1 t9 p10 t11 p12;19f3586d1f95d4a9 +k2136;4;0 0 0 0 0 0 0 0;0;4 3 1;5@11 2@8 6@9;t5 t6 b- b- s0:2,1:2,2:1 b6 t7 b- b- p43 b44 t101 p101 p102 p103 b103 b101 b- p137 p137 p143 b- b148 p143;c5d5bbdd6a3ad7de +k2147;0;0 3 2 1 2 0 1 1;0;4 3 6 7;1@4 5@-;t1 b7 p1 p2 p2 p2 p2 p3 p3 p3 p4 p5 p5 p6 p6 p7 b- p8 p8 p9 p45 p47 p48 p48 p50 p54 p55 p60 p61 p65 p67 p68;f14bf14f5c1a82ce +k2155;0;0 1;0;1;;t4 b10 p4 p4 p5 p5 p5 p5 p5 p5 p5 p5 p5 p8 p8 p8;84f25b760614c94f +k2162;104;0 1 1 1 0 1 1 0 1;0;7 1 3;8@- 2@106;w6 y w3 w3 b105 w7 t106 w5 b- b104 p106 t162 y t163 b161 p163 b167 p163 p163 p163 p163 p164 p165 p165 p165 p165 p165 p166 p168 t169 w0 t170;295c64684d328557 +k2165;1;0 0 2;0;1;;t4 t5 b6 t6 t7 w2 y t8 s2:2,2:2,0:2 y t13 p17 p17 p17 p18 p18;0cc4f66de7b74f78 +k2180;5;0 3 1 1;0;1 3;;b5 p5 b- p6 p7 p53 p53 p53 p53 p54 p54 p55 p55 p55 p55 p55;006981835dfef0c7 +k2210;3;0 0 1;0;1;2@2;t4 b3 s1:3,6:2,1:3,0:77 b6 p4 s0:8,0:2,0:1 y t6 t7 t8 b10 t9 b13 p11 t14 w0;9f8adb6856f706b0 +k2218;0;0 3 1 1 2 2 3 1 1;0;1 6 3 7 8 2 5;4@7;t1 w1 t2 w6 t3 b4 p3 p3 p3 p3 p3 p4 t9 t10 w0 y t11 t12 t17 t18 b16 p18 b23 p18 p18 p18 p18 p18 p18 p18 p72 t73 t74 b72 p74 b- p74 p75 p75 p75 p75 p75 p76 p76 p76 p76 p76 p78;276c46747539fde5 +k2225;0;0 1 1 1 0 0 0 1 1;0;1 7 6 2;8@-;s1:2,0:1 t1 s0:1 t2 t5 t6 s1:2,6:8,0:2 t7 x3 s0:1,0:3,0:1,0:1 s0:1 s2:3,0:1 t8 s1:1,0:1,1:3,1:1 w5 s1:1,0:3;0d19e844879fa81a +k2235;3;0 1;0;;1@7;t4 s0:8,1:152 w0 t7 s1:2,0:2 t8 s3:1,1:8,0:7 t9 s0:62 t10 t11 t12 s3:1,0:1,4:1,1:1,1:1,0:153,1:3,1:3,0:1 t13 y s0:1,1:3,0:4;573697f657b0da0b +k2242;5;0 0 0;0;;1@11 2@6;x0 b5 p5 b4 p7 b7 t66 t67 t69 t70 y y t71 t72 t73 t74 b73 b- b75 p74 b80 p75 t76 t79 b- p79 p80 b84 p81 p81 p81 p82;6666894876501e30 +k2275;0;0;0;;;t2 x0 b- p3 p3 p3 p3 p3 p4 p8 p9 p10 p10 p11 p11 p11;859b8895aa1f4ba9 +k2287;0;0 0 0 0 0 1 1 0 0 0;0;3 8 6 2 4 5;9@- 1@-;y t1 t2 t3 t6 t7 t10 t11 b12 t12 s0:7,6:1,0:2,0:2 b14 t13 b13 s0:1 b12 b- t14 t19 w3 t23 b- s0:1 t24 w8 t25 b25 t26 b28 w9 b29 t43;e335cf62f6b84598 +k2298;0;0 1 3 2 1 3;0;5;4@- 2@3 1@-;t1 t2 t3 b3 p3 w4 s2:1,0:1 t7 p7 p7 p7 p7 p7 p7 p8 t9 p9 p14 w1 t15 p15 p16 x2 t17 p19 p20 t21 p21 p22 t23 p27 p27 p28 y w1 t29 p29 p29 p30 t31 p31 p31 p34 t36 s0:1,3:1,2:1,2:1 y y t37;6c4ef80ec1f7f9ba +k2302;0;0;0;;;t2 t3 t4 t47 t48 y y b54 p48 p49 p50 p51 p52 p53 p54 b52 p54 t55 t56 b56 p56 t57 t62 t65 t75 t76 t80 t81 t82 t94 y t95;98ed60b1fad14d85 +k2306;0;0 2;0;1;;t1 t2 y y b2 p2 t4 y y y y t5 t8 t9 y t62 t65 t66 w1 t68 t69 t70 b72 p70;0f52b8edf1889356 +k2307;0;0 0;0;;1@8;x1 b- p0 p1 p1 p5 p5 p5 p5 p5 p6 p7 p8 y t10 b- p49 p54 p55 p60 p63 p63 p63 p64 p65 p66 p66 p67 p67 p68 p69 p69;d662dee4b7106118 +k2315;0;0 1 0 1;0;3;;t1 b- p2 p2 p2 p2 p2 p2 p2 p19 p20 p20 p20 p21 p21 p22;6d9a18de434652f6 +k2321;0;0 0;0;1;;t4 w1 s0:1 t5 s1:1,0:2,1:1 x0 b3 t9 y w1 t10 p11 p11 p11 p12 t13 w0 b18 t14 p15 p15 p15 p16 b-;470cb632940d0fdd +k2326;4;0 0 1 1;0;3;1@4 2@2;w1 t5 t6 t7 t8 w3 x2 y t12 t13 t14 b19 y b20 p15 p32 t33 b35 t38 x0 t39 b43 b39 p39;313229028faea533 +k2345;0;0 2;0;1;;t1 t2 t3 b- p3 p3 p3 p3 p46 p47 p48 p48 p48 p48 p52 p52;23e0a9bd53a4299a +k2376;4;0 0;0;;;t5 x1 t6 t7 x1 w1 b5 p8 t9 w0 x0 x1 b9 p9 b7 p9 w0 t10 s1:6,0:1 t11 w1 t12 p12 p12;cc9c6643ac04c71a +k2385;0;0 0;0;1;;x1 b5 b4 p1 p1 p1 p1 p1 p2 p2 p2 p2 p3 p4 x0 t6;22f0ab12078a37b3 +k2395;0;0 0 0 3 3;0;2;4@7 1@-;y t1 t2 s5:2,0:1 t3 s0:2,2:2 t4 t5 t10 t18 x4 b- t19 p20 p20 p20;7358809ae4211d03 +k2404;0;0 0 0 0 0 0 0 0;0;3 2 1 7;4@- 5@-;t30 t31 t32 w7 t33 s0:1,0:1 y s6:2,0:1 b34 x0 t34 t35 p35 p35 p35 p36 p36 p36 p37 b- b42 t38 p38 p42 p42 p42 p43 t47 p48 p49 b- t50 p51 p52 t55 t56 p57 p58 w7 w3 x4;b1f2ddfba2f514e5 +k2420;0;0;0;;;b- p0 p1 p1 p1 p6 p6 p7 p7 p8 p8 p8 p9 p9 p9 p11;30c5a8b853bca715 +k2441;4;0 0;0;;1@3;x1 y b4 p4 y t5 y b- t7 y t10 y w0 w1 y y t14 s0:1,0:2 x0 y x1 y s0:1 s0:1,0:37;400042d584fb46f5 +k2455;4;0;0;;;b6 p4 p4 p8 t9 b- p9 p10 p11 p11 p11 p11 p16 p17 p18 p19;cdfb9d6378e98624 +k2472;3;0 1 1 1 0 1 0 0;0;2 1 7 4;5@- 3@7;t17 b- t20 t24 x5 s0:1,0:3,0:1,1:1,0:1,0:3,0:3,1:1 s0:6 t29 s0:2,1:1 t32 t33 t37 t38 s0:2,1:1 b- s0:2,2:2 s1:2,0:2,1:1 b36 p39 t40 s4:1,0:1,1:2,0:1 t41 t42 p42 p42 p46 b45 p46 b45 p46 s1:1,7:1,0:1;910221e0c600e65d +k2480;1;0 0;0;;;y y y x0 b- p2 p2 p7 p10 p14 p15 p16 p16 p16 p17 p17;d1c951e44a152b3a +k2490;0;0 0 0 0 0;0;3;;s0:1 w0 w4 s1:3,2:1,0:1 y s0:1,1:7,5:1 t1 t2 t3 p3 p4 p9 p11 y t14 p15;b0ba4487df16391e +k2515;0;0 1 1 2 2 0 0;0;5 6 4;3@- 1@-;b- y t1 b2 t2 b8 b2 p2 t3 b4 p4 b7 p4 p4 p5 p6;cb945c465bac9baf +k2539;0;0 1 0 1 0;0;1 2 3;;y s4:7,0:2 t2 p3 p46 y t47 p48 p48 p49 p53 p54 s0:2,1:1,1:3 y s0:2 x2 t88 b- y w2 y y t89 b95 t90 t91 t92 t93 t94 t95 t96 x1 t98 b- y y t103 t104 t159 t160;91a440ca1d59bf25 +k2560;1;0 0 0 1 1 1;0;3 2;;t2 t3 t4 x2 t5 y t6 t10 t11 t12 s1:1,0:1 t13 y t14 t15 t16;8fca446345cb6e6d +k2562;2;0 0 0 0;0;1 3;2@-;t7 t8 w3 t9 t10 y s2:1,0:229,2:2,0:2,2:2,2:1 s0:3,0:1 s0:2,2:1,1:1 y s0:1,2:3,1:1,2:2 x0 y t15 p16 p16 p17 p17 p22 p23 p23 p23 p24 p24 p24 p24 p25 p26 b26 y t31 p32;bf3c28597b64386d +k2570;5;0 0 0 0 1 0;0;5 1;2@12;t10 s3:81,2:1,1:1,0:3,3:1,0:1,0:2,0:1,1:1,1:1,2:2,1:1,0:1,4:1,1:1,5:1 t11 b11 b10 t12 p12 p12 p13 p13 p14 p14 p14 p14 p15 p15;97c407e60368b0bd +k2579;4;0 2 1 2 2 1 0 2 2;0;7 6 3 4;1@- 8@4 2@8;t5 t6 b6 s6:3,0:8,4:2 t7 y t8 p9 p9 p10 p10 p11 w5 b17 s2:7,0:2 t12 w6 w4 w0 w8 w1 w8 y t16 w1 y w4 w2 w2 t18 w3 t19 b19 y w8 w1 w4 w4 b25 w2 w2 w1 t20 t21 b20 w0 w6 t22 w5 y s1:1,2:3,0:2 b23 t23 t24 t25 y t29 b- w2 t30 w3 w2 t31 w2 t32 t33 b34 t34 w1 w6 w7 y t35 w8 t37 w7 t39 w1 t40 w3;57212ece123a21c8 +k2586;777;0 0 0 0 0 0 0;0;3;1@778 4@- 2@778 6@-;w6 b775 b- b- p778 b783 b784 w6 s0:7 t779 t782 y b- w4 s0:1,5:1 b- s0:1 w1 x5 t787 t791 s0:2 t792 t796;156668df5280bc94 +k2590;0;0 0 1 0 0 0 0;0;6;3@- 1@8 4@-;x6 b5 t1 x5 t3 x2 b1 p3 b6 p3 p3 p3 p3 p3 p3 p3;c9c508c106492f04 +k2597;994;0 0;0;1;;t995 b994 y s0:1 w1 w0 t996 b994 b997 p1000 t1005 w0 b1009 b1011 p1006 p1006 p1006 p1006 p1061 x0 b1060 b1065 p1066 t1067 t1068 b1068 b1066 p1068 b- y b- p1069;1213166947858717 +k2627;2;0 0 0 0 0;0;3 4 1;;w1 t5 b10 s6:1,0:2,0:2,7:1,7:1,0:211,1:1,1:1 s0:2,4:1,0:1,0:2,0:3,7:2,1:1,1:1,1:1,0:1,1:3,1:2 t6 s0:2 s0:1,1:1 t7 t8 w0 b10 t9 p14 b17 b14 t15 p16 t19 p59 p61 p61 p61 p61 p64 x2 b68 t65 p65 p69 p74 b72;33ac5e6ca1bcbd0a +k2645;937;0;0;;;w0 y t942 t943 t944 t945 t946 b945 p946 w0 t949 t950 t951 b950 p952 x0;0e0229b950d7702f +k2660;0;0;0;;;t4 t5 b- p6 p9 p9 p10 p10 p11 p11 p11 p15 p15 p18 p19 p19;4bc52e69116d171a +k2691;5;0 0 0 1 1 1 1 0 1 0;0;5 6 4 1 2;8@- 9@11 3@12 7@-;b5 b5 x3 t58 t62 t63 t64 t65 t66 s0:1 t67 w8 t93 b97 w1 w9 t98 x8 x0 t99 x9 s0:1 x7 s0:1,6:2,1:2;6abf593620a40a4d +k2722;0;0 0 0 0;0;;;s6:1,0:2 t1 w3 t47 p48 t53 p53 p53 p53 p54 t55 w1 t56 p56 p63 t67 t68 p68 p71 p76 t77 p77 p81 t82 y y t83 p83 p83 p84 b87 p84;72260403fe9e0fb4 +k2724;3;0 0 0 0 0 0 0;0;6 1 5 4;2@10;y b- b2 b1 t4 t5 t6 y y t7 t8 t9 s7:1,0:1 y t10 t11 p11 p12 y t13 p13 p16 y t17 p18 y t20 t21 p21 p22 s2:4,0:3,3:2 t23 p23 p24 p24 p48 w0 t49 p50 p54 p55 t56 s3:1,5:2,0:8 t57 b60 t59 p59 p59 p61 y b59 b- s2:1,0:2,0:8 s0:1,1:2 w1 t66 t68 p68 p68 p68 p72 t73 p74 p74 p74 p74 p74 p75 s0:2,1:2 y t80 p80 p85 t86 t87 p87 p87 p87 p88 p88;601c65aceb36887d +k2735;0;0 0 0 0;0;;1@4;b- p0 p1 p1 p1 p1 p2 p2 p2 p3 p3 p3 p3 p3 p5 x0;4ee7afe703a223ef +k2747;2;0 0;0;1;;t3 b4 b1 p4 t5 t6 t7 t10 x0 s0:3 t11 s0:3 b17 t12 b12 p12 t13 t14 b17 p14 p14 p14 p15 p18 t21 t22 t23 t24 y t25 t26 s5:3,0:3,1:1;837e34e4b3870acd +k2770;2;0 3 1 0 3;0;4 1;2@5;y w0 s0:3 b- p3 p5 p6 p6 p6 p7 p8 p8 p9 p9 p9 p11;83ed3650982cf812 +k2775;0;0 0 0 0;0;2;;t1 x2 t2 t3 w2 b5 t4 s1:1,0:1 w0 t5 y t6 p7 w3 t11 t12;209187408aea735b +k2780;4;0 0;0;1;;y y x1 t5 b3 s1:2,1:1,0:1 x1 y t6 y t7 p10 t11 p11 p13 p14;bc62e6270add6066 +k2820;2;0 0 0 0;0;1;2@6 3@-;s1:1,0:2 t3 t4 p39 t40 p41 t42 t43 p43 p43 p43 p43 p48 t49 p49 p49;8e73f605c671b08c +k2840;3;0 0 0;0;2;1@9;t4 b7 b4 p4 s0:2,1:1 s1:98,1:1,0:5 t5 t6 p6 p6 p7 p8 p10 p10 p10 p11;6c724ae8e86255bc +k2851;4;0;0;;;y t5 b4 p5 t6 w0 y t7 t8 t9 b- p9 p9 p10 p11 p12 p12 p12 p13 p17 p20 p21 p21 p21;58468e65a3b220bd +k2866;4;0;0;;;t5 t6 t7 t10 y x0 b11 p10 p10 p10 p15 t16 b14 p16 b20 p17 p18 p19 p19 p20 t21 t22 b25 p23;d66ca05677fe181e +k2876;0;0 0 0 0 2 1;0;4 3 5 1;2@-;x1 t1 t2 s2:1,0:1,2:2,1:1 w2 t3 t4 x2 t5 w2 t6 t10 t11 x1 t13 w2 t14 t15 t20 b26 t21 s4:1,2:1 t22 s2:2;23446d5cbb7b4ee1 +k2887;768;0 0 0 0 0 0 0;0;4 5 1;2@- 3@769 6@772;t773 b777 t774 b777 t775 t776 t777 b781 y y t778 w6 w2 t781 t786 t790 t791 t792 t794 t798 t799 b801 t800 t804 y b- y y y y t805 b811;b897da1542610063 +k2900;0;0;0;;;w0 x0 t1 b- p4 p4 p5 p5 p5 p5 p6 p6 p6 p7 p8 p8;ca98a0ee8b9c4030 +k2909;604;0 0 0 0;0;1;3@602 2@604;s3:2,0:3,1:2 y t605 w1 y b- b610 t606 p606 p609 w0 w2 t611 p614 p615 t616 t618 p620 p620 p621 p621 p624 y w2 y w2 s0:1,1:1 t625 p625 p625;160a927868a2794b +k2910;0;0 1;0;1;;b- p0 p1 p2 p2 p3 p4 p5 p5 p5 p6 p6 p6 p8 p8 p12;d60f5f2c274e0b66 +k2911;3;0 0 1 0 1 0 1 1;0;1 6;7@- 3@6 5@7 4@- 2@6;t5 b10 t6 x7 t8 t11 b17 t12 x2 b- t13 t14 w5 t19 x4 w1 t20 w7 x0 y w7 t21 t22 b23;a254df4dd5a93530 +k2912;0;0 2 0 2 3;0;1;2@6;x2 x3 t5 t7 y t8 y s2:1,2:1,0:2 s2:1,0:2 t9 b- y t10 t11 t12 t13 t14 t15 y t16 x2 t17 t18 t21 t22 t23 t24 b22 t25 t26 y t27;6c4fa8412f19df14 +k2951;5;0 0 0 0 0 0 0 0 0;0;7 5 3 6 8;2@7 1@3;t6 b8 t7 x3 b13 w0 s0:1,1:1,1:3,0:1 t12 p12 p12 p12 p12 p13 p13 p14 w4 x2 t15 t16 p26 b32 t27 b30 t28;4b4abb7935d9d078 +k2961;3;0 1 1;0;1 2;;w2 w1 b2 p3 w1 b6 p3 p4 p63 b- p64 p65 p66 p67 p67 p68 p68 p69 p69 p69 p74 p75 p76 p77;858c12786d6f4569 +k2975;0;0 1 1;0;2;1@3;s0:1 t2 b- p2 p2 p2 p3 p3 p3 p4 p5 p10 p11 p12 p12 p12;9867656f9ff08c30 +p0;0;0 1;0;1;;t4 w1 w0 y w1 b7 p4 p4 p4 p4 p4 p4 p4 p4 p5 p5;9643325498614604 +p1;866;0 0 0 0 0;0;2 3;4@872;p866 t867 p867 s0:1,0:102 t868 t869 t871 x1 w4 w3 t872 t873 t874 t875 x2 b881 s0:3 t876 p876 y w3 b876 w4 y;ddc7ec3ca064b2f0 +p3;0;0 1;0;1;;w0 b- p1 p4 p5 p44 p45 p46 p47 p49 p49 p50 p54 p55 p55 p55 p55 p56 p59 p59 p60 p60 p64 p64 p69 p69 p74 p74 p76 p78 p78;bf52c5c027ec62e5 +p4;0;0 2 0 1 1 1 1;0;1 2;5@8 4@-;y t1 y t2 t3 s1:2,0:1 t4 s0:1 t5 t6 b- p7 t8 t9 t11 t15 x5 t16 y t17 t18 x4 y t22 t23 t24 y x0 t28 b32 p29 p29 p30 p31;ee267895f1794044 +p5;0;0 0 1;0;1;;w1 p0 t1 p1 t2 t3 b- w0 w1 b6 t7 b- t8 y b12 p8;5d9adfb57f283fdf +p6;5;0 2 2 0 1 2 0 1 2;0;2 4 6 7 5 3;;t6 t9 t10 t11 s1:8,0:2,1:3 t12 t13 t14 t15 t16 t17 t18 x5 t22 t23 t24 t28 t29 t30 t31 t32 t33 s0:1,0:1,1:3 t34;0df2a92abfbc27dc +p7;2;0;0;;;p2 p3 t6 s0:1 t7 w0 t8 t10 t11 w0 t12 t13 x0 t14 t15 t16 p20 t21 t22 t23 b21 p23 t27 t28 w0 t29 t30 t33 p33 t34 t35 s1:1,7:1,0:1;b44246eba2a348e8 +p9;2;0 0 0 0 0 0;0;4 1 3;2@- 5@-;w0 s0:4,1:3,1:1 t3 s0:1 t4 s0:1,0:1,0:1,0:1,0:1,0:2,0:2,0:1,0:2,0:3,0:3,0:2 t5 t6 t7 t8 t9 t10 s0:3 w2 w5 t12 s0:226,2:128 t13 s0:2 t14 s0:3,2:2 t15 t16 x3 w5 t17 s0:2,7:168,2:1,6:3 t18 s0:1 t19 p19 p19 p24 w4 t25 t26 t28 s1:2,0:1,2:129 t29 w4 w4 w0 w4 s0:1,2:1 w0 t30 t31 t32 p33 b- x1 s4:2,0:1,1:3,2:3,2:1,1:2 t34 p35 p36 p37 w4 t38 p39 p40 p40 p40 p41 p42 p42 p45 p45 p46 p46 p46 p46 p46 p46 p46 p47;daa4b1b0e88c96c7 +p10;0;0 1;0;;1@-;b- p1 p1 p1 p15 p15 p16 p16 p17 p17 p18 p18 p19 p19 p19 p19;d2870645530de966 +p11;0;0 0 0 0 0;0;1 3;;t1 s3:5,0:2,3:1 y s1:2,0:20,2:1 b1 t2 t4 p4 p4 p5 t6 s0:1 s0:1,1:6,1:1 t7 s6:7,0:7,1:5,1:5,7:133,6:2,1:3,0:2,0:1,1:3,1:4,2:8,1:1,2:1,0:1,0:1 s0:1,1:3 t8 t9 s0:1,1:4,0:1,1:1,3:1,0:2,2:2,1:3,2:128,7:1,1:1,0:1,4:1,7:3 s0:6 t10 p11 t12 t14;e927e846dc2f6ad6 +p12;0;0 0 0 0 0;0;1;3@1 2@3 4@-;w3 t1 t2 t3 y t4 t5 t6 t7 x1 t8 t9 p9 b- t10 t11 x3 b16 t13 y t16 s2:3,1:1,1:2,0:2,3:1,1:2,2:244,0:1,3:1,0:2,2:42,1:3,2:1 b16 y b17 t17 t18 p18 p18 p19 p19 p19;ebc0018b3ea946ef +p13;0;0 1 0 1 2;0;4 1;3@6;p4 w1 t6 t27 t28 p77 y w1 t78 s0:1 s0:2 t79 t80 p80 t81 t82 y x3 s1:2,0:1 t114 t116 x4 t117 w4 p121 t122 s0:2,0:1 x2 t123 w3 t124 t125 w0 p125 t126 p126;b9dbcdcb18addf5b +p14;0;0 2 0 2 0 3 2 1;0;3 4 1 2;7@6 6@2;t1 x6 t2 t3 s0:1,1:1 t4 s1:237,7:1,3:3,6:1,1:1,0:2,2:3,3:1,0:8,1:1,3:1,1:116,4:1,0:1 t5 t6 t7 s1:2 s2:1,1:1,3:1 t8 t9 w0 b8 t10 x3 t11 p69 s3:6,2:7 s2:3 t70 s1:2,0:1 s0:2,3:1,2:2,0:1,3:1,1:1,1:5,0:1,7:1,2:1,0:1 t71 p72 t73 y y t74 p74 p75 y p76 y t81 y t82 t83 w5 t84 t85 t89 t90 w1 t91 p92 t93;5e750f24adf22589 +p15;0;0 1 1 0 0 0 1 0 0 0;0;1 2 7 4 5 9 6 3;;b- t1 b2 b- s1:3,0:1 s0:2 t2 t3 y s0:2,1:2,3:3,0:2 t7 p8 t9 p10 p10 p10;4e719a2da249a7df +p16;0;0 1 1 0;0;3 2;1@1;t1 t3 x1 s1:2,0:1 t4 s4:2,0:3,0:1 t5 x2 s0:1,0:3,1:1,0:1,0:1 t6 s0:1,5:2 t7 s0:2 t8 t9 y x1 y y x0 y t10 s3:1,0:1 t11;04e0b9c867d358e0 +p17;0;0 1 2;0;1;2@3;t1 t2 t3 t4 t6 t7 w0 t8 s0:1,3:1,1:2,2:2,1:8,0:1,2:1,2:1 w2 p9 s0:1 y b15 p10 p15 t16 y t17 t18 s0:1 t19 s0:3 t20 t21 t26 p27 t28 y t29 w2 b27;52c9f1ace27a00c2 +p18;1;0 1 1 1 0;0;2;4@3 3@1;t2 b5 p2 p2 p2 p4 w1 t5 t6 w3 t7 y s1:2,0:1 w2 w1 t8 t9 w2 w2 s0:2,1:1 t10 t13 t14 p15 t16 x2 t17 t18 p18 b17 w0 x3 p18 b16 t23 p24 y s0:1 p25 t27 x3 b30 t28 t29 p29 w1 t30 t31;6e3c3231a4e128a7 +p19;0;0 3 0 0 0 3 3 1 2 2;0;1 5 6 3 7;4@1 8@-;w7 p0 t1 t2 t3 t4 t6 t11 t12 w3 p12 p12 t13 x8 y w9 w5 t14 t15 t18 t19 t24 b- p28 t29 t31 t32 t33 t37 t38 y t39 t40 t41 w9 w0 b41 y t42 t43 t44 t45 p48 p48 t50 y t51 b56 x1 t56 t61 x6 t63 t64 s0:2,3:1 b- t68 t72 x1 b- t73 t74 t75 p76 t77 t78 b80 p79 p79;3848aad6e6d65ce7 +p20;0;0 0 1 1 0 1;0;3 1;2@- 5@1;t1 t2 s0:1,1:2,1:1,1:2 t3 x2 t6 t7 w0 t8 t9 p12 t17 x2 w4 w5 w1;c3483d4118fb4ec5 +p21;4;0;0;;;x0 t5 t6 t7 t8 t9 t11 t12 y t13 t17 b15 p20 t21 t24 b29 p24 p24 p24 p24 p26 p27 p27 p28;359b8f53de0785da +p23;0;0 0 2 1 0 1;0;4;1@-;b- y t1 t2 t3 b7 p4 p8 t10 t11 p12 s0:1 t16 t17 y p18 y b17 p18 t20 y t25 t26 s2:1,0:1 s0:1,1:1 s0:1 t29 b34 p29 p30 p30 p34 s0:144,2:2 s0:1 p34 y s1:1,0:1,0:3 s0:1 t35 t36 y t37 p38 t39 y t40 y t41;97df0e7bd808563e +p24;0;0 0 0 0;0;2;;t1 b- t2 t3 t4 t5 b- p5 p9 p9 p10 p13 p14 p14 p15 p16 p16 p17 p17 p18 p18 p18 p19 p20 p21 p21 p21 p21 p22 p23 p24 p24 p24 p24 p24 p24 p28 p28 p29 p29 p30 p30 p30 p30 p30 p30 p31 p31 p31 p35 p35 p36 p37 p38 p43 p44 p44 p48 p49 p53 p54 p54 p54 p89 p90 p90 p90 p91 p96 p103 p103 p103 p105 p105 p107 p107 p108 p109 p109 p113;72affa0b1fc3cf5d +p25;0;0 3;0;1;;t1 y t3 p4 t5 s0:1,1:1 y t8 p11 t61 p61 w0 x1 t62 p66 p67;a736b3295cf5e343 +p26;3;0 0 2 3 2 2 0 1 1;0;5 8 1;7@11 2@7;w4 t4 t5 t9 t10 t11 t12 t13 t15 w5 w3 t16 b18 t17 x2 t18 t19 w2 s3:1,0:1 s0:2,5:2 t20 s0:4,3:1,3:2 s0:1 t21;112d6d41aab5d216 +p27;0;0;0;;;w0 y y y p0 t1 y t2 t7 b10 p11 s0:1,7:2 t12 s0:1 t13 t14 y y y p14 t15 t16 t17 t18 p72 t73 y s1:2,0:1 s0:1 t95 y t121;93114bb33535613e +p28;832;0 1 2 2 1 1 1 2;0;1 5 3;6@835 7@- 4@839;t833 t836 p836 t837 t838 t839 t840 t841 t842 t846 t847 t848 t849 t850 y t855 y b853 p880 s0:2 y p881 y y b- p881 p882 p883 p884 p885 p885 p885 p885 p886;8374c4d39c9a5931 +p29;3;0 0 0 0 0 0;0;5;4@11 1@- 3@3;x2 t4 y t5 s0:3,1:1 s1:1,1:1,1:1,0:8 x3 t10 b- y b14 b12 p12 t13 t14 p14 t15 p15 t16 y t17 x4 s0:1,0:8 t18 p18 p22 t26 t29 t32 s1:2,0:1 y x5 t33 t34 p34 p34 p52 p52 p52 p52 p52 p53 p53 p53 p55 p55 p55 p55 p56 p57 y t58 p58 p58 p59 p60 s0:2,0:3,0:3 w3 w3 s0:2 s0:2;14b88696acf6b7cf +p31;0;0 2 1 0;0;3 1;;y t3 x1 t4 y y y t6 x3 t7 y y w3 y t9 p9 w1 t10 t11 t12 y p13 t14 w0;f1705cae812b6d1e +p32;5;0 1 1 0 0 0 1;0;1 5 2 4;3@-;b5 y p5 t6 t8 t12 y y y p13 p16 w3 t18 p18 b24 y t21 t22 y b- y t23 b26 t24 p24 y t25 b29 b28 p25 p25 p25;65143d58d63332d2 +p34;0;0 0 0;0;;2@-;t21 p22 x2 b24 p22 p22 p22 p23 p24 y p24 t25 t70 t71 t76 t77 t78 y t79 y t80 b86 p85 p85 p86 t87 b- p87 p88 p91 p91 p92 p92 p93 p94 p95 p95 p95 p96 p96 p97 p100 p100 p103 p103 p104 p164 p164 p164 p164 p175 p175 p175 p175 p177 p220 p220 p220 p220 p220 p223 p223 p223 p223 p224 p224 p225 p226 p226 p227 p227 p227 p227 p230 p230 p230 p230 p231 p232 p267;16c5cd896accd0c4 +p35;264;0 1 0 0;0;2;3@271 1@262;p264 b- p268 w2 t269 t270 p274 s6:1,0:1 t275 p275 b- t276 p276 p276 p277 p278;496046b5b57497c2 +p36;0;0 1;0;;1@3;t1 s0:6,1:1 b7 p2 p3 p3 p3 p4 p4 p4 p4 p5 p6 p7 t8 s0:1 s0:3 p9 t10 p10 t11 x0 t12 t13;27d75974510bb840 +p37;1;0 2;0;;1@3;t2 t3 t4 p4 b6 p5 p7 w1 s3:1,0:2 t8 s0:2,3:1 s5:2,0:1 b8 p8 s3:2,3:1,3:6,0:1,1:2,1:1 t9 w0 t10 p11 p12 p64 p68 p69 p70 p71 w1 t73 p74 p79 p87 p91 p92;7075283eb7b970fa +p38;5;0 1 2 1 0 0 1;0;4 5 3;6@- 1@- 2@9;t6 b9 y b7 t7 t11 t16 b- t17 b18 t18 t46 b47 b- p46 p46 p49 t50 b50 p50 b48 p51 w5 t53 t54 x4 x1 t55 b55 s3:1,3:2,3:2,0:2,3:1,3:1 b60 p55 t58 p61 p66 p67 p68 p68 p69 p69 p71 t75 p78 p79 p79 p80 b82 b-;7bf9095842001f93 +p41;3;0 2 0 0;0;3;1@-;x3 b- t4 y t5 w0 t6 y w0 t7 x1 t8 t11 b- s4:2,0:1,3:6 w3 b17 t14 p15 w0 t16 p16 p17 p18;6b7f9e10a93221e4 +p42;1;0 0 0 0 0;0;2 3 4;;t5 w2 p6 b- p6 b9 b9 t7 b10 p8 p10 t11 s0:1 b13 b13 t12 b- p12 p13 y t17 s0:1,0:2 s0:31,6:2,0:5,6:2 t18 s0:7,1:2 s0:3,0:1,0:2,7:1 t19 t20 t21 t22 t23;73aa5a1e2beadf7d +p43;3;0 0 3 2;0;3;;w0 x1 x0 t50 s0:2,4:3 s0:2,6:2 p55 p55 p56 p59 p59 p63 p68 t78 p78 p79 p79 p80 s0:1 t81 b81 p82 s5:8,4:2,1:1,2:3,3:3,0:1,1:1,1:1,1:1,1:2,3:2,1:1,1:3 w3 s0:1 w1 s0:3,0:2,0:1 s2:1,0:1,1:1,3:2 x1 p82 b88 p82 p83 p84 s1:1,2:12,2:4 w2 t85 p88 w3 w0 y s2:2,1:8,1:2,1:1 b- p88 p91 p91 p91 p91;e706ceb2146257b5 +p44;3;0 2;0;1;;t4 t7 t8 x1 t9 y s0:1,0:7 b11 p10 p11 s0:1,2:3 t12 s0:2,1:3 t13 s0:2,5:1 t14 t15 w0 s0:1,1:2,5:135,5:1 b- p16 p16 p16 p16 p16 p17 p17 p17 p17 p18 p19 p19 p19 p22 p22 p22 p22 p22 p23 p24 p25 p29 p33 p33 p33 p38 p38 p38 p38 p42 p46 p49 p49 p49 p60 p60 p62 p62 p62 p62 p62 p66 p67 p67 p68 p72 p77 p77 p77 p77 p78 p79 p84 p84 p86 p89 p94 p94 p94 p94;222a0c8a803ea41e +p46;0;0 0 2 0;0;2 3;1@6;t1 t5 t6 t7 b7 t12 b13 p12 x0 b- x1 y b18 p12 p12 p12 p13 p13 s0:1 s0:2,1:2,0:1,6:2,1:1,0:1,1:3,0:1,1:3,1:1,0:144,2:2,1:2,1:2,1:1 t14 s0:2,5:1 s0:3,2:2 t15;cc7b64c6c3fa0f81 +p47;3;0 0 2 2 0 0 0;0;4;1@2 5@- 6@-;p4 s0:3 t7 s0:1,0:1,2:1,0:3 s0:1 s0:1,1:3,1:1,1:1 p7 y t12 p12 p12 p12 p12 p56 p57 s1:3,0:2 b- t58 p59 p59 p60 p61 p62 p63 w0 p63 t64 p64 p76 p76 p77 t78;ec499ed64623c92e +p48;4;0 1 0;0;2;1@2;y t5 p6 w1 p7 p8 t9 p26 y t27 w1 y b25 p28 t30 s1:3,0:1,1:2,0:1 y w0 t32 t33 p37 p38 y x0 s0:2 y t39 t42 t45 t46 t47 p48 w2 s0:3 p48 t49 s1:1,1:1,0:4 y x0 t50 t51 p52;dfadb7530b7b02b9 +p50;0;0 2 2 2;0;3 2 1;;y s0:1,0:3,0:2 p0 t2 y t3 p3 y t4 s2:2,0:5 p5 s0:1 t6 w1 b- p10;b78d969bafda879b +p51;0;0 2 2 1;0;3 2;1@2;b5 p0 p5 t6 t7 w3 b8 p8 s2:1,2:2,0:1,2:3 t9 s0:1,2:2 s2:3,0:3 s0:1 t10 b- p11 p11 p11 p11 p12 p12 p13 p13 p13;063c307345ac7821 +p52;0;0 0 3 0;0;3;1@-;t1 x2 t51 b53 t52 b55 p52 p57 b- p57 t94 t95 y y s0:238,2:3 t96 s2:1,0:1 t97 t98 p99 t100 p100 p100 p105 t106 p106 p106 p106 p106 p107 t108 p108;173455b3173d4293 +p53;0;0 0;0;;1@-;t1 t2 t3 s5:3,0:1,0:3,1:2,0:2,4:1 b8 p3 p5 p5 p7 p8 b- p8 p8 p9 p11 p12 p12 p12 p34 p35 p36 p37 p42 p42 p42 p42 p43 p44 p46 p47 p52 p52 p52 p53 p53 p68 p68 p69 p69 p69 p69 p69 p69 p70 p71 p71 p96 p96;768ff1681e41ca85 +p55;0;0 0 1;0;1;2@-;w0 y t1 y y w1 w1 t2 y w2 y y w0 w1 x2 w0;fb74db9ac0f2aed4 +p56;0;0;0;;;t1 t3 t4 t6 t7 t8 t9 t10 w0 x0 y t11 y s0:2,1:1,0:7,1:186,1:1,0:2,1:1,1:2,0:1,1:7,1:2,0:1,1:1,1:1,0:169 s0:1,7:1,1:1 x0 t12 w0 t15 p15 p15 p16 y t17;79f17e4b49a8391a +p57;71;0 0 0 0 0 0 0 0 0;0;1;5@- 7@79 6@-;t72 t73 s1:1,0:2,0:1,0:1,0:1,0:3,0:1,0:1,0:1,0:1,6:1,0:1 y b74 b- p73 p73 p74 w6 b75 x5 p74 w4 x7 b- p74 p74 p74 p78 t79 t80 t81 x3 w2 y p81 b83 x7 t82 p83 s0:1;35be16a61dbc6ca7 +p58;0;0 1 0 0 2;0;;3@-;s2:2,5:2,0:3 t1 t2 p3 p6 t9 p12 p13 b13 p14 b14 p16 p16 p16 p16 p16 p16 p17 p17 p19 p24 p27 b27 p27 s2:1,0:1 w3 t28 t29 p29 p29 p29 p29 p33 p37 p37 p53 p53 p54 w0 t55 p55 p55 p55 p55 p55 p98 b97 b97;7e525c9158842828 +p59;0;0 0 0 0 0 0;0;4 1 3 2;5@-;t5 b10 w2 s0:1,0:1 t6 s3:1,0:2,0:229,7:1 t7 s0:7,0:2,0:1,0:1,6:1,7:1,0:2,6:2,0:3,0:2,1:2,0:2,0:3,0:1,0:1 t8 t9 w5 t10 t11 t12 s0:4,4:1,0:1 t16 t17 p17 t18 p18 p18 p23 t27 s0:1 b26 t28 t29 t30 x0 s7:2,0:7,0:2 w1 t35 s7:3,0:3 t36 s0:2,0:3,0:3 t37 s0:1,0:1 p37 t77 b76 x4 x0 t78 s0:1,0:3 s0:179 t79 s0:2,0:1,0:3 s0:1,5:2 t80 t81 x2 t82 p83 p84 s0:1,0:3,0:2 w4 t137 t193 t198 b- t199 p199 t200 b- x5 t201 t202 t207 w5 w2 b205 t208 t213 s0:1,0:8,0:1,0:8 t214 w3 t215 x4 w0 t216;bda9c7c933375915 +p61;0;0 3 0 1 3 0 1 1 3;0;1 3 7 4;2@1 6@3 5@2;p0 b3 p0 p1 t2 t7 t8 p9 t10 s0:3,3:3 s0:1,1:3 t11 s0:1 s3:1,2:1,0:3 t12 t13 p18 t23 t24 p25 s1:3,3:2,2:1,1:3,0:1,2:2,1:1,2:2 t26 w0 x6;9b2bf22573e29050 +p62;0;0 1 2 1;0;1 3;2@6;s0:1,7:1 t1 p2 p3 p3 p4 t5 p7 p7 p8 p8 t12 t13 p14 t15 p18 t23 p23 p24 x2 p25 p26 w0 p28 p28 x0 w0 t29 p29 p29 p30 t31;5000d8dd4b22c87f +p63;0;0 0 0 0;0;2 3;;t1 w2 t2 p3 w0 y t4 t5 s1:5,1:3,0:1 t6 s0:1,0:2,0:2,1:1,5:1,1:3,1:1,1:108,1:1,1:2,0:1,1:3,0:1,1:3 t7 t8 t9 t11 b15 t12 b12 s0:2 s0:1 s0:1,0:2 y s0:1 y w2 t15 p15 y p15 y b- w2 t19 t24 t25 t26 p27 w3 y b25 y b28 p28 t29 w0 b35 t32 y;3b629f4644306482 +p65;0;0 1 0 2 1 0 0 1 2 0;0;2 6 4 3;5@- 1@-;t4 t5 p5 p5 x0 p6 p7 p8 b7 p8 p8 y t9 p9 s0:1,2:2 p10;15382d8ef6eee87e +p67;0;0;0;;;t1 t2 t3 t4 t5 y t10 t11 t12 t53 t54 t59 t60 b66 p113 t116 t117 t118 s7:2,0:1,7:3 t119 t120 p171 p176 y t177 p180 p181 p182 t183 p184 p184 p184;013493850a1dd91f +p69;314;0 1 1 0 0;0;;4@- 3@315 1@-;t315 w4 s0:1,4:8,7:1,0:1 s0:1 t316 s0:69,0:2,0:1 s0:2 t317 t318 t319 t320 w3 t321 t325 w0 w1 w0 t327 b- y p328 p329 w0 t330 t331 t332 w0 t333 p338 t339 y p342 t344 s4:1,1:125,0:1,1:1 y y t345 s0:1 t346 s0:2,5:1,1:1 t347 t348 y t353 w4 y t358 p361 w4 t366 p367 p367 p368 y y t369 y t370 p391 p391 p391 p391 p395 p396 b397 y p396 w4 p399 p399 p399 p399 p399;2a847308a80ab0d5 +p70;0;0 2 1 2 0 2 0 0;0;6;1@- 5@- 2@- 3@-;t1 t6 t7 y t8 t9 y w5 t10 t11 t12 t13 t14 y w6 y;72fbf2a37709d72e +p71;0;0 0 0;0;;2@1 1@-;t1 t2 t5 y w1 t6 t10 t12 t16 t17 t18 w1 w1 w0 t19 t20 t24 x0 t25 w0 p63 t64 t65 w2;be968d52ba8947ac +p72;0;0 1 1;0;1;2@1;t1 p1 b6 p1 p4 p4 p5 p5 p5 p6 x2 t7 t8 t9 x2 t10 x2 b8 p10 s7:1,0:1 t11 s0:2,0:8,0:169,0:1 t12 t13 t54 x0 t55 x0 b- p55 p55 p55;685d43cb17eb81ac +p73;0;0 1 1 1;0;2 3;;y y b- p0 p0 p0 p5 p44 p47 p48 p50 p50 p51 p51 p52 p57 p58 p60 p60 p60 p60 p60 p60 p61 p64 p113 p113 p114 p114 p114 p115 p115 p115 p120 p120 p120 p125 p129 p131 p136 p136 p137 p138 p138 p139 p139 p169 p172;1e31309f458d064b +p74;4;0 0 1 1 1 1 1;0;1 5;4@- 6@11 3@8;w4 s1:2,0:2,0:1 t5 s0:3,0:2 t6 t7 t8 w4 b7 w6 w1 t9 t10 w6 t14 t17 w5 t20 t21 s0:3,0:1,1:230,0:3,0:3,1:3,0:1,1:1,0:2,5:3,0:1,1:1 t22 s0:1,1:1 t23 t24 t28 s0:161 s0:1,0:5,0:1,0:3 w5 s0:2 t29 s1:2 t30 t31 w4 w6 w2 t84 p120 s0:1,0:1,0:1,1:2,1:1,1:7,1:1,3:2,0:2 t122 p122 t123 y w3 t124 w3 y t127 w5 y t131 p131 s1:1,1:8 w4 t136 w0 b137 w6 b136 t140 t141 t145 t146 t147 w3 t151 t152 w2 t153 y w5 y b152 x4 t154 w4 s1:1,0:2 s0:2,1:1 t155 s1:2,0:7;984ddaf13ba71093 +p76;502;0 1 0 1 0 1 0;0;4 2 3 5;1@-;t506 x1 t509 x6 y t514 t515 t516 t517 x3 t518 t519 y s0:2,1:1,1:1 t521 t522 t523 w6 t561 t562 t563 t566 x6 x1;ddf2677fdf0093c1 +p77;0;0 0 0 0 0 0;0;3 4 1;2@-;y x3 t3 x1 t5 t6 t7 y w4 x5 t8 w2 t9 y y w4 t12 t16 y t17 b- t21 p21 t22 p23 b27 t24 s0:1,0:3,7:2 b- t27 b- x0;d9bbc07aeac4023c +p78;0;0 1;0;;1@-;w0 w0 t1 x1 y x1 t3 w0 y t4 t5 y y p6 t7 y w1 s0:7 y w1 t8 t9 t10 b15 p14 p15 b14 p16 s0:1 t19 t20 t42 t43 s2:1,4:2,0:1,0:1 t44 x1 w0 t45 p46 p50 p51 p51 p51 p51 p52 p84 y y;8a19fe6e1cf83789 +p81;5;0 0 0 0 0 0 0;0;1 5;6@5 2@- 4@8;w2 w6 w4 w0 t7 w3 y x1 t10 w4 p10 t11 y w0 t16 w3 t17 t18 t19 t24 t25 t26 w1 x4;f600e8b567639f1b +p82;3;0;0;;;w0 s2:3,0:3,3:1 x0 t4 t6 p6 p6 p6 p6 p6 p7 p9 w0 w0 t10 x0 p10 t11 p12 p13 p13 p14 p14 p15 w0 t16 t17 t18 p19 p20 p23 w0;3f04d6fb373697dd +p83;0;0 1 0 0 1 1 1 0 1 1;0;7 5 9;8@1 6@- 1@5 4@-;p0 b- p1 p6 t10 p11 y t12 p15 t16 p17 p53 t54 t55 x1 t56 t59 x1 p59 w0 p62 b- t63 p64 t68 p68 t72 b- p72 p72 p72 p72 p73 p74 p76 p76;02ff3b6e42d84c68 +p84;0;0 3 2 0 0;0;3 2;4@-;p5 b11 s0:2 x3 t6 y b4 p6 t7 x3 s0:161 t8 b6 p12 s0:1 t13 s5:1,0:1,2:1 p13 b19 t14 t15 p20 y s1:1,2:253 t21 p21 p21 p22 p23 t24 t27 p28 t29 t30 p32 b30 p32 t33 s2:1 s2:31 t34 s0:1,1:2,2:4,1:1 s3:1,2:1,0:2,2:1,1:1,2:2,5:2,3:1,1:1 t35 t36 p36 p36 p36 p39 t40 b41 p40 p41 p41 p41 p41 p42 b- p43 p44 p45 p50 t51 t52 p54 p54 p55 p56 p56 p59 p60 p61 p62 s1:2,5:1,1:3,0:1,2:1,7:1,3:196,0:1 t63 t67 p67 p67 p105 p105;152590724047af8a +p85;1;0 0 1 1 1 0 0 1 0;0;8 7 6;5@5 4@- 3@-;t2 x3 t5 w5 s0:4 p6 t9 t13 t14 t15 t16 t17 t18 s0:1,0:1,0:1 s0:1 t19;dc8bdebfdfb55186 +p86;0;0 3;0;1;;w0 t4 p5 t6 t7 t8 b- p8 p8 p13 p70 p75 p78 p78 p79 p79 p83 p88 p89 p89 p89 p90 p90 p90;48611e4d7e12e5b4 +p87;0;0 0 1 1 1;0;2 3 1;;t1 t2 t7 p8 t9 t10 t11 s0:1,0:8 p13 p13 y p14 t17 s0:1 p17 t18 x4 p18 p18 p18 b20 t19 t20 p20 t21 b- b22 p21 p21 p22 w1 w2;19985d5ab84c1a18 +p88;0;0 1 1 1 0 0 1 0;0;4 7 5;3@2 6@2 2@- 1@-;t1 t35 t38 t39 t40 x1 t41 t42 y x5 t43 s1:55,1:1,0:3,5:2,2:2 t44 t45 t46 y x2 t60 t82 t83 t85 x0 s1:3,0:1 p85 t86 p87 t88 y t89 t90 t95;caf726ac55bf91a3 +p89;5;0 2 1 1;0;;3@4 2@7 1@5;t6 t7 y p7 x1 t12 t14 t15 y x2 t16 y t17 p17 t22 b20 p23 t24 b- p46 p49 p50 p54 p55 p55 p55 p55 p56 p56 p57 p59 p59 p60 p60 p61 p61 p62 p62 p63 p64 p65 p66 p66 p69 p69 p69 p69 p69 p69 p70 p70 p71 p71 p71 p83 p84 p85 p85 p85 p86 p91;90ec77350c7d814e +p90;1;0;0;;;t2 t3 t6 t7 t8 p13 t14 w0 y t15 p15 t16 w0 t21 t26 p27;4580928a219e6646 +p93;41;0 0 1 0 0 0 0 1;0;5 7 2;6@48;t42 t43 p44 x2 x7 y t45 t46 t47 s0:3,0:171,0:2,0:1,0:1,0:1,0:1,0:1,0:2,0:1,0:1,0:1 t48 p48 x1 x1 t49 b47 s1:2,0:6,0:3,7:1,0:1,6:2,7:1 b49 t50 t51 p51 x6 t52 t54 t55 y b61 x2 b- x6 t57 t60 t61 t64 p64 p66 p66 p66 p66 p68 x2 x7 t69 t74 s0:1 t75 s0:1 t76;cdb4de0440223e3e +p94;4;0;0;;;x0 b8 p4 p4 p4 p4 p4 p4 p4 p4 p5 p6 p6 p8 b12 p8 p9 p10 p11 p12 t13 b13 p13 p14 b19 p14 p15 p19 w0 b21 p19 p19 p19 p20;617eaa4ecbdf026a +p95;0;0 3 2 1 2 3;0;1 2 3;5@4;t1 t3 t4 t17 t18 b22 p19 p25 b29 p25 p25 p25 p25 p30 y b28;3acc5b08a6f6e672 +p97;0;0 2 2 2 1 2;0;4 2;5@7;w0 t1 t2 t3 y t7 y y t8 t9 y y p9 b- p14 p14 p15 p15 p15 p15 p15 p15 p18 p20 p21 p21 p21 p23 p27 p82 p82 p83;474a5433bd522943 +p98;4;0 0 0 1 1 1;0;3 1 2;5@8 4@-;x1 s6:1,0:4 p4 b4 t8 b- x4 x5 t9 p9 p10 b11 w0 y t15 t16 p61 p64 p65 t66 p71 p71 p76 p77 t78 y y x5 t79 t80 x5 t81 p81;577a9ce37e70e181 +p99;0;0 1 0 2 1 0 2 1;0;4 7 5;1@- 2@4;t5 t6 t11 t14 s0:1,1:1,3:2 t15 s0:1 t16 s1:1,0:2 t17 t18 p30 s1:1 p31 p32 t33 t34 p34 s1:1 t39 x4 p39 p40 t41 p42 t44 s2:1,1:1,3:7,1:1 b48 t47 t48 p49 p50 p51 p51 p53 p55 t56 p56 p56 p57 y t83 p84 p85 w1 b88 s1:2,3:2 b83 p85 p85 s5:1,2:3,0:1,1:20 x0 p85 b84 x1 t86 p86 p122 s1:2,2:4,3:1,0:1 t123 s1:2,0:1 t125 p125 w0 b131 b125 b123 p141 s1:1 w2 t142 y t143 p143 b- t144 y s1:1,3:2 s1:1,2:2,6:1,2:1,1:133,3:6,2:3 p144;42b5a6400ae6de18 +p100;482;0 0;0;1;;y t483 p483 t484 p484 y t485 t486 s0:2 t487 t488 t489 p492 p494 t495 t496;1f117022df0f9b9c +p101;3;0 0 1 0 1 3;0;1;4@10 5@7;y t4 s0:1 t5 s0:1 t6 s1:1,4:2,2:1,0:2,0:3,6:1,3:1,3:2,1:3,0:1,2:1,3:3,1:2,6:3,6:73 t7 t8 p8 p9 p9 p9 p9 p12 w2 t13 t14 y b15 t15 p15 p15 y;88de6d836e045d15 +p102;0;0 1 0 0 3 2 3 1 1;0;4 1 2 8 5;7@5 3@-;t1 t2 t3 w3 x3 t20 t21 y t22 x2 b- t23 s0:3,1:1,2:2 y t24 b30 t34 t35 y p36 t37 y y t38 t43 y w1 s1:3,0:1,2:5 t44 s1:1,0:2 t45 s0:4;b0ac8f0b44a22c9a +p105;2;0;0;;;y t3 t4 p4 w0 y t5 t6 t9 t10 t11 x0 x0 t12 w0 w0;5e5f3638033cb946 +p106;2;0 1;0;;1@6;t3 t8 y s2:1,0:1,2:1 y t9 t10 p10 p10 p11 t58 p58 p59 t63 p64 p65 s5:8,2:185,0:3 t66 p71 p71 p71 p76 p76 p77;5844e95718ffc611 +p111;0;0 0;0;1;;x0 t1 t2 t3 y t5 t6 t7 b10 t67 p67 b- x0 t68 t73 t74 x1 t75 t76 t77 w0 t78 t80 t81;847cb37b99077461 +p112;1;0 1;0;;;w1 p5 x1 w0 t6 t7 p7 p10 p10 s6:1,1:2,0:1 b12 p11 p14 p23 s1:2,0:2 p24 p24 p24 p24 p25 p26 p27 t28 t29 p30 p35 s0:1,1:2,1:2 p36 s1:1,0:2 b42 p36 p39;ade5cd23e0d4563e +p114;4;0 2 2 2;0;3 1;2@-;w1 p4 s2:1,1:3,1:2,0:1,0:212,1:1 t5 s0:1 t6 s0:3,4:2,4:7 t7 t8 y w2 p10 x2 w0 b8 p11 p12 p12 p13 p13 p13 p14 p15 p16 p16 p17 p17 p20 b20 p21 t24 p24 p24 p25 p25 p26 p30 p31 p31 p31 p32 w0 p32 s0:1,0:1 t33 s0:1,0:1,0:1 t34 s0:1 t35 p36 t37 p42 x3 w1 w0 t43 t45 p45 w2 x2 p45 b49 p45 p45 p46 p51 y p51 w3 y y w1 t52 t53 w2 t54 t55 w1 w0 p56;b57652e162940366 +p115;2;0;0;;;t3 w0 w0 t50 y t51 t52 t54 t55 b57 p56 p57 t58 t59 x0 t60;1e28dd5a88c9eeb4 +p116;5;0 3 2;0;2;1@7;w1 t6 t62 b- p62 p62 p63 p63 p64 p65 p65 p65 p70 p71 p72 p72 p72 p72 p72 p73 p88 p89 p89 p94;9166d7d61ac1a594 +p117;4;0 0 0 0 0 0 0;0;1 3;4@9;t5 t6 p11 t12 t13 t14 w6 t15 w0 t16 w5 t17 t19 p20 t25 b- t26 w0 w5 t27 w2 t28 y w2 t29 s0:2 s0:1 p29 t30 t31 b29 p31;5cf598e56bbc477d +p119;3;0 1 1;0;;1@6 2@-;t7 x1 t8 x0 t9 t10 s0:1,4:6 b- p11 p11 p11 p11 p15 p15 p15 p15 p15 p15 p16 p17 p17 p17 p17 p18 p18 p18 p18 p19 p19 p19 p20 p25 p25 p33 p34 p34 p36 p36 p37 p37 p37 p37 p40 p40 p40 p43 p43 p44 p44 p48 p49 p49 p54 p54 p57 p58 p60 p65 p65 p65 p65 p70 p71 p71 p74 p77 p77 p77 p77 p77 p78 p78 p79 p79 p84 p89 p93 p94 p94 p95;b6e66dd91d2ff30f +p120;0;0 0 1 0 1 1 1 1 1;0;1 2 4 6;7@-;t1 w8 w5 w6 w3 b6 w8 w0 t2 p3 t7 t8 y t9 w8 b7;975eb72a5c50dd4c +p121;0;0 0 0 0 0 0 0 0 0 0;0;7 2 8 9 6;3@- 1@-;p1 t2 b8 b1 t3 t4 t5 b7 w4 t6 t7 x3 x4 b- w6 b12 b7 x7 t36 s0:2,1:46 b- x9 s1:2,1:1,0:1,1:77 b39;1a730049f301b224 +p122;0;0;0;;;t1 t2 t3 x0 t4 y t5 t6 b- p7 p7 p8 p8 p8 p9 p12 p12 p12 p12 p12 p13 p13 p13 p13 p14 p16 p16 p17 p18 p19 p19 p20;a4bb0a88ea045943 +p123;5;0 0 0 1 0 1 1 0 0 1;0;4 5 9 6 8;1@12 7@7 2@- 3@-;y t6 t10 p10 w1 p10 t11 t16 t17 t18 t19 w3 t20 t23 y t24 t25 t29 t30 t31 t32 t67 t68 t69 t70 t71 t76 t77 t80 t81 t82 t85 p85 t86 t89 x3 x2 t90 t94 t95 t96 t99 t100 t101 t102 y b107 t104;8bca297a5c911e6c +p124;0;0 0 0 0 0 0 0;0;5 1 3 6 4;2@-;w3 t1 t2 s0:2,4:2 w3 b- t6 p6 p6 p6 p6 p6 p6 p44 y t45 t46 p69 t70 p70 p70 p71 p72 b- t76 b- t77 b- t78 p79 p79 p79 p82 p82 p82 p82 p83 p123 p128 y t129 y t130 p130 p133 b131 t138 p138 p139 p139 p139 p139 p139 p139 p140 b- x5 p141 t142 p164 t165 t166 p166 p166 p166 p166 p170 p170 p170 p170 p170 p170 p172 t173 y w2 t206 p207 p210 p211;790473fb7fa3afe8 +p126;3;0 1 1 0 3;0;;1@5 3@- 2@-;s3:8,1:2,0:3 t4 t5 p6 p7 p8 p9 p9 p12 p12 p13 t14 t17 p20 p23 p23 p23 p57 p57 p57 p58 p59 p60 p114;83f7cddc6837a7d3 +p127;4;0 0 0 0 0 0;0;3 5;4@3;w1 x2 t5 t6 t7 t19 y s6:1,0:3,1:1,3:1 s2:1,0:2 t20 t25 w0 p25 t26 y t27 p27 p27 p27 p28 t29 t30 p30 p34 t36 p36 p37 p37 t38 b- t85 w4;8859479ded35e2ee +p129;687;0 0 0;0;1;;p687 t688 b687 t689 s0:1,0:3 b694 y w1 p717 t718 w1 p721 b720 y s0:2,0:3,0:2,0:1 t726 y t727 t728 y t729 p729 w1 s0:5,0:1,0:1,0:1,0:2,0:1,0:3,0:1,0:3,0:1,0:3,0:1,0:3,0:2,7:2,0:1 w1 p729 y t732 t733 x2 t734 t735 b736 p736 b736 p737 t738 p771 t772 b770 w1 y t773 y t774 y y p775 t779 w0 t781 t782;8fe24a958656dcf6 +p130;0;0 2 2 2 0 2 1 2;0;3 4;1@5 7@5;t3 p4 w7 p4 t5 t6 t7 t8 t9 t14 t15 t19 t20 w4 t23 b-;62a335ca514ae868 +p131;3;0 1;0;1;;x1 t4 b2 p4 y w1 t5 t6 y x0 p7 x1 t8 t9 y p10 t12 t15 y t19 y x0 t20 p20;17d5179abc90279f +p132;0;0 2 0 0 0 0 1;0;1;2@- 5@- 4@5 3@5;s0:1,2:1 s7:3,0:1 y b3 p0 p1 p2 p4 p4 p5 t10 p10 p15 p19 p20 p20 p21 t22 p23 p23 p25 b- t30 p30 p30 p30 p30 p31 p34 p34 p35 p35;5fada2f86f0e01fe +p133;1;0 1 1 0 0;0;3 4;1@2;b4 p1 b4 b5 p11 x0 t12 w2 b16 y b12 t13 t14 t15 t16 y t17 t18 x4 b23 w2 b- t19 y s0:3,7:4 s3:113,0:3,1:1,0:2 b17 p22 p22 p23 p24 p24 p24 p25 p25 p26 p26 p26 p26 p30 p30 p30 p30 p30 p32 p32 p32 p33;91bd26f408b613cc +p134;3;0 0 0 0 0;0;1;2@4 3@11 4@5;t4 x1 t5 t6 b- b- b5 b- p8 b13 p9 p9 p9 p9 p9 p9 p10 p10 p10 p11 x1 b12 p52 x1 t55 x1 t56 s0:3 w1 s3:5,0:2,1:1,1:1 t57 s0:2,0:1,0:2 s0:1,0:1 x3 b63 t62 x3 t63 y b- t64 x1 b63 t65 t70 y w3 b- b70 p72 b-;56571c21a79f4d3f +p135;0;0 0 0 0;0;;;b- p0 p0 p4 p5 p5 p6 p10 p11 p16 p17 p20 p73 p73 p78 p78;b9b0e61b80a038b7 +p137;0;0 3 2 2;0;1 2;3@-;p1 w0 t2 w2 x2 y x0 x0 w0 t34 y t35 p35 w3 w0 t36 t42 t43 x3 t44 p46 t47 x0 w1 x3 y t48 t49 t50 y t51 t52;13eefbabd4a41322 +p138;1;0 1 1 1 0 1 1 0;0;4 2 5;3@4;p2 t6 t7 p7 t11 t12 p13 t14 w6 t15 t20 t21 b24 t22 w4 s0:2,0:6,1:1 s0:1,5:1,3:2 s5:2,0:1,5:5 t26 x3 s0:1,1:1,0:2,1:1,0:1,1:1,1:2,0:1,1:2,1:1,3:1,1:203,1:3 p27 p31 t32 p32 x7 t33 x1 x5 p34 b32 t35 t36 s1:207 t38 w7 t76 t77 x0 x3 t79 t84 b83 t85 p85 p86 w0 y;833486c077914cf5 +p139;2;0 0 0 0 0 0 0 0;0;2 5 3 7;1@7 6@-;t3 y t4 t9 b12 p12 y w6 x5 y t13 t14 x6 t15 t19 s0:1,0:1 t20 s1:1,4:2,1:2,0:2 t21 t22 p23 p23 p24 p25 p25 p26 p26 p31 p32 p32 p33 p33 p33 p33 p33 p33 p34 t35 t37 p37 p38 p38 p66 p66 p66;56760e56dc60248e +p140;0;0;0;;;x0 w0 t3 y w0 t6 y t7 b- p7 p8 p8 p8 p8 p9 p11;4f319ba1e7121cf4 +p141;1;0 1 0 0 1 1 0 1 0 0;0;7 1 4 2 5 6;9@- 3@5;w9 t2 b- t3 s0:1 t4 t5 y b- t6 p6 p7 x6 t8 t9 t10 t11 w0 t12 s0:2,1:6,0:1,0:2 s7:1,0:1,1:3,0:2,0:2,0:2 t13 t15 t16;c2b66fd461a83f51 +p142;0;0 0 0 1 0 0 0 0 0;0;7 5;4@3 3@- 8@- 6@-;b4 t1 b- t3 y w8 t4 b- w1 w0 t5 t6 y t8 y w8 b- w5 b- t9 t10 p15 t18 t19 t20 t21 y y x3 t22 t27 t28;00001ac36f3bdc66 +p143;0;0 0 0 0 0 0 0 0 0;0;7 6 8 4 1;5@- 3@-;x6 b- t1 p1 x4 w2 b3 t2 p2 s0:2 t38 t39 t42 b47 t43 t44 t47 w1 t48 p48 t49 p49 t54 b60 w1 t55 w6 w5 t58 w3 y w8 p58 b57 w5 w0 t59 w7 p60 s2:4,0:1,0:2 s1:1,0:2,1:8 t61 s0:1 s7:1,0:7,1:1,6:1 t62 t63 p63 p63;12e9287494e381ed +p144;1;0 1 0;0;2;;t3 t59 t60 s0:1,0:2,3:1,5:1 t64 y w0 b- t65 p68 t69 t74 t79 t80 p80 p82 t83 y y w0 t88 w0 t90 p90 p91 p92 b- y t93 t94 t95 p96 p96 p96 p96 p96 p97 t99;9328d419bf23ec2e +p145;0;0 1 1 0 1;0;4;1@6;t1 p1 t2 b- p42 p42 p42 p43 p45 p45 p45 p46 p47 p47 p47 p47;ae2593cf99cee822 +p146;0;0 0;0;1;;t3 t5 w1 x0 t9 t10 x1 t11 x0 t12 y t14 t15 t16 s0:1 b- x0 s2:1,0:3,2:1,2:1,0:1,1:1,7:1,2:6,2:2 x0 t17 x1 t18 p21 t22;29c07d36452875ce +p147;0;0 0 1 2 0 1;0;5 2;1@3 4@6;b2 p0 p1 p1 p2 x0 p3 y t8 t9 b12 b8 p9 t10 t11 t12 b11 b10 t13 x0 t15 t19 b- b19 t20 b24 p20 y t21 t22 b28 p22;4d4336680eb8afd7 +p149;2;0;0;;;t3 p4 s0:1,1:1,1:1,1:1 t5 w0 w0 t6 x0 w0 w0 x0 y t7 p8 p8 p9 p9 p10 y x0 b11 p10 p10 p10 p13 p14 s1:3,0:2,0:1,0:8 x0 x0 t15 p18 p18 p19 x0 w0 t20 x0 t22 x0 w0 s0:1 w0 w0 s0:203,2:5 x0 t26 s0:2,0:1,5:133,1:1 w0 x0 w0 t31 p31 p31 p32 p33 p33 p33 p33 p33 p38 p39 p39 p40 p41 p41 p41 p42 p42 p42 p42 p43 p70 p70 p71 p72 p72 p72 p72 p72 p72;5f76647cd7ec6938 +p151;200;0;0;;;w0 p201 b- p201 p201 p201 p201 p201 p201 p202 p203 p204 p205 p208 p209 p209 p209 p209 p209 p210 p215 p215 p216 p216;28bbbf225a7bfd21 +p152;2;0 0 2 2 1;0;4;2@1 3@1;b- p3 p3 p3 p8 p8 p9 p9 p10 p15 p17 p18 p18 p22 p22 p22 p24 p25 p26 p27 p65 p65 p65 p65 p65 p65 p66 p66 p67 p68 p69 p69;c99df50180142e77 +p153;5;0 1;0;;1@8;x0 x1 t6 t7 t8 w1 t9 y t10 t11 s0:3 s0:1,1:2,1:1,1:7,1:1,4:2,3:1,0:3,1:8,4:2,0:1,2:2,2:2,0:4 t42 p43 p57 t58 x0 w0 x1 t62 p62 p62 p65 t66 t67 w1 w1 t68 t69 t70 t74 y t75 x0 b- p75 p76 p79 p79 p80 p85 t86 x1 p87 t88 t91 t92 p93;e7720f8b47d7879a +p155;0;0 0 0 1 2 2 0;0;4 1 5;3@5;x3 t1 s2:1,0:2 p2 y w2 s1:1,0:4,1:174 b8 t7 x0 t8 t13 s1:3 w3 t15 b-;9f8ce3c86192d8ca +p157;2;0 1 2 1 0;0;2;4@5 3@-;x0 t3 t5 p5 x3 p5 y t6 y t7 y p10 s0:1,0:3 p10 s1:4,1:3,0:2 t11 s0:2 p11 y y b- t12 s0:3,1:1 t13 p14 p14 p14 y y b13 p15 b19;0855985729e88029 +p158;4;0 2 3 0 2;0;3 4 2;;t5 b9 w0 t6 t7 t8 t9 y t14 t15 t16 t17 x2 w1 x1 t19 t20 t21 p22 b24 y t23 p25 t26 t27 y y t28 t29 y t30 y p32 w4 p32 t33 t34 w0 t60 p61 t62 t63 t64 t65 s0:3,3:1,1:1 t68 t69 t70;cc71c7b90908ffbe +p159;0;0 0 0 0 0 0 0 0 0;0;5 6 1 7;3@- 8@1 4@- 2@-;y x0 t1 t3 w8 x6 y t4 p6 y w7 t8 t11 t12 b10 t14 s0:1,0:2,7:1,0:2 t15 p19 p19 p20 t21 s0:4 t22 t23 y y t24 w2 t25 t26 y t30 t31 p32 p32 b38 t33 p35 t36;7906717bd8fcd738 +p161;0;0 0 0 0;0;;3@2 2@-;b- p0 p0 p7 t8 t9 t14 p14 t15 t16 b20 p17 p17 p18 p19 p19 p19 p23 y t24 t25 t30 w3 x1;dacf71e840cd1688 +p162;664;0 3 1 3 3 0 3;0;6 1 4;2@-;t665 w3 t666 t667 y w1 p667 t668 t669 b- p670 p671 p672 p672 p677 p678 p678 p678 p681 p681 p681 p685 p687 p687 p687 p687 p687 p687 p690 p690 p691 p691;df6d10b61393fe67 +p163;2;0 0 0 0 0 0 0 0 0 0;0;7 3 9 6 1 5;8@- 4@3;x3 t3 b8 b1 t4 t5 b8 t6 b- t7 t11 s0:5 p16 y b- w8 b19 t17 t18 b22 t19 t21 t24 b24 b23 t25 t26 b- x7 t28 t30 w3 t31 b30 w5 b33 t32 x9 y t33 t34 t35 t36 b- w5 p38 t39 w0;9a9b7b865863bd31 +p164;429;0 1 2 1 1;0;;4@- 1@- 3@430 2@-;t430 t431 s0:2,1:3 s2:1,4:2,0:2 t432 t433 p434 p435 p438 p438 p438 p438 p439 p439 p442 t443 p444 p475 p476 t477 t478 p479 p480 p481 y t524 p525 p526 s0:1,4:3 t527 s0:1,1:1 y w1 t528 p529 t530 b- p530 p530 p532 p532 p532 p533 y w0 s1:1,0:1,4:2,2:1 s0:1,4:2,4:1,2:2 t534 p536 p536 p536 p541 t542 p542 p542 p543 p543 p543 p544 p545 p596 p655 t656 p656 p707 p708 p709 p709 t713 p714 p715 t719 p720 p721 b726 p721 p770 p770 p770 p771;16c0e2edde2c107c +p165;0;0 0 2 0 0 2 2 0 0 0;0;2 9 3 6 7;4@- 1@4 5@1;t5 s7:1,0:1 t6 t9 p13 p14 b16 s0:3,1:154,2:1,1:2,0:1,2:1,1:1,2:2,0:1,0:1,2:1,1:2 t17 y w8 t18 p20 p20 p24 p24;c247652e6834dde6 +p166;0;0 2 1 1;0;2;3@5;t1 w0 p2 s0:1 t3 t4 t5 p5 x2 p5 t6 p8 s1:2,0:1 t9 t10 t14 w2 s1:2,2:3 t15 t38 p39 p39 p92 s3:2,6:1,2:3,1:4,0:2,0:1,3:1,1:1,0:1,2:5,1:1,2:1,3:3,4:2;4b1b41e0512fecf7 +p167;0;0 0;0;;1@7;w0 y w1 t1 p2 p2 w0 t3 w0 y w1 s1:1,0:1 t4 t5 p61 p61 p61 p62 b- s1:3,0:1,0:1 s0:1,0:1,1:1 t63 p66 p67 t68 t73 b78 p73 p73 p74 p75 p75;1670631f4598438e +p168;0;0 0 0 0 0 0 0 0 0;0;3 6 5 4 8 7 1;2@4;w2 t1 t2 b2 w3 t3 b- b1 p4 t6 t8 w6 w3 w1 w8 w0 w6 w6 w1 b- w7 b10 t10 t11 w6 w1 x5 t12 b11 x7 t13 x4 t14 w6 b- b14 w3 b16 w6 w4 t15 p16 b15 w1 w5 s0:3 t17 s0:1,0:2;5d24a2115477679c +p169;0;0 0 2 3 2 1 1;0;4 3 2;6@-;p1 t2 s0:2 t3 t4 t5 w6 t6 b- p8 p8 p9 p9 p10 p10 p11 p15 p15 p15 p15 p18 p57 p57 p61 p62 p63 p66 p67 p67 p70 p70 p71 p72 p73 p73 p73 p74 p75 p75 p115 p115 p116 p116 p116 p117 p121 p121 p121 p121 p121 p121 p121 p126 p126 p126 p126 p127 p127 p128 p129 p134 p134 p136 p139 p139 p139 p139 p140 p140 p141 p146 p147 p152 p152 p153 p153 p154 p155 p155 p155;9383f02ac93f561c +p170;0;0 3 3 0 3 2 0 1 2;0;8 1 2 5;3@5 4@- 7@8;p1 p2 t3 t5 t6 t7 p7 s0:1,2:1 t10 p13 p14 s2:2,1:1,0:2,1:3,0:1,0:240,1:2,0:100,1:1,0:1,0:5 y p32 t33 t34;3b694369ec4f7b3b +p171;0;0 1 0 1 1;0;3 1;2@- 4@6;s0:189,0:231 t1 s0:2 t2 s0:2 t3 t4 b7 p4 p30 y b30 p30 t31 p31 t32 t33 t35 t36 t37 t38 b- p38 p38;5161b3a4b959f71b +p172;0;0 0 0 0 0 0;0;5 3;1@5 4@8 2@-;w3 y t2 y y b7 t3 x2 x5 y t4 x4 t6 y y t7 t8 x4 b- x2 y t11 w5 s0:1,0:1 x3 t12 t13 t14 y y t16 b14;37da0334b64ddce0 +p173;0;0 0 1 0 1 1 0 0 1 0;0;6 5 1 9 7 8 4;3@- 2@5;p0 s0:58,6:2 t1 s0:3,1:1 t2 t3 t4 t5 t6 p6 p26 s5:3,6:2,1:4,0:1,4:2,2:3,1:1,1:1,1:2,0:1,0:101,0:7,0:1,1:2 t27 s0:2,1:2 t28 s7:1,0:1 t29 t30 p30 p34 p65 t66 p67 s1:2,0:1,7:1 s0:1 p68 p70 t74 t76 t77 t78 t79 t80 t81 s0:1 s0:5 t82 s1:3,0:3,1:2 t83 t84 t89 p89 p89 t93 t94 t95 t96 s0:1;8f75dd0ae67e337a +p174;0;0 0 0;0;;2@4 1@-;t2 t3 p3 b9 p3 p4 t5 b- p6 p6 p7 p7 p8 p8 p9 p10 t11 b13 p11 p11 p11 p12 p12 p12 p12 p13 t14 t15 p15 x2 b- p15 p15 p15 p15 p15 p15 p40 p40 p41 p41 p43 p45 p50 p50 p53 p54 p55 p55 p56 p57 p57 p60 p61 p61 p61 p62 p63 p64 p64 p64 p64 p64 p65 p65 p65 p65 p98 p98 p99 p100 p100 p100 p100 p102 p102 p102 p103 p107 p107;8e54155a8e3a504e +p175;3;0 0 1 1 1 1;0;5 1 4 2;;p59 t63 t64 t65 t66 t67 b71 y b71 p67 p67 p69 p72 t73 b- y;2fbb9d1bd2197e51 +p176;5;0 0 0;0;2 1;;t6 w0 y t7 x0 t8 y t10 x2 w1 p10 b8 x0 t23 p23 x2 w1 t24 p25 p25 t26 y s1:2,0:1,0:1,0:2 t27;11eb320a721195f6 +p178;0;0 1;0;1;;t1 p1 p1 b6 p5 p5 p5 p5 p16 t17 b23 p18 p18 p18 p18 p19 p19 p19 p24 t25 t29 t30 w0 t31 t32 p32 t33 b31 p33 t34 t35 t40 t41 x0 p41 t44 t47 t48 t52 t54;64fcd576b72fcf12 +p179;0;0 0 2 1 0;0;2 3;;y t1 x1 t2 y y y y t4 t7 y y y p8 t12 t13 t14 y p14 p14 y y p15 t16 s6:3,0:1 s0:244 t19 p20 y t21 y s0:5 p22 p22 t23 x4 p23 x4 b- p23 p25 p26 p26 p26 p26 p31 p35 p36 p36 p38 p38 p38 p40 p40 p41 p41 p41 p41 p41 p41 p41 p41 p41 p41 p42 p42 p42;a2aacae073e3d46d +p180;0;0 0 0 0 0 0 0 0 0 0;0;2 3 8;6@6 4@7 7@5 1@-;y t5 b5 t6 t7 y t8 y s1:2,0:2 t9 s0:3 t10 t11 t14 x6 t15;c45f1d269057a167 +p243;2;0 1 0;0;2;1@2;w1 x1 x2 t3 x0 p3 t6 t7 t8 t12 x1 x2 y t13 t14 t19 b19 b- p19 t23 t24 b22 p24 t25 t26 t27 y t28 x2 x0 s0:2,0:1 t29 s1:2,0:2,2:2 t30 s1:1,1:1,0:2 t31 t32 x0 b38 p37 p37 p38 t39 t40 t41 b47 p41 p41;a6768600e1c7fd52 +p246;529;0 0 0 0 0 0 0 0 0 0;0;1 9 8 4;5@537 2@530 7@528 6@-;t530 b533 t531 t532 t533 t534 w5 b- b535 t538 t539 b542 t540 t541 y b- b541 b- b- t546 b- t547 t548 x7;e069f58f84428f42 +p257;0;0 0 0 0 0;0;2;1@- 3@-;s0:3,0:1 t1 s1:1,1:1,6:3,0:2 t2 t3 p6 p11 p14 p14 p14 p14 p14 p14 p14 p15 w3 t31 p31 p31 p32 p32 p33 p33 p33 p33 p33 p33 p33 p33 p33 p33 p68;c9db31d40979973c +p259;4;0 2 2 2 3 0 0 2 2 0;0;9 3 8 2 1 6 5;7@4;t5 t6 t7 y b5 t11 s0:1 t12 y w1 t13 t16 t17 x7 t18 t21 y s0:1,3:1 t22 t27 y t28 p28 p29 t30 p31 y t76 p76 p77 w9 b75 t78 p79 w6 p79 t80 p80 p85 t86 p87 x1 y x0 b88 t88 p89 y p90 p93 t94 p94 p99 t100 p101 b107 y p103 t104 p105 b105 x8 t106 p107 p107 s0:1 p107 s0:3,2:1,1:1 t108 p108 p141 x1 t142 y t143 p147 t148 p200 t201 t205;ff7b801fc8b34f27 +p271;0;0 1;0;;;x1 y t1 t2 t3 t4 t5 w0 x1 x0 t7 y x1 t8 y b7 p8 y y w1 t9 y t10 x0;4d7266f2d5d6c30e +p292;203;0 1 0 0 2;0;2;4@- 1@205 3@-;s0:1,2:3 t205 y x1 p206 p248 p249 y t250 p250 p250 p251 p252 p257 s0:4,2:4 t258 p258 p258 p259 t260 w3 t261 t262 t266 p268 s3:1,0:1,0:2 y t269 y t270 p270 p270;2c9769abadd73cec +p301;0;0 0 0 0 0 0 0 0 0 0;0;9 4 6 3;5@- 8@2 1@5 2@4;x4 t1 x9 t52 x7 t53 t54 x0 x7 t55 b57 t56 s0:1 b- s1:1,1:3,0:2 t61 p64 p64 p64 p65 p66 p67 p67 p71;5e0e763af023602a +p311;2;0 1 1 1;0;1 2;;b2 p2 y t6 t7 y y t8 b7 p9 b10 p10 b10 p10 w0 t11 b17 p13 p16 p17 t18 t19 p24 s0:1,0:1,7:1,0:2,0:1,1:3,1:1,1:1;c3c686e9c6a00be8 +p338;0;0 0 1 1 1;0;3;4@- 2@5;t1 y t6 t7 w1 x0 t11 w3 y t56 b54 p56 x2 t57 x4 t62 b61 p62 b- p62 p63 p63 p63 p64 p65 p66 p66 p67 p68 p68 p69 p70 p71 p71 p71 p71 p72 p76 p77 p80 p80 p82 p83 p83 p83 p83 p84 p84;9613b561071a4d14 +p345;1;0;0;;;b- p1 p1 p1 p1 p1 p2 p7 p8 p9 p10 p11 p11 p46 p46 p47;10959acbe4c26ec5 +p346;4;0 0 0 1 0 0 1;0;2 4 3 6;;s0:2 x4 s3:1,3:2,0:1,3:1 t5 x0 y t6 p6 p6 p6 p7 p8 p9 b- x6 y s0:1,1:1,0:1,0:1,0:1,1:5,0:2,2:1 y t10 p11 t12 t13 w2 y;829d4faf8b917a9f +p400;77;0 0 0 0 0 0 0 0 0 0;0;1 6 4;2@81 8@77 3@77 5@76 9@-;b77 b- b- y b75 p78 t83 t85 b89 b90 t86 t87 b- y t89 s0:1,2:1,0:3,1:7;2a33cc06d17b82ab +p420;5;0 2 3 3 3 0;0;2;4@8 1@-;p9 t10 x4 x1 x3 t11 t12 w3 x5 b16 p43 t44 b- p44 p44 p44;9ec76deceb1c7b82 +p470;0;0 0 0 0 0 0 0 0 0 0;0;7 8 2 3;4@- 9@2 1@- 6@6;p0 b3 t1 p1 s4:4,2:2,0:2,0:1,2:1,3:8,0:1,0:1,0:1 t5 p5 p5 p5 p5 p9 y p9 y p9 y;e7aa26e31aa8fb3e +p472;0;0 0 1 1 3 0 3 2;0;1 7 3;5@3 6@- 4@-;b3 y b4 p0 p0 p0 p0 p0 p1 p1 p3 b4 p3 x6 w0 w4 p5 s0:2,1:1 w4 p6 w6 b9 t9 y w6 b12 p14 y y p15 w5 p15;46f5fa7384a06075 +p501;0;0 2 1;0;2 1;;x2 t4 t5 x0 t9 x1 t10 b10 p10 t11 x1 x2 t12 t13 t15 t16 w1 b17 p17 t18 t19 s0:1 x0 t20;e07604b024c28bf7 +p503;0;0;0;;;x0 t1 t2 w0 w0 t5 t6 t7 y w0 t11 p12 t15 s0:1,1:1 t16 t17 t18 p64 p64 p64 p73 t75 p75 t76 p77 y t78 p78 p82 p83 w0 w0 t87 t88 p90 p91 t92 p92 p93 y t98;c769cada3a15204a +p557;0;0 1 1;0;2 1;;t1 t2 t3 x0 t7 t10 t11 w2 s1:1,0:1 t12 t13 t14 b19 p14 p15 x0 t16 t17 t18 w1 t19 t20 t25 b25 t26 t27 t28 b29 p28 p29 s1:2,0:1 p30;11a24d6d2d4b1f17 +p567;0;0 1;0;;1@-;w1 s0:3,2:3 p0 w1 t1 b6 p2 p2 p4 p18 p18 p23 p23 p24 p24 p25 p25 p25 p25 p25 p26 w0 b- p26 p28 p29 p32 p36 p49 p49 p49 p49;8075c75db41347df +p580;0;0 1 3;0;;2@4;b- p1 p2 p3 p6 p6 p6 p6 p6 p6 p18 p18 p18 p18 p18 p18;59807e9f5a80cb81 +p585;0;0;0;;;x0 s0:2,3:2 x0 t3 x0 x0 p4 p8 p8 p8 p8 p8 p8 p8 p9 p9;3f6c684e58a019dd +p591;0;0 0 1 0 0 1;0;2 3 1;;t3 t4 y y b10 s0:1,1:1 y t5 b3 t10 y b12 w5 s0:1,1:4 b8 s0:5,0:2 b9 p10 x4 b9 y w3 t11 b-;31d47a68db02222f +p603;0;0 0 0;0;;2@-;w1 s3:1,1:1,3:3,0:2 t1 p22 x0 t27 p27 p28 y s3:1,0:1,2:2 t29 s1:3,0:2 t30 p31 p32 p33 p33 p34 y b32 p34 y t35 p35 b34 p35 b33 p35 p36 p37 p37 p37 p37 p37 p38 p41 p41 p41 p42 p43 p45 x2 y t46 p46 p50 t51 p52;3b7a7c7f6c6986f3 +p612;2;0 0 2 1 1 1 0 0 0 2;0;1 7 6 8 5;4@10 9@9 2@9 3@3;t3 t4 x6 x9 t7 x3 t8 p8 p8 t10 t11 x3 p12 y p15 x2 t16 y t19 x4 p20 t23 t24 t29 t33 w8 p33 p33 t34 p34 x6 t39;08016390ed340ac7 +p615;0;0;0;;;s6:3,0:2 t1 t2 p2 p6 t7 p7 p7 p7 p11 w0 t12 p36 w0 t37 p37;20dfefa7bb76f136 +p630;0;0;0;;;x0 w0 s1:1,0:1,0:12 t2 p3 x0 t8 y y y w0 y t9 x0 t10 x0;71568c38f9a56541 +p640;1;0 1 2 1 2 2 0 2 1 1;0;9 1 2 4 7;8@1 5@6 3@1;t2 y s2:3,0:2 x5 t3 y t18 t19 t22 x3 y x8 b- p38 p38 p39;ccc2ca3e98851789 +p658;2;0 0 0 1;0;2;3@3 1@2;p2 t3 y y w2 p3 y b1 y p3 t4 p5 t6 x3 y y y y x3 b5 b4 b9 p7 t8 y b9 y b14 p9 p9 p10 b- b13 p14 t18 b17 t19 y t20 t21 w0 t22 t23 t26 y w1 p27 y;3f60414d6d5898d8 +p661;0;0 0;0;1;;b6 s0:1 w0 p0 b1 t1 t2 b8 b- p7 p8 t9 b13 p10 p11 p12 p12 p12 p13 b11 p13 b- p13 p14;1f936cecdbc8666a +p677;0;0 0 1 1 0 2 2 2;0;1 5 4 3;7@-;y p1 t2 t3 t4 t8 y p8 t12 t13 t14 s2:1,0:1 w5 y p14 t16 t74 p74 y t75 t77 p77 y b- t80 t81 t84 p84 s2:1 t85 s0:3,2:1,0:1 b90;a81e5bca353a9587 +p686;0;0 1 0 0 1 1 0;0;2 3;4@4 1@8 5@- 6@5;w4 t1 t2 t3 b5 x0 x0 y t6 y w1 p7 t8 t9 x1 w6 t10 x5 t11 t16 x0 t17 x4 w1;db70a9f9d6d5a209 +p715;0;0 0 0;0;1;;p5 t6 b4 t7 t8 x1 b11 t9 y y b11 p9 p10 p11 t12 y;798283ef8f484207 +p721;825;0 2 1 0 0 1 2;0;4 3 1;;p825 t829 t830 s0:2 w6 t831 b831 s0:2 t832 s2:6,0:2,1:1,2:1 t833 b838 t834 p837 t838 s2:2,0:1 p842 t843 t844 x5 p845 y t846 t847;657f6abbd886b0c5 +p732;3;0 1 0 0 0 1 1 1;0;6 1 3;2@- 5@-;t4 s0:1,0:3 t5 s2:1,1:1,0:1 t6 t7 p7 p42 b40 s4:2,0:10,0:3,0:1 t43 p44 p91 w5 t92 p107 b108 p108 p109 p109 p116 p116 t117 b- b- p118 p119 p120 p120 p120 p120 p125;b5b03d634578cafd +p737;0;0 1 1 3 2 1 2;0;1 6;3@2 5@1 2@7;t1 x1 y t2 s2:2,0:1,0:1,1:1 b2 p2 t3 t4 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t19 t20 t21 t22 x0 t23 p24 x3 t25 s2:2 t26 t27 s3:1,3:1,1:2,3:1,0:1,2:1,2:2,7:1;e1816c0fbe00df55 +p750;0;0 2 2 3;0;1 3;2@-;p50 b51 p51 t52 b50 p52 t53 b- p54 p54 p54 p54 p54 p55 p55 p60;5c35b08b5a3fec79 +p758;184;0 0 2 2 0;0;1;4@185;t188 t189 b188 y t192 y y s1:1,1:1,0:4 y y p193 t198 t199 y y t200 p200 p200 p200 p250 s2:1,0:1 y t251 p251 x2 w2 y t252 p252 p252 p252 p253 t254 p254 p255 b259 t256 p256 p256 p256 p257 y y y t315 b- p315 x4;683c24a2e36d57df +p761;0;0 0 0 0 0 0 0 0 0;0;5 8 3 1 6 4;7@- 2@7;y t1 t2 p3 w1 t4 t5 b3 x5 s0:1,1:232 b11 s0:1 b9 t10 b8 b9 w5 p10 t11 w7 b14 t12 s0:1 t15;f2b69f817434c24b +p772;2;0 0 1 1 1 1 1 0;0;4 5 2 7;1@3;x7 y s7:1,1:1,1:2,0:1 x2 t5 y t6 b- s0:1,1:3 t7 t8 t13 y t14 t15 y w0 p20 s5:1,0:2 t25 p25 p30 y x5 x6 t34 p35 p67 p67 p67 p67 p69;95dc0ad2bd3c385d +p779;0;0 2 1 2 1 1;0;1 2 4;3@2;t1 t2 b2 p3 t4 y t5 b9 p5 p6 p6 p6 p6 p6 p8 p8 p8 p8 p9 t10 t11 t12 p13 t14 b- p14 p15 p20 p20 p20 p23 p23 p23 p24 p24 p25 p25 p25 p60 p60 p61;b7b4eb91bcf23520 +p819;476;0 0 2;0;1;2@476;t477 b- b476 p478 b476 p478 y t479 t480 s2:1,0:1 t481 y p483 b486 p483 p483 p483 p483 p483 p485 p486 b- p486 p487 b487 p487 t492 p495 b495 p495 t496 p496 p496 p497 t498 p499 t502 p502 p503 b501 p503 t504 p505 t510 p511 b511 p514 p514 p515 b513 p515 t516 p516 p516 p516 p517 y b516 p517 y b- p517 p517 p518 p519 p519 p520 p521 p521 p523 p523 p523 p523 p523 p525 p525 p526 p527 p528 p528;2095fde69b7967a2 +p836;5;0 0 0 0 1 0 1;0;4 5;6@9 1@3 2@9;s1:1,3:1,0:85 t6 s1:1,0:1,1:1,1:1 w2 t7 w3 t12 w2 w5 y w4 w2 y y y t13 y t14 y t15 x2 t16 t17 t18;59a52626f19832cb +p860;0;0 1;0;1;;b- p0 p0 p0 p0 p0 p0 p1 p1 p46 p46 p47 p47 p47 p47 p47;a4d2f58918ebc61f +p861;319;0 2 0 3 1 2 2 0 2 3;0;2 6;3@- 5@318 7@325 8@324 1@322;x6 b319 t322 x5 x2 x3 t323 w7 w4 x1 t327 b328 x8 t332 w4 w0 w1 w6 t333 w1 t338 t339 t340 x6;2161d7977d96af2a +p925;0;0 3;0;;1@-;t1 t2 b8 p3 p3 p4 p4 p4 p5 p5 p5 p6 p7 p7 p7 p7;6a60a9f26b74ba33 +p940;0;0 0;0;1;;b- t3 t6 b- p6 p7 p8 p9 p10 p10 p11 p11 p15 p16 p16 p16;f08a3dd92926d892 +p952;0;0;0;;;t1 b1 p1 t2 t3 w0 w0 w0 w0 t4 y t5 t6 w0 t7 t8 t9 t10 w0 t11 t12 w0 w0 y t31 w0 t32 t37 t38 t39 p40 y;eb22b21eba27f344 +p1025;3;0 1 1 1 1 0;0;1 2;5@-;y t4 s1:1,0:1 t5 y x3 y b- p5 p8 y y t11 p12 b16 x0;cddee9ac354a4ee0 +p1045;3;0 0 1;0;;;b6 p3 p7 b12 p7 p8 p9 p10 p10 p10 p10 p11 p11 p11 p11 p12;308f34fc0c64f3c2 +p1066;2;0 1 3;0;2;;t3 p3 s0:210,1:1,2:5 b3 p3 b9 p3 p3 p4 p5 p6 p20 t21 x1 p21 t22 t25 t26 w1 t29 t30 b35 p30 p30;9db2e23b4a1fb0d1 +p1081;5;0 0 0 0;0;3 2;1@4;b5 y b9 t39 b42 y x3 b42 b42 p40 b- p40 p44 b- y b- b49 p44 p44 p44 p44 p45 p46 p46;f11f7da234979867 +p1096;796;0 1 1 0 0 1 0 0 0;0;4 6 7 8;2@- 1@795 3@803;t797 t801 y s0:2,0:2,0:3 s0:101 t802 s1:6,0:2 s7:2,0:1 t803 t804 p805 p810 p810 p810 p830 s0:1,0:255,1:1 x2 p830 t833 y t834 t835 t840 t841;a7a9851a6544badb +p1122;0;0 0 0 2 1 2 1 2 0 1;0;2 9 3;7@4;t1 t2 t3 t4 t5 x7 t7 y s1:2,0:1 x6 b8 t8 x5 t9 t10 w3 t11 y t12 y x5 y t17 b19 t18 t19 t20 s0:2,2:1,2:4 t21 y s1:1 s1:1;802993416adc17a3 +p1142;1;0 0 0 0 1 0 0 1 0 0;0;6 8 7 2;9@6 1@- 5@-;s1:1,0:1 t3 p3 t4 t51 t52 t53 x4 t54 p55 s1:2,0:1 t56 t57 w0 t58 t59 y t82 t83 t84 w2 s0:1,0:3,1:3,0:2,0:2,0:1,0:1,0:3,1:3,0:2,1:3,1:1,6:8,0:1 t87 t91 t95 w1 t96 s1:7,0:2 t97 p97 t98 t99;40e9e9e27ca0ddce +p1177;5;0 0 0 0 1 1 0 0 1;0;8 1 3 4;2@7 6@- 7@- 5@8;s1:1,0:1,1:1 t29 t30 x6 x7 x4 t31 t36 t37 t38 w6 t43 b- t44 b45 t49 t54 s1:2 t58 t60 t65 t67 p68 t69 p70 s1:2,0:6 t71 p71 t72 p76 t77 y;5629965d0d3ed440 +p1186;3;0 0 0 0 0 0 0 0 0 0;0;9 1;8@7 2@11 5@2 4@3 3@8 7@9;s0:1,0:2,0:1,2:1,0:1 t4 y t5 b5 b- y s0:3 t6 t8 t9 b- t10 t11 t12 t16 t17 x8 t18 t22 w1 t23 t25 t26;1ff71236038d0fc8 +p1188;4;0 0 0 0 0 0;0;4;3@- 5@9;x1 p4 x3 t7 p7 y s0:1,7:2 t8 t9 p10 p11 p12 p12 t14 p14 p14 p15 w3 b21 t16 p16 p16 p17 p22 p22 p26 p27 b32 t32 p32 p32 p33 t34 p35 p35 p36 x1 t37 p37 p39 b39 w3 t44 p44 p44 p44 p51 p51;456c0590498c522b +p1214;5;0 0 0 0 1 0;0;2 1 5 3;4@12;s0:2 s0:2 p5 s1:3,1:1,0:6 t6 b- s0:2,1:1,1:2 t7 s0:1,3:2 t8 t9 x4 t14 p15 x5 t16 p71 p72 t73 p73 p78 t79 p81 t82 p83 p83 p84 w0 t85 p86;9730a0d6a8f57c30 +p1223;3;0 1 3 3 2 3 1 0 0 0;0;4 7 5 2 3;8@10 6@8;p3 w8 b4 s0:1,3:2 t4 p4 b6 w3 w7 t5 b6 p5 t6 t7 t8 s0:1,2:1,2:2 p8 p9 b14 p10 t11 s2:184,0:2 p11 b9 p11 s0:2,2:1,0:3,3:1 x6 x3 t12 b10 p12 s3:1,2:2,3:1 t13 t16 w7 p16 b20 p17;b01a392509d21211 +p1247;0;0 0 1 1 1 0 0;0;4 1 3;;t2 w5 y s0:2 w1 t5 w3 s1:1,0:2 t6 w0 t7 y t8 w0 w4 p8 t9 w4 y w3 w0 t10 t11 s0:154 t12 t13 w5 w1 t18 t19 w6 x4;f4f911e4f045413a +p1267;0;0 1 1 1 0;0;1 4 2;;t9 y t10 y y t11 b13 b10 p11 p12 b- p12 p13 y b12 p13 t14 b18 p15 p15 p16 p17 p18 t19 b- p23 p24 p26 p26 p26 p26 p26;21c158ed3afef505 +p1270;0;0 3;0;1;;s0:2,3:1 x0 t4 t9 w0 b12 p9 p9 p10 b12 p11 p11 p11 p12 p12 t13;dc9d393124692ce3 +p1286;0;0 0 0 0 0 0 0 0 0 0;0;9 4 5 3;2@1 1@- 7@4 6@-;t1 t2 t3 b9 t4 x2 t5 t6 t7 y t8 b12 b12 t9 y t10 b11 p10 t11 b11 w6 t12 b17 t13;705cc526c3bb5ecf +p1300;0;0;0;;;p0 t1 b- p2 p5 p6 p9 p11 p11 p12 p13 p13 p14 p15 p64 p91;46d824b98378861b +p1325;2;0 1 0;0;1 2;;x0 y x1 s4:3,0:1 t6 p7 t8 p8 p9 p9 p9 p10 p11 y y t12;b0540d7ba3356c76 +p1342;0;0 0;0;;1@4;s1:1,0:1 t3 t4 p8 p8 p9 t12 p17 p17 t18 p21 y t22 p23 t24 p25 p25 p25 t26 p27 t34 p34 p38 p39 t40 p40 p40 p41 s0:1,1:3,1:1,0:1 s1:1,0:2,1:2 t42 p42;e5c11137e35f5b1a +p1350;0;0 0 3;0;1;;b4 y s0:1,2:1 t1 t2 w0 b7 p4 w1 t5 p6 t11 p12 y t13 p14;872d606e811d5a8e +p1380;4;0;0;;;b- p4 p5 p9 p11 p11 p11 p12 p12 p13 p13 p13 p14 p14 p15 p15;454d44b2ea556a7b +p1403;4;0;0;;;x0 t5 x0 t6 b6 p6 s0:2,1:1 x0 b10 p7 p8 p8 p8 p8 p9 p9 p9 p9 p9 p9 p9 p9 p9 p9 p10 p11 t16 p21 b21 p21 b25 p78 y b- p78 p78 p78 p79 p80 p80 p81 p81 p81 p82 p82 p82 p82 p82;d7d8f6258d8ebd9e +p1411;0;0;0;;;t1 s0:1 t2 t6 t7 s0:5 s1:1,0:1 t9 p13 p14 t15 p15 p15 p18 x0 t23 p34 x0 x0 s0:1 t35 p35 p35 p78;b5b7f9c27d5fda73 +p1418;2;0 0 0 0 0 0 0 0 0 0;0;4 1 6 7 9 2 5;3@7 8@2;b2 b- t3 y b3 p4 b2 s3:1,0:2 t6 p6 p7 t11 t12 p12 p13 t14 p15 p20 p20 b19 b- t21 p21 p22 t23 b27 t24 p24 p25 b23 t26 b- t29 b34 t30 p31 p31 b35;6d801ecbfaf79497 +p1432;0;0 1 0 1 0 0 1;0;6 5 4;3@- 2@3;s0:1 p2 t3 s6:3,1:2,0:1,1:1,0:1,0:1,0:3,1:2,0:1,1:6,1:4 b3 t4 x3 b- t9 t10 x5 p11 t12 t15 x1 w4 b13 w3 y w5 t16 y p20 t24 p47 w0 t48 t49 y t50 w3 t51;8d4d89a9a1ecbeba +p1436;0;0;0;;;t1 y t2 w0 y b3 p3 t4 t5 w0 t6 t7 t8 t10 b8 p10 p11 t16 b- p16 p16 p16 p20 p20;60bb5ad09b38d984 +p1452;4;0 0 0 2 0 2 0;0;4 3 5 1 2;6@3;b- b10 t5 b10 t6 b9 t7 b- p8 p8 p9 b7 p9 x3 t10 t11 b16 b11 t12 b18 s3:5,0:1,1:1 t13 s1:2,0:5 b12 p13 x6 b15 p14 p14 p15 p16 p17;3cff596c87686675 +p1464;0;0 0 0;0;1;;s0:2 t1 s0:1 t2 s0:1,0:1,4:1,0:1 t3 t4 t5 t10 p11 t12 t13 x1 y t14 p14 p15 p16 t17 t35 t36 t37 t38 p39 p40 t41 t44 t45 b47 t46;7fb22767b29165d1 +p1466;0;0 1 0 1 0 0;0;4 5 3;;s1:1,0:1 x0 y b- p4 t5 x0 s0:1,0:2,1:1 t7 b5 s0:3 t8 s1:1,1:1,0:3 y y t9 t10 w0 w0 t11 t12 w4 y t16;2aca58d6741dbe36 +p1476;0;0;0;;;t1 t2 t3 t4 b2 p4 b- p4 p5 p5 p5 p5 p5 p5 p5 p5 p5 p5 p6 p6 p6 p6 p6 p6;5dcdd5448cf7e9da +p1478;533;0 1;0;;1@-;b536 p534 p534 p535 p535 p536 p540 w0 b539 p540 t541 w0 t542 t544 t545 y w0 b545 p548 w1 b554 p607 p626 w0 p626 w1 w1 w0 t627 w0 y t628 t640 s5:1,0:3 t645 t646 p647 t648 t649 w0 p649 t650 p651 w0 w1 w1 b650 p651;e2641973ad6ed975 +t0;0;0 2 2 1 0 2 0 0 2 1;0;7 6 8 4 2 3 9;1@-;t1 s1:1,0:1,0:1,1:2 t5 t6 t7 t8 s2:155,5:1,1:113,4:4,5:8,2:1,2:2,2:2 t9 s1:1,1:2,2:7,7:2,1:1,2:2,1:1,2:3,0:2,1:2,6:205 t10 t11 t11 t12 s0:3,1:2 x1 s2:2,2:1,1:1,2:5,2:1,2:1,2:1,2:6;9e6ab0c7153e7d30 +t1;0;0 0 0 0 0 0 0 0 0;0;7 3 2;8@5 1@- 6@6 4@-;t1 s0:1 y x2 b1 s0:1 t2 s0:1,0:1,0:2,0:1 t3 t4 b3 x0 x2 b7 x6 t5 b- x4 t9 t10 y x5 b10 x5;ee7e1e6a0a5be3da +t2;0;0 2;0;1;;y t1 t2 y y b7 t3 p3 p3 p3 t5 p5 p61 y t62 b66 p62 p64 p65 p65 p68 t68 t69 b- p69 t70 t71 p71 p71 t72 t77 t79;738c33f0f6dfa379 +t3;0;0 1 0 1 0;0;3 1 4;2@1;w2 s4:90,1:1,0:1,1:3,0:4,1:2,1:2,7:8,1:1,0:162,1:1,1:1,1:160,1:1,0:3 t1 w1 t1 t2 p2 t53 p58 p59 t60 p60 p60 p60 p60 p61 t62 t65 p65 t66 t67 p72 t73 t76 p76 t79 t80 p83 p133 b136 t134 x1 w4 b133;cc9a7e1e43b83f9f +t4;467;0;0;;;y t468 t469 s0:2,0:2,0:1 y y x0 t470 t471 t472 t477 t478 x0 t479 b483 p479 p484 b- t485 p485 p498 p499 p500 t501 p501 p502 p502 p502 t502 t503 p504 p505 p506 p507 p507 t510 t511 p511 p511 t511 t512 t517 p517 t518 p519 t520 p521 p524 p524 p574 p574 p574 t575 p575 t576;dc0e8eaf9d61d754 +t5;5;0 0 0 1 0 1 1 0;0;2 6 1 5 3 7;4@3;t6 y x1 t7 t8 t8 y y x2 x5 s0:6,1:1,1:1,1:3 t9 t10 x1 y b-;12b2dfa09d60b4dd +t6;0;0;0;;;y s0:1 t1 s0:1 t2 s0:1,5:2,5:2,1:1 t3 t4 w0 b- p7 t8 t10 p10 p10 p14 t17 t17 p17 p17 t18 p19 t20 t21;a67cd97a4b3f37ba +t7;4;0 0 0 1;0;2 1;3@3;s0:1,3:1,1:1,1:1 w1 t5 t6 y y y w2 t7 t8 y w1 y t11 t15 t16 t21 x0 s1:5 t22 y w0 w1 t23 y y x3 x1 t27 t28 t30 t31;4cf94cbab5e8b6dc +t8;0;0 0 0 0;0;;2@7;w2 t1 s0:246,0:1,0:1 t2 x1 w2 w0 t3 s0:2,0:2 s0:3,4:1,0:1 t4 s0:1,0:4 s0:219 t5 t6 t11 t12 t12 t13 t13 t14 t14 t15 x0 t16 t17 b19 t18 t19 t21 t69 t70 w1 t71 w1 w3 y s0:2,6:1,0:1,0:1 w1 t72 t73 w2 t74 w0 s6:5,0:74,0:1,0:1,3:2,0:1,0:4,2:1,0:2,4:1,0:3,0:1,0:2 t75 t76 p77;3100a89a690a4adb +t9;139;0 1 3;0;2;1@144;b144 p139 p139 p142 p143 p143 t144 t149 b- p150 t151 p152 p153 t158 p162 t163 p164 p164 t165 p166 p167 p172 t173 p173 t174 t224 t225 p226 t227 t229 p229 t230 p232 t233 p234 t235 t236 p236 p237 p238 t243 t246 p247 p248 p248;938c6681961b082f +t10;3;0 0 2 2 0;0;2 3;4@5 1@1;x0 y t4 t59 t60 b- y t61 t62 w0 w4 w4 t63 t64 x3 w0;c66a450865953c31 +t11;0;0;0;;;t1 t2 t3 b2 p4 t4 t5 w0 t6 t7 t9 t10 t11 t14 t19 t19 s0:1 t19 t19 t20 s0:87 t23 t24 y;1a6c900f4eea0efd +t12;1;0 1 0 0 1 1 0 0 1 0;0;1 8 5 4 6;2@- 9@- 3@-;y t2 t3 t7 t8 w9 y t10 t11 t16 t17 b- y t18 w6 s0:2,1:1,0:110,3:1,1:2 s0:3 t19 s0:3,1:1,0:2 s0:2,1:2,0:3 t20 t21 w6 w2 t22 b26 t23 y t24 t25 y t26;5fcad072a1026d33 +t13;2;0 0 0 0 0;0;3 1 2;;s0:1,0:1,0:1,0:1 t3 t4 t5 y t6 w4 t7 t8 s0:2,0:1,0:3 t9 t10 t11 t12 t13 x3 w3 t14 w1 t15 s0:3 t18 y w4 t19 t20 t21 b25 y y w1 y t22 w0 s0:1,0:1 t23 w4 t28 t29 t30 t31 t32 t33 b- t34 t35 s3:3,0:3 b35;0e80751c1aef0595 +t14;2;0 1;0;1;;w1 w1 w1 s0:2 t3 s0:1 x0 t4 x0 t5 y s0:2,2:1,2:1 t6 y b5 p7 x0 w0 t8 b14 p9 p10 p11 t12 t60 x1 w1 x0 t61 p62 p63 y b63 p63 t64 t65 p65 p66 p66 t92 t97 t98 p99 t100 w0 y w1 t100 t101 p102 p104 x0 s0:1 t105 t122 y t122 s0:3,2:3 s4:39,1:1,0:1 t123 s0:2,0:1,1:1,0:1,2:3,0:1,3:1,2:1,0:3,2:2,2:88,0:3,1:2 t124 s0:1,1:3,7:1 t125 t126 w1 x0 s0:3,3:3,0:1 s2:1,0:1,0:1,2:2 t127 t128 t129 b130 p130 x1 t130 w1 w1 w1 x0;e00b484c47ae5f9a +t15;3;0;0;;;t4 t5 x0 w0 t6 s2:1,0:1 t7 t8 p30 p32 p32 t33 s0:1,1:1 t34 t35 t79;6f3e48c1c1a79440 +t16;0;0 0 3 1 2 0 2 1;0;5 4;2@1 6@- 1@5;t1 t2 s0:3,3:1,3:2,0:1,5:2,1:1,3:148,2:3,2:2,2:2,4:1,2:1,0:1,6:1 t2 x6 b- t3 t4 y b- p5 w4 t6 w0 t7 t10 y b16 b11 t11 p11 p15 t19 x0;f5f551920fa8be6c +t17;0;0 3 1 1 2 1 1 0 0 3;0;9 6 8 3;5@8 4@- 2@-;t2 t3 s0:1,3:1 t4 t5 t6 t7 t8 s3:2 y w6 t13 w2 t14 s1:1,3:6,1:2,6:3 w6 t15 t16 b21 t17 y b15 t18 s3:3,4:2,4:18 b- p19 p24 t28 p28 t35 p35 p36;2fccd0df0e759773 +t19;0;0 2 2 0 0 2 2 1 2;0;5 2 6 7;4@7 8@7 3@-;t1 w6 t2 t5 t6 t11 y t12 t13 t14 x8 t15 y t16 s0:3,2:6,1:1,3:1 t17 s2:1,0:3 t18 t19 t20 x6 t21 t25 w3 t26 t27 t28 t31 t32 t33 t34 t35 x3 b- x7 t36 t41 s2:1,0:1,2:2,1:3 t44 t44 x4 x8 t45 x6 t49 x7 t50 y t54 w5 t55 w1 b- t56 t57 s2:151 s0:3,1:1,2:3 t58 t59 s0:2,2:1,1:3,2:1,1:1,2:2,2:2,1:1,1:1,2:5,0:2,6:1 t60 s4:1,4:1,0:1,4:3,4:6,4:1,4:6,4:3,4:6,4:1,4:35,4:1,4:1 t61 y t63 t67 t68 t69 p69 t70 p71 p75 p80 t83 t84 p84 p85 p86 p86 t87;d6726e334c9207b5 +t20;0;0 2 0;0;1 2;;b3 s0:2 t1 s0:1 t2 t3 x2 b6 t4 t7 y t8 s0:1 t9 s0:1,4:2 t10;7fc56a42f4684520 +t23;1;0 3 3;0;2;1@3;t2 x2 s2:2,0:1,0:3 t4 t5 p10 p24 t25 x0 t26 t26 s0:4 b29 p26 p27 p28 t29 x1 x0 t29 t30 t31 s0:2,1:2 t31 t32 t33 w0 w2 w0 s7:1,4:1,0:1,2:2 s1:1,3:1,0:7,0:1,1:1,2:1,2:1,1:2,3:2,3:114,4:1,3:2,3:2,2:3 t34 x0 t35 p35 p35 t35 p35 t36 s0:7,0:1,2:3,3:1,3:91,4:4,4:1 x0 x2 t37 s0:7,2:1 t39 s0:4,0:3,0:4,1:3 s3:3,0:8 t40;9e17bd6da707dab6 +t24;46;0 0 0 0 0 0 0;0;1 6 4 2;5@45;t98 t99 t100 y w5 w4 t101 x5 t102 s4:2,0:1,0:2,0:2 s0:6 t103 s1:1,0:1 s0:1,0:1,4:2 t104 t105 t106 s0:1,0:1 s0:1,0:1,0:1 s0:3 w3 t107 p108 t109 s0:1,0:1,0:2,0:1 w1 t110 w3 t111 t115 x4 t116 w1 t116 w6 x4 t118 y t120 t121 t122 t124 s0:3 t125 s0:1,0:2,0:3 t126 s2:3,0:1 t127 t128 p128 p129 p130 p130 p131 s0:2,0:1;1ad85af94ca3dbec +t25;0;0 2 0 2 0 0;0;4 3;1@8;t1 x1 t2 x4 x2 x3 b1 y s1:56,0:1 s0:4,2:3 t3 x4 x4 t4 t5 t6;238bc6d859afcf66 +t26;0;0 0;0;;;w1 s0:1 t1 t1 t2 t3 t4 x0 t5 t6 t7 t8 w0 t9 s0:1 t10 t11 t11 s5:1,1:2,7:3,4:2,1:1,2:1,3:2,6:1,2:2,5:1,2:1,0:3,0:2,0:3 x0 t16 t17 p22 p22;d81025c39bf3912b +t27;0;0 1 1 2 2 1;0;5 1 2 3;;t1 t2 t5 y t6 t7 t7 t8 t9 b7 p11 b14 p11 p11 t16 b21 p16 p16 t21 t22 x3 t23 t24 t25 x0 t26 b27 t27 t28 t29 t30 x2;67f9415a53447d6f +t28;3;0 0 0 0 0 0 0;0;4 5 3;6@10 1@8 2@-;t4 t5 b- t8 b12 y t9 b- t12 b17 b12 w1 y b17 t13 t14 w6 b12 t15 t15 t16 t19 t20 b- b- s0:2 t20 b- b- p21 p21;249db0ba866b2eb8 +t29;3;0 0 0 0 0 0 0 0 0;0;5 1 2 7 6 8;4@- 3@-;b- y b6 b3 w2 t4 t5 x0 y y b5 y t6 t7 w0 t7 t8 t9 t10 t11 t12 x3 t13 b16 t14 b12 w6 t15 t15 t16 s7:2,0:1,2:7 t20 y t23 t27 t27 t28 p28 t29 t33 p34 t38 p39 p40 t41 t42 t46 t47 p47 t48 p48 p53 p53 p54 p54 t54 p54 p55 p56 t57 p57 p57 p57 p57 p57 p57 t60 b62 y y w5 t61 p62 p62 t63 p64 t67 p68 t69 p69;b29825e66393dbf8 +t31;1;0 3 1 0 1 3 0 3;0;4 7 5 2;1@2;t2 x1 t3 t4 t9 x7 w3 t10 w0 x2 t13 x2 b19 t14 p14 p15 t16 t21 s2:2,0:2,2:1,0:2,1:110,3:1,2:2,2:1,1:1,2:2,3:1,1:1,0:1,0:48 t21 x2 t22 y y;6aa07d8345099d32 +t32;611;0;0;;;t612 y x0 b- p612 p664 p664 p665 p666 p668 t669 t672 p672 t672 p673 p674 p696 p697 t721 p721 t722 p724 p725 p725 p726 p726 p727 t727 t728 t729 t730 p730;cfb22d4de63c2f2e +t33;0;0 0 0 0 0 0 0 0;0;4 2;3@5;w3 y t1 s0:8 s0:2 t2 y y t3 y y t4 t9 t10 t11 s0:1,0:1,0:3,0:2,0:1,0:1,1:1,7:1,0:87,0:3,0:8,5:1,0:1,5:100,1:1 y t12 x2 x1 t13 t14 w0 y s0:1 w0 t15 t19 y t65 y t66 y t70 t75 t76 t77 w1 y y t82 y s0:1,0:2 y t83;7aff73eb37756996 +t34;0;0 0;0;1;;x0 b- t1 t2 t3 t4 s0:1,2:5,2:162 x0 t5 t10 t11 t16 t17 p17 p17 t18 t19 t22 t28 p28 t33 p36 p36 p37 p37 t38 p38 p41 p43 p48 t51 p51 p51 t54 p54 t55 p56 t57 p57 p58 t58 t59 t60 p61 p61;8494b85d09d81829 +t35;0;0 0 1 1 1;0;1;4@6;b2 t0 t1 t2 y s0:1,7:2,0:1 t3 t4 y t6 t9 t10 p10 t11 t12 t13;c75b421c0a20542e +t36;884;0 0;0;;1@882;t885 x0 b891 t886 t887 y t888 x0 t889 t890 t894 t895 t896 b902 y t897 x0 t898 t901 t902 y t903 x1 x0;f54f44548b640bc0 +t37;487;0 0 0 1 1;0;2;4@-;b- s0:182,7:2 t488 s0:2,4:2,1:1,2:1 b494 p489 p489 t490 p490 p490 t493 p495 p500 t501 p501 t501 p501 p502 b- t503 p504 t507 t508 t509 t512 t513 p516 p516 p517 p518 p518 t519;40cb2a5a09174c23 +t38;0;0 0 0 0 0 0;0;1;2@6 4@1;x5 t0 x4 t1 s1:3,2:1,0:2,2:3 s0:1 x1 y b4 x0 t31 t32 t33 b37 t34 x4 t34 t35 s1:1,0:1 s0:3,6:2,0:2,3:1,1:1,3:1,2:8,2:1,1:1,2:1 t36 x0 x1 t37 t38 y t39 t44 p45 p77 t117 p119 p120 t121 t123 x3 t124 p129 p129 p130 t131 t132 t136 t136 p136 t139 p140 t141;311770aa9d388825 +t39;3;0 0 1 0 1 0;0;1 4;3@- 2@9 5@2;t4 b3 t5 t6 t7 t8 t9 t10 t15 s0:3 t18 t18 x5 x2 t22 t23 t24 y x2 w3 s0:1 t25 s0:2,0:145 t26 t26 s0:1,1:2 t27 x2 t31 y t32 x3 t33 t34 t35 s1:3,0:3,1:1 x4 y;94bd44c7cb9ba6e7 +t40;1;0 0 0 1 0 0 1 0;0;2 4 3 7;6@2 5@-;t2 t3 w6 t4 w5 s0:1,0:1,0:2 s2:1,0:2,7:5,1:2,1:1,0:1,0:1,1:2,0:1,0:1,4:1,1:1 t5 s0:1,0:3 x6 t5 t6 s0:1 t11 y w1;272c969f74037074 +t41;4;0 1 0 3 1 0 1 2;0;7 4 3 1;2@12 6@3;w2 s0:1 t5 t6 w4 w6 w6 t7 t10 t11 w7 w2 b17 t12 w0 w2 w1 t14 y w0 x6 w6 t15 w5;df273ec92eec41f2 +t43;0;0 1 1 2;0;1 3 2;;w0 t1 t2 w2 t46 w0 w3 w3 s1:2,0:3 s2:1,0:2,2:2,2:1 s1:232,0:1,3:1 t47 s0:1,4:1,2:3 t48 t49 t50 p50 t51 t56 w2 y w3 w3 w3 y x1 w1 b- t57 p58 p58 p94 t95 p95 p96 p96 p96 p98 p98 p98 p98 p98 p98 t99 s0:1,2:3 t100 p101 y;c237d0f328973973 +t44;314;0 1 1 1 1 1 2 0;0;7 5 3 6;4@316 1@-;w0 y t319 b- s0:1 s1:3,2:2,1:1,0:2,2:1,0:1,2:1,2:1,1:3,0:2,1:1,0:1 t320 s0:2,0:1,0:1 t321 s0:1,3:1 t322 t323 s2:1,0:1,2:1 w4 t324 p325 b326 t326 t327 s3:105,2:1,5:1,7:2 t328 t329 p334 t335 p335 p338 p338 p338 t339 t343 p344 p348 t349 p350 t355 t356 p356 p357 t358 p358 t359 p359 p360 t361 p361 p366 p366 t369 t370 p370 t371 p371 p374 p378 p379 p380 t384 p385 p385 t386 p387 p387 p387 p387 p388 t405 p405 p405;8dfa67a4b6d87725 +t45;3;0 1 1 0;0;;1@6;t4 w3 w3 y b- t5 t6 t6 p8 p8 p13 p13 t14 t17 t18 p18;537ec79c16663eaa +t46;0;0;0;;;t1 t2 t2 t3 t3 t7 w0 t9 w0 t10 t11 w0 t12 t65 y w0 y t66 b65 t67 t68 t69 t71 y;0f17aa97489329c0 +t47;487;0 0 0 0 0 0 0 0;0;1 7 5 2 6;;w7 t490 w1 w4 t491 t492 x6 s0:3,0:1,0:1,1:2,0:36,5:1,0:1,0:3,0:2,1:1,0:1,0:1,0:164,6:1,0:1 t493 w1 t494 y t495 w6 t495 s0:2,0:58,0:1 s0:2,0:1,0:2,0:2,0:3,0:1,0:1,0:1,7:4,0:1,0:2,0:3,0:1,0:1 t496 t497 t498 x1 t557 t560 t561 t562 t566 s1:5,0:1 t567 s6:2,0:2,0:1 w4 w6 t568;85ec5420d5939c9f +t48;0;0 0 3 1 0 0 2 1;0;6 3 2 1;7@-;t1 b5 t3 t4 x7 t5 t9 x5 t10 b- t15 t16 b20 t17 p17 p19 t45 x1 t46 b49 t51 t59 x4 t60 t61 t62 x4 t63 t64 t65 b63 t66 t67 t89 b89 t90 x0 t91 t92 b96 p93 p93 t94 t95 p96 t97 t100 t105;4a8981afc43ca7aa +t49;0;0 0 0 0 0 0;0;3 1;4@8;t1 t1 b- b2 t2 t3 t4 t5 t6 y t7 y x3 t8 t9 x5 w0 y t10 t10 t11 t12 x0 b- t13 t14 w4 b- t15 t18 y t19 t20 t23 s0:1,2:4,4:1 t24 s0:1,1:1,1:4,1:1 y t24 w5 w1;ddb8b17ff96bc69a +t50;0;0 0 2 2 2 0 1;0;5 6;2@1 3@5 1@-;b3 w6 y t9 t11 s1:1,0:1 y w1 w1 t12 y t13 w3 w6 y w2;c8408431d11fc0c2 +t51;501;0;0;;;t502 x0 t503 t504 t505 t506 t507 y w0 t507 y t508 s3:1,0:3,1:1 t509 y t513 s0:2 t514 p514 p514 t515 t516 x0 x0;28c796f5c73d3022 +t52;4;0 1 1 0 2 0;0;5 2 1;4@7;w2 t5 w4 t6 y x1 x4 w4 t7 t12 t13 t14 w3 t17 y t17 t18 y t29 s0:1 w2 t30 b- b29 t31 s0:1,1:229 w0 t35 y y y s0:226,0:2,2:1,2:1,4:2,2:1,2:3,1:2,2:2,2:205,2:2,3:2,1:8,1:5,1:2,2:232;7a2b04d2bbc5ef28 +t53;3;0 0 0;0;1;;t5 t6 s6:2,3:3,0:3 t7 t9 p9 t9 p9 p13 t14 t14 t18 p19 p20 p21 b20 s1:1,1:1,1:3,1:3,1:1,1:3,1:2,0:2,1:1,1:6,1:2 w1 t21 s6:1,0:3 s7:3,0:159,0:1,0:1,1:1,1:2,3:1,0:1,0:1,1:4,0:1,1:2,1:3,0:1,0:2,1:8 t22 t23 t25 p28 t29 s0:2 t30 t62 s2:2,6:1,0:1,0:1,1:1,0:1,0:3 s0:1,2:3 t63 t64 t65 p65 p66 p66 p66 p66 t69 p70 p70 p70 t71 p110 p143 p144 t147;9a02ef47e7a40064 +t54;0;0 0 0 0 0 0 0;0;5 3 2 1 6;;w5 t1 s1:1,0:2,0:3,6:1,0:2 s0:3 t2 s0:2 s0:2,7:2 t3 t4 t5 b9 t9 s0:1 s0:1,0:1,0:1 t10 t15 t16 w4 b- w5 w4 y t17 t18 x4 w2 x6 s0:1 t19 s0:1 t20 t21 w1 x2 s0:89,0:1 w0 t22 t27 w6 t28 t29 t30 t31 s0:2,0:1,0:2,0:1 s6:1,0:1 t32 s0:2,0:58,0:1,1:2,3:2,6:1,0:1,5:1,0:2,0:1,0:1,0:2,0:1,0:3,0:7,0:1 s0:1,0:2 t33 t34 w5 w6 s0:1,0:1,5:212,0:2 t40 p40 p41 p41 t42 p42 t43 p43 t44 p47 p50 p51 t52 p52 p52 p52 t52 t53 t54 p54 p54 p55 t56 t57 p57 t58 t59;ca3fee0d0bd9e921 +t56;2;0 1 0 1 0 1 0 1 1;0;5 1 6 8 7 4;2@4;t3 x4 b- w0 b- x7 t4 t5 b11 w2 b- b8 p5 p5 t6 t7 p7 p7 p12 s3:1,0:1 t13 t13 x7 b-;1d2e1df98f64235b +t57;3;0;0;;;y t5 y t5 t6 w0 y t7 b11 t8 p9 p14 t15 x0 t16 t17 t20 w0 t49 t51 t52 t53 x0 x0 t98 t99 t100 t101 y t102 t103 x0;d4f9b13bc11debf8 +t58;827;0;0;;;t828 t829 y x0 w0 t834 y w0 w0 t834 t835 t836 y t837 t838 w0 t839 y s0:1,2:2 b843 p839 p840 t841 t842 t843 t843 t844 b846 p844 t844 t845 p846 p847 y y s0:3 w0 w0 s0:2,1:6 t848 t853 t854 p854 p855 p856 p857 y y;e1949f5dfea3054d +t59;0;0 1 1 1 1 1 1;0;1 6 5;2@4 3@6;t1 w2 t6 t6 t10 b- p10 t13 t14 p14 p15 p15 p15 p20 p20 t21 p21 t26 t27 p27 p30 p30 p30 t31 t32 t33 p33 p34 t35 t36 t37 p37 p41 p41 t42 t43 t44 p45 p45 p45 p45 p45 t46 p46 t47 p48 t49 t52 t53 p54 t55 p55 p56 t57 p57 t58 p107 p111 p111 t112 t114 p115 p116 p116 t117 t118 p118 p119 p119 t120 p122 p122 t123 t124 p127 t132 p132;68f64c3cd451c386 +t60;0;0 1 0 1 1 0 1;0;3 2 5;4@1 6@5;y y s0:2,0:1 t1 s0:3,1:4,1:1,0:8 t2 s1:3,1:4,0:1,1:1 t3 t4 x4 w6 t5 t6 t7 x1 s1:6;9e62269d5c44df21 +t61;0;0 0 0;0;1;2@-;b- t0 x1 y t1 t2 t24 t25 t26 y t26 t27 t28 t29 w1 t30 y t31 y y w0 t31 y t32;054bd41f1685c3f9 +t62;0;0 1 1 1 1 2 2;0;5 3 1 2;4@3;t2 t3 b- p3 p3 t4 p48 p49 t50 p50 t51 t52 p52 p56 t56 t57 p57 t61 t61 p61 p61 p62 p63 t64 p68 p69 p90 p91 t92 p93 t94 p94;13febb8b1bfe6224 +t63;1;0;0;;;w0 s1:2,0:1,1:1,0:2,0:173,1:75,7:1,0:1,0:3,0:2,0:2,1:187,0:2 s0:1,0:6,0:2,3:1,3:1,0:1,6:2 w0 s6:1,2:3,4:4,1:1,0:2,0:3,1:6,5:5,0:1,1:1,0:2,1:1,0:2,0:2,1:2,1:2 y t2 t3 t6 t6 p23 p23 p23 t24 t25 t26 t27 p27 t28 x0 s1:1,7:3,0:2 x0 x0 y y w0 y t28 s0:6 x0 w0 y s1:2,0:6 t29 p29 p29 p29 p29 t30 p34 y y s1:2,1:1,1:1,0:1,0:2,0:6,0:1,2:3,0:2,7:2,1:1,1:1 t35 t38 p41 b41 p41;1a4553543a1af35f +t64;0;0 1 0 0 1 0;0;2 4 3;1@-;t1 t4 t5 t6 b4 x1 x5 s0:1 x3 b10 t7 y t8 t12 t13 t14 t15 t16 t21 y t22 t37 t38 w4 t39 t42 t96 t111 t112 s1:2,0:1 t113 w1 t115 y b116 s1:1,0:1,0:3 s1:1,6:1 t116 s0:1 s4:1,0:3 t117 t118 p120 y t121 t122 t122 p122 t123 t125 t126 p127 t128 w3 w5 y w5 s1:2,0:1 y t129 t130 t133 t134 t135 w0 t135 y t136 t136;36ccace6516af164 +t65;0;0 0 1 0 0 0 0;0;2 4 3;6@2;w6 t3 t4 t5 t6 w4 s1:168,0:1,0:1 y t8 t9 t10 t11 s0:3,1:3,0:1 y s1:2 t12;ac4f8ffb074d4e5f +t66;0;0 0 1 1 1 0 0 1 1 0;0;7 3 6 9;4@5 8@5;t1 y t4 y t5 t7 b- t8 t9 w0 t10 x4 w4 w4 t31 t32 w9 t33 w3 w0 x5 t34 w3 t35;3dbe119116a93749 +t67;2;0 2 0 1;0;2 3;1@-;b2 t3 y w3 w0 t5 t6 w0 t7 t8 s0:8,5:1,3:3,3:1 t9 w1 w3 t10 w1 y s1:1,2:1,0:1,0:1 t11 t12 y t13 t18 w3 t19 w0 t20 t21 t22 t23 t24 t25;16bd84097b7eb8cf +t69;0;0 0 1 1 1 0 0 1;0;1 3 6 2;4@- 7@4 5@2;t1 t2 t3 t4 t5 y t6 t12 t13 t13 t14 s0:1,7:1 s0:1,5:1,0:2,6:1 t15 s1:1,0:2 s0:2 t16 t17 t18 t19 x4 t22 t22 t23 t26 x7 s0:3,1:1 t27 t28 t29 t33 t34 t35 t39 t40 x2 t40 t41 t92 t92 t94 t95 s0:3,1:1,1:2,1:1,7:1,0:3,0:1,1:1,1:1 t96 t97 x7 t98 t99 t100 b102 t101 t132 p132 t132 t137 x5 x3 t138 t142 y x0 t142 b142 s1:2;26a45348adb10323 +t70;1;0 3 3;0;1;2@-;t2 t3 t4 x2 t5 t6 t7 x1 w1 b- p7 t8 p8 t58 p58 p62;189f5690f508cf15 +t71;0;0 0 0 0 0 0 0 0 0;0;3 2 6 8 4 1;5@-;t0 t1 w5 t31 t33 t34 s0:229,1:1,0:38,1:3,0:1,1:1,1:3,0:2 t35 x0 t36 t37 y t38 x3 s0:1,1:1,5:2,3:1,1:2,0:2,1:1,1:1 t39 s1:1,0:1 t40 t41 t45 t56 x6 t58 b58;b1e3cc7cf3ba203a +t73;1;0 0 0 0 0 0 0 0;0;5 1;7@1 6@- 4@3;t2 y b1 w5 x2 t3 x1 x7 b3 t4 y b- t5 t6 b8 s2:1,0:1 y y t9 b- x7 t10 p10 p10 p11 t12 t17 x2 b15 t17 x6 t18;60ce7e0b71982190 +t74;0;0 0 0 0 2 1 1 1 2 1;0;3 7;6@6 2@4 4@5 5@-;t1 t2 w5 w2 w0 w4 w3 w2 w2 w4 w6 t3 w3 y w9 t4 t5 w5 t6 t32 w1 w0 t33 b33 y w3 x5 w4 s0:1 t34 x6 x4 x0 t35 b41 w0 w3 b36 s0:1,2:1,1:1 s0:2 b- w3 w2 b37 w0 w8;6fb37aa39bdfe9f9 +t75;0;0;0;;;s0:1,5:3 s0:1,0:7,1:1,1:3 b- p0 p0 p0 p5 p39 p40 p41 t42 t47 p48 p49 p50 p50;eff4a32b6334c7e0 +t76;4;0;0;;;t5 b7 t6 p7 w0 b7 p9 b9 p9 w0 t10 t10 w0 s0:4,0:3 t11 t12 t13 t13 t13 t17 t55 t56 t57 t61;d4ab593f310021be +t77;4;0 0 0 0 0;0;2 3;;x4 w0 t4 t5 t6 t10 s1:2,0:3 t10 w0 t11 w3 s0:1 t12 x4 w0 t13 w3 y x3 t14 t19 x4 w2 t22 w0 w4 t23 t23 x3 w4 w1 w1;b0744326576a32e6 +t78;0;0;0;;;t1 t2 t3 x0 t4 t5 t5 w0 b- p5 p6 p56 p56 t57 t58 p59 p60 t61 p62 p63 p63 t64 p65 p66 p67 t68 t69 t71 p71 p72 t73 t74 p74 p75 p76 p79 p80 p80 t81 p81 p81 p81 p82 t83 p84 p85 t86 p89;1ca3a0a1de3eb5c3 +t79;0;0 1 0;0;1;;x1 t3 b- t3 p3 p4 p4 t5 t5 p5 t6 t7 p7 p60 p65 p70 t71 t72 t72 p73 t74 p75 t76 t77 t78 p79 p79 p80 p80 p81 p82 t87 p88 p91 p92 p95 t96 p96 p97 p98 t101 p139 p140 t140 t140 t141 p142 p143 t144 p144 t145 t146 p147 t148 p148 t149 t153 t154 p155 t156 t157 t161 p165 p165 p165 p166 t167 p167 t168 p168 t169 p172 p172 t173 p173 p174 p177 t182 p184 p185;d5d61f4d65d05b9d +t80;0;0 0;0;;1@-;t51 t52 t53 b55 p57 t58 t59 t60 s0:2 t60 t61 t61 b- p91 t95 t96;5789fa5f6534f4d7 +t81;0;0 0 1 1 0;0;3 4 2;;t1 b2 t29 b33 t30 w4 t34 t94 w4 b94 t95 t96 t97 w3 b100 b- t98 p102 t103 s0:2 t104 s0:2 y x2;c4a6939c2e959c0b +t82;0;0 0 0;0;1;;y y t18 y y y t19 y y t20 t20 t20 b20 x0 b22 t21 w0 t22 s0:1 y y t23 s1:5,1:1,6:2,1:6,2:3,0:1,0:3,0:6,1:1,7:1,1:1 b25 y s0:1,0:1,1:2,0:8,4:2,4:2,0:1,0:1,1:1,3:1,1:1,0:1,1:1,0:1,5:163 y b- p23 t24 p25 t26;47153d1f0437bbf6 +t84;265;0;0;;;w0 t266 t271 t272 x0 t273 t274 b280 t275 t276 t277 p278 t279 p279 p280 x0 t281 t282 x0 t288 t289 t290 t291 x0 t292 y x0 t293 t294 t295 t295 s0:2,0:2 b- p295 p295 t295 t296 t296 p297 p297 p298 t299 t359 p359 p359 t360 p360 p360 p360 p360 t361 p361 t362 p362 p362 t363 p367 p370 p370 p371 p371 t372 t373 p373 p373 p373 p374 p375 p380 p381 p382 t383 p383 p383 t384 p384 p385 p385 p385 t386;163522bd94cf02f2 +t85;0;0;0;;;s0:2 s0:2,0:1,0:2 t1 t2 s1:2,0:1 t3 s0:89 t4 s0:2,1:87 t5 t6 t7 t8 t12 p12 p12;4b7fda8fea4992d9 +t86;3;0 1 0 0 0 1 0;0;1 3;6@1 4@3 2@-;x3 s0:1,2:2,4:3 t4 x0 t5 t6 p7 t10 p11 b10 s1:1,7:1,0:1,0:2,0:3,0:5,6:2,6:1,0:2,7:1,1:1,0:1,1:1 t13 b- p14 t19 w1 x1 x2 w5 y t20 t21 y t23;419483baf7f8f185 +t87;5;0 0 1 2 2;0;3;4@12 1@8;t6 s1:2,0:5 b6 p7 w1 t8 t9 t10 w4 t11 s1:242,1:6,0:1,4:2,1:1,0:1,0:1,0:1,0:3,5:1,0:1,6:3,4:1 t12 s0:7,7:1,1:1,2:2,0:3,4:1,1:2 t13 t14 t16 y t28 t33 t34 s0:1,1:2 y t37 t47 p47 t48 b48 t49 p49 t50 p50 t51;140d4acb6117c05d +t88;0;0 0;0;1;;s7:168,0:3,1:2 y t3 p4 p5 p6 p9 p9 p10 p15 p19 p19 p19 t23 t24 t27 p28 t29 t30 p31 p33 t34 p39 p40 p40 p40 t40 t43 p71 p76 t79 p79;d1d0d90fbb8e1abc +t89;0;0 0 0 0 0 0 0 0 0 0;0;5 3;7@- 1@7 9@7 8@3;t1 t2 x4 t6 y y x0 t9 t10 t11 s0:1,0:6 t12 s0:1,0:1,0:1,0:1,0:2,0:3,0:1 t12 s0:1,4:3 t13 t14 t15 p16 t20 t23 p23 t24 t25 p25 p25 p26 t27 p28 t31 t32 t33 t34 y s0:3,0:1 t38 t39 t41 t42 s0:2,5:1 x3 t43 s0:1 y s0:2,0:1,2:2,0:1 t44 t44 t48;5ec50e348a98591a +t90;0;0 0 1 1 0;0;4 2;3@5;t1 b- b1 t2 y s6:5,0:1,0:3,0:2,1:3,1:2,1:1,0:1,0:1,1:2,2:1,1:1,1:2,1:1,0:1,1:1 t3 s2:1,0:1 t4 t5 t6 y y x3 w3 y;d1fb6db97a264083 +t91;0;0 0 1 0 0 0 0 0 0 1;0;3 6 1 9 4 5;7@6 8@7 2@-;t1 t2 y t3 t4 y t5 t6 b- t7 w5 b- x9 t11 b17 s0:2,1:4 s1:1,5:2,1:2,0:2,1:1,1:1,0:1,1:158,0:1,1:1 y b15 b11 w1 t13 w2 t14;936126daafcfd9c8 +t92;3;0 0 1 0 1 1 1 1;0;3 6 2 4 7 5;;x6 s0:1 t4 w0 x3 w2 t62 y t63 b63 w0 b63 w1 t64 t65 t66 x1 y w0 w2 x0 w6 w2 b65 y b- p66 s1:140,1:1,1:67,1:7,1:1,1:7,1:3,0:2,1:4,1:2,1:1,1:1,1:2,1:2,1:2,1:2 t67 s1:1,1:8,0:7,1:1,4:5,0:2,2:3 t68 t69;ebeaf712c8b5bdfb +t93;0;0 3 1 3 0 3 3 2 2;0;1 7 5 4 6;2@- 3@8;t1 t1 y t2 t3 w1 t7 w8 t8 b6 s6:3,0:1 t9 w2 t64 t65 w1 t66 t71 t72 p73 x8 t74 t75 t76 t77 t78 t79 t80 p80 p81 t82 p82 t82 p85 t86 p86 t87 p90 p91 t92 p92 p92 p92 t93 t94 p95 p96 p98;364931334e75a5fe +t94;5;0 0 0 0 0 0;0;5 1 4;2@13;t6 t7 t8 y t10 t11 t12 y y t13 b11 b- t14 x3 t15 s0:1 s0:2,0:3,2:1,2:1,0:1,0:2,0:2,1:1,0:1,2:3,1:1,0:103,2:1,0:2,0:1,6:170 t16 s0:2 s1:3,1:1,1:1,1:2,2:173,2:1,1:1,2:1,0:1,2:1,2:1,4:1,5:2 t17 t18 p18 t19 p20 p56 p56 p57 t58 t59 t62 p66 p66 p70 p71 p73 p73 p74 t74 p74 p74 t78 t80 p98 p98 t99 t100 p100 p100 p100 t101 t102 t103 t104 t105 p108 p108 p108 p111 p112 p113 t113 p114 p114 p114 p117 p117 t118 p119 p119 p120 t121 p121 p121 t122 p123 t124 p124 p124 p124;15a9c673caf06251 +t95;0;0 0 0 0 0 0;0;2;5@3 4@1 3@1 1@-;t1 x5 b1 t2 t3 y t53 w1 w0 t54 y b58 s0:205 t55 t56 s0:1,0:3;00d9b4c193c30b1b +t96;0;0 0 1;0;2 1;;t1 t2 y x2 t3 w2 t4 t5 y w0 t10 t11 w1 s7:3,0:1 t12 s0:2,4:2 t13 s5:104,4:1,1:2,0:2,1:1,1:1,1:154,0:6,4:1,1:1,1:1,7:3,1:3,1:1 t14 t15 p16 t17 p17 t18;06864c961fcbf62f +t97;0;0 1 1;0;;;x2 b4 t1 p1 p2 t3 p3 p3 p4 s0:2,0:1 b3 t5 b3 p6 y t7 s5:1,0:2 t8 s0:1 t9 t10 y b9 t11 t14 t14 t15 w1 t16 t17 w1 t18;a986cbb5125798c4 +t98;0;0 0 2;0;1 2;;t1 t2 x1 b5 s0:2,1:1 t3 b- p3 t37 w0 y t37 y w1 t38 t39 t40 t41 b46 t42 p42 p42 p45 p45 p45 t50 y t52 t53 y t54 t55 t55 b54 y y y t56 w0 b55 y t57 t60 p60 p60 p61 t62 t63;5a1113dfbfc02d77 +t100;0;0 2 2 0 2 2 1 0 1;0;2 7 3 1;4@-;x4 x0 x1 t1 x0 y t2 t8 x2 x2 t9 x5 t10 x8 t11 x1;223d7141df8c7c3a +t101;5;0 1 0 0 1 1 0;0;6 4 2 3;;t7 w6 y y y t8 y y y x0 y t9 x4 t10 y w0 y x6 t11 t12 y y b- y;2ffb74ea4bf67601 +t102;0;0;0;;;t1 x0 t2 b- t3 p4 t5 p5 t6 p6 p6 t7 t8 t9 p10 p10 p10 p10 t15 p15 t56 p56 t57 p62 p63 t64 p64 t65 t66 p66 p67 p68;4e6db2cd5d3e0257 +t103;4;0 0 0 0 0 1 0 1 1;0;8 1 7 4;3@- 5@8 6@10;t8 b10 y x1 b- x5 x1 t9 t10 x1 b15 x5 w3 t11 s0:1,3:2 w6 x6 x8 t14 t15 t16 s1:3,0:67 s0:1 t17 p17 p18 y x7 t19 b17 y y t20 b19 t20 b- s0:2,0:3,0:2,0:1,0:2,0:1,0:1,0:186,0:2,0:3,0:1,0:1,0:3,0:1,0:2,0:8 w3 t21 t22 x8 t23 y w0 b25 t23 x0 x6;dee3060ca00eccb1 +t104;0;0 0 0 0 0 0;0;5;2@1 1@-;t1 x0 t2 s3:1,0:1 t3 x5 x2 b- b6 t4 p9 b13 w1 t10 t11 t12 t15 t16 p16 t17 s0:2 b17 b- t18 p19 w1 t20 b21 b25 t21 t25 t25 t26 t27 t30 t31 s0:2,5:1 t32 t33 t34 x2 t35 p39 t40 t78 b- b79 p79 t80 t81 w5 w2 t82 t82 x0 w1 t83 t84;6e62d61642f446c2 +t105;1;0;0;;;t2 w0 t3 s0:2,0:8 y b- t4 p4 t5 p5 t5 t65 t65 t66 t67 p68;559d0e4fe58e1f94 +t106;0;0 1 1 0 1;0;4;1@- 2@6 3@-;b- p3 p4 t7 p48 t48 t49 p50 p50 t51 p52 t53 t54 p54 p54 t57 p57 p58 p58 t59 p59 p60 t61 p61;a1e6e5105996ccb0 +t108;1;0 1 1 3;0;3;1@9 2@-;t4 t5 t9 t10 b15 t11 t12 p12 t16 t17 b- p17 p21 p21 p22 t23 t24 t25 t26 p27 p28 p28 t32 p32 p33 p35 p35 p36 p37 p38 p39 p39 t40 t45 t46 t50 p50 p50 t54 t55 t60 p61 t62 p63 p64 t65 p66 p67;7eb3de2568f764ce +t109;4;0 2;0;;;w1 b- t5 p6 p9 t10 t11 t12 t12 t12 t13 p14 t15 t17 p18 t19 p24 p25 t26 t27 p27 t28 t29 p33 t34 t35 p38 t39 p40 p41 t42 p42 t43 t44 t44 p45 p45 t46 p46 t47 t50 p50 p51 p51 t52 p52 p53 p53 p85 t86 t87 p87 t88 t93 p93 t94 t95 t95 p95 t99 p101 p101 p101 p102 t107 t107 p108 p109 t110 p110 t111 p111 t112 t113 p113 p114 t115 t116 t117 p117;67089f807235bc39 +t110;0;0 0;0;1;;t1 t2 t6 w1 x0 t7 w0 b12 b- t8 t13 t14 b- p15 p15 p15;cef7fe3bdd4ced98 +t111;962;0 0 1 2;0;3;1@962;b967 p963 b962 p963 b968 p1014 w1 b1018 b1020 t1015 t1016 t1016 t1017 t1018 t1023 t1024 b- t1024 t1025 b- p1025 p1025 t1026 p1026;e7fd1ce39540d49b +t112;3;0;0;;;s1:1,0:1 t4 w0 t9 p10 w0 w0 y s1:3,0:2 s0:1,1:4 y b9 p10 y w0 b14 p11 t11 p12 t13 p13 p13 t18 p21 p22 y y y b25 p33 p34 t35;0129412afc3af82d +t113;0;0 1 0 1 0 1 0 0 1;0;8 3 4 6 5 2;;t1 s1:1,0:1 s0:1,0:1,2:1 t2 t3 t4 t5 t6 t10 y b14 x2 y w6 t11 t12 t13 x5 y t14 p17 p18 t19 t20 p20 p20 t21 t25 t26 t27 s1:2,0:1 s0:2 t28 s0:3 t29 t30;8db3bb22abaebe15 +t114;0;0;0;;;x0 t5 b8 p5 p5 p5 p5 t6 t11 y t12 b13 p68 b74 p69 p69 t73 p75 b- t79 p79 p79 t80 t92 t93 p97 t98 p98 p99 t100 p100 t101 t102 t102 t103 p103 t103 t104 p104 t105 p106 t107 t108 p109 p110 p110 t111 t116 p116 p117 t122 p122 p122 p122 p122 p147 p148 t149 t150 t151 t152 t153 t154 p154 t155 p155 p155 p155 t156 t159 p159 t162 t163 p164;9372945f93647a49 +t115;5;0 0 0 0 0 0 0 0;0;6 4 3;5@8 7@11 1@7 2@4;y b- t6 t7 t7 t8 t9 t10 t11 t12 t13 t14 w6 w3 b- t15;e7de247b80788be1 +t116;5;0 1 3 1 0 0 3 0 0;0;4 1 7 6;3@8 8@4;b8 t6 t6 x3 t7 x8 b13 t8 t8 x5 y t9 t10 t11 t12 w2 x2 t13 b16 w0 y t14 t15 b19;86b42957e6b4b223 +t117;0;0 2;0;1;;y t24 t24 t25 b23 t29 t30 t31 b- p32 p33 p34 t35 p36 t37 t38 t39 p40 t41 p43 t44 t45 t46 p47 p47 p48 p49 t50 t51 p52 t53 p53;7e9fb1bb0281209c +t118;2;0 0 0 0 0 0;0;3 2 5 1;;t5 t6 t6 t6 b11 t8 b- b10 t13 b14 b12 b15 t18 t19 b23 t20 b21 s0:6,3:3,0:1,0:2 s0:1,0:1 w5 b23 y t21 x0 b26 y b27 t22 s0:3,0:91,0:3,0:1 t22 b26 p22 t23 y t24 b28 t24 p24 t27 x2 t28 w2 b27 t29 y w2 s0:1,0:2,0:1,0:3,5:1,0:2,0:1,4:1 t30;7aa023ac8984ae1c +t119;0;0 0 0 0 0 0 0;0;6 5 2 4 1;3@-;t1 t2 w3 t3 s0:1,0:1,2:3,0:1,1:1,0:1,0:1,0:1,0:1,4:244,0:2,1:2,0:73,0:1,0:1 t4 s0:1,1:3,1:1,1:3 x5 t5 s0:82,0:2 t6 t7 t8 t8 t9 t10 t11 t12 t13 w0 b- t17 s0:2 x0 t18 t19 t19 w1 t20 y t21 t22 t23 t24 b23 w3 w2 w6 y t25 t27 x1 x0 t27 y t28 t29 t30 y x5 t34 w3 t39 t40 t45 t46 y b50 t47 t48 x6 t49 t50 t50 t51 s0:2,0:1,5:1,0:1 t52 t53 t54 b58 t55 t56 t66 p67 t68 t70 t70 t71 t72 w2;b39e3c0c825100ae +t120;5;0 0 0 0 0;0;1 4 3 2;;w3 s0:1,0:1,0:3,1:3,0:1,0:2,0:1,0:1,0:5,3:2,0:56,0:3,7:1,0:2 t6 y t7 t8 t9 b14 w3 b14 t10 t13 p13 t14 p14 t15;d68b4bca9efd468d +t121;0;0 0 0;0;2;;y w1 t5 x2 t6 w1 b10 t9 t10 b- y b10 p10 w0 t11 t14 t18 y b- t19 t20 w1 x0 b22;736d0c9ab4a52003 +t123;0;0 0;0;1;;b- t5 t9 b- t10 p11 t12 t13 t14 p17 p17 t17 t18 p18 p19 p20 p20 p20 t21 p21 t26 t27 p27 t28 p29 t30 p31 t32 p33 t33 t33 p34 p34 t35 p36 p36 t37 t38 p38 p39 t69 t70 t71 t72 t112 p112 t113 p118;d037b258a6304969 +t124;1;0 1 2 3 2 0 1 1;0;7 5 2 4 3;1@-;y t1 t1 t2 t3 t4 t7 t7 y t8 t9 s3:4,0:1,0:2,2:2,5:2,1:1,6:1,6:6,1:5 s0:1 t10 t11 y t11 w6 t12 t15 t16 w5 s2:1,0:3 s0:1 s0:1,2:2 t19 t24 y t25 t30 s2:1,2:1,0:2 s0:117 s1:4,1:3,3:2,3:1,2:1,5:59,3:2,1:4,1:3,6:1,3:1,1:2,0:1,4:1,2:1 s0:2,3:1,5:1,0:2,0:1,1:1,3:3,2:8,5:3,2:1,3:1,5:1,0:2 t31 t72 s0:2,0:1,2:1,2:2,1:5,2:3,0:2,1:1,0:1,0:1 t73 s0:1,2:240,2:41,2:1 t74 s0:2,2:2,0:1 t75 t76 s0:2 t78 s0:4,1:3,0:3,0:3 t79 s7:1,1:1,0:3 s3:1,3:3,2:1,2:5,0:1,2:1,3:2,3:2,1:2 t80 s0:8,2:1,3:1,6:4 s0:1 y t81 w4 y s2:3,2:2,5:2,2:3,2:1,2:8,5:1,5:169,2:2,3:1,6:2,0:2,1:1 s2:187,0:3 t81 t81;70b59117edceff13 +t125;0;0 0 0 0 0;0;2 4;;t1 t2 w2 s1:1,0:1,3:1 t2 t3 t4 p5 t36 p36 t37 t38 t42 t43 p43 p43;591d18fc06ba5cee +t126;0;0 0 0 0;0;2 1;;w2 t1 w0 s0:2,0:1,3:2 s0:1 t2 s0:2,0:3,0:5,0:1,0:1,4:6,2:4,0:2,4:1,0:2,0:3,6:7,0:3,0:1,0:3 s0:1,0:2,0:1 t3 t4 t6 t7 t8 x1 s2:2,0:1,0:6 b9 t9 w0 t10 p10 p10 p31 t33 x3;8220512c44bee545 +t127;0;0 0 0 0 0 0 0;0;6 2 1 3;4@- 5@7;t40 t41 t42 t43 t43 t44 b49 y s0:1,0:1 s0:1,0:1,0:3 t45 s0:2,0:3 s0:6 t46 t47 t48 t48 t48 t49 t50 t53 t54 t59 t60 x6 t61 y t62 x4 t63 x5 y;8f88aa043c0528f3 +t129;50;0 2 3 2 1;0;3 2 4;1@53;b- p50 p50 p50 t51 t55 p56 t57 p57 p74 t75 p76 t79 t80 t81 p81 p82 p83 p83 p83 p83 p85 p85 p90 p91 p91 p91 p91 p91 t92 p96 p97 p98 p99 p99 t100 p100 t105 t106 t129 t130 t131 p131 p132 p132 p133 t134 t134 p134 p134 t135 p135;fd886fdd1aff3a38 +t134;0;0 0 1;0;1;2@4;t54 b59 t57 s1:1,0:2 t59 b- p59 p59 t60 t61 y t62 p64 x2 x0 t65 t66 s7:1,7:1,0:2 b68 t67 t68 p69 p71 x1 t117 t118 x2 b117 y s0:1;1904507e043b4553 +t135;352;0 0 0 1 0;0;3 1;;t353 y s0:2 t354 t355 t356 s5:3,0:1,1:2,0:1 t361 w4 t362 s6:1,1:1 t367 t368 p417 t417 t418;a42d77b4e2ce73c1 +t136;5;0 1 2 2 2 1 0 1;0;6 4;5@- 3@9;s1:1,0:1 s0:1,1:1,2:1,7:5,2:2 b- s0:1,2:1 t6 s0:2,2:1,0:2 t7 t8 t8 y s0:1,1:1,0:3 w7 s2:2,0:1,2:3 y t12 s0:2 t13 s0:8,5:1,0:1,1:3,2:3 y w1 s1:1,2:1 t14 s2:6,1:1,7:148 t15;3eae8d90fcca6b67 +t137;865;0 2 2 2 3;0;1 3;2@866 4@-;t866 t910 b912 t911 t911 t912 t913 w3 t914 b919 p914 t915 t915 t920 t921 t922 w4 t925 w4 b- t926 t927 p927 t928 p928 p928 t929 p929 p932 t933 p933 p933;015f8e9adf7fc86f +t138;3;0 0 0 0 0 0 0 0;0;5 2 6 4 1;7@2 3@-;x7 t4 t5 t6 t7 t10 t11 y t12 s0:1,0:3 t13 s0:1,0:5,7:4,0:1 t14 t15 t17 t17 w3 b- t21 p22 p22 p23 t28 b28 x3 t35 t36 b35 t37 w6 t92 t93 w4 t94 t95 x1 s0:3 t96 s0:1,0:3 t97 x0 t98 t99 t100 s0:1 t101 s5:2,0:2,0:1 t102;9e4e16fb0a258545 +t139;0;0 0;0;;1@1;x0 t1 x1 s0:1 s2:1,0:1,1:1,1:1 b3 x1 s2:1,0:1,2:2,2:3,1:3 b- p1 p1 p2 t7 p8 p9 p9 t10 p14 t15 t16 p16 p16 t17 p18 p19 t23 t27 t28 p28 t28 p28 p29 p67 p67 p70 t71 p71 p71 t72 p72 t72 p73 t76 p78 p78 t81 p81 p82 p82 t83 p83 p83 p83 t84 x0 t87 p87 p88 t89 p89 t90 p91 p92 t93 p93 p93;a59ce33ba611f8af +t140;0;0 1 0 2 2 0 1 2;0;5 1 2 7 6;3@- 4@1;s0:166,1:1,1:1,2:2,4:4,2:2,0:1,1:1,1:1,5:3,2:1,0:1 s0:1,2:2,6:1 t1 s0:1 s1:1,0:1 t2 t3 t3 t7 w3 t8 t9 y t12 b- s0:2,1:2,2:3;c89120d4f02d16bf +t141;0;0 0;0;1;;t1 y t2 x0 b- s0:2 t3 t3 t4 t4 t6 b- t7 t8 t9 p12 t15 t16 t17 t18 t19 p19 p20 t63;bf1dc9d3bab2c600 +t142;0;0;0;;;t1 t2 s0:1,1:6 t3 t42 p42 p42 t43 p43 p97 t98 p98 t99 t100 p100 t101 p101 p104 p104 p105 p105 p105 p105 t107 p107 t108 p108 p109 t110 t110 t115 p115;f841fe70b4d0605e +t144;3;0 0 1 2 1;0;2 1 3;;s0:1 t4 t5 t6 t6 t7 t9 t12 t13 t14 s2:1,0:8,3:59 b13 w1 b12 t15 w2 t16 t17 t18 x2 t19 t20 s0:1,3:1,0:1 t21 x0 t22 y t23 p24 s3:2,0:1 b22 t25 t25 t26 p27 t28 s2:4,0:1,2:1 t29 p31 y y t32 y t33 x2 y t38 w4 b36 t39 t40 w4 b41 t43 w1 s3:1,2:1 t44 w4 t45 t46 t47 p47 t52 y t54 x2 t55 t55 p57 p58 t59 t60 b60;2318a68bf90a7d82 +t146;0;0 0 2 3;0;2 1;3@5;y t0 t1 x0 t2 t3 t4 y t5 b- x3 y t6 t7 t8 x3 w2 x2 t9 x2 y y t10 x0;e70eb7bac791f927 +t147;5;0 0 0;0;;;t7 t8 b13 p9 p10 t11 p13 t15 t16 s0:1 b20 p17 t18 t19 p22 x2 b- p22 p22 p22 p22 t23 p23 p25 t26 p26 p26 p26 t30 p30 p30 p31;9779397a4f436056 +t148;1;0;0;;;t3 t4 t7 y t7 t10 t11 b- p33 p34 t35 p35 t36 p36 t37 t38 p42 p43 p43 t43 p43 p43 t44 p82 p82 t83 p83 p84 t88 p88 p88 p88 t89 t90 t91 p91 t93 t94 t123 p124 p124;2d5eb757d7675a9d +t149;0;0 0 0 0 0;0;;2@7 3@-;w4 b- t1 p1 t2 p3 p3 p3 p4 p35 t36 t37 t39 w1 t40 t41 t42 t44 w3 s0:1,2:2 t45 b47 w3 w0 t50 p51 p52 t53 p54 t55 t56 p57 t61 t62 p62 t63 p63 t64 w1 w3 x3 w2 s0:3 t65 t66 w3 w3 w1 w3 t67 w3 s0:1 w4 t68 w3 w0 t69 w2 w1 w2 y b- t73 b76 x3 w2 t74 t75 w0 x4 t76 t77 w3 t78 t79 t80 s0:1,1:2 t81 s2:1,2:1,0:1,3:1 t82;94619303a2e93617 +t150;1;0 1 1 1 1 1 0;0;5 4;6@1 2@4 1@-;t2 x3 t3 b4 t4 t5 x1 t56 t57 x2 t58 t59 b59 t60 t61 t79;1a50b81f215aa5fa +t151;2;0 0;0;1;;s4:1,0:1 x1 t3 t4 p4 p4 p4 t5 t6 t7 y x1 x0 t11 t12 p12 p32 t33 y t35 x1 x0 s0:2 x0;c92e22b9b3416dd4 +t152;5;0 0;0;1;;x1 b- s0:1,0:1 s1:1,0:1,1:2 b- t6 p18 t19 p20 t21 t22 t23 p23 p25 p29 t31 p32 p33 p33 p34 p39 p39 p40 t41 p41 p44 p44 p47 p47 t51 p51 t52;b24c1e8ab2bb1ade +t153;0;0;0;;;t42 y b48 t43 t44 t45 t46 t47 p48 t49 t51 y t52 t53 x0 t54 w0 t55 s3:62,0:3 t60 t61 t62 t97 p98 t99 t100 t100 p100 p100 t102 t106 t107 t108 t109 p109 t110 t110 t110 t111 p111 p111 t112 p113 t134 t136 p137 t138 p138;8d3748667ca4b41b +t154;0;0 0 0 0 0 0 0 0;0;1 4 3;5@5 7@-;x5 t1 w7 b- x6 t27 t28 t29 b32 y b27 t31 t34 t35 x6 t36 t37 w0 x4 y t38 x7 b- y t39 w1 b43 y b39 b45 w7 t40 w0 y w3 t41 t42 b45 b40 w3 t45 w2 t46 t47;dbd76a3e309df7b5 +t155;2;0 0 1 0 0 0 0;0;5;3@4 2@- 4@7 1@7;y t3 t4 x2 t27 s0:72,0:2 b26 t28 b30 t29 t31 b- y b34 t32 t33;47adb3a6910ade3f +t156;0;0 2 2 0 0;0;4;2@7;t1 w0 w4 t2 w2 t4 t6 b- t45 t46 t48 t49 t52 t52 s4:121,0:2,2:1 t53 w4 w1 t55 t58 t59 p60 t61 p74;63f3dd9ce4c217f3 +t157;1;0 1 0 1 1 2 1 0;0;2 6;5@6 4@-;t2 t5 t6 y t8 t9 t40 b42 t40 y w2 t52 t112 t113 t115 b117 w2 t116 w5 t117 t120 s0:179 t121 w5 w1 t122 t123 y y y t125 x3;9e8ba1d65ae08193 +t159;0;0 0 0 1 1 0 1;0;3 4 1 5 6;2@3;t0 t1 t2 w2 t3 t4 t5 b- b11 t6 b- x6 x3 t7 t12 t13 t14 t28 t29 t30 t31 y s0:1 t33 w5 w3 t33 t60 t65 w4 t67 t68 b- s1:7,1:1,0:1,2:1,1:1,3:2,0:1,1:2,1:1,0:1,0:1,1:3,1:1,1:1,1:7 s2:3,0:1,1:1,0:2,5:2,0:2,1:3,0:1,1:2 t73 t74 t75 t75 b- t76 t76 t81 w4 t82 b82 t83 y t114 b120 p118 t119 t120 w4 y w1 y t121 p125 t126 w1 x4 s0:2 b- t127 y;12bc7e795060817c +t160;4;0 0 0 0 1 1 1 1;0;6 5 1;4@- 2@- 7@8;w2 s0:2,1:2,0:2 t4 w1 t5 y w0 t6 t13 y x4 t14 b19 t34 b38 t35;3716134e007b6d1a +t161;0;0 1 1 1 0 0;0;2 4 5 1 3;;y x2 y t1 b- w5 y y t2 t3 t4 t5 y t6 w3 t7 t8 s0:3,0:1 t9 y t10 t11 t11 y;af168229af809442 +t162;0;0 0 1 1 1;0;2 1 4;;t1 t2 w4 x3 t3 t5 t48 t49 t50 t51 s0:1,0:8 t52 t53 y t54 t55 t56 t57 w3 t58 t59 x4 s0:1,1:2 t60 y s1:3,1:1,0:7,1:1 s1:1,0:1 t61 s2:1,0:1 t62 t63 t64;980dcb232af6b823 +t163;0;0 1 1 1 0 0 1 0;0;4 3 2;6@4;b6 y t1 w1 b- p6 t7 b5 t8 b11 p10 p10 t11 b- p11 t12 p13 t14 t15 t16 t17 p25 t25 t26 p84 t85 p85 p86 p86 p86 t87 t88 p90 t91 p91 p91 p91 p91 p95 p95 p95 p95 p96 p96 p96 p97 t98 t99;67b162360ee0ee4a +t164;0;0 2 0 1 2 1 0;0;1 3 5;2@3 6@6 4@-;t4 x4 t9 w4 y w1 s0:1,2:2 t10 t11 w1 t14 y b13 t15 s2:2 w1 s0:49,0:1,2:2 t16 t16 w0 t55 w6 t56 y w3 x3 t57 b61 y w6 t58 s6:3,4:6,1:1,2:1,1:131,3:1,2:3,3:1,2:2,0:223,3:6,3:3 s0:1,6:1,6:1,6:2,6:1,6:1,6:5,6:217,6:1,6:1 y t59 s0:3 t60 s1:1,0:1,0:1,1:2,3:1,2:6,3:2,2:8,0:1,2:2,0:1,3:1,3:2,2:5,1:3,0:1 t61 t62 t63 t64 w0 y t65 t66 w2 y t66 t67 t71 s2:1 t72 t73 t74 t75 t76 t77 y w3 b77 t78 t83 b- w4 t84 y t85 w2 t86 s1:3,2:3,0:1 x2 w5 t89 w0 b91 w5 w1 t90 t92;251814f0b9ace228 +t165;4;0 0 1;0;2;1@-;s0:1,1:2,1:2 y x2 x1 t5 t6 y t7 t9 t10 t11 t12 t15 s0:3,4:2,1:1,4:1,4:1,1:2 s1:5 x1;ba90e2c441991554 +t166;0;0 0 0;0;1;;t2 s0:48 w2 b- x0 t3 t4 t5 b11 p6 p9 p10 t11 s2:136,0:1 t12 t13 t14 p14 p14 p14 t16 p16 t20 p21;58347fdba42942a1 +t167;0;0 0 0 0;0;2 1 3;;b1 y w1 w3 y w0 b- t1 t1 w0 b- t2 b- y y y b4 t3 t8 t9 w1 t10 x1 t11 w2 t12 t13 t17 y w3 b- t18;1916f49210fae0a4 +t179;0;0 1 0 0;0;3 2;1@-;y y b- t1 b1 y t2 s0:1,7:1 t5 t9 p9 t11 p11 p11 t16 y w2 t17 p18 w2 y y y t23 p24 t28 t28 s6:2,1:1,6:2,3:1,2:5,1:2,3:1,6:1,5:1,3:2,4:1,0:1,3:1,0:1,3:2 t29 p29 p29 t30;ea101b5b3ea4321a +t183;0;0 1 3 3 0;0;;2@-;w1 b6 t1 p1 t2 t3 t3 p4 p4 p5 p5 p5 p10 t12 w1 t13 t14 t15 t16 t17 s0:2,2:3 s0:1 t18 x2 s1:1,0:2,3:2 s4:1,5:1,1:3,2:6,5:2,3:3,2:2,0:2,0:2,1:2,3:1,3:1,5:2,3:1,1:1,2:1 t19 s0:3 s2:2,3:1,0:1,1:1 t20 t21 p22 p22 t22 p22 p23 t24 y t28 t29 t30 t30 p35 p37 t37 t37 p38 s3:1;706d45e3837e7083 +t188;0;0 0 2;0;1;;t1 w0 t2 t3 y t4 t5 b- y s0:1 s2:5,0:1 t6 t7 p7 t8 p9 p9 p10 p13 t13 p13 p17 t18 t19 p20 p21 p21 t22 p22 t26 t27 p27 p31 t32 p32 t33 t34 p35 p35 p35 t36;b892af601f2bcfd4 +t198;5;0 3 2 0 1 2 2 2 2 2;0;7 1 5 6;9@9 4@3 8@- 2@9;t6 t7 y w5 x8 x9 t8 y y x0 t9 x3 t10 t14 s0:6,1:6 w6 t15 t16 t17 x2 x6 t18 x9 w6 x5 w0 t19 t20 x4 x8 b19 t74 x1 x0;9e9e640de1d6177b +t210;0;0;0;;;b- t1 t1 p12 t13 t14 p15 t16 t17 t18 p19 t23 p23 t24 t25 p26;9969c3c6d3fd43ba +t217;0;0 1 3 2 3 2 3 1 3;0;1 3 5 4 2;6@- 7@-;t1 t2 w4 s0:1,3:1 t3 y t7 t7 w7 y t8 t9 b- x8 t10 t12 t13 b- p13 p14 t15 t16 y t17 t17 p17 p18 w1 y t19 p19 p20;d2b60a8b739e6641 +t222;124;0 0 0 0 0;0;;4@132 1@-;b128 p124 p124 p125 t129 t130 b136 p130 t131 p132 t133 t134 b139 t135 t135 t137 t138 x4 b141 t180 b179 b179 p182 x3 t183 t184 b183 b- p185 b185 p185 b188;13d795b9f2141740 +t226;1;0 1 0;0;2 1;;w1 t2 y t3 x0 b8 y y y t4 y x1 y y y b4 p6 y b9 t10 y t11 y y;9f14621451090b68 +t229;0;0 0 0 0;0;2 3;1@-;t2 t3 s0:1 t4 s3:3,6:3,0:1,2:6,1:1,3:2,0:1 t5 t6 p6 t11 p12 t13 p13 p13 p14 p14 p14 t15 t16 p16 t17 p22 t23 p23 t24 p24 t25 p25 t26 p26 p26 p26 p26 p26 t27 t28 p28 p29 t30 t31 p32 t33 t34 p34 p34 p34 t35 p37 p38 t39 t40 t41 p42 p42 p42 p42 t43 t100 p101 p102 p102 t148 x1 t203 p262 p264 p265 p265 p265 p265 p265 p265 p266 p266 p269 p269 t271 t272 p273 p273 t274;2af6a0776a1ed679 +t252;0;0 2 1 0 0 0 2 1 0 0;0;8 4 3 7 1 5;2@5 9@-;t1 b5 t58 b- x2 t59 b58 b58 t60 b59 b65 t61 y b- t65 b70 b68 b66 p66 b70 p66 t67 p67 p94 x4 b98 t95 b99 b100 p95 t96 p96;473e3d4f1ede51ab +t275;0;0;0;;;x0 b- t1 p1 t2 t3 t8 t9 p11 t14 t14 t15 p15 p15 p15 p16;601213e88031165a +t276;0;0 0 0;0;;2@- 1@-;t1 t2 s0:4,1:2 y t2 t3 t4 t5 t6 y t7 t8 t9 p10 s0:2 y t11 t14 b14 p14 t17 t18 b- p18;9a8439124fe09485 +t298;4;0 2 1 0 2 2 2 1 1;0;7 2 1 8;4@4 6@11 5@4;y y t5 t6 w1 b- t7 p7 t7 t8 p8 p8 p9 t10 t11 t11 t12 p12 p12 p13 p13 p13 t14 t15 p15 p16 t17 t18 t18 t18 p18 t19 t20 p21 p21 t22 t23 t24 p25 t29 t30 p31 t32 t33 t69 t70 p73 p74;435b05068e5943f5 +t306;2;0;0;;;t3 s1:2,0:2 t19 w0 t20 t21 p22 p22 t23 t24 t25 p28 y t29 p29 p29 p30 t31 y t32 x0 y t33 p34;53f0cfb7f3f45af1 +t322;3;0 1 1;0;2 1;;y t8 t9 t10 t11 s0:2 t12 s0:1,2:2 t13 t14 t18 t20 t24 t25 p25 p26 s0:2,2:1 t29 t30 p31 x0 t32 t33 p33 p33 t34 t35 t36 p36 p37 t38 t39;40403fc6096c9190 +t327;0;0 0 0 0 0 0 0 0 0;0;5 3 6 7 2 8;;t1 w0 s0:1,1:1 t2 y t3 b6 t6 p7 b- b5 w6 t8 t9 b10 b- b10 b- t10 t14 p14 p14 p15 b- s0:3,0:3 t16 p17 t18 b21 t20 b20 t21;a1221de3ee32645d +t332;1;0;0;;;t2 t3 b6 p3 t4 t5 p5 t6 y x0 w0 b6 p6 x0 t65 b65 p65 b66 p65 t66 b- p66 t67 t67 p67 p72 p73 p73 t74 p75 t76 t77;ab5d176ce2a57cc3 +t356;2;0 1 0 1 0;0;3 1;4@6 2@-;y t3 t7 b- b11 t7 p7 p8 p8 t9 p9 p9 p9 p9 t9 p9 t11 w4 y t14 t15 b- b17 p15;8395e472c49d6749 +t366;5;0 2 2 1 1;0;2 3;1@4;t5 t6 s0:2,2:1 b4 p7 w2 t8 t10 b11 b13 p10 p10 p11 t12 b15 t13 b19 t17 t18 t19 b- y t20 b18;b71542d5836352c2 +t400;4;0;0;;;y t5 b- p5 p5 t6 t7 t8 p9 t11 p15 t19 p20 t21 p21 p25;d03438a204b423e2 +t402;0;0;0;;;y t1 y w0 s0:3 w0 w0 s1:1,0:6,1:2 t4 b4 p4 b- t5 t5 p5 t6 t7 t7 p8 p8 t9 p10 t11 p14 p16 t17 t18 t19 t20 p51 t52 p54;f9c9fc00fc776380 +t426;494;0 0 1 2 1 0 0;0;6 5;1@- 4@497;t498 b502 b497 x4 b- p498 b- p524 x6 b522 p524 t525 b- t526 t527 p528 t533 t534 t535 p537 t538 p538 p539 p539;aef3b182f9610c14 +t437;0;0 0 0 0;0;1 3;2@-;w2 t1 t2 w2 s2:1,0:1 t3 w1 t4 p5 t5 t6 t7 t8 p8 t12 p13 t14 p14 p15 b- b- t16 p16 p17 t18 p21 w1 t21 t21 b- t22 p22;14c6f083a583a0ad +t438;0;0 3 1 3 0 0 2 2;0;4 5 1 7 6;2@8;t1 y y x4 b3 b4 t1 t3 t26 b29 t27 w5 s0:1 x2 y t28 y s7:1,2:2,0:1,7:3 s2:1,3:1,0:4 y t29 y b- b31 b33 t30 t35 t36 y t37 y b37 p37 b- t38 y t39 y y b38 b42 p39 t40 s0:3 t43 y b45 w4;18de84b869a8824b +t442;451;0 0 1 0;0;3;2@-;b453 s0:1,0:1 t452 s0:2,2:3,7:1 t453 s1:4,0:1 t454 t455 p462 p463 p463 t465 t469 b471 t473 p473 t474 b472 w3 b475 t475 p475 p475 t476 t477 t478 p482 p482 p482 p483 t484 x1;74c708533a08e207 +t454;0;0 0 2 1 0;0;4 1 3;2@7;s2:1,0:1,0:1,3:2,2:1,2:1,1:1 s3:1,2:1,1:1,0:3 s1:1,4:1,1:1,1:3,0:1 s2:2,5:1,2:1,0:3,3:1,2:1,3:1,1:1,0:1,3:1,6:1,1:1,3:1,3:2 t1 x2 t2 t3 b- p3 p3 p55 p60 t61 t64 t65 t66 s1:1 x2 b64 t69 t70 w3 t71 y b- p72 t72 p73 p77 p77 t77 p78 t79 p79 t80 p81 t82 t83 t84 t84 t85 t85 t85 p86 t87 p90 p90 t91 p91 p92 p92 p92 t93 t94 t95 p96 t97 t98 p98 p99 t100 t101 t102 p102 p103 p103 p103 p104 p105 t105 p107 p135;549f5c1ef4a9b967 +t494;696;0 2 0 2 2;0;3;4@694;t697 x4 t700 y t702 w0 x0 b- t702 p702 p703 t704 t705 p705 t705 p705 p709 t710 p711 p711 p712 t712 p759 p760 p760 t761 t762 p762 p762 t763 t763 p763 p768 t769 t770 p770;da268a5bd427057c +t502;0;0 0 0 0;0;1;3@-;t3 t4 t5 b10 y b3 p6 b5 p6 t7 t8 t9 t9 t9 b7 p9 b9 p13 t14 b- b19 t15 p16 p16 p16 p20 w3 t21 t24 w2 w0 t25;9408606e2f48e7ea +t505;0;0 0 3 1 2 0;0;5 4;;t1 s2:2,0:3,7:1 t2 t3 t4 t5 y t6 t7 y b13 t8 p8 t13 w5 t14;a2027820574a7a66 +t516;3;0 0 1 0 1;0;4 2;3@8 1@-;s0:1 s0:2 t4 s2:31,0:1 s3:1,0:2 t5 t6 p9 t10 t11 y t12 p12 p13 t14 y y w1 b- t15 p16 t17 t18 p22;e7e46eb5f82e9429 +t534;0;0;0;;;t2 t15 t16 t17 x0 y t18 b- p18 p18 t19 p19 p19 p20 p20 t23 t25 t26 p28 p28 p28 p29 p29 t34 t35 t35 t36 p39 p40 p41 p41 t42 t47 t48 p49 p49 p49 p54 t55 t55 p56 t57 p61 p62 t63 t66 p78 p78 t79 t80 t81 p82 p86 t87 t87 p87 t87 p89 t90 p90 p90 p95 t95 p96 t100 p100 p101 t102 p102 t103 t103 t104 p105 p105 p105 t106 t107 p107 t108 t109;f4eca714323766b5 +t535;324;0 1 1 3;0;1 3;;t325 b- t325 p326 t326 t327 t328 p328 t329 t330 p330 t335 p335 t336 p336 p336;5f4fd8f5a30e88ed +t564;0;0 2 0 2 0 2 3;0;1 2 6 3;4@7;t1 t2 s2:1,1:1,0:1,1:1 t3 s0:2 t4 s4:2,0:1,2:3 t5 t6 p6 p7 p8 t9 t10 b- b15 p10 t11 t11 p11 t52 w3 b58 t55 p56 w6 t57 t61 p61 p61 p61 p62 s2:1,1:1,0:1 w5 t63 t63 b61 w4 w0 t64 t65 t66 b71 y w2 t66 b71 b70 b- t67 t93 b92 b97 p93 t94 b92 w1 w0 t95 t99 b104 t128 t129 b129 b135 t130 x4 s2:1,0:6,3:1,1:2,3:88,3:8,1:1,1:1,3:1,1:1,2:1,0:1,1:5 b- x2 t131 p160 w2 b- p160 p213 p214 p215 p216 t217;0a6787b1367104b2 +t602;0;0 1 1 0 1 1 1 1 0 1;0;7 1 8 4;3@- 2@- 6@5 5@- 9@-;b- t1 w1 t2 y t3 b8 p3 p3 p3 p3 t4 p4 p4 t5 p6 p8 y t13 b- p13 t14 p14 p14 p30 p31 p31 p32 t32 p44 t45 t46;da803a13c50507a3 +t633;3;0 2;0;1;;b3 p3 t3 y x1 s0:1,0:1,0:1,0:1,2:1,2:2,0:3,1:3,0:5,2:1,1:2,0:1 t4 t4 y t5 t6 t6 t7 w0 b- t7 p8 p9 t11 x0 t12 w0 b11 p12 w0 y t13 b- p14 p15 p15 p15 t16 p21 t26 p26 t27 p28 t29 t34 p35 p35 p36 p36 t37 p38 t40 t41;8b5ba4d055ba853a +t645;0;0 0;0;;;t1 t6 t7 x1 b- t8 p8 p8 t8 p13 p13 t14 p14 t17 p18 p18;d667af4a7fb21d19 +t648;3;0 2 0 0 2 0 1 2;0;3 6 4;1@- 2@- 7@6;b2 y b1 t8 b6 b11 p8 b6 p8 b- p28 b- p33 p33 t34 p34 p35 p76 t77 p78 p79 p80 p80 p85 t86 p91 p91 p92 t94 p114 p115;cdfb8e50015f3f48 +t662;2;0 0 0 0 1 0 2;0;5 4 6;2@-;t3 t4 t5 s2:1,0:1 t10 t11 w1 t12 t13 t14 t15 b19 t16 t17 p18 t19 t20 y s0:1,6:3 t21 s2:1,0:1 t22 t23 t24 b- t26 t27 t73 t73 t74 t75 t77;d26a8cc921fe7023 +t664;0;0;0;;;b- t4 p4 t4 t5 p6 t7 p8 t9 p9 p9 p14 p15 p17 p17 p18 t18 t19 t20 p20 t21 t23 t24 p24 p24 t25 p28 t33 p34 p47 p47 p48 t49;f0bbad255c293c82 +t667;0;0 0 0 0 0;0;2 3 4;1@7;t3 t3 b7 x4 t4 t5 x2 t10 b12 b8 b8 t11 b10 b- b- t12 b- b10 b12 p13 b13 t14 s0:2,0:1,4:1,0:2,0:52,5:3,0:2,0:1,0:1,0:1,0:2 s0:2 b13 t15 b14 w4 t49 b49 b51 p49;3e918e76c3728ceb +t685;0;0 1;0;;;t1 t2 t7 t8 x0 b- t9 t10 t15 t16 p17 t18 t19 t20 p21 t23;4cc291229c852e57 +t700;0;0 0;0;;1@-;t3 b5 t3 t8 x1 t9 x1 t10 t10 t11 b11 p11 s0:7,0:175 s0:3,0:7,1:1,0:1,1:5,0:1,1:2,1:1,0:2,1:3,0:1 x0 y;af8eff5b805ff5ad +t710;2;0 3;0;1;;b- p3 p8 p8 t9 p9 p9 t10 p10 p10 t39 t43 p44 p44 t56 t57;19edc049e1162427 +t716;0;0 2 1 1 1 0 1 3;0;5 4;1@- 6@7 3@-;w3 y t0 w1 y w7 s0:1,3:5 t1 s2:2,2:3,0:1 t2 t3 t6 p6 p7 p8 y t12 p14 y t18 p19 p19 t20 t53;6b536f9932d2cdff +t717;2;0 3 2 3 2 2;0;2 1;4@- 3@-;b3 t3 w0 y t4 y y y x4 y t5 w4 t6 s3:3,0:3 t7 s0:2,7:2 y b7 p7 y t10 b9 p10 b- p10 p12 p17 p18 p19 p19 t20 t21;2e0dd6ff3a3514f3 +t724;0;0;0;;;w0 t0 t1 y s0:1,1:2 t2 t7 p7 t8 t9 t9 t9 t10 t11 p33 b38 p36 p62 p63 b69 p63 p63 p63 t64 t64 t65 t67 p72 t73 p73 p73 t74 t75 t76 t77 p77 t78 b81 t79 p80 p80 t84 t85 p85 t86 t87 t89 t90 t91 p91;2d7d15f1d3c1f005 +t726;1;0 3;0;;;t2 t2 t6 t7 t8 t9 t10 t15 y t16 t17 b- p17 t17 t18 p18 t19 t20 p20 t21 t22 p22 t22 p23;3a2e39564977977d +t735;829;0 0 0 0 0;0;2 3 4;1@827;s1:2,0:2,1:1,1:2 t830 t831 t832 p832 t835 p835 t836 t841 t842 p843 t843 t843 p887 t888 p888;f18130c5238204dd +t778;0;0 0 0 0 0 0;0;5 3 1;2@8 4@-;t1 x3 t2 y b6 s0:2,1:1 t3 t4 t4 t5 w3 b10 w5 t6 p6 p7 s1:3,0:3 t8 t9 t10 p10 p10 p11 t12 t13 w4 t14 w0 s0:2 s0:1,5:71,5:1 y t15 t16 w3 t17 t18 p18 t20 t21 p22 p24 t28;86c14d50d18c4770 +t782;3;0 0 3;0;2 1;;b6 b- p5 t5 p5 p6 s0:1 s0:2,2:2,3:1 t7 s0:39,2:8 s0:1,2:1,2:1 t8 t9 s0:1,1:1,2:1 t10 p11 w0 y b- t12 p13 t18 t23 t24 p25 t25 p26 p75 t75 p76 p76 p77;b9007cd77361b2a5 +t790;60;0 0 0;0;1;;b58 t65 t66 y y w0 b65 b67 p66 t67 w2 t68 b69 b70 p69 y;7150720d740c36fd +t801;0;0;0;;;t2 t3 t4 t5 t6 t6 t9 b7 t9 p9 t10 b- t11 t12 t13 p14 p14 t59 t60 t63 p95 t96 p97 t98;f64d4aab3dd9e78d +t823;4;0 0 0 0 0;0;3 1 2;4@4;t5 s2:2,0:2,1:2,0:1,0:1 b3 b- t6 t7 p38 w3 b- y y y w2 y w2 t43 p59 t60 p61 t62 t65 b- x4 x3 t66 y t67 p67 p67 t68 p69;be1e9f51fa869da9 +t825;0;0;0;;;t1 w0 b- p1 p1 p6 p6 p6 p7 p8 p67 t68 t69 p69 p69 t70;19dcfc3aaaec3394 +t845;4;0;0;;;t5 s0:3,1:1 b- p8 p8 t10 t11 t11 t12 p13 t13 p13 p13 p13 t17 p17;c4da3276a23b6ade +t848;0;0 0 0 0 0;0;2 1 3;;t1 w2 w2 t2 x0 t4 t7 b- t8 w3 t9 t12 b- x0 y w3 b10 t13 y t14 w1 t15 x1 w0 t16 t17 t18 t19 y t19 t20 t20 t24 x1 b26 x3 b24 t62 s0:255,2:1 t63 b- s0:1 t64 t68 t69 t70 t71 b74;8abcf029ad94994c +t901;5;0 1 1;0;2;;x0 t6 t8 t9 t10 t14 t15 w2 w2 t16 t17 t18 b17 p18 t19 t20 t21 b25 t21 p21 p21 t22 p23 t23;8175ad186a6147ed +t902;5;0 0 1 0 2 1 1;0;2 3;6@- 4@- 5@8;t6 t7 x5 b10 s1:1,0:1,2:1,0:3 y b9 p9 b12 s1:4 t13 s1:1 s0:3,2:3,0:111,1:1 t14 s0:1,1:3 s1:1 t15 t16 t17 s1:2 y y t19 s2:3,2:169,2:2,2:1,2:2,2:6,1:1,2:1 x4 t20 x3 t24 s3:3,2:1,2:2,0:255 t28;932525f017a01644 +t921;967;0 2 0 1 0 0 2 0;0;4 5 7 1;6@- 2@- 3@-;t968 t972 w2 s2:5,0:2 w1 y t977 t979 s0:6,4:1,1:1,2:1,1:1 t980 s7:5,0:1 y b984 y t981 b980 p981 s2:1 x4 s2:2,2:2,0:43 y t986 s2:1 y;8b1f1700bd9ada4d +t929;0;0 1 0 1 1 1 1 1 0;0;3 1 2 6 8;7@1 4@-;t1 t2 w7 w6 w8 w1 t3 w8 t5 w7 t6 t9 w2 t10 w2 s1:1,0:2 t11 b- t12 t17 t18 x2 b24 w4 w8 w4 w1 t19 w8 w7 t20 t21 t22 t23 w6 t24 b29 t25 w5 b23 t30 t31 w2 b37 x8 x6 w2 t32 t34 t35 s0:2,5:6,5:3 s0:2,1:191 w6 t36 x1 b37 w4 w8 w8 t37 w4 w8 w1 y y w1 w5 w8 t38 t39 b- t40 t40 b46 w6 w1 w3;7d8e13b075cc7ab1 +t935;4;0;0;;;t5 t5 t5 t5 t7 t50 w0 t50 b- p51 p69 p70 t72 p72 t73 p73;7d7e6f571baa2bd2 +t960;0;0 1;0;;1@5;t0 t1 t2 t4 t5 t9 b- t13 t14 p14 t15 p16 t17 t21 t22 p22;fb84029262cb70cd +t963;0;0 0 0 2;0;1;;x0 x0 t1 x3 t2 x2 t3 b- x3 x1 x1 y b- p4 p4 t5 t6 t11 p11 t11 p11 p11 p13 t13 t14 p14 t14 p14 t15 p16 p16 t17 p17 p17 p18 t19 t20 t21 t22;edb548f3d7dd06df +t972;0;0 0;0;1;;s0:7,2:1,1:2 s0:1 t1 s6:2,2:81,0:1 s0:1,2:1 t2 t3 b9 t4 p8 p9 x1 t10 p10 p10 p11 t12 p14 p14 t15 t20 t21 w1 t21 b25 b23 p21 t24 p25 b23 t26 p27;f5d18046315f4d71 +t975;5;0 1 0 0;0;3 1;;y s4:2,0:2 t6 s0:125 t7 t8 y t9 y s1:2,0:1,0:2,0:1 t10 s0:3 t11 y t11 t12;fce65c9005b23030 +t988;0;0 0 0 0 0 0 0;0;4 3;2@-;s1:1,0:1 s0:2 t1 t2 b- y t2 t3 y y y s2:1,0:1 x2 y y t4 b6 y y y y b10 p5 p8 t11 t12 t13 t13 t17 p18 t19 p19 t20 y y t21 p21 t22 y y t23 t27 t28 t29 p29 p30 t31 p31;2fab2083fd63e658 +t1023;2;0 1 3 2 1 1;0;1 2;3@3;w2 t3 t8 s0:2,2:1 t11 w0 t12 t13 t15 x2 t16 w1 t50 t51 t52 t53 w0 t54 x5 x3 s0:1,4:1,2:16,1:3 t55 t56 t57 p57 p59 x5 t60 t61 t82 t83 t84 x0 t88 b94 t89 p90 t91 t92 t92 p92 t93 p93 t94 s2:74,6:1,6:3,6:2 w4 x4 t95;37b25653f963fcee +t1025;0;0 1;0;1;;b- t1 p1 p1 p4 p5 t5 t6 p6 t7 t10 p10 p10 p15 p16 p17;960c904b0c1a1c44 +t1036;0;0 1 1 0 3 1 2 3 2 2;0;6 8 9 5 2 3;7@8 4@-;t1 t6 y x4 t7 s0:2 t8 s0:1 s0:1,2:1,3:1 y t9 t62 b65 t67 t68 y s2:3,6:2 t69 t70 b73 y t70 y t75;91e0224cca90d7c9 +t1039;0;0 0 0;0;2;;t1 s0:1,2:2 t2 s1:3,0:1 t3 s4:2,0:1 t4 t5 p6 p7 y y t8 p8 p8 p39 t40 y y y t41 p41 t42 t73 t74 t75 t76 t77 t79 t80 t81 p81 p81 p86 t89 p92 t93 p93 t96 t100 y t102 p103 t104 p104 t104 p105 t107 p107 t108 t109 y y b109 t109 t110 t115 y w0 t116 p117 p117 p117 p118 t119 t120 t121 t122 t122 p123 p124 w1 w1 t127 t128 t131 t135 p136 t141 t142;7d12bd2a9fe1b65b +t1078;5;0 3 0 0;0;3 1;2@5;t6 s0:1 x1 t10 x0 t11 s0:1,5:1,2:170,1:3,1:1,3:2,3:5,2:1,1:1 t12 s0:2,3:2 t13 s0:1,2:6 t14 t15 t20 p21 p21 t22 y t27 t28 t29 b27 w2 t30 p30 p33 p33 p33 p34 t35 t36 x1 y t37 p40 t42 t45 p45 t46 t47 p48 p48 p48 p48 p48 t49;1fe6014396d918e9 +t1092;0;0 2;0;1;;t2 b- p3 t4 p4 t5 p5 t6 t6 p7 t8 t8 p8 t11 t12 p12 t13 t14 p14 p14 p14 p14 p15 t16 p19 p23 t24 p24 p24 p25 t26 p26;83bec99495dd61ca +t1115;4;0;0;;;b5 p4 p9 s0:2 b9 p9 b8 t10 b- t11 p12 p43 t44 p44 p44 t45;90e5fb24e6c49bd9 +t1127;0;0 0;0;1;;t1 t2 t3 t3 w0 s0:1 s1:1,0:2,4:1 t4 y t5 t6 w1 t7 t7 w1 y t8 t66 t67 s0:2 t68 p68 t69 s4:1,0:1 s0:2 b- w0 w1 y s0:1,0:1,7:3,1:1,3:1,1:2,1:8,0:3,1:1,5:1,1:1,2:1,1:3,1:2,0:166 y s0:1,1:1,0:2;1a3f6e65cf625cb6 +t1136;4;0 2 2 1 1;0;;4@12;s2:2,0:1 t8 t9 p10 p11 t12 t13 t14 t15 t16 p16 t16 t16 t17 x4 t19 t20 t21 t22 p22 t23 t24 p27 p27;4e4c396b3ad308b5 +t1170;0;0;0;;;w0 t1 y y s1:1,0:1 t2 t4 t5 p5 t6 t7 p10 t11 t12 w0 t13;ff701a23cf33df98 +t1171;0;0 0 1 1;0;2 3;1@-;t1 t2 s0:1 t3 s0:1,6:1,5:3 t4 t5 t6 t7 t8 p9 p10 x3 b10 p10 x2 b12 t11 t12 p13 t13 t14 p14 p59;4cb705f838a07797 +t1180;3;0;0;;;t4 b4 p4 w0 t8 t9 s0:1 x0 w0 t9 t10 y y x0 y x0;577a2271abf18ef1 +t1201;5;0 0 0 0 2 2 2 2 2;0;3 5 1 4;7@13;t6 t7 y s1:1,0:1,3:3,2:1,7:1 t8 b9 t8 t9 p14 t14 t15 t45 b45 x2 s0:3 t46 t47 t49 t50 b- t51 t52 b- w0;eb6a397bb382dd71 +t1217;3;0 0 0;0;2;1@3;t4 b- y t5 b10 s0:3 b4 p6 t8 b- p22 s1:1,1:1,1:1,0:255,0:1,1:1,0:1,0:1 s7:1,0:1,1:1 t23 s0:1 s0:1,1:3,1:1,0:4,1:4,1:2,0:2,1:1,1:2,1:2,0:3,1:3,1:2,1:2,0:1 t24 t25 t26 p26 p26 p26 p26 p30 b- t31 p32 p32 p32 p32 p32 t33;723d190025a340f8 +t1224;0;0 0;0;1;;t4 t39 s0:2,0:1,0:224,0:1,0:1,0:1,0:161 t40 t91 y s0:1,5:2 t92 t93 t94 t95 p100 t101 p102 y t103 p134 t135 t136 p136 p136 p136 t137 t138 y y b- t139 t140 p140 t179 p179 p179 t184 p185 p186 w0;c0657eb67fb07516 +t1230;2;0 1 1 1 0 0 0;0;1 6 2 4;5@9;w5 t5 w2 w5 t6 t7 w0 y w4 t8 w3 w0 s1:3,6:4,0:1,1:1,0:2,6:1,0:3,1:3,1:1,0:191,1:2,0:1,7:2,0:2,1:3,1:1 t9 b9 w4;31ad8ba231c6e85b +t1231;0;0 1;0;1;;x0 x0 x1 y b- p0 t1 t2 t2 p3 p14 p15 p15 p16 p17 p21 p21 t22 p22 t23 p24 p26 t26 p26;34c188117115950d +t1241;0;0;0;;;t1 t2 s2:2,0:1 t6 t7 p7 p7 p7 p7 t8 p8 t9 t10 t11 p14 p15 x0 y y t16 t17 p18 b- t19;847175b4aa161109 +t1246;1;0 3 0 3 3 0 3 2 3 2;0;9 1 8 7;3@2 2@6 5@9;b6 p1 p3 t4 t5 p5 t6 t7 t8 b11 t9 t10 y b16 s2:1,0:1,2:1 x0 t15 t16 t17 s1:1,3:1,2:2 s2:1,1:1 t18 s2:2 s2:2;a049941ad31e2c39 +t1255;0;0;0;;;y t1 b7 p2 t52 s0:1 t53 t54 t55 t57 t58 t61 t62 b60 p62 y;928447d4da1698e4 +t1273;0;0 2 1 0 2 0 2 0;0;1 7;4@3 3@- 6@8;b1 t1 t2 s0:1 w6 t6 b9 w7 t7 t8 b8 x6 w3 x1 t9 t13 s2:1,0:5 x3 b- t18 b23 b18 p19 t22 s0:1 s2:1,1:1,0:1,6:1,0:3,1:1,0:2,4:1,3:2 b22 p22 b- t23 x4 s0:1,2:1 t23 w3 x3 t25 b- t26 s2:8,2:3,2:8 s1:2,0:2,2:1 b- t27 w3 x3 b32 s0:2,1:1 t28 t29;a2ceea7c0576c6da +t1280;0;0 0 0;0;2 1;;y w2 y s1:4,0:1 y t1 t2 p3 t4 p5 p5 p7 p8 t9 t10 t12;3b67697dc5c6cbbe +t1299;342;0 1 0 0;0;3 2;1@344;t343 t346 t347 y t348 t349 t350 t351 s3:1,0:1 b351 t352 t353 t355 t356 t360 x1 t365 p365 p368 w1 t369 t370 b370 y b370 t371 t372 w0 y t373 t375 t376 t398 t399 p399 t400 t401 t401 p402 w2 t403 t404 b404 t405 p405 p405 p405 t408 w0 b406 t409 t410 t414 t415 p415 p424 w3 t426 w3 t427 p457 t458 t459 t460 t465 t469 t470 t471 t472 s0:1,0:7,0:112,0:2,0:8,1:2,0:69,0:6,0:1,1:3,0:3,0:2,1:3,1:1 s0:1,1:1 t473 t474;d732ff369e421424 +t1316;0;0 1 1 0 1;0;1 4;;w2 t1 x2 t2 w3 b1 t30 b- t31 t32 t33 p33 p34 t35 p35 t36 t37 t38 t38 t41 t46 p47 t50 t50;3704d84136f974eb +t1349;1;0 0 0 1 0;0;4 1 3;2@4;x3 x2 x3 x3 x3 s1:2,0:1 y x4 t2 y y x2 t3 b9 p8 s0:1 w2 x3 s0:2,4:1 y t66 t68 s0:1,5:2 s1:1,0:1,1:81 s0:1,2:1 t69 p69 p69 p69 t70 y b- t71 t72 w3 x0 x3 y b70 t73 p93 t152 x0 y t153 p157 t158 x4 s0:2,2:1 t159 t160 b164 w4 s0:2 x3 s2:2,0:1 y;55a7ca06146c6d39 +t1373;0;0 0 0;0;1 2;;t1 w2 s2:2,0:1 y x2 s0:3 y w1 t2 w1 s2:3,0:2 s2:2,0:6,2:3 t3 s0:1 s2:183,0:1,2:3 t4 t5 t8 p56 p56 t57 p57 p61 p61 t61 p61 t62 p62 p62 p62 p62 p63 t64 p64 t65 p65 p70 p70 t71 t72 t73 p73 t73 t74 p74 p74 t74 t74;26a385362ace42b2 +t1380;2;0 1 1 1 1;0;4 2;1@-;t3 b- t8 t9 p9 p13 p13 t18 p18 t22 p22 t22 p22 p23 t23 p24;62d6d73862b898a7 +t1382;0;0 1 0 0 0 1 0 1 1 0;0;9 5 7 3 4;2@6 8@- 6@1;x5 y y x0 x3 s4:1,0:2 y w0 x8 t1 y t2 p2 p2 p2 t4 t5 t6 x8 t7 x6 y t8 p8 t57 t57 x2 y y t58 x1 x0;606c3a156c22b7c0 +t1393;0;0 0 0 0 0 0;0;2 4 5 1;;b4 t4 w4 t5 y t6 t9 x5 b- b11 w4 t10 t11 t12 b- b12 b15 b10 t13 b18 b16 t13 t14 t15 t15 s0:1 s5:1,5:1,0:3,0:5,0:2,1:2,0:1 b16 t15 p16 y b15 b20 p16 x0 y b22 p17 p22 b- y t23 b26 b- p26 y b25 t27;f360f637baa4feb4 +t1408;1;0;0;;;y y t2 b- p2 t3 p3 p3 t4 p4 t5 t6 p8 p8 p8 p9 t13 p16 t16 p17 p17 p18 t19 t20 p20 p28 t29 t31 p32 t37 p44 t46 p46 t47 t49 p50 t51 t56 t57 p57 t58 t58 p58 t58 t63 t64 p65 t66;19814bdbd0bc1fcf +t1421;5;0 3 1 2;0;1 3;2@11;t6 w2 t7 s0:1,2:2,3:2 y w1 t10 t11 b15 p11 t11 p16 t17 t18 w0 t19 t20 t21 w3 s0:1,2:1 y t22 t23 t24;12186cfcd09e9a3a +t1430;0;0 0 0;0;;1@6;t0 t1 y t2 b2 t3 t4 y b5 p4 p5 b10 t64 y y s0:110,0:5;2ad96c04c9852b5b +t1431;0;0 0;0;1;;x1 x1 s1:1,0:2 t41 p45 b- t50 p50 p51 s0:1 t73 s0:1 s0:2 t74 t75 s0:3 y t80 t81 s0:1,1:3 b81 t82 x0 t83;6e8640b4ba996d44 +t1438;5;0 1;0;1;;x0 t8 b12 p8 p9 p9 p11 p12 t12 s1:1,0:1 x1 y y x1 w1 t13 y y x0 y t14 t15 t16 t17 y t18 t19 t20 w1 y t20 t24 x1 y t24 y t24 t26 y t29 y t29 y s0:1 y;d0038abfd929a8d9 +t1444;0;0;0;;;s1:235,0:1 t1 s1:1,0:1 t2 t3 t4 b- p9 t9 p10 t11 p13 t14 p14 p15 t16 t17 t20 t20 p21 p22 p22 p26 t28 p28 t29 t30 p31 t32 p32 p33 p33 p35 p36 p37 t38 p38 t39 p39 p39 t40 p40 t40 t42 t43 p43 p44 p44 p46 t47 p47 p47 p48 p48 t49 t50 p90 p90 p90 t91 p96 p97 t98 t99 p112 p113 p113 p113 p114 p167 p168 p168 p168 t169 p174 p174 t175 p176 p176 p177;bb74c3d8418b8042 +t1446;0;0 3 3;0;1 2;;x1 w0 y y s1:2,4:2,5:3,2:1,2:1,0:1,2:1,0:2 x1 w1 y t3 t3 t4 p5 p5 p6 t6 t7 p10 t11 w0 b13 p11 p11 t12 t14;a570e1abf2e5b388 +t1467;0;0 3 3 1;0;3 2 1;;t1 t2 t3 x2 t3 w3 t4 x2 t5 t6 w0 w2 t7 b- p7 p7 t12 p15 p15 t16 p21 t22 t22 t22 p22 t22 p23 p23 p23 p24 p25 p28;8b47413a482c7ecc +t1491;766;0 0 0 0 0 0 0 0;0;7 5 1 2 4 3 6;;x1 b771 x4 t767 b769 x6 b767 x2 x6 b766 b- b765 b773 t768 b767 x1 y b- t769 b768 t770 b- t771 b772;2273b91331269597 +e0;1;0;0;;;t3 t4 t5 t10 t11 t18 t19 x0 t20 b22 p72 t73 t74 w0 t75 w0;32f0e97b1c840247 +e1;3;0 0 1 0 1 0 1 0;0;1 2 7;4@4;b- t40 t41 t44 b- b- p44 s1:1,1:1,1:2 s0:3,0:1 p44 p45 p45 p46 p46 s1:3,4:1,7:1,1:3,6:1,2:3,2:1,0:5,5:6,0:1,2:4,0:2,1:2 p46 p67 p86 b- b85 p86 w2 x7 b-;62f995d9dd242ee2 +e2;0;0 2 3 0 1;0;2;1@1 3@7;b6 s1:3,2:2,0:1 p0 p0 p0 p0 p1 s3:7 s3:1,2:1 p1 s0:1 p2 s3:2,2:1 p3 s1:171,1:1,1:5,1:1 p4 p5 p5 s0:143 p6 s7:1,1:3 s1:1,1:8,1:1 s2:1,2:3 p7 s0:3,3:2,0:2,6:1,2:1,0:1,0:2,0:1,0:2,0:2,2:1,1:2,1:1,1:1,3:3,3:1 s2:1 p7 p8 p9 w4 t10 s3:1,0:3,3:2;7b06913db60a6517 +e3;2;0 0 0 0 0 0 0 0 0 0;0;9 2 4 5 3 8 1;6@- 7@-;w5 w7 w8 t3 t4 t5 s0:1,7:7,0:1 s1:67,0:2,3:3 s0:1,1:2,6:1,0:2,1:201,1:2 s0:1 t6 s0:1,0:1,1:1 t7 s1:1,7:3,1:7 t8 t9 p9 p10 p11 p11 p11 p11 p12 p12 p13 p14 p15 p18 s0:4 p19 s0:1,0:1,0:1,0:2 p20 p21 x5 t22 w1 t23 w4 t24 w6 t25 w2 s1:6,0:3,1:1,3:1,7:2,0:3 t26 t27 p28 p28 p29;763417f9904cdc5c +e4;0;0 0 0;0;2;;x1 t1 t2 t5 t6 t11 t13 t14 s2:3 s0:3,0:101,4:1 t15 t18 s0:6,0:1,0:1,0:197,0:1,0:2,1:3,0:1 t19 s3:1,0:1 t20 t21 p22 s0:3,0:3,0:1 w0 s0:1,6:1 s0:1,1:1 t23 s0:1,0:53,0:3 p24 s0:1,0:2,0:7,0:1,0:5,0:1,0:2,0:2,6:1,0:1 t25 p26 t27 s1:2,0:3,0:3,5:2,0:1,0:1,0:3,0:1,0:1,0:1,0:1,7:1,0:2,0:1 s0:2,0:1,0:3,0:2,0:1,0:1,0:2 t28 s0:2,0:2,0:1,0:1,0:2,0:1,0:3,5:1 b27 t33 x1 t34 t35 t36 t37 t38 t39 t40 t45 t46 t47 t50 t51 t52 s0:1,0:1,0:5 s3:1,0:1,0:1,0:1 b- t53 t54 s0:1,6:5 p55 t56 w1 t57 p58 p59;a57ec9065e3d7c5f +e5;752;0 0 0 0 0 0;0;3 4 2 1;;x5 y w2 w3 w4 t794 s0:2 s0:2,0:1 t795 s0:23,0:1 s7:1,7:5,7:3 t796 t797 s0:2 s0:3 p797;fad959295c71768f +e6;3;0 0 0 1 1 0 0 0 1;0;7 1 4 8;3@-;t4 w4 t5 w0 x3 x1 t6 b5 s0:2 s0:1,3:205 t7 s0:4,0:2 s0:1 t8 t9 t10 t14 y s1:1,0:1,1:1 t31 t36 t37 x7 x8;1c27cb710e0cb8e7 +e7;0;0 0 0 0 0 0;0;4 3;2@- 1@5 5@-;t1 t2 s0:2,0:4,0:1 s0:2,0:240,0:1,3:3,3:1,0:2,0:2,0:1,7:3,5:2 t3 s6:3,6:2,6:2,6:1 s1:2 t4 t5 s5:1,0:1 p6 s0:1,0:3 p7 s5:1,0:1,0:2,0:2 p8 p9 s0:2,0:1,0:2,0:1 p9 p9 p9 p9 p9 s0:1,3:1 p10 t11 w5 t12 p13 t14 s0:2 s0:1,0:2,0:2,4:1,0:1,0:2,0:1,0:7 p19;2f2f1d8a5ef707d1 +e8;0;0 0 2 1 1 1 2;0;4 3 5;6@4;t3 t4 t5 w6 t7 t9 t10 x4 x6 t11 x5 t53 t54 w0 x6 t56 s2:3 t57 t58 x1 x2 t59 t63 t64 s0:1,2:1 t65 s1:1,2:2,2:1 t66 s2:1 t67 t68 x2 t71 t72 x5 t73 s1:3 t74 t75 t76 t77 t80 t81 t86 w6 t87 t88 t93;dc06020e25d417a1 +e9;0;0 0 1 0 1 2 1 1 2;0;1 7 4 8;6@3 5@- 2@-;y t1 b5 t2 t3 t4 y w3 t5 y t6 t7 x3 t8 t9 x4 t10 y w5 t11 t14 b- t15 y x0 t16 s2:2,0:3,0:3,2:1,1:1,0:1,0:1,4:3,1:2,1:1,2:2,1:3 t17 t18 b- p18 p19 p22 y x5 y w0 t23 y t24 t25 y t26 t29 b28 w1 s3:143,0:2,2:1,1:1,1:2,0:1,0:2,0:2,2:1,2:1,2:2,0:2,2:1 y t30 p35 s0:2,0:1,1:1 p40 w0 y t41 x3 b43 t42;d574a16027d885a0 +e13;0;0 2 1;0;2;1@-;t1 t2 t3 b9 p8 p8 s5:1,0:2,1:8,0:1,2:1,1:3,0:1,5:1,2:1,1:1 p9 t10 p10 p11 t12 t13 t18 t21 b- p21 p26 p26 s7:1,5:2 p27 p28 p29 s0:1,1:2 p31 p31 p34 p37 p38 t43 s0:2,1:1 p44 b- p44 p44;97bf1ad0beb0876c +e14;293;0 0 0;0;2 1;;x2 x1 x1 s5:8 s1:3,2:1 t294 t295 s1:1,1:1,0:1 s4:2,3:1,1:1,1:1,0:1,1:1,0:1,0:2,0:2,1:2,0:1,1:6,1:5 p311 x0 x1 s2:1,0:2 t312 s7:1,0:1,1:1 p313 s0:1,2:2,1:8,7:1,0:1,0:2,5:1,1:1,0:1,1:1,0:6,0:1,7:1 p314 p315 w0 t316 p316 p316 p317 p317 p317 p317 s1:1,0:1,2:1 s0:2 s1:2,1:1,6:3 p318 s1:1,0:3,6:4 p319 s2:2 p320 p321 p321 p322 p323 p323 p323 p324 s0:1,1:1 s1:2,0:1 p327 p327 p328 x0 x1 t332 s0:1 p383 s1:1 b386 t384 x2 t388 p388 s1:1,1:2 p389 p389 p390 p390 p391 p392 p449 p449 p450 s0:1 p450 s0:2,0:1 s0:2,0:3 p450 s0:1 p451 s1:1,1:3 p452 p453 p454 p455;6cf1af1fa25a4691 +e15;0;0 0 0 1 0 1;0;1 5 2;4@5 3@-;t1 x4 t2 t47 b47 t48 x3 t49 t50 s0:1 t51 t52 s0:1,1:1,1:1,2:1,0:1,0:2,1:3,0:3,7:2,6:7,4:1,2:2,2:1 t53 t55 s1:1,5:2;4d53cffff22365a7 +e17;0;0 2 0;0;2 1;;s2:2 t1 s2:1,2:1 b- s1:1 s2:3 s2:2,2:3 y t2 t4 t5 t8 b8 p8 t9 s1:2,0:2 t13 s4:1,4:2,4:1 s0:1 s1:191,1:1 s0:2 s4:1 t14 s1:2,1:1,1:2,1:1,1:2,1:1,1:1,1:1,1:1,1:1,1:4 s7:1,0:3 t15 p16 s2:2,1:1,2:1,1:1 s2:2,2:3,1:2,2:3,0:5,0:1,2:2,2:3,0:1 s0:1,0:1,6:1,2:3,0:1,2:1,2:1 s0:2,1:2,1:3 s1:1,2:8;f2b03b7105ca24ed +e18;0;0 2 1;0;1;2@-;y s2:2 t1 s5:2 b- s0:182,2:1,2:2,0:1,2:1,2:1,0:7,1:1,2:1,2:1,2:1,2:2,0:2,2:1,7:1 p1 p2 p3 p3 p3 p3 p3 s0:3,7:1 p4 s1:1 p5 p6 p6 p6 p6 p7 p9 p9 p9 p10 p11 p12 p12 s0:2,2:1 p13 p13 p16 b- p16 p29 p29 p30 p30 p30 p30 p30 p30 p35 p36 p36 p37 p38;a6d6344e87a6ca58 +e19;0;0 0 0 0 0 0 0 0;0;7 2 4;6@5 1@- 3@8;b2 s3:1 t1 t2 s3:1,0:1,7:1,0:3,2:2,1:2,2:3,0:1,2:1,4:1,3:3,7:1,2:1,0:3,2:1 p2 s0:4,0:2 p2 p3 s3:1,5:2,0:4 s1:1 p3 p3 p5 p6 p7 p7 p12 p13 p13 p13 p13 p16 p16 p16 p16 p22 s1:42 p23 s1:1,0:3,5:2 p24 p25 p25 p25 p25 p26 y x1 t27 x2 t28 t29 p29 p29 s2:2,1:3,0:85,0:4 p29 p29 p29 p29 s1:3,3:4,2:1,3:1,3:3,1:1,1:2,3:2,0:1,2:1,5:2,5:4,3:1,6:1,0:1,3:2 p29 p29 p29 p34 s0:2,1:1 p38 p38 p38 p39 b-;b1c422585f4e45ac +e20;0;0;0;;;b- p1 p2 p2 p3 s1:1,2:1,1:3,2:2,1:2,1:1,4:1,2:6,1:1,0:2 s2:1 p4 s1:1,0:3 s2:1,1:1 p5 p6 p6 p11 s2:1 p13;6a8646d3293121b6 +e21;0;0 1 2 2 0 2 1 2 2 2;0;2 8;4@- 6@-;s2:2,1:1 t1 b7 p1 s1:3,2:1 p3 p3 p3 p4 p5 s2:1 p5 p5 p5 p8 y b- b14 p8 p8 s6:1,0:2 p8 s1:2,4:251,0:2,4:1,2:2,2:1,0:2,5:2,0:3,1:1,1:3,1:1 s2:3,2:1;cd6104fb08a91088 +e23;0;0 0 0;0;2;;y t1 x1 t53 y y t54 y t55 t56 x0 x1 t57 y y y y x2 t58 t59 y t60 t64 t65 y y w2 t66 y y t67 y w0 x2 y y x2 t68;92463e29c1d21c48 +e24;2;0 3 2;0;1;2@8;t5 t6 t7 t8 t9 t12 t13 t14 t15 b- p15 p16 p16 s2:1,2:2,0:1 p16 p17 p18 t19 w1 t20 t21 p22 t23 t24 t25 p25 p26 t31 t84 y t85 p86 y w1 b84 p86 t87 t88 t90 b88 p90 t91 t92 t96 y s4:2,3:1,3:1 t100 y y y y t101 y t102 p104 w1 t105 y y t107 p107 p110 p111 p111 p114 p115 s3:1,0:187 p116 s0:2,0:1,1:1,1:1,2:2,0:3,0:3,2:155,2:1,1:1,6:1,3:1 t117 t118 p118 s0:2 p119;bdb66fb45fbfa63f +e26;0;0 0 2;0;;2@2;t2 t3 t4 t5 b5 p5 x2 x2 t7 t8 y t12 t13 x0 t14 t17 t22 x2 y x1 y y x2 t23;50a5ab4971081797 +e28;0;0 0 1 0 1 1 0 0 0 0;0;1 4 6 2 7 9 5;;s0:1,0:3,0:1 w9 x4 s1:2,1:2,0:1,0:1 t1 s0:2,1:132,1:1 t2 t3 b8 s1:3,0:2,0:1,1:1,2:2,0:1,1:1,1:1,0:1,0:4,3:3,1:1,0:2 t4 s0:2,0:1 y t5 s0:1,1:3 t6 s0:1,0:2,3:2,1:1,1:1,1:1,1:2,1:1,0:1,0:6,1:1,0:1,1:2,0:1 s0:1 t11 t12 t13 w0 t18 w0 t19 w9 s1:1 w8 x8 t20 t21 t22 t24 t25 w0 t26 y t27 w1 t28 w9 s1:2,0:1,0:1 t29 s1:1 t30 s3:2,6:1,0:1 t31 t32;47643fc50de6165b +e29;0;0 2 0 2;0;3;2@-;w2 t1 y t4 w2 x2 t5 x3 t6 t7 y t8 t12 t13 t14 y x0 t18 s2:2,0:1,5:1 b22 w1 t21 t23 p64 t65 t66 x0 s0:1,0:1,1:2,5:3,2:3,0:5,0:1,2:1 t67 s0:1,0:3,0:2 p68 s1:1 t69 t70 p74 p75 p75 p75 p76 s1:2,1:1 p77 s1:1 p78 p79 p80 p80 p81 p81 p82 p83 p84 p84 p84 s0:1,0:2,0:1 p89 t134 w1 x0 y x3 t135 t137 w1 w1 t138 t139 t142 x2 t143 t144 t145 t146 t147 t152 t153 t154;2d6681f634e92a3e +e30;0;0 0 0 0 0 0 0 0 0 0;0;9 5 8 7;1@- 3@- 4@-;y t4 t8 x8 t9 t10 b- t11 t14 t15 x1 t47 t48 t49 t52 t53;78e269a650ef8f06 +e31;3;0 0;0;;1@11;w0 t4 t9 w1 t30 t35 t36 s1:2 t37 t39 p39 p39 s0:1,0:3,0:6 p39 p40 p40 p40 p42 t43 y t46 t47 w1 t50;59cf73d721770ce7 +e33;3;0 0 0 0;0;2;3@- 1@8;t8 b- x0 t11 y x1 x3 t12 x1 t13 x0 s0:8,7:1,0:7 b17 b12 s0:2,0:3 p13 x2 x2 x3 x1 x0 x1 x3 t14 t15 x0 b20 p20 b- t25 t26 t27 y b33 p35 x1 x2 t40 x0 b46 p45 p45 p48 t49 y t52 t57 y;6e9b6d9954c0adb3 +e34;0;0 0 0 0 0 0 0 0 0 0;0;1 4 9;7@- 2@- 3@1;t1 y t2 b- y b- b5 t3 t4 b- b4 p5 w9 t6 b8 b5 b- p7 w3 b- b- p8 p9 p9 p12 p13 p13 s0:1 p14 s4:1 p15 s0:3,0:1,0:1,0:8,0:101,0:1,0:1,0:2,0:1,0:1,0:2 p16 p17 p21 s1:1,2:8,0:1,0:1,2:1,7:1,2:1,0:2,2:63,0:2,0:3,1:3,0:1,1:3,2:2 p21 p21 p21 p21 p21 p21 p21 p22 p22 p22 s0:79,4:2,3:7 p22 p22 s4:7,1:1 p23 p24 s2:2,2:1,1:246,2:3,2:5,1:3,5:2,0:5,6:2 s5:3 p25 p30 p30 p31 p31 p32 p32 p35 p36 p36 p36 p40 p40 p41 p42 s2:2;cf6ee7d9956d291d +e35;0;0 1 0 0;0;;3@2;b3 p0 p0 p0 p1 p1 p2 b3 p3 t7 w0 w0 w2 t8 y t9;56aba6cb9ac4d5d2 +e36;0;0 0;0;1;;t1 s1:1,0:1 t2 y y w1 s2:1 x0 t3 x1 b2 b- p4 p5 p6 p6 s3:1 s0:8,0:1 p6 s1:1,1:1,1:1,1:3,1:1 s1:1,0:1 p6 p6 s0:2,1:1,0:1,0:1,7:1,0:1,1:1,2:1,2:2,0:1,2:2,2:3,2:7;9401ac297dcca4ff +e38;0;0 1 0;0;;2@7 1@7;t1 x2 b2 p1 p9 x1 t10 t11 t12 s7:3,2:2 t13 s2:2,1:1,2:1 t14 s0:1,0:6 t15 t16 t18 t19 t24 t25 b- t28 t29 w2 s0:1,0:1,0:2,0:1,0:1,0:3,0:2,0:1,0:2,0:8,0:1,0:1,0:2 t30 s1:2,2:1,1:1 t31 x1 t32 t63 x2 b63 p64 t65 t66 p66 p66 s6:1,1:1 s1:8,2:2,2:2 s0:1,1:1,1:2 p67 t69 y b73 p71 p126 s0:4;4b88380cb7d6386b +e39;0;0 3 3 0 3 2 0 2 0;0;1 6 2 3 4;8@1 7@1 5@1;t1 t2 t7 w8 t16 t17 t18 t19 t20 t24 t28 y x7 t29 t30 t32 t35 x5 s1:1,3:3,0:1 s0:1,0:4 t36 s3:1,1:1,1:2,0:3 s2:1 t37 t38 x0 t39 t40 y x5 t41 t43 t44 t45 t50 t51 y t52 t53 t54 t59 t63 t68 t69 y t70 t72 t73 t74 t75 t76 t81 t82 y t84 s0:2,1:1 t85 t87 s2:1,0:1,0:1,1:2,2:1,2:1 t88 p89 t90 x2 t92 s3:1 s2:1,3:1 p93 p93 p93 p94 x0 s5:1,1:224,0:1 t133 p133 p134 p137 p137 p138 p140 p140;0f10bb951a2f0a7f +e40;3;0 1 0 0 1 0 1;0;2;6@2 1@11;b- x6 t5 t6 t7 x1 t8 w1 x5 y w3 y t9 t10 s0:1 t11;79e0f5b6d57b99aa +e41;824;0 0 0 0 0 0 0 0 0 0;0;1 5 2 8;3@826 6@-;y t828 s0:1,0:1,0:1 t829 t830 s3:1,0:1,0:2,0:8,0:2,5:1,0:8,0:2,0:1,0:3,0:2 s6:1 t831 t832 p832 s0:2 s0:60,7:1,0:1,0:2,0:2,0:2,0:2,0:1,0:1,0:1 p837 s0:1,0:2 t838 w6 t839 t864 s0:2,0:1 s0:2,4:1 t869 w1 t870 s0:6;e0385e7967a7486f +e42;0;0 0 0 0 0 1 1 1;0;1 4 5 7 2;3@1;y y y t2 b3 t7 t8 b- y y t10 t15 t16 t17 t18 b16 s1:1,1:1,0:2 t19 s1:1 t68 t69 t70 w7 w5 t71 t72 y y w4 b- t76 b-;44d1cce65c9ce0ca +e43;0;0 0 3 3 3;0;1 4 2 3;;t1 t6 b12 y s1:2,1:2,1:2 t7 s2:1 t8 s0:2,0:2,3:1,3:2,3:1,3:2,2:2,1:72,1:1,2:1,2:2 t9 t10 y w1 t11 x4 t12 t14 w2 y w3 w3 w4 w1 y y w2 y t15 w4 y t16 y w4 y s1:5,2:2,2:1 t17 s1:2 t18 t19 p21 p54 p54 p54 p54 p58 p61 p77 p77;026bb184c63ecbd3 +e44;0;0;0;;;t5 t6 t8 t9 t10 x0 t13 t14 t15 t16 w0 t17 t18 t19 t20 t21 t22 t23 t24 t25 t26 t27 y s1:1 s0:1,1:2,0:1 t28 s1:2,0:1 s1:1,1:1,1:2,1:2,1:7,1:2,1:1,1:196,1:1,1:2,1:2,1:154,1:1,1:1,1:1,1:2 t29 t30 s0:8 s0:1 p30 p38 s7:1 t39 t40 p40 s1:3,1:8 s0:188 p43 y t44 t45 t46 t47 s0:1 t48 b- p48 p49 p49 p95 s0:2,1:1,1:2,2:1,0:5,0:2,1:1,0:1 s1:2,0:1 p96 s1:3 s0:2,0:2,0:1,0:1,0:1,0:1,0:1,0:2,0:2 p97 p98 p102 p103 p103 p103 s0:2;84a26e4633db52f8 +e45;0;0 0 0 1 1 1 0 1 1 0;0;7 2 4 8;6@- 1@4;b- t3 b- p3 p4 t5 b9 p6 p7 p8 p9 b8 p9 t10 x2 y;bbea89911cfee7ed +e46;565;0 1 1 0 1 0 0;0;3;2@567 6@564 5@569;s1:174,0:4 t566 t570 w3 t571 b- p572 p573 p573 p592 s1:3,1:1 p638 p639 s0:1 p642 y s0:2,7:1 s3:2,1:39 y w1 y b- s1:1,1:1,1:2,1:50 t643;5917ed4c5eb3a398 +e47;0;0 0 0 0 0 0 0 0 0;0;6 2 7;5@6 3@5 4@6 8@-;b- b- t56 w2 t57 s0:2,0:2 b61 y w6 b- w3 w8 b60 b60 t58 w3 b63 t59 w0 s0:1,5:2 b62 t61 b62 b67 t64 t65 p65 p69 p70 w2 b74 t71;3935b50380e4bd57 +e48;2;0 0 0;0;;1@9;t3 t4 x0 t5 t6 y y t7 t8 t9 y t14 y t15 t16 t17 t56 t91 x0 y s1:3,0:2 s1:2 t92 s0:1 s1:1,0:2,2:1,1:3,6:1,1:1,1:1,1:1,0:1,1:1,1:1,0:1,1:1,1:3,1:1 t93 t94 p94 p95 t96 t98 p99 p100 p100 p100 p101 p102 p102 s1:1,1:1,0:1,0:3,2:1,0:2,0:4,1:1,0:3 p103 p103 p148 b152 t149 t150 t151 p151 p151;bf8dd500406d4398 +e49;0;0;0;;;x0 t1 t4 b10 p5 p5 p5 p6 p6 p7 p7 p7 p7 s0:3,3:1,1:8 p8 s1:1,3:1 p9 p10 s7:3 p10 p10 p10 s0:1,1:1,1:3,1:3,0:1,0:1,0:2,0:1,0:1,1:4,1:2,0:1 p10 p10 p10 p11 p11 p12 y t15 p15 p15 p36 p38 s0:6,1:8 p38 s7:2,0:1,0:1 p68 p119 b125 p171 b175 p172 p173 p173 s0:1 p174 s1:2,0:3,1:1 p175 b- s1:1,0:1,0:2,1:64,5:1,0:1,0:5,1:1,1:7,0:1,0:7,6:2,0:2,0:1 p176 s0:2 p177 s0:1,0:3,0:1,0:1 p178 p179 p179 p184 p184 p189 p193 p193 p193 p194 s0:1 p195 s1:36,0:2 p196 s1:1,0:3 p197 p198 s1:1 s0:1 s0:1,1:219,7:2,3:25,5:2,3:1,0:2,1:2,3:1,1:2,3:2,0:2,0:3,1:1,2:1 p199 s0:1,1:1,1:1 p200 s0:8,1:2,1:2;9c2f5a757fe19964 +e50;0;0 3 0 3 3 1 0 0 3;0;1 5 6 2;3@7 4@1;x4 w2 y t1 w8 t2 w3 w8 w8 t5 w0 t6 w3 w7 x3 w8;8ceaf311bb1bac3c +e52;0;0;0;;;b4 s3:1 p0 p1 p1 s0:2,3:3 p2 s1:1,3:5,1:2 p3 s5:99,6:2,3:3,3:1,0:2,2:1,0:2,2:3,2:188,3:1,1:1,2:2 p4 t5 s2:1,0:2,1:223,2:2,1:1,5:2,0:1,2:3 p6 s2:1 p6 s1:1,7:1,2:146,1:1,1:2,1:2,6:2,3:2,7:1,1:69,3:1,2:2,1:3,2:1 s0:3,2:1,2:2 p7 s0:1,3:2,5:1,1:1,2:2,5:7,2:1 s0:1 p8 p9 b- p9 s3:2,1:2 s1:2,2:1,1:7 p10 s6:7,7:1,1:1,3:29 p11 s4:1,4:1,4:3 p12;75413fb335b10046 +e53;0;0;0;;;t1 t2 y y x0 y t3 t7 y t8 t9 t10 b15 p11 p11 s4:80 s3:1 p11 p11 p16 p16 p17 p17 p19 p19 p19 p19 s0:2,0:3 s1:2,0:1,1:2,0:2,2:2 p20 s1:1 s0:1,1:1,1:1 p21 p22 t23 p42 p42 p43 w0 y y t48 p53 p54 p80 p81 p82 t83;78ed19f2a843079b +e54;5;0;0;;;t7 t8 x0 t10 x0 t11 w0 s0:1,0:2 t14 t15 s0:1,4:1,2:1,0:3 w0 t17 t18 p19 p20 w0 t21 x0 t22 s0:1,0:1 t23 s0:3,0:2,1:2 t31 s0:1 p32 b35 p33 s0:1,0:1,7:1 s0:1,0:6,0:1,0:3,0:1,0:1,0:1,0:6,0:121,0:8,0:3,0:1,0:1 p34 s0:3,0:1 s0:1,0:5 p35 t36 t39 s0:2,0:3,0:2,0:1,0:1 t40 s3:1,3:2,3:3,3:2,3:2 t41 t42 p43 p43 p43 s0:2,1:7,0:3 p44 s0:1,0:1 p45 p46 s6:7,0:1,0:66,0:1 t47 s0:3,0:2,0:2 t48 t49 s0:1,6:1 t50 s0:3,0:2 t51 t52 b- p53 s0:1,0:1 p53 p53 p53 p53 p53 s0:2,2:3,4:1,0:1,0:3,6:1,4:2,0:6,0:1 p53 s0:1,0:1 s0:1,0:3 p54 s0:31,0:4 s5:2,3:2,7:1,2:4,2:2,0:1,4:1,6:134,0:1,1:1,0:1 p55 p56 p59 p60 p64 p64;3ca3c7b9606277be +e55;0;0 0;0;1;;t1 t2 y b- y y t5 t6 t9 t10 t12 w0 t13 t14 y b14;e0c1ded9c22d7276 +e56;0;0 1 2 1 0 0 2 0 2;0;8 4 3;2@7 5@- 6@1 7@3;t1 s3:194,2:1,0:3 s2:1 t2 s2:3,1:1 t3 s2:1,6:1,1:1,4:1,5:1,2:3 t4 t5 t6 p7 s1:2,1:1,1:1,1:1,1:1,1:1,1:3,1:123,1:3,1:1,1:2,1:2 s2:1,2:2 t8 s4:2,2:1,2:1,1:6 p9 s0:1,0:2,2:1 s7:5,0:1 p10 t11 p11 s1:2,2:1 s2:1,1:1 p12;4e76b591f1a81c2f +e58;0;0 0 0 0 0 0 0 0;0;6 3 4 2 7;;t5 s0:2 w5 t6 y y t7 s0:1,0:2 t8 s0:2,0:3,0:3,0:3 t9 s2:1 t10 t11 s0:1,0:2,0:1,0:7,0:1 s0:6,0:3 p12 s0:2,0:1,0:1,0:3,0:1,0:7,0:3,0:1,0:2,0:1,0:2 s6:1,0:1 p13 p14 p15 t17 w7 t22 p23 s0:1,0:1 x7 t24 p25 t26 t27 t32 t33 t34 t35 t36 s0:3,0:2 t37 t38 t39 t40 t45 t46 t47 t48 t49 s0:1,0:2,7:1,0:3;5de4bc4bbc4f29a3 +e59;5;0 1;0;;1@-;t6 t7 b- p8 p8 p9 p10 p11 p15 p15 p16 p16 p16 p17 p17 p17 p17 p17 p17 p17 p18 p18 p19 p19 p19 p19 p19 p19 p19 p19 p22 s0:2,0:1,1:1 p27 p27 p28 p28 p29 p32 p33 p33 p34 p34 p37 p37 s0:2,0:2 p37 p37 p37 p38 p38 p38 p39 p39 p40 p43 p43 p43 p46 p47 s1:1,3:3,1:1 s7:1 p48 p49 p49 p49 p50 p88 p88 p88 p89 p90 p91 p91 p92 p92 p102 p102 p103 p103 p103;60c16a9fb5a0593f +e60;0;0 1;0;;;y x0 y y y x0 t1 s1:1,2:1,0:2 x0 t2 y y x1 s2:1,3:1 t3 t4;9ac56f411b794188 +e61;4;0 1;0;1;;t5 t6 t7 y w1 t8 t9 x1 x0 t10 y s0:3,0:1 t11 s1:3,0:4,0:1,0:2 t12 t13 t14 t15 t16 t17 t18 t19 w1 x0;7ee50cabedd6465f +e62;0;0 1 0 1 2 0 0 1 2 2;0;4 7 8 2;6@4 9@- 3@- 1@1 5@2;s0:1,5:2,0:1 t4 s4:1,2:1,1:2,4:4,1:1,1:149,2:1,3:2,2:1,2:1,0:1,2:4,1:141,2:1,0:1 p5 t9 t10 p14 x9 t15 t16 w3 x6 t17 y s1:1,0:1,2:2,5:2,0:1,1:1,3:1,0:1,0:2,1:2,2:1,0:1,0:1 t18 t22 s0:126,1:3 w1 s1:1,2:2,0:1,2:4,1:1,0:4,1:3,0:3,3:1,2:1,0:1,1:1,1:3,2:1 x4 t23 p24 s1:3,1:2,1:1 t27 x0 t28 t29 w5 t34 t60 y;d4faba174879e2d4 +e63;0;0 0 1 0 1 1 1 0 0;0;7 3 4;5@- 1@-;t1 s1:2,0:2 t2 s1:1 t3 t61 t65 y t70 w5 t71 t72 w4 w1 x8 t73 t74 t75 y s7:3,3:1,1:2 s5:1,1:3,1:1,1:2 t76 s0:130 s0:1 t77 t78 t79 t80 t81 y y t82 w7 w7 b88 w1 b- s0:3,1:3 t83 s1:2,4:2,0:2 t84 t85 w3 b91 s0:3 t87 b- t88;c08d55527be30eed +e64;830;0 0 0 0 0;0;4;3@- 2@830;s0:6,0:3 t831 s0:3,0:1 t832 s0:2,0:2 y y b832 x1 y y t833 b836 y b832 t834 t839 s0:1,0:1,4:1,0:1,0:1,0:3,0:1,0:1,0:54,0:2,0:2,0:2,0:1,0:3,0:2,0:1 t840 s0:2,0:210,1:2 t841 t842 b847 b845 t843 b842 p844 b- s0:1 p849 s2:2,7:4 t850 s0:2,0:1,0:3 t851 s0:1,0:3,0:1,0:1,5:3,0:5,0:1,0:1,7:2,0:7 t852 t853 y w2 y b- t856 b- w1 b855 p856 y t861 s0:1 p862 b861 s0:1,0:1,0:1,0:1 p863 s1:2 t864 t865 p866 s0:1,0:2 p867 p867 s4:4,4:2,4:7,4:1,4:1,4:2,4:1,4:1,4:1,4:68,4:2,4:1,4:2,4:5,4:7 p867 s0:2,0:8 p868 p875 b875;227ae982fd9fef23 +e65;0;0 3 0 3 1 3 2 0;0;2 7;1@- 4@8;t1 y y s0:1,2:1 t3 b5 s2:1,2:1 t4 p8 p8 p8 p8 p8 p9 p9 p10;0096c59a0f418372 +e66;0;0 0 0 0 0 0 0 0 0;0;4 3 1 6;8@2 5@- 7@1;t1 w8 t3 y t4 w2 t5 x3 t10 t11 t12 x1 t16 t18 t19 t20 t21 x4 t22 t23 t27 t29 x1 t32;6a2ab741971e227b +e67;0;0 0;0;;;t1 t2 t3 t4 t5 t7 s4:1,4:3,4:1,4:8,4:2,4:140,4:199,4:2,4:1,4:1 t8 y w1 y t9 p9 p9 p10 p10 p11 s0:1,3:3,0:2,1:1 s1:1,6:2,0:1 p12 p13 p13 p13 s1:1,2:1 s0:1 p13 s0:6,3:1,0:3,6:3 s0:1 p14 p19 x1 s0:1;43e1026a0bab6540 +e68;4;0 0 0;0;;2@-;b- s1:13,1:1,0:1,1:2 p4 p5 p5 p5 s0:3 p6 p6 p9 p11 p32 p32 p32 p37 s0:2,1:3 p37 p38 p39 p39 p60 p60 p60 p60 p63 p68 p69 s0:1,0:3,0:1,2:1,6:1,1:1,0:1,3:1,7:1,1:2 s3:2,0:1 p70 s1:135 p71 s0:2,1:1,1:177 p72 p73 s1:1,1:1 p74 s0:1 p75 p76 s1:1 s0:2 p77 s0:2 s1:1 p78 p79 p84;16c87df56481ca2e +e69;3;0 1 1 0;0;2 3;1@3;t4 w1 w1 y y t5 b10 w0 t6 y t7 t8 s1:2,1:1 y t9 w0 b- t10 t13 y x0 b14 w2 y y t14 b19 y y t15 s0:1,0:3 s1:2 t16 s1:3,3:1 s4:1,1:2,1:4 t17 t18 p18 p18 s1:2,7:2,1:2,5:2,1:3 p19 x0 t20 y t21 y w0 y y b26 y b21 p21 x1 y t23 s1:1 p23 p23 p23 p24 y t28 b33 t29 t30 y w1 y y t31 y t32 t33 t34 w1 y y t35 t36;a696594888a98729 +e70;0;0 1 1 0;0;2 1;;t1 t2 y y s0:2,0:2 s0:26,1:1,0:1,0:3,0:2,3:2 t3 t4 w2 s7:1 s3:3,3:1,1:1 t5 s2:3,6:1 s0:3,1:1 t6 t7;700f0b57d56c38fb +e71;4;0 0;0;;1@-;t5 t6 t11 b13 p11 p12 p12 p15 t38 y t43 t46 w1 t47 y y t50 t52 b57 y t53 t83 w0 t88;74ed7975a1b45132 +e72;0;0 1 1 0;0;2 1 3;;y t43 y y t44 b46 y t45 w3 t46 t47 y y t48 y t49 t50 t54 w0 y t55 y y s6:1,3:1 t56 t60 p60 p60 p61 p62 p62 p64;764e02b1f8e01aff +e73;5;0;0;;;t6 s3:2,3:3 t7 x0 t8 p12 p12 s6:1,2:2,2:3 p12 p15 p16 p16 p16 p17 s0:2,0:1,7:4 s3:1,3:2,0:2 p18 p23 t24 p25 p25 p54 p54 p54 s2:1,1:2 p54 p55 p55 p55 p55 p58 p58 p62 p62 p63 p64 p65 s3:2,0:115 p65 s3:109 p66 p67 p67 p67 p68 s3:3,3:3,3:1 s0:1,2:1,0:1 p107;28739e5312ee7fd8 +e74;5;0 0 0 0 0 0;0;1 3 5;2@- 4@10;t10 t11 t13 w1 s4:1 t14 s0:2 t15 t16 b21 t19 s0:1 b- t20 s1:1 s1:2,1:2,1:2,1:1 t21 s0:1,5:3,0:27,5:1 s1:3,1:2,1:1,1:1,1:1,1:2,1:1,1:2,1:1,1:1,1:1 t22 t23 s0:3 s1:16,1:98,0:127,3:1 p23 p24 s7:6,0:6,0:1 s4:2,4:2 s1:2 s1:1,1:1,1:1,1:1 p25 s3:1,1:3,0:1,0:2 p26 p27 s1:1,1:3,0:1 p27 p27 s0:2,0:2,3:2 s1:26,0:1,1:1 p28 s1:1,1:1 s0:2 p29 p30 t31 t34 x5;e52a8f97bc94dbee +e75;2;0 0 1 1 1 0 0 1;0;2 1 5 7 4 3;;t7 x2 t9 t10 s0:2 t11 t12 t13 t14 s6:1,0:8,1:3,0:3,0:1,1:3,0:1,1:3,1:253 t15 s0:3,1:5,0:3 t16 s1:1,7:2 t17 t18;fc8eefd7e988759f +e76;0;0 1 1 1 1 1;0;1 4 3;2@5;w0 t1 x2 y t2 t3 t4 t5 b- s0:1,0:1 s0:1,0:6 p6 s5:1,2:2,6:3,1:2,1:3,1:2,1:6,0:1,1:2,1:1,1:1,0:7,0:2,1:2 s1:2,1:1,1:2 p7 p8 t9 w5 s1:1,1:142,1:1,1:1,6:2,1:2 t11 t12 t13 t14 t19;3b18537bdb005f87 +e77;0;0 0 0 0 0;0;2 4;1@-;t1 w1 w4 t2 w1 b4 w2 w2 w2 w3 t3 b- y t5 t6 w3 x0 y t7 t8 w2 x4 t9 t10 t11 w4 t12 y t13 t14 t16 t17;592786cb2cb53336 +e78;960;0 0 0 0 0 0 0 0 0 0;0;6 4 2 1 9 3;;x4 t961 t963 w8 t966 w2 t967 t968 t969 t970 t971 t972 t973 t976 t977 t978 b979 b976 w3 s1:1,0:2 t979 t980 p980 s3:2 p985 p985 p986 p987 p987 p1018 p1018 p1018 s0:1,3:96 s0:1,2:2 p1018 p1020 t1021 p1021 s3:1,3:1,2:3 p1021 p1022 p1022 s1:1 s1:1,6:1,1:2,2:1,4:1,1:1,1:2,3:2,0:1,2:29,1:2,0:2,3:1,0:2 p1023 y t1024 s1:5,0:1,0:3,0:2,6:4,6:1,1:1,2:1;9d643cdaa52d27bd +e79;0;0 0 0 0 0 0 0;0;3 2;6@- 5@- 4@-;y t1 t2 t3 t4 y w6 t5 x4 t6 t11 t12 x0 t13 t14 t15 b- y t16 t21 y t22 s0:3,0:2 s0:3,0:3,0:1,0:1,0:2,0:3,0:3,0:3,0:1,0:2,0:1,0:2,0:2,6:1,0:1 t23 s0:169,5:5,0:1 t24 s0:1,0:1 t25 t26 y t27 t31 t35 y t36 t40 y t41 x1 t42 s0:2,0:1,0:2,0:3 t44 s4:1,0:1,5:1 w4 y b46 t46 p49 p52 p53 t55 p59 t64 p64 p119 t120 p125 t130 p130 p130 p130 p130 p130 p130 p133 p134 t135 p140 t141 p141 p141 p141;d22b349b67578991 +e80;0;0 0 0 0;0;3 1;2@-;t1 t6 b10 b12 b7 p7 w0 b6 p7 y b6 p8 s1:1,1:3,0:1 w1 t9 t10;b6d605eb3508041d +e81;0;0 0 2 1 2 1 1 0 2 0;0;5 7 8 3 2 4 9;1@- 6@-;t1 t2 b- t42 t43 t44 w1 t45 b47 x6 t46 b47 t47 x6 s2:1 s0:1,1:2,0:1,3:7 t48 s0:1,3:1,1:240,1:1,2:2,3:1,7:3,2:1,5:2,1:2,0:250,1:1,6:1,2:1,3:1 s0:2 t49 t50 t54 y w7;7d02b13277fce32a +e83;5;0;0;;;t6 y t10 t15 y w0 x0 t16 t17 t18 t19 t22 t23 t24 t29 x0 y t89 w0 s0:59,1:2 w0 s0:1,0:1 w0 t90 x0 t91 t96 x0 t97 t98 x0 s4:171 w0 y t99 t103 p108 p108 p109 p109 p110;9b9818bba14d32a9 +e84;2;0 0 0 0 0 0 0;0;4 5 3;2@5;t3 t4 t5 w5 s0:2,1:1,0:1,0:1,0:2,0:1,0:2 t6 y w2 w1 w5 t7 w2 y w6 y t8 b11 t9 p10 y t14 w0 t15 s0:2,0:5,0:2,0:116,0:1 y s0:2,4:209,0:2 w5 t16 w0 t17 t18 s1:3 t23 s0:2 p28 y y y t30 t31 s1:1,0:1 y t75 p75 p75 p76 w6 y y t78 t79 p79 p80 y w5 w5 w2 t81 s0:1,0:2,0:3 p82 s0:1,0:2 y w3 t89 y w2 t90 t91 w6 y t93 w5 t94 t95 b99 y y;fd95627cb44fcb85 +e85;622;0 0;0;;1@-;t623 b626 p627 w0 t631 t632 t633 b- p634 p635 p636 p637 p638 p638 p638 p643;ec78b51e3aa5418d +e87;0;0 1 0 0 1 0;0;;3@3 4@- 5@-;t5 t6 w5 t8 s0:1,0:5 t9 s1:1,0:2,1:1,0:7 t10 t11 p12 x4 b- x5 x2 t13 x3 y x3 t14 t54 x4 t59 x0 b59 y t60 t64 w1 t69 t70 t71 y;7a7df4a5ed3189b5 +e88;0;0 3 3;0;2 1;;b2 s4:1 s5:1,2:2 p0 p0 s0:1 s2:1,2:2,2:2,3:8 p3 s3:2 p3 s1:4,0:2,0:134,3:2 p50 s5:1 t51 t52 p52 s0:3 p52 s2:2 p52 p54 s0:4,1:1,0:1 p54 p54 p55 p56 w2 t57 s2:2,1:1,1:3,4:1 x1 x1 t60 s1:2,3:3,0:1 p60 p60 p60 p60 p61 p61 p61 p62 p66 w2 w0 s6:1,2:2,1:1,6:5 s1:1,3:235 w1 w1;25e2c8f8c00d3d5c +e89;3;0 1 1 1;0;2 3;1@1;t4 t5 b7 p6 p6 p6 p7 t9 x1 t10 x3 t14 t15 t16 t17 t18 x2 t19 t20 t21 t25 b23 p25 s0:1 t26 s0:3,0:2,0:1,0:1 x1 t28 x3 b33 p31 s0:2 p32 s0:1,0:2 p33 t34 x1 t35 x1 t36 x2 x2 t37 s0:1,0:2,0:1,0:2 t38 s4:2,0:4,6:1,3:2 b38 s0:7,1:1 p38 w0 t39 b- p40 p40 p40 p43 s1:2,1:2,1:1,4:2,3:1,0:3,0:234,6:1,1:2,7:1,1:8 p43 s0:1,0:2,1:1,0:3,1:1,7:1,0:3,0:6,1:1 s1:1,1:3 s1:1,1:2 p44 s6:1,1:2,1:129,6:1 p44 s1:124,0:1 p45 s1:3,0:1 p46 s1:3,2:1,1:1 p47 t48 x0 s3:1 x3 t49 t50 p50 p50 s0:1 p50;ff4db8813886486b +e90;0;0 0 1 0 1 1;0;1;5@- 2@- 4@-;y t1 t6 t7 t8 x4 y t9 t10 t11 t12 t13 y y y x5;8c36ba7b90a75b53 +e91;0;0 2;0;;1@-;t4 w1 b8 p7 p8 t9 x1 t10 s2:2,3:2,6:1 y t11 b17 s2:2,3:2 p11 s1:1,1:2,1:2,1:84,1:2,1:2,1:1 s1:1,0:1,1:170,0:3,2:1,2:2,0:1,3:1,1:8,3:2,0:1,7:2 s2:3,1:2 s1:1 p12 p12 s3:1 p12 p13 p14;b36d690432fe4d18 +e92;3;0 0 0 1 0 0 2 1;0;5 4 2 7;1@- 3@8;s1:1,0:1,1:2,1:1,2:2,2:7,2:1,2:1 t4 x3 w5 t5 t10 p10 p10 s2:195,0:3,0:3,0:2,1:1,6:1,2:3,0:2,0:1 p10 s1:2 s4:1,5:1,1:2 p11 s2:1,0:2 s0:1,0:1,1:8 p12 p13 b16 s1:1 w5 t14 s2:1,1:2 t15 y t16 p17 b16 t22 p23 w1 t24 w6;c2bf7088b811dd6b +e93;3;0 2 2 1 0 0 0;0;1 2;3@8;b- p7 p7 p7 s7:1 p7 p7 p8 p9 p13 p14 p14 p14 p14 p14 p14 p14 p14 p14 s2:4,0:1,1:1,2:7,0:1 p14 p18 b17 w1 w0 w5 t21 w0 b- p22 b22 y t23 t24 x4 w0 b30 t27 b33 s5:169 p27 p85 p86 p87 p89 p90 p90 p91;dc82fdedffa18390 +e94;0;0 0;0;1;;y t1 w1 w1 w0 w1 t2 t5 w1 w1 t8 y t9 t13 y t17 y y s1:5 y y s1:1,0:8 t18 y t23 t24 w0 y b- t25 t29 w0 w0 w1 b32 y t30 b- p33 y t34 s1:1,0:167,1:2 t35 s0:1,1:1,0:1 s5:2,0:3 t36 s4:1;39ba0dcf6dce31d4 +e95;911;0;0;;;t912 x0 b- p916 p916 s4:1,2:3 p917 p917 s1:1,0:1 p917 s3:3,1:61 p918 s1:6,3:1,3:1 p919 p920 s0:1,0:1;d4a06a3e16d47f78 +e96;3;0;0;;;t7 t8 t9 x0 t10 t15 t16 t18 t19 x0 t20 t21 x0 t22 x0 t23 w0 b28 p23 p46 t47 t48 s0:3,2:1 s2:1,0:3,0:2;d10ee066dabd2e4c +e97;0;0 0 1 1;0;2 1;3@8;b- y w3 w0 y t1 y y t3 b3 t4 t5 t6 y t10 t11 y y t15 t16 b- w2 t19 y x3 t22 b20 p22 y w0 b22 w0;2b4f3119f30f54ad +e98;0;0 1 1 2 2 0 0 2 2;0;7 6 3 4 8;5@6 2@2 1@-;t1 t6 t7 w2 b9 t8 t9 t10 t11 s0:1 t16 t17 w1 x8 t18 t19 t20 t21 w3 t22 t26 t30 t32 b- t33 x1 w6 x2 x0 b31 t34 w8 t35 w5 w3 t36 b39 t37 t38 t39 w2 w6 t44 t45 s4:3,0:3 s1:3 x5 t46;8b793be2cc1bca7c +e100;0;0 1 1 0 2;0;1 3 2;4@-;t1 b5 t4 t5 w2 t8 t10 t14 t24 x2 b25 b24 p24 b28 p25 b-;cf2c017c72b4a996 +e101;5;0 0 1 1 0 0;0;4 5 3;1@9;y t6 y t9 x5 y t11 t16 y y t17 b17 t18 t19 x2 s1:2,0:6,0:1 t20 y y t21 t22 t23 t24 x4;7dc48efdf9c4b379 +e103;5;0 1 2 2 3 3 2;0;1 2 6 3 4;5@3;w2 y t6 b- p6 p11 p12 p13 p13 p18 p19 p19 p20 p20 p20 p21 s1:103,1:1,1:3 p21 p22 p22 p22 p25 t26 t27 t28 t29 w1 y b- p34 s1:1,2:1,0:135,1:3,2:1,3:1,2:2,0:8,3:1,1:1,2:3 p34 p34 p35 p39 p39 p43 s1:3 p47 p48 s0:2,7:1,2:1 s3:1,3:1 s3:3,1:1,1:8 p48 p48 s1:7 p51 p51;cfdd1e4d0de3def5 +e104;130;0 1;0;;1@138;x1 t131 s2:3,0:84,0:8 s2:2,1:2,0:3,2:1,1:1,0:1,1:2,0:1 t132 s0:2,6:3 s0:2,0:1,0:2,0:1,0:4,0:1,0:1,0:1,0:1,0:1,0:1,0:3,0:1 t133 t134 t136 t137 t138 t140 t141 t144 x0 t145 x0 w1 t150 w1 t152 x1 x0 w0 t153 t154 t155 t156 w0 t159 t162 t163 w1 t164 t167 b- p195 s0:4 p195 p198 p198 p199 s1:1,2:1,0:2 p202 p202 p202 p202 p203 p204 p204 p204 p204 p205 w0 w1 w0 t209 t210 p210 p213 t214 p215 p215 p216 p218 p218 p221 x0 t222 p223 t224 t225 t226 p226 p226 p226 p226 p226 p226;9e2e50d5752fd012 +e105;0;0 0 1 0 0 0 1 0;0;2 5 4;3@- 7@-;t1 s1:1,1:1,1:1 x6 w6 t2 y y t3 b- p3 p3 p3 p4 p4 s1:1,1:1,1:2,7:2 s7:1,1:1,1:1,1:154,1:2,6:1,0:2;657445e407617bbe +e106;0;0;0;;;t5 y x0 b- p6 p7 p62 p63 p63 s3:1,0:3,2:1,3:1,3:2,1:3,3:2,2:7,1:1,3:1,0:8,0:5,1:2,1:2,0:1,1:1 p63 p63 s2:1,2:3,2:3 s0:1,6:1 p64 p68 p72 p75 p75 p76 p77 p78 p80 p85;60cb2a289b9ae3c4 +e107;2;0 0 1 1;0;1 2 3;;t3 t4 s0:1,0:1 t5 t6 t7 t8 x2 t9 x0 x0 t10 t13 x1 s0:3,5:2,0:223 w1 w1 t14 t15 t16 w1 t17 t18 p18 p18 p19 p19 p20 t21 t22;060e51e4cbe77772 +e108;0;0 3 1 2 3;0;2 3 4;;t10 w0 t11 t13 y x4 t14 s2:1 t15 s0:1,4:2,3:1,1:1,0:1,3:1,0:1,1:1,0:2,3:2 t16 t17 y y t18 p19 p19 p20 y t21 t22 x0 x4 t23 t24 w1 s6:1 x1 t25 t26 p26 p27 p27 p30 p30 s1:2,1:157,1:1 p31 s2:1,3:1,2:2 p32 p37 t38 x3 t41 t42 b44 p42 p42 p42;62dd9c66db196ecd +e110;2;0 0 1 1;0;2 3;1@-;x0 b7 p2 p3 p4 p4 s1:5,1:3 p4 s1:26,1:1,1:2 s0:2 p4 p9 t10 t11 t13 x3;c1974a71464670ca +e111;3;0;0;;;b- p4 p4 p5 s4:5 p6 s0:1,3:1 p6 p7 p7 p8 s3:1,2:2,1:6,7:1,3:8,1:2,4:194,2:2,0:1,0:1,2:1,2:2,3:2,1:1,1:1 p8 p9 p9 p14 p14 s6:1,0:1,1:5 p19 p20 s3:2 s2:4 p20 p20;943c9e20403553f5 +e113;710;0 0 0 0 0 0;0;3 1;2@-;t712 t713 x2 x2 t714 t715 b- t716 b717 t717 t718 s1:1,1:2,1:1,1:2,1:3,1:3,1:160 t719 t720 p720 p721 p722 s1:1,0:2,0:6,5:3,0:3,0:2,0:2,3:1,3:1,1:1,2:1,5:3,2:8 s2:2 s0:2,1:3,2:2,3:1 p722 p722 p723 p723 s3:1,2:1 p727 p727 p727 p727 p727 p727 p728 p728 p728 s1:1 p729 p729 p730 p731 s6:1,6:3,6:1,6:3,6:2,6:3,6:1,6:2,6:1,6:5,6:1 p731 p732 p733 p733 p734 p734 s5:1,1:2 p734;d4b15fa3c73f1d40 +e114;762;0 2 3 0 0 0 1 2 2;0;7 3 4 6 5;2@- 1@763;s3:2,3:2,3:2,3:2,3:1,3:3,3:2,3:252,3:1,3:6,3:8 b760 t763 w3 t767 p768 p768 p769 p773 p776 s0:1 p777 p778 t798 t799 w5 s2:1,1:1 t800 s3:1,6:3,0:1 t801 w1 s1:1 s0:1,0:2,0:1 t802 s3:1,3:2,3:1 s0:2,2:2 t803 t804 t849 t850 w5 w3 t852 b- t853 w6 t854 t855 t856 y y x2 w1 w5 w2 w3 w2 t861 b861 s6:1,4:1 t862 s0:2,2:1,0:1 t863 s2:1,3:1,2:1 t864 t865 w1 t870 b- t871 y t872 t873 t874 y t875 x7 t876 t877 t879 w7 w8 s0:3,7:1 t880 t883 w8 x0 w3 t885 t886;59cca9d47c090dff +e116;0;0 0 0 0 1;0;2 1 4 3;;s1:8,0:1 t2 t4 w2 t5 w4 t6 t7 w0 t8 t9 t10 t11 w4 s0:120 t12 s5:3 w1 s0:117,0:1,0:1,0:1,0:1,5:5,1:3,0:1,7:1,0:1,0:1,4:2,0:1 w0 t13 t18 s3:2 s3:1,1:1,0:2,4:7;d69176cddbd35bfd +e117;0;0 1 0 2;0;1 3;;t4 t9 t10 y t14 w0 x2 t15 x2 b19 p15 s0:1,0:96 p20 s1:2,1:2,0:1,2:2 t21 t22 t23 t24 s0:2,0:2 t25 x3 b29 s2:2,3:1 p26 t29 p29 p30 x1 y y t31 t32;8149efc23c4297e0 +e119;0;0 0 1 0 1;0;;1@- 3@- 2@6;s1:1 t1 x1 s0:1 t2 s1:2 t3 t4 p9 t10 t11 b9 s1:1,0:8,0:1,1:3 p11 s1:123 b11 p14 w2 t15 b- p15 p15 p19 p19 p19 p19 p19 s1:1 s1:7,0:1,1:1 s0:2 s1:6,1:1,7:3,1:1,0:1,1:1,0:2,0:1,6:2 p20 s1:3 p21 p22 p22 p23 p23 p23 p24 p25 p26 s1:2,0:1 p26 p26 p84 t85 s0:1,1:1,1:2,1:1,0:2,1:1,4:2,1:1,1:1,4:2,1:2,0:1,0:1,0:1,7:1,0:1 p86;6b83a5397dad2228 +e120;144;0 3 1 0;0;1;3@-;w0 b145 p144 p144 p145 w3 s3:1,0:1,2:2,2:1 t146 b151 w1 t147 b- p148 b- p153 w0;7d3009fdbe5d0e4b +e121;0;0 0 1 0 0;0;2 3;1@-;t1 s1:1,1:4,5:1 s1:2,1:2 s1:2,1:1,1:2,1:198,1:1,1:6,1:1,1:3,1:1,1:2,1:2,1:2,1:4,1:1 t3 s0:1 t4 s1:1 s1:143,0:6,5:1 b5 s7:2,3:1,1:1,0:4 p4 s0:1,3:3 s1:1,1:1 p43 s1:1,7:2 t85 p87 t89 p89 s0:5,0:1,0:4 p89 s1:1,6:3 p90;1b43e32591a5abca +e122;3;0 0 2;0;1 2;;t4 t5 w2 t65 t66 y y t67 t71 t72 b- t73 t74 s2:1,0:1 y x2 t75 t76 t79 y t80 t81 b79 p81 t93 t94 t95 x1 b- p95 p95 p100;ccea77059bc44b7b +e124;791;0 1 1 1 0 1 1 1 1;0;3 6 2;1@790 7@789 4@- 5@- 8@796;t792 y t793 w4 w5 s0:2 s0:3,5:2,1:1 t795 t800 x6 x0 t801 y b806 t806 s1:1 t809 w4 s1:2,1:1,1:1,0:2,0:160,0:1,4:1,0:1,1:4,0:1,0:2,0:3,1:1,7:2 t810 s1:1,0:3,0:2,0:2 s1:193 t811 s1:2,1:1 s5:2 t812 t813 p813 p814 p815 p815 p815 p818 s0:2,1:2,1:1,6:1,0:2,0:2,0:3,0:7,0:1,0:1,1:5,0:1 p818 s1:3,1:1,1:1,0:1 s1:1,1:8 s0:1,0:1,0:1 p848 b- w0 t904 t905 t906 t907 t956 s0:2,0:2,0:1,0:2,0:1,0:1,0:2,0:1,0:103,0:1,0:2 y w7 b961 t957 t958 t959 y t960 t961 b965 t965 b- w0 t966 w4 t967 w2 t971 t972 w2 w2 b973 y s0:1 x6 w4 t973 t974 t975 t976 b- y t981;fea8d73e43f66d8c +e126;0;0 1 0 1 1 0 0 0;0;2 7 5 1 6;3@- 4@6;t4 w3 b3 x4 w0 y w1 w5 t5 t6 b12 b6 t7 w5 w6 b- s0:4,1:4 t8 w0 w0 t11 t12 s1:1,0:3 t36;d94cb61b58e9ca8d +e127;3;0 2 0 0 2 3 3;0;5 6;4@1 1@2;b9 p3 p3 p3 p3 p7 p8 p9 t10 t12 t16 t17 s0:1,2:1,1:1 t18 b17 p19 t20 t21 p21 p21 p21 p22 y t24 p25 t26 b27 x3 t27 p27 s1:1,0:1 s0:2;f29a0dad10d431fe +e129;3;0 0 1 0 1 0;0;1 3;5@6 2@4;t5 b8 b10 t6 t7 s3:1,5:1 y y b- s0:5,1:1,5:3 y b12 p8 x2 y b14 p9 s2:2 p10 t11 s0:1,0:2,1:1,0:3,0:2,1:5,1:8,0:1,0:1,0:2,5:1,0:2,3:3 s0:2 p11 p11 p11 p30 x5 t31 t32 t33 y y t34 t35 y t39 t40 t41 t42 y t43 t48 t49 t51 t52 w5 t53 t55 b59 b- t56 t57 y w5 b- t58 x4 t60 w4 t61 b66 t62 t63 y x0 t80 y t81 t82 t83 x2 y t84 t85 t86 t87 t88 t89 t90 b88;44c317ccc76bbd45 +e130;0;0 2 1 2 0 2 2 1;0;4 3 2 7 5;1@-;w7 t5 b7 t8 b6 b10 p10 b- b- p10 p11 p11 p12 p12 p13 p14;4895bd94281c6ced +e131;0;0 0 0 0 0 0 0 0 0 0;0;3 7 1 8 9;4@5 5@- 6@- 2@4;t1 b3 t5 x3 t6 b- y w5 y s0:2 b- t60 y y y y s0:1,0:1,0:2,1:1,1:1,0:1,0:2,0:1,0:1,6:1,0:1 t61 s0:1,0:3,0:2,5:121 t62 b- t63 x2 t64;228c2672400bfefb +e132;0;0 0 0;0;1 2;;y t1 t2 t3 s0:3,0:1 t4 s7:2,0:1,0:2 t5 s0:3 t6 t7 y s0:1,0:1,0:3,0:7,0:1,0:2,0:1,6:1,0:1,0:6,0:2,1:1,1:3,0:102 x1 w0 b11 t8 x0 t9 t10 t12 t13 s0:1,0:1 b18 b19 x2 y t15 w2 s0:3 x2 t16;6db7e42fb1332a9e +e134;1;0 0 0 0 0;0;2 4 1;3@9;b3 x3 b- w3 y x4 b- t6 y b4 x4 b5 w1 t10 t11 b13 y y b17 t12 t16 b- t17 y x4 b21 y t18 x3 x3 b19 b21 p19 b- p19 p19 s0:2 p21 y w0 t22 y t23 t24 t29 t33 t34 t35 y t36 x0 x0 t41 y t42 t43 s1:2,3:1 w2 t44 t45 p45 p78 p79 p79 p79 p79 p79 p79 p81 p81 p82 p83 s3:1,0:1,3:1 p84 p84 p84 p140 t141 p141 p141;afe1a27d34954d21 +e135;0;0 0 1 0 2 1 0 2;0;5 6 7 3 2;;s1:1,2:1,0:1 t1 s2:1,0:2,0:1,1:1 t2 s1:1,0:7 t3 t4 s1:1,7:1,5:3,0:3,2:2,2:2,0:1,2:1,2:1,0:1,0:3 t5 s1:1,2:1,0:1 t6 t7 y x5 x2 y;3c82c3920cf17363 +e136;0;0 1 1;0;2;1@-;t1 y s0:1,2:205 t2 t3 t8 p8 p8 s2:147,1:1,7:1 p12 p13 p13 s2:1,0:1 s1:2 s6:1,2:2,1:2 s2:2 s1:1,7:2 p14 p14 p14 p15 w1 w1 t16;2285eb902312a39a +e137;5;0 0 1 0 0 0 1;0;2 4 1 5 6;;w0 y w3 t6 t7 x6 s0:2 t8 w6 w0 x6 t9 y x2 x6 x3 x2 t10 w4 w2 w0 s1:1,1:4,0:1,0:1,1:42,2:3,0:2,5:1,0:2,1:3,0:2,4:3,1:4,6:2,1:7 t11 w4 w1 t12 y t71 t72 t73 y t74;d6000de466097195 +e138;0;0 2 2 2 0 0;0;5 2 1 3;;b- y t5 t6 t7 t8 b7 s2:2,1:1,1:1,5:2,2:2,3:3,1:3,3:1,2:2,3:124 s3:2 p8 t9 b9 p10 p15 p15 s7:201 p16 s1:2 p17 s2:2 p18 p19 t20 t21 t22 y t23 b29 x4 s3:5 t24 s6:7,2:1 t25 t26 s0:1,6:4 p27 s0:139,0:2,0:2 p28 p29 b33 p29 s1:1,3:1,1:49,1:1,0:2,3:1,0:7,6:2,7:2,1:2,3:2,3:2,2:4,0:94,3:2,7:1 s3:1,2:1,1:1 s7:3 p30 s1:1 s5:2,0:1 p31;50d81008102bf74e +e139;3;0 2 1 0 2 2 0 0 1 2;0;1 6;5@11 7@- 9@1 4@- 2@8;t4 t5 t6 t47 t48 w7 t49 t66 s1:2,2:4 s2:1,2:8,0:3,1:2 t67 s1:1,3:1,0:3 s2:1,2:1,0:1,2:1 t68 t69 t70 s2:1,1:1 t72 y t73 t74 t75 t76 t77 t78 b84 s1:7,1:1,1:1,1:1 t79 t80 t83 t84 t114 t119 t120 t121 t122 b- p125 p127 p127 s0:1,1:1 p127 p127 p127 p127 s2:1,0:2,3:65,2:1 p127 s2:1 p128 s1:1,1:1,1:2;e5c659c552dbce23 +e140;733;0 0;0;1;;t734 b732 t735 t736 t737 t738 y t739 y t742 t761 t762 t763 t764 t765 y;686d1f36df73e5ad +e141;0;0 0;0;;1@-;t1 x1 b- p1 p1 s1:1,7:77,0:3 s0:1,2:7,2:51,1:1,2:1 s0:1,1:1,2:1,6:2 s1:3 p2 p5 s2:2,2:2,2:1,2:1 p6 s2:1,2:102 p12 p12 s4:1,0:8,0:3,2:1 p13 p13 s2:2,0:2 s1:1,1:2 p13 p13 s1:1;a86beb6c0f210e24 +e142;4;0 0 0 0 0 0;0;2;5@3 4@12 1@4;b- t5 t6 b5 t8 b- b10 y t9 t14 y b13 w1 b18 x4 x1 b12 p15 t16 t17 b18 y b- p42 t44 b46 y b- p75 b- p75 p75;e3a923cc83666d1f +e143;131;0 0 0 0 0 1 1 0 2 1;0;5 3 9;1@130 7@130 2@- 6@132;w8 t132 t137 t154 t155 y t156 t157 w2 t159 t161 t204 t217 t218 t219 t220 t221 w4 t224 t225 w5 y t226 t227 t229 t230 t233 t234 w1 t235 t236 t237 b- t238 t239 t240 w6 t241 t242 t243 t247 t248 t261 t264 w0 t265 t270 s5:1,2:1,2:1,0:1,1:2,0:2,0:255,0:1,1:2,0:1,0:1,0:3,1:3,0:3,1:3,2:3;e617bdf14375b188 +e144;3;0 0 0 0 0 1 1 1 1 0;0;3 9 6 4;;w3 t4 t5 t6 t7 s7:3,0:1 t8 t9 s3:2 p11 p11 p11 p11 s0:5,1:3,2:2 p12 p12 s0:2 p12 s5:1,5:2 s0:1 s1:1,0:1,0:3,0:1 p13 s0:3 p14 p14 p15 t52 t53 t54 t55 t56 s1:1,0:3 t57 t59 t60 t61 w4 t62 s7:2,7:2,7:1 w8 t65 p66 p67 p68 s0:1,1:1 s0:1,0:2 p69 s0:1 s1:1,0:3,0:2 s0:1 p70 p70 s0:1 p70 s0:1,0:1 p70 p70 p70 p74 t75 t76 t77 t78;14e9955429f533c1 +e147;0;0;0;;;t1 t6 w0 t11 t33 t34 t37 x0 t38 b- p38 p39 p41 p45 p45 s2:4 p45 p45 p45 p45 p45 p47 p47 p47 s2:1,0:2,0:2,0:1,1:3,1:1,1:2,6:1,6:5 p50 p51 p51 p51 p51 p53 s1:2,2:5,0:2;bf77ee3ef93a59f9 +e148;0;0;0;;;t4 t5 x0 w0 b10 p5 p5 p5 p6 p6 s0:2,0:3,0:2 p7 s4:5,0:1,0:1,7:1,0:1,0:1,0:2 p8 p9 p9 p9 p9 p11 p12 s0:3 p13 s0:1 p14 w0 b- p14 p14 p14 p14 s0:3,0:216 p15 p15 p16 p21 p26 p29 p29 s0:1,0:2 p30 p30 p30 p35 p36 p37 p37 p41 s0:2,0:3,0:1,7:1,0:3,0:7,0:1,0:5,0:1,0:3,0:1;2a7b8e6530869bc8 +e149;5;0;0;;;b- p5 p5 p5 s1:2,0:1,1:1,1:2,0:1,0:1,1:2 s0:2,1:1,0:156 p6 s0:1 p7 p8 p9 p10 p12 p66 p68 s1:1,1:5 p68 p69 p70 p70 p70 p70 p70 p71 p71 p71 s1:2,0:141,1:2 s4:2 p73 p73 s0:1,3:83 p74 s0:2,1:1 p75 p76 p93 p94 s1:3,1:3,1:1,1:2 p94 p95 s1:5,6:2 p96 s0:1,1:7 p96 p97 p97 p98 p98 p98 p99 p100 p101 p101 s0:3 p102 s7:1 s1:1,2:2,0:1 p102 p103 s0:2,1:1,0:1,1:3 p106 p107 p107 p107 s0:2,0:1 s1:1,1:1,3:2,1:1,1:182,0:1,0:3,1:3 p107 s0:2,0:244,0:1 p107 s1:1,0:1,1:3 p108 p108 p108 s1:1,0:1,2:1,1:1,0:1,1:1,0:1,6:3,1:3 s1:1 p109 p110 p155 p155 p155;72ba5d952f1aec5c +e150;4;0 1 1 0 2 1 2;0;4 5 3;2@8 1@11;w6 x1 y t5 w5 s2:150 w5 t10 t15 s1:4 t16 t17 x1 t19 y t20;896cb613db5e9446 +e151;337;0 1 0 0 1 1 1;0;6;1@339 4@- 2@-;t338 t339 x3 t340 t341 t342 y t343 t344 t347 s1:1,0:2,0:1 t348 b350 p348 p348 p348 s1:6,1:1 p348 p348 p348 s1:3,1:2,1:1 p348 p348 p348;681817e2c2c777ab +e152;0;0 0 0 0 0 1 0;0;2 1 5 3;6@- 4@2;t1 w4 t2 x1 t3 t4 w6 b- w0 w6 y x2 t5 x3 t6 w3 b- x5 t7 w2 s7:1,0:2,2:7 y x5 w1 t8 x2 t9 p12 p13 p14 p41 t42;fc1eb251a7aace97 +e153;0;0 3 3 3 3;0;1 4 3;2@8;w2 t1 x2 x2 w1 x0 b- p1 p1 p1 p1 p2 p2 p3 s2:1,2:3 p4 s0:2 p17 p22 p27 s3:2 p28 p28 p29 x2 s0:2,0:3,0:3 t30 s3:2,3:1 t31 t32 x0 t33 t34 t35 t39 b44 x1 w2 x3 b- w1 t40 t42 s2:1,3:2 t43 x1 x4 x4;820d992dfc7eb25b +e154;0;0 0;0;1;;t4 b5 t5 w1 b- t8 t9 x0 y y x1 s3:1,3:2,1:2 b- p13 p13 p13 p13 p13 s2:1,2:8,2:1,2:1 p13 p13 p18 p19 p19 p22 s3:241,1:1,7:3,3:3,2:6,2:1,1:4 p22 p22 p22 p23 p23 p27 p28 s3:2 s1:7,1:2,1:1,1:2 s2:74,0:1,1:2,2:66,3:5,1:3,0:1,1:1 p28 p28 p29 p30 p30 p30 p30 s3:2,7:1,4:1,0:3,1:1,4:1,7:1,2:2,3:2,6:8,2:1,1:2,0:6 p31 s3:1,1:1,1:1,5:223,3:1,3:8,2:1,2:2,3:3,0:8 p31 p34 p34 p34 p34 s0:1 p34 p35 p40 s3:1 p43 p44 p44 p44 s0:2,0:2,0:2 s3:1,0:2 s1:1,1:2,1:3,1:2,1:1,1:17,1:140,1:3,1:2,1:2,1:3,1:1,1:2,1:5 s2:4 p44 p44 p44 p44 s1:1 p45 p45 p45 p45 p47 p48 s2:191,0:1,3:93,0:7,3:1,1:2,5:1,0:1,3:1,0:2,6:1,1:1,2:1 p49 p52 s2:1,3:2,1:1,3:1 s2:3,5:1;918d5ba12a99af4a +e155;0;0 0 0 1 0 2 0 2;0;4 7 5 2;3@- 1@8;t1 y w1 t2 w4 s2:177 t3 x3 s1:1 w7 s0:1,2:1,0:1,2:2,0:1,0:2,0:2,1:1,2:1,7:2 y b2 t4 t5 s7:1,1:1,0:1,1:1;61b918fc958bb302 +e156;1;0;0;;;t29 y t33 s0:1,1:1 s0:1,0:1,2:3 t41 t46 b50 p46 p46 p47 p48 p48 p49 p49 p50 w0 t51 w0 w0 y y y b-;a043e72682b4c2fa +e157;0;0 3;0;;1@1;t3 s3:1 x0 w1 w0 b2 p3 b7 p4 s7:2,2:3 p4 p9 s2:1 p10 s3:2,0:1,1:3 p10 s0:3,1:1,7:2,1:1,0:1,6:2,1:2,3:8,2:3,2:1,0:2,4:3,2:1,4:3 p11 p14 t15 s1:2,0:174,4:4,2:1 s1:1 s0:1,3:1 s0:2,1:1 s7:1,1:2 p16 p16 p17 p20 p20 p24 s1:1;a33b37a25dd52176 +e159;4;0 0 0 0 0;0;1 2;4@-;t9 t10 b- s2:2 t11 t12 p57 p57 p58 p58 p60 p61 p61 p62 p67 p68 p69 p69 p69 p69 s0:1,0:1 p70 s0:1,0:2,0:1,0:1 p71 p72 t74 w3 t78 t79 t80 y x2 t81 t84 t85 b- b- p85 p85 p86 p87 p89 p91 p92 p93 p93 p93 p93 p93 p93 p94 p96 p96 s0:1,0:3,0:3 p96 p96 p96 p96 p96 p97 p97 s0:1 p98 p98 p98 p98 s7:1,0:1 p98 p98 p98 p99 p103 p103 p103 p107 p108 p110 p111 p111 p113;6343eb7793faa4be +e160;0;0 1 1 0 0 1 1;0;1 5 6 4;2@-;t4 w5 w0 s0:2,1:1 x6 t5 t6 w2 t7 s6:1,1:65 s0:1,0:1,1:1 t8 t9 s0:6 s1:1,1:2,1:2,0:2 t10;62b973ea78ec582a +e161;300;0 1 0 1 1 0 0 1;0;3 4 1;5@308 2@-;b- p300 s1:1,0:3 p300 p300 p303 p303 p303 p304 p304 p304 p305 p306 b304 b312 t307 p308 t362 w1 t363 b361 p363 w0 x0;81e41581f8534575 +e163;0;0 1 0 1;0;;1@3 2@1;t1 y t2 t3 x1 x1 t4 x2 w1 w2 b3 w3 y w2 t7 t8 y b6 w0 b- b8 s1:1,0:4 s6:1,1:1 s3:2,1:2 p9 s0:2 s0:3,0:2,5:2,1:1 t10 t11 t12 t17 p17 p17 p17 p18 t19 t20 w2 y b- t21 s1:5,1:2 t22 w1 t23 s6:1,0:1,0:1,1:1,1:3 t24 s0:1;bc9a4dd6d6c487e0 +e164;2;0 1 1 1 0 1;0;3 2;4@- 5@5;t31 t32 t34 t35 t36 t61 b59 s0:1,1:1,0:56 p62 s0:1,1:2,1:2,0:2 t63 s1:3,3:3,0:1,0:1 t64 t65 y t69 s0:236 p70 p70 p72 w4 b78 w3 t73 w3 x1 t78 t79 b80 b84 s1:1,0:2,7:1 s2:1,1:5 p80 s0:2 t81 s2:3,0:1,0:2,1:1,0:1,2:1,1:1 t82 t83 p84 p87 t88 y t89 t91 p92 t93 p93 p93;e12134a19b1fdbab +e167;0;0 0 0 0 0 0 0 0;0;6 3 5 2 1;4@1 7@1;t2 t3 t5 y t6 t7 t8 t13 t14 t15 s6:2 t47 p47 p47 p48 s0:2,0:2 p48 p48 p49 p51 t52 t53 t55 t56 b55 b- t57 t58 t59 w7 s2:1 w4;df47b2a66effee08 +e169;0;0 3 2 1 3 0;0;4 1 2;3@1;t2 x3 x3 x1 b- p2 p2 p2 p2 p2 p3 s2:3 s2:1,1:7,0:2,1:1 p4 s1:8,0:3,2:2 s0:1,3:1,2:1,0:1,0:1,1:1,3:1,2:1,0:106,2:2,0:1 p5 p6 p7 t8 t13 w2 y y t14 p19 p20 p21 p21 p22 p23 p24 p25 p29 p68 p68 p68 p69 p115 s0:1,0:1 p115 p116 p117 p118 p122 p129 s1:1,1:2,3:1 s2:2 p129 p130 p130 p131 x2 x5 t132 x2 x0 x5 b- p132 s0:1,3:1,6:2,2:2 p133 s3:2,0:1 p134 p135 w1 x2;c9df31abe010d556 +e170;4;0 2 2 3 1 3;0;3 2 1;4@12;t8 b14 p10 p10 p11 s1:1,1:1 p12 p12 p13 x0 t14 t15 t16 t20 w2 b24;5861cba1189fe0d2 +e171;0;0 1 0 1 0 1 0;0;5 6 1 2;3@-;b3 t1 t2 y b5 s1:2,0:3 t3 s0:1,1:1,1:182,0:1,1:170,0:2,0:1,0:2,0:3,1:2,0:2,0:1,0:4,1:1,0:1 s0:1,1:1,0:1,4:3,1:1,0:1,1:2,1:1 t4 s7:2,7:1,7:1 s0:1,7:1,0:3,0:105 t5 t6 t7 p7 s1:1,0:3,1:8,0:3,0:114,0:1,6:1,5:1,7:2,3:1,1:1,0:1,0:1,0:3,2:2,1:1 p8 t16 t20 s0:8,1:2,0:3,4:1,1:2,0:1,7:2,4:1,1:1,1:3,6:1,0:7,0:4,1:2,0:1 b- t21 t22;acd28b979ae5c330 +e172;0;0 0 0;0;1;2@-;s0:2,4:1 s0:1 t4 w2 s0:1,0:1 b3 t5 w1 t6 t7 t8 w1 s0:1,0:2,0:1,0:2,2:1,0:189,0:16,0:1,0:1,0:1,0:3,7:3,0:1 s0:1 t9 s2:1,0:1,3:1,0:1,0:1,0:2,0:2,0:1,0:3 s0:1,0:1 t10 t11 w0 s0:3,0:1,0:1 w2 t12 y y b- w1 t13 b- t18 w2 t21;17e7ed01103cf3ff +e173;4;0 1 1 0 0 0;0;3 2 1 5;;w0 s1:2,2:1,0:1,7:2,2:1 t5 b6 x0 t7 t8 p8 p9 t10 p10 p11 p12 p12 p12 p13 y t15 p19 p19 s4:1,4:1,4:2 p63 p63 p63 s6:1 p64 p64 p65 p66 p67 p68 s1:7,0:1,2:3 p68 p68 p68 p70 t71 t74 y x4 s1:2,1:1 s0:1,0:7 t76 s3:5,1:2,0:8,0:2,0:3,3:3,2:3,0:3,2:4,4:3,2:1,0:3,6:7 s3:1,2:8 t77 t78 p78;77b9acf51f1f3513 +e174;0;0;0;;;x0 t1 x0 t6 b12 p6 p6 p6 p6 p6 p7 p7 p7 p7 p7 p7 s2:1,2:3,2:1,0:2,4:1,0:1,1:1,2:1,0:1,0:2,2:1 p7 p11 p11 p12 p13 p13 p15 t16 p16 p16 p17 b20 s2:7,2:1,4:59,2:1,0:2,3:2 p18 p18 p19 p19 p19 s2:130,0:1;aba512b47cbb92a1 +e175;3;0 1 0 1 0 1 0;0;1 2 3;4@9;t4 t9 t14 y t15 y t16 t17 y s1:2,0:2 t18 s0:2,0:2 t19 t20 t21 t68;db92fcf197ac1b6b +e223;0;0 0 0 0 0 0 0 0;0;4 2 5 1 6;;s0:2,7:1,7:1 t1 t2 t3 w0 t7 y y y t8 p9 p43 y y t44 p44 p45 p45 p45 p46 w2 t47 t51 t55 t56 p77 p77 p77 p77 p77 p77 p77 p77 p78 y y y b81 t80 p80 p81 p81 p82 t83 t84 p84 p85 s0:2,0:8,0:2;44987ad1b0e1d3ee +e245;0;0 0 0 1 1 0 0 1 1 0;0;1 3 9 4;5@3 7@- 8@-;t1 t6 b- t7 b- t8 t12 b12 w9 b12 b17 s1:3,7:1,1:2 p12 t13 t14 b20;b7ed8a4ebaedf9bd +e292;0;0 1 0 0 0 0;0;2;3@- 4@8 1@3;t1 b5 b6 p5 b11 p6 t7 w0 b8 s1:2 t8 s0:1,0:2 w3 b11 x1 b8 b9 b- p50 x2 t54 b60 x4 x2 s0:1,3:5 w3 b57 w0 t58 p58 p58 p58;1a7fb4e6966b303c +e293;5;0 0 0 1 0 0 0 0 1;0;3 8 5 4 7;6@- 2@8;t19 y t20 t21 t22 t23 t24 w0 y t28 t29 t34 t35 t40 w6 w3 x5 t41 x7 t42 t43 x0 w6 y x2 t44 t45 s0:3,1:1 t46 y t50 t51 t52 t53 t54 b59 x2 t55 t56 t57;175987132172a6e8 +e297;0;0 0 2 3 1 1 1 1 0 1;0;1 3 7 8 2;6@7 9@- 4@-;t4 t5 t9 t10 y b8 t11 t14 t15 t66 t67 b67 t68 t69 y s0:1 t70 b71 t71 b- b69 t72 y b- s3:1,0:1,1:2 y t77 t78 t79 t80 y t83;aeefeec739c9ef59 +e300;3;0;0;;;t4 t5 s1:1 t6 t7 s4:1,0:1 p8 p9 p9 s0:1,3:6 p9 p9 p9 s3:1 p9 p14;a0cb392fbbb16ae7 +e332;1;0 0 2 1;0;3 2;1@-;y y s2:5 t2 s1:1,2:1 t3 t4 t5 t9 t10 w1 y t11 s0:3,2:1,3:1 s0:1,1:1,2:1 t12 s1:1,0:1,2:2,1:1,0:2,1:1,0:1,6:1,2:3,0:2,0:1 s0:2,0:1,0:1,0:1 t13 t14 t68 b70 p69 p70 b- p71 p72 p73 p73 p73 p73 p74;0fb4053865877c03 +e370;5;0;0;;;t13 b13 p13 t16 b- p17 p17 p17 p17 p17 p17 s3:3,2:1,5:2,3:1 p18 p23 p28 p28;bc72b2b166994adc +e376;0;0 0;0;;;w0 t1 s0:2,7:1 t2 s6:1,1:3,2:1,0:1,2:1,3:2,2:1,0:4,2:2,2:3,1:2,0:1,0:1,5:8,2:3,1:5 w0 s0:1,1:3 s1:1,6:2 t3 w1 t4 s2:2,0:2 p4 p4 p4 p4 p4 p4 p5 s3:1 p9 s2:1,1:1,1:1,2:1 s1:2,2:2,2:1,2:2 s0:2,0:1,5:1,3:1,0:1,4:2,0:204,3:3,1:3,3:2,1:1,5:2,2:2,1:3,3:2,3:3;ea0c267da84256c7 +e377;0;0 0 0 0 0 0 0 0 0 0;0;5 9 3;2@1 7@- 8@2 6@2;t3 t4 b5 w1 b4 t5 y t6 t7 t63 y y b69 t64 y y y y y t66 y t67 t68 b- s5:1,0:1 y y t71 y b69 y y;49cc8f8cb786c75c +e385;0;0;0;;;x0 t1 x0 b- s0:1,1:1,0:2 p1 p4 p4 p8 p8 p10 p35 p36 p40 p41 p42;591211f3b61fdb32 +e400;5;0 1 1 1 0;0;4;3@-;t6 t8 x3 t9 t14 t15 s6:2 b- t17 p20 p20 p20 s1:2,0:1 p33 t81 t82;5777af7a027107a1 +e411;1;0 2 0 3 3 3 1 3 3 3;0;5 2 1 4 6 8;9@-;w4 t2 s0:2 t7 s2:1 t8 s1:1,2:1,3:1,3:255,0:1,2:7,3:8,1:8,0:8,4:3,1:1,2:2,2:3,3:2 b9 t9 b- t14 t15 w9 t16 x5 s7:3,1:1,2:2,2:1 x2 y w2 w6 w9 t17 y x4;c092611bedca55c3 +e430;3;0 1;0;1;;w0 t4 t6 x0 b4 p6 t7 t9 t10 s0:1 s3:5 t11 t16 s6:2,0:2 p17 s0:1;2153b5fe0ed78022 +e432;0;0 1 0 0;0;1;2@4;y b- p0 p1 p2 s1:1 p3 s3:1,0:5,4:2,7:1 p4 s0:4,0:1 t5 t6 w0 s1:1,0:2,0:1 t7 s1:1,1:1 t8 s1:2 t9 t10 w0 t11 t48 t53 t54 t55 t56 w0 t57 t58 w3 b58;7690f45d0a32b67c +e465;5;0 0 0 0 0 0 0 0 0;0;8 5;1@9 2@- 7@8 3@11;t6 w2 y t11 t62 y t63 b64 t64 t65 y y t68 w6 t69 w1;9b18c4c4191c84ea +e472;1;0 2 2;0;;1@5 2@-;w1 x2 y t2 t3 t4 w0 t5 t6 t7 t8 w1 t9 t10 t11 x1 s1:4,1:2,6:2 t12 s2:2,2:8 b- p12 p15 t17 x0 y w0 w1 w2 w1 t22 t23 t25;7116da341d2e7caf +e493;0;0 2;0;1;;y t1 y x0 w1 y w1 w1 t5 y x0 t6 w1 b6 p6 t7 w0 y x1 w1 w1 t12 x0 y x0 w0 y w0 t13 b16 p14 p14 p14 p14 p15 p15 p15 p15 p16 w1 t21 t22 y t25 w0 b23 p25 y;4baa0b784fd39606 +e495;4;0;0;;;t5 t6 t7 t8 b7 p8 t9 w0 w0 t13 t14 y s0:2 t15 t16 t17;2a1de72e223cb548 +e506;2;0;0;;;t3 t7 w0 x0 t8 x0 x0 b10 s1:2,0:1 p9 s0:2,3:33,1:3 p14 s1:2 p14 p15 s0:1 p15 p16 s2:5,0:1 s1:7,2:65,4:1,2:89 p17 p17 s2:1,2:7 p17;e5805be176f8daae +e510;4;0 2 2;0;2;;y y x1 x1 b3 p4 t9 y b7 p10 y y y t11 s1:2,0:2,0:1,2:1,1:1,0:3,1:1,0:2,1:2,2:1 y;9223de12074c3fbc +e516;0;0 0 0 1 1 1 0 1;0;2 6 5 1 7;4@2 3@-;y y y y b- w4 t1 t2 s3:1,0:1,0:2,0:1 t3 s7:1,0:3 t4 y s1:5,6:1,1:1 t5 s0:2,0:1 t9 y t11 b- y y w4 y;2d81b884bb613a24 +e524;5;0 0 1 1 1 2 2;0;3 5 1;4@10 2@7 6@9;y t8 b11 s3:7,0:2,0:1 s1:1,2:1,1:1 s3:2,1:4,0:1 b- p13 y w0 b- t14 b16 t15 w4 s0:1,5:1,7:1,1:1,7:1,1:9,3:6 y x6 t17 t18 p18 s1:2,0:1,2:1,2:1,0:2 p18 p18 s1:1,1:1,2:1 p19 p21 b- y w4 b- t22 y s2:1,0:1 s1:1,1:2,0:5 t23 s2:1,2:1,6:1,0:1 t24 s1:2 t25 b- t26 b24 p26 s1:2,2:2,2:2 w5 y t30 t31 x3 s2:1 t32 t37 x0 t38 t39 s6:1 t43 p44 p44 p44 p47 s1:3,0:3,7:1 p48 s6:3,1:6 p49 p50 p50 p51 p51 p52 p57 b- t58 t59 p60 s1:1,0:254 p65 t66 t68;8ea4c361e98b5d2d +e553;0;0 0;0;;;w0 w0 t1 s0:2,0:1 t2 w1 b5 p2 p2 p2 p2 p3 p4 p4 p5 w0 t6 x0 t11 t16 w1 w0 b16 p16 b15 s0:2,5:2,0:1,0:1,0:1,0:1,0:1,0:3,0:1,0:1,0:1,0:1,6:1,5:1 p16 b- p16 p16 s0:2,0:1,2:2,0:1,0:1 p17 p19 p23 p23 p23 p23;75a37569c993d00b +e560;0;0 1;0;1;;y t5 b4 s1:1,2:3,0:1,2:3,0:1,0:2 p6 s0:2,0:8,0:2,1:3,0:3,0:1,0:2,7:1,0:1,1:1,1:255,0:1,0:1 y w0 t7 t12 x0 y t13 b12 p13 b12;3290e8bf1cf1a1f5 +e583;1;0 0 0 1;0;1 3;;t2 t7 x2 y b5 y b5 p11 t12 t13 y b11 b11 p18 t19 b19 b19 p20 t23 b- b21 p24 t29 b29 p33 b- p33 p33 p34 p35 p56 p57 p58 p59 p62 p63 p67 s5:2 p67 p68 p69 p73 p74 p75 p78 p78 p78 p79;4ef05aac17213ae5 +e598;0;0 0;0;1;;b2 t1 t3 x1 w1 t4 y x0 y w0 b8 x1 x0 b2 p4 w1 s4:1,1:1 b9 t5 t6 p6 p7 p8 s2:255 p9 p9 p14 p14 p14 p14 p14 p15 p16 s2:1,5:2,1:3,2:1 p16 p18 p18 p18 p19 p20 p20 p20 p20 p20 p21 p25 p25 p26;9d3594071fb5a101 +e623;4;0 1 0 2 1 1;0;2 4 5;1@7 3@-;w3 t5 t6 x5 t7 x1 b12 b7 p7 t10 t11 w0 b- x5 b11 p11 t12 w2 w2 t17 t18 t19 y y b17 y t20 b20 w0 t21 w1 t22 t23 w0 t24 t25 w4 t26 t71 t72 w2 t73 x0 t74 x0 t75 t76 t77;1ea35a8b0ec7b8ec +e637;0;0 2 3 0 1 0 1 2 0 2;0;7 5 8 4 9 6 2 3;1@8;s2:1,1:2,2:1,3:1,1:3,2:1 t1 s2:1,2:1,1:1 t2 b2 t3 b6 t4 t5 w9 y t6 y b7 y t7 y t8 y t9 y t10 t11 t12 t13 t16 s0:227,7:1,2:2,0:3,3:3,1:6,2:3,1:1,3:2,6:1,1:1 t17 t21 t22 t23 y;f3bee699e8d95aad +e681;1;0 0 1 2 3 2 0 1 2;0;1 5 6;8@9 4@8 2@-;x4 t2 w2 x8 t3 x2 t4 t5 x5 x5 s3:2 t6 s6:1 t7 s0:1 t8 t9 y t10 t11 t12 t13 t14 b-;15d0002dca16787f +e705;372;0 1 1;0;2 1;;x0 b371 p372 x0 t373 b371 p374 t375 t376 t377 y x2 t378 x1 b- p378;1523e37d31e7089c +e725;5;0 2 0 2;0;;1@9 3@-;t6 t11 t14 y t15 t16 t17 w3 t18 x3 t21 t22 t23 t24 x1 t25;87de8ca7e7a51a1e +e790;0;0;0;;;y t1 t2 x0 b- p4 s0:3 s1:1,1:2,0:1 p4 p5 p5 p5 p5 p5 p6 s1:1,0:1;0589f8a233da623e +e815;3;0 0 2;0;2;;b- p3 p4 p4 p5 p5 p5 p8 p8 p8 p24 s2:2,2:6 p25 s2:1 p25 p25;4522eb30e6771689 +e825;0;0;0;;;t1 y w0 s1:138,3:2,2:1,3:1 b2 p3 s3:2 s0:2 s7:1 s4:1,0:4 p3 s1:1 p23 s3:3 s3:1,0:3,5:1 p23;99a086aa630c6eb5 +e849;0;0 1 1 1;0;3 1 2;;t3 y b- p4 p5 p6 p7 s1:1 p8 s1:1,1:1,6:3 p9 s1:2,0:2 p10 p11 y w0 t12 t13 p14 p14 p14 p15 y t18 s0:2,0:2 s2:1,1:6,0:1,1:1 p19 t22 b20 s1:2,7:1 t23 y y w1 y b27 t25 t26 p27 y y b25 y w1 y y y w2 t28 y t29 p29 s1:2,4:2,1:1,0:2 p30 w1 y t31 t32 y t33 p33 p33 p38 t39 y y t44 p44 s0:2 p45 b- y y y s0:1 b51 w3 b- b43 s0:46,0:1;61524809e1d6fe4c +e855;0;0 1 0 0 2 1;0;3 2 1;4@- 5@8;s0:3,0:1,4:1,2:1,0:2,2:7,0:3,0:1,0:2,1:3,1:2,6:1,0:6,2:1,0:6,0:6 y t1 t2 t3 t8 b8 y b14 t9 b11 w1 t10 p10 p10 p10;16f66c54c93413da +e859;1;0 0 0 3 2 3 3 0;0;3 2;4@7 7@9 6@-;t2 t3 t4 s1:1,1:3,1:1,1:1 t5 s3:3,3:2,2:2,4:3,1:1,4:2,2:255,3:1,1:2,3:1,2:2,3:5,0:2,3:1 t6 b5 w0 t7 s2:3,0:1,0:167,1:1 s1:1 t8 y y t9 p9 p9 p9 p10 p10 s0:2 p10 p14 t15 w0 t16 t20 t22 t27 t32 b- y y t33 t34 s1:2,1:1,1:1 y t35 b33 y s0:1,0:1,3:67 t36 w2 b36 t39 x7 b37 p39 y t43 t44 t47;4f97a957131327c4 +e860;0;0 0 0 0 0;0;4;3@- 2@6;x4 t1 t2 b- t3 b2 p3 w2 s0:2 s0:2 t4 s0:1,0:1 s1:3,0:1 t5 t6 p20;bde9ea30b2fc7ece +e877;0;0 2 1 2 1 2 0;0;4 3 1 6;;t4 b4 s0:1,1:1 b- p4 t5 w6 t10 s0:1,0:2,1:7 b12 y t58 y b57 p59 t60 t63 t64 b69 y b63 p64 t67 t68 b67 p70 y t72 t74 b76 t98 t99;906bf35acdf124c1 +e960;3;0;0;;;b- p6 p6 p7 p8 p8 p8 p12 p12 p16 p17 p21 p21 p21 p23 p24;078838f57762b6ae +e978;5;0 0 1 1 0 0;0;5 3 2;1@-;t6 t7 t8 x4 t9 y x4 y x0 b9 b12 s0:5,1:1,1:1,0:1,0:1,3:3,0:6,3:1,0:1,1:2 p10 t11 t12 t13 t14 t15 y t16 s1:1,1:1,0:1 t17 s0:2,6:1,1:1 t18 s1:6 t19 t20 y t21 b19 t22 b23 t24 b- b22 p24 t25 b23 p25 x1 x3 x5 x0 t30 b- p31 p67 p67;09898be08f5e8044 +e1040;0;0;0;;;w0 w0 b- p0 p1 s4:5 p2 s7:2,3:1 p7 p8 p9 p9 p10 s2:1 p11 p12;0bd226f8cecc8897 +e1045;0;0 2;0;1;;t1 t2 b1 p2 s1:3,3:3 s2:3,2:2,2:1 y b- p3 p3 p3 p3 p4 t5 t6 t10;ad13d71938c1b24b +e1050;0;0 0;0;;1@-;t1 t2 y t3 t4 t5 b5 p5 y t8 y x1 x1 t9 s1:3,1:2 x1;b2f6017848d1ef16 +e1060;2;0 0 0 1 1;0;2;4@10 3@3 1@-;y y t4 x4 t5 t7 b8 x3 t8 t11 w1 b10 w0 x0 t12 x1;69670f3a902774ad +e1068;1;0 3 1 0 1 3 1 0 3;0;3 8;4@- 5@-;t6 t7 t11 x5 b10 b- p12 w3 t13 t17 b23 s3:2,3:3 w0 b16 t22 y s2:1 x3 y t23 t24 p25 p54 s2:1,2:1 s1:1,0:1 s1:1,2:1,2:1 s3:2,3:1 p55 s1:2,3:3 p58 p58 s0:1,1:1,2:1,3:1 p59 w6 t60 y t63 b62 b64 p63 s5:3,2:8 w3 t64 t65 s1:1,0:1,0:2 p65 p68 y;69f02e84ead0be89 +e1107;3;0 0 0 0 0 0 0 0 0 0;0;2 5 4 8;7@2 9@6 3@- 1@-;t4 s0:1,2:1 t5 b3 b9 b11 t6 t7 p7 s0:3,0:3,0:2 p7 p8 b13 s0:1,0:1 y t10 t11 b9 b13 y w5 t12 b- t14 b19 b19 t15 b18 b- t16 b21 t17;0a48b5b02db6165b +e1112;0;0 0 0 0;0;;1@- 2@-;t1 t2 w1 y b8 t3 y b1 p8 y y y w2 b- t9 b15 w1 t10 w0 t11 t12 t13 t14 b17 y t15 t16 y b14 t21 w3 w2;efee0597146f0d27 +e1140;0;0 1 1 1 1 1 1 0 0 1;0;8 7 1;2@1 3@7 4@-;b- x4 w0 t1 b4 x2 t2 t3 b2 b- p3 t4 t5 x8 b11 w4;397a1d15e4a89d6c +e1176;0;0 0 1 1;0;2;3@-;t1 y b4 p3 p40 s1:1 s1:51,1:3 t41 t42 b41 p42 t45 y t46 t47 y y t48 t49 w3 y t50 x0 s5:1,0:1;8d22c6bc9e536225 +e1189;0;0 2 1 1;0;1 3;2@-;y y t4 y t5 t6 b- s2:3,2:1,1:4 s0:4 s1:1,0:3,0:1 s0:1,0:3,0:2 p11 s1:1,2:1 s0:2,2:1,1:1 s1:1,1:1 s2:8,1:1,5:1,1:6 s1:1,2:2 s2:2,1:2,0:3 p11 s0:2,2:1,0:1,0:2,2:1,6:1,1:157,2:2,2:216,2:1 s0:3,0:1 p11 p12 p13 p13 s5:1,1:1,0:6 s1:2,1:1 s2:1,2:3 s2:2,0:1 s7:1,2:1 p13 p13 s2:1,0:1 s2:2 p14 p15 t16 y b- s5:1,0:2,1:2,1:1 s2:3 p16 p17 p20 p22 s1:7,0:2,1:3 s0:1,0:1 p23;747a62d24ddab575 +e1200;0;0 2 0 0;0;1 3;2@-;t1 t2 t3 t4 y t5 t6 t7 y s1:5,7:3 t8 s1:2,1:1 t9 s0:1,4:1,3:1 t10 t11;29952d4c2d478df1 +e1226;0;0;0;;;s2:2,0:1,2:3 t1 s2:3,2:2,2:2 w0 w0 t4 s1:1,4:1 p5 s1:4,0:7,2:2 p6 s0:1,1:1 p7 p8 w0 w0 t9 p9 s0:2,0:1 p10 s2:2,2:2,2:1,2:1 t11 s0:3 p12 t13;97f478e666db63b7 +e1230;167;0 0 1 0 1 1 1 1 1;0;4 8 3 1;5@- 6@175 7@175 2@166;x7 y t168 x2 x5 x6 s1:1,1:1,1:1,1:1 s1:1,0:1 x1 y x5 t172 t177 x1 t178 y;d3400076175dab72 +e1236;0;0 1 0 0 0 2;0;4 3 5 2;1@4;w2 s2:1 w4 t3 y s1:1,1:1,0:1 t4 w3 w4 w3 t7 s0:1,0:1 t8 s1:1 t9 s0:170 t10 s1:1,0:1,0:1 t11 t12 t13 w0 t14 t15;3dcba8515285b9b3 +e1258;790;0 0 0 0 0 0 0 0 0 0;0;4 5 6 3 1;2@790 8@- 7@792;t791 t792 t793 y t808 t809 y t810 y x7 t811 t812 y s1:1,0:1 y t813 y b818 b816 t816 p816 p816 p816 p860 p861 t863 y t864 p864 p869 t871 w1 y w6 w8 y y t872 p877 t882 p882 s0:2,0:7 p882 s0:2,0:1,1:1,0:1,5:3,1:1,7:2,1:1 p883 s1:2,1:1 t884 s1:76,0:20,1:1;92bc7389579bfb48 +e1270;0;0 1 0 0 0 1;0;2;4@5 5@- 1@- 3@4;y t1 b- t2 b1 p6 b6 t11 t12 b11 t13 t14 b12 b- w5 t15;f5d35271159c8d8c +e1310;2;0 1;0;;;b1 p7 t12 t13 t15 t19 b17 p19 s1:1,0:1 w0 w0 x1 b17 p19 t20 t21;3e3200e72951e68f +e1313;0;0 0 3 3;0;2 3 1;;s7:3,7:1,1:2,0:1 t1 s2:1,3:1 t2 s1:100 t3 t4 p5 p5 s0:1 s1:2,7:8,2:1 p6 s6:2,1:2,1:29 p7 s2:2,0:1 p8 s6:1,6:2,6:1 p9 p10 p11 p11 s3:1,6:1,0:1,2:7,0:1,0:1,0:1 p11 p12 p13 b16 t14 p14 p14 p14 p14 p15 s2:3 s3:1,2:1,2:2 t16 s6:3,2:5,0:4,2:8,1:1,3:2,2:1,3:2,0:1,3:1,5:1,2:1,2:3,2:1,0:2,2:1 s1:1 p20 s3:1,3:2,3:137 p21 s0:1,2:2 p22 s3:1 s3:1 p23 s0:3,3:3,0:2,0:2 s2:6 p24;95733e5fabcfcf43 +e1360;2;0 0 0 2 0 2;0;2 3;1@2;y w1 s2:2,1:1,0:2 y t3 y t4 y t30 s3:1,1:1,0:3,1:2,0:1 t35 w2 s2:1,2:2,2:1 y t79 t83;35c9f7f70ae1cd5c +e1430;4;0 3 1;0;2;1@11;t5 t6 t7 t12 b- p12 p15 p15 p16 p18 s3:3 p19 p20 b18 p20 t21;e40968b6aff0b3bc +e1478;0;0 2 0;0;;1@2;b3 p44 t45 t46 t47 t48 t49 t50 w1 b49 p50 t52 x2 t53 y t55 s2:3 t56 s4:2 t57 t58 p59 p59 s0:1 p59 s1:1 p60 s0:3,1:1 p61 p62 b63 p63 t64 b63 p64 b67 p65 p65 p65 p65 p66 p67 t68 x1 t69 s0:2,0:2 s0:1,1:1 p74;2a3a1fa78b5d7475 +i5;0;0 0 0 0 0 0;0;1 5;2@-;b- b5 t3 t6 y x3 t7 b6 w2 y b7 p11 w0 s0:1,0:1 t12 b15;6bf60a85a359b66b +i50;0;0 2;0;1;;t1 t3 t4 b10 p5 p5 s5:2 p5 x0 w0 t6 y p6 p7 b8 x0;60c94b944965a80c +i71;0;0;0;;;y y y t1 t5 b5 p5 t6 t7 t7 t8 y y y s4:1,0:2 t9 t10 w0 p14 x0 t15 t16 s0:2,3:1 y;96f7cb1545790977 +i82;0;0;0;;;p1 t2 t3 t4 x0 t5 t6 t7 t9 p10 b13 p10 p10 p10 p10 p11 y p11 s2:2,2:1 t12 s6:1 t13 t14 x0 p14 p15 p16 p17 t18 y p19 p21;651a3e5319308df8 +i95;0;0 0 0 2 1 2;0;5 2;4@- 3@-;w4 y w5 y t1 s1:1,1:22,1:1,1:2 t2 y p2 w3 p3 t4 p4 p5 t6 p15;79461a913b807c1c +i108;4;0 2 1 0 0 0 1;0;2 1 6 4;5@-;b6 b9 w5 w0 b8 w5 s0:3 s1:1 s2:2,3:77 t4 b8 b10 b- w4 w5 t5 t9 y b- t10 w2 w0 s0:1,0:1 b8 x0 p11 w5 b- p11 y w4 p11 w0 p11 t12 b14 t13 t14 y w5 y x4 t15 w2 s0:1 t16;e9aa98dce6a07608 +i115;0;0 1 0 2 3 0 3;0;1 4;6@6 5@-;t1 t3 w3 y t4 s7:3 y w6 x6 y w5 y x2 w2 w0 t8;1943c9d5d9b2bde7 +i123;0;0 1 1 1 1 1 0 1 1;0;8 3 4 6;1@4 5@1 2@5;t1 w0 t2 t3 x8 x5 t4 t5 w4 t21 b25 t22 t27 t28 t78 x5 p78 w8 b78 w6 t79 x2 w2 x1 x7 s0:2,1:4 t80 t81 t82 t84 t86 t87 b- t88 t89 t90 x4 x0 t91 b90 t94 b94 t95 t153 b- t158 x2 t162;9173689e7a012591 +i125;0;0 0 3 1 2 2 3 0;0;3 5 2;4@7 6@8 1@8;y x6 t4 w1 y w6 t5 y y t6 w6 x4 t7 t8 b14 w1;86ed001e5e2a0565 +i145;5;0;0;;;b11 p8 x0 t9 s3:1,1:2,0:8,1:1 t10 p10 x0 s0:3,2:1,1:3,0:3 p10 p10 w0 x0 x0 w0 t11;2e8201ad3cf2f636 +i165;0;0 0 0 0;0;2;;b- x1 t1 t3 b3 b- b5 p3 b- p3 t8 t9 t10 t11 t12 t13;6b9b2830807c0cbc +i197;4;0;0;;;b7 b8 t5 b- w0 y p5 y t6 p7 t8 y b7 p9 s0:2 t10 s1:1,0:2 w0 y p11 w0 w0 y y b9 w0 p11 y y b13 t16 w0;c9793743d0cc37e2 +i205;0;0;0;;;s1:2,1:8 t0 p1 w0 t1 t3 p3 t33 p34 p35 t36 p36 p37 y p37 t40;2e39931cc5598dcb +i211;3;0;0;;;t4 y y x0 p6 t7 t8 y t9 t10 x0 p11 b9 s3:1,2:1 p11 b12 t12 x0 b- b- p12 p13 y t14;969fe32a1e8e38ba +i240;0;0;0;;;p0 y y y t3 s0:1,5:3,4:5 y s1:6,5:2 t4 s3:3 p5 w0 w0 s0:7,0:3 y t6;50047dca69aaac77 +i258;2;0 1 0 0;0;2;1@2;t3 x1 t4 b- s1:1,1:1 s0:1,1:1 y b2 y t5 t8 t9 t10 w2 t11 t35 t36 t37 t38 t38 t42 t43 t44 t45 x1 x3 t46 t47 x0 t52 b- t52 t56 t57 t58 b57 t59 t61 t62 x2;29ae4e33de3b7cc7 +i262;4;0 1 0 0 0;0;4;3@6 2@11;w2 x0 p4 w3 t5 t6 t7 t8 b13 b- w3 p8 w0 t9 t10 b16 b10 x1 w2 b- w0 w3 b14 b- w2 t18 b21 w0 b23 w3 s1:2 w0;20ec46e01bf723b1 +i280;0;0;0;;;w0 p0 t2 t3 t4 p7 x0 s2:2 t8 s1:2 t9 s0:3,0:1,0:1,1:1,2:1 t10 t11 b16 w0;d48c86473ed454ef +i288;0;0 0 0 0 0 0 0;0;1 5;3@8 2@1 4@-;w3 x4 y t1 w4 t2 y t3 x5 y x6 x3 y t4 t5 p6 x2 x6 y x6 t6 t6 t7 s3:1 s0:1 t8 s5:1,0:2 s1:2,0:1 t9 t10 p11 t16 p17 y b23 x4 t18 b17 t19 t20 t21 x4 t22 t42 x1 y x2 p79;5c824da8bf924afd +i315;0;0 0 0 1 1;0;4 1;2@- 3@5;x3 w2 s1:2,2:1 w4 w0 t1 t2 t3 t4 t4 t4 x3 s3:1,7:1 s1:1 t7 t7;996c93c5297790e2 +i323;0;0 1 2 2;0;1 3;2@-;w3 b- t0 t1 p1 t2 p2 p3 t3 y t4 t4 p5 w1 p5 p6 t8 b10 t8 b13 t8 w1 y w0 p8 t10 p10 t12 p12 t13 y s2:1,2:1 p14 p14 t17 w3 w2 t19 t20 w2 w3 t25 t55 t56 w1 t59 w0 t60;eb77f0e3d57c994b +i355;0;0 0 1 1 0;0;4 3;2@6 1@-;w1 s0:1,1:1 t1 t2 t3 t4 t4 p5 w2 t6 t7 y y t8 b14 p8;ebd3fc968f796c02 +i366;0;0 2;0;;1@-;y y t1 t2 w1 w0 t3 t5 t5 w0 y w0 t6 y b6 p6 w1 y t7 t8 y b8 t9 y;4e3b5a3eeda9c3ed +i370;3;0 1 1 1 0 1 1 1 0 0;0;1 3 6 7 9 5;2@11 4@8;p5 t6 t7 p8 b6 b10 x6 b14 p8 t9 x2 b11 p13 t44 y p44;46858cb1501ddb08 +i372;4;0 0 1 2 0 2 0;0;3 2 4 1;5@- 6@-;p5 w6 s0:1,1:1 s0:1,6:3 w0 s1:1,7:3 t7 t8 t9 p9 p9 t10 t11 t12 p13 t14 p19 t24 t25 t26 t26 p26 t27 t28 b- p29 t30 p31 x2 t38;f438d056e8148769 +i380;3;0 0 1 1 0 2 0 1 0;0;5 8 3 2 7 6;4@1;b5 x3 b3 w1 t5 t6 t7 t8 b6 t9 t10 s1:2 t13 x8 y t14;554a1dffb0702741 +i428;0;0 2 1 0 1 2 2 2 1 0;0;1 8 3 9 2 5;4@- 7@- 6@-;p3 t4 x1 t6 t7 s2:2,1:1,2:1 s1:1,0:1,2:1 t8 t9 y p9 w4 t13 t14 t17 t18 x1 x3 t20 p20 x3 y t23 w5 x7 y s1:1,1:1,2:1,1:1 t23 t24 t32 x8 w5 p36 t37 t38 w6 y t39 t42 t43 p44 t45 x6 x8 t46 t47 t48 y;c79ea5185ecaaaa4 +i452;5;0 0 0 0 0 0 0 0 0;0;6 2;8@5 5@5 4@10 3@5;t6 t7 p8 p9 t10 x2 t11 t12 w6 w2 t13 y w1 t14 t16 y w6 t18 t18 b17 b16 t19 t22 t22 t23 w5 t30 w3 w1 t31 t32 x1;45d47678cabde928 +i471;5;0;0;;;t6 x0 b- x0 s6:224,1:1,1:1,1:4,1:1,0:1,2:1,7:2 s5:8,0:3,0:2 b11 x0 w0 w0 p6 b11 x0 x0 x0 p7 t11 t11 t12 b12 p15 p15 p15 p15;ab9fe42a1ac41d29 +i488;2;0 0 0 0 0 0 0 0 0 0;0;5 1 9;2@8 7@7 3@- 4@9;w4 p2 t28 w3 t29 b35 p32 t32 t33 t36 t37 w2 p38 b39 s1:1,1:2,4:1 t38 b38 t42 w3 p47 p48 w2 p48 t49 w7 s0:255,1:2,5:3,1:1,0:2,0:1,0:2,0:3 t50 s1:1,0:1 t51 s1:234,7:1,1:2,1:2,1:2,1:219,1:3,1:3,1:2,1:3 t52 t53 p53 p53 s1:1,1:1,1:1,1:1,1:3,1:1,1:2 s0:2 t54 s7:8,1:2 t55 x3;2fdf7cf57557d26e +i522;0;0 0;0;1;;p0 w1 t1 t2 t3 w0 y b7 w1 b8 b- t4 p4 w1 b- s2:2,3:3,0:1 t6 w1 p7 p7 p11 s1:3,2:1,3:1,3:1,3:1 b- x1 w0 p13 s0:2,2:1 s2:1,2:6 s3:1,0:1,2:1,2:2 p13 b- p14;b49d685445fe6bce +i536;0;0 2 3 0 1 1;0;5;2@- 3@-;s0:1,3:1,0:5 s3:1,6:1 s1:2,3:1,3:1 t1 s3:2,3:6,3:1 s1:1,0:1 t2 t3 y t8 y t9 t11 t12 t13 t17 b16 p18 s5:1 s3:1,1:3,2:1,6:1,2:2,2:2,3:1,1:3,1:1,0:2 t19 s1:1,1:2,1:3 s1:128,0:1,2:2 t20;86185579a6f63894 +i540;562;0 0 1;0;;1@-;y b560 p562 s7:1,1:1 t563 t564 y t565 b563 b- b563 y t565 x0 s0:2,6:1,1:3,0:1 t567;a4cb76a0439d95da +i548;0;0 1 1 1 0 0 1 0 0;0;5 3 7 8;2@8;x2 b1 x5 t1 w3 b- s0:5,1:1 s0:3 t2 s6:3,7:1 s1:1,1:3,6:3 t3 t4 t5 s0:1 b9 t6 t7 p7 b9 t8 b13 x2 b9 p9 w7 w3 p9 w5 t10 b- b16 b13 t11 t12 t13 t14 t15 b16 t42 b44 x2 t43 b45 x2 b44 p44 t45;858b5da3b07a7f8a +i555;0;0 0 0 0 0;0;2 3 4;1@4;t1 t2 t3 s2:1,2:3,7:1 s0:1,4:7 y t7 b6 y t12 b12 y p12 p13 y w3;79ecf43fa19091b4 +i556;148;0 0 0 0 0 0 0 0;0;4;1@148 5@156 6@149;w4 b- x1 b153 p149 x1 y x7 t150 t151 t152 s0:1,0:2 w0 s0:1,6:1,0:1,0:1,1:1,0:1,7:3,0:1,0:3,0:1,0:1,0:1,0:3,0:193,0:1,0:1 s0:4,0:2,0:1,0:1,0:1,0:2,0:1,7:1,0:2,5:3,0:1,0:2,0:1,0:3,0:2,0:1 s0:124,0:2 b- w4 t153 t154 t154 x3 t155 x0;41fa446f8350604f +i618;1;0 1 0 0 1 1 2 0;0;4 2 1;5@9 3@7 6@-;w3 x5 y b- t2 b7 b- x6 x6 t3 b2 b7 p3 x6 b3 p3 p3 x6 b3 p7 x2 b- y t8 t9 p9 x4 b- b11 b11 p10 b- x6 p10 x2 p10 t11 w0 t12 p12 b- p13 b14 t14 p15 w0 p15 w1;ef1b19b3239f7530 +i629;0;0 0 0 0 0 1;0;2 5 1 3;;t1 b7 t4 s2:2,1:1,5:2,1:2,0:1,1:1,1:4,1:3,0:3,0:2 t5 s0:1,1:1 y t6 t7 b10 t8 t49 t50 t51 b56 y t52 s1:3,1:1 t53 s1:5,0:3,0:241 w0 x2 b54 t54 t55 x5 t56 t57 b- p58 t59 p75 t76 t77 b- b82;91a85b4286904a73 +i640;0;0 1;0;1;;y t1 t2 p2 y p3 b3 p3 x1 y x0 x0 p3 x1 y t4;b7643ebff59e6f1f +i666;0;0;0;;;t39 x0 s2:1,1:1 t40 x0 s1:2 t40 t41 s1:3 t42 t43 p48 p48 s1:2,0:2,1:1 t49 b51 p50 p50 s2:3,0:2,1:1 s1:1 t51 s2:2,3:2,1:6 t52 s0:1,0:2,1:3,0:1;88c9b3599055154c +i715;0;0;0;;;b2 p4 p4 t5 b- p5 b8 t6 p6 p6 p6 b4 p6 t7 w0 p7;eeed0d3d08c738af +i725;0;0 0 0 0 0 0 0;0;4 2 6 5;1@- 3@-;s2:1 t1 t2 t2 p2 t3 t4 p7 t12 p12 x2 p13 t13 x4 p33 t34;cb4d554178db754e +i762;0;0;0;;;t4 p4 p5 s4:3,1:5,0:1 s2:1,2:3 s2:3 t6 s4:8,4:1,4:2,4:1,4:2,4:3,4:2,4:8,4:1,4:1 t7 s3:4 t8 t9 p10 y p11 x0 t14 p14 s3:3,2:1,2:1 b13 t15 p20 p22 s3:1 t23 s0:2,0:1 t24 s0:5 t25 t26 t31 p31;80118120b660b9d9 +i785;0;0 0;0;1;;t1 t2 t6 y p6 s1:2,0:1,0:1 t7 y t8 x0 s0:3,0:3,6:1,0:1,1:1,2:3 p8 b14 p8 w1 t9;0375ec93a40a9752 +i792;0;0 0;0;1;;w0 t1 s1:3 t6 p6 w1 b7 s7:6,0:1 p7 t8 w1 p8 t9 p10 p11 t12 p12 b- b13 t13 p14 t15 p15 x1 t19 b23 p19 p19 b- t20 p20 p21;a1ddf30b7ff00eaf +i805;0;0;0;;;x0 x0 b- x0 t5 w0 y b6 s7:1,1:5,0:2 t6 s1:1,1:3 t7 s1:1 t8 t9 b9;6e726bfb7b5a4d2f +i830;4;0;0;;;t5 s5:3,2:1,0:3,0:1,0:2,2:2,0:1,0:3,1:1,0:7,1:3,4:1,2:3,2:1,0:1,0:1 t6 s6:1 t7 y w0 w0 t8 s1:6,5:1 w0 t9 p65 t66 p67 x0;1e9ba03c66d24807 +i837;5;0 2 3 2 1;0;4 1;2@13 3@-;t6 b6 s2:3,3:2 p6 b5 s3:2 y p6 t11 x2 t15 b16 t16 y y y t20 b20 p71 w3 y b75 t72 t73 p74 p74 t75 x3 t75 p77 b- p80;9fd09d5f7658cb71 +i855;0;0;0;;;t1 t1 s1:1,1:2 t2 s0:1,0:3 y w0 y y y t6 b4 p6 t6 t11 s4:1,2:1,0:1;afd32e4f8af5b0cd +i918;0;0 1 1 1 3 0 2;0;2 4 1;3@-;p1 t24 w2 t25 p29 w2 b- w0 w0 b32 x3 w1 p33 t37 p37 p37 s1:1,0:2,2:1,7:83 p37 p37 x2 t41 y t42 p42 b- p42 p42 x3 x2 p43 w0 x0 t45 y x1 p50 p50 w2 t50 x2 w1 w0 t55 p55 x3 p60 p60 p61;576c023c11dbdaa0 +i920;0;0 0 0 0 0;0;;3@6 1@3 2@7;p0 y t1 x2 y y t6 t7 t8 y t9 t9 y t14 p15 t24;9f16992e123d20bf +i931;0;0 1 0 0 0 0 0 1;0;5 4 7 3 6;1@3 2@1;t1 p1 p1 p1 p1 p1 p2 p2 t3 t4 t5 t6 t6 y t7 b13 p8 t9 p9 w6 t10 t12 p12 t30;dac0a41a11cc4efc +i936;0;0 1;0;;;s1:1 t1 t2 p3 t3 p3 t4 t5 t6 p6 w1 p6 w1 p7 p7 w1 w1 t8 p13 t13 b- p13 t14 p15;ea0695aabfe94136 +i941;0;0 1 2 2 2 2 1 0 2 3;0;1 2 9 8 4;7@1 3@3;b- p1 b- t5 w5 b4 p5 p55 w8 t56 t57 b- p60 t64 w5 w7 w1 w1 b64 x0 p64 w0 t65 p65;01a44a9486cdc344 +i952;0;0;0;;;t3 t8 x0 p8 t9 y y y t10 b12 y t42 b- p42 t43 b- x0 y w0 p44 t45 w0 b- y p45 p45 y y y p46 t47 y;c8fdc9a9a92e106d +i970;0;0 0 0 0;0;2 3;1@-;t1 t2 t3 t4 b5 p4 x0 b3 t5 t6 t7 b- t8 t9 t10 b9;ac47c4037f7bc1e9 +i1005;3;0 1;0;1;;t4 p5 x0 t6 x0 s1:1,0:1 t10 t10 t11 t12 t15 b21 y s0:3,0:1,0:1,1:1 w0 y;f9903b34f4485734 +i1021;0;0;0;;;y y t1 t2 b1 p2 y y s2:135,0:1 w0 p3 t4 p41 t42 t43 y x0 p43 p43 t44 p45 p46 s2:2 p46;6121034559cf56a7 +i1051;0;0;0;;;t1 t2 t7 b- p7 t11 t11 y p11 t11 p12 p12 t13 p13 t13 w0 t14 p15 t16 s5:1,0:2 p16 p16 y p16;16d43a684e776db3 +i1056;0;0 2 1 1 0 1 0 0 0;0;6 7;5@7 4@6;t1 t1 s7:1 t2 t3 t4 t5 t5 t6 x2 t9 p11 t11 p11 p12 p13 p18 p18 s0:1 p22 t23 t24 t25 t25;1e03f19e44ed2774 +i1060;0;0 2;0;1;;s2:2,2:1 p3 t4 s0:5,6:2 b3 p9 s1:1 s7:1,1:2,2:1,2:2,1:1,0:2,1:1,1:3,2:6,2:1,1:5,2:155,1:1,2:1,3:1,3:7 t10 b- s0:2 s0:1,7:1,1:1 t11 t49 p50 p50;bd45c67801add043 +i1131;0;0 0 0 0 0 0;0;2 1 3 5 4;;t0 t4 s2:2,0:2,1:2 t5 s7:1 t6 t7 t8 p8 s0:2,1:3,2:2,3:1,1:2,2:3,0:1,4:2 p8 t8 s2:219 t9 p9 p9 s1:1 s3:2,2:1,4:2 t10 s2:1,2:3,0:2 t11 s0:1,2:1,2:2 t12 t13;e2ca1d5de3d8be35 +i1135;0;0 1 1 0;0;2;3@- 1@5;b- p0 t1 p1 b- t2 b6 t3 y t7 p7 b- p7 p7 t8 t10;321d41380d0ac574 +i1145;2;0 2;0;1;;t3 t4 t4 y t5 b- t6 p6 p6 p7 p7 t8 p9 b- t10 b16;2ffa859b230ddb7f +i1160;2;0 0;0;1;;t3 b4 b1 p3 w1 t7 t8 t9 y b7 t10 t11 b- t12 t13 t14;9acdc18f6bf193f9 +i1200;149;0 0 1 1 0;0;1;3@149;x1 x4 b- t150 b150 p150 b- p150 x3 t151 w1 s7:3,0:2 t183 y t184 b183;af0dca3bfbfaf45c +i1205;151;0 0 0 0 0 0 0 0;0;3 5 2 6;4@157 1@159;b- t152 b150 t153 b158 w1 y b151 y s0:2 b154 b- b156 x4 b159 p153;86ebc215f19f7900 +i1209;3;0 1 3 2 0 3 2 1 2;0;2 3 6 1 5;7@-;t4 t5 w0 t7 w8 w3 w4 y y w4 t8 w8 x7 w6 w1 t9 b- p9 t10 s2:2 s5:4 p10 p11 x5 w0 p11 w6 p11 t12 s2:3,3:2 t13 s1:1,2:1,3:1 t14 t15 t16 b- t17 t21 w4 t22 t23 y w2 y b22 t24 x5 t29 y t31 t32 t33 w3 y y s5:1,1:2 x3 t34 t34 y t35 b40 p36 t37 w1 y t38 p38 t39 y y t40 x0 p88 t89 t90 t90 t95 t96 x4;fa55ea0f12741aa5 +i1221;0;0;0;;;t1 t1 b6 t2 p2 p2 s1:3 w0 t3 s2:17 p4 s6:3,0:5 p5 y w0 s1:1,2:2,1:4 y p5 w0 t6 t10 p11 s0:2,0:1,1:1 p11;7e42299b4873a761 +i1257;1;0 0 0 0 0 0 0 0 0 0;0;3 7 9 2 8;6@- 4@- 5@-;p1 t4 b3 b6 s0:1,2:1 y s1:7,1:1,6:3,4:76,0:1,0:7,0:255,0:1,0:1,1:1,6:216,0:6,5:1,0:2,0:2 t5 t6 b- t7 t12 p12 t15 p56 w9 t57 t58 p58 b- p59 p60 p60 p60 p86 t87 t87 p87 t88 p88 p88 p90;a94d677949090f27 +i1280;4;0 0 2 0 3 0 1 2 1;0;8 6 2 4;1@7 7@4 3@4;s2:1 w8 w5 w4 x3 y t4 y t5 b10 b5 p5 b- t10 x1 s1:4,2:8;0c18251cdce6e19f +i1302;3;0 0 0 0 0 0 0 0;0;4 1;2@11 3@5 6@5 7@3;x7 b3 t4 t5 b9 p5 t6 y b- y b11 b8 t7 t8 b10 y y t9 y y t12 y t12 t14 w0 w7 t15 y y t16 y p22;fc4a8915c442b61d +i1345;0;0 1;0;;1@-;p1 t4 s1:2,1:3,1:2,1:1,1:1 p5 y t6 t6 w1 w1 x1 t6 p6 p7 p11 b16 p14;fa40fe87dabd3465 +i1360;0;0 1 2 2;0;3 2;;x2 y b- t5 p15 p15 b- b- t16 p33 y t34 b38 p35 p36 p53;df34866d2d60f08f +i1386;420;0 0 0 0 0 0 0 0 0 0;0;2 3 9;5@418 7@- 4@424 6@419;t421 y t422 t423 b423 s0:245,5:2,0:6,0:1 b- t423 b- b424 w6 b421 b- b- b423 t424 b424 w2 b430 b427 b- b430 b- b429;811553dfa131e695 +i1393;713;0 0 1 0 1 0 0 1 1;0;3 1 6 7;5@- 2@718 8@712;x3 t716 s1:1,0:1 t717 s1:2,0:1,0:1,0:2,1:1,3:2 b- b716 x8 x8 x1 t718 w8 b721 w7 y t756 y x6 x5 t757 w3 b- t757 y x6 t758 t759 t760 t761 w1 w7 t801 t802 w5 b807 t803 t804 b- w0 t809 b807 t809 t810 t811 w1 x7 t812 t813;82ab684fde5418d8 +i1395;0;0 3 2 2 0 0 0 1 3 1;0;3 2 1;5@8;x6 y y t0 y y t1 t4 t5 b3 p5 t6 b7 t7 x8 t8;3622cb87826fed54 +i1400;0;0 1 1 0 0 1 0 1 0;0;2 7 5 4 8 3;6@- 1@2;x6 w7 b4 w5 x1 b- x5 t1 x5 b1 b5 b4 p6 t7 b5 t8;3d5896498caf8cb4 +i1410;5;0;0;;;t6 x0 t8 w0 p8 b12 t9 p10 t11 p12 w0 t13 b11 p13 p14 t15;14b5b50538880aed +i1440;5;0 2;0;1;;b3 p5 p61 b- p62 t63 b- t64 y p64 t69 t70 p70 t71 s0:7,0:1,2:1 t72;1f41fa6f00cfbdc0 +i1450;0;0 1;0;;;b- t1 t1 t2 t3 y t4 b8 p4 b7 x1 x0 w0 p5 b3 t6;5dcc506375690619 +i1455;0;0 0;0;;1@4;s1:2,1:2,7:1 t1 t2 p3 t4 t4 w1 t4 t6 t30 t31 t32 p33 p34 t35 p36;60debf8d6d5f634c +i1531;3;0 1 0 1 0 1 1 1 0;0;3 6 8 5 4 2;;y y t4 t5 x5 t7 t8 s6:1,1:1 t9 t11 t16 p17 y b18 t18 t19 t20 p21 w2 b- t24 p25 x5 b31;9c47e7d89650b577 +i1532;0;0 1 1 1 1 0 1;0;2 1 5 3;6@-;t1 t2 s1:2 w4 p3 s0:1,0:1,0:1,7:5,0:2 s1:1,1:2,1:1 b5 t6 p7 s1:1,1:2 s1:8 s1:1 t8 s4:4 p9 s2:1,2:1,1:1 t10 b- t11 b- w1 p11 s4:1,0:255,1:7 s1:1 s1:1,1:2 p12 t13 t14 t15 t16 t20;722fe6132dd36298 +i1555;0;0 1 1 1 1;0;3;;b1 p1 t6 t7 t8 t9 s1:1,2:2 t10 s2:1,2:1 t11 s2:1 t12 t13 p14 p15 p15;afc83e54fc7cba41 +i1556;0;0;0;;;s4:2,4:1 s1:8,1:1,1:1,0:2,0:2,1:1,0:2,1:1,0:184,1:2,1:2,1:3,0:2,0:3,0:1,0:3 b- p0 t1 p5 p6 s0:1,1:2,0:1,0:3 s0:1 x0 p6 b11 x0 s1:1,7:1,0:1,1:4,4:1,0:1,1:2,0:39,5:225,1:2,1:2,1:1,1:1,3:3,1:1,4:3 p6 p7 s1:1,5:1 p7 t12 t13 s0:1 s1:1,0:2,1:1 p13 b15;68df738ec9093706 +i1597;0;0 1 1;0;2 1;;t4 s0:2 s1:1,1:1,0:162 t5 t6 s1:1,1:4,0:3,5:2 t7 t8 t9 t10 x0 t11 w2 x0 w0 w1 b- s1:3,0:2 s0:4 t12 s1:6,1:1,1:2 s1:2,0:1 t13 t14 t15 t16 t38 x1 p39 b44 p40 t44;ea0f62fadd7def25 +i1602;1;0 0 0 0 0 0;0;1 3 4 5;2@3;t2 b7 t3 b1 w1 t4 b10 t4 t5 s0:1,0:1,0:1,0:1 b- b7 t39 y b- w1 w4 y t40 t41 t42 b45 t43 w2 x1 b- w1 t44 b46 y x0 b-;94537f68cc2a5617 +i1636;576;0 0 0 0;0;1;3@577 2@577;t577 b575 b578 b580 t580 b- t581 b- t582 y y y b586 b- b581 t582 b588 p583 t584 b- p584 t585 p585 s0:1,7:2;ad97aca3e6fd654f +i1684;0;0 0 1 1 0 1;0;5;1@- 4@3 3@-;w0 t1 t2 s1:2 t3 s1:1,0:4,1:8,1:1,1:2 p3 t4 t5 s1:2 w3 b- t6 w2 p6 b10 t7 p10 t11 p11 x1 t11 p12 t13 p14 x4 b- p14 y p14 p15 t16 p17 t18 p19;fa38ef1e980f85d4 +i1691;0;0 3 2 3 1;0;2 1;3@5;s4:1,0:2 y y t1 s3:1,3:3 s2:1 t2 s3:1,3:1 t3 s0:2,0:1 t4 t5 b8 t6 p40 t41 w1 y w3 t42 w3 t43 b- t44;11b8ecff8b3248da +i1701;4;0 1 1;0;1 2;;y w0 y t5 y p16 p17 y t18 b18 p18 w2 y t18 t19 t20 t21 t22 t23 t24 t26 t30 t34 y;dc4e7efe797c962a +i1725;0;0 1 2;0;;1@-;t1 t2 t3 w1 t4 w1 b- p7 p8 w0 y w0 p8 x1 p9 t10;608b24f3f1fc7fd5 +i1751;254;0 1 0 1 0 1 1 1 1;0;3 2 1 6 7 8;5@253;t255 s1:3,0:2,1:2 p255 t256 t258 t259 p260 t262 t263 y p263 s0:1,1:1 t264 y b266 p269 s1:2,4:66 b267 t271 t302 p303 y y p303;f3a1ba3fd40222ec +i1781;75;0 0 0 0;0;2;3@75 1@74;b76 t77 t82 t83 t88 y p90 t91 t92 t115 t115 x1 b115 t116 t117 b121 x2 s0:1 t118 s0:1,7:1 t119 t120 t121 p122;55d28e8fefbd03f7 +i1792;3;0 2 2 2 1 1 1 0 0 1;0;1 5 3 8 7 4;9@-;y y t4 x1 y t6 t7 s5:2,6:1,0:3,2:1 t7 y y t9 t10 w9 t14 y y t15 y y w9 t16 x4 p17 y s2:1 t18 p19 t58 y y w0;557acf0ead34afe0 +i1793;2;0 3 2 3;0;3;2@6 1@-;t3 s0:2,3:7 t4 s2:3,6:1 t5 s0:2,2:1 t6 t7 x2 t8 t58 t59 t60 t61 t62 t63 t64 t65 t66 t70 t75 w1 t76 t77 t78 b82 b78 t83 t86 y t87 t89 t90 y t91 t92 x0 t93 t94 t99 y t100 y w3 t101 t102 p103 y;7cd3a69cb6bee5d8 +i1794;2;0;0;;;x0 b- p4 t5 t6 p6 p7 t8 t9 p9 x0 w0 b8 t11 x0 x0 x0 p12 t12 t13 t14 x0 t18 t19 t24 p24 t25 p26 p27 p28 x0 p28 t29 p29 y t32 t33 p34 p35 w0 t36 x0 t38 b- t39 p40 t41 w0 t42 p42 p42 t43 x0 p43 x0 t44 p45 p45 y t46 t47 w0 t48 t50 p50 p50 x0 p50 t51 t52 w0 p52 x0 y p53 x0 t54 b53 t55 p98;c1738b2adf4e8daa +i1800;3;0 0 2;0;1;2@-;t4 t6 p6 b- p9 b9 p9 b10 p9 t10 y t11 b- s2:1,2:6,2:3 p11 p12;cff12866c4e309e5 +i1805;0;0 1;0;;;b- p1 p2 p4 p5 t6 t7 t8 p9 t10 p10 t11 p12 p12 y p12;e1945acf7a635833 +i1828;1;0 0 1;0;2 1;;b4 t2 s2:1,5:2,3:2,2:1,2:1,1:1,0:6,2:1,1:1,2:2,7:2,0:1 p4 y b7 b- p4 t9 t10 b- p10 t10 p11 t12 b- t13 b- t14 t15 p15 b21 p15 p18 w2 b- b18 b20 b- y p18 p18 b17 y t19 w1 t20 t21 t22 t23 t24 p29 t30 p33 s0:1 b- t34 p34;14cb5cffe0f0bd14 +i1835;335;0 0 2 0 0 3 2;0;4 3;6@334 2@335 5@336 1@339;t336 s2:1,7:2,3:1 b342 s0:1,2:1,3:1,3:2 t340 b- t341 b- p342 x5 t343 s1:2,1:1 t344 t345 s0:1,1:1 b-;eecb60673a17519d +i1840;0;0 0 0 0;0;3 1;;t1 w3 w2 t2 t3 x3 b6 t4 b2 b9 t5 b3 p6 t7 t8 b8;0f904dad583a5e56 +i1881;3;0 3;0;1;;w1 w1 w0 t15 t16 w1 t21 w1 t22 y t23 b22 w0 p23 w1 t24 t25 t26 b30 p27 p27 p28 t29 w0;cbc63a598370eaed +i1900;1;0 2;0;1;;t2 t3 b2 p3 b- p9 b12 p10 p11 p12 p13 t14 p14 w0 t15 p16;e8f2815e168f4c5b +i1925;856;0 3 2 0 0 2 2;0;1 5;2@- 3@-;t859 x5 b862 t860 b- y t861 w3 p861 p862 t867 t868 b866 y p868 p868;48d5e874a5a5de47 +i1947;3;0;0;;;t4 x0 t5 b11 t5 p6 p7 t8 b- x0 x0 x0 s5:1,1:1,0:1,0:1 t9 p9 p9 x0 p9 y p9 p9 p9 t10 p10 p10 t11 x0 p14 b19 b- p14 p15;35164cb5947fc7fd +i1955;0;0 1 2 0;0;3;2@-;t1 t2 w2 s2:1,2:1 t7 t8 y s2:1 t9 s7:2,1:3,3:1,2:3,1:2,0:2,1:1,1:2,2:3,6:1,0:3,1:1,2:1,2:7,0:1,0:3 t10 t11 p11 p12 p12 s1:1;4253847753d2cd3e +i1957;0;0;0;;;s3:7 t1 s1:3 x0 t2 t3 t6 y b7 b11 t7 x0 b6 t8 s3:5 p9 x0 b- t9 s3:3,2:1 t10 s0:2,2:1,5:1 t11 s3:1,1:1 t12 t13 p13 t14 p14 t14 p15 t20;e91a30ce28260c66 +i1960;0;0;0;;;t1 t2 y t3 w0 x0 b5 x0 p7 b7 p7 b- p11 p11 t12 p13;b181165067075d70 +i1980;1;0 3;0;1;;t5 b- b11 p5 t5 p5 t5 p6 b8 y p7 p7 t46 t47 t48 y;331e1d5950966b5e +i2005;2;0;0;;;b4 x0 p2 y p2 x0 p3 x0 p6 t11 b- p11 y p11 t12 b-;1ab6a4083aca4ea7 +i2037;1;0 0 2 1 0 2;0;1 2 4 5;;t2 w5 t3 t4 s1:1 t5 s2:1,0:76 t6 s2:1,2:2 t7 s5:227,5:1 t8 s2:1,4:1,2:3 t9 t10 b- y t11 s2:1,2:6 t12 s2:2,1:3 t13 t14 y p16 p16 w4 s0:1,1:7 t17 s2:8,2:1,0:1 p18 p19;39be112b3fb149f9 +i2060;0;0;0;;;t1 t2 b1 p2 t3 t4 b2 t4 s1:2,0:1,0:2,0:71,0:1,0:2,0:2 p4 x0 b7 y s0:1,0:2 t5 s0:3,0:80;47dabe5b24be7cd3 +i2085;4;0 0 1 1 0 1 0 1;0;5 3 6;2@- 4@7;t5 b4 t6 w4 b4 p6 t8 t9 s7:1 y t11 t14 t15 p16 w6 x2;cfad782d49fbfaf9 +i2087;0;0 0 1;0;2;;w2 t1 s0:1,0:2 t2 s2:3,2:3,2:1,2:1,2:2,2:3,2:1,2:2,2:1,2:3,2:1,2:255,2:2,2:6,2:1,2:1 x1 t3 w2 t4 t5 y p6 p7 y y w2 t7 s2:227 s4:1 w0 t12 w0 t13 p13 p13 w0 t14 w0 p14 w0 t15 w1;322d3c00389401df +i2113;4;0 0;0;;1@-;t5 t6 s0:1,0:2,4:2 b6 b- p6 s0:1 x1 b4 w1 p6 w1 t7 y t7 t7 b10 t8 t9 t10 s0:2,6:1,2:1,4:1 t10 t11 s0:1,0:2,0:1,0:1,0:1,0:247,0:2 t12 s0:3 y t13 y y b14 p14 t15 y t16 t21 t22 t22 t24 t25 t29 t30 y w1 t31 s7:1,4:2,7:1 s0:3 t32;ae2d86d832b4f908 +i2116;1;0 0;0;;1@-;t6 p7 b7 p7 p7 t7 t9 t10 b- b8 t12 p12 p12 p12 p13 p17 p17 p22 p23 t24 y p24 t25 p25;00fa751ca98c1a07 +i2127;0;0 3 3 2 0;0;4 1 3;;p3 t4 p4 p4 p4 t5 p6 p6 p7 w3 p12 t13 t18 x2 p19 t20 w2 t21 y p24 p24 t25 p25 p25 p25 p25 y p25 s5:222,2:1 y t26 t27;37ba85793db78dde +i2135;0;0 1;0;;1@-;t1 t2 t6 t7 t8 b8 p8 s1:5 t9 t54 p55 p85 t86 t87 x0 w1;2caf3510a26d8305 +i2140;0;0 0 2 1 1 0 2;0;5 6 3 1;;t5 x5 b8 w3 x0 t6 b5 t17 w2 b17 b17 t18 t23 t27 t28 y;698d50b1e2ce62c5 +i2145;1;0 1 1 0 0 0 0 1 1 1;0;7 1 3 4;6@1 8@8 5@2;t2 t2 t3 s4:1,4:1 t6 t7 p7 t7 p7 t8 s0:1,1:2,0:3,3:3,4:195 p9 t9 t10 t11 t11;a1f41e96cbadcd9f +i2176;0;0 0 0 0 0 0 0 0;0;4 7 6 2 1;3@3;w3 x6 s0:1,1:1 t1 s6:3,1:1 t2 s1:1,7:1,1:3,1:1 t3 t4 p6 s0:2,0:1 t7 t8 b- b11 b14 y b14 p8 b- p24 t25 p27 t33;a74fcfe660c178a5 +i2220;1;0 1 1;0;2;1@3;t2 t3 t3 t4 t4 w2 t58 t58 t86 t86 w1 b- p86 t87 p87 t92;20c7cc35c43dc688 +i2223;4;0;0;;;t5 t6 t7 s0:1,1:3 t12 t13 t14 p15 t16 t48 s1:54,1:8,1:1 t49 b53 p50 s1:2,0:3,0:11,1:251 b- t51 s0:1,1:1 p51 t52 t53 t54 p54 p74 b72 t74 p74 p79 y y t80 p81 t83 t84 p84 p84 p85 t86 t90 p91 t95 y t96 p97 y b101 p97 p97;c1d1006a09dc3751 +i2233;0;0 0 0;0;2;1@-;y x2 y y t1 t2 y b- b6 t3 x0 y y t4 y y w1 p63 t64 b- x0 t65 t67 p85 x0 p85 y p88 y x0 p93 w1 y p93 p93 p94 p94 b93 p94 x0 t95 x2 t96 y p96 x1 w2 t143;050440f9d5b6711f +i2235;0;0 1 1 0;0;3;1@- 2@-;t1 t47 x2 t48 y t49 t50 y t51 x1 t56 t57 y t58 y b56;26b7cc6ff2943ce7 +i2259;3;0 0 1 2 3 3;0;5 3 1;2@- 4@-;y x4 t4 p11 t12 p13 b19 x2 y t14 b14 x4 p14 t15 y b13 y x4 p17 y s3:3,1:2,2:2 t18 y y p19 t20 y t21 y s2:1,0:1,0:2,5:1,0:1,3:1,5:7,2:2,1:1,0:2 y t75 w1 y t76 t77 y t78 y t79 y w0 t80 t80 t81 s3:3,0:1 y y t82 x5 p83 y y y y y b85 y y y t84 x3 y t88 t89 y p89 t90 w3 t91 t92 t93 t94 b93 p95 x1 w3 p96 b94 p97;a7fa75dc960ba5f0 +i2270;0;0 1 1 1 0;0;2;3@- 1@-;t1 t2 t4 t5 t6 w3 t7 t8 w3 x3 b7 t9 x1 t10 x1 t11;d5f5ba5f2a205a89 +i2286;921;0 1 2 2 0 0 2 2 1;0;5 8 1 3 4;6@- 2@- 7@919;p922 w8 t923 w1 t924 s2:13,0:1,0:1 t925 t927 t932 t933 t934 b932 t935 b- t935 s0:1,2:1,3:1,1:8,1:2 w6 x7 t960 t963 p963 s0:1 y t964;674005022d733342 +i2301;0;0 1 0 1 0 1 1;0;2 5 6 4 3;1@-;t1 b- w3 s5:1,1:4,0:1,0:2,0:3,7:2,0:3,0:1 t2 w0 t3 t4 x1 s1:1,0:1,0:131,1:1,1:1,1:1,1:1,0:255,1:1,1:3,0:1 t5 y t9 t10 w4 t11 x1 w2 b- w2 x2 t12 x3 y;a54562b5eea6a08f +i2305;3;0 2 1 3 3 0 0 2 3 0;0;6 8 4;9@6 5@2 2@10;b- b4 p3 b5 p3 t4 b4 t5 b6 t6 x5 s2:3,1:2 p7 y t12 t13;ac51b9cb4a9b00cf +i2323;0;0 1 0 1 1 0;0;1 2 3;4@-;w2 s0:1,1:1,2:2 t1 s0:1,1:1 t2 t3 b- w0 p3 t3 w2 t6 t7 w2 x2 t11 b10 t12 y t13 y t14 t14 p14 w4 w5 x2 y t15 s3:2,0:2,0:1,0:2 x2 t16 p16 t19 t20 x2 b24 b- s1:2,0:1,2:1 t21 s1:2,2:2 t22 t23 x2 p25 x0 w4 x4;684e900cc9e1686a +i2337;5;0 3 1 3 3 1 2;0;4 2 3 1;6@4;y b3 p5 x6 p6 t7 w3 s0:3,0:1,2:1,0:1,1:3,0:1,3:2,1:1,1:1,0:1,2:1,6:2,3:1 x5 s3:2 w5 b6 p7 w1 y t9 b14 s3:1,1:1,3:1 t11 w4 b17 w3 t12 t13 s6:2,1:5,3:1 p14 y y t15 p15 w6 p15;4637bfda5e6cd69f +i2364;0;0 0 0 0 0 0 0 0 0 0;0;4 5 9 1 2 3;6@-;t1 x0 t2 b- s0:1,3:2 p2 p2 p3 x8 p50 x6 p55 p56 p56 t61 t62 p62 p89 t89 w7 p90 p90 p91 x3 w4 b- b- y t92 x4 t93 p95 p96 t97 b- t98 b96 p107 p107 p108 p108 t109;34cbea4d53695475 +i2425;0;0;0;;;p0 t1 s1:1,1:2 w0 b6 t2 t3 s1:1,3:5,6:2 s1:1,0:5 p3 s0:2 t4 p4 t4 t4 t9;7e99a315bf704915 +i2487;0;0;0;;;b3 p0 p1 p1 p1 s2:1 p2 p4 p4 p5 p5 p5 p5 b10 p5 s0:1 p5 p6 p11 b- p46 t92 p92 p93 p94 s0:1,0:3 s3:1 p94 t95 s1:5,1:4,1:1 b93 p95;62a525fb78fa724e +i2494;0;0 2 2;0;;2@3;b- t0 t1 p1 b- t1 b- w1 x2 t1 t2 t7 t7 p9 p9 p9 p9 s2:1,2:2 t10 s5:2,4:69,2:1 p10 b10 b13 t14 t14 b12 t15 t16 p17 t18 s0:7,2:8 s1:3,1:2,0:2;6389fb49e4238005 +i2495;0;0 1 1 1 0;0;1 2 3;4@-;b- b4 b2 y t1 w4 t1 p2 w2 p2 y p3 t4 t5 p6 t7;801aa44203f94082 +i2501;0;0 1 0 1;0;2 3;;p1 s2:2,2:1 t2 s1:1 t3 t4 b4 p4 t8 x0 x3 y t9 w2 t10 t11 b- p11 y p11 y p14 p14 p16;c57cd69ca1b503c4 +i2505;3;0 1 3 2 1;0;3 2;4@6;t4 t5 y t6 t6 b9 t7 p8 p8 p8 w0 x4 b13 b- t8 t9;21708ebd58bae452 +i2530;0;0 0 0;0;1 2;;t0 s1:1,0:1,2:1,1:2,2:1,0:2,7:1,2:4,2:2,1:1,2:4,2:3,2:2,1:1,3:2,1:2 t1 s0:2,2:1 t2 y w0 t59 p61 w1 t62 p63 b- b66 b61 p64;8ec927d9fee5bc4b +i2531;0;0;0;;;s2:1 x0 t1 t2 x0 t3 s4:2,4:2,4:1 p3 p3 y t4 p4 t37 x0 x0 p41 x0 t42 p80 y x0 t81 p81 t82;6cfdb4d9beed8680 +i2535;0;0;0;;;y w0 w0 t1 b5 p2 b4 b1 p2 p3 y y s0:2 b- y p4;9aa11c684e2908c7 +i2538;0;0;0;;;b2 t1 t2 t3 t4 t5 s0:2,0:2,0:206 s0:1 t6 s0:3,0:2,0:105 s0:1,0:1,0:1 t7 t8 t9 y s4:1,7:2,2:2 t10 s0:1,0:2 w0 s0:1,0:2 t11 s0:1,0:1,0:1,0:93,0:2,0:1,7:3,0:1,0:2,0:1,0:1,4:1,5:255,2:1 w0 x0 x0 t12 p12 x0 y t13 x0 t29 w0 t30 t31 s0:7 t32 t33 w0 s0:3,0:2 t34 y y b38 t34 p38 t39 t39;5d7f6495ed88c047 +i2550;0;0 1 2 2 3 1 1 2 0;0;3 1 2 4 7 6 8;;y x4 w6 w7 y t3 x4 s4:1 s1:2 t4 s0:1,6:1,2:2,1:2,1:3,1:7,0:2,3:2,2:2,3:3,3:1,3:3,0:2,0:2,3:3,0:3 s3:3,0:1 t5 t6 b6 w3;1e69528e078f07e5 +i2551;0;0 2 0 0;0;1;;s6:70,4:2,1:1 w3 t1 b- t2 t3 s2:1,2:1,2:3 s0:1,0:3,7:3 w0 t3 s2:3,2:1,2:3,2:2 p4 s0:1 w3 t5 s2:1 t6 s4:2,2:1,2:7,0:1,1:1,2:1 p7 s7:4 t8 s3:1,3:1,3:3,3:3,3:1 t9 s2:3,2:2,2:140,2:163,2:1,2:1,2:2,2:1,2:1,2:2,2:8,2:206,2:1;fddc2cd07ec75423 +i2557;0;0 0 0 0 0 0 0 0 0;0;6;5@5 1@8 4@- 7@- 2@-;t3 w6 w7 t4 p9 t10 p10 b- b- p10 t11 t13 t14 b15 b17 s0:1,0:7,0:3 b14 p53 b56 b59 t53 t54 w6 w1 t55 w3 t59 b- t60 t61 p62 t64;9cc8be240e97a820 +i2640;0;0 3 2 3 2 2 2 2 3 3;0;2 8 3;9@8 4@-;p0 p0 s3:1 s4:3 p0 t2 p2 p2 p5 t6 b- t7 p7 y y p7;8b5dcae5463500c7 +i2641;0;0 2 2 0 0 2 1 0 1;0;1 3 4 6 5;8@-;s2:2 x8 t1 s1:2 t4 s2:1,1:1 t5 y t6 b- p6 t6 t7 t7 w6 t8 t9 y w4 w2 t10 w1 w3 t11;6cb8def6e15f6174 +i2642;5;0;0;;;y s3:1,2:1 t6 s7:3,0:1 t7 s2:2,2:3 t8 t9 x0 p9 p10 y t11 y p12 t12 t13 y t13 x0 p17 t46 t47 t48 t49 p50 t51 t54 t55 t55 p55 w0;0fb5e3731fbdfa7a +i2650;5;0 1 2 2 2;0;4 3 2;1@13;b8 y p6 p7 s2:1,2:2,2:236,1:3,0:1 t8 y t11 b10 b11 b11 t12 y t12 b- t31;909719cb9a67003e +i2652;0;0;0;;;b- b- t4 s0:2,1:1 t5 b6 y s0:186 b9 s1:3 b- p6 s4:5 t7 s1:1 t8 s0:1,1:1 t9 t10 b- x0 s0:1,1:7 p10 b- b12 x0 y x0 p10 s1:8,1:8 b- t11;49ec2e35966035c1 +i2705;0;0 0 0;0;2 1;;p1 t2 p20 t21 t22 b21 b20 t25 p25 p25 p25 w1 b26 p26 t27 x0;d975d013a9ef7bbc +i2718;0;0 0;0;;1@-;t2 t3 t4 t5 t14 y b18 y t15 y p16 p17 p18 y b- y t19 p20 p20 p21 y x0 p21 x0 t22 x1 p23 x0 p27 x1 x0 p28 p28 p29 t30 p32 x0 t33 x0 y t36 x1 p37 y p39 t40 t41 p41;70b99e54430a482a +i2722;1;0 2 2 1 0 1 1 1 0 0;0;9 5 7 3 6;4@1 2@- 8@-;t2 t3 p8 b9 b14 t9 t9 s4:1 b10 x3 b9 w0 w8 s0:31,2:3 t13 t14 w8 t15 w7 t16 w1 t17 t17 b17 p17 p18 w8 t19 t24 b24 b24 t25;0085f60564dac7d7 +i2726;0;0 2 0 1;0;1 3;2@-;t1 y s0:1 x2 t2 b8 p2 y p34 b37 y b- y p35 s0:4,1:2 y y y w3 x2 y p35 s0:3,0:2,2:1 t39;8bf24d8d9fcb654c +i2727;5;0 1 0 1 0 0 2 0 1 2;0;7 6 1 9;8@5 2@- 5@5 3@-;b4 x8 t6 t7 w2 p7 w1 p8 t9 b8 b7 p9 t10 p70 p70 b73 p71 p72 t73 t73 x3 p73 w6 t78 t79 x9 t80 t81 t81 p81 t86 y;cbd63baaf99adae3 +i2728;177;0 1 0 1 0 0 1;0;4 6;2@- 3@181 1@175 5@-;p177 t178 w1 w5 w2 x3 y t179 t183 t230 t231 p232 p232 w4 t233 y p234 w6 p235 w4 y w3 t236 s0:1 x2 s0:3,1:1,1:2 t240 p240 w3 y w5 p241 p242 y p246 p290 p290 t291 w5 w3 w5 b296 t292 y p293 t294 b- p294;e1c871e2e2804ab3 +i2741;0;0;0;;;t1 w0 b1 y s4:1 y p1 s2:8,0:1 t2 y t3 p3 t4 y s0:1,0:2,3:2 p5 s0:1 y p5 t54 w0 x0 t55 y;2624bbce00ec2f7e +i2750;595;0 0 0 0 0 0 0 0 0 0;0;;4@594 2@- 6@595 8@594 1@599 3@- 5@594;y t596 y y t596 y y b597 x9 b- t597 y t598 b603 y t599;2e6580c3519a8d37 +i2765;0;0 2;0;;1@-;t1 b- w0 w0 w0 w0 p1 p1 p2 t3 w0 b4 y x1 y y;ff061df3657747ce +i2772;510;0 0 0;0;2;1@513;x1 t511 y y p512 b517 b511 p512 y y s0:1,2:2,1:2 t513 t513 x1 b- t518 p518 t519 b520 p520 p520 p521 t526 p530 t531 p531 t532 p532 s1:2,0:1,1:2,2:1 t533 s2:2,2:1,5:6 t534;a86fcc238368943b +i2786;0;0 1 1 1 1 1;0;1 2 3 5;;w0 w2 s0:2 x2 t4 p5 t6 x1 t7 t8 p8 t9 p10 x2 t11 t13 x2 x3 x2 b11 p15 x3 t16 x5;b7d6e9bfdcb0a284 +i2817;0;0 1;0;1;;t0 b- y t1 y w0 t3 t4 t5 p5 t6 y t6 p10 p10 t12 w1 t13 p18 s1:1,1:8,1:1 p36 x1 b34 p37 t41 y w0 t51 b57 t51 p52 t106;7b637030273030ca +i2823;0;0;0;;;w0 t1 y s0:1 s1:42 b- t1 w0 y s0:63 t2 s1:1,1:1 t3 s1:1 t4 t5 b4 p6 t7 w0 t8 t10 y p11 t12 s0:1 t13 s0:2,1:3 t14 t15 t15 p15 p15 t16 p17 t18 t19 b19 y t20 t20 b23;fd8764d75d30bc61 +i2869;0;0 1 2 1 0;0;3 4 1;2@8;t5 t6 t7 t8 y t9 y t10 p10 s4:2 b8 t12 p13 p13 t14 t15 s1:2,7:1,2:1 p17 t18 t19 t20 t21 t22 x4 t23 t24 t25 t26 y p26 t27 t28 p28 w2 t28 p31 p50 s1:2,1:1,1:8,1:1,1:8,1:1,1:1,1:1,1:1 b53 y t51 t52 s0:1,2:1,6:2 t53 t56 x2 p57 t58 t59 p59 x4 t60 y p64 t65 t66 t67 t68 w2 p73 t75 t76 t77 p77 t81 p81 p81 t81 p82 b- t84 w2 t85 w3 p85 p86 t91 t92 p96;1d339e42d5c14139 +i2870;0;0 0 0 0 0;0;4 1;3@3;x0 t1 y b1 t6 y y b7 b- t7 t8 y b- t9 b10 t10;e77673077a1532f3 +i2890;1;0 0 0 0 0 0 0 0 0 0;0;5 4 3 8;2@1 9@- 7@2 6@4;t48 t49 s0:1,0:6,1:2,0:209 t50 s0:2,3:1,0:3 b49 w7 t51 b- w9 t52 b50 t56 t58 t59 b-;594946cc83e4a272 +i2998;0;0 0 0 0 0 0 0;0;3 5;6@- 1@3 2@-;t1 w6 t4 t5 x4 y x6 w2 y t6 t7 t8 t9 x1 t10 s3:3 x3 t11 b- x4 t13 p17 t18 p19 t20 b- t20 x3 p21 t21 p21 t22 w1 p22 t22 p23 p23 b24 t24 t25 x6 p30 p31 p32 p32 x6 b38 y;f2af2d81f2f4cd2e diff --git a/crates/k0-part/src/tests.rs b/crates/k0-part/src/tests.rs new file mode 100644 index 0000000..30b48c7 --- /dev/null +++ b/crates/k0-part/src/tests.rs @@ -0,0 +1,2724 @@ +//! 진짜 Core를 이산 사건 모형 위에서 돌려 검증하는 테스트 모듈입니다. +//! +//! 모형은 커널이 하는 일을 틱 하나를 [STEPS]칸으로 나눈 시간 위에서 흉내 +//! 냅니다. 틱이 오면 먼저 틱 사건을 처리하고, 칸마다 도는 태스크가 프로그램의 +//! 연산 하나를 합니다. 실행 중인 태스크가 없으면(Idle) 그 칸은 비며, 입력이 +//! 도착했을 때만 대기 루프가 poll을 부릅니다. 틱은 태스크가 도는 중이면 tick, +//! 커널이 기다리는 중이면 poll로 들어옵니다(실제 커널의 두 경로). +//! +//! 기준은 Core와 따로 적었습니다. [Plan]은 표의 효력 시점(설정한 틱 + 2)과 +//! 한 바퀴 펼치기를 Core와 다른 방식으로 적은 기준이고, [Host]는 Env의 구현이면서 +//! 호출이 올바른지 스스로 검사합니다(창 밖의 실행, 다른 도메인의 일, 경계에서 +//! enter_domain 누락 등). 위반은 첫 하나만 기록하고 시뮬레이션이 끝난 뒤에 +//! 보고합니다. +//! +//! 깨뜨리기 시험을 위해 Core의 사건 논리를 옮겨 적고 한 줄씩 틀리게 만든 +//! [MutCore]를 둡니다. 실제 Core는 테스트에서 변형할 수 없으므로 이 방식을 +//! 씁니다. 틀림 없는 [MutCore]가 실제 Core와 같은 결과를 내는지는 따로 +//! 확인하므로(`copy_equals_core`), 옮겨 적은 쪽이 갈라지면 그 테스트가 알립니다. +//! +//! 모형이 다루지 않는 것은 다음과 같습니다. 시스템 콜에 걸리는 시간, 커널 경로의 +//! 길이, 실제 준비 큐와 기한 목록의 구현, 캐시와 같은 마이크로 아키텍처 상태입니다. + +use std::collections::VecDeque; + +use k0_slice::{Entry, Slice, Verdict}; + +use super::*; + +/// 틱 하나를 나눈 칸의 수 +const STEPS: u8 = 3; + +/// 공유 오브젝트(세마포어)의 수. 도메인 d는 2d와 2d+1번을 씀 +const NOBJ: usize = 16; + +/// 태스크가 칸 하나에 하는 연산입니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Op { + /// CPU를 내놓지 않고 돎 + Spin, + Yield, + /// 틱 n개짜리 기한 대기 + Wait(u64), + /// 오브젝트를 기다림(Post가 있을 때까지) + Pend(usize), + /// 오브젝트에 신호를 보냄. 다른 도메인의 오브젝트면 명시적인 공유 채널임 + Post(usize), + /// 입력을 기다림 + Read, + Exit, +} + +/// 태스크 하나의 프로그램과 도메인, 입력이 도착하는 (틱, 칸)입니다. +#[derive(Clone, Debug)] +struct Spec { + domain: u8, + prog: Vec, + inputs: Vec<(u64, u8)>, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Why { + Timeout, + Input, + Post, +} + +/// 도메인의 흔적에 남는 사건입니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Ev { + Ran { tick: u64, step: u8, task: usize }, + Woke { tick: u64, step: u8, task: usize, why: Why }, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum St { + Ready, + Running, + Timed(u64), + Pending(usize), + Reading, + Dead, +} + +struct Task { + spec: Spec, + pc: usize, + st: St, + input: u32, +} + +/// 표 변경의 효력 시점을 Core와 다르게 적은 기준입니다. 설정한 시점에 아직 +/// 효력이 없던 표는 새 설정에 밀려 버려집니다. +struct Plan { + segs: Vec<(u64, Table)>, +} + +impl Plan { + fn new() -> Self { + Self { segs: vec![(0, Table::DEFAULT)] } + } + + fn set(&mut self, now: u64, t: Table) { + while self.segs.len() > 1 && self.segs.last().unwrap().0 > now { + self.segs.pop(); + } + self.segs.push((now + 2, t)); + } + + fn domain_at(&self, k: u64) -> Domain { + let (s, t) = self.segs.iter().rev().find(|(s, _)| *s <= k).unwrap(); + let mut cycle = Vec::new(); + for i in 0..t.len() { + let (d, w) = t.entry(i).unwrap(); + for _ in 0..w { + cycle.push(d); + } + } + cycle[((k - s) % cycle.len() as u64) as usize] + } +} + +/// Core가 Env에 한 호출입니다. 깨우는 쪽(커널의 enqueue)이 하는 일은 담지 않습니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Call { + Push(Domain, usize), + PushFront(Domain, usize), + Pop(Domain, Option), + Run(usize), + Enter(Domain), + Serve(Domain, u64), +} + +/// 검사가 어떤 사건을 얼마나 보았는지 세는 값입니다. 속성이 비어 있지 않음을 보입니다. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +struct Stats { + events: u64, + boundaries: u64, + boundaries_running: u64, + boundaries_rotated: u64, + same_domain_ticks: u64, + idle_entries: u64, + polls_without_tick: u64, + yields: u64, + blocks: u64, + repeats: u64, + jumps: u64, + partitioned_events: u64, +} + +/// Env의 구현이자 호출을 검사하는 기준입니다. +struct Host { + now: u64, + step: u8, + tasks: Vec, + q: Vec>, + current: Option, + entered: Domain, + plan: Plan, + sems: Vec, + waiters: Vec>, + trace: Vec<(Domain, Ev)>, + runs: Vec<(u64, usize)>, + bad: Option, + calls: Vec, + kcur: Option, + seen: u64, + stats: Stats, +} + +impl Host { + fn new(specs: &[Spec]) -> Self { + Self { + now: 0, + step: 0, + tasks: specs + .iter() + .map(|s| Task { spec: s.clone(), pc: 0, st: St::Ready, input: 0 }) + .collect(), + q: (0..MAX_DOMAINS).map(|_| VecDeque::new()).collect(), + current: None, + entered: Domain::ROOT, + plan: Plan::new(), + sems: vec![0; NOBJ], + waiters: (0..NOBJ).map(|_| VecDeque::new()).collect(), + trace: Vec::new(), + runs: Vec::new(), + bad: None, + calls: Vec::new(), + kcur: None, + seen: 0, + stats: Stats::default(), + } + } + + fn fail(&mut self, msg: String) { + if self.bad.is_none() { + self.bad = Some(format!("tick {} step {}: {}", self.now, self.step, msg)); + } + } + + fn dom(&self, t: usize) -> Domain { + Domain::new(self.tasks[t].spec.domain).unwrap() + } + + fn record(&mut self, t: usize, ev: Ev) { + let d = self.dom(t); + self.trace.push((d, ev)); + } + + /// 깨우는 쪽이 부르는 함수입니다. Core의 사건이 아니라 태스크 자신의 도메인 + /// 큐에 넣는 것이 전부입니다. + fn wake(&mut self, t: usize, why: Why) { + self.tasks[t].st = St::Ready; + let d = self.dom(t); + self.record(t, Ev::Woke { tick: self.now, step: self.step, task: t, why }); + self.enqueue_check(d, t); + self.q[d.index()].push_back(t); + } + + fn enqueue_check(&mut self, d: Domain, t: usize) { + if d != self.dom(t) { + self.fail(format!("task {t} pushed into the queue of domain {}", d.id())); + } + if self.q.iter().any(|q| q.contains(&t)) { + self.fail(format!("task {t} queued twice")); + } + if self.current == Some(t) { + self.current = None; + } + self.tasks[t].st = St::Ready; + } + + fn check_next(&mut self, r: Next) { + match r { + Next::Run(x) => { + if self.tasks[x].st != St::Running || self.current != Some(x) { + self.fail(format!("Next::Run({x}) but the task is not the running one")); + } + } + Next::Idle => { + if self.current.is_some() { + self.fail("Next::Idle while a task is current".into()); + } + } + } + } +} + +impl Env for Host { + fn now(&self) -> u64 { + self.now + } + + fn domain(&self, t: usize) -> Domain { + self.dom(t) + } + + fn push(&mut self, d: Domain, t: usize) { + self.calls.push(Call::Push(d, t)); + self.enqueue_check(d, t); + self.q[d.index()].push_back(t); + } + + fn push_front(&mut self, d: Domain, t: usize) { + self.calls.push(Call::PushFront(d, t)); + self.enqueue_check(d, t); + self.q[d.index()].push_front(t); + } + + fn pop(&mut self, d: Domain) -> Option { + let r = self.q[d.index()].pop_front(); + self.calls.push(Call::Pop(d, r)); + r + } + + fn run(&mut self, t: usize) { + let want = self.plan.domain_at(self.now); + if self.dom(t) != want { + self.fail(format!("run({t}) of domain {} in a window of domain {}", self.dom(t).id(), want.id())); + } + if self.entered != self.dom(t) { + self.fail(format!("run({t}) before enter_domain({})", self.dom(t).id())); + } + self.calls.push(Call::Run(t)); + self.tasks[t].st = St::Running; + self.current = Some(t); + self.kcur = Some(t); + self.runs.push((self.now, t)); + } + + fn enter_domain(&mut self, d: Domain) { + self.calls.push(Call::Enter(d)); + if d != self.plan.domain_at(self.now) { + self.fail(format!("enter_domain({}) outside its window", d.id())); + } + if d == self.entered { + self.fail(format!("enter_domain({}) without a change", d.id())); + } + self.entered = d; + } + + fn serve(&mut self, d: Domain, now: u64) { + self.calls.push(Call::Serve(d, now)); + if d != self.plan.domain_at(self.now) || now != self.now { + self.fail(format!("serve({}) outside its window", d.id())); + } + if d != self.entered { + self.fail(format!("serve({}) while the kernel is still in domain {}", d.id(), self.entered.id())); + } + for t in 0..self.tasks.len() { + if self.dom(t) == d && self.tasks[t].st == St::Reading && self.tasks[t].input > 0 { + self.tasks[t].input -= 1; + self.wake(t, Why::Input); + } + } + for t in 0..self.tasks.len() { + if self.dom(t) == d + && let St::Timed(dl) = self.tasks[t].st + && dl <= now + { + self.wake(t, Why::Timeout); + } + } + } +} + +/// 시뮬레이션이 부르는 스케줄러의 사건입니다. 실제 Core, 틀리게 만든 사본, 얼린 +/// 옛 스케줄러가 같은 모양을 가집니다. +trait Sched { + fn start(&mut self, h: &mut Host, first: usize); + fn yield_now(&mut self, h: &mut Host); + fn block(&mut self, h: &mut Host) -> Next; + fn tick(&mut self, h: &mut Host) -> Next; + fn poll(&mut self, h: &mut Host) -> Next; + fn set_table(&mut self, t: Table); + fn next_tick_switches(&self) -> bool; + fn running_domain(&self) -> Domain; + /// 스케줄러가 현재로 보는 태스크입니다. + fn running(&self, h: &Host) -> Option; + fn partitioned(&self) -> bool; + /// 같은 틱 번호로 틱 사건을 되풀이해 부를 수 있는지(옛 스케줄러는 안 됨) + fn idempotent_tick(&self) -> bool { + true + } +} + +impl Sched for Core { + fn start(&mut self, h: &mut Host, first: usize) { + Core::start(self, h, first) + } + fn yield_now(&mut self, h: &mut Host) { + Core::yield_now(self, h) + } + fn block(&mut self, h: &mut Host) -> Next { + Core::block(self, h) + } + fn tick(&mut self, h: &mut Host) -> Next { + Core::tick(self, h) + } + fn poll(&mut self, h: &mut Host) -> Next { + Core::poll(self, h) + } + fn set_table(&mut self, t: Table) { + Core::set_table(self, t) + } + fn next_tick_switches(&self) -> bool { + Core::next_tick_switches(self) + } + fn running_domain(&self) -> Domain { + Core::running_domain(self) + } + fn running(&self, _: &Host) -> Option { + self.running + } + fn partitioned(&self) -> bool { + Core::partitioned(self) + } +} + +/// 사건의 종류입니다. 사건마다 Env 호출의 순서가 정해져 있습니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Kind { + Start(usize), + Yield, + Block, + Tick, + Poll, + Set, +} + +/// 사건 직전의 상태입니다. +struct Before { + running: Option, + rd: Domain, + calls: usize, + kcur: Option, +} + +fn begin(h: &Host, sc: &dyn Sched) -> Before { + Before { running: sc.running(h), rd: sc.running_domain(), calls: h.calls.len(), kcur: h.kcur } +} + +/// 틱 사건(또는 틱이 든 poll)이 낸 호출이 설계가 정한 순서인지 봅니다. +/// +/// 경계에서는 `(도는 태스크에 틱 규칙을 적용해 세워 둠) Enter(새) Serve(새) Pop(새) (Run)` +/// 이고 같은 도메인에서는 `Serve(옛)` 뒤에 규칙의 호출입니다. +fn tick_grammar(b: &Before, calls: &[Call], n: u64, new: Domain, r: Next) -> Result<(), String> { + let old = b.rd; + let done = |i: usize, got: Option| -> Result<(), String> { + let want_len = i + usize::from(got.is_some()); + if calls.len() != want_len || got.is_some_and(|x| calls[i] != Call::Run(x)) { + return Err(format!("calls after the pop: {:?}", &calls[i.min(calls.len())..])); + } + let want = got.map_or(Next::Idle, Next::Run); + if r != want { Err(format!("result {r:?} want {want:?}")) } else { Ok(()) } + }; + if new != old { + let i = match (b.running, calls) { + (None, _) => 0, + (Some(c), [Call::PushFront(d, x), ..]) if *d == old && *x == c => 1, + (Some(c), [Call::Pop(d, None), Call::PushFront(e, x), ..]) if *d == old && *e == old && *x == c => 2, + (Some(c), [Call::Pop(d, Some(x)), Call::Push(e, y), Call::PushFront(f, z), ..]) + if *d == old && *e == old && *f == old && *y == c && z == x => + { + 3 + } + _ => return Err(format!("the rule at the boundary did not park the running task first: {calls:?}")), + }; + let rest = &calls[i..]; + let [Call::Enter(e), Call::Serve(s, m), Call::Pop(p, got), ..] = rest else { + return Err(format!("expected enter_domain, serve, pop after the rule: {rest:?}")); + }; + if *e != new || *s != new || *m != n || *p != new { + return Err(format!("wrong arguments at the boundary: {rest:?} (new {} tick {n})", new.id())); + } + return done(i + 3, *got); + } + let [Call::Serve(s, m), ..] = calls else { + return Err(format!("a tick in the same domain must start with serve: {calls:?}")); + }; + if *s != old || *m != n { + return Err(format!("serve({}, {m}) but the domain {} runs at tick {n}", s.id(), old.id())); + } + match (b.running, &calls[1..]) { + (Some(c), []) => { + if r != Next::Run(c) { + return Err(format!("result {r:?} want the running task {c}")); + } + Ok(()) + } + (Some(c), [Call::Pop(d, None)]) if *d == old => { + if r != Next::Run(c) { Err(format!("result {r:?} want the running task {c}")) } else { Ok(()) } + } + (Some(c), [Call::Pop(d, Some(x)), Call::Push(e, y), Call::Run(z)]) if *d == old && *e == old && *y == c && z == x => { + if r != Next::Run(*x) { Err(format!("result {r:?} want {x}")) } else { Ok(()) } + } + (None, [Call::Pop(d, got), ..]) if *d == old => done(2, *got), + (_, other) => Err(format!("unexpected calls after serve: {other:?}")), + } +} + +/// 사건이 낸 호출과 사건 뒤의 상태를 검사합니다. 위반은 [Host::fail]로 기록합니다. +/// +/// 상태 규칙은 설계의 I1(Running인 TCB는 스케줄러의 현재 태스크이고 그것뿐), I2(돌리는 +/// 태스크가 없으면 Running인 TCB가 없음), I3(커널의 current는 `Env::run`에서만 바뀜)이고, +/// 도는 도메인과 `next_tick_switches`는 기준 [Plan]과 견줍니다. +fn finish(h: &mut Host, sc: &dyn Sched, kind: Kind, b: Before, r: Option>) { + let calls: Vec = h.calls[b.calls..].to_vec(); + let n = h.now; + let seen0 = h.seen; + let new = h.plan.domain_at(n); + h.stats.events += 1; + let res: Result<(), String> = (|| { + match kind { + Kind::Start(first) => { + if calls != [Call::Run(first)] { + return Err(format!("start must only run the first task: {calls:?}")); + } + } + Kind::Set => { + if !calls.is_empty() { + return Err(format!("set_table must not touch the environment: {calls:?}")); + } + } + Kind::Yield => match (b.running, calls.as_slice()) { + (None, []) => {} + (Some(_), [Call::Pop(d, None)]) if *d == b.rd => {} + (Some(c), [Call::Pop(d, Some(x)), Call::Push(e, y), Call::Run(z)]) + if *d == b.rd && *e == b.rd && *y == c && z == x => {} + _ => return Err(format!("yield: {calls:?}")), + }, + Kind::Block => { + let r = r.unwrap(); + match calls.as_slice() { + [Call::Pop(d, None)] if *d == b.rd && r == Next::Idle => {} + [Call::Pop(d, Some(x)), Call::Run(y)] if *d == b.rd && x == y && r == Next::Run(*x) => {} + _ => return Err(format!("block of the domain {}: {calls:?} result {r:?}", b.rd.id())), + } + } + Kind::Tick | Kind::Poll => { + let r = r.unwrap(); + if n > seen0 { + h.stats.jumps += u64::from(n > seen0 + 1); + if new != b.rd { + h.stats.boundaries += 1; + h.stats.boundaries_running += u64::from(b.running.is_some()); + h.stats.boundaries_rotated += + u64::from(calls.iter().any(|c| matches!(c, Call::Push(..))) && b.running.is_some()); + } else { + h.stats.same_domain_ticks += 1; + } + if b.running.is_none() && matches!(r, Next::Run(_)) { + h.stats.idle_entries += 1; + } + tick_grammar(&b, &calls, n, new, r)?; + } else if kind == Kind::Tick { + h.stats.repeats += 1; + if !calls.is_empty() { + return Err(format!("a tick event that brings no new tick must do nothing: {calls:?}")); + } + let want = b.running.map_or(Next::Idle, Next::Run); + if r != want { + return Err(format!("result {r:?} of a repeated tick, want {want:?}")); + } + } else { + h.stats.polls_without_tick += 1; + let [Call::Serve(s, m), rest @ ..] = calls.as_slice() else { + return Err(format!("poll without a tick must start with serve: {calls:?}")); + }; + if *s != b.rd || *m != n { + return Err(format!("poll serve({}, {m})", s.id())); + } + match (b.running, rest) { + (Some(c), []) if r == Next::Run(c) => {} + (None, [Call::Pop(d, None)]) if *d == b.rd && r == Next::Idle => {} + (None, [Call::Pop(d, Some(x)), Call::Run(y)]) if *d == b.rd && x == y && r == Next::Run(*x) => {} + _ => return Err(format!("poll without a tick: {rest:?} result {r:?}")), + } + } + } + } + if matches!(kind, Kind::Tick | Kind::Poll) && n > seen0 { + h.seen = n; + } + if kind == Kind::Yield { + h.stats.yields += 1; + } + if kind == Kind::Block { + h.stats.blocks += 1; + } + // I1, I2 + let running = sc.running(h); + let on: Vec = (0..h.tasks.len()).filter(|&t| h.tasks[t].st == St::Running).collect(); + match running { + Some(c) => { + if on != [c] { + return Err(format!("I1: the core runs {c} but the Running tasks are {on:?}")); + } + if h.kcur != Some(c) { + return Err(format!("I1: the core runs {c} but the kernel's current is {:?}", h.kcur)); + } + } + None => { + if !on.is_empty() { + return Err(format!("I2: nothing runs but {on:?} are Running")); + } + } + } + // I3 + let last_run = calls.iter().rev().find_map(|c| if let Call::Run(x) = c { Some(*x) } else { None }); + match last_run { + Some(x) if h.kcur != Some(x) => return Err(format!("I3: current {:?} after run({x})", h.kcur)), + None if h.kcur != b.kcur => { + return Err(format!("I3: current changed from {:?} to {:?} without run", b.kcur, h.kcur)); + } + _ => {} + } + // 도는 도메인과 도메인 변경 예고 + let rd = sc.running_domain(); + let want = h.plan.domain_at(h.seen); + if rd != want { + return Err(format!("running_domain {} but the plan says {} at tick {}", rd.id(), want.id(), h.seen)); + } + if h.now == h.seen && sc.next_tick_switches() != (h.plan.domain_at(h.seen + 1) != rd) { + return Err(format!("next_tick_switches disagrees with the plan after tick {}", h.seen)); + } + if sc.partitioned() { + h.stats.partitioned_events += 1; + } + Ok(()) + })(); + if let Err(e) = res { + h.fail(format!("{kind:?}: {e}")); + } +} + +fn ev_start(h: &mut Host, sc: &mut dyn Sched, first: usize) { + let b = begin(h, sc); + sc.start(h, first); + finish(h, sc, Kind::Start(first), b, None); +} + +fn ev_yield(h: &mut Host, sc: &mut dyn Sched) { + let b = begin(h, sc); + sc.yield_now(h); + finish(h, sc, Kind::Yield, b, None); +} + +fn ev_block(h: &mut Host, sc: &mut dyn Sched) -> Next { + let b = begin(h, sc); + let r = sc.block(h); + finish(h, sc, Kind::Block, b, Some(r)); + r +} + +fn ev_tick(h: &mut Host, sc: &mut dyn Sched) -> Next { + let b = begin(h, sc); + let r = sc.tick(h); + finish(h, sc, Kind::Tick, b, Some(r)); + r +} + +fn ev_poll(h: &mut Host, sc: &mut dyn Sched) -> Next { + let b = begin(h, sc); + let r = sc.poll(h); + finish(h, sc, Kind::Poll, b, Some(r)); + r +} + +/// 표를 정하는 사건입니다. 기준 Plan에도 같이 적습니다. +/// +/// 시스템 콜은 센 틱을 전부 처리한 뒤에만 도므로 이 사건은 처리하지 않은 틱이 +/// 남아 있으면 쓸 수 없습니다. 틱을 먼저 전하는 것은 부르는 쪽의 몫입니다. +fn ev_set(h: &mut Host, sc: &mut dyn Sched, t: Table) { + if h.now != h.seen { + h.fail(format!("set_table with the tick {} outstanding (processed {})", h.now, h.seen)); + } + let b = begin(h, sc); + sc.set_table(t); + h.plan.set(h.seen, t); + finish(h, sc, Kind::Set, b, None); +} + +/// 얼린 옛 스케줄러입니다. crates/k0-sched/src/lib.rs의 이 브랜치(커밋 +/// 6324648)의 `switch_to`, `rotate_as`, `rotate`, `on_tick`, `switch_next`, +/// `block_and_switch`, `resume_from_idle`, `handoff`를 준비 큐와 TCB만 Host로 +/// 바꿔 옮겼고 경위 인자는 그대로입니다. 커널 쪽 연결은 crates/k0-slice/src/tests.rs의 +/// `Wiring::Kernel`과 kernel/src/syscall.rs의 `k0_preempt`(콘솔 깨움과 기한 +/// 처리를 한 뒤 on_tick), `idle_until_ready`(기다림 뒤 깨움과 기한 처리, 그다음 +/// resume_from_idle)를 따랐습니다. 이 사본은 일부러 고치지 않습니다. +struct Legacy { + slice: Slice, + idle_before: u64, +} + +impl Legacy { + fn new() -> Self { + Self { slice: Slice::new(), idle_before: 0 } + } + + fn switch_to(&mut self, h: &mut Host, next: usize, how: Entry) { + self.slice.entered(how); + h.run(next); + } + + fn rotate_as(&mut self, h: &mut Host, how: Entry) -> bool { + let Some(next) = h.pop(Domain::ROOT) else { return false }; + let cur = h.current.unwrap(); + h.push(Domain::ROOT, cur); + self.switch_to(h, next, how); + true + } + + fn on_tick(&mut self, h: &mut Host) { + if self.slice.on_tick() == Verdict::Keep { + return; + } + let _ = self.rotate_as(h, Entry::Tick); + } + + fn switch_next(&mut self, h: &mut Host, how: Entry) -> bool { + let Some(next) = h.pop(Domain::ROOT) else { return false }; + self.switch_to(h, next, how); + true + } + + fn status(h: &Host) -> Next { + h.current.map_or(Next::Idle, Next::Run) + } +} + +impl Sched for Legacy { + fn start(&mut self, h: &mut Host, first: usize) { + self.slice.entered(Entry::Between); + h.run(first); + } + fn yield_now(&mut self, h: &mut Host) { + let _ = self.rotate_as(h, Entry::Between); + } + fn block(&mut self, h: &mut Host) -> Next { + self.idle_before = h.now; + self.switch_next(h, Entry::Between); + Self::status(h) + } + fn tick(&mut self, h: &mut Host) -> Next { + h.serve(Domain::ROOT, h.now); + self.on_tick(h); + Self::status(h) + } + fn poll(&mut self, h: &mut Host) -> Next { + let tick_seen = h.now != self.idle_before; + self.idle_before = h.now; + h.serve(Domain::ROOT, h.now); + let _ = self.switch_next(h, Entry::after_idle(tick_seen)); + Self::status(h) + } + fn set_table(&mut self, _t: Table) {} + fn next_tick_switches(&self) -> bool { + false + } + fn running_domain(&self) -> Domain { + Domain::ROOT + } + fn running(&self, h: &Host) -> Option { + h.current + } + fn partitioned(&self) -> bool { + false + } + fn idempotent_tick(&self) -> bool { + false + } +} + +/// [MutCore]에 한 번에 하나만 넣는 틀린 줄입니다. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Mutant { + None, + YieldAsTick, + BlockAsTick, + PollInputAsTick, + EnterAsBetween, + StartAsTick, + RotateAsBetween, + BoundaryKeepToBack, + BoundaryRotateToBack, + ServeOldAtBoundary, + PopOldDomain, + EffectNextTick, + NoRuleAtBoundary, + NoEnterDomain, + SlackDonation, + PollIgnoresTick, + SwitchesNeverTrue, + SecondSetIgnored, + CatchUpOneByOne, + ServeBeforeEnter, + ServeOldInstead, + ReplaceStartsNextTick, + SpuriousAsTick, + BlockKeepsRunning, + StartsInThree, + SwitchesIgnoresPending, +} + +const ALL_MUTANTS: [Mutant; 25] = [ + Mutant::YieldAsTick, + Mutant::BlockAsTick, + Mutant::PollInputAsTick, + Mutant::EnterAsBetween, + Mutant::StartAsTick, + Mutant::RotateAsBetween, + Mutant::BoundaryKeepToBack, + Mutant::BoundaryRotateToBack, + Mutant::ServeOldAtBoundary, + Mutant::PopOldDomain, + Mutant::EffectNextTick, + Mutant::NoRuleAtBoundary, + Mutant::NoEnterDomain, + Mutant::SlackDonation, + Mutant::PollIgnoresTick, + Mutant::SwitchesNeverTrue, + Mutant::SecondSetIgnored, + Mutant::CatchUpOneByOne, + Mutant::ServeBeforeEnter, + Mutant::ServeOldInstead, + Mutant::ReplaceStartsNextTick, + Mutant::SpuriousAsTick, + Mutant::BlockKeepsRunning, + Mutant::StartsInThree, + Mutant::SwitchesIgnoresPending, +]; + +/// lib.rs의 Core를 옮겨 적고 `m`이 가리키는 줄 하나만 틀리게 한 사본입니다. +struct MutCore { + m: Mutant, + table: Table, + epoch: u64, + pending: Option<(Table, u64)>, + seen: u64, + rd: Domain, + running: Option, + slice: Slice, +} + +impl MutCore { + fn new(m: Mutant) -> Self { + Self { + m, + table: Table::DEFAULT, + epoch: 0, + pending: None, + seen: 0, + rd: Domain::ROOT, + running: None, + slice: Slice::new(), + } + } + + fn plan_at(&self, k: u64) -> Domain { + if let Some((t, s)) = &self.pending + && k >= *s + { + return t.domain_at(k - *s); + } + self.table.domain_at(k.saturating_sub(self.epoch)) + } + + fn advance(&mut self, n: u64) { + if let Some((t, s)) = self.pending + && s <= n + { + self.table = t; + self.epoch = s; + self.pending = None; + } + } + + fn status(&self) -> Next { + self.running.map_or(Next::Idle, Next::Run) + } + + fn switch(&mut self, h: &mut Host, x: usize, how: Entry) { + self.slice.entered(how); + self.running = Some(x); + h.run(x); + } + + fn enter(&mut self, h: &mut Host, d: Domain) -> Next { + let how = if self.m == Mutant::EnterAsBetween { Entry::Between } else { Entry::Tick }; + let mut got = h.pop(d); + if got.is_none() && self.m == Mutant::SlackDonation { + for i in 0..MAX_DOMAINS { + if got.is_none() { + got = h.pop(Domain::new(i as u8).unwrap()); + } + } + } + match got { + Some(x) => { + self.switch(h, x, how); + Next::Run(x) + } + None => Next::Idle, + } + } +} + +impl Sched for MutCore { + fn start(&mut self, h: &mut Host, first: usize) { + let m = self.m; + *self = MutCore::new(m); + self.seen = h.now; + self.epoch = self.seen; + let how = if m == Mutant::StartAsTick { Entry::Tick } else { Entry::Between }; + self.switch(h, first, how); + } + + fn yield_now(&mut self, h: &mut Host) { + let Some(c) = self.running else { return }; + if let Some(x) = h.pop(self.rd) { + h.push(self.rd, c); + let how = if self.m == Mutant::YieldAsTick { Entry::Tick } else { Entry::Between }; + self.switch(h, x, how); + } + } + + fn block(&mut self, h: &mut Host) -> Next { + if self.m != Mutant::BlockKeepsRunning { + self.running = None; + } + match h.pop(self.rd) { + Some(x) => { + let how = if self.m == Mutant::BlockAsTick { Entry::Tick } else { Entry::Between }; + self.switch(h, x, how); + Next::Run(x) + } + None => Next::Idle, + } + } + + fn tick(&mut self, h: &mut Host) -> Next { + let n = h.now; + if n <= self.seen && self.m != Mutant::SpuriousAsTick { + return self.status(); + } + self.advance(n); + let old = self.rd; + let new = if self.m == Mutant::CatchUpOneByOne { + self.table.domain_at(self.seen + 1 - self.epoch.min(self.seen + 1)) + } else { + self.table.domain_at(n - self.epoch) + }; + self.seen = n; + if new == old { + h.serve(old, n); + return match self.running { + Some(c) => match self.slice.on_tick() { + Verdict::Keep => Next::Run(c), + Verdict::Rotate => match h.pop(old) { + Some(x) => { + h.push(old, c); + let how = + if self.m == Mutant::RotateAsBetween { Entry::Between } else { Entry::Tick }; + self.switch(h, x, how); + Next::Run(x) + } + None => Next::Run(c), + }, + }, + None => self.enter(h, old), + }; + } + if let Some(c) = self.running.take() { + let verdict = if self.m == Mutant::NoRuleAtBoundary { Verdict::Keep } else { self.slice.on_tick() }; + match verdict { + Verdict::Keep => { + if self.m == Mutant::BoundaryKeepToBack { + h.push(old, c) + } else { + h.push_front(old, c) + } + } + Verdict::Rotate => match h.pop(old) { + Some(x) => { + h.push(old, c); + if self.m == Mutant::BoundaryRotateToBack { + h.push(old, x) + } else { + h.push_front(old, x) + } + } + None => h.push_front(old, c), + }, + } + } + self.rd = new; + match self.m { + Mutant::NoEnterDomain => h.serve(new, n), + Mutant::ServeBeforeEnter => { + h.serve(new, n); + h.enter_domain(new); + } + Mutant::ServeOldInstead => { + h.enter_domain(new); + h.serve(old, n); + } + _ => { + h.enter_domain(new); + h.serve(new, n); + } + } + if self.m == Mutant::ServeOldAtBoundary { + h.serve(old, n); + } + if self.m == Mutant::PopOldDomain { self.enter(h, old) } else { self.enter(h, new) } + } + + fn poll(&mut self, h: &mut Host) -> Next { + let n = h.now; + if n > self.seen && self.m != Mutant::PollIgnoresTick { + return self.tick(h); + } + h.serve(self.rd, n); + if self.running.is_some() { + return self.status(); + } + match h.pop(self.rd) { + Some(x) => { + let how = if self.m == Mutant::PollInputAsTick { Entry::Tick } else { Entry::Between }; + self.switch(h, x, how); + Next::Run(x) + } + None => Next::Idle, + } + } + + fn set_table(&mut self, t: Table) { + if self.m == Mutant::SecondSetIgnored && self.pending.is_some() { + return; + } + let replacing = self.pending.is_some(); + let now = self.seen; + let at = match self.m { + Mutant::EffectNextTick => now + 1, + Mutant::ReplaceStartsNextTick if replacing => now + 1, + Mutant::StartsInThree => now + 3, + _ => now + 2, + }; + self.pending = Some((t, at)); + } + + fn next_tick_switches(&self) -> bool { + if self.m == Mutant::SwitchesNeverTrue { + return false; + } + if self.m == Mutant::SwitchesIgnoresPending { + return self.table.domain_at((self.seen + 1).saturating_sub(self.epoch)) != self.rd; + } + self.plan_at(self.seen + 1) != self.rd + } + + fn running_domain(&self) -> Domain { + self.rd + } + + fn running(&self, _: &Host) -> Option { + self.running + } + + fn partitioned(&self) -> bool { + !self.table.is_default() || self.pending.is_some_and(|(t, _)| !t.is_default()) + } +} + +struct Rng(u64); + +impl Rng { + fn new(seed: u64) -> Self { + Rng(seed.wrapping_mul(0x9E37_79B9_7F4A_7C15) | 1) + } + + fn next(&mut self) -> u64 { + self.0 ^= self.0 << 13; + self.0 ^= self.0 >> 7; + self.0 ^= self.0 << 17; + self.0 + } + + fn below(&mut self, n: u64) -> u64 { + self.next() % n + } +} + +/// 한 번의 시뮬레이션이 받는 입력입니다. +#[derive(Clone, Debug)] +struct World { + specs: Vec, + changes: Vec<(u64, Table)>, + jumps: Vec<(u64, u64)>, + horizon: u64, +} + +/// 세계를 `sc`로 돌리고 Host를 돌려주는 함수입니다. +/// +/// 틱 번호 t에서 틱 사건을 처리하고 표 변경을 적용한 뒤 칸마다 한 연산씩 +/// 돕니다. `jumps`의 (at, extra)는 틱 at 다음에 extra개의 틱이 사건 없이 +/// 건너뛰어지는 것(커널이 오래 멈춘 경우)입니다. +fn simulate(w: &World, sc: &mut dyn Sched) -> Host { + let mut h = Host::new(&w.specs); + for t in 1..w.specs.len() { + let d = h.dom(t); + h.push(d, t); + } + ev_start(&mut h, sc, 0); + let mut changes = w.changes.iter().peekable(); + while let Some(&&(at, tbl)) = changes.peek() { + if at > 0 { + break; + } + ev_set(&mut h, sc, tbl); + changes.next(); + } + let mut arrivals: Vec<(u64, u8, usize)> = Vec::new(); + for (t, task) in w.specs.iter().enumerate() { + for &(k, s) in &task.inputs { + arrivals.push((k, s, t)); + } + } + arrivals.sort(); + let mut next_arrival = 0; + let mut t = 1; + while t <= w.horizon && h.bad.is_none() { + h.now = t; + h.step = 0; + let r = if h.current.is_some() { ev_tick(&mut h, sc) } else { ev_poll(&mut h, sc) }; + h.check_next(r); + let want = h.plan.domain_at(t); + if sc.running_domain() != want { + h.fail(format!("running_domain {} but the plan says {}", sc.running_domain().id(), want.id())); + } + // 비교값보다 이른 인터럽트(Spurious)는 커널이 사건으로 올리지 않지만, 같은 번호로 + // 다시 불려도 Core는 아무 일도 하지 않아야 한다 + if sc.idempotent_tick() && t % 2 == 0 && h.bad.is_none() { + let again = ev_tick(&mut h, sc); + h.check_next(again); + } + while let Some(&&(at, tbl)) = changes.peek() { + if at > t { + break; + } + ev_set(&mut h, sc, tbl); + changes.next(); + } + if sc.next_tick_switches() != (h.plan.domain_at(t + 1) != want) { + h.fail("next_tick_switches disagrees with the plan".into()); + } + for step in 0..STEPS { + h.step = step; + while next_arrival < arrivals.len() && (arrivals[next_arrival].0, arrivals[next_arrival].1) <= (t, step) + { + let task = arrivals[next_arrival].2; + next_arrival += 1; + h.tasks[task].input += 1; + // 입력 인터럽트: 도는 도메인의 읽는 태스크만 바로 깨움 + if h.tasks[task].st == St::Reading && h.dom(task) == sc.running_domain() { + h.tasks[task].input -= 1; + h.wake(task, Why::Input); + } + if h.current.is_none() { + let r = ev_poll(&mut h, sc); + h.check_next(r); + } + } + match h.current { + Some(c) => exec(&mut h, sc, c), + None => { + let d = h.plan.domain_at(t); + if !h.q[d.index()].is_empty() { + h.fail(format!("idle although domain {} has a ready task", d.id())); + } + } + } + if h.bad.is_some() { + break; + } + } + t += 1 + w.jumps.iter().find(|j| j.0 == t).map_or(0, |j| j.1); + } + h +} + +fn exec(h: &mut Host, sc: &mut dyn Sched, t: usize) { + let want = h.plan.domain_at(h.now); + if h.dom(t) != want { + h.fail(format!("task {t} of domain {} executes in a window of domain {}", h.dom(t).id(), want.id())); + return; + } + let len = h.tasks[t].spec.prog.len(); + let op = h.tasks[t].spec.prog[h.tasks[t].pc]; + h.tasks[t].pc = (h.tasks[t].pc + 1) % len; + h.record(t, Ev::Ran { tick: h.now, step: h.step, task: t }); + let leave = |h: &mut Host, sc: &mut dyn Sched, st: St| { + h.tasks[t].st = st; + h.current = None; + let r = ev_block(h, sc); + h.check_next(r); + }; + match op { + Op::Spin => {} + Op::Yield => ev_yield(h, sc), + Op::Wait(n) => leave(h, sc, St::Timed(h.now + n)), + Op::Pend(o) => { + if h.sems[o] > 0 { + h.sems[o] -= 1; + } else { + h.waiters[o].push_back(t); + leave(h, sc, St::Pending(o)); + } + } + Op::Post(o) => match h.waiters[o].pop_front() { + Some(w) => h.wake(w, Why::Post), + None => h.sems[o] += 1, + }, + Op::Read => { + if h.tasks[t].input > 0 { + h.tasks[t].input -= 1; + } else { + leave(h, sc, St::Reading); + } + } + Op::Exit => leave(h, sc, St::Dead), + } +} + +fn trace_of(h: &Host, d: u8) -> Vec { + h.trace.iter().filter(|(x, _)| x.id() == d).map(|(_, e)| *e).collect() +} + +fn rand_op(r: &mut Rng, dom: u8) -> Op { + let obj = dom as usize * 2 + r.below(2) as usize; + match r.below(18) { + 0..=2 => Op::Spin, + 3..=6 => Op::Yield, + 7..=9 => Op::Wait(1 + r.below(3)), + 10..=11 => Op::Read, + 12 => Op::Exit, + 13 => Op::Pend(obj), + _ => Op::Post(obj), + } +} + +fn rand_spec(r: &mut Rng, dom: u8, horizon: u64) -> Spec { + let prog: Vec = (0..1 + r.below(4)).map(|_| rand_op(r, dom)).collect(); + let mut inputs = Vec::new(); + if prog.contains(&Op::Read) { + for _ in 0..r.below(5) { + inputs.push((1 + r.below(horizon), r.below(STEPS as u64) as u8)); + } + } + Spec { domain: dom, prog, inputs } +} + +fn rand_table(r: &mut Rng, ndom: u64, must: u8) -> Table { + let n = 1 + r.below(5) as usize; + let mut e: Vec<(Domain, u32)> = (0..n) + .map(|_| (Domain::new(r.below(ndom) as u8).unwrap(), 1 + r.below(3) as u32)) + .collect(); + if !e.iter().any(|x| x.0.id() == must) { + let i = r.below(n as u64) as usize; + e[i].0 = Domain::new(must).unwrap(); + } + Table::from_entries(&e).unwrap() +} + +fn rand_changes(r: &mut Rng, ndom: u64, must: u8, horizon: u64) -> Vec<(u64, Table)> { + let mut v: Vec<(u64, Table)> = (0..r.below(4)) + .map(|_| (r.below(horizon.saturating_sub(3)), rand_table(r, ndom, must))) + .collect(); + v.sort_by_key(|x| x.0); + v +} + +fn rand_jumps(r: &mut Rng, horizon: u64) -> Vec<(u64, u64)> { + (0..r.below(3)).map(|_| (1 + r.below(horizon), 1 + r.below(4))).collect() +} + +/// 모든 도메인이 무작위인 세계입니다. 0번 태스크는 도메인 0입니다. +fn random_world(seed: u64, horizon: u64) -> World { + let mut r = Rng::new(seed); + let ndom = 1 + r.below(8); + let n = 2 + r.below(6); + let mut specs = vec![rand_spec(&mut r, 0, horizon)]; + for _ in 1..n { + let d = r.below(ndom) as u8; + specs.push(rand_spec(&mut r, d, horizon)); + } + let changes = rand_changes(&mut r, ndom, 0, horizon); + let jumps = if r.below(2) == 0 { rand_jumps(&mut r, horizon) } else { Vec::new() }; + World { specs, changes, jumps, horizon } +} + +/// 같은 표와 같은 시간 흐름을 쓰고 도메인 `d`의 태스크는 같으며 나머지만 다른 +/// 세계 한 쌍입니다. `shared`가 true면 다른 도메인의 태스크가 `d`의 오브젝트에 +/// 신호를 보냄(명시적 공유 채널)으로써 흔적이 갈리는 경우를 만듭니다. +fn two_worlds(seed: u64, d: u8, horizon: u64) -> (World, World) { + let mut r = Rng::new(seed); + let ndom = 3; + let mine: Vec = (0..1 + r.below(3)).map(|_| rand_spec(&mut r, d, horizon)).collect(); + let changes = rand_changes(&mut r, ndom, d, horizon); + let jumps = if r.below(2) == 0 { rand_jumps(&mut r, horizon) } else { Vec::new() }; + let build = |s: u64| { + let mut o = Rng::new(s ^ 0xABCD_1234); + let mut specs = Vec::new(); + if d != 0 { + specs.push(rand_spec(&mut o, 0, horizon)); + } + specs.extend(mine.iter().cloned()); + for _ in 0..o.below(5) { + let mut x = o.below(ndom) as u8; + if x == d { + x = (x + 1) % ndom as u8; + } + specs.push(rand_spec(&mut o, x, horizon)); + } + World { specs, changes: changes.clone(), jumps: jumps.clone(), horizon } + }; + (build(seed.wrapping_add(1)), build(seed.wrapping_add(2))) +} + +type Mk<'a> = &'a dyn Fn() -> Box; + +fn real() -> Box { + Box::new(Core::::new()) +} + +fn mutant(m: Mutant) -> Box { + Box::new(MutCore::new(m)) +} + +fn check(h: &Host, what: &str) -> Result<(), String> { + match &h.bad { + Some(b) => Err(format!("{what}: {b}")), + None => Ok(()), + } +} + +/// 시험 규모입니다. 깨뜨리기 시험은 같은 속성을 더 작게 돌립니다. +#[derive(Clone, Copy)] +struct Scale { + random: u64, + exhaustive: bool, +} + +const FULL: Scale = Scale { random: 4000, exhaustive: true }; +const QUICK: Scale = Scale { random: 400, exhaustive: false }; + +/// 모든 표(항목 1~2개, 도메인 0~1, 창 1~2틱)입니다. +fn small_tables() -> Vec { + let one: Vec<(Domain, u32)> = (0..2) + .flat_map(|d| (1..=2).map(move |w| (Domain::new(d).unwrap(), w))) + .collect(); + let mut v = Vec::new(); + for a in &one { + v.push(Table::from_entries(&[*a]).unwrap()); + for b in &one { + v.push(Table::from_entries(&[*a, *b]).unwrap()); + } + } + v +} + +/// 길이 2 이하의 모든 프로그램입니다. +fn small_progs() -> Vec> { + let ops = [Op::Spin, Op::Yield, Op::Wait(1), Op::Exit]; + let mut v: Vec> = ops.iter().map(|&a| vec![a]).collect(); + for &a in &ops { + for &b in &ops { + v.push(vec![a, b]); + } + } + v +} + +fn spec(domain: u8, prog: Vec) -> Spec { + Spec { domain, prog, inputs: Vec::new() } +} + +/// 속성 2: 창이 정확하고 남는 시간을 양도하지 않습니다. +fn p_window_exact(mk: Mk, sc: Scale) -> Result<(), String> { + for seed in 0..sc.random { + let w = random_world(seed, 40); + let h = simulate(&w, &mut *mk()); + check(&h, &format!("random world {seed}"))?; + } + if sc.exhaustive { + let progs = small_progs(); + for tbl in small_tables() { + for a in &progs { + for b in &progs { + let w = World { + specs: vec![spec(0, a.clone()), spec(0, vec![Op::Spin]), spec(1, b.clone())], + changes: vec![(0, tbl)], + jumps: Vec::new(), + horizon: 10, + }; + let h = simulate(&w, &mut *mk()); + check(&h, &format!("exhaustive {:?} {:?} {:?}", tbl, a, b))?; + } + } + } + } + Ok(()) +} + +/// 속성 1: 한 도메인의 흔적은 다른 도메인이 무엇을 하든 같습니다. 두 세계의 +/// 다른 도메인 흔적이 실제로 갈렸는지(속성이 비어 있지 않은지)도 세어 돌려줍니다. +fn p_two_run(mk: Mk, sc: Scale) -> Result { + let mut differing = 0; + for seed in 0..sc.random { + let d = (seed % 3) as u8; + let (a, b) = two_worlds(seed, d, 40); + let (ha, hb) = (simulate(&a, &mut *mk()), simulate(&b, &mut *mk())); + check(&ha, &format!("world A seed {seed}"))?; + check(&hb, &format!("world B seed {seed}"))?; + if trace_of(&ha, d) != trace_of(&hb, d) { + return Err(format!("domain {d} trace differs, seed {seed}")); + } + if (0..3).filter(|&x| x != d).any(|x| trace_of(&ha, x) != trace_of(&hb, x)) { + differing += 1; + } + } + if sc.exhaustive { + let progs = small_progs(); + for tbl in small_tables() { + if !tbl.contains(Domain::new(1).unwrap()) { + continue; + } + for mine in &progs { + let mut base: Option> = None; + for a in &progs { + for b in &progs { + let w = World { + specs: vec![spec(0, a.clone()), spec(1, mine.clone()), spec(0, b.clone())], + changes: vec![(0, tbl)], + jumps: Vec::new(), + horizon: 10, + }; + let h = simulate(&w, &mut *mk()); + check(&h, &format!("exhaustive two-run {:?} {:?}", tbl, mine))?; + let tr = trace_of(&h, 1); + match &base { + None => base = Some(tr), + Some(x) if *x != tr => { + return Err(format!("exhaustive: domain 1 trace differs, {:?} {:?} {:?} {:?}", tbl, mine, a, b)); + } + _ => {} + } + } + } + } + } + } + Ok(differing) +} + +/// 속성 3: 기본 표(와 루트만 든 표)에서 Core의 결정은 얼린 옛 스케줄러와 같습니다. +fn p_default_equal(mk: Mk, sc: Scale) -> Result<(), String> { + let all_root = |v: &[(u32,)]| { + Table::from_entries(&v.iter().map(|x| (Domain::ROOT, x.0)).collect::>()).unwrap() + }; + let tables = [Table::DEFAULT, all_root(&[(3,)]), all_root(&[(1,), (2,)])]; + let run = |w: &World| -> Result<(), String> { + let (mut a, mut b) = (mk(), Legacy::new()); + let (ha, hb) = (simulate(w, &mut *a), simulate(w, &mut b)); + check(&ha, "core")?; + check(&hb, "legacy")?; + if ha.runs != hb.runs || ha.trace != hb.trace || ha.calls != hb.calls { + return Err(format!("decisions differ from the frozen scheduler: {:?}", w.specs)); + } + Ok(()) + }; + for seed in 0..sc.random { + let mut w = random_world(seed ^ 0x5555, 40); + for s in &mut w.specs { + s.domain = 0; + } + let mut r = Rng::new(seed); + w.changes = (0..r.below(3)) + .map(|_| (r.below(30), tables[r.below(3) as usize])) + .collect(); + w.changes.sort_by_key(|x| x.0); + run(&w)?; + } + if sc.exhaustive { + let progs = small_progs(); + for a in &progs { + for b in &progs { + for c in &progs { + let w = World { + specs: vec![spec(0, a.clone()), spec(0, b.clone()), spec(0, c.clone())], + changes: Vec::new(), + jumps: Vec::new(), + horizon: 10, + }; + run(&w)?; + } + } + } + } + Ok(()) +} + +/// 속성 4: 도메인 안에서 계속 도는 태스크의 몫은 도메인의 창 시간을 기준으로 +/// 1/N 아래로 한계 이상 내려가지 않습니다. +/// +/// 한계는 k0-slice의 한계 "(N-1)주기 + 한 주기"를 틱 단위로 옮긴 N틱입니다. +/// 도메인 안의 흐름은 창에 속한 틱만 이어 붙인 시간 위에서 k0-slice와 같다고 +/// 보고 한계를 그대로 가져왔으며, 증명이 아니라 시험의 기준입니다. +fn share_lag(n: u64) -> u64 { + n * STEPS as u64 +} + +fn share_world(seed: u64) -> (World, usize, u8, u64) { + let mut r = Rng::new(seed); + let d = r.below(2) as u8; + let n = 2 + r.below(3); + let mut specs: Vec = Vec::new(); + if d == 1 { + specs.push(rand_spec(&mut r, 0, 40)); + } + let first = specs.len(); + let spinner = first + r.below(n) as usize; + for i in 0..n as usize { + let mut s = rand_spec(&mut r, d, 40); + if first + i == spinner { + s.prog = vec![Op::Spin]; + s.inputs.clear(); + } + specs.push(s); + } + for _ in 0..r.below(3) { + specs.push(rand_spec(&mut r, 1 - d, 40)); + } + let changes = vec![(r.below(4), rand_table(&mut r, 2, d))]; + let jumps = if r.below(3) == 0 { rand_jumps(&mut r, 40) } else { Vec::new() }; + (World { specs, changes, jumps, horizon: 60 }, spinner, d, n) +} + +/// `share_world`를 돌리며 매 칸마다 몫을 보고 가장 크게 뒤처진 값을 돌려줍니다. +fn worst_lag(mk: Mk, w: &World, spinner: usize, d: u8, n: u64) -> Result { + let mut sc = mk(); + // 칸마다 다시 돌리지 않고 흔적에서 계산 + let h = simulate(w, &mut *sc); + check(&h, "share")?; + let mut window_steps = 0u64; + let mut mine = 0u64; + let mut worst = i64::MIN; + let mut ran: std::collections::BTreeMap<(u64, u8), usize> = std::collections::BTreeMap::new(); + for (_, ev) in &h.trace { + if let Ev::Ran { tick, step, task } = ev { + ran.insert((*tick, *step), *task); + } + } + let plan = &h.plan; + let mut t = 1; + while t <= w.horizon { + if plan.domain_at(t).id() == d { + for s in 0..STEPS { + window_steps += 1; + if ran.get(&(t, s)) == Some(&spinner) { + mine += 1; + } + worst = worst.max(window_steps as i64 - (mine * n) as i64); + } + } + t += 1 + w.jumps.iter().find(|j| j.0 == t).map_or(0, |j| j.1); + } + Ok(worst) +} + +fn p_share(mk: Mk, sc: Scale) -> Result<(), String> { + for seed in 0..sc.random { + let (w, spinner, d, n) = share_world(seed); + let worst = worst_lag(mk, &w, spinner, d, n)?; + if worst > share_lag(n) as i64 { + return Err(format!("share bound broken, seed {seed}: lag {worst} > {}", share_lag(n))); + } + } + if sc.exhaustive { + let progs = small_progs(); + for tbl in small_tables() { + if !tbl.contains(Domain::ROOT) { + continue; + } + for a in &progs { + for b in &progs { + let w = World { + specs: vec![spec(0, vec![Op::Spin]), spec(0, a.clone()), spec(0, b.clone()), spec(1, vec![Op::Spin])], + changes: vec![(0, tbl)], + jumps: Vec::new(), + horizon: 14, + }; + let worst = worst_lag(mk, &w, 0, 0, 3)?; + if worst > share_lag(3) as i64 { + return Err(format!("exhaustive share bound broken: {:?} {:?} {:?} lag {worst}", tbl, a, b)); + } + } + } + } + } + Ok(()) +} + +/// 틱마다 어느 태스크가 도는지 모은 것입니다(모든 도메인). +fn ran_by_tick(h: &Host) -> Vec<(u64, Vec)> { + let mut v: Vec<(u64, Vec)> = Vec::new(); + for (_, ev) in &h.trace { + if let Ev::Ran { tick, task, .. } = ev { + match v.last_mut() { + Some((t, l)) if t == tick => l.push(*task), + _ => v.push((*tick, vec![*task])), + } + } + } + v +} + +fn scenario(specs: Vec, table: Option
, horizon: u64, sc: &mut dyn Sched) -> Host { + let w = World { + specs, + changes: table.map(|t| vec![(0, t)]).unwrap_or_default(), + jumps: Vec::new(), + horizon, + }; + simulate(&w, sc) +} + +fn tbl(e: &[(u8, u32)]) -> Table { + Table::from_entries(&e.iter().map(|&(d, w)| (Domain::new(d).unwrap(), w)).collect::>()).unwrap() +} + +/// 속성 6: 경계에서의 틱 규칙입니다. +fn p_tick_rule(mk: Mk) -> Result<(), String> { + let flat = |v: &[(u64, &[usize])]| -> Vec<(u64, Vec)> { v.iter().map(|&(t, l)| (t, l.to_vec())).collect() }; + let same = |got: Vec<(u64, Vec)>, want: Vec<(u64, Vec)>, what: &str| { + if got == want { Ok(()) } else { Err(format!("{what}: got {got:?}, want {want:?}")) } + }; + // 경계에서 세워 둔 태스크는 자기 도메인의 다음 창에서 맨 앞이고, 한 틱짜리 + // 창은 스피너 둘 사이를 돌린다. 표는 틱 2부터 [(0,1),(1,1)] + let two = vec![spec(0, vec![Op::Spin]), spec(0, vec![Op::Spin]), spec(1, vec![Op::Spin])]; + let h = scenario(two, Some(tbl(&[(0, 1), (1, 1)])), 9, &mut *mk()); + check(&h, "rotation")?; + same( + ran_by_tick(&h), + flat(&[ + (1, &[0, 0, 0]), + (2, &[1, 1, 1]), + (3, &[2, 2, 2]), + (4, &[0, 0, 0]), + (5, &[2, 2, 2]), + (6, &[1, 1, 1]), + (7, &[2, 2, 2]), + (8, &[0, 0, 0]), + (9, &[2, 2, 2]), + ]), + "one-tick windows rotate between two spinners", + )?; + // 틱과 틱 사이에 들어온 태스크는 경계의 틱에서 끊기지 않고 다음 창에서도 + // 맨 앞이다. 0번이 양보해서 1번이 틱 1 직후가 아니라 칸 0에 들어옴 + let between = vec![spec(0, vec![Op::Yield, Op::Spin]), spec(0, vec![Op::Spin]), spec(1, vec![Op::Spin])]; + let h = scenario(between, Some(tbl(&[(1, 1), (0, 1)])), 6, &mut *mk()); + check(&h, "between")?; + same( + ran_by_tick(&h), + flat(&[ + (1, &[0, 1, 1]), + (2, &[2, 2, 2]), + (3, &[1, 1, 1]), + (4, &[2, 2, 2]), + (5, &[0, 0, 1]), + (6, &[2, 2, 2]), + ]), + "a task that entered between ticks is not cut at the boundary", + )?; + // 기본 표: 양보로 들어온 태스크는 처음 맞는 틱을 넘기고 그다음 틱에서 끊긴다 + let dflt = vec![spec(0, vec![Op::Yield, Op::Spin]), spec(0, vec![Op::Spin])]; + let h = scenario(dflt, None, 4, &mut *mk()); + check(&h, "default")?; + same( + ran_by_tick(&h), + flat(&[(1, &[0, 1, 1]), (2, &[1, 1, 1]), (3, &[0, 0, 1]), (4, &[1, 1, 1])]), + "default table keeps the first tick of a task that entered between ticks", + )?; + // 한 틱짜리 기본 표에서 스피너 둘은 틱마다 번갈아 돈다(틱 1은 시작 면제) + let spin2 = vec![spec(0, vec![Op::Spin]), spec(0, vec![Op::Spin])]; + let h = scenario(spin2, None, 6, &mut *mk()); + check(&h, "spin2")?; + same( + ran_by_tick(&h), + flat(&[ + (1, &[0, 0, 0]), + (2, &[1, 1, 1]), + (3, &[0, 0, 0]), + (4, &[1, 1, 1]), + (5, &[0, 0, 0]), + (6, &[1, 1, 1]), + ]), + "default table alternates two spinners", + )?; + // 비어 있는 도메인으로 경계가 오면 CPU는 놀고 남는 시간은 양도되지 않는다 + let donate = vec![spec(0, vec![Op::Spin]), spec(1, vec![Op::Wait(1), Op::Spin])]; + let h = scenario(donate, Some(tbl(&[(1, 1), (0, 1)])), 6, &mut *mk()); + check(&h, "idle window")?; + Ok(()) +} + +/// 속성 5: 표를 틱 n에 정하면 n + 2의 0번 항목부터 효력이 생기고, 새 설정이 앞의 +/// 보류 표를 밀어내며, 틱이 건너뛰어져도 맞는 항목에 닿고, 도메인 변경 예고가 맞습니다. +fn p_table(mk: Mk, sc: Scale) -> Result<(), String> { + let dom = |sc: &dyn Sched| sc.running_domain().id(); + let mut h = Host::new(&[]); + let mut s = mk(); + // 틱 5에 [(1,2),(0,1)]을 정함: 틱 6은 그대로, 7부터 1,1,0,1,1,0 + for t in 1..=5 { + h.now = t; + s.tick(&mut h); + } + s.set_table(tbl(&[(1, 2), (0, 1)])); + let mut got = Vec::new(); + for t in 6..=12 { + h.now = t; + s.tick(&mut h); + got.push(dom(&*s)); + } + if got != [0, 1, 1, 0, 1, 1, 0] { + return Err(format!("table set at 5: domains of ticks 6..=12 are {got:?}")); + } + // 보류 중에 다시 정하면 앞의 표는 효력이 생기지 않는다 + let mut h = Host::new(&[]); + let mut s = mk(); + for t in 1..=5 { + h.now = t; + s.tick(&mut h); + } + s.set_table(tbl(&[(1, 1)])); + h.now = 6; + s.tick(&mut h); + s.set_table(tbl(&[(2, 1)])); + let mut got = Vec::new(); + for t in 7..=9 { + h.now = t; + s.tick(&mut h); + got.push(dom(&*s)); + } + if got != [0, 2, 2] { + return Err(format!("second set must replace the first: {got:?}")); + } + // 효력이 생긴 시점(틱 7)에 다시 정하면 앞의 표는 그 시점부터 자리를 지킨다 + let mut h = Host::new(&[]); + let mut s = mk(); + for t in 1..=5 { + h.now = t; + s.tick(&mut h); + } + s.set_table(tbl(&[(1, 1)])); + let mut got = Vec::new(); + for t in 6..=9 { + h.now = t; + s.tick(&mut h); + if t == 7 { + s.set_table(tbl(&[(2, 1)])); + } + got.push(dom(&*s)); + } + if got != [0, 1, 1, 2] { + return Err(format!("a set at the tick the first one starts: {got:?}")); + } + // 건너뜀: [(0,2),(1,3),(2,1)]은 틱 2부터 한 바퀴 6틱. 3에서 8로 뛰면 0번 항목 + let mut h = Host::new(&[]); + let mut s = mk(); + s.set_table(tbl(&[(0, 2), (1, 3), (2, 1)])); + for (t, want) in [(1u64, 0u8), (3, 0), (8, 0), (11, 1), (13, 2), (14, 0), (20, 0), (22, 1)] { + h.now = t; + s.tick(&mut h); + if dom(&*s) != want { + return Err(format!("jump to tick {t}: domain {} want {want}", dom(&*s))); + } + } + // 무작위: 설정, 건너뜀, 예고를 기준(Plan)과 견줌 + for seed in 0..sc.random { + let mut r = Rng::new(seed ^ 0x77); + let mut h = Host::new(&[]); + let mut s = mk(); + let mut t = 0; + for _ in 0..30 { + t += 1 + if r.below(5) == 0 { r.below(6) } else { 0 }; + h.now = t; + s.tick(&mut h); + let want = h.plan.domain_at(t); + if s.running_domain() != want { + return Err(format!("seed {seed} tick {t}: domain {} want {}", s.running_domain().id(), want.id())); + } + if r.below(3) == 0 { + let tb = rand_table(&mut r, 4, 0); + s.set_table(tb); + h.plan.set(t, tb); + } + if s.next_tick_switches() != (h.plan.domain_at(t + 1) != want) { + return Err(format!("seed {seed} tick {t}: next_tick_switches is wrong")); + } + } + } + Ok(()) +} + +fn replace_specs() -> Vec { + vec![ + spec(0, vec![Op::Spin]), + spec(0, vec![Op::Yield, Op::Spin]), + spec(1, vec![Op::Spin]), + spec(1, vec![Op::Wait(1), Op::Spin]), + ] +} + +/// 태스크가 든 Host를 만들고 0번을 시작시킵니다. 나머지는 자기 도메인 큐에 순서대로 섭니다. +fn script_host(specs: Vec, sc: &mut dyn Sched) -> Host { + let mut h = Host::new(&specs); + for t in 1..specs.len() { + let d = h.dom(t); + h.push(d, t); + } + h.calls.clear(); + ev_start(&mut h, sc, 0); + h +} + +/// 틱 `t`가 오고 커널이 그것을 처리하는 한 걸음입니다(도는 태스크가 없으면 poll). +fn step_to(h: &mut Host, sc: &mut dyn Sched, t: u64) { + h.now = t; + let r = if h.current.is_some() { ev_tick(h, sc) } else { ev_poll(h, sc) }; + h.check_next(r); +} + +/// 속성 7: 보류 중인 표를 갈아 끼웁니다. 효력이 생기기 전에 다시 정하면 앞의 표는 +/// 버려지고 새 표가 정한 틱 + 2에서 시작하며, 앞 표의 시작 틱이 지난 뒤에 다시 정하면 +/// 앞 표는 그 틱을 처리할 때 이미 올라가 있습니다. 사건마다 `next_tick_switches`를 +/// 기준 Plan과 견주는 일은 [finish]가 합니다. +fn p_replace(mk: Mk, sc: Scale) -> Result<(), String> { + let all = small_tables(); + let tables: Vec
= all.iter().copied().step_by(if sc.exhaustive { 1 } else { 3 }).collect(); + for &a in &tables { + for &b in &tables { + for s1 in 0..4u64 { + for gap in 0..=3u64 { + let w = World { + specs: replace_specs(), + changes: vec![(s1, a), (s1 + gap, b)], + jumps: Vec::new(), + horizon: 14, + }; + let h = simulate(&w, &mut *mk()); + check(&h, &format!("replace {:?} at {s1} by {:?} at {}", a, b, s1 + gap))?; + } + } + } + } + // 앞 표의 시작 틱이 지난 뒤에 다시 정하는 경우. 틱 처리가 멈춰 있었다면 그 + // 틱을 먼저 전해야 시스템 콜이 돌 수 있으므로, 틱을 하나씩 전하는 쪽과 한 + // 번에 건너뛰어 전하는 쪽을 둘 다 본다. 앞 표는 전해지는 사이에 올라가고 + // 새 표는 그 뒤의 틱 + 2에서 시작한다 + for &a in &tables { + for &b in &tables { + for s1 in 0..3u64 { + for stall in 0..=3u64 { + for jump in [false, true] { + let mut s = mk(); + let mut h = script_host(replace_specs(), &mut *s); + for t in 1..=s1 { + step_to(&mut h, &mut *s, t); + } + ev_set(&mut h, &mut *s, a); + let now = s1 + 2 + stall; + if jump { + step_to(&mut h, &mut *s, now); + } else { + for t in s1 + 1..=now { + step_to(&mut h, &mut *s, t); + } + } + ev_set(&mut h, &mut *s, b); + for t in now + 1..=now + 12 { + step_to(&mut h, &mut *s, t); + } + check(&h, &format!("late set {:?} at {s1}, {:?} at {now}, jump {jump}", a, b))?; + } + } + } + } + } + Ok(()) +} + +/// 틱을 전하고 표를 정하는 사건의 열에서 한 걸음입니다. +#[derive(Clone, Copy, Debug)] +enum Step { + /// 지금까지 처리한 틱에서 이만큼 뒤의 틱을 전함(1이면 다음 틱, 더 크면 건너뜀) + Tick(u64), + Set(Table), + /// 같은 번호의 틱 사건을 되풀이함(이른 인터럽트 뒤의 같은 번호) + Again, +} + +fn random_script(r: &mut Rng, len: u64) -> Vec { + (0..len) + .map(|_| match r.below(10) { + 0..=3 => Step::Tick(1), + 4 => Step::Tick(2 + r.below(4)), + 5 => Step::Again, + _ => Step::Set(rand_table(r, 4, 0)), + }) + .collect() +} + +fn guard_specs() -> Vec { + let mut v = replace_specs(); + v.push(spec(2, vec![Op::Spin])); + v +} + +/// 열을 처음부터 돌려 스케줄러와 Host를 돌려주는 함수입니다. `extra`가 있으면 열의 +/// 끝에서 그 표를 한 번 더 정합니다. +fn replay(mk: Mk, script: &[Step], extra: Option
) -> (Box, Host) { + let mut s = mk(); + let mut h = script_host(guard_specs(), &mut *s); + for st in script { + match *st { + Step::Tick(d) => { + let t = h.now + d; + step_to(&mut h, &mut *s, t); + } + Step::Set(t) => ev_set(&mut h, &mut *s, t), + Step::Again => { + let r = ev_tick(&mut h, &mut *s); + h.check_next(r); + } + } + } + if let Some(t) = extra { + ev_set(&mut h, &mut *s, t); + } + (s, h) +} + +/// 속성 11: 틱, 건너뜀, 되풀이, 표 설정이 섞인 어떤 열에서도 `next_tick_switches()`는 +/// 사건마다(표를 정한 바로 뒤 포함) 기준 Plan의 틱 seen + 1의 답과 같습니다. 기준은 +/// Core와 따로 적은 [Plan]이고 표를 정하는 것은 처리한 틱 seen에서뿐입니다. +fn p_guard_answer(mk: Mk, sc: Scale) -> Result { + let mut checked = 0; + for seed in 0..sc.random { + let mut r = Rng::new(seed ^ 0x6A6A); + let len = 2 + r.below(14); + let script = random_script(&mut r, len); + let mut s = mk(); + let mut h = script_host(guard_specs(), &mut *s); + for (i, st) in script.iter().enumerate() { + match *st { + Step::Tick(d) => { + let t = h.now + d; + step_to(&mut h, &mut *s, t); + } + Step::Set(t) => ev_set(&mut h, &mut *s, t), + Step::Again => { + let r = ev_tick(&mut h, &mut *s); + h.check_next(r); + } + } + check(&h, &format!("guard world {seed} step {i}"))?; + let want = h.plan.domain_at(h.seen + 1) != s.running_domain(); + if s.next_tick_switches() != want { + return Err(format!( + "seed {seed} after step {i} {st:?} (seen {}): next_tick_switches {} but the plan says {want}: {script:?}", + h.seen, + s.next_tick_switches() + )); + } + checked += 1; + } + } + Ok(checked) +} + +/// 속성 12: 처리한 틱 seen에서 표를 정해도 틱 seen + 1의 도메인은 바뀌지 않습니다. 다만 +/// seen + 1에서 시작하기로 한 보류 표를 갈아 끼울 때는 예외이고, 그때는 도메인이 바뀌는 +/// 만큼 `next_tick_switches()`가 바로 달라집니다(Lean의 `guard_sound`와 그 가정이 빠진 +/// 반례). 같은 열을 표를 더 정한 쪽과 안 정한 쪽으로 두 번 돌려 실제 Core의 도메인을 +/// 견주고, 기준 Plan의 답과도 견줍니다. 센 값은 (예외가 아닌 경우, 예외인 경우, 예외에서 +/// 도메인이 실제로 달라진 경우, 예외에서 예고가 달라진 경우)입니다. +fn p_guard_sound(mk: Mk, sc: Scale) -> Result<(u64, u64, u64, u64), String> { + let (mut plain, mut replacing, mut domain_changed, mut guard_changed) = (0, 0, 0, 0); + for seed in 0..sc.random { + let mut r = Rng::new(seed ^ 0x5151); + let len = 1 + r.below(10); + let script = random_script(&mut r, len); + let table = rand_table(&mut r, 4, 0); + let (mut a, mut ha) = replay(mk, &script, Some(table)); + let (mut b, mut hb) = replay(mk, &script, None); + check(&ha, &format!("guard sound A {seed}"))?; + check(&hb, &format!("guard sound B {seed}"))?; + let seen = hb.seen; + if ha.seen != seen { + return Err(format!("seed {seed}: the set_table changed the processed tick")); + } + let starts_next = hb.plan.segs.iter().any(|(st, _)| *st == seen + 1); + let (before, after) = (b.next_tick_switches(), a.next_tick_switches()); + let rd = b.running_domain(); + if a.running_domain() != rd { + return Err(format!("seed {seed}: set_table changed the running domain")); + } + let (want_b, want_a) = (hb.plan.domain_at(seen + 1), ha.plan.domain_at(seen + 1)); + if before != (want_b != rd) || after != (want_a != rd) { + return Err(format!("seed {seed}: next_tick_switches {before}/{after} vs the plan {want_b:?}/{want_a:?}")); + } + step_to(&mut ha, &mut *a, seen + 1); + step_to(&mut hb, &mut *b, seen + 1); + check(&ha, &format!("guard sound A tick {seed}"))?; + check(&hb, &format!("guard sound B tick {seed}"))?; + let (da, db) = (a.running_domain(), b.running_domain()); + if da != want_a || db != want_b { + return Err(format!("seed {seed}: the domains of tick {} are {da:?}/{db:?}, the plan says {want_a:?}/{want_b:?}", seen + 1)); + } + if !starts_next { + plain += 1; + if da != db || after != before { + return Err(format!("seed {seed}: set_table changed tick {} or its guard without a pending table starting there: {script:?} {table:?}", seen + 1)); + } + } else { + replacing += 1; + domain_changed += u64::from(da != db); + guard_changed += u64::from(after != before); + } + } + Ok((plain, replacing, domain_changed, guard_changed)) +} + +/// 속성 8: 틱이 한 바퀴 또는 여러 바퀴를 건너뛰어도 사건은 한 번이고 도메인은 도착한 +/// 번호가 정합니다(건너뛴 틱의 도메인은 일하지 않음). 사건마다의 호출은 [finish]가 봅니다. +fn p_jumps(mk: Mk, sc: Scale) -> Result<(), String> { + let mut tables = small_tables(); + tables.push(tbl(&[(0, 2), (1, 3), (2, 1)])); + tables.push(tbl(&[(2, 1), (0, 1), (1, 1)])); + tables.push(tbl(&[(1, 1), (1, 2), (0, 1), (1, 1)])); + let specs = || { + vec![ + spec(0, vec![Op::Spin]), + spec(0, vec![Op::Yield, Op::Spin]), + spec(1, vec![Op::Spin]), + spec(1, vec![Op::Wait(1), Op::Spin]), + spec(2, vec![Op::Spin]), + ] + }; + for (i, &t) in tables.iter().enumerate() { + if !sc.exhaustive && i % 3 != 0 { + continue; + } + let c = t.cycle() as u64; + let mut extras = vec![0, 1, c, c + 1, 2 * c, 3 * c + 1, 5 * c + 2]; + if c > 1 { + extras.push(c - 1); + } + for at in 1..=c + 2 { + for &extra in &extras { + for set_at in [0u64, 1, 2] { + let w = World { + specs: specs(), + changes: vec![(set_at, t)], + jumps: vec![(at, extra)], + horizon: 6 * c + 8, + }; + let h = simulate(&w, &mut *mk()); + check(&h, &format!("jump of {extra} after tick {at}, table {:?} set at {set_at}", t))?; + // 기준으로 센 도메인 변경 횟수와 enter_domain의 횟수 + let mut k = 1; + let mut prev = Domain::ROOT; + let mut changes = 0; + while k <= w.horizon { + let d = h.plan.domain_at(k); + changes += usize::from(d != prev); + prev = d; + k += 1 + w.jumps.iter().find(|j| j.0 == k).map_or(0, |j| j.1); + } + let enters = h.calls.iter().filter(|c| matches!(c, Call::Enter(_))).count(); + if enters != changes { + return Err(format!("{enters} enter_domain calls but {changes} domain changes: {:?} jump {at}+{extra}", t)); + } + } + } + } + } + Ok(()) +} + +fn root_tables() -> Vec
{ + vec![ + tbl(&[(0, 3)]), + tbl(&[(0, 1), (0, 2)]), + tbl(&[(0, 2), (0, 2)]), + tbl(&[(0, 255)]), + tbl(&[(0, 1); 16]), + ] +} + +/// 속성 9: 루트만 든 표는 나뉜 표가 아니고 기본 표와 호출 하나하나까지 같게 움직입니다. +fn p_root_only(mk: Mk, sc: Scale) -> Result<(), String> { + let tabs = root_tables(); + for t in &tabs { + if !t.is_default() || !t.contains(Domain::ROOT) { + return Err(format!("{t:?} must be a default table")); + } + } + let same = |w: &World, base: &World, what: &str| -> Result<(), String> { + let (ha, hb) = (simulate(w, &mut *mk()), simulate(base, &mut *mk())); + check(&ha, what)?; + check(&hb, what)?; + if ha.stats.partitioned_events != 0 { + return Err(format!("{what}: a root-only table was reported as partitioned")); + } + if ha.calls != hb.calls || ha.runs != hb.runs || ha.trace != hb.trace { + return Err(format!("{what}: the calls differ from those of the default table")); + } + Ok(()) + }; + for seed in 0..sc.random { + let mut w = random_world(seed ^ 0xA5A5, 40); + for s in &mut w.specs { + s.domain = 0; + } + let mut base = w.clone(); + base.changes = Vec::new(); + let mut r = Rng::new(seed); + w.changes = (0..1 + r.below(3)).map(|_| (r.below(30), tabs[r.below(tabs.len() as u64) as usize])).collect(); + w.changes.sort_by_key(|x| x.0); + same(&w, &base, &format!("root-only world {seed}"))?; + } + if sc.exhaustive { + let progs = small_progs(); + for tab in &tabs[..3] { + for a in &progs { + for b in &progs { + let specs = vec![spec(0, a.clone()), spec(0, b.clone()), spec(0, vec![Op::Yield, Op::Spin])]; + let base = World { specs: specs.clone(), changes: Vec::new(), jumps: vec![(3, 2)], horizon: 10 }; + let w = World { changes: vec![(0, *tab)], ..base.clone() }; + same(&w, &base, &format!("exhaustive root-only {:?} {:?} {:?}", tab, a, b))?; + } + } + } + } + // 보류 표도 루트만 든 표면 나뉜 것이 아니다. 나뉜 표 위에 정하면 올라가기 전까지는 나뉜 것이다 + let mut c = mk(); + let mut h = Host::new(&[]); + c.set_table(tabs[0]); + if c.partitioned() { + return Err("a pending root-only table must not count as partitioned".into()); + } + c.set_table(tbl(&[(0, 1), (1, 1)])); + if !c.partitioned() { + return Err("a pending partitioned table counts as partitioned".into()); + } + c.set_table(tabs[1]); + if c.partitioned() { + return Err("replacing the pending table by a root-only one clears partitioned".into()); + } + c.set_table(tbl(&[(1, 1)])); + for t in 1..=3 { + h.now = t; + c.tick(&mut h); + } + c.set_table(tabs[2]); + if !c.partitioned() { + return Err("a partitioned table in force stays partitioned until the root-only one starts".into()); + } + for t in 4..=5 { + h.now = t; + c.tick(&mut h); + } + if c.partitioned() { + return Err("partitioned must clear when the root-only table starts".into()); + } + Ok(()) +} + +/// 속성 10: 사건마다 호출 순서와 상태 규칙(I1 I2 I3)과 도는 도메인이 맞는지는 [finish]가 +/// 봅니다. 여기서는 되풀이한 틱과 건너뜀이 섞인 무작위 세계를 돌리고 본 사건의 수를 +/// 합쳐 돌려줍니다. +fn p_events(mk: Mk, sc: Scale) -> Result { + let mut sum = Stats::default(); + for seed in 0..sc.random { + let mut w = random_world(seed ^ 0xE7E7, 40); + if w.jumps.is_empty() { + let mut r = Rng::new(seed); + w.jumps = rand_jumps(&mut r, 40); + } + let h = simulate(&w, &mut *mk()); + check(&h, &format!("event world {seed}"))?; + let s = h.stats; + sum.events += s.events; + sum.boundaries += s.boundaries; + sum.boundaries_running += s.boundaries_running; + sum.boundaries_rotated += s.boundaries_rotated; + sum.same_domain_ticks += s.same_domain_ticks; + sum.idle_entries += s.idle_entries; + sum.polls_without_tick += s.polls_without_tick; + sum.yields += s.yields; + sum.blocks += s.blocks; + sum.repeats += s.repeats; + sum.jumps += s.jumps; + sum.partitioned_events += s.partitioned_events; + } + Ok(sum) +} + +/// 모든 속성을 돌려 어느 것이 실패했는지 모아 돌려줍니다. +fn check_all(mk: Mk, sc: Scale) -> Vec<(&'static str, String)> { + let mut bad = Vec::new(); + let mut note = |name: &'static str, r: Result<(), String>| { + if let Err(e) = r { + bad.push((name, e)); + } + }; + note("window exactness", p_window_exact(mk, sc)); + note("two-run equality", p_two_run(mk, sc).map(|_| ())); + note("default table equivalence", p_default_equal(mk, sc)); + note("share bound", p_share(mk, sc)); + note("table", p_table(mk, sc)); + note("tick rule at a boundary", p_tick_rule(mk)); + note("pending replacement", p_replace(mk, sc)); + note("guard answer after every event", p_guard_answer(mk, sc).map(|_| ())); + note("guard soundness of set_table", p_guard_sound(mk, sc).map(|_| ())); + note("jumps", p_jumps(mk, sc)); + note("root-only tables", p_root_only(mk, sc)); + note("call order and invariants", p_events(mk, sc).map(|_| ())); + bad +} + +#[test] +fn window_exactness_and_no_slack_donation() { + p_window_exact(&real, FULL).unwrap(); +} + +#[test] +fn two_run_equality() { + let differing = p_two_run(&real, FULL).unwrap(); + assert!(differing > FULL.random / 4, "workloads of the other domains must really differ: {differing}"); +} + +#[test] +fn two_run_equality_is_not_vacuous_with_a_shared_object() { + // 도메인 1의 읽는 태스크가 오브젝트 2를 기다리고, 도메인 0의 태스크가 얼마 + // 뒤에 신호를 보냄. 신호를 보내는 쪽의 일정이 달라지면 도메인 1의 흔적도 달라짐 + let build = |wait: u64| World { + specs: vec![ + spec(0, vec![Op::Wait(wait), Op::Post(2), Op::Spin]), + spec(1, vec![Op::Pend(2), Op::Spin]), + ], + changes: vec![(0, tbl(&[(0, 1), (1, 1)]))], + jumps: Vec::new(), + horizon: 14, + }; + let (a, b) = (simulate(&build(1), &mut *real()), simulate(&build(4), &mut *real())); + check(&a, "a").unwrap(); + check(&b, "b").unwrap(); + assert_ne!(trace_of(&a, 1), trace_of(&b, 1), "a shared object must leak, else the property tests nothing"); + // 같은 두 세계에서 신호가 없으면(도메인 0이 오브젝트를 안 건드림) 흔적이 같다 + let quiet = |wait: u64| World { + specs: vec![spec(0, vec![Op::Wait(wait), Op::Spin]), spec(1, vec![Op::Pend(2), Op::Spin])], + changes: vec![(0, tbl(&[(0, 1), (1, 1)]))], + jumps: Vec::new(), + horizon: 14, + }; + let (a, b) = (simulate(&quiet(1), &mut *real()), simulate(&quiet(4), &mut *real())); + assert_eq!(trace_of(&a, 1), trace_of(&b, 1)); +} + +#[test] +fn default_table_equals_the_frozen_scheduler() { + p_default_equal(&real, FULL).unwrap(); +} + +#[test] +fn share_bound_inside_a_domain() { + p_share(&real, FULL).unwrap(); +} + +#[test] +fn table_timing_and_jumps() { + p_table(&real, FULL).unwrap(); +} + +#[test] +fn tick_rule_at_a_boundary() { + p_tick_rule(&real).unwrap(); +} + +#[test] +fn copy_equals_core() { + // 틀림 없는 사본이 실제 Core와 같은 결정을 내리는지 + for seed in 0..FULL.random { + let w = random_world(seed ^ 0x99, 40); + let (a, b) = (simulate(&w, &mut *real()), simulate(&w, &mut *mutant(Mutant::None))); + assert_eq!(a.runs, b.runs, "seed {seed}"); + assert_eq!(a.trace, b.trace, "seed {seed}"); + assert_eq!(a.bad, b.bad, "seed {seed}"); + } + let bad = check_all(&|| mutant(Mutant::None), QUICK); + assert!(bad.is_empty(), "{bad:?}"); +} + +#[test] +fn deliberate_breaks_are_caught() { + for m in ALL_MUTANTS { + let bad = check_all(&|| mutant(m), QUICK); + println!("{:?}: caught by {:?}", m, bad.iter().map(|b| b.0).collect::>()); + assert!(!bad.is_empty(), "{m:?} was not caught by any property"); + } + // 새 연결 실수는 새 속성에 걸려야 한다 + let new_props = ["pending replacement", "jumps", "root-only tables", "call order and invariants"]; + for m in [ + Mutant::NoEnterDomain, + Mutant::ServeBeforeEnter, + Mutant::ServeOldInstead, + Mutant::ReplaceStartsNextTick, + Mutant::SpuriousAsTick, + Mutant::BlockKeepsRunning, + Mutant::StartsInThree, + Mutant::SwitchesIgnoresPending, + ] { + let bad = check_all(&|| mutant(m), QUICK); + assert!(bad.iter().any(|b| new_props.contains(&b.0)), "{m:?} was not caught by a new property: {bad:?}"); + } + // 시계 산술의 연결 실수도 같은 자리에서 확인한다 + for v in crate::clock_tests::ALL_BREAKS { + assert!(crate::clock_tests::caught(v), "{v:?} was not caught by the clock properties"); + } +} + +/// 표의 읽기 쓰기를 한 단계씩 확인하는 기준입니다. Table::decode와 따로 적었습니다. +fn oracle(count: u64, regs: [u64; 4]) -> bool { + if !(1..=16).contains(&count) { + return false; + } + (0..16).all(|i| { + let v = (regs[i / 4] >> (16 * (i % 4))) & 0xffff; + if (i as u64) < count { (v & 0xff) < 8 && (v >> 8) >= 1 } else { v == 0 } + }) +} + +#[test] +fn table_decode_accepts_exactly_the_well_formed() { + // 항목 0의 16비트 전부 x 항목 수 0..=3 (나머지 칸은 0) + for count in 0..=3u64 { + for v in 0..=0xffffu64 { + let regs = [v, 0, 0, 0]; + assert_eq!(Table::decode(count, regs).is_ok(), oracle(count, regs), "count {count} v {v:#x}"); + } + } + // 항목 0, 1은 대표값으로 격자, 둘째 칸은 전부 + let firsts = [0u64, 1, 0x0100, 0x0101, 0x0107, 0x0108, 0x01ff, 0xff07, 0x0007, 0x8001]; + for count in [1u64, 2, 3] { + for &a in &firsts { + for b in 0..=0xffffu64 { + let regs = [a | (b << 16), 0, 0, 0]; + assert_eq!(Table::decode(count, regs).is_ok(), oracle(count, regs)); + } + } + } + // 항목 수 경계 + for count in [0u64, 1, 15, 16, 17, 18, 255, u64::MAX] { + let full = [0x0101_0101_0101_0101u64; 4]; + assert_eq!(Table::decode(count, full).is_ok(), oracle(count, full), "count {count}"); + } + // 무작위: 성긴 비트와 올바른 인코딩에 비트 하나를 뒤집은 것 + let mut r = Rng::new(42); + for _ in 0..400_000 { + let count = r.below(20); + let mut regs = [0u64; 4]; + for i in 0..count.min(16) as usize { + let v = ((1 + r.below(255)) << 8) | r.below(8); + regs[i / 4] |= v << (16 * (i % 4)); + } + match r.below(3) { + 0 => {} + 1 => regs[r.below(4) as usize] ^= 1 << r.below(64), + _ => regs[r.below(4) as usize] = r.next() & r.next() & r.next(), + } + assert_eq!(Table::decode(count, regs).is_ok(), oracle(count, regs), "count {count} regs {regs:x?}"); + } +} + +#[test] +fn table_decode_reads_the_abi_packing_and_reports_the_first_fault() { + let regs = [0x0201_0105_0301_0200u64, 0, 0, 0]; + let t = Table::decode(4, regs).unwrap(); + let got: Vec<(u8, u32)> = (0..t.len()).map(|i| (t.entry(i).unwrap().0.id(), t.entry(i).unwrap().1)).collect(); + // 항목 0은 하위 16비트 0x0200(틱 2, 도메인 0), 항목 1은 0x0301(틱 3, 도메인 1) + assert_eq!(got, [(0, 2), (1, 3), (5, 1), (1, 2)]); + assert_eq!(t.cycle(), 8); + assert_eq!(Table::decode(0, [0; 4]), Err(TableError::Count)); + assert_eq!(Table::decode(17, [0; 4]), Err(TableError::Count)); + assert_eq!(Table::decode(1, [0x0108, 0, 0, 0]), Err(TableError::Domain)); + assert_eq!(Table::decode(1, [0x0001, 0x00, 0, 0]), Err(TableError::Window)); + assert_eq!(Table::decode(1, [0x0100 | (1 << 16), 0, 0, 0]), Err(TableError::Reserved)); + assert_eq!(Table::decode(1, [0x0100, 0, 0, 1 << 63]), Err(TableError::Reserved)); + assert!(Table::decode(1, [0x0100, 0, 0, 0]).unwrap().is_default()); + assert_eq!(Table::decode(1, [0x0100, 0, 0, 0]).unwrap(), Table::DEFAULT); + let max = [0xff07_ff07_ff07_ff07u64; 4]; + assert_eq!(Table::decode(16, max).unwrap().cycle(), 16 * 255); +} + +#[test] +fn table_helpers() { + assert!(Table::DEFAULT.is_default() && Table::DEFAULT.contains(Domain::ROOT)); + assert!(!tbl(&[(0, 1), (1, 1)]).is_default()); + assert!(tbl(&[(0, 2), (0, 1)]).is_default()); + assert!(!tbl(&[(1, 1)]).contains(Domain::ROOT)); + assert_eq!(Table::from_entries(&[]), Err(TableError::Count)); + assert_eq!(Table::from_entries(&[(Domain::ROOT, 0)]), Err(TableError::Window)); + assert_eq!(Table::from_entries(&[(Domain::ROOT, 256)]), Err(TableError::Window)); + assert_eq!(Domain::new(8), None); + let mut c = Core::::new(); + assert!(!c.partitioned()); + c.set_table(tbl(&[(0, 1), (1, 1)])); + assert!(c.partitioned()); + c.set_table(Table::DEFAULT); + assert!(!c.partitioned()); +} + +#[test] +fn share_lag_is_not_sloppy() { + // 한계가 너무 느슨해서 속성이 비는 일이 없도록, 실제로 관측한 가장 큰 뒤처짐을 본다 + let mut worst = [i64::MIN; 6]; + for seed in 0..FULL.random { + let (w, spinner, d, n) = share_world(seed); + let l = worst_lag(&real, &w, spinner, d, n).unwrap(); + worst[n as usize] = worst[n as usize].max(l); + } + println!("observed worst lag by N: {:?}", &worst[2..5]); + for (n, &w) in worst.iter().enumerate().skip(2).take(3) { + assert!(w <= share_lag(n as u64) as i64); + assert!(w > 0, "the workloads must really take share from the spinner"); + } +} + +#[test] +fn a_pending_table_can_be_replaced_before_it_starts() { + p_replace(&real, FULL).unwrap(); +} + +#[test] +fn replacement_hand_cases_with_next_tick_switches() { + // 틱 5에 [(1,1)]을 정하면 틱 7에서 시작한다 틱 6에 [(2,1)]로 바꾸면 틱 8에서 시작한다 + let mut s = real(); + let mut h = script_host(replace_specs(), &mut *s); + for t in 1..=5 { + step_to(&mut h, &mut *s, t); + } + ev_set(&mut h, &mut *s, tbl(&[(1, 1)])); + assert!(!s.next_tick_switches(), "tick 6 is still the root domain"); + step_to(&mut h, &mut *s, 6); + assert!(s.next_tick_switches(), "tick 7 starts the pending table"); + ev_set(&mut h, &mut *s, tbl(&[(2, 1)])); + assert!(!s.next_tick_switches(), "the replaced table no longer starts at tick 7"); + step_to(&mut h, &mut *s, 7); + assert_eq!(s.running_domain(), Domain::ROOT); + assert!(s.next_tick_switches(), "tick 8 starts the replacement"); + step_to(&mut h, &mut *s, 8); + assert_eq!(s.running_domain().id(), 2); + assert!(!s.next_tick_switches()); + h.bad.map_or(Ok(()), Err).unwrap(); + + // 틱 5에 정한 표(시작 7)가 있는데 틱 처리가 멈춰 있다가 틱 8로 건너뛴 뒤에 다시 정한다 + let mut s = real(); + let mut h = script_host(replace_specs(), &mut *s); + for t in 1..=5 { + step_to(&mut h, &mut *s, t); + } + ev_set(&mut h, &mut *s, tbl(&[(1, 1)])); + // 건너뛰어 도착한 틱 8에서 앞 표가 올라가 있고(도메인 1), 새 표는 틱 10에서 시작한다 + step_to(&mut h, &mut *s, 8); + assert_eq!(s.running_domain().id(), 1); + assert!(!s.next_tick_switches()); + ev_set(&mut h, &mut *s, tbl(&[(0, 1), (2, 1)])); + assert!(!s.next_tick_switches(), "tick 9 is still the first table"); + step_to(&mut h, &mut *s, 9); + assert_eq!(s.running_domain().id(), 1); + assert!(s.next_tick_switches(), "tick 10 starts the second table at its entry 0"); + step_to(&mut h, &mut *s, 10); + assert_eq!(s.running_domain().id(), 0); + step_to(&mut h, &mut *s, 11); + assert_eq!(s.running_domain().id(), 2); + step_to(&mut h, &mut *s, 12); + assert_eq!(s.running_domain().id(), 0); + h.bad.map_or(Ok(()), Err).unwrap(); +} + +#[test] +fn next_tick_switches_equals_the_plan_after_every_event() { + let n = p_guard_answer(&real, FULL).unwrap(); + assert!(n > 20_000, "the property must see many events: {n}"); +} + +#[test] +fn set_table_keeps_the_next_tick_unless_it_replaces_a_table_starting_there() { + let (plain, replacing, domain_changed, guard_changed) = p_guard_sound(&real, FULL).unwrap(); + println!("plain {plain} replacing {replacing} domain changed {domain_changed} guard changed {guard_changed}"); + assert!(plain > 1000 && replacing > 100, "both sides must be exercised: {plain} {replacing}"); + assert!(domain_changed > 20, "the replacing side must really change a domain: {domain_changed}"); + assert!(guard_changed > 20, "the guard must follow the change at once: {guard_changed}"); +} + +#[test] +fn guard_soundness_by_hand_both_sides() { + // 쪽 하나: 표를 정해도 다음 틱의 도메인과 예고는 그대로다(앞의 보류 표가 없음) + let mut s = real(); + let mut h = script_host(guard_specs(), &mut *s); + for t in 1..=3 { + step_to(&mut h, &mut *s, t); + } + assert!(!s.next_tick_switches()); + ev_set(&mut h, &mut *s, tbl(&[(1, 1)])); + assert!(!s.next_tick_switches(), "tick 4 is still the root domain, the table starts at 5"); + step_to(&mut h, &mut *s, 4); + assert_eq!(s.running_domain(), Domain::ROOT); + assert!(s.next_tick_switches(), "tick 5 starts the table"); + // 쪽 둘: Lean의 반례와 같은 모양: 틱 1에 정하면 3에서 시작하고, 틱 2에 다시 정하면 그 표는 버려진다 + let mut s = real(); + let mut h = script_host(guard_specs(), &mut *s); + step_to(&mut h, &mut *s, 1); + ev_set(&mut h, &mut *s, tbl(&[(1, 1)])); + step_to(&mut h, &mut *s, 2); + assert_eq!(s.running_domain(), Domain::ROOT); + assert!(s.next_tick_switches(), "tick 3 starts the first table"); + ev_set(&mut h, &mut *s, tbl(&[(2, 1)])); + assert!(!s.next_tick_switches(), "the guard follows the replacement at once: tick 3 stays root"); + step_to(&mut h, &mut *s, 3); + assert_eq!(s.running_domain(), Domain::ROOT); + assert!(s.next_tick_switches(), "tick 4 starts the replacement"); + step_to(&mut h, &mut *s, 4); + assert_eq!(s.running_domain().id(), 2); + h.bad.map_or(Ok(()), Err).unwrap(); + // 같은 열에서 둘째 설정이 없었다면 틱 3은 도메인 1이었다(예외가 실제로 도메인을 바꿈) + let mut s = real(); + let mut h = script_host(guard_specs(), &mut *s); + step_to(&mut h, &mut *s, 1); + ev_set(&mut h, &mut *s, tbl(&[(1, 1)])); + step_to(&mut h, &mut *s, 2); + step_to(&mut h, &mut *s, 3); + assert_eq!(s.running_domain().id(), 1); + h.bad.map_or(Ok(()), Err).unwrap(); +} + +#[test] +fn jumps_over_one_cycle_and_over_several() { + p_jumps(&real, FULL).unwrap(); + // 한 바퀴 6틱인 표에서 틱 2부터 틱 14로, 다시 틱 40으로 뛴다 + let w = World { + specs: replace_specs(), + changes: vec![(0, tbl(&[(0, 2), (1, 3), (0, 1)]))], + jumps: vec![(3, 10), (15, 24)], + horizon: 45, + }; + let h = simulate(&w, &mut *real()); + check(&h, "jump").unwrap(); + let ticks: Vec = ran_by_tick(&h).iter().map(|x| x.0).collect(); + assert!(ticks.contains(&14) && ticks.contains(&40), "the events land on the arrival ticks: {ticks:?}"); + assert!(!ticks.contains(&5) && !ticks.contains(&20), "skipped ticks have no event: {ticks:?}"); + // 건너뛴 뒤의 도메인은 도착한 번호가 정한다: 틱 2부터 0,0,1,1,1,0 이므로 틱 14는 오프셋 12에서 0 + let mut s = real(); + let mut h = script_host(replace_specs(), &mut *s); + ev_set(&mut h, &mut *s, tbl(&[(0, 2), (1, 3), (0, 1)])); + step_to(&mut h, &mut *s, 1); + step_to(&mut h, &mut *s, 2); + for (t, d) in [(14u64, 0u8), (17, 1), (26, 0), (28, 1), (60, 1), (63, 0), (1000, 1)] { + let c0 = h.calls.len(); + step_to(&mut h, &mut *s, t); + assert_eq!(s.running_domain().id(), d, "tick {t}"); + let serves = h.calls[c0..].iter().filter(|c| matches!(c, Call::Serve(..))).count(); + assert_eq!(serves, 1, "one serve for the whole jump to {t}"); + let enters: Vec<&Call> = h.calls[c0..].iter().filter(|c| matches!(c, Call::Enter(_))).collect(); + assert!(enters.len() <= 1, "at most one domain entry for the jump to {t}"); + } + h.bad.map_or(Ok(()), Err).unwrap(); +} + +#[test] +fn consecutive_entries_of_one_domain_are_not_a_boundary() { + let pairs = [ + (tbl(&[(1, 1), (1, 2), (0, 1), (1, 1)]), tbl(&[(1, 3), (0, 1), (1, 1)])), + (tbl(&[(0, 1), (1, 1), (1, 1)]), tbl(&[(0, 1), (1, 2)])), + (tbl(&[(1, 1), (0, 1), (0, 1), (1, 1)]), tbl(&[(1, 1), (0, 2), (1, 1)])), + (tbl(&[(1, 2), (1, 2)]), tbl(&[(1, 4)])), + ]; + for (a, b) in pairs { + let mk = |t: Table| World { + specs: vec![ + spec(0, vec![Op::Spin]), + spec(0, vec![Op::Yield, Op::Spin]), + spec(1, vec![Op::Spin]), + spec(1, vec![Op::Wait(1), Op::Spin]), + spec(1, vec![Op::Spin]), + ], + changes: vec![(0, t)], + jumps: Vec::new(), + horizon: 24, + }; + let (ha, hb) = (simulate(&mk(a), &mut *real()), simulate(&mk(b), &mut *real())); + check(&ha, "a").unwrap(); + check(&hb, "b").unwrap(); + assert_eq!(ha.calls, hb.calls, "{a:?} and {b:?} describe the same plan"); + assert_eq!(ha.trace, hb.trace); + // 기준 Plan으로 센 도메인 변경 횟수만큼만 들어간다(틱 1은 루트 그대로) + let mut prev = Domain::ROOT; + let mut changes = 0; + for t in 1..=24 { + let d = ha.plan.domain_at(t); + changes += usize::from(d != prev); + prev = d; + } + let enters = ha.calls.iter().filter(|c| matches!(c, Call::Enter(_))).count(); + assert_eq!(enters, changes, "{a:?}"); + // 세워 두는 일(맨 앞으로 넣기)은 도는 태스크가 있는 경계에서만 한 번씩 있다 + let fronts = ha.calls.iter().filter(|c| matches!(c, Call::PushFront(..))).count() as u64; + assert_eq!(fronts, ha.stats.boundaries_running, "{a:?}"); + assert_eq!(ha.stats.boundaries as usize, changes); + } +} + +#[test] +fn state_invariants_and_call_order_hold_after_every_event_and_are_exercised() { + let s = p_events(&real, FULL).unwrap(); + println!("{s:?}"); + assert!(s.events > 100_000); + assert!(s.boundaries > 1000 && s.boundaries_running > 500 && s.boundaries_rotated > 50); + assert!(s.same_domain_ticks > 1000 && s.idle_entries > 100 && s.polls_without_tick > 100); + assert!(s.yields > 1000 && s.blocks > 1000 && s.repeats > 1000 && s.jumps > 100); + assert!(s.partitioned_events > 1000); +} + +#[test] +fn root_only_tables_are_not_partitioned_and_equal_the_default() { + p_root_only(&real, FULL).unwrap(); +} + +#[test] +fn boundary_calls_come_in_the_designed_order() { + use Call::*; + let (d0, d1, d2) = (Domain::ROOT, Domain::new(1).unwrap(), Domain::new(2).unwrap()); + let run = |specs: Vec, table: Table, f: &mut dyn FnMut(&mut Host, &mut dyn Sched)| { + let mut s = real(); + let mut h = script_host(specs, &mut *s); + ev_set(&mut h, &mut *s, table); + f(&mut h, &mut *s); + h.bad.clone().map_or(Ok(()), Err).unwrap(); + h + }; + let at = |h: &mut Host, s: &mut dyn Sched, t: u64| -> Vec { + let c0 = h.calls.len(); + step_to(h, s, t); + h.calls[c0..].to_vec() + }; + // 규칙이 Rotate이고 준비된 태스크가 없음: 도는 태스크를 세우고, 들어가고, 깨우고, 꺼내서 실행 + run(vec![spec(0, vec![Op::Spin]), spec(1, vec![Op::Spin])], tbl(&[(1, 1), (0, 1)]), &mut |h, s| { + assert_eq!(at(h, s, 1), [Serve(d0, 1)]); + assert_eq!( + at(h, s, 2), + [Pop(d0, None), PushFront(d0, 0), Enter(d1), Serve(d1, 2), Pop(d1, Some(1)), Run(1)] + ); + assert_eq!( + at(h, s, 3), + [Pop(d1, None), PushFront(d1, 1), Enter(d0), Serve(d0, 3), Pop(d0, Some(0)), Run(0)] + ); + }); + // 틱 사이에 들어온 태스크는 경계에서 Keep이라 그대로 맨 앞에 선다 + run( + vec![spec(0, vec![Op::Spin]), spec(1, vec![Op::Spin]), spec(0, vec![Op::Spin])], + tbl(&[(1, 1), (0, 1)]), + &mut |h, s| { + let c0 = h.calls.len(); + ev_yield(h, s); + assert_eq!(h.calls[c0..], [Pop(d0, Some(2)), Push(d0, 0), Run(2)]); + assert_eq!( + at(h, s, 2), + [PushFront(d0, 2), Enter(d1), Serve(d1, 2), Pop(d1, Some(1)), Run(1)] + ); + // 틱 3에서 돌아오면 맨 앞은 2, 그다음 0 + assert_eq!( + at(h, s, 3), + [Pop(d1, None), PushFront(d1, 1), Enter(d0), Serve(d0, 3), Pop(d0, Some(2)), Run(2)] + ); + }, + ); + // Rotate이고 준비된 태스크가 있음: 큐 앞을 꺼내 도는 태스크를 뒤에 넣고 꺼낸 것을 다시 맨 앞에 둔다 + run( + vec![spec(0, vec![Op::Spin]), spec(1, vec![Op::Spin]), spec(0, vec![Op::Spin]), spec(0, vec![Op::Spin])], + tbl(&[(1, 1), (0, 1)]), + &mut |h, s| { + assert_eq!(at(h, s, 1), [Serve(d0, 1)]); + assert_eq!( + at(h, s, 2), + [ + Pop(d0, Some(2)), + Push(d0, 0), + PushFront(d0, 2), + Enter(d1), + Serve(d1, 2), + Pop(d1, Some(1)), + Run(1) + ] + ); + assert_eq!(h.q[0], [2, 3, 0]); + }, + ); + // 들어갈 도메인이 비어 있음: 일할 것이 없으면 Idle이고 다른 도메인의 큐는 건드리지 않는다 + run(vec![spec(0, vec![Op::Spin]), spec(1, vec![Op::Spin])], tbl(&[(2, 1), (0, 1)]), &mut |h, s| { + assert_eq!(at(h, s, 1), [Serve(d0, 1)]); + assert_eq!(at(h, s, 2), [Pop(d0, None), PushFront(d0, 0), Enter(d2), Serve(d2, 2), Pop(d2, None)]); + assert!(h.current.is_none() && h.q[1] == [1]); + // 같은 틱에 입력으로 깨어난 poll은 도는 도메인만 일한다 + let c0 = h.calls.len(); + let r = ev_poll(h, s); + assert_eq!(r, Next::Idle); + assert_eq!(h.calls[c0..], [Serve(d2, 2), Pop(d2, None)]); + assert_eq!(at(h, s, 3), [Enter(d0), Serve(d0, 3), Pop(d0, Some(0)), Run(0)]); + }); +} + +// 빈 채로 기다리던 도메인에 창 안쪽의 틱에서 들어오는 태스크: 도메인 1은 두 세계에서 +// 같고 도메인 0만 태스크 하나가 다름. 다른 도메인의 태스크가 남긴 틱 면제가 넘어오면 +// 도메인 1의 순서가 도메인 0의 태스크 수에 따라 달라짐 +#[test] +fn a_task_entering_an_idle_domain_at_an_interior_tick_owes_nothing_to_another_domain() { + let world = |extra: bool| { + let late = || { + let mut p = vec![Op::Wait(5)]; + p.extend(std::iter::repeat_n(Op::Spin, 60)); + p + }; + let mut specs = vec![spec(0, vec![Op::Wait(3)]), spec(1, late()), spec(1, late())]; + if extra { + specs.push(spec(0, vec![Op::Wait(3)])); + } + World { specs, changes: vec![(0, tbl(&[(0, 1), (1, 3)]))], jumps: Vec::new(), horizon: 12 } + }; + let (ha, hb) = (simulate(&world(true), &mut *real()), simulate(&world(false), &mut *real())); + check(&ha, "world A").unwrap(); + check(&hb, "world B").unwrap(); + // 보려는 경우에 실제로 닿음: 도메인 1의 두 태스크가 빈 창 안쪽의 틱 8에서 깨어남 + let woke8 = trace_of(&ha, 1).iter().filter(|e| matches!(e, Ev::Woke { tick: 8, .. })).count(); + assert_eq!(woke8, 2, "the pair must reach the idle entry at an interior tick"); + let at9 = |h: &Host| -> Vec { + trace_of(h, 1).iter().filter_map(|e| if let Ev::Ran { tick: 9, task, .. } = e { Some(*task) } else { None }).collect() + }; + assert_eq!(trace_of(&ha, 1), trace_of(&hb, 1), "domain 1 differs: tick 9 ran {:?} / {:?}", at9(&ha), at9(&hb)); + assert_eq!(at9(&ha), vec![2, 2, 2], "the task that entered at tick 8 must be rotated at tick 9"); +} diff --git a/crates/k0-sched/Cargo.toml b/crates/k0-sched/Cargo.toml index 46f0bbf..4585c01 100644 --- a/crates/k0-sched/Cargo.toml +++ b/crates/k0-sched/Cargo.toml @@ -16,4 +16,4 @@ granule-16k = ["k0-task/granule-16k", "k0-mm/granule-16k"] k0-arch = { path = "../k0-arch" } k0-mm = { path = "../k0-mm", default-features = false } k0-task = { path = "../k0-task", default-features = false } -k0-slice = { path = "../k0-slice" } +k0-part = { path = "../k0-part" } diff --git a/crates/k0-sched/src/lib.rs b/crates/k0-sched/src/lib.rs index 7276244..21e0ae6 100644 --- a/crates/k0-sched/src/lib.rs +++ b/crates/k0-sched/src/lib.rs @@ -1,126 +1,250 @@ -//! 라운드 로빈 스케줄러 크레이트입니다. +//! 시간 분할 스케줄러의 커널 쪽 크레이트입니다. //! //! # Features -//! 커널 heap 없이 TCB에 내장된 링크(intrusive list)로 준비 큐를 만듭니다. -//! 큐 노드 할당이 없어 큐 길이가 태스크 수로 자연히 상한되므로 스케줄러가 -//! 커널 자원 고갈의 원인이 되지 못합니다. 이양(handoff) 후 커널은 예외 -//! 컨텍스트에서만 실행되고, 벡터가 사용자 컨텍스트를 현재 TCB에 저장한 -//! 상태에서 전환이 일어나므로 전환은 `__current_context` 포인터 갱신과 -//! TTBR0 교체(주소 공간이 다를 때만, ASID 미사용이라 전체 TLB 무효화 -//! 동반)로 끝납니다. IPC 블록은 [block_and_switch]로 현재 태스크를 준비 큐 -//! 밖(엔드포인트 대기 큐나 reply 링크)에서 재우고, 깨우기는 [enqueue]입니다. +//! 판정은 전부 k0-part의 `Core`가 합니다. 어느 도메인이 도는지, 틱이 현재 +//! 태스크를 끊는지, 창의 경계에서 무엇을 하는지가 거기에 있고 호스트에서 +//! 시험합니다. 이 크레이트는 그 판정이 다루는 실물을 맡습니다. 도메인마다 하나씩 +//! 있는 준비 큐와 기한 목록, 현재 태스크의 설치(`__current_context` 포인터 +//! 갱신과 TTBR0 교체)입니다. 커널은 사건의 이름으로만 알립니다([handoff], +//! [rotate], [block_and_switch], [on_tick], [poll], [set_table]). CPU를 받은 +//! 경위나 "틱이 지나갔는지"를 커널이 골라 넘기는 자리는 없습니다. //! -//! 선점 신호는 타이머 틱이고 판정은 [on_tick]이 합니다. 타이머는 전환할 때 -//! 다시 걸지 않으므로, 틱이 실행 중인 태스크를 무조건 끊으면 틱 직전에 양보한 -//! 태스크가 뒤에 선 태스크에게 주기의 끝자락만 주고 다음 주기를 통째로 다시 -//! 받습니다. 그래서 틱과 틱 사이에 CPU를 받은 태스크는 처음 맞는 틱 하나를 -//! 넘깁니다. 틱의 판정으로 CPU를 받은 태스크는 주기의 처음에 들어온 것이라 -//! 다음 틱에서 끊깁니다. 어느 쪽이든 CPU를 받은 태스크는 스스로 내놓지 않는 -//! 한 온전한 한 주기 전에는 끊기지 않습니다. 규칙 자체는 k0-slice 크레이트에 -//! 있고 호스트에서 시험합니다. 여기서는 현재 태스크가 바뀌는 유일한 자리인 -//! `switch_to`가 들어온 경위를 규칙에 알려 줍니다. 깨어나는 것만으로는 면제가 -//! 생기지 않습니다(깨어난 태스크는 준비 큐의 끝에 설 뿐임). +//! 커널 heap 없이 TCB에 내장된 링크(intrusive list)로 큐를 만듭니다. 큐 노드 +//! 할당이 없어 큐 길이가 태스크 수로 자연히 상한되므로 스케줄러가 커널 자원 +//! 고갈의 원인이 되지 못합니다. 이양(handoff) 후 커널은 예외 컨텍스트에서만 +//! 실행되고, 벡터가 사용자 컨텍스트를 현재 TCB에 저장한 상태에서 전환이 +//! 일어나므로 전환은 포인터 갱신과 TTBR0 교체(주소 공간이 다를 때만, ASID +//! 미사용이라 전체 TLB 무효화 동반)로 끝납니다. 도메인이 바뀔 때는 주소 공간이 +//! 같아도 TLB를 비웁니다. //! -//! 기한이 있는 IPC 대기자는 준비 큐나 대기 큐와 별개인 기한 목록에도 -//! 들어갑니다([arm_timeout]). 블록된 태스크가 블록 상태를 벗어나는 길은 -//! 깨어남([enqueue])과 종료(k0-ipc의 teardown) 둘뿐이고 둘 다 태스크를 이 -//! 목록에서 빼므로, 목록에는 지금 블록돼 있는 태스크만 남습니다. 목록은 -//! 정렬하지 않습니다. 틱마다 [expired]가 부르지만, 가장 이른 기한이 아직 오지 -//! 않았으면 목록을 훑지 않습니다. 훑는 비용은 기한을 건 대기자 수에 -//! 비례하고 그 수는 TCB 수를 넘지 못합니다. +//! 도메인에 관한 규칙은 다음과 같습니다. +//! +//! - 깨어나는 태스크는 자기 도메인의 큐에만 들어갑니다([enqueue]가 TCB에서 +//! 도메인을 읽음). 다른 도메인이 도는 중에 깨어나도 실행은 자기 창에서 +//! 합니다. +//! - 기한 목록도 도메인마다 따로 있고, 기한이 지났는지는 그 도메인이 도는 +//! 틱에서만 봅니다([expired]). 그래서 타임아웃은 늦게 올 수는 있어도 일찍 +//! 오지는 않고, 한 도메인의 대기자 수가 다른 도메인의 틱 처리 시간을 바꾸지 +//! 못합니다. +//! - 도는 도메인에 준비된 태스크가 없으면 커널은 기다립니다. 다른 도메인의 +//! 태스크를 대신 실행하지 않습니다. +//! +//! 상태는 둘로 나뉩니다. `CORE`(판정 상태)는 사건 함수만 만지고, 한 사건이 +//! 끝나기 전에 다른 사건이 들어오면 정지합니다. `Q`(큐, 기한 목록, 현재 +//! 태스크)는 함수 하나가 도는 동안만 빌립니다. 틱 사건 도중에 도는 도메인의 +//! 일(콘솔 깨우기, 타임아웃)을 하는 콜백이 [enqueue]로 다시 들어오기 때문에, +//! 콜백을 부르는 동안에는 `Q`에 대한 참조를 들고 있지 않습니다. +//! +//! 지켜지는 불변식은 다음과 같습니다. +//! +//! - 상태가 Running인 TCB는 `Q.current`이고 `Core`의 실행 중 태스크입니다. +//! - `Core`에 실행 중 태스크가 없으면(커널이 기다리는 중) Running인 TCB도 +//! 없습니다. 그동안 `Q.current`는 마지막으로 설치한 태스크를 가리킨 채 +//! 남는데, "이 태스크가 현재 태스크인가"의 판정과 벡터가 복원할 컨텍스트로만 +//! 쓰입니다. `current`를 바꾸는 자리는 `Env::run` 하나입니다. +//! - TCB의 도메인은 그 TCB가 어느 목록에든 들어 있는 동안 바뀌지 않습니다 +//! (구성은 Inactive에서만, 도메인 지정은 Stopped에서만 허용됨). //! //! # Errors //! 전환 대상이 없으면 현재 태스크가 그대로 계속됩니다(에러 아님). 현재 -//! 태스크가 종료됐거나 블록됐는데 준비된 태스크가 없으면 -//! [block_and_switch]가 false를 반환하고, 호출자(커널 정책)는 다음 -//! 인터럽트를 기다렸다가 다시 시도합니다. 기한 목록의 링크가 어긋나 있으면 +//! 태스크가 종료됐거나 블록됐는데 그 도메인에 준비된 태스크가 없으면 +//! [block_and_switch]가 false를 반환하고, 호출자(커널 정책)는 다음 인터럽트를 +//! 기다렸다가 [poll]을 부릅니다. 기한 목록의 링크가 어긋나 있거나, 태스크가 +//! 자기 도메인이 아닌 큐에 들어가려 하거나, 사건이 겹쳐 들어오면 //! `k0_arch::fatal`로 정지합니다. #![no_std] use core::cell::UnsafeCell; +use core::sync::atomic::{AtomicBool, Ordering}; -use k0_slice::{Entry, Slice, Verdict}; +use k0_part::{Core, Env, Next, MAX_DOMAINS}; use k0_task::{TaskState, Tcb, TcbQueue}; -/// 스케줄러 상태 구조체입니다. `current`는 TCB의 커널 VA(0 = 없음)입니다. -struct Sched { +pub use k0_part::{Domain, Table, TableError}; + +/// 큐와 기한 목록, 설치된 태스크를 담는 구조체입니다. 값은 TCB의 커널 +/// VA(0 = 없음)입니다. +struct Queues { + /// 컨텍스트가 설치된 태스크. 커널이 기다리는 동안에는 Running이 아닐 수 + /// 있음 current: u64, - ready: TcbQueue, - /// 기한이 있는 대기자 목록의 머리(TCB의 커널 VA, 0 = 없음) - timed: u64, + /// 도메인별 준비 큐 + ready: [TcbQueue; MAX_DOMAINS], + /// 도메인별 기한 목록의 머리 + timed: [u64; MAX_DOMAINS], /// 목록에 든 기한 중 가장 이른 값의 하한. 대기자가 빠질 때는 고치지 /// 않으므로 실제보다 이를 수 있고(그러면 한 번 헛되이 훑을 뿐), 늦을 수는 /// 없음 - timed_min: u64, - /// 현재 태스크가 다음 틱 하나를 넘길 수 있는지. `current`를 바꾸는 자리 - /// (handoff와 switch_to)에서만 다시 정하고 [on_tick]만 씀 - slice: Slice, + timed_min: [u64; MAX_DOMAINS], } -struct SyncCell(UnsafeCell); +struct SyncCell(UnsafeCell); /// # Safety /// 부트 코어의 초기화 시퀀스와 이양 후의 예외 컨텍스트(단일 코어, 예외 /// 진입 시 DAIF 마스크)에서만 접근하므로 동시 접근이 없습니다. -unsafe impl Sync for SyncCell {} +unsafe impl Sync for SyncCell {} -static SCHED: SyncCell = SyncCell(UnsafeCell::new(Sched { +static Q: SyncCell = SyncCell(UnsafeCell::new(Queues { current: 0, - ready: TcbQueue::new(), - timed: 0, - timed_min: 0, - slice: Slice::new(), + ready: [const { TcbQueue::new() }; MAX_DOMAINS], + timed: [0; MAX_DOMAINS], + timed_min: [0; MAX_DOMAINS], })); -/// 준비 큐 꼬리에 TCB를 붙이는 함수입니다. +static CORE: SyncCell> = SyncCell(UnsafeCell::new(Core::new())); + +/// 사건 하나가 `CORE`를 쥐고 있는지 +static IN_EVENT: AtomicBool = AtomicBool::new(false); + +/// `CORE`를 쥐는 동안 살아 있는 표식 구조체입니다. /// -/// # Safety -/// `tcb`는 유효한 커널 VA의 TCB이고 큐에 없어야 합니다. -unsafe fn push(s: &mut Sched, tcb: *mut Tcb) { - // SAFETY: 함수 계약대로 tcb는 유효하고 큐 밖에 있음 - unsafe { - (*tcb).state = TaskState::Ready; - s.ready.push(tcb); +/// 참조를 만들기 전에 표식부터 세우므로, 사건이 겹쳐 들어와도 같은 상태에 +/// 대한 두 번째 참조가 생기기 전에 정지합니다. 놓는 것은 Drop이 합니다. +struct Event(()); + +impl Event { + fn begin() -> Self { + if IN_EVENT.swap(true, Ordering::Relaxed) { + k0_arch::fatal("scheduler event re-entered"); + } + Self(()) + } + + fn core(&mut self) -> &mut Core { + // SAFETY: 표식을 쥔 동안에는 다른 사건이 CORE에 닿지 못하고, 돌려주는 + // 참조의 수명이 이 표식의 빌림에 묶여 한 번에 하나만 존재함 + unsafe { &mut *CORE.0.get() } + } +} + +impl Drop for Event { + fn drop(&mut self) { + IN_EVENT.store(false, Ordering::Relaxed); } } -/// 준비 큐 머리를 꺼내는 함수입니다. 비어 있으면 0 +/// TCB가 속한 도메인을 읽는 함수입니다. /// /// # Safety -/// 큐의 링크들이 유효한 TCB를 가리켜야 합니다. -unsafe fn pop(s: &mut Sched) -> u64 { - // SAFETY: 함수 계약을 큐로 중계함 - unsafe { s.ready.pop() as u64 } +/// `tcb`는 유효한 TCB여야 합니다. +pub unsafe fn domain_of(tcb: *mut Tcb) -> Domain { + // SAFETY: 함수 계약대로 tcb는 유효함 + match Domain::new(unsafe { (*tcb).domain }) { + Some(d) => d, + None => k0_arch::fatal("task domain out of range"), + } } -/// 다음 태스크로 실행 문맥을 전환하는 함수입니다. -/// -/// 벡터의 복귀 경로(`__user_restore`)가 `__current_context`를 다시 읽기 -/// 때문에 포인터 갱신만으로 전환이 완성됩니다. -/// -/// 현재 태스크가 바뀌는 자리는 이 함수와 handoff뿐이므로 틱 면제도 여기서 -/// 정합니다. 경위를 인자로 반드시 받으며, 앞 태스크가 남긴 값은 버립니다. -/// -/// # Arguments -/// `next` - 준비 큐에서 꺼낸 TCB의 커널 VA -/// `how` - 그 태스크가 CPU를 받는 경위(틱의 판정인지, 틱 사이의 전환인지) +/// `Core`가 큐와 현재 태스크를 다루는 통로 구조체입니다. +/// +/// 태스크 값은 TCB의 커널 VA입니다. `Core`가 넘겨주는 값은 [handoff]가 준 루트 +/// TCB와 이 구조체의 `pop`이 큐에서 꺼낸 TCB뿐이라서 언제나 유효한 TCB입니다. +struct Kenv<'a> { + /// 도는 도메인의 일(콘솔 깨우기, 타임아웃)을 하는 콜백. 틱과 대기 루프의 + /// 사건에만 있음 + serve: Option<&'a mut dyn FnMut(Domain, u64)>, +} + +impl Kenv<'_> { + const fn bare() -> Self { + Self { serve: None } + } + + /// 태스크를 자기 도메인의 큐에 넣기 전에 확인하는 함수입니다. + fn check_home(d: Domain, t: u64) { + // SAFETY: 구조체 설명대로 t는 유효한 TCB임 + if unsafe { domain_of(t as *mut Tcb) } != d { + k0_arch::fatal("task queued outside its domain"); + } + } +} + +impl Env for Kenv<'_> { + fn now(&self) -> u64 { + k0_arch::irq::ticks() + } + + fn domain(&self, t: u64) -> Domain { + // SAFETY: 구조체 설명대로 t는 유효한 TCB임 + unsafe { domain_of(t as *mut Tcb) } + } + + fn push(&mut self, d: Domain, t: u64) { + Self::check_home(d, t); + // SAFETY: 예외 컨텍스트라 접근이 배타적이고, 이 빌림은 이 함수 안에서 + // 끝남. t는 유효하고 큐 밖에 있음(Core가 막 끊었거나 깨어남) + unsafe { push(&mut *Q.0.get(), d, t as *mut Tcb) }; + } + + fn push_front(&mut self, d: Domain, t: u64) { + Self::check_home(d, t); + let tcb = t as *mut Tcb; + // SAFETY: push와 같음 + unsafe { + let q = &mut *Q.0.get(); + (*tcb).state = TaskState::Ready; + q.ready[d.index()].push_front(tcb); + } + } + + fn pop(&mut self, d: Domain) -> Option { + // SAFETY: 접근이 배타적이고 큐 링크는 이 모듈만 만지므로 유효함 + let t = unsafe { (*Q.0.get()).ready[d.index()].pop() } as u64; + (t != 0).then_some(t) + } + + /// 현재 태스크를 바꾸는 유일한 자리입니다. 벡터의 복귀 경로 + /// (`__user_restore`)가 `__current_context`를 다시 읽기 때문에 포인터 + /// 갱신만으로 전환이 완성됩니다. + fn run(&mut self, t: u64) { + let tcb = t as *mut Tcb; + // SAFETY: 접근이 배타적이고 t는 유효한 TCB이며, 앞 태스크의 컨텍스트 + // 저장은 벡터가 끝냄 + unsafe { + (*tcb).state = TaskState::Running; + (*Q.0.get()).current = t; + k0_arch::usermode::set_current(&raw mut (*tcb).ctx); + // ASID를 쓰지 않으므로 주소 공간이 다를 때만 교체(전체 TLB 무효화 동반) + if (*tcb).ttbr0_pa != k0_mm::current_user_root() { + k0_mm::install_user_ttbr0((*tcb).ttbr0_pa); + } + } + } + + fn enter_domain(&mut self, _d: Domain) { + // 앞 도메인이 남긴 변환 캐시를 다음 도메인이 이어받지 않게 함 + k0_mm::flush_user_tlb(); + } + + fn serve(&mut self, d: Domain, now: u64) { + if let Some(f) = self.serve.as_mut() { + f(d, now); + } + } +} + +/// 사건 하나를 처리한 뒤에 타이머 쪽에 알리는 함수입니다. +/// +/// 분할 중인지(틱 줄을 낼지)와, 다음 틱에서 도메인이 바뀌어 인터럽트를 보호 +/// 구간만큼 일찍 걸어야 하는지를 알립니다. 틱 사건과 표를 바꾸는 사건 뒤에 +/// 부릅니다. +fn publish(core: &Core) { + k0_arch::irq::set_partitioned(core.partitioned()); + k0_arch::irq::guard_next(core.next_tick_switches()); +} + +/// 도메인 `d`의 준비 큐 꼬리에 TCB를 붙이는 함수입니다. /// /// # Safety -/// `next`는 준비 큐에서 나온 유효한 TCB여야 하고, 현재 태스크의 컨텍스트 -/// 저장이 끝난 예외 컨텍스트여야 합니다(벡터가 보장). -unsafe fn switch_to(s: &mut Sched, next: u64, how: Entry) { - s.slice.entered(how); - let t = next as *mut Tcb; - // SAFETY: 함수 계약대로 t는 유효한 TCB임 +/// `tcb`는 유효한 커널 VA의 TCB이고 큐에 없어야 하며 `d`가 그 TCB의 +/// 도메인이어야 합니다. +unsafe fn push(q: &mut Queues, d: Domain, tcb: *mut Tcb) { + // SAFETY: 함수 계약대로 tcb는 유효하고 큐 밖에 있음 unsafe { - (*t).state = TaskState::Running; - s.current = next; - k0_arch::usermode::set_current(&raw mut (*t).ctx); - // ASID를 쓰지 않으므로 주소 공간이 다를 때만 교체(전체 TLB 무효화 동반) - if (*t).ttbr0_pa != k0_mm::current_user_root() { - k0_mm::install_user_ttbr0((*t).ttbr0_pa); - } + (*tcb).state = TaskState::Ready; + q.ready[d.index()].push(tcb); } } @@ -133,22 +257,23 @@ unsafe fn switch_to(s: &mut Sched, next: u64, how: Entry) { /// # Safety /// `tcb`는 유효한 TCB이고, 기한이 있다면 목록의 링크들이 유효한 TCB를 /// 가리켜야 합니다. -unsafe fn disarm(s: &mut Sched, tcb: *mut Tcb) { +unsafe fn disarm(q: &mut Queues, tcb: *mut Tcb) { // SAFETY: 함수 계약대로 tcb와 그 이웃은 유효한 TCB임 unsafe { if (*tcb).deadline == 0 { return; } + let d = domain_of(tcb).index(); let me = tcb as u64; let next = (*tcb).tnext as *mut Tcb; let prev = (*tcb).tprev as *mut Tcb; - let prev_ok = if prev.is_null() { s.timed == me } else { (*prev).tnext == me }; + let prev_ok = if prev.is_null() { q.timed[d] == me } else { (*prev).tnext == me }; let next_ok = next.is_null() || (*next).tprev == me; if !prev_ok || !next_ok { k0_arch::fatal("timeout list corrupt"); } if prev.is_null() { - s.timed = next as u64; + q.timed[d] = next as u64; } else { (*prev).tnext = next as u64; } @@ -161,7 +286,7 @@ unsafe fn disarm(s: &mut Sched, tcb: *mut Tcb) { } } -/// 블록된 태스크에 기한을 걸어 기한 목록에 넣는 함수입니다. +/// 블록된 태스크에 기한을 걸어 그 도메인의 기한 목록에 넣는 함수입니다. /// /// # Arguments /// `tcb` - 방금 블록 상태가 된 TCB @@ -177,31 +302,44 @@ pub unsafe fn arm_timeout(tcb: *mut Tcb, deadline: u64) { // SAFETY: 함수 계약대로 접근이 배타적이고 tcb는 목록 밖의 유효한 TCB임. // 머리는 비었거나 유효한 TCB임 unsafe { - let s = &mut *SCHED.0.get(); + let q = &mut *Q.0.get(); if (*tcb).deadline != 0 { k0_arch::fatal("timeout armed twice"); } - let head = s.timed as *mut Tcb; + let d = domain_of(tcb).index(); + let head = q.timed[d] as *mut Tcb; (*tcb).deadline = deadline; (*tcb).tprev = 0; (*tcb).tnext = head as u64; if head.is_null() { - s.timed_min = deadline; + q.timed_min[d] = deadline; } else { (*head).tprev = tcb as u64; - s.timed_min = s.timed_min.min(deadline); + q.timed_min[d] = q.timed_min[d].min(deadline); } - s.timed = tcb as u64; + q.timed[d] = tcb as u64; } } -/// 기한을 건 대기자가 하나라도 있는지 알려 주는 함수입니다. +/// 기한을 건 대기자가 어느 도메인에든 하나라도 있는지 알려 주는 함수입니다. /// /// # Safety /// 시스템 콜/IRQ 컨텍스트(단일 코어, DAIF 마스크)에서만 호출해야 합니다. pub unsafe fn has_timed() -> bool { // SAFETY: 함수 계약대로 접근이 배타적임 - unsafe { (*SCHED.0.get()).timed != 0 } + unsafe { (*Q.0.get()).timed.iter().any(|&t| t != 0) } +} + +/// 준비 큐에 선 태스크가 어느 도메인에든 하나라도 있는지 알려 주는 함수입니다. +/// +/// 분할 중에는 도는 도메인에 준비된 태스크가 없어도 다른 도메인의 창이 오면 +/// 실행이 이어집니다. 커널이 영영 기다리게 됐는지는 모든 도메인을 봐야 압니다. +/// +/// # Safety +/// 시스템 콜/IRQ 컨텍스트(단일 코어, DAIF 마스크)에서만 호출해야 합니다. +pub unsafe fn has_ready() -> bool { + // SAFETY: 함수 계약대로 접근이 배타적임 + unsafe { (*Q.0.get()).ready.iter().any(|q| q.head != 0) } } /// TCB의 기한을 취소하는 함수입니다. 기한이 없으면 아무 일도 하지 않습니다. @@ -213,32 +351,38 @@ pub unsafe fn has_timed() -> bool { /// `tcb`는 유효한 TCB여야 합니다. pub unsafe fn disarm_timeout(tcb: *mut Tcb) { // SAFETY: 함수 계약대로 접근이 배타적이고 계약을 disarm으로 중계함 - unsafe { disarm(&mut *SCHED.0.get(), tcb) }; + unsafe { disarm(&mut *Q.0.get(), tcb) }; } -/// 기한이 지난 대기자를 목록에서 빼면서 하나씩 넘겨 주는 함수입니다. +/// 도메인 `d`에서 기한이 지난 대기자를 목록에서 빼면서 하나씩 넘겨 주는 +/// 함수입니다. /// /// 넘겨받은 쪽이 그 태스크를 대기 큐나 응답 링크에서 떼어 내고 [enqueue]로 /// 깨워야 합니다. 콜백이 스케줄러 상태를 다시 빌리므로 이 함수는 콜백을 /// 부르는 동안 스케줄러에 대한 참조를 들고 있지 않습니다. /// +/// 다른 도메인의 목록은 보지 않습니다. 그 도메인의 대기자는 그 도메인이 도는 +/// 틱에서 깨어납니다. +/// /// # Arguments +/// `d` - 지금 도는 도메인 /// `now` - 지금의 틱 수 /// `f` - 기한이 지난 TCB마다 한 번 불리는 콜백. 넘겨받은 TCB 외의 태스크를 /// 기한 목록에서 빼면 안 됨 /// /// # Safety /// 시스템 콜/IRQ 컨텍스트(단일 코어, DAIF 마스크)에서만 호출해야 합니다. -pub unsafe fn expired(now: u64, mut f: impl FnMut(*mut Tcb)) { +pub unsafe fn expired(d: Domain, now: u64, mut f: impl FnMut(*mut Tcb)) { + let d = d.index(); // SAFETY: 함수 계약대로 접근이 배타적이고 목록의 링크는 유효한 TCB임. // 다음 링크는 콜백 전에 읽어 두며, 콜백은 넘겨받은 TCB만 다룸 unsafe { let mut t = { - let s = &*SCHED.0.get(); - if s.timed == 0 || now < s.timed_min { + let q = &*Q.0.get(); + if q.timed[d] == 0 || now < q.timed_min[d] { return; } - s.timed as *mut Tcb + q.timed[d] as *mut Tcb }; // 남는 대기자들의 가장 이른 기한을 다시 구함 let mut earliest = u64::MAX; @@ -246,22 +390,22 @@ pub unsafe fn expired(now: u64, mut f: impl FnMut(*mut Tcb)) { let next = (*t).tnext as *mut Tcb; let deadline = (*t).deadline; if deadline <= now { - disarm(&mut *SCHED.0.get(), t); + disarm(&mut *Q.0.get(), t); f(t); } else { earliest = earliest.min(deadline); } t = next; } - (*SCHED.0.get()).timed_min = earliest; + (*Q.0.get()).timed_min[d] = earliest; } } /// 루트 태스크로 제어권을 이양하는 함수입니다. 복귀하지 않습니다. /// -/// 루트 태스크를 Running으로 등록하고 벡터의 EL0 경로가 저장/복원할 +/// 루트 태스크를 실행 중으로 등록하고 벡터의 EL0 경로가 저장/복원할 /// 컨텍스트를 지정한 뒤 EL0로 진입합니다. 이후 커널 코드는 예외로만 -/// 실행됩니다. +/// 실행됩니다. 분할 표는 기본 표(루트 도메인 하나)로 시작합니다. /// /// # Arguments /// `tcb` - 스폰을 마친 루트 태스크의 TCB @@ -270,22 +414,31 @@ pub unsafe fn expired(now: u64, mut f: impl FnMut(*mut Tcb)) { /// TCB의 주소 공간(TTBR0)이 설치된 뒤에만 호출해야 합니다. 커널의 identity /// 의존이 남아 있으면 안 됩니다(호출 순서는 kernel_main이 강제). pub unsafe fn handoff(tcb: &'static mut Tcb) -> ! { - tcb.state = TaskState::Running; - // SAFETY: 이양 직전의 단일 부트 코어라 접근이 배타적임 - let s = unsafe { &mut *SCHED.0.get() }; - s.current = core::ptr::from_mut(tcb) as u64; - // 부팅 중에도 타이머는 돌고 있어서 루트 태스크는 주기의 중간에 들어옴 - s.slice.entered(Entry::Between); - k0_arch::usermode::set_current(&raw mut tcb.ctx); + let t = core::ptr::from_mut(tcb); + // SAFETY: t는 방금 받은 유효한 TCB임 + if unsafe { domain_of(t) } != Domain::ROOT { + k0_arch::fatal("root task outside the root domain"); + } + // 틱 번호를 읽는 것과 EL0 진입 사이에 타이머 인터럽트가 끼면 틱 번호만 + // 오르고 스케줄러는 그 틱을 보지 못함(커널 문맥의 틱은 사건을 만들지 + // 않음). 그러면 첫 틱까지 "마지막으로 처리한 틱"이 틱 번호보다 하나 + // 뒤처져, 그 사이에 정한 표가 한 틱 일찍 시작하고 보호 구간도 걸리지 않음. + // 먼저 막아 두면 그 틱은 EL0에 들어간 직후에 평소의 틱 사건으로 들어옴 + k0_arch::irq::mask_all(); + { + let mut ev = Event::begin(); + ev.core().start(&mut Kenv::bare(), t as u64); + } // SAFETY: 함수 계약대로 컨텍스트와 주소 공간이 준비된 발산 경로에서 호출됨 unsafe { k0_arch::usermode::enter_user() } } -/// TCB를 준비 큐에 넣어 실행 대상으로 만드는 함수입니다. +/// TCB를 자기 도메인의 준비 큐에 넣어 실행 대상으로 만드는 함수입니다. /// /// 구성(TCB_CONFIGURE)을 마친 태스크의 첫 진입과 IPC 블록에서 깨어나는 /// 태스크가 같은 경로를 씁니다. 깨어나는 태스크에 기한이 걸려 있었다면 /// 여기서 취소되므로, 지나간 대기의 기한이 나중의 대기를 끝내는 일은 +/// 없습니다. 큐는 TCB에 적힌 도메인으로 정해지고 부르는 쪽이 고를 수 /// 없습니다. /// /// # Arguments @@ -295,115 +448,106 @@ pub unsafe fn handoff(tcb: &'static mut Tcb) -> ! { /// 시스템 콜/IRQ 컨텍스트(단일 코어, DAIF 마스크)에서만 호출해야 하고, /// `tcb`는 유효한 TCB이며 큐에 없고 실행 중(Running)이 아니어야 합니다. pub unsafe fn enqueue(tcb: *mut Tcb) { - // SAFETY: 함수 계약대로 접근이 배타적임 - let s = unsafe { &mut *SCHED.0.get() }; - // SAFETY: 함수 계약을 disarm과 push로 중계함 + // SAFETY: 함수 계약대로 접근이 배타적이고 계약을 disarm과 push로 중계함 unsafe { - disarm(s, tcb); - push(s, tcb); + let q = &mut *Q.0.get(); + disarm(q, tcb); + push(q, domain_of(tcb), tcb); } } -/// 현재 태스크를 큐 꼬리로 돌리고 준비 큐의 머리를 실행하는 함수입니다. -/// 준비된 다른 태스크가 없으면 아무 일도 하지 않고 false를 줍니다. -/// -/// # Arguments -/// `how` - 머리의 태스크가 CPU를 받는 경위 -/// -/// # Safety -/// 시스템 콜/IRQ 컨텍스트에서 벡터의 컨텍스트 저장이 끝난 뒤에만 호출해야 -/// 하고, 현재 태스크는 실행 중(Running)이어야 합니다. -unsafe fn rotate_as(s: &mut Sched, how: Entry) -> bool { - // SAFETY: 큐 링크는 이 모듈만 만지므로 유효함 - let next = unsafe { pop(s) }; - if next == 0 { - return false; - } - let cur = s.current; - // SAFETY: current는 handoff/switch_to가 유지하는 유효한 TCB이고 next는 - // 방금 큐에서 나옴 - unsafe { - push(s, cur as *mut Tcb); - switch_to(s, next, how); - } - true -} - /// 현재 태스크가 CPU를 내놓는 함수입니다(YIELD). /// -/// 현재 태스크를 큐 꼬리로 돌리고 다음 태스크를 실행합니다. 준비된 다른 -/// 태스크가 없으면 아무 일도 하지 않고 현재 태스크가 계속되며, 그때는 틱 -/// 면제도 생기거나 사라지지 않습니다. 넘겨받은 태스크는 주기의 중간에 -/// 들어오므로 처음 맞는 틱 하나를 넘깁니다. +/// 같은 도메인에 준비된 다른 태스크가 있으면 현재 태스크를 큐 꼬리로 돌리고 +/// 그 태스크를 실행합니다. 없으면 아무 일도 하지 않고 현재 태스크가 계속되며, +/// 그때는 틱 면제도 생기거나 사라지지 않습니다. 넘겨받은 태스크는 주기의 +/// 중간에 들어오므로 처음 맞는 틱 하나를 넘깁니다. /// /// # Safety /// 시스템 콜 컨텍스트에서 벡터의 컨텍스트 저장이 끝난 뒤에만 호출해야 /// 합니다. pub unsafe fn rotate() { - // SAFETY: 함수 계약대로 접근이 배타적이고 계약을 rotate_as로 중계함 - unsafe { - let _ = rotate_as(&mut *SCHED.0.get(), Entry::Between); - } + let mut ev = Event::begin(); + ev.core().yield_now(&mut Kenv::bare()); } -/// 실행 중인 태스크를 끊고 들어온 타이머 틱을 판정하는 함수입니다. +/// EL0에서 들어온 타이머 틱을 처리하는 함수입니다. 실행할 태스크가 있으면 +/// true를 줍니다. /// -/// 현재 태스크가 틱 사이에 CPU를 받았고 그 뒤로 틱을 맞은 적이 없으면 이번 -/// 틱은 그 면제를 쓰는 것으로 끝나고 현재 태스크가 계속됩니다. 그렇지 않으면 -/// 현재 태스크를 큐 꼬리로 돌리고 다음 태스크를 실행합니다(준비된 태스크가 -/// 없으면 그대로 계속). 틱에서 CPU를 받은 태스크는 주기의 처음에 들어온 -/// 것이므로 면제가 없습니다. +/// 도는 도메인이 그대로면 그 도메인의 일(`serve`)을 한 뒤 현재 태스크를 끊을지 +/// 판정합니다. 틱과 틱 사이에 CPU를 받은 태스크는 처음 맞는 틱 하나를 넘기고, +/// 틱의 판정으로 받은 태스크는 다음 틱에서 끊깁니다. 창의 경계면 현재 태스크에 +/// 같은 규칙을 적용해 자기 도메인 큐에 세워 두고, 들어오는 도메인의 일을 한 뒤 +/// 그 도메인의 큐 머리를 실행합니다. /// -/// 틱마다 정확히 한 번, 기한이 지난 대기자를 깨운 뒤에 불러야 합니다. 커널이 -/// 실행할 태스크 없이 기다리는 동안의 틱에는 부르지 않습니다(그때는 끊을 -/// 태스크가 없고, 깨어난 태스크는 [resume_from_idle]이 들여보냄). +/// # Arguments +/// `serve` - 도메인 하나의 밀린 일(콘솔 깨우기, 그다음 타임아웃)을 하는 +/// 콜백. 그 도메인의 태스크만 깨워야 함 +/// +/// # Errors +/// 들어온 도메인에 준비된 태스크가 없으면 false를 반환합니다. 끊긴 태스크는 +/// 이미 자기 큐에 서 있으므로 호출자는 EL0로 돌아가지 말고 인터럽트를 +/// 기다렸다가 [poll]을 불러야 합니다 /// /// # Safety /// EL0에서 진입한 IRQ의 핸들러에서 벡터의 컨텍스트 저장이 끝난 뒤에만 -/// 호출해야 합니다(현재 태스크가 실행 중이던 문맥). -pub unsafe fn on_tick() { - // SAFETY: 함수 계약대로 접근이 배타적임 - let s = unsafe { &mut *SCHED.0.get() }; - if s.slice.on_tick() == Verdict::Keep { - return; - } - // SAFETY: 함수 계약을 rotate_as로 중계함 - unsafe { - let _ = rotate_as(s, Entry::Tick); - } +/// 호출해야 합니다(현재 태스크가 실행 중이던 문맥). `serve`는 이 크레이트의 +/// 사건 함수를 부르면 안 됩니다([enqueue]와 기한 함수는 됨). +pub unsafe fn on_tick(serve: &mut dyn FnMut(Domain, u64)) -> bool { + let mut ev = Event::begin(); + let core = ev.core(); + let next = core.tick(&mut Kenv { serve: Some(serve) }); + publish(core); + matches!(next, Next::Run(_)) } -/// 현재 실행 중인 태스크의 TCB 포인터를 주는 함수입니다. +/// 실행할 태스크 없이 기다리던 커널이 인터럽트를 받은 뒤에 부르는 +/// 함수입니다. 실행할 태스크가 생겼으면 true를 줍니다. +/// +/// 기다리는 동안 틱이 지나갔으면 틱 사건과 같습니다. 그때 들어오는 태스크는 +/// 주기의 처음에 들어오므로 틱 면제가 없습니다. 틱 없이 깨어났으면(콘솔 입력) +/// 도는 도메인의 일을 하고, 준비된 태스크는 주기의 중간에 들어오는 것이라 +/// 면제를 받습니다. 틱이 지나갔는지는 틱 번호를 보고 여기서 판단합니다. +/// +/// 도메인이 바뀌는 틱은 보호 구간만큼 일찍 처리됩니다. 들어온 도메인이 비어 +/// 있다가 그 구간 안에 입력으로 깨어난 태스크는 틱의 예정 시각에 시작하면서도 +/// 틱 사이에 들어온 것으로 쳐서 면제를 받습니다. 틱 바로 뒤에 깨어난 태스크와 +/// 같은 대우이고, 그 차이는 깨어난 태스크의 도메인 안에만 남습니다. +/// +/// 블록된 채로 기다리던 태스크 자신이 준비 큐에 돌아와 있으면 그 태스크로 +/// 전환합니다(같은 컨텍스트로 복귀). +/// +/// # Arguments +/// `serve` - [on_tick]과 같음 +/// +/// # Errors +/// 도는 도메인에 준비된 태스크가 없으면 false를 반환합니다. 호출자는 다음 +/// 인터럽트를 기다렸다가 다시 불러야 합니다 /// /// # Safety -/// 이양 후의 시스템 콜/IRQ 컨텍스트에서만 호출해야 합니다(그 전에는 0). -pub unsafe fn current() -> *mut Tcb { - // SAFETY: 함수 계약대로 접근이 배타적임 - let s = unsafe { &mut *SCHED.0.get() }; - s.current as *mut Tcb +/// [on_tick]과 같되, 커널이 실행할 태스크 없이 기다리던 문맥이어야 합니다. +pub unsafe fn poll(serve: &mut dyn FnMut(Domain, u64)) -> bool { + let mut ev = Event::begin(); + let core = ev.core(); + let next = core.poll(&mut Kenv { serve: Some(serve) }); + publish(core); + matches!(next, Next::Run(_)) } -/// 현재 태스크를 준비 큐에 되돌리지 않고 준비 큐의 머리로 전환하는 -/// 함수입니다. 준비된 태스크가 없으면 false를 줍니다. +/// 현재 설치된 태스크의 TCB 포인터를 주는 함수입니다. /// -/// # Arguments -/// `how` - 머리의 태스크가 CPU를 받는 경위 +/// 시스템 콜과 폴트의 문맥에서는 그 진입을 일으킨 태스크입니다. 커널이 실행할 +/// 태스크 없이 기다리는 동안에는 마지막으로 설치된 태스크입니다. /// /// # Safety -/// [rotate]와 동일합니다. -unsafe fn switch_next(s: &mut Sched, how: Entry) -> bool { - // SAFETY: 큐 링크는 유효함 - let next = unsafe { pop(s) }; - if next == 0 { - return false; - } - // SAFETY: next는 방금 큐에서 나온 유효한 TCB임 - unsafe { switch_to(s, next, how) }; - true +/// 이양 후의 시스템 콜/IRQ 컨텍스트에서만 호출해야 합니다(그 전에는 0). +pub unsafe fn current() -> *mut Tcb { + // SAFETY: 함수 계약대로 접근이 배타적임 + unsafe { (*Q.0.get()).current as *mut Tcb } } -/// 블록 표시를 마친(또는 종료된) 현재 태스크를 두고 다음 태스크로 전환하는 -/// 함수입니다. +/// 블록 표시를 마친(또는 종료된) 현재 태스크를 두고 같은 도메인의 다음 +/// 태스크로 전환하는 함수입니다. /// /// 현재 태스크를 준비 큐에 되돌리지 않는 것이 [rotate]와의 차이입니다. /// 호출 전에 현재 태스크를 깨울 주체(엔드포인트 대기 큐나 수신자의 reply @@ -414,42 +558,21 @@ unsafe fn switch_next(s: &mut Sched, how: Entry) -> bool { /// 선 태스크의 몫을 줄이는 길이 막힙니다. /// /// # Errors -/// 준비된 태스크가 없으면 false를 반환합니다. 호출자는 인터럽트를 기다렸다가 -/// [resume_from_idle]을 불러야 합니다 +/// 같은 도메인에 준비된 태스크가 없으면 false를 반환합니다. 다른 도메인에 +/// 준비된 태스크가 있어도 넘어가지 않습니다. 호출자는 인터럽트를 기다렸다가 +/// [poll]을 불러야 합니다 /// /// # Safety /// [rotate]와 동일합니다. pub unsafe fn block_and_switch() -> bool { - // SAFETY: 함수 계약대로 접근이 배타적이고 계약을 switch_next로 중계함 - unsafe { switch_next(&mut *SCHED.0.get(), Entry::Between) } -} - -/// 실행할 태스크 없이 기다리던 커널이 준비된 태스크로 전환하는 함수입니다. -/// -/// 블록된 채로 기다리던 현재 태스크 자신이 준비 큐에 돌아와 있으면 그 -/// 태스크로 전환합니다(같은 컨텍스트로 복귀). -/// -/// 기다리는 동안 틱이 지나갔으면 그 태스크는 틱 처리 직후, 곧 주기의 처음에 -/// 들어오므로 틱 면제가 없습니다. 틱 없이 깨어났으면(콘솔 입력) 주기의 중간에 -/// 들어오는 것이라 면제를 받습니다. -/// -/// # Arguments -/// `tick_seen` - 마지막으로 전환을 시도한 뒤로 틱이 지나갔는지 -/// -/// # Errors -/// 준비된 태스크가 없으면 false를 반환합니다. 호출자는 다음 인터럽트를 -/// 기다렸다가 다시 불러야 합니다 -/// -/// # Safety -/// [rotate]와 동일합니다. -pub unsafe fn resume_from_idle(tick_seen: bool) -> bool { - // SAFETY: 함수 계약대로 접근이 배타적이고 계약을 switch_next로 중계함 - unsafe { switch_next(&mut *SCHED.0.get(), Entry::after_idle(tick_seen)) } + let mut ev = Event::begin(); + matches!(ev.core().block(&mut Kenv::bare()), Next::Run(_)) } /// 준비 큐에 있는 TCB를 큐에서 빼내는 함수입니다. /// /// 준비 상태의 태스크가 종료 처리될 때 씁니다. 상태는 호출자가 바꿉니다. +/// 창의 경계에서 끊겨 다른 도메인의 큐에 서 있는 태스크도 같은 길로 빠집니다. /// /// # Errors /// 큐 링크가 어긋나 있으면 false를 반환합니다. 큐 손상이므로 호출자는 @@ -459,10 +582,11 @@ pub unsafe fn resume_from_idle(tick_seen: bool) -> bool { /// 시스템 콜 컨텍스트여야 하고 `tcb`는 준비 큐에 든 유효한 TCB여야 합니다. #[must_use] pub unsafe fn remove_ready(tcb: *mut Tcb) -> bool { - // SAFETY: 함수 계약대로 접근이 배타적임 - let s = unsafe { &mut *SCHED.0.get() }; - // SAFETY: 함수 계약을 큐로 중계함 - unsafe { s.ready.remove(tcb) } + // SAFETY: 함수 계약대로 접근이 배타적이고 계약을 큐로 중계함 + unsafe { + let d = domain_of(tcb).index(); + (*Q.0.get()).ready[d].remove(tcb) + } } /// 현재 태스크가 이번 커널 진입 중에 종료됐는지 확인하는 함수입니다. @@ -472,8 +596,56 @@ pub unsafe fn remove_ready(tcb: *mut Tcb) -> bool { pub unsafe fn current_is_dead() -> bool { // SAFETY: 함수 계약대로 접근이 배타적이고 current는 유효한 TCB임. 종료된 // TCB의 메모리도 이번 커널 진입이 끝날 때까지는 재사용되지 않음 - unsafe { - let s = &mut *SCHED.0.get(); - (*(s.current as *mut Tcb)).state == TaskState::Dead - } + unsafe { (*current()).state == TaskState::Dead } +} + +/// 새 분할 표를 정하는 함수입니다. +/// +/// 표는 지금 틱의 두 틱 뒤에 0번 항목부터 효력이 생깁니다. 다음 틱은 지금의 +/// 계획을 따릅니다. 다만 이 호출이 아직 시작하지 않은 보류 표를 갈아 끼우면 +/// 다음 틱의 도메인이 달라질 수 있으므로, 다음 틱을 일찍 받을지를 호출 끝에 +/// 다시 정합니다. 그때 이미 보호 구간 안이면 그 틱 한 번은 구간이 짧습니다. +/// +/// # Arguments +/// `table` - 형식 검사를 마친 표 +/// +/// # Safety +/// 시스템 콜 컨텍스트에서만 호출해야 합니다. +pub unsafe fn set_table(table: Table) { + let mut ev = Event::begin(); + let core = ev.core(); + core.set_table(table); + publish(core); +} + +/// 지금 도는 도메인을 주는 함수입니다. +/// +/// # Safety +/// 이양 후의 시스템 콜/IRQ 컨텍스트에서만 호출해야 하고, 사건 함수의 콜백 +/// 안에서 부르면 안 됩니다. +pub unsafe fn running_domain() -> Domain { + Event::begin().core().running_domain() +} + +/// 분할 표(또는 보류 중인 표)가 기본 표가 아닌지 알려 주는 함수입니다. +/// +/// # Safety +/// [running_domain]과 같습니다. +pub unsafe fn partitioned() -> bool { + Event::begin().core().partitioned() +} + +/// 아직 시작하지 않은 태스크의 도메인을 정하는 함수입니다. +/// +/// # Arguments +/// `tcb` - Inactive 또는 Stopped 상태의 TCB +/// `d` - 새 도메인 +/// +/// # Safety +/// 시스템 콜 컨텍스트여야 하고, `tcb`는 유효한 TCB이며 준비 큐에도 대기 큐에도 +/// 기한 목록에도 없어야 합니다(목록은 도메인마다 따로라서, 들어 있는 채로 +/// 도메인이 바뀌면 빼낼 때 엉뚱한 목록을 보게 됨). +pub unsafe fn assign(tcb: *mut Tcb, d: Domain) { + // SAFETY: 함수 계약대로 tcb는 유효하고 어느 목록에도 없음 + unsafe { (*tcb).domain = d.id() }; } diff --git a/crates/k0-task/src/lib.rs b/crates/k0-task/src/lib.rs index 012e5bb..2897d01 100644 --- a/crates/k0-task/src/lib.rs +++ b/crates/k0-task/src/lib.rs @@ -110,6 +110,13 @@ pub const TCB_SLOTS: usize = 3; /// 큐에 선 채로 이 목록에도 들어 있습니다. 태스크가 깨어나거나 종료되면 /// 스케줄러가 목록에서 빼고 `deadline`을 0으로 되돌립니다. /// +/// `domain`은 이 태스크가 속한 시간 분할 도메인의 번호입니다. 0이 루트 +/// 도메인이고, 소거된 프레임이 그대로 루트 도메인의 TCB입니다. 구성 +/// (TCB_CONFIGURE) 때 구성한 태스크의 도메인을 물려받고, 시작하기 전에만 +/// 제어 케이퍼빌리티로 바꿀 수 있습니다. 준비 큐와 기한 목록이 도메인마다 +/// 따로 있으므로, TCB가 어느 목록에든 들어 있는 동안에는 이 값이 바뀌지 +/// 않아야 합니다. +/// /// `slots`는 이 태스크에 묶인 케이퍼빌리티입니다. [TCB_SLOT_CSPACE]의 /// CNode가 이 태스크의 시스템 콜이 슬롯 번호를 해석하는 유일한 장소이고, /// [TCB_SLOT_VSPACE]의 AddrSpace가 이 태스크가 실행되는 주소 공간입니다. @@ -125,6 +132,7 @@ pub struct Tcb { pub ctx: Context, pub ttbr0_pa: u64, pub state: TaskState, + pub domain: u8, pub next: u64, pub prev: u64, pub reply_to: u64, @@ -184,6 +192,9 @@ impl Tcb { const _: () = assert!(size_of::() <= 4096); // 재분류된 TCB는 그래뉼 프레임 하나에 들어가야 함 const _: () = assert!(size_of::() <= GRANULE); +// domain은 state 바로 뒤의 채움 바이트에 들어가 TCB의 크기를 바꾸지 않음 +const _: () = assert!(core::mem::offset_of!(Tcb, domain) == core::mem::offset_of!(Tcb, state) + 1); +const _: () = assert!(core::mem::offset_of!(Tcb, next) == core::mem::offset_of!(Tcb, state) + 8); /// TCB의 intrusive 이중 연결 큐 구조체입니다. /// @@ -220,6 +231,28 @@ impl TcbQueue { self.tail = tcb as u64; } + /// 큐 머리에 TCB를 끼워 넣는 함수입니다. + /// + /// 창의 경계에서 끊긴 태스크를 자기 도메인 큐의 맨 앞에 세워 둘 때 + /// 씁니다. + /// + /// # Safety + /// `tcb`는 유효한 커널 VA의 TCB이고 어느 큐에도 없어야 합니다. 큐의 + /// 링크들이 유효한 TCB를 가리켜야 합니다. + pub unsafe fn push_front(&mut self, tcb: *mut Tcb) { + // SAFETY: 함수 계약대로 tcb는 유효하고 큐 밖에 있으며 head는 유효함 + unsafe { + (*tcb).prev = 0; + (*tcb).next = self.head; + if self.head == 0 { + self.tail = tcb as u64; + } else { + (*(self.head as *mut Tcb)).prev = tcb as u64; + } + } + self.head = tcb as u64; + } + /// 큐 머리를 꺼내는 함수입니다. 비어 있으면 null /// /// # Safety diff --git a/design/en/README.md b/design/en/README.md index 2fb9842..d2ad422 100644 --- a/design/en/README.md +++ b/design/en/README.md @@ -23,9 +23,11 @@ Read them in the order of the following table the first time. This order follows | [uefi.md](uefi.md) | The UEFI loader: why it sits outside the kernel, its flow, which memory it refuses to call RAM, the device tree rewrite, the self-check before the jump, what QEMU cannot test, and what has been booted | | [hardening.md](hardening.md) | PAC key derivation, PAN, closing EL0 access to counters, debug and PMU, and the root task integrity check, including what each does not protect yet | | [exceptions.md](exceptions.md) | The vector table, saving user state, system call dispatch, and fault isolation | -| [scheduling.md](scheduling.md) | TCBs and their bound CNode and address space, task creation and teardown, the round-robin scheduler, and timer preemption, including the rule that a task switched in between two ticks is not cut by the first tick it meets | +| [scheduling.md](scheduling.md) | TCBs and their bound CNode and address space, task creation and teardown, the round-robin scheduler, and timer preemption, including the rule that a task switched in between two ticks is not cut by the first tick it meets. Fixed time partitions: domains and the table, windows, the tick clock, the guard and the hold, the control capability and its two system calls, what is tested and what is proved about a model, and the limits of the claim | | [ipc.md](ipc.md) | Endpoints and badges, `SEND`, `RECV`, `CALL` and `REPLY_RECV`, the single-use reply right, and what happens to waiting tasks when an endpoint is deleted | | [vault.md](vault.md) | The signing oracle: the vault task and its frames, the `CALL` protocol and nonce, the fixed badge policy, the provider boundary, the boot seed and its wipe, features, tests, and known gaps | | [terminal.md](terminal.md) | Serial input and the operator terminal: why the kernel receives, the receive ring and its bounds, `CONSOLE_READ` and the Console rights, waiting and waking, the terminal's wiring and the hostile-task check, the screen and command rules, tests, and known gaps | Every note ends with a "**Known gaps**" section. The open security advisories are listed in [SECURITY.md](../../SECURITY.md). + +The Lean 4 proofs about a model of the partition scheduler are outside these notes, in [proofs/lean/README.md](../../proofs/lean/README.md). They are proofs about a model, not about the Rust code. diff --git a/design/en/boot.md b/design/en/boot.md index 6bd7fb9..cf107c0 100644 --- a/design/en/boot.md +++ b/design/en/boot.md @@ -112,16 +112,16 @@ In the following table, each row gives a log line and the step it stands for, in | `k0: console input on (pl011 irq 33)` or `k0: console input off ()` | Printed only by an image built with `console-input`, right after the platform is accepted. See "Optional console input". | | `k0: root task integrity ok (...)` | The embedded root task image is hashed again and compared with the hash fixed at build time. | | `k0: entropy ...`, `k0: pac=... bti=... pan=...` | PAC keys are derived and loaded, and the key words are wiped from the boot stack. The 32-byte seed for the root task is derived here too, independent of the PAC keys, and kept for the handoff. PAN is enabled and EL0 access to counters, debug and PMU is turned off. See [hardening.md](hardening.md). | -| `k0: irq on (timer 1s)` | `setup_irq` maps only the interrupt controller pages it needs. For GICv3 it looks at the redistributor frames one at a time to find the boot CPU's frame, then maps that frame and its SGI frame. The driver checks the GIC identification registers against what the DTB claimed. The EL1 virtual timer is programmed with the interrupt number from the platform descriptor. IRQ and SError are unmasked. | +| `k0: irq on (timer 1s)` | `setup_irq` maps only the interrupt controller pages it needs. For GICv3 it looks at the redistributor frames one at a time to find the boot CPU's frame, then maps that frame and its SGI frame. The driver checks the GIC identification registers against what the DTB claimed. The EL1 virtual timer is programmed with the interrupt number from the platform descriptor. The counter value read at this point is the instant of tick 0, and every later tick is due a whole number of seconds after it (see [scheduling.md](scheduling.md#the-tick-clock-and-skipped-ticks)). IRQ and SError are unmasked. | | `k0: kernel table pool N/40` | A 2 MiB boot frame window is chosen and mapped, then the number of kernel page tables in use is printed (for example `16/40` on QEMU virt). The static pool of 40 tables is used only during boot. | | `k0: root task loaded (entry ...)` | The root task is copied into frames from the window, its root TCB is made in the window, and its address space is built. The kernel does not print the physical address of the user root table. The address space is then entered in the address space registry. See [user-address-space.md](user-address-space.md). | -| `k0: memory + not handed out ()` (only when it happens), `k0: kernel reserve tables + address space entries = bytes in ranges` | `reserve_kernel_share` carves the kernel share out of each free physical range before any untyped capability exists (see "Carving the kernel share out of untyped memory"). A range that cannot hold its share is not handed out, and the kernel prints the first kind of line with the reason. The second line is printed once, for example `k0: kernel reserve 262 tables + 130130 address space entries = 0x206000 bytes in 3 ranges` on QEMU virt with 512 MiB and the 4 KiB granule. | -| `k0: untyped ...`, `k0: root cnode ready (N caps, N untyped, N image frames, N slots)` | The root CNode (an object in the window with `ROOT_CNODE_SLOTS` = 512 slots, as the log shows) is filled: slot 1 the root TCB, slot 2 the root address space, slot 3 the console, slot 4 the root CNode itself, then every free physical range that was handed out as an untyped capability, then one Frame capability per mapped granule of the root task image (text with R and X, read-only data with R, data with R and W). Finally the root task is bound to its CNode and address space, exactly as any other task is: copies of those two capabilities go into its TCB. See [capabilities.md](capabilities.md). | -| `k0: bootinfo page ready` | The capability list is written into the read-only bootinfo page (layout version 4): a header and one descriptor per slot, with the VA, size and rights of every image Frame. The page does not hold the boot seed. | +| `k0: memory + not handed out ()` (only when it happens), `k0: kernel reserve tables + address space entries = bytes in ranges` | `reserve_kernel_share` carves the kernel share out of each free physical range before any untyped capability exists (see "Carving the kernel share out of untyped memory"). A range that cannot hold its share is not handed out, and the kernel prints the first kind of line with the reason. The second line is printed once, for example `k0: kernel reserve 262 tables + 130124 address space entries = 0x206000 bytes in 3 ranges` on QEMU virt with 512 MiB and the 4 KiB granule. | +| `k0: untyped ...`, `k0: root cnode ready (N caps, N untyped, N image frames, N slots)` | The root CNode (an object in the window with `ROOT_CNODE_SLOTS` = 1024 slots in every image, as the log shows) is filled: slot 1 the root TCB, slot 2 the root address space, slot 3 the console, slot 4 the root CNode itself, slot 5 the control capability of the time partitions (`PartCtl`), then from slot 6 every free physical range that was handed out as an untyped capability, then one Frame capability per mapped granule of the root task image (text with R and X, read-only data with R, data with R and W). Finally the root task is bound to its CNode and address space, exactly as any other task is: copies of those two capabilities go into its TCB. See [capabilities.md](capabilities.md). | +| `k0: bootinfo page ready` | The capability list is written into the read-only bootinfo page (layout version 5): a header and one descriptor per slot, with the VA, size and rights of every image Frame. The page does not hold the boot seed. | | `k0: user w^x checks pass` | `TTBR0` now points at the user tables, the identity map is gone, and the user mappings are checked from both EL0 and EL1. | | `k0: dtb seeds wiped B` | The DTB is not needed any more, so the kernel zeroes the `rng-seed` and `kaslr-seed` bytes in it (through the read-only alias, switched to read-write for the write), reads them back, and wipes its own copy. The line is `40B` on QEMU virt. If the read-back is not zero, the line is `k0: WARNING dtb seeds not wiped`. See [hardening.md](hardening.md). | | `k0: device pages [...] of 0x1000 bytes` | Every device page the kernel keeps mapped. After this line the kernel maps no further device. | -| `k0: entering root task (el0)` | `k0_sched::handoff` enters EL0. The boot seed travels in the root task's entry registers `x0` to `x3`, with `x4` saying how many `rng-seed` bytes went in and whether `RNDR` did. Just after this line the kernel zeroes the boot stack below its live frames. | +| `k0: entering root task (el0)` | `k0_sched::handoff` masks interrupts, starts the scheduler with the default time partition table (one domain) and enters EL0. The boot seed travels in the root task's entry registers `x0` to `x3`, with `x4` saying how many `rng-seed` bytes went in and whether `RNDR` did. Just after this line the kernel zeroes the boot stack below its live frames. | | `root: boot seed from rng-seed bytes 0x... and rndr` or `... without rndr` | An early line of the root task, not of the kernel. After the bootinfo version check it prints where the seed material came from, never the seed. | ### Choosing the boot frame window @@ -152,7 +152,9 @@ This step **never refuses to boot**. The worst case is that memory is not handed The root task starts with the boot seed in its registers `x0` to `x3` and the seed info word in `x4`. These values are in its saved context, and the first time the root task enters the kernel, its own registers overwrite them. The kernel's copies of the seed on its stack were zeroed before, and the stack scrub described in the table above is best effort: the live frames of `kernel_main` cannot be cleared. See [hardening.md](hardening.md). -`handoff` records the root task as the running task and points the vector code at its saved context. `enter_user` then masks all exceptions (`DAIFSet`), rewinds the kernel stack to the top, and returns to EL0 through the same path every later return uses. **The mask comes first** because that path writes `ELR_EL1` and `SPSR_EL1` before `eret`. The boot path has already unmasked the timer, and an interrupt in between would overwrite both registers with EL1 values. From then on, kernel code runs only in response to an exception: a system call, a fault, or the timer interrupt. [exceptions.md](exceptions.md) describes that path. +`handoff` first masks interrupts and only then reads the tick number, records the root task as the running task and points the vector code at its saved context. The order matters: a tick counted between that read and the entry to EL0 would leave the scheduler one tick behind the timer. A tick that becomes pending meanwhile is taken right after the entry, as an ordinary tick. `enter_user` then masks all exceptions (`DAIFSet`), rewinds the kernel stack to the top, and returns to EL0 through the same path every later return uses. **The mask comes first** because that path writes `ELR_EL1` and `SPSR_EL1` before `eret`. The boot path has already unmasked the timer, and an interrupt in between would overwrite both registers with EL1 values. From then on, kernel code runs only in response to an exception: a system call, a fault, or the timer interrupt. [exceptions.md](exceptions.md) describes that path. + +The root task holds the control capability of the time partitions only during its self-tests. It tries the mechanism (`root: partition refusal pass`, `root: partition window pass`) and deletes the capability at the end (`root: partition sealed`). After that line the image runs with one domain and nothing can change that until the next boot (see [scheduling.md](scheduling.md#time-partitions)). ## The boot log diff --git a/design/en/capabilities.md b/design/en/capabilities.md index c9aa54b..f0d9f0b 100644 --- a/design/en/capabilities.md +++ b/design/en/capabilities.md @@ -23,7 +23,7 @@ The related code is in the files of the following table. | `crates/k0-abi/src/lib.rs` | numbers and error codes (the source of truth for the ABI) | > [!IMPORTANT] -> The system call ABI changed incompatibly with this model (bootinfo version 2, now 4). Read the "Known gaps" section before relying on any of this. +> The system call ABI changed incompatibly with this model (bootinfo version 2, now 5). Version 5 moved the first untyped slot, so a root task built for an earlier version does not run on this kernel. Read the "Known gaps" section before relying on any of this. Capability-based isolation covers confidentiality and integrity between tasks. It does not cover availability. @@ -67,6 +67,7 @@ In the following table, each kind is listed with the time it is created and what | `CNode` | by `RETYPE`, and at boot for the root CNode | an array of slots, used as a capability space and as a destination for copies and moves | | `AddrSpace` | by `RETYPE`, and at boot for the root task | an address space: the right to map into it and to run a task in it | | `Console` | at boot | the right to write bytes to the debug output (`W`): the boot log, and the console in an image built with a console driver. With `R` it also grants reading console input in an image built with `console-input` | +| `PartCtl` | at boot, exactly one | the right to set the time partition table and to put a task that has not run yet in a domain (see [scheduling.md](scheduling.md#time-partitions)). It names no object and cannot be copied | ### Rights @@ -106,7 +107,7 @@ Both are copies (children) of the capabilities given to `TCB_CONFIGURE` and are ## The root CNode and the boot capabilities -The root task's CNode is the root CNode. It has `ROOT_CNODE_SLOTS` (512) slots and lives in the 2 MiB boot frame window, together with the bootinfo page, the root TCB, and the root task's image, stack and page tables. None of these boot objects is untyped, so they can never be retyped. Boot capabilities are originals and each is the root (depth 0) of its own derivation list. +The root task's CNode is the root CNode. It has `ROOT_CNODE_SLOTS` (1024) slots in every image and lives in the 2 MiB boot frame window, together with the bootinfo page, the root TCB, and the root task's image, stack and page tables. None of these boot objects is untyped, so they can never be retyped. Boot capabilities are originals and each is the root (depth 0) of its own derivation list. `bootstrap` fills the root CNode in the order of the following table. @@ -117,7 +118,8 @@ The root task's CNode is the root CNode. It has `ROOT_CNODE_SLOTS` (512) slots a | 2 | `AddrSpace` of the root task | | 3 | `Console`, with `W`. It has `R` only in an image built with `console-input` | | 4 | `CNode`, a capability to the root CNode itself, so it can be used as a copy or move destination | -| 5 and up | `Untyped` capabilities, then one `Frame` capability per mapped granule of the root task image | +| 5 | `PartCtl`, the control capability of the time partitions | +| 6 and up | `Untyped` capabilities, then one `Frame` capability per mapped granule of the root task image | The image `Frame` capabilities have rights fixed by the segment: text is `R|X` (no `W`), read-only data is `R`, data is `R|W` (no `X`). The text frames are the only frames in the system that carry `X`, and their contents are the image whose hash was verified at boot. The root task's own boot mappings are permanent and are not represented by these capabilities. @@ -139,7 +141,7 @@ Running out of slots also stops the boot. A DTB memory region beyond the CPU's p ## The bootinfo page -Just before the handoff, the kernel writes a description of the root CNode into the bootinfo page, which is mapped read-only for the root task at `bootinfo::VA`. The version is 4 (`bootinfo::VERSION`). The page layout did not change from version 2. Version 3 came because the root task receives a boot seed in its entry registers (the seed in `x0..x3`, its description in `x4`; see [boot.md](boot.md)), and the seed is not in this page. Version 4 came because the `Console` capability now carries rights. A root task that sees another version must not proceed. +Just before the handoff, the kernel writes a description of the root CNode into the bootinfo page, which is mapped read-only for the root task at `bootinfo::VA`. The version is 5 (`bootinfo::VERSION`). The page layout did not change from version 2. Version 3 came because the root task receives a boot seed in its entry registers (the seed in `x0..x3`, its description in `x4`; see [boot.md](boot.md)), and the seed is not in this page. Version 4 came because the `Console` capability now carries rights. Version 5 came because slot 5 now holds `PartCtl`, so the first untyped capability moved from slot 5 to slot 6. A root task that sees another version must not proceed. The page starts with a header `{version, frame_size, cap_count, cnode_slots}`, followed by `cap_count` descriptors `{kind, base, size, rights}`. The index of a descriptor is its slot number in the root CNode, and every slot at or beyond `cap_count` is empty. A descriptor is filled in by kind as follows: @@ -147,7 +149,7 @@ The page starts with a header `{version, frame_size, cap_count, cnode_slots}`, f - **Image Frame**: `base` is the virtual address where the granule is mapped in the root address space, `size` is the frame size and `rights` the rights bits. - **Everything else**: all zero, so kernel object addresses are not exposed. The kernel also no longer prints the root page table's physical address. -The page is a snapshot. Capabilities created later by `RETYPE` do not appear in it, because the caller chooses their slots. `crates/k0-boot/build.rs` fails the build if the root image maps more 4 KiB frames than the page can describe. +The page is a snapshot. Capabilities created later by `RETYPE` do not appear in it, because the caller chooses their slots. `crates/k0-boot/build.rs` fails the build if the root image maps more 4 KiB frames than the page can describe. The bound is 77 frames: the page holds 127 descriptors, 6 of them are the fixed slots (the null slot included), and at most 44 are untyped. ## Retype @@ -211,9 +213,9 @@ The depth is capped at `MAX_DEPTH`. A `CAP_COPY` or `RETYPE` that would exceed i - `mask` must be a subset of `R|W|X`, otherwise `BAD_PERM`. It is ANDed with the rights of a `Frame` or `Endpoint`. If no rights remain, the result is `NO_RIGHTS`. - `badge` follows the rules above. - The copy has an empty mapping record, and a copy is never an original. -- `Untyped` and `PageTable` capabilities cannot be copied (`BAD_CAP`). Copying an untyped would allow retyping the same memory twice, and copying a page table would allow installing it in two address spaces. +- `Untyped`, `PageTable` and `PartCtl` capabilities cannot be copied (`BAD_CAP`). Copying an untyped would allow retyping the same memory twice, and copying a page table would allow installing it in two address spaces. `PartCtl` stays single so that deleting it seals the partition table for good. The copy rule names every kind one by one, so a kind added later does not compile until its rule is written. -`CAP_MOVE(src, cnode, index)` moves a capability to an empty slot. Its place in the list and its mapping record move with it. A capability bound to a TCB cannot be moved (`BAD_CAP`). `Untyped` and `PageTable` capabilities can be moved, which is the only way to hand them to another CNode. +`CAP_MOVE(src, cnode, index)` moves a capability to an empty slot. Its place in the list and its mapping record move with it. A capability bound to a TCB cannot be moved (`BAD_CAP`). `Untyped`, `PageTable` and `PartCtl` capabilities can be moved, which is the only way to hand them to another CNode. `CAP_REVOKE(slot)` removes every descendant of the slot and keeps the slot itself. @@ -236,6 +238,7 @@ When an original capability is removed, its object is finalized by the callbacks - **Console**: a task that waits in `CONSOLE_READ` on this capability wakes at once with `REVOKED` when the capability is deleted, revoked or moved (see [ipc.md](ipc.md)). - **Tcb** (original), and any capability bound to a task: the task is torn down, see [scheduling.md](scheduling.md) and [ipc.md](ipc.md). - **AddrSpace** (original): it is released in the registry (which bumps its generation). If it is installed in TTBR0, TTBR0 is switched to an empty table from the kernel pool. +- **PartCtl**: there is no object to finalize. Because no other `PartCtl` exists and none can be made, removing it means that the partition table and the domains of tasks can no longer be changed (see [scheduling.md](scheduling.md#the-control-capability-and-the-two-system-calls)). A **mapping record** is `(asid, generation, va, level)`. The `asid` is the number of the granule that holds the root table of the address space, a `u64` (the same number as in `Cap::AddrSpace`). It is checked when the word is decoded. Unmapping, deleting and revoking only walk a root that the registry confirms is still the same address space, and only clear an entry that still points at that very frame or table. See [user-address-space.md](user-address-space.md). @@ -256,6 +259,8 @@ The following table lists the capabilities and rights each system call requires. | `UNMAP` | a `Frame` or `PageTable` that is mapped | | `TCB_CONFIGURE` | a `Tcb` in the `Inactive` state, an `AddrSpace` and a `CNode` | | `TCB_RESUME` | a `Tcb` in the `Stopped` state | +| `PART_SET_TABLE` | the `PartCtl` | +| `PART_SET_DOMAIN` | the `PartCtl`, and a `Tcb` in the `Stopped` state | | `SEND`, `CALL` | an `Endpoint` with `W` | | `RECV`, `REPLY_RECV` | an `Endpoint` with `R` | | `CAP_COPY` | the source, and a `CNode` naming the destination | @@ -265,7 +270,7 @@ The following table lists the capabilities and rights each system call requires. > [!IMPORTANT] > There is no implicit authority. The target of `MAP` is always the `AddrSpace` the caller presents, never "the current address space". -`TCB_CONFIGURE` is atomic: both bindings are validated before either is written, and a failure leaves both embedded slots empty. It is accepted only on an `Inactive` TCB, forces the saved state to EL0t, and gives the new task its argument in `x0`. +`TCB_CONFIGURE` is atomic: both bindings are validated before either is written, and a failure leaves both embedded slots empty. It is accepted only on an `Inactive` TCB, forces the saved state to EL0t, gives the new task its argument in `x0`, and puts it in the time partition domain of the caller. Because mappings are limited to `RO`, `RW` and `RX`, and `X` exists only on the root task's text frames (without `W`), no physical frame is ever writable in one place and executable in another. The consequence is that new executable code cannot be loaded after boot, and a confined task runs code from the root task image. @@ -298,6 +303,7 @@ The following table lists the error codes for slot problems and their meaning. - that bad sources are rejected before any preparation runs - that retyped frames never carry execute - the copy rules per kind + - that `PartCtl` cannot be copied whatever the mask and the badge, that it can be moved, and that a `PartCtl` word carrying anything else does not decode - that a move keeps the subtree attached - that deleting finalizes only with the original - that untyped memory is reused only when nothing is left @@ -341,7 +347,7 @@ The 16 KiB image boots and passes the boot checks on QEMU `-cpu max`, and it boo - All objects are exactly one granule, and an untyped cannot be split. - No capability transfer over IPC. - No hardware ASIDs: TTBR0 changes flush the whole TLB, as does every unmap, table detach and address space destruction. -- **Control capabilities**: they are all or nothing. `Tcb`, `CNode` and `AddrSpace` capabilities carry no rights, so there is no reduced copy of one. Whoever holds such a capability has full control of the object, and a task is controlled by whoever holds a capability to its TCB, its CNode or its address space. +- **Control capabilities**: they are all or nothing. `Tcb`, `CNode` and `AddrSpace` capabilities carry no rights, so there is no reduced copy of one. Whoever holds such a capability has full control of the object, and a task is controlled by whoever holds a capability to its TCB, its CNode or its address space. `PartCtl` is all or nothing as well: one capability covers the table and the domains of all tasks, and it cannot be split into a part that sets the table and a part that places tasks. - **New code after boot**: it cannot be loaded. Because of W^X by capability rights, executable memory exists only in the root task image. - **Interrupts during revoke**: they are masked. The time of `CAP_REVOKE` and `CAP_DELETE` is proportional to the number of capabilities removed. - **Not verified here**: anything in tier 3: any real board, KVM, Firecracker, Cloud Hypervisor, crosvm, the 16550 console driver (never run), GICs with real security extensions on hardware, and CPUs with `HCR_EL2.E2H` fixed to 1 (that path follows Linux and has not run anywhere). Tier 1 (`tools/boot-matrix.sh`, run in CI and locally) and tier 2 (by hand on 2026-11-11 and 2026-11-12, Apple M5 Pro, QEMU HVF) are the supported set. The UEFI rows are listed in [uefi.md](uefi.md). diff --git a/design/en/exceptions.md b/design/en/exceptions.md index 4966d8f..158efe7 100644 --- a/design/en/exceptions.md +++ b/design/en/exceptions.md @@ -6,7 +6,7 @@ English | [한국어](../kr/exceptions_KR.md) -After the handoff, **kernel code runs only in response to an exception**. This note describes the vector table, how user state is saved and restored, how system calls are dispatched, and how a faulting task is contained. The code is in `crates/k0-arch/src/vectors.S`, `vectors.rs`, `usermode.rs` and `irq.rs`, and in `k0_syscall`, `k0_fault`, `k0_preempt` and `finish` in `kernel/src/syscall.rs`. The note describes the current `main` branch (unreleased). +After the handoff, **kernel code runs only in response to an exception**. This note describes the vector table, how user state is saved and restored, how system calls are dispatched, and how a faulting task is contained. The code is in `crates/k0-arch/src/vectors.S`, `vectors.rs`, `usermode.rs` and `irq.rs`, and in `k0_syscall`, `k0_fault`, `k0_preempt`, `k0_leave`, `finish` and `wait_for_work` in `kernel/src/syscall.rs`. The note describes the current `main` branch (unreleased). The following figure shows the path that the kernel follows for each kind of exception. @@ -43,7 +43,7 @@ The fatal vector path above is for exceptions the CPU raises. `k0_arch::fatal` i ### Interrupts while in the kernel -An IRQ taken at EL1 saves the caller-saved registers on the kernel stack, calls the handler and returns. While the kernel handles an exception it keeps interrupts masked, with one exception: the idle wait in `idle_until_ready` (see [The finish path](#the-finish-path)). The kernel itself is never preempted. +An IRQ taken at EL1 saves the caller-saved registers on the kernel stack, calls the handler and returns. While the kernel handles an exception it keeps interrupts masked, with one exception: the idle wait in `wait_for_work` (see [The finish path](#the-finish-path)). The kernel itself is never preempted. The idle wait opens only the I bit, for one pending interrupt, by `k0_arch::irq::wait_for_interrupt` (`wfi` with IRQs masked, then a short unmask). This is safe for three reasons. First, the whole EL0 context, including `ELR_EL1` and `SPSR_EL1`, is already saved in the TCB, so the nested EL1 IRQ may overwrite both registers without losing anything. Second, the handler runs on the kernel stack, which has plenty of room because the exception entry starts at the top of it. Third, the mask is set again right after the interrupt, so no other kernel code runs with interrupts open. @@ -68,7 +68,7 @@ The thread pointer registers are saved too, so that one task's thread pointer ne The handler receives a mutable reference to this context and may change it: write return values, advance the program counter, or point `__current_context` at another task. When the handler returns, execution falls through into `__user_restore`. It loads `__current_context` again and restores the user state from whatever context it now names. That is why **a task switch is just a pointer change** (see [scheduling.md](scheduling.md)). -The very first entry to EL0 at handoff uses the same restore path. That entry, `enter_user`, masks all of DAIF before it loads `ELR_EL1` and `SPSR_EL1`. At boot the timer is already running, and an interrupt between those register writes and the `eret` would overwrite both registers with EL1 values. On the normal path through an exception entry the mask is already set. +The very first entry to EL0 at handoff uses the same restore path. That entry, `enter_user`, masks all of DAIF before it loads `ELR_EL1` and `SPSR_EL1`. At boot the timer is already running, and an interrupt between those register writes and the `eret` would overwrite both registers with EL1 values. On the normal path through an exception entry the mask is already set. `k0_sched::handoff` masks interrupts even earlier, before the scheduler reads the tick number for the first time. A tick that was counted between that read and the entry to EL0 would leave the scheduler one tick behind the timer. A tick that becomes pending while the mask is set is taken right after the entry to EL0 as an ordinary tick. FP/SIMD registers are not part of the context. They do not need to be, because every FP/SIMD instruction at EL0 traps (see [hardening.md](hardening.md)). @@ -77,7 +77,7 @@ FP/SIMD registers are not part of the context. They do not need to be, because e `el0_sync` reads `ESR_EL1` and decides by exception class as follows: - **System call**: an `SVC` from AArch64 goes to `k0_syscall`. The CPU has already set the return address to the instruction after `svc`. -- **Skipped instruction**: a trapped `WFI` or `WFE` is skipped. The return address moves past the instruction and the task continues. +- **Skipped instruction**: a trapped `WFI` or `WFE` is skipped. The return address moves past the instruction and the task continues. The scheduler state does not change, but this path passes the exit check like every other (see [The exit check](#the-exit-check)). - **Fault**: everything else is a fault: aborts, undefined instructions, trapped system register accesses, FP/SIMD use, alignment faults, `brk` and the rest. It goes to `k0_fault` together with `FAR_EL1`. ## System calls @@ -103,6 +103,8 @@ The system call number is in `x8`. Arguments are in `x0` to `x5`, and the result | 14 | `CAP_DELETE` | delete a capability and everything derived from it | | 15 | `CAP_REVOKE` | delete everything derived from a capability and keep the capability | | 16 | `CONSOLE_READ` | read one byte of console input (only in an image built with `console-input`, see below); needs a `Console` capability with the read right | +| 17 | `PART_SET_TABLE` | set the time partition table; needs the `PartCtl` capability (see [scheduling.md](scheduling.md#the-control-capability-and-the-two-system-calls)) | +| 18 | `PART_SET_DOMAIN` | put a task that has not run yet in a time partition domain; needs the `PartCtl` capability | > [!IMPORTANT] > An unknown number is not just an error code. K0 treats it as a sign that the task is broken or hostile, prints `k0: unknown syscall N, killing task`, and terminates the caller. @@ -123,31 +125,44 @@ It then calls `kill_current`, which runs the teardown described in [scheduling.m Every system call and every fault ends in `finish`, which runs after the handler and after all capability cleanup. A handler can kill the calling task without a fault: `EXIT`, deleting its own CNode, address space or TCB, or revoking the untyped it came from. So `finish` decides what happens to the context only once everything else is done: -1. **The current task is Dead**: no return value is written into its context. The context is zeroed, so no register of a dead task survives, and the kernel switches to the next ready task. If none is ready, it calls `idle_until_ready` (see below). +1. **The current task is Dead**: no return value is written into its context. The context is zeroed, so no register of a dead task survives, and the kernel switches to the next ready task of the same domain. If none is ready, it calls `wait_for_work` (see below). 2. **Any other case**: the return value is written to `x0`. IPC calls that block write their results later, when the partner acts. Cleanup comes before the switch because a revoke can destroy the very address space or CNode the task was using. The next task must not run on top of half-finished cleanup. -When no task is ready (for example the last runnable task died, or every task is blocked), `idle_until_ready` **keeps the kernel idle instead of stopping it**. In a loop it waits for the next interrupt with `k0_arch::irq::wait_for_interrupt`, calls `k0_ipc::expire_timeouts` so that every IPC waiter whose deadline has passed is woken, and switches to a ready task if there is one. Timer ticks keep being counted and handled while the kernel idles. The nested EL1 IRQ is explained in [Interrupts while in the kernel](#interrupts-while-in-the-kernel). The function prints two lines, each at most once per boot: +When the running domain has no ready task (for example its last runnable task died, or every task is blocked), `wait_for_work` **keeps the kernel idle instead of stopping it**. In a loop it waits for the next interrupt with `k0_arch::irq::wait_for_interrupt` and then asks the scheduler (`k0_sched::poll`). The scheduler follows the time partition table if the tick number went up, wakes the waiters of the running domain that are due (console input first, then IPC timeouts through `k0_ipc::expire_timeouts`), and installs a ready task of that domain if there is one. A ready task of another domain is not run in its place (see [scheduling.md](scheduling.md#windows)). The same loop is used when a tick cut the running task at the end of its window and the incoming domain is empty. Timer ticks keep being counted and handled while the kernel idles. The nested EL1 IRQ is explained in [Interrupts while in the kernel](#interrupts-while-in-the-kernel). With no table set, the function prints two lines, each at most once per boot: | Line | When | | --- | --- | | `k0: idle (waiting for a timeout)` | the first time the kernel idles while at least one waiter has a deadline | | `k0: all tasks stopped (none ready, no timeout pending)` | the first time the kernel idles while no waiter has a deadline | -In the second state nothing can wake a task today, because there are no notification objects and no device interrupts for tasks other than console input. The machine stays idle. In an image with `console-input`, a task that waits for console input counts as a waiter: when that is the only thing left to wait for, the kernel prints nothing, which is the normal state of a terminal image. The second line is printed only when there is neither a timed waiter nor a console waiter. `tools/qemu-boot-test.sh` treats any line that starts with `k0: all tasks` as a failure. +In the second state nothing can wake a task today, because there are no notification objects and no device interrupts for tasks other than console input. The machine stays idle. In an image with `console-input`, a task that waits for console input counts as a waiter: when that is the only thing left to wait for, the kernel prints nothing, which is the normal state of a terminal image. The second line is printed only when there is neither a timed waiter nor a console waiter. While a table that names a domain other than the root domain is set or pending, the first line is not printed, and the second is printed only when no domain has a ready task or a timed waiter and no task waits for console input. `tools/qemu-boot-test.sh` treats any line that starts with `k0: all tasks` as a failure. + +### The exit check + +Every return from an exception to EL0 passes one function, `k0_leave`: the end of `k0_syscall`, the end of `k0_fault`, the end of the IRQ path whatever the interrupt was, and the skipped `WFI` or `WFE`. It does two things: + +1. It checks that the task about to be resumed is `Running` and belongs to the domain that is running now. If not, the scheduler state is broken, and the kernel halts with `k0: FATAL returning to a task outside its window` and does not run a task outside its window. +2. It spins until the instant of the last processed tick (`k0_arch::irq::hold_until_due`). That instant is in the future only when the tick was taken early, which happens before a change of domain. Otherwise it returns at once. + +[scheduling.md](scheduling.md#the-guard-and-the-hold) explains what the early tick and the hold are for. The first entry to EL0 at handoff does not pass this function. ## Timer interrupts from EL0 The interrupt the kernel always enables is **the EL1 virtual timer**. An image built with `console-input` takes a second one, the console UART's receive interrupt (see below). Its interrupt number comes from the DTB, and the kernel uses no physical timer. The interrupt controller is GICv2 or GICv3, whichever the DTB says is the timer's interrupt parent. Before it writes anything, the driver checks the identification registers against that description and refuses to boot if they differ. See [dtb.md](dtb.md). -An IRQ taken from EL0 is saved the same way as a system call. The handler acknowledges the interrupt. If it was the timer, it re-arms the timer for one second, and prints `k0: tick N`. In an image built with a console driver, the line also goes to the console; only the first 4 tick lines are logged. Then it calls `k0_preempt`. That function first expires the IPC timeouts that are due (`k0_ipc::expire_timeouts`), so a waiter whose deadline has passed is ready before the round-robin switch, and then calls `k0_sched::on_tick`. That call moves the current task to the end of the ready queue and runs the next ready task only if the slice rule says this tick cuts the current task, see [scheduling.md](scheduling.md#the-slice-rule). Spurious interrupt numbers 1020 to 1023 are ignored. Any other interrupt number, or any FIQ, cannot happen by design, so the kernel prints `k0: UNEXPECTED ...` and parks. +An IRQ taken from EL0 is saved the same way as a system call. The handler acknowledges the interrupt. If it was the timer, it works out the tick number from the counter, arms the next tick at its fixed instant and prints `k0: tick N`. In an image built with a console driver, the line also goes to the console; only the first 4 tick lines are logged. A timer interrupt that arrives before the instant it was armed for is not a tick: the handler arms the same instant again and nothing else happens. A handler that runs more than a period late skips the tick numbers in between (see [scheduling.md](scheduling.md#the-tick-clock-and-skipped-ticks)). + +For a tick the handler then calls `k0_preempt`, which calls `k0_sched::on_tick`. Inside a window of the time partition table, the scheduler first wakes the waiters of the running domain that are due (`k0_ipc::expire_timeouts` for IPC timeouts), so a waiter whose deadline has passed is ready before the round-robin switch. It then moves the current task to the end of its domain's ready queue and runs the next ready task of that domain only if the slice rule says this tick cuts the current task, see [scheduling.md](scheduling.md#the-slice-rule). At the end of a window it parks the current task and enters the next domain. If that domain has no ready task, `k0_preempt` does not return to EL0 and waits in `wait_for_work`. With no table set there is one domain and every tick is a tick inside its window. + +Spurious interrupt numbers 1020 to 1023 are ignored. Any other interrupt number, or any FIQ, cannot happen by design, so the kernel prints `k0: UNEXPECTED ...` and parks. Once a tick has been counted, the handler also drains the console receive ring (an image with `console-input`), and after a task has started reading console input it stops printing the periodic tick lines (see [boot.md](boot.md)). Ticks, preemption and timeouts are unchanged. ## Console interrupt -An image built with `console-input` takes one more interrupt: the console UART's receive interrupt. The dispatcher tells the two apart by interrupt number (the timer's, then the console's), in the same function for IRQs taken at EL0 and at EL1. Anything else is still `k0: UNEXPECTED ...`. The console branch drains the UART into a ring of 256 bytes and never interprets a byte. It reports to the kernel binary through `k0_console_event`, a policy function like `k0_preempt`, which wakes a waiting `CONSOLE_READ` caller. The woken task goes to the end of the ready queue, so input does not preempt a running task. +An image built with `console-input` takes one more interrupt: the console UART's receive interrupt. The dispatcher tells the two apart by interrupt number (the timer's, then the console's), in the same function for IRQs taken at EL0 and at EL1. Anything else is still `k0: UNEXPECTED ...`. The console branch drains the UART into a ring of 256 bytes and never interprets a byte. It reports to the kernel binary through `k0_console_event`, a policy function like `k0_preempt`, which wakes a waiting `CONSOLE_READ` caller. The woken task goes to the end of its domain's ready queue, so input does not preempt a running task. Under a time partition table the byte is handed over only while the reader's domain runs. Otherwise it stays in the ring until the next tick at which that domain runs (see [scheduling.md](scheduling.md#console-input-under-a-table)). The interrupt is bounded by the reader. When the ring is full the kernel masks the UART's receive interrupt itself and reopens it after the reader has taken half of the ring. A character with a break, framing or parity error uses no place in the ring, so it is counted by itself: after 256 of them in one tick the kernel masks the receive interrupt until the next tick. The same drain also runs once per tick, so input still arrives, up to a tick late, when the interrupt does not. A line that fires without a UART cause is switched off after 8 entries with `k0: console input off (interrupt N fired without a uart cause)`. The cut-off is covered only by host tests. Receive interrupts stay off until a task first reads console input with the read right. diff --git a/design/en/hardening.md b/design/en/hardening.md index 7393ae1..84bc658 100644 --- a/design/en/hardening.md +++ b/design/en/hardening.md @@ -46,7 +46,7 @@ Because the inputs are hashed together, a hostile or predictable input cannot ca The kernel also derives a 32-byte seed for the root task (`k0_boot::derive_root_seed`). It is SHA-256 over its own domain string (`k0-root-task-seed-v1`), the length of the DTB entropy, the DTB entropy itself, the counter and, when the CPU has `RNDR`, four fresh `RNDR` words. The domain string differs from the one of the PAC keys, so the two outputs are independent of each other by domain separation: knowing one does not give the other. They do share the DTB entropy and the counter, so the seed is as good as its inputs and no better. -The seed is not in the bootinfo page. The kernel puts it into the saved context of the root task, so it arrives in the entry registers `x0` to `x3`. Register `x4` is the seed info word: bits 15..0 hold how many `rng-seed` bytes went into the seed, and bit 16 is set when `RNDR` contributed. The layout of the bootinfo page is now version 4 (`bootinfo::VERSION`), and a root task that sees another version stops. The kernel wipes its own copies of the seed from the boot stack. The root task prints only the material, never the seed: `root: boot seed from rng-seed bytes 0x... and rndr` or `... without rndr`. +The seed is not in the bootinfo page. The kernel puts it into the saved context of the root task, so it arrives in the entry registers `x0` to `x3`. Register `x4` is the seed info word: bits 15..0 hold how many `rng-seed` bytes went into the seed, and bit 16 is set when `RNDR` contributed. The layout of the bootinfo page is now version 5 (`bootinfo::VERSION`), and a root task that sees another version stops. The kernel wipes its own copies of the seed from the boot stack. The root task prints only the material, never the seed: `root: boot seed from rng-seed bytes 0x... and rndr` or `... without rndr`. ### Wiping the seed from the DTB @@ -102,7 +102,7 @@ The bootloader may leave registers in states that let user space observe or cont A trap at EL0 is handled as a fault, and the task is terminated (see [exceptions.md](exceptions.md)). The only exception is `WFI` and `WFE`, which the kernel skips. Trapping FP/SIMD means the kernel never has to save vector registers, so a task can never read vector state left behind by another task. -EL0 still cannot read any hardware counter or timer. IPC timeouts, however, give EL0 **a clock that is as coarse as the scheduler tick** (one second), together with a wake-up that is aligned to the timer interrupt (see [ipc.md](ipc.md)). The **tick period is therefore a side-channel decision**. Whether this clock can be amplified into a useful timing source for cache or speculation attacks has not been analysed. +EL0 still cannot read any hardware counter or timer. IPC timeouts, however, give EL0 **a clock that is as coarse as the scheduler tick** (one second), together with a wake-up that is aligned to the timer interrupt (see [ipc.md](ipc.md)). The **tick period is therefore a side-channel decision**. Whether this clock can be amplified into a useful timing source for cache or speculation attacks has not been analysed. Fixed time partitions keep the same tick, and a window is a whole number of ticks. They flush the TLB at every change of domain and do not flush caches or branch predictors (see [scheduling.md](scheduling.md#what-the-partitions-claim-and-what-they-do-not)). The EL0 thread pointer registers `TPIDR_EL0` and `TPIDRRO_EL0` are part of each task's saved context. `TCB_CONFIGURE` zeroes them, so a new task starts without the creator's values. @@ -111,7 +111,7 @@ The EL0 thread pointer registers `TPIDR_EL0` and `TPIDRRO_EL0` are part of each The filter does not mark who wrote a line. Kernel output and task output share the boot log, and in an image built with a console driver also the console. The terminal can additionally erase within its current line. > [!NOTE] -> In an image built with `console-input`, an outside party can cause interrupts while tasks run. The kernel masks the receive interrupt itself when the ring is full, so the rate is bounded by the reader, and it masks it until the next tick after 256 characters with a line error, which use no place in the ring. The reader still learns arrival times finer than the tick, and other tasks can notice the stolen time. This timing channel has not been analysed. The kernel's receive code runs at EL1 and never interprets a byte, but it is kernel code driven by an outside party, and a user-space driver would need device and interrupt delegation, which K0 does not have. +> In an image built with `console-input`, an outside party can cause interrupts while tasks run. The kernel masks the receive interrupt itself when the ring is full, so the rate is bounded by the reader, and it masks it until the next tick after 256 characters with a line error, which use no place in the ring. The reader still learns arrival times finer than the tick, and other tasks can notice the stolen time. This timing channel has not been analysed, and fixed time partitions do not close it: the time of a console interrupt is taken from whichever domain is running. The kernel's receive code runs at EL1 and never interprets a byte, but it is kernel code driven by an outside party, and a user-space driver would need device and interrupt delegation, which K0 does not have. > [!WARNING] > A task with a `Console` capability can print a newline followed by text that starts with `k0:`. A reader of the console or the log, including `tools/qemu-boot-test.sh`, cannot treat a `k0:` line that appears after `k0: entering root task (el0)` as written by the kernel. diff --git a/design/en/ipc.md b/design/en/ipc.md index a4d0d92..90f849a 100644 --- a/design/en/ipc.md +++ b/design/en/ipc.md @@ -115,7 +115,8 @@ When the original capability of an endpoint is deleted, every task still queued Every wait can be bounded. A timeout is the upper 32 bits of the flags register `x1`, counted in scheduler ticks. The tick period is 1 second (a kernel constant), so the tick is the unit of every timeout. The following rules apply. - **Deadline rule**: a timeout of n ticks ends at the (n+1)-th timer tick after the call. As long as ticks are handled on time, the wait lasts between n and n+1 tick periods. The timeout makes the task ready at that point. When it runs depends on the ready queue (see [scheduling.md](scheduling.md#timeouts)). -- **Lower bound, not wall-clock time**: the kernel runs with interrupts masked during every system call, and a long one such as a large `CAP_REVOKE` makes a tick late. The wait is then that much longer. +- **Lower bound, not wall-clock time**: the kernel runs with interrupts masked during every system call, and a long one such as a large `CAP_REVOKE` makes a tick late. The wait is then that much longer. Tick numbers follow the counter, so a handler that is more than a period late skips numbers, and a deadline counts those skipped ticks too. +- **Late under a time partition table, never early**: a deadline is a global tick number, but the kernel looks at the deadlines of a domain only at a tick at which that domain runs. A waiter whose deadline passes while another domain runs wakes when its own domain's next window opens (see [scheduling.md](scheduling.md#time-partitions)). With no table set there is one domain, and nothing changes. - **0 means no deadline**: the task waits until its partner acts, as before. - **One deadline for a call**: the deadline of `CALL` covers both phases, waiting for a receiver and then waiting for the reply. - **Reply and receive**: `REPLY_RECV` applies the timeout to its receive phase only. @@ -134,17 +135,17 @@ When a `CALL` ends with `REPLY_TIMEOUT`, the kernel clears the reply right of th ### The timed list -Each TCB has the fields `deadline`, `tnext` and `tprev`. `k0-sched` keeps an unsorted, intrusive list of the timed waiters (`arm_timeout`, `disarm_timeout`, `expired`, `has_timed`), plus a lower bound of the earliest deadline so that most ticks do not walk the list. A task leaves a blocked state in only two ways, and both remove it from the list: +Each TCB has the fields `deadline`, `tnext` and `tprev`. `k0-sched` keeps an unsorted, intrusive list of the timed waiters for each of the 8 time partition domains (`arm_timeout`, `disarm_timeout`, `expired`, `has_timed`), plus a lower bound of the earliest deadline of each list so that most ticks do not walk it. A new waiter is linked at the head of the list of its own domain. A task leaves a blocked state in only two ways, and both remove it from the list: - `k0_sched::enqueue` (a wake-up), so a waiter woken by a message keeps no deadline, and - `k0_ipc::teardown` (death). -`k0_ipc::expire_timeouts` handles the expired waiters. It removes a waiter from its endpoint queue and wakes it with `TIMEOUT`, or it clears the reply link of the task that holds its reply and wakes it with `REPLY_TIMEOUT`. A link that does not match the state halts the kernel with `k0: FATAL`, as in teardown. It runs on every timer tick: +`k0_ipc::expire_timeouts` handles the expired waiters. It removes a waiter from its endpoint queue and wakes it with `TIMEOUT`, or it clears the reply link of the task that holds its reply and wakes it with `REPLY_TIMEOUT`. A link that does not match the state halts the kernel with `k0: FATAL`, as in teardown. It takes the domain whose list it walks, and the scheduler calls it for the running domain only: -- from `k0_preempt`, when a task was running, and -- from the idle loop, when none was. +- at every tick inside that domain's window and at the tick that opens the window, whether a task was running or the kernel was waiting, and +- from the wait loop after an interrupt that was not a tick. -The walk costs O(number of timed waiters) with interrupts masked, at most once per tick. +The walk goes from the head of the list, so of several waiters that are due at once, the one that armed last is queued first. It costs O(number of timed waiters of that domain) with interrupts masked. The number of waiters in one domain therefore does not change how long a tick takes in another. > [!NOTE] > EL0 still cannot read any hardware counter or timer. A timeout gives EL0 a clock as coarse as the scheduler tick and a wake-up aligned to the timer interrupt. Whether that can be amplified into a useful timing source for cache or speculation attacks has not been analysed. @@ -153,12 +154,12 @@ The walk costs O(number of timed waiters) with interrupts masked, at most once p A task that has to wait is marked with its blocked state and linked into the endpoint queue or held by a reply right. If the call has a timeout, the task is also put in the timed list. Then the scheduler switches to the next ready task (see [scheduling.md](scheduling.md)). Its return registers are written later, by the task that releases it. -If no task is ready at that point, the kernel does not stop. It idles in `idle_until_ready` (`kernel/src/syscall.rs`): it waits for the next interrupt, wakes every waiter whose deadline has passed, and switches to a ready task if there is one. Timer ticks keep being counted and handled meanwhile. The idle loop prints one of two lines, each at most once per boot: +If no task of the same domain is ready at that point, the kernel does not stop. It idles in `wait_for_work` (`kernel/src/syscall.rs`): it waits for the next interrupt, lets the scheduler wake the waiters of the running domain whose deadline has passed, and switches to a ready task of that domain if there is one. A ready task of another domain has to wait for its own window. Timer ticks keep being counted and handled meanwhile. With no table set, the idle loop prints one of two lines, each at most once per boot: - `k0: idle (waiting for a timeout)`: at least one waiter has a deadline, so something will wake a task. - `k0: all tasks stopped (none ready, no timeout pending)`: no waiter has a deadline and no task waits for console input. Nothing can wake a task in that state today, because K0 has no notification objects and the only device interrupt that wakes a task is console input, so the machine stays idle. `tools/qemu-boot-test.sh` treats any line that starts with `k0: all tasks` as a failure. -When the only thing left to wait for is console input, the kernel prints neither line. That is the normal state of a terminal image. +When the only thing left to wait for is console input, the kernel prints neither line. That is the normal state of a terminal image. While a time partition table that names a domain other than the root domain is set or pending, the first line is not printed at all, and the second only when no domain has a ready task or a timed waiter and nobody waits for input (see [scheduling.md](scheduling.md#when-there-is-nothing-left-to-run)). > [!WARNING] > The kernel no longer halts when every task is blocked, and a task can bound its own waits with timeouts. Availability is still not protected. A task that waits without a timeout can wait forever if its partner never acts, and a confined task that holds a capability to an endpoint can still make others wait. This is the subject of advisory GHSA-q99x-2wrv-358p in [SECURITY.md](../../SECURITY.md). The advisory is updated at release time. @@ -186,7 +187,8 @@ If no byte is ready, the task waits in the state `BlockedConsole`. The wait work - **Revocation**: a waiter whose `Console` capability is deleted, revoked or moved wakes at once with `REVOKED`, and gets no byte. - **No input path**: `NO_DEVICE` means that the image has no receive driver for this console, or that the input path was turned off. A waiter wakes with it when the path is turned off while it waits. - **Teardown**: a task that dies while it waits is removed from the waiter place. -- **Wake-up order**: a woken reader goes to the end of the ready queue. Input does not preempt a running task. +- **Wake-up order**: a woken reader goes to the end of its domain's ready queue. Input does not preempt a running task. +- **Under a time partition table**: a byte is handed to the waiter only while the waiter's domain runs. Otherwise it stays in the ring until the next tick at which that domain runs. `REVOKED` and `NO_DEVICE` are delivered whichever domain runs. This rule has no test yet (see [scheduling.md](scheduling.md#console-input-under-a-table)). Receive interrupts stay off until a task first reads console input with the right. That first read discards what the device holds and stops the periodic `k0: tick N` lines after one line `k0: tick lines off (console input in use)`. Ticks, preemption and timeouts keep working. The receive path and its limits are described in [USAGE.md](../../USAGE.md) and [exceptions.md](exceptions.md). @@ -257,7 +259,8 @@ The boot test script also requires an exact number of `k0: task fault` lines and > [!NOTE] > Capability transfer over IPC and notification objects do not exist yet. Timeouts are opt-in per call, so a task that waits without one still waits until its partner acts. -- **Timeouts say when a task becomes ready, not when it runs**: there is no priority and no CPU budget, and the scheduler is round robin on a one-second tick. A task that got the CPU between two ticks keeps it through the next tick, so a woken task can wait one tick period longer than it did before. With k tasks to run before it, a task starts within k + 1 tick periods. These numbers describe this version of the scheduler and are not an interface (see [scheduling.md](scheduling.md)). +- **Timeouts say when a task becomes ready, not when it runs**: there is no priority and no CPU budget, and the scheduler is round robin on a one-second tick. A task that got the CPU between two ticks keeps it through the next tick, so a woken task can wait one tick period longer than it did before. With k tasks to run before it, a task starts within k + 1 tick periods. Under a time partition table a timeout can also fire late, at the start of the waiter's next window, and the woken task runs only in its own windows. These numbers describe this version of the scheduler and are not an interface (see [scheduling.md](scheduling.md)). +- **An endpoint shared across domains is a channel**: fixed time partitions do not cover IPC between domains. A send, a reply, a timeout that depends on the partner, the deletion of the endpoint and the end of a task that holds a reply all tell the other side something, and when. That is what the capability was given for (see [scheduling.md](scheduling.md#what-the-partitions-claim-and-what-they-do-not)). - **Long system calls**: the kernel is not preemptible, so a long call such as `CAP_REVOKE` on an untyped with many objects delays every other task and every timeout. - **Fatal stops**: a `k0_arch::fatal` or a kernel panic still stops the machine. - **Timing source for EL0**: whether the tick-aligned wake-up can be used for timing attacks has not been analysed. In an image with console input, an outside party can cause interrupts while tasks run (bounded by the reader for bytes and by 256 per tick for characters with a line error), and the reader learns arrival times finer than the tick. Other tasks can notice the stolen time. This timing channel is not analysed either. diff --git a/design/en/scheduling.md b/design/en/scheduling.md index 49e308b..1d4d5bd 100644 --- a/design/en/scheduling.md +++ b/design/en/scheduling.md @@ -11,13 +11,17 @@ This note describes the following: - how K0 represents a task - how user space creates, starts and tears down tasks - how the round-robin scheduler switches between tasks and decides when a timer tick cuts a task +- how fixed time partitions give each domain of tasks its own windows of ticks, and what that does and does not claim The code is in the following places: - `crates/k0-task/src/lib.rs` -- `crates/k0-sched/src/lib.rs` +- `crates/k0-part/src/lib.rs` (every scheduling decision, type `Core`) and `crates/k0-part/src/clock.rs` (the arithmetic of tick instants) +- `crates/k0-slice/src/lib.rs` (the rule for one tick, used by `Core`) +- `crates/k0-sched/src/lib.rs` (the queues and the installed task, around `Core`) +- the timer in `crates/k0-arch/src/irq.rs` - `teardown` in `crates/k0-ipc/src/lib.rs` -- `sys_tcb_configure`, `sys_tcb_resume`, `kill_current` and `finish` in `kernel/src/syscall.rs` +- `sys_tcb_configure`, `sys_tcb_resume`, `sys_part_set_table`, `sys_part_set_domain`, `k0_preempt`, `k0_leave`, `wait_for_work`, `kill_current` and `finish` in `kernel/src/syscall.rs` The note describes the current `main` branch (unreleased). @@ -28,6 +32,7 @@ A **task control block** (TCB) holds the following: - **Saved user context**: 31 general-purpose registers, the stack pointer, the return address, the saved processor state, and the two EL0 thread pointer registers. - **Top-level page table address** (`ttbr0_pa`): a copy of the address space root that is valid only while the task's embedded slots are bound. - **State**: the current state of the task. +- **Domain**: the number of the time partition domain the task belongs to, 0 to 7 (see [Time partitions](#time-partitions)). Domain 0 is the root domain. The byte sits in what was padding after the state, so the TCB did not grow. - **Queue links**: `next` and `prev`, the links to its neighbours in whatever queue the task is in. - **Reply right**: the single-use reply right (`reply_to`) and its reverse link (`reply_from`), described in [ipc.md](ipc.md). - **IPC wait information**: `blocked_on`, the endpoint the task is queued at, and `ipc_badge`, the badge of the message it is waiting to send. @@ -52,7 +57,7 @@ The following figure shows the task states and the transitions between them. The | --- | --- | | `Inactive` | just retyped, not configured | | `Stopped` | configured, not yet started | -| `Ready` | in the ready queue | +| `Ready` | in the ready queue of its domain | | `Running` | the current task | | `BlockedSend`, `BlockedRecv`, `BlockedCall` | waiting in an endpoint queue | | `BlockedReply` | waiting for the answer to a `CALL` | @@ -61,7 +66,7 @@ The following figure shows the task states and the transitions between them. The A task in any of the blocked states can also become `Ready` when its deadline passes. A `BlockedConsole` task also becomes `Ready` when a byte arrives or when its capability is deleted, revoked or moved (for deadlines see [Timeouts](#timeouts)). -`Inactive` has the value 0. A freshly retyped frame is all zeroes, so it already is a valid `Inactive` TCB with empty queue links, empty embedded slots and no reply right. Retype needs no constructor. +`Inactive` has the value 0. A freshly retyped frame is all zeroes, so it already is a valid `Inactive` TCB of the root domain with empty queue links, empty embedded slots and no reply right. Retype needs no constructor. ## Creating a task @@ -77,13 +82,17 @@ A task in any of the blocked states can also become `Ready` when its deadline pa If any check fails, both embedded slots stay empty and the TCB stays `Inactive`. -The kernel then zeroes the saved context and sets the entry address, the stack pointer, `x0` and `ttbr0_pa`. It sets the saved processor state itself, to EL0 with interrupts unmasked. User space never supplies processor state, so it cannot ask to return to EL1 or to run with interrupts masked. The thread pointer registers start at zero, so the new task does not inherit the creator's values. The TCB moves to `Stopped`. +The kernel then zeroes the saved context and sets the entry address, the stack pointer, `x0` and `ttbr0_pa`. It sets the saved processor state itself, to EL0 with interrupts unmasked. User space never supplies processor state, so it cannot ask to return to EL1 or to run with interrupts masked. The thread pointer registers start at zero, so the new task does not inherit the creator's values. The new task gets **the domain of the task that configured it**. The TCB moves to `Stopped`. -`TCB_RESUME` accepts only a `Stopped` TCB and puts it in the ready queue. A TCB that is already queued, running, blocked or dead is refused, so the same TCB can never sit in a queue twice. +`TCB_RESUME` accepts only a `Stopped` TCB and puts it in the ready queue of its domain. A TCB that is already queued, running, blocked or dead is refused, so the same TCB can never sit in a queue twice. + +Between the two calls, and only then, the holder of the control capability can put the task in another domain with `PART_SET_DOMAIN` (see [The control capability and the two system calls](#the-control-capability-and-the-two-system-calls)). A task's domain never changes after its first `TCB_RESUME`. ## The ready queue -The scheduler keeps three values: the current task, and the head and tail of the ready queue. Each is the kernel address of a TCB, with 0 meaning none. The queue is linked through the TCBs' own `next` and `prev` fields, so it needs no memory of its own. Its length is bounded by the number of TCBs, which user space paid for with untyped memory. The scheduler cannot become a way to exhaust kernel memory. +The scheduler keeps the installed task and, **for each of the 8 domains**, the head and tail of a ready queue and the head of a list of timed waiters. Each value is the kernel address of a TCB, with 0 meaning none. A queue is linked through the TCBs' own `next` and `prev` fields, so it needs no memory of its own. Its length is bounded by the number of TCBs, which user space paid for with untyped memory. The scheduler cannot become a way to exhaust kernel memory. + +A task is only ever put in the queue of its own domain. `k0_sched::enqueue`, which every wake-up uses, reads the domain from the TCB, and the caller cannot choose the queue. When the scheduler itself queues a task (at a rotation or at the end of a window), it checks that the queue is the task's own and halts with `k0: FATAL task queued outside its domain` otherwise. With no table set, every task is in domain 0 and one queue is in use, as before. The queue is doubly linked so that a task can be removed from anywhere in it in constant time. That matters because a task can be torn down while it is ready, and the kernel must not walk the queue to find it. Removal checks that the links agree with the queue's head and tail. If they do not, the queue is corrupt and the kernel halts with `k0: FATAL ready queue corrupt`. @@ -94,60 +103,190 @@ The same `next` and `prev` fields also link a blocked task into an endpoint queu When an exception arrives from EL0, the vector code saves all user registers into the context of the current TCB before any Rust code runs (see [exceptions.md](exceptions.md)). On the way back, it restores registers from whatever context the global `__current_context` pointer names. A task switch is therefore just two steps: 1. Point `__current_context` at the next task's saved context. -2. If the next task uses a different top-level page table, load it into `TTBR0_EL1` and invalidate the whole TLB. K0 does not use address space identifiers, so every switch between tasks in different address spaces flushes the TLB. Switching between tasks in the same address space does not touch `TTBR0_EL1`. +2. If the next task uses a different top-level page table, load it into `TTBR0_EL1` and invalidate the whole TLB. K0 does not use address space identifiers, so every switch between tasks in different address spaces flushes the TLB. Switching between tasks in the same address space does not touch `TTBR0_EL1`. A change of domain flushes the TLB too, even when the address space stays the same. Tasks can run in different address spaces, so `TTBR0_EL1` really changes between them. If an address space is destroyed while it is installed, the kernel first switches `TTBR0_EL1` to an empty table. -Five operations use this switch, as shown in the following table. Each one passes the entry kind of the next task: `Tick` if the task got the CPU by a tick's own decision, `Between` if it got it between two ticks. The next section explains why the kernel keeps this. +Every decision about who runs next is made in one place, the type `Core` of the crate `k0-part`. `Core` holds the table, the running domain, the running task and the mark of the slice rule, and it reaches the queues only through a small trait (`Env`), so the host tests run the same code on a fake environment. `k0-sched` implements that trait on the real queues. The kernel tells the scheduler only **which event happened**, by calling one of the functions in the following table. It never passes an entry kind or a "a tick went by" flag, so it cannot pass a wrong one. + +The entry kind says how the next task got the CPU: `Tick` if by a tick's own decision, `Between` if between two ticks. The next sections explain why `Core` keeps this. -| Operation | Used by | What happens to the current task | Entry kind of the next task | +| Function of `k0-sched` | Called for | What happens to the current task | Entry kind of the next task | | --- | --- | --- | --- | -| `rotate` | `YIELD` | goes to the tail of the ready queue, unless nothing else is ready, in which case it simply continues | `Between` | -| `on_tick` | timer preemption | if it got the CPU between two ticks and has met no tick yet, it continues and the exemption is used up. Otherwise it goes to the tail of the ready queue, unless nothing else is ready | `Tick` | +| `rotate` | `YIELD` | goes to the tail of its domain's ready queue, unless nothing else is ready in the domain, in which case it simply continues | `Between` | +| `on_tick` | a timer tick taken from EL0 | inside a window: if it got the CPU between two ticks and has met no tick yet, it continues and the exemption is used up. Otherwise it goes to the tail of the queue, unless nothing else is ready. At the end of a window it is parked in its domain's queue (see [Windows](#windows)) | `Tick` | | `block_and_switch` | IPC, `CONSOLE_READ`, and the system call exit path when the current task died | stays out of the ready queue. The caller has already put it in an endpoint queue, behind a reply right or in the console waiter slot, or it is `Dead`. | `Between` | -| `resume_from_idle` | the idle loop | (the current task is blocked or dead) | `Tick` if a tick passed while idle, otherwise `Between` | +| `poll` | the wait loop, after every interrupt | (no task is running) | `Tick` if the tick number went up while the kernel waited, otherwise `Between` | | `handoff` | boot, once | the root task becomes the first `Running` task | `Between` | +| `set_table` | `PART_SET_TABLE` | continues | (no switch) | + +None of these functions ever takes a task from another domain's queue. If the running domain has nothing ready, `block_and_switch`, `on_tick` and `poll` report that, and the kernel waits (see [When there is nothing left to run](#when-there-is-nothing-left-to-run)). ## Preemption -The timer fires once per second. When it fires while EL0 is running, the IRQ path acknowledges it, re-arms the timer, prints `k0: tick N` and calls `k0_preempt`. That function wakes the console and timeout waiters that are due and then calls `k0_sched::on_tick`, which decides whether this tick cuts the current task (see [The slice rule](#the-slice-rule)). The `k0: tick N` line goes to the console in an image built with a console driver, and only the first 4 tick lines are logged. A task that never yields or blocks therefore **loses the CPU after at most two seconds**, and after one second if it got the CPU at a tick. Once a task has read console input, the tick lines stop after one line `k0: tick lines off (console input in use)`, but the tick, the preemption and the timeouts go on. +The tick is one second. Tick number n is due at a fixed instant: the counter value read when the timer was set up, plus n periods. The timer is always armed at such an absolute instant, so a handler that runs late does not push the later ticks back (see [The tick clock and skipped ticks](#the-tick-clock-and-skipped-ticks)). + +When the timer fires while EL0 is running, the IRQ path acknowledges it, works out the tick number, arms the next tick, prints `k0: tick N` and calls `k0_preempt`. That function calls `k0_sched::on_tick`. Inside a window, the scheduler first wakes the console reader and the timeout waiters of the running domain that are due, and then decides whether this tick cuts the current task (see [The slice rule](#the-slice-rule)). At the end of a window it parks the current task and enters the next domain (see [Windows](#windows)). + +With no table set, a task that never yields or blocks therefore **loses the CPU after at most two seconds**, and after one second if it got the CPU at a tick. Under a table the same holds inside the task's own windows, and the end of a window takes the CPU whatever the task did. + +The `k0: tick N` line goes to the console in an image built with a console driver. Only the first 4 tick lines are logged, and they are logged even when a number was skipped or a table is set. The later lines, which go to the console only, are not printed while a table that names a domain other than the root domain is set or pending. Once a task has read console input, the tick lines stop after one line `k0: tick lines off (console input in use)`, but the tick, the preemption and the timeouts go on. > [!IMPORTANT] > The kernel itself is never preempted. Exception entry masks interrupts, and the kernel keeps them masked while it handles a system call or fault. -A tick still cuts a task only when another task is ready. A timer interrupt that arrives at EL1 is possible only during boot, before the handoff, or while the kernel idles, and it only counts the tick. `on_tick` is called exactly once for every tick taken from EL0. In an image with `console-input`, an arriving input byte does not preempt: the woken reader goes to the end of the ready queue like any other woken task. There are no priorities, so input latency is up to one tick per ready task, plus one more tick when the running task got the CPU between two ticks. +Inside a window, a tick still cuts a task only when another task of the same domain is ready. A timer interrupt that arrives at EL1 is possible only during boot, before the handoff, or while the kernel waits with nothing to run. It only counts the tick, and the wait loop hands the new number to the scheduler right after (`poll`). `on_tick` is called exactly once for every tick event taken from EL0, and a timer interrupt that arrives before the instant it was armed for is not a tick. In an image with `console-input`, an arriving input byte does not preempt: the woken reader goes to the end of its domain's ready queue like any other woken task. There are no priorities, so input latency is up to one tick per ready task, plus one more tick when the running task got the CPU between two ticks. ## The slice rule -The timer is armed only in the tick handler, never when the kernel switches tasks. A task that gets the CPU between two ticks therefore receives only the rest of a period. Before this rule, the next tick moved it to the end of the queue however short a time it had run. A task could call `YIELD`, which needs no capability, shortly before each tick. The task behind it then got only the sliver after the yield, and the yielding task was back at the head of the queue for the next full period. In a QEMU run with two CPU-bound tasks, the other task fell from about 52 % of the CPU to between 7.9 % and 11.1 % when the attacker yielded at 90 % of the period. The yield point in that run was set from a loop count that the root task had measured for the attacker. No attacker that finds the tick phase by itself was built. +Ticks fall at fixed instants, and a task switch does not move them. A task that gets the CPU between two ticks therefore receives only the rest of a period. Before this rule, the next tick moved it to the end of the queue however short a time it had run. A task could call `YIELD`, which needs no capability, shortly before each tick. The task behind it then got only the sliver after the yield, and the yielding task was back at the head of the queue for the next full period. In a QEMU run with two CPU-bound tasks, the other task fell from about 52 % of the CPU to between 7.9 % and 11.1 % when the attacker yielded at 90 % of the period. The yield point in that run was set from a loop count that the root task had measured for the attacker. No attacker that finds the tick phase by itself was built. -The rule is in the crate `k0-slice`, which only answers the question "does this tick cut the current task". The scheduler keeps one mark next to the current task and writes it only where the current task changes: +The rule is in the crate `k0-slice`, which only answers the question "does this tick cut the current task". `Core` keeps one mark next to the running task and writes it in one function, the only one that changes the running task: -- A task that gets the CPU **between two ticks** (`Entry::Between`) is not cut by the first tick it meets. That tick uses up the exemption, and the task runs on to the tick after it. This covers a previous task that called `YIELD`, blocked (IPC or `CONSOLE_READ`), exited or was killed, and a kernel that was idle and woke for something that was not a tick, such as console input. -- A task that gets the CPU **by a tick's own decision** (`Entry::Tick`) starts at the beginning of a period and is cut by the next tick, as before. That includes a task the idle kernel switches to after a tick woke it, for example an expired timeout. If a tick and console input arrive in the same wake-up, `Entry::after_idle` counts it as a tick. +- A task that gets the CPU **between two ticks** (`Entry::Between`) is not cut by the first tick it meets. That tick uses up the exemption, and the task runs on to the tick after it. This covers a previous task that called `YIELD`, blocked (IPC or `CONSOLE_READ`), exited or was killed, and a kernel that was waiting and woke for something that was not a tick, such as console input. +- A task that gets the CPU **by a tick's own decision** (`Entry::Tick`) starts at the beginning of a period and is cut by the next tick, as before. That includes a task the waiting kernel switches to after a tick woke it, for example an expired timeout, and the first task of a domain whose window opens. If a tick and console input arrive in the same wake-up, it counts as a tick: `Core::poll` decides by the tick number alone. - The root task at boot counts as entering between two ticks, because the timer already runs during boot. -- Waking a task never grants the exemption. A woken task goes to the end of the ready queue as before, and console input still does not preempt. +- Waking a task never grants the exemption. A woken task goes to the end of the ready queue of its domain as before, and console input still does not preempt. - `YIELD` with nothing else ready changes nothing. -`Slice::entered` assigns the mark from the entry kind alone and never reads the previous value, so a mark left by the previous task cannot survive a switch. Blocking and exiting grant the exemption as well as `YIELD`. If only `YIELD` did, two tasks that start timed waits just before each tick would starve the task between them (the model shows this case). +`Slice::entered` assigns the mark from the entry kind alone and never reads the previous value, so a mark left by the previous task cannot survive a switch, and neither can a mark left by a task of another domain. Blocking and exiting grant the exemption as well as `YIELD`. If only `YIELD` did, two tasks that start timed waits just before each tick would starve the task between them (the model shows this case). -What follows from the rule: +What follows from the rule, with one domain: - A task that was switched in is not cut by the timer before it has had one full tick period, unless it gives up the CPU itself. Before a forced preemption it runs at least one period and at most two. -- With N ready tasks, a task that never yields or blocks keeps at least 1/N of the CPU in the long run, whatever the other tasks do with `YIELD`, blocking and timed waits. This was checked by search in a model (see [How it is tested](#how-it-is-tested)). It is **not a proof**, and it is **not a budget**: nothing caps what a task may use, and N grows with every task that is created. +- With N ready tasks, a task that never yields or blocks keeps at least 1/N of the CPU in the long run, whatever the other tasks do with `YIELD`, blocking and timed waits. This was checked by search in a model, and a Lean theorem states it for a model of one domain (see [How it is tested](#how-it-is-tested)). It is **not a proof about the Rust code**, there is no such statement for a table with several domains, and it is **not a budget**: nothing caps what a task may use, and N grows with every task that is created. - It costs latency. A task that becomes ready with k tasks to run before it (the running one included) used to start within k tick periods and now starts within k + 1. In the model, a caller and a server that exchange calls and replies behind one CPU-bound task need 4 ticks per round trip instead of 2. With no CPU-bound task nothing changes. +Under a table, read these points on the domain's own time, that is its windows put end to end. The tick that ends a window applies the same rule to the running task and then parks it (see [Windows](#windows)), so a task can be taken off the CPU by the end of its window before it has run a full period. It continues in the next window of its domain. A window that ends in a change of domain is also shorter by the guard (see [The guard and the hold](#the-guard-and-the-hold)). + > [!NOTE] > The numbers in this section (one to two periods per run, k + 1 periods of waiting) describe this version of the scheduler. They are not an interface. The tick is still one second and timeouts are still counted in ticks. ## Timeouts -The tick is the unit of every IPC timeout, as described in [ipc.md](ipc.md). The scheduler keeps the waiters that have a deadline in a timed list (`arm_timeout`, `disarm_timeout`, `expired`, `has_timed` in `k0-sched`). The list is unsorted, and a lower bound of the earliest deadline lets most ticks skip it. +The tick is the unit of every IPC timeout, as described in [ipc.md](ipc.md). The scheduler keeps the waiters that have a deadline in timed lists, **one per domain** (`arm_timeout`, `disarm_timeout`, `expired`, `has_timed` in `k0-sched`). A list is unsorted, and a lower bound of its earliest deadline lets most ticks skip it. A new waiter is linked at the head. -A task leaves a blocked state only through `k0_sched::enqueue` (wake-up) or `k0_ipc::teardown` (death), and both remove it from the timed list. On every timer tick, `k0_ipc::expire_timeouts` wakes the waiters whose deadline has passed. It runs from `k0_preempt` when a task was running, and from the idle loop when none was. A timeout of n ticks ends at the (n+1)-th tick after the call. +A task leaves a blocked state only through `k0_sched::enqueue` (wake-up) or `k0_ipc::teardown` (death), and both remove it from the timed list of its domain. A deadline is a global tick number: a timeout of n ticks ends at the (n+1)-th tick after the call, whichever domains run in between. + +`k0_ipc::expire_timeouts` wakes the waiters of **one domain** whose deadline has passed. The scheduler calls it for the running domain only: at every tick inside that domain's window, at the tick that opens its window, and from the wait loop while that domain runs. The lists of the other domains are not looked at. So under a table a timeout can fire **late, and never early**: a waiter whose deadline passes while another domain runs wakes at the first tick of its own domain's next window. The walk goes from the head of the list, so when several waiters are due at once, the one that armed last is queued first. > [!NOTE] -> A timeout says when a task becomes ready, not when it runs. The woken task joins the tail of the ready queue like any other. +> A timeout says when a task becomes ready, not when it runs. The woken task joins the tail of its domain's ready queue like any other. + +## Time partitions + +K0 has a domain scheduler that is always compiled in. Every task belongs to one of 8 **domains**, numbered 0 to 7, and a **table** says which domain may use the CPU at which tick. A domain runs only in its own windows of the table. The mechanism is aimed at one channel only, **the channel between domains that goes through the scheduler**. The claim and its limits are stated together in [What the partitions claim and what they do not](#what-the-partitions-claim-and-what-they-do-not). + +> [!NOTE] +> No image uses more than one domain yet. The root task tries the mechanism at every boot and then deletes the control capability, so every image built today runs with one domain and with the table sealed. Putting the key vault in a domain of its own is future work. + +The following figure shows a table of three entries and what happens where the domain changes. + +

+ A table of three entries gives domain 1 one tick, domain 0 one tick and domain 2 two ticks, and then repeats. A domain runs only in its windows, and when it has nothing ready the CPU waits. Before a tick that changes the domain, the timer interrupt is taken one fortieth of a tick early, the kernel does the switch work and holds, and the next domain starts at the tick instant +

+ +### Domains and the table + +A table has 1 to 16 entries. Each entry names a domain (0 to 7) and a number of ticks (1 to 255). The table runs from entry 0 to its last entry and then starts again, and the tick is one second, so one round of a table takes between 1 second and 68 minutes. + +- **No table set**: the kernel starts with the default table, one entry that gives domain 0 every tick. Domain 0 is the **root domain**, the one the root task is in. With this table the scheduler makes the same decision as the scheduler before it for the same sequence of events, as long as no tick is skipped (see [The tick clock and skipped ticks](#the-tick-clock-and-skipped-ticks) for what changed when one is). +- **A table that names only the root domain**: it behaves like the default table whatever its window lengths are, and the kernel does not treat the system as partitioned. +- **A domain that is in no table**: its tasks are never run. They stay ready, and they can still be deleted. +- **Where a task's domain comes from**: a task gets the domain of the task that configured it (`TCB_CONFIGURE`). Only the holder of the control capability can put a task elsewhere, and only before the task first runs. + +### Windows + +A **window** is a run of consecutive ticks that the table gives to one domain. Entries that follow one another with the same domain, also across the end of the table, are one window, and the ticks between them are ordinary ticks. + +- **Which domain runs at tick n** is a function of the table, the tick at which the table started and n. Nothing a task does enters into it. +- **A tick inside a window** is handled as before: the due waiters of the running domain are woken, and then the slice rule decides whether the running task goes to the tail of its domain's queue. +- **The tick that ends a window** applies the slice rule to the running task once and then parks the task in its own domain's queue. If the rule keeps the task, it goes to the front. If the rule rotates it and another task of the domain is ready, it goes to the tail and that other task is put at the front. Then the kernel flushes the TLB, wakes the due waiters of the incoming domain and enters the task at the front of that domain's queue, as by a tick's decision. A parked task is `Ready`, and it continues when its domain's next window opens. +- **Time left over is not given away**: if the running domain has no ready task, because the incoming domain is empty or because its last task blocked or exited in the middle of the window, the CPU waits. It waits until a task of that domain becomes ready or until the window ends. A ready task of another domain is not run in its place. +- **A woken task goes to its own domain's queue**, whichever domain is running when it is woken, and it runs in its own window. + +### The tick clock and skipped ticks + +Tick n is due at `T0 + n * P`, where `T0` is the counter value read when the timer was set up at boot and `P` is one second in counter units. The arithmetic is in `k0_part::clock` and touches no hardware, so it is tested on the host. `crates/k0-arch/src/irq.rs` only reads and writes the registers. + +- The timer compare value is always an absolute instant of this grid. How long a handler took has no effect on when the next tick is due. +- The tick number is a function of the counter. When the timer interrupt is handled, the tick number becomes the larger of "the last number plus one" and "the number of whole periods since `T0`". +- **A late handler jumps**: if the kernel kept interrupts masked for longer than a period, or the host stalled the virtual machine, the numbers in between are skipped. They are not replayed: the scheduler sees one tick event with the number that arrived, and the table position is computed from that number. So **a stall longer than a tick skips windows**, and a domain can lose a whole window that way. +- A timer interrupt that arrives before the instant it was armed for is not counted as a tick. The same instant is armed again. + +> [!NOTE] +> Before this change the kernel counted the ticks it handled and armed the timer one period after each handler. A stall then pushed every later tick back and skipped no number. Now a stall skips numbers and moves no tick. With one domain the decision at the tick is the same either way. What differs is the number the tick gets, and with it the tick at which a timeout ends. + +### The guard and the hold + +A domain that could shift the instant at which the next domain starts would still have a channel. A system call that is in flight when the tick is due delays the tick handler, and how long it delays it depends on what the outgoing domain chose to do. Two things bound this. + +- **Guard**: when the next tick will change the domain, the scheduler arms the timer one fortieth of a tick (25 ms) before the tick instant. The interrupt is taken that early, the tick is processed and the switch work is done inside this guard interval. The decision is made again after every tick and after every `PART_SET_TABLE`, because a call that replaces a table that was about to start can change the domain of the next tick. If such a call comes inside the guard interval, the guard of that one tick is shorter. +- **Hold**: every return from an exception to EL0 passes one exit function, `k0_leave`. It first checks that the task it is about to return to is `Running` and belongs to the running domain, and halts with `k0: FATAL returning to a task outside its window` otherwise. Then it spins until the instant of the last processed tick. After an early tick that is the tick instant. In every other case the instant is already past and the function returns at once. + +The result is this and no more: **the next domain starts at the tick instant, to within the spin and the exit path, as long as the kernel path in flight and the switch work fit in the guard**. A kernel path that is longer than the guard and is in flight when the guard starts still delays the start of the next window. + +The guard costs the outgoing domain its last 25 ms of every window that ends in a change of domain. Ticks inside a window, and every tick with one domain, are armed at the tick instant and have no guard. + +Measured once on the development Mac, the tick handler was entered 2 to 5 ms after the start of the guard under QEMU TCG and 5 to 31 microseconds after it under HVF. This is one measurement on one machine, not a bound. + +### The control capability and the two system calls + +The authority over the table and over the domains is one capability, `PartCtl` (kind 9). The kernel creates exactly one at boot and puts it in slot 5 of the root CNode (see [capabilities.md](capabilities.md)). It has no rights bits and no object behind it. + +- **No copy**: `CAP_COPY` of it returns `BAD_CAP`, whatever the rights mask and the badge. It can be moved with `CAP_MOVE`, and the authority goes with the slot. +- **Deleting it seals the table and the domains for good**: nothing can create another one, so after `CAP_DELETE` no task can change the table or a task's domain until the next boot. A table that was still pending when the capability was deleted takes effect. + +The two system calls take the slot of the capability in `x0`. Both read registers only. The source of truth for the numbers is `crates/k0-abi/src/lib.rs`. + +| Call | Arguments | What it does | +| --- | --- | --- | +| `PART_SET_TABLE` (17) | `x0` = `PartCtl` slot, `x1` = number of entries (1 to 16), `x2` to `x5` = the entries | sets a new table | +| `PART_SET_DOMAIN` (18) | `x0` = `PartCtl` slot, `x1` = `Tcb` slot, `x2` = domain (0 to 7) | puts a task that has not run yet in a domain | + +An entry of the table is 16 bits: `(ticks << 8) | domain`. Entry i is in register `x(2 + i / 4)`, starting at bit `16 * (i % 4)`, so each of the four registers holds four entries. Every bit that is not used must be zero, which includes all entries after the last one. + +`PART_SET_TABLE` works as follows: + +- **When it takes effect**: the new table starts **two ticks after the last processed tick, at entry 0**. The tick in between is governed by the table that is in force at the time of the call. +- **A second call before that** discards the first table, which then never governs any tick. This is the one case in which a call changes the domain of the very next tick: when the discarded table was to start at that tick, the tick goes back to the table in force. A table that is already in force stays until the new one starts. +- **The table must contain the caller's own domain**: this stops the holder from setting a table by mistake under which it never runs again. +- **Errors**: `BAD_SLOT` or `BAD_CAP` when `x0` does not name a `PartCtl`. `BAD_TABLE` (-25) when the number of entries is 0 or more than 16, a domain is above 7, a window is 0 ticks, an unused bit is set, or the caller's domain is missing. A refused call changes nothing. + +`PART_SET_DOMAIN` works as follows: + +- **Only a stopped TCB**: the task must be `Stopped`, that is configured and not yet resumed. A task in that state is in no queue and in no timed list, and since those are kept per domain, this is what keeps a task from sitting in a list of a domain it has left. +- **The domain need not be in the table**: a task put in a domain that no table names is simply never run. +- **Errors**: `BAD_SLOT` or `BAD_CAP` when `x0` does not name a `PartCtl`, `BAD_DOMAIN` (-26) when `x2` is above 7, `BAD_SLOT` or `BAD_CAP` when `x1` does not name a `Tcb`, and `BAD_STATE` when the TCB is not `Stopped`. The checks run in that order today. + +### Console input under a table + +In an image with `console-input`, a byte that arrives is handed to a waiting reader **only while the reader's domain runs**. If another domain is running, the byte stays in the kernel's ring, and the reader gets it at the next tick at which its own domain runs or is entered. So the arrival time of input does not change the reader's queue inside another domain's window. + +Two wake-ups of a reader are not bytes and are delivered whichever domain runs: `REVOKED`, when the reader lost its capability, and `NO_DEVICE`, when the input path was turned off. The woken reader still runs only in its own window. With one domain nothing changes. + +> [!WARNING] +> The interrupt itself is not tied to a domain. The time of every console interrupt, and of the UART work in the tick handler, is taken from whichever domain is running. + +### What the partitions claim and what they do not + +The claim is this and no more: **fixed time partitions close the channel between domains that goes through the scheduler**. With a table set, which task of a domain runs, in which order and at which tick does not depend on what the tasks of the other domains do, as long as the domains share no kernel object and none of the limits below applies. It is not a claim about timing channels in general. + +> [!WARNING] +> The limits below are part of the claim. A design that puts a secret in one domain and an observer in another must be checked against every one of them. + +1. **Long kernel paths**: a kernel path that is longer than the guard and is in flight when the guard starts delays the start of the next window. `CAP_REVOKE` and the deletion of a capability with many descendants are such paths, and so is a task end line written to a slow serial line. The kernel is not preemptible. +2. **Caches and branch predictors** are not flushed at a change of domain. Only the TLB is. +3. **Interrupt time**: the time of console input interrupts, and of the UART work that the tick handler does, lands in whichever domain runs. How much work that is depends on the serial input and on how full the receive ring is. +4. **Shared kernel state other than the scheduler**: the UART and the boot log with its quotas, the single console waiter slot (a second reader in any domain gets `BUSY`), and the kernel memory pools. +5. **Skipped ticks**: a stall longer than a tick skips windows. +6. **Shared objects are channels by design**: an endpoint that tasks of two domains hold is a channel between them. So is every other capability operation on an object shared with another domain: deleting or revoking an endpoint its tasks wait on, the end of a task that holds its reply, `TCB_RESUME` of one of its tasks, and deleting one of its TCBs. Each needs a capability, and the woken task still runs only in its own window. +7. **A reader woken inside the guard**: when the incoming domain is empty and console input wakes its reader inside the guard interval, the reader starts at the tick instant and is still treated as entered between two ticks, so it is not cut at its first tick. The effect stays inside the reader's own domain. +8. **What no test sees**: EL0 has no clock, so the boot test judges by the order of events only. No test sees the guard, the hold or the TLB flush at a change of domain: a kernel without them passes every test. The rule for console input under a table has no test either. These rest on review. +9. **The proofs are about a model**, not about the Rust code (see [How it is tested](#how-it-is-tested)). +10. **Real hardware was not tested**: everything ran in QEMU, under TCG and HVF. + +Inside one domain nothing changed: a task still changes when, and for how long, another task of the same domain runs by choosing when to yield or block. ## Teardown @@ -176,24 +315,26 @@ The following table shows what teardown does in each state. For every state it then withdraws any reply right the task itself holds, so that the caller waiting for that reply wakes with `NO_REPLY` and does not stay blocked forever. Finally it sets the state to `Dead`, clears the queue links, `blocked_on`, `reply_from`, `ipc_badge` and `ttbr0_pa`, and, unless the task is `Running`, zeroes its saved registers. A queue or reply link that does not match what the state promises is a kernel invariant violation, and the kernel halts with `k0: FATAL ...` (see [exceptions.md](exceptions.md)). -The running task is the one case teardown does not finish. The system call handler holds a mutable reference to the running task's saved context, so teardown only marks the task `Dead`. The system call exit path, `finish`, runs after the handler and after all capability cleanup, including the finalization of everything that was removed. If the current task is `Dead`, `finish` writes no return value into its context, zeroes the context, and switches to the next ready task. A task can therefore delete its own CNode, its own address space or its own TCB, or revoke the untyped it was carved from, without ever resuming afterwards. +The running task is the one case teardown does not finish. The system call handler holds a mutable reference to the running task's saved context, so teardown only marks the task `Dead`. The system call exit path, `finish`, runs after the handler and after all capability cleanup, including the finalization of everything that was removed. If the current task is `Dead`, `finish` writes no return value into its context, zeroes the context, and switches to the next ready task of the same domain. A task can therefore delete its own CNode, its own address space or its own TCB, or revoke the untyped it was carved from, without ever resuming afterwards. A dead task's frame is not freed by teardown. It stays a `Dead` TCB, and `TCB_CONFIGURE` and `TCB_RESUME` refuse it, so a dead task is never restarted. The memory is reusable once the TCB's original capability is deleted, or the untyped it came from is revoked, and the untyped is then retyped, which zeroes the frame again. A task that merely exited keeps its two bound capabilities until then. ## When there is nothing left to run -The kernel no longer parks the core when no task can run. If the current task blocked or died and no task is ready, `idle_until_ready` in `kernel/src/syscall.rs` takes over: +The kernel no longer parks the core when no task can run. `wait_for_work` in `kernel/src/syscall.rs` takes over in three cases: the current task blocked and its domain has no ready task, the current task died and its domain has no ready task, and a tick cut the running task at the end of its window and the incoming domain has no ready task. In the third case the cut task is parked `Ready` in its own queue, and nothing returns to EL0 until the scheduler installs a task. The loop works as follows: 1. It waits for the next interrupt (`k0_arch::irq::wait_for_interrupt`: `wfi` with IRQs masked, then a short unmask so that the EL1 vector takes the interrupt). -2. It wakes every IPC waiter whose deadline has passed. -3. It switches to a ready task if there is one (`resume_from_idle`, which tells the slice rule whether a tick passed while idle), and otherwise waits again. +2. It asks the scheduler (`k0_sched::poll`). If the tick number went up, that is a tick event: the table may move to another domain, and the due waiters of the domain that runs are woken. If not, the interrupt was console input, and the reader of the running domain is woken. +3. If the scheduler installed a task, it returns, and otherwise it waits again. A ready task of another domain is not run. It has to wait for its domain's window. -Timer ticks keep being counted and handled while the kernel idles. The idle loop prints one of two lines, each at most once per boot: +Timer ticks keep being counted and handled while the kernel waits. Unless a table that names a domain other than the root domain is set or pending, the loop prints one of two lines, each at most once per boot: - `k0: idle (waiting for a timeout)`: at least one waiter has a deadline. - `k0: all tasks stopped (none ready, no timeout pending)`: no waiter has a deadline and no task waits for console input. Nothing can wake a task in that state today, because there are no notification objects and no device interrupts for tasks other than console input, so the machine stays idle. -When the only thing left to wait for is console input (an image with `console-input`), the kernel prints nothing: that is the normal state of a terminal image. The idle loop also looks for arrived input after each interrupt and wakes the reader. +When the only thing left to wait for is console input (an image with `console-input`), the kernel prints nothing: that is the normal state of a terminal image. + +While a table that names a domain other than the root domain is set or pending, waiting in an empty window is normal, so the first line is not printed. The second line is still printed, once, when no domain has a ready task, no domain has a timed waiter and no task waits for console input. A ready task of a domain that no table names counts as ready in this check, although it will never run. > [!WARNING] > Availability is still not protected. A task that waits without a timeout can wait forever if its partner never acts, and a confined task that is the last one to block can still leave the system with nothing to run (advisory GHSA-q99x-2wrv-358p in [SECURITY.md](../../SECURITY.md), updated at release time). Isolation protects confidentiality and integrity between tasks, not availability. @@ -202,16 +343,17 @@ An SError taken from EL0 still stops the whole machine, and so does a `k0_arch:: ## How it is tested -The scheduler and the system call paths read system registers, so they are tested by booting. The queue and capability logic that does not touch hardware (`k0-cap`, `k0-mm`) is tested on the host, see [capabilities.md](capabilities.md). The root task self-tests: +The system call paths and the kernel side of the scheduler (`k0-sched`, `k0-ipc`, `kernel/src/syscall.rs`) read system registers, so they are tested by booting. The scheduling decisions (`k0-part`) and the tick rule (`k0-slice`) touch no hardware and are tested on the host, and so is the queue and capability logic of `k0-cap` and `k0-mm`, see [capabilities.md](capabilities.md). The root task self-tests: - create a task that counts to a target and exits, and wait for it, - refuse to resume an unconfigured task, refuse to resume a task twice, and refuse to resume a dead task, - run the slice test (`userspace/root-task/src/timeslice.rs`), which shows that a task which never yields is still preempted by the timer and that a task which got the CPU by a yield or by a block is not cut at its first tick, +- run the partition test (`userspace/root-task/src/partition.rs`, see [The partition test at boot](#the-partition-test-at-boot)), - confirm that thread pointer registers do not leak between tasks, - build confined tasks that have their own CNode and their own address space, and check that the root task's slot numbers mean nothing there, and - delete a task in each state (inactive, stopped, ready, blocked in send, receive and call, waiting for a reply, holding a reply right, and at the head, middle and tail of an endpoint queue), delete endpoints with tasks queued, kill a task by revoking its CNode or deleting its address space, and have a task delete its own TCB and revoke the untyped it was carved from. -`tools/qemu-boot-test.sh` requires the markers `root: child exit test pass`, `root: slice test yield pass`, `root: slice test block pass`, `root: preempt test pass`, `root: isolation tests pass`, `root: violation tests pass`, `root: teardown tests pass`, `root: revocation tests pass` and `root: sched tests pass`, followed by at least one more timer tick. The markers also include `k0: idle (waiting for a timeout)` and `root: timeout tests pass`, which come from the timeout tests (see [ipc.md](ipc.md)). It fails if the log contains a line that starts with `k0: all tasks`, `k0: FATAL` or `k0: PANIC`, so a run in which the kernel ends up with nothing to run and no timeout pending fails. It also counts task fault lines exactly (see [exceptions.md](exceptions.md)), which catches a task that keeps running after its teardown. +`tools/qemu-boot-test.sh` requires the markers `root: child exit test pass`, `root: slice test yield pass`, `root: slice test block pass`, `root: preempt test pass`, `root: partition refusal pass`, `root: partition window pass`, `root: isolation tests pass`, `root: violation tests pass`, `root: teardown tests pass`, `root: revocation tests pass`, `root: partition sealed` and `root: sched tests pass`, followed by at least one more timer tick. The markers also include `k0: idle (waiting for a timeout)` and `root: timeout tests pass`, which come from the timeout tests (see [ipc.md](ipc.md)). It fails if the log contains a line that starts with `k0: all tasks`, `k0: FATAL` or `k0: PANIC`, so a run in which the kernel ends up with nothing to run and no timeout pending fails. It also counts task fault lines exactly (see [exceptions.md](exceptions.md)), which catches a task that keeps running after its teardown. The slice test replaces the old test with a busy child and a counter. EL0 has no clock, so it judges by order of execution, not by time. It starts four tasks: one that hands the CPU over (by `YIELD` in the first run, by blocking in the second), one that then spins for ever, one that leaves a mark the first time it runs, and a helper. The root task goes into a timed wait of one tick. If the spinning task is cut at its first tick, the marker task runs and the spinner sees the mark before the root task wakes. If it is not cut, the root task wakes first. The test logs `root: slice test yield pass`, `root: slice test block pass` and then `root: preempt test pass`, and on failure `root: FAIL slice: a task that got the cpu by a yield was cut at its first tick` (or `by a block`). Each run takes about 2 ticks, so the two runs add about 4 seconds to every boot test where the old test took about 1. @@ -222,21 +364,76 @@ The rule itself is tested on the host in the crate `k0-slice` (9 tests, run by ` - The share of a CPU-bound task holds against one yielding task at every percent of the period, against up to three cooperating tasks over a grid of yields and timed waits, and against 3,000 sets of random tasks. - The two measured cases are reproduced (10 % and 55 % at a 90 % yield, and with three tasks 5 % for the task behind the yielder under the old rule). -This is a search in a bounded model (up to 6 tasks), **not a proof**. Each of nine deliberate breaks of the rule fails at least one host test. With the kernel connection broken on purpose, the boot test fails for the old rule, for `YIELD` passing the wrong entry kind and for blocking passing the wrong entry kind. The boot test would not see the tick's own switch passing `Between`, the idle loop reporting the wrong thing about a tick, or the wrong entry kind at `handoff`. Those mistakes change how long a task runs before it is cut, not its share, and the host model covers the rule for these cases but not the kernel's use of it. +This is a search in a bounded model (up to 6 tasks), **not a proof**. Each of nine deliberate breaks of the rule fails at least one host test. With the kernel connection broken on purpose, the boot test fails for the old rule, for `YIELD` passing the wrong entry kind and for blocking passing the wrong entry kind. The boot test would not see the tick's own switch passing `Between`, the wait loop treating a tick as no tick, or the wrong entry kind at `handoff`. Those mistakes change how long a task runs before it is cut, not its share. Since the time partition change the kernel cannot make them any more, because it names an event and `Core` chooses the entry kind. They are covered where they can now be made, in the host tests of `k0-part`. -With the change in QEMU, an attacker that yields at 90 % of the period left the other task 53.8 % to 54.9 % of the CPU (three runs). With three tasks no task was below 29.7 %. With an attacker that starts a timed wait just before the tick instead of yielding, the other task had 56.5 %. Everything ran in QEMU (TCG and HVF), nothing ran on hardware, and the yield point was set for the attacker, so what an attacker needs to find it by itself was not measured. +With the slice rule in QEMU, an attacker that yields at 90 % of the period left the other task 53.8 % to 54.9 % of the CPU (three runs). With three tasks no task was below 29.7 %. With an attacker that starts a timed wait just before the tick instead of yielding, the other task had 56.5 %. Everything ran in QEMU (TCG and HVF), nothing ran on hardware, and the yield point was set for the attacker, so what an attacker needs to find it by itself was not measured. + +### Host tests of the partition scheduler + +The crate `k0-part` has 36 host tests, run by `tools/host-test.sh`. + +- **The scheduling core on a model of the kernel** (24 tests): the real `Core` runs on a discrete event model with ticks, timed waits, input at arbitrary times, exits, shared objects, table changes and skipped ticks. The reference it is compared with is written separately from `Core`. The properties are the following: + - A domain runs at the ticks of its windows and at no other tick, and time left over is never given to another domain. + - **Two-run equality**: the record of one domain (which of its tasks ran at which tick, and what woke them) is the same whatever the tasks of the other domains do. A second test shows that the property is not empty: with an object shared across domains the records do differ. + - With the default table, `Core` makes the decisions of a frozen copy of the scheduler it replaced. + - The share bound of the slice rule holds inside a domain, on the domain's own windows put end to end, and the tick rule holds at the end of a window. + - A table takes effect two ticks after the call, a pending table can be replaced, skipped ticks land on the right entry, consecutive entries of one domain make no boundary, and a table that names only the root domain is not a partition. + - The answer of `next_tick_switches`, which the guard is armed from, equals the plan after every event. + - The table decoder accepts exactly the well-formed register values. + - 25 wrong versions of a copy of the logic are each caught by at least one property, and the unbroken copy is checked to equal the real `Core`. +- **The clock arithmetic** (9 tests): the tick number against a separately written reference, the instants just before and at the armed instant, values near the end of the counter range, a period of zero, and that the tick number never goes back or repeats. +- **The recorded results of the Lean model** (3 tests): see [What is proved](#what-is-proved). + +`k0-cap` has 54 host tests. Two of them are about `PartCtl`: no copy of it can be made whatever the mask and the badge, and a `PartCtl` word that carries anything else does not decode. + +`k0-sched`, `k0-ipc` and the kernel binary have no host tests. What they add to `Core` (the queues, the timed lists, the calls into the timer) is covered by the boot test and by review. + +### The partition test at boot + +The root task runs three checks at every boot. + +- **Refusals** (`root: partition refusal pass`): both calls through a slot that is empty, out of range or holds another kind of capability, malformed tables, a table without the caller's domain, a domain out of range, `PART_SET_DOMAIN` on a TCB that is not `Stopped` (not configured, running, ready, blocked, ended), and a copy of the control capability. Each must return its error, and the system must still run with the default table afterwards. +- **Windows** (`root: partition window pass`): one round of a table of 8 entries and 9 ticks, with tasks in domains 0, 1 and 2, a domain 3 that is in the table and has no task, and a task in domain 4, which is in no table. EL0 has no clock, so the test **judges by the order of events only**. Every task appends a letter to one log, the root task's own timed waits are the only clock, and at the end the log must read `XkwRhabryvx`. The order shows, among other things, that a child inherits its creator's domain, that time left over in a window is not given away, that a task cut at the end of a window continues at the front of its queue in the next one, that two deadlines of domain 1 that pass in other domains' windows are served only when domain 1 is entered, with the waiter that armed last first, and that the task of the domain in no table never runs. Two tasks of domain 1 that only yield to each other count every yield that came back without the other having run, and the count must be 0. That is how the test sees a task that kept running after its window closed. +- **Seal** (`root: partition sealed`): the root task deletes the control capability, and both calls must then return `BAD_SLOT`. This runs at the end of the self-tests, before the console input test and before a terminal image starts its services. + +If the host stalls the virtual machine for longer than a tick, a tick is skipped and the log of the window test is different. A wrong run prints its log as `root: partition window log `. The test then cleans up, prints `root: partition window retry` and runs once more. It fails only when both runs are wrong, with `root: FAIL partition: window order wrong twice`. `tools/qemu-boot-test.sh` prints the number of retries (`boot-test: partition window retries: N`) and does not judge by it. `tools/boot-matrix.sh` does: it runs a boot row again when its window test needed the retry, and fails the row when the second run needed it too, because a stall rarely repeats and a defect that shows only on the first table after boot always does. The terminal rows are not run again in this way. + +The partition test adds about 15 seconds to every boot. + +### What is proved + +`proofs/lean` holds Lean 4 proofs about an abstract model of the scheduler, in five proof files. `proofs/lean/README.md` says what each theorem states, under which hypotheses, and what the models leave out. + +> [!IMPORTANT] +> These are proofs about a model, not about the Rust code. They are not run in CI, and they are no claim of certification or compliance. + +In the model, and under the hypotheses of each theorem: + +- The running domain is a function of the tick numbers and the `PART_SET_TABLE` calls. Queues, waits and task actions do not enter into it. +- For any domain D, two runs that agree on the tick numbers, on the table calls and on what the tasks of D do, and in which no task outside D wakes a task of D, give D the same view after every step: its queue, its waiting list and which of its tasks runs. +- A window is never used by another domain, a timed wait is served only when its own domain runs and never before its deadline, and no task is lost or duplicated. +- A table set after tick n governs the ticks from n + 2 on. It leaves tick n + 1 as planned unless it replaces a table that was to start exactly there, which is why the kernel decides about the guard again after every `PART_SET_TABLE`. +- Inside one domain, a task that never gives up the CPU among at most N tasks keeps its share up to an additive bound. There is no such theorem for a table with several domains. + +The link between the model and the code is a test, not a proof. The host test `core_gives_the_lines_of_the_lean_model_on_every_recorded_script` in `crates/k0-part/src/model_tests.rs` runs 1600 recorded event scripts (`model_vectors.txt`) through the real `Core` and compares the state after every event with the state the model gave, through a hash that the Lean side computed. That test is in CI. The model has no time inside a tick, so it says nothing about the guard, the hold, caches or kernel path lengths. ## Known gaps > [!NOTE] -> Priorities and CPU budgets do not exist yet. There is one core only. - -- **Scheduling**: round robin with a one-second tick and the slice rule. There is no priority and no CPU budget: a CPU-bound task uses its whole turn and nothing caps it. A task that holds untyped memory can still create many tasks and dilute everybody's share. -- **Timing channels**: they are open. A task still changes when, and now also for how long, another task runs by choosing when to yield or block. This has not been analysed. Closing it would need fixed time partitions, which K0 does not have. -- **Latency**: there is no real-time or latency promise. The tick is one second and the kernel is not preemptible. -- **Slice rule checks**: the host model covers the rule, not the kernel's use of it (see [How it is tested](#how-it-is-tested)), and the measurements ran only in QEMU with an attacker whose yield point was set for it. +> Priorities and CPU budgets do not exist yet. There is one core only. No image uses more than one domain yet: the root task seals the table at the end of its self-tests. + +- **Scheduling**: round robin inside a domain, with a one-second tick and the slice rule, and fixed windows between domains. There is no priority and no CPU budget inside a domain: a CPU-bound task uses its whole turn and nothing caps it. A task that holds untyped memory can still create many tasks and dilute the share of everybody in its domain. A window is the only budget there is, and it is per domain. +- **Timing channels**: fixed time partitions close the channel between domains that goes through the scheduler, with the limits listed in [What the partitions claim and what they do not](#what-the-partitions-claim-and-what-they-do-not). Every other timing channel is open and has not been analysed. Inside a domain a task still changes when, and for how long, another task runs by choosing when to yield or block. Caches and branch predictors are not flushed between domains. +- **No test of the timing side**: the guard, the hold and the TLB flush at a change of domain are seen by no test, because EL0 has no clock. The rule that console input is handed over only in the reader's window has no test either. +- **Proofs**: they are about a model, not about the Rust code, they are not run in CI, and there is no share bound for a table with several domains. +- **The guard is a fixed length**: a kernel path longer than 25 ms that is in flight when the guard starts delays the next window. No bound on the length of kernel paths backs that number, and the only measurement is one run in QEMU on one machine. +- **Skipped ticks**: a stall longer than a tick skips windows, and nothing gives a domain a lost window back. +- **Table limits**: 8 domains, 16 entries and windows of whole seconds up to 255. A table cannot be read back, and once the control capability is deleted nothing can change it until the next boot. +- **Latency**: there is no real-time or latency promise. The tick is one second and the kernel is not preemptible. Under a table a task also waits for its domain's window, and a timeout can fire as late as the start of that window. +- **Slice rule checks**: the measurements ran only in QEMU with an attacker whose yield point was set for it (see [How it is tested](#how-it-is-tested)). - **Timeouts**: they say when a task becomes ready, not when it runs. They are opt-in per call, so a task that waits without one can wait forever. - **Idle state**: it exists, but while the root task keeps calling `YIELD` after its self-tests, the CPU does not sleep. When no task is ready and no waiter has a deadline, the machine stays idle and nothing can wake a task. +- **Real hardware**: nothing here ran on a real board. Everything ran in QEMU, under TCG and HVF. - **Availability**: a task that blocks without a timeout, including a confined one, can stay blocked for good if its partner never acts (GHSA-q99x-2wrv-358p). The kernel is not preemptible, so a long system call such as `CAP_REVOKE` on an untyped with many objects delays every other task and every timeout. Task isolation does not cover availability. - **Blocked tasks**: a blocked task wakes when its IPC partner acts, when its deadline passes, or when the endpoint is deleted. - **Dead TCB**: it is not reclaimed by teardown. Its frame becomes reusable only when its capability is deleted or its untyped is revoked and retyped. diff --git a/design/en/terminal.md b/design/en/terminal.md index d7c3d53..cb8e505 100644 --- a/design/en/terminal.md +++ b/design/en/terminal.md @@ -71,7 +71,7 @@ At boot the kernel prints `k0: console input on (pl011 irq 33)` or `k0: console The flags are `NONBLOCK` (1) and `FLUSH` (2), and a timeout in ticks in bits 63 to 32. Any other bit is refused with `BAD_FLAGS`. `NO_DEVICE` (-24) means that there is no input path or that it was turned off. -The `Console` capability now has rights: **R** reads input and **W** writes output. `CAP_COPY` can only remove them. The root task's capability has W, and R only in images with `console-input`. `DEBUG_PUTC` needs W. `bootinfo::VERSION` is 4. +The `Console` capability now has rights: **R** reads input and **W** writes output. `CAP_COPY` can only remove them. The root task's capability has W, and R only in images with `console-input`. `DEBUG_PUTC` needs W. The rights came with `bootinfo::VERSION` 4. The version is 5 now, because of the control capability of the time partitions in slot 5. The output filter is unchanged, except for one thing: a `Console` capability with R (the terminal's) may also emit backspace (0x08). Every other control byte is still printed as `?`. @@ -79,7 +79,8 @@ The output filter is unchanged, except for one thing: a `Console` capability wit Only one task can wait for input at a time. A second reader gets `BUSY` (-23). A reader that finds the ring empty and did not ask for `NONBLOCK` goes to sleep, with the timeout from its flags if there is one. -- **Waking on a byte**: a received byte wakes the waiter. It goes to the end of the ready queue. There is no preemption on input. +- **Waking on a byte**: a received byte wakes the waiter. It goes to the end of the ready queue of its domain. There is no preemption on input. +- **Only in the reader's window**: under a time partition table the byte is handed over only while the reader's domain runs. Otherwise it waits in the ring until the next tick at which that domain runs (see [scheduling.md](scheduling.md#console-input-under-a-table)). A terminal image runs with one domain, so this does not apply to it today. - **Waking on a capability change**: a waiter whose capability is deleted, revoked or moved wakes at once with `REVOKED`. - **Waking on a timeout**: a reader that gave a timeout in its flags is woken when it runs out (see [scheduling.md](scheduling.md) for timeouts). - **Quiet idle**: when the only thing left to wait for is console input, the kernel prints nothing. That is the normal state of a terminal image. `k0: all tasks stopped (none ready, no timeout pending)` is printed only when there is neither a timed waiter nor a console waiter. @@ -137,7 +138,7 @@ The vault side changed with this feature. There are four roles by endpoint badge ## How it is tested -**Host tests** (`tools/host-test.sh`): `k0-conin` has 19 tests with a fake UART, `k0-term` has 24 with the vault feature and 21 without, and `k0-vault` has 20 with Ed25519 and 11 without. The suite has 377 tests on an ARM host and 289 on other hosts (`k0-slice` adds 9). +**Host tests** (`tools/host-test.sh`): `k0-conin` has 19 tests with a fake UART, `k0-term` has 24 with the vault feature and 21 without, and `k0-vault` has 20 with Ed25519 and 11 without. The suite has 415 tests on an ARM host and 327 on other hosts. **Boot matrix**: the new rows are `input-only`, `input-gicv2`, `input-16550`, `input-bad-irq`, the static row `input-symbols` (an image without `console-input` has no receive code and none of the new log lines), `term`, `term-max`, `term-el2`, `term-gicv2`, `term-16k`, `term-no-vault`, `term-no-alg`, `term-uefi`, `term-uefi-acpi` and `hvf-term`. The matrix has 82 rows on a Mac with HVF and 71 in CI. @@ -154,6 +155,7 @@ The vault side changed with this feature. There are four roles by endpoint badge - **Kernel code driven from outside**: the receive code runs at EL1. - **A timing channel that is not analysed**: an outside party can now cause interrupts while tasks run, bounded by the reader for bytes and by 256 per tick for characters with a line error. The reader learns arrival times finer than the tick, and other tasks can notice the stolen time. - **Latency**: input waits behind running tasks. There are no priorities, so the latency is up to a tick per ready task, plus one more tick when the running task got the CPU between two ticks (see [scheduling.md](scheduling.md)). +- **One domain**: the root task deletes the control capability of the time partitions at the end of its self-tests, before it starts the services. The terminal, the vault and the root task therefore all run in the root domain, and the time partitions do not separate the vault from the terminal yet. The rule that input is handed over only in the reader's window has no test. - **No input on a 16550 console**: a 16550 console has output and no input. - **No measurement under a flood**: no test measures kernel time under a flood on a machine. The bound is argued from the gate and shown in host tests. - **Dropped before the prompt**: this counts bytes that reached the UART. An emulator or adapter that holds bytes back delivers them later (QEMU does). diff --git a/design/en/uefi.md b/design/en/uefi.md index 59f2ad7..a7c7068 100644 --- a/design/en/uefi.md +++ b/design/en/uefi.md @@ -183,7 +183,7 @@ The loader has no signature code. Under Secure Boot the firmware verifies the wh - **Host unit tests**: `crates/k0-efi/src/tests.rs` holds 32 tests. The vectors are measured firmware memory maps. They cover the descriptor rules, overlap, the entry limit, the writer, the rewrite, the verifier, the ACPI reader and the tree synthesis. A fourth fuzzer, `fuzz_acpi_with_mutated_tables`, mutates table images. Campaigns of 2 to 3 million cases passed on 2026-11-12, and it found one real mismatch earlier (the reader accepted a GIC frame alignment that the kernel's discovery refuses), which is fixed by applying the kernel's placement rules in the reader. - **Three deterministic fuzzers**: `fuzz_plan_with_random_maps`, `fuzz_rewrite_with_mutated_trees` and `fuzz_prepare_end_to_end` in `k0-efi`. They use the same variables as the other fuzzers: `K0_FUZZ_ITERS`, `K0_FUZZ_SEED`, `K0_FUZZ_CASE`. The defaults are 20,000, 20,000 and 5,000 cases. The weekly workflow runs all three at 5 million cases. Campaigns of 5 million cases each passed on 2026-11-12. The planner fuzzer found one real bug earlier (a block at physical address 0 was accepted). It is fixed. -- **Host test script**: `tools/host-test.sh` now runs 377 tests on an ARM host (`k0-abi` 15, `k0-cap` 52, `k0-boot` 85, `k0-efi` 33, `k0-conin` 19, `k0-slice` 9, `k0-vault` 20 with Ed25519 and 11 without, `k0-term` 24 with the vault feature and 21 without, and `k0-mm` 44 for each of the two granules) and 289 on other hosts, where the `k0-mm` tests are skipped. +- **Host test script**: `tools/host-test.sh` now runs 415 tests on an ARM host (`k0-abi` 15, `k0-cap` 54, `k0-boot` 85, `k0-efi` 33, `k0-conin` 19, `k0-slice` 9, `k0-part` 36, `k0-vault` 20 with Ed25519 and 11 without, `k0-term` 24 with the vault feature and 21 without, and `k0-mm` 44 for each of the two granules) and 327 on other hosts, where the `k0-mm` tests are skipped. - **PE check**: `tools/pe-check.py .efi` checks the PE form (four sections, none both writable and executable) and the order of the cache and MMU instructions, and prints `pe-check: ok (...)`. - **Boot tests under EDK2**: `tools/qemu-virt-runner.sh` boots a `.efi` argument through EDK2 firmware. The default machine is `virt,gic-version=3,acpi=off`, so it uses the device tree path. The ACPI rows pass `K0_QEMU_MACHINE=virt,gic-version=3` or `virt,gic-version=2`. `tools/qemu-boot-test.sh` judges a failure from the loader's first line, `k0-loader: start`, so firmware messages do not count. `tools/build-loader.sh ` embeds an already built kernel and prints the path of the `.efi`, which is `.efi`. This way the UEFI rows boot the same kernel binary as the other rows. The usage notes in [USAGE.md](../../USAGE.md) show the commands. diff --git a/design/en/user-address-space.md b/design/en/user-address-space.md index 91689f6..5444276 100644 --- a/design/en/user-address-space.md +++ b/design/en/user-address-space.md @@ -144,7 +144,7 @@ Capabilities for frames below a detached table keep their records. Those records ### TLB policy -K0 uses no hardware ASIDs. Switching `TTBR0` invalidates the whole TLB, and so does every unmap, every table detach and every address space destruction (`flush_user_tlb`). The TLB therefore only ever holds translations of the address space that is installed. `MAP` only turns an invalid entry into a valid one and needs no invalidation. +K0 uses no hardware ASIDs. Switching `TTBR0` invalidates the whole TLB, and so does every unmap, every table detach and every address space destruction (`flush_user_tlb`). The TLB therefore only ever holds translations of the address space that is installed. `MAP` only turns an invalid entry into a valid one and needs no invalidation. The scheduler also calls `flush_user_tlb` at every change of time partition domain, even when the address space stays the same, so that the next domain does not start with translations cached for the previous one (see [scheduling.md](scheduling.md#windows)). ### Destroying an address space diff --git a/design/en/vault.md b/design/en/vault.md index 6d6ec0b..89d2101 100644 --- a/design/en/vault.md +++ b/design/en/vault.md @@ -110,7 +110,7 @@ The operator can neither get a signature nor deliver a seed. A call without a ba The kernel derives 32 bytes for the root task with SHA-256 under its own domain string from the DTB entropy, the counter and, when the CPU has RNDR, four fresh RNDR words (`k0_boot::derive_root_seed`). It is independent of the PAC keys by domain separation. The seed is as good as its inputs and no better. -The seed is delivered in the root task's entry registers `x0` to `x3`. `x4` holds how many `rng-seed` bytes were used (bits 15 to 0), and bit 16 says that RNDR contributed. It is not in the bootinfo page, and `bootinfo::VERSION` is 4. The root task prints only `root: boot seed from rng-seed bytes 0x... and rndr` or `... without rndr`, never the seed. It then gives the seed to a vault with `INIT`, which only delivers it. The key is made later by `KEYGEN`. +The seed is delivered in the root task's entry registers `x0` to `x3`. `x4` holds how many `rng-seed` bytes were used (bits 15 to 0), and bit 16 says that RNDR contributed. It is not in the bootinfo page (`bootinfo::VERSION` is 5 today). The root task prints only `root: boot seed from rng-seed bytes 0x... and rndr` or `... without rndr`, never the seed. It then gives the seed to a vault with `INIT`, which only delivers it. The key is made later by `KEYGEN`. **Seed wipe**: the FDT parser records where the `rng-seed` and `kaslr-seed` values are, and a second `/chosen` node is refused (`DuplicateChosen`, also in the UEFI loader's pre-check, which shares the parser). Right before the kernel enters the root task, it zeroes those bytes. `k0_mm::wipe_ro_alias` switches the read-only alias entry of the page to read-write in place (break-before-make), writes zeros, cleans and invalidates the cache lines, and switches it back. The kernel then reads the bytes back, wipes its own copy in `BootInfo`, prints `k0: dtb seeds wiped B` (40B on QEMU virt) and zeroes the boot stack below the live frames. This is the only write the kernel makes through the DTB mapping, and it happens after the DTB was parsed and validated. @@ -147,7 +147,7 @@ You can build an image with the vault as follows: $ cargo build -p k0-kernel --features console,vault-ed25519 ``` -`crates/k0-boot/build.rs` forwards the feature to the nested build of the root task. The vault's code is part of the root task image, which is checked by SHA-256 at boot like before. Nothing is loaded after boot. With Ed25519 the image has 24 frames of 4 KiB (the limit is 78). +`crates/k0-boot/build.rs` forwards the feature to the nested build of the root task. The vault's code is part of the root task image, which is checked by SHA-256 at boot like before. Nothing is loaded after boot. With Ed25519 the image has 28 frames of 4 KiB (the limit is 77). ## How it is tested @@ -156,7 +156,7 @@ $ cargo build -p k0-kernel --features console,vault-ed25519 - always: `badges_map_to_fixed_roles_and_frames`, `each_role_may_do_exactly_its_operations`, `no_frame_is_touched_for_a_request_that_cannot_have_a_body`, `a_request_that_claims_a_body_it_cannot_have_is_refused`, `the_status_word_packs_state_algorithm_and_what_is_built`, `a_call_without_a_known_badge_is_denied`, `malformed_requests_are_refused_whole`, `a_seed_without_real_entropy_makes_no_key`, `the_seed_is_taken_once_and_zeroize_is_final`, `fetch_clamps_the_length_and_publish_writes_header_and_body`, and `without_an_algorithm_the_vault_takes_no_seed_and_serves_nothing` (the last one without the algorithm only). - with Ed25519: `the_self_test_passes_and_is_reported`, `key_generation_follows_the_states`, `the_operator_gets_the_public_key_and_never_a_signature`, `a_vault_that_fails_holds_no_secret`, `signatures_verify_and_the_key_follows_the_seed`, `a_public_key_request_carries_no_body`, `unknown_algorithms_are_unsupported`, `nothing_is_served_after_zeroize`, `a_small_order_public_key_is_refused_even_with_a_matching_signature`, `a_failed_vault_refuses_everything_but_status`. -With the other crates, the host suite has 377 tests on an ARM host and 289 on other hosts (without `k0-mm`), and `k0-slice` adds 9 of them. +With the other crates, the host suite has 415 tests on an ARM host and 327 on other hosts (without `k0-mm`). **Root task self-test** (`test_oracle` in `userspace/root-task/src/oracle.rs`, only in images built with `vault`). It checks the following: @@ -185,6 +185,7 @@ The marker is `root: oracle tests pass`. The client tasks run one after another - **The terminal and the vault are not restarted**: if they die, they stay dead. The root task is trusted. - **Availability is not protected**: clients share one endpoint and must use timeouts on every call (see [ipc.md](ipc.md)). Behind one CPU-bound task, a caller and the vault need 4 ticks per round trip in the scheduler model, where they needed 2. The terminal's calls use a 5 tick timeout, and the fixed image has no CPU-bound task in service mode. - **The root task is trusted**: it builds the vault and could read it. +- **No domain of its own**: the vault is not in a time partition domain of its own yet. The root task deletes the control capability of the time partitions at the end of its self-tests, so the vault, its clients and the terminal all run in the root domain, and what they learn about each other through the scheduler is not limited (see [scheduling.md](scheduling.md#time-partitions)). - **No client identity**: all signers share the one key. - **Entropy**: the seed is as good as its inputs. The key does not come from an approved random bit generator. - **Best-effort wipes**: see the note in the boot seed section. diff --git a/design/kr/README.md b/design/kr/README.md index 56dcaa9..3dd2db1 100644 --- a/design/kr/README.md +++ b/design/kr/README.md @@ -23,9 +23,11 @@ | [uefi_KR.md](uefi_KR.md) | UEFI 로더: 커널 밖에 두는 이유, 실행 흐름, RAM으로 인정하지 않는 메모리, 디바이스 트리 재작성, 점프 전 자가 검사, QEMU로 테스트할 수 없는 것, 부팅해 본 환경 | | [hardening_KR.md](hardening_KR.md) | PAC 키 파생, PAN, 카운터·디버그·PMU에 대한 EL0 접근 차단, 루트 태스크 무결성 검사와 각각이 아직 보호하지 못하는 것 | | [exceptions_KR.md](exceptions_KR.md) | 벡터 테이블, 사용자 상태 저장, 시스템 콜 디스패치, 폴트 격리 | -| [scheduling_KR.md](scheduling_KR.md) | TCB와 거기에 묶인 CNode, 주소 공간, 태스크 생성과 정리, 라운드 로빈 스케줄러, 타이머 선점, 두 틱 사이에 실행을 넘겨받은 태스크는 처음 만나는 틱에 끊기지 않는다는 규칙 | +| [scheduling_KR.md](scheduling_KR.md) | TCB와 거기에 묶인 CNode, 주소 공간, 태스크 생성과 정리, 라운드 로빈 스케줄러, 타이머 선점, 두 틱 사이에 실행을 넘겨받은 태스크는 처음 만나는 틱에 끊기지 않는다는 규칙. 고정 시간 분할: 도메인과 표, 창, 틱 시계, 보호 구간과 틱 시각까지의 대기, 제어 케이퍼빌리티와 두 시스템 콜, 테스트한 것과 모델에 대해 증명한 것, 주장의 한계 | | [ipc_KR.md](ipc_KR.md) | 엔드포인트와 배지, `SEND`, `RECV`, `CALL`, `REPLY_RECV`, 1회성 응답 자격, 엔드포인트가 삭제될 때 대기 중인 태스크의 처리 | | [vault_KR.md](vault_KR.md) | 서명 오라클: 볼트 태스크와 프레임, `CALL` 프로토콜과 nonce, 고정된 배지 정책, 프로바이더 경계, 부팅 시드와 지우기, feature, 테스트, 알려진 공백 | | [terminal_KR.md](terminal_KR.md) | 시리얼 입력과 운영자 터미널: 커널이 입력을 받는 이유, 수신 링과 그 한계, `CONSOLE_READ`와 Console 권한, 대기와 깨우기, 터미널의 연결과 적대적 태스크 점검, 화면과 명령 규칙, 테스트, 알려진 공백 | 모든 노트는 "**알려진 공백**" 절로 끝납니다. 열려 있는 보안 어드바이저리는 [SECURITY_KR.md](../../SECURITY_KR.md)에 정리되어 있습니다. + +시간 분할 스케줄러의 모델에 대한 Lean 4 증명은 이 노트들 밖의 [proofs/lean/README.md](../../proofs/lean/README.md)(영문)에 있습니다. 이것은 모델에 대한 증명이지 Rust 코드에 대한 증명이 아닙니다. diff --git a/design/kr/boot_KR.md b/design/kr/boot_KR.md index 84bd70d..cb99182 100644 --- a/design/kr/boot_KR.md +++ b/design/kr/boot_KR.md @@ -105,17 +105,17 @@ $ cargo build -p k0-kernel --offline --no-default-features --features granule-16 | `k0: platform ...` | `bring_up_platform`이 DTB에서 콘솔, 콘솔의 인터럽트(콘솔 노드에 쓸 만한 것이 있을 때), 인터럽트 컨트롤러, 타이머 인터럽트를 찾아 불변인 플랫폼 기술서 하나를 만듭니다. 디바이스 페이지를 매핑하기 전에 기술서를 메모리 맵과 대조합니다. RAM은 2^47 아래이면서 CPU의 물리 주소 폭 안에 있어야 하고, 커널 이미지와 DTB는 선언된 메모리 안에 있어야 하며, 그래뉼 단위로 넓힌 디바이스 구간은 메모리나 예약 구간과 겹치거나 CPU의 물리 주소 폭(`k0_mm::pa_bits`)을 넘으면 안 됩니다. 이 줄에는 콘솔 인터럽트 번호가 들어갑니다(예: `k0: platform con=pl011@0x9000000,irq33 ...`). 고정 모드에서는 이어서 이 줄을 기대값과 비교하므로, 이 필드가 생기기 전에 만든 고정 문자열은 더 이상 맞지 않아 다시 만들어야 합니다. 그 뒤에야 콘솔을 연결합니다. 이 종류의 콘솔 드라이버가 있는 이미지는 콘솔을 매핑하고 연결하며, 이때 버퍼에 쌓인 로그가 재생됩니다. 드라이버가 없는 이미지는 아무것도 매핑하지 않고 `k0: no console (driver not built in)`을 출력합니다. 플랫폼이 거부되더라도 콘솔만으로 대조를 통과하면(그리고 이미지가 고정 모드가 아니고 드라이버가 있으면) 사유가 보이도록 콘솔을 먼저 연결합니다. 콘솔이 없으면 `k0: no console (...)`이 이유를 알려 줍니다. [dtb_KR.md](dtb_KR.md)를 참고하세요. | | `k0: root task integrity ok (...)` | 내장 루트 태스크 이미지를 다시 해시하고 빌드 시점에 고정된 해시와 비교합니다. | | `k0: entropy ...`, `k0: pac=... bti=... pan=...` | PAC 키를 파생해 적재하고 키 워드를 부트 스택에서 지웁니다. 루트 태스크에 넘길 32바이트 시드도 여기서 PAC 키와 독립적으로 파생하여 이양까지 보관합니다. PAN을 켜고, 카운터·디버그·PMU에 대한 EL0 접근을 끕니다. [hardening_KR.md](hardening_KR.md)를 참고하세요. | -| `k0: irq on (timer 1s)` | `setup_irq`가 필요한 인터럽트 컨트롤러 페이지만 매핑합니다. GICv3는 리디스트리뷰터 프레임을 하나씩 들여다보며 부트 CPU의 프레임을 찾은 뒤, 그 프레임과 SGI 프레임만 매핑합니다. 드라이버는 GIC 식별 레지스터가 DTB의 설명과 맞는지 확인합니다. EL1 가상 타이머는 플랫폼 기술서의 인터럽트 번호로 설정합니다. IRQ와 SError의 마스크를 해제합니다. | +| `k0: irq on (timer 1s)` | `setup_irq`가 필요한 인터럽트 컨트롤러 페이지만 매핑합니다. GICv3는 리디스트리뷰터 프레임을 하나씩 들여다보며 부트 CPU의 프레임을 찾은 뒤, 그 프레임과 SGI 프레임만 매핑합니다. 드라이버는 GIC 식별 레지스터가 DTB의 설명과 맞는지 확인합니다. EL1 가상 타이머는 플랫폼 기술서의 인터럽트 번호로 설정합니다. 이 시점에 읽은 카운터 값이 0번 틱의 시각이고, 그 뒤의 모든 틱은 거기서 정수 초 뒤에 옵니다([scheduling_KR.md](scheduling_KR.md#틱-시계와-건너뛴-틱) 참고). IRQ와 SError의 마스크를 해제합니다. | | `k0: kernel table pool N/40` | 2 MiB 부트 프레임 윈도우를 고르고 매핑한 뒤, 사용 중인 커널 페이지 테이블 수를 출력합니다(예: QEMU virt에서 `16/40`). 40개짜리 정적 풀은 부트 중에만 사용합니다. | | `k0: root task loaded (entry ...)` | 루트 태스크를 윈도우의 프레임에 복사하고, 윈도우에 루트 TCB를 만들고, 주소 공간을 만듭니다. 커널은 사용자 루트 테이블의 물리 주소를 출력하지 않습니다. 이후 이 주소 공간을 주소 공간 등록부에 올립니다. [user-address-space_KR.md](user-address-space_KR.md)를 참고하세요. | -| `k0: memory + not handed out ()`(일어날 때만), `k0: kernel reserve tables + address space entries = bytes in ranges` | `reserve_kernel_share`가 untyped 케이퍼빌리티가 만들어지기 전에 비어 있는 물리 범위마다 커널 몫을 떼어 냅니다("untyped 메모리에서 커널 몫 떼어 내기" 참고). 자기 몫을 담지 못하는 범위는 넘기지 않으며, 이때 커널은 첫 번째 종류의 줄에 이유를 출력합니다. 두 번째 줄은 한 번 출력됩니다. 예를 들어 512 MiB, 4 KiB 그래뉼의 QEMU virt에서는 `k0: kernel reserve 262 tables + 130130 address space entries = 0x206000 bytes in 3 ranges`입니다. | -| `k0: untyped ...`, `k0: root cnode ready (N caps, N untyped, N image frames, N slots)` | 루트 CNode(윈도우 안의 오브젝트이며 슬롯은 `ROOT_CNODE_SLOTS` = 512개, 로그에도 그렇게 나옵니다)를 채웁니다. 슬롯 1은 루트 TCB, 2는 루트 주소 공간, 3은 콘솔, 4는 루트 CNode 자신이고, 이어서 넘기기로 한 비어 있는 물리 범위마다 untyped 케이퍼빌리티, 루트 태스크 이미지의 매핑된 그래뉼마다 Frame 케이퍼빌리티 하나(text는 R과 X, 읽기 전용 데이터는 R, 데이터는 R과 W)가 들어갑니다. 마지막으로 루트 태스크를 다른 태스크와 똑같이 자신의 CNode와 주소 공간에 묶습니다. 두 케이퍼빌리티의 복사본이 TCB에 들어갑니다. [capabilities_KR.md](capabilities_KR.md)를 참고하세요. | +| `k0: memory + not handed out ()`(일어날 때만), `k0: kernel reserve tables + address space entries = bytes in ranges` | `reserve_kernel_share`가 untyped 케이퍼빌리티가 만들어지기 전에 비어 있는 물리 범위마다 커널 몫을 떼어 냅니다("untyped 메모리에서 커널 몫 떼어 내기" 참고). 자기 몫을 담지 못하는 범위는 넘기지 않으며, 이때 커널은 첫 번째 종류의 줄에 이유를 출력합니다. 두 번째 줄은 한 번 출력됩니다. 예를 들어 512 MiB, 4 KiB 그래뉼의 QEMU virt에서는 `k0: kernel reserve 262 tables + 130124 address space entries = 0x206000 bytes in 3 ranges`입니다. | +| `k0: untyped ...`, `k0: root cnode ready (N caps, N untyped, N image frames, N slots)` | 루트 CNode(윈도우 안의 오브젝트이며 슬롯은 모든 이미지에서 `ROOT_CNODE_SLOTS` = 1024개, 로그에도 그렇게 나옵니다)를 채웁니다. 슬롯 1은 루트 TCB, 2는 루트 주소 공간, 3은 콘솔, 4는 루트 CNode 자신, 5는 시간 분할의 제어 케이퍼빌리티(`PartCtl`)이고, 이어서 슬롯 6부터 넘기기로 한 비어 있는 물리 범위마다 untyped 케이퍼빌리티, 루트 태스크 이미지의 매핑된 그래뉼마다 Frame 케이퍼빌리티 하나(text는 R과 X, 읽기 전용 데이터는 R, 데이터는 R과 W)가 들어갑니다. 마지막으로 루트 태스크를 다른 태스크와 똑같이 자신의 CNode와 주소 공간에 묶습니다. 두 케이퍼빌리티의 복사본이 TCB에 들어갑니다. [capabilities_KR.md](capabilities_KR.md)를 참고하세요. | | `k0: console input on (pl011 irq 33)` 또는 `k0: console input off ()` | `console-input`으로 빌드한 이미지만 플랫폼이 받아들여진 직후에 출력합니다. "선택적 콘솔 입력"을 참고하십시오. | -| `k0: bootinfo page ready` | 케이퍼빌리티 목록을 읽기 전용 bootinfo 페이지(레이아웃 버전 4)에 기록합니다. 헤더와 슬롯마다 하나의 디스크립터이며, 이미지 Frame마다 VA, 크기, 권한이 들어갑니다. 이 페이지에는 부트 시드가 들어 있지 않습니다. | +| `k0: bootinfo page ready` | 케이퍼빌리티 목록을 읽기 전용 bootinfo 페이지(레이아웃 버전 5)에 기록합니다. 헤더와 슬롯마다 하나의 디스크립터이며, 이미지 Frame마다 VA, 크기, 권한이 들어갑니다. 이 페이지에는 부트 시드가 들어 있지 않습니다. | | `k0: user w^x checks pass` | `TTBR0`가 사용자 테이블을 가리키고, identity 매핑은 사라졌으며, 사용자 매핑을 EL0와 EL1 양쪽에서 검사합니다. | | `k0: dtb seeds wiped B` | 이제 DTB는 필요 없으므로 커널이 그 안의 `rng-seed`와 `kaslr-seed` 바이트를 0으로 지웁니다(읽기 전용 별칭을 쓰는 동안만 읽기·쓰기로 바꿈). 지운 바이트를 다시 읽어 확인하고, 커널이 가진 자기 사본도 지웁니다. QEMU virt에서는 `40B`입니다. 다시 읽은 값이 0이 아니면 줄은 `k0: WARNING dtb seeds not wiped`가 됩니다. [hardening_KR.md](hardening_KR.md)를 참고하세요. | | `k0: device pages [...] of 0x1000 bytes` | 커널이 매핑한 채로 두는 모든 디바이스 페이지입니다. 이 줄 뒤에 커널은 더 이상 디바이스를 매핑하지 않습니다. | -| `k0: entering root task (el0)` | `k0_sched::handoff`가 EL0로 진입합니다. 부트 시드는 루트 태스크의 진입 레지스터 `x0`부터 `x3`으로 전달되고, `x4`는 `rng-seed` 바이트가 몇 개 들어갔는지와 `RNDR`이 들어갔는지를 알립니다. 이 줄 직후에 커널은 살아 있는 프레임 아래의 부트 스택을 0으로 채웁니다. | +| `k0: entering root task (el0)` | `k0_sched::handoff`가 인터럽트를 마스크하고, 기본 시간 분할 표(도메인 하나)로 스케줄러를 시작한 뒤 EL0로 진입합니다. 부트 시드는 루트 태스크의 진입 레지스터 `x0`부터 `x3`으로 전달되고, `x4`는 `rng-seed` 바이트가 몇 개 들어갔는지와 `RNDR`이 들어갔는지를 알립니다. 이 줄 직후에 커널은 살아 있는 프레임 아래의 부트 스택을 0으로 채웁니다. | | `root: boot seed from rng-seed bytes 0x... and rndr` 또는 `... without rndr` | 커널이 아니라 루트 태스크가 초기에 출력하는 줄입니다. bootinfo 버전을 확인한 뒤 시드 재료가 어디서 왔는지를 출력하며, 시드 자체는 출력하지 않습니다. | ### 부트 프레임 윈도우 고르기 @@ -146,7 +146,9 @@ $ cargo build -p k0-kernel --offline --no-default-features --features granule-16 루트 태스크는 레지스터 `x0`부터 `x3`에 부트 시드를, `x4`에 시드 정보 워드를 담고 시작합니다. 이 값은 저장된 컨텍스트에 있으며, 루트 태스크가 처음 커널에 들어올 때 그 시점의 자기 레지스터로 덮입니다. 스택에 있던 커널의 시드 사본은 그 전에 0으로 지웠고, 위 표에서 설명한 스택 지우기는 최선의 노력입니다. `kernel_main`의 살아 있는 프레임은 지울 수 없기 때문입니다. [hardening_KR.md](hardening_KR.md)를 참고하세요. -`handoff`는 루트 태스크를 실행 중인 태스크로 기록하고, 벡터 코드가 루트 태스크의 저장된 컨텍스트를 가리키게 합니다. 이어서 `enter_user`가 모든 예외를 마스크(`DAIFSet`)하고, 커널 스택을 꼭대기로 되감은 뒤, 이후의 모든 복귀가 사용하는 것과 같은 경로로 EL0에 복귀합니다. **마스크를 먼저 하는 이유**는 이 경로가 `eret` 전에 `ELR_EL1`과 `SPSR_EL1`을 기록하기 때문입니다. 부트 경로는 이미 타이머를 언마스크했으므로, 그 사이에 인터럽트가 들어오면 두 레지스터가 EL1 값으로 덮입니다. 이때부터 커널 코드는 예외에 대한 응답으로만 실행됩니다. 시스템 콜, 폴트, 타이머 인터럽트가 그 예외입니다. 이 경로는 [exceptions_KR.md](exceptions_KR.md)에서 설명합니다. +`handoff`는 먼저 인터럽트를 마스크하고, 그런 다음에야 틱 번호를 읽고, 루트 태스크를 실행 중인 태스크로 기록하고, 벡터 코드가 루트 태스크의 저장된 컨텍스트를 가리키게 합니다. 이 순서가 중요합니다. 틱 번호를 읽은 뒤 EL0에 진입하기 전에 틱이 하나 세어지면 스케줄러가 타이머보다 한 틱 뒤처지기 때문입니다. 그 사이에 보류된 틱은 진입 직후에 보통의 틱으로 받습니다. 이어서 `enter_user`가 모든 예외를 마스크(`DAIFSet`)하고, 커널 스택을 꼭대기로 되감은 뒤, 이후의 모든 복귀가 사용하는 것과 같은 경로로 EL0에 복귀합니다. **마스크를 먼저 하는 이유**는 이 경로가 `eret` 전에 `ELR_EL1`과 `SPSR_EL1`을 기록하기 때문입니다. 부트 경로는 이미 타이머를 언마스크했으므로, 그 사이에 인터럽트가 들어오면 두 레지스터가 EL1 값으로 덮입니다. 이때부터 커널 코드는 예외에 대한 응답으로만 실행됩니다. 시스템 콜, 폴트, 타이머 인터럽트가 그 예외입니다. 이 경로는 [exceptions_KR.md](exceptions_KR.md)에서 설명합니다. + +루트 태스크는 자가 테스트를 하는 동안에만 시간 분할의 제어 케이퍼빌리티를 가집니다. 이 메커니즘을 시험해 본 뒤(`root: partition refusal pass`, `root: partition window pass`) 끝에서 케이퍼빌리티를 삭제합니다(`root: partition sealed`). 이 줄 뒤로 이미지는 도메인 하나로 실행되고, 다음 부팅까지 어떤 것도 이를 바꿀 수 없습니다([scheduling_KR.md](scheduling_KR.md#시간-분할) 참고). ## 부트 로그 diff --git a/design/kr/capabilities_KR.md b/design/kr/capabilities_KR.md index 53d7a0c..bd73b14 100644 --- a/design/kr/capabilities_KR.md +++ b/design/kr/capabilities_KR.md @@ -23,7 +23,7 @@ | `crates/k0-abi/src/lib.rs` | 번호와 에러 코드(ABI의 기준) | > [!IMPORTANT] -> 이 모델과 함께 시스템 콜 ABI가 호환되지 않게 바뀌었습니다(bootinfo 버전 2, 현재 4). 이 내용에 의존하기 전에 "알려진 공백" 절을 먼저 읽어 주세요. +> 이 모델과 함께 시스템 콜 ABI가 호환되지 않게 바뀌었습니다(bootinfo 버전 2, 현재 5). 버전 5에서 첫 untyped 슬롯이 옮겨 갔으므로, 이전 버전에 맞춰 빌드한 루트 태스크는 이 커널에서 실행되지 않습니다. 이 내용에 의존하기 전에 "알려진 공백" 절을 먼저 읽어 주세요. 케이퍼빌리티 기반 격리가 다루는 것은 태스크 간 기밀성과 무결성입니다. 가용성은 포함하지 않습니다. @@ -67,6 +67,7 @@ | `CNode` | `RETYPE`으로, 그리고 루트 CNode용으로 부팅 시 | 슬롯 배열. 케이퍼빌리티 공간이자 복사와 이동의 목적지로 쓰임 | | `AddrSpace` | `RETYPE`으로, 그리고 루트 태스크용으로 부팅 시 | 주소 공간. 그 안에 매핑하고 그 안에서 태스크를 실행할 권한 | | `Console` | 부팅 시 | 디버그 출력에 바이트를 쓸 권한(`W`). 부트 로그, 그리고 콘솔 드라이버를 포함해 빌드한 이미지에서는 콘솔. `R`이 있으면 `console-input`으로 빌드한 이미지에서 콘솔 입력을 읽을 권한도 됨 | +| `PartCtl` | 부팅 시, 정확히 하나 | 시간 분할 표를 정하고, 아직 실행된 적 없는 태스크를 도메인에 넣을 권한([scheduling_KR.md](scheduling_KR.md#시간-분할) 참고). 가리키는 오브젝트가 없고 복사할 수 없음 | ### 권한 @@ -106,7 +107,7 @@ ## 루트 CNode와 부트 케이퍼빌리티 -루트 태스크의 CNode가 루트 CNode입니다. 슬롯은 `ROOT_CNODE_SLOTS`(512)개이고, bootinfo 페이지, 루트 TCB, 루트 태스크의 이미지, 스택, 페이지 테이블과 함께 2 MiB 부트 프레임 윈도우에 있습니다. 이 부트 오브젝트들은 untyped가 아니므로 retype될 수 없습니다. 부트 케이퍼빌리티는 모두 원본이고, 각각 독립된 파생 리스트의 뿌리(깊이 0)입니다. +루트 태스크의 CNode가 루트 CNode입니다. 슬롯은 모든 이미지에서 `ROOT_CNODE_SLOTS`(1024)개이고, bootinfo 페이지, 루트 TCB, 루트 태스크의 이미지, 스택, 페이지 테이블과 함께 2 MiB 부트 프레임 윈도우에 있습니다. 이 부트 오브젝트들은 untyped가 아니므로 retype될 수 없습니다. 부트 케이퍼빌리티는 모두 원본이고, 각각 독립된 파생 리스트의 뿌리(깊이 0)입니다. `bootstrap`은 다음 표의 순서로 루트 CNode를 채웁니다. @@ -117,7 +118,8 @@ | 2 | 루트 태스크의 `AddrSpace` | | 3 | `W`가 있는 `Console`. `R`은 `console-input`으로 빌드한 이미지에만 있음 | | 4 | `CNode`. 루트 CNode 자신에 대한 케이퍼빌리티로, 복사와 이동의 목적지로 쓸 수 있음 | -| 5 이후 | `Untyped` 케이퍼빌리티들, 그다음 루트 태스크 이미지의 매핑된 그래뉼마다 `Frame` 케이퍼빌리티 하나 | +| 5 | `PartCtl`. 시간 분할의 제어 케이퍼빌리티 | +| 6 이후 | `Untyped` 케이퍼빌리티들, 그다음 루트 태스크 이미지의 매핑된 그래뉼마다 `Frame` 케이퍼빌리티 하나 | 이미지 `Frame` 케이퍼빌리티의 권한은 세그먼트로 정해집니다. 텍스트는 `R|X`(`W` 없음), 읽기 전용 데이터는 `R`, 데이터는 `R|W`(`X` 없음)입니다. `X`를 가진 프레임은 시스템 전체에서 이 텍스트 프레임뿐이며, 그 내용은 부팅 시 해시 검증을 통과한 이미지입니다. 루트 태스크 자신의 부트 매핑은 영구적이고 이 케이퍼빌리티로 표현되지 않습니다. @@ -139,7 +141,7 @@ untyped 케이퍼빌리티는 디바이스 트리가 보고한 RAM의 모든 바 ## bootinfo 페이지 -이양 직전에 커널은 루트 CNode의 설명을 bootinfo 페이지에 기록합니다. 이 페이지는 루트 태스크에 읽기 전용으로 `bootinfo::VA`에 매핑됩니다. 버전은 4입니다(`bootinfo::VERSION`). 페이지 레이아웃은 버전 2와 같습니다. 버전 3은 루트 태스크가 진입 레지스터로 부트 시드를 받게 되어 생겼으며(시드는 `x0..x3`, 그 설명은 `x4`)(자세한 내용은 [boot_KR.md](boot_KR.md) 참고), 시드는 이 페이지에 없습니다. 버전 4는 `Console` 케이퍼빌리티에 권한이 생겨 만들어졌습니다. 다른 버전이면 루트 태스크는 진행하면 안 됩니다. +이양 직전에 커널은 루트 CNode의 설명을 bootinfo 페이지에 기록합니다. 이 페이지는 루트 태스크에 읽기 전용으로 `bootinfo::VA`에 매핑됩니다. 버전은 5입니다(`bootinfo::VERSION`). 페이지 레이아웃은 버전 2와 같습니다. 버전 3은 루트 태스크가 진입 레지스터로 부트 시드를 받게 되어 생겼으며(시드는 `x0..x3`, 그 설명은 `x4`)(자세한 내용은 [boot_KR.md](boot_KR.md) 참고), 시드는 이 페이지에 없습니다. 버전 4는 `Console` 케이퍼빌리티에 권한이 생겨 만들어졌습니다. 버전 5는 슬롯 5에 `PartCtl`이 들어가면서 첫 untyped 케이퍼빌리티가 슬롯 5에서 슬롯 6으로 옮겨 가 만들어졌습니다. 다른 버전이면 루트 태스크는 진행하면 안 됩니다. 페이지는 헤더 `{version, frame_size, cap_count, cnode_slots}`로 시작하고, 그 뒤에 `cap_count`개의 디스크립터 `{kind, base, size, rights}`가 이어집니다. 디스크립터의 인덱스가 곧 루트 CNode의 슬롯 번호이며, `cap_count` 이상의 슬롯은 전부 비어 있습니다. 디스크립터는 종류에 따라 다음과 같이 채워집니다. @@ -147,7 +149,7 @@ untyped 케이퍼빌리티는 디바이스 트리가 보고한 RAM의 모든 바 - **이미지 Frame**: `base`는 그 그래뉼이 루트 주소 공간에 매핑된 가상 주소, `size`는 프레임 크기, `rights`는 권한 비트입니다. - **그 외**: 전부 0이므로 커널 오브젝트 주소가 드러나지 않습니다. 커널은 이제 루트 페이지 테이블의 물리 주소도 출력하지 않습니다. -이 페이지는 스냅샷입니다. 이후에 `RETYPE`으로 만든 케이퍼빌리티는 슬롯을 호출자가 선택하므로 여기에 나타나지 않습니다. 루트 이미지가 bootinfo 페이지로 서술할 수 있는 수보다 많은 4 KiB 프레임을 매핑하면 `crates/k0-boot/build.rs`가 빌드를 실패시킵니다. +이 페이지는 스냅샷입니다. 이후에 `RETYPE`으로 만든 케이퍼빌리티는 슬롯을 호출자가 선택하므로 여기에 나타나지 않습니다. 루트 이미지가 bootinfo 페이지로 서술할 수 있는 수보다 많은 4 KiB 프레임을 매핑하면 `crates/k0-boot/build.rs`가 빌드를 실패시킵니다. 한도는 프레임 77개입니다. 페이지는 디스크립터 127개를 담고, 그중 6개는 고정 슬롯(null 슬롯 포함)이며, untyped는 많아야 44개이기 때문입니다. ## Retype @@ -211,9 +213,9 @@ untyped에서 파생된 것이 모두 사라지면 메모리가 그 untyped로 - `mask`는 `R|W|X`의 부분집합이어야 하며, 아니면 `BAD_PERM`입니다. `mask`는 `Frame`이나 `Endpoint`의 권한과 AND됩니다. 남는 권한이 없으면 `NO_RIGHTS`입니다. - `badge`는 앞에서 설명한 규칙을 따릅니다. - 복사본의 매핑 기록은 비어 있고, 복사본은 원본이 아닙니다. -- `Untyped`와 `PageTable`은 복사할 수 없습니다(`BAD_CAP`). untyped를 복사하면 같은 메모리를 두 번 retype할 수 있고, 페이지 테이블을 복사하면 두 주소 공간에 설치할 수 있기 때문입니다. +- `Untyped`, `PageTable`, `PartCtl`은 복사할 수 없습니다(`BAD_CAP`). untyped를 복사하면 같은 메모리를 두 번 retype할 수 있고, 페이지 테이블을 복사하면 두 주소 공간에 설치할 수 있기 때문입니다. `PartCtl`은 하나로 남아야 삭제했을 때 시간 분할 표가 영구히 봉인됩니다. 복사 규칙은 모든 종류를 하나씩 적으므로, 나중에 추가하는 종류는 그 규칙을 작성하기 전에는 컴파일되지 않습니다. -`CAP_MOVE(src, cnode, index)`는 케이퍼빌리티를 빈 슬롯으로 옮깁니다. 리스트에서의 위치와 매핑 기록이 함께 따라갑니다. TCB에 묶인 케이퍼빌리티는 옮길 수 없습니다(`BAD_CAP`). `Untyped`와 `PageTable`은 옮길 수 있으며, 이것이 다른 CNode로 넘기는 유일한 방법입니다. +`CAP_MOVE(src, cnode, index)`는 케이퍼빌리티를 빈 슬롯으로 옮깁니다. 리스트에서의 위치와 매핑 기록이 함께 따라갑니다. TCB에 묶인 케이퍼빌리티는 옮길 수 없습니다(`BAD_CAP`). `Untyped`, `PageTable`, `PartCtl`은 옮길 수 있으며, 이것이 다른 CNode로 넘기는 유일한 방법입니다. `CAP_REVOKE(slot)`은 슬롯의 자손을 전부 제거하고 슬롯 자신은 남깁니다. @@ -236,6 +238,7 @@ untyped를 회수하면 거기서 잘라낸 것이 전부 종료됩니다. 조 - **Console**: 이 케이퍼빌리티로 `CONSOLE_READ`에서 기다리던 태스크는 케이퍼빌리티가 삭제, 회수, 이동되면 즉시 `REVOKED`로 깨어납니다([ipc_KR.md](ipc_KR.md) 참고). - **Tcb**(원본), 그리고 태스크에 묶인 모든 케이퍼빌리티: 그 태스크를 종료시킵니다. [scheduling_KR.md](scheduling_KR.md)와 [ipc_KR.md](ipc_KR.md)를 참고하세요. - **AddrSpace**(원본): 등록부에서 해제하고(이때 세대가 올라갑니다), TTBR0에 설치돼 있으면 TTBR0를 커널 풀의 빈 테이블로 바꿉니다. +- **PartCtl**: 종료시킬 오브젝트가 없습니다. 다른 `PartCtl`은 없고 새로 만들 수도 없으므로, 이것을 제거하면 시간 분할 표와 태스크의 도메인을 더 이상 바꿀 수 없게 됩니다([scheduling_KR.md](scheduling_KR.md#제어-케이퍼빌리티와-두-시스템-콜) 참고). **매핑 기록**은 `(asid, 세대, va, 레벨)`입니다. `asid`는 주소 공간의 루트 테이블이 놓인 그래뉼의 번호이고 `u64`입니다(`Cap::AddrSpace`의 번호와 같음). 워드를 해석할 때 검사합니다. 해제, 삭제, 회수는 등록부가 여전히 같은 주소 공간이라고 확인한 루트만 걷고, 정확히 그 프레임이나 테이블을 가리키는 엔트리만 지웁니다. [user-address-space_KR.md](user-address-space_KR.md)를 참고하세요. @@ -256,6 +259,8 @@ untyped를 회수하면 거기서 잘라낸 것이 전부 종료됩니다. 조 | `UNMAP` | 매핑된 `Frame` 또는 `PageTable` | | `TCB_CONFIGURE` | `Inactive` 상태의 `Tcb`, `AddrSpace`, `CNode` | | `TCB_RESUME` | `Stopped` 상태의 `Tcb` | +| `PART_SET_TABLE` | `PartCtl` | +| `PART_SET_DOMAIN` | `PartCtl`, 그리고 `Stopped` 상태의 `Tcb` | | `SEND`, `CALL` | `W`를 가진 `Endpoint` | | `RECV`, `REPLY_RECV` | `R`을 가진 `Endpoint` | | `CAP_COPY` | 원본, 그리고 목적지를 지정하는 `CNode` | @@ -265,7 +270,7 @@ untyped를 회수하면 거기서 잘라낸 것이 전부 종료됩니다. 조 > [!IMPORTANT] > 암묵 권한은 없습니다. `MAP`의 타겟은 항상 호출자가 제시한 `AddrSpace`이며 "현재 주소 공간"이 아닙니다. -`TCB_CONFIGURE`는 원자적입니다. 두 바인딩을 모두 검증한 뒤에야 기록하고, 실패하면 두 내장 슬롯은 비어 있는 그대로입니다. `Inactive` TCB에서만 허용되고, 저장 상태를 EL0t로 강제하며, 새 태스크에게 인자를 `x0`으로 전달합니다. +`TCB_CONFIGURE`는 원자적입니다. 두 바인딩을 모두 검증한 뒤에야 기록하고, 실패하면 두 내장 슬롯은 비어 있는 그대로입니다. `Inactive` TCB에서만 허용되고, 저장 상태를 EL0t로 강제하며, 새 태스크에게 인자를 `x0`으로 전달하고, 새 태스크를 호출자의 시간 분할 도메인에 넣습니다. 매핑이 `RO`, `RW`, `RX`로 제한되고 `X`가 루트 태스크의 텍스트 프레임(`W` 없음)에만 있으므로, 어떤 물리 프레임도 한곳에서 쓰기 가능하면서 다른 곳에서 실행 가능할 수 없습니다. 그 결과 부팅 이후에는 새 실행 코드를 올릴 수 없고, 격리된 태스크는 루트 태스크 이미지의 코드를 실행합니다. @@ -298,6 +303,7 @@ untyped를 회수하면 거기서 잘라낸 것이 전부 종료됩니다. 조 - 잘못된 소스가 준비 단계 전에 거부되는지 - retype된 프레임이 실행 권한을 갖지 않는지 - 종류별 복사 규칙 + - `PartCtl`이 마스크와 배지가 무엇이든 복사되지 않는지, 옮길 수는 있는지, 다른 값이 함께 든 `PartCtl` 워드가 디코드되지 않는지 - 이동해도 하위 트리가 붙어 있는지 - 삭제가 원본일 때만 종료시키는지 - untyped 메모리가 아무것도 남지 않았을 때만 재사용되는지 @@ -341,7 +347,7 @@ untyped를 회수하면 거기서 잘라낸 것이 전부 종료됩니다. 조 - 모든 오브젝트는 정확히 1 그래뉼이고 untyped는 쪼갤 수 없습니다. - IPC를 통한 케이퍼빌리티 전송이 없습니다. - 하드웨어 ASID를 사용하지 않으며, TTBR0 교체와 모든 해제, 테이블 분리, 주소 공간 파괴는 TLB 전체를 비웁니다. -- **제어 케이퍼빌리티**: 전부 아니면 전무입니다. `Tcb`, `CNode`, `AddrSpace` 케이퍼빌리티는 권한을 갖지 않으므로 권한을 줄인 복사본을 만들 수 없습니다. 이런 케이퍼빌리티를 쥔 쪽은 그 오브젝트를 완전히 통제하며, 어떤 태스크의 TCB나 CNode, 주소 공간의 케이퍼빌리티를 쥔 쪽이 그 태스크를 통제합니다. +- **제어 케이퍼빌리티**: 전부 아니면 전무입니다. `Tcb`, `CNode`, `AddrSpace` 케이퍼빌리티는 권한을 갖지 않으므로 권한을 줄인 복사본을 만들 수 없습니다. 이런 케이퍼빌리티를 쥔 쪽은 그 오브젝트를 완전히 통제하며, 어떤 태스크의 TCB나 CNode, 주소 공간의 케이퍼빌리티를 쥔 쪽이 그 태스크를 통제합니다. `PartCtl`도 전부 아니면 전무입니다. 케이퍼빌리티 하나가 표와 모든 태스크의 도메인을 다루며, 표를 정하는 부분과 태스크를 배치하는 부분으로 나눌 수 없습니다. - **부팅 이후 새 코드**: 올릴 수 없습니다. 케이퍼빌리티 권한으로 보장하는 W^X 때문에 실행 가능한 메모리는 루트 태스크 이미지에만 있습니다. - **회수 중 인터럽트**: 마스크됩니다. `CAP_REVOKE`와 `CAP_DELETE`의 시간은 제거되는 케이퍼빌리티 수에 비례합니다. - **여기서 검증하지 못한 것**: 3단계 전부입니다. 실제 보드, KVM, Firecracker, Cloud Hypervisor, crosvm, 16550 콘솔 드라이버(실행한 적 없음), 하드웨어의 실제 보안 확장이 있는 GIC, `HCR_EL2.E2H`가 1로 고정된 CPU(이 경로는 Linux를 따랐고 어디에서도 실행하지 않았습니다)가 해당합니다. 1단계(`tools/boot-matrix.sh`, CI와 로컬에서 실행)와 2단계(2026-11-11과 2026-11-12에 손으로, Apple M5 Pro, QEMU HVF)가 지원 범위입니다. UEFI 행은 [uefi_KR.md](uefi_KR.md)에 있습니다. diff --git a/design/kr/exceptions_KR.md b/design/kr/exceptions_KR.md index f77fead..0fcb2ae 100644 --- a/design/kr/exceptions_KR.md +++ b/design/kr/exceptions_KR.md @@ -6,7 +6,7 @@ -이양 이후 **커널 코드는 예외에 응답할 때만 실행됩니다**. 이 문서는 벡터 테이블, 사용자 상태를 저장하고 복원하는 방법, 시스템 콜을 디스패치하는 방법, 폴트를 일으킨 태스크를 격리하는 방법을 설명합니다. 코드는 `crates/k0-arch/src/vectors.S`, `vectors.rs`, `usermode.rs`, `irq.rs`, 그리고 `kernel/src/syscall.rs`의 `k0_syscall`, `k0_fault`, `k0_preempt`, `finish`에 있습니다. 이 문서는 현재 `main` 브랜치(미배포)를 기준으로 합니다. +이양 이후 **커널 코드는 예외에 응답할 때만 실행됩니다**. 이 문서는 벡터 테이블, 사용자 상태를 저장하고 복원하는 방법, 시스템 콜을 디스패치하는 방법, 폴트를 일으킨 태스크를 격리하는 방법을 설명합니다. 코드는 `crates/k0-arch/src/vectors.S`, `vectors.rs`, `usermode.rs`, `irq.rs`, 그리고 `kernel/src/syscall.rs`의 `k0_syscall`, `k0_fault`, `k0_preempt`, `k0_leave`, `finish`, `wait_for_work`에 있습니다. 이 문서는 현재 `main` 브랜치(미배포)를 기준으로 합니다. 다음 그림은 예외 종류별로 커널이 어떤 경로를 따르는지 보여 줍니다. @@ -43,7 +43,7 @@ fatal 엔트리는 **스택 포인터를 신뢰하지 않습니다**. 폴트가 ### 커널 안에서 발생한 인터럽트 -EL1에서 받은 IRQ는 caller-saved 레지스터를 커널 스택에 저장하고, 핸들러를 호출한 뒤 복귀합니다. 커널은 예외를 처리하는 동안 인터럽트를 마스크한 채로 둡니다. 예외는 `idle_until_ready`의 대기([종료 경로](#종료-경로) 참고) 하나뿐입니다. 커널 자체는 선점되지 않습니다. +EL1에서 받은 IRQ는 caller-saved 레지스터를 커널 스택에 저장하고, 핸들러를 호출한 뒤 복귀합니다. 커널은 예외를 처리하는 동안 인터럽트를 마스크한 채로 둡니다. 예외는 `wait_for_work`의 대기([종료 경로](#종료-경로) 참고) 하나뿐입니다. 커널 자체는 선점되지 않습니다. 대기 중에는 `k0_arch::irq::wait_for_interrupt`가 대기 중인 인터럽트 하나를 위해 I 비트만 엽니다(IRQ를 마스크한 채 `wfi`를 실행하고, 이어서 짧게 마스크를 해제함). 이것이 안전한 이유는 세 가지입니다. 첫째, ELR_EL1과 SPSR_EL1을 포함한 EL0 컨텍스트 전체가 이미 TCB에 저장되어 있으므로, 중첩된 EL1 IRQ가 두 레지스터를 덮어써도 잃는 것이 없습니다. 둘째, 핸들러는 커널 스택에서 실행되며, 예외 진입이 스택 최상단에서 시작하므로 여유가 충분합니다. 셋째, 인터럽트를 받은 직후 마스크를 다시 설정하므로 다른 커널 코드는 인터럽트가 열린 채 실행되지 않습니다. @@ -68,7 +68,7 @@ EL1에서 받은 IRQ는 caller-saved 레지스터를 커널 스택에 저장하 핸들러는 이 컨텍스트에 대한 가변 참조를 받으며 컨텍스트를 바꿀 수 있습니다. 반환값을 기록하거나, 프로그램 카운터를 진행시키거나, `__current_context`가 다른 태스크를 가리키게 할 수 있습니다. 핸들러가 반환하면 실행은 `__user_restore`로 이어집니다. 여기서 `__current_context`를 다시 로드해 그 포인터가 가리키는 컨텍스트로 사용자 상태를 복원합니다. 그래서 **태스크 전환은 포인터 변경일 뿐**입니다([scheduling_KR.md](scheduling_KR.md) 참고). -이양 때 EL0로 처음 진입하는 경로도 같은 복원 경로를 사용합니다. 이 진입 함수 `enter_user`는 `ELR_EL1`과 `SPSR_EL1`을 로드하기 전에 DAIF를 전부 마스크합니다. 부트 시점에는 타이머가 이미 동작 중이라, 이 레지스터들을 기록한 뒤 `eret` 전에 인터럽트가 들어오면 두 레지스터가 EL1 값으로 덮입니다. 예외 진입을 거치는 평소 경로에서는 마스크가 이미 걸려 있습니다. +이양 때 EL0로 처음 진입하는 경로도 같은 복원 경로를 사용합니다. 이 진입 함수 `enter_user`는 `ELR_EL1`과 `SPSR_EL1`을 로드하기 전에 DAIF를 전부 마스크합니다. 부트 시점에는 타이머가 이미 동작 중이라, 이 레지스터들을 기록한 뒤 `eret` 전에 인터럽트가 들어오면 두 레지스터가 EL1 값으로 덮입니다. 예외 진입을 거치는 평소 경로에서는 마스크가 이미 걸려 있습니다. `k0_sched::handoff`는 그보다도 먼저, 스케줄러가 틱 번호를 처음 읽기 전에 인터럽트를 마스크합니다. 틱 번호를 읽은 뒤 EL0에 진입하기 전에 틱이 하나 세어지면 스케줄러가 타이머보다 한 틱 뒤처지기 때문입니다. 마스크가 걸린 동안 보류된 틱은 EL0에 진입한 직후에 보통의 틱으로 받습니다. FP/SIMD 레지스터는 컨텍스트에 포함되지 않습니다. EL0의 모든 FP/SIMD 명령이 트랩되므로 포함할 필요가 없습니다([hardening_KR.md](hardening_KR.md) 참고). @@ -77,7 +77,7 @@ FP/SIMD 레지스터는 컨텍스트에 포함되지 않습니다. EL0의 모든 `el0_sync`는 `ESR_EL1`을 읽고 예외 클래스에 따라 다음과 같이 처리합니다. - **시스템 콜**: AArch64의 `SVC`는 `k0_syscall`로 이어집니다. CPU가 이미 반환 주소를 `svc` 다음 명령으로 설정해 두었습니다. -- **건너뛰는 명령**: 트랩된 `WFI` 또는 `WFE`는 건너뜁니다. 반환 주소를 그 명령 뒤로 옮기고 태스크는 계속 실행됩니다. +- **건너뛰는 명령**: 트랩된 `WFI` 또는 `WFE`는 건너뜁니다. 반환 주소를 그 명령 뒤로 옮기고 태스크는 계속 실행됩니다. 스케줄러 상태는 바뀌지 않지만, 이 경로도 다른 모든 경로처럼 복귀 검사를 지납니다([복귀 검사](#복귀-검사) 참고). - **폴트**: 그 외 전부는 폴트입니다. abort, 정의되지 않은 명령, 트랩된 시스템 레지스터 접근, FP/SIMD 사용, 정렬 폴트, `brk` 등이 여기에 속합니다. 이들은 `FAR_EL1`과 함께 `k0_fault`로 이어집니다. ## 시스템 콜 @@ -103,6 +103,8 @@ FP/SIMD 레지스터는 컨텍스트에 포함되지 않습니다. EL0의 모든 | 14 | `CAP_DELETE` | 케이퍼빌리티와 거기서 파생된 모든 것을 삭제 | | 15 | `CAP_REVOKE` | 케이퍼빌리티에서 파생된 모든 것을 삭제하고 케이퍼빌리티 자신은 남김 | | 16 | `CONSOLE_READ` | 콘솔 입력 바이트 하나를 읽음(`console-input`으로 빌드한 이미지에만 있음, 아래 참고). 읽기 권리가 있는 `Console` 케이퍼빌리티가 필요 | +| 17 | `PART_SET_TABLE` | 시간 분할 표를 정함. `PartCtl` 케이퍼빌리티가 필요([scheduling_KR.md](scheduling_KR.md#제어-케이퍼빌리티와-두-시스템-콜) 참고) | +| 18 | `PART_SET_DOMAIN` | 아직 실행된 적 없는 태스크를 시간 분할 도메인에 넣음. `PartCtl` 케이퍼빌리티가 필요 | > [!IMPORTANT] > 알 수 없는 번호는 단순한 오류 코드로 끝나지 않습니다. K0는 이를 태스크가 손상되었거나 악의적이라는 신호로 보고, `k0: unknown syscall N, killing task`를 출력한 뒤 호출자를 종료합니다. @@ -123,31 +125,44 @@ k0: task fault dabort-lower (esr 0x92000046 elr 0x400398 far 0x0), killing task 모든 시스템 콜과 모든 폴트는 `finish`로 끝납니다. `finish`는 핸들러가 끝나고 케이퍼빌리티 정리가 전부 끝난 뒤에 실행됩니다. 핸들러는 폴트 없이도 호출한 태스크를 죽일 수 있습니다. `EXIT`, 자신의 CNode·주소 공간·TCB 삭제, 자신이 잘려 나온 untyped의 회수가 그렇습니다. 그래서 `finish`는 다른 모든 일이 끝난 뒤에야 컨텍스트를 어떻게 할지 정합니다. -1. **현재 태스크가 Dead인 경우**: 그 컨텍스트에 반환값을 기록하지 않습니다. 컨텍스트를 0으로 지우므로 죽은 태스크의 레지스터는 하나도 남지 않고, 커널은 다음 준비 태스크로 전환합니다. 준비된 태스크가 없으면 `idle_until_ready`를 호출합니다(아래 참고). +1. **현재 태스크가 Dead인 경우**: 그 컨텍스트에 반환값을 기록하지 않습니다. 컨텍스트를 0으로 지우므로 죽은 태스크의 레지스터는 하나도 남지 않고, 커널은 같은 도메인의 다음 준비 태스크로 전환합니다. 준비된 태스크가 없으면 `wait_for_work`를 호출합니다(아래 참고). 2. **그 밖의 경우**: 반환값을 `x0`에 기록합니다. 블록하는 IPC 호출은 상대가 동작할 때 나중에 결과를 기록합니다. 정리가 전환보다 먼저인 이유는, revoke가 태스크가 사용하던 주소 공간이나 CNode 자체를 파괴할 수 있기 때문입니다. 다음 태스크가 끝나지 않은 정리 위에서 실행되어서는 안 됩니다. -준비된 태스크가 없으면(마지막 실행 가능 태스크가 죽었거나 모든 태스크가 블록된 경우) `idle_until_ready`가 **커널을 멈추지 않고 대기 상태로 둡니다**. 루프에서 `k0_arch::irq::wait_for_interrupt`로 다음 인터럽트를 기다리고, `k0_ipc::expire_timeouts`를 호출해 기한이 지난 IPC 대기자를 모두 깨우고, 준비된 태스크가 있으면 그쪽으로 전환합니다. 커널이 대기하는 동안에도 타이머 tick은 계속 세어지고 처리됩니다. 중첩된 EL1 IRQ는 [커널 안에서 발생한 인터럽트](#커널-안에서-발생한-인터럽트)에서 설명합니다. 이 함수는 다음 두 줄을 부팅당 최대 한 번씩 출력합니다. +도는 도메인에 준비된 태스크가 없으면(그 도메인의 마지막 실행 가능 태스크가 죽었거나 모든 태스크가 블록된 경우) `wait_for_work`가 **커널을 멈추지 않고 대기 상태로 둡니다**. 루프에서 `k0_arch::irq::wait_for_interrupt`로 다음 인터럽트를 기다린 다음 스케줄러에 묻습니다(`k0_sched::poll`). 스케줄러는 틱 번호가 올라갔으면 시간 분할 표를 따라가고, 도는 도메인에서 기한이 된 대기자를 깨우고(콘솔 입력이 먼저, 그다음 `k0_ipc::expire_timeouts`로 IPC 타임아웃), 그 도메인에 준비된 태스크가 있으면 설치합니다. 다른 도메인의 준비된 태스크를 대신 실행하지 않습니다([scheduling_KR.md](scheduling_KR.md#창) 참고). 틱이 창의 끝에서 실행 중이던 태스크를 끊었는데 들어오는 도메인이 비어 있을 때도 같은 루프를 사용합니다. 커널이 대기하는 동안에도 타이머 tick은 계속 세어지고 처리됩니다. 중첩된 EL1 IRQ는 [커널 안에서 발생한 인터럽트](#커널-안에서-발생한-인터럽트)에서 설명합니다. 표를 정하지 않았으면 이 함수는 다음 두 줄을 부팅당 최대 한 번씩 출력합니다. | 줄 | 시점 | | --- | --- | | `k0: idle (waiting for a timeout)` | 기한을 가진 대기자가 하나 이상 있는 채로 커널이 처음 대기할 때 | | `k0: all tasks stopped (none ready, no timeout pending)` | 기한을 가진 대기자가 없는 채로 커널이 처음 대기할 때 | -두 번째 상태에서는 지금으로서는 태스크를 깨울 수단이 없습니다. 알림 오브젝트도, 콘솔 입력을 제외하면 태스크용 장치 인터럽트도 없기 때문입니다. 기계는 대기 상태로 남습니다. `console-input` 이미지에서는 콘솔 입력을 기다리는 태스크도 대기자로 셉니다. 기다릴 것이 콘솔 입력뿐이면 커널은 아무것도 출력하지 않으며, 이것이 터미널 이미지의 정상 상태입니다. 두 번째 줄은 기한이 있는 대기자도 콘솔 대기자도 없을 때만 출력됩니다. `tools/qemu-boot-test.sh`는 `k0: all tasks`로 시작하는 줄이 나오면 실패로 판정합니다. +두 번째 상태에서는 지금으로서는 태스크를 깨울 수단이 없습니다. 알림 오브젝트도, 콘솔 입력을 제외하면 태스크용 장치 인터럽트도 없기 때문입니다. 기계는 대기 상태로 남습니다. `console-input` 이미지에서는 콘솔 입력을 기다리는 태스크도 대기자로 셉니다. 기다릴 것이 콘솔 입력뿐이면 커널은 아무것도 출력하지 않으며, 이것이 터미널 이미지의 정상 상태입니다. 두 번째 줄은 기한이 있는 대기자도 콘솔 대기자도 없을 때만 출력됩니다. 루트 도메인이 아닌 도메인이 적힌 표가 정해져 있거나 보류 중인 동안에는 첫 번째 줄을 출력하지 않습니다. 그때 두 번째 줄은 어느 도메인에도 준비된 태스크와 기한이 있는 대기자가 없고 콘솔 입력을 기다리는 태스크도 없을 때만 출력합니다. `tools/qemu-boot-test.sh`는 `k0: all tasks`로 시작하는 줄이 나오면 실패로 판정합니다. + +### 복귀 검사 + +예외에서 EL0로 돌아가는 모든 길은 함수 하나, `k0_leave`를 지납니다. `k0_syscall`의 끝, `k0_fault`의 끝, 어떤 인터럽트였든 IRQ 경로의 끝, 그리고 건너뛴 `WFI` 또는 `WFE`가 그 길입니다. 이 함수는 두 가지 일을 합니다. + +1. 이제 재개할 태스크가 `Running`이고 지금 도는 도메인에 속하는지 검사합니다. 아니면 스케줄러 상태가 망가진 것이므로, 커널은 창 밖의 태스크를 실행하지 않고 `k0: FATAL returning to a task outside its window`를 출력하고 정지합니다. +2. 마지막으로 처리한 틱의 시각까지 스핀하며 기다립니다(`k0_arch::irq::hold_until_due`). 그 시각이 아직 오지 않은 경우는 틱을 일찍 받았을 때뿐이며, 이는 도메인이 바뀌기 전에 일어납니다. 그 밖의 경우에는 곧바로 돌아옵니다. + +일찍 받는 틱과 이 대기가 무엇을 위한 것인지는 [scheduling_KR.md](scheduling_KR.md#보호-구간과-틱-시각까지의-대기)에서 설명합니다. 이양 때 EL0로 처음 진입하는 경로는 이 함수를 지나지 않습니다. ## EL0의 타이머 인터럽트 커널이 항상 켜는 인터럽트는 **EL1 가상 타이머**입니다. `console-input`으로 빌드한 이미지는 콘솔 UART의 수신 인터럽트를 하나 더 받습니다(아래 참고). 인터럽트 번호는 DTB에서 가져오며, 커널은 물리 타이머를 사용하지 않습니다. 인터럽트 컨트롤러는 DTB가 타이머의 인터럽트 부모로 가리키는 GICv2 또는 GICv3입니다. 드라이버는 레지스터에 기록하기 전에 식별 레지스터를 그 기술과 대조하고, 다르면 부팅을 거부합니다. [dtb_KR.md](dtb_KR.md)를 참고하세요. -EL0에서 받은 IRQ는 시스템 콜과 같은 방식으로 저장됩니다. 핸들러는 인터럽트를 확인합니다. 타이머였다면 타이머를 1초 뒤로 다시 설정하고 `k0: tick N`을 출력합니다. 콘솔 드라이버를 포함해 빌드한 이미지에서는 콘솔에 출력하며, 로그에는 처음 4개의 tick 줄만 남깁니다. 그다음 `k0_preempt`를 호출합니다. 이 함수는 먼저 기한이 된 IPC 타임아웃을 만료시키고(`k0_ipc::expire_timeouts`), 그래서 기한이 지난 대기자는 라운드 로빈 전환 전에 준비 상태가 됩니다. 그런 다음 `k0_sched::on_tick`을 호출합니다. 슬라이스 규칙이 이번 틱이 현재 태스크를 끊는다고 할 때만 현재 태스크를 준비 큐의 맨 뒤로 보내고 다음 준비 태스크를 실행합니다. 규칙은 [scheduling_KR.md](scheduling_KR.md#슬라이스-규칙)를 참고하세요. 1020부터 1023까지의 가짜 인터럽트 번호는 무시합니다. 그 외의 인터럽트 번호와 모든 FIQ는 설계상 발생할 수 없으므로 커널은 `k0: UNEXPECTED ...`를 출력하고 파킹합니다. +EL0에서 받은 IRQ는 시스템 콜과 같은 방식으로 저장됩니다. 핸들러는 인터럽트를 확인합니다. 타이머였다면 카운터에서 틱 번호를 계산하고, 다음 틱을 그 정해진 시각에 맞춰 설정하고, `k0: tick N`을 출력합니다. 콘솔 드라이버를 포함해 빌드한 이미지에서는 콘솔에 출력하며, 로그에는 처음 4개의 tick 줄만 남깁니다. 설정해 둔 시각보다 일찍 도착한 타이머 인터럽트는 틱이 아닙니다. 핸들러는 같은 시각을 다시 설정하고 그 밖의 일은 하지 않습니다. 한 주기 넘게 늦게 실행된 핸들러는 그 사이의 틱 번호를 건너뜁니다([scheduling_KR.md](scheduling_KR.md#틱-시계와-건너뛴-틱) 참고). + +틱이었다면 핸들러는 이어서 `k0_preempt`를 호출하고, 이 함수가 `k0_sched::on_tick`을 호출합니다. 시간 분할 표의 창 안에서는 스케줄러가 먼저 도는 도메인에서 기한이 된 대기자를 깨웁니다(IPC 타임아웃은 `k0_ipc::expire_timeouts`). 그래서 기한이 지난 대기자는 라운드 로빈 전환 전에 준비 상태가 됩니다. 그런 다음 슬라이스 규칙이 이번 틱이 현재 태스크를 끊는다고 할 때만 현재 태스크를 자기 도메인 준비 큐의 맨 뒤로 보내고 그 도메인의 다음 준비 태스크를 실행합니다. 규칙은 [scheduling_KR.md](scheduling_KR.md#슬라이스-규칙)를 참고하세요. 창이 끝날 때는 현재 태스크를 세워 두고 다음 도메인으로 들어갑니다. 그 도메인에 준비된 태스크가 없으면 `k0_preempt`는 EL0로 돌아가지 않고 `wait_for_work`에서 기다립니다. 표를 정하지 않았으면 도메인은 하나이고 모든 틱이 그 창 안의 틱입니다. + +1020부터 1023까지의 가짜 인터럽트 번호는 무시합니다. 그 외의 인터럽트 번호와 모든 FIQ는 설계상 발생할 수 없으므로 커널은 `k0: UNEXPECTED ...`를 출력하고 파킹합니다. 틱을 센 뒤 핸들러는 콘솔 수신 링도 비우며(`console-input` 이미지), 태스크가 콘솔 입력을 읽기 시작한 뒤에는 주기적인 틱 줄을 출력하지 않습니다([boot_KR.md](boot_KR.md) 참고). 틱, 선점, 타임아웃은 그대로입니다. ## 콘솔 인터럽트 -`console-input`으로 빌드한 이미지는 인터럽트를 하나 더 받습니다. 콘솔 UART의 수신 인터럽트입니다. 디스패처는 인터럽트 번호로 둘을 구분합니다(타이머, 그다음 콘솔). EL0와 EL1에서 받은 IRQ가 같은 함수를 지납니다. 그 밖의 번호는 여전히 `k0: UNEXPECTED ...`입니다. 콘솔 가지는 UART를 256바이트 링으로 비우며, 바이트를 해석하지 않습니다. 커널 바이너리의 정책 함수 `k0_console_event`(`k0_preempt`와 같은 종류)를 불러 대기 중인 `CONSOLE_READ` 호출자를 깨웁니다. 깨어난 태스크는 준비 큐의 맨 뒤로 가므로 입력은 실행 중인 태스크를 선점하지 않습니다. +`console-input`으로 빌드한 이미지는 인터럽트를 하나 더 받습니다. 콘솔 UART의 수신 인터럽트입니다. 디스패처는 인터럽트 번호로 둘을 구분합니다(타이머, 그다음 콘솔). EL0와 EL1에서 받은 IRQ가 같은 함수를 지납니다. 그 밖의 번호는 여전히 `k0: UNEXPECTED ...`입니다. 콘솔 가지는 UART를 256바이트 링으로 비우며, 바이트를 해석하지 않습니다. 커널 바이너리의 정책 함수 `k0_console_event`(`k0_preempt`와 같은 종류)를 불러 대기 중인 `CONSOLE_READ` 호출자를 깨웁니다. 깨어난 태스크는 자기 도메인 준비 큐의 맨 뒤로 가므로 입력은 실행 중인 태스크를 선점하지 않습니다. 시간 분할 표가 있을 때 바이트는 읽는 쪽의 도메인이 도는 동안에만 전달됩니다. 그렇지 않으면 그 도메인이 도는 다음 틱까지 링에 남습니다([scheduling_KR.md](scheduling_KR.md#표가-있을-때의-콘솔-입력) 참고). 인터럽트는 읽는 쪽이 한도를 정합니다. 링이 차면 커널이 UART의 수신 인터럽트를 스스로 가리고, 읽는 쪽이 링의 절반을 가져가면 다시 엽니다. 브레이크, 프레이밍 오류, 패리티 오류가 난 문자는 링의 자리를 쓰지 않으므로 따로 셉니다. 한 틱 동안 256개가 들어오면 커널은 다음 틱까지 수신 인터럽트를 가립니다. 같은 비우기가 틱마다 한 번 더 실행되므로, 인터럽트가 오지 않아도 입력은 (최대 한 틱 늦게) 도착합니다. UART 원인 없이 발생하는 선은 8번 진입 뒤 `k0: console input off (interrupt N fired without a uart cause)`와 함께 꺼집니다. 이 차단은 호스트 테스트로만 확인했습니다. 수신 인터럽트는 태스크가 읽기 권리로 콘솔 입력을 처음 읽을 때까지 꺼져 있습니다. diff --git a/design/kr/hardening_KR.md b/design/kr/hardening_KR.md index 2f373ad..a44ce2f 100644 --- a/design/kr/hardening_KR.md +++ b/design/kr/hardening_KR.md @@ -46,7 +46,7 @@ 커널은 루트 태스크에 넘길 32바이트 시드도 파생합니다(`k0_boot::derive_root_seed`). 자체 도메인 문자열(`k0-root-task-seed-v1`), DTB 엔트로피의 길이, DTB 엔트로피 자체, 카운터를 SHA-256으로 해시하고, CPU에 `RNDR`이 있으면 새로 뽑은 `RNDR` 워드 네 개를 더합니다. 도메인 문자열이 PAC 키의 것과 다르므로 두 출력은 도메인 분리로 서로 독립입니다. 하나를 안다고 다른 하나를 알 수는 없습니다. 다만 DTB 엔트로피와 카운터는 공유하므로, 시드는 입력만큼만 좋고 그보다 낫지 않습니다. -시드는 bootinfo 페이지에 없습니다. 커널이 루트 태스크의 저장된 컨텍스트에 넣으므로 진입 레지스터 `x0`부터 `x3`으로 도착합니다. `x4`는 시드 정보 워드입니다. 비트 15..0은 시드에 들어간 `rng-seed` 바이트 수이고, 비트 16은 `RNDR`이 기여했을 때 설정됩니다. bootinfo 페이지의 레이아웃은 이제 버전 4(`bootinfo::VERSION`)이며, 다른 버전을 본 루트 태스크는 멈춥니다. 커널은 부트 스택에 있던 시드 사본을 직접 지웁니다. 루트 태스크는 시드가 아니라 재료만 출력합니다. `root: boot seed from rng-seed bytes 0x... and rndr` 또는 `... without rndr`입니다. +시드는 bootinfo 페이지에 없습니다. 커널이 루트 태스크의 저장된 컨텍스트에 넣으므로 진입 레지스터 `x0`부터 `x3`으로 도착합니다. `x4`는 시드 정보 워드입니다. 비트 15..0은 시드에 들어간 `rng-seed` 바이트 수이고, 비트 16은 `RNDR`이 기여했을 때 설정됩니다. bootinfo 페이지의 레이아웃은 이제 버전 5(`bootinfo::VERSION`)이며, 다른 버전을 본 루트 태스크는 멈춥니다. 커널은 부트 스택에 있던 시드 사본을 직접 지웁니다. 루트 태스크는 시드가 아니라 재료만 출력합니다. `root: boot seed from rng-seed bytes 0x... and rndr` 또는 `... without rndr`입니다. ### DTB에서 시드 지우기 @@ -102,7 +102,7 @@ CPU가 FEAT_E0PD를 구현하면 `TCR_EL1.E0PD1`을 설정합니다. 그러면 E EL0의 트랩은 폴트로 처리되고 태스크는 종료됩니다([exceptions_KR.md](exceptions_KR.md) 참고). 유일한 예외는 `WFI`와 `WFE`로, 커널이 건너뜁니다. FP/SIMD를 트랩하면 커널이 벡터 레지스터를 저장할 필요가 전혀 없으므로, 태스크는 다른 태스크가 남긴 벡터 상태를 읽을 수 없습니다. -EL0는 여전히 어떤 하드웨어 카운터나 타이머도 읽을 수 없습니다. 다만 IPC 타임아웃은 EL0에 **스케줄러 tick만큼 거친 시계**(1초)와 타이머 인터럽트에 맞춰 정렬된 깨어남을 제공합니다([ipc_KR.md](ipc_KR.md) 참고). 따라서 **tick 주기는 사이드 채널에 관한 결정**입니다. 이 시계가 캐시나 추측 실행 공격에 쓸 만한 시간 원천으로 증폭될 수 있는지는 분석하지 않았습니다. +EL0는 여전히 어떤 하드웨어 카운터나 타이머도 읽을 수 없습니다. 다만 IPC 타임아웃은 EL0에 **스케줄러 tick만큼 거친 시계**(1초)와 타이머 인터럽트에 맞춰 정렬된 깨어남을 제공합니다([ipc_KR.md](ipc_KR.md) 참고). 따라서 **tick 주기는 사이드 채널에 관한 결정**입니다. 이 시계가 캐시나 추측 실행 공격에 쓸 만한 시간 원천으로 증폭될 수 있는지는 분석하지 않았습니다. 고정 시간 분할은 같은 tick을 유지하며, 창은 tick의 정수 배입니다. 도메인이 바뀔 때마다 TLB를 비우고, 캐시와 분기 예측기는 비우지 않습니다([scheduling_KR.md](scheduling_KR.md#시간-분할이-주장하는-것과-주장하지-않는-것) 참고). EL0 스레드 포인터 레지스터 `TPIDR_EL0`와 `TPIDRRO_EL0`는 각 태스크의 저장된 컨텍스트에 포함됩니다. `TCB_CONFIGURE`가 이를 0으로 만들기 때문에 새 태스크는 생성자의 값 없이 시작합니다. @@ -111,7 +111,7 @@ EL0 스레드 포인터 레지스터 `TPIDR_EL0`와 `TPIDRRO_EL0`는 각 태스 이 필터는 줄을 누가 썼는지 표시하지 않습니다. 커널 출력과 태스크 출력이 부트 로그를 함께 사용하고 (콘솔 드라이버를 포함해 빌드한 이미지에서는) 콘솔도 함께 사용합니다. 터미널은 추가로 자신의 현재 줄 안에서 지울 수 있습니다. 읽기 권리(R)가 있는 `Console` 케이퍼빌리티(터미널의 것)만 백스페이스(0x08)도 출력할 수 있습니다. > [!NOTE] -> `console-input` 이미지에서는 외부가 태스크 실행 중에 인터럽트를 일으킬 수 있습니다. 링이 차면 커널이 수신 인터럽트를 스스로 가리므로 빈도는 읽는 쪽이 한도를 정합니다. 선로 오류가 난 문자는 링의 자리를 쓰지 않으므로, 한 틱 동안 256개가 들어오면 다음 틱까지 가립니다. 그래도 읽는 쪽은 틱보다 세밀한 도착 시각을 알게 되고 다른 태스크는 빼앗긴 시간을 알아챌 수 있습니다. 이 타이밍 채널은 분석하지 않았습니다. 커널의 수신 코드는 EL1에서 실행되며 바이트를 해석하지 않지만 외부가 구동하는 커널 코드이고, 사용자 공간 드라이버에는 K0에 없는 장치·인터럽트 위임이 필요합니다. +> `console-input` 이미지에서는 외부가 태스크 실행 중에 인터럽트를 일으킬 수 있습니다. 링이 차면 커널이 수신 인터럽트를 스스로 가리므로 빈도는 읽는 쪽이 한도를 정합니다. 선로 오류가 난 문자는 링의 자리를 쓰지 않으므로, 한 틱 동안 256개가 들어오면 다음 틱까지 가립니다. 그래도 읽는 쪽은 틱보다 세밀한 도착 시각을 알게 되고 다른 태스크는 빼앗긴 시간을 알아챌 수 있습니다. 이 타이밍 채널은 분석하지 않았으며, 고정 시간 분할은 이 채널을 닫지 않습니다. 콘솔 인터럽트의 시간은 그때 돌고 있는 도메인의 시간에서 나가기 때문입니다. 커널의 수신 코드는 EL1에서 실행되며 바이트를 해석하지 않지만 외부가 구동하는 커널 코드이고, 사용자 공간 드라이버에는 K0에 없는 장치·인터럽트 위임이 필요합니다. > [!WARNING] > `Console` 케이퍼빌리티를 가진 태스크는 개행 뒤에 `k0:`로 시작하는 글을 출력할 수 있습니다. 콘솔이나 로그를 읽는 쪽은 `tools/qemu-boot-test.sh`를 포함해 누구도 `k0: entering root task (el0)` 뒤에 나온 `k0:` 줄을 커널이 쓴 것으로 믿을 수 없습니다. diff --git a/design/kr/ipc_KR.md b/design/kr/ipc_KR.md index 320fac5..83ca1ff 100644 --- a/design/kr/ipc_KR.md +++ b/design/kr/ipc_KR.md @@ -115,7 +115,8 @@ K0의 IPC는 seL4 방식의 **동기 랑데부**입니다. 메시지는 레지 모든 대기에 상한을 걸 수 있습니다. 타임아웃은 플래그 레지스터 `x1`의 상위 32비트이며 스케줄러 틱 단위입니다. 틱 주기는 1초(커널 상수)이므로 모든 타임아웃의 단위는 틱입니다. 다음 규칙이 적용됩니다. - **기한 규칙**: n 틱의 타임아웃은 호출 뒤 (n+1)번째 타이머 틱에서 끝납니다. 틱이 제때 처리되는 한 대기는 틱 주기의 n배에서 n+1배 사이입니다. 타임아웃은 그 시점에 태스크를 준비 상태로 만들 뿐입니다. 실제로 실행되는 시점은 준비 큐에 달려 있습니다([scheduling_KR.md](scheduling_KR.md#타임아웃) 참고). -- **하한이지 벽시계 시간이 아님**: 커널은 모든 시스템 콜을 인터럽트를 마스크한 채 실행하고, 큰 `CAP_REVOKE`처럼 긴 호출은 틱을 늦춥니다. 그러면 대기도 그만큼 길어집니다. +- **하한이지 벽시계 시간이 아님**: 커널은 모든 시스템 콜을 인터럽트를 마스크한 채 실행하고, 큰 `CAP_REVOKE`처럼 긴 호출은 틱을 늦춥니다. 그러면 대기도 그만큼 길어집니다. 틱 번호는 카운터를 따르므로, 한 주기 넘게 늦은 핸들러는 번호를 건너뛰고, 기한은 건너뛴 틱도 함께 셉니다. +- **시간 분할 표가 있으면 늦을 수는 있어도 이르지는 않음**: 기한은 전역 틱 번호이지만, 커널은 한 도메인의 기한을 그 도메인이 도는 틱에서만 들여다봅니다. 다른 도메인이 도는 동안 기한이 지난 대기자는 자기 도메인의 다음 창이 열릴 때 깨어납니다([scheduling_KR.md](scheduling_KR.md#시간-분할) 참고). 표를 정하지 않았으면 도메인은 하나이고 달라지는 것이 없습니다. - **0은 기한 없음**: 이전처럼 상대방이 동작할 때까지 기다립니다. - **호출의 기한은 하나**: `CALL`의 기한은 수신자를 기다리는 단계와 응답을 기다리는 단계를 모두 덮습니다. - **응답 후 수신**: `REPLY_RECV`의 타임아웃은 수신 단계에만 적용됩니다. @@ -134,17 +135,17 @@ K0의 IPC는 seL4 방식의 **동기 랑데부**입니다. 메시지는 레지 ### 기한 목록 -TCB에는 `deadline`, `tnext`, `tprev` 필드가 있습니다. `k0-sched`는 기한이 있는 대기자의 정렬되지 않은 intrusive 리스트(`arm_timeout`, `disarm_timeout`, `expired`, `has_timed`)와 가장 이른 기한의 하한을 유지하므로, 대부분의 틱은 리스트를 훑지 않습니다. 태스크가 블록 상태를 벗어나는 길은 두 가지뿐이며, 둘 다 태스크를 리스트에서 제거합니다. +TCB에는 `deadline`, `tnext`, `tprev` 필드가 있습니다. `k0-sched`는 기한이 있는 대기자의 정렬되지 않은 intrusive 리스트를 8개 시간 분할 도메인마다 하나씩 유지합니다(`arm_timeout`, `disarm_timeout`, `expired`, `has_timed`). 리스트마다 가장 이른 기한의 하한도 유지하므로, 대부분의 틱은 리스트를 훑지 않습니다. 새 대기자는 자기 도메인 리스트의 머리에 연결됩니다. 태스크가 블록 상태를 벗어나는 길은 두 가지뿐이며, 둘 다 태스크를 리스트에서 제거합니다. - `k0_sched::enqueue`(깨우기). 메시지로 깨어난 대기자는 기한을 남기지 않습니다. - `k0_ipc::teardown`(죽음) -기한이 지난 대기자는 `k0_ipc::expire_timeouts`가 처리합니다. 대기자를 엔드포인트 큐에서 빼고 `TIMEOUT`으로 깨우거나, 그 응답을 쥔 태스크의 응답 링크를 지우고 `REPLY_TIMEOUT`으로 깨웁니다. 링크가 상태와 맞지 않으면 해체와 마찬가지로 커널은 `k0: FATAL`을 출력하고 정지합니다. 이 함수는 타이머 틱마다 실행됩니다. +기한이 지난 대기자는 `k0_ipc::expire_timeouts`가 처리합니다. 대기자를 엔드포인트 큐에서 빼고 `TIMEOUT`으로 깨우거나, 그 응답을 쥔 태스크의 응답 링크를 지우고 `REPLY_TIMEOUT`으로 깨웁니다. 링크가 상태와 맞지 않으면 해체와 마찬가지로 커널은 `k0: FATAL`을 출력하고 정지합니다. 이 함수는 리스트를 훑을 도메인을 인자로 받으며, 스케줄러는 도는 도메인에 대해서만 다음 경우에 호출합니다. -- 태스크가 실행 중이었다면 `k0_preempt`에서 -- 실행 중인 태스크가 없었다면 idle 루프에서 +- 그 도메인의 창 안에 있는 틱마다, 그리고 그 창을 여는 틱에서. 태스크가 실행 중이었든 커널이 기다리고 있었든 같습니다. +- 틱이 아닌 인터럽트 뒤에 대기 루프에서 -순회 비용은 인터럽트를 마스크한 상태에서 O(기한이 있는 대기자 수)이며 틱당 최대 한 번입니다. +순회는 리스트의 머리부터 하므로, 여러 대기자의 기한이 함께 지나 있으면 가장 나중에 기한을 건 대기자가 먼저 큐에 들어갑니다. 순회 비용은 인터럽트를 마스크한 상태에서 O(그 도메인의 기한이 있는 대기자 수)입니다. 그래서 한 도메인의 대기자 수는 다른 도메인에서 틱 하나가 걸리는 시간을 바꾸지 않습니다. > [!NOTE] > EL0는 여전히 어떤 하드웨어 카운터나 타이머도 읽을 수 없습니다. 타임아웃은 EL0에 스케줄러 틱만큼 거친 시계와 타이머 인터럽트에 맞춰진 깨어남을 줍니다. 이것이 캐시 또는 투기 실행 공격에 쓸 만한 시간 소스로 증폭될 수 있는지는 분석하지 않았습니다. @@ -153,12 +154,12 @@ TCB에는 `deadline`, `tnext`, `tprev` 필드가 있습니다. `k0-sched`는 기 기다려야 하는 태스크는 블록 상태로 표시되어 엔드포인트 큐에 연결되거나 응답 자격에 붙잡힙니다. 호출에 타임아웃이 있으면 태스크는 기한 목록에도 들어갑니다. 그 뒤 스케줄러가 다음 준비 태스크로 전환합니다([scheduling_KR.md](scheduling_KR.md) 참고). 이 태스크의 반환 레지스터는 나중에 해제하는 태스크가 기록합니다. -그 시점에 준비된 태스크가 없어도 커널은 멈추지 않습니다. 커널은 `idle_until_ready`(`kernel/src/syscall.rs`)에서 idle 상태로 기다립니다. 다음 인터럽트까지 기다렸다가 기한이 지난 대기자를 모두 깨우고, 준비된 태스크가 있으면 그 태스크로 전환합니다. 그동안에도 타이머 틱은 계속 세고 처리합니다. idle 루프는 다음 두 줄 가운데 하나를 부팅당 최대 한 번씩 출력합니다. +그 시점에 같은 도메인에 준비된 태스크가 없어도 커널은 멈추지 않습니다. 커널은 `wait_for_work`(`kernel/src/syscall.rs`)에서 idle 상태로 기다립니다. 다음 인터럽트까지 기다렸다가, 스케줄러가 도는 도메인에서 기한이 지난 대기자를 깨우게 하고, 그 도메인에 준비된 태스크가 있으면 그 태스크로 전환합니다. 다른 도메인의 준비된 태스크는 자기 창을 기다려야 합니다. 그동안에도 타이머 틱은 계속 세고 처리합니다. 표를 정하지 않았으면 idle 루프는 다음 두 줄 가운데 하나를 부팅당 최대 한 번씩 출력합니다. - `k0: idle (waiting for a timeout)`: 기한이 있는 대기자가 하나 이상 있으므로 태스크를 깨울 것이 있습니다. - `k0: all tasks stopped (none ready, no timeout pending)`: 기한이 있는 대기자도 콘솔 입력을 기다리는 태스크도 없습니다. 지금은 Notification 오브젝트가 없고 태스크를 깨우는 장치 인터럽트는 콘솔 입력뿐이므로 이 상태에서는 어떤 것도 태스크를 깨울 수 없고, 머신은 idle 상태로 남습니다. `tools/qemu-boot-test.sh`는 `k0: all tasks`로 시작하는 줄을 모두 실패로 처리합니다. -기다릴 것이 콘솔 입력뿐이면 커널은 어느 줄도 출력하지 않습니다. 터미널 이미지에서는 이것이 정상 상태입니다. +기다릴 것이 콘솔 입력뿐이면 커널은 어느 줄도 출력하지 않습니다. 터미널 이미지에서는 이것이 정상 상태입니다. 루트 도메인이 아닌 도메인이 적힌 시간 분할 표가 정해져 있거나 보류 중인 동안에는 첫째 줄을 출력하지 않습니다. 둘째 줄은 어느 도메인에도 준비된 태스크와 기한이 있는 대기자가 없고 입력을 기다리는 태스크도 없을 때만 출력합니다([scheduling_KR.md](scheduling_KR.md#실행할-태스크가-없을-때) 참고). > [!WARNING] > 모든 태스크가 블록되어도 커널은 더 이상 정지하지 않으며, 태스크는 타임아웃으로 자신의 대기에 상한을 걸 수 있습니다. 그래도 가용성은 보호되지 않습니다. 타임아웃 없이 기다리는 태스크는 상대방이 동작하지 않으면 영원히 기다릴 수 있고, 엔드포인트 케이퍼빌리티를 가진 격리 태스크는 여전히 다른 태스크를 기다리게 만들 수 있습니다. 이것이 [SECURITY_KR.md](../../SECURITY_KR.md)의 어드바이저리 GHSA-q99x-2wrv-358p의 주제입니다. 어드바이저리는 릴리즈 시점에 갱신합니다. @@ -186,7 +187,8 @@ TCB에는 `deadline`, `tnext`, `tprev` 필드가 있습니다. `k0-sched`는 기 - **회수**: `Console` 케이퍼빌리티가 삭제, 회수, 이동된 대기자는 즉시 `REVOKED`로 깨어나며 바이트를 받지 못합니다. - **입력 경로 없음**: `NO_DEVICE`는 이미지에 이 콘솔용 수신 드라이버가 없거나 입력 경로가 꺼졌다는 뜻입니다. 기다리는 동안 경로가 꺼지면 대기자가 이 값으로 깨어납니다. - **해체**: 기다리는 동안 죽은 태스크는 대기자 자리에서 제거됩니다. -- **깨우는 순서**: 깨어난 읽기 태스크는 준비 큐의 끝에 섭니다. 입력이 실행 중인 태스크를 선점하지 않습니다. +- **깨우는 순서**: 깨어난 읽기 태스크는 자기 도메인 준비 큐의 끝에 섭니다. 입력이 실행 중인 태스크를 선점하지 않습니다. +- **시간 분할 표가 있을 때**: 바이트는 대기자의 도메인이 도는 동안에만 대기자에게 전달됩니다. 그렇지 않으면 그 도메인이 도는 다음 틱까지 링에 남습니다. `REVOKED`와 `NO_DEVICE`는 어느 도메인이 돌든 전달됩니다. 이 규칙에는 아직 테스트가 없습니다([scheduling_KR.md](scheduling_KR.md#표가-있을-때의-콘솔-입력) 참고). 수신 인터럽트는 태스크가 권한을 가지고 처음 콘솔 입력을 읽을 때까지 꺼져 있습니다. 그 첫 읽기는 장치가 쥔 입력을 버리고, `k0: tick lines off (console input in use)` 한 줄을 출력한 뒤 주기적인 `k0: tick N` 줄을 멈춥니다. 틱, 선점, 타임아웃은 계속 동작합니다. 수신 경로와 그 한계는 [USAGE_KR.md](../../USAGE_KR.md)와 [exceptions_KR.md](exceptions_KR.md)에 있습니다. @@ -257,7 +259,8 @@ IPC와 해체는 부팅으로 테스트합니다. 루트 태스크는 서버 태 > [!NOTE] > IPC를 통한 케이퍼빌리티 전송과 Notification 오브젝트는 아직 없습니다. 타임아웃은 호출마다 선택하는 것이므로, 타임아웃 없이 기다리는 태스크는 여전히 상대방이 동작할 때까지 기다립니다. -- **타임아웃은 태스크가 준비되는 시점이지 실행되는 시점이 아님**: 우선순위도 CPU 예산도 없으며, 스케줄러는 1초 틱 기준의 라운드 로빈입니다. 두 틱 사이에 CPU를 받은 태스크는 다음 틱까지 CPU를 유지하므로, 깨어난 태스크는 이전보다 한 틱 주기 더 기다릴 수 있습니다. 앞에 실행할 태스크가 k개이면 k + 1 틱 주기 안에 시작합니다. 이 수치는 이 버전의 스케줄러를 설명할 뿐 인터페이스가 아닙니다([scheduling_KR.md](scheduling_KR.md) 참고). +- **타임아웃은 태스크가 준비되는 시점이지 실행되는 시점이 아님**: 우선순위도 CPU 예산도 없으며, 스케줄러는 1초 틱 기준의 라운드 로빈입니다. 두 틱 사이에 CPU를 받은 태스크는 다음 틱까지 CPU를 유지하므로, 깨어난 태스크는 이전보다 한 틱 주기 더 기다릴 수 있습니다. 앞에 실행할 태스크가 k개이면 k + 1 틱 주기 안에 시작합니다. 시간 분할 표가 있으면 타임아웃이 늦게, 대기자의 다음 창이 시작할 때 끝날 수도 있고, 깨어난 태스크는 자기 창에서만 실행됩니다. 이 수치는 이 버전의 스케줄러를 설명할 뿐 인터페이스가 아닙니다([scheduling_KR.md](scheduling_KR.md) 참고). +- **도메인 사이에 공유한 엔드포인트는 채널임**: 고정 시간 분할은 도메인 사이의 IPC를 다루지 않습니다. 송신, 응답, 상대에 달린 타임아웃, 엔드포인트의 삭제, 응답 자격을 쥔 태스크의 종료는 모두 상대 쪽에 무언가를, 그리고 그 시점을 알려 줍니다. 그 케이퍼빌리티를 준 목적이 바로 그것입니다([scheduling_KR.md](scheduling_KR.md#시간-분할이-주장하는-것과-주장하지-않는-것) 참고). - **긴 시스템 콜**: 커널은 선점되지 않으므로, 객체가 많은 untyped에 대한 `CAP_REVOKE` 같은 긴 호출은 다른 모든 태스크와 모든 타임아웃을 지연시킵니다. - **치명적 정지**: `k0_arch::fatal`이나 커널 패닉은 여전히 머신을 정지시킵니다. - **EL0의 시간 소스**: 틱에 맞춰 깨어나는 성질을 타이밍 공격에 쓸 수 있는지는 분석하지 않았습니다. 콘솔 입력이 있는 이미지에서는 외부의 누군가가 태스크가 실행되는 동안 인터럽트를 일으킬 수 있고(바이트는 읽는 쪽이, 선로 오류가 난 문자는 틱당 256개가 속도를 정함), 읽는 태스크는 틱보다 세밀한 도착 시각을 압니다. 다른 태스크도 빼앗긴 시간을 알아챌 수 있습니다. 이 타이밍 채널도 분석하지 않았습니다. diff --git a/design/kr/scheduling_KR.md b/design/kr/scheduling_KR.md index 6340985..41cc771 100644 --- a/design/kr/scheduling_KR.md +++ b/design/kr/scheduling_KR.md @@ -11,13 +11,17 @@ - K0가 태스크를 표현하는 방법 - 사용자 공간이 태스크를 만들고 시작하고 정리하는 방법 - 라운드 로빈 스케줄러가 태스크 사이를 전환하고, 타이머 틱이 태스크를 끊을지 정하는 방법 +- 고정 시간 분할이 태스크의 도메인마다 자기 틱 창을 주는 방법, 그리고 그것이 주장하는 것과 주장하지 않는 것 코드는 다음 위치에 있습니다. - `crates/k0-task/src/lib.rs` -- `crates/k0-sched/src/lib.rs` +- `crates/k0-part/src/lib.rs`(모든 스케줄링 판정, 타입 `Core`)와 `crates/k0-part/src/clock.rs`(틱 시각의 산술) +- `crates/k0-slice/src/lib.rs`(틱 하나에 대한 규칙, `Core`가 사용) +- `crates/k0-sched/src/lib.rs`(`Core`를 둘러싼 큐와 설치된 태스크) +- `crates/k0-arch/src/irq.rs`의 타이머 - `crates/k0-ipc/src/lib.rs`의 `teardown` -- `kernel/src/syscall.rs`의 `sys_tcb_configure`, `sys_tcb_resume`, `kill_current`, `finish` +- `kernel/src/syscall.rs`의 `sys_tcb_configure`, `sys_tcb_resume`, `sys_part_set_table`, `sys_part_set_domain`, `k0_preempt`, `k0_leave`, `wait_for_work`, `kill_current`, `finish` 이 문서는 현재 `main` 브랜치(미배포)를 기준으로 합니다. @@ -28,6 +32,7 @@ - **저장된 사용자 컨텍스트**: 범용 레지스터 31개, 스택 포인터, 반환 주소, 저장된 프로세서 상태, EL0 스레드 포인터 레지스터 2개입니다. - **최상위 페이지 테이블의 물리 주소**(`ttbr0_pa`): 주소 공간 루트의 사본이며 내장 슬롯이 묶여 있는 동안에만 유효합니다. - **상태**: 태스크의 현재 상태입니다. +- **도메인**: 태스크가 속한 시간 분할 도메인의 번호이며 0부터 7까지입니다([시간 분할](#시간-분할) 참고). 도메인 0이 루트 도메인입니다. 이 바이트는 상태 뒤의 채움 자리에 들어가므로 TCB는 커지지 않았습니다. - **큐 링크**: 태스크가 속한 큐에서 이웃 TCB로 가는 `next`와 `prev`입니다. - **응답 자격**: 1회성 응답 자격(`reply_to`)과 그 역방향 링크(`reply_from`)입니다. [ipc_KR.md](ipc_KR.md)에서 설명합니다. - **IPC 대기 정보**: 태스크가 줄 서 있는 엔드포인트 `blocked_on`, 그리고 보내려는 메시지에 붙을 배지 `ipc_badge`입니다. @@ -52,7 +57,7 @@ | --- | --- | | `Inactive` | retype 직후, 구성 전 | | `Stopped` | 구성 완료, 아직 시작 전 | -| `Ready` | 준비 큐에 있음 | +| `Ready` | 자기 도메인의 준비 큐에 있음 | | `Running` | 현재 태스크 | | `BlockedSend`, `BlockedRecv`, `BlockedCall` | 엔드포인트 큐에서 대기 중 | | `BlockedReply` | `CALL`의 응답을 기다리는 중 | @@ -61,7 +66,7 @@ 블록 상태의 태스크는 기한이 지나도 `Ready`가 될 수 있습니다([타임아웃](#타임아웃) 참고). `BlockedConsole` 태스크는 바이트가 도착하거나 케이퍼빌리티가 삭제·회수·이동될 때도 `Ready`가 됩니다. -`Inactive`의 값은 0입니다. 방금 retype한 프레임은 전부 0이므로, 큐 링크가 비어 있고 내장 슬롯이 비어 있으며 응답 자격이 없는 유효한 `Inactive` TCB입니다. retype에 생성자가 필요 없습니다. +`Inactive`의 값은 0입니다. 방금 retype한 프레임은 전부 0이므로, 큐 링크가 비어 있고 내장 슬롯이 비어 있으며 응답 자격이 없는, 루트 도메인의 유효한 `Inactive` TCB입니다. retype에 생성자가 필요 없습니다. ## 태스크 생성 @@ -77,13 +82,17 @@ 검사 중 하나라도 실패하면 두 내장 슬롯은 모두 빈 채로 남고 TCB는 `Inactive`를 유지합니다. -그다음 커널은 저장 컨텍스트를 0으로 지우고 진입 주소, 스택 포인터, `x0`, `ttbr0_pa`를 설정합니다. 저장되는 프로세서 상태도 커널이 직접 정해서, 인터럽트가 마스크 해제된 EL0로 설정합니다. 사용자 공간은 프로세서 상태를 절대 지정할 수 없으므로 EL1로 복귀하거나 인터럽트를 마스크한 채 실행하도록 요청할 수 없습니다. 스레드 포인터 레지스터는 0에서 시작하므로 새 태스크가 생성자의 값을 물려받지 않습니다. TCB는 `Stopped`가 됩니다. +그다음 커널은 저장 컨텍스트를 0으로 지우고 진입 주소, 스택 포인터, `x0`, `ttbr0_pa`를 설정합니다. 저장되는 프로세서 상태도 커널이 직접 정해서, 인터럽트가 마스크 해제된 EL0로 설정합니다. 사용자 공간은 프로세서 상태를 절대 지정할 수 없으므로 EL1로 복귀하거나 인터럽트를 마스크한 채 실행하도록 요청할 수 없습니다. 스레드 포인터 레지스터는 0에서 시작하므로 새 태스크가 생성자의 값을 물려받지 않습니다. 새 태스크는 **자신을 구성한 태스크의 도메인**을 받습니다. TCB는 `Stopped`가 됩니다. -`TCB_RESUME`은 `Stopped` TCB만 받아 준비 큐에 넣습니다. 이미 큐에 있거나, 실행 중이거나, 블록됐거나, 종료된 TCB는 거부되므로 같은 TCB가 큐에 두 번 들어갈 수 없습니다. +`TCB_RESUME`은 `Stopped` TCB만 받아 그 태스크가 속한 도메인의 준비 큐에 넣습니다. 이미 큐에 있거나, 실행 중이거나, 블록됐거나, 종료된 TCB는 거부되므로 같은 TCB가 큐에 두 번 들어갈 수 없습니다. + +제어 케이퍼빌리티를 가진 쪽은 이 두 호출 사이에서만 `PART_SET_DOMAIN`으로 태스크를 다른 도메인에 넣을 수 있습니다([제어 케이퍼빌리티와 두 시스템 콜](#제어-케이퍼빌리티와-두-시스템-콜) 참고). 태스크의 도메인은 첫 `TCB_RESUME` 뒤에는 바뀌지 않습니다. ## 준비 큐 -스케줄러는 세 값을 유지합니다. 현재 태스크, 그리고 준비 큐의 머리와 꼬리입니다. 각각 TCB의 커널 주소이고 0은 없음을 뜻합니다. 큐는 TCB 자체의 `next`와 `prev` 필드로 연결되므로 별도 메모리가 필요 없습니다. 큐의 길이는 TCB 수로 제한되고, TCB는 사용자 공간이 untyped 메모리로 비용을 치른 것입니다. 따라서 스케줄러가 커널 메모리를 고갈시키는 수단이 될 수 없습니다. +스케줄러는 설치된 태스크를 유지하고, **8개 도메인마다** 준비 큐의 머리와 꼬리, 기한 목록의 머리를 유지합니다. 각 값은 TCB의 커널 주소이고 0은 없음을 뜻합니다. 큐는 TCB 자체의 `next`와 `prev` 필드로 연결되므로 별도 메모리가 필요 없습니다. 큐의 길이는 TCB 수로 제한되고, TCB는 사용자 공간이 untyped 메모리로 비용을 치른 것입니다. 따라서 스케줄러가 커널 메모리를 고갈시키는 수단이 될 수 없습니다. + +태스크는 자기 도메인의 큐에만 들어갑니다. 모든 깨우기가 사용하는 `k0_sched::enqueue`는 TCB에서 도메인을 읽으며, 호출자는 큐를 고를 수 없습니다. 스케줄러가 직접 태스크를 큐에 넣을 때(순환할 때 또는 창이 끝날 때)는 그 큐가 태스크 자신의 것인지 검사하고, 아니면 `k0: FATAL task queued outside its domain`을 출력하고 정지합니다. 표를 정하지 않았으면 모든 태스크가 도메인 0에 있고, 이전처럼 큐 하나만 사용합니다. 큐는 이중 연결이므로 큐 어디에 있는 태스크든 상수 시간에 뺄 수 있습니다. 태스크가 준비 상태에서 정리될 수 있고, 그때 커널이 큐를 훑어 찾아서는 안 되기 때문입니다. 제거할 때 링크가 큐의 머리와 꼬리와 일치하는지 검사합니다. 일치하지 않으면 큐가 손상된 것이므로 커널은 `k0: FATAL ready queue corrupt`를 출력하고 정지합니다. @@ -94,60 +103,190 @@ 예외가 EL0에서 도착하면 벡터 코드는 Rust 코드가 실행되기 전에 모든 사용자 레지스터를 현재 TCB의 컨텍스트에 저장합니다([exceptions_KR.md](exceptions_KR.md) 참고). 복귀할 때는 전역 `__current_context` 포인터가 가리키는 컨텍스트에서 레지스터를 복원합니다. 따라서 태스크 전환은 두 단계입니다. 1. `__current_context`를 다음 태스크의 저장 컨텍스트로 돌립니다. -2. 다음 태스크가 다른 최상위 페이지 테이블을 사용하면 `TTBR0_EL1`에 로드하고 TLB 전체를 무효화합니다. K0는 주소 공간 식별자(ASID)를 사용하지 않으므로, 서로 다른 주소 공간의 태스크 사이를 전환할 때마다 TLB를 전부 비웁니다. 같은 주소 공간의 태스크 사이 전환은 `TTBR0_EL1`을 건드리지 않습니다. +2. 다음 태스크가 다른 최상위 페이지 테이블을 사용하면 `TTBR0_EL1`에 로드하고 TLB 전체를 무효화합니다. K0는 주소 공간 식별자(ASID)를 사용하지 않으므로, 서로 다른 주소 공간의 태스크 사이를 전환할 때마다 TLB를 전부 비웁니다. 같은 주소 공간의 태스크 사이 전환은 `TTBR0_EL1`을 건드리지 않습니다. 도메인이 바뀔 때는 주소 공간이 그대로여도 TLB를 비웁니다. 태스크마다 다른 주소 공간에서 실행될 수 있으므로 `TTBR0_EL1`은 태스크 사이에서 실제로 바뀝니다. 설치돼 있는 주소 공간이 파괴될 때는 커널이 먼저 `TTBR0_EL1`을 빈 테이블로 바꿉니다. -이 전환을 사용하는 동작은 다음 표와 같이 다섯 가지입니다. 각 동작은 다음 태스크의 진입 종류를 함께 넘깁니다. 틱의 판정으로 CPU를 받았으면 `Tick`, 틱과 틱 사이에 받았으면 `Between`입니다. 커널이 이를 유지하는 까닭은 다음 절에서 설명합니다. +다음에 누가 실행될지에 대한 판정은 모두 한 곳, 크레이트 `k0-part`의 타입 `Core`에서 내립니다. `Core`는 표, 도는 도메인(지금 실행 차례인 도메인), 실행 중인 태스크, 슬라이스 규칙의 표시를 가지며, 큐에는 작은 트레이트(`Env`)를 통해서만 접근합니다. 그래서 호스트 테스트가 같은 코드를 가짜 환경 위에서 실행합니다. `k0-sched`는 그 트레이트를 실제 큐 위에 구현합니다. 커널은 다음 표의 함수 가운데 하나를 호출해 **어떤 사건이 일어났는지**만 스케줄러에 알립니다. 진입 종류나 "틱이 지나갔다"는 플래그를 넘기는 일이 없으므로 틀린 값을 넘길 수도 없습니다. + +진입 종류는 다음 태스크가 CPU를 어떻게 받았는지를 말합니다. 틱의 판정으로 받았으면 `Tick`, 틱과 틱 사이에 받았으면 `Between`입니다. `Core`가 이를 유지하는 까닭은 다음 절들에서 설명합니다. -| 동작 | 사용처 | 현재 태스크에 일어나는 일 | 다음 태스크의 진입 종류 | +| `k0-sched`의 함수 | 호출되는 경우 | 현재 태스크에 일어나는 일 | 다음 태스크의 진입 종류 | | --- | --- | --- | --- | -| `rotate` | `YIELD` | 준비 큐의 꼬리로 가고, 준비된 다른 태스크가 없으면 그대로 계속 실행 | `Between` | -| `on_tick` | 타이머 선점 | 틱과 틱 사이에 CPU를 받았고 아직 틱을 맞은 적이 없으면 계속 실행하며 면제를 소모합니다. 그렇지 않으면 준비 큐의 꼬리로 가고, 준비된 다른 태스크가 없으면 그대로 계속 실행 | `Tick` | +| `rotate` | `YIELD` | 자기 도메인 준비 큐의 꼬리로 가고, 그 도메인에 준비된 다른 태스크가 없으면 그대로 계속 실행 | `Between` | +| `on_tick` | EL0에서 받은 타이머 틱 | 창 안에서는 틱과 틱 사이에 CPU를 받았고 아직 틱을 맞은 적이 없으면 계속 실행하며 면제를 소모합니다. 그렇지 않으면 큐의 꼬리로 가고, 준비된 다른 태스크가 없으면 그대로 계속 실행합니다. 창이 끝날 때는 자기 도메인의 큐에 세워 둡니다([창](#창) 참고) | `Tick` | | `block_and_switch` | IPC, `CONSOLE_READ`, 그리고 현재 태스크가 죽었을 때의 시스템 콜 종료 경로 | 준비 큐 밖에 머뭅니다. 호출자가 이미 엔드포인트 큐, 응답 자격 뒤, 콘솔 대기자 슬롯 중 하나에 걸어 두었거나, 태스크가 `Dead`입니다. | `Between` | -| `resume_from_idle` | idle 루프 | (현재 태스크는 블록됐거나 죽음) | 대기 중 틱이 지나갔으면 `Tick`, 아니면 `Between` | +| `poll` | 대기 루프, 인터럽트마다 | (실행 중인 태스크 없음) | 커널이 기다리는 동안 틱 번호가 올라갔으면 `Tick`, 아니면 `Between` | | `handoff` | 부트, 한 번 | 루트 태스크가 첫 `Running` 태스크가 됨 | `Between` | +| `set_table` | `PART_SET_TABLE` | 계속 실행 | (전환 없음) | + +이 함수들은 어느 것도 다른 도메인의 큐에서 태스크를 꺼내지 않습니다. 도는 도메인에 준비된 태스크가 없으면 `block_and_switch`, `on_tick`, `poll`이 그 사실을 알리고, 커널은 기다립니다([실행할 태스크가 없을 때](#실행할-태스크가-없을-때) 참고). ## 선점 -타이머는 1초에 한 번 발생합니다. EL0가 실행 중일 때 발생하면 IRQ 경로가 인터럽트를 확인하고 타이머를 다시 설정한 뒤 `k0: tick N`을 출력하고 `k0_preempt`를 호출합니다. `k0_preempt`는 기한이 된 콘솔 대기자와 타임아웃 대기자를 깨운 다음 `k0_sched::on_tick`을 호출하고, `on_tick`이 이번 틱이 현재 태스크를 끊을지 정합니다([슬라이스 규칙](#슬라이스-규칙) 참고). `k0: tick N`은 콘솔 드라이버를 포함해 빌드한 이미지에서는 콘솔에 출력하며, 로그에는 처음 4개의 tick 줄만 남깁니다. 양보하지도 블록하지도 않는 태스크는 **최대 2초 뒤에는 CPU를 잃고**, 틱에서 CPU를 받았다면 1초 뒤에 잃습니다. 태스크가 콘솔 입력을 읽은 뒤에는 줄 하나 `k0: tick lines off (console input in use)`를 남기고 틱 줄이 멈추지만, 틱과 선점과 타임아웃은 계속됩니다. +틱은 1초입니다. n번 틱은 정해진 시각에 옵니다. 타이머를 설정할 때 읽은 카운터 값에 주기 n개를 더한 시각입니다. 타이머는 언제나 이런 절대 시각에 맞춰 설정하므로, 핸들러가 늦게 실행되어도 뒤의 틱이 밀리지 않습니다([틱 시계와 건너뛴 틱](#틱-시계와-건너뛴-틱) 참고). + +EL0가 실행 중일 때 타이머가 발생하면 IRQ 경로가 인터럽트를 확인하고, 틱 번호를 계산하고, 다음 틱을 설정한 뒤 `k0: tick N`을 출력하고 `k0_preempt`를 호출합니다. `k0_preempt`는 `k0_sched::on_tick`을 호출합니다. 창 안에서는 스케줄러가 먼저 도는 도메인에서 기한이 된 콘솔 읽는 쪽과 타임아웃 대기자를 깨운 다음, 이번 틱이 현재 태스크를 끊을지 정합니다([슬라이스 규칙](#슬라이스-규칙) 참고). 창이 끝날 때는 현재 태스크를 세워 두고 다음 도메인으로 들어갑니다([창](#창) 참고). + +표를 정하지 않았으면 양보하지도 블록하지도 않는 태스크는 **최대 2초 뒤에는 CPU를 잃고**, 틱에서 CPU를 받았다면 1초 뒤에 잃습니다. 표가 있으면 태스크 자신의 창 안에서 같은 것이 성립하고, 창이 끝나면 태스크가 무엇을 했든 CPU를 내놓습니다. + +`k0: tick N` 줄은 콘솔 드라이버를 포함해 빌드한 이미지에서는 콘솔에 출력합니다. 로그에는 처음 4개의 tick 줄만 남기며, 번호를 건너뛰었거나 표가 정해져 있어도 이 줄들은 남깁니다. 콘솔에만 나가는 그 뒤의 줄은 루트 도메인이 아닌 도메인이 적힌 표가 정해져 있거나 보류 중인 동안에는 출력하지 않습니다. 태스크가 콘솔 입력을 읽은 뒤에는 줄 하나 `k0: tick lines off (console input in use)`를 남기고 틱 줄이 멈추지만, 틱과 선점과 타임아웃은 계속됩니다. > [!IMPORTANT] > 커널 자체는 선점되지 않습니다. 예외 진입이 인터럽트를 마스크하고, 커널은 시스템 콜이나 폴트를 처리하는 동안 마스크를 유지합니다. -틱은 여전히 준비된 다른 태스크가 있을 때만 태스크를 끊습니다. EL1에서 타이머 인터럽트가 도착하는 것은 이양 전 부트 중이나 커널이 대기하는 동안에만 가능하며, 그때는 틱을 세기만 합니다. `on_tick`은 EL0에서 받은 틱마다 정확히 한 번 호출됩니다. `console-input` 이미지에서 입력 바이트가 도착해도 선점하지 않습니다. 깨어난 읽는 쪽은 다른 깨어난 태스크처럼 준비 큐의 맨 뒤로 갑니다. 우선순위가 없으므로 입력 지연은 준비된 태스크마다 최대 한 틱이고, 실행 중인 태스크가 틱과 틱 사이에 CPU를 받았다면 한 틱이 더해집니다. +창 안에서 틱은 여전히 같은 도메인에 준비된 다른 태스크가 있을 때만 태스크를 끊습니다. EL1에서 타이머 인터럽트가 도착하는 것은 이양 전 부트 중이나, 실행할 것이 없어 커널이 기다리는 동안에만 가능합니다. 그때는 틱을 세기만 하고, 대기 루프가 곧바로 새 번호를 스케줄러에 넘깁니다(`poll`). `on_tick`은 EL0에서 받은 틱 사건마다 정확히 한 번 호출되며, 설정해 둔 시각보다 일찍 도착한 타이머 인터럽트는 틱이 아닙니다. `console-input` 이미지에서 입력 바이트가 도착해도 선점하지 않습니다. 깨어난 읽는 쪽은 다른 깨어난 태스크처럼 자기 도메인 준비 큐의 맨 뒤로 갑니다. 우선순위가 없으므로 입력 지연은 준비된 태스크마다 최대 한 틱이고, 실행 중인 태스크가 틱과 틱 사이에 CPU를 받았다면 한 틱이 더해집니다. ## 슬라이스 규칙 -타이머는 틱 핸들러에서만 다시 설정하며, 커널이 태스크를 전환할 때는 건드리지 않습니다. 그래서 틱과 틱 사이에 CPU를 받은 태스크는 주기의 남은 조각만 받습니다. 이 규칙이 생기기 전에는 얼마나 짧게 실행했든 다음 틱이 그 태스크를 큐의 끝으로 보냈습니다. 태스크가 매 틱 직전에 `YIELD`를 호출할 수 있었고, `YIELD`에는 케이퍼빌리티가 필요 없습니다. 그러면 뒤에 선 태스크는 양보 뒤의 조각만 받고, 양보한 태스크는 다음 온전한 주기를 위해 큐의 맨 앞으로 돌아옵니다. CPU를 계속 쓰는 태스크 둘을 QEMU에서 돌린 실행에서, 공격 태스크가 주기의 90 %에서 양보하면 다른 태스크의 몫이 약 52 %에서 7.9 %부터 11.1 % 사이로 떨어졌습니다. 이 실행의 양보 지점은 루트 태스크가 공격 태스크를 위해 측정한 반복 횟수로 정했습니다. 틱의 위상을 스스로 찾아내는 공격 태스크는 만들지 않았습니다. +틱은 정해진 시각에 오고, 태스크 전환은 그 시각을 옮기지 않습니다. 그래서 틱과 틱 사이에 CPU를 받은 태스크는 주기의 남은 조각만 받습니다. 이 규칙이 생기기 전에는 얼마나 짧게 실행했든 다음 틱이 그 태스크를 큐의 끝으로 보냈습니다. 태스크가 매 틱 직전에 `YIELD`를 호출할 수 있었고, `YIELD`에는 케이퍼빌리티가 필요 없습니다. 그러면 뒤에 선 태스크는 양보 뒤의 조각만 받고, 양보한 태스크는 다음 온전한 주기를 위해 큐의 맨 앞으로 돌아옵니다. CPU를 계속 쓰는 태스크 둘을 QEMU에서 돌린 실행에서, 공격 태스크가 주기의 90 %에서 양보하면 다른 태스크의 몫이 약 52 %에서 7.9 %부터 11.1 % 사이로 떨어졌습니다. 이 실행의 양보 지점은 루트 태스크가 공격 태스크를 위해 측정한 반복 횟수로 정했습니다. 틱의 위상을 스스로 찾아내는 공격 태스크는 만들지 않았습니다. -규칙은 크레이트 `k0-slice`에 있으며, 이 크레이트는 "이번 틱이 현재 태스크를 끊는가"라는 물음에만 답합니다. 스케줄러는 현재 태스크 옆에 표시를 하나 두고, 현재 태스크가 바뀌는 곳에서만 그 표시를 기록합니다. +규칙은 크레이트 `k0-slice`에 있으며, 이 크레이트는 "이번 틱이 현재 태스크를 끊는가"라는 물음에만 답합니다. `Core`는 실행 중인 태스크 옆에 표시를 하나 두고, 실행 중인 태스크를 바꾸는 단 하나의 함수에서만 그 표시를 기록합니다. -- 틱과 틱 사이에 CPU를 받은 태스크(`Entry::Between`)는 처음 맞는 틱에 끊기지 않습니다. 그 틱이 면제를 소모하고, 태스크는 그다음 틱까지 실행합니다. 앞선 태스크가 `YIELD`를 호출했거나, 블록됐거나(IPC 또는 `CONSOLE_READ`), 종료됐거나 죽은 경우, 그리고 커널이 대기하다가 콘솔 입력처럼 틱이 아닌 일로 깨어난 경우가 여기에 해당합니다. -- 틱의 판정으로 CPU를 받은 태스크(`Entry::Tick`)는 주기의 처음에 들어온 것이므로 이전처럼 다음 틱에서 끊깁니다. 틱이 깨운 뒤(예를 들어 기한이 지난 타임아웃) 대기 중이던 커널이 전환해 준 태스크도 여기에 속합니다. 틱과 콘솔 입력이 같은 깨어남에 함께 오면 `Entry::after_idle`이 틱으로 셉니다. +- 틱과 틱 사이에 CPU를 받은 태스크(`Entry::Between`)는 처음 맞는 틱에 끊기지 않습니다. 그 틱이 면제를 소모하고, 태스크는 그다음 틱까지 실행합니다. 앞선 태스크가 `YIELD`를 호출했거나, 블록됐거나(IPC 또는 `CONSOLE_READ`), 종료됐거나 죽은 경우, 그리고 커널이 기다리다가 콘솔 입력처럼 틱이 아닌 일로 깨어난 경우가 여기에 해당합니다. +- 틱의 판정으로 CPU를 받은 태스크(`Entry::Tick`)는 주기의 처음에 들어온 것이므로 이전처럼 다음 틱에서 끊깁니다. 틱이 깨운 뒤(예를 들어 기한이 지난 타임아웃) 기다리던 커널이 전환해 준 태스크, 그리고 창이 열리는 도메인의 첫 태스크도 여기에 속합니다. 틱과 콘솔 입력이 같은 깨어남에 함께 오면 틱으로 셉니다. `Core::poll`이 틱 번호만 보고 판정하기 때문입니다. - 부트 때의 루트 태스크는 틱과 틱 사이에 들어온 것으로 셉니다. 타이머가 부트 중에 이미 돌고 있기 때문입니다. -- 태스크를 깨우는 것은 면제를 주지 않습니다. 깨어난 태스크는 이전처럼 준비 큐의 맨 뒤로 가고, 콘솔 입력은 여전히 선점하지 않습니다. +- 태스크를 깨우는 것은 면제를 주지 않습니다. 깨어난 태스크는 이전처럼 자기 도메인의 준비 큐 맨 뒤로 가고, 콘솔 입력은 여전히 선점하지 않습니다. - 준비된 다른 태스크가 없을 때의 `YIELD`는 아무것도 바꾸지 않습니다. -`Slice::entered`는 진입 종류만으로 표시를 대입하고 이전 값을 읽지 않으므로, 앞 태스크가 남긴 표시가 전환을 넘어 살아남지 않습니다. 면제는 `YIELD`뿐 아니라 블록과 종료에도 줍니다. `YIELD`만 주면, 틱 직전마다 타임아웃 대기를 시작하는 두 태스크가 그 사이의 태스크를 굶길 수 있습니다(모델이 이 경우를 보여 줍니다). +`Slice::entered`는 진입 종류만으로 표시를 대입하고 이전 값을 읽지 않으므로, 앞 태스크가 남긴 표시가 전환을 넘어 살아남지 않습니다. 다른 도메인의 태스크가 남긴 표시도 마찬가지입니다. 면제는 `YIELD`뿐 아니라 블록과 종료에도 줍니다. `YIELD`만 주면, 틱 직전마다 타임아웃 대기를 시작하는 두 태스크가 그 사이의 태스크를 굶길 수 있습니다(모델이 이 경우를 보여 줍니다). -규칙에서 따라 나오는 것은 다음과 같습니다. +도메인이 하나일 때 규칙에서 따라 나오는 것은 다음과 같습니다. - 전환돼 들어온 태스크는 스스로 CPU를 내놓지 않는 한 온전한 한 틱 주기를 채우기 전에는 타이머에 끊기지 않습니다. 강제로 선점되기 전에 적어도 한 주기, 많아야 두 주기를 실행합니다. -- 준비된 태스크가 N개일 때 양보하지도 블록하지도 않는 태스크는 다른 태스크가 `YIELD`, 블록, 타임아웃 대기를 어떻게 하든 오래 보면 CPU의 1/N 이상을 유지합니다. 이는 모델에서 탐색으로 확인했습니다([테스트 방법](#테스트-방법) 참고). **증명이 아니며**, **예산도 아닙니다**. 태스크가 쓸 수 있는 양에 상한이 없고, 태스크를 만들 때마다 N이 늘어납니다. +- 준비된 태스크가 N개일 때 양보하지도 블록하지도 않는 태스크는 다른 태스크가 `YIELD`, 블록, 타임아웃 대기를 어떻게 하든 오래 보면 CPU의 1/N 이상을 유지합니다. 이는 모델에서 탐색으로 확인했고, Lean 정리 하나가 도메인 하나의 모델에 대해 이를 진술합니다([테스트 방법](#테스트-방법) 참고). **Rust 코드에 대한 증명이 아니며**, 도메인이 여럿인 표에 대해서는 그런 진술이 없고, **예산도 아닙니다**. 태스크가 쓸 수 있는 양에 상한이 없고, 태스크를 만들 때마다 N이 늘어납니다. - 대가는 지연입니다. 앞에 실행할 태스크가 k개(실행 중인 것 포함)인 채로 준비된 태스크는 예전에는 k 틱 주기 안에 시작했고, 지금은 k + 1 주기 안에 시작합니다. 모델에서는 CPU를 계속 쓰는 태스크 하나 뒤에서 호출과 응답을 주고받는 호출자와 서버가 왕복마다 2틱 대신 4틱이 필요합니다. CPU를 계속 쓰는 태스크가 없으면 달라지는 것이 없습니다. +표가 있을 때는 이 내용을 도메인 자신의 시간, 즉 그 도메인의 창을 이어 붙인 시간 위에서 읽어야 합니다. 창을 끝내는 틱은 실행 중인 태스크에 같은 규칙을 적용한 다음 그 태스크를 세워 둡니다([창](#창) 참고). 그래서 태스크는 온전한 한 주기를 실행하기 전에 창의 끝에서 CPU를 내놓을 수 있습니다. 그 태스크는 자기 도메인의 다음 창에서 이어집니다. 도메인이 바뀌면서 끝나는 창은 보호 구간만큼 더 짧습니다([보호 구간과 틱 시각까지의 대기](#보호-구간과-틱-시각까지의-대기) 참고). + > [!NOTE] > 이 절의 수치(실행당 한 주기부터 두 주기, 대기 k + 1 주기)는 이 버전 스케줄러의 동작을 설명할 뿐 인터페이스가 아닙니다. 틱은 여전히 1초이고 타임아웃은 여전히 틱 단위로 셉니다. ## 타임아웃 -틱은 [ipc_KR.md](ipc_KR.md)에서 설명하는 모든 IPC 타임아웃의 단위입니다. 스케줄러는 기한이 있는 대기자를 기한 목록(`k0-sched`의 `arm_timeout`, `disarm_timeout`, `expired`, `has_timed`)에 유지합니다. 이 리스트는 정렬되어 있지 않고, 가장 이른 기한의 하한 덕분에 대부분의 틱은 리스트를 건너뜁니다. +틱은 [ipc_KR.md](ipc_KR.md)에서 설명하는 모든 IPC 타임아웃의 단위입니다. 스케줄러는 기한이 있는 대기자를 기한 목록에 유지하며, 목록은 **도메인마다 하나**입니다(`k0-sched`의 `arm_timeout`, `disarm_timeout`, `expired`, `has_timed`). 목록은 정렬되어 있지 않고, 가장 이른 기한의 하한 덕분에 대부분의 틱은 목록을 건너뜁니다. 새 대기자는 목록의 머리에 연결됩니다. + +태스크가 블록 상태를 벗어나는 길은 `k0_sched::enqueue`(깨우기)와 `k0_ipc::teardown`(죽음)뿐이며, 둘 다 태스크를 자기 도메인의 기한 목록에서 제거합니다. 기한은 전역 틱 번호입니다. n 틱의 타임아웃은 그 사이에 어느 도메인이 돌든 호출 뒤 (n+1)번째 틱에서 끝납니다. + +`k0_ipc::expire_timeouts`는 **도메인 하나**에서 기한이 지난 대기자를 깨웁니다. 스케줄러는 도는 도메인에 대해서만 이 함수를 호출합니다. 그 도메인의 창 안에 있는 틱마다, 그 창을 여는 틱에서, 그리고 그 도메인이 도는 동안 대기 루프에서 호출합니다. 다른 도메인의 목록은 들여다보지 않습니다. 그래서 표가 있을 때 타임아웃은 **늦게 끝날 수는 있어도 일찍 끝나지는 않습니다**. 다른 도메인이 도는 동안 기한이 지난 대기자는 자기 도메인의 다음 창의 첫 틱에서 깨어납니다. 목록은 머리부터 훑으므로, 여러 대기자의 기한이 함께 지나 있으면 가장 나중에 기한을 건 대기자가 먼저 큐에 들어갑니다. -태스크가 블록 상태를 벗어나는 길은 `k0_sched::enqueue`(깨우기)와 `k0_ipc::teardown`(죽음)뿐이며, 둘 다 태스크를 기한 목록에서 제거합니다. 타이머 틱마다 `k0_ipc::expire_timeouts`가 기한이 지난 대기자를 깨웁니다. 태스크가 실행 중이었다면 `k0_preempt`에서, 없었다면 idle 루프에서 실행됩니다. n 틱의 타임아웃은 호출 뒤 (n+1)번째 틱에서 끝납니다. +> [!NOTE] +> 타임아웃은 태스크가 준비되는 시점이지 실행되는 시점이 아닙니다. 깨어난 태스크는 다른 태스크와 마찬가지로 자기 도메인 준비 큐의 꼬리에 들어갑니다. + +## 시간 분할 + +K0에는 항상 컴파일되어 들어가는 도메인 스케줄러가 있습니다. 모든 태스크는 0부터 7까지 번호가 붙은 8개 **도메인** 가운데 하나에 속하고, **표**가 어느 틱에 어느 도메인이 CPU를 사용할 수 있는지 정합니다. 도메인은 표에 있는 자기 창에서만 실행됩니다. 이 메커니즘이 겨냥하는 채널은 하나뿐이며, **도메인 사이에서 스케줄러를 거치는 채널**입니다. 주장과 그 한계는 [시간 분할이 주장하는 것과 주장하지 않는 것](#시간-분할이-주장하는-것과-주장하지-않는-것)에 함께 적었습니다. > [!NOTE] -> 타임아웃은 태스크가 준비되는 시점이지 실행되는 시점이 아닙니다. 깨어난 태스크는 다른 태스크와 마찬가지로 준비 큐의 꼬리에 들어갑니다. +> 도메인을 둘 이상 사용하는 이미지는 아직 없습니다. 루트 태스크가 부팅할 때마다 이 메커니즘을 시험해 본 뒤 제어 케이퍼빌리티를 삭제하므로, 지금 빌드하는 모든 이미지는 도메인 하나로, 표가 봉인된 채 실행됩니다. 키 볼트를 자기만의 도메인에 두는 것은 앞으로 할 일입니다. + +다음 그림은 항목 셋짜리 표와, 도메인이 바뀌는 자리에서 일어나는 일을 보여 줍니다. + +

+ 항목 셋짜리 표가 도메인 1에 1틱, 도메인 0에 1틱, 도메인 2에 2틱을 주고 되풀이되는 모습. 도메인은 자기 창에서만 실행되고, 준비된 태스크가 없으면 CPU는 기다립니다. 도메인이 바뀌는 틱 앞에서는 타이머 인터럽트를 틱의 40분의 1만큼 일찍 받아 커널이 전환 작업을 하고 기다리며, 다음 도메인은 틱 시각에 시작합니다 +

+ +### 도메인과 표 + +표의 항목은 1개부터 16개까지입니다. 항목마다 도메인(0부터 7) 하나와 틱 수(1부터 255)를 적습니다. 표는 0번 항목부터 마지막 항목까지 돈 뒤 처음으로 돌아갑니다. 틱은 1초이므로 표 한 바퀴는 1초에서 68분 사이입니다. + +- **표를 정하지 않은 경우**: 커널은 기본 표로 시작합니다. 항목 하나가 모든 틱을 도메인 0에 주는 표입니다. 도메인 0은 **루트 도메인**이며 루트 태스크가 속한 도메인입니다. 이 표에서는 틱을 건너뛰지 않는 한 스케줄러가 같은 사건 순서에 대해 이전 스케줄러와 같은 판정을 내립니다(틱을 건너뛸 때 달라진 점은 [틱 시계와 건너뛴 틱](#틱-시계와-건너뛴-틱) 참고). +- **루트 도메인만 적힌 표**: 창의 길이가 어떻든 기본 표처럼 동작하며, 커널은 시스템이 분할된 것으로 다루지 않습니다. +- **어떤 표에도 없는 도메인**: 그 도메인의 태스크는 실행되지 않습니다. 준비 상태로 남으며, 삭제는 여전히 할 수 있습니다. +- **태스크의 도메인이 정해지는 곳**: 태스크는 자신을 구성한 태스크(`TCB_CONFIGURE`)의 도메인을 받습니다. 제어 케이퍼빌리티를 가진 쪽만 태스크를 다른 도메인에 넣을 수 있고, 태스크가 처음 실행되기 전에만 가능합니다. + +### 창 + +**창**은 표가 한 도메인에 주는 연속된 틱의 묶음입니다. 같은 도메인이 이어지는 항목들은 표의 끝을 넘어 이어지는 경우까지 포함해 창 하나이며, 그 사이의 틱은 보통의 틱입니다. + +- **n번 틱에 어느 도메인이 도는지**는 표, 표가 시작된 틱, n의 함수입니다. 태스크가 하는 어떤 일도 여기에 들어가지 않습니다. +- **창 안의 틱**은 이전처럼 처리합니다. 도는 도메인에서 기한이 된 대기자를 깨운 다음, 슬라이스 규칙이 실행 중인 태스크를 자기 도메인 큐의 꼬리로 보낼지 정합니다. +- **창을 끝내는 틱**은 실행 중인 태스크에 슬라이스 규칙을 한 번 적용한 다음 그 태스크를 자기 도메인의 큐에 세워 둡니다. 규칙이 태스크를 그대로 두면 태스크는 큐의 맨 앞에 섭니다. 규칙이 태스크를 순환시키고 그 도메인에 준비된 다른 태스크가 있으면 태스크는 꼬리로 가고, 그 다른 태스크가 맨 앞에 섭니다. 그다음 커널은 TLB를 비우고, 들어오는 도메인에서 기한이 된 대기자를 깨우고, 그 도메인 큐의 맨 앞에 있는 태스크로 들어갑니다. 이 진입은 틱의 판정에 따른 것으로 셉니다. 세워 둔 태스크는 `Ready`이며, 자기 도메인의 다음 창이 열릴 때 이어집니다. +- **남는 시간은 넘겨주지 않습니다**: 들어오는 도메인이 비어 있거나, 마지막 태스크가 창 중간에 블록되거나 종료해서 도는 도메인에 준비된 태스크가 없으면 CPU는 기다립니다. 그 도메인의 태스크가 준비되거나 창이 끝날 때까지 기다립니다. 다른 도메인의 준비된 태스크를 대신 실행하지 않습니다. +- **깨어난 태스크는 자기 도메인의 큐로 갑니다**. 깨어날 때 어느 도메인이 돌고 있든 그렇고, 그 태스크는 자기 창에서 실행됩니다. + +### 틱 시계와 건너뛴 틱 + +n번 틱은 `T0 + n * P`에 옵니다. `T0`는 부팅 때 타이머를 설정하면서 읽은 카운터 값이고, `P`는 카운터 단위로 나타낸 1초입니다. 이 산술은 `k0_part::clock`에 있고 하드웨어를 건드리지 않으므로 호스트에서 테스트합니다. `crates/k0-arch/src/irq.rs`는 레지스터를 읽고 쓰기만 합니다. + +- 타이머 비교 값은 언제나 이 격자 위의 절대 시각입니다. 핸들러가 얼마나 오래 걸렸는지는 다음 틱이 오는 시각에 영향을 주지 않습니다. +- 틱 번호는 카운터의 함수입니다. 타이머 인터럽트를 처리할 때 틱 번호는 "마지막 번호에 1을 더한 값"과 "`T0` 뒤로 지난 온전한 주기의 수" 가운데 큰 쪽이 됩니다. +- **늦은 핸들러는 번호를 건너뜁니다**: 커널이 한 주기보다 오래 인터럽트를 마스크했거나 호스트가 가상 머신을 멈춰 세웠으면 그 사이의 번호는 건너뜁니다. 건너뛴 틱을 다시 재생하지 않습니다. 스케줄러는 도착한 번호를 가진 틱 사건 하나만 보고, 표의 위치는 그 번호로 계산합니다. 그래서 **한 틱보다 긴 멈춤은 창을 건너뛰며**, 도메인이 창 하나를 통째로 잃을 수 있습니다. +- 설정해 둔 시각보다 일찍 도착한 타이머 인터럽트는 틱으로 세지 않습니다. 같은 시각을 다시 설정합니다. + +> [!NOTE] +> 이 변경 전에는 커널이 자신이 처리한 틱을 세었고, 핸들러가 끝날 때마다 한 주기 뒤로 타이머를 설정했습니다. 그때는 멈춤이 뒤의 모든 틱을 밀었고 번호는 건너뛰지 않았습니다. 지금은 멈춤이 번호를 건너뛰고 틱은 옮기지 않습니다. 도메인이 하나일 때 틱에서 내리는 판정은 어느 쪽이든 같습니다. 달라지는 것은 틱이 받는 번호이고, 그에 따라 타임아웃이 끝나는 틱입니다. + +### 보호 구간과 틱 시각까지의 대기 + +다음 도메인이 시작하는 시각을 옮길 수 있는 도메인에는 여전히 채널이 남습니다. 틱이 올 때 진행 중이던 시스템 콜은 틱 핸들러를 늦추고, 얼마나 늦추는지는 나가는 도메인이 무엇을 하기로 했는지에 달려 있습니다. 다음 두 가지가 이를 제한합니다. + +- **보호 구간**: 다음 틱에서 도메인이 바뀔 예정이면 스케줄러는 타이머를 틱 시각보다 틱의 40분의 1(25 ms)만큼 앞당겨 설정합니다. 인터럽트를 그만큼 일찍 받고, 이 보호 구간 안에서 틱을 처리하고 전환 작업을 합니다. 이 결정은 틱이 끝날 때마다, 그리고 `PART_SET_TABLE`이 끝날 때마다 다시 내립니다. 곧 시작하려던 표를 바꾸는 호출은 다음 틱의 도메인을 바꿀 수 있기 때문입니다. 그런 호출이 보호 구간 안에 들어오면 그 틱 하나의 보호 구간은 더 짧습니다. +- **틱 시각까지의 대기**: 예외에서 EL0로 돌아가는 모든 길은 복귀 함수 하나, `k0_leave`를 지납니다. 이 함수는 먼저 돌아갈 태스크가 `Running`이고 도는 도메인에 속하는지 검사하고, 아니면 `k0: FATAL returning to a task outside its window`를 출력하고 정지합니다. 그다음 마지막으로 처리한 틱의 시각까지 스핀하며 기다립니다. 틱을 일찍 받은 뒤라면 그 시각이 틱 시각입니다. 그 밖의 경우에는 그 시각이 이미 지났으므로 함수는 곧바로 돌아옵니다. + +결과는 다음과 같고 그 이상은 아닙니다. **진행 중이던 커널 경로와 전환 작업이 보호 구간 안에 들어가는 한, 다음 도메인은 스핀과 복귀 경로만큼의 오차 안에서 틱 시각에 시작합니다**. 보호 구간보다 길고 보호 구간이 시작될 때 진행 중이던 커널 경로는 여전히 다음 창의 시작을 늦춥니다. + +보호 구간은 나가는 도메인에게서 마지막 25 ms를 가져갑니다. 도메인이 바뀌면서 끝나는 창마다 그렇습니다. 창 안의 틱, 그리고 도메인이 하나일 때의 모든 틱은 틱 시각에 맞춰 설정하며 보호 구간이 없습니다. + +개발용 Mac에서 한 번 측정했을 때, 틱 핸들러에 진입한 시점은 QEMU TCG에서 보호 구간이 시작되고 2~5 ms 뒤, HVF에서 5~31마이크로초 뒤였습니다. 이는 한 기계에서 한 번 측정한 값이며 상한이 아닙니다. + +### 제어 케이퍼빌리티와 두 시스템 콜 + +표와 도메인에 대한 권한은 케이퍼빌리티 하나, `PartCtl`(종류 9)입니다. 커널은 부팅 때 정확히 하나를 만들어 루트 CNode의 슬롯 5에 넣습니다([capabilities_KR.md](capabilities_KR.md) 참고). 권한 비트가 없고, 뒤에 오브젝트도 없습니다. + +- **복사할 수 없습니다**: `CAP_COPY`는 권한 마스크와 배지가 무엇이든 `BAD_CAP`을 돌려줍니다. `CAP_MOVE`로 옮길 수는 있으며, 권한은 슬롯을 따라갑니다. +- **삭제하면 표와 도메인이 영구히 봉인됩니다**: 어떤 것도 이 케이퍼빌리티를 새로 만들 수 없으므로, `CAP_DELETE` 뒤에는 다음 부팅까지 어떤 태스크도 표나 태스크의 도메인을 바꿀 수 없습니다. 케이퍼빌리티를 삭제할 때 아직 보류 중이던 표는 효력이 생깁니다. + +두 시스템 콜은 `x0`에 이 케이퍼빌리티의 슬롯을 받습니다. 둘 다 레지스터만 읽습니다. 번호의 기준은 `crates/k0-abi/src/lib.rs`입니다. + +| 호출 | 인자 | 하는 일 | +| --- | --- | --- | +| `PART_SET_TABLE`(17) | `x0` = `PartCtl` 슬롯, `x1` = 항목 수(1부터 16), `x2`부터 `x5` = 항목 | 새 표를 정함 | +| `PART_SET_DOMAIN`(18) | `x0` = `PartCtl` 슬롯, `x1` = `Tcb` 슬롯, `x2` = 도메인(0부터 7) | 아직 실행된 적 없는 태스크를 도메인에 넣음 | + +표의 항목은 16비트이며 `(ticks << 8) | domain`입니다. i번 항목은 레지스터 `x(2 + i / 4)`의 비트 `16 * (i % 4)`부터 들어가므로, 네 레지스터가 각각 항목 넷을 담습니다. 사용하지 않는 비트는 전부 0이어야 하며, 마지막 항목 뒤의 항목 자리도 모두 여기에 포함됩니다. + +`PART_SET_TABLE`은 다음과 같이 동작합니다. + +- **효력이 생기는 때**: 새 표는 **마지막으로 처리한 틱의 두 틱 뒤에, 0번 항목부터** 시작합니다. 그 사이의 틱은 호출 시점에 효력이 있는 표가 정합니다. +- **그 전에 한 번 더 호출하면** 첫 표는 버려지고, 그 표는 어떤 틱도 정하지 못합니다. 호출이 바로 다음 틱의 도메인을 바꾸는 경우는 이것 하나뿐입니다. 버려진 표가 그 틱에서 시작할 예정이었다면 그 틱은 효력이 있는 표로 돌아갑니다. 이미 효력이 있는 표는 새 표가 시작할 때까지 유지됩니다. +- **표에는 호출자 자신의 도메인이 있어야 합니다**: 케이퍼빌리티를 가진 쪽이 실수로 자신이 다시는 실행되지 않는 표를 정하는 일을 막습니다. +- **에러**: `x0`이 `PartCtl`을 가리키지 않으면 `BAD_SLOT` 또는 `BAD_CAP`입니다. 항목 수가 0이거나 16을 넘거나, 도메인이 7을 넘거나, 창이 0틱이거나, 사용하지 않는 비트가 서 있거나, 호출자의 도메인이 없으면 `BAD_TABLE`(-25)입니다. 거부된 호출은 아무것도 바꾸지 않습니다. + +`PART_SET_DOMAIN`은 다음과 같이 동작합니다. + +- **멈춰 있는 TCB만 받습니다**: 태스크는 `Stopped`, 즉 구성은 됐고 아직 재개되지 않은 상태여야 합니다. 이 상태의 태스크는 어떤 큐에도, 어떤 기한 목록에도 없습니다. 큐와 기한 목록은 도메인마다 따로 있으므로, 이 조건 덕분에 태스크가 자신이 떠난 도메인의 목록에 남는 일이 없습니다. +- **도메인이 표에 없어도 됩니다**: 어떤 표에도 없는 도메인에 넣은 태스크는 실행되지 않을 뿐입니다. +- **에러**: `x0`이 `PartCtl`을 가리키지 않으면 `BAD_SLOT` 또는 `BAD_CAP`, `x2`가 7을 넘으면 `BAD_DOMAIN`(-26), `x1`이 `Tcb`를 가리키지 않으면 `BAD_SLOT` 또는 `BAD_CAP`, TCB가 `Stopped`가 아니면 `BAD_STATE`입니다. 지금은 검사가 이 순서로 실행됩니다. + +### 표가 있을 때의 콘솔 입력 + +`console-input` 이미지에서 도착한 바이트는 **읽는 쪽의 도메인이 도는 동안에만** 기다리는 읽는 쪽에 전달됩니다. 다른 도메인이 돌고 있으면 바이트는 커널의 링에 남고, 읽는 쪽은 자기 도메인이 돌거나 자기 도메인으로 들어가는 다음 틱에서 그 바이트를 받습니다. 그래서 입력이 도착한 시각은 다른 도메인의 창 안에서 읽는 쪽의 큐를 바꾸지 않습니다. + +읽는 쪽을 깨우는 일 가운데 둘은 바이트가 아니며, 어느 도메인이 돌든 전달됩니다. 읽는 쪽이 케이퍼빌리티를 잃었을 때의 `REVOKED`와, 입력 경로가 꺼졌을 때의 `NO_DEVICE`입니다. 깨어난 읽는 쪽은 그래도 자기 창에서만 실행됩니다. 도메인이 하나일 때는 달라지는 것이 없습니다. + +> [!WARNING] +> 인터럽트 자체는 도메인에 묶여 있지 않습니다. 모든 콘솔 인터럽트의 시간, 그리고 틱 핸들러가 하는 UART 작업의 시간은 그때 돌고 있는 도메인의 시간에서 나갑니다. + +### 시간 분할이 주장하는 것과 주장하지 않는 것 + +주장은 다음과 같고 그 이상은 아닙니다. **고정 시간 분할은 도메인 사이에서 스케줄러를 거치는 채널을 닫습니다**. 표가 정해져 있으면 한 도메인의 어느 태스크가 어떤 순서로 어느 틱에 실행되는지는 다른 도메인의 태스크가 무엇을 하는지에 달려 있지 않습니다. 단, 도메인들이 커널 오브젝트를 공유하지 않고 다음 한계 가운데 어느 것도 해당하지 않을 때에 한합니다. 타이밍 채널 전반에 대한 주장이 아닙니다. + +> [!WARNING] +> 다음 한계는 주장의 일부입니다. 비밀을 한 도메인에, 관찰자를 다른 도메인에 두는 설계는 이 한계 하나하나에 비추어 확인해야 합니다. + +1. **긴 커널 경로**: 보호 구간보다 길고 보호 구간이 시작될 때 진행 중이던 커널 경로는 다음 창의 시작을 늦춥니다. `CAP_REVOKE`와 자손이 많은 케이퍼빌리티의 삭제가 그런 경로이고, 태스크가 끝날 때 커널이 느린 시리얼 줄에 출력하는 줄도 그렇습니다. 커널은 선점되지 않습니다. +2. **캐시와 분기 예측기**는 도메인이 바뀔 때 비우지 않습니다. TLB만 비웁니다. +3. **인터럽트 시간**: 콘솔 입력 인터럽트의 시간, 그리고 틱 핸들러가 하는 UART 작업의 시간은 그때 돌고 있는 도메인에 떨어집니다. 그 작업이 얼마나 되는지는 시리얼 입력과 수신 링이 얼마나 찼는지에 달려 있습니다. +4. **스케줄러 이외의 공유 커널 상태**: UART, 할당량이 있는 부트 로그, 하나뿐인 콘솔 대기자 슬롯(어느 도메인에서든 두 번째 읽는 쪽은 `BUSY`를 받음), 커널 메모리 풀입니다. +5. **건너뛴 틱**: 한 틱보다 긴 멈춤은 창을 건너뜁니다. +6. **공유 오브젝트는 설계상 채널입니다**: 두 도메인의 태스크가 함께 가진 엔드포인트는 그 둘 사이의 채널입니다. 다른 도메인과 공유한 오브젝트에 대한 그 밖의 케이퍼빌리티 연산도 모두 마찬가지입니다. 그 도메인의 태스크가 기다리는 엔드포인트의 삭제나 회수, 그 도메인의 태스크에게 돌려줄 응답 자격을 쥔 태스크의 종료, 그 도메인의 태스크에 대한 `TCB_RESUME`, 그 도메인의 TCB 삭제가 그렇습니다. 어느 것이든 케이퍼빌리티가 필요하며, 깨어난 태스크는 그래도 자기 창에서만 실행됩니다. +7. **보호 구간 안에서 깨어난 읽는 쪽**: 들어오는 도메인이 비어 있고 콘솔 입력이 보호 구간 안에서 그 도메인의 읽는 쪽을 깨우면, 읽는 쪽은 틱 시각에 시작하면서도 틱과 틱 사이에 들어온 것으로 다뤄져 처음 맞는 틱에 끊기지 않습니다. 이 영향은 읽는 쪽 자신의 도메인 안에 머뭅니다. +8. **어떤 테스트도 보지 못하는 것**: EL0에는 시계가 없으므로 부팅 테스트는 사건의 순서만으로 판정합니다. 보호 구간, 틱 시각까지의 대기, 도메인이 바뀔 때의 TLB 비우기는 어떤 테스트도 보지 못합니다. 이것들이 없는 커널도 모든 테스트를 통과합니다. 표가 있을 때의 콘솔 입력 규칙에도 테스트가 없습니다. 이 부분은 리뷰에 기대고 있습니다. +9. **증명은 모델에 대한 것**이며 Rust 코드에 대한 것이 아닙니다([테스트 방법](#테스트-방법) 참고). +10. **실제 하드웨어에서는 테스트하지 않았습니다**: 모든 실행은 QEMU의 TCG와 HVF에서 했습니다. + +도메인 하나 안에서는 달라진 것이 없습니다. 태스크는 양보하거나 블록할 시점을 골라 같은 도메인의 다른 태스크가 언제, 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. ## 정리 @@ -176,24 +315,32 @@ 모든 상태에서 이어서 태스크 자신이 쥔 응답 자격을 철회하므로, 그 응답을 기다리던 호출자는 `NO_REPLY`로 깨어나 영원히 블록되지 않습니다. 마지막으로 상태를 `Dead`로 바꾸고, 큐 링크, `blocked_on`, `reply_from`, `ipc_badge`, `ttbr0_pa`를 지우며, `Running`이 아니면 저장된 레지스터를 0으로 지웁니다. 상태가 약속하는 것과 큐나 응답 링크가 맞지 않으면 커널 불변식 위반이므로 커널은 `k0: FATAL ...`을 출력하고 정지합니다([exceptions_KR.md](exceptions_KR.md) 참고). -실행 중인 태스크는 정리가 끝까지 처리하지 않는 유일한 경우입니다. 시스템 콜 핸들러가 실행 중인 태스크의 저장 컨텍스트에 대한 가변 참조를 쥐고 있으므로, 정리는 그 태스크를 `Dead`로 표시하기만 합니다. 시스템 콜 종료 경로 `finish`는 핸들러가 끝나고, 제거된 모든 것의 종료 처리를 포함한 케이퍼빌리티 정리가 전부 끝난 뒤에 실행됩니다. 현재 태스크가 `Dead`이면 `finish`는 그 컨텍스트에 반환값을 기록하지 않고, 컨텍스트를 0으로 지운 뒤 다음 준비 태스크로 전환합니다. 그래서 태스크는 자신의 CNode, 주소 공간, TCB를 삭제하거나 자신이 잘려 나온 untyped를 회수하고도 이후에 다시 실행되는 일이 없습니다. +실행 중인 태스크는 정리가 끝까지 처리하지 않는 유일한 경우입니다. 시스템 콜 핸들러가 실행 중인 태스크의 저장 컨텍스트에 대한 가변 참조를 쥐고 있으므로, 정리는 그 태스크를 `Dead`로 표시하기만 합니다. 시스템 콜 종료 경로 `finish`는 핸들러가 끝나고, 제거된 모든 것의 종료 처리를 포함한 케이퍼빌리티 정리가 전부 끝난 뒤에 실행됩니다. 현재 태스크가 `Dead`이면 `finish`는 그 컨텍스트에 반환값을 기록하지 않고, 컨텍스트를 0으로 지운 뒤 같은 도메인의 다음 준비 태스크로 전환합니다. 그래서 태스크는 자신의 CNode, 주소 공간, TCB를 삭제하거나 자신이 잘려 나온 untyped를 회수하고도 이후에 다시 실행되는 일이 없습니다. 죽은 태스크의 프레임은 정리가 해제하지 않습니다. 프레임은 `Dead` TCB로 남고, `TCB_CONFIGURE`와 `TCB_RESUME`이 이를 거부하므로 죽은 태스크는 다시 시작되지 않습니다. 그 메모리는 TCB의 원본 케이퍼빌리티를 삭제하거나 그것이 나온 untyped를 회수한 뒤, untyped를 다시 retype할 때 재사용되며 그때 프레임은 다시 0으로 지워집니다. 단순히 종료만 한 태스크는 그때까지 묶인 케이퍼빌리티 두 개를 유지합니다. ## 실행할 태스크가 없을 때 -실행할 태스크가 없어도 커널은 더 이상 코어를 파킹하지 않습니다. 현재 태스크가 블록됐거나 죽었는데 준비된 태스크가 없으면 `kernel/src/syscall.rs`의 `idle_until_ready`가 다음 순서로 처리합니다. +실행할 태스크가 없어도 커널은 더 이상 코어를 파킹하지 않습니다. `kernel/src/syscall.rs`의 `wait_for_work`가 다음 세 경우에 넘겨받습니다. + +- 현재 태스크가 블록됐는데 그 도메인에 준비된 태스크가 없는 경우 +- 현재 태스크가 죽었는데 그 도메인에 준비된 태스크가 없는 경우 +- 틱이 창의 끝에서 실행 중이던 태스크를 끊었는데 들어오는 도메인에 준비된 태스크가 없는 경우 + +세 번째 경우에 끊긴 태스크는 `Ready`로 자기 큐에 서 있고, 스케줄러가 태스크를 설치할 때까지 어떤 것도 EL0로 돌아가지 않습니다. 루프는 다음과 같이 동작합니다. 1. 다음 인터럽트를 기다립니다(`k0_arch::irq::wait_for_interrupt`: IRQ를 마스크한 `wfi`, 그다음 EL1 벡터가 인터럽트를 받도록 잠깐 마스크 해제). -2. 기한이 지난 IPC 대기자를 모두 깨웁니다. -3. 준비된 태스크가 있으면 그 태스크로 전환하고(`resume_from_idle`, 대기 중 틱이 지나갔는지를 슬라이스 규칙에 알려 줍니다), 없으면 다시 기다립니다. +2. 스케줄러에 묻습니다(`k0_sched::poll`). 틱 번호가 올라갔으면 틱 사건입니다. 이때 표가 다른 도메인으로 넘어갈 수 있고, 도는 도메인에서 기한이 된 대기자를 깨웁니다. 올라가지 않았으면 인터럽트는 콘솔 입력이었고, 도는 도메인의 읽는 쪽을 깨웁니다. +3. 스케줄러가 태스크를 설치했으면 돌아가고, 아니면 다시 기다립니다. 다른 도메인의 준비된 태스크는 실행하지 않습니다. 그 태스크는 자기 도메인의 창을 기다려야 합니다. -커널이 idle 상태인 동안에도 타이머 틱은 계속 세고 처리합니다. idle 루프는 다음 두 줄 가운데 하나를 부팅당 최대 한 번씩 출력합니다. +커널이 기다리는 동안에도 타이머 틱은 계속 세고 처리합니다. 표를 정하지 않았으면 루프는 다음 두 줄 가운데 하나를 부팅당 최대 한 번씩 출력합니다. - `k0: idle (waiting for a timeout)`: 기한이 있는 대기자가 하나 이상 있습니다. - `k0: all tasks stopped (none ready, no timeout pending)`: 기한이 있는 대기자도 콘솔 입력을 기다리는 태스크도 없습니다. 지금은 Notification 오브젝트도, 콘솔 입력을 제외한 태스크용 장치 인터럽트도 없으므로 이 상태에서는 어떤 것도 태스크를 깨울 수 없고, 머신은 idle 상태로 남습니다. -기다릴 것이 콘솔 입력뿐이면(`console-input` 이미지) 커널은 아무것도 출력하지 않으며, 이것이 터미널 이미지의 정상 상태입니다. idle 루프는 인터럽트마다 도착한 입력을 확인해 읽는 쪽을 깨웁니다. +기다릴 것이 콘솔 입력뿐이면(`console-input` 이미지) 커널은 아무것도 출력하지 않으며, 이것이 터미널 이미지의 정상 상태입니다. + +루트 도메인이 아닌 도메인이 적힌 표가 정해져 있거나 보류 중인 동안에는 빈 창에서 기다리는 것이 정상이므로 첫째 줄은 출력하지 않습니다. 둘째 줄은 그때도 한 번 출력합니다. 어느 도메인에도 준비된 태스크가 없고, 어느 도메인에도 기한이 있는 대기자가 없고, 콘솔 입력을 기다리는 태스크도 없을 때입니다. 어떤 표에도 없는 도메인의 준비된 태스크는 끝내 실행되지 않지만, 이 검사에서는 준비된 것으로 셉니다. > [!WARNING] > 가용성은 여전히 보호되지 않습니다. 타임아웃 없이 기다리는 태스크는 상대방이 동작하지 않으면 영원히 기다릴 수 있고, 마지막으로 블록하는 격리 태스크는 여전히 시스템에 실행할 태스크가 없게 만들 수 있습니다([SECURITY_KR.md](../../SECURITY_KR.md)의 어드바이저리 GHSA-q99x-2wrv-358p, 릴리즈 시점에 갱신). 격리는 태스크 사이의 기밀성과 무결성을 지키는 것이지 가용성을 지키지 않습니다. @@ -202,16 +349,17 @@ EL0에서 받은 SError는 여전히 머신 전체를 정지시키며, `k0_arch: ## 테스트 방법 -스케줄러와 시스템 콜 경로는 시스템 레지스터를 읽으므로 부팅으로 테스트합니다. 하드웨어를 건드리지 않는 큐와 케이퍼빌리티 로직(`k0-cap`, `k0-mm`)은 호스트에서 테스트하며, [capabilities_KR.md](capabilities_KR.md)를 참고하세요. 루트 태스크 자가 테스트는 다음을 수행합니다. +시스템 콜 경로와 스케줄러의 커널 쪽(`k0-sched`, `k0-ipc`, `kernel/src/syscall.rs`)은 시스템 레지스터를 읽으므로 부팅으로 테스트합니다. 스케줄링 판정(`k0-part`)과 틱 규칙(`k0-slice`)은 하드웨어를 건드리지 않으므로 호스트에서 테스트합니다. `k0-cap`과 `k0-mm`의 큐와 케이퍼빌리티 로직도 마찬가지이며, [capabilities_KR.md](capabilities_KR.md)를 참고하세요. 루트 태스크 자가 테스트는 다음을 수행합니다. - 목표값까지 세고 종료하는 태스크를 만들고 기다림 - 구성되지 않은 태스크, 이미 재개한 태스크, 죽은 태스크의 재개를 거부 - 슬라이스 테스트(`userspace/root-task/src/timeslice.rs`) 실행: 양보하지 않는 태스크가 여전히 타이머에 선점되는지, 그리고 양보나 블록으로 CPU를 받은 태스크가 처음 맞는 틱에 끊기지 않는지 확인 +- 시간 분할 테스트(`userspace/root-task/src/partition.rs`) 실행([부팅 때의 시간 분할 테스트](#부팅-때의-시간-분할-테스트) 참고) - 스레드 포인터 레지스터가 태스크 사이에 새지 않는지 확인 - 자기 CNode와 자기 주소 공간을 가진 격리 태스크를 만들고, 루트 태스크의 슬롯 번호가 거기서 아무 의미가 없는지 확인 - 모든 상태(inactive, stopped, ready, send·receive·call에서 블록, 응답 대기, 응답 자격 보유, 엔드포인트 큐의 머리·중간·꼬리)의 태스크 삭제, 태스크가 줄 서 있는 엔드포인트 삭제, CNode 회수 또는 주소 공간 삭제로 태스크 종료, 태스크가 자기 TCB를 삭제하고 자신이 잘려 나온 untyped를 회수하는 경우 -`tools/qemu-boot-test.sh`는 마커 `root: child exit test pass`, `root: slice test yield pass`, `root: slice test block pass`, `root: preempt test pass`, `root: isolation tests pass`, `root: violation tests pass`, `root: teardown tests pass`, `root: revocation tests pass`, `root: sched tests pass`를 요구하고, 그 뒤에 타이머 틱이 적어도 하나 더 나와야 합니다. 마커에는 타임아웃 테스트가 출력하는 `k0: idle (waiting for a timeout)`와 `root: timeout tests pass`도 포함됩니다([ipc_KR.md](ipc_KR.md) 참고). 로그에 `k0: all tasks`로 시작하는 줄, `k0: FATAL`, `k0: PANIC`이 있으면 실패하므로 실행할 태스크도 대기 중인 타임아웃도 없는 상태에 이른 실행은 실패로 처리됩니다. 태스크 폴트 줄도 정확한 개수로 세므로([exceptions_KR.md](exceptions_KR.md) 참고), 정리된 뒤에도 계속 실행되는 태스크를 잡아냅니다. +`tools/qemu-boot-test.sh`는 마커 `root: child exit test pass`, `root: slice test yield pass`, `root: slice test block pass`, `root: preempt test pass`, `root: partition refusal pass`, `root: partition window pass`, `root: isolation tests pass`, `root: violation tests pass`, `root: teardown tests pass`, `root: revocation tests pass`, `root: partition sealed`, `root: sched tests pass`를 요구하고, 그 뒤에 타이머 틱이 적어도 하나 더 나와야 합니다. 마커에는 타임아웃 테스트가 출력하는 `k0: idle (waiting for a timeout)`와 `root: timeout tests pass`도 포함됩니다([ipc_KR.md](ipc_KR.md) 참고). 로그에 `k0: all tasks`로 시작하는 줄, `k0: FATAL`, `k0: PANIC`이 있으면 실패하므로 실행할 태스크도 대기 중인 타임아웃도 없는 상태에 이른 실행은 실패로 처리됩니다. 태스크 폴트 줄도 정확한 개수로 세므로([exceptions_KR.md](exceptions_KR.md) 참고), 정리된 뒤에도 계속 실행되는 태스크를 잡아냅니다. 슬라이스 테스트는 바쁜 자식과 카운터를 쓰던 예전 테스트를 대신합니다. EL0에는 시계가 없으므로 시간이 아니라 실행 순서로 판정합니다. 태스크 넷을 시작합니다. CPU를 넘기는 태스크(첫 실행에서는 `YIELD`로, 두 번째 실행에서는 블록으로), 그 뒤에 영원히 도는 태스크, 처음 실행될 때 표시를 남기는 태스크, 도우미입니다. 루트 태스크는 한 틱짜리 타임아웃 대기에 들어갑니다. 도는 태스크가 처음 맞는 틱에 끊기면 표시 태스크가 실행되어, 루트 태스크가 깨기 전에 도는 태스크가 표시를 봅니다. 끊기지 않으면 루트 태스크가 먼저 깹니다. 테스트는 `root: slice test yield pass`, `root: slice test block pass`, 그다음 `root: preempt test pass`를 출력하고, 실패하면 `root: FAIL slice: a task that got the cpu by a yield was cut at its first tick`(또는 `by a block`)을 출력합니다. 한 번 실행에 약 2틱이 들므로, 예전 테스트가 약 1초였던 자리에 두 번의 실행이 부팅 테스트마다 약 4초를 더합니다. @@ -222,21 +370,83 @@ EL0에서 받은 SError는 여전히 머신 전체를 정지시키며, `k0_arch: - CPU를 계속 쓰는 태스크의 몫은 주기의 모든 퍼센트에서 양보하는 태스크 하나를 상대로, 양보와 타임아웃 대기의 격자에서 협력하는 태스크 최대 셋을 상대로, 그리고 무작위 태스크 집합 3,000개를 상대로 유지됩니다. - 측정한 두 경우를 재현합니다(90 % 양보에서 10 %와 55 %, 태스크 셋일 때 예전 규칙에서 양보하는 태스크 뒤의 태스크가 5 %). -이는 한정된 모델(태스크 최대 6개)에서의 탐색이며 **증명이 아닙니다**. 규칙을 일부러 망가뜨린 아홉 가지는 각각 호스트 테스트를 적어도 하나 실패시킵니다. 커널 연결을 일부러 망가뜨리면 부팅 테스트는 예전 규칙, `YIELD`가 잘못된 진입 종류를 넘기는 경우, 블록이 잘못된 진입 종류를 넘기는 경우에서 실패합니다. 틱 자신의 전환이 `Between`을 넘기는 경우, idle 루프가 틱에 대해 잘못 보고하는 경우, `handoff`의 잘못된 진입 종류는 부팅 테스트가 잡지 못합니다. 이런 실수는 태스크의 몫이 아니라 끊기기 전까지 실행하는 시간을 바꾸며, 호스트 모델은 이 경우들에서 규칙을 다룰 뿐 커널이 규칙을 쓰는 방식은 다루지 않습니다. +이는 한정된 모델(태스크 최대 6개)에서의 탐색이며 **증명이 아닙니다**. 규칙을 일부러 망가뜨린 아홉 가지는 각각 호스트 테스트를 적어도 하나 실패시킵니다. 커널 연결을 일부러 망가뜨리면 부팅 테스트는 예전 규칙, `YIELD`가 잘못된 진입 종류를 넘기는 경우, 블록이 잘못된 진입 종류를 넘기는 경우에서 실패합니다. 틱 자신의 전환이 `Between`을 넘기는 경우, 대기 루프가 틱을 틱이 아닌 것으로 다루는 경우, `handoff`의 잘못된 진입 종류는 부팅 테스트가 잡지 못합니다. 이런 실수는 태스크의 몫이 아니라 끊기기 전까지 실행하는 시간을 바꿉니다. 시간 분할 변경 뒤로는 커널이 이런 실수를 할 수 없습니다. 커널은 사건의 이름만 알리고, 진입 종류는 `Core`가 고르기 때문입니다. 이 실수들은 이제 일어날 수 있는 곳인 `k0-part`의 호스트 테스트에서 다룹니다. -QEMU에서 변경 뒤에 측정하니, 주기의 90 %에서 양보하는 공격 태스크 곁에서 다른 태스크가 CPU의 53.8 %부터 54.9 %를 가졌습니다(세 번 실행). 태스크 셋일 때는 어느 태스크도 29.7 % 아래로 내려가지 않았습니다. 양보 대신 틱 직전에 타임아웃 대기를 시작하는 공격 태스크 곁에서는 다른 태스크가 56.5 %를 가졌습니다. 모든 실행은 QEMU(TCG와 HVF)에서 했고 하드웨어에서는 실행하지 않았으며, 양보 지점은 공격 태스크를 위해 정했으므로 공격 태스크가 스스로 그 지점을 찾는 데 무엇이 필요한지는 측정하지 않았습니다. +슬라이스 규칙을 넣은 상태로 QEMU에서 측정하니, 주기의 90 %에서 양보하는 공격 태스크 곁에서 다른 태스크가 CPU의 53.8 %부터 54.9 %를 가졌습니다(세 번 실행). 태스크 셋일 때는 어느 태스크도 29.7 % 아래로 내려가지 않았습니다. 양보 대신 틱 직전에 타임아웃 대기를 시작하는 공격 태스크 곁에서는 다른 태스크가 56.5 %를 가졌습니다. 모든 실행은 QEMU(TCG와 HVF)에서 했고 하드웨어에서는 실행하지 않았으며, 양보 지점은 공격 태스크를 위해 정했으므로 공격 태스크가 스스로 그 지점을 찾는 데 무엇이 필요한지는 측정하지 않았습니다. + +### 시간 분할 스케줄러의 호스트 테스트 + +크레이트 `k0-part`에는 호스트 테스트가 36개 있고, `tools/host-test.sh`가 실행합니다. + +- **커널 모델 위의 스케줄링 코어**(24개): 실제 `Core`를 이산 사건 모델 위에서 실행합니다. 모델에는 틱, 타임아웃 대기, 임의의 시각에 오는 입력, 종료, 공유 오브젝트, 표 변경, 건너뛴 틱이 있습니다. 비교 대상인 기준 구현은 `Core`와 따로 작성했습니다. 확인하는 성질은 다음과 같습니다. + - 도메인은 자기 창의 틱에서 실행되고 다른 틱에서는 실행되지 않으며, 남는 시간이 다른 도메인에 넘어가는 일이 없습니다. + - **두 실행의 동등성**: 한 도메인의 기록(그 도메인의 어느 태스크가 어느 틱에 실행됐고 무엇이 깨웠는지)은 다른 도메인의 태스크가 무엇을 하든 같습니다. 두 번째 테스트는 이 성질이 공허하지 않음을 보입니다. 도메인 사이에 공유한 오브젝트가 있으면 기록이 실제로 달라집니다. + - 기본 표에서 `Core`는 자신이 대체한 스케줄러의 동결된 사본과 같은 판정을 내립니다. + - 슬라이스 규칙의 몫 한계는 도메인 안에서, 그 도메인의 창을 이어 붙인 시간 위에서 성립하고, 틱 규칙은 창의 끝에서도 성립합니다. + - 표는 호출의 두 틱 뒤에 효력이 생기고, 보류 중인 표는 바꿀 수 있고, 건너뛴 틱은 맞는 항목에 떨어지고, 같은 도메인이 이어지는 항목은 경계를 만들지 않고, 루트 도메인만 적힌 표는 분할이 아닙니다. + - 보호 구간을 거는 근거인 `next_tick_switches`의 답은 모든 사건 뒤에 계획과 같습니다. + - 표 디코더는 형식이 맞는 레지스터 값을 받아들이고 그 밖의 값은 받아들이지 않습니다. + - 로직의 사본을 틀리게 고친 25가지가 각각 적어도 하나의 성질에 걸리고, 고치지 않은 사본이 실제 `Core`와 같은지도 확인합니다. +- **시계 산술**(9개): 따로 작성한 기준과 비교한 틱 번호, 설정한 시각의 직전과 바로 그 시각, 카운터 범위의 끝 근처 값, 주기 0, 그리고 틱 번호가 뒤로 가거나 되풀이되지 않는다는 것을 확인합니다. +- **Lean 모델의 기록된 결과**(3개): [증명한 것](#증명한-것)을 참고하세요. + +`k0-cap`에는 호스트 테스트가 54개 있습니다. 그 가운데 둘이 `PartCtl`에 관한 것입니다. 마스크와 배지가 무엇이든 복사본을 만들 수 없다는 것, 그리고 다른 값이 함께 든 `PartCtl` 워드는 디코드되지 않는다는 것입니다. + +`k0-sched`, `k0-ipc`, 커널 바이너리에는 호스트 테스트가 없습니다. 이들이 `Core`에 더하는 것(큐, 기한 목록, 타이머 호출)은 부팅 테스트와 리뷰로 확인합니다. + +### 부팅 때의 시간 분할 테스트 + +루트 태스크는 부팅할 때마다 세 가지 검사를 실행합니다. + +- **거부**(`root: partition refusal pass`): 비어 있거나, 범위 밖이거나, 다른 종류의 케이퍼빌리티가 든 슬롯을 통한 두 호출, 형식이 틀린 표, 호출자의 도메인이 없는 표, 범위 밖의 도메인, `Stopped`가 아닌 TCB(구성 전, 실행 중, 준비, 블록, 종료)에 대한 `PART_SET_DOMAIN`, 그리고 제어 케이퍼빌리티의 복사를 시도합니다. 각각 정해진 에러를 돌려줘야 하고, 그 뒤에도 시스템은 기본 표로 계속 돌아야 합니다. +- **창**(`root: partition window pass`): 항목 8개에 9틱짜리 표를 한 바퀴 돌립니다. 도메인 0, 1, 2에 태스크가 있고, 도메인 3은 표에 있지만 태스크가 없으며, 어떤 표에도 없는 도메인 4에 태스크가 하나 있습니다. EL0에는 시계가 없으므로 테스트는 **사건의 순서만으로 판정합니다**. 모든 태스크가 한 로그에 글자를 덧붙이고, 루트 태스크 자신의 타임아웃 대기가 유일한 시계이며, 끝났을 때 로그는 `XkwRhabryvx`여야 합니다. 이 순서는 무엇보다 다음을 보여 줍니다. + - 자식은 자신을 만든 쪽의 도메인을 물려받습니다. + - 창에서 남는 시간은 다른 도메인에 넘어가지 않습니다. + - 창의 끝에서 끊긴 태스크는 다음 창에서 자기 큐의 맨 앞에서 이어집니다. + - 다른 도메인의 창에서 지난 도메인 1의 두 기한은 도메인 1에 들어갈 때에야 처리되고, 나중에 기한을 건 대기자가 먼저 깨어납니다. + - 어떤 표에도 없는 도메인의 태스크는 한 번도 실행되지 않습니다. + + 서로에게 양보만 하는 도메인 1의 두 태스크는 상대가 실행되지 않은 채 돌아온 양보를 모두 세며, 그 수는 0이어야 합니다. 테스트는 이 방법으로 창이 닫힌 뒤에도 계속 실행된 태스크를 봅니다. +- **봉인**(`root: partition sealed`): 루트 태스크가 제어 케이퍼빌리티를 삭제하고, 그 뒤 두 호출은 `BAD_SLOT`을 돌려줘야 합니다. 이 검사는 자가 테스트의 끝에서, 콘솔 입력 테스트보다 먼저, 그리고 터미널 이미지가 서비스를 시작하기 전에 실행됩니다. + +호스트가 가상 머신을 한 틱보다 오래 멈춰 세우면 틱 하나를 건너뛰고, 창 테스트의 로그가 달라집니다. 틀린 실행은 자기 로그를 `root: partition window log `로 출력합니다. 그다음 테스트는 정리하고 `root: partition window retry`를 출력한 뒤 한 번 더 실행합니다. 두 실행이 모두 틀렸을 때만 `root: FAIL partition: window order wrong twice`로 실패합니다. `tools/qemu-boot-test.sh`는 재시도 횟수를 출력하고(`boot-test: partition window retries: N`) 그 수로 판정하지는 않습니다. `tools/boot-matrix.sh`는 그 수로 판정합니다. 창 테스트가 재시도한 부팅 행을 다시 실행하고, 두 번째 실행도 재시도했으면 그 행을 실패로 처리합니다. 멈춤은 좀처럼 되풀이되지 않지만, 부팅 뒤 첫 표에서만 드러나는 결함은 언제나 되풀이되기 때문입니다. 터미널 행은 이런 식으로 다시 실행하지 않습니다. + +시간 분할 테스트는 부팅마다 약 15초를 더합니다. + +### 증명한 것 + +`proofs/lean`에는 스케줄러의 추상 모델에 대한 Lean 4 증명이 증명 파일 다섯 개로 들어 있습니다. [proofs/lean/README.md](../../proofs/lean/README.md)(영문)가 각 정리가 무엇을 어떤 가정 아래 진술하는지, 모델이 무엇을 빼놓았는지 설명합니다. + +> [!IMPORTANT] +> 이것은 모델에 대한 증명이지 Rust 코드에 대한 증명이 아닙니다. CI에서 실행하지 않으며, 인증이나 규정 준수를 주장하는 것도 아닙니다. + +모델 안에서, 각 정리의 가정 아래 다음이 성립합니다. + +- 도는 도메인은 틱 번호와 `PART_SET_TABLE` 호출의 함수입니다. 큐, 대기, 태스크의 행동은 여기에 들어가지 않습니다. +- 어느 도메인 D에 대해서든, 틱 번호와 표 호출과 D의 태스크가 하는 일이 같고 D 밖의 어떤 태스크도 D의 태스크를 깨우지 않는 두 실행은 매 단계 뒤에 D에게 같은 모습을 줍니다. D의 큐, D의 대기 목록, D의 어느 태스크가 실행되는지가 같습니다. +- 창을 다른 도메인이 사용하는 일이 없고, 타임아웃 대기는 자기 도메인이 돌 때에만 처리되며 기한보다 일찍 처리되지 않고, 태스크가 사라지거나 중복되는 일이 없습니다. +- n번 틱 뒤에 정한 표는 n + 2번 틱부터의 틱을 정합니다. n + 1번 틱은 계획대로 두며, 바로 그 틱에서 시작할 예정이던 표를 바꾸는 경우만 예외입니다. 커널이 `PART_SET_TABLE`마다 보호 구간을 다시 결정하는 까닭이 이것입니다. +- 도메인 하나 안에서, 많아야 N개의 태스크 가운데 CPU를 내놓지 않는 태스크는 덧셈 상수 하나만큼의 오차 안에서 자기 몫을 유지합니다. 도메인이 여럿인 표에 대해서는 그런 정리가 없습니다. + +모델과 코드를 잇는 것은 증명이 아니라 테스트입니다. `crates/k0-part/src/model_tests.rs`의 호스트 테스트 `core_gives_the_lines_of_the_lean_model_on_every_recorded_script`는 기록해 둔 사건 스크립트 1600개(`model_vectors.txt`)를 실제 `Core`에 넣어 실행하고, 사건마다 그 뒤의 상태를 모델이 낸 상태와 비교합니다. 비교에는 Lean 쪽이 계산한 해시를 사용합니다. 이 테스트는 CI에서 실행됩니다. 모델에는 틱 안의 시간이 없으므로 보호 구간, 틱 시각까지의 대기, 캐시, 커널 경로의 길이에 대해서는 아무것도 말하지 않습니다. ## 알려진 공백 > [!NOTE] -> 우선순위와 CPU 예산은 아직 없습니다. 코어는 하나뿐입니다. - -- **스케줄링**: 틱 1초와 슬라이스 규칙을 쓰는 라운드 로빈입니다. 우선순위도 CPU 예산도 없으므로 CPU를 계속 쓰는 태스크는 자기 차례를 전부 쓰며 이를 막는 것이 없습니다. untyped 메모리를 가진 태스크는 여전히 태스크를 많이 만들어 모두의 몫을 희석시킬 수 있습니다. -- **타이밍 채널**: 열려 있습니다. 태스크는 양보하거나 블록할 시점을 골라 다른 태스크가 언제, 그리고 이제는 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. 분석하지 않았습니다. 막으려면 고정된 시간 분할이 필요한데 K0에는 없습니다. -- **지연**: 실시간이나 지연에 대한 약속은 없습니다. 틱은 1초이고 커널은 선점되지 않습니다. -- **슬라이스 규칙 검증**: 호스트 모델은 규칙을 다룰 뿐 커널이 규칙을 쓰는 방식은 다루지 않으며([테스트 방법](#테스트-방법) 참고), 측정은 양보 지점을 공격 태스크를 위해 정한 QEMU에서만 했습니다. +> 우선순위와 CPU 예산은 아직 없습니다. 코어는 하나뿐입니다. 도메인을 둘 이상 사용하는 이미지는 아직 없습니다. 루트 태스크가 자가 테스트의 끝에서 표를 봉인하기 때문입니다. + +- **스케줄링**: 도메인 안에서는 틱 1초와 슬라이스 규칙을 쓰는 라운드 로빈이고, 도메인 사이에서는 고정된 창입니다. 도메인 안에는 우선순위도 CPU 예산도 없으므로 CPU를 계속 쓰는 태스크는 자기 차례를 전부 쓰며 이를 막는 것이 없습니다. untyped 메모리를 가진 태스크는 여전히 태스크를 많이 만들어 자기 도메인에 있는 모두의 몫을 희석시킬 수 있습니다. 예산이라고 할 것은 창뿐이며, 창은 도메인 단위입니다. +- **타이밍 채널**: 고정 시간 분할은 도메인 사이에서 스케줄러를 거치는 채널을 닫으며, 그 한계는 [시간 분할이 주장하는 것과 주장하지 않는 것](#시간-분할이-주장하는-것과-주장하지-않는-것)에 나열했습니다. 그 밖의 타이밍 채널은 모두 열려 있고 분석하지 않았습니다. 도메인 안에서는 태스크가 양보하거나 블록할 시점을 골라 다른 태스크가 언제, 얼마나 오래 실행되는지를 여전히 바꿀 수 있습니다. 캐시와 분기 예측기는 도메인 사이에서 비우지 않습니다. +- **타이밍 쪽에는 테스트가 없습니다**: 보호 구간, 틱 시각까지의 대기, 도메인이 바뀔 때의 TLB 비우기는 EL0에 시계가 없어서 어떤 테스트도 보지 못합니다. 콘솔 입력을 읽는 쪽의 창에서만 전달한다는 규칙에도 테스트가 없습니다. +- **증명**: 모델에 대한 것이지 Rust 코드에 대한 것이 아니고, CI에서 실행하지 않으며, 도메인이 여럿인 표에 대한 몫 한계는 없습니다. +- **보호 구간의 길이는 고정입니다**: 25 ms보다 길고 보호 구간이 시작될 때 진행 중이던 커널 경로는 다음 창을 늦춥니다. 커널 경로의 길이에 대한 상한이 이 숫자를 뒷받침하고 있지 않으며, 측정은 한 기계의 QEMU에서 한 번 실행한 것뿐입니다. +- **건너뛴 틱**: 한 틱보다 긴 멈춤은 창을 건너뛰고, 잃은 창을 도메인에 돌려주는 것은 없습니다. +- **표의 한도**: 도메인 8개, 항목 16개, 창은 초 단위로 255까지입니다. 표는 다시 읽어 올 수 없고, 제어 케이퍼빌리티를 삭제하면 다음 부팅까지 어떤 것도 표를 바꿀 수 없습니다. +- **지연**: 실시간이나 지연에 대한 약속은 없습니다. 틱은 1초이고 커널은 선점되지 않습니다. 표가 있으면 태스크는 자기 도메인의 창도 기다리며, 타임아웃은 그 창이 시작할 때까지 늦어질 수 있습니다. +- **슬라이스 규칙 검증**: 측정은 양보 지점을 공격 태스크를 위해 정한 QEMU에서만 했습니다([테스트 방법](#테스트-방법) 참고). - **타임아웃**: 태스크가 준비되는 시점을 정할 뿐 실행되는 시점을 정하지 않습니다. 호출마다 선택하는 것이므로 타임아웃 없이 기다리는 태스크는 영원히 기다릴 수 있습니다. - **idle 상태**: 있지만, 루트 태스크가 자가 테스트 뒤에 `YIELD`를 계속 호출하는 동안에는 CPU가 잠들지 않습니다. 준비된 태스크도 기한이 있는 대기자도 없으면 머신은 idle 상태로 남고 어떤 것도 태스크를 깨울 수 없습니다. +- **실제 하드웨어**: 여기 적은 어떤 것도 실제 보드에서 실행하지 않았습니다. 모든 실행은 QEMU의 TCG와 HVF에서 했습니다. - **가용성**: 타임아웃 없이 블록하는 태스크는 격리 태스크를 포함해 상대방이 동작하지 않으면 계속 블록된 채로 남을 수 있습니다(GHSA-q99x-2wrv-358p). 커널은 선점되지 않으므로 객체가 많은 untyped에 대한 `CAP_REVOKE` 같은 긴 시스템 콜은 다른 모든 태스크와 모든 타임아웃을 지연시킵니다. 태스크 격리는 가용성을 다루지 않습니다. - **블록된 태스크**: IPC 상대가 동작하거나, 기한이 지나거나, 엔드포인트가 삭제되면 깨어납니다. - **죽은 TCB**: 정리가 회수하지 않습니다. 프레임은 케이퍼빌리티를 삭제하거나 untyped를 회수한 뒤 다시 retype할 때만 재사용됩니다. diff --git a/design/kr/terminal_KR.md b/design/kr/terminal_KR.md index a8bd829..d40a7a3 100644 --- a/design/kr/terminal_KR.md +++ b/design/kr/terminal_KR.md @@ -71,7 +71,7 @@ QEMU는 시리얼 포트를 사용자의 터미널에 연결합니다. `cargo ru 플래그는 `NONBLOCK`(1), `FLUSH`(2)이고, 63비트부터 32비트까지는 틱 단위 타임아웃입니다. 다른 비트는 `BAD_FLAGS`로 거부됩니다. `NO_DEVICE`(-24)는 입력 경로가 없거나 꺼졌다는 뜻입니다. -`Console` 케이퍼빌리티에는 이제 권한이 있습니다. **R**은 입력 읽기, **W**는 출력 쓰기입니다. `CAP_COPY`는 권한을 제거하기만 할 수 있습니다. 루트 태스크의 케이퍼빌리티는 W를 가지며, R은 `console-input`이 있는 이미지에서만 가집니다. `DEBUG_PUTC`는 W가 필요합니다. `bootinfo::VERSION`은 4입니다. +`Console` 케이퍼빌리티에는 이제 권한이 있습니다. **R**은 입력 읽기, **W**는 출력 쓰기입니다. `CAP_COPY`는 권한을 제거하기만 할 수 있습니다. 루트 태스크의 케이퍼빌리티는 W를 가지며, R은 `console-input`이 있는 이미지에서만 가집니다. `DEBUG_PUTC`는 W가 필요합니다. 이 권한은 `bootinfo::VERSION` 4에서 생겼습니다. 지금 버전은 5이며, 슬롯 5에 시간 분할의 제어 케이퍼빌리티가 들어갔기 때문입니다. 출력 필터는 한 가지를 빼고 그대로입니다. R이 있는 `Console` 케이퍼빌리티(터미널의 것)는 백스페이스(0x08)도 내보낼 수 있습니다. 다른 제어 바이트는 여전히 `?`로 출력됩니다. @@ -79,7 +79,8 @@ QEMU는 시리얼 포트를 사용자의 터미널에 연결합니다. `cargo ru 입력을 기다릴 수 있는 태스크는 한 번에 하나입니다. 두 번째로 읽으려는 태스크는 `BUSY`(-23)를 받습니다. 링이 비어 있고 `NONBLOCK`을 요구하지 않은 읽기는 잠들며, 플래그에 타임아웃이 있으면 그 시간만큼만 잡니다. -- **바이트로 깨우기**: 바이트를 받으면 대기자를 깨웁니다. 대기자는 준비 큐의 맨 뒤로 갑니다. 입력 때문에 선점하지는 않습니다. +- **바이트로 깨우기**: 바이트를 받으면 대기자를 깨웁니다. 대기자는 자기 도메인의 준비 큐 맨 뒤로 갑니다. 입력 때문에 선점하지는 않습니다. +- **읽는 쪽의 창에서만**: 시간 분할 표가 있을 때 바이트는 읽는 쪽의 도메인이 도는 동안에만 전달됩니다. 그렇지 않으면 그 도메인이 도는 다음 틱까지 링에서 기다립니다([scheduling_KR.md](scheduling_KR.md#표가-있을-때의-콘솔-입력) 참고). 터미널 이미지는 도메인 하나로 실행되므로 지금은 터미널 이미지에 해당하지 않습니다. - **케이퍼빌리티 변경으로 깨우기**: 케이퍼빌리티가 삭제, 회수 또는 이동된 대기자는 즉시 `REVOKED`로 깨어납니다. - **타임아웃으로 깨우기**: 플래그에 타임아웃을 준 읽기는 그 시간이 다 되면 깨어납니다(타임아웃은 [scheduling_KR.md](scheduling_KR.md) 참고). - **조용한 유휴**: 기다릴 것이 콘솔 입력뿐이면 커널은 아무것도 출력하지 않습니다. 이것이 터미널 이미지의 정상 상태입니다. `k0: all tasks stopped (none ready, no timeout pending)`는 시간 제한이 있는 대기자도, 콘솔 대기자도 없을 때만 출력됩니다. @@ -137,7 +138,7 @@ QEMU는 시리얼 포트를 사용자의 터미널에 연결합니다. `cargo ru ## 테스트 방법 -**호스트 테스트**(`tools/host-test.sh`): `k0-conin`은 가짜 UART로 19개, `k0-term`은 vault feature가 있으면 24개, 없으면 21개, `k0-vault`는 Ed25519가 있으면 20개, 없으면 11개입니다. 전체는 ARM 호스트에서 377개, 다른 호스트에서 289개입니다(`k0-slice`가 9개를 더합니다). +**호스트 테스트**(`tools/host-test.sh`): `k0-conin`은 가짜 UART로 19개, `k0-term`은 vault feature가 있으면 24개, 없으면 21개, `k0-vault`는 Ed25519가 있으면 20개, 없으면 11개입니다. 전체는 ARM 호스트에서 415개, 다른 호스트에서 327개입니다. **부팅 매트릭스**: 새 행은 `input-only`, `input-gicv2`, `input-16550`, `input-bad-irq`, 정적 행 `input-symbols`(`console-input`이 없는 이미지에는 수신 코드도 새 로그 줄도 없음), `term`, `term-max`, `term-el2`, `term-gicv2`, `term-16k`, `term-no-vault`, `term-no-alg`, `term-uefi`, `term-uefi-acpi`, `hvf-term`입니다. 매트릭스는 HVF가 있는 Mac에서 82행, CI에서 71행입니다. @@ -154,6 +155,7 @@ QEMU는 시리얼 포트를 사용자의 터미널에 연결합니다. `cargo ru - **외부가 구동하는 커널 코드**: 수신 코드는 EL1에서 실행됩니다. - **분석하지 않은 타이밍 채널**: 외부 당사자가 이제 태스크가 실행되는 동안 인터럽트를 일으킬 수 있습니다(바이트는 읽는 쪽이 정한 한계 안에서, 선로 오류가 난 문자는 틱당 256개 안에서). 읽는 쪽은 틱보다 세밀한 도착 시각을 알게 되고, 다른 태스크는 빼앗긴 시간을 알아챌 수 있습니다. - **지연**: 입력은 실행 중인 태스크 뒤에서 기다립니다. 우선순위가 없으므로 준비된 태스크마다 최대 한 틱씩 지연되며, 실행 중인 태스크가 두 틱 사이에 CPU를 받았다면 한 틱이 더해집니다([scheduling_KR.md](scheduling_KR.md) 참고). +- **도메인 하나**: 루트 태스크는 자가 테스트의 끝에서, 서비스를 시작하기 전에 시간 분할의 제어 케이퍼빌리티를 삭제합니다. 그래서 터미널, 볼트, 루트 태스크는 모두 루트 도메인에서 실행되고, 시간 분할은 아직 볼트를 터미널과 갈라놓지 않습니다. 입력을 읽는 쪽의 창에서만 전달한다는 규칙에는 테스트가 없습니다. - **16550 콘솔에는 입력 없음**: 16550 콘솔에는 출력만 있고 입력은 없습니다. - **폭주 중 측정 없음**: 어떤 테스트도 머신에서 폭주 중 커널 시간을 측정하지 않습니다. 한계는 게이트로 논증하고 호스트 테스트로 보였습니다. - **프롬프트 전에 버림**: UART에 도착한 바이트를 센 것입니다. 바이트를 붙잡고 있는 에뮬레이터나 어댑터는 나중에 전달합니다(QEMU가 그렇습니다). diff --git a/design/kr/uefi_KR.md b/design/kr/uefi_KR.md index 19d875c..e527ad8 100644 --- a/design/kr/uefi_KR.md +++ b/design/kr/uefi_KR.md @@ -183,7 +183,7 @@ $ K0_LOADER_FEATURES=refuse-halt tools/build-loader.sh - **호스트 단위 테스트**: `crates/k0-efi/src/tests.rs`에 32개가 있습니다. 벡터는 실제로 측정한 펌웨어 메모리 맵입니다. 디스크립터 규칙, 겹침, 항목 한계, 작성기와 재작성, 검증기, ACPI 리더, 트리 합성을 다룹니다. 네 번째 퍼저 `fuzz_acpi_with_mutated_tables`는 테이블 이미지를 변형합니다. 2026-11-12에 200만에서 300만 케이스의 캠페인이 통과했고, 앞서 실제 불일치 하나를 찾았습니다(리더가 커널의 디스커버리가 거부하는 GIC 프레임 정렬을 받아들였습니다). 커널의 배치 규칙을 리더에 적용해 수정했습니다. - **결정적 퍼저 셋**: `k0-efi`의 `fuzz_plan_with_random_maps`, `fuzz_rewrite_with_mutated_trees`, `fuzz_prepare_end_to_end`입니다. 다른 퍼저와 같은 변수 `K0_FUZZ_ITERS`, `K0_FUZZ_SEED`, `K0_FUZZ_CASE`를 사용합니다. 기본값은 각각 20,000, 20,000, 5,000개의 케이스입니다. 주간 워크플로가 셋 모두를 500만 케이스로 실행합니다. 2026-11-12에 각각 500만 케이스의 캠페인이 통과했습니다. 계획 퍼저는 앞서 실제 버그 하나를 찾았습니다(물리 주소 0의 블록이 받아들여졌습니다). 수정되었습니다. -- **호스트 테스트 스크립트**: `tools/host-test.sh`는 이제 ARM 호스트에서 377개(`k0-abi` 15, `k0-cap` 52, `k0-boot` 85, `k0-efi` 33, `k0-conin` 19, `k0-slice` 9, Ed25519 포함 20개와 제외 11개의 `k0-vault`, 볼트 feature 포함 24개와 제외 21개의 `k0-term`, 두 그래뉼 각각에 `k0-mm` 44)를, `k0-mm` 테스트를 건너뛰는 그 밖의 호스트에서 289개를 실행합니다. +- **호스트 테스트 스크립트**: `tools/host-test.sh`는 이제 ARM 호스트에서 415개(`k0-abi` 15, `k0-cap` 54, `k0-boot` 85, `k0-efi` 33, `k0-conin` 19, `k0-slice` 9, `k0-part` 36, Ed25519 포함 20개와 제외 11개의 `k0-vault`, 볼트 feature 포함 24개와 제외 21개의 `k0-term`, 두 그래뉼 각각에 `k0-mm` 44)를, `k0-mm` 테스트를 건너뛰는 그 밖의 호스트에서 327개를 실행합니다. - **PE 검사**: `tools/pe-check.py .efi`는 PE 형태(섹션 4개, 쓰기와 실행이 함께 가능한 섹션 없음)와 캐시 및 MMU 명령의 순서를 검사하고 `pe-check: ok (...)`를 출력합니다. - **EDK2 부팅 테스트**: `tools/qemu-virt-runner.sh`는 `.efi` 인자를 EDK2 펌웨어로 부팅합니다. 기본 머신은 `virt,gic-version=3,acpi=off`이므로 디바이스 트리 경로입니다. ACPI 행은 `K0_QEMU_MACHINE=virt,gic-version=3` 또는 `virt,gic-version=2`를 넘깁니다. `tools/qemu-boot-test.sh`는 로더의 첫 줄 `k0-loader: start`부터 실패를 판정하므로 펌웨어 메시지는 세지 않습니다. `tools/build-loader.sh <커널 ELF>`는 이미 빌드된 커널을 내장하고 `.efi`의 경로(`<커널 ELF>.efi`)를 출력합니다. 그래서 UEFI 행도 다른 행과 같은 커널 바이너리를 부팅합니다. 명령은 [USAGE_KR.md](../../USAGE_KR.md)에 있습니다. diff --git a/design/kr/user-address-space_KR.md b/design/kr/user-address-space_KR.md index f0bfa2e..c04592c 100644 --- a/design/kr/user-address-space_KR.md +++ b/design/kr/user-address-space_KR.md @@ -144,7 +144,7 @@ ### TLB 정책 -K0는 하드웨어 ASID를 사용하지 않습니다. `TTBR0`를 바꿀 때, 그리고 모든 매핑 해제, 테이블 분리, 주소 공간 파괴마다 TLB 전체를 무효화합니다(`flush_user_tlb`). 그래서 TLB에는 설치된 주소 공간의 변환만 남습니다. `MAP`은 무효 엔트리를 유효하게 만들 뿐이라 무효화가 필요 없습니다. +K0는 하드웨어 ASID를 사용하지 않습니다. `TTBR0`를 바꿀 때, 그리고 모든 매핑 해제, 테이블 분리, 주소 공간 파괴마다 TLB 전체를 무효화합니다(`flush_user_tlb`). 그래서 TLB에는 설치된 주소 공간의 변환만 남습니다. `MAP`은 무효 엔트리를 유효하게 만들 뿐이라 무효화가 필요 없습니다. 스케줄러도 시간 분할 도메인이 바뀔 때마다 주소 공간이 그대로여도 `flush_user_tlb`를 호출합니다. 다음 도메인이 이전 도메인을 위해 캐시된 변환을 가진 채 시작하지 않게 하려는 것입니다([scheduling_KR.md](scheduling_KR.md#창) 참고). ### 주소 공간 파괴 diff --git a/design/kr/vault_KR.md b/design/kr/vault_KR.md index 8f3f1dc..315c831 100644 --- a/design/kr/vault_KR.md +++ b/design/kr/vault_KR.md @@ -110,7 +110,7 @@ operator는 서명을 받을 수도 시드를 넘길 수도 없습니다. 배지 커널은 루트 태스크용 32바이트를 자체 도메인 문자열로 SHA-256에 넣어 만듭니다. 입력은 DTB 엔트로피, 카운터, 그리고 CPU에 RNDR이 있으면 새 RNDR 워드 네 개입니다(`k0_boot::derive_root_seed`). 도메인 분리로 PAC 키와는 서로 독립입니다. 시드는 입력만큼만 좋습니다. -시드는 루트 태스크의 진입 레지스터 `x0`부터 `x3`로 전달됩니다. `x4`는 사용한 `rng-seed` 바이트 수(비트 15부터 0)이고, 비트 16은 RNDR이 기여했음을 뜻합니다. bootinfo 페이지에는 없으며 `bootinfo::VERSION`은 4입니다. 루트 태스크는 `root: boot seed from rng-seed bytes 0x... and rndr` 또는 `... without rndr`만 출력하고 시드는 출력하지 않습니다. 이후 `INIT`으로 시드를 볼트에 주며, `INIT`은 시드를 전달할 뿐입니다. 키는 나중에 `KEYGEN`이 만듭니다. +시드는 루트 태스크의 진입 레지스터 `x0`부터 `x3`로 전달됩니다. `x4`는 사용한 `rng-seed` 바이트 수(비트 15부터 0)이고, 비트 16은 RNDR이 기여했음을 뜻합니다. bootinfo 페이지에는 없습니다(`bootinfo::VERSION`은 지금 5입니다). 루트 태스크는 `root: boot seed from rng-seed bytes 0x... and rndr` 또는 `... without rndr`만 출력하고 시드는 출력하지 않습니다. 이후 `INIT`으로 시드를 볼트에 주며, `INIT`은 시드를 전달할 뿐입니다. 키는 나중에 `KEYGEN`이 만듭니다. **시드 지우기**: FDT 파서는 `rng-seed`와 `kaslr-seed` 값의 위치를 기록하고, 두 번째 `/chosen` 노드는 거부합니다(`DuplicateChosen`, 파서를 공유하는 UEFI 로더의 사전 검사에서도 같습니다). 커널은 루트 태스크에 진입하기 직전에 그 바이트를 0으로 만듭니다. `k0_mm::wipe_ro_alias`가 페이지의 읽기 전용 별칭 항목을 제자리에서 읽기·쓰기로 바꾸고(break-before-make), 0을 쓰고, 캐시 라인을 clean 및 invalidate한 뒤 되돌립니다. 이어서 커널은 그 바이트를 다시 읽어 확인하고, `BootInfo`에 있는 자신의 사본을 지우고, `k0: dtb seeds wiped B`(QEMU virt에서는 40B)를 출력하고, 살아 있는 프레임 아래의 부트 스택을 0으로 만듭니다. 이것이 커널이 DTB 매핑으로 하는 유일한 쓰기이며, DTB를 파싱하고 검증한 뒤에 일어납니다. @@ -147,7 +147,7 @@ $ cargo build -p k0-kernel --features console,terminal,vault-ed25519 $ cargo build -p k0-kernel --features console,vault-ed25519 ``` -`crates/k0-boot/build.rs`가 feature를 루트 태스크의 중첩 빌드로 전달합니다. 볼트의 코드는 루트 태스크 이미지의 일부이며 이전처럼 부팅 시 SHA-256으로 검사됩니다. 부팅 뒤에는 아무것도 적재하지 않습니다. Ed25519를 넣으면 이미지는 4 KiB 프레임 24개입니다(한도 78개). +`crates/k0-boot/build.rs`가 feature를 루트 태스크의 중첩 빌드로 전달합니다. 볼트의 코드는 루트 태스크 이미지의 일부이며 이전처럼 부팅 시 SHA-256으로 검사됩니다. 부팅 뒤에는 아무것도 적재하지 않습니다. Ed25519를 넣으면 이미지는 4 KiB 프레임 28개입니다(한도 77개). ## 테스트 방법 @@ -156,7 +156,7 @@ $ cargo build -p k0-kernel --features console,vault-ed25519 - 항상: `badges_map_to_fixed_roles_and_frames`, `each_role_may_do_exactly_its_operations`, `no_frame_is_touched_for_a_request_that_cannot_have_a_body`, `a_request_that_claims_a_body_it_cannot_have_is_refused`, `the_status_word_packs_state_algorithm_and_what_is_built`, `a_call_without_a_known_badge_is_denied`, `malformed_requests_are_refused_whole`, `a_seed_without_real_entropy_makes_no_key`, `the_seed_is_taken_once_and_zeroize_is_final`, `fetch_clamps_the_length_and_publish_writes_header_and_body`, 그리고 `without_an_algorithm_the_vault_takes_no_seed_and_serves_nothing`(마지막 것은 알고리즘이 없을 때만). - Ed25519가 있을 때: `the_self_test_passes_and_is_reported`, `key_generation_follows_the_states`, `the_operator_gets_the_public_key_and_never_a_signature`, `a_vault_that_fails_holds_no_secret`, `signatures_verify_and_the_key_follows_the_seed`, `a_public_key_request_carries_no_body`, `unknown_algorithms_are_unsupported`, `nothing_is_served_after_zeroize`, `a_small_order_public_key_is_refused_even_with_a_matching_signature`, `a_failed_vault_refuses_everything_but_status`. -다른 크레이트와 합치면 호스트 테스트는 ARM 호스트에서 377개, 그 외 호스트에서 289개입니다(`k0-mm` 제외). 이 가운데 9개는 `k0-slice`의 테스트입니다. +다른 크레이트와 합치면 호스트 테스트는 ARM 호스트에서 415개, 그 외 호스트에서 327개입니다(`k0-mm` 제외). **루트 태스크 자가 테스트**(`userspace/root-task/src/oracle.rs`의 `test_oracle`, `vault`로 빌드한 이미지에만 있음). 다음을 검사합니다. @@ -185,6 +185,7 @@ $ cargo build -p k0-kernel --features console,vault-ed25519 - **터미널과 볼트는 죽어도 다시 시작하지 않습니다**: 죽으면 그대로 멈춥니다. 루트 태스크는 신뢰 대상입니다. - **가용성은 보호되지 않습니다**: 클라이언트는 엔드포인트 하나를 공유하며 모든 호출에 타임아웃을 써야 합니다([ipc_KR.md](ipc_KR.md) 참고). CPU를 계속 쓰는 태스크 하나 뒤에서는 호출자와 볼트가 왕복 한 번에 스케줄러 모델에서 4틱을 쓰며, 이전에는 2틱이었습니다. 터미널의 호출은 5틱 타임아웃을 쓰고, 고정 이미지의 서비스 모드에는 CPU를 계속 쓰는 태스크가 없습니다. - **루트 태스크는 신뢰 대상입니다**: 볼트를 만들고 읽을 수 있습니다. +- **자기만의 도메인이 없습니다**: 볼트는 아직 자기만의 시간 분할 도메인에 있지 않습니다. 루트 태스크가 자가 테스트의 끝에서 시간 분할의 제어 케이퍼빌리티를 삭제하므로, 볼트와 그 클라이언트와 터미널은 모두 루트 도메인에서 실행됩니다. 이들이 스케줄러를 통해 서로에 대해 알게 되는 것에는 제한이 없습니다([scheduling_KR.md](scheduling_KR.md#시간-분할) 참고). - **클라이언트 신원 없음**: 모든 signer가 키 하나를 공유합니다. - **엔트로피**: 시드는 입력만큼만 좋습니다. 키는 승인된 난수 비트 생성기에서 나오지 않습니다. - **최선 노력의 지우기**: 부팅 시드 경로 절의 참고를 보십시오. diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 903a98e..5ee3b28 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -38,7 +38,7 @@ console = ["console-pl011", "console-16550"] # terminal 루트 태스크 이미지에 운영자 터미널을 넣음(자가 검증 뒤에 # 서비스로 시작). console-input을 함께 켬 console-input = ["k0-arch/console-input", "k0-ipc/console-input", "k0-task/console-input", "k0-boot/console-input"] -terminal = ["console-input", "k0-boot/terminal", "k0-cap/root-cnode-1024"] +terminal = ["console-input", "k0-boot/terminal"] # 루트 태스크 이미지에 키 볼트(서명 오라클)를 넣음. 알고리즘은 따로 더함 # vault 볼트 서비스와 그 자가 검증(서명 알고리즘 없음) # vault-ed25519 위에 Ed25519를 더함 diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 63b455a..ebfe8b6 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -766,6 +766,7 @@ fn write_bootinfo(frame_pa: u64, cnode: &k0_cap::CNodeRef, count: u64, image: &I ..plain(cap_kind::CONSOLE) }, Some(Cap::CNode { .. }) => plain(cap_kind::CNODE), + Some(Cap::PartCtl) => plain(cap_kind::PART_CTL), Some(Cap::PageTable { .. }) => plain(cap_kind::PAGE_TABLE), Some(Cap::Endpoint { .. }) => plain(cap_kind::ENDPOINT), Some(Cap::Untyped { base, size, .. }) => CapDesc { diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index ee620d3..7b301fc 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -2,7 +2,7 @@ //! //! # Features //! k0-arch의 EL0 벡터가 링크 계약으로 부르는 `k0_syscall` / `k0_fault` / -//! `k0_preempt`를 정의합니다. 격리의 핵심 규칙은 두 가지입니다. +//! `k0_preempt` / `k0_leave`를 정의합니다. 격리의 핵심 규칙은 두 가지입니다. //! //! - 모든 슬롯 번호는 호출한 태스크 자신의 CNode(현재 TCB의 내장 슬롯이 //! 가리키는 것)에서만 해석합니다. 전역 CNode는 없으므로 다른 태스크의 @@ -17,9 +17,18 @@ //! 않고 소거만 합니다. //! //! 실행할 태스크가 없어도 커널은 정지하지 않습니다. 현재 태스크가 블록되거나 -//! 종료됐는데 준비된 태스크가 없으면 [idle_until_ready]가 인터럽트를 받으며 -//! 기다리고, 틱마다 기한이 지난 IPC 대기자를 깨웁니다. 그래서 한 태스크가 -//! 마지막으로 블록되는 것만으로는 나머지 태스크의 타임아웃이 멈추지 않습니다. +//! 종료됐는데 그 도메인에 준비된 태스크가 없으면 [wait_for_work]가 인터럽트를 +//! 받으며 기다리고, 틱마다 기한이 지난 IPC 대기자를 깨웁니다. 그래서 한 +//! 태스크가 마지막으로 블록되는 것만으로는 나머지 태스크의 타임아웃이 멈추지 +//! 않습니다. +//! +//! 태스크는 시간 분할 도메인에 속하고, 분할 표가 정한 틱 동안에는 그 도메인의 +//! 태스크만 실행됩니다(판정은 k0-part, 큐는 k0-sched). 도는 도메인에 준비된 +//! 태스크가 없으면 다른 도메인에 준비된 태스크가 있어도 커널은 기다립니다. +//! 틱이 실행 중인 태스크를 끊었는데 들어온 도메인이 비어 있는 경우도 같은 +//! 길로 기다립니다. EL0로 돌아가는 모든 길은 마지막에 [k0_leave]를 거칩니다. +//! 거기서 돌아갈 태스크가 지금 도는 도메인의 실행 중 태스크인지 확인하고, 틱을 +//! 보호 구간만큼 일찍 받았으면 틱의 예정 시각까지 기다립니다. //! //! 커널을 `console-input`으로 빌드하면 콘솔 입력을 읽는 시스템 콜이 하나 //! 더 있습니다(CONSOLE_READ). 입력을 기다리며 잠든 태스크는 바이트가 도착했을 @@ -52,6 +61,7 @@ const _: () = { assert!(k0_abi::bootinfo::slot::ADDR_SPACE == k0_cap::boot_slot::ADDR_SPACE); assert!(k0_abi::bootinfo::slot::CONSOLE == k0_cap::boot_slot::CONSOLE); assert!(k0_abi::bootinfo::slot::CNODE == k0_cap::boot_slot::CNODE); + assert!(k0_abi::bootinfo::slot::PART_CTL == k0_cap::boot_slot::PART_CTL); }; /// EL0 svc 트랩의 시스템 콜 정책 함수입니다. (k0-arch가 링크 계약으로 호출) @@ -89,6 +99,8 @@ extern "C" fn k0_syscall(ctx: &mut Context) { nr::CAP_MOVE => Some(sys_cap_move(a[0], a[1], a[2])), nr::CAP_DELETE => Some(sys_cap_delete(a[0])), nr::CAP_REVOKE => Some(sys_cap_revoke(a[0])), + nr::PART_SET_TABLE => Some(sys_part_set_table(a[0], a[1], [a[2], a[3], a[4], a[5]])), + nr::PART_SET_DOMAIN => Some(sys_part_set_domain(a[0], a[1], a[2])), // IPC는 블록 경로에서 반환 레지스터를 미래의 상대가 기록하므로 // 핸들러가 ctx 기록까지 직접 책임짐. false는 호출한 태스크가 // 블록됐는데 준비된 태스크가 없다는 뜻이고, 그때는 커널이 기다림 @@ -121,6 +133,7 @@ extern "C" fn k0_syscall(ctx: &mut Context) { } }; finish(ctx, ret); + k0_leave(); } /// EL0 동기 폴트의 격리 정책 함수입니다. (k0-arch가 링크 계약으로 호출) @@ -143,28 +156,77 @@ extern "C" fn k0_fault(ctx: &mut Context, esr: u64, far: u64) { ); kill_current(); finish(ctx, None); + k0_leave(); } /// 타이머 틱의 선점 정책 함수입니다. (k0-arch가 EL0 IRQ 경로에서 링크 /// 계약으로 호출) /// -/// 기한이 지난 IPC 대기자를 먼저 깨운 뒤 현재 태스크를 끊을지 판정합니다. 틱은 -/// 실행 중인 태스크를 끊고 들어왔으므로 현재 태스크는 기한 목록에 없습니다. +/// 판정은 스케줄러가 합니다(`k0_sched::on_tick`). 도는 도메인이 그대로면 그 +/// 도메인의 기한이 지난 IPC 대기자를 먼저 깨운 뒤 현재 태스크를 끊을지 정하고, +/// 창의 경계면 현재 태스크를 자기 도메인의 큐에 세워 두고 들어오는 도메인의 +/// 태스크를 실행합니다. 틱은 실행 중인 태스크를 끊고 들어왔으므로 현재 태스크는 +/// 기한 목록에 없습니다. /// /// 틱이 언제나 다음 태스크로 돌리는 것은 아닙니다. 틱과 틱 사이에 CPU를 받은 -/// 태스크는 처음 맞는 틱 하나를 넘깁니다(`k0_sched::on_tick`). 그래서 틱 -/// 직전에 양보하거나 블록하는 태스크가 뒤에 선 태스크에게 주기의 끝자락만 주는 -/// 일이 없고, CPU를 받은 태스크는 온전한 한 주기 전에는 끊기지 않습니다. +/// 태스크는 처음 맞는 틱 하나를 넘깁니다. 그래서 틱 직전에 양보하거나 블록하는 +/// 태스크가 뒤에 선 태스크에게 주기의 끝자락만 주는 일이 없고, CPU를 받은 +/// 태스크는 온전한 한 주기 전에는 끊기지 않습니다. +/// +/// 들어온 도메인에 준비된 태스크가 없으면 EL0로 돌아가지 않고 기다립니다. +/// 끊긴 태스크는 자기 도메인의 큐에 서 있고, 그 도메인의 다음 창에서 +/// 이어집니다. #[unsafe(no_mangle)] extern "C" fn k0_preempt() { - // SAFETY: 벡터가 사용자 컨텍스트 저장을 마친 EL0 IRQ/FIQ 컨텍스트임 + // SAFETY: 벡터가 사용자 컨텍스트 저장을 마친 EL0 IRQ/FIQ 컨텍스트이고, + // 실행 중이던 태스크는 블록돼 있지 않아 깨울 대상이 아님 + let running = unsafe { k0_sched::on_tick(&mut |d, now| serve(d, now, None)) }; + if !running { + wait_for_work(None); + } +} + +/// 도메인 하나의 밀린 일을 하는 함수입니다. 스케줄러가 그 도메인이 도는 틱과 +/// 대기 루프에서 부릅니다. +/// +/// 틱이 장치를 들여다보다 가져온 입력이 있으면 기다리는 태스크를 깨우고, 그다음 +/// 기한이 지난 IPC 대기자를 깨웁니다. 둘 다 `d`의 태스크만 깨웁니다. +/// +/// # Arguments +/// `d` - 지금 도는 도메인 +/// `now` - 지금의 틱 수 +/// `ctx` - 블록된 채 기다리는 현재 태스크의 컨텍스트를 호출자가 쥐고 있으면 +/// 그 참조 +fn serve(d: k0_sched::Domain, now: u64, mut ctx: Option<&mut Context>) { + // SAFETY: 스케줄러의 사건 처리 중(EL0에서 들어온 예외의 핸들러)에만 + // 불리고, ctx가 Some이면 현재 태스크의 컨텍스트임 unsafe { - // 틱이 장치를 들여다보다 가져온 입력이 있으면 기다리는 태스크를 깨움 #[cfg(feature = "console-input")] - k0_ipc::console::wake(None); - k0_ipc::expire_timeouts(k0_arch::irq::ticks(), None); - k0_sched::on_tick(); + k0_ipc::console::wake(d, ctx.as_deref_mut()); + k0_ipc::expire_timeouts(d, now, ctx.as_deref_mut()); + } +} + +/// EL0로 돌아가기 직전의 마지막 확인 함수입니다. (시스템 콜과 폴트의 끝에서, +/// 그리고 k0-arch가 EL0 IRQ 경로의 끝에서 링크 계약으로 호출) +/// +/// 돌아갈 태스크가 실행 중 상태이고 지금 도는 도메인의 태스크인지 확인합니다. +/// 아니면 커널의 상태가 어긋난 것이므로 정지합니다(창 밖의 태스크를 조용히 +/// 실행하지 않음). 그다음 마지막으로 처리한 틱의 예정 시각까지 기다립니다. +/// 도메인이 바뀌는 틱은 보호 구간만큼 일찍 받으므로, 전환 작업이 그 안에 +/// 끝났다면 다음 도메인은 언제나 틱의 예정 시각에 시작합니다. 그 밖의 경우에는 +/// 이미 지난 시각이라 기다리지 않습니다. +#[unsafe(no_mangle)] +extern "C" fn k0_leave() { + // SAFETY: 핸들러의 일이 끝난 예외 컨텍스트라 스케줄러 접근이 배타적이고 + // current는 유효한 TCB임 + unsafe { + let cur = k0_sched::current(); + if (*cur).state != TaskState::Running || k0_sched::domain_of(cur) != k0_sched::running_domain() { + k0_arch::fatal("returning to a task outside its window"); + } } + k0_arch::irq::hold_until_due(); } /// 콘솔 입력이 도착했을 때의 정책 함수입니다. (k0-arch가 EL0 IRQ 경로에서 @@ -172,12 +234,14 @@ extern "C" fn k0_preempt() { /// /// 입력을 기다리는 태스크가 있으면 바이트를 전달하고 준비 큐의 끝에 넣습니다. /// 실행 중이던 태스크는 그대로 이어서 실행됩니다(입력이 선점을 일으키지 않음). +/// 기다리는 태스크가 지금 도는 도메인의 태스크가 아니면 바이트는 버퍼에 남고, +/// 그 태스크의 도메인이 도는 틱에서 전달됩니다. #[cfg(feature = "console-input")] #[unsafe(no_mangle)] extern "C" fn k0_console_event() { // SAFETY: 벡터가 사용자 컨텍스트 저장을 마친 EL0 IRQ 컨텍스트라 스케줄러 // 접근이 배타적이고, 실행 중이던 태스크는 대기자가 아님 - unsafe { k0_ipc::console::wake(None) }; + unsafe { k0_ipc::console::wake(k0_sched::running_domain(), None) }; } /// 핸들러가 끝난 뒤의 공통 종료 경로 함수입니다. @@ -199,7 +263,7 @@ fn finish(ctx: &mut Context, ret: Option) { // 태스크의 컨텍스트이고 그 TCB 프레임은 아직 재사용 전임 *ctx = Context::zeroed(); if !k0_sched::block_and_switch() { - idle_until_ready(ctx); + wait_for_work(Some(ctx)); } return; } @@ -229,38 +293,58 @@ fn kill_current() { /// `switched` - IPC 처리 함수의 반환값(false = 블록됐고 전환할 태스크가 없음) fn ipc_or_idle(ctx: &mut Context, switched: bool) -> Option { if !switched { - idle_until_ready(ctx); + wait_for_work(Some(ctx)); } None } -/// 준비된 태스크가 생길 때까지 인터럽트를 받으며 기다리는 함수입니다. +/// 실행할 태스크가 생길 때까지 인터럽트를 받으며 기다리는 함수입니다. /// -/// 현재 태스크가 블록됐거나 종료됐는데 준비 큐가 비었을 때 부릅니다. 코어를 -/// 세우지 않고 다음 인터럽트까지 재웠다가, 틱이 지나면 기한이 지난 IPC -/// 대기자를 깨우고 준비된 태스크로 전환합니다. 깨어나는 태스크는 블록된 채 -/// 기다리던 현재 태스크 자신일 수도 있습니다. 지금 태스크를 깨울 수 있는 -/// 것은 타임아웃과 (입력 경로가 있는 이미지에서는) 콘솔 입력뿐이라서, 기한을 -/// 건 대기자도 입력을 기다리는 태스크도 없으면 이 함수는 돌아오지 -/// 않습니다(틱은 계속 처리함). +/// 세 경우에 부릅니다. 현재 태스크가 블록됐는데, 또는 종료됐는데 그 도메인에 +/// 준비된 태스크가 없을 때, 그리고 틱이 실행 중이던 태스크를 끊었는데 들어온 +/// 도메인에 준비된 태스크가 없을 때입니다. 코어를 세우지 않고 다음 +/// 인터럽트까지 재웠다가 스케줄러에 묻습니다(`k0_sched::poll`). 틱이 지났으면 +/// 스케줄러가 분할 표를 따라 도메인을 옮기고, 도는 도메인의 기한이 지난 IPC +/// 대기자를 깨우고, 준비된 태스크로 전환합니다. 깨어나는 태스크는 블록된 채 +/// 기다리던 현재 태스크 자신일 수도 있습니다. 다른 도메인에 준비된 태스크가 +/// 있어도 그 도메인의 창이 올 때까지는 실행하지 않습니다. /// -/// 깨어난 태스크가 틱에서 깨어났는지 틱 사이에 깨어났는지를 스케줄러에 알려 -/// 줍니다. 틱에서 깨어난 태스크는 주기의 처음에 들어오므로 다음 틱에서 끊길 수 -/// 있고, 콘솔 입력으로 틱 사이에 깨어난 태스크는 처음 맞는 틱 하나를 넘깁니다. -/// 기다리는 동안 틱과 입력이 함께 왔으면 틱으로 봅니다. +/// 지금 태스크를 깨울 수 있는 것은 타임아웃과 (입력 경로가 있는 이미지에서는) +/// 콘솔 입력, 그리고 분할 표가 여는 다른 도메인의 창뿐입니다. 셋 다 없으면 이 +/// 함수는 돌아오지 않습니다(틱은 계속 처리함). +/// +/// 깨어난 태스크가 틱에서 들어오는지 틱 사이에 들어오는지는 스케줄러가 틱 +/// 번호를 보고 판단합니다. /// /// # Arguments -/// `ctx` - 이번 진입을 일으킨 태스크(스케줄러의 현재 태스크)의 컨텍스트 -fn idle_until_ready(ctx: &mut Context) { +/// `ctx` - 블록됐거나 종료된 현재 태스크의 컨텍스트. 틱이 끊은 태스크를 두고 +/// 기다리는 경우에는 `None`(그 태스크는 블록돼 있지 않아 깨울 대상이 아님) +fn wait_for_work(mut ctx: Option<&mut Context>) { static WAITING: AtomicBool = AtomicBool::new(false); static STOPPED: AtomicBool = AtomicBool::new(false); let mut con = EarlyCon; + // SAFETY: 예외 컨텍스트라 스케줄러 접근이 배타적이고 current는 유효한 + // TCB임 + if ctx.is_none() && unsafe { (*k0_sched::current()).state } != TaskState::Ready { + // 컨텍스트 없이 기다리는 것은 틱이 끊은 태스크가 큐에 서 있을 때뿐임 + k0_arch::fatal("waiting without a context while a task is not parked"); + } loop { // 대기에 들어갈 때마다 찍으면 로그를 채우므로 종류마다 처음 한 번만 // 알림. 기한을 건 대기자가 없는 쪽은 회복할 길이 없는 상태이므로 - // 예전의 정지 메시지와 같은 머리말을 써서 눈에 띄게 함 - // SAFETY: 시스템 콜/폴트 컨텍스트라 스케줄러 접근이 배타적임 - if unsafe { k0_sched::has_timed() } { + // 예전의 정지 메시지와 같은 머리말을 써서 눈에 띄게 함. 분할 중에는 + // 빈 창에서 기다리는 것이 정상이므로 기다린다는 줄은 찍지 않음. 다만 + // 어느 도메인에도 준비된 태스크와 기한을 건 대기자가 없고 입력을 + // 기다리는 태스크도 없으면 다른 창이 와도 실행할 것이 없으므로, 그 + // 정지만은 분할 중에도 알림 + // SAFETY: 시스템 콜/폴트/IRQ 컨텍스트라 스케줄러 접근이 배타적임 + if unsafe { k0_sched::partitioned() } { + // SAFETY: 위와 같음 + let alive = unsafe { k0_sched::has_ready() || k0_sched::has_timed() } || console_waiting(); + if !alive && !STOPPED.swap(true, Ordering::Relaxed) { + let _ = writeln!(con, "k0: all tasks stopped (none ready, no timeout pending)"); + } + } else if unsafe { k0_sched::has_timed() } { if !WAITING.swap(true, Ordering::Relaxed) { let _ = writeln!(con, "k0: idle (waiting for a timeout)"); } @@ -272,18 +356,11 @@ fn idle_until_ready(ctx: &mut Context) { } // SAFETY: EL0에서 진입한 예외의 핸들러 안이라 사용자 컨텍스트가 TCB에 // 저장돼 있고, 커널 스택은 최상단에서 시작해 여유가 있음. - // ctx는 현재 태스크의 컨텍스트이며, 기한이 지난 현재 태스크의 - // 반환값은 이 참조로만 기록됨 + // ctx가 Some이면 현재 태스크의 컨텍스트이며, 기한이 지났거나 + // 입력을 받은 현재 태스크의 반환값은 이 참조로만 기록됨 unsafe { - let before = k0_arch::irq::ticks(); k0_arch::irq::wait_for_interrupt(); - // 방금의 인터럽트가 입력을 가져왔으면 기다리는 태스크를 깨움. - // 대기자가 블록된 현재 태스크 자신일 수 있어 ctx를 넘김 - #[cfg(feature = "console-input")] - k0_ipc::console::wake(Some(&mut *ctx)); - let now = k0_arch::irq::ticks(); - k0_ipc::expire_timeouts(now, Some(&mut *ctx)); - if k0_sched::resume_from_idle(now != before) { + if k0_sched::poll(&mut |d, now| serve(d, now, ctx.as_deref_mut())) { return; } } @@ -691,7 +768,7 @@ fn console_recheck() { // 부른 실행 중인 태스크는 대기자가 아님 #[cfg(feature = "console-input")] unsafe { - k0_ipc::console::wake(None) + k0_ipc::console::wake(k0_sched::running_domain(), None) }; } @@ -777,12 +854,86 @@ fn sys_tcb_configure(slot: u64, entry: u64, stack: u64, aspace: u64, cnode: u64, t.ctx.spsr = 0; // EL0t, DAIF 언마스크, 커널이 강제 t.ctx.x[0] = arg; t.ttbr0_pa = root_pa; + // 새 태스크는 구성한 태스크의 도메인에 속함. 다른 도메인에 두려면 + // 제어 케이퍼빌리티가 필요함(PART_SET_DOMAIN) + t.domain = k0_sched::domain_of(k0_sched::current()).id(); t.state = TaskState::Stopped; } Ok(()) })()) } +/// 슬롯에 시간 분할 제어 케이퍼빌리티가 있는지 확인하는 함수입니다. +/// +/// # Errors +/// 슬롯이 비었거나 범위 밖이면 BAD_SLOT, 다른 종류면 BAD_CAP +fn part_ctl(cn: &CNodeRef, slot: u64) -> Result<(), i64> { + let (_, e) = lookup(cn, slot)?; + match e.cap { + Cap::PartCtl => Ok(()), + _ => Err(err::BAD_CAP), + } +} + +/// PART_SET_TABLE 시스템 콜 처리 함수입니다. +/// +/// 표의 형식 검사는 k0-part가 합니다. 호출한 태스크 자신의 도메인이 표에 +/// 없으면 거부합니다(실수로 자기 자신을 영영 멈추는 표를 막음). 표는 지금 틱의 +/// 두 틱 뒤에 0번 항목부터 효력이 생깁니다. +/// +/// # Arguments +/// `ctl` - PartCtl 슬롯(x0) +/// `count` - 항목 수(x1) +/// `regs` - 항목을 담은 레지스터 넷(x2-x5) +fn sys_part_set_table(ctl: u64, count: u64, regs: [u64; 4]) -> i64 { + done((|| { + let cn = cspace()?; + part_ctl(&cn, ctl)?; + let table = k0_sched::Table::decode(count, regs).map_err(|_| err::BAD_TABLE)?; + // SAFETY: 시스템 콜 컨텍스트라 접근이 배타적이고 current는 유효한 TCB임 + unsafe { + if !table.contains(k0_sched::domain_of(k0_sched::current())) { + return Err(err::BAD_TABLE); + } + k0_sched::set_table(table); + } + Ok(()) + })()) +} + +/// PART_SET_DOMAIN 시스템 콜 처리 함수입니다. +/// +/// 구성을 마치고 아직 시작하지 않은(Stopped) TCB의 도메인만 바꿉니다. 그 +/// 상태의 TCB는 준비 큐에도 대기 큐에도 기한 목록에도 없으므로, 도메인마다 +/// 따로 있는 목록과 어긋날 일이 없습니다. 도메인이 표에 있는지는 보지 +/// 않습니다(표에 없는 도메인의 태스크는 실행되지 않을 뿐임). +/// +/// # Arguments +/// `ctl` - PartCtl 슬롯(x0) +/// `slot` - TCB 슬롯(x1) +/// `domain` - 새 도메인(x2) +fn sys_part_set_domain(ctl: u64, slot: u64, domain: u64) -> i64 { + done((|| { + let cn = cspace()?; + part_ctl(&cn, ctl)?; + let d = u8::try_from(domain).ok().and_then(k0_sched::Domain::new).ok_or(err::BAD_DOMAIN)?; + let (_, e) = lookup(&cn, slot)?; + let Cap::Tcb { base } = e.cap else { + return Err(err::BAD_CAP); + }; + let t = kva(base) as *mut Tcb; + // SAFETY: t는 TCB 케이퍼빌리티가 가리키는 전용 프레임의 별칭이고, + // Stopped인 TCB는 어느 목록에도 없음 + unsafe { + if (*t).state != TaskState::Stopped { + return Err(err::BAD_STATE); + } + k0_sched::assign(t, d); + } + Ok(()) + })()) +} + /// TCB_RESUME 시스템 콜 처리 함수입니다. /// /// 구성(Stopped)을 마친 TCB만 준비 큐에 넣습니다. 이미 큐에 있거나 실행 diff --git a/proofs/lean/K0Bridge.lean b/proofs/lean/K0Bridge.lean new file mode 100644 index 0000000..aa39a0a --- /dev/null +++ b/proofs/lean/K0Bridge.lean @@ -0,0 +1,1660 @@ +import K0Part +import K0Share + +/- +K0Bridge.lean: the tick rule of `K0Part.lean` is the tick rule of `K0Share.lean`. + +WHAT THIS FILE IS + `K0Part.lean` models the partition scheduler over several domains and keeps + an exemption bit for the running task. `K0Share.lean` models one domain and + proves what that bit buys: a bound on the CPU share of a task that never + gives up the CPU. `K0Part.lean` has no theorem about its tick rule, and + before this file no theorem linked the two. + This file imports both, changes neither, and proves that `K0Part` does to + its running domain, rule by rule, what `K0Share` does to its one domain. + Everything here is about the two MODELS. Nothing here is about the Rust + code. + +THE PROJECTION + `Rel lab s k`: in the `K0Part` state `s` a task runs, and the `K0Share` + state `k` has the label of that task as `cur`, its exemption bit as `ex` + and the labels of the running domain's ready queue as `q`. Only these + three fields are compared. The countdown, `age`, `time` and `ran` of `k` + are free. + `lab : Tid → Nat` gives a task its `K0Share` name. `K0Share` only asks + whether a name is 0, so "the spinner" is a task with label 0. With + `lab = id` it is task 0. Any other choice works, one per domain if wanted. + `Parked lab s d k`: domain `d` does not run, and `k` is what it will look + like when its window opens (the head of its queue runs, without the mark). + +WHAT IS PROVED + (1) Rule by rule, for every state. No invariant is needed. + sameStep_onTick a tick inside the running domain is `onTick` + serve_wakes the timed wakes are wakes at the back of the queue, + in the order `serve` appends them + tick_same, tick_same_run both, for `step` on a new tick + yield_step `yield`, if the running task is not the spinner + block_step `block`, same condition, queue not empty + wake_step `wake` of a task that waits in the running domain + boot_start0 at boot the first task has the mark, as in `start0` + Side conditions, all explicit: a woken task does not have label 0, and + the cap `N` of `K0Share.step` is not reached. `K0Part` has no cap. + Where `K0Share` excludes a case the two sides really differ: + yield_spinner_differs, block_spinner_differs (the spinner gives up the + CPU), block_empty_idle (the domain idles; `K0Share` has no idle state), + wake_cap_needed (a wake at the cap). + (2) The window boundary. `K0Share` has no window and no other domain, so + there is no rule of it to compare with. What is proved is how `K0Part` + treats the running task at a boundary, in `K0Share` terms: + cut_parked parking is `onTick`, with the task `onTick` would + run kept at the head of the queue: a task with the + mark keeps the front and loses the mark, a task + without it goes behind the one that was at the head + enter_parked the task that enters has no mark + tick_leave, tick_return the same for `step` on a new tick + parked_keep an event of another window leaves a parked domain + alone, unless it is a wake across domains into it + window_cycle from the tick that closes a window to the tick that + opens it again, the domain moves by ONE `onTick` and + then by the wakes `serve` does when it opens. + Hypotheses: `K0Part.Inv`, no wake across domains into + the domain in between, and for the wakes at the + opening the side conditions of `serve_wakes` + (3) One domain, run level. `K0Part` has no time between ticks, so the + bridge adds it: a step `pass` (time passes, no tick), a countdown to the + next tick and two counters (`TSt`, `tstep`). These belong to the + bridge, not to `K0Part`; the `K0Part` state moves by `K0Part.step` only. + run_projects, run_projects_prefix + a timed run of one domain projects, step after step, onto the + `K0Share` behaviour `trRun` builds from it + timed_share_bound, boot_share_bound + so `K0Share.share_bound` holds for it: steps passed + `<= N *` steps in which the task with label 0 was the running + task of the `K0Part` state `+ (N - 1) * P +` the first countdown + Hypotheses (`Start`, `OkRun`): the table in force and any pending table + name the running domain only; a tick falls every `P` steps; the spinner + never yields or blocks; no `poll`; exactly one task with label 0 among + the running and the ready tasks and none among the waiting ones; at most + `N` tasks in the domain. Under them the domain never idles. + (4) example_start, example_ok, example_events: a concrete run where all + hypotheses of (3) hold. example_tight: a run that reaches the constant + of the bound (`N = 3`, `P = 2`). example_spinner_yield: without "the + spinner never yields" the bound fails. example_window: a concrete + boundary with two domains where all hypotheses of `window_cycle` hold. + (1) and (2) pin the tick rule of `K0Part.lean`. With the mark not cleared + by a tick, no mark after a yield or a block, a mark at a tick entry, no mark + at boot, or a cut task parked at the other end, one of them is false. + +WHAT IS NOT PROVED + * Nothing about the Rust code. Both models are read off it by hand. + * No share bound for a table with several domains. `window_cycle` says + what one boundary does to the projection. No theorem counts the steps of + a domain across its windows, and nothing is said about a window that ends + inside a period (in `K0Part` a window is a whole number of ticks). + * The time between ticks is not `K0Part`'s. `OkRun` asks for a tick every + `P` steps; `K0Part` does not enforce that. A jump of the tick index over + several ticks counts as one tick and one step. + * The idle paths of `K0Part` (the idle loop `poll`, a tick that finds the + domain idle, a block with an empty queue) have no counterpart in `K0Share` + and are not covered. + * Only `share_bound` is carried over. `K0Share.no_early_cut` and + `K0Share.wait_bound` are not: `age` is not part of the projection. + * Nothing about instants, the guard, caches or any channel outside the + scheduler decision. +`#print axioms` lines are at the end of the file. +-/ + +namespace K0Bridge + +open K0Part (Tid Dom) + +/-! ## The projection -/ + +/-- The projection, as a relation. `Rel lab s k`: in the `K0Part` state `s` a + task runs, and the running domain of `s` looks to `K0Share` like `k`: + the label of the running task is `k.cur`, its exemption bit is `k.ex`, and + the labels of the running domain's ready queue are `k.q`, in order. + Only these three fields of `k` are compared. The countdown `c`, `age`, + `time` and `ran` of `k` are free. -/ +def Rel (lab : Tid → Nat) (s : K0Part.St) (k : K0Share.St) : Prop := + ∃ c, s.cur = some (c, k.ex) ∧ lab c = k.cur ∧ (s.q s.rd).map lab = k.q + +/-- The tasks that `serve s d n` appends to the queue of `d`, in that order. -/ +def woken (s : K0Part.St) (d n : Nat) : List Tid := + (((s.wl d).filter (fun w => K0Part.expired w n)).reverse).map Prod.fst + +/-- One `K0Share` wake per task, in the order of the list. -/ +def wakes (lab : Tid → Nat) (ts : List Tid) : List K0Share.Ev := + ts.map (fun t => K0Share.Ev.wake (lab t)) + +/-- A domain whose window is closed, seen as the `K0Share` state `k` it will + have when the window opens: the head of its queue will be the running + task, without the mark, and the rest of the queue is `k.q`. -/ +def Parked (lab : Tid → Nat) (s : K0Part.St) (d : Dom) (k : K0Share.St) : Prop := + k.ex = false ∧ (s.q d).map lab = k.cur :: k.q + +/-! ## Facts about `K0Share` used below -/ + +theorem exec_append (N P : Nat) (a b : List K0Share.Ev) : ∀ (k : K0Share.St), + K0Share.exec N P k (a ++ b) = K0Share.exec N P (K0Share.exec N P k a) b := by + induction a with + | nil => intro k; rfl + | cons e a ih => intro k; exact ih _ + +/-- A list of wakes below the cap, none of them of a task with label 0, is an + append at the back of the queue and nothing else. -/ +theorem exec_wakes (lab : Tid → Nat) (N P : Nat) : ∀ (ts : List Tid) (k : K0Share.St), + (∀ t ∈ ts, lab t ≠ 0) → k.q.length + ts.length + 1 ≤ N → + K0Share.exec N P k (wakes lab ts) = { k with q := k.q ++ ts.map lab } := by + intro ts + induction ts with + | nil => intro k _ _; simp [wakes, K0Share.exec] + | cons t ts ih => + intro k hne hcap + have ht : lab t ≠ 0 := hne t (by simp) + have hlt : K0Share.cnt k < N := by + simp only [List.length_cons] at hcap + simp only [K0Share.cnt] + omega + have hs : K0Share.step N P k (.wake (lab t)) = { k with q := k.q ++ [lab t] } := by + simp [K0Share.step, ht, hlt] + have h2 := ih { k with q := k.q ++ [lab t] } (fun u hu => hne u (by simp [hu])) + (by simp only [List.length_cons, List.length_append, List.length_nil] at hcap ⊢; omega) + show K0Share.exec N P (K0Share.step N P k (.wake (lab t))) (wakes lab ts) = _ + rw [hs, h2] + simp + +/-- `K0Share.onTick` keeps the length of the queue. -/ +theorem onTick_q_length (P : Nat) (k : K0Share.St) : + (K0Share.onTick P k).q.length = k.q.length := by + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + cases kex with + | true => simp [K0Share.onTick] + | false => cases kq <;> simp [K0Share.onTick] + +/-- After `K0Share.onTick` the running task has no mark. -/ +theorem onTick_ex (P : Nat) (k : K0Share.St) : (K0Share.onTick P k).ex = false := by + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + cases kex with + | true => simp [K0Share.onTick] + | false => cases kq <;> simp [K0Share.onTick] + +/-! ## Rule by rule -/ + +theorem serve_q (s : K0Part.St) (d n : Nat) : + (K0Part.serve s d n).q d = s.q d ++ woken s d n := by + simp [K0Part.serve, K0Part.upd, woken] + +/-- The tick rule. `K0Part.sameStep` (what a tick does inside the running + domain, after `serve`) is `K0Share.onTick` on the projection: with the mark + the tick only clears it; without the mark the running task goes to the back + and the head runs without a mark; with an empty queue nothing moves. + No side condition. -/ +theorem sameStep_onTick (lab : Tid → Nat) (P : Nat) {s : K0Part.St} {k : K0Share.St} + (h : Rel lab s k) : Rel lab (K0Part.sameStep s) (K0Share.onTick P k) := by + obtain ⟨c, hc, hl, hq⟩ := h + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc hl hq + subst hl hq + cases kex with + | true => + refine ⟨c, ?_, ?_, ?_⟩ <;> simp [K0Part.sameStep, hc, K0Share.onTick] + | false => + cases hq' : s.q s.rd with + | nil => + refine ⟨c, ?_, ?_, ?_⟩ <;> simp [K0Part.sameStep, hc, hq', K0Share.onTick] + | cons x r => + refine ⟨x, ?_, ?_, ?_⟩ <;> + simp [K0Part.sameStep, hc, hq', K0Share.onTick, K0Part.upd] + +/-- The timed wakes of `serve` are `K0Share` wakes at the back of the queue, + in the order `serve` appends them. Side conditions: no woken task has + label 0, and the cap `N` of `K0Share.step` is not reached. -/ +theorem serve_wakes (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} {k : K0Share.St} (n : Nat) + (h : Rel lab s k) (hne : ∀ t ∈ woken s s.rd n, lab t ≠ 0) + (hcap : k.q.length + (woken s s.rd n).length + 1 ≤ N) : + Rel lab (K0Part.serve s s.rd n) (K0Share.exec N P k (wakes lab (woken s s.rd n))) := by + obtain ⟨c, hc, hl, hq⟩ := h + rw [exec_wakes lab N P _ k hne hcap] + refine ⟨c, hc, hl, ?_⟩ + show ((K0Part.serve s s.rd n).q s.rd).map lab = k.q ++ (woken s s.rd n).map lab + rw [serve_q, List.map_append, hq] + +/-- `s` with the clock part moved to tick `n`, the first thing `tickStep` does. + Queues, waiting lists, the running task and `rd` are those of `s`. -/ +def clocked (s : K0Part.St) (n : Nat) : K0Part.St := + { s with part := { s.part.advance n with seen := n } } + +/-- Unfolding of `K0Part.step` on a new tick that stays in the running domain. -/ +theorem step_tick_same (dom : Tid → Dom) (s : K0Part.St) (n : Nat) (hn : s.part.seen < n) + (hd : (s.part.advance n).domNow n = s.rd) : + K0Part.step dom s (.tick n) = K0Part.sameStep (K0Part.serve (clocked s n) s.rd n) := by + have hn' : ¬ n ≤ s.part.seen := by omega + simp [K0Part.step, K0Part.tickStep, hn', hd, clocked] + +/-- Unfolding of `K0Part.step` on a new tick that changes the domain to `d`. -/ +theorem step_tick_other (dom : Tid → Dom) (s : K0Part.St) (n : Nat) (d : Dom) + (hn : s.part.seen < n) (hd : (s.part.advance n).domNow n = d) (hrd : s.rd ≠ d) : + K0Part.step dom s (.tick n) = + K0Part.enter (K0Part.serve { K0Part.cut (clocked s n) with rd := d } d n) d := by + have hn' : ¬ n ≤ s.part.seen := by omega + have hrd' : ¬ d = s.rd := fun e => hrd e.symm + simp [K0Part.step, K0Part.tickStep, hn', hd, hrd', clocked] + +/-- A new tick that stays in the running domain (`K0Part.step` on `tick n` + with `n` not seen before and the same domain planned for `n`) is, on the + projection, the wakes of `serve` followed by `K0Share.onTick`. + A jump of the index over several ticks is still one `onTick`. -/ +theorem tick_same (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (n : Nat) (h : Rel lab s k) (hn : s.part.seen < n) + (hd : (s.part.advance n).domNow n = s.rd) + (hne : ∀ t ∈ woken s s.rd n, lab t ≠ 0) + (hcap : k.q.length + (woken s s.rd n).length + 1 ≤ N) : + Rel lab (K0Part.step dom s (.tick n)) + (K0Share.onTick P (K0Share.exec N P k (wakes lab (woken s s.rd n)))) := by + rw [step_tick_same dom s n hn hd] + have h1 : Rel lab (clocked s n) k := h + exact sameStep_onTick lab P (serve_wakes lab N P n h1 hne hcap) + +/-- A `K0Share` `run` that ends a period (countdown at most 1) is `onTick` on + the three fields. -/ +theorem run_tick_fields (N P : Nat) (k : K0Share.St) (hc : k.c ≤ 1) : + (K0Share.step N P k .run).cur = (K0Share.onTick P k).cur ∧ + (K0Share.step N P k .run).ex = (K0Share.onTick P k).ex ∧ + (K0Share.step N P k .run).q = (K0Share.onTick P k).q := by + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc + cases kex with + | true => simp [K0Share.step, K0Share.runStep, K0Share.onTick, hc] + | false => cases kq <;> simp [K0Share.step, K0Share.runStep, K0Share.onTick, hc] + +/-- So such a `run` is `K0Part.sameStep` on the projection. -/ +theorem run_tick (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} {k : K0Share.St} + (h : Rel lab s k) (hc : k.c ≤ 1) : + Rel lab (K0Part.sameStep s) (K0Share.step N P k .run) := by + obtain ⟨f1, f2, f3⟩ := run_tick_fields N P k hc + obtain ⟨c, hc1, hl, hq⟩ := sameStep_onTick lab P h + exact ⟨c, by rw [f2]; exact hc1, by rw [f1]; exact hl, by rw [f3]; exact hq⟩ + +/-- A `K0Share` `run` inside a period (countdown above 1) leaves the three + fields alone. `K0Part` has no event for it. -/ +theorem run_pass (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} {k : K0Share.St} + (h : Rel lab s k) (hc : 1 < k.c) : Rel lab s (K0Share.step N P k .run) := by + obtain ⟨c, hc1, hl, hq⟩ := h + have hc' : ¬ k.c ≤ 1 := by omega + refine ⟨c, ?_, ?_, ?_⟩ <;> simp [K0Share.step, K0Share.runStep, hc', hc1, hl, hq] + +/-- `tick_same` in `K0Share` events only: the wakes of `serve`, then one `run` + that ends a period. -/ +theorem tick_same_run (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (n : Nat) (h : Rel lab s k) (hn : s.part.seen < n) + (hd : (s.part.advance n).domNow n = s.rd) + (hne : ∀ t ∈ woken s s.rd n, lab t ≠ 0) + (hcap : k.q.length + (woken s s.rd n).length + 1 ≤ N) (hc : k.c ≤ 1) : + Rel lab (K0Part.step dom s (.tick n)) + (K0Share.exec N P k (wakes lab (woken s s.rd n) ++ [.run])) := by + rw [step_tick_same dom s n hn hd, exec_append] + have h1 : Rel lab (clocked s n) k := h + have h2 := serve_wakes lab N P n h1 hne hcap + have hc' : (K0Share.exec N P k (wakes lab (woken s s.rd n))).c ≤ 1 := by + rw [exec_wakes lab N P _ k hne hcap]; exact hc + exact run_tick lab N P h2 hc' + +/-- `yield`. When the running task is not the spinner, `K0Part`'s yield is + `K0Share.step .yield` on the projection: the head runs with the mark and + the task that yielded is at the back; with an empty queue nothing moves. -/ +theorem yield_step (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (h : Rel lab s k) (hsp : k.cur ≠ 0) : + Rel lab (K0Part.step dom s .yield) (K0Share.step N P k .yield) := by + obtain ⟨c, hc, hl, hq⟩ := h + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc hl hq hsp + subst hl hq + cases hq' : s.q s.rd with + | nil => + refine ⟨c, ?_, ?_, ?_⟩ <;> + simp [K0Part.step, K0Part.yieldStep, hc, hq', K0Share.step, hsp] + | cons x r => + refine ⟨x, ?_, ?_, ?_⟩ <;> + simp [K0Part.step, K0Part.yieldStep, hc, hq', K0Share.step, hsp, K0Part.upd] + +/-- The case `K0Share` excludes. `K0Part` lets any running task yield; + `K0Share.step .yield` does nothing when the spinner runs. If the spinner + yields with a non-empty queue the two sides differ, so `yield_step` needs + its hypothesis. (`0 ∉ k.q`: there is no second task with label 0.) -/ +theorem yield_spinner_differs (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (h : Rel lab s k) (hsp : k.cur = 0) (h0 : 0 ∉ k.q) (hq : k.q ≠ []) : + ¬ Rel lab (K0Part.step dom s .yield) (K0Share.step N P k .yield) := by + obtain ⟨c, hc, hl, hq1⟩ := h + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc hl hq1 hsp h0 hq + subst hq1 + cases hq' : s.q s.rd with + | nil => simp [hq'] at hq + | cons x r => + have hx : lab x ≠ 0 := fun e => h0 (by simp [hq', e]) + rintro ⟨c', hc', hl', -⟩ + simp [K0Part.step, K0Part.yieldStep, hc, hq', K0Share.step, hsp] at hc' hl' + exact hx (by rw [hc'.1]; exact hl') + +/-- `block`. When the running task is not the spinner and the queue is not + empty, `K0Part`'s block is `K0Share.step .block` on the projection: the + head runs with the mark. The waiting list is outside the projection. -/ +theorem block_step (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (dl : Option Nat) (h : Rel lab s k) (hsp : k.cur ≠ 0) (hne : k.q ≠ []) : + Rel lab (K0Part.step dom s (.block dl)) (K0Share.step N P k .block) := by + obtain ⟨c, hc, hl, hq⟩ := h + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc hl hq hsp hne + subst hl hq + cases hq' : s.q s.rd with + | nil => simp [hq'] at hne + | cons x r => + refine ⟨x, ?_, ?_, ?_⟩ <;> + simp [K0Part.step, K0Part.blockStep, K0Part.popBetween, hc, hq', K0Share.step, hsp, + K0Part.upd] + +/-- The spinner's block is excluded like its yield: `K0Share.step .block` + does nothing when the spinner runs, `K0Part` hands the CPU to the head. -/ +theorem block_spinner_differs (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (dl : Option Nat) (h : Rel lab s k) (hsp : k.cur = 0) (h0 : 0 ∉ k.q) + (hq : k.q ≠ []) : + ¬ Rel lab (K0Part.step dom s (.block dl)) (K0Share.step N P k .block) := by + obtain ⟨c, hc, hl, hq1⟩ := h + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc hl hq1 hsp h0 hq + subst hq1 + cases hq' : s.q s.rd with + | nil => simp [hq'] at hq + | cons x r => + have hx : lab x ≠ 0 := fun e => h0 (by simp [hq', e]) + rintro ⟨c', hc', hl', -⟩ + simp [K0Part.step, K0Part.blockStep, K0Part.popBetween, hc, hq', K0Share.step, hsp] + at hc' hl' + exact hx (by rw [hc'.1]; exact hl') + +/-- The other case `K0Share` excludes. A block with an empty queue leaves the + domain idle in `K0Part`. `K0Share` has no idle state, so the result has no + projection at all. -/ +theorem block_empty_idle (dom : Tid → Dom) (lab : Tid → Nat) {s : K0Part.St} {k : K0Share.St} + (dl : Option Nat) (h : Rel lab s k) (he : k.q = []) (k' : K0Share.St) : + ¬ Rel lab (K0Part.step dom s (.block dl)) k' := by + obtain ⟨c, hc, -, hq⟩ := h + have hq' : s.q s.rd = [] := by + rw [he] at hq + exact List.map_eq_nil_iff.mp hq + rintro ⟨c', hc', -, -⟩ + simp [K0Part.step, K0Part.blockStep, K0Part.popBetween, hc, hq'] at hc' + +/-- `wake`. A wake of a task that waits in the running domain is a + `K0Share` wake of its label: an append at the back of the queue. Side + conditions: the task does not have label 0, and the cap of `K0Share.step` + is not reached (`k.q.length + 1 < N`). -/ +theorem wake_step (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (t : Tid) (h : Rel lab s k) (hd : dom t = s.rd) + (hw : ∃ w ∈ s.wl s.rd, w.1 = t) (hne : lab t ≠ 0) (hcap : k.q.length + 1 < N) : + Rel lab (K0Part.step dom s (.wake t)) (K0Share.step N P k (.wake (lab t))) := by + obtain ⟨c, hc, hl, hq⟩ := h + have hany : (s.wl s.rd).any (fun w => decide (w.1 = t)) = true := by + obtain ⟨w, hw1, hw2⟩ := hw + exact List.any_eq_true.mpr ⟨w, hw1, by simp [hw2]⟩ + have hs : K0Share.step N P k (.wake (lab t)) = { k with q := k.q ++ [lab t] } := by + simp [K0Share.step, hne, K0Share.cnt, hcap] + rw [hs] + refine ⟨c, ?_, hl, ?_⟩ + · simp [K0Part.step, K0Part.doWake, hc, hd, hany] + · simp [K0Part.step, K0Part.doWake, hc, hd, hany, K0Part.upd, hq] + +/-- A wake of a task that does not wait changes nothing in `K0Part`. It + projects onto no `K0Share` event. -/ +theorem wake_not_waiting (dom : Tid → Dom) (s : K0Part.St) (t : Tid) + (hw : ¬ ∃ w ∈ s.wl (dom t), w.1 = t) : K0Part.step dom s (.wake t) = s := by + have hany : (s.wl (dom t)).any (fun w => decide (w.1 = t)) = false := by + cases hb : (s.wl (dom t)).any (fun w => decide (w.1 = t)) with + | false => rfl + | true => + obtain ⟨w, hw1, hw2⟩ := List.any_eq_true.mp hb + exact absurd ⟨w, hw1, by simpa using hw2⟩ hw + simp [K0Part.step, K0Part.doWake, hany] + +/-- The cap is a real side condition. `K0Part` has no bound on the number of + tasks; at the cap `K0Share.step` drops the wake and the two sides differ. -/ +theorem wake_cap_needed (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (t : Tid) (h : Rel lab s k) (hd : dom t = s.rd) + (hw : ∃ w ∈ s.wl s.rd, w.1 = t) (hcap : ¬ k.q.length + 1 < N) : + ¬ Rel lab (K0Part.step dom s (.wake t)) (K0Share.step N P k (.wake (lab t))) := by + obtain ⟨c, hc, -, hq⟩ := h + have hany : (s.wl s.rd).any (fun w => decide (w.1 = t)) = true := by + obtain ⟨w, hw1, hw2⟩ := hw + exact List.any_eq_true.mpr ⟨w, hw1, by simp [hw2]⟩ + have hs : K0Share.step N P k (.wake (lab t)) = k := by + simp [K0Share.step, K0Share.cnt, hcap] + rw [hs] + rintro ⟨c', -, -, hq'⟩ + have hl := congrArg List.length hq' + simp [K0Part.step, K0Part.doWake, hc, hd, hany, K0Part.upd, ← hq] at hl + +/-- Boot. The state of `K0Part.boot` projects onto `K0Share.start0`: the first + task runs with the mark. (`start` is the offset inside a period; it only + sets the countdown, which is not compared.) -/ +theorem boot_start0 (lab : Tid → Nat) (now : Nat) (first : Tid) (q0 : Dom → List Tid) + (w0 : Dom → List (Tid × Option Nat)) (P start : Nat) : + Rel lab (K0Part.boot now first q0 w0) + (K0Share.start0 (lab first) ((q0 0).map lab) P start) := + ⟨first, rfl, rfl, rfl⟩ + +/-! ## The window boundary + +`K0Share` has one domain and no window. What is shown here is how `K0Part` +treats the running task and its queue at a boundary, in `K0Share` terms. -/ + +/-- Parking at a boundary is `K0Share.onTick`, with the task that `onTick` + would run kept at the head of the queue. A task with the mark stays at + the front and loses the mark; a task without it goes behind the task that + was at the head (or stays, if the queue was empty). -/ +theorem cut_parked (lab : Tid → Nat) (P : Nat) {s : K0Part.St} {k : K0Share.St} + (h : Rel lab s k) : + (K0Part.cut s).cur = none ∧ Parked lab (K0Part.cut s) s.rd (K0Share.onTick P k) := by + obtain ⟨c, hc, hl, hq⟩ := h + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc hl hq + subst hl hq + cases kex with + | true => + refine ⟨?_, ?_, ?_⟩ <;> simp [K0Part.cut, hc, K0Share.onTick, K0Part.upd] + | false => + cases hq' : s.q s.rd with + | nil => + refine ⟨?_, ?_, ?_⟩ <;> simp [K0Part.cut, hc, hq', K0Share.onTick, K0Part.upd] + | cons x r => + refine ⟨?_, ?_, ?_⟩ <;> simp [K0Part.cut, hc, hq', K0Share.onTick, K0Part.upd] + +/-- Entering a domain: the head of its queue runs, without the mark. -/ +theorem enter_parked (lab : Tid → Nat) {s : K0Part.St} {k : K0Share.St} + (h : Parked lab s s.rd k) : Rel lab (K0Part.enter s s.rd) k := by + obtain ⟨hex, hq⟩ := h + cases hq' : s.q s.rd with + | nil => simp [hq'] at hq + | cons x r => + rw [hq'] at hq + simp only [List.map_cons, List.cons.injEq] at hq + refine ⟨x, ?_, hq.1, ?_⟩ + · simp [K0Part.enter, hq', hex] + · simp [K0Part.enter, hq', K0Part.upd, hq.2] + +/-- A window that closes and opens again with nothing in between is one + `K0Share.onTick` on the projection. -/ +theorem cut_enter_onTick (lab : Tid → Nat) (P : Nat) {s : K0Part.St} {k : K0Share.St} + (h : Rel lab s k) : + Rel lab (K0Part.enter (K0Part.cut s) s.rd) (K0Share.onTick P k) := by + have h1 := (cut_parked lab P h).2 + have h2 : Parked lab (K0Part.cut s) (K0Part.cut s).rd (K0Share.onTick P k) := by + rw [K0Part.cut_rd]; exact h1 + have h3 := enter_parked lab h2 + rw [K0Part.cut_rd] at h3 + exact h3 + +theorem woken_congr {s s' : K0Part.St} {d : Dom} (n : Nat) (h : s.wl d = s'.wl d) : + woken s d n = woken s' d n := by + unfold woken; rw [h] + +theorem enter_cons (s : K0Part.St) (d : Dom) (x : Tid) (r : List Tid) (h : s.q d = x :: r) : + K0Part.enter s d = { s with q := K0Part.upd s.q d r, cur := some (x, false) } := by + simp [K0Part.enter, h] + +/-- A new tick that leaves the running domain `d`: afterwards `d`'s queue + holds, parked, the `K0Share` state `onTick` gives. -/ +theorem tick_leave (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) {s : K0Part.St} + {k : K0Share.St} (n : Nat) (h : Rel lab s k) (hn : s.part.seen < n) + (hd : (s.part.advance n).domNow n ≠ s.rd) : + Parked lab (K0Part.step dom s (.tick n)) s.rd (K0Share.onTick P k) := by + have hd' : s.rd ≠ (s.part.advance n).domNow n := fun e => hd e.symm + have h1 : Rel lab (clocked s n) k := h + obtain ⟨hex, hq⟩ := (cut_parked lab P h1).2 + refine ⟨hex, ?_⟩ + rw [← hq, step_tick_other dom s n _ hn rfl hd'] + have e : (K0Part.enter (K0Part.serve + { K0Part.cut (clocked s n) with rd := (s.part.advance n).domNow n } + ((s.part.advance n).domNow n) n) ((s.part.advance n).domNow n)).q s.rd = + (K0Part.cut (clocked s n)).q s.rd := by + unfold K0Part.enter + split <;> simp [K0Part.serve, K0Part.upd, hd'] + rw [e] + rfl + +/-- A new tick that opens the window of a parked domain `d`: the head of `d`'s + queue runs without the mark, and the wakes of `serve` come after it. + Side conditions as in `serve_wakes`. -/ +theorem tick_return (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s : K0Part.St} + {k : K0Share.St} (n : Nat) (d : Dom) (h : Parked lab s d k) (hn : s.part.seen < n) + (hd : (s.part.advance n).domNow n = d) (hrd : s.rd ≠ d) + (hne : ∀ t ∈ woken s d n, lab t ≠ 0) + (hcap : k.q.length + (woken s d n).length + 1 ≤ N) : + Rel lab (K0Part.step dom s (.tick n)) (K0Share.exec N P k (wakes lab (woken s d n))) := by + have hrd' : ¬ d = s.rd := fun e => hrd e.symm + obtain ⟨hex, hq⟩ := h + rw [exec_wakes lab N P _ k hne hcap, step_tick_other dom s n d hn hd hrd] + cases hq' : s.q d with + | nil => simp [hq'] at hq + | cons x r => + rw [hq'] at hq + simp only [List.map_cons, List.cons.injEq] at hq + have hcq : (K0Part.cut (clocked s n)).q d = x :: r := by + rw [← hq'] + unfold K0Part.cut + split + · rfl + · simp [K0Part.upd, hrd', clocked] + have hcw : (K0Part.cut (clocked s n)).wl d = s.wl d := by + unfold K0Part.cut + split <;> rfl + have hw : woken { K0Part.cut (clocked s n) with rd := d } d n = woken s d n := + woken_congr n hcw + have hsq : (K0Part.serve { K0Part.cut (clocked s n) with rd := d } d n).q d + = x :: (r ++ woken s d n) := by + rw [serve_q, hw] + show (K0Part.cut (clocked s n)).q d ++ _ = _ + rw [hcq] + rfl + rw [enter_cons _ d x _ hsq] + refine ⟨x, ?_, hq.1, ?_⟩ + · show some (x, false) = some (x, k.ex) + rw [hex] + · show (K0Part.upd _ d (r ++ woken s d n) d).map lab = k.q ++ (woken s d n).map lab + rw [K0Part.upd_same, List.map_append, hq.2] + +/-- A new tick leaves the queue of a domain alone when that domain neither + runs before the tick nor after it. -/ +theorem tick_other_q (dom : Tid → Dom) (s : K0Part.St) (d : Dom) (n : Nat) + (hn : s.part.seen < n) (hrd : s.rd ≠ d) (hstay : (K0Part.step dom s (.tick n)).rd ≠ d) : + (K0Part.step dom s (.tick n)).q d = s.q d := by + by_cases hd : (s.part.advance n).domNow n = s.rd + · rw [step_tick_same dom s n hn hd] + have h1 := K0Part.serve_R0_other (clocked s n) s.rd n d hrd + have h2 := K0Part.sameStep_R0_other (K0Part.serve (clocked s n) s.rd n) d hrd + exact (h1.trans h2).q.symm + · have hd' : s.rd ≠ (s.part.advance n).domNow n := fun e => hd e.symm + rw [step_tick_other dom s n _ hn rfl hd'] at hstay ⊢ + have hnew : (s.part.advance n).domNow n ≠ d := by simpa using hstay + have h1 := K0Part.cut_R0_other (clocked s n) d hrd + have h2 := K0Part.serve_R0_other + { K0Part.cut (clocked s n) with rd := (s.part.advance n).domNow n } + ((s.part.advance n).domNow n) n d hnew + have h3 := K0Part.enter_R0_other (K0Part.serve + { K0Part.cut (clocked s n) with rd := (s.part.advance n).domNow n } + ((s.part.advance n).domNow n) n) ((s.part.advance n).domNow n) d hnew + exact ((h2.trans h3).q.symm).trans h1.q.symm + +/-- While its window is closed, the parked picture of `d` does not change: an + event of another domain's window that is not a wake across domains into + `d` and does not open `d`'s window leaves it as it is. -/ +theorem parked_keep (dom : Tid → Dom) (lab : Tid → Nat) {s : K0Part.St} {k : K0Share.St} + {d : Dom} (hi : K0Part.Inv dom s) (h : Parked lab s d k) (hrd : s.rd ≠ d) (e : K0Part.Ev) + (hnc : K0Part.NoCross dom d e) (hstay : (K0Part.step dom s e).rd ≠ d) : + Parked lab (K0Part.step dom s e) d k := by + have hq : (K0Part.step dom s e).q d = s.q d := by + by_cases hc : K0Part.clockEv s e + · cases e with + | tick n => exact tick_other_q dom s d n hc hrd hstay + | poll n => + have hn : s.part.seen < n := hc + rw [K0Part.poll_eq_tick dom s n hn] at hstay ⊢ + exact tick_other_q dom s d n hn hrd hstay + | setTable t => rfl + | yield => exact absurd hc (fun hf => hf) + | block dl => exact absurd hc (fun hf => hf) + | wake t => exact absurd hc (fun hf => hf) + | wakeX t => exact absurd hc (fun hf => hf) + · exact (K0Part.local_R0_other hi hrd e hc hnc).q.symm + exact ⟨h.1, by rw [hq]; exact h.2⟩ + +/-- `d` stays closed along the events, and none of them is a wake across + domains into `d`. -/ +def Away (dom : Tid → Dom) (d : Dom) : K0Part.St → List K0Part.Ev → Prop + | _, [] => True + | s, e :: es => + K0Part.NoCross dom d e ∧ (K0Part.step dom s e).rd ≠ d ∧ Away dom d (K0Part.step dom s e) es + +instance awayDec (dom : Tid → Dom) (d : Dom) : + (es : List K0Part.Ev) → (s : K0Part.St) → Decidable (Away dom d s es) + | [], _ => isTrue trivial + | e :: es, s => + have : Decidable (Away dom d (K0Part.step dom s e) es) := awayDec dom d es _ + inferInstanceAs (Decidable (K0Part.NoCross dom d e ∧ (K0Part.step dom s e).rd ≠ d ∧ + Away dom d (K0Part.step dom s e) es)) + +theorem parked_run (dom : Tid → Dom) (lab : Tid → Nat) {k : K0Share.St} {d : Dom} : + ∀ (es : List K0Part.Ev) (s : K0Part.St), K0Part.Inv dom s → Parked lab s d k → s.rd ≠ d → + Away dom d s es → + Parked lab (K0Part.exec dom s es) d k ∧ (K0Part.exec dom s es).rd ≠ d := by + intro es + induction es with + | nil => intro s _ h hrd _; exact ⟨h, hrd⟩ + | cons e es ih => + intro s hi h hrd ha + exact ih _ (K0Part.inv_step s hi e) (parked_keep dom lab hi h hrd e ha.1 ha.2.1) ha.2.1 ha.2.2 + +/-- ONE WINDOW BOUNDARY, in full. Domain `s.rd` runs and looks like `k`. A + new tick `n1` closes its window; then come any events `es` during which + the window stays closed and nothing wakes across domains into it; then a + new tick `n2` opens the window again. At that point the domain looks like + `K0Share.onTick P k` followed by the wakes `serve` does at `n2`: the + boundary is one tick of the domain's own timeline, whatever the other + domains did. The mark of a task parked with it is gone, not kept for + later. Side conditions as in `serve_wakes`. + Not claimed: anything about the number of steps the domain gets. -/ +theorem window_cycle (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) {s s2 : K0Part.St} + {k : K0Share.St} (hi : K0Part.Inv dom s) (h : Rel lab s k) + (n1 : Nat) (hn1 : s.part.seen < n1) (hleave : (s.part.advance n1).domNow n1 ≠ s.rd) + (es : List K0Part.Ev) (haway : Away dom s.rd (K0Part.step dom s (.tick n1)) es) + (hs2 : s2 = K0Part.exec dom (K0Part.step dom s (.tick n1)) es) + (n2 : Nat) (hn2 : s2.part.seen < n2) (hback : (s2.part.advance n2).domNow n2 = s.rd) + (hne : ∀ t ∈ woken s2 s.rd n2, lab t ≠ 0) + (hcap : k.q.length + (woken s2 s.rd n2).length + 1 ≤ N) : + Rel lab (K0Part.step dom s2 (.tick n2)) + (K0Share.exec N P (K0Share.onTick P k) (wakes lab (woken s2 s.rd n2))) := by + have h1 := tick_leave dom lab P n1 h hn1 hleave + have hrd1 : (K0Part.step dom s (.tick n1)).rd ≠ s.rd := by + have hd' : s.rd ≠ (s.part.advance n1).domNow n1 := fun e => hleave e.symm + rw [step_tick_other dom s n1 _ hn1 rfl hd'] + simpa using hleave + obtain ⟨h2, hrd2⟩ := parked_run dom lab es _ (K0Part.inv_step s hi (.tick n1)) h1 hrd1 haway + rw [← hs2] at h2 hrd2 + exact tick_return dom lab N P n2 s.rd h2 hn2 hback hrd2 hne + (by rw [onTick_q_length]; exact hcap) + +/-! ## One domain, run level + +`K0Part` has ticks as indexes and no time between them. `K0Share` counts +steps, and a tick falls every `P` steps. To compare runs, the bridge adds +what `K0Part` lacks: a step `pass` in which time passes and no tick falls, a +countdown to the next tick, and two counters. None of this is in `K0Part`. -/ + +/-- A table that names domain `d` only, and has at least one tick. -/ +def Names (d : Dom) (t : K0Part.Table) : Prop := + (∀ e ∈ t, e.1 = d) ∧ 0 < K0Part.cycle t + +instance (d : Dom) (t : K0Part.Table) : Decidable (Names d t) := + inferInstanceAs (Decidable ((∀ e ∈ t, e.1 = d) ∧ 0 < K0Part.cycle t)) + +/-- The table in force and the pending table, if there is one, name `d` only. -/ +def PartOne (d : Dom) (p : K0Part.Part) : Prop := + Names d p.tbl ∧ ∀ st t, p.pend = some (st, t) → Names d t + +theorem names_domAtPos (d : Dom) : ∀ (t : K0Part.Table) (p : Nat), + (∀ e ∈ t, e.1 = d) → p < K0Part.cycle t → K0Part.domAtPos t p = d := by + intro t + induction t with + | nil => intro p _ hp; simp [K0Part.cycle] at hp + | cons e r ih => + intro p hall hp + obtain ⟨d', l⟩ := e + simp only [K0Part.cycle] at hp + simp only [K0Part.domAtPos] + split + · exact hall (d', l) (by simp) + · exact ih (p - l) (fun e he => hall e (by simp [he])) (by omega) + +/-- Such a table gives `d` at every tick. -/ +theorem names_domAt {d : Dom} {t : K0Part.Table} (h : Names d t) (j : Nat) : + K0Part.domAt t j = d := + names_domAtPos d t _ h.1 (Nat.mod_lt _ h.2) + +/-- With one domain named, every new tick stays in it. -/ +theorem partOne_domNow {d : Dom} {p : K0Part.Part} (h : PartOne d p) (n : Nat) : + (p.advance n).domNow n = d := by + unfold K0Part.Part.advance K0Part.Part.domNow + rcases hp : p.pend with _ | ⟨st, t⟩ + · exact names_domAt h.1 _ + · by_cases hs : st ≤ n + · simp only [hs, ite_true] + exact names_domAt (h.2 st t hp) _ + · simp only [hs, ite_false] + exact names_domAt h.1 _ + +theorem partOne_tick {d : Dom} {p : K0Part.Part} (h : PartOne d p) (n : Nat) : + PartOne d { p.advance n with seen := n } := by + unfold K0Part.Part.advance + rcases hp : p.pend with _ | ⟨st, t⟩ + · refine ⟨h.1, ?_⟩ + intro st t ht + simp [hp] at ht + · by_cases hs : st ≤ n + · simp only [hs, ite_true] + refine ⟨h.2 st t hp, ?_⟩ + intro st' t' ht + simp at ht + · simp only [hs, ite_false] + refine ⟨h.1, ?_⟩ + intro st' t' ht + exact h.2 st' t' ht + +theorem partOne_setTable {d : Dom} {p : K0Part.Part} (h : PartOne d p) {t : K0Part.Table} + (ht : Names d t) : PartOne d (p.setTable t) := by + refine ⟨h.1, ?_⟩ + intro st t' he + simp only [K0Part.Part.setTable, Option.some.injEq, Prod.mk.injEq] at he + rw [← he.2]; exact ht + +/-- One step of a timed run: time passes and no tick falls, or an event of + `K0Part`. A `tick` event is the step of time at whose end the tick falls; + every other event takes no time. -/ +inductive TEv where + | pass + | ev (e : K0Part.Ev) +deriving DecidableEq + +/-- A `K0Part` state with the clock of the bridge: `c` steps are left until + the next tick (the tick falls at the end of the step that finds `c = 1`), + `time` steps have passed, and in `ran` of them the running task of the + `K0Part` state had label 0. -/ +structure TSt where + s : K0Part.St + c : Nat + time : Nat + ran : Nat + +/-- 1 if the running task of `s` has label 0 (the spinner runs), else 0. -/ +def spin (lab : Tid → Nat) (s : K0Part.St) : Nat := + match s.cur with + | some (t, _) => if lab t = 0 then 1 else 0 + | none => 0 + +/-- One step of a timed run with period `P`. The `K0Part` state moves by + `K0Part.step` and by nothing else. Every `tick` event is charged one + step, also one with an old index; `OkRun` rules those out. -/ +def tstep (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) (x : TSt) : TEv → TSt + | .pass => { x with c := x.c - 1, time := x.time + 1, ran := x.ran + spin lab x.s } + | .ev (.tick n) => + { s := K0Part.step dom x.s (.tick n), c := P, time := x.time + 1, + ran := x.ran + spin lab x.s } + | .ev e => { x with s := K0Part.step dom x.s e } + +def texec (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) (x : TSt) : List TEv → TSt + | [] => x + | e :: es => texec dom lab P (tstep dom lab P x e) es + +/-- What a step may be in state `x`, for the run to be one that `K0Share` + describes. + * `pass` only inside a period, a `tick` only at its end, with an index not + seen before. Together: a tick every `P` steps. + * The spinner never yields and never blocks. + * No `poll` (the kernel does not call it while a task runs). + * `set_table` only with a table that names the running domain only. -/ +def OkEv (lab : Tid → Nat) (x : TSt) : TEv → Prop + | .pass => 1 < x.c + | .ev (.tick n) => x.c = 1 ∧ x.s.part.seen < n + | .ev (.poll _) => False + | .ev .yield => spin lab x.s = 0 + | .ev (.block _) => spin lab x.s = 0 + | .ev (.wake _) => True + | .ev (.wakeX _) => True + | .ev (.setTable t) => Names x.s.rd t + +/-- Every step of the run is allowed in the state it is taken in. -/ +def OkRun (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) : TSt → List TEv → Prop + | _, [] => True + | x, e :: es => OkEv lab x e ∧ OkRun dom lab P (tstep dom lab P x e) es + +instance okEvDec (lab : Tid → Nat) (x : TSt) : (e : TEv) → Decidable (OkEv lab x e) + | .pass => inferInstanceAs (Decidable (1 < x.c)) + | .ev (.tick n) => inferInstanceAs (Decidable (x.c = 1 ∧ x.s.part.seen < n)) + | .ev (.poll _) => inferInstanceAs (Decidable False) + | .ev .yield => inferInstanceAs (Decidable (spin lab x.s = 0)) + | .ev (.block _) => inferInstanceAs (Decidable (spin lab x.s = 0)) + | .ev (.wake _) => inferInstanceAs (Decidable True) + | .ev (.wakeX _) => inferInstanceAs (Decidable True) + | .ev (.setTable t) => inferInstanceAs (Decidable (Names x.s.rd t)) + +instance okRunDec (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) : + (es : List TEv) → (x : TSt) → Decidable (OkRun dom lab P x es) + | [], _ => isTrue trivial + | e :: es, x => + match okEvDec lab x e, okRunDec dom lab P es (tstep dom lab P x e) with + | isTrue h1, isTrue h2 => isTrue ⟨h1, h2⟩ + | isFalse h1, _ => isFalse (fun h => h1 h.1) + | _, isFalse h2 => isFalse (fun h => h2 h.2) + +/-- The `K0Share` events one step of a timed run projects onto. They depend + on the `K0Part` state: a new tick is the wakes of `serve` and then `run`; + a wake of a task that does not wait in the running domain is nothing. -/ +def tr (dom : Tid → Dom) (lab : Tid → Nat) (s : K0Part.St) : TEv → List K0Share.Ev + | .pass => [.run] + | .ev (.tick n) => wakes lab (woken s s.rd n) ++ [.run] + | .ev .yield => [.yield] + | .ev (.block _) => [.block] + | .ev (.wake t) => + if dom t = s.rd ∧ (s.wl s.rd).any (fun w => decide (w.1 = t)) = true then [.wake (lab t)] + else [] + | .ev _ => [] + +/-- The `K0Share` behaviour a timed run projects onto, step after step. -/ +def trRun (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) : TSt → List TEv → List K0Share.Ev + | _, [] => [] + | x, e :: es => tr dom lab x.s e ++ trRun dom lab P (tstep dom lab P x e) es + +/-! ### Small facts used by the simulation -/ + +theorem filter_split_length {α : Type} (p : α → Bool) : ∀ (l : List α), + (l.filter p).length + (l.filter (fun a => !p a)).length = l.length := by + intro l + induction l with + | nil => rfl + | cons a l ih => + cases h : p a with + | true => + have h1 : (a :: l).filter p = a :: l.filter p := List.filter_cons_of_pos h + have h2 : (a :: l).filter (fun a => !p a) = l.filter (fun a => !p a) := + List.filter_cons_of_neg (by simp [h]) + rw [h1, h2] + simp only [List.length_cons] + omega + | false => + have h1 : (a :: l).filter p = l.filter p := List.filter_cons_of_neg (by simp [h]) + have h2 : (a :: l).filter (fun a => !p a) = a :: l.filter (fun a => !p a) := + List.filter_cons_of_pos (by simp [h]) + rw [h1, h2] + simp only [List.length_cons] + omega + +theorem filter_length_lt {α : Type} (p : α → Bool) : ∀ (l : List α), + (∃ a ∈ l, p a = false) → (l.filter p).length < l.length := by + intro l + induction l with + | nil => rintro ⟨a, ha, -⟩; simp at ha + | cons b l ih => + rintro ⟨a, ha, hpa⟩ + have hle : (l.filter p).length ≤ l.length := List.length_filter_le p l + cases hb : p b with + | false => + have h1 : (b :: l).filter p = l.filter p := List.filter_cons_of_neg (by simp [hb]) + rw [h1] + simp only [List.length_cons] + omega + | true => + have hal : a ∈ l := by + rcases List.mem_cons.mp ha with rfl | h + · rw [hb] at hpa; cases hpa + · exact h + have := ih ⟨a, hal, hpa⟩ + have h1 : (b :: l).filter p = b :: l.filter p := List.filter_cons_of_pos hb + rw [h1] + simp only [List.length_cons] + omega + +/-- `serve` moves each waiter to the queue or keeps it: nothing is lost or made. -/ +theorem woken_length (s : K0Part.St) (d n : Nat) : + (woken s d n).length + ((s.wl d).filter (fun w => !K0Part.expired w n)).length + = (s.wl d).length := by + simp only [woken, List.length_map, List.length_reverse] + exact filter_split_length _ _ + +theorem mem_woken {s : K0Part.St} {d n : Nat} {t : Tid} (h : t ∈ woken s d n) : + ∃ w ∈ s.wl d, w.1 = t := by + simp only [woken, List.mem_map, List.mem_reverse, List.mem_filter] at h + obtain ⟨w, ⟨hw, -⟩, rfl⟩ := h + exact ⟨w, hw, rfl⟩ + +theorem sameStep_wl (s : K0Part.St) : (K0Part.sameStep s).wl = s.wl := by + unfold K0Part.sameStep + split + · rfl + · split <;> rfl + · unfold K0Part.enter; split <;> rfl + +theorem tick_same_rd (dom : Tid → Dom) (s : K0Part.St) (n : Nat) (hn : s.part.seen < n) + (hd : (s.part.advance n).domNow n = s.rd) : (K0Part.step dom s (.tick n)).rd = s.rd := by + rw [step_tick_same dom s n hn hd] + simp [clocked] + +theorem tick_same_wl (dom : Tid → Dom) (s : K0Part.St) (n : Nat) (hn : s.part.seen < n) + (hd : (s.part.advance n).domNow n = s.rd) : + (K0Part.step dom s (.tick n)).wl s.rd + = (s.wl s.rd).filter (fun w => !K0Part.expired w n) := by + rw [step_tick_same dom s n hn hd, sameStep_wl] + simp [K0Part.serve, K0Part.upd, clocked] + +theorem yield_wl (dom : Tid → Dom) (s : K0Part.St) : (K0Part.step dom s .yield).wl = s.wl := by + show (K0Part.yieldStep s).wl = s.wl + unfold K0Part.yieldStep + split + · rfl + · split <;> rfl + +theorem popBetween_wl (s : K0Part.St) : (K0Part.popBetween s).wl = s.wl := by + unfold K0Part.popBetween; split <;> rfl + +theorem block_wl (dom : Tid → Dom) {s : K0Part.St} {c : Tid} {ex : Bool} (dl : Option Nat) + (hc : s.cur = some (c, ex)) (hd : dom c = s.rd) : + (K0Part.step dom s (.block dl)).wl s.rd = s.wl s.rd ++ [(c, dl)] := by + show (K0Part.blockStep dom s dl).wl s.rd = _ + simp only [K0Part.blockStep, hc] + rw [popBetween_wl] + simp [K0Part.upd, hd] + +theorem wake_eq (dom : Tid → Dom) {s : K0Part.St} (t : Tid) (hc : s.cur.isSome = true) + (hd : dom t = s.rd) (hany : (s.wl s.rd).any (fun w => decide (w.1 = t)) = true) : + K0Part.step dom s (.wake t) = + { s with wl := K0Part.upd s.wl s.rd ((s.wl s.rd).filter (fun w => !decide (w.1 = t))), + q := K0Part.upd s.q s.rd (s.q s.rd ++ [t]) } := by + simp [K0Part.step, K0Part.doWake, hc, hd, hany] + +theorem wake_noop (dom : Tid → Dom) (s : K0Part.St) (t : Tid) + (h : ¬ (dom t = s.rd ∧ (s.wl s.rd).any (fun w => decide (w.1 = t)) = true)) : + K0Part.step dom s (.wake t) = s := by + by_cases hd : dom t = s.rd + · have hany : (s.wl s.rd).any (fun w => decide (w.1 = t)) = false := by + cases hb : (s.wl s.rd).any (fun w => decide (w.1 = t)) with + | false => rfl + | true => exact absurd ⟨hd, hb⟩ h + simp [K0Part.step, K0Part.doWake, hd, hany] + · simp [K0Part.step, hd] + +/-- A wake across domains leaves the running task and the running domain's + queue and waiting list alone. -/ +theorem wakeX_frame (dom : Tid → Dom) (s : K0Part.St) (t : Tid) : + (K0Part.step dom s (.wakeX t)).cur = s.cur ∧ + K0Part.R0 s.rd s (K0Part.step dom s (.wakeX t)) := by + simp only [K0Part.step] + split + · next hg => + refine ⟨?_, K0Part.doWake_R0_other s t s.rd hg.2⟩ + unfold K0Part.doWake; split <;> rfl + · exact ⟨rfl, K0Part.R0.refl _ _⟩ + +theorem run_pass_frame (N P : Nat) (k : K0Share.St) (hc : 1 < k.c) : + (K0Share.step N P k .run).c = k.c - 1 ∧ (K0Share.step N P k .run).time = k.time + 1 ∧ + (K0Share.step N P k .run).ran = k.ran + (if k.cur = 0 then 1 else 0) ∧ + (K0Share.step N P k .run).q = k.q := by + have hc' : ¬ k.c ≤ 1 := by omega + simp [K0Share.step, K0Share.runStep, hc'] + +theorem run_tick_frame (N P : Nat) (k : K0Share.St) (hc : k.c ≤ 1) : + (K0Share.step N P k .run).c = P ∧ (K0Share.step N P k .run).time = k.time + 1 ∧ + (K0Share.step N P k .run).ran = k.ran + (if k.cur = 0 then 1 else 0) ∧ + (K0Share.step N P k .run).q.length = k.q.length := by + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at hc + cases kex with + | true => simp [K0Share.step, K0Share.runStep, K0Share.onTick, hc] + | false => cases kq <;> simp [K0Share.step, K0Share.runStep, K0Share.onTick, hc] + +theorem yield_frame (N P : Nat) (k : K0Share.St) : + (K0Share.step N P k .yield).c = k.c ∧ (K0Share.step N P k .yield).time = k.time ∧ + (K0Share.step N P k .yield).ran = k.ran ∧ + (K0Share.step N P k .yield).q.length = k.q.length := by + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + by_cases h0 : kc = 0 + · simp [K0Share.step, h0] + · cases kq <;> simp [K0Share.step, h0] + +theorem block_frame (N P : Nat) (k : K0Share.St) (h0 : k.cur ≠ 0) (hq : k.q ≠ []) : + (K0Share.step N P k .block).c = k.c ∧ (K0Share.step N P k .block).time = k.time ∧ + (K0Share.step N P k .block).ran = k.ran ∧ + (K0Share.step N P k .block).q.length + 1 = k.q.length := by + obtain ⟨kc, kex, kq, kcd, kage, ktime, kran⟩ := k + simp only at h0 hq + cases kq with + | nil => exact absurd rfl hq + | cons a r => simp [K0Share.step, h0] + +/-- In a well-formed `K0Share` state where the spinner does not run, the + spinner is ready, so the queue is not empty. This is why the domain never + idles in the runs below. -/ +theorem wf_queue_ne {N P : Nat} {k : K0Share.St} (hw : K0Share.Wf N P k) (hc : k.cur ≠ 0) : + k.q ≠ [] := by + intro he + have h3 := hw.2.2.1 + rw [he] at h3 + simp [hc] at h3 + +theorem spin_eq {lab : Tid → Nat} {s : K0Part.St} {k : K0Share.St} (h : Rel lab s k) : + spin lab s = if k.cur = 0 then 1 else 0 := by + obtain ⟨c, hc, hl, -⟩ := h + simp [spin, hc, hl] + +/-! ### The simulation -/ + +/-- The invariant of the simulation. The timed state `x` and the `K0Share` + state `k` agree on the projection, on the countdown and on both counters; + `k` is well formed; the table names the running domain only; no task with + label 0 waits; and the tasks of the running domain, ready, running or + waiting, are at most `N`. -/ +structure Sim (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) (x : TSt) (k : K0Share.St) : + Prop where + rel : Rel lab x.s k + c : k.c = x.c + time : k.time = x.time + ran : k.ran = x.ran + wf : K0Share.Wf N P k + inv : K0Part.Inv dom x.s + one : PartOne x.s.rd x.s.part + waiters : ∀ w ∈ x.s.wl x.s.rd, lab w.1 ≠ 0 + cap : k.q.length + (x.s.wl x.s.rd).length + 1 ≤ N + +section sim +variable {dom : Tid → Dom} {lab : Tid → Nat} {N P : Nat} {x : TSt} {k : K0Share.St} + +theorem sim_pass (h : Sim dom lab N P x k) (hc : 1 < x.c) : + Sim dom lab N P (tstep dom lab P x .pass) (K0Share.exec N P k [.run]) := by + have hk : 1 < k.c := by rw [h.c]; exact hc + obtain ⟨f1, f2, f3, f4⟩ := run_pass_frame N P k hk + refine ⟨run_pass lab N P h.rel hk, ?_, ?_, ?_, (K0Share.step_pot N P k h.wf .run).1, + h.inv, h.one, h.waiters, ?_⟩ + · show (K0Share.step N P k .run).c = x.c - 1 + rw [f1, h.c] + · show (K0Share.step N P k .run).time = x.time + 1 + rw [f2, h.time] + · show (K0Share.step N P k .run).ran = x.ran + spin lab x.s + rw [f3, h.ran, spin_eq h.rel] + · show (K0Share.step N P k .run).q.length + (x.s.wl x.s.rd).length + 1 ≤ N + rw [f4]; exact h.cap + +theorem sim_tick (h : Sim dom lab N P x k) (n : Nat) (hc : x.c = 1) + (hn : x.s.part.seen < n) : + Sim dom lab N P (tstep dom lab P x (.ev (.tick n))) + (K0Share.exec N P k (wakes lab (woken x.s x.s.rd n) ++ [.run])) := by + have hd := partOne_domNow h.one n + have hne : ∀ t ∈ woken x.s x.s.rd n, lab t ≠ 0 := by + intro t ht + obtain ⟨w, hw, rfl⟩ := mem_woken ht + exact h.waiters w hw + have hlen := woken_length x.s x.s.rd n + have hcap : k.q.length + (woken x.s x.s.rd n).length + 1 ≤ N := by + have := h.cap; omega + have hk : k.c ≤ 1 := by rw [h.c, hc]; exact Nat.le_refl 1 + have hw := exec_wakes lab N P _ k hne hcap + have hk1 : (K0Share.exec N P k (wakes lab (woken x.s x.s.rd n))).c ≤ 1 := by + rw [hw]; exact hk + obtain ⟨f1, f2, f3, f4⟩ := run_tick_frame N P _ hk1 + have hrd := tick_same_rd dom x.s n hn hd + have e : K0Share.exec N P k (wakes lab (woken x.s x.s.rd n) ++ [.run]) = + K0Share.step N P (K0Share.exec N P k (wakes lab (woken x.s x.s.rd n))) .run := + exec_append N P _ _ k + refine ⟨tick_same_run dom lab N P n h.rel hn hd hne hcap hk, ?_, ?_, ?_, + (K0Share.exec_pot N P _ k h.wf).1, K0Part.inv_step x.s h.inv (.tick n), ?_, ?_, ?_⟩ + · show (K0Share.exec N P k (wakes lab (woken x.s x.s.rd n) ++ [.run])).c = P + rw [e, f1] + · show (K0Share.exec N P k (wakes lab (woken x.s x.s.rd n) ++ [.run])).time = x.time + 1 + rw [e, f2, hw] + show k.time + 1 = x.time + 1 + rw [h.time] + · show (K0Share.exec N P k (wakes lab (woken x.s x.s.rd n) ++ [.run])).ran + = x.ran + spin lab x.s + rw [e, f3, hw, spin_eq h.rel] + show k.ran + _ = x.ran + _ + rw [h.ran] + · show PartOne (K0Part.step dom x.s (.tick n)).rd (K0Part.step dom x.s (.tick n)).part + have hn' : ¬ n ≤ x.s.part.seen := by omega + rw [hrd, K0Part.step_part] + simp only [K0Part.pstep, K0Part.pTick, hn', ite_false] + exact partOne_tick h.one n + · intro w hw' + have hw2 : w ∈ (K0Part.step dom x.s (.tick n)).wl x.s.rd := by + rw [← hrd]; exact hw' + rw [tick_same_wl dom x.s n hn hd] at hw2 + exact h.waiters w (List.mem_filter.mp hw2).1 + · show (K0Share.exec N P k (wakes lab (woken x.s x.s.rd n) ++ [.run])).q.length + + ((K0Part.step dom x.s (.tick n)).wl (K0Part.step dom x.s (.tick n)).rd).length + 1 ≤ N + rw [e, f4, hw, hrd, tick_same_wl dom x.s n hn hd] + show (k.q ++ (woken x.s x.s.rd n).map lab).length + _ + 1 ≤ N + simp only [List.length_append, List.length_map] + have := h.cap + omega + +theorem sim_yield (h : Sim dom lab N P x k) (hs : spin lab x.s = 0) : + Sim dom lab N P (tstep dom lab P x (.ev .yield)) (K0Share.exec N P k [.yield]) := by + have hsp : k.cur ≠ 0 := by + intro e; rw [spin_eq h.rel, e] at hs; simp at hs + obtain ⟨f1, f2, f3, f4⟩ := yield_frame N P k + have hrd : (K0Part.step dom x.s .yield).rd = x.s.rd := K0Part.step_rd_pub_free dom x.s .yield rfl + have hpt : (K0Part.step dom x.s .yield).part = x.s.part := K0Part.step_part dom x.s .yield + have hwl := yield_wl dom x.s + refine ⟨yield_step dom lab N P h.rel hsp, ?_, ?_, ?_, (K0Share.step_pot N P k h.wf .yield).1, + K0Part.inv_step x.s h.inv .yield, ?_, ?_, ?_⟩ + · show (K0Share.step N P k .yield).c = x.c + rw [f1, h.c] + · show (K0Share.step N P k .yield).time = x.time + rw [f2, h.time] + · show (K0Share.step N P k .yield).ran = x.ran + rw [f3, h.ran] + · show PartOne (K0Part.step dom x.s .yield).rd (K0Part.step dom x.s .yield).part + rw [hrd, hpt]; exact h.one + · show ∀ w ∈ (K0Part.step dom x.s .yield).wl (K0Part.step dom x.s .yield).rd, lab w.1 ≠ 0 + rw [hrd, hwl]; exact h.waiters + · show (K0Share.step N P k .yield).q.length + + ((K0Part.step dom x.s .yield).wl (K0Part.step dom x.s .yield).rd).length + 1 ≤ N + rw [f4, hrd, hwl]; exact h.cap + +theorem sim_block (h : Sim dom lab N P x k) (dl : Option Nat) (hs : spin lab x.s = 0) : + Sim dom lab N P (tstep dom lab P x (.ev (.block dl))) (K0Share.exec N P k [.block]) := by + have hsp : k.cur ≠ 0 := by + intro e; rw [spin_eq h.rel, e] at hs; simp at hs + have hq := wf_queue_ne h.wf hsp + obtain ⟨f1, f2, f3, f4⟩ := block_frame N P k hsp hq + obtain ⟨c0, hcur, hlab, -⟩ := h.rel + have hrd : (K0Part.step dom x.s (.block dl)).rd = x.s.rd := + K0Part.step_rd_pub_free dom x.s (.block dl) rfl + have hpt : (K0Part.step dom x.s (.block dl)).part = x.s.part := + K0Part.step_part dom x.s (.block dl) + have hwl := block_wl dom dl hcur (h.inv.cur_dom c0 k.ex hcur) + refine ⟨block_step dom lab N P dl h.rel hsp hq, ?_, ?_, ?_, + (K0Share.step_pot N P k h.wf .block).1, K0Part.inv_step x.s h.inv (.block dl), ?_, ?_, ?_⟩ + · show (K0Share.step N P k .block).c = x.c + rw [f1, h.c] + · show (K0Share.step N P k .block).time = x.time + rw [f2, h.time] + · show (K0Share.step N P k .block).ran = x.ran + rw [f3, h.ran] + · show PartOne (K0Part.step dom x.s (.block dl)).rd (K0Part.step dom x.s (.block dl)).part + rw [hrd, hpt]; exact h.one + · show ∀ w ∈ (K0Part.step dom x.s (.block dl)).wl (K0Part.step dom x.s (.block dl)).rd, + lab w.1 ≠ 0 + rw [hrd, hwl] + intro w hw + rcases List.mem_append.mp hw with h1 | h1 + · exact h.waiters w h1 + · simp only [List.mem_singleton] at h1 + rw [h1] + show lab c0 ≠ 0 + rw [hlab]; exact hsp + · show (K0Share.step N P k .block).q.length + + ((K0Part.step dom x.s (.block dl)).wl (K0Part.step dom x.s (.block dl)).rd).length + + 1 ≤ N + rw [hrd, hwl] + simp only [List.length_append, List.length_singleton] + have := h.cap + omega + +theorem sim_wake (h : Sim dom lab N P x k) (t : Tid) : + Sim dom lab N P (tstep dom lab P x (.ev (.wake t))) + (K0Share.exec N P k (tr dom lab x.s (.ev (.wake t)))) := by + obtain ⟨c0, hcur, hlab, hq0⟩ := h.rel + by_cases hg : dom t = x.s.rd ∧ (x.s.wl x.s.rd).any (fun w => decide (w.1 = t)) = true + · obtain ⟨hd, hany⟩ := hg + have htr : tr dom lab x.s (.ev (.wake t)) = [.wake (lab t)] := by + simp [tr, hd, hany] + obtain ⟨w, hw1, hw2⟩ := List.any_eq_true.mp hany + have hw2' : w.1 = t := by simpa using hw2 + have hne : lab t ≠ 0 := by rw [← hw2']; exact h.waiters w hw1 + have hpos : 0 < (x.s.wl x.s.rd).length := List.length_pos_of_mem hw1 + have hcap : k.q.length + 1 < N := by have := h.cap; omega + have hs : K0Share.step N P k (.wake (lab t)) = { k with q := k.q ++ [lab t] } := by + simp [K0Share.step, hne, K0Share.cnt, hcap] + have hsome : x.s.cur.isSome = true := by rw [hcur]; rfl + have he := wake_eq dom t hsome hd hany + have hlt : ((x.s.wl x.s.rd).filter (fun w => !decide (w.1 = t))).length + < (x.s.wl x.s.rd).length := + filter_length_lt _ _ ⟨w, hw1, by simp [hw2']⟩ + have hrd : (K0Part.step dom x.s (.wake t)).rd = x.s.rd := + K0Part.step_rd_pub_free dom x.s (.wake t) rfl + have hpt : (K0Part.step dom x.s (.wake t)).part = x.s.part := + K0Part.step_part dom x.s (.wake t) + have hwl : (K0Part.step dom x.s (.wake t)).wl x.s.rd + = (x.s.wl x.s.rd).filter (fun w => !decide (w.1 = t)) := by + rw [he]; exact K0Part.upd_same _ _ _ + rw [htr] + refine ⟨wake_step dom lab N P t h.rel hd ⟨w, hw1, hw2'⟩ hne hcap, ?_, ?_, ?_, + (K0Share.step_pot N P k h.wf (.wake (lab t))).1, + K0Part.inv_step x.s h.inv (.wake t), ?_, ?_, ?_⟩ + · show (K0Share.step N P k (.wake (lab t))).c = x.c + rw [hs]; exact h.c + · show (K0Share.step N P k (.wake (lab t))).time = x.time + rw [hs]; exact h.time + · show (K0Share.step N P k (.wake (lab t))).ran = x.ran + rw [hs]; exact h.ran + · show PartOne (K0Part.step dom x.s (.wake t)).rd (K0Part.step dom x.s (.wake t)).part + rw [hrd, hpt]; exact h.one + · show ∀ w ∈ (K0Part.step dom x.s (.wake t)).wl (K0Part.step dom x.s (.wake t)).rd, + lab w.1 ≠ 0 + rw [hrd, hwl] + intro w' hw' + exact h.waiters w' (List.mem_filter.mp hw').1 + · show (K0Share.step N P k (.wake (lab t))).q.length + + ((K0Part.step dom x.s (.wake t)).wl (K0Part.step dom x.s (.wake t)).rd).length + + 1 ≤ N + rw [hs, hrd, hwl] + show (k.q ++ [lab t]).length + _ + 1 ≤ N + simp only [List.length_append, List.length_singleton] + have := h.cap + omega + · have htr : tr dom lab x.s (.ev (.wake t)) = [] := by + simp only [tr, hg, ite_false] + have he := wake_noop dom x.s t hg + rw [htr] + show Sim dom lab N P { x with s := K0Part.step dom x.s (.wake t) } k + rw [he] + exact h + +theorem sim_wakeX (h : Sim dom lab N P x k) (t : Tid) : + Sim dom lab N P (tstep dom lab P x (.ev (.wakeX t))) (K0Share.exec N P k []) := by + obtain ⟨hcur, hr⟩ := wakeX_frame dom x.s t + obtain ⟨c0, hc0, hlab, hq0⟩ := h.rel + refine ⟨⟨c0, ?_, hlab, ?_⟩, h.c, h.time, h.ran, h.wf, K0Part.inv_step x.s h.inv (.wakeX t), + ?_, ?_, ?_⟩ + · show (K0Part.step dom x.s (.wakeX t)).cur = some (c0, k.ex) + rw [hcur]; exact hc0 + · show ((K0Part.step dom x.s (.wakeX t)).q (K0Part.step dom x.s (.wakeX t)).rd).map lab = k.q + rw [← hr.rd, ← hr.q]; exact hq0 + · show PartOne (K0Part.step dom x.s (.wakeX t)).rd (K0Part.step dom x.s (.wakeX t)).part + rw [← hr.rd, ← hr.part]; exact h.one + · show ∀ w ∈ (K0Part.step dom x.s (.wakeX t)).wl (K0Part.step dom x.s (.wakeX t)).rd, + lab w.1 ≠ 0 + rw [← hr.rd, ← hr.wl]; exact h.waiters + · show k.q.length + + ((K0Part.step dom x.s (.wakeX t)).wl (K0Part.step dom x.s (.wakeX t)).rd).length + + 1 ≤ N + rw [← hr.rd, ← hr.wl]; exact h.cap + +theorem sim_setTable (h : Sim dom lab N P x k) (t : K0Part.Table) (ht : Names x.s.rd t) : + Sim dom lab N P (tstep dom lab P x (.ev (.setTable t))) (K0Share.exec N P k []) := + ⟨h.rel, h.c, h.time, h.ran, h.wf, K0Part.inv_step x.s h.inv (.setTable t), + partOne_setTable h.one ht, h.waiters, h.cap⟩ + +/-- One allowed step of a timed run is matched by the `K0Share` events `tr` + gives for it, and the invariant holds again. -/ +theorem sim_step (h : Sim dom lab N P x k) (e : TEv) (hok : OkEv lab x e) : + Sim dom lab N P (tstep dom lab P x e) (K0Share.exec N P k (tr dom lab x.s e)) := by + cases e with + | pass => exact sim_pass h hok + | ev e => + cases e with + | tick n => exact sim_tick h n hok.1 hok.2 + | poll n => exact absurd hok (fun hf => hf) + | yield => exact sim_yield h hok + | block dl => exact sim_block h dl hok + | wake t => exact sim_wake h t + | wakeX t => exact sim_wakeX h t + | setTable t => exact sim_setTable h t hok + +end sim + +/-- The invariant along a whole allowed run. -/ +theorem sim_run (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) : + ∀ (es : List TEv) (x : TSt) (k : K0Share.St), Sim dom lab N P x k → + OkRun dom lab P x es → + Sim dom lab N P (texec dom lab P x es) (K0Share.exec N P k (trRun dom lab P x es)) := by + intro es + induction es with + | nil => intro x k h _; exact h + | cons e es ih => + intro x k h hok + show Sim dom lab N P (texec dom lab P (tstep dom lab P x e) es) + (K0Share.exec N P k (tr dom lab x.s e ++ trRun dom lab P (tstep dom lab P x e) es)) + rw [exec_append] + exact ih _ _ (sim_step h e hok.1) hok.2 + +/-! ### Statements for one domain -/ + +/-- The `K0Share` state a timed state starts from: the projection of `x.s`, + with the countdown and the counters of `x`. `age` is not compared; `P` + makes the state well formed whatever the mark is. -/ +def share0 (lab : Tid → Nat) (P : Nat) (x : TSt) : K0Share.St := + match x.s.cur with + | some (c, ex) => + { cur := lab c, ex := ex, q := (x.s.q x.s.rd).map lab, c := x.c, age := P, + time := x.time, ran := x.ran } + | none => { cur := 0, ex := false, q := [], c := x.c, age := P, time := x.time, ran := x.ran } + +/-- The start conditions, in `K0Part` terms. + * `inv`: the invariant of `K0Part`. + * `one`: the table in force and a pending table name the running domain only. + * `c_pos`, `c_le`: the countdown to the first tick is in `1..P`. + * `spinner`: a task runs, and exactly one task among the running one and the + ready ones of the running domain has label 0. + * `waiters`: no task with label 0 waits in the running domain. + * `cap`: the running domain has at most `N` tasks, ready, running or waiting. -/ +structure Start (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) (x : TSt) : Prop where + inv : K0Part.Inv dom x.s + one : PartOne x.s.rd x.s.part + c_pos : 1 ≤ x.c + c_le : x.c ≤ P + spinner : ∃ c ex, x.s.cur = some (c, ex) ∧ ((c :: x.s.q x.s.rd).map lab).count 0 = 1 + waiters : ∀ w ∈ x.s.wl x.s.rd, lab w.1 ≠ 0 + cap : (x.s.q x.s.rd).length + (x.s.wl x.s.rd).length + 1 ≤ N + +theorem start_sim {dom : Tid → Dom} {lab : Tid → Nat} {N P : Nat} {x : TSt} + (h : Start dom lab N P x) : Sim dom lab N P x (share0 lab P x) := by + obtain ⟨c, ex, hcur, hcount⟩ := h.spinner + have e : share0 lab P x = + { cur := lab c, ex := ex, q := (x.s.q x.s.rd).map lab, c := x.c, age := P, + time := x.time, ran := x.ran } := by + simp [share0, hcur] + rw [e] + refine ⟨⟨c, hcur, rfl, rfl⟩, rfl, rfl, rfl, ?_, h.inv, h.one, h.waiters, ?_⟩ + · refine ⟨h.c_pos, h.c_le, hcount, ?_, ?_⟩ + · have := h.cap + simp only [List.length_cons, List.length_map] + omega + · intro _; exact Nat.le_add_right _ _ + · simp only [List.length_map]; exact h.cap + +/-- Every prefix of an allowed run is an allowed run. -/ +theorem okRun_take (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) : + ∀ (es : List TEv) (x : TSt) (i : Nat), OkRun dom lab P x es → + OkRun dom lab P x (es.take i) := by + intro es + induction es with + | nil => intro x i _; simp [OkRun] + | cons e es ih => + intro x i hok + cases i with + | zero => exact trivial + | succ i => exact ⟨hok.1, ih _ i hok.2⟩ + +/-- The projection of a prefix is a prefix of the projection. -/ +theorem trRun_take (dom : Tid → Dom) (lab : Tid → Nat) (P : Nat) : + ∀ (es : List TEv) (x : TSt) (i : Nat), + trRun dom lab P x es = trRun dom lab P x (es.take i) + ++ trRun dom lab P (texec dom lab P x (es.take i)) (es.drop i) := by + intro es + induction es with + | nil => intro x i; simp [trRun, texec] + | cons e es ih => + intro x i + cases i with + | zero => rfl + | succ i => + show tr dom lab x.s e ++ trRun dom lab P (tstep dom lab P x e) es = + (tr dom lab x.s e ++ trRun dom lab P (tstep dom lab P x e) (es.take i)) + ++ trRun dom lab P (texec dom lab P (tstep dom lab P x e) (es.take i)) (es.drop i) + rw [List.append_assoc, ← ih] + +/-- RUN LEVEL. A timed run of `K0Part` that starts as `Start` says and is + allowed (`OkRun`: a tick every `P` steps, the spinner never yields or + blocks, no `poll`, tables of one domain) projects onto the `K0Share` + behaviour `trRun` builds from it: after the run the projection, the + countdown, the steps passed and the steps of the spinner are those of the + `K0Share` state. -/ +theorem run_projects (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) (x : TSt) + (hs : Start dom lab N P x) (es : List TEv) (hok : OkRun dom lab P x es) : + Rel lab (texec dom lab P x es).s + (K0Share.exec N P (share0 lab P x) (trRun dom lab P x es)) ∧ + (K0Share.exec N P (share0 lab P x) (trRun dom lab P x es)).c = (texec dom lab P x es).c ∧ + (K0Share.exec N P (share0 lab P x) (trRun dom lab P x es)).time + = (texec dom lab P x es).time ∧ + (K0Share.exec N P (share0 lab P x) (trRun dom lab P x es)).ran + = (texec dom lab P x es).ran := by + have h := sim_run dom lab N P es x _ (start_sim hs) hok + exact ⟨h.rel, h.c, h.time, h.ran⟩ + +/-- The same after every step: for each `i`, the first `i` steps of the run + project onto a prefix of the one `K0Share` behaviour `trRun x es`. -/ +theorem run_projects_prefix (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) (x : TSt) + (hs : Start dom lab N P x) (es : List TEv) (hok : OkRun dom lab P x es) (i : Nat) : + (∃ rest, trRun dom lab P x es = trRun dom lab P x (es.take i) ++ rest) ∧ + Rel lab (texec dom lab P x (es.take i)).s + (K0Share.exec N P (share0 lab P x) (trRun dom lab P x (es.take i))) ∧ + (K0Share.exec N P (share0 lab P x) (trRun dom lab P x (es.take i))).time + = (texec dom lab P x (es.take i)).time ∧ + (K0Share.exec N P (share0 lab P x) (trRun dom lab P x (es.take i))).ran + = (texec dom lab P x (es.take i)).ran := by + have h := run_projects dom lab N P x hs (es.take i) (okRun_take dom lab P es x i hok) + exact ⟨⟨_, trRun_take dom lab P es x i⟩, h.1, h.2.2.1, h.2.2.2⟩ + +/-- THE SHARE BOUND FOR ONE-DOMAIN TIMED RUNS OF `K0Part`. From a start as in + `Start` with both counters at 0, after any allowed run: the steps that + passed are at most `N` times the steps in which the task with label 0 was + the running task of the `K0Part` state, plus `(N - 1) * P` plus the + countdown to the first tick. This is `K0Share.share_bound` carried over + by `run_projects`. The steps, the countdown and the counters are those of + the bridge (`TSt`, `tstep`), not of `K0Part`. -/ +theorem timed_share_bound (dom : Tid → Dom) (lab : Tid → Nat) (N P : Nat) (x : TSt) + (hs : Start dom lab N P x) (ht : x.time = 0) (hr : x.ran = 0) (es : List TEv) + (hok : OkRun dom lab P x es) : + (texec dom lab P x es).time ≤ N * (texec dom lab P x es).ran + (N - 1) * P + x.c := by + have h0 := start_sim hs + have h := sim_run dom lab N P es x _ h0 hok + have hb := K0Share.share_bound N P (share0 lab P x) h0.wf (by rw [h0.time, ht]) + (by rw [h0.ran, hr]) (trRun dom lab P x es) + rw [h.time, h.ran, h0.c] at hb + exact hb + +/-- The timed state at boot: `K0Part.boot`, with `start` steps of the first + period already gone and both counters at 0. -/ +def tboot (now : Nat) (first : Tid) (q0 : Dom → List Tid) (w0 : Dom → List (Tid × Option Nat)) + (P start : Nat) : TSt := + { s := K0Part.boot now first q0 w0, c := P - start, time := 0, ran := 0 } + +/-- `Start` holds at boot (default table, domain 0) when the given queues and + waiting lists respect the domains, the first task is in domain 0, exactly + one of the first task and the ready tasks of domain 0 has label 0, no + waiting task of domain 0 has label 0, and domain 0 has at most `N` tasks. -/ +theorem start_boot (dom : Tid → Dom) (lab : Tid → Nat) (N P start now : Nat) (first : Tid) + (q0 : Dom → List Tid) (w0 : Dom → List (Tid × Option Nat)) + (hq : ∀ d t, t ∈ q0 d → dom t = d) (hw : ∀ d w, w ∈ w0 d → dom w.1 = d) + (hf : dom first = 0) (hs : start < P) + (h1 : ((first :: q0 0).map lab).count 0 = 1) (hw0 : ∀ w ∈ w0 0, lab w.1 ≠ 0) + (hN : (q0 0).length + (w0 0).length + 1 ≤ N) : + Start dom lab N P (tboot now first q0 w0 P start) := by + have hone : PartOne 0 (K0Part.boot now first q0 w0).part := by + refine ⟨⟨?_, ?_⟩, ?_⟩ + · intro e he + have he' : e = (0, 1) := by simpa [K0Part.boot, K0Part.defaultTable] using he + rw [he'] + · show 0 < K0Part.cycle K0Part.defaultTable + decide + · intro st t ht + simp [K0Part.boot] at ht + refine ⟨K0Part.inv_boot dom now first q0 w0 hq hw hf, hone, ?_, ?_, + ⟨first, true, rfl, h1⟩, hw0, hN⟩ + · show 1 ≤ P - start + omega + · show P - start ≤ P + omega + +/-- The share bound from boot, with the default table: as long as every + `set_table` call names domain 0 only. -/ +theorem boot_share_bound (dom : Tid → Dom) (lab : Tid → Nat) (N P start now : Nat) + (first : Tid) (q0 : Dom → List Tid) (w0 : Dom → List (Tid × Option Nat)) + (hq : ∀ d t, t ∈ q0 d → dom t = d) (hw : ∀ d w, w ∈ w0 d → dom w.1 = d) + (hf : dom first = 0) (hs : start < P) + (h1 : ((first :: q0 0).map lab).count 0 = 1) (hw0 : ∀ w ∈ w0 0, lab w.1 ≠ 0) + (hN : (q0 0).length + (w0 0).length + 1 ≤ N) + (es : List TEv) (hok : OkRun dom lab P (tboot now first q0 w0 P start) es) : + (texec dom lab P (tboot now first q0 w0 P start) es).time ≤ + N * (texec dom lab P (tboot now first q0 w0 P start) es).ran + (N - 1) * P + + (P - start) := + timed_share_bound dom lab N P _ + (start_boot dom lab N P start now first q0 w0 hq hw hf hs h1 hw0 hN) rfl rfl es hok + +/-! ## A concrete run: the hypotheses hold together + +Tasks 0, 1 and 2 are in domain 0 (`K0Part.dom0`). Labels are the ids, so +task 0 is the spinner. Period 2, at most 3 tasks, default table. -/ + +deriving instance DecidableEq for K0Share.Ev + +def exBoot : TSt := tboot 0 0 (fun d => if d = 0 then [1, 2] else []) (fun _ => []) 2 0 + +/-- Ticks 1 to 7 with a jump over tick 5, a yield, a timed block that expires + at tick 6, an untimed block and its wake, a wake of a task that does not + wait, a wake across domains, and a `set_table` that names domain 0. -/ +def exRun : List TEv := + [.pass, .ev (.tick 1), .pass, .ev (.tick 2), .ev .yield, .pass, .ev (.tick 3), + .ev (.block (some 6)), .ev (.setTable [(0, 3)]), .pass, .ev (.tick 4), .pass, + .ev (.tick 6), .ev (.block none), .ev .yield, .ev (.wake 1), .ev (.wake 1), + .ev (.wakeX 10), .pass, .ev (.tick 7)] + +theorem example_start : Start K0Part.dom0 id 3 2 exBoot := by + apply start_boot + · intro d t ht + by_cases h0 : d = 0 + · subst h0 + simp at ht + rcases ht with rfl | rfl <;> decide + · simp [h0] at ht + · intro d w hw; simp at hw + · decide + · decide + · decide + · intro w hw; simp at hw + · decide + +theorem example_ok : OkRun K0Part.dom0 id 2 exBoot exRun := by decide + +/-- The `K0Share` behaviour the run projects onto, and the counters. -/ +theorem example_events : + trRun K0Part.dom0 id 2 exBoot exRun = + [.run, .run, .run, .run, .yield, .run, .run, .block, .run, .run, .run, .wake 2, .run, + .block, .yield, .wake 1, .run, .run] ∧ + (texec K0Part.dom0 id 2 exBoot exRun).time = 12 ∧ + (texec K0Part.dom0 id 2 exBoot exRun).ran = 10 := by decide + +/-- The constant of `timed_share_bound` is reached by a timed run of `K0Part` + (`N = 3`, `P = 2`, first countdown 2). Task 1 runs first with the mark, + task 2 is ready, the spinner is last: after 6 steps the spinner has not + run, and `3 * 0 + (3 - 1) * 2 + 2 = 6`. -/ +def exTight : TSt := tboot 0 1 (fun d => if d = 0 then [2, 0] else []) (fun _ => []) 2 0 + +def exTightRun : List TEv := + [.pass, .ev (.tick 1), .pass, .ev (.tick 2), .pass, .ev (.tick 3)] + +theorem example_tight : + OkRun K0Part.dom0 id 2 exTight exTightRun ∧ + (texec K0Part.dom0 id 2 exTight exTightRun).time = 6 ∧ + (texec K0Part.dom0 id 2 exTight exTightRun).ran = 0 ∧ + 3 * (texec K0Part.dom0 id 2 exTight exTightRun).ran + (3 - 1) * 2 + exTight.c = 6 := by + decide + +theorem example_tight_start : Start K0Part.dom0 id 3 2 exTight := by + apply start_boot + · intro d t ht + by_cases h0 : d = 0 + · subst h0 + simp at ht + rcases ht with rfl | rfl <;> decide + · simp [h0] at ht + · intro d w hw; simp at hw + · decide + · decide + · decide + · intro w hw; simp at hw + · decide + +/-- "The spinner never yields" is needed. Two tasks, period 1. Task 0 yields + each time it gets the CPU: the start is as `Start` says, the run is not + allowed, 6 steps pass, task 0 runs in none of them, and the bound of + `timed_share_bound` would be 2. -/ +def exBad : TSt := tboot 0 0 (fun d => if d = 0 then [1] else []) (fun _ => []) 1 0 + +def exBadRun : List TEv := + [.ev .yield, .ev (.tick 1), .ev (.tick 2), .ev .yield, .ev (.tick 3), .ev (.tick 4), + .ev .yield, .ev (.tick 5), .ev (.tick 6)] + +theorem example_spinner_yield : + ¬ OkRun K0Part.dom0 id 1 exBad exBadRun ∧ + (texec K0Part.dom0 id 1 exBad exBadRun).time = 6 ∧ + (texec K0Part.dom0 id 1 exBad exBadRun).ran = 0 ∧ + ¬ ((texec K0Part.dom0 id 1 exBad exBadRun).time ≤ + 2 * (texec K0Part.dom0 id 1 exBad exBadRun).ran + (2 - 1) * 1 + exBad.c) := by decide + +theorem example_bad_start : Start K0Part.dom0 id 2 1 exBad := by + apply start_boot + · intro d t ht + by_cases h0 : d = 0 + · subst h0 + simp at ht + subst ht + decide + · simp [h0] at ht + · intro d w hw; simp at hw + · decide + · decide + · decide + · intro w hw; simp at hw + · decide + +/-! ## A concrete window boundary: the hypotheses of `window_cycle` hold together + +Domains 0 and 1 with one tick each (table set at boot, in force from tick 2). +Domain 0 has tasks 0, 1, 2; domain 1 has tasks 10, 11. -/ + +/-- After tick 2 and a block of task 1 until tick 4: task 2 runs in domain 0 + with the mark, task 0 is ready, task 1 waits. -/ +def exW : K0Part.St := + K0Part.exec K0Part.dom0 + (K0Part.boot 0 0 (fun d => if d = 0 then [1, 2] else if d = 1 then [10, 11] else []) + (fun _ => [])) + [.setTable [(0, 1), (1, 1)], .tick 1, .tick 2, .block (some 4)] + +def exWk : K0Share.St := + { cur := 2, ex := true, q := [0], c := 1, age := 0, time := 0, ran := 0 } + +/-- What domain 1 does in its window. -/ +def exWes : List K0Part.Ev := [.yield, .block (some 9)] + +/-- Tick 3 closed the window of domain 0 and domain 1 has done `exWes`. -/ +def exW2 : K0Part.St := + K0Part.exec K0Part.dom0 (K0Part.step K0Part.dom0 exW (.tick 3)) exWes + +theorem exW_inv : K0Part.Inv K0Part.dom0 exW := by + apply K0Part.inv_exec + apply K0Part.inv_boot + · intro d t ht + by_cases h0 : d = 0 + · subst h0 + simp at ht + rcases ht with rfl | rfl <;> decide + · by_cases h1 : d = 1 + · subst h1 + simp at ht + rcases ht with rfl | rfl <;> decide + · simp [h0, h1] at ht + · intro d w hw; simp at hw + · decide + +/-- `window_cycle` applies: tick 4 opens the window of domain 0 again. Task 2, + parked with the mark, runs without it; task 0 is behind it; task 1, whose + wait ended at tick 4, is at the back. -/ +theorem example_window : + Rel id (K0Part.step K0Part.dom0 exW2 (.tick 4)) + (K0Share.exec 3 2 (K0Share.onTick 2 exWk) [.wake 1]) ∧ + (K0Part.step K0Part.dom0 exW2 (.tick 4)).cur = some (2, false) ∧ + (K0Part.step K0Part.dom0 exW2 (.tick 4)).q 0 = [0, 1] := by + refine ⟨?_, by decide, by decide⟩ + have hw : woken exW2 exW.rd 4 = [1] := by decide + have h := window_cycle K0Part.dom0 id 3 2 (s := exW) (s2 := exW2) (k := exWk) exW_inv + ⟨2, by decide, by decide, by decide⟩ 3 (by decide) (by decide) exWes (by decide) rfl + 4 (by decide) (by decide) (by decide) (by decide) + rw [hw] at h + exact h + +/-! ## Headline theorems and their axioms -/ + +#print axioms sameStep_onTick +#print axioms serve_wakes +#print axioms tick_same +#print axioms tick_same_run +#print axioms yield_step +#print axioms yield_spinner_differs +#print axioms block_step +#print axioms block_spinner_differs +#print axioms block_empty_idle +#print axioms wake_step +#print axioms wake_not_waiting +#print axioms wake_cap_needed +#print axioms boot_start0 +#print axioms cut_parked +#print axioms enter_parked +#print axioms cut_enter_onTick +#print axioms tick_leave +#print axioms tick_return +#print axioms parked_keep +#print axioms window_cycle +#print axioms sim_step +#print axioms run_projects +#print axioms run_projects_prefix +#print axioms timed_share_bound +#print axioms start_boot +#print axioms boot_share_bound +#print axioms example_start +#print axioms example_ok +#print axioms example_events +#print axioms example_tight +#print axioms example_tight_start +#print axioms example_spinner_yield +#print axioms example_window +#print axioms example_bad_start + +end K0Bridge diff --git a/proofs/lean/K0Close.lean b/proofs/lean/K0Close.lean new file mode 100644 index 0000000..5b5dc64 --- /dev/null +++ b/proofs/lean/K0Close.lean @@ -0,0 +1,357 @@ +/- +K0Close.lean: statements that pin down definitions the other files leave free. + +A sensitivity run changed one definition of the model at a time and built the +four files again. A change that still builds is behaviour that no theorem +constrains. Each section below closes one such change: the general theorem is +false in the changed file. Every `inst_` is one concrete instance of the +theorem above it, proved by `decide`, and every `from_` derives the same +instance from the general theorem, so the instance failing means the theorem +fails. The ids are those of the run (README.md, "Checks that are not in the +repository"). + +Nothing here changes `K0Part.lean` or `K0Bridge.lean`. +-/ +import K0Part +import K0Bridge +open K0Part + +namespace K0Close + +/-! ## `view` and `viewTrace` (NV01, NV02, NV03, NV05) -/ + +/-- Equal views give the relation back: a view holds the queue, the waiting + list and the running task of `D` with its slice bit, and nothing less. -/ +theorem R_of_view {dom : Tid → Dom} {D : Dom} {s s' : St} (hi : Inv dom s) (hi' : Inv dom s') + (hp : s.part = s'.part) (hr : s.rd = s'.rd) (hv : view dom D s = view dom D s') : + R D s s' := by + have hq : s.q D = s'.q D := congrArg View.q hv + have hw : s.wl D = s'.wl D := congrArg View.wl hv + refine ⟨⟨hp, hr, hq, hw⟩, ?_⟩ + intro hD + have hrun := congrArg View.run hv + simp only [view] at hrun + rcases hc : s.cur with _ | ⟨t, b⟩ <;> rcases hc' : s'.cur with _ | ⟨t', b'⟩ + · rfl + · have h2 : dom t' = D := by rw [hi'.cur_dom t' b' hc', ← hr]; exact hD + simp [hc, hc', h2] at hrun + · have h1 : dom t = D := by rw [hi.cur_dom t b hc]; exact hD + simp [hc, hc', h1] at hrun + · have h1 : dom t = D := by rw [hi.cur_dom t b hc]; exact hD + have h2 : dom t' = D := by rw [hi'.cur_dom t' b' hc', ← hr]; exact hD + simp [hc, hc', h1, h2] at hrun + simp [hrun] + +/-- The view trace has one view per step, the first one before any event. -/ +theorem viewTrace_get (dom : Tid → Dom) (D : Dom) : ∀ (es : List Ev) (s : St) (k : Nat), + k ≤ es.length → + (viewTrace dom D s es)[k]? = some (view dom D (exec dom s (es.take k))) := by + intro es + induction es with + | nil => + intro s k hk + have : k = 0 := by simpa using hk + subst this + rfl + | cons e es ih => + intro s k hk + cases k with + | zero => rfl + | succ k => + simp only [viewTrace, List.getElem?_cons_succ, List.take_succ_cons, exec] + exact ih _ k (by simpa using hk) + +theorem viewTrace_length (dom : Tid → Dom) (D : Dom) : ∀ (es : List Ev) (s : St), + (viewTrace dom D s es).length = es.length + 1 := by + intro es + induction es with + | nil => intro s; rfl + | cons e es ih => intro s; simp [viewTrace, ih] + +/-- A state in which domain `d` runs task `c` and nothing else exists. -/ +def one (d : Dom) (c : Option (Tid × Bool)) (w : List (Tid × Option Nat)) (seen : Nat) : St := + { part := { tbl := [(d, 1)], epoch := 0, pend := none, seen := seen }, rd := d, cur := c, + q := fun _ => [], wl := fun x => if x = d then w else [] } + +/-- Such a state satisfies `Inv` when the running task and the waiters belong to `d`. -/ +theorem one_inv (d : Dom) (c : Tid) (b : Bool) (w : List (Tid × Option Nat)) (seen : Nat) + (hc : dom0 c = d) (hw : ∀ x ∈ w, dom0 x.1 = d) : + Inv dom0 (one d (some (c, b)) w seen) := by + refine ⟨⟨?_, ⟨?_, ?_⟩, ?_, ?_⟩, ⟨Nat.zero_le _, ?_⟩⟩ + · simp [one, Part.plan, domAt, domAtPos, cycle, Nat.mod_one] + · intro x t h; simp [one] at h + · intro x y h + simp only [one] at h + split at h + · next hx => subst hx; exact hw y h + · simp at h + · intro t b' h + simp [one] at h + rw [← h.1]; exact hc + · intro h; simp [one] at h + · intro k t h; simp [one] at h + +theorem inst_NV01 : view dom0 1 (one 1 (some (10, false)) [(11, none)] 0) + ≠ view dom0 1 (one 1 (some (10, false)) [] 0) := by decide +theorem inst_NV02 : view dom0 1 (one 1 (some (10, false)) [] 0) + ≠ view dom0 1 (one 1 (some (11, false)) [] 0) := by decide +theorem inst_NV03 : view dom0 1 (one 1 (some (10, true)) [] 0) + ≠ view dom0 1 (one 1 (some (10, false)) [] 0) := by decide +theorem inst_NV05 : (viewTrace dom0 1 sA esA).length = esA.length + 1 := by decide + +/-- The three instances are instances of `R_of_view`: the states satisfy `Inv`, + have the same clock part and running domain, and are not related by `R`. -/ +theorem from_NV01 : view dom0 1 (one 1 (some (10, false)) [(11, none)] 0) + ≠ view dom0 1 (one 1 (some (10, false)) [] 0) := fun hv => + have h : R 1 (one 1 (some (10, false)) [(11, none)] 0) (one 1 (some (10, false)) [] 0) := + R_of_view (one_inv 1 10 false [(11, none)] 0 (by decide) (by decide)) + (one_inv 1 10 false [] 0 (by decide) (by decide)) rfl rfl hv + absurd h.wl (by decide) +theorem from_NV02 : view dom0 1 (one 1 (some (10, false)) [] 0) + ≠ view dom0 1 (one 1 (some (11, false)) [] 0) := fun hv => + have h : R 1 (one 1 (some (10, false)) [] 0) (one 1 (some (11, false)) [] 0) := + R_of_view (one_inv 1 10 false [] 0 (by decide) (by decide)) + (one_inv 1 11 false [] 0 (by decide) (by decide)) rfl rfl hv + absurd (h.cur rfl) (by decide) +theorem from_NV03 : view dom0 1 (one 1 (some (10, true)) [] 0) + ≠ view dom0 1 (one 1 (some (10, false)) [] 0) := fun hv => + have h : R 1 (one 1 (some (10, true)) [] 0) (one 1 (some (10, false)) [] 0) := + R_of_view (one_inv 1 10 true [] 0 (by decide) (by decide)) + (one_inv 1 10 false [] 0 (by decide) (by decide)) rfl rfl hv + absurd (h.cur rfl) (by decide) +theorem from_NV05 : (viewTrace dom0 1 sA esA).length = esA.length + 1 := + viewTrace_length dom0 1 esA sA + +/-! ## The slice bit on the paths the bridge leaves out (ND16, ND25, NX03) -/ + +theorem enter_bit (s : St) (d : Dom) (t : Tid) (b : Bool) (h : (enter s d).cur = some (t, b)) : + b = false := by + unfold enter at h + split at h + · simp at h; exact h.2 + · simp at h + +/-- After a tick with a new index the running task has no exemption: a tick + clears the mark, and a task that a tick starts gets none, also when the + tick finds the domain idle. -/ +theorem tick_clears_mark (dom : Tid → Dom) (s : St) (n : Nat) (hn : s.part.seen < n) + (t : Tid) (b : Bool) (h : (step dom s (.tick n)).cur = some (t, b)) : b = false := by + have hn' : ¬ n ≤ s.part.seen := by omega + simp only [step, tickStep, hn', ite_false] at h + split at h + · unfold sameStep at h + split at h + · simp at h; exact h.2 + · next c hc => + split at h + · simp at h; exact h.2 + · rw [hc] at h; simp at h; exact h.2 + · exact enter_bit _ _ t b h + · exact enter_bit _ _ t b h + +/-- A poll without a new tick leaves a running task alone, with its bit. -/ +theorem poll_keeps_running (dom : Tid → Dom) (s : St) (n : Nat) (hn : n ≤ s.part.seen) + (c : Tid × Bool) (hc : s.cur = some c) : (step dom s (.poll n)).cur = some c := by + have hn' : ¬ s.part.seen < n := by omega + simp only [step, pollStep, hn', ite_false] + unfold pollRest + have : (serve s s.rd n).cur = some c := by simpa using hc + rw [this] + exact this + +/-- A task that the idle loop starts has the exemption. -/ +theorem poll_idle_mark (dom : Tid → Dom) (s : St) (n : Nat) (hn : n ≤ s.part.seen) + (hc : s.cur = none) (t : Tid) (b : Bool) (h : (step dom s (.poll n)).cur = some (t, b)) : + b = true := by + have hn' : ¬ s.part.seen < n := by omega + simp only [step, pollStep, hn', ite_false] at h + unfold pollRest at h + have hs : (serve s s.rd n).cur = none := by simpa using hc + rw [hs] at h + simp only at h + unfold popBetween at h + split at h + · simp at h; exact h.2 + · simp at h + +/-- "The running task, if there is one, has bit `b`", in a form `decide` can read. -/ +def bitIs (s : St) (b : Bool) : Prop := s.cur.map Prod.snd ≠ some (!b) + +instance (s : St) (b : Bool) : Decidable (bitIs s b) := by unfold bitIs; exact inferInstance + +theorem bitIs_of (s : St) (b : Bool) (h : ∀ t b', s.cur = some (t, b') → b' = b) : bitIs s b := by + unfold bitIs + rcases hc : s.cur with _ | ⟨t, b'⟩ + · simp + · have := h t b' hc + subst this + cases b' <;> simp + +theorem inst_ND25 : bitIs (step dom0 (one 0 none [(1, some 1)] 0) (.tick 1)) false := by decide +theorem inst_ND16 : bitIs (step dom0 (one 0 none [(1, some 3)] 5) (.poll 5)) true := by decide +theorem inst_NX03 : (step dom0 (one 0 (some (0, true)) [] 5) (.poll 5)).cur = some (0, true) := by decide + +theorem from_ND25 : bitIs (step dom0 (one 0 none [(1, some 1)] 0) (.tick 1)) false := + bitIs_of _ _ (tick_clears_mark dom0 _ 1 (by decide)) +theorem from_ND16 : bitIs (step dom0 (one 0 none [(1, some 3)] 5) (.poll 5)) true := + bitIs_of _ _ (poll_idle_mark dom0 _ 5 (by decide) rfl) +theorem from_NX03 : (step dom0 (one 0 (some (0, true)) [] 5) (.poll 5)).cur = some (0, true) := + poll_keeps_running dom0 _ 5 (by decide) (0, true) rfl + +/-! ## The waiting list after a poll, in order (ND31) -/ + +/-- A poll without a new tick takes the due waiters out of the waiting list of + the running domain and leaves the others in their order. -/ +theorem poll_wl (dom : Tid → Dom) (s : St) (n : Nat) (hn : n ≤ s.part.seen) : + (step dom s (.poll n)).wl s.rd = (s.wl s.rd).filter (fun w => !expired w n) := by + have hn' : ¬ s.part.seen < n := by omega + simp only [step, pollStep, hn', ite_false, pollRest_wl] + simp [serve, upd] + +/-- The same for a tick with a new index, for the domain that runs after it + (a tick inside a window and a tick that changes the domain). -/ +theorem tick_wl (dom : Tid → Dom) (s : St) (n : Nat) (hn : s.part.seen < n) : + (step dom s (.tick n)).wl (step dom s (.tick n)).rd + = (s.wl (step dom s (.tick n)).rd).filter (fun w => !expired w n) := by + have hn' : ¬ n ≤ s.part.seen := by omega + simp only [step, tickStep, hn', ite_false] + split + · simp [serve, upd] + · simp [serve, upd] + +theorem inst_ND31 : (step dom0 (one 0 (some (0, false)) [(1, none), (2, none)] 5) (.poll 5)).wl 0 + = [(1, none), (2, none)] := by decide +theorem from_ND31 : (step dom0 (one 0 (some (0, false)) [(1, none), (2, none)] 5) (.poll 5)).wl 0 + = [(1, none), (2, none)] := + poll_wl dom0 (one 0 (some (0, false)) [(1, none), (2, none)] 5) 5 (by decide) + +/-! ## A wake while nothing runs (NX01) -/ + +theorem wakeX_idle_noop (dom : Tid → Dom) (s : St) (t : Tid) (hc : s.cur = none) : + step dom s (.wakeX t) = s := by + simp [step, hc] + +theorem wake_idle_noop (dom : Tid → Dom) (s : St) (t : Tid) (hc : s.cur = none) : + step dom s (.wake t) = s := by + simp [step, hc] + +/-- Domain 0 idles, task 10 of domain 1 waits. -/ +def idleX : St := + { part := { tbl := [(0, 1)], epoch := 0, pend := none, seen := 0 }, rd := 0, cur := none, + q := fun _ => [], wl := fun x => if x = 1 then [(10, none)] else [] } + +theorem inst_NX01 : (step dom0 idleX (.wakeX 10)).q 1 = [] := by decide +theorem from_NX01 : (step dom0 idleX (.wakeX 10)).q 1 = [] := by + rw [wakeX_idle_noop dom0 idleX 10 rfl]; rfl + +/-! ## A table of zero ticks (NT01), the boot epoch (NT09) -/ + +theorem domAtPos_zero_cycle : ∀ (t : Table) (p : Nat), cycle t = 0 → domAtPos t p = 0 := by + intro t + induction t with + | nil => intro p _; rfl + | cons e r ih => + obtain ⟨d, l⟩ := e + intro p h + simp only [cycle] at h + have hl : l = 0 := by omega + have hr : cycle r = 0 := by omega + subst hl + simp only [domAtPos, Nat.not_lt_zero, ite_false, Nat.sub_zero] + exact ih p hr + +/-- A table of zero ticks (empty, or only windows of 0 ticks) gives the root + domain at every tick. -/ +theorem domAt_zero_cycle (t : Table) (n : Nat) (h : cycle t = 0) : domAt t n = 0 := + domAtPos_zero_cycle t _ h + +theorem inst_NT01 : domAt [] 5 = 0 := by decide +theorem from_NT01 : domAt [] 5 = 0 := domAt_zero_cycle [] 5 rfl + +/-- At boot the default table starts at the boot tick. -/ +theorem boot_part (now : Nat) (first : Tid) (q0 : Dom → List Tid) + (w0 : Dom → List (Tid × Option Nat)) : + (boot now first q0 w0).part = { tbl := defaultTable, epoch := now, pend := none, seen := now } := + rfl + +theorem inst_NT09 : (boot 3 0 (fun _ => []) (fun _ => [])).part.epoch = 3 := by decide +theorem from_NT09 : (boot 3 0 (fun _ => []) (fun _ => [])).part.epoch = 3 := by + rw [boot_part] + +/-! ## The clause `epoch <= seen` of `PInv` (NV23: no other theorem uses it) -/ + +/-- What the clause is for, as a statement: at a new tick `n` the offset + `n - epoch` that `Core::tick` computes after `advance` does not underflow. -/ +theorem advance_epoch_le (p : Part) (n : Nat) (h : PInv p) (hn : p.seen < n) : + (p.advance n).epoch ≤ n := by + unfold Part.advance + rcases hp : p.pend with _ | ⟨s0, t0⟩ + · have := h.epoch_le; simp; omega + · by_cases hs : s0 ≤ n + · simp [hs] + · have := h.epoch_le; simp [hs]; omega + +/-! ## Definitions that one statement uses (NV28, NB11) -/ + +/-- `blockIdleRust` does pop: with a task ready it starts that task, with the + exemption. (So `blockIdleRust_eq` is not about a function that does nothing.) -/ +theorem blockIdleRust_pops (s : St) (x : Tid) (r : List Tid) (h : s.q s.rd = x :: r) : + (blockIdleRust s).cur = some (x, true) ∧ (blockIdleRust s).q s.rd = r := by + simp [blockIdleRust, popBetween, h, upd] + +/-- Domain 0 has nothing running and task 7 ready (not an `Inv` state). -/ +def idleQ : St := + { part := { tbl := [(0, 1)], epoch := 0, pend := none, seen := 0 }, rd := 0, cur := none, + q := fun x => if x = 0 then [7] else [], wl := fun _ => [] } + +theorem inst_NV28 : (blockIdleRust idleQ).cur = some (7, true) := by decide +theorem from_NV28 : (blockIdleRust idleQ).cur = some (7, true) := + (blockIdleRust_pops idleQ 7 [] rfl).1 + +/-- An idle step is not a step of the spinner. -/ +theorem spin_idle (lab : Tid → Nat) (s : St) (h : s.cur = none) : K0Bridge.spin lab s = 0 := by + simp [K0Bridge.spin, h] + +theorem inst_NB11 : K0Bridge.spin id idleX = 0 := by decide +theorem from_NB11 : K0Bridge.spin id idleX = 0 := spin_idle id idleX rfl + +end K0Close + +#print axioms K0Close.R_of_view +#print axioms K0Close.viewTrace_get +#print axioms K0Close.tick_clears_mark +#print axioms K0Close.poll_keeps_running +#print axioms K0Close.poll_idle_mark +#print axioms K0Close.poll_wl +#print axioms K0Close.tick_wl +#print axioms K0Close.wakeX_idle_noop +#print axioms K0Close.domAt_zero_cycle +#print axioms K0Close.blockIdleRust_pops +#print axioms K0Close.spin_idle +#print axioms K0Close.inst_NV01 +#print axioms K0Close.inst_NV02 +#print axioms K0Close.inst_NV03 +#print axioms K0Close.inst_NV05 +#print axioms K0Close.from_NV01 +#print axioms K0Close.from_NV02 +#print axioms K0Close.from_NV03 +#print axioms K0Close.from_NV05 +#print axioms K0Close.inst_ND25 +#print axioms K0Close.inst_ND16 +#print axioms K0Close.inst_NX03 +#print axioms K0Close.from_ND25 +#print axioms K0Close.from_ND16 +#print axioms K0Close.from_NX03 +#print axioms K0Close.inst_ND31 +#print axioms K0Close.from_ND31 +#print axioms K0Close.inst_NX01 +#print axioms K0Close.from_NX01 +#print axioms K0Close.inst_NT01 +#print axioms K0Close.from_NT01 +#print axioms K0Close.inst_NT09 +#print axioms K0Close.from_NT09 +#print axioms K0Close.inst_NV28 +#print axioms K0Close.from_NV28 +#print axioms K0Close.inst_NB11 +#print axioms K0Close.from_NB11 +#print axioms K0Close.advance_epoch_le diff --git a/proofs/lean/K0Part.lean b/proofs/lean/K0Part.lean new file mode 100644 index 0000000..750a6a2 --- /dev/null +++ b/proofs/lean/K0Part.lean @@ -0,0 +1,2981 @@ +/- +K0Part.lean: a model of the K0 partition scheduler core. + +WHAT THIS FILE IS + A Lean 4 model of the pure scheduling core `Core` of the crate `k0-part` + (`Core::tick`, `poll`, `block`, `yield_now`, `set_table`, with the tick rule + of `k0-slice`), and proofs about that MODEL. It is a proof about the model, + not about the Rust code. The link to the Rust code is a reading of `lib.rs` + and `k0-slice/src/lib.rs`, the host tests of the Rust crate, and a host + test that runs recorded event scripts through `Core` and compares the + result with what `step` gives for them (`ModelVectors.lean`, README.md). + None of these is a proof. + +WHAT IS MODELLED + * A table of (domain, ticks) entries with its cycle, `domAt`. + * A pending table that starts two ticks after the last processed tick and + takes over at its entry 0, with `epoch` set to its start tick (`Part`). + `Part.setTable` is the Rust call as written: it promotes nothing and + discards an earlier pending table. + * Per-domain ready queues and per-domain waiting lists with optional + deadlines in GLOBAL ticks, served only when the owner domain is served + (same-domain tick, entry at a boundary, or the idle loop `poll`). Expired + waiters are pushed to the back of their own domain's queue, the one that + started to wait last going first (`k0_sched::arm_timeout` links a waiter + at the head of the list and `k0_sched::expired` walks it from the head; + in the model: `serve_due_order`). + * The tick rule state of the running task (`exempt` bit, kept inside `cur`). + * Parking at a boundary (rule applied, then front of the own queue), entering + a domain (front of its queue, as a tick entry), idle when the running + domain has nothing ready (no slack donation), and a jump of the tick index + over several ticks as ONE step. + * Wakes. `wake t`: the running task wakes a task of its own domain. + Timer wakes happen inside `serve`. `wakeX t`: a wake across domains, + an explicitly labelled separate event (the model of a shared capability). + A `wakeX` gives nothing back to the task that makes it. + +WHAT IS NOT MODELLED + * Time, the timer, the guard band, the hold before the return to EL0. Nothing + here says anything about instants. Ticks are given as indexes, and what + makes a tick late or skipped is outside the model. + * Caches, predictors, the TLB, interrupt latency, the length of kernel paths. + Only the channel through the scheduler decision is in scope. + * Console input. In Rust `Env::serve` wakes a console reader before the timed + waits; here `serve` only does timed waits. The Rust console wake reports a + lost capability or a closed device to a reader of ANY domain, whichever + domain is served, so `serve_only_own` is a fact about the model only. + * IPC rendezvous, capabilities, task creation and `TCB_RESUME` (an enqueue of + a task that waits nowhere), task domain changes (a task's domain `dom` is a + fixed function), the removal of a ready or waiting task that another task + ends (`k0_ipc::teardown`), fault and exit of the running task (exit is + `block none` of a task nobody wakes). The only way one domain changes + another domain's queue or waiting list in the model is `wakeX`. + * `Core::start` is only an initial state (`boot`). + * `Core::block` while nothing runs pops the queue in Rust and does nothing + here. Under `Inv` that queue is empty, so the two agree (`blockIdleRust_eq`). + * Events the kernel does not raise are allowed here: `poll` while a task runs, + `tick` while none runs, an index below `seen`, a deadline that is already + past, `set_table` while nothing runs. The model is the wider side. + * Uniqueness of a task in the structures. The events make no duplicate + checks and `Inv` does not ask for it: `Inv` holds for states where a task + is queued twice (`inv_with_duplicate`). One group of theorems takes it as + a separate hypothesis: `step_tasks_perm` and `exec_tasks_perm` need `NoDup` + (no task twice among the tasks of a domain), which every step keeps + (`nodup_step`). Without it a wake can drop an entry of a task that waits + twice (`wake_needs_nodup`). No other theorem needs it. + * Rust uses `u64`. `plan_at` and `set_table` saturate, `tick` computes + `n - epoch` directly. Here `Nat` with truncated subtraction. `epoch <= seen` + is part of `PInv`, so `n - epoch` does not underflow for a new tick `n`. + Within two ticks of `2^64` the two differ; the kernel's tick counter stops + before that. + * Tables are arbitrary lists. The Rust constructors reject an empty table and + a window of zero ticks, so `cycle` is never 0 there, and the system call + rejects a table without the caller's domain. + * A deadline `some 0` has no Rust counterpart (Rust keeps 0 for "no deadline"). + +FINDINGS recorded while proving and while checking the proofs + * `set_table` after tick n does NOT in general keep the domain of tick n + 1, + when an earlier pending table starts exactly at n + 1 (two `set_table` + calls in two consecutive ticks): the second call discards it. + `guard_sound` therefore has the hypothesis "no pending table starts at + n + 1". `guard_unsound_without_hyp` is a counterexample on a state that + is reached from boot (`exP_reachable`), and there the guard decision + itself flips (`guard_decision_flips`). + * `Core::set_table` and `Core::tick` rely on two facts the Rust code does not + state: a pending table always starts after the last processed tick, and + the epoch is never after it (`PInv`). Both hold from boot and are kept by + every event (`pinv_pstep`). Without the first one `set_table` would + change the domain of the current tick (`setTable_now_needs_pendAfter`). + +THEOREM INDEX (all about the model) + (0) pinv_pstep, pinv_pexec, inv_boot, inv_step, inv_exec (the invariants); + sample_inv, sample_nodup (the state of the first `#eval` satisfies `Inv` + and `NoDup`) + (1) guard_sound, guard_sound_event, guard_unsound_without_hyp + (2) plan_setTable_ge / plan_setTable_lt / plan_setTable_now (clock part), + table_effective_at (events). A table governs only until a later call + (`first_table_never_governs`). + The layout of a table, which those statements take from `cycle` and + `domAtPos`: cycle_append, cycle_eq_sum, domAtPos_window, window_cover, + domAt_window (entry i governs exactly its window, the windows follow in + the order of the entries, the table repeats), plan_setTable_window (the + same for the plan after a `set_table` call). + (3) running_domain_function, running_domain_same, tick_jump_domain + (4) no_slack_donation (`Inv` restated over runs) + (5) noninterference, noninterference_final. Hypotheses: both states satisfy + `Inv`; `R D s s'` (same clock part and running domain, same queue and + waiting list of D, same running task if D runs; other domains arbitrary); + `Sync`, which compares the two lists place by place. A clock event (a + tick index not seen before, or a `set_table` call) is the same public + event in both runs; a new tick may come through `tick` in one run and + through the idle loop's `poll` in the other (`poll_eq_tick`). Every + other event is local to the running domain: an action of its task, its + idle loop taking an interrupt without a new tick, or a repeated index. + While D runs the local events are the same in both runs. While another + domain runs they are unrelated, and `tick 0` pads the run that has fewer + (`tick_zero_noop`). No `wakeX` into D in either run. + The hypotheses fix as equal in both runs, and so the theorem does not + explain: the tick indexes, jumps included (`tick_indexes_needed`), and + the `set_table` calls. + Conclusion: D's `view` (queue, waiting list, running task of D with its + slice bit) is equal after every step. Not claimed: anything about + instants, caches, the guard, console input, or the Rust code. + (6) cross_wake_breaks (the `wakeX` hypothesis is needed), example_views_equal + and example_applies (a concrete pair of runs where the hypotheses hold, + the views of D agree and the views of the other domains differ), + example_effects and example_kernel_shaped (what the example exercises). + (7) serve_only_own, serve_not_early. Both are read off the definition of + `serve`. They say nothing about the kernel's `serve` callback. + Timed waits do fire, and only for the domain that runs: serve_wakes_due, + serve_due_order (due waiters are queued, the last waiter first), + tick_serves (a new tick serves the domain that runs after it), + tick_frame and tick_old_domain (it serves no other domain; at a domain + change the old domain's due waiters stay until it runs again), + poll_serves and poll_frame (the same for the idle loop's `poll` without a + new tick), block_keeps_deadline, waiter_leaves_only (a waiter leaves its + list only when its domain is served at or after its deadline, or by a + wake), example_timed_waits. They are about tick indexes: none says + when a tick comes or that one comes. + (8) blockIdleRust_eq, poll_eq_tick, tick_repeat_noop, tick_zero_noop (where + the model's events differ from the kernel's calls, and why that does not + matter; a tick index that is not new changes nothing). + (9) No task is lost and none is duplicated. `tasks d s`: the running task + if d runs, d's queue, the tasks of d's waiting list. + step_tasks_perm, exec_tasks_perm: from a state with `Inv` and `NoDup`, + the tasks of every domain after a step (a run) are a permutation of + the tasks before. nodup_step, nodup_exec, nodup_boot: `NoDup` is kept and + holds at boot for lists without duplicates. step_tasks_perm_of: only a + wake needs `NoDup`, and only for the woken task's waiting list. + step_tasks_mem, exec_tasks_mem: with `Inv` alone a task is among the + tasks of d after a run exactly if it was before. wake_needs_nodup: the + hypothesis cannot be dropped. wake_effect, wakeX_effect: a woken task + goes to the back of its own queue, and a wake of a task that does not + wait changes nothing. Not claimed: the order inside a queue beyond + these, or anything about task creation and exit (not modelled). + No theorem in this file constrains the exemption bit beyond its bookkeeping. + `K0Bridge.lean` shows that the rules that set and clear it here are the + rules of `K0Share.lean`, which proves the share that the bit buys. +`#print axioms` lines are at the end of the file. +-/ + +namespace K0Part + +abbrev Dom := Nat +abbrev Tid := Nat +/-- Entries (domain, ticks), in order. -/ +abbrev Table := List (Dom × Nat) + +/-! ## Tables -/ + +/-- Number of ticks of one cycle. -/ +def cycle : Table → Nat + | [] => 0 + | (_, l) :: r => l + cycle r + +/-- Domain at position `p` inside one cycle (mirrors `Table::domain_at` loop). -/ +def domAtPos : Table → Nat → Dom + | [], _ => 0 + | (d, l) :: r, p => if p < l then d else domAtPos r (p - l) + +/-- Domain `offset` ticks after the table's entry 0 started (`Table::domain_at`). -/ +def domAt (t : Table) (n : Nat) : Dom := domAtPos t (n % cycle t) + +/-- The default table: root domain, one tick. -/ +def defaultTable : Table := [(0, 1)] + +/-! ### The layout of a table + +`cycle`, `domAtPos` and `domAt` are the vocabulary of every plan theorem below. +The theorems here say what they compute, in terms of the list of entries: the +windows lie one after the other in the order of the entries, entry `(d, l)` +covers exactly `l` ticks, and the table repeats. -/ + +/-- `cycle` adds up over `++`. (A helper: it does not fix what `cycle` counts; + `cycle_eq_sum` and `domAtPos_window` do.) -/ +theorem cycle_append (a b : Table) : cycle (a ++ b) = cycle a + cycle b := by + induction a with + | nil => simp [cycle] + | cons x a ih => obtain ⟨d, l⟩ := x; simp [cycle, ih, Nat.add_assoc] + +/-- One cycle is as long as the windows together. -/ +theorem cycle_eq_sum (t : Table) : cycle t = (t.map Prod.snd).sum := by + induction t with + | nil => rfl + | cons x t ih => obtain ⟨d, l⟩ := x; simp [cycle, ih] + +/-- The window of an entry. In the table `a ++ (d, l) :: b` the positions + `cycle a`, ..., `cycle a + l - 1` of a cycle belong to `d`: the window starts + where the entries before it end and is `l` ticks long. -/ +theorem domAtPos_window (a b : Table) (d : Dom) (l p : Nat) (hp : p < l) : + domAtPos (a ++ (d, l) :: b) (cycle a + p) = d := by + induction a with + | nil => simp [cycle, domAtPos, hp] + | cons x a ih => + obtain ⟨d0, l0⟩ := x + have h1 : ¬ (l0 + cycle a + p < l0) := by omega + have h2 : l0 + cycle a + p - l0 = cycle a + p := by omega + simp [cycle, domAtPos, h1, h2, ih] + +/-- Every position of a cycle lies in the window of some entry. With + `domAtPos_window` this fixes `domAtPos` on a whole cycle. -/ +theorem window_cover (t : Table) (pos : Nat) (h : pos < cycle t) : + ∃ a d l b p, t = a ++ (d, l) :: b ∧ p < l ∧ pos = cycle a + p := by + induction t generalizing pos with + | nil => simp [cycle] at h + | cons x t ih => + obtain ⟨d0, l0⟩ := x + by_cases h0 : pos < l0 + · exact ⟨[], d0, l0, t, pos, rfl, h0, by simp [cycle]⟩ + · have h1 : pos - l0 < cycle t := by simp only [cycle] at h; omega + obtain ⟨a, d, l, b, p, rfl, hp, hpos⟩ := ih (pos - l0) h1 + exact ⟨(d0, l0) :: a, d, l, b, p, rfl, hp, by simp only [cycle]; omega⟩ + +/-- The table repeats. Tick `k * cycle + cycle a + p` after the start of the + table `a ++ (d, l) :: b`, with `p < l`, belongs to `d`, for every round `k`. + Together with `window_cover` this is the specification of `domAt` for a + table whose cycle is not 0: entry by entry, in order, round after round. -/ +theorem domAt_window (a b : Table) (d : Dom) (l p k : Nat) (hp : p < l) : + domAt (a ++ (d, l) :: b) (k * cycle (a ++ (d, l) :: b) + cycle a + p) = d := by + unfold domAt + have hc : cycle (a ++ (d, l) :: b) = cycle a + (l + cycle b) := by rw [cycle_append]; rfl + have hlt : cycle a + p < cycle (a ++ (d, l) :: b) := by omega + have hm : (k * cycle (a ++ (d, l) :: b) + cycle a + p) % cycle (a ++ (d, l) :: b) + = cycle a + p := by + rw [Nat.add_assoc, Nat.mul_comm, Nat.mul_add_mod, Nat.mod_eq_of_lt hlt] + rw [hm] + exact domAtPos_window a b d l p hp + +/-! ## The clock part of the state: table, pending table, epoch -/ + +/-- `tbl`/`epoch`: table in force and the tick where its entry 0 started. + `pend = some (start, t)`: table `t` takes over at tick `start`. + `seen`: last processed tick index. -/ +structure Part where + tbl : Table + epoch : Nat + pend : Option (Nat × Table) + seen : Nat +deriving Repr, DecidableEq + +/-- Domain of tick `k` as planned now (`Core::plan_at`). -/ +def Part.plan (p : Part) (k : Nat) : Dom := + match p.pend with + | some (s, t) => if s ≤ k then domAt t (k - s) else domAt p.tbl (k - p.epoch) + | none => domAt p.tbl (k - p.epoch) + +/-- Promote a pending table whose start is `≤ n` (`Core::advance`). -/ +def Part.advance (p : Part) (n : Nat) : Part := + match p.pend with + | some (s, t) => if s ≤ n then { p with tbl := t, epoch := s, pend := none } else p + | none => p + +/-- Domain of tick `n` read from the table in force (what `tick` uses after `advance`). -/ +def Part.domNow (p : Part) (n : Nat) : Dom := domAt p.tbl (n - p.epoch) + +/-- `Core::set_table t`: the new table is pending from `seen + 2`. Nothing is + promoted and an earlier pending table is discarded, as in the Rust call. -/ +def Part.setTable (p : Part) (t : Table) : Part := + { p with pend := some (p.seen + 2, t) } + +/-- A pending table starts after the last processed tick. -/ +def PendAfter (p : Part) : Prop := ∀ k t, p.pend = some (k, t) → p.seen < k + +/-- The clock part is well formed. True at boot and kept by every event + (`pinv_pstep`); a field of `Inv`. The Rust code relies on both clauses + without stating them: `Core::tick` computes `n - epoch` without a check, + and `Core::set_table` does not look at the pending table it replaces. -/ +structure PInv (p : Part) : Prop where + epoch_le : p.epoch ≤ p.seen + pend_after : PendAfter p + +/-- Effect of a tick event with index `n` on the clock part. -/ +def pTick (p : Part) (n : Nat) : Part := + if n ≤ p.seen then p else { p.advance n with seen := n } + +theorem plan_seen (p : Part) (m k : Nat) : ({ p with seen := m } : Part).plan k = p.plan k := by + simp [Part.plan] + +theorem domNow_advance (p : Part) (n : Nat) : (p.advance n).domNow n = p.plan n := by + unfold Part.advance Part.plan Part.domNow + rcases hp : p.pend with _ | ⟨s, t⟩ + · simp + · by_cases hs : s ≤ n <;> simp [hs] + +theorem plan_advance (p : Part) (n k : Nat) (hk : n ≤ k) : (p.advance n).plan k = p.plan k := by + unfold Part.advance Part.plan + rcases hp : p.pend with _ | ⟨s, t⟩ + · simp [hp] + · by_cases hs : s ≤ n + · have : s ≤ k := Nat.le_trans hs hk + simp [hs, this] + · simp [hs, hp] + +/-- (2a) After `set_table` with last processed tick `seen`, tick `k >= seen + 2` + follows the new table's entry at `(k - (seen + 2)) mod cycle`. -/ +theorem plan_setTable_ge (p : Part) (t : Table) (k : Nat) (hk : p.seen + 2 ≤ k) : + (p.setTable t).plan k = domAtPos t ((k - (p.seen + 2)) % cycle t) := by + simp [Part.setTable, Part.plan, hk, domAt] + +/-- (2a) entry by entry. After `set_table (a ++ (d, l) :: b)` with last + processed tick `seen`, the new table starts at `seen + 2`, and in every + round `k` the `l` ticks from `cycle a` on belong to `d`. As `plan_setTable_ge`, + this is the plan until a later `set_table` call. -/ +theorem plan_setTable_window (p : Part) (a b : Table) (d : Dom) (l i k : Nat) (hi : i < l) : + (p.setTable (a ++ (d, l) :: b)).plan + (p.seen + 2 + (k * cycle (a ++ (d, l) :: b) + cycle a + i)) = d := by + rw [plan_setTable_ge _ _ _ (by omega)] + have h : p.seen + 2 + (k * cycle (a ++ (d, l) :: b) + cycle a + i) - (p.seen + 2) + = k * cycle (a ++ (d, l) :: b) + cycle a + i := by omega + rw [h] + exact domAt_window a b d l i k hi + +/-- (2b) Ticks `k < seen + 2` keep the domain they had. For `k <= seen` that + needs nothing beyond `PendAfter`. For `k = seen + 1` it needs that no + earlier pending table starts at `seen + 1` (the call discards that table). -/ +theorem plan_setTable_lt (p : Part) (t : Table) (k : Nat) (hpa : PendAfter p) + (h2 : k < p.seen + 2) (hk : k = p.seen + 1 → ∀ t0, p.pend ≠ some (p.seen + 1, t0)) : + (p.setTable t).plan k = p.plan k := by + have hn : ¬ (p.seen + 2 ≤ k) := by omega + unfold Part.setTable Part.plan + rcases hp : p.pend with _ | ⟨s, t0⟩ + · simp [hn] + · have h1 : p.seen < s := hpa s t0 hp + have : ¬ s ≤ k := by + intro hsk + have hk1 : k = p.seen + 1 := by omega + have hs1 : s = p.seen + 1 := by omega + exact hk hk1 t0 (by rw [hp, hs1]) + simp [this, hn] + +/-- (1) `guard_sound`: `set_table` after tick `seen` does not change the domain + of tick `seen + 1`, provided no earlier pending table starts exactly at + `seen + 1`. -/ +theorem guard_sound (p : Part) (t : Table) (hpa : PendAfter p) + (hk : ∀ t0, p.pend ≠ some (p.seen + 1, t0)) : + (p.setTable t).plan (p.seen + 1) = p.plan (p.seen + 1) := + plan_setTable_lt p t (p.seen + 1) hpa (by omega) (fun _ => hk) + +/-- Counterexample to `guard_sound` without its hypothesis: table set at tick 1 + starts at 3; a second call at tick 2 discards it, so tick 3 changes. -/ +def exP : Part := { tbl := [(0, 1)], epoch := 0, pend := some (3, [(1, 1)]), seen := 2 } + +/-- The counterexample is a state the model can be in. -/ +theorem exP_pendAfter : PendAfter exP := by + intro k t h + simp only [exP, Option.some.injEq, Prod.mk.injEq] at h + rw [← h.1]; decide + +theorem guard_unsound_without_hyp : + (exP.setTable [(2, 1)]).plan 3 ≠ exP.plan 3 := by decide + +#eval (exP.plan 3, (exP.setTable [(2, 1)]).plan 3) + +/-- The counterexample at the level of the guard decision: before the second + call the next tick changes the domain, after it it does not. -/ +theorem guard_decision_flips : + exP.plan (exP.seen + 1) ≠ exP.plan exP.seen ∧ + (exP.setTable [(2, 1)]).plan (exP.seen + 1) = exP.plan exP.seen := by decide + +/-- The current tick's domain is not changed by `set_table` at that tick. -/ +theorem plan_setTable_now (p : Part) (t : Table) (hpa : PendAfter p) : + (p.setTable t).plan p.seen = p.plan p.seen := by + have hn : ¬ (p.seen + 2 ≤ p.seen) := by omega + unfold Part.setTable Part.plan + rcases hp : p.pend with _ | ⟨s, t0⟩ + · simp [hn] + · have : ¬ s ≤ p.seen := by have := hpa s t0 hp; omega + simp [this, hn] + +/-- `PendAfter` is needed for that: on a state where a pending table is + already due, the call would discard a table that should be in force and so + change the domain of the current tick. The Rust code never reaches such a + state (`pendAfter_pstep`). -/ +def exQ : Part := { tbl := [(0, 1)], epoch := 0, pend := some (1, [(1, 1)]), seen := 2 } + +theorem setTable_now_needs_pendAfter : + (exQ.setTable [(2, 1)]).plan exQ.seen ≠ exQ.plan exQ.seen := by decide + + +/-! ## Events and the scheduler state -/ + +/-- Events of the model. + * `tick n`: timer interrupt taken from EL0, tick index `n` (a jump is `n > seen + 1`). + * `poll n`: the idle loop after an interrupt, `env.now() = n`. + * `yield`, `block dl`, `wake t`, `wakeX t`: actions of the RUNNING task. + `block dl`: it waits, with deadline `dl` in global ticks (`none`: untimed, + also the model of exit). `wake t`: it wakes a waiting task of its own + domain. `wakeX t`: it wakes a waiting task of ANOTHER domain through a + shared object (the only cross-domain wake of the model). + * `setTable t`: the control capability's `set_table`. -/ +inductive Ev where + | tick (n : Nat) + | poll (n : Nat) + | yield + | block (dl : Option Nat) + | wake (t : Tid) + | wakeX (t : Tid) + | setTable (t : Table) +deriving DecidableEq, Repr + +/-- Scheduler state. `cur = some (t, ex)`: `t` runs, `ex` = tick rule exemption. + `q d`: ready queue of domain `d`. `wl d`: waiting tasks of domain `d` in the + order they started to wait, with an optional deadline in global ticks. -/ +structure St where + part : Part + rd : Dom + cur : Option (Tid × Bool) + q : Dom → List Tid + wl : Dom → List (Tid × Option Nat) + +/-- Function update. -/ +def upd {α : Type} (f : Dom → α) (d : Dom) (v : α) : Dom → α := + fun x => if x = d then v else f x + +/-- A waiter is expired at tick `n`. -/ +def expired (w : Tid × Option Nat) (n : Nat) : Bool := + match w.2 with + | some k => decide (k ≤ n) + | none => false + +/-- `Env::serve d n` (timed waits only): expired waiters of domain `d` to the + back of `d`'s queue, the last one to start waiting first. That is the + order in which `k0_sched::expired` hands them to `k0_sched::enqueue`: + `arm_timeout` links a waiter at the head of the list and `expired` walks + the list from the head. No other domain is touched. -/ +def serve (s : St) (d n : Nat) : St := + { s with + wl := upd s.wl d ((s.wl d).filter (fun w => !expired w n)) + q := upd s.q d (s.q d ++ (((s.wl d).filter (fun w => expired w n)).reverse).map Prod.fst) } + +/-- `enter(d)`: pop the front of `d`'s queue as a tick entry (no exemption), or idle. -/ +def enter (s : St) (d : Dom) : St := + match s.q d with + | x :: r => { s with q := upd s.q d r, cur := some (x, false) } + | [] => { s with cur := none } + +/-- Boundary parking of the running task: rule applied, then front of the own queue. -/ +def cut (s : St) : St := + match s.cur with + | none => s + | some (c, ex) => + { s with cur := none, + q := upd s.q s.rd + (if ex then c :: s.q s.rd + else match s.q s.rd with + | x :: r => x :: (r ++ [c]) + | [] => [c]) } + +/-- Tick inside the same domain, after `serve`: `Keep` / `Rotate` / idle entry. -/ +def sameStep (s : St) : St := + match s.cur with + | some (c, true) => { s with cur := some (c, false) } + | some (c, false) => + match s.q s.rd with + | x :: r => { s with q := upd s.q s.rd (r ++ [c]), cur := some (x, false) } + | [] => s + | none => enter s s.rd + +/-- `Core::tick`. -/ +def tickStep (s : St) (n : Nat) : St := + if n ≤ s.part.seen then s else + let p := s.part.advance n + let new := p.domNow n + let s1 : St := { s with part := { p with seen := n } } + if new = s.rd then sameStep (serve s1 s.rd n) + else + let s2 : St := { cut s1 with rd := new } + enter (serve s2 new n) new + +/-- Pop the own queue as a between-ticks entry (exemption), or idle. -/ +def popBetween (s : St) : St := + match s.q s.rd with + | x :: r => { s with q := upd s.q s.rd r, cur := some (x, true) } + | [] => { s with cur := none } + +/-- `Core::poll`. -/ +def pollRest (s1 : St) : St := + match s1.cur with + | some _ => s1 + | none => popBetween s1 + +def pollStep (s : St) (n : Nat) : St := + if s.part.seen < n then tickStep s n else pollRest (serve s s.rd n) + +/-- `Core::yield_now`. -/ +def yieldStep (s : St) : St := + match s.cur with + | none => s + | some (c, _) => + match s.q s.rd with + | x :: r => { s with q := upd s.q s.rd (r ++ [c]), cur := some (x, true) } + | [] => s + +variable (dom : Tid → Dom) + +/-- The running task starts to wait (in its own domain's list), then `Core::block`. -/ +def blockStep (s : St) (dl : Option Nat) : St := + match s.cur with + | none => s + | some (c, _) => + popBetween { s with cur := none, wl := upd s.wl (dom c) (s.wl (dom c) ++ [(c, dl)]) } + +/-- `k0_sched::enqueue` of a waiting task: into its OWN domain's queue, never `Core`. -/ +def doWake (s : St) (t : Tid) : St := + if (s.wl (dom t)).any (fun w => w.1 = t) then + { s with wl := upd s.wl (dom t) ((s.wl (dom t)).filter (fun w => !decide (w.1 = t))), + q := upd s.q (dom t) (s.q (dom t) ++ [t]) } + else s + +/-- One step of the model. -/ +def step (s : St) : Ev → St + | .tick n => tickStep s n + | .poll n => pollStep s n + | .yield => yieldStep s + | .block dl => blockStep dom s dl + | .wake t => if s.cur.isSome = true ∧ dom t = s.rd then doWake dom s t else s + | .wakeX t => if s.cur.isSome = true ∧ dom t ≠ s.rd then doWake dom s t else s + | .setTable t => { s with part := s.part.setTable t } + +/-- Run a list of events. -/ +def exec (s : St) : List Ev → St + | [] => s + | e :: es => exec (step dom s e) es + +/-- A state at boot: default table, root domain, `first` running with the + between-ticks exemption (`Core::start`), other tasks given. -/ +def boot (now : Nat) (first : Tid) (q0 : Dom → List Tid) (w0 : Dom → List (Tid × Option Nat)) : St := + { part := { tbl := defaultTable, epoch := now, pend := none, seen := now }, + rd := 0, cur := some (first, true), q := q0, wl := w0 } + +/-! ## Clock part as a function of the public events only -/ + +/-- Effect of an event on the clock part. -/ +def pstep (p : Part) : Ev → Part + | .tick n => pTick p n + | .poll n => pTick p n + | .setTable t => p.setTable t + | _ => p + +def pexec (p : Part) : List Ev → Part + | [] => p + | e :: es => pexec (pstep p e) es + +/-- Public events: ticks and `set_table` calls. For the clock part a `poll n` + is the tick `n`. (A `poll n` with `n <= seen` leaves the clock alone but + still serves the running domain and may start a task.) -/ +inductive Pub where + | tick (n : Nat) + | setTable (t : Table) +deriving DecidableEq + +def pubOf : Ev → Option Pub + | .tick n => some (.tick n) + | .poll n => some (.tick n) + | .setTable t => some (.setTable t) + | _ => none + +/-! ## Quick runs with #eval -/ + +/-- Tasks 0..9 are domain 0, 10..19 domain 1, 20..29 domain 2. -/ +def dom0 (t : Tid) : Dom := t / 10 + +/-- Compact observation of a state. -/ +def St.show (s : St) : String := + s!"rd={s.rd} seen={s.part.seen} cur={s.cur} q={(List.range 3).map s.q} wl={(List.range 3).map s.wl}" + +def sample : St := + boot 0 0 (fun d => if d = 0 then [1] else if d = 1 then [10, 11] else if d = 2 then [20] else []) + (fun d => if d = 1 then [(12, some 5)] else []) + +-- table set at tick 0 takes over at tick 2: [(1,1),(0,1),(2,1)] +#eval + let es := [Ev.setTable [(1,1),(0,1),(2,1)], .tick 1, .tick 2, .tick 3, .tick 4, .tick 5, .tick 9] + let rec go (s : St) : List Ev → List String + | [] => [s.show] + | e :: r => s.show :: go (step dom0 s e) r + go sample es + + +/-! ## Frame lemmas: which fields each primitive touches -/ + +section frame +variable (s : St) (d n : Nat) + +@[simp] theorem serve_part : (serve s d n).part = s.part := rfl +@[simp] theorem serve_rd : (serve s d n).rd = s.rd := rfl +@[simp] theorem serve_cur : (serve s d n).cur = s.cur := rfl + +@[simp] theorem enter_part : (enter s d).part = s.part := by + unfold enter; split <;> rfl +@[simp] theorem enter_rd : (enter s d).rd = s.rd := by + unfold enter; split <;> rfl + +@[simp] theorem cut_part : (cut s).part = s.part := by + unfold cut; split <;> rfl +@[simp] theorem cut_rd : (cut s).rd = s.rd := by + unfold cut; split <;> rfl + +@[simp] theorem sameStep_part : (sameStep s).part = s.part := by + unfold sameStep; split <;> (try split) <;> (try split) <;> simp +@[simp] theorem sameStep_rd : (sameStep s).rd = s.rd := by + unfold sameStep; split <;> (try split) <;> (try split) <;> simp + +@[simp] theorem popBetween_part : (popBetween s).part = s.part := by + unfold popBetween; split <;> rfl +@[simp] theorem popBetween_rd : (popBetween s).rd = s.rd := by + unfold popBetween; split <;> rfl + +end frame + +theorem step_part (s : St) (e : Ev) : (step dom s e).part = pstep s.part e := by + cases e with + | tick n => + simp only [step, tickStep, pstep, pTick] + split + · rfl + · split <;> simp + | poll n => + simp only [step, pollStep, pstep] + split + · next h => + have : ¬ n ≤ s.part.seen := by omega + simp only [tickStep, pTick, this, ite_false] + split <;> simp + · next h => + have : n ≤ s.part.seen := by omega + simp only [pTick, this, ite_true] + unfold pollRest; split <;> simp + | yield => + simp only [step, yieldStep, pstep] + split <;> (try split) <;> rfl + | block dl => + simp only [step, blockStep, pstep] + split <;> simp + | wake t => + simp only [step, pstep] + split + · unfold doWake; split <;> rfl + · rfl + | wakeX t => + simp only [step, pstep] + split + · unfold doWake; split <;> rfl + · rfl + | setTable t => rfl + +theorem step_rd_pub_free (s : St) (e : Ev) (h : pubOf e = none) : (step dom s e).rd = s.rd := by + cases e <;> simp [pubOf] at h + · simp only [step, yieldStep]; split <;> (try split) <;> rfl + · simp only [step, blockStep]; split <;> simp + · simp only [step]; split + · unfold doWake; split <;> rfl + · rfl + · simp only [step]; split + · unfold doWake; split <;> rfl + · rfl + + +/-- Every event keeps `PInv`: a tick promotes a pending table that is due (its + start becomes the epoch), and `set_table` makes one that starts two ticks + ahead. -/ +theorem pinv_pstep (p : Part) (e : Ev) (h : PInv p) : PInv (pstep p e) := by + cases e with + | tick n | poll n => + simp only [pstep, pTick] + split + · exact h + · next hn => + unfold Part.advance + rcases hp : p.pend with _ | ⟨s0, t0⟩ + · refine ⟨?_, ?_⟩ + · have := h.epoch_le; simp; omega + · intro k t hkt; simp [hp] at hkt + · by_cases hs : s0 ≤ n + · simp only [hs, ite_true] + refine ⟨hs, ?_⟩ + intro k t hkt; simp at hkt + · simp only [hs, ite_false] + refine ⟨?_, ?_⟩ + · have := h.epoch_le; simp; omega + · intro k t hkt + simp [hp] at hkt + obtain ⟨rfl, rfl⟩ := hkt + show n < s0 + omega + | setTable t => + refine ⟨h.epoch_le, ?_⟩ + intro k t' hkt + simp only [pstep, Part.setTable, Option.some.injEq, Prod.mk.injEq] at hkt + show p.seen < k + omega + | yield | block _ | wake _ | wakeX _ => exact h + +theorem pinv_pexec (p : Part) (es : List Ev) (h : PInv p) : PInv (pexec p es) := by + induction es generalizing p with + | nil => exact h + | cons e es ih => exact ih _ (pinv_pstep p e h) + + +/-! ## Invariants -/ + +/-- Membership facts of queues and wait lists: a task sits only in its own + domain's queue and wait list. -/ +structure QW (s : St) : Prop where + q_dom : ∀ d t, t ∈ s.q d → dom t = d + wl_dom : ∀ d w, w ∈ s.wl d → dom w.1 = d + +/-- The queue and running-task part of the invariant. -/ +structure Inv0 (s : St) : Prop where + rd_plan : s.rd = s.part.plan s.part.seen + qw : QW dom s + cur_dom : ∀ t b, s.cur = some (t, b) → dom t = s.rd + idle_empty : s.cur = none → s.q s.rd = [] + +/-- The invariant of every reachable state. -/ +structure Inv (s : St) : Prop extends Inv0 dom s where + clock : PInv s.part + +theorem inv_boot (now first : Nat) (q0 : Dom → List Tid) (w0 : Dom → List (Tid × Option Nat)) + (hq : ∀ d t, t ∈ q0 d → dom t = d) (hw : ∀ d w, w ∈ w0 d → dom w.1 = d) + (hf : dom first = 0) : Inv dom (boot now first q0 w0) := by + refine ⟨⟨?_, ⟨hq, hw⟩, ?_, ?_⟩, ?_⟩ + · simp [boot, Part.plan, defaultTable, domAt, domAtPos, cycle] + · intro t b h + simp [boot] at h + simp [boot, ← h.1, hf] + · intro h; simp [boot] at h + · exact ⟨Nat.le_refl _, by intro k t h; simp [boot] at h⟩ + +section prim +variable {dom} + +theorem upd_same {α : Type} (f : Dom → α) (d : Dom) (v : α) : upd f d v d = v := by simp [upd] +theorem upd_other {α : Type} (f : Dom → α) (d x : Dom) (v : α) (h : x ≠ d) : upd f d v x = f x := by + simp [upd, h] + +theorem serve_QW (s : St) (d n : Nat) (h : QW dom s) : QW dom (serve s d n) := by + constructor + · intro x t ht + simp only [serve, upd] at ht + split at ht + · next hx => + subst hx + rcases List.mem_append.mp ht with h1 | h1 + · exact h.q_dom _ _ h1 + · obtain ⟨w, hw, rfl⟩ := List.mem_map.mp h1 + exact h.wl_dom _ _ (List.mem_filter.mp (List.mem_reverse.mp hw)).1 + · exact h.q_dom _ _ ht + · intro x w hw + simp only [serve, upd] at hw + split at hw + · next hx => subst hx; exact h.wl_dom _ _ (List.mem_filter.mp hw).1 + · exact h.wl_dom _ _ hw + +theorem enter_QW (s : St) (d : Dom) (h : QW dom s) : QW dom (enter s d) := by + unfold enter + split + · next x r hr => + constructor + · intro y t ht + simp only [upd] at ht + split at ht + · next hy => subst hy; exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_of_mem _ ht) + · exact h.q_dom _ _ ht + · exact h.wl_dom + · exact ⟨h.q_dom, h.wl_dom⟩ + +theorem enter_cur_dom (s : St) (h : QW dom s) : + ∀ t b, (enter s s.rd).cur = some (t, b) → dom t = s.rd := by + intro t b hc + unfold enter at hc + split at hc + · next x r hr => + simp at hc + rw [← hc.1] + exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_self) + · simp at hc + +theorem enter_idle (s : St) (d : Dom) : (enter s d).cur = none → (enter s d).q d = [] := by + unfold enter + split + · next x r hr => simp + · next hr => intro _; simpa using hr + +theorem cut_QW (s : St) (h : QW dom s) (hc : ∀ t b, s.cur = some (t, b) → dom t = s.rd) : + QW dom (cut s) := by + unfold cut + split + · exact h + · next c ex hcur => + have hcd : dom c = s.rd := hc c ex hcur + constructor + · intro y t ht + simp only [upd] at ht + split at ht + · next hy => + subst hy + split at ht + · rcases List.mem_cons.mp ht with rfl | h1 + · exact hcd + · exact h.q_dom _ _ h1 + · split at ht + · next x r hr => + rcases List.mem_cons.mp ht with rfl | h1 + · exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_self) + · rcases List.mem_append.mp h1 with h2 | h2 + · exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_of_mem _ h2) + · simp at h2; subst h2; exact hcd + · simp at ht; subst ht; exact hcd + · exact h.q_dom _ _ ht + · exact h.wl_dom + +theorem sameStep_QW (s : St) (h : QW dom s) (hc : ∀ t b, s.cur = some (t, b) → dom t = s.rd) : + QW dom (sameStep s) := by + unfold sameStep + split + · exact ⟨h.q_dom, h.wl_dom⟩ + · next c hcur => + split + · next x r hr => + have hcd : dom c = s.rd := hc c false hcur + constructor + · intro y t ht + simp only [upd] at ht + split at ht + · next hy => + subst hy + rcases List.mem_append.mp ht with h2 | h2 + · exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_of_mem _ h2) + · simp at h2; subst h2; exact hcd + · exact h.q_dom _ _ ht + · exact h.wl_dom + · exact h + · exact enter_QW s _ h + +theorem sameStep_cur_dom (s : St) (h : QW dom s) (hc : ∀ t b, s.cur = some (t, b) → dom t = s.rd) : + ∀ t b, (sameStep s).cur = some (t, b) → dom t = s.rd := by + intro t b hb + unfold sameStep at hb + split at hb + · next c hcur => simp at hb; rw [← hb.1]; exact hc c true hcur + · next c hcur => + split at hb + · next x r hr => + simp at hb; rw [← hb.1] + exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_self) + · exact hc t b hb + · exact enter_cur_dom s h t b hb + +theorem sameStep_idle (s : St) : (sameStep s).cur = none → (sameStep s).q s.rd = [] := by + intro hn + unfold sameStep at hn ⊢ + split at hn + · simp at hn + · split at hn + · simp at hn + · simp_all + · exact enter_idle s s.rd hn + +theorem popBetween_QW (s : St) (h : QW dom s) : QW dom (popBetween s) := by + unfold popBetween + split + · next x r hr => + constructor + · intro y t ht + simp only [upd] at ht + split at ht + · next hy => subst hy; exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_of_mem _ ht) + · exact h.q_dom _ _ ht + · exact h.wl_dom + · exact ⟨h.q_dom, h.wl_dom⟩ + +theorem popBetween_cur_dom (s : St) (h : QW dom s) : + ∀ t b, (popBetween s).cur = some (t, b) → dom t = s.rd := by + intro t b hb + unfold popBetween at hb + split at hb + · next x r hr => + simp at hb; rw [← hb.1] + exact h.q_dom _ _ (by rw [hr]; exact List.mem_cons_self) + · simp at hb + +theorem popBetween_idle (s : St) : (popBetween s).cur = none → (popBetween s).q s.rd = [] := by + unfold popBetween + split + · next x r hr => simp + · next hr => intro _; simpa using hr + + +theorem plan_tick_part (p : Part) (n : Nat) : + ({ p.advance n with seen := n } : Part).plan n = p.plan n := by + rw [plan_seen, plan_advance _ _ _ (Nat.le_refl n)] + +theorem inv_tick (s : St) (hi : Inv0 dom s) (n : Nat) : Inv0 dom (tickStep s n) := by + unfold tickStep + split + · exact hi + · next hn => + have hqw : QW dom { s with part := { s.part.advance n with seen := n } } := ⟨hi.qw.q_dom, hi.qw.wl_dom⟩ + by_cases hnew : (s.part.advance n).domNow n = s.rd + · simp only [hnew, ite_true] + have hpl : s.rd = s.part.plan n := by rw [← domNow_advance, hnew] + have hq1 := serve_QW _ s.rd n hqw + refine ⟨?_, sameStep_QW _ hq1 ?_, ?_, ?_⟩ + · simp only [sameStep_part, sameStep_rd, serve_part, serve_rd] + rw [plan_tick_part]; exact hpl + · intro t b h; simpa using hi.cur_dom t b h + · intro t b h + have := sameStep_cur_dom _ hq1 (by intro t b h; simpa using hi.cur_dom t b h) t b h + simpa using this + · intro h + have := sameStep_idle (serve { s with part := { s.part.advance n with seen := n } } s.rd n) h + simpa using this + · simp only [hnew, ite_false] + have hc1 : ∀ t b, ({ s with part := { s.part.advance n with seen := n } } : St).cur = some (t, b) → + dom t = ({ s with part := { s.part.advance n with seen := n } } : St).rd := by + intro t b h; simpa using hi.cur_dom t b h + have hcut := cut_QW _ hqw hc1 + have hq2 : QW dom ({ cut { s with part := { s.part.advance n with seen := n } } with rd := (s.part.advance n).domNow n } : St) := + ⟨hcut.q_dom, hcut.wl_dom⟩ + have hq3 := serve_QW _ ((s.part.advance n).domNow n) n hq2 + have hpl : (s.part.advance n).domNow n = s.part.plan n := domNow_advance _ _ + refine ⟨?_, enter_QW _ _ hq3, ?_, ?_⟩ + · simp only [enter_part, serve_part, enter_rd, serve_rd, cut_part] + rw [plan_tick_part]; exact hpl + · intro t b h + have := enter_cur_dom _ hq3 t b (by simpa using h) + simpa using this + · intro h + have := enter_idle (serve { cut { s with part := { s.part.advance n with seen := n } } with rd := (s.part.advance n).domNow n } ((s.part.advance n).domNow n) n) ((s.part.advance n).domNow n) (by simpa using h) + simpa using this + + +theorem inv_poll (s : St) (hi : Inv0 dom s) (n : Nat) : Inv0 dom (pollStep s n) := by + unfold pollStep + split + · exact inv_tick s hi n + · have hq1 := serve_QW s s.rd n hi.qw + unfold pollRest + split + · next c hc => + refine ⟨by simpa using hi.rd_plan, hq1, ?_, ?_⟩ + · intro t b h; simpa using hi.cur_dom t b h + · intro h; simp_all + · next hc => + refine ⟨by simpa using hi.rd_plan, popBetween_QW _ hq1, ?_, ?_⟩ + · intro t b h + have := popBetween_cur_dom _ hq1 t b h + simpa using this + · intro h + have := popBetween_idle (serve s s.rd n) h + simpa using this + +theorem inv_yield (s : St) (hi : Inv0 dom s) : Inv0 dom (yieldStep s) := by + unfold yieldStep + split + · exact hi + · next c ex hc => + split + · next x r hr => + have hcd : dom c = s.rd := hi.cur_dom c ex hc + refine ⟨hi.rd_plan, ⟨?_, hi.qw.wl_dom⟩, ?_, ?_⟩ + · intro y t ht + simp only [upd] at ht + split at ht + · next hy => + subst hy + rcases List.mem_append.mp ht with h2 | h2 + · exact hi.qw.q_dom _ _ (by rw [hr]; exact List.mem_cons_of_mem _ h2) + · simp at h2; subst h2; exact hcd + · exact hi.qw.q_dom _ _ ht + · intro t b h + simp at h; rw [← h.1] + exact hi.qw.q_dom _ _ (by rw [hr]; exact List.mem_cons_self) + · intro h; simp at h + · exact hi + +theorem inv_block (s : St) (hi : Inv0 dom s) (dl : Option Nat) : Inv0 dom (blockStep dom s dl) := by + unfold blockStep + split + · exact hi + · next c ex hc => + have hq1 : QW dom ({ s with cur := none, wl := upd s.wl (dom c) (s.wl (dom c) ++ [(c, dl)]) } : St) := by + refine ⟨hi.qw.q_dom, ?_⟩ + intro y w hw + simp only [upd] at hw + split at hw + · next hy => + subst hy + rcases List.mem_append.mp hw with h2 | h2 + · exact hi.qw.wl_dom _ _ h2 + · simp at h2; subst h2; rfl + · exact hi.qw.wl_dom _ _ hw + refine ⟨by simpa using hi.rd_plan, popBetween_QW _ hq1, ?_, ?_⟩ + · intro t b h + have := popBetween_cur_dom _ hq1 t b h + simpa using this + · intro h + have := popBetween_idle ({ s with cur := none, wl := upd s.wl (dom c) (s.wl (dom c) ++ [(c, dl)]) } : St) h + simpa using this + +theorem doWake_QW (s : St) (t : Tid) (h : QW dom s) : QW dom (doWake dom s t) := by + unfold doWake + split + · constructor + · intro y u hu + simp only [upd] at hu + split at hu + · next hy => + subst hy + rcases List.mem_append.mp hu with h2 | h2 + · exact h.q_dom _ _ h2 + · simp at h2; subst h2; rfl + · exact h.q_dom _ _ hu + · intro y w hw + simp only [upd] at hw + split at hw + · next hy => subst hy; exact h.wl_dom _ _ (List.mem_filter.mp hw).1 + · exact h.wl_dom _ _ hw + · exact h + +theorem inv_wake_gen (s : St) (hi : Inv0 dom s) (t : Tid) (hg : s.cur.isSome = true) : + Inv0 dom (doWake dom s t) := by + have hq := doWake_QW s t hi.qw + have hcur : (doWake dom s t).cur = s.cur := by unfold doWake; split <;> rfl + have hrd : (doWake dom s t).rd = s.rd := by unfold doWake; split <;> rfl + have hpt : (doWake dom s t).part = s.part := by unfold doWake; split <;> rfl + refine ⟨by rw [hrd, hpt]; exact hi.rd_plan, hq, ?_, ?_⟩ + · intro u b h; rw [hcur] at h; rw [hrd]; exact hi.cur_dom u b h + · intro h; rw [hcur] at h; rw [h] at hg; simp at hg + +theorem inv_step (s : St) (hi : Inv dom s) (e : Ev) : Inv dom (step dom s e) := by + refine ⟨?_, by rw [step_part]; exact pinv_pstep _ _ hi.clock⟩ + cases e with + | tick n => exact inv_tick s hi.toInv0 n + | poll n => exact inv_poll s hi.toInv0 n + | yield => exact inv_yield s hi.toInv0 + | block dl => exact inv_block s hi.toInv0 dl + | wake t => + simp only [step] + split + · next h => exact inv_wake_gen s hi.toInv0 t h.1 + · exact hi.toInv0 + | wakeX t => + simp only [step] + split + · next h => exact inv_wake_gen s hi.toInv0 t h.1 + · exact hi.toInv0 + | setTable t => + refine ⟨?_, ⟨hi.qw.q_dom, hi.qw.wl_dom⟩, hi.cur_dom, hi.idle_empty⟩ + show s.rd = (s.part.setTable t).plan (s.part.setTable t).seen + have : (s.part.setTable t).seen = s.part.seen := rfl + rw [this, plan_setTable_now _ _ hi.clock.pend_after]; exact hi.rd_plan + +theorem inv_exec (s : St) (hi : Inv dom s) (es : List Ev) : Inv dom (exec dom s es) := by + induction es generalizing s with + | nil => exact hi + | cons e es ih => exact ih _ (inv_step s hi e) + + +/-! ## Theorems (3), (4), (2) at the level of events -/ + +/-- Effect of a public event on the clock part. -/ +def pstepP (p : Part) : Pub → Part + | .tick n => pTick p n + | .setTable t => p.setTable t + +def pexecP (p : Part) : List Pub → Part + | [] => p + | e :: es => pexecP (pstepP p e) es + +theorem pstep_eq (p : Part) (e : Ev) : + pstep p e = match pubOf e with | none => p | some b => pstepP p b := by + cases e <;> rfl + +theorem pexec_eq (p : Part) (es : List Ev) : pexec p es = pexecP p (es.filterMap pubOf) := by + induction es generalizing p with + | nil => rfl + | cons e es ih => + simp only [pexec, List.filterMap_cons] + rw [pstep_eq] + cases h : pubOf e with + | none => simpa using ih p + | some b => simpa [pexecP] using ih (pstepP p b) + +theorem exec_part (s : St) (es : List Ev) : (exec dom s es).part = pexec s.part es := by + induction es generalizing s with + | nil => rfl + | cons e es ih => simp only [exec, pexec]; rw [ih, step_part] + +/-- (3) The running domain after any sequence of events is the domain of the last + processed tick, and that is a function of the clock part alone, which in turn + is a function of the public events (ticks and `set_table` calls) only. -/ +theorem running_domain_function (s : St) (hi : Inv dom s) (es : List Ev) : + (exec dom s es).rd = + (pexecP s.part (es.filterMap pubOf)).plan (pexecP s.part (es.filterMap pubOf)).seen := by + have h := (inv_exec s hi es).rd_plan + rw [exec_part, pexec_eq] at h + exact h + +/-- (3') Two runs with the same clock part and the same public events end in + the same running domain, whatever the other events and queues are. -/ +theorem running_domain_same (s s' : St) (hi : Inv dom s) (hi' : Inv dom s') + (hp : s.part = s'.part) (es es' : List Ev) (h : es.filterMap pubOf = es'.filterMap pubOf) : + (exec dom s es).rd = (exec dom s' es').rd := by + rw [running_domain_function s hi, running_domain_function s' hi', hp, h] + +/-- (4) No slack donation. After any sequence of events: a task that runs belongs + to the running domain, which is the domain of the last processed tick; and if + the core idles, the running domain's ready queue is empty. -/ +theorem no_slack_donation (s : St) (hi : Inv dom s) (es : List Ev) : + (∀ t b, (exec dom s es).cur = some (t, b) → + dom t = (exec dom s es).rd ∧ + dom t = (exec dom s es).part.plan (exec dom s es).part.seen) ∧ + ((exec dom s es).cur = none → (exec dom s es).q (exec dom s es).rd = []) := by + have h := inv_exec s hi es + refine ⟨fun t b hc => ⟨h.cur_dom t b hc, ?_⟩, h.idle_empty⟩ + rw [h.cur_dom t b hc]; exact h.rd_plan + +theorem seen_mono_pstep (p : Part) (e : Ev) : p.seen ≤ (pstep p e).seen := by + cases e <;> simp [pstep, pTick, Part.setTable, Part.advance] <;> + (try split) <;> (try split) <;> simp <;> omega + +theorem seen_mono_pexec (p : Part) (es : List Ev) : p.seen ≤ (pexec p es).seen := by + induction es generalizing p with + | nil => exact Nat.le_refl _ + | cons e es ih => exact Nat.le_trans (seen_mono_pstep p e) (ih _) + +def NoSet : Ev → Prop + | .setTable _ => False + | _ => True + +theorem plan_pstep_noset (p : Part) (e : Ev) (h : NoSet e) (k : Nat) (hk : (pstep p e).seen ≤ k) : + (pstep p e).plan k = p.plan k := by + cases e with + | tick n | poll n => + by_cases hn : n ≤ p.seen + · simp [pstep, pTick, hn] + · have hk' : n ≤ k := by simpa [pstep, pTick, hn] using hk + simp [pstep, pTick, hn, plan_seen, plan_advance p n k hk'] + | setTable t => exact h.elim + | _ => rfl + +theorem plan_pexec_noset (p : Part) (es : List Ev) (h : ∀ e ∈ es, NoSet e) (k : Nat) + (hk : (pexec p es).seen ≤ k) : (pexec p es).plan k = p.plan k := by + induction es generalizing p with + | nil => rfl + | cons e es ih => + simp only [pexec] at hk ⊢ + rw [ih (pstep p e) (fun e' he' => h e' (List.mem_cons_of_mem _ he')) hk] + exact plan_pstep_noset p e (h e List.mem_cons_self) k + (Nat.le_trans (seen_mono_pexec _ es) hk) + +theorem setTable_seen (p : Part) (t : Table) : (p.setTable t).seen = p.seen := rfl + +/-- (2) `table_effective_at`: after `set_table` with last processed tick `n` and no later + `set_table`, if the last processed tick `k` is `>= n + 2`, the running domain + is the new table's entry at `(k - (n + 2)) mod cycle`. -/ +theorem table_effective_at (s : St) (hi : Inv dom s) (t : Table) (es : List Ev) + (hno : ∀ e ∈ es, NoSet e) + (hk : s.part.seen + 2 ≤ (exec dom s (.setTable t :: es)).part.seen) : + (exec dom s (.setTable t :: es)).rd = + domAtPos t (((exec dom s (.setTable t :: es)).part.seen - (s.part.seen + 2)) % cycle t) := by + have h := (inv_exec s hi (.setTable t :: es)).rd_plan + rw [h] + have hp : (exec dom s (.setTable t :: es)).part = pexec (s.part.setTable t) es := by + rw [exec_part]; rfl + rw [hp] at hk ⊢ + rw [plan_pexec_noset _ es hno _ (Nat.le_refl _)] + exact plan_setTable_ge _ _ _ hk + + +end prim + +/-! ## Non-interference -/ + +section ni +variable (dom : Tid → Dom) + +/-- The part of the state that domain `D` can see, besides the public clock: + its queue, its waiting list, and which of its tasks runs (with the slice bit). -/ +structure View where + q : List Tid + wl : List (Tid × Option Nat) + run : Option (Tid × Bool) +deriving DecidableEq, Repr + +/-- `D`'s view of a state. -/ +def view (D : Dom) (s : St) : View := + { q := s.q D, wl := s.wl D, + run := match s.cur with + | some (t, b) => if dom t = D then some (t, b) else none + | none => none } + +/-- The views after every step: the initial one and one per event. -/ +def viewTrace (D : Dom) (s : St) : List Ev → List View + | [] => [view dom D s] + | e :: es => view dom D s :: viewTrace D (step dom s e) es + +end ni + +section ni2 +variable {dom : Tid → Dom} + +/-- Relation between two runs seen from `D`, without the running task. -/ +structure R0 (D : Dom) (s s' : St) : Prop where + part : s.part = s'.part + rd : s.rd = s'.rd + q : s.q D = s'.q D + wl : s.wl D = s'.wl D + +/-- Relation between two runs seen from `D`: same clock part, same running domain, + same queue and waiting list of `D`, and the same running task when `D` runs. + Nothing is said about other domains. -/ +structure R (D : Dom) (s s' : St) : Prop extends R0 D s s' where + cur : s.rd = D → s.cur = s'.cur + +theorem R0.trans {D : Dom} {a b c : St} (h1 : R0 D a b) (h2 : R0 D b c) : R0 D a c := + ⟨h1.part.trans h2.part, h1.rd.trans h2.rd, h1.q.trans h2.q, h1.wl.trans h2.wl⟩ + +theorem R0.symm {D : Dom} {a b : St} (h1 : R0 D a b) : R0 D b a := + ⟨h1.part.symm, h1.rd.symm, h1.q.symm, h1.wl.symm⟩ + +theorem R0.refl (D : Dom) (a : St) : R0 D a a := ⟨rfl, rfl, rfl, rfl⟩ + +/-- Equal views from the relation, for two well formed states. -/ +theorem view_eq {D : Dom} {s s' : St} (hi : Inv dom s) (hi' : Inv dom s') (h : R D s s') : + view dom D s = view dom D s' := by + unfold view + have hq := h.q + have hw := h.wl + by_cases hD : s.rd = D + · have hc := h.cur hD + simp [hq, hw, hc] + · have e1 : (match s.cur with | some (t, b) => if dom t = D then some (t, b) else none | none => none) = none := by + split + · next t b hc => + have : dom t ≠ D := by rw [hi.cur_dom t b hc]; exact hD + simp [this] + · rfl + have e2 : (match s'.cur with | some (t, b) => if dom t = D then some (t, b) else none | none => none) = none := by + split + · next t b hc => + have : dom t ≠ D := by rw [hi'.cur_dom t b hc, ← h.rd]; exact hD + simp [this] + · rfl + simp [hq, hw, e1, e2] + +theorem R_of_other {D : Dom} {s s' x x' : St} (h : R D s s') (hne : s.rd ≠ D) + (hx : R0 D s x) (hx' : R0 D s' x') : R D x x' := + ⟨hx.symm.trans (h.toR0.trans hx'), fun hD => absurd (hx.rd.trans hD) hne⟩ + +/-- Frame: a step that changes nothing `D` sees and keeps `rd` and `cur`. -/ +theorem R_frame {D : Dom} {s s' x x' : St} (h : R D s s') (hx : R0 D s x) (hx' : R0 D s' x') + (hc : x.cur = s.cur) (hc' : x'.cur = s'.cur) : R D x x' := by + refine ⟨hx.symm.trans (h.toR0.trans hx'), ?_⟩ + intro hD + rw [hc, hc'] + apply h.cur + rw [hx.rd]; exact hD + +/-! frame lemmas: operations on another domain are invisible to `D` -/ + +theorem serve_R0_other (s : St) (d n D : Nat) (h : d ≠ D) : R0 D s (serve s d n) := by + refine ⟨rfl, rfl, ?_, ?_⟩ <;> simp [serve, upd, Ne.symm h] + +theorem enter_R0_other (s : St) (d D : Nat) (h : d ≠ D) : R0 D s (enter s d) := by + unfold enter + split + · refine ⟨rfl, rfl, ?_, rfl⟩ + simp [upd, Ne.symm h] + · exact ⟨rfl, rfl, rfl, rfl⟩ + +theorem cut_R0_other (s : St) (D : Nat) (h : s.rd ≠ D) : R0 D s (cut s) := by + unfold cut + split + · exact R0.refl _ _ + · refine ⟨rfl, rfl, ?_, rfl⟩ + simp [upd, Ne.symm h] + +theorem sameStep_R0_other (s : St) (D : Nat) (h : s.rd ≠ D) : R0 D s (sameStep s) := by + unfold sameStep + split + · exact ⟨rfl, rfl, rfl, rfl⟩ + · split + · refine ⟨rfl, rfl, ?_, rfl⟩ + simp [upd, Ne.symm h] + · exact R0.refl _ _ + · exact enter_R0_other s _ D h + +theorem popBetween_R0_other (s : St) (D : Nat) (h : s.rd ≠ D) : R0 D s (popBetween s) := by + unfold popBetween + split + · refine ⟨rfl, rfl, ?_, rfl⟩ + simp [upd, Ne.symm h] + · exact ⟨rfl, rfl, rfl, rfl⟩ + +theorem yield_R0_other (s : St) (D : Nat) (h : s.rd ≠ D) : R0 D s (yieldStep s) := by + unfold yieldStep + split + · exact R0.refl _ _ + · split + · refine ⟨rfl, rfl, ?_, rfl⟩ + simp [upd, Ne.symm h] + · exact R0.refl _ _ + +theorem block_R0_other (s : St) (hi : Inv dom s) (D : Nat) (dl : Option Nat) (h : s.rd ≠ D) : + R0 D s (blockStep dom s dl) := by + unfold blockStep + split + · exact R0.refl _ _ + · next c ex hc => + have hcd : dom c ≠ D := by rw [hi.cur_dom c ex hc]; exact h + have h1 : R0 D s { s with cur := none, wl := upd s.wl (dom c) (s.wl (dom c) ++ [(c, dl)]) } := + ⟨rfl, rfl, rfl, by simp [upd, Ne.symm hcd]⟩ + exact h1.trans (popBetween_R0_other _ D h) + +theorem doWake_R0_other (s : St) (t D : Nat) (h : dom t ≠ D) : R0 D s (doWake dom s t) := by + unfold doWake + split + · refine ⟨rfl, rfl, ?_, ?_⟩ <;> simp [upd, Ne.symm h] + · exact R0.refl _ _ + + +/-! pair lemmas: the primitives applied to two related states -/ + +theorem R0_serve {D : Dom} {s s' : St} (h : R0 D s s') (d n : Nat) : + R0 D (serve s d n) (serve s' d n) := by + refine ⟨h.part, h.rd, ?_, ?_⟩ + · simp only [serve, upd] + split + · next hDd => subst hDd; rw [h.q, h.wl] + · exact h.q + · simp only [serve, upd] + split + · next hDd => subst hDd; rw [h.wl] + · exact h.wl + +theorem R_serve {D : Dom} {s s' : St} (h : R D s s') (d n : Nat) : + R D (serve s d n) (serve s' d n) := + ⟨R0_serve h.toR0 d n, fun hD => h.cur hD⟩ + +theorem R_withPart {D : Dom} {s s' : St} (h : R D s s') (p : Part) : + R D { s with part := p } { s' with part := p } := + ⟨⟨rfl, h.rd, h.q, h.wl⟩, fun hD => by simpa using h.cur hD⟩ + +theorem R_enter {D : Dom} {s s' : St} (h : R0 D s s') : + R D (enter s s.rd) (enter s' s.rd) := by + by_cases hD : s.rd = D + · subst hD + have hq : s'.q s.rd = s.q s.rd := h.q.symm + unfold enter + rw [hq] + split + · refine ⟨⟨h.part, h.rd, ?_, h.wl⟩, fun _ => rfl⟩ + simp [upd] + · exact ⟨⟨h.part, h.rd, h.q, h.wl⟩, fun _ => rfl⟩ + · exact ⟨(enter_R0_other s _ D hD).symm.trans (h.trans (enter_R0_other s' s.rd D hD)), + fun hh => absurd (by simpa using hh) hD⟩ + +theorem R0_cut {D : Dom} {s s' : St} (h : R D s s') : R0 D (cut s) (cut s') := by + by_cases hD : s.rd = D + · subst hD + have hc := h.cur rfl + have hr := h.rd + have hq : s'.q s.rd = s.q s.rd := h.q.symm + unfold cut + rw [← hc, ← hr] + split + · exact h.toR0 + · refine ⟨h.part, rfl, ?_, h.wl⟩ + simp [upd, hq] + · exact (cut_R0_other s D hD).symm.trans (h.toR0.trans (cut_R0_other s' D (by rw [← h.rd]; exact hD))) + +theorem R_sameStep {D : Dom} {s s' : St} (h : R D s s') : R D (sameStep s) (sameStep s') := by + by_cases hD : s.rd = D + · subst hD + have hc := h.cur rfl + have hr := h.rd + have hq : s'.q s.rd = s.q s.rd := h.q.symm + unfold sameStep + rw [← hc, ← hr, hq] + split + · exact ⟨⟨h.part, rfl, h.q, h.wl⟩, fun _ => rfl⟩ + · split + · refine ⟨⟨h.part, rfl, ?_, h.wl⟩, fun _ => rfl⟩ + simp [upd] + · exact ⟨⟨h.part, h.rd, h.q, h.wl⟩, fun _ => hc⟩ + · exact R_enter h.toR0 + · exact R_of_other h hD (sameStep_R0_other s D hD) + (sameStep_R0_other s' D (by rw [← h.rd]; exact hD)) + +theorem R_popBetween {D : Dom} {s s' : St} (h : R D s s') : R D (popBetween s) (popBetween s') := by + by_cases hD : s.rd = D + · subst hD + have hr := h.rd + have hq : s'.q s.rd = s.q s.rd := h.q.symm + unfold popBetween + rw [← hr, hq] + split + · refine ⟨⟨h.part, rfl, ?_, h.wl⟩, fun _ => rfl⟩ + simp [upd] + · exact ⟨⟨h.part, rfl, h.q, h.wl⟩, fun _ => rfl⟩ + · exact R_of_other h hD (popBetween_R0_other s D hD) + (popBetween_R0_other s' D (by rw [← h.rd]; exact hD)) + +theorem R_pollRest {D : Dom} {s s' : St} (h : R D s s') : R D (pollRest s) (pollRest s') := by + by_cases hD : s.rd = D + · have hc := h.cur hD + unfold pollRest + rw [← hc] + split + · exact h + · exact R_popBetween h + · have e1 : R0 D s (pollRest s) := by + unfold pollRest; split + · exact R0.refl _ _ + · exact popBetween_R0_other s D hD + have e2 : R0 D s' (pollRest s') := by + unfold pollRest; split + · exact R0.refl _ _ + · exact popBetween_R0_other s' D (by rw [← h.rd]; exact hD) + exact R_of_other h hD e1 e2 + +theorem R_tick {D : Dom} {s s' : St} (h : R D s s') (n : Nat) : + R D (tickStep s n) (tickStep s' n) := by + obtain ⟨⟨hp, hr, hq, hw⟩, hc⟩ := h + obtain ⟨p', rd', c', q', w'⟩ := s' + dsimp only at hp hr hq hw hc + subst hp + subst hr + have h : R D s ⟨s.part, s.rd, c', q', w'⟩ := ⟨⟨rfl, rfl, hq, hw⟩, hc⟩ + unfold tickStep + by_cases h1 : n ≤ s.part.seen + · simp only [h1, ite_true]; exact h + · simp only [h1, ite_false] + have h2 := R_withPart h { s.part.advance n with seen := n } + by_cases hnew : (s.part.advance n).domNow n = s.rd + · simp only [hnew, ite_true] + exact R_sameStep (R_serve h2 s.rd n) + · simp only [hnew, ite_false] + have h3 := R0_cut h2 + have h4 := R0_serve (⟨h3.part, rfl, h3.q, h3.wl⟩ : + R0 D ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) + ({ cut { (⟨s.part, s.rd, c', q', w'⟩ : St) with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St)) ((s.part.advance n).domNow n) n + exact R_enter h4 + +theorem R_poll {D : Dom} {s s' : St} (h : R D s s') (n : Nat) : + R D (pollStep s n) (pollStep s' n) := by + have hp := h.part + have hr := h.rd + obtain ⟨⟨hp, hr, hq, hw⟩, hc⟩ := h + obtain ⟨p', rd', c', q', w'⟩ := s' + dsimp only at hp hr hq hw hc + subst hp + subst hr + have h : R D s ⟨s.part, s.rd, c', q', w'⟩ := ⟨⟨rfl, rfl, hq, hw⟩, hc⟩ + unfold pollStep + by_cases h1 : s.part.seen < n + · simp only [h1, ite_true]; exact R_tick h n + · simp only [h1, ite_false] + exact R_pollRest (R_serve h s.rd n) + +theorem R_setTable {D : Dom} {s s' : St} (h : R D s s') (t : Table) : + R D (step dom s (.setTable t)) (step dom s' (.setTable t)) := by + simp only [step] + rw [← h.part] + exact R_withPart h _ + + +/-! actions of the running task -/ + +/-- No wake across domains into `D`. -/ +def NoCross (dom : Tid → Dom) (D : Dom) : Ev → Prop + | .wakeX t => dom t ≠ D + | _ => True + +theorem act_R0_other {D : Dom} {s : St} (hi : Inv dom s) (hne : s.rd ≠ D) (e : Ev) + (hnc : NoCross dom D e) : R0 D s (step dom s e) ∨ pubOf e ≠ none := by + by_cases hp : pubOf e = none + · left + cases e with + | tick n => simp [pubOf] at hp + | poll n => simp [pubOf] at hp + | setTable t => simp [pubOf] at hp + | yield => exact yield_R0_other s D hne + | block dl => exact block_R0_other s hi D dl hne + | wake t => + simp only [step] + split + · next hg => exact doWake_R0_other s t D (by rw [hg.2]; exact hne) + · exact R0.refl _ _ + | wakeX t => + simp only [step] + split + · exact doWake_R0_other s t D hnc + · exact R0.refl _ _ + · right; exact hp + +theorem R_wakeX {D : Dom} {s s' : St} (h : R D s s') (t : Tid) (hnc : dom t ≠ D) : + R D (step dom s (.wakeX t)) (step dom s' (.wakeX t)) := by + have e1 : R0 D s (step dom s (.wakeX t)) := by + simp only [step]; split + · exact doWake_R0_other s t D hnc + · exact R0.refl _ _ + have e2 : R0 D s' (step dom s' (.wakeX t)) := by + simp only [step]; split + · exact doWake_R0_other s' t D hnc + · exact R0.refl _ _ + have c1 : (step dom s (.wakeX t)).cur = s.cur := by + simp only [step]; split + · unfold doWake; split <;> rfl + · rfl + have c2 : (step dom s' (.wakeX t)).cur = s'.cur := by + simp only [step]; split + · unfold doWake; split <;> rfl + · rfl + exact R_frame h e1 e2 c1 c2 + +theorem R_yield {D : Dom} {s s' : St} (h : R D s s') (hD : s.rd = D) : + R D (yieldStep s) (yieldStep s') := by + obtain ⟨⟨hp, hr, hq, hw⟩, hc⟩ := h + obtain ⟨p', rd', c', q', w'⟩ := s' + dsimp only at hp hr hq hw hc + have hc := hc hD + subst hp; subst hr; subst hc; subst hD + have hq' : q' s.rd = s.q s.rd := hq.symm + unfold yieldStep + dsimp only + rw [hq'] + split + · exact ⟨⟨rfl, rfl, hq, hw⟩, fun _ => rfl⟩ + · split + · refine ⟨⟨rfl, rfl, ?_, hw⟩, fun _ => rfl⟩ + simp [upd] + · exact ⟨⟨rfl, rfl, hq, hw⟩, fun _ => rfl⟩ + +theorem R_block {D : Dom} {s s' : St} (hi : Inv dom s) (h : R D s s') (hD : s.rd = D) (dl : Option Nat) : + R D (blockStep dom s dl) (blockStep dom s' dl) := by + obtain ⟨⟨hp, hr, hq, hw⟩, hc⟩ := h + obtain ⟨p', rd', c', q', w'⟩ := s' + dsimp only at hp hr hq hw hc + have hc := hc hD + subst hp; subst hr; subst hc + unfold blockStep + dsimp only + split + · exact ⟨⟨rfl, rfl, hq, hw⟩, fun _ => rfl⟩ + · next c ex hcur => + have hcd : dom c = D := by rw [hi.cur_dom c ex hcur]; exact hD + refine R_popBetween ⟨⟨rfl, rfl, hq, ?_⟩, fun _ => rfl⟩ + simp [upd, hcd, hw] + +theorem R_wake {D : Dom} {s s' : St} (h : R D s s') (hD : s.rd = D) (t : Tid) : + R D (step dom s (.wake t)) (step dom s' (.wake t)) := by + obtain ⟨⟨hp, hr, hq, hw⟩, hc⟩ := h + obtain ⟨p', rd', c', q', w'⟩ := s' + dsimp only at hp hr hq hw hc + have hc := hc hD + subst hp; subst hr; subst hc + simp only [step] + by_cases hg : s.cur.isSome = true ∧ dom t = s.rd + · simp only [hg, and_self, ite_true] + have hdt : dom t = D := by rw [hg.2]; exact hD + unfold doWake + rw [hdt] at * + have hw' : w' D = s.wl D := hw.symm + simp only [hw'] + split + · refine ⟨⟨rfl, rfl, ?_, ?_⟩, fun _ => rfl⟩ + · simp [upd, hq] + · simp [upd, hw] + · exact ⟨⟨rfl, rfl, hq, hw⟩, fun _ => rfl⟩ + · simp only [hg, ite_false] + exact ⟨⟨rfl, rfl, hq, hw⟩, fun _ => rfl⟩ + + +/-- The event moves the clock part: a tick index not seen before (through + `tick` or through the idle loop's `poll`), or a `set_table` call. -/ +def clockEv (s : St) : Ev → Prop + | .tick n => s.part.seen < n + | .poll n => s.part.seen < n + | .setTable _ => True + | _ => False + +instance (s : St) (e : Ev) : Decidable (clockEv s e) := by + cases e <;> simp only [clockEv] <;> infer_instance + +theorem clockEv_congr {s s' : St} (h : s.part = s'.part) (e : Ev) : clockEv s e ↔ clockEv s' e := by + cases e <;> simp [clockEv, h] + +/-- A new tick is the same step whether the kernel takes it from EL0 (`tick`) + or from the idle loop (`poll`). Which of the two happens depends on + whether the running domain idles. -/ +theorem poll_eq_tick (dom : Tid → Dom) (s : St) (n : Nat) (h : s.part.seen < n) : + step dom s (.poll n) = step dom s (.tick n) := by + simp [step, pollStep, h] + +/-- A tick event whose index is not new (`n <= seen`: a repeated or an older + index) changes nothing at all. -/ +theorem tick_repeat_noop (dom : Tid → Dom) (s : St) (n : Nat) (h : n ≤ s.part.seen) : + step dom s (.tick n) = s := by + simp [step, tickStep, h] + +/-- An event that does nothing in every state. It is not a clock event, so it + can stand in a run where the other run has one more local event. -/ +theorem tick_zero_noop (dom : Tid → Dom) (s : St) : step dom s (.tick 0) = s := + tick_repeat_noop dom s 0 (Nat.zero_le _) + +/-- How two event lists of two runs may differ, as seen from `D`, at one step. + * A clock event is the same public event in both runs. A new tick may + come through `tick` in one run and through `poll` in the other. + * Any other event is local to the running domain: an action of its task, + its idle loop taking an interrupt without a new tick (`poll n` with + `n <= seen`), or a repeated tick index (a no-op). Both runs have a local + event there. If `D` is the running domain, it is the same event. If + another domain runs, the two events are unrelated. -/ +def Shape (D : Dom) (s : St) (e e' : Ev) : Prop := + (clockEv s e → pubOf e' = pubOf e) ∧ + (¬ clockEv s e → ¬ clockEv s e' ∧ (s.rd = D → e' = e)) + +/-- The hypotheses of non-interference at one step: `Shape`, and no wake across + domains into `D` in either run. -/ +def Ok (dom : Tid → Dom) (D : Dom) (s : St) (e e' : Ev) : Prop := + Shape D s e e' ∧ NoCross dom D e ∧ NoCross dom D e' + +/-- The two event lists agree step by step, as seen from `D`. -/ +def Sync (dom : Tid → Dom) (D : Dom) : St → St → List Ev → List Ev → Prop + | _, _, [], [] => True + | s, s', e :: es, e' :: es' => + Ok dom D s e e' ∧ Sync dom D (step dom s e) (step dom s' e') es es' + | _, _, _, _ => False + +/-- The same event in both runs keeps the relation. -/ +theorem R_step_same {D : Dom} {s s' : St} (hi : Inv dom s) (hi' : Inv dom s') (hR : R D s s') + (e : Ev) (hnc : NoCross dom D e) : R D (step dom s e) (step dom s' e) := by + cases e with + | tick n => exact R_tick hR n + | poll n => exact R_poll hR n + | setTable t => exact R_setTable hR t + | wakeX t => exact R_wakeX hR t hnc + | yield => + by_cases hD : s.rd = D + · exact R_yield hR hD + · exact R_of_other hR hD (yield_R0_other s D hD) (yield_R0_other s' D (by rw [← hR.rd]; exact hD)) + | block dl => + by_cases hD : s.rd = D + · exact R_block hi hR hD dl + · exact R_of_other hR hD (block_R0_other s hi D dl hD) + (block_R0_other s' hi' D dl (by rw [← hR.rd]; exact hD)) + | wake t => + by_cases hD : s.rd = D + · exact R_wake hR hD t + · have hne' : s'.rd ≠ D := by rw [← hR.rd]; exact hD + have a1 := (act_R0_other hi hD (.wake t) trivial).resolve_right (fun h => h rfl) + have a2 := (act_R0_other hi' hne' (.wake t) trivial).resolve_right (fun h => h rfl) + exact R_of_other hR hD a1 a2 + +/-- A local event of another domain is invisible to `D`. -/ +theorem local_R0_other {D : Dom} {s : St} (hi : Inv dom s) (hne : s.rd ≠ D) (e : Ev) + (hc : ¬ clockEv s e) (hnc : NoCross dom D e) : R0 D s (step dom s e) := by + cases e with + | tick n => + have hn : n ≤ s.part.seen := by simp only [clockEv] at hc; omega + simp only [step, tickStep, hn, ite_true] + exact R0.refl _ _ + | poll n => + have hn : ¬ s.part.seen < n := hc + simp only [step, pollStep, hn, ite_false] + have h1 : R0 D s (serve s s.rd n) := serve_R0_other s s.rd n D hne + have h2 : R0 D (serve s s.rd n) (pollRest (serve s s.rd n)) := by + unfold pollRest; split + · exact R0.refl _ _ + · exact popBetween_R0_other _ D (by simpa using hne) + exact h1.trans h2 + | setTable t => exact absurd trivial hc + | yield => exact (act_R0_other hi hne .yield hnc).resolve_right (fun h => h rfl) + | block dl => exact (act_R0_other hi hne (.block dl) hnc).resolve_right (fun h => h rfl) + | wake t => exact (act_R0_other hi hne (.wake t) hnc).resolve_right (fun h => h rfl) + | wakeX t => exact (act_R0_other hi hne (.wakeX t) hnc).resolve_right (fun h => h rfl) + +theorem R_step {D : Dom} {s s' : St} (hi : Inv dom s) (hi' : Inv dom s') (hR : R D s s') + (e e' : Ev) (hok : Ok dom D s e e') : R D (step dom s e) (step dom s' e') := by + by_cases hc : clockEv s e + · have hp := hok.1.1 hc + have tk : ∀ n, s.part.seen < n → R D (step dom s (.tick n)) (step dom s' (.tick n)) := + fun n _ => R_tick hR n + have key : ∀ n, s.part.seen < n → pubOf e' = some (.tick n) → + R D (step dom s (.tick n)) (step dom s' e') := by + intro n hn hpe + have hn' : s'.part.seen < n := by rw [← hR.part]; exact hn + cases e' with + | tick m => + simp only [pubOf, Option.some.injEq, Pub.tick.injEq] at hpe + subst hpe; exact tk m hn + | poll m => + simp only [pubOf, Option.some.injEq, Pub.tick.injEq] at hpe + subst hpe; rw [poll_eq_tick dom s' m hn']; exact tk m hn + | setTable t => simp [pubOf] at hpe + | yield => simp [pubOf] at hpe + | block dl => simp [pubOf] at hpe + | wake t => simp [pubOf] at hpe + | wakeX t => simp [pubOf] at hpe + cases e with + | tick n => exact key n hc hp + | poll n => rw [poll_eq_tick dom s n hc]; exact key n hc hp + | setTable t => + cases e' with + | setTable t' => + simp only [pubOf, Option.some.injEq, Pub.setTable.injEq] at hp + subst hp; exact R_setTable hR t' + | tick m => simp [pubOf] at hp + | poll m => simp [pubOf] at hp + | yield => simp [pubOf] at hp + | block dl => simp [pubOf] at hp + | wake t => simp [pubOf] at hp + | wakeX t => simp [pubOf] at hp + | yield => exact absurd hc (by simp [clockEv]) + | block dl => exact absurd hc (by simp [clockEv]) + | wake t => exact absurd hc (by simp [clockEv]) + | wakeX t => exact absurd hc (by simp [clockEv]) + · obtain ⟨hc', hsame⟩ := hok.1.2 hc + by_cases hD : s.rd = D + · have he := hsame hD + subst he + exact R_step_same hi hi' hR e' hok.2.1 + · have hne' : s'.rd ≠ D := by rw [← hR.rd]; exact hD + have hc2 : ¬ clockEv s' e' := fun h => hc' ((clockEv_congr hR.part e').mpr h) + exact R_of_other hR hD (local_R0_other hi hD e hc hok.2.1) + (local_R0_other hi' hne' e' hc2 hok.2.2) + +/-- (5) Non-interference. Let `D` be a domain. Take two runs from two + well formed states that look the same from `D` (`R D`: same clock part, same + running domain, same queue and waiting list of `D`, same running task if + `D` runs; every other domain may be arbitrary). If the event lists agree + step by step as in `Sync` (same new ticks and `set_table` calls, a tick + counting as the same whether it comes through `tick` or `poll`; the same + local events whenever `D` runs; otherwise arbitrary local events of the + running domain, among them its idle loop's interrupts; no wake across + domains into `D`), then `D`'s view (queue, timed waits, which of its tasks + runs with the slice bit) is the same after every step, and the relation + still holds at the end. The runs are compared position by position; a run + with fewer local events is padded with `tick 0` (`tick_zero_noop`). -/ +theorem noninterference (D : Dom) : + ∀ (es es' : List Ev) (s s' : St), Inv dom s → Inv dom s' → R D s s' → + Sync dom D s s' es es' → + viewTrace dom D s es = viewTrace dom D s' es' ∧ R D (exec dom s es) (exec dom s' es') := by + intro es + induction es with + | nil => + intro es' s s' hi hi' hR hs + cases es' with + | nil => exact ⟨by simp [viewTrace, view_eq hi hi' hR], hR⟩ + | cons e' es' => simp [Sync] at hs + | cons e es ih => + intro es' s s' hi hi' hR hs + cases es' with + | nil => simp [Sync] at hs + | cons e' es' => + obtain ⟨hok, hrest⟩ := hs + have hR' := R_step hi hi' hR e e' hok + obtain ⟨h1, h2⟩ := ih es' _ _ (inv_step _ hi e) (inv_step _ hi' e') hR' hrest + refine ⟨?_, h2⟩ + simp only [viewTrace] + rw [h1, view_eq hi hi' hR] + +/-- The final views agree. -/ +theorem noninterference_final (D : Dom) (es es' : List Ev) (s s' : St) + (hi : Inv dom s) (hi' : Inv dom s') (hR : R D s s') (hs : Sync dom D s s' es es') : + view dom D (exec dom s es) = view dom D (exec dom s' es') := + view_eq (inv_exec s hi es) (inv_exec s' hi' es') (noninterference D es es' s s' hi hi' hR hs).2 + +end ni2 + +/-! ## (6) The hypothesis "no wake across domains into D" is needed -/ + +/-- A state: root task 0 runs, task 10 of domain 1 waits without deadline. -/ +def s0 : St := + boot 0 0 (fun _ => []) (fun d => if d = 1 then [(10, none)] else []) + +theorem s0_inv : Inv dom0 s0 := by + apply inv_boot + · intro d t ht; simp at ht + · intro d w hw + by_cases hd : d = 1 + · subst hd; simp at hw; subst hw; decide + · simp [hd] at hw + · decide + +/-- (6) With a cross-domain wake into `D = 1`, the views of two runs that agree in + all other respects differ: run 1 wakes task 10 through a shared object, run 2 + does something else, and `D`'s queue differs after the step. Everything + else of `Ok` holds: same state, `Shape`, no cross wake in the second run. -/ +theorem cross_wake_breaks : + Inv dom0 s0 ∧ R 1 s0 s0 ∧ Shape 1 s0 (.wakeX 10) .yield ∧ + NoCross dom0 1 (.yield) ∧ ¬ NoCross dom0 1 (.wakeX 10) ∧ + view dom0 1 (step dom0 s0 (.wakeX 10)) ≠ view dom0 1 (step dom0 s0 .yield) := by + refine ⟨s0_inv, ⟨⟨rfl, rfl, rfl, rfl⟩, fun _ => rfl⟩, ?_, trivial, ?_, ?_⟩ + · refine ⟨fun h => ?_, fun _ => ⟨fun h => h, fun h => ?_⟩⟩ + · exact h.elim + · simp [s0, boot] at h + · simp [NoCross, dom0] + · decide + + +/-! ## Decidable checks of the hypotheses, for concrete examples -/ + +instance (dom : Tid → Dom) (D : Dom) (e : Ev) : Decidable (NoCross dom D e) := by + cases e <;> simp only [NoCross] <;> infer_instance + +instance (D : Dom) (s : St) (e e' : Ev) : Decidable (Shape D s e e') := by + unfold Shape; infer_instance + +instance (dom : Tid → Dom) (D : Dom) (s : St) (e e' : Ev) : Decidable (Ok dom D s e e') := by + unfold Ok; infer_instance + +instance (dom : Tid → Dom) (D : Dom) : + (s s' : St) → (es es' : List Ev) → Decidable (Sync dom D s s' es es') + | _, _, [], [] => isTrue trivial + | s, s', e :: es, e' :: es' => + have : Decidable (Sync dom D (step dom s e) (step dom s' e') es es') := + instDecidableSync dom D (step dom s e) (step dom s' e') es es' + inferInstanceAs (Decidable (Ok dom D s e e' ∧ Sync dom D (step dom s e) (step dom s' e') es es')) + | _, _, [], _ :: _ => isFalse (fun h => h) + | _, _, _ :: _, [] => isFalse (fun h => h) + + +/-! ## (5) is not vacuous: a concrete pair of runs -/ + +/-- Domain 1 has the same queue and the same timed wait in both runs. The other + domains differ: run A has ready tasks in domains 0 and 2 and a waiter in + domain 0; run B has nothing ready there and two waiters in domain 2. -/ +def sA : St := + boot 0 0 (fun d => if d = 0 then [1] else if d = 1 then [10] else if d = 2 then [20] else []) + (fun d => if d = 0 then [(5, none)] else if d = 1 then [(11, some 4)] else []) + +def sB : St := + boot 0 0 (fun d => if d = 1 then [10] else []) + (fun d => if d = 1 then [(11, some 4)] else if d = 2 then [(21, none), (22, none)] else []) + +/-- Same new ticks and `set_table`; the same events while domain 1 runs (places + 4 to 7 and 13); unrelated events while domains 0 and 2 run. + * Place 2: run A wakes a task of domain 0, run B's only task blocks, so + domain 0 idles in run B from there on. + * Ticks 2 and 5 reach run B through its idle loop (`poll`), run A from EL0 + (`tick`). Tick 10 is the other way round. + * Place 4: domain 1 wakes task 21 of domain 2 (`wakeX`, outward). It takes + effect in run B only. Domain 1 sees nothing of that. + * Places 9 and 16: an interrupt without a new tick reaches the idle loop of + one run (`poll 4`, `poll 9`) while the other run does something else or + nothing (`tick 0` pads). + * Ticks 6, 8 and 11 are skipped in both runs (jumps). -/ +def esA : List Ev := + [.setTable [(1, 2), (0, 1), (2, 1)], .tick 1, .wake 5, .tick 2, .wakeX 21, .tick 3, .wake 11, + .yield, .tick 4, .yield, .tick 5, .yield, .tick 7, .block (some 9), .tick 9, .block none, + .poll 9, .poll 10, .tick 12] + +def esB : List Ev := + [.setTable [(1, 2), (0, 1), (2, 1)], .tick 1, .block none, .poll 2, .wakeX 21, .tick 3, .wake 11, + .yield, .tick 4, .poll 4, .poll 5, .wake 22, .tick 7, .block (some 9), .tick 9, .yield, + .tick 0, .tick 10, .tick 12] + +#eval (viewTrace dom0 1 sA esA).map fun v => (v.q, v.wl, v.run) +#eval (viewTrace dom0 1 sB esB).map fun v => (v.q, v.wl, v.run) +#eval (viewTrace dom0 0 sA esA).map fun v => (v.q, v.wl, v.run) +#eval (viewTrace dom0 0 sB esB).map fun v => (v.q, v.wl, v.run) + +theorem example_views_equal : viewTrace dom0 1 sA esA = viewTrace dom0 1 sB esB := by decide + +/-- The relation and the hypotheses hold in the example (so the theorem applies to it) + while the views of both other domains differ. -/ +theorem example_applies : + Inv dom0 sA ∧ Inv dom0 sB ∧ R 1 sA sB ∧ Sync dom0 1 sA sB esA esB ∧ + viewTrace dom0 0 sA esA ≠ viewTrace dom0 0 sB esB ∧ + viewTrace dom0 2 sA esA ≠ viewTrace dom0 2 sB esB := by + refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ + · apply inv_boot + · intro d t ht + by_cases h0 : d = 0 + · subst h0; simp at ht; subst ht; decide + · by_cases h1 : d = 1 + · subst h1; simp at ht; subst ht; decide + · by_cases h2 : d = 2 + · subst h2; simp at ht; subst ht; decide + · simp [h0, h1, h2] at ht + · intro d w hw + by_cases h0 : d = 0 + · subst h0; simp at hw; subst hw; decide + · by_cases h1 : d = 1 + · subst h1; simp at hw; subst hw; decide + · simp [h0, h1] at hw + · decide + · apply inv_boot + · intro d t ht + by_cases h1 : d = 1 + · subst h1; simp at ht; subst ht; decide + · simp [h1] at ht + · intro d w hw + by_cases h1 : d = 1 + · subst h1; simp at hw; subst hw; decide + · by_cases h2 : d = 2 + · subst h2; simp at hw; rcases hw with rfl | rfl <;> decide + · simp [h1, h2] at hw + · decide + · exact ⟨⟨rfl, rfl, rfl, rfl⟩, fun _ => by decide⟩ + · decide + · decide + · decide + +/-- State after the first `k` events of a run. -/ +def after (s : St) (es : List Ev) (k : Nat) : St := exec dom0 s (es.take k) + +/-- Everything of a state for domains 0 to 2. -/ +def obs (s : St) : Nat × Nat × Option (Tid × Bool) × List (List Tid) × List (List (Tid × Option Nat)) := + (s.rd, s.part.seen, s.cur, (List.range 3).map s.q, (List.range 3).map s.wl) + +/-- Places of the local events of a run that change its state. -/ +def effective (s : St) (es : List Ev) : List Nat := + (List.range es.length).filter fun k => + obs (after s es k) != obs (after s es (k + 1)) && + (match es[k]? with | some e => !decide (clockEv (after s es k) e) | none => false) + +/-- What the example exercises. Run A: a wake inside domain 0 (place 2), a wake + inside domain 1 (6), yields and blocks. Run B: the outward `wakeX` of + domain 1 (4) and a wake inside domain 2 (11) take effect as well. -/ +theorem example_effects : + effective sA esA = [2, 6, 7, 9, 13, 15] ∧ effective sB esB = [2, 4, 6, 7, 11, 13, 15] := by + decide + +/-- The example keeps to the kernel's call pattern: a `poll` occurs only while + its run has no task on the CPU, and a new tick comes through `tick` only + while one is. -/ +theorem example_kernel_shaped : + ((List.range esA.length).all fun k => match esA[k]? with + | some (.poll _) => (after sA esA k).cur.isNone + | some (.tick n) => (after sA esA k).cur.isSome || decide (n ≤ (after sA esA k).part.seen) + | _ => true) = true ∧ + ((List.range esB.length).all fun k => match esB[k]? with + | some (.poll _) => (after sB esB k).cur.isNone + | some (.tick n) => (after sB esB k).cur.isSome || decide (n ≤ (after sB esB k).part.seen) + | _ => true) = true := by + decide + + +/-! ## Witnesses for the remarks in the header -/ + +/-- `exP` of `guard_unsound_without_hyp` is reached from boot: tick 1, a + `set_table` call, tick 2. -/ +theorem exP_reachable : + pexec (boot 0 0 (fun _ => []) (fun _ => [])).part [.tick 1, .setTable [(1, 1)], .tick 2] = exP := by + decide + +/-- A table governs only until a later call: a second call one tick later + discards the first table, which then never governs any tick. -/ +def bootP : St := + boot 0 0 (fun d => if d = 1 then [10] else if d = 2 then [20] else []) (fun _ => []) + +theorem first_table_never_governs : + (exec dom0 bootP [.setTable [(1, 1)], .tick 1, .setTable [(2, 1)], .tick 2]).rd = 0 ∧ + (exec dom0 bootP [.setTable [(1, 1)], .tick 1, .setTable [(2, 1)], .tick 2, .tick 3]).rd = 2 ∧ + (exec dom0 bootP [.setTable [(1, 1)], .tick 1, .setTable [(2, 1)], .tick 2, .tick 3, .tick 4]).rd = 2 := by + decide + +/-- The tick indexes are an input the theorem leans on. Same state, the same + (absent) actions, and the views of domain 1 differ when one run sees ticks + 1 and 2 and the other skips tick 1. -/ +def jS : St := + { part := { tbl := [(0, 1), (1, 1)], epoch := 0, pend := none, seen := 0 }, + rd := 0, cur := some (0, false), + q := fun d => if d = 1 then [10, 11] else [], wl := fun _ => [] } + +theorem tick_indexes_needed : + (view dom0 1 (exec dom0 jS [.tick 1, .tick 2])).q = [11, 10] ∧ + (view dom0 1 (exec dom0 jS [.yield, .tick 2])).q = [10, 11] ∧ + ¬ Sync dom0 1 jS jS [.tick 1, .tick 2] [.yield, .tick 2] := by decide + +/-- The state `sample` of the `#eval` near the top is an `Inv` state. -/ +theorem sample_inv : Inv dom0 sample := by + apply inv_boot + · intro d t ht + by_cases h0 : d = 0 + · subst h0; simp at ht; subst ht; decide + · by_cases h1 : d = 1 + · subst h1; simp at ht; rcases ht with rfl | rfl <;> decide + · by_cases h2 : d = 2 + · subst h2; simp at ht; subst ht; decide + · simp [h0, h1, h2] at ht + · intro d w hw + by_cases h1 : d = 1 + · subst h1; simp at hw; subst hw; decide + · simp [h1] at hw + · decide + +/-- `Inv` has no uniqueness: the running task may also sit in a queue. -/ +theorem inv_with_duplicate : + Inv dom0 (boot 0 0 (fun d => if d = 0 then [0, 0] else []) (fun _ => [])) := by + apply inv_boot + · intro d t ht + by_cases h0 : d = 0 + · subst h0; simp at ht; subst ht; decide + · simp [h0] at ht + · intro d w hw; simp at hw + · decide + + +/-! ## Further facts about the model -/ + +section extra +variable {dom : Tid → Dom} + +/-- The decision the guard arms on: is the tick after the last processed one a + domain change? (`Core::next_tick_switches`) -/ +def nextSwitches (s : St) : Prop := s.part.plan (s.part.seen + 1) ≠ s.rd + +/-- The guard decision is not changed by a `set_table` call, unless an earlier + pending table starts exactly at the next tick (see `guard_unsound_without_hyp`). -/ +theorem guard_sound_event (s : St) (t : Table) (hpa : PendAfter s.part) + (hk : ∀ t0, s.part.pend ≠ some (s.part.seen + 1, t0)) : + nextSwitches (step dom s (.setTable t)) ↔ nextSwitches s := by + unfold nextSwitches + show (s.part.setTable t).plan ((s.part.setTable t).seen + 1) ≠ s.rd ↔ _ + rw [setTable_seen, guard_sound _ _ hpa hk] + +/-- A tick event with index `n > seen` (a jump when `n > seen + 1`) makes the + domain of tick `n` run, whatever the skipped ticks would have been. -/ +theorem tick_jump_domain (s : St) (n : Nat) (hn : s.part.seen < n) : + (step dom s (Ev.tick n)).rd = s.part.plan n ∧ (step dom s (Ev.tick n)).part.seen = n := by + have hn' : ¬ n ≤ s.part.seen := by omega + have hpl : (s.part.advance n).domNow n = s.part.plan n := domNow_advance _ _ + simp only [step, tickStep, hn', ite_false] + by_cases hnew : (s.part.advance n).domNow n = s.rd + · simp only [hnew, ite_true, sameStep_rd, sameStep_part, serve_rd, serve_part] + exact ⟨by rw [← hpl, hnew], trivial⟩ + · simp only [hnew, ite_false, enter_rd, enter_part, serve_rd, serve_part, cut_part] + exact ⟨hpl, trivial⟩ + +/-- Timer wakes stay in the served domain. -/ +theorem serve_only_own (s : St) (d n e : Nat) (h : e ≠ d) : + (serve s d n).q e = s.q e ∧ (serve s d n).wl e = s.wl e := by + simp [serve, upd, h] + +/-- A timer wake never fires early: a task that `serve` moves into the queue + already was in it, or has a deadline `<= n`. -/ +theorem serve_not_early (s : St) (d n t : Nat) (h : t ∈ (serve s d n).q d) : + t ∈ s.q d ∨ ∃ w ∈ s.wl d, w.1 = t ∧ ∃ k, w.2 = some k ∧ k ≤ n := by + simp only [serve, upd, ite_true] at h + rcases List.mem_append.mp h with h1 | h1 + · exact Or.inl h1 + · right + obtain ⟨w, hw, rfl⟩ := List.mem_map.mp h1 + obtain ⟨hw1, hw2⟩ := List.mem_filter.mp (List.mem_reverse.mp hw) + refine ⟨w, hw1, rfl, ?_⟩ + unfold expired at hw2 + revert hw2 + rcases w with ⟨a, b⟩ + cases b <;> simp + +/-- `Core::block` as written when nothing runs: clear `running`, pop the queue. -/ +def blockIdleRust (s : St) : St := popBetween { s with cur := none } + +/-- Under `Inv` that is what `blockStep` does when nothing runs: nothing. -/ +theorem blockIdleRust_eq (s : St) (hi : Inv dom s) (hc : s.cur = none) (dl : Option Nat) : + blockIdleRust s = blockStep dom s dl := by + have hq : s.q s.rd = [] := hi.idle_empty hc + obtain ⟨p, rd, c, q, w⟩ := s + simp only at hc hq + subst hc + simp [blockIdleRust, blockStep, popBetween, hq] + +end extra + + +/-! ## Timed waits fire, and only in the domain that runs + +`serve_not_early` says that a timer wake is never early. The theorems here +say that it does happen and where: a waiter whose deadline has come is moved +when its domain is served, a tick and an idle poll serve the domain that +runs, and they serve no other domain (`waiter_leaves_only` puts the "only" +into one statement). "Due at `n`" is written out (`w.2 = some k` and +`k <= n`), not through `expired`, so that the statements do not lean on that +definition. Ticks are indexes; nothing here is about instants, and nothing +says that a tick ever comes. -/ + +section fire + +/-- `expired` written out: the waiter has a deadline and it is not after `n`. -/ +theorem expired_iff (w : Tid × Option Nat) (n : Nat) : + expired w n = true ↔ ∃ k, w.2 = some k ∧ k ≤ n := by + obtain ⟨a, b⟩ := w + cases b <;> simp [expired] + +theorem not_expired_iff (w : Tid × Option Nat) (n : Nat) : + expired w n = false ↔ ∀ k, w.2 = some k → n < k := by + obtain ⟨a, b⟩ := w + cases b <;> simp [expired] + +/-- `serve d n` wakes every waiter of `d` that is due at `n`: it is in `d`'s + queue afterwards, no due waiter is left in `d`'s waiting list, a waiter + that is not due stays, and the tasks that were queued keep their places in + front. (That nothing else is queued is `serve_not_early`.) -/ +theorem serve_wakes_due (s : St) (d n : Nat) : + (∀ w ∈ s.wl d, ∀ k, w.2 = some k → k ≤ n → w.1 ∈ (serve s d n).q d) ∧ + (∀ w ∈ (serve s d n).wl d, ∀ k, w.2 = some k → n < k) ∧ + (∀ w ∈ s.wl d, (∀ k, w.2 = some k → n < k) → w ∈ (serve s d n).wl d) ∧ + (∃ r, (serve s d n).q d = s.q d ++ r) := by + refine ⟨?_, ?_, ?_, ⟨(((s.wl d).filter (fun w => expired w n)).reverse).map Prod.fst, ?_⟩⟩ + · intro w hw k hk hkn + simp only [serve, upd, ite_true] + apply List.mem_append_right + exact List.mem_map.mpr ⟨w, List.mem_reverse.mpr + (List.mem_filter.mpr ⟨hw, (expired_iff w n).mpr ⟨k, hk, hkn⟩⟩), rfl⟩ + · intro w hw + simp only [serve, upd, ite_true] at hw + have h := (List.mem_filter.mp hw).2 + exact (not_expired_iff w n).mp (by simpa using h) + · intro w hw h + simp only [serve, upd, ite_true] + exact List.mem_filter.mpr ⟨hw, by simpa using (not_expired_iff w n).mpr h⟩ + · simp only [serve, upd, ite_true] + +/-- The order of timer wakes. The queue of `d` keeps its tasks in front, and + of two due waiters the one that started to wait later (`w2`) is queued + before the earlier one (`w1`). -/ +theorem serve_due_order (s : St) (d n : Nat) (a b c : List (Tid × Option Nat)) + (w1 w2 : Tid × Option Nat) (k1 k2 : Nat) + (hwl : s.wl d = a ++ w1 :: (b ++ w2 :: c)) + (h1 : w1.2 = some k1) (hk1 : k1 ≤ n) (h2 : w2.2 = some k2) (hk2 : k2 ≤ n) : + ∃ x y z, (serve s d n).q d = s.q d ++ (x ++ w2.1 :: (y ++ w1.1 :: z)) := by + have e1 : expired w1 n = true := (expired_iff w1 n).mpr ⟨k1, h1, hk1⟩ + have e2 : expired w2 n = true := (expired_iff w2 n).mpr ⟨k2, h2, hk2⟩ + refine ⟨((c.filter (fun w => expired w n)).reverse).map Prod.fst, + ((b.filter (fun w => expired w n)).reverse).map Prod.fst, + ((a.filter (fun w => expired w n)).reverse).map Prod.fst, ?_⟩ + simp [serve, upd, hwl, e1, e2] + +@[simp] theorem enter_wl (s : St) (d : Dom) : (enter s d).wl = s.wl := by + unfold enter; split <;> rfl +@[simp] theorem cut_wl (s : St) : (cut s).wl = s.wl := by + unfold cut; split <;> rfl +@[simp] theorem sameStep_wl (s : St) : (sameStep s).wl = s.wl := by + unfold sameStep; split <;> (try split) <;> simp +@[simp] theorem popBetween_wl (s : St) : (popBetween s).wl = s.wl := by + unfold popBetween; split <;> rfl +@[simp] theorem pollRest_wl (s : St) : (pollRest s).wl = s.wl := by + unfold pollRest; split <;> simp +@[simp] theorem pollRest_rd (s : St) : (pollRest s).rd = s.rd := by + unfold pollRest; split <;> simp + +/-- A queued task of `d` is still queued after `enter d`, or it runs. -/ +theorem enter_mem (s : St) (d : Dom) (x : Tid) (h : x ∈ s.q d) : + x ∈ (enter s d).q d ∨ ∃ b, (enter s d).cur = some (x, b) := by + unfold enter + split + · next y r hr => + rw [hr] at h + rcases List.mem_cons.mp h with rfl | h1 + · exact Or.inr ⟨false, rfl⟩ + · exact Or.inl (by simpa [upd] using h1) + · next hr => rw [hr] at h; simp at h + +theorem popBetween_mem (s : St) (x : Tid) (h : x ∈ s.q s.rd) : + x ∈ (popBetween s).q s.rd ∨ ∃ b, (popBetween s).cur = some (x, b) := by + unfold popBetween + split + · next y r hr => + rw [hr] at h + rcases List.mem_cons.mp h with rfl | h1 + · exact Or.inr ⟨true, rfl⟩ + · exact Or.inl (by simpa [upd] using h1) + · next hr => rw [hr] at h; simp at h + +theorem sameStep_mem (s : St) (x : Tid) (h : x ∈ s.q s.rd) : + x ∈ (sameStep s).q s.rd ∨ ∃ b, (sameStep s).cur = some (x, b) := by + unfold sameStep + split + · exact Or.inl h + · split + · next y r hr => + rw [hr] at h + rcases List.mem_cons.mp h with rfl | h1 + · exact Or.inr ⟨false, rfl⟩ + · exact Or.inl (by simp [upd, h1]) + · exact Or.inl h + · exact enter_mem s s.rd x h + +theorem pollRest_mem (s : St) (x : Tid) (h : x ∈ s.q s.rd) : + x ∈ (pollRest s).q s.rd ∨ ∃ b, (pollRest s).cur = some (x, b) := by + unfold pollRest + split + · exact Or.inl h + · exact popBetween_mem s x h + +/-- A new tick serves the domain that runs after it. After a tick event with + a new index `n`: no waiter that is due at `n` is left in the waiting list + of the domain that now runs, each waiter of that domain that was due is in + its queue or is the running task, and each of its waiters that was not due + still waits. This holds for a tick inside a window and for a tick that + changes the domain, jumps included, and for a new index that comes through + `poll` (`poll_eq_tick`). + It does not say that the waiter runs soon, and it says nothing about a + domain that does not get the tick (see `tick_frame`, `tick_old_domain`). -/ +theorem tick_serves (dom : Tid → Dom) (s : St) (n : Nat) (hn : s.part.seen < n) : + (∀ w ∈ (step dom s (.tick n)).wl (step dom s (.tick n)).rd, + ∀ k, w.2 = some k → n < k) ∧ + (∀ w ∈ s.wl (step dom s (.tick n)).rd, ∀ k, w.2 = some k → k ≤ n → + w.1 ∈ (step dom s (.tick n)).q (step dom s (.tick n)).rd ∨ + ∃ b, (step dom s (.tick n)).cur = some (w.1, b)) ∧ + (∀ w ∈ s.wl (step dom s (.tick n)).rd, (∀ k, w.2 = some k → n < k) → + w ∈ (step dom s (.tick n)).wl (step dom s (.tick n)).rd) := by + have hn' : ¬ n ≤ s.part.seen := by omega + simp only [step, tickStep, hn', ite_false] + by_cases hnew : (s.part.advance n).domNow n = s.rd + · simp only [hnew, ite_true, sameStep_rd, serve_rd, sameStep_wl] + have hs := serve_wakes_due { s with part := { s.part.advance n with seen := n } } s.rd n + refine ⟨hs.2.1, ?_, hs.2.2.1⟩ + intro w hw k hk hkn + exact sameStep_mem (serve { s with part := { s.part.advance n with seen := n } } s.rd n) + w.1 (hs.1 w hw k hk hkn) + · simp only [hnew, ite_false, enter_rd, serve_rd, enter_wl] + have hs := serve_wakes_due + ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) ((s.part.advance n).domNow n) n + refine ⟨hs.2.1, ?_, ?_⟩ + · intro w hw k hk hkn + exact enter_mem _ _ w.1 (hs.1 w (by simpa using hw) k hk hkn) + · intro w hw h + exact hs.2.2.1 w (by simpa using hw) h + +/-- A tick touches no third domain: the queue and the waiting list of a domain + that neither ran before the tick nor runs after it are unchanged. -/ +theorem tick_frame (dom : Tid → Dom) (s : St) (n : Nat) (e : Dom) + (h1 : e ≠ s.rd) (h2 : e ≠ (step dom s (.tick n)).rd) : + (step dom s (.tick n)).q e = s.q e ∧ (step dom s (.tick n)).wl e = s.wl e := by + by_cases hn : n ≤ s.part.seen + · rw [tick_repeat_noop dom s n hn]; exact ⟨rfl, rfl⟩ + · simp only [step, tickStep, hn, ite_false] at h2 ⊢ + by_cases hnew : (s.part.advance n).domNow n = s.rd + · simp only [hnew, ite_true] + have a := serve_R0_other { s with part := { s.part.advance n with seen := n } } s.rd n e + (Ne.symm h1) + have b := sameStep_R0_other + (serve { s with part := { s.part.advance n with seen := n } } s.rd n) e (Ne.symm h1) + exact ⟨(a.q.trans b.q).symm, (a.wl.trans b.wl).symm⟩ + · simp only [hnew, ite_false, enter_rd, serve_rd] at h2 ⊢ + have a := cut_R0_other { s with part := { s.part.advance n with seen := n } } e (Ne.symm h1) + have b := serve_R0_other + ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) ((s.part.advance n).domNow n) n e + (Ne.symm h2) + have c := enter_R0_other + (serve ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) ((s.part.advance n).domNow n) n) + ((s.part.advance n).domNow n) e (Ne.symm h2) + exact ⟨(a.q.trans (b.q.trans c.q)).symm, (a.wl.trans (b.wl.trans c.wl)).symm⟩ + +/-- The queue of the running domain after `cut`: the old queue and the task + that ran, nothing else. -/ +theorem cut_q_perm (s : St) : + ((cut s).q s.rd).Perm + (match s.cur with | some (c, _) => c :: s.q s.rd | none => s.q s.rd) := by + rcases hc : s.cur with _ | ⟨c, ex⟩ + · simp [cut, hc] + · cases ex with + | true => simp [cut, hc, upd] + | false => + rcases hr : s.q s.rd with _ | ⟨x, r⟩ + · simp [cut, hc, upd, hr] + · simp only [cut, hc, upd, ite_true, hr, Bool.false_eq_true, ite_false] + exact List.perm_append_singleton c (x :: r) + +/-- A tick that changes the domain does not serve the domain that ran before: + its waiting list is as it was, so its due waiters stay until that domain + runs again. Its queue gets the task that ran, and nothing else. -/ +theorem tick_old_domain (dom : Tid → Dom) (s : St) (n : Nat) + (h : (step dom s (.tick n)).rd ≠ s.rd) : + (step dom s (.tick n)).wl s.rd = s.wl s.rd ∧ + ((step dom s (.tick n)).q s.rd).Perm + (match s.cur with | some (c, _) => c :: s.q s.rd | none => s.q s.rd) := by + by_cases hn : n ≤ s.part.seen + · rw [tick_repeat_noop dom s n hn] at h; exact absurd rfl h + · simp only [step, tickStep, hn, ite_false] at h ⊢ + by_cases hnew : (s.part.advance n).domNow n = s.rd + · simp [hnew] at h + · simp only [hnew, ite_false, enter_wl] + have b := serve_R0_other + ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) ((s.part.advance n).domNow n) n s.rd hnew + have c := enter_R0_other + (serve ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) ((s.part.advance n).domNow n) n) + ((s.part.advance n).domNow n) s.rd hnew + refine ⟨b.wl.symm.trans (by simp), ?_⟩ + rw [← c.q, ← b.q] + exact cut_q_perm { s with part := { s.part.advance n with seen := n } } + +/-- The idle loop taking an interrupt without a new tick (`poll n`, `n <= seen`) + serves the running domain, which stays the running domain: no waiter due + at `n` is left in its waiting list, each of its waiters that was due is in + its queue or is the running task, and each that was not due still waits. -/ +theorem poll_serves (dom : Tid → Dom) (s : St) (n : Nat) (hn : n ≤ s.part.seen) : + (step dom s (.poll n)).rd = s.rd ∧ + (∀ w ∈ (step dom s (.poll n)).wl s.rd, ∀ k, w.2 = some k → n < k) ∧ + (∀ w ∈ s.wl s.rd, ∀ k, w.2 = some k → k ≤ n → + w.1 ∈ (step dom s (.poll n)).q s.rd ∨ + ∃ b, (step dom s (.poll n)).cur = some (w.1, b)) ∧ + (∀ w ∈ s.wl s.rd, (∀ k, w.2 = some k → n < k) → w ∈ (step dom s (.poll n)).wl s.rd) := by + have hn' : ¬ s.part.seen < n := by omega + simp only [step, pollStep, hn', ite_false, pollRest_rd, serve_rd, pollRest_wl] + have hs := serve_wakes_due s s.rd n + refine ⟨trivial, hs.2.1, ?_, hs.2.2.1⟩ + intro w hw k hk hkn + exact pollRest_mem (serve s s.rd n) w.1 (hs.1 w hw k hk hkn) + +/-- Such a poll touches no other domain. -/ +theorem poll_frame (dom : Tid → Dom) (s : St) (n : Nat) (hn : n ≤ s.part.seen) (e : Dom) + (he : e ≠ s.rd) : + (step dom s (.poll n)).q e = s.q e ∧ (step dom s (.poll n)).wl e = s.wl e := by + have hn' : ¬ s.part.seen < n := by omega + simp only [step, pollStep, hn', ite_false, pollRest_wl] + have a := serve_R0_other s s.rd n e (Ne.symm he) + refine ⟨?_, a.wl.symm⟩ + rw [a.q] + unfold pollRest + split + · rfl + · exact ((popBetween_R0_other (serve s s.rd n) e (Ne.symm he)).q).symm + +/-- A task that blocks is appended to the waiting list of its own domain with + the deadline it gave. -/ +theorem block_keeps_deadline (dom : Tid → Dom) (s : St) (c : Tid) (b : Bool) (dl : Option Nat) + (hc : s.cur = some (c, b)) : + (step dom s (.block dl)).wl (dom c) = s.wl (dom c) ++ [(c, dl)] ∧ + (c, dl) ∈ (step dom s (.block dl)).wl (dom c) := by + have h : (step dom s (.block dl)).wl (dom c) = s.wl (dom c) ++ [(c, dl)] := by + simp [step, blockStep, hc, upd] + exact ⟨h, by rw [h]; simp⟩ + +theorem due_or_not (w : Tid × Option Nat) (n : Nat) : + (∃ k, w.2 = some k ∧ k ≤ n) ∨ (∀ k, w.2 = some k → n < k) := by + obtain ⟨a, b⟩ := w + cases b with + | none => right; intro k h; simp at h + | some k0 => + by_cases h : k0 ≤ n + · left; exact ⟨k0, rfl, h⟩ + · right; intro k hk; simp at hk; omega + +/-- A tick does not touch the waiting list of a domain that does not run + after it. -/ +theorem tick_wl_other (dom : Tid → Dom) (s : St) (n : Nat) (e : Dom) + (h : e ≠ (step dom s (.tick n)).rd) : (step dom s (.tick n)).wl e = s.wl e := by + by_cases he : e = s.rd + · subst he; exact (tick_old_domain dom s n (Ne.symm h)).1 + · exact (tick_frame dom s n e he h).2 + +theorem tick_leaves (dom : Tid → Dom) (s : St) (n : Nat) (d : Dom) (w : Tid × Option Nat) + (hn : s.part.seen < n) (hw : w ∈ s.wl d) (hl : w ∉ (step dom s (.tick n)).wl d) : + (step dom s (.tick n)).rd = d ∧ ∃ k, w.2 = some k ∧ k ≤ n := by + by_cases hd : d = (step dom s (.tick n)).rd + · subst hd + rcases due_or_not w n with h | h + · exact ⟨rfl, h⟩ + · exact absurd ((tick_serves dom s n hn).2.2 w hw h) hl + · rw [tick_wl_other dom s n d hd] at hl; exact absurd hw hl + +theorem yieldStep_wl (s : St) : (yieldStep s).wl = s.wl := by + unfold yieldStep; split <;> (try split) <;> rfl + +theorem blockStep_wl_mono (dom : Tid → Dom) (s : St) (dl : Option Nat) (d : Dom) + (w : Tid × Option Nat) (hw : w ∈ s.wl d) : w ∈ (blockStep dom s dl).wl d := by + unfold blockStep + split + · exact hw + · next c ex hc => + simp only [popBetween_wl, upd] + split + · next hd => subst hd; exact List.mem_append_left _ hw + · exact hw + +theorem doWake_leaves (dom : Tid → Dom) (s : St) (t : Tid) (d : Dom) (w : Tid × Option Nat) + (hw : w ∈ s.wl d) (hl : w ∉ (doWake dom s t).wl d) : w.1 = t := by + unfold doWake at hl + split at hl + · simp only [upd] at hl + split at hl + · next hd => + subst hd + by_cases h : w.1 = t + · exact h + · exact absurd (List.mem_filter.mpr ⟨hw, by simp [h]⟩) hl + · exact absurd hw hl + · exact absurd hw hl + +/-- A waiter leaves its waiting list in two ways only. Either its domain is + served: a tick or poll event after which its domain runs, with an index at + or after its deadline. Or a task wakes it. So a timed wait fires only + for the domain that runs and never early, no event takes a waiter out of + the list of a domain that does not run after it (except a wake), and + `yield`, `block` and `set_table` take no waiter out at all. -/ +theorem waiter_leaves_only (dom : Tid → Dom) (s : St) (e : Ev) (d : Dom) (w : Tid × Option Nat) + (hw : w ∈ s.wl d) (hl : w ∉ (step dom s e).wl d) : + (∃ n, (e = .tick n ∨ e = .poll n) ∧ (step dom s e).rd = d ∧ ∃ k, w.2 = some k ∧ k ≤ n) ∨ + e = .wake w.1 ∨ e = .wakeX w.1 := by + cases e with + | tick n => + by_cases hn : n ≤ s.part.seen + · rw [tick_repeat_noop dom s n hn] at hl; exact absurd hw hl + · exact Or.inl ⟨n, Or.inl rfl, tick_leaves dom s n d w (by omega) hw hl⟩ + | poll n => + by_cases hn : s.part.seen < n + · rw [poll_eq_tick dom s n hn] at hl ⊢ + exact Or.inl ⟨n, Or.inr rfl, tick_leaves dom s n d w hn hw hl⟩ + · have hn' : n ≤ s.part.seen := by omega + have hp := poll_serves dom s n hn' + by_cases hd : d = s.rd + · subst hd + rcases due_or_not w n with h | h + · exact Or.inl ⟨n, Or.inr rfl, hp.1, h⟩ + · exact absurd (hp.2.2.2 w hw h) hl + · rw [(poll_frame dom s n hn' d hd).2] at hl; exact absurd hw hl + | yield => + have h : (step dom s .yield).wl = s.wl := yieldStep_wl s + rw [h] at hl; exact absurd hw hl + | block dl => exact absurd (blockStep_wl_mono dom s dl d w hw) hl + | wake t => + simp only [step] at hl + split at hl + · exact Or.inr (Or.inl (by rw [doWake_leaves dom s t d w hw hl])) + · exact absurd hw hl + | wakeX t => + simp only [step] at hl + split at hl + · exact Or.inr (Or.inr (by rw [doWake_leaves dom s t d w hw hl])) + · exact absurd hw hl + | setTable t => exact absurd hw hl + +end fire + + +/-! ## No task is lost and none is duplicated + +For a domain `d` the tasks of `d` in a state are: the running task if `d` runs, +then `d`'s queue, then the tasks of `d`'s waiting list (`tasks`). A step +permutes the tasks of every domain: it moves tasks between the three places +and neither drops nor copies one. A wake needs one hypothesis for that: the +woken task is not twice in its waiting list (`doWake` removes every entry of +it and queues it once). `NoDup` (no task twice among the tasks of a domain) +gives it, and every step keeps `NoDup`. `NoDup` is not part of `Inv`. + +The theorems are about membership and multiplicity. They do not give the +order inside a queue (for that see `serve_due_order`, `wake_effect`, +`block_keeps_deadline`), and the model has no event that creates or ends a +task, so "no task is lost" is a statement about the events it has. -/ + +section conserve +variable {dom : Tid → Dom} + +/-- The running task as a list, for the domain that runs; empty otherwise. -/ +def runOf (d : Dom) (s : St) : List Tid := + if s.rd = d then (match s.cur with | some (c, _) => [c] | none => []) else [] + +/-- The tasks of domain `d`: the running task if `d` runs, then `d`'s queue, + then the tasks of `d`'s waiting list. -/ +def tasks (d : Dom) (s : St) : List Tid := + runOf d s ++ s.q d ++ (s.wl d).map Prod.fst + +/-- No task occurs twice among the tasks of a domain. With `Inv` (a task sits + only in its own domain's structures) no task occurs twice in the state. + Not part of `Inv`; a hypothesis of `step_tasks_perm`. -/ +def NoDup (s : St) : Prop := ∀ d, (tasks d s).Nodup + +theorem tasks_serve (s : St) (e n : Nat) (d : Dom) : + (tasks d (serve s e n)).Perm (tasks d s) := by + by_cases h : d = e + · subst h + have hp : ((((s.wl d).filter (fun w => expired w n)).reverse).map Prod.fst ++ + ((s.wl d).filter (fun w => !expired w n)).map Prod.fst).Perm ((s.wl d).map Prod.fst) := by + have h1 := ((List.reverse_perm ((s.wl d).filter (fun w => expired w n))).map + Prod.fst).append_right (((s.wl d).filter (fun w => !expired w n)).map Prod.fst) + have h2 := (List.filter_append_perm (fun w => expired w n) (s.wl d)).map Prod.fst + rw [List.map_append] at h2 + exact h1.trans h2 + simp only [tasks, runOf, serve, upd, ite_true, List.append_assoc] + exact (hp.append_left _).append_left _ + · simp [tasks, runOf, serve, upd, h] + +theorem tasks_rd (s : St) (r : Dom) (d : Dom) (hc : s.cur = none) : + tasks d { s with rd := r } = tasks d s := by + simp [tasks, runOf, hc] + +theorem cut_cur (s : St) : (cut s).cur = none := by + unfold cut; split + · next h => exact h + · rfl + +theorem tasks_cut (s : St) (d : Dom) : (tasks d (cut s)).Perm (tasks d s) := by + by_cases h : s.rd = d + · subst h + have hq := cut_q_perm s + rcases hc : s.cur with _ | ⟨c, ex⟩ + · simp only [hc] at hq + simp only [tasks, runOf, cut_rd, cut_cur, cut_wl, hc, ite_true, List.nil_append] + exact hq.append_right _ + · simp only [hc] at hq + simp only [tasks, runOf, cut_rd, cut_cur, cut_wl, hc, ite_true, List.nil_append] + exact hq.append_right _ + · have hq := (cut_R0_other s d h).q + simp [tasks, runOf, h, ← hq] + +theorem tasks_enter (s : St) (d : Dom) (hc : s.cur = none) : + tasks d (enter s s.rd) = tasks d s := by + unfold enter + split + · next x r hr => + by_cases h : s.rd = d + · subst h; simp [tasks, runOf, upd, hr, hc] + · have h' : ¬ d = s.rd := fun e => h e.symm + simp [tasks, runOf, upd, h, h'] + · simp [tasks, runOf, hc] + +theorem tasks_popBetween (s : St) (d : Dom) (hc : s.cur = none) : + tasks d (popBetween s) = tasks d s := by + unfold popBetween + split + · next x r hr => + by_cases h : s.rd = d + · subst h; simp [tasks, runOf, upd, hr, hc] + · have h' : ¬ d = s.rd := fun e => h e.symm + simp [tasks, runOf, upd, h, h'] + · simp [tasks, runOf, hc] + +theorem tasks_sameStep (s : St) (d : Dom) : (tasks d (sameStep s)).Perm (tasks d s) := by + unfold sameStep + split + · next c hc => simp [tasks, runOf, hc] + · next c hc => + split + · next x r hr => + by_cases h : s.rd = d + · subst h + simp only [tasks, runOf, upd, ite_true, hc, hr] + exact (List.perm_append_singleton c (x :: r)).append_right _ + · have h' : ¬ d = s.rd := fun e => h e.symm + simp [tasks, runOf, upd, h, h'] + · exact List.Perm.refl _ + · next hc => rw [tasks_enter s d hc] + +theorem tasks_yield (s : St) (d : Dom) : (tasks d (yieldStep s)).Perm (tasks d s) := by + unfold yieldStep + split + · exact List.Perm.refl _ + · next c ex hc => + split + · next x r hr => + by_cases h : s.rd = d + · subst h + simp only [tasks, runOf, upd, ite_true, hc, hr] + exact (List.perm_append_singleton c (x :: r)).append_right _ + · have h' : ¬ d = s.rd := fun e => h e.symm + simp [tasks, runOf, upd, h, h'] + · exact List.Perm.refl _ + +theorem tasks_pollRest (s : St) (d : Dom) : tasks d (pollRest s) = tasks d s := by + unfold pollRest + split + · rfl + · next hc => exact tasks_popBetween s d hc + +theorem tasks_tick (s : St) (n : Nat) (d : Dom) : (tasks d (tickStep s n)).Perm (tasks d s) := by + unfold tickStep + split + · exact List.Perm.refl _ + · by_cases hnew : (s.part.advance n).domNow n = s.rd + · simp only [hnew, ite_true] + exact (tasks_sameStep _ d).trans + (tasks_serve { s with part := { s.part.advance n with seen := n } } s.rd n d) + · simp only [hnew, ite_false] + have hc : (cut { s with part := { s.part.advance n with seen := n } }).cur = none := + cut_cur _ + have h1 := tasks_enter + (serve ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) ((s.part.advance n).domNow n) n) d hc + have h2 := tasks_serve + ({ cut { s with part := { s.part.advance n with seen := n } } with + rd := (s.part.advance n).domNow n } : St) ((s.part.advance n).domNow n) n d + have h3 := tasks_rd (cut { s with part := { s.part.advance n with seen := n } }) + ((s.part.advance n).domNow n) d hc + have h4 := tasks_cut { s with part := { s.part.advance n with seen := n } } d + rw [serve_rd] at h1 + rw [h1] + exact h2.trans (h3 ▸ h4) + +theorem tasks_poll (s : St) (n : Nat) (d : Dom) : (tasks d (pollStep s n)).Perm (tasks d s) := by + unfold pollStep + split + · exact tasks_tick s n d + · rw [tasks_pollRest]; exact tasks_serve s s.rd n d + +theorem tasks_block (s : St) (hi : Inv dom s) (dl : Option Nat) (d : Dom) : + (tasks d (blockStep dom s dl)).Perm (tasks d s) := by + unfold blockStep + split + · exact List.Perm.refl _ + · next c ex hc => + have hcd : dom c = s.rd := hi.cur_dom c ex hc + rw [tasks_popBetween _ d rfl] + by_cases h : s.rd = d + · subst h + simp only [tasks, runOf, upd, ite_true, hc, hcd, List.map_append, List.map_cons, + List.map_nil, List.nil_append, ← List.append_assoc] + exact List.perm_append_singleton c _ + · have h' : ¬ d = s.rd := fun e => h e.symm + simp [tasks, runOf, upd, h, h', hcd] + +/-- Removing the entries of `t` from a waiting list in which `t` waits once, + and putting `t` in front, gives the same tasks. -/ +theorem wake_perm (l : List (Tid × Option Nat)) (t : Tid) (hn : (l.map Prod.fst).Nodup) + (hm : ∃ w ∈ l, w.1 = t) : + (t :: (l.filter (fun w => !decide (w.1 = t))).map Prod.fst).Perm (l.map Prod.fst) := by + induction l with + | nil => obtain ⟨w, hw, _⟩ := hm; simp at hw + | cons w r ih => + simp only [List.map_cons, List.nodup_cons] at hn + by_cases hw : w.1 = t + · have hall : r.filter (fun w => !decide (w.1 = t)) = r := by + apply List.filter_eq_self.mpr + intro a ha + have hne : a.1 ≠ t := by + intro h + apply hn.1 + rw [hw, ← h] + exact List.mem_map_of_mem ha + simp [hne] + simp [hw, hall] + · have hm' : ∃ w' ∈ r, w'.1 = t := by + obtain ⟨w', hw', ht⟩ := hm + rcases List.mem_cons.mp hw' with rfl | h + · exact absurd ht hw + · exact ⟨w', h, ht⟩ + have h := ih hn.2 hm' + simp only [List.filter_cons, hw, decide_false, Bool.not_false, ite_true, List.map_cons] + exact (List.Perm.swap _ _ _).trans (h.cons _) + +theorem tasks_doWake (s : St) (t : Tid) (hn : ((s.wl (dom t)).map Prod.fst).Nodup) (d : Dom) : + (tasks d (doWake dom s t)).Perm (tasks d s) := by + unfold doWake + split + · next hany => + have hm : ∃ w ∈ s.wl (dom t), w.1 = t := by + obtain ⟨w, hw, h⟩ := List.any_eq_true.mp hany + exact ⟨w, hw, by simpa using h⟩ + have hp := wake_perm (s.wl (dom t)) t hn hm + by_cases h : d = dom t + · subst h + simp only [tasks, runOf, upd, ite_true, List.append_assoc] + exact (hp.append_left _).append_left _ + · simp [tasks, runOf, upd, h] + · exact List.Perm.refl _ + +/-- One step permutes the tasks of every domain. `Inv` is used for `block` + only (the task that blocks belongs to the running domain). The hypothesis + `hw` is used for a wake only: the woken task is at most once in its + waiting list. -/ +theorem step_tasks_perm_of (s : St) (hi : Inv dom s) (e : Ev) + (hw : ∀ t, e = .wake t ∨ e = .wakeX t → ((s.wl (dom t)).map Prod.fst).Nodup) (d : Dom) : + (tasks d (step dom s e)).Perm (tasks d s) := by + cases e with + | tick n => exact tasks_tick s n d + | poll n => exact tasks_poll s n d + | yield => exact tasks_yield s d + | block dl => exact tasks_block s hi dl d + | wake t => + simp only [step] + split + · exact tasks_doWake s t (hw t (Or.inl rfl)) d + · exact List.Perm.refl _ + | wakeX t => + simp only [step] + split + · exact tasks_doWake s t (hw t (Or.inr rfl)) d + · exact List.Perm.refl _ + | setTable t => exact List.Perm.refl _ + +/-- No task is lost and none is duplicated by a step: for every event, from a + state that satisfies `Inv` and has no task twice, the tasks of every domain + after the step are a permutation of the tasks before. In particular no + task moves to another domain. The order inside the queue and the + waiting list is not given by this theorem. -/ +theorem step_tasks_perm (s : St) (hi : Inv dom s) (hu : NoDup s) (e : Ev) (d : Dom) : + (tasks d (step dom s e)).Perm (tasks d s) := + step_tasks_perm_of s hi e (fun t _ => (List.nodup_append.mp (hu (dom t))).2.1) d + +/-- Every step keeps `NoDup`. -/ +theorem nodup_step (s : St) (hi : Inv dom s) (hu : NoDup s) (e : Ev) : NoDup (step dom s e) := + fun d => (step_tasks_perm s hi hu e d).nodup_iff.mpr (hu d) + +theorem nodup_exec (s : St) (hi : Inv dom s) (hu : NoDup s) (es : List Ev) : + NoDup (exec dom s es) := by + induction es generalizing s with + | nil => exact hu + | cons e es ih => exact ih _ (inv_step s hi e) (nodup_step s hi hu e) + +/-- The same over a run: after any list of events the tasks of every domain + are a permutation of the tasks at the start. -/ +theorem exec_tasks_perm (s : St) (hi : Inv dom s) (hu : NoDup s) (es : List Ev) (d : Dom) : + (tasks d (exec dom s es)).Perm (tasks d s) := by + induction es generalizing s with + | nil => exact List.Perm.refl _ + | cons e es ih => + exact (ih _ (inv_step s hi e) (nodup_step s hi hu e)).trans (step_tasks_perm s hi hu e d) + +theorem mem_tasks_doWake (s : St) (t : Tid) (d : Dom) (x : Tid) : + x ∈ tasks d (doWake dom s t) ↔ x ∈ tasks d s := by + unfold doWake + split + · next hany => + obtain ⟨w0, hw0, h0⟩ := List.any_eq_true.mp hany + have ht : w0.1 = t := by simpa using h0 + by_cases h : d = dom t + · subst h + simp only [tasks, upd, ite_true, List.mem_append, List.mem_map, List.mem_filter, + List.mem_singleton] + constructor + · rintro ((h1 | h1 | h1) | ⟨w, ⟨hw, _⟩, hx⟩) + · exact Or.inl (Or.inl h1) + · exact Or.inl (Or.inr h1) + · exact Or.inr ⟨w0, hw0, by rw [ht, h1]⟩ + · exact Or.inr ⟨w, hw, hx⟩ + · rintro ((h1 | h1) | ⟨w, hw, hx⟩) + · exact Or.inl (Or.inl h1) + · exact Or.inl (Or.inr (Or.inl h1)) + · by_cases hwt : w.1 = t + · exact Or.inl (Or.inr (Or.inr (by rw [← hx, hwt]))) + · exact Or.inr ⟨w, ⟨hw, by simp [hwt]⟩, hx⟩ + · simp [tasks, runOf, upd, h] + · exact Iff.rfl + +/-- Without `NoDup`: no task is lost by a step and none comes from nowhere. + For every event and every `Inv` state a task is among the tasks of `d` + after the step exactly if it was before. This says nothing about how + often it occurs; `step_tasks_perm` does, with `NoDup`. -/ +theorem step_tasks_mem (s : St) (hi : Inv dom s) (e : Ev) (d : Dom) (x : Tid) : + x ∈ tasks d (step dom s e) ↔ x ∈ tasks d s := by + cases e with + | wake t => + simp only [step] + split + · exact mem_tasks_doWake s t d x + · exact Iff.rfl + | wakeX t => + simp only [step] + split + · exact mem_tasks_doWake s t d x + · exact Iff.rfl + | tick n => exact (step_tasks_perm_of s hi (.tick n) (by simp) d).mem_iff + | poll n => exact (step_tasks_perm_of s hi (.poll n) (by simp) d).mem_iff + | yield => exact (step_tasks_perm_of s hi .yield (by simp) d).mem_iff + | block dl => exact (step_tasks_perm_of s hi (.block dl) (by simp) d).mem_iff + | setTable t => exact (step_tasks_perm_of s hi (.setTable t) (by simp) d).mem_iff + +/-- The same over a run. -/ +theorem exec_tasks_mem (s : St) (hi : Inv dom s) (es : List Ev) (d : Dom) (x : Tid) : + x ∈ tasks d (exec dom s es) ↔ x ∈ tasks d s := by + induction es generalizing s with + | nil => exact Iff.rfl + | cons e es ih => exact (ih _ (inv_step s hi e)).trans (step_tasks_mem s hi e d x) + +/-- `NoDup` at boot, from the lists given to `boot`. -/ +theorem nodup_boot (now first : Nat) (q0 : Dom → List Tid) (w0 : Dom → List (Tid × Option Nat)) + (h0 : (first :: (q0 0 ++ (w0 0).map Prod.fst)).Nodup) + (h : ∀ d, d ≠ 0 → (q0 d ++ (w0 d).map Prod.fst).Nodup) : + NoDup (boot now first q0 w0) := by + intro d + by_cases hd : d = 0 + · subst hd; simpa [tasks, runOf, boot] using h0 + · have h' : ¬ 0 = d := fun e => hd e.symm + simpa [tasks, runOf, boot, h'] using h d hd + +/-- What `doWake` does in the woken task's domain. -/ +theorem doWake_effect (s : St) (t : Tid) : + ((∃ dl, (t, dl) ∈ s.wl (dom t)) → + (doWake dom s t).q (dom t) = s.q (dom t) ++ [t] ∧ + (∀ w ∈ (doWake dom s t).wl (dom t), w.1 ≠ t) ∧ + (∀ w ∈ s.wl (dom t), w.1 ≠ t → w ∈ (doWake dom s t).wl (dom t))) ∧ + ((∀ dl, (t, dl) ∉ s.wl (dom t)) → doWake dom s t = s) := by + refine ⟨?_, ?_⟩ + · rintro ⟨dl, hdl⟩ + have hany : (s.wl (dom t)).any (fun w => decide (w.1 = t)) = true := + List.any_eq_true.mpr ⟨(t, dl), hdl, by simp⟩ + refine ⟨by simp [doWake, hany, upd], ?_, ?_⟩ + · intro w hw + simp only [doWake, hany, ite_true, upd] at hw + simpa using (List.mem_filter.mp hw).2 + · intro w hw hne + simp only [doWake, hany, ite_true, upd] + exact List.mem_filter.mpr ⟨hw, by simp [hne]⟩ + · intro hno + have hany : ¬ (s.wl (dom t)).any (fun w => decide (w.1 = t)) = true := by + intro h + obtain ⟨⟨a, b⟩, hw, hwt⟩ := List.any_eq_true.mp h + have ht : a = t := by simpa using hwt + subst ht + exact hno b hw + simp [doWake, hany] + +end conserve + +section wake + +/-- What a wake does. If the running task wakes a task `t` of its own domain + that waits, `t` goes to the back of its domain's queue and all its entries + leave the waiting list; the other waiters stay. If `t` does not wait, + nothing changes (a task that is ready or runs is not queued again). -/ +theorem wake_effect (dom : Tid → Dom) (s : St) (t : Tid) (hc : s.cur.isSome = true) + (hd : dom t = s.rd) : + ((∃ dl, (t, dl) ∈ s.wl (dom t)) → + (step dom s (.wake t)).q (dom t) = s.q (dom t) ++ [t] ∧ + (∀ w ∈ (step dom s (.wake t)).wl (dom t), w.1 ≠ t) ∧ + (∀ w ∈ s.wl (dom t), w.1 ≠ t → w ∈ (step dom s (.wake t)).wl (dom t))) ∧ + ((∀ dl, (t, dl) ∉ s.wl (dom t)) → step dom s (.wake t) = s) := by + have h : step dom s (.wake t) = doWake dom s t := by simp [step, hc, hd] + rw [h] + exact doWake_effect s t + +/-- The same for a wake across domains (`wakeX`). -/ +theorem wakeX_effect (dom : Tid → Dom) (s : St) (t : Tid) (hc : s.cur.isSome = true) + (hd : dom t ≠ s.rd) : + ((∃ dl, (t, dl) ∈ s.wl (dom t)) → + (step dom s (.wakeX t)).q (dom t) = s.q (dom t) ++ [t] ∧ + (∀ w ∈ (step dom s (.wakeX t)).wl (dom t), w.1 ≠ t) ∧ + (∀ w ∈ s.wl (dom t), w.1 ≠ t → w ∈ (step dom s (.wakeX t)).wl (dom t))) ∧ + ((∀ dl, (t, dl) ∉ s.wl (dom t)) → step dom s (.wakeX t) = s) := by + have h : step dom s (.wakeX t) = doWake dom s t := by simp [step, hc, hd] + rw [h] + exact doWake_effect s t + +end wake + +/-! Witnesses for the two sections above -/ + +/-- `sample` has no task twice, so `exec_tasks_perm` applies to its runs. -/ +theorem sample_nodup : NoDup sample := by + apply nodup_boot + · decide + · intro d hd + by_cases h1 : d = 1 + · subst h1; decide + · by_cases h2 : d = 2 + · subst h2; decide + · simp [hd, h1, h2] + +/-- A state with a task twice in a waiting list: task 1 of the root domain + waits twice while task 0 runs. -/ +def sDup : St := + boot 0 0 (fun _ => []) (fun d => if d = 0 then [(1, none), (1, none)] else []) + +/-- `NoDup` is needed in `step_tasks_perm`: `sDup` satisfies `Inv`, and one wake + of task 1 takes both entries out of the waiting list and queues it once. -/ +theorem wake_needs_nodup : + Inv dom0 sDup ∧ ¬ NoDup sDup ∧ + ¬ (tasks 0 (step dom0 sDup (.wake 1))).Perm (tasks 0 sDup) := by + refine ⟨?_, ?_, ?_⟩ + · apply inv_boot + · intro d t ht; simp at ht + · intro d w hw + by_cases hd : d = 0 + · subst hd; simp at hw; subst hw; decide + · simp [hd] at hw + · decide + · intro h + exact absurd (h 0) (by decide) + · decide + +/-- A state for timed waits: task 0 of the root domain runs, task 10 of domain 1 + is ready, task 11 of domain 1 and task 20 of domain 2 wait with deadline 3. -/ +def sT : St := + boot 0 0 (fun d => if d = 1 then [10] else []) + (fun d => if d = 1 then [(11, some 3)] else if d = 2 then [(20, some 3)] else []) + +/-- The table `[(0, 1), (1, 1), (2, 1)]` set at tick 0 starts at tick 2, so + tick 3 belongs to domain 1 and tick 4 to domain 2. Both timed waits are + due at tick 3. Tick 3 wakes task 11 (domain 1 runs) and leaves task 20 + waiting; tick 4 wakes task 20, which then runs. (The slice bit of the + running task is left out on purpose.) -/ +theorem example_timed_waits : + let es : List Ev := [.setTable [(0, 1), (1, 1), (2, 1)], .tick 1, .tick 2, .tick 3] + (exec dom0 sT es).rd = 1 ∧ + (exec dom0 sT es).cur.map Prod.fst = some 10 ∧ (exec dom0 sT es).q 1 = [11] ∧ + (exec dom0 sT es).wl 1 = [] ∧ (exec dom0 sT es).wl 2 = [(20, some 3)] ∧ + (exec dom0 sT (es ++ [.tick 4])).rd = 2 ∧ + (exec dom0 sT (es ++ [.tick 4])).cur.map Prod.fst = some 20 ∧ + (exec dom0 sT (es ++ [.tick 4])).wl 2 = [] := by + decide + + +/-! ## Headline theorems and their axioms -/ + +#print axioms pinv_pexec +#print axioms inv_exec +#print axioms guard_sound +#print axioms guard_sound_event +#print axioms guard_unsound_without_hyp +#print axioms guard_decision_flips +#print axioms exP_reachable +#print axioms setTable_now_needs_pendAfter +#print axioms cycle_append +#print axioms cycle_eq_sum +#print axioms domAtPos_window +#print axioms window_cover +#print axioms domAt_window +#print axioms plan_setTable_ge +#print axioms plan_setTable_window +#print axioms plan_setTable_lt +#print axioms plan_setTable_now +#print axioms table_effective_at +#print axioms first_table_never_governs +#print axioms running_domain_function +#print axioms running_domain_same +#print axioms tick_jump_domain +#print axioms no_slack_donation +#print axioms noninterference +#print axioms noninterference_final +#print axioms cross_wake_breaks +#print axioms tick_indexes_needed +#print axioms example_views_equal +#print axioms example_applies +#print axioms example_effects +#print axioms example_kernel_shaped +#print axioms serve_only_own +#print axioms serve_not_early +#print axioms blockIdleRust_eq +#print axioms poll_eq_tick +#print axioms tick_repeat_noop +#print axioms tick_zero_noop +#print axioms inv_with_duplicate +#print axioms sample_inv +#print axioms sample_nodup +#print axioms serve_wakes_due +#print axioms serve_due_order +#print axioms tick_serves +#print axioms tick_frame +#print axioms tick_old_domain +#print axioms poll_serves +#print axioms poll_frame +#print axioms block_keeps_deadline +#print axioms waiter_leaves_only +#print axioms example_timed_waits +#print axioms step_tasks_perm_of +#print axioms step_tasks_perm +#print axioms nodup_step +#print axioms nodup_exec +#print axioms nodup_boot +#print axioms exec_tasks_perm +#print axioms step_tasks_mem +#print axioms exec_tasks_mem +#print axioms wake_needs_nodup +#print axioms wake_effect +#print axioms wakeX_effect + +end K0Part diff --git a/proofs/lean/K0Share.lean b/proofs/lean/K0Share.lean new file mode 100644 index 0000000..8711038 --- /dev/null +++ b/proofs/lean/K0Share.lean @@ -0,0 +1,1270 @@ +/-! +# K0Share: the share bound inside one domain + +This file is a proof about a MODEL of one domain's own timeline. It is not a +proof about the Rust code (`k0-slice`, `k0-part`). Nothing here checks that the +Rust code implements the model; the host tests and review do that job. + +## What is modelled + +* One domain, seen on its own timeline. Time advances in whole steps. A tick + falls every `P` steps (`P >= 1`, a parameter). `c` is the number of steps left + until the next tick, `1 <= c <= P`. At time 0, `c = P - start` where `start` + is the offset of time 0 inside a period. +* Tasks are in a first-in first-out ready queue `q`. `cur` is the running task. + Task `0` is the spinner: it never yields and never blocks, nobody stops or + deletes it, and it is in the system (running or ready) from the start state + on. Every other task is controlled by the adversary and is anonymous (only + its being "not the spinner" matters). +* `ex` is the "between ticks" mark of `k0_slice::Slice` (`exempt`). `onTick` is + the same-domain branch of `k0_part::Core::tick` (the verdict of + `k0_slice::Slice::on_tick`, then the rotation): with the mark the tick only + clears it, without the mark the running task goes to the back and the head + enters by the tick's decision (no mark). If the queue is empty the running + task stays. +* Events (the adversary's choices, any finite list of them is a behaviour): + `run` (one step passes; the tick falls when `c` reaches 0, inside the same + event), `yield`, `block`, `wake t`. `yield`, `block` and `wake` take no time. + After `yield` or `block` the head runs with the mark. +* `wake t` puts a task at the back of the ready queue when fewer than `N` tasks + are ready or running. A blocked task is not counted, so `N` bounds the tasks + that are ready or running at one instant, not the tasks that exist. A wake + above `N` is dropped. This is an assumption about the domain (it never has + more than `N` runnable tasks), not a fact the model derives. The woken task + is anonymous, so a task that is already ready may be "woken" again; this is + only a bigger adversary than the real one (it can still never have more than + `N` tasks). + +## Adversary strength + +Any finite list of events is a behaviour, so the adversary may act adaptively +and at zero cost in time: any number of `yield`, `block` and `wake` between two +steps, also one step before a tick and right after it. The initial state is any +well-formed state (`Wf`): any queue order, any mark `ex`, any countdown +`1 <= c <= P`, any `age` that is consistent with `ex`. + +The adversary of this file has three limits that `K0ShareWide.lean` removes. +That file defines a wider model, proves the share bound, "no early cut" and a +wait bound for it, and shows that every behaviour of this file from a +well-formed state is a behaviour of the wider model (`Wide.contains`). + +* No event falls between the last step of a period and its tick (`run` does + both). In the kernel the handlers run with interrupts masked, so a timer + interrupt that becomes pending during a yield or a block is taken as soon as + the next task is entered, before that task has run. In `K0ShareWide.lean` + the tick is its own event. +* A ready task is never taken out of the queue. In the kernel a ready task + that is deleted leaves the queue from any position (`k0_ipc::teardown` calls + `k0_sched::remove_ready`). In `K0ShareWide.lean` that is the event `remove`. +* The cap `N` is a rule of `wake`: a wake above `N` is dropped without a + trace. In `K0ShareWide.lean` no wake is dropped, and the cap is a hypothesis + on the behaviour (`Wide.Capped`). + +These limits remain, here and in `K0ShareWide.lean`: + +* The spinner is in the system from the start state on and never arrives later + (`wake 0` changes nothing). For a spinner that becomes ready after the + start, use `share_bound_diff` from the state in which it is in the queue. + `c0` is then the countdown at that instant. +* Idle is not modelled (see below). +* The bound is relative to `N`. That the domain never has more than `N` tasks + ready or running is assumed, not derived. +* Time is counted in whole steps (see below). + +`Core::start` begins with one task and an empty queue. `start0` has the mark +set and allows any queue, so `share_bound_prefix` covers `Core::start` when the +first task is the spinner. A start without the mark, and a spinner that joins +later, are covered by `share_bound` and `share_bound_diff`, which take any +well-formed state. + +## What is NOT modelled + +* Other domains and the partition table (that is `K0Part.lean`, which this file + does not import). This is the timeline of one domain, windows are not cut. +* IPC, timeouts, capability operations, faults, task exit, console wake, as far + as their effect on the ready queue is a mix of `block` and `wake`, which the + adversary may do at any instant anyway. One effect is not such a mix: the + removal of a ready task. This file has no event for it; `K0ShareWide.lean` + has. +* Idle. The spinner is always ready or running, so the domain is never empty. + A task that gets the CPU out of idle (`Core::poll`, or `Core::tick` with + nothing running) is therefore outside `no_early_cut`. +* Timing noise of the real kernel (the switch path takes time, the counter is + read late, a late tick that skips numbers is one event in `Core::tick`). + Steps are exact here and every period has its tick. +* Cache and predictor channels. The bound is on CPU shares only. A task still + chooses when the others run by the instant at which it yields or blocks, so + the timing channel through the scheduler inside the domain stays. + +## Results + +* `share_bound` (headline): for every `N >= 1`, `P >= 1`, every behaviour `es` and + every time `t` (a prefix of `es` is a time), + `t <= N * ran(t) + (N-1)*P + c0`, with `c0 = P - start`. + Two `example`s at the end reach the constant (`N = 3, P = 2` and + `N = 4, P = 3`, with `ran = 0`). There is no theorem of tightness for all + `N` and `P`; a search outside this repository suggested it, but that is not + part of what Lean checks here. +* `no_early_cut`: a task that got the CPU is never cut by a tick before it has + run `P` steps. +* `wait_bound`: a ready task with `k` tasks to run before it (the running one + included) has become the running task within `(k+1)*P` steps. +* `step_time`, `exec_time`, `step_ran`, `exec_ran_le_time`, `alone_time_eq_ran`, + `adv_head_none`, `step_cur_keeps`, `step_age`, `age_counts`, `started_sound`: + what the counters `time`, `ran`, `age` and the helper definitions `runs`, + `started` stand for. Without them a change to one of these (a frozen `time`, + a `ran` that counts twice) would leave every theorem above intact. +-/ + +set_option linter.unusedSimpArgs false + +namespace K0Share + +/-- Adversary events. `run` lets one step pass. -/ +inductive Ev where + | run + | yield + | block + | wake (t : Nat) + +/-- State of the domain. `age` counts the steps the running task has run since it +got the CPU. It is a ghost field: no rule reads it, and in a start state it is +any value that `Wf` allows. `time` and `ran` count steps in total and steps in +which the spinner (task 0) was the running task. What the three counters count +is fixed by `step_time`, `step_ran` and `step_age`. -/ +structure St where + cur : Nat + ex : Bool + q : List Nat + c : Nat + age : Nat + time : Nat + ran : Nat + deriving Repr + +/-- The tick rule of `k0_slice` inside the domain. `P` is the period; the +countdown restarts. -/ +def onTick (P : Nat) (s : St) : St := + if s.ex then { s with ex := false, c := P } + else match s.q with + | [] => { s with c := P } + | x :: r => { s with cur := x, q := r ++ [s.cur], c := P, age := 0 } + +/-- One step of time passes. The tick falls after it when the countdown ends. -/ +def runStep (P : Nat) (s : St) : St := + let s1 : St := { s with time := s.time + 1, age := s.age + 1, + ran := s.ran + (if s.cur = 0 then 1 else 0) } + if s.c ≤ 1 then onTick P s1 else { s1 with c := s.c - 1 } + +/-- Number of tasks in the system (running and ready). -/ +def cnt (s : St) : Nat := s.q.length + 1 + +/-- One event. Events that the model excludes (the spinner yields or blocks, a +wake above `N` tasks, `wake 0`) change nothing. A yield or a block with an empty +queue changes nothing either; from a well-formed state that case cannot occur, +because a running task other than the spinner has the spinner behind it. -/ +def step (N P : Nat) (s : St) : Ev → St + | .run => runStep P s + | .yield => + if s.cur = 0 then s + else match s.q with + | [] => s + | x :: r => { s with cur := x, ex := true, q := r ++ [s.cur], age := 0 } + | .block => + if s.cur = 0 then s + else match s.q with + | [] => s + | x :: r => { s with cur := x, ex := true, q := r, age := 0 } + | .wake t => if t ≠ 0 ∧ cnt s < N then { s with q := s.q ++ [t] } else s + +/-- Run a behaviour. -/ +def exec (N P : Nat) (s : St) : List Ev → St + | [] => s + | e :: es => exec N P (step N P s e) es + +/-- Well-formed states: countdown in `1..P`, exactly one spinner in the system, +at most `N` tasks, and the task without the mark has already used up +`P - c` steps of its slice (`age + c >= P`). The last clause, on `age`, is +there for `no_early_cut`. The share bound does not need it (see +`share_bound_diff`). -/ +def Wf (N P : Nat) (s : St) : Prop := + 1 ≤ s.c ∧ s.c ≤ P ∧ (s.cur :: s.q).count 0 = 1 ∧ (s.cur :: s.q).length ≤ N ∧ + (s.ex = false → P ≤ s.age + s.c) + +/-- Number of tasks ahead of the first spinner in a queue. -/ +def pos : List Nat → Nat + | [] => 0 + | x :: xs => if x = 0 then 0 else pos xs + 1 + +/-- The potential. It bounds from above how much `time - N * ran` can still +grow. -/ +def psi (N P : Nat) (s : St) : Int := + if s.cur = 0 then + (if s.ex then 0 else ((N - 1 : Nat) : Int) * ((P : Int) - s.c)) + else (s.c : Int) + (if s.ex then (P : Int) else 0) + (pos s.q : Int) * P + +/-- `time - N * ran` -/ +def lag (N : Nat) (s : St) : Int := (s.time : Int) - (N : Int) * (s.ran : Int) + +/-- A start in the manner of `Core::start`: the first task entered between ticks +and `start` steps of the period are gone. `Core::start` itself has an empty +queue; here the queue is any `q`. -/ +def start0 (cur : Nat) (q : List Nat) (P start : Nat) : St := + { cur := cur, ex := true, q := q, c := P - start, age := 0, time := 0, ran := 0 } + + +/-! ## Facts about `pos` and the spinner count -/ + +theorem pos_lt {q : List Nat} (h : 0 ∈ q) : pos q < q.length := by + induction q with + | nil => simp at h + | cons x xs ih => + by_cases hx : x = 0 + · simp [pos, hx] + · have h0 : 0 ∈ xs := by + simp only [List.mem_cons] at h + rcases h with h | h + · exact absurd h.symm hx + · exact h + have := ih h0 + simp [pos, hx] + omega + +theorem pos_append_of_mem (y : Nat) {q : List Nat} (h : 0 ∈ q) : pos (q ++ [y]) = pos q := by + induction q with + | nil => simp at h + | cons x xs ih => + by_cases hx : x = 0 + · simp [pos, hx] + · have h0 : 0 ∈ xs := by + simp only [List.mem_cons] at h + rcases h with h | h + · exact absurd h.symm hx + · exact h + simp [pos, hx, ih h0] + +theorem pos_append_self {r : List Nat} (h : 0 ∉ r) : pos (r ++ [0]) = r.length := by + induction r with + | nil => simp [pos] + | cons x xs ih => + have hx : x ≠ 0 := fun e => h (by simp [e]) + have h' : 0 ∉ xs := fun e => h (by simp [e]) + simp [pos, hx, ih h'] + +theorem pos_cons_ne {x : Nat} (r : List Nat) (h : x ≠ 0) : pos (x :: r) = pos r + 1 := by + simp [pos, h] + +theorem pos_cons_zero (r : List Nat) : pos (0 :: r) = 0 := by + simp [pos] + +theorem mem_tail {x : Nat} {r : List Nat} (h : 0 ∈ x :: r) (hx : x ≠ 0) : 0 ∈ r := by + simp only [List.mem_cons] at h + rcases h with h | h + · exact absurd h.symm hx + · exact h + +theorem nonneg_mul (a b : Nat) : (0 : Int) ≤ (a : Int) * (b : Int) := by + exact_mod_cast Nat.zero_le (a * b) + +/-! ## One step of the potential argument -/ + +theorem run_pot (N P : Nat) (s : St) (hw : Wf N P s) : + Wf N P (step N P s .run) ∧ + lag N (step N P s .run) + psi N P (step N P s .run) ≤ lag N s + psi N P s := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + simp only at h1 h2 h3 h4 h5 + obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by simp at h4; omega⟩ + by_cases hc : cur = 0 + · subst hc + simp at h3 + have hq : 0 ∉ q := List.count_eq_zero.mp h3 + have hlen : q.length ≤ M := by simpa using h4 + by_cases hc1 : c = 1 + · subst hc1 + cases ex with + | true => + simp [step, runStep, onTick, Wf, lag, psi, Int.mul_add, Int.add_mul] + omega + | false => + cases q with + | nil => + have hMP : (0:Int) ≤ (M : Int) * ((P : Int) - 1) := + Int.mul_nonneg (by omega) (by omega) + rw [Int.mul_sub] at hMP + simp [step, runStep, onTick, Wf, lag, psi, Int.mul_add, Int.add_mul, Int.mul_sub] + omega + | cons x r => + have hx : x ≠ 0 := fun e => hq (by simp [e]) + have hr0 : 0 ∉ r := fun e => hq (by simp [e]) + have hr3 : List.count 0 r = 0 := List.count_eq_zero.mpr hr0 + have hrl : r.length + 1 ≤ M := by simpa using hlen + have hm : r.length * P + P ≤ M * P := by + have := Nat.mul_le_mul_right P hrl + rw [Nat.add_mul, Nat.one_mul] at this + exact this + have hm' : (r.length : Int) * P + P ≤ (M : Int) * P := by exact_mod_cast hm + simp [step, runStep, onTick, Wf, lag, psi, hx, pos_append_self hr0, + Int.mul_add, Int.add_mul, Int.mul_sub] + omega + · have hnle : ¬ c ≤ 1 := by omega + cases ex with + | true => + simp [step, runStep, onTick, Wf, lag, psi, hnle, Int.mul_add, Int.add_mul] + omega + | false => + have h5' := h5 rfl + obtain ⟨c', rfl⟩ : ∃ c', c = c' + 2 := ⟨c - 2, by omega⟩ + simp [step, runStep, Wf, lag, psi, Int.mul_add, Int.add_mul, Int.mul_sub] + omega + · have hq : 0 ∈ q := by + cases Decidable.em (0 ∈ q) with + | inl hm => exact hm + | inr hn => + have : List.count 0 q = 0 := List.count_eq_zero.mpr hn + simp [List.count_cons, hc] at h3 + omega + have hp := pos_lt hq + have h4' : q.length ≤ M := by simp at h4; omega + have hP0 := nonneg_mul (pos q) P + by_cases hc1 : c = 1 + · subst hc1 + cases ex with + | true => + simp [step, runStep, onTick, Wf, lag, psi, hc, Int.mul_add, Int.add_mul] + simp [List.count_cons, hc] at h3 + omega + | false => + cases q with + | nil => simp at hq + | cons x r => + by_cases hx : x = 0 + · subst hx + simp [List.count_cons, hc] at h3 + have hr3 : List.count 0 r = 0 := h3 + have hr0 : 0 ∉ r := List.count_eq_zero.mp h3 + simp [step, runStep, onTick, Wf, lag, psi, hc, pos_cons_zero, Int.mul_add, Int.add_mul] + simp at h4 + omega + · have hr := mem_tail hq hx + simp [List.count_cons, hc, hx] at h3 + have hr0 : (List.count 0 r) = 1 := by omega + simp [step, runStep, onTick, Wf, lag, psi, hc, hx, pos_cons_ne r hx, + pos_append_of_mem cur hr, List.count_cons, Int.mul_add, Int.add_mul] + simp at h4 + omega + · have hnle : ¬ c ≤ 1 := by omega + obtain ⟨c', rfl⟩ : ∃ c', c = c' + 2 := ⟨c - 2, by omega⟩ + cases ex with + | true => + simp [step, runStep, Wf, lag, psi, hc, Int.mul_add, Int.add_mul] + simp [List.count_cons, hc] at h3 + omega + | false => + have h5' := h5 rfl + simp [step, runStep, Wf, lag, psi, hc, Int.mul_add, Int.add_mul] + simp [List.count_cons, hc] at h3 + omega + +theorem yield_pot (N P : Nat) (s : St) (hw : Wf N P s) : + Wf N P (step N P s .yield) ∧ + lag N (step N P s .yield) + psi N P (step N P s .yield) ≤ lag N s + psi N P s := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + simp only at h1 h2 h3 h4 h5 + by_cases hc : cur = 0 + · subst hc + simp [step, Wf, lag, psi] + simp at h3 h4 + exact ⟨h1, h2, h3, h4, h5⟩ + · have hq : 0 ∈ q := by + cases Decidable.em (0 ∈ q) with + | inl hm => exact hm + | inr hn => + have : List.count 0 q = 0 := List.count_eq_zero.mpr hn + simp [List.count_cons, hc] at h3 + omega + have hP0 := nonneg_mul (pos q) P + cases q with + | nil => simp at hq + | cons x r => + by_cases hx : x = 0 + · subst hx + simp [List.count_cons, hc] at h3 + cases ex <;> + simp [step, Wf, lag, psi, hc, pos_cons_zero, List.count_cons] at * <;> omega + · have hr := mem_tail hq hx + simp [List.count_cons, hc, hx] at h3 + cases ex <;> + simp [step, Wf, lag, psi, hc, hx, pos_cons_ne r hx, pos_append_of_mem cur hr, + List.count_cons, Int.add_mul] at * <;> omega + +theorem block_pot (N P : Nat) (s : St) (hw : Wf N P s) : + Wf N P (step N P s .block) ∧ + lag N (step N P s .block) + psi N P (step N P s .block) ≤ lag N s + psi N P s := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + simp only at h1 h2 h3 h4 h5 + by_cases hc : cur = 0 + · subst hc + simp [step, Wf, lag, psi] + simp at h3 h4 + exact ⟨h1, h2, h3, h4, h5⟩ + · have hq : 0 ∈ q := by + cases Decidable.em (0 ∈ q) with + | inl hm => exact hm + | inr hn => + have : List.count 0 q = 0 := List.count_eq_zero.mpr hn + simp [List.count_cons, hc] at h3 + omega + have hP0 := nonneg_mul (pos q) P + cases q with + | nil => simp at hq + | cons x r => + by_cases hx : x = 0 + · subst hx + simp [List.count_cons, hc] at h3 + cases ex <;> + simp [step, Wf, lag, psi, hc, pos_cons_zero, List.count_cons] at * <;> omega + · have hr := mem_tail hq hx + simp [List.count_cons, hc, hx] at h3 + cases ex <;> + simp [step, Wf, lag, psi, hc, hx, pos_cons_ne r hx, pos_append_of_mem cur hr, + List.count_cons, Int.add_mul] at * <;> omega + +theorem wake_pot (N P : Nat) (s : St) (t : Nat) (hw : Wf N P s) : + Wf N P (step N P s (.wake t)) ∧ + lag N (step N P s (.wake t)) + psi N P (step N P s (.wake t)) ≤ lag N s + psi N P s := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + simp only at h1 h2 h3 h4 h5 + by_cases hg : t ≠ 0 ∧ cnt ⟨cur, ex, q, c, age, time, ran⟩ < N + · have hlt : q.length + 1 < N := hg.2 + have ht : t ≠ 0 := hg.1 + have e : step N P ⟨cur, ex, q, c, age, time, ran⟩ (.wake t) + = { cur := cur, ex := ex, q := q ++ [t], c := c, age := age, time := time, ran := ran } := by + simp only [step]; split + · rfl + · contradiction + rw [e] + by_cases hc : cur = 0 + · subst hc + simp [List.count_cons] at h3 + simp [cnt, Wf, lag, psi, List.count_cons, ht] + simp at h4 + refine ⟨h1, h2, h3, by omega, h5⟩ + · have hq : 0 ∈ q := by + cases Decidable.em (0 ∈ q) with + | inl hm => exact hm + | inr hn => + have : List.count 0 q = 0 := List.count_eq_zero.mpr hn + simp [List.count_cons, hc] at h3 + omega + simp [List.count_cons, hc] at h3 + simp [cnt, Wf, lag, psi, List.count_cons, ht, hc, pos_append_of_mem t hq] + simp at h4 + refine ⟨h1, h2, ?_, by omega, h5⟩ + omega + · simp [step, hg, Int.le_refl] + exact ⟨h1, h2, h3, h4, h5⟩ + +theorem step_pot (N P : Nat) (s : St) (hw : Wf N P s) (e : Ev) : + Wf N P (step N P s e) ∧ + lag N (step N P s e) + psi N P (step N P s e) ≤ lag N s + psi N P s := by + cases e with + | run => exact run_pot N P s hw + | yield => exact yield_pot N P s hw + | block => exact block_pot N P s hw + | wake t => exact wake_pot N P s t hw + +theorem exec_pot (N P : Nat) : ∀ (es : List Ev) (s : St), Wf N P s → + Wf N P (exec N P s es) ∧ + lag N (exec N P s es) + psi N P (exec N P s es) ≤ lag N s + psi N P s := by + intro es + induction es with + | nil => intro s hw; exact ⟨hw, Int.le_refl _⟩ + | cons e es ih => + intro s hw + obtain ⟨hw1, hl1⟩ := step_pot N P s hw e + obtain ⟨hw2, hl2⟩ := ih _ hw1 + exact ⟨hw2, by simp only [exec]; omega⟩ + +theorem psi_nonneg (N P : Nat) (s : St) (hw : Wf N P s) : 0 ≤ psi N P s := by + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + have hP0 := nonneg_mul (pos s.q) P + by_cases hc : s.cur = 0 + · cases hex : s.ex with + | true => simp [psi, hc, hex] + | false => + simp only [psi, hc, hex] + simp + exact Int.mul_nonneg (Int.natCast_nonneg _) (by omega) + · cases hex : s.ex <;> simp [psi, hc, hex] <;> omega + +theorem psi_le (N P : Nat) (s : St) (hw : Wf N P s) : + psi N P s ≤ ((N - 1 : Nat) : Int) * P + s.c := by + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by simp at h4; omega⟩ + have hMc : (0:Int) ≤ (M : Int) * (s.c : Int) := nonneg_mul M s.c + by_cases hc : s.cur = 0 + · cases hex : s.ex with + | true => + simp [psi, hc, hex] + have := nonneg_mul M P + omega + | false => + simp [psi, hc, hex, Int.mul_sub] + omega + · have hq : 0 ∈ s.q := by + cases Decidable.em (0 ∈ s.q) with + | inl hm => exact hm + | inr hn => + have : List.count 0 s.q = 0 := List.count_eq_zero.mpr hn + simp [List.count_cons, hc] at h3 + omega + have hp := pos_lt hq + simp at h4 + have hm : (pos s.q + 1) * P ≤ M * P := Nat.mul_le_mul_right P (by omega) + rw [Nat.add_mul, Nat.one_mul] at hm + have hm' : (pos s.q : Int) * P + P ≤ (M : Int) * P := by exact_mod_cast hm + cases hex : s.ex <;> simp [psi, hc, hex] <;> omega + +/-- HEADLINE, difference form. Starting from any well-formed state `s0` and +running any behaviour `es`, the steps that passed minus `N` times the steps in +which the spinner ran grew by at most `(N-1)*P + c0`, where `c0 = s0.c` is the +number of steps until the first tick. + +Of `Wf` this uses the countdown in `1..P`, the one spinner and the `N` tasks. +The `age` clause is not needed: no rule reads `age`, and +`Wide.share_bound_diff_base` in `K0ShareWide.lean` is this statement without +it. The statement is kept as it is so that one invariant serves all three +results. -/ +theorem share_bound_diff (N P : Nat) (s0 : St) (hw : Wf N P s0) (es : List Ev) : + (((exec N P s0 es).time : Int) - s0.time) ≤ + (N : Int) * (((exec N P s0 es).ran : Int) - s0.ran) + ((N - 1 : Nat) : Int) * P + s0.c := by + obtain ⟨hw1, hl⟩ := exec_pot N P es s0 hw + have h0 := psi_nonneg N P _ hw1 + have h1 := psi_le N P s0 hw + simp only [lag] at hl + rw [Int.mul_sub] + omega + +/-- HEADLINE. A system that starts at time 0 (`time = 0`, `ran = 0`) with the +countdown `c0 = P - start` to its first tick, `start < P` the offset of time 0 +inside a period. For every `N`, `P`, every adversary behaviour `es`: the number +of steps `t` that have passed is at most `N` times the number of steps in which +the spinner ran, plus `(N-1)*P + (P - start)`. Every prefix of a behaviour is a +behaviour, so this holds at every time `t`. In words: the spinner keeps at +least `1/N` of the CPU up to an additive constant of `N-1` ticks plus the rest +of the first period. + +`N` is the cap that `wake` enforces, so the bound is relative to that +assumption. The hypothesis `hr` (`ran = 0` at the start) is not needed: a +larger `ran` at the start only makes the right side larger +(`Wide.share_bound_base` in `K0ShareWide.lean` is this statement without `hr` +and without the `age` clause of `Wf`). It is kept so that the statement reads +as "a system that starts at time 0". -/ +theorem share_bound (N P : Nat) (s0 : St) (hw : Wf N P s0) + (ht : s0.time = 0) (hr : s0.ran = 0) (es : List Ev) : + (exec N P s0 es).time ≤ N * (exec N P s0 es).ran + (N - 1) * P + s0.c := by + have := share_bound_diff N P s0 hw es + rw [ht, hr] at this + refine Int.ofNat_le.mp ?_ + simp only [Int.natCast_add, Int.natCast_mul] + simp at this + omega + +/-- A system that starts as `Core::start` does: the first task `cur` entered +between ticks (mark set), `start < P` steps of the period are already gone. It is +well-formed when exactly one task of the system is the spinner and there are at +most `N` tasks. -/ +theorem wf_start0 (N P start cur : Nat) (q : List Nat) (hs : start < P) + (h1 : (cur :: q).count 0 = 1) (h2 : (cur :: q).length ≤ N) : + Wf N P (start0 cur q P start) := by + refine ⟨?_, ?_, h1, h2, ?_⟩ <;> simp [start0] <;> omega + +/-- The headline at the first `k` events of any behaviour (every time `t` is +reached by a prefix of some behaviour). This is `share_bound` at the list +`es.take k`, stated for `start0`. The prefix length `k` adds nothing: `es` +ranges over all lists, and `es.take k` is one of them, so the statement without +`take` (take `k = es.length`) says the same. -/ +theorem share_bound_prefix (N P start cur : Nat) (q : List Nat) (hs : start < P) + (h1 : (cur :: q).count 0 = 1) (h2 : (cur :: q).length ≤ N) (es : List Ev) (k : Nat) : + (exec N P (start0 cur q P start) (es.take k)).time ≤ + N * (exec N P (start0 cur q P start) (es.take k)).ran + (N - 1) * P + (P - start) := by + have := share_bound N P _ (wf_start0 N P start cur q hs h1 h2) rfl rfl (es.take k) + simpa [start0] using this + +/-! ## Lemma 2: a task that got the CPU is not cut before `P` steps -/ + +/-- A `run` step cuts the running task exactly when the running task's `age` +(steps since it got the CPU) is reset to 0 by it (`step_age`). When that +happens, the task has run at least `P` steps since it got the CPU, the step just +taken included. For one state this is the `age` clause of `Wf` read at the end +of the countdown; the content is that every behaviour keeps `Wf` +(`exec_no_early_cut`) and that `age` counts what its name says (`age_counts`). -/ +theorem no_early_cut (N P : Nat) (s : St) (hw : Wf N P s) + (h : (step N P s .run).age = 0) : P ≤ s.age + 1 := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + simp only at h1 h2 h3 h4 h5 + by_cases hc : c ≤ 1 + · cases ex with + | true => simp [step, runStep, onTick, hc] at h + | false => + have := h5 rfl + show P ≤ age + 1 + omega + · simp [step, runStep, hc] at h + +/-- The same along any behaviour: whenever the next `run` step cuts the running +task, that task has run at least `P` steps since it got the CPU. -/ +theorem exec_no_early_cut (N P : Nat) (s0 : St) (hw : Wf N P s0) (pre : List Ev) + (h : (step N P (exec N P s0 pre) .run).age = 0) : + P ≤ (exec N P s0 pre).age + 1 := + no_early_cut N P _ (exec_pot N P pre s0 hw).1 h + +/-! ## Lemma 3: a ready task starts within `(k+1)*P` steps + +A ready task is a slot `i` of the queue (`i` tasks ahead of it; with the running +task, `k = i + 1` tasks run before it). `adv s i e` follows the slot through the +event `e`: `none` when the task in the slot becomes the running task, `some j` +when it is now in slot `j`. `adv_track` and `adv_none` show that this really +follows the same task. -/ + +/-- Where the task in queue slot `i` is after event `e`; `none` if it started. -/ +def adv (s : St) (i : Nat) : Ev → Option Nat + | .run => + if s.c ≤ 1 ∧ s.ex = false ∧ s.q ≠ [] then + (match i with | 0 => none | j + 1 => some j) + else some i + | .yield => + if s.cur ≠ 0 ∧ s.q ≠ [] then (match i with | 0 => none | j + 1 => some j) else some i + | .block => + if s.cur ≠ 0 ∧ s.q ≠ [] then (match i with | 0 => none | j + 1 => some j) else some i + | .wake _ => some i + +/-- The slot `i` of `s` started to run at some event of the behaviour. This is +"became the running task at some event", not "is running at the end": the task +may be cut again later. `started_sound` says what it gives. -/ +def started (N P : Nat) : St → Nat → List Ev → Prop + | _, _, [] => False + | s, i, e :: es => + match adv s i e with + | none => True + | some j => started N P (step N P s e) j es + +/-- Number of `run` events, that is, steps of time (`exec_time`). -/ +def runs : List Ev → Nat + | [] => 0 + | .run :: es => runs es + 1 + | _ :: es => runs es + +/-- Steps still to wait for slot `i`, as a bound. -/ +def wt (P : Nat) (s : St) (i : Nat) : Nat := s.c + (if s.ex then P else 0) + i * P + +theorem run_q_keep (P : Nat) (s : St) (h : ¬ (s.c ≤ 1 ∧ s.ex = false ∧ s.q ≠ [])) : + (runStep P s).q = s.q := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at h + by_cases hc : c ≤ 1 + · cases ex with + | true => simp [runStep, onTick, hc] + | false => + cases q with + | nil => simp [runStep, onTick, hc] + | cons x r => exact absurd ⟨hc, rfl, by simp⟩ h + · simp [runStep, hc] + +theorem run_q_cut (P : Nat) (s : St) (h : s.c ≤ 1 ∧ s.ex = false ∧ s.q ≠ []) : + ∃ x r, s.q = x :: r ∧ (runStep P s).q = r ++ [s.cur] := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨hc, hex, hq⟩ := h + simp only at hc hex hq + subst hex + cases q with + | nil => exact absurd rfl hq + | cons x r => exact ⟨x, r, rfl, by simp [runStep, onTick, hc]⟩ + +/-- The slot is followed correctly: the same task, in its new slot. -/ +theorem adv_track (N P : Nat) (s : St) (i j : Nat) (e : Ev) (h : adv s i e = some j) + (hi : i < s.q.length) : + j < (step N P s e).q.length ∧ (step N P s e).q[j]? = s.q[i]? := by + cases e with + | run => + simp only [adv] at h + split at h + · rename_i hcut + obtain ⟨x, r, hq, hq'⟩ := run_q_cut P s hcut + cases i with + | zero => simp at h + | succ i => + simp at h + subst h + simp only [step] + rw [hq'] + rw [hq] at hi ⊢ + simp at hi ⊢ + refine ⟨by omega, ?_⟩ + rw [List.getElem?_append_left (by omega)] + · simp at h + subst h + simp only [step] + rw [run_q_keep P s ‹_›] + exact ⟨hi, rfl⟩ + | yield => + simp only [adv] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hc hq hi + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp at h + | succ i => + simp at h + subst h + simp [step, hc] at hi ⊢ + refine ⟨by omega, ?_⟩ + rw [List.getElem?_append_left (by omega)] + · rename_i hn + simp at h + subst h + have : step N P s .yield = s := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hn + by_cases hc : cur = 0 + · simp [step, hc] + · cases q with + | nil => simp [step] + | cons x r => exact absurd ⟨hc, by simp⟩ hn + rw [this] + exact ⟨hi, rfl⟩ + | block => + simp only [adv] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hc hq hi + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp at h + | succ i => + simp at h + subst h + simp [step, hc] at hi ⊢ + omega + · rename_i hn + simp at h + subst h + have : step N P s .block = s := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hn + by_cases hc : cur = 0 + · simp [step, hc] + · cases q with + | nil => simp [step] + | cons x r => exact absurd ⟨hc, by simp⟩ hn + rw [this] + exact ⟨hi, rfl⟩ + | wake t => + simp only [adv] at h + simp at h + subst h + simp only [step] + split + · simp + refine ⟨by omega, ?_⟩ + rw [List.getElem?_append_left hi] + · exact ⟨hi, rfl⟩ + +/-- The slot started: it was the head of the queue and it is now the running task. -/ +theorem adv_none (N P : Nat) (s : St) (i : Nat) (e : Ev) (h : adv s i e = none) : + i = 0 ∧ ∃ x r, s.q = x :: r ∧ (step N P s e).cur = x := by + cases e with + | run => + simp only [adv] at h + split at h + · rename_i hcut + obtain ⟨x, r, hq, _⟩ := run_q_cut P s hcut + cases i with + | zero => + refine ⟨rfl, x, r, hq, ?_⟩ + obtain ⟨hc, hex, _⟩ := hcut + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hq hc hex + subst hq; subst hex + simp [step, runStep, onTick, hc] + | succ i => simp at h + · simp at h + | yield => + simp only [adv] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hc hq + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => exact ⟨rfl, x, r, rfl, by simp [step, hc]⟩ + | succ i => simp at h + · simp at h + | block => + simp only [adv] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hc hq + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => exact ⟨rfl, x, r, rfl, by simp [step, hc]⟩ + | succ i => simp at h + · simp at h + | wake t => simp [adv] at h + +/-- Each event either starts the slot or moves it forward, and the bound `wt` +falls by one for each step of time. -/ +theorem wt_step (N P : Nat) (s : St) (hw : Wf N P s) (i j : Nat) (e : Ev) + (h : adv s i e = some j) (hi : i < s.q.length) : + wt P (step N P s e) j + (match e with | .run => 1 | _ => 0) ≤ wt P s i := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h1, h2, h3, h4, h5⟩ := hw + simp only at h1 h2 h3 h4 h5 hi + cases e with + | run => + by_cases hcut : c ≤ 1 ∧ ex = false ∧ q ≠ [] + · obtain ⟨hc, hex, hq⟩ := hcut + subst hex + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [adv, hc] at h + | succ i => + have hj : j = i := by simp [adv, hc] at h; omega + subst hj + have hc1 : c = 1 := by omega + subst hc1 + simp [step, runStep, onTick, wt, Nat.add_mul] + omega + · have hj : j = i := by + simp [adv, hcut] at h + omega + subst hj + by_cases hc : c ≤ 1 + · cases ex with + | true => + have hc1 : c = 1 := by omega + subst hc1 + simp [step, runStep, onTick, wt, Nat.add_mul] + omega + | false => + exfalso + apply hcut + refine ⟨hc, rfl, ?_⟩ + intro hq + subst hq + simp at hi + · obtain ⟨c', rfl⟩ : ∃ c', c = c' + 2 := ⟨c - 2, by omega⟩ + cases ex <;> simp [step, runStep, wt] <;> omega + | yield => + by_cases hcond : cur ≠ 0 ∧ q ≠ [] + · obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [adv, hc] at h + | succ i => + have hj : j = i := by simp [adv, hc] at h; omega + subst hj + cases ex <;> simp [step, hc, wt, Nat.add_mul] <;> omega + · have hj : j = i := by + simp [adv, hcond] at h + omega + subst hj + have : step N P ⟨cur, ex, q, c, age, time, ran⟩ .yield = ⟨cur, ex, q, c, age, time, ran⟩ := by + by_cases hc : cur = 0 + · simp [step, hc] + · cases q with + | nil => simp [step] + | cons x r => exact absurd ⟨hc, by simp⟩ hcond + rw [this] + simp + | block => + by_cases hcond : cur ≠ 0 ∧ q ≠ [] + · obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [adv, hc] at h + | succ i => + have hj : j = i := by simp [adv, hc] at h; omega + subst hj + cases ex <;> simp [step, hc, wt, Nat.add_mul] <;> omega + · have hj : j = i := by + simp [adv, hcond] at h + omega + subst hj + have : step N P ⟨cur, ex, q, c, age, time, ran⟩ .block = ⟨cur, ex, q, c, age, time, ran⟩ := by + by_cases hc : cur = 0 + · simp [step, hc] + · cases q with + | nil => simp [step] + | cons x r => exact absurd ⟨hc, by simp⟩ hcond + rw [this] + simp + | wake t => + have hj : j = i := by simp [adv] at h; omega + subst hj + simp only [step] + split <;> simp [wt] + +/-- The bound `wt` counts steps: if the behaviour has at least `wt P s i` steps +of time then the task in slot `i` has started. -/ +theorem wait_wt (N P : Nat) : ∀ (es : List Ev) (s : St) (i : Nat), Wf N P s → + i < s.q.length → wt P s i ≤ runs es → started N P s i es := by + intro es + induction es with + | nil => + intro s i hw _ hb + obtain ⟨h1, _⟩ := hw + simp [wt, runs] at hb + omega + | cons e es ih => + intro s i hw hi hb + simp only [started] + cases hadv : adv s i e with + | none => trivial + | some j => + simp only + obtain ⟨hj, _⟩ := adv_track N P s i j e hadv hi + have hwt := wt_step N P s hw i j e hadv hi + have hw1 := (step_pot N P s hw e).1 + apply ih _ _ hw1 hj + cases e <;> simp [runs] at hb hwt ⊢ <;> omega + +/-- LEMMA 3. A ready task with `k` tasks to run before it (the running one +included), that is in queue slot `k - 1`, starts to run within `(k+1)*P` steps of +time, whatever the other tasks do. -/ +theorem wait_bound (N P : Nat) (s : St) (hw : Wf N P s) (k : Nat) (hk : 1 ≤ k) + (hq : k - 1 < s.q.length) (es : List Ev) (hes : (k + 1) * P ≤ runs es) : + started N P s (k - 1) es := by + apply wait_wt N P es s (k - 1) hw hq + obtain ⟨h1, h2, _⟩ := hw + have : wt P s (k - 1) ≤ (k + 1) * P := by + simp only [wt] + have : (k + 1) * P = (k - 1) * P + 2 * P := by + obtain ⟨m, rfl⟩ : ∃ m, k = m + 1 := ⟨k - 1, by omega⟩ + simp [Nat.add_mul] + omega + rw [this] + cases s.ex <;> simp <;> omega + omega + +/-! ## What the counters and the helper definitions stand for + +`time`, `ran` and `age` are fields that the rules write and never read, and +`runs` and `started` occur only in statements. A change to one of them can +leave every theorem above intact: with `time` frozen the share bound is +trivially true. The statements below tie each of them down from outside its own +definition. -/ + +/-- `time` grows by one on a `run` and on no other event. -/ +theorem step_time (N P : Nat) (s : St) (e : Ev) : + (step N P s e).time = s.time + (match e with | .run => 1 | _ => 0) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | run => + by_cases hc : c ≤ 1 + · cases ex <;> cases q <;> simp [step, runStep, onTick, hc] + · simp [step, runStep, hc] + | yield => + by_cases h0 : cur = 0 + · simp [step, h0] + · cases q <;> simp [step, h0] + | block => + by_cases h0 : cur = 0 + · simp [step, h0] + · cases q <;> simp [step, h0] + | wake t => + simp only [step] + split <;> simp + +/-- The steps that pass in a behaviour are its `run` events: `time` at the end +is `time` at the start plus `runs es`. This ties `time` and `runs` to each +other, so `wait_bound` counts the same steps as `share_bound`. -/ +theorem exec_time (N P : Nat) : ∀ (es : List Ev) (s : St), + (exec N P s es).time = s.time + runs es := by + intro es + induction es with + | nil => intro s; rfl + | cons e es ih => + intro s + have h := step_time N P s e + simp only [exec, ih] + cases e <;> simp [runs] at h ⊢ <;> omega + +/-- `ran` grows by exactly one on a `run` that is taken while the spinner is the +running task, and on nothing else. The step is credited to the task that ran +it, also when the tick at its end hands the CPU over. -/ +theorem step_ran (N P : Nat) (s : St) (e : Ev) : + (step N P s e).ran = + s.ran + (match e with | .run => if s.cur = 0 then 1 else 0 | _ => 0) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | run => + by_cases hc : c ≤ 1 + · cases ex <;> cases q <;> simp [step, runStep, onTick, hc] + · simp [step, runStep, hc] + | yield => + by_cases h0 : cur = 0 + · simp [step, h0] + · cases q <;> simp [step, h0] + | block => + by_cases h0 : cur = 0 + · simp [step, h0] + · cases q <;> simp [step, h0] + | wake t => + simp only [step] + split <;> simp + +/-- Along any behaviour `ran` does not fall and grows by no more than `time`: +the spinner is not credited more steps than pass. -/ +theorem exec_ran_le_time (N P : Nat) : ∀ (es : List Ev) (s : St), + s.ran ≤ (exec N P s es).ran ∧ + (exec N P s es).ran + s.time ≤ (exec N P s es).time + s.ran := by + intro es + induction es with + | nil => intro s; exact ⟨Nat.le_refl _, by simp only [exec]; omega⟩ + | cons e es ih => + intro s + obtain ⟨h1, h2⟩ := ih (step N P s e) + have ht := step_time N P s e + have hr := step_ran N P s e + simp only [exec] + cases e with + | run => + simp only at ht hr + by_cases h0 : s.cur = 0 + · rw [ite_eq_left h0] at hr; omega + · rw [ite_eq_right h0] at hr; omega + | yield => simp only at ht hr; omega + | block => simp only at ht hr; omega + | wake t => simp only at ht hr; omega + +/-- With `N = 1` the spinner is alone and gets every step: `time` and `ran` grow +by the same amount along every behaviour. (So for `N = 1` the headline holds +with `c0` to spare.) -/ +theorem alone_time_eq_ran (P : Nat) : ∀ (es : List Ev) (s : St), Wf 1 P s → + (exec 1 P s es).time + s.ran = (exec 1 P s es).ran + s.time := by + intro es + induction es with + | nil => intro s _; simp only [exec]; omega + | cons e es ih => + intro s hw + have ih' := ih _ (step_pot 1 P s hw e).1 + obtain ⟨_, _, h3, h4, _⟩ := hw + have hq : s.q = [] := by + cases hs : s.q with + | nil => rfl + | cons x r => simp [hs] at h4 + have hc : s.cur = 0 := by + cases Decidable.em (s.cur = 0) with + | inl h => exact h + | inr h => simp [hq, h] at h3 + have ht := step_time 1 P s e + have hr := step_ran 1 P s e + simp only [exec] + cases e with + | run => simp only [hc, ite_true] at ht hr; omega + | yield => simp only at ht hr; omega + | block => simp only at ht hr; omega + | wake t => simp only at ht hr; omega + +/-- Slot 0 either starts or stays slot 0. -/ +theorem adv_head (s : St) (e : Ev) (j : Nat) (h : adv s 0 e = some j) : j = 0 := by + cases e with + | run => simp only [adv] at h; split at h <;> simp at h <;> omega + | yield => simp only [adv] at h; split at h <;> simp at h <;> omega + | block => simp only [adv] at h; split at h <;> simp at h <;> omega + | wake t => simp [adv] at h; omega + +/-- The events at which the head of the queue starts, spelled out: a `run` at +the end of the countdown with no mark and somebody waiting (a cut), or a +`yield` or a `block` of a task other than the spinner with somebody waiting. -/ +theorem adv_head_none (s : St) (e : Ev) : + adv s 0 e = none ↔ + match e with + | .run => s.c ≤ 1 ∧ s.ex = false ∧ s.q ≠ [] + | .yield => s.cur ≠ 0 ∧ s.q ≠ [] + | .block => s.cur ≠ 0 ∧ s.q ≠ [] + | .wake _ => False := by + cases e with + | run => simp only [adv]; split <;> simp_all + | yield => simp only [adv]; split <;> simp_all + | block => simp only [adv]; split <;> simp_all + | wake t => simp [adv] + +/-- The CPU changes hands only at the events at which the head of the queue +starts (`adv s 0 e = none`, spelled out in `adv_head_none`; by `adv_none` the +head is then the running task). At every other event the running task is the +same as before. -/ +theorem step_cur_keeps (N P : Nat) (s : St) (e : Ev) (h : adv s 0 e ≠ none) : + (step N P s e).cur = s.cur := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | run => + by_cases hc : c ≤ 1 + · cases ex with + | true => simp [step, runStep, onTick, hc] + | false => + cases q with + | nil => simp [step, runStep, onTick, hc] + | cons x r => simp [adv, hc] at h + · simp [step, runStep, hc] + | yield => + by_cases h0 : cur = 0 + · simp [step, h0] + · cases q with + | nil => simp [step, h0] + | cons x r => simp [adv, h0] at h + | block => + by_cases h0 : cur = 0 + · simp [step, h0] + · cases q with + | nil => simp [step, h0] + | cons x r => simp [adv, h0] at h + | wake t => + simp only [step] + split <;> rfl + +/-- `age` is 0 right after the CPU changed hands (by a `yield`, a `block` or a +cut; `adv_head_none`), it grows by one on every other `run`, and no other event +changes it. -/ +theorem step_age (N P : Nat) (s : St) (e : Ev) : + (step N P s e).age = + if adv s 0 e = none then 0 else s.age + (match e with | .run => 1 | _ => 0) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | run => + by_cases hc : c ≤ 1 + · cases ex <;> cases q <;> simp [step, runStep, onTick, adv, hc] + · simp [step, runStep, adv, hc] + | yield => + by_cases h0 : cur = 0 + · simp [step, adv, h0] + · cases q <;> simp [step, adv, h0] + | block => + by_cases h0 : cur = 0 + · simp [step, adv, h0] + · cases q <;> simp [step, adv, h0] + | wake t => + simp only [step, adv] + split <;> simp + +/-- `age` counts steps: along a behaviour in which the CPU does not change hands +(the head of the queue never starts), `age` grows by the number of `run` +events. With `step_age` this makes `age` the number of steps since the running +task got the CPU, for a task that got it during the behaviour. For a start +state `age` is whatever `Wf` allows. -/ +theorem age_counts (N P : Nat) : ∀ (es : List Ev) (s : St), ¬ started N P s 0 es → + (exec N P s es).age = s.age + runs es := by + intro es + induction es with + | nil => intro s _; rfl + | cons e es ih => + intro s h + simp only [started] at h + have ha := step_age N P s e + cases hadv : adv s 0 e with + | none => rw [hadv] at h; exact absurd trivial h + | some j => + rw [hadv] at h + simp only at h + have hj := adv_head s e j hadv + subst hj + rw [hadv] at ha + simp only [exec, ih _ h] + cases e <;> simp [runs] at ha ⊢ <;> omega + +/-- `started` means what its name says: if the task in queue slot `i` started +during `es`, then `es` splits as `pre ++ e :: post` such that the task is at the +head of the queue after `pre` and is the running task after `e`. In particular +the empty behaviour starts nothing. (Tasks are anonymous, so "the task" is the +content of the slot.) -/ +theorem started_sound (N P : Nat) : ∀ (es : List Ev) (s : St) (i : Nat), i < s.q.length → + started N P s i es → + ∃ pre e post, es = pre ++ e :: post ∧ (exec N P s pre).q.head? = s.q[i]? ∧ + some (exec N P s (pre ++ [e])).cur = s.q[i]? := by + intro es + induction es with + | nil => intro s i _ h; simp [started] at h + | cons e es ih => + intro s i hi h + simp only [started] at h + cases hadv : adv s i e with + | none => + obtain ⟨hi0, x, r, hq, hcur⟩ := adv_none N P s i e hadv + subst hi0 + refine ⟨[], e, es, rfl, ?_, ?_⟩ + · simp [exec, hq] + · simp [exec, hq, hcur] + | some j => + rw [hadv] at h + simp only at h + obtain ⟨hj, hq1⟩ := adv_track N P s i j e hadv hi + obtain ⟨pre, e', post, hes, h1, h2⟩ := ih _ j hj h + refine ⟨e :: pre, e', post, by rw [hes]; rfl, ?_, ?_⟩ + · rw [← hq1]; exact h1 + · rw [← hq1]; exact h2 + +/-! ## Tightness: the constant of `share_bound` is reached + +In the two instances below the first steps reach `t = N * ran + (N-1)*P + c0` +with `ran = 0`: the first task has the mark, the spinner is at the back, every +other task is busy. `decide` evaluates the model. -/ + +/-- `N = 3`, `P = 2`, `c0 = 2`: after `(N-1)*P + c0 = 6` steps the spinner has not +run once. -/ +example : (exec 3 2 { cur := 1, ex := true, q := [1, 0], c := 2, age := 0, time := 0, ran := 0 } + [.run, .run, .run, .run, .run, .run]).ran = 0 ∧ + (exec 3 2 { cur := 1, ex := true, q := [1, 0], c := 2, age := 0, time := 0, ran := 0 } + [.run, .run, .run, .run, .run, .run]).time = 6 := by decide + +/-- `N = 4`, `P = 3`, `c0 = 1`: `3*3 + 1 = 10` steps with no spinner step. -/ +example : (exec 4 3 { cur := 1, ex := true, q := [1, 1, 0], c := 1, age := 0, time := 0, ran := 0 } + (List.replicate 10 .run)).ran = 0 ∧ + (exec 4 3 { cur := 1, ex := true, q := [1, 1, 0], c := 1, age := 0, time := 0, ran := 0 } + (List.replicate 10 .run)).time = 10 := by decide + +#print axioms share_bound_diff +#print axioms share_bound +#print axioms share_bound_prefix +#print axioms no_early_cut +#print axioms exec_no_early_cut +#print axioms wait_bound +#print axioms step_time +#print axioms exec_time +#print axioms step_ran +#print axioms exec_ran_le_time +#print axioms alone_time_eq_ran +#print axioms adv_head_none +#print axioms step_cur_keeps +#print axioms step_age +#print axioms age_counts +#print axioms started_sound + +end K0Share diff --git a/proofs/lean/K0ShareWide.lean b/proofs/lean/K0ShareWide.lean new file mode 100644 index 0000000..700f42a --- /dev/null +++ b/proofs/lean/K0ShareWide.lean @@ -0,0 +1,1703 @@ +import K0Share + +/-! +# K0ShareWide: the share bound in a wider model of one domain + +This file is a proof about a MODEL of one domain's own timeline. It is not a +proof about the Rust code (`k0-slice`, `k0-part`, `k0-sched`). Nothing here +checks that the Rust code implements the model; the host tests and review do +that job. + +`K0Share.lean` leaves out three behaviours of the kernel. This file defines one +model that has all three, and proves the results of `K0Share.lean` again for it. +The state `St`, the tick rule `onTick`, the potential `psi` and `lag` are those +of `K0Share.lean`. + +## What is wider than in `K0Share.lean` + +* The tick is its own event. In `K0Share.lean` the event `run` lets one step + pass and delivers the tick when the countdown ends, so no event can fall + between the last step of a period and its tick. In the kernel that order + exists: the handlers run with interrupts masked, so a timer interrupt that + becomes pending during a yield or a block is taken when the next task is + entered, before that task has run. This is a reading of the kernel code, not + a Lean fact. Here `step` lets one step pass and needs a countdown above 0, + `tick` delivers the tick and needs a countdown of 0, and any events may come + between the two. No step passes while a tick is due. +* `remove i` takes the ready task in queue slot `i` out of the queue, from any + position (`k0_ipc::teardown` calls `k0_sched::remove_ready`). The spinner is + never removed. The running task does not leave this way; that is `block`. +* `wake` has no cap, and `N` does not occur in the transition function. The + headline takes the cap as a hypothesis on the run: `Capped N P s0 es` says + that no state along the run has more than `N` tasks ready or running. + +As in `K0Share.lean`, any finite list of events is a behaviour, and an event +that cannot happen changes nothing (a `step` while a tick is due, a `tick` +that is not due, a yield or a block of the spinner, `wake 0`, a `remove` of an +empty slot or of the spinner). + +## What is still NOT modelled + +* A spinner that arrives later. Task `0` is in the system (running or ready) + from the start state on (`Inv`), and `wake 0` changes nothing. For a spinner + that becomes ready later, use `share_bound_diff` from the state in which it + is in the queue. +* Idle. The spinner is always ready or running, so the domain is never empty, + and a task that gets the CPU out of idle is outside `no_early_cut`. +* A proof of the cap. That a domain never has more than `N` tasks ready or + running is a hypothesis (`Capped`), and the bound is relative to that `N`. +* Time below one step. Steps are whole, every period has its tick, and the + tick is not late: the model lets no step pass while a tick is due. The switch + path of the real kernel takes time and the counter is read late. +* Other domains and the partition table (`K0Part.lean`). This is the timeline + of one domain, windows are not cut. +* Cache and predictor channels. The bound is on CPU shares only. A task still + chooses when the others run by the instant at which it yields or blocks, so + the timing channel through the scheduler inside the domain stays. + +## Results (all about the model) + +* `share_bound` (headline), `share_bound_diff`, `share_bound_always`: from a + state with a countdown `c0 <= P` and exactly one spinner (`Inv`), for every + behaviour `es` that is `Capped N`, + `time <= N * ran + (N - 1) * P + c0`, at the end of the run and at every + instant of it. For `P = 0` the countdown is 0, no step ever passes, and the + statement says nothing. `share_bound_reached` is one instance in which the + hypotheses hold and the constant is reached; there is no theorem of + tightness for all `N` and `P`. +* `wexec_widen`, `capped_widen`, `contains`: every behaviour of `K0Share.lean` + from a state with a countdown above 0 is a behaviour of this model with the + same final state, and it keeps the cap when the start state does. + `share_bound_base` and `share_bound_diff_base` get the headline of + `K0Share.lean` back from the headline here, without two hypotheses that the + former does not need (`ran = 0` at the start, the `age` clause of `Wf`). +* `no_early_cut`: when a tick takes the CPU from the running task, that task + has run at least `P` steps since it got the CPU. `tick_keeps`: no other tick + takes it. +* `wait_bound`, `wait_bound_passed`, `wait_bound_tick`: a ready task with `k` + tasks to run before it becomes the running task at an instant no later than + `(k + 1) * P` steps of time after the start, unless it is removed. The form + of `K0Share.lean` ("after `(k + 1) * P` steps it has started") is false here, + because at exactly that many steps the last tick may still be due + (`wait_at_bound`). The section says what is proved instead. + `fate_instance` shows the three outcomes on one state. +* Witnesses: `tick_after_yield` with `tick_after_yield_not_base` and + `base_mark_needs_step` (an order that `K0Share.lean` cannot express), + `remove_not_block_wake` (the removal is not a mix of the other events), + `cap_needed` (the hypothesis `Capped` is needed). +* `wstep_time`, `wstep_ran`, `wstep_age`, `wexec_ran_le_time`: what the three + counters count. `follow_waits`, `follow_started`, `follow_removed`, + `fate_started`, `fate_removed`: what the words of the wait bound mean. + +`#print axioms` lines are at the end of the file. +-/ + +namespace K0Share.Wide + +/-! ## The model -/ + +/-- Events of the wide model. `step` lets one step of time pass. `tick` is the +timer tick. `remove i` takes the ready task in queue slot `i` away. -/ +inductive Event where + | step + | tick + | yield + | block + | wake (t : Nat) + | remove (i : Nat) + deriving DecidableEq, Repr + +/-- One event. `step` needs a countdown above 0 and `tick` a countdown of 0; +otherwise they change nothing. `yield` and `block` are those of `K0Share.step`. +`wake` has no cap. `remove` leaves the spinner and an empty slot alone. -/ +def wstep (P : Nat) (s : St) : Event → St + | .step => + if 1 ≤ s.c then + { s with time := s.time + 1, age := s.age + 1, + ran := s.ran + (if s.cur = 0 then 1 else 0), c := s.c - 1 } + else s + | .tick => if s.c = 0 then onTick P s else s + | .yield => + if s.cur = 0 then s + else match s.q with + | [] => s + | x :: r => { s with cur := x, ex := true, q := r ++ [s.cur], age := 0 } + | .block => + if s.cur = 0 then s + else match s.q with + | [] => s + | x :: r => { s with cur := x, ex := true, q := r, age := 0 } + | .wake t => if t = 0 then s else { s with q := s.q ++ [t] } + | .remove i => if s.q[i]? = some 0 then s else { s with q := s.q.eraseIdx i } + +/-- Run a behaviour. -/ +def wexec (P : Nat) (s : St) : List Event → St + | [] => s + | e :: es => wexec P (wstep P s e) es + +/-- The invariant of the share bound: the countdown is in `0..P` (0 is the +instant between the last step of a period and its tick) and exactly one task in +the system is the spinner. It does not mention `N` or `age`. -/ +def Inv (P : Nat) (s : St) : Prop := + s.c ≤ P ∧ (s.cur :: s.q).count 0 = 1 + +/-- The invariant of `no_early_cut`: the task without the mark has already used +up `P - c` steps of its slice. -/ +def AgeOk (P : Nat) (s : St) : Prop := s.ex = false → P ≤ s.age + s.c + +/-- The cap as a hypothesis on a run: no state along the run, the first and the +last included, has more than `N` tasks ready or running. `es.take k` is the run +up to its `k`-th event. -/ +def Capped (N P : Nat) (s : St) (es : List Event) : Prop := + ∀ k, cnt (wexec P s (es.take k)) ≤ N + +/-! ## Runs and the cap -/ + +theorem wexec_append (P : Nat) : ∀ (a b : List Event) (s : St), + wexec P s (a ++ b) = wexec P (wexec P s a) b := by + intro a + induction a with + | nil => intro b s; rfl + | cons e a ih => intro b s; exact ih b (wstep P s e) + +theorem capped_head {N P : Nat} {s : St} {es : List Event} (h : Capped N P s es) : + cnt s ≤ N := by + simpa [wexec] using h 0 + +theorem capped_last {N P : Nat} {s : St} {es : List Event} (h : Capped N P s es) : + cnt (wexec P s es) ≤ N := by + simpa using h es.length + +/-- A prefix of a run that keeps the cap keeps the cap. -/ +theorem capped_take {N P : Nat} {s : St} {es : List Event} (h : Capped N P s es) (k : Nat) : + Capped N P s (es.take k) := by + intro j + rw [List.take_take] + exact h _ + +theorem capped_nil (N P : Nat) (s : St) : Capped N P s [] ↔ cnt s ≤ N := by + constructor + · intro h; exact capped_head h + · intro h k; simpa [wexec] using h + +theorem capped_cons (N P : Nat) (s : St) (e : Event) (es : List Event) : + Capped N P s (e :: es) ↔ cnt s ≤ N ∧ Capped N P (wstep P s e) es := by + constructor + · intro h + refine ⟨capped_head h, fun k => ?_⟩ + simpa [wexec] using h (k + 1) + · intro ⟨h0, h⟩ k + cases k with + | zero => simpa [wexec] using h0 + | succ k => simpa [wexec] using h k + +theorem capped_append (N P : Nat) : ∀ (a b : List Event) (s : St), + Capped N P s (a ++ b) ↔ Capped N P s a ∧ Capped N P (wexec P s a) b := by + intro a + induction a with + | nil => + intro b s + exact ⟨fun h => ⟨(capped_nil N P s).mpr (capped_head h), h⟩, fun h => h.2⟩ + | cons e a ih => + intro b s + simp only [List.cons_append, capped_cons, ih, wexec, and_assoc] + +/-! ## Facts about the queue -/ + +theorem count_erase {q : List Nat} {i : Nat} (h : q[i]? ≠ some 0) : + (q.eraseIdx i).count 0 = q.count 0 := by + induction q generalizing i with + | nil => simp + | cons x xs ih => + cases i with + | zero => + have hx : x ≠ 0 := by simpa using h + simp [hx] + | succ i => + have h' : xs[i]? ≠ some 0 := by simpa using h + simp [List.count_cons, ih h'] + +theorem pos_erase {q : List Nat} {i : Nat} (h : q[i]? ≠ some 0) : + pos (q.eraseIdx i) ≤ pos q := by + induction q generalizing i with + | nil => simp + | cons x xs ih => + cases i with + | zero => + have hx : x ≠ 0 := by simpa using h + simp [pos, hx] + | succ i => + have h' : xs[i]? ≠ some 0 := by simpa using h + have := ih h' + by_cases hx : x = 0 + · simp [pos, hx] + · simp [pos, hx] + omega + +/-- A running task other than the spinner has the spinner in the queue. -/ +theorem mem_of_count {cur : Nat} {q : List Nat} (hc : cur ≠ 0) (h : (cur :: q).count 0 = 1) : + 0 ∈ q ∧ q.count 0 = 1 := by + have h1 : q.count 0 = 1 := by simpa [List.count_cons, hc] using h + refine ⟨?_, h1⟩ + cases Decidable.em (0 ∈ q) with + | inl hm => exact hm + | inr hn => + have : List.count 0 q = 0 := List.count_eq_zero.mpr hn + omega + +/-! ## The potential argument -/ + +theorem inv_wstep (P : Nat) (s : St) (e : Event) (hi : Inv P s) : Inv P (wstep P s e) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h2, h3⟩ := hi + simp only at h2 h3 + cases e with + | step => + by_cases hc : 1 ≤ c + · refine ⟨?_, ?_⟩ + · simp [wstep, hc]; omega + · simpa [wstep, hc] using h3 + · have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .step = ⟨cur, ex, q, c, age, time, ran⟩ := by + simp [wstep, hc] + rw [this]; exact ⟨h2, h3⟩ + | tick => + by_cases hc0 : c = 0 + · subst hc0 + cases ex with + | true => exact ⟨by simp [wstep, onTick], by simpa [wstep, onTick] using h3⟩ + | false => + cases q with + | nil => exact ⟨by simp [wstep, onTick], by simpa [wstep, onTick] using h3⟩ + | cons x r => + refine ⟨by simp [wstep, onTick], ?_⟩ + simp [wstep, onTick, List.count_cons] at h3 ⊢ + omega + · have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .tick = ⟨cur, ex, q, c, age, time, ran⟩ := by + simp [wstep, hc0] + rw [this]; exact ⟨h2, h3⟩ + | yield => + by_cases hc : cur = 0 + · have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .yield = ⟨cur, ex, q, c, age, time, ran⟩ := by + simp [wstep, hc] + rw [this]; exact ⟨h2, h3⟩ + · cases q with + | nil => simp [hc] at h3 + | cons x r => + refine ⟨by simpa [wstep, hc] using h2, ?_⟩ + simp [wstep, hc, List.count_cons] at h3 ⊢ + omega + | block => + by_cases hc : cur = 0 + · have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .block = ⟨cur, ex, q, c, age, time, ran⟩ := by + simp [wstep, hc] + rw [this]; exact ⟨h2, h3⟩ + · cases q with + | nil => simp [hc] at h3 + | cons x r => + refine ⟨by simpa [wstep, hc] using h2, ?_⟩ + simp [wstep, hc, List.count_cons] at h3 ⊢ + omega + | wake t => + by_cases ht : t = 0 + · have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ (.wake t) = ⟨cur, ex, q, c, age, time, ran⟩ := by + simp [wstep, ht] + rw [this]; exact ⟨h2, h3⟩ + · refine ⟨by simpa [wstep, ht] using h2, ?_⟩ + simp [wstep, ht, List.count_cons] at h3 ⊢ + omega + | remove i => + by_cases hr : q[i]? = some 0 + · have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ (.remove i) = ⟨cur, ex, q, c, age, time, ran⟩ := by + simp [wstep, hr] + rw [this]; exact ⟨h2, h3⟩ + · refine ⟨by simpa [wstep, hr] using h2, ?_⟩ + have := count_erase hr + simp [wstep, hr, List.count_cons] at h3 ⊢ + omega + +/-- No event raises `lag + psi`. The cap is used at one place only: when the +tick cuts the spinner, the tasks that now run before it are at most `N - 1`. -/ +theorem pot_wstep (N P : Nat) (s : St) (e : Event) (hi : Inv P s) (hN : cnt s ≤ N) : + lag N (wstep P s e) + psi N P (wstep P s e) ≤ lag N s + psi N P s := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h2, h3⟩ := hi + simp only at h2 h3 + have hlen : q.length + 1 ≤ N := hN + obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by omega⟩ + have hP0 := nonneg_mul (pos q) P + cases e with + | step => + by_cases hc1 : 1 ≤ c + · obtain ⟨c', rfl⟩ : ∃ c', c = c' + 1 := ⟨c - 1, by omega⟩ + by_cases hc : cur = 0 + · subst hc + cases ex with + | true => + simp [wstep, lag, psi, Int.mul_add, Int.add_mul] + omega + | false => + simp [wstep, lag, psi, Int.mul_add, Int.add_mul, Int.mul_sub] + omega + · cases ex <;> simp [wstep, lag, psi, hc, Int.add_mul] <;> omega + · simp [wstep, hc1] + | tick => + by_cases hc0 : c = 0 + · subst hc0 + by_cases hc : cur = 0 + · subst hc + have hq : 0 ∉ q := List.count_eq_zero.mp (by simpa using h3) + cases ex with + | true => simp [wstep, onTick, lag, psi] + | false => + cases q with + | nil => + have hMP := nonneg_mul M P + simp [wstep, onTick, lag, psi] + omega + | cons x r => + have hx : x ≠ 0 := fun e => hq (by simp [e]) + have hr0 : 0 ∉ r := fun e => hq (by simp [e]) + have hrl : r.length + 1 ≤ M := by simpa using hlen + have hm : r.length * P + P ≤ M * P := by + have := Nat.mul_le_mul_right P hrl + rw [Nat.add_mul, Nat.one_mul] at this + exact this + have hm' : (r.length : Int) * P + P ≤ (M : Int) * P := by exact_mod_cast hm + simp [wstep, onTick, lag, psi, hx, pos_append_self hr0] + omega + · obtain ⟨hq, _⟩ := mem_of_count hc h3 + cases ex with + | true => simp [wstep, onTick, lag, psi, hc] + | false => + cases q with + | nil => simp at hq + | cons x r => + by_cases hx : x = 0 + · subst hx + simp [wstep, onTick, lag, psi, hc, pos_cons_zero] + · have hr := mem_tail hq hx + simp [wstep, onTick, lag, psi, hc, hx, pos_cons_ne r hx, + pos_append_of_mem cur hr, Int.add_mul] + omega + · simp [wstep, hc0] + | yield => + by_cases hc : cur = 0 + · simp [wstep, hc] + · obtain ⟨hq, _⟩ := mem_of_count hc h3 + cases q with + | nil => simp at hq + | cons x r => + by_cases hx : x = 0 + · subst hx + cases ex <;> simp [wstep, lag, psi, hc, pos_cons_zero] at hP0 ⊢ <;> omega + · have hr := mem_tail hq hx + cases ex <;> + simp [wstep, lag, psi, hc, hx, pos_cons_ne r hx, pos_append_of_mem cur hr, + Int.add_mul] at hP0 ⊢ <;> omega + | block => + by_cases hc : cur = 0 + · simp [wstep, hc] + · obtain ⟨hq, _⟩ := mem_of_count hc h3 + cases q with + | nil => simp at hq + | cons x r => + by_cases hx : x = 0 + · subst hx + cases ex <;> simp [wstep, lag, psi, hc, pos_cons_zero] at hP0 ⊢ <;> omega + · cases ex <;> + simp [wstep, lag, psi, hc, hx, pos_cons_ne r hx, Int.add_mul] at hP0 ⊢ <;> omega + | wake t => + by_cases ht : t = 0 + · simp [wstep, ht] + · by_cases hc : cur = 0 + · simp [wstep, ht, lag, psi, hc] + · obtain ⟨hq, _⟩ := mem_of_count hc h3 + simp [wstep, ht, lag, psi, hc, pos_append_of_mem t hq] + | remove i => + by_cases hr : q[i]? = some 0 + · simp [wstep, hr] + · have hmul : (pos (q.eraseIdx i) : Int) * P ≤ (pos q : Int) * P := by + exact_mod_cast Nat.mul_le_mul_right P (pos_erase hr) + by_cases hc : cur = 0 + · simp [wstep, hr, lag, psi, hc] + · cases ex <;> simp [wstep, hr, lag, psi, hc] <;> omega + +theorem pot_wexec (N P : Nat) : ∀ (es : List Event) (s : St), Inv P s → Capped N P s es → + Inv P (wexec P s es) ∧ + lag N (wexec P s es) + psi N P (wexec P s es) ≤ lag N s + psi N P s := by + intro es + induction es with + | nil => intro s hi _; exact ⟨hi, Int.le_refl _⟩ + | cons e es ih => + intro s hi hN + obtain ⟨h0, hN'⟩ := (capped_cons N P s e es).mp hN + have hl1 := pot_wstep N P s e hi h0 + obtain ⟨hi2, hl2⟩ := ih _ (inv_wstep P s e hi) hN' + exact ⟨hi2, by simp only [wexec]; omega⟩ + +theorem pot_nonneg (N P : Nat) (s : St) (hi : Inv P s) : 0 ≤ psi N P s := by + obtain ⟨h2, _⟩ := hi + have hP0 := nonneg_mul (pos s.q) P + by_cases hc : s.cur = 0 + · cases hex : s.ex with + | true => simp [psi, hc, hex] + | false => + simp only [psi, hc, hex] + simp + exact Int.mul_nonneg (Int.natCast_nonneg _) (by omega) + · cases hex : s.ex <;> simp [psi, hc, hex] <;> omega + +theorem pot_le (N P : Nat) (s : St) (hi : Inv P s) (hN : cnt s ≤ N) : + psi N P s ≤ ((N - 1 : Nat) : Int) * P + s.c := by + obtain ⟨h2, h3⟩ := hi + have hlen : s.q.length + 1 ≤ N := hN + obtain ⟨M, rfl⟩ : ∃ M, N = M + 1 := ⟨N - 1, by omega⟩ + have hMc : (0:Int) ≤ (M : Int) * (s.c : Int) := nonneg_mul M s.c + by_cases hc : s.cur = 0 + · cases hex : s.ex with + | true => + simp [psi, hc, hex] + have := nonneg_mul M P + omega + | false => + simp [psi, hc, hex, Int.mul_sub] + omega + · obtain ⟨hq, _⟩ := mem_of_count hc h3 + have hp := pos_lt hq + have hm : (pos s.q + 1) * P ≤ M * P := Nat.mul_le_mul_right P (by omega) + rw [Nat.add_mul, Nat.one_mul] at hm + have hm' : (pos s.q : Int) * P + P ≤ (M : Int) * P := by exact_mod_cast hm + cases hex : s.ex <;> simp [psi, hc, hex] <;> omega + +/-! ## The share bound -/ + +/-- HEADLINE, difference form. From any state `s0` with a countdown `c0 <= P` +and exactly one spinner, along any behaviour `es` of the wide model that never +holds more than `N` tasks ready or running: the steps that passed minus `N` +times the steps in which the spinner ran grew by at most `(N-1)*P + c0`. + +The cap is a hypothesis; nothing here shows that a domain keeps it. The +statement needs no hypothesis on `age`. -/ +theorem share_bound_diff (N P : Nat) (s0 : St) (hi : Inv P s0) (es : List Event) + (hN : Capped N P s0 es) : + (((wexec P s0 es).time : Int) - s0.time) ≤ + (N : Int) * (((wexec P s0 es).ran : Int) - s0.ran) + ((N - 1 : Nat) : Int) * P + s0.c := by + obtain ⟨hi1, hl⟩ := pot_wexec N P es s0 hi hN + have h0 := pot_nonneg N P _ hi1 + have h1 := pot_le N P s0 hi (capped_head hN) + simp only [lag] at hl + rw [Int.mul_sub] + omega + +/-- HEADLINE. A system that starts at time 0 with the countdown `c0` to its +first tick and with the spinner in it. For every `N`, `P` and every behaviour +`es` of the wide model: if no state along the run has more than `N` tasks ready +or running, then the number of steps that have passed is at most `N` times the +number of steps in which the spinner ran, plus `(N-1)*P + c0`. + +This is a statement about the model. `N` is not derived: the theorem says +nothing about a run that at some instant holds more than `N` tasks +(`cap_needed`). The spinner must be in the system from `s0` on. -/ +theorem share_bound (N P : Nat) (s0 : St) (hi : Inv P s0) (ht : s0.time = 0) + (es : List Event) (hN : Capped N P s0 es) : + (wexec P s0 es).time ≤ N * (wexec P s0 es).ran + (N - 1) * P + s0.c := by + have h := share_bound_diff N P s0 hi es hN + have hr := nonneg_mul N s0.ran + rw [ht, Int.mul_sub] at h + refine Int.ofNat_le.mp ?_ + simp only [Int.natCast_add, Int.natCast_mul] + simp at h + omega + +/-- The headline at every instant of the run: `es.take k` is the run up to its +`k`-th event. -/ +theorem share_bound_always (N P : Nat) (s0 : St) (hi : Inv P s0) (ht : s0.time = 0) + (es : List Event) (hN : Capped N P s0 es) (k : Nat) : + (wexec P s0 (es.take k)).time ≤ + N * (wexec P s0 (es.take k)).ran + (N - 1) * P + s0.c := + share_bound N P s0 hi ht _ (capped_take hN k) + +/-- The hypotheses of `share_bound` hold together and the constant is reached: +`N = 3`, `P = 2`, `c0 = 2`, the first task has the mark and the spinner is at +the back. After `(N-1)*P + c0 = 6` steps the spinner has not run once. This is +the first tightness instance of `K0Share.lean` written in the events of this +file. There is no theorem of tightness for all `N` and `P`. -/ +theorem share_bound_reached : + Inv 2 (start0 1 [1, 0] 2 0) ∧ (start0 1 [1, 0] 2 0).time = 0 ∧ + Capped 3 2 (start0 1 [1, 0] 2 0) [.step, .step, .tick, .step, .step, .tick, .step, .step] ∧ + (wexec 2 (start0 1 [1, 0] 2 0) + [.step, .step, .tick, .step, .step, .tick, .step, .step]).time = 6 ∧ + (wexec 2 (start0 1 [1, 0] 2 0) + [.step, .step, .tick, .step, .step, .tick, .step, .step]).ran = 0 := by + refine ⟨⟨by decide, by decide⟩, rfl, ?_, by decide, by decide⟩ + simp only [capped_cons, capped_nil] + decide + +/-! ## The wide model contains `K0Share.lean` + +`widen` rewrites a behaviour of `K0Share.lean` as a behaviour of the wide model: +a `run` is a `step`, followed by a `tick` when the countdown ends; a wake that +the cap of `K0Share.step` drops is no event at all. -/ + +/-- One event of `K0Share.lean` as events of the wide model, at state `s`. -/ +def widen1 (N : Nat) (s : St) : Ev → List Event + | .run => if s.c ≤ 1 then [.step, .tick] else [.step] + | .yield => [.yield] + | .block => [.block] + | .wake t => if t ≠ 0 ∧ cnt s < N then [.wake t] else [] + +/-- A behaviour of `K0Share.lean` from state `s` as a behaviour of the wide +model. -/ +def widen (N P : Nat) (s : St) : List Ev → List Event + | [] => [] + | e :: es => widen1 N s e ++ widen N P (step N P s e) es + +theorem wexec_widen1 (N P : Nat) (s : St) (e : Ev) (h1 : 1 ≤ s.c) : + wexec P s (widen1 N s e) = step N P s e := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at h1 + cases e with + | run => + by_cases hc : c ≤ 1 + · have hc1 : c = 1 := by omega + subst hc1 + cases ex <;> cases q <;> simp [widen1, wexec, wstep, step, runStep, onTick] + · simp [widen1, wexec, wstep, step, runStep, hc, h1] + | yield => rfl + | block => rfl + | wake t => + by_cases hg : t ≠ 0 ∧ cnt ⟨cur, ex, q, c, age, time, ran⟩ < N + · simp [widen1, wexec, wstep, step, hg] + · simp [widen1, wexec, step, hg] + +/-- In `K0Share.lean` the countdown stays above 0 (for `P >= 1`). -/ +theorem base_c_pos (N P : Nat) (hP : 1 ≤ P) (s : St) (e : Ev) (h1 : 1 ≤ s.c) : + 1 ≤ (step N P s e).c := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at h1 + cases e with + | run => + by_cases hc : c ≤ 1 + · cases ex <;> cases q <;> simpa [step, runStep, onTick, hc] using hP + · simp [step, runStep, hc]; omega + | yield => + by_cases h0 : cur = 0 + · simpa [step, h0] using h1 + · cases q <;> simpa [step, h0] using h1 + | block => + by_cases h0 : cur = 0 + · simpa [step, h0] using h1 + · cases q <;> simpa [step, h0] using h1 + | wake t => + simp only [step] + split <;> exact h1 + +/-- In `K0Share.lean` no event takes the number of tasks above `N`. This is the +cap of `wake` at work; it needs no other part of `Wf`. -/ +theorem base_cnt_le (N P : Nat) (s : St) (e : Ev) (h : cnt s ≤ N) : cnt (step N P s e) ≤ N := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only [cnt] at h ⊢ + cases e with + | run => + by_cases hc : c ≤ 1 + · cases ex <;> cases q <;> simpa [step, runStep, onTick, hc] using h + · simpa [step, runStep, hc] using h + | yield => + by_cases h0 : cur = 0 + · simpa [step, h0] using h + · cases q <;> simpa [step, h0] using h + | block => + by_cases h0 : cur = 0 + · simpa [step, h0] using h + · cases q with + | nil => simpa [step, h0] using h + | cons x r => simp [step, h0] at h ⊢; omega + | wake t => + by_cases hg : t ≠ 0 ∧ cnt ⟨cur, ex, q, c, age, time, ran⟩ < N + · have hlt : q.length + 1 < N := hg.2 + simp [step, hg] + omega + · simpa [step, hg] using h + +theorem capped_widen1 (N P : Nat) (s : St) (e : Ev) (h1 : 1 ≤ s.c) (h0 : cnt s ≤ N) : + Capped N P s (widen1 N s e) := by + have hn : cnt (step N P s e) ≤ N := base_cnt_le N P s e h0 + have he := wexec_widen1 N P s e h1 + cases e with + | run => + by_cases hc : s.c ≤ 1 + · have hs : cnt (wstep P s .step) = cnt s := by + simp only [wstep]; split <;> rfl + have hl : widen1 N s .run = [.step, .tick] := ite_eq_left hc + rw [hl] at he ⊢ + simp only [capped_cons, capped_nil] + exact ⟨h0, by omega, by rw [← he] at hn; exact hn⟩ + · have hl : widen1 N s .run = [.step] := ite_eq_right hc + rw [hl] at he ⊢ + simp only [capped_cons, capped_nil] + exact ⟨h0, by rw [← he] at hn; exact hn⟩ + | yield => + simp only [widen1, capped_cons, capped_nil] + exact ⟨h0, by rw [← he] at hn; exact hn⟩ + | block => + simp only [widen1, capped_cons, capped_nil] + exact ⟨h0, by rw [← he] at hn; exact hn⟩ + | wake t => + by_cases hg : t ≠ 0 ∧ cnt s < N + · have hl : widen1 N s (.wake t) = [.wake t] := ite_eq_left hg + rw [hl] at he ⊢ + simp only [capped_cons, capped_nil] + exact ⟨h0, by rw [← he] at hn; exact hn⟩ + · have hl : widen1 N s (.wake t) = [] := ite_eq_right hg + rw [hl] + exact (capped_nil N P s).mpr h0 + +/-- Every behaviour of `K0Share.lean` from a state with a countdown above 0, +rewritten by `widen`, ends in the same state in the wide model. All seven +fields are equal, the counters `time`, `ran` and `age` included. -/ +theorem wexec_widen (N P : Nat) (hP : 1 ≤ P) : ∀ (es : List Ev) (s : St), 1 ≤ s.c → + wexec P s (widen N P s es) = exec N P s es := by + intro es + induction es with + | nil => intro s _; rfl + | cons e es ih => + intro s h1 + simp only [widen, exec, wexec_append, wexec_widen1 N P s e h1] + exact ih _ (base_c_pos N P hP s e h1) + +/-- The rewritten behaviour never holds more than `N` tasks ready or running, +when the start state does not. -/ +theorem capped_widen (N P : Nat) (hP : 1 ≤ P) : ∀ (es : List Ev) (s : St), 1 ≤ s.c → + cnt s ≤ N → Capped N P s (widen N P s es) := by + intro es + induction es with + | nil => intro s _ h0; exact (capped_nil N P s).mpr h0 + | cons e es ih => + intro s h1 h0 + simp only [widen, capped_append, wexec_widen1 N P s e h1] + exact ⟨capped_widen1 N P s e h1 h0, + ih _ (base_c_pos N P hP s e h1) (base_cnt_le N P s e h0)⟩ + +/-- A well-formed state of `K0Share.lean` meets the hypotheses of this file. -/ +theorem inv_of_wf {N P : Nat} {s : St} (hw : Wf N P s) : + Inv P s ∧ AgeOk P s ∧ cnt s ≤ N ∧ 1 ≤ s.c ∧ 1 ≤ P := + ⟨⟨hw.2.1, hw.2.2.1⟩, hw.2.2.2.2, hw.2.2.2.1, hw.1, Nat.le_trans hw.1 hw.2.1⟩ + +/-- Every behaviour of `K0Share.lean` from a well-formed state is a behaviour of +the wide model that keeps the cap, with the same final state. The converse is +false (`tick_after_yield_not_base`, `remove_not_block_wake`, `cap_needed`). -/ +theorem contains (N P : Nat) (s : St) (hw : Wf N P s) (es : List Ev) : + ∃ es' : List Event, wexec P s es' = exec N P s es ∧ Capped N P s es' := + ⟨widen N P s es, wexec_widen N P (inv_of_wf hw).2.2.2.2 es s hw.1, + capped_widen N P (inv_of_wf hw).2.2.2.2 es s hw.1 hw.2.2.2.1⟩ + +/-- The headline of `K0Share.lean`, obtained from `share_bound` of this file, so +the headline here is not the weaker one of the two. The hypotheses are those of +`K0Share.share_bound` without two that it does not need: `ran = 0` at the +start, and the `age` clause of `Wf`. -/ +theorem share_bound_base (N P : Nat) (s0 : St) (h1 : 1 ≤ s0.c) (h2 : s0.c ≤ P) + (h3 : (s0.cur :: s0.q).count 0 = 1) (h4 : (s0.cur :: s0.q).length ≤ N) + (ht : s0.time = 0) (es : List Ev) : + (exec N P s0 es).time ≤ N * (exec N P s0 es).ran + (N - 1) * P + s0.c := by + have hP : 1 ≤ P := Nat.le_trans h1 h2 + rw [← wexec_widen N P hP es s0 h1] + exact share_bound N P s0 ⟨h2, h3⟩ ht _ (capped_widen N P hP es s0 h1 h4) + +/-- The same for the difference form: `K0Share.share_bound_diff` from any state, +without the `age` clause of `Wf`. -/ +theorem share_bound_diff_base (N P : Nat) (s0 : St) (h1 : 1 ≤ s0.c) (h2 : s0.c ≤ P) + (h3 : (s0.cur :: s0.q).count 0 = 1) (h4 : (s0.cur :: s0.q).length ≤ N) (es : List Ev) : + (((exec N P s0 es).time : Int) - s0.time) ≤ + (N : Int) * (((exec N P s0 es).ran : Int) - s0.ran) + ((N - 1 : Nat) : Int) * P + s0.c := by + have hP : 1 ≤ P := Nat.le_trans h1 h2 + rw [← wexec_widen N P hP es s0 h1] + exact share_bound_diff N P s0 ⟨h2, h3⟩ _ (capped_widen N P hP es s0 h1 h4) + +/-! ## A task that got the CPU is not cut before `P` steps -/ + +theorem ageOk_wstep (P : Nat) (s : St) (e : Event) (h : AgeOk P s) : AgeOk P (wstep P s e) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only [AgeOk] at h ⊢ + cases e with + | step => + by_cases hc : 1 ≤ c + · intro hex + have := h (by simpa [wstep, hc] using hex) + simp [wstep, hc] + omega + · simpa [wstep, hc] using h + | tick => + by_cases hc0 : c = 0 + · cases ex <;> cases q <;> simp [wstep, onTick, hc0] + · simpa [wstep, hc0] using h + | yield => + by_cases hc : cur = 0 + · simpa [wstep, hc] using h + · cases q with + | nil => simpa [wstep, hc] using h + | cons x r => simp [wstep, hc] + | block => + by_cases hc : cur = 0 + · simpa [wstep, hc] using h + · cases q with + | nil => simpa [wstep, hc] using h + | cons x r => simp [wstep, hc] + | wake t => + by_cases ht : t = 0 + · simpa [wstep, ht] using h + · simpa [wstep, ht] using h + | remove i => + by_cases hr : q[i]? = some 0 + · simpa [wstep, hr] using h + · simpa [wstep, hr] using h + +theorem ageOk_wexec (P : Nat) : ∀ (es : List Event) (s : St), AgeOk P s → + AgeOk P (wexec P s es) := by + intro es + induction es with + | nil => intro s h; exact h + | cons e es ih => intro s h; exact ih _ (ageOk_wstep P s e h) + +/-- A tick takes the CPU from the running task only when it is due and the +running task has no mark: in every other case the running task, the queue and +`age` are as before. -/ +theorem tick_keeps (P : Nat) (s : St) (h : ¬ (s.c = 0 ∧ s.ex = false)) : + (wstep P s .tick).cur = s.cur ∧ (wstep P s .tick).q = s.q ∧ + (wstep P s .tick).age = s.age := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at h + by_cases hc0 : c = 0 + · cases ex with + | true => simp [wstep, onTick, hc0] + | false => exact absurd ⟨hc0, rfl⟩ h + · simp [wstep, hc0] + +/-- "No early cut" for the wide model. Along any behaviour from a state that +meets `AgeOk`: at an instant at which the tick is due (countdown 0) and the +running task has no mark, so that the tick takes the CPU from it if anybody +waits, that task has run at least `P` steps since it got the CPU. Needs neither +the cap nor the spinner. `age` is tied to "steps since the task got the CPU" by +`wstep_age`. A task that gets the CPU out of idle is not covered (no idle). -/ +theorem no_early_cut (P : Nat) (s0 : St) (ha : AgeOk P s0) (pre : List Event) + (hc : (wexec P s0 pre).c = 0) (hex : (wexec P s0 pre).ex = false) : + P ≤ (wexec P s0 pre).age := by + have := ageOk_wexec P pre s0 ha hex + omega + +/-! ## A ready task starts within `(k+1)*P` steps of time + +A ready task is a slot `i` of the queue (`i` tasks ahead of it; with the running +task, `k = i + 1` tasks run before it). `follow s i e` says what the event `e` +does to the task in slot `i`, and `fate` follows the task along a behaviour until +it starts or is removed. `follow_waits`, `follow_started`, `follow_removed`, +`fate_started` and `fate_removed` show that this really follows the same task. + +Time is the field `time`. A `tick`, a `step` while a tick is due, and every +other event take no time, so the number of events says nothing. -/ + +/-- What became of a ready task. `waits j`: it is still ready, now in slot `j`. +`started t`: it became the running task when `time` was `t`. `removed`: a +`remove` took it out of the queue. -/ +inductive Fate where + | waits (j : Nat) + | started (t : Nat) + | removed + deriving DecidableEq, Repr + +/-- The head of the queue gets the CPU at time `t`: slot 0 starts, the others +move up by one. -/ +def moveUp (t : Nat) : Nat → Fate + | 0 => .started t + | j + 1 => .waits j + +/-- What the event `e` does to the task in queue slot `i` of `s`. -/ +def follow (s : St) (i : Nat) : Event → Fate + | .step => .waits i + | .tick => if s.c = 0 ∧ s.ex = false ∧ s.q ≠ [] then moveUp s.time i else .waits i + | .yield => if s.cur ≠ 0 ∧ s.q ≠ [] then moveUp s.time i else .waits i + | .block => if s.cur ≠ 0 ∧ s.q ≠ [] then moveUp s.time i else .waits i + | .wake _ => .waits i + | .remove j => + if s.q[j]? = some 0 then .waits i + else if j < i then .waits (i - 1) + else if j = i then .removed + else .waits i + +/-- What a behaviour does to the task in queue slot `i` of `s`: the first event +that starts or removes it decides. -/ +def fate (P : Nat) : St → Nat → List Event → Fate + | _, i, [] => .waits i + | s, i, e :: es => + match follow s i e with + | .waits j => fate P (wstep P s e) j es + | .started t => .started t + | .removed => .removed + +/-- `waits j` is right: the same task is in slot `j` after the event. -/ +theorem follow_waits (P : Nat) (s : St) (i j : Nat) (e : Event) + (h : follow s i e = .waits j) (hi : i < s.q.length) : + j < (wstep P s e).q.length ∧ (wstep P s e).q[j]? = s.q[i]? := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hi + cases e with + | step => + simp only [follow, Fate.waits.injEq] at h + subst h + simp only [wstep] + split <;> exact ⟨hi, rfl⟩ + | tick => + simp only [follow] at h + split at h + · rename_i hcut + obtain ⟨hc0, hex, hq⟩ := hcut + subst hc0; subst hex + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [moveUp] at h + | succ i => + simp only [moveUp, Fate.waits.injEq] at h + subst h + simp [wstep, onTick] at hi ⊢ + refine ⟨by omega, ?_⟩ + rw [List.getElem?_append_left (by omega)] + · rename_i hn + simp only [Fate.waits.injEq] at h + subst h + have : (wstep P ⟨cur, ex, q, c, age, time, ran⟩ .tick).q = q := by + by_cases hc0 : c = 0 + · cases ex with + | true => simp [wstep, onTick, hc0] + | false => + cases q with + | nil => simp [wstep, onTick, hc0] + | cons x r => exact absurd ⟨hc0, rfl, by simp⟩ hn + · simp [wstep, hc0] + rw [this]; exact ⟨hi, rfl⟩ + | yield => + simp only [follow] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [moveUp] at h + | succ i => + simp only [moveUp, Fate.waits.injEq] at h + subst h + simp [wstep, hc] at hi ⊢ + refine ⟨by omega, ?_⟩ + rw [List.getElem?_append_left (by omega)] + · rename_i hn + simp only [Fate.waits.injEq] at h + subst h + have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .yield = ⟨cur, ex, q, c, age, time, ran⟩ := by + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q with + | nil => simp [wstep] + | cons x r => exact absurd ⟨hc, by simp⟩ hn + rw [this]; exact ⟨hi, rfl⟩ + | block => + simp only [follow] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [moveUp] at h + | succ i => + simp only [moveUp, Fate.waits.injEq] at h + subst h + simp [wstep, hc] at hi ⊢ + omega + · rename_i hn + simp only [Fate.waits.injEq] at h + subst h + have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .block = ⟨cur, ex, q, c, age, time, ran⟩ := by + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q with + | nil => simp [wstep] + | cons x r => exact absurd ⟨hc, by simp⟩ hn + rw [this]; exact ⟨hi, rfl⟩ + | wake t => + simp only [follow, Fate.waits.injEq] at h + subst h + by_cases ht : t = 0 + · simp only [wstep, ht] + exact ⟨hi, rfl⟩ + · simp [wstep, ht] + refine ⟨by omega, ?_⟩ + rw [List.getElem?_append_left hi] + | remove j' => + simp only [follow] at h + by_cases hr : q[j']? = some 0 + · simp only [hr, ite_true, Fate.waits.injEq] at h + subst h + have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ (.remove j') = ⟨cur, ex, q, c, age, time, ran⟩ := by + simp [wstep, hr] + rw [this]; exact ⟨hi, rfl⟩ + · simp only [hr, ite_false] at h + have hq' : (wstep P ⟨cur, ex, q, c, age, time, ran⟩ (.remove j')).q = q.eraseIdx j' := by + simp [wstep, hr] + rw [hq', List.length_eraseIdx, List.getElem?_eraseIdx] + by_cases hlt : j' < i + · simp only [hlt, ite_true, Fate.waits.injEq] at h + subst h + have h1 : j' < q.length := by omega + have h2 : ¬ (i - 1 < j') := by omega + have h3 : i - 1 + 1 = i := by omega + simp only [h1, h2, h3, ite_true, ite_false] + exact ⟨by omega, trivial⟩ + · simp only [hlt, ite_false] at h + by_cases heq : j' = i + · simp [heq] at h + · simp only [heq, ite_false, Fate.waits.injEq] at h + subst h + have h2 : i < j' := by omega + simp only [h2, ite_true] + refine ⟨?_, trivial⟩ + split <;> omega + +/-- `started t` is right: the task was at the head of the queue, it is the +running task after the event, the event took no time, and `t` is that time. -/ +theorem follow_started (P : Nat) (s : St) (i t : Nat) (e : Event) + (h : follow s i e = .started t) : + i = 0 ∧ t = s.time ∧ (wstep P s e).time = s.time ∧ + ∃ x r, s.q = x :: r ∧ (wstep P s e).cur = x := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | step => simp [follow] at h + | tick => + simp only [follow] at h + split at h + · rename_i hcut + obtain ⟨hc0, hex, hq⟩ := hcut + subst hc0; subst hex + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => + simp only [moveUp, Fate.started.injEq] at h + exact ⟨rfl, h.symm, by simp [wstep, onTick], x, r, rfl, by simp [wstep, onTick]⟩ + | succ i => simp [moveUp] at h + · simp at h + | yield => + simp only [follow] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => + simp only [moveUp, Fate.started.injEq] at h + exact ⟨rfl, h.symm, by simp [wstep, hc], x, r, rfl, by simp [wstep, hc]⟩ + | succ i => simp [moveUp] at h + · simp at h + | block => + simp only [follow] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => + simp only [moveUp, Fate.started.injEq] at h + exact ⟨rfl, h.symm, by simp [wstep, hc], x, r, rfl, by simp [wstep, hc]⟩ + | succ i => simp [moveUp] at h + · simp at h + | wake t' => simp [follow] at h + | remove j' => + simp only [follow] at h + split at h + · simp at h + · split at h + · simp at h + · split at h <;> simp at h + +/-- `removed` is right: the event is `remove` of that very slot, the task in it +is not the spinner, and the queue loses exactly that slot. -/ +theorem follow_removed (P : Nat) (s : St) (i : Nat) (e : Event) + (h : follow s i e = .removed) : + e = .remove i ∧ s.q[i]? ≠ some 0 ∧ (wstep P s e).q = s.q.eraseIdx i := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | step => simp [follow] at h + | tick => + simp only [follow] at h + split at h + · cases i <;> simp [moveUp] at h + · simp at h + | yield => + simp only [follow] at h + split at h + · cases i <;> simp [moveUp] at h + · simp at h + | block => + simp only [follow] at h + split at h + · cases i <;> simp [moveUp] at h + · simp at h + | wake t' => simp [follow] at h + | remove j' => + simp only [follow] at h + by_cases hr : q[j']? = some 0 + · simp [hr] at h + · simp only [hr, ite_false] at h + by_cases hlt : j' < i + · simp [hlt] at h + · simp only [hlt, ite_false] at h + by_cases heq : j' = i + · subst heq + exact ⟨rfl, hr, by simp [wstep, hr]⟩ + · simp [heq] at h + +/-- While the task waits, `time + wt` does not grow: every step of time takes +one off the bound `wt`, and no other event raises it. No invariant is needed. -/ +theorem wt_follow (P : Nat) (s : St) (i j : Nat) (e : Event) + (h : follow s i e = .waits j) (hi : i < s.q.length) : + (wstep P s e).time + wt P (wstep P s e) j ≤ s.time + wt P s i := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at hi + cases e with + | step => + simp only [follow, Fate.waits.injEq] at h + subst h + by_cases hc : 1 ≤ c + · cases ex <;> simp [wstep, hc, wt] <;> omega + · simp [wstep, hc] + | tick => + simp only [follow] at h + split at h + · rename_i hcut + obtain ⟨hc0, hex, hq⟩ := hcut + subst hc0; subst hex + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [moveUp] at h + | succ i => + simp only [moveUp, Fate.waits.injEq] at h + subst h + simp [wstep, onTick, wt, Nat.add_mul] + omega + · rename_i hn + simp only [Fate.waits.injEq] at h + subst h + by_cases hc0 : c = 0 + · cases ex with + | true => simp [wstep, onTick, hc0, wt] + | false => + cases q with + | nil => simp at hi + | cons x r => exact absurd ⟨hc0, rfl, by simp⟩ hn + · simp [wstep, hc0] + | yield => + simp only [follow] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [moveUp] at h + | succ i => + simp only [moveUp, Fate.waits.injEq] at h + subst h + cases ex <;> simp [wstep, hc, wt, Nat.add_mul] <;> omega + · rename_i hn + simp only [Fate.waits.injEq] at h + subst h + have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .yield = ⟨cur, ex, q, c, age, time, ran⟩ := by + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q with + | nil => simp [wstep] + | cons x r => exact absurd ⟨hc, by simp⟩ hn + rw [this]; exact Nat.le_refl _ + | block => + simp only [follow] at h + split at h + · rename_i hcond + obtain ⟨hc, hq⟩ := hcond + cases q with + | nil => exact absurd rfl hq + | cons x r => + cases i with + | zero => simp [moveUp] at h + | succ i => + simp only [moveUp, Fate.waits.injEq] at h + subst h + cases ex <;> simp [wstep, hc, wt, Nat.add_mul] <;> omega + · rename_i hn + simp only [Fate.waits.injEq] at h + subst h + have : wstep P ⟨cur, ex, q, c, age, time, ran⟩ .block = ⟨cur, ex, q, c, age, time, ran⟩ := by + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q with + | nil => simp [wstep] + | cons x r => exact absurd ⟨hc, by simp⟩ hn + rw [this]; exact Nat.le_refl _ + | wake t => + simp only [follow, Fate.waits.injEq] at h + subst h + by_cases ht : t = 0 + · simp [wstep, ht] + · simp [wstep, ht, wt] + | remove j' => + have hji : j ≤ i := by + simp only [follow] at h + split at h + · simp only [Fate.waits.injEq] at h; omega + · split at h + · simp only [Fate.waits.injEq] at h; omega + · split at h + · simp at h + · simp only [Fate.waits.injEq] at h; omega + have hm := Nat.mul_le_mul_right P hji + by_cases hr : q[j']? = some 0 + · simp [wstep, hr, wt]; omega + · simp [wstep, hr, wt]; omega + +/-- Along a behaviour, for a task that still waits at the end: it is the same +task, and `time + wt` is not above its start value. -/ +theorem fate_waits (P : Nat) : ∀ (es : List Event) (s : St) (i j : Nat), i < s.q.length → + fate P s i es = .waits j → + j < (wexec P s es).q.length ∧ (wexec P s es).q[j]? = s.q[i]? ∧ + (wexec P s es).time + wt P (wexec P s es) j ≤ s.time + wt P s i := by + intro es + induction es with + | nil => + intro s i j hi h + simp only [fate, Fate.waits.injEq] at h + subst h + exact ⟨hi, rfl, Nat.le_refl _⟩ + | cons e es ih => + intro s i j hi h + simp only [fate] at h + cases hf : follow s i e with + | waits j1 => + rw [hf] at h + simp only at h + obtain ⟨hj1, hq1⟩ := follow_waits P s i j1 e hf hi + have hw1 := wt_follow P s i j1 e hf hi + obtain ⟨a, b, c⟩ := ih _ j1 j hj1 h + exact ⟨a, by rw [← hq1]; exact b, by simp only [wexec]; omega⟩ + | started t => rw [hf] at h; simp at h + | removed => rw [hf] at h; simp at h + +/-- `fate = started t` means what it says: the behaviour splits as +`pre ++ e :: post` such that the task is at the head of the queue after `pre`, +is the running task after `e`, and `time` is `t` then. That instant is no later +than `wt` steps of time after the start. -/ +theorem fate_started (P : Nat) : ∀ (es : List Event) (s : St) (i t : Nat), i < s.q.length → + fate P s i es = .started t → + t ≤ s.time + wt P s i ∧ + ∃ pre e post, es = pre ++ e :: post ∧ (wexec P s pre).q.head? = s.q[i]? ∧ + some (wexec P s (pre ++ [e])).cur = s.q[i]? ∧ (wexec P s (pre ++ [e])).time = t := by + intro es + induction es with + | nil => intro s i t _ h; simp [fate] at h + | cons e es ih => + intro s i t hi h + simp only [fate] at h + cases hf : follow s i e with + | waits j1 => + rw [hf] at h + simp only at h + obtain ⟨hj1, hq1⟩ := follow_waits P s i j1 e hf hi + have hw1 := wt_follow P s i j1 e hf hi + obtain ⟨hb, pre, e', post, hes, h1, h2, h3⟩ := ih _ j1 t hj1 h + refine ⟨by omega, e :: pre, e', post, by rw [hes]; rfl, ?_, ?_, h3⟩ + · rw [← hq1]; exact h1 + · rw [← hq1]; exact h2 + | started t' => + rw [hf] at h + simp only [Fate.started.injEq] at h + subst h + obtain ⟨hi0, ht, htime, x, r, hq, hcur⟩ := follow_started P s i t' e hf + subst hi0 + refine ⟨by omega, [], e, es, rfl, ?_, ?_, ?_⟩ + · simp [wexec, hq] + · simp [wexec, hq, hcur] + · simp only [List.nil_append, wexec]; omega + | removed => rw [hf] at h; simp at h + +/-- `fate = removed` means what it says: a `remove` event hit the slot in which +the task was, and the task is not the spinner. -/ +theorem fate_removed (P : Nat) : ∀ (es : List Event) (s : St) (i : Nat), i < s.q.length → + fate P s i es = .removed → + s.q[i]? ≠ some 0 ∧ + ∃ pre j post, es = pre ++ Event.remove j :: post ∧ (wexec P s pre).q[j]? = s.q[i]? ∧ + (wexec P s (pre ++ [Event.remove j])).q = (wexec P s pre).q.eraseIdx j := by + intro es + induction es with + | nil => intro s i _ h; simp [fate] at h + | cons e es ih => + intro s i hi h + simp only [fate] at h + cases hf : follow s i e with + | waits j1 => + rw [hf] at h + simp only at h + obtain ⟨hj1, hq1⟩ := follow_waits P s i j1 e hf hi + obtain ⟨hne, pre, j, post, hes, h1, h2⟩ := ih _ j1 hj1 h + refine ⟨by rw [← hq1]; exact hne, e :: pre, j, post, by rw [hes]; rfl, ?_, h2⟩ + rw [← hq1]; exact h1 + | started t' => rw [hf] at h; simp at h + | removed => + obtain ⟨he, hne, hq⟩ := follow_removed P s i e hf + subst he + exact ⟨hne, [], i, es, rfl, rfl, hq⟩ + +theorem fate_append (P : Nat) : ∀ (a b : List Event) (s : St) (i : Nat), + fate P s i (a ++ b) = + match fate P s i a with + | .waits j => fate P (wexec P s a) j b + | .started t => .started t + | .removed => .removed := by + intro a + induction a with + | nil => intro b s i; rfl + | cons e a ih => + intro b s i + simp only [List.cons_append, fate, wexec] + cases follow s i e with + | waits j1 => exact ih b _ j1 + | started t => rfl + | removed => rfl + +/-- The bound `wt` at the start is at most `(k+1)*P`. -/ +theorem wt_start (P : Nat) (s : St) (hc : s.c ≤ P) (k : Nat) (hk : 1 ≤ k) : + wt P s (k - 1) ≤ (k + 1) * P := by + obtain ⟨m, rfl⟩ : ∃ m, k = m + 1 := ⟨k - 1, by omega⟩ + simp only [wt, Nat.add_sub_cancel, Nat.add_mul, Nat.one_mul] + cases s.ex <;> simp <;> omega + +/-- LEMMA 3 for the wide model. A ready task with `k` tasks to run before it +(the running one included), that is in queue slot `k - 1`, in a state whose +countdown is at most `P`. Along any behaviour: + +* if the task became the running task, it did so at an instant no later than + `(k+1)*P` steps of time after the start; +* as long as it waits, no more than `(k+1)*P` steps of time have passed. + +Nothing is said about a task that was removed. The cap, the spinner and `age` +play no part. This is not "after `(k+1)*P` steps it has started": at exactly +`(k+1)*P` steps the last tick may still be due (`wait_at_bound`); see +`wait_bound_passed` and `wait_bound_tick`. -/ +theorem wait_bound (P : Nat) (s : St) (hc : s.c ≤ P) (k : Nat) (hk : 1 ≤ k) + (hq : k - 1 < s.q.length) (es : List Event) : + (∀ t, fate P s (k - 1) es = .started t → t ≤ s.time + (k + 1) * P) ∧ + (∀ j, fate P s (k - 1) es = .waits j → (wexec P s es).time ≤ s.time + (k + 1) * P) := by + have hwt := wt_start P s hc k hk + constructor + · intro t h + have := (fate_started P es s (k - 1) t hq h).1 + omega + · intro j h + have := (fate_waits P es s (k - 1) j hq h).2.2 + omega + +/-- Once more than `(k+1)*P` steps of time have passed, a task that was not +removed has become the running task, and it did so no later than `(k+1)*P` +steps after the start. -/ +theorem wait_bound_passed (P : Nat) (s : St) (hc : s.c ≤ P) (k : Nat) (hk : 1 ≤ k) + (hq : k - 1 < s.q.length) (es : List Event) + (hes : s.time + (k + 1) * P < (wexec P s es).time) + (hrm : fate P s (k - 1) es ≠ .removed) : + ∃ t, fate P s (k - 1) es = .started t ∧ t ≤ s.time + (k + 1) * P := by + obtain ⟨h1, h2⟩ := wait_bound P s hc k hk hq es + cases hf : fate P s (k - 1) es with + | waits j => have := h2 j hf; omega + | started t => exact ⟨t, rfl, h1 t hf⟩ + | removed => exact absurd hf hrm + +/-- When exactly `(k+1)*P` steps of time (or more) have passed and the task +still waits, then the tick is due, and that tick starts the task. No step can +pass before it. -/ +theorem wait_bound_tick (P : Nat) (hP : 1 ≤ P) (s : St) (hc : s.c ≤ P) (k : Nat) (hk : 1 ≤ k) + (hq : k - 1 < s.q.length) (es : List Event) (j : Nat) + (hes : s.time + (k + 1) * P ≤ (wexec P s es).time) + (hf : fate P s (k - 1) es = .waits j) : + (wexec P s es).c = 0 ∧ + fate P s (k - 1) (es ++ [.tick]) = .started (wexec P s es).time := by + have hwt := wt_start P s hc k hk + obtain ⟨hj, _, hb⟩ := fate_waits P es s (k - 1) j hq hf + have h0 : wt P (wexec P s es) j = 0 := by omega + simp only [wt] at h0 + have hc0 : (wexec P s es).c = 0 := by omega + have hex : (wexec P s es).ex = false := by + cases hx : (wexec P s es).ex with + | false => rfl + | true => rw [hx] at h0; simp at h0; omega + have hj0 : j = 0 := by + cases j with + | zero => rfl + | succ j => + have : 1 * P ≤ (j + 1) * P := Nat.mul_le_mul_right P (by omega) + omega + subst hj0 + refine ⟨hc0, ?_⟩ + have hne : (wexec P s es).q ≠ [] := by + intro h; rw [h] at hj; simp at hj + rw [fate_append, hf] + simp [fate, follow, moveUp, hc0, hex, hne] + +/-- The form of `K0Share.wait_bound` is false in the wide model. `P = 1`, +`k = 1`: after `(k+1)*P = 2` steps of time the task in slot 0 still waits, +because the second tick is due and has not been delivered. That tick starts it, +at time 2. -/ +theorem wait_at_bound : + let s : St := { cur := 1, ex := true, q := [7, 0], c := 1, age := 0, time := 0, ran := 0 } + (wexec 1 s [.step, .tick, .step]).time = 2 ∧ + fate 1 s 0 [.step, .tick, .step] = .waits 0 ∧ + fate 1 s 0 [.step, .tick, .step, .tick] = .started 2 := by + decide + +/-- The three fates on one state (`P = 1`, the queue is `[7, 8, 0]`). The task in +slot 1 moves up when the task ahead of it is removed and starts at the second +tick, at time 2. The task in slot 0 is removed. The spinner, in slot 2, is not +removed by a `remove` of its slot. -/ +theorem fate_instance : + let s : St := { cur := 1, ex := true, q := [7, 8, 0], c := 1, age := 0, time := 0, ran := 0 } + fate 1 s 1 [.remove 0, .step, .tick, .step, .tick] = .started 2 ∧ + fate 1 s 0 [.remove 0, .step, .tick, .step, .tick] = .removed ∧ + fate 1 s 2 [.remove 2] = .waits 2 := by + decide + +/-! ## What the counters count + +`time`, `ran` and `age` are fields that the rules write and never read. These +statements tie them to the events from outside the definition of `wstep`. -/ + +/-- `time` grows by one on a `step` that is taken (countdown above 0) and on +nothing else. -/ +theorem wstep_time (P : Nat) (s : St) (e : Event) : + (wstep P s e).time = s.time + (if e = .step ∧ 1 ≤ s.c then 1 else 0) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | step => by_cases hc : 1 ≤ c <;> simp [wstep, hc] + | tick => + by_cases hc0 : c = 0 + · cases ex <;> cases q <;> simp [wstep, onTick, hc0] + · simp [wstep, hc0] + | yield => + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q <;> simp [wstep, hc] + | block => + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q <;> simp [wstep, hc] + | wake t => by_cases ht : t = 0 <;> simp [wstep, ht] + | remove i => by_cases hr : q[i]? = some 0 <;> simp [wstep, hr] + +/-- `ran` grows by one on a `step` that is taken while the spinner is the +running task, and on nothing else. -/ +theorem wstep_ran (P : Nat) (s : St) (e : Event) : + (wstep P s e).ran = s.ran + (if e = .step ∧ 1 ≤ s.c ∧ s.cur = 0 then 1 else 0) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | step => by_cases hc : 1 ≤ c <;> by_cases h0 : cur = 0 <;> simp [wstep, hc, h0] + | tick => + by_cases hc0 : c = 0 + · cases ex <;> cases q <;> simp [wstep, onTick, hc0] + · simp [wstep, hc0] + | yield => + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q <;> simp [wstep, hc] + | block => + by_cases hc : cur = 0 + · simp [wstep, hc] + · cases q <;> simp [wstep, hc] + | wake t => by_cases ht : t = 0 <;> simp [wstep, ht] + | remove i => by_cases hr : q[i]? = some 0 <;> simp [wstep, hr] + +/-- `age` is 0 right after the head of the queue got the CPU (by a yield, a +block or a cut; `follow_started` says what that means), it grows by one on a +`step` that is taken, and no other event changes it. -/ +theorem wstep_age (P : Nat) (s : St) (e : Event) : + (wstep P s e).age = + if follow s 0 e = .started s.time then 0 + else s.age + (if e = .step ∧ 1 ≤ s.c then 1 else 0) := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + cases e with + | step => by_cases hc : 1 ≤ c <;> simp [wstep, follow, hc] + | tick => + by_cases hc0 : c = 0 + · cases ex <;> cases q <;> simp [wstep, onTick, follow, moveUp, hc0] + · simp [wstep, follow, hc0] + | yield => + by_cases hc : cur = 0 + · simp [wstep, follow, hc] + · cases q <;> simp [wstep, follow, moveUp, hc] + | block => + by_cases hc : cur = 0 + · simp [wstep, follow, hc] + · cases q <;> simp [wstep, follow, moveUp, hc] + | wake t => by_cases ht : t = 0 <;> simp [wstep, follow, ht] + | remove i => + have hf : follow ⟨cur, ex, q, c, age, time, ran⟩ 0 (.remove i) ≠ .started time := by + simp only [follow] + split + · simp + · split + · simp + · split <;> simp + by_cases hr : q[i]? = some 0 <;> simp [wstep, hr, hf] + +/-- Along any behaviour `time` and `ran` do not fall, and `ran` grows by no +more than `time`: the spinner is not credited more steps than pass. -/ +theorem wexec_ran_le_time (P : Nat) : ∀ (es : List Event) (s : St), + s.time ≤ (wexec P s es).time ∧ s.ran ≤ (wexec P s es).ran ∧ + (wexec P s es).ran + s.time ≤ (wexec P s es).time + s.ran := by + intro es + induction es with + | nil => intro s; exact ⟨Nat.le_refl _, Nat.le_refl _, by simp only [wexec]; omega⟩ + | cons e es ih => + intro s + obtain ⟨h1, h2, h3⟩ := ih (wstep P s e) + have ht := wstep_time P s e + have hr := wstep_ran P s e + simp only [wexec] + by_cases ha : e = .step ∧ 1 ≤ s.c + · rw [ite_eq_left ha] at ht + by_cases hb : e = .step ∧ 1 ≤ s.c ∧ s.cur = 0 + · rw [ite_eq_left hb] at hr + omega + · rw [ite_eq_right hb] at hr + omega + · have hb : ¬ (e = .step ∧ 1 ≤ s.c ∧ s.cur = 0) := fun h => ha ⟨h.1, h.2.1⟩ + rw [ite_eq_right ha] at ht + rw [ite_eq_right hb] at hr + omega + +/-! ## Witnesses: the wide model is strictly wider, and the cap is needed -/ + +/-- In `K0Share.lean` the mark is taken only by a `run`, and that `run` first +gives the marked task one step: no task loses the mark before it has run. -/ +theorem base_mark_needs_step (N P : Nat) (s : St) (e : Ev) (h : s.ex = true) + (h' : (step N P s e).ex = false) : + (step N P s e).cur = s.cur ∧ (step N P s e).age = s.age + 1 ∧ + (step N P s e).time = s.time + 1 := by + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + simp only at h + subst h + cases e with + | run => + by_cases hc : c ≤ 1 + · simp [step, runStep, onTick, hc] + · simp [step, runStep, hc] at h' + | yield => + by_cases h0 : cur = 0 + · simp [step, h0] at h' + · cases q <;> simp [step, h0] at h' + | block => + by_cases h0 : cur = 0 + · simp [step, h0] at h' + · cases q <;> simp [step, h0] at h' + | wake t => + simp only [step] at h' + split at h' <;> simp at h' + +/-- An order that `K0Share.lean` cannot express. The running task (with the +mark) yields to the spinner after the last step of the period and before its +tick: the spinner enters with the mark (`age = 0`, countdown 0) and the tick +takes the mark at once, before the spinner has run (`age` still 0, `ran = 0`). +By `base_mark_needs_step` no event of `K0Share.lean` does this, and +`tick_after_yield_not_base` shows that no behaviour of it does. -/ +theorem tick_after_yield : + let s0 : St := { cur := 1, ex := true, q := [0], c := 1, age := 0, time := 0, ran := 0 } + let s1 := wexec 3 s0 [.step, .yield] + let s2 := wexec 3 s0 [.step, .yield, .tick] + (s1.cur = 0 ∧ s1.ex = true ∧ s1.age = 0 ∧ s1.c = 0) ∧ + (s2.cur = 0 ∧ s2.ex = false ∧ s2.age = 0 ∧ s2.c = 3 ∧ s2.q = [1] ∧ s2.time = 1 ∧ + s2.ran = 0) := by + decide + +/-- The state that `tick_after_yield` reaches is out of reach of `K0Share.lean`: +from the same start state, for every `N` and `P`, no behaviour of it comes to +an instant at which one step has passed, the spinner has not run, and the +spinner is the running task without the mark. -/ +theorem tick_after_yield_not_base (N P : Nat) (es : List Ev) : + let s0 : St := { cur := 1, ex := true, q := [0], c := 1, age := 0, time := 0, ran := 0 } + ¬ ((exec N P s0 es).time = 1 ∧ (exec N P s0 es).ran = 0 ∧ (exec N P s0 es).cur = 0 ∧ + (exec N P s0 es).ex = false) := by + intro s0 + have key : ∀ (es : List Ev) (s : St), + ((s.time = 0 → s.ex = true ∧ s.c = 1 ∧ s.ran = 0) ∧ + (s.time = 1 → s.ran = 0 → s.cur = 0 → s.ex = true)) → + ((exec N P s es).time = 1 → (exec N P s es).ran = 0 → (exec N P s es).cur = 0 → + (exec N P s es).ex = true) := by + intro es + induction es with + | nil => intro s hJ; exact hJ.2 + | cons e es ih => + intro s hJ + apply ih + obtain ⟨cur, ex, q, c, age, time, ran⟩ := s + obtain ⟨h1, h2⟩ := hJ + simp only at h1 h2 + cases e with + | run => + by_cases ht : time = 0 + · obtain ⟨hex, hc, hr⟩ := h1 ht + subst ht; subst hex; subst hc; subst hr + by_cases h0 : cur = 0 <;> simp [step, runStep, onTick, h0] + · have hrun : (step N P ⟨cur, ex, q, c, age, time, ran⟩ .run).time = time + 1 := by + by_cases hc : c ≤ 1 + · cases ex <;> cases q <;> simp [step, runStep, onTick, hc] + · simp [step, runStep, hc] + refine ⟨fun h => ?_, fun h => ?_⟩ <;> (rw [hrun] at h; omega) + | yield => + by_cases h0 : cur = 0 + · have : step N P ⟨cur, ex, q, c, age, time, ran⟩ .yield = + ⟨cur, ex, q, c, age, time, ran⟩ := by simp [step, h0] + rw [this]; exact ⟨h1, h2⟩ + · cases q with + | nil => + have : step N P ⟨cur, ex, [], c, age, time, ran⟩ .yield = + ⟨cur, ex, [], c, age, time, ran⟩ := by simp [step] + rw [this]; exact ⟨h1, h2⟩ + | cons x r => + have : step N P ⟨cur, ex, x :: r, c, age, time, ran⟩ .yield = + ⟨x, true, r ++ [cur], c, 0, time, ran⟩ := by simp [step, h0] + rw [this] + exact ⟨fun h => ⟨rfl, (h1 h).2⟩, fun _ _ _ => rfl⟩ + | block => + by_cases h0 : cur = 0 + · have : step N P ⟨cur, ex, q, c, age, time, ran⟩ .block = + ⟨cur, ex, q, c, age, time, ran⟩ := by simp [step, h0] + rw [this]; exact ⟨h1, h2⟩ + · cases q with + | nil => + have : step N P ⟨cur, ex, [], c, age, time, ran⟩ .block = + ⟨cur, ex, [], c, age, time, ran⟩ := by simp [step] + rw [this]; exact ⟨h1, h2⟩ + | cons x r => + have : step N P ⟨cur, ex, x :: r, c, age, time, ran⟩ .block = + ⟨x, true, r, c, 0, time, ran⟩ := by simp [step, h0] + rw [this] + exact ⟨fun h => ⟨rfl, (h1 h).2⟩, fun _ _ _ => rfl⟩ + | wake t => + simp only [step] + split + · exact ⟨h1, h2⟩ + · exact ⟨h1, h2⟩ + intro ⟨a, b, c, d⟩ + have := key es s0 ⟨fun _ => ⟨rfl, rfl, rfl⟩, fun h => absurd h (by decide)⟩ a b c + rw [d] at this + cases this + +/-- `remove` is not a mix of the other events. The spinner runs and two tasks +are ready. No list of events without `remove` reaches, in zero time, the queue +that `remove 0` leaves: `yield` and `block` do nothing for the spinner, `wake` +only appends, and a `step` takes time. (With time it can be reached: the task +at the head gets the CPU at a tick and blocks.) -/ +theorem remove_not_block_wake (P : Nat) (es : List Event) (hno : ∀ i, Event.remove i ∉ es) : + let s : St := { cur := 0, ex := false, q := [1, 2], c := 2, age := 2, time := 0, ran := 0 } + (wexec P s es).time = 0 → (wexec P s es).q ≠ (wstep P s (.remove 0)).q := by + intro s + have key : ∀ (es : List Event) (t : St), (∀ i, Event.remove i ∉ es) → t.cur = 0 → + 2 ≤ t.q.length → t.time = 0 → t.c = 2 → + (wexec P t es).time = 0 → 2 ≤ (wexec P t es).q.length := by + intro es + induction es with + | nil => intro t _ _ hl _ _ _; exact hl + | cons e es ih => + intro t hno hc hl ht hcc h + have hno' : ∀ i, Event.remove i ∉ es := fun i hm => hno i (List.mem_cons_of_mem _ hm) + simp only [wexec] at h ⊢ + cases e with + | step => + have h1 := wstep_time P t .step + have h2 := (wexec_ran_le_time P es (wstep P t .step)).1 + simp [hcc] at h1 + omega + | tick => + have : wstep P t .tick = t := by simp [wstep, hcc] + rw [this] at h ⊢ + exact ih t hno' hc hl ht hcc h + | yield => + have : wstep P t .yield = t := by simp [wstep, hc] + rw [this] at h ⊢ + exact ih t hno' hc hl ht hcc h + | block => + have : wstep P t .block = t := by simp [wstep, hc] + rw [this] at h ⊢ + exact ih t hno' hc hl ht hcc h + | wake w => + by_cases hw : w = 0 + · have : wstep P t (.wake w) = t := by simp [wstep, hw] + rw [this] at h ⊢ + exact ih t hno' hc hl ht hcc h + · refine ih _ hno' ?_ ?_ ?_ ?_ h + · simpa [wstep, hw] using hc + · simp [wstep, hw]; omega + · simpa [wstep, hw] using ht + · simpa [wstep, hw] using hcc + | remove i => exact absurd (List.mem_cons_self) (hno i) + intro h heq + have := key es s hno rfl (by simp [s]) rfl rfl h + rw [heq] at this + simp [wstep, s] at this + +/-- The hypothesis `Capped` of `share_bound` is needed. `N = 1`: the spinner is +alone, then a second task is woken. The run is not `Capped 1`, plain round robin +gives the spinner every other period, and the `N = 1` bound `time <= ran + c0` +fails after 10 steps (the spinner ran 6). -/ +theorem cap_needed : + let s0 : St := start0 0 [] 2 0 + let es : List Event := [.wake 1, .step, .step, .tick, .step, .step, .tick, .step, .step, + .tick, .step, .step, .tick, .step, .step, .tick] + Inv 2 s0 ∧ s0.time = 0 ∧ ¬ Capped 1 2 s0 es ∧ + ¬ ((wexec 2 s0 es).time ≤ 1 * (wexec 2 s0 es).ran + (1 - 1) * 2 + s0.c) := by + refine ⟨⟨by decide, by decide⟩, rfl, ?_, by decide⟩ + intro h + exact absurd (h 1) (by decide) + +#print axioms share_bound_diff +#print axioms share_bound +#print axioms share_bound_always +#print axioms share_bound_reached +#print axioms wexec_widen +#print axioms capped_widen +#print axioms contains +#print axioms share_bound_base +#print axioms share_bound_diff_base +#print axioms no_early_cut +#print axioms tick_keeps +#print axioms wait_bound +#print axioms wait_bound_passed +#print axioms wait_bound_tick +#print axioms fate_started +#print axioms fate_removed +#print axioms wait_at_bound +#print axioms fate_instance +#print axioms wstep_time +#print axioms wstep_ran +#print axioms wstep_age +#print axioms wexec_ran_le_time +#print axioms base_mark_needs_step +#print axioms tick_after_yield +#print axioms tick_after_yield_not_base +#print axioms remove_not_block_wake +#print axioms cap_needed + +end K0Share.Wide diff --git a/proofs/lean/ModelVectors.lean b/proofs/lean/ModelVectors.lean new file mode 100644 index 0000000..2e6bc40 --- /dev/null +++ b/proofs/lean/ModelVectors.lean @@ -0,0 +1,321 @@ +/- +ModelVectors.lean: the recorded results of the model `K0Part.step`. + +WHAT THIS FILE IS + The executable `vectors`. It reads a file of event scripts + (`crates/k0-part/src/model_vectors.txt`), runs every script through + `K0Part.step` from `K0Part.boot`, and writes one canonical line for the boot + state and one after every event. The hash of those lines is the recorded + result of the script. The Rust host test `crates/k0-part/src/model_tests.rs` + runs the same scripts through the real `Core` and compares the hashes, + so CI, which has no Lean, fails when the Rust code and the recorded results + differ. + + This is testing, not proof. A passing test says that `Core` and `step` gave + the same lines on the recorded scripts, with a list in place of the kernel's + queues. It says nothing about other inputs. Nothing here is used by a + theorem, and no theorem is proved here. + +USE (in `proofs/lean`) + lake exe vectors FILE print FILE again with freshly computed hashes + lake exe vectors --check FILE report every script whose stored hash is not + the model's; exit status 1 if there is one + lake exe vectors --trace FILE print the canonical lines of every script + Exit status 2: the file cannot be read, a line is not a script this file + accepts, or (with --check) a hash is missing or there is no script at all. + +FILE + A line that is empty or starts with `#` is kept as it is. Every other line + is one script, fields separated by `;`: + id ; boot tick ; domain of task 0, 1, ... ; first task ; ready tasks in + order ; waiting tasks in order as tid@deadline or tid@- ; events ; hash + Events: `tN` tick with index N, `pN` poll with index N, `y` yield, `b-` and + `bN` block without a deadline and with deadline N, `wT` wake of task T, + `xT` wakeX of task T, `sD:W,D:W,...` set_table. The hash may be left out + when the file is printed again. + + `Script.check` refuses what does not mean the same on both sides. It + accepts: task domains below 8, the first task in domain 0, known task ids, + tables as the Rust constructors accept them (1 to 16 entries, domain below + 8, window 1 to 255), tick indexes and deadlines below 2^32, no deadline 0 + (the kernel keeps 0 for "no deadline"). One accepted input is treated + differently by the two sides, a block while nothing runs (below). + +THE TWO SIDES + Here a script is `boot` followed by `step` for every event (`Script.lines`). + The Rust test starts `Core` with `Core::start` at the boot tick, with the + ready tasks in the queues and the waiting tasks in the waiting lists of + their domains. `tN` and `pN` set `Env::now` to N and call `Core::tick` and + `Core::poll`. `y` calls `yield_now`. `b` puts the running task, if there + is one, at the end of its domain's waiting list and calls `block`. `w` and + `x` move a waiting task to the back of its queue under the condition `step` + has (a task runs; own domain for `w`, another domain for `x`); they are not + calls of `Core`. `s` calls `set_table`. + While nothing runs, `y` and `b` still call `yield_now` and `block` in the + test and `step` does nothing. For `y` that is the same thing. For `b` it + is not: `Core::block` pops the queue of the running domain. The two agree + because that queue is empty whenever nothing runs (`blockIdleRust_eq`, under + `Inv`). The kernel raises neither; the recorded scripts hold them because + nothing else reaches the early return of `Core::yield_now`. + +CANONICAL LINE (`showSt`; `model_tests.rs` builds the same text from `Core`) + seen=N tbl=D:W,... ep=N pend=START/D:W,... rd=D cur=T q=[..|..] wl=[..|..] nx=B + `pend=-` without a pending table. `cur=T*` when the running task has the + exemption, `cur=-` when nothing runs. `q` and `wl` list domains 0 to 7 + separated by `|`, tasks separated by a blank, a waiter as tid@deadline or + tid@-. `nx` is 1 when `nextSwitches` holds and 0 otherwise. + +HASH (`hashLines`; the same in `model_tests.rs`) + FNV-1a, 64 bit, over the bytes of the lines of a script in order, every line + followed by one newline byte: start with 14695981039346656037 + (0xcbf29ce484222325); for every byte, xor the byte into the hash, then + multiply by 1099511628211 (0x100000001b3) modulo 2^64. Written as 16 hex + digits. It only keeps the file small. It is not a security measure. +-/ +import K0Part +open K0Part + +namespace ModelVectors + +/-! ## The canonical line and the hash -/ + +/-- Number of domains printed in a line (`MAX_DOMAINS` in Rust). -/ +def ndom : Nat := 8 + +def showTable (t : Table) : String := + ",".intercalate (t.map fun e => s!"{e.1}:{e.2}") + +def showWait (w : Tid × Option Nat) : String := + match w.2 with + | some k => s!"{w.1}@{k}" + | none => s!"{w.1}@-" + +/-- One list per domain, domains separated by `|`. -/ +def showDoms (f : Dom → List String) : String := + "|".intercalate ((List.range ndom).map fun d => " ".intercalate (f d)) + +instance (s : St) : Decidable (nextSwitches s) := by + unfold nextSwitches + exact inferInstance + +/-- The canonical line of a state. -/ +def showSt (s : St) : String := + let p := s.part + let pend := match p.pend with + | some (start, t) => s!"{start}/{showTable t}" + | none => "-" + let cur := match s.cur with + | some (t, true) => s!"{t}*" + | some (t, false) => s!"{t}" + | none => "-" + let q := showDoms fun d => (s.q d).map toString + let wl := showDoms fun d => (s.wl d).map showWait + let nx := if nextSwitches s then "1" else "0" + s!"seen={p.seen} tbl={showTable p.tbl} ep={p.epoch} pend={pend} rd={s.rd} cur={cur} q=[{q}] wl=[{wl}] nx={nx}" + +/-- One round of FNV-1a over the bytes of `s`. -/ +def fnv (h : UInt64) (s : String) : UInt64 := + s.toUTF8.foldl (fun h b => (h ^^^ b.toUInt64) * 1099511628211) h + +/-- The hash of the lines of a script. -/ +def hashLines (ls : List String) : UInt64 := + ls.foldl (fun h l => fnv h (l ++ "\n")) 14695981039346656037 + +def hex (h : UInt64) : String := + let d := Nat.toDigits 16 h.toNat + String.ofList (List.replicate (16 - d.length) '0' ++ d) + +-- The published FNV-1a values of the empty input, "a" and "foobar". +#guard hex (fnv 14695981039346656037 "") == "cbf29ce484222325" +#guard hex (fnv 14695981039346656037 "a") == "af63dc4c8601ec8c" +#guard hex (fnv 14695981039346656037 "foobar") == "85944171f73967e8" + +/-! ## Scripts -/ + +/-- A script. An event is kept with its text for `--trace`. -/ +structure Script where + now : Nat + dom : Array Dom + first : Tid + ready : List Tid + waits : List (Tid × Option Nat) + evs : List (String × Ev) + +def words (s : String) : List String := + (s.splitOn " ").filter (· != "") + +def parseNat (s : String) : Except String Nat := + match s.toNat? with + | some n => pure n + | none => throw s!"bad number '{s}'" + +def parseEntry (s : String) : Except String (Dom × Nat) := + match s.splitOn ":" with + | [d, w] => do pure (← parseNat d, ← parseNat w) + | _ => throw s!"bad table entry '{s}'" + +def parseWait (s : String) : Except String (Tid × Option Nat) := + match s.splitOn "@" with + | [t, "-"] => do pure (← parseNat t, none) + | [t, d] => do pure (← parseNat t, some (← parseNat d)) + | _ => throw s!"bad waiter '{s}'" + +def parseEv (tok : String) : Except String Ev := + let r := (tok.drop 1).toString + match tok.front with + | 't' => Ev.tick <$> parseNat r + | 'p' => Ev.poll <$> parseNat r + | 'y' => if r == "" then pure Ev.yield else throw s!"bad event '{tok}'" + | 'b' => if r == "-" then pure (Ev.block none) else (Ev.block ∘ some) <$> parseNat r + | 'w' => Ev.wake <$> parseNat r + | 'x' => Ev.wakeX <$> parseNat r + | 's' => Ev.setTable <$> (r.splitOn ",").mapM parseEntry + | _ => throw s!"bad event '{tok}'" + +/-- Tick indexes and deadlines stay below this, far from the end of `u64`. -/ +def limit : Nat := 2 ^ 32 + +/-- A table the Rust constructors accept. -/ +def okTable (t : Table) : Bool := + 0 < t.length && t.length ≤ 16 && t.all fun e => e.1 < ndom && 0 < e.2 && e.2 ≤ 255 + +def okDeadline : Option Nat → Bool + | some k => 0 < k && k < limit + | none => true + +/-- The event is one that means the same in the Rust test (`n` tasks). -/ +def okEv (n : Nat) : Ev → Bool + | .tick k | .poll k => k < limit + | .yield => true + | .block dl => okDeadline dl + | .wake t | .wakeX t => t < n + | .setTable t => okTable t + +/-- The script is one that means the same on both sides. -/ +def Script.check (sc : Script) : Except String Unit := do + let n := sc.dom.size + unless sc.dom.all (· < ndom) do throw "task domain out of range" + unless sc.first < n && sc.dom.getD sc.first 0 == 0 do throw "the first task must be a task of domain 0" + unless sc.now < limit do throw "boot tick too large" + unless sc.ready.all (· < n) && sc.waits.all (·.1 < n) do throw "unknown task" + unless sc.waits.all (okDeadline ·.2) do throw "deadline 0 or too large" + for (tok, e) in sc.evs do + unless okEv n e do throw s!"event '{tok}' is outside the common input" + +def parseScript (now doms first ready waits evs : String) : Except String Script := do + let sc : Script := { + now := ← parseNat now + dom := (← (words doms).mapM parseNat).toArray + first := ← parseNat first + ready := ← (words ready).mapM parseNat + waits := ← (words waits).mapM parseWait + evs := ← (words evs).mapM fun tok => do pure (tok, ← parseEv tok) } + sc.check + pure sc + +/-! ## Running a script through the model -/ + +/-- The state before the first event and after every event. -/ +def states (dom : Tid → Dom) (s : St) : List Ev → List St + | [] => [s] + | e :: es => s :: states dom (step dom s e) es + +/-- The canonical lines of a script: `boot`, then `step` for every event. -/ +def Script.lines (sc : Script) : List String := + let dom : Tid → Dom := fun t => sc.dom.getD t 0 + let s0 := boot sc.now sc.first (fun d => sc.ready.filter (dom · == d)) + (fun d => sc.waits.filter (dom ·.1 == d)) + (states dom s0 (sc.evs.map (·.2))).map showSt + +/-! ## The file -/ + +/-- A line of the file. -/ +inductive Line where + /-- A comment or an empty line. -/ + | text (s : String) + /-- A script: its text without the hash, its id, the stored hash if any. -/ + | script (body id : String) (stored : Option String) (sc : Script) + +def parseLine (l : String) : Except String Line := + if l == "" || l.front == '#' then pure (.text l) else + match l.splitOn ";" with + | [id, now, doms, first, ready, waits, evs] => + .script l id none <$> parseScript now doms first ready waits evs + | [id, now, doms, first, ready, waits, evs, h] => + .script (";".intercalate [id, now, doms, first, ready, waits, evs]) id (some h) + <$> parseScript now doms first ready waits evs + | _ => throw "not a script (7 or 8 fields separated by ';')" + +/-- The lines of the file, or the first line that is not accepted. -/ +def parseFile (text : String) : Except String (List Line) := do + let ls := text.splitOn "\n" + let ls := if ls.getLast? == some "" then ls.dropLast else ls + let mut out := [] + let mut i := 1 + for l in ls do + match parseLine l with + | .ok x => out := x :: out + | .error e => throw s!"line {i}: {e}" + i := i + 1 + pure out.reverse + +/-- The file again, every script with the hash the model gives. -/ +def regen (ls : List Line) : String := + String.join (ls.map fun + | .text s => s ++ "\n" + | .script body _ _ sc => s!"{body};{hex (hashLines sc.lines)}\n") + +/-- The scripts whose stored hash is not the model's, or the reason the file cannot be checked. -/ +def check (ls : List Line) : Except String (Nat × List String) := do + let mut n := 0 + let mut bad := [] + for l in ls do + if let .script _ id stored sc := l then + let h := hex (hashLines sc.lines) + match stored with + | none => throw s!"script {id} has no hash" + | some st => if st != h then bad := s!"script {id}: stored {st}, model {h}" :: bad + n := n + 1 + if n == 0 then throw "no script" + pure (n, bad.reverse) + +/-- The canonical lines of every script, each after the event that gave it. -/ +def trace (ls : List Line) : String := + String.join (ls.map fun + | .text _ => "" + | .script _ id _ sc => + let toks := "boot" :: sc.evs.map (·.1) + s!"script {id}\n" ++ String.join ((toks.zip sc.lines).map fun (t, l) => s!" {t} -> {l}\n")) + +end ModelVectors + +open ModelVectors in +def main (args : List String) : IO UInt32 := do + let (mode, path) := match args with + | [path] => ("", path) + | [mode, path] => (mode, path) + | _ => ("?", "") + unless mode == "" || mode == "--check" || mode == "--trace" do + IO.eprintln "usage: vectors [--check | --trace] FILE" + return 2 + let fail (e : String) : IO UInt32 := do + IO.eprintln s!"{path}: {e}" + return 2 + match ← (IO.FS.readFile path).toBaseIO with + | .error e => fail (toString e) + | .ok text => + match parseFile text with + | .error e => fail e + | .ok ls => + if mode == "" then + IO.print (regen ls) + else if mode == "--trace" then + IO.print (trace ls) + else + match check ls with + | .error e => return ← fail e + | .ok (n, bad) => + for b in bad do IO.println b + IO.println s!"scripts: {n}, differing from the model: {bad.length}" + if !bad.isEmpty then return 1 + return 0 diff --git a/proofs/lean/README.md b/proofs/lean/README.md new file mode 100644 index 0000000..d4d81e2 --- /dev/null +++ b/proofs/lean/README.md @@ -0,0 +1,603 @@ +# Lean proofs for the K0 partition scheduler + +These are machine-checked proofs about **models** of the K0 scheduler. They are +proofs about the models, not about the Rust code, and they make no claim of +certification or compliance. One host test ties the Rust code to one of the +models on recorded inputs. It is a test, not a proof. + +## Files + +| File | What it is | +|---|---| +| `K0Part.lean` | A model of `Core` of the `k0-part` crate (`tick`, `poll`, `block`, `yield_now`, `set_table`, with the tick rule of `k0-slice`) across several domains | +| `K0Share.lean` | A model of one domain on its own timeline under the tick rule, with a bound on the CPU share of a task that never gives up the CPU | +| `K0ShareWide.lean` | The same results for a wider model of that domain. It imports `K0Share.lean` | +| `K0Bridge.lean` | Links the two models. It imports `K0Part.lean` and `K0Share.lean` and changes neither | +| `K0Close.lean` | Statements that pin down definitions the other files leave free. It imports `K0Part.lean` and `K0Bridge.lean` and changes neither | +| `ModelVectors.lean` | The executable `vectors`, which computes what `K0Part.lean` gives for recorded event scripts | +| `../../crates/k0-part/src/model_vectors.txt` | The recorded scripts with the model's result for each | +| `../../crates/k0-part/src/model_tests.rs` | The host test that runs those scripts through the Rust `Core` | + +The first five files hold the proofs. All Lean files use core Lean only (no +Mathlib, no Std, no other dependency). + +## What `K0Part.lean` proves + +State: a table with a pending table and an epoch, per-domain ready queues, +per-domain waiting lists with optional deadlines in global ticks, the running +task with its tick-rule exemption bit. Events: `tick n` (a jump is one step), +`poll n`, `yield`, `block`, `wake t` (own domain), `wakeX t` (a cross-domain +wake, a separately labelled event), `setTable t`. The four task events +(`yield`, `block`, `wake`, `wakeX`) do nothing while no task runs, so only a +tick or an idle `poll` can queue a task of an idle domain. + +- `pinv_pstep`, `inv_boot`, `inv_step`, `inv_exec`: the invariant `Inv` holds + at boot and is kept by every event. Part of it is `PInv`: a pending table + always starts after the last processed tick, and the epoch is never after + it. The Rust code relies on both without stating them (`Core::set_table` + does not look at the pending table it replaces, `Core::tick` computes + `n - epoch` without a check). `setTable_now_needs_pendAfter` shows what + would go wrong without the first. +- `guard_sound`, `guard_sound_event`: `set_table` after tick `n` leaves the + domain of tick `n + 1` unchanged, provided a pending table starts after `n` + (`PendAfter`, part of `Inv`) and none starts exactly at `n + 1`. Without the + second hypothesis the statement is false: `guard_unsound_without_hyp` is a + counterexample on a state reached from boot (`exP_reachable`: tick 1, a + `set_table` call and tick 2 reach the state; a second call in tick 2 then + discards the pending table the first one made), and there the decision + itself flips (`guard_decision_flips`). Anything that arms a guard for tick + `n + 1` before the second call must be recomputed after it. +- `plan_setTable_ge`, `plan_setTable_lt`, `plan_setTable_now`, + `table_effective_at`: a table set after tick `n` governs ticks `>= n + 2` at + position `(k - (n + 2)) mod cycle`, until a later call + (`first_table_never_governs`); ticks `n` and `n + 1` keep the old plan (same + hypothesis as above for `n + 1`). +- `cycle_eq_sum`, `domAtPos_window`, `window_cover`, `domAt_window`, + `plan_setTable_window`: the layout of a table. Entry `i` governs exactly its + window, the windows follow in the order of the entries, and the table + repeats. +- `running_domain_function`, `running_domain_same`, `tick_jump_domain`: the + running domain is the planned domain of the last processed tick, a function + of the public events (new ticks and `set_table` calls) and the initial clock + part only. Queues, waits and task actions do not enter. +- `no_slack_donation`: after any events from an `Inv` state, the running task + belongs to the running domain, and if nothing runs the running domain's + ready queue is empty. The model never lets one domain use another's window. +- `serve_wakes_due`, `serve_due_order`, `tick_serves`, `tick_frame`, + `tick_old_domain`, `poll_serves`, `poll_frame`, `block_keeps_deadline`, + `waiter_leaves_only`: timed waits do fire, and only for the domain that + runs. A new tick takes every waiter of the domain that runs after it whose + deadline has passed out of the waiting list: it is then in that domain's + queue or is the task that runs. `serve` queues the last waiter first. No + theorem here states the order of the queue after a whole tick. A new tick + touches no domain that neither ran before nor runs after. A waiter leaves + its list only when its domain is served at or after its deadline, or by a + wake. Each of these is about one step and about tick indexes: none says when + a tick comes, or that one comes. +- `step_tasks_perm`, `exec_tasks_perm`, `nodup_step`, `nodup_exec`, + `step_tasks_mem`, `exec_tasks_mem`: no task is lost and none is duplicated. + From a state with `Inv` and without duplicates (`NoDup`), the tasks of every + domain (running, ready, waiting) after a run are a permutation of the tasks + before, and `NoDup` is kept. `wake_needs_nodup` shows the hypothesis cannot + be dropped. `wake_effect`, `wakeX_effect`: a woken task goes to the back of + its own domain's queue. +- `noninterference`, `noninterference_final`: for any domain `D`, two `Inv` + states related by `R D` (same clock part and running domain, same queue and + waiting list of `D`, same running task and slice bit when `D` runs, all + other domains arbitrary) and two event lists related by `Sync` give `D` the + same view (its queue, its waiting list, which of its tasks runs with the + slice bit) after every step, and `R` is preserved. `Sync` compares the two + lists place by place: + - A clock event (a tick index not seen before, or a `set_table` call) is the + same public event in both runs. A new tick may reach one run through + `tick` and the other through the idle loop's `poll` (`poll_eq_tick`), so + the runs may differ in whether another domain idles. + - Every other event is local to the running domain: an action of its task, + its idle loop taking an interrupt without a new tick, or a repeated tick + index. While `D` runs the local events are the same in both runs. While + another domain runs they are unrelated, and `tick 0`, which does nothing, + pads the run that has fewer (`tick_zero_noop`). + - No `wakeX` into `D` in either run. This is the reading of "no shared + capability": no task outside `D` can wake a task of `D`. A `wakeX` from + `D` outward is allowed and gives `D` nothing back. + + The hypotheses fix the tick indexes (jumps included) and the `set_table` + calls as equal in both runs, so the theorem does not explain them. + `tick_indexes_needed` and `cross_wake_breaks` show that these two + hypotheses are needed. +- `example_applies`, `example_views_equal`, `example_effects`, + `example_kernel_shaped`: a concrete pair of runs that satisfies every + hypothesis and keeps to the kernel's call pattern (`poll` only while nothing + runs). The other domains have different tasks, wake different tasks, and + idle at different times; the views of `D = 1` are equal at every step and + the views of domains 0 and 2 differ. +- `serve_only_own`, `serve_not_early` are read off the definition of the + model's `serve`. They say nothing about the kernel's `serve` callback. + +No theorem in this file constrains the exemption bit beyond its bookkeeping. +That is the subject of `K0Bridge.lean`, and of `K0Close.lean` for the idle +paths that the bridge leaves out. + +## What `K0Share.lean` proves + +Model: one domain, a ready queue, a tick every `P` steps, the exemption bit, +and an adversary choosing any finite list of `run`, `yield`, `block`, `wake` +events. Yield, block and wake take no time and may occur between any two +steps, including one step before a tick and right after it, but not between +the last step of a period and its tick. Task `0` is a "spinner" that never +yields or blocks, is never stopped or deleted, and is in the system from the +start state on. At most `N` tasks are ready or running at one instant: this is +an assumption, and the model drops a wake above `N`. The start state is any +well-formed state (`Wf`). + +- `share_bound`, `share_bound_diff`, `share_bound_prefix`: + `time <= N * ran + (N - 1) * P + c0`, where `c0` is the number of steps to + the first tick. The bound quantifies over all lists of these four events. + For a spinner that becomes ready after the start, use `share_bound_diff` + from that instant. +- `no_early_cut`, `exec_no_early_cut`: a task is cut by a tick only after it + has run at least `P` steps since it got the CPU. For the task that runs in + the start state the count starts from the `age` that `Wf` allows, so for + that task the conclusion is the assumption. A task that gets the CPU out of + idle is not covered (the model has no idle). +- `wait_bound`: a ready task with `k` tasks ahead of it (the running task + included) has started to run within `(k + 1) * P` steps. +- `step_time`, `exec_time`, `step_ran`, `exec_ran_le_time`, + `alone_time_eq_ran`, `step_age`, `step_cur_keeps`, `age_counts`, + `started_sound`: the counters mean what the statements read as. `time` grows + by one per `run`. `ran` grows by one exactly on a `run` taken while the + spinner runs, never by more than `time`, and by as much as `time` when + `N = 1`. `age` is 0 right after the CPU changes hands and counts the steps + since. A task that "started" was at the head of the queue and became the + running task. +- Tightness: two `decide` examples reach `t = (N - 1) * P + c0` with `ran = 0` + (`N = 3, P = 2` and `N = 4, P = 3`). There is no tightness theorem for all + `N` and `P`. + +## What `K0ShareWide.lean` proves + +Model: the domain of `K0Share.lean` with three behaviours of the kernel that +it leaves out. `step` lets one step pass and `tick` delivers the tick when the +countdown is 0, so yield, block, wake and remove may fall between the last +step of a period and its tick; no step passes while a tick is due. `remove i` +takes a ready task out of the queue from any position; the spinner is never +removed. `wake` has no cap: `N` is not in the transition function, and "no +state along the run has more than `N` tasks ready or running" (`Wide.Capped`) +is a hypothesis. + +- `Wide.share_bound`, `Wide.share_bound_diff`, `Wide.share_bound_always`: from + a state with a countdown `c0 <= P` and the spinner in the system, for every + behaviour that keeps the cap, `time <= N * ran + (N - 1) * P + c0` at every + instant of the run. `Wide.cap_needed`: without the cap hypothesis the bound + fails. +- `Wide.contains` (`Wide.wexec_widen`, `Wide.capped_widen`): every behaviour of + `K0Share.lean` from a well-formed state is a behaviour of the wide model with + the same final state, and it keeps the cap. `Wide.share_bound_base`: the + headline of `K0Share.lean` follows from the wide one. The converse fails + (`Wide.tick_after_yield`, `Wide.tick_after_yield_not_base`, + `Wide.remove_not_block_wake`). +- `Wide.no_early_cut`: when a tick takes the CPU from the running task, that + task has run at least `P` steps since it got the CPU. +- `Wide.wait_bound`, `Wide.wait_bound_passed`, `Wide.wait_bound_tick`: a ready + task with `k` tasks ahead of it becomes the running task no later than + `(k + 1) * P` steps of time after the start, unless it is removed; at exactly + that many steps the tick that is due starts it. Steps are counted by the + `time` field. "After `(k + 1) * P` steps it has started" is false in this + model (`Wide.wait_at_bound`): the last tick may be due and not yet + delivered. + +That a timer interrupt which becomes pending during a yield or a block is +taken before the next task has run is a reading of the kernel code, not a Lean +fact. + +## What `K0Bridge.lean` proves + +`Rel lab s k` relates a `K0Part` state in which a task runs to a `K0Share` +state: the label of the running task, its exemption bit, and the labels of the +running domain's ready queue. `lab` maps task ids to `K0Share` names; a task +with label 0 is the spinner. The countdown, `age`, `time` and `ran` are not +compared. + +- Rule by rule (`sameStep_onTick`, `serve_wakes`, `tick_same`, `yield_step`, + `block_step`, `wake_step`, `boot_start0`): a tick inside the running domain, + a yield, a block, a wake and boot do to the projection what `K0Share.onTick` + and `K0Share.step` do, for every state. The side conditions are explicit: + the running task is not the spinner (yield, block), the queue is not empty + (block), a woken task does not have label 0, the cap `N` is not reached. + `yield_spinner_differs`, `block_spinner_differs`, `block_empty_idle` and + `wake_cap_needed` show that the models differ where the first, the second or + the fourth condition fails. No theorem in the file shows it for the third (a + woken task with label 0). +- The window boundary (`cut_parked`, `enter_parked`, `tick_leave`, + `tick_return`, `window_cycle`): `K0Share` has no window. In `K0Part`, from + the tick that closes a domain's window to the tick that opens it again, the + projection moves by one `K0Share.onTick` and then by the timed wakes served + at the opening. The hypotheses of `window_cycle` are: `K0Part.Inv`; a task + of the domain runs when the window closes (a domain that is idle at the + closing tick is not covered); both ticks have new indexes; no task of the + domain is woken across domains in between; the wakes served at the opening + meet the side conditions of the rule lemmas (no label 0, below the cap `N`). + A parked task with the mark keeps the front and loses the mark; a task that + enters has no mark. +- One domain, run level (`run_projects`, `run_projects_prefix`, + `timed_share_bound`, `boot_share_bound`): `K0Part` has no time between + ticks, so the bridge adds a step in which time passes without a tick, a + countdown and two counters. These are not part of `K0Part`. A timed run in + which the tables name the running domain only, a tick falls every `P` steps, + the spinner never yields or blocks, there is no `poll`, and the domain has + at most `N` tasks, projects step by step onto a `K0Share` behaviour, and + `time <= N * ran + (N - 1) * P + c0` holds for it, where `ran` counts the + steps in which the task with label 0 is the running task of the `K0Part` + state. The start state (`Start`) and the run (`OkRun`) carry more + conditions than that sentence: `K0Part.Inv` holds; a task runs at the start; + exactly one task among the running and the ready ones has label 0 and no + waiting one has; the first countdown is in `1..P`; for `timed_share_bound` + both counters start at 0. The `N` here counts the waiting tasks too + (`Start.cap`), while the `N` of `K0Share.lean` counts ready and running + tasks only, so the two are not the same assumption. + +The rule lemmas pin the tick rule of `K0Part.lean`: with the mark not cleared +by a tick, no mark after a yield or a block, a mark at a tick entry, no mark +at boot, or a cut task parked at the other end, one of them is false. This is +a sentence about changed definitions, so no theorem in the files states it. + +What it does not give: no share bound for a table with several domains (no +theorem counts a domain's steps across its windows); the time between ticks is +an addition of the bridge, and a jump of the tick index counts as one tick; +the idle paths of `K0Part` have no counterpart in `K0Share` (what the +exemption bit is on those paths is stated in `K0Close.lean`, for `K0Part` +alone); `no_early_cut` and `wait_bound` are not carried over; +`K0ShareWide.lean` is not bridged. + +## What `K0Close.lean` proves + +Every theorem of the other four files stays true under some changes of their +definitions. A change that no theorem notices is behaviour that no theorem +constrains. This file holds a statement for each such gap that a sensitivity +run found (see "Checks that are not in the repository" for the run, and the +ids in parentheses are the ids of its changes). Each statement is proved for +the definitions as they are. For every id except NV23 the run recorded a +concrete instance of the statement that is false under the change. The file +changes nothing in `K0Part.lean` or `K0Bridge.lean`. + +- `R_of_view`, `viewTrace_get`, `viewTrace_length` (NV01, NV02, NV03, NV05): + what `view` and `viewTrace` hold. The conclusion of `noninterference` is + written with them and nothing else fixed them. Two `Inv` states with the + same clock part and the same running domain whose views of `D` are equal + are related by `R D`, so a view holds the queue, the waiting list and the + running task of `D` with its slice bit, and nothing less. The view trace + has one view per step: entry `k` is the view after the first `k` events, + and the trace of a list of events has one entry more than the list. +- `tick_clears_mark`, `poll_keeps_running`, `poll_idle_mark` (ND25, NX03, + ND16): the exemption bit on the paths the bridge leaves out. After a tick + with a new index the running task has no exemption, also when the tick + finds the domain idle and starts a task. A `poll` without a new tick leaves + a running task alone, with its bit. A task that such a `poll` starts out of + idle has the exemption. +- `poll_wl`, `tick_wl` (ND31): the waiting list after a step, in order. After + a `poll` without a new tick the waiting list of the running domain is the + old list without the waiters that were due, in the old order. After a tick + with a new index the same holds for the domain that runs after it. +- `wakeX_idle_noop`, `wake_idle_noop` (NX01): a wake while no task runs + changes nothing. +- `domAt_zero_cycle` (NT01): a table of zero ticks (empty, or only windows of + 0 ticks) gives the root domain at every tick. Rust rejects such tables, and + the model accepts them. +- `boot_part` (NT09): at boot the table is the default table, it starts at the + boot tick, the last processed tick is the boot tick, and no table is + pending. +- `advance_epoch_le` (NV23): what the clause `epoch <= seen` of `PInv` is for. + At a new tick `n` the epoch after `advance` is at most `n`, so the offset + `n - epoch` that `Core::tick` computes does not underflow. No other theorem + uses the clause. +- `blockIdleRust_pops` (NV28): `blockIdleRust`, the copy of `Core::block` that + `blockIdleRust_eq` is about, does pop. With a task ready it starts that task + with the exemption, so `blockIdleRust_eq` is not about a function that does + nothing. +- `spin_idle` (NB11): `K0Bridge.spin` is 0 for a state in which no task runs, + so the counter `ran` of `timed_share_bound` never counts an idle step as a + step of the spinner. + +Every `inst_` is one concrete instance of the theorem above it, proved by +`decide`, and every `from_` derives the same instance from the general +theorem. `one`, `one_inv`, `idleX`, `idleQ`, `bitIs`, `bitIs_of`, `enter_bit` +and `domAtPos_zero_cycle` are helpers for these. + +These are more statements about the model, and they add nothing about the +Rust code. Six of the ids (ND16, ND25, NX03, ND31, NX01, NT09) are about +behaviour that the recorded results below already held, although no theorem +stated it. The others are about definitions that neither a theorem nor the +recorded results had fixed. + +## Recorded results of the model + +The proofs are about the model. This part is a test that ties the Rust code to +the model on a fixed set of inputs, and unlike the proofs it runs in CI. + +- `crates/k0-part/src/model_vectors.txt` holds 1600 event scripts: a boot + state, then ticks, polls, yields, blocks, wakes and `set_table` calls. Every + line ends with the result the model gives for the script, a 64-bit hash + (FNV-1a) of one canonical line per state, for the boot state and after every + event. A line holds the last processed tick, the table in force and its + epoch, the pending table and its start, the running domain, the running task + and its exemption bit, every domain's queue and waiting list, and the + decision `next_tick_switches`. +- `ModelVectors.lean` is the executable `vectors`. It runs the scripts through + `K0Part.boot` and `K0Part.step` and computes the hashes. It imports `K0Part` + and changes nothing in it. Its header comment defines the script format, the + line and the hash. +- `crates/k0-part/src/model_tests.rs` is a host test of the crate `k0-part`. + It runs the same scripts through the unmodified `Core`, builds the same + lines from the fields of `Core`, and compares the hashes. CI has no Lean, but + it runs this test with the other host tests (`tools/host-test.sh`), so it + fails as soon as the Rust code and the recorded results differ. On a + mismatch the test prints the script and the lines `Core` gave. + +### What a passing test shows and what it does not + +It shows that `Core` and `step` gave the same line after every event of the +recorded scripts. The scripts take every branch of `Core::tick`, `poll`, +`yield_now`, `block` and `set_table` and both wake events, with jumps of the +tick index, repeated indexes, two `set_table` calls between two ticks and in +consecutive ticks, single-domain tables, idle stretches, several waiters +expiring at once and deadlines in the past. The test counts the branches +itself and fails on a file that reaches one of them fewer than 100 times. It +also fails on a file that does not hold exactly 1600 scripts, and when `Core` +calls `Env::enter_domain` on anything but a change of the running domain or +leaves the call out on one. The hash covers the state lines only, so that +last check is made beside it. + +It is testing, not proof. + +- It says nothing about inputs that are not in the file. +- The `Env` of the test is a list model, not the kernel. Queues and waiting + lists are lists, and expired waiters go to the back of their queue last + waiter first, which is the kernel's order (`k0_sched::arm_timeout` links at + the head, `k0_sched::expired` walks from the head). The kernel's intrusive + queues, its own `Env` and its call sites are not run here. +- Only inputs that mean the same on both sides are in the file: valid tables, + tick indexes below 2^32, no deadline 0. In the recorded file the tick + indexes also never go back, but `vectors` does not require that. There + is one exception. The 170 scripts whose id starts with `i` may hold a + yield, a block or a wake while nothing runs, which the kernel does not + raise; they are there because nothing else reaches the early return of + `Core::yield_now`. For a block in that state the two sides do different + things (`Core::block` pops the queue, `step` does nothing) and agree only + because the queue is empty then (`blockIdleRust_eq`). +- What the model leaves out (console input, time inside a tick, caches) is + left out here too. +- The comparison goes through a 64-bit hash that only keeps the file small. + Two different traces with the same hash are possible in principle. +- CI does not check that the hashes are the model's. That needs the Lean + toolchain and the `--check` command below. + +### How to check and regenerate + +```sh +$ cd proofs/lean +$ lake exe vectors --check ../../crates/k0-part/src/model_vectors.txt +``` + +The last line must be `scripts: 1600, differing from the model: 0` and the exit +status 0. A script whose stored hash is not the model's is listed and the exit +status is 1. Status 2 means the file could not be read or holds a line that is +not an accepted script. `lake` prints its own build messages on stderr. + +To write the hashes again: + +```sh +$ lake exe vectors ../../crates/k0-part/src/model_vectors.txt > model_vectors.new +$ mv model_vectors.new ../../crates/k0-part/src/model_vectors.txt +``` + +Comment lines are kept, so with an unchanged model the new file is the old one +byte for byte. `lake exe vectors --trace FILE` prints the model's lines for +every script of FILE in the layout of the failing test's report, so the two +can be compared line by line. + +The scripts came from the generator of a differential harness that is not in +the repository, so the scripts cannot be regenerated from here; the hashes +can. A script can be added by hand: append the line without its hash, write +the hashes again, and change the number of scripts that `model_tests.rs` +requires (1600). + +### When the Rust code or the model changes on purpose + +- `Core` changes its behaviour: make the same change in `K0Part.lean`, get + `lake build` to pass again (the theorems must still hold or be restated in + the open), write the hashes again, then run the host tests. Never write the + hashes again from anything but the model, and never edit a hash, to make + the test pass: the file must always satisfy the `--check` command above. +- The model changes: run `--check`. If it still passes, the change did not + alter any recorded result and nothing else is needed. If it reports + scripts, the Rust test will fail on those scripts once the hashes are + written again, until `Core` follows. +- A new event, a new field of the state or a new `Env` call: `showSt` in + `ModelVectors.lean` and `line` and `step` in `model_tests.rs` change + together, and scripts that use the new part are added. The list `NEED` in + `model_tests.rs` names every path the scripts must take. + +## What the models leave out + +- Time inside a tick. `K0Share` and `K0ShareWide` count whole steps; `K0Part` + has only tick indexes. Nothing is said about instants, the timer, the guard + band, the hold before returning to EL0, interrupt latency or the length of + kernel paths. What makes a tick late or skipped is outside the models. +- Where the tick indexes come from: the model takes the index of every tick + event as given. That the kernel hands `Core` every tick it counts before any + other event is a property of the kernel paths, not of the model. The + hand-off to the root task masks interrupts before `Core::start` reads the + tick for this reason: a tick counted between that read and the entry to EL0 + would leave `Core` one tick behind the counter, and a table set in that + state would start one tick early, with no guard for its first change of + domain. +- The guard (only the decision it is based on, `next_tick_switches`, is + modelled), caches, predictors, the TLB. +- The real queues: Rust uses intrusive lists, the models use lists. +- The console. Rust `Env::serve` also wakes a console reader, and it reports + a lost capability or a closed device to a reader of any domain, whichever + domain is served. Input arrival is external. None of this is modelled. +- IPC rendezvous, capabilities, task creation and `TCB_RESUME`, domain + changes, faults. Exit is a block nobody wakes. In `K0Part` the only way one + domain changes another domain's queue or waiting list is `wakeX`; the kernel + has others that need a capability (ending another task removes it from a + queue or a waiting list of any domain, resuming a task queues it). +- `Nat` instead of `u64`. Within two ticks of `2^64` the Rust arithmetic + saturates and the model does not; the kernel's tick counter stops before + that. Tables are arbitrary lists (Rust limits entries, windows and domain + ids, and the system call rejects a table without the caller's domain). +- Events the kernel does not raise are allowed in `K0Part`: `poll` while a + task runs, `tick` while none runs, an index below the last one, a deadline + that is already past. The model is the wider side there. +- In `K0Share` and `K0ShareWide`: a spinner that arrives after the start + state, idle, a proof that a domain has at most `N` runnable tasks (the bound + is relative to that `N`), a late tick or a tick that skips numbers. A task + still chooses when the others run by the instant at which it yields or + blocks, so the timing channel through the scheduler inside a domain stays. +- In `K0Share` only: an event between the last step of a period and its tick, + and the removal of a ready task. Both are in `K0ShareWide`. +- A share bound for a table with several domains. `K0Bridge` links the tick + rule and timed runs of one domain only. + +## How to check + +```sh +$ cd proofs/lean +$ lake build +$ lake env leanchecker K0Part K0Share K0ShareWide K0Bridge K0Close +$ lake exe vectors --check ../../crates/k0-part/src/model_vectors.txt +``` + +The toolchain is pinned in `lean-toolchain` (`leanprover/lean4:v4.35.0`); +`elan` fetches it on first use, and after that nothing is downloaded. + +- `lake build` must finish with zero errors, zero warnings and no `sorry`. The + sources contain no `axiom`, `native_decide`, `unsafe` or `partial`, and one + `set_option`, a linter option in `K0Share.lean`. The build prints + `#print axioms` for the headline theorems; allowed results are `propext`, + `Classical.choice`, `Quot.sound`. +- `leanchecker` comes with the toolchain. It replays the compiled modules + through the kernel, and must print nothing and exit with status 0. A + declaration that was added without the kernel passes `lake build` and fails + here. +- The last command is described under "Recorded results of the model". + +The proofs are not run in CI. The host test with the recorded results is. +`lake-manifest.json` and `.lake/` are generated by `lake`. + +## Checks that are not in the repository + +These were done when the files were reviewed (November 2026). None of them can +be repeated from the repository alone, and each part says what is missing. + +### An external type checker + +`leanexport` (lean4export 3.1.0) and `nanoda_bin` (nanoda 0.4.19) checked the +five modules `K0Part`, `K0Share`, `K0ShareWide`, `K0Bridge` and `K0Close`. The +two programs are not in the repository. On the machine of the review they were +in the directory of the pinned toolchain, and whether every copy of the +toolchain has them was not confirmed, so this check cannot be repeated from +the repository alone. The commands were: + +```sh +$ cd proofs/lean +$ lake build +$ lake env leanexport K0Part K0Share K0ShareWide K0Bridge K0Close > /tmp/k0.ndjson +$ lake env nanoda_bin /tmp/nanoda.json +``` + +The file `/tmp/nanoda.json` was: + +```json +{ + "export_file_path": "/tmp/k0.ndjson", + "use_stdin": false, + "permitted_axioms": ["propext", "Classical.choice", "Quot.sound"], + "unpermitted_axiom_hard_error": false, + "nat_extension": true, + "string_extension": true, + "print_success_message": true +} +``` + +The last command printed `Checked 60911 declarations with no typechecker +errors` and exited with status 0. The number covers the five modules and what +they import from core Lean, and it changes with the toolchain and with the +list of modules. The line `1 pretty printer errors` that it also printed is +not about type checking. The export also declares `sorryAx`, an axiom of the +prelude. With `"unpermitted_axiom_hard_error": false` nanoda does not admit it +and stops at the first declaration that uses an axiom outside the list, so a +pass means that no exported declaration uses an axiom other than the three. +With `true` it stops on the prelude's `sorryAx` before it checks anything. + +### Differential runs + +A differential harness ran the Rust `Core` and `K0Part.step` on 420,000 +random event scripts (about 31 million events) and compared one line per +event: no difference. The recorded scripts are a selection from its +generator. The harness, its generator and its seeds are not in the +repository, so that figure cannot be checked from the repository. During the +review, 40,000 more scripts from a second generator (about 1.6 million events, +half of the scripts with tick indexes that go back) gave no difference either. +That generator is not in the repository. + +What the repository does allow is to compare the two sides on a script file of +your own. `lake exe vectors FILE` writes the model's hash for every script of +`FILE`, and the host test compares whatever file stands in the place of +`model_vectors.txt`. The test also requires exactly 1600 scripts and every +path 100 times, so for another file those two checks have to be relaxed in a +scratch copy of the tree. + +### Changes of the definitions + +The definitions of the models were changed one at a time and the files were +built again, to see whether a theorem notices. + +- An earlier run made 105 changes, and no theorem noticed 19 of them. Those + led to the theorems on timed waits, the table layout and task conservation + in `K0Part.lean`, the counter theorems in `K0Share.lean`, and + `K0Bridge.lean`. +- The last run, on the four files as they were before `K0Close.lean`, made + 260 changes: those 105 and 155 new ones. The build rejected 254, 5 survived, + and 1 of the old ones had no counterpart in the final files. +- A rejected build says less than it seems to. Of 12 control rewrites that + compute the same function, the build rejected 9, because the proofs lean on + the wording of the definitions. So 254 is an upper bound on what the + statements hold. Of the 150 new rejections, 125 were put down to a theorem + whose statement is false under the change, 13 to concrete `decide` examples + only, and 12 to the wording of proofs only: with edits to proofs alone those + 12 changed files build, so every theorem holds in them as stated. The first + two numbers come from reading the statements against the change, not from + counterexamples. +- `K0Close.lean` holds the statements for the gaps. It covers four of the five + survivors (NT01, NV01, NV28, NB11) and ten of the twelve changes that only + proof wording rejected (NV02, NV03, NV05, ND16, ND25, NX03, ND31, NX01, + NT09, NV23). For every one of these ids except NV23 the run recorded that + the instance `inst_` is false in the changed file. That record is for + the file `K0Close.lean` was made from, which has the same statements and + proofs and differs in its header comment only. The two changes left + without a statement, the fifth survivor NB33 and NB29, alter a value on a + branch that the hypotheses of every theorem using it exclude. NV06 is NV01, + NV02, NV03 and NV05 made at once. +- The recorded results are not a net under the theorems. They catch none of + the five survivors, and seven of the changes on the model side of + `K0Part.lean` are noticed by theorems and not by the 1600 scripts. + +The scripts of both runs and their lists of changes are not in the +repository, so the runs cannot be repeated from it. + +## What a proof of the model says + +A theorem here says: for the Lean definitions in these files, the stated +property holds for every input. Whether the Rust code does what the +definitions do is established by reading it, by the host tests, and for +`K0Part.step` by the recorded results, none of which is a proof. A mistake in +a model definition makes a theorem about the wrong thing, and the statements +are only as strong as their hypotheses: `Inv`, `NoDup`, `R`, `Sync` and no +`wakeX` into `D` in `K0Part`; `Wf`, the cap `N` and a spinner that is there +from the start in `K0Share`; `Wide.Inv` and `Wide.Capped N` in `K0ShareWide`; +`Start`, `OkRun` and the side conditions of the rule lemmas in `K0Bridge`. +Nothing here covers timing below the scheduler decision, caches, hardware, or +anything outside the models. The most that can be said is that, inside the +model and under those hypotheses, what a domain sees of the scheduler does not +depend on what the other domains do. diff --git a/proofs/lean/lake-manifest.json b/proofs/lean/lake-manifest.json new file mode 100644 index 0000000..f37abd3 --- /dev/null +++ b/proofs/lean/lake-manifest.json @@ -0,0 +1,6 @@ +{"version": "1.3.0", + "packagesDir": ".lake/packages", + "packages": [], + "name": "k0proofs", + "lakeDir": ".lake", + "fixedToolchain": false} diff --git a/proofs/lean/lakefile.toml b/proofs/lean/lakefile.toml new file mode 100644 index 0000000..fec6d25 --- /dev/null +++ b/proofs/lean/lakefile.toml @@ -0,0 +1,10 @@ +name = "k0proofs" +defaultTargets = ["K0"] + +[[lean_lib]] +name = "K0" +roots = ["K0Part", "K0Share", "K0ShareWide", "K0Bridge", "K0Close"] + +[[lean_exe]] +name = "vectors" +root = "ModelVectors" diff --git a/proofs/lean/lean-toolchain b/proofs/lean/lean-toolchain new file mode 100644 index 0000000..a6aff06 --- /dev/null +++ b/proofs/lean/lean-toolchain @@ -0,0 +1 @@ +leanprover/lean4:v4.35.0 diff --git a/tools/boot-matrix.sh b/tools/boot-matrix.sh index e1f4b07..442e961 100755 --- a/tools/boot-matrix.sh +++ b/tools/boot-matrix.sh @@ -86,13 +86,28 @@ pass() { name="$1"; elf="$2"; shift 2 want "$name" $only || return 0 ran=$((ran + 1)) - if env "$@" K0_BOOT_LOG="$root/target/matrix-$name.log" tools/qemu-boot-test.sh "$elf" > "target/matrix-$name.out" 2>&1; then - echo "matrix: $name pass" - else - echo "matrix: $name FAIL" - show "target/matrix-$name.out" - failed="$failed $name" - fi + tries=0 + while :; do + tries=$((tries + 1)) + if ! env "$@" K0_BOOT_LOG="$root/target/matrix-$name.log" tools/qemu-boot-test.sh "$elf" > "target/matrix-$name.out" 2>&1; then + echo "matrix: $name FAIL" + show "target/matrix-$name.out" + failed="$failed $name" + return 0 + fi + # 시간 분할 창 검증이 한 번 다시 돈 실행은 호스트의 멈춤일 수도, 부팅 뒤 첫 + # 표에서만 드러나는 결함일 수도 있음. 행을 한 번 더 돌려 또 다시 돌면 실패로 + # 봄(멈춤은 되풀이되기 어렵고 결함은 늘 되풀이됨) + grep -q '^boot-test: partition window retries: [1-9]' "target/matrix-$name.out" || break + if [ "$tries" -ge 2 ]; then + echo "matrix: $name FAIL (the window test needed its retry in two runs)" + show "target/matrix-$name.out" + failed="$failed $name" + return 0 + fi + echo "matrix: $name ran the window test twice, running the row again" + done + echo "matrix: $name pass" } # 터미널 행: 이름, 이미지, 그 뒤는 환경 변수 대입들. 이미지를 부팅해 직렬 diff --git a/tools/host-test.sh b/tools/host-test.sh index 8bfb253..c0d2345 100755 --- a/tools/host-test.sh +++ b/tools/host-test.sh @@ -6,7 +6,7 @@ cd "$root" host="$(rustc -vV | sed -n 's/^host: //p')" -cargo test --offline --target "$host" -p k0-abi -p k0-cap -p k0-boot -p k0-efi -p k0-conin -p k0-slice "$@" +cargo test --offline --target "$host" -p k0-abi -p k0-cap -p k0-boot -p k0-efi -p k0-conin -p k0-slice -p k0-part "$@" # 키 볼트: 알고리즘을 넣은 것과 뺀 것을 따로 돌림(feature가 다르면 다른 코드) cargo test --offline --target "$host" -p k0-vault --features ed25519 "$@" cargo test --offline --target "$host" -p k0-vault "$@" diff --git a/tools/qemu-boot-test.sh b/tools/qemu-boot-test.sh index 2c89dde..d132647 100755 --- a/tools/qemu-boot-test.sh +++ b/tools/qemu-boot-test.sh @@ -172,7 +172,7 @@ else reuse_sed='' fi -markers="k0: entry phase 1 (pre-MMU)|k0: dtb = |k0: mmu on (identity + fixed image address)|k0: jumping to higher half|k0: higher half (pc = |k0: w^x checks pass|k0: memory |k0: platform |k0: root task integrity ok|k0: entropy dtb=|k0: pac=|k0: irq on (timer 1s)|k0: kernel table pool |k0: root task loaded|k0: kernel reserve |k0: untyped |k0: root cnode ready|k0: bootinfo page ready|k0: user w^x checks pass|k0: dtb seeds wiped |k0: entering root task (el0)|root: hello from EL0|root: boot seed from rng-seed bytes |root: control byte filter [?]|root: retype/map tests pass|root: capability tests pass|root: untyped reuse test pass|root: child exit test pass|root: ipc tests pass|k0: task fault dabort-lower|k0: task fault fp-simd|root: fault isolation tests pass|root: slice test yield pass|root: slice test block pass|root: preempt test pass|root: secret at |root: confined task reported|k0: task fault dabort-lower|root: isolation tests pass|k0: task fault dabort-lower|k0: task fault iabort-lower|k0: task fault dabort-lower|k0: unknown syscall 65535, killing task|root: violation tests pass|root: teardown tests pass|k0: idle (waiting for a timeout)|root: timeout tests pass|root: revocation tests pass|root: kernel reserve tests pass|root: sched tests pass|k0: tick " +markers="k0: entry phase 1 (pre-MMU)|k0: dtb = |k0: mmu on (identity + fixed image address)|k0: jumping to higher half|k0: higher half (pc = |k0: w^x checks pass|k0: memory |k0: platform |k0: root task integrity ok|k0: entropy dtb=|k0: pac=|k0: irq on (timer 1s)|k0: kernel table pool |k0: root task loaded|k0: kernel reserve |k0: untyped |k0: root cnode ready|k0: bootinfo page ready|k0: user w^x checks pass|k0: dtb seeds wiped |k0: entering root task (el0)|root: hello from EL0|root: boot seed from rng-seed bytes |root: control byte filter [?]|root: retype/map tests pass|root: capability tests pass|root: untyped reuse test pass|root: child exit test pass|root: ipc tests pass|k0: task fault dabort-lower|k0: task fault fp-simd|root: fault isolation tests pass|root: slice test yield pass|root: slice test block pass|root: preempt test pass|root: partition refusal pass|root: partition window pass|root: secret at |root: confined task reported|k0: task fault dabort-lower|root: isolation tests pass|k0: task fault dabort-lower|k0: task fault iabort-lower|k0: task fault dabort-lower|k0: unknown syscall 65535, killing task|root: violation tests pass|root: teardown tests pass|k0: idle (waiting for a timeout)|root: timeout tests pass|root: revocation tests pass|root: kernel reserve tests pass|root: partition sealed|root: sched tests pass|k0: tick " # 메모리의 로그에는 처음 몇 번의 틱만 남습니다. 자가 검증이 그보다 오래 걸리는 # 호스트에서는 끝의 틱이 로그에 없을 수 있으므로 순서 목록에서는 빼고, 첫 틱이 # 기록됐는지와(아래) 자가 검증 뒤에도 틱이 이어지는지를(위의 대기) 따로 봅니다. @@ -314,6 +314,11 @@ if [ -z "$missing" ] && [ -n "$require" ]; then set +f fi +# 시간 분할 창 검증이 호스트의 멈춤으로 한 번 다시 돈 횟수. 판정에는 쓰지 않고 +# 알리기만 함(두 번 다 틀리면 검증 자체가 실패 줄을 남김) +retries="$(tr -d '\r' < "$log" | grep -c '^root: partition window retry' || true)" +echo "boot-test: partition window retries: $retries" + if [ "$state" = done ] && [ -z "$missing" ]; then echo "boot-test: pass (${elapsed}s, log $log)" exit 0 diff --git a/userspace/root-task/src/main.rs b/userspace/root-task/src/main.rs index a6abd2d..07090e1 100644 --- a/userspace/root-task/src/main.rs +++ b/userspace/root-task/src/main.rs @@ -38,6 +38,7 @@ use core::sync::atomic::{AtomicU64, Ordering}; #[cfg(feature = "vault")] mod oracle; +mod partition; #[cfg(feature = "terminal")] mod service; mod timeslice; @@ -322,6 +323,33 @@ fn tcb_resume(tcb: i64) -> i64 { sys1(syscall::TCB_RESUME, tcb as u64) as i64 } +/// 시간 분할 표의 항목들을 PART_SET_TABLE의 레지스터 넷으로 싸는 함수입니다. +/// +/// 항목 i는 레지스터 i / 4의 비트 16 * (i % 4)부터 16비트이고 값은 +/// `(틱 수 << 8) | 도메인`입니다. 열여섯 개를 넘는 항목은 싣지 않습니다(항목 +/// 수는 부르는 쪽이 따로 넘기므로 커널이 거부함). +fn pack_table(entries: &[(u8, u8)]) -> [u64; 4] { + let mut regs = [0u64; 4]; + for (i, &(domain, ticks)) in entries.iter().take(16).enumerate() { + regs[i / 4] |= (u64::from(ticks) << 8 | u64::from(domain)) << (16 * (i % 4)); + } + regs +} + +/// 시간 분할 표를 정하는 함수입니다. 항목은 (도메인, 틱 수)입니다. +fn part_set_table(ctl: i64, entries: &[(u8, u8)]) -> i64 { + let r = pack_table(entries); + sys( + syscall::PART_SET_TABLE, + [ctl as u64, entries.len() as u64, r[0], r[1], r[2], r[3]], + ) as i64 +} + +/// 아직 시작하지 않은 태스크의 도메인을 정하는 함수입니다. +fn part_set_domain(ctl: i64, tcb: i64, domain: u64) -> i64 { + sys(syscall::PART_SET_DOMAIN, [ctl as u64, tcb as u64, domain, 0, 0, 0]) as i64 +} + /// IPC 반환값 묶음 구조체입니다. (x0 = 상태, x1 = 배지, x2-x5 = 수신 MR) struct IpcRet { status: i64, @@ -797,7 +825,7 @@ extern "C" fn _start(s0: u64, s1: u64, s2: u64, s3: u64, seed_info: u64) -> ! { ); check( "bootinfo slots", - cap_count > slot::CNODE && cnode_slots >= cap_count + 3 * REUSE_SLOTS, + cap_count > slot::PART_CTL && cnode_slots >= cap_count + 3 * REUSE_SLOTS, ); NEXT_SLOT.store(cap_count, Ordering::Relaxed); REUSE_BASE.store(cnode_slots - REUSE_SLOTS, Ordering::Relaxed); @@ -809,6 +837,7 @@ extern "C" fn _start(s0: u64, s1: u64, s2: u64, s3: u64, seed_info: u64) -> ! { check("slot aspace", desc(slot::ADDR_SPACE).kind == kind::ADDR_SPACE); check("slot console", desc(slot::CONSOLE).kind == kind::CONSOLE); check("slot cnode", desc(slot::CNODE).kind == kind::CNODE); + check("slot part ctl", desc(slot::PART_CTL).kind == kind::PART_CTL); let mut b = Boot { frame_size, ut_main: 0, @@ -865,6 +894,9 @@ extern "C" fn _start(s0: u64, s1: u64, s2: u64, s3: u64, seed_info: u64) -> ! { #[cfg(feature = "vault")] oracle::test_oracle(&b, seed_info); test_reserve(&b); + // 제어 케이퍼빌리티는 입력 검증이 쓰지 않으므로 입력 검증 앞에서 지움(입력 + // 검증의 표지가 끝의 표지 바로 앞에 끼므로 순서 목록에서 봉인이 뒤처지면 안 됨) + partition::seal(); // 입력을 처음 읽으면 커널이 주기적인 틱 줄을 멈추므로, 틱 줄을 세는 검증이 // 모두 끝난 뒤인 맨 마지막에 돌림 #[cfg(feature = "console-input")] @@ -1664,6 +1696,11 @@ fn test_sched_ipc_fault(b: &Boot) { // 준비 큐에는 루트뿐임(이 검증의 전제) timeslice::test(b); + // 시간 분할: 거절은 기다림 없이, 창은 위 검증이 틱 바로 뒤에 끝난 자리에서 + // 시작함(위 검증은 틱 번호가 4 이상에서 끝나므로 처음 네 틱 줄은 이미 찍힘) + partition::test_refusals(b); + partition::test_windows(b); + // 여기서 만든 태스크는 모두 끝났고 엔드포인트와 스택도 더 쓰지 않음 release_slots(first_slot); } diff --git a/userspace/root-task/src/partition.rs b/userspace/root-task/src/partition.rs new file mode 100644 index 0000000..80cf49e --- /dev/null +++ b/userspace/root-task/src/partition.rs @@ -0,0 +1,544 @@ +//! 시간 분할(도메인과 표)을 부팅 때마다 검증하는 자가 검증 모듈입니다. +//! +//! # Features +//! 세 부분으로 나뉩니다. +//! +//! - 거절: 제어 케이퍼빌리티가 아닌 슬롯, 빈 슬롯, 틀린 표, 범위 밖 도메인, +//! Stopped가 아닌 TCB(구성 전, 실행 중, 준비, 블록, 종료), 제어 케이퍼빌리티의 +//! 복사가 모두 정해진 에러로 거절되고, 거절 뒤에도 기본 표로 시스템이 계속 +//! 도는지 봅니다. 기다리는 일은 마지막의 틱 하나짜리 대기뿐입니다. +//! - 창: 아홉 틱짜리 표 하나를 한 바퀴 돌려 보고 실행 순서만으로 판정합니다. +//! EL0에는 시계가 없으므로 시간을 재지 않습니다. 루트 태스크가 기한 대기로 깨어나는 +//! 순서가 곧 시계이고, 모든 태스크가 한 로그에 남긴 글자의 순서를 비교합니다. +//! - 봉인: 제어 케이퍼빌리티를 지우면 표를 더 바꿀 수 없는지 봅니다. +//! +//! 창 검증의 표는 틱 E부터 `E:1 E+1:0 E+2:2 E+3:0 E+4:2 E+5:2 E+6:1 E+7:3 E+8:0` +//! 입니다(숫자는 도메인이고 도메인 2의 창은 두 틱). 도메인 0은 루트 태스크와 기한 2틱 대기자 H, 1은 +//! 기한 대기자 X와 X가 만든 자식 C, 그리고 X보다 나중에 기한을 거는 V, 2는 +//! 양보하는 Y1과 도는 Y2, 3은 표에 있지만 태스크가 없는 도메인, 4는 어떤 표에도 +//! 없는 도메인(Z)입니다. 표는 호출한 틱 n의 +//! 두 틱 뒤인 E = n + 2에서 0번 항목부터 효력이 생깁니다. 기한 n틱짜리 대기는 호출 +//! 때의 틱 수에 n + 1을 더한 틱에 끝나고, 한 도메인의 대기자는 그 도메인이 도는 +//! (또는 들어가는) 틱에서만 깨어납니다. +//! +//! Y1과 Y2는 다른 태스크가 그 사이에 실행된 뒤에만 로그를 남깁니다(마지막으로 돈 +//! 태스크를 적은 변수로 판단). 그래서 로그의 글자는 "누가 언제 다시 CPU를 받았는가" +//! 를 나타냅니다. +//! +//! | 틱 | 도메인 | 일어나는 일 | 로그 | +//! | --- | --- | --- | --- | +//! | E | 1 | X가 `X`를 남기고 자식을 구성해 시작시킨 뒤 양보, V도 양보, 자식이 `k`를 남기고 영영 블록, X가 `w`를 남기고 기한 1틱 대기(기한 E+2), V가 기한 2틱 대기(기한 E+3), 남는 창은 빈 채로 | X k w | +//! | E+1 | 0 | 루트의 기한(E)과 H의 기한(E+1)이 지나 둘이 깨어남. 루트가 `R`을 남기고 다시 대기(기한 E+3), H가 `h`를 남기고 영영 블록 | R h | +//! | E+2 | 2 | Y1이 `a`를 남기고 양보, Y2가 `b`를 남기고 돎 | a b | +//! | E+3 | 0 | 도는 Y2를 끊고(틱 사이에 들어와 첫 틱 면제) 큐 앞에 세움, 루트가 `r`을 남기고 대기(기한 E+5) | r | +//! | E+4 | 2 | 큐 앞의 Y2가 다시 들어와 돎(Y1이 앞서면 이때 `y`가 남음) | | +//! | E+5 | 2 | 같은 도메인의 틱: 틱의 판정으로 들어온 Y2가 끊기고 Y1이 `y`를 남김(들어올 때의 경위가 틱이 아니면 Y2가 이어서 돌아 `y`가 없음) | y | +//! | E+6 | 1 | Y1을 끊고 들어가 두 기한(E+2, E+3)이 이제야 처리됨. 나중에 건 V가 먼저 깨어나 `v`를, 이어서 X가 `x`를 남기고 둘이 번갈아 양보하며 돎 | v x | +//! | E+7 | 3 | 돌던 태스크를 끊고 태스크 없는 도메인에 들어가 빈 채로 기다림 | | +//! | E+8 | 0 | 루트의 기한(E+5)이 지나 깨어나 로그 `XkwRhabryvx`를 확인하고 정리, 기본 표 복원 | | +//! +//! 도메인 1의 두 기한은 모두 다른 도메인의 창에서 지납니다. 기한이 그 창에서 +//! 처리됐다면 X가 먼저 큐에 서서 `x`가 `v`보다 앞섭니다. E+6에서 X와 V는 블록되지 +//! 않고 서로에게 양보만 하므로 양보는 언제나 상대를 거쳐 돌아옵니다. 창이 닫힌 +//! 뒤에(E+7의 빈 창에서) 끊긴 태스크가 계속 실행된다면 양보가 상대 없이 돌아오고, +//! 그 횟수를 세어 0인지 봅니다. +//! +//! 복원 뒤에는 기한 2틱 대기를 한 번 더 하며, 그동안 도메인 2의 Y1과 어떤 표에도 +//! 없는 도메인의 Z가 한 번도 실행되지 않았는지 카운터로 확인합니다. 복원이 +//! 적용되지 않았다면 표가 이어져 도메인 2의 창이 열리므로 Y1이 돕니다. 이 +//! 대기가 기본 표에서 CPU가 노는 일 없이 끝나도록(처음 노는 때의 안내 줄이 이 +//! 검증 안에서 찍히지 않도록) 복원할 때 도메인 0에 도는 태스크를 하나 둡니다. +//! +//! 틱 하나가 호스트의 멈춤으로 통째로 건너뛰어지면 로그가 달라집니다. 그때는 +//! 정리하고 한 번 더 돌리며 `root: partition window retry` 줄을 남깁니다. 두 번 +//! 다 틀리면 실패입니다. +//! +//! # Examples +//! ```rust,ignore +//! partition::test_refusals(b); +//! partition::test_windows(b); +//! partition::seal(); +//! ``` + +use core::sync::atomic::{AtomicU64, Ordering::Relaxed}; + +use super::{ + alloc_slot, cap_delete, check, copy_here, fail, map, part_set_domain, part_set_table, + put_str, recv, release_slots, retype, retype_at, sys, tcb_configure, tcb_resume, Boot, + NEXT_SLOT, TEST_VA, +}; +use k0_abi::bootinfo::slot; +use k0_abi::{err, ipc, obj, perm, rights, syscall}; + +/// 태스크들이 남기는 글자의 로그. 인덱스는 [LEN]의 fetch_add로 받음 +static LOG: [AtomicU64; 16] = [const { AtomicU64::new(0) }; 16]; +static LEN: AtomicU64 = AtomicU64::new(0); +/// X가 구성할 자식의 TCB 슬롯과 스택 최상단 +static CHILD_TCB: AtomicU64 = AtomicU64::new(0); +static CHILD_SP: AtomicU64 = AtomicU64::new(0); +/// X가 기한 대기를 거는 엔드포인트 +static EP_X: AtomicU64 = AtomicU64::new(0); +/// H가 기한 대기를 거는 엔드포인트 +static EP_H: AtomicU64 = AtomicU64::new(0); +/// 영영 블록되는 태스크들(X의 자식, H)이 기다리는 엔드포인트 +static EP_V: AtomicU64 = AtomicU64::new(0); +/// Y1, Y2, Z의 진행(복원 뒤에 실행되지 않았는지 보는 데 씀) +static Y1_SPINS: AtomicU64 = AtomicU64::new(0); +static Y2_SPINS: AtomicU64 = AtomicU64::new(0); +/// 마지막으로 로그를 남기며 돈 Y 태스크(1 또는 2) +static LAST: AtomicU64 = AtomicU64::new(0); +static Z_SPINS: AtomicU64 = AtomicU64::new(0); +/// 도메인 1에서 마지막으로 양보한 태스크(1 = X, 2 = V) +static TURN: AtomicU64 = AtomicU64::new(0); +/// 양보가 상대를 거치지 않고 돌아온 횟수 +static ALONE: AtomicU64 = AtomicU64::new(0); + +/// 창 검증이 끝났을 때 로그에 있어야 하는 글자 +const EXPECT: &[u8] = b"XkwRhabryvx"; + +/// 창 검증의 표입니다. 항목은 (도메인, 틱 수) +const T8: [(u8, u8); 8] = [(1, 1), (0, 1), (2, 1), (0, 1), (2, 2), (1, 1), (3, 1), (0, 1)]; + +/// 태스크 스택이 놓이는 첫 그래뉼 번호(TEST_VA 기준). 사이사이는 가드로 비워 둠 +const STACK_BASE: u64 = 62; + +/// 창 검증의 태스크 여덟 개의 번호입니다. 거절 검증은 앞의 여섯 자리를 씁니다. +const X: usize = 0; +const C: usize = 1; +const Y1: usize = 2; +const Y2: usize = 3; +const Z: usize = 4; +const S0: usize = 5; +const H: usize = 6; +const V: usize = 7; + +/// 로그에 글자 하나를 남기는 함수입니다. +fn log(tag: u8) { + let i = LEN.fetch_add(1, Relaxed) as usize; + if i < LOG.len() { + LOG[i].store(u64::from(tag), Relaxed); + } +} + +/// 기한 없이 블록되는 함수입니다. 루트가 이 태스크를 지울 때까지 돌아오지 않습니다. +fn park(ep: u64) -> ! { + let _ = recv(ep as i64, 0); + loop { + core::hint::spin_loop(); + } +} + +/// 도메인 1의 기한 대기자 X의 진입점입니다. 자식 태스크를 하나 구성해 시작시키고(자식은 +/// 만든 태스크의 도메인을 물려받아야 함), 자식이 돌 때까지 양보한 뒤 기한 대기에 +/// 들어갑니다. 기한이 지나 깨어나면 `x`를 남기고 V와 번갈아 양보합니다. +extern "C" fn x_entry(_arg: u64) -> ! { + log(b'X'); + let (t, sp) = (CHILD_TCB.load(Relaxed) as i64, CHILD_SP.load(Relaxed)); + let ok = super::thread_configure(t, c_entry as usize as u64, sp) == 0 && tcb_resume(t) == 0; + super::yield_now(); + log(if ok { b'w' } else { b'e' }); + let st = recv(EP_X.load(Relaxed) as i64, ipc::timeout(1)).status; + log(if st == err::TIMEOUT { b'x' } else { b'e' }); + pair(1) +} + +/// 도메인 1의 둘째 기한 대기자 V의 진입점입니다. X가 기한을 건 뒤에 걸리도록 한 번 +/// 양보하고 기한 2틱 대기에 들어갑니다. 기한이 지나 깨어나면 `v`를 남기고 X와 +/// 번갈아 양보합니다. +extern "C" fn v_entry(_arg: u64) -> ! { + super::yield_now(); + let st = recv(EP_X.load(Relaxed) as i64, ipc::timeout(2)).status; + log(if st == err::TIMEOUT { b'v' } else { b'e' }); + pair(2) +} + +/// 같은 도메인의 두 태스크가 번갈아 양보하며 도는 함수입니다. 양보가 상대를 거치지 +/// 않고 돌아오면 [ALONE]을 올립니다. +/// +/// 둘 다 블록되지 않으므로 창 안에서는 양보가 언제나 상대에게 갑니다. 상대 없이 +/// 돌아오는 것은 창이 닫혀 큐에 서 있어야 할 태스크가 계속 실행될 때뿐입니다. +/// +/// # Arguments +/// `me` - 이 태스크의 번호(1 또는 2) +fn pair(me: u64) -> ! { + loop { + TURN.store(me, Relaxed); + super::yield_now(); + if TURN.load(Relaxed) == me { + ALONE.fetch_add(1, Relaxed); + } + } +} + +/// 거절 검증에서 기한을 걸고 블록되는 태스크의 진입점입니다. +extern "C" fn timed_entry(_arg: u64) -> ! { + let _ = recv(EP_V.load(Relaxed) as i64, ipc::timeout(100)); + loop { + core::hint::spin_loop(); + } +} + +/// 거절 검증에서 기한 없이 블록되는 태스크의 진입점입니다. +extern "C" fn parked_entry(_arg: u64) -> ! { + park(EP_V.load(Relaxed)) +} + +/// 거절 검증에서 곧바로 끝나는 태스크의 진입점입니다. +extern "C" fn exit_entry(_arg: u64) -> ! { + super::sys1(syscall::EXIT, 21); + loop { + core::hint::spin_loop(); + } +} + +/// X가 만든 자식의 진입점입니다. `k`를 남기고 영영 블록됩니다. 도메인 1에 있다면 +/// X가 양보한 자리에서 돌고, 도메인 0에 잘못 놓였다면 루트의 창에서야 돕니다. +extern "C" fn c_entry(_arg: u64) -> ! { + log(b'k'); + park(EP_V.load(Relaxed)) +} + +/// 도메인 0의 기한 대기자 H의 진입점입니다. 표를 거는 직전에 기한 2틱 대기에 +/// 들어가고, 깨어나면 `h`를 남기고 영영 블록됩니다. +extern "C" fn h_entry(_arg: u64) -> ! { + let st = recv(EP_H.load(Relaxed) as i64, ipc::timeout(2)).status; + log(if st == err::TIMEOUT { b'h' } else { b'e' }); + park(EP_V.load(Relaxed)) +} + +/// 도메인 2에서 한 번 양보하는 Y1의 진입점입니다. 다른 태스크가 돈 뒤에 다시 CPU를 +/// 받으면 `y`를 남깁니다. +extern "C" fn y1_entry(_arg: u64) -> ! { + log(b'a'); + LAST.store(1, Relaxed); + super::yield_now(); + loop { + if LAST.load(Relaxed) != 1 { + LAST.store(1, Relaxed); + log(b'y'); + } + Y1_SPINS.fetch_add(1, Relaxed); + } +} + +/// 도메인 2에서 끝없이 도는 Y2의 진입점입니다. 처음에는 `b`, 다른 태스크가 돈 뒤에 +/// 다시 CPU를 받으면 `c`를 남깁니다. +extern "C" fn y2_entry(_arg: u64) -> ! { + let mut tag = b'b'; + loop { + if LAST.load(Relaxed) != 2 { + LAST.store(2, Relaxed); + log(tag); + tag = b'c'; + } + Y2_SPINS.fetch_add(1, Relaxed); + } +} + +/// 어떤 표에도 없는 도메인의 Z의 진입점입니다. 실행되면 `z`를 남기고 돕니다. +extern "C" fn z_entry(_arg: u64) -> ! { + log(b'z'); + loop { + Z_SPINS.fetch_add(1, Relaxed); + } +} + +/// 도메인 0에서 끝없이 도는 태스크의 진입점입니다. 아무것도 남기지 않습니다. +extern "C" fn s0_entry(_arg: u64) -> ! { + loop { + core::hint::spin_loop(); + } +} + +/// 여러 번 쓰는 슬롯과 스택 묶음 구조체입니다. 두 번 도는 검증이 같은 슬롯을 다시 씁니다. +struct Stage { + ut: u64, + /// 루트가 기한 대기를 거는 엔드포인트 + wait: i64, + tcb: [u64; 8], + sp: [u64; 8], +} + +/// 슬롯과 스택을 준비하는 함수입니다. 스택은 TCB마다 프레임을 하나씩 매핑합니다. +/// +/// # Arguments +/// `b` - 부팅 때 찾은 untyped와 그래뉼 크기 +/// `count` - 만들 태스크의 수(8 이하) +fn stage(b: &Boot, count: usize) -> Stage { + let (ut, fs) = (b.ut_main, b.frame_size); + let wait = retype(ut, obj::ENDPOINT); + check("partition: wait endpoint", wait > 0); + let mut st = Stage { + ut, + wait, + tcb: [0; 8], + sp: [0; 8], + }; + for i in 0..count { + let frame = retype(ut, obj::FRAME); + let va = TEST_VA + (STACK_BASE + 2 * i as u64) * fs; + check("partition: stack", frame > 0 && map(frame, va, perm::RW) == 0); + st.sp[i] = va + fs; + st.tcb[i] = alloc_slot(); + } + st +} + +/// TCB를 만들고 구성해서 Stopped로 두는 함수입니다. +/// +/// # Arguments +/// `st` - 슬롯과 스택 +/// `i` - 태스크 번호 +/// `entry` - 진입점 +fn make(st: &Stage, i: usize, entry: extern "C" fn(u64) -> !) { + check("partition: tcb", retype_at(st.ut, obj::TCB, st.tcb[i]) == 0); + check( + "partition: configure", + super::thread_configure(st.tcb[i] as i64, entry as usize as u64, st.sp[i]) == 0, + ); +} + +/// 기한 `n`틱짜리 대기를 걸어 기한으로 끝났는지 알려 주는 함수입니다. +fn wait(st: &Stage, n: u32) -> bool { + recv(st.wait, ipc::timeout(n)).status == err::TIMEOUT +} + +/// 거절 검증입니다. 시스템 콜은 모두 기다림 없이 거절돼야 하고, 마지막에 기본 표로 +/// 계속 도는지 틱 하나짜리 대기로 봅니다. +/// +/// 이 안의 대기가 CPU를 놀리면 "처음 노는 때"의 안내 줄이 이 검증 안에서 찍혀 +/// 뒤의 검증이 기대하는 자리를 잃으므로, 기다리는 동안 도메인 0에서 도는 태스크를 +/// 하나 둡니다. +/// +/// # Arguments +/// `b` - 부팅 때 찾은 untyped와 그래뉼 크기 +pub fn test_refusals(b: &Boot) { + let first_slot = NEXT_SLOT.load(Relaxed); + let st = stage(b, 6); + let ctl = slot::PART_CTL as i64; + let empty = alloc_slot() as i64; + let (spin, stopped, inactive) = (st.tcb[0] as i64, st.tcb[1] as i64, st.tcb[2] as i64); + make(&st, 0, s0_entry); + make(&st, 1, s0_entry); + // 구성하지 않은 TCB는 Inactive + check("partition: inactive tcb", retype_at(st.ut, obj::TCB, st.tcb[2]) == 0); + + let ok = [(0u8, 1u8)]; + // 제어 케이퍼빌리티가 아닌 슬롯과 빈 슬롯 + for (what, s) in [ + ("partition: table via cnode", slot::CNODE as i64), + ("partition: table via console", slot::CONSOLE as i64), + ("partition: table via own tcb", slot::TCB as i64), + ("partition: table via endpoint", st.wait), + ("partition: table via untyped slot", st.ut as i64), + ] { + check(what, part_set_table(s, &ok) == err::BAD_CAP); + } + check("partition: table via empty slot", part_set_table(empty, &ok) == err::BAD_SLOT); + check("partition: table via slot 0", part_set_table(0, &ok) == err::BAD_SLOT); + check("partition: table via far slot", part_set_table(1 << 40, &ok) == err::BAD_SLOT); + + // 틀린 표. 호출한 태스크의 도메인(0)은 들어 있게 해서 다른 까닭이 가려지지 않게 함 + let bad = |what: &'static str, r: i64| check(what, r == err::BAD_TABLE); + bad("partition: count 0", part_set_table(ctl, &[])); + bad("partition: count 17", part_set_table(ctl, &[(0, 1); 17])); + bad("partition: zero ticks", part_set_table(ctl, &[(0, 0)])); + bad("partition: zero ticks late", part_set_table(ctl, &[(0, 1), (1, 0)])); + bad("partition: domain 8", part_set_table(ctl, &[(0, 1), (8, 1)])); + bad("partition: domain 255", part_set_table(ctl, &[(0, 1), (255, 1)])); + // 마지막 항목 뒤의 비트 하나라도 서 있으면 거절(레지스터 하나씩, 맨 끝 비트까지) + let entry0 = 1u64 << 8; + for (what, count, regs) in [ + ("partition: bit after entry 0", 1u64, [entry0 | 1 << 16, 0, 0, 0]), + ("partition: bit after entry 3", 4, [entry0 | entry0 << 16 | entry0 << 32 | entry0 << 48, 1 << 32, 0, 0]), + ("partition: bit in register 3", 1, [entry0, 0, 0, 1 << 63]), + ("partition: bit 0 of register 2", 5, [entry0 | entry0 << 16 | entry0 << 32 | entry0 << 48, entry0, 1, 0]), + ] { + let r = sys( + syscall::PART_SET_TABLE, + [ctl as u64, count, regs[0], regs[1], regs[2], regs[3]], + ) as i64; + bad(what, r); + } + // 호출한 태스크의 도메인이 없는 표 + bad("partition: no own domain", part_set_table(ctl, &[(1, 1)])); + bad("partition: no own domain 2", part_set_table(ctl, &[(1, 3), (2, 1), (7, 255)])); + + // PART_SET_DOMAIN: 범위 밖 도메인은 Stopped인 TCB에도 거절됨 + for d in [8u64, 9, 255, 256, 1 << 32, u64::MAX] { + check("partition: domain out of range", part_set_domain(ctl, stopped, d) == err::BAD_DOMAIN); + } + // Stopped가 아닌 TCB: 블록된 TCB(기한 없이, 기한을 걸고)와 끝난 TCB. 블록된 + // 채로 도메인이 바뀌면 기한 목록과 TCB의 도메인이 어긋남. 셋은 루트가 양보한 + // 사이에 차례로 돌아 블록되거나 끝남(도는 태스크를 시작시키기 전이라 곧 돌아옴) + EP_V.store(st.wait as u64, Relaxed); + let states: [(usize, extern "C" fn(u64) -> !, &'static str); 3] = [ + (3, parked_entry, "partition: set domain blocked"), + (4, timed_entry, "partition: set domain blocked with a deadline"), + (5, exit_entry, "partition: set domain dead"), + ]; + for (i, entry, _) in states { + make(&st, i, entry); + check("partition: resume for a state", tcb_resume(st.tcb[i] as i64) == 0); + } + super::yield_now(); + for (i, _, what) in states { + check(what, part_set_domain(ctl, st.tcb[i] as i64, 1) == err::BAD_STATE); + check("partition: delete after a state", cap_delete(st.tcb[i] as i64) == 0); + } + // Inactive, 루트 자신(실행 중), 준비 큐에 선 TCB + check("partition: set domain inactive", part_set_domain(ctl, inactive, 1) == err::BAD_STATE); + check( + "partition: set domain of the running tcb", + part_set_domain(ctl, slot::TCB as i64, 1) == err::BAD_STATE, + ); + check("partition: resume spinner", tcb_resume(spin) == 0); + check("partition: set domain ready", part_set_domain(ctl, spin, 1) == err::BAD_STATE); + // 틀린 케이퍼빌리티 + check("partition: domain via cnode", part_set_domain(slot::CNODE as i64, stopped, 1) == err::BAD_CAP); + check("partition: domain via tcb", part_set_domain(slot::TCB as i64, stopped, 1) == err::BAD_CAP); + check("partition: domain via empty", part_set_domain(empty, stopped, 1) == err::BAD_SLOT); + check("partition: domain of a cnode", part_set_domain(ctl, slot::CNODE as i64, 1) == err::BAD_CAP); + check("partition: domain of an endpoint", part_set_domain(ctl, st.wait, 1) == err::BAD_CAP); + check("partition: domain of an empty slot", part_set_domain(ctl, empty, 1) == err::BAD_SLOT); + + // 제어 케이퍼빌리티는 복사되지 않음 + check("partition: copy of the control", copy_here(ctl, rights::ALL, 0) == err::BAD_CAP); + check("partition: copy of the control r", copy_here(ctl, rights::R, 0) == err::BAD_CAP); + + // 거절은 아무것도 바꾸지 않았음: 기본 표로 틱 하나짜리 대기가 끝나고, 거절된 + // 표가 효력을 냈다면 도메인 0이 멈춰 이 대기는 끝나지 않음 + check("partition: still running", wait(&st, 1)); + check("partition: delete spinner", cap_delete(spin) == 0); + release_slots(first_slot); + put_str("root: partition refusal pass\n"); +} + +/// 창 검증을 한 번 돌리는 함수입니다. 로그의 순서가 맞았으면 true +/// +/// 틀렸더라도 정리는 맞았을 때와 똑같이 하고(기본 표 복원, 태스크 삭제), 복원이 +/// 적용됐는지는 로그가 맞았을 때만 봅니다. 호스트가 틱을 건너뛰어 틀린 실행은 +/// 표의 어느 자리에서 복원을 걸었는지 알 수 없어, 그 자리의 창이 Y2를 돌릴 수 +/// 있기 때문입니다. +/// +/// # Arguments +/// `st` - 슬롯과 스택 +fn one(st: &Stage) -> bool { + let ctl = slot::PART_CTL as i64; + LEN.store(0, Relaxed); + Y1_SPINS.store(0, Relaxed); + Y2_SPINS.store(0, Relaxed); + LAST.store(0, Relaxed); + Z_SPINS.store(0, Relaxed); + TURN.store(0, Relaxed); + ALONE.store(0, Relaxed); + let entries: [(usize, extern "C" fn(u64) -> !); 7] = [ + (X, x_entry), + (V, v_entry), + (Y1, y1_entry), + (Y2, y2_entry), + (Z, z_entry), + (S0, s0_entry), + (H, h_entry), + ]; + for (i, entry) in entries { + make(st, i, entry); + } + let t = |i: usize| st.tcb[i] as i64; + // X의 자식은 재분류만 해 둠(X가 구성하고 시작시킴) + check("partition: child tcb", retype_at(st.ut, obj::TCB, st.tcb[C]) == 0); + CHILD_TCB.store(st.tcb[C], Relaxed); + CHILD_SP.store(st.sp[C], Relaxed); + // 도메인은 모두 정한 뒤에 시작시킴. 시작 순서가 각 도메인 큐의 순서임 + for (i, d) in [(X, 1), (V, 1), (Y1, 2), (Y2, 2), (Z, 4)] { + check("partition: set domain", part_set_domain(ctl, t(i), d) == 0); + } + for i in [X, V, Y1, Y2, Z] { + check("partition: resume", tcb_resume(t(i)) == 0); + } + // 도메인 0의 기한 대기자 H: 기한 2틱 대기에 들어간 뒤 루트가 돌아옴. 표를 거는 + // 시스템 콜 바로 앞에서 해야 H의 기한이 루트의 기한과 같은 틱 수에서 잡힘 + check("partition: resume waiter", tcb_resume(t(H)) == 0); + super::yield_now(); + // 표를 건 시스템 콜과 대기 사이에는 시스템 콜이 없어야 함(둘 사이에 틱이 끼면 + // 기한이 한 틱 늦게 잡힘) + check("partition: set table", part_set_table(ctl, &T8) == 0); + check("partition: wait E", wait(st, 1)); + log(b'R'); + check("partition: wait E+1", wait(st, 1)); + log(b'r'); + check("partition: wait E+3", wait(st, 1)); + + let n = LEN.load(Relaxed) as usize; + let mut seen = [0u8; 16]; + for (i, c) in seen.iter_mut().enumerate().take(n.min(16)) { + *c = LOG[i].load(Relaxed) as u8; + } + // 도메인 1의 창이 닫힌 뒤에 그 태스크가 실행됐으면 양보가 상대 없이 돌아왔음 + let alone = ALONE.load(Relaxed) != 0; + let matched = n == EXPECT.len() && seen[..n] == *EXPECT && !alone; + if !matched { + put_str("root: partition window log "); + // 로그는 ASCII 글자만 담음 + put_str(core::str::from_utf8(&seen[..n.min(16)]).unwrap_or("?")); + put_str(if alone { " (a task ran outside its window)\n" } else { "\n" }); + } + + // 블록된 태스크(다른 도메인의 X의 자식 C, 도메인 0의 H), 큐에 서 있는 태스크(X와 + // V는 둘뿐인 큐의 앞과 뒤, Y2는 뒤에 Y1이 있는 큐의 앞)를 지움 + for i in [X, C, V, H, Y2] { + check("partition: delete", cap_delete(t(i)) == 0); + } + // 복원. 도는 태스크가 있어야 기본 표에서 CPU가 놀지 않음 + check("partition: resume spinner", tcb_resume(t(S0)) == 0); + check("partition: restore", part_set_table(ctl, &[(0, 1)]) == 0); + let (y1, z, len) = (Y1_SPINS.load(Relaxed), Z_SPINS.load(Relaxed), LEN.load(Relaxed)); + check("partition: wait restore", wait(st, 2)); + if matched { + check( + "partition: restore not in force", + Y1_SPINS.load(Relaxed) == y1 && Z_SPINS.load(Relaxed) == z && LEN.load(Relaxed) == len, + ); + } + // Y1은 큐의 끝에서, Z는 다른 도메인의 큐에서, S0는 도메인 0에서 지움 + for i in [Y1, Z, S0] { + check("partition: delete", cap_delete(t(i)) == 0); + } + matched +} + +/// 시간 분할 표 하나를 한 바퀴 돌리고 순서를 판정하는 함수입니다. 틀리면 한 번 +/// 더 돌립니다. +/// +/// # Arguments +/// `b` - 부팅 때 찾은 untyped와 그래뉼 크기 +pub fn test_windows(b: &Boot) { + let first_slot = NEXT_SLOT.load(Relaxed); + let st = stage(b, 8); + let ep_x = retype(st.ut, obj::ENDPOINT); + let ep_v = retype(st.ut, obj::ENDPOINT); + let ep_h = retype(st.ut, obj::ENDPOINT); + check("partition: endpoints", ep_x > 0 && ep_v > 0 && ep_h > 0); + EP_H.store(ep_h as u64, Relaxed); + EP_X.store(ep_x as u64, Relaxed); + EP_V.store(ep_v as u64, Relaxed); + if !one(&st) { + put_str("root: partition window retry\n"); + if !one(&st) { + fail("partition: window order wrong twice"); + } + } + release_slots(first_slot); + put_str("root: partition window pass\n"); +} + +/// 제어 케이퍼빌리티를 지우고 표를 더 바꿀 수 없는지 확인하는 함수입니다. +/// +/// 다른 자가 검증은 이 케이퍼빌리티를 쓰지 않으므로 지운 뒤에 돌려도 됩니다. +pub fn seal() { + let ctl = slot::PART_CTL as i64; + check("partition: seal delete", super::cap_delete(ctl) == 0); + check("partition: sealed table", part_set_table(ctl, &[(0, 1)]) == err::BAD_SLOT); + check("partition: sealed domain", part_set_domain(ctl, slot::TCB as i64, 0) == err::BAD_SLOT); + put_str("root: partition sealed\n"); +}