From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 515913858CDA; Mon, 19 Sep 2022 08:22:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 515913858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663575751; bh=I2XNGIrrycqPH4CODpUkzmxnEIlHOlYAUWXbzicgt7o=; h=From:To:Subject:Date:From; b=uBekV2wD7rKM22VfJ2G8D2YOXJjY90Ix5OTR1XYnQGVRJY/735EW7Ji268w4vnHgy ns2CfqMpl7SikTqXDXvZVgplpsYojZyOQKO+xC9cY1Dmh9so9AxdSUmg4/X3KssHPp CHFOJc5EvZs18Zec++dtGw4lobbQJ13Shh4Cb7IE= From: "mjbaars1977 at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/29585] New: sched_getcpu returns invalid results Date: Mon, 19 Sep 2022 08:22:30 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: 2.35 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mjbaars1977 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29585 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 process= es are not supposed to migrate from processor to processor. When looking at the manual page of sched_getcpu(), it states that: The call cpu =3D sched_getcpu(); is equivalent to the following getcpu(2) call: int c, s; s =3D getcpu(&c, NULL, NULL); cpu =3D (s =3D=3D -1) ? s : c; But when you compare the output of these two in a multi-threaded program (u= sing 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 =3D sched_get_cpu() + 1;=20=20=20=20 double x =3D 1.0; double y =3D (double) (random() + 1) * 1.00E-19f; for (long i =3D 0; i < ((long) 1 << 32); i++) x *=3D 1.00f + y; // sleep (1); // usleep (random() % 1000000L); // core_upto =3D sched_get_cpu() + 1; sched_get_cpu_timer_free(); Compilation is done with -Ofast -mfpmath=3D387 -fno-toplevel-reorder, for s= ake of completeness. Best regards, Mischa Baars. --=20 You are receiving this mail because: You are on the CC list for the bug.=