netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] net: ipv4: Use macro DIV_ROUND_UP.
       [not found] <cover.1490813977.git.rvarsha016@gmail.com>
@ 2017-03-29 19:15 ` Varsha Rao
  2017-03-29 19:16 ` [PATCH 2/2] net: ipv4: Use BIT macro Varsha Rao
  1 sibling, 0 replies; 3+ messages in thread
From: Varsha Rao @ 2017-03-29 19:15 UTC (permalink / raw)
  To: netdev; +Cc: outreachy-kernel

The macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /(d)).
It simplifies the divisor calculations. This was done using the following
coccinelle script:

@@
expression e1;
expression e2;
@@
(
- ((e1) + e2 - 1) / (e2)
+ DIV_ROUND_UP(e1,e2)
|
- ((e1) + (e2 - 1)) / (e2)
+ DIV_ROUND_UP(e1,e2)
)

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
---
 net/ipv4/tcp_bbr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c
index b89bce4..4da4bc1 100644
--- a/net/ipv4/tcp_bbr.c
+++ b/net/ipv4/tcp_bbr.c
@@ -314,7 +314,7 @@ static u32 bbr_target_cwnd(struct sock *sk, u32 bw, int gain)
 	w = (u64)bw * bbr->min_rtt_us;
 
 	/* Apply a gain to the given value, then remove the BW_SCALE shift. */
-	cwnd = (((w * gain) >> BBR_SCALE) + BW_UNIT - 1) / BW_UNIT;
+	cwnd = DIV_ROUND_UP((w * gain) >> BBR_SCALE, BW_UNIT);
 
 	/* Allow enough full-sized skbs in flight to utilize end systems. */
 	cwnd += 3 * bbr->tso_segs_goal;
-- 
2.9.3

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

* [PATCH 2/2] net: ipv4: Use BIT macro.
       [not found] <cover.1490813977.git.rvarsha016@gmail.com>
  2017-03-29 19:15 ` [PATCH 1/2] net: ipv4: Use macro DIV_ROUND_UP Varsha Rao
@ 2017-03-29 19:16 ` Varsha Rao
  2017-03-29 20:16   ` Eric Dumazet
  1 sibling, 1 reply; 3+ messages in thread
From: Varsha Rao @ 2017-03-29 19:16 UTC (permalink / raw)
  To: David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy
  Cc: outreachy-kernel, netdev

Replace bitwise left shift by one operations with BIT() macro. This patch
fixes the checkpatch issue.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
---
 net/ipv4/tcp_bbr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c
index 4da4bc1..9f2c869 100644
--- a/net/ipv4/tcp_bbr.c
+++ b/net/ipv4/tcp_bbr.c
@@ -71,10 +71,10 @@
  * an issue. The upper bound isn't an issue with existing technologies.
  */
 #define BW_SCALE 24
-#define BW_UNIT (1 << BW_SCALE)
+#define BW_UNIT BIT(BW_SCALE)
 
 #define BBR_SCALE 8	/* scaling factor for fractions in BBR (e.g. gains) */
-#define BBR_UNIT (1 << BBR_SCALE)
+#define BBR_UNIT BIT(BBR_SCALE)
 
 /* BBR has the following modes for deciding how fast to send: */
 enum bbr_mode {
-- 
2.9.3

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

* Re: [PATCH 2/2] net: ipv4: Use BIT macro.
  2017-03-29 19:16 ` [PATCH 2/2] net: ipv4: Use BIT macro Varsha Rao
@ 2017-03-29 20:16   ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2017-03-29 20:16 UTC (permalink / raw)
  To: Varsha Rao
  Cc: David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy, outreachy-kernel, netdev

On Thu, 2017-03-30 at 00:46 +0530, Varsha Rao wrote:
> Replace bitwise left shift by one operations with BIT() macro. This patch
> fixes the checkpatch issue.
> 
> Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
> ---
>  net/ipv4/tcp_bbr.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c
> index 4da4bc1..9f2c869 100644
> --- a/net/ipv4/tcp_bbr.c
> +++ b/net/ipv4/tcp_bbr.c
> @@ -71,10 +71,10 @@
>   * an issue. The upper bound isn't an issue with existing technologies.
>   */
>  #define BW_SCALE 24
> -#define BW_UNIT (1 << BW_SCALE)
> +#define BW_UNIT BIT(BW_SCALE)
>  
>  #define BBR_SCALE 8	/* scaling factor for fractions in BBR (e.g. gains) */
> -#define BBR_UNIT (1 << BBR_SCALE)
> +#define BBR_UNIT BIT(BBR_SCALE)
>  
>  /* BBR has the following modes for deciding how fast to send: */
>  enum bbr_mode {

Well, no.  BIT() is using unsigned long.

#define BIT(nr)    (1UL << (nr))


This change might have unintended effects.

Maybe checkpatch should be fixed.

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

end of thread, other threads:[~2017-03-29 20:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1490813977.git.rvarsha016@gmail.com>
2017-03-29 19:15 ` [PATCH 1/2] net: ipv4: Use macro DIV_ROUND_UP Varsha Rao
2017-03-29 19:16 ` [PATCH 2/2] net: ipv4: Use BIT macro Varsha Rao
2017-03-29 20:16   ` Eric Dumazet

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