* [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups
@ 2015-12-18 15:04 Max Reitz
2015-12-18 15:04 ` [Qemu-devel] [PATCH 1/2] vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries() Max Reitz
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Max Reitz @ 2015-12-18 15:04 UTC (permalink / raw)
To: qemu-block; +Cc: Kevin Wolf, Jeff Cody, qemu-devel, Max Reitz
Just some bits I discovered while going through the Coverity report.
(The issue reported by Coverity actually was not an issue.)
Max Reitz (2):
vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries()
vhdx: Simplify vhdx_set_shift_bits()
block/vhdx.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
--
2.6.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries()
2015-12-18 15:04 [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
@ 2015-12-18 15:04 ` Max Reitz
2015-12-18 15:04 ` [Qemu-devel] [PATCH 2/2] vhdx: Simplify vhdx_set_shift_bits() Max Reitz
2016-02-22 17:39 ` [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
2 siblings, 0 replies; 5+ messages in thread
From: Max Reitz @ 2015-12-18 15:04 UTC (permalink / raw)
To: qemu-block; +Cc: Kevin Wolf, Jeff Cody, qemu-devel, Max Reitz
We have DIV_ROUND_UP(), so we can use it to produce more easily readable
code. It may be slower than the bit shifting currently performed
(because it actually performs a division), but since
vhdx_calc_bat_entries() is never used in a hot path, this is completely
fine.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/vhdx.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index 2fe9a5e..3955f7f 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -856,14 +856,8 @@ static void vhdx_calc_bat_entries(BDRVVHDXState *s)
{
uint32_t data_blocks_cnt, bitmap_blocks_cnt;
- data_blocks_cnt = s->virtual_disk_size >> s->block_size_bits;
- if (s->virtual_disk_size - (data_blocks_cnt << s->block_size_bits)) {
- data_blocks_cnt++;
- }
- bitmap_blocks_cnt = data_blocks_cnt >> s->chunk_ratio_bits;
- if (data_blocks_cnt - (bitmap_blocks_cnt << s->chunk_ratio_bits)) {
- bitmap_blocks_cnt++;
- }
+ data_blocks_cnt = DIV_ROUND_UP(s->virtual_disk_size, s->block_size);
+ bitmap_blocks_cnt = DIV_ROUND_UP(data_blocks_cnt, s->chunk_ratio);
if (s->parent_entries) {
s->bat_entries = bitmap_blocks_cnt * (s->chunk_ratio + 1);
--
2.6.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] vhdx: Simplify vhdx_set_shift_bits()
2015-12-18 15:04 [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
2015-12-18 15:04 ` [Qemu-devel] [PATCH 1/2] vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries() Max Reitz
@ 2015-12-18 15:04 ` Max Reitz
2016-02-22 17:39 ` [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
2 siblings, 0 replies; 5+ messages in thread
From: Max Reitz @ 2015-12-18 15:04 UTC (permalink / raw)
To: qemu-block; +Cc: Kevin Wolf, Jeff Cody, qemu-devel, Max Reitz
For values which are powers of two (and we do assume all of these to
be), sizeof(x) * 8 - 1 - clz(x) == ctz(x). Therefore, use ctz().
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/vhdx.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index 3955f7f..475f602 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -263,10 +263,10 @@ static void vhdx_region_unregister_all(BDRVVHDXState *s)
static void vhdx_set_shift_bits(BDRVVHDXState *s)
{
- s->logical_sector_size_bits = 31 - clz32(s->logical_sector_size);
- s->sectors_per_block_bits = 31 - clz32(s->sectors_per_block);
- s->chunk_ratio_bits = 63 - clz64(s->chunk_ratio);
- s->block_size_bits = 31 - clz32(s->block_size);
+ s->logical_sector_size_bits = ctz32(s->logical_sector_size);
+ s->sectors_per_block_bits = ctz32(s->sectors_per_block);
+ s->chunk_ratio_bits = ctz64(s->chunk_ratio);
+ s->block_size_bits = ctz32(s->block_size);
}
/*
--
2.6.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups
2015-12-18 15:04 [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
2015-12-18 15:04 ` [Qemu-devel] [PATCH 1/2] vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries() Max Reitz
2015-12-18 15:04 ` [Qemu-devel] [PATCH 2/2] vhdx: Simplify vhdx_set_shift_bits() Max Reitz
@ 2016-02-22 17:39 ` Max Reitz
2016-02-23 4:04 ` Jeff Cody
2 siblings, 1 reply; 5+ messages in thread
From: Max Reitz @ 2016-02-22 17:39 UTC (permalink / raw)
To: qemu-block; +Cc: Kevin Wolf, Jeff Cody, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 407 bytes --]
On 18.12.2015 16:04, Max Reitz wrote:
> Just some bits I discovered while going through the Coverity report.
>
> (The issue reported by Coverity actually was not an issue.)
>
>
> Max Reitz (2):
> vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries()
> vhdx: Simplify vhdx_set_shift_bits()
>
> block/vhdx.c | 18 ++++++------------
> 1 file changed, 6 insertions(+), 12 deletions(-)
Ping
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups
2016-02-22 17:39 ` [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
@ 2016-02-23 4:04 ` Jeff Cody
0 siblings, 0 replies; 5+ messages in thread
From: Jeff Cody @ 2016-02-23 4:04 UTC (permalink / raw)
To: Max Reitz; +Cc: Kevin Wolf, qemu-devel, qemu-block
On Mon, Feb 22, 2016 at 06:39:48PM +0100, Max Reitz wrote:
> On 18.12.2015 16:04, Max Reitz wrote:
> > Just some bits I discovered while going through the Coverity report.
> >
> > (The issue reported by Coverity actually was not an issue.)
> >
> >
> > Max Reitz (2):
> > vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries()
> > vhdx: Simplify vhdx_set_shift_bits()
> >
> > block/vhdx.c | 18 ++++++------------
> > 1 file changed, 6 insertions(+), 12 deletions(-)
>
> Ping
>
Thanks, applied to my block branch
Jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-23 4:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-18 15:04 [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
2015-12-18 15:04 ` [Qemu-devel] [PATCH 1/2] vhdx: DIV_ROUND_UP() in vhdx_calc_bat_entries() Max Reitz
2015-12-18 15:04 ` [Qemu-devel] [PATCH 2/2] vhdx: Simplify vhdx_set_shift_bits() Max Reitz
2016-02-22 17:39 ` [Qemu-devel] [PATCH 0/2] block/vhdx: Small cleanups Max Reitz
2016-02-23 4:04 ` Jeff Cody
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.