3 Z!d?d@Z"ed<dkdAdBZ#edCd+d,dDdEZ$edCdldFdGZ%dHdIZ&dJdKZ'dLdMZ(dNdOZ)dPdQZ*dRdSZ+dTdUZ,dmdVdWZ-dXdYZ.e/dZd+d,d[d\Z0e/d]d+d,d^d_Z1e/d`d+d,dadbZ2e/dcd+d,dddeZ3e/dfd+d,dgdhZ4Z5S)nNetTuningPlugina `net`:: 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`. + 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 ---- ==== + The [option]`coalesce` option allows changing coalescing settings for the specified network devices. The syntax is: + [subs="+quotes,+macros"] ---- 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 ---- ==== + 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 ---- ==== 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 ---- ==== + 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 ----- ===== + 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. + 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 ---- ==== + 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 ---- ==== + 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 ---- ==== cs6tt|j||d|_d|_t|_i|_d|_dS)Ng?T) superr__init___load_smallest _level_stepsr_cmd_re_ip_link_show_use_ip)selfargskwargs) __class__ /usr/lib/python3.6/plugin_net.pyr s zNetTuningPlugin.__init__cCshd|_t|_t|_tjd}x.|jjdD]}|j|j r.|jj |j q.Wt j dt|jdS)NTz(?!.*/virtual/.*)netz devices: %s)Z_devices_supportedsetZ _free_devicesZ_assigned_devicesrecompile_hardware_inventoryZ get_devicesmatchZ device_pathaddZsys_namelogdebugstr)rZre_not_virtualdevicerrr _init_devicess  zNetTuningPlugin._init_devicescsfdd|DS)Ncsg|]}jjd|qS)r)rZ get_device).0x)rrr sz7NetTuningPlugin._get_device_objects..r)rZdevicesr)rr_get_device_objectssz#NetTuningPlugin._get_device_objectscCsXd|_|j|jdr.levelrreadwriterz%s: setting 100Mbpsdz%s: setting max speedz %s load: read %0.2f, write %0.2fz$%s idle: read %d, write %d, level %d)r(Zget_device_loadr*_init_stats_and_idle _update_stats _update_idler)r rinforZ set_speed set_max_speedr)rr+r loadZstatsZidlerrrr/s&     ($ z(NetTuningPlugin._instance_update_dynamiccCs2dddddddddddddddddddddddS)N)z adaptive-rxz adaptive-txzrx-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-intervalr)clsrrr_get_config_options_coalesces,z,NetTuningPlugin._get_config_options_coalescecCs ddddS)N)autonegrxtxr)r=rrr_get_config_options_pausesz)NetTuningPlugin._get_config_options_pausecCsdddddS)N)r@zrx-minizrx-jumborAr)r=rrr_get_config_options_ringsz(NetTuningPlugin._get_config_options_ringcCsdddddS)N)r@rAothercombinedr)r=rrr_get_config_options_channelssz,NetTuningPlugin._get_config_options_channelsc Csddddddddddd S)NT) r& wake_on_lannf_conntrack_hashsizefeaturescoalescepauseringchannels txqueuelenmtur)r=rrr_get_config_optionssz#NetTuningPlugin._get_config_optionscCsF|jt|j}ddgd|dgd|j|<dddd|j|<dS)Nrr)newmax)r3r4r5) _calc_speedrZ get_max_speedr*r))rr+r Z max_speedrrrr7sz$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) NrSoldcSsg|]}|d|dqS)rrr)r"Znew_oldrrrr$(sz1NetTuningPlugin._update_stats..diffrTcSsg|] }t|qSr)rT)r"Zpairrrrr$-srr4rRr5)r*zipfloat)rr+r Znew_loadZold_loadrWZ old_max_loadZmax_loadrrrr8"s"zNetTuningPlugin._update_statscCsLxFdD]>}|j|||jkr6|j||d7<qd|j||<qWdS)Nr4r5rr)r4r5)r*r r))rr+r Z operationrrrr94s zNetTuningPlugin._update_idlecCsH||jkrD|j|ddkrDd|j|d<tjd|t|jdS)Nr3rz%s: setting max speed)r)rr:rr;)rr+r rrr_instance_unapply_dynamic<sz)NetTuningPlugin._instance_unapply_dynamiccCstd|dS)Ng333333?ig333333@g333333#A)r1)rZspeedrrrrUBszNetTuningPlugin._calc_speedcCs|jj|}ttjdd|j}t|}|ddkrPtjd|t|fdS|dkr^t St t t |ddd|dddS)Nz (:\s*)|(\s+)|(\s*;\s*)|(\s*,\s*) rRrzinvalid %s parameter: '%s'r) Z _variablesexpandrrsubsplitlenrerrordictlistrX)rr2contextvZlvrrr_parse_config_parametersKs  z(NetTuningPlugin._parse_config_parameterscCs||jjddddddddd d d d d dddddd|}dd|jdD}t|dkrXdStdddd|ddDDS)Nz adaptive-rx:z adaptive-tx: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 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:cSs2g|]*}tt|dkrtjdt| r|qS)rz \[fixed\]$)r`rrsearch)r"rerrrr$ssz. rRcSsg|]}t|dkr|qS)rR)r`)r"urrrr$xscSsg|]}tjdt|qS)z:\s*)rr_r)r"rerrrr$xsr)r multiple_re_replacer_r`rb)rr2Zvlrrr_parse_device_parametersZs0 z(NetTuningPlugin._parse_device_parameterscCsdS)Nz,/sys/module/nf_conntrack/parameters/hashsizer)rrrr_nf_conntrack_hashsize_pathzsz+NetTuningPlugin._nf_conntrack_hashsize_pathrGT)Z per_devicecCs^|dkr dStjddt|}tjdtd|s@tjddS|sZ|jjdd|d|g|S) N0dz^[z]+$zIncorrect 'wake_on_lan' value.ethtoolz-sZwol) rr^rr WOL_VALUESrwarnr execute)rr2r simremoverrr_set_wake_on_lan~s z NetTuningPlugin._set_wake_on_lanFc CsXd}y:tjdtd|jjd|gdtj}|r<|jd}Wntk rRYnX|S)Nz.*Wake-on:\s*([z]+).*ror)rrrpr rrSgroupIOError)rr ignore_missingr2mrrr_get_wake_on_lans(z NetTuningPlugin._get_wake_on_lanrHcCsN|dkr dSt|}|dkrF|sB|jj|j||r:tjgndd|SdSdS)NrF)Zno_error)r1r Z write_to_filerlerrnoENOENT)rr2rsrtZhashsizerrr_set_nf_conntrack_hashsizesz*NetTuningPlugin._set_nf_conntrack_hashsizecCs(|jj|j}t|dkr$t|SdS)Nr)r Z read_filerlr`r1)rr2rrr_get_nf_conntrack_hashsizes z*NetTuningPlugin._get_nf_conntrack_hashsizecCsz|js dSddg|}|jj|tjgdd\}}}|tj krRtjdd|_dS|rvtjdtjd||fdS|S) NZiplinkT) no_errorsZ return_errz0ip command not found, ignoring for other devicesFzProblem calling ip commandz(rc: %s, msg: '%s')) rr rrr|r}rrqr:r)rrZrcoutZerr_msgrrr _call_ip_links    zNetTuningPlugin._call_ip_linkNcCsdg}|r|j||j|S)NZshow)appendr)rr rrrr _ip_link_shows zNetTuningPlugin._ip_link_showrNcCsr|dkr dSy t|Wn"tk r:tjd|dSX|sn|jdd|d|g}|dkrntjd|dS|S)Nz$txqueuelen value '%s' is not integerrdevrNz%Cannot set txqueuelen for device '%s')r1 ValueErrorrrqr)rr2r rsrtresrrr_set_txqueuelens zNetTuningPlugin._set_txqueuelencCs(||jkrtjd||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_shows z$NetTuningPlugin._get_re_ip_link_showcCs`|j|}|dkr(|s$tjd|dS|jdj|}|dkrV|sRtjd|dS|jdS)NzECannot get 'ip link show' result for txqueuelen value for device '%s'ZqlenzFCannot get txqueuelen value from 'ip link show' result for device '%s'r)rrr:rrgrw)rr ryrrrrr_get_txqueuelens zNetTuningPlugin._get_txqueuelenrOcCsr|dkr dSy t|Wn"tk r:tjd|dSX|sn|jdd|d|g}|dkrntjd|dS|S)Nzmtu value '%s' is not integerrrrOzCannot set mtu for device '%s')r1rrrqr)rr2r rsrtrrrr_set_mtus zNetTuningPlugin._set_mtucCs`|j|}|dkr(|s$tjd|dS|jdj|}|dkrV|sRtjd|dS|jdS)Nz>Cannot get 'ip link show' result for mtu value for device '%s'rOz?Cannot get mtu value from 'ip link show' result for device '%s'r)rrr:rrgrw)rr ryrrrrr_get_mtus zNetTuningPlugin._get_mtucCsl|dkr dSt|j}|j|j|j|jd}t||j}|j|shtjd|t ||fdSdS)NrIT)rJrKrLrMzunknown %s parameter(s): %sF) rkeysr>rBrCrFissubsetrrar)rrdrnZparamsZsupported_getterZ supportedrrr_check_parameters s   z!NetTuningPlugin._check_parameterscCsR|jjdddd|}|jddd}dd|D}td dd d|DDS) Nr?r@rA)Z AutonegotiateRXTXrhrcSs&g|]}|dkrtjd| r|qS)z \[fixed\])rrg)r"r#rrrr$sz;NetTuningPlugin._parse_pause_parameters..cSsg|]}t|dkr|qS)rR)r`)r"r#rrrr$ scSsg|]}tjd|qS)z:\s*)rr_)r"r#rrrr$ s)r rjr_rb)rslrrr_parse_pause_parameterss z'NetTuningPlugin._parse_pause_parameterscCsjtjd|tjd}|d}|jjddddd|}|jd }d d |D}d d d d |DD}t|S)Nz^Current hardware settings:$)flagsrr@zrx-minizrx-jumborA)rzRX MinizRX JumborrhcSsg|]}|dkr|qS)rr)r"r#rrrr$,sz:NetTuningPlugin._parse_ring_parameters..cSsg|]}t|dkr|qS)rR)r`)r"r#rrrr$-scSsg|]}tjd|qS)z:\s*)rr_)r"r#rrrr$-s)rr_ MULTILINEr rjrb)rrarrrr_parse_ring_parameters#s  z&NetTuningPlugin._parse_ring_parameterscCsjtjd|tjd}|d}|jjddddd|}|jd }d d |D}d d d d |DD}t|S)Nz^Current hardware settings:$)rrr@rArDrE)rrZOtherZCombinedrhcSsg|]}|dkr|qS)rr)r"r#rrrr$:sz>NetTuningPlugin._parse_channels_parameters..cSsg|]}t|dkr|qS)rR)r`)r"r#rrrr$;scSsg|]}tjd|qS)z:\s*)rr_)r"r#rrrr$;s)rr_rr rjrb)rrrrrrr_parse_channels_parameters1s  z*NetTuningPlugin._parse_channels_parameterscCszg}d|kr(|jd|dd|dgn,ttt|dt|d}|jd|gttt|ddd|dddS)NrEr@rrArR)extendrrTr1rbrcrX)rrdZ params_list dev_paramsZmod_params_listZcntrrr_replace_channels_parameters>s z,NetTuningPlugin._replace_channels_parametersc CsRt|j}t|j}||}x,|D]$}tjd|||f|j|dq&WdS)aFilter unsupported parameters and log warnings about it Positional parameters: 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)rrrZwarningpop) rrdZ parametersr rZsupported_parametersZparameters_to_changeZunsupported_parametersparamrrr_check_device_supportGs    z%NetTuningPlugin._check_device_supportc Csdddddd}||}|jjd||g\}}|dksBt|dkrFdS|j|j|j|j|jd}||}||} |d kr|j||  rdS| S) Nz-cz-kz-az-gz-l)rJrIrKrLrMrorrJ)r rrr`rkrrrr) rrdr context2optoptretr2Zcontext2parserparserrnrrr_get_device_parameters^s  z&NetTuningPlugin._get_device_parametersc Cs|dkst|dkrdS|j||}|dks:|j|| r>iS|r|j|||||dkrt|tt|dkr|j||jj ||}| rt|dkrt j d|t|fdddd d d }||}|jj d ||g|jj |d gd|S)NrrMn/armzsetting %s: %sz-Cz-Kz-Az-Gz-L)rJrIrKrLrMroP)r)rrm) r`rfrrrnextiterrr dict2listrrrr) rrdr2r rsrrnrrrrr_set_device_parametersps   $z&NetTuningPlugin._set_device_parametersc s|j||d}|r|j||}|dks2t|dkr6dS|j|||||ddks^tdkrbdSfdd|jD}t|}|r|jj|jj|k} |j|| ||d| S|j j |dj |jj|n|j j |} |j|| |ddS) N)Z command_nameZ device_namerF)rcs g|]\}}|kr||fqSrr)r"rr2) params_setrrr$sz6NetTuningPlugin._custom_parameters..)r r\) Z _storage_keyrr`ritemsrbr rZ_log_verification_resultZ_storagerjoinget) rrdstartr2r verifyZ storage_keyZparams_currentZrelevant_params_currentroriginal_valuer)rr_custom_parameterss:     z"NetTuningPlugin._custom_parametersrIcCs|jd||||S)NrI)r)rrr2r rryrrr _featuresszNetTuningPlugin._featuresrJcCs|jd||||S)NrJ)r)rrr2r rryrrr _coalesceszNetTuningPlugin._coalescerKcCs|jd||||S)NrK)r)rrr2r rryrrr_pauseszNetTuningPlugin._pauserLcCs|jd||||S)NrL)r)rrr2r rryrrr_ringszNetTuningPlugin._ringrMcCs|jd||||S)NrM)r)rrr2r rryrrr _channelsszNetTuningPlugin._channels)F)N)F)F)N)6__name__ __module__ __qualname____doc__r r!r%r,r.r0r/ classmethodr>rBrCrFrPr7r8r9rZrUrfrkrlZ command_setruZ command_getr{r~rrrrrrrrrrrrrrrrrZcommand_customrrrrr __classcell__rr)rrrsd                    &r)r|rrZ decoratorsZ tuned.logsZtunedZtuned.utils.nettoolrZtuned.utils.commandsrosrZlogsrrrpZPluginrrrrrs