Skip to contentSkip to conversation

kernel.h: Split out mathematical helpers

PATCH In review Andy Shevchenko 2 participants 3 messages Sep 10, 2019 – Feb 4, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

---
 fs/nfs/callback_proc.c        |   1 +
 include/linux/bitops.h        |   3 +-
 include/linux/dcache.h        |   1 +
 include/linux/iommu-helper.h  |   1 +
 include/linux/kernel.h        | 143 --------------------------------
 include/linux/math.h          | 149 ++++++++++++++++++++++++++++++++++
 include/linux/rcu_node_tree.h |   2 +
 7 files changed, 156 insertions(+), 144 deletions(-)
 create mode 100644 include/linux/math.h
fs/nfs/callback_proc.c +1 -0
index f39924ba050b..aa00d109600c 100644
@@ -6,6 +6,7 @@
  *
  * NFSv4 callback procedures
  */
+#include <linux/math.h>
 #include <linux/nfs4.h>
 #include <linux/nfs_fs.h>
 #include <linux/slab.h>
include/linux/bitops.h +2 -1
index cf074bce3eb3..fbd4917603a0 100644
@@ -3,9 +3,10 @@
 #define _LINUX_BITOPS_H
 #include <asm/types.h>
 #include <linux/bits.h>
+#include <uapi/linux/kernel.h>
 
 #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_LONGS(nr)	__KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
 
 extern unsigned int __sw_hweight8(unsigned int w);
 extern unsigned int __sw_hweight16(unsigned int w);
include/linux/dcache.h +1 -0
index 10090f11ab95..d0fe48715226 100644
@@ -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 +1 -0
index 70d01edcbf8b..16fcd3cdee92 100644
@@ -4,6 +4,7 @@
 
 #include <linux/bug.h>
 #include <linux/kernel.h>
+#include <linux/math.h>
 
 static inline unsigned long iommu_device_max_index(unsigned long size,
 						   unsigned long offset,
include/linux/kernel.h +0 -143

170 lines not on this page · raw message

include/linux/math.h new file +149 -0

149 lines not on this page · raw message

include/linux/rcu_node_tree.h +2 -0
index b8e094b125ee..78feb8ba7358 100644
@@ -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.
Signature · 1 line
2.23.0
#1 lore raw
Quoted 5 lines · On Tue, 10 Sep 2019 13:51:05 +0300 Andy Shevchenko…

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.

Quoted 8 lines
---
 fs/nfs/callback_proc.c        |   1 +
 include/linux/bitops.h        |   3 +-
 include/linux/dcache.h        |   1 +
 include/linux/iommu-helper.h  |   1 +
 include/linux/kernel.h        | 143 --------------------------------
 include/linux/math.h          | 149 ++++++++++++++++++++++++++++++++++
 include/linux/rcu_node_tree.h |   2 +

I'm not really understanding how this works, apart from "dumb luck".

Random example: mm/percpu.c needs roundup(), so how does it include the new math.h?

....... ./arch/x86/include/asm/uprobes.h
........ ./include/linux/notifier.h
......... ./include/linux/mutex.h
......... ./include/linux/srcu.h
.......... ./include/linux/workqueue.h
........... ./include/linux/timer.h
............ ./include/linux/ktime.h
............. ./include/linux/time.h
.............. ./include/linux/time32.h ............... ./include/linux/timex.h ................ ./include/uapi/linux/timex.h ................. ./include/linux/time.h ................ ./include/uapi/linux/param.h ................. ./arch/x86/include/generated/uapi/asm/param.h .................. ./include/asm-generic/param.h ................... ./include/uapi/asm-generic/param.h ................ ./arch/x86/include/asm/timex.h ................. ./arch/x86/include/asm/tsc.h ............. ./include/linux/jiffies.h .............. ./arch/x86/include/generated/uapi/asm/param.h .............. ./include/generated/timeconst.h ............. ./include/linux/timekeeping.h ............. ./include/linux/timekeeping32.h ............ ./include/linux/debugobjects.h .......... ./include/linux/rcu_segcblist.h
.......... ./include/linux/srcutree.h
........... ./include/linux/rcu_node_tree.h ............ ./include/linux/math.h

oh, like that.

It seems rather unreliable. Perhaps a "#include <linux/math.h>" was intended in kernel.h?

#2 lore raw
Quoted 16 lines · Andrew Morton
Quoted 5 lines · On Tue, 10 Sep 2019 13:51:05 +0300 Andy Shevchenko…

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.

Quoted 8 lines
---
 fs/nfs/callback_proc.c        |   1 +
 include/linux/bitops.h        |   3 +-
 include/linux/dcache.h        |   1 +
 include/linux/iommu-helper.h  |   1 +
 include/linux/kernel.h        | 143 --------------------------------
 include/linux/math.h          | 149 ++++++++++++++++++++++++++++++++++
 include/linux/rcu_node_tree.h |   2 +
Quoted 1 line

I'm not really understanding how this works, apart from "dumb luck".

Looks like it right now.

Quoted 32 lines

Random example: mm/percpu.c needs roundup(), so how does it include the new math.h?

....... ./arch/x86/include/asm/uprobes.h
........ ./include/linux/notifier.h
......... ./include/linux/mutex.h
......... ./include/linux/srcu.h
.......... ./include/linux/workqueue.h
........... ./include/linux/timer.h
............ ./include/linux/ktime.h
............. ./include/linux/time.h
.............. ./include/linux/time32.h ............... ./include/linux/timex.h ................ ./include/uapi/linux/timex.h ................. ./include/linux/time.h ................ ./include/uapi/linux/param.h ................. ./arch/x86/include/generated/uapi/asm/param.h .................. ./include/asm-generic/param.h ................... ./include/uapi/asm-generic/param.h ................ ./arch/x86/include/asm/timex.h ................. ./arch/x86/include/asm/tsc.h ............. ./include/linux/jiffies.h .............. ./arch/x86/include/generated/uapi/asm/param.h .............. ./include/generated/timeconst.h ............. ./include/linux/timekeeping.h ............. ./include/linux/timekeeping32.h ............ ./include/linux/debugobjects.h .......... ./include/linux/rcu_segcblist.h
.......... ./include/linux/srcutree.h
........... ./include/linux/rcu_node_tree.h ............ ./include/linux/math.h

Quoted 1 line

oh, like that.

Long way to clean up this...

Quoted 2 lines

It seems rather unreliable. Perhaps a "#include <linux/math.h>" was intended in kernel.h?

Yeah, this needs to be done for time being in hope that it will be clearer in the future. I'll do this in v2.

Thanks for review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko