Skip to contentSkip to conversation

linux-next: build failure after merge of the rcu tree

DISCUSSION Applied Stephen Rothwell 4 participants 14 messages Jan 7, 2016 – Jan 8, 2016

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

Hi Paul,

[I found this a few days ago, but I think I forgot to send the email, sorry.]

After merging the rcu tree, today's linux-next build (powerpc allyesconfig) failed like this:

kernel/rcu/rcuperf.o:(.discard+0x0): multiple definition of `__pcpu_unique_srcu_ctl_srcu_array' kernel/rcu/rcutorture.o:(.discard+0x0): first defined here

Caused by commit

abcd7ec0808e ("rcutorture: Add RCU grace-period performance tests")

I have reverted that commit for today.

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]
#1 lore raw
Quoted 8 lines · Stephen Rothwell

Hi Paul,

[I found this a few days ago, but I think I forgot to send the email, sorry.]

After merging the rcu tree, today's linux-next build (powerpc allyesconfig) failed like this:

Quoted 8 lines

kernel/rcu/rcuperf.o:(.discard+0x0): multiple definition of `__pcpu_unique_srcu_ctl_srcu_array' kernel/rcu/rcutorture.o:(.discard+0x0): first defined here

Caused by commit

abcd7ec0808e ("rcutorture: Add RCU grace-period performance tests")

I have reverted that commit for today.

Hello, Stephen,

Very strange. The "static" keyword does not mean anything here? Easy enough to use different symbols in the two different files, but this situation is not so good for information hiding.

Happy to update rcuperf.c to use a different name, but in the immortal words of MSDOS, "Are you sure?" :-)

Thanx, Paul

#2 lore raw

Hi Paul,

Quoted 19 lines · On Thu, 7 Jan 2016 10:02:44 -0800 "Paul E. McKenney"…
Quoted 8 lines · Stephen Rothwell

Hi Paul,

[I found this a few days ago, but I think I forgot to send the email, sorry.]

After merging the rcu tree, today's linux-next build (powerpc allyesconfig) failed like this:

Quoted 8 lines

kernel/rcu/rcuperf.o:(.discard+0x0): multiple definition of `__pcpu_unique_srcu_ctl_srcu_array' kernel/rcu/rcutorture.o:(.discard+0x0): first defined here

Caused by commit

abcd7ec0808e ("rcutorture: Add RCU grace-period performance tests")

I have reverted that commit for today.

Quoted 8 lines

Hello, Stephen,

Very strange. The "static" keyword does not mean anything here? Easy enough to use different symbols in the two different files, but this situation is not so good for information hiding.

Happy to update rcuperf.c to use a different name, but in the immortal words of MSDOS, "Are you sure?" :-)

I have no idea why it happens, but I do get the error above unless I revert that commit. So, yes, I am sure :-)

OK, I looked further and

DEFINE_STATIC_SRCU(srcu_ctl);

becomes this (NLs added for clarity):

static __attribute__((section(".discard"), unused)) char __pcpu_scope_srcu_ctl_srcu_array;
extern __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array; __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array;
extern __attribute__((section(".data..percpu" ""))) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array; __attribute__((section(".data..percpu" ""))) __attribute__((weak)) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array;

static struct srcu_struct srcu_ctl = {
	.
	.
};

So, the "static" is not very effective :-(

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]
#3 lore raw
Quoted 45 lines · Stephen Rothwell

Hi Paul,

Quoted 19 lines · On Thu, 7 Jan 2016 10:02:44 -0800 "Paul E. McKenney"…
Quoted 8 lines · Stephen Rothwell

Hi Paul,

[I found this a few days ago, but I think I forgot to send the email, sorry.]

After merging the rcu tree, today's linux-next build (powerpc allyesconfig) failed like this:

Quoted 8 lines

kernel/rcu/rcuperf.o:(.discard+0x0): multiple definition of `__pcpu_unique_srcu_ctl_srcu_array' kernel/rcu/rcutorture.o:(.discard+0x0): first defined here

Caused by commit

abcd7ec0808e ("rcutorture: Add RCU grace-period performance tests")

I have reverted that commit for today.

Quoted 8 lines

Hello, Stephen,

Very strange. The "static" keyword does not mean anything here? Easy enough to use different symbols in the two different files, but this situation is not so good for information hiding.

Happy to update rcuperf.c to use a different name, but in the immortal words of MSDOS, "Are you sure?" :-)

I have no idea why it happens, but I do get the error above unless I revert that commit. So, yes, I am sure :-)

OK, I looked further and

DEFINE_STATIC_SRCU(srcu_ctl);

becomes this (NLs added for clarity):

static __attribute__((section(".discard"), unused)) char __pcpu_scope_srcu_ctl_srcu_array;
extern __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array; __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array;
extern __attribute__((section(".data..percpu" ""))) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array; __attribute__((section(".data..percpu" ""))) __attribute__((weak)) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array;

Quoted 6 lines
static struct srcu_struct srcu_ctl = {
	.
	.
};

So, the "static" is not very effective :-(

Oddly enough, this appears to be toolchain dependent. No idea why.

Here is a patch that I will be merging in.

Thanx, Paul

------------------------------------------------------------------------

commit d81f900405de0dc6152692a2088258b8b35d740d

Author: Paul E. McKenney <[email protected]>
Date:   Thu Jan 7 12:39:10 2016 -0800

Merge with abcd7ec0808e (rcutorture: Add RCU grace-period performance tests)

kernel/rcu/rcuperf.c +2 -2
index eef82a9460d8..4c8d99aa4f5e 100644
@@ -188,8 +188,8 @@ static struct rcu_perf_ops rcu_bh_ops = {
  * Definitions for srcu perf testing.
  */
 
-DEFINE_STATIC_SRCU(srcu_ctl);
-static struct srcu_struct *srcu_ctlp = &srcu_ctl;
+DEFINE_STATIC_SRCU(srcu_ctl_perf);
+static struct srcu_struct *srcu_ctlp = &srcu_ctl_perf;
 
 static int srcu_perf_read_lock(void) __acquires(srcu_ctlp)
 {
#4 lore raw
Quoted 51 lines · Paul E. McKenney
Quoted 50 lines · Stephen Rothwell

Hi Paul,

Quoted 19 lines · On Thu, 7 Jan 2016 10:02:44 -0800 "Paul E. McKenney"…
Quoted 8 lines · Stephen Rothwell

Hi Paul,

[I found this a few days ago, but I think I forgot to send the email, sorry.]

After merging the rcu tree, today's linux-next build (powerpc allyesconfig) failed like this:

Quoted 8 lines

kernel/rcu/rcuperf.o:(.discard+0x0): multiple definition of `__pcpu_unique_srcu_ctl_srcu_array' kernel/rcu/rcutorture.o:(.discard+0x0): first defined here

Caused by commit

abcd7ec0808e ("rcutorture: Add RCU grace-period performance tests")

I have reverted that commit for today.

Quoted 8 lines

Hello, Stephen,

Very strange. The "static" keyword does not mean anything here? Easy enough to use different symbols in the two different files, but this situation is not so good for information hiding.

Happy to update rcuperf.c to use a different name, but in the immortal words of MSDOS, "Are you sure?" :-)

I have no idea why it happens, but I do get the error above unless I revert that commit. So, yes, I am sure :-)

OK, I looked further and

DEFINE_STATIC_SRCU(srcu_ctl);

becomes this (NLs added for clarity):

static __attribute__((section(".discard"), unused)) char __pcpu_scope_srcu_ctl_srcu_array;
extern __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array; __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array;
extern __attribute__((section(".data..percpu" ""))) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array; __attribute__((section(".data..percpu" ""))) __attribute__((weak)) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array;

static struct srcu_struct srcu_ctl = {
	.
	.
};
Quoted 4 lines
Quoted 1 line

So, the "static" is not very effective :-(

Oddly enough, this appears to be toolchain dependent. No idea why.

Maybe the reason is because "static" doesn't work well with DEFINE_PER_CPU sometimes?

The definition of __DEFINE_STATIC_SRCU is:

#define __DEFINE_SRCU(name, is_static)					\
	static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
	is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)

whereas DEFINE_PER_CPU(which calls DEFINE_PER_CPU_SECTION) *could* consists of *several* definitions:

#if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU)
...

#define DEFINE_PER_CPU_SECTION(type, name, sec)				\
	__PCPU_DUMMY_ATTRS char __pcpu_scope_##name;			\
	extern __PCPU_DUMMY_ATTRS char __pcpu_unique_##name;		\
	__PCPU_DUMMY_ATTRS char __pcpu_unique_##name;			\
	extern __PCPU_ATTRS(sec) __typeof__(type) name;			\
	__PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES __weak			\
	__typeof__(type) name
#else
...
#define DEFINE_PER_CPU_SECTION(type, name, sec)				\
	__PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES			\
	__typeof__(type) name

#endif

So if ARCH_NEEDS_WEAK_PER_CPU=y or CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y, the "static" keyword only has effects on the first definition i.e. __pcpu_scope_##name.

Mind to check your config options, Stephen?

IOW, DEFINE_PER_CPU is not designed to work with "static", maybe we should add STATIC_DEFINE_PER_CPU for that purpose?

Cc Tejun and Christoph for their opinions.

Regards,
Boqun

Quoted 30 lines

Here is a patch that I will be merging in.

Thanx, Paul

------------------------------------------------------------------------

commit d81f900405de0dc6152692a2088258b8b35d740d

Author: Paul E. McKenney <[email protected]>
Date:   Thu Jan 7 12:39:10 2016 -0800

Merge with abcd7ec0808e (rcutorture: Add RCU grace-period performance tests)

kernel/rcu/rcuperf.c +2 -2
index eef82a9460d8..4c8d99aa4f5e 100644
@@ -188,8 +188,8 @@ static struct rcu_perf_ops rcu_bh_ops = {
  * Definitions for srcu perf testing.
  */
 
-DEFINE_STATIC_SRCU(srcu_ctl);
-static struct srcu_struct *srcu_ctlp = &srcu_ctl;
+DEFINE_STATIC_SRCU(srcu_ctl_perf);
+static struct srcu_struct *srcu_ctlp = &srcu_ctl_perf;
 
 static int srcu_perf_read_lock(void) __acquires(srcu_ctlp)
 {
#5 lore raw
Quoted 89 lines · Boqun Feng
Quoted 51 lines · Paul E. McKenney
Quoted 50 lines · Stephen Rothwell

Hi Paul,

Quoted 19 lines · On Thu, 7 Jan 2016 10:02:44 -0800 "Paul E. McKenney"…
Quoted 8 lines · Stephen Rothwell

Hi Paul,

[I found this a few days ago, but I think I forgot to send the email, sorry.]

After merging the rcu tree, today's linux-next build (powerpc allyesconfig) failed like this:

Quoted 8 lines

kernel/rcu/rcuperf.o:(.discard+0x0): multiple definition of `__pcpu_unique_srcu_ctl_srcu_array' kernel/rcu/rcutorture.o:(.discard+0x0): first defined here

Caused by commit

abcd7ec0808e ("rcutorture: Add RCU grace-period performance tests")

I have reverted that commit for today.

Quoted 8 lines

Hello, Stephen,

Very strange. The "static" keyword does not mean anything here? Easy enough to use different symbols in the two different files, but this situation is not so good for information hiding.

Happy to update rcuperf.c to use a different name, but in the immortal words of MSDOS, "Are you sure?" :-)

I have no idea why it happens, but I do get the error above unless I revert that commit. So, yes, I am sure :-)

OK, I looked further and

DEFINE_STATIC_SRCU(srcu_ctl);

becomes this (NLs added for clarity):

static __attribute__((section(".discard"), unused)) char __pcpu_scope_srcu_ctl_srcu_array;
extern __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array; __attribute__((section(".discard"), unused)) char __pcpu_unique_srcu_ctl_srcu_array;
extern __attribute__((section(".data..percpu" ""))) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array; __attribute__((section(".data..percpu" ""))) __attribute__((weak)) __typeof__(struct srcu_struct_array) srcu_ctl_srcu_array;

static struct srcu_struct srcu_ctl = {
	.
	.
};
Quoted 4 lines
Quoted 1 line

So, the "static" is not very effective :-(

Oddly enough, this appears to be toolchain dependent. No idea why.

Maybe the reason is because "static" doesn't work well with DEFINE_PER_CPU sometimes?

The definition of __DEFINE_STATIC_SRCU is:

#define __DEFINE_SRCU(name, is_static)					\
	static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
	is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)

whereas DEFINE_PER_CPU(which calls DEFINE_PER_CPU_SECTION) *could* consists of *several* definitions:

#if defined(ARCH_NEEDS_WEAK_PER_CPU) || defined(CONFIG_DEBUG_FORCE_WEAK_PER_CPU)
...

#define DEFINE_PER_CPU_SECTION(type, name, sec)				\
	__PCPU_DUMMY_ATTRS char __pcpu_scope_##name;			\
	extern __PCPU_DUMMY_ATTRS char __pcpu_unique_##name;		\
	__PCPU_DUMMY_ATTRS char __pcpu_unique_##name;			\
	extern __PCPU_ATTRS(sec) __typeof__(type) name;			\
	__PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES __weak			\
	__typeof__(type) name
#else
...
#define DEFINE_PER_CPU_SECTION(type, name, sec)				\
	__PCPU_ATTRS(sec) PER_CPU_DEF_ATTRIBUTES			\
	__typeof__(type) name

#endif

So if ARCH_NEEDS_WEAK_PER_CPU=y or CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y, the "static" keyword only has effects on the first definition i.e. __pcpu_scope_##name.

Quoted 5 lines

Mind to check your config options, Stephen?

IOW, DEFINE_PER_CPU is not designed to work with "static", maybe we should add STATIC_DEFINE_PER_CPU for that purpose?

Indeed, I suspect that SRCU might not be the only thing that would like static per-CPU variables. ;-)

Quoted 4 lines

Cc Tejun and Christoph for their opinions.

Regards,
Boqun

Thanx, Paul

Quoted 30 lines
Quoted 30 lines

Here is a patch that I will be merging in.

Thanx, Paul

------------------------------------------------------------------------

commit d81f900405de0dc6152692a2088258b8b35d740d

Author: Paul E. McKenney <[email protected]>
Date:   Thu Jan 7 12:39:10 2016 -0800

Merge with abcd7ec0808e (rcutorture: Add RCU grace-period performance tests)

kernel/rcu/rcuperf.c +2 -2
index eef82a9460d8..4c8d99aa4f5e 100644
@@ -188,8 +188,8 @@ static struct rcu_perf_ops rcu_bh_ops = {
  * Definitions for srcu perf testing.
  */
 
-DEFINE_STATIC_SRCU(srcu_ctl);
-static struct srcu_struct *srcu_ctlp = &srcu_ctl;
+DEFINE_STATIC_SRCU(srcu_ctl_perf);
+static struct srcu_struct *srcu_ctlp = &srcu_ctl_perf;
 
 static int srcu_perf_read_lock(void) __acquires(srcu_ctlp)
 {
#6 lore raw

Hi Paul,

Quoted 3 lines · On Thu, 7 Jan 2016 19:41:57 -0800 "Paul E. McKenney"…

Indeed, I suspect that SRCU might not be the only thing that would like static per-CPU variables. ;-)

from include/linux/percpu-defs.h:

* s390 and alpha modules require percpu variables to be defined as
* weak to force the compiler to generate GOT based external
* references for them. This is necessary because percpu sections
* will be located outside of the usually addressable area. *
* This definition puts the following two extra restrictions when
* defining percpu variables.
*
* 1. The symbol must be globally unique, even the static ones.
* 2. Static percpu variables cannot be defined inside a function. *
* Archs which need weak percpu definitions should define
* ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. *
* To ensure that the generic code observes the above two
* restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak
* definition is used for all cases.

so they can be static, but must be globally unique.

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]
#13 lore raw
In reply to Boqun Feng

Hi Boqun,

Quoted 2 lines · On Fri, 8 Jan 2016 09:37:04 +0800 Boqun Feng <[email protected]> wrote:

Mind to check your config options, Stephen?

This was an allyesconfig build, so I assume that CONFIG_DEBUG_FORCE_WEAK_PER_CPU was set (sorry, I don;t have the .config file at the moment).

Signature · 2 lines
Cheers,
Stephen Rothwell                    [email protected]
#7 lore raw
In reply to Stephen Rothwell
Quoted 27 lines · Stephen Rothwell

Hi Paul,

Quoted 3 lines · On Thu, 7 Jan 2016 19:41:57 -0800 "Paul E. McKenney"…

Indeed, I suspect that SRCU might not be the only thing that would like static per-CPU variables. ;-)

from include/linux/percpu-defs.h:

* s390 and alpha modules require percpu variables to be defined as
* weak to force the compiler to generate GOT based external
* references for them. This is necessary because percpu sections
* will be located outside of the usually addressable area. *
* This definition puts the following two extra restrictions when
* defining percpu variables.
*
* 1. The symbol must be globally unique, even the static ones.
* 2. Static percpu variables cannot be defined inside a function. *
* Archs which need weak percpu definitions should define
* ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. *
* To ensure that the generic code observes the above two
* restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak
* definition is used for all cases.

Quoted 1 line

so they can be static, but must be globally unique.

Thank you for the tutorial! I have updated the patch to use a unique name for the srcu_struct added by rcuperf.c.

Thanx, Paul

#8 lore raw
Quoted 28 lines · Paul E. McKenney
Quoted 27 lines · Stephen Rothwell

Hi Paul,

Quoted 3 lines · On Thu, 7 Jan 2016 19:41:57 -0800 "Paul E. McKenney"…

Indeed, I suspect that SRCU might not be the only thing that would like static per-CPU variables. ;-)

from include/linux/percpu-defs.h:

* s390 and alpha modules require percpu variables to be defined as
* weak to force the compiler to generate GOT based external
* references for them. This is necessary because percpu sections
* will be located outside of the usually addressable area. *
* This definition puts the following two extra restrictions when
* defining percpu variables.
*
* 1. The symbol must be globally unique, even the static ones.
* 2. Static percpu variables cannot be defined inside a function. *
* Archs which need weak percpu definitions should define
* ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. *
* To ensure that the generic code observes the above two
* restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak
* definition is used for all cases.

Quoted 1 line
Quoted 1 line

so they can be static, but must be globally unique.

Interesting ;-) Thank you.

Quoted 4 lines

Thank you for the tutorial! I have updated the patch to use a unique name for the srcu_struct added by rcuperf.c.

Plus a comment for DEFINE_STATIC_SRCU saying srcu can be defined as static but must have a unique name for this reason?

Regards,
Boqun

Quoted 2 lines

Thanx, Paul

#9 lore raw
Quoted 31 lines · Boqun Feng
Quoted 28 lines · Paul E. McKenney
Quoted 27 lines · Stephen Rothwell

Hi Paul,

Quoted 3 lines · On Thu, 7 Jan 2016 19:41:57 -0800 "Paul E. McKenney"…

Indeed, I suspect that SRCU might not be the only thing that would like static per-CPU variables. ;-)

from include/linux/percpu-defs.h:

* s390 and alpha modules require percpu variables to be defined as
* weak to force the compiler to generate GOT based external
* references for them. This is necessary because percpu sections
* will be located outside of the usually addressable area. *
* This definition puts the following two extra restrictions when
* defining percpu variables.
*
* 1. The symbol must be globally unique, even the static ones.
* 2. Static percpu variables cannot be defined inside a function. *
* Archs which need weak percpu definitions should define
* ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. *
* To ensure that the generic code observes the above two
* restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak
* definition is used for all cases.

Quoted 1 line
Quoted 1 line

so they can be static, but must be globally unique.

Quoted 7 lines

Interesting ;-) Thank you.

Quoted 2 lines

Thank you for the tutorial! I have updated the patch to use a unique name for the srcu_struct added by rcuperf.c.

Plus a comment for DEFINE_STATIC_SRCU saying srcu can be defined as static but must have a unique name for this reason?

Yes, plus some words about how to work around the limitation. How about the patch below?

Thanx, Paul

------------------------------------------------------------------------

commit 61822ff81839ee3c5b6094ce348944d972b87892

Author: Paul E. McKenney <[email protected]>
Date:   Fri Jan 8 07:43:50 2016 -0800

rcu: Document unique-name limitation for DEFINE_STATIC_SRCU()

SRCU uses per-CPU variables, and DEFINE_STATIC_SRCU() uses a static per-CPU variable. However, per-CPU variables have significant restrictions, for example, names of per-CPU variables must be globally unique, even if declared static. These restrictions carry over to DEFINE_STATIC_SRCU(), and this commit therefore documents these restrictions.

include/linux/srcu.h +17 -2
index f5f80c5643ac..dc8eb63c6568 100644
@@ -99,8 +99,23 @@ void process_srcu(struct work_struct *work);
 	}
 
 /*
- * define and init a srcu struct at build time.
- * dont't call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ * Define and initialize a srcu struct at build time.
+ * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ *
+ * Note that although DEFINE_STATIC_SRCU() hides the name from other
+ * files, the per-CPU variable rules nevertheless require that the
+ * chosen name be globally unique.  These rules also prohibit use of
+ * DEFINE_STATIC_SRCU() within a function.  If these rules are too
+ * restrictive, declare the srcu_struct manually.  For example, in
+ * each file:
+ *
+ *	static struct srcu_struct my_srcu;
+ *
+ * Then, before the first use of each my_srcu, manually initialize it:
+ *
+ *	init_srcu_struct(&my_srcu);
+ *
+ * See include/linux/percpu-defs.h for the rules on per-CPU variables.
  */
 #define __DEFINE_SRCU(name, is_static)					\
 	static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
Reviewed-by
#10 lore raw
Quoted 35 lines · Paul E. McKenney

commit 61822ff81839ee3c5b6094ce348944d972b87892

Author: Paul E. McKenney <[email protected]>
Date:   Fri Jan 8 07:43:50 2016 -0800

rcu: Document unique-name limitation for DEFINE_STATIC_SRCU()

SRCU uses per-CPU variables, and DEFINE_STATIC_SRCU() uses a static per-CPU variable. However, per-CPU variables have significant restrictions, for example, names of per-CPU variables must be globally unique, even if declared static. These restrictions carry over to DEFINE_STATIC_SRCU(), and this commit therefore documents these restrictions.

include/linux/srcu.h +7 -2
index f5f80c5643ac..dc8eb63c6568 100644
@@ -99,8 +99,23 @@ void process_srcu(struct work_struct *work);
 	}
 
 /*
- * define and init a srcu struct at build time.
- * dont't call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ * Define and initialize a srcu struct at build time.
+ * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ *
+ * Note that although DEFINE_STATIC_SRCU() hides the name from other
+ * files, the per-CPU variable rules nevertheless require that the
+ * chosen name be globally unique.  These rules also prohibit use of
+ * DEFINE_STATIC_SRCU() within a function.  If these rules are too

include/linux/srcu.h void process_srcu(struct work_struct *work); · line 118

Quoted 10 lines
include/linux/srcu.h +10 -0
+ * restrictive, declare the srcu_struct manually.  For example, in
+ * each file:
+ *
+ *	static struct srcu_struct my_srcu;
+ *
+ * Then, before the first use of each my_srcu, manually initialize it:
+ *
+ *	init_srcu_struct(&my_srcu);
+ *
+ * See include/linux/percpu-defs.h for the rules on per-CPU variables.

FWIW,

Thanks Stephen for posting the rules around static percpu definitions. I wonder whether there is a better way to tell people what's going on.

Thanks.

Signature · 1 line
tejun
#12 lore raw
In reply to Paul E. McKenney
Quoted 34 lines · Paul E. McKenney
Quoted 33 lines · Boqun Feng
Quoted 28 lines · Paul E. McKenney
Quoted 27 lines · Stephen Rothwell

Hi Paul,

Quoted 3 lines · On Thu, 7 Jan 2016 19:41:57 -0800 "Paul E. McKenney"…

Indeed, I suspect that SRCU might not be the only thing that would like static per-CPU variables. ;-)

from include/linux/percpu-defs.h:

* s390 and alpha modules require percpu variables to be defined as
* weak to force the compiler to generate GOT based external
* references for them. This is necessary because percpu sections
* will be located outside of the usually addressable area. *
* This definition puts the following two extra restrictions when
* defining percpu variables.
*
* 1. The symbol must be globally unique, even the static ones.
* 2. Static percpu variables cannot be defined inside a function. *
* Archs which need weak percpu definitions should define
* ARCH_NEEDS_WEAK_PER_CPU in asm/percpu.h when necessary. *
* To ensure that the generic code observes the above two
* restrictions, if CONFIG_DEBUG_FORCE_WEAK_PER_CPU is set weak
* definition is used for all cases.

Quoted 1 line
Quoted 1 line

so they can be static, but must be globally unique.

Interesting ;-) Thank you.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Thank you for the tutorial! I have updated the patch to use a unique name for the srcu_struct added by rcuperf.c.

Plus a comment for DEFINE_STATIC_SRCU saying srcu can be defined as static but must have a unique name for this reason?

Yes, plus some words about how to work around the limitation. How about the patch below?

Looks very good to me ;-)

Regards,
Boqun

Quoted 53 lines

Thanx, Paul

------------------------------------------------------------------------

commit 61822ff81839ee3c5b6094ce348944d972b87892

Author: Paul E. McKenney <[email protected]>
Date:   Fri Jan 8 07:43:50 2016 -0800

rcu: Document unique-name limitation for DEFINE_STATIC_SRCU()

SRCU uses per-CPU variables, and DEFINE_STATIC_SRCU() uses a static per-CPU variable. However, per-CPU variables have significant restrictions, for example, names of per-CPU variables must be globally unique, even if declared static. These restrictions carry over to DEFINE_STATIC_SRCU(), and this commit therefore documents these restrictions.

include/linux/srcu.h +17 -2
index f5f80c5643ac..dc8eb63c6568 100644
@@ -99,8 +99,23 @@ void process_srcu(struct work_struct *work);
 	}
 
 /*
- * define and init a srcu struct at build time.
- * dont't call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ * Define and initialize a srcu struct at build time.
+ * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ *
+ * Note that although DEFINE_STATIC_SRCU() hides the name from other
+ * files, the per-CPU variable rules nevertheless require that the
+ * chosen name be globally unique.  These rules also prohibit use of
+ * DEFINE_STATIC_SRCU() within a function.  If these rules are too
+ * restrictive, declare the srcu_struct manually.  For example, in
+ * each file:
+ *
+ *	static struct srcu_struct my_srcu;
+ *
+ * Then, before the first use of each my_srcu, manually initialize it:
+ *
+ *	init_srcu_struct(&my_srcu);
+ *
+ * See include/linux/percpu-defs.h for the rules on per-CPU variables.
  */
 #define __DEFINE_SRCU(name, is_static)					\
 	static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
#11 lore raw
In reply to Tejun Heo
Quoted 49 lines · Tejun Heo
Quoted 35 lines · Paul E. McKenney

commit 61822ff81839ee3c5b6094ce348944d972b87892

Author: Paul E. McKenney <[email protected]>
Date:   Fri Jan 8 07:43:50 2016 -0800

rcu: Document unique-name limitation for DEFINE_STATIC_SRCU()

SRCU uses per-CPU variables, and DEFINE_STATIC_SRCU() uses a static per-CPU variable. However, per-CPU variables have significant restrictions, for example, names of per-CPU variables must be globally unique, even if declared static. These restrictions carry over to DEFINE_STATIC_SRCU(), and this commit therefore documents these restrictions.

include/linux/srcu.h +7 -2
index f5f80c5643ac..dc8eb63c6568 100644
@@ -99,8 +99,23 @@ void process_srcu(struct work_struct *work);
 	}
 
 /*
- * define and init a srcu struct at build time.
- * dont't call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ * Define and initialize a srcu struct at build time.
+ * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ *
+ * Note that although DEFINE_STATIC_SRCU() hides the name from other
+ * files, the per-CPU variable rules nevertheless require that the
+ * chosen name be globally unique.  These rules also prohibit use of
+ * DEFINE_STATIC_SRCU() within a function.  If these rules are too

include/linux/srcu.h void process_srcu(struct work_struct *work); · line 118

Quoted 10 lines
include/linux/srcu.h +10 -0
+ * restrictive, declare the srcu_struct manually.  For example, in
+ * each file:
+ *
+ *	static struct srcu_struct my_srcu;
+ *
+ * Then, before the first use of each my_srcu, manually initialize it:
+ *
+ *	init_srcu_struct(&my_srcu);
+ *
+ * See include/linux/percpu-defs.h for the rules on per-CPU variables.

FWIW,

Quoted 1 line

Applied, thank you!

Quoted 1 line

Thanks Stephen for posting the rules around static percpu definitions.

Me too! Hey, it was building fine with all of my configurations, so I was really beginning to wonder if this was some sort of early April Fools joke. ;-)

Quoted 1 line

I wonder whether there is a better way to tell people what's going on.

I hope so. ;-)

Thanx, Paul