403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /lib/python3.9/site-packages/tuned/ppd/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /lib/python3.9/site-packages/tuned/ppd/__pycache__/controller.cpython-39.pyc
a

,�ggL�@s(ddlmZmZddlmZddlmZmZmZddl	m
Z
mZmZm
Z
ddlmZddlmZddlZddlZddlZddlZddlZe��ZdZd	Zd
ZdZdZd
ZdZdZ e
eed�Z!Gdd�de�Z"Gdd�dej#�Z$Gdd�dej#�Z%Gdd�de&�Z'Gdd�de&�Z(Gdd�dej)j*�Z+dS)�)�exports�logs)�commands)�PPD_CONFIG_FILE�PPD_BASE_PROFILE_FILE�PPD_API_COMPATIBILITY)�	PPDConfig�PPD_PERFORMANCE�PPD_BALANCED�PPD_POWER_SAVER)�Enum)�RandomN�tunedz-/sys/devices/system/cpu/intel_pstate/no_turboz4/sys/bus/platform/devices/thinkpad_acpi/dytc_lapmode�unknownzorg.freedesktop.UPowerz/org/freedesktop/UPowerz#/sys/firmware/acpi/platform_profile)z	low-powerZbalancedZperformancec@seZdZdZdZdZdZdS)�PerformanceDegradedz7
    Possible reasons for performance degradation.
    �zlap-detectedzhigh-operating-temperatureN)�__name__�
__module__�__qualname__�__doc__�NONE�LAP_DETECTED�HIGH_OPERATING_TEMPERATURE�rr�8/usr/lib/python3.9/site-packages/tuned/ppd/controller.pyr!srcs(eZdZdZ�fdd�Zdd�Z�ZS)�PerformanceDegradedEventHandlerz=
    Event handler for checking performance degradation.
    cstt|���||_||_dS�N)�superr�__init__�_controller�_path)�self�
controller�path��	__class__rrr.sz(PerformanceDegradedEventHandler.__init__cCs|j|jkrdS|j��dSr)�pathnamer r�check_performance_degraded�r!Zeventrrr�process_IN_MODIFY3sz1PerformanceDegradedEventHandler.process_IN_MODIFY)rrrrrr)�
__classcell__rrr$rr*srcsDeZdZdZdZ�fdd�Zdd�Zdd�Zd	d
�Zdd�Z	�Z
S)
�PlatformProfileEventHandlera
    Event handler for switching PPD profiles based on the
    ACPI platform profile

    This handler should only invoke a PPD profile change if the
    change of the file at PLATFORM_PROFILE_PATH comes from within
    the kernel (e.g., when the user presses Fn-L on a Thinkpad laptop).
    This is currently detected as the file being modified without
    being opened before.
    g�������?cs$tt|���||_d|_d|_dS)NFr)rr+rr�
_file_open�_last_close�r!r"r$rrrFsz$PlatformProfileEventHandler.__init__cCs|jtkrdSd|_d|_dS)NTr)r&�PLATFORM_PROFILE_PATHr,r-r(rrr�process_IN_OPENLs
z+PlatformProfileEventHandler.process_IN_OPENcCs"|jtkrdSd|_t��|_dS�NF)r&r/r,�timer-r(rrr�process_IN_CLOSE_WRITERs
z2PlatformProfileEventHandler.process_IN_CLOSE_WRITEcCs|jtkrdSd|_dSr1)r&r/r,r(rrr�process_IN_CLOSE_NOWRITEXs
z4PlatformProfileEventHandler.process_IN_CLOSE_NOWRITEcCs6|jtks$|js$|j|jt��kr(dS|j��dSr)r&r/r,r-�CLOSE_MODIFY_BUFFERr2r�check_platform_profiler(rrrr)]s$z-PlatformProfileEventHandler.process_IN_MODIFY)rrrrr5rr0r3r4r)r*rrr$rr+9s
r+c@s eZdZdZdd�Zdd�ZdS)�ProfileHoldz}
    Class holding information about a single profile hold,
    i.e., a temporary profile switch requested by a process.
    cCs"||_||_||_||_||_dSr)�profile�reason�app_id�caller�watch)r!r8r9r:r;r<rrrrks
zProfileHold.__init__cCs|j|j|jd�S)zF
        Returns the hold information as a Python dictionary.
        )�ProfileZReasonZ
ApplicationId)r8r9r:�r!rrr�as_dictrs�zProfileHold.as_dictN)rrrrrr?rrrrr7fsr7c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�ProfileHoldManagerz�
    Manager of profile holds responsible for their creation/deletion
    and for choosing the effective one. Holds are identified using
    integer cookies which are distributed to the hold-requesting processes.
    cCsi|_t�|_||_dSr)�_holdsr
�_cookie_generatorrr.rrrr�szProfileHoldManager.__init__cs���fdd�}|S)z�
        Returns the callback to invoke when the process with the given ID
        (which requested a hold with the given cookie) disappears.
        cs(|dkr$t�d��f�����dS)Nrz1Application '%s' disappeared, releasing hold '%s')�log�info�remove)�name�r:�cookier!rr�callback�sz6ProfileHoldManager._removal_callback.<locals>.callbackr)r!rHr:rIrrGr�_removal_callback�sz$ProfileHoldManager._removal_callbackcCs tdd�|j��D��rtStS)zJ
        Returns the hold to use from the set of all active ones.
        css|]}|jtkVqdSr)r8r��.0�holdrrr�	<genexpr>��z=ProfileHoldManager._effective_hold_profile.<locals>.<genexpr>)�anyrA�valuesrr	r>rrr�_effective_hold_profile�sz*ProfileHoldManager._effective_hold_profilecCs\||jvrdS|j�|�}|j��t�d|�t�d|���t�	d||j
|jf�dS)zC
        Cancels the hold saved under the provided cookie.
        N�ProfileReleased�ActiveProfileHoldsz5Releasing hold '%s': profile '%s' by application '%s')rA�popr<�cancelrZsend_signal�property_changed�
as_dbus_arrayrCrDr8r:)r!rHrMrrr�_cancel�s

zProfileHoldManager._cancelcCstjdd�|j��D�dd�S)zY
        Returns the information about current holds as a DBus-compatible array.
        cSsg|]}|���qSr)r?rKrrr�
<listcomp>�rOz4ProfileHoldManager.as_dbus_array.<locals>.<listcomp>�a{sv}�Z	signature)�dbus�ArrayrArQr>rrrrX�sz ProfileHoldManager.as_dbus_arraycCs�d}|dks||jvr&|j�dd�}q|jj�||�||��}t�d|||f�t	|||||�|j|<t
�d|���|j�
|���|S)z*
        Adds a new profile hold.
        rl��z2Adding hold '%s': profile '%s' by application '%s'rT)rArBZrandintr�busZwatch_name_ownerrJrCrDr7rrWrX�switch_profilerR)r!r8r9r:r;rHr<rrr�add�szProfileHoldManager.addcCs
||jvS)zI
        Returns True if there is a hold under the given cookie.
        )rA�r!rHrrr�has�szProfileHoldManager.hascCs:|�|�t|j�dkr"|��}n|jj}|j�|�dS)zf
        Releases the hold saved under the provided cookie and
        sets the next profile.
        rN)rY�lenrArRr�base_profiler`)r!rH�new_profilerrrrE�s


zProfileHoldManager.removecCs"t|j���D]}|�|�qdS)z-
        Releases all profile holds.
        N)�listrA�keysrYrbrrr�clear�szProfileHoldManager.clearcCs||jvo|j|j|kSr)rAr;�r!rHr;rrr�check_caller�szProfileHoldManager.check_callerN)rrrrrrJrRrYrXrarcrErirkrrrrr@}sr@cs^eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zedd��Zedd��Zdd�Zd d!�Ze�d"d#d$�d%d&��Ze�d#d'd(�d)d*��Ze�d#�d+d,��Ze�d-d.�d/d0��Ze�d-�d1d2��Ze�d3�d4d5��Ze�d6�d7d8��Z e�d9�d:d;��Z!e�d<�d=d>��Z"e�d?�d@dA��Z#�Z$S)B�
ControllerzF
    The main tuned-ppd controller, exporting its DBus interface.
    cs�tt|���||_||_t�|_t��|_	d|_
d|_t�
�|_t�|j�|_i|_tj�t�|_tj�t�|_tj�t�|_|j�d|j�|��dS)NFZprofile_changed)rrlr�_bus�_tuned_interfacer�_cmd�	threading�Event�
_terminate�_battery_handler�_on_battery�	pyinotifyZWatchManager�_watch_managerZThreadedNotifier�	_notifier�_inotify_watches�osr#�isfiler/�_platform_profile_supported�
NO_TURBO_PATH�_no_turbo_supported�
LAP_MODE_PATH�_lap_mode_supported�connect_to_signal�_tuned_profile_changed�
initialize)r!r_Ztuned_interfacer$rrr�s

zController.__init__cCs<t|j�td��|_t�d|jr$dnd�|�|j�dS)zG
        The callback to invoke when the power supply changes.
        �	OnBatteryzBattery status changed: zDC (battery)z
AC (charging)N)	�bool�_upower_properties�Get�UPOWER_DBUS_INTERFACErtrCrDr`�_active_profile)r!Z	interfaceZchangedZinvalidatedrrr�_upower_changed�szController._upower_changedcCs�|sdS||j��kr$t�d�dSz|jj�||j�}Wn$ty^t	}t�
d|�Yn0|j|kr�t�d|�|j
��||_t�d|j�|t	kr�||_|�|�dS)zM
        The callback to invoke when TuneD signals a profile change.
        NzLReceived a profile change signal from TuneD, but it is not relevant anymore.z0TuneD profile changed to an unknown profile '%s'zProfile changed to '%s'�
ActiveProfile)rn�active_profilerC�debug�_configZtuned_to_ppd�getrt�KeyError�UNKNOWN_PROFILEZwarningr�rD�_profile_holdsrirrW�
_base_profile�_save_base_profile)r!�
tuned_profile�resultZerrstrZppd_profilerrrr��s$


z!Controller._tuned_profile_changedc
Cs�d|_|jjs,|jdur(|j��d|_dSzP|jdurf|j�tt�}t	�
|t	j�|_|�
d|j�|_t|j�td��|_Wn2t	jjy�}zt�|�WYd}~n
d}~00dS)z;
        Sets up handling of power supply changes.
        FNZPropertiesChangedr�)rtr�Zbattery_detectionrsrErmZ
get_object�UPOWER_DBUS_NAME�UPOWER_DBUS_PATHr]Z	InterfaceZPROPERTIES_IFACEr�r�r�r�r�r��
exceptions�
DBusExceptionrCr�)r!Zupower_proxy�errorrrr�_setup_battery_signaling
s


z#Controller._setup_battery_signalingcCs�|j�t|j����|jrH|j|jjtj�	t
�tjt
t
|�d�O_|jrz|j|jjtj�	t�tjt
t|�d�O_|jr�|jjr�|j|jjtj�	t�tjtjBtjBtjBt|�d�O_dS)z/
        Sets up inotify file watches.
        )r#�maskZproc_funN)rv�rm_watchrgrxrQr}Z	add_watchryr#�dirnamer|ruZ	IN_MODIFYrrr~r{r�Zthinkpad_function_keysr/ZIN_OPENZIN_CLOSE_WRITEZIN_CLOSE_NOWRITEr+r>rrr�_setup_inotify s �
�
�zController._setup_inotifycCs�tj}tj�t�r,|j�t���dkr,tj	}tj�t
�rR|j�t
���dkrRtj}||jkr�t
�d|j�||_t�d|j�dS)ze
        Checks the current performance degradation status and sends a signal if it changed.
        �1zPerformance degraded: %srN)rrryr#�existsr|ro�	read_file�striprr~r�_performance_degradedrCrD�valuerrW)r!Zperformance_degradedrrrr'2s  
z%Controller.check_performance_degradedcCsZ|j�t���}|tvrdSt�d|�t|}|j��|�	|�||_
|�|�dS)z`
        Sets the active PPD profile based on the content of the ACPI platform profile.
        NzPlatform profile changed: %s)ror�r/r��PLATFORM_PROFILE_MAPPINGrCr�r�rir`r�r�)r!Zplatform_profilerfrrrr6@s

z!Controller.check_platform_profilecCs|jjtdd���pdS)z?
        Loads and returns the saved PPD base profile.
        T)Zno_errorN)ror�rr�r>rrr�_load_base_profileNszController._load_base_profilecCs|j�t|d�dS)zI
        Saves the given PPD profile into the base profile file.
        �
N)roZ
write_to_filer�r!r8rrrr�TszController._save_base_profilecCsN|j��}||krdSt�d|�|j�|�\}}|sFt�t|��t|�S)zM
        Sets the TuneD profile to the given one if not already set.
        TzSetting TuneD profile to '%s')rnr�rCrDr`r��strr�)r!r�Zactive_tuned_profile�okZ	error_msgrrr�_set_tuned_profileZs
zController._set_tuned_profilecCsld|_t|�|_tj|_|��tt|j	�|_
|��|��pD|j
j
|_|�|j�|�|j�|��dS)z-
        Initializes the controller.
        N)r�r@r�rrr�r'rrrnr�r�r�Zdefault_profiler�r`r�r�r>rrrr�gs
zController.initializecCsPt��|j��|j�|jd�s$q|j�t|j	�
���|j��t��dS)zK
        Exports the DBus interface and runs the main daemon loop.
        �N)r�startrwro�waitrrrvr�rgrxrQ�stopr>rrr�runvs

zController.runcCs|jS)zG
        DBus interface for communication with other services.
        )rmr>rrrr_�szController.buscCs|jS)z�
        The base PPD profile. This is the profile to restore when
        all profile holds are released or when tuned-ppd is restarted.
        It may not be equal to the currently active profile.
        )r�r>rrrre�szController.base_profilecCs|j��dS)z4
        Stops the main loop of the daemon.
        N)rr�setr>rrr�	terminate�szController.terminatecCs<|�|jj�||j��sdS|j|kr8t�d|�||_dS)z�
        Sets the currently active profile to the given one, if not already set.
        Does not change the base profile.
        Fr�T)r�r��ppd_to_tunedr�rtr�rrWr�rrrr`�s
zController.switch_profileZsss�uzhold-profilecCs6|tkr$|tkr$tj�dttf��|j�||||�S)zT
        Initiates a profile hold and returns a cookie for referring to it.
        z'Only '%s' and '%s' profiles may be held)rr	r]r�r�r�ra)r!r8r9r:r;rrr�HoldProfile�s

�zController.HoldProfilerzrelease-profilecCsF|j�|�stj�d|��|j�||�s6tj�d��|j�|�dS)z@
        Releases a held profile with the given cookie.
        zNo active hold for cookie '%s'z<Cannot release a profile hold inititated by another process.N)r�rcr]r�r�rkrErjrrr�ReleaseProfile�s
zController.ReleaseProfilecCsdS)zG
        The DBus signal sent when a held profile is released.
        NrrbrrrrS�szController.ProfileReleasedr�zswitch-profilecCsj||jj�|j�vr$tj�d|��t�d|�|j	�
�|�|�sVtj�d|��||_|�
|�dS)z�
        Sets the base profile to the given one and also makes it active.
        If there are any active profile holds, these are cancelled.
        zInvalid profile '%s'zSetting base profile to %szError setting profile %s'N)r�r�rhrtr]r�r�rCr�r�rir`r�r�)r!r8r;rrr�set_active_profile�s

zController.set_active_profilecCs|jS)z;
        Returns the currently active PPD profile.
        )r��r!r;rrr�get_active_profile�szController.get_active_profileZProfilescCs$tjdd�|jj�|j�D�dd�S)zE
        Returns a DBus array of all available PPD profiles.
        cSsg|]}|td��qS))r=ZDriver)�DRIVER)rLr8rrrrZ�rOz+Controller.get_profiles.<locals>.<listcomp>r[r\)r]r^r�r�rhrtr�rrr�get_profiles�s�zController.get_profilesZActionscCstjgdd�S)z[
        Returns a DBus array of all available actions (currently there are none).
        �sr\)r]r^r�rrr�get_actions�szController.get_actionsrcCs|jjS)zE
        Returns the current performance degradation status.
        )r�r�r�rrr�get_performance_degraded�sz#Controller.get_performance_degradedrTcCs
|j��S)z?
        Returns a DBus array of active profile holds.
        )r�rXr�rrr�get_active_profile_holds�sz#Controller.get_active_profile_holdsZVersioncCstSr)rr�rrr�version�szController.version)%rrrrrr�r�r�r�r'r6r�r�r�r�r��propertyr_rer�r`rZexportr�r��signalrSZproperty_setterr�Zproperty_getterr�r�r�r�r�r�r*rrr$rrl�sN











	


rl),rrrZtuned.utils.commandsrZtuned.constsrrrZtuned.ppd.configrr	r
r�enumrZrandomr
rurpr]ryr2r�rCr�r|r~r�r�r�r�r/r�rZProcessEventrr+�objectr7r@Z
interfacesZExportableInterfacerlrrrr�<module>s:�	-\

Youez - 2016 - github.com/yon3zu
LinuXploit