Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU System Emulator |
| 3 | * |
| 4 | * Copyright (c) 2003-2008 Fabrice Bellard |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
| 24 | #include <stdint.h> |
| 25 | #include <stdarg.h> |
Michael S. Tsirkin | b2e0a13 | 2010-11-22 19:52:34 +0200 | [diff] [blame] | 26 | #include <stdlib.h> |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 27 | #ifndef _WIN32 |
Blue Swirl | 1c47cb1 | 2010-03-30 19:27:34 +0000 | [diff] [blame] | 28 | #include <sys/types.h> |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 29 | #include <sys/mman.h> |
| 30 | #endif |
| 31 | #include "config.h" |
Paolo Bonzini | 83c9089 | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 32 | #include "monitor/monitor.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 33 | #include "sysemu/sysemu.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 34 | #include "qemu/bitops.h" |
| 35 | #include "qemu/bitmap.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 36 | #include "sysemu/arch_init.h" |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 37 | #include "audio/audio.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 38 | #include "hw/i386/pc.h" |
Michael S. Tsirkin | a2cb15b | 2012-12-12 14:24:50 +0200 | [diff] [blame] | 39 | #include "hw/pci/pci.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 40 | #include "hw/audio/audio.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 41 | #include "sysemu/kvm.h" |
Paolo Bonzini | caf71f8 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 42 | #include "migration/migration.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 43 | #include "hw/i386/smbios.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 44 | #include "exec/address-spaces.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 45 | #include "hw/audio/pcspk.h" |
Paolo Bonzini | caf71f8 | 2012-12-17 18:19:50 +0100 | [diff] [blame] | 46 | #include "migration/page_cache.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 47 | #include "qemu/config-file.h" |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 48 | #include "qemu/error-report.h" |
Daniel P. Berrange | 99afc91 | 2012-08-20 15:31:38 +0100 | [diff] [blame] | 49 | #include "qmp-commands.h" |
Juan Quintela | 3c12193 | 2012-09-04 13:08:57 +0200 | [diff] [blame] | 50 | #include "trace.h" |
Paolo Bonzini | 0d6d3c8 | 2012-11-14 15:45:02 +0100 | [diff] [blame] | 51 | #include "exec/cpu-all.h" |
Juan Quintela | 12291ec | 2013-10-14 17:14:47 +0200 | [diff] [blame] | 52 | #include "exec/ram_addr.h" |
Michael S. Tsirkin | 0445259 | 2013-04-15 09:19:22 +0300 | [diff] [blame] | 53 | #include "hw/acpi/acpi.h" |
Juan Quintela | aa8dc04 | 2013-11-06 11:33:05 +0100 | [diff] [blame] | 54 | #include "qemu/host-utils.h" |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 55 | #include "qemu/rcu_queue.h" |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 56 | |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 57 | #ifdef DEBUG_ARCH_INIT |
| 58 | #define DPRINTF(fmt, ...) \ |
| 59 | do { fprintf(stdout, "arch_init: " fmt, ## __VA_ARGS__); } while (0) |
| 60 | #else |
| 61 | #define DPRINTF(fmt, ...) \ |
| 62 | do { } while (0) |
| 63 | #endif |
| 64 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 65 | #ifdef TARGET_SPARC |
| 66 | int graphic_width = 1024; |
| 67 | int graphic_height = 768; |
| 68 | int graphic_depth = 8; |
| 69 | #else |
| 70 | int graphic_width = 800; |
| 71 | int graphic_height = 600; |
Alexander Graf | f1ff0e8 | 2013-06-20 14:06:27 +0200 | [diff] [blame] | 72 | int graphic_depth = 32; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 73 | #endif |
| 74 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 75 | |
| 76 | #if defined(TARGET_ALPHA) |
| 77 | #define QEMU_ARCH QEMU_ARCH_ALPHA |
| 78 | #elif defined(TARGET_ARM) |
| 79 | #define QEMU_ARCH QEMU_ARCH_ARM |
| 80 | #elif defined(TARGET_CRIS) |
| 81 | #define QEMU_ARCH QEMU_ARCH_CRIS |
| 82 | #elif defined(TARGET_I386) |
| 83 | #define QEMU_ARCH QEMU_ARCH_I386 |
| 84 | #elif defined(TARGET_M68K) |
| 85 | #define QEMU_ARCH QEMU_ARCH_M68K |
Michael Walle | 81ea0e1 | 2011-02-17 23:45:02 +0100 | [diff] [blame] | 86 | #elif defined(TARGET_LM32) |
| 87 | #define QEMU_ARCH QEMU_ARCH_LM32 |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 88 | #elif defined(TARGET_MICROBLAZE) |
| 89 | #define QEMU_ARCH QEMU_ARCH_MICROBLAZE |
| 90 | #elif defined(TARGET_MIPS) |
| 91 | #define QEMU_ARCH QEMU_ARCH_MIPS |
Anthony Green | d15a9c2 | 2013-03-18 15:49:25 -0400 | [diff] [blame] | 92 | #elif defined(TARGET_MOXIE) |
| 93 | #define QEMU_ARCH QEMU_ARCH_MOXIE |
Jia Liu | e67db06 | 2012-07-20 15:50:39 +0800 | [diff] [blame] | 94 | #elif defined(TARGET_OPENRISC) |
| 95 | #define QEMU_ARCH QEMU_ARCH_OPENRISC |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 96 | #elif defined(TARGET_PPC) |
| 97 | #define QEMU_ARCH QEMU_ARCH_PPC |
| 98 | #elif defined(TARGET_S390X) |
| 99 | #define QEMU_ARCH QEMU_ARCH_S390X |
| 100 | #elif defined(TARGET_SH4) |
| 101 | #define QEMU_ARCH QEMU_ARCH_SH4 |
| 102 | #elif defined(TARGET_SPARC) |
| 103 | #define QEMU_ARCH QEMU_ARCH_SPARC |
Max Filippov | 2328826 | 2011-09-06 03:55:25 +0400 | [diff] [blame] | 104 | #elif defined(TARGET_XTENSA) |
| 105 | #define QEMU_ARCH QEMU_ARCH_XTENSA |
Guan Xuetao | 4f23a1e | 2012-08-10 14:42:21 +0800 | [diff] [blame] | 106 | #elif defined(TARGET_UNICORE32) |
| 107 | #define QEMU_ARCH QEMU_ARCH_UNICORE32 |
Bastian Koppelmann | 48e06fe | 2014-09-01 12:59:46 +0100 | [diff] [blame] | 108 | #elif defined(TARGET_TRICORE) |
| 109 | #define QEMU_ARCH QEMU_ARCH_TRICORE |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 110 | #endif |
| 111 | |
| 112 | const uint32_t arch_type = QEMU_ARCH; |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 113 | static bool mig_throttle_on; |
| 114 | static int dirty_rate_high_cnt; |
| 115 | static void check_guest_throttling(void); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 116 | |
ChenLiang | 71411d3 | 2014-04-04 17:57:54 +0800 | [diff] [blame] | 117 | static uint64_t bitmap_sync_count; |
| 118 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 119 | /***********************************************************/ |
| 120 | /* ram save/restore */ |
| 121 | |
Yoshiaki Tamura | d20878d | 2010-08-18 13:30:12 +0900 | [diff] [blame] | 122 | #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ |
| 123 | #define RAM_SAVE_FLAG_COMPRESS 0x02 |
| 124 | #define RAM_SAVE_FLAG_MEM_SIZE 0x04 |
| 125 | #define RAM_SAVE_FLAG_PAGE 0x08 |
| 126 | #define RAM_SAVE_FLAG_EOS 0x10 |
| 127 | #define RAM_SAVE_FLAG_CONTINUE 0x20 |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 128 | #define RAM_SAVE_FLAG_XBZRLE 0x40 |
Michael R. Hines | 0033b8b | 2013-07-22 10:01:55 -0400 | [diff] [blame] | 129 | /* 0x80 is reserved in migration.h start with 0x100 next */ |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 130 | |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 131 | static struct defconfig_file { |
| 132 | const char *filename; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 133 | /* Indicates it is an user config file (disabled by -no-user-config) */ |
| 134 | bool userconfig; |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 135 | } default_config_files[] = { |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 136 | { CONFIG_QEMU_CONFDIR "/qemu.conf", true }, |
Paolo Bonzini | 2e59915 | 2013-06-04 14:45:27 +0200 | [diff] [blame] | 137 | { CONFIG_QEMU_CONFDIR "/target-" TARGET_NAME ".conf", true }, |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 138 | { NULL }, /* end of list */ |
| 139 | }; |
| 140 | |
Dr. David Alan Gilbert | 6d3cb1f | 2014-02-13 19:44:45 +0000 | [diff] [blame] | 141 | static const uint8_t ZERO_TARGET_PAGE[TARGET_PAGE_SIZE]; |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 142 | |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 143 | int qemu_read_default_config_files(bool userconfig) |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 144 | { |
| 145 | int ret; |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 146 | struct defconfig_file *f; |
| 147 | |
| 148 | for (f = default_config_files; f->filename; f++) { |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 149 | if (!userconfig && f->userconfig) { |
| 150 | continue; |
| 151 | } |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 152 | ret = qemu_read_config_file(f->filename); |
| 153 | if (ret < 0 && ret != -ENOENT) { |
| 154 | return ret; |
| 155 | } |
| 156 | } |
Laszlo Ersek | 4d8b3c6 | 2013-03-21 00:23:13 +0100 | [diff] [blame] | 157 | |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
Isaku Yamahata | dc3c26a | 2013-09-21 01:23:36 +0900 | [diff] [blame] | 161 | static inline bool is_zero_range(uint8_t *p, uint64_t size) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 162 | { |
Isaku Yamahata | dc3c26a | 2013-09-21 01:23:36 +0900 | [diff] [blame] | 163 | return buffer_find_nonzero_offset(p, size) == size; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 166 | /* struct contains XBZRLE cache and a static page |
| 167 | used by the compression */ |
| 168 | static struct { |
| 169 | /* buffer used for XBZRLE encoding */ |
| 170 | uint8_t *encoded_buf; |
| 171 | /* buffer for storing page content */ |
| 172 | uint8_t *current_buf; |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 173 | /* Cache for XBZRLE, Protected by lock. */ |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 174 | PageCache *cache; |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 175 | QemuMutex lock; |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 176 | } XBZRLE; |
| 177 | |
Gonglei (Arei) | 905f26f | 2014-01-30 20:08:35 +0200 | [diff] [blame] | 178 | /* buffer used for XBZRLE decoding */ |
| 179 | static uint8_t *xbzrle_decoded_buf; |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 180 | |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 181 | static void XBZRLE_cache_lock(void) |
| 182 | { |
| 183 | if (migrate_use_xbzrle()) |
| 184 | qemu_mutex_lock(&XBZRLE.lock); |
| 185 | } |
| 186 | |
| 187 | static void XBZRLE_cache_unlock(void) |
| 188 | { |
| 189 | if (migrate_use_xbzrle()) |
| 190 | qemu_mutex_unlock(&XBZRLE.lock); |
| 191 | } |
| 192 | |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 193 | /* |
| 194 | * called from qmp_migrate_set_cache_size in main thread, possibly while |
| 195 | * a migration is in progress. |
| 196 | * A running migration maybe using the cache and might finish during this |
| 197 | * call, hence changes to the cache are protected by XBZRLE.lock(). |
| 198 | */ |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 199 | int64_t xbzrle_cache_resize(int64_t new_size) |
| 200 | { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 201 | PageCache *new_cache; |
| 202 | int64_t ret; |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 203 | |
Orit Wasserman | c91e681 | 2014-01-30 20:08:34 +0200 | [diff] [blame] | 204 | if (new_size < TARGET_PAGE_SIZE) { |
| 205 | return -1; |
| 206 | } |
| 207 | |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 208 | XBZRLE_cache_lock(); |
| 209 | |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 210 | if (XBZRLE.cache != NULL) { |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 211 | if (pow2floor(new_size) == migrate_xbzrle_cache_size()) { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 212 | goto out_new_size; |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 213 | } |
| 214 | new_cache = cache_init(new_size / TARGET_PAGE_SIZE, |
| 215 | TARGET_PAGE_SIZE); |
| 216 | if (!new_cache) { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 217 | error_report("Error creating cache"); |
| 218 | ret = -1; |
| 219 | goto out; |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 220 | } |
| 221 | |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 222 | cache_fini(XBZRLE.cache); |
| 223 | XBZRLE.cache = new_cache; |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 224 | } |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 225 | |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 226 | out_new_size: |
| 227 | ret = pow2floor(new_size); |
| 228 | out: |
| 229 | XBZRLE_cache_unlock(); |
| 230 | return ret; |
Orit Wasserman | 9e1ba4c | 2012-08-06 21:42:54 +0300 | [diff] [blame] | 231 | } |
| 232 | |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 233 | /* accounting for migration statistics */ |
| 234 | typedef struct AccountingInfo { |
| 235 | uint64_t dup_pages; |
Peter Lieven | f1c7279 | 2013-03-26 10:58:37 +0100 | [diff] [blame] | 236 | uint64_t skipped_pages; |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 237 | uint64_t norm_pages; |
| 238 | uint64_t iterations; |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 239 | uint64_t xbzrle_bytes; |
| 240 | uint64_t xbzrle_pages; |
| 241 | uint64_t xbzrle_cache_miss; |
ChenLiang | 8bc3923 | 2014-04-04 17:57:56 +0800 | [diff] [blame] | 242 | double xbzrle_cache_miss_rate; |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 243 | uint64_t xbzrle_overflows; |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 244 | } AccountingInfo; |
| 245 | |
| 246 | static AccountingInfo acct_info; |
| 247 | |
| 248 | static void acct_clear(void) |
| 249 | { |
| 250 | memset(&acct_info, 0, sizeof(acct_info)); |
| 251 | } |
| 252 | |
| 253 | uint64_t dup_mig_bytes_transferred(void) |
| 254 | { |
| 255 | return acct_info.dup_pages * TARGET_PAGE_SIZE; |
| 256 | } |
| 257 | |
| 258 | uint64_t dup_mig_pages_transferred(void) |
| 259 | { |
| 260 | return acct_info.dup_pages; |
| 261 | } |
| 262 | |
Peter Lieven | f1c7279 | 2013-03-26 10:58:37 +0100 | [diff] [blame] | 263 | uint64_t skipped_mig_bytes_transferred(void) |
| 264 | { |
| 265 | return acct_info.skipped_pages * TARGET_PAGE_SIZE; |
| 266 | } |
| 267 | |
| 268 | uint64_t skipped_mig_pages_transferred(void) |
| 269 | { |
| 270 | return acct_info.skipped_pages; |
| 271 | } |
| 272 | |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 273 | uint64_t norm_mig_bytes_transferred(void) |
| 274 | { |
| 275 | return acct_info.norm_pages * TARGET_PAGE_SIZE; |
| 276 | } |
| 277 | |
| 278 | uint64_t norm_mig_pages_transferred(void) |
| 279 | { |
| 280 | return acct_info.norm_pages; |
| 281 | } |
| 282 | |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 283 | uint64_t xbzrle_mig_bytes_transferred(void) |
| 284 | { |
| 285 | return acct_info.xbzrle_bytes; |
| 286 | } |
| 287 | |
| 288 | uint64_t xbzrle_mig_pages_transferred(void) |
| 289 | { |
| 290 | return acct_info.xbzrle_pages; |
| 291 | } |
| 292 | |
| 293 | uint64_t xbzrle_mig_pages_cache_miss(void) |
| 294 | { |
| 295 | return acct_info.xbzrle_cache_miss; |
| 296 | } |
| 297 | |
ChenLiang | 8bc3923 | 2014-04-04 17:57:56 +0800 | [diff] [blame] | 298 | double xbzrle_mig_cache_miss_rate(void) |
| 299 | { |
| 300 | return acct_info.xbzrle_cache_miss_rate; |
| 301 | } |
| 302 | |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 303 | uint64_t xbzrle_mig_pages_overflow(void) |
| 304 | { |
| 305 | return acct_info.xbzrle_overflows; |
| 306 | } |
| 307 | |
Juan Quintela | 3f7d7b0 | 2012-10-18 13:56:35 +0200 | [diff] [blame] | 308 | static size_t save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, |
| 309 | int cont, int flag) |
Orit Wasserman | 0c51f43 | 2012-06-19 18:43:14 +0300 | [diff] [blame] | 310 | { |
Juan Quintela | 3f7d7b0 | 2012-10-18 13:56:35 +0200 | [diff] [blame] | 311 | size_t size; |
Orit Wasserman | 0c51f43 | 2012-06-19 18:43:14 +0300 | [diff] [blame] | 312 | |
Juan Quintela | 3f7d7b0 | 2012-10-18 13:56:35 +0200 | [diff] [blame] | 313 | qemu_put_be64(f, offset | cont | flag); |
| 314 | size = 8; |
| 315 | |
| 316 | if (!cont) { |
| 317 | qemu_put_byte(f, strlen(block->idstr)); |
| 318 | qemu_put_buffer(f, (uint8_t *)block->idstr, |
| 319 | strlen(block->idstr)); |
| 320 | size += 1 + strlen(block->idstr); |
| 321 | } |
| 322 | return size; |
Orit Wasserman | 0c51f43 | 2012-06-19 18:43:14 +0300 | [diff] [blame] | 323 | } |
| 324 | |
Dr. David Alan Gilbert | 6d3cb1f | 2014-02-13 19:44:45 +0000 | [diff] [blame] | 325 | /* This is the last block that we have visited serching for dirty pages |
| 326 | */ |
| 327 | static RAMBlock *last_seen_block; |
| 328 | /* This is the last block from where we have sent data */ |
| 329 | static RAMBlock *last_sent_block; |
| 330 | static ram_addr_t last_offset; |
| 331 | static unsigned long *migration_bitmap; |
| 332 | static uint64_t migration_dirty_pages; |
| 333 | static uint32_t last_version; |
| 334 | static bool ram_bulk_stage; |
| 335 | |
| 336 | /* Update the xbzrle cache to reflect a page that's been sent as all 0. |
| 337 | * The important thing is that a stale (not-yet-0'd) page be replaced |
| 338 | * by the new data. |
| 339 | * As a bonus, if the page wasn't in the cache it gets added so that |
| 340 | * when a small write is made into the 0'd page it gets XBZRLE sent |
| 341 | */ |
| 342 | static void xbzrle_cache_zero_page(ram_addr_t current_addr) |
| 343 | { |
| 344 | if (ram_bulk_stage || !migrate_use_xbzrle()) { |
| 345 | return; |
| 346 | } |
| 347 | |
| 348 | /* We don't care if this fails to allocate a new cache page |
| 349 | * as long as it updated an old one */ |
ChenLiang | 27af7d6 | 2014-11-24 19:55:47 +0800 | [diff] [blame] | 350 | cache_insert(XBZRLE.cache, current_addr, ZERO_TARGET_PAGE, |
| 351 | bitmap_sync_count); |
Dr. David Alan Gilbert | 6d3cb1f | 2014-02-13 19:44:45 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 354 | #define ENCODING_FLAG_XBZRLE 0x1 |
| 355 | |
ChenLiang | 1534ee9 | 2014-04-04 17:57:53 +0800 | [diff] [blame] | 356 | static int save_xbzrle_page(QEMUFile *f, uint8_t **current_data, |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 357 | ram_addr_t current_addr, RAMBlock *block, |
Juan Quintela | dd051c7 | 2012-08-06 21:42:58 +0300 | [diff] [blame] | 358 | ram_addr_t offset, int cont, bool last_stage) |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 359 | { |
| 360 | int encoded_len = 0, bytes_sent = -1; |
| 361 | uint8_t *prev_cached_page; |
| 362 | |
ChenLiang | 27af7d6 | 2014-11-24 19:55:47 +0800 | [diff] [blame] | 363 | if (!cache_is_cached(XBZRLE.cache, current_addr, bitmap_sync_count)) { |
ChenLiang | 1534ee9 | 2014-04-04 17:57:53 +0800 | [diff] [blame] | 364 | acct_info.xbzrle_cache_miss++; |
Juan Quintela | dd051c7 | 2012-08-06 21:42:58 +0300 | [diff] [blame] | 365 | if (!last_stage) { |
ChenLiang | 27af7d6 | 2014-11-24 19:55:47 +0800 | [diff] [blame] | 366 | if (cache_insert(XBZRLE.cache, current_addr, *current_data, |
| 367 | bitmap_sync_count) == -1) { |
Orit Wasserman | 89db998 | 2014-01-30 20:08:38 +0200 | [diff] [blame] | 368 | return -1; |
ChenLiang | 1534ee9 | 2014-04-04 17:57:53 +0800 | [diff] [blame] | 369 | } else { |
| 370 | /* update *current_data when the page has been |
| 371 | inserted into cache */ |
| 372 | *current_data = get_cached_data(XBZRLE.cache, current_addr); |
Orit Wasserman | 89db998 | 2014-01-30 20:08:38 +0200 | [diff] [blame] | 373 | } |
Juan Quintela | dd051c7 | 2012-08-06 21:42:58 +0300 | [diff] [blame] | 374 | } |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 375 | return -1; |
| 376 | } |
| 377 | |
| 378 | prev_cached_page = get_cached_data(XBZRLE.cache, current_addr); |
| 379 | |
| 380 | /* save current buffer into memory */ |
ChenLiang | 1534ee9 | 2014-04-04 17:57:53 +0800 | [diff] [blame] | 381 | memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 382 | |
| 383 | /* XBZRLE encoding (if there is no overflow) */ |
| 384 | encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf, |
| 385 | TARGET_PAGE_SIZE, XBZRLE.encoded_buf, |
| 386 | TARGET_PAGE_SIZE); |
| 387 | if (encoded_len == 0) { |
| 388 | DPRINTF("Skipping unmodified page\n"); |
| 389 | return 0; |
| 390 | } else if (encoded_len == -1) { |
| 391 | DPRINTF("Overflow\n"); |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 392 | acct_info.xbzrle_overflows++; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 393 | /* update data in the cache */ |
ChenLiang | 1534ee9 | 2014-04-04 17:57:53 +0800 | [diff] [blame] | 394 | if (!last_stage) { |
| 395 | memcpy(prev_cached_page, *current_data, TARGET_PAGE_SIZE); |
| 396 | *current_data = prev_cached_page; |
| 397 | } |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 398 | return -1; |
| 399 | } |
| 400 | |
| 401 | /* we need to update the data in the cache, in order to get the same data */ |
Juan Quintela | dd051c7 | 2012-08-06 21:42:58 +0300 | [diff] [blame] | 402 | if (!last_stage) { |
| 403 | memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE); |
| 404 | } |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 405 | |
| 406 | /* Send XBZRLE based compressed page */ |
Juan Quintela | 3f7d7b0 | 2012-10-18 13:56:35 +0200 | [diff] [blame] | 407 | bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 408 | qemu_put_byte(f, ENCODING_FLAG_XBZRLE); |
| 409 | qemu_put_be16(f, encoded_len); |
| 410 | qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len); |
Juan Quintela | 3f7d7b0 | 2012-10-18 13:56:35 +0200 | [diff] [blame] | 411 | bytes_sent += encoded_len + 1 + 2; |
Orit Wasserman | f36d55a | 2012-08-06 21:42:57 +0300 | [diff] [blame] | 412 | acct_info.xbzrle_pages++; |
| 413 | acct_info.xbzrle_bytes += bytes_sent; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 414 | |
| 415 | return bytes_sent; |
| 416 | } |
| 417 | |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 418 | static inline |
| 419 | ram_addr_t migration_bitmap_find_and_reset_dirty(MemoryRegion *mr, |
| 420 | ram_addr_t start) |
Juan Quintela | 69268cd | 2012-07-20 10:36:12 +0200 | [diff] [blame] | 421 | { |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 422 | unsigned long base = mr->ram_addr >> TARGET_PAGE_BITS; |
| 423 | unsigned long nr = base + (start >> TARGET_PAGE_BITS); |
Michael S. Tsirkin | 0851c9f | 2013-08-19 17:26:52 +0300 | [diff] [blame] | 424 | uint64_t mr_size = TARGET_PAGE_ALIGN(memory_region_size(mr)); |
| 425 | unsigned long size = base + (mr_size >> TARGET_PAGE_BITS); |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 426 | |
Peter Lieven | 70c8652 | 2013-03-26 10:58:38 +0100 | [diff] [blame] | 427 | unsigned long next; |
| 428 | |
| 429 | if (ram_bulk_stage && nr > base) { |
| 430 | next = nr + 1; |
| 431 | } else { |
| 432 | next = find_next_bit(migration_bitmap, size, nr); |
| 433 | } |
Juan Quintela | 69268cd | 2012-07-20 10:36:12 +0200 | [diff] [blame] | 434 | |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 435 | if (next < size) { |
| 436 | clear_bit(next, migration_bitmap); |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 437 | migration_dirty_pages--; |
Juan Quintela | 69268cd | 2012-07-20 10:36:12 +0200 | [diff] [blame] | 438 | } |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 439 | return (next - base) << TARGET_PAGE_BITS; |
Juan Quintela | 69268cd | 2012-07-20 10:36:12 +0200 | [diff] [blame] | 440 | } |
| 441 | |
Juan Quintela | 791fa2a | 2013-11-05 16:47:20 +0100 | [diff] [blame] | 442 | static inline bool migration_bitmap_set_dirty(ram_addr_t addr) |
Juan Quintela | e44d26c | 2012-07-20 10:16:08 +0200 | [diff] [blame] | 443 | { |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 444 | bool ret; |
Juan Quintela | 791fa2a | 2013-11-05 16:47:20 +0100 | [diff] [blame] | 445 | int nr = addr >> TARGET_PAGE_BITS; |
Juan Quintela | e44d26c | 2012-07-20 10:16:08 +0200 | [diff] [blame] | 446 | |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 447 | ret = test_and_set_bit(nr, migration_bitmap); |
| 448 | |
| 449 | if (!ret) { |
| 450 | migration_dirty_pages++; |
Juan Quintela | e44d26c | 2012-07-20 10:16:08 +0200 | [diff] [blame] | 451 | } |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 452 | return ret; |
Juan Quintela | e44d26c | 2012-07-20 10:16:08 +0200 | [diff] [blame] | 453 | } |
| 454 | |
Juan Quintela | 791fa2a | 2013-11-05 16:47:20 +0100 | [diff] [blame] | 455 | static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length) |
| 456 | { |
| 457 | ram_addr_t addr; |
Juan Quintela | aa8dc04 | 2013-11-06 11:33:05 +0100 | [diff] [blame] | 458 | unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS); |
Juan Quintela | 791fa2a | 2013-11-05 16:47:20 +0100 | [diff] [blame] | 459 | |
Juan Quintela | aa8dc04 | 2013-11-06 11:33:05 +0100 | [diff] [blame] | 460 | /* start address is aligned at the start of a word? */ |
| 461 | if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) { |
| 462 | int k; |
| 463 | int nr = BITS_TO_LONGS(length >> TARGET_PAGE_BITS); |
| 464 | unsigned long *src = ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]; |
| 465 | |
| 466 | for (k = page; k < page + nr; k++) { |
| 467 | if (src[k]) { |
| 468 | unsigned long new_dirty; |
| 469 | new_dirty = ~migration_bitmap[k]; |
| 470 | migration_bitmap[k] |= src[k]; |
| 471 | new_dirty &= src[k]; |
| 472 | migration_dirty_pages += ctpopl(new_dirty); |
| 473 | src[k] = 0; |
| 474 | } |
| 475 | } |
| 476 | } else { |
| 477 | for (addr = 0; addr < length; addr += TARGET_PAGE_SIZE) { |
| 478 | if (cpu_physical_memory_get_dirty(start + addr, |
| 479 | TARGET_PAGE_SIZE, |
| 480 | DIRTY_MEMORY_MIGRATION)) { |
| 481 | cpu_physical_memory_reset_dirty(start + addr, |
| 482 | TARGET_PAGE_SIZE, |
| 483 | DIRTY_MEMORY_MIGRATION); |
| 484 | migration_bitmap_set_dirty(start + addr); |
| 485 | } |
Juan Quintela | 791fa2a | 2013-11-05 16:47:20 +0100 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | |
ChenLiang | 6c1b663 | 2014-03-20 20:15:03 +0800 | [diff] [blame] | 491 | /* Fix me: there are too many global variables used in migration process. */ |
| 492 | static int64_t start_time; |
| 493 | static int64_t bytes_xfer_prev; |
| 494 | static int64_t num_dirty_pages_period; |
| 495 | |
| 496 | static void migration_bitmap_sync_init(void) |
| 497 | { |
| 498 | start_time = 0; |
| 499 | bytes_xfer_prev = 0; |
| 500 | num_dirty_pages_period = 0; |
| 501 | } |
Paolo Bonzini | 32c835b | 2013-02-22 17:36:27 +0100 | [diff] [blame] | 502 | |
Mike Day | ae3a704 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 503 | /* Called with iothread lock held, to protect ram_list.dirty_memory[] */ |
Juan Quintela | dd2df73 | 2012-07-20 10:52:51 +0200 | [diff] [blame] | 504 | static void migration_bitmap_sync(void) |
| 505 | { |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 506 | RAMBlock *block; |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 507 | uint64_t num_dirty_pages_init = migration_dirty_pages; |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 508 | MigrationState *s = migrate_get_current(); |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 509 | int64_t end_time; |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 510 | int64_t bytes_xfer_now; |
ChenLiang | 8bc3923 | 2014-04-04 17:57:56 +0800 | [diff] [blame] | 511 | static uint64_t xbzrle_cache_miss_prev; |
| 512 | static uint64_t iterations_prev; |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 513 | |
ChenLiang | 71411d3 | 2014-04-04 17:57:54 +0800 | [diff] [blame] | 514 | bitmap_sync_count++; |
| 515 | |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 516 | if (!bytes_xfer_prev) { |
| 517 | bytes_xfer_prev = ram_bytes_transferred(); |
| 518 | } |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 519 | |
| 520 | if (!start_time) { |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 521 | start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 522 | } |
Juan Quintela | 3c12193 | 2012-09-04 13:08:57 +0200 | [diff] [blame] | 523 | |
| 524 | trace_migration_bitmap_sync_start(); |
Paolo Bonzini | 1d67136 | 2013-04-24 10:46:55 +0200 | [diff] [blame] | 525 | address_space_sync_dirty_bitmap(&address_space_memory); |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 526 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 527 | rcu_read_lock(); |
| 528 | QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { |
Michael S. Tsirkin | 9b8424d | 2014-12-15 22:55:32 +0200 | [diff] [blame] | 529 | migration_bitmap_sync_range(block->mr->ram_addr, block->used_length); |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 530 | } |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 531 | rcu_read_unlock(); |
| 532 | |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 533 | trace_migration_bitmap_sync_end(migration_dirty_pages |
Juan Quintela | 3c12193 | 2012-09-04 13:08:57 +0200 | [diff] [blame] | 534 | - num_dirty_pages_init); |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 535 | num_dirty_pages_period += migration_dirty_pages - num_dirty_pages_init; |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 536 | end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 537 | |
| 538 | /* more than 1 second = 1000 millisecons */ |
| 539 | if (end_time > start_time + 1000) { |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 540 | if (migrate_auto_converge()) { |
| 541 | /* The following detection logic can be refined later. For now: |
| 542 | Check to see if the dirtied bytes is 50% more than the approx. |
| 543 | amount of bytes that just got transferred since the last time we |
| 544 | were in this routine. If that happens >N times (for now N==4) |
| 545 | we turn on the throttle down logic */ |
| 546 | bytes_xfer_now = ram_bytes_transferred(); |
| 547 | if (s->dirty_pages_rate && |
| 548 | (num_dirty_pages_period * TARGET_PAGE_SIZE > |
| 549 | (bytes_xfer_now - bytes_xfer_prev)/2) && |
| 550 | (dirty_rate_high_cnt++ > 4)) { |
| 551 | trace_migration_throttle(); |
| 552 | mig_throttle_on = true; |
| 553 | dirty_rate_high_cnt = 0; |
| 554 | } |
| 555 | bytes_xfer_prev = bytes_xfer_now; |
| 556 | } else { |
| 557 | mig_throttle_on = false; |
| 558 | } |
ChenLiang | 8bc3923 | 2014-04-04 17:57:56 +0800 | [diff] [blame] | 559 | if (migrate_use_xbzrle()) { |
| 560 | if (iterations_prev != 0) { |
| 561 | acct_info.xbzrle_cache_miss_rate = |
| 562 | (double)(acct_info.xbzrle_cache_miss - |
| 563 | xbzrle_cache_miss_prev) / |
| 564 | (acct_info.iterations - iterations_prev); |
| 565 | } |
| 566 | iterations_prev = acct_info.iterations; |
| 567 | xbzrle_cache_miss_prev = acct_info.xbzrle_cache_miss; |
| 568 | } |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 569 | s->dirty_pages_rate = num_dirty_pages_period * 1000 |
| 570 | / (end_time - start_time); |
Juan Quintela | 90f8ae7 | 2013-02-01 13:22:37 +0100 | [diff] [blame] | 571 | s->dirty_bytes_rate = s->dirty_pages_rate * TARGET_PAGE_SIZE; |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 572 | start_time = end_time; |
| 573 | num_dirty_pages_period = 0; |
ChenLiang | 58570ed | 2014-04-04 17:57:55 +0800 | [diff] [blame] | 574 | s->dirty_sync_count = bitmap_sync_count; |
Juan Quintela | 8d01719 | 2012-08-13 12:31:25 +0200 | [diff] [blame] | 575 | } |
Juan Quintela | dd2df73 | 2012-07-20 10:52:51 +0200 | [diff] [blame] | 576 | } |
| 577 | |
Orit Wasserman | 6c779f2 | 2012-07-10 12:37:13 +0300 | [diff] [blame] | 578 | /* |
Dr. David Alan Gilbert | 14bcfdc | 2014-05-09 11:54:55 +0100 | [diff] [blame] | 579 | * ram_save_page: Send the given page to the stream |
| 580 | * |
| 581 | * Returns: Number of bytes written. |
| 582 | */ |
| 583 | static int ram_save_page(QEMUFile *f, RAMBlock* block, ram_addr_t offset, |
| 584 | bool last_stage) |
| 585 | { |
| 586 | int bytes_sent; |
| 587 | int cont; |
| 588 | ram_addr_t current_addr; |
| 589 | MemoryRegion *mr = block->mr; |
| 590 | uint8_t *p; |
| 591 | int ret; |
| 592 | bool send_async = true; |
| 593 | |
| 594 | cont = (block == last_sent_block) ? RAM_SAVE_FLAG_CONTINUE : 0; |
| 595 | |
| 596 | p = memory_region_get_ram_ptr(mr) + offset; |
| 597 | |
| 598 | /* In doubt sent page as normal */ |
| 599 | bytes_sent = -1; |
| 600 | ret = ram_control_save_page(f, block->offset, |
| 601 | offset, TARGET_PAGE_SIZE, &bytes_sent); |
| 602 | |
| 603 | XBZRLE_cache_lock(); |
| 604 | |
| 605 | current_addr = block->offset + offset; |
| 606 | if (ret != RAM_SAVE_CONTROL_NOT_SUPP) { |
| 607 | if (ret != RAM_SAVE_CONTROL_DELAYED) { |
| 608 | if (bytes_sent > 0) { |
| 609 | acct_info.norm_pages++; |
| 610 | } else if (bytes_sent == 0) { |
| 611 | acct_info.dup_pages++; |
| 612 | } |
| 613 | } |
| 614 | } else if (is_zero_range(p, TARGET_PAGE_SIZE)) { |
| 615 | acct_info.dup_pages++; |
| 616 | bytes_sent = save_block_hdr(f, block, offset, cont, |
| 617 | RAM_SAVE_FLAG_COMPRESS); |
| 618 | qemu_put_byte(f, 0); |
| 619 | bytes_sent++; |
| 620 | /* Must let xbzrle know, otherwise a previous (now 0'd) cached |
| 621 | * page would be stale |
| 622 | */ |
| 623 | xbzrle_cache_zero_page(current_addr); |
| 624 | } else if (!ram_bulk_stage && migrate_use_xbzrle()) { |
| 625 | bytes_sent = save_xbzrle_page(f, &p, current_addr, block, |
| 626 | offset, cont, last_stage); |
| 627 | if (!last_stage) { |
| 628 | /* Can't send this cached data async, since the cache page |
| 629 | * might get updated before it gets to the wire |
| 630 | */ |
| 631 | send_async = false; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | /* XBZRLE overflow or normal page */ |
| 636 | if (bytes_sent == -1) { |
| 637 | bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE); |
| 638 | if (send_async) { |
| 639 | qemu_put_buffer_async(f, p, TARGET_PAGE_SIZE); |
| 640 | } else { |
| 641 | qemu_put_buffer(f, p, TARGET_PAGE_SIZE); |
| 642 | } |
| 643 | bytes_sent += TARGET_PAGE_SIZE; |
| 644 | acct_info.norm_pages++; |
| 645 | } |
| 646 | |
| 647 | XBZRLE_cache_unlock(); |
| 648 | |
| 649 | return bytes_sent; |
| 650 | } |
| 651 | |
| 652 | /* |
| 653 | * ram_find_and_save_block: Finds a page to send and sends it to f |
Orit Wasserman | 6c779f2 | 2012-07-10 12:37:13 +0300 | [diff] [blame] | 654 | * |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 655 | * Called within an RCU critical section. |
| 656 | * |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 657 | * Returns: The number of bytes written. |
| 658 | * 0 means no dirty pages |
Orit Wasserman | 6c779f2 | 2012-07-10 12:37:13 +0300 | [diff] [blame] | 659 | */ |
| 660 | |
Dr. David Alan Gilbert | 14bcfdc | 2014-05-09 11:54:55 +0100 | [diff] [blame] | 661 | static int ram_find_and_save_block(QEMUFile *f, bool last_stage) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 662 | { |
Juan Quintela | b23a9a5 | 2012-10-17 20:08:04 +0200 | [diff] [blame] | 663 | RAMBlock *block = last_seen_block; |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 664 | ram_addr_t offset = last_offset; |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 665 | bool complete_round = false; |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 666 | int bytes_sent = 0; |
Avi Kivity | 71c510e | 2011-12-21 13:11:22 +0200 | [diff] [blame] | 667 | MemoryRegion *mr; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 668 | |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 669 | if (!block) |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 670 | block = QLIST_FIRST_RCU(&ram_list.blocks); |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 671 | |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 672 | while (true) { |
Avi Kivity | 71c510e | 2011-12-21 13:11:22 +0200 | [diff] [blame] | 673 | mr = block->mr; |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 674 | offset = migration_bitmap_find_and_reset_dirty(mr, offset); |
| 675 | if (complete_round && block == last_seen_block && |
| 676 | offset >= last_offset) { |
| 677 | break; |
| 678 | } |
Michael S. Tsirkin | 9b8424d | 2014-12-15 22:55:32 +0200 | [diff] [blame] | 679 | if (offset >= block->used_length) { |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 680 | offset = 0; |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 681 | block = QLIST_NEXT_RCU(block, next); |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 682 | if (!block) { |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 683 | block = QLIST_FIRST_RCU(&ram_list.blocks); |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 684 | complete_round = true; |
Peter Lieven | 78d07ae | 2013-03-26 10:58:36 +0100 | [diff] [blame] | 685 | ram_bulk_stage = false; |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 686 | } |
| 687 | } else { |
Dr. David Alan Gilbert | 14bcfdc | 2014-05-09 11:54:55 +0100 | [diff] [blame] | 688 | bytes_sent = ram_save_page(f, block, offset, last_stage); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 689 | |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 690 | /* if page is unmodified, continue to the next */ |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 691 | if (bytes_sent > 0) { |
Juan Quintela | 5f718a1 | 2012-10-17 20:10:55 +0200 | [diff] [blame] | 692 | last_sent_block = block; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 693 | break; |
| 694 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 695 | } |
Juan Quintela | 4c8ae0f | 2012-10-18 00:00:59 +0200 | [diff] [blame] | 696 | } |
Mike Day | ae3a704 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 697 | |
Juan Quintela | b23a9a5 | 2012-10-17 20:08:04 +0200 | [diff] [blame] | 698 | last_seen_block = block; |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 699 | last_offset = offset; |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 700 | return bytes_sent; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static uint64_t bytes_transferred; |
| 704 | |
Michael R. Hines | 2b0ce07 | 2013-06-25 21:35:28 -0400 | [diff] [blame] | 705 | void acct_update_position(QEMUFile *f, size_t size, bool zero) |
| 706 | { |
| 707 | uint64_t pages = size / TARGET_PAGE_SIZE; |
| 708 | if (zero) { |
| 709 | acct_info.dup_pages += pages; |
| 710 | } else { |
| 711 | acct_info.norm_pages += pages; |
| 712 | bytes_transferred += size; |
| 713 | qemu_update_position(f, size); |
| 714 | } |
| 715 | } |
| 716 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 717 | static ram_addr_t ram_save_remaining(void) |
| 718 | { |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 719 | return migration_dirty_pages; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | uint64_t ram_bytes_remaining(void) |
| 723 | { |
| 724 | return ram_save_remaining() * TARGET_PAGE_SIZE; |
| 725 | } |
| 726 | |
| 727 | uint64_t ram_bytes_transferred(void) |
| 728 | { |
| 729 | return bytes_transferred; |
| 730 | } |
| 731 | |
| 732 | uint64_t ram_bytes_total(void) |
| 733 | { |
Alex Williamson | d17b528 | 2010-06-25 11:08:38 -0600 | [diff] [blame] | 734 | RAMBlock *block; |
| 735 | uint64_t total = 0; |
| 736 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 737 | rcu_read_lock(); |
| 738 | QLIST_FOREACH_RCU(block, &ram_list.blocks, next) |
Michael S. Tsirkin | 9b8424d | 2014-12-15 22:55:32 +0200 | [diff] [blame] | 739 | total += block->used_length; |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 740 | rcu_read_unlock(); |
Alex Williamson | d17b528 | 2010-06-25 11:08:38 -0600 | [diff] [blame] | 741 | return total; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Gonglei (Arei) | 905f26f | 2014-01-30 20:08:35 +0200 | [diff] [blame] | 744 | void free_xbzrle_decoded_buf(void) |
| 745 | { |
| 746 | g_free(xbzrle_decoded_buf); |
| 747 | xbzrle_decoded_buf = NULL; |
| 748 | } |
| 749 | |
Orit Wasserman | 8e21cd3 | 2012-06-19 18:43:17 +0300 | [diff] [blame] | 750 | static void migration_end(void) |
| 751 | { |
Paolo Bonzini | 244eaa7 | 2012-12-12 12:54:43 +0100 | [diff] [blame] | 752 | if (migration_bitmap) { |
| 753 | memory_global_dirty_log_stop(); |
| 754 | g_free(migration_bitmap); |
| 755 | migration_bitmap = NULL; |
| 756 | } |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 757 | |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 758 | XBZRLE_cache_lock(); |
Paolo Bonzini | 244eaa7 | 2012-12-12 12:54:43 +0100 | [diff] [blame] | 759 | if (XBZRLE.cache) { |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 760 | cache_fini(XBZRLE.cache); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 761 | g_free(XBZRLE.encoded_buf); |
| 762 | g_free(XBZRLE.current_buf); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 763 | XBZRLE.cache = NULL; |
Orit Wasserman | f6c6483 | 2014-01-30 20:08:33 +0200 | [diff] [blame] | 764 | XBZRLE.encoded_buf = NULL; |
| 765 | XBZRLE.current_buf = NULL; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 766 | } |
Gonglei | fd8cec9 | 2014-03-04 21:29:21 +0800 | [diff] [blame] | 767 | XBZRLE_cache_unlock(); |
Orit Wasserman | 8e21cd3 | 2012-06-19 18:43:17 +0300 | [diff] [blame] | 768 | } |
| 769 | |
Juan Quintela | 9b5bfab | 2012-06-26 19:26:41 +0200 | [diff] [blame] | 770 | static void ram_migration_cancel(void *opaque) |
| 771 | { |
| 772 | migration_end(); |
| 773 | } |
| 774 | |
Juan Quintela | 5a17077 | 2012-07-17 17:02:24 +0200 | [diff] [blame] | 775 | static void reset_ram_globals(void) |
| 776 | { |
Juan Quintela | b23a9a5 | 2012-10-17 20:08:04 +0200 | [diff] [blame] | 777 | last_seen_block = NULL; |
Juan Quintela | 5f718a1 | 2012-10-17 20:10:55 +0200 | [diff] [blame] | 778 | last_sent_block = NULL; |
Juan Quintela | 5a17077 | 2012-07-17 17:02:24 +0200 | [diff] [blame] | 779 | last_offset = 0; |
Umesh Deshpande | f798b07 | 2011-08-18 11:41:17 -0700 | [diff] [blame] | 780 | last_version = ram_list.version; |
Peter Lieven | 78d07ae | 2013-03-26 10:58:36 +0100 | [diff] [blame] | 781 | ram_bulk_stage = true; |
Juan Quintela | 5a17077 | 2012-07-17 17:02:24 +0200 | [diff] [blame] | 782 | } |
| 783 | |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 784 | #define MAX_WAIT 50 /* ms, half buffered_file limit */ |
| 785 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 786 | |
| 787 | /* Each of ram_save_setup, ram_save_iterate and ram_save_complete has |
| 788 | * long-running RCU critical section. When rcu-reclaims in the code |
| 789 | * start to become numerous it will be necessary to reduce the |
| 790 | * granularity of these critical sections. |
| 791 | */ |
| 792 | |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 793 | static int ram_save_setup(QEMUFile *f, void *opaque) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 794 | { |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 795 | RAMBlock *block; |
Dr. David Alan Gilbert | e30d1d8 | 2014-03-27 15:01:48 +0000 | [diff] [blame] | 796 | int64_t ram_bitmap_pages; /* Size of bitmap in pages, including gaps */ |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 797 | |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 798 | mig_throttle_on = false; |
| 799 | dirty_rate_high_cnt = 0; |
ChenLiang | 71411d3 | 2014-04-04 17:57:54 +0800 | [diff] [blame] | 800 | bitmap_sync_count = 0; |
ChenLiang | 6c1b663 | 2014-03-20 20:15:03 +0800 | [diff] [blame] | 801 | migration_bitmap_sync_init(); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 802 | |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 803 | if (migrate_use_xbzrle()) { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 804 | XBZRLE_cache_lock(); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 805 | XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() / |
| 806 | TARGET_PAGE_SIZE, |
| 807 | TARGET_PAGE_SIZE); |
| 808 | if (!XBZRLE.cache) { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 809 | XBZRLE_cache_unlock(); |
| 810 | error_report("Error creating cache"); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 811 | return -1; |
| 812 | } |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 813 | XBZRLE_cache_unlock(); |
Orit Wasserman | a17b2fd | 2014-01-30 20:08:37 +0200 | [diff] [blame] | 814 | |
| 815 | /* We prefer not to abort if there is no memory */ |
| 816 | XBZRLE.encoded_buf = g_try_malloc0(TARGET_PAGE_SIZE); |
| 817 | if (!XBZRLE.encoded_buf) { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 818 | error_report("Error allocating encoded_buf"); |
Orit Wasserman | a17b2fd | 2014-01-30 20:08:37 +0200 | [diff] [blame] | 819 | return -1; |
| 820 | } |
| 821 | |
| 822 | XBZRLE.current_buf = g_try_malloc(TARGET_PAGE_SIZE); |
| 823 | if (!XBZRLE.current_buf) { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 824 | error_report("Error allocating current_buf"); |
Orit Wasserman | a17b2fd | 2014-01-30 20:08:37 +0200 | [diff] [blame] | 825 | g_free(XBZRLE.encoded_buf); |
| 826 | XBZRLE.encoded_buf = NULL; |
| 827 | return -1; |
| 828 | } |
| 829 | |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 830 | acct_clear(); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 831 | } |
| 832 | |
Mike Day | ae3a704 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 833 | /* iothread lock needed for ram_list.dirty_memory[] */ |
Paolo Bonzini | 9b09503 | 2013-02-22 17:36:28 +0100 | [diff] [blame] | 834 | qemu_mutex_lock_iothread(); |
| 835 | qemu_mutex_lock_ramlist(); |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 836 | rcu_read_lock(); |
Paolo Bonzini | 9b09503 | 2013-02-22 17:36:28 +0100 | [diff] [blame] | 837 | bytes_transferred = 0; |
| 838 | reset_ram_globals(); |
| 839 | |
Dr. David Alan Gilbert | e30d1d8 | 2014-03-27 15:01:48 +0000 | [diff] [blame] | 840 | ram_bitmap_pages = last_ram_offset() >> TARGET_PAGE_BITS; |
| 841 | migration_bitmap = bitmap_new(ram_bitmap_pages); |
| 842 | bitmap_set(migration_bitmap, 0, ram_bitmap_pages); |
| 843 | |
| 844 | /* |
| 845 | * Count the total number of pages used by ram blocks not including any |
| 846 | * gaps due to alignment or unplugs. |
| 847 | */ |
| 848 | migration_dirty_pages = 0; |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 849 | QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { |
Dr. David Alan Gilbert | e30d1d8 | 2014-03-27 15:01:48 +0000 | [diff] [blame] | 850 | uint64_t block_pages; |
| 851 | |
Michael S. Tsirkin | 9b8424d | 2014-12-15 22:55:32 +0200 | [diff] [blame] | 852 | block_pages = block->used_length >> TARGET_PAGE_BITS; |
Dr. David Alan Gilbert | e30d1d8 | 2014-03-27 15:01:48 +0000 | [diff] [blame] | 853 | migration_dirty_pages += block_pages; |
| 854 | } |
| 855 | |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 856 | memory_global_dirty_log_start(); |
Juan Quintela | c6bf8e0 | 2012-07-20 12:33:00 +0200 | [diff] [blame] | 857 | migration_bitmap_sync(); |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 858 | qemu_mutex_unlock_ramlist(); |
Paolo Bonzini | 9b09503 | 2013-02-22 17:36:28 +0100 | [diff] [blame] | 859 | qemu_mutex_unlock_iothread(); |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 860 | |
| 861 | qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE); |
| 862 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 863 | QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 864 | qemu_put_byte(f, strlen(block->idstr)); |
| 865 | qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr)); |
Michael S. Tsirkin | 9b8424d | 2014-12-15 22:55:32 +0200 | [diff] [blame] | 866 | qemu_put_be64(f, block->used_length); |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 867 | } |
| 868 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 869 | rcu_read_unlock(); |
Michael R. Hines | 0033b8b | 2013-07-22 10:01:55 -0400 | [diff] [blame] | 870 | |
| 871 | ram_control_before_iterate(f, RAM_CONTROL_SETUP); |
| 872 | ram_control_after_iterate(f, RAM_CONTROL_SETUP); |
| 873 | |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 874 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame] | 879 | static int ram_save_iterate(QEMUFile *f, void *opaque) |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 880 | { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 881 | int ret; |
| 882 | int i; |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame] | 883 | int64_t t0; |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 884 | int total_sent = 0; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 885 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 886 | rcu_read_lock(); |
Umesh Deshpande | f798b07 | 2011-08-18 11:41:17 -0700 | [diff] [blame] | 887 | if (ram_list.version != last_version) { |
| 888 | reset_ram_globals(); |
| 889 | } |
| 890 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 891 | /* Read version before ram_list.blocks */ |
| 892 | smp_rmb(); |
| 893 | |
Michael R. Hines | 0033b8b | 2013-07-22 10:01:55 -0400 | [diff] [blame] | 894 | ram_control_before_iterate(f, RAM_CONTROL_ROUND); |
| 895 | |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 896 | t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 897 | i = 0; |
Juan Quintela | 2975725 | 2011-10-19 15:22:18 +0200 | [diff] [blame] | 898 | while ((ret = qemu_file_rate_limit(f)) == 0) { |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 899 | int bytes_sent; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 900 | |
Dr. David Alan Gilbert | 14bcfdc | 2014-05-09 11:54:55 +0100 | [diff] [blame] | 901 | bytes_sent = ram_find_and_save_block(f, false); |
Orit Wasserman | 6c779f2 | 2012-07-10 12:37:13 +0300 | [diff] [blame] | 902 | /* no more blocks to sent */ |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 903 | if (bytes_sent == 0) { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 904 | break; |
| 905 | } |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 906 | total_sent += bytes_sent; |
Orit Wasserman | 004d4c1 | 2012-08-06 21:42:56 +0300 | [diff] [blame] | 907 | acct_info.iterations++; |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 908 | check_guest_throttling(); |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 909 | /* we want to check in the 1st loop, just in case it was the 1st time |
| 910 | and we had to sync the dirty bitmap. |
| 911 | qemu_get_clock_ns() is a bit expensive, so we only check each some |
| 912 | iterations |
| 913 | */ |
| 914 | if ((i & 63) == 0) { |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 915 | uint64_t t1 = (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - t0) / 1000000; |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 916 | if (t1 > MAX_WAIT) { |
Igor Mitsyanko | ef37a69 | 2012-09-05 13:04:56 +0400 | [diff] [blame] | 917 | DPRINTF("big wait: %" PRIu64 " milliseconds, %d iterations\n", |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 918 | t1, i); |
| 919 | break; |
| 920 | } |
| 921 | } |
| 922 | i++; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 923 | } |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 924 | rcu_read_unlock(); |
Paolo Bonzini | fb3409d | 2012-12-20 11:25:45 +0100 | [diff] [blame] | 925 | |
Michael R. Hines | 0033b8b | 2013-07-22 10:01:55 -0400 | [diff] [blame] | 926 | /* |
| 927 | * Must occur before EOS (or any QEMUFile operation) |
| 928 | * because of RDMA protocol. |
| 929 | */ |
| 930 | ram_control_after_iterate(f, RAM_CONTROL_ROUND); |
| 931 | |
Lei Li | 6cd0bed | 2013-09-04 17:02:36 +0800 | [diff] [blame] | 932 | bytes_transferred += total_sent; |
| 933 | |
| 934 | /* |
| 935 | * Do not count these 8 bytes into total_sent, so that we can |
| 936 | * return 0 if no page had been dirtied. |
| 937 | */ |
| 938 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
| 939 | bytes_transferred += 8; |
| 940 | |
| 941 | ret = qemu_file_get_error(f); |
Juan Quintela | 2975725 | 2011-10-19 15:22:18 +0200 | [diff] [blame] | 942 | if (ret < 0) { |
| 943 | return ret; |
| 944 | } |
| 945 | |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 946 | return total_sent; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 947 | } |
| 948 | |
Mike Day | ae3a704 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 949 | /* Called with iothread lock */ |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame] | 950 | static int ram_save_complete(QEMUFile *f, void *opaque) |
| 951 | { |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 952 | rcu_read_lock(); |
| 953 | |
Paolo Bonzini | 9c33948 | 2012-12-20 11:26:04 +0100 | [diff] [blame] | 954 | migration_bitmap_sync(); |
Umesh Deshpande | b2a8658 | 2011-08-17 00:01:33 -0700 | [diff] [blame] | 955 | |
Michael R. Hines | 0033b8b | 2013-07-22 10:01:55 -0400 | [diff] [blame] | 956 | ram_control_before_iterate(f, RAM_CONTROL_FINISH); |
| 957 | |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame] | 958 | /* try transferring iterative blocks of memory */ |
| 959 | |
| 960 | /* flush all remaining blocks regardless of rate limiting */ |
Orit Wasserman | 6c779f2 | 2012-07-10 12:37:13 +0300 | [diff] [blame] | 961 | while (true) { |
| 962 | int bytes_sent; |
| 963 | |
Dr. David Alan Gilbert | 14bcfdc | 2014-05-09 11:54:55 +0100 | [diff] [blame] | 964 | bytes_sent = ram_find_and_save_block(f, true); |
Orit Wasserman | 6c779f2 | 2012-07-10 12:37:13 +0300 | [diff] [blame] | 965 | /* no more blocks to sent */ |
Juan Quintela | b823cea | 2012-12-10 13:27:50 +0100 | [diff] [blame] | 966 | if (bytes_sent == 0) { |
Orit Wasserman | 6c779f2 | 2012-07-10 12:37:13 +0300 | [diff] [blame] | 967 | break; |
| 968 | } |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame] | 969 | bytes_transferred += bytes_sent; |
| 970 | } |
Michael R. Hines | 0033b8b | 2013-07-22 10:01:55 -0400 | [diff] [blame] | 971 | |
| 972 | ram_control_after_iterate(f, RAM_CONTROL_FINISH); |
Paolo Bonzini | 244eaa7 | 2012-12-12 12:54:43 +0100 | [diff] [blame] | 973 | migration_end(); |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame] | 974 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 975 | rcu_read_unlock(); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 976 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
| 977 | |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 978 | return 0; |
| 979 | } |
| 980 | |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame] | 981 | static uint64_t ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size) |
| 982 | { |
| 983 | uint64_t remaining_size; |
| 984 | |
| 985 | remaining_size = ram_save_remaining() * TARGET_PAGE_SIZE; |
| 986 | |
| 987 | if (remaining_size < max_size) { |
Paolo Bonzini | 32c835b | 2013-02-22 17:36:27 +0100 | [diff] [blame] | 988 | qemu_mutex_lock_iothread(); |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 989 | rcu_read_lock(); |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame] | 990 | migration_bitmap_sync(); |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 991 | rcu_read_unlock(); |
Paolo Bonzini | 32c835b | 2013-02-22 17:36:27 +0100 | [diff] [blame] | 992 | qemu_mutex_unlock_iothread(); |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame] | 993 | remaining_size = ram_save_remaining() * TARGET_PAGE_SIZE; |
| 994 | } |
| 995 | return remaining_size; |
| 996 | } |
| 997 | |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 998 | static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) |
| 999 | { |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1000 | unsigned int xh_len; |
| 1001 | int xh_flags; |
| 1002 | |
Gonglei (Arei) | 905f26f | 2014-01-30 20:08:35 +0200 | [diff] [blame] | 1003 | if (!xbzrle_decoded_buf) { |
| 1004 | xbzrle_decoded_buf = g_malloc(TARGET_PAGE_SIZE); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /* extract RLE header */ |
| 1008 | xh_flags = qemu_get_byte(f); |
| 1009 | xh_len = qemu_get_be16(f); |
| 1010 | |
| 1011 | if (xh_flags != ENCODING_FLAG_XBZRLE) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1012 | error_report("Failed to load XBZRLE page - wrong compression!"); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1013 | return -1; |
| 1014 | } |
| 1015 | |
| 1016 | if (xh_len > TARGET_PAGE_SIZE) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1017 | error_report("Failed to load XBZRLE page - len overflow!"); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1018 | return -1; |
| 1019 | } |
| 1020 | /* load data and decode */ |
Gonglei (Arei) | 905f26f | 2014-01-30 20:08:35 +0200 | [diff] [blame] | 1021 | qemu_get_buffer(f, xbzrle_decoded_buf, xh_len); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1022 | |
| 1023 | /* decode RLE */ |
Chen Gang | fb62666 | 2014-05-10 20:51:24 +0800 | [diff] [blame] | 1024 | if (xbzrle_decode_buffer(xbzrle_decoded_buf, xh_len, host, |
| 1025 | TARGET_PAGE_SIZE) == -1) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1026 | error_report("Failed to load XBZRLE page - decode error!"); |
Chen Gang | fb62666 | 2014-05-10 20:51:24 +0800 | [diff] [blame] | 1027 | return -1; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1028 | } |
| 1029 | |
Chen Gang | fb62666 | 2014-05-10 20:51:24 +0800 | [diff] [blame] | 1030 | return 0; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1031 | } |
| 1032 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 1033 | /* Must be called from within a rcu critical section. |
| 1034 | * Returns a pointer from within the RCU-protected ram_list. |
| 1035 | */ |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 1036 | static inline void *host_from_stream_offset(QEMUFile *f, |
| 1037 | ram_addr_t offset, |
| 1038 | int flags) |
| 1039 | { |
| 1040 | static RAMBlock *block = NULL; |
| 1041 | char id[256]; |
| 1042 | uint8_t len; |
| 1043 | |
| 1044 | if (flags & RAM_SAVE_FLAG_CONTINUE) { |
Michael S. Tsirkin | 9b8424d | 2014-12-15 22:55:32 +0200 | [diff] [blame] | 1045 | if (!block || block->max_length <= offset) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1046 | error_report("Ack, bad migration stream!"); |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 1047 | return NULL; |
| 1048 | } |
| 1049 | |
Avi Kivity | dc94a7e | 2011-12-21 13:54:33 +0200 | [diff] [blame] | 1050 | return memory_region_get_ram_ptr(block->mr) + offset; |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | len = qemu_get_byte(f); |
| 1054 | qemu_get_buffer(f, (uint8_t *)id, len); |
| 1055 | id[len] = 0; |
| 1056 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 1057 | QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { |
Michael S. Tsirkin | 9b8424d | 2014-12-15 22:55:32 +0200 | [diff] [blame] | 1058 | if (!strncmp(id, block->idstr, sizeof(id)) && |
| 1059 | block->max_length > offset) { |
Avi Kivity | dc94a7e | 2011-12-21 13:54:33 +0200 | [diff] [blame] | 1060 | return memory_region_get_ram_ptr(block->mr) + offset; |
Michael S. Tsirkin | 0be839a | 2014-11-12 11:44:39 +0200 | [diff] [blame] | 1061 | } |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 1062 | } |
| 1063 | |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1064 | error_report("Can't find block %s!", id); |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 1065 | return NULL; |
| 1066 | } |
| 1067 | |
Michael R. Hines | 44c3b58 | 2013-07-22 10:01:53 -0400 | [diff] [blame] | 1068 | /* |
| 1069 | * If a page (or a whole RDMA chunk) has been |
| 1070 | * determined to be zero, then zap it. |
| 1071 | */ |
| 1072 | void ram_handle_compressed(void *host, uint8_t ch, uint64_t size) |
| 1073 | { |
Isaku Yamahata | d613a56 | 2013-09-21 01:23:37 +0900 | [diff] [blame] | 1074 | if (ch != 0 || !is_zero_range(host, size)) { |
Michael R. Hines | 44c3b58 | 2013-07-22 10:01:53 -0400 | [diff] [blame] | 1075 | memset(host, ch, size); |
Michael R. Hines | 44c3b58 | 2013-07-22 10:01:53 -0400 | [diff] [blame] | 1076 | } |
| 1077 | } |
| 1078 | |
Juan Quintela | 7908c78 | 2012-06-26 18:46:10 +0200 | [diff] [blame] | 1079 | static int ram_load(QEMUFile *f, void *opaque, int version_id) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1080 | { |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1081 | int flags = 0, ret = 0; |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 1082 | static uint64_t seq_iter; |
| 1083 | |
| 1084 | seq_iter++; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1085 | |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1086 | if (version_id != 4) { |
Chen Gang | 4798fe5 | 2014-05-01 21:28:11 +0800 | [diff] [blame] | 1087 | ret = -EINVAL; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 1090 | /* This RCU critical section can be very long running. |
| 1091 | * When RCU reclaims in the code start to become numerous, |
| 1092 | * it will be necessary to reduce the granularity of this |
| 1093 | * critical section. |
| 1094 | */ |
| 1095 | rcu_read_lock(); |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1096 | while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) { |
| 1097 | ram_addr_t addr, total_ram_bytes; |
| 1098 | void *host; |
| 1099 | uint8_t ch; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1100 | |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1101 | addr = qemu_get_be64(f); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1102 | flags = addr & ~TARGET_PAGE_MASK; |
| 1103 | addr &= TARGET_PAGE_MASK; |
| 1104 | |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1105 | switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { |
| 1106 | case RAM_SAVE_FLAG_MEM_SIZE: |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1107 | /* Synchronize RAM block list */ |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1108 | total_ram_bytes = addr; |
| 1109 | while (!ret && total_ram_bytes) { |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1110 | RAMBlock *block; |
| 1111 | uint8_t len; |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1112 | char id[256]; |
| 1113 | ram_addr_t length; |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 1114 | |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1115 | len = qemu_get_byte(f); |
| 1116 | qemu_get_buffer(f, (uint8_t *)id, len); |
| 1117 | id[len] = 0; |
| 1118 | length = qemu_get_be64(f); |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 1119 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 1120 | QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1121 | if (!strncmp(id, block->idstr, sizeof(id))) { |
Michael S. Tsirkin | b0cc3f8 | 2014-11-17 17:55:43 +0200 | [diff] [blame] | 1122 | if (length != block->used_length) { |
| 1123 | Error *local_err = NULL; |
| 1124 | |
| 1125 | ret = qemu_ram_resize(block->offset, length, &local_err); |
| 1126 | if (local_err) { |
Markus Armbruster | 565f65d | 2015-02-12 13:55:05 +0100 | [diff] [blame] | 1127 | error_report_err(local_err); |
Michael S. Tsirkin | b0cc3f8 | 2014-11-17 17:55:43 +0200 | [diff] [blame] | 1128 | } |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 1129 | } |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1130 | break; |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 1131 | } |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 1132 | } |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1133 | |
| 1134 | if (!block) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1135 | error_report("Unknown ramblock \"%s\", cannot " |
| 1136 | "accept migration", id); |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1137 | ret = -EINVAL; |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1138 | } |
ChenLiang | 21a246a | 2014-04-25 17:06:20 +0800 | [diff] [blame] | 1139 | |
| 1140 | total_ram_bytes -= length; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1141 | } |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1142 | break; |
| 1143 | case RAM_SAVE_FLAG_COMPRESS: |
Avi Kivity | f09f218 | 2011-12-21 13:37:56 +0200 | [diff] [blame] | 1144 | host = host_from_stream_offset(f, addr, flags); |
Michael S. Tsirkin | 492fb99 | 2010-10-17 20:43:40 +0200 | [diff] [blame] | 1145 | if (!host) { |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1146 | error_report("Illegal RAM offset " RAM_ADDR_FMT, addr); |
Chen Gang | 4798fe5 | 2014-05-01 21:28:11 +0800 | [diff] [blame] | 1147 | ret = -EINVAL; |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1148 | break; |
Michael S. Tsirkin | 492fb99 | 2010-10-17 20:43:40 +0200 | [diff] [blame] | 1149 | } |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 1150 | ch = qemu_get_byte(f); |
Michael R. Hines | 44c3b58 | 2013-07-22 10:01:53 -0400 | [diff] [blame] | 1151 | ram_handle_compressed(host, ch, TARGET_PAGE_SIZE); |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1152 | break; |
| 1153 | case RAM_SAVE_FLAG_PAGE: |
Avi Kivity | f09f218 | 2011-12-21 13:37:56 +0200 | [diff] [blame] | 1154 | host = host_from_stream_offset(f, addr, flags); |
Orit Wasserman | 0ff1f9f | 2012-06-19 11:51:37 +0300 | [diff] [blame] | 1155 | if (!host) { |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1156 | error_report("Illegal RAM offset " RAM_ADDR_FMT, addr); |
Chen Gang | 4798fe5 | 2014-05-01 21:28:11 +0800 | [diff] [blame] | 1157 | ret = -EINVAL; |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1158 | break; |
Orit Wasserman | 0ff1f9f | 2012-06-19 11:51:37 +0300 | [diff] [blame] | 1159 | } |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 1160 | qemu_get_buffer(f, host, TARGET_PAGE_SIZE); |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1161 | break; |
| 1162 | case RAM_SAVE_FLAG_XBZRLE: |
| 1163 | host = host_from_stream_offset(f, addr, flags); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1164 | if (!host) { |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1165 | error_report("Illegal RAM offset " RAM_ADDR_FMT, addr); |
Chen Gang | 4798fe5 | 2014-05-01 21:28:11 +0800 | [diff] [blame] | 1166 | ret = -EINVAL; |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1167 | break; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1168 | } |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1169 | if (load_xbzrle(f, addr, host) < 0) { |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1170 | error_report("Failed to decompress XBZRLE page at " |
| 1171 | RAM_ADDR_FMT, addr); |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1172 | ret = -EINVAL; |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1173 | break; |
Orit Wasserman | 17ad9b3 | 2012-08-06 21:42:53 +0300 | [diff] [blame] | 1174 | } |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1175 | break; |
| 1176 | case RAM_SAVE_FLAG_EOS: |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1177 | /* normal exit */ |
| 1178 | break; |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1179 | default: |
| 1180 | if (flags & RAM_SAVE_FLAG_HOOK) { |
| 1181 | ram_control_load_hook(f, flags); |
| 1182 | } else { |
| 1183 | error_report("Unknown combination of migration flags: %#x", |
| 1184 | flags); |
| 1185 | ret = -EINVAL; |
| 1186 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1187 | } |
Peter Lieven | 5b0e9dd | 2014-06-24 11:32:36 +0200 | [diff] [blame] | 1188 | if (!ret) { |
| 1189 | ret = qemu_file_get_error(f); |
| 1190 | } |
Peter Lieven | db80fac | 2014-06-10 11:29:16 +0200 | [diff] [blame] | 1191 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1192 | |
Mike Day | 0dc3f44 | 2013-09-05 14:41:35 -0400 | [diff] [blame] | 1193 | rcu_read_unlock(); |
Igor Mitsyanko | ef37a69 | 2012-09-05 13:04:56 +0400 | [diff] [blame] | 1194 | DPRINTF("Completed load of VM with exit code %d seq iteration " |
| 1195 | "%" PRIu64 "\n", ret, seq_iter); |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 1196 | return ret; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Dr. David Alan Gilbert | 0d6ab3a | 2014-03-19 18:32:30 +0000 | [diff] [blame] | 1199 | static SaveVMHandlers savevm_ram_handlers = { |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 1200 | .save_live_setup = ram_save_setup, |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame] | 1201 | .save_live_iterate = ram_save_iterate, |
| 1202 | .save_live_complete = ram_save_complete, |
Juan Quintela | e4ed154 | 2012-09-21 11:18:18 +0200 | [diff] [blame] | 1203 | .save_live_pending = ram_save_pending, |
Juan Quintela | 7908c78 | 2012-06-26 18:46:10 +0200 | [diff] [blame] | 1204 | .load_state = ram_load, |
Juan Quintela | 9b5bfab | 2012-06-26 19:26:41 +0200 | [diff] [blame] | 1205 | .cancel = ram_migration_cancel, |
Juan Quintela | 7908c78 | 2012-06-26 18:46:10 +0200 | [diff] [blame] | 1206 | }; |
| 1207 | |
Dr. David Alan Gilbert | 0d6ab3a | 2014-03-19 18:32:30 +0000 | [diff] [blame] | 1208 | void ram_mig_init(void) |
| 1209 | { |
Dr. David Alan Gilbert | d97326e | 2014-03-19 18:32:31 +0000 | [diff] [blame] | 1210 | qemu_mutex_init(&XBZRLE.lock); |
Dr. David Alan Gilbert | 0d6ab3a | 2014-03-19 18:32:30 +0000 | [diff] [blame] | 1211 | register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL); |
| 1212 | } |
| 1213 | |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1214 | struct soundhw { |
| 1215 | const char *name; |
| 1216 | const char *descr; |
| 1217 | int enabled; |
| 1218 | int isa; |
| 1219 | union { |
Hervé Poussineau | 4a0f031 | 2011-12-15 22:10:01 +0100 | [diff] [blame] | 1220 | int (*init_isa) (ISABus *bus); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1221 | int (*init_pci) (PCIBus *bus); |
| 1222 | } init; |
| 1223 | }; |
| 1224 | |
Paolo Bonzini | 36cd6f6 | 2013-04-18 18:43:58 +0200 | [diff] [blame] | 1225 | static struct soundhw soundhw[9]; |
| 1226 | static int soundhw_count; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1227 | |
Paolo Bonzini | 36cd6f6 | 2013-04-18 18:43:58 +0200 | [diff] [blame] | 1228 | void isa_register_soundhw(const char *name, const char *descr, |
| 1229 | int (*init_isa)(ISABus *bus)) |
| 1230 | { |
| 1231 | assert(soundhw_count < ARRAY_SIZE(soundhw) - 1); |
| 1232 | soundhw[soundhw_count].name = name; |
| 1233 | soundhw[soundhw_count].descr = descr; |
| 1234 | soundhw[soundhw_count].isa = 1; |
| 1235 | soundhw[soundhw_count].init.init_isa = init_isa; |
| 1236 | soundhw_count++; |
| 1237 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1238 | |
Paolo Bonzini | 36cd6f6 | 2013-04-18 18:43:58 +0200 | [diff] [blame] | 1239 | void pci_register_soundhw(const char *name, const char *descr, |
| 1240 | int (*init_pci)(PCIBus *bus)) |
| 1241 | { |
| 1242 | assert(soundhw_count < ARRAY_SIZE(soundhw) - 1); |
| 1243 | soundhw[soundhw_count].name = name; |
| 1244 | soundhw[soundhw_count].descr = descr; |
| 1245 | soundhw[soundhw_count].isa = 0; |
| 1246 | soundhw[soundhw_count].init.init_pci = init_pci; |
| 1247 | soundhw_count++; |
| 1248 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1249 | |
| 1250 | void select_soundhw(const char *optarg) |
| 1251 | { |
| 1252 | struct soundhw *c; |
| 1253 | |
Peter Maydell | c8057f9 | 2012-08-02 13:45:54 +0100 | [diff] [blame] | 1254 | if (is_help_option(optarg)) { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1255 | show_valid_cards: |
| 1256 | |
Paolo Bonzini | 36cd6f6 | 2013-04-18 18:43:58 +0200 | [diff] [blame] | 1257 | if (soundhw_count) { |
| 1258 | printf("Valid sound card names (comma separated):\n"); |
| 1259 | for (c = soundhw; c->name; ++c) { |
| 1260 | printf ("%-11s %s\n", c->name, c->descr); |
| 1261 | } |
| 1262 | printf("\n-soundhw all will enable all of the above\n"); |
| 1263 | } else { |
| 1264 | printf("Machine has no user-selectable audio hardware " |
| 1265 | "(it may or may not have always-present audio hardware).\n"); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1266 | } |
Peter Maydell | c8057f9 | 2012-08-02 13:45:54 +0100 | [diff] [blame] | 1267 | exit(!is_help_option(optarg)); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1268 | } |
| 1269 | else { |
| 1270 | size_t l; |
| 1271 | const char *p; |
| 1272 | char *e; |
| 1273 | int bad_card = 0; |
| 1274 | |
| 1275 | if (!strcmp(optarg, "all")) { |
| 1276 | for (c = soundhw; c->name; ++c) { |
| 1277 | c->enabled = 1; |
| 1278 | } |
| 1279 | return; |
| 1280 | } |
| 1281 | |
| 1282 | p = optarg; |
| 1283 | while (*p) { |
| 1284 | e = strchr(p, ','); |
| 1285 | l = !e ? strlen(p) : (size_t) (e - p); |
| 1286 | |
| 1287 | for (c = soundhw; c->name; ++c) { |
| 1288 | if (!strncmp(c->name, p, l) && !c->name[l]) { |
| 1289 | c->enabled = 1; |
| 1290 | break; |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | if (!c->name) { |
| 1295 | if (l > 80) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1296 | error_report("Unknown sound card name (too big to show)"); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1297 | } |
| 1298 | else { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1299 | error_report("Unknown sound card name `%.*s'", |
| 1300 | (int) l, p); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1301 | } |
| 1302 | bad_card = 1; |
| 1303 | } |
| 1304 | p += l + (e != NULL); |
| 1305 | } |
| 1306 | |
| 1307 | if (bad_card) { |
| 1308 | goto show_valid_cards; |
| 1309 | } |
| 1310 | } |
| 1311 | } |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1312 | |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1313 | void audio_init(void) |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1314 | { |
| 1315 | struct soundhw *c; |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1316 | ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL); |
| 1317 | PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1318 | |
| 1319 | for (c = soundhw; c->name; ++c) { |
| 1320 | if (c->enabled) { |
| 1321 | if (c->isa) { |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1322 | if (!isa_bus) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1323 | error_report("ISA bus not available for %s", c->name); |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1324 | exit(1); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1325 | } |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1326 | c->init.init_isa(isa_bus); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1327 | } else { |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1328 | if (!pci_bus) { |
Le Tan | 0971f1b | 2014-05-21 08:10:38 +0800 | [diff] [blame] | 1329 | error_report("PCI bus not available for %s", c->name); |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1330 | exit(1); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1331 | } |
Paolo Bonzini | f81222b | 2013-04-18 18:44:03 +0200 | [diff] [blame] | 1332 | c->init.init_pci(pci_bus); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | } |
| 1336 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1337 | |
| 1338 | int qemu_uuid_parse(const char *str, uint8_t *uuid) |
| 1339 | { |
| 1340 | int ret; |
| 1341 | |
| 1342 | if (strlen(str) != 36) { |
| 1343 | return -1; |
| 1344 | } |
| 1345 | |
| 1346 | ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3], |
| 1347 | &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9], |
| 1348 | &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], |
| 1349 | &uuid[15]); |
| 1350 | |
| 1351 | if (ret != 16) { |
| 1352 | return -1; |
| 1353 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1354 | return 0; |
| 1355 | } |
| 1356 | |
Laszlo Ersek | 0c764a9 | 2013-03-21 00:23:17 +0100 | [diff] [blame] | 1357 | void do_acpitable_option(const QemuOpts *opts) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1358 | { |
| 1359 | #ifdef TARGET_I386 |
Laszlo Ersek | 2308432 | 2013-03-21 00:23:19 +0100 | [diff] [blame] | 1360 | Error *err = NULL; |
| 1361 | |
| 1362 | acpi_table_add(opts, &err); |
| 1363 | if (err) { |
Seiji Aguchi | 4a44d85 | 2013-08-05 15:40:44 -0400 | [diff] [blame] | 1364 | error_report("Wrong acpi table provided: %s", |
| 1365 | error_get_pretty(err)); |
Laszlo Ersek | 2308432 | 2013-03-21 00:23:19 +0100 | [diff] [blame] | 1366 | error_free(err); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1367 | exit(1); |
| 1368 | } |
| 1369 | #endif |
| 1370 | } |
| 1371 | |
Markus Armbruster | 4f953d2 | 2013-08-16 15:18:29 +0200 | [diff] [blame] | 1372 | void do_smbios_option(QemuOpts *opts) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1373 | { |
| 1374 | #ifdef TARGET_I386 |
Markus Armbruster | 4f953d2 | 2013-08-16 15:18:29 +0200 | [diff] [blame] | 1375 | smbios_entry_add(opts); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1376 | #endif |
| 1377 | } |
| 1378 | |
| 1379 | void cpudef_init(void) |
| 1380 | { |
| 1381 | #if defined(cpudef_setup) |
| 1382 | cpudef_setup(); /* parse cpu definitions in target config file */ |
| 1383 | #endif |
| 1384 | } |
| 1385 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 1386 | int kvm_available(void) |
| 1387 | { |
| 1388 | #ifdef CONFIG_KVM |
| 1389 | return 1; |
| 1390 | #else |
| 1391 | return 0; |
| 1392 | #endif |
| 1393 | } |
| 1394 | |
| 1395 | int xen_available(void) |
| 1396 | { |
| 1397 | #ifdef CONFIG_XEN |
| 1398 | return 1; |
| 1399 | #else |
| 1400 | return 0; |
| 1401 | #endif |
| 1402 | } |
Daniel P. Berrange | 99afc91 | 2012-08-20 15:31:38 +0100 | [diff] [blame] | 1403 | |
| 1404 | |
| 1405 | TargetInfo *qmp_query_target(Error **errp) |
| 1406 | { |
| 1407 | TargetInfo *info = g_malloc0(sizeof(*info)); |
| 1408 | |
Paolo Bonzini | c02a955 | 2013-06-04 14:45:28 +0200 | [diff] [blame] | 1409 | info->arch = g_strdup(TARGET_NAME); |
Daniel P. Berrange | 99afc91 | 2012-08-20 15:31:38 +0100 | [diff] [blame] | 1410 | |
| 1411 | return info; |
| 1412 | } |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 1413 | |
| 1414 | /* Stub function that's gets run on the vcpu when its brought out of the |
| 1415 | VM to run inside qemu via async_run_on_cpu()*/ |
| 1416 | static void mig_sleep_cpu(void *opq) |
| 1417 | { |
| 1418 | qemu_mutex_unlock_iothread(); |
| 1419 | g_usleep(30*1000); |
| 1420 | qemu_mutex_lock_iothread(); |
| 1421 | } |
| 1422 | |
| 1423 | /* To reduce the dirty rate explicitly disallow the VCPUs from spending |
| 1424 | much time in the VM. The migration thread will try to catchup. |
| 1425 | Workload will experience a performance drop. |
| 1426 | */ |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 1427 | static void mig_throttle_guest_down(void) |
| 1428 | { |
Andreas Färber | 38fcbd3 | 2013-07-07 19:50:23 +0200 | [diff] [blame] | 1429 | CPUState *cpu; |
| 1430 | |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 1431 | qemu_mutex_lock_iothread(); |
Andreas Färber | 38fcbd3 | 2013-07-07 19:50:23 +0200 | [diff] [blame] | 1432 | CPU_FOREACH(cpu) { |
| 1433 | async_run_on_cpu(cpu, mig_sleep_cpu, NULL); |
| 1434 | } |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 1435 | qemu_mutex_unlock_iothread(); |
| 1436 | } |
| 1437 | |
| 1438 | static void check_guest_throttling(void) |
| 1439 | { |
| 1440 | static int64_t t0; |
| 1441 | int64_t t1; |
| 1442 | |
| 1443 | if (!mig_throttle_on) { |
| 1444 | return; |
| 1445 | } |
| 1446 | |
| 1447 | if (!t0) { |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 1448 | t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 1449 | return; |
| 1450 | } |
| 1451 | |
Alex Bligh | bc72ad6 | 2013-08-21 16:03:08 +0100 | [diff] [blame] | 1452 | t1 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); |
Chegu Vinod | 7ca1dfa | 2013-06-24 03:47:39 -0600 | [diff] [blame] | 1453 | |
| 1454 | /* If it has been more than 40 ms since the last time the guest |
| 1455 | * was throttled then do it again. |
| 1456 | */ |
| 1457 | if (40 < (t1-t0)/1000000) { |
| 1458 | mig_throttle_guest_down(); |
| 1459 | t0 = t1; |
| 1460 | } |
| 1461 | } |