diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -1488,8 +1488,28 @@ assert(error == 0); } + /* Allocate per-VCPU resources. */ + mt_vmm_info = calloc(guest_ncpus, sizeof(*mt_vmm_info)); + + /* + * Add all vCPUs. + */ + for (int vcpu = 0; vcpu < guest_ncpus; vcpu++) { + bool suspend = (vcpu != BSP); +#ifdef BHYVE_SNAPSHOT + if (restore_file != NULL) + suspend = true; +#endif + spinup_vcpu(ctx, vcpu, suspend); + } + #ifdef BHYVE_SNAPSHOT + /* initialize mutex/cond variables */ + init_snapshot(); + if (restore_file != NULL) { + vm_vcpu_pause(ctx); + fprintf(stdout, "Pausing pci devs...\r\n"); if (vm_pause_user_devs() != 0) { fprintf(stderr, "Failed to pause PCI device state.\n"); @@ -1564,36 +1584,18 @@ #endif #ifdef BHYVE_SNAPSHOT - if (restore_file != NULL) - destroy_restore_state(&rstate); - - /* initialize mutex/cond variables */ - init_snapshot(); - /* * checkpointing thread for communication with bhyvectl */ if (init_checkpoint_thread(ctx) < 0) printf("Failed to start checkpoint thread!\r\n"); - if (restore_file != NULL) + if (restore_file != NULL) { + destroy_restore_state(&rstate); vm_restore_time(ctx); -#endif - - /* Allocate per-VCPU resources. */ - mt_vmm_info = calloc(guest_ncpus, sizeof(*mt_vmm_info)); - - /* - * Add all vCPUs. - */ - for (int vcpu = 0; vcpu < guest_ncpus; vcpu++) { - bool suspend = (vcpu != BSP); -#ifdef BHYVE_SNAPSHOT - if (restore_file != NULL) - suspend = false; -#endif - spinup_vcpu(ctx, vcpu, suspend); + vm_vcpu_resume(ctx); } +#endif /* * Head off to the main event dispatch loop diff --git a/usr.sbin/bhyve/snapshot.h b/usr.sbin/bhyve/snapshot.h --- a/usr.sbin/bhyve/snapshot.h +++ b/usr.sbin/bhyve/snapshot.h @@ -106,4 +106,8 @@ int load_restore_file(const char *filename, struct restore_state *rstate); +void vm_vcpu_pause(struct vmctx *ctx); +void vm_vcpu_resume(struct vmctx *ctx); + + #endif diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c --- a/usr.sbin/bhyve/snapshot.c +++ b/usr.sbin/bhyve/snapshot.c @@ -1290,7 +1290,7 @@ pthread_mutex_unlock(&vcpu_lock); } -static void +void vm_vcpu_pause(struct vmctx *ctx) { @@ -1302,7 +1302,7 @@ pthread_mutex_unlock(&vcpu_lock); } -static void +void vm_vcpu_resume(struct vmctx *ctx) {