RISC-V: Add support for ACPI RQSC table
cover RISC-V: Add support for ACPI RQSC table
Add support for the ACPI RISC-V Quality of Service Controller (RQSC) table [1] which describes the CBQRI controllers present in a system. This series is based on the v5 series that implements Ssqosid extension and CBQRI controllers [2]. The patches are also available as the b4/riscv-rqsc branch [3].
This series is marked as an RFC due to open issues:
- The "Add cache structure table creation for PPTT table" series [4] by Sia Jee Heng is used to generate to the PPTT table with a cache type 1 structure for a 3-layer cache topology. This series doesn't seem to have made progress on landing upstream.
- cluster_id is not set by the riscv arch, so cores 0-3 are hard-coded to be cluster 0 and cores 4-8 are cluster 1. The proper solution is for the riscv code to set cluster_id the same way as the arm code.
- cluster 0 uses the first L2 cache controller and cluster 1 uses the second L2 cache controller. A more general solution is to make the L2 cache private to the cluster and not private to the core.
- struct CPUCaches is modified to add CPUCacheInfo *l2_cluster1_cache and CPUCacheInfo *l2_cluster2_cache. This is a hack to support the example configuration used for CBQRI. A solution could make use of the flexible approach in the "Specifying cache topology on ARM" patch series by Alireza Sanaee [5].
- Need a solution to correlate bandwidth controllers to the Proximity Domain for Memory Affinity Structures in the SRAT table.
There is a Linux kernel patch series [6] and branch [7] that implement Ssqosid and CBQRI support in resctrl as well as parsing the RQSC to discover the CBQRI controllers in the system.
This Qemu series was developed and tested with the following configuration:
Base addr Size 0x4820000 4KB Cluster 0 L2 cache controller 0x4821000 4KB Cluster 1 L2 cache controller 0x4828000 4KB Memory controller 0 0x4829000 4KB Memory controller 1 0X482a000 4KB Memory controller 2 0X482b000 4KB Shared LLC cache controller
The example platform is created with the following:
qemu-system-riscv64 \
-M virt,pflash0=pflash0,pflash1=pflash1,aia=aplic-imsic \
-smp cpus=8,sockets=1,clusters=2,cores=4,threads=1 \
-m 1G \
-nographic \
-kernel ${LINUX}/arch/riscv/boot/Image \
-append "root=/dev/vda rootwait" \
-blockdev node-name=pflash0,driver=file,read-only=on,filename=${EDK}/RISCV_VIRT_CODE.fd \
-blockdev node-name=pflash1,driver=file,filename=${EDK}/RISCV_VIRT_VARS.fd \
-drive if=none,file=${ROOTFS}/rootfs.ext2,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-device qemu-xhci \
-device usb-kbd \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0 \
-device riscv.cbqri.capacity,max_mcids=256,max_rcids=64,ncblks=12,alloc_op_flush_rcid=false,mon_op_config_event=false,mon_op_read_counter=false,mon_evt_id_none=false,mon_evt_id_occupancy=false,mmio_base=0x04820000 \
-device riscv.cbqri.capacity,max_mcids=256,max_rcids=64,ncblks=12,alloc_op_flush_rcid=false,mon_op_config_event=false,mon_op_read_counter=false,mon_evt_id_none=false,mon_evt_id_occupancy=false,mmio_base=0x04821000 \
-device riscv.cbqri.capacity,max_mcids=256,max_rcids=64,ncblks=16,mmio_base=0x0482B000 \
-device riscv.cbqri.bandwidth,max_mcids=256,max_rcids=64,nbwblks=1024,mrbwb=819,mmio_base=0x04828000 \
-device riscv.cbqri.bandwidth,max_mcids=256,max_rcids=64,nbwblks=1024,mrbwb=819,mmio_base=0x04829000 \
-device riscv.cbqri.bandwidth,max_mcids=256,max_rcids=64,nbwblks=1024,mrbwb=819,mmio_base=0x0482a000[1] https://github.com/riscv-non-isa/riscv-rqsc/blob/main/src/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://github.com/tt-fustini/qemu/tree/b4/riscv-rqsc
[4] https://lore.kernel.org/all/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/
[6] https://lore.kernel.org/all/[email protected]/
[7] https://git.kernel.org/pub/scm/linux/kernel/git/fustini/linux.git/log/?h=b4/ssqosid-cbqri
---
Drew Fustini (4):
hw/riscv: virt-acpi-build: Adjust RQSC cache properties
include: acpi: aml-build: Add Cache ID and L2 cache for each cluster
acpi: aml-build: Add Cache ID to PPTT table and set Cluster ID hw/riscv: virt-acpi-build: Build PPTT table before RQSC table
Sia Jee Heng (2):
acpi: aml-build: Add cache structure table creation for PPTT table hw/riscv: virt-acpi-build: Generate PPTT table
Vasudevan Srinivasan (1):
hw/riscv: Add support for ACPI RQSC table
hw/acpi/aml-build.c | 108 ++++++++++++++++++++++++-- hw/core/sysbus-fdt.c | 3 + hw/riscv/cbqri_bandwidth.c | 11 +++ hw/riscv/cbqri_capacity.c | 11 +++ hw/riscv/virt-acpi-build.c | 181 ++++++++++++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 1 + include/hw/acpi/aml-build.h | 23 +++++- include/hw/riscv/cbqri.h | 12 +++ 8 files changed, 343 insertions(+), 7 deletions(-)
---
base-commit: 117b7aeabad83d437dfa69f2ee2bac75c0e02abe
change-id: 20260201-riscv-rqsc-ae806ee0a7aa
Best regards,
Signature · 1 line
Drew Fustini <[email protected]>
RFC PATCH 1/7 hw/riscv: Add support for ACPI RQSC table
From: Vasudevan Srinivasan <[email protected]>
In build_rqsc(), set Res ID 1 for each cache controller in RQSC table. The AML code that generates that PPTT table uses the cache controller mmio_base address as the Cache ID.
TODO: Similar plumbing still needs to be done to correlate bandwitch controllers to the Proximity Domain for Memory Affinity Structures in the SRAT table.
--- hw/core/sysbus-fdt.c | 3 ++ hw/riscv/cbqri_bandwidth.c | 11 +++++ hw/riscv/cbqri_capacity.c | 11 +++++ hw/riscv/virt-acpi-build.c | 121 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/riscv/cbqri.h | 12 +++++ 5 files changed, 158 insertions(+)
hw/core/sysbus-fdt.c +3 -0
@@ -36,6 +36,7 @@#include "hw/display/ramfb.h" #include "hw/uefi/var-service-api.h" #include "hw/arm/fdt.h" +#include "hw/riscv/cbqri.h" /* * internal struct that contains the information to create dynamic
@@ -140,6 +141,8 @@ static const BindingEntry bindings[] = {TYPE_BINDING (TYPE_ARM_SMMUV3 , no_fdt_node),TYPE_BINDING (TYPE_RAMFB_DEVICE , no_fdt_node),TYPE_BINDING (TYPE_UEFI_VARS_SYSBUS , add_uefi_vars_node), +TYPE_BINDING (TYPE_RISCV_CBQRI_BC , no_fdt_node), +TYPE_BINDING (TYPE_RISCV_CBQRI_CC , no_fdt_node), TYPE_BINDING("", NULL), /* last element */ };
hw/riscv/cbqri_bandwidth.c +11 -0
@@ -635,4 +635,15 @@ DeviceState *riscv_cbqri_bc_create(hwaddr addr,return dev; } +void get_bc_details (DeviceState *ds,const char *type,RQSC *rqsc) +{ +if (strcmp (type,TYPE_RISCV_CBQRI_BC ) ==0 ) { +RiscvCbqriBandwidthState *bcs =RISCV_CBQRI_BC (ds); + (rqsc)->controllerType =1 ; + (rqsc)->mmio_base = bcs->mmio_base; + (rqsc)->rcidCount = bcs->nb_rcids; + (rqsc)->mcidCount = bcs->nb_mcids; + } +} +type_init (riscv_cbqri_bc_register_types)
hw/riscv/cbqri_capacity.c +11 -0
@@ -730,4 +730,15 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr,return dev; } +void get_cc_details (DeviceState *ds,const char *type,RQSC *rqsc) +{ +if (strcmp (type,TYPE_RISCV_CBQRI_CC ) ==0 ) { +RiscvCbqriCapacityState *ccs =RISCV_CBQRI_CC (ds); + rqsc->controllerType =0 ; + rqsc->mmio_base = ccs->mmio_base; + rqsc->rcidCount = ccs->nb_rcids; + rqsc->mcidCount = ccs->nb_mcids; + } +} +type_init (riscv_cbqri_cc_register_types)
hw/riscv/virt-acpi-build.c +121 -0
139 lines not on this page · raw message
include/hw/riscv/cbqri.h +12 -0
@@ -79,4 +79,16 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr,DeviceState *riscv_cbqri_bc_create (hwaddr addr,const RiscvCbqriBandwidthCaps *caps,const char *target_name); +void example_soc_cbqri_init (void ); + +typedef struct _RQSC { +u_int8_t controllerType; +u_int64_t mmio_base; +u_int16_t rcidCount; +u_int16_t mcidCount; +}RQSC ; + +void get_bc_details (DeviceState *ds,const char *type,RQSC *rqsc); +void get_cc_details (DeviceState *ds,const char *type,RQSC *rqsc); +#endif
Signature · 1 line
2.43.0
RFC PATCH 2/7 acpi: aml-build: Add cache structure table creation for PPTT table
In reply to Drew FustiniFrom: Sia Jee Heng <[email protected]>
Adds cache structure table generation for the Processor Properties Topology Table (PPTT) to describe cache hierarchy information for ACPI guests.
A 3-level cache topology is employed here, referring to the type 1 cache structure according to ACPI spec v6.3. The L1 cache and L2 cache are private resources for the core, while the L3 cache is the private resource for the cluster.
In the absence of cluster values in the QEMU command, a 2-layer cache is expected. The default cache value should be passed in from the architecture code.
Examples:
3-layer: -smp 4,sockets=1,clusters=2,cores=2,threads=1 2-layer: -smp 4,sockets=1,cores=2,threads=2
--- hw/acpi/aml-build.c | 69 +++++++++++++++++++++++++++++++++++++++++---- include/hw/acpi/aml-build.h | 21 +++++++++++++- 2 files changed, 84 insertions(+), 6 deletions(-)
hw/acpi/aml-build.c +64 -5
@@ -2140,12 +2140,41 @@ void build_spcr(GArray *table_data, BIOSLinker *linker, }acpi_table_end (linker, &table); } + +/* ACPI spec, Revision 6.3 Cache type structure (Type 1) */ +static void build_cache_structure (GArray *tbl, +uint32_t next_level, +CPUCacheInfo *cache_info) +{ +/* Cache type structure */ +build_append_byte (tbl,1 ); +/* Length */ +build_append_byte (tbl,24 ); +/* Reserved */ +build_append_int_noprefix (tbl,0 ,2 ); +/* Flags */ +build_append_int_noprefix (tbl,0x7f ,4 ); +/* Next level cache */ +build_append_int_noprefix (tbl, next_level,4 ); +/* Size */ +build_append_int_noprefix (tbl, cache_info->size,4 ); +/* Number of sets */ +build_append_int_noprefix (tbl, cache_info->sets,4 ); +/* Associativity */ +build_append_byte (tbl, cache_info->associativity); +/* Attributes */ +build_append_byte (tbl, cache_info->attributes); +/* Line size */ +build_append_int_noprefix (tbl, cache_info->line_size,2 ); +} +/* * ACPI spec, Revision 6.3 * 5.2.29 Processor Properties Topology Table (PPTT) */ void build_pptt (GArray *table_data,BIOSLinker *linker,MachineState *ms, -const char *oem_id,const char *oem_table_id) +const char *oem_id,const char *oem_table_id, +const CPUCaches *CPUCaches) {MachineClass *mc =MACHINE_GET_CLASS (ms);CPUArchIdList *cpus = ms->possible_cpus;
@@ -2153,6 +2182,8 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,uint32_t socket_offset =0 , cluster_offset =0 , core_offset =0 ;uint32_t pptt_start = table_data->len;uint32_t root_offset; +uint32_t l3_offset =0 , priv_num =0 ; +uint32_t priv_rsrc[3 ] = {0 };int n;AcpiTable table = { .sig ="PPTT" , .rev =2 , .oem_id = oem_id, .oem_table_id = oem_table_id };
@@ -2183,11 +2214,15 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, socket_id = cpus->cpus[n].props.socket_id; cluster_id =-1 ; core_id =-1 ; + priv_num =0 ; socket_offset = table_data->len - pptt_start;build_processor_hierarchy_node (table_data, (1 <<0 ) |/* Physical package */ (1 <<4 ),/* Identical Implementation */ - root_offset, socket_id,NULL ,0 ); + root_offset, + socket_id, +NULL , + priv_num); }if (mc->smp_props.clusters_supported && mc->smp_props.has_clusters) {
@@ -2195,21 +2230,45 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,assert (cpus->cpus[n].props.cluster_id > cluster_id); cluster_id = cpus->cpus[n].props.cluster_id; core_id =-1 ; + priv_num =0 ; + l3_offset = table_data->len - pptt_start; +/* L3 cache type structure */ +if (CPUCaches && CPUCaches->l3_cache) { + priv_num =1 ; +build_cache_structure (table_data,0 , CPUCaches->l3_cache); + } cluster_offset = table_data->len - pptt_start;build_processor_hierarchy_node (table_data, (0 <<0 ) |/* Not a physical package */ (1 <<4 ),/* Identical Implementation */ - socket_offset, cluster_id,NULL ,0 ); + socket_offset, cluster_id, &l3_offset, priv_num); } }else { cluster_offset = socket_offset; } +if (CPUCaches) { +/* L2 cache type structure */ + priv_rsrc[0 ] = table_data->len - pptt_start; +build_cache_structure (table_data,0 , CPUCaches->l2_cache); + +/* L1d cache type structure */ + priv_rsrc[1 ] = table_data->len - pptt_start; +build_cache_structure (table_data, priv_rsrc[0 ], + CPUCaches->l1d_cache); + +/* L1i cache type structure */ + priv_rsrc[2 ] = table_data->len - pptt_start; +build_cache_structure (table_data, priv_rsrc[0 ], + CPUCaches->l1i_cache); + + priv_num =3 ; + }if (ms->smp.threads ==1 ) {build_processor_hierarchy_node (table_data, (1 <<1 ) |/* ACPI Processor ID valid */ (1 <<3 ),/* Node is a Leaf */ - cluster_offset, n,NULL ,0 ); + cluster_offset, n, priv_rsrc, priv_num); }else {if (cpus->cpus[n].props.core_id != core_id) {assert (cpus->cpus[n].props.core_id > core_id);
@@ -2225,7 +2284,7 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, (1 <<1 ) |/* ACPI Processor ID valid */ (1 <<2 ) |/* Processor is a Thread */ (1 <<3 ),/* Node is a Leaf */ - core_offset, n, NULL, 0); + core_offset, n, priv_rsrc, priv_num); } }
include/hw/acpi/aml-build.h +20 -1
@@ -3,6 +3,7 @@#include "hw/acpi/acpi-defs.h" #include "hw/acpi/bios-linker-loader.h" +#include "include/hw/core/cpu.h" #define ACPI_BUILD_APPNAME6 "BOCHS "#define ACPI_BUILD_APPNAME8 "BXPC "
@@ -234,6 +235,23 @@ struct CrsRangeSet {GPtrArray *mem_64bit_ranges; } CrsRangeSet; +typedef +struct CPUCacheInfo { +enum CacheType type;/* Cache Type*/ +uint32_t size;/* Size of the cache in bytes */ +uint32_t sets;/* Number of sets in the cache */ +uint8_t associativity;/* Cache associativity */ +uint8_t attributes;/* Cache attributes */ +uint16_t line_size;/* Line size in bytes */ +}CPUCacheInfo ; + +typedef +struct CPUCaches { +CPUCacheInfo *l1d_cache; +CPUCacheInfo *l1i_cache; +CPUCacheInfo *l2_cache; +CPUCacheInfo *l3_cache; +}CPUCaches ;/* * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors
@@ -499,7 +517,8 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms, const char *oem_id, const char *oem_table_id);void build_pptt (GArray *table_data,BIOSLinker *linker,MachineState *ms, -const char *oem_id,const char *oem_table_id); +const char *oem_id,const char *oem_table_id, +const CPUCaches *CPUCaches);void build_fadt (GArray *tbl,BIOSLinker *linker,const AcpiFadtData *f,const char *oem_id,const char *oem_table_id);
Signature · 1 line
2.43.0
RFC PATCH 3/7 hw/riscv: virt-acpi-build: Generate PPTT table
In reply to Drew FustiniFrom: Sia Jee Heng <[email protected]>
Generate the Processor Properties Topology Table (PPTT) with a cache type 1 structure for RISC-V virtual machine. A 3-layer cache topology is used.
--- hw/riscv/virt-acpi-build.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 1 + 2 files changed, 48 insertions(+)
hw/riscv/virt-acpi-build.c +47 -0
@@ -40,6 +40,7 @@#include "qapi/error.h" #include "qemu/error-report.h" #include "system/reset.h" +#include "qemu/units.h" #define ACPI_BUILD_TABLE_SIZE 0x20000#define ACPI_BUILD_INTC_ID (socket, index) ((socket << 24) | (index))
@@ -973,6 +974,48 @@ build_srat(GArray *table_data, BIOSLinker *linker, RISCVVirtState *vms)acpi_table_end (linker, &table); } +static void pptt_setup (GArray *table_data,BIOSLinker *linker,MachineState *ms, +const char *oem_id,const char *oem_table_id) +{ +CPUCaches default_cache_info = { + .l1d_cache = &(CPUCacheInfo ) { + .type =DATA_CACHE , + .size =64 * KiB, + .line_size =64 , + .associativity =4 , + .sets =256 , + .attributes =0x02 , + }, + .l1i_cache = &(CPUCacheInfo ) { + .type =INSTRUCTION_CACHE , + .size =64 * KiB, + .line_size =64 , + .associativity =4 , + .sets =256 , + .attributes =0x04 , + }, + .l2_cache = &(CPUCacheInfo ) { + .type =UNIFIED_CACHE , + .size =2048 * KiB, + .line_size =64 , + .associativity =8 , + .sets =4096 , + .attributes =0x0a , + }, + .l3_cache = &(CPUCacheInfo ) { + .type =UNIFIED_CACHE , + .size =4096 * KiB, + .line_size =64 , + .associativity =8 , + .sets =8192 , + .attributes =0x0a , + }, + }; + +build_pptt (table_data, linker, ms, oem_id, oem_table_id, + &default_cache_info); +} +static void virt_acpi_build (RISCVVirtState *s,AcpiBuildTables *tables) {GArray *table_offsets;
@@ -1015,6 +1058,10 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_rqsc (tables_blob, tables->linker, s); +acpi_add_table (table_offsets, tables_blob); +pptt_setup (tables_blob, tables->linker, ms, + s->oem_id, s->oem_table_id); +acpi_add_table (table_offsets, tables_blob); {AcpiMcfgInfo mcfg = {
hw/riscv/virt.c +1 -0
@@ -1929,6 +1929,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props; mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id; mc->numa_mem_supported = true; + mc->smp_props.clusters_supported = true;/* platform instead of architectural choice */ mc->cpu_cluster_has_numa_boundary = true; mc->default_ram_id ="riscv_virt_board.ram" ;
Signature · 1 line
2.43.0
RFC PATCH 4/7 hw/riscv: virt-acpi-build: Adjust RQSC cache properties
In reply to Drew FustiniIn pptt_setup(), set the cache properties to match the example CBQRI controller configuration.
Base addr
0x4820000 Cluster 0 L2 cache controller 0x4821000 Cluster 1 L2 cache controller 0X482b000 Shared LLC cache controller
--- hw/riscv/virt-acpi-build.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
hw/riscv/virt-acpi-build.c +20 -7
@@ -985,6 +985,7 @@ static void pptt_setup(GArray *table_data, BIOSLinker *linker, MachineState *ms, .associativity = 4, .sets = 256, .attributes = 0x02, + .id = 0x1D, }, .l1i_cache = &(CPUCacheInfo ) { .type =INSTRUCTION_CACHE ,
@@ -993,22 +994,34 @@ static void pptt_setup(GArray *table_data, BIOSLinker *linker, MachineState *ms, .associativity = 4, .sets = 256, .attributes = 0x04, + .id = 0x1E, }, - .l2_cache = &(CPUCacheInfo ) { + .l2_cluster1_cache = &(CPUCacheInfo ) { .type =UNIFIED_CACHE , - .size =2048 * KiB, + .size =750 * KiB, .line_size =64 , - .associativity =8 , - .sets =4096 , + .associativity =12 , + .sets =1000 , + .attributes =0x0a , + .id =0x4821000 , + }, + .l2_cluster2_cache = &(CPUCacheInfo ) { + .type =UNIFIED_CACHE , + .size =750 * KiB, + .line_size =64 , + .associativity =12 , + .sets =1000 , .attributes =0x0a , + .id =0x4820000 , }, .l3_cache = &(CPUCacheInfo ) { .type =UNIFIED_CACHE , - .size =4096 * KiB, + .size =3 * MiB, .line_size =64 , - .associativity =8 , - .sets =8192 , + .associativity =16 , + .sets =4096 , .attributes =0x0a , + .id =0x482b000 , }, };
Signature · 1 line
2.43.0
RFC PATCH 5/7 include: acpi: aml-build: Add Cache ID and L2 cache for each cluster
In reply to Drew FustiniACPI 6.4 added Cache ID to the PPTT Cache Type Structure so add id field to CPUCacheInfo.
Add an L2 cache for each of the two clusters in CPUCaches.
NOTE: This is hack as it mixes the specifics of the CBQRI example SoC into the the core ACPI AML code. A proper solution would make use of the flexible approach in the "Specifying cache topology on ARM" patch series by Alireza Sanaee.
--- include/hw/acpi/aml-build.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/hw/acpi/aml-build.h +3 -1
@@ -243,13 +243,15 @@ struct CPUCacheInfo {uint8_t associativity;/* Cache associativity */ uint8_t attributes;/* Cache attributes */ uint16_t line_size;/* Line size in bytes */ +uint32_t id;/* Cache ID - added in ACPI 6.4 */ } CPUCacheInfo;typedef struct CPUCaches {CPUCacheInfo *l1d_cache;CPUCacheInfo *l1i_cache; -CPUCacheInfo *l2_cache; +CPUCacheInfo *l2_cluster1_cache; +CPUCacheInfo *l2_cluster2_cache;CPUCacheInfo *l3_cache; }CPUCaches ;
Signature · 1 line
2.43.0
RFC PATCH 6/7 acpi: aml-build: Add Cache ID to PPTT table and set Cluster ID
In reply to Drew FustiniBump PPTT table revision to 3 which corresponds to ACPI 6.4. A new field was added to the end of PPTT for the Cache ID. Ensure the Cache ID Valid bit is set in the flags.
HACK: cluster_id is not set by the riscv arch so force setting it. Divide the cores between the number of clusters. For the CBQRI example, cores 0-3 are cluster 0 and cores 4-8 are cluster 1. The proper solution is for the riscv code to set cluster_id the same way as the arm code.
HACK: cluster 0 uses the first L2 cache controller and cluster 1 uses the second L2 cache controller. A more general solution is to make the L2 cache private to the cluster and not private to the core.
The series "[PATCH v8 0/6] Specifying cache topology on ARM" looks to be the correct approach. RISC-V support could be based on this.
--- hw/acpi/aml-build.c | 57 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-)
hw/acpi/aml-build.c +47 -10
@@ -2148,12 +2148,16 @@ static void build_cache_structure(GArray *tbl, {/* Cache type structure */ build_append_byte (tbl,1 ); -/* Length */ -build_append_byte (tbl,24 ); +/* +* Length - ACPI 6.4 table 5.140 shows size 28 which increased from +* previous version to include space for the new cache id property +* https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#cache-type-structure-table +*/ +build_append_byte (tbl,28 );/* Reserved */ build_append_int_noprefix (tbl,0 ,2 ); -/* Flags */ -build_append_int_noprefix (tbl,0x7f ,4 ); +/* Flags - enable bit 7 for Cache ID Valid */ +build_append_int_noprefix (tbl,0xff ,4 );/* Next level cache */ build_append_int_noprefix (tbl, next_level,4 );/* Size */
@@ -2166,6 +2170,8 @@ static void build_cache_structure(GArray *tbl,build_append_byte (tbl, cache_info->attributes);/* Line size */ build_append_int_noprefix (tbl, cache_info->line_size,2 ); +/* Cache ID */ +build_append_int_noprefix (tbl, cache_info->id,4 ); }/*
@@ -2183,9 +2189,13 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,uint32_t pptt_start = table_data->len;uint32_t root_offset;uint32_t l3_offset =0 , priv_num =0 ; -uint32_t priv_rsrc[3 ] = {0 }; +uint32_t priv_rsrc[4 ] = {0 };int n; -AcpiTable table = { .sig ="PPTT" , .rev =2 , +/* +* rev should 3 not 2 based on +* https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#processor-properties-topology-table-pptt +*/ +AcpiTable table = { .sig ="PPTT" , .rev =3 , .oem_id = oem_id, .oem_table_id = oem_table_id };acpi_table_begin (&table, table_data);
@@ -2209,6 +2219,16 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,* created. */ for (n =0 ; n < cpus->len; n++) { +/* +* HACK: cluster_id is not set by the riscv arch so force setting it. +* Divide the cores between the number of clusters. For the CBQRI +* example, cores 0-3 are cluster 0 and cores 4-8 are cluster 1. +* The correct solution is for the riscv code to set cluster_id the +* same way the arm code is doing it. +*/ + cpus->cpus[n].props.cluster_id = (n / (ms->smp.cores * ms->smp.threads)) + % ms->smp.clusters; +if (cpus->cpus[n].props.socket_id != socket_id) {assert (cpus->cpus[n].props.socket_id > socket_id); socket_id = cpus->cpus[n].props.socket_id;
@@ -2250,7 +2270,25 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,if (CPUCaches) {/* L2 cache type structure */ priv_rsrc[0 ] = table_data->len - pptt_start; -build_cache_structure (table_data,0 , CPUCaches->l2_cache); + +/* +* HACK: cluster 0 uses the first L2 cache controller and +* cluster 1 uses the second L2 cache controller. A more +* general solution is to make the L2 cache private to +* the cluster and not private to the core. +* +* This series seems to be the correct direction: +* https://lore.kernel.org/all/[email protected]/ +* but it is only adding support for ARM so it needs to +* be broaden to support RISC-V too +*/ +if (cluster_id ==0 ) { +build_cache_structure (table_data, l3_offset, + CPUCaches->l2_cluster1_cache); + }else { +build_cache_structure (table_data, l3_offset, + CPUCaches->l2_cluster2_cache); + }/* L1d cache type structure */ priv_rsrc[1 ] = table_data->len - pptt_start;
@@ -2261,14 +2299,13 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms, priv_rsrc[2 ] = table_data->len - pptt_start;build_cache_structure (table_data, priv_rsrc[0 ], CPUCaches->l1i_cache); - - priv_num =3 ; + priv_num =2 ; }if (ms->smp.threads ==1 ) {build_processor_hierarchy_node (table_data, (1 <<1 ) |/* ACPI Processor ID valid */ (1 <<3 ),/* Node is a Leaf */ - cluster_offset, n, priv_rsrc, priv_num); + cluster_offset, n, &priv_rsrc[1 ], priv_num); }else {if (cpus->cpus[n].props.core_id != core_id) {assert (cpus->cpus[n].props.core_id > core_id);
Signature · 1 line
2.43.0
RFC PATCH 7/7 hw/riscv: virt-acpi-build: Build PPTT table before RQSC table
In reply to Drew FustiniRQSC table will reference cache IDs in PPTT so PPTT must be built first.
--- hw/riscv/virt-acpi-build.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/riscv/virt-acpi-build.c +3 -3
@@ -1068,13 +1068,13 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables)spcr_setup (tables_blob, tables->linker, s); } -acpi_add_table (table_offsets, tables_blob); -build_rqsc (tables_blob, tables->linker, s); -acpi_add_table (table_offsets, tables_blob);pptt_setup (tables_blob, tables->linker, ms, s->oem_id, s->oem_table_id); +acpi_add_table (table_offsets, tables_blob); +build_rqsc (tables_blob, tables->linker, s); +acpi_add_table (table_offsets, tables_blob); {AcpiMcfgInfo mcfg = {
Signature · 1 line
2.43.0