Skip to contentSkip to conversation

target/arm/cpu: adjust virtual time for arm cpu

PATCH Superseded Ying Fang 4 participants 5 messages Jun 3, 2020 – Jun 4, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ying Fang

author
#0 lore raw

PATCH v2 1/1 target/arm/cpu: adjust virtual time for arm cpu

Virtual time adjustment was implemented for virt-5.0 machine type, but the cpu property was enabled only for host-passthrough and max cpu model. Let's add it for arm cpu which has the gernic timer feature enabled.

---
v2:
- move kvm_arm_add_vcpu_properties into arm_cpu_post_init

v1:
- initial commit
- https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg08518.html

---
 target/arm/cpu.c   | 3 +--
 target/arm/cpu64.c | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)
target/arm/cpu.c +1 -2
index 32bec156f2..1e9b7a51f2 100644
@@ -1244,6 +1244,7 @@ void arm_cpu_post_init(Object *obj)
 
     if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) {
         qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property);
+        kvm_arm_add_vcpu_properties(obj);
     }
 }
 
@@ -2029,7 +2030,6 @@ static void arm_max_initfn(Object *obj)
 
     if (kvm_enabled()) {
         kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
     } else {
         cortex_a15_initfn(obj);
 
@@ -2183,7 +2183,6 @@ static void arm_host_initfn(Object *obj)
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
         aarch64_add_sve_properties(obj);
     }
-    kvm_arm_add_vcpu_properties(obj);
     arm_cpu_post_init(obj);
 }
 
target/arm/cpu64.c +0 -1
index cbc5c3868f..778cecc2e6 100644
@@ -592,7 +592,6 @@ static void aarch64_max_initfn(Object *obj)
 
     if (kvm_enabled()) {
         kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
     } else {
         uint64_t t;
         uint32_t u;
Signature · 1 line
2.23.0
#2 lore raw
In reply to Ying Fang
Quoted 26 lines · Ying Fang

Virtual time adjustment was implemented for virt-5.0 machine type, but the cpu property was enabled only for host-passthrough and max cpu model. Let's add it for arm cpu which has the gernic timer feature enabled.

---
v2:
- move kvm_arm_add_vcpu_properties into arm_cpu_post_init

v1:
- initial commit
- https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg08518.html

---
 target/arm/cpu.c   | 3 +--
 target/arm/cpu64.c | 1 -
 2 files changed, 1 insertion(+), 3 deletions(-)
target/arm/cpu.c +0 -0
index 32bec156f2..1e9b7a51f2 100644

target/arm/cpu.c void arm_cpu_post_init(Object *obj) · line 1247

Quoted 4 lines
target/arm/cpu.c +1 -0
@@ -1244,6 +1244,7 @@ void arm_cpu_post_init(Object *obj)
 
     if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) {
         qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property);
+        kvm_arm_add_vcpu_properties(obj);

The name 'kvm_arm_add_vcpu_properties' says nothing about being specific to the timer. So this is either the wrong place for this function, or the function is named wrong. I'd say it's the wrong place, because, as the comment above kvm_arm_add_vcpu_properties() implies, the function is for all 'kvm-*' prefixed properties, not just timer related ones. It's true we don't have any others yet, but we will. I have plans to post kvm-steal-time soon, and despite it also having 'time' in its name, it shouldn't depend on ARM_FEATURE_GENERIC_TIMER.

How about the below [untested] patch instead?

Thanks,
drew

target/arm/cpu.c +4 -2
index 32bec156f2d4..e9084f98ef10 100644
@@ -1245,6 +1245,10 @@ void arm_cpu_post_init(Object *obj)
     if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) {
         qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property);
     }
+
+    if (kvm_enabled()) {
+        kvm_arm_add_vcpu_properties();
+    }
 }
 
 static void arm_cpu_finalizefn(Object *obj)
@@ -2029,7 +2033,6 @@ static void arm_max_initfn(Object *obj)
 
     if (kvm_enabled()) {
         kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
     } else {
         cortex_a15_initfn(obj);
 
@@ -2183,7 +2186,6 @@ static void arm_host_initfn(Object *obj)
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
         aarch64_add_sve_properties(obj);
     }
-    kvm_arm_add_vcpu_properties(obj);
     arm_cpu_post_init(obj);
 }
 
target/arm/cpu64.c +0 -1
index cbc5c3868fce..778cecc2e6ca 100644
@@ -592,7 +592,6 @@ static void aarch64_max_initfn(Object *obj)
 
     if (kvm_enabled()) {
         kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
     } else {
         uint64_t t;
         uint32_t u;
target/arm/kvm.c +11 -10
index 4bdbe6dcac07..eef3bbd1cc2c 100644
@@ -194,17 +194,18 @@ static void kvm_no_adjvtime_set(Object *obj, bool value, Error **errp)
 /* KVM VCPU properties should be prefixed with "kvm-". */
 void kvm_arm_add_vcpu_properties(Object *obj)
 {
-    if (!kvm_enabled()) {
-        return;
-    }
+    ARMCPU *cpu = ARM_CPU(obj);
+    CPUARMState *env = &cpu->env;
 
-    ARM_CPU(obj)->kvm_adjvtime = true;
-    object_property_add_bool(obj, "kvm-no-adjvtime", kvm_no_adjvtime_get,
-                             kvm_no_adjvtime_set);
-    object_property_set_description(obj, "kvm-no-adjvtime",
-                                    "Set on to disable the adjustment of "
-                                    "the virtual counter. VM stopped time "
-                                    "will be counted.");
+    if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) {
+        cpu->kvm_adjvtime = true;
+        object_property_add_bool(obj, "kvm-no-adjvtime", kvm_no_adjvtime_get,
+                                 kvm_no_adjvtime_set);
+        object_property_set_description(obj, "kvm-no-adjvtime",
+                                        "Set on to disable the adjustment of "
+                                        "the virtual counter. VM stopped time "
+                                        "will be counted.");
+    }
 }
 
 bool kvm_arm_pmu_supported(CPUState *cpu)
Quoted 36 lines
target/arm/cpu.c +0 -2
     }
 }
 
@@ -2029,7 +2030,6 @@ static void arm_max_initfn(Object *obj)
 
     if (kvm_enabled()) {
         kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
     } else {
         cortex_a15_initfn(obj);
 
@@ -2183,7 +2183,6 @@ static void arm_host_initfn(Object *obj)
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
         aarch64_add_sve_properties(obj);
     }
-    kvm_arm_add_vcpu_properties(obj);
     arm_cpu_post_init(obj);
 }
 
target/arm/cpu64.c +0 -1
index cbc5c3868f..778cecc2e6 100644
@@ -592,7 +592,6 @@ static void aarch64_max_initfn(Object *obj)
 
     if (kvm_enabled()) {
         kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
     } else {
         uint64_t t;
         uint32_t u;
Signature · 1 line
2.23.0
#3 lore raw
Quoted 10 lines · Andrew Jones

The name 'kvm_arm_add_vcpu_properties' says nothing about being specific to the timer. So this is either the wrong place for this function, or the function is named wrong. I'd say it's the wrong place, because, as the comment above kvm_arm_add_vcpu_properties() implies, the function is for all 'kvm-*' prefixed properties, not just timer related ones. It's true we don't have any others yet, but we will. I have plans to post kvm-steal-time soon, and despite it also having 'time' in its name, it shouldn't depend on ARM_FEATURE_GENERIC_TIMER.

How about the below [untested] patch instead?

Your patch is the code arrangement I had in mind, yes.

-- PMM

author
#4 lore raw
In reply to Andrew Jones
Quoted 28 lines · Andrew Jones
Quoted 27 lines · Ying Fang

Virtual time adjustment was implemented for virt-5.0 machine type, but the cpu property was enabled only for host-passthrough and max cpu model. Let's add it for arm cpu which has the gernic timer feature enabled.

---
v2:
- move kvm_arm_add_vcpu_properties into arm_cpu_post_init

v1:
- initial commit
- https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg08518.html

---
  target/arm/cpu.c   | 3 +--
  target/arm/cpu64.c | 1 -
  2 files changed, 1 insertion(+), 3 deletions(-)
target/arm/cpu.c +0 -0
index 32bec156f2..1e9b7a51f2 100644
@@ -1244,6 +1244,7 @@ void arm_cpu_post_init(Object *obj)
 
Quoted 10 lines

target/arm/cpu.c void arm_cpu_post_init(Object *obj)

Quoted 3 lines
target/arm/cpu.c +1 -0
      if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) {
          qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property);
+        kvm_arm_add_vcpu_properties(obj);

The name 'kvm_arm_add_vcpu_properties' says nothing about being specific to the timer. So this is either the wrong place for this function, or the function is named wrong. I'd say it's the wrong place, because, as the comment above kvm_arm_add_vcpu_properties() implies, the function is for all 'kvm-*' prefixed properties, not just timer related ones. It's true we don't have any others yet, but we will. I have plans to post

can't agree more.

Quoted 2 lines

kvm-steal-time soon, and despite it also having 'time' in its name, it shouldn't depend on ARM_FEATURE_GENERIC_TIMER.

yes, that would be nice.

Quoted 2 lines

How about the below [untested] patch instead?

this patch is much more reasonable for me, thanks for your help. I've tested it and it works fine.

Quoted 9 lines

Thanks,
drew

target/arm/cpu.c +0 -0
index 32bec156f2d4..e9084f98ef10 100644

target/arm/cpu.c void arm_cpu_post_init(Object *obj) · line 1250

Quoted 6 lines
target/arm/cpu.c +3 -0
@@ -1245,6 +1245,10 @@ void arm_cpu_post_init(Object *obj)
      if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) {
          qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property);
      }
+
+    if (kvm_enabled()) {
+        kvm_arm_add_vcpu_properties()

should be kvm_arm_add_vcpu_properties(obj);

Quoted 107 lines
target/arm/cpu.c +1 -2
+    }
  }
 
  static void arm_cpu_finalizefn(Object *obj)
@@ -2029,7 +2033,6 @@ static void arm_max_initfn(Object *obj)
 
      if (kvm_enabled()) {
          kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
      } else {
          cortex_a15_initfn(obj);
 
@@ -2183,7 +2186,6 @@ static void arm_host_initfn(Object *obj)
      if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
          aarch64_add_sve_properties(obj);
      }
-    kvm_arm_add_vcpu_properties(obj);
      arm_cpu_post_init(obj);
  }
 
target/arm/cpu64.c +0 -1
index cbc5c3868fce..778cecc2e6ca 100644
@@ -592,7 +592,6 @@ static void aarch64_max_initfn(Object *obj)
 
      if (kvm_enabled()) {
          kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
      } else {
          uint64_t t;
          uint32_t u;
target/arm/kvm.c +11 -10
index 4bdbe6dcac07..eef3bbd1cc2c 100644
@@ -194,17 +194,18 @@ static void kvm_no_adjvtime_set(Object *obj, bool value, Error **errp)
  /* KVM VCPU properties should be prefixed with "kvm-". */
  void kvm_arm_add_vcpu_properties(Object *obj)
  {
-    if (!kvm_enabled()) {
-        return;
-    }
+    ARMCPU *cpu = ARM_CPU(obj);
+    CPUARMState *env = &cpu->env;
 
-    ARM_CPU(obj)->kvm_adjvtime = true;
-    object_property_add_bool(obj, "kvm-no-adjvtime", kvm_no_adjvtime_get,
-                             kvm_no_adjvtime_set);
-    object_property_set_description(obj, "kvm-no-adjvtime",
-                                    "Set on to disable the adjustment of "
-                                    "the virtual counter. VM stopped time "
-                                    "will be counted.");
+    if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) {
+        cpu->kvm_adjvtime = true;
+        object_property_add_bool(obj, "kvm-no-adjvtime", kvm_no_adjvtime_get,
+                                 kvm_no_adjvtime_set);
+        object_property_set_description(obj, "kvm-no-adjvtime",
+                                        "Set on to disable the adjustment of "
+                                        "the virtual counter. VM stopped time "
+                                        "will be counted.");
+    }
  }
 
  bool kvm_arm_pmu_supported(CPUState *cpu)
Quoted 38 lines
target/arm/cpu.c +0 -2
      }
  }
 
@@ -2029,7 +2030,6 @@ static void arm_max_initfn(Object *obj)
 
      if (kvm_enabled()) {
          kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
      } else {
          cortex_a15_initfn(obj);
 
@@ -2183,7 +2183,6 @@ static void arm_host_initfn(Object *obj)
      if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
          aarch64_add_sve_properties(obj);
      }
-    kvm_arm_add_vcpu_properties(obj);
      arm_cpu_post_init(obj);
  }
 
target/arm/cpu64.c +0 -1
index cbc5c3868f..778cecc2e6 100644
@@ -592,7 +592,6 @@ static void aarch64_max_initfn(Object *obj)
 
      if (kvm_enabled()) {
          kvm_arm_set_cpu_features_from_host(cpu);
-        kvm_arm_add_vcpu_properties(obj);
      } else {
          uint64_t t;
          uint32_t u;
Signature · 1 line
2.23.0

.