perf/x86/amd: IOMMU Performance Counter Support
Subsystems (3)
v3 cover perf/x86/amd: IOMMU Performance Counter Support
From: Suravee Suthikulpanit <[email protected]>
These patches implement the AMD IOMMU Performance Counter functionality via custom perf PMU and implement static counting for various IOMMU translations.
1) Extend the AMD IOMMU initialization to include performance counter enablement.
2) The perf AMD IOMMU PMU to manage performance counters, which interface with the AMD IOMMU core driver.
Steven L Kinney (1):
perf/x86/amd: Adding IOMMU PC resource management
Suravee Suthikulpanit (1):
perf/x86/amd: AMD IOMMU PC PERF uncore PMU implementation
arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/perf_event_amd_iommu.c | 500 ++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_amd_iommu.h | 40 +++ drivers/iommu/amd_iommu_init.c | 121 ++++++- drivers/iommu/amd_iommu_proto.h | 7 + drivers/iommu/amd_iommu_types.h | 12 +- 6 files changed, 675 insertions(+), 7 deletions(-) create mode 100644 arch/x86/kernel/cpu/perf_event_amd_iommu.c create mode 100644 arch/x86/kernel/cpu/perf_event_amd_iommu.h
Signature · 1 line
1.7.10.4
PATCH v3 1/2 perf/x86/amd: Adding IOMMU PC resource management
From: Steven L Kinney <[email protected]>
Add functionality to check the availability of the AMD IOMMU Performance Counters and export this functionality to other core drivers, such as in this case, a perf AMD IOMMU PMU. This feature is not bound to any specific AMD family/model other than the presence of the IOMMU with PC enabled.
The AMD IOMMU PC support static counting only at this time.
---
V2 Changes:
- Modify the amd_iommu_pc_get_set_reg_val function to support 64 bit values.
- Fix logic to properly clear amd_iommu_pc_present when initialization failed.
drivers/iommu/amd_iommu_init.c | 121 ++++++++++++++++++++++++++++++++++++++- drivers/iommu/amd_iommu_proto.h | 7 +++ drivers/iommu/amd_iommu_types.h | 12 +++- 3 files changed, 134 insertions(+), 6 deletions(-)
drivers/iommu/amd_iommu_init.c +118 -3
@@ -154,6 +154,7 @@ bool amd_iommu_iotlb_sup __read_mostly = true;u32 amd_iommu_max_pasids__read_mostly = ~0 ;bool amd_iommu_v2_present__read_mostly ; +bool amd_iommu_pc_present__read_mostly ;bool amd_iommu_force_isolation__read_mostly ;
@@ -371,21 +372,21 @@ static void iommu_disable(struct amd_iommu *iommu)*/ static u8 __iomem *__init iommu_map_mmio_space (u64 address) { -if (!request_mem_region (address,MMIO_REGION_LENGTH ,"amd_iommu" )) { +if (!request_mem_region (address,MMIO_REG_END_OFFSET ,"amd_iommu" )) {pr_err ("AMD-Vi: Can not reserve memory region %llx for mmio\n" , address);pr_err ("AMD-Vi: This is a BIOS bug. Please contact your hardware vendor\n" );return NULL ; } -return (u8 __iomem *)ioremap_nocache (address,MMIO_REGION_LENGTH ); +return (u8 __iomem *)ioremap_nocache (address,MMIO_REG_END_OFFSET ); }static void __init iommu_unmap_mmio_space (struct amd_iommu *iommu) {if (iommu->mmio_base)iounmap (iommu->mmio_base); -release_mem_region (iommu->mmio_phys,MMIO_REGION_LENGTH ); +release_mem_region (iommu->mmio_phys,MMIO_REG_END_OFFSET ); }/****************************************************************************
@@ -1160,6 +1161,33 @@ static int __init init_iommu_all(struct acpi_table_header *table)return 0 ; } + +static void init_iommu_perf_ctr (struct amd_iommu *iommu) +{ +u64 val =0xabcd , val2 =0 ; + +if (!iommu_feature (iommu,FEATURE_PC )) +return ; + + amd_iommu_pc_present = true; + +/* Check if the performance counters can be written to */ +if ((0 !=amd_iommu_pc_get_set_reg_val (0 ,0 ,0 ,0 , &val, true)) || + (0 !=amd_iommu_pc_get_set_reg_val (0 ,0 ,0 ,0 , &val2, false)) || + (val != val2)) { +pr_err ("AMD-Vi: Unable to write to IOMMU perf counter.\n" ); + amd_iommu_pc_present = false; +return ; + } + +pr_info ("AMD-Vi: IOMMU performance counters " "supported\n" ); + + val =readl (iommu->mmio_base +MMIO_CNTR_CONF_OFFSET ); + iommu->max_banks = (u8) ((val >>12 ) &0x3f ); + iommu->max_counters = (u8) ((val >>7 ) &0xf ); +} + +static int iommu_init_pci (struct amd_iommu *iommu) {int cap_ptr = iommu->cap_ptr;
@@ -1226,6 +1254,8 @@ static int iommu_init_pci(struct amd_iommu *iommu)if (iommu->cap & (1UL <<IOMMU_CAP_NPCACHE )) amd_iommu_np_cache = true; +init_iommu_perf_ctr (iommu); +if (is_rd890_iommu (iommu->dev)) {int i, j;
@@ -2232,3 +2262,88 @@ bool amd_iommu_v2_supported(void)return amd_iommu_v2_present; }EXPORT_SYMBOL (amd_iommu_v2_supported); + +/**************************************************************************** +* +* IOMMU EFR Performance Counter support functionality. This code allows +* access to the IOMMU PC functionality. +* +****************************************************************************/ + +u8 amd_iommu_pc_get_max_banks (u16 devid) +{ +struct amd_iommu *iommu; + +/* locate the iommu governing the devid */ + iommu = amd_iommu_rlookup_table[devid]; + +if (iommu) +return iommu->max_banks; + +return -ENODEV ; +} +EXPORT_SYMBOL (amd_iommu_pc_get_max_banks); + +bool amd_iommu_pc_supported (void ) +{ +return amd_iommu_pc_present; +} +EXPORT_SYMBOL (amd_iommu_pc_supported); + +u8 amd_iommu_pc_get_max_counters (u16 devid) +{ +struct amd_iommu *iommu; + +/* locate the iommu governing the devid */ + iommu = amd_iommu_rlookup_table[devid]; + +if (iommu) +return iommu->max_counters; + +return -ENODEV ; +} +EXPORT_SYMBOL (amd_iommu_pc_get_max_counters); + +int amd_iommu_pc_get_set_reg_val (u16 devid,u8 bank,u8 cntr,u8 fxn, +u64 *value,bool is_write) +{ +struct amd_iommu *iommu; +u32 offset; +u32 max_offset_lim; + +/* Make sure the IOMMU PC resource is available */ +if (!amd_iommu_pc_present) { +pr_info ("AMD IOMMU - PC Not supported.\n" ); +return -ENODEV ; + } + +/* locate the iommu associated with the device ID */ + iommu = amd_iommu_rlookup_table[devid]; +if (iommu ==NULL ) +return -ENODEV ; + +/* check for valid iommu pc register indexing */ +if (fxn <0 || fxn >0x28 || (fxn &7 )) +return -ENODEV ; + + offset = (u32)(((0x40 |bank) <<12 ) | (cntr <<8 ) | fxn); + +/* limit the offset to the hw defined mmio region aperture */ + max_offset_lim = (u32)(((0x40 |iommu->max_banks) <<12 ) | + (iommu->max_counters <<8 ) |0x28 ); +if ((offset <MMIO_CNTR_REG_OFFSET ) || + (offset > max_offset_lim)) +return -EINVAL ; + +if (is_write) { +writel ((u32)*value, iommu->mmio_base + offset); +writel ((*value >>32 ), iommu->mmio_base + offset +4 ); + }else { + *value =readl (iommu->mmio_base + offset +4 ); + *value <<=32 ; + *value =readl (iommu->mmio_base + offset); + } + +return 0 ; +} +EXPORT_SYMBOL (amd_iommu_pc_get_set_reg_val);
drivers/iommu/amd_iommu_proto.h +7 -0
@@ -56,6 +56,13 @@ extern int amd_iommu_domain_set_gcr3(struct iommu_domain *dom, int pasid,extern int amd_iommu_domain_clear_gcr3 (struct iommu_domain *dom,int pasid);extern struct iommu_domain *amd_iommu_get_v2_domain (struct pci_dev *pdev); +/* IOMMU Performance Counter functions */ +extern bool amd_iommu_pc_supported (void ); +extern u8 amd_iommu_pc_get_max_banks (u16 devid); +extern u8 amd_iommu_pc_get_max_counters (u16 devid); +extern int amd_iommu_pc_get_set_reg_val (u16 devid,u8 bank,u8 cntr,u8 fxn, +u64 *value,bool is_write); +#define PPR_SUCCESS 0x0#define PPR_INVALID 0x1#define PPR_FAILURE 0xf
drivers/iommu/amd_iommu_types.h +9 -3
@@ -38,9 +38,6 @@#define ALIAS_TABLE_ENTRY_SIZE 2#define RLOOKUP_TABLE_ENTRY_SIZE (sizeof(void *)) -/* Length of the MMIO region for the AMD IOMMU */ -#define MMIO_REGION_LENGTH 0x4000 -/* Capability offsets used by the driver */ #define MMIO_CAP_HDR_OFFSET 0x00#define MMIO_RANGE_OFFSET 0x0c
@@ -78,6 +75,10 @@#define MMIO_STATUS_OFFSET 0x2020#define MMIO_PPR_HEAD_OFFSET 0x2030#define MMIO_PPR_TAIL_OFFSET 0x2038 +#define MMIO_CNTR_CONF_OFFSET 0x4000 +#define MMIO_CNTR_REG_OFFSET 0x40000 +#define MMIO_REG_END_OFFSET 0x80000 +/* Extended Feature Bits */
@@ -507,6 +508,7 @@ struct amd_iommu {/* physical address of MMIO space */ u64 mmio_phys; +/* virtual address of MMIO space */ u8 __iomem *mmio_base;
@@ -584,6 +586,10 @@ struct amd_iommu {/* The l2 indirect registers */ u32 stored_l2[0x83 ]; + +/* The maximum PC banks and counters/bank (PCSup=1) */ +u8 max_banks; +u8 max_counters; };struct devid_map {
Signature · 1 line
1.7.10.4
Joerg Roedel
maintainerRe: [PATCH 1/2 V3] perf/x86/amd: Adding IOMMU PC resource management
Quoted 36 lines · Suravee
From: Steven L Kinney <[email protected]>
Add functionality to check the availability of the AMD IOMMU Performance Counters and export this functionality to other core drivers, such as in this case, a perf AMD IOMMU PMU. This feature is not bound to any specific AMD family/model other than the presence of the IOMMU with PC enabled.
The AMD IOMMU PC support static counting only at this time.
Signed-off-by Steven Kinney <[email protected]>Signed-off-by Suravee Suthikulpanit <[email protected]>---
V2 Changes:
- Modify theamd_iommu_pc_get_set_reg_valfunction to support 64 bit values.
- Fix logic to properly clearamd_iommu_pc_presentwhen initialization failed.drivers/iommu/amd_iommu_init.c | 121 ++++++++++++++++++++++++++++++++++++++- drivers/iommu/amd_iommu_proto.h | 7 +++ drivers/iommu/amd_iommu_types.h | 12 +++- 3 files changed, 134 insertions(+), 6 deletions(-)drivers/iommu/amd_iommu_init.c +1
-0@@ -154,6 +154,7 @@ bool amd_iommu_iotlb_sup __read_mostly = true;u32 amd_iommu_max_pasids__read_mostly = ~0 ;bool amd_iommu_v2_present__read_mostly ; +bool amd_iommu_pc_present__read_mostly ;bool amd_iommu_force_isolation__read_mostly ;
drivers/iommu/amd_iommu_init.c static void iommu_disable(struct amd_iommu *iommu) · line 375
Quoted 5 lines
drivers/iommu/amd_iommu_init.c +1
-1@@ -371,21 +372,21 @@ static void iommu_disable(struct amd_iommu *iommu)*/ static u8 __iomem *__init iommu_map_mmio_space (u64 address) { -if (!request_mem_region (address,MMIO_REGION_LENGTH ,"amd_iommu" )) { +if (!request_mem_region (address,MMIO_REG_END_OFFSET ,"amd_iommu" )) {
This length needs to be different on IOMMUv1 systems where the MMI region is only 16kb large. Only use MMIO_REG_END_OFFSET on IOMMUv2 systems.
Quoted 9 lines
drivers/iommu/amd_iommu_init.c +9
-0+static void init_iommu_perf_ctr (struct amd_iommu *iommu) +{ +u64 val =0xabcd , val2 =0 ; + +if (!iommu_feature (iommu,FEATURE_PC )) +return ; + + amd_iommu_pc_present = true; +
drivers/iommu/amd_iommu_init.c static int __init init_iommu_all(struct acpi_table_header *table) · line 1183
Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+/* Check if the performance counters can be written to */ +if ((0 !=amd_iommu_pc_get_set_reg_val (0 ,0 ,0 ,0 , &val, true)) || + (0 !=amd_iommu_pc_get_set_reg_val (0 ,0 ,0 ,0 , &val2, false)) || + (val != val2)) { +pr_err ("AMD-Vi: Unable to write to IOMMU perf counter.\n" ); + amd_iommu_pc_present = false; +return ; + } + +pr_info ("AMD-Vi: IOMMU performance counters " "supported\n" );
Why are this two strings? This makes it hard to grep for the message.
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2285
Quoted 13 lines
drivers/iommu/amd_iommu_init.c +13
-0+u8 amd_iommu_pc_get_max_banks (u16 devid) +{ +struct amd_iommu *iommu; + +/* locate the iommu governing the devid */ + iommu = amd_iommu_rlookup_table[devid]; + +if (iommu) +return iommu->max_banks; + +return -ENODEV ; +} +EXPORT_SYMBOL (amd_iommu_pc_get_max_banks);
You can't return -ENODEV in a function returning u8. Return int instead.
Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+ +bool amd_iommu_pc_supported (void ) +{ +return amd_iommu_pc_present; +} +EXPORT_SYMBOL (amd_iommu_pc_supported); + +u8 amd_iommu_pc_get_max_counters (u16 devid) +{ +struct amd_iommu *iommu;
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2305
Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+ +/* locate the iommu governing the devid */ + iommu = amd_iommu_rlookup_table[devid]; + +if (iommu) +return iommu->max_counters; + +return -ENODEV ; +} +EXPORT_SYMBOL (amd_iommu_pc_get_max_counters);
Same here. Please don't return negative values as u8.
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2316
Quoted 11 lines
drivers/iommu/amd_iommu_init.c +11
-0+ +int amd_iommu_pc_get_set_reg_val (u16 devid,u8 bank,u8 cntr,u8 fxn, +u64 *value,bool is_write) +{ +struct amd_iommu *iommu; +u32 offset; +u32 max_offset_lim; + +/* Make sure the IOMMU PC resource is available */ +if (!amd_iommu_pc_present) { +pr_info ("AMD IOMMU - PC Not supported.\n" );
This message is redundant. You already print about about performance counter availability in the init code. Please remove it.
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2327
Quoted 11 lines
drivers/iommu/amd_iommu_init.c +11
-0+return -ENODEV ; + } + +/* locate the iommu associated with the device ID */ + iommu = amd_iommu_rlookup_table[devid]; +if (iommu ==NULL ) +return -ENODEV ; + +/* check for valid iommu pc register indexing */ +if (fxn <0 || fxn >0x28 || (fxn &7 )) +return -ENODEV ;
Does this check for calling errors? If so, you might consider turning this into a WARN_ON.
Quoted 11 lines
drivers/iommu/amd_iommu_init.c +11
-0+ + offset = (u32)(((0x40 |bank) <<12 ) | (cntr <<8 ) | fxn); + +/* limit the offset to the hw defined mmio region aperture */ + max_offset_lim = (u32)(((0x40 |iommu->max_banks) <<12 ) | + (iommu->max_counters <<8 ) |0x28 ); +if ((offset <MMIO_CNTR_REG_OFFSET ) || + (offset > max_offset_lim)) +return -EINVAL ; + +if (is_write) {
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2348
Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+writel ((u32)*value, iommu->mmio_base + offset); +writel ((*value >>32 ), iommu->mmio_base + offset +4 ); + }else { + *value =readl (iommu->mmio_base + offset +4 ); + *value <<=32 ; + *value =readl (iommu->mmio_base + offset); + } + +return 0 ; +}
Joerg
Re: [PATCH 1/2 V3] perf/x86/amd: Adding IOMMU PC resource management
Joerg,
Thanks for the review. I'll post new patch set to address your comment shortly.
Suravee
Quoted 159 lines · Joerg Roedel
Quoted 36 lines · Suravee
From: Steven L Kinney <[email protected]>
Add functionality to check the availability of the AMD IOMMU Performance Counters and export this functionality to other core drivers, such as in this case, a perf AMD IOMMU PMU. This feature is not bound to any specific AMD family/model other than the presence of the IOMMU with PC enabled.
The AMD IOMMU PC support static counting only at this time.
Signed-off-by Steven Kinney <[email protected]>Signed-off-by Suravee Suthikulpanit <[email protected]>---
V2 Changes:
- Modify theamd_iommu_pc_get_set_reg_valfunction to support 64 bit values.
- Fix logic to properly clearamd_iommu_pc_presentwhen initialization failed.drivers/iommu/amd_iommu_init.c | 121 ++++++++++++++++++++++++++++++++++++++- drivers/iommu/amd_iommu_proto.h | 7 +++ drivers/iommu/amd_iommu_types.h | 12 +++- 3 files changed, 134 insertions(+), 6 deletions(-)drivers/iommu/amd_iommu_init.c +1
-0@@ -154,6 +154,7 @@ bool amd_iommu_iotlb_sup __read_mostly = true;u32 amd_iommu_max_pasids__read_mostly = ~0 ;bool amd_iommu_v2_present__read_mostly ; +bool amd_iommu_pc_present__read_mostly ;bool amd_iommu_force_isolation__read_mostly ;drivers/iommu/amd_iommu_init.c static void iommu_disable(struct amd_iommu *iommu) · line 375
Quoted 5 lines
drivers/iommu/amd_iommu_init.c +1
-1@@ -371,21 +372,21 @@ static void iommu_disable(struct amd_iommu *iommu)*/ static u8 __iomem *__init iommu_map_mmio_space (u64 address) { -if (!request_mem_region (address,MMIO_REGION_LENGTH ,"amd_iommu" )) { +if (!request_mem_region (address,MMIO_REG_END_OFFSET ,"amd_iommu" )) {This length needs to be different on IOMMUv1 systems where the MMI region is only 16kb large. Only use
MMIO_REG_END_OFFSETon IOMMUv2 systems.Quoted 9 lines
drivers/iommu/amd_iommu_init.c +9
-0+static void init_iommu_perf_ctr (struct amd_iommu *iommu) +{ +u64 val =0xabcd , val2 =0 ; + +if (!iommu_feature (iommu,FEATURE_PC )) +return ; + + amd_iommu_pc_present = true; +drivers/iommu/amd_iommu_init.c static int __init init_iommu_all(struct acpi_table_header *table) · line 1183
Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+/* Check if the performance counters can be written to */ +if ((0 !=amd_iommu_pc_get_set_reg_val (0 ,0 ,0 ,0 , &val, true)) || + (0 !=amd_iommu_pc_get_set_reg_val (0 ,0 ,0 ,0 , &val2, false)) || + (val != val2)) { +pr_err ("AMD-Vi: Unable to write to IOMMU perf counter.\n" ); + amd_iommu_pc_present = false; +return ; + } + +pr_info ("AMD-Vi: IOMMU performance counters " "supported\n" );Why are this two strings? This makes it hard to grep for the message.
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2285
Quoted 13 lines
drivers/iommu/amd_iommu_init.c +13
-0+u8 amd_iommu_pc_get_max_banks (u16 devid) +{ +struct amd_iommu *iommu; + +/* locate the iommu governing the devid */ + iommu = amd_iommu_rlookup_table[devid]; + +if (iommu) +return iommu->max_banks; + +return -ENODEV ; +} +EXPORT_SYMBOL (amd_iommu_pc_get_max_banks);You can't return
-ENODEVin a function returning u8. Return int instead.Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+ +bool amd_iommu_pc_supported (void ) +{ +return amd_iommu_pc_present; +} +EXPORT_SYMBOL (amd_iommu_pc_supported); + +u8 amd_iommu_pc_get_max_counters (u16 devid) +{ +struct amd_iommu *iommu;drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2305
Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+ +/* locate the iommu governing the devid */ + iommu = amd_iommu_rlookup_table[devid]; + +if (iommu) +return iommu->max_counters; + +return -ENODEV ; +} +EXPORT_SYMBOL (amd_iommu_pc_get_max_counters);Same here. Please don't return negative values as u8.
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2316
Quoted 11 lines
drivers/iommu/amd_iommu_init.c +11
-0+ +int amd_iommu_pc_get_set_reg_val (u16 devid,u8 bank,u8 cntr,u8 fxn, +u64 *value,bool is_write) +{ +struct amd_iommu *iommu; +u32 offset; +u32 max_offset_lim; + +/* Make sure the IOMMU PC resource is available */ +if (!amd_iommu_pc_present) { +pr_info ("AMD IOMMU - PC Not supported.\n" );This message is redundant. You already print about about performance counter availability in the init code. Please remove it.
drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2327
Quoted 11 lines
drivers/iommu/amd_iommu_init.c +11
-0+return -ENODEV ; + } + +/* locate the iommu associated with the device ID */ + iommu = amd_iommu_rlookup_table[devid]; +if (iommu ==NULL ) +return -ENODEV ; + +/* check for valid iommu pc register indexing */ +if (fxn <0 || fxn >0x28 || (fxn &7 )) +return -ENODEV ;Does this check for calling errors? If so, you might consider turning this into a
WARN_ON.Quoted 11 lines
drivers/iommu/amd_iommu_init.c +11
-0+ + offset = (u32)(((0x40 |bank) <<12 ) | (cntr <<8 ) | fxn); + +/* limit the offset to the hw defined mmio region aperture */ + max_offset_lim = (u32)(((0x40 |iommu->max_banks) <<12 ) | + (iommu->max_counters <<8 ) |0x28 ); +if ((offset <MMIO_CNTR_REG_OFFSET ) || + (offset > max_offset_lim)) +return -EINVAL ; + +if (is_write) {drivers/iommu/amd_iommu_init.c bool amd_iommu_v2_supported(void) · line 2348
Quoted 10 lines
drivers/iommu/amd_iommu_init.c +10
-0+writel ((u32)*value, iommu->mmio_base + offset); +writel ((*value >>32 ), iommu->mmio_base + offset +4 ); + }else { + *value =readl (iommu->mmio_base + offset +4 ); + *value <<=32 ; + *value =readl (iommu->mmio_base + offset); + } + +return 0 ; +}Joerg
PATCH v3 2/2 perf/x86/amd: AMD IOMMU PC PERF uncore PMU implementation
In reply to [email protected]From: Suravee Suthikulpanit <[email protected]>
Implement a perf PMU to handle IOMMU performance counters and events. The PMU only supports counting mode (e.g. perf stat). Since the counters are shared across all cores, the PMU is implemented as "system-wide" mode.
To invoke the AMD IOMMU PMU, issue a perf tool command such as:
./perf stat -a -e amd_iommu/<events>/ <command>
or
./perf stat -a -e amd_iommu/config=<config-data>,config1=<config1-data>/ <command>
For example:
./perf stat -a -e amd_iommu/mem_trans_total/ <command>
The resulting count will be how many IOMMU total peripheral memory operations were performed during the command execution window.
The IOMMU performance counter support is available starting in the AMD family15h model 0x30. For information regarding IOMMU performance counter configuration, please see the AMD IOMMU v2.5 specification.
---
V3 Changes:
This version contain several changes:
- Properly implement system-wide mode.
- Add "amd_iommu/cpumask".
- Add "amd_iommu/events"
- Simplify "amd_iommu/format"
- Add supports for devid, domid, and pasid filtering
arch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/perf_event_amd_iommu.c | 498 ++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_amd_iommu.h | 40 +++ 3 files changed, 539 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/cpu/perf_event_amd_iommu.c create mode 100644 arch/x86/kernel/cpu/perf_event_amd_iommu.h
arch/x86/kernel/cpu/Makefile +1 -1
@@ -30,7 +30,7 @@ obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o ifdef CONFIG_PERF_EVENTS -obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd.o perf_event_amd_uncore.o +obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd.o perf_event_amd_uncore.o perf_event_amd_iommu.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_p6.o perf_event_knc.o perf_event_p4.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o obj-$(CONFIG_CPU_SUP_INTEL) += perf_event_intel_uncore.o
arch/x86/kernel/cpu/perf_event_amd_iommu.c new file +498 -0
498 lines not on this page · raw message
arch/x86/kernel/cpu/perf_event_amd_iommu.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2013 Advanced Micro Devices, Inc. +* +* Author: Steven Kinney <[email protected]> +* Author: Suravee Suthikulpanit <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef _PERF_EVENT_AMD_IOMMU_H_ +#define _PERF_EVENT_AMD_IOMMU_H_ + +/* iommu pc mmio region register indexes */ +#define IOMMU_PC_COUNTER_REG 0x00 +#define IOMMU_PC_COUNTER_SRC_REG 0x08 +#define IOMMU_PC_PASID_MATCH_REG 0x10 +#define IOMMU_PC_DOMID_MATCH_REG 0x18 +#define IOMMU_PC_DEVID_MATCH_REG 0x20 +#define IOMMU_PC_COUNTER_REPORT_REG 0x28 + +/* maximun specified bank/counters */ +#define PC_MAX_SPEC_BNKS 64 +#define PC_MAX_SPEC_CNTRS 16 + +/* iommu pc reg masks*/ +#define IOMMU_BASE_DEVID 0x0000 + +/* amd_iommu_init.c external support functions */ +extern bool amd_iommu_pc_supported (void ); + +extern u8 amd_iommu_pc_get_max_banks (u16 devid); + +extern u8 amd_iommu_pc_get_max_counters (u16 devid); + +extern int amd_iommu_pc_get_set_reg_val (u16 devid,u8 bank,u8 cntr, +u8 fxn,u64 *value,bool is_write); + +#endif /*_PERF_EVENT_AMD_IOMMU_H_*/
Signature · 1 line
1.7.10.4
Joerg Roedel
maintainerRe: [PATCH 2/2 V3] perf/x86/amd: AMD IOMMU PC PERF uncore PMU implementation
arch/x86/kernel/cpu/Makefile obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o · line 33
Quoted 10 lines · Suravee
arch/x86/kernel/cpu/Makefile +1
-1@@ -30,7 +30,7 @@ obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o ifdef CONFIG_PERF_EVENTS -obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd.o perf_event_amd_uncore.o +obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd.o perf_event_amd_uncore.o perf_event_amd_iommu.o
This should also depend on CONFIG_AMD_IOMMU. If no IOMMU driver is compiled in it doesn't make sense to have that PMU.
Quoted 40 lines
arch/x86/kernel/cpu/Makefile +40
-0+static int perf_iommu_event_init(struct perf_event *event) +{ + struct hw_perf_event *hwc = &event->hw; + struct perf_amd_iommu *perf_iommu; + u64 config, config1; + + /* test the event attr type check for PMU enumeration */ + if (event->attr.type != event->pmu->type) + return -ENOENT; + + /* + * IOMMU counters are shared across all cores. + * Therefore, it does not support per-process mode. + * Also, it does not support event sampling mode. + */ + if (is_sampling_event(event) || event->attach_state & PERF_ATTACH_TASK) + return -EINVAL; + + /* IOMMU counters do not have usr/os/guest/host bits */ + if (event->attr.exclude_user || event->attr.exclude_kernel || + event->attr.exclude_host || event->attr.exclude_guest) + return -EINVAL; + + if (event->cpu < 0) + return -EINVAL; + + perf_iommu = &__perf_iommu; + + if (event->pmu != &perf_iommu->pmu) + return -ENOENT; + + if (perf_iommu) { + config = event->attr.config; + config1 = event->attr.config1; + } else { + return -EINVAL; + } + + /* integrate with iommu base devid (0000), assume one iommu */ + perf_iommu->max_banks =
arch/x86/kernel/cpu/Makefile obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o
Quoted 10 lines
arch/x86/kernel/cpu/Makefile +10
-0+ amd_iommu_pc_get_max_banks(IOMMU_BASE_DEVID); + perf_iommu->max_counters = + amd_iommu_pc_get_max_counters(IOMMU_BASE_DEVID); + + /* update the hw_perf_event struct with the iommu config data */ + hwc->config = config; + hwc->extra_reg.config = config1; + + return 0; +}
That implementation is very basic. Any reason for not using the event reporting mechanism of the IOMMU? You could implement a nice perf iommutop or something to see which devices do the most transactions or something like that.
Joerg
Re: [PATCH 2/2 V3] perf/x86/amd: AMD IOMMU PC PERF uncore PMU implementation
Quoted 8 lines · Joerg Roedel
Quoted 7 lines · Suravee
arch/x86/kernel/cpu/Makefile +0
-0@@ -30,7 +30,7 @@ obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o obj-$(CONFIG_PERF_EVENTS) += perf_event.o
Quoted 5 lines
arch/x86/kernel/cpu/Makefile obj-$(CONFIG_CPU_SUP_UMC_32) += umc.o · line 33
Quoted 3 lines
arch/x86/kernel/cpu/Makefile +1
-1ifdef CONFIG_PERF_EVENTS -obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd.o perf_event_amd_uncore.o +obj-$(CONFIG_CPU_SUP_AMD) += perf_event_amd.o perf_event_amd_uncore.o perf_event_amd_iommu.oThis should also depend on
CONFIG_AMD_IOMMU. If no IOMMU driver is compiled in it doesn't make sense to have that PMU.
I will take care of this.
Quoted 22 lines
arch/x86/kernel/cpu/perf_event_amd_iommu.c new file +16
-0+ }else { +return -EINVAL ; + } + +/* integrate with iommu base devid (0000), assume one iommu */ + perf_iommu->max_banks = +amd_iommu_pc_get_max_banks (IOMMU_BASE_DEVID ); + perf_iommu->max_counters = +amd_iommu_pc_get_max_counters (IOMMU_BASE_DEVID ); + +/* update the hw_perf_event struct with the iommu config data */ + hwc->config = config; + hwc->extra_reg.config = config1; + +return 0 ; +}That implementation is very basic. Any reason for not using the event reporting mechanism of the IOMMU? You could implement a nice perf iommutop or something to see which devices do the most transactions or something like that.
Quoted 1 line
Joerg
This patch is adding perf system-wide counting mode support which is used by "perf stat" tool. We are not implementing the sampling mode since MSI interrupt of the IOMMU cannot be used for current perf sampling tools (e.g. perf record or top) since the IOMMU counters are not core-specific. The current "perf record" and "perf top" needs to attribute each sample to a particular core/pid which would allow the tools to figure out the instruction pointer and map the sample to a paticular module.
If I understand correctly, when you mentioned "perf iommutop", you want a new perf user-space tool which will show real-time IOMMU events per IOMMU HW and/or device?
Suravee
Peter Zijlstra
maintainerRe: [PATCH 2/2 V3] perf/x86/amd: AMD IOMMU PC PERF uncore PMU implementation
Quoted 15 lines · Suravee Suthikulanit
Quoted 4 lines · Joerg Roedel
That implementation is very basic. Any reason for not using the event reporting mechanism of the IOMMU? You could implement a nice perf iommutop or something to see which devices do the most transactions or something like that.
This patch is adding perf system-wide counting mode support which is used by "perf stat" tool. We are not implementing the sampling mode since MSI interrupt of the IOMMU cannot be used for current perf sampling tools (e.g.
perf record or top) since the IOMMU counters are not core-specific. The
current "perf record" and "perf top" needs to attribute each sample to a particular core/pid which would allow the tools to figure out the instruction pointer and map the sample to a paticular module.
Quoted 3 lines
If I understand correctly, when you mentioned "perf iommutop", you want a new perf user-space tool which will show real-time IOMMU events per IOMMU HW and/or device?
Right, unless there's more to the IOMMU event reporting than setting an event threshold to get an interrupt of kinds I don't see how an interrupt would be useful except for making sure we don't loose a counter overflow.
Note that for Intel uncore we poll with a software timer to ensure we don't miss the overflow because its interrupt facility is either broken or missing.
If otoh the event reporting thing includes more data than just 'hey counter overflow!' it might be useful. Not exactly sure how yet because it would be the first PMU to need this.
Peter,
Please let me know if you have any questions/concerns regarding the PMU implementation.
Joerg,
Please let me know if you have any questions/concerns regarding the changes in the IOMMU driver.
Thank you,
Suravee
Quoted 28 lines · On 5/17/2013 2:43 PM, [email protected] wrote:
From: Suravee Suthikulpanit <[email protected]>
These patches implement the AMD IOMMU Performance Counter functionality via custom perf PMU and implement static counting for various IOMMU translations.
1) Extend the AMD IOMMU initialization to include performance counter enablement.
2) The perf AMD IOMMU PMU to manage performance counters, which interface with the AMD IOMMU core driver.
Steven L Kinney (1):
perf/x86/amd: Adding IOMMU PC resource managementSuravee Suthikulpanit (1):
perf/x86/amd: AMD IOMMU PC PERF uncore PMU implementationarch/x86/kernel/cpu/Makefile | 2 +- arch/x86/kernel/cpu/perf_event_amd_iommu.c | 500 ++++++++++++++++++++++++++++ arch/x86/kernel/cpu/perf_event_amd_iommu.h | 40 +++ drivers/iommu/amd_iommu_init.c | 121 ++++++- drivers/iommu/amd_iommu_proto.h | 7 + drivers/iommu/amd_iommu_types.h | 12 +- 6 files changed, 675 insertions(+), 7 deletions(-)create mode 100644
arch/x86/kernel/cpu/perf_event_amd_iommu.ccreate mode 100644arch/x86/kernel/cpu/perf_event_amd_iommu.h
Peter Zijlstra
maintainerQuoted 4 lines · Suravee Suthikulanit
Peter,
Please let me know if you have any questions/concerns regarding the PMU implementation.
Looks good, how would you like to go about merging this? Should I push it through Ingo's tree or do you prefer it goes through some IOMMU tree?
Quoted 8 lines · Peter Zijlstra
Quoted 4 lines · Suravee Suthikulanit
Peter,
Please let me know if you have any questions/concerns regarding the PMU implementation.
Looks good, how would you like to go about merging this? Should I push it through Ingo's tree or do you prefer it goes through some IOMMU tree?
Thank you, Peter. Since this is mostly PERF-related feature, I think it would be appropriate to push this through Ingo's tree.
Suravee
Peter Zijlstra
maintainerQuoted 11 lines · Suravee Suthikulanit
Quoted 8 lines · Peter Zijlstra
Quoted 4 lines · Suravee Suthikulanit
Peter,
Please let me know if you have any questions/concerns regarding the PMU implementation.
Looks good, how would you like to go about merging this? Should I push it through Ingo's tree or do you prefer it goes through some IOMMU tree?
Thank you, Peter. Since this is mostly PERF-related feature, I think it would be appropriate to push this through Ingo's tree.
OK, I'll take them and will push them to Ingo.
Thanks!
Joerg Roedel
maintainerHi Peter,
Quoted 1 line · Peter Zijlstra
OK, I'll take them and will push them to Ingo.
Please wait with that until I had a look at the IOMMU pieces.
Thanks,
Joerg
Peter Zijlstra
maintainerQuoted 6 lines · Joerg Roedel
Hi Peter,
Quoted 1 line · Peter Zijlstra
OK, I'll take them and will push them to Ingo.
Please wait with that until I had a look at the IOMMU pieces.
Sure thing, I'll wait until I hear from you again.
Peter Zijlstra
maintainerQuoted 6 lines · Joerg Roedel
Hi Peter,
Quoted 1 line · Peter Zijlstra
OK, I'll take them and will push them to Ingo.
Please wait with that until I had a look at the IOMMU pieces.
Have you had time to look at this yet? -- mostly sending this email to make sure I don't forget about these patches.
Joerg Roedel
maintainerHi Peter,
Quoted 2 lines · Peter Zijlstra
Have you had time to look at this yet? -- mostly sending this email to make sure I don't forget about these patches.
Sorry about that, I didn't forget it. But I was traveling last week and had an outage of my root-server (where all my email is) over the weekend. But it should all be back to normal now and I will look at these patches tomorrow.
Thanks,
Joerg