RISC-V: Add support for ACPI RQSC table
v2 cover RISC-V: Add support for ACPI RQSC table
Add support for the ACPI RISC-V Quality of Service Controllers (RQSC) table [1] that describes the CBQRI controllers [2] present in a system. A capacity controller is described by the PPTT Cache ID of the cache it backs. A bandwidth controller is described by the SRAT proximity domain of its NUMA node.
This series depends on:
- "riscv: implement Ssqosid extension and CBQRI controllers" v8 [3]
- "RISC-V: ACPI: Add PPTT support" v2 from Sunil [4]
- "hw/acpi: Build PPTT rev 3 with cache IDs for MPAM cross-references" from Jinjie's MPAM series [5].
Note: bios-tables-test fails on the riscv64 PPTT golden file
as this patch does not update it.
Tested with the Linux series [6] at the tip of its b4/ssqosid-cbqri-rqsc branch [7], with this configuration:
Base addr Spacing 0x4820000 4KB Cluster 0 L2 cache controller 0x4821000 4KB Cluster 1 L2 cache controller 0x4828000 4KB Memory controller 0 0x482b000 4KB Shared L3 cache controller
qemu-system-riscv64 \
-M virt,pflash0=pflash0,pflash1=pflash1,aia=aplic-imsic,smp-cache.0.cache=l1d,smp-cache.0.topology=core,smp-cache.1.cache=l1i,smp-cache.1.topology=core,smp-cache.2.cache=l2,smp-cache.2.topology=cluster,smp-cache.3.cache=l3,smp-cache.3.topology=socket \
-smp cpus=8,sockets=1,clusters=2,cores=4,threads=1 \
-blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
-blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
-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,cache_level=3,mmio_base=0x0482b000 \
-device riscv.cbqri.bandwidth,max_mcids=256,max_rcids=64,nbwblks=1024,mrbwb=819,mmio_base=0x04828000Changes in v2:
- Drop the RFC prefix as RQSC v1.0 is ratified
- Rebase on Sunil's PPTT series and Jinjie's PPTT Cache ID patch
- Add cache_level and node properties to the CBQRI controllers
- Use the PPTT Cache ID and the SRAT proximity domain as the resource
IDs instead of the MMIO address
- Only build the table when CBQRI controllers are present
- Set the table revision to 1
- Make RCID Count and MCID Count 2 bytes each
- Add the Bandwidth per Block field to memory resources
- Make RISCV_VIRT select RISCV_CBQRI
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://github.com/riscv-non-isa/riscv-rqsc/releases/tag/v1.0.0
[2] https://github.com/riscv-non-isa/riscv-cbqri/releases/tag/v1.0
[3] https://lore.kernel.org/qemu-devel/[email protected]/
[4] https://lore.kernel.org/qemu-devel/[email protected]/
[5] https://lore.kernel.org/qemu-devel/[email protected]/
[6] https://lore.kernel.org/all/[email protected]/
[7] https://github.com/tt-fustini/linux/tree/b4/ssqosid-cbqri-rqsc
---
Drew Fustini (2):
hw/riscv: add cache_level and node properties to CBQRI controllers hw/riscv: add support for ACPI RQSC table
hw/riscv/Kconfig | 2 +- hw/riscv/cbqri_bandwidth.c | 26 ++++ hw/riscv/cbqri_capacity.c | 21 ++++ hw/riscv/virt-acpi-build.c | 298 ++++++++++++++++++++++++++++++++++++++++++++- include/hw/riscv/cbqri.h | 20 +++ 5 files changed, 365 insertions(+), 2 deletions(-)
---
base-commit: bf67d56f282c1ee25b67dfda3f8ca54d2bd4648e
change-id: 20260201-riscv-rqsc-ae806ee0a7aa
prerequisite-change-id: 20251229-riscv-ssqosid-cbqri-aee2271532ff:v8
prerequisite-patch-id: 7d1487071207ac8c9750af152baec0cfa80b704f
prerequisite-patch-id: 7d852a70275071c5b5cfce579bbb442cf5b4d456
prerequisite-patch-id: 6361057143117707a309b225a6e0d6a708e6f5ff
prerequisite-patch-id: b207082f77e5882c20a061cf415055b6832eef7c
prerequisite-patch-id: 2d20f4be6cb77039cca28cb0b774524f88f964b1
prerequisite-patch-id: f3474864af8c82a4d96ac2b99de7abb80458e366
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 2ff76b9d66b52771c4f963d891f39a6a93fbe5b4
prerequisite-patch-id: 95682b479c131bd09f4bd68426554918e1d43075
prerequisite-patch-id: cca54a74db19c96cb4cf048393dc278d96edd905
prerequisite-patch-id: ee77339d6590704a4240b641ebfc2574f7f29ed5
prerequisite-patch-id: 2b50d0ab2b41d993906cdf0abbd2013192d6e411
Best regards,
Signature · 1 line
Drew Fustini <[email protected]>
PATCH v2 1/2 hw/riscv: add cache_level and node properties to CBQRI controllers
The ACPI RQSC table specifies which cache a capacity controller backs and which proximity domain a bandwidth controller serves.
Add a cache_level property to the capacity controller. It accepts 2 or 3, the unified cache levels that the smp-cache option can place and the PPTT can describe, and defaults to 2. Add a node property to the bandwidth controller. It defaults to 0 and rejects a node the machine does not have.
--- hw/riscv/cbqri_bandwidth.c | 13 +++++++++++++ hw/riscv/cbqri_capacity.c | 8 ++++++++ 2 files changed, 21 insertions(+)
hw/riscv/cbqri_bandwidth.c +13 -0
@@ -17,7 +17,9 @@#include "hw/core/sysbus.h" #include "migration/vmstate.h" #include "target/riscv/cpu.h" +#include "hw/core/boards.h" #include "hw/riscv/cbqri.h" +#include "system/numa.h" /* Property defaults, shared with riscv_cbqri_bc_caps_init() */ #define BC_DEFAULT_MAX_MCIDS 256
@@ -139,6 +141,7 @@ typedef struct RiscvCbqriBandwidthState {uint16_t nbwblks;uint16_t mrbwb; +uint32_t node;bool supports_at_code;
@@ -542,12 +545,21 @@ static const MemoryRegionOps riscv_cbqri_bc_ops = {static void riscv_cbqri_bc_realize (DeviceState *dev,Error **errp) {RiscvCbqriBandwidthState *bc =RISCV_CBQRI_BC (dev); +MachineState *ms =MACHINE (qdev_get_machine ()); +unsigned int nb_nodes = ms->numa_state ? ms->numa_state->num_nodes :0 ;if (!bc->mmio_base) {error_setg (errp,"mmio_base property not set" );return ; } +/* Without -numa there is a single implicit node 0. */ +if (bc->node >=MAX (nb_nodes,1 )) { +error_setg (errp,"node %u out of range, %u NUMA node(s)" , + bc->node,MAX (nb_nodes,1 )); +return ; + } +if (bc->nb_rcids ==0 ) {error_setg (errp,"max_rcids must be at least 1" );return ;
@@ -638,6 +650,7 @@ static const Property riscv_cbqri_bc_properties[] = { BC_DEFAULT_NBWBLKS),DEFINE_PROP_UINT16 ("mrbwb" , RiscvCbqriBandwidthState, mrbwb,BC_DEFAULT_MRBWB ), +DEFINE_PROP_UINT32 ("node" , RiscvCbqriBandwidthState, node,0 ),DEFINE_PROP_BOOL ("at_code" , RiscvCbqriBandwidthState, supports_at_code, true),
hw/riscv/cbqri_capacity.c +8 -0
@@ -127,6 +127,7 @@ typedef struct RiscvCbqriCapacityState {uint16_t nb_rcids;uint16_t ncblks; +uint8_t cache_level;bool supports_at_code;
@@ -591,6 +592,11 @@ static void riscv_cbqri_cc_realize(DeviceState *dev, Error **errp)return ; } +if (cc->cache_level !=2 && cc->cache_level !=3 ) { +error_setg (errp,"cache_level must be 2 or 3" ); +return ; + } +if (cc->nb_rcids ==0 ) {error_setg (errp,"max_rcids must be at least 1" );return ;
@@ -666,6 +672,8 @@ static const Property riscv_cbqri_cc_properties[] = { CC_DEFAULT_MAX_RCIDS),DEFINE_PROP_UINT16 ("ncblks" , RiscvCbqriCapacityState, ncblks,CC_DEFAULT_NCBLKS ), +DEFINE_PROP_UINT8 ("cache_level" , RiscvCbqriCapacityState, + cache_level,2 ),DEFINE_PROP_BOOL ("at_code" , RiscvCbqriCapacityState, supports_at_code, true),
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] hw/riscv: add cache_level and node properties to CBQRI controllers
Quoted 80 lines · Drew Fustini
The ACPI RQSC table specifies which cache a capacity controller backs and which proximity domain a bandwidth controller serves.
Add a
cache_levelproperty to the capacity controller. It accepts 2 or 3, the unified cache levels that the smp-cache option can place and the PPTT can describe, and defaults to 2. Add a node property to the bandwidth controller. It defaults to 0 and rejects a node the machine does not have.Signed-off-by Drew Fustini <[email protected]>--- hw/riscv/cbqri_bandwidth.c | 13 +++++++++++++ hw/riscv/cbqri_capacity.c | 8 ++++++++ 2 files changed, 21 insertions(+)hw/riscv/cbqri_bandwidth.c +13
-0@@ -17,7 +17,9 @@#include "hw/core/sysbus.h" #include "migration/vmstate.h" #include "target/riscv/cpu.h" +#include "hw/core/boards.h" #include "hw/riscv/cbqri.h" +#include "system/numa.h" /* Property defaults, shared with riscv_cbqri_bc_caps_init() */ #define BC_DEFAULT_MAX_MCIDS 256@@ -139,6 +141,7 @@ typedef struct RiscvCbqriBandwidthState {uint16_t nbwblks;uint16_t mrbwb; +uint32_t node;bool supports_at_code;@@ -542,12 +545,21 @@ static const MemoryRegionOps riscv_cbqri_bc_ops = {static void riscv_cbqri_bc_realize (DeviceState *dev,Error **errp) {RiscvCbqriBandwidthState *bc =RISCV_CBQRI_BC (dev); +MachineState *ms =MACHINE (qdev_get_machine ()); +unsigned int nb_nodes = ms->numa_state ? ms->numa_state->num_nodes :0 ;if (!bc->mmio_base) {error_setg (errp,"mmio_base property not set" );return ; } +/* Without -numa there is a single implicit node 0. */ +if (bc->node >=MAX (nb_nodes,1 )) { +error_setg (errp,"node %u out of range, %u NUMA node(s)" , + bc->node,MAX (nb_nodes,1 )); +return ; + } +if (bc->nb_rcids ==0 ) {error_setg (errp,"max_rcids must be at least 1" );return ;@@ -638,6 +650,7 @@ static const Property riscv_cbqri_bc_properties[] = { BC_DEFAULT_NBWBLKS),DEFINE_PROP_UINT16 ("mrbwb" , RiscvCbqriBandwidthState, mrbwb,BC_DEFAULT_MRBWB ), +DEFINE_PROP_UINT32 ("node" , RiscvCbqriBandwidthState, node,0 ),DEFINE_PROP_BOOL ("at_code" , RiscvCbqriBandwidthState, supports_at_code, true),hw/riscv/cbqri_capacity.c +1
-0@@ -127,6 +127,7 @@ typedef struct RiscvCbqriCapacityState {uint16_t nb_rcids;uint16_t ncblks; +uint8_t cache_level;bool supports_at_code;
hw/riscv/cbqri_capacity.c static void riscv_cbqri_cc_realize(DeviceState *dev, Error **errp) · line 599
Quoted 8 lines
hw/riscv/cbqri_capacity.c +5
-0@@ -591,6 +592,11 @@ static void riscv_cbqri_cc_realize(DeviceState *dev, Error **errp)return ; } +if (cc->cache_level !=2 && cc->cache_level !=3 ) { +error_setg (errp,"cache_level must be 2 or 3" ); +return ; + } +
For this kind of property that has a very specific and restrictive value range (i.e. we'll abort if we don't get what we want), I suggest not using DEFINE_PROP_UINT8() to declare the prop in the array.
What we do in target/riscv/cpu.c in for 'num-pmp-regions':
static void prop_num_pmp_regions_set(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
RISCVCPU *cpu = RISCV_CPU(obj);
uint8_t value;
visit_type_uint8(v, name, &value, errp);
(... a bunch of checks ....)
}static void prop_num_pmp_regions_get(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
uint8_t value = RISCV_CPU(obj)->cfg.pmp_regions;
visit_type_uint8(v, name, &value, errp);
}static const PropertyInfo prop_num_pmp_regions = {
.type = "uint8",
.qapi_type = &uint8_type_info, .description = "num-pmp-regions",
.get = prop_num_pmp_regions_get,
.set = prop_num_pmp_regions_set,
};
And this is added in a property array like this:
{.name = "num-pmp-regions", .info = &prop_num_pmp_regions},
This is more verbose but it will make realize() easier since the property is guaranteed to be valid. 'cache_level' seems like a good candidate for this kind of pattern.
Thanks,
Daniel
Quoted 13 lines
hw/riscv/cbqri_capacity.c +2
-0if (cc->nb_rcids ==0 ) {error_setg (errp,"max_rcids must be at least 1" );return ;@@ -666,6 +672,8 @@ static const Property riscv_cbqri_cc_properties[] = { CC_DEFAULT_MAX_RCIDS),DEFINE_PROP_UINT16 ("ncblks" , RiscvCbqriCapacityState, ncblks,CC_DEFAULT_NCBLKS ), +DEFINE_PROP_UINT8 ("cache_level" , RiscvCbqriCapacityState, + cache_level,2 ),DEFINE_PROP_BOOL ("at_code" , RiscvCbqriCapacityState, supports_at_code, true),
Re: [PATCH v2 1/2] hw/riscv: add cache_level and node properties to CBQRI controllers
Quoted 116 lines · Daniel Henrique Barboza
Quoted 70 lines · Drew Fustini
The ACPI RQSC table specifies which cache a capacity controller backs and which proximity domain a bandwidth controller serves.
Add a
cache_levelproperty to the capacity controller. It accepts 2 or 3, the unified cache levels that the smp-cache option can place and the PPTT can describe, and defaults to 2. Add a node property to the bandwidth controller. It defaults to 0 and rejects a node the machine does not have.Signed-off-by Drew Fustini <[email protected]>--- hw/riscv/cbqri_bandwidth.c | 13 +++++++++++++ hw/riscv/cbqri_capacity.c | 8 ++++++++ 2 files changed, 21 insertions(+)hw/riscv/cbqri_bandwidth.c +13
-0@@ -17,7 +17,9 @@#include "hw/core/sysbus.h" #include "migration/vmstate.h" #include "target/riscv/cpu.h" +#include "hw/core/boards.h" #include "hw/riscv/cbqri.h" +#include "system/numa.h" /* Property defaults, shared with riscv_cbqri_bc_caps_init() */ #define BC_DEFAULT_MAX_MCIDS 256@@ -139,6 +141,7 @@ typedef struct RiscvCbqriBandwidthState {uint16_t nbwblks;uint16_t mrbwb; +uint32_t node;bool supports_at_code;@@ -542,12 +545,21 @@ static const MemoryRegionOps riscv_cbqri_bc_ops = {static void riscv_cbqri_bc_realize (DeviceState *dev,Error **errp) {RiscvCbqriBandwidthState *bc =RISCV_CBQRI_BC (dev); +MachineState *ms =MACHINE (qdev_get_machine ()); +unsigned int nb_nodes = ms->numa_state ? ms->numa_state->num_nodes :0 ;if (!bc->mmio_base) {error_setg (errp,"mmio_base property not set" );return ; } +/* Without -numa there is a single implicit node 0. */ +if (bc->node >=MAX (nb_nodes,1 )) { +error_setg (errp,"node %u out of range, %u NUMA node(s)" , + bc->node,MAX (nb_nodes,1 )); +return ; + } +if (bc->nb_rcids ==0 ) {error_setg (errp,"max_rcids must be at least 1" );return ;@@ -638,6 +650,7 @@ static const Property riscv_cbqri_bc_properties[] = { BC_DEFAULT_NBWBLKS),DEFINE_PROP_UINT16 ("mrbwb" , RiscvCbqriBandwidthState, mrbwb,BC_DEFAULT_MRBWB ), +DEFINE_PROP_UINT32 ("node" , RiscvCbqriBandwidthState, node,0 ),DEFINE_PROP_BOOL ("at_code" , RiscvCbqriBandwidthState, supports_at_code, true),hw/riscv/cbqri_capacity.c +1
-0@@ -127,6 +127,7 @@ typedef struct RiscvCbqriCapacityState {uint16_t nb_rcids;uint16_t ncblks; +uint8_t cache_level;bool supports_at_code;hw/riscv/cbqri_capacity.c static void riscv_cbqri_cc_realize(DeviceState *dev, Error **errp) · line 598
Quoted 7 lines
hw/riscv/cbqri_capacity.c +5
-0@@ -591,6 +592,11 @@ static void riscv_cbqri_cc_realize(DeviceState *dev, Error **errp)return ; } +if (cc->cache_level !=2 && cc->cache_level !=3 ) { +error_setg (errp,"cache_level must be 2 or 3" ); +return ; + } +For this kind of property that has a very specific and restrictive value range (i.e. we'll abort if we don't get what we want), I suggest not using
DEFINE_PROP_UINT8()to declare the prop in the array.What we do in
target/riscv/cpu.cin for 'num-pmp-regions':static void prop_num_pmp_regions_set(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp){ RISCVCPU *cpu = RISCV_CPU(obj); uint8_t value; visit_type_uint8(v, name, &value, errp); (... a bunch of checks ....) }static void prop_num_pmp_regions_get(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp){ uint8_t value = RISCV_CPU(obj)->cfg.pmp_regions; visit_type_uint8(v, name, &value, errp); }static const PropertyInfo
prop_num_pmp_regions= {
.type = "uint8",
.qapi_type =&uint8_type_info, .description = "num-pmp-regions",
.get =prop_num_pmp_regions_get,
.set =prop_num_pmp_regions_set,
};
Quoted 8 lines
And this is added in a property array like this:
{.name = "num-pmp-regions", .info =
&prop_num_pmp_regions},This is more verbose but it will make
realize()easier since the property is guaranteed to be valid. 'cache_level' seems like a good candidate for this kind of pattern.
That makes sense. I'll change cache_level to a custom PropertyInfo and remove the check from realize.
Drew
PATCH v2 2/2 hw/riscv: add support for ACPI RQSC table
In reply to Drew FustiniBuild the ACPI RISC-V Quality of Service Controllers (RQSC) table for the virt machine when CBQRI controllers are present. A capacity controller is described by the PPTT Cache ID of the cache it backs and a bandwidth controller by the SRAT proximity domain of its NUMA node.
Make RISCV_VIRT select RISCV_CBQRI as the table code calls into the CBQRI devices.
--- hw/riscv/Kconfig | 2 +- hw/riscv/cbqri_bandwidth.c | 13 ++ hw/riscv/cbqri_capacity.c | 13 ++ hw/riscv/virt-acpi-build.c | 298 ++++++++++++++++++++++++++++++++++++++++++++- include/hw/riscv/cbqri.h | 20 +++ 5 files changed, 344 insertions(+), 2 deletions(-)
hw/riscv/Kconfig +1 -1
@@ -71,7 +71,7 @@ config RISCV_VIRT select PLATFORM_BUS select ACPI select ACPI_PCI - imply RISCV_CBQRI + select RISCV_CBQRI config RISCV_SERVER_PLATFORM_REF bool
hw/riscv/cbqri_bandwidth.c +13 -0
@@ -760,4 +760,17 @@ DeviceState *riscv_cbqri_bc_create(hwaddr addr,return dev; } +void riscv_cbqri_bc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc) +{ +if (strcmp (type,TYPE_RISCV_CBQRI_BC ) ==0 ) { +RiscvCbqriBandwidthState *bcs =RISCV_CBQRI_BC (ds); + rqsc->type =RQSC_CONTROLLER_TYPE_BANDWIDTH ; + rqsc->mmio_base = bcs->mmio_base; + rqsc->rcid_count = bcs->nb_rcids; + rqsc->mcid_count = bcs->nb_mcids; + rqsc->node = bcs->node; + } +} +type_init (riscv_cbqri_bc_register_types)
hw/riscv/cbqri_capacity.c +13 -0
@@ -776,4 +776,17 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr,return dev; } +void riscv_cbqri_cc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc) +{ +if (strcmp (type,TYPE_RISCV_CBQRI_CC ) ==0 ) { +RiscvCbqriCapacityState *ccs =RISCV_CBQRI_CC (ds); + rqsc->type =RQSC_CONTROLLER_TYPE_CAPACITY ; + rqsc->mmio_base = ccs->mmio_base; + rqsc->rcid_count = ccs->nb_rcids; + rqsc->mcid_count = ccs->nb_mcids; + rqsc->cache_level = ccs->cache_level; + } +} +type_init (riscv_cbqri_cc_register_types)
hw/riscv/virt-acpi-build.c +297 -1
325 lines not on this page · raw message
include/hw/riscv/cbqri.h +20 -0
@@ -78,4 +78,24 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr, const RiscvCbqriCapacityCaps *caps);DeviceState *riscv_cbqri_bc_create (hwaddr addr,const RiscvCbqriBandwidthCaps *caps); + +/* RQSC QoS Controller Type */ +#define RQSC_CONTROLLER_TYPE_CAPACITY 0 +#define RQSC_CONTROLLER_TYPE_BANDWIDTH 1 + +/* What the ACPI RQSC table reports about one CBQRI controller */ +typedef struct RqscController { +uint8_t type;/* RQSC_CONTROLLER_TYPE_* */ +uint64_t mmio_base; +uint16_t rcid_count; +uint16_t mcid_count; +uint8_t cache_level;/* capacity controllers */ +uint32_t node;/* bandwidth controllers */ +}RqscController ; + +void riscv_cbqri_bc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc); +void riscv_cbqri_cc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc); +#endif
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] hw/riscv: add support for ACPI RQSC table
Quoted 38 lines · Drew Fustini
Build the ACPI RISC-V Quality of Service Controllers (RQSC) table for the virt machine when CBQRI controllers are present. A capacity controller is described by the PPTT Cache ID of the cache it backs and a bandwidth controller by the SRAT proximity domain of its NUMA node.
Make
RISCV_VIRTselectRISCV_CBQRIas the table code calls into the CBQRI devices.Co-developed-by Vasudevan Srinivasan <[email protected]>Signed-off-by Vasudevan Srinivasan <[email protected]>Signed-off-by Drew Fustini <[email protected]>--- hw/riscv/Kconfig | 2 +- hw/riscv/cbqri_bandwidth.c | 13 ++ hw/riscv/cbqri_capacity.c | 13 ++ hw/riscv/virt-acpi-build.c | 298 ++++++++++++++++++++++++++++++++++++++++++++- include/hw/riscv/cbqri.h | 20 +++ 5 files changed, 344 insertions(+), 2 deletions(-)hw/riscv/Kconfig +1
-1@@ -71,7 +71,7 @@ config RISCV_VIRT select PLATFORM_BUS select ACPI select ACPI_PCI - imply RISCV_CBQRI + select RISCV_CBQRI config RISCV_SERVER_PLATFORM_REF boolhw/riscv/cbqri_bandwidth.c +0
-0
hw/riscv/cbqri_bandwidth.c DeviceState *riscv_cbqri_bc_create(hwaddr addr, · line 766
Quoted 7 lines
hw/riscv/cbqri_bandwidth.c +4
-0@@ -760,4 +760,17 @@ DeviceState *riscv_cbqri_bc_create(hwaddr addr,return dev; } +void riscv_cbqri_bc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc) +{ +if (strcmp (type,TYPE_RISCV_CBQRI_BC ) ==0 ) {
The only existing caller for riscv_cbqri_bc_get_details() is already doing this check:
Quoted 1 line
hw/riscv/cbqri_bandwidth.c +1
-0+bool is_bc = !strcmp (type,TYPE_RISCV_CBQRI_BC );
(...)
hw/riscv/cbqri_bandwidth.c
Quoted 3 lines
hw/riscv/cbqri_bandwidth.c +3
-0+if (is_bc) { +riscv_cbqri_bc_get_details (kid->child, type, &rqsc[count]); + }
Unless there are plans to add new callers that will unsafely call the function without guaranteeing that the device type is correct, I suggest removing the redundant strcmp().
Same thing with riscv_cbqri_cc_get_details() below.
Otherwise LGTM. Thanks,
Daniel
Quoted 395 lines
hw/riscv/cbqri_bandwidth.c +9
-0+RiscvCbqriBandwidthState *bcs =RISCV_CBQRI_BC (ds); + rqsc->type =RQSC_CONTROLLER_TYPE_BANDWIDTH ; + rqsc->mmio_base = bcs->mmio_base; + rqsc->rcid_count = bcs->nb_rcids; + rqsc->mcid_count = bcs->nb_mcids; + rqsc->node = bcs->node; + } +} +type_init (riscv_cbqri_bc_register_types)hw/riscv/cbqri_capacity.c +13
-0@@ -776,4 +776,17 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr,return dev; } +void riscv_cbqri_cc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc) +{ +if (strcmp (type,TYPE_RISCV_CBQRI_CC ) ==0 ) { +RiscvCbqriCapacityState *ccs =RISCV_CBQRI_CC (ds); + rqsc->type =RQSC_CONTROLLER_TYPE_CAPACITY ; + rqsc->mmio_base = ccs->mmio_base; + rqsc->rcid_count = ccs->nb_rcids; + rqsc->mcid_count = ccs->nb_mcids; + rqsc->cache_level = ccs->cache_level; + } +} +type_init (riscv_cbqri_cc_register_types)hw/riscv/virt-acpi-build.c +297
-1@@ -34,6 +34,7 @@#include "hw/pci-host/gpex.h" #include "hw/riscv/virt.h" #include "hw/riscv/numa.h" +#include "hw/riscv/cbqri.h" #include "hw/virtio/virtio-acpi.h" #include "kvm/kvm_riscv.h" #include "migration/vmstate.h" @@ -279,6 +280,295 @@ spcr_setup(GArray *table_data, BIOSLinker *linker, RISCVVirtState *s)/* RHCT Node[N] starts at offset 56 */ #define RHCT_NODE_ARRAY_OFFSET 56 +/* +* RISC-V Quality of Service Controllers (RQSC) table, v1.0 +* https://github.com/riscv-non-isa/riscv-rqsc/releases/tag/v1.0.0 +*/ + +/* RQSC Resource Type and Resource ID Type */ +#define RQSC_RESOURCE_TYPE_CACHE 0 +#define RQSC_RESOURCE_TYPE_MEMORY 1 +#define RQSC_RESOURCE_ID_TYPE_PROCESSOR_CACHE 0 +#define RQSC_RESOURCE_ID_TYPE_MEMORY_RANGE 1 + +#define RQSC_MAX_CONTROLLERS 10 + +/* PPTT nodes start after the 36-byte table header */ +#define PPTT_NODE_ARRAY_OFFSET 36 +/* PPTT revision 3 Cache Type Structure */ +#define PPTT_NODE_TYPE_CACHE 1 +#define PPTT_CACHE_NODE_LEN 28 +#define PPTT_CACHE_ID_OFFSET 24 + +static bool virt_has_cbqri (RISCVVirtState *vs) +{ +BusChild *kid; + +if (!vs->platform_bus_dev) { +return false; + } + + QTAILQ_FOREACH(kid, &vs->platform_bus_dev->parent_bus->children, sibling) { +const char *type =object_get_typename (OBJECT (kid->child)); + +if (!strcmp (type,TYPE_RISCV_CBQRI_BC ) || + !strcmp (type,TYPE_RISCV_CBQRI_CC )) { +return true; + } + } + +return false; +} + +static int rqsc_cmp_mmio_base (const void *a,const void *b) +{ +const RqscController *x = a, *y = b; + +return x->mmio_base < y->mmio_base ?-1 : x->mmio_base > y->mmio_base; +} + +static unsigned int gather_cbqri_details (RISCVVirtState *vs, +RqscController rqsc[]) +{ +BusChild *kid; +unsigned int count =0 ; + +if (!vs->platform_bus_dev) { +return 0 ; + } + + QTAILQ_FOREACH(kid, &vs->platform_bus_dev->parent_bus->children, sibling) { +const char *type =object_get_typename (OBJECT (kid->child)); +bool is_bc = !strcmp (type,TYPE_RISCV_CBQRI_BC ); +bool is_cc = !strcmp (type,TYPE_RISCV_CBQRI_CC ); + +if (!is_bc && !is_cc) { +continue ; + } + +if (count ==RQSC_MAX_CONTROLLERS ) { +error_setg (&error_fatal,"RQSC: more than %d CBQRI controllers" , +RQSC_MAX_CONTROLLERS ); + } + +if (is_bc) { +riscv_cbqri_bc_get_details (kid->child, type, &rqsc[count]); + }else { +riscv_cbqri_cc_get_details (kid->child, type, &rqsc[count]); + } + count++; + } + +/* +* The bus lists its children newest first. Order the controllers by +* address so that the n-th capacity controller of a cache level is +* the one backing the n-th cache of that level. +*/ +qsort (rqsc, count,sizeof (*rqsc), rqsc_cmp_mmio_base); + +return count; +} + +/* +* Return the PPTT Cache ID of one unified cache of the given level. The +* topology containers that hold a cache of that level are counted from 0 +* in possible_cpus order, and idx selects the container. build_pptt() +* derives the ID with PPTT_CACHE_ID() from the cache type and level plus +* the first CPU of the container, so walk possible_cpus the way it does. +* Return -1 when there is no such cache and store in num_caches how many +* caches of that level the topology has, 0 when no smp-cache option places +* that level. +*/ +static int64_t rqsc_pptt_cache_id (MachineState *ms,unsigned int level, +unsigned int idx,unsigned int *num_caches) +{ +const CPUArchIdList *cpus = ms->possible_cpus; +int64_t socket_id =-1 , cluster_id =-1 , core_id =-1 ; +unsigned int n, found =0 ; +CpuTopologyLevel topo; + + *num_caches =0 ; + +switch (level) { +case 2 : + topo =machine_get_cache_topo_level (ms,CACHE_LEVEL_AND_TYPE_L2 ); +break ; +case 3 : + topo =machine_get_cache_topo_level (ms,CACHE_LEVEL_AND_TYPE_L3 ); +break ; +default : +return -1 ; + } + +for (n =0 ; n < cpus->len; n++) { +const CpuInstanceProperties *p = &cpus->cpus[n].props; +bool first; + +switch (topo) { +case CPU_TOPOLOGY_LEVEL_SOCKET : + first = p->socket_id != socket_id; +break ; +case CPU_TOPOLOGY_LEVEL_CLUSTER : + first = p->socket_id != socket_id || p->cluster_id != cluster_id; +break ; +case CPU_TOPOLOGY_LEVEL_CORE : + first = p->socket_id != socket_id || + p->cluster_id != cluster_id || p->core_id != core_id; +break ; +default : +return -1 ; + } + +if (!first) { +continue ; + } + + socket_id = p->socket_id; + cluster_id = p->cluster_id; + core_id = p->core_id; + +if (found++ == idx) { +return PPTT_CACHE_ID (UNIFIED_CACHE , level, n); + } + } + + *num_caches = found; +return -1 ; +} + +/* +* Whether the PPTT at pptt_start holds a Cache Type Structure with the +* given Cache ID. build_pptt() does not emit every cache level for every +* smp-cache layout, for example an L3 cache placed at core level. +*/ +static bool rqsc_pptt_has_cache_id (GArray *table_data,unsigned int pptt_start, +uint32_t id) +{ +const uint8_t *pptt = (const uint8_t *)table_data->data + pptt_start; +uint32_t len =ldl_le_p (pptt +4 ); +uint32_t off =PPTT_NODE_ARRAY_OFFSET ; + +while (off +PPTT_CACHE_NODE_LEN <= len) { +uint8_t node_len = pptt[off +1 ]; + +if (pptt[off] ==PPTT_NODE_TYPE_CACHE && + node_len >=PPTT_CACHE_NODE_LEN && +ldl_le_p (pptt + off +PPTT_CACHE_ID_OFFSET ) == id) { +return true; + } +if (!node_len) { +break ; + } + off += node_len; + } + +return false; +} + +static void build_rqsc (GArray *table_data,BIOSLinker *linker, +RISCVVirtState *s,unsigned int pptt_start) +{ +MachineState *ms =MACHINE (s); +RqscController rqsc[RQSC_MAX_CONTROLLERS ]; +unsigned int num, i, nr_cc[4 ] = {}; +AcpiTable table = { .sig ="RQSC" , .rev =1 , .oem_id = s->oem_id, + .oem_table_id = s->oem_table_id }; + +acpi_table_begin (&table, table_data); + + num =gather_cbqri_details (s, rqsc); + +/* Number of QoS Controllers */ +build_append_int_noprefix (table_data, num,4 ); + +for (i =0 ; i < num; i++) { +bool is_cc = rqsc[i].type ==RQSC_CONTROLLER_TYPE_CAPACITY ; +/* A Memory resource carries 8 bytes of Bandwidth per Block */ +unsigned int res_len = is_cc ?20 :28 ; +uint8_t res_type, id_type; +int64_t id; + +if (is_cc) { +unsigned int level = rqsc[i].cache_level; +unsigned int num_caches; + + res_type =RQSC_RESOURCE_TYPE_CACHE ; + id_type =RQSC_RESOURCE_ID_TYPE_PROCESSOR_CACHE ; + id =rqsc_pptt_cache_id (ms, level, nr_cc[level]++, &num_caches); +if (id <0 && !num_caches) { +error_setg (&error_fatal, +"CBQRI capacity controller at 0x%" PRIx64 +" backs an L%u cache, but no smp-cache option" +" places the L%u cache" , + rqsc[i].mmio_base, level, level); + }else if (id <0 ) { +error_setg (&error_fatal, +"CBQRI capacity controller at 0x%" PRIx64 +" is L%u controller %u, but the smp-cache" +" topology has only %u L%u cache%s" , + rqsc[i].mmio_base, level, nr_cc[level] -1 , + num_caches, level, num_caches ==1 ?"" :"s" ); + }else if (!rqsc_pptt_has_cache_id (table_data, pptt_start, id)) { +error_setg (&error_fatal, +"CBQRI capacity controller at 0x%" PRIx64 +" backs an L%u cache, but the PPTT has no L%u" +" cache with ID 0x%" PRIx64, + rqsc[i].mmio_base, level, level, (uint64_t )id); + } + }else { + res_type =RQSC_RESOURCE_TYPE_MEMORY ; + id_type =RQSC_RESOURCE_ID_TYPE_MEMORY_RANGE ; + id = rqsc[i].node; + } + +/* Controller Type */ +build_append_int_noprefix (table_data, rqsc[i].type,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Length */ +build_append_int_noprefix (table_data,24 + res_len,2 ); +/* Register Interface Address */ +build_append_gas (table_data, +AML_AS_SYSTEM_MEMORY , +0 , +0 , +4 , + rqsc[i].mmio_base); +/* RCID Count */ +build_append_int_noprefix (table_data, rqsc[i].rcid_count,2 ); +/* MCID Count */ +build_append_int_noprefix (table_data, rqsc[i].mcid_count,2 ); +/* Controller Flags */ +build_append_int_noprefix (table_data,0 ,2 ); +/* Number of Resources, one per controller */ +build_append_int_noprefix (table_data,1 ,2 ); + +/* Resource Structure */ +/* Resource Type */ +build_append_int_noprefix (table_data, res_type,1 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Length of Resource Structure */ +build_append_int_noprefix (table_data, res_len,2 ); +/* Resource Flags */ +build_append_int_noprefix (table_data,0 ,2 ); +/* Reserved */ +build_append_int_noprefix (table_data,0 ,1 ); +/* Resource ID Type */ +build_append_int_noprefix (table_data, id_type,1 ); +/* Resource ID 1: PPTT Cache ID or SRAT Proximity Domain */ +build_append_int_noprefix (table_data, id,8 ); +/* Resource ID 2 */ +build_append_int_noprefix (table_data,0 ,4 ); +if (!is_cc) { +/* Bandwidth per Block, 0 means not provided */ +build_append_int_noprefix (table_data,0 ,8 ); + } + } + +acpi_table_end (linker, &table); +} +/* * ACPI spec, Revision 6.6 * 5.2.37 RISC-V Hart Capabilities Table (RHCT) @@ -879,7 +1169,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, RISCVVirtState *vms)static void virt_acpi_build (RISCVVirtState *s,AcpiBuildTables *tables) {GArray *table_offsets; -unsigned dsdt, xsdt; +unsigned dsdt, xsdt, pptt_start;GArray *tables_blob = tables->table_data;MachineState *ms =MACHINE (s);CPUCoreCaches caches[CPU_MAX_CACHES ];@@ -913,9 +1203,15 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) }acpi_add_table (table_offsets, tables_blob); + pptt_start = tables_blob->len;build_pptt (tables_blob, tables->linker, ms, s->oem_id, s->oem_table_id, num_caches, caches); +if (virt_has_cbqri (s)) { +acpi_add_table (table_offsets, tables_blob); +build_rqsc (tables_blob, tables->linker, s, pptt_start); + } +acpi_add_table (table_offsets, tables_blob);if (ms->acpi_spcr_enabled) {include/hw/riscv/cbqri.h +20
-0@@ -78,4 +78,24 @@ DeviceState *riscv_cbqri_cc_create(hwaddr addr, const RiscvCbqriCapacityCaps *caps);DeviceState *riscv_cbqri_bc_create (hwaddr addr,const RiscvCbqriBandwidthCaps *caps); + +/* RQSC QoS Controller Type */ +#define RQSC_CONTROLLER_TYPE_CAPACITY 0 +#define RQSC_CONTROLLER_TYPE_BANDWIDTH 1 + +/* What the ACPI RQSC table reports about one CBQRI controller */ +typedef struct RqscController { +uint8_t type;/* RQSC_CONTROLLER_TYPE_* */ +uint64_t mmio_base; +uint16_t rcid_count; +uint16_t mcid_count; +uint8_t cache_level;/* capacity controllers */ +uint32_t node;/* bandwidth controllers */ +}RqscController ; + +void riscv_cbqri_bc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc); +void riscv_cbqri_cc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc); +#endif
Re: [PATCH v2 2/2] hw/riscv: add support for ACPI RQSC table
Quoted 58 lines · Daniel Henrique Barboza
Quoted 37 lines · Drew Fustini
Build the ACPI RISC-V Quality of Service Controllers (RQSC) table for the virt machine when CBQRI controllers are present. A capacity controller is described by the PPTT Cache ID of the cache it backs and a bandwidth controller by the SRAT proximity domain of its NUMA node.
Make
RISCV_VIRTselectRISCV_CBQRIas the table code calls into the CBQRI devices.Co-developed-by Vasudevan Srinivasan <[email protected]>Signed-off-by Vasudevan Srinivasan <[email protected]>Signed-off-by Drew Fustini <[email protected]>--- hw/riscv/Kconfig | 2 +- hw/riscv/cbqri_bandwidth.c | 13 ++ hw/riscv/cbqri_capacity.c | 13 ++ hw/riscv/virt-acpi-build.c | 298 ++++++++++++++++++++++++++++++++++++++++++++- include/hw/riscv/cbqri.h | 20 +++ 5 files changed, 344 insertions(+), 2 deletions(-)hw/riscv/Kconfig +1
-1@@ -71,7 +71,7 @@ config RISCV_VIRT select PLATFORM_BUS select ACPI select ACPI_PCI - imply RISCV_CBQRI + select RISCV_CBQRI config RISCV_SERVER_PLATFORM_REF boolhw/riscv/cbqri_bandwidth.c +0
-0hw/riscv/cbqri_bandwidth.c DeviceState *riscv_cbqri_bc_create(hwaddr addr, · line 765
Quoted 6 lines
hw/riscv/cbqri_bandwidth.c +4
-0@@ -760,4 +760,17 @@ DeviceState *riscv_cbqri_bc_create(hwaddr addr,return dev; } +void riscv_cbqri_bc_get_details (DeviceState *ds,const char *type, +RqscController *rqsc) +{ +if (strcmp (type,TYPE_RISCV_CBQRI_BC ) ==0 ) {The only existing caller for
riscv_cbqri_bc_get_details()is already doing this check:Quoted 1 line
hw/riscv/cbqri_bandwidth.c +1
-0+bool is_bc = !strcmp (type,TYPE_RISCV_CBQRI_BC );(...)
hw/riscv/cbqri_bandwidth.c
Quoted 3 lines
hw/riscv/cbqri_bandwidth.c +3
-0+if (is_bc) { +riscv_cbqri_bc_get_details (kid->child, type, &rqsc[count]); + }
Quoted 5 lines
Unless there are plans to add new callers that will unsafely call the function without guaranteeing that the device type is correct, I suggest removing the redundant
strcmp().Same thing with
riscv_cbqri_cc_get_details()below.
Good point, I'll remove the redundant checks.
Quoted 2 lines
Otherwise LGTM. Thanks,
Daniel
Thanks for reviewing!
Drew