# sched-ext/scx architecture

> Architecture diagram of the GitHub repository sched-ext/scx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sched-ext/scx
- Repository: https://github.com/sched-ext/scx

## Overview

##### Main Components Identification

The system consists of these primary components:
- Kernel Space (BPF Schedulers)
- User Space (Rust/C Implementations)
- Support Libraries
- Tools and Utilities
- Service Management

**┌─────────────────────────────────────────────────────────┐**
- Linux Kernel                        │
- ┌─────────────────┐        ┌────────────────────┐     │
- sched_ext     │◄─────►│    BPF Runtime     │     │
- ┘        └────────────────────┘     │
- ┘
- ▲

**┌─────────────────────────────────────────────────────────┐**
- User Space                           │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────┐   │
- Schedulers  │  │  Libraries   │  │    Tools     │   │
- ┘  └──────────────┘  └──────────────┘   │
- ┘

**┌────────────────────────────────────────────┐**
- Schedulers                    │
- ┌──────────┐            ┌─────────────┐  │
- C      │            │    Rust     │  │
- Schedulers│            │ Schedulers  │  │
- ┘            └─────────────┘  │
- ┘

**┌────────────────────────────────────────┐**
- Support Libraries           │
- ┌─────────────┐    ┌──────────────┐  │
- scx_utils  │    │  libbpf      │  │
- ┘    └──────────────┘  │
- ┘

##### Component Relationships

- BPF programs loading into kernel (↑)
- Library dependencies (→)
- Service management connections (↔)
- Data flow between components (⇢)

##### Additional Details

Callouts for:
- Build system (meson)
- Configuration management
- Monitoring tools (scxtop)
- Service management (systemd/OpenRC)

##### Implementation Notes

Annotations for:
- BPF program loading paths
- Scheduler registration process
- Statistics collection points
- Configuration loading points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Kernel["Linux Kernel"]
        direction TB
        SCHED["sched_ext"]
        BPF_RT["BPF Runtime"]
        SCHED <--> BPF_RT
    end

    subgraph UserSpace["User Space Components"]
        direction TB
        
        subgraph Schedulers["Scheduler Implementations"]
            direction TB
            C_SCHED["C Schedulers"]:::scheduler
            RUST_SCHED["Rust Schedulers"]:::scheduler
        end

        subgraph Libraries["Support Libraries"]
            direction TB
            SCX_UTILS["SCX Utils"]:::lib
            RUSTLAND["Rustland Core"]:::lib
            COMMON_LIB["Common Library"]:::lib
            STATS_LIB["Stats Library"]:::lib
        end

        subgraph Services["Service Management"]
            direction TB
            SYSTEMD["Systemd"]:::service
            OPENRC["OpenRC"]:::service
            LOADER["Loader Service"]:::service
        end

        subgraph Tools["Tools & Utilities"]
            direction TB
            SCXTOP["System Monitor"]:::tool
            SCRIPTS["Scripts"]:::tool
        end

        subgraph Build["Build System"]
            direction TB
            MESON_SCRIPTS["Build Scripts"]:::build
            MESON_CONFIG["Main Build Config"]:::build
        end

        subgraph BPF_Headers["BPF Interface"]
            direction TB
            SCX_HEADERS["SCX Headers"]:::header
            BPF_COMMON["Common BPF Headers"]:::header
        end
    end

    %% Relationships
    Kernel <--> UserSpace
    Schedulers --> BPF_Headers
    Libraries --> Schedulers
    Services --> Schedulers
    Tools --> Services
    Build --> Schedulers
    Build --> Libraries
    STATS_LIB --> Tools

    %% Click Events
    click C_SCHED "https://github.com/sched-ext/scx/tree/main/scheds/c"
    click RUST_SCHED "https://github.com/sched-ext/scx/tree/main/scheds/rust"
    click SCX_UTILS "https://github.com/sched-ext/scx/tree/main/rust/scx_utils"
    click RUSTLAND "https://github.com/sched-ext/scx/tree/main/rust/scx_rustland_core"
    click COMMON_LIB "https://github.com/sched-ext/scx/tree/main/lib"
    click STATS_LIB "https://github.com/sched-ext/scx/tree/main/rust/scx_stats"
    click SYSTEMD "https://github.com/sched-ext/scx/tree/main/services/systemd"
    click OPENRC "https://github.com/sched-ext/scx/tree/main/services/openrc"
    click LOADER "https://github.com/sched-ext/scx/tree/main/rust/scx_loader"
    click SCXTOP "https://github.com/sched-ext/scx/tree/main/tools/scxtop"
    click SCRIPTS "https://github.com/sched-ext/scx/tree/main/scripts"
    click MESON_SCRIPTS "https://github.com/sched-ext/scx/tree/main/meson-scripts"
    click MESON_CONFIG "https://github.com/sched-ext/scx/blob/main/meson.build"
    click SCX_HEADERS "https://github.com/sched-ext/scx/tree/main/scheds/include/scx"
    click BPF_COMMON "https://github.com/sched-ext/scx/blob/main/scheds/include/scx/common.bpf.h"

    %% Styles
    classDef scheduler fill:#f9f,stroke:#333
    classDef lib fill:#ff9,stroke:#333
    classDef service fill:#9cf,stroke:#333
    classDef tool fill:#fc9,stroke:#333
    classDef build fill:#cfc,stroke:#333
    classDef header fill:#ccf,stroke:#333

    %% Legend
    subgraph Legend
        direction TB
        L1["Scheduler"]:::scheduler
        L2["Library"]:::lib
        L3["Service"]:::service
        L4["Tool"]:::tool
        L5["Build"]:::build
        L6["Header"]:::header
    end
```
