-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2792 from AYUSHJAIN951/perf/perf_genericevents
perf/perf_genericevents.py: Use AMD Zen for parsing
- Loading branch information
Showing
2 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ | |
# | ||
# | ||
# Copyright: 2017 IBM | ||
# Copyright (C) 2024 Advanced Micro Devices, Inc. | ||
# Author: Athira Rajeev<[email protected]> | ||
# Author: Shriya Kulkarni <[email protected]> | ||
# Author: Ayush Jain <[email protected]> | ||
|
||
import os | ||
import configparser | ||
|
@@ -46,19 +48,28 @@ def read_generic_events(self): | |
self.generic_events = dict(parser.items('POWER10')) | ||
else: | ||
self.cancel("Processor is not supported: %s" % cpu_info) | ||
if 'amd' in cpu.get_vendor(): | ||
for line in cpu_info.splitlines(): | ||
if 'cpu family' in line: | ||
self.family = int(line.split(':')[1]) | ||
self.arch = cpu.get_arch() | ||
self.vendor = cpu.get_vendor() | ||
if 'amd' in self.vendor: | ||
self.family = cpu.get_family() | ||
if self.family == 0x16: | ||
self.log.info("AMD Family: 16h") | ||
self.generic_events = dict(parser.items('AMD16h')) | ||
elif self.family >= 0x17: | ||
self.log.info("AMD Family: 17h") | ||
self.generic_events = dict(parser.items('AMD17h')) | ||
self.amd_zen = cpu.get_x86_amd_zen() | ||
if self.amd_zen is None: | ||
self.cancel("Unsupported AMD ZEN") | ||
self.log.info(f"AMD Family: {self.family} ZEN{self.amd_zen}") | ||
if f'AMDZEN{self.amd_zen}' in parser.keys() is not None: | ||
self.generic_events = dict(parser.items(f'AMDZEN{self.amd_zen}')) | ||
else: | ||
self.cancel(f"AMD ZEN{self.amd_zen} raw_code cfg not found") | ||
else: | ||
self.cancel("Unsupported AMD Family") | ||
|
||
def hex_to_int(self, input): | ||
return int(input, 0) | ||
|
||
def test(self): | ||
nfail = 0 | ||
dir = "/sys/bus/event_source/devices/cpu/events" | ||
|
@@ -71,19 +82,24 @@ def test(self): | |
if val is None: | ||
continue | ||
if 'umask' in event_code: | ||
self.log.debug("EventCode: %s" % event_code) | ||
event = (event_code.split('0x')[1]).rstrip(',umask=') | ||
umask = event_code.split('=', 2)[2].rstrip() | ||
raw_code = umask + event | ||
if self.arch == "x86_64" and 'amd' in self.vendor: | ||
umask = self.hex_to_int(umask) | ||
event = self.hex_to_int(event_code.split('=', 2)[1].rstrip(',umask=')) | ||
raw_code = (event & 0xff) | (umask << 8) | ((event & 0xf00) << 24) | ||
else: | ||
event = (event_code.split('0x')[1]).rstrip(',umask=') | ||
raw_code = self.hex_to_int(umask + event) | ||
else: | ||
raw_code = event_code.split('=', 2)[1].rstrip() | ||
raw_code = self.hex_to_int(event_code.split('=', 2)[1].rstrip()) | ||
|
||
self.log.info('FILE in %s is %s' % (dir, file)) | ||
if raw_code != val: | ||
if raw_code != self.hex_to_int(val): | ||
nfail += 1 | ||
self.log.info('FAIL : Expected value is %s but got ' | ||
'%s' % (val, raw_code)) | ||
self.log.info('FAIL : Expected value is %s or %s but got ' | ||
'%s' % (val, self.hex_to_int(val), raw_code)) | ||
else: | ||
self.log.info('PASS : Expected value: %s and got ' | ||
'%s' % (val, raw_code)) | ||
self.log.info('PASS : Expected value: %s or %s and got ' | ||
'%s' % (val, self.hex_to_int(val), raw_code)) | ||
if nfail != 0: | ||
self.fail('Failed to verify generic PMU event codes') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters