a hG@spddlmZddlTddlZddlmZddlmZddlm Z ddl Z ddl Z ej ZGdddejZdS) )base)*N) exceptions)commandscseZdZdZfddZddZddZedd Zd d Z d d Z ddZ ddZ ddZ ddZddZejfddZddZeddddd ZZS)! 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@tjtjstdtjtt|j |i|t |_ dS)NzERequired systemd '%s' configuration file not found, disabling plugin.) ospathisfileconstsSYSTEMD_SYSTEM_CONF_FILErZNotSupportedPluginExceptionsuperr__init__r_cmd)selfargskwargs __class__@/usr/lib/python3.9/site-packages/tuned/plugins/plugin_systemd.pyr"szSystemdPlugin.__init__cCsd|_d|_dS)NFT)Z_has_dynamic_tuningZ_has_static_tuningrinstancerrr_instance_init(szSystemdPlugin._instance_initcCsdSNrrrrr_instance_cleanup,szSystemdPlugin._instance_cleanupcCsddiS)N cpu_affinityr)clsrrr_get_config_options/sz!SystemdPlugin._get_config_optionscCsB|dur>tjd|d|tjd}|dur>|jdkr>|dSdS)N^\s*z \s*=\s*(.*)$flagsr)research MULTILINE lastindexgroup)rconfkeymorrr _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"subnstrr$ IndexError)rr'r(valZconf_newZnsubsrrr _add_keyval=s(   zSystemdPlugin._add_keyvalcCstjd|dd|tjdS)Nrz\s*=.*\nr )r"subr$)rr'r(rrr_del_keyIszSystemdPlugin._del_keycCs,|jjtjdd}|dur(tddS|S)N)err_retz(error reading systemd configuration file)r read_filer r logerror)rZsystemd_system_confrrr_read_systemd_system_confLs  z'SystemdPlugin._read_systemd_system_confcCsptjtj}|j||s8td|jj|dddS|j|tjsltdtj|jj|dddSdS)Nz(error writing systemd configuration fileT)no_errorFz/error replacing systemd configuration file '%s') r r ZTMP_FILE_SUFFIXr write_to_filer8r9unlinkrename)rr'Ztmpfilerrr_write_systemd_system_confSs  z(SystemdPlugin._write_systemd_system_confcCstjtj|jSr)rr joinr ZPERSISTENT_STORAGE_DIRname)rrrr_get_storage_filenameasz#SystemdPlugin._get_storage_filenamecCsl|}|durh|}|jj|ddd}|j||durN||tj}n||tj|}| |dS)NTr6r;) r:rBrr7r=r5r SYSTEMD_CPUAFFINITY_VARr2r?)rr'fnamecpu_affinity_savedrrr_remove_systemd_tuningds z$SystemdPlugin._remove_systemd_tuningcCs0|tjkr,tdtj|tddS)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_FULLr8inforDrGZconsole)rrZrollbackrrr_instance_unapply_staticps z&SystemdPlugin._instance_unapply_staticcCs<|dur dSddd|jtddtdd|DS)Nr3 css|]}t|VqdSrr/.0vrrr zz8SystemdPlugin._cpulist_convert_unpack..z\s+,z,\s+)r@rcpulist_unpackr"r4)rZcpulistrrr_cpulist_convert_unpackwsz%SystemdPlugin._cpulist_convert_unpackrF)Z per_devicec Csd}d}|j|j|j|}ddd|j|D} |} | durh|| t j }| |}|r|| d| ||S|r| } |jj| ddd} |dur| dur| |kr|jj| |ddtdt j | t jf||| t j | dSdS) NrJcss|]}t|VqdSrrKrLrrrrOrPz)SystemdPlugin._cmdline..rTrC)Zmakedirz setting '%s' to '%s' in the '%s')rZunescapeZ _variablesexpandunquoter@rRr:r*r rDrSZ _verify_valuerBr7r<r8rHr r?r2) rZenablingvalueZverifyZignore_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"Zlogsgetr8ZPluginrrrrrs