ó æ ”\c@s­ddlmZddlTddlZddlmZddljZddl Z ddl Z ddl Z ddl Z ddl Z ejjƒZdejfd„ƒYZdS(i(tbase(t*iÿÿÿÿN(tcommandstCPULatencyPlugincBs¬eZdZd„Zd„Zd„Zed„ƒZd„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„Zd„Zd„Zed„Zd„Zd„Zd„Zd„Zd„Zeddeƒd„ƒZedƒed„ƒZdd„Z eddeddƒd „ƒZ!edƒed!„ƒZ"d"„Z#ed#deƒd$„ƒZ$d%„Z%d&„Z&d'„Z'ed#ƒed(„ƒZ(RS()sP Plugin for tuning CPU options. Powersaving, governor, required latency, etc. cOsŒtt|ƒj||Žt|_d|_t|_t|_t|_ t|_ t|_ d|_ d|_d|_i|_tƒ|_dS(Ntx86_64(tsuperRt__init__tTruet _has_pm_qost_archtFalset_is_x86t _is_intelt_is_amdt_has_energy_perf_biast_has_intel_pstatetNonet_min_perf_pct_savet_max_perf_pct_savet_no_turbo_savet_governors_mapRt_cmd(tselftargstkwargs((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyRs           cCsUt|_tƒ|_x-|jjdƒD]}|jj|jƒq(Wtƒ|_dS(Ntcpu( Rt_devices_supportedtsett _free_devicest_hardware_inventoryt get_devicestaddtsys_namet_assigned_devices(Rtdevice((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt _init_devices(s   cCs&g|D]}|jjd|ƒ^qS(NR(Rt get_device(Rtdevicestx((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_get_device_objects1scCsJi dd6dd6dd6dd6dd6dd 6dd 6dd 6dd 6dd 6S(Ngš™™™™™É?tload_thresholdidt latency_lowièt latency_hight force_latencytgovernortsampling_down_factortenergy_perf_biast min_perf_pctt max_perf_pcttno_turbo(R(R((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_get_config_options4scCsèdddddg}tjƒ|_|j|krªtjƒ}|jjdƒ}|dkrit|_n-|dks|d krt|_ n t|_t j d |ƒnt j d |jƒ|jtkrä|j ƒ|j ƒndS( NRti686ti585ti486ti386t vendor_idt GenuineIntelt AuthenticAMDt HygonGenuines$We are running on an x86 %s platformsWe are running on %s (non x86)(tplatformtmachineR tprocfstcpuinfottagstgetRR R tlogtinfot_check_energy_perf_biast_check_intel_pstate(Rt intel_archsRtvendor((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt _check_archCs      cCst|_d}|jjddgdtj|gƒd}|dkrRt|_n)|dkrntjdƒn tjdƒdS(Nitx86_energy_perf_policys-rt no_errorsisgunable to run x86_energy_perf_policy tool, ignoring CPU energy performance bias, is the tool installed?sXyour CPU doesn't support MSR_IA32_ENERGY_PERF_BIAS, ignoring CPU energy performance bias( R RRtexecuteterrnotENOENTRRAtwarning(Rtretcode_unsupportedtretcode((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyRC^s +   cCs2tjjdƒ|_|jr.tjdƒndS(Ns$/sys/devices/system/cpu/intel_pstatesintel_pstate detected(tostpathtexistsRRARB(R((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyRDis cCs.t|ƒ}|jjt|ƒjddƒƒS(NRt(tstrRt is_cpu_onlinetreplace(RR"tsd((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_is_cpu_onlinens cCstjjd|ƒS(Ns3/sys/devices/system/cpu/%s/cpufreq/scaling_governor(RPRQRR(RR"((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_cpu_has_scaling_governorrscCsL|j|ƒs$tjd|ƒtS|j|ƒsHtjd|ƒtStS(Ns'%s' is not online, skippings.there is no scaling governor fo '%s', skipping(RXRAtdebugR RYR(RR"((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_check_cpu_can_change_governoruscCst|_t|_t|jjƒƒd|kràt|_ytj t j tj ƒ|_ Wn.tk r‰tjdt j ƒt|_nXd|_|jddkrÊ|jjddƒ|_t|_n d|_|jƒnt|_tjd|jƒt|jƒd|_dS(Nis-Unable to open '%s', disabling PM_QoS controlR+tloadsILatency settings from non-first CPU plugin instance '%s' will be ignored.(Rt_has_static_tuningR t_has_dynamic_tuningtlistt _instancestvaluest_first_instanceRPtopentconststPATH_CPU_DMA_LATENCYtO_WRONLYt_cpu_latency_fdtOSErrorRAterrorRRt_latencytoptionst_monitors_repositorytcreatet _load_monitorRGRBtnametassigned_devicest _first_device(Rtinstance((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_instance_init~s$          cCsQ|jrM|jr%tj|jƒn|jdk rM|jj|jƒqMndS(N( RbRRPtcloseRgRnRRltdelete(RRr((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_instance_cleanup™s   cCs|jjd|dƒjƒS(Ns'/sys/devices/system/cpu/intel_pstate/%s(Rt read_fileRtstrip(Rtattr((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_get_intel_pstate_attr scCs*|dk r&|jjd||ƒndS(Ns'/sys/devices/system/cpu/intel_pstate/%s(RRt write_to_file(RRytval((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_set_intel_pstate_attr£s cCs3|dkrdS|j|ƒ}|j||ƒ|S(N(RRzR}(RRytvaluetv((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_getset_intel_pstate_attr§s  cCs°tt|ƒj|ƒ|js#dS|jd}|dk rL|j|ƒn|jr¬|jd|jdƒ|_ |jd|jdƒ|_ |jd|jdƒ|_ ndS(NR+R/R0R1( RRt_instance_apply_staticRbRkRt _set_latencyRR€RRR(RRrtforce_latency_value((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyR®s    cCsktt|ƒj||ƒ|jrg|jrg|jd|jƒ|jd|jƒ|jd|jƒndS(NR/R0R1( RRt_instance_unapply_staticRbRR}RRR(RRrt full_rollback((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyR„¼s cCs|j||ƒdS(N(t_instance_update_dynamic(RRrR"((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_instance_apply_dynamicÄscCsw|jst‚||jkr"dS|jjƒd}||jdkr_|j|jdƒn|j|jdƒdS(NtsystemR(R*R)(RbtAssertionErrorRqRntget_loadRkR‚(RRrR"R\((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyR†ÇscCsdS(N((RRrR"((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_instance_unapply_dynamicÒscCsjt|ƒ}|jrf|j|krftjd|ƒtjd|ƒ}tj|j |ƒ||_ndS(Nssetting new cpu latency %dti( tintRRjRARBtstructtpackRPtwriteRg(Rtlatencyt latency_bin((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyR‚Õs  cCs |jjd|ƒjƒjƒS(Ns>/sys/devices/system/cpu/%s/cpufreq/scaling_available_governors(RRwRxtsplit(RR"((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_get_available_governorsÝsR,t per_devicecCs,|j|ƒsdSt|ƒ}|jdƒ}g|D]}|jƒ^q5}x1|D])}t|ƒdkrTtjdƒdSqTW|j|ƒ}x•|D]m}||krä|sàtj d||fƒ|j j d||ƒnPq—|s—tj d||fƒq—q—Wtj ddj|ƒƒd}|S( Nt|is.The 'governor' option contains an empty value.s!setting governor '%s' on cpu '%s's3/sys/devices/system/cpu/%s/cpufreq/scaling_governors7Ignoring governor '%s' on cpu '%s', it is not supporteds.None of the scaling governors is supported: %ss, (R[RRTR“RxtlenRARiR”RBRR{RZtwarntjoin(Rt governorsR"tsimR,tavailable_governors((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt _set_governoràs2         cCszd}|j|ƒsdS|jjd|d|ƒjƒ}t|ƒdkrV|}n|dkrvtjd|ƒn|S(Ns3/sys/devices/system/cpu/%s/cpufreq/scaling_governortno_erroris*could not get current governor on cpu '%s'(RR[RRwRxR—RARi(RR"tignore_missingR,tdata((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt _get_governorýs"  tondemandcCsd|S(Ns7/sys/devices/system/cpu/cpufreq/%s/sampling_down_factor((RR,((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_sampling_down_factor_path sR-tpriorityi cCs d}||jkr%|jjƒnd|j|<|j|ƒ}|dkrbtjd|ƒdS|t|jjƒƒkr||j|<|j|ƒ}t j j |ƒsÆtjd||fƒdSt |ƒ}|stj d||fƒ|jj||ƒqn|S(NsIignoring sampling_down_factor setting for CPU '%s', cannot match governorsTignoring sampling_down_factor setting for CPU '%s', governor '%s' doesn't support its6setting sampling_down_factor to '%s' for governor '%s'(RRtclearR¡RARZR_RaR£RPRQRRRTRBRR{(RR-R"R›R|R,RQ((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_set_sampling_down_factors&    cCs`|j|d|ƒ}|dkr%dS|j|ƒ}tjj|ƒsJdS|jj|ƒjƒS(NRŸ( R¡RR£RPRQRRRRwRx(RR"RŸR,RQ((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_get_sampling_down_factor)s cCs=|jjdd|t|ƒgdtƒ\}}}||fS(NRHs-ct return_err(RRJRTR(Rtcpu_idR~ROtoutterr_msg((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_try_set_energy_perf_bias3s  R.c Cs"|j|ƒs$tjd|ƒdS|jr|s|jdƒ}|jdƒ}x¼|D] }|jƒ}tjd||fƒ|j||ƒ\}}|dkrÀtj d||fƒPqX|dkrátj d|ƒPqXtjd||fƒqXWtj d |ƒnt |ƒSdSdS( Ns%s is not online, skippingRR–s2Trying to set energy_perf_bias to '%s' on cpu '%s'is5energy_perf_bias successfully set to '%s' on cpu '%s's"Failed to set energy_perf_bias: %ssHCould not set energy_perf_bias to '%s' on cpu '%s', trying another valuesPFailed to set energy_perf_bias on cpu '%s'. Is the value in the profile correct?( RXRARZRRtlstripR“RxR¬RBRiRT( RR.R"R›R©tvalsR|ROR«((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_set_energy_perf_bias<s6            cCsYyt|ƒ}WnBtk rT}yt|dƒ}WqUtk rP}|}qUXnX|S(Ni(Rt ValueError(RtsRte((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_try_parse_num]scCs.idd6dd6dd6j|j|ƒ|ƒS(Nt performanceitnormalit powersavei(R@R³(RR±((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_energy_perf_policy_to_humanhscCs<idd6dd6dd6dd6d d 6j|j|ƒ|ƒS( NR´isbalance-performanceiRµis balance-poweritpoweri(R@R³(RR±((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_energy_perf_policy_to_human_v2ls   c Csñd}|j|ƒs*tjd|ƒdS|jrí|jdƒ}|jjdd|dgƒ\}}|dkríxu|jƒD]d}|j ƒ}t |ƒdkrº|j |dƒ}Pqt |ƒd kr|j |dƒ}PqqWqín|S( Ns%s is not online, skippingRRHs-cs-riiii( RRXRARZRR­RRJt splitlinesR“R—R·R¹( RR"RŸR.R©ROtlinestlinetl((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyt_get_energy_perf_biasts" $  ()t__name__t __module__t__doc__RR#R't classmethodR2RGRCRDRXRYR[RsRvRzR}R€RR R„R‡R†R‹R‚R”t command_setRRt command_getR¡R£R¦R§R¬R¯R³R·R¹R¾(((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyRsJ                   !  !   (RSRt decoratorst tuned.logsttunedttuned.utils.commandsRt tuned.constsRdRPRŽRKR;R=tlogsR@RAtPluginR(((s</usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.pyts