Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f0edc5f
feat(async): add task::kill() for force-terminating async tasks
ytakano Jun 16, 2026
a96d470
test(async): add test_task_kill application for task::kill()
ytakano Jun 16, 2026
c055862
test(task): verify resource cleanup after kill()
ytakano Jun 16, 2026
4769720
fix(display): exit early when no framebuffer is available
ytakano Jun 16, 2026
adb1647
fix(sleep): release state lock before waker.wake() to prevent deadlock
ytakano Jun 16, 2026
330623d
Revert "fix(display): exit early when no framebuffer is available"
ytakano Jun 16, 2026
6130429
Potential fix for pull request finding
ytakano Jun 16, 2026
e0b3363
fix(task): safely kill Preempted tasks via kill_pending deferred term…
ytakano Jun 16, 2026
17b04f0
Update task kill semantics tests and add repository guidelines
ytakano Jun 17, 2026
80d5ba8
Improve task kill resource cleanup and scheduling safety
ytakano Jun 17, 2026
f9ba428
Handle deferred kill cleanup for preempted tasks
ytakano Jun 17, 2026
62c108a
fix: detach service tasks in awkernel_services
ytakano Jun 17, 2026
d8d363c
Fix task kill races
ytakano Jun 17, 2026
ed4722a
Add SPIN kill test variant
ytakano Jun 17, 2026
dc7dc66
Add async scheduler testing skill
ytakano Jun 17, 2026
0699b69
add CLAUDE.md
ytakano Jun 17, 2026
fa5cb14
Fix clippy warnings without logic changes
ytakano Jun 17, 2026
06bfe79
Await service task spawns before dropping handles
ytakano Jun 17, 2026
9894193
Handle missing preemption targets in schedulers
ytakano Jun 17, 2026
8550c73
fmt
ytakano Jun 17, 2026
799dad6
Cover preempted kill race in SPIN
ytakano Jun 17, 2026
e99f32e
fmt
ytakano Jun 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .agents/skills/awkernel-async-scheduler-testing/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
name: awkernel-async-scheduler-testing
description: Use when testing or debugging Awkernel async/await task scheduler behavior, including task kill, preemption, sleep/wake, timer interactions, QEMU reproduction, and SPIN model checking under specification/awkernel_async_lib/src/task/preemptive_spin.
---

# Awkernel Async Scheduler Testing

Use this skill when changing or reviewing `awkernel_async_lib` task scheduling behavior: `kill()`, preemption, sleep/wake, timer wakeups, task registry removal, or scheduler queues.

## Core workflow

1. Identify whether the issue is in runtime code, model code, or a test app.
2. Prefer `make` for kernel builds; do not replace kernel validation with direct `cargo` commands.
3. Reproduce on the smallest layer first, then escalate:
- Rust/library check for compile-level regressions.
- SPIN for scheduler state-machine properties.
- RELEASE QEMU for real kernel behavior and shell responsiveness.
4. Treat shell stuck as a scheduler/timer symptom, not necessarily a shell bug.

## Build and QEMU commands

Use RELEASE builds for QEMU experiments:

```sh
make x86_64 RELEASE=1
make qemu-x86_64_nographic RELEASE=1
```

For kill-specific QEMU testing:

```sh
make x86_64 RELEASE=1 OPT='--release --features test_task_kill'
make qemu-x86_64_nographic RELEASE=1
```

After feature tests complete, verify the shell still responds with a small expression such as `(+ 7 8)`. Intentional panic logs from panic-specific tests are not automatically failures; check the PASS/FAIL lines after the panic.

## SPIN model checking

The preemptive scheduler model lives in:

```text
specification/awkernel_async_lib/src/task/preemptive_spin
```

Use the normal LTL tests for non-kill scheduler behavior:

```sh
make -C specification/awkernel_async_lib/src/task/preemptive_spin clean run
```

Use the kill-specific reduced model for kill behavior:

```sh
make -C specification/awkernel_async_lib/src/task/preemptive_spin clean kill-test
```

`kill-test` enables `KILL_TEST`, uses a smaller task set, and should keep killer/kill-only state out of normal `make run`. Do not run `clean run` and `clean kill-test` concurrently in the same directory; both targets delete and regenerate `pan.*` files.

## Scheduler failure patterns to check

- Stale task IDs: a running snapshot may reference a task removed from the registry by `kill()`.
- Terminal tasks: `Terminated` and `Panicked` tasks must not be requeued or selected for preemption.
- Deferred kill: `Preempted` tasks should set `kill_pending` and terminate at a safe await/resume point.
- Lock nesting: watch for self-deadlock around sleep/timer wake paths and global scheduler locks.
- Pending preemption: queues may contain tasks that become terminal before the interrupt handler consumes them.

## Generated files and commits

Do not commit SPIN or QEMU generated artifacts unless explicitly requested:

```text
pan
pan.*
*.trail
*_spin_nvr.tmp
kill-test-*.log
qemu-*.log
```

When committing scheduler work, include only source/model/test files relevant to the change. Leave unrelated dirty files untouched.
1 change: 1 addition & 0 deletions .claude/skills/awkernel-async-scheduler-testing
1 change: 1 addition & 0 deletions .codex/skills/awkernel-async-scheduler-testing
54 changes: 54 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Repository Guidelines

## Project Structure & Module Organization
This repository is a Rust workspace (`Cargo.toml`) with these primary areas:

- `kernel/`: core OS kernel crate.
- `awkernel_lib/`, `awkernel_async_lib/`, `awkernel_drivers/`: shared kernel/runtime infrastructure.
- `awkernel_aarch64/`, `x86bootdisk/`: architecture/platform support helpers.
- `userland/`: user-space library and app support.
- `applications/`: runnable samples/tests (`applications/tests/*`) and app crates.
- `smoltcp/`: network stack crate used by kernel/user code.
- `mdbook/`: documentation source; `docs/` stores generated docs output.
- `specification/`: design and implementation notes.
- `docker/`, `scripts/`, `targets/`, `misc/`: tooling, build config, boot artifacts, and platform files.

## Build, Test, and Development Commands
- `make x86_64 [RELEASE=1]`: build x86_64 kernel image.
- `make aarch64 BSP=<raspi3|raspi4|raspi5|aarch64_virt> [RELEASE=1]`: build AArch64 targets.
- `make riscv32` / `make riscv64`: build RISC-V targets.
- `make qemu-x86_64`, `make qemu-aarch64-virt`, `make qemu-raspi3`: boot in QEMU.
- `make check`: run check across kernel targets and std crates.
- `make clippy`: run lints for major targets.
- `make test`: run `test_awkernel_lib`, `test_awkernel_async_lib`, `test_awkernel_drivers`, `test_smoltcp`, `test_rd_gen_to_dags`.
- `make docs`: build mdBook docs.
- `make fmt`: run `cargo fmt`.
- Direct aliases are in `.cargo/config.toml` (examples: `cargo +nightly-2026-06-13 test_awkernel_lib`, `cargo +nightly-2026-06-13 x86`, `cargo +nightly-2026-06-13 doc_x86`).

## Coding Style & Naming Conventions
- Rust 2021 edition, default rustfmt formatting (`cargo fmt`).
- Use 4-space indentation and standard Rust naming:
- crates, modules, functions: `snake_case`.
- types/traits: `CamelCase`.
- test functions: `test_*`.
- Prefer small, explicit feature-gated modules; avoid broad default features.
- Keep architecture-specific code separated by crate and feature flags (`x86`, `aarch64`, `rv32`, `rv64`, `std`).

## Testing Guidelines
- Unit tests are in `mod tests` blocks under crate source and can be run per-package through cargo aliases (e.g., `cargo +nightly-2026-06-13 test_awkernel_lib`).
- Integration-style workload tests are under `applications/tests/*`, typically invoked through the general `make test` suite.
- For behavior validation requiring emulation, reproduce with matching QEMU target command and board (`qemu-...` targets).
- Use `cargo +nightly-2026-06-13 clippy_x86` / `clippy_rv64` style aliases for target-specific linting.

## Commit & Pull Request Guidelines
- Use Conventional Commit style observed in history: `type(scope): short summary` (examples: `feat(async): ...`, `fix(task): ...`, `test(task): ...`).
- Keep each commit focused to one logical change.
- PRs should include:
- target architecture and commands run (`make`, `cargo`, QEMU target),
- rationale for API/behavior changes,
- test commands and results.
- Link related issues when applicable and call out platform impact (`x86_64`, `aarch64`, `riscv32`, `riscv64`).

## Security & Environment Notes
- Repository uses nightly toolchain; ensure `rustup toolchain install nightly-2026-06-13` and target support are in place before builds.
- x86 UEFI QEMU flows require `OVMF_PATH` to point at valid `code.fd` and `vars.fd` locations.
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CLAUDE.md

@AGENTS.md
6 changes: 3 additions & 3 deletions applications/awkernel_services/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ const BUFFERED_LOGGER_NAME: &str = "[Awkernel] buffered logger service";
const DISPLAY_SERVICE_NAME: &str = "[Awkernel] display service";

pub async fn run() {
awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
BUFFERED_LOGGER_NAME.into(),
buffered_logger::run(),
awkernel_async_lib::scheduler::SchedulerType::PrioritizedFIFO(0),
)
.await;

awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
NETWORK_SERVICE_NAME.into(),
network_service::run(),
awkernel_async_lib::scheduler::SchedulerType::PrioritizedFIFO(0),
)
.await;

awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
DISPLAY_SERVICE_NAME.into(),
awkernel_display::run(),
awkernel_async_lib::scheduler::SchedulerType::PrioritizedFIFO(0),
Expand Down
10 changes: 5 additions & 5 deletions applications/awkernel_services/src/network_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ type ChanProtoInterruptHandlerDual = Chan<(), <ProtoInterruptHandler as HasDual>
pub async fn run() {
log::info!("Starting {}.", crate::NETWORK_SERVICE_NAME);

awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
GARBAGE_COLLECTOR_NAME.into(),
tcp_garbage_collector(),
SchedulerType::PrioritizedFIFO(0),
)
.await;

awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
NETWORK_IF_POLLER_NAME.into(),
network_interface_poller(),
SchedulerType::PrioritizedFIFO(0),
Expand Down Expand Up @@ -137,7 +137,7 @@ async fn spawn_handlers(
if_status.device_name,
);

awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
name.into(),
interrupt_handler(if_status.interface_id, irq, server),
SchedulerType::PrioritizedFIFO(0),
Expand All @@ -155,7 +155,7 @@ async fn spawn_handlers(
if_status.device_name,
);

awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
name.into(),
poll_handler(if_status.interface_id, server),
SchedulerType::PrioritizedFIFO(0),
Expand All @@ -173,7 +173,7 @@ async fn spawn_handlers(
if_status.device_name,
);

awkernel_async_lib::spawn(
let _ = awkernel_async_lib::spawn(
name.into(),
tick_handler(if_status.interface_id, tick_msec, server),
SchedulerType::PrioritizedFIFO(0),
Expand Down
15 changes: 15 additions & 0 deletions applications/tests/test_task_kill/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "test_task_kill"
version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4"

[dependencies.awkernel_async_lib]
path = "../../../awkernel_async_lib"
default-features = false

[dependencies.awkernel_lib]
path = "../../../awkernel_lib"
default-features = false
Loading
Loading