]>
Commit | Line | Data |
---|---|---|
947701cc JQ |
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 | ||
13 | #include "qemu/osdep.h" | |
14 | #include "qemu/stats64.h" | |
e1fde0e0 | 15 | #include "qemu-file.h" |
3db9c05a | 16 | #include "trace.h" |
947701cc JQ |
17 | #include "migration-stats.h" |
18 | ||
96820df2 | 19 | MigrationAtomicStats mig_stats; |
e1fde0e0 JQ |
20 | |
21 | bool migration_rate_exceeded(QEMUFile *f) | |
22 | { | |
23 | if (qemu_file_get_error(f)) { | |
24 | return true; | |
25 | } | |
26 | ||
813cd616 JQ |
27 | uint64_t rate_limit_start = stat64_get(&mig_stats.rate_limit_start); |
28 | uint64_t rate_limit_current = migration_transferred_bytes(f); | |
29 | uint64_t rate_limit_used = rate_limit_current - rate_limit_start; | |
e1fde0e0 JQ |
30 | uint64_t rate_limit_max = stat64_get(&mig_stats.rate_limit_max); |
31 | ||
32 | if (rate_limit_max == RATE_LIMIT_DISABLED) { | |
33 | return false; | |
34 | } | |
35 | if (rate_limit_max > 0 && rate_limit_used > rate_limit_max) { | |
36 | return true; | |
37 | } | |
38 | return false; | |
39 | } | |
40 | ||
41 | uint64_t migration_rate_get(void) | |
42 | { | |
43 | return stat64_get(&mig_stats.rate_limit_max); | |
44 | } | |
45 | ||
46 | #define XFER_LIMIT_RATIO (1000 / BUFFER_DELAY) | |
47 | ||
48 | void migration_rate_set(uint64_t limit) | |
49 | { | |
50 | /* | |
d8b71d96 | 51 | * 'limit' is per second. But we check it each BUFFER_DELAY milliseconds. |
e1fde0e0 JQ |
52 | */ |
53 | stat64_set(&mig_stats.rate_limit_max, limit / XFER_LIMIT_RATIO); | |
54 | } | |
55 | ||
813cd616 | 56 | void migration_rate_reset(QEMUFile *f) |
e1fde0e0 | 57 | { |
813cd616 | 58 | stat64_set(&mig_stats.rate_limit_start, migration_transferred_bytes(f)); |
e1fde0e0 JQ |
59 | } |
60 | ||
99319e2d JQ |
61 | uint64_t migration_transferred_bytes(QEMUFile *f) |
62 | { | |
3db9c05a | 63 | uint64_t multifd = stat64_get(&mig_stats.multifd_bytes); |
67c31c9c | 64 | uint64_t rdma = stat64_get(&mig_stats.rdma_bytes); |
3db9c05a JQ |
65 | uint64_t qemu_file = qemu_file_transferred(f); |
66 | ||
67c31c9c JQ |
67 | trace_migration_transferred_bytes(qemu_file, multifd, rdma); |
68 | return qemu_file + multifd + rdma; | |
99319e2d | 69 | } |