Skip to content

Adding a method to check for accelerators#6294

Open
saijanani-c wants to merge 2 commits intoavocado-framework:masterfrom
saijanani-c:accelerator-class-check
Open

Adding a method to check for accelerators#6294
saijanani-c wants to merge 2 commits intoavocado-framework:masterfrom
saijanani-c:accelerator-class-check

Conversation

@saijanani-c
Copy link
Copy Markdown

Adding a new function isAccelerator()
to detect PCI devices with class name
"accelerator".

@mr-avocado mr-avocado bot moved this to Review Requested in Default project Apr 5, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new utility function isAccelerator to check for the presence of PCI accelerator devices. The review feedback suggests renaming the function to is_accelerator to adhere to PEP 8 naming conventions and replacing the broad exception handler with a more specific one. Additionally, the reviewer noted that the current implementation is inefficient due to frequent process forking and suggested a more performant approach by reading directly from the sysfs filesystem.

cfg_dic["subvendor_device"] = device_subvendor.group()
return cfg_dic

def isAccelerator():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function name isAccelerator uses camelCase, which is inconsistent with the snake_case naming convention used throughout this module (e.g., get_pci_addresses, get_pci_class_name) and violates PEP 8 guidelines. It should be renamed to is_accelerator.

Suggested change
def isAccelerator():
def is_accelerator():

Comment on lines +709 to +713
try:
if get_pci_class_name(dev) == "accelerator":
return True
except Exception:
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a bare except Exception is discouraged as it can catch and hide unrelated errors (such as KeyboardInterrupt or implementation bugs). Since get_pci_class_name specifically raises ValueError when a class is not recognized or cannot be retrieved, it is better to catch that specifically.

Additionally, this implementation is inefficient because it forks an lspci process for every PCI device on the system via get_pci_class_name. For a more performant approach, consider reading the class ID directly from /sys/bus/pci/devices/<dev>/class to avoid the overhead of multiple process forks.

Suggested change
try:
if get_pci_class_name(dev) == "accelerator":
return True
except Exception:
pass
try:
if get_pci_class_name(dev) == "accelerator":
return True
except ValueError:
continue

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 12.50000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.30%. Comparing base (1cb5c87) to head (39678db).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
avocado/utils/pci.py 12.50% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6294      +/-   ##
==========================================
- Coverage   74.04%   72.30%   -1.75%     
==========================================
  Files         206      206              
  Lines       22651    23258     +607     
==========================================
+ Hits        16773    16817      +44     
- Misses       5878     6441     +563     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@saijanani-c saijanani-c force-pushed the accelerator-class-check branch from f36cf1a to 6e65fd6 Compare April 6, 2026 07:36
Adding a new function isAccelerator()
to detect PCI devices with class name
"accelerator".

Signed-off-by: Sai Janani C <jananic@linux.ibm.com>
@saijanani-c saijanani-c force-pushed the accelerator-class-check branch from 6e65fd6 to 1b8610f Compare April 8, 2026 08:28
Apply black formatting to pci.py

Signed-off-by: Praveen K Pandey <praveen@linux.vnet.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Review Requested

Development

Successfully merging this pull request may close these issues.

2 participants