관리-도구
편집 파일: controller.cpython-39.pyc
a ����,�ggL����������������������@���s(��d�dl�mZmZ�d�dlmZ�d�dlmZmZmZ�d�dl m Z mZmZm Z �d�dlmZ�d�dlmZ�d�dlZd�dlZd�dlZd�dlZd�dlZe���ZdZd Zd ZdZdZd ZdZdZ e eed�Z!G�dd��de�Z"G�dd��dej#�Z$G�dd��dej#�Z%G�dd��de&�Z'G�dd��de&�Z(G�dd��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�������������������@���s���e�Zd�ZdZdZdZdZdS�)�PerformanceDegradedz7 Possible reasons for performance degradation. ��zlap-detectedzhigh-operating-temperatureN)�__name__� __module__�__qualname__�__doc__�NONE�LAP_DETECTED�HIGH_OPERATING_TEMPERATURE��r���r����8/usr/lib/python3.9/site-packages/tuned/ppd/controller.pyr���!���s���r���c�����������������������s(���e�Zd�ZdZ��fdd�Zdd��Z���ZS�)�PerformanceDegradedEventHandlerz= Event handler for checking performance degradation. c��������������������s���t�t|������||�_||�_d�S��N)�superr����__init__�_controller�_path)�self� controller�path�� __class__r���r���r���.���s����z(PerformanceDegradedEventHandler.__init__c�����������������C���s���|j�|�jkrd�S�|�j����d�S�r���)�pathnamer ���r����check_performance_degraded�r!���Zeventr���r���r����process_IN_MODIFY3���s����z1PerformanceDegradedEventHandler.process_IN_MODIFY)r���r���r���r���r���r)���� __classcell__r���r���r$���r���r���*���s���r���c�����������������������sD���e�Zd�ZdZdZ��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�������?c��������������������s$���t�t|������||�_d|�_d|�_d�S�)NFr���)r���r+���r���r���� _file_open�_last_close�r!���r"���r$���r���r���r���F���s����z$PlatformProfileEventHandler.__init__c�����������������C���s���|j�tkrd�S�d|�_d|�_d�S�)NTr���)r&����PLATFORM_PROFILE_PATHr,���r-���r(���r���r���r����process_IN_OPENL���s���� z+PlatformProfileEventHandler.process_IN_OPENc�����������������C���s"���|j�tkrd�S�d|�_t���|�_d�S��NF)r&���r/���r,����timer-���r(���r���r���r����process_IN_CLOSE_WRITER���s���� z2PlatformProfileEventHandler.process_IN_CLOSE_WRITEc�����������������C���s���|j�tkrd�S�d|�_d�S�r1���)r&���r/���r,���r(���r���r���r����process_IN_CLOSE_NOWRITEX���s���� z4PlatformProfileEventHandler.process_IN_CLOSE_NOWRITEc�����������������C���s6���|j�tks$|�js$|�j|�j�t���kr(d�S�|�j����d�S�r���)r&���r/���r,���r-����CLOSE_MODIFY_BUFFERr2���r����check_platform_profiler(���r���r���r���r)���]���s����$z-PlatformProfileEventHandler.process_IN_MODIFY)r���r���r���r���r5���r���r0���r3���r4���r)���r*���r���r���r$���r���r+���9���s��� r+���c�������������������@���s ���e�Zd�ZdZdd��Zdd��ZdS�)�ProfileHoldz} Class holding information about a single profile hold, i.e., a temporary profile switch requested by a process. c�����������������C���s"���||�_�||�_||�_||�_||�_d�S�r���)�profile�reason�app_id�caller�watch)r!���r8���r9���r:���r;���r<���r���r���r���r���k���s ����zProfileHold.__init__c�����������������C���s���|�j�|�j|�jd�S�)zF Returns the hold information as a Python dictionary. )�ProfileZReasonZ ApplicationId)r8���r9���r:����r!���r���r���r����as_dictr���s�����zProfileHold.as_dictN)r���r���r���r���r���r?���r���r���r���r���r7���f���s���r7���c�������������������@���s`���e�Zd�ZdZdd��Zdd��Zdd��Zdd ��Zd d��Zdd ��Z dd��Z dd��Zdd��Zdd��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. c�����������������C���s���i�|�_�t��|�_||�_d�S�r���)�_holdsr ����_cookie_generatorr���r.���r���r���r���r�������s����zProfileHoldManager.__init__c��������������������s�������fdd�}|S�)z� Returns the callback to invoke when the process with the given ID (which requested a hold with the given cookie) disappears. c��������������������s(���|�dkr$t��d���f��������d�S�)Nr���z1Application '%s' disappeared, releasing hold '%s')�log�info�remove)�name�r:����cookier!���r���r����callback����s����z6ProfileHoldManager._removal_callback.<locals>.callbackr���)r!���rH���r:���rI���r���rG���r����_removal_callback����s����z$ProfileHoldManager._removal_callbackc�����������������C���s ���t�dd��|�j���D���rtS�tS�)zJ Returns the hold to use from the set of all active ones. c�����������������s���s���|�]}|j�tkV��qd�S�r���)r8���r�����.0�holdr���r���r���� <genexpr>���������z=ProfileHoldManager._effective_hold_profile.<locals>.<genexpr>)�anyrA����valuesr���r ���r>���r���r���r����_effective_hold_profile����s����z*ProfileHoldManager._effective_hold_profilec�����������������C���s\���||�j�vrdS�|�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<����cancelr���Zsend_signal�property_changed� as_dbus_arrayrC���rD���r8���r:���)r!���rH���rM���r���r���r����_cancel����s���� zProfileHoldManager._cancelc�����������������C���s���t�jdd��|�j���D��dd�S�)zY Returns the information about current holds as a DBus-compatible array. c�����������������S���s���g�|�]}|�����qS�r���)r?���rK���r���r���r���� <listcomp>����rO���z4ProfileHoldManager.as_dbus_array.<locals>.<listcomp>�a{sv}�Z signature)�dbus�ArrayrA���rQ���r>���r���r���r���rX�������s����z ProfileHoldManager.as_dbus_arrayc�����������������C���s����d}|dks||�j�v�r&|�j�dd�}q|�jj�||��||��}t�d|||f���t |||||�|�j�|<�t �d|������|�j� |������|S�)z* Adds a new profile hold. r���l������z2Adding hold '%s': profile '%s' by application '%s'rT���)rA���rB���Zrandintr����busZwatch_name_ownerrJ���rC���rD���r7���r���rW���rX����switch_profilerR���)r!���r8���r9���r:���r;���rH���r<���r���r���r����add����s����zProfileHoldManager.addc�����������������C���s ���||�j�v�S�)zI Returns True if there is a hold under the given cookie. )rA����r!���rH���r���r���r����has����s����zProfileHoldManager.hasc�����������������C���s:���|���|��t|�j�dkr"|����}n|�jj}|�j�|��dS�)zf Releases the hold saved under the provided cookie and sets the next profile. r���N)rY����lenrA���rR���r����base_profiler`���)r!���rH����new_profiler���r���r���rE�������s ���� zProfileHoldManager.removec�����������������C���s"���t�|�j����D�]}|��|��qdS�)z- Releases all profile holds. N)�listrA����keysrY���rb���r���r���r����clear����s����zProfileHoldManager.clearc�����������������C���s���||�j�v�o|�j�|�j|kS�r���)rA���r;����r!���rH���r;���r���r���r����check_caller����s����zProfileHoldManager.check_callerN)r���r���r���r���r���rJ���rR���rY���rX���ra���rc���rE���ri���rk���r���r���r���r���r@���}���s���r@���c�����������������������s^��e�Zd�ZdZ��fdd�Zdd��Zdd��Zdd ��Zd d��Zdd ��Z dd��Z dd��Zdd��Zdd��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. c��������������������s����t�t|������||�_||�_t��|�_t���|�_ d�|�_ d|�_t� ��|�_t�|�j�|�_i�|�_tj�t�|�_tj�t�|�_tj�t�|�_|�j�d|�j��|�����d�S�)NFZprofile_changed)r���rl���r����_bus�_tuned_interfacer����_cmd� threading�Event� _terminate�_battery_handler�_on_battery� pyinotifyZWatchManager�_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$���r���r���r�������s���� zController.__init__c�����������������C���s<���t�|�j�td��|�_t�d|�jr$dnd���|��|�j��dS�)zG The callback to invoke when the power supply changes. � OnBatteryzBattery status changed: zDC (battery)z AC (charging)N) �bool�_upower_properties�Get�UPOWER_DBUS_INTERFACErt���rC���rD���r`����_active_profile)r!���Z interfaceZchangedZinvalidatedr���r���r����_upower_changed����s����zController._upower_changedc�����������������C���s����|sdS�||�j����kr$t�d��dS�z|�jj�||�j�}W�n$�ty^���t }t� d|���Y�n0�|�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�_configZtuned_to_ppd�getrt����KeyError�UNKNOWN_PROFILEZwarningr����rD����_profile_holdsri���r���rW���� _base_profile�_save_base_profile)r!���� tuned_profile�resultZerrstrZppd_profiler���r���r���r��������s$���� z!Controller._tuned_profile_changedc�������������� ���C���s����d|�_�|�jjs,|�jdur(|�j����d|�_dS�zP|�jdu�rf|�j�tt�}t � |t j�|�_|� d|�j�|�_t|�j�td��|�_�W�n2�t jjy��}�zt�|��W�Y�d}~n d}~0�0�dS�)z; Sets up handling of power supply changes. FNZPropertiesChangedr����)rt���r����Zbattery_detectionrs���rE���rm���Z get_object�UPOWER_DBUS_NAME�UPOWER_DBUS_PATHr]���Z InterfaceZPROPERTIES_IFACEr����r����r����r����r����r����� exceptions� DBusExceptionrC���r����)r!���Zupower_proxy�errorr���r���r����_setup_battery_signaling ��s���� z#Controller._setup_battery_signalingc�����������������C���s����|�j��t|�j������|�jrH|��j|�j�jtj� t �tjt t |��d�O��_|�jrz|��j|�j�jtj� t�tjt t|��d�O��_|�jr�|�jjr�|��j|�j�jtj� t�tjtjB�tjB�tjB�t|��d�O��_dS�)z/ Sets up inotify file watches. )r#����maskZproc_funN)rv����rm_watchrg���rx���rQ���r}���Z add_watchry���r#����dirnamer|���ru���Z IN_MODIFYr���r���r~���r{���r����Zthinkpad_function_keysr/���ZIN_OPENZIN_CLOSE_WRITEZIN_CLOSE_NOWRITEr+���r>���r���r���r����_setup_inotify ��s ����� � �zController._setup_inotifyc�����������������C���s����t�j}tj�t�r,|�j�t����dkr,t�j }tj�t �rR|�j�t ����dkrRt�j}||�jkr�t �d|j���||�_t�d|j��dS�)ze Checks the current performance degradation status and sends a signal if it changed. �1zPerformance degraded: %sr���N)r���r���ry���r#����existsr|���ro���� read_file�stripr���r~���r����_performance_degradedrC���rD����valuer���rW���)r!���Zperformance_degradedr���r���r���r'���2��s���� z%Controller.check_performance_degradedc�����������������C���sZ���|�j��t����}|tvrdS�t�d|���t|�}|�j����|�� |��||�_ |��|��dS�)z` Sets the active PPD profile based on the content of the ACPI platform profile. NzPlatform profile changed: %s)ro���r����r/���r�����PLATFORM_PROFILE_MAPPINGrC���r����r����ri���r`���r����r����)r!���Zplatform_profilerf���r���r���r���r6���@��s���� z!Controller.check_platform_profilec�����������������C���s���|�j�jtdd����pdS�)z? Loads and returns the saved PPD base profile. T)Zno_errorN)ro���r����r���r����r>���r���r���r����_load_base_profileN��s����zController._load_base_profilec�����������������C���s���|�j��t|d���dS�)zI Saves the given PPD profile into the base profile file. � N)ro���Z write_to_filer����r!���r8���r���r���r���r����T��s����zController._save_base_profilec�����������������C���sN���|�j����}||krdS�t�d|���|�j��|�\}}|sFt�t|���t|�S�)zM Sets the TuneD profile to the given one if not already set. TzSetting TuneD profile to '%s')rn���r����rC���rD���r`���r�����strr����)r!���r����Zactive_tuned_profile�okZ error_msgr���r���r����_set_tuned_profileZ��s���� zController._set_tuned_profilec�����������������C���sl���d|�_�t|��|�_tj|�_|�����tt|�j �|�_ |�����|����pD|�j j |�_|��|�j��|��|�j��|�����dS�)z- Initializes the controller. N)r����r@���r����r���r���r����r'���r���r���rn���r����r����r����Zdefault_profiler����r`���r����r����r>���r���r���r���r����g��s���� zController.initializec�����������������C���sP���t�����|�j����|�j�|�jd�s$q|�j�t|�j � �����|�j����t�����dS�)zK Exports the DBus interface and runs the main daemon loop. ����N)r����startrw���ro����waitrr���rv���r����rg���rx���rQ����stopr>���r���r���r����runv��s���� zController.runc�����������������C���s���|�j�S�)zG DBus interface for communication with other services. )rm���r>���r���r���r���r_������s����zController.busc�����������������C���s���|�j�S�)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>���r���r���r���re������s����zController.base_profilec�����������������C���s���|�j�����dS�)z4 Stops the main loop of the daemon. N)rr����setr>���r���r���r���� terminate���s����zController.terminatec�����������������C���s<���|���|�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����rt���r����r���rW���r����r���r���r���r`������s���� zController.switch_profileZsss�uzhold-profilec�����������������C���s6���|t�kr$|tkr$tj�dt�tf���|�j�||||�S�)zT Initiates a profile hold and returns a cookie for referring to it. z'Only '%s' and '%s' profiles may be held)r���r ���r]���r����r����r����ra���)r!���r8���r9���r:���r;���r���r���r����HoldProfile���s ���� �zController.HoldProfiler���zrelease-profilec�����������������C���sF���|�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����rc���r]���r����r����rk���rE���rj���r���r���r����ReleaseProfile���s ����zController.ReleaseProfilec�����������������C���s���dS�)zG The DBus signal sent when a held profile is released. Nr���rb���r���r���r���rS������s����zController.ProfileReleasedr����zswitch-profilec�����������������C���sj���||�j�j�|�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����rh���rt���r]���r����r����rC���r����r����ri���r`���r����r����)r!���r8���r;���r���r���r����set_active_profile���s���� zController.set_active_profilec�����������������C���s���|�j�S�)z; Returns the currently active PPD profile. )r�����r!���r;���r���r���r����get_active_profile���s����zController.get_active_profileZProfilesc�����������������C���s$���t�jdd��|�jj�|�j�D��dd�S�)zE Returns a DBus array of all available PPD profiles. c�����������������S���s���g�|�]}|t�d���qS�))r=���ZDriver)�DRIVER)rL���r8���r���r���r���rZ������rO���z+Controller.get_profiles.<locals>.<listcomp>r[���r\���)r]���r^���r����r����rh���rt���r����r���r���r����get_profiles���s�����zController.get_profilesZActionsc�����������������C���s���t�jg�dd�S�)z[ Returns a DBus array of all available actions (currently there are none). �sr\���)r]���r^���r����r���r���r����get_actions���s����zController.get_actionsr���c�����������������C���s���|�j�jS�)zE Returns the current performance degradation status. )r����r����r����r���r���r����get_performance_degraded���s����z#Controller.get_performance_degradedrT���c�����������������C���s ���|�j����S�)z? Returns a DBus array of active profile holds. )r����rX���r����r���r���r����get_active_profile_holds���s����z#Controller.get_active_profile_holdsZVersionc�����������������C���s���t�S�r���)r���r����r���r���r����version���s����zController.version)%r���r���r���r���r���r����r����r����r����r'���r6���r����r����r����r����r�����propertyr_���re���r����r`���r���Zexportr����r�����signalrS���Zproperty_setterr����Zproperty_getterr����r����r����r����r����r����r*���r���r���r$���r���rl�������sN��� rl���),r���r���r���Ztuned.utils.commandsr���Ztuned.constsr���r���r���Ztuned.ppd.configr���r ���r ���r����enumr���Zrandomr ���ru���rp���r]���ry���r2���r����rC���r����r|���r~���r����r����r����r����r/���r����r���ZProcessEventr���r+����objectr7���r@���Z interfacesZExportableInterfacerl���r���r���r���r����<module>���s:���� -\