3 À<×esã@sjddlmZddlTddlZddlmZddlZddlZej j ƒ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 „Ze d d „ƒZ dd„Z e ddd�dd„ƒZ edƒddd„ƒZe ddd�dd„ƒZedƒddd„ƒZdS) Ú UncorePlugina| `uncore`:: `max_freq_khz, min_freq_khz`::: Limit the maximum and minumum uncore frequency. Those options are Intel specific and correspond directly to `sysfs` files exposed by Intel uncore frequency driver. ==== ---- [uncore] max_freq_khz=4000000 ---- Using this options *TuneD* will limit maximum frequency of all uncore units on the Intel system to 4 GHz. ==== c Cs’d|_tƒ|_tƒ|_d|_ytjtƒ}Wntk r>dSXt j |dƒ}t |ƒdkrbd|_|}x|D]}|jj |ƒqhWt jdt|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.6/plugin_uncore.pyÚ _init_devices$s   zUncorePlugin._init_devicescCsd|_d|_dS)NTF)Z_has_static_tuningZ_has_dynamic_tuning)rÚinstancerrrÚ_instance_init:szUncorePlugin._instance_initcCsdS)Nr)rrrrrÚ_instance_cleanup>szUncorePlugin._instance_cleanupcCs2t|d|}tj|ƒ}t|ƒdkr.t|ƒSdS)Nú/r)r ÚcmdZ read_filerÚint)rÚdev_dirÚfileÚ sysfs_fileÚvaluerrrÚ_getAs   zUncorePlugin._getcCs(t|d|}tj|d|ƒr$|SdS)Nrz%u)r rZ write_to_file)rrrr!r rrrÚ_setHszUncorePlugin._setcCs dddœS)N)Ú max_freq_khzÚ min_freq_khzr)ÚclsrrrÚ_get_config_optionsNsz UncorePlugin._get_config_optionsc Cs*y t|ƒ}Wn"tk r.tjd|ƒdSXy4|j|dƒ}|j|dƒ}|j|dƒ}|j|dƒ}Wn"ttfk r†tjdƒdSX|tkrÒ||kr°tjd|||fƒdS||krÐtjd|||fƒ|}nT|t k�r"||k�rþtjd |||fƒdS||k�r&tjd |||fƒ|}ndS|S) Nzvalue '%s' is not integerÚinitial_max_freq_khzÚinitial_min_freq_khzr$r%z+fail to read inital uncore frequency valuesz/%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Ú ValueErrorrÚerrorr"r ÚIOErrorÚIS_MAXÚinfoÚIS_MIN) rÚdeviceZ min_or_maxr!Zfreq_khzr(r)r$r%rrrÚ_validate_valueUs:        zUncorePlugin._validate_valuer$T)Z per_devicecCsB|j|t|ƒ}|dkrdS|r"|Stjd||fƒ|j|d|ƒS)Nz%s: set max_freq_khz %dr$)r1r-rrr#)rr!r0ÚsimÚremover$rrrÚ_set_max_freq_khz|szUncorePlugin._set_max_freq_khzFc Cs`|rtjjtƒ rdSy|j|dƒ}Wn"ttfk rHtjdƒdSXtj d||fƒ|S)Nr$z$fail to read uncore frequency valuesz%s: get max_freq_khz %d) rÚpathÚisdirr r"r r,rr+r)rr0Úignore_missingr$rrrÚ_get_max_freq_khzˆs zUncorePlugin._get_max_freq_khzr%cCsB|j|t|ƒ}|dkrdS|r"|Stjd||fƒ|j|d|ƒS)Nz%s: set min_freq_khz %dr%)r1r/rrr#)rr!r0r2r3r%rrrÚ_set_min_freq_khz–szUncorePlugin._set_min_freq_khzc Cs`|rtjjtƒ rdSy|j|dƒ}Wn"ttfk rHtjdƒdSXtj d||fƒ|S)Nr%z$fail to read uncore frequency valuesz%s: get min_freq_khz %d) rr5r6r r"r r,rr+r)rr0r7r%rrrÚ_get_min_freq_khz¢s zUncorePlugin._get_min_freq_khzN)F)F)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr"r#Ú classmethodr'r1Z command_setr4Z command_getr8r9r:rrrrrs '   r)ÚrZ decoratorsZ tuned.logsZtunedZtuned.utils.commandsrrr ZlogsÚgetrrr r/r-ZPluginrrrrrÚs