HEX
Server: LiteSpeed
System: Linux w5304130.sdnsbox.com 4.18.0-425.3.1.lve.el8.x86_64 #1 SMP Tue Nov 22 22:59:23 EST 2022 x86_64
User: makefitmeserver (1001)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/plugin_cpu.cpython-36.opt-1.pyc
3

]�beR�@s~ddlmZddlTddlZddlmZddljZddl	Z	ddl
Z
ddlZddlZddl
Z
ejj�ZdZGdd�dej�ZdS)	�)�base)�*�N)�commandsz$/sys/devices/system/cpu/cpu0/cpuidlecs�eZdZdZ�fdd�Zdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Z�fd d!�ZdW�fd#d$�	Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�ZdXd/d0�ZdYd1d2�Zd3d4�Zd5d6�Zd7d8�Ze d9d:d;�d<d=��Z!e"d9�dZd>d?��Z#d[dAdB�Z$e dCd:dDdE�dFdG��Z%e"dC�d\dHdI��Z&dJdK�Z'e dLd:d;�dMdN��Z(dOdP�Z)dQdR�Z*dSdT�Z+e"dL�d]dUdV��Z,�Z-S)^�CPULatencyPlugina�
	`cpu`::
	
	Sets the CPU governor to the value specified by the [option]`governor`
	option and dynamically changes the Power Management Quality of
	Service (PM QoS) CPU Direct Memory Access (DMA) latency according
	to the CPU load.
	
	`governor`:::
	The [option]`governor` option of the 'cpu' plug-in supports specifying
	CPU governors. Multiple governors are separated using '|'. The '|'
	character is meant to represent a logical 'or' operator. Note that the
	same syntax is used for the [option]`energy_perf_bias` option. *TuneD*
	will set the first governor that is available on the system.
	+    
	For example, with the following profile, *TuneD* will set the 'ondemand'
	governor, if it is available. If it is not available, but the 'powersave'
	governor is available, 'powersave' will be set. If neither of them are
	available, the governor will not be changed.
	+
	.Specifying a CPU governor
	====
	----
	[cpu]
	governor=ondemand|powersave
	----
	====
	
	`sampling_down_factor`:::
	The sampling rate determines how frequently the governor checks
	to tune the CPU. The [option]`sampling_down_factor` is a tunable
	that multiplies the sampling rate when the CPU is at its highest
	clock frequency thereby delaying load evaluation and improving
	performance. Allowed values for sampling_down_factor are 1 to 100000.
	+
	.The recommended setting for jitter reduction
	====
	----
	[cpu]
	sampling_down_factor = 100
	----
	====
	
	`energy_perf_bias`:::
	[option]`energy_perf_bias` supports managing energy
	vs. performance policy via x86 Model Specific Registers using the
	`x86_energy_perf_policy` tool. Multiple alternative Energy Performance
	Bias (EPB) values are supported. The alternative values are separated
	using the '|' character. The following EPB values are supported
	starting with kernel 4.13: "performance", "balance-performance",
	"normal", "balance-power" and "power".
	+
	.Specifying alternative Energy Performance Bias values
	====
	----
	[cpu]
	energy_perf_bias=powersave|power
	----
	
	*TuneD* will try to set EPB to 'powersave'. If that fails, it will
	try to set it to 'power'.
	====
	
	`latency_low, latency_high, load_threshold`:::
	+
	If the CPU load is lower than the value specified by
	the[option]`load_threshold` option, the latency is set to the value
	specified either by the [option]`latency_high` option or by the
	[option]`latency_low` option.
	+
	`force_latency`:::
	You can also force the latency to a specific value and prevent it from
	dynamically changing further. To do so, set the [option]`force_latency`
	option to the required latency value.
	+
	The maximum latency value can be specified in several ways:
	+
	 * by a numerical value in microseconds (for example, `force_latency=10`)
	 * as the kernel CPU idle level ID of the maximum C-state allowed
	   (for example, force_latency = cstate.id:1)
	 * as a case sensitive name of the maximum C-state allowed
	   (for example, force_latency = cstate.name:C1)
	 * by using 'None' as a fallback value to prevent errors when alternative
	   C-state IDs/names do not exist. When 'None' is used in the alternatives
	   pipeline, all the alternatives that follow 'None' are ignored.
	+
	It is also possible to specify multiple fallback values separated by '|' as
	the C-state names and/or IDs may not be available on some systems.
	+
	.Specifying fallback C-state values
	====
	----
	[cpu]
	force_latency=cstate.name:C6|cstate.id:4|10
	----
	This configuration tries to obtain and set the latency of C-state named C6.
	If the C-state C6 does not exist, kernel CPU idle level ID 4 (state4) latency
	is searched for in sysfs. Finally, if the state4 directory in sysfs is not found,
	the last latency fallback value is `10` us. The value is encoded and written into
	the kernel's PM QoS file `/dev/cpu_dma_latency`.
	====
	+
	.Specifying fallback C-state values using 'None'.
	====
	----
	[cpu]
	force_latency=cstate.name:XYZ|None
	----
	In this case, if C-state with the name `XYZ` does not exist
	[option]`force_latency`, no latency value will be written into the
	kernel's PM QoS file, and no errors will be reported due to the
	presence of 'None'.
	====
	
	`min_perf_pct, max_perf_pct, no_turbo`:::
	These options set the internals of the Intel P-State driver exposed via the kernel's
	`sysfs` interface.
	+
	.Adjusting the configuration of the Intel P-State driver
	====
	----
	[cpu]
	min_perf_pct=100
	----
	Limit the minimum P-State that will be requested by the driver. It states
	it as a percentage of the max (non-turbo) performance level.
	====
	cs`tt|�j||�d|_d|_d|_d|_d|_d|_d|_	d|_
d|_d|_i|_
t�|_dS)NT�x86_64F)�superr�__init__�_has_pm_qos�_archZ_is_x86�	_is_intel�_is_amd�_has_energy_perf_bias�_has_intel_pstate�_min_perf_pct_save�_max_perf_pct_save�_no_turbo_save�_governors_mapr�_cmd)�self�args�kwargs)�	__class__�� /usr/lib/python3.6/plugin_cpu.pyr	�szCPULatencyPlugin.__init__cCs>d|_t�|_x"|jjd�D]}|jj|j�qWt�|_dS)NT�cpu)Z_devices_supported�setZ
_free_devices�_hardware_inventoryZget_devices�addZsys_nameZ_assigned_devices)r�devicerrr�
_init_devices�s
zCPULatencyPlugin._init_devicescs�fdd�|D�S)Ncsg|]}�jjd|��qS)r)rZ
get_device)�.0�x)rrr�
<listcomp>�sz8CPULatencyPlugin._get_device_objects.<locals>.<listcomp>r)rZdevicesr)rr�_get_device_objects�sz$CPULatencyPlugin._get_device_objectscCsddddddddddd�
S)Ng�������?�di�)
�load_threshold�latency_low�latency_high�
force_latency�governor�sampling_down_factor�energy_perf_bias�min_perf_pct�max_perf_pct�no_turbor)rrrr�_get_config_options�sz$CPULatencyPlugin._get_config_optionscCs�dddddg}tj�|_|j|krttj�}|jjd�}|dkrFd|_n|d	ksV|d
kr^d|_nd|_t	j
d|�nt	j
d|j�|jdkr�|j�|j�dS)
NrZi686Zi585Zi486Zi386Z	vendor_idZGenuineIntelTZAuthenticAMDZHygonGenuinez$We are running on an x86 %s platformzWe are running on %s (non x86))
�platform�machiner�procfsZcpuinfoZtags�getrr
�log�info�_check_energy_perf_bias�_check_intel_pstate)rZintel_archsrZvendorrrr�_check_arch�s


zCPULatencyPlugin._check_archcCsbd|_d}|jjddgtj|gd�\}}|dkr@|dkr@d|_n|dkrTtjd	�n
tjd
�dS)NFr�x86_energy_perf_policyz-r)Z	no_errorsr�Tzgunable to run x86_energy_perf_policy tool, ignoring CPU energy performance bias, is the tool installed?zXyour CPU doesn't support MSR_IA32_ENERGY_PERF_BIAS, ignoring CPU energy performance bias)rr�execute�errno�ENOENTr5Zwarning)rZretcode_unsupported�retcode�outrrrr7�sz(CPULatencyPlugin._check_energy_perf_biascCs"tjjd�|_|jrtjd�dS)Nz$/sys/devices/system/cpu/intel_pstatezintel_pstate detected)�os�path�existsrr5r6)rrrrr8�sz$CPULatencyPlugin._check_intel_pstatecCs t|�}|jjt|�jdd��S)Nrr;)�strrZ
is_cpu_online�replace)rrZsdrrr�_is_cpu_online�szCPULatencyPlugin._is_cpu_onlinecCstjjd|�S)Nz3/sys/devices/system/cpu/%s/cpufreq/scaling_governor)rArBrC)rrrrr�_cpu_has_scaling_governor�sz*CPULatencyPlugin._cpu_has_scaling_governorcCs<|j|�stjd|�dS|j|�s8tjd|�dSdS)Nz'%s' is not online, skippingFz.there is no scaling governor fo '%s', skippingT)rFr5�debugrG)rrrrr�_check_cpu_can_change_governor�s

z/CPULatencyPlugin._check_cpu_can_change_governorcCs�d|_d|_t|jj��d|kr�d|_ytjtj	tj
�|_Wn*tk
rht
jdtj	�d|_YnXd|_|jddkr�|jjdd�|_d|_nd|_|j�nd|_t
jd|j�yt|j�d|_Wntk
r�d|_YnXdS)NTFrz-Unable to open '%s', disabling PM_QoS controlr)�loadzILatency settings from non-first CPU plugin instance '%s' will be ignored.)Z_has_static_tuningZ_has_dynamic_tuning�listZ
_instances�values�_first_instancerA�open�constsZPATH_CPU_DMA_LATENCY�O_WRONLY�_cpu_latency_fd�OSErrorr5�errorr
�_latency�options�_monitors_repositoryZcreate�
_load_monitorr9r6�nameZassigned_devices�
_first_device�
IndexError)r�instancerrr�_instance_init�s*
zCPULatencyPlugin._instance_initcCs4|jr0|jrtj|j�|jdk	r0|jj|j�dS)N)rMr
rA�closerQrWrV�delete)rr[rrr�_instance_cleanups

z"CPULatencyPlugin._instance_cleanupcCs|jjd|d�j�S)Nz'/sys/devices/system/cpu/intel_pstate/%s)r�	read_file�strip)r�attrrrr�_get_intel_pstate_attr"sz'CPULatencyPlugin._get_intel_pstate_attrcCs|dk	r|jjd||�dS)Nz'/sys/devices/system/cpu/intel_pstate/%s)r�
write_to_file)rrb�valrrr�_set_intel_pstate_attr%sz'CPULatencyPlugin._set_intel_pstate_attrcCs&|dkrdS|j|�}|j||�|S)N)rcrf)rrb�value�vrrr�_getset_intel_pstate_attr)s

z*CPULatencyPlugin._getset_intel_pstate_attrcs�tt|�j|�|jsdS|jj|jd�}|dk	r>|j|�|jr�|jj|jd�}|j	d|�|_
|jj|jd�}|j	d|�|_|jj|jd�}|j	d|�|_dS)Nr)r-r.r/)
rr�_instance_apply_staticrMZ
_variables�expandrU�_set_latencyrrirrr)rr[Zforce_latency_valueZ	new_value)rrrrj0s(


z'CPULatencyPlugin._instance_apply_staticFcsLtt|�j||�|jrH|jrH|jd|j�|jd|j�|jd|j�dS)Nr-r.r/)	rr�_instance_unapply_staticrMrrfrrr)rr[Z
full_rollback)rrrrmHs
z)CPULatencyPlugin._instance_unapply_staticcCs|j||�dS)N)�_instance_update_dynamic)rr[rrrr�_instance_apply_dynamicPsz(CPULatencyPlugin._instance_apply_dynamiccCsP||jkrdS|jj�d}||jdkr<|j|jd�n|j|jd�dS)N�systemr&r(r')rYrWZget_loadrUrl)rr[rrJrrrrnSs
z)CPULatencyPlugin._instance_update_dynamiccCsdS)Nr)rr[rrrr�_instance_unapply_dynamic^sz*CPULatencyPlugin._instance_unapply_dynamiccCs&yt|�Sttfk
r dSXdS)N)�int�
ValueError�	TypeError)r�srrr�_str2intaszCPULatencyPlugin._str2intcCs�i|_xztjt�D]l}td|}|jj|dddd�}|jj|dddd�}|dk	r|dk	r|j|�}|dk	r||j|j�<qWdS)Nz/%s/rXT)�err_ret�no_error�latency)�cstates_latencyrA�listdir�cpuidle_states_pathrr`rvra)r�dZcstate_pathrXryrrr�_read_cstates_latencygs
z&CPULatencyPlugin._read_cstates_latencycCshtjd|�|jdkr*tjd�|j�|jj|d�}|rR|dkrRtjd�dStjdt|��|S)Nz)getting latency for cstate with name '%s'zreading cstates latency tablerz"skipping latency 0 as set by paramz!cstate name mapped to latency: %s)r5rHrzr~r4rD)rrX�no_zeroryrrr�_get_latency_by_cstate_namers


z,CPULatencyPlugin._get_latency_by_cstate_namecCs�tjdt|��|j|�}|dkr2tjd�dStdd|}|j|jj|ddd��}|rt|dkrttjd�dStjd	t|��|S)
Nz'getting latency for cstate with ID '%s'zcstate ID is invalidz/%s/latencyzstate%dT)rwrxrz"skipping latency 0 as set by paramzcstate ID mapped to latency: %s)r5rHrDrvr|rr`)rZlidrZlatency_pathryrrr�_get_latency_by_cstate_id~s


z*CPULatencyPlugin._get_latency_by_cstate_idcCs:d|_t|�jd�}tjd��x|D�]}yt|�}tjd|�Wn�tk
�r"|dd�dkr�|j|dd�dd�}n�|dd	�d
kr�|j|d	d��}nz|dd�dkr�|j|dd�dd�}nR|dd
�dkr�|j|d
d��}n.|dk�rtjd�dSd}tjdt|��YnX|dk	r&Pq&W|dfS)N�|zparsing latencyz+parsed directly specified latency value: %dr�zcstate.id_no_zero:T)r�
z
cstate.id:�zcstate.name_no_zero:�zcstate.name:�none�Nonezlatency 'none' specifiedzinvalid latency specified: '%s'F)r�r�)NT)	rzrD�splitr5rHrrrsr�r�)rryZ	latenciesrrr�_parse_latency�s0


zCPULatencyPlugin._parse_latencycCsp|j|�\}}|rl|jrl|dkr4tjd�d|_n8|j|krltjd|�tjd|�}tj	|j
|�||_dS)Nztunable to evaluate latency value (probably wrong settings in the 'cpu' section of current profile), disabling PM QoSFzsetting new cpu latency %d�i)r�r
r5rSrTr6�struct�packrA�writerQ)rry�skipZlatency_binrrrrl�s

zCPULatencyPlugin._set_latencycCs|jjd|�j�j�S)Nz>/sys/devices/system/cpu/%s/cpufreq/scaling_available_governors)rr`rar�)rrrrr�_get_available_governors�sz)CPULatencyPlugin._get_available_governorsr*T)�
per_devicecCs�|j|�sdSt|�}|jd�}dd�|D�}x&|D]}t|�dkr4tjd�dSq4W|j|�}xn|D]N}||kr�|s�tjd||f�|jj	d||�Pqf|sftj
d||f�qfWtjd	d
j|��d}|S)Nr�cSsg|]}|j��qSr)ra)r!r*rrrr#�sz2CPULatencyPlugin._set_governor.<locals>.<listcomp>rz.The 'governor' option contains an empty value.z!setting governor '%s' on cpu '%s'z3/sys/devices/system/cpu/%s/cpufreq/scaling_governorz7Ignoring governor '%s' on cpu '%s', it is not supportedz.None of the scaling governors is supported: %sz, )
rIrDr��lenr5rSr�r6rrdrH�warn�join)rZ	governorsr�simr*Zavailable_governorsrrr�
_set_governor�s2






zCPULatencyPlugin._set_governorcCsTd}|j|�sdS|jjd||d�j�}t|�dkr:|}|dkrPtjd|�|S)Nz3/sys/devices/system/cpu/%s/cpufreq/scaling_governor)rxrz*could not get current governor on cpu '%s')rIrr`rar�r5rS)rr�ignore_missingr*�datarrr�
_get_governor�s
zCPULatencyPlugin._get_governor�ondemandcCsd|S)Nz7/sys/devices/system/cpu/cpufreq/%s/sampling_down_factorr)rr*rrr�_sampling_down_factor_path�sz+CPULatencyPlugin._sampling_down_factor_pathr+r�)r�ZprioritycCs�d}||jkr|jj�d|j|<|j|�}|dkrFtjd|�dS|t|jj��kr�||j|<|j|�}tj	j
|�s�tjd||f�dSt|�}|s�tjd||f�|j
j||�|S)NzIignoring sampling_down_factor setting for CPU '%s', cannot match governorzTignoring sampling_down_factor setting for CPU '%s', governor '%s' doesn't support itz6setting sampling_down_factor to '%s' for governor '%s')r�clearr�r5rHrKrLr�rArBrCrDr6rrd)rr+rr�rer*rBrrr�_set_sampling_down_factor�s&





z*CPULatencyPlugin._set_sampling_down_factorcCsD|j||d�}|dkrdS|j|�}tjj|�s4dS|jj|�j�S)N)r�)r�r�rArBrCrr`ra)rrr�r*rBrrr�_get_sampling_down_factors
z*CPULatencyPlugin._get_sampling_down_factorcCs*|jjdd|t|�gdd�\}}}||fS)Nr:z-cT)Z
return_err)rr<rD)r�cpu_idrgr?r@�err_msgrrr�_try_set_energy_perf_bias
sz*CPULatencyPlugin._try_set_energy_perf_biasr,c	Cs�|j|�stjd|�dS|jr�|s�|jd�}|jd�}x�|D]x}|j�}tjd||f�|j||�\}}|dkr�tjd||f�Pq@|dkr�tj	d|�Pq@tjd||f�q@Wtj	d	|�t
|�SdSdS)
Nz%s is not online, skippingrr�z2Trying to set energy_perf_bias to '%s' on cpu '%s'rz5energy_perf_bias successfully set to '%s' on cpu '%s'z"Failed to set energy_perf_bias: %szHCould not set energy_perf_bias to '%s' on cpu '%s', trying another valuezPFailed to set energy_perf_bias on cpu '%s'. Is the value in the profile correct?)rFr5rHr�lstripr�rar�r6rSrD)	rr,rr�r��valsrer?r�rrr�_set_energy_perf_biass6



z&CPULatencyPlugin._set_energy_perf_biascCsjyt|�}WnXtk
rd}z<yt|d�}Wn&tk
rR}z
|}WYdd}~XnXWYdd}~XnX|S)N�)rrrs)rrurh�errr�_try_parse_num4s(zCPULatencyPlugin._try_parse_numcCsdddd�j|j|�|�S)N�performance�normalZ	powersave)r��)r4r�)rrurrr�_energy_perf_policy_to_human?sz-CPULatencyPlugin._energy_perf_policy_to_humancCsdddddd�j|j|�|�S)Nr�zbalance-performancer�z
balance-powerZpower)r�r��r�)r4r�)rrurrr�_energy_perf_policy_to_human_v2Csz0CPULatencyPlugin._energy_perf_policy_to_human_v2c	Cs�d}|j|�s tjd|�dS|jr�|jd�}|jjdd|dg�\}}|dkr�xR|j�D]F}|j�}t	|�dkr�|j
|d�}PqZt	|�d	krZ|j|d�}PqZW|S)
Nz%s is not online, skippingrr:z-cz-rr�r�)rFr5rHrr�rr<�
splitlinesr�r�r�r�)	rrr�r,r�r?�lines�line�lrrr�_get_energy_perf_biasKs"

z&CPULatencyPlugin._get_energy_perf_bias)F)F)F)F)r�)F)F).�__name__�
__module__�__qualname__�__doc__r	r r$�classmethodr0r9r7r8rFrGrIr\r_rcrfrirjrmrornrqrvr~r�r�r�rlr�Zcommand_setr�Zcommand_getr�r�r�r�r�r�r�r�r�r��
__classcell__rr)rrrsV		


		!r)r;rZ
decoratorsZ
tuned.logsZtunedZtuned.utils.commandsrZtuned.constsrOrAr�r=r1r3Zlogsr4r5r|ZPluginrrrrr�<module>s