[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20201112133815.13332-7-david@redhat.com>
Date: Thu, 12 Nov 2020 14:37:52 +0100
From: David Hildenbrand <david@...hat.com>
To: linux-kernel@...r.kernel.org
Cc: virtualization@...ts.linux-foundation.org, linux-mm@...ck.org,
"Michael S . Tsirkin" <mst@...hat.com>,
David Hildenbrand <david@...hat.com>,
Wei Yang <richard.weiyang@...ux.alibaba.com>,
Pankaj Gupta <pankaj.gupta.linux@...il.com>,
Jason Wang <jasowang@...hat.com>
Subject: [PATCH v2 06/29] virtio-mem: factor out calculation of the bit number within the subblock bitmap
The calculation is already complicated enough, let's limit it to one
location.
Reviewed-by: Wei Yang <richard.weiyang@...ux.alibaba.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta.linux@...il.com>
Cc: "Michael S. Tsirkin" <mst@...hat.com>
Cc: Jason Wang <jasowang@...hat.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@...il.com>
Signed-off-by: David Hildenbrand <david@...hat.com>
---
drivers/virtio/virtio_mem.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c
index 94451b401fba..30b4d07f5263 100644
--- a/drivers/virtio/virtio_mem.c
+++ b/drivers/virtio/virtio_mem.c
@@ -290,6 +290,16 @@ static int virtio_mem_mb_state_prepare_next_mb(struct virtio_mem *vm)
_mb_id--) \
if (virtio_mem_mb_get_state(_vm, _mb_id) == _state)
+/*
+ * Calculate the bit number in the subblock bitmap for the given subblock
+ * inside the given memory block.
+ */
+static int virtio_mem_sb_bitmap_bit_nr(struct virtio_mem *vm,
+ unsigned long mb_id, int sb_id)
+{
+ return (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+}
+
/*
* Mark all selected subblocks plugged.
*
@@ -299,7 +309,7 @@ static void virtio_mem_mb_set_sb_plugged(struct virtio_mem *vm,
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
__bitmap_set(vm->sb_bitmap, bit, count);
}
@@ -313,7 +323,7 @@ static void virtio_mem_mb_set_sb_unplugged(struct virtio_mem *vm,
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
__bitmap_clear(vm->sb_bitmap, bit, count);
}
@@ -325,7 +335,7 @@ static bool virtio_mem_mb_test_sb_plugged(struct virtio_mem *vm,
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
if (count == 1)
return test_bit(bit, vm->sb_bitmap);
@@ -342,7 +352,7 @@ static bool virtio_mem_mb_test_sb_unplugged(struct virtio_mem *vm,
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
/* TODO: Helper similar to bitmap_set() */
return find_next_bit(vm->sb_bitmap, bit + count, bit) >= bit + count;
@@ -355,7 +365,7 @@ static bool virtio_mem_mb_test_sb_unplugged(struct virtio_mem *vm,
static int virtio_mem_mb_first_unplugged_sb(struct virtio_mem *vm,
unsigned long mb_id)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, 0);
return find_next_zero_bit(vm->sb_bitmap, bit + vm->nb_sb_per_mb, bit) -
bit;
--
2.26.2
Powered by blists - more mailing lists