[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/21] target/arm/kvm: Use a switch for kvm_arm_cpreg_level
From: |
Richard Henderson |
Subject: |
[PATCH 11/21] target/arm/kvm: Use a switch for kvm_arm_cpreg_level |
Date: |
Wed, 22 Nov 2023 22:42:09 -0600 |
Use a switch instead of a linear search through data.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/arm/kvm64.c | 32 +++++++++-----------------------
1 file changed, 9 insertions(+), 23 deletions(-)
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
index 504526b24c..61fb9dbde0 100644
--- a/target/arm/kvm64.c
+++ b/target/arm/kvm64.c
@@ -361,32 +361,18 @@ bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx)
}
}
-typedef struct CPRegStateLevel {
- uint64_t regidx;
- int level;
-} CPRegStateLevel;
-
-/* All system registers not listed in the following table are assumed to be
- * of the level KVM_PUT_RUNTIME_STATE. If a register should be written less
- * often, you must add it to this table with a state of either
- * KVM_PUT_RESET_STATE or KVM_PUT_FULL_STATE.
- */
-static const CPRegStateLevel non_runtime_cpregs[] = {
- { KVM_REG_ARM_TIMER_CNT, KVM_PUT_FULL_STATE },
- { KVM_REG_ARM_PTIMER_CNT, KVM_PUT_FULL_STATE },
-};
-
int kvm_arm_cpreg_level(uint64_t regidx)
{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(non_runtime_cpregs); i++) {
- const CPRegStateLevel *l = &non_runtime_cpregs[i];
- if (l->regidx == regidx) {
- return l->level;
- }
+ /*
+ * All system registers are assumed to be level KVM_PUT_RUNTIME_STATE.
+ * If a register should be written less often, you must add it here
+ * with a state of either KVM_PUT_RESET_STATE or KVM_PUT_FULL_STATE.
+ */
+ switch (regidx) {
+ case KVM_REG_ARM_TIMER_CNT:
+ case KVM_REG_ARM_PTIMER_CNT:
+ return KVM_PUT_FULL_STATE;
}
-
return KVM_PUT_RUNTIME_STATE;
}
--
2.34.1
- Re: [PATCH 12/21] target/arm/kvm: Move kvm_arm_cpreg_level and unexport, (continued)
- [PATCH 10/21] target/arm/kvm: Move kvm_arm_get_host_cpu_features and unexport, Richard Henderson, 2023/11/22
- [PATCH 09/21] target/arm/kvm: Inline kvm_arm_steal_time_supported, Richard Henderson, 2023/11/22
- [PATCH 08/21] target/arm/kvm: Unexport kvm_arm_{get, put}_virtual_time, Richard Henderson, 2023/11/22
- [PATCH 11/21] target/arm/kvm: Use a switch for kvm_arm_cpreg_level,
Richard Henderson <=
- [PATCH 17/21] target/arm/kvm: Unexport kvm_arm_init_cpreg_list, Richard Henderson, 2023/11/22
- [PATCH 14/21] target/arm/kvm: Merge kvm64.c into kvm.c, Richard Henderson, 2023/11/22
- [PATCH 16/21] target/arm/kvm: Unexport kvm_arm_vcpu_finalize, Richard Henderson, 2023/11/22