Lines Matching refs:mis
89 void postcopy_thread_create(MigrationIncomingState *mis, in postcopy_thread_create() argument
93 qemu_sem_init(&mis->thread_sync_sem, 0); in postcopy_thread_create()
94 qemu_thread_create(thread, name, fn, mis, joinable); in postcopy_thread_create()
95 qemu_sem_wait(&mis->thread_sync_sem); in postcopy_thread_create()
96 qemu_sem_destroy(&mis->thread_sync_sem); in postcopy_thread_create()
186 MigrationIncomingState *mis = migration_incoming_get_current(); in fill_destination_postcopy_migration_info() local
187 PostcopyBlocktimeContext *bc = mis->blocktime_ctx; in fill_destination_postcopy_migration_info()
201 MigrationIncomingState *mis = migration_incoming_get_current(); in get_postcopy_total_blocktime() local
202 PostcopyBlocktimeContext *bc = mis->blocktime_ctx; in get_postcopy_total_blocktime()
283 static bool ufd_check_and_apply(int ufd, MigrationIncomingState *mis, in ufd_check_and_apply() argument
306 if (!mis->blocktime_ctx) { in ufd_check_and_apply()
307 mis->blocktime_ctx = blocktime_context_new(); in ufd_check_and_apply()
372 bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp) in postcopy_ram_supported_by_host() argument
401 if (!ufd_check_and_apply(ufd, mis, errp)) { in postcopy_ram_supported_by_host()
526 MigrationIncomingState *mis = opaque; in cleanup_range() local
544 if (ioctl(mis->userfault_fd, UFFDIO_UNREGISTER, &range_struct)) { in cleanup_range()
558 int postcopy_ram_incoming_init(MigrationIncomingState *mis) in postcopy_ram_incoming_init() argument
567 static void postcopy_temp_pages_cleanup(MigrationIncomingState *mis) in postcopy_temp_pages_cleanup() argument
571 if (mis->postcopy_tmp_pages) { in postcopy_temp_pages_cleanup()
572 for (i = 0; i < mis->postcopy_channels; i++) { in postcopy_temp_pages_cleanup()
573 if (mis->postcopy_tmp_pages[i].tmp_huge_page) { in postcopy_temp_pages_cleanup()
574 munmap(mis->postcopy_tmp_pages[i].tmp_huge_page, in postcopy_temp_pages_cleanup()
575 mis->largest_page_size); in postcopy_temp_pages_cleanup()
576 mis->postcopy_tmp_pages[i].tmp_huge_page = NULL; in postcopy_temp_pages_cleanup()
579 g_free(mis->postcopy_tmp_pages); in postcopy_temp_pages_cleanup()
580 mis->postcopy_tmp_pages = NULL; in postcopy_temp_pages_cleanup()
583 if (mis->postcopy_tmp_zero_page) { in postcopy_temp_pages_cleanup()
584 munmap(mis->postcopy_tmp_zero_page, mis->largest_page_size); in postcopy_temp_pages_cleanup()
585 mis->postcopy_tmp_zero_page = NULL; in postcopy_temp_pages_cleanup()
592 int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) in postcopy_ram_incoming_cleanup() argument
596 if (mis->preempt_thread_status == PREEMPT_THREAD_CREATED) { in postcopy_ram_incoming_cleanup()
598 mis->preempt_thread_status = PREEMPT_THREAD_QUIT; in postcopy_ram_incoming_cleanup()
611 WITH_QEMU_LOCK_GUARD(&mis->page_request_mutex) { in postcopy_ram_incoming_cleanup()
612 if (qatomic_read(&mis->page_requested_count)) { in postcopy_ram_incoming_cleanup()
618 qemu_cond_wait(&mis->page_request_cond, in postcopy_ram_incoming_cleanup()
619 &mis->page_request_mutex); in postcopy_ram_incoming_cleanup()
623 if (mis->postcopy_qemufile_dst) { in postcopy_ram_incoming_cleanup()
624 qemu_file_shutdown(mis->postcopy_qemufile_dst); in postcopy_ram_incoming_cleanup()
626 qemu_thread_join(&mis->postcopy_prio_thread); in postcopy_ram_incoming_cleanup()
627 mis->preempt_thread_status = PREEMPT_THREAD_NONE; in postcopy_ram_incoming_cleanup()
630 if (mis->have_fault_thread) { in postcopy_ram_incoming_cleanup()
634 qatomic_set(&mis->fault_thread_quit, 1); in postcopy_ram_incoming_cleanup()
635 postcopy_fault_thread_notify(mis); in postcopy_ram_incoming_cleanup()
637 qemu_thread_join(&mis->fault_thread); in postcopy_ram_incoming_cleanup()
644 if (foreach_not_ignored_block(cleanup_range, mis)) { in postcopy_ram_incoming_cleanup()
649 close(mis->userfault_fd); in postcopy_ram_incoming_cleanup()
650 close(mis->userfault_event_fd); in postcopy_ram_incoming_cleanup()
651 mis->have_fault_thread = false; in postcopy_ram_incoming_cleanup()
664 postcopy_temp_pages_cleanup(mis); in postcopy_ram_incoming_cleanup()
699 int postcopy_ram_prepare_discard(MigrationIncomingState *mis) in postcopy_ram_prepare_discard() argument
701 if (foreach_not_ignored_block(nhp_range, mis)) { in postcopy_ram_prepare_discard()
721 MigrationIncomingState *mis = opaque; in ram_block_enable_notify() local
729 if (ioctl(mis->userfault_fd, UFFDIO_REGISTER, ®_struct)) { in ram_block_enable_notify()
755 static int postcopy_request_page(MigrationIncomingState *mis, RAMBlock *rb, in postcopy_request_page() argument
772 return received ? 0 : postcopy_place_page_zero(mis, aligned, rb); in postcopy_request_page()
775 return migrate_send_rp_req_pages(mis, rb, start, haddr); in postcopy_request_page()
787 MigrationIncomingState *mis = migration_incoming_get_current(); in postcopy_request_shared_page() local
796 postcopy_request_page(mis, rb, aligned_rbo, client_addr); in postcopy_request_shared_page()
833 MigrationIncomingState *mis = migration_incoming_get_current(); in mark_postcopy_blocktime_begin() local
834 PostcopyBlocktimeContext *dc = mis->blocktime_ctx; in mark_postcopy_blocktime_begin()
898 MigrationIncomingState *mis = migration_incoming_get_current(); in mark_postcopy_blocktime_end() local
899 PostcopyBlocktimeContext *dc = mis->blocktime_ctx; in mark_postcopy_blocktime_end()
946 static void postcopy_pause_fault_thread(MigrationIncomingState *mis) in postcopy_pause_fault_thread() argument
949 qemu_sem_wait(&mis->postcopy_pause_sem_fault); in postcopy_pause_fault_thread()
958 MigrationIncomingState *mis = opaque; in postcopy_ram_fault_thread() local
966 mis->last_rb = NULL; /* last RAMBlock we sent part of */ in postcopy_ram_fault_thread()
967 qemu_sem_post(&mis->thread_sync_sem); in postcopy_ram_fault_thread()
970 size_t pfd_len = 2 + mis->postcopy_remote_fds->len; in postcopy_ram_fault_thread()
974 pfd[0].fd = mis->userfault_fd; in postcopy_ram_fault_thread()
976 pfd[1].fd = mis->userfault_event_fd; in postcopy_ram_fault_thread()
979 for (index = 0; index < mis->postcopy_remote_fds->len; index++) { in postcopy_ram_fault_thread()
980 struct PostCopyFD *pcfd = &g_array_index(mis->postcopy_remote_fds, in postcopy_ram_fault_thread()
1004 if (!mis->to_src_file) { in postcopy_ram_fault_thread()
1010 postcopy_pause_fault_thread(mis); in postcopy_ram_fault_thread()
1017 if (read(mis->userfault_event_fd, &tmp64, 8) != 8) { in postcopy_ram_fault_thread()
1022 if (qatomic_read(&mis->fault_thread_quit)) { in postcopy_ram_fault_thread()
1030 ret = read(mis->userfault_fd, &msg, sizeof(msg)); in postcopy_ram_fault_thread()
1080 ret = postcopy_request_page(mis, rb, rb_offset, in postcopy_ram_fault_thread()
1084 postcopy_pause_fault_thread(mis); in postcopy_ram_fault_thread()
1094 &g_array_index(mis->postcopy_remote_fds, in postcopy_ram_fault_thread()
1151 static int postcopy_temp_pages_setup(MigrationIncomingState *mis) in postcopy_temp_pages_setup() argument
1159 mis->postcopy_channels = RAM_CHANNEL_MAX; in postcopy_temp_pages_setup()
1162 mis->postcopy_channels = 1; in postcopy_temp_pages_setup()
1165 channels = mis->postcopy_channels; in postcopy_temp_pages_setup()
1166 mis->postcopy_tmp_pages = g_malloc0_n(sizeof(PostcopyTmpPage), channels); in postcopy_temp_pages_setup()
1169 tmp_page = &mis->postcopy_tmp_pages[i]; in postcopy_temp_pages_setup()
1170 temp_page = mmap(NULL, mis->largest_page_size, PROT_READ | PROT_WRITE, in postcopy_temp_pages_setup()
1187 mis->postcopy_tmp_zero_page = mmap(NULL, mis->largest_page_size, in postcopy_temp_pages_setup()
1190 if (mis->postcopy_tmp_zero_page == MAP_FAILED) { in postcopy_temp_pages_setup()
1192 mis->postcopy_tmp_zero_page = NULL; in postcopy_temp_pages_setup()
1198 memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_size); in postcopy_temp_pages_setup()
1203 int postcopy_ram_incoming_setup(MigrationIncomingState *mis) in postcopy_ram_incoming_setup() argument
1208 mis->userfault_fd = uffd_open(O_CLOEXEC | O_NONBLOCK); in postcopy_ram_incoming_setup()
1209 if (mis->userfault_fd == -1) { in postcopy_ram_incoming_setup()
1219 if (!ufd_check_and_apply(mis->userfault_fd, mis, &local_err)) { in postcopy_ram_incoming_setup()
1225 mis->userfault_event_fd = eventfd(0, EFD_CLOEXEC); in postcopy_ram_incoming_setup()
1226 if (mis->userfault_event_fd == -1) { in postcopy_ram_incoming_setup()
1229 close(mis->userfault_fd); in postcopy_ram_incoming_setup()
1233 postcopy_thread_create(mis, &mis->fault_thread, in postcopy_ram_incoming_setup()
1236 mis->have_fault_thread = true; in postcopy_ram_incoming_setup()
1239 if (foreach_not_ignored_block(ram_block_enable_notify, mis)) { in postcopy_ram_incoming_setup()
1244 if (postcopy_temp_pages_setup(mis)) { in postcopy_ram_incoming_setup()
1254 postcopy_thread_create(mis, &mis->postcopy_prio_thread, in postcopy_ram_incoming_setup()
1257 mis->preempt_thread_status = PREEMPT_THREAD_CREATED; in postcopy_ram_incoming_setup()
1265 static int qemu_ufd_copy_ioctl(MigrationIncomingState *mis, void *host_addr, in qemu_ufd_copy_ioctl() argument
1268 int userfault_fd = mis->userfault_fd; in qemu_ufd_copy_ioctl()
1278 qemu_mutex_lock(&mis->page_request_mutex); in qemu_ufd_copy_ioctl()
1285 if (g_tree_lookup(mis->page_requested, host_addr)) { in qemu_ufd_copy_ioctl()
1286 g_tree_remove(mis->page_requested, host_addr); in qemu_ufd_copy_ioctl()
1287 int left_pages = qatomic_dec_fetch(&mis->page_requested_count); in qemu_ufd_copy_ioctl()
1289 trace_postcopy_page_req_del(host_addr, mis->page_requested_count); in qemu_ufd_copy_ioctl()
1292 if (mis->preempt_thread_status == PREEMPT_THREAD_QUIT && in qemu_ufd_copy_ioctl()
1299 qemu_cond_signal(&mis->page_request_cond); in qemu_ufd_copy_ioctl()
1302 qemu_mutex_unlock(&mis->page_request_mutex); in qemu_ufd_copy_ioctl()
1311 MigrationIncomingState *mis = migration_incoming_get_current(); in postcopy_notify_shared_wake() local
1312 GArray *pcrfds = mis->postcopy_remote_fds; in postcopy_notify_shared_wake()
1328 int postcopy_place_page(MigrationIncomingState *mis, void *host, void *from, in postcopy_place_page() argument
1339 e = qemu_ufd_copy_ioctl(mis, host, from, pagesize, rb); in postcopy_place_page()
1353 int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, in postcopy_place_page_zero() argument
1364 e = qemu_ufd_copy_ioctl(mis, host, NULL, pagesize, rb); in postcopy_place_page_zero()
1372 return postcopy_place_page(mis, host, mis->postcopy_tmp_zero_page, rb); in postcopy_place_page_zero()
1382 bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp) in postcopy_ram_supported_by_host() argument
1388 int postcopy_ram_incoming_init(MigrationIncomingState *mis) in postcopy_ram_incoming_init() argument
1394 int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) in postcopy_ram_incoming_cleanup() argument
1399 int postcopy_ram_prepare_discard(MigrationIncomingState *mis) in postcopy_ram_prepare_discard() argument
1410 int postcopy_ram_incoming_setup(MigrationIncomingState *mis) in postcopy_ram_incoming_setup() argument
1415 int postcopy_place_page(MigrationIncomingState *mis, void *host, void *from, in postcopy_place_page() argument
1421 int postcopy_place_page_zero(MigrationIncomingState *mis, void *host, in postcopy_place_page_zero() argument
1447 void postcopy_fault_thread_notify(MigrationIncomingState *mis) in postcopy_fault_thread_notify() argument
1455 if (write(mis->userfault_event_fd, &tmp64, 8) != 8) { in postcopy_fault_thread_notify()
1556 MigrationIncomingState *mis = migration_incoming_get_current(); in postcopy_register_shared_ufd() local
1558 mis->postcopy_remote_fds = g_array_append_val(mis->postcopy_remote_fds, in postcopy_register_shared_ufd()
1567 MigrationIncomingState *mis = migration_incoming_get_current(); in postcopy_unregister_shared_ufd() local
1568 GArray *pcrfds = mis->postcopy_remote_fds; in postcopy_unregister_shared_ufd()
1577 mis->postcopy_remote_fds = g_array_remove_index(pcrfds, i); in postcopy_unregister_shared_ufd()
1583 void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *file) in postcopy_preempt_new_channel() argument
1590 mis->postcopy_qemufile_dst = file; in postcopy_preempt_new_channel()
1591 qemu_sem_post(&mis->postcopy_qemufile_dst_done); in postcopy_preempt_new_channel()
1696 static void postcopy_pause_ram_fast_load(MigrationIncomingState *mis) in postcopy_pause_ram_fast_load() argument
1699 qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); in postcopy_pause_ram_fast_load()
1700 qemu_sem_wait(&mis->postcopy_pause_sem_fast_load); in postcopy_pause_ram_fast_load()
1701 qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); in postcopy_pause_ram_fast_load()
1705 static bool preempt_thread_should_run(MigrationIncomingState *mis) in preempt_thread_should_run() argument
1707 return mis->preempt_thread_status != PREEMPT_THREAD_QUIT; in preempt_thread_should_run()
1712 MigrationIncomingState *mis = opaque; in postcopy_preempt_thread() local
1719 qemu_sem_post(&mis->thread_sync_sem); in postcopy_preempt_thread()
1725 qemu_sem_wait(&mis->postcopy_qemufile_dst_done); in postcopy_preempt_thread()
1728 qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); in postcopy_preempt_thread()
1729 while (preempt_thread_should_run(mis)) { in postcopy_preempt_thread()
1730 ret = ram_load_postcopy(mis->postcopy_qemufile_dst, in postcopy_preempt_thread()
1733 if (ret && preempt_thread_should_run(mis)) { in postcopy_preempt_thread()
1734 postcopy_pause_ram_fast_load(mis); in postcopy_preempt_thread()
1740 qemu_mutex_unlock(&mis->postcopy_prio_thread_mutex); in postcopy_preempt_thread()