Commit 0914d2bb authored by Mao Wenan's avatar Mao Wenan Committed by David S. Miller

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.

This patch is to refactory code and make it more readable.
Signed-off-by: default avatarMao Wenan <maowenan@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9476654b
...@@ -520,7 +520,7 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, ...@@ -520,7 +520,7 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po,
int blk_size_in_bytes) int blk_size_in_bytes)
{ {
struct net_device *dev; struct net_device *dev;
unsigned int mbits = 0, msec = 0, div = 0, tmo = 0; unsigned int mbits, div;
struct ethtool_link_ksettings ecmd; struct ethtool_link_ksettings ecmd;
int err; int err;
...@@ -532,31 +532,25 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po, ...@@ -532,31 +532,25 @@ static int prb_calc_retire_blk_tmo(struct packet_sock *po,
} }
err = __ethtool_get_link_ksettings(dev, &ecmd); err = __ethtool_get_link_ksettings(dev, &ecmd);
rtnl_unlock(); rtnl_unlock();
if (!err) { 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
return DEFAULT_PRB_RETIRE_TOV; 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); mbits = (blk_size_in_bytes * 8) / (1024 * 1024);
if (div) if (div)
mbits /= div; mbits /= div;
tmo = mbits * msec;
if (div) if (div)
return tmo+1; return mbits + 1;
return tmo; return mbits;
} }
static void prb_init_ft_ops(struct tpacket_kbdq_core *p1, static void prb_init_ft_ops(struct tpacket_kbdq_core *p1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment