# quic/gunyah-hypervisor architecture

> Architecture diagram of the GitHub repository quic/gunyah-hypervisor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/quic/gunyah-hypervisor
- Repository: https://github.com/quic/gunyah-hypervisor

## Overview

##### Main Components
- Hypervisor Core: The “hyp” directory is the heart of Gunyah, and it is subdivided into many functional modules. Be sure to represent key subsystems such as:
– Boot & Initialization (e.g., hyp/core/boot)
– CPU and VCPU Management (e.g., hyp/core, hyp/vm/vcpu and hyp/vm/vcpu_*)
– Scheduling & Threading (modules under hyp/core/thread_standard, hyp/core/scheduler_fprr, hyp/core/scheduler_trivial)
– Memory Management (under hyp/mem, including address space, allocators, and page tables)
– Interrupt, IPI, and ISR Management (modules under hyp/core/irq, hyp/core/ipi, and various “interfaces/irq”)
– Debug and Diagnostics (hyp/core/debug and hyp/debug)
– Device and Peripheral Virtualization (hyp/core/vdevice, hyp/platform and portions of hyp/interfaces such as doorbell, virtio_mmio, and others)
– Hypercall/API Handling (hyp/core/api and corresponding tools/hypercalls)

##### Architecture-Specific & Platform Support Modules
- Configuration Files: The “config” directory with “arch” and “featureset” files provides architecture- and platform-specific configuration details. Show these as external configuration layers feeding into the hypervisor core.
- Architecture Subdirectories within “hyp/arch” (e.g., aarch64, armv8, cortex variants) should be represented to illustrate how the hypervisor tailors its low-level implementations to different ARM platforms.

##### Virtual Machine (VM) Subsystem
- VM Management: The “hyp/vm” directory contains submodules that manage different aspects of virtual machine operation and isolation such as “vcpu”, “psci”, “rootvm”, “arm_vm_timer”, etc. Represent the VM manager as a distinct layer interfacing with the core services.
- Emulation and Paravirtualization: Highlight components in “hyp/vdevice” for device emulation and parts of “hyp/ipc” such as doorbell and msgqueue that support inter-VM communication.

##### Interfaces and Abstraction Layers
- How the various modules (core, VM, platform) interact via these common interfaces.

##### Tools and Build Infrastructure
- Configuration and quality control files (e.g., SConstruct, .clang-format, .editorconfig, config/quality) that underline the build and deployment processes.

##### Relationships and Interactions
- Bidirectional interactions between the Hypervisor Core and the VM layer, showing that core services (e.g., scheduling, memory management) directly impact virtual machine operation.
- Connections between Interfaces and the various core components to underscore the common API contracts.
- For platform support, include directional flow from low-level hardware abstraction modules (hyp/platform) to hypervisor initialization and runtime.

##### Architectural Patterns and Design Principles
- Design as modular and layered:
– The bottom layers (hardware-specific implementations) are abstracted through interfaces.
– A core hypervisor layer provides essential services like scheduling and memory management.
– The VM layer sits on top of the core, managing guest VMs and leveraging the underlying hardware virtualization features.
- Separation between generic hypervisor services and architecture-specific implementations, reinforcing portability and minimal trusted computing base ideas.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration & Platform"
      Config["Configuration (config)"]:::config
      Arch["Architecture Specific (hyp/arch)"]:::arch
      Platform["Platform Abstraction"]:::arch
    end

    subgraph "Hypervisor Core"
      Boot["Boot & Initialization"]:::core
      CPUMgmt["CPU & VCPU Management"]:::core
      Sched["Scheduling & Threading"]:::core
      MemMgmt["Memory Management"]:::core
      IRQ["Interrupt, IPI & ISR Management"]:::core
      Debug["Debug & Diagnostics"]:::core
      DeviceVirt["Device & Peripheral Virtualization"]:::core
      Hypercall["Hypercall/API Handling"]:::core
    end

    subgraph "VM Subsystem"
      VMSubsys["VM Manager"]:::vm
      EmuPV["Emulation & Paravirtualization"]:::vm
    end

    subgraph "Interfaces & Abstractions"
      Interfaces["Interfaces/APIs"]:::interface
    end

    subgraph "Tools & Build Infrastructure"
      Tools["Tools & Build Infrastructure"]:::tool
    end

    %% Connections from Configuration layer to Hypervisor Core
    Config -->|"configures"| Boot
    Arch -->|"supports"| Boot
    Platform -->|"interfaces with"| DeviceVirt

    %% Hypervisor Core internal flow
    Boot --> CPUMgmt
    CPUMgmt --> Sched
    Sched --> MemMgmt
    MemMgmt --> IRQ
    IRQ --> Debug
    Debug --> DeviceVirt
    DeviceVirt --> Hypercall

    %% Core and VM Subsystem bidirectional interactions
    CPUMgmt <--> VMSubsys
    Sched <--> VMSubsys
    MemMgmt <--> VMSubsys

    %% Interfaces linking to core and VM components
    Interfaces --- CPUMgmt
    Interfaces --- Sched
    Interfaces --- MemMgmt
    Interfaces --- IRQ
    Interfaces --- Hypercall
    Interfaces --- EmuPV

    %% Tools influencing Hypercall handling
    Tools -->|"generates"| Hypercall

    %% Click Events
    click Config "https://github.com/quic/gunyah-hypervisor/tree/develop/config"
    click Arch "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/arch"
    click Platform "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/platform"
    click Boot "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/core/boot"
    click CPUMgmt "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/core"
    click Sched "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/core/thread_standard"
    click MemMgmt "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/mem"
    click IRQ "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/core/irq"
    click Debug "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/core/debug"
    click DeviceVirt "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/core/vdevice"
    click Hypercall "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/core/api"
    click VMSubsys "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/vm"
    click EmuPV "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/ipc"
    click Interfaces "https://github.com/quic/gunyah-hypervisor/tree/develop/hyp/interfaces"
    click Tools "https://github.com/quic/gunyah-hypervisor/tree/develop/tools"

    %% Styles
    classDef config fill:#fde2e4,stroke:#ffbac1,stroke-width:2px;
    classDef arch fill:#bbdefb,stroke:#1e88e5,stroke-width:2px;
    classDef core fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef vm fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
    classDef interface fill:#d1c4e9,stroke:#673ab7,stroke-width:2px;
    classDef tool fill:#ffccbc,stroke:#e64a19,stroke-width:2px;
```
