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

From QEMU
 
(40 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Tasks ==
# Convert -machine, -object, -accel from QemuOpts to keyval [Paolo]
# Deprecate x-exit-preconfig, replacing it with cont/finish-machine-init/loadvm/migrate_incoming [Paolo]
# Replace -qtest with "-object qtest,chardev=...,log=..." [Paolo]
# Replace -m, -smp, -boot, -semihosting-config, -rtc with machine properties
# Add machine-set and accel-set commands
Independent pieces:
* QAPIfy -display, add "-display add".
* Make more commands available in preconfig (e.g. object-add, netdev-add, blockdev-add)
== Basic phases ==
== Basic phases ==
* Until machine is created:
;PHASE_NO_MACHINE:
** Only backends can be created
:* Only backends can be created
** No machines have compat props that affect the backends
:* No machines have compat props that affect the backends, so that's good
* Once machine is created ("machine-set")
:QMP configuration flow starts here. machine-set command moves to the next step
** Backends can be connected to on-board devices (how?)
 
** Machine options include -smp, -boot, -m, -numa
;PHASE_MACHINE_CREATED:
* Once accelerator is created ("accel-set")
:* Backends can be connected to on-board devices (how?)
** migration_object_init() can be called
:set-numa-options available here
** plugins can be loaded
:accel-set (can only be invoked again if it fails) moves to the next step
* Once board devices are created ("finish-machine-init")
 
** Devices can be created
;PHASE_ACCEL_CREATED:
** The machine can be started ("cont") or incoming migration can proceed ("migrate_incoming")
:* vl.c sets up memory here, but that's not required
:* migration_object_init() can be called
:* plugins can be loaded
:CLI configuration flow starts here (preconfig enters the monitor here; w/o preconfig, x-exit-preconfig is invoked immediately)
:accel-set actually goes directly from PHASE_MACHINE_CREATED to the next step


== Current machine init sequence ==
;PHASE_MACHINE_INITIALIZED:
=== Up to CHECKPOINT_INIT ===
:* Devices can be created (including by x-exit-preconfig)
* Runstate is RUN_STATE_PRECONFIG or RUN_STATE_INMIGRATE
:finish-machine-init, cont, migrate_incoming, x-exit-preconfig move to the next step
* Get machine_class
 
* Set machine compat props
;PHASE_MACHINE_READY
* set_memory_options
:* everything after qdev_machine_creation_done()
* 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 ===
== QMP configuration flow ==
* qdev_machine_init()
=== Existing commands ===
** Only creates /machine/peripheral and /machine/peripheral-anon
*Backend creation: netdev-add, object-add, blockdev-add, ...
* Determine ram_size
*Device creation: device-add
* parse_numa_opts() -> set_numa_options()
*set-action (replaces -action and indirectly -watchdog-action, -no-reboot, -no-shutdown)
* Preconfig monitor
=== New commands ===
** set_numa_options (same as -numa but more powerful)
*machine-set (covers -M but also -smp, -boot, -m, -semihosting-config, -acpitable, -smbios, -fw_cfg, -option-rom, -rtc, maybe -cpu)
=== RUN_STATE_PRELAUNCH ===
*accel-set (-accel)
* machine_run_board_init(current_machine)
*something to replace -incoming defer??
** On-board devices are created
=== Non-QemuOpts options ===
** Requires accelerator to be initialized
* -k (should have replacement property in -display curses / -display vnc / -object input-barrier)
* Devices cannot be realized before this point (buses don't exist)
* -uuid (should be added to -machine)
* Start VM
* -qtest, -qtest-log (replaced by -object qtest)
** loadvm or incoming migration
=== Other command line options without QMP equivalent ===
** Otherwise, vm_start()
Move to "missing commands" as you see fit or remark on whether it's not needed in the QMP configuration flow:
*-display
*-fsdev
*-global
*-icount (tcg accelerator options?)
* -iscsi (obsoleted by -blockdev?)
*-mon (just use stdio)
*-msg
* -overcommit
*-plugin (plugin-add?)
*-replay
*-tpmdev


== First attempt at cleaned up sequence ==
== 6.0 cleaned up sequence ==
=== Early option parsing ===
=== Early option parsing ===
* Runstate is RUN_STATE_PRECONFIG or RUN_STATE_INMIGRATE
* Runstate is RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE
* Desugaring: -mem-prealloc, -watchdog
* qemu_process_sugar_options: -mem-prealloc, -watchdog
* Options: -pidfile, -sandbox, -name, -add-fd, -trace, -L
* qemu_process_early_options: -pidfile, -sandbox, -name, -add-fd, -trace, -L, -incoming defer
* replay_configure
* qemu_process_help_options
* qemu_maybe_daemonize


=== Early initialization ===
=== Early initialization ===
Line 83: Line 74:
* cpu_timers_init()
* cpu_timers_init()


=== Command-line processing part one ===
=== Early command-line processing, machine creation ===
* Options: -global, -rtc
* Options: -global, -rtc, replay_configure
* Get machine_class
* qemu_create_machine
* Set machine compat props
** set_memory_options + current_machine is created (these two could be moved after early backend creation?)
* Handle default devices
** Set machine compat props
** Default device check (needs machine_class but not MS)
* Handle default devices (qemu_disable_default_devices, qemu_create_default_devices)
** A bunch of checks for -daemonize
** Add default devices to device_configs
* Create default network
* Create default network
* Create backends
* Create early backends
** Create displays
** Create displays
** Create early objects
** Create early objects
Line 99: Line 88:
** Create fsdevs
** Create fsdevs
** Create audiodevs
** Create audiodevs
* Initialize qtest server
* qemu_apply_machine_options
** -boot, smp, -semihosting-config
** set current_migration->send_configuration as in migration_object_init


=== 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 ===
=== Accelerator creation ===
* Accelerators created and properties set
* 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 ===
=== Late creation ===
* Options: -boot
* Create late backends
* net_init_clients
** qtest (needs chardev)
* Create late objects
** net_init_clients
* Create monitors
** Create late objects
* Create backends for -serial/-parallel/-debugcon
** Create monitors
* get_default_vga_model, select_vgahw, select_watchdog
** Create backends for -serial/-parallel/-debugcon/semihosting
* Determine ram_size
* Determine ram_size
** qemu_resolve_machine_memdev()
** parse_numa_opts() -> set_numa_options()
** parse_numa_opts() -> set_numa_options()
* Monitor entered here if preconfig, otherwise qemu_init invokes qmp_x_exit_preconfig


=== RUN_STATE_PRELAUNCH ===
=== Leaving preconfig ===
* CHECKPOINT_INIT
* CHECKPOINT_INIT
* migration_object_init()
** blk_mig_init, ram_mig_init, dirty_bitmap_mig_init
* Options: -plugin (requires -smp, but must be before CPUs are created)
* Options: -plugin (requires -smp, but must be before CPUs are created)
* machine_run_board_init(current_machine)
* machine_run_board_init(current_machine)
Line 131: Line 116:
** Requires accelerator to be initialized
** Requires accelerator to be initialized
* Devices cannot be realized before this point (buses don't exist)
* Devices cannot be realized before this point (buses don't exist)
* Start VM
* cont/migrate_incoming/loadvm complete initialization of the machine
** loadvm or incoming migration
** everything starting with cpu_synchronize_all_post_init
** Otherwise, vm_start()

Latest revision as of 14:38, 7 October 2021

Tasks

  1. Convert -machine, -object, -accel from QemuOpts to keyval [Paolo]
  2. Deprecate x-exit-preconfig, replacing it with cont/finish-machine-init/loadvm/migrate_incoming [Paolo]
  3. Replace -qtest with "-object qtest,chardev=...,log=..." [Paolo]
  4. Replace -m, -smp, -boot, -semihosting-config, -rtc with machine properties
  5. Add machine-set and accel-set commands

Independent pieces:

  • QAPIfy -display, add "-display add".
  • Make more commands available in preconfig (e.g. object-add, netdev-add, blockdev-add)

Basic phases

PHASE_NO_MACHINE
  • Only backends can be created
  • No machines have compat props that affect the backends, so that's good
QMP configuration flow starts here. machine-set command moves to the next step
PHASE_MACHINE_CREATED
  • Backends can be connected to on-board devices (how?)
set-numa-options available here
accel-set (can only be invoked again if it fails) moves to the next step
PHASE_ACCEL_CREATED
  • vl.c sets up memory here, but that's not required
  • migration_object_init() can be called
  • plugins can be loaded
CLI configuration flow starts here (preconfig enters the monitor here; w/o preconfig, x-exit-preconfig is invoked immediately)
accel-set actually goes directly from PHASE_MACHINE_CREATED to the next step
PHASE_MACHINE_INITIALIZED
  • Devices can be created (including by x-exit-preconfig)
finish-machine-init, cont, migrate_incoming, x-exit-preconfig move to the next step
PHASE_MACHINE_READY
  • everything after qdev_machine_creation_done()

QMP configuration flow

Existing commands

  • Backend creation: netdev-add, object-add, blockdev-add, ...
  • Device creation: device-add
  • set-action (replaces -action and indirectly -watchdog-action, -no-reboot, -no-shutdown)

New commands

  • machine-set (covers -M but also -smp, -boot, -m, -semihosting-config, -acpitable, -smbios, -fw_cfg, -option-rom, -rtc, maybe -cpu)
  • accel-set (-accel)
  • something to replace -incoming defer??

Non-QemuOpts options

  • -k (should have replacement property in -display curses / -display vnc / -object input-barrier)
  • -uuid (should be added to -machine)
  • -qtest, -qtest-log (replaced by -object qtest)

Other command line options without QMP equivalent

Move to "missing commands" as you see fit or remark on whether it's not needed in the QMP configuration flow:

  • -display
  • -fsdev
  • -global
  • -icount (tcg accelerator options?)
  • -iscsi (obsoleted by -blockdev?)
  • -mon (just use stdio)
  • -msg
  • -overcommit
  • -plugin (plugin-add?)
  • -replay
  • -tpmdev

6.0 cleaned up sequence

Early option parsing

  • Runstate is RUN_STATE_PRELAUNCH or RUN_STATE_INMIGRATE
  • qemu_process_sugar_options: -mem-prealloc, -watchdog
  • qemu_process_early_options: -pidfile, -sandbox, -name, -add-fd, -trace, -L, -incoming defer
  • qemu_process_help_options
  • qemu_maybe_daemonize

Early initialization

  • qemu_init_main_loop()
  • cpu_timers_init()

Early command-line processing, machine creation

  • Options: -global, -rtc, replay_configure
  • qemu_create_machine
    • set_memory_options + current_machine is created (these two could be moved after early backend creation?)
    • Set machine compat props
  • Handle default devices (qemu_disable_default_devices, qemu_create_default_devices)
  • Create default network
  • Create early backends
    • Create displays
    • Create early objects
    • Options: -spice
    • Create chardevs
    • Create fsdevs
    • Create audiodevs
  • qemu_apply_machine_options
    • -boot, smp, -semihosting-config
    • set current_migration->send_configuration as in migration_object_init

Accelerator creation

  • Accelerators created and properties set
  • migration_object_init()
    • blk_mig_init, ram_mig_init, dirty_bitmap_mig_init

Late creation

  • Create late backends
    • qtest (needs chardev)
    • net_init_clients
    • Create late objects
    • Create monitors
    • Create backends for -serial/-parallel/-debugcon/semihosting
  • Determine ram_size
    • qemu_resolve_machine_memdev()
    • parse_numa_opts() -> set_numa_options()
  • Monitor entered here if preconfig, otherwise qemu_init invokes qmp_x_exit_preconfig

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