From 9ab8250fbc167a5944a30e02ec118ffbe4aa094f Mon Sep 17 00:00:00 2001 From: Amber Lin Date: Fri, 18 Aug 2017 10:15:21 -0400 Subject: [PATCH] IOMMU path in sysfs is renamed IOMMU path in sysfs was amd_iommu. After implementing multiple devices support, the path is replaced with amd_iommu_. Current Thunk spec is not clear about how to support multiple instances in one block. There is no products having multiple IOMMUs yet at this point. This patch changes the path to support both amd_iommu and amd_iommu_0 for Carizo. Change-Id: I3beea2fc78d96296232226191501a02ccf20d6b1 Signed-off-by: Amber Lin [ROCm/ROCR-Runtime commit: 369902bf5b3a957179200c378f46a90300456d42] --- projects/rocr-runtime/src/perfctr.c | 11 +++++++++-- projects/rocr-runtime/src/pmc_table.c | 14 ++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/projects/rocr-runtime/src/perfctr.c b/projects/rocr-runtime/src/perfctr.c index 5a0d6bd84a..bf05880ca5 100644 --- a/projects/rocr-runtime/src/perfctr.c +++ b/projects/rocr-runtime/src/perfctr.c @@ -365,9 +365,16 @@ static unsigned int get_perf_event_type(enum perf_block_id block_id) FILE *file = NULL; unsigned int type = 0; - if (block_id == PERFCOUNTER_BLOCKID__IOMMUV2) - file = fopen("/sys/bus/event_source/devices/amd_iommu/type", + if (block_id == PERFCOUNTER_BLOCKID__IOMMUV2) { + /* Starting from kernel 4.12, amd_iommu_0 is used */ + file = fopen("/sys/bus/event_source/devices/amd_iommu_0/type", "r"); + if (!file) + file = fopen(/* kernel 4.11 and older */ + "/sys/bus/event_source/devices/amd_iommu/type", + "r"); + } + if (!file) return 0; diff --git a/projects/rocr-runtime/src/pmc_table.c b/projects/rocr-runtime/src/pmc_table.c index 1bb4ba04bf..5f1cb3c877 100644 --- a/projects/rocr-runtime/src/pmc_table.c +++ b/projects/rocr-runtime/src/pmc_table.c @@ -1601,8 +1601,8 @@ static HSAKMT_STATUS alloc_pmc_blocks_iommu(void) { DIR *dir; struct dirent *dent; - const char sysfs_amdiommu_event_path[] = - "/sys/bus/event_source/devices/amd_iommu/events"; + const char *sysfs_amdiommu_event_path = + "/sys/bus/event_source/devices/amd_iommu_0/events"; /* Counter source in IOMMU's Counter Bank Addressing register is 8 bits, * so the biggest counter number/id possible is 0xff. */ @@ -1619,8 +1619,14 @@ static HSAKMT_STATUS alloc_pmc_blocks_iommu(void) memset(block, 0, sizeof(struct perf_counter_block)); dir = opendir(sysfs_amdiommu_event_path); - if (!dir) - goto out; + if (!dir) { + /* Before kernel 4.12, amd_iommu is the path */ + sysfs_amdiommu_event_path = + "/sys/bus/event_source/devices/amd_iommu/events"; + dir = opendir(sysfs_amdiommu_event_path); + if (!dir) + goto out; + } memset(counter_id, 0, max_counter_id + 1); while ((dent = readdir(dir))) {