a ]ii@sxddlZddlmZddlTddlZddlmZddlm Z ddl Z ddl Z ddl Z ej ZdZGdd d ejZdS) N)hotplug)*)ethcard)commandsZpumbagsdcseZdZdZfddZfddZddZdd Zd d Zd d Z fddZ fddZ fddZ ddZ ddZddZddZddZfddZd d!Zfd"d#Zd$d%Zd&d'Zed(d)Zed*d+Zed,d-Zed.d/Zed0d1Zd2d3Zd4d5Zd6d7Zd8d9Z d:d;Z!dd?Z#ed@dAZ$e%dBdCdDdEdFZ&e'dBddHdIZ(e%dJdKdLZ)e'dJdMdNZ*gfdOdPZ+ddRdSZ,e%dTdCdDdUdVZ-dWdXZ.e'dTddYdZZ/e%d[dCdDd\d]Z0e'd[dd^d_Z1d`daZ2dbdcZ3dddeZ4dfdgZ5dhdiZ6djdkZ7dldmZ8ddndoZ9dpdqZ:e;drdCdDdsdtZe;d{dCdDd|d}Z?e;d~dCdDddZ@ZAS)NetTuningPluginaO Configures network driver, hardware and Netfilter settings. Dynamic change of the interface speed according to the interface utilization is also supported. The dynamic tuning is controlled by the [option]`dynamic` and the global [option]`dynamic_tuning` option in `tuned-main.conf`. `wake_on_lan`::: The [option]`wake_on_lan` option sets wake-on-lan to the specified value as when using the `ethtool` utility. + .Set Wake-on-LAN for device eth0 on MagicPacket(TM) ==== ---- [net] devices=eth0 wake_on_lan=g ---- ==== `coalesce`::: The [option]`coalesce` option allows changing coalescing settings for the specified network devices. The syntax is: + [subs="quotes"] ---- coalesce=__param1__ __value1__ __param2__ __value2__ ... __paramN__ __valueN__ ---- + Note that not all the coalescing parameters are supported by all network cards. For the list of coalescing parameters of your network device, use `ethtool -c device`. + .Setting coalescing parameters rx/tx-usecs for all network devices ==== ---- [net] coalesce=rx-usecs 3 tx-usecs 16 ---- ==== `features`::: The [option]`features` option allows changing the offload parameters and other features for the specified network devices. To query the features of your network device, use `ethtool -k device`. The syntax of the option is the same as the [option]`coalesce` option. + .Turn off TX checksumming, generic segmentation and receive offload ==== ---- [net] features=tx off gso off gro off ---- ==== `pause`::: The [option]`pause` option allows changing the pause parameters for the specified network devices. To query the pause parameters of your network device, use `ethtool -a device`. The syntax of the option is the same as the [option]`coalesce` option. + .Disable autonegotiation ==== ---- [net] pause=autoneg off ---- ==== `ring`::: The [option]`ring` option allows changing the rx/tx ring parameters for the specified network devices. To query the ring parameters of your network device, use `ethtool -g device`. The syntax of the option is the same as the [option]`coalesce` option. + .Change the number of ring entries for the Rx/Tx rings to 1024/512 respectively ===== ----- [net] ring=rx 1024 tx 512 ----- ===== `channels`::: The [option]`channels` option allows changing the numbers of channels for the specified network device. A channel is an IRQ and the set of queues that can trigger that IRQ. To query the channels parameters of your network device, use `ethtool -l device`. The syntax of the option is the same as the [option]`coalesce` option. + .Set the number of multi-purpose channels to 16 ===== ----- [net] channels=combined 16 ----- ===== + A network device either supports rx/tx or combined queue mode. The [option]`channels` option automatically adjusts the parameters based on the mode supported by the device as long as a valid configuration is requested. `nf_conntrack_hashsize`::: The [option]`nf_conntrack_hashsize` option sets the size of the hash table which stores lists of conntrack entries by writing to `/sys/module/nf_conntrack/parameters/hashsize`. + .Adjust the size of the conntrack hash table ==== ---- [net] nf_conntrack_hashsize=131072 ---- ==== `txqueuelen`::: The [option]`txqueuelen` option allows changing txqueuelen (the length of the transmit queue). It uses `ip` utility that is in package iproute recommended for TuneD, so the package needs to be installed for its correct functionality. To query the txqueuelen parameters of your network device use `ip link show` and the current value is shown after the qlen column. + .Adjust the length of the transmit queue ==== ---- [net] txqueuelen=5000 ---- ==== `mtu`::: The [option]`mtu` option allows changing MTU (Maximum Transmission Unit). It uses `ip` utility that is in package iproute recommended for TuneD, so the package needs to be installed for its correct functionality. To query the MTU parameters of your network device use `ip link show` and the current value is shown after the MTU column. + .Adjust the size of the MTU ==== ---- [net] mtu=9000 ---- ==== csdtt|j|i|d|_d|_t|_i|_d|_t d|_ t t jdrX|j|_n|j|_dS)Ng?Tz(?!.*/virtual/.*) properties)superr__init___load_smallest _level_stepsr_cmd_re_ip_link_show_use_iprecompilere_not_virtualhasattrpyudevZDevice_get_device_property_1_get_device_property_get_device_property_2)selfargskwargs __class__z7NetTuningPlugin._get_device_objects..r)rdevicesrr/r_get_device_objectssz#NetTuningPlugin._get_device_objectscCs|j|jSN)rmatchZ device_pathr)rrrr$sz$NetTuningPlugin._device_is_supportedcCs|j|d|jdSNr )r#Z subscribe_hardware_events_callbackr/rrr_hardware_events_initsz%NetTuningPlugin._hardware_events_initcCs|j|dSr4)r#Z unsubscriber/rrr_hardware_events_cleanupsz(NetTuningPlugin._hardware_events_cleanupcs ||rtt|||dSr4)r$r rr7)rZeventr*rrrr7s z)NetTuningPlugin._hardware_events_callbackcs,|jdur|j|tt|||dSr4) _load_monitorZ add_devicer r_added_device_apply_tuningrinstance device_namerrrr;s  z*NetTuningPlugin._added_device_apply_tuningcs,|jdur|j|tt|||dSr4)r:Z remove_devicer r_removed_device_unapply_tuningr<rrrr?s  z.NetTuningPlugin._removed_device_unapply_tuningcCs |j|Sr4)r get)r pyudev_devproprrrrsz&NetTuningPlugin._get_device_property_1cCs*z||}Wnty$d}Yn0|Sr4) __getitem__KeyError)rrArBprrrrs   z&NetTuningPlugin._get_device_property_2cCsp|jd|}|rl||d}|rlt|jD]:\}}|j|}|r0t d|||f||j |<qlq0dS)Nr IFINDEXz?Rename device, ifindex: '%s', original name '%s', new name '%s') r#r+rlistZ _instancesitems _ifmap_origr@r&r' _ifnamemap)rr>diZ instance_namer=Zdevice_name_oldrrr _move_devices   zNetTuningPlugin._move_devicecsfdd}|S)Ncsj|}|r|S|Sr4)rJr@)r*rKr=rr_get_curr_devices zBNetTuningPlugin._get_curr_device_wrapper.._get_curr_devicer)rr=rOrrNr_get_curr_device_wrappers z(NetTuningPlugin._get_curr_device_wrappercCs@d|_d|_d|_d|_i|_|||_||jd|_ dS)NTdynamic) Z_has_static_tuningr:_idle_statsrJrPrOZ _option_booloptionsZ_has_dynamic_tuningrr=rrr_instance_inits zNetTuningPlugin._instance_initcsVtt||i|_|j}|D]0}|jd|}|r ||d}|r ||j|<q dS)Nr rF)r rassign_free_devicesrIassigned_devicesr#r+r)rr=r2r*rKrLrrrrWs z#NetTuningPlugin.assign_free_devicescCs"|jdur|j|jd|_dSr4)r:_monitors_repositorydeleterUrrr_instance_cleanups z!NetTuningPlugin._instance_cleanupcs@tt||i|_i|_|jd|j|_|j |j dSr6) r r_instance_init_dynamicrRrSrYZcreaterXr:Z _set_dev_maprOrUrrrr\s z&NetTuningPlugin._instance_init_dynamiccCs|||dSr4)_instance_update_dynamicrr=r*rrr_instance_apply_dynamicsz'NetTuningPlugin._instance_apply_dynamiccCs<dd|j|D}|dur"dS||jvr8|||||||||||j|}|j|}|ddkr|d|jkr|d|jkrd|d<t d|t | d nF|ddkr|ddks|ddkrd|d<t d |t | t d ||d|dft d ||d|d|dfdS) NcSsg|] }t|qSrint)r-valuerrrr0r1z.levelrreadwriterz%s: setting 100Mbpsd%s: setting max speedz %s load: read %0.2f, write %0.2fz$%s idle: read %d, write %d, level %d)r:Zget_device_loadrS_init_stats_and_idle _update_stats _update_idlerRr r&inforZ set_speed set_max_speedr')rr=r*loadZstatsZidlerrrr]s&     ($ z(NetTuningPlugin._instance_update_dynamiccCs4ddddddddddddddddddddddddS)N)z adaptive-rxz adaptive-txz cqe-mode-rxzrx-usecsz rx-framesz rx-usecs-irqz rx-frames-irqztx-usecsz tx-framesz tx-usecs-irqz tx-frames-irqzstats-block-usecsz pkt-rate-lowz rx-usecs-lowz rx-frames-lowz tx-usecs-lowz tx-frames-lowz pkt-rate-highz rx-usecs-highzrx-frames-highz tx-usecs-highztx-frames-highzsample-intervalrclsrrr_get_config_options_coalesce6s0z,NetTuningPlugin._get_config_options_coalescecCs ddddS)N)autonegrxtxrrnrrr_get_config_options_pauseRsz)NetTuningPlugin._get_config_options_pausecCsdddddS)N)rrrx-minirx-jumborsrrnrrr_get_config_options_ringXs z(NetTuningPlugin._get_config_options_ringcCsdddddS)N)rrrsothercombinedrrnrrr_get_config_options_channels_s z,NetTuningPlugin._get_config_options_channelsc Csddddddddddd S)NT) rQ wake_on_lannf_conntrack_hashsizefeaturescoalescepauseringchannels txqueuelenmturrnrrr_get_config_optionsfsz#NetTuningPlugin._get_config_optionscCsL|t||}ddgd|dgd|j|<dddd|j|<dS)Nrr)newmax)rcrdre) _calc_speedrrOZ get_max_speedrSrR)rr=r*Z max_speedrrrrhusz$NetTuningPlugin._init_stats_and_idlecCs|j|d|j|d<}||j|d<ddt||D}||j|d<|j|d}ddt||D}||j|d<t|dt|d|j|d <t|d t|d |j|d <dS) NroldcSsg|]}|d|dqS)rrr)r-Znew_oldrrrr0r1z1NetTuningPlugin._update_stats..diffrcSsg|] }t|qSr)r)r-Zpairrrrr0r1rrdrre)rSzipfloat)rr=r*Znew_loadZold_loadrZ old_max_loadZmax_loadrrrrizs"zNetTuningPlugin._update_statscCsHdD]>}|j|||jkr4|j||d7<qd|j||<qdS)N)rdrerr)rSr rR)rr=r*Z operationrrrrjszNetTuningPlugin._update_idlecCsN||jvrJ|j|ddkrJd|j|d<td|t||dS)Nrcrrg)rRr&rkrrOrlr^rrr_instance_unapply_dynamicsz)NetTuningPlugin._instance_unapply_dynamiccCstd|dS)Ng333333#Ar`)rZspeedrrrrszNetTuningPlugin._calc_speedcCs|j|}ttdd|}t|}|ddkrPtd|t|fdS|dkr^t St t t |ddd|dddS)Nz (:\s*)|(\s+)|(\s*;\s*)|(\s*,\s*) rrzinvalid %s parameter: '%s'r) Z _variablesexpandr(rsubsplitlenr&errordictrGr)rrbcontextvlvrrr_parse_config_parameterss  z(NetTuningPlugin._parse_config_parameterscCs~|jddddddddd d d d d ddddddd|}dd|dD}t|dkrZdStdddd|ddDDS)Nz adaptive-rx:z adaptive-tx:z cqe-mode-rx:zrx-frames-low:zrx-frames-high:ztx-frames-low:ztx-frames-high:zlro:zrx:ztx:zsg:ztso:zufo:zgso:zgro:zrxvlan:ztxvlan:zntuple:zrxhash:)z Adaptive RX:z\s+TX:z CQE mode RX:z rx-frame-low:zrx-frame-high:z tx-frame-low:ztx-frame-high:zlarge-receive-offload:zrx-checksumming:ztx-checksumming:zscatter-gather:ztcp-segmentation-offload:zudp-fragmentation-offload:zgeneric-segmentation-offload:zgeneric-receive-offload:zrx-vlan-offload:ztx-vlan-offload:zntuple-filters:zreceive-hashing:cSs0g|](}tt|dkrtdt|s|qS)rz \[fixed\]$)rr(rsearchr-rrrrr0r1z. rcSsg|]}t|dkr|qSrr)r-urrrr0r1cSsg|]}tdt|qSz:\s*)rrr(rrrrr0r1r)rmultiple_re_replacerrr)rrbZvlrrr_parse_device_parameterss6 z(NetTuningPlugin._parse_device_parameterscCsdS)Nz,/sys/module/nf_conntrack/parameters/hashsizerr/rrr_nf_conntrack_hashsize_pathsz+NetTuningPlugin._nf_conntrack_hashsize_pathr{T)Z per_devicecCsd|dur dStddt|}tdtd|s@tddS|s`|jdd| |d|g|S) N0rKz^[z]+$zIncorrect 'wake_on_lan' value.ethtoolz-sZwol) rrr(r5 WOL_VALUESr&warningrexecuterO)rrbr*r=simremoverrr_set_wake_on_lans z NetTuningPlugin._set_wake_on_lanFc Cs\d}z@tdtd|jd||gdtj}|rB|d}WntyVYn0|S)Nz.*Wake-on:\s*([z]+).*rr) rr5rrrrOSgroupIOError)rr*r=ignore_missingrbmrrr_get_wake_on_lans z NetTuningPlugin._get_wake_on_lanr|cCsN|dur dSt|}|dkrF|sB|jj|||r:tjgndd|SdSdS)NrF)Zno_error)rarZ write_to_filererrnoENOENT)rrbr=rrZhashsizerrr_set_nf_conntrack_hashsizesz*NetTuningPlugin._set_nf_conntrack_hashsizecCs(|j|}t|dkr$t|SdS)Nr)rZ read_filerrra)rr=rbrrr_get_nf_conntrack_hashsizes z*NetTuningPlugin._get_nf_conntrack_hashsizecCsz|js dSddg|}|jj|tjgdd\}}}|tj krRtdd|_dS|rvtdtd||fdS|S) NiplinkT) no_errorsZ return_errz0ip command not found, ignoring for other devicesFzProblem calling ip commandz(rc: %s, msg: '%s')) rrrrrr&rrkr')rrrcouterr_msgrrr _call_ip_links    zNetTuningPlugin._call_ip_linkNcCsdg}|r||||S)NZshow)appendr)rr*rrrr _ip_link_shows zNetTuningPlugin._ip_link_showrcCs~|dur dSz t|Wn"ty:td|YdS0|sz|dd||d|g}|durztd||dS|S)Nz$txqueuelen value '%s' is not integerr"devrz%Cannot set txqueuelen for device '%s'ra ValueErrorr&rrrOrrbr*r=rrresrrr_set_txqueuelens  zNetTuningPlugin._set_txqueuelencCs(||jvrtd||j|<|j|S)z@ Return regex for int arg value from "ip link show" command z.*\s+%s\s+(\d+))rrr)rargrrr_get_re_ip_link_show-s z$NetTuningPlugin._get_re_ip_link_showcCsr|||}|dur4|s0td||dS|d|}|durh|sdtd||dS|dS)NzECannot get 'ip link show' result for txqueuelen value for device '%s'ZqlenzFCannot get txqueuelen value from 'ip link show' result for device '%s'rrrOr&rkrrrrr*r=rrrrrr_get_txqueuelen5szNetTuningPlugin._get_txqueuelenrcCs~|dur dSz t|Wn"ty:td|YdS0|sz|dd||d|g}|durztd||dS|S)Nzmtu value '%s' is not integerr"rrzCannot set mtu for device '%s'rrrrr_set_mtuFs  zNetTuningPlugin._set_mtucCsr|||}|dur4|s0td||dS|d|}|durh|sdtd||dS|dS)Nz>Cannot get 'ip link show' result for mtu value for device '%s'rz?Cannot get mtu value from 'ip link show' result for device '%s'rrrrrr_get_mtuVszNetTuningPlugin._get_mtucCsl|dkr dSt|}|j|j|j|jd}t||}||shtd|t ||fdSdS)Nr}T)r~rrrzunknown %s parameter(s): %sF) r"keysrprtrwrzissubsetr&rr()rrrKparamsZsupported_getterZ supportedrrr_check_parametershs  z!NetTuningPlugin._check_parameterscCsR|jdddd|}|ddd}dd|D}td dd d|DDS) Nrqrrrs)Z AutonegotiateRXTXrrcSs$g|]}|dkrtd|s|qS)z \[fixed\])rrr,rrrr0}r1z;NetTuningPlugin._parse_pause_parameters..cSsg|]}t|dkr|qSrrr,rrrr0~r1cSsg|]}td|qSrrrr,rrrr0~r1)rrrr)rslrrr_parse_pause_parameterswsz'NetTuningPlugin._parse_pause_parameterscCsjtjd|tjd}|d}|jddddd|}|d }d d |D}d d d d |DD}t|S)N^Current hardware settings:$flagsrrrrurvrs)rzRX MinizRX JumborrcSsg|]}|dkr|qSrrr,rrrr0r1z:NetTuningPlugin._parse_ring_parameters..cSsg|]}t|dkr|qSrrr,rrrr0r1cSsg|]}td|qSrrr,rrrr0r1rr MULTILINErrrrrarrrr_parse_ring_parameterss z&NetTuningPlugin._parse_ring_parameterscCsjtjd|tjd}|d}|jddddd|}|d }d d |D}d d d d |DD}t|S)Nrrrrrrsrxry)rrZOtherZCombinedrcSsg|]}|dkr|qSrrr,rrrr0r1z>NetTuningPlugin._parse_channels_parameters..cSsg|]}t|dkr|qSrrr,rrrr0r1cSsg|]}td|qSrrr,rrrr0r1rrrrr_parse_channels_parameterss z*NetTuningPlugin._parse_channels_parameterscCszg}d|vr(|d|dd|dgn,ttt|dt|d}|d|gttt|ddd|dddS)Nryrrrrsr)extendr(rrarrGr)rrZ params_list dev_paramsZmod_params_listZcntrrr_replace_channels_parameterss z,NetTuningPlugin._replace_channels_parametersc CsTt|}t|}||}|D]*} td|| ||f|| dq$dS)a:Filter unsupported parameters and log warnings about it Positional parameters: instance -- instance calling it context -- context of change parameters -- parameters to change device -- name of device on which should be parameters set dev_params -- dictionary of currently known parameters of device z-%s parameter %s is not supported by device %sN)r"rr&rrOpop) rr=r parametersr*rZsupported_parametersZparameters_to_changeZunsupported_parametersparamrrr_check_device_supports  z%NetTuningPlugin._check_device_supportc Csdddddd}||}|jd|||g\}}|dksHt|dkrLdS|j|j|j|j|jd}||} | |} |d kr||| sdS| S) Nz-cz-kz-az-gz-lr~r}rrrrrr~) rrrOrrrrrr) rr=rr* context2optoptretrbZcontext2parserparserrKrrr_get_device_parameterss$z&NetTuningPlugin._get_device_parametersc Cs|dust|dkrdS|||}|dus8|||srF)rcs g|]\}}|vr||fqSrr)r-rrbZ params_setrrr0s z6NetTuningPlugin._custom_parameters..)r*r)Z _storage_keyrrrrHrrrZ_log_verification_resultrOZ_storager"joinr@) rrstartrbr*verifyr=Z storage_keyZparams_currentZrelevant_params_currentroriginal_valuerrr_custom_parameterssD      z"NetTuningPlugin._custom_parametersr}cCs|d|||||S)Nr}rrrrbr*rrr=rrr _features szNetTuningPlugin._featuresr~cCs|d|||||S)Nr~rrrrr _coalesceszNetTuningPlugin._coalescercCs|d|||||S)Nrrrrrr_pauseszNetTuningPlugin._pausercCs|d|||||S)Nrrrrrr_ringszNetTuningPlugin._ringrcCs|d|||||S)Nrrrrrr _channelsszNetTuningPlugin._channels)F)N)F)F)N)B__name__ __module__ __qualname____doc__r r!r3r$r8r9r7r;r?rrrMrPrVrWr[r\r_r] classmethodrprtrwrzrrhrirjrrrrrZ command_setrZ command_getrrrrrrrrrrrrrrrrrrrZcommand_customrrrrr __classcell__rrrrrs              !                  %         r)rrrZ decoratorsZ tuned.logsZtunedZtuned.utils.nettoolrZtuned.utils.commandsrosrrZlogsr@r&rZPluginrrrrrs