
\c           @   s   d  d l  m Z d  d l Td d l Z d d l Z d d l Td d l Z d d l Z d d l	 Z	 d d l
 j Z d d l Z d d l Z d d l m Z d d l Z e j j   Z d e f d     YZ d e f d	     YZ d
 e j f d     YZ d S(   i   (   t   base(   t   *iN(   t   commandst   SchedulerParamsc           B   s>   e  Z d d d d d   Z e d    Z e j d    Z RS(   c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   _cmdt   cmdlinet	   schedulert   priorityt   affinity(   t   selft   cmdR   R   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   __init__   s
    				c         C   s*   |  j  d  k r d  S|  j j |  j   Sd  S(   N(   t	   _affinityt   NoneR   t   bitmask2cpulist(   R	   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR      s    c         C   s1   | d  k r d  |  _ n |  j j |  |  _ d  S(   N(   R   R   R   t   cpulist2bitmask(   R	   t   value(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR   %   s    N(   t   __name__t
   __module__R   R   t   propertyR   t   setter(    (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR      s   t   IRQAffinitiesc           B   s   e  Z d    Z RS(   c         C   s   i  |  _  d  |  _ d  S(   N(   t   irqsR   t   default(   R	   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR   -   s    	(   R   R   R   (    (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR   ,   s   t   SchedulerPluginc           B   s  e  Z d  Z i e j d 6e j d 6e j d 6e j d 6e j d 6Z	 d   Z
 d   Z d   Z e d	    Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z  d   Z! d   Z" d   Z# e$ d d e d     Z% e$ d! d e d"    Z& d#   Z' d$   Z( d%   Z) e d&  Z* d'   Z+ d(   Z, d)   Z- d*   Z. d+   Z/ d,   Z0 d-   Z1 d.   Z2 e$ d/ d e d0 d1 d2    Z3 RS(3   s   
	Plugin for tuning of scheduler. Currently it can control scheduling
	priorities of system threads (it is substitution for the rtctl tool).
	t   ft   bt   rt   ot   ic	   	   	   C   s   t  t |   j | | | | | | | |  t |  _ t j |  _ t t j	  |  _
 | d  k	 r | j t j t j  |  _ t | j t j t j	   |  _
 n  t   |  _ d |  _ d |  _ t j   |  _ |  j d d  |  _ |  j d d  |  _ d  S(   Ns   .*t    t   command_nameR   t   irq(   t   superR   R   t   Truet   _has_dynamic_optionst   constst   CFG_DEF_DAEMONt   _daemont   intt   CFG_DEF_SLEEP_INTERVALt   _sleep_intervalR   t   get_boolt
   CFG_DAEMONt   gett   CFG_SLEEP_INTERVALR   R   t   _ps_whitelistt   _ps_blacklistt   perft   cpu_mapt   _cpust   _storage_keyt   _scheduler_storage_keyt   _irq_storage_key(	   R	   t   monitor_repositoryt   storage_factoryt   hardware_inventoryt   device_matchert   device_matcher_udevt   plugin_instance_factoryt
   global_cfgt	   variables(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR   ?   s    +	$				c         C   s  t  | _ t | _ t | _ |  j j |  j i   |  _ t	 |  j  d k r t
 j d  |  j   i  |  _ |  j j |  j  n  | j | _ x1 | j D]& } |  j j | j |  | j | <q W|  j j | j j d d   d k r t  | _ n  t j   | _ |  j r| j ry t j   | _ t j d t j d t j d d d	 d d
 d d d d d d d d t j t j B 	} | j  d |  j! d | j  t j" |  j! | j  | _# | j# j$ |  | j# j%   Wqt  | _ qXn  d  S(   Ni    s0   recovering scheduling settings from previous runt   runtimei   t   0t   typet   configt   taskt   commt   mmapt   freqt   wakeup_eventst	   watermarkt   sample_typet   cpust   threads(&   t   Falset   _has_dynamic_tuningR"   t   _has_static_tuningt   _runtime_tuningt   _storageR,   R4   t   _scheduler_originalt   lent   logt   infot   _restore_ps_affinityt   unsett   optionst
   _schedulert
   _variablest   expandR   R*   t	   threadingt   Eventt
   _terminateR&   R0   t
   thread_mapt   _threadst   evselt   TYPE_SOFTWAREt   COUNT_SW_DUMMYt
   SAMPLE_TIDt
   SAMPLE_CPUt   openR2   t   evlistt   _evlistt   addRD   (   R	   t   instancet   kR_   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _instance_initQ   s<    				
	$'	c         C   s   d  S(   N(    (   R	   Rh   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _instance_cleanupy   s    c         C   s   i d  d 6d  d 6d  d 6S(   Nt   isolated_corest   ps_whitelistt   ps_blacklist(   R   (   t   cls(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _get_config_options|   s    c         C   s]   t  | t j  s* | } t j |  } n  t j |  } |  j |  rY d | d } n  | S(   Nt   [t   ](   t
   isinstancet   procfst   processt   process_cmdlinet   _is_kthread(   R	   Ru   t   pidR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _get_cmdline   s    c         C   s   t  j   } | j   i  } x | j   D] } yj |  j |  } | d } | | | <d | k r x4 | d j   D] } |  j |  } | | | <qr Wn  Wq) t t f k
 r } | j t j	 k s) | j t j
 k r q) q   q) Xq) W| S(   NRx   RJ   (   Rt   t   pidstatst   reload_threadst   valuesRy   t   keyst   OSErrort   IOErrort   errnot   ENOENTt   ESRCH(   R	   t   pst	   processest   procR
   Rx   t   e(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   get_processes   s$    


c         C   sQ   t  j |  } t  j |  } t  j |  } t j d | | | f  | | f S(   Ns8   Read scheduler policy '%s' and priority '%d' of PID '%d'(   t
   schedutilst   get_schedulert   schedstrt   get_priorityRR   t   debug(   R	   Rx   R   t	   sched_strR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _get_rt   s    	c         C   s3  t  j |  } t j d | | | f  yZ t  j |  } t  j |  } | | k  sb | | k r t j d | | | | f  n  Wn* t t f k
 r } t j d |  n Xy t  j	 | | |  Wne t t f k
 r.} t
 | d  r| j t j k rt j d |  q/t j d | | f  n Xd  S(   NsB   Setting scheduler policy to '%s' and priority to '%d' of PID '%d'.s9   Priority for %s must be in range %d - %d. '%d' was given.s(   Failed to get allowed priority range: %sR   sA   Failed to set scheduling parameters of PID %d, the task vanished.s1   Failed to set scheduling parameters of PID %d: %s(   R   R   RR   R   t   get_priority_mint   get_priority_maxt   errort   SystemErrorR~   t   set_schedulert   hasattrR   R   (   R	   Rx   t   schedt   prioR   t   prio_mint   prio_maxR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _set_rt   s*    			!		c         C   s   | d d t  j j @d k S(   Nt   statt   flagsi    (   Rt   t   pidstatt
   PF_KTHREAD(   R	   Ru   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRw      s    c         C   s+  y t  j |  } | d j   r | d d d k rJ t j d |  n4 |  j |  rm t j d |  n t j d |  d Sd SWn t t f k
 r } | j	 t	 j
 k s | j	 t	 j k r t j d	 |  d
 St j d | | f  d Sn1 t t f k
 r&} t j d | | f  d SXd  S(   NR   t   statet   ZsY   Affinity 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.sR   Affinity of task with PID %d cannot be changed, the task's affinity mask is fixed.i    i   s6   Failed to get task info for PID %d, the task vanished.is&   Failed to get task info for PID %d: %si(   Rt   Ru   t   is_bound_to_cpuRR   R   Rw   t   warnR~   R   R   R   R   R   t   AttributeErrort   KeyError(   R	   Rx   Ru   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _affinity_changeable   s2    			$			c         C   sx   y |  j  | } Wn- t k
 r@ t |  j  } | |  j  | <n X| j d  k rt | j d  k rt | | _ | | _ n  d  S(   N(   RP   R   R   R   R   R   R   (   R	   Rx   R   R   t   params(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _store_orig_process_rt   s    	c         C   s  t  } | d  k r" | d  k r" | SyT |  j |  \ } } | d  k rO | } n  |  j | | |  |  j | | |  Wn t t f k
 r } t | d  r | j t j	 k r t
 j d |  | |  j k r |  j | =n  t } q t
 j d | | f  n X| S(   NR   s=   Failed to read scheduler policy of PID %d, the task vanished.sc   Refusing to set scheduler and priority of PID %d, reading original scheduling parameters failed: %s(   R"   R   R   R   R   R   R~   R   R   R   RR   R   RP   RK   R   (   R	   Rx   R   R   t   contt
   prev_schedt	   prev_prioR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _tune_process_rt   s&    	!			c         C   s`   y |  j  | } Wn- t k
 r@ t |  j  } | |  j  | <n X| j d  k r\ | | _ n  d  S(   N(   RP   R   R   R   R   R   (   R	   Rx   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _store_orig_process_affinity  s    c         C   s   t  } | d  k r | SyQ |  j |  } | rF |  j | | |  } n  |  j | |  |  j | |  Wn t t f k
 r } t | d  r | j	 t	 j
 k r t j d |  | |  j k r |  j | =n  t } q t j d | | f  n X| S(   NR   s5   Failed to read affinity of PID %d, the task vanished.sL   Refusing to set CPU affinity of PID %d, reading original affinity failed: %s(   R"   R   t   _get_affinityt   _get_intersect_affinityt   _set_affinityR   R   R~   R   R   R   RR   R   RP   RK   R   (   R	   Rx   R   t	   intersectR   t   prev_affinityR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _tune_process_affinity  s,    	!			c         C   s_   |  j  | | |  } | s d  S|  j | |  } | sG | |  j k rK d  S| |  j | _ d  S(   N(   R   R   RP   R   (   R	   Rx   R
   R   R   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _tune_process5  s    c         C   s   |  j  j |  } | d  k r? | d k r? t j d |  d Sy t |  } Wn# t k
 rt t j d |  d SX| | f S(   NR   s>   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   RR   R   R'   t
   ValueError(   R	   t   str_schedulert   str_priorityR   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _convert_sched_params>  s    		c         C   sK   | d k r d  } n2 |  j j |  } | sG t j d |  d  } n  | S(   NR   s)   Invalid affinity: %s. It will be ignored.(   R   R   t   hex2cpulistRR   R   (   R	   t   str_affinityR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _convert_affinityM  s    			c         C   sO   | \ } } } } } |  j  | |  \ } } |  j |  } | | | | | f S(   N(   R   R   (   R	   t   valst	   rule_prioR   R   R   t   regex(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _convert_sched_cfgX  s
    c         C   s  t  t |   j |  y |  j   } Wn+ t t f k
 rS } t j d |  d  SXg  | j j	   D]* \ } } | t
 |  j d d  f ^ qd } g  | D]E \ } } t j d |  r t |  d k r | |  j |  f ^ q } t | d d   } t   }	 i  | _ x6| D].\ } \ }
 } } } } y t j |  } Wn0 t j k
 rt} t j d t
 |   qn Xg  | j	   D]0 \ } } t j | |  d  k	 r| | f ^ q} t g  | D]* \ } } | | | | | | | f f ^ q } |	 j |  t
 |  j d	 d
  } | j d d  } | | | g | j | <qWxE |	 j	   D]7 \ } \ } } } } } } |  j | | | | |  qSW|  j j |  j |  j  |  j r| j rt j  d |  j! d | g  | _" | j" j#   n  d  S(   NsI   error applying tuning, cannot get information about running processes: %st   :i   s   group\.i   t   keyc         S   s   |  d d S(   Ni   i    (    (   t   option_vals(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   <lambda>l  s    s(   error compiling regular expression: '%s't   (s   \(t   )s   \)t   targett   args($   R!   R   t   _instance_apply_staticR   R~   R   RR   R   RW   t   itemst   strt   splitt   ret   matchRQ   R   t   sortedt   dictt   _sched_lookupt   compilet   searchR   t   updatet   replaceR   RO   t   setR4   RP   R&   RN   RZ   t   Threadt   _thread_codet   _threadt   start(   R	   Rh   R   R   t   optionR   t	   sched_cfgR   t   buft	   sched_allR   R   R   R   R   R   Rx   R
   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR   _  sL    	@-		C7(
!c         C   s  y |  j    } Wn+ t t f k
 r= } t j d |  d  SXx |  j j   D] \ } } | | k sN | | | j k r qN n  | j d  k	 r | j
 d  k	 r |  j | | j | j
  n  | j d  k	 rN |  j | | j  qN qN Wi  |  _ |  j j |  j  d  S(   NsK   error unapplying tuning, cannot get information about running processes: %s(   R   R~   R   RR   R   RP   R   R   R   R   R   R   R   R   RO   RU   R4   (   R	   R   R   Rx   t   orig_params(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyRT     s"    		c         C   sV   t  t |   j | |  |  j rH | j rH | j j   | j j   n  |  j	   d  S(   N(
   R!   R   t   _instance_unapply_staticR&   RN   R\   R   R   t   joinRT   (   R	   Rh   t   full_rollback(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR     s
    c   
      C   s  y |  j  |  } Wni t t f k
 r~ } | j t j k sO | j t j k rc t j d |  n t j d | | f  d  SX|  j	 j
 | j | |  } | d  k	 r| |  j k rt j d | | t |  f  | \ } } }	 |  j | | | | |	  |  j j |  j |  j  n  d  S(   Ns3   Failed 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'(   Ry   R~   R   R   R   R   RR   R   R   R   t	   re_lookupR   R   RP   R   R   RO   R   R4   (
   R	   Rh   Rx   R   R
   R   t   vR   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _add_pid  s$    		 c         C   sJ   | |  j  k rF |  j  | =t j d |  |  j j |  j |  j   n  d  S(   Ns)   removed PID %d from the rollback database(   RP   RR   R   RO   R   R4   (   R	   Rh   Rx   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _remove_pid  s
    
c   	      C   sJ  |  j  j | j  } t j   } | j j   } x | D] } | j |  q7 Wx | j j	   sEt
 | j |  j d   d k rQ | j j	   rQ t } x | r>t } x |  j D] } | j j |  } | r t } | j t j k r|  j | t | j  |  q7| j t j k r7|  j | t | j   q7q q Wq WqQ qQ Wd  S(   Ni  i    (   R   t   re_lookup_compileR   t   selectt   pollRf   t
   get_pollfdt   registerR\   t   is_setRQ   R)   R"   RK   R2   t   read_on_cpuR@   R0   t   RECORD_COMMR   R'   t   tidt   RECORD_EXITR   (	   R	   Rh   R   R   t   fdst   fdt   read_eventst   cput   event(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR     s$    2	Rm   t
   per_devicec         C   s^   | r
 d  S| rZ | d  k	 rZ d j g  t j d t |   D] } d | ^ q;  |  _ n  d  S(   Nt   |s   (?<!\\);s   (%s)(   R   R   R   R   R   R.   (   R	   t   enablingR   t   verifyt   ignore_missingR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR.     s    Rn   c         C   s^   | r
 d  S| rZ | d  k	 rZ d j g  t j d t |   D] } d | ^ q;  |  _ n  d  S(   NR   s   (?<!\\);s   (%s)(   R   R   R   R   R   R/   (   R	   R   R   R   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR/     s    c         C   s*   t  j |  } t j d | | f  | S(   Ns   Read affinity '%s' of PID %d(   R   t   get_affinityRR   R   (   R	   Rx   t   res(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR     s    c         C   s   t  j d | | f  y t j | |  t SWn t t f k
 r } t | d  r| | j t j	 k r| t  j d |  nD |  j
 |  } | d k s | d k r t  j d | | | f  n  t SXd  S(   Ns'   Setting CPU affinity of PID %d to '%s'.R   s4   Failed to set affinity of PID %d, the task vanished.i   is,   Failed to set affinity of PID %d to '%s': %s(   RR   R   R   t   set_affinityR"   R   R~   R   R   R   R   R   RK   (   R	   Rx   R   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR     s    !		c         C   s/   t  |  j t  |   } | r+ t |  S| S(   N(   R   t   intersectiont   list(   R	   t	   affinity1t	   affinity2t	   affinity3t   aff(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR     s    
c         C   s  g  | D]0 } t  j |  j |  j |   d  k	 r | ^ q } |  j d k r g  | D]0 } t  j |  j |  j |   d  k rS | ^ qS } n  t g  | D] } | j | f ^ q  } x| D]} y |  j | |  } Wnk t	 t
 f k
 rE}	 |	 j t j k s|	 j t j k r(t j d |  q t j d | |	 f  q n X|  j | | d t }
 |
 sjq n  | |  j k r| |  j | _ n  | r d | | k r |  j | | d j   | t  q q Wd  S(   NR   s3   Failed to get cmdline of PID %d, the task vanished.sA   Refusing to set affinity of PID %d, failed to get its cmdline: %sR   RJ   (   R   R   R.   t   _get_stat_commR   R/   R   Rx   Ry   R~   R   R   R   R   RR   R   R   R   R"   RP   R   t   _set_all_obj_affinityR|   (   R	   t   objsR   RJ   R   t   pslt   psdRx   R
   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR  
  s6    $'(			c         C   s2   y | d d SWn t  t t f k
 r- d SXd  S(   NR   RC   R   (   R~   R   R   (   R	   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR  )  s    c         C   sd   y3 t  j   } | j   |  j | j   | t  Wn* t t f k
 r_ } t j	 d |  n Xd  S(   NsI   error applying tuning, cannot get information about running processes: %s(
   Rt   Rz   R{   R  R|   RK   R~   R   RR   R   (   R	   R   R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _set_ps_affinity/  s    
	c         C   s   y` |  j  j |  } t j d | | f  d | } t | d   } | j |  Wd  QXt SWnp t t f k
 r } t	 | d  r | j
 t
 j k r | r t j d |  n t j d | | | f  t SXd  S(   Ns&   Setting SMP affinity of IRQ %s to '%s's   /proc/irq/%s/smp_affinityt   wR   s/   Setting SMP affinity of IRQ %s is not supporteds0   Failed to set SMP affinity of IRQ %s to '%s': %s(   R   t   cpulist2hexRR   R   Rd   t   writeR"   R~   R   R   R   t   EIOR   RK   (   R	   R    R   t	   restoringt   affinity_hext   filenameR   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _set_irq_affinity8  s     	
!		c         C   s   yL |  j  j |  } t j d |  t d d   } | j |  Wd  QXWn0 t t f k
 r~ } t j d | | f  n Xd  S(   Ns(   Setting default SMP IRQ affinity to '%s's   /proc/irq/default_smp_affinityR  s2   Failed to set default SMP IRQ affinity to '%s': %s(	   R   R	  RR   R   Rd   R
  R~   R   R   (   R	   R   R  R   R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _set_default_irq_affinityO  s    		c         C   s-  t    } t j   } x | j   D] } y) | | d } t j d | | f  Wn t k
 rg q" n X|  j | | |  } t |  t |  k r q" n  |  j	 | | t
  r" | | j | <q" q" W|  j j d  } |  j j |  } |  j | | |  } |  j |  | | _ |  j j |  j |  d  S(   NR   s   Read affinity of IRQ '%s': '%s's   /proc/irq/default_smp_affinity(   R   Rt   t
   interruptsR}   RR   R   R   R   R   R  RK   R   R   t	   read_fileR   R  R   RO   R5   (   R	   R   t   irq_originalR   R    R   R   t   prev_affinity_hex(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _set_all_irq_affinityZ  s(    			c         C   s   |  j  j |  j d   } | d  k r( d  Sx0 | j j   D] \ } } |  j | | t  q8 W| j } |  j	 |  |  j  j
 |  j  d  S(   N(   RO   R,   R5   R   R   R   R  R"   R   R  RU   (   R	   R  R    R   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _restore_all_irq_affinityr  s    	c         C   s_   t  |  j t  |   } | r> t j t j | | f  n t j t j | | | f  | S(   N(   R   t   issubsetRR   RS   R$   t   STR_VERIFY_PROFILE_VALUE_OKR   t   STR_VERIFY_PROFILE_VALUE_FAIL(   R	   t   irq_descriptiont   correct_affinityt   current_affinityR   (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _verify_irq_affinity|  s    c         C   s   t  j   } t } x| | j   D]n } yQ | | d } t j d | | f  d | } |  j | | |  su t } n  Wq t k
 r q q Xq W|  j	 j
 d  } |  j	 j |  } |  j d | |  s t } n  | S(   NR   s#   Read SMP affinity of IRQ '%s': '%s's   SMP affinity of IRQ %ss   /proc/irq/default_smp_affinitys   default IRQ SMP affinity(   Rt   R  R"   R}   RR   R   R  RK   R   R   R  R   (   R	   R  R   R   R    R  R  t   current_affinity_hex(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _verify_all_irq_affinity  s,    	
					Rl   R   i
   c   
      C   s   d  } | d  k	 r t |  j j |   } t |  j  } | j |  r[ t | |  } q d j g  |  j D] } t |  ^ qk  }	 t	 j
 d | |	 f  n  | s | r | d  k r d  S| r |  j |  S| r |  j |  |  j |  n
 |  j   d  S(   Nt   ,sJ   Invalid isolated_cores specified, '%s' does not match available cores '%s'(   R   R   R   t   cpulist_unpackR2   R  R   R   R   RR   R   R  R  R  R  (
   R	   R   R   R   R   R   t   isolatedt   presentt   xt   str_cpus(    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   _isolated_cores  s"    +	(4   R   R   t   __doc__R   t
   SCHED_FIFOt   SCHED_BATCHt   SCHED_RRt   SCHED_OTHERt
   SCHED_IDLER   R   Rj   Rk   t   classmethodRp   Ry   R   R   R   Rw   R   R   R   R   RK   R   R   R   R   R   R   RT   R   R   R   R   t   command_customR.   R/   R   R   R   R  R  R  R  R  R  R  R  R  R&  (    (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyR   1   s\   



		(			
						
									*														
		(   R   R    t
   decoratorst
   tuned.logst   tunedR   t
   subprocessRZ   R0   R   t   tuned.constsR$   Rt   R   t   tuned.utils.commandsR   R   t   logsR,   RR   t   objectR   R   t   PluginR   (    (    (    sB   /usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.pyt   <module>   s    

