[PATCH v2 4/6] perf/amd/iommu: Introduce data structure for tracking prev count.

From: Suravee Suthikulpanit
Date: Fri Jan 01 2016 - 13:24:47 EST


To enable AMD IOMMU PMU to support multiple IOMMUs, this patch introduces
a new data structure, perf_amd_iommu.prev_cnts, to track previous counts
of IOMMU performance counters in multi-IOMMU environment.

Also, this patch allocates perf_iommu_cnts for internal use
when manages counters.

Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@xxxxxxx>
---
arch/x86/kernel/cpu/perf_event_amd_iommu.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
index e6d2485..99fcd10 100644
--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
@@ -42,6 +42,7 @@ struct perf_amd_iommu {
u64 cntr_assign_mask;
raw_spinlock_t lock;
const struct attribute_group *attr_groups[4];
+ local64_t *prev_cnts;
};

#define format_group attr_groups[0]
@@ -126,6 +127,8 @@ static struct amd_iommu_event_desc amd_iommu_v2_event_descs[] = {
{ /* end: all zeroes */ },
};

+static u64 *perf_iommu_cnts;
+
/*---------------------------------------------
* sysfs cpumask attributes
*---------------------------------------------*/
@@ -423,10 +426,14 @@ static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)

static __init void amd_iommu_pc_exit(void)
{
- if (__perf_iommu.events_group != NULL) {
- kfree(__perf_iommu.events_group);
- __perf_iommu.events_group = NULL;
- }
+ kfree(__perf_iommu.events_group);
+ __perf_iommu.events_group = NULL;
+
+ kfree(__perf_iommu.prev_cnts);
+ __perf_iommu.prev_cnts = NULL;
+
+ kfree(perf_iommu_cnts);
+ perf_iommu_cnts = NULL;
}

static __init int _init_perf_amd_iommu(
@@ -456,6 +463,17 @@ static __init int _init_perf_amd_iommu(
perf_iommu->null_group = NULL;
perf_iommu->pmu.attr_groups = perf_iommu->attr_groups;

+ perf_iommu->prev_cnts = kzalloc(sizeof(*perf_iommu->prev_cnts) *
+ (amd_iommu_get_num_iommus() * perf_iommu->max_banks *
+ perf_iommu->max_counters), GFP_KERNEL);
+ if (!perf_iommu->prev_cnts)
+ return -ENOMEM;
+
+ perf_iommu_cnts = kzalloc(sizeof(*perf_iommu_cnts) *
+ amd_iommu_get_num_iommus(), GFP_KERNEL);
+ if (!perf_iommu_cnts)
+ return -ENOMEM;
+
ret = perf_pmu_register(&perf_iommu->pmu, name, -1);
if (ret) {
pr_err("perf: amd_iommu: Failed to initialized.\n");
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/