[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/16] bitmap: provide to_le/from_le helpers
From: |
Juan Quintela |
Subject: |
[Qemu-devel] [PULL 12/16] bitmap: provide to_le/from_le helpers |
Date: |
Wed, 20 Sep 2017 12:46:35 +0200 |
From: Peter Xu <address@hidden>
Provide helpers to convert bitmaps to little endian format. It can be
used when we want to send one bitmap via network to some other hosts.
One thing to mention is that, these helpers only solve the problem of
endianess, but it does not solve the problem of different word size on
machines (the bitmaps managing same count of bits may contains different
size when malloced). So we need to take care of the size alignment issue
on the callers for now.
Signed-off-by: Peter Xu <address@hidden>
Reviewed-by: Juan Quintela <address@hidden>
Signed-off-by: Juan Quintela <address@hidden>
---
include/qemu/bitmap.h | 7 +++++++
util/bitmap.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 2718706edb..509eeddece 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -39,6 +39,8 @@
* bitmap_clear(dst, pos, nbits) Clear specified bit area
* bitmap_test_and_clear_atomic(dst, pos, nbits) Test and clear area
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
+ * bitmap_to_le(dst, src, nbits) Convert bitmap to little endian
+ * bitmap_from_le(dst, src, nbits) Convert bitmap from little endian
*/
/*
@@ -247,4 +249,9 @@ static inline unsigned long *bitmap_zero_extend(unsigned
long *old,
return new;
}
+void bitmap_to_le(unsigned long *dst, const unsigned long *src,
+ long nbits);
+void bitmap_from_le(unsigned long *dst, const unsigned long *src,
+ long nbits);
+
#endif /* BITMAP_H */
diff --git a/util/bitmap.c b/util/bitmap.c
index 90a42ff625..e80bcc74e2 100644
--- a/util/bitmap.c
+++ b/util/bitmap.c
@@ -370,3 +370,35 @@ long slow_bitmap_count_one(const unsigned long *bitmap,
long nbits)
return result;
}
+
+static void bitmap_to_from_le(unsigned long *dst,
+ const unsigned long *src, long nbits)
+{
+ long len = BITS_TO_LONGS(nbits);
+
+#ifdef HOST_WORDS_BIGENDIAN
+ long index;
+
+ for (index = 0; index < len; index++) {
+# if __WORD_SIZE == 64
+ dst[index] = bswap64(src[index]);
+# else
+ dst[index] = bswap32(src[index]);
+# endif
+ }
+#else
+ memcpy(dst, src, len * sizeof(unsigned long));
+#endif
+}
+
+void bitmap_from_le(unsigned long *dst, const unsigned long *src,
+ long nbits)
+{
+ bitmap_to_from_le(dst, src, nbits);
+}
+
+void bitmap_to_le(unsigned long *dst, const unsigned long *src,
+ long nbits)
+{
+ bitmap_to_from_le(dst, src, nbits);
+}
--
2.13.5
- [Qemu-devel] [PULL 00/16] Migration PULL request, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 02/16] migration: Teach it about G_SOURCE_REMOVE, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 04/16] migration: Create migration_has_all_channels, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 12/16] bitmap: provide to_le/from_le helpers,
Juan Quintela <=
- [Qemu-devel] [PULL 09/16] migration: Split migration_fd_process_incoming, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 10/16] bitmap: remove BITOP_WORD(), Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 13/16] migration: pass MigrationIncomingState* into migration check functions, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 03/16] migration: Add comments to channel functions, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 05/16] migration: Add multifd capability, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 06/16] migration: Create x-multifd-channels parameter, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 08/16] migration: Create multifd migration threads, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 01/16] migration: Create migration_ioc_process_incoming(), Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 14/16] migration: fix hardcoded function name in error report, Juan Quintela, 2017/09/20
- [Qemu-devel] [PULL 07/16] migration: Create x-multifd-page-count parameter, Juan Quintela, 2017/09/20