a ”ˆ«häã@sjddlmZddlTddlZddlmZddlZddlZej   ¡Z eƒZ dZ dZdZGdd„dejƒZdS) é)Úhotplug)Ú*éN)Úcommandsz//sys/devices/system/cpu/intel_uncore_frequency/c@s°eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z e dd„ƒZ dd„Z dd„Z dd„Zeddddd„ƒZedƒd$dd„ƒZeddddd „ƒZedƒd%d!d"„ƒZd#S)&Ú UncorePlugina  An Intel-specific plug-in for limiting the maximum and minimum uncore frequency. The options [option]`max_freq_khz`, [option]`min_freq_khz` correspond to `sysfs` files exposed by Intel uncore frequency driver. Their values can be specified in kHz or as a percentage of their configurable range. .Limiting maximum uncore frequency ==== ---- [uncore10] type=uncore devices=uncore10 max_freq_khz=4000000 [uncore_all] type=uncore max_freq_khz=90% ---- Using this options *TuneD* will limit maximum frequency of all uncore units on the Intel system to 90% of the allowable range. Except uncore10 which maximum frequency limit will be set to 4 GHz. ==== cCsŽd|_tƒ|_tƒ|_d|_zt t¡}Wnty>YdS0t   |d¡}t |ƒdkrbd|_|}|D]}|j  |¡qft  dt|jƒ¡dS)NTFzuncore*rz devices: %s)Z_devices_supportedÚsetZ_assigned_devicesZ _free_devicesZ_is_tpmiÚosÚlistdirÚ SYSFS_DIRÚOSErrorÚfnmatchÚfilterÚlenÚaddÚlogÚdebugÚstr)ÚselfZdevicesZ tpmi_devicesÚd©rú?/usr/lib/python3.9/site-packages/tuned/plugins/plugin_uncore.pyÚ _init_devices+s   zUncorePlugin._init_devicescCsd|_d|_dS)NTF)Z_has_static_tuningZ_has_dynamic_tuning©rÚinstancerrrÚ_instance_initAszUncorePlugin._instance_initcCsdS)NrrrrrÚ_instance_cleanupEszUncorePlugin._instance_cleanupcCs2t|d|}t |¡}t|ƒdkr.t|ƒSdS)Nú/r)r ÚcmdZ read_filerÚint)rÚdev_dirÚfileÚ sysfs_fileÚvaluerrrÚ_getHs   zUncorePlugin._getcCs(t|d|}t |d|¡r$|SdS)Nrz%u)r rZ write_to_file)rrr r"r!rrrÚ_setOszUncorePlugin._setc Csdz4| |d¡}| |d¡}| |d¡}| |d¡}Wn"ttfyVt d¡YdS0||||fS)NÚinitial_max_freq_khzÚinitial_min_freq_khzÚ max_freq_khzÚ min_freq_khzú$fail to read uncore frequency values)r#r ÚIOErrorrÚerror)rÚdevicer%r&r'r(rrrÚ_get_allUs    zUncorePlugin._get_allcCs dddœS)N)r'r(r)ÚclsrrrÚ_get_config_options`sþz UncorePlugin._get_config_optionsc Csîz t|ƒ}Wn"ty.t d|¡YdS0| |¡}|durFdS|\}}}} |tkrœ|| krzt d||| f¡dS||krêt d|||f¡|}nN|tkræ||krÄt d|||f¡dS||krêt d|||f¡|}ndS|S)Núvalue '%s' is not integerz/%s: max_freq_khz %d value below min_freq_khz %dzC%s: max_freq_khz %d value above initial_max_freq_khz - capped to %dz/%s: min_freq_khz %d value above max_freq_khz %dzC%s: min_freq_khz %d value below initial_max_freq_khz - capped to %d)rÚ ValueErrorrr+r-ÚIS_MAXÚinfoÚIS_MIN) rr,Ú min_or_maxr"Zfreq_khzÚvaluesr%r&r'r(rrrÚ_validate_khz_valuegs2    z UncorePlugin._validate_khz_valuecCsVz t|ƒ}Wn"ty.t d|¡YdS0|dks@|dkrRt d|¡dS|S)Nr0rédz/percent value '%s' is not within [0..100] range)rr1rr+)rr"ÚpctrrrÚ_validate_percent_valueŠs  z$UncorePlugin._validate_percent_valuec Cs€t|tƒrn|ddkrn| | d¡¡}|dur2dS| |¡}|durHdS|\}}}}|t|||dƒ} n|} | ||| ¡S)Néÿÿÿÿú%r8)Ú isinstancerr:Úrstripr-rr7) rr,r5r"r9r6r%r&Ú_ZkhzrrrÚ_validate_value—s  zUncorePlugin._validate_valuer'T)Z per_devicecCsB| |t|¡}|durdS|r"|St d||f¡| |d|¡S)Nz%s: set max_freq_khz %dr')r@r2rrr$)rr"r,rÚsimÚremover'rrrÚ_set_max_freq_khz¨szUncorePlugin._set_max_freq_khzFc Cs^|rtj t¡sdSz| |d¡}Wn"ttfyFt d¡YdS0t  d||f¡|S)Nr'r)z%s: get max_freq_khz %d© rÚpathÚisdirr r#r r*rr+r)rr,rÚignore_missingr'rrrÚ_get_max_freq_khz´s zUncorePlugin._get_max_freq_khzr(cCsB| |t|¡}|durdS|r"|St d||f¡| |d|¡S)Nz%s: set min_freq_khz %dr()r@r4rrr$)rr"r,rrArBr(rrrÚ_set_min_freq_khzÂszUncorePlugin._set_min_freq_khzc Cs^|rtj t¡sdSz| |d¡}Wn"ttfyFt d¡YdS0t  d||f¡|S)Nr(r)z%s: get min_freq_khz %drD)rr,rrGr(rrrÚ_get_min_freq_khzÎs zUncorePlugin._get_min_freq_khzN)F)F)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr#r$r-Ú classmethodr/r7r:r@Z command_setrCZ command_getrHrIrJrrrrrs(  #     r)ÚrZ decoratorsZ tuned.logsZtunedZtuned.utils.commandsrrr ZlogsÚgetrrr r4r2ZPluginrrrrrÚs