a ”ˆ«hè&ã@shddlmZddlTddlmZddlZddlZddlZej   ¡Z Gdd„de ƒZ Gdd„dejƒZdS) é)Úhotplug)Ú*éNc@seZdZdd„ZdS)ÚIrqInfocCs ||_d||_d|_d|_dS)Nzirq%sF)ÚirqÚdeviceÚ unchangeableÚoriginal_affinity)Úselfr©r ú`, where `` 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 s(tt|ƒ ||||||||¡i|_dS©N)Úsuperrr Ú_irqs) r Zmonitor_repositoryZstorage_factoryZhardware_inventoryZdevice_matcherZdevice_matcher_udevZplugin_instance_factoryZ global_cfgZ variables©Ú __class__r r r :szIrqPlugin.__init__cCs’d|_tƒ|_tƒ|_t d¡D]F}tj d|¡}tj |¡r |  ¡r t |ƒ}||j |<|j  |j ¡q t dƒ}d|_ ||j d<|j  |j ¡dS)z$Read /proc/irq to collect devices Tz /proc/irqÚDEFAULTN)Z_devices_supportedÚsetZ _free_devicesZ_assigned_devicesÚosÚlistdirÚpathÚjoinÚisdirÚisdigitrrÚaddr)r ÚiÚpÚinfoZ default_infor r r Ú _init_devicesAs  zIrqPlugin._init_devicescCs dddœS)NÚr)ÚaffinityÚmoder )Úclsr r r Ú_get_config_optionsSsþzIrqPlugin._get_config_optionscCs¸d|_d|_|j |j d¡¡}|j |¡}t|  ¡ƒdkrTt   d|j ¡d|_ n&t|ƒdkrzt  d|j |f¡d|_ |j |j d¡¡}|dvr´t  d ||j f¡d |jd<dS) NTFr%rz;Instance '%s' configured with empty affinity. Deactivating.z7Instance '%s' with invalid affinity '%s'. Deactivating.r&)rÚ intersectzOInvalid operating mode '%s' for instance '%s'. Using the default 'set' instead.r)Z_has_static_tuningZ_has_dynamic_tuningZ _variablesÚexpandÚoptionsÚgetÚ_cmdÚcpulist_unpackÚlenÚstripÚlogr"ÚnameÚ_activeÚerror)r Úinstancer%Z affinity_listr&r r r Ú_instance_init]s   ÿzIrqPlugin._instance_initcCsdSrr ©r r5r r r Ú_instance_cleanuprszIrqPlugin._instance_cleanupcs$t d|j¡tt|ƒ |¡dS)NzApplying IRQ affinities (%s))r1Údebugr2rrÚ_instance_apply_staticr7rr r r:usz IrqPlugin._instance_apply_staticcs&t d|j¡tt|ƒ ||¡dS)NzUnapplying IRQ affinities (%s))r1r9r2rrÚ_instance_unapply_static)r r5Zrollbackrr r r;ysz"IrqPlugin._instance_unapply_staticcs$t d|j¡tt|ƒ |||¡S)NzVerifying IRQ affinities (%s))r1r9r2rrÚ_instance_verify_static)r r5Úignore_missingZdevicesrr r r<}sz!IrqPlugin._instance_verify_staticc Cs¢z\|dkrdnd|}t|dƒ}| ¡ ¡}Wdƒn1sB0Yt|j |¡ƒWSttfyœ}z$t  d||f¡tƒWYd}~Sd}~00dS)zú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_affinityÚrNz)Failed to read SMP affinity of IRQ %s: %s) ÚopenÚreadliner0rr-Z hex2cpulistÚOSErrorÚIOErrorr1r9)r rÚfilenameÚfÚ affinity_hexÚer r r Ú_get_irq_affinity„s  *zIrqPlugin._get_irq_affinityc Csözp|j t|ƒ¡}t d||f¡|dkr0dnd|}t|dƒ}| |¡Wdƒn1sb0YWdSttfyð}zdt |dƒrº|j t j krº|sºt d |¡WYd}~d St  d |||f¡WYd}~d SWYd}~n d}~00dS) aDSet 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 %s to '%s'rr>r?ÚwNrÚerrnoz/Setting SMP affinity of IRQ %s is not supportedéþÿÿÿz0Failed to set SMP affinity of IRQ %s to '%s': %séÿÿÿÿ) r-Z cpulist2hexÚlistr1r9rAÚwriterCrDÚhasattrrKZEIOr4)r rr%Z restoringrGrErFrHr r r Ú_set_irq_affinity—s  (zIrqPlugin._set_irq_affinitycCsn| |j¡}|dkr ||@p|}|js.||kr2dS| |j|d¡}|dkr\|jdurj||_n|dkrjd|_dS)zxApply IRQ affinity tuning Args: irqinfo (IrqInfo): IRQ that should be tuned affinity (set): desired affinity r)NFrrLT)rIrrrQr )r Úirqinfor%r&ÚoriginalÚresr r r Ú_apply_irq_affinity¹s   zIrqPlugin._apply_irq_affinitycCs0|js|jdurdS| |j|jd¡d|_dS)zRRestore IRQ affinity Args: irqinfo (IrqInfo): IRQ that should be restored NT)rr rQr)r rRr r r Ú_restore_irq_affinityÍszIrqPlugin._restore_irq_affinityc Csº|jr dSd|j}|}|j |j t|ƒ¡¡}| |j¡}|j |j t|ƒ¡¡}|dkrdd|}|dkrt||ks„|dkrœ||krœt t j ||f¡dSt  t j |||f¡dSdS)zËVerify IRQ affinity tuning Args: irqinfo (IrqInfo): IRQ that should be verified affinity (set): desired affinity Returns: status (bool): True if verification successful, False otherwise TzIRQ %s affinityr)z subset of rFN) rrr-Zcpulist2stringZ cpulist_packrNrIr1r"ÚconstsZSTR_VERIFY_PROFILE_VALUE_OKr4ZSTR_VERIFY_PROFILE_VALUE_FAIL) r rRr%r&Zaffinity_descriptionZdesired_affinityZdesired_affinity_stringZcurrent_affinityZcurrent_affinity_stringr r r Ú_verify_irq_affinityØs,   ÿÿÿÿzIrqPlugin._verify_irq_affinityr&Fiöÿÿÿ)Ú per_deviceÚprioritycCs|s|r|dur||_dSr)Ú _mode_val)r ÚenablingÚvalueÚverifyr=r5r r r Ú_modeúszIrqPlugin._moder%T)rYc Cs˜|dkr dn|tdƒd…}||jvr8t d|¡dS|j|}|rft|j |¡ƒ} | || |j¡S|rŠt|j |¡ƒ} |  || |j¡S|  |¡SdS)NrrzUnknown device: %s) r/rr1r4rr-r.rXr[rUrV) r r\r]rr^r=r5rrRr%r r r Ú _affinitys  zIrqPlugin._affinity)rrrÚ__doc__r r#Ú classmethodr(r6r8r:r;r<rIrQrUrVrXZcommand_customr_r`Ú __classcell__r r rr rs&&     " "   r)r$rZ decoratorsZ tuned.constsrWZ tuned.logsZtunedrKrZlogsr,r1ÚobjectrZPluginrr r r r Ús