Skip to contentSkip to conversation

sysemu/accel: Simplify sysemu/xen.h

PATCH In review Philippe Mathieu-Daudé 3 participants 7 messages Sep 5, 2023 – Oct 4, 2023

lore
Share & tools
lore
#0 lore raw

cover sysemu/accel: Simplify sysemu/xen.h

Trivial cleanups which simplify "sysemu/xen.h".

Philippe Mathieu-Daudé (3):
sysemu/xen: Remove unuseful CONFIG_USER_ONLY header guard sysemu/xen: Remove unreachable xen_ram_alloc() code sysemu/xen: Allow elision of xen_hvm_modified_memory()

 include/exec/ram_addr.h |  8 ++++++--
 include/sysemu/xen.h    | 24 +++---------------------
 2 files changed, 9 insertions(+), 23 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/3 sysemu/xen: Remove unuseful CONFIG_USER_ONLY header guard

In commit da278d58a0 ("accel: Move Xen accelerator code under accel/xen/") we used include/sysemu/kvm.h as a template for include/sysemu/xen.h, using the CONFIG_USER_ONLY header guard. In retrospective, it is not used / useful, so remove it.

---
 include/sysemu/xen.h | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
include/sysemu/xen.h +1 -4
index bc13ad5692..9b2d0b21ff 100644
@@ -26,16 +26,14 @@ extern bool xen_allowed;
 
 #define xen_enabled()           (xen_allowed)
 
-#ifndef CONFIG_USER_ONLY
 void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                    struct MemoryRegion *mr, Error **errp);
-#endif
 
 #else /* !CONFIG_XEN_IS_POSSIBLE */
 
 #define xen_enabled() 0
-#ifndef CONFIG_USER_ONLY
+
 static inline void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
 {
     /* nothing */
@@ -45,7 +43,6 @@ static inline void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
 {
     g_assert_not_reached();
 }
-#endif
 
 #endif /* CONFIG_XEN_IS_POSSIBLE */
 
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/3 sysemu/xen: Remove unreachable xen_ram_alloc() code

In reply to Philippe Mathieu-Daudé

The xen_ram_alloc() call in softmmu/physmem.c is guarded by checking for xen_enabled(), which evaluate to 'false' when XEN is not built in. The compiler elide the function call, and thus the inlined function is not used. Remove it.

---
 include/sysemu/xen.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
include/sysemu/xen.h +3 -7
index 9b2d0b21ff..1f797a9abe 100644
@@ -27,8 +27,6 @@ extern bool xen_allowed;
 #define xen_enabled()           (xen_allowed)
 
 void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
-void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
-                   struct MemoryRegion *mr, Error **errp);
 
 #else /* !CONFIG_XEN_IS_POSSIBLE */
 
@@ -38,12 +36,10 @@ static inline void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
 {
     /* nothing */
 }
-static inline void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
-                                 MemoryRegion *mr, Error **errp)
-{
-    g_assert_not_reached();
-}
 
 #endif /* CONFIG_XEN_IS_POSSIBLE */
 
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
+                   struct MemoryRegion *mr, Error **errp);
+
 #endif
Signature · 1 line
2.41.0
#3 lore raw

Re: [PATCH 2/3] sysemu/xen: Remove unreachable xen_ram_alloc() code

Quoted 4 lines · Philippe Mathieu-Daudé

The xen_ram_alloc() call in softmmu/physmem.c is guarded by checking for xen_enabled(), which evaluate to 'false' when XEN is not built in. The compiler elide the function call, and thus the inlined function is not used. Remove it.

I still don't think it is a good way to just eliminate the function (stub) in a hope compiler will elide the call. It's definitely not guaranteed by any standard, and compiler itself can produce varying results (eg building with -O0 to make gdb debugging easier).

static inline function costs nothing but keeps whole thing manageable. IMHO anyway.

/mjt

Quoted 35 lines
---
  include/sysemu/xen.h | 10 +++-------
  1 file changed, 3 insertions(+), 7 deletions(-)
include/sysemu/xen.h +3 -7
index 9b2d0b21ff..1f797a9abe 100644
@@ -27,8 +27,6 @@ extern bool xen_allowed;
  #define xen_enabled()           (xen_allowed)
 
  void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
-void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
-                   struct MemoryRegion *mr, Error **errp);
 
  #else /* !CONFIG_XEN_IS_POSSIBLE */
 
@@ -38,12 +36,10 @@ static inline void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
  {
      /* nothing */
  }
-static inline void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
-                                 MemoryRegion *mr, Error **errp)
-{
-    g_assert_not_reached();
-}
 
  #endif /* CONFIG_XEN_IS_POSSIBLE */
 
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
+                   struct MemoryRegion *mr, Error **errp);
+
  #endif
#4 lore raw

PATCH 3/3 sysemu/xen: Allow elision of xen_hvm_modified_memory()

In reply to Philippe Mathieu-Daudé

Call xen_enabled() before xen_hvm_modified_memory() to let the compiler elide its call.

Have xen_enabled() return a boolean to match its declaration in the CONFIG_XEN_IS_POSSIBLE case.

---
 include/exec/ram_addr.h |  8 ++++++--
 include/sysemu/xen.h    | 15 ++-------------
 2 files changed, 8 insertions(+), 15 deletions(-)
include/exec/ram_addr.h +6 -2
index 9f2e3893f5..66e849ac4e 100644
@@ -330,7 +330,9 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
         }
     }
 
-    xen_hvm_modified_memory(start, length);
+    if (xen_enabled()) {
+        xen_hvm_modified_memory(start, length);
+    }
 }
 
 #if !defined(_WIN32)
@@ -406,7 +408,9 @@ uint64_t cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
             }
         }
 
-        xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
+        if (xen_enabled()) {
+            xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
+        }
     } else {
         uint8_t clients = tcg_enabled() ? DIRTY_CLIENTS_ALL : DIRTY_CLIENTS_NOCODE;
 
include/sysemu/xen.h +2 -13
index 1f797a9abe..d84a5f3551 100644
@@ -21,24 +21,13 @@
 #endif
 
 #ifdef CONFIG_XEN_IS_POSSIBLE
-
 extern bool xen_allowed;
-
 #define xen_enabled()           (xen_allowed)
-
-void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
-
 #else /* !CONFIG_XEN_IS_POSSIBLE */
-
-#define xen_enabled() 0
-
-static inline void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
-{
-    /* nothing */
-}
-
+#define xen_enabled()           false
 #endif /* CONFIG_XEN_IS_POSSIBLE */
 
+void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
                    struct MemoryRegion *mr, Error **errp);
 
Signature · 1 line
2.41.0
Reviewed-by on v1 3/3
#5 lore raw

Re: [PATCH 3/3] sysemu/xen: Allow elision of xen_hvm_modified_memory()

Quoted 9 lines · Philippe Mathieu-Daudé

Call xen_enabled() before xen_hvm_modified_memory() to let the compiler elide its call.

Have xen_enabled() return a boolean to match its declaration in the CONFIG_XEN_IS_POSSIBLE case.

---

Signature · 3 lines
Cheers,

David / dhildenb
#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

Trivial cleanups which simplify "sysemu/xen.h".

Philippe Mathieu-Daudé (3):
sysemu/xen: Remove unuseful CONFIG_USER_ONLY header guard sysemu/xen: Remove unreachable xen_ram_alloc() code sysemu/xen: Allow elision of xen_hvm_modified_memory()

  include/exec/ram_addr.h |  8 ++++++--
  include/sysemu/xen.h    | 24 +++---------------------
  2 files changed, 9 insertions(+), 23 deletions(-)

ping for trivial patches 1 & 2?