3 d?d@dAZ%e&d=dpdBdCZ'dqdEdFZ(e$dGd>dHdIdJdKZ)e&dGdrdLdMZ*dNdOZ+dsdPdQZ,dRdSZ-e$dTd>d?dUdVZ.dWdXZ/dYdZZ0d[d\Z1e&dTdtd]d^Z2d_d`Z3dadbZ4e$dcd>d?dddeZ5e&dcdudfdgZ6e$dhd>d?didjZ7e&dhdvdkdlZ8Z9S)wCPULatencyPlugina `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". On newer processors is value writen straight to file (see rhbz#2095829) + .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'. ==== `energy_performance_preference`::: [option]`energy_performance_preference` supports managing energy vs. performance hints on newer Intel and AMD processors with active P-State CPU scaling drivers (intel_pstate or amd-pstate). Multiple alternative Energy Performance Preferences (EPP) values are supported. The alternative values are separated using the '|' character. Available values can be found in `energy_performance_available_preferences` file in `CPUFreq` policy directory in `sysfs`. in + .Specifying alternative Energy Performance Hints values ==== ---- [cpu] energy_performance_preference=balance_power|power ---- *TuneD* will try to set EPP to 'balance_power'. 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. ==== + `pm_qos_resume_latency_us`::: This option allow to set specific latency for all cpus or specific ones. ==== ---- [cpu] pm_qos_resume_latency_us=n/a ---- Special value that disables C-states completely. ==== ---- [cpu] pm_qos_resume_latency_us=0 ---- Allows all C-states. ==== ---- [cpu] pm_qos_resume_latency_us=100 ---- Allows any C-state with a resume latency less than value. csrtt|j||d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_i|_t|_d|_dS)NTx86_64F)superr__init__ _has_pm_qos_archZ_is_x86 _is_intel_is_amd_has_energy_perf_bias_has_intel_pstate_has_amd_pstate_has_pm_qos_resume_latency_us_min_perf_pct_save_max_perf_pct_save_no_turbo_save_governors_mapr_cmd_flags)selfargskwargs) __class__ /usr/lib/python3.6/plugin_cpu.pyr s zCPULatencyPlugin.__init__cCs>d|_t|_x"|jjdD]}|jj|jqWt|_dS)NTcpu)Z_devices_supportedsetZ _free_devices_hardware_inventoryZ get_devicesaddZsys_nameZ_assigned_devices)rdevicerrr _init_devicess zCPULatencyPlugin._init_devicescsfdd|DS)Ncsg|]}jjd|qS)r)r Z get_device).0x)rrr sz8CPULatencyPlugin._get_device_objects..r)rZdevicesr)rr_get_device_objectssz$CPULatencyPlugin._get_device_objectsc Csddddddddddddd S)Ng?di) load_threshold latency_low latency_high force_latencygovernorsampling_down_factorenergy_perf_bias min_perf_pct max_perf_pctno_turbopm_qos_resume_latency_usenergy_performance_preferencer)rrrr_get_config_optionssz$CPULatencyPlugin._get_config_optionscCsdddddg}tj|_|j|krttj}|jjd}|dkrFd|_n|d ksV|d kr^d|_nd|_t j d |nt j d |j|jr|j |j |jr|j dS) NrZi686Zi585Zi486Zi386Z vendor_idZ GenuineIntelTZ AuthenticAMDZ HygonGenuinez$We are running on an x86 %s platformzWe are running on %s (non x86))platformmachiner procfscpuinfotagsgetr r loginfo_check_energy_perf_bias_check_intel_pstate_check_amd_pstate)rZ intel_archsrZvendorrrr _check_archs"   zCPULatencyPlugin._check_archcCsbd|_d}|jjddgtj|gd\}}|dkr@|dkr@d|_n|dkrTtjd n tjd dS) NFrx86_energy_perf_policyz-r)Z no_errorsrTzgunable 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)rrexecuteerrnoENOENTr<warning)rZretcode_unsupportedretcodeoutrrrr>s z(CPULatencyPlugin._check_energy_perf_biascCs"tjjd|_|jrtjddS)Nz$/sys/devices/system/cpu/intel_pstatezintel_pstate detected)ospathexistsrr<r=)rrrrr?sz$CPULatencyPlugin._check_intel_pstatecCs"tjjd|_|jrtjddS)Nz"/sys/devices/system/cpu/amd_pstatezamd-pstate detected)rJrKrLrr<r=)rrrrr@#sz"CPULatencyPlugin._check_amd_pstatecCs$|jdkrtjjjdg|_|jS)Nflags)rr8r9r:r;)rrrr_get_cpuinfo_flags(s z#CPULatencyPlugin._get_cpuinfo_flagscCs t|}|jjt|jddS)NrrC)strrZ is_cpu_onlinereplace)rr"Zsdrrr_is_cpu_online-szCPULatencyPlugin._is_cpu_onlinecCstjjd|S)Nz3/sys/devices/system/cpu/%s/cpufreq/scaling_governor)rJrKrL)rr"rrr_cpu_has_scaling_governor1sz*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)rQr<debugrR)rr"rrr_check_cpu_can_change_governor4s  z/CPULatencyPlugin._check_cpu_can_change_governorcCsd|_d|_t|jjd|krd|_ytjtj tj |_ Wn*t k rht jdtj d|_YnXd|_|jddkr|jddkr|jjdd|_d|_nd|_|jnd|_t jd|jyt|jd|_Wntk rd|_YnXdS) NTFrz-Unable to open '%s', disabling PM_QoS controlr,r3loadzILatency settings from non-first CPU plugin instance '%s' will be ignored.)Z_has_static_tuningZ_has_dynamic_tuninglistZ _instancesvalues_first_instancerJopenconstsZPATH_CPU_DMA_LATENCYO_WRONLY_cpu_latency_fdOSErrorr<errorr _latencyoptions_monitors_repositoryZcreate _load_monitorrAr=nameZassigned_devices _first_device IndexError)rinstancerrr_instance_init=s*  zCPULatencyPlugin._instance_initcCs4|jr0|jrtj|j|jdk r0|jj|jdS)N)rXr rJcloser\rbradelete)rrfrrr_instance_cleanup[s   z"CPULatencyPlugin._instance_cleanupcCs|jjd|djS)Nz'/sys/devices/system/cpu/intel_pstate/%s)r read_filestrip)rattrrrr_get_intel_pstate_attrbsz'CPULatencyPlugin._get_intel_pstate_attrcCs|dk r|jjd||dS)Nz'/sys/devices/system/cpu/intel_pstate/%s)r write_to_file)rrmvalrrr_set_intel_pstate_attresz'CPULatencyPlugin._set_intel_pstate_attrcCs&|dkr dS|j|}|j|||S)N)rnrq)rrmvaluevrrr_getset_intel_pstate_attris   z*CPULatencyPlugin._getset_intel_pstate_attrcstt|j||jsdS|jj|jd}|dk r>|j||jr|jj|jd}|j d||_ |jj|jd}|j d||_ |jj|jd}|j d||_ dS)Nr,r0r1r2) rr_instance_apply_staticrXZ _variablesexpandr` _set_latencyrrtrrr)rrfZforce_latency_valueZ new_value)rrrrups(       z'CPULatencyPlugin._instance_apply_staticcsLtt|j|||jrH|jrH|jd|j|jd|j|jd|jdS)Nr0r1r2) rr_instance_unapply_staticrXrrqrrr)rrfZrollback)rrrrxs  z)CPULatencyPlugin._instance_unapply_staticcCs|j||dS)N)_instance_update_dynamic)rrfr"rrr_instance_apply_dynamicsz(CPULatencyPlugin._instance_apply_dynamiccCsP||jkrdS|jjd}||jdkr<|j|jdn|j|jddS)Nsystemr)r+r*)rdrbZget_loadr`rw)rrfr"rUrrrrys  z)CPULatencyPlugin._instance_update_dynamiccCsdS)Nr)rrfr"rrr_instance_unapply_dynamicsz*CPULatencyPlugin._instance_unapply_dynamicc Cs&yt|Sttfk r dSXdS)N)int ValueError TypeError)rsrrr_str2intszCPULatencyPlugin._str2intcCsi|_xztjtD]l}td|}|jj|dddd}|jj|dddd}|dk r|dk r|j|}|dk r||j|j<qWdS)Nz/%s/rcT)err_retno_errorlatency)cstates_latencyrJlistdircpuidle_states_pathrrkrrl)rdZ cstate_pathrcrrrr_read_cstates_latencys  z&CPULatencyPlugin._read_cstates_latencyFcCshtjd||jdkr*tjd|j|jj|d}|rR|dkrRtjddStjdt||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)r<rSrrr;rO)rrcno_zerorrrr_get_latency_by_cstate_names    z,CPULatencyPlugin._get_latency_by_cstate_namecCstjdt||j|}|dkr2tjddStdd|}|j|jj|ddd}|rt|dkrttjddStjd t||S) Nz'getting latency for cstate with ID '%s'zcstate ID is invalidz /%s/latencyzstate%dT)rrrz"skipping latency 0 as set by paramzcstate ID mapped to latency: %s)r<rSrOrrrrk)rZlidrZ latency_pathrrrr_get_latency_by_cstate_ids    z*CPULatencyPlugin._get_latency_by_cstate_idc Cs`d|_t|jd}tjd||fx.|D]$}yt|}tjd|Wntk rH|dddkr|j|dddd}n|dd d kr|j|d d}n|dd d kr|j|d ddd}nn|dd dkr|j|d d}nJ|dkrtjddS|r.|dkr.tjdntjdt|d}YnX|dk r.Pq.W|dfS)N|z#parsing latency '%s', allow_na '%s'z+parsed directly specified latency value: %drzcstate.id_no_zero:T)r z cstate.id:zcstate.name_no_zero: z cstate.name:noneNonezlatency 'none' specifiedzn/azlatency 'n/a' specifiedzinvalid latency specified: '%s'F)rr)NT) rrOsplitr<rSr}r~rr)rrallow_naZ latenciesrrr_parse_latencys6    zCPULatencyPlugin._parse_latencycCsp|j|\}}| rl|jrl|dkr4tjdd|_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 %di) rr r<r^r_r=structpackrJwriter\)rrskipZ latency_binrrrrws    zCPULatencyPlugin._set_latencycCs|jjd|jjS)Nz>/sys/devices/system/cpu/%s/cpufreq/scaling_available_governors)rrkrlr)rr"rrr_get_available_governorssz)CPULatencyPlugin._get_available_governorsr-T) per_devicecCs|j|sdSt|}|jd}dd|D}x&|D]}t|dkr4tjddSq4W|j|}x~|D]^}||kr|stjd||f|jj d|||rt j gndd Pqf|sftj d ||fqfWtj d d j|d}|S) NrcSsg|] }|jqSr)rl)r$r-rrrr&sz2CPULatencyPlugin._set_governor..rz.The 'governor' option contains an empty value.z!setting governor '%s' on cpu '%s'z3/sys/devices/system/cpu/%s/cpufreq/scaling_governorF)rz7Ignoring governor '%s' on cpu '%s', it is not supportedz.None of the scaling governors is supported: %sz, )rTrOrlenr<r^rr=rrorErFrSwarnjoin)rZ governorsr"simremover-Zavailable_governorsrrr _set_governors2        zCPULatencyPlugin._set_governorcCsTd}|j|sdS|jjd||dj}t|dkr:|}|dkrPtjd||S)Nz3/sys/devices/system/cpu/%s/cpufreq/scaling_governor)rrz*could not get current governor on cpu '%s')rTrrkrlrr<r^)rr"ignore_missingr-datarrr _get_governors  zCPULatencyPlugin._get_governorondemandcCsd|S)Nz7/sys/devices/system/cpu/cpufreq/%s/sampling_down_factorr)rr-rrr_sampling_down_factor_path%sz+CPULatencyPlugin._sampling_down_factor_pathr.r)rZprioritycCsd}||jkr|jjd|j|<|j|}|dkrFtjd|dS|t|jjkr||j|<|j|}tj j |stjd||fdSt |}|stj d||f|j j|||rtjgndd|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'F)r)rclearrr<rSrVrWrrJrKrLrOr=rrorErF)rr.r"rrrpr-rKrrr_set_sampling_down_factor(s&       z*CPULatencyPlugin._set_sampling_down_factorcCsD|j||d}|dkrdS|j|}tjj|s4dS|jj|jS)N)r)rrrJrKrLrrkrl)rr"rr-rKrrr_get_sampling_down_factorCs  z*CPULatencyPlugin._get_sampling_down_factorcCs*|jjdd|t|gdd\}}}||fS)NrBz-cT)Z return_err)rrDrO)rcpu_idrrrHrIerr_msgrrr_try_set_energy_perf_biasMs z*CPULatencyPlugin._try_set_energy_perf_biascCsd||r dndfS)Nz>/sys/devices/system/cpu/cpufreq/policy%s/energy_performance_%sZavailable_preferencesZ preferencer)rrZ availablerrr_pstate_preference_pathVsz(CPULatencyPlugin._pstate_preference_pathcCsd|S)Nz4/sys/devices/system/cpu/cpu%s/power/energy_perf_biasr)rrrrr_energy_perf_bias_pathYsz'CPULatencyPlugin._energy_perf_bias_pathr/c Cs||j|stjd|dS|jd}|jd}tj|jkr|j|}t j j |r|sxT|D]>}|j }|j j|||rtjgnddr^tjd||fPq^Wtjd|t|Stjd|dSn|jrt|slx|D]|}|j }tjd ||f|j||\} } | d kr,tjd||fPq| d krHtjd | Pqtjd ||fqWtjd|t|SdSdS) Nz%s is not online, skippingrrF)rz5energy_perf_bias successfully set to '%s' on cpu '%s'zPFailed to set energy_perf_bias on cpu '%s'. Is the value in the profile correct?zXFailed to set energy_perf_bias on cpu '%s' because energy_perf_bias file does not exist.z2Trying to set energy_perf_bias to '%s' on cpu '%s'rz"Failed to set energy_perf_bias: %szHCould not set energy_perf_bias to '%s' on cpu '%s', trying another value)rQr<rSlstriprrZCFG_CPU_EPP_FLAGrNrrJrKrLrlrrorErFr=r^rOrr) rr/r"rrrvalsenergy_perf_bias_pathrprHrrrr_set_energy_perf_bias\sX              z&CPULatencyPlugin._set_energy_perf_biascCsjy t|}WnXtk rd}z|j| rBdS|dksZ|dkrp|dkrptjd||fdS|s|jj|j|||rt j gndd|S) Nz%s is not online, skippingT)rzn/arzr?r@rNrQrRrTrgrjrnrqrtrurZZ ROLLBACK_SOFTrxrzryr|rrrrrrwrZ command_setrZ command_getrrrrrrrrrrrrrrrrrr __classcell__rr)rrrsn,            8   r)rCrZ decoratorsZ tuned.logsZtunedZtuned.utils.commandsrZ tuned.constsrZrJrErr6r8Zlogsr;r<rZPluginrrrrrs