Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bitops: make BYTES_TO_BITS() treewide-available

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>

authored by

Alexander Lobakin and committed by
David S. Miller
7d8296b2 72cc1980

+5 -5
+2
include/linux/bitops.h
··· 21 21 #define BITS_TO_U32(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) 22 22 #define BITS_TO_BYTES(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) 23 23 24 + #define BYTES_TO_BITS(nb) ((nb) * BITS_PER_BYTE) 25 + 24 26 extern unsigned int __sw_hweight8(unsigned int w); 25 27 extern unsigned int __sw_hweight16(unsigned int w); 26 28 extern unsigned int __sw_hweight32(unsigned int w);
-2
kernel/trace/trace_probe.c
··· 1180 1180 return ret; 1181 1181 } 1182 1182 1183 - #define BYTES_TO_BITS(nb) ((BITS_PER_LONG * (nb)) / sizeof(long)) 1184 - 1185 1183 /* Bitfield type needs to be parsed into a fetch function */ 1186 1184 static int __parse_bitfield_probe_arg(const char *bf, 1187 1185 const struct fetch_type *t,
+2
tools/include/linux/bitops.h
··· 20 20 #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u32)) 21 21 #define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(char)) 22 22 23 + #define BYTES_TO_BITS(nb) ((nb) * BITS_PER_BYTE) 24 + 23 25 extern unsigned int __sw_hweight8(unsigned int w); 24 26 extern unsigned int __sw_hweight16(unsigned int w); 25 27 extern unsigned int __sw_hweight32(unsigned int w);
+1 -3
tools/perf/util/probe-finder.c
··· 186 186 return ret2; 187 187 } 188 188 189 - #define BYTES_TO_BITS(nb) ((nb) * BITS_PER_LONG / sizeof(long)) 190 - 191 189 static int convert_variable_type(Dwarf_Die *vr_die, 192 190 struct probe_trace_arg *tvar, 193 191 const char *cast, bool user_access) ··· 215 217 total = dwarf_bytesize(vr_die); 216 218 if (boffs < 0 || total < 0) 217 219 return -ENOENT; 218 - ret = snprintf(buf, 16, "b%d@%d/%zd", bsize, boffs, 220 + ret = snprintf(buf, 16, "b%d@%d/%d", bsize, boffs, 219 221 BYTES_TO_BITS(total)); 220 222 goto formatted; 221 223 }