Re: [PATCH] perf tools: Work around lack of sched_getcpu in glibc < 2.6.

Peter Zijlstra
2015-03-18T09:15:52Z

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.