public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "mjbaars1977 at gmail dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug libc/29585] sched_getcpu returns invalid results Date: Wed, 21 Sep 2022 08:00:07 +0000 [thread overview] Message-ID: <bug-29585-131-7SeZGrQtkw@http.sourceware.org/bugzilla/> (raw) In-Reply-To: <bug-29585-131@http.sourceware.org/bugzilla/> https://sourceware.org/bugzilla/show_bug.cgi?id=29585 --- Comment #2 from Mischa Baars <mjbaars1977 at gmail dot com> --- (In reply to Mischa Baars from comment #0) > 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. (In reply to Florian Weimer from comment #1) > Would you please post a complete, self-contained reproducer, and state your > glibc and kernel versions? Thanks. Yes... working on it. -- You are receiving this mail because: You are on the CC list for the bug.
next prev parent reply other threads:[~2022-09-21 8:00 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-19 8:22 [Bug libc/29585] New: " 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 [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-29585-131-7SeZGrQtkw@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).