public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/29585] New: sched_getcpu returns invalid results
@ 2022-09-19  8:22 mjbaars1977 at gmail dot com
  2022-09-19 14:21 ` [Bug libc/29585] " fweimer at redhat dot com
                   ` (24 more replies)
  0 siblings, 25 replies; 26+ messages in thread
From: mjbaars1977 at gmail dot com @ 2022-09-19  8:22 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=29585

            Bug ID: 29585
           Summary: sched_getcpu returns invalid results
           Product: glibc
           Version: 2.35
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: mjbaars1977 at gmail dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

Hello,

I noticed the following while I was trying SCHED_FIFO, because FIFO processes
are not supposed to migrate from processor to processor.

When looking at the manual page of sched_getcpu(), it states that:

The call

           cpu = sched_getcpu();

       is equivalent to the following getcpu(2) call:

           int c, s;
           s = getcpu(&c, NULL, NULL);
           cpu = (s == -1) ? s : c;

But when you compare the output of these two in a multi-threaded program (using
clone()), the two produce very different outcomes. Only the second one will
give you the right answer.

The results can be reproduced with sched_setaffinity() before calling clone()
and a call to both methods above from within the child process. My version uses
a timer_create() to make this call periodically.

        sched_get_cpu_timer_init(0);
//      core_from     = sched_get_cpu() + 1;    

        double x = 1.0;
        double y = (double) (random() + 1) * 1.00E-19f;

        for     (long i = 0; i < ((long) 1 << 32); i++) x *= 1.00f + y;

//      sleep   (1);
//      usleep  (random() % 1000000L);

//      core_upto     = sched_get_cpu() + 1;
        sched_get_cpu_timer_free();

Compilation is done with -Ofast -mfpmath=387 -fno-toplevel-reorder, for sake of
completeness.

Best regards,
Mischa Baars.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2022-11-14 16:40 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-19  8:22 [Bug libc/29585] New: sched_getcpu returns invalid results mjbaars1977 at gmail dot com
2022-09-19 14:21 ` [Bug libc/29585] " fweimer at redhat dot com
2022-09-21  8:00 ` mjbaars1977 at gmail dot com
2022-09-22  8:30 ` mjbaars1977 at gmail dot com
2022-09-22 12:59 ` mjbaars1977 at gmail dot com
2022-09-22 13:00 ` mjbaars1977 at gmail dot com
2022-09-26  8:04 ` mjbaars1977 at gmail dot com
2022-09-26  9:18 ` fweimer at redhat dot com
2022-09-26 11:14 ` mjbaars1977 at gmail dot com
2022-09-26 11:21 ` fweimer at redhat dot com
2022-09-26 12:15 ` mjbaars1977 at gmail dot com
2022-09-28  9:59 ` mjbaars1977 at gmail dot com
2022-09-28 10:09 ` schwab@linux-m68k.org
2022-09-28 14:03 ` mjbaars1977 at gmail dot com
2022-10-10  9:18 ` fweimer at redhat dot com
2022-10-10 15:14 ` mjbaars1977 at gmail dot com
2022-10-10 16:20 ` mjbaars1977 at gmail dot com
2022-10-10 16:31 ` fweimer at redhat dot com
2022-10-10 16:41 ` mjbaars1977 at gmail dot com
2022-10-10 17:05 ` mjbaars1977 at gmail dot com
2022-10-10 17:09 ` schwab@linux-m68k.org
2022-10-10 17:10 ` mjbaars1977 at gmail dot com
2022-11-14  9:58 ` mjbaars1977 at gmail dot com
2022-11-14 12:55 ` fweimer at redhat dot com
2022-11-14 16:15 ` mjbaars1977 at gmail dot com
2022-11-14 16:40 ` mjbaars1977 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).