| 1 |
# Copyright (C) Advanced Micro Devices. All rights reserved. |
| 2 |
# |
| 3 |
# Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
# this software and associated documentation files (the "Software"), to deal in |
| 5 |
# the Software without restriction, including without limitation the rights to |
| 6 |
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 7 |
# the Software, and to permit persons to whom the Software is furnished to do so, |
| 8 |
# subject to the following conditions: |
| 9 |
# |
| 10 |
# The above copyright notice and this permission notice shall be included in all |
| 11 |
# copies or substantial portions of the Software. |
| 12 |
# |
| 13 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 15 |
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 16 |
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 17 |
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 18 |
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 19 |
|
| 20 |
from amdsmi import * |
| 21 |
import os |
| 22 |
|
| 23 |
amdsmi_init() |
| 24 |
|
| 25 |
def amdsmi_get_afids_from_cper(): |
| 26 |
directory_path = "/tmp/cper_dump/" |
| 27 |
print(f"Searching for cper file in {directory_path}") |
| 28 |
with os.scandir(directory_path) as cper_files: |
| 29 |
for cper_file in cper_files: |
| 30 |
if cper_file.is_file(): # Check if the entry is a file (not a subdirectory) |
| 31 |
if ".bin" in cper_file.path: |
| 32 |
print(f"Found {cper_file.path}") |
| 33 |
with open(cper_file.path, "rb") as file: |
| 34 |
raw = file.read() |
| 35 |
afids, num_afids = amdsmi_interface.amdsmi_get_afids_from_cper(raw) |
| 36 |
print(f"afids: {afids}") |
| 37 |
|
| 38 |
amdsmi_get_afids_from_cper() |
| 39 |
|
| 40 |
""" |
| 41 |
Sample output: |
| 42 |
|
| 43 |
sudo python3 afid.py |
| 44 |
Searching for cper file in /tmp/cper_dump/ |
| 45 |
Found /tmp/cper_dump/cper_entry_0.bin |
| 46 |
afids: [17] |
| 47 |
Found /tmp/cper_dump/cper_entry_1.bin |
| 48 |
afids: [17] |
| 49 |
""" |