<!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
<e                 @   s   d dl mZmZ d dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ d dlZd dlZd dlZej ZdZdZd	ZG d
d deZG dd deZG dd deZG dd dejjZdS )    )exportslogs)commands)PPD_CONFIG_FILE)	PPDConfigPPD_PERFORMANCEPPD_POWER_SAVER)StrEnumNtunedz-/sys/devices/system/cpu/intel_pstate/no_turboz4/sys/bus/platform/devices/thinkpad_acpi/dytc_lapmodec               @   s   e Zd ZdZdZdZdS )PerformanceDegraded zlap-detectedzhigh-operating-temperatureN)__name__
__module____qualname__NONELAP_DETECTEDHIGH_OPERATING_TEMPERATURE r   r    /usr/lib/python3.6/controller.pyr      s   r   c               @   s   e Zd Zdd Zdd ZdS )ProfileHoldc             C   s   || _ || _|| _|| _d S )N)profilereasonapp_idwatch)selfr   r   r   r   r   r   r   __init__   s    zProfileHold.__init__c             C   s   | j | j| jdS )N)ProfileZReasonZApplicationId)r   r   r   )r   r   r   r   as_dict   s    zProfileHold.as_dictN)r   r   r   r   r   r   r   r   r   r      s   r   c               @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )ProfileHoldManagerc             C   s   i | _ d| _|| _d S )Nr   )_holds_cookie_counter_controller)r   Z
controllerr   r   r   r   '   s    zProfileHoldManager.__init__c                s    fdd}|S )Nc                s(   | dkr$t jd f  j d S )Nr   z1Application '%s' disappeared, releasing hold '%s')loginforemove)name)r   cookier   r   r   callback-   s    z.ProfileHoldManager._callback.<locals>.callbackr   )r   r&   r   r'   r   )r   r&   r   r   	_callback,   s    zProfileHoldManager._callbackc             C   s    t dd | jj D rtS tS )Nc             s   s   | ]}|j tkV  qd S )N)r   r   ).0holdr   r   r   	<genexpr>5   s    z=ProfileHoldManager._effective_hold_profile.<locals>.<genexpr>)anyr   valuesr   r   )r   r   r   r   _effective_hold_profile4   s    z*ProfileHoldManager._effective_hold_profilec             C   s\   || j krd S | j j|}|jj  tjd| tjd| j  tj	d||j
|jf  d S )NProfileReleasedActiveProfileHoldsz5Releasing hold '%s': profile '%s' by application '%s')r   popr   Zcancelr   Zsend_signalproperty_changedas_dbus_arrayr"   r#   r   r   )r   r&   r*   r   r   r   _cancel9   s    

zProfileHoldManager._cancelc             C   s   t jdd | jj D ddS )Nc             S   s   g | ]}|j  qS r   )r   )r)   r*   r   r   r   
<listcomp>C   s    z4ProfileHoldManager.as_dbus_array.<locals>.<listcomp>za{sv})	signature)dbusArrayr   r-   )r   r   r   r   r3   B   s    z ProfileHoldManager.as_dbus_arrayc             C   st   | j }|  j d7  _ | jjj|| j||}tjd|||f  t||||| j|< t	j
d| j  | jj| |S )N   z2Adding hold '%s': profile '%s' by application '%s'r0   )r    r!   busZwatch_name_ownerr(   r"   r#   r   r   r   r2   r3   switch_profile)r   r   r   r   callerr&   r   r   r   r   addE   s    zProfileHoldManager.addc             C   s
   || j kS )N)r   )r   r&   r   r   r   hasO   s    zProfileHoldManager.hasc             C   s:   | j | t| jdkr"| j }n| jj}| jj| d S )Nr   )r4   lenr   r.   r!   base_profiler;   )r   r&   Znew_profiler   r   r   r$   R   s
    

zProfileHoldManager.removec             C   s   x| j D ]}| j| qW d S )N)r   r4   )r   r&   r   r   r   clearZ   s    zProfileHoldManager.clearN)r   r   r   r   r(   r.   r4   r3   r=   r>   r$   rA   r   r   r   r   r   &   s   	
r   c                   s
  e Zd Z fddZdd Zdd Zedd Zed	d
 Zdd Z	dd Z
dd Zdd Zejdddd Zejdddd Zejddd Zejddd Zejddd  Zejd!d"d# Zejd$d%d& Zejd'd(d) Zejd*d+d, Z  ZS )-
Controllerc                sJ   t t| j  || _|| _t| | _tj| _	t
 | _tj | _| j  d S )N)superrB   r   _bus_tuned_interfacer   _profile_holdsr   r   _performance_degradedr   _cmd	threadingZEvent
_terminateload_config)r   r:   Ztuned_interface)	__class__r   r   r   `   s    

zController.__init__c             C   s   t j}tjjtr,t| jjtdkr,t j	}tjjt
rRt| jjt
dkrRt j}|| jkr|tjd|  || _tjd| d S )Nr9   zPerformance degraded: %sr   )r   r   ospathexistsNO_TURBO_PATHintrH   Z	read_filer   LAP_MODE_PATHr   rG   r"   r#   r   r2   )r   Zperformance_degradedr   r   r   _check_performance_degradedj   s    
z&Controller._check_performance_degradedc             C   s2   t j  x| jj| jds$| j  q
W t j  d S )Nr9   )r   startrH   waitrJ   rS   stop)r   r   r   r   runw   s    zController.runc             C   s   | j S )N)rD   )r   r   r   r   r:   }   s    zController.busc             C   s   | j S )N)_base_profile)r   r   r   r   r@      s    zController.base_profilec             C   s   | j j  d S )N)rJ   set)r   r   r   r   	terminate   s    zController.terminatec             C   s&   t t| _| jj| _| j| jj d S )N)r   r   _configZdefault_profilerX   r;   )r   r   r   r   rK      s    

zController.load_configc             C   sF   | j  |krd S | jj| }tjd|  | jj| tjd| d S )NzSwitching to profile '%s'ActiveProfile)	active_profiler[   ppd_to_tunedr"   r#   rE   r;   r   r2   )r   r   tuned_profiler   r   r   r;      s    zController.switch_profilec             C   s   | j j }| jjj|dS )Nunknown)rE   r]   r[   Ztuned_to_ppdget)r   r_   r   r   r   r]      s    
zController.active_profileZsssuc             C   s6   |t kr$|tkr$tjjdt tf | jj||||S )Nz'Only '%s' and '%s' profiles may be held)r   r   r7   
exceptionsDBusExceptionrF   r=   )r   r   r   r   r<   r   r   r   HoldProfile   s    zController.HoldProfiler   c             C   s,   | j j|stjjd| | j j| d S )NzNo active hold for cookie '%s')rF   r>   r7   rc   rd   r$   )r   r&   r<   r   r   r   ReleaseProfile   s    zController.ReleaseProfilec             C   s   d S )Nr   )r   r&   r   r   r   r/      s    zController.ProfileReleasedr\   c             C   s:   || j jkrtjjd| || _| jj  | j| d S )NzInvalid profile '%s')	r[   r^   r7   rc   rd   rX   rF   rA   r;   )r   r   r   r   r   set_active_profile   s
    
zController.set_active_profilec             C   s   | j  S )N)r]   )r   r   r   r   get_active_profile   s    zController.get_active_profileZProfilesc             C   s    t jdd | jjj D ddS )Nc             S   s   g | ]}|t d qS ))r   ZDriver)DRIVER)r)   r   r   r   r   r5      s    z+Controller.get_profiles.<locals>.<listcomp>za{sv})r6   )r7   r8   r[   r^   keys)r   r   r   r   get_profiles   s    zController.get_profilesZActionsc             C   s   t jg ddS )Ns)r6   )r7   r8   )r   r   r   r   get_actions   s    zController.get_actionsr   c             C   s   | j S )N)rG   )r   r   r   r   get_performance_degraded   s    z#Controller.get_performance_degradedr0   c             C   s
   | j j S )N)rF   r3   )r   r   r   r   get_active_profile_holds   s    z#Controller.get_active_profile_holds)r   r   r   r   rS   rW   propertyr:   r@   rZ   rK   r;   r]   r   Zexportre   rf   signalr/   Zproperty_setterrg   Zproperty_getterrh   rk   rm   rn   ro   __classcell__r   r   )rL   r   rB   _   s$   
rB   )r
   r   r   Ztuned.utils.commandsr   Ztuned.constsr   Ztuned.ppd.configr   r   r   enumr	   rI   r7   rM   ra   r"   ri   rP   rR   r   objectr   r   Z
interfacesZExportableInterfacerB   r   r   r   r   <module>   s   9