diff mbox series

[v2] exec.c: refactor function flatview_add_to_dispatch()

Message ID 20190311013016.14411-1-richardw.yang@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v2] exec.c: refactor function flatview_add_to_dispatch() | expand

Commit Message

Wei Yang March 11, 2019, 1:30 a.m. UTC
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 <richardw.yang@linux.intel.com>

---
v2:
  * removes the loop iteration as suggested by Paolo
---
 exec.c | 50 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 17 deletions(-)

Comments

no-reply@patchew.org March 11, 2019, 4:54 a.m. UTC | #1
Patchew URL: https://patchew.org/QEMU/20190311013016.14411-1-richardw.yang@linux.intel.com/



Hi,

This series failed the docker-mingw@fedora build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  CC      x86_64-softmmu/accel/tcg/tcg-runtime.o
  CC      aarch64-softmmu/hw/cpu/realview_mpcore.o
/tmp/qemu-test/src/exec.c: In function 'flatview_add_to_dispatch':
/tmp/qemu-test/src/exec.c:1644:32: error: incompatible type for argument 2 of 'int128_gt'
     if (int128_gt(remain.size, 0)) {
                                ^
In file included from /tmp/qemu-test/src/include/exec/memory.h:24,
---
  CC      aarch64-softmmu/hw/display/vga.o
  CC      aarch64-softmmu/hw/display/bcm2835_fb.o
/tmp/qemu-test/src/exec.c: In function 'flatview_add_to_dispatch':
/tmp/qemu-test/src/exec.c:1644:32: error: incompatible type for argument 2 of 'int128_gt'
     if (int128_gt(remain.size, 0)) {
                                ^
In file included from /tmp/qemu-test/src/include/exec/memory.h:24,


The full log is available at
http://patchew.org/logs/20190311013016.14411-1-richardw.yang@linux.intel.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
Wei Yang March 11, 2019, 5:39 a.m. UTC | #2
On Sun, Mar 10, 2019 at 09:54:54PM -0700, no-reply@patchew.org wrote:
>Patchew URL: https://patchew.org/QEMU/20190311013016.14411-1-richardw.yang@linux.intel.com/
>
>
>
>Hi,
>
>This series failed the docker-mingw@fedora build test. Please find the testing commands and
>their output below. If you have Docker installed, you can probably reproduce it
>locally.
>
>=== TEST SCRIPT BEGIN ===
>#!/bin/bash
>time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1
>=== TEST SCRIPT END ===
>
>  CC      x86_64-softmmu/accel/tcg/tcg-runtime.o
>  CC      aarch64-softmmu/hw/cpu/realview_mpcore.o
>/tmp/qemu-test/src/exec.c: In function 'flatview_add_to_dispatch':
>/tmp/qemu-test/src/exec.c:1644:32: error: incompatible type for argument 2 of 'int128_gt'
>     if (int128_gt(remain.size, 0)) {
>                                ^
>In file included from /tmp/qemu-test/src/include/exec/memory.h:24,
>---
>  CC      aarch64-softmmu/hw/display/vga.o
>  CC      aarch64-softmmu/hw/display/bcm2835_fb.o
>/tmp/qemu-test/src/exec.c: In function 'flatview_add_to_dispatch':
>/tmp/qemu-test/src/exec.c:1644:32: error: incompatible type for argument 2 of 'int128_gt'
>     if (int128_gt(remain.size, 0)) {
>                                ^

Not sure why this works at my side.

Fixed this with 

      if (int128_gt(remain.size, int128_make64(0))) {

>In file included from /tmp/qemu-test/src/include/exec/memory.h:24,
>
>
>The full log is available at
>http://patchew.org/logs/20190311013016.14411-1-richardw.yang@linux.intel.com/testing.docker-mingw@fedora/?type=message.
>---
>Email generated automatically by Patchew [http://patchew.org/].
>Please send your feedback to patchew-devel@redhat.com
diff mbox series

Patch

diff --git a/exec.c b/exec.c
index 0959b00c06..160b8587d4 100644
--- a/exec.c
+++ b/exec.c
@@ -1598,34 +1598,50 @@  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.
+ *
+ * The procedure in following function could be described as:
+ *
+ * - register first subpage
+ * - register page
+ * - register last subpage
+ */
 void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section)
 {
-    MemoryRegionSection now = *section, remain = *section;
+    MemoryRegionSection now, 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;
 
+        now = remain;
         now.size = int128_min(int128_make64(left), now.size);
+        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, &now);
-    } else {
-        now.size = int128_zero();
     }
-    while (int128_ne(remain.size, now.size)) {
+
+    /* register page */
+    if (int128_ge(remain.size, page_size)) {
+        now = remain;
+        now.size = int128_and(now.size, int128_neg(page_size));
         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_multipage(fv, &now);
+    }
+
+    /* register last subpage */
+    if (int128_gt(remain.size, 0)) {
+        register_subpage(fv, &remain);
     }
 }