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))) {