net: ipv4: Use DIV_ROUND_UP macro.
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/2 net: ipv4: Use DIV_ROUND_UP macro.
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)
)
--- net/ipv4/tcp_bbr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_bbr.c +1 -1
@@ -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;
Signature · 1 line
2.9.3
PATCH 1/2 net: ipv4: Use macro DIV_ROUND_UP.
In reply to a message not in the archiveThe 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)
)
--- net/ipv4/tcp_bbr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp_bbr.c +1 -1
@@ -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;
Signature · 1 line
2.9.3
PATCH 2/2 net: ipv4: Use BIT macro.
In reply to a message not in the archiveReplace bitwise left shift by one operations with BIT() macro. This patch fixes the checkpatch issue.
--- net/ipv4/tcp_bbr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv4/tcp_bbr.c +2 -2
@@ -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 {
Signature · 1 line
2.9.3
Re: [PATCH 2/2] net: ipv4: Use BIT macro.
Quoted 15 lines · Varsha Rao
Replace bitwise left shift by one operations with
BIT()macro. This patch fixes the checkpatch issue.Signed-off-by Varsha Rao <[email protected]>--- net/ipv4/tcp_bbr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/ipv4/tcp_bbr.c +0
-0@@ -71,10 +71,10 @@* an issue. The upper bound isn't an issue with existing technologies. */
net/ipv4/tcp_bbr.c line 80
Quoted 10 lines
net/ipv4/tcp_bbr.c +2
-2#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.
Re: [PATCH 2/2] net: ipv4: Use BIT macro.
Quoted 27 lines · Eric Dumazet
Quoted 1 line · Varsha Rao
Replace bitwise left shift by one operations with
BIT()macro. Thispatch
Quoted 12 lines
fixes the checkpatch issue.
Signed-off-by Varsha Rao <[email protected] <javascript:>>---
net/ipv4/tcp_bbr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/ipv4/tcp_bbr.c +0
-0net/ipv4/tcp_bbr.c line 76
Quoted 7 lines
net/ipv4/tcp_bbr.c +1
-1@@ -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) */
Quoted 3 lines
net/ipv4/tcp_bbr.c +1
-1-#define BBR_UNIT (1 << BBR_SCALE) +#define BBR_UNIT BIT(BBR_SCALE)
Quoted 6 lines
net/ipv4/tcp_bbr.c line 80
Quoted 2 lines
net/ipv4/tcp_bbr.c +0
-0/* 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.
Quoted 3 lines
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