All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] net: ipv4: Use DIV_ROUND_UP macro.
       [not found] <cover.1490813977.git.rvarsha016@gmail.com>
@ 2017-03-29 19:14 ` Varsha Rao
  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
  2 siblings, 0 replies; 5+ messages in thread
From: Varsha Rao @ 2017-03-29 19:14 UTC (permalink / raw)
  To: David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy
  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] 5+ messages in thread

* [PATCH 1/2] net: ipv4: Use macro DIV_ROUND_UP.
       [not found] <cover.1490813977.git.rvarsha016@gmail.com>
  2017-03-29 19:14 ` [PATCH 1/2] net: ipv4: Use DIV_ROUND_UP macro Varsha Rao
@ 2017-03-29 19:15 ` Varsha Rao
  2017-03-29 19:16 ` [PATCH 2/2] net: ipv4: Use BIT macro Varsha Rao
  2 siblings, 0 replies; 5+ 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] 5+ messages in thread

* [PATCH 2/2] net: ipv4: Use BIT macro.
       [not found] <cover.1490813977.git.rvarsha016@gmail.com>
  2017-03-29 19:14 ` [PATCH 1/2] net: ipv4: Use DIV_ROUND_UP macro Varsha Rao
  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
  2 siblings, 1 reply; 5+ 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] 5+ 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
  2017-03-31  1:43     ` Varsha Rao
  0 siblings, 1 reply; 5+ 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] 5+ messages in thread

* Re: [PATCH 2/2] net: ipv4: Use BIT macro.
  2017-03-29 20:16   ` Eric Dumazet
@ 2017-03-31  1:43     ` Varsha Rao
  0 siblings, 0 replies; 5+ messages in thread
From: Varsha Rao @ 2017-03-31  1:43 UTC (permalink / raw)
  To: outreachy-kernel
  Cc: rvarsha016, davem, kuznet, jmorris, yoshfuji, kaber, netdev


[-- Attachment #1.1: Type: text/plain, Size: 1791 bytes --]



On Thursday, March 30, 2017 at 2:20:27 AM UTC+5:30, Eric Dumazet wrote:
>
> 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 <rvars...@gmail.com <javascript:>> 
> > --- 
> >  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. 
>


Okay, I will revert these changes. When I grep fot definition, I get the 
following.   

arch/arm/mach-davinci/sleep.S:#define BIT(nr)                   (1 << (nr))
include/linux/bitops.h:#define BIT(nr)                  (1UL << (nr))
tools/perf/bench/numa.c:#define BIT(x) (1ul << x)
tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c:#define 
BIT(n)          (1 << (n))
tools/vm/page-types.c:#define BIT(name)         (1ULL << KPF_##name)
 
But why is the definition not uniform if it causes problem in some files on 
usage?

Thanks,
Varsha Rao     

[-- Attachment #1.2: Type: text/html, Size: 2602 bytes --]

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

end of thread, other threads:[~2017-03-31  1:43 UTC | newest]

Thread overview: 5+ 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:14 ` [PATCH 1/2] net: ipv4: Use DIV_ROUND_UP macro Varsha Rao
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
2017-03-31  1:43     ` Varsha Rao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.