af_packet: refactoring code for prb_calc_retire_blk_tmo
Subsystems (4)
PATCH 1/1 af_packet: refactoring code for prb_calc_retire_blk_tmo
If __ethtool_get_link_ksettings() is failed and with non-zero value, prb_calc_retire_blk_tmo() should return DEFAULT_PRB_RETIRE_TOV firstly. Refactoring code and make it more readable.
--- net/packet/af_packet.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
net/packet/af_packet.c +11 -15
@@ -520,7 +520,7 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, int blk_size_in_bytes) {struct net_device *dev; -unsigned int mbits =0 , msec =0 , div =0 , tmo =0 ; +unsigned int mbits =0 , msec =1 , div =0 , tmo =0 ;struct ethtool_link_ksettings ecmd;int err;
@@ -532,21 +532,17 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, } err =__ethtool_get_link_ksettings (dev, &ecmd);rtnl_unlock (); -if (!err) { -/* -* If the link speed is so slow you don't really -* need to worry about perf anyways -*/ -if (ecmd.base.speed <SPEED_1000 || - ecmd.base.speed =SPEED_UNKNOWN ) { -return DEFAULT_PRB_RETIRE_TOV ; - }else { - msec =1 ; - div = ecmd.base.speed /1000 ; - } - }else +if (err) +return DEFAULT_PRB_RETIRE_TOV ; + +/* If the link speed is so slow you don't really +* need to worry about perf anyways +*/ +if (ecmd.base.speed <SPEED_1000 || + ecmd.base.speed =SPEED_UNKNOWN )return DEFAULT_PRB_RETIRE_TOV ; + div = ecmd.base.speed /1000 ; mbits = (blk_size_in_bytes *8 ) / (1024 *1024 );if (div)
@@ -555,7 +551,7 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, tmo = mbits * msec;if (div) -return tmo+1 ; +return tmo +1 ;return tmo; }
Signature · 1 line
2.7.4
Willem de Bruijn
maintainerQuoted 7 lines · Mao Wenan
If
__ethtool_get_link_ksettings()is failed and with non-zero value,prb_calc_retire_blk_tmo()should returnDEFAULT_PRB_RETIRE_TOVfirstly. Refactoring code and make it more readable.Fixes b43d1f9f7067 ("af_packet: set defaule value for tmo")
This is a pure refactor, not a fix.
Code refactors make backporting fixes across releases harder, among other things. I think this code is better left as is. Either way, it would be a candidate for net-next, not net.
net/packet/af_packet.c static int prb_calc_retire_blk_tmo(struct packet_sock *po, · line 523
Quoted 2 lines
net/packet/af_packet.c +1
-1-unsigned int mbits =0 , msec =0 , div =0 , tmo =0 ; +unsigned int mbits =0 , msec =1 , div =0 , tmo =0 ;
Most of these do not need to be initialized here at all, really.
Quoted 10 lines · Willem de Bruijn
Quoted 7 lines · Mao Wenan
If
__ethtool_get_link_ksettings()is failed and with non-zero value,prb_calc_retire_blk_tmo()should returnDEFAULT_PRB_RETIRE_TOVfirstly. Refactoring code and make it more readable.Fixes b43d1f9f7067 ("af_packet: set defaule value for tmo")This is a pure refactor, not a fix.
yes , it is not a fix.
Quoted 4 lines
Code refactors make backporting fixes across releases harder, among other things. I think this code is better left as is. Either way, it would be a candidate for net-next, not net.
sorry, it would be net-next.
Quoted 6 lines
net/packet/af_packet.c static int prb_calc_retire_blk_tmo(struct packet_sock *po, · line 523
Quoted 3 lines
net/packet/af_packet.c +1
-1-unsigned int mbits =0 , msec =0 , div =0 , tmo =0 ; +unsigned int mbits =0 , msec =1 , div =0 , tmo =0 ;Most of these do not need to be initialized here at all, really.
some of them do not need to be initialized,
msec=1 can be reserved because it can indicate tmo is for millisecond and msec initialized value is 1ms.
PATCH v2 1/1 af_packet: refactoring code for prb_calc_retire_blk_tmo
In reply to Willem de BruijnIf __ethtool_get_link_ksettings() is failed and with non-zero value, prb_calc_retire_blk_tmo() should return DEFAULT_PRB_RETIRE_TOV firstly.
This patch is to refactory code and make it more readable.
---
v2: delete 'Fixes' tag, do not initialize some variable, and delete two variable as Willem de Bruijn proposal.
net/packet/af_packet.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-)
net/packet/af_packet.c +12 -18
@@ -520,7 +520,7 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, int blk_size_in_bytes) {struct net_device *dev; -unsigned int mbits =0 , msec =0 , div =0 , tmo =0 ; +unsigned int mbits, div;struct ethtool_link_ksettings ecmd;int err;
@@ -532,31 +532,25 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, } err =__ethtool_get_link_ksettings (dev, &ecmd);rtnl_unlock (); -if (!err) { -/* -* If the link speed is so slow you don't really -* need to worry about perf anyways -*/ -if (ecmd.base.speed <SPEED_1000 || - ecmd.base.speed =SPEED_UNKNOWN ) { -return DEFAULT_PRB_RETIRE_TOV ; - }else { - msec =1 ; - div = ecmd.base.speed /1000 ; - } - }else +if (err)return DEFAULT_PRB_RETIRE_TOV ; +/* If the link speed is so slow you don't really +* need to worry about perf anyways +*/ +if (ecmd.base.speed <SPEED_1000 || + ecmd.base.speed =SPEED_UNKNOWN ) +return DEFAULT_PRB_RETIRE_TOV ; + + div = ecmd.base.speed /1000 ; mbits = (blk_size_in_bytes *8 ) / (1024 *1024 );if (div) mbits /= div; - tmo = mbits * msec; -if (div) -return tmo+1 ; -return tmo; +return mbits +1 ; +return mbits; } static void prb_init_ft_ops(struct tpacket_kbdq_core *p1,
Signature · 1 line
2.20.1
From: Mao Wenan <[email protected]>
Date: Mon, 23 Dec 2019 18:42:57 +0800
Quoted 7 lines
If
__ethtool_get_link_ksettings()is failed and with non-zero value,prb_calc_retire_blk_tmo()should returnDEFAULT_PRB_RETIRE_TOVfirstly.This patch is to refactory code and make it more readable.
Signed-off-by Mao Wenan <[email protected]>
Applied, thanks.