a Á]›iGã@spddlmZddlTddlZddlmZddlmZddlm Z ddl Z ddl Z ej   ¡ZGdd„dejƒZdS) é)Úbase)Ú*éN)Ú exceptions)ÚcommandscsžeZdZdZ‡fdd„Zdd„Zdd„Zedd „ƒZd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zejfdd„Zdd„Zeddd�dd „ƒZ‡ZS)!Ú SystemdPlugina' Plug-in for tuning systemd options. The [option]`cpu_affinity` option allows setting CPUAffinity in `/etc/systemd/system.conf`. This configures the CPU affinity for the service manager as well as the default CPU affinity for all forked off processes. The option takes a comma-separated list of CPUs with optional CPU ranges specified by the minus sign (`-`). .Set the CPUAffinity for `systemd` to `0 1 2 3` ==== ---- [systemd] cpu_affinity=0-3 ---- ==== NOTE: These tunings are unloaded only on profile change followed by a reboot. cs@tj tj¡st dtj¡‚tt|ƒj |i|¤Žt ƒ|_ dS)NzERequired systemd '%s' configuration file not found, disabling plugin.) ÚosÚpathÚisfileÚconstsÚSYSTEMD_SYSTEM_CONF_FILErZNotSupportedPluginExceptionÚsuperrÚ__init__rÚ_cmd)ÚselfÚargsÚkwargs©Ú __class__©ú@/usr/lib/python3.9/site-packages/tuned/plugins/plugin_systemd.pyr"szSystemdPlugin.__init__cCsd|_d|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuning©rÚinstancerrrÚ_instance_init(szSystemdPlugin._instance_initcCsdS©NrrrrrÚ_instance_cleanup,szSystemdPlugin._instance_cleanupcCsddiS)NÚ cpu_affinityr)ÚclsrrrÚ_get_config_options/sÿz!SystemdPlugin._get_config_optionscCsB|dur>tjd|d|tjd�}|dur>|jdkr>| d¡SdS)Nú^\s*z \s*=\s*(.*)$©Úflagsr)ÚreÚsearchÚ MULTILINEÚ lastindexÚgroup)rÚconfÚkeyÚmorrrÚ _get_keyval5s  zSystemdPlugin._get_keyvalcCs|tjd|ddt|ƒ|tjd�\}}|dkrxz|ddkrF|d7}WntyZYn0||dt|ƒd7}|S|S) Nz^(\s*z\s*=).*$z\g<1>r réÿÿÿÿÚ ú=)r"ÚsubnÚstrr$Ú IndexError)rr'r(ÚvalZconf_newZnsubsrrrÚ _add_keyval=s(   zSystemdPlugin._add_keyvalcCstjd|dd|tjd�S)Nrz\s*=.*\nÚr )r"Úsubr$)rr'r(rrrÚ_del_keyIszSystemdPlugin._del_keycCs,|jjtjdd�}|dur(t d¡dS|S)N)Úerr_retz(error reading systemd configuration file)rÚ read_filer r ÚlogÚerror)rZsystemd_system_confrrrÚ_read_systemd_system_confLs  z'SystemdPlugin._read_systemd_system_confcCsptjtj}|j ||¡s8t d¡|jj|dd�dS|j |tj¡slt dtj¡|jj|dd�dSdS)Nz(error writing systemd configuration fileT)Úno_errorFz/error replacing systemd configuration file '%s') r r ZTMP_FILE_SUFFIXrÚ write_to_filer8r9ÚunlinkÚrename)rr'ZtmpfilerrrÚ_write_systemd_system_confSs  z(SystemdPlugin._write_systemd_system_confcCstj tj|j¡Sr)rr Újoinr ZPERSISTENT_STORAGE_DIRÚname)rrrrÚ_get_storage_filenameasz#SystemdPlugin._get_storage_filenamecCsl| ¡}|durh| ¡}|jj|ddd�}|j |¡|durN| |tj¡}n| |tj|¡}|  |¡dS)NT©r6r;) r:rBrr7r=r5r ÚSYSTEMD_CPUAFFINITY_VARr2r?)rr'ÚfnameÚcpu_affinity_savedrrrÚ_remove_systemd_tuningds z$SystemdPlugin._remove_systemd_tuningcCs0|tjkr,t dtj¡| ¡t d¡dS)Nz6removing '%s' systemd tuning previously added by TuneDz[you may need to manualy run 'dracut -f' to update the systemd configuration in initrd image)r Z ROLLBACK_FULLr8ÚinforDrGZconsole)rrZrollbackrrrÚ_instance_unapply_staticps z&SystemdPlugin._instance_unapply_staticcCs<|dur dSd dd„|j t ddt dd|¡¡¡Dƒ¡S)Nr3ú css|]}t|ƒVqdSr©r/©Ú.0ÚvrrrÚ zóz8SystemdPlugin._cpulist_convert_unpack..z\s+ú,z,\s+)r@rÚcpulist_unpackr"r4)rZcpulistrrrÚ_cpulist_convert_unpackwsz%SystemdPlugin._cpulist_convert_unpackrF)Z per_devicec Csúd}d}|j |j |j |¡¡¡}d dd„|j |¡Dƒ¡} | ¡} | durh| | t j ¡}|  |¡}|r||  d| ||¡S|rö|  ¡} |jj| ddd�} |durÄ| durÄ| |krÄ|jj| |dd�t dt j | t jf¡| | | t j | ¡¡dSdS) NrJcss|]}t|ƒVqdSrrKrLrrrrO�rPz)SystemdPlugin._cmdline..rTrC)Zmakedirz setting '%s' to '%s' in the '%s')rZunescapeZ _variablesÚexpandÚunquoter@rRr:r*r rDrSZ _verify_valuerBr7r<r8rHr r?r2) rZenablingÚvalueZverifyZignore_missingrZ conf_affinityZconf_affinity_unpackedrNZ v_unpackedr'rErFrrrÚ_cmdline|s& zSystemdPlugin._cmdline)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrÚ classmethodrr*r2r5r:r?rBrGr Z ROLLBACK_SOFTrIrSZcommand_customrWÚ __classcell__rrrrr s"     r)r3rZ decoratorsZ tuned.logsZtunedrZtuned.utils.commandsrZ tuned.constsr rr"ZlogsÚgetr8ZPluginrrrrrÚs