HEX
Server: Apache
System: Linux nc-ph-4101.simplemoneygoals.com 5.14.0-503.21.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jan 12 09:45:05 EST 2025 x86_64
User: dailygoldindex (1004)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //lib/python3.9/site-packages/tuned/plugins/__pycache__/plugin_scheduler.cpython-39.pyc
a

,�g���@s"ddlmZddlTddlZddlZddlTddlZzddlZWne	yRYn0ddl
Z
ddlmZddl
Z
ddlmZddlZddlZddlZddlZz
ejWney�ddlZYn0ej��ZGdd�de�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�dej�Z dS)�)�base)�*�N)�commandsc@s0eZdZddd�Zedd��Zejdd��ZdS)�SchedulerParamsNcCs(||_||_||_||_||_||_dS�N)�_cmd�cmdline�	scheduler�priority�affinity�cgroup)�self�cmdr	r
rrr
�r�B/usr/lib/python3.9/site-packages/tuned/plugins/plugin_scheduler.py�__init__"szSchedulerParams.__init__cCs |jdurdS|j�|j�SdSr)�	_affinityrZbitmask2cpulist�rrrrr+s
zSchedulerParams.affinitycCs"|durd|_n|j�|�|_dSr)rrZcpulist2bitmask�r�valuerrrr2s)NNNNN)�__name__�
__module__�__qualname__r�propertyr�setterrrrrr!s�
	
rc@seZdZdd�ZdS)�
IRQAffinitiescCsi|_d|_g|_dSr)�irqs�default�unchangeablerrrrr:szIRQAffinities.__init__N)rrrrrrrrr9src@speZdZdZdddddd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�SchedulerUtilsz=
	Class encapsulating scheduler implementation in os module
	�
SCHED_FIFO�SCHED_BATCH�SCHED_RR�SCHED_OTHER�
SCHED_IDLE)�f�b�r�o�icCs8tdd�|j��D��|_tdd�|j��D��|_dS)Ncss |]\}}|tt|�fVqdSr��getattr�os��.0�k�namerrr�	<genexpr>O�z*SchedulerUtils.__init__.<locals>.<genexpr>css|]}tt|�|fVqdSrr+�r/r1rrrr2Qr3��dict�_dict_schedcfg2schedconst�items�_dict_schedcfg2num�values�_dict_num2schedconstrrrrrMszSchedulerUtils.__init__cCs|j�|�Sr)r9�get)r�
str_schedulerrrr�sched_cfg_to_numSszSchedulerUtils.sched_cfg_to_numcCs|j�|�Sr)r;r<)rr
rrr�sched_num_to_constWsz!SchedulerUtils.sched_num_to_constcCs
t�|�Sr)r-�sched_getscheduler�r�pidrrr�
get_schedulerZszSchedulerUtils.get_schedulercCst�||t�|��dSr)r-�sched_setscheduler�sched_param�rrB�sched�priorrr�
set_scheduler]szSchedulerUtils.set_schedulercCs
t�|�Sr)r-�sched_getaffinityrArrr�get_affinity`szSchedulerUtils.get_affinitycCst�||�dSr)r-�sched_setaffinity�rrBrrrr�set_affinitycszSchedulerUtils.set_affinitycCst�|�jSr)r-�sched_getparam�sched_priorityrArrr�get_priorityfszSchedulerUtils.get_prioritycCs
t�|�Sr)r-�sched_get_priority_min�rrGrrr�get_priority_miniszSchedulerUtils.get_priority_mincCs
t�|�Sr)r-�sched_get_priority_maxrSrrr�get_priority_maxlszSchedulerUtils.get_priority_maxN)rrr�__doc__r7rr>r?rCrIrKrNrQrTrVrrrrr @s"�r c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�SchedulerUtilsSchedutilszE
	Class encapsulating scheduler implementation in schedutils module
	cCs8tdd�|j��D��|_tdd�|j��D��|_dS)Ncss |]\}}|tt|�fVqdSr�r,�
schedutilsr.rrrr2ur3z4SchedulerUtilsSchedutils.__init__.<locals>.<genexpr>css|]}tt|�|fVqdSrrYr4rrrr2wr3r5rrrrrssz!SchedulerUtilsSchedutils.__init__cCs
t�|�Sr)rZrCrArrrrCysz&SchedulerUtilsSchedutils.get_schedulercCst�|||�dSr)rZrIrFrrrrI|sz&SchedulerUtilsSchedutils.set_schedulercCs
t�|�Sr)rZrKrArrrrKsz%SchedulerUtilsSchedutils.get_affinitycCst�||�dSr)rZrNrMrrrrN�sz%SchedulerUtilsSchedutils.set_affinitycCs
t�|�Sr)rZrQrArrrrQ�sz%SchedulerUtilsSchedutils.get_prioritycCs
t�|�Sr)rZrTrSrrrrT�sz)SchedulerUtilsSchedutils.get_priority_mincCs
t�|�Sr)rZrVrSrrrrV�sz)SchedulerUtilsSchedutils.get_priority_maxN)rrrrWrrCrIrKrNrQrTrVrrrrrXosrXcs>eZdZdZdddd�Z�fdd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd�d&d'�Zd(d)�Zd*d+�Zd,d-�Zd�d.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$d�dDdE�Z%dFdG�Z&dHdI�Z'�fdJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+e,j-f�fdRdS�	Z.dTdU�Z/dVdW�Z0�fdXdY�Z1dZd[�Z2d\d]�Z3d^d_�Z4e5d`d%da�dbdc��Z6e5ddd%da�dedf��Z7e5dgd%da�dhdi��Z8e5djd%da�dkdl��Z9e5dmd%da�dndo��Z:e5dpd%da�dqdr��Z;e5dsd%da�dtdu��Z<dvdw�Z=dxdy�Z>dzd{�Z?d�d|d}�Z@d~d�ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZIe5d�d%d�d��d�d���ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d�d��ZOePd��d�d���ZQeRd��d�d���ZSePd��d�d���ZTeRd��d�d���ZUePd��d�d���ZVeRd��d�d���ZWePd��d�d���ZXeRd��d�d���ZYePd��d�d���ZZeRd��d�d���Z[ePd��d�d���Z\eRd��d�d���Z]ePd��d�d���Z^eRd��d�d���Z_ePdƒd�dĄ�Z`eRdƒd�dƄ�ZaePdǃd�dɄ�ZbeRdǃd�d˄�ZcePd̃d�d΄�ZdeRd̃d�dЄ�ZeePdуd�dӄ�ZfeRdуd�dՄ�Zg�ZhS)��SchedulerPluginaX.
	Allows tuning of scheduling priorities, process/thread/IRQ
	affinities, and CPU isolation.

	To prevent processes/threads/IRQs from using certain CPUs, use
	the [option]`isolated_cores` option. It changes process/thread
	affinities, IRQs affinities and it sets `default_smp_affinity`
	for IRQs. The CPU affinity mask is adjusted for all processes and
	threads matching [option]`ps_whitelist` option subject to success
	of the `sched_setaffinity()` system call. The default setting of
	the [option]`ps_whitelist` regular expression is `.*` to match all
	processes and thread names. To exclude certain processes and threads
	use [option]`ps_blacklist` option. The value of this option is also
	interpreted as a regular expression and process/thread names (`ps -eo
	cmd`) are matched against that expression. Profile rollback allows
	all matching processes and threads to run on all CPUs and restores
	the IRQ settings prior to the profile application.

	Multiple regular expressions for [option]`ps_whitelist`
	and [option]`ps_blacklist` options are allowed and separated by
	`;`. Quoted semicolon `\;` is taken literally.

	.Isolate CPUs 2-4
	====
	----
	[scheduler]
	isolated_cores=2-4
	ps_blacklist=.*pmd.*;.*PMD.*;^DPDK;.*qemu-kvm.*
	----
	Isolate CPUs 2-4 while ignoring processes and threads matching
	`ps_blacklist` regular expressions.
	====

	The [option]`irq_process` option controls whether the scheduler plugin
	applies the `isolated_cores` parameter to IRQ affinities. The default
	value is `true`, which means that the scheduler plugin will move all
	possible IRQs away from the isolated cores. When `irq_process` is set
	to `false`, the plugin will not change any IRQ affinities.

	The [option]`default_irq_smp_affinity` option controls the values
	*TuneD* writes to `/proc/irq/default_smp_affinity`. The file specifies
	default affinity mask that applies to all non-active IRQs. Once an
	IRQ is allocated/activated its affinity bitmask will be set to the
	default mask.

	The following values are supported:

	* `calc`
	+
	The content of `/proc/irq/default_smp_affinity` will be calculated
	from the `isolated_cores` parameter. Non-isolated cores
	are calculated as an inversion of the `isolated_cores`. Then
	the intersection of the non-isolated cores and the previous
	content of `/proc/irq/default_smp_affinity` is written to
	`/proc/irq/default_smp_affinity`. If the intersection is
	an empty set, then just the non-isolated cores are written to
	`/proc/irq/default_smp_affinity`. This behavior is the default if
	the parameter `default_irq_smp_affinity` is omitted.

	* `ignore`
	+
	*TuneD* will not touch `/proc/irq/default_smp_affinity`.

	* an explicit cpulist
	+
	The cpulist (such as `1,3-4`) is unpacked and written directly to
	`/proc/irq/default_smp_affinity`.

	.An explicit CPU list to set the default IRQ smp affinity to CPUs 0 and 2
	====
	----
	[scheduler]
	isolated_cores=1,3
	default_irq_smp_affinity=0,2
	----
	====

	To adjust scheduling policy, priority and affinity for a group of
	processes/threads, use the following syntax.

	[subs="quotes"]
	----
	group.__groupname__=__rule_prio__:__sched__:__prio__:__affinity__:__regex__
	----

	Here, `__rule_prio__` defines internal *TuneD* priority of the
	rule. Rules are sorted based on priority. This is needed for
	inheritence to be able to reorder previously defined rules. Equal
	`__rule_prio__` rules should be processed in the order they were
	defined. However, this is Python interpreter dependant. To disable
	an inherited rule for `__groupname__` use:

	[subs="quotes"]
	----
	group.__groupname__=
	----

	`__sched__` must be one of:
	*`f`* for FIFO,
	*`b`* for batch,
	*`r`* for round robin,
	*`o`* for other,
	*`*`* do not change.

	`__affinity__` is CPU affinity in hexadecimal. Use `*` for no change.

	`__prio__` scheduling priority (see `chrt -m`).

	`__regex__` is Python regular expression. It is matched against the output of:

	[subs="quotes"]
	----
	ps -eo cmd
	----

	Any given process name may match more than one group. In such a case,
	the priority and scheduling policy are taken from the last matching
	`__regex__`.

	.Setting scheduling policy and priorities to kernel threads and watchdog
	====
	----
	[scheduler]
	group.kthreads=0:*:1:*:\[.*\]$
	group.watchdog=0:f:99:*:\[watchdog.*\]
	----
	====

	The scheduler plug-in uses perf event loop to catch newly created
	processes. By default it listens to `perf.RECORD_COMM` and
	`perf.RECORD_EXIT` events. By setting [option]`perf_process_fork`
	option to `true`, `perf.RECORD_FORK` events will be also listened
	to. In other words, child processes created by the `fork()` system
	call will be processed. Since child processes inherit CPU affinity
	from their parents, the scheduler plug-in usually does not need to
	explicitly process these events. As processing perf events can
	pose a significant CPU overhead, the [option]`perf_process_fork`
	option parameter is set to `false` by default. Due to this, child
	processes are not processed by the scheduler plug-in.

	The CPU overhead of the scheduler plugin can be mitigated by using
	the scheduler [option]`runtime` option and setting it to `0`. This
	will completely disable the dynamic scheduler functionality and the
	perf events will not be monitored and acted upon. The disadvantage
	ot this approach is the procees/thread tuning will be done only at
	profile application.

	.Disabling the scheduler dynamic functionality
	====
	----
	[scheduler]
	runtime=0
	isolated_cores=1,3
	----
	====

	NOTE: For perf events, memory mapped buffer is used. Under heavy load
	the buffer may overflow. In such cases the `scheduler` plug-in
	may start missing events and failing to process some newly created
	processes. Increasing the buffer size may help. The buffer size can
	be set with the [option]`perf_mmap_pages` option. The value of this
	parameter has to expressed in powers of 2. If it is not the power
	of 2, the nearest higher power of 2 value is calculated from it
	and this calculated value used. If the [option]`perf_mmap_pages`
	option is omitted, the default kernel value is used.

	The scheduler plug-in supports process/thread confinement using
	cgroups v1.

	[option]`cgroup_mount_point` option specifies the path to mount the
	cgroup filesystem or where *TuneD* expects it to be mounted. If unset,
	`/sys/fs/cgroup/cpuset` is expected.

	If [option]`cgroup_groups_init` option is set to `1` *TuneD*
	will create (and remove) all cgroups defined with the `cgroup*`
	options. This is the default behavior. If it is set to `0` the
	cgroups need to be preset by other means.

	If [option]`cgroup_mount_point_init` option is set to `1`,
	*TuneD* will create (and remove) the cgroup mountpoint. It implies
	`cgroup_groups_init = 1`. If set to `0` the cgroups mount point
	needs to be preset by other means. This is the default behavior.

	The [option]`cgroup_for_isolated_cores` option is the cgroup
	name used for the [option]`isolated_cores` option functionality. For
	example, if a system has 4 CPUs, `isolated_cores=1` means that all
	processes/threads will be moved to CPUs 0,2-3.
	The scheduler plug-in will isolate the specified core by writing
	the calculated CPU affinity to the `cpuset.cpus` control file of
	the specified cgroup and move all the matching processes/threads to
	this group. If this option is unset, classic cpuset affinity using
	`sched_setaffinity()` will be used.

	[option]`cgroup.__cgroup_name__` option defines affinities for
	arbitrary cgroups. Even hierarchic cgroups can be used, but the
	hieararchy needs to be specified in the correct order. Also *TuneD*
	does not do any sanity checks here, with the exception that it forces
	the cgroup to be under [option]`cgroup_mount_point`.

	The syntax of the scheduler option starting with `group.` has been
	augmented to use `cgroup.__cgroup_name__` instead of the hexadecimal
	`__affinity__`. The matching processes will be moved to the cgroup
	`__cgroup_name__`. It is also possible to use cgroups which have
	not been defined by the [option]`cgroup.` option as described above,
	i.e. cgroups not managed by *TuneD*.

	All cgroup names are sanitized by replacing all all dots (`.`) with
	slashes (`/`). This is to prevent the plug-in from writing outside
	[option]`cgroup_mount_point`.

	.Using cgroups v1 with the scheduler plug-in
	====
	----
	[scheduler]
	cgroup_mount_point=/sys/fs/cgroup/cpuset
	cgroup_mount_point_init=1
	cgroup_groups_init=1
	cgroup_for_isolated_cores=group
	cgroup.group1=2
	cgroup.group2=0,2
	
	group.ksoftirqd=0:f:2:cgroup.group1:ksoftirqd.*
	ps_blacklist=ksoftirqd.*;rcuc.*;rcub.*;ktimersoftd.*
	isolated_cores=1
	----
	Cgroup `group1` has the affinity set to CPU 2 and the cgroup `group2`
	to CPUs 0,2. Given a 4 CPU setup, the [option]`isolated_cores=1`
	option causes all processes/threads to be moved to CPU
	cores 0,2-3. Processes/threads that are blacklisted by the
	[option]`ps_blacklist` regular expression will not be moved.
	
	The scheduler plug-in will isolate the specified core by writing the
	CPU affinity 0,2-3 to the `cpuset.cpus` control file of the `group`
	and move all the matching processes/threads to this cgroup.
	====

	Option [option]`cgroup_ps_blacklist` allows excluding processes
	which belong to the blacklisted cgroups. The regular expression specified
	by this option is matched against cgroup hierarchies from
	`/proc/PID/cgroups`. Cgroups v1 hierarchies from `/proc/PID/cgroups`
	are separated by commas ',' prior to regular expression matching. The
	following is an example of content against which the regular expression
	is matched against: `10:hugetlb:/,9:perf_event:/,8:blkio:/`

	Multiple regular expressions can be separated by semicolon ';'. The
	semicolon represents a logical 'or' operator.

	.Cgroup-based exclusion of processes from the scheduler
	====
	----
	[scheduler]
	isolated_cores=1
	cgroup_ps_blacklist=:/daemons\b
	----
	The scheduler plug-in will move all processes away from core 1 except processes which
	belong to cgroup '/daemons'. The '\b' is a regular expression
	metacharacter that matches a word boundary.
	----
	[scheduler]
	isolated_cores=1
	cgroup_ps_blacklist=\b8:blkio:
	----
	The scheduler plug-in will exclude all processes which belong to a cgroup
	with hierarchy-ID 8 and controller-list blkio.
	====

	Kernels 5.13 and newer moved some `sched_` and `numa_balancing_` kernel run-time
	parameters from `/proc/sys/kernel`, managed by the `sysctl` utility, to
	`debugfs`, typically mounted under `/sys/kernel/debug`.  TuneD provides an
	abstraction mechanism for the following parameters via the scheduler plug-in:
	[option]`sched_min_granularity_ns`, [option]`sched_latency_ns`,
	[option]`sched_wakeup_granularity_ns`, [option]`sched_tunable_scaling`,
	[option]`sched_migration_cost_ns`, [option]`sched_nr_migrate`,
	[option]`numa_balancing_scan_delay_ms`,
	[option]`numa_balancing_scan_period_min_ms`,
	[option]`numa_balancing_scan_period_max_ms` and
	[option]`numa_balancing_scan_size_mb`.
	Moreover in kernel 6.6 and newer support for the `sched_wakeup_granularity_ns` and
	`sched_latency_ns` were removed. The `sched_min_granularity_ns` was renamed to
	`sched_base_slice_ns`. Based on the kernel used, TuneD will write the specified
	value to the correct location or ignore it. For the compatibility the alias
	[option]`sched_base_slice_ns` was added, but the [option]`sched_min_granularity_ns`
	can be still used instead.

	.Set tasks' "cache hot" value for migration decisions.
	====
	----
	[scheduler]
	sched_migration_cost_ns=500000
	----
	On the old kernels, this is equivalent to:
	----
	[sysctl]
	kernel.sched_migration_cost_ns=500000
	----
	that is, value `500000` will be written to `/proc/sys/kernel/sched_migration_cost_ns`.
	However, on more recent kernels, the value `500000` will be written to
	`/sys/kernel/debug/sched/migration_cost_ns`.
	====
	�Z
base_slice_ns)�wakeup_granularity_ns�min_granularity_ns�
latency_nsc	

s6tt|��||||||||�d|_tj|_ttj�|_	|durh|�
tjtj�|_t|�tj
tj��|_	t�|_d|_i|_d|_d|_d|_d|_zt��|_Wn<ttfy�|j�tj�}	|	r�|j�|	�ndg|_Yn0|jdd�|_d|_ |jdd�|_!d|_"zt#�|_$Wnt�y0t%�|_$Yn0dS)NTz.*r\rr
)Zcommand_name�irq)&�superr[rZ_has_dynamic_options�constsZCFG_DEF_DAEMON�_daemon�intZCFG_DEF_SLEEP_INTERVAL�_sleep_interval�get_boolZ
CFG_DAEMONr<ZCFG_SLEEP_INTERVALrr�_secure_boot_hint�_sched_knob_paths_cache�
_ps_whitelist�
_ps_blacklist�_kthread_process�_cgroup_ps_blacklist_re�perfZcpu_map�_cpus�	NameError�AttributeError�	read_fileZSYSFS_CPUS_PRESENT_PATH�cpulist_unpackZ_storage_key�_scheduler_storage_key�_irq_process�_irq_storage_key�_evlistr �_scheduler_utilsrX)
rZmonitor_repositoryZstorage_factoryZhardware_inventoryZdevice_matcherZdevice_matcher_udevZplugin_instance_factoryZ
global_cfgZ	variables�cpus��	__class__rrr�s>��zSchedulerPlugin.__init__cCsT|durdSzt|�}Wnty,YdS0|dkr:dStdt�t�|d���S)Nr�)rd�
ValueError�mathZceil�log)rZ
mmap_pagesZmprrr�_calc_mmap_pages�sz SchedulerPlugin._calc_mmap_pagescs
d|_d|_d|_d|_�j��ji��_t�j�dkr^t	�
d����i�_�j��j�t
��_d�_d�_d�_t��fdd�|j��D���_|j|_�j�|jd�}��|�}|dkr�t	�d|�d}|dur�t|�|kr�t	�
d	||f�|jD]}�j�|j|�|j|<�q�j�|j�d
d��dk�rDd|_t� �|_!�j"�r|j�rz�t#�$�|_%t#j&t#j't#j(ddddddt#j)t#j*Bd
�	}|j+�j,|j%d�t#�-�j,|j%�|_|j�.|�|du�r�|j�/�n|jj/|d�Wnt	�0d�d|_Yn0dS)NFTrz0recovering scheduling settings from previous runcsJg|]B\}}|dd�dkrt|�dkr��|dd���j�|�f�qS�N�zcgroup.)�len�_sanitize_cgroup_path�
_variables�expand)r/�optionrrrr�
<listcomp>s"�z2SchedulerPlugin._instance_init.<locals>.<listcomp>�perf_mmap_pageszKInvalid 'perf_mmap_pages' value specified: '%s', using default kernel valuezL'perf_mmap_pages' value has to be power of two, specified: '%s', using: '%d'Zruntimer�0)	�typeZconfigZtask�comm�mmapZfreqZ
wakeup_eventsZ	watermarkZsample_type)rx�threads)Zpageszupython-perf unavailable, disabling perf support and runtime tuning, you can try to (re)install python(3)-perf package)1rvZ_has_dynamic_tuningZ_has_static_tuning�_runtime_tuning�_storager<rs�_scheduler_originalr�r~�info�_restore_ps_affinity�unsetr6�_cgroups_original_affinityr�_cgroup_affinity_initialized�_cgroup�collections�OrderedDict�optionsr8�_cgroups�
_schedulerr�r�r�error�strrrf�	threading�Event�
_terminatercrmZ
thread_mapZ_threads�evselZ
TYPE_SOFTWAREZCOUNT_SW_DUMMYZ
SAMPLE_TIDZ
SAMPLE_CPU�openrnZevlist�addr��warning)r�instanceZperf_mmap_pages_rawr�r0r�rrr�_instance_init�sh�
�

�



�

zSchedulerPlugin._instance_initcCs&|jr"|j��D]}t�|j�qdSr)rv�
get_pollfdr-�closer1)rr��fdrrr�_instance_cleanup5sz!SchedulerPlugin._instance_cleanupcCs8dtjddddddddddddddddddddddd�S)NFT�calcZfalse)�isolated_cores�cgroup_mount_point�cgroup_mount_point_init�cgroup_groups_init�cgroup_for_isolated_cores�cgroup_ps_blacklist�ps_whitelist�ps_blacklist�kthread_process�irq_process�default_irq_smp_affinityr��perf_process_fork�sched_min_granularity_ns�sched_base_slice_ns�sched_latency_ns�sched_wakeup_granularity_ns�sched_tunable_scaling�sched_migration_cost_ns�sched_nr_migrate�numa_balancing_scan_delay_ms�!numa_balancing_scan_period_min_ms�!numa_balancing_scan_period_max_ms�numa_balancing_scan_size_mb)rbZDEF_CGROUP_MOUNT_POINT)�clsrrr�_get_config_options:s2�z#SchedulerPlugin._get_config_optionscCs|durt|��dd�SdS)N�.�/)r��replacerrrrr�Wsz%SchedulerPlugin._sanitize_cgroup_pathcCs>t|tj�s|}t�|�}t�|�}|�|�r:d|d}|S)N�[�])�
isinstance�procfs�processZprocess_cmdline�_is_kthread)rr�rBr	rrr�_get_cmdline[s


zSchedulerPlugin._get_cmdlinecCs�t��}|��i}|��D]�}z^|js6|�|�r6Wq|�|�}|d}|||<d|vr||d��D]}|�|�}|||<qdWqtt	fy�}z4|j
t
jks�|j
t
jkr�WYd}~qn�WYd}~qd}~00q|S)NrBr�)
r��pidstats�reload_threadsr:rkr�r��keys�OSError�IOError�errno�ENOENT�ESRCH)r�ps�	processes�procrrB�errr�
get_processeses*


�zSchedulerPlugin.get_processescCs@|j�|�}|j�|�}|j�|�}t�d|||f�||fS)Nz8Read scheduler policy '%s' and priority '%d' of PID '%d')rwrCr?rQr~�debug)rrBr
�	sched_strrrrr�_get_rt�s�zSchedulerPlugin._get_rtc
Cs|j�|�}t�d|||f�zB|j�|�}|j�|�}||ksJ||kr`t�d||||f�Wn6ttfy�}zt�d|�WYd}~n
d}~00z|j�	|||�Wnbttf�y}zDt
|d�r�|jtjkr�t�d|�nt�d||f�WYd}~n
d}~00dS)NzBSetting scheduler policy to '%s' and priority to '%d' of PID '%d'.z9Priority for %s must be in range %d - %d. '%d' was given.z(Failed to get allowed priority range: %sr�zAFailed to set scheduling parameters of PID %d, the task vanished.z1Failed to set scheduling parameters of PID %d: %s)
rwr?r~r�rTrVr��SystemErrorr�rI�hasattrr�r�)rrBrGrHr�Zprio_minZprio_maxr�rrr�_set_rt�s6���
���zSchedulerPlugin._set_rtcCs|ddtjj@dkS)N�stat�flagsr)r�ZpidstatZ
PF_KTHREAD�rr�rrrr��szSchedulerPlugin._is_kthreadcCs&|jdkrdSt�|j|�|��duS)Nr\F)rl�re�search�_get_stat_cgroupr�rrr�_process_in_blacklisted_cgroup�s
z.SchedulerPlugin._process_in_blacklisted_cgroupc
Cs�|j}z�|dddkr,t�d|�WdS|�|�rJt�d|�WdS|d��r�|�|�rpt�d|�nt�d|�WdSt�d	||�|�f�t�d
||�	|�f�t�d|t
|j�|��f�Wn�t
tf�yH}zV|jtjk�s|jtjk�r"t�d|�WYd}~dSt�d
||f�WYd}~nDd}~0ttf�y�}zt�d
||f�WYd}~n
d}~00dS)Nr��state�Zz9Affinity of zombie task with PID %d could not be changed.Tz`Affinity of task with PID %d could not be changed, the task was moved into a blacklisted cgroup.z[Affinity of kernel thread with PID %d cannot be changed, the task's affinity mask is fixed.zRAffinity of task with PID %d cannot be changed, the task's affinity mask is fixed.zTask %d cmdline: %szTask %d cgroup: %szTask %d affinity: %sz6Failed to get task info for PID %d, the task vanished.z&Failed to get task info for PID %d: %sF)rBr~r�r�Zis_bound_to_cpur�r�r�r�r��listrwrKr�r�r�r�r�r�rp�KeyError)rr�rBr�rrr�_ignore_set_affinity_error�sL�
�
��"���z*SchedulerPlugin._ignore_set_affinity_errorcCsZz|j|}Wn&ty4t|j�}||j|<Yn0|jdurV|jdurV||_||_dSr)r�r�rrr
r)rrBr
r�paramsrrr�_store_orig_process_rt�s
z&SchedulerPlugin._store_orig_process_rtc
Cs�d}|dur|dur|Sz:|�|�\}}|dur4|}|�|||�|�|||�Wnvttfy�}zZt|d�r�|jtjkr�t�	d|�||j
vr�|j
|=d}nt�d||f�WYd}~n
d}~00|S)NTr�z=Failed to read scheduler policy of PID %d, the task vanished.FzcRefusing to set scheduler and priority of PID %d, reading original scheduling parameters failed: %s)r�r�r�r�r�r�r�r�r~r�r�r�)rrBrGrH�contZ
prev_schedZ	prev_prior�rrr�_tune_process_rt�s*�
�z SchedulerPlugin._tune_process_rtcCst|�dd�dkSr�)r�)rrrrr�_is_cgroup_affinity�sz#SchedulerPlugin._is_cgroup_affinityFcCs`z|j|}Wn&ty4t|j�}||j|<Yn0|jdur\|jdur\|rV||_n||_dSr)r�r�rrrr
)rrBr�	is_cgroupr�rrr�_store_orig_process_affinity�s
z,SchedulerPlugin._store_orig_process_affinityc	Csp|jjdtjt|�dfdd��d�D]D}z,|�d�ddd�}|dkrN|nd	WStyhYq&0q&d	S)
N�%s/%s/%sr
T��no_error�
z:cpuset:rr\r�)rrqrbZPROCFS_MOUNT_POINTr��split�
IndexError)rrB�lr
rrr�_get_cgroup_affinity�s*z$SchedulerPlugin._get_cgroup_affinitycCsB|�|�}|j}|dkr$d||f}|jjd|t|�dd�dS)Nr��%s/%sz%s/tasksTr�)r��_cgroup_mount_pointr�
write_to_filer�)rrBr
�pathrrr�_set_cgroups

zSchedulerPlugin._set_cgroupcCs,|dd�}t|t�o"t|�dk}||fS)Nr�r)r�r�r�)rr
r�rrr�_parse_cgroup_affinitysz&SchedulerPlugin._parse_cgroup_affinityc	
Cs�d}|dur|Szd|�|�\}}|r<|�|�}|�||�n(|�|�}|rX|�|||�}|�||�|�|||�Wnvttfy�}zZt	|d�r�|j
t
jkr�t�
d|�||jvr�|j|=d}nt�d||f�WYd}~n
d}~00|S)NTr�z5Failed to read affinity of PID %d, the task vanished.FzLRefusing to set CPU affinity of PID %d, reading original affinity failed: %s)rr�r�
_get_affinity�_get_intersect_affinity�
_set_affinityr�r�r�r�r�r�r~r�r�r�)	rrBr�	intersectr�r�r
�
prev_affinityr�rrr�_tune_process_affinitys<

���
�z&SchedulerPlugin._tune_process_affinitycCsD|�|||�}|sdS|�||�}|r0||jvr4dS||j|_dSr)r�rr�r	)rrBrrGrHrr�rrr�
_tune_process9szSchedulerPlugin._tune_processcCsf|j�|�}|dur.|dkr.t�d|�dSzt|�}Wn"ty\t�d|�YdS0||fS)Nrz>Invalid scheduler: %s. Scheduler and priority will be ignored.)NNz=Invalid priority: %s. Scheduler and priority will be ignored.)rwr>r~r�rdr|)rr=Zstr_priorityr
rrrr�_convert_sched_paramsBs��z%SchedulerPlugin._convert_sched_paramscCsD|dkrd}n2|�|�r|}n"|j�|�}|s@t�d|�d}|S)Nrz)Invalid affinity: %s. It will be ignored.)r�r�hex2cpulistr~r�)rZstr_affinityrrrr�_convert_affinityQs
�z!SchedulerPlugin._convert_affinitycCs6|\}}}}}|�||�\}}|�|�}|||||fSr)r
r)r�vals�	rule_prior
rr�regexrrr�_convert_sched_cfg^s�
z"SchedulerPlugin._convert_sched_cfgc
Cs�d|j|f}zt�|tj�Wn6tyV}zt�d||f�WYd}~n
d}~00|jj	d|df|jj
d|jdfdd�dd�s�t�d|�dS)Nr�z Unable to create cgroup '%s': %szcpuset.memsTr�z3Unable to initialize 'cpuset.mems ' for cgroup '%s')r�r-�mkdirrb�DEF_CGROUP_MODEr�r~r�rr�rq)rr
rr�rrr�_cgroup_create_groupes(�z$SchedulerPlugin._cgroup_create_groupcCs<|jdur"|j|jvr"|�|j�|jD]}|�|�q(dSr)r�r�r�r�cgrrr�_cgroup_initialize_groupsps
z)SchedulerPlugin._cgroup_initialize_groupsc
Cs�t�d�zt�|jtj�Wn2tyP}zt�d|�WYd}~n
d}~00|j	�
dddddd|jg�\}}|dkr�t�d	|j�dS)
NzInitializing cgroups settingsz'Unable to create cgroup mount point: %sZmountz-tr
z-oZcpusetrzUnable to mount '%s')r~r�r-�makedirsr�rbrr�r�r�execute)rr��ret�outrrr�_cgroup_initializevs
$ z"SchedulerPlugin._cgroup_initializec
CsJzt�|�Wn6tyD}zt�d||f�WYd}~n
d}~00dS)Nz#Unable to remove directory '%s': %s)r-�rmdirr�r~r�)rr
r�rrr�_remove_dir�szSchedulerPlugin._remove_dircCsTt|j�D]}|�d|j|f�q
|jdurP|j|jvrP|�d|j|jf�dS)Nr�)�reversedr�rr�r�rrrr�_cgroup_finalize_groups�sz'SchedulerPlugin._cgroup_finalize_groupscCslt�d�|j�d|jg�\}}|dkr<t�d|j�dS|�|j�tj�	|j�}|dkrh|�|�dS)NzRemoving cgroups settingsZumountrzUnable to umount '%s'Fr�)
r~r�rrr�r�rr-r�dirname)rrr�drrr�_cgroup_finalize�s
z SchedulerPlugin._cgroup_finalizecCs�|dkrt�d||f�nt�d|�dSd|j|df}|r~|jj|ddd���}|dkrl||j|<nt�d	|�dS|jj||dd
�s�t�d||f�dS)Nr\z$Setting cgroup '%s' affinity to '%s'z.Skipping cgroup '%s', empty affinity requestedr��cpuset.cpus�ERRT��err_retr�zIRefusing to set affinity of cgroup '%s', reading original affinity failedr�z+Unable to set affinity '%s' for cgroup '%s')	r~r�r�rrq�stripr�r�r�)rr
r�backuprZ
orig_affinityrrr�_cgroup_set_affinity_one�sz(SchedulerPlugin._cgroup_set_affinity_onecCsz|jr
dSt�d�|jdurH|jdurH|j|jvrH|j|j|jdd�|j��D]}|j|d|ddd�qRd|_dS)NzSetting cgroups affinitiesT)r(rr)r�r~r�rr�r�r)r8rrrr�_cgroup_set_affinity�s
 z$SchedulerPlugin._cgroup_set_affinitycCs2t�d�|j��D]}|�|d|d�qdS)NzRestoring cgroups affinitiesrr)r~r�r�r8r)rrrr�_cgroup_restore_affinity�s
z(SchedulerPlugin._cgroup_restore_affinitycsx�j�|jd��_�j��j�|jd��dk�_�j��j�|jd��dk�_���j�|jd���_	�jr|��
��js��jr����tt
���|����z���}Wn8ttfy�}zt�d|�WYd}~dSd}~00dd�|j��D�}�fd	d�|D�}t|d
d�d�}t�}i|_|D]�\�\}����zt����WnHtj�y�}z,t�d
t���WYd}~�q4WYd}~n
d}~00�fdd�|��D�}t�����fdd�|D��}	|�|	�t�ddt�������g|j�<�q4|��D](\}
\}�������|
|�����q
�j �!�j"�j#��j$�rt|j%�rtt&j'�j(|gd�|_)|j)�*�dS)Nr�r��1r�r��Ierror applying tuning, cannot get information about running processes: %scSs$g|]\}}|t|��dd�f�qS)�:�)r�r�)r/r�rrrrr��r3z:SchedulerPlugin._instance_apply_static.<locals>.<listcomp>cs6g|].\}}t�d|�rt|�dkr|��|�f�qS)zgroup\.�)r��matchr�r)r/r�r
rrrr��s�cSs|ddS)Nrrr)Zoption_valsrrr�<lambda>�r3z8SchedulerPlugin._instance_apply_static.<locals>.<lambda>)�keyz(error compiling regular expression: '%s'cs(g|] \}}t��|�dur||f�qSr)r�r��r/rBr)r(rrr��r3c	s$g|]\}}||�����ff�qSrrr4)rr�rrr
rrr��s�z(?<!\\)\((?!\?)z(?:)�target�args)+r�r�r�r�rrf�_cgroup_mount_point_init�_cgroup_groups_initr�r�rrrar[�_instance_apply_staticr*r�r�r�r~r�r�r8�sortedr6�
_sched_lookupr��compiler��update�subr	r��setrsr�rcr�r��Thread�_thread_code�_thread�start)rr�r�r�Z	sched_cfg�bufZ	sched_allrr�rGrBrry)rr�rr(rr
rrr9�sv����
��
��$�
�
�
�z&SchedulerPlugin._instance_apply_staticc
Cs�z|��}Wn8ttfyD}zt�d|�WYd}~dSd}~00|j��D]x\}}||vsP|||jkrpqP|jdur�|j	dur�|�
||j|j	�|jdur�|�||j�qP|j
durP|�||j
�qPi|_|j�|j�dS)NzKerror unapplying tuning, cannot get information about running processes: %s)r�r�r�r~r�r�r8r	r
rr�r
rrrr�r�rs)rr�r�rBZorig_paramsrrrr��s,�
�
�

z$SchedulerPlugin._restore_ps_affinitycCs�ttj�}d}|dkrz|dkrz|jjd|j|dfddd�}|dvrp|�d	�D] }|jjd
|jdf|dd�qN|d8}q|dkr�t�	d
|�dS)N� r\rr�ZtasksTr%)r\rEr�r�r�rz(Unable to cleanup tasks from cgroup '%s')
rdrbZCGROUP_CLEANUP_TASKS_RETRYrrqr�r�r�r~r�)rr
Zcnt�datar�rrr�_cgroup_cleanup_tasks_one	s
�
z)SchedulerPlugin._cgroup_cleanup_tasks_onecCs<|jdur"|j|jvr"|�|j�|jD]}|�|�q(dSr)r�r�rGrrrr�_cgroup_cleanup_taskss
z%SchedulerPlugin._cgroup_cleanup_taskscsptt|��||�|jr2|jr2|j��|j��|�	�|�
�|��|jsV|j
r^|��|j
rl|��dSr)rar[�_instance_unapply_staticrcr�r�r?rB�joinr�r+rHr8r7rr")rr�ZrollbackryrrrIs

z(SchedulerPlugin._instance_unapply_staticcCs�t�d|�d|j|df}|jj|ddd�}|dkr<dS|j�|j�|��}|j�|j�|��}d|}||kr�t�tj	||f�dSt�
tj|||f�dSdS)	NzVerifying cgroup '%s' affinityr�r#r$Tr%zcgroup '%s' affinityF)r~r�r�rrq�cpulist2stringZcpulist_packr�rb�STR_VERIFY_PROFILE_VALUE_OKr��STR_VERIFY_PROFILE_VALUE_FAIL)rr
rr�current_affinityZaffinity_descriptionrrr�_cgroup_verify_affinity_one)s&���z+SchedulerPlugin._cgroup_verify_affinity_onecCsnt�d�d}|jdurB|jdurB|j|jvrB|o@|�|j|j�}|j��D]}|of|�|d|d�}qL|S)NzVeryfying cgroups affinitiesTrr)r~r�rr�r�rOr8)rrrrrr�_cgroup_verify_affinity<s
 z'SchedulerPlugin._cgroup_verify_affinitycs$tt|��|||�}|��}|o"|Sr)rar[�_instance_verify_staticrP)rr��ignore_missingZdevicesZret1Zret2ryrrrQEsz'SchedulerPlugin._instance_verify_staticc
Csz.t�|�}|js"|�|�r"WdS|�|�}Wndttfy�}zH|jtjksZ|jtj	krjt
�d|�nt
�d||f�WYd}~dSd}~00|j
�|j||�}|du�r||jv�rt
�d||t|�f�|\}}	}
|�||||	|
�|j�|j|j�dS)N�3Failed to get cmdline of PID %d, the task vanished.z#Failed to get cmdline of PID %d: %sz-tuning new process '%s' with PID '%d' by '%s')r�r�rkr�r�r�r�r�r�r�r~r�r�rZ	re_lookupr;r�r�r	r�r?rs)rr�rBr(r�rr��vrGrHrrrr�_add_pidJs4

���
�
�zSchedulerPlugin._add_pidcCs6||jvr2|j|=t�d|�|j�|j|j�dS)Nz)removed PID %d from the rollback database)r�r~r�r�r?rs)rr�rBrrr�_remove_pidbs

�zSchedulerPlugin._remove_pidc	Cs�|j�|j�}t��}|j��}|D]}|�|�q$|j�	�s�t
|�|jd��dkr4|j�	�s4d}|r4d}|jD]�}|j�
|�}|rrd}t|tj�s�|jr�t|tj�r�|jtjkr�|�|t|j�|�qrt|tj�rr|jtjkrr|�|t|j��qrqdq4dS)Ni�rTF)rZre_lookup_compiler;�select�pollrvr��registerr��is_setr�rernZread_on_cpur�rmZ
comm_event�_perf_process_fork_valueZ
task_eventr�ZRECORD_FORKrUrd�tidZRECORD_EXITrV)	rr�r(rXZfdsr�Zread_eventsZcpuZeventrrrrAis0

"
�
�
�zSchedulerPlugin._thread_coder�)�
per_devicecCs:|rdS|r6|dur6d�dd�t�dt|��D��|_dS)N�|cSsg|]}d|�qS�z(%s)r�r/rTrrrr��r3z8SchedulerPlugin._cgroup_ps_blacklist.<locals>.<listcomp>�(?<!\\);)rJr�r�r�rl�r�enablingr�verifyrRr�rrr�_cgroup_ps_blacklist�sz$SchedulerPlugin._cgroup_ps_blacklistr�cCs:|rdS|r6|dur6d�dd�t�dt|��D��|_dS)Nr^cSsg|]}d|�qSr_rr`rrrr��r3z1SchedulerPlugin._ps_whitelist.<locals>.<listcomp>ra)rJr�r�r�rirbrrrri�szSchedulerPlugin._ps_whitelistr�cCs:|rdS|r6|dur6d�dd�t�dt|��D��|_dS)Nr^cSsg|]}d|�qSr_rr`rrrr��r3z1SchedulerPlugin._ps_blacklist.<locals>.<listcomp>ra)rJr�r�r�rjrbrrrrj�szSchedulerPlugin._ps_blacklistr�cCs*|rdS|r&|dur&|j�|�dk|_dS�Nr,)rrfrkrbrrrrk�sz SchedulerPlugin._kthread_processr�cCs*|rdS|r&|dur&|j�|�dk|_dSrf)rrfrtrbrrrrt�szSchedulerPlugin._irq_processr�cCs6|rdS|r2|dur2|dvr$||_n|j�|�|_dS)N)r��ignore)�_default_irq_smp_affinity_valuerrrrbrrr�_default_irq_smp_affinity�sz)SchedulerPlugin._default_irq_smp_affinityr�cCs*|rdS|r&|dur&|j�|�dk|_dSrf)rrfr[rbrrr�_perf_process_fork�sz"SchedulerPlugin._perf_process_forkcCs"|j�|�}t�d||f�|S)NzRead affinity '%s' of PID %d)rwrKr~r�)rrB�resrrrr�szSchedulerPlugin._get_affinityc
Cs�t�|�}|�|�r&t�d|�dSt�d||f�z|j�||�WnFttfy�}z*|�	|�s|t�
d|||f�WYd}~n
d}~00dS)NzMNot setting CPU affinity of PID %d, the task belongs to a blacklisted cgroup.z'Setting CPU affinity of PID %d to '%s'.z,Failed to set affinity of PID %d to '%s': %s)r�r�r�r~r�rwrNr�r�r�r�)rrBrr�r�rrrr�s


�zSchedulerPlugin._set_affinitycCs"t|��t|��}|rt|�S|Sr)r?�intersectionr�)rZ	affinity1Z	affinity2Z	affinity3Zaffrrrr�sz'SchedulerPlugin._get_intersect_affinityc
sD|}�js�fdd�|D�}�fdd�|D�}�jdkrJ�fdd�|D�}tdd�|D��}|D]�}z��||�}Wnnttfy�}zR|jtjks�|jtjkr�t	�
d|�nt	�d||f�WYd}~q`WYd}~n
d}~00�j||d	d
�}	|	s�q`|�j
v�r|�j
|_|s`d||vr`��||d��|d	�q`dS)Ncsg|]}��|�s|�qSr)r�r`rrrr��r3z9SchedulerPlugin._set_all_obj_affinity.<locals>.<listcomp>cs(g|] }t��j��|��dur|�qSr)r�r�ri�_get_stat_commr`rrrr��s��r\cs(g|] }t��j��|��dur|�qSr)r�r�rjrmr`rrrr��s��cSsg|]}|j|f�qSr)rBr`rrrr��r3rSzARefusing to set affinity of PID %d, failed to get its cmdline: %sT)rr�)rkrjr6r�r�r�r�r�r�r~r�r�rr�r	�_set_all_obj_affinityr:)
rZobjsrr�ZpslZpsdrBrr�r�rrrrn�sB

���"��z%SchedulerPlugin._set_all_obj_affinityc
Cs*z
|dWStttfy$YdS0dS)NZcgroupsr\�r�r�r��rr)rrrr�s
z SchedulerPlugin._get_stat_cgroupc
Cs.z|ddWStttfy(YdS0dS)Nr�r�r\rorprrrrmszSchedulerPlugin._get_stat_commc
Csbz&t��}|��|�|��|d�Wn6ttfy\}zt�d|�WYd}~n
d}~00dS)NFr-)	r�r�r�rnr:r�r�r~r�)rrr�r�rrr�_set_ps_affinity
s�z SchedulerPlugin._set_ps_affinityc
Cs�z`|j�|�}t�d||f�d|}t|d��}|�|�Wd�n1sR0YWdSttfy�}zdt|d�r�|j	t	j
kr�|s�t�d|�WYd}~dSt�d|||f�WYd}~d	SWYd}~n
d}~00dS)
Nz&Setting SMP affinity of IRQ %s to '%s'z/proc/irq/%s/smp_affinity�wrr�z/Setting SMP affinity of IRQ %s is not supported���z0Failed to set SMP affinity of IRQ %s to '%s': %s���)r�cpulist2hexr~r�r��writer�r�r�r�ZEIOr�)rr`rZ	restoring�affinity_hex�filenamer&r�rrr�_set_irq_affinitys*�(���z!SchedulerPlugin._set_irq_affinityc
Cs�zR|j�|�}t�d|�tdd��}|�|�Wd�n1sF0YWn:ttfy�}zt�d||f�WYd}~n
d}~00dS)Nz(Setting default SMP IRQ affinity to '%s'�/proc/irq/default_smp_affinityrrz2Failed to set default SMP IRQ affinity to '%s': %s)	rrur~r�r�rvr�r�r�)rrrwr&r�rrr�_set_default_irq_affinity0s�,�z)SchedulerPlugin._set_default_irq_affinityc		Cst�}t��}|��D]�}z"||d}t�d||f�WntyRYqYn0|�|||�}t|�t|�krtq|�	||d�}|dkr�||j
|<q|dkr|j�|�q|j
�d�}|j
�|�}|jdkr�|�|||�}n|jdkr�|j}|jdk�r
|�|�||_|j�|j|�dS)	NrzRead affinity of IRQ '%s': '%s'Frrsrzr�rg)rr��
interruptsr�r~r�r�rr?ryrr�appendrrqrrhr{rr�ru)	rr�irq_originalrr`rrrkZprev_affinity_hexrrr�_set_all_irq_affinity;s8�




z%SchedulerPlugin._set_all_irq_affinitycCsj|j�|jd�}|durdS|j��D]\}}|�||d�q&|jdkrX|j}|�|�|j�	|j�dS)NTrg)
r�r<rurr8ryrhrr{r�)rr~r`rrrr�_restore_all_irq_affinityZs

z)SchedulerPlugin._restore_all_irq_affinitycCsFt|��t|��}|r,t�tj||f�nt�tj|||f�|Sr)r?�issubsetr~r�rbrLr�rM)r�irq_description�correct_affinityrNrkrrr�_verify_irq_affinityes���z$SchedulerPlugin._verify_irq_affinityc	Cs�|j�|jd�}t��}d}|��D]�}||jvrP|rPd|}t�t	j
|�q$z<||d}t�d||f�d|}	|�|	||�s�d}Wq$t
y�Yq$Yq$0q$|j�d�}
|j�|
�}|jdkr�|�d	||jd
kr�|n|j�s�d}|S)NTz-IRQ %s does not support changing SMP affinityrz#Read SMP affinity of IRQ '%s': '%s'zSMP affinity of IRQ %sFrzrgzdefault IRQ SMP affinityr�)r�r<rur�r|r�rr~r�rbZ STR_VERIFY_PROFILE_VALUE_MISSINGr�r�r�rrqrrh)rr�rRr~rrkr`�descriptionrNr�Zcurrent_affinity_hexrrr�_verify_all_irq_affinityqs@����z(SchedulerPlugin._verify_all_irq_affinityr��
)r]rcCs�d}d|_|durrt|j�|��}t|j�}|�|�rRt||�}|j�|�|_n |j�|j�}	t�	d||	f�|sz|r�|dur�dS|r�|j
r�|�||�SdS|r�|jr�|�
�d|j}
n|}
|�|
�|j
r�|�|�n|j
r�|��dS)NzJInvalid isolated_cores specified, '%s' does not match available cores '%s'Tz	cgroup.%s)rr?rrrrnr�r�rKr~r�rtr�r�r*rqrr�)rrcrrdrRr�r�isolatedZpresentZstr_cpusZps_affinityrrr�_isolated_cores�s:

�
zSchedulerPlugin._isolated_corescCs,|dkrd||f}nd|||f}d|S)Nr\r�r�z/sys/kernel/debug/%sr)r�prefix�	namespace�knobrrrr�_sched_assembly_path�sz$SchedulerPlugin._sched_assembly_pathcCs<|}|dkr8|j�|�}|dur8|r4|�|||�}nd}|S)NrGr\)�_dict_sched_knob_mapr<r�)rrr�r�r�ZlpathZlknobrrr�_sched_assembly_path2�sz%SchedulerPlugin._sched_assembly_path2cCs�d|||f}|j�|�}|s&|dkr*|Sd||f}tj�|�s�|�|||�}tj�|�sl|�||||�}|dkr�|jdur�d|_||j|<|S)Nz%s_%s_%sr\z/proc/sys/kernel/%s_%sT)rhr<r-r�existsr�r�rg)rr�r�r�r3rrrr�_get_sched_knob_path�s
z$SchedulerPlugin._get_sched_knob_pathcCsZd}|�|||�}|dkrV|jj|dd�}|durVt�d|�|jrVt�d�d|_|S)Nr\)r&zError reading '%s'zUThis may not work with Secure Boot or kernel_lockdown (this hint is logged only once)F)r�rrqr~r�rg)rr�r�r�rFrrrr�_get_sched_knob�s
zSchedulerPlugin._get_sched_knobcCsh|durdS|�|||�}|s0t�d|�dS|sd|jj|||rJtjgndd�sdt�d||f�|S)Nz(knob '%s' ignored, unsupported by kernelFr�z Error writing value '%s' to '%s')r�r~r�rr�r�r�r�)rr�r�r�r�sim�removerrrr�_set_sched_knob�s
�zSchedulerPlugin._set_sched_knobr�cCs|�ddd�S�Nr\rGr^�r��rr�rrr�_get_sched_min_granularity_ns�sz-SchedulerPlugin._get_sched_min_granularity_nscCs|�ddd|||�Sr��r��rrr�r�r�rrr�_set_sched_min_granularity_ns�sz-SchedulerPlugin._set_sched_min_granularity_nsr�cCs
|�|�Sr)r�r�rrr�_get_sched_base_slice_ns�sz(SchedulerPlugin._get_sched_base_slice_nscCs|�||||�Sr)r�r�rrr�_set_sched_base_slice_ns�sz(SchedulerPlugin._set_sched_base_slice_nsr�cCs|�ddd�S�Nr\rGr_r�r�rrr�_get_sched_latency_nssz%SchedulerPlugin._get_sched_latency_nscCs|�ddd|||�Sr�r�r�rrr�_set_sched_latency_nssz%SchedulerPlugin._set_sched_latency_nsr�cCs|�ddd�S�Nr\rGr]r�r�rrr� _get_sched_wakeup_granularity_ns	sz0SchedulerPlugin._get_sched_wakeup_granularity_nscCs|�ddd|||�Sr�r�r�rrr� _set_sched_wakeup_granularity_ns
sz0SchedulerPlugin._set_sched_wakeup_granularity_nsr�cCs|�ddd�S�Nr\rGZtunable_scalingr�r�rrr�_get_sched_tunable_scalingsz*SchedulerPlugin._get_sched_tunable_scalingcCs|�ddd|||�Sr�r�r�rrr�_set_sched_tunable_scalingsz*SchedulerPlugin._set_sched_tunable_scalingr�cCs|�ddd�S�Nr\rGZmigration_cost_nsr�r�rrr�_get_sched_migration_cost_nssz,SchedulerPlugin._get_sched_migration_cost_nscCs|�ddd|||�Sr�r�r�rrr�_set_sched_migration_cost_nssz,SchedulerPlugin._set_sched_migration_cost_nsr�cCs|�ddd�S�Nr\rGZ
nr_migrater�r�rrr�_get_sched_nr_migrate!sz%SchedulerPlugin._get_sched_nr_migratecCs|�ddd|||�Sr�r�r�rrr�_set_sched_nr_migrate%sz%SchedulerPlugin._set_sched_nr_migrater�cCs|�ddd�S�NrG�numa_balancingZ
scan_delay_msr�r�rrr�!_get_numa_balancing_scan_delay_ms)sz1SchedulerPlugin._get_numa_balancing_scan_delay_mscCs|�ddd|||�Sr�r�r�rrr�!_set_numa_balancing_scan_delay_ms-sz1SchedulerPlugin._set_numa_balancing_scan_delay_msr�cCs|�ddd�S�NrGr�Zscan_period_min_msr�r�rrr�&_get_numa_balancing_scan_period_min_ms1sz6SchedulerPlugin._get_numa_balancing_scan_period_min_mscCs|�ddd|||�Sr�r�r�rrr�&_set_numa_balancing_scan_period_min_ms5sz6SchedulerPlugin._set_numa_balancing_scan_period_min_msr�cCs|�ddd�S�NrGr�Zscan_period_max_msr�r�rrr�&_get_numa_balancing_scan_period_max_ms9sz6SchedulerPlugin._get_numa_balancing_scan_period_max_mscCs|�ddd|||�Sr�r�r�rrr�&_set_numa_balancing_scan_period_max_ms=sz6SchedulerPlugin._set_numa_balancing_scan_period_max_msr�cCs|�ddd�S�NrGr�Zscan_size_mbr�r�rrr� _get_numa_balancing_scan_size_mbAsz0SchedulerPlugin._get_numa_balancing_scan_size_mbcCs|�ddd|||�Sr�r�r�rrr� _set_numa_balancing_scan_size_mbEsz0SchedulerPlugin._set_numa_balancing_scan_size_mb)F)F)F)F)F)irrrrWr�rrr�r��classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr	r
rrrrrrrr"r)r*r+r9r�rGrHrbZ
ROLLBACK_SOFTrIrOrPrQrUrVrAZcommand_customrerirjrkrtrirjrrrrnr�rmrqryr{rr�r�r�r�r�r�r�r�r�Zcommand_getr�Zcommand_setr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__rrryrr[�s0�&A

"



	



<

	















"
$






















r[)!r\rZ
decoratorsZ
tuned.logsZtunedr��
subprocessr�rm�ImportErrorrWZtuned.constsrbr�Ztuned.utils.commandsrr�r-r�r}r!rprZZlogsr<r~�objectrrr rXZPluginr[rrrr�<module>s6

/