linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection
@ 2015-10-06 15:21 Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-06 15:21 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner
  Cc: Michael Ellerman, Rasmus Villemoes, linuxppc-dev, linux-kernel

v2: fix build failure on ppc, add acks.

The four cpumasks cpu_{possible,online,present,active}_bits are
exposed readonly via the corresponding const variables
cpu_xyz_mask. But they are also accessible for arbitrary writing via
the exposed functions set_cpu_xyz. There's quite a bit of code
throughout the kernel which iterates over or otherwise accesses these
bitmaps, and having the access go via the cpu_xyz_mask variables is
nowadays [1] simply a useless indirection.

It may be that any problem in CS can be solved by an extra level of
indirection, but that doesn't mean every extra indirection solves a
problem. In this case, it even necessitates some minor ugliness (see
4/6).

Patch 1/6 is new in v2, and fixes a build failure on ppc by renaming a
struct member, to avoid problems when the identifier cpu_online_mask
becomes a macro later in the series. The next four patches eliminate
the cpu_xyz_mask variables by simply exposing the actual bitmaps,
after renaming them to discourage direct access - that still happens
through cpu_xyz_mask, which are now simply macros with the same type
and value as they used to have.

After that, there's no longer any reason to have the setter functions
be out-of-line: The boolean parameter is almost always a literal true
or false, so by making them static inlines they will usually compile
to one or two instructions.

For a defconfig build on x86_64, bloat-o-meter says we save ~3000
bytes. We also save a little stack (stackdelta says 127 functions have
a 16 byte smaller stack frame, while two grow by that amount). Mostly
because, when iterating over the mask, gcc typically loads the value
of cpu_xyz_mask into a callee-saved register and from there into %rdi
before each find_next_bit call - now it can just load the appropriate
immediate address into %rdi before each call.

[1] See Rusty's kind explanation
http://thread.gmane.org/gmane.linux.kernel/2047078/focus=2047722 for
some historic context.

Rasmus Villemoes (6):
  powerpc/fadump: rename cpu_online_mask member of struct
    fadump_crash_info_header
  kernel/cpu.c: change type of cpu_possible_bits and friends
  kernel/cpu.c: export __cpu_*_mask
  drivers/base/cpu.c: use __cpu_*_mask directly
  kernel/cpu.c: eliminate cpu_*_mask
  kernel/cpu.c: make set_cpu_* static inlines

 arch/powerpc/include/asm/fadump.h |  2 +-
 arch/powerpc/kernel/fadump.c      |  4 +--
 drivers/base/cpu.c                | 10 +++---
 include/linux/cpumask.h           | 55 ++++++++++++++++++++++++++++-----
 kernel/cpu.c                      | 64 ++++++++-------------------------------
 5 files changed, 68 insertions(+), 67 deletions(-)

-- 
2.1.3


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
@ 2015-10-06 15:21 ` Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends Rasmus Villemoes
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-06 15:21 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner
  Cc: Michael Ellerman, Rasmus Villemoes, linuxppc-dev, linux-kernel

As preparation for eliminating the indirect access to the various
global cpu_*_bits bitmaps via the pointer variables cpu_*_mask, rename
the cpu_online_mask member of struct fadump_crash_info_header to
simply online_mask, thus allowing cpu_online_mask to become a macro.

Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 arch/powerpc/include/asm/fadump.h | 2 +-
 arch/powerpc/kernel/fadump.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/fadump.h b/arch/powerpc/include/asm/fadump.h
index 493e72f64b35..b4407d0add27 100644
--- a/arch/powerpc/include/asm/fadump.h
+++ b/arch/powerpc/include/asm/fadump.h
@@ -191,7 +191,7 @@ struct fadump_crash_info_header {
 	u64		elfcorehdr_addr;
 	u32		crashing_cpu;
 	struct pt_regs	regs;
-	struct cpumask	cpu_online_mask;
+	struct cpumask	online_mask;
 };
 
 /* Crash memory ranges */
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 26d091a1a54c..3cb3b02a13dd 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -415,7 +415,7 @@ void crash_fadump(struct pt_regs *regs, const char *str)
 	else
 		ppc_save_regs(&fdh->regs);
 
-	fdh->cpu_online_mask = *cpu_online_mask;
+	fdh->online_mask = *cpu_online_mask;
 
 	/* Call ibm,os-term rtas call to trigger firmware assisted dump */
 	rtas_os_term((char *)str);
@@ -646,7 +646,7 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
 		}
 		/* Lower 4 bytes of reg_value contains logical cpu id */
 		cpu = be64_to_cpu(reg_entry->reg_value) & FADUMP_CPU_ID_MASK;
-		if (fdh && !cpumask_test_cpu(cpu, &fdh->cpu_online_mask)) {
+		if (fdh && !cpumask_test_cpu(cpu, &fdh->online_mask)) {
 			SKIP_TO_NEXT_CPU(reg_entry);
 			continue;
 		}
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
@ 2015-10-06 15:21 ` Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 3/6] kernel/cpu.c: export __cpu_*_mask Rasmus Villemoes
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-06 15:21 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Change cpu_possible_bits and friends (online, present, active) from
being bitmaps that happen to have the right size to actually being
struct cpumasks. Also rename them to __cpu_xyz_mask. This is mostly a
small cleanup in preparation for exporting them and, eventually,
eliminating the extra indirection through the cpu_xyz_mask variables.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 kernel/cpu.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 82cf9dff4295..fea4a3ce3011 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -772,71 +772,71 @@ const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
 EXPORT_SYMBOL(cpu_all_bits);
 
 #ifdef CONFIG_INIT_ALL_POSSIBLE
-static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly
-	= CPU_BITS_ALL;
+static struct cpumask __cpu_possible_mask __read_mostly
+	= {CPU_BITS_ALL};
 #else
-static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly;
+static struct cpumask __cpu_possible_mask __read_mostly;
 #endif
-const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits);
+const struct cpumask *const cpu_possible_mask = &__cpu_possible_mask;
 EXPORT_SYMBOL(cpu_possible_mask);
 
-static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly;
-const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits);
+static struct cpumask __cpu_online_mask __read_mostly;
+const struct cpumask *const cpu_online_mask = &__cpu_online_mask;
 EXPORT_SYMBOL(cpu_online_mask);
 
-static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly;
-const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits);
+static struct cpumask __cpu_present_mask __read_mostly;
+const struct cpumask *const cpu_present_mask = &__cpu_present_mask;
 EXPORT_SYMBOL(cpu_present_mask);
 
-static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly;
-const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits);
+static struct cpumask __cpu_active_mask __read_mostly;
+const struct cpumask *const cpu_active_mask = &__cpu_active_mask;
 EXPORT_SYMBOL(cpu_active_mask);
 
 void set_cpu_possible(unsigned int cpu, bool possible)
 {
 	if (possible)
-		cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits));
+		cpumask_set_cpu(cpu, &__cpu_possible_mask);
 	else
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits));
+		cpumask_clear_cpu(cpu, &__cpu_possible_mask);
 }
 
 void set_cpu_present(unsigned int cpu, bool present)
 {
 	if (present)
-		cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits));
+		cpumask_set_cpu(cpu, &__cpu_present_mask);
 	else
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits));
+		cpumask_clear_cpu(cpu, &__cpu_present_mask);
 }
 
 void set_cpu_online(unsigned int cpu, bool online)
 {
 	if (online) {
-		cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits));
-		cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits));
+		cpumask_set_cpu(cpu, &__cpu_online_mask);
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
 	} else {
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits));
+		cpumask_clear_cpu(cpu, &__cpu_online_mask);
 	}
 }
 
 void set_cpu_active(unsigned int cpu, bool active)
 {
 	if (active)
-		cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits));
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
 	else
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits));
+		cpumask_clear_cpu(cpu, &__cpu_active_mask);
 }
 
 void init_cpu_present(const struct cpumask *src)
 {
-	cpumask_copy(to_cpumask(cpu_present_bits), src);
+	cpumask_copy(&__cpu_present_mask, src);
 }
 
 void init_cpu_possible(const struct cpumask *src)
 {
-	cpumask_copy(to_cpumask(cpu_possible_bits), src);
+	cpumask_copy(&__cpu_possible_mask, src);
 }
 
 void init_cpu_online(const struct cpumask *src)
 {
-	cpumask_copy(to_cpumask(cpu_online_bits), src);
+	cpumask_copy(&__cpu_online_mask, src);
 }
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 3/6] kernel/cpu.c: export __cpu_*_mask
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends Rasmus Villemoes
@ 2015-10-06 15:21 ` Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 4/6] drivers/base/cpu.c: use __cpu_*_mask directly Rasmus Villemoes
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-06 15:21 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Exporting the cpumasks __cpu_possible_mask and friends will allow us
to remove the extra indirection through the cpu_*_mask variables. It
will also allow the set_cpu_* functions to become static inlines,
which will give a .text reduction.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/cpumask.h |  4 ++++
 kernel/cpu.c            | 14 +++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 59915ea5373c..d4545a1852f2 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -89,6 +89,10 @@ extern const struct cpumask *const cpu_possible_mask;
 extern const struct cpumask *const cpu_online_mask;
 extern const struct cpumask *const cpu_present_mask;
 extern const struct cpumask *const cpu_active_mask;
+extern struct cpumask __cpu_possible_mask;
+extern struct cpumask __cpu_online_mask;
+extern struct cpumask __cpu_present_mask;
+extern struct cpumask __cpu_active_mask;
 
 #if NR_CPUS > 1
 #define num_online_cpus()	cpumask_weight(cpu_online_mask)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index fea4a3ce3011..e08db26d351b 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -772,23 +772,27 @@ const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
 EXPORT_SYMBOL(cpu_all_bits);
 
 #ifdef CONFIG_INIT_ALL_POSSIBLE
-static struct cpumask __cpu_possible_mask __read_mostly
+struct cpumask __cpu_possible_mask __read_mostly
 	= {CPU_BITS_ALL};
 #else
-static struct cpumask __cpu_possible_mask __read_mostly;
+struct cpumask __cpu_possible_mask __read_mostly;
 #endif
+EXPORT_SYMBOL(__cpu_possible_mask);
 const struct cpumask *const cpu_possible_mask = &__cpu_possible_mask;
 EXPORT_SYMBOL(cpu_possible_mask);
 
-static struct cpumask __cpu_online_mask __read_mostly;
+struct cpumask __cpu_online_mask __read_mostly;
+EXPORT_SYMBOL(__cpu_online_mask);
 const struct cpumask *const cpu_online_mask = &__cpu_online_mask;
 EXPORT_SYMBOL(cpu_online_mask);
 
-static struct cpumask __cpu_present_mask __read_mostly;
+struct cpumask __cpu_present_mask __read_mostly;
+EXPORT_SYMBOL(__cpu_present_mask);
 const struct cpumask *const cpu_present_mask = &__cpu_present_mask;
 EXPORT_SYMBOL(cpu_present_mask);
 
-static struct cpumask __cpu_active_mask __read_mostly;
+struct cpumask __cpu_active_mask __read_mostly;
+EXPORT_SYMBOL(__cpu_active_mask);
 const struct cpumask *const cpu_active_mask = &__cpu_active_mask;
 EXPORT_SYMBOL(cpu_active_mask);
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 4/6] drivers/base/cpu.c: use __cpu_*_mask directly
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
                   ` (2 preceding siblings ...)
  2015-10-06 15:21 ` [PATCH v2 3/6] kernel/cpu.c: export __cpu_*_mask Rasmus Villemoes
@ 2015-10-06 15:21 ` Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 5/6] kernel/cpu.c: eliminate cpu_*_mask Rasmus Villemoes
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-06 15:21 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

The only user of the lvalue-ness of the cpu_*_mask variables is in
drivers/base/cpu.c, and that is mostly a work-around for the fact that
not even const variables can be used in static initialization. Now
that the underlying struct cpumasks are exposed we can take their
address.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/base/cpu.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 91bbb1959d8d..691eeea2f19a 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -200,7 +200,7 @@ static const struct attribute_group *hotplugable_cpu_attr_groups[] = {
 
 struct cpu_attr {
 	struct device_attribute attr;
-	const struct cpumask *const * const map;
+	const struct cpumask *const map;
 };
 
 static ssize_t show_cpus_attr(struct device *dev,
@@ -209,7 +209,7 @@ static ssize_t show_cpus_attr(struct device *dev,
 {
 	struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr);
 
-	return cpumap_print_to_pagebuf(true, buf, *ca->map);
+	return cpumap_print_to_pagebuf(true, buf, ca->map);
 }
 
 #define _CPU_ATTR(name, map) \
@@ -217,9 +217,9 @@ static ssize_t show_cpus_attr(struct device *dev,
 
 /* Keep in sync with cpu_subsys_attrs */
 static struct cpu_attr cpu_attrs[] = {
-	_CPU_ATTR(online, &cpu_online_mask),
-	_CPU_ATTR(possible, &cpu_possible_mask),
-	_CPU_ATTR(present, &cpu_present_mask),
+	_CPU_ATTR(online, &__cpu_online_mask),
+	_CPU_ATTR(possible, &__cpu_possible_mask),
+	_CPU_ATTR(present, &__cpu_present_mask),
 };
 
 /*
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 5/6] kernel/cpu.c: eliminate cpu_*_mask
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
                   ` (3 preceding siblings ...)
  2015-10-06 15:21 ` [PATCH v2 4/6] drivers/base/cpu.c: use __cpu_*_mask directly Rasmus Villemoes
@ 2015-10-06 15:21 ` Rasmus Villemoes
  2015-10-06 15:21 ` [PATCH v2 6/6] kernel/cpu.c: make set_cpu_* static inlines Rasmus Villemoes
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-06 15:21 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Replace the variables cpu_possible_mask, cpu_online_mask,
cpu_present_mask and cpu_active_mask with macros expanding to
expressions of the same type and value, eliminating some indirection.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/cpumask.h | 8 ++++----
 kernel/cpu.c            | 8 --------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index d4545a1852f2..52ab539aefce 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -85,14 +85,14 @@ extern int nr_cpu_ids;
  *    only one CPU.
  */
 
-extern const struct cpumask *const cpu_possible_mask;
-extern const struct cpumask *const cpu_online_mask;
-extern const struct cpumask *const cpu_present_mask;
-extern const struct cpumask *const cpu_active_mask;
 extern struct cpumask __cpu_possible_mask;
 extern struct cpumask __cpu_online_mask;
 extern struct cpumask __cpu_present_mask;
 extern struct cpumask __cpu_active_mask;
+#define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask)
+#define cpu_online_mask   ((const struct cpumask *)&__cpu_online_mask)
+#define cpu_present_mask  ((const struct cpumask *)&__cpu_present_mask)
+#define cpu_active_mask   ((const struct cpumask *)&__cpu_active_mask)
 
 #if NR_CPUS > 1
 #define num_online_cpus()	cpumask_weight(cpu_online_mask)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index e08db26d351b..dd70f600442f 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -778,23 +778,15 @@ struct cpumask __cpu_possible_mask __read_mostly
 struct cpumask __cpu_possible_mask __read_mostly;
 #endif
 EXPORT_SYMBOL(__cpu_possible_mask);
-const struct cpumask *const cpu_possible_mask = &__cpu_possible_mask;
-EXPORT_SYMBOL(cpu_possible_mask);
 
 struct cpumask __cpu_online_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_online_mask);
-const struct cpumask *const cpu_online_mask = &__cpu_online_mask;
-EXPORT_SYMBOL(cpu_online_mask);
 
 struct cpumask __cpu_present_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_present_mask);
-const struct cpumask *const cpu_present_mask = &__cpu_present_mask;
-EXPORT_SYMBOL(cpu_present_mask);
 
 struct cpumask __cpu_active_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_active_mask);
-const struct cpumask *const cpu_active_mask = &__cpu_active_mask;
-EXPORT_SYMBOL(cpu_active_mask);
 
 void set_cpu_possible(unsigned int cpu, bool possible)
 {
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 6/6] kernel/cpu.c: make set_cpu_* static inlines
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
                   ` (4 preceding siblings ...)
  2015-10-06 15:21 ` [PATCH v2 5/6] kernel/cpu.c: eliminate cpu_*_mask Rasmus Villemoes
@ 2015-10-06 15:21 ` Rasmus Villemoes
  2015-10-17 22:07 ` [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
  7 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-06 15:21 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Almost all callers of the set_cpu_* functions pass an explicit true
or false. Making them static inline thus replaces the function calls
with a simple set_bit/clear_bit, saving some .text.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/cpumask.h | 43 +++++++++++++++++++++++++++++++++++++++----
 kernel/cpu.c            | 34 ----------------------------------
 2 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 52ab539aefce..fc14275ff34e 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -720,14 +720,49 @@ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
 #define for_each_present_cpu(cpu)  for_each_cpu((cpu), cpu_present_mask)
 
 /* Wrappers for arch boot code to manipulate normally-constant masks */
-void set_cpu_possible(unsigned int cpu, bool possible);
-void set_cpu_present(unsigned int cpu, bool present);
-void set_cpu_online(unsigned int cpu, bool online);
-void set_cpu_active(unsigned int cpu, bool active);
 void init_cpu_present(const struct cpumask *src);
 void init_cpu_possible(const struct cpumask *src);
 void init_cpu_online(const struct cpumask *src);
 
+static inline void
+set_cpu_possible(unsigned int cpu, bool possible)
+{
+	if (possible)
+		cpumask_set_cpu(cpu, &__cpu_possible_mask);
+	else
+		cpumask_clear_cpu(cpu, &__cpu_possible_mask);
+}
+
+static inline void
+set_cpu_present(unsigned int cpu, bool present)
+{
+	if (present)
+		cpumask_set_cpu(cpu, &__cpu_present_mask);
+	else
+		cpumask_clear_cpu(cpu, &__cpu_present_mask);
+}
+
+static inline void
+set_cpu_online(unsigned int cpu, bool online)
+{
+	if (online) {
+		cpumask_set_cpu(cpu, &__cpu_online_mask);
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
+	} else {
+		cpumask_clear_cpu(cpu, &__cpu_online_mask);
+	}
+}
+
+static inline void
+set_cpu_active(unsigned int cpu, bool active)
+{
+	if (active)
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
+	else
+		cpumask_clear_cpu(cpu, &__cpu_active_mask);
+}
+
+
 /**
  * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
  * @bitmap: the bitmap
diff --git a/kernel/cpu.c b/kernel/cpu.c
index dd70f600442f..5210d80efc28 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -788,40 +788,6 @@ EXPORT_SYMBOL(__cpu_present_mask);
 struct cpumask __cpu_active_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_active_mask);
 
-void set_cpu_possible(unsigned int cpu, bool possible)
-{
-	if (possible)
-		cpumask_set_cpu(cpu, &__cpu_possible_mask);
-	else
-		cpumask_clear_cpu(cpu, &__cpu_possible_mask);
-}
-
-void set_cpu_present(unsigned int cpu, bool present)
-{
-	if (present)
-		cpumask_set_cpu(cpu, &__cpu_present_mask);
-	else
-		cpumask_clear_cpu(cpu, &__cpu_present_mask);
-}
-
-void set_cpu_online(unsigned int cpu, bool online)
-{
-	if (online) {
-		cpumask_set_cpu(cpu, &__cpu_online_mask);
-		cpumask_set_cpu(cpu, &__cpu_active_mask);
-	} else {
-		cpumask_clear_cpu(cpu, &__cpu_online_mask);
-	}
-}
-
-void set_cpu_active(unsigned int cpu, bool active)
-{
-	if (active)
-		cpumask_set_cpu(cpu, &__cpu_active_mask);
-	else
-		cpumask_clear_cpu(cpu, &__cpu_active_mask);
-}
-
 void init_cpu_present(const struct cpumask *src)
 {
 	cpumask_copy(&__cpu_present_mask, src);
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
                   ` (5 preceding siblings ...)
  2015-10-06 15:21 ` [PATCH v2 6/6] kernel/cpu.c: make set_cpu_* static inlines Rasmus Villemoes
@ 2015-10-17 22:07 ` Rasmus Villemoes
  2015-10-18  1:41   ` Rusty Russell
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
  7 siblings, 1 reply; 16+ messages in thread
From: Rasmus Villemoes @ 2015-10-17 22:07 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner,
	Michael Ellerman, linuxppc-dev, linux-kernel

On Tue, Oct 06 2015, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:

> v2: fix build failure on ppc, add acks.

Does anyone want to take these through their tree?

Rasmus

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection
  2015-10-17 22:07 ` [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
@ 2015-10-18  1:41   ` Rusty Russell
  0 siblings, 0 replies; 16+ messages in thread
From: Rusty Russell @ 2015-10-18  1:41 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: Greg Kroah-Hartman, Oleg Nesterov, Thomas Gleixner,
	Michael Ellerman, linuxppc-dev, linux-kernel

Rasmus Villemoes <rv@rasmusvillemoes.dk> writes:
> On Tue, Oct 06 2015, Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:
>
>> v2: fix build failure on ppc, add acks.
>
> Does anyone want to take these through their tree?

I think the x86 tree is the least illogical place, unless akpm wants it?

Cheers,
Rusty.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2, resend 0/6] kernel/cpu.c: eliminate some indirection
  2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
                   ` (6 preceding siblings ...)
  2015-10-17 22:07 ` [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
@ 2015-11-23 19:51 ` Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
                     ` (5 more replies)
  7 siblings, 6 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-11-23 19:51 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov,
	Thomas Gleixner, Andrew Morton
  Cc: Michael Ellerman, Rasmus Villemoes, linuxppc-dev, linux-kernel

Andrew, can I get you to take these through -mm? Noone else seems to
want to pick them up. They're rebased on top of 4.4-rc2 (and applied
cleanly), but otherwise identical to what I've sent previously.

=====

v2: fix build failure on ppc, add acks.

The four cpumasks cpu_{possible,online,present,active}_bits are
exposed readonly via the corresponding const variables
cpu_xyz_mask. But they are also accessible for arbitrary writing via
the exposed functions set_cpu_xyz. There's quite a bit of code
throughout the kernel which iterates over or otherwise accesses these
bitmaps, and having the access go via the cpu_xyz_mask variables is
nowadays [1] simply a useless indirection.

It may be that any problem in CS can be solved by an extra level of
indirection, but that doesn't mean every extra indirection solves a
problem. In this case, it even necessitates some minor ugliness (see
4/6).

Patch 1/6 is new in v2, and fixes a build failure on ppc by renaming a
struct member, to avoid problems when the identifier cpu_online_mask
becomes a macro later in the series. The next four patches eliminate
the cpu_xyz_mask variables by simply exposing the actual bitmaps,
after renaming them to discourage direct access - that still happens
through cpu_xyz_mask, which are now simply macros with the same type
and value as they used to have.

After that, there's no longer any reason to have the setter functions
be out-of-line: The boolean parameter is almost always a literal true
or false, so by making them static inlines they will usually compile
to one or two instructions.

For a defconfig build on x86_64, bloat-o-meter says we save ~3000
bytes. We also save a little stack (stackdelta says 127 functions have
a 16 byte smaller stack frame, while two grow by that amount). Mostly
because, when iterating over the mask, gcc typically loads the value
of cpu_xyz_mask into a callee-saved register and from there into %rdi
before each find_next_bit call - now it can just load the appropriate
immediate address into %rdi before each call.

[1] See Rusty's kind explanation
http://thread.gmane.org/gmane.linux.kernel/2047078/focus=2047722 for
some historic context.

Rasmus Villemoes (6):
  powerpc/fadump: rename cpu_online_mask member of struct
    fadump_crash_info_header
  kernel/cpu.c: change type of cpu_possible_bits and friends
  kernel/cpu.c: export __cpu_*_mask
  drivers/base/cpu.c: use __cpu_*_mask directly
  kernel/cpu.c: eliminate cpu_*_mask
  kernel/cpu.c: make set_cpu_* static inlines

 arch/powerpc/include/asm/fadump.h |  2 +-
 arch/powerpc/kernel/fadump.c      |  4 +--
 drivers/base/cpu.c                | 10 +++---
 include/linux/cpumask.h           | 55 ++++++++++++++++++++++++++++-----
 kernel/cpu.c                      | 64 ++++++++-------------------------------
 5 files changed, 68 insertions(+), 67 deletions(-)

-- 
2.6.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2, resend 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
@ 2015-11-23 19:51   ` Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends Rasmus Villemoes
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-11-23 19:51 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov,
	Thomas Gleixner, Andrew Morton
  Cc: Michael Ellerman, Rasmus Villemoes, linuxppc-dev, linux-kernel

As preparation for eliminating the indirect access to the various
global cpu_*_bits bitmaps via the pointer variables cpu_*_mask, rename
the cpu_online_mask member of struct fadump_crash_info_header to
simply online_mask, thus allowing cpu_online_mask to become a macro.

Acked-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 arch/powerpc/include/asm/fadump.h | 2 +-
 arch/powerpc/kernel/fadump.c      | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/fadump.h b/arch/powerpc/include/asm/fadump.h
index 493e72f64b35..b4407d0add27 100644
--- a/arch/powerpc/include/asm/fadump.h
+++ b/arch/powerpc/include/asm/fadump.h
@@ -191,7 +191,7 @@ struct fadump_crash_info_header {
 	u64		elfcorehdr_addr;
 	u32		crashing_cpu;
 	struct pt_regs	regs;
-	struct cpumask	cpu_online_mask;
+	struct cpumask	online_mask;
 };
 
 /* Crash memory ranges */
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 26d091a1a54c..3cb3b02a13dd 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -415,7 +415,7 @@ void crash_fadump(struct pt_regs *regs, const char *str)
 	else
 		ppc_save_regs(&fdh->regs);
 
-	fdh->cpu_online_mask = *cpu_online_mask;
+	fdh->online_mask = *cpu_online_mask;
 
 	/* Call ibm,os-term rtas call to trigger firmware assisted dump */
 	rtas_os_term((char *)str);
@@ -646,7 +646,7 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
 		}
 		/* Lower 4 bytes of reg_value contains logical cpu id */
 		cpu = be64_to_cpu(reg_entry->reg_value) & FADUMP_CPU_ID_MASK;
-		if (fdh && !cpumask_test_cpu(cpu, &fdh->cpu_online_mask)) {
+		if (fdh && !cpumask_test_cpu(cpu, &fdh->online_mask)) {
 			SKIP_TO_NEXT_CPU(reg_entry);
 			continue;
 		}
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2, resend 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
@ 2015-11-23 19:51   ` Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 3/6] kernel/cpu.c: export __cpu_*_mask Rasmus Villemoes
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-11-23 19:51 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov,
	Thomas Gleixner, Andrew Morton
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Change cpu_possible_bits and friends (online, present, active) from
being bitmaps that happen to have the right size to actually being
struct cpumasks. Also rename them to __cpu_xyz_mask. This is mostly a
small cleanup in preparation for exporting them and, eventually,
eliminating the extra indirection through the cpu_xyz_mask variables.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 kernel/cpu.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 85ff5e26e23b..6a96b713cea7 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -759,71 +759,71 @@ const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
 EXPORT_SYMBOL(cpu_all_bits);
 
 #ifdef CONFIG_INIT_ALL_POSSIBLE
-static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly
-	= CPU_BITS_ALL;
+static struct cpumask __cpu_possible_mask __read_mostly
+	= {CPU_BITS_ALL};
 #else
-static DECLARE_BITMAP(cpu_possible_bits, CONFIG_NR_CPUS) __read_mostly;
+static struct cpumask __cpu_possible_mask __read_mostly;
 #endif
-const struct cpumask *const cpu_possible_mask = to_cpumask(cpu_possible_bits);
+const struct cpumask *const cpu_possible_mask = &__cpu_possible_mask;
 EXPORT_SYMBOL(cpu_possible_mask);
 
-static DECLARE_BITMAP(cpu_online_bits, CONFIG_NR_CPUS) __read_mostly;
-const struct cpumask *const cpu_online_mask = to_cpumask(cpu_online_bits);
+static struct cpumask __cpu_online_mask __read_mostly;
+const struct cpumask *const cpu_online_mask = &__cpu_online_mask;
 EXPORT_SYMBOL(cpu_online_mask);
 
-static DECLARE_BITMAP(cpu_present_bits, CONFIG_NR_CPUS) __read_mostly;
-const struct cpumask *const cpu_present_mask = to_cpumask(cpu_present_bits);
+static struct cpumask __cpu_present_mask __read_mostly;
+const struct cpumask *const cpu_present_mask = &__cpu_present_mask;
 EXPORT_SYMBOL(cpu_present_mask);
 
-static DECLARE_BITMAP(cpu_active_bits, CONFIG_NR_CPUS) __read_mostly;
-const struct cpumask *const cpu_active_mask = to_cpumask(cpu_active_bits);
+static struct cpumask __cpu_active_mask __read_mostly;
+const struct cpumask *const cpu_active_mask = &__cpu_active_mask;
 EXPORT_SYMBOL(cpu_active_mask);
 
 void set_cpu_possible(unsigned int cpu, bool possible)
 {
 	if (possible)
-		cpumask_set_cpu(cpu, to_cpumask(cpu_possible_bits));
+		cpumask_set_cpu(cpu, &__cpu_possible_mask);
 	else
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_possible_bits));
+		cpumask_clear_cpu(cpu, &__cpu_possible_mask);
 }
 
 void set_cpu_present(unsigned int cpu, bool present)
 {
 	if (present)
-		cpumask_set_cpu(cpu, to_cpumask(cpu_present_bits));
+		cpumask_set_cpu(cpu, &__cpu_present_mask);
 	else
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_present_bits));
+		cpumask_clear_cpu(cpu, &__cpu_present_mask);
 }
 
 void set_cpu_online(unsigned int cpu, bool online)
 {
 	if (online) {
-		cpumask_set_cpu(cpu, to_cpumask(cpu_online_bits));
-		cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits));
+		cpumask_set_cpu(cpu, &__cpu_online_mask);
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
 	} else {
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_online_bits));
+		cpumask_clear_cpu(cpu, &__cpu_online_mask);
 	}
 }
 
 void set_cpu_active(unsigned int cpu, bool active)
 {
 	if (active)
-		cpumask_set_cpu(cpu, to_cpumask(cpu_active_bits));
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
 	else
-		cpumask_clear_cpu(cpu, to_cpumask(cpu_active_bits));
+		cpumask_clear_cpu(cpu, &__cpu_active_mask);
 }
 
 void init_cpu_present(const struct cpumask *src)
 {
-	cpumask_copy(to_cpumask(cpu_present_bits), src);
+	cpumask_copy(&__cpu_present_mask, src);
 }
 
 void init_cpu_possible(const struct cpumask *src)
 {
-	cpumask_copy(to_cpumask(cpu_possible_bits), src);
+	cpumask_copy(&__cpu_possible_mask, src);
 }
 
 void init_cpu_online(const struct cpumask *src)
 {
-	cpumask_copy(to_cpumask(cpu_online_bits), src);
+	cpumask_copy(&__cpu_online_mask, src);
 }
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2, resend 3/6] kernel/cpu.c: export __cpu_*_mask
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends Rasmus Villemoes
@ 2015-11-23 19:51   ` Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 4/6] drivers/base/cpu.c: use __cpu_*_mask directly Rasmus Villemoes
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-11-23 19:51 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov,
	Thomas Gleixner, Andrew Morton
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Exporting the cpumasks __cpu_possible_mask and friends will allow us
to remove the extra indirection through the cpu_*_mask variables. It
will also allow the set_cpu_* functions to become static inlines,
which will give a .text reduction.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/cpumask.h |  4 ++++
 kernel/cpu.c            | 14 +++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 59915ea5373c..d4545a1852f2 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -89,6 +89,10 @@ extern const struct cpumask *const cpu_possible_mask;
 extern const struct cpumask *const cpu_online_mask;
 extern const struct cpumask *const cpu_present_mask;
 extern const struct cpumask *const cpu_active_mask;
+extern struct cpumask __cpu_possible_mask;
+extern struct cpumask __cpu_online_mask;
+extern struct cpumask __cpu_present_mask;
+extern struct cpumask __cpu_active_mask;
 
 #if NR_CPUS > 1
 #define num_online_cpus()	cpumask_weight(cpu_online_mask)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 6a96b713cea7..35d1d45be8e9 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -759,23 +759,27 @@ const DECLARE_BITMAP(cpu_all_bits, NR_CPUS) = CPU_BITS_ALL;
 EXPORT_SYMBOL(cpu_all_bits);
 
 #ifdef CONFIG_INIT_ALL_POSSIBLE
-static struct cpumask __cpu_possible_mask __read_mostly
+struct cpumask __cpu_possible_mask __read_mostly
 	= {CPU_BITS_ALL};
 #else
-static struct cpumask __cpu_possible_mask __read_mostly;
+struct cpumask __cpu_possible_mask __read_mostly;
 #endif
+EXPORT_SYMBOL(__cpu_possible_mask);
 const struct cpumask *const cpu_possible_mask = &__cpu_possible_mask;
 EXPORT_SYMBOL(cpu_possible_mask);
 
-static struct cpumask __cpu_online_mask __read_mostly;
+struct cpumask __cpu_online_mask __read_mostly;
+EXPORT_SYMBOL(__cpu_online_mask);
 const struct cpumask *const cpu_online_mask = &__cpu_online_mask;
 EXPORT_SYMBOL(cpu_online_mask);
 
-static struct cpumask __cpu_present_mask __read_mostly;
+struct cpumask __cpu_present_mask __read_mostly;
+EXPORT_SYMBOL(__cpu_present_mask);
 const struct cpumask *const cpu_present_mask = &__cpu_present_mask;
 EXPORT_SYMBOL(cpu_present_mask);
 
-static struct cpumask __cpu_active_mask __read_mostly;
+struct cpumask __cpu_active_mask __read_mostly;
+EXPORT_SYMBOL(__cpu_active_mask);
 const struct cpumask *const cpu_active_mask = &__cpu_active_mask;
 EXPORT_SYMBOL(cpu_active_mask);
 
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2, resend 4/6] drivers/base/cpu.c: use __cpu_*_mask directly
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
                     ` (2 preceding siblings ...)
  2015-11-23 19:51   ` [PATCH v2, resend 3/6] kernel/cpu.c: export __cpu_*_mask Rasmus Villemoes
@ 2015-11-23 19:51   ` Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 5/6] kernel/cpu.c: eliminate cpu_*_mask Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 6/6] kernel/cpu.c: make set_cpu_* static inlines Rasmus Villemoes
  5 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-11-23 19:51 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov,
	Thomas Gleixner, Andrew Morton
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

The only user of the lvalue-ness of the cpu_*_mask variables is in
drivers/base/cpu.c, and that is mostly a work-around for the fact that
not even const variables can be used in static initialization. Now
that the underlying struct cpumasks are exposed we can take their
address.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/base/cpu.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 91bbb1959d8d..691eeea2f19a 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -200,7 +200,7 @@ static const struct attribute_group *hotplugable_cpu_attr_groups[] = {
 
 struct cpu_attr {
 	struct device_attribute attr;
-	const struct cpumask *const * const map;
+	const struct cpumask *const map;
 };
 
 static ssize_t show_cpus_attr(struct device *dev,
@@ -209,7 +209,7 @@ static ssize_t show_cpus_attr(struct device *dev,
 {
 	struct cpu_attr *ca = container_of(attr, struct cpu_attr, attr);
 
-	return cpumap_print_to_pagebuf(true, buf, *ca->map);
+	return cpumap_print_to_pagebuf(true, buf, ca->map);
 }
 
 #define _CPU_ATTR(name, map) \
@@ -217,9 +217,9 @@ static ssize_t show_cpus_attr(struct device *dev,
 
 /* Keep in sync with cpu_subsys_attrs */
 static struct cpu_attr cpu_attrs[] = {
-	_CPU_ATTR(online, &cpu_online_mask),
-	_CPU_ATTR(possible, &cpu_possible_mask),
-	_CPU_ATTR(present, &cpu_present_mask),
+	_CPU_ATTR(online, &__cpu_online_mask),
+	_CPU_ATTR(possible, &__cpu_possible_mask),
+	_CPU_ATTR(present, &__cpu_present_mask),
 };
 
 /*
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2, resend 5/6] kernel/cpu.c: eliminate cpu_*_mask
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
                     ` (3 preceding siblings ...)
  2015-11-23 19:51   ` [PATCH v2, resend 4/6] drivers/base/cpu.c: use __cpu_*_mask directly Rasmus Villemoes
@ 2015-11-23 19:51   ` Rasmus Villemoes
  2015-11-23 19:51   ` [PATCH v2, resend 6/6] kernel/cpu.c: make set_cpu_* static inlines Rasmus Villemoes
  5 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-11-23 19:51 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov,
	Thomas Gleixner, Andrew Morton
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Replace the variables cpu_possible_mask, cpu_online_mask,
cpu_present_mask and cpu_active_mask with macros expanding to
expressions of the same type and value, eliminating some indirection.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/cpumask.h | 8 ++++----
 kernel/cpu.c            | 8 --------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index d4545a1852f2..52ab539aefce 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -85,14 +85,14 @@ extern int nr_cpu_ids;
  *    only one CPU.
  */
 
-extern const struct cpumask *const cpu_possible_mask;
-extern const struct cpumask *const cpu_online_mask;
-extern const struct cpumask *const cpu_present_mask;
-extern const struct cpumask *const cpu_active_mask;
 extern struct cpumask __cpu_possible_mask;
 extern struct cpumask __cpu_online_mask;
 extern struct cpumask __cpu_present_mask;
 extern struct cpumask __cpu_active_mask;
+#define cpu_possible_mask ((const struct cpumask *)&__cpu_possible_mask)
+#define cpu_online_mask   ((const struct cpumask *)&__cpu_online_mask)
+#define cpu_present_mask  ((const struct cpumask *)&__cpu_present_mask)
+#define cpu_active_mask   ((const struct cpumask *)&__cpu_active_mask)
 
 #if NR_CPUS > 1
 #define num_online_cpus()	cpumask_weight(cpu_online_mask)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 35d1d45be8e9..8734fc74fcbc 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -765,23 +765,15 @@ struct cpumask __cpu_possible_mask __read_mostly
 struct cpumask __cpu_possible_mask __read_mostly;
 #endif
 EXPORT_SYMBOL(__cpu_possible_mask);
-const struct cpumask *const cpu_possible_mask = &__cpu_possible_mask;
-EXPORT_SYMBOL(cpu_possible_mask);
 
 struct cpumask __cpu_online_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_online_mask);
-const struct cpumask *const cpu_online_mask = &__cpu_online_mask;
-EXPORT_SYMBOL(cpu_online_mask);
 
 struct cpumask __cpu_present_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_present_mask);
-const struct cpumask *const cpu_present_mask = &__cpu_present_mask;
-EXPORT_SYMBOL(cpu_present_mask);
 
 struct cpumask __cpu_active_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_active_mask);
-const struct cpumask *const cpu_active_mask = &__cpu_active_mask;
-EXPORT_SYMBOL(cpu_active_mask);
 
 void set_cpu_possible(unsigned int cpu, bool possible)
 {
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2, resend 6/6] kernel/cpu.c: make set_cpu_* static inlines
  2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
                     ` (4 preceding siblings ...)
  2015-11-23 19:51   ` [PATCH v2, resend 5/6] kernel/cpu.c: eliminate cpu_*_mask Rasmus Villemoes
@ 2015-11-23 19:51   ` Rasmus Villemoes
  5 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2015-11-23 19:51 UTC (permalink / raw)
  To: Rusty Russell, Greg Kroah-Hartman, Oleg Nesterov,
	Thomas Gleixner, Andrew Morton
  Cc: Michael Ellerman, Rasmus Villemoes, linux-kernel

Almost all callers of the set_cpu_* functions pass an explicit true
or false. Making them static inline thus replaces the function calls
with a simple set_bit/clear_bit, saving some .text.

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 include/linux/cpumask.h | 43 +++++++++++++++++++++++++++++++++++++++----
 kernel/cpu.c            | 34 ----------------------------------
 2 files changed, 39 insertions(+), 38 deletions(-)

diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 52ab539aefce..fc14275ff34e 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -720,14 +720,49 @@ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
 #define for_each_present_cpu(cpu)  for_each_cpu((cpu), cpu_present_mask)
 
 /* Wrappers for arch boot code to manipulate normally-constant masks */
-void set_cpu_possible(unsigned int cpu, bool possible);
-void set_cpu_present(unsigned int cpu, bool present);
-void set_cpu_online(unsigned int cpu, bool online);
-void set_cpu_active(unsigned int cpu, bool active);
 void init_cpu_present(const struct cpumask *src);
 void init_cpu_possible(const struct cpumask *src);
 void init_cpu_online(const struct cpumask *src);
 
+static inline void
+set_cpu_possible(unsigned int cpu, bool possible)
+{
+	if (possible)
+		cpumask_set_cpu(cpu, &__cpu_possible_mask);
+	else
+		cpumask_clear_cpu(cpu, &__cpu_possible_mask);
+}
+
+static inline void
+set_cpu_present(unsigned int cpu, bool present)
+{
+	if (present)
+		cpumask_set_cpu(cpu, &__cpu_present_mask);
+	else
+		cpumask_clear_cpu(cpu, &__cpu_present_mask);
+}
+
+static inline void
+set_cpu_online(unsigned int cpu, bool online)
+{
+	if (online) {
+		cpumask_set_cpu(cpu, &__cpu_online_mask);
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
+	} else {
+		cpumask_clear_cpu(cpu, &__cpu_online_mask);
+	}
+}
+
+static inline void
+set_cpu_active(unsigned int cpu, bool active)
+{
+	if (active)
+		cpumask_set_cpu(cpu, &__cpu_active_mask);
+	else
+		cpumask_clear_cpu(cpu, &__cpu_active_mask);
+}
+
+
 /**
  * to_cpumask - convert an NR_CPUS bitmap to a struct cpumask *
  * @bitmap: the bitmap
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 8734fc74fcbc..5b9d39633ce9 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -775,40 +775,6 @@ EXPORT_SYMBOL(__cpu_present_mask);
 struct cpumask __cpu_active_mask __read_mostly;
 EXPORT_SYMBOL(__cpu_active_mask);
 
-void set_cpu_possible(unsigned int cpu, bool possible)
-{
-	if (possible)
-		cpumask_set_cpu(cpu, &__cpu_possible_mask);
-	else
-		cpumask_clear_cpu(cpu, &__cpu_possible_mask);
-}
-
-void set_cpu_present(unsigned int cpu, bool present)
-{
-	if (present)
-		cpumask_set_cpu(cpu, &__cpu_present_mask);
-	else
-		cpumask_clear_cpu(cpu, &__cpu_present_mask);
-}
-
-void set_cpu_online(unsigned int cpu, bool online)
-{
-	if (online) {
-		cpumask_set_cpu(cpu, &__cpu_online_mask);
-		cpumask_set_cpu(cpu, &__cpu_active_mask);
-	} else {
-		cpumask_clear_cpu(cpu, &__cpu_online_mask);
-	}
-}
-
-void set_cpu_active(unsigned int cpu, bool active)
-{
-	if (active)
-		cpumask_set_cpu(cpu, &__cpu_active_mask);
-	else
-		cpumask_clear_cpu(cpu, &__cpu_active_mask);
-}
-
 void init_cpu_present(const struct cpumask *src)
 {
 	cpumask_copy(&__cpu_present_mask, src);
-- 
2.6.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-11-23 20:04 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-06 15:21 [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
2015-10-06 15:21 ` [PATCH v2 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
2015-10-06 15:21 ` [PATCH v2 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends Rasmus Villemoes
2015-10-06 15:21 ` [PATCH v2 3/6] kernel/cpu.c: export __cpu_*_mask Rasmus Villemoes
2015-10-06 15:21 ` [PATCH v2 4/6] drivers/base/cpu.c: use __cpu_*_mask directly Rasmus Villemoes
2015-10-06 15:21 ` [PATCH v2 5/6] kernel/cpu.c: eliminate cpu_*_mask Rasmus Villemoes
2015-10-06 15:21 ` [PATCH v2 6/6] kernel/cpu.c: make set_cpu_* static inlines Rasmus Villemoes
2015-10-17 22:07 ` [PATCH v2 0/6] kernel/cpu.c: eliminate some indirection Rasmus Villemoes
2015-10-18  1:41   ` Rusty Russell
2015-11-23 19:51 ` [PATCH v2, resend " Rasmus Villemoes
2015-11-23 19:51   ` [PATCH v2, resend 1/6] powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header Rasmus Villemoes
2015-11-23 19:51   ` [PATCH v2, resend 2/6] kernel/cpu.c: change type of cpu_possible_bits and friends Rasmus Villemoes
2015-11-23 19:51   ` [PATCH v2, resend 3/6] kernel/cpu.c: export __cpu_*_mask Rasmus Villemoes
2015-11-23 19:51   ` [PATCH v2, resend 4/6] drivers/base/cpu.c: use __cpu_*_mask directly Rasmus Villemoes
2015-11-23 19:51   ` [PATCH v2, resend 5/6] kernel/cpu.c: eliminate cpu_*_mask Rasmus Villemoes
2015-11-23 19:51   ` [PATCH v2, resend 6/6] kernel/cpu.c: make set_cpu_* static inlines Rasmus Villemoes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).