[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 28/31] exec.c: refactor function flatview_add_to_d
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL v2 28/31] exec.c: refactor function flatview_add_to_dispatch() |
Date: |
Mon, 11 Mar 2019 17:55:32 +0100 |
From: Wei Yang <address@hidden>
flatview_add_to_dispatch() registers page based on the condition of
*section*, which may looks like this:
|s|PPPPPPP|s|
where s stands for subpage and P for page.
The procedure of this function could be described as:
- register first subpage
- register page
- register last subpage
This means the procedure could be simplified into these three steps
instead of a loop iteration.
This patch refactors the function into three corresponding steps and
adds some comment to clarify it.
Signed-off-by: Wei Yang <address@hidden>
Message-Id: <address@hidden>
[Paolo: move exit before adjustment of remain.offset_within_*,
otherwise int128_get64 fails when a region is 2^64 bytes long]
Signed-off-by: Paolo Bonzini <address@hidden>
---
exec.c | 48 +++++++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/exec.c b/exec.c
index 1d4f378..86a38d3 100644
--- a/exec.c
+++ b/exec.c
@@ -1599,35 +1599,49 @@ static void register_multipage(FlatView *fv,
phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_index);
}
+/*
+ * The range in *section* may look like this:
+ *
+ * |s|PPPPPPP|s|
+ *
+ * where s stands for subpage and P for page.
+ */
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) {
- uint64_t left = TARGET_PAGE_ALIGN(now.offset_within_address_space)
- - now.offset_within_address_space;
+ /* register first subpage */
+ if (remain.offset_within_address_space & ~TARGET_PAGE_MASK) {
+ uint64_t left = TARGET_PAGE_ALIGN(remain.offset_within_address_space)
+ - remain.offset_within_address_space;
+ MemoryRegionSection now = remain;
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);
+ }
+
+ /* register whole pages */
+ 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 last subpage */
+ register_subpage(fv, &remain);
}
void qemu_flush_coalesced_mmio_buffer(void)
--
1.8.3.1
- [Qemu-devel] [PULL v2 17/31] build: clean trace/generated-helpers.c, (continued)
- [Qemu-devel] [PULL v2 17/31] build: clean trace/generated-helpers.c, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 19/31] oslib-posix: Ignore fcntl("/dev/null", F_SETFL, O_NONBLOCK) failure, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 18/31] accel: Allow to build QEMU without TCG or KVM support, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 21/31] scsi-disk: Fix crash if request is invaild or disk is no medium, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 22/31] lsi: use ldn_le_p()/stn_le_p(), Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 25/31] lsi: use SCSI phase names instead of numbers in trace, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 20/31] configure: Disable W^X on OpenBSD, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 23/31] lsi: use enum type for s->waiting, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 24/31] lsi: use enum type for s->msg_action, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 26/31] lsi: return dfifo value, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 28/31] exec.c: refactor function flatview_add_to_dispatch(),
Paolo Bonzini <=
- [Qemu-devel] [PULL v2 31/31] qemugdb: fix licensing, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 27/31] lsi: 810/895A are always little endian, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 30/31] chardev: add support for authorization for TLS clients, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 29/31] qom: cpu: destroy work_mutex in cpu_common_finalize, Paolo Bonzini, 2019/03/11
- Re: [Qemu-devel] [PULL v2 00/31] Misc patches for 2019-03-09, Peter Maydell, 2019/03/11