migration-stats.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Migration stats
  3. *
  4. * Copyright (c) 2012-2023 Red Hat Inc
  5. *
  6. * Authors:
  7. * Juan Quintela <quintela@redhat.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #ifndef QEMU_MIGRATION_STATS_H
  13. #define QEMU_MIGRATION_STATS_H
  14. #include "qemu/stats64.h"
  15. /*
  16. * Amount of time to allocate to each "chunk" of bandwidth-throttled
  17. * data.
  18. */
  19. #define BUFFER_DELAY 100
  20. /*
  21. * If rate_limit_max is 0, there is special code to remove the rate
  22. * limit.
  23. */
  24. #define RATE_LIMIT_DISABLED 0
  25. /*
  26. * These are the ram migration statistic counters. It is loosely
  27. * based on MigrationStats. We change to Stat64 any counter that
  28. * needs to be updated using atomic ops (can be accessed by more than
  29. * one thread).
  30. */
  31. typedef struct {
  32. /*
  33. * Number of bytes that were dirty last time that we synced with
  34. * the guest memory. We use that to calculate the downtime. As
  35. * the remaining dirty amounts to what we know that is still dirty
  36. * since last iteration, not counting what the guest has dirtied
  37. * since we synchronized bitmaps.
  38. */
  39. Stat64 dirty_bytes_last_sync;
  40. /*
  41. * Number of pages dirtied per second.
  42. */
  43. Stat64 dirty_pages_rate;
  44. /*
  45. * Number of times we have synchronized guest bitmaps.
  46. */
  47. Stat64 dirty_sync_count;
  48. /*
  49. * Number of times zero copy failed to send any page using zero
  50. * copy.
  51. */
  52. Stat64 dirty_sync_missed_zero_copy;
  53. /*
  54. * Number of bytes sent at migration completion stage while the
  55. * guest is stopped.
  56. */
  57. Stat64 downtime_bytes;
  58. /*
  59. * Number of bytes sent through multifd channels.
  60. */
  61. Stat64 multifd_bytes;
  62. /*
  63. * Number of pages transferred that were not full of zeros.
  64. */
  65. Stat64 normal_pages;
  66. /*
  67. * Number of bytes sent during postcopy.
  68. */
  69. Stat64 postcopy_bytes;
  70. /*
  71. * Number of postcopy page faults that we have handled during
  72. * postcopy stage.
  73. */
  74. Stat64 postcopy_requests;
  75. /*
  76. * Number of bytes sent during precopy stage.
  77. */
  78. Stat64 precopy_bytes;
  79. /*
  80. * Number of bytes transferred with QEMUFile.
  81. */
  82. Stat64 qemu_file_transferred;
  83. /*
  84. * Amount of transferred data at the start of current cycle.
  85. */
  86. Stat64 rate_limit_start;
  87. /*
  88. * Maximum amount of data we can send in a cycle.
  89. */
  90. Stat64 rate_limit_max;
  91. /*
  92. * Number of bytes sent through RDMA.
  93. */
  94. Stat64 rdma_bytes;
  95. /*
  96. * Number of pages transferred that were full of zeros.
  97. */
  98. Stat64 zero_pages;
  99. } MigrationAtomicStats;
  100. extern MigrationAtomicStats mig_stats;
  101. /**
  102. * migration_rate_get: Get the maximum amount that can be transferred.
  103. *
  104. * Returns the maximum number of bytes that can be transferred in a cycle.
  105. */
  106. uint64_t migration_rate_get(void);
  107. /**
  108. * migration_rate_reset: Reset the rate limit counter.
  109. *
  110. * This is called when we know we start a new transfer cycle.
  111. */
  112. void migration_rate_reset(void);
  113. /**
  114. * migration_rate_set: Set the maximum amount that can be transferred.
  115. *
  116. * Sets the maximum amount of bytes that can be transferred in one cycle.
  117. *
  118. * @new_rate: new maximum amount
  119. */
  120. void migration_rate_set(uint64_t new_rate);
  121. /**
  122. * migration_transferred_bytes: Return number of bytes transferred
  123. *
  124. * Returns how many bytes have we transferred since the beginning of
  125. * the migration. It accounts for bytes sent through any migration
  126. * channel, multifd, qemu_file, rdma, ....
  127. */
  128. uint64_t migration_transferred_bytes(void);
  129. #endif