Your IP : 18.191.171.121


Current Path : /usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/plugins/__pycache__/plugin_scheduler.cpython-36.pyc

3

�<�e���@s
ddlmZddlTddlZddlZddlTddlZddlZddl	Z	ddl
jZddlZddl
mZddlZddlZddlZddlZy
ejWnek
r�ddlZYnXejj�ZGdd�de�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�dej�ZdS)�)�base)�*�N)�commandsc@s0eZdZddd�Zedd��Zejdd��ZdS)�SchedulerParamsNcCs(||_||_||_||_||_||_dS)N)�_cmd�cmdline�	scheduler�priority�affinity�cgroup)�self�cmdrr	r
rr�r�&/usr/lib/python3.6/plugin_scheduler.py�__init__szSchedulerParams.__init__cCs |jdkrdS|jj|j�SdS)N)�	_affinityrZbitmask2cpulist)r
rrrr&s
zSchedulerParams.affinitycCs"|dkrd|_n|jj|�|_dS)N)rrZcpulist2bitmask)r
�valuerrrr-s)NNNNN)�__name__�
__module__�__qualname__r�propertyr�setterrrrrrs
rc@seZdZdd�ZdS)�
IRQAffinitiescCsi|_d|_g|_dS)N)�irqs�default�unchangeable)r
rrrr5szIRQAffinities.__init__N)rrrrrrrrr4src@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�|jj�D��|_tdd�|jj�D��|_dS)Ncss |]\}}|tt|�fVqdS)N)�getattr�os)�.0�k�namerrr�	<genexpr>Jsz*SchedulerUtils.__init__.<locals>.<genexpr>css|]}tt|�|fVqdS)N)r(r))r*r,rrrr-Ls)�dict�_dict_schedcfg2schedconst�items�_dict_schedcfg2num�values�_dict_num2schedconst)r
rrrrHszSchedulerUtils.__init__cCs|jj|�S)N)r1�get)r
�
str_schedulerrrr�sched_cfg_to_numNszSchedulerUtils.sched_cfg_to_numcCs|jj|�S)N)r3r4)r
r	rrr�sched_num_to_constRsz!SchedulerUtils.sched_num_to_constcCs
tj|�S)N)r)�sched_getscheduler)r
�pidrrr�
get_schedulerUszSchedulerUtils.get_schedulercCstj||tj|��dS)N)r)�sched_setscheduler�sched_param)r
r9�sched�priorrr�
set_schedulerXszSchedulerUtils.set_schedulercCs
tj|�S)N)r)�sched_getaffinity)r
r9rrr�get_affinity[szSchedulerUtils.get_affinitycCstj||�dS)N)r)�sched_setaffinity)r
r9rrrr�set_affinity^szSchedulerUtils.set_affinitycCstj|�jS)N)r)�sched_getparam�sched_priority)r
r9rrr�get_priorityaszSchedulerUtils.get_prioritycCs
tj|�S)N)r)�sched_get_priority_min)r
r=rrr�get_priority_mindszSchedulerUtils.get_priority_mincCs
tj|�S)N)r)�sched_get_priority_max)r
r=rrr�get_priority_maxgszSchedulerUtils.get_priority_maxN)rrr�__doc__r/rr6r7r:r?rArCrFrHrJrrrrr;s rc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�SchedulerUtilsSchedutilszE
	Class encapsulating scheduler implementation in schedutils module
	cCs8tdd�|jj�D��|_tdd�|jj�D��|_dS)Ncss |]\}}|tt|�fVqdS)N)r(�
schedutils)r*r+r,rrrr-psz4SchedulerUtilsSchedutils.__init__.<locals>.<genexpr>css|]}tt|�|fVqdS)N)r(rM)r*r,rrrr-rs)r.r/r0r1r2r3)r
rrrrnsz!SchedulerUtilsSchedutils.__init__cCs
tj|�S)N)rMr:)r
r9rrrr:tsz&SchedulerUtilsSchedutils.get_schedulercCstj|||�dS)N)rMr?)r
r9r=r>rrrr?wsz&SchedulerUtilsSchedutils.set_schedulercCs
tj|�S)N)rMrA)r
r9rrrrAzsz%SchedulerUtilsSchedutils.get_affinitycCstj||�dS)N)rMrC)r
r9rrrrrC}sz%SchedulerUtilsSchedutils.set_affinitycCs
tj|�S)N)rMrF)r
r9rrrrF�sz%SchedulerUtilsSchedutils.get_prioritycCs
tj|�S)N)rMrH)r
r=rrrrH�sz)SchedulerUtilsSchedutils.get_priority_mincCs
tj|�S)N)rMrJ)r
r=rrrrJ�sz)SchedulerUtilsSchedutils.get_priority_maxN)rrrrKrr:r?rArCrFrHrJrrrrrLjsrLcs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zed
d��Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd�d!d"�Zd#d$�Zd%d&�Zd'd(�Zd�d)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d�d?d@�Z#dAdB�Z$dCdD�Z%�fdEdF�Z&dGdH�Z'dIdJ�Z(dKdL�Z)e*j+f�fdMdN�	Z,dOdP�Z-dQdR�Z.�fdSdT�Z/dUdV�Z0dWdX�Z1dYdZ�Z2e3d[d d\�d]d^��Z4e3d_d d\�d`da��Z5e3dbd d\�dcdd��Z6e3ded d\�dfdg��Z7e3dhd d\�didj��Z8e3dkd d\�dldm��Z9dndo�Z:dpdq�Z;drds�Z<d�dtdu�Z=dvdw�Z>dxdy�Z?dzd{�Z@d|d}�ZAd~d�ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFe3d�d d�d��d�d���ZGd�d��ZHd�d��ZId�d�d��ZJeKd��d�d���ZLeMd��d�d���ZNeKd��d�d���ZOeMd��d�d���ZPeKd��d�d���ZQeMd��d�d���ZReKd��d�d���ZSeMd��d�d���ZTeKd��d�d���ZUeMd��d�d���ZVeKd��d�d���ZWeMd��d�d���ZXeKd��d�d���ZYeMd��d�d���ZZeKd��d�d���Z[eMd��d�d���Z\eKd��d�d���Z]eMd��d�d���Z^eKd��d�d„�Z_eMd��d�dĄ�Z`�ZaS)��SchedulerPlugina]-
	`scheduler`::
	
	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`::
	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`.
	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,+macros"]
	----
	group.__groupname__=__rule_prio__:__sched__:__prio__:__affinity__:__regex__
	----
	+
	where `__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,+macros"]
	----
	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,+macros"]
	----
	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.
	====
	Recent kernels 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`.
	Based on the kernel used, TuneD will write the specified value to the correct
	location.
	+
	.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`.
	====
	c		s�tt|�j||||||||�d|_tj|_ttj�|_	|dk	rh|j
tjtj�|_t|jtj
tj��|_	t�|_d|_i|_d|_d|_d|_tj�|_|jdd�|_d|_|jdd�|_d|_yt�|_Wntk
r�t �|_YnXdS)NTz.*�r	)Zcommand_name�irq)!�superrNrZ_has_dynamic_options�constsZCFG_DEF_DAEMON�_daemon�intZCFG_DEF_SLEEP_INTERVAL�_sleep_interval�get_boolZ
CFG_DAEMONr4ZCFG_SLEEP_INTERVALrr�_secure_boot_hint�_sched_knob_paths_cache�
_ps_whitelist�
_ps_blacklist�_cgroup_ps_blacklist_re�perfZcpu_map�_cpusZ_storage_key�_scheduler_storage_key�_irq_process�_irq_storage_key�_evlistr�_scheduler_utils�AttributeErrorrL)	r
Zmonitor_repositoryZstorage_factoryZhardware_inventoryZdevice_matcherZdevice_matcher_udevZplugin_instance_factoryZ
global_cfg�	variables)�	__class__rrr�s0


zSchedulerPlugin.__init__cCsT|dkrdSyt|�}Wntk
r,dSX|dkr:dStdtjtj|d���S)Nr�)rT�
ValueError�mathZceil�log)r
Z
mmap_pagesZmprrr�_calc_mmap_pages�sz SchedulerPlugin._calc_mmap_pagescsd|_d|_d|_d|_�jj�ji��_t�j�dkr^t	j
d��j�i�_�jj�j�t
��_d�_d�_d�_tj�fdd�|jj�D���_|j|_�jj|jd�}�j|�}|dkr�t	jd|�d}|dk	r�t|�|kr�t	j
d	||f�x(|jD]}�jj|j|�|j|<�qW�jj|jjd
d��dk�rHd|_tj �|_!�j"�r|j�ry�t#j$�|_%t#j&t#j't#j(ddddddt#j)t#j*Bd
�	}|j+�j,|j%d�t#j-�j,|j%�|_|jj.|�|dk�r�|jj/�n|jj/|d�Wnd|_YnXdS)NFTrz0recovering scheduling settings from previous runcsJg|]B\}}|dd�dkrt|�dkr�j|dd���jj|�f�qS)N�zcgroup.)�len�_sanitize_cgroup_path�
_variables�expand)r*�optionr)r
rr�
<listcomp>�sz2SchedulerPlugin._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)	�type�configZtask�comm�mmapZfreqZ
wakeup_eventsZ	watermarkZsample_type)Zcpus�threads)Zpages)0raZ_has_dynamic_tuningZ_has_static_tuning�_runtime_tuning�_storager4r^�_scheduler_originalrlri�info�_restore_ps_affinity�unsetr.�_cgroups_original_affinityr�_cgroup_affinity_initialized�_cgroup�collections�OrderedDict�optionsr0�_cgroups�
_schedulerrnrorj�error�strrrV�	threadingZEvent�
_terminaterSr\Z
thread_mapZ_threads�evselZ
TYPE_SOFTWAREZCOUNT_SW_DUMMYZ
SAMPLE_TIDZ
SAMPLE_CPU�openr]Zevlist�addrw)r
�instanceZperf_mmap_pages_rawrrr+r�r)r
r�_instance_init�s^




zSchedulerPlugin._instance_initcCs*|jr&x|jj�D]}tj|j�qWdS)N)ra�
get_pollfdr)�closer,)r
r��fdrrr�_instance_cleanupsz!SchedulerPlugin._instance_cleanupcCs4dtjddddddddddddddddddddd�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�irq_process�default_irq_smp_affinityrr�perf_process_fork�sched_min_granularity_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)rRZDEF_CGROUP_MOUNT_POINT)�clsrrr�_get_config_optionss,z#SchedulerPlugin._get_config_optionscCs|dk	rt|�jdd�SdS)N�.�/)r��replace)r
rrrrrm9sz%SchedulerPlugin._sanitize_cgroup_pathcCs>t|tj�s|}tj|�}tj|�}|j|�r:d|d}|S)N�[�])�
isinstance�procfs�processZprocess_cmdline�_is_kthread)r
r�r9rrrr�_get_cmdline=s


zSchedulerPlugin._get_cmdlinecCs�tj�}|j�i}x�|j�D]�}yN|j|�}|d}|||<d|krnx&|dj�D]}|j|�}|||<qTWWqttfk
r�}z$|jtj	ks�|jtj
kr�wn�WYdd}~XqXqW|S)Nr9rx)r��pidstats�reload_threadsr2r��keys�OSError�IOError�errno�ENOENT�ESRCH)r
�ps�	processes�procrr9�errr�
get_processesGs$

zSchedulerPlugin.get_processescCs@|jj|�}|jj|�}|jj|�}tjd|||f�||fS)Nz8Read scheduler policy '%s' and priority '%d' of PID '%d')rbr:r7rFri�debug)r
r9r	�	sched_strr
rrr�_get_rt`szSchedulerPlugin._get_rtcCs|jj|�}tjd|||f�yB|jj|�}|jj|�}||ksJ||kr`tjd||||f�Wn4ttfk
r�}ztjd|�WYdd}~XnXy|jj	|||�Wn`ttfk
�r}z>t
|d�r�|jtjkr�tjd|�ntjd||f�WYdd}~XnXdS)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)
rbr7rir�rHrJr��SystemErrorr�r?�hasattrr�r�)r
r9r=r>r�Zprio_minZprio_maxr�rrr�_set_rths*
zSchedulerPlugin._set_rtcCs|ddtjj@dkS)N�stat�flagsr)r�ZpidstatZ
PF_KTHREAD)r
r�rrrr��szSchedulerPlugin._is_kthreadcCsyjtj|�}|dj�rd|dddkr8tjd|�n(|j|�rRtjd|�ntjd|�dSdSWn�ttfk
r�}zF|j	t	j
ks�|j	t	jkr�tjd	|�dStjd
||f�d
SWYdd}~Xn8t
tfk
�r}ztjd
||f�dSd}~XnXdS)Nr��state�ZzYAffinity of zombie task with PID %d cannot be changed, the task's affinity mask is fixed.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.rrz6Failed to get task info for PID %d, the task vanished.z&Failed to get task info for PID %d: %srf������r�)r�r�Zis_bound_to_cpurir�r��warnr�r�r�r�r�r�rc�KeyError)r
r9r�r�rrr�_affinity_changeable�s2



z$SchedulerPlugin._affinity_changeablecCs\y|j|}Wn(tk
r6t|j�}||j|<YnX|jdkrX|jdkrX||_||_dS)N)r{r�rrr	r
)r
r9r	r
�paramsrrr�_store_orig_process_rt�s
z&SchedulerPlugin._store_orig_process_rtcCs�d}|dkr|dkr|Sy:|j|�\}}|dkr4|}|j|||�|j|||�Wntttfk
r�}zTt|d�r�|jtjkr�tj	d|�||j
kr�|j
|=d}ntjd||f�WYdd}~XnX|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�rir�r{r�)r
r9r=r>�contZ
prev_schedZ	prev_prior�rrr�_tune_process_rt�s&
z SchedulerPlugin._tune_process_rtcCst|�dd�dkS)Nrkzcgroup.)r�)r
rrrr�_is_cgroup_affinity�sz#SchedulerPlugin._is_cgroup_affinityFcCsby|j|}Wn(tk
r6t|j�}||j|<YnX|jdkr^|jdkr^|rX||_n||_dS)N)r{r�rrrr)r
r9r�	is_cgroupr�rrr�_store_orig_process_affinity�s
z,SchedulerPlugin._store_orig_process_affinitycCspxj|jjdtjt|�dfdd�jd�D]@}y&|jd�ddd�}|dkrP|Sd	Stk
rfYq(Xq(Wd	S)
Nz%s/%s/%srT)�no_error�
z:cpuset:rrOr�)r�	read_filerRZPROCFS_MOUNT_POINTr��split�
IndexError)r
r9�lrrrr�_get_cgroup_affinity�s,
z$SchedulerPlugin._get_cgroup_affinitycCsB|j|�}|j}|dkr$d||f}|jjd|t|�dd�dS)Nr�z%s/%sz%s/tasksT)r�)rm�_cgroup_mount_pointr�
write_to_filer�)r
r9r�pathrrr�_set_cgroup�s

zSchedulerPlugin._set_cgroupcCs,|dd�}t|t�o"t|�dk}||fS)Nrkr)r��listrl)r
rr�rrr�_parse_cgroup_affinity�sz&SchedulerPlugin._parse_cgroup_affinityc	Cs�d}|dkr|Syd|j|�\}}|r<|j|�}|j||�n(|j|�}|rX|j|||�}|j||�|j|||�Wntttfk
r�}zTt	|d�r�|j
t
jkr�tj
d|�||jkr�|j|=d}ntjd||f�WYdd}~XnX|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)r�r�r��
_get_affinity�_get_intersect_affinity�
_set_affinityr�r�r�r�r�r�rir�r{r�)	r
r9r�	intersectr�r�r�
prev_affinityr�rrr�_tune_process_affinity�s4


z&SchedulerPlugin._tune_process_affinitycCsF|j|||�}|sdS|j||�}|s2||jkr6dS||j|_dS)N)r�r�r{r)r
r9rr=r>rr�rrr�
_tune_processszSchedulerPlugin._tune_processcCsf|jj|�}|dkr.|dkr.tjd|�dSyt|�}Wn"tk
r\tjd|�dSX||fS)Nrz>Invalid scheduler: %s. Scheduler and priority will be ignored.z=Invalid priority: %s. Scheduler and priority will be ignored.)NN)NN)rbr6rir�rTrg)r
r5Zstr_priorityr	r
rrr�_convert_sched_paramssz%SchedulerPlugin._convert_sched_paramscCsD|dkrd}n2|j|�r|}n"|jj|�}|s@tjd|�d}|S)Nrz)Invalid affinity: %s. It will be ignored.)r�r�hex2cpulistrir�)r
Zstr_affinityrrrr�_convert_affinity+s
z!SchedulerPlugin._convert_affinitycCs6|\}}}}}|j||�\}}|j|�}|||||fS)N)r�r�)r
�vals�	rule_prior	r
r�regexrrr�_convert_sched_cfg8s

z"SchedulerPlugin._convert_sched_cfgcCs�d|j|f}ytj|tj�Wn4tk
rT}ztjd||f�WYdd}~XnX|jj	d|df|jj
d|jdfdd�dd�s�tjd|�dS)Nz%s/%sz Unable to create cgroup '%s': %szcpuset.memsT)r�z3Unable to initialize 'cpuset.mems ' for cgroup '%s')r�r)�mkdirrR�DEF_CGROUP_MODEr�rir�rr�r�)r
rr�r�rrr�_cgroup_create_group?s$z$SchedulerPlugin._cgroup_create_groupcCs@|jdk	r"|j|jkr"|j|j�x|jD]}|j|�q*WdS)N)r�r�r�)r
�cgrrr�_cgroup_initialize_groupsJsz)SchedulerPlugin._cgroup_initialize_groupscCs�tjd�ytj|jtj�Wn0tk
rN}ztjd|�WYdd}~XnX|j	j
dddddd|jg�\}}|dkr�tjd	|j�dS)
NzInitializing cgroups settingsz'Unable to create cgroup mount point: %sZmountz-trz-oZcpusetrzUnable to mount '%s')rir�r)�makedirsr�rRr�r�r�r�execute)r
r��ret�outrrr�_cgroup_initializePs
  z"SchedulerPlugin._cgroup_initializecCsHytj|�Wn4tk
rB}ztjd||f�WYdd}~XnXdS)Nz#Unable to remove directory '%s': %s)r)�rmdirr�rir�)r
rr�rrr�_remove_dirZszSchedulerPlugin._remove_dircCsXx&t|j�D]}|jd|j|f�qW|jdk	rT|j|jkrT|jd|j|jf�dS)Nz%s/%s)�reversedr�r�r�r�)r
r�rrr�_cgroup_finalize_groups`sz'SchedulerPlugin._cgroup_finalize_groupscCsltjd�|jjd|jg�\}}|dkr<tjd|j�dS|j|j�tjj	|j�}|dkrh|j|�dS)NzRemoving cgroups settingsZumountrzUnable to umount '%s'Fr�)
rir�rr�r�r�r�r)r��dirname)r
r�r��drrr�_cgroup_finalizefs
z SchedulerPlugin._cgroup_finalizecCs�|dkrtjd||f�ntjd|�dSd|j|df}|r~|jj|ddd�j�}|dkrl||j|<ntjd	|�dS|jj||dd
�s�tjd||f�dS)NrOz$Setting cgroup '%s' affinity to '%s'z.Skipping cgroup '%s', empty affinity requestedz%s/%s/%szcpuset.cpus�ERRT)�err_retr�zIRefusing to set affinity of cgroup '%s', reading original affinity failed)r�z+Unable to set affinity '%s' for cgroup '%s')	rir�r�rr��striprr�r�)r
rr�backupr�Z
orig_affinityrrr�_cgroup_set_affinity_oneqsz(SchedulerPlugin._cgroup_set_affinity_onecCs~|jr
dStjd�|jdk	rH|jdk	rH|j|jkrH|j|j|jdd�x*|jj�D]}|j|d|ddd�qTWd|_dS)NzSetting cgroups affinitiesT)rrr)r�rir�rr�r�r	r0)r
r�rrr�_cgroup_set_affinity�s
 z$SchedulerPlugin._cgroup_set_affinitycCs6tjd�x&|jj�D]}|j|d|d�qWdS)NzRestoring cgroups affinitiesrr)rir�rr0r	)r
r�rrr�_cgroup_restore_affinity�s
z(SchedulerPlugin._cgroup_restore_affinityc#sn�jj|jd��_�jj�jj|jd��dk�_�jj�jj|jd��dk�_�j�jj|jd���_	�jr|�j
��js��jr��j�tt
��j|��j�y�j�}Wn2ttfk
r�}ztjd|�dSd}~XnXdd�|jj�D�}�fd	d�|D�}t|d
d�d�}t�}i|_x�|D]�\�\}����ytj���Wn<tjk
�r�}ztjd
t����w0WYdd}~XnX�fdd�|j�D�}t�����fdd�|D��}	|j|	�tjddt�������g|j�<�q0Wx4|j�D](\}
\}������j|
|�����q�W�j j!�j"�j#��j$�rj|j%�rjt&j'�j(|gd�|_)|j)j*�dS)Nr�r��1r�r�zIerror applying tuning, cannot get information about running processes: %scSs$g|]\}}|t|�jdd�f�qS)�:�)r�r�)r*rprrrrrq�sz:SchedulerPlugin._instance_apply_static.<locals>.<listcomp>cs6g|].\}}tjd|�rt|�dkr|�j|�f�qS)zgroup\.�)�re�matchrlr�)r*rpr�)r
rrrq�scSs|ddS)Nrrr)Zoption_valsrrr�<lambda>�sz8SchedulerPlugin._instance_apply_static.<locals>.<lambda>)�keyz(error compiling regular expression: '%s'cs(g|] \}}tj�|�dk	r||f�qS)N)r�search)r*r9r)r%rrrq�sc	s$g|]\}}||�����ff�qSrr)r*r9r)rrpr
r�r	rrrq�sz(?<!\\)\((?!\?)z(?:)�target�args)+rnror�r�rrV�_cgroup_mount_point_init�_cgroup_groups_initrmr�r�r�rQrN�_instance_apply_staticr
r�r�r�rir�r�r0�sortedr.�
_sched_lookupr�compiler��update�subr�rz�setr^r{rSryr�ZThread�_thread_code�_thread�start)r
r�r�r�Z	sched_cfgZbufZ	sched_allr�r�r=r9r)re)rrpr
r%r�r	r
rr�s^





z&SchedulerPlugin._instance_apply_staticcCs�y|j�}Wn2ttfk
r>}ztjd|�dSd}~XnXx�|jj�D]x\}}||ksL|||jkrlqL|jdk	r�|j	dk	r�|j
||j|j	�|jdk	r�|j||j�qL|j
dk	rL|j||j
�qLWi|_|jj|j�dS)NzKerror unapplying tuning, cannot get information about running processes: %s)r�r�r�rir�r{r0rr	r
r�rr�rr�rzr~r^)r
r�r�r9Zorig_paramsrrrr}�s&




z$SchedulerPlugin._restore_ps_affinitycCs�ttj�}d}xr|dkr�|dkr�|jjd|j|dfddd�}|d
krvx.|jd�D] }|jjd	|jdf|dd
�qRW|d8}qW|dkr�tj	d|�dS)N� rOrz%s/%s/%sZtasksT)rr�r�z%s/%s)r�rz(Unable to cleanup tasks from cgroup '%s')rOr#)
rTrRZCGROUP_CLEANUP_TASKS_RETRYrr�r�r�r�rir�)r
rZcnt�datar�rrr�_cgroup_cleanup_tasks_one�s

 z)SchedulerPlugin._cgroup_cleanup_tasks_onecCs@|jdk	r"|j|jkr"|j|j�x|jD]}|j|�q*WdS)N)r�r�r%)r
r�rrr�_cgroup_cleanup_tasks�sz%SchedulerPlugin._cgroup_cleanup_taskscsptt|�j||�|jr2|jr2|jj�|jj�|j	�|j
�|j�|jsV|j
r^|j�|j
rl|j�dS)N)rQrN�_instance_unapply_staticrSryr�rr!�joinr}rr&rrrr)r
r�Zrollback)rerrr'�s

z(SchedulerPlugin._instance_unapply_staticcCs�tjd|�d|j|df}|jj|ddd�}|dkr<dS|jj|jj|��}|jj|jj|��}d|}||kr�tjtj	||f�dStj
tj|||f�dSdS)	NzVerifying cgroup '%s' affinityz%s/%s/%szcpuset.cpusrT)rr�zcgroup '%s' affinityF)rir�r�rr��cpulist2stringZcpulist_packr|rR�STR_VERIFY_PROFILE_VALUE_OKr��STR_VERIFY_PROFILE_VALUE_FAIL)r
rrr��current_affinityZaffinity_descriptionrrr�_cgroup_verify_affinity_ones 
z+SchedulerPlugin._cgroup_verify_affinity_onecCsrtjd�d}|jdk	rB|jdk	rB|j|jkrB|o@|j|j|j�}x*|jj�D]}|oh|j|d|d�}qNW|S)NzVeryfying cgroups affinitiesTrr)rir�rr�r�r-r0)r
r�r�rrr�_cgroup_verify_affinitys
 z'SchedulerPlugin._cgroup_verify_affinitycs$tt|�j|||�}|j�}|o"|S)N)rQrN�_instance_verify_staticr.)r
r��ignore_missingZdevicesZret1Zret2)rerrr/sz'SchedulerPlugin._instance_verify_staticc
Cs�y|j|�}Wn^ttfk
rl}z>|jtjks<|jtjkrLtjd|�ntjd||f�dSd}~XnX|j	j
|j||�}|dk	r�||jkr�tjd||t
|�f�|\}}}	|j|||||	�|jj|j|j�dS)Nz3Failed 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�r�r�r�r�rir�r�rZ	re_lookuprr{r�r�rzrr^)
r
r�r9r%rr��vr=r>rrrr�_add_pid$s$


zSchedulerPlugin._add_pidcCs6||jkr2|j|=tjd|�|jj|j|j�dS)Nz)removed PID %d from the rollback database)r{rir�rzrr^)r
r�r9rrr�_remove_pid9s


zSchedulerPlugin._remove_pidc	Cs�|jj|j�}tj�}|jj�}x|D]}|j|�q&Wx�|jj	�s�t
|j|jd��dkr:|jj	�r:d}x�|r�d}xt|jD]j}|jj
|�}|r~d}|jtjks�|jr�|jtjkr�|j|t|j�|�q~|jtjkr~|j|t|j��q~WqnWq:WdS)Ni�rTF)rZre_lookup_compiler�select�pollrar��registerr�Zis_setrlrUr]Zread_on_cpurtr\ZRECORD_COMM�_perf_process_fork_valueZRECORD_FORKr2rT�tidZRECORD_EXITr3)	r
r�r%r5Zfdsr�Zread_eventsZcpuZeventrrrr @s&

$zSchedulerPlugin._thread_coder�)�
per_devicecCs:|rdS|r6|dk	r6djdd�tjdt|��D��|_dS)N�|cSsg|]}d|�qS)z(%s)r)r*r1rrrrq_sz8SchedulerPlugin._cgroup_ps_blacklist.<locals>.<listcomp>z(?<!\\);)r(rr�r�r[)r
�enablingr�verifyr0rrr�_cgroup_ps_blacklistYsz$SchedulerPlugin._cgroup_ps_blacklistr�cCs:|rdS|r6|dk	r6djdd�tjdt|��D��|_dS)Nr:cSsg|]}d|�qS)z(%s)r)r*r1rrrrqgsz1SchedulerPlugin._ps_whitelist.<locals>.<listcomp>z(?<!\\);)r(rr�r�rY)r
r;rr<r0rrrrYaszSchedulerPlugin._ps_whitelistr�cCs:|rdS|r6|dk	r6djdd�tjdt|��D��|_dS)Nr:cSsg|]}d|�qS)z(%s)r)r*r1rrrrqosz1SchedulerPlugin._ps_blacklist.<locals>.<listcomp>z(?<!\\);)r(rr�r�rZ)r
r;rr<r0rrrrZiszSchedulerPlugin._ps_blacklistr�cCs*|rdS|r&|dk	r&|jj|�dk|_dS)Nr)rrVr_)r
r;rr<r0rrrr_qszSchedulerPlugin._irq_processr�cCs6|rdS|r2|dk	r2|dkr$||_n|jj|�|_dS)Nr��ignore)r�r>)�_default_irq_smp_affinity_valuer�cpulist_unpack)r
r;rr<r0rrr�_default_irq_smp_affinityysz)SchedulerPlugin._default_irq_smp_affinityr�cCs*|rdS|r&|dk	r&|jj|�dk|_dS)Nr)rrVr7)r
r;rr<r0rrr�_perf_process_fork�sz"SchedulerPlugin._perf_process_forkcCs"|jj|�}tjd||f�|S)NzRead affinity '%s' of PID %d)rbrArir�)r
r9�resrrrr��szSchedulerPlugin._get_affinitycCs�tjd||f�y|jj||�dSttfk
r�}zXt|d�r`|jtjkr`tjd|�n.|j	|�}|dksz|d	kr�tj
d|||f�dSd}~XnXdS)
Nz'Setting CPU affinity of PID %d to '%s'.Tr�z4Failed to set affinity of PID %d, the task vanished.rrfz,Failed to set affinity of PID %d to '%s': %sFr�)rir�rbrCr�r�r�r�r�r�r�)r
r9rr�rCrrrr��s

zSchedulerPlugin._set_affinitycCs"t|�jt|��}|rt|�S|S)N)r�intersectionr�)r
Z	affinity1Z	affinity2Z	affinity3Zaffrrrr��sz'SchedulerPlugin._get_intersect_affinityc
s>�fdd�|D�}�jdkr.�fdd�|D�}�jdkrJ�fdd�|D�}tdd�|D��}x�|D]�}y�j||�}Wnbttfk
r�}zB|jtjks�|jtjkr�t	j
d|�nt	jd||f�wbWYdd}~XnX�j||d	d
�}	|	s�qb|�j
k�r
|�j
|_|rbd||krb�j||dj�|d	�qbWdS)Ncs(g|] }tj�j�j|��dk	r|�qS)N)rrrY�_get_stat_comm)r*r1)r
rrrq�s
z9SchedulerPlugin._set_all_obj_affinity.<locals>.<listcomp>rOcs(g|] }tj�j�j|��dkr|�qS)N)rrrZrE)r*r1)r
rrrq�s
cs(g|] }tj�j�j|��dkr|�qS)N)rrr[�_get_stat_cgroup)r*r1)r
rrrq�s
cSsg|]}|j|f�qSr)r9)r*r1rrrrq�sz3Failed to get cmdline of PID %d, the task vanished.zARefusing to set affinity of PID %d, failed to get its cmdline: %sT)r�rx)rZr[r.r�r�r�r�r�r�rir�r�r�r{r�_set_all_obj_affinityr2)
r
ZobjsrrxZpslZpsdr9rr�r�r)r
rrG�s6



z%SchedulerPlugin._set_all_obj_affinityc
Cs(y|dStttfk
r"dSXdS)NZcgroupsrO)r�r�r�)r
r&rrrrF�sz SchedulerPlugin._get_stat_cgroupc
Cs,y|ddStttfk
r&dSXdS)Nr�rvrO)r�r�r�)r
r&rrrrE�szSchedulerPlugin._get_stat_commcCs`y&tj�}|j�|j|j�|d�Wn4ttfk
rZ}ztjd|�WYdd}~XnXdS)NFzIerror applying tuning, cannot get information about running processes: %s)	r�r�r�rGr2r�r�rir�)r
rr�r�rrr�_set_ps_affinity�sz SchedulerPlugin._set_ps_affinitycCs�yJ|jj|�}tjd||f�d|}t|d��}|j|�WdQRXdSttfk
r�}zLt|d�r�|j	t	j
kr�|r�tjd|�d
Stjd|||f�dSWYdd}~XnXdS)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 supportedrfz0Failed to set SMP affinity of IRQ %s to '%s': %srr�r�)r�cpulist2hexrir�r��writer�r�r�r�ZEIOr�)r
rPrZ	restoring�affinity_hex�filenamer#r�rrr�_set_irq_affinity�s"z!SchedulerPlugin._set_irq_affinitycCs|y>|jj|�}tjd|�tdd��}|j|�WdQRXWn8ttfk
rv}ztjd||f�WYdd}~XnXdS)Nz(Setting default SMP IRQ affinity to '%s'z/proc/irq/default_smp_affinityrIz2Failed to set default SMP IRQ affinity to '%s': %s)	rrJrir�r�rKr�r�r�)r
rrLr#r�rrr�_set_default_irq_affinity�sz)SchedulerPlugin._set_default_irq_affinityc	
Cs"t�}tj�}x�|j�D]�}y"||d}tjd||f�Wntk
rTwYnX|j|||�}t|�t|�krvq|j	||d�}|dkr�||j
|<q|d	kr|jj|�qW|j
jd�}|j
j|�}|jdkr�|j|||�}n|jdkr�|j}|jdk�r|j|�||_|jj|j|�dS)
NrzRead affinity of IRQ '%s': '%s'Frrfz/proc/irq/default_smp_affinityr�r>r�)rr��
interruptsr�rir�r�r�rrNrr�appendrr�r�r?rOrrzr`)	r
r�irq_originalrrPr�rrCZprev_affinity_hexrrr�_set_all_irq_affinity
s6


z%SchedulerPlugin._set_all_irq_affinitycCsn|jj|jd�}|dkrdSx$|jj�D]\}}|j||d�q(W|jdkr\|j}|j|�|jj	|j�dS)NTr>)
rzr4r`rr0rNr?rrOr~)r
rRrPrrrr�_restore_all_irq_affinity)s

z)SchedulerPlugin._restore_all_irq_affinitycCsFt|�jt|��}|r,tjtj||f�ntjtj|||f�|S)N)r�issubsetrir|rRr*r�r+)r
�irq_description�correct_affinityr,rCrrr�_verify_irq_affinity4s
z$SchedulerPlugin._verify_irq_affinitycCs�|jj|jd�}tj�}d}x�|j�D]�}||jkrR|rRd|}tjt	j
|�q&y<||d}tjd||f�d|}	|j|	||�s�d}Wq&t
k
r�w&Yq&Xq&W|jjd�}
|jj|
�}|jdkr�|jd	||jd
kr�|n|j�r�d}|S)NTz-IRQ %s does not support changing SMP affinityrz#Read SMP affinity of IRQ '%s': '%s'zSMP affinity of IRQ %sFz/proc/irq/default_smp_affinityr>zdefault IRQ SMP affinityr�)rzr4r`r�rPr�rrir|rRZ STR_VERIFY_PROFILE_VALUE_MISSINGr�rXr�rr�r�r?)r
rWr0rRrrCrP�descriptionr,rVZcurrent_affinity_hexrrr�_verify_all_irq_affinity@s8
z(SchedulerPlugin._verify_all_irq_affinityr��
)r9r
c
Cs�d}d|_|dk	rrt|jj|��}t|j�}|j|�rRt||�}|jj|�|_n |jj|j�}tj	d||f�|sz|r�|dkr�dS|r�|j
r�|j||�SdS|r�|jr�|j
�d|j}	n|}	|j|	�|j
r�|j|�n|j
r�|j�dS)NzJInvalid isolated_cores specified, '%s' does not match available cores '%s'Tz	cgroup.%s)rrrr@r]rUr�r)rir�r_rZr�r
rHrSrT)
r
r;rr<r0r�isolatedZpresentZstr_cpusZps_affinityrrr�_isolated_cores_s6


zSchedulerPlugin._isolated_corescCs�d|||f}|jj|�}|r"|Sd||f}tjj|�sv|dkrPd||f}nd|||f}d|}|jdkrvd|_||j|<|S)Nz%s_%s_%sz/proc/sys/kernel/%s_%srOz%s/%sz%s/%s/%sz/sys/kernel/debug/%sT)rXr4r)r��existsrW)r
�prefix�	namespace�knobrr�rrr�_get_sched_knob_path�s

z$SchedulerPlugin._get_sched_knob_pathcCsJ|jj|j|||�dd�}|dkrFtjd|�|jrFtjd�d|_|S)N)rzError reading '%s'zUThis may not work with Secure Boot or kernel_lockdown (this hint is logged only once)F)rr�rbrir�rW)r
r_r`rar$rrr�_get_sched_knob�s
zSchedulerPlugin._get_sched_knobcCsN|dkrdS|sJ|jj|j|||�||r0tjgndd�sJtjd||f�|S)NF)r�z Error writing value '%s' to '%s')rr�rbr�r�rir�)r
r_r`rar�sim�removerrr�_set_sched_knob�szSchedulerPlugin._set_sched_knobr�cCs|jddd�S)NrOr=�min_granularity_ns)rc)r
rrr�_get_sched_min_granularity_ns�sz-SchedulerPlugin._get_sched_min_granularity_nscCs|jddd|||�S)NrOr=rg)rf)r
rrdrerrr�_set_sched_min_granularity_ns�sz-SchedulerPlugin._set_sched_min_granularity_nsr�cCs|jddd�S)NrOr=�
latency_ns)rc)r
rrr�_get_sched_latency_ns�sz%SchedulerPlugin._get_sched_latency_nscCs|jddd|||�S)NrOr=rj)rf)r
rrdrerrr�_set_sched_latency_ns�sz%SchedulerPlugin._set_sched_latency_nsr�cCs|jddd�S)NrOr=�wakeup_granularity_ns)rc)r
rrr� _get_sched_wakeup_granularity_ns�sz0SchedulerPlugin._get_sched_wakeup_granularity_nscCs|jddd|||�S)NrOr=rm)rf)r
rrdrerrr� _set_sched_wakeup_granularity_ns�sz0SchedulerPlugin._set_sched_wakeup_granularity_nsr�cCs|jddd�S)NrOr=�tunable_scaling)rc)r
rrr�_get_sched_tunable_scaling�sz*SchedulerPlugin._get_sched_tunable_scalingcCs|jddd|||�S)NrOr=rp)rf)r
rrdrerrr�_set_sched_tunable_scaling�sz*SchedulerPlugin._set_sched_tunable_scalingr�cCs|jddd�S)NrOr=�migration_cost_ns)rc)r
rrr�_get_sched_migration_cost_ns�sz,SchedulerPlugin._get_sched_migration_cost_nscCs|jddd|||�S)NrOr=rs)rf)r
rrdrerrr�_set_sched_migration_cost_ns�sz,SchedulerPlugin._set_sched_migration_cost_nsr�cCs|jddd�S)NrOr=�
nr_migrate)rc)r
rrr�_get_sched_nr_migrate�sz%SchedulerPlugin._get_sched_nr_migratecCs|jddd|||�S)NrOr=rv)rf)r
rrdrerrr�_set_sched_nr_migrate�sz%SchedulerPlugin._set_sched_nr_migrater�cCs|jddd�S)Nr=�numa_balancing�
scan_delay_ms)rc)r
rrr�!_get_numa_balancing_scan_delay_ms�sz1SchedulerPlugin._get_numa_balancing_scan_delay_mscCs|jddd|||�S)Nr=ryrz)rf)r
rrdrerrr�!_set_numa_balancing_scan_delay_ms�sz1SchedulerPlugin._set_numa_balancing_scan_delay_msr�cCs|jddd�S)Nr=ry�scan_period_min_ms)rc)r
rrr�&_get_numa_balancing_scan_period_min_ms�sz6SchedulerPlugin._get_numa_balancing_scan_period_min_mscCs|jddd|||�S)Nr=ryr})rf)r
rrdrerrr�&_set_numa_balancing_scan_period_min_ms�sz6SchedulerPlugin._set_numa_balancing_scan_period_min_msr�cCs|jddd�S)Nr=ry�scan_period_max_ms)rc)r
rrr�&_get_numa_balancing_scan_period_max_ms�sz6SchedulerPlugin._get_numa_balancing_scan_period_max_mscCs|jddd|||�S)Nr=ryr�)rf)r
rrdrerrr�&_set_numa_balancing_scan_period_max_ms�sz6SchedulerPlugin._set_numa_balancing_scan_period_max_msr�cCs|jddd�S)Nr=ry�scan_size_mb)rc)r
rrr� _get_numa_balancing_scan_size_mb�sz0SchedulerPlugin._get_numa_balancing_scan_size_mbcCs|jddd|||�S)Nr=ryr�)rf)r
rrdrerrr� _set_numa_balancing_scan_size_mb�sz0SchedulerPlugin._set_numa_balancing_scan_size_mb)F)F)F)F)F)brrrrKrrjr�r��classmethodr�rmr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr	r
rrr}r%r&rRZ
ROLLBACK_SOFTr'r-r.r/r2r3r Zcommand_customr=rYrZr_rArBr�r�r�rGrFrErHrNrOrSrTrXrZr]rbrcrfZcommand_getrhZcommand_setrirkrlrnrorqrrrtrurwrxr{r|r~rr�r�r�r��
__classcell__rr)rerrN�s�(?




	



<

	
"$	
	rN) rOrZ
decoratorsZ
tuned.logsZtunedr�
subprocessr�r\r4Ztuned.constsrRr�Ztuned.utils.commandsrr�r)r�rhrrcrMZlogsr4ri�objectrrrrLZPluginrNrrrr�<module>s0


/

?>