linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] af_packet: refactoring code for prb_calc_retire_blk_tmo
@ 2019-12-19  1:33 Mao Wenan
  2019-12-19 13:56 ` Willem de Bruijn
  0 siblings, 1 reply; 5+ messages in thread
From: Mao Wenan @ 2019-12-19  1:33 UTC (permalink / raw)
  To: davem, maowenan, edumazet, willemb, maximmi, pabeni, yuehaibing, nhorman
  Cc: netdev, linux-kernel, kernel-janitors

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.

Fixes: b43d1f9f7067 ("af_packet: set defaule value for tmo")
Signed-off-by: Mao Wenan <maowenan@huawei.com>
---
 net/packet/af_packet.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 118cd66..843ebf8 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -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;
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] af_packet: refactoring code for prb_calc_retire_blk_tmo
  2019-12-19  1:33 [PATCH net] af_packet: refactoring code for prb_calc_retire_blk_tmo Mao Wenan
@ 2019-12-19 13:56 ` Willem de Bruijn
  2019-12-20  2:19   ` maowenan
  2019-12-23 10:42   ` [PATCH net-next v2] " Mao Wenan
  0 siblings, 2 replies; 5+ messages in thread
From: Willem de Bruijn @ 2019-12-19 13:56 UTC (permalink / raw)
  To: Mao Wenan
  Cc: David Miller, Eric Dumazet, maximmi, Paolo Abeni, yuehaibing,
	Neil Horman, Network Development, linux-kernel, kernel-janitors

On Wed, Dec 18, 2019 at 8:37 PM Mao Wenan <maowenan@huawei.com> wrote:
>
> 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.
>
> 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.

> -       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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] af_packet: refactoring code for prb_calc_retire_blk_tmo
  2019-12-19 13:56 ` Willem de Bruijn
@ 2019-12-20  2:19   ` maowenan
  2019-12-23 10:42   ` [PATCH net-next v2] " Mao Wenan
  1 sibling, 0 replies; 5+ messages in thread
From: maowenan @ 2019-12-20  2:19 UTC (permalink / raw)
  To: Willem de Bruijn
  Cc: David Miller, Eric Dumazet, maximmi, Paolo Abeni, yuehaibing,
	Neil Horman, Network Development, linux-kernel, kernel-janitors



On 2019/12/19 21:56, Willem de Bruijn wrote:
> On Wed, Dec 18, 2019 at 8:37 PM Mao Wenan <maowenan@huawei.com> wrote:
>>
>> 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.
>>
>> Fixes: b43d1f9f7067 ("af_packet: set defaule value for tmo")
> 
> This is a pure refactor, not a fix.
yes , it is 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.
sorry, it would be net-next.
> 
>> -       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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net-next v2] af_packet: refactoring code for prb_calc_retire_blk_tmo
  2019-12-19 13:56 ` Willem de Bruijn
  2019-12-20  2:19   ` maowenan
@ 2019-12-23 10:42   ` Mao Wenan
  2019-12-26 23:20     ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Mao Wenan @ 2019-12-23 10:42 UTC (permalink / raw)
  To: davem, edumazet, willemb, maximmi, maowenan, pabeni, yuehaibing, nhorman
  Cc: netdev, linux-kernel, kernel-janitors, willemdebruijn.kernel

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: Mao Wenan <maowenan@huawei.com>
---
 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(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 118cd66b7516..3bec515ccde3 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -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,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2] af_packet: refactoring code for prb_calc_retire_blk_tmo
  2019-12-23 10:42   ` [PATCH net-next v2] " Mao Wenan
@ 2019-12-26 23:20     ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-12-26 23:20 UTC (permalink / raw)
  To: maowenan
  Cc: edumazet, willemb, maximmi, pabeni, yuehaibing, nhorman, netdev,
	linux-kernel, kernel-janitors, willemdebruijn.kernel

From: Mao Wenan <maowenan@huawei.com>
Date: Mon, 23 Dec 2019 18:42:57 +0800

> 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: Mao Wenan <maowenan@huawei.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-12-26 23:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19  1:33 [PATCH net] af_packet: refactoring code for prb_calc_retire_blk_tmo Mao Wenan
2019-12-19 13:56 ` Willem de Bruijn
2019-12-20  2:19   ` maowenan
2019-12-23 10:42   ` [PATCH net-next v2] " Mao Wenan
2019-12-26 23:20     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).