MINI MINI MANI MO

Path : /usr/lib/python2.7/site-packages/tuned/plugins/
File Upload :
Current File : //usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyo


=[c@sddlmZddlTddlZddlZddlTddlZddlZddl	Z	ddl
jZddlZddl
Z
ddlmZddlZejjZdefdYZdefd	YZd
ejfdYZdS(i(tbase(t*iN(tcommandstSchedulerParamscBs>eZdddddZedZejdZRS(cCs1||_||_||_||_||_dS(N(t_cmdtcmdlinet	schedulertprioritytaffinity(tselftcmdRRRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt__init__s
				cCs*|jdkrdS|jj|jSdS(N(t	_affinitytNoneRtbitmask2cpulist(R	((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRscCs1|dkrd|_n|jj||_dS(N(R
RRtcpulist2bitmask(R	tvalue((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR%sN(t__name__t
__module__R
RtpropertyRtsetter(((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRst
IRQAffinitiescBseZdZRS(cCsi|_d|_dS(N(tirqsR
tdefault(R	((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR-s	(RRR(((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR,stSchedulerPlugincBseZdZiejd6ejd6ejd6ejd6ejd6Z	dZ
dZdZe
d	Zd
ZdZdZd
ZdZdZdZdZdZedZdZdZdZdZdZdZedZ dZ!dZ"dZ#e$dded Z%e$d!ded"Z&d#Z'd$Z(d%Z)ed&Z*d'Z+d(Z,d)Z-d*Z.d+Z/d,Z0d-Z1d.Z2e$d/ded0d1d2Z3RS(3s
	Plugin for tuning of scheduler. Currently it can control scheduling
	priorities of system threads (it is substitution for the rtctl tool).
	tftbtrtotic			Cstt|j||||||||t|_tj|_ttj	|_
|dk	r|jtj
tj|_t|jtjtj	|_
nt|_d|_d|_tj|_|jdd|_|jdd|_dS(Ns.*ttcommand_nameRtirq(tsuperRRtTruet_has_dynamic_optionstconststCFG_DEF_DAEMONt_daemontinttCFG_DEF_SLEEP_INTERVALt_sleep_intervalR
tget_boolt
CFG_DAEMONtgettCFG_SLEEP_INTERVALRRt
_ps_whitelistt
_ps_blacklisttperftcpu_mapt_cpust_storage_keyt_scheduler_storage_keyt_irq_storage_key(	R	tmonitor_repositorytstorage_factorythardware_inventorytdevice_matchertdevice_matcher_udevtplugin_instance_factoryt
global_cfgt	variables((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR?s+	$				cCst|_t|_t|_|jj|ji|_t	|jdkrt
jd|ji|_|jj
|jn|j|_x1|jD]&}|jj|j||j|<qW|jj|jjdddkrt|_ntj|_|jr|jrytj|_tjdtjdtjddd	dd
dddddd
ddtjtjB	}|j d|j!d|jtj"|j!|j|_#|j#j$||j#j%Wqt|_qXndS(Nis0recovering scheduling settings from previous runtruntimeit0ttypetconfigttasktcommtmmaptfreqt
wakeup_eventst	watermarktsample_typetcpustthreads(&tFalset_has_dynamic_tuningR"t_has_static_tuningt_runtime_tuningt_storageR,R4t_scheduler_originaltlentlogtinfot_restore_ps_affinitytunsettoptionst
_schedulert
_variablestexpandRR*t	threadingtEventt
_terminateR&R0t
thread_mapt_threadstevselt
TYPE_SOFTWAREtCOUNT_SW_DUMMYt
SAMPLE_TIDt
SAMPLE_CPUtopenR2tevlistt_evlisttaddRD(R	tinstancetkR_((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_instance_initQs<				

	$'	cCsdS(N((R	Rh((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_instance_cleanupyscCsidd6dd6dd6S(Ntisolated_corestps_whitelisttps_blacklist(R
(tcls((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_get_config_options|scCs]t|tjs*|}tj|}ntj|}|j|rYd|d}n|S(Nt[t](t
isinstancetprocfstprocesstprocess_cmdlinet_is_kthread(R	RutpidR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_get_cmdlinescCstj}|ji}x|jD]}yj|j|}|d}|||<d|krx4|djD]}|j|}|||<qrWnWq)ttfk
r}|jtj	ks)|jtj
krq)qq)Xq)W|S(NRxRJ(Rttpidstatstreload_threadstvaluesRytkeystOSErrortIOErrorterrnotENOENTtESRCH(R	tpst	processestprocR
Rxte((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt
get_processess$


cCsQtj|}tj|}tj|}tjd|||f||fS(Ns8Read scheduler policy '%s' and priority '%d' of PID '%d'(t
schedutilst
get_schedulertschedstrtget_priorityRRtdebug(R	RxRt	sched_strR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_get_rts	cCs3tj|}tjd|||fyZtj|}tj|}||ksb||krtjd||||fnWn*ttfk
r}tjd|nXytj	|||Wnettfk
r.}t
|dr|jtjkrtjd|q/tjd||fnXdS(NsBSetting scheduler policy to '%s' and priority to '%d' of PID '%d'.s9Priority for %s must be in range %d - %d. '%d' was given.s(Failed to get allowed priority range: %sRsAFailed to set scheduling parameters of PID %d, the task vanished.s1Failed to set scheduling parameters of PID %d: %s(
RRRRRtget_priority_mintget_priority_maxterrortSystemErrorR~t
set_schedulerthasattrRR(R	RxtschedtprioRtprio_mintprio_maxR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_set_rts*			!		cCs|ddtjj@dkS(Ntstattflagsi(Rttpidstatt
PF_KTHREAD(R	Ru((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRwscCs+ytj|}|djr|dddkrJtjd|n4|j|rmtjd|ntjd|dSdSWnttfk
r}|j	t	j
ks|j	t	jkrtjd	|d
Stjd||fdSn1t
tfk
r&}tjd||fdSXdS(
NRtstatetZsYAffinity of zombie task with PID %d cannot be changed, the task's affinity mask is fixed.s[Affinity of kernel thread with PID %d cannot be changed, the task's affinity mask is fixed.sRAffinity of task with PID %d cannot be changed, the task's affinity mask is fixed.iis6Failed to get task info for PID %d, the task vanished.is&Failed to get task info for PID %d: %si(RtRutis_bound_to_cpuRRRRwtwarnR~RRRRRtAttributeErrortKeyError(R	RxRuR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_affinity_changeables2			$			cCsxy|j|}Wn-tk
r@t|j}||j|<nX|jdkrt|jdkrt||_||_ndS(N(RPRRRRR
R(R	RxRRtparams((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_store_orig_process_rts
	cCst}|dkr"|dkr"|SyT|j|\}}|dkrO|}n|j||||j|||Wnttfk
r}t|dr|jtj	krt
jd|||jkr|j|=nt
}qt
jd||fnX|S(NRs=Failed to read scheduler policy of PID %d, the task vanished.scRefusing to set scheduler and priority of PID %d, reading original scheduling parameters failed: %s(R"R
RRRRR~RRRRRRRPRKR(R	RxRRtcontt
prev_schedt	prev_prioR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_tune_process_rts&	!	
		cCs`y|j|}Wn-tk
r@t|j}||j|<nX|jdkr\||_ndS(N(RPRRRRR
(R	RxRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_store_orig_process_affinitys
cCst}|dkr|SyQ|j|}|rF|j|||}n|j|||j||Wnttfk
r}t|dr|j	t	j
krtjd|||j
kr|j
|=nt}qtjd||fnX|S(NRs5Failed to read affinity of PID %d, the task vanished.sLRefusing to set CPU affinity of PID %d, reading original affinity failed: %s(R"R
t
_get_affinityt_get_intersect_affinityt
_set_affinityRRR~RRRRRRRPRKR(R	RxRt	intersectRt
prev_affinityR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_tune_process_affinitys,	!	
		cCs_|j|||}|sdS|j||}|sG||jkrKdS||j|_dS(N(RRRPR(R	RxR
RRRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt
_tune_process5scCs|jj|}|dkr?|dkr?tjd|dSyt|}Wn#tk
rttjd|dSX||fS(NRs>Invalid scheduler: %s. Scheduler and priority will be ignored.s=Invalid priority: %s. Scheduler and priority will be ignored.(NN(NN(t_dict_schedcfg2numR,R
RRRR't
ValueError(R	t
str_schedulertstr_priorityRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_convert_sched_params>s	
	cCsK|dkrd}n2|jj|}|sGtjd|d}n|S(NRs)Invalid affinity: %s. It will be ignored.(R
Rthex2cpulistRRR(R	tstr_affinityR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_convert_affinityMs			cCsO|\}}}}}|j||\}}|j|}|||||fS(N(RR(R	tvalst	rule_prioRRRtregex((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_convert_sched_cfgXs
cCstt|j|y|j}Wn+ttfk
rS}tjd|dSXg|jj	D]*\}}|t
|jddf^qd}g|D]E\}}tj
d|rt|dkr||j|f^q}t|dd}t}	i|_x6|D].\}\}
}}}
}ytj|}Wn0tjk
rt}tjdt
|qnXg|j	D]0\}}tj||dk	r||f^q}tg|D]*\}}||||||
|ff^q}|	j|t
|jd	d
}|jdd}|||
g|j|<qWxE|	j	D]7\}\}}}}}
}|j|||||
qSW|jj|j|j|jr|jrtj d
|j!d|g|_"|j"j#ndS(NsIerror applying tuning, cannot get information about running processes: %st:isgroup\.itkeycSs|ddS(Nii((toption_vals((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt<lambda>lss(error compiling regular expression: '%s't(s\(t)s\)ttargettargs($R!Rt_instance_apply_staticRR~RRRRRWtitemststrtsplittretmatchRQRtsortedtdictt
_sched_lookuptcompiletsearchR
tupdatetreplaceRROtsetR4RPR&RNRZtThreadt_thread_codet_threadtstart(R	RhRRtoptionRt	sched_cfgRtbuft	sched_allRRRRRRRxR
RR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR_sL	@-		C7
(
!cCsy|j}Wn+ttfk
r=}tjd|dSXx|jjD]\}}||ksN|||jkrqNn|jdk	r|j
dk	r|j||j|j
n|jdk	rN|j
||jqNqNWi|_|jj|jdS(NsKerror unapplying tuning, cannot get information about running processes: %s(RR~RRRRRPRRRR
RRRRRORUR4(R	RRRxtorig_params((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRTs"	
	cCsVtt|j|||jrH|jrH|jj|jjn|j	dS(N(
R!Rt_instance_unapply_staticR&RNR\RRtjoinRT(R	Rht
full_rollback((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRs

c
Csy|j|}Wnittfk
r~}|jtjksO|jtjkrctjd|ntjd||fdSX|j	j
|j||}|dk	r||j
krtjd||t|f|\}}}	|j|||||	|jj|j|j
ndS(Ns3Failed to get cmdline of PID %d, the task vanished.s#Failed to get cmdline of PID %d: %ss-tuning new process '%s' with PID '%d' by '%s'(RyR~RRRRRRRRRt	re_lookupRR
RPRRRORR4(
R	RhRxRR
RtvRRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_add_pids$		 cCsJ||jkrF|j|=tjd||jj|j|jndS(Ns)removed PID %d from the rollback database(RPRRRRORR4(R	RhRx((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_remove_pids

cCsD|jj|j}tj}x$|jjD]}|j|q1Wx|jj	s?t
|j|jddkrK|jj	rKt}x|r8t
}x|jD]}|jj|}|rt}|jtjkr|j|t|j|q1|jtjkr1|j|t|jq1qqWqWqKqKWdS(Nii(Rtre_lookup_compileRtselecttpollRft
get_pollfdtregisterR\tis_setRQR)R"RKR2tread_on_cpuR@R0tRECORD_COMMRR'ttidtRECORD_EXITR(R	RhRRtfdtread_eventstcputevent((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRs"2	Rmt
per_devicecCs^|r
dS|rZ|dk	rZdjgtjdt|D]}d|^q;|_ndS(Nt|s(?<!\\);s(%s)(R
RRRRR.(R	tenablingRtverifytignore_missingR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR.sRncCs^|r
dS|rZ|dk	rZdjgtjdt|D]}d|^q;|_ndS(NRs(?<!\\);s(%s)(R
RRRRR/(R	RRRRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR/scCs*tj|}tjd||f|S(NsRead affinity '%s' of PID %d(Rtget_affinityRRR(R	Rxtres((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRscCstjd||fytj||tSWnttfk
r}t|dr||jtj	kr|tjd|nD|j
|}|dks|dkrtjd|||fntSXdS(Ns'Setting CPU affinity of PID %d to '%s'.Rs4Failed to set affinity of PID %d, the task vanished.iis,Failed to set affinity of PID %d to '%s': %s(
RRRRtset_affinityR"RR~RRRRRRK(R	RxRRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRs!		cCs/t|jt|}|r+t|S|S(N(Rtintersectiontlist(R	t	affinity1t	affinity2t	affinity3taff((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRs
cCsg|D]0}tj|j|j|dk	r|^q}|jdkrg|D]0}tj|j|j|dkrS|^qS}ntg|D]}|j|f^q}x|D]}y|j||}Wnkt	t
fk
rE}	|	jtjks|	jtj
kr(tjd|qtjd||	fqnX|j||dt}
|
sjqn||jkr||j|_n|rd||kr|j||dj|tqqWdS(NRs3Failed to get cmdline of PID %d, the task vanished.sARefusing to set affinity of PID %d, failed to get its cmdline: %sRRJ(RRR.t_get_stat_commR
R/RRxRyR~RRRRRRRRRR"RPRt_set_all_obj_affinityR|(R	tobjsRRJRtpsltpsdRxR
RR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRs6$'(
			cCs2y|ddSWntttfk
r-dSXdS(NRRCR(R~RR(R	R((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR%scCsdy3tj}|j|j|j|tWn*ttfk
r_}tj	d|nXdS(NsIerror applying tuning, cannot get information about running processes: %s(
RtRzR{RR|RKR~RRRR(R	RRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_set_ps_affinity+s
	cCsy`|jj|}tjd||fd|}t|d}|j|WdQXtSWnpttfk
r}t	|dr|j
t
jkr|rtjd|ntjd|||ft
SXdS(Ns&Setting SMP affinity of IRQ %s to '%s's/proc/irq/%s/smp_affinitytwRs/Setting SMP affinity of IRQ %s is not supporteds0Failed to set SMP affinity of IRQ %s to '%s': %s(Rtcpulist2hexRRRRdtwriteR"R~RRRtEIORRK(R	R Rt	restoringtaffinity_hextfilenameRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_set_irq_affinity4s 	
!		cCsyL|jj|}tjd|tdd}|j|WdQXWn0ttfk
r~}tjd||fnXdS(Ns(Setting default SMP IRQ affinity to '%s's/proc/irq/default_smp_affinityRs2Failed to set default SMP IRQ affinity to '%s': %s(	RRRRRRdR	R~RR(R	RRRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_set_default_irq_affinityKs		cCs-t}tj}x|jD]}y)||d}tjd||fWntk
rgq"nX|j|||}t|t|krq"n|j	||t
r"||j|<q"q"W|jj
d}|jj|}|j|||}|j|||_|jj|j|dS(NRsRead affinity of IRQ '%s': '%s's/proc/irq/default_smp_affinity(RRtt
interruptsR}RRRRRRRRKRRt	read_fileRRRROR5(R	Rtirq_originalRR RRtprev_affinity_hex((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_set_all_irq_affinityVs(		

	cCs|jj|jd}|dkr(dSx0|jjD]\}}|j||tq8W|j}|j	||jj
|jdS(N(ROR,R5R
RRRR"RRRU(R	RR R((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_restore_all_irq_affinityns	
cCs_t|jt|}|r>tjtj||fntjtj|||f|S(N(RtissubsetRRRSR$tSTR_VERIFY_PROFILE_VALUE_OKRtSTR_VERIFY_PROFILE_VALUE_FAIL(R	tirq_descriptiontcorrect_affinitytcurrent_affinityR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_verify_irq_affinityxscCstj}t}x||jD]n}yQ||d}tjd||fd|}|j|||sut}nWqtk
rqqXqW|j	j
d}|j	j|}|jd||st}n|S(NRs#Read SMP affinity of IRQ '%s': '%s'sSMP affinity of IRQ %ss/proc/irq/default_smp_affinitysdefault IRQ SMP affinity(RtRR"R}RRRRRKRRRR(R	RRRR RRtcurrent_affinity_hex((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_verify_all_irq_affinitys,	
	

				RlRi
c
Csd}|dk	rt|jj|}t|j}|j|r[t||}qdjg|jD]}t|^qk}	t	j
d||	fn|s|r|dkrdS|r|j|S|r|j||j
|n
|jdS(Nt,sJInvalid isolated_cores specified, '%s' does not match available cores '%s'(R
RRtcpulist_unpackR2RRRRRRRRRRR(
R	RRRRRtisolatedtpresenttxtstr_cpus((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_isolated_coress"+	

(4RRt__doc__Rt
SCHED_FIFOtSCHED_BATCHtSCHED_RRtSCHED_OTHERt
SCHED_IDLERRRjRktclassmethodRpRyRRRRwRRRRRKRRRRRRRTRRRRtcommand_customR.R/RRRRRRRRRRRRR%(((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR1s\




		(			
						
									*														
		(RRt
decoratorst
tuned.logsttunedRt
subprocessRZR0Rttuned.constsR$RtRttuned.utils.commandsRRtlogsR,RRtobjectRRtPluginR(((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt<module>s 



OHA YOOOO