bitops: make BYTES_TO_BITS() treewide-available
authorAlexander Lobakin <aleksander.lobakin@intel.com>
Wed, 27 Mar 2024 15:23:42 +0000 (16:23 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 1 Apr 2024 09:49:27 +0000 (10:49 +0100)
Avoid open-coding that simple expression each time by moving
BYTES_TO_BITS() from the probes code to <linux/bitops.h> to export
it to the rest of the kernel.
Simplify the macro while at it. `BITS_PER_LONG / sizeof(long)` always
equals to %BITS_PER_BYTE, regardless of the target architecture.
Do the same for the tools ecosystem as well (incl. its version of
bitops.h). The previous implementation had its implicit type of long,
while the new one is int, so adjust the format literal accordingly in
the perf code.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Acked-by: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/bitops.h
kernel/trace/trace_probe.c
tools/include/linux/bitops.h
tools/perf/util/probe-finder.c

index f7f5a783da2aa8ad8f5de0a3a70ab3340e5963f6..e0cd09eb91cdca687742ea7e31be339b2b367321 100644 (file)
@@ -21,6 +21,8 @@
 #define BITS_TO_U32(nr)                __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
 #define BITS_TO_BYTES(nr)      __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
 
+#define BYTES_TO_BITS(nb)      ((nb) * BITS_PER_BYTE)
+
 extern unsigned int __sw_hweight8(unsigned int w);
 extern unsigned int __sw_hweight16(unsigned int w);
 extern unsigned int __sw_hweight32(unsigned int w);
index dfe3ee6035ecc74da70ebd8104d23f1ef2a25cde..87337a0c8e034cc539122c3b98a8ce4e06727e59 100644 (file)
@@ -1180,8 +1180,6 @@ parse_probe_arg(char *arg, const struct fetch_type *type,
        return ret;
 }
 
-#define BYTES_TO_BITS(nb)      ((BITS_PER_LONG * (nb)) / sizeof(long))
-
 /* Bitfield type needs to be parsed into a fetch function */
 static int __parse_bitfield_probe_arg(const char *bf,
                                      const struct fetch_type *t,
index 7319f6ced10860e3f0c30c599086384a5268740f..272f15d0e43489469ecbf42aeace02b187166851 100644 (file)
@@ -20,6 +20,8 @@
 #define BITS_TO_U32(nr)                DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
 #define BITS_TO_BYTES(nr)      DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
 
+#define BYTES_TO_BITS(nb)      ((nb) * BITS_PER_BYTE)
+
 extern unsigned int __sw_hweight8(unsigned int w);
 extern unsigned int __sw_hweight16(unsigned int w);
 extern unsigned int __sw_hweight32(unsigned int w);
index c8923375e30d6618fda564b84c41317c46009a3d..630e16c54ed5cb91b6b73769e40a1c30f8133e90 100644 (file)
@@ -186,8 +186,6 @@ static_var:
        return ret2;
 }
 
-#define BYTES_TO_BITS(nb)      ((nb) * BITS_PER_LONG / sizeof(long))
-
 static int convert_variable_type(Dwarf_Die *vr_die,
                                 struct probe_trace_arg *tvar,
                                 const char *cast, bool user_access)
@@ -217,7 +215,7 @@ static int convert_variable_type(Dwarf_Die *vr_die,
                total = dwarf_bytesize(vr_die);
                if (boffs < 0 || total < 0)
                        return -ENOENT;
-               ret = snprintf(buf, 16, "b%d@%d/%zd", bsize, boffs,
+               ret = snprintf(buf, 16, "b%d@%d/%d", bsize, boffs,
                                BYTES_TO_BITS(total));
                goto formatted;
        }