MOON
Server: Apache
System: Linux s5.yayogua.com.py 6.12.0-124.55.3.el10_1.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:54:02 EDT 2026 x86_64
User: sanbercountryclu (1012)
PHP: 8.2.33
Disabled: NONE
Upload Files
File: //lib/python3.12/site-packages/tuned/ppd/__pycache__/controller.cpython-312.pyc
�

�]�i.P���ddlmZmZddlmZddlmZmZmZddl	m
Z
mZmZm
Z
ddlmZddlmZddlZddlZddlZddlZddlZej.�ZdZd	Zd
ZdZdZd
ZdZdZ e
eed�Z!Gd�de�Z"Gd�dejF�Z$Gd�dejF�Z%Gd�de&�Z'Gd�de&�Z(Gd�dejRjT�Z+y)�)�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-power�balanced�performancec��eZdZdZdZdZdZy)�PerformanceDegradedz7
    Possible reasons for performance degradation.
    �zlap-detectedzhigh-operating-temperatureN)�__name__�
__module__�__qualname__�__doc__�NONE�LAP_DETECTED�HIGH_OPERATING_TEMPERATURE���9/usr/lib/python3.12/site-packages/tuned/ppd/controller.pyrr!s����D�!�L�!=�rrc�(��eZdZdZ�fd�Zd�Z�xZS)�PerformanceDegradedEventHandlerz=
    Event handler for checking performance degradation.
    c�F��tt|��||_||_y�N)�superr!�__init__�_controller�_path)�self�
controller�path�	__class__s   �rr%z(PerformanceDegradedEventHandler.__init__.s ���
�-�t�=�?�%�����
rc�l�|j|jk7ry|jj�yr#)�pathnamer'r&�check_performance_degraded�r(�events  r�process_IN_MODIFYz1PerformanceDegradedEventHandler.process_IN_MODIFY3s'���>�>�T�Z�Z�'�����3�3�5r)rrrrr%r1�
__classcell__�r+s@rr!r!*s�����
6rr!c�>��eZdZdZdZ�fd�Zd�Zd�Zd�Zd�Z	�xZ
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�������?c�T��tt|��||_d|_d|_y)NFr)r$r5r%r&�
_file_open�_last_close)r(r)r+s  �rr%z$PlatformProfileEventHandler.__init__Fs(���
�)�4�9�;�%��������rc�H�|jtk7ryd|_d|_y)NTr)r-�PLATFORM_PROFILE_PATHr7r8r/s  r�process_IN_OPENz+PlatformProfileEventHandler.process_IN_OPENLs!���>�>�2�2�������rc�l�|jtk7ryd|_tj�|_y�NF)r-r:r7�timer8r/s  r�process_IN_CLOSE_WRITEz2PlatformProfileEventHandler.process_IN_CLOSE_WRITERs'���>�>�2�2������9�9�;��rc�:�|jtk7ryd|_yr=)r-r:r7r/s  r�process_IN_CLOSE_NOWRITEz4PlatformProfileEventHandler.process_IN_CLOSE_NOWRITEXs���>�>�2�2����rc���|jtk7s:|js.|j|jztj
�kDry|jj�yr#)r-r:r7r8�CLOSE_MODIFY_BUFFERr>r&�check_platform_profiler/s  rr1z-PlatformProfileEventHandler.process_IN_MODIFY]s_���>�>�2�2�d�o�o��IY�IY�\`�\t�\t�It�w{�xA�xA�xC�JC�
����/�/�1r)rrrrrCr%r;r?rAr1r2r3s@rr5r59s)���	�����'� �
2rr5c��eZdZdZd�Zd�Zy)�ProfileHoldz}
    Class holding information about a single profile hold,
    i.e., a temporary profile switch requested by a process.
    c�J�||_||_||_||_||_yr#)�profile�reason�app_id�caller�watch)r(rHrIrJrKrLs      rr%zProfileHold.__init__ks%����������������
rc�J�|j|j|jd�S)zF
        Returns the hold information as a Python dictionary.
        )�Profile�Reason�
ApplicationId)rHrIrJ�r(s r�as_dictzProfileHold.as_dictrs#��
�|�|��k�k�!�[�[�
�	
rN)rrrrr%rRrrrrFrFfs����
rrFc�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�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.
    c�>�i|_t�|_||_yr#)�_holdsr�_cookie_generatorr&)r(r)s  rr%zProfileHoldManager.__init__�s�����!'����%��rc��������fd�}|S)z�
        Returns the callback to invoke when the process with the given ID
        (which requested a hold with the given cookie) disappears.
        c�l��|dk(r.tjd��d��d���j��yy)Nrz
Application 'z' disappeared, releasing hold '�')�log�info�remove)�namerJ�cookier(s ���r�callbackz6ProfileHoldManager._removal_callback.<locals>.callback�s.����r�z����PV�X^�_�`����F�#�rr)r(r_rJr`s``` r�_removal_callbackz$ProfileHoldManager._removal_callback�s���
	$�
�rc�n�td�|jj�D��rtStS)zJ
        Returns the hold to use from the set of all active ones.
        c3�BK�|]}|jtk(���y�wr#)rHr)�.0�holds  r�	<genexpr>z=ProfileHoldManager._effective_hold_profile.<locals>.<genexpr>�s����P�;O�4�t�|�|��.�;O�s�)�anyrV�valuesrr
rQs r�_effective_hold_profilez*ProfileHoldManager._effective_hold_profile�s+���P�4�;�;�;M�;M�;O�P�P�"�"��rc	�f�||jvry|jj|�}|jj�t	j
d|�t	jd|j��tjd|�d|j�d|j�d��y)zC
        Cancels the hold saved under the provided cookie.
        N�ProfileReleased�ActiveProfileHoldszReleasing hold '�': profile '�' by application 'rZ)rV�poprL�cancelr�send_signal�property_changed�
as_dbus_arrayr[r\rHrJ)r(r_res   r�_cancelzProfileHoldManager._cancel�s�������$���{�{���v�&���
�
�������-�v�6�� � �!5�t�7I�7I�7K�L����F�TX�T`�T`�bf�bm�bm�n�orc��tj|jj�D�cgc]}|j	���c}d��Scc}w)zY
        Returns the information about current holds as a DBus-compatible array.
        �a{sv}��	signature)�dbus�ArrayrVrhrR)r(res  rrsz ProfileHoldManager.as_dbus_array�s=���z�z�d�k�k�6H�6H�6J�K�6J�d�4�<�<�>�6J�K�W^�_�_��Ks�Ac	��d}|dk(s||jvr1|jjdd�}|dk(r�"||jvr�1|jjj||j
||��}tjd|�d|�d|�d��t|||||�|j|<tjd|j��|jj|j��|S)z*
        Adds a new profile hold.
        rl��z
Adding hold 'rmrnrZrl)rVrW�randintr&�bus�watch_name_ownerrar[r\rFrrrrs�switch_profileri)r(rHrIrJrKr_rLs       r�addzProfileHoldManager.add�s�������k�V�t�{�{�2��+�+�3�3�A�w�?�F���k�V�t�{�{�2�� � �$�$�5�5�f�d�>T�>T�U[�]c�>d�e������QX�Z`�a�b�)�'�6�6�6�5�Q����F��� � �!5�t�7I�7I�7K�L����'�'��(D�(D�(F�G��
rc��||jvS)zI
        Returns True if there is a hold under the given cookie.
        )rV�r(r_s  r�haszProfileHoldManager.has�s������$�$rc���|j|�t|j�dk7r|j�}n|jj
}|jj
|�y)zf
        Releases the hold saved under the provided cookie and
        sets the next profile.
        rN)rt�lenrVrir&�base_profiler)r(r_�new_profiles   rr]zProfileHoldManager.remove�sT��
	
���V���t�{�{��q� ��6�6�8�K��*�*�7�7�K����'�'��4rc�v�t|jj��D]}|j|��y)z-
        Releases all profile holds.
        N)�listrV�keysrtr�s  r�clearzProfileHoldManager.clear�s,���4�;�;�+�+�-�.�F��L�L�� �/rc�Z�||jvxr|j|j|k(Sr#)rVrK�r(r_rKs   r�check_callerzProfileHoldManager.check_caller�s*������$�M����V�)<�)C�)C�v�)M�MrN)rrrrr%rarirtrsr�r�r]r�r�rrrrTrT}s<���
&�

��
p�`��%�
5�!�NrrTc���eZdZdZ�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zed��Zed��Zd�Zd�Zej.ddd�d��Zej.ddd�d��Zej4d�d��Zej8dd�d��Zej<d�d��Zej<d�d ��Z ej<d!�d"��Z!ej<d#�d$��Z"ej<d%�d&��Z#ej<d'�d(��Z$�xZ%S))�
ControllerzF
    The main tuned-ppd controller, exporting its DBus interface.
    c���tt|��||_||_t�|_tj�|_	d|_
d|_tj�|_tj|j�|_i|_g|_t&j(j+t,�|_t&j(j+t0�|_t&j(j+t4�|_|jj9d|j:�|j=�y)NF�profile_changed)r$r�r%�_bus�_tuned_interfacer�_cmd�	threading�Event�
_terminate�_battery_handler�_on_battery�	pyinotify�WatchManager�_watch_manager�ThreadedNotifier�	_notifier�_inotify_watches�_pinned_virtual_files�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}�tuned_interfacer+s   �rr%zController.__init__�s����
�j�$�(�*���	� /����J��	�#�/�/�+��� $��� ���'�4�4�6���"�3�3�D�4G�4G�H��� "���%'��"�+-�7�7�>�>�:O�+P��(�#%�7�7�>�>�-�#@�� �#%�7�7�>�>�-�#@�� ����/�/�0A�4�C^�C^�_����rc���t|jjtd��|_t
j
d|jrdndz�|j|j�y)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_INTERFACEr�r[r\r�_active_profile)r(�	interface�changed�invalidateds    r�_upower_changedzController._upower_changed�sW�� �� 7� 7� ;� ;�<Q�S^� _�`������+��AQ�AQ�~�Wf�g�h����D�0�0�1rc�B�|sy||jj�k7rtjd�y	|jj
j
||j�}|j|k7r|tjd|z�|jj�||_tj d|j�|tk7r||_|j%|�yyy#t$r!t}tjd|z�Y��wxYw)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)r��active_profiler[�debug�_config�tuned_to_ppd�getr��KeyError�UNKNOWN_PROFILE�warningr�r\�_profile_holdsr�rrr�
_base_profile�_save_base_profile)r(�
tuned_profile�result�errstr�ppd_profiles     rr�z!Controller._tuned_profile_changed�s������D�1�1�@�@�B�B��I�I�d�e��	\��,�,�3�3�7�7�
�t�GW�GW�X�K����;�.��H�H�.��<�=����%�%�'�#.�D� ��$�$�_�d�6J�6J�K��o�-�%0��"��'�'��4�.�/���	\�)�K��K�K�J�]�Z�[�	\�s�0C4�4'D�Dc�j�d|_|jjs.|j�!|jj	�d|_y	|j�n|j
j
tt�}tj|tj�|_|jd|j�|_t|jj!t"d��|_y#tj$j&$r}t(j+|�Yd}~yd}~wwxYw)z;
        Sets up handling of power supply changes.
        FN�PropertiesChangedr�)r�r��battery_detectionr�r]r��
get_object�UPOWER_DBUS_NAME�UPOWER_DBUS_PATHry�	Interface�PROPERTIES_IFACEr�r�r�r�r�r��
exceptions�
DBusExceptionr[r�)r(�upower_proxy�errors   r�_setup_battery_signalingz#Controller._setup_battery_signalings���!����|�|�-�-��$�$�0��%�%�,�,�.�(,��%��	��$�$�,�#�y�y�3�3�4D�FV�W��*.�.�.��t�G\�G\�*]��'�(4�(F�(F�GZ�\`�\p�\p�(q��%�#�D�$;�$;�$?�$?�@U�Wb�$c�d�D������,�,�	��I�I�e����	�s�
B(C6�6D2�D-�-D2c
�P�|jD]}|j��|jj�|jj	t|jj���|jr�|jjttd��|xj|jjtjjt�t j"t%|t���zc_|j&r�|jjtt(d��|xj|jjtjjt(�t j"t%|t(���zc_|j*r�|j,j.r�|jjtt0d��|xj|jjtjjt0�t j2t j"zt j4zt j6zt9|���zc_yyy)z/
        Sets up inotify file watches.
        �r)r*�mask�proc_funN)r��closer�r��rm_watchr�r�rhr��append�openr��	add_watchr�r*�dirnamer��	IN_MODIFYr!r�r�r�r��sysfs_acpi_monitorr:�IN_OPEN�IN_CLOSE_WRITE�IN_CLOSE_NOWRITEr5�r(�fs  r�_setup_inotifyzController._setup_inotify!s���+�+�A�
�G�G�I�,��"�"�(�(�*����$�$�T�$�*?�*?�*F�*F�*H�%I�J��#�#��&�&�-�-�d�=�#�.F�G��!�!�T�%8�%8�%B�%B������Xe�Hf�HQ�H[�H[�Lk�lp�r�MA�&C�&B�
B�!��#�#��&�&�-�-�d�=�#�.F�G��!�!�T�%8�%8�%B�%B������Xe�Hf�HQ�H[�H[�Lk�lp�r�MA�&C�&B�
B�!��+�+����0O�0O��&�&�-�-�d�3H�#�.N�O��!�!�T�%8�%8�%B�%B������Xm�Hn�HQ�HY�HY�\e�\o�\o�Ho�r{�sK�sK�IK�NW�Nh�Nh�Ih�Lg�hl�Lm�&C�&o�
o�!�1P�+rc�b�tj}tjj	t
�r@|jjt
�j�dk(rtj}tjj	t�r@|jjt�j�dk(rtj}||jk7rJtjd|jz�||_t!j"d|j�yy)ze
        Checks the current performance degradation status and sends a signal if it changed.
        �1zPerformance degraded: %srN)rrr�r*�existsr�r��	read_file�striprr�r�_performance_degradedr[r\�valuerrr)r(�performance_degradeds  rr.z%Controller.check_performance_degraded9s��� 3�7�7��
�7�7�>�>�-�(�T�Y�Y�-@�-@��-O�-U�-U�-W�[^�-^�#6�#Q�#Q� �
�7�7�>�>�-�(�T�Y�Y�-@�-@��-O�-U�-U�-W�[^�-^�#6�#C�#C� ��4�#=�#=�=��H�H�/�2F�2L�2L�L�M�)=�D�&��$�$�%:�<P�<V�<V�W�>rc�8�|jjt�j�}|tvryt
j
d|z�t|}|jj�|j|�||_
|j|�y)z`
        Sets the active PPD profile based on the content of the ACPI platform profile.
        NzPlatform profile changed: %s)r�r�r:r��PLATFORM_PROFILE_MAPPINGr[r�r�r�rr�r�)r(�platform_profiler�s   rrDz!Controller.check_platform_profileGs��� �9�9�.�.�/D�E�K�K�M���#;�;���	�	�0�3C�C�D�.�/?�@�����!�!�#����K�(�(�������,rc�h�|jjtd��j�xsdS)z?
        Loads and returns the saved PPD base profile.
        T)�no_errorN)r�r�rr�rQs r�_load_base_profilezController._load_base_profileUs.���y�y�"�"�#8�4�"�H�N�N�P�X�TX�Xrc���|jj�}	|jjj	||j
�}|S#t$rtjd|�YywxYw)z0
        Get TuneD recommended profile.
        z+TuneD recommends profile unknown to PPD: %sN)	r��recommend_profiler�r�r�r�r�r[r�)r(r�r�s   r�_get_recommend_profilez!Controller._get_recommend_profile[sj���-�-�?�?�A�
�	��,�,�3�3�7�7�
�t�GW�GW�X�K�����	��K�K�E�}�U��	�s�0A�A0�/A0c�J�|jjt|dz�y)zI
        Saves the given PPD profile into the base profile file.
        �
N)r��
write_to_filer�r(rHs  rr�zController._save_base_profilegs��	
�	�	��� 5�w��~�Frc��|jj�}||k(rytjd|z�|jj	|�\}}|stjt
|��t|�S)zM
        Sets the TuneD profile to the given one if not already set.
        TzSetting TuneD profile to '%s')r�r�r[r\rr��strr�)r(r��active_tuned_profile�ok�	error_msgs     r�_set_tuned_profilezController._set_tuned_profilemsl�� $�4�4�C�C�E���=�0�����0�=�@�A��-�-�<�<�]�K�
��I���I�I�c�)�n�%��B�x�rc���d|_t|�|_tj|_|j
�tt|j�|_
|j�|j�xs(|j�xs|jj|_|j!|j�|j#|j�|j%�y)z-
        Initializes the controller.
        N)r�rTr�rrr�r.r	rr�r�r�r�r��default_profiler�rr�r�rQs rr�zController.initializezs��� $���0��6���%8�%=�%=��"��'�'�)� ��$�2G�2G�H����%�%�'�"�5�5�7�-�4�;V�;V�;X�-����,�,�	
�����D�.�.�/����� 2� 2�3����rc�F�tj�|jj�|jj	|j
d�s(	|jj	|j
d�s�(|jD]}|j��|jj�|jjt|jj���|jj�tj�y)zK
        Exports the DBus interface and runs the main daemon loop.
        �N)r�startr�r��waitr�r�r�r�r�r�r�r�rh�stopr�s  r�runzController.run�s���	�
�
���������)�)�.�.����!�4���)�)�.�.����!�4��+�+�A�
�G�G�I�,��"�"�(�(�*����$�$�T�$�*?�*?�*F�*F�*H�%I�J����������rc��|jS)zG
        DBus interface for communication with other services.
        )r�rQs rr}zController.bus�s��
�y�y�rc��|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�rQs rr�zController.base_profile�s���!�!�!rc�8�|jj�y)z4
        Stops the main loop of the daemon.
        N)r��setrQs r�	terminatezController.terminate�s��	
�����rc���|j|jjj||j��sy|j
|k7rt
jd|�||_y)z�
        Sets the currently active profile to the given one, if not already set.
        Does not change the base profile.
        Fr�T)rr��ppd_to_tunedr�r�r�rrrr�s  rrzController.switch_profile�s[��
�&�&�t�|�|�'@�'@�'D�'D�W�d�N^�N^�'_�`�����7�*��$�$�_�g�>�#*�D� �r�sss�uzhold-profilec��|tk7r7|tk7r.tjj	dt�dt�d���|j
j
||||�S)zT
        Initiates a profile hold and returns a cookie for referring to it.
        zOnly 'z' and 'z' profiles may be held)rr
ryr�r�r�r�)r(rHrIrJrKs     r�HoldProfilezController.HoldProfile�sQ��
�o�%�'�_�*D��/�/�/�/�=L�o�^��
��"�"�&�&�w����G�Grrzrelease-profilec�*�|jj|�s"tjj	d|z��|jj||�stjj	d��|jj
|�y)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�r�ryr�r�r�r]r�s   r�ReleaseProfilezController.ReleaseProfile�st��
�"�"�&�&�v�.��/�/�/�/�0P�SY�0Y�Z�Z��"�"�/�/���?��/�/�/�/�0n�o�o����"�"�6�*rc��y)zG
        The DBus signal sent when a held profile is released.
        Nrr�s  rrkzController.ProfileReleased�s��
	
rr�zswitch-profilec��||jjj|j�vr"tj
j
d|z��tjd|z�|jj�|j|�s"tj
j
d|z��||_|j|�y)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�rr�r�ryr�r�r[r�r�r�rr�r�)r(rHrKs   r�set_active_profilezController.set_active_profile�s����$�,�,�3�3�8�8��9I�9I�J�J��/�/�/�/�0F��0P�Q�Q��	�	�.��8�9����!�!�#��"�"�7�+��/�/�/�/�0K�g�0U�V�V�$�������(rc��|jS)z;
        Returns the currently active PPD profile.
        )r��r(rKs  r�get_active_profilezController.get_active_profile�s��
�#�#�#r�Profilesc��tj|jjj	|j
�D�cgc]}|td���
c}d��Scc}w)zE
        Returns a DBus array of all available PPD profiles.
        )rN�Driverrvrw)ryrzr�rr�r��DRIVER)r(rKrHs   r�get_profileszController.get_profiles�sP��
�z�z�CG�<�<�C\�C\�Ca�Ca�bf�br�br�Cs�t�Cs���F�
3�Cs�t��
�	
��ts�A�Actionsc�0�tjgd��S)z[
        Returns a DBus array of all available actions (currently there are none).
        �srw)ryrzrs  r�get_actionszController.get_actions�s��
�z�z�"��,�,rrc�.�|jjS)zE
        Returns the current performance degradation status.
        )r�r�rs  r�get_performance_degradedz#Controller.get_performance_degraded�s��
�)�)�/�/�/rrlc�6�|jj�S)z?
        Returns a DBus array of active profile holds.
        )r�rsrs  r�get_active_profile_holdsz#Controller.get_active_profile_holdss��
�"�"�0�0�2�2r�Versionc��tSr#)rrs  r�versionzController.version
s��$�$r)&rrrrr%r�r�r�r�r.rDr�r�r�rr�r
�propertyr}r�rrr�exportrr�signalrk�property_setterr�property_getterrr"r&r(r*r-r2r3s@rr�r��s������$2�5�.�&o�0X�-�Y�
�G��� 
������"��"��
��W�^�^�E�3��/�H�0�H��W�^�^�C��.�/�+�0�+��W�^�^�C��
��
��W���_�.>�?�)�@�)��W���_�-�$�.�$��W���Z�(�
�)�
��W���Y�'�-�(�-��W���2�3�0�4�0��W���1�2�3�3�3��W���Y�'�%�(�%rr�),rrr�tuned.utils.commandsr�tuned.constsrrr�tuned.ppd.configr	r
rr�enumr
�randomrr�r�ryr�r>r�r[r!r�r�r�r�r�r�r:r�r�ProcessEventr!r5�objectrFrT�
interfaces�ExportableInterfacer�rrr�<module>r<s����)�V�V�V�V������	���d�h�h�j��	��?�
�F�
���+��,��0��=�� ��"���>�$�>�6�i�&<�&<�6�*2�)�"8�"8�*2�Z
�&�
�.YN��YN�xv%��#�#�7�7�v%r