[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 25/25] exec: streamline flatview_add_to_dispatch
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 25/25] exec: streamline flatview_add_to_dispatch |
Date: |
Sat, 9 Mar 2019 08:48:18 +0100 |
The while loop in flatview_add_to_dispatch can only be executed twice
and it will go through different paths on each execution (in fact
one of the "if" branches is dead). Remove the loop completely,
the code becomes clearer at the cost of a handful of duplicated
lines.
Reported-by: Wei Yang <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
exec.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/exec.c b/exec.c
index 1d4f378..9647593 100644
--- a/exec.c
+++ b/exec.c
@@ -1601,33 +1601,37 @@ static void register_multipage(FlatView *fv,
void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section)
{
- MemoryRegionSection now = *section, remain = *section;
+ MemoryRegionSection remain = *section;
Int128 page_size = int128_make64(TARGET_PAGE_SIZE);
- if (now.offset_within_address_space & ~TARGET_PAGE_MASK) {
+ if (remain.offset_within_address_space & ~TARGET_PAGE_MASK) {
+ MemoryRegionSection now = remain;
uint64_t left = TARGET_PAGE_ALIGN(now.offset_within_address_space)
- now.offset_within_address_space;
now.size = int128_min(int128_make64(left), now.size);
register_subpage(fv, &now);
- } else {
- now.size = int128_zero();
- }
- while (int128_ne(remain.size, now.size)) {
+ if (int128_eq(remain.size, now.size)) {
+ return;
+ }
remain.size = int128_sub(remain.size, now.size);
remain.offset_within_address_space += int128_get64(now.size);
remain.offset_within_region += int128_get64(now.size);
- now = remain;
- if (int128_lt(remain.size, page_size)) {
- register_subpage(fv, &now);
- } else if (remain.offset_within_address_space & ~TARGET_PAGE_MASK) {
- now.size = page_size;
- register_subpage(fv, &now);
- } else {
- now.size = int128_and(now.size, int128_neg(page_size));
- register_multipage(fv, &now);
+ }
+
+ if (int128_ge(remain.size, page_size)) {
+ MemoryRegionSection now = remain;
+ now.size = int128_and(now.size, int128_neg(page_size));
+ register_multipage(fv, &now);
+ if (int128_eq(remain.size, now.size)) {
+ return;
}
+ remain.size = int128_sub(remain.size, now.size);
+ remain.offset_within_address_space += int128_get64(now.size);
+ remain.offset_within_region += int128_get64(now.size);
}
+
+ register_subpage(fv, &remain);
}
void qemu_flush_coalesced_mmio_buffer(void)
--
1.8.3.1
- [Qemu-devel] [PULL 12/25] update copyright notice, (continued)
- [Qemu-devel] [PULL 12/25] update copyright notice, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 19/25] scsi-disk: Fix crash if request is invaild or disk is no medium, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 11/25] lsi: check if SIGP bit is already set in Wait reselect, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 20/25] lsi: use ldn_le_p()/stn_le_p(), Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 17/25] oslib-posix: Ignore fcntl("/dev/null", F_SETFL, O_NONBLOCK) failure, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 16/25] accel: Allow to build QEMU without TCG or KVM support, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 24/25] lsi: return dfifo value, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 10/25] lsi: implement basic SBCL functionality, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 06/25] configure: Enable werror for git worktrees, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 18/25] configure: Disable W^X on OpenBSD, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 25/25] exec: streamline flatview_add_to_dispatch,
Paolo Bonzini <=
- [Qemu-devel] [PULL 22/25] lsi: use enum type for s->msg_action, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 09/25] virtio-scsi: Fix build with gcc 9, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 23/25] lsi: use SCSI phase names instead of numbers in trace, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 05/25] contrib/elf2dmp: add kernel start address checking, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 13/25] build: get rid of target-obj-y, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 15/25] build: clean trace/generated-helpers.c, Paolo Bonzini, 2019/03/09
- [Qemu-devel] [PULL 21/25] lsi: use enum type for s->waiting, Paolo Bonzini, 2019/03/09
- Re: [Qemu-devel] [PULL 00/25] Misc patches for QEMU 4.0 soft freeze, Peter Maydell, 2019/03/10