All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
@ 2015-02-14  2:06 Vinson Lee
  2015-02-16 20:50 ` Yann Droneaud
  0 siblings, 1 reply; 15+ messages in thread
From: Vinson Lee @ 2015-02-14  2:06 UTC (permalink / raw)
  To: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	Masami Hiramatsu, Namhyung Kim, Yann Droneaud
  Cc: linux-kernel, linux-perf-users, Vinson Lee

From: Vinson Lee <vlee@twitter.com>

This patch fixes this build error with glibc < 2.6.

  CC       util/cloexec.o
cc1: warnings being treated as errors
util/cloexec.c: In function ‘perf_flag_probe’:
util/cloexec.c:24: error: implicit declaration of function
‘sched_getcpu’
util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
make: *** [util/cloexec.o] Error 1

Cc: stable@vger.kernel.org # 3.18+
Signed-off-by: Vinson Lee <vlee@twitter.com>
---
 tools/perf/util/cloexec.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 47b78b3..3738924 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -7,6 +7,12 @@
 
 static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
 
+#ifdef __GLIBC_PREREQ
+#if __GLIBC_PREREQ(2, 6)
+#define HAVE_SCHED_GETCPU
+#endif
+#endif
+
 static int perf_flag_probe(void)
 {
 	/* use 'safest' configuration as used in perf_evsel__fallback() */
@@ -21,9 +27,13 @@ static int perf_flag_probe(void)
 	pid_t pid = -1;
 	char sbuf[STRERR_BUFSIZE];
 
+#ifdef HAVE_SCHED_GETCPU
 	cpu = sched_getcpu();
 	if (cpu < 0)
 		cpu = 0;
+#else
+	cpu = 0;
+#endif
 
 	while (1) {
 		/* check cloexec flag */
-- 
1.8.2.1


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

* Re: [PATCH] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-02-14  2:06 [PATCH] perf tools: Work around lack of sched_getcpu in glibc < 2.6 Vinson Lee
@ 2015-02-16 20:50 ` Yann Droneaud
  2015-03-17 23:49   ` Vinson Lee
  0 siblings, 1 reply; 15+ messages in thread
From: Yann Droneaud @ 2015-02-16 20:50 UTC (permalink / raw)
  To: Vinson Lee
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	Masami Hiramatsu, Namhyung Kim, linux-kernel, linux-perf-users,
	Vinson Lee

Hi,

Le vendredi 13 février 2015 à 18:06 -0800, Vinson Lee a écrit :
> From: Vinson Lee <vlee@twitter.com>
> 
> This patch fixes this build error with glibc < 2.6.
> 
>   CC       util/cloexec.o
> cc1: warnings being treated as errors
> util/cloexec.c: In function ‘perf_flag_probe’:
> util/cloexec.c:24: error: implicit declaration of function
> ‘sched_getcpu’
> util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
> make: *** [util/cloexec.o] Error 1
> 
> Cc: stable@vger.kernel.org # 3.18+
> Signed-off-by: Vinson Lee <vlee@twitter.com>
> ---
>  tools/perf/util/cloexec.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index 47b78b3..3738924 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -7,6 +7,12 @@
>  
>  static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
>  
> +#ifdef __GLIBC_PREREQ
> +#if __GLIBC_PREREQ(2, 6)
> +#define HAVE_SCHED_GETCPU
> +#endif
> +#endif
> +

OK

>  static int perf_flag_probe(void)
>  {
>  	/* use 'safest' configuration as used in perf_evsel__fallback() */
> @@ -21,9 +27,13 @@ static int perf_flag_probe(void)
>  	pid_t pid = -1;
>  	char sbuf[STRERR_BUFSIZE];
>  
> +#ifdef HAVE_SCHED_GETCPU
>  	cpu = sched_getcpu();
>  	if (cpu < 0)
>  		cpu = 0;
> +#else
> +	cpu = 0;
> +#endif
>  
>  	while (1) {
>  		/* check cloexec flag */

I've reviewed the use of __GLIBC_PREREQ(2, 6), but not whether using cpu
= 0 is OK if sched_getcpu() is not available.

Reviewed-by: Yann Droneaud <ydroneaud@opteya.com>

Regards.

-- 
Yann Droneaud
OPTEYA




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

* Re: [PATCH] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-02-16 20:50 ` Yann Droneaud
@ 2015-03-17 23:49   ` Vinson Lee
  2015-03-18  9:15     ` Peter Zijlstra
  0 siblings, 1 reply; 15+ messages in thread
From: Vinson Lee @ 2015-03-17 23:49 UTC (permalink / raw)
  To: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	Masami Hiramatsu, Namhyung Kim
  Cc: LKML, linux-perf-users, Vinson Lee, Yann Droneaud

On Mon, Feb 16, 2015 at 12:50 PM, Yann Droneaud <ydroneaud@opteya.com> wrote:
> Hi,
>
> Le vendredi 13 février 2015 à 18:06 -0800, Vinson Lee a écrit :
>> From: Vinson Lee <vlee@twitter.com>
>>
>> This patch fixes this build error with glibc < 2.6.
>>
>>   CC       util/cloexec.o
>> cc1: warnings being treated as errors
>> util/cloexec.c: In function ‘perf_flag_probe’:
>> util/cloexec.c:24: error: implicit declaration of function
>> ‘sched_getcpu’
>> util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
>> make: *** [util/cloexec.o] Error 1
>>
>> Cc: stable@vger.kernel.org # 3.18+
>> Signed-off-by: Vinson Lee <vlee@twitter.com>
>> ---
>>  tools/perf/util/cloexec.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
>> index 47b78b3..3738924 100644
>> --- a/tools/perf/util/cloexec.c
>> +++ b/tools/perf/util/cloexec.c
>> @@ -7,6 +7,12 @@
>>
>>  static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
>>
>> +#ifdef __GLIBC_PREREQ
>> +#if __GLIBC_PREREQ(2, 6)
>> +#define HAVE_SCHED_GETCPU
>> +#endif
>> +#endif
>> +
>
> OK
>
>>  static int perf_flag_probe(void)
>>  {
>>       /* use 'safest' configuration as used in perf_evsel__fallback() */
>> @@ -21,9 +27,13 @@ static int perf_flag_probe(void)
>>       pid_t pid = -1;
>>       char sbuf[STRERR_BUFSIZE];
>>
>> +#ifdef HAVE_SCHED_GETCPU
>>       cpu = sched_getcpu();
>>       if (cpu < 0)
>>               cpu = 0;
>> +#else
>> +     cpu = 0;
>> +#endif
>>
>>       while (1) {
>>               /* check cloexec flag */
>
> I've reviewed the use of __GLIBC_PREREQ(2, 6), but not whether using cpu
> = 0 is OK if sched_getcpu() is not available.
>
> Reviewed-by: Yann Droneaud <ydroneaud@opteya.com>
>
> Regards.
>
> --
> Yann Droneaud
> OPTEYA
>
>
>

Ping. Please review the sched_getcpu hunk.

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

* Re: [PATCH] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-17 23:49   ` Vinson Lee
@ 2015-03-18  9:15     ` Peter Zijlstra
  2015-03-18 23:11       ` [PATCH v2] " Vinson Lee
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Zijlstra @ 2015-03-18  9:15 UTC (permalink / raw)
  To: Vinson Lee
  Cc: Paul Mackerras, Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa,
	Adrian Hunter, Masami Hiramatsu, Namhyung Kim, LKML,
	linux-perf-users, Vinson Lee, Yann Droneaud

On Tue, Mar 17, 2015 at 04:49:13PM -0700, Vinson Lee wrote:
> On Mon, Feb 16, 2015 at 12:50 PM, Yann Droneaud <ydroneaud@opteya.com> wrote:
> >> +#ifdef __GLIBC_PREREQ
> >> +#if __GLIBC_PREREQ(2, 6)
> >> +#define HAVE_SCHED_GETCPU
> >> +#endif
> >> +#endif

> >> @@ -21,9 +27,13 @@ static int perf_flag_probe(void)
> >>       pid_t pid = -1;
> >>       char sbuf[STRERR_BUFSIZE];
> >>
> >> +#ifdef HAVE_SCHED_GETCPU
> >>       cpu = sched_getcpu();
> >>       if (cpu < 0)
> >>               cpu = 0;
> >> +#else
> >> +     cpu = 0;
> >> +#endif
> >>
> >>       while (1) {
> >>               /* check cloexec flag */

Would it not be much nicer to implement a sched_getcpu() stub that
returns -1 and sets errno to -ENOSYS or something?

That avoids the magic #ifdef mushroom.

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

* [PATCH v2] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-18  9:15     ` Peter Zijlstra
@ 2015-03-18 23:11       ` Vinson Lee
  2015-03-19 10:13         ` Jiri Olsa
  0 siblings, 1 reply; 15+ messages in thread
From: Vinson Lee @ 2015-03-18 23:11 UTC (permalink / raw)
  To: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	Masami Hiramatsu, Namhyung Kim, Yann Droneaud
  Cc: linux-kernel, linux-perf-users, Vinson Lee

From: Vinson Lee <vlee@twitter.com>

This patch fixes this build error with glibc < 2.6.

  CC       util/cloexec.o
cc1: warnings being treated as errors
util/cloexec.c: In function ‘perf_flag_probe’:
util/cloexec.c:24: error: implicit declaration of function
‘sched_getcpu’
util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
make: *** [util/cloexec.o] Error 1

Cc: stable@vger.kernel.org # 3.18+
Signed-off-by: Vinson Lee <vlee@twitter.com>
---
 tools/perf/util/cloexec.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 6da965b..285bd70 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -7,6 +7,16 @@
 
 static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
 
+#ifdef __GLIBC_PREREQ
+#if !__GLIBC_PREREQ(2, 6)
+static int sched_getcpu(void)
+{
+	errno = ENOSYS;
+	return -1;
+}
+#endif
+#endif
+
 static int perf_flag_probe(void)
 {
 	/* use 'safest' configuration as used in perf_evsel__fallback() */
-- 
1.8.2.1


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

* Re: [PATCH v2] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-18 23:11       ` [PATCH v2] " Vinson Lee
@ 2015-03-19 10:13         ` Jiri Olsa
  2015-03-19 13:14           ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 15+ messages in thread
From: Jiri Olsa @ 2015-03-19 10:13 UTC (permalink / raw)
  To: Vinson Lee
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Adrian Hunter, Masami Hiramatsu,
	Namhyung Kim, Yann Droneaud, linux-kernel, linux-perf-users,
	Vinson Lee

On Wed, Mar 18, 2015 at 04:11:52PM -0700, Vinson Lee wrote:
> From: Vinson Lee <vlee@twitter.com>
> 
> This patch fixes this build error with glibc < 2.6.
> 
>   CC       util/cloexec.o
> cc1: warnings being treated as errors
> util/cloexec.c: In function ‘perf_flag_probe’:
> util/cloexec.c:24: error: implicit declaration of function
> ‘sched_getcpu’
> util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
> make: *** [util/cloexec.o] Error 1
> 
> Cc: stable@vger.kernel.org # 3.18+
> Signed-off-by: Vinson Lee <vlee@twitter.com>
> ---
>  tools/perf/util/cloexec.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index 6da965b..285bd70 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -7,6 +7,16 @@
>  
>  static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
>  
> +#ifdef __GLIBC_PREREQ
> +#if !__GLIBC_PREREQ(2, 6)
> +static int sched_getcpu(void)
> +{
> +	errno = ENOSYS;
> +	return -1;
> +}
> +#endif
> +#endif

you could mark it as __weak and get rid of those ifdef's
like we do for strlcpy in utilpath.c

jirka

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

* Re: [PATCH v2] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-19 10:13         ` Jiri Olsa
@ 2015-03-19 13:14           ` Arnaldo Carvalho de Melo
  2015-03-19 21:12             ` Vinson Lee
  0 siblings, 1 reply; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-03-19 13:14 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Vinson Lee, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Adrian Hunter, Masami Hiramatsu, Namhyung Kim, Yann Droneaud,
	linux-kernel, linux-perf-users, Vinson Lee

Em Thu, Mar 19, 2015 at 11:13:04AM +0100, Jiri Olsa escreveu:
> On Wed, Mar 18, 2015 at 04:11:52PM -0700, Vinson Lee wrote:
> > This patch fixes this build error with glibc < 2.6.

> > +#ifdef __GLIBC_PREREQ
> > +#if !__GLIBC_PREREQ(2, 6)
> > +static int sched_getcpu(void)
> > +{
> > +	errno = ENOSYS;
> > +	return -1;
> > +}
> > +#endif
> > +#endif
 
> you could mark it as __weak and get rid of those ifdef's
> like we do for strlcpy in utilpath.c

Agreed.

- Arnaldo

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

* Re: [PATCH v2] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-19 13:14           ` Arnaldo Carvalho de Melo
@ 2015-03-19 21:12             ` Vinson Lee
  2015-03-20 13:03               ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 15+ messages in thread
From: Vinson Lee @ 2015-03-19 21:12 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Jiri Olsa
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, Adrian Hunter,
	Masami Hiramatsu, Namhyung Kim, Yann Droneaud, LKML,
	linux-perf-users, Vinson Lee

On Thu, Mar 19, 2015 at 6:14 AM, Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
> Em Thu, Mar 19, 2015 at 11:13:04AM +0100, Jiri Olsa escreveu:
>> On Wed, Mar 18, 2015 at 04:11:52PM -0700, Vinson Lee wrote:
>> > This patch fixes this build error with glibc < 2.6.
>
>> > +#ifdef __GLIBC_PREREQ
>> > +#if !__GLIBC_PREREQ(2, 6)
>> > +static int sched_getcpu(void)
>> > +{
>> > +   errno = ENOSYS;
>> > +   return -1;
>> > +}
>> > +#endif
>> > +#endif
>
>> you could mark it as __weak and get rid of those ifdef's
>> like we do for strlcpy in utilpath.c
>
> Agreed.
>
> - Arnaldo

I tried this approach but am having trouble getting a patch to compile
with both older glibc and recent glibc.

With older glibc I will get a "no previous prototype" compilation
error. I can fix this error by adding a prototype but this results in
a "redundant redeclaration" error with newer glibc.

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

* Re: [PATCH v2] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-19 21:12             ` Vinson Lee
@ 2015-03-20 13:03               ` Arnaldo Carvalho de Melo
  2015-03-20 18:44                 ` Vinson Lee
  0 siblings, 1 reply; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-03-20 13:03 UTC (permalink / raw)
  To: Vinson Lee
  Cc: Jiri Olsa, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Adrian Hunter, Masami Hiramatsu, Namhyung Kim, Yann Droneaud,
	LKML, linux-perf-users, Vinson Lee

Em Thu, Mar 19, 2015 at 02:12:05PM -0700, Vinson Lee escreveu:
> On Thu, Mar 19, 2015 at 6:14 AM, Arnaldo Carvalho de Melo
> <acme@kernel.org> wrote:
> > Em Thu, Mar 19, 2015 at 11:13:04AM +0100, Jiri Olsa escreveu:
> >> On Wed, Mar 18, 2015 at 04:11:52PM -0700, Vinson Lee wrote:
> >> > This patch fixes this build error with glibc < 2.6.
> >
> >> > +#ifdef __GLIBC_PREREQ
> >> > +#if !__GLIBC_PREREQ(2, 6)
> >> > +static int sched_getcpu(void)
> >> > +{
> >> > +   errno = ENOSYS;
> >> > +   return -1;
> >> > +}
> >> > +#endif
> >> > +#endif
> >
> >> you could mark it as __weak and get rid of those ifdef's
> >> like we do for strlcpy in utilpath.c
> >
> > Agreed.
 
> I tried this approach but am having trouble getting a patch to compile
> with both older glibc and recent glibc.
 
> With older glibc I will get a "no previous prototype" compilation
> error. I can fix this error by adding a prototype but this results in
> a "redundant redeclaration" error with newer glibc.

So for strlcpy we have in tools/perf/util/cache.h:

#ifndef __UCLIBC__
/* Matches the libc/libbsd function attribute so we declare this
 * unconditionally: */
extern size_t strlcpy(char *dest, const char *src, size_t size);
#endif

I.e. have the ifdef just in the header file.

This way, if we end up needing to use sched_getcpu elsewhere, it will
work and the needed #ifdef will be constrained to the header file.

At some point we should try to move these functions to some
libc-compat.c file and move it to somewhere in tools/lib/.

- Arnaldo

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

* Re: [PATCH v2] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-20 13:03               ` Arnaldo Carvalho de Melo
@ 2015-03-20 18:44                 ` Vinson Lee
  2015-03-20 20:38                   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 15+ messages in thread
From: Vinson Lee @ 2015-03-20 18:44 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Adrian Hunter, Masami Hiramatsu, Namhyung Kim, Yann Droneaud,
	LKML, linux-perf-users, Vinson Lee

On Fri, Mar 20, 2015 at 6:03 AM, Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
> Em Thu, Mar 19, 2015 at 02:12:05PM -0700, Vinson Lee escreveu:
>> On Thu, Mar 19, 2015 at 6:14 AM, Arnaldo Carvalho de Melo
>> <acme@kernel.org> wrote:
>> > Em Thu, Mar 19, 2015 at 11:13:04AM +0100, Jiri Olsa escreveu:
>> >> On Wed, Mar 18, 2015 at 04:11:52PM -0700, Vinson Lee wrote:
>> >> > This patch fixes this build error with glibc < 2.6.
>> >
>> >> > +#ifdef __GLIBC_PREREQ
>> >> > +#if !__GLIBC_PREREQ(2, 6)
>> >> > +static int sched_getcpu(void)
>> >> > +{
>> >> > +   errno = ENOSYS;
>> >> > +   return -1;
>> >> > +}
>> >> > +#endif
>> >> > +#endif
>> >
>> >> you could mark it as __weak and get rid of those ifdef's
>> >> like we do for strlcpy in utilpath.c
>> >
>> > Agreed.
>
>> I tried this approach but am having trouble getting a patch to compile
>> with both older glibc and recent glibc.
>
>> With older glibc I will get a "no previous prototype" compilation
>> error. I can fix this error by adding a prototype but this results in
>> a "redundant redeclaration" error with newer glibc.
>
> So for strlcpy we have in tools/perf/util/cache.h:
>
> #ifndef __UCLIBC__
> /* Matches the libc/libbsd function attribute so we declare this
>  * unconditionally: */
> extern size_t strlcpy(char *dest, const char *src, size_t size);
> #endif
>
> I.e. have the ifdef just in the header file.
>
> This way, if we end up needing to use sched_getcpu elsewhere, it will
> work and the needed #ifdef will be constrained to the header file.
>
> At some point we should try to move these functions to some
> libc-compat.c file and move it to somewhere in tools/lib/.
>
> - Arnaldo


I tried moving the prototype to a header file and it does not compile
with newer glibc for me either. I still get a "redundant
redeclaration" compiler error.

Here is the diff that I tried.

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 6da965b..85b5238 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -7,6 +7,12 @@

 static unsigned long flag = PERF_FLAG_FD_CLOEXEC;

+int __weak sched_getcpu(void)
+{
+       errno = ENOSYS;
+       return -1;
+}
+
 static int perf_flag_probe(void)
 {
        /* use 'safest' configuration as used in perf_evsel__fallback() */
diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
index 94a5a7d..06904bc 100644
--- a/tools/perf/util/cloexec.h
+++ b/tools/perf/util/cloexec.h
@@ -3,4 +3,6 @@

 unsigned long perf_event_open_cloexec_flag(void);

+extern int sched_getcpu(void) __THROW;
+
 #endif /* __PERF_CLOEXEC_H */

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

* Re: [PATCH v2] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-20 18:44                 ` Vinson Lee
@ 2015-03-20 20:38                   ` Arnaldo Carvalho de Melo
  2015-03-23 19:09                     ` [PATCH v3] " Vinson Lee
  0 siblings, 1 reply; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-03-20 20:38 UTC (permalink / raw)
  To: Vinson Lee
  Cc: Jiri Olsa, Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Adrian Hunter, Masami Hiramatsu, Namhyung Kim, Yann Droneaud,
	LKML, linux-perf-users, Vinson Lee

Em Fri, Mar 20, 2015 at 11:44:42AM -0700, Vinson Lee escreveu:
> On Fri, Mar 20, 2015 at 6:03 AM, Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> > So for strlcpy we have in tools/perf/util/cache.h:

> > #ifndef __UCLIBC__
> > /* Matches the libc/libbsd function attribute so we declare this
> >  * unconditionally: */
> > extern size_t strlcpy(char *dest, const char *src, size_t size);
> > #endif

> > I.e. have the ifdef just in the header file.

This part you didn't take into account, the __weak marked part is ok,
the linker will DTRT with that, its just the redeclaration part that
needs to get out of the way, enclose that under appropriate ifdef, i.e.
one that is associated with the libc where that file first appeared and
that has been present since then.

- Arnaldo

> > This way, if we end up needing to use sched_getcpu elsewhere, it will
> > work and the needed #ifdef will be constrained to the header file.
 
> I tried moving the prototype to a header file and it does not compile
> with newer glibc for me either. I still get a "redundant
> redeclaration" compiler error.
 
> Here is the diff that I tried.
 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> @@ -7,6 +7,12 @@
> 
>  static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
> 
> +int __weak sched_getcpu(void)
> +{
> +       errno = ENOSYS;
> +       return -1;
> +}
> +
>  static int perf_flag_probe(void)
>  {
>         /* use 'safest' configuration as used in perf_evsel__fallback() */
> diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
> @@ -3,4 +3,6 @@
> 
>  unsigned long perf_event_open_cloexec_flag(void);
> 
> +extern int sched_getcpu(void) __THROW;
> +
>  #endif /* __PERF_CLOEXEC_H */

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

* [PATCH v3] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-20 20:38                   ` Arnaldo Carvalho de Melo
@ 2015-03-23 19:09                     ` Vinson Lee
  2015-03-24  0:21                       ` Namhyung Kim
                                         ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Vinson Lee @ 2015-03-23 19:09 UTC (permalink / raw)
  To: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	Masami Hiramatsu, Namhyung Kim, Yann Droneaud
  Cc: linux-kernel, linux-perf-users, Vinson Lee

From: Vinson Lee <vlee@twitter.com>

This patch fixes this build error with glibc < 2.6.

  CC       util/cloexec.o
cc1: warnings being treated as errors
util/cloexec.c: In function ‘perf_flag_probe’:
util/cloexec.c:24: error: implicit declaration of function
‘sched_getcpu’
util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
make: *** [util/cloexec.o] Error 1

Cc: stable@vger.kernel.org # 3.18+
Signed-off-by: Vinson Lee <vlee@twitter.com>
---
 tools/perf/util/cloexec.c | 6 ++++++
 tools/perf/util/cloexec.h | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 6da965b..85b5238 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -7,6 +7,12 @@
 
 static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
 
+int __weak sched_getcpu(void)
+{
+	errno = ENOSYS;
+	return -1;
+}
+
 static int perf_flag_probe(void)
 {
 	/* use 'safest' configuration as used in perf_evsel__fallback() */
diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
index 94a5a7d..68888c2 100644
--- a/tools/perf/util/cloexec.h
+++ b/tools/perf/util/cloexec.h
@@ -3,4 +3,10 @@
 
 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 */
-- 
1.8.2.1


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

* Re: [PATCH v3] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-23 19:09                     ` [PATCH v3] " Vinson Lee
@ 2015-03-24  0:21                       ` Namhyung Kim
  2015-03-24  7:10                       ` Jiri Olsa
  2015-03-24 16:32                       ` [tip:perf/core] " tip-bot for Vinson Lee
  2 siblings, 0 replies; 15+ messages in thread
From: Namhyung Kim @ 2015-03-24  0:21 UTC (permalink / raw)
  To: Vinson Lee
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Jiri Olsa, Adrian Hunter,
	Masami Hiramatsu, Yann Droneaud, linux-kernel, linux-perf-users,
	Vinson Lee

Hi Vinson,

On Mon, Mar 23, 2015 at 12:09:16PM -0700, Vinson Lee wrote:
> From: Vinson Lee <vlee@twitter.com>
> 
> This patch fixes this build error with glibc < 2.6.
> 
>   CC       util/cloexec.o
> cc1: warnings being treated as errors
> util/cloexec.c: In function ‘perf_flag_probe’:
> util/cloexec.c:24: error: implicit declaration of function
> ‘sched_getcpu’
> util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
> make: *** [util/cloexec.o] Error 1
> 
> Cc: stable@vger.kernel.org # 3.18+
> Signed-off-by: Vinson Lee <vlee@twitter.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung


> ---
>  tools/perf/util/cloexec.c | 6 ++++++
>  tools/perf/util/cloexec.h | 6 ++++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index 6da965b..85b5238 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -7,6 +7,12 @@
>  
>  static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
>  
> +int __weak sched_getcpu(void)
> +{
> +	errno = ENOSYS;
> +	return -1;
> +}
> +
>  static int perf_flag_probe(void)
>  {
>  	/* use 'safest' configuration as used in perf_evsel__fallback() */
> diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
> index 94a5a7d..68888c2 100644
> --- a/tools/perf/util/cloexec.h
> +++ b/tools/perf/util/cloexec.h
> @@ -3,4 +3,10 @@
>  
>  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 */
> -- 
> 1.8.2.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

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

* Re: [PATCH v3] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-23 19:09                     ` [PATCH v3] " Vinson Lee
  2015-03-24  0:21                       ` Namhyung Kim
@ 2015-03-24  7:10                       ` Jiri Olsa
  2015-03-24 16:32                       ` [tip:perf/core] " tip-bot for Vinson Lee
  2 siblings, 0 replies; 15+ messages in thread
From: Jiri Olsa @ 2015-03-24  7:10 UTC (permalink / raw)
  To: Vinson Lee
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar,
	Arnaldo Carvalho de Melo, Adrian Hunter, Masami Hiramatsu,
	Namhyung Kim, Yann Droneaud, linux-kernel, linux-perf-users,
	Vinson Lee

On Mon, Mar 23, 2015 at 12:09:16PM -0700, Vinson Lee wrote:
> From: Vinson Lee <vlee@twitter.com>
> 
> This patch fixes this build error with glibc < 2.6.
> 
>   CC       util/cloexec.o
> cc1: warnings being treated as errors
> util/cloexec.c: In function ‘perf_flag_probe’:
> util/cloexec.c:24: error: implicit declaration of function
> ‘sched_getcpu’
> util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
> make: *** [util/cloexec.o] Error 1
> 
> Cc: stable@vger.kernel.org # 3.18+
> Signed-off-by: Vinson Lee <vlee@twitter.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  tools/perf/util/cloexec.c | 6 ++++++
>  tools/perf/util/cloexec.h | 6 ++++++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index 6da965b..85b5238 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -7,6 +7,12 @@
>  
>  static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
>  
> +int __weak sched_getcpu(void)
> +{
> +	errno = ENOSYS;
> +	return -1;
> +}
> +
>  static int perf_flag_probe(void)
>  {
>  	/* use 'safest' configuration as used in perf_evsel__fallback() */
> diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
> index 94a5a7d..68888c2 100644
> --- a/tools/perf/util/cloexec.h
> +++ b/tools/perf/util/cloexec.h
> @@ -3,4 +3,10 @@
>  
>  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 */
> -- 
> 1.8.2.1
> 

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

* [tip:perf/core] perf tools: Work around lack of sched_getcpu in glibc < 2.6.
  2015-03-23 19:09                     ` [PATCH v3] " Vinson Lee
  2015-03-24  0:21                       ` Namhyung Kim
  2015-03-24  7:10                       ` Jiri Olsa
@ 2015-03-24 16:32                       ` tip-bot for Vinson Lee
  2 siblings, 0 replies; 15+ messages in thread
From: tip-bot for Vinson Lee @ 2015-03-24 16:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: a.p.zijlstra, masami.hiramatsu.pt, linux-kernel, ydroneaud,
	mingo, namhyung, acme, hpa, paulus, adrian.hunter, jolsa, tglx,
	vlee

Commit-ID:  e1e455f4f4d35850c30235747620d0d078fe9f64
Gitweb:     http://git.kernel.org/tip/e1e455f4f4d35850c30235747620d0d078fe9f64
Author:     Vinson Lee <vlee@twitter.com>
AuthorDate: Mon, 23 Mar 2015 12:09:16 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 24 Mar 2015 12:08:07 -0300

perf tools: Work around lack of sched_getcpu in glibc < 2.6.

This patch fixes this build error with glibc < 2.6.

  CC       util/cloexec.o
cc1: warnings being treated as errors
util/cloexec.c: In function ‘perf_flag_probe’:
util/cloexec.c:24: error: implicit declaration of function
‘sched_getcpu’
util/cloexec.c:24: error: nested extern declaration of ‘sched_getcpu’
make: *** [util/cloexec.o] Error 1

Signed-off-by: Vinson Lee <vlee@twitter.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Yann Droneaud <ydroneaud@opteya.com>
Cc: stable@vger.kernel.org # 3.18+
Link: http://lkml.kernel.org/r/1427137761-16119-1-git-send-email-vlee@twopensource.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cloexec.c | 6 ++++++
 tools/perf/util/cloexec.h | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index 6da965b..85b5238 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -7,6 +7,12 @@
 
 static unsigned long flag = PERF_FLAG_FD_CLOEXEC;
 
+int __weak sched_getcpu(void)
+{
+	errno = ENOSYS;
+	return -1;
+}
+
 static int perf_flag_probe(void)
 {
 	/* use 'safest' configuration as used in perf_evsel__fallback() */
diff --git a/tools/perf/util/cloexec.h b/tools/perf/util/cloexec.h
index 94a5a7d..68888c2 100644
--- a/tools/perf/util/cloexec.h
+++ b/tools/perf/util/cloexec.h
@@ -3,4 +3,10 @@
 
 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 */

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

end of thread, other threads:[~2015-03-24 16:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-14  2:06 [PATCH] perf tools: Work around lack of sched_getcpu in glibc < 2.6 Vinson Lee
2015-02-16 20:50 ` Yann Droneaud
2015-03-17 23:49   ` Vinson Lee
2015-03-18  9:15     ` Peter Zijlstra
2015-03-18 23:11       ` [PATCH v2] " Vinson Lee
2015-03-19 10:13         ` Jiri Olsa
2015-03-19 13:14           ` Arnaldo Carvalho de Melo
2015-03-19 21:12             ` Vinson Lee
2015-03-20 13:03               ` Arnaldo Carvalho de Melo
2015-03-20 18:44                 ` Vinson Lee
2015-03-20 20:38                   ` Arnaldo Carvalho de Melo
2015-03-23 19:09                     ` [PATCH v3] " Vinson Lee
2015-03-24  0:21                       ` Namhyung Kim
2015-03-24  7:10                       ` Jiri Olsa
2015-03-24 16:32                       ` [tip:perf/core] " tip-bot for Vinson Lee

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.