From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 021413858C52; Wed, 21 Sep 2022 08:00:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 021413858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663747208; bh=MIz1QdImRfZe4DonS6quVCRB/hEyax11pQLgXfJSqmI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fupQZLzxYxVtv9t3ue7IW65owbflEkahtt8IyLkEgIdABQM1XzJ8ZWXWTxAfgjQQZ mJlG2R3MeS/NdN3ra2I9rD1yfI+jCMALZLPbdSW0tIQduEVLyEFr2dT85TP5Hfygey O6dmhwkYElk87HmUsLzxycaz4C7SrMRWtnOYj8Qw= From: "mjbaars1977 at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/29585] sched_getcpu returns invalid results Date: Wed, 21 Sep 2022 08:00:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: security- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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 --- Comment #2 from Mischa Baars --- (In reply to Mischa Baars from comment #0) > Hello, >=20 > I noticed the following while I was trying SCHED_FIFO, because FIFO > processes are not supposed to migrate from processor to processor. >=20 > When looking at the manual page of sched_getcpu(), it states that: >=20 > The call >=20 > cpu =3D sched_getcpu(); >=20 > is equivalent to the following getcpu(2) call: >=20 > int c, s; > s =3D getcpu(&c, NULL, NULL); > cpu =3D (s =3D=3D -1) ? s : c; >=20 > 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. >=20 > 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. >=20 > sched_get_cpu_timer_init(0); > // core_from =3D sched_get_cpu() + 1;=09 >=20 > double x =3D 1.0; > double y =3D (double) (random() + 1) * 1.00E-19f; >=20 > for (long i =3D 0; i < ((long) 1 << 32); i++) x *=3D 1.00f + y; >=20 > // sleep (1); > // usleep (random() % 1000000L); >=20=09 > // core_upto =3D sched_get_cpu() + 1; > sched_get_cpu_timer_free(); >=20 > Compilation is done with -Ofast -mfpmath=3D387 -fno-toplevel-reorder, for= sake > of completeness. >=20 > Best regards, > Mischa Baars. (In reply to Florian Weimer from comment #1) > Would you please post a complete, self-contained reproducer, and state yo= ur > glibc and kernel versions? Thanks. Yes... working on it. --=20 You are receiving this mail because: You are on the CC list for the bug.=