Skip to contentSkip to conversation

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

PATCH Superseded Andy Shevchenko 3 participants 6 messages Aug 20, 2019 – Aug 22, 2019

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

---
 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
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Andy Shevchenko

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

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

drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h static inline void bnx2x_dcb_config_qm(struct bnx2x *bp, enum cos_mode mode, · line 299

Quoted 4 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -1
@@ -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)>

I don't think this is a equivalent replace, or it is in fact wrong before?

Quoted 7 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -0
 /* CMNG constants, as derived from system spec calculations */
 
fs/ocfs2/dlm/dlmcommon.h +0 -0
index aaf24548b02a..0463dce65bb2 100644

fs/ocfs2/dlm/dlmcommon.h struct dlm_begin_reco · line 694

Quoted 7 lines
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)
-

For ocfs2 part, it looks good to me.

Quoted 16 lines
fs/ocfs2/dlm/dlmcommon.h +0 -0
 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);
#2 lore raw
Quoted 11 lines · Joseph Qi
Quoted 10 lines · Andy Shevchenko

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

---
 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(-)
Quoted 11 lines

drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h static inline void bnx2x_dcb_config_qm(struct bnx2x *bp, enum cos_mode mode, · line 299

Quoted 9 lines
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)>

I don't think this is a equivalent replace, or it is in fact wrong before?

I was thinking about this one and there are two applications:
- calculus of the amount of structures of certain type per PAGE (obviously off-by-one error in the original code IIUC purpose of STRUCT_SIZE)
- calculus of some threshold based on line speed in bytes per second (I dunno it will have any difference on the Gbs / 100 MBs speeds)

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -0
 /* CMNG constants, as derived from system spec calculations */
 
fs/ocfs2/dlm/dlmcommon.h +0 -0
index aaf24548b02a..0463dce65bb2 100644
@@ -688,10 +688,6 @@ struct dlm_begin_reco
 	__be32 pad2;
 };
 
Quoted 6 lines

fs/ocfs2/dlm/dlmcommon.h struct dlm_begin_reco · line 694

Quoted 4 lines
fs/ocfs2/dlm/dlmcommon.h +0 -4
-
-#define BITS_PER_BYTE 8
-#define BITS_TO_BYTES(bits) (((bits)+BITS_PER_BYTE-1)/BITS_PER_BYTE)
-

For ocfs2 part, it looks good to me.

Thanks!

Quoted 17 lines
Quoted 17 lines
fs/ocfs2/dlm/dlmcommon.h +0 -0
 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 · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 40 lines

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

Quoted 11 lines · Joseph Qi
Quoted 10 lines · Andy Shevchenko

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

---
 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(-)
Quoted 6 lines

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

Quoted 6 lines
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 6 lines

drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h static inline void bnx2x_dcb_config_qm(struct bnx2x *bp, enum cos_mode mode,

Quoted 4 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)>

I don't think this is a equivalent replace, or it is in fact wrong before?

Quoted 7 lines

I was thinking about this one and there are two applications:
- calculus of the amount of structures of certain type per PAGE (obviously off-by-one error in the original code IIUC purpose of
STRUCT_SIZE)
- calculus of some threshold based on line speed in bytes per second (I dunno it will have any difference on the Gbs / 100 MBs speeds)

I see that both the implementations (existing vs new) yield same value for standard speeds 10G (i.e.,10000), 1G (1000) that device supports. Hence the change look to be ok.

Quoted 43 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_init.h +0 -0
 /* CMNG constants, as derived from system spec calculations */
 
fs/ocfs2/dlm/dlmcommon.h +0 -0
index aaf24548b02a..0463dce65bb2 100644
@@ -688,10 +688,6 @@ struct dlm_begin_reco
 	__be32 pad2;
 };
 
Quoted 7 lines

fs/ocfs2/dlm/dlmcommon.h struct dlm_begin_reco · line 694

Quoted 5 lines
fs/ocfs2/dlm/dlmcommon.h +0 -4
-
-#define BITS_PER_BYTE 8
-#define BITS_TO_BYTES(bits)
 (((bits)+BITS_PER_BYTE-1)/BITS_PER_BYTE)
-

For ocfs2 part, it looks good to me.

Thanks!

Quoted 11 lines
Quoted 11 lines
fs/ocfs2/dlm/dlmcommon.h +0 -0
 struct dlm_query_join_request
 {
fs/ocfs2/dlm/dlmcommon.h +0 -0
 	u8 node_idx;
include/linux/bitops.h index renamed from include/linux/bitops.h +0 -0

cf074bce3eb3..79d80f5ddf7b 100644

include/linux/bitops.h +0 -0
@@ -5,6 +5,7 @@
 #include <linux/bits.h>
 
Quoted 3 lines

include/linux/bitops.h

Quoted 3 lines
include/linux/bitops.h +1 -0
 #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 3 lines

include/linux/bitops.h line 11

Quoted 3 lines
include/linux/bitops.h +0 -0
 extern unsigned int __sw_hweight8(unsigned int w);
 

--
With Best Regards,
Andy Shevchenko

#4 lore raw
Quoted 23 lines · Sudarsana Reddy Kalluru
Quoted 23 lines

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

Quoted 7 lines · Joseph Qi
Quoted 4 lines · Andy Shevchenko

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

-#define BITS_TO_BYTES(x) ((x)/8)>

I don't think this is a equivalent replace, or it is in fact wrong before?

Quoted 8 lines
Quoted 7 lines

I was thinking about this one and there are two applications:
- calculus of the amount of structures of certain type per PAGE (obviously off-by-one error in the original code IIUC purpose of
STRUCT_SIZE)
- calculus of some threshold based on line speed in bytes per second (I dunno it will have any difference on the Gbs / 100 MBs speeds)

I see that both the implementations (existing vs new) yield same value for standard speeds 10G (i.e.,10000), 1G (1000) that device supports. Hence the change look to be ok.

Thank you for testing, may I use your Tested-by tag?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 47 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Thursday, August 22, 2019 2:39 PM
To: Sudarsana Reddy Kalluru <[email protected]>
Cc: Joseph Qi <[email protected]>; Mark Fasheh <[email protected]>; Joel Becker <[email protected]>; ocfs2- [email protected]; Ariel Elior <[email protected]>; GR-everest-linux-l2 <[email protected]>; David S. Miller <[email protected]>; [email protected]; Colin Ian King <[email protected]>
Subject: Re: [PATCH v1] ocfs2/dlm: Move BITS_TO_BYTES() to bitops.h for wider use

Quoted 3 lines · Sudarsana Reddy Kalluru
Quoted 3 lines

-----Original Message-----
From: [email protected] <[email protected]>

On

Quoted 28 lines
Quoted 28 lines

Behalf Of Andy Shevchenko
Sent: Wednesday, August 21, 2019 2:56 PM
To: Joseph Qi <[email protected]>
Cc: Mark Fasheh <[email protected]>; Joel Becker <[email protected]>; [email protected]; Ariel Elior <[email protected]>; Sudarsana Reddy Kalluru <[email protected]>; GR-everest-linux-l2 <GR-everest- [email protected]>; David S. Miller <[email protected]>; [email protected]; Colin Ian King <[email protected]>
Subject: Re: [PATCH v1] ocfs2/dlm: Move BITS_TO_BYTES() to bitops.h for wider use

Quoted 7 lines · Joseph Qi
Quoted 4 lines · Andy Shevchenko

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

-#define BITS_TO_BYTES(x) ((x)/8)>

I don't think this is a equivalent replace, or it is in fact wrong before?

I was thinking about this one and there are two applications:
- calculus of the amount of structures of certain type per PAGE (obviously off-by-one error in the original code IIUC purpose of
STRUCT_SIZE)
- calculus of some threshold based on line speed in bytes per second (I dunno it will have any difference on the Gbs / 100 MBs speeds)

Quoted 5 lines
Quoted 1 line

I see that both the implementations (existing vs new) yield same value for

standard speeds 10G (i.e.,10000), 1G (1000) that device supports. Hence the change look to be ok.

Thank you for testing, may I use your Tested-by tag?

Sorry, I didn't test the actual driver flows. Was only referring to the output values for 1000/10000 speed values.

Quoted 5 lines

--
With Best Regards,
Andy Shevchenko