AxVCpu
AxVCpu is a virtual CPU abstraction library for ArceOS hypervisors, providing a unified, architecture-independent interface for managing virtual CPUs in hypervisor environments.
Features
- Architecture Agnostic: Unified interface supporting multiple architectures (x86_64, ARM64, RISC-V)
- State Management: Robust VCpu lifecycle management with clear state transitions
- Per-CPU Virtualization: Efficient per-CPU state management and resource isolation
- Hardware Abstraction: Clean separation between architecture-specific and common operations
- CPU Affinity: Support for CPU binding and affinity management
- Exit Handling: Comprehensive VM exit reason handling and processing
Architecture
AxVCpu follows a layered architecture design:
┌─────────────────────────────────────────┐
│ Application Layer │ ← Hypervisor/VMM
├─────────────────────────────────────────┤
│ AxVCpu Core Interface │ ← Main API
├─────────────────────────────────────────┤
│ Architecture Abstraction │ ← AxArchVCpu trait
├─────────────────────────────────────────┤
│ Hardware Abstraction Layer │ ← AxVCpuHal trait
├─────────────────────────────────────────┤
│ Architecture-Specific Backends │ ← x86_64, ARM64, etc.
└─────────────────────────────────────────┘
Core Components
VCpu State Machine
Created → Free → Ready → Running → Blocked
↓ ↓ ↓ ↓ ↓
└───────┴──────┴────────┴────────┘
Invalid
- Created: Initial state after VCpu creation
- Free: Initialized and ready to be bound to a physical CPU
- Ready: Bound to a physical CPU and ready for execution
- Running: Currently executing on a physical CPU
- Blocked: Execution blocked (waiting for I/O, etc.)
- Invalid: Error state when transitions fail
Key Traits
AxArchVCpu: Architecture-specific VCpu implementation interfaceAxVCpuHal: Hardware abstraction layer for hypervisor operationsAxVCpuExitReason: VM exit reason enumeration and handling
Quick Start
Add AxVCpu to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use ;
// Mock implementation for example
;
// Create a new virtual CPU
let vcpu = new?;
// Check VCpu state
assert_eq!;
// Setup the VCpu
vcpu.setup?;
// Bind to current physical CPU and run
vcpu.bind?;
let exit_reason = vcpu.run?;
// Handle VM exit
match exit_reason
Architecture Implementation
To implement AxVCpu for a new architecture:
use AxArchVCpu;
Related Projects
- ArceOS - A component-based OS kernel
- AxVisor - A hypervisor implemented based on the ArceOS unikernel framework.
License
This project is licensed under multiple licenses. You may choose to use this project under any of the following licenses:
- GPL-3.0-or-later - GNU General Public License v3.0 or later
- Apache-2.0 - Apache License 2.0
- MulanPubL-2.0 - Mulan Public License 2.0
- MulanPSL2 - Mulan Permissive Software License v2
You may use this software under the terms of any of these licenses at your option.