mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #238] feat(sandbox): bind running Firecracker threads to host CPUs #279
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#279
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/AgentENV/pull/238
Author: @emailcannotbeblank
Created: 9/1/2026
Status: 🔄 Open
Base:
main← Head:feature/bind-cpu-v2📝 Commits (1)
9d25c73feat(sandbox): support live CPU affinity binding📊 Changes
28 files changed (+1871 additions, -5 deletions)
View changed files
📝
Cargo.lock(+18 -0)📝
Cargo.toml(+1 -0)📝
crates/aenv/src/client/sandboxes.rs(+76 -2)➕
crates/aenv/src/commands/cpu_bind.rs(+49 -0)📝
crates/aenv/src/commands/mod.rs(+1 -0)📝
crates/aenv/src/main.rs(+3 -0)📝
docs/src/concepts/sandboxes/working.md(+45 -0)📝
docs/src/getting-started/aenv-cli/sandboxes.md(+22 -0)📝
services/gateway/internal/routes.go(+1 -0)📝
services/gateway/internal/routes_test.go(+3 -0)📝
services/gateway/internal/server_test.go(+59 -0)📝
src/api/generated/src/apis/admin.rs(+34 -0)📝
src/api/generated/src/models.rs(+353 -0)📝
src/api/generated/src/server/mod.rs(+224 -0)📝
src/api/impls/admin.rs(+64 -0)📝
src/api/impls/sandbox.rs(+33 -1)📝
src/api/openapi.yml(+93 -0)📝
src/orchestrator/mod.rs(+6 -0)📝
src/orchestrator/service.rs(+106 -0)📝
src/orchestrator/tests.rs(+107 -0)...and 8 more files
📄 Description
What
Add runtime CPU-affinity control for running Firecracker sandboxes.
POST /sandboxes/{sandboxID}/cpu-affinityAPI.aenv cpu-bind <sandbox-id> --vcpu <list|*> --core <list>.0-10:2.*, toonline host logical CPUs.
fails.
Why
Hardware architects use AgentENV sandboxes for processor benchmarking and
workload characterization. Runtime CPU affinity supports three main use cases:
to LLC, NUMA, and SMT topology to improve long-running workload performance.
host CPUs, reducing run-to-run noise in PMU counters, IPC, cache-miss rates,
and latency measurements.
CPU, or on SMT siblings of one physical core, to evaluate oversubscription
behavior.
Related issue
Closes #228
Scope and non-goals
Included:
public API.
user documentation.
Non-goals:
abstractions introduced here in a follow-up.
Design and behavior changes
The orchestrator accepts only running sandboxes, locks the backend while the
blocking affinity operation runs, and keeps the operation cancellation-safe so
pause, snapshot, or delete cannot replace the Firecracker process midway.
The sandbox layer scans
/proc/<pid>/task, identifies vCPU threads by theirfc_vcpu Nnames, and checks thread start times around numeric-TID syscalls tonarrow the TID-reuse window. Input length, expansion, value count, and CPU IDs
are bounded before allocation. Requested offline CPUs are ignored; an empty
online intersection is rejected before any affinity change.
Before applying changes, the implementation records every target's original
affinity. It then updates and reads back each thread one at a time. A failure or
kernel mismatch triggers best-effort rollback of all threads already changed.
Compatibility and operations
OpenAPI-generated server types. Existing endpoints are unchanged.
by default and protected by the deployment API key; there is no separate
feature flag.
kernel state and is not persisted.
API, but an already-applied affinity remains until changed or the Firecracker
process exits.
/procandpermission to call
sched_setaffinityon Firecracker threads. No new port orruntime dependency is introduced. Supported logical CPU IDs are 0-1023.
Validation
make fmtmake clippymake test-unitmake -C services test(required whenservices/changes)maketargetCommands and results:
Skipped checks and reasons:
make agentenv-server: generated server changes and their OpenAPI source arecommitted, but final regeneration could not be rerun because Java is not
installed in the validation environment.
than changing a request-processing hot path.
environment.
Risks and reviewer notes
the endpoint is therefore admin-only.
exclusive access. All selected threads receive the same host CPU set.
*selects threads present when the request is handled; it is not a policyfor threads created later.
Firecracker process.
checks before and after affinity reads narrow that window.
Suggested review order:
src/sandbox/cpu_affinity.rsfor parsing, thread selection, verification,and rollback.
src/orchestrator/service.rsfor lifecycle locking and PID handling.src/api/openapi.ymlandsrc/api/impls/admin.rsfor the admin API.services/gateway/internal/server.goand theaenvclient/command forrouting and user-facing behavior.
Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.