Skip to contentSkip to conversation

sched/sysctl: Fix attributes of some extern declarations

PATCH In review Matthias Kaehlcke 4 participants 6 messages Oct 30, 2017 – Nov 1, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched/sysctl: Fix attributes of some extern declarations

The definition of sysctl_sched_migration_cost, sysctl_sched_nr_migrate and sysctl_sched_time_avg includes the attribute const_debug. This attribute is not part of the extern declaration of these variables in include/linux/sched/sysctl.h, as a result clang generates warnings like this:

kernel/sched/sched.h:1618:33: warning: section attribute is specified on
redeclared variable [-Wsection]

  extern const_debug unsigned int sysctl_sched_time_avg;
                                ^

./include/linux/sched/sysctl.h:42:21: note: previous declaration is here extern unsigned int sysctl_sched_time_avg;

The header only declares the variables when CONFIG_SCHED_DEBUG is defined, therefore it is not necessary to duplicate the definition of const_debug. Instead we can use the attribute __read_mostly, which is the expansion of const_debug when CONFIG_SCHED_DEBUG is set.

---
Changes in v2:
- removed pointless include of linux/static_key.h
- added Reviewed-by tag

 include/linux/sched/sysctl.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/sched/sysctl.h +3 -3
index 0f5ecd4d298e..d34c823f3d36 100644
@@ -37,9 +37,9 @@ extern unsigned int sysctl_numa_balancing_scan_period_max;
 extern unsigned int sysctl_numa_balancing_scan_size;
 
 #ifdef CONFIG_SCHED_DEBUG
-extern unsigned int sysctl_sched_migration_cost;
-extern unsigned int sysctl_sched_nr_migrate;
-extern unsigned int sysctl_sched_time_avg;
+extern __read_mostly unsigned int sysctl_sched_migration_cost;
+extern __read_mostly unsigned int sysctl_sched_nr_migrate;
+extern __read_mostly unsigned int sysctl_sched_time_avg;
 
 int sched_proc_update_handler(struct ctl_table *table, int write,
 		void __user *buffer, size_t *length,
Signature · 1 line
2.15.0.rc2.357.g7e34df9404-goog
#1 lore raw
Quoted 33 lines · Matthias Kaehlcke

The definition of sysctl_sched_migration_cost, sysctl_sched_nr_migrate and sysctl_sched_time_avg includes the attribute const_debug. This attribute is not part of the extern declaration of these variables in include/linux/sched/sysctl.h, as a result clang generates warnings like this:

kernel/sched/sched.h:1618:33: warning: section attribute is specified on
redeclared variable [-Wsection]

  extern const_debug unsigned int sysctl_sched_time_avg;
                                ^

./include/linux/sched/sysctl.h:42:21: note: previous declaration is here extern unsigned int sysctl_sched_time_avg;

The header only declares the variables when CONFIG_SCHED_DEBUG is defined, therefore it is not necessary to duplicate the definition of const_debug. Instead we can use the attribute __read_mostly, which is the expansion of const_debug when CONFIG_SCHED_DEBUG is set.

---
Changes in v2:
- removed pointless include of linux/static_key.h
- added Reviewed-by tag

 include/linux/sched/sysctl.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/sched/sysctl.h +0 -0
index 0f5ecd4d298e..d34c823f3d36 100644

include/linux/sched/sysctl.h extern unsigned int sysctl_numa_balancing_scan_period_max; · line 42

Quoted 9 lines
include/linux/sched/sysctl.h +3 -3
@@ -37,9 +37,9 @@ extern unsigned int sysctl_numa_balancing_scan_period_max;
 extern unsigned int sysctl_numa_balancing_scan_size;
 
 #ifdef CONFIG_SCHED_DEBUG
-extern unsigned int sysctl_sched_migration_cost;
-extern unsigned int sysctl_sched_nr_migrate;
-extern unsigned int sysctl_sched_time_avg;
+extern __read_mostly unsigned int sysctl_sched_migration_cost;
+extern __read_mostly unsigned int sysctl_sched_nr_migrate;
+extern __read_mostly unsigned int sysctl_sched_time_avg;

So I hate this change, because it pointlessly duplicates an attribute that should only matter at the definition site. The Clang warning:

include/linux/sched/sysctl.h extern unsigned int sysctl_numa_balancing_scan_period_max; · line 44

Quoted 2 lines
include/linux/sched/sysctl.h +0 -0
  kernel/sched/sched.h:1618:33: warning: section attribute is specified on
    redeclared variable [-Wsection]

suggests that the -Wsection warning can be turned off. The Clang build should probably do that.

Thanks,

Ingo

#2 lore raw

El Tue, Oct 30, 2017 at 10:57:58AM +0100 Ingo Molnar ha dit:

Quoted 37 lines · Matthias Kaehlcke
Quoted 36 lines

The definition of sysctl_sched_migration_cost, sysctl_sched_nr_migrate and sysctl_sched_time_avg includes the attribute const_debug. This attribute is not part of the extern declaration of these variables in include/linux/sched/sysctl.h, as a result clang generates warnings like this:

kernel/sched/sched.h:1618:33: warning: section attribute is specified on
redeclared variable [-Wsection]

  extern const_debug unsigned int sysctl_sched_time_avg;
                                ^

./include/linux/sched/sysctl.h:42:21: note: previous declaration is here extern unsigned int sysctl_sched_time_avg;

The header only declares the variables when CONFIG_SCHED_DEBUG is defined, therefore it is not necessary to duplicate the definition of const_debug. Instead we can use the attribute __read_mostly, which is the expansion of const_debug when CONFIG_SCHED_DEBUG is set.

---
Changes in v2:
- removed pointless include of linux/static_key.h
- added Reviewed-by tag

 include/linux/sched/sysctl.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/sched/sysctl.h +0 -0
index 0f5ecd4d298e..d34c823f3d36 100644
@@ -37,9 +37,9 @@ extern unsigned int sysctl_numa_balancing_scan_period_max;
 extern unsigned int sysctl_numa_balancing_scan_size;
 
Quoted 10 lines

include/linux/sched/sysctl.h extern unsigned int sysctl_numa_balancing_scan_period_max; · line 42

Quoted 7 lines
include/linux/sched/sysctl.h +3 -3
 #ifdef CONFIG_SCHED_DEBUG
-extern unsigned int sysctl_sched_migration_cost;
-extern unsigned int sysctl_sched_nr_migrate;
-extern unsigned int sysctl_sched_time_avg;
+extern __read_mostly unsigned int sysctl_sched_migration_cost;
+extern __read_mostly unsigned int sysctl_sched_nr_migrate;
+extern __read_mostly unsigned int sysctl_sched_time_avg;

So I hate this change, because it pointlessly duplicates an attribute that should only matter at the definition site.

It's certainly not ideal, and then again essentially the same is done in kernel/sched/sched.h, just that here the specific attribute is hidden behind const_debug.

Quoted 7 lines

The Clang warning:

include/linux/sched/sysctl.h extern unsigned int sysctl_numa_balancing_scan_period_max; · line 44

Quoted 2 lines
include/linux/sched/sysctl.h +0 -0
  kernel/sched/sched.h:1618:33: warning: section attribute is specified on
    redeclared variable [-Wsection]

suggests that the -Wsection warning can be turned off. The Clang build should probably do that.

That can definitely be done. I don't have a really strong opinion on this, just wonder if the warning could be useful in other circumstances to spot conflicting declarations. This instance looks like a somewhat special case with the declarations in two header files and it might be worth to pay the price of the pointlessly duplicate attribute to get a useful warning in others.

Adding kbuild maintainer Masahiro Yamada to the thread, who tends to be reluctant about disabling warnings globally.

#3 lore raw
Quoted 15 lines

El Tue, Oct 30, 2017 at 10:57:58AM +0100 Ingo Molnar ha dit:

Quoted 2 lines

So I hate this change, because it pointlessly duplicates an attribute that should only matter at the definition site.

It's certainly not ideal, and then again essentially the same is done in kernel/sched/sched.h, just that here the specific attribute is hidden behind const_debug.

Quoted 7 lines

The Clang warning:

Quoted 2 lines

kernel/sched/sched.h:1618:33: warning: section attribute is specified on
redeclared variable [-Wsection]

suggests that the -Wsection warning can be turned off. The Clang build should probably do that.

Naive question: can these definitions be hoisted to include/linux/sched.h?

#4 lore raw
In reply to Matthias Kaehlcke
Quoted 50 lines · Matthias Kaehlcke

El Tue, Oct 30, 2017 at 10:57:58AM +0100 Ingo Molnar ha dit:

Quoted 37 lines · Matthias Kaehlcke
Quoted 36 lines

The definition of sysctl_sched_migration_cost, sysctl_sched_nr_migrate and sysctl_sched_time_avg includes the attribute const_debug. This attribute is not part of the extern declaration of these variables in include/linux/sched/sysctl.h, as a result clang generates warnings like this:

kernel/sched/sched.h:1618:33: warning: section attribute is specified on
redeclared variable [-Wsection]

  extern const_debug unsigned int sysctl_sched_time_avg;
                                ^

./include/linux/sched/sysctl.h:42:21: note: previous declaration is here extern unsigned int sysctl_sched_time_avg;

The header only declares the variables when CONFIG_SCHED_DEBUG is defined, therefore it is not necessary to duplicate the definition of const_debug. Instead we can use the attribute __read_mostly, which is the expansion of const_debug when CONFIG_SCHED_DEBUG is set.

---
Changes in v2:
- removed pointless include of linux/static_key.h
- added Reviewed-by tag

 include/linux/sched/sysctl.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/sched/sysctl.h +0 -0
index 0f5ecd4d298e..d34c823f3d36 100644
@@ -37,9 +37,9 @@ extern unsigned int sysctl_numa_balancing_scan_period_max;
 extern unsigned int sysctl_numa_balancing_scan_size;
 
Quoted 10 lines

include/linux/sched/sysctl.h extern unsigned int sysctl_numa_balancing_scan_period_max; · line 42

Quoted 7 lines
include/linux/sched/sysctl.h +3 -3
 #ifdef CONFIG_SCHED_DEBUG
-extern unsigned int sysctl_sched_migration_cost;
-extern unsigned int sysctl_sched_nr_migrate;
-extern unsigned int sysctl_sched_time_avg;
+extern __read_mostly unsigned int sysctl_sched_migration_cost;
+extern __read_mostly unsigned int sysctl_sched_nr_migrate;
+extern __read_mostly unsigned int sysctl_sched_time_avg;

So I hate this change, because it pointlessly duplicates an attribute that should only matter at the definition site.

Quoted 3 lines

It's certainly not ideal, and then again essentially the same is done in kernel/sched/sched.h, just that here the specific attribute is hidden behind const_debug.

Ok - and that indeed is a problem and makes the Clang build warning useful, as there are two conflicting prototypes and one definition.

I'll apply your fix.

Thanks,

Ingo

#5 lore raw
In reply to Matthias Kaehlcke
sched/sysctl: Fix attributes of some extern declarations
Commit-ID:  a9903f04e0a4ea522d959c2f287cdf0ab029e324
Gitweb:     https://git.kernel.org/tip/a9903f04e0a4ea522d959c2f287cdf0ab029e324
Author:     Matthias Kaehlcke <[email protected]>
AuthorDate: Mon, 30 Oct 2017 11:08:16 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Nov 2017 09:36:17 +0100

sched/sysctl: Fix attributes of some extern declarations

The definition of sysctl_sched_migration_cost, sysctl_sched_nr_migrate and sysctl_sched_time_avg includes the attribute const_debug. This attribute is not part of the extern declaration of these variables in include/linux/sched/sysctl.h, while it is in kernel/sched/sched.h, and as a result Clang generates warnings like this:

kernel/sched/sched.h:1618:33: warning: section attribute is specified on redeclared variable [-Wsection]

  extern const_debug unsigned int sysctl_sched_time_avg;
                                ^

./include/linux/sched/sysctl.h:42:21: note: previous declaration is here extern unsigned int sysctl_sched_time_avg;

The header only declares the variables when CONFIG_SCHED_DEBUG is defined, therefore it is not necessary to duplicate the definition of const_debug. Instead we can use the attribute __read_mostly, which is the expansion of const_debug when CONFIG_SCHED_DEBUG=y is set.

---
 include/linux/sched/sysctl.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/sched/sysctl.h +3 -3
index 0f5ecd4..d34c823 100644
@@ -37,9 +37,9 @@ extern unsigned int sysctl_numa_balancing_scan_period_max;
 extern unsigned int sysctl_numa_balancing_scan_size;
 
 #ifdef CONFIG_SCHED_DEBUG
-extern unsigned int sysctl_sched_migration_cost;
-extern unsigned int sysctl_sched_nr_migrate;
-extern unsigned int sysctl_sched_time_avg;
+extern __read_mostly unsigned int sysctl_sched_migration_cost;
+extern __read_mostly unsigned int sysctl_sched_nr_migrate;
+extern __read_mostly unsigned int sysctl_sched_time_avg;
 
 int sched_proc_update_handler(struct ctl_table *table, int write,
 		void __user *buffer, size_t *length,