Skip to contentSkip to conversation

Cleanup cpumask.h inclusion in core headers

PATCH New Yury Norov 1 participant 7 messages May 28, 2024

Subsystems (14)
lore
Share & tools
lore

Yury Norov

author maintainer
#0 lore raw

cover Cleanup cpumask.h inclusion in core headers

Many core headers include linux/cpumask.h for nothing, and some others include it just for types. We already have nodemask_types.h, and this series adds cpumask_types.h to optimize core headers inclusion paths.

Interestingly, it doesn't improve on build time for me, but the headers cleanup work should keep going.

Yury Norov (6):
MAINTAINERS: add linux/nodemask_types.h to BITMAP API
sched: pre-caculate ilog2(TASK_REPORT_MAX)
cpumask: split out include/linux/cpumask_types.h
sched: drop dependency on cpumask.h
cpumask: cleanup core headers inclusion
cpumask: make core headers including cpumask_types.h where possible

Yury Norov (6):
MAINTAINERS: add linux/nodemask_types.h to BITMAP API
sched: pre-caculate ilog2(TASK_REPORT_MAX)
cpumask: split out include/linux/cpumask_types.h
sched: drop dependency on cpumask.h
cpumask: cleanup core headers inclusion
cpumask: make core headers including cpumask_types.h where possible

 MAINTAINERS                                  |  2 +
 include/linux/cacheinfo.h                    |  2 +-
 include/linux/cgroup.h                       |  1 -
 include/linux/clockchips.h                   |  2 +-
 include/linux/cpu.h                          |  1 -
 include/linux/cpu_cooling.h                  |  1 -
 include/linux/cpu_rmap.h                     |  2 +-
 include/linux/cpumask.h                      | 56 +----------------
 include/linux/cpumask_types.h                | 66 ++++++++++++++++++++
 include/linux/interrupt.h                    |  2 +-
 include/linux/irqchip/irq-partition-percpu.h |  2 +-
 include/linux/kernel_stat.h                  |  1 -
 include/linux/msi.h                          |  2 +-
 include/linux/node.h                         |  1 -
 include/linux/percpu.h                       |  1 -
 include/linux/pm_domain.h                    |  2 +-
 include/linux/profile.h                      |  1 -
 include/linux/rcupdate.h                     |  1 -
 include/linux/sched.h                        |  7 ++-
 include/linux/seq_file.h                     |  1 -
 include/linux/stop_machine.h                 |  2 +-
 include/linux/torture.h                      |  2 +-
 include/linux/tracepoint.h                   |  1 -
 include/linux/workqueue.h                    |  2 +-
 24 files changed, 83 insertions(+), 78 deletions(-)
 create mode 100644 include/linux/cpumask_types.h
Signature · 1 line
2.40.1
author maintainer
#1 lore raw

PATCH 1/6 MAINTAINERS: add linux/nodemask_types.h to BITMAP API

Commit bea32141764b ("nodemask: Split out include/linux/nodemask_types.h") added the nodemask_types.h but didn't cover it with corresponding record in the MAINTAINERS file.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index d6c90161c7bf..6ae73aaee305 100644
@@ -3733,6 +3733,7 @@ F:	include/linux/bits.h
 F:	include/linux/cpumask.h
 F:	include/linux/find.h
 F:	include/linux/nodemask.h
+F:	include/linux/nodemask_types.h
 F:	include/vdso/bits.h
 F:	lib/bitmap-str.c
 F:	lib/bitmap.c
Signature · 1 line
2.40.1
author maintainer
#2 lore raw

PATCH 2/6 sched: avoid using ilog2() in sched.h

In reply to Yury Norov

<linux/sched.h> indirectly via cpumask.h path includes the ilog2.h header to calculate ilog2(TASK_REPORT_MAX). The following patches drops sched.h dependency on cpumask.h, and to have a successful build, the header has to be included explicitly.

sched.h is a frequently included header, and it's better to keep the dependency list as small as possible. So, instead of including ilog2.h for a single BUILD_BUG_ON() check, the same check may be implemented by taking exponent of the other part of equation.

---
 include/linux/sched.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sched.h +1 -1
index 61591ac6eab6..98abb07de149 100644
@@ -1604,7 +1604,7 @@ static inline char task_index_to_char(unsigned int state)
 {
 	static const char state_char[] = "RSDTtXZPI";
 
-	BUILD_BUG_ON(1 + ilog2(TASK_REPORT_MAX) != sizeof(state_char) - 1);
+	BUILD_BUG_ON(TASK_REPORT_MAX * 2 != 1 << (sizeof(state_char) - 1));
 
 	return state_char[state];
 }
Signature · 1 line
2.40.1
author maintainer
#3 lore raw

PATCH 3/6 cpumask: split out include/linux/cpumask_types.h

In reply to Yury Norov

From: Yury Norov <[email protected]>

Many core headers, like sched.h, include cpumask.h mostly for struct cpumask and cpumask_var_t. Those are frequently used headers and shouldn't pull more than the bare minimum.

---
 MAINTAINERS                   |  1 +
 include/linux/cpumask.h       | 56 +----------------------------
 include/linux/cpumask_types.h | 66 +++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 55 deletions(-)
 create mode 100644 include/linux/cpumask_types.h
MAINTAINERS +1 -0
index 6ae73aaee305..c4fa8f264156 100644
@@ -3731,6 +3731,7 @@ F:	include/linux/bitmap-str.h
 F:	include/linux/bitmap.h
 F:	include/linux/bits.h
 F:	include/linux/cpumask.h
+F:	include/linux/cpumask_types.h
 F:	include/linux/find.h
 F:	include/linux/nodemask.h
 F:	include/linux/nodemask_types.h
include/linux/cpumask.h +1 -55

81 lines not on this page · raw message

include/linux/cpumask_types.h new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.40.1
author maintainer
#4 lore raw

PATCH 4/6 sched: drop sched.h dependency on cpumask

In reply to Yury Norov

sched.h needs cpumask.h mostly for types declaration. Now that we have cpumask_types.h, which is a significantly smaller header, we can rely on it.

The only exception is UP stub for set_cpus_allowed_ptr(). The function needs to test bit #0 in a @new_mask, which can be trivially opencoded.

---
 include/linux/sched.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
include/linux/sched.h +3 -2
index 98abb07de149..f2f907ef1389 100644
@@ -13,7 +13,7 @@
 #include <asm/processor.h>
 #include <linux/thread_info.h>
 #include <linux/preempt.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 
 #include <linux/cache.h>
 #include <linux/irqflags_types.h>
@@ -1778,7 +1778,8 @@ static inline void do_set_cpus_allowed(struct task_struct *p, const struct cpuma
 }
 static inline int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask)
 {
-	if (!cpumask_test_cpu(0, new_mask))
+	/* Opencoded cpumask_test_cpu(0, new_mask) to avoid dependency on cpumask.h */
+	if ((*cpumask_bits(new_mask) & 1) == 0)
 		return -EINVAL;
 	return 0;
 }
Signature · 1 line
2.40.1
author maintainer
#5 lore raw

PATCH 5/6 cpumask: cleanup core headers inclusion

In reply to Yury Norov

Many core headers include cpumask.h for nothing. Drop it.

---
 include/linux/cgroup.h      | 1 -
 include/linux/cpu.h         | 1 -
 include/linux/cpu_cooling.h | 1 -
 include/linux/kernel_stat.h | 1 -
 include/linux/node.h        | 1 -
 include/linux/percpu.h      | 1 -
 include/linux/profile.h     | 1 -
 include/linux/rcupdate.h    | 1 -
 include/linux/seq_file.h    | 1 -
 include/linux/tracepoint.h  | 1 -
 10 files changed, 10 deletions(-)
include/linux/cgroup.h +0 -1
index 2150ca60394b..c60ba0ab1462 100644
@@ -10,7 +10,6 @@
  */
 
 #include <linux/sched.h>
-#include <linux/cpumask.h>
 #include <linux/nodemask.h>
 #include <linux/rculist.h>
 #include <linux/cgroupstats.h>
include/linux/cpu.h +0 -1
index 861c3bfc5f17..ea6ac8f98e4a 100644
@@ -16,7 +16,6 @@
 
 #include <linux/node.h>
 #include <linux/compiler.h>
-#include <linux/cpumask.h>
 #include <linux/cpuhotplug.h>
 #include <linux/cpu_smt.h>
 
include/linux/cpu_cooling.h +0 -1
index a3bdc8a98f2c..2c774fb3c091 100644
@@ -15,7 +15,6 @@
 
 #include <linux/of.h>
 #include <linux/thermal.h>
-#include <linux/cpumask.h>
 
 struct cpufreq_policy;
 
include/linux/kernel_stat.h +0 -1
index 9c042c6384bb..b97ce2df376f 100644
@@ -5,7 +5,6 @@
 #include <linux/smp.h>
 #include <linux/threads.h>
 #include <linux/percpu.h>
-#include <linux/cpumask.h>
 #include <linux/interrupt.h>
 #include <linux/sched.h>
 #include <linux/vtime.h>
include/linux/node.h +0 -1
index dfc004e4bee7..9a881c2208b3 100644
@@ -16,7 +16,6 @@
 #define _LINUX_NODE_H_
 
 #include <linux/device.h>
-#include <linux/cpumask.h>
 #include <linux/list.h>
 
 /**
include/linux/percpu.h +0 -1
index 03053de557cf..4b2047b78b67 100644
@@ -6,7 +6,6 @@
 #include <linux/mmdebug.h>
 #include <linux/preempt.h>
 #include <linux/smp.h>
-#include <linux/cpumask.h>
 #include <linux/pfn.h>
 #include <linux/init.h>
 #include <linux/cleanup.h>
include/linux/profile.h +0 -1
index 04ae5ebcb637..2fb487f61d12 100644
@@ -4,7 +4,6 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/cpumask.h>
 #include <linux/cache.h>
 
 #include <asm/errno.h>
include/linux/rcupdate.h +0 -1
index dfd2399f2cde..fb8ab4618d63 100644
@@ -29,7 +29,6 @@
 #include <linux/lockdep.h>
 #include <linux/cleanup.h>
 #include <asm/processor.h>
-#include <linux/cpumask.h>
 #include <linux/context_tracking_irq.h>
 
 #define ULONG_CMP_GE(a, b)	(ULONG_MAX / 2 >= (a) - (b))
include/linux/seq_file.h +0 -1
index 8bd4fda6e027..2fb266ea69fa 100644
@@ -7,7 +7,6 @@
 #include <linux/string_helpers.h>
 #include <linux/bug.h>
 #include <linux/mutex.h>
-#include <linux/cpumask.h>
 #include <linux/nodemask.h>
 #include <linux/fs.h>
 #include <linux/cred.h>
include/linux/tracepoint.h +0 -1
index 689b6d71590e..6be396bb4297 100644
@@ -16,7 +16,6 @@
 #include <linux/srcu.h>
 #include <linux/errno.h>
 #include <linux/types.h>
-#include <linux/cpumask.h>
 #include <linux/rcupdate.h>
 #include <linux/tracepoint-defs.h>
 #include <linux/static_call.h>
Signature · 1 line
2.40.1
author maintainer
#6 lore raw

PATCH 6/6 cpumask: make core headers including cpumask_types.h where possible

In reply to Yury Norov

Now that cpumask types are split out to a separate smaller header, many frequently included core headers may switch to using it.

---
 include/linux/cacheinfo.h                    | 2 +-
 include/linux/clockchips.h                   | 2 +-
 include/linux/cpu_rmap.h                     | 2 +-
 include/linux/interrupt.h                    | 2 +-
 include/linux/irqchip/irq-partition-percpu.h | 2 +-
 include/linux/msi.h                          | 2 +-
 include/linux/pm_domain.h                    | 2 +-
 include/linux/stop_machine.h                 | 2 +-
 include/linux/torture.h                      | 2 +-
 include/linux/workqueue.h                    | 2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)
include/linux/cacheinfo.h +1 -1
index 2cb15fe4fe12..286db104e054 100644
@@ -3,7 +3,7 @@
 #define _LINUX_CACHEINFO_H
 
 #include <linux/bitops.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/smp.h>
 
 struct device_node;
include/linux/clockchips.h +1 -1
index 9aac31d856f3..b0df28ddd394 100644
@@ -12,7 +12,7 @@
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 # include <linux/clocksource.h>
-# include <linux/cpumask.h>
+# include <linux/cpumask_types.h>
 # include <linux/ktime.h>
 # include <linux/notifier.h>
 
include/linux/cpu_rmap.h +1 -1
index cae324d10965..20b5729903d7 100644
@@ -7,7 +7,7 @@
  * Copyright 2011 Solarflare Communications Inc.
  */
 
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/gfp.h>
 #include <linux/slab.h>
 #include <linux/kref.h>
include/linux/interrupt.h +1 -1
index 5c9bdd3ffccc..da88261f4748 100644
@@ -5,7 +5,7 @@
 
 #include <linux/kernel.h>
 #include <linux/bitops.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/irqreturn.h>
 #include <linux/irqnr.h>
 #include <linux/hardirq.h>
include/linux/irqchip/irq-partition-percpu.h +1 -1
index 2f6ae7551748..b35ee22c278f 100644
@@ -8,7 +8,7 @@
 #define __LINUX_IRQCHIP_IRQ_PARTITION_PERCPU_H
 
 #include <linux/fwnode.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/irqdomain.h>
 
 struct partition_affinity {
include/linux/msi.h +1 -1
index dc27cf3903d5..26588da88bdd 100644
@@ -19,7 +19,7 @@
  */
 
 #include <linux/irqdomain_defs.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/msi_api.h>
 #include <linux/xarray.h>
 #include <linux/mutex.h>
include/linux/pm_domain.h +1 -1
index f24546a3d3db..71e4f0fb8867 100644
@@ -16,7 +16,7 @@
 #include <linux/of.h>
 #include <linux/notifier.h>
 #include <linux/spinlock.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/time64.h>
 
 /*
include/linux/stop_machine.h +1 -1
index ea7a74ea7389..3132262a404d 100644
@@ -3,7 +3,7 @@
 #define _LINUX_STOP_MACHINE
 
 #include <linux/cpu.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/smp.h>
 #include <linux/list.h>
 
include/linux/torture.h +1 -1
index 1541454da03e..c2e979f82f8d 100644
@@ -14,7 +14,7 @@
 #include <linux/cache.h>
 #include <linux/spinlock.h>
 #include <linux/threads.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/seqlock.h>
 #include <linux/lockdep.h>
 #include <linux/completion.h>
include/linux/workqueue.h +1 -1
index fb3993894536..52496f07fba5 100644
@@ -12,7 +12,7 @@
 #include <linux/lockdep.h>
 #include <linux/threads.h>
 #include <linux/atomic.h>
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 #include <linux/rcupdate.h>
 #include <linux/workqueue_types.h>
 
Signature · 1 line
2.40.1