Skip to contentSkip to conversation

cpupower: avoid multiple definition with gcc -fno-common

PATCH Superseded Mike Gilbert 2 participants 6 messages Feb 1, 2020 – Feb 26, 2020 CPU power monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpupower: avoid multiple definition with gcc -fno-common

The -fno-common option will be enabled by default in GCC 10.

---
 tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c  | 2 +-
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +1 -1
index 33dc34db4f3c..1b69f25a1281 100644
@@ -82,7 +82,7 @@ static struct pci_access *pci_acc;
 static struct pci_dev *amd_fam14h_pci_dev;
 static int nbp1_entered;
 
-struct timespec start_time;
+extern struct timespec start_time;
 static unsigned long long timediff;
 
 #ifdef DEBUG
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +2 -0
index 6d44fec55ad5..7c77045fef52 100644
@@ -27,6 +27,8 @@ struct cpuidle_monitor *all_monitors[] = {
 0
 };
 
+int cpu_count;
+
 static struct cpuidle_monitor *monitors[MONITORS_MAX];
 static unsigned int avail_monitors;
 
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +1 -1
index 5b5eb1da0cce..c559d3115330 100644
@@ -25,7 +25,7 @@
 #endif
 #define CSTATE_DESC_LEN 60
 
-int cpu_count;
+extern int cpu_count;
 
 /* Hard to define the right names ...: */
 enum power_range_e {
Signature · 1 line
2.25.0
#1 lore raw

PATCH v2 1/1 cpupower: avoid multiple definition with gcc -fno-common

The -fno-common option will be enabled by default in GCC 10.

---

v2: Made start_time static instead of extern.

 tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c  | 2 +-
 tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c    | 2 +-
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h | 2 +-
 4 files changed, 5 insertions(+), 3 deletions(-)
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +1 -1
index 33dc34db4f3c..20f46348271b 100644
@@ -82,7 +82,7 @@ static struct pci_access *pci_acc;
 static struct pci_dev *amd_fam14h_pci_dev;
 static int nbp1_entered;
 
-struct timespec start_time;
+static struct timespec start_time;
 static unsigned long long timediff;
 
 #ifdef DEBUG
tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c +1 -1
index 3c4cee160b0e..a65f7d011513 100644
@@ -19,7 +19,7 @@ struct cpuidle_monitor cpuidle_sysfs_monitor;
 
 static unsigned long long **previous_count;
 static unsigned long long **current_count;
-struct timespec start_time;
+static struct timespec start_time;
 static unsigned long long timediff;
 
 static int cpuidle_get_count_percent(unsigned int id, double *percent,
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +2 -0
index 6d44fec55ad5..7c77045fef52 100644
@@ -27,6 +27,8 @@ struct cpuidle_monitor *all_monitors[] = {
 0
 };
 
+int cpu_count;
+
 static struct cpuidle_monitor *monitors[MONITORS_MAX];
 static unsigned int avail_monitors;
 
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +1 -1
index 5b5eb1da0cce..c559d3115330 100644
@@ -25,7 +25,7 @@
 #endif
 #define CSTATE_DESC_LEN 60
 
-int cpu_count;
+extern int cpu_count;
 
 /* Hard to define the right names ...: */
 enum power_range_e {
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Hi Mike,

Quoted 1 line · Mike Gilbert

The -fno-common option will be enabled by default in GCC 10.

Great. It landed in my inbox now.
Please include the message you are seeing in the change log.

Quoted 16 lines

--- >> v2: Made start_time static instead of extern.

  tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c  | 2 +-
  tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c    | 2 +-
  tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
  tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h | 2 +-
  4 files changed, 5 insertions(+), 3 deletions(-)
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +0 -0
index 33dc34db4f3c..20f46348271b 100644

tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c static struct pci_access *pci_acc; · line 86

Quoted 6 lines
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +1 -1
@@ -82,7 +82,7 @@ static struct pci_access *pci_acc;
  static struct pci_dev *amd_fam14h_pci_dev;
  static int nbp1_entered;
 
-struct timespec start_time;
+static struct timespec start_time;
  static unsigned long long timediff;

Does it make sense to move start_time and timediff defines to cpupower-monitor.c and adding externs for them in cpupower-monitor.h?

Quoted 34 lines
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +0 -0
  #ifdef DEBUG
tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c +1 -1
index 3c4cee160b0e..a65f7d011513 100644
@@ -19,7 +19,7 @@ struct cpuidle_monitor cpuidle_sysfs_monitor;
 
  static unsigned long long **previous_count;
  static unsigned long long **current_count;
-struct timespec start_time;
+static struct timespec start_time;
  static unsigned long long timediff;
 
  static int cpuidle_get_count_percent(unsigned int id, double *percent,
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +2 -0
index 6d44fec55ad5..7c77045fef52 100644
@@ -27,6 +27,8 @@ struct cpuidle_monitor *all_monitors[] = {
  0
  };
 
+int cpu_count;
+
  static struct cpuidle_monitor *monitors[MONITORS_MAX];
  static unsigned int avail_monitors;
 
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +0 -0
index 5b5eb1da0cce..c559d3115330 100644

tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h line 31

Quoted 8 lines
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +1 -1
@@ -25,7 +25,7 @@
  #endif
  #define CSTATE_DESC_LEN 60
 
-int cpu_count;
+extern int cpu_count;
 
  /* Hard to define the right names ...: */
  enum power_range_e {

thanks,
-- Shuah

#3 lore raw
Quoted 8 lines · shuah

Hi Mike,

Quoted 1 line · Mike Gilbert

The -fno-common option will be enabled by default in GCC 10.

Great. It landed in my inbox now.
Please include the message you are seeing in the change log.

Sure, I will roll a v3 shortly.

Quoted 8 lines
Quoted 8 lines
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +0 -0
index 33dc34db4f3c..20f46348271b 100644
@@ -82,7 +82,7 @@ static struct pci_access *pci_acc;
  static struct pci_dev *amd_fam14h_pci_dev;
  static int nbp1_entered;
 
Quoted 7 lines

tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c static struct pci_access *pci_acc; · line 86

Quoted 3 lines
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +1 -1
-struct timespec start_time;
+static struct timespec start_time;
  static unsigned long long timediff;

Does it make sense to move start_time and timediff defines to cpupower-monitor.c and adding externs for them in cpupower-monitor.h?

I don't think that makes a lot of sense. start_time is really an internal value and does not need to be shared between the two object files.

maintainer
#4 lore raw
Quoted 11 lines · Mike Gilbert
Quoted 8 lines · shuah

Hi Mike,

Quoted 1 line · Mike Gilbert

The -fno-common option will be enabled by default in GCC 10.

Great. It landed in my inbox now.
Please include the message you are seeing in the change log.

Sure, I will roll a v3 shortly.

Great.

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +0 -0
index 33dc34db4f3c..20f46348271b 100644
@@ -82,7 +82,7 @@ static struct pci_access *pci_acc;
   static struct pci_dev *amd_fam14h_pci_dev;
   static int nbp1_entered;
 
Quoted 7 lines

tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c static struct pci_access *pci_acc; · line 86

Quoted 3 lines
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +1 -1
-struct timespec start_time;
+static struct timespec start_time;
   static unsigned long long timediff;

Does it make sense to move start_time and timediff defines to cpupower-monitor.c and adding externs for them in cpupower-monitor.h?

Quoted 4 lines

I don't think that makes a lot of sense. start_time is really an internal value and does not need to be shared between the two object files.

Makes sense.

thanks,
-- Shuah

#5 lore raw

PATCH v3 1/1 cpupower: avoid multiple definition with gcc -fno-common

In reply to Mike Gilbert

Building cpupower with -fno-common in CFLAGS results in errors due to multiple definitions of the 'cpu_count' and 'start_time' variables.

./utils/idle_monitor/snb_idle.o:./utils/idle_monitor/cpupower-monitor.h:28:
multiple definition of `cpu_count'; ./utils/idle_monitor/nhm_idle.o:./utils/idle_monitor/cpupower-monitor.h:28:
first defined here
...
./utils/idle_monitor/cpuidle_sysfs.o:./utils/idle_monitor/cpuidle_sysfs.c:22:
multiple definition of `start_time'; ./utils/idle_monitor/amd_fam14h_idle.o:./utils/idle_monitor/amd_fam14h_idle.c:85:
first defined here

The -fno-common option will be enabled by default in GCC 10.

---
 tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c  | 2 +-
 tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c    | 2 +-
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c | 2 ++
 tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h | 2 +-
 4 files changed, 5 insertions(+), 3 deletions(-)
tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c +1 -1
index 33dc34db4f3c..20f46348271b 100644
@@ -82,7 +82,7 @@ static struct pci_access *pci_acc;
 static struct pci_dev *amd_fam14h_pci_dev;
 static int nbp1_entered;
 
-struct timespec start_time;
+static struct timespec start_time;
 static unsigned long long timediff;
 
 #ifdef DEBUG
tools/power/cpupower/utils/idle_monitor/cpuidle_sysfs.c +1 -1
index 3c4cee160b0e..a65f7d011513 100644
@@ -19,7 +19,7 @@ struct cpuidle_monitor cpuidle_sysfs_monitor;
 
 static unsigned long long **previous_count;
 static unsigned long long **current_count;
-struct timespec start_time;
+static struct timespec start_time;
 static unsigned long long timediff;
 
 static int cpuidle_get_count_percent(unsigned int id, double *percent,
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.c +2 -0
index 6d44fec55ad5..7c77045fef52 100644
@@ -27,6 +27,8 @@ struct cpuidle_monitor *all_monitors[] = {
 0
 };
 
+int cpu_count;
+
 static struct cpuidle_monitor *monitors[MONITORS_MAX];
 static unsigned int avail_monitors;
 
tools/power/cpupower/utils/idle_monitor/cpupower-monitor.h +1 -1
index 5b5eb1da0cce..c559d3115330 100644
@@ -25,7 +25,7 @@
 #endif
 #define CSTATE_DESC_LEN 60
 
-int cpu_count;
+extern int cpu_count;
 
 /* Hard to define the right names ...: */
 enum power_range_e {
Signature · 1 line
2.25.1