Re: [RFC PATCH 09/12] target/arm/cpu: Add CPU cache description for arm

2020-09-17 Thread Ying Fang




On 9/17/2020 4:39 PM, Andrew Jones wrote:

On Thu, Sep 17, 2020 at 11:20:30AM +0800, Ying Fang wrote:

Add the CPUCacheInfo structure to hold CPU cache information for ARM cpus.
A classic three level cache topology is used here. The default cache
capacity is given and userspace can overwrite these values.


Doesn't TCG already have some sort of fake cache hierarchy? If so, then


TCG may have some sort of fake cache hierarchy via CCSIDR.


we shouldn't be adding another one, we should be simply describing the
one we already have. For KVM, we shouldn't describe anything other than
what is actually on the host.


Yes, I agreed. Cache capacity should be the with host otherwise it may
have bad impact on guest performance, we can do that by query from the
host and make cache capacity configurable from userspace.

Dario Faggioli is going to give a talk about it in KVM forum [1].

[1] 
https://kvmforum2020.sched.com/event/eE1y/virtual-topology-for-virtual-machines-friend-or-foe-dario-faggioli-suse?iframe=no=100%=yes=no


Thanks.



drew

.





Re: [RFC PATCH 09/12] target/arm/cpu: Add CPU cache description for arm

2020-09-17 Thread Andrew Jones
On Thu, Sep 17, 2020 at 11:20:30AM +0800, Ying Fang wrote:
> Add the CPUCacheInfo structure to hold CPU cache information for ARM cpus.
> A classic three level cache topology is used here. The default cache
> capacity is given and userspace can overwrite these values.

Doesn't TCG already have some sort of fake cache hierarchy? If so, then
we shouldn't be adding another one, we should be simply describing the
one we already have. For KVM, we shouldn't describe anything other than
what is actually on the host.

drew




[RFC PATCH 09/12] target/arm/cpu: Add CPU cache description for arm

2020-09-16 Thread Ying Fang
Add the CPUCacheInfo structure to hold CPU cache information for ARM cpus.
A classic three level cache topology is used here. The default cache
capacity is given and userspace can overwrite these values.

Signed-off-by: Ying Fang 
---
 target/arm/cpu.c | 42 ++
 target/arm/cpu.h | 27 +++
 2 files changed, 69 insertions(+)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index c179e0752d..efa8e1974a 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -27,6 +27,7 @@
 #include "qapi/visitor.h"
 #include "cpu.h"
 #include "internals.h"
+#include "qemu/units.h"
 #include "exec/exec-all.h"
 #include "hw/qdev-properties.h"
 #if !defined(CONFIG_USER_ONLY)
@@ -998,6 +999,45 @@ uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz)
 return (Aff1 << ARM_AFF1_SHIFT) | Aff0;
 }
 
+static CPUCaches default_cache_info = {
+.l1d_cache = &(CPUCacheInfo) {
+.type = DATA_CACHE,
+.level = 1,
+.size = 64 * KiB,
+.line_size = 64,
+.associativity = 4,
+.sets = 256,
+.attributes = 0x02,
+},
+.l1i_cache = &(CPUCacheInfo) {
+.type = INSTRUCTION_CACHE,
+.level = 1,
+.size = 64 * KiB,
+.line_size = 64,
+.associativity = 4,
+.sets = 256,
+.attributes = 0x04,
+},
+.l2_cache = &(CPUCacheInfo) {
+.type = UNIFIED_CACHE,
+.level = 2,
+.size = 512 * KiB,
+.line_size = 64,
+.associativity = 8,
+.sets = 1024,
+.attributes = 0x0a,
+},
+.l3_cache = &(CPUCacheInfo) {
+.type = UNIFIED_CACHE,
+.level = 3,
+.size = 65536 * KiB,
+.line_size = 64,
+.associativity = 15,
+.sets = 2048,
+.attributes = 0x0a,
+},
+};
+
 static void cpreg_hashtable_data_destroy(gpointer data)
 {
 /*
@@ -1835,6 +1875,8 @@ static void arm_cpu_realizefn(DeviceState *dev, Error 
**errp)
 }
 }
 
+cpu->caches = default_cache_info;
+
 qemu_init_vcpu(cs);
 cpu_reset(cs);
 
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index a1c7d8ebae..e9e3817e20 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -745,6 +745,30 @@ typedef enum ARMPSCIState {
 
 typedef struct ARMISARegisters ARMISARegisters;
 
+/* Cache information type */
+enum CacheType {
+DATA_CACHE,
+INSTRUCTION_CACHE,
+UNIFIED_CACHE
+};
+
+typedef struct CPUCacheInfo {
+enum CacheType type;  /* Cache Type*/
+uint8_t level;
+uint32_t size;/* Size in bytes */
+uint16_t line_size;   /* Line size in bytes */
+uint8_t associativity;/* Cache associativity */
+uint32_t sets;/* Number of sets */
+uint8_t attributes;   /* Cache attributest  */
+} CPUCacheInfo;
+
+typedef struct CPUCaches {
+CPUCacheInfo *l1d_cache;
+CPUCacheInfo *l1i_cache;
+CPUCacheInfo *l2_cache;
+CPUCacheInfo *l3_cache;
+} CPUCaches;
+
 /**
  * ARMCPU:
  * @env: #CPUARMState
@@ -986,6 +1010,9 @@ struct ARMCPU {
 
 /* Generic timer counter frequency, in Hz */
 uint64_t gt_cntfrq_hz;
+
+/* CPU cache information */
+CPUCaches caches;
 };
 
 unsigned int gt_cntfrq_period_ns(ARMCPU *cpu);
-- 
2.23.0