aboutsummaryrefslogtreecommitdiff
path: root/util/bitmap.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2022-11-21 09:26:18 -0500
committerStefan Hajnoczi <stefanha@redhat.com>2022-11-21 09:26:18 -0500
commitaf29446f32df4f369d4ee32d721fc3c989095731 (patch)
tree48d402001ba9b7f0f7a8439359a2683bbb7536ff /util/bitmap.c
parent050143bfc70c1d7d623fa48d2f82830ebf5775b1 (diff)
parentb5280437a7f49cf617cdd99bbbe2c7bd1652408b (diff)
downloadqemu-af29446f32df4f369d4ee32d721fc3c989095731.zip
qemu-af29446f32df4f369d4ee32d721fc3c989095731.tar.gz
qemu-af29446f32df4f369d4ee32d721fc3c989095731.tar.bz2
Merge tag 'next-pull-request' of https://gitlab.com/juan.quintela/qemu into staging
Migration PULL request (take 3) Hi Drop everything that is not a bug fix: - fixes by peter - fix comment on block creation (me) - fix return values from qio_channel_block() Please, apply. (take 1) It includes: - Leonardo fix for zero_copy flush - Fiona fix for return value of readv/writev - Peter Xu cleanups - Peter Xu preempt patches - Patches ready from zero page (me) - AVX2 support (ling) - fix for slow networking and reordering of first packets (manish) Please, apply. # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEEGJn/jt6/WMzuA0uC9IfvGFhy1yMFAmN7dhUACgkQ9IfvGFhy # 1yN0GhAAmpBGFomPXqOhixXcZdCOpFvLVKU13O+okp2NgY9W5Qlicf6ANo0cbvUh # VVLCnXToySbP+7TLLqZjT4mVgM6EUIk1xqUXXICJ1mXIznvMnMtnseMNX033E2RL # mhIVx+2AsoClWR9AdQVrzvjwR/gmzEa915w1HnHVfLFSPWmIfd9iWvOEenf5SYY5 # R7yAq0tWohOAtPiyrFAchcyTidW7pB2ZqD85ZEuGQ6EBpPxHM2NZ46NuK52j02k3 # eKGrKBFAh4QTRf5+QT0ASAGUqxPYM3iT/WOw3FZkZDQoedcReeECgDh1gfdd27iH # Rebn+UHThgofBAspFVrJs9rSVlOnDdDp7yY1YDC6s6285Dci9JyWe0raIyvfdBK7 # h+AtBFLZVkIR0LXu4NlVe4IHnO5t/XVsLPwZ+7SQ9fc3gezAn4kAiEf+m8umTgho # n3Jo+2dl52QoMOW2OsX9199g0lorQAby6bJVG4xbq82ijE9N1NHuLe44w9OGZTKg # 697cNPDaoSRrvAdCPPh5KaZXsxpfLPxoMlZWxCTsNvs/jCzGs7AnvbU0QHlB+skU # R2Ae42QBq6ZSogtN8tNZFPH82Z6xTOJNILtmMgEQGAjLf3yOd8T5gZLsYNujTOyJ # ZsahXU0yRTkGmCkzCyr//mGu4KEPWtDOq27QqQPFfayvhr16ECw= # =dosb # -----END PGP SIGNATURE----- # gpg: Signature made Mon 21 Nov 2022 07:59:01 EST # gpg: using RSA key 1899FF8EDEBF58CCEE034B82F487EF185872D723 # gpg: Good signature from "Juan Quintela <quintela@redhat.com>" [full] # gpg: aka "Juan Quintela <quintela@trasno.org>" [full] # Primary key fingerprint: 1899 FF8E DEBF 58CC EE03 4B82 F487 EF18 5872 D723 * tag 'next-pull-request' of https://gitlab.com/juan.quintela/qemu: migration: Block migration comment or code is wrong migration: Disable multifd explicitly with compression migration: Use non-atomic ops for clear log bitmap migration: Disallow postcopy preempt to be used with compress migration: Fix race on qemu_file_shutdown() migration: Fix possible infinite loop of ram save process migration/multifd/zero-copy: Create helper function for flushing migration/channel-block: fix return value for qio_channel_block_{readv,writev} Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'util/bitmap.c')
-rw-r--r--util/bitmap.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/util/bitmap.c b/util/bitmap.c
index f81d805..8d12e90 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -240,6 +240,51 @@ void bitmap_clear(unsigned long *map, long start, long nr)
}
}
+bool bitmap_test_and_clear(unsigned long *map, long start, long nr)
+{
+ unsigned long *p = map + BIT_WORD(start);
+ const long size = start + nr;
+ int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
+ unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
+ bool dirty = false;
+
+ assert(start >= 0 && nr >= 0);
+
+ /* First word */
+ if (nr - bits_to_clear > 0) {
+ if ((*p) & mask_to_clear) {
+ dirty = true;
+ }
+ *p &= ~mask_to_clear;
+ nr -= bits_to_clear;
+ bits_to_clear = BITS_PER_LONG;
+ p++;
+ }
+
+ /* Full words */
+ if (bits_to_clear == BITS_PER_LONG) {
+ while (nr >= BITS_PER_LONG) {
+ if (*p) {
+ dirty = true;
+ *p = 0;
+ }
+ nr -= BITS_PER_LONG;
+ p++;
+ }
+ }
+
+ /* Last word */
+ if (nr) {
+ mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
+ if ((*p) & mask_to_clear) {
+ dirty = true;
+ }
+ *p &= ~mask_to_clear;
+ }
+
+ return dirty;
+}
+
bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr)
{
unsigned long *p = map + BIT_WORD(start);