Skip to contentSkip to conversation

ocfs2/dlm: Move BITS_TO_BYTES() to bitops.h for wider use

PATCH Superseded Andy Shevchenko 3 participants 4 messages Aug 27, 2019 – Dec 11, 2019

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ocfs2/dlm: Move BITS_TO_BYTES() to bitops.h for wider use

There are users already and will be more of BITS_TO_BYTES() macro. Move it to bitops.h for wider use.

In the case of ocfs2 the replacement is identical.

As for bnx2x, there are two places where floor version is used.
In the first case to calculate the amount of structures that can fit one memory page. In this case obviously the ceiling variant is correct and original code might have a potential bug, if amount of bits % 8 is not 0. In the second case the macro is used to calculate bytes transmitted in one microsecond. This will work for all speeds which is multiply of 1Gbps without any change, for the rest new code will give ceiling value, for instance 100Mbps will give 13 bytes, while old code gives 12 bytes and the arithmetically correct one is 12.5 bytes. Further the value is used to setup timer threshold which in any case has its own margins due to certain resolution. I don't see here an issue with slightly shifting thresholds for low speed connections, the card is supposed to utilize highest available rate, which is usually 10Gbps.

---
- described bnx2x cases in the commit message
- appended Rb (for ocfs2)

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h | 1 -
 fs/ocfs2/dlm/dlmcommon.h                         | 4 ----
 include/linux/bitops.h                           | 1 +
 3 files changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -1
index 066765fbef06..0a59a09ef82f 100644
@@ -296,7 +296,6 @@ static inline void bnx2x_dcb_config_qm(struct bnx2x *bp, enum cos_mode mode,
  *    possible, the driver should only write the valid vnics into the internal
  *    ram according to the appropriate port mode.
  */
-#define BITS_TO_BYTES(x) ((x)/8)
 
 /* CMNG constants, as derived from system spec calculations */
 
fs/ocfs2/dlm/dlmcommon.h +0 -4
index aaf24548b02a..0463dce65bb2 100644
@@ -688,10 +688,6 @@ struct dlm_begin_reco
 	__be32 pad2;
 };
 
-
-#define BITS_PER_BYTE 8
-#define BITS_TO_BYTES(bits) (((bits)+BITS_PER_BYTE-1)/BITS_PER_BYTE)
-
 struct dlm_query_join_request
 {
 	u8 node_idx;
include/linux/bitops.h +1 -0
index cf074bce3eb3..79d80f5ddf7b 100644
@@ -5,6 +5,7 @@
 #include <linux/bits.h>
 
 #define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_BYTES(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE)
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
 
 extern unsigned int __sw_hweight8(unsigned int w);
Signature · 1 line
2.23.0.rc1
#1 lore raw
Quoted 5 lines · Andy Shevchenko

There are users already and will be more of BITS_TO_BYTES() macro. Move it to bitops.h for wider use.

In the case of ocfs2 the replacement is identical.

Quoted 12 lines

As for bnx2x, there are two places where floor version is used.
In the first case to calculate the amount of structures that can fit one memory page. In this case obviously the ceiling variant is correct and original code might have a potential bug, if amount of bits % 8 is not 0. In the second case the macro is used to calculate bytes transmitted in one microsecond. This will work for all speeds which is multiply of 1Gbps without any change, for the rest new code will give ceiling value, for instance 100Mbps will give 13 bytes, while old code gives 12 bytes and the arithmetically correct one is 12.5 bytes. Further the value is used to setup timer threshold which in any case has its own margins due to certain resolution. I don't see here an issue with slightly shifting thresholds for low speed connections, the card is supposed to utilize highest available rate, which is usually 10Gbps.

Anybody to comment on bnx2 change?
Can we survive with this applied?

Quoted 54 lines

---
- described bnx2x cases in the commit message
- appended Rb (for ocfs2)

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h | 1 -
 fs/ocfs2/dlm/dlmcommon.h                         | 4 ----
 include/linux/bitops.h                           | 1 +
 3 files changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -1
index 066765fbef06..0a59a09ef82f 100644
@@ -296,7 +296,6 @@ static inline void bnx2x_dcb_config_qm(struct bnx2x *bp, enum cos_mode mode,
  *    possible, the driver should only write the valid vnics into the internal
  *    ram according to the appropriate port mode.
  */
-#define BITS_TO_BYTES(x) ((x)/8)
 
 /* CMNG constants, as derived from system spec calculations */
 
fs/ocfs2/dlm/dlmcommon.h +0 -4
index aaf24548b02a..0463dce65bb2 100644
@@ -688,10 +688,6 @@ struct dlm_begin_reco
 	__be32 pad2;
 };
 
-
-#define BITS_PER_BYTE 8
-#define BITS_TO_BYTES(bits) (((bits)+BITS_PER_BYTE-1)/BITS_PER_BYTE)
-
 struct dlm_query_join_request
 {
 	u8 node_idx;
include/linux/bitops.h +1 -0
index cf074bce3eb3..79d80f5ddf7b 100644
@@ -5,6 +5,7 @@
 #include <linux/bits.h>
 
 #define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_BYTES(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE)
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
 
 extern unsigned int __sw_hweight8(unsigned int w);
Signature · 1 line
2.23.0.rc1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Acked-by
#2 lore raw
Quoted 88 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Andy Shevchenko
Sent: Monday, December 9, 2019 10:14 PM
To: Mark Fasheh <[email protected]>; Joel Becker <[email protected]>; Joseph Qi <[email protected]>; [email protected]; Ariel Elior <[email protected]>; Sudarsana Reddy Kalluru <[email protected]>; GR-everest-linux-l2 <GR-everest-linux- [email protected]>; David S. Miller <[email protected]>; [email protected]; Colin Ian King <[email protected]>
Subject: Re: [PATCH v2] ocfs2/dlm: Move BITS_TO_BYTES() to bitops.h for wider use

Quoted 5 lines · Andy Shevchenko

There are users already and will be more of BITS_TO_BYTES() macro. Move it to bitops.h for wider use.

In the case of ocfs2 the replacement is identical.

Quoted 12 lines

As for bnx2x, there are two places where floor version is used. In the first case to calculate the amount of structures that can fit one memory page. In this case obviously the ceiling variant is correct and original code might have a potential bug, if amount of bits % 8 is not 0. In the second case the macro is used to calculate bytes transmitted in one microsecond. This will work for all speeds which is multiply of 1Gbps without any change, for the rest new code will give ceiling value, for instance 100Mbps will give 13 bytes, while old code gives 12 bytes and the arithmetically correct one is 12.5 bytes. Further the value is used to setup timer threshold which in any case has its own margins due to certain resolution. I don't see here an issue with slightly shifting thresholds for low speed connections, the card is supposed

to utilize highest available rate, which is usually 10Gbps.

Anybody to comment on bnx2 change?
Can we survive with this applied?

drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h static inline void bnx2x_dcb_config_qm(struct bnx2x

Quoted 18 lines

---
- described bnx2x cases in the commit message
- appended Rb (for ocfs2)

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h | 1 -
 fs/ocfs2/dlm/dlmcommon.h                         | 4 ----
 include/linux/bitops.h                           | 1 +
 3 files changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -0
index 066765fbef06..0a59a09ef82f 100644
@@ -296,7 +296,6 @@ static inline void bnx2x_dcb_config_qm(struct bnx2x

*bp, enum cos_mode mode,

Quoted 33 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -1
  *    possible, the driver should only write the valid vnics into the internal
  *    ram according to the appropriate port mode.
  */
-#define BITS_TO_BYTES(x) ((x)/8)
 
 /* CMNG constants, as derived from system spec calculations */
 
fs/ocfs2/dlm/dlmcommon.h index renamed from fs/ocfs2/dlm/dlmcommon.h +0 -0

aaf24548b02a..0463dce65bb2 100644

fs/ocfs2/dlm/dlmcommon.h +0 -4
@@ -688,10 +688,6 @@ struct dlm_begin_reco
 	__be32 pad2;
 };
 
-
-#define BITS_PER_BYTE 8
-#define BITS_TO_BYTES(bits) (((bits)+BITS_PER_BYTE-1)/BITS_PER_BYTE)
-
 struct dlm_query_join_request
 {
 	u8 node_idx;
include/linux/bitops.h index renamed from include/linux/bitops.h +0 -0

cf074bce3eb3..79d80f5ddf7b 100644

include/linux/bitops.h +1 -0
@@ -5,6 +5,7 @@
 #include <linux/bits.h>
 
 #define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_BYTES(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE)
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
 
Quoted 9 lines
Quoted 4 lines
include/linux/bitops.h +0 -1
 extern unsigned int __sw_hweight8(unsigned int w);
--

2.23.0.rc1

--
With Best Regards,
Andy Shevchenko

Thanks for the changes.

maintainer
#3 lore raw

Add akpm as well.

Quoted 102 lines · Sudarsana Reddy Kalluru
Quoted 88 lines

-----Original Message-----
From: netdev-owner at vger.kernel.org <[email protected]> On Behalf Of Andy Shevchenko
Sent: Monday, December 9, 2019 10:14 PM
To: Mark Fasheh <[email protected]>; Joel Becker <[email protected]>; Joseph Qi <[email protected]>; ocfs2-devel at oss.oracle.com; Ariel Elior <[email protected]>; Sudarsana Reddy Kalluru <[email protected]>; GR-everest-linux-l2 <GR-everest-linux-
l2 at marvell.com>; David S. Miller <[email protected]>;
netdev at vger.kernel.org; Colin Ian King <[email protected]>
Subject: Re: [PATCH v2] ocfs2/dlm: Move BITS_TO_BYTES() to bitops.h for wider use

Quoted 5 lines · Andy Shevchenko

There are users already and will be more of BITS_TO_BYTES() macro. Move it to bitops.h for wider use.

In the case of ocfs2 the replacement is identical.

Quoted 12 lines

As for bnx2x, there are two places where floor version is used. In the first case to calculate the amount of structures that can fit one memory page. In this case obviously the ceiling variant is correct and original code might have a potential bug, if amount of bits % 8 is not 0. In the second case the macro is used to calculate bytes transmitted in one microsecond. This will work for all speeds which is multiply of 1Gbps without any change, for the rest new code will give ceiling value, for instance 100Mbps will give 13 bytes, while old code gives 12 bytes and the arithmetically correct one is 12.5 bytes. Further the value is used to setup timer threshold which in any case has its own margins due to certain resolution. I don't see here an issue with slightly shifting thresholds for low speed connections, the card is supposed

to utilize highest available rate, which is usually 10Gbps.

Anybody to comment on bnx2 change?
Can we survive with this applied?

drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h static inline void bnx2x_dcb_config_qm(struct bnx2x

Quoted 18 lines

---
- described bnx2x cases in the commit message
- appended Rb (for ocfs2)

 drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h | 1 -
 fs/ocfs2/dlm/dlmcommon.h                         | 4 ----
 include/linux/bitops.h                           | 1 +
 3 files changed, 1 insertion(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -0
index 066765fbef06..0a59a09ef82f 100644
@@ -296,7 +296,6 @@ static inline void bnx2x_dcb_config_qm(struct bnx2x

*bp, enum cos_mode mode,

Quoted 33 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -1
  *    possible, the driver should only write the valid vnics into the internal
  *    ram according to the appropriate port mode.
  */
-#define BITS_TO_BYTES(x) ((x)/8)
 
 /* CMNG constants, as derived from system spec calculations */
 
fs/ocfs2/dlm/dlmcommon.h index renamed from fs/ocfs2/dlm/dlmcommon.h +0 -0

aaf24548b02a..0463dce65bb2 100644

fs/ocfs2/dlm/dlmcommon.h +0 -4
@@ -688,10 +688,6 @@ struct dlm_begin_reco
 	__be32 pad2;
 };
 
-
-#define BITS_PER_BYTE 8
-#define BITS_TO_BYTES(bits) (((bits)+BITS_PER_BYTE-1)/BITS_PER_BYTE)
-
 struct dlm_query_join_request
 {
 	u8 node_idx;
include/linux/bitops.h index renamed from include/linux/bitops.h +0 -0

cf074bce3eb3..79d80f5ddf7b 100644

include/linux/bitops.h +1 -0
@@ -5,6 +5,7 @@
 #include <linux/bits.h>
 
 #define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
+#define BITS_TO_BYTES(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE)
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
 
Quoted 9 lines
Quoted 4 lines
include/linux/bitops.h +0 -1
 extern unsigned int __sw_hweight8(unsigned int w);
--

2.23.0.rc1

--
With Best Regards,
Andy Shevchenko

Thanks for the changes.