Skip to content

jounathaen

Jonathan edited this page Apr 22, 2026 · 2 revisions

Network Threads—Lifetime and interactions

The following (pseudo-) sequence diagram depicts the initialization and interactions of the network threads:

sequenceDiagram
    participant Main as Main Thread

    participant KVNetDev as VirtioNetImpl<br>(VirtioNetPciDevice)
    box  NW Threads
    participant SendThread
    participant ReceiveThread
    end
    participant Kernel

    activate Main
    Main ->>+KVNetDev: new
    KVNetDev-->>Main: 
    Main->>KVNetDev: setup

    KVNetDev->>+SendThread: start_network_threads

    KVNetDev->>+ReceiveThread: start_network_threads

    KVNetDev-->>-Main: 

    SendThread->>-SendThread: recv()
    ReceiveThread->>-ReceiveThread: recv()


    Note over Main,KVNetDev: VM initialized
    Main->>+Kernel: run()

    loop PCI negotiation
        Kernel->>Main: write_status
        Main->>+KVNetDev: 
        KVNetDev-->>Main: status response
        Main-->>Kernel: 

    end
    KVNetDev->>+SendThread: ThreadControlMsg::Start
    KVNetDev->>+ReceiveThread: ThreadControlMsg::Start
    KVNetDev-->-Main: 

    loop data exchange
        Kernel->>SendThread: virtio send data
        ReceiveThread->>Kernel: virtio receive data
    end


    Kernel-->>-Main: Exit

    Note over Main,KVNetDev: Terminate Threads:

    Main ->>+KVNetDev: drop
    KVNetDev->>SendThread: ThreadControlMsg::Abort
    deactivate SendThread
    KVNetDev->>ReceiveThread: ThreadControlMsg::Abort
    deactivate ReceiveThread
    KVNetDev-->>-Main: 
    deactivate Main
Loading

Clone this wiki locally