kernel.h: Split out mathematical helpers
Subsystems (8)
PATCH 1/1 kernel.h: Split out mathematical helpers
kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out mathematical helpers.
At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for existing users.
Signed-off-by Andy Shevchenko <[email protected]>
--- fs/nfs/callback_proc.c | 5 + include/linux/bitops.h | 11 ++- include/linux/dcache.h | 1 + include/linux/iommu-helper.h | 4 +- include/linux/kernel.h | 173 +-------------------------------- include/linux/math.h | 177 ++++++++++++++++++++++++++++++++++ include/linux/rcu_node_tree.h | 2 + include/linux/units.h | 2 +- lib/errname.c | 1 + lib/errseq.c | 1 + lib/find_bit.c | 3 +- lib/math/div64.c | 3 +- lib/math/int_pow.c | 2 +- lib/math/int_sqrt.c | 3 +- lib/math/reciprocal_div.c | 9 +- 15 files changed, 214 insertions(+), 183 deletions(-) create mode 100644 include/linux/math.h
fs/nfs/callback_proc.c +5 -0
@@ -6,10 +6,15 @@* * NFSv4 callback procedures */ + +#include <linux/errno.h> +#include <linux/math.h> #include <linux/nfs4.h> #include <linux/nfs_fs.h> #include <linux/slab.h> #include <linux/rcupdate.h> +#include <linux/types.h> +#include "nfs4_fs.h" #include "callback.h" #include "delegation.h"
include/linux/bitops.h +7 -4
@@ -1,9 +1,12 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _LINUX_BITOPS_H#define _LINUX_BITOPS_H +#include <asm/types.h> #include <linux/bits.h> +#include <uapi/linux/kernel.h> +/* Set bits in the first 'n' bytes when loaded from memory */ #ifdef __LITTLE_ENDIAN# define aligned_byte_mask (n) ((1UL << 8*(n))-1)
@@ -12,10 +15,10 @@#endif #define BITS_PER_TYPE (type) (sizeof(type) * BITS_PER_BYTE) -#define BITS_TO_LONGS (nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long)) -#define BITS_TO_U64 (nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u64)) -#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 BITS_TO_LONGS (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long)) +#define BITS_TO_U64 (nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(u64)) +#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))extern unsigned int __sw_hweight8 (unsigned int w);extern unsigned int __sw_hweight16 (unsigned int w);
include/linux/dcache.h +1 -0
@@ -4,6 +4,7 @@#include <linux/atomic.h> #include <linux/list.h> +#include <linux/math.h> #include <linux/rculist.h> #include <linux/rculist_bl.h> #include <linux/spinlock.h>
include/linux/iommu-helper.h +3 -1
@@ -3,7 +3,9 @@#define _LINUX_IOMMU_HELPER_H#include <linux/bug.h> -#include <linux/kernel.h> +#include <linux/log2.h> +#include <linux/math.h> +#include <linux/types.h> static inline unsigned long iommu_device_max_index(unsigned long size, unsigned long offset,
include/linux/kernel.h +3 -170
213 lines not on this page · raw message
include/linux/math.h new file +177 -0
177 lines not on this page · raw message
include/linux/rcu_node_tree.h +2 -0
@@ -20,6 +20,8 @@#ifndef __LINUX_RCU_NODE_TREE_H#define __LINUX_RCU_NODE_TREE_H +#include <linux/math.h> +/* * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and * CONFIG_RCU_FANOUT_LEAF.
include/linux/units.h +1 -1
@@ -2,7 +2,7 @@#ifndef _LINUX_UNITS_H#define _LINUX_UNITS_H -#include <linux/kernel.h> +#include <linux/math.h> #define ABSOLUTE_ZERO_MILLICELSIUS -273150
lib/errname.c +1 -0
@@ -3,6 +3,7 @@#include <linux/errno.h> #include <linux/errname.h> #include <linux/kernel.h> +#include <linux/math.h> /* * Ensure these tables do not accidentally become gigantic if some
lib/errseq.c +1 -0
@@ -3,6 +3,7 @@#include <linux/bug.h> #include <linux/atomic.h> #include <linux/errseq.h> +#include <linux/log2.h> /* * An errseq_t is a way of recording errors in one place, and allowing any
lib/find_bit.c +2 -1
@@ -15,8 +15,9 @@#include <linux/bitops.h> #include <linux/bitmap.h> #include <linux/export.h> -#include <linux/kernel.h> +#include <linux/math.h> #include <linux/minmax.h> +#include <linux/swab.h> #if !defined(find_next_bit) || !defined(find_next_zero_bit) || \ !defined(find_next_bit_le) || !defined(find_next_zero_bit_le) || \
lib/math/div64.c +2 -1
@@ -18,8 +18,9 @@* or by defining a preprocessor macro in arch/include/asm/div64.h. */ +#include <linux/bitops.h> #include <linux/export.h> -#include <linux/kernel.h> +#include <linux/math.h> #include <linux/math64.h> /* Not needed on 64bit architectures */
lib/math/int_pow.c +1 -1
@@ -6,7 +6,7 @@*/ #include <linux/export.h> -#include <linux/kernel.h> +#include <linux/math.h> #include <linux/types.h> /**
lib/math/int_sqrt.c +2 -1
@@ -6,9 +6,10 @@* square root from Guy L. Steele. */ -#include <linux/kernel.h> #include <linux/export.h> #include <linux/bitops.h> +#include <linux/limits.h> +#include <linux/math.h> /** * int_sqrt - computes the integer square root
lib/math/reciprocal_div.c +6 -3
@@ -1,10 +1,13 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/bitops.h> #include <linux/bug.h> -#include <linux/kernel.h> -#include <asm/div64.h> -#include <linux/reciprocal_div.h> #include <linux/export.h> +#include <linux/limits.h> +#include <linux/math.h> #include <linux/minmax.h> +#include <linux/types.h> + +#include <linux/reciprocal_div.h> /* * For a description of the algorithm please have a look at
Signature · 1 line
2.28.0