Skip to contentSkip to conversation

s390: kvm: reduce frequency of CPU syncs of diag318 info

RFC PATCH In review Collin Walling 2 participants 5 messages Nov 22, 2021 – Dec 6, 2021

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 s390: kvm: reduce frequency of CPU syncs of diag318 info

DIAGNOSE 0318 is invoked only once during IPL. As such, the diag318 info will only change once initially and during resets. Let's only sync the register to convey the info to KVM if and only if the diag318 info has changed. Only set the dirty bit flag for diag318 whenever it must be updated.

The migration handler will invoke the set_diag318 helper on post_load to ensure the info is set on the destination machine.

---
 target/s390x/kvm/kvm.c |  5 -----
 target/s390x/machine.c | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 5 deletions(-)
target/s390x/kvm/kvm.c +0 -5
index 6acf14d5ec..6a141399f7 100644
@@ -599,11 +599,6 @@ int kvm_arch_put_registers(CPUState *cs, int level)
         cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ETOKEN;
     }
 
-    if (can_sync_regs(cs, KVM_SYNC_DIAG318)) {
-        cs->kvm_run->s.regs.diag318 = env->diag318_info;
-        cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_DIAG318;
-    }
-
     /* Finally the prefix */
     if (can_sync_regs(cs, KVM_SYNC_PREFIX)) {
         cs->kvm_run->s.regs.prefix = env->psa;
target/s390x/machine.c +14 -0
index 37a076858c..a5d113ce3a 100644
@@ -234,6 +234,19 @@ const VMStateDescription vmstate_etoken = {
     }
 };
 
+static int diag318_post_load(void *opaque, int version_id)
+{
+    S390CPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
+    CPUS390XState *env = &S390_CPU(cs)->env;
+
+    if (kvm_enabled()) {
+        kvm_s390_set_diag318(cs, env->diag318_info);
+    }
+
+    return 0;
+}
+
 static bool diag318_needed(void *opaque)
 {
     return s390_has_feat(S390_FEAT_DIAG_318);
@@ -243,6 +256,7 @@ const VMStateDescription vmstate_diag318 = {
     .name = "cpu/diag318",
     .version_id = 1,
     .minimum_version_id = 1,
+    .post_load = diag318_post_load,
     .needed = diag318_needed,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64(env.diag318_info, S390CPU),
Signature · 1 line
2.31.1
#1 lore raw
Quoted 10 lines · Collin Walling

DIAGNOSE 0318 is invoked only once during IPL. As such, the diag318 info will only change once initially and during resets. Let's only sync the register to convey the info to KVM if and only if the diag318 info has changed. Only set the dirty bit flag for diag318 whenever it must be updated.

The migration handler will invoke the set_diag318 helper on post_load to ensure the info is set on the destination machine.

This is a long-overdue response to this thread:
https://www.spinics.net/lists/kvm/msg258071.html

Quoted 54 lines
---
 target/s390x/kvm/kvm.c |  5 -----
 target/s390x/machine.c | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 5 deletions(-)
target/s390x/kvm/kvm.c +0 -5
index 6acf14d5ec..6a141399f7 100644
@@ -599,11 +599,6 @@ int kvm_arch_put_registers(CPUState *cs, int level)
         cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ETOKEN;
     }
 
-    if (can_sync_regs(cs, KVM_SYNC_DIAG318)) {
-        cs->kvm_run->s.regs.diag318 = env->diag318_info;
-        cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_DIAG318;
-    }
-
     /* Finally the prefix */
     if (can_sync_regs(cs, KVM_SYNC_PREFIX)) {
         cs->kvm_run->s.regs.prefix = env->psa;
target/s390x/machine.c +14 -0
index 37a076858c..a5d113ce3a 100644
@@ -234,6 +234,19 @@ const VMStateDescription vmstate_etoken = {
     }
 };
 
+static int diag318_post_load(void *opaque, int version_id)
+{
+    S390CPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
+    CPUS390XState *env = &S390_CPU(cs)->env;
+
+    if (kvm_enabled()) {
+        kvm_s390_set_diag318(cs, env->diag318_info);
+    }
+
+    return 0;
+}
+
 static bool diag318_needed(void *opaque)
 {
     return s390_has_feat(S390_FEAT_DIAG_318);
@@ -243,6 +256,7 @@ const VMStateDescription vmstate_diag318 = {
     .name = "cpu/diag318",
     .version_id = 1,
     .minimum_version_id = 1,
+    .post_load = diag318_post_load,
     .needed = diag318_needed,
     .fields = (VMStateField[]) {
         VMSTATE_UINT64(env.diag318_info, S390CPU),
Signature · 4 lines
Regards,
Collin

Stay safe and stay healthy
#2 lore raw
In reply to Collin Walling

Am 22.11.21 um 23:33 schrieb Collin Walling:

Quoted 5 lines

DIAGNOSE 0318 is invoked only once during IPL. As such, the diag318 info will only change once initially and during resets. Let's only sync the register to convey the info to KVM if and only if the diag318 info has changed. Only set the dirty bit flag for diag318 whenever it must be updated.

Is this really necessary? In my logs the sync only happens for larger changes (like reset) operations and then yes we log again. But I think it is ok to see such a log entry in these rare events.

Quoted 59 lines

The migration handler will invoke the set_diag318 helper on post_load to ensure the info is set on the destination machine.

---
  target/s390x/kvm/kvm.c |  5 -----
  target/s390x/machine.c | 14 ++++++++++++++
  2 files changed, 14 insertions(+), 5 deletions(-)
target/s390x/kvm/kvm.c +0 -5
index 6acf14d5ec..6a141399f7 100644
@@ -599,11 +599,6 @@ int kvm_arch_put_registers(CPUState *cs, int level)
          cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ETOKEN;
      }
 
-    if (can_sync_regs(cs, KVM_SYNC_DIAG318)) {
-        cs->kvm_run->s.regs.diag318 = env->diag318_info;
-        cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_DIAG318;
-    }
-
      /* Finally the prefix */
      if (can_sync_regs(cs, KVM_SYNC_PREFIX)) {
          cs->kvm_run->s.regs.prefix = env->psa;
target/s390x/machine.c +14 -0
index 37a076858c..a5d113ce3a 100644
@@ -234,6 +234,19 @@ const VMStateDescription vmstate_etoken = {
      }
  };
 
+static int diag318_post_load(void *opaque, int version_id)
+{
+    S390CPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
+    CPUS390XState *env = &S390_CPU(cs)->env;
+
+    if (kvm_enabled()) {
+        kvm_s390_set_diag318(cs, env->diag318_info);
+    }
+
+    return 0;
+}
+
  static bool diag318_needed(void *opaque)
  {
      return s390_has_feat(S390_FEAT_DIAG_318);
@@ -243,6 +256,7 @@ const VMStateDescription vmstate_diag318 = {
      .name = "cpu/diag318",
      .version_id = 1,
      .minimum_version_id = 1,
+    .post_load = diag318_post_load,
      .needed = diag318_needed,
      .fields = (VMStateField[]) {
          VMSTATE_UINT64(env.diag318_info, S390CPU),
#3 lore raw
Quoted 11 lines · Christian Borntraeger

Am 22.11.21 um 23:33 schrieb Collin Walling:

Quoted 5 lines

DIAGNOSE 0318 is invoked only once during IPL. As such, the diag318 info will only change once initially and during resets. Let's only sync the register to convey the info to KVM if and only if the diag318 info has changed. Only set the dirty bit flag for diag318 whenever it must be updated.

Is this really necessary? In my logs the sync only happens for larger changes (like reset) operations and then yes we log again. But I think it is ok to see such a log entry in these rare events.

Albeit a micro-optimization, I don't see why the diag318 dirtied bit must to be set during /every/ sync. It makes more sense to set the flag after the register was actually modified.

Quoted 58 lines
Quoted 57 lines

The migration handler will invoke the set_diag318 helper on post_load to ensure the info is set on the destination machine.

---
  target/s390x/kvm/kvm.c |  5 -----
  target/s390x/machine.c | 14 ++++++++++++++

  2 files changed, 14 insertions(+), 5 deletions(-)
target/s390x/kvm/kvm.c +0 -4
index 6acf14d5ec..6a141399f7 100644
@@ -599,11 +599,6 @@ int kvm_arch_put_registers(CPUState *cs, int level)
           cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ETOKEN;
       }
   -    if (can_sync_regs(cs, KVM_SYNC_DIAG318)) {
-        cs->kvm_run->s.regs.diag318 = env->diag318_info;
-        cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_DIAG318;
-    }
-
       /* Finally the prefix */
       if (can_sync_regs(cs, KVM_SYNC_PREFIX)) {
           cs->kvm_run->s.regs.prefix = env->psa;
target/s390x/machine.c +13 -0
index 37a076858c..a5d113ce3a 100644
@@ -234,6 +234,19 @@ const VMStateDescription vmstate_etoken = {
       }
   };
   +static int diag318_post_load(void *opaque, int version_id)
+{
+    S390CPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
+    CPUS390XState *env = &S390_CPU(cs)->env;
+
+    if (kvm_enabled()) {
+        kvm_s390_set_diag318(cs, env->diag318_info);
+    }
+
+    return 0;
+}
+
   static bool diag318_needed(void *opaque)
   {
       return s390_has_feat(S390_FEAT_DIAG_318);
@@ -243,6 +256,7 @@ const VMStateDescription vmstate_diag318 = {
       .name = "cpu/diag318",
       .version_id = 1,
       .minimum_version_id = 1,
+    .post_load = diag318_post_load,
       .needed = diag318_needed,
       .fields = (VMStateField[]) {
           VMSTATE_UINT64(env.diag318_info, S390CPU),
Signature · 4 lines
Regards,
Collin

Stay safe and stay healthy
#4 lore raw

Am 02.12.21 um 21:54 schrieb Collin Walling:

Quoted 9 lines · Christian Borntraeger
Quoted 8 lines

Am 22.11.21 um 23:33 schrieb Collin Walling:

Quoted 5 lines

DIAGNOSE 0318 is invoked only once during IPL. As such, the diag318 info will only change once initially and during resets. Let's only sync the register to convey the info to KVM if and only if the diag318 info has changed. Only set the dirty bit flag for diag318 whenever it must be updated.

Quoted 7 lines
Quoted 3 lines

Is this really necessary? In my logs the sync only happens for larger changes (like reset) operations and then yes we log again. But I think it is ok to see such a log entry in these rare events.

Albeit a micro-optimization, I don't see why the diag318 dirtied bit must to be set during /every/ sync. It makes more sense to set the flag after the register was actually modified.

My point is that it is NOT set during /every/ sync.
We only set it when level != KVM_PUT_RUNTIME_STATE (see kvm_arch_put_registers) And this basically never happens during normal runtime, only for major events like reset.

Quoted 61 lines
Quoted 59 lines
Quoted 58 lines

The migration handler will invoke the set_diag318 helper on post_load to ensure the info is set on the destination machine.

---
   target/s390x/kvm/kvm.c |  5 -----
   target/s390x/machine.c | 14 ++++++++++++++
   2 files changed, 14 insertions(+), 5 deletions(-)
target/s390x/kvm/kvm.c +0 -4
index 6acf14d5ec..6a141399f7 100644
@@ -599,11 +599,6 @@ int kvm_arch_put_registers(CPUState *cs, int level)
           cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ETOKEN;
       }
   -    if (can_sync_regs(cs, KVM_SYNC_DIAG318)) {
-        cs->kvm_run->s.regs.diag318 = env->diag318_info;
-        cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_DIAG318;
-    }
-
       /* Finally the prefix */
       if (can_sync_regs(cs, KVM_SYNC_PREFIX)) {
           cs->kvm_run->s.regs.prefix = env->psa;
target/s390x/machine.c +13 -0
index 37a076858c..a5d113ce3a 100644
@@ -234,6 +234,19 @@ const VMStateDescription vmstate_etoken = {
       }
   };
   +static int diag318_post_load(void *opaque, int version_id)
+{
+    S390CPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
+    CPUS390XState *env = &S390_CPU(cs)->env;
+
+    if (kvm_enabled()) {
+        kvm_s390_set_diag318(cs, env->diag318_info);
+    }
+
+    return 0;
+}
+
   static bool diag318_needed(void *opaque)
   {
       return s390_has_feat(S390_FEAT_DIAG_318);
@@ -243,6 +256,7 @@ const VMStateDescription vmstate_diag318 = {
       .name = "cpu/diag318",
       .version_id = 1,
       .minimum_version_id = 1,
+    .post_load = diag318_post_load,
       .needed = diag318_needed,
       .fields = (VMStateField[]) {
           VMSTATE_UINT64(env.diag318_info, S390CPU),