User:Paolo Bonzini/Machine init sequence: Difference between revisions

From QEMU
Line 1: Line 1:
== Basic phases ==
== Basic phases ==
* PHASE_NO_MACHINE:
;PHASE_NO_MACHINE:
** Only backends can be created
:* Only backends can be created
** No machines have compat props that affect the backends, so that's good
:* No machines have compat props that affect the backends, so that's good
* machine-set command
:machine-set command moves to the next step
* PHASE_MACHINE_CREATED:
 
** Backends can be connected to on-board devices (how?)
;PHASE_MACHINE_CREATED:
** Machine options include -smp, -m, -boot, -semihosting-config, -cpu
:* Backends can be connected to on-board devices (how?)
* accel-set (can only be invoked again if it fails)
:* Machine options include -smp, -m, -boot, -semihosting-config, -cpu
* PHASE_ACCEL_CREATED:
:accel-set (can only be invoked again if it fails) moves to the next step
** migration_object_init() can be called
 
** plugins can be loaded
;PHASE_ACCEL_CREATED:
** memory can be attached to the machine
:* migration_object_init() can be called
* 1) set-numa-options stays in PHASE_ACCEL_CREATED (x-exit-preconfig then goes direcly to PHASE_MACHINE_READY)
:* plugins can be loaded
* 2) machine-set-memory goes to PHASE_MACHINE_INITIALIZED
:* memory can be attached to the machine
* PHASE_MACHINE_INITIALIZED
:set-numa-options stays in PHASE_ACCEL_CREATED (x-exit-preconfig then goes direcly to PHASE_MACHINE_READY)
** Devices can be created
:machine-set-memory goes to PHASE_MACHINE_INITIALIZED
* finish-machine-init, cont, migrate_incoming, x-exit-preconfig
 
* PHASE_MACHINE_READY
;PHASE_MACHINE_INITIALIZED
** everything after qdev_machine_creation_done()
:* Devices can be created
:finish-machine-init, cont, migrate_incoming, x-exit-preconfig move to the next step
 
;PHASE_MACHINE_READY
:* everything after qdev_machine_creation_done()


== Current machine init sequence ==
== Current machine init sequence ==

Revision as of 16:31, 27 October 2020

Basic phases

PHASE_NO_MACHINE
  • Only backends can be created
  • No machines have compat props that affect the backends, so that's good
machine-set command moves to the next step
PHASE_MACHINE_CREATED
  • Backends can be connected to on-board devices (how?)
  • Machine options include -smp, -m, -boot, -semihosting-config, -cpu
accel-set (can only be invoked again if it fails) moves to the next step
PHASE_ACCEL_CREATED
  • migration_object_init() can be called
  • plugins can be loaded
  • memory can be attached to the machine
set-numa-options stays in PHASE_ACCEL_CREATED (x-exit-preconfig then goes direcly to PHASE_MACHINE_READY)
machine-set-memory goes to PHASE_MACHINE_INITIALIZED
PHASE_MACHINE_INITIALIZED
  • Devices can be created
finish-machine-init, cont, migrate_incoming, x-exit-preconfig move to the next step
PHASE_MACHINE_READY
  • everything after qdev_machine_creation_done()

Current machine init sequence

Up to CHECKPOINT_INIT

  • Runstate is RUN_STATE_PRECONFIG or RUN_STATE_INMIGRATE
  • Get machine_class
  • Set machine compat props
  • set_memory_options
  • Options: -global
  • replay_configure
  • Options: -rtc
  • Option: -pidfile
  • qemu_init_main_loop
  • Options: -sandbox, -name, -add-fd
  • current_machine is created
  • Options: -trace, -L
  • Options: -smp
  • Options: -mem-prealloc (requires current_machine->smp.cpus, but could look at -smp cpus directly)
  • Options: -plugin (requires -smp)
  • Handle default devices
    • Default device check (needs machine_class)
    • A bunch of checks for -daemonize
    • Add default devices to device_configs
  • Create backends
    • Create displays
    • Create early objects
    • Options: -spice
    • Create chardevs
    • Create fsdevs
    • Create audiodevs
  • Machine properties set
  • Accelerators created and properties set
  • migration_object_init
    • Wants current_machine->enforce_config_section, but that part can be done later though
  • Initialize qtest server (QOMify)
  • Parse bootorder and -machine kernel_filename/initrd_filename/kernel_cmdline
  • cpu_timers_init() (can be done earlier)
  • Create default network (move with other device_configs operations)
  • net_init_clients
  • Create late objects
  • blk_mig_init, ram_mig_init, dirty_bitmap_mig_init (move to migration_object_init())
  • Create monitors (why so late?)
  • Create backends for -serial/-parallel/-debugcon
  • get_default_vga_model, select_vgahw, select_watchdog

After CHECKPOINT_INIT

  • qdev_machine_init()
    • Only creates /machine/peripheral and /machine/peripheral-anon
  • Determine ram_size
  • parse_numa_opts() -> set_numa_options()
  • Preconfig monitor
    • set_numa_options (same as -numa but more powerful)

RUN_STATE_PRELAUNCH

  • machine_run_board_init(current_machine)
    • On-board devices are created
    • Requires accelerator to be initialized
  • Devices cannot be realized before this point (buses don't exist)
  • Start VM
    • loadvm or incoming migration
    • Otherwise, vm_start()

First attempt at cleaned up sequence

Early option parsing

  • Runstate is RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE
  • Desugaring: -mem-prealloc, -watchdog
  • Options: -pidfile, -sandbox, -name, -add-fd, -trace, -L, -incoming defer
  • replay_configure

Early initialization

  • qemu_init_main_loop()
  • cpu_timers_init()

Command-line processing part one

  • Options: -global, -rtc
  • Get machine_class
  • Set machine compat props
  • Handle default devices
    • Default device check (needs machine_class but not MS)
    • A bunch of checks for -daemonize
    • Add default devices to device_configs
  • Create default network
  • Create backends
    • Create displays
    • Create early objects
    • Options: -spice
    • Create chardevs
    • Create fsdevs
    • Create audiodevs
  • Initialize qtest server

Machine creation

  • set_memory_options
  • current_machine is created
    • qdev_machine_init()
  • Options: -smp
  • Machine properties set
    • set current_migration->send_configuration as in migration_object_init

Accelerator creation

  • Accelerators created and properties set
  • Parse bootorder and -machine kernel_filename/initrd_filename/kernel_cmdline
  • migration_object_init()
    • blk_mig_init, ram_mig_init, dirty_bitmap_mig_init

Late creation

  • Options: -boot
  • net_init_clients
  • Create late objects
  • Create monitors
  • Create backends for -serial/-parallel/-debugcon
  • get_default_vga_model, select_vgahw, select_watchdog
  • Determine ram_size
    • parse_numa_opts() -> set_numa_options()

Leaving preconfig

  • CHECKPOINT_INIT
  • Options: -plugin (requires -smp, but must be before CPUs are created)
  • machine_run_board_init(current_machine)
    • On-board devices are created
    • Requires accelerator to be initialized
  • Devices cannot be realized before this point (buses don't exist)
  • cont/migrate_incoming/loadvm complete initialization of the machine
    • everything starting with cpu_synchronize_all_post_init