o
    Û1jè  ã                   @   s&   d dl mZmZ G dd„ deeƒZdS )é    )ÚPluginÚIndependentPluginc                   @   s0   e Zd ZdZdZdZdZedd„ ƒZdd„ Z	d	S )
ÚSpyreuÖ   Spyre chip is IBMâ€™s AI accelerator, designed to handle AI inferencing
    and workloads.

    The Spyre plugin collects data about the Spyre cardâ€™s VFIO device node
    tree, configuration files, and more.
    z!IBM Spyre Accelerator InformationÚspyre)zppc.*c              	   C   sÔ   g }| sdS |   ¡ D ]]}| ¡ sq
z|jdd�\}}}}| ¡  d¡\}}W n	 ty/   Y q
w |dkrg|dv rg| d¡dkrCd| }z| d¡\}	}
}| d	¡\}}W n	 ty]   Y q
w | |	|
||f¡ q
|S )
a�  Extract PCI domain, bus, device, function for devices that match:
        - Vendor ID = 0x1014 (IBM)
        - Device ID = 0x06a7 or 0x06a8

        Parameters
        ----------
        lspci_out : str
        The output string from `lspci -n`.

        Returns
        -------
        list of tuples
        A list of (domain, bus, device, function) tuples for each matching
        card.
        Né   )Úmaxsplitú:Ú1014)Ú06a7Ú06a8é   z0000:Ú.)Ú
splitlinesÚstripÚsplitÚlowerÚ
ValueErrorÚcountÚappend)Úlspci_outputÚspyre_cardsÚlineÚpci_addrÚ_classÚidsÚ_restÚvendorÚdeviceÚdomainÚbusÚdev_funcÚ
pci_deviceÚfunction© r#   ú:/usr/lib/python3/dist-packages/sos/report/plugins/spyre.pyÚget_ibm_spyre_devices   s0   ÿÿ€zSpyre.get_ibm_spyre_devicesc           	      C   s”   |   d¡}|d dkrd S |  |d ¡}|sd S |D ]&\}}}}|› d|› d|› d|› �}d|› d|› d|› d	�}| j|d
d� q|  g d¢¡ d S )Nzlspci -nÚstatusr   Úoutputr   r   z/sys/devices/pciú/z	/vfio-devT)Útree)z/etc/modprobe.d/vfio-pci.confz!/etc/udev/rules.d/95-vfio-3.rulesz#/etc/security/limits.d/memlock.conf)Úexec_cmdr%   Úadd_dir_listingÚadd_copy_spec)	ÚselfÚlspcir   r   r   r   r"   r   Úpci_vfior#   r#   r$   ÚsetupH   s   
zSpyre.setupN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
short_descÚplugin_nameÚarchitecturesÚstaticmethodr%   r0   r#   r#   r#   r$   r      s    
-r   N)Úsos.report.pluginsr   r   r   r#   r#   r#   r$   Ú<module>   s   
