a ]iG @ sp d dl mZ d dlT ddlZd dl mZ ddlmZ ddlm Z ddl Z ddlZej ZG dd dejZdS ) )base)* N) exceptions)commandsc s e Zd ZdZ fddZdd Zdd Zedd Zd d Z dd Z dd Zdd Zdd Z dd Zdd ZejfddZdd Zeddddd 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. c s@ t jtjstdtj tt| j |i | t | _d S )NzERequired systemd '%s' configuration file not found, disabling plugin.)ospathisfileconstsSYSTEMD_SYSTEM_CONF_FILEr ZNotSupportedPluginExceptionsuperr __init__r _cmd)selfargskwargs __class__ @/usr/lib/python3.9/site-packages/tuned/plugins/plugin_systemd.pyr " s zSystemdPlugin.__init__c C s d|_ d|_d S )NFT)Z_has_dynamic_tuningZ_has_static_tuningr instancer r r _instance_init( s zSystemdPlugin._instance_initc C s d S Nr r r r r _instance_cleanup, s zSystemdPlugin._instance_cleanupc C s dd iS )Ncpu_affinityr )clsr r r _get_config_options/ s z!SystemdPlugin._get_config_optionsc C sB |d ur>t jd| d |t jd}|d ur>|jdkr>|dS d S )N^\s*z\s*=\s*(.*)$flagsr )research MULTILINE lastindexgroup)r confkeymor r r _get_keyval5 s zSystemdPlugin._get_keyvalc C s| t jd| d dt| |t jd\}}|dk rxz|d dkrF|d7 }W n tyZ Y n0 ||d t| d 7 }|S |S ) Nz^(\s*z\s*=).*$z\g<1>r r =)r" subnstrr$ IndexError)r r' r( valZconf_newZnsubsr r r _add_keyval= s (zSystemdPlugin._add_keyvalc C s t jd| d d|t jdS )Nr z\s*=.*\n r )r" subr$ )r r' r( r r r _del_keyI s zSystemdPlugin._del_keyc C s, | j jtjd d}|d u r(td d S |S )N)err_retz(error reading systemd configuration file)r read_filer r logerror)r Zsystemd_system_confr r r _read_systemd_system_confL s z'SystemdPlugin._read_systemd_system_confc C sp t jt j }| j||s8td | jj|dd dS | j|t jsltdt j | jj|dd dS dS )Nz(error writing systemd configuration fileT)no_errorFz/error replacing systemd configuration file '%s') r r ZTMP_FILE_SUFFIXr write_to_filer8 r9 unlinkrename)r r' Ztmpfiler r r _write_systemd_system_confS s z(SystemdPlugin._write_systemd_system_confc C s t jtj| jS r )r r joinr ZPERSISTENT_STORAGE_DIRname)r r r r _get_storage_filenamea s z#SystemdPlugin._get_storage_filenamec C sl | }|d urh| }| jj|d dd}| j| |d u rN| |tj}n| |tj|}| | d S )NTr6 r; ) r: rB r r7 r= r5 r SYSTEMD_CPUAFFINITY_VARr2 r? )r r' fnamecpu_affinity_savedr r r _remove_systemd_tuningd s z$SystemdPlugin._remove_systemd_tuningc C s0 |t jkr,tdt j | td d S )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 inforD rG Zconsole)r r Zrollbackr r r _instance_unapply_staticp s z&SystemdPlugin._instance_unapply_staticc C s<