Whamcloud - gitweb
LU-4423 lprocfs: use log2.h macros instead of shift loop. 74/35274/3
authorNeilBrown <neilb@suse.com>
Thu, 20 Jun 2019 03:43:30 +0000 (23:43 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 27 Jun 2019 21:34:05 +0000 (21:34 +0000)
These shift loops seem to be trying to avoid doing a
multiplication.
The same effect can be achieved more transparently using
rounddown_pow_of_two().  Even though there is a multiplication
in the C code, the resulting machine code just does a single shift.

As rounddown_pow_of_two() is not defined for 0, and as we cannot be
positively use the blk_size is non-zero, use blk_size ?: 1.

Change-Id: Ie4cec1ca3f30617df0022a9c0dd80fe7e755ed64
Signed-off-by: NeilBrown <neilb@suse.com>
Reviewed-on: https://review.whamcloud.com/35274
Tested-by: Jenkins
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/lprocfs_status.c

index 87d2af8..6f81f5d 100644 (file)
@@ -425,9 +425,7 @@ static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
                u32 blk_size = osfs.os_bsize >> 10;
                u64 result = osfs.os_blocks;
 
-               while (blk_size >>= 1)
-                       result <<= 1;
-
+               result *= rounddown_pow_of_two(blk_size ?: 1);
                return sprintf(buf, "%llu\n", result);
        }