\c@sddlmZddlTddlZddlZddlTddlZddlZddl Z ddl j Z ddl Z ddl Z ddlmZddlZejjZdefdYZdefd YZd ejfd YZdS( 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 R tpropertyRtsetter(((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 dZ dZ e d Zd Zd Zd 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(tsuperRR tTruet_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 j d|j i|_|jj |jn|j|_x1|jD]&}|jj|j||j|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 Rt hex2cpulistRRR(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 c Cstt|j|y|j}Wn+ttfk rS}tjd|dSXg|jj D]*\}}|t |j ddf^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 }|jd d }| | | g|j|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 RRRxt orig_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  c CsJ|jj|j}tj}|jj}x|D]}|j|q7Wx|jj sEt |j|j ddkrQ|jj rQt }x|r>t }x|jD]}|jj|}|rt }|jtjkr|j|t|j|q7|jtjkr7|j|t|jq7qqWqWqQqQWdS(Nii(Rtre_lookup_compileRtselecttpollRft get_pollfdtregisterR\tis_setRQR)R"RKR2t read_on_cpuR@R0t RECORD_COMMRR'ttidt RECORD_EXITR( R RhRRtfdstfdt read_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(?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_affinity|s   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_FIFOt SCHED_BATCHtSCHED_RRt SCHED_OTHERt SCHED_IDLERR RjRkt classmethodRpRyRRRRwRRRRRKRRRRRRRTRRRRtcommand_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.pyts