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

cpumask: split out include/linux/cpumask_types.h

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.

Link: https://lkml.kernel.org/r/20240528005648.182376-4-yury.norov@gmail.com
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Cc: Amit Daniel Kachhap <amit.kachhap@gmail.com>
Cc: Anna-Maria Behnsen <anna-maria@linutronix.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Yury Norov and committed by
Andrew Morton
eb4faa36 7c45d828

+68 -55
+1
MAINTAINERS
··· 3730 3730 F: include/linux/bitmap.h 3731 3731 F: include/linux/bits.h 3732 3732 F: include/linux/cpumask.h 3733 + F: include/linux/cpumask_types.h 3733 3734 F: include/linux/find.h 3734 3735 F: include/linux/nodemask.h 3735 3736 F: include/linux/nodemask_types.h
+1 -55
include/linux/cpumask.h
··· 9 9 */ 10 10 #include <linux/cleanup.h> 11 11 #include <linux/kernel.h> 12 - #include <linux/threads.h> 13 12 #include <linux/bitmap.h> 13 + #include <linux/cpumask_types.h> 14 14 #include <linux/atomic.h> 15 15 #include <linux/bug.h> 16 16 #include <linux/gfp_types.h> 17 17 #include <linux/numa.h> 18 - 19 - /* Don't assign or return these: may not be this big! */ 20 - typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; 21 - 22 - /** 23 - * cpumask_bits - get the bits in a cpumask 24 - * @maskp: the struct cpumask * 25 - * 26 - * You should only assume nr_cpu_ids bits of this mask are valid. This is 27 - * a macro so it's const-correct. 28 - */ 29 - #define cpumask_bits(maskp) ((maskp)->bits) 30 18 31 19 /** 32 20 * cpumask_pr_args - printf args to output a cpumask ··· 910 922 return bitmap_size(large_cpumask_bits); 911 923 } 912 924 913 - /* 914 - * cpumask_var_t: struct cpumask for stack usage. 915 - * 916 - * Oh, the wicked games we play! In order to make kernel coding a 917 - * little more difficult, we typedef cpumask_var_t to an array or a 918 - * pointer: doing &mask on an array is a noop, so it still works. 919 - * 920 - * i.e. 921 - * cpumask_var_t tmpmask; 922 - * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) 923 - * return -ENOMEM; 924 - * 925 - * ... use 'tmpmask' like a normal struct cpumask * ... 926 - * 927 - * free_cpumask_var(tmpmask); 928 - * 929 - * 930 - * However, one notable exception is there. alloc_cpumask_var() allocates 931 - * only nr_cpumask_bits bits (in the other hand, real cpumask_t always has 932 - * NR_CPUS bits). Therefore you don't have to dereference cpumask_var_t. 933 - * 934 - * cpumask_var_t tmpmask; 935 - * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) 936 - * return -ENOMEM; 937 - * 938 - * var = *tmpmask; 939 - * 940 - * This code makes NR_CPUS length memcopy and brings to a memory corruption. 941 - * cpumask_copy() provide safe copy functionality. 942 - * 943 - * Note that there is another evil here: If you define a cpumask_var_t 944 - * as a percpu variable then the way to obtain the address of the cpumask 945 - * structure differently influences what this_cpu_* operation needs to be 946 - * used. Please use this_cpu_cpumask_var_t in those cases. The direct use 947 - * of this_cpu_ptr() or this_cpu_read() will lead to failures when the 948 - * other type of cpumask_var_t implementation is configured. 949 - * 950 - * Please also note that __cpumask_var_read_mostly can be used to declare 951 - * a cpumask_var_t variable itself (not its content) as read mostly. 952 - */ 953 925 #ifdef CONFIG_CPUMASK_OFFSTACK 954 - typedef struct cpumask *cpumask_var_t; 955 926 956 927 #define this_cpu_cpumask_var_ptr(x) this_cpu_read(x) 957 928 #define __cpumask_var_read_mostly __read_mostly ··· 957 1010 } 958 1011 959 1012 #else 960 - typedef struct cpumask cpumask_var_t[1]; 961 1013 962 1014 #define this_cpu_cpumask_var_ptr(x) this_cpu_ptr(x) 963 1015 #define __cpumask_var_read_mostly
+66
include/linux/cpumask_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __LINUX_CPUMASK_TYPES_H 3 + #define __LINUX_CPUMASK_TYPES_H 4 + 5 + #include <linux/bitops.h> 6 + #include <linux/threads.h> 7 + 8 + /* Don't assign or return these: may not be this big! */ 9 + typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t; 10 + 11 + /** 12 + * cpumask_bits - get the bits in a cpumask 13 + * @maskp: the struct cpumask * 14 + * 15 + * You should only assume nr_cpu_ids bits of this mask are valid. This is 16 + * a macro so it's const-correct. 17 + */ 18 + #define cpumask_bits(maskp) ((maskp)->bits) 19 + 20 + /* 21 + * cpumask_var_t: struct cpumask for stack usage. 22 + * 23 + * Oh, the wicked games we play! In order to make kernel coding a 24 + * little more difficult, we typedef cpumask_var_t to an array or a 25 + * pointer: doing &mask on an array is a noop, so it still works. 26 + * 27 + * i.e. 28 + * cpumask_var_t tmpmask; 29 + * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) 30 + * return -ENOMEM; 31 + * 32 + * ... use 'tmpmask' like a normal struct cpumask * ... 33 + * 34 + * free_cpumask_var(tmpmask); 35 + * 36 + * 37 + * However, one notable exception is there. alloc_cpumask_var() allocates 38 + * only nr_cpumask_bits bits (in the other hand, real cpumask_t always has 39 + * NR_CPUS bits). Therefore you don't have to dereference cpumask_var_t. 40 + * 41 + * cpumask_var_t tmpmask; 42 + * if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) 43 + * return -ENOMEM; 44 + * 45 + * var = *tmpmask; 46 + * 47 + * This code makes NR_CPUS length memcopy and brings to a memory corruption. 48 + * cpumask_copy() provide safe copy functionality. 49 + * 50 + * Note that there is another evil here: If you define a cpumask_var_t 51 + * as a percpu variable then the way to obtain the address of the cpumask 52 + * structure differently influences what this_cpu_* operation needs to be 53 + * used. Please use this_cpu_cpumask_var_t in those cases. The direct use 54 + * of this_cpu_ptr() or this_cpu_read() will lead to failures when the 55 + * other type of cpumask_var_t implementation is configured. 56 + * 57 + * Please also note that __cpumask_var_read_mostly can be used to declare 58 + * a cpumask_var_t variable itself (not its content) as read mostly. 59 + */ 60 + #ifdef CONFIG_CPUMASK_OFFSTACK 61 + typedef struct cpumask *cpumask_var_t; 62 + #else 63 + typedef struct cpumask cpumask_var_t[1]; 64 + #endif /* CONFIG_CPUMASK_OFFSTACK */ 65 + 66 + #endif /* __LINUX_CPUMASK_TYPES_H */