perf tools: rework of handling lack of sched_getcpu in old glibc
PATCH 1/1 perf tools: rework of handling lack of sched_getcpu in old glibc
Commit e1e455f4f4d3 ("perf tools: Work around lack of sched_getcpu in glibc < 2.6.") introduced weak function sched_getcpu() which should be overridden by sched_getcpu() provided by glibc >= 2.6. Unfortunately, the weak function was linked to sched_getcpu() used in perf bench numa and made the benchmark heavily relying on this function unusable.
This patch alternates weak function magic for preprocessor defines.
--- tools/perf/util/cloexec.c | 13 +++++++++++-- tools/perf/util/cloexec.h | 6 ------ 2 files changed, 11 insertions(+), 8 deletions(-)
tools/perf/util/cloexec.c +11 -2
@@ -7,11 +7,20 @@static unsigned long flag =PERF_FLAG_FD_CLOEXEC ; -int __weak sched_getcpu (void ) +#ifdef __GLIBC_PREREQ +#if !__GLIBC_PREREQ (2 ,6 ) +static int do_sched_getcpu (void ) { errno =ENOSYS ;return -1 ; } +#else +static int do_sched_getcpu (void ) +{ +return sched_getcpu (); +} +#endif +#endif static int perf_flag_probe (void ) {
@@ -27,7 +36,7 @@ static int perf_flag_probe(void)pid_t pid =-1 ;char sbuf[STRERR_BUFSIZE ]; - cpu =sched_getcpu (); + cpu =do_sched_getcpu ();if (cpu <0 ) cpu =0 ;
tools/perf/util/cloexec.h +0 -6
@@ -3,10 +3,4 @@unsigned long perf_event_open_cloexec_flag (void ); -#ifdef __GLIBC_PREREQ -#if !__GLIBC_PREREQ (2 ,6 ) -extern int sched_getcpu(void) __THROW; -#endif -#endif -#endif /* __PERF_CLOEXEC_H */
Signature · 1 line
2.1.0
Arnaldo Carvalho de Melo
maintainerEm Tue, May 19, 2015 at 03:20:47PM +0200, Petr Holasek escreveu:
Quoted 7 lines
Commit
e1e455f4f4d3("perf tools: Work around lack ofsched_getcpuin glibc < 2.6.") introduced weak functionsched_getcpu()which should be overridden bysched_getcpu()provided by glibc >= 2.6. Unfortunately, the weak function was linked tosched_getcpu()used in perf bench numa and made the benchmark heavily relying on this function unusable.This patch alternates weak function magic for preprocessor defines.
With this you break the build again on RHEL5, right? That "fix" was a quickie, the good thing would be to have this sched_getcpu() thing somewhere else, far from its user, i.e. cloexec has no business doing this if there are other places (perf bench numa) that need this, right?
- Arnaldo
Quoted 58 lines
Signed-off-by Petr Holasek <[email protected]>--- tools/perf/util/cloexec.c | 13 +++++++++++-- tools/perf/util/cloexec.h | 6 ------ 2 files changed, 11 insertions(+), 8 deletions(-)tools/perf/util/cloexec.c +11
-2@@ -7,11 +7,20 @@static unsigned long flag =PERF_FLAG_FD_CLOEXEC ; -int __weak sched_getcpu (void ) +#ifdef __GLIBC_PREREQ +#if !__GLIBC_PREREQ (2 ,6 ) +static int do_sched_getcpu (void ) { errno =ENOSYS ;return -1 ; } +#else +static int do_sched_getcpu (void ) +{ +return sched_getcpu (); +} +#endif +#endif static int perf_flag_probe (void ) {@@ -27,7 +36,7 @@ static int perf_flag_probe(void)pid_t pid =-1 ;char sbuf[STRERR_BUFSIZE ]; - cpu =sched_getcpu (); + cpu =do_sched_getcpu ();if (cpu <0 ) cpu =0 ;tools/perf/util/cloexec.h +0
-6@@ -3,10 +3,4 @@unsigned long perf_event_open_cloexec_flag (void ); -#ifdef __GLIBC_PREREQ -#if !__GLIBC_PREREQ (2 ,6 ) -extern int sched_getcpu(void) __THROW; -#endif -#endif -#endif /* __PERF_CLOEXEC_H */ Signature · 1 line
2.1.0
Quoted 7 lines · Arnaldo Carvalho de Melo
Em Tue, May 19, 2015 at 03:20:47PM +0200, Petr Holasek escreveu:
Quoted 6 lines
Commit
e1e455f4f4d3("perf tools: Work around lack ofsched_getcpuin glibc < 2.6.") introduced weak functionsched_getcpu()which should be overridden bysched_getcpu()provided by glibc >= 2.6. Unfortunately, the weak function was linked tosched_getcpu()used in perf bench numa and made the benchmark heavily relying on this function unusable.
Quoted 9 lines
Quoted 1 line
This patch alternates weak function magic for preprocessor defines.
With this you break the build again on RHEL5, right? That "fix" was a quickie, the good thing would be to have this
sched_getcpu()thing somewhere else, far from its user, i.e. cloexec has no business doing this if there are other places (perf bench numa) that need this, right?- Arnaldo
This fix is also quickie, since perf bench numa was unusable from 4.0-rc1 and I needed to fix it somehow. But I agree, the right place for the fix should be *far* from its users.
Quoted 59 lines
Quoted 59 lines
Signed-off-by Petr Holasek <[email protected]>--- tools/perf/util/cloexec.c | 13 +++++++++++-- tools/perf/util/cloexec.h | 6 ------ 2 files changed, 11 insertions(+), 8 deletions(-)tools/perf/util/cloexec.c +11
-2@@ -7,11 +7,20 @@static unsigned long flag =PERF_FLAG_FD_CLOEXEC ; -int __weak sched_getcpu (void ) +#ifdef __GLIBC_PREREQ +#if !__GLIBC_PREREQ (2 ,6 ) +static int do_sched_getcpu (void ) { errno =ENOSYS ;return -1 ; } +#else +static int do_sched_getcpu (void ) +{ +return sched_getcpu (); +} +#endif +#endif static int perf_flag_probe (void ) {@@ -27,7 +36,7 @@ static int perf_flag_probe(void)pid_t pid =-1 ;char sbuf[STRERR_BUFSIZE ]; - cpu =sched_getcpu (); + cpu =do_sched_getcpu ();if (cpu <0 ) cpu =0 ;tools/perf/util/cloexec.h +0
-6@@ -3,10 +3,4 @@unsigned long perf_event_open_cloexec_flag (void ); -#ifdef __GLIBC_PREREQ -#if !__GLIBC_PREREQ (2 ,6 ) -extern int sched_getcpu(void) __THROW; -#endif -#endif -#endif /* __PERF_CLOEXEC_H */ Signature · 1 line
2.1.0
Signature · 2 lines
Petr Holasek [email protected]