+
     Gi&  c                   s    ^RI Ht ^RI5 ^ RIHt ^ RIt^ RIt^ RIt]P                  P                  4       t ! R R]4      t ! R R]P                  4      tR# )i   )hotplug)Z*Nc                   s&   a  ] tR t^t o R tRtV tR# )IrqInfoc                sJ    Wn         R V,          V n        RV n        RV n        R# )zirq%sFN)irqdeviceunchangeableoriginal_affinity)selfr      &&=/usr/lib/python3.14/site-packages/tuned/plugins/plugin_irq.py__init__ZIrqInfo.__init__   s"    (#$+$$    )r   r   r   r   N)__name__
__module____qualname____firstlineno__r	   __static_attributes____classdictcell__)__classdict__s   @r   r   r      s        r
   r   c                   s   a a ] tR t^t oRtV 3R ltR t]R 4       tR t	R t
V 3R ltV 3R ltV 3R	 ltR
 tR tR tR tR t]! RRRR7      R 4       t]! RRR7      R 4       tRtVtV ;t# )	IrqPlugina  
Allows tuning of IRQ affinities, and thus re-implements functionality
already present in the `scheduler` plugin. However, this plugin offers
more flexibility, as it allows tuning of individual interrupts with
different affinities. When using the `irq` plugin, make sure to disable
IRQ processing in the `scheduler` plugin by setting its option
[option]`irq_process=false`.

The plugin handles individual IRQs as devices and multiple plugin
instances can be defined, each addressing different devices/irqs.
The device names used by the plugin are `irq<n>`, where `<n>` is the
IRQ number. The special device `DEFAULT` controls values written to
`/proc/irq/default_smp_affinity`, which applies to all non-active IRQs.

The option [option]`affinity` controls the IRQ affinity to be set. It is
a string in "cpulist" format (such as `1,3-4`). If the configured affinity
is empty, then the affinity of the respective IRQs is not touched.

The option [option]`mode` is a string which can either be `set` (default)
or `intersect`. In `set` mode the [option]`affinity` is always written
as configured, whereas in `intersect` mode, the new affinity will be
calculated as the intersection of the current and the configured affinity.
If that intersection is empty, the configured affinity will be used.

.Moving all IRQs to CPU0, except irq16, which is directed to CPU2
====
----
[irq_special]
type=irq
devices=irq16
affinity=2

[irq]
affinity=0
----
====
c	           
     sB   < \         \        V `  WW4WVWx4       / V n        R # N)superr   r	   _irqs)
r   Zmonitor_repositoryZstorage_factoryZhardware_inventoryZdevice_matcherZdevice_matcher_udevZplugin_instance_factoryZ
global_cfgZ	variables	__class__s
   &&&&&&&&&r   r	   ZIrqPlugin.__init__:   s*    	4!"4GYk~  Zd  p$*r
   c                sN   RV n         \        4       V n        \        4       V n        \        P
                  ! R4       F  p\        P                  P                  RV4      p\        P                  P                  V4      '       g   KJ  VP                  4       '       g   Kb  \        V4      pW0P                  V&   V P                  P                  VP                  4       K  	  \        R4      pRVn        W@P                  R&   V P                  P                  VP                  4       R# )z2Read /proc/irq to collect devices
                Tz	/proc/irqDEFAULTN)_devices_supportedset_free_devices_assigned_devicesosZlistdirZpathZjoinZisdirZisdigitr   r   Zaddr   )r   ZiZpinfoZdefault_infos   &    r   _init_devicesZIrqPlugin._init_devicesA   s     !$u$5$::k"a	ww||K#1ggmmA199;;1:DJJqM4;;' # #,!,&**Y,,-r
   c                s    R RRR/# )affinity moder    )Zclss   &r   _get_config_optionsZIrqPlugin._get_config_optionsS   s     r	5
 r
   c                s   R Vn         RVn        V P                  P                  VP                  P                  R4      4      pV P                  P                  V4      p\        VP                  4       4      ^ 8X  d/   \        P                  RVP                  ,          4       RVn        M?\        V4      ^ 8X  d0   \        P                  RVP                  : RV: R24       RVn        V P                  P                  VP                  P                  R4      4      pVR9  d:   \        P                  R	V: R
VP                  : R24       RVP                  R&   R# R# )TFr   z;Instance '%s' configured with empty affinity. Deactivating.z
Instance 'z' with invalid affinity 'z'. Deactivating.r!   r   zInvalid operating mode 'z' for instance 'z#'. Using the default 'set' instead.N)r   	intersect)Z_has_static_tuningZ_has_dynamic_tuningZ
_variablesZexpandZoptionsget_cmdcpulist_unpacklenstriplogr   nameZ_activeerror)r   instancer   Zaffinity_listr!   s   &&   r   _instance_initZIrqPlugin._instance_init]   s    $(!&(__##H$4$4$8$8$DE())**84-	a88IHMMYZ8
=Q99(--Yabc8			 0 0 4 4V <	=$	%%99hmm #8F &r
   c                s    R # r   r"   )r   r-   r   r   _instance_cleanupZIrqPlugin._instance_cleanupr   s    r
   c                sz   < \         P                  R VP                  ,          4       \        \        V `  V4       R# )zApplying IRQ affinities (%s)N)r*   debugr+   r   r   _instance_apply_static)r   r-   r   s   &&r   r1   Z IrqPlugin._instance_apply_staticu   s(    ))*X]]:;	4/9r
   c                sz   < \         P                  R VP                  ,          4       \        \        V `  W4       R# )zUnapplying IRQ affinities (%s)N)r*   r0   r+   r   r   _instance_unapply_static)r   r-   Zrollbackr   s   &&&r   r2   Z"IrqPlugin._instance_unapply_staticy   s(    )),x}}<=	41(Er
   c                sx   < \         P                  R VP                  ,          4       \        \        V `  WV4      # )zVerifying IRQ affinities (%s))r*   r0   r+   r   r   _instance_verify_static)r   r-   ignore_missingZdevicesr   s   &&&&r   r3   Z!IrqPlugin._instance_verify_static}   s.    ))+hmm;<	y$	7RY	ZZr
   c                s    VR8X  d   RMRV,          p\        VR4      ;_uu_ 4       pVP                  4       P                  4       pRRR4       \        V P                  P                  X4      4      #   + '       g   i     L4; i  \        \        3 d2   p\        P                  RT: RT: 24       \        4       u Rp?# Rp?ii ; i)a
  Get current IRQ affinity from the kernel

Args:
        irq (str): IRQ number (as string) or "DEFAULT"

Returns:
        affinity (set): set of all CPUs that belong to the IRQ affinity mask,
                if reading of the affinity fails, an empty set is returned
r   /proc/irq/default_smp_affinity/proc/irq/%s/smp_affinityZrNz#Failed to read SMP affinity of IRQ z: )
openZreadliner)   r   r&   Zhex2cpulistOSErrorIOErrorr*   r0   )r   r   filenamefaffinity_hexes   &&    r   _get_irq_affinityZIrqPlugin._get_irq_affinity   s    252B.HcfiHi8Xsq::<%%'L 	
dii##L1
22 	 7	 99CCD
%<s4   &B A3+B 3B	>B C&C=CCc           	     sn    V P                   P                  \        V4      4      p\        P	                  RV: RV: R24       VR8X  d   RMRV,          p\        VR4      ;_uu_ 4       pVP                  V4       RRR4       ^ #   + '       g   i     ^ # ; i  \        \        3 d   p\        TR	4      '       dK   TP                  \        P                  8X  d,   T'       g$   \        P	                  R
T,          4       Ru Rp?# \        P                  RT: RX: RT: 24       Ru Rp?# Rp?ii ; i)a^  Set IRQ affinity in the kernel

Args:
        irq (str): IRQ number (as string) or "DEFAULT"
        affinity (set): affinity mask as set of CPUs
        restoring (bool): are we rolling back a previous change?

Returns:
        status (int):  0 on success, -2 if changing the affinity is not
                supported, -1 if some other error occurs
zSetting SMP affinity of IRQ z to 'Z'r   r5   r6   ZwNerrnoz/Setting SMP affinity of IRQ %s is not supportedz"Failed to set SMP affinity of IRQ z': i)r&   Zcpulist2hexlistr*   r0   r7   Zwriter8   r9   Zhasattrr?   ZEIOr,   )r   r   r   Z	restoringr<   r:   r;   r=   s   &&&&    r   _set_irq_affinityZIrqPlugin._set_irq_affinity   s    ))''X7<99lKL252B.HcfiHi8XsqGGL 	
 	

7	 

 aagg29II?#EFIIICWXYZI
sN   A(B *B<B B	B B D4+8D/$D/D4"D/)D4/D4c                s:   V P                  VP                  4      pVR8X  d   W$,          ;'       g    TpVP                  '       g   W$8X  d   R# V P                  VP                  VR4      pV^ 8X  d   VP                  f	   WAn        R# R# VR8X  d
   RVn        R# R# )z~Apply IRQ affinity tuning

Args:
        irqinfo (IrqInfo): IRQ that should be tuned
        affinity (set): desired affinity
r$   NFTr@   )r>   r   r   rB   r   )r   irqinfor   r!   ZoriginalZress   &&&&  r   _apply_irq_affinityZIrqPlugin._apply_irq_affinity   s     ##GKK0(	[!--X8X1	w{{He<#AX' ( (
by7 r
   c                s    VP                   '       g   VP                  f   R# V P                  VP                  VP                  R4       RVn        R# )zSRestore IRQ affinity

Args:
        irqinfo (IrqInfo): IRQ that should be restored
NT)r   r   rB   r   )r   rC   r   r   _restore_irq_affinityZIrqPlugin._restore_irq_affinity   sB     W66>	g&?&?F"'r
   c                s   VP                   '       d   R# RVP                  ,          pTpV P                  P                  V P                  P	                  \        V4      4      4      pV P                  VP                  4      pV P                  P                  V P                  P	                  \        V4      4      4      pVR8X  d
   RV,           pVR8X  d   Wu8:  g   VR8X  d4   Wu8X  d.   \        P                  \        P                  WF3,          4       R# \        P                  \        P                  WHV3,          4       R# )zVerify IRQ affinity tuning

Args:
        irqinfo (IrqInfo): IRQ that should be verified
        affinity (set): desired affinity

Returns:
        status (bool): True if verification successful, False otherwise
TzIRQ %s affinityr$   z
subset of r   F)r   r   r&   Zcpulist2stringZcpulist_packrA   r>   r*   r   constsZSTR_VERIFY_PROFILE_VALUE_OKr,   ZSTR_VERIFY_PROFILE_VALUE_FAIL)	r   rC   r   r!   Zaffinity_descriptionZdesired_affinityZdesired_affinity_stringZcurrent_affinityZcurrent_affinity_strings	   &&&&     r   _verify_irq_affinityZIrqPlugin._verify_irq_affinity   s    
*W[[8 II44TYY5K5KDQaLb5cd++GKK8 II44TYY5K5KDQaLb5cd	[ *,CC{/C
em(<88F..67 8
99V117NOP Q
r
   r!   F)
per_deviceZpriorityc                sB    V'       g	   V'       d   Ve	   W n         R # R # R # r   )	_mode_val)r   enablingvalueverifyr4   r-   s   &&&&&&r   _modeZIrqPlugin._mode   s    &e/ >	 0&r
   r   T)rH   c                s   VR 8X  d   R MV\        R4      R pWpP                  9  d   \        P                  RV,          4       R# V P                  V,          pV'       dA   \	        V P
                  P                  V4      4      p	V P                  WV P                  4      # V'       dA   \	        V P
                  P                  V4      4      p	V P                  WV P                  4      # V P                  V4      # )r   r   NzUnknown device: %s)r(   r   r*   r,   r   r&   r'   rG   rI   rD   rE   )
r   rJ   rK   r   rL   r4   r-   r   rC   r   s
   &&&&&&&   r   	_affinityZIrqPlugin._affinity  s    y(	fSZ[.A#

99!F*+
JJsO'$))**5128

#
#Gt~~
FF$))**5128

"
"7dnn
EE

$
$W
--r
   )r   r   r   r   rI   i)r   r   r   r   Z__doc__r	   r   Zclassmethodr#   r.   r/   r1   r2   r3   r>   rB   rD   rE   rG   Zcommand_customrM   rN   r   r   Z__classcell__)r   r   s   @@r   r   r      s     $L.$  $*:F[&D(	#D EC8 9 -. .. .r
   r   )r    r    Z
decoratorsZtuned.constsrF   Z
tuned.logsZtunedr?   r   Zlogsr%   r*   Zobjectr   ZPluginr   r"   r
   r   <module>rO      sE         	jjnn f  }. }.r
   