2Yc@sddlZddlTddlZddlZddlTddlZddlZddlZddl j Z ddl Z ddl Z ddl mZddlZejjZdejfdYZdS(iN(t*(tcommandstSchedulerPlugincBseZdZidd6dd6dd6dd6d d 6Zd Zd Zd ZdZedZ dZ dZ dZ dZ dZedZdZdZedZd0dZedZedZdZedZdZdZd Zed!d"ed#Zed$d"ed%Zd&Z d'Z!d(Z"eed)Z#d*Z$ed+Z%ed,d"ed-d.d/Z&RS(1s Plugin for tuning of scheduler. Currently it can control scheduling priorities of system threads (it is substitution for the rtctl tool). tft SCHED_FIFOtbt SCHED_BATCHtrtSCHED_RRtot SCHED_OTHERtit SCHED_IDLEc Cst|j|j||||||||t|_tj|_ttj |_ |dk r|j tj tj|_t|jtjtj |_ nt|_d|_d|_dS(Ns.*t(tsupert __class__t__init__tTruet_has_dynamic_optionstconststCFG_DEF_DAEMONt_daemontinttCFG_DEF_SLEEP_INTERVALt_sleep_intervaltNonetget_boolt CFG_DAEMONtgettCFG_SLEEP_INTERVALRt_cmdt _ps_whitelistt _ps_blacklist( tselftmonitor_repositorytstorage_factorythardware_inventorytdevice_matchertdevice_matcher_udevtplugin_instance_factoryt global_cfgt variables((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRs.   $  cCs d|jS(Ns %s/options(tname(R!tinstance((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_scheduler_storage_key,scCst|_t|_t|_|jj|j|i|_t |jdkrt j d|j |i|_|jj |j|n|j|_x1|jD]&}|jj|j||j|qscSst|dkS(Ni(R@(R ((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRqrscSs|jddS(Ni(tsplitR(ts((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRqrss (RtexecuteR@RtdicttmaptfilterRr(R!trctout((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt get_processesms ! cCs:|jdd}t|dkr2|djSdSdS(Nt:ii(RrR@RhR(R!tvaltv((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt _parse_valtscCs&ytj|}tSWntSXdS(N(tprocfstpidstatRR:(R!Rjtp((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt _pid_exists{s cCs|jjddt|gdt\}}}|dkrp|j|r[tj|ntjd|dS|j dd}t |dkr|j |d}|j |d}n d}d}tjd|||f||fS( Ntchrts-pt return_errisCUnable to read scheduling parameters for PID %s, the task vanished.s is9read scheduler policy '%s' and priority '%s' for pid '%s'( RRttstrRRRAterrortdebugRRrR@R~(R!RjRxRyterr_msgtvalstschedtprio((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_get_rts0 cCs|jjddt|gd|r-dgngdt\}}}|dkr|dksd| r|j|rtj|qtjd|ndS|j |j ddd}tjd ||f|S( Nttasksets-pt no_errorsiRis6Unable to read affinity for PID %s, the task vanished.s sread affinity '%s' for pid '%s'( RRtRRRRARRRR~Rr(R!RjRbRxRyRR}((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt _get_affinitysE cCs|dkrd|SdSdS(NRRRR t-R (RRRR ((R!R((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_schedcfg2params cCs,yd|j|SWntk r'dSXdS(NRR (t_dict_sched2paramtKeyError(R!R((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt _sched2params c Cs&|dks|dkrdS|dk r]t|dkr]|g}tjd||fng}tjd||f|jjdg|dt|t|gd|rdgngdt\}}}|dks|dkr|rdS|j|rtj |ntjd |dS( Nis-setting scheduler policy to '%s' for PID '%s's/setting scheduler priority to '%s' for PID '%s'Rs-pRiRsBUnable to set scheduling parameters for PID %s, the task vanished.( RR@RARRRtRRRR( R!RjRRRbtschedltretRyR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_set_rts VcCsLy|dkr!tj|}n|djr|dddkrYtjd|n;t|ddkrtjd|ntjd|dSd SWntk r}|dt j ks|dt j krtjd |d Stj d |t |fd Sn:tttfk rG}tj d |t |fd SXdS(NtstattstatetZsYAffinity of zombie task with PID %s cannot be changed, the task's affinity mask is fixed.Rlis[Affinity of kernel thread with PID %s cannot be changed, the task's affinity mask is fixed.sRAffinity of task with PID %s cannot be changed, the task's affinity mask is fixed.is5Unable to set affinity for PID %s, the task vanished.is&Failed to get task info for PID %s: %si(RRtprocesstis_bound_to_cpuRARR@twarntIOErrorterrnotENOENTtESRCHRRtOSErrortAttributeErrorR(R!RjRte((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_affinity_changeables( &cCs|dks|dkrdStjd||f|jjddt|t|gd|ridgngdt\}}}|dks|dkr|rdS|j|}|dks|dkrtj|ndS( Ns%setting affinity to '%s' for PID '%s'Rs-pRiRii( RRARRRtRRRR(R!RjtaffinityRbRRyRtres((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt _set_affinitysNc Cs|j|}|j||} | dk r|dk rt|dkr|ddk r|ddk r||d|d| f|j|tsetR?RR=RItThreadt _thread_codet_threadtstart( R!R+Rntbuft sched_allRt processesRtv4Rj((RRRsB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRs8     ! &0!cCst|j|j|||j}|jrW|jrW|jj|jj nx|j j D]u\}}yS|||dkr|j ||j |d|d|j||dnWqgtk r}qgXqgWdS(Niiii(RRRCRzRR=RKRRtjoinR?RRRRR(R!R+t full_rollbackRnRjRR((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRCs  $c Cs|j|}|dkrdS|jj|j||}|dk r||jkrtjd||t|f|j ||||d|d|ddt |j j d|jndS(NR s-tuning new process '%s' with pid '%s' by '%s'iiiRbRE( RmRt re_lookupRRR?RARRRRR>R(R!R+RjRRkR}((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt_add_pid&s  .cCsG||jkrC|j|=tjd||jjd|jndS(Ns)removed PID %s from the rollback databaseRE(R?RARR>R(R!R+Rj((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt _remove_pid2s cCsD|jj|j}tj}x$|jjD]}|j|q1Wx|jj s?t |j|j ddkrK|jj rKt }x|r8t }x|jD]}|jj|}|rt }|jtjkr|j|t|j|q1|jtjkr1|j|t|jq1qqWqWqKqKWdS(Nii(Rtre_lookup_compileRtselecttpollRXt get_pollfdtregisterRKtis_setR@RRR:RNt read_on_cpuR/RLt RECORD_COMMRRRjt RECORD_EXITR(R!R+RRtfdt read_eventstcputevent((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR8s" 2 R^t per_devicecCsS|r dS|rO|dk rOdjtdtjdt||_ndS(Nt|cSsd|S(Ns(%s)((R}((sB/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRqRss(?s