staging: lustre: Replace a bit shift by a use of BIT.
PATCH 1/1 staging: lustre: Replace a bit shift by a use of BIT.
This patch replaces bit shifting on 1 with the BIT(x) macro. This was done with coccinelle:
@@
constant c;
@@
-1 << c
+BIT(c)
--- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 2 +- drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 8 ++++---- drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c | 2 +- drivers/staging/lustre/lnet/lnet/lib-ptl.c | 4 ++-- drivers/staging/lustre/lnet/lnet/net_fault.c | 8 ++++---- drivers/staging/lustre/lustre/llite/lproc_llite.c | 4 ++-- drivers/staging/lustre/lustre/obdclass/lustre_handles.c | 2 +- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +1 -1
@@ -2241,7 +2241,7 @@ static int kiblnd_hdev_get_attr(struct kib_hca_dev *hdev)* matching that of the native system */ hdev->ibh_page_shift =PAGE_SHIFT ; - hdev->ibh_page_size =1 <<PAGE_SHIFT ; + hdev->ibh_page_size =BIT (PAGE_SHIFT ); hdev->ibh_page_mask = ~((__u64 )hdev->ibh_page_size -1 ); hdev->ibh_mr_size = hdev->ibh_ibdev->attrs.max_mr_size;
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +4 -4
@@ -1906,14 +1906,14 @@ ksocknal_connect(struct ksock_route *route)if (retry_later)/* needs reschedule */ break ; -if (wanted & (1 <<SOCKLND_CONN_ANY )) { +if (wanted & (BIT (SOCKLND_CONN_ANY ))) { type =SOCKLND_CONN_ANY ; - }else if (wanted & (1 <<SOCKLND_CONN_CONTROL )) { + }else if (wanted & (BIT (SOCKLND_CONN_CONTROL ))) { type =SOCKLND_CONN_CONTROL ; - }else if (wanted & (1 <<SOCKLND_CONN_BULK_IN )) { + }else if (wanted & (BIT (SOCKLND_CONN_BULK_IN ))) { type =SOCKLND_CONN_BULK_IN ; }else { -LASSERT (wanted & (1 <<SOCKLND_CONN_BULK_OUT )); +LASSERT (wanted & (BIT (SOCKLND_CONN_BULK_OUT ))); type =SOCKLND_CONN_BULK_OUT ; }
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c +1 -1
@@ -71,7 +71,7 @@ static int typed_conns = 1;module_param (typed_conns, int,0444 );MODULE_PARM_DESC (typed_conns,"use different sockets for bulk" ); -static int min_bulk =1 <<10 ; +static int min_bulk =BIT (10 );module_param (min_bulk, int,0644 );MODULE_PARM_DESC (min_bulk,"smallest 'large' message" );
drivers/staging/lustre/lnet/lnet/lib-ptl.c +2 -2
@@ -332,7 +332,7 @@ lnet_mt_test_exhausted(struct lnet_match_table *mtable, int pos)LASSERT (pos <=LNET_MT_HASH_IGNORE );/* mtable::mt_mhash[pos] is marked as exhausted or not */ bmap = &mtable->mt_exhausted[pos >>LNET_MT_BITS_U64 ]; - pos &= (1 <<LNET_MT_BITS_U64 ) -1 ; + pos &= (BIT (LNET_MT_BITS_U64 )) -1 ;return (*bmap & (1ULL << pos)); }
@@ -347,7 +347,7 @@ lnet_mt_set_exhausted(struct lnet_match_table *mtable, int pos, int exhausted)/* set mtable::mt_mhash[pos] as exhausted/non-exhausted */ bmap = &mtable->mt_exhausted[pos >>LNET_MT_BITS_U64 ]; - pos &= (1 <<LNET_MT_BITS_U64 ) -1 ; + pos &= (BIT (LNET_MT_BITS_U64 )) -1 ;if (!exhausted) *bmap &= ~(1ULL << pos);
drivers/staging/lustre/lnet/lnet/net_fault.c +4 -4
@@ -997,10 +997,10 @@ lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data)int lnet_fault_init (void ) { -BUILD_BUG_ON (LNET_PUT_BIT !=1 <<LNET_MSG_PUT ); -BUILD_BUG_ON (LNET_ACK_BIT !=1 <<LNET_MSG_ACK ); -BUILD_BUG_ON (LNET_GET_BIT !=1 <<LNET_MSG_GET ); -BUILD_BUG_ON (LNET_REPLY_BIT !=1 <<LNET_MSG_REPLY ); +BUILD_BUG_ON (LNET_PUT_BIT !=BIT (LNET_MSG_PUT )); +BUILD_BUG_ON (LNET_ACK_BIT !=BIT (LNET_MSG_ACK )); +BUILD_BUG_ON (LNET_GET_BIT !=BIT (LNET_MSG_GET )); +BUILD_BUG_ON (LNET_REPLY_BIT !=BIT (LNET_MSG_REPLY ));mutex_init (&delay_dd.dd_mutex);spin_lock_init (&delay_dd.dd_lock);
drivers/staging/lustre/lustre/llite/lproc_llite.c +2 -2
@@ -1308,7 +1308,7 @@ static void ll_display_extents_info(struct ll_rw_extents_info *io_extents, r,pct (r, read_tot),pct (read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); start = end; -if (start ==1 <<10 ) { +if (start ==BIT (10 )) { start =1 ; units +=10 ; unitp++;
@@ -1506,7 +1506,7 @@ void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,lprocfs_oh_clear (&io_extents->pp_extents[cur].pp_w_hist); } -for (i =0 ; (count >= (1 <<LL_HIST_START << i)) && +for (i =0 ; (count >= (BIT (LL_HIST_START ) << i)) && (i < (LL_HIST_MAX -1 )); i++) ;if (rw ==0 ) {
drivers/staging/lustre/lustre/obdclass/lustre_handles.c +1 -1
@@ -49,7 +49,7 @@ static struct handle_bucket {struct list_head head; } *handle_hash; -#define HANDLE_HASH_SIZE (1 << 16) +#define HANDLE_HASH_SIZE (BIT(16))#define HANDLE_HASH_MASK (HANDLE_HASH_SIZE - 1)/*
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
@@ -2847,7 +2847,7 @@ static int __init osc_init(void)register_shrinker (&osc_cache_shrinker);/* This is obviously too much memory, only prevent overflow here */ -if (osc_reqpool_mem_max >=1 <<12 || osc_reqpool_mem_max ==0 ) { +if (osc_reqpool_mem_max >=BIT (12 ) || osc_reqpool_mem_max ==0 ) { rc = -EINVAL ; goto out_type; }
Signature · 1 line
2.11.0
Quoted 9 lines · Arushi Singhal
This patch replaces bit shifting on 1 with the BIT(x) macro. This was done with coccinelle:
@@
constant c;
@@-1 << c
+BIT(c)
Did you take the time to look at what this Coccinelle script actually did, to see if it actually makes sense? Some of the cases where this replacement was done makes sense because a specific bit is being accessed (i.e. a bitmask). Elsewhere, it doesn't make sense to use BIT() to specify numeric values (e.g. PAGE_SHIFT, 1 << 12 = 1024, etc) since they are not bitmasks.
Quoted 17 lines
Signed-off-by Arushi Singhal <[email protected]>---
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 2 +- drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 8 ++++---- drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c | 2 +- drivers/staging/lustre/lnet/lnet/lib-ptl.c | 4 ++-- drivers/staging/lustre/lnet/lnet/net_fault.c | 8 ++++---- drivers/staging/lustre/lustre/llite/lproc_llite.c | 4 ++-- drivers/staging/lustre/lustre/obdclass/lustre_handles.c | 2 +- drivers/staging/lustre/lustre/osc/osc_request.c | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-)drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +0
-0
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c static int kiblnd_hdev_get_attr(struct kib_hca_dev *hdev) · line 2244
Quoted 5 lines
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +1
-1@@ -2241,7 +2241,7 @@ static int kiblnd_hdev_get_attr(struct kib_hca_dev *hdev)* matching that of the native system */ hdev->ibh_page_shift =PAGE_SHIFT ; - hdev->ibh_page_size =1 <<PAGE_SHIFT ; + hdev->ibh_page_size =BIT (PAGE_SHIFT );
This should just be replaced with "PAGE_SIZE".
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c ksocknal_connect(struct ksock_route *route) · line 1909
Quoted 13 lines
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +0
-0hdev->ibh_page_mask = ~((__u64 )hdev->ibh_page_size -1 ); hdev->ibh_mr_size = hdev->ibh_ibdev->attrs.max_mr_size;drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +1
-1@@ -1906,14 +1906,14 @@ ksocknal_connect(struct ksock_route *route)if (retry_later)/* needs reschedule */ break ; -if (wanted & (1 <<SOCKLND_CONN_ANY )) { +if (wanted & (BIT (SOCKLND_CONN_ANY ))) {
There shouldn't be any need to put parenthesis around (BIT(x)) here, or any of the cases below, or the BIT macro is broken. But besides that, the use of BIT() here looks OK.
Quoted 18 lines
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +3
-3type =SOCKLND_CONN_ANY ; - }else if (wanted & (1 <<SOCKLND_CONN_CONTROL )) { + }else if (wanted & (BIT (SOCKLND_CONN_CONTROL ))) { type =SOCKLND_CONN_CONTROL ; - }else if (wanted & (1 <<SOCKLND_CONN_BULK_IN )) { + }else if (wanted & (BIT (SOCKLND_CONN_BULK_IN ))) { type =SOCKLND_CONN_BULK_IN ; }else { -LASSERT (wanted & (1 <<SOCKLND_CONN_BULK_OUT )); +LASSERT (wanted & (BIT (SOCKLND_CONN_BULK_OUT ))); type =SOCKLND_CONN_BULK_OUT ; }drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c +0
-0
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c static int typed_conns = 1; · line 74
Quoted 5 lines
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c +1
-1@@ -71,7 +71,7 @@ static int typed_conns = 1;module_param (typed_conns, int,0444 );MODULE_PARM_DESC (typed_conns,"use different sockets for bulk" ); -static int min_bulk =1 <<10 ; +static int min_bulk =BIT (10 );
This is a scalar value and not a bitmask. It could just be "1024", but using BIT() is not correct.
drivers/staging/lustre/lnet/lnet/lib-ptl.c lnet_mt_test_exhausted(struct lnet_match_table *mtable, int pos) · line 335
Quoted 13 lines
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c +0
-0module_param (min_bulk, int,0644 );MODULE_PARM_DESC (min_bulk,"smallest 'large' message" );drivers/staging/lustre/lnet/lnet/lib-ptl.c +1
-1@@ -332,7 +332,7 @@ lnet_mt_test_exhausted(struct lnet_match_table *mtable, int pos)LASSERT (pos <=LNET_MT_HASH_IGNORE );/* mtable::mt_mhash[pos] is marked as exhausted or not */ bmap = &mtable->mt_exhausted[pos >>LNET_MT_BITS_U64 ]; - pos &= (1 <<LNET_MT_BITS_U64 ) -1 ; + pos &= (BIT (LNET_MT_BITS_U64 )) -1 ;
The use of BIT() above is probably not correct. This is creating a mask to align pos to a multiple of (1 << LNET_MT_BITS_U64), and IMHO BIT() shouldn't be used just any time a value is being shifted but rather only when a one-bit mask is needed.
Conversely, the below usage could be converted to use the macro since this is actually a bitmask:
return *bmap & BIT(pos);
drivers/staging/lustre/lnet/lnet/lib-ptl.c lnet_mt_set_exhausted(struct lnet_match_table *mtable, int pos, int exhausted) · line 353
Quoted 11 lines
drivers/staging/lustre/lnet/lnet/lib-ptl.c +1
-1return (*bmap & (1ULL << pos)); }@@ -347,7 +347,7 @@ lnet_mt_set_exhausted(struct lnet_match_table *mtable, int pos, int exhausted)/* set mtable::mt_mhash[pos] as exhausted/non-exhausted */ bmap = &mtable->mt_exhausted[pos >>LNET_MT_BITS_U64 ]; - pos &= (1 <<LNET_MT_BITS_U64 ) -1 ; + pos &= (BIT (LNET_MT_BITS_U64 )) -1 ;if (!exhausted) *bmap &= ~(1ULL << pos);
Ditto.
Quoted 8 lines
drivers/staging/lustre/lnet/lnet/net_fault.c +0
-0@@ -997,10 +997,10 @@ lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data)int
lnet_fault_init(void)
{
drivers/staging/lustre/lnet/lnet/net_fault.c lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data) · line 1003
Quoted 8 lines
drivers/staging/lustre/lnet/lnet/net_fault.c +4
-4-BUILD_BUG_ON (LNET_PUT_BIT !=1 <<LNET_MSG_PUT ); -BUILD_BUG_ON (LNET_ACK_BIT !=1 <<LNET_MSG_ACK ); -BUILD_BUG_ON (LNET_GET_BIT !=1 <<LNET_MSG_GET ); -BUILD_BUG_ON (LNET_REPLY_BIT !=1 <<LNET_MSG_REPLY ); +BUILD_BUG_ON (LNET_PUT_BIT !=BIT (LNET_MSG_PUT )); +BUILD_BUG_ON (LNET_ACK_BIT !=BIT (LNET_MSG_ACK )); +BUILD_BUG_ON (LNET_GET_BIT !=BIT (LNET_MSG_GET )); +BUILD_BUG_ON (LNET_REPLY_BIT !=BIT (LNET_MSG_REPLY ));
This looks reasonable at first glance, though on further thought it seems kind of pointless since this is really:
#defined LET_PUT_BIT BIT(LNET_MSG_PUT)
BUILD_BUG_ON(BIT(LNET_MSG_PUT) != BIT(LNET_MSG_PUT))
so it is just checking that the macro's value is the same when called two times. I'd suggest just getting rid of these BUILD_BUG_ON() checks completely
drivers/staging/lustre/lustre/llite/lproc_llite.c static void ll_display_extents_info(struct ll_rw_extents_info *io_extents, · line 1311
Quoted 10 lines
drivers/staging/lustre/lustre/llite/lproc_llite.c +1
-1@@ -1308,7 +1308,7 @@ static void ll_display_extents_info(struct ll_rw_extents_info *io_extents, r,pct (r, read_tot),pct (read_cum, read_tot), w, pct(w, write_tot), pct(write_cum, write_tot)); start = end; -if (start ==1 <<10 ) { +if (start ==BIT (10 )) {
This should just be 1024, or could be left as-is left as-is.
drivers/staging/lustre/lustre/llite/lproc_llite.c void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid, · line 1509
Quoted 9 lines
drivers/staging/lustre/lustre/llite/lproc_llite.c +1
-1start =1 ; units +=10 ; unitp++;@@ -1506,7 +1506,7 @@ void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,lprocfs_oh_clear (&io_extents->pp_extents[cur].pp_w_hist); } - for (i = 0; (count >= (1 << LL_HIST_START << i)) && + for (i = 0; (count >= (BIT(LL_HIST_START) << i)) &&
This is also not a bitmask, but rather a scalar value.
drivers/staging/lustre/lustre/obdclass/lustre_handles.c static struct handle_bucket { · line 52
Quoted 13 lines
drivers/staging/lustre/lustre/llite/lproc_llite.c +0
-0(i < (LL_HIST_MAX - 1)); i++) ;if (rw ==0 ) {drivers/staging/lustre/lustre/obdclass/lustre_handles.c +1
-1@@ -49,7 +49,7 @@ static struct handle_bucket {struct list_head head; } *handle_hash; -#define HANDLE_HASH_SIZE (1 << 16) +#define HANDLE_HASH_SIZE (BIT(16))
Also not a bitmask, but a scalar value.
drivers/staging/lustre/lustre/osc/osc_request.c static int __init osc_init(void) · line 2850
Quoted 13 lines
drivers/staging/lustre/lustre/obdclass/lustre_handles.c +0
-0#define HANDLE_HASH_MASK (HANDLE_HASH_SIZE - 1)/* drivers/staging/lustre/lustre/osc/osc_request.c +1
-1@@ -2847,7 +2847,7 @@ static int __init osc_init(void)register_shrinker (&osc_cache_shrinker);/* This is obviously too much memory, only prevent overflow here */ -if (osc_reqpool_mem_max >=1 <<12 || osc_reqpool_mem_max ==0 ) { +if (osc_reqpool_mem_max >=BIT (12 ) || osc_reqpool_mem_max ==0 ) {
Also a scalar value. Could be 4096.
Cheers, Andreas
Quoted 5 lines · Andreas
Quoted 3 lines · Arushi Singhal
This patch replaces bit shifting on 1 with the BIT(x) macro. This was done with coccinelle:
[snip]
Quoted 20 lines
Quoted 8 lines
drivers/staging/lustre/lnet/lnet/net_fault.c +0
-0@@ -997,10 +997,10 @@ lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data)int
lnet_fault_init(void)
{drivers/staging/lustre/lnet/lnet/net_fault.c lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data) · line 1003
Quoted 8 lines
drivers/staging/lustre/lnet/lnet/net_fault.c +4
-4-BUILD_BUG_ON (LNET_PUT_BIT !=1 <<LNET_MSG_PUT ); -BUILD_BUG_ON (LNET_ACK_BIT !=1 <<LNET_MSG_ACK ); -BUILD_BUG_ON (LNET_GET_BIT !=1 <<LNET_MSG_GET ); -BUILD_BUG_ON (LNET_REPLY_BIT !=1 <<LNET_MSG_REPLY ); +BUILD_BUG_ON (LNET_PUT_BIT !=BIT (LNET_MSG_PUT )); +BUILD_BUG_ON (LNET_ACK_BIT !=BIT (LNET_MSG_ACK )); +BUILD_BUG_ON (LNET_GET_BIT !=BIT (LNET_MSG_GET )); +BUILD_BUG_ON (LNET_REPLY_BIT !=BIT (LNET_MSG_REPLY ));This looks reasonable at first glance, though on further thought it seems kind of pointless since this is really:
Quoted 6 lines
#defined
LET_PUT_BITBIT(LNET_MSG_PUT)BUILD_BUG_ON(BIT(LNET_MSG_PUT) != BIT(LNET_MSG_PUT))so it is just checking that the macro's value is the same when called two times. I'd suggest just getting rid of these
BUILD_BUG_ON()checks completely .
Arushi, it would be great if you could submit a patch to remove the above BUILD_BUG_ON() lines completely. I don't think they have any value anymore.
Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation