Skip to contentSkip to conversation

xen/vcpu: Improve code generation for VCPUOP_register_runstate_memory_area

PATCH In review Andrew Cooper 2 participants 2 messages Oct 27 – Oct 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/vcpu: Improve code generation for VCPUOP_register_runstate_memory_area

Both XLAT_vcpu_runstate_info() and __copy_to_guest() are common paths in their respective cases, but the optimiser can't/doesn't merge them.

Rearrange the code to do so explicitly.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

Bloat-o-meter reports:

add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-110 (-110)
Function old new delta
common_vcpu_op 1943 1902 -41
compat_vcpu_op 967 898 -69

and the size of the stack frame doesn't change at all.

---
 xen/arch/x86/x86_64/domain.c | 13 ++++++-------
 xen/common/domain.c          | 11 +++++------
 2 files changed, 11 insertions(+), 13 deletions(-)
xen/arch/x86/x86_64/domain.c +6 -7
index 533b0b21a00e..1510d593b18c 100644
@@ -44,6 +44,7 @@ compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
     {
         struct compat_vcpu_register_runstate_memory_area area;
         struct compat_vcpu_runstate_info info;
+        struct vcpu_runstate_info runstate, *rs;
 
         area.addr.p = 0;
 
@@ -64,16 +65,14 @@ compat_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         /* Update the newly-registered runstate area, best-effort. */
         if ( v == current )
-        {
-            XLAT_vcpu_runstate_info(&info, &v->runstate);
-        }
+            rs = &v->runstate;
         else
         {
-            struct vcpu_runstate_info runstate;
-
-            vcpu_runstate_get(v, &runstate);
-            XLAT_vcpu_runstate_info(&info, &runstate);
+            rs = &runstate;
+            vcpu_runstate_get(v, rs);
         }
+
+        XLAT_vcpu_runstate_info(&info, rs);
         __copy_to_guest(v->runstate_guest.compat, &info, 1);
 
         break;
xen/common/domain.c +5 -6
index b41be89cd0b9..2e6a1f9b98f7 100644
@@ -2318,7 +2318,7 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
     case VCPUOP_register_runstate_memory_area:
     {
         struct vcpu_register_runstate_memory_area area;
-        struct vcpu_runstate_info runstate;
+        struct vcpu_runstate_info runstate, *rs;
 
         rc = -EFAULT;
         if ( copy_from_guest(&area, arg, 1) )
@@ -2340,15 +2340,14 @@ long common_vcpu_op(int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg)
 
         /* Update the newly-registered runstate area, best-effort. */
         if ( v == current )
-        {
-            __copy_to_guest(runstate_guest(v), &v->runstate, 1);
-        }
+            rs = &v->runstate;
         else
         {
-            vcpu_runstate_get(v, &runstate);
-            __copy_to_guest(runstate_guest(v), &runstate, 1);
+            rs = &runstate;
+            vcpu_runstate_get(v, rs);
         }
 
+        __copy_to_guest(runstate_guest(v), rs, 1);
         break;
     }
 

base-commit: 8b0a70ddd29dec2f86a49c21e3664a21e281e859

Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andrew Cooper

Both XLAT_vcpu_runstate_info() and __copy_to_guest() are common paths in their respective cases, but the optimiser can't/doesn't merge them.

Rearrange the code to do so explicitly.

No functional change.

Quoted 4 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>

Just to mention: This is only the x86 list of reviewers, whereas ...

Quoted 3 lines
---
 xen/arch/x86/x86_64/domain.c | 13 ++++++-------
 xen/common/domain.c          | 11 +++++------

... this is a common file you change.

Jan