<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
<es                 @   sj   d dl mZ d dlT ddlZddlmZ ddlZddlZej	j
 Ze ZdZdZd ZG dd dejZdS )	   )hotplug)*    N)commandsz//sys/devices/system/cpu/intel_uncore_frequency/c               @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	dd Z
dd Zeddddd ZeddddZeddddd ZeddddZdS ) 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             C   s   d| _ t | _t | _d| _ytjt}W n tk
r>   d S X t	j
|d}t|dkrbd| _|}x|D ]}| jj| qhW tjdt| j d S )NTFzuncore*r   zdevices: %s)Z_devices_supportedsetZ_assigned_devicesZ_free_devicesZ_is_tpmioslistdir	SYSFS_DIROSErrorfnmatchfilterlenaddlogdebugstr)selfZdevicesZtpmi_devicesd r   #/usr/lib/python3.6/plugin_uncore.py_init_devices$   s    
zUncorePlugin._init_devicesc             C   s   d|_ d|_d S )NTF)Z_has_static_tuningZ_has_dynamic_tuning)r   instancer   r   r   _instance_init:   s    zUncorePlugin._instance_initc             C   s   d S )Nr   )r   r   r   r   r   _instance_cleanup>   s    zUncorePlugin._instance_cleanupc             C   s2   t | d | }tj|}t|dkr.t|S d S )N/r   )r
   cmdZ	read_filer   int)r   dev_dirfile
sysfs_filevaluer   r   r   _getA   s
    
zUncorePlugin._getc             C   s(   t | d | }tj|d| r$|S d S )Nr   z%u)r
   r   Zwrite_to_file)r   r   r   r!   r    r   r   r   _setH   s    zUncorePlugin._setc             C   s
   d d dS )N)max_freq_khzmin_freq_khzr   )clsr   r   r   _get_config_optionsN   s    z UncorePlugin._get_config_optionsc       	      C   s*  yt |}W n" tk
r.   tjd|  d S X y4| j|d}| j|d}| j|d}| j|d}W n" ttfk
r   tjd d S X |tkr||k rtjd|||f  d S ||krtjd|||f  |}nT|t	kr"||k rtjd	|||f  d S ||k r&tjd
|||f  |}nd S |S )Nzvalue '%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!   Zfreq_khzr(   r)   r$   r%   r   r   r   _validate_valueU   s:    



zUncorePlugin._validate_valuer$   T)Z
per_devicec             C   sB   | j |t|}|d krd S |r"|S tjd||f  | j|d|S )Nz%s: set max_freq_khz %dr$   )r1   r-   r   r   r#   )r   r!   r0   simremover$   r   r   r   _set_max_freq_khz|   s    zUncorePlugin._set_max_freq_khzFc             C   s`   |rt jjt rd S y| j|d}W n" ttfk
rH   tjd d S X tj	d||f  |S )Nr$   z$fail to read uncore frequency valuesz%s: get max_freq_khz %d)
r   pathisdirr
   r"   r   r,   r   r+   r   )r   r0   ignore_missingr$   r   r   r   _get_max_freq_khz   s    
zUncorePlugin._get_max_freq_khzr%   c             C   sB   | j |t|}|d krd S |r"|S tjd||f  | j|d|S )Nz%s: set min_freq_khz %dr%   )r1   r/   r   r   r#   )r   r!   r0   r2   r3   r%   r   r   r   _set_min_freq_khz   s    zUncorePlugin._set_min_freq_khzc             C   s`   |rt jjt rd S y| j|d}W n" ttfk
rH   tjd d S X tj	d||f  |S )Nr%   z$fail to read uncore frequency valuesz%s: get min_freq_khz %d)
r   r5   r6   r
   r"   r   r,   r   r+   r   )r   r0   r7   r%   r   r   r   _get_min_freq_khz   s    
zUncorePlugin._get_min_freq_khzN)F)F)__name__
__module____qualname____doc__r   r   r   r"   r#   classmethodr'   r1   Zcommand_setr4   Zcommand_getr8   r9   r:   r   r   r   r   r      s   'r   ) r   Z
decoratorsZ
tuned.logsZtunedZtuned.utils.commandsr   r   r   Zlogsgetr   r   r
   r/   r-   ZPluginr   r   r   r   r   <module>   s   
